Skip to content

Commit c522add

Browse files
committed
[RISCV] Check S0 register list check for qc.cm.pushfp to after we parsed the whole register list.
In my mind, this is more of a semantic check. I've also changed the diagnostic location to point at the register list start instead of the closing brace, or whatever character might be there instead of a brace if its malformed.
1 parent ffed176 commit c522add

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,20 +2588,8 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
25882588
return Error(getLoc(), "register list must start from 'ra' or 'x1'");
25892589
getLexer().Lex();
25902590

2591-
bool SeenComma = parseOptionalToken(AsmToken::Comma);
2592-
2593-
// There are two choices here:
2594-
// - `s0` is not required (usual case), so only try to parse `s0` if there is
2595-
// a comma
2596-
// - `s0` is required (qc.cm.pushfp), and so we must see the comma between
2597-
// `ra` and `s0` and must always try to parse `s0`, below
2598-
if (MustIncludeS0 && !SeenComma) {
2599-
Error(getLoc(), "register list must include 's0' or 'x8'");
2600-
return ParseStatus::Failure;
2601-
}
2602-
26032591
// parse case like ,s0 (knowing the comma must be there if required)
2604-
if (SeenComma) {
2592+
if (parseOptionalToken(AsmToken::Comma)) {
26052593
if (getLexer().isNot(AsmToken::Identifier))
26062594
return Error(getLoc(), "invalid register");
26072595
StringRef RegName = getLexer().getTok().getIdentifier();
@@ -2664,8 +2652,10 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
26642652

26652653
auto Encode = RISCVZC::encodeRlist(RegEnd, IsRVE);
26662654
assert(Encode != RISCVZC::INVALID_RLIST);
2667-
if (MustIncludeS0)
2668-
assert(Encode != RISCVZC::RA);
2655+
2656+
if (MustIncludeS0 && Encode == RISCVZC::RA)
2657+
return Error(S, "register list must include 's0' or 'x8'");
2658+
26692659
Operands.push_back(RISCVOperand::createRlist(Encode, S));
26702660

26712661
return ParseStatus::Success;

llvm/test/MC/RISCV/rv32xqccmp-invalid.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ qc.cm.pushfp {ra, s0}, -12
3434
# CHECK-ERROR: :[[@LINE+1]]:24: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
3535
qc.cm.pop {ra, s0-s1}, -40
3636

37-
# CHECK-ERROR: :[[@LINE+1]]:17: error: register list must include 's0' or 'x8'
37+
# CHECK-ERROR: :[[@LINE+1]]:14: error: register list must include 's0' or 'x8'
3838
qc.cm.pushfp {ra}, -16
3939

0 commit comments

Comments
 (0)