Hi, this patch fixes ice in resolve_speculatoin expecting that there is callgraph node for declaration it is passed. I also revisited earlier fix to cgraph_update_edges_for_call_stmt_node: the function would still ICE if dead indirect call was updated. I do not think it happens as only user is fold_marked_statements and fold_stmt will likely only suceed either fodling out the builtin or turning indirect call to direct, but it is better to be safe.
Bootstrapped/regtested x86_64-linux, comitted. PR ipa/65600 * cgraph.c (cgraph_update_edges_for_call_stmt_node): Fix the case of optimized out indirect call. (redirect_to_unreachable): Always build symbol table node for BUILT_IN_UNREACHABLE * g++.dg/torture/pr65600.C: New testcase. Index: testsuite/g++.dg/torture/pr65600.C =================================================================== --- testsuite/g++.dg/torture/pr65600.C (revision 0) +++ testsuite/g++.dg/torture/pr65600.C (revision 0) @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-std=c++11" } +class A { +public: + virtual void m_fn1() {} + int weak_release___trans_tmp_1; + void m_fn2() { + __asm__("\n\n\n\n"); + if (weak_release___trans_tmp_1) + m_fn1(); + } +}; +class weak_count { + A *pi_; + +public: + weak_count() : pi_() {} + ~weak_count() { + if (pi_) + pi_->m_fn2(); + } +}; +class B { + weak_count pn; +}; +int +main() { B a; } + Index: cgraph.c =================================================================== --- cgraph.c (revision 221726) +++ cgraph.c (working copy) @@ -1516,7 +1516,7 @@ cgraph_update_edges_for_call_stmt_node ( if (e) { /* Keep calls marked as dead dead. */ - if (new_call && e->callee + if (new_stmt && is_gimple_call (new_stmt) && e->callee && DECL_BUILT_IN_CLASS (e->callee->decl) == BUILT_IN_NORMAL && DECL_FUNCTION_CODE (e->callee->decl) == BUILT_IN_UNREACHABLE) { Index: ipa-inline-analysis.c =================================================================== --- ipa-inline-analysis.c (revision 221725) +++ ipa-inline-analysis.c (working copy) @@ -766,15 +766,15 @@ static struct cgraph_edge * redirect_to_unreachable (struct cgraph_edge *e) { struct cgraph_node *callee = !e->inline_failed ? e->callee : NULL; + struct cgraph_node *target = cgraph_node::get_create + (builtin_decl_implicit (BUILT_IN_UNREACHABLE)); if (e->speculative) - e = e->resolve_speculation (builtin_decl_implicit (BUILT_IN_UNREACHABLE)); + e = e->resolve_speculation (target->decl); else if (!e->callee) - e->make_direct (cgraph_node::get_create - (builtin_decl_implicit (BUILT_IN_UNREACHABLE))); + e->make_direct (target); else - e->redirect_callee (cgraph_node::get_create - (builtin_decl_implicit (BUILT_IN_UNREACHABLE))); + e->redirect_callee (target); struct inline_edge_summary *es = inline_edge_summary (e); e->inline_failed = CIF_UNREACHABLE; e->frequency = 0;