Author: dergachev Date: Wed Feb 6 16:30:20 2019 New Revision: 353353 URL: http://llvm.org/viewvc/llvm-project?rev=353353&view=rev Log: [analyzer] Canonicalize declarations within variable regions.
Memory region that correspond to a variable is identified by the variable's declaration and, in case of local variables, the stack frame it belongs to. The declaration needs to be canonical, otherwise we'd have two different memory regions that correspond to the same variable. Fix such bug for global variables with forward declarations and assert that no other problems of this kind happen. Differential Revision: https://reviews.llvm.org/D57619 Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp cfe/trunk/test/Analysis/globals.cpp Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h?rev=353353&r1=353352&r2=353353&view=diff ============================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h (original) +++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h Wed Feb 6 16:30:20 2019 @@ -908,7 +908,7 @@ protected: DeclRegion(const ValueDecl *d, const MemRegion *sReg, Kind k) : TypedValueRegion(sReg, k), D(d) { assert(classof(this)); - assert(d); + assert(d && d->isCanonicalDecl()); } static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Decl *D, Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=353353&r1=353352&r2=353353&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Wed Feb 6 16:30:20 2019 @@ -844,6 +844,7 @@ getStackOrCaptureRegionForDeclContext(co const VarRegion* MemRegionManager::getVarRegion(const VarDecl *D, const LocationContext *LC) { + D = D->getCanonicalDecl(); const MemRegion *sReg = nullptr; if (D->hasGlobalStorage() && !D->isStaticLocal()) { @@ -930,6 +931,7 @@ const VarRegion* MemRegionManager::getVa const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D, const MemRegion *superR) { + D = D->getCanonicalDecl(); return getSubRegion<VarRegion>(D, superR); } Modified: cfe/trunk/test/Analysis/globals.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/globals.cpp?rev=353353&r1=353352&r2=353353&view=diff ============================================================================== --- cfe/trunk/test/Analysis/globals.cpp (original) +++ cfe/trunk/test/Analysis/globals.cpp Wed Feb 6 16:30:20 2019 @@ -109,3 +109,18 @@ void recordinit() S3 s3; *(s3.p - 1) = 0; // expected-warning{{Dereference of null pointer}} } + +extern int ext_int; + +void update_original_declaration() { + ext_int = 2; +} + +extern int ext_int; + +int test_redeclaration() { + ext_int = 1; + update_original_declaration(); + int int_int = 3 / (ext_int - 1); // no-warning + return int_int / (ext_int - 2); // expected-warning{{Division by zero}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits