https://gcc.gnu.org/g:7999eb8672c7a5bb6923b1df75dbf29d60637713

commit r16-2360-g7999eb8672c7a5bb6923b1df75dbf29d60637713
Author: Artemiy Volkov <artem...@acm.org>
Date:   Sat Jul 19 08:03:02 2025 -0600

    [PATCH] RISC-V: prevent NULL_RTX dereference in riscv_macro_fusion_pair_p ()
    
    > A number of folks have had their fingers in this code and it's going to 
take
    > a few submissions to do everything we want to do.
    >
    > This patch is primarily concerned with avoiding signaling that fusion can
    > occur in cases where it obviously should not be signaling fusion.
    
    Hi Jeff,
    
    With this change, we're liable to ICE whenever prev_set or curr_set are
    NULL_RTX.  For a fix, how about something like the below?
    
    Thanks,
    Artemiy
    
    Introduced in r16-1984-g83d19b5d842dad, initializers for
    {prev,curr}_dest_regno can cause an ICE if the respective insn isn't a
    single set.  Rectify this by inserting a NULL_RTX check before using
    {prev,curr}_set.
    
    Regtested on riscv32.
    
    gcc/
            * config/riscv/riscv.cc (riscv_macro_fusion_pair_p): Protect
            from a NULL PREV_SET or CURR_SET.

Diff:
---
 gcc/config/riscv/riscv.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1275b034cf83..0517e7974947 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -10359,10 +10359,10 @@ riscv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn 
*curr)
   bool simple_sets_p = prev_set && curr_set && !any_condjump_p (curr);
   bool sched1 = can_create_pseudo_p ();
 
-  unsigned int prev_dest_regno = (REG_P (SET_DEST (prev_set))
+  unsigned int prev_dest_regno = (prev_set && REG_P (SET_DEST (prev_set))
                                  ? REGNO (SET_DEST (prev_set))
                                  : FIRST_PSEUDO_REGISTER);
-  unsigned int curr_dest_regno = (REG_P (SET_DEST (curr_set))
+  unsigned int curr_dest_regno = (curr_set && REG_P (SET_DEST (curr_set))
                                  ? REGNO (SET_DEST (curr_set))
                                  : FIRST_PSEUDO_REGISTER);

Reply via email to