case tok::star:
Res = LHS.Val * RHS.Val;
- if (LHS.Val != 0 && RHS.Val != 0)
+ if (Res.isSigned() && LHS.Val != 0 && RHS.Val != 0)
Overflow = Res/RHS.Val != LHS.Val || Res/LHS.Val != RHS.Val;
break;
case tok::lessless: {
if (ShAmt >= LHS.Val.getBitWidth())
Overflow = true, ShAmt = LHS.Val.getBitWidth()-1;
else if (LHS.isUnsigned())
- Overflow = ShAmt > LHS.Val.countLeadingZeros();
+ Overflow = false;
else if (LHS.Val.isNonNegative()) // Don't allow sign change.
Overflow = ShAmt >= LHS.Val.countLeadingZeros();
else
case tok::plus:
Res = LHS.Val + RHS.Val;
if (LHS.isUnsigned())
- Overflow = Res.ult(LHS.Val);
+ Overflow = false;
else if (LHS.Val.isNonNegative() == RHS.Val.isNonNegative() &&
Res.isNonNegative() != LHS.Val.isNonNegative())
Overflow = true; // Overflow for signed addition.
case tok::minus:
Res = LHS.Val - RHS.Val;
if (LHS.isUnsigned())
- Overflow = Res.ugt(LHS.Val);
+ Overflow = false;
else if (LHS.Val.isNonNegative() != RHS.Val.isNonNegative() &&
Res.isNonNegative() != LHS.Val.isNonNegative())
Overflow = true; // Overflow for signed subtraction.
--- /dev/null
+// RUN: clang-cc -Eonly %s -verify -triple i686-pc-linux-gnu
+
+// Multiply signed overflow
+#if 0x7FFFFFFFFFFFFFFF*2 // expected-warning {{overflow}}
+#endif
+
+// Multiply unsigned overflow
+#if 0xFFFFFFFFFFFFFFFF*2
+#endif
+
+// Add signed overflow
+#if 0x7FFFFFFFFFFFFFFF+1 // expected-warning {{overflow}}
+#endif
+
+// Add unsigned overflow
+#if 0xFFFFFFFFFFFFFFFF+1
+#endif
+
+// Subtract signed overflow
+#if 0x7FFFFFFFFFFFFFFF- -1 // expected-warning {{overflow}}
+#endif
+
+// Subtract unsigned overflow
+#if 0xFFFFFFFFFFFFFFFF- -1 // expected-warning {{converted from negative value}}
+#endif