From: Ted Kremenek Date: Thu, 28 Feb 2008 10:21:43 +0000 (+0000) Subject: Merged ValueState and ValueStateImpl into just ValueState, with GRExprEngine::StateTy... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aed9b6ac2ed0013133e4d4aebf2fad2ccd27f3e6;p=clang Merged ValueState and ValueStateImpl into just ValueState, with GRExprEngine::StateTy just becoming ValueState*. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47714 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRExprEngine.cpp b/Analysis/GRExprEngine.cpp index e820cfd903..6106ef39cb 100644 --- a/Analysis/GRExprEngine.cpp +++ b/Analysis/GRExprEngine.cpp @@ -26,7 +26,7 @@ using llvm::dyn_cast; using llvm::cast; using llvm::APSInt; -GRExprEngine::StateTy GRExprEngine::getInitialState() { +ValueState* GRExprEngine::getInitialState() { // The LiveVariables information already has a compilation of all VarDecls // used in the function. Iterate through this set, and "symbolicate" @@ -35,7 +35,7 @@ GRExprEngine::StateTy GRExprEngine::getInitialState() { typedef LiveVariables::AnalysisDataTy LVDataTy; LVDataTy& D = Liveness.getAnalysisData(); - ValueStateImpl StateImpl = *StateMgr.getInitialState().getImpl(); + ValueState StateImpl = *StateMgr.getInitialState(); for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) { @@ -50,8 +50,7 @@ GRExprEngine::StateTy GRExprEngine::getInitialState() { return StateMgr.getPersistentState(StateImpl); } -GRExprEngine::StateTy -GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal& V) { +ValueState* GRExprEngine::SetRVal(ValueState* St, Expr* Ex, RVal V) { if (!StateCleaned) { St = RemoveDeadBindings(CurrentStmt, St); @@ -70,9 +69,10 @@ GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal& V) { return StateMgr.SetRVal(St, Ex, V, isBlkExpr, false); } -const GRExprEngine::StateTy::BufferTy& -GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal::BufferTy& RB, - StateTy::BufferTy& RetBuf) { +#if 0 +const ValueState::BufferTy& +GRExprEngine::SetRVal(ValueState* St, Expr* Ex, const RVal::BufferTy& RB, + ValueState::BufferTy& RetBuf) { assert (RetBuf.empty()); @@ -81,9 +81,9 @@ GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal::BufferTy& RB, return RetBuf; } +#endif -GRExprEngine::StateTy -GRExprEngine::SetRVal(StateTy St, const LVal& LV, const RVal& RV) { +ValueState* GRExprEngine::SetRVal(ValueState* St, LVal LV, RVal RV) { if (!StateCleaned) { St = RemoveDeadBindings(CurrentStmt, St); @@ -93,8 +93,8 @@ GRExprEngine::SetRVal(StateTy St, const LVal& LV, const RVal& RV) { return StateMgr.SetRVal(St, LV, RV); } -GRExprEngine::StateTy -GRExprEngine::MarkBranch(StateTy St, Stmt* Terminator, bool branchTaken) { +ValueState* GRExprEngine::MarkBranch(ValueState* St, Stmt* Terminator, + bool branchTaken) { switch (Terminator->getStmtClass()) { default: @@ -151,7 +151,7 @@ void GRExprEngine::ProcessBranch(Expr* Condition, Stmt* Term, BranchNodeBuilder& builder) { // Remove old bindings for subexpressions. - StateTy PrevState = StateMgr.RemoveSubExprBindings(builder.getState()); + ValueState* PrevState = StateMgr.RemoveSubExprBindings(builder.getState()); // Check for NULL conditions; e.g. "for(;;)" if (!Condition) { @@ -204,7 +204,7 @@ void GRExprEngine::ProcessBranch(Expr* Condition, Stmt* Term, bool isFeasible = true; - StateTy St = Assume(PrevState, V, true, isFeasible); + ValueState* St = Assume(PrevState, V, true, isFeasible); if (isFeasible) builder.generateNode(MarkBranch(St, Term, true), true); @@ -224,7 +224,7 @@ void GRExprEngine::ProcessBranch(Expr* Condition, Stmt* Term, bool isFeasible = false; - StateTy St = Assume(PrevState, V, false, isFeasible); + ValueState* St = Assume(PrevState, V, false, isFeasible); if (isFeasible) builder.generateNode(MarkBranch(St, Term, false), false); @@ -239,7 +239,7 @@ void GRExprEngine::ProcessBranch(Expr* Condition, Stmt* Term, /// nodes by processing the 'effects' of a computed goto jump. void GRExprEngine::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) { - StateTy St = builder.getState(); + ValueState* St = builder.getState(); RVal V = GetRVal(St, builder.getTarget()); // Three possibilities: @@ -286,7 +286,7 @@ void GRExprEngine::ProcessSwitch(SwitchNodeBuilder& builder) { typedef SwitchNodeBuilder::iterator iterator; - StateTy St = builder.getState(); + ValueState* St = builder.getState(); Expr* CondE = builder.getCondition(); RVal CondV = GetRVal(St, CondE); @@ -296,7 +296,7 @@ void GRExprEngine::ProcessSwitch(SwitchNodeBuilder& builder) { return; } - StateTy DefaultSt = St; + ValueState* DefaultSt = St; // While most of this can be assumed (such as the signedness), having it // just computed makes sure everything makes the same assumptions end-to-end. @@ -342,7 +342,7 @@ void GRExprEngine::ProcessSwitch(SwitchNodeBuilder& builder) { // Now "assume" that the case matches. bool isFeasible = false; - StateTy StNew = Assume(St, Res, true, isFeasible); + ValueState* StNew = Assume(St, Res, true, isFeasible); if (isFeasible) { builder.generateCaseStmtNode(I, StNew); @@ -382,7 +382,7 @@ void GRExprEngine::VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred, assert (B == CurrentStmt && getCFG().isBlkExpr(B)); - StateTy St = Pred->getState(); + ValueState* St = Pred->getState(); RVal X = GetBlkExprRVal(St, B); assert (X.isUndef()); @@ -410,7 +410,7 @@ void GRExprEngine::VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred, // the payoff is not likely to be large. Instead, we do eager evaluation. bool isFeasible = false; - StateTy NewState = Assume(St, X, true, isFeasible); + ValueState* NewState = Assume(St, X, true, isFeasible); if (isFeasible) Nodify(Dst, B, Pred, SetBlkExprRVal(NewState, B, MakeConstantVal(1U, B))); @@ -446,7 +446,7 @@ void GRExprEngine::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) { // dead mappings removed. if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) { - StateTy St = RemoveDeadBindings(S, StmtEntryNode->getState()); + ValueState* St = RemoveDeadBindings(S, StmtEntryNode->getState()); builder.generateNode(S, St, StmtEntryNode); } @@ -458,7 +458,7 @@ void GRExprEngine::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) { } GRExprEngine::NodeTy* -GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St) { +GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, ValueState* St) { // If the state hasn't changed, don't generate a new node. if (St == Pred->getState()) @@ -470,12 +470,14 @@ GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St) { return N; } +#if 0 void GRExprEngine::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, - const StateTy::BufferTy& SB) { + const ValueState::BufferTy& SB) { - for (StateTy::BufferTy::const_iterator I=SB.begin(), E=SB.end(); I!=E; ++I) + for (ValueState::BufferTy::const_iterator I=SB.begin(), E=SB.end(); I!=E; ++I) Nodify(Dst, S, Pred, *I); } +#endif void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){ @@ -487,7 +489,7 @@ void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){ // If we are here, we are loading the value of the decl and binding // it to the block-level expression. - StateTy St = Pred->getState(); + ValueState* St = Pred->getState(); Nodify(Dst, D, Pred, SetRVal(St, D, GetRVal(St, D))); } @@ -524,7 +526,7 @@ void GRExprEngine::VisitCall(CallExpr* CE, NodeTy* Pred, // Finally, evaluate the function call. for (NodeSet::iterator DI = DstTmp.begin(), DE = DstTmp.end(); DI!=DE; ++DI) { - StateTy St = (*DI)->getState(); + ValueState* St = (*DI)->getState(); RVal L = GetLVal(St, Callee); // Check for undefined control-flow. @@ -589,7 +591,7 @@ void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){ for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1) { NodeTy* N = *I1; - StateTy St = N->getState(); + ValueState* St = N->getState(); RVal V = GetRVal(St, Ex); Nodify(Dst, CastE, N, SetRVal(St, CastE, EvalCast(V, CastE->getType()))); } @@ -598,7 +600,7 @@ void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){ void GRExprEngine::VisitDeclStmt(DeclStmt* DS, GRExprEngine::NodeTy* Pred, GRExprEngine::NodeSet& Dst) { - StateTy St = Pred->getState(); + ValueState* St = Pred->getState(); for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator()) if (const VarDecl* VD = dyn_cast(D)) { @@ -638,7 +640,7 @@ void GRExprEngine::VisitGuardedExpr(Expr* Ex, Expr* L, Expr* R, assert (Ex == CurrentStmt && getCFG().isBlkExpr(Ex)); - StateTy St = Pred->getState(); + ValueState* St = Pred->getState(); RVal X = GetBlkExprRVal(St, Ex); assert (X.isUndef()); @@ -697,7 +699,7 @@ void GRExprEngine::VisitDeref(UnaryOperator* U, NodeTy* Pred, NodeSet& Dst) { for (NodeSet::iterator I = DstTmp.begin(), DE = DstTmp.end(); I != DE; ++I) { NodeTy* N = *I; - StateTy St = N->getState(); + ValueState* St = N->getState(); // FIXME: Bifurcate when dereferencing a symbolic with no constraints? @@ -735,7 +737,7 @@ void GRExprEngine::VisitDeref(UnaryOperator* U, NodeTy* Pred, NodeSet& Dst) { // "Assume" that the pointer is Not-NULL. - StateTy StNotNull = Assume(St, LV, true, isFeasibleNotNull); + ValueState* StNotNull = Assume(St, LV, true, isFeasibleNotNull); if (isFeasibleNotNull) { @@ -750,7 +752,7 @@ void GRExprEngine::VisitDeref(UnaryOperator* U, NodeTy* Pred, NodeSet& Dst) { // Now "assume" that the pointer is NULL. - StateTy StNull = Assume(St, LV, false, isFeasibleNull); + ValueState* StNull = Assume(St, LV, false, isFeasibleNull); if (isFeasibleNull) { @@ -800,7 +802,7 @@ void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, NodeTy* Pred, for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1) { NodeTy* N1 = *I1; - StateTy St = N1->getState(); + ValueState* St = N1->getState(); RVal SubV = use_GetLVal ? GetLVal(St, U->getSubExpr()) : GetRVal(St, U->getSubExpr()); @@ -907,7 +909,7 @@ void GRExprEngine::VisitSizeOfExpr(UnaryOperator* U, NodeTy* Pred, SourceLocation Loc = U->getExprLoc(); uint64_t size = getContext().getTypeSize(T, Loc) / 8; - StateTy St = Pred->getState(); + ValueState* St = Pred->getState(); St = SetRVal(St, U, NonLVal::MakeVal(ValMgr, size, U->getType(), Loc)); Nodify(Dst, U, Pred, St); @@ -975,7 +977,7 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, for (NodeSet::iterator I2 = S2.begin(), E2 = S2.end(); I2 != E2; ++I2) { NodeTy* N2 = *I2; - StateTy St = N2->getState(); + ValueState* St = N2->getState(); Expr* RHS = B->getRHS(); RVal RightV = GetRVal(St, RHS); @@ -1004,7 +1006,7 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, // First, "assume" that the denominator is 0 or undefined. bool isFeasible = false; - StateTy ZeroSt = Assume(St, RightV, false, isFeasible); + ValueState* ZeroSt = Assume(St, RightV, false, isFeasible); if (isFeasible) { NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2); @@ -1160,7 +1162,7 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, // First, "assume" that the denominator is 0. bool isFeasible = false; - StateTy ZeroSt = Assume(St, RightV, false, isFeasible); + ValueState* ZeroSt = Assume(St, RightV, false, isFeasible); if (isFeasible) { NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2); @@ -1236,7 +1238,7 @@ void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) { break; } else if (B->getOpcode() == BinaryOperator::Comma) { - StateTy St = Pred->getState(); + ValueState* St = Pred->getState(); Nodify(Dst, B, Pred, SetRVal(St, B, GetRVal(St, B->getRHS()))); break; } @@ -1301,7 +1303,7 @@ void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) { case Stmt::StmtExprClass: { StmtExpr* SE = cast(S); - StateTy St = Pred->getState(); + ValueState* St = Pred->getState(); Expr* LastExpr = cast(*SE->getSubStmt()->body_rbegin()); Nodify(Dst, SE, Pred, SetRVal(St, SE, GetRVal(St, LastExpr))); break; @@ -1339,7 +1341,7 @@ void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) { // "Assume" logic. //===----------------------------------------------------------------------===// -GRExprEngine::StateTy GRExprEngine::Assume(StateTy St, LVal Cond, +ValueState* GRExprEngine::Assume(ValueState* St, LVal Cond, bool Assumption, bool& isFeasible) { switch (Cond.getSubKind()) { @@ -1370,7 +1372,7 @@ GRExprEngine::StateTy GRExprEngine::Assume(StateTy St, LVal Cond, } } -GRExprEngine::StateTy GRExprEngine::Assume(StateTy St, NonLVal Cond, +ValueState* GRExprEngine::Assume(ValueState* St, NonLVal Cond, bool Assumption, bool& isFeasible) { switch (Cond.getSubKind()) { @@ -1405,18 +1407,18 @@ GRExprEngine::StateTy GRExprEngine::Assume(StateTy St, NonLVal Cond, } } -GRExprEngine::StateTy -GRExprEngine::AssumeSymNE(StateTy St, SymbolID sym, +ValueState* +GRExprEngine::AssumeSymNE(ValueState* St, SymbolID sym, const llvm::APSInt& V, bool& isFeasible) { // First, determine if sym == X, where X != V. - if (const llvm::APSInt* X = St.getSymVal(sym)) { + if (const llvm::APSInt* X = St->getSymVal(sym)) { isFeasible = *X != V; return St; } // Second, determine if sym != V. - if (St.isNotEqual(sym, V)) { + if (St->isNotEqual(sym, V)) { isFeasible = true; return St; } @@ -1428,18 +1430,18 @@ GRExprEngine::AssumeSymNE(StateTy St, SymbolID sym, return StateMgr.AddNE(St, sym, V); } -GRExprEngine::StateTy -GRExprEngine::AssumeSymEQ(StateTy St, SymbolID sym, +ValueState* +GRExprEngine::AssumeSymEQ(ValueState* St, SymbolID sym, const llvm::APSInt& V, bool& isFeasible) { // First, determine if sym == X, where X != V. - if (const llvm::APSInt* X = St.getSymVal(sym)) { + if (const llvm::APSInt* X = St->getSymVal(sym)) { isFeasible = *X == V; return St; } // Second, determine if sym != V. - if (St.isNotEqual(sym, V)) { + if (St->isNotEqual(sym, V)) { isFeasible = false; return St; } @@ -1451,8 +1453,8 @@ GRExprEngine::AssumeSymEQ(StateTy St, SymbolID sym, return StateMgr.AddEQ(St, sym, V); } -GRExprEngine::StateTy -GRExprEngine::AssumeSymInt(StateTy St, bool Assumption, +ValueState* +GRExprEngine::AssumeSymInt(ValueState* St, bool Assumption, const SymIntConstraint& C, bool& isFeasible) { switch (C.getOpcode()) { @@ -1486,14 +1488,13 @@ template<> struct VISIBILITY_HIDDEN DOTGraphTraits : public DefaultDOTGraphTraits { - static void PrintVarBindings(std::ostream& Out, GRExprEngine::StateTy St) { + static void PrintVarBindings(std::ostream& Out, ValueState* St) { Out << "Variables:\\l"; bool isFirst = true; - for (GRExprEngine::StateTy::vb_iterator I=St.vb_begin(), - E=St.vb_end(); I!=E;++I) { + for (ValueState::vb_iterator I=St->vb_begin(), E=St->vb_end(); I!=E;++I) { if (isFirst) isFirst = false; @@ -1507,12 +1508,11 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : } - static void PrintSubExprBindings(std::ostream& Out, GRExprEngine::StateTy St){ + static void PrintSubExprBindings(std::ostream& Out, ValueState* St){ bool isFirst = true; - for (GRExprEngine::StateTy::seb_iterator I=St.seb_begin(), E=St.seb_end(); - I != E;++I) { + for (ValueState::seb_iterator I=St->seb_begin(), E=St->seb_end();I!=E;++I) { if (isFirst) { Out << "\\l\\lSub-Expressions:\\l"; @@ -1528,12 +1528,11 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : } } - static void PrintBlkExprBindings(std::ostream& Out, GRExprEngine::StateTy St){ + static void PrintBlkExprBindings(std::ostream& Out, ValueState* St){ bool isFirst = true; - for (GRExprEngine::StateTy::beb_iterator I=St.beb_begin(), E=St.beb_end(); - I != E; ++I) { + for (ValueState::beb_iterator I=St->beb_begin(), E=St->beb_end(); I!=E;++I){ if (isFirst) { Out << "\\l\\lBlock-level Expressions:\\l"; isFirst = false; @@ -1548,8 +1547,8 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : } } - static void PrintEQ(std::ostream& Out, GRExprEngine::StateTy St) { - ValueState::ConstEqTy CE = St.getImpl()->ConstEq; + static void PrintEQ(std::ostream& Out, ValueState* St) { + ValueState::ConstEqTy CE = St->ConstEq; if (CE.isEmpty()) return; @@ -1560,8 +1559,8 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : Out << "\\l $" << I.getKey() << " : " << I.getData()->toString(); } - static void PrintNE(std::ostream& Out, GRExprEngine::StateTy St) { - ValueState::ConstNotEqTy NE = St.getImpl()->ConstNotEq; + static void PrintNE(std::ostream& Out, ValueState* St) { + ValueState::ConstNotEqTy NE = St->ConstNotEq; if (NE.isEmpty()) return; @@ -1692,9 +1691,9 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : } } - Out << "\\|StateID: " << (void*) N->getState().getImpl() << "\\|"; + Out << "\\|StateID: " << (void*) N->getState() << "\\|"; - N->getState().printDOT(Out); + N->getState()->printDOT(Out); Out << "\\l"; return Out.str(); diff --git a/Analysis/GRSimpleVals.cpp b/Analysis/GRSimpleVals.cpp index a5e8e57c0f..4ed80afe10 100644 --- a/Analysis/GRSimpleVals.cpp +++ b/Analysis/GRSimpleVals.cpp @@ -340,11 +340,9 @@ RVal GRSimpleVals::EvalNE(ValueManager& ValMgr, LVal L, LVal R) { // Transfer function for Function Calls. //===----------------------------------------------------------------------===// -ValueStateImpl* +ValueState* GRSimpleVals::EvalCall(ValueStateManager& StateMgr, ValueManager& ValMgr, - CallExpr* CE, LVal L, ValueStateImpl* StImpl) { - - ValueState St(StImpl); + CallExpr* CE, LVal L, ValueState* St) { // Invalidate all arguments passed in by reference (LVals). @@ -357,5 +355,5 @@ GRSimpleVals::EvalCall(ValueStateManager& StateMgr, ValueManager& ValMgr, St = StateMgr.SetRVal(St, cast(V), UnknownVal()); } - return St.getImpl(); + return St; } diff --git a/Analysis/GRSimpleVals.h b/Analysis/GRSimpleVals.h index 10d4acd4b9..43fed85fdd 100644 --- a/Analysis/GRSimpleVals.h +++ b/Analysis/GRSimpleVals.h @@ -52,10 +52,10 @@ public: // Calls. - virtual ValueStateImpl* EvalCall(ValueStateManager& StateMgr, - ValueManager& ValMgr, - CallExpr* CE, LVal L, - ValueStateImpl* StImpl); + virtual ValueState* EvalCall(ValueStateManager& StateMgr, + ValueManager& ValMgr, + CallExpr* CE, LVal L, + ValueState* St); protected: diff --git a/Analysis/ValueState.cpp b/Analysis/ValueState.cpp index c552bc9e3b..dac9211030 100644 --- a/Analysis/ValueState.cpp +++ b/Analysis/ValueState.cpp @@ -1,4 +1,4 @@ -//= ValueState.cpp - Path-Sens. "State" for tracking valuues -----*- C++ -*--=// +//= ValueState*cpp - Path-Sens. "State" for tracking valuues -----*- C++ -*--=// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This files defines SymbolID, ExprBindKey, and ValueState. +// This files defines SymbolID, ExprBindKey, and ValueState* // //===----------------------------------------------------------------------===// @@ -19,19 +19,19 @@ using namespace clang; bool ValueState::isNotEqual(SymbolID sym, const llvm::APSInt& V) const { // Retrieve the NE-set associated with the given symbol. - ConstNotEqTy::TreeTy* T = Data->ConstNotEq.SlimFind(sym); + ConstNotEqTy::TreeTy* T = ConstNotEq.SlimFind(sym); // See if V is present in the NE-set. return T ? T->getValue().second.contains(&V) : false; } const llvm::APSInt* ValueState::getSymVal(SymbolID sym) const { - ConstEqTy::TreeTy* T = Data->ConstEq.SlimFind(sym); + ConstEqTy::TreeTy* T = ConstEq.SlimFind(sym); return T ? T->getValue().second : NULL; } -ValueState -ValueStateManager::RemoveDeadBindings(ValueState St, Stmt* Loc, +ValueState* +ValueStateManager::RemoveDeadBindings(ValueState* St, Stmt* Loc, const LiveVariables& Liveness) { // This code essentially performs a "mark-and-sweep" of the VariableBindings. @@ -45,14 +45,14 @@ ValueStateManager::RemoveDeadBindings(ValueState St, Stmt* Loc, llvm::SmallPtrSet Marked; llvm::SmallSet MarkedSymbols; - ValueStateImpl NewSt = *St; + ValueState NewSt = *St; // Drop bindings for subexpressions. NewSt.SubExprBindings = EXFactory.GetEmptyMap(); // Iterate over the block-expr bindings. - for (ValueState::beb_iterator I = St.beb_begin(), E = St.beb_end(); + for (ValueState::beb_iterator I = St->beb_begin(), E = St->beb_end(); I!=E ; ++I) { Expr* BlkExpr = I.getKey(); @@ -81,7 +81,7 @@ ValueStateManager::RemoveDeadBindings(ValueState St, Stmt* Loc, // Iterate over the variable bindings. - for (ValueState::vb_iterator I = St.vb_begin(), E = St.vb_end(); I!=E ; ++I) + for (ValueState::vb_iterator I = St->vb_begin(), E = St->vb_end(); I!=E ; ++I) if (Liveness.isLive(Loc, I.getKey())) { WList.push_back(I.getKey()); @@ -128,16 +128,16 @@ ValueStateManager::RemoveDeadBindings(ValueState St, Stmt* Loc, } // Remove dead variable bindings. - for (ValueState::vb_iterator I = St.vb_begin(), E = St.vb_end(); I!=E ; ++I) + for (ValueState::vb_iterator I = St->vb_begin(), E = St->vb_end(); I!=E ; ++I) if (!Marked.count(I.getKey())) NewSt.VarBindings = Remove(NewSt, I.getKey()); // Remove dead symbols. - for (ValueState::ce_iterator I = St.ce_begin(), E=St.ce_end(); I!=E; ++I) + for (ValueState::ce_iterator I = St->ce_begin(), E=St->ce_end(); I!=E; ++I) if (!MarkedSymbols.count(I.getKey())) NewSt.ConstEq = CEFactory.Remove(NewSt.ConstEq, I.getKey()); - for (ValueState::cne_iterator I = St.cne_begin(), E=St.cne_end(); I!=E; ++I) + for (ValueState::cne_iterator I = St->cne_begin(), E=St->cne_end(); I!=E; ++I) if (!MarkedSymbols.count(I.getKey())) NewSt.ConstNotEq = CNEFactory.Remove(NewSt.ConstNotEq, I.getKey()); @@ -145,7 +145,7 @@ ValueStateManager::RemoveDeadBindings(ValueState St, Stmt* Loc, } -RVal ValueStateManager::GetRVal(ValueState St, const LVal& LV, QualType T) { +RVal ValueStateManager::GetRVal(ValueState* St, LVal LV, QualType T) { if (isa(LV)) return UnknownVal(); @@ -184,8 +184,7 @@ RVal ValueStateManager::GetRVal(ValueState St, const LVal& LV, QualType T) { return UnknownVal(); } -ValueState -ValueStateManager::AddNE(ValueState St, SymbolID sym, const llvm::APSInt& V) { +ValueState* ValueStateManager::AddNE(ValueState* St, SymbolID sym, const llvm::APSInt& V) { // First, retrieve the NE-set associated with the given symbol. ValueState::ConstNotEqTy::TreeTy* T = St->ConstNotEq.SlimFind(sym); @@ -195,25 +194,24 @@ ValueStateManager::AddNE(ValueState St, SymbolID sym, const llvm::APSInt& V) { S = ISetFactory.Add(S, &V); // Create a new state with the old binding replaced. - ValueStateImpl NewSt = *St; + ValueState NewSt = *St; NewSt.ConstNotEq = CNEFactory.Add(NewSt.ConstNotEq, sym, S); // Get the persistent copy. return getPersistentState(NewSt); } -ValueState -ValueStateManager::AddEQ(ValueState St, SymbolID sym, const llvm::APSInt& V) { +ValueState* ValueStateManager::AddEQ(ValueState* St, SymbolID sym, const llvm::APSInt& V) { // Create a new state with the old binding replaced. - ValueStateImpl NewSt = *St; + ValueState NewSt = *St; NewSt.ConstEq = CEFactory.Add(NewSt.ConstEq, sym, &V); // Get the persistent copy. return getPersistentState(NewSt); } -RVal ValueStateManager::GetRVal(ValueState St, Expr* E) { +RVal ValueStateManager::GetRVal(ValueState* St, Expr* E) { for (;;) { @@ -336,7 +334,7 @@ RVal ValueStateManager::GetRVal(ValueState St, Expr* E) { return T ? T->getValue().second : UnknownVal(); } -RVal ValueStateManager::GetBlkExprRVal(ValueState St, Expr* E) { +RVal ValueStateManager::GetBlkExprRVal(ValueState* St, Expr* E) { E = E->IgnoreParens(); @@ -358,7 +356,7 @@ RVal ValueStateManager::GetBlkExprRVal(ValueState St, Expr* E) { } } -RVal ValueStateManager::GetLVal(ValueState St, Expr* E) { +RVal ValueStateManager::GetLVal(ValueState* St, Expr* E) { E = E->IgnoreParens(); @@ -386,8 +384,8 @@ RVal ValueStateManager::GetLVal(ValueState St, Expr* E) { return GetRVal(St, E); } -ValueState -ValueStateManager::SetRVal(ValueState St, Expr* E, RVal V, +ValueState* +ValueStateManager::SetRVal(ValueState* St, Expr* E, RVal V, bool isBlkExpr, bool Invalidate) { assert (E); @@ -396,7 +394,7 @@ ValueStateManager::SetRVal(ValueState St, Expr* E, RVal V, if (Invalidate) { - ValueStateImpl NewSt = *St; + ValueState NewSt = *St; if (isBlkExpr) NewSt.BlockExprBindings = EXFactory.Remove(NewSt.BlockExprBindings, E); @@ -409,7 +407,7 @@ ValueStateManager::SetRVal(ValueState St, Expr* E, RVal V, return St; } - ValueStateImpl NewSt = *St; + ValueState NewSt = *St; if (isBlkExpr) { NewSt.BlockExprBindings = EXFactory.Add(NewSt.BlockExprBindings, E, V); @@ -422,7 +420,7 @@ ValueStateManager::SetRVal(ValueState St, Expr* E, RVal V, } -ValueState ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) { +ValueState* ValueStateManager::SetRVal(ValueState* St, LVal LV, RVal V) { switch (LV.getSubKind()) { @@ -437,34 +435,34 @@ ValueState ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) { } } -void ValueStateManager::BindVar(ValueStateImpl& StImpl, VarDecl* D, RVal V) { +void ValueStateManager::BindVar(ValueState& StImpl, VarDecl* D, RVal V) { StImpl.VarBindings = VBFactory.Add(StImpl.VarBindings, D, V); } -ValueState ValueStateManager::BindVar(ValueState St, VarDecl* D, RVal V) { +ValueState* ValueStateManager::BindVar(ValueState* St, VarDecl* D, RVal V) { // Create a new state with the old binding removed. - ValueStateImpl NewSt = *St; + ValueState NewSt = *St; NewSt.VarBindings = VBFactory.Add(NewSt.VarBindings, D, V); // Get the persistent copy. return getPersistentState(NewSt); } -ValueState ValueStateManager::UnbindVar(ValueState St, VarDecl* D) { +ValueState* ValueStateManager::UnbindVar(ValueState* St, VarDecl* D) { // Create a new state with the old binding removed. - ValueStateImpl NewSt = *St; + ValueState NewSt = *St; NewSt.VarBindings = VBFactory.Remove(NewSt.VarBindings, D); // Get the persistent copy. return getPersistentState(NewSt); } -ValueState ValueStateManager::getInitialState() { +ValueState* ValueStateManager::getInitialState() { // Create a state with empty variable bindings. - ValueStateImpl StateImpl(EXFactory.GetEmptyMap(), + ValueState StateImpl(EXFactory.GetEmptyMap(), VBFactory.GetEmptyMap(), CNEFactory.GetEmptyMap(), CEFactory.GetEmptyMap()); @@ -472,17 +470,17 @@ ValueState ValueStateManager::getInitialState() { return getPersistentState(StateImpl); } -ValueState ValueStateManager::getPersistentState(const ValueStateImpl &State) { +ValueState* ValueStateManager::getPersistentState(ValueState& State) { llvm::FoldingSetNodeID ID; State.Profile(ID); void* InsertPos; - if (ValueStateImpl* I = StateSet.FindNodeOrInsertPos(ID, InsertPos)) + if (ValueState* I = StateSet.FindNodeOrInsertPos(ID, InsertPos)) return I; - ValueStateImpl* I = (ValueStateImpl*) Alloc.Allocate(); - new (I) ValueStateImpl(State); + ValueState* I = (ValueState*) Alloc.Allocate(); + new (I) ValueState(State); StateSet.InsertNode(I, InsertPos); return I; } @@ -541,12 +539,12 @@ void ValueState::printDOT(std::ostream& Out) const { // Print equality constraints. - if (!Data->ConstEq.isEmpty()) { + if (!ConstEq.isEmpty()) { Out << "\\l\\|'==' constraints:"; - for (ConstEqTy::iterator I = Data->ConstEq.begin(), - E = Data->ConstEq.end(); I!=E; ++I) { + for (ConstEqTy::iterator I = ConstEq.begin(), + E = ConstEq.end(); I!=E; ++I) { Out << "\\l $" << I.getKey() << " : " << I.getData()->toString(); @@ -555,12 +553,12 @@ void ValueState::printDOT(std::ostream& Out) const { // Print != constraints. - if (!Data->ConstNotEq.isEmpty()) { + if (!ConstNotEq.isEmpty()) { Out << "\\l\\|'!=' constraints:"; - for (ConstNotEqTy::iterator I = Data->ConstNotEq.begin(), - EI = Data->ConstNotEq.end(); I != EI; ++I) { + for (ConstNotEqTy::iterator I = ConstNotEq.begin(), + EI = ConstNotEq.end(); I != EI; ++I) { Out << "\\l $" << I.getKey() << " : "; isFirst = true; diff --git a/include/clang/Analysis/PathSensitive/ExplodedGraph.h b/include/clang/Analysis/PathSensitive/ExplodedGraph.h index 16dff25037..dfdfa5b780 100644 --- a/include/clang/Analysis/PathSensitive/ExplodedGraph.h +++ b/include/clang/Analysis/PathSensitive/ExplodedGraph.h @@ -163,7 +163,7 @@ public: // Profiling (for FoldingSet). inline void Profile(llvm::FoldingSetNodeID& ID) const { - StateTy::Profile(ID, getState()); + GRTrait::Profile(ID, getState()); } // Iterators over successor and predecessor vertices. @@ -317,7 +317,7 @@ public: llvm::FoldingSetNodeID profile; void* InsertPos = 0; - StateTy::Profile(profile, State); + GRTrait::Profile(profile, State); NodeTy* V = VSet->FindNodeOrInsertPos(profile, InsertPos); if (!V) { diff --git a/include/clang/Analysis/PathSensitive/GRExprEngine.h b/include/clang/Analysis/PathSensitive/GRExprEngine.h index 051fd1b490..f4984e1e5d 100644 --- a/include/clang/Analysis/PathSensitive/GRExprEngine.h +++ b/include/clang/Analysis/PathSensitive/GRExprEngine.h @@ -13,9 +13,8 @@ // //===----------------------------------------------------------------------===// -#include "ValueState.h" - #include "clang/Analysis/PathSensitive/GRCoreEngine.h" +#include "clang/Analysis/PathSensitive/ValueState.h" #include "clang/Analysis/PathSensitive/GRTransferFuncs.h" namespace clang { @@ -23,7 +22,7 @@ namespace clang { class GRExprEngine { public: - typedef ValueStateManager::StateTy StateTy; + typedef ValueState* StateTy; typedef ExplodedGraph GraphTy; typedef GraphTy::NodeTy NodeTy; @@ -155,7 +154,7 @@ public: /// getInitialState - Return the initial state used for the root vertex /// in the ExplodedGraph. - StateTy getInitialState(); + ValueState* getInitialState(); bool isUndefControlFlow(const NodeTy* N) const { return N->isSink() && UndefBranches.count(const_cast(N)) != 0; @@ -219,45 +218,47 @@ protected: /// that all subexpression mappings are removed and that any /// block-level expressions that are not live at 'S' also have their /// mappings removed. - inline StateTy RemoveDeadBindings(Stmt* S, StateTy St) { + inline ValueState* RemoveDeadBindings(Stmt* S, ValueState* St) { return StateMgr.RemoveDeadBindings(St, S, Liveness); } - StateTy SetRVal(StateTy St, Expr* Ex, const RVal& V); + ValueState* SetRVal(ValueState* St, Expr* Ex, RVal V); - StateTy SetRVal(StateTy St, const Expr* Ex, const RVal& V) { + ValueState* SetRVal(ValueState* St, const Expr* Ex, RVal V) { return SetRVal(St, const_cast(Ex), V); } - StateTy SetBlkExprRVal(StateTy St, Expr* Ex, const RVal& V) { + ValueState* SetBlkExprRVal(ValueState* St, Expr* Ex, RVal V) { return StateMgr.SetRVal(St, Ex, V, true, false); } +#if 0 /// SetRVal - This version of SetRVal is used to batch process a set /// of different possible RVals and return a set of different states. - const StateTy::BufferTy& SetRVal(StateTy St, Expr* Ex, - const RVal::BufferTy& V, - StateTy::BufferTy& RetBuf); + const ValueState*::BufferTy& SetRVal(ValueState* St, Expr* Ex, + const RVal::BufferTy& V, + ValueState*::BufferTy& RetBuf); +#endif - StateTy SetRVal(StateTy St, const LVal& LV, const RVal& V); + ValueState* SetRVal(ValueState* St, LVal LV, RVal V); - RVal GetRVal(const StateTy& St, Expr* Ex) { + RVal GetRVal(ValueState* St, Expr* Ex) { return StateMgr.GetRVal(St, Ex); } - RVal GetRVal(const StateTy& St, const Expr* Ex) { + RVal GetRVal(ValueState* St, const Expr* Ex) { return GetRVal(St, const_cast(Ex)); } - RVal GetBlkExprRVal(const StateTy& St, Expr* Ex) { + RVal GetBlkExprRVal(ValueState* St, Expr* Ex) { return StateMgr.GetBlkExprRVal(St, Ex); } - RVal GetRVal(const StateTy& St, const LVal& LV, QualType T = QualType()) { + RVal GetRVal(ValueState* St, LVal LV, QualType T = QualType()) { return StateMgr.GetRVal(St, LV, T); } - RVal GetLVal(const StateTy& St, Expr* Ex) { + RVal GetLVal(ValueState* St, Expr* Ex) { return StateMgr.GetLVal(St, Ex); } @@ -267,7 +268,8 @@ protected: /// Assume - Create new state by assuming that a given expression /// is true or false. - StateTy Assume(StateTy St, RVal Cond, bool Assumption, bool& isFeasible) { + ValueState* Assume(ValueState* St, RVal Cond, bool Assumption, + bool& isFeasible) { if (Cond.isUnknown()) { isFeasible = true; @@ -280,23 +282,29 @@ protected: return Assume(St, cast(Cond), Assumption, isFeasible); } - StateTy Assume(StateTy St, LVal Cond, bool Assumption, bool& isFeasible); - StateTy Assume(StateTy St, NonLVal Cond, bool Assumption, bool& isFeasible); + ValueState* Assume(ValueState* St, LVal Cond, bool Assumption, + bool& isFeasible); + + ValueState* Assume(ValueState* St, NonLVal Cond, bool Assumption, + bool& isFeasible); - StateTy AssumeSymNE(StateTy St, SymbolID sym, const llvm::APSInt& V, - bool& isFeasible); + ValueState* AssumeSymNE(ValueState* St, SymbolID sym, const llvm::APSInt& V, + bool& isFeasible); - StateTy AssumeSymEQ(StateTy St, SymbolID sym, const llvm::APSInt& V, - bool& isFeasible); + ValueState* AssumeSymEQ(ValueState* St, SymbolID sym, const llvm::APSInt& V, + bool& isFeasible); - StateTy AssumeSymInt(StateTy St, bool Assumption, const SymIntConstraint& C, - bool& isFeasible); + ValueState* AssumeSymInt(ValueState* St, bool Assumption, + const SymIntConstraint& C, bool& isFeasible); - NodeTy* Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St); + NodeTy* Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, ValueState* St); +#if 0 /// Nodify - This version of Nodify is used to batch process a set of states. /// The states are not guaranteed to be unique. - void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, const StateTy::BufferTy& SB); + void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, + const ValueState*::BufferTy& SB); +#endif /// HandleUndefinedStore - Create the necessary sink node to represent /// a store to an "undefined" LVal. @@ -387,10 +395,10 @@ protected: return TF->EvalBinOp(ValMgr, Op, cast(L), cast(R)); } - StateTy EvalCall(CallExpr* CE, LVal L, StateTy St) { - return StateTy(TF->EvalCall(StateMgr, ValMgr, CE, L, St.getImpl())); + ValueState* EvalCall(CallExpr* CE, LVal L, ValueState* St) { + return TF->EvalCall(StateMgr, ValMgr, CE, L, St); } - StateTy MarkBranch(StateTy St, Stmt* Terminator, bool branchTaken); + ValueState* MarkBranch(ValueState* St, Stmt* Terminator, bool branchTaken); }; } // end clang namespace \ No newline at end of file diff --git a/include/clang/Analysis/PathSensitive/GRTransferFuncs.h b/include/clang/Analysis/PathSensitive/GRTransferFuncs.h index b4953d6401..01e67ea68d 100644 --- a/include/clang/Analysis/PathSensitive/GRTransferFuncs.h +++ b/include/clang/Analysis/PathSensitive/GRTransferFuncs.h @@ -19,7 +19,7 @@ namespace clang { - class ValueStateImpl; + class ValueState; class ValueStateManager; class GRTransferFuncs { @@ -53,10 +53,9 @@ public: // Calls. - virtual ValueStateImpl* EvalCall(ValueStateManager& StateMgr, - ValueManager& ValMgr, - CallExpr* CE, LVal L, - ValueStateImpl* StImpl) = 0; + virtual ValueState* EvalCall(ValueStateManager& StateMgr, + ValueManager& ValMgr, CallExpr* CE, LVal L, + ValueState* St) = 0; }; } // end clang namespace diff --git a/include/clang/Analysis/PathSensitive/ValueState.h b/include/clang/Analysis/PathSensitive/ValueState.h index c3e913ab70..fd0b1ef1b0 100644 --- a/include/clang/Analysis/PathSensitive/ValueState.h +++ b/include/clang/Analysis/PathSensitive/ValueState.h @@ -1,4 +1,4 @@ -//== ValueState.h - Path-Sens. "State" for tracking valuues -----*- C++ -*--==// +//== ValueState*h - Path-Sens. "State" for tracking valuues -----*- C++ -*--==// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This files defines SymbolID, ExprBindKey, and ValueState. +// This files defines SymbolID, ExprBindKey, and ValueState* // //===----------------------------------------------------------------------===// @@ -39,36 +39,42 @@ namespace clang { //===----------------------------------------------------------------------===// -// ValueState - An ImmutableMap type Stmt*/Decl*/Symbols to RVals. +// ValueState- An ImmutableMap type Stmt*/Decl*/Symbols to RVals. //===----------------------------------------------------------------------===// -namespace vstate { - typedef llvm::ImmutableSet IntSetTy; +/// ValueState - This class encapsulates the actual data values for +/// for a "state" in our symbolic value tracking. It is intended to be +/// used as a functional object; that is once it is created and made +/// "persistent" in a FoldingSet its values will never change. +class ValueState : public llvm::FoldingSetNode { +public: + // Typedefs. + + typedef llvm::ImmutableSet IntSetTy; typedef llvm::ImmutableMap ExprBindingsTy; typedef llvm::ImmutableMap VarBindingsTy; typedef llvm::ImmutableMap ConstNotEqTy; typedef llvm::ImmutableMap ConstEqTy; -} -/// ValueStateImpl - This class encapsulates the actual data values for -/// for a "state" in our symbolic value tracking. It is intended to be -/// used as a functional object; that is once it is created and made -/// "persistent" in a FoldingSet its values will never change. -class ValueStateImpl : public llvm::FoldingSetNode { private: - void operator=(const ValueStateImpl& R) const; + void operator=(const ValueState& R) const; + + // FIXME: Make these private. + +public: + ExprBindingsTy SubExprBindings; + ExprBindingsTy BlockExprBindings; + VarBindingsTy VarBindings; + ConstNotEqTy ConstNotEq; + ConstEqTy ConstEq; + public: - vstate::ExprBindingsTy SubExprBindings; - vstate::ExprBindingsTy BlockExprBindings; - vstate::VarBindingsTy VarBindings; - vstate::ConstNotEqTy ConstNotEq; - vstate::ConstEqTy ConstEq; - /// This ctor is used when creating the first ValueStateImpl object. - ValueStateImpl(vstate::ExprBindingsTy EB, vstate::VarBindingsTy VB, - vstate::ConstNotEqTy CNE, vstate::ConstEqTy CE) + /// This ctor is used when creating the first ValueState object. + ValueState(ExprBindingsTy EB, VarBindingsTy VB, + ConstNotEqTy CNE, ConstEqTy CE) : SubExprBindings(EB), BlockExprBindings(EB), VarBindings(VB), @@ -77,7 +83,7 @@ public: /// Copy ctor - We must explicitly define this or else the "Next" ptr /// in FoldingSetNode will also get copied. - ValueStateImpl(const ValueStateImpl& RHS) + ValueState(const ValueState& RHS) : llvm::FoldingSetNode(), SubExprBindings(RHS.SubExprBindings), BlockExprBindings(RHS.BlockExprBindings), @@ -85,111 +91,63 @@ public: ConstNotEq(RHS.ConstNotEq), ConstEq(RHS.ConstEq) {} - /// Profile - Profile the contents of a ValueStateImpl object for use + /// Profile - Profile the contents of a ValueState object for use /// in a FoldingSet. - static void Profile(llvm::FoldingSetNodeID& ID, const ValueStateImpl& V) { - V.SubExprBindings.Profile(ID); - V.BlockExprBindings.Profile(ID); - V.VarBindings.Profile(ID); - V.ConstNotEq.Profile(ID); - V.ConstEq.Profile(ID); + static void Profile(llvm::FoldingSetNodeID& ID, ValueState* V) { + V->SubExprBindings.Profile(ID); + V->BlockExprBindings.Profile(ID); + V->VarBindings.Profile(ID); + V->ConstNotEq.Profile(ID); + V->ConstEq.Profile(ID); } /// Profile - Used to profile the contents of this object for inclusion /// in a FoldingSet. - void Profile(llvm::FoldingSetNodeID& ID) const { - Profile(ID, *this); + void Profile(llvm::FoldingSetNodeID& ID) { + Profile(ID, this); } -}; - -/// ValueState - This class represents a "state" in our symbolic value -/// tracking. It is really just a "smart pointer", wrapping a pointer -/// to ValueStateImpl object. Making this class a smart pointer means that its -/// size is always the size of a pointer, which allows easy conversion to -/// void* when being handled by GRCoreEngine. It also forces us to unique states; -/// consequently, a ValueStateImpl* with a specific address will always refer -/// to the unique state with those values. -class ValueState { - ValueStateImpl* Data; -public: - ValueState(ValueStateImpl* D) : Data(D) {} - ValueState() : Data(0) {} - - // Accessors. - ValueStateImpl* getImpl() const { return Data; } - ValueStateImpl& operator*() { return *Data; } - ValueStateImpl* operator->() { return Data; } - - // Typedefs. - typedef vstate::IntSetTy IntSetTy; - typedef vstate::ExprBindingsTy ExprBindingsTy; - typedef vstate::VarBindingsTy VarBindingsTy; - typedef vstate::ConstNotEqTy ConstNotEqTy; - typedef vstate::ConstEqTy ConstEqTy; - - typedef llvm::SmallVector BufferTy; - // Queries. bool isNotEqual(SymbolID sym, const llvm::APSInt& V) const; const llvm::APSInt* getSymVal(SymbolID sym) const; - + // Iterators. typedef VarBindingsTy::iterator vb_iterator; - vb_iterator vb_begin() const { return Data->VarBindings.begin(); } - vb_iterator vb_end() const { return Data->VarBindings.end(); } + vb_iterator vb_begin() const { return VarBindings.begin(); } + vb_iterator vb_end() const { return VarBindings.end(); } typedef ExprBindingsTy::iterator seb_iterator; - seb_iterator seb_begin() const { return Data->SubExprBindings.begin(); } - seb_iterator seb_end() const { return Data->SubExprBindings.end(); } + seb_iterator seb_begin() const { return SubExprBindings.begin(); } + seb_iterator seb_end() const { return SubExprBindings.end(); } typedef ExprBindingsTy::iterator beb_iterator; - beb_iterator beb_begin() const { return Data->BlockExprBindings.begin(); } - beb_iterator beb_end() const { return Data->BlockExprBindings.end(); } + beb_iterator beb_begin() const { return BlockExprBindings.begin(); } + beb_iterator beb_end() const { return BlockExprBindings.end(); } typedef ConstNotEqTy::iterator cne_iterator; - cne_iterator cne_begin() const { return Data->ConstNotEq.begin(); } - cne_iterator cne_end() const { return Data->ConstNotEq.end(); } + cne_iterator cne_begin() const { return ConstNotEq.begin(); } + cne_iterator cne_end() const { return ConstNotEq.end(); } typedef ConstEqTy::iterator ce_iterator; - ce_iterator ce_begin() const { return Data->ConstEq.begin(); } - ce_iterator ce_end() const { return Data->ConstEq.end(); } - - // Profiling and equality testing. - - bool operator==(const ValueState& RHS) const { - return Data == RHS.Data; - } - - static void Profile(llvm::FoldingSetNodeID& ID, const ValueState& V) { - ID.AddPointer(V.getImpl()); - } - - void Profile(llvm::FoldingSetNodeID& ID) const { - Profile(ID, *this); - } + ce_iterator ce_begin() const { return ConstEq.begin(); } + ce_iterator ce_end() const { return ConstEq.end(); } void printDOT(std::ostream& Out) const; void print(std::ostream& Out) const; - void printStdErr() const { print(*llvm::cerr); } - + void printStdErr() const { print(*llvm::cerr); } }; -template<> struct GRTrait { - static inline void* toPtr(ValueState St) { - return reinterpret_cast(St.getImpl()); - } - static inline ValueState toState(void* P) { - return ValueState(static_cast(P)); +template<> struct GRTrait { + static inline void* toPtr(ValueState* St) { return (void*) St; } + static inline ValueState* toState(void* P) { return (ValueState*) P; } + static inline void Profile(llvm::FoldingSetNodeID& profile, ValueState* St) { + ValueState::Profile(profile, St); } }; class ValueStateManager { -public: - typedef ValueState StateTy; - private: ValueState::IntSetTy::Factory ISetFactory; ValueState::ExprBindingsTy::Factory EXFactory; @@ -199,7 +157,7 @@ private: /// StateSet - FoldingSet containing all the states created for analyzing /// a particular function. This is used to unique states. - llvm::FoldingSet StateSet; + llvm::FoldingSet StateSet; /// ValueMgr - Object that manages the data for all created RVals. ValueManager ValMgr; @@ -220,16 +178,16 @@ private: return VBFactory.Remove(B, V); } - inline ValueState::ExprBindingsTy Remove(const ValueStateImpl& V, Expr* E) { + inline ValueState::ExprBindingsTy Remove(const ValueState& V, Expr* E) { return Remove(V.BlockExprBindings, E); } - inline ValueState::VarBindingsTy Remove(const ValueStateImpl& V, VarDecl* D) { + inline ValueState::VarBindingsTy Remove(const ValueState& V, VarDecl* D) { return Remove(V.VarBindings, D); } - ValueState BindVar(ValueState St, VarDecl* D, RVal V); - ValueState UnbindVar(ValueState St, VarDecl* D); + ValueState* BindVar(ValueState* St, VarDecl* D, RVal V); + ValueState* UnbindVar(ValueState* St, VarDecl* D); public: ValueStateManager(ASTContext& Ctx, llvm::BumpPtrAllocator& alloc) @@ -241,36 +199,36 @@ public: ValMgr(Ctx, alloc), Alloc(alloc) {} - ValueState getInitialState(); + ValueState* getInitialState(); ValueManager& getValueManager() { return ValMgr; } SymbolManager& getSymbolManager() { return SymMgr; } - ValueState RemoveDeadBindings(ValueState St, Stmt* Loc, - const LiveVariables& Liveness); + ValueState* RemoveDeadBindings(ValueState* St, Stmt* Loc, + const LiveVariables& Liveness); - ValueState RemoveSubExprBindings(ValueState St) { - ValueStateImpl NewSt = *St; + ValueState* RemoveSubExprBindings(ValueState* St) { + ValueState NewSt = *St; NewSt.SubExprBindings = EXFactory.GetEmptyMap(); return getPersistentState(NewSt); } - ValueState SetRVal(ValueState St, Expr* E, RVal V, - bool isBlkExpr, bool Invalidate); + ValueState* SetRVal(ValueState* St, Expr* E, RVal V, bool isBlkExpr, + bool Invalidate); - ValueState SetRVal(ValueState St, LVal LV, RVal V); + ValueState* SetRVal(ValueState* St, LVal LV, RVal V); - RVal GetRVal(ValueState St, Expr* E); - RVal GetRVal(ValueState St, const LVal& LV, QualType T = QualType()); - RVal GetLVal(ValueState St, Expr* E); + RVal GetRVal(ValueState* St, Expr* E); + RVal GetRVal(ValueState* St, LVal LV, QualType T = QualType()); + RVal GetLVal(ValueState* St, Expr* E); - RVal GetBlkExprRVal(ValueState St, Expr* Ex); + RVal GetBlkExprRVal(ValueState* St, Expr* Ex); - void BindVar(ValueStateImpl& StImpl, VarDecl* D, RVal V); - ValueState getPersistentState(const ValueStateImpl& Impl); + void BindVar(ValueState& StImpl, VarDecl* D, RVal V); + ValueState* getPersistentState(ValueState& Impl); - ValueState AddEQ(ValueState St, SymbolID sym, const llvm::APSInt& V); - ValueState AddNE(ValueState St, SymbolID sym, const llvm::APSInt& V); + ValueState* AddEQ(ValueState* St, SymbolID sym, const llvm::APSInt& V); + ValueState* AddNE(ValueState* St, SymbolID sym, const llvm::APSInt& V); }; } // end clang namespace