https://gcc.gnu.org/g:216d94d970ea900e35ff41da7a52a31cc53cba49

commit 216d94d970ea900e35ff41da7a52a31cc53cba49
Author: Josef Melcr <melcr...@fit.cvut.cz>
Date:   Fri Oct 18 23:41:37 2024 +0200

    omp-cp: resolve segfault through monkey stick debugging
    
    gcc/ChangeLog:
    
            * cgraph.h: modify functions regarding speculative call edges
            * ipa-fnsummary.cc (analyze_function_body): integrate callback
              edges
            (compute_fn_summary): integrate callback edges in similar
            fashion to speculative edges
    
    Signed-off-by: Josef Melcr <melcr...@fit.cvut.cz>

Diff:
---
 gcc/cgraph.h         | 24 +++++++++++++++++++++---
 gcc/ipa-fnsummary.cc |  9 ++++++++-
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 4d937b1cde24..84fe17a2a450 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1769,6 +1769,10 @@ public:
      target2.  */
   cgraph_edge *next_speculative_call_target ()
   {
+    if (callback)
+      {
+       return NULL;
+      }
     cgraph_edge *e = this;
     gcc_checking_assert (speculative && callee);
 
@@ -1783,15 +1787,29 @@ public:
      indirect call edge in the speculative call sequence.  */
   cgraph_edge *speculative_call_indirect_edge ()
   {
-    gcc_checking_assert (speculative);
+    gcc_checking_assert (speculative || callback);
     if (!callee)
       return this;
-    for (cgraph_edge *e2 = caller->indirect_calls;
-        true; e2 = e2->next_callee)
+    
+    cgraph_edge * e2 = NULL;
+    for (e2 = caller->indirect_calls;
+        e2; e2 = e2->next_callee)
       if (e2->speculative
          && call_stmt == e2->call_stmt
          && lto_stmt_uid == e2->lto_stmt_uid)
        return e2;
+
+    if (!e2 && callback)
+      {
+       for (e2 = caller->callees; e2; e2 = e2->next_callee)
+         {
+           if (e2->has_callback && call_stmt == e2->call_stmt)
+             {
+               return e2;
+             }
+         }
+      }
+          gcc_unreachable();
   }
 
   /* When called on any edge in speculative call and when given any target
diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index 3f5e09960ef8..348bf2c17724 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -3080,7 +3080,7 @@ analyze_function_body (struct cgraph_node *node, bool 
early)
              es->call_stmt_time = this_time;
              es->loop_depth = bb_loop_depth (bb);
              edge_set_predicate (edge, &bb_predicate);
-             if (edge->speculative)
+             if (edge->speculative || edge->callback)
                {
                  cgraph_edge *indirect
                        = edge->speculative_call_indirect_edge ();
@@ -3489,6 +3489,13 @@ compute_fn_summary (struct cgraph_node *node, bool early)
       for (e = node->indirect_calls; e; e = e->next_callee)
        if (e->speculative)
         break;
+
+      if (!e)
+       {
+         for (e = node->callees; e; e = e->next_callee)
+           if (e->callback)
+             break;
+       }
       gcc_assert (e || size_info->size == size_info->self_size);
     }
 }

Reply via email to