Skip to content

Commit 3ea7902

Browse files
authored
[RISCV] Check S0 register list check for qc.cm.pushfp to after we parsed the whole register list. (#134180)
This is more of a semantic check. The diagnostic location to has been changed 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 4998273 commit 3ea7902

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
@@ -2592,20 +2592,8 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
25922592
return Error(getLoc(), "register list must start from 'ra' or 'x1'");
25932593
getLexer().Lex();
25942594

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

26692657
auto Encode = RISCVZC::encodeRlist(RegEnd, IsRVE);
26702658
assert(Encode != RISCVZC::INVALID_RLIST);
2671-
if (MustIncludeS0)
2672-
assert(Encode != RISCVZC::RA);
2659+
2660+
if (MustIncludeS0 && Encode == RISCVZC::RA)
2661+
return Error(S, "register list must include 's0' or 'x8'");
2662+
26732663
Operands.push_back(RISCVOperand::createRlist(Encode, S));
26742664

26752665
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)