diff options
-rw-r--r-- | clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h | 2 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/MemRegion.cpp | 2 | ||||
-rw-r--r-- | clang/test/Analysis/globals.cpp | 15 |
3 files changed, 18 insertions, 1 deletions
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 85eb4b865ab..071e35085a5 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -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, diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp index fd08f92a658..b9619d173dd 100644 --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -844,6 +844,7 @@ getStackOrCaptureRegionForDeclContext(const LocationContext *LC, 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::getVarRegion(const VarDecl *D, const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D, const MemRegion *superR) { + D = D->getCanonicalDecl(); return getSubRegion<VarRegion>(D, superR); } diff --git a/clang/test/Analysis/globals.cpp b/clang/test/Analysis/globals.cpp index 5bbb241bdcf..d3df6eb6d27 100644 --- a/clang/test/Analysis/globals.cpp +++ b/clang/test/Analysis/globals.cpp @@ -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}} +} |