https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116861
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Pan Li <pa...@gcc.gnu.org>: https://gcc.gnu.org/g:cd430b1fd95dce5868ce6a8063119d253ea2f995 commit r15-3926-gcd430b1fd95dce5868ce6a8063119d253ea2f995 Author: Pan Li <pan2...@intel.com> Date: Fri Sep 27 11:03:51 2024 +0800 Widening-Mul: Fix one ICE when iterate on phi node We iterate all phi node of bb to try to match the SAT_* pattern for scalar integer. We also remove the phi mode when the relevant pattern matched. Unfortunately the iterator may have no idea the phi node is removed and continue leverage the free data and then ICE similar as below. [0] psi ptr 0x75216340c000 [0] psi ptr 0x75216340c400 [1] psi ptr 0xa5a5a5a5a5a5a5a5 <=== GC freed pointer. during GIMPLE pass: widening_mul tmp.c: In function âfâ: tmp.c:45:6: internal compiler error: Segmentation fault 45 | void f(int rows, int cols) { | ^ 0x36e2788 internal_error(char const*, ...) ../../gcc/diagnostic-global-context.cc:517 0x18005f0 crash_signal ../../gcc/toplev.cc:321 0x752163c4531f ??? ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0 0x103ae0e bool is_a_helper<gphi*>::test<gimple>(gimple*) ../../gcc/gimple.h:1256 0x103f9a5 bool is_a<gphi*, gimple>(gimple*) ../../gcc/is-a.h:232 0x103dc78 gphi* as_a<gphi*, gimple>(gimple*) ../../gcc/is-a.h:255 0x104f12e gphi_iterator::phi() const ../../gcc/gimple-iterator.h:47 0x1a57bef after_dom_children ../../gcc/tree-ssa-math-opts.cc:6140 0x3344482 dom_walker::walk(basic_block_def*) ../../gcc/domwalk.cc:354 0x1a58601 execute ../../gcc/tree-ssa-math-opts.cc:6312 This patch would like to fix the iterate on modified collection problem by backup the next phi in advance. The below test suites are passed for this patch. * The rv64gcv fully regression test. * The x86 bootstrap test. * The x86 fully regression test. PR middle-end/116861 gcc/ChangeLog: * tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children): Backup the next psi iterator before remove the phi node. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr116861-1.c: New test. Signed-off-by: Pan Li <pan2...@intel.com>