]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PATCH] RISC-V: prevent NULL_RTX dereference in riscv_macro_fusion_pair_p ()
authorArtemiy Volkov <artemiyv@acm.org>
Sat, 19 Jul 2025 14:03:02 +0000 (08:03 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Sat, 19 Jul 2025 14:03:02 +0000 (08:03 -0600)
> 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.

gcc/config/riscv/riscv.cc

index 1275b034cf834a2e5e0a28407e0e7151594060be..0517e7974947862f26691ade02e01778c419abf8 100644 (file)
@@ -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);