public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++, coroutines: Fix block nests when the function has no top-level bind.
@ 2023-04-06  6:27 Iain Sandoe
  2023-04-08 17:10 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Iain Sandoe @ 2023-04-06  6:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, arsen

I spotted this problem while trying to collate my WIP patches (sorry
for not spotting it when the original patch was discussed).

Although we do not yet have any regression filed against this (AFAIK),
it's only a matter of time - so I'd suggest that we should apply to
13.

 Tested on x86_64-darwin21 and x86_64_linux-gnu.
 OK for trunk? (when?)
 Iain
 
 --- 8< ---

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 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index b307c8ca8b6..59a240ebd40 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -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;
     }
 
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++, coroutines: Fix block nests when the function has no top-level bind.
  2023-04-06  6:27 [PATCH] c++, coroutines: Fix block nests when the function has no top-level bind Iain Sandoe
@ 2023-04-08 17:10 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-04-08 17:10 UTC (permalink / raw)
  To: iain, gcc-patches; +Cc: arsen

On 4/6/23 02:27, Iain Sandoe wrote:
> I spotted this problem while trying to collate my WIP patches (sorry
> for not spotting it when the original patch was discussed).
> 
> Although we do not yet have any regression filed against this (AFAIK),
> it's only a matter of time - so I'd suggest that we should apply to
> 13.
> 
>   Tested on x86_64-darwin21 and x86_64_linux-gnu.
>   OK for trunk? (when?)
>   Iain
>   
>   --- 8< ---
> 
> 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 | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
> index b307c8ca8b6..59a240ebd40 100644
> --- a/gcc/cp/coroutines.cc
> +++ b/gcc/cp/coroutines.cc
> @@ -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;
>       }

I wonder if you want to use c_build_bind_expr for various BIND_EXPR 
creation?  You'll still need to explicitly build a BLOCK in this 
particular case, as in poplevel with nonzero functionbody, but that 
might reduce the boilerplate in general.

The patch is OK.

Jason


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-08 17:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06  6:27 [PATCH] c++, coroutines: Fix block nests when the function has no top-level bind Iain Sandoe
2023-04-08 17:10 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).