https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103328
--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> --- Basically with lower_gimple_bind we re-wire the BLOCK tree to match the GIMPLE_BLOCK IL nesting. Whatever gets "unreachable" in that process is "lost". The following shows this, but it seems it is expected that we lose some blocks, just not that we lose used ones (so I use TREE_USED to mark the blocks we record in stmts and only check those). Interestingly then it doesn't trigger. Instead it looks like the BIND_EXPR tree contains BLOCKs not in the initial BLOCK tree!? { Scope block #0 struct _ZNSt11server_impl8io_fiberEN12_GLOBAL__N_114append_requestE.Frame * _Coro_frameptr; bool _Coro_promise_live; bool _Coro_gro_live; { Scope block #0 } } for example. diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c index 7d9b3df2ffb..b0ae15f0368 100644 --- a/gcc/gimple-low.c +++ b/gcc/gimple-low.c @@ -77,6 +77,7 @@ static void lower_gimple_return (gimple_stmt_iterator *, struct lower_data *); static void lower_builtin_setjmp (gimple_stmt_iterator *); static void lower_builtin_posix_memalign (gimple_stmt_iterator *); +extern void collect_subblocks (hash_set<tree> *, tree); /* Lower the body of current_function_decl from High GIMPLE into Low GIMPLE. */ @@ -96,6 +97,11 @@ lower_function_body (void) gcc_assert (gimple_seq_first (body) == gimple_seq_last (body) && gimple_code (gimple_seq_first_stmt (body)) == GIMPLE_BIND); + hash_set<tree> blocks; + collect_subblocks (&blocks, DECL_INITIAL (current_function_decl)); + for (auto i = blocks.begin (); i != blocks.end (); ++i) + TREE_USED (*i) = 0; + memset (&data, 0, sizeof (data)); data.block = DECL_INITIAL (current_function_decl); BLOCK_SUBBLOCKS (data.block) = NULL_TREE; @@ -165,6 +171,17 @@ lower_function_body (void) = blocks_nreverse (BLOCK_SUBBLOCKS (data.block)); clear_block_marks (data.block); + + hash_set<tree> blocks_after; + collect_subblocks (&blocks_after, DECL_INITIAL (current_function_decl)); + for (auto i = blocks.begin (); i != blocks.end (); ++i) + if (TREE_USED (*i) && !blocks_after.contains (*i)) + gcc_unreachable (); + for (auto i = blocks_after.begin (); i != blocks_after.end (); ++i) + if (!blocks.contains (*i)) + gcc_unreachable (); + + data.return_statements.release (); return 0; } @@ -248,6 +265,7 @@ lower_stmt (gimple_stmt_iterator *gsi, struct lower_data *data) gimple *stmt = gsi_stmt (*gsi); gimple_set_block (stmt, data->block); + TREE_USED (data->block) = 1; switch (gimple_code (stmt)) { diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index cde606e1a40..719941dea42 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -5396,7 +5396,7 @@ verify_expr_location (tree *tp, int *walk_subtrees, void *data) /* Insert all subblocks of BLOCK into BLOCKS and recurse. */ -static void +void collect_subblocks (hash_set<tree> *blocks, tree block) { tree t;