public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106188] New: [11.3 Regression] [coroutines] Incorrect frame layout after transforming conditional statement without top-level bind expression
@ 2022-07-04 19:30 gcc-bugzilla at decltype dot org
  2022-09-07 14:47 ` [Bug c++/106188] " cvs-commit at gcc dot gnu.org
  2023-03-16 19:46 ` arsen at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gcc-bugzilla at decltype dot org @ 2022-07-04 19:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106188
           Summary: [11.3 Regression] [coroutines] Incorrect frame layout
                    after transforming conditional statement without
                    top-level bind expression
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugzilla at decltype dot org
  Target Milestone: ---

Created attachment 53257
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53257&action=edit
Minimal test case

During `morph_fn_to_coro`, `await_statement_walker` rewrites IF and SWITCH
statements by breaking the condition out into a local variable. The new
variable is inserted at the beginning of the containing bind expression.

If the original function lacked a top-level bind expression, this pushes the
resume function pointer and all following fixed-layout frame members away from
their intended placement.

Expected frame layout:
_Coro_resume_fn
_Coro_destroy_fn
_Coro_promise
_Coro_self_handle
params
_Coro_resume_index
_Coro_frame_needs_free
_Coro_initial_await_resume_called
locals (ifcd/swch)

Actual frame layout (since 11.3.0):
locals (ifcd/swch) <- out of place
_Coro_resume_fn
_Coro_destroy_fn
_Coro_promise
_Coro_self_handle
params
_Coro_resume_index
_Coro_frame_needs_free
_Coro_initial_await_resume_called

The attached program triggers this error and crashes. Uncommenting the unused
local variable resolves the crash.

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

* [Bug c++/106188] [coroutines] Incorrect frame layout after transforming conditional statement without top-level bind expression
  2022-07-04 19:30 [Bug c++/106188] New: [11.3 Regression] [coroutines] Incorrect frame layout after transforming conditional statement without top-level bind expression gcc-bugzilla at decltype dot org
@ 2022-09-07 14:47 ` cvs-commit at gcc dot gnu.org
  2023-03-16 19:46 ` arsen at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-07 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:a961ad1b13b9c294d4565344912b8e35ba71b369

commit r13-2524-ga961ad1b13b9c294d4565344912b8e35ba71b369
Author: Arsen ArsenoviÄ <arsen@aarsen.me>
Date:   Sun Sep 4 21:04:23 2022 +0200

    c++: top level bind when rewriting coroutines [PR106188]

    In the edge case of a coroutine not containing any locals, the ifcd/switch
    temporaries would get added to the coroutine frame, corrupting its
    layout. To prevent this, we can make sure there is always a BIND_EXPR at
    the top of the function body, and thus, always a place for our new
    temporaries to go without interfering with the coroutine frame.

    PR c++/106188 - Incorrect frame layout after transforming conditional
statement without top-level bind expression
    PR c++/106713 - if (co_await ...) crashes with a jump to ud2

            PR c++/106188
            PR c++/106713

    gcc/cp/ChangeLog:

            * coroutines.cc (coro_rewrite_function_body): Ensure we have a
            BIND_EXPR wrapping the function body.

    gcc/testsuite/ChangeLog:

            * g++.dg/coroutines/pr106188.C: New test.

    Signed-off-by: Arsen ArsenoviÄ <arsen@aarsen.me>

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

* [Bug c++/106188] [coroutines] Incorrect frame layout after transforming conditional statement without top-level bind expression
  2022-07-04 19:30 [Bug c++/106188] New: [11.3 Regression] [coroutines] Incorrect frame layout after transforming conditional statement without top-level bind expression gcc-bugzilla at decltype dot org
  2022-09-07 14:47 ` [Bug c++/106188] " cvs-commit at gcc dot gnu.org
@ 2023-03-16 19:46 ` arsen at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: arsen at gcc dot gnu.org @ 2023-03-16 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

Arsen Arsenović <arsen at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
Should be fixed on all branches.

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

end of thread, other threads:[~2023-03-16 19:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04 19:30 [Bug c++/106188] New: [11.3 Regression] [coroutines] Incorrect frame layout after transforming conditional statement without top-level bind expression gcc-bugzilla at decltype dot org
2022-09-07 14:47 ` [Bug c++/106188] " cvs-commit at gcc dot gnu.org
2023-03-16 19:46 ` arsen at gcc dot gnu.org

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).