From 28bc74bbade67656ddded84a083e3cc1967b8bea Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Sat, 8 Jun 2019 13:26:35 +0000 Subject: [PATCH] c++-coroutines - Simplify the conditional for freeing the coro frame. The existing scheme avoided messing with scopes, which had merit at the time, but now we have a mechanism to use most of the machinery to build if statements - so do that. 2019-06-08 Iain Sandoe * coroutines.cc (build_actor_fn): Simplify the conditional call to free the coroutine frame. From-SVN: r272080 --- ChangeLog.coroutines | 5 +++++ gcc/cp/coroutines.cc | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ChangeLog.coroutines b/ChangeLog.coroutines index 8481a55b0561..8a29bde7b4de 100644 --- a/ChangeLog.coroutines +++ b/ChangeLog.coroutines @@ -1,3 +1,8 @@ +2019-06-08 Iain Sandoe + + * coroutines.cc (build_actor_fn): Simplify the conditional call to + free the coroutine frame. + 2019-06-08 Iain Sandoe * coroutines.cc (co_return_expander): Look inside cleanup point diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index c42ad36de1c8..f9ab4f3e1b00 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1451,19 +1451,20 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tf_warning_or_error); tree fnf2_x = build_class_member_access_expr (actor_frame, fnf_m, NULL_TREE, false, tf_warning_or_error); + + tree need_free_if = begin_if_stmt (); + fnf2_x = build1 (CONVERT_EXPR, integer_type_node, fnf2_x); + tree cmp = build2 (NE_EXPR, integer_type_node, fnf2_x, integer_zero_node); + finish_if_stmt_cond (cmp, need_free_if); tree free_coro_fr = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_FREE), 1, actor_fp); free_coro_fr = coro_build_cvt_void_expr_stmt (free_coro_fr, loc); - tree free_list = NULL; - append_to_statement_list (free_coro_fr, &free_list); - - tree goto_ret_list = NULL; - r = build1 (GOTO_EXPR, void_type_node, ret_label); - append_to_statement_list (r, &goto_ret_list); - - r = build3 (COND_EXPR, void_type_node, fnf2_x, free_list, goto_ret_list); - r = coro_build_expr_stmt (r, loc); + add_stmt (free_coro_fr); + finish_then_clause (need_free_if); + tree scope = IF_SCOPE (need_free_if); + IF_SCOPE (need_free_if) = NULL; + r = do_poplevel (scope); add_stmt (r); /* This is the eventual (or suspend) return point. */