From: Artemiy Volkov Date: Sat, 19 Jul 2025 14:03:02 +0000 (-0600) Subject: [PATCH] RISC-V: prevent NULL_RTX dereference in riscv_macro_fusion_pair_p () X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7999eb8672c7a5bb6923b1df75dbf29d60637713;p=thirdparty%2Fgcc.git [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 --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 1275b034cf8..0517e797494 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);