Skip to content

Commit 07161a3

Browse files
committed
[RISCV] Return NoMatch if register list does not start with a curly brace.
This way we emit the error message that explains the full syntax for a register list. parseZcmpStackAdj had to be modified to not assume the previous operand had been successfully parsed as a register list.
1 parent 4090910 commit 07161a3

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Diff for: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -2576,10 +2576,12 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
25762576
// must include `fp`/`s0` in the list:
25772577
// Rlist: {ra, s0[-sN]}
25782578
// XRlist: {x1, x8[-x9][, x18[-xN]]}
2579-
SMLoc S = getLoc();
25802579

2581-
if (parseToken(AsmToken::LCurly, "register list must start with '{'"))
2582-
return ParseStatus::Failure;
2580+
if (getTok().isNot(AsmToken::LCurly))
2581+
return ParseStatus::NoMatch;
2582+
2583+
SMLoc S = getLoc();
2584+
Lex();
25832585

25842586
bool IsRVE = isRVE();
25852587

@@ -2674,7 +2676,12 @@ ParseStatus RISCVAsmParser::parseZcmpStackAdj(OperandVector &Operands,
26742676
return ParseStatus::NoMatch;
26752677

26762678
int64_t StackAdjustment = getTok().getIntVal();
2677-
unsigned RlistVal = static_cast<RISCVOperand *>(Operands[1].get())->Rlist.Val;
2679+
2680+
auto *RListOp = static_cast<RISCVOperand *>(Operands.back().get());
2681+
if (!RListOp->isRlist())
2682+
return ParseStatus::NoMatch;
2683+
2684+
unsigned RlistVal = RListOp->Rlist.Val;
26782685

26792686
assert(RlistVal != RISCVZC::INVALID_RLIST);
26802687
unsigned StackAdjBase = RISCVZC::getStackAdjBase(RlistVal, isRV64());

Diff for: llvm/test/MC/RISCV/rv32xqccmp-invalid.s

+5
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ qc.cm.pop {ra, s0-s1}, -40
3737
# CHECK-ERROR: :[[@LINE+1]]:14: error: register list must include 's0' or 'x8'
3838
qc.cm.pushfp {ra}, -16
3939

40+
# CHECK-ERROR: :[[@LINE+1]]:12: error: operand must be {ra [, s0[-sN]]} or {x1 [, x8[-x9][, x18[-xN]]]}
41+
qc.cm.push x1, -16
42+
43+
# CHECK-ERROR: :[[@LINE+1]]:14: error: operand must be {ra, s0[-sN]} or {x1, x8[-x9][, x18[-xN]]}
44+
qc.cm.pushfp x1, -16

Diff for: llvm/test/MC/RISCV/rv32zcmp-invalid.s

+3
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ cm.pop {ra, x8-x9, x18-x17}, -40
4545

4646
# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
4747
cm.pop {ra, x8-f8, x18-x17}, -40
48+
49+
# CHECK-ERROR: :[[@LINE+1]]:9: error: operand must be {ra [, s0[-sN]]} or {x1 [, x8[-x9][, x18[-xN]]]}
50+
cm.push x1, -16

0 commit comments

Comments
 (0)