public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Benno Evers <benno.martin.evers@googlemail.com>, gcc-patches@gcc.gnu.org
Cc: iain Sandoe <iains.gcc@gmail.com>
Subject: Re: [PATCH RFC] Fix ICE due to shared BLOCK node in coroutine generation [PR103328]
Date: Sat, 26 Mar 2022 21:33:22 -0400	[thread overview]
Message-ID: <eed5e058-f726-5d55-7e08-98a3bf6d5a92@redhat.com> (raw)
In-Reply-To: <CAEQVFRFcgqZZMEdDatwz8DFQ-C5U63rUKkhnoYRxTACEPaoe5A@mail.gmail.com>

On 3/17/22 07:37, Benno Evers via Gcc-patches wrote:
> The coroutine transformation moves the original function body into a
> newly created actor function, but the block of the
> `current_binding_level` still points into the original function,
> causing the block to be shared between the two functions if it is
> subsequently used. This may cause havoc later on, as subsequent
> compiler passes for one function will also implicitly modify the
> other. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103328#c19 for
> a more detailed writeup.
> 
> This patch fixes the issue locally, but I'm not familiar with the GCC
> code base so I'm not sure if this is the right way to go about it or
> if there's a cleaner way to reset the current binding level. If this
> is the way to go I'm happy to extend the patch with a testcase and
> changelog entry.

Please do, it looks like a good fix to me.  Iain, does it make sense to 
you as well?

> ---
>   gcc/cp/coroutines.cc | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
> index b1bfdc767a4..eb5f80f499b 100644
> --- a/gcc/cp/coroutines.cc
> +++ b/gcc/cp/coroutines.cc
> @@ -4541,6 +4541,8 @@ morph_fn_to_coro (tree orig, tree *resumer, tree
> *destroyer)
>     BLOCK_VARS (top_block) = BIND_EXPR_VARS (ramp_bind);
>     BLOCK_SUBBLOCKS (top_block) = NULL_TREE;
> 
> +  current_binding_level->blocks = top_block;
> +
>     /* The decl_expr for the coro frame pointer, initialize to zero so that we
>        can pass it to the IFN_CO_FRAME (since there's no way to pass a type,
>        directly apparently).  This avoids a "used uninitialized" warning.  */


  reply	other threads:[~2022-03-27  1:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 11:37 Benno Evers
2022-03-27  1:33 ` Jason Merrill [this message]
2022-03-28  6:57   ` Iain Sandoe
2022-03-30 13:06     ` Benno Evers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eed5e058-f726-5d55-7e08-98a3bf6d5a92@redhat.com \
    --to=jason@redhat.com \
    --cc=benno.martin.evers@googlemail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iains.gcc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).