[cfe-commits] r53070 - in /cfe/trunk: lib/Lex/PPExpressions.cpp test/Lexer/number.c

Chris Lattner sabre at nondot.org
Wed Jul 2 20:47:30 PDT 2008


Author: lattner
Date: Wed Jul  2 22:47:30 2008
New Revision: 53070

URL: http://llvm.org/viewvc/llvm-project?rev=53070&view=rev
Log:
Fix PR2252: don't warn on negating an unsigned value ever, and don't emit
'integer constant is so large that it is unsigned' warning for hex literals.

Modified:
    cfe/trunk/lib/Lex/PPExpressions.cpp
    cfe/trunk/test/Lexer/number.c

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=53070&r1=53069&r2=53070&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Wed Jul  2 22:47:30 2008
@@ -198,7 +198,8 @@
       // 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 @@
     // 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)

Modified: cfe/trunk/test/Lexer/number.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/number.c?rev=53070&r1=53069&r2=53070&view=diff

==============================================================================
--- cfe/trunk/test/Lexer/number.c (original)
+++ cfe/trunk/test/Lexer/number.c Wed Jul  2 22:47:30 2008
@@ -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
+





More information about the cfe-commits mailing list