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 | 79404afc1c9a6b4c498bb28c6cb0aad23783de9d (patch) | |
tree | 6347990d03dd9d1592cfaf75df317a2d04dc1e3f /clang/lib/Checker/SimpleSValuator.cpp | |
parent | fb008dfa05230ca997d402d0e3b1e6f7b1865b51 (diff) | |
download | bcm5719-llvm-79404afc1c9a6b4c498bb28c6cb0aad23783de9d.tar.gz bcm5719-llvm-79404afc1c9a6b4c498bb28c6cb0aad23783de9d.zip |
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.
llvm-svn: 106458
Diffstat (limited to 'clang/lib/Checker/SimpleSValuator.cpp')
-rw-r--r-- | clang/lib/Checker/SimpleSValuator.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/clang/lib/Checker/SimpleSValuator.cpp b/clang/lib/Checker/SimpleSValuator.cpp index 0799380e80f..bf539defd4a 100644 --- a/clang/lib/Checker/SimpleSValuator.cpp +++ b/clang/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); } } |