From patchwork Thu Apr 30 12:33:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1280331 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49CZYH2g1qz9sRY for ; Thu, 30 Apr 2020 22:33:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C4E0395B826; Thu, 30 Apr 2020 12:33:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp1.wavenetuk.net (smtp.wavenetuk.net [195.26.36.10]) by sourceware.org (Postfix) with ESMTP id A93F03896815 for ; Thu, 30 Apr 2020 12:33:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A93F03896815 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=iain@sandoe.co.uk Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by smtp1.wavenetuk.net (Postfix) with ESMTPA id 9ED451200B77; Thu, 30 Apr 2020 13:33:10 +0100 (BST) From: Iain Sandoe Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] coroutines: Fix cases where proxy variables are used [PR94879] Message-Id: <2D37A3D2-F639-40A7-B06E-9F4AFAFF77F8@sandoe.co.uk> Date: Thu, 30 Apr 2020 13:33:03 +0100 To: GCC Patches X-Mailer: Apple Mail (2.3273) X-Spam-Status: No, score=-25.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nathan Sidwell Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This was found when attempting to build folly’s experimental coros tests. tested on x86_64-darwin, linux, powerpc64-linux ok for master? thanks Iain ---- There are several places where the handling of a variable declaration depends on whether it corresponds to a compiler temporary, or to some other entity. We were testing that var decls were artificial in determining this. However, proxy vars are also artificial so that this is not sufficient. The solution is to exclude variables with a DECL_VALUE_EXPR as well, since the value variable will not be a temporary. gcc/cp/ChangeLog: 2020-04-30 Iain Sandoe PR c++/94879 * coroutines.cc (build_co_await): Account for variables with DECL_VALUE_EXPRs. (captures_temporary): Likewise. (register_awaits): Likewise. gcc/testsuite/ChangeLog: 2020-04-30 Iain Sandoe PR c++/94879 * g++.dg/coroutines/pr94879-folly-1.C: New test. --- gcc/cp/coroutines.cc | 9 ++-- .../g++.dg/coroutines/pr94879-folly-1.C | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr94879-folly-1.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 7bb3e98fe6c..e2dbeabf48b 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -748,7 +748,8 @@ build_co_await (location_t loc, tree a, suspend_point_kind suspend_kind) if (INDIRECT_REF_P (e_proxy)) e_proxy = TREE_OPERAND (e_proxy, 0); if (TREE_CODE (e_proxy) == PARM_DECL - || (TREE_CODE (e_proxy) == VAR_DECL && !DECL_ARTIFICIAL (e_proxy))) + || (VAR_P (e_proxy) && (!DECL_ARTIFICIAL (e_proxy) + || DECL_HAS_VALUE_EXPR_P (e_proxy)))) e_proxy = o; else { @@ -2659,7 +2660,8 @@ captures_temporary (tree *stmt, int *do_subtree, void *d) } /* This isn't a temporary. */ - if ((TREE_CODE (parm) == VAR_DECL && !DECL_ARTIFICIAL (parm)) + if ((VAR_P (parm) + && (!DECL_ARTIFICIAL (parm) || DECL_HAS_VALUE_EXPR_P (parm))) || TREE_CODE (parm) == PARM_DECL || TREE_CODE (parm) == NON_LVALUE_EXPR) continue; @@ -2742,7 +2744,8 @@ register_awaits (tree *stmt, int *do_subtree ATTRIBUTE_UNUSED, void *d) if (INDIRECT_REF_P (aw)) aw = TREE_OPERAND (aw, 0); if (TREE_CODE (aw) == PARM_DECL - || (TREE_CODE (aw) == VAR_DECL && !DECL_ARTIFICIAL (aw))) + || (VAR_P (aw) && (!DECL_ARTIFICIAL (aw) + || DECL_HAS_VALUE_EXPR_P (aw)))) ; /* Don't make an additional copy. */ else { diff --git a/gcc/testsuite/g++.dg/coroutines/pr94879-folly-1.C b/gcc/testsuite/g++.dg/coroutines/pr94879-folly-1.C new file mode 100644 index 00000000000..7d66ce004f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr94879-folly-1.C @@ -0,0 +1,49 @@ +// { dg-additional-options "-fpreprocessed -w" } + +namespace std { +template a b(a &&); +template struct d { c e; }; +template struct coroutine_traits : f {}; +template struct coroutine_handle; +template <> struct coroutine_handle<> {}; +template struct coroutine_handle : coroutine_handle<> {}; +struct g {}; +} // namespace std + +class h {}; +class i { + i(i &&); +}; + +namespace ac { +template class ad { +public: + bool await_ready(); + void await_resume(); + void await_suspend(std::coroutine_handle<>); + i ae; +}; +} // namespace ac + +template ac::ad operator co_await(ab); +class j { + class l {}; + +public: + std::g initial_suspend(); + l final_suspend(); +}; +class m : public j { +public: + void get_return_object(); + void unhandled_exception(); +}; +class n { +public: + using promise_type = m; +}; +std::d k; +void a() { + auto am = k; + [&]() -> n { co_await std::b(am.e); }; +}