Skip to content

Commit 19fb4b0

Browse files
authored
[RISCV] Validate the end of register ranges in Zcmp register lists. (#133866)
We were only checking that the last register was a register, not that it was a legal register for a register list. This caused the encoder function to hit an llvm_unreachable. The error messages are not good, but this only one of multiple things that need to be fixed in this function. I'll focus on error messages later once I have the other issues fixed.
1 parent 8741412 commit 19fb4b0

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,7 +2620,8 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
26202620
StringRef EndName = getLexer().getTok().getIdentifier();
26212621
// FIXME: the register mapping and checks of EABI is wrong
26222622
RegEnd = matchRegisterNameHelper(EndName);
2623-
if (!RegEnd)
2623+
if (!(RegEnd == RISCV::X9 ||
2624+
(RegEnd >= RISCV::X18 && RegEnd <= RISCV::X27)))
26242625
return Error(getLoc(), "invalid register");
26252626
if (IsEABI && RegEnd != RISCV::X9)
26262627
return Error(getLoc(), "contiguous register list of EABI can only be "
@@ -2653,7 +2654,7 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
26532654
return Error(getLoc(), "invalid register");
26542655
EndName = getLexer().getTok().getIdentifier();
26552656
RegEnd = MatchRegisterName(EndName);
2656-
if (!RegEnd)
2657+
if (!(RegEnd >= RISCV::X19 && RegEnd <= RISCV::X27))
26572658
return Error(getLoc(), "invalid register");
26582659
getLexer().Lex();
26592660
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,23 @@ cm.pop {ra, s0-s1}, -32
2525
# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
2626
cm.push {ra}, -8
2727

28-
# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
29-
cm.pop {ra, s0-s1}, -40
28+
# CHECK-ERROR: :[[@LINE+1]]:9: error: register list must start from 'ra' or 'x1'
29+
cm.pop {s0}, -40
30+
31+
# CHECK-ERROR: :[[@LINE+1]]:13: error: continuous register list must start from 's0' or 'x8'
32+
cm.pop {ra, t1}, -40
33+
34+
# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
35+
cm.pop {ra, s0-t1}, -40
36+
37+
# CHECK-ERROR: :[[@LINE+1]]:20: error: second contiguous registers pair of register list must start from 'x18'
38+
cm.pop {ra, x8-x9, x28}, -40
39+
40+
# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
41+
cm.pop {ra, x8-x9, x18-x28}, -40
42+
43+
# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
44+
cm.pop {ra, x8-x9, x18-x17}, -40
45+
46+
# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
47+
cm.pop {ra, x8-f8, x18-x17}, -40

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,24 @@ cm.push {ra}, -15
2727

2828
# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
2929
cm.pop {ra, s0-s1}, -33
30+
31+
# CHECK-ERROR: :[[@LINE+1]]:9: error: register list must start from 'ra' or 'x1'
32+
cm.pop {s0}, -40
33+
34+
# CHECK-ERROR: :[[@LINE+1]]:13: error: continuous register list must start from 's0' or 'x8'
35+
cm.pop {ra, t1}, -40
36+
37+
# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
38+
cm.pop {ra, s0-t1}, -40
39+
40+
# CHECK-ERROR: :[[@LINE+1]]:20: error: second contiguous registers pair of register list must start from 'x18'
41+
cm.pop {ra, x8-x9, x28}, -40
42+
43+
# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
44+
cm.pop {ra, x8-x9, x18-x28}, -40
45+
46+
# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
47+
cm.pop {ra, x8-x9, x18-x17}, -40
48+
49+
# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
50+
cm.pop {ra, x8-f8, x18-x17}, -40

0 commit comments

Comments
 (0)