When analyzing a function, eagerly create symbolic values for all

globals/parameters at the beginning of the analysis.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47664 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2008-02-27 06:47:26 +00:00
Родитель 0f5f0595d6
Коммит 0793263741
4 изменённых файлов: 32 добавлений и 41 удалений

Просмотреть файл

@ -26,6 +26,30 @@ using llvm::dyn_cast;
using llvm::cast;
using llvm::APSInt;
GRExprEngine::StateTy 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();
ValueStateImpl StateImpl = *StateMgr.getInitialState().getImpl();
for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
VarDecl* VD = cast<VarDecl>(const_cast<ScopedDecl*>(I->first));
if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) {
RVal X = RVal::GetSymbolValue(SymMgr, VD);
StateMgr.BindVar(StateImpl, VD, X);
}
}
return StateMgr.getPersistentState(StateImpl);
}
GRExprEngine::StateTy
GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal& V) {
@ -455,22 +479,6 @@ void GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred,
void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){
if (VarDecl* VD = dyn_cast<VarDecl>(D->getDecl()))
if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) {
StateTy StOld = Pred->getState();
StateTy St = Symbolicate(StOld, VD);
if (!(St == StOld)) {
if (D != CurrentStmt)
Nodify(Dst, D, Pred, St);
else
Nodify(Dst, D, Pred, SetRVal(St, D, GetRVal(St, D)));
return;
}
}
if (D != CurrentStmt) {
Dst.Add(Pred); // No-op. Simply propagate the current state unchanged.
return;
@ -884,20 +892,7 @@ void GRExprEngine::VisitLVal(Expr* Ex, NodeTy* Pred, NodeSet& Dst) {
Ex = Ex->IgnoreParens();
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(Ex)) {
if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl()))
if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) {
StateTy StOld = Pred->getState();
StateTy St = Symbolicate(StOld, VD);
if (!(St == StOld)) {
Nodify(Dst, Ex, Pred, St);
return;
}
}
if (isa<DeclRefExpr>(Ex)) {
Dst.Add(Pred);
return;
}

Просмотреть файл

@ -437,10 +437,14 @@ ValueState ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) {
}
}
void ValueStateManager::BindVar(ValueStateImpl& StImpl, VarDecl* D, RVal V) {
StImpl.VarBindings = VBFactory.Add(StImpl.VarBindings, D, V);
}
ValueState ValueStateManager::BindVar(ValueState St, VarDecl* D, RVal V) {
// Create a new state with the old binding removed.
ValueStateImpl NewSt = *St;
ValueStateImpl NewSt = *St;
NewSt.VarBindings = VBFactory.Add(NewSt.VarBindings, D, V);
// Get the persistent copy.

Просмотреть файл

@ -150,7 +150,7 @@ public:
/// getInitialState - Return the initial state used for the root vertex
/// in the ExplodedGraph.
StateTy getInitialState() { return StateMgr.getInitialState(); }
StateTy getInitialState();
bool isUninitControlFlow(const NodeTy* N) const {
return N->isSink() && UninitBranches.count(const_cast<NodeTy*>(N)) != 0;
@ -252,15 +252,6 @@ protected:
return StateMgr.GetLVal(St, Ex);
}
StateTy Symbolicate(StateTy St, VarDecl* VD) {
lval::DeclVal X(VD);
if (GetRVal(St, X).isUnknown()) {
return SetRVal(St, lval::DeclVal(VD), RVal::GetSymbolValue(SymMgr, VD));
}
else return St;
}
inline NonLVal MakeConstantVal(uint64_t X, Expr* Ex) {
return NonLVal::MakeVal(ValMgr, X, Ex->getType(), Ex->getLocStart());
}

Просмотреть файл

@ -266,6 +266,7 @@ public:
RVal GetBlkExprRVal(ValueState St, Expr* Ex);
void BindVar(ValueStateImpl& StImpl, VarDecl* D, RVal V);
ValueState getPersistentState(const ValueStateImpl& Impl);
ValueState AddEQ(ValueState St, SymbolID sym, const llvm::APSInt& V);