public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcc at bmevers dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/103328] [11/12 Regression] ICE in remap_gimple_stmt, at tree-inline.c:1921 since r11-7419-g0f161cc8494cf728
Date: Fri, 11 Mar 2022 02:14:59 +0000	[thread overview]
Message-ID: <bug-103328-4-nAM1CHqoEq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103328-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103328

Benno Evers <gcc at bmevers dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gcc at bmevers dot de

--- Comment #19 from Benno Evers <gcc at bmevers dot de> ---
I've independently encountered this issue, and investigated a bit using the
reproducer by Avi Kivity.

>From what I've found, the issue is when inlining the function body into the
actor function in `coro_rewrite_function_body()`:

    /* Append the original function body.  */
    add_stmt (fnbody);

it will contain a reference to the top-level BLOCK of the user-provided
function.

However, when the actor function gets built it is not actually the "current"
function being finished, so `current_function_decl` points to the lambda (that
is currently being morphed into the ramp) instead.

Later on when we finish the lambda in `poplevel()` in decl.cc, we (may) assign
the DECL_INITIAL for that function from the `current_binding_level` which still
points to the last top-level block of the original function that is also used
by `fnbody`.

    subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
    // [...]
    DECL_INITIAL (current_function_decl) = block ? block : subblocks;


So we end up with the same `tree` being used in two different functions, and
then during gimple lowering bad things happen (in particular, the `subblocks`
set by the actor function are overwritten while lowering the ramp function)

The following change fixed the segfault on both reproducers on a local build.
I'm not too familiar with the GCC codebase so there's probably a better way to
handle the issue, but if the approach looks reasonable I'm happy to submit a
full patch.


--- 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.  */

  parent reply	other threads:[~2022-03-11  2:14 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19  9:56 [Bug c++/103328] New: IC in remap_gimple_stmt, at tree-inline.c:1921 avi@cloudius-systems.com
2021-11-19 10:41 ` [Bug c++/103328] ICE " rguenth at gcc dot gnu.org
2021-11-19 10:41 ` rguenth at gcc dot gnu.org
2021-11-19 11:07 ` [Bug c++/103328] [11/12 Regression] ICE in remap_gimple_stmt, at tree-inline.c:1921 since r11-7419-g0f161cc8494cf728 marxin at gcc dot gnu.org
2021-11-19 11:26 ` jakub at gcc dot gnu.org
2021-11-19 11:57 ` avi@cloudius-systems.com
2021-11-19 12:03 ` avi@cloudius-systems.com
2021-11-19 12:07 ` jakub at gcc dot gnu.org
2021-11-19 12:10 ` avi@cloudius-systems.com
2021-11-19 12:11 ` avi@cloudius-systems.com
2021-11-19 12:20 ` avi@cloudius-systems.com
2021-11-19 12:28 ` rguenth at gcc dot gnu.org
2021-11-19 12:46 ` rguenth at gcc dot gnu.org
2021-11-19 12:48 ` rguenth at gcc dot gnu.org
2021-11-19 13:42 ` rguenth at gcc dot gnu.org
2021-11-19 13:59 ` iains at gcc dot gnu.org
2021-11-19 14:05 ` rguenth at gcc dot gnu.org
2021-11-20 11:15 ` avi@cloudius-systems.com
2022-01-17 12:55 ` rguenth at gcc dot gnu.org
2022-02-26 17:17 ` piotr.grabowski at scylladb dot com
2022-03-11  2:14 ` gcc at bmevers dot de [this message]
2022-03-11 16:40 ` gcc at bmevers dot de
2022-03-15 15:29 ` avi at scylladb dot com
2022-03-22 14:48 ` [Bug c++/103328] [11/12 Regression] ICE in remap_gimple_stmt with coroutines " avi at scylladb dot com
2022-04-03 10:28 ` cvs-commit at gcc dot gnu.org
2022-04-04 15:05 ` avi at scylladb dot com
2022-04-07 12:04 ` [Bug c++/103328] [11 " cvs-commit at gcc dot gnu.org
2022-04-07 12:06 ` rguenth at gcc dot gnu.org
2022-04-07 14:42 ` avi at scylladb dot com

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=bug-103328-4-nAM1CHqoEq@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).