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