fix rdar://7997827 - Accept and ignore LL and ULL suffixes on integer literals.
authorChris Lattner <sabre@nondot.org>
Tue, 24 Aug 2010 00:43:25 +0000 (00:43 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 24 Aug 2010 00:43:25 +0000 (00:43 +0000)
Also fix 0b010 syntax to actually work while we're at it :-)

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

lib/MC/MCParser/AsmLexer.cpp
test/MC/AsmParser/directive_values.s

index 465d98382877b83b83efa1a8b0b9463bf1909de4..086df081a938f0ebebedb7880aca3fddd3b16c03 100644 (file)
@@ -117,6 +117,13 @@ AsmToken AsmLexer::LexLineComment() {
   return AsmToken(AsmToken::EndOfStatement, StringRef(CurPtr, 0));
 }
 
+static void SkipIgnoredIntegerSuffix(const char *&CurPtr) {
+  if (CurPtr[0] == 'L' && CurPtr[1] == 'L')
+    CurPtr += 2;
+  if (CurPtr[0] == 'U' && CurPtr[1] == 'L' && CurPtr[2] == 'L')
+    CurPtr += 3;
+}
+
 
 /// LexDigit: First character is [0-9].
 ///   Local Label: [0-9][:]
@@ -133,7 +140,7 @@ AsmToken AsmLexer::LexDigit() {
       ++CurPtr;
     
     StringRef Result(TokStart, CurPtr - TokStart);
-    
+
     long long Value;
     if (Result.getAsInteger(10, Value)) {
       // We have to handle minint_as_a_positive_value specially, because
@@ -143,6 +150,11 @@ AsmToken AsmLexer::LexDigit() {
       else
         return ReturnError(TokStart, "Invalid decimal number");
     }
+    
+    // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
+    // suffixes on integer literals.
+    SkipIgnoredIntegerSuffix(CurPtr);
+    
     return AsmToken(AsmToken::Integer, Result, Value);
   }
   
@@ -165,9 +177,13 @@ AsmToken AsmLexer::LexDigit() {
     StringRef Result(TokStart, CurPtr - TokStart);
     
     long long Value;
-    if (Result.getAsInteger(2, Value))
+    if (Result.substr(2).getAsInteger(2, Value))
       return ReturnError(TokStart, "Invalid binary number");
     
+    // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
+    // suffixes on integer literals.
+    SkipIgnoredIntegerSuffix(CurPtr);
+    
     return AsmToken(AsmToken::Integer, Result, Value);
   }
  
@@ -185,6 +201,10 @@ AsmToken AsmLexer::LexDigit() {
     if (StringRef(TokStart, CurPtr - TokStart).getAsInteger(0, Result))
       return ReturnError(TokStart, "Invalid hexadecimal number");
       
+    // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
+    // suffixes on integer literals.
+    SkipIgnoredIntegerSuffix(CurPtr);
+    
     return AsmToken(AsmToken::Integer, StringRef(TokStart, CurPtr - TokStart),
                     (int64_t)Result);
   }
@@ -198,6 +218,10 @@ AsmToken AsmLexer::LexDigit() {
   if (Result.getAsInteger(8, Value))
     return ReturnError(TokStart, "Invalid octal number");
   
+  // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
+  // suffixes on integer literals.
+  SkipIgnoredIntegerSuffix(CurPtr);
+  
   return AsmToken(AsmToken::Integer, Result, Value);
 }
 
index beac69a4aeb1d72e1f0ba2b73a8b43af24fb76ba..c7617a337e02f146037391d06ea6e23fc92b878d 100644 (file)
@@ -19,3 +19,20 @@ TEST2:
 # CHECK: .quad 9
 TEST3:  
         .quad 9
+
+
+# rdar://7997827
+TEST4:
+        .quad 0b0100
+        .quad 4294967295
+        .quad 4294967295+1
+        .quad 4294967295LL+1
+        .quad 0b10LL + 07ULL + 0x42AULL
+# CHECK: TEST4
+# CHECK:       .quad   4
+# CHECK: .quad 4294967295
+# CHECK:       .quad   4294967296
+# CHECK:       .quad   4294967296
+# CHECK:       .quad   1075
+
+