Hello,

On Tue, Jun 23 2026, Josef Melcr wrote:
> Hi,
> 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.
>
> Bootstrapped and regtested x86-linux without issues.  Also bootstrapped
> and regtested with RUNTESTFLAGS="--target_board=unix/-fno-ipa-cp" to
> check for different problems of the same nature, none found.
>
> OK for master and 16 backport?
>
> Best regards,
> Josef
>
>       PR 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.

This is OK for both branches, just please...

>
> gcc/testsuite/ChangeLog:
>
>       * c-c++-common/gomp/pr125121.c: New test.
>
> Signed-off-by: Josef Melcr <[email protected]>
> ---
>  gcc/cgraph.cc                              |  1 +
>  gcc/ipa-prop.cc                            | 26 ++++++++++------------
>  gcc/testsuite/c-c++-common/gomp/pr125121.c | 11 +++++++++
>  3 files changed, 24 insertions(+), 14 deletions(-)
>  create mode 100644 gcc/testsuite/c-c++-common/gomp/pr125121.c
>
> diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
> index 13ea9c34629..4b22cad9f11 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 625a2b25969..dbd26f9453c 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.  */
> @@ -2631,7 +2619,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)
>                   {
> @@ -2640,7 +2628,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);
>                   }
>               }
> @@ -5151,6 +5138,17 @@ ipa_edge_args_sum_t::duplicate (cgraph_edge *src, 
> cgraph_edge *dst,
>        new_args->jump_functions = NULL;
>        return;
>      }
> +
> +  if (src->has_callback && dst->callback)
> +    {

...assert here that the two edges have the same caller.

Thanks!

Martin

Reply via email to