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 +#include int a() { const int x = 3; @@ -50,6 +51,7 @@ static_assert(sub(static_cast(0),static_cast(1)) == Result{true, UCHAR_MAX}); static_assert(sub(static_cast(0),static_cast(1)) == Result{false, -1}); static_assert(sub(static_cast(0),static_cast(1)) == Result{true, USHRT_MAX}); +static_assert(sub(static_cast(255),static_cast(100)) == Result{false, 155}); static_assert(sub(17,22) == Result{false, -5}); static_assert(sub(INT_MAX - 22, -23) == Result{true, INT_MIN}); @@ -91,3 +93,4 @@ static_assert(smul(17,22) == Result{false, 374}); static_assert(smul(INT_MAX / 22, 23) == Result{true, -2049870757}); static_assert(smul(INT_MIN / 22, -23) == Result{true, -2049870757}); +