]> granicus.if.org Git - clang/commit
Fix constexpr __builtin_*_overflow issue when unsigned->signed operand.
authorErich Keane <erich.keane@intel.com>
Thu, 30 May 2019 21:35:32 +0000 (21:35 +0000)
committerErich Keane <erich.keane@intel.com>
Thu, 30 May 2019 21:35:32 +0000 (21:35 +0000)
commita5acace6e3574d196f16fd9fb8a2233ee2de38a1
tree195af22435368104009ad88231e42a65499ecb67
parentd2c6411c22d48d28d70c3988002d0c3cfbc7acb6
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362157 91177308-0d34-0410-b5e6-96231b3b80d8
lib/AST/ExprConstant.cpp
test/SemaCXX/builtins-overflow.cpp