https://gcc.gnu.org/g:aa41b0bd7fa07e2e7820e07fbe2b904251a8e378
commit r16-9264-gaa41b0bd7fa07e2e7820e07fbe2b904251a8e378 Author: Josef Melcr <[email protected]> Date: Tue Jun 23 17:46:08 2026 +0200 ipa: Add missing call to duplication hooks [PR ipa/125121] This patch adds a missing call to edge duplication hooks in cgraph_edge::make_callback. In PR125121, we get an ICE in ipa-sra when compiling with -fno-ipa-cp, because the analysis in ipa-prop runs after sra generates its summaries. Because of the missing call to the hooks, the summaries required by sra don't get copied over for the newly added callback edges, leading to segfaults. This patch adds the call to the hooks to remedy this. It also changes some of the initialization logic for summaries for callback edges to make it a little more consistent. PR ipa/125121 gcc/ChangeLog: * cgraph.cc (cgraph_edge::make_callback): Add missing call to duplication hooks. * ipa-prop.cc (init_callback_edge_summary): Remove function. (ipa_compute_jump_functions_for_edge): Remove call to init_callback_edge_summary, fix comment. (ipa_edge_args_sum_t::duplicate): Fix the initialization of jump functions vector for callback edges. gcc/testsuite/ChangeLog: * c-c++-common/gomp/pr125121.c: New test. Signed-off-by: Josef Melcr <[email protected]> (cherry picked from commit 3bbe1a86ccecb180a4d32de6eab97bcc624a410f) Diff: --- gcc/cgraph.cc | 1 + gcc/ipa-prop.cc | 27 +++++++++++++-------------- gcc/testsuite/c-c++-common/gomp/pr125121.c | 11 +++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 353e8b498aa6..aec65e47a2ba 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -1383,6 +1383,7 @@ cgraph_edge::make_callback (cgraph_node *n2, unsigned int callback_id) else e2->can_throw_external = can_throw_external; e2->lto_stmt_uid = lto_stmt_uid; + symtab->call_edge_duplication_hooks (this, e2); n2->mark_address_taken (); return e2; } diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index dee7632eef0c..4c60c903a381 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -2480,18 +2480,6 @@ skip_a_safe_conversion_op (tree t) return t; } -/* Initializes ipa_edge_args summary of CBE given its callback-carrying edge. - This primarily means allocating the correct amount of jump functions. */ - -static inline void -init_callback_edge_summary (struct cgraph_edge *cbe, tree attr) -{ - ipa_edge_args *cb_args = ipa_edge_args_sum->get_create (cbe); - size_t jf_vec_length = callback_num_args(attr); - vec_safe_grow_cleared (cb_args->jump_functions, - jf_vec_length, true); -} - /* Compute jump function for all arguments of callsite CS and insert the information in the jump_functions array in the ipa_edge_args corresponding to this callsite. */ @@ -2632,7 +2620,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, } /* If a callback attribute describing this pointer is found, - create a callback edge to the pointee function to + create a callback edge to the pointee function to allow for further optimizations. */ if (callback_attr) { @@ -2641,7 +2629,6 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, unsigned callback_id = n; cgraph_edge *cbe = cs->make_callback (kernel_node, callback_id); - init_callback_edge_summary (cbe, callback_attr); callback_edges.safe_push (cbe); } } @@ -5152,6 +5139,18 @@ ipa_edge_args_sum_t::duplicate (cgraph_edge *src, cgraph_edge *dst, new_args->jump_functions = NULL; return; } + + if (src->has_callback && dst->callback) + { + gcc_assert (src->caller == dst->caller); + tree attr = callback_fetch_attr_by_edge (dst, src); + unsigned arg_count = callback_num_args (attr); + vec_safe_grow_cleared (new_args->jump_functions, arg_count, true); + /* Duplication of jump functions is handled separately for callback + pairs. */ + return; + } + vec_safe_grow_cleared (new_args->jump_functions, old_args->jump_functions->length (), true); diff --git a/gcc/testsuite/c-c++-common/gomp/pr125121.c b/gcc/testsuite/c-c++-common/gomp/pr125121.c new file mode 100644 index 000000000000..0aceb6e51657 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr125121.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-ipa-cp" } */ + +void +a () +{ +#pragma omp parallel sections + { + ; + } +}
