https://gcc.gnu.org/g:d7cb845cffe79d72dacbc4d5bae501c3702e574e
commit r17-5623-gd7cb845cffe79d72dacbc4d5bae501c3702e574e Author: Josef Melcr <[email protected]> Date: Thu Sep 10 16:44:01 2026 +0200 cgraph: Add callback_with_carrying_edge_p method This patch adds a new predicate called callback_with_carrying_edge_p, which returns true if a callback edge *should* have a carrying edge bound to it. This predicate was suggested by Martin, to hide the somewhat confusing checking of assume_function and to capture the meaning of the check in more detail. gcc/ChangeLog: * cgraph.cc (cgraph_node::get_edge): Use callback_with_carrying_edge_p. (cgraph_edge::set_call_stmt): Likewise. (cgraph_edge::callback_with_carrying_edge_p): Add implementation. (cgraph_edge::redirect_call_stmt_to_callee): Use callback_with_carrying_edge_p. * cgraph.h: Add method callback_with_carrying_edge_p, returns TRUE if THIS is a callback edge with an existing callback-carrying edge. Signed-off-by: Josef Melcr <[email protected]> Diff: --- gcc/cgraph.cc | 15 ++++++++++++--- gcc/cgraph.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 184b741b1be2..e87b7998e006 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -934,7 +934,7 @@ cgraph_node::get_edge (gimple *call_stmt) comes to callback edges, a call statement might have multiple callback edges attached to it. These can be easily obtained from the carrying edge instead. */ - if (e && e->callback) + if (e && e->callback_with_carrying_edge_p ()) e = e->get_callback_carrying_edge (); if (n > 100) @@ -1012,7 +1012,8 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt, /* When updating a callback or a callback-carrying edge, update every edge involved. */ - if (update_derived_edges && (e->callback || e->has_callback)) + if (update_derived_edges + && (e->callback_with_carrying_edge_p () || e->has_callback)) { cgraph_edge *current, *next, *carrying; carrying = e->has_callback ? e : e->get_callback_carrying_edge (); @@ -1406,6 +1407,14 @@ cgraph_edge::get_callback_carrying_edge () return e; } +/* Returns TRUE iff THIS is a callback edge with a carrying edge. */ +bool +cgraph_edge::callback_with_carrying_edge_p () const +{ + /* Callback edges are always direct, i.e. callee != NULL. */ + return callback && !callee->assume_function; +} + /* Returns the first callback edge in the list of callees of the caller node. Note that the edges might be in arbitrary order. Must be called on a callback or callback-carrying edge. */ @@ -1851,7 +1860,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e, /* When redirecting a callback edge, all we need to do is replace the original address with the address of the function we are redirecting to. */ - if (e->callback) + if (e->callback_with_carrying_edge_p ()) { cgraph_edge *carrying = e->get_callback_carrying_edge (); if (!callback_is_special_cased (carrying->callee->decl, e->call_stmt) diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 9799605ed24a..1b55df76e95a 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -1941,6 +1941,9 @@ public: this method is caled on. */ cgraph_edge *get_callback_carrying_edge (); + /* Returns TRUE iff THIS is a callback edge with a carrying edge. */ + bool callback_with_carrying_edge_p () const; + /* Returns the first callback edge in the list of callees of the caller node. Note that the edges might be in arbitrary order. Must be called on a callback or callback-carrying edge. */
