Remove extents of dead symbolic regions when RemoveDeadBindings.
This requires creating new persistent states due to the nature of GDM.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104668 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Checker/BasicStore.cpp b/lib/Checker/BasicStore.cpp
index 34470af..5be5ca6 100644
--- a/lib/Checker/BasicStore.cpp
+++ b/lib/Checker/BasicStore.cpp
@@ -72,7 +72,7 @@
 
   /// RemoveDeadBindings - Scans a BasicStore of 'state' for dead values.
   ///  It updatees the GRState object in place with the values removed.
-  Store RemoveDeadBindings(Store store, Stmt* Loc, 
+  const GRState *RemoveDeadBindings(GRState &state, Stmt* Loc, 
                            const StackFrameContext *LCtx,
                            SymbolReaper& SymReaper,
                           llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
@@ -251,11 +251,12 @@
   }
 }
 
-Store BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc,
+const GRState *BasicStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc,
                                             const StackFrameContext *LCtx,
                                             SymbolReaper& SymReaper,
                            llvm::SmallVectorImpl<const MemRegion*>& RegionRoots)
 {
+  Store store = state.getStore();
   BindingsTy B = GetBindings(store);
   typedef SVal::symbol_iterator symbol_iterator;
 
@@ -329,7 +330,8 @@
     }
   }
 
-  return store;
+  state.setStore(store);
+  return StateMgr.getPersistentState(state);
 }
 
 Store BasicStoreManager::scanForIvars(Stmt *B, const Decl* SelfDecl,
diff --git a/lib/Checker/FlatStore.cpp b/lib/Checker/FlatStore.cpp
index 2af9ffa..7f1c579 100644
--- a/lib/Checker/FlatStore.cpp
+++ b/lib/Checker/FlatStore.cpp
@@ -44,11 +44,11 @@
   }
 
   SVal ArrayToPointer(Loc Array);
-  Store RemoveDeadBindings(Store store, Stmt* Loc, 
+  const GRState *RemoveDeadBindings(GRState &state, Stmt* Loc, 
                            const StackFrameContext *LCtx,
                            SymbolReaper& SymReaper,
                          llvm::SmallVectorImpl<const MemRegion*>& RegionRoots){
-    return store;
+    return StateMgr.getPersistentState(state);
   }
 
   Store BindDecl(Store store, const VarRegion *VR, SVal initVal);
diff --git a/lib/Checker/GRState.cpp b/lib/Checker/GRState.cpp
index f68e10b..b16e922 100644
--- a/lib/Checker/GRState.cpp
+++ b/lib/Checker/GRState.cpp
@@ -51,11 +51,10 @@
                                            state, RegionRoots);
 
   // Clean up the store.
-  NewState.St = StoreMgr->RemoveDeadBindings(NewState.St, Loc, LCtx, SymReaper, 
-                                             RegionRoots);
+  const GRState *s = StoreMgr->RemoveDeadBindings(NewState, Loc, LCtx, 
+                                                  SymReaper, RegionRoots);
 
-  return ConstraintMgr->RemoveDeadBindings(getPersistentState(NewState),
-                                           SymReaper);
+  return ConstraintMgr->RemoveDeadBindings(s, SymReaper);
 }
 
 const GRState *GRState::unbindLoc(Loc LV) const {
diff --git a/lib/Checker/RegionStore.cpp b/lib/Checker/RegionStore.cpp
index 0e4c443..f0b61a4 100644
--- a/lib/Checker/RegionStore.cpp
+++ b/lib/Checker/RegionStore.cpp
@@ -352,9 +352,9 @@
 
   /// RemoveDeadBindings - Scans the RegionStore of 'state' for dead values.
   ///  It returns a new Store with these values removed.
-  Store RemoveDeadBindings(Store store, Stmt* Loc, 
-                           const StackFrameContext *LCtx,
-                           SymbolReaper& SymReaper,
+  const GRState *RemoveDeadBindings(GRState &state, Stmt* Loc, 
+                                    const StackFrameContext *LCtx,
+                                    SymbolReaper& SymReaper,
                           llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
 
   const GRState *EnterStackFrame(const GRState *state,
@@ -1822,12 +1822,12 @@
   return changed;
 }
 
-Store RegionStoreManager::RemoveDeadBindings(Store store, Stmt* Loc,
+const GRState *RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc,
                                              const StackFrameContext *LCtx,
                                              SymbolReaper& SymReaper,
                            llvm::SmallVectorImpl<const MemRegion*>& RegionRoots)
 {
-  RegionBindings B = GetRegionBindings(store);
+  RegionBindings B = GetRegionBindings(state.getStore());
   RemoveDeadBindingsWorker W(*this, StateMgr, B, SymReaper, Loc, LCtx);
   W.GenerateClusters();
 
@@ -1860,8 +1860,16 @@
     for (; SI != SE; ++SI)
       SymReaper.maybeDead(*SI);
   }
-
-  return B.getRoot();
+  state.setStore(B.getRoot());
+  const GRState *s = StateMgr.getPersistentState(state);
+  // Remove the extents of dead symbolic regions.
+  llvm::ImmutableMap<const MemRegion*,SVal> Extents =state.get<RegionExtents>();
+  for (llvm::ImmutableMap<const MemRegion *, SVal>::iterator I=Extents.begin(),
+         E = Extents.end(); I != E; ++I) {
+    if (!W.isVisited(I->first))
+      s = s->remove<RegionExtents>(I->first);
+  }
+  return s;
 }