]> granicus.if.org Git - clang/commitdiff
Reapply most of r82939, but add a guard that FieldRegions and friends
authorTed Kremenek <kremenek@apple.com>
Tue, 29 Sep 2009 03:34:03 +0000 (03:34 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 29 Sep 2009 03:34:03 +0000 (03:34 +0000)
are only specially treated by RegionStore::InvalidateRegion() when
their super region is also invalidated.  When this isn't the case,
conjure a new symbol for a FieldRegion.  Thanks to Zhongxing Xu and
Daniel Dunbar for pointing out this issue.

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

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

index da04d68dcf04dd70951e278709fe96e236405d96..3b27150baa1f9ead8f360e05330c5911cb832bcf 100644 (file)
@@ -514,15 +514,20 @@ const GRState *RegionStoreManager::InvalidateRegion(const GRState *state,
       continue;
     }
     
-    // FIXME: Special case FieldRegion/ElementRegion for more
-    // efficient invalidation.  We don't need to conjure symbols for
-    // these regions in all cases.
-    
     // Get the old binding.  Is it a region?  If so, add it to the worklist.
     if (const SVal *OldV = B.lookup(R)) {
       if (const MemRegion *RV = OldV->getAsRegion())
         WorkList.push_back(RV);
     }
+
+    if ((isa<FieldRegion>(R)||isa<ElementRegion>(R)||isa<ObjCIvarRegion>(R))
+        && Visited[cast<SubRegion>(R)->getSuperRegion()]) {
+        // For fields and elements whose super region has also been invalidated,
+        // only remove the old binding.  The super region will get set with a
+        // default value from which we can lazily derive a new symbolic value.
+      B = RBFactory.Remove(B, R);
+      continue;
+    }
     
     // Invalidate the binding.
     DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(R, Ex, T, Count);
index 76084d5c9ed48c37e1650232572c0c9fe51ed541..03e3f6f2dcefde2d7fe49342a63d8b1b48ad1109 100644 (file)
@@ -249,3 +249,20 @@ int rdar_6914474(void) {
   return x; // no-warning
 }
 
+// Test invalidation of a single field.
+struct s_test_field_invalidate {
+  int x;
+};
+extern void test_invalidate_field(int *x);
+int test_invalidate_field_test() {
+  struct s_test_field_invalidate y;
+  test_invalidate_field(&y.x);
+  return y.x; // no-warning
+}
+int test_invalidate_field_test_positive() {
+  struct s_test_field_invalidate y;
+  return y.x; // expected-warning{{garbage}}
+}
+
+
+