]> granicus.if.org Git - llvm/commitdiff
[MC] Fix Error Location for ParseIdentifier
authorNirav Dave <niravd@google.com>
Wed, 12 Oct 2016 13:58:07 +0000 (13:58 +0000)
committerNirav Dave <niravd@google.com>
Wed, 12 Oct 2016 13:58:07 +0000 (13:58 +0000)
Prevent partial parsing of '$' or '@' of invalid identifiers and fixup
workaround points. NFC Intended.

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

lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/at-pseudo-variable-bad.s
test/MC/Mips/cpsetup-bad.s

index f4de6343660f2f64a0b25389c0d5dd76e345bc70..e817a8fa57df9610ed2f14ee98ebd34aae0555dd 100644 (file)
@@ -924,8 +924,10 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
   case AsmToken::Identifier: {
     StringRef Identifier;
     if (parseIdentifier(Identifier)) {
-      if (FirstTokenKind == AsmToken::Dollar) {
+      // We may have failed but $ may be a valid token.
+      if (getTok().is(AsmToken::Dollar)) {
         if (Lexer.getMAI().getDollarIsPC()) {
+          Lex();
           // This is a '$' reference, which references the current PC.  Emit a
           // temporary label to the streamer and refer to it.
           MCSymbol *Sym = Ctx.createTempSymbol();
@@ -2607,14 +2609,19 @@ bool AsmParser::parseIdentifier(StringRef &Res) {
     SMLoc PrefixLoc = getLexer().getLoc();
 
     // Consume the prefix character, and check for a following identifier.
-    Lexer.Lex(); // Lexer's Lex guarantees consecutive token.
-    if (Lexer.isNot(AsmToken::Identifier))
+
+    AsmToken Buf[1];
+    Lexer.peekTokens(Buf, false);
+
+    if (Buf[0].isNot(AsmToken::Identifier))
       return true;
 
     // We have a '$' or '@' followed by an identifier, make sure they are adjacent.
-    if (PrefixLoc.getPointer() + 1 != getTok().getLoc().getPointer())
+    if (PrefixLoc.getPointer() + 1 != Buf[0].getLoc().getPointer())
       return true;
 
+    // eat $ or @
+    Lexer.Lex(); // Lexer's Lex guarantees consecutive token.
     // Construct the joined identifier and consume the token.
     Res =
         StringRef(PrefixLoc.getPointer(), getTok().getIdentifier().size() + 1);
index 885f18b2d4f4517d15bb42f9d79877ab73dfde54..0859cab82a025f37a7edebdd3664b1630d4e61a3 100644 (file)
@@ -6,7 +6,7 @@ add  $1\@, %eax
 .macro A @
   mov  %eax, %eax
 .endm
-# CHECK: :[[@LINE-3]]:11: error: expected identifier in '.macro' directive
+# CHECK: :[[@LINE-3]]:10: error: expected identifier in '.macro' directive
 
 .rept 2
   addi $8, $8, \@
index ec6525a195f13829d3c87ed0d87eea2f5128b8cd..4b2148603bd093151da8e69d5129334750cf749b 100644 (file)
@@ -13,7 +13,7 @@ t1:
         .cpsetup $31, $32, __cerror
 # ASM: :[[@LINE-1]]:23: error: invalid register
         .cpsetup $25, $2, $3
-# ASM: :[[@LINE-1]]:28: error: expected expression
+# ASM: :[[@LINE-1]]:27: error: expected expression
         .cpsetup $25, $2, 4
 # ASM: :[[@LINE-1]]:28: error: expected symbol
         .cpsetup $25, $2, 4+65