From: Ted Kremenek Date: Sat, 19 Feb 2011 03:56:19 +0000 (+0000) Subject: Change 'StoreRef' back to 'Store' in GRState, shrinking the size of GRState back... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09fe4a55248bd28a950ec4ba19900e5892be42f6;p=clang Change 'StoreRef' back to 'Store' in GRState, shrinking the size of GRState back by one pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126020 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h b/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h index 92156d508f..37694da657 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/GRState.h @@ -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); } diff --git a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp index 3ce50d6539..2a8364d411 100644 --- a/lib/StaticAnalyzer/Core/ExplodedGraph.cpp +++ b/lib/StaticAnalyzer/Core/ExplodedGraph.cpp @@ -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; diff --git a/lib/StaticAnalyzer/Core/GRState.cpp b/lib/StaticAnalyzer/Core/GRState.cpp index 7defecb366..7b216775b8 100644 --- a/lib/StaticAnalyzer/Core/GRState.cpp +++ b/lib/StaticAnalyzer/Core/GRState.cpp @@ -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::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. //===----------------------------------------------------------------------===//