[llvm-branch-commits] [llvm] 4de8e56 - [RISCV] Fix parseBareSymbol to not double-parse top-level operators
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Feb 28 15:20:39 PST 2022
Author: Jessica Clarke
Date: 2022-02-28T15:18:17-08:00
New Revision: 4de8e56982784b4eafa7df70662129cb553a5f10
URL: https://github.com/llvm/llvm-project/commit/4de8e56982784b4eafa7df70662129cb553a5f10
DIFF: https://github.com/llvm/llvm-project/commit/4de8e56982784b4eafa7df70662129cb553a5f10.diff
LOG: [RISCV] Fix parseBareSymbol to not double-parse top-level operators
By failing to lex the token we end up both parsing it as a binary
operator ourselves and parsing it as a unary operator when calling
parseExpression on the RHS. For plus this is harmless but for minus this
parses "foo - 4" as "foo - -4", effectively treating a top-level minus
as a plus.
Fixes https://github.com/llvm/llvm-project/issues/54105
Reviewed By: asb, MaskRay
Differential Revision: https://reviews.llvm.org/D120635
(cherry picked from commit 6aa8521fdb7a551e32927cce71ecb0c424b51955)
Added:
Modified:
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/test/MC/RISCV/rvi-pseudos.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 95319d1b0b74e..9a6ffb20615b2 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1607,9 +1607,11 @@ OperandMatchResultTy RISCVAsmParser::parseBareSymbol(OperandVector &Operands) {
return MatchOperand_Success;
case AsmToken::Plus:
Opcode = MCBinaryExpr::Add;
+ getLexer().Lex();
break;
case AsmToken::Minus:
Opcode = MCBinaryExpr::Sub;
+ getLexer().Lex();
break;
}
diff --git a/llvm/test/MC/RISCV/rvi-pseudos.s b/llvm/test/MC/RISCV/rvi-pseudos.s
index 859f5fe640f6e..7a20cfc292fbc 100644
--- a/llvm/test/MC/RISCV/rvi-pseudos.s
+++ b/llvm/test/MC/RISCV/rvi-pseudos.s
@@ -187,3 +187,9 @@ sw a3, zero, a4
# CHECK: auipc a5, %pcrel_hi((255+a_symbol)-4)
# CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi30)
lla a5, (0xFF + a_symbol) - 4
+
+## Check that we don't double-parse a top-level minus.
+# CHECK: .Lpcrel_hi31:
+# CHECK: auipc a5, %pcrel_hi(a_symbol-4)
+# CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi31)
+lla a5, a_symbol - 4
More information about the llvm-branch-commits
mailing list