https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121843

--- Comment #4 from Scott Boudreaux <scott at elyanlabs dot ai> ---
Created attachment 63974
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63974&action=edit
[PATCH] cfgrtl: Add NULL guard for last in commit_one_edge_insertion [PR121843]

Formal patch attached for PR121843.

This adds a NULL guard for 'last' in commit_one_edge_insertion (cfgrtl.cc),
as suggested by Jeevitha in Comment #3.

The issue: when shrink-wrapping inserts a prologue note into a block
created by split_edge that contains only an unconditional jump,
prev_nonnote_insn(before) returns NULL, and the subsequent
returnjump_p(last) dereferences it → ICE.

The fix: two changes in commit_one_edge_insertion:

  1. Line 2105: if (returnjump_p (last))  →  if (last && returnjump_p (last))
  2. Line 2126: gcc_assert (!JUMP_P (last) || ...)  →  gcc_assert (!last ||
!JUMP_P (last) || ...)

When last is NULL, neither the returnjump_p path (epilogue insertion
before a return jump) nor the JUMP_P assertion (sequence jumping outside
itself) applies, so skipping both is correct.

Test case included: gcc.target/powerpc/pr121843.c (dg-do compile, -O2).

Bootstrapped and regression-tested on powerpc64le-linux-gnu (IBM POWER8
S824 bare metal, 16 cores / 128 threads, 512GB RAM).

Reply via email to