Hi,
this patch has been pre-approved by Martin, so I applied it to master.
I pushed 
https://patchwork.sourceware.org/project/gcc/patch/[email protected]/
along with it, as the following patch was its last prerequisite.

Bootstrapped and regtested with and without the linked patch applied, no
regressions.  I did both, as the linked patch makes the error manifest
more easily.

*****

This function is used to determine whether a callback edge should be
kept or not.  It was supposed to capture the idea that a callback edge
has been redirected at some point, however, it only considered
redirecting to some clone.  However, an edge may not always be
redirected to a clone.  For example, common function bodies produced by
icf are not clones.  This version of this function should cover all
cases, at least for the time being.

gcc/ChangeLog:

        PR ipa/122768
        * attr-callback.cc (callback_edge_useful_p): Rewrite the
        heuristic, now consider clones as well as icf bodies.

Signed-off-by: Josef Melcr <[email protected]>
---
 gcc/attr-callback.cc | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/gcc/attr-callback.cc b/gcc/attr-callback.cc
index ee39ef61a20..04b5ad0ef11 100644
--- a/gcc/attr-callback.cc
+++ b/gcc/attr-callback.cc
@@ -344,11 +344,19 @@ bool
 callback_edge_useful_p (cgraph_edge *e)
 {
   gcc_checking_assert (e->callback);
-  /* If the edge is not pointing towards a clone, it is no longer useful as its
-     entire purpose is to produce clones of callbacks.  */
-  if (!e->callee->clone_of)
-    return false;
-  return true;
+  /* If the edge is pointing towards a clone, it is useful.  */
+  if (e->callee->clone_of)
+    return true;
+
+  /* If the callee has been produced by icf, the edge is useful, as it will be
+     used to for the redirection.  */
+  if (e->callee->icf_merged)
+    return true;
+
+  /* In case some future pass redirects edges, it should be added as a case
+     here.  */
+
+  return false;
 }
 
 /* Returns the number of arguments the callback function described by ATTR
-- 
2.51.1

Reply via email to