diff options
author | Nirav Dave <niravd@google.com> | 2016-10-12 13:58:07 +0000 |
---|---|---|
committer | Nirav Dave <niravd@google.com> | 2016-10-12 13:58:07 +0000 |
commit | d046332679ada51644bff7f7a06352ae97d7b97e (patch) | |
tree | b81dda54ca54bd48eeb924d9e5335c87b6465f3f /llvm/lib/MC/MCParser/AsmParser.cpp | |
parent | 9f50fffc0487b74b1828afc4f63d2a8df586df51 (diff) | |
download | bcm5719-llvm-d046332679ada51644bff7f7a06352ae97d7b97e.tar.gz bcm5719-llvm-d046332679ada51644bff7f7a06352ae97d7b97e.zip |
[MC] Fix Error Location for ParseIdentifier
Prevent partial parsing of '$' or '@' of invalid identifiers and fixup
workaround points. NFC Intended.
llvm-svn: 284017
Diffstat (limited to 'llvm/lib/MC/MCParser/AsmParser.cpp')
-rw-r--r-- | llvm/lib/MC/MCParser/AsmParser.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index f4de6343660..e817a8fa57d 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -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); |