diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-08-19 16:51:45 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-08-19 16:51:45 +0000 |
commit | caa3724b1d525a888982f94a6ae2b527eb3bca7d (patch) | |
tree | fad69505b5fcf075b6ddabee24e00cb93428420e /lib/Analysis/BasicStore.cpp | |
parent | c7089f1be946f3ca6e59596f0e0f92d96136e4c8 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54993 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BasicStore.cpp')
-rw-r--r-- | lib/Analysis/BasicStore.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index 64a230975f..15284567e6 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -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 @@ public: 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 @@ Store BasicStoreManager::RemoveDeadBindings(Store store, 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; +} |