]> granicus.if.org Git - clang/commitdiff
improve isHexaLiteral to work with escaped newlines and trigraphs,
authorChris Lattner <sabre@nondot.org>
Tue, 31 Aug 2010 16:42:00 +0000 (16:42 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 31 Aug 2010 16:42:00 +0000 (16:42 +0000)
patch by Francois Pichet!

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

lib/Lex/Lexer.cpp
test/Lexer/ms-extensions.c

index 98277a444f75bf33d9fc3067093c0037b0fe9de8..917829be47c6a86321c9f7bb88fbade70fee0e71 100644 (file)
@@ -921,13 +921,14 @@ FinishIdentifier:
 }
 
 /// isHexaLiteral - Return true if Start points to a hex constant.
-/// FIXME: This isn't correct, it will mislex:
-///     0\       <- escaped newline.
-///     x1234e+1
 /// in microsoft mode (where this is supposed to be several different tokens).
-static inline bool isHexaLiteral(const char *Start, const char *End) {
-  return ((End - Start > 2) && Start[0] == '0' && 
-          (Start[1] == 'x' || Start[1] == 'X'));
+static bool isHexaLiteral(const char *Start, const LangOptions &Features) {
+  unsigned Size;
+  char C1 = Lexer::getCharAndSizeNoWarn(Start, Size, Features);
+  if (C1 != '0')
+    return false;
+  char C2 = Lexer::getCharAndSizeNoWarn(Start + Size, Size, Features);
+  return (C2 == 'x' || C2 == 'X');
 }
 
 /// LexNumericConstant - Lex the remainder of a integer or floating point
@@ -947,7 +948,7 @@ void Lexer::LexNumericConstant(Token &Result, const char *CurPtr) {
   if ((C == '-' || C == '+') && (PrevCh == 'E' || PrevCh == 'e')) {
     // If we are in Microsoft mode, don't continue if the constant is hex.
     // For example, MSVC will accept the following as 3 tokens: 0x1234567e+1
-    if (!Features.Microsoft || !isHexaLiteral(BufferPtr, CurPtr))
+    if (!Features.Microsoft || !isHexaLiteral(BufferPtr, Features))
       return LexNumericConstant(Result, ConsumeChar(CurPtr, Size, Result));
   }
 
index 5b45ab4ab54fb12632d2b68813651c0e736964e6..8b7d2e1efc0c3b3d8064277788ba8d0d05d135e2 100644 (file)
@@ -30,4 +30,12 @@ void pr_7968()
   int var2 = 0X1111111e+1;
   int var3 = 0xe+1;
   int var4 = 0XE+1;
+
+  int var5=    0\
+x1234e+1;
+
+  int var6=
+  /*expected-warning {{backslash and newline separated by space}} */    0\       
+x1234e+1;                      
 }
+