diff options
| author | Ted Kremenek <kremenek@apple.com> | 2008-07-17 23:15:45 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2008-07-17 23:15:45 +0000 |
| commit | 9c32a1ecf5dfcd7c26b89550d813602018bbfa03 (patch) | |
| tree | 3d80c8e7b2ac2268198d55c9aedc0cf9dd70ed9a /clang/lib/Analysis | |
| parent | 9976888190cd508bd4b0d55f3a5e6f6030f28112 (diff) | |
| download | bcm5719-llvm-9c32a1ecf5dfcd7c26b89550d813602018bbfa03.tar.gz bcm5719-llvm-9c32a1ecf5dfcd7c26b89550d813602018bbfa03.zip | |
Move GRTransferFunc* into ValueStateManager, and move the assumption logic there as well.
llvm-svn: 53743
Diffstat (limited to 'clang/lib/Analysis')
| -rw-r--r-- | clang/lib/Analysis/GRExprEngine.cpp | 190 | ||||
| -rw-r--r-- | clang/lib/Analysis/ValueState.cpp | 172 |
2 files changed, 181 insertions, 181 deletions
diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp index 5159f4a4cdf..c4278b1e5b1 100644 --- a/clang/lib/Analysis/GRExprEngine.cpp +++ b/clang/lib/Analysis/GRExprEngine.cpp @@ -123,7 +123,6 @@ GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx, StateMgr(G.getContext(), CreateBasicStoreManager(G.getAllocator()), G.getAllocator(), G.getCFG()), BasicVals(StateMgr.getBasicValueFactory()), - TF(NULL), // FIXME SymMgr(StateMgr.getSymbolManager()), CurrentStmt(NULL), NSExceptionII(NULL), NSExceptionInstanceRaiseSelectors(NULL), @@ -178,8 +177,8 @@ void GRExprEngine::EmitWarnings(BugReporterData& BRData) { } void GRExprEngine::setTransferFunctions(GRTransferFuncs* tf) { - TF = tf; - TF->RegisterChecks(*this); + StateMgr.TF = tf; + getTF().RegisterChecks(*this); } void GRExprEngine::AddCheck(GRSimpleAPICheck* A, Stmt::StmtClass C) { @@ -252,7 +251,7 @@ void GRExprEngine::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) { SaveAndRestore<bool> OldPurgeDeadSymbols(Builder->PurgingDeadSymbols); Builder->PurgingDeadSymbols = true; - TF->EvalDeadSymbols(Tmp, *this, *Builder, EntryNode, S, + getTF().EvalDeadSymbols(Tmp, *this, *Builder, EntryNode, S, CleanedState, DeadSymbols); if (!Builder->BuildSinks && !Builder->HasGeneratedNode) @@ -964,13 +963,13 @@ void GRExprEngine::EvalStore(NodeSet& Dst, Expr* Ex, NodeTy* Pred, assert (!location.isUndef()); - TF->EvalStore(Dst, *this, *Builder, Ex, Pred, St, location, Val); + getTF().EvalStore(Dst, *this, *Builder, Ex, Pred, St, location, Val); // Handle the case where no nodes where generated. Auto-generate that // contains the updated state if we aren't generating sinks. if (!Builder->BuildSinks && Dst.size() == size && !Builder->HasGeneratedNode) - TF->GRTransferFuncs::EvalStore(Dst, *this, *Builder, Ex, Pred, St, + getTF().GRTransferFuncs::EvalStore(Dst, *this, *Builder, Ex, Pred, St, location, Val); } @@ -1939,7 +1938,7 @@ void GRExprEngine::EvalReturn(NodeSet& Dst, ReturnStmt* S, NodeTy* Pred) { SaveAndRestore<bool> OldSink(Builder->BuildSinks); SaveOr OldHasGen(Builder->HasGeneratedNode); - TF->EvalReturn(Dst, *this, *Builder, S, Pred); + getTF().EvalReturn(Dst, *this, *Builder, S, Pred); // Handle the case where no nodes where generated. @@ -2240,7 +2239,7 @@ void GRExprEngine::EvalBinOp(ExplodedNodeSet<ValueState>& Dst, Expr* Ex, unsigned size = Dst.size(); SaveOr OldHasGen(Builder->HasGeneratedNode); - TF->EvalBinOpNN(Dst, *this, *Builder, Op, Ex, L, R, Pred); + getTF().EvalBinOpNN(Dst, *this, *Builder, Op, Ex, L, R, Pred); if (!Builder->BuildSinks && Dst.size() == size && !Builder->HasGeneratedNode) @@ -2248,177 +2247,6 @@ void GRExprEngine::EvalBinOp(ExplodedNodeSet<ValueState>& Dst, Expr* Ex, } //===----------------------------------------------------------------------===// -// "Assume" logic. -//===----------------------------------------------------------------------===// - -const ValueState* GRExprEngine::Assume(const ValueState* St, LVal Cond, - bool Assumption, bool& isFeasible) { - - St = AssumeAux(St, Cond, Assumption, isFeasible); - - return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible) - : St; -} - -const ValueState* GRExprEngine::AssumeAux(const ValueState* St, LVal Cond, - bool Assumption, bool& isFeasible) { - - switch (Cond.getSubKind()) { - default: - assert (false && "'Assume' not implemented for this LVal."); - return St; - - case lval::SymbolValKind: - if (Assumption) - return AssumeSymNE(St, cast<lval::SymbolVal>(Cond).getSymbol(), - BasicVals.getZeroWithPtrWidth(), isFeasible); - else - return AssumeSymEQ(St, cast<lval::SymbolVal>(Cond).getSymbol(), - BasicVals.getZeroWithPtrWidth(), isFeasible); - - - case lval::DeclValKind: - case lval::FuncValKind: - case lval::GotoLabelKind: - case lval::StringLiteralValKind: - isFeasible = Assumption; - return St; - - case lval::FieldOffsetKind: - return AssumeAux(St, cast<lval::FieldOffset>(Cond).getBase(), - Assumption, isFeasible); - - case lval::ArrayOffsetKind: - return AssumeAux(St, cast<lval::ArrayOffset>(Cond).getBase(), - Assumption, isFeasible); - - case lval::ConcreteIntKind: { - bool b = cast<lval::ConcreteInt>(Cond).getValue() != 0; - isFeasible = b ? Assumption : !Assumption; - return St; - } - } -} - -const ValueState* GRExprEngine::Assume(const ValueState* St, NonLVal Cond, - bool Assumption, bool& isFeasible) { - - St = AssumeAux(St, Cond, Assumption, isFeasible); - - return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible) - : St; -} - -const ValueState* GRExprEngine::AssumeAux(const ValueState* St, NonLVal Cond, - bool Assumption, bool& isFeasible) { - switch (Cond.getSubKind()) { - default: - assert (false && "'Assume' not implemented for this NonLVal."); - return St; - - - case nonlval::SymbolValKind: { - nonlval::SymbolVal& SV = cast<nonlval::SymbolVal>(Cond); - SymbolID sym = SV.getSymbol(); - - if (Assumption) - return AssumeSymNE(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)), - isFeasible); - else - return AssumeSymEQ(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)), - isFeasible); - } - - case nonlval::SymIntConstraintValKind: - return - AssumeSymInt(St, Assumption, - cast<nonlval::SymIntConstraintVal>(Cond).getConstraint(), - isFeasible); - - case nonlval::ConcreteIntKind: { - bool b = cast<nonlval::ConcreteInt>(Cond).getValue() != 0; - isFeasible = b ? Assumption : !Assumption; - return St; - } - - case nonlval::LValAsIntegerKind: { - return AssumeAux(St, cast<nonlval::LValAsInteger>(Cond).getLVal(), - Assumption, isFeasible); - } - } -} - -const ValueState* GRExprEngine::AssumeSymNE(const 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)) { - isFeasible = *X != V; - return St; - } - - // Second, determine if sym != V. - if (St->isNotEqual(sym, V)) { - isFeasible = true; - return St; - } - - // If we reach here, sym is not a constant and we don't know if it is != V. - // Make that assumption. - - isFeasible = true; - return StateMgr.AddNE(St, sym, V); -} - -const ValueState* GRExprEngine::AssumeSymEQ(const 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)) { - isFeasible = *X == V; - return St; - } - - // Second, determine if sym != V. - if (St->isNotEqual(sym, V)) { - isFeasible = false; - return St; - } - - // If we reach here, sym is not a constant and we don't know if it is == V. - // Make that assumption. - - isFeasible = true; - return StateMgr.AddEQ(St, sym, V); -} - -const ValueState* GRExprEngine::AssumeSymInt(const ValueState* St, - bool Assumption, - const SymIntConstraint& C, - bool& isFeasible) { - - switch (C.getOpcode()) { - default: - // No logic yet for other operators. - isFeasible = true; - return St; - - case BinaryOperator::EQ: - if (Assumption) - return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); - else - return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); - - case BinaryOperator::NE: - if (Assumption) - return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); - else - return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); - } -} - -//===----------------------------------------------------------------------===// // Visualization. //===----------------------------------------------------------------------===// @@ -2733,7 +2561,7 @@ void GRExprEngine::ViewGraph(bool trim) { else { GraphPrintCheckerState = this; GraphPrintSourceManager = &getContext().getSourceManager(); - GraphCheckerStatePrinter = TF->getCheckerStatePrinter(); + GraphCheckerStatePrinter = getTF().getCheckerStatePrinter(); llvm::ViewGraph(*G.roots_begin(), "GRExprEngine"); @@ -2748,7 +2576,7 @@ void GRExprEngine::ViewGraph(NodeTy** Beg, NodeTy** End) { #ifndef NDEBUG GraphPrintCheckerState = this; GraphPrintSourceManager = &getContext().getSourceManager(); - GraphCheckerStatePrinter = TF->getCheckerStatePrinter(); + GraphCheckerStatePrinter = getTF().getCheckerStatePrinter(); GRExprEngine::GraphTy* TrimmedG = G.Trim(Beg, End); diff --git a/clang/lib/Analysis/ValueState.cpp b/clang/lib/Analysis/ValueState.cpp index ca78faf3491..2c3e6dabc66 100644 --- a/clang/lib/Analysis/ValueState.cpp +++ b/clang/lib/Analysis/ValueState.cpp @@ -13,6 +13,7 @@ #include "clang/Analysis/PathSensitive/ValueState.h" #include "llvm/ADT/SmallSet.h" +#include "clang/Analysis/PathSensitive/GRTransferFuncs.h" using namespace clang; @@ -294,3 +295,174 @@ void ValueState::print(std::ostream& Out, CheckerStatePrinter* P, if (P && CheckerState) P->PrintCheckerState(Out, CheckerState, nl, sep); } + +//===----------------------------------------------------------------------===// +// "Assume" logic. +//===----------------------------------------------------------------------===// + +const ValueState* ValueStateManager::Assume(const ValueState* St, LVal Cond, + bool Assumption, bool& isFeasible) { + + St = AssumeAux(St, Cond, Assumption, isFeasible); + + return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible) + : St; +} + +const ValueState* ValueStateManager::AssumeAux(const ValueState* St, LVal Cond, + bool Assumption, bool& isFeasible) { + + switch (Cond.getSubKind()) { + default: + assert (false && "'Assume' not implemented for this LVal."); + return St; + + case lval::SymbolValKind: + if (Assumption) + return AssumeSymNE(St, cast<lval::SymbolVal>(Cond).getSymbol(), + BasicVals.getZeroWithPtrWidth(), isFeasible); + else + return AssumeSymEQ(St, cast<lval::SymbolVal>(Cond).getSymbol(), + BasicVals.getZeroWithPtrWidth(), isFeasible); + + + case lval::DeclValKind: + case lval::FuncValKind: + case lval::GotoLabelKind: + case lval::StringLiteralValKind: + isFeasible = Assumption; + return St; + + case lval::FieldOffsetKind: + return AssumeAux(St, cast<lval::FieldOffset>(Cond).getBase(), + Assumption, isFeasible); + + case lval::ArrayOffsetKind: + return AssumeAux(St, cast<lval::ArrayOffset>(Cond).getBase(), + Assumption, isFeasible); + + case lval::ConcreteIntKind: { + bool b = cast<lval::ConcreteInt>(Cond).getValue() != 0; + isFeasible = b ? Assumption : !Assumption; + return St; + } + } +} + +const ValueState* ValueStateManager::Assume(const ValueState* St, NonLVal Cond, + bool Assumption, bool& isFeasible) { + + St = AssumeAux(St, Cond, Assumption, isFeasible); + + return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible) + : St; +} + +const ValueState* ValueStateManager::AssumeAux(const ValueState* St, NonLVal Cond, + bool Assumption, bool& isFeasible) { + switch (Cond.getSubKind()) { + default: + assert (false && "'Assume' not implemented for this NonLVal."); + return St; + + + case nonlval::SymbolValKind: { + nonlval::SymbolVal& SV = cast<nonlval::SymbolVal>(Cond); + SymbolID sym = SV.getSymbol(); + + if (Assumption) + return AssumeSymNE(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)), + isFeasible); + else + return AssumeSymEQ(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)), + isFeasible); + } + + case nonlval::SymIntConstraintValKind: + return + AssumeSymInt(St, Assumption, + cast<nonlval::SymIntConstraintVal>(Cond).getConstraint(), + isFeasible); + + case nonlval::ConcreteIntKind: { + bool b = cast<nonlval::ConcreteInt>(Cond).getValue() != 0; + isFeasible = b ? Assumption : !Assumption; + return St; + } + + case nonlval::LValAsIntegerKind: { + return AssumeAux(St, cast<nonlval::LValAsInteger>(Cond).getLVal(), + Assumption, isFeasible); + } + } +} + +const ValueState* ValueStateManager::AssumeSymNE(const 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)) { + isFeasible = *X != V; + return St; + } + + // Second, determine if sym != V. + if (St->isNotEqual(sym, V)) { + isFeasible = true; + return St; + } + + // If we reach here, sym is not a constant and we don't know if it is != V. + // Make that assumption. + + isFeasible = true; + return AddNE(St, sym, V); +} + +const ValueState* ValueStateManager::AssumeSymEQ(const 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)) { + isFeasible = *X == V; + return St; + } + + // Second, determine if sym != V. + if (St->isNotEqual(sym, V)) { + isFeasible = false; + return St; + } + + // If we reach here, sym is not a constant and we don't know if it is == V. + // Make that assumption. + + isFeasible = true; + return AddEQ(St, sym, V); +} + +const ValueState* ValueStateManager::AssumeSymInt(const ValueState* St, + bool Assumption, + const SymIntConstraint& C, + bool& isFeasible) { + + switch (C.getOpcode()) { + default: + // No logic yet for other operators. + isFeasible = true; + return St; + + case BinaryOperator::EQ: + if (Assumption) + return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); + else + return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); + + case BinaryOperator::NE: + if (Assumption) + return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); + else + return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); + } +} |

