[llvm] r284017 - [MC] Fix Error Location for ParseIdentifier
Nirav Dave via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 12 06:58:08 PDT 2016
Author: niravd
Date: Wed Oct 12 08:58:07 2016
New Revision: 284017
URL: http://llvm.org/viewvc/llvm-project?rev=284017&view=rev
Log:
[MC] Fix Error Location for ParseIdentifier
Prevent partial parsing of '$' or '@' of invalid identifiers and fixup
workaround points. NFC Intended.
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/test/MC/AsmParser/at-pseudo-variable-bad.s
llvm/trunk/test/MC/Mips/cpsetup-bad.s
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=284017&r1=284016&r2=284017&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Oct 12 08:58:07 2016
@@ -924,8 +924,10 @@ bool AsmParser::parsePrimaryExpr(const M
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(StringRe
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);
Modified: llvm/trunk/test/MC/AsmParser/at-pseudo-variable-bad.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/at-pseudo-variable-bad.s?rev=284017&r1=284016&r2=284017&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/at-pseudo-variable-bad.s (original)
+++ llvm/trunk/test/MC/AsmParser/at-pseudo-variable-bad.s Wed Oct 12 08:58:07 2016
@@ -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, \@
Modified: llvm/trunk/test/MC/Mips/cpsetup-bad.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/cpsetup-bad.s?rev=284017&r1=284016&r2=284017&view=diff
==============================================================================
--- llvm/trunk/test/MC/Mips/cpsetup-bad.s (original)
+++ llvm/trunk/test/MC/Mips/cpsetup-bad.s Wed Oct 12 08:58:07 2016
@@ -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
More information about the llvm-commits
mailing list