summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2019-05-30 21:35:32 +0000
committerErich Keane <erich.keane@intel.com>2019-05-30 21:35:32 +0000
commitfc3dfd3e35a637cdbef1bc21c56a31c28e4a5b4c (patch)
tree728762b37972219e86de2ddda50e8d26266e005d /clang/lib
parent46511d75b5bf3278bff5262181e07e0f977690b8 (diff)
downloadbcm5719-llvm-fc3dfd3e35a637cdbef1bc21c56a31c28e4a5b4c.tar.gz
bcm5719-llvm-fc3dfd3e35a637cdbef1bc21c56a31c28e4a5b4c.zip
Fix constexpr __builtin_*_overflow issue when unsigned->signed operand.
As reported here https://bugs.llvm.org/show_bug.cgi?id=42000, it was possible to get the constexpr version of __builtin_*_overflow to give the wrong answer. This was because when extending the operands to fit the largest type (so that the math could be done), the decision on whether to sign/zero extend the operands was based on the result signedness, not on the operands signedness. In the reported case, (unsigned char)255 - (int)100 needed to have each extended to the int in order to do the math. However, when extending the first operand to 'int', we incorrectly sign extended it instead of zero extending. Thus, the result didnt fit back into the unsigned char. The fix for this was simply to choose zero/sign extension based on the sign of the operand itself. Differential Revision: https://reviews.llvm.org/D62665 llvm-svn: 362157
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ExprConstant.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index df9b3067b8d..57d428282cb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9454,10 +9454,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
if (IsSigned && !AllSigned)
++MaxBits;
- LHS = APSInt(IsSigned ? LHS.sextOrSelf(MaxBits) : LHS.zextOrSelf(MaxBits),
- !IsSigned);
- RHS = APSInt(IsSigned ? RHS.sextOrSelf(MaxBits) : RHS.zextOrSelf(MaxBits),
- !IsSigned);
+ LHS = APSInt(LHS.extOrTrunc(MaxBits), !IsSigned);
+ RHS = APSInt(RHS.extOrTrunc(MaxBits), !IsSigned);
Result = APSInt(MaxBits, !IsSigned);
}
OpenPOWER on IntegriCloud