https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120745
Bug ID: 120745 Summary: SEGV in process_uses_of_deleted_def, at rtl-ssa/changes.cc:271 Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ondrejmachota at gmail dot com CC: rsandifo at gcc dot gnu.org Target Milestone: --- Hi, Jan Hubicka <hubi...@ucw.cz> and I are working on a new RTL DCE pass based on the RTL SSA framework. To help reproduce this bug, we have provided a branch: refs/users/omachota/heads/rtl-ssa-dce (commit: eb73be9bde7). We tested our DCE implementation agains UD_DCE, which deleted the same instructions in both provided testcases. Reduced testcase (921011-1.i): int fun_th, fun_h; void fun(int nb) { int sy; while (nb) while (fun_h) if (++sy == fun_th) sy = 0; } Run: gcc -c 921011-1.i -O1 Compiler output: gcc: internal compiler error: Segmentation fault signal terminated program cc1 The bug occurs inside function process_uses_of_deleted_def. A phi_insn might have a use pointing to itself. When this use is processed by process_uses_of_deleted_def, the function recurses (see rtl-ssa/changes.cc:271) until GCC crashes. Compiler details: Using built-in specs. COLLECT_GCC=/mnt/tmpfs/gcc-install/usr/local/bin/gcc COLLECT_LTO_WRAPPER=/mnt/tmpfs/gcc-install/usr/local/bin/../libexec/gcc/x86_64-pc-linux-gnu/15.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc/configure --enable-languages=c,c++ --disable-bootstrap --disable-multilib --disable-libquadmath --disable-nls --disable-lto --disable-shared --disable-threads Thread model: single Supported LTO compression algorithms: zlib zstd gcc version 15.0.1 20250123 (experimental) (GCC) Compiling GCC from the provided branch may fail. You might need to disable the rtl_ssa_dce pass, compile GCC, then re-enable the pass and compile again. One more simplified testcase (testcase_pr82875.i): char a; long c, d; void foo() { while (0) while (a) lab: d ? a %= c : 0; goto lab; } Run: gcc -c testcase_pr82875.i -O1 Compiler output: gcc: internal compiler error: Segmentation fault signal terminated program cc1