From patchwork Tue Feb 11 02:14:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: JunMa X-Patchwork-Id: 1236127 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-519298-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=Dmt6mAQS; 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 48GmZL4mdjz9sP7 for ; Tue, 11 Feb 2020 13:15:04 +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=V4CMxEiXNc4fHuA7tKLb3qrARcOV4qtnKb9KdEWybxmlrkbnaG Wbn1gotjeNfLlnisdpqml43q6xvs1Wnj3r5P//M6Y28cc/D3mIN3WZS7IkauJyo+ GOVdZtFc9Dbws/Se+wK4E+/yMd590hJq7BnGN+CBe3uoifUpHg6ANjQLQ= 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=e6jlQHQk/mrrL21gSeOCgylI2aI=; b=Dmt6mAQSA2ta/6CiE9Z5 iDfQFjWaG+l6MzX4S1nGbjJOG2ewVBuDADyYbyASyORBpsUIgZzCfnJf42DBJtgK 2jRf/vJtMYAdDsof9DB6+Qi+oKRcrB3+oCF37EBTxBWwfnpacRAyKavTpM7+dBqa SiIeUIxDS87vArdUWGSxlfQ= Received: (qmail 99301 invoked by alias); 11 Feb 2020 02:14:55 -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 99289 invoked by uid 89); 11 Feb 2020 02:14:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 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=H*UA:Macintosh, H*u:Macintosh X-HELO: out30-131.freemail.mail.aliyun.com Received: from out30-131.freemail.mail.aliyun.com (HELO out30-131.freemail.mail.aliyun.com) (115.124.30.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 02:14:53 +0000 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R201e4; 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_---0TpdeAPD_1581387286; Received: from 30.25.219.200(mailfrom:JunMa@linux.alibaba.com fp:SMTPD_---0TpdeAPD_1581387286) by smtp.aliyun-inc.com(127.0.0.1); Tue, 11 Feb 2020 10:14:47 +0800 To: gcc-patches Cc: Iain Sandoe , Nathan Sidwell From: JunMa Subject: [PATCH coroutines] Do not strip cleanup_point when promote temporaries out of current stmt Message-ID: Date: Tue, 11 Feb 2020 10:14:46 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 X-IsSubscribed: yes Hi In maybe_promote_captured_temps, the cleanup_point_stmt has been stripped when handle temporaries captured by reference. However, maybe there are non-reference temporaries in current stmt which cause ice in gimpilify pass. This patch fix this. The testcase comes from cppcoro and is reduced by creduce. Bootstrap and test on X86_64, is it OK? Regards JunMa gcc/cp 2020-02-11  Jun Ma         * coroutines.cc (maybe_promote_captured_temps): Do not strip         cleanup_point_stmt. gcc/testsuite 2020-02-11  Jun Ma         * g++.dg/coroutines/torture/lambda-09-capture-object.C: New test. --- gcc/cp/coroutines.cc | 8 +- .../torture/lambda-09-capture-object.C | 132 ++++++++++++++++++ 2 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/torture/lambda-09-capture-object.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 9fcbb647201..3095b46ecb1 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -2681,11 +2681,9 @@ maybe_promote_captured_temps (tree *stmt, void *d) location_t sloc = EXPR_LOCATION (*stmt); tree aw_bind = build3_loc (sloc, BIND_EXPR, void_type_node, NULL, NULL, NULL); - tree aw_statement_current; - if (TREE_CODE (*stmt) == CLEANUP_POINT_EXPR) - aw_statement_current = TREE_OPERAND (*stmt, 0); - else - aw_statement_current = *stmt; + /* Do not skip cleanup_point since maybe there are other temporaries + need cleanup. */ + tree aw_statement_current = *stmt; /* Collected the scope vars we need move the temps to regular. */ tree aw_bind_body = push_stmt_list (); tree varlist = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/coroutines/torture/lambda-09-capture-object.C b/gcc/testsuite/g++.dg/coroutines/torture/lambda-09-capture-object.C new file mode 100644 index 00000000000..1297b72cc8f --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/lambda-09-capture-object.C @@ -0,0 +1,132 @@ +// { dg-do compile } +// { dg-additional-options "-Wno-return-type" } + +#include "../coro.h" +#include +#include + +template > struct a; +template +struct a().await_resume())>> + : std::conjunction<> {}; +template +auto c(b value, int) -> decltype(value.operator co_await()); +template ::value, int> = 0> b c(b, int); +template auto d(b value) -> decltype(c(value, 3)) {} +template struct f { + using e = decltype(d(std::declval())); + using h = decltype(std::declval().await_resume()); +}; +template class s; +template class s> { +public: + s(std::tuple); + auto operator co_await() { + struct aa { + std::tuple await_resume() {}; + s i; + }; + return aa{*this}; + } +}; +template class k { +public: + using l = std::coroutine_handle; + j m(); +}; +template class ab { +public: + using promise_type = k; + using l = typename promise_type::l; + auto m() { return n.promise().m(); } + auto ac() { return m(); } + l n; +}; +template ::h, + std::enable_if_t, int> = 0> +ab p(o); +template struct u { using ad = b; }; +template using t = typename u::ad; +template , int> = 0> +auto af(ae... ag) { + return s>>::h>...>>( + std::make_tuple(p(ag)...)); +} +template class ah { + using e = typename f::e; + +public: + ah(q ai, o aj) : r(ai), ak(d(aj)) {} + auto await_ready() { return 0; } + template auto await_suspend(std::coroutine_handle) {} + template , int> = 0> + auto await_resume() { + return invoke(r, ak.await_resume()); + } + q r; + e ak; +}; +template class x { +public: + template , int> = 0> + x(y ai, al aj) : r(ai), i(aj) {} + auto operator co_await() { return ah(r, i); } + q r; + o i; +}; +template auto am(q ai, o aj) { + return x>, + std::remove_cv_t>>(ai, aj); +} +template , int> = 0> +auto an(ae... ag) { + return am( + [](auto ao) { + auto ap = + apply([](auto... aq) { return std::make_tuple(aq.ac()...); }, ao); + return ap; + }, + af(ag...)); +} +class ar; +class z { +public: + ar as(); +}; +class at { +public: + ~at(); +}; +class ar { +public: + at await_resume(); +}; +class au; +class av { + struct aw { + bool await_ready(); + template void await_suspend(std::coroutine_handle); + void await_resume(); + }; + +public: + auto initial_suspend() { return std::suspend_always{}; } + auto final_suspend() { return aw{}; } +}; +class ax : public av { +public: + au get_return_object(); + void unhandled_exception(); +}; +class au { +public: + using promise_type = ax; +}; +void d() { + []() -> au { + z ay; + co_await an(ay.as()); + }; +}