]> granicus.if.org Git - clang/commitdiff
Change 'StoreRef' back to 'Store' in GRState, shrinking the size of GRState back...
authorTed Kremenek <kremenek@apple.com>
Sat, 19 Feb 2011 03:56:19 +0000 (03:56 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 19 Feb 2011 03:56:19 +0000 (03:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126020 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h
lib/StaticAnalyzer/Core/ExplodedGraph.cpp
lib/StaticAnalyzer/Core/GRState.cpp

index 92156d508fb811313d4ad79628fa06ecf1971206..37694da6573c5ce3e343d83085fe4439621bf2a1 100644 (file)
@@ -83,7 +83,7 @@ private:
 
   GRStateManager *stateMgr;
   Environment Env;           // Maps a Stmt to its current SVal.
-  StoreRef St;               // Maps a location to its current value.
+  Store store;               // Maps a location to its current value.
   GenericDataMap   GDM;      // Custom data stored by a client of this class.
   unsigned refCount;
 
@@ -91,26 +91,19 @@ private:
   ///  state with the exception of using the specified Store.
   const GRState *makeWithStore(const StoreRef &store) const;
 
+  void setStore(const StoreRef &storeRef);
+
 public:
 
   /// This ctor is used when creating the first GRState object.
   GRState(GRStateManager *mgr, const Environment& env,
-          StoreRef st, GenericDataMap gdm)
-    : stateMgr(mgr),
-      Env(env),
-      St(st),
-      GDM(gdm),
-      refCount(0) {}
-
+          StoreRef st, GenericDataMap gdm);
+    
   /// Copy ctor - We must explicitly define this or else the "Next" ptr
   ///  in FoldingSetNode will also get copied.
-  GRState(const GRState& RHS)
-    : llvm::FoldingSetNode(),
-      stateMgr(RHS.stateMgr),
-      Env(RHS.Env),
-      St(RHS.St),
-      GDM(RHS.GDM),
-      refCount(0) {}
+  GRState(const GRState& RHS);
+  
+  ~GRState();
 
   /// Return the GRStateManager associated with this state.
   GRStateManager &getStateManager() const { return *stateMgr; }
@@ -122,13 +115,10 @@ public:
   ///  The environment is the mapping from expressions to values.
   const Environment& getEnvironment() const { return Env; }
 
-
-  /// getStore - Return the store associated with this state.  The store
+  /// Return the store associated with this state.  The store
   ///  is a mapping from locations to values.
-  Store getStore() const { return St.getStore(); }
-#if 0
-  void setStore(Store s) { St = s; }
-#endif
+  Store getStore() const { return store; }
+
   
   /// getGDM - Return the generic data map associated with this state.
   GenericDataMap getGDM() const { return GDM; }
@@ -140,7 +130,7 @@ public:
   ///  have the same Environment, Store, and GenericDataMap.
   static void Profile(llvm::FoldingSetNodeID& ID, const GRState* V) {
     V->Env.Profile(ID);
-    ID.AddPointer(V->St.getStore());
+    ID.AddPointer(V->store);
     V->GDM.Profile(ID);
   }
 
index 3ce50d65391926ce507cafa20d7a31695dd59ca1..2a8364d4117f416b3445e68f7bc2f519083cbf7b 100644 (file)
@@ -105,7 +105,7 @@ void ExplodedGraph::reclaimRecentlyAllocatedNodes() {
     // Conditions 5, 6, and 7.
     const GRState *state = node->getState();
     const GRState *pred_state = pred->getState();    
-    if (state->St != pred_state->St || state->GDM != pred_state->GDM ||
+    if (state->store != pred_state->store || state->GDM != pred_state->GDM ||
         progPoint.getLocationContext() != pred->getLocationContext())
       continue;
 
index 7defecb36637f351416d01fa3b0f11abae84646e..7b216775b8e66239454bfbc2a3ec71be4143d363 100644 (file)
@@ -25,6 +25,31 @@ using namespace ento;
 // FIXME: Move this elsewhere.
 ConstraintManager::~ConstraintManager() {}
 
+GRState::GRState(GRStateManager *mgr, const Environment& env,
+                 StoreRef st, GenericDataMap gdm)
+  : stateMgr(mgr),
+    Env(env),
+    store(st.getStore()),
+    GDM(gdm),
+    refCount(0) {
+  stateMgr->getStoreManager().incrementReferenceCount(store);
+}
+
+GRState::GRState(const GRState& RHS)
+    : llvm::FoldingSetNode(),
+      stateMgr(RHS.stateMgr),
+      Env(RHS.Env),
+      store(RHS.store),
+      GDM(RHS.GDM),
+      refCount(0) {
+  stateMgr->getStoreManager().incrementReferenceCount(store);
+}
+
+GRState::~GRState() {
+  if (store)
+    stateMgr->getStoreManager().decrementReferenceCount(store);
+}
+
 GRStateManager::~GRStateManager() {
   for (std::vector<GRState::Printer*>::iterator I=Printers.begin(),
         E=Printers.end(); I!=E; ++I)
@@ -53,8 +78,8 @@ GRStateManager::removeDeadBindings(const GRState* state,
                                            state, RegionRoots);
 
   // Clean up the store.
-  NewState.St = StoreMgr->removeDeadBindings(NewState.getStore(), LCtx, 
-                                             SymReaper, RegionRoots);
+  NewState.setStore(StoreMgr->removeDeadBindings(NewState.getStore(), LCtx,
+                                                 SymReaper, RegionRoots));
   state = getPersistentState(NewState);
   return ConstraintMgr->removeDeadBindings(state, SymReaper);
 }
@@ -323,10 +348,19 @@ const GRState* GRStateManager::getPersistentState(GRState& State) {
 
 const GRState* GRState::makeWithStore(const StoreRef &store) const {
   GRState NewSt = *this;
-  NewSt.St = store;
+  NewSt.setStore(store);
   return getStateManager().getPersistentState(NewSt);
 }
 
+void GRState::setStore(const StoreRef &newStore) {
+  Store newStoreStore = newStore.getStore();
+  if (newStoreStore)
+    stateMgr->getStoreManager().incrementReferenceCount(newStoreStore);
+  if (store)
+    stateMgr->getStoreManager().decrementReferenceCount(store);
+  store = newStoreStore;
+}
+
 //===----------------------------------------------------------------------===//
 //  State pretty-printing.
 //===----------------------------------------------------------------------===//