[cfe-commits] r54993 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRState.h include/clang/Analysis/PathSensitive/Store.h lib/Analysis/BasicStore.cpp lib/Analysis/GRExprEngine.cpp lib/Analysis/GRState.cpp
Ted Kremenek
kremenek at apple.com
Tue Aug 19 09:51:48 PDT 2008
Author: kremenek
Date: Tue Aug 19 11:51:45 2008
New Revision: 54993
URL: http://llvm.org/viewvc/llvm-project?rev=54993&view=rev
Log:
Patch by Zhongxing Xu!
This patch extends BasicStoreManager::getInitialStore() to include code that symbolicates input variables.
It also removes redundant handling of ImplicitParamDecl, since it is a subclass of VarDecl.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
cfe/trunk/lib/Analysis/BasicStore.cpp
cfe/trunk/lib/Analysis/GRExprEngine.cpp
cfe/trunk/lib/Analysis/GRState.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h?rev=54993&r1=54992&r2=54993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Tue Aug 19 11:51:45 2008
@@ -270,7 +270,11 @@
/// TF - Object that represents a bundle of transfer functions
/// for manipulating and creating RVals.
GRTransferFuncs* TF;
-
+
+ /// Liveness - live-variables information of the ValueDecl* and block-level
+ /// Expr* in the CFG. Used to get initial store and prune out dead state.
+ LiveVariables& Liveness;
+
private:
Environment RemoveBlkExpr(const Environment& Env, Expr* E) {
@@ -284,7 +288,7 @@
public:
GRStateManager(ASTContext& Ctx, StoreManager* stmgr,
- llvm::BumpPtrAllocator& alloc, CFG& c)
+ llvm::BumpPtrAllocator& alloc, CFG& c, LiveVariables& L)
: EnvMgr(alloc),
StMgr(stmgr),
ISetFactory(alloc),
@@ -292,7 +296,8 @@
BasicVals(Ctx, alloc),
SymMgr(alloc),
Alloc(alloc),
- cfg(c) {}
+ cfg(c),
+ Liveness(L) {}
~GRStateManager();
@@ -301,7 +306,8 @@
BasicValueFactory& getBasicVals() { return BasicVals; }
const BasicValueFactory& getBasicVals() const { return BasicVals; }
SymbolManager& getSymbolManager() { return SymMgr; }
-
+ LiveVariables& getLiveVariables() { return Liveness; }
+
typedef StoreManager::DeadSymbolsTy DeadSymbolsTy;
const GRState* RemoveDeadBindings(const GRState* St, Stmt* Loc,
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Store.h?rev=54993&r1=54992&r2=54993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Store.h Tue Aug 19 11:51:45 2008
@@ -23,6 +23,7 @@
namespace clang {
typedef const void* Store;
+class GRStateManager;
class LiveVariables;
class Stmt;
@@ -36,7 +37,7 @@
virtual RVal GetRVal(Store St, LVal LV, QualType T = QualType()) = 0;
virtual Store SetRVal(Store St, LVal LV, RVal V) = 0;
virtual Store Remove(Store St, LVal LV) = 0;
- virtual Store getInitialStore() = 0;
+ virtual Store getInitialStore(GRStateManager& StateMgr) = 0;
virtual Store RemoveDeadBindings(Store store, Stmt* Loc,
const LiveVariables& Live,
Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=54993&r1=54992&r2=54993&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Tue Aug 19 11:51:45 2008
@@ -13,6 +13,7 @@
#include "clang/Analysis/Analyses/LiveVariables.h"
#include "clang/Analysis/PathSensitive/BasicStore.h"
+#include "clang/Analysis/PathSensitive/GRState.h"
#include "llvm/ADT/ImmutableMap.h"
#include "llvm/Support/Compiler.h"
@@ -32,9 +33,7 @@
virtual Store SetRVal(Store St, LVal LV, RVal V);
virtual Store Remove(Store St, LVal LV);
- virtual Store getInitialStore() {
- return VBFactory.GetEmptyMap().getRoot();
- }
+ virtual Store getInitialStore(GRStateManager& StateMgr);
virtual Store RemoveDeadBindings(Store store, Stmt* Loc,
const LiveVariables& Live,
@@ -200,3 +199,38 @@
return store;
}
+
+Store BasicStoreManager::getInitialStore(GRStateManager& StateMgr) {
+ // 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();
+
+ Store St = VBFactory.GetEmptyMap().getRoot();
+
+ for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
+ ScopedDecl* SD = const_cast<ScopedDecl*>(I->first);
+
+ if (VarDecl* VD = dyn_cast<VarDecl>(SD)) {
+ // Punt on static variables for now.
+ if (VD->getStorageClass() == VarDecl::Static)
+ continue;
+
+ // Only handle pointers and integers for now.
+ QualType T = VD->getType();
+ if (LVal::IsLValType(T) || T->isIntegerType()) {
+ // Initialize globals and parameters to symbolic values.
+ // Initialize local variables to undefined.
+ RVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
+ isa<ImplicitParamDecl>(VD))
+ ? RVal::GetSymbolValue(StateMgr.getSymbolManager(), VD)
+ : UndefinedVal();
+
+ St = SetRVal(St, lval::DeclVal(VD), X);
+ }
+ }
+ }
+ return St;
+}
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=54993&r1=54992&r2=54993&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Tue Aug 19 11:51:45 2008
@@ -121,7 +121,7 @@
Liveness(L),
Builder(NULL),
StateMgr(G.getContext(), CreateBasicStoreManager(G.getAllocator()),
- G.getAllocator(), G.getCFG()),
+ G.getAllocator(), G.getCFG(), L),
SymMgr(StateMgr.getSymbolManager()),
CurrentStmt(NULL),
NSExceptionII(NULL), NSExceptionInstanceRaiseSelectors(NULL),
@@ -189,47 +189,7 @@
}
const GRState* GRExprEngine::getInitialState() {
-
- // 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 = Liveness.getAnalysisData();
-
- GRState StateImpl = *StateMgr.getInitialState();
-
- for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
-
- ScopedDecl *SD = const_cast<ScopedDecl*>(I->first);
- if (VarDecl* VD = dyn_cast<VarDecl>(SD)) {
- // Punt on static variables for now.
- if (VD->getStorageClass() == VarDecl::Static)
- continue;
-
- // Only handle pointers and integers for now.
- QualType T = VD->getType();
- if (!(LVal::IsLValType(T) || T->isIntegerType()))
- continue;
-
- // Initialize globals and parameters to symbolic values.
- // Initialize local variables to undefined.
- RVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
- isa<ImplicitParamDecl>(VD))
- ? RVal::GetSymbolValue(SymMgr, VD)
- : UndefinedVal();
-
- StateMgr.SetRVal(StateImpl, lval::DeclVal(VD), X);
-
- } else if (ImplicitParamDecl *IPD = dyn_cast<ImplicitParamDecl>(SD)) {
- RVal X = RVal::GetSymbolValue(SymMgr, IPD);
- StateMgr.SetRVal(StateImpl, lval::DeclVal(IPD), X);
- }
-
-
- }
-
- return StateMgr.getPersistentState(StateImpl);
+ return StateMgr.getInitialState();
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Analysis/GRState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRState.cpp?rev=54993&r1=54992&r2=54993&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Tue Aug 19 11:51:45 2008
@@ -211,9 +211,10 @@
const GRState* GRStateManager::getInitialState() {
- GRState StateImpl(EnvMgr.getInitialEnvironment(), StMgr->getInitialStore(),
+ GRState StateImpl(EnvMgr.getInitialEnvironment(),
+ StMgr->getInitialStore(*this),
GDMFactory.GetEmptyMap());
-
+
return getPersistentState(StateImpl);
}
More information about the cfe-commits
mailing list