This revision was automatically updated to reflect the committed changes. Closed by commit rL362157: Fix constexpr __builtin_*_overflow issue when unsigned->signed operand. (authored by erichkeane, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D62665?vs=202268&id=202302#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D62665/new/ https://reviews.llvm.org/D62665 Files: cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/SemaCXX/builtins-overflow.cpp Index: cfe/trunk/test/SemaCXX/builtins-overflow.cpp =================================================================== --- cfe/trunk/test/SemaCXX/builtins-overflow.cpp +++ cfe/trunk/test/SemaCXX/builtins-overflow.cpp @@ -2,6 +2,7 @@ // expected-no-diagnostics #include <limits.h> +#include <stdint.h> int a() { const int x = 3; @@ -50,6 +51,7 @@ static_assert(sub<unsigned char>(static_cast<char>(0),static_cast<char>(1)) == Result<unsigned char>{true, UCHAR_MAX}); static_assert(sub<char>(static_cast<unsigned char>(0),static_cast<unsigned char>(1)) == Result<char>{false, -1}); static_assert(sub<unsigned short>(static_cast<short>(0),static_cast<short>(1)) == Result<unsigned short>{true, USHRT_MAX}); +static_assert(sub<uint8_t>(static_cast<uint8_t>(255),static_cast<int>(100)) == Result<uint8_t>{false, 155}); static_assert(sub<int>(17,22) == Result<int>{false, -5}); static_assert(sub<int>(INT_MAX - 22, -23) == Result<int>{true, INT_MIN}); @@ -91,3 +93,4 @@ static_assert(smul(17,22) == Result<int>{false, 374}); static_assert(smul(INT_MAX / 22, 23) == Result<int>{true, -2049870757}); static_assert(smul(INT_MIN / 22, -23) == Result<int>{true, -2049870757}); + Index: cfe/trunk/lib/AST/ExprConstant.cpp =================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp +++ cfe/trunk/lib/AST/ExprConstant.cpp @@ -9454,10 +9454,8 @@ 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); }
Index: cfe/trunk/test/SemaCXX/builtins-overflow.cpp =================================================================== --- cfe/trunk/test/SemaCXX/builtins-overflow.cpp +++ cfe/trunk/test/SemaCXX/builtins-overflow.cpp @@ -2,6 +2,7 @@ // expected-no-diagnostics #include <limits.h> +#include <stdint.h> int a() { const int x = 3; @@ -50,6 +51,7 @@ static_assert(sub<unsigned char>(static_cast<char>(0),static_cast<char>(1)) == Result<unsigned char>{true, UCHAR_MAX}); static_assert(sub<char>(static_cast<unsigned char>(0),static_cast<unsigned char>(1)) == Result<char>{false, -1}); static_assert(sub<unsigned short>(static_cast<short>(0),static_cast<short>(1)) == Result<unsigned short>{true, USHRT_MAX}); +static_assert(sub<uint8_t>(static_cast<uint8_t>(255),static_cast<int>(100)) == Result<uint8_t>{false, 155}); static_assert(sub<int>(17,22) == Result<int>{false, -5}); static_assert(sub<int>(INT_MAX - 22, -23) == Result<int>{true, INT_MIN}); @@ -91,3 +93,4 @@ static_assert(smul(17,22) == Result<int>{false, 374}); static_assert(smul(INT_MAX / 22, 23) == Result<int>{true, -2049870757}); static_assert(smul(INT_MIN / 22, -23) == Result<int>{true, -2049870757}); + Index: cfe/trunk/lib/AST/ExprConstant.cpp =================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp +++ cfe/trunk/lib/AST/ExprConstant.cpp @@ -9454,10 +9454,8 @@ 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); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits