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) {
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;
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;
}
}
}
+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.
/// 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;
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());
}