From bc678fdf614d2b66a4358f14a0a072f31b559c5c Mon Sep 17 00:00:00 2001 From: Zhongxing Xu Date: Tue, 7 Oct 2008 01:31:04 +0000 Subject: [PATCH] Migrate MemRegionManager from StateManager to StoreManager. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57225 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/Analysis/PathSensitive/GRState.h | 16 +++++------ include/clang/Analysis/PathSensitive/Store.h | 6 ++-- lib/Analysis/BasicStore.cpp | 28 ++++++++++++------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/clang/Analysis/PathSensitive/GRState.h b/include/clang/Analysis/PathSensitive/GRState.h index 992174c2a3..54731b27b8 100644 --- a/include/clang/Analysis/PathSensitive/GRState.h +++ b/include/clang/Analysis/PathSensitive/GRState.h @@ -236,7 +236,6 @@ private: EnvironmentManager EnvMgr; llvm::OwningPtr StMgr; llvm::OwningPtr ConstraintMgr; - MemRegionManager MRMgr; GRState::IntSetTy::Factory ISetFactory; GRState::GenericDataMap::Factory GDMFactory; @@ -283,9 +282,9 @@ private: } // FIXME: Remove when we do lazy initializaton of variable bindings. - const GRState* BindVar(const GRState* St, VarDecl* D, RVal V) { - return SetRVal(St, getLVal(D), V); - } +// const GRState* BindVar(const GRState* St, VarDecl* D, RVal V) { +// return SetRVal(St, getLVal(D), V); +// } public: @@ -297,7 +296,6 @@ public: ConstraintManagerCreator CreateConstraintManager, llvm::BumpPtrAllocator& alloc, CFG& c, LiveVariables& L) : EnvMgr(alloc), - MRMgr(alloc), ISetFactory(alloc), GDMFactory(alloc), BasicVals(Ctx, alloc), @@ -319,7 +317,7 @@ public: SymbolManager& getSymbolManager() { return SymMgr; } LiveVariables& getLiveVariables() { return Liveness; } llvm::BumpPtrAllocator& getAllocator() { return Alloc; } - MemRegionManager& getRegionManager() { return MRMgr; } + MemRegionManager& getRegionManager() { return StMgr->getRegionManager(); } typedef StoreManager::DeadSymbolsTy DeadSymbolsTy; @@ -340,11 +338,11 @@ public: // Utility methods for getting regions. VarRegion* getRegion(const VarDecl* D) { - return MRMgr.getVarRegion(D); + return getRegionManager().getVarRegion(D); } - lval::MemRegionVal getLVal(const VarDecl* D) { - return lval::MemRegionVal(getRegion(D)); + LVal getLVal(const VarDecl* D) { + return StMgr->getLVal(D); } // Methods that query & manipulate the Environment. diff --git a/include/clang/Analysis/PathSensitive/Store.h b/include/clang/Analysis/PathSensitive/Store.h index 495244d577..060bce5992 100644 --- a/include/clang/Analysis/PathSensitive/Store.h +++ b/include/clang/Analysis/PathSensitive/Store.h @@ -29,7 +29,8 @@ class GRStateManager; class LiveVariables; class Stmt; class MemRegion; - +class MemRegionManager; + class StoreManager { public: typedef llvm::SmallSet LiveSymbolsTy; @@ -40,7 +41,8 @@ public: virtual Store SetRVal(Store St, LVal LV, RVal V) = 0; virtual Store Remove(Store St, LVal LV) = 0; virtual Store getInitialStore() = 0; - + virtual MemRegionManager& getRegionManager() = 0; + virtual LVal getLVal(const VarDecl* VD) = 0; virtual Store RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live, llvm::SmallVectorImpl& RegionRoots, diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index 3be8a112d2..47e2905e02 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -26,9 +26,11 @@ namespace { class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager { VarBindingsTy::Factory VBFactory; GRStateManager& StateMgr; + MemRegionManager MRMgr; public: - BasicStoreManager(GRStateManager& mgr) : StateMgr(mgr) {} + BasicStoreManager(GRStateManager& mgr) + : StateMgr(mgr), MRMgr(StateMgr.getAllocator()) {} virtual ~BasicStoreManager() {} @@ -37,6 +39,12 @@ public: virtual Store Remove(Store St, LVal LV); virtual Store getInitialStore(); + + virtual MemRegionManager& getRegionManager() { return MRMgr; } + + virtual LVal getLVal(const VarDecl* VD) { + return lval::MemRegionVal(MRMgr.getVarRegion(VD)); + } virtual Store RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live, @@ -55,7 +63,7 @@ public: virtual void print(Store store, std::ostream& Out, const char* nl, const char *sep); - + }; } // end anonymous namespace @@ -164,7 +172,7 @@ BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, // Iterate over the variable bindings. for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) if (Liveness.isLive(Loc, I.getKey())) { - RegionRoots.push_back(StateMgr.getRegion(I.getKey())); + RegionRoots.push_back(MRMgr.getVarRegion(I.getKey())); RVal X = I.getData(); for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) @@ -198,7 +206,7 @@ BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, // Remove dead variable bindings. for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) { - const VarRegion* R = cast(StateMgr.getRegion(I.getKey())); + const VarRegion* R = cast(MRMgr.getVarRegion(I.getKey())); if (!Marked.count(R)) { store = Remove(store, lval::MemRegionVal(R)); @@ -240,7 +248,7 @@ Store BasicStoreManager::getInitialStore() { ? RVal::GetSymbolValue(StateMgr.getSymbolManager(), VD) : UndefinedVal(); - St = SetRVal(St, StateMgr.getLVal(VD), X); + St = SetRVal(St, lval::MemRegionVal(MRMgr.getVarRegion(VD)), X); } } } @@ -280,16 +288,16 @@ Store BasicStoreManager::AddDecl(Store store, if (!Ex) { QualType T = VD->getType(); if (LVal::IsLValType(T)) - store = SetRVal(store, StateMgr.getLVal(VD), + store = SetRVal(store, getLVal(VD), lval::ConcreteInt(BasicVals.getValue(0, T))); else if (T->isIntegerType()) - store = SetRVal(store, StateMgr.getLVal(VD), + store = SetRVal(store, getLVal(VD), nonlval::ConcreteInt(BasicVals.getValue(0, T))); else { // assert(0 && "ignore other types of variables"); } } else { - store = SetRVal(store, StateMgr.getLVal(VD), InitVal); + store = SetRVal(store, getLVal(VD), InitVal); } } } else { @@ -307,7 +315,7 @@ Store BasicStoreManager::AddDecl(Store store, : cast(nonlval::SymbolVal(Sym)); } - store = SetRVal(store, StateMgr.getLVal(VD), V); + store = SetRVal(store, getLVal(VD), V); } } @@ -337,7 +345,7 @@ void BasicStoreManager::iterBindings(Store store, BindingsHandler& f) { for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) { - f.HandleBinding(*this, store, StateMgr.getRegion(I.getKey()),I.getData()); + f.HandleBinding(*this, store, MRMgr.getVarRegion(I.getKey()),I.getData()); } } -- 2.40.0