Skip to content

Commit aebe6c5

Browse files
authored
[RISCV] Improve Errors for X1/X5/X1X5 Reg Classes (#126184)
LLVM has functionality for producing a register-class-specific error message in the assembly parser, rather than just emitting the generic "invalid operand for instruction" error. This starts the gradual adoption of this functionality for RISC-V, with some lesser-used shadow-stack register classes: - GPRX1 (only contains `ra`) - GPRX5 (only contains `t0`) - GPRX1X5 (only contains `ra` and `t0`) LLVM is reasonably conservative about when these errors are used, in particular you have to have all the features for the relevant mnemonic enabled before it will do, hence the test updates. This also merges a pair of almost identical rv32/rv64 test files into a single file with one run line.
1 parent 70fdd9f commit aebe6c5

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,16 @@ def GPR : GPRRegisterClass<(add (sequence "X%u", 10, 17),
247247
(sequence "X%u", 0, 4))>;
248248

249249
def GPRX0 : GPRRegisterClass<(add X0)>;
250-
def GPRX1 : GPRRegisterClass<(add X1)>;
251-
def GPRX5 : GPRRegisterClass<(add X5)>;
250+
251+
def GPRX1 : GPRRegisterClass<(add X1)> {
252+
let DiagnosticType = "InvalidRegClassGPRX1";
253+
let DiagnosticString = "register must be ra (x1)";
254+
}
255+
256+
def GPRX5 : GPRRegisterClass<(add X5)> {
257+
let DiagnosticType = "InvalidRegClassGPRX5";
258+
let DiagnosticString = "register must be t0 (x5)";
259+
}
252260

253261
def GPRNoX0 : GPRRegisterClass<(sub GPR, X0)>;
254262

@@ -282,7 +290,10 @@ def SP : GPRRegisterClass<(add X2)>;
282290
def SR07 : GPRRegisterClass<(add (sequence "X%u", 8, 9),
283291
(sequence "X%u", 18, 23))>;
284292

285-
def GPRX1X5 : GPRRegisterClass<(add X1, X5)>;
293+
def GPRX1X5 : GPRRegisterClass<(add X1, X5)> {
294+
let DiagnosticType = "InvalidRegClassGPRX1X5";
295+
let DiagnosticString = "register must be ra or t0 (x1 or x5)";
296+
}
286297

287298
//===----------------------------------------------------------------------===//
288299
// Even-Odd GPR Pairs

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

Lines changed: 0 additions & 17 deletions
This file was deleted.

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

Lines changed: 0 additions & 17 deletions
This file was deleted.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: not llvm-mc %s -triple=riscv32 -mattr=+experimental-zicfiss,+zcmop,+c -M no-aliases -show-encoding \
2+
# RUN: 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s
3+
# RUN: not llvm-mc %s -triple=riscv64 -mattr=+experimental-zicfiss,+zcmop,+c -M no-aliases -show-encoding \
4+
# RUN: 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s
5+
6+
# CHECK-ERR: error: register must be ra or t0 (x1 or x5)
7+
sspopchk a1
8+
9+
# CHECK-ERR: error: register must be ra (x1)
10+
c.sspush t0
11+
12+
# CHECK-ERR: error: register must be t0 (x5)
13+
c.sspopchk ra
14+
15+
# CHECK-ERR: error: register must be ra or t0 (x1 or x5)
16+
sspush a0
17+
18+
# CHECK-ERR: error: invalid operand for instruction
19+
ssrdp zero

0 commit comments

Comments
 (0)