diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-07-16 01:32:00 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-07-16 01:32:00 +0000 |
commit | 06669c8e5c24251f6b140298148fbe53ab70a936 (patch) | |
tree | 77a2453a15694d4b74532334766ae8dbee0f6e39 /lib/Analysis | |
parent | f23ecd91bf0205b776dfab2c5231e895019a7400 (diff) |
Two changes:
(1) Moved the SValuator object from GRExprEngine to ValueManager. This
allows ValueManager to use the SValuator when creating SVals.
(2) Added ValueManager::makeArrayIndex() and
ValueManager::convertToArrayIndex(), two SVal creation methods
that will help RegionStoreManager always have a consistent set of
SVals with the same integer size and type when reasoning about
array indices.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75882 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 10 | ||||
-rw-r--r-- | lib/Analysis/ValueManager.cpp | 11 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 31ee3fc323..f83e92acb3 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -124,7 +124,7 @@ GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx, StateMgr(G.getContext(), SMC, CMC, G.getAllocator(), cfg, CD, L), SymMgr(StateMgr.getSymbolManager()), ValMgr(StateMgr.getValueManager()), - SVator(clang::CreateSimpleSValuator(ValMgr)), // FIXME: Generalize later. + SVator(ValMgr.getSValuator()), CurrentStmt(NULL), NSExceptionII(NULL), NSExceptionInstanceRaiseSelectors(NULL), RaiseSel(GetNullarySelector("raise", G.getContext())), @@ -3090,9 +3090,9 @@ SVal GRExprEngine::EvalBinOp(const GRState* state, BinaryOperator::Opcode Op, if (isa<Loc>(L)) { if (isa<Loc>(R)) - return SVator->EvalBinOpLL(Op, cast<Loc>(L), cast<Loc>(R), T); + return SVator.EvalBinOpLL(Op, cast<Loc>(L), cast<Loc>(R), T); else - return SVator->EvalBinOpLN(state, Op, cast<Loc>(L), cast<NonLoc>(R), T); + return SVator.EvalBinOpLN(state, Op, cast<Loc>(L), cast<NonLoc>(R), T); } if (isa<Loc>(R)) { @@ -3102,10 +3102,10 @@ SVal GRExprEngine::EvalBinOp(const GRState* state, BinaryOperator::Opcode Op, assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub); // Commute the operands. - return SVator->EvalBinOpLN(state, Op, cast<Loc>(R), cast<NonLoc>(L), T); + return SVator.EvalBinOpLN(state, Op, cast<Loc>(R), cast<NonLoc>(L), T); } else - return SVator->EvalBinOpNN(Op, cast<NonLoc>(L), cast<NonLoc>(R), T); + return SVator.EvalBinOpNN(Op, cast<NonLoc>(L), cast<NonLoc>(R), T); } //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/ValueManager.cpp b/lib/Analysis/ValueManager.cpp index c9e24223df..62d8b0093b 100644 --- a/lib/Analysis/ValueManager.cpp +++ b/lib/Analysis/ValueManager.cpp @@ -55,6 +55,17 @@ NonLoc ValueManager::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, } +SVal ValueManager::convertToArrayIndex(SVal V) { + // Common case: we have an appropriately sized integer. + if (nonloc::ConcreteInt* CI = dyn_cast<nonloc::ConcreteInt>(&V)) { + const llvm::APSInt& I = CI->getValue(); + if (I.getBitWidth() == ArrayIndexWidth && I.isSigned()) + return V; + } + + return SVator->EvalCast(V, ArrayIndexTy); +} + SVal ValueManager::getRegionValueSymbolVal(const MemRegion* R, QualType T) { SymbolRef sym = SymMgr.getRegionValueSymbol(R, T); |