diff options
| author | Ted Kremenek <kremenek@apple.com> | 2009-08-25 18:44:25 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2009-08-25 18:44:25 +0000 |
| commit | 3a459dc8c98f707478a2e66b360995e201dfe25b (patch) | |
| tree | 7c729e4c03cdc18444f6d28bb0c298ca9bddf5e4 | |
| parent | 2d0855605a380b7e281e6ac652fb3963322e10e6 (diff) | |
| download | bcm5719-llvm-3a459dc8c98f707478a2e66b360995e201dfe25b.tar.gz bcm5719-llvm-3a459dc8c98f707478a2e66b360995e201dfe25b.zip | |
Move logic of GRExprEngine::EvalBinOp to SValuator::EvalBinOp.
llvm-svn: 80018
| -rw-r--r-- | clang/include/clang/Analysis/PathSensitive/GRExprEngine.h | 6 | ||||
| -rw-r--r-- | clang/include/clang/Analysis/PathSensitive/SValuator.h | 3 | ||||
| -rw-r--r-- | clang/lib/Analysis/GRExprEngine.cpp | 42 | ||||
| -rw-r--r-- | clang/lib/Analysis/SValuator.cpp | 29 |
4 files changed, 41 insertions, 39 deletions
diff --git a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h index fbfcded7109..4ebc3f61a70 100644 --- a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h +++ b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h @@ -592,8 +592,10 @@ public: return R.isValid() ? SVator.EvalBinOpNN(op, L, cast<NonLoc>(R), T) : R; } - SVal EvalBinOp(const GRState *state, BinaryOperator::Opcode op, - SVal lhs, SVal rhs, QualType T); + SVal EvalBinOp(const GRState *ST, BinaryOperator::Opcode Op, + SVal LHS, SVal RHS, QualType T) { + return SVator.EvalBinOp(ST, Op, LHS, RHS, T); + } protected: diff --git a/clang/include/clang/Analysis/PathSensitive/SValuator.h b/clang/include/clang/Analysis/PathSensitive/SValuator.h index 5a6e6945e7c..4635a9cd2a0 100644 --- a/clang/include/clang/Analysis/PathSensitive/SValuator.h +++ b/clang/include/clang/Analysis/PathSensitive/SValuator.h @@ -59,6 +59,9 @@ public: virtual SVal EvalBinOpLN(const GRState *state, BinaryOperator::Opcode Op, Loc lhs, NonLoc rhs, QualType resultTy) = 0; + + SVal EvalBinOp(const GRState *ST, BinaryOperator::Opcode Op, + SVal L, SVal R, QualType T); }; SValuator* CreateSimpleSValuator(ValueManager &valMgr); diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp index cfb914842ff..3abaf552d8e 100644 --- a/clang/lib/Analysis/GRExprEngine.cpp +++ b/clang/lib/Analysis/GRExprEngine.cpp @@ -1354,9 +1354,11 @@ static bool EvalOSAtomicCompareAndSwap(ExplodedNodeSet& Dst, if (theValueVal.isUndef() || oldValueVal.isUndef()) { return false; } + + SValuator &SVator = Engine.getSValuator(); // Perform the comparison. - SVal Cmp = Engine.EvalBinOp(stateLoad, BinaryOperator::EQ, theValueVal, + SVal Cmp = SVator.EvalBinOp(stateLoad, BinaryOperator::EQ, theValueVal, oldValueVal, Engine.getContext().IntTy); const GRState *stateEqual = stateLoad->assume(Cmp, true); @@ -1370,9 +1372,8 @@ static bool EvalOSAtomicCompareAndSwap(ExplodedNodeSet& Dst, // Handle implicit value casts. if (const TypedRegion *R = dyn_cast_or_null<TypedRegion>(location.getAsRegion())) { - llvm::tie(state, val) = - Engine.getSValuator().EvalCast(val, state, R->getValueType(C), - newValueExpr->getType()); + llvm::tie(state, val) = SVator.EvalCast(val, state, R->getValueType(C), + newValueExpr->getType()); } Engine.EvalStore(TmpStore, theValueExpr, N, stateEqual, location, @@ -3033,39 +3034,6 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, } //===----------------------------------------------------------------------===// -// Transfer-function Helpers. -//===----------------------------------------------------------------------===// - -SVal GRExprEngine::EvalBinOp(const GRState* state, BinaryOperator::Opcode Op, - SVal L, SVal R, QualType T) { - - if (L.isUndef() || R.isUndef()) - return UndefinedVal(); - - if (L.isUnknown() || R.isUnknown()) - return UnknownVal(); - - if (isa<Loc>(L)) { - if (isa<Loc>(R)) - return SVator.EvalBinOpLL(Op, cast<Loc>(L), cast<Loc>(R), T); - else - return SVator.EvalBinOpLN(state, Op, cast<Loc>(L), cast<NonLoc>(R), T); - } - - if (isa<Loc>(R)) { - // Support pointer arithmetic where the increment/decrement operand - // is on the left and the pointer on the right. - - assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub); - - // Commute the operands. - return SVator.EvalBinOpLN(state, Op, cast<Loc>(R), cast<NonLoc>(L), T); - } - else - return SVator.EvalBinOpNN(Op, cast<NonLoc>(L), cast<NonLoc>(R), T); -} - -//===----------------------------------------------------------------------===// // Visualization. //===----------------------------------------------------------------------===// diff --git a/clang/lib/Analysis/SValuator.cpp b/clang/lib/Analysis/SValuator.cpp index 079481a62ac..2542cfdd3c6 100644 --- a/clang/lib/Analysis/SValuator.cpp +++ b/clang/lib/Analysis/SValuator.cpp @@ -17,6 +17,35 @@ using namespace clang; + +SVal SValuator::EvalBinOp(const GRState *ST, BinaryOperator::Opcode Op, + SVal L, SVal R, QualType T) { + + if (L.isUndef() || R.isUndef()) + return UndefinedVal(); + + if (L.isUnknown() || R.isUnknown()) + return UnknownVal(); + + if (isa<Loc>(L)) { + if (isa<Loc>(R)) + return EvalBinOpLL(Op, cast<Loc>(L), cast<Loc>(R), T); + + return EvalBinOpLN(ST, Op, cast<Loc>(L), cast<NonLoc>(R), T); + } + + if (isa<Loc>(R)) { + // Support pointer arithmetic where the increment/decrement operand + // is on the left and the pointer on the right. + assert(Op == BinaryOperator::Add || Op == BinaryOperator::Sub); + + // Commute the operands. + return EvalBinOpLN(ST, Op, cast<Loc>(R), cast<NonLoc>(L), T); + } + + return EvalBinOpNN(Op, cast<NonLoc>(L), cast<NonLoc>(R), T); +} + SValuator::CastResult SValuator::EvalCast(SVal val, const GRState *state, QualType castTy, QualType originalTy){ |

