diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-09-19 17:31:13 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-09-19 17:31:13 +0000 |
commit | 2675875099ef178aa047fab8d51370555fc744f5 (patch) | |
tree | a1df7a42b5a0ed74b1fe4b9ca199a6c779c99222 | |
parent | 94b8312a8dde681f6ab860e1e34f0b1fba937fcf (diff) |
When we have a binary expression 'int operator symbol', properly rewrite this as
'symbol operator-reverse int'. This patch is a combination of code from
Zhongxing Xu and myself (Zhongxing noticed this bug for the cases of
relational operators).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56351 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/GRSimpleVals.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/Analysis/GRSimpleVals.cpp b/lib/Analysis/GRSimpleVals.cpp index 89f7c3e584..b33d5122b1 100644 --- a/lib/Analysis/GRSimpleVals.cpp +++ b/lib/Analysis/GRSimpleVals.cpp @@ -126,12 +126,13 @@ static unsigned char LNotOpMap[] = { RVal GRSimpleVals::DetermEvalBinOpNN(GRStateManager& StateMgr, BinaryOperator::Opcode Op, NonLVal L, NonLVal R) { - + BasicValueFactory& BasicVals = StateMgr.getBasicVals(); + unsigned subkind = L.getSubKind(); while (1) { - switch (L.getSubKind()) { + switch (subkind) { default: return UnknownVal(); @@ -169,18 +170,28 @@ RVal GRSimpleVals::DetermEvalBinOpNN(GRStateManager& StateMgr, if (isa<nonlval::ConcreteInt>(R)) { const nonlval::ConcreteInt& L_CI = cast<nonlval::ConcreteInt>(L); - const nonlval::ConcreteInt& R_CI = cast<nonlval::ConcreteInt>(R); + const nonlval::ConcreteInt& R_CI = cast<nonlval::ConcreteInt>(R); return L_CI.EvalBinOp(BasicVals, Op, R_CI); } else { + subkind = R.getSubKind(); NonLVal tmp = R; R = L; L = tmp; + + // Swap the operators. + switch (Op) { + case BinaryOperator::LT: Op = BinaryOperator::GT; break; + case BinaryOperator::GT: Op = BinaryOperator::LT; break; + case BinaryOperator::LE: Op = BinaryOperator::GE; break; + case BinaryOperator::GE: Op = BinaryOperator::LE; break; + default: break; + } + continue; } - case nonlval::SymbolValKind: { - + case nonlval::SymbolValKind: if (isa<nonlval::ConcreteInt>(R)) { const SymIntConstraint& C = BasicVals.getConstraint(cast<nonlval::SymbolVal>(L).getSymbol(), Op, @@ -190,7 +201,6 @@ RVal GRSimpleVals::DetermEvalBinOpNN(GRStateManager& StateMgr, } else return UnknownVal(); - } } } } |