https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128853
Bug ID: 128853
Summary: ICE in cgraph_edge::redirect_callee inlining OpenMP
code at -O3
Product: gcc
Version: 16.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: j.l.k at gmx dot com
Target Milestone: ---
Created attachment 66216
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66216&action=edit
minimal reproducible example
The attached testcase (66 lines, no #include needed, compiles as C++17 with
OpenMP) causes an ICE in cgraph_edge::redirect_callee (gcc/cgraph.cc:1711),
triggered during the "inline" IPA pass.
This is a regression: GCC 15.3.0 compiles the testcase, GCC 16.0.1 and later
crash on it.
To reproduce, save the attachment as mre.cpp and run:
$ g++ -O3 -fopenmp -c mre.cpp
Output from 16.2.1:
----------------------------------------------------------
during IPA pass: inline
mre.cpp:66:31: internal compiler error: Segmentation fault
66 | template void body< double >();
| ^
0x2815bf8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2818207 internal_error(char const*, ...)
???:0
0xeb3f7c ipa_ref::remove_reference()
???:0
0xb72b67 cgraph_edge::redirect_callee(cgraph_node*)
???:0
0xe2f0e8 ipa_call_summary_t::duplicate(cgraph_edge*, cgraph_edge*,
ipa_call_summary*, ipa_call_summary*)
???:0
0xb9821b cgraph_edge::clone(cgraph_node*, gcall*, unsigned int, profile_count,
profile_count, bool)
???:0
0xb998e2 cgraph_node::create_clone(tree_node*, profile_count, bool,
vec<cgraph_edge*, va_heap, vl_ptr>, bool, cgraph_node*, ipa_param_adjustments*,
char const*)
???:0
0xe53ff1 clone_inlined_nodes(cgraph_edge*, bool, bool, bool, int*)
???:0
0xe54071 clone_inlined_nodes(cgraph_edge*, bool, bool, bool, int*)
???:0
0xe54071 clone_inlined_nodes(cgraph_edge*, bool, bool, bool, int*)
???:0
0xe5a997 inline_call(cgraph_edge*, bool, vec<cgraph_edge*, va_heap, vl_ptr>*,
int*, bool, bool*)
???:0
/usr/lib/gcc/x86_64-pc-linux-gnu/16/cc1plus -quiet -D_GNU_SOURCE -D_REENTRANT
mre.cpp -quiet -dumpdir /tmp/ -dumpbase o162.cpp -dumpbase-ext .cpp
-mtune=generic -march=x86-64 -O3 -std=c++17 -fopenmp -o /tmp/ccrxE1y5.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
----------------------------------------------------------
Builds with checking enabled abort instead at the IPA reference lookup, in the
same function:
mre.cpp:66:31: internal compiler error: in redirect_callee, at cgraph.cc:1711
(GCC 16 branch; trunk reports cgraph.cc:1749)
The minimal flag set is -O3 -fopenmp (-DNDEBUG, -march and -std are not
needed); -O2 -fopenmp and -O3 without -fopenmp both compile the testcase fine.
AI ANALYSIS (deepseek-v4.1-flash)
=================================
When inlined callees are cloned, ipa_call_summary_t::duplicate() copies the
call summary of an edge whose predicate has become false and calls
edge_set_predicate() -> redirect_to_unreachable() ->
cgraph_edge::redirect_callee(). On 16.2.1 the segfault happens inside
ipa_ref::remove_reference(), which redirect_callee() calls indirectly (via
remove_callee()) at its very beginning, i.e. the edge's reference list is
already inconsistent when the redirection starts. In checking-enabled builds
of the 16 branch the abort happens a bit later, in the IPA_REF_ADDR lookup.
In a gdb session on the checking build the edge being redirected turned out to
be an internal "callback" edge (edge->callback_name != NULL, callback index 1)
whose callee is __builtin_unreachable(); no IPA reference for such an edge
exists in the caller, which is what the lookups do not tolerate.
The testcase reproduces only when the same function template is instantiated
twice (body<int> and body<double>); with a single instantiation it compiles
fine. This points at identical code folding (ICF) of the two instantiations as
the step that leaves the callgraph in the state which the inliner then trips
over - consistent with -fno-ipa-icf avoiding the crash.
On the original (much larger) translation unit from which this was reduced,
-fno-ipa-cp also avoided the crash. On the reduced testcase it does not, so the
ICE seems reachable from both the early-inliner and the IPA-CP cloning paths
depending on the TU.
FLAGS THAT AVOID THE ICE (testcase)
===================================
-fno-ipa-icf
-fno-early-inlining
-fno-inline-functions
-O2
FLAGS THAT DO NOT AVOID IT
==========================
-fno-ipa-cp
-fno-ipa-cp-clone
-fno-ipa-sra
--param ipa-cp-eval-threshold=500
--param ipa-cp-eval-threshold=2000