[llvm] 6aa8521 - [RISCV] Fix parseBareSymbol to not double-parse top-level operators
Jessica Clarke via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 27 12:48:56 PST 2022
Author: Jessica Clarke
Date: 2022-02-27T20:48:52Z
New Revision: 6aa8521fdb7a551e32927cce71ecb0c424b51955
URL: https://github.com/llvm/llvm-project/commit/6aa8521fdb7a551e32927cce71ecb0c424b51955
DIFF: https://github.com/llvm/llvm-project/commit/6aa8521fdb7a551e32927cce71ecb0c424b51955.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
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 df1ed414d915..c3f859b2c61d 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1613,9 +1613,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 859f5fe640f6..7a20cfc292fb 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-commits
mailing list