[PATCH] D57319: [RISCV] Fix failure to parse parenthesized immediates
Lewis Revill via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 28 03:06:05 PST 2019
lewis-revill created this revision.
lewis-revill added a reviewer: asb.
Herald added subscribers: llvm-commits, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, apazos, simoncook, johnrusso, rbar.
Since the parser attempts to parse an operand as a register with parentheses before parsing it as an immediate, immediates in parenthesis should not be parsed by parseRegister. However in the case where the immediate does not start with an identifier, the LParen is not unlexed and so the RParen causes an unexpected token error.
This patch adds the missing UnLex, and modifies the existing UnLex to not use a buffered token, as it should always be unlexing an LParen.
Repository:
rL LLVM
https://reviews.llvm.org/D57319
Files:
lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
test/MC/RISCV/rv32i-valid.s
Index: test/MC/RISCV/rv32i-valid.s
===================================================================
--- test/MC/RISCV/rv32i-valid.s
+++ test/MC/RISCV/rv32i-valid.s
@@ -128,6 +128,9 @@
lb s3, 4(ra)
# CHECK-ASM-AND-OBJ: lb s3, 4(ra)
# CHECK-ASM: encoding: [0x83,0x89,0x40,0x00]
+lb s3, (4)(ra)
+# CHECK-ASM-AND-OBJ: lb s3, 4(ra)
+# CHECK-ASM: encoding: [0x83,0x89,0x40,0x00]
lb s3, +4(ra)
# CHECK-ASM-AND-OBJ: lh t1, -2048(zero)
# CHECK-ASM: encoding: [0x03,0x13,0x00,0x80]
Index: lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===================================================================
--- lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -925,6 +925,8 @@
switch (getLexer().getKind()) {
default:
+ if (HadParens)
+ getLexer().UnLex(AsmToken(AsmToken::LParen, "("));
return MatchOperand_NoMatch;
case AsmToken::Identifier:
StringRef Name = getLexer().getTok().getIdentifier();
@@ -933,7 +935,7 @@
RegNo = MatchRegisterAltName(Name);
if (RegNo == 0) {
if (HadParens)
- getLexer().UnLex(Buf[0]);
+ getLexer().UnLex(AsmToken(AsmToken::LParen, "("));
return MatchOperand_NoMatch;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57319.183815.patch
Type: text/x-patch
Size: 1237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190128/e8e4be8d/attachment.bin>
More information about the llvm-commits
mailing list