[PATCH] D153204: RISCVAsmParser: support comments in more places
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 17 10:22:46 PDT 2023
MaskRay created this revision.
MaskRay added reviewers: asb, craig.topper, jrtc27, abel-bernabeu.
Herald added subscribers: luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD.
Herald added a project: LLVM.
Currently we fail to parse an instruction when comments occur in certain places
(e.g. after a register, after a bare symbol). Call MCAsmParser::Lex instead of
MCAsmLexer::Lex to fix the issue by consuming the comments.
Reported by https://discourse.llvm.org/t/interleaving-several-c-style-comments-in-the-same-inline-assembly-line/71353
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153204
Files:
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/test/MC/RISCV/rvi-pseudos.s
Index: llvm/test/MC/RISCV/rvi-pseudos.s
===================================================================
--- llvm/test/MC/RISCV/rvi-pseudos.s
+++ llvm/test/MC/RISCV/rvi-pseudos.s
@@ -229,3 +229,13 @@
# CHECK: auipc a5, %pcrel_hi(a_symbol-4)
# CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi37)
lla a5, a_symbol - 4
+
+# CHECK: .Lpcrel_hi38:
+# CHECK: auipc a5, %pcrel_hi(a_symbol-5)
+# CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi38)
+/**/lla /**/a5/**/, /**/a_symbol/**/ - /**/5/**/
+
+# CHECK: .Lpcrel_hi39:
+# CHECK: auipc a5, %pcrel_hi(a_symbol+5)
+# CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi39)
+/**/lla /**/a5/**/, /**/a_symbol/**/ + /**/5/**/
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===================================================================
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1617,7 +1617,7 @@
Operands.push_back(RISCVOperand::createToken("(", FirstS));
SMLoc S = getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());
- getLexer().Lex();
+ Lex();
Operands.push_back(RISCVOperand::createReg(RegNo, S, E));
}
@@ -1978,11 +1978,11 @@
return MatchOperand_Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
- getLexer().Lex();
+ Lex();
break;
case AsmToken::Minus:
Opcode = MCBinaryExpr::Sub;
- getLexer().Lex();
+ Lex();
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153204.532413.patch
Type: text/x-patch
Size: 1444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230617/982e6699/attachment.bin>
More information about the llvm-commits
mailing list