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

Chris Lattner sabre at nondot.org
Sun Jun 29 23:44:50 PDT 2008


Author: lattner
Date: Mon Jun 30 01:44:49 2008
New Revision: 52890

URL: http://llvm.org/viewvc/llvm-project?rev=52890&view=rev
Log:
Fix a bug reported by Kelly Wilson, where we incorrectly
rejected FP immediates like 08.123

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

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

==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Mon Jun 30 01:44:49 2008
@@ -376,6 +376,7 @@
   // Handle simple binary numbers 0b01010
   if (*s == 'b' || *s == 'B') {
     // 0b101010 is a GCC extension.
+    PP.Diag(TokLoc, diag::ext_binary_literal);
     ++s;
     radix = 2;
     DigitsBegin = s;
@@ -385,10 +386,8 @@
     } else if (isxdigit(*s)) {
       Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin),
            diag::err_invalid_binary_digit, std::string(s, s+1));
-      return;
     }
-    // Otherwise suffixes will be diagnosed by the caller.
-    PP.Diag(TokLoc, diag::ext_binary_literal);
+    // Other suffixes will be diagnosed by the caller.
     return;
   }
   
@@ -401,6 +400,18 @@
   if (s == ThisTokEnd)
     return; // Done, simple octal number like 01234
   
+  // If we have some other non-octal digit that *is* a decimal digit, see if
+  // this is part of a floating point number like 094.123 or 09e1.
+  if (isdigit(*s)) {
+    const char *EndDecimal = SkipDigits(s);
+    if (EndDecimal[0] == '.' || EndDecimal[0] == 'e' || EndDecimal[0] == 'E') {
+      s = EndDecimal;
+      radix = 10;
+    }
+  }
+  
+  // If we have a hex digit other than 'e' (which denotes a FP exponent) then
+  // the code is using an incorrect base.
   if (isxdigit(*s) && *s != 'e' && *s != 'E') {
     Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin),
          diag::err_invalid_octal_digit, std::string(s, s+1));
@@ -411,7 +422,7 @@
     s++;
     radix = 10;
     saw_period = true;
-    s = SkipDigits(s);
+    s = SkipDigits(s); // Skip suffix.
   }
   if (*s == 'e' || *s == 'E') { // exponent
     const char *Exponent = s;

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

==============================================================================
--- cfe/trunk/test/Lexer/number.c (original)
+++ cfe/trunk/test/Lexer/number.c Mon Jun 30 01:44:49 2008
@@ -2,3 +2,5 @@
 
 float X = 1.17549435e-38F;
 
+float Y = 08.123456;
+





More information about the cfe-commits mailing list