https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128765
Bug ID: 128765
Summary: [17 Regression] ICE in
maybe_duplicate_ssa_info_at_copy during sccopy with
-fnon-call-exceptions after EH edges are purged
mid-SCC since r17-1266
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: lzy20000419 at outlook dot com
Target Milestone: ---
Fails with trunk (gcc 17.0.0 20261115, 4182b22649d4); 9.5.0 through 16.2.0
compile it.
Target: x86_64-pc-linux-gnu.
int n, q;
void f(double x)
{
double a = x;
for (int i = 0; i < n; i++)
try { q += a < x; }
catch (...) { for (int k = 0; k < n; k++) a = a; }
}
int main() { n = 3; f(1.0); return q; }
g++ -O2 -fnon-call-exceptions -fno-tree-fre -fno-tree-ccp -c t.C
during GIMPLE pass: sccopy
t.C: In function 'void f(double)':
t.C:9:39: internal compiler error: Segmentation fault
maybe_duplicate_ssa_info_at_copy(tree_node*, tree_node*)
scc_copy_prop::replace_scc_by_value(vec<gimple*, va_heap, vl_ptr>,
tree_node*)
Expected: successful compilation. -fdisable-tree-sccopy1, -fno-trapping-math
and -fno-non-call-exceptions avoid the ICE.
Godbolt (trunk): https://godbolt.org/z/z38d3Tnc3
Cause: r17-1266-gf4ab559af9c423 ("sccopy: Handle ssa info for copies in
sccopy") lets sccopy accept copies whose SSA info differs, and
scc_copy_prop::replace_scc_by_value calls maybe_duplicate_ssa_info_at_copy
(name, val) after each replace_uses_by. replace_uses_by can fold the trapping a
< x into a non-trapping form. That purges the EH edges and deletes the catch
blocks, which still hold later PHIs of the same SCC. Those PHIs are removed and
their results released, so for the later members SSA_NAME_DEF_STMT (name) is
NULL and gimple_bb () in maybe_duplicate_ssa_info_at_copy dereferences it. The
PR117919 fix prunes members with no basic block before an SCC is processed, but
not while it is being replaced.
Possible fix: in the replace_scc_by_value loop, skip members whose statement no
longer has a basic block (gimple_bb (stmt) == NULL), before calling
replace_uses_by and maybe_duplicate_ssa_info_at_copy.
Disclaimer: This test case was found with LLM-assisted targeted testing, and
the report was written with LLM assistance.