[binutils-gdb] RISC-V: match_*() improvements

Jan Beulich jbeulich@sourceware.org
Fri Jun 5 09:13:37 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=175c54561d4f9f5bae4064d0bdac5a228243589f

commit 175c54561d4f9f5bae4064d0bdac5a228243589f
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Jun 5 11:09:38 2026 +0200

    RISC-V: match_*() improvements
    
    Match functions referenced by macro insns should not
    unconditionally invoke match_opcode(): The macro enumeration can change
    (grow), making the function potentially yield false negatives.
    
    In match_rs1_nonzero(), used solely by macro insns, add an assertion to
    that effect.
    
    While there also drop the pointless attribute from
    match_rs1_nonzero_rs2_even()'s first parameter.

Diff:
---
 opcodes/riscv-opc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c
index 114846f410f..ba155335878 100644
--- a/opcodes/riscv-opc.c
+++ b/opcodes/riscv-opc.c
@@ -22,6 +22,7 @@
 
 #include "sysdep.h"
 #include "opcode/riscv.h"
+#include <assert.h>
 #include <stdio.h>
 
 /* Register names used by gas and objdump.  */
@@ -210,14 +211,16 @@ 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);
+  return ((rd & 1) == 0)
+         && (op->pinfo == INSN_MACRO || 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);
+  return ((rs2 & 1) == 0)
+         && (op->pinfo == INSN_MACRO || match_opcode (op, insn));
 }
 
 static int
@@ -236,11 +239,12 @@ match_rd_even_nonzero (const struct riscv_opcode *op, insn_t insn)
 static int
 match_rs1_nonzero (const struct riscv_opcode *op ATTRIBUTE_UNUSED, insn_t insn)
 {
+  assert (op->pinfo == INSN_MACRO);
   return (insn & MASK_RS1) != 0;
 }
 
 static int
-match_rs1_nonzero_rs2_even (const struct riscv_opcode *op ATTRIBUTE_UNUSED, insn_t insn)
+match_rs1_nonzero_rs2_even (const struct riscv_opcode *op, insn_t insn)
 {
   return match_rs1_nonzero (op, insn) && match_rs2_even (op, insn);
 }


More information about the Binutils-cvs mailing list