aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorArsen Arsenović <arsen@aarsen.me>2022-09-04 21:04:23 +0200
committerJason Merrill <jason@redhat.com>2022-09-07 10:47:49 -0400
commita961ad1b13b9c294d4565344912b8e35ba71b369 (patch)
treea6020fff5623328c808e7debb3a74d1f6f56e729 /gcc/cp
parentcdcc27c1ca9c485c66ac1914e352c79e5048b6b5 (diff)
downloadgcc-a961ad1b13b9c294d4565344912b8e35ba71b369.zip
gcc-a961ad1b13b9c294d4565344912b8e35ba71b369.tar.gz
gcc-a961ad1b13b9c294d4565344912b8e35ba71b369.tar.bz2
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>
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/coroutines.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index edb3b70..eca01ab 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4095,6 +4095,15 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig,
BLOCK_SUPERCONTEXT (replace_blk) = top_block;
BLOCK_SUBBLOCKS (top_block) = replace_blk;
}
+ else
+ {
+ /* We are missing a top level BIND_EXPR. We need one to ensure that we
+ don't shuffle around the coroutine frame and corrupt it. */
+ tree bind_wrap = build3_loc (fn_start, BIND_EXPR, void_type_node,
+ NULL, NULL, NULL);
+ BIND_EXPR_BODY (bind_wrap) = fnbody;
+ fnbody = bind_wrap;
+ }
/* Wrap the function body in a try {} catch (...) {} block, if exceptions
are enabled. */