[PATCH] D57619: [analyzer] Canonicalize variable declarations in VarRegion objects.

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 6 16:30:13 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL353353: [analyzer] Canonicalize declarations within variable regions. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D57619?vs=184843&id=185673#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57619/new/

https://reviews.llvm.org/D57619

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
  cfe/trunk/test/Analysis/globals.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -844,6 +844,7 @@
 
 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 MemRegion *superR) {
+  D = D->getCanonicalDecl();
   return getSubRegion<VarRegion>(D, superR);
 }
 
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -908,7 +908,7 @@
   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,
Index: cfe/trunk/test/Analysis/globals.cpp
===================================================================
--- cfe/trunk/test/Analysis/globals.cpp
+++ cfe/trunk/test/Analysis/globals.cpp
@@ -109,3 +109,18 @@
     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}}
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57619.185673.patch
Type: text/x-patch
Size: 1960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190207/9eec5076/attachment.bin>


More information about the cfe-commits mailing list