diff options
author | Jordy Rose <jediknil@belkadan.com> | 2010-06-21 20:15:15 +0000 |
---|---|---|
committer | Jordy Rose <jediknil@belkadan.com> | 2010-06-21 20:15:15 +0000 |
commit | b4954a4175b36d912bdfc43834d09754faddd855 (patch) | |
tree | 36547c06e7cf35deabdcb1681e3c7e0ee4af5265 /lib/Checker/SimpleSValuator.cpp | |
parent | 9a126850968b0aa25f7c6f214e7309e33f2d800a (diff) |
When folding additive operations, convert the values to the same type. When assuming relationships, convert the integers to the same type as the symbol, at least for now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106458 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Checker/SimpleSValuator.cpp')
-rw-r--r-- | lib/Checker/SimpleSValuator.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/Checker/SimpleSValuator.cpp b/lib/Checker/SimpleSValuator.cpp index 0799380e80..bf539defd4 100644 --- a/lib/Checker/SimpleSValuator.cpp +++ b/lib/Checker/SimpleSValuator.cpp @@ -411,15 +411,22 @@ SVal SimpleSValuator::EvalBinOpNN(const GRState *state, BinaryOperator::Opcode lop = symIntExpr->getOpcode(); if (BinaryOperator::isAdditiveOp(lop)) { BasicValueFactory &BVF = ValMgr.getBasicValueFactory(); + + // resultTy may not be the best type to convert to, but it's + // probably the best choice in expressions with mixed type + // (such as x+1U+2LL). The rules for implicit conversions should + // choose a reasonable type to preserve the expression, and will + // at least match how the value is going to be used. + const llvm::APSInt &first = + BVF.Convert(resultTy, symIntExpr->getRHS()); + const llvm::APSInt &second = + BVF.Convert(resultTy, rhsInt->getValue()); + const llvm::APSInt *newRHS; if (lop == op) - newRHS = BVF.EvaluateAPSInt(BinaryOperator::Add, - symIntExpr->getRHS(), - rhsInt->getValue()); + newRHS = BVF.EvaluateAPSInt(BinaryOperator::Add, first, second); else - newRHS = BVF.EvaluateAPSInt(BinaryOperator::Sub, - symIntExpr->getRHS(), - rhsInt->getValue()); + newRHS = BVF.EvaluateAPSInt(BinaryOperator::Sub, first, second); return MakeSymIntVal(symIntExpr->getLHS(), lop, *newRHS, resultTy); } } |