From f1656ae9234d1a1caee79183786d1f0ac2f8dbf4 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Tue, 5 May 2020 20:27:27 +0100 Subject: [PATCH] coroutines: Replace extra checks for co_yield with asserts. The lowering of co_yield to a promise method call and a co_await was moved to the initial analysis phase with the intention of avoiding the need to handle the two cases later. Before removing the later checks entirely, this patch replaces them with checking asserts. gcc/cp/Changelog: 2020-05-05 Iain Sandoe * coroutines.cc (transform_await_wrapper): Check that we have no unlowered co_yields. (captures_temporary): Likewise. (register_awaits): Likewise. --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/coroutines.cc | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3dece835650..17e24d269d2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2020-05-05 Iain Sandoe + + * coroutines.cc (transform_await_wrapper): Check that we have + no unlowered co_yields. + (captures_temporary): Likewise. + (register_awaits): Likewise. + 2020-05-05 Nathan Sidwell PR c++/94807 diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 0c91abc84f2..ed871e1bab1 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1743,7 +1743,9 @@ transform_await_wrapper (tree *stmt, int *do_subtree, void *d) && DECL_CONTEXT (*stmt) != xform->actor_fn) DECL_CONTEXT (*stmt) = xform->actor_fn; - if (TREE_CODE (*stmt) != CO_AWAIT_EXPR && TREE_CODE (*stmt) != CO_YIELD_EXPR) + /* We should have already lowered co_yields to their co_await. */ + gcc_checking_assert (TREE_CODE (*stmt) != CO_YIELD_EXPR); + if (TREE_CODE (*stmt) != CO_AWAIT_EXPR) return NULL_TREE; tree await_expr = *stmt; @@ -2612,9 +2614,12 @@ struct susp_frame_data static tree captures_temporary (tree *stmt, int *do_subtree, void *d) { + /* We should have already lowered co_yields to their co_await. */ + gcc_checking_assert (TREE_CODE (*stmt) != CO_YIELD_EXPR); + /* Stop recursing if we see an await expression, the subtrees of that will be handled when it is processed. */ - if (TREE_CODE (*stmt) == CO_AWAIT_EXPR || TREE_CODE (*stmt) == CO_YIELD_EXPR) + if (TREE_CODE (*stmt) == CO_AWAIT_EXPR) { *do_subtree = 0; return NULL_TREE; @@ -2732,17 +2737,14 @@ register_awaits (tree *stmt, int *do_subtree ATTRIBUTE_UNUSED, void *d) { susp_frame_data *data = (susp_frame_data *) d; - if (TREE_CODE (*stmt) != CO_AWAIT_EXPR && TREE_CODE (*stmt) != CO_YIELD_EXPR) + /* We should have already lowered co_yields to their co_await. */ + gcc_checking_assert (TREE_CODE (*stmt) != CO_YIELD_EXPR); + + if (TREE_CODE (*stmt) != CO_AWAIT_EXPR) return NULL_TREE; tree aw_expr = *stmt; location_t aw_loc = EXPR_LOCATION (aw_expr); /* location of the co_xxxx. */ - /* co_yield is syntactic sugar, re-write it to co_await. */ - if (TREE_CODE (aw_expr) == CO_YIELD_EXPR) - { - aw_expr = TREE_OPERAND (aw_expr, 1); - *stmt = aw_expr; - } /* If the awaitable is a parm or a local variable, then we already have a frame copy, so don't make a new one. */ -- 2.30.2