[PATCH] RISC-V: Modify the error message for zilsd/zclsd
Dongyan Chen
chendongyan@isrc.iscas.ac.cn
Tue Aug 12 13:32:49 GMT 2025
Regarding the error messages caused by the use of register pairs in
"zilsd" and "zclsd", it is necessary to inform the users that they
need to use even-numbered register pairs.
bfd/ChangeLog:
* version.h (BFD_VERSION_DATE): Updated.
gas/ChangeLog:
* config/tc-riscv.c (riscv_ip): Select the error message.
* testsuite/gas/riscv/zilsd-zclsd-fail.l: Updated.
include/ChangeLog:
* opcode/riscv.h (riscv_get_sp_base): Declare.
opcodes/ChangeLog:
* riscv-opc.c (match_rd_even): Add error message.
(match_rs2_even): Ditto.
(match_crs2s_even): Ditto.
(match_crs2_even): Ditto.
---
bfd/version.h | 2 +-
gas/config/tc-riscv.c | 5 +++-
gas/testsuite/gas/riscv/zilsd-zclsd-fail.l | 14 +++++-----
include/opcode/riscv.h | 2 ++
opcodes/riscv-opc.c | 30 +++++++++++++++++++---
5 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/bfd/version.h b/bfd/version.h
index 7bdf479e492..9bf25d4a9cd 100644
--- a/bfd/version.h
+++ b/bfd/version.h
@@ -16,7 +16,7 @@
In releases, the date is not included in either version strings or
sonames. */
-#define BFD_VERSION_DATE 20250811
+#define BFD_VERSION_DATE 20250812
#define BFD_VERSION @bfd_version@
#define BFD_VERSION_STRING @bfd_version_package@ @bfd_version_string@
#define REPORT_BUGS_TO @report_bugs_to@
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 8a3356888d2..52a8abe0a58 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -2908,7 +2908,10 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
{
case '\0': /* End of args. */
if (insn->match_func && !insn->match_func (insn, ip->insn_opcode))
- break;
+ {
+ error.msg = riscv_match_error_msg ? riscv_match_error_msg : error.msg;
+ break;
+ }
if (insn->pinfo != INSN_MACRO)
{
diff --git a/gas/testsuite/gas/riscv/zilsd-zclsd-fail.l b/gas/testsuite/gas/riscv/zilsd-zclsd-fail.l
index 18e29039c6d..ccfed481fa5 100644
--- a/gas/testsuite/gas/riscv/zilsd-zclsd-fail.l
+++ b/gas/testsuite/gas/riscv/zilsd-zclsd-fail.l
@@ -1,15 +1,15 @@
.*: Assembler messages:
-.*: Error: illegal operands `ld x7,\(x5\)'
+.*: Error: rd must be an even `ld x7,\(x5\)'
.*: Error: illegal operands `ld x9,8\(x11\)'
.*: Error: illegal operands `ld x13,16\(x16\)'
.*: Error: illegal operands `sd x7,\(x5\)'
.*: Error: illegal operands `sd x9,8\(x11\)'
.*: Error: illegal operands `sd x13,16\(x16\)'
-.*: Error: illegal operands `c.ld x11,\(x9\)'
+.*: Error: crs2s must be an even `c.ld x11,\(x9\)'
.*: Error: illegal operands `c.ld x13,\(x16\)'
-.*: Error: illegal operands `c.ldsp x0,\(x2\)'
-.*: Error: illegal operands `c.ldsp x11,\(x2\)'
-.*: Error: illegal operands `c.sd x11,\(x9\)'
+.*: Error: crs2s must be an even `c.ldsp x0,\(x2\)'
+.*: Error: rd must be an even `c.ldsp x11,\(x2\)'
+.*: Error: crs2s must be an even `c.sd x11,\(x9\)'
.*: Error: illegal operands `c.sd x13,\(x16\)'
-.*: Error: illegal operands `c.sdsp x11,\(x2\)'
-.*: Error: illegal operands `c.sdsp x13,8\(x2\)'
+.*: Error: crs2 must be an even `c.sdsp x11,\(x2\)'
+.*: Error: crs2 must be an even `c.sdsp x13,8\(x2\)'
diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h
index 858fcce6871..470237365d0 100644
--- a/include/opcode/riscv.h
+++ b/include/opcode/riscv.h
@@ -732,4 +732,6 @@ extern const struct riscv_opcode riscv_insn_types[];
extern unsigned int riscv_get_sp_base (insn_t, unsigned int);
+extern const char * riscv_match_error_msg;
+
#endif /* _RISCV_H_ */
diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c
index 56ef62a622f..776c594d1e9 100644
--- a/opcodes/riscv-opc.c
+++ b/opcodes/riscv-opc.c
@@ -24,6 +24,8 @@
#include "opcode/riscv.h"
#include <stdio.h>
+const char * riscv_match_error_msg = NULL;
+
/* Register names used by gas and objdump. */
const char riscv_gpr_names_numeric[NGPR][NRC] =
@@ -210,14 +212,24 @@ static int
match_rd_even (const struct riscv_opcode *op, insn_t insn)
{
int rd = (insn & MASK_RD) >> OP_SH_RD;
- return ((rd & 1) == 0) && match_opcode (op, insn);
+ if ((rd & 1) != 0)
+ {
+ riscv_match_error_msg = "rd must be an even";
+ return 0;
+ }
+ return match_opcode (op, insn);
}
static int
match_rs2_even (const struct riscv_opcode *op, insn_t insn)
{
int rs2 = (insn & MASK_RS2) >> OP_SH_RS2;
- return ((rs2 & 1) == 0) && match_opcode (op, insn);
+ if((rs2 & 1) != 0)
+ {
+ riscv_match_error_msg = "rs2 must be an even";
+ return 0;
+ }
+ return match_opcode (op, insn);
}
static int
@@ -249,14 +261,24 @@ static int
match_crs2s_even (const struct riscv_opcode *op, insn_t insn)
{
int crs2s = (insn & MASK_CRS2S) >> OP_SH_CRS2S;
- return ((crs2s & 1) == 0) && match_opcode (op, insn);
+ if((crs2s & 1) != 0)
+ {
+ riscv_match_error_msg = "crs2s must be an even";
+ return 0;
+ }
+ return match_opcode (op, insn);
}
static int
match_crs2_even (const struct riscv_opcode *op, insn_t insn)
{
int crs2 = (insn & MASK_CRS2) >> OP_SH_CRS2;
- return ((crs2 & 1) == 0) && match_opcode (op, insn);
+ if((crs2 & 1) != 0)
+ {
+ riscv_match_error_msg = "crs2 must be an even";
+ return 0;
+ }
+ return match_opcode (op, insn);
}
static int
--
2.43.0
More information about the Binutils
mailing list