Skip to content

[RISCV] Validate the end of register ranges in Zcmp register lists. #133866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2616,7 +2616,8 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
StringRef EndName = getLexer().getTok().getIdentifier();
// FIXME: the register mapping and checks of EABI is wrong
RegEnd = matchRegisterNameHelper(EndName);
if (!RegEnd)
if (!(RegEnd == RISCV::X9 ||
(RegEnd >= RISCV::X18 && RegEnd <= RISCV::X27)))
return Error(getLoc(), "invalid register");
if (IsEABI && RegEnd != RISCV::X9)
return Error(getLoc(), "contiguous register list of EABI can only be "
Expand Down Expand Up @@ -2649,7 +2650,7 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
return Error(getLoc(), "invalid register");
EndName = getLexer().getTok().getIdentifier();
RegEnd = MatchRegisterName(EndName);
if (!RegEnd)
if (!(RegEnd >= RISCV::X19 && RegEnd <= RISCV::X27))
return Error(getLoc(), "invalid register");
getLexer().Lex();
}
Expand Down
22 changes: 20 additions & 2 deletions llvm/test/MC/RISCV/rv32zcmp-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,23 @@ cm.pop {ra, s0-s1}, -32
# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
cm.push {ra}, -8

# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
cm.pop {ra, s0-s1}, -40
# CHECK-ERROR: :[[@LINE+1]]:9: error: register list must start from 'ra' or 'x1'
cm.pop {s0}, -40

# CHECK-ERROR: :[[@LINE+1]]:13: error: continuous register list must start from 's0' or 'x8'
cm.pop {ra, t1}, -40

# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
cm.pop {ra, s0-t1}, -40

# CHECK-ERROR: :[[@LINE+1]]:20: error: second contiguous registers pair of register list must start from 'x18'
cm.pop {ra, x8-x9, x28}, -40

# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
cm.pop {ra, x8-x9, x18-x28}, -40

# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
cm.pop {ra, x8-x9, x18-x17}, -40

# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
cm.pop {ra, x8-f8, x18-x17}, -40
21 changes: 21 additions & 0 deletions llvm/test/MC/RISCV/rv64zcmp-invalid.s
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,24 @@ cm.push {ra}, -15

# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
cm.pop {ra, s0-s1}, -33

# CHECK-ERROR: :[[@LINE+1]]:9: error: register list must start from 'ra' or 'x1'
cm.pop {s0}, -40

# CHECK-ERROR: :[[@LINE+1]]:13: error: continuous register list must start from 's0' or 'x8'
cm.pop {ra, t1}, -40

# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
cm.pop {ra, s0-t1}, -40

# CHECK-ERROR: :[[@LINE+1]]:20: error: second contiguous registers pair of register list must start from 'x18'
cm.pop {ra, x8-x9, x28}, -40

# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
cm.pop {ra, x8-x9, x18-x28}, -40

# CHECK-ERROR: :[[@LINE+1]]:24: error: invalid register
cm.pop {ra, x8-x9, x18-x17}, -40

# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
cm.pop {ra, x8-f8, x18-x17}, -40