diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2020-04-29 19:46:35 +0100 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2020-04-30 15:58:48 +0100 |
commit | aa94a22f5cb337e173d7119ffd5a92f1e607f544 (patch) | |
tree | 9c9e6e0016044853d6888e89af6d1509fbd017b4 /gcc/cp | |
parent | b16fd5fd8afe6f95c8ae44e759971e605c31f97b (diff) | |
download | gcc-aa94a22f5cb337e173d7119ffd5a92f1e607f544.zip gcc-aa94a22f5cb337e173d7119ffd5a92f1e607f544.tar.gz gcc-aa94a22f5cb337e173d7119ffd5a92f1e607f544.tar.bz2 |
coroutines: Fix handling of target cleanup exprs [PR94883]
The problem here is that target cleanup expressions have been
added to the initialisers for the awaitable (and returns of
non-trivial values from await_suspend() calls. This is because
the expansion of the co_await into its control flow is not
apparent to the machinery adding the target cleanup expressions.
The solution being tested is simply to recreate target expressions
as the co_awaits are lowered. Teaching the machinery to handle
walking co_await expressions in different ways at different points
(outside the coroutine transformation) seems overly complex.
gcc/cp/ChangeLog:
2020-04-30 Iain Sandoe <iain@sandoe.co.uk>
PR c++/94883
* coroutines.cc (register_awaits): Update target
expressions for awaitable and suspend handle
initializers.
gcc/testsuite/ChangeLog:
2020-04-30 Iain Sandoe <iain@sandoe.co.uk>
PR c++/94883
* g++.dg/coroutines/pr94883-folly-2.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/coroutines.cc | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3172f94..62f997e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,12 @@ 2020-04-30 Iain Sandoe <iain@sandoe.co.uk> + PR c++/94883 + * coroutines.cc (register_awaits): Update target + expressions for awaitable and suspend handle + initializers. + +2020-04-30 Iain Sandoe <iain@sandoe.co.uk> + PR c++/94879 * coroutines.cc (build_co_await): Account for variables with DECL_VALUE_EXPRs. diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index e2dbeab..cb9074e 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -2757,6 +2757,17 @@ register_awaits (tree *stmt, int *do_subtree ATTRIBUTE_UNUSED, void *d) free (nam); } + tree o = TREE_OPERAND (aw_expr, 2); /* Initialiser for the frame var. */ + /* If this is a target expression, then we need to remake it to strip off + any extra cleanups added. */ + if (TREE_CODE (o) == TARGET_EXPR) + TREE_OPERAND (aw_expr, 2) = get_target_expr (TREE_OPERAND (o, 1)); + + tree v = TREE_OPERAND (aw_expr, 3); + o = TREE_VEC_ELT (v, 1); + if (TREE_CODE (o) == TARGET_EXPR) + TREE_VEC_ELT (v, 1) = get_target_expr (TREE_OPERAND (o, 1)); + register_await_info (aw_expr, aw_field_type, aw_field_nam); /* Count how many awaits the current expression contains. */ |