[cfe-commits] r96067 - in /cfe/trunk: lib/Checker/RegionStore.cpp test/Analysis/misc-ps-region-store.m

Ted Kremenek kremenek at apple.com
Fri Feb 12 17:52:34 PST 2010


Author: kremenek
Date: Fri Feb 12 19:52:33 2010
New Revision: 96067

URL: http://llvm.org/viewvc/llvm-project?rev=96067&view=rev
Log:
Enhance RegionStore::InvalidateRegions() to correctly invalidate bindings
by scanning through the values of LazyCompoundVals.

Modified:
    cfe/trunk/lib/Checker/RegionStore.cpp
    cfe/trunk/test/Analysis/misc-ps-region-store.m

Modified: cfe/trunk/lib/Checker/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/RegionStore.cpp?rev=96067&r1=96066&r2=96067&view=diff

==============================================================================
--- cfe/trunk/lib/Checker/RegionStore.cpp (original)
+++ cfe/trunk/lib/Checker/RegionStore.cpp Fri Feb 12 19:52:33 2010
@@ -475,17 +475,19 @@
   ClusterMap ClusterM;
   WorkList WL;
   
+  RegionStoreManager &RM;
   StoreManager::InvalidatedSymbols *IS;
   ASTContext &Ctx;
   ValueManager &ValMgr;
   
 public:
-  InvalidateRegionsWorker(StoreManager::InvalidatedSymbols *is,
+  InvalidateRegionsWorker(RegionStoreManager &rm,
+                          StoreManager::InvalidatedSymbols *is,
                           ASTContext &ctx, ValueManager &valMgr)
-    : IS(is), Ctx(ctx), ValMgr(valMgr) {}
+    : RM(rm), IS(is), Ctx(ctx), ValMgr(valMgr) {}
   
-  Store InvalidateRegions(RegionStoreManager &RM, Store store,
-                          const MemRegion * const *I,const MemRegion * const *E,
+  Store InvalidateRegions(Store store, const MemRegion * const *I,
+                          const MemRegion * const *E,
                           const Expr *Ex, unsigned Count);
   
 private:
@@ -529,17 +531,34 @@
 }
 
 void InvalidateRegionsWorker::VisitBinding(SVal V) {
-  if (const MemRegion *R = V.getAsRegion())
-    AddToWorkList(R);
-  
   // A symbol?  Mark it touched by the invalidation.
   if (IS)
     if (SymbolRef Sym = V.getAsSymbol())
       IS->insert(Sym);
-}
   
-Store InvalidateRegionsWorker::InvalidateRegions(RegionStoreManager &RM,
-                                                 Store store,
+  if (const MemRegion *R = V.getAsRegion()) {
+    AddToWorkList(R);
+    return;
+  }
+
+  // Is it a LazyCompoundVal?  All references get invalidated as well.
+  if (const nonloc::LazyCompoundVal *LCS =
+        dyn_cast<nonloc::LazyCompoundVal>(&V)) {
+
+    const MemRegion *LazyR = LCS->getRegion();
+    RegionBindings B = RegionStoreManager::GetRegionBindings(LCS->getStore());
+
+    for (RegionBindings::iterator RI = B.begin(), RE = B.end(); RI != RE; ++RI){
+      const MemRegion *baseR = RI.getKey().getRegion();
+      if (cast<SubRegion>(baseR)->isSubRegionOf(LazyR))
+        VisitBinding(RI.getData());
+    }
+
+    return;
+  }
+}
+
+Store InvalidateRegionsWorker::InvalidateRegions(Store store,
                                                  const MemRegion * const *I,
                                                  const MemRegion * const *E,
                                                  const Expr *Ex, unsigned Count)
@@ -652,8 +671,9 @@
                                             const MemRegion * const *E,
                                             const Expr *Ex, unsigned Count,
                                             InvalidatedSymbols *IS) {
-  InvalidateRegionsWorker W(IS, getContext(), StateMgr.getValueManager());
-  return W.InvalidateRegions(*this, store, I, E, Ex, Count);
+  InvalidateRegionsWorker W(*this, IS, getContext(),
+                            StateMgr.getValueManager());
+  return W.InvalidateRegions(store, I, E, Ex, Count);
 }
   
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.m?rev=96067&r1=96066&r2=96067&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.m (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.m Fri Feb 12 19:52:33 2010
@@ -836,3 +836,34 @@
     return x; // no-warning
 }
 
+//===----------------------------------------------------------------------===//
+// Test invalidation of values in struct literals.
+//===----------------------------------------------------------------------===//
+
+struct s_rev96062 { int *x; int *y; };
+struct s_rev96062_nested { struct s_rev96062 z; };
+
+void test_a_rev96062_aux(struct s_rev96062 *s);
+void test_a_rev96062_aux2(struct s_rev96062_nested *s);
+
+int test_a_rev96062() {
+  int a, b;
+  struct s_rev96062 x = { &a, &b };
+  test_a_rev96062_aux(&x);
+  return a + b; // no-warning
+}
+int test_b_rev96062() {
+  int a, b;
+  struct s_rev96062 x = { &a, &b };
+  struct s_rev96062 z = x;
+  test_a_rev96062_aux(&z);
+  return a + b; // no-warning
+}
+int test_c_rev96062() {
+  int a, b;
+  struct s_rev96062 x = { &a, &b };
+  struct s_rev96062_nested w = { x };
+  struct s_rev96062_nested z = w;
+  test_a_rev96062_aux2(&z);
+  return a + b; // no-warning
+}





More information about the cfe-commits mailing list