]> granicus.if.org Git - clang/commitdiff
Fix PR2252: don't warn on negating an unsigned value ever, and don't emit
authorChris Lattner <sabre@nondot.org>
Thu, 3 Jul 2008 03:47:30 +0000 (03:47 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 3 Jul 2008 03:47:30 +0000 (03:47 +0000)
'integer constant is so large that it is unsigned' warning for hex literals.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53070 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPExpressions.cpp
test/Lexer/number.c

index 5f11df089368f22c045bb893de71d4b63e0eb747..2a4794de8353f14f1c72e5eafcf34fb12a8fde32 100644 (file)
@@ -198,7 +198,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
       // large that it is unsigned" e.g. on 12345678901234567890 where intmax_t
       // is 64-bits.
       if (!Literal.isUnsigned && Result.Val.isNegative()) {
-        if (ValueLive)
+        // Don't warn for a hex literal: 0x8000..0 shouldn't warn.
+        if (ValueLive && Literal.getRadix() != 16)
           PP.Diag(PeekTok, diag::warn_integer_too_large_for_signed);
         Result.Val.setIsUnsigned(true);
       }
@@ -288,11 +289,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
     // C99 6.5.3.3p3: The sign of the result matches the sign of the operand.
     Result.Val = -Result.Val;
     
-    bool Overflow = false;
-    if (Result.isUnsigned())
-      Overflow = Result.Val.isNegative();
-    else if (Result.Val.isMinSignedValue())
-      Overflow = true;   // -MININT is the only thing that overflows.
+    // -MININT is the only thing that overflows.  Unsigned never overflows.
+    bool Overflow = !Result.isUnsigned() && Result.Val.isMinSignedValue();
       
     // If this operator is live and overflowed, report the issue.
     if (Overflow && ValueLive)
index e48816e405307d71cd12239fedf7ece5cc0ef4d4..bafbc022d5e88d0614d5215d549a66ddce9f6485 100644 (file)
@@ -1,6 +1,9 @@
 // RUN: clang %s -fsyntax-only
 
 float X = 1.17549435e-38F;
-
 float Y = 08.123456;
 
+// PR2252
+#if -0x8000000000000000  // should not warn.
+#endif
+