From patchwork Tue Jan 21 04:08:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: JunMa X-Patchwork-Id: 1226234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-517848-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=JFHxEY8j; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 481w4t3BRTz9sNF for ; Tue, 21 Jan 2020 15:08:28 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=QE16vR8jEb5hj73HdzXscUK8Akh/2b8CR1ToqjUtF70aJdeoQw hrSn5sFrN6igwzft8Z5Yah1pGzLtQ5wRE1g7rEXS8BneTyvIbWss5Hq67vRf9LmX UN6l5EdhPKJFm/Ca2fOsvowvs4KGEyZNawngd+hC3EvAvBgp/fnudL9vg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=QLk7J+4Kzlp66eJVWdlfZEMBRpQ=; b=JFHxEY8j27DkbfCH+oVN pSnlfYd3XVPmPm35+z++T8IlayNusv3XPdfaEvGQ4vw6WpY/PaoZGPAJrgJ+sbDi 3qWMje07exuOnz9NNysmCt+hVguBInwmJTt13+oicR5YUf2IMVqaE8qaeT6yzvX7 cJtP4UsOUn3g9CJctN61ufE= Received: (qmail 99233 invoked by alias); 21 Jan 2020 04:08:20 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 99212 invoked by uid 89); 21 Jan 2020 04:08:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.0 required=5.0 tests=AWL, BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy= X-HELO: out30-57.freemail.mail.aliyun.com Received: from out30-57.freemail.mail.aliyun.com (HELO out30-57.freemail.mail.aliyun.com) (115.124.30.57) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jan 2020 04:08:16 +0000 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R101e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01f04427; MF=junma@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0ToGlZMw_1579579691; Received: from MacBook-Pro-6.local(mailfrom:JunMa@linux.alibaba.com fp:SMTPD_---0ToGlZMw_1579579691) by smtp.aliyun-inc.com(127.0.0.1); Tue, 21 Jan 2020 12:08:12 +0800 To: gcc-patches Cc: Iain Sandoe , Nathan Sidwell From: JunMa Subject: [PATCH Coroutines] Change context of label_decl in original function Message-ID: <8a01fe69-363d-fce5-cc25-3cba820d0533@linux.alibaba.com> Date: Tue, 21 Jan 2020 12:08:11 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi This patch does minor fix on changing context of label_decl from original function to actor function which avoid assertion in gimplify pass. Bootstrap and test on X86_64, is it OK? Regards JunMa gcc/cp 2020-01-21  Jun Ma         * coroutines.cc (transform_await_wrapper): Set actor funcion as         new context of label_decl.         (build_actor_fn): Fill new field of await_xform_data. gcc/testsuite 2020-01-21  Jun Ma         * g++.dg/coroutines/co-await-04-control-flow.C: Add label. --- gcc/cp/coroutines.cc | 11 ++++++++--- .../coroutines/torture/co-await-04-control-flow.C | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index bd3656562ec..2b6a154d28f 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1562,6 +1562,7 @@ static hash_map *suspend_points; struct await_xform_data { + tree actor_fn; /* Decl for context. */ tree actor_frame; tree promise_proxy; tree real_promise; @@ -1643,12 +1644,16 @@ transform_await_expr (tree await_expr, await_xform_data *xform) static tree transform_await_wrapper (tree *stmt, int *do_subtree, void *d) { + /* Set actor function as new DECL_CONTEXT of label_decl. */ + struct await_xform_data *xform = (struct await_xform_data *) d; + if (TREE_CODE (*stmt) == LABEL_DECL + && 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) return NULL_TREE; tree await_expr = *stmt; - await_xform_data *xform = (await_xform_data *) d; - *stmt = transform_await_expr (await_expr, xform); if (*stmt == error_mark_node) *do_subtree = 0; @@ -2005,7 +2010,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody, decide where to put things. */ await_xform_data xform - = {actor_frame, promise_proxy, ap, self_h_proxy, ash}; + = {actor, actor_frame, promise_proxy, ap, self_h_proxy, ash}; /* Get a reference to the initial suspend var in the frame. */ transform_await_expr (initial_await, &xform); diff --git a/gcc/testsuite/g++.dg/coroutines/torture/co-await-04-control-flow.C b/gcc/testsuite/g++.dg/coroutines/torture/co-await-04-control-flow.C index 9bc99e875d0..e8da2d2e2ad 100644 --- a/gcc/testsuite/g++.dg/coroutines/torture/co-await-04-control-flow.C +++ b/gcc/testsuite/g++.dg/coroutines/torture/co-await-04-control-flow.C @@ -16,9 +16,11 @@ coro1 f () { if (gX < 12) { +L1: gX += y; gX += co_await 11; } else +L2: gX += co_await 12; co_return gX;