]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++, coroutines: Fix block nests when the function has no top-level bind.
authorIain Sandoe <iain@sandoe.co.uk>
Sat, 1 Apr 2023 16:23:51 +0000 (21:53 +0530)
committerIain Sandoe <iain@sandoe.co.uk>
Sun, 9 Apr 2023 02:15:04 +0000 (07:45 +0530)
When the function contains no local vars and also no nested scopes, there
is no top-level bind expression.  Because the rewritten coroutine body will
require both local vars and contain nested scopes, we add a bind expression
to such functions.  When this was done the necessary scope blocks were
omitted which leads to disconnected function content.

Fixed by adding a new block to the added bind expression.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/cp/ChangeLog:

* coroutines.cc (coro_rewrite_function_body): Ensure that added
bind expressions have scope blocks.

gcc/cp/coroutines.cc

index b307c8ca8b64aa7c45df1dd38ff02ae7d9aa5beb..59a240ebd403996494dd8004c1e41a667b9d6cf7 100644 (file)
@@ -4113,6 +4113,10 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig,
       tree bind_wrap = build3_loc (fn_start, BIND_EXPR, void_type_node,
                                   NULL, NULL, NULL);
       BIND_EXPR_BODY (bind_wrap) = fnbody;
+      /* Ensure we have a block to connect up the scopes.  */
+      tree new_blk = make_node (BLOCK);
+      BIND_EXPR_BLOCK (bind_wrap) = new_blk;
+      BLOCK_SUBBLOCKS (top_block) = new_blk;
       fnbody = bind_wrap;
     }