]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix speculative devirtualization ICE
authorJan Hubicka <hubicka@ucw.cz>
Thu, 5 Feb 2026 11:30:50 +0000 (12:30 +0100)
committerJan Hubicka <hubicka@ucw.cz>
Thu, 5 Feb 2026 11:30:50 +0000 (12:30 +0100)
this patch fixes cgraph verifier ICE about missing indirect call in the
speculative call sequence.  This is triggered when tree-inline manages to
devirtualize call during folding it does and the call has multiple specualtive
targets.  cgraph_update_edges_for_call_stmt_node calls
cgraph_edge::resolve_speculation which resolves one edge, but it should make
the whole sequence direct which is done by cgraph_edge::make_direct.

The code was also handling the case that call changed but it is not direct.
This should be impossible (and would require similar updating) so I added unreachable.

Bootstrapped/regtested x86_64-linux and also tested with autofdo and spec2017.

gcc/ChangeLog:

PR ipa/123226
* cgraph.cc (cgraph_update_edges_for_call_stmt_node): Fix handling
of multi-target speculations resolved at clone materialization time

gcc/cgraph.cc

index 91ff2775de1359606965dfd9337f4ca000acb93a..508a5559569d33a31d18adb25487697138d44ce6 100644 (file)
@@ -2014,10 +2014,11 @@ cgraph_update_edges_for_call_stmt_node (cgraph_node *node,
                {
                  tree decl = gimple_call_fndecl (new_stmt);
                  if (decl)
-                   e = cgraph_edge::resolve_speculation (e, decl);
+                   e = cgraph_edge::make_direct
+                           (e, cgraph_node::get_create (decl));
                }
              else
-               e = cgraph_edge::resolve_speculation (e, NULL);
+               gcc_unreachable ();
            }
          /* Keep calls marked as dead dead.  */
          if (new_stmt && is_gimple_call (new_stmt) && e->callee