From: Zhongxing Xu Date: Mon, 17 Aug 2009 06:19:58 +0000 (+0000) Subject: To make the analysis independent on the locally stored liveness and cfg X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17fd8632dcda97022a51effc24060eacdad9dbe0;p=clang To make the analysis independent on the locally stored liveness and cfg of GRStateManager and GRExprEngine, pass the initial location context to the getInitialState() method. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79228 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/AnalysisContext.h b/include/clang/Analysis/PathSensitive/AnalysisContext.h index 7141f56d11..e7ef89ae69 100644 --- a/include/clang/Analysis/PathSensitive/AnalysisContext.h +++ b/include/clang/Analysis/PathSensitive/AnalysisContext.h @@ -79,6 +79,10 @@ public: LocationContext *getParent() const { return Parent; } + LiveVariables *getLiveVariables() const { + return getAnalysisContext()->getLiveVariables(); + } + void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Kind, Ctx, Parent); } diff --git a/include/clang/Analysis/PathSensitive/GRCoreEngine.h b/include/clang/Analysis/PathSensitive/GRCoreEngine.h index 29336a195a..8d93963e75 100644 --- a/include/clang/Analysis/PathSensitive/GRCoreEngine.h +++ b/include/clang/Analysis/PathSensitive/GRCoreEngine.h @@ -69,8 +69,8 @@ class GRCoreEngine { ExplodedNode* Pred); /// Get the initial state from the subengine. - const GRState* getInitialState() { - return SubEngine.getInitialState(); + const GRState* getInitialState(const LocationContext *InitLoc) { + return SubEngine.getInitialState(InitLoc); } void ProcessEndPath(GREndPathNodeBuilder& Builder); diff --git a/include/clang/Analysis/PathSensitive/GRExprEngine.h b/include/clang/Analysis/PathSensitive/GRExprEngine.h index dcf4e56d11..a651f95b90 100644 --- a/include/clang/Analysis/PathSensitive/GRExprEngine.h +++ b/include/clang/Analysis/PathSensitive/GRExprEngine.h @@ -246,7 +246,7 @@ public: /// getInitialState - Return the initial state used for the root vertex /// in the ExplodedGraph. - const GRState* getInitialState(); + const GRState* getInitialState(const LocationContext *InitLoc); ExplodedGraph& getGraph() { return G; } const ExplodedGraph& getGraph() const { return G; } diff --git a/include/clang/Analysis/PathSensitive/GRState.h b/include/clang/Analysis/PathSensitive/GRState.h index c31e1fc608..6439043aa9 100644 --- a/include/clang/Analysis/PathSensitive/GRState.h +++ b/include/clang/Analysis/PathSensitive/GRState.h @@ -454,7 +454,7 @@ public: ~GRStateManager(); - const GRState *getInitialState(); + const GRState *getInitialState(const LocationContext *InitLoc); ASTContext &getContext() { return ValueMgr.getContext(); } const ASTContext &getContext() const { return ValueMgr.getContext(); } diff --git a/include/clang/Analysis/PathSensitive/GRSubEngine.h b/include/clang/Analysis/PathSensitive/GRSubEngine.h index caf88a960a..f4636095ad 100644 --- a/include/clang/Analysis/PathSensitive/GRSubEngine.h +++ b/include/clang/Analysis/PathSensitive/GRSubEngine.h @@ -25,12 +25,13 @@ class GRBranchNodeBuilder; class GRIndirectGotoNodeBuilder; class GRSwitchNodeBuilder; class GREndPathNodeBuilder; +class LocationContext; class GRSubEngine { public: virtual ~GRSubEngine() {} - virtual const GRState* getInitialState() = 0; + virtual const GRState* getInitialState(const LocationContext *InitLoc) = 0; virtual GRStateManager& getStateManager() = 0; diff --git a/include/clang/Analysis/PathSensitive/Store.h b/include/clang/Analysis/PathSensitive/Store.h index fcc5e54cf7..a9fbcc55d5 100644 --- a/include/clang/Analysis/PathSensitive/Store.h +++ b/include/clang/Analysis/PathSensitive/Store.h @@ -77,7 +77,7 @@ public: /// getInitialStore - Returns the initial "empty" store representing the /// value bindings upon entry to an analyzed function. - virtual Store getInitialStore() = 0; + virtual Store getInitialStore(const LocationContext *InitLoc) = 0; /// getRegionManager - Returns the internal RegionManager object that is /// used to query and manipulate MemRegion objects. diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index b044d400ae..aed5bdc66b 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -13,6 +13,7 @@ #include "clang/AST/ExprObjC.h" #include "clang/Analysis/Analyses/LiveVariables.h" +#include "clang/Analysis/PathSensitive/AnalysisContext.h" #include "clang/Analysis/PathSensitive/GRState.h" #include "llvm/ADT/ImmutableMap.h" #include "llvm/Support/Compiler.h" @@ -61,7 +62,7 @@ public: Store BindInternal(Store St, Loc loc, SVal V); Store Remove(Store St, Loc loc); - Store getInitialStore(); + Store getInitialStore(const LocationContext *InitLoc); // FIXME: Investigate what is using this. This method should be removed. virtual Loc getLoc(const VarDecl* VD) { @@ -488,12 +489,12 @@ Store BasicStoreManager::scanForIvars(Stmt *B, const Decl* SelfDecl, Store St) { return St; } -Store BasicStoreManager::getInitialStore() { +Store BasicStoreManager::getInitialStore(const LocationContext *InitLoc) { // The LiveVariables information already has a compilation of all VarDecls // used in the function. Iterate through this set, and "symbolicate" // any VarDecl whose value originally comes from outside the function. typedef LiveVariables::AnalysisDataTy LVDataTy; - LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData(); + LVDataTy& D = InitLoc->getLiveVariables()->getAnalysisData(); Store St = VBFactory.GetEmptyMap().getRoot(); for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) { diff --git a/lib/Analysis/GRCoreEngine.cpp b/lib/Analysis/GRCoreEngine.cpp index cd20e3ca66..3ff27fc498 100644 --- a/lib/Analysis/GRCoreEngine.cpp +++ b/lib/Analysis/GRCoreEngine.cpp @@ -170,7 +170,7 @@ bool GRCoreEngine::ExecuteWorkList(const LocationContext *L, unsigned Steps) { WList->setBlockCounter(BCounterFactory.GetEmptyCounter()); // Generate the root. - GenerateNode(StartLoc, getInitialState(), 0); + GenerateNode(StartLoc, getInitialState(L), 0); } while (Steps && WList->hasWork()) { diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 849dd354bb..740ad8a6b3 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -202,8 +202,8 @@ void GRExprEngine::AddCheck(GRSimpleAPICheck *A) { ((MappedBatchAuditor*) BatchAuditor.get())->AddCheck(A); } -const GRState* GRExprEngine::getInitialState() { - const GRState *state = StateMgr.getInitialState(); +const GRState* GRExprEngine::getInitialState(const LocationContext *InitLoc) { + const GRState *state = StateMgr.getInitialState(InitLoc); // Precondition: the first argument of 'main' is an integer guaranteed // to be > 0. diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp index dc7c799288..828ea26eea 100644 --- a/lib/Analysis/GRState.cpp +++ b/lib/Analysis/GRState.cpp @@ -115,12 +115,12 @@ const GRState *GRState::bindExpr(const Stmt* Ex, SVal V, return bindExpr(Ex, V, isBlkExpr, Invalidate); } -const GRState* GRStateManager::getInitialState() { - GRState StateImpl(this, EnvMgr.getInitialEnvironment(), - StoreMgr->getInitialStore(), - GDMFactory.GetEmptyMap()); +const GRState* GRStateManager::getInitialState(const LocationContext *InitLoc) { + GRState State(this, EnvMgr.getInitialEnvironment(), + StoreMgr->getInitialStore(InitLoc), + GDMFactory.GetEmptyMap()); - return getPersistentState(StateImpl); + return getPersistentState(State); } const GRState* GRStateManager::getPersistentState(GRState& State) { diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 48e6de7cd8..8efa0cc001 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -231,7 +231,9 @@ public: SVal EvalBinOp(const GRState *state, BinaryOperator::Opcode Op,Loc L, NonLoc R, QualType resultTy); - Store getInitialStore() { return RBFactory.GetEmptyMap().getRoot(); } + Store getInitialStore(const LocationContext *InitLoc) { + return RBFactory.GetEmptyMap().getRoot(); + } /// getSelfRegion - Returns the region for the 'self' (Objective-C) or /// 'this' object (C++). When used when analyzing a normal function this