]> granicus.if.org Git - clang/commitdiff
Teach MemRegion::getBaseRegion() about ObjCIvarRegions. We want to treat
authorTed Kremenek <kremenek@apple.com>
Tue, 6 Apr 2010 22:06:03 +0000 (22:06 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 6 Apr 2010 22:06:03 +0000 (22:06 +0000)
them the same way as fields.  This fixes a regression in RegionStore::RemoveDeadbindings()
that emerged from going to the cluster-based analysis.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100570 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/MemRegion.cpp
test/Analysis/misc-ps-region-store.m

index 9f12ab622fbffee9316727ff589166073a14adf7..0571d81f9021e28aba6cc3908ad3ef5453e2903d 100644 (file)
@@ -647,13 +647,14 @@ bool MemRegion::hasGlobalsOrParametersStorage() const {
 const MemRegion *MemRegion::getBaseRegion() const {
   const MemRegion *R = this;
   while (true) {
-    if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) {
-      R = ER->getSuperRegion();
-      continue;
-    }
-    if (const FieldRegion *FR = dyn_cast<FieldRegion>(R)) {
-      R = FR->getSuperRegion();
-      continue;
+    switch (R->getKind()) {
+      case MemRegion::ElementRegionKind:
+      case MemRegion::FieldRegionKind:
+      case MemRegion::ObjCIvarRegionKind:
+        R = cast<SubRegion>(R)->getSuperRegion();
+        continue;
+      default:
+        break;
     }
     break;
   }
index d10b9fa5ded78a7ba0031eca6385b09ecefacd0b..0e305bf1dfba864fedb53c849751336ed3c76507 100644 (file)
@@ -955,3 +955,24 @@ void pr6288_b(void) {
   *(px[0]) = 0; // no-warning
 }
 
+// <rdar://problem/7817800> - A bug in RemoveDeadBindings was causing instance variable bindings
+//  to get prematurely pruned from the state.
+@interface Rdar7817800 {
+  char *x;
+}
+- (void) rdar7817800_baz;
+@end
+
+char *rdar7817800_foobar();
+void rdar7817800_qux(void*);
+
+@implementation Rdar7817800
+- (void) rdar7817800_baz {
+  if (x)
+    rdar7817800_qux(x);
+  x = rdar7817800_foobar();
+  // Previously this triggered a bogus null dereference warning.
+  x[1] = 'a'; // no-warning
+}
+@end
+