From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 88E5C385E019 for ; Fri, 5 Nov 2021 16:01:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 88E5C385E019 Received: by mail-wr1-x42c.google.com with SMTP id s13so14513099wrb.3 for ; Fri, 05 Nov 2021 09:01:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=Kd0P/H48HLGAvqDabufZo4rDjcVMqohvFR+qeUGbajE=; b=btP+3Ht/uEATl3ekOWkviVod3vf6sP+wtd/g1aCrJxIIEtUGATkr2JzWQAgDKPNiAO qEogECTBVlKVhDuTPcJypXpxALVdibp6u4/bEZgxmK1/Zere9znbrLLsmq4WVJghZpQU fkAY4AdCpViXZCXsTbTF6hG+nkQHVcM25rCBq+I6oUYY/nCEg1IR+8C1A0fLZzmRWX16 F4bIQKX9EwXVys0HNtokkuue0GwCAx5y1tvFWSLGNve/Eoo9UN5U/Kssb+RKZe47S49e W+R09xY8uP1bEFUviAdQ9E/FJIi6JTjPcET23zjLK0P3SqNGlqO6D9FNv7DX+Cu0y6BG LEhQ== X-Gm-Message-State: AOAM533NZ+zTZqI/7mRWwCIKggsp1wa7EyGYKJ7ay68DUd2PQXRYRvDh nN8j0ZU4zp0tcbbq0xg2vZcAA0qPgwA= X-Google-Smtp-Source: ABdhPJwiQ8MH49LIrcpmf61L2TdpFU8rzF8vv7glDDqMen+G9pd08O0Y4e2BBjb8yayGKcERRBhARw== X-Received: by 2002:a5d:400e:: with SMTP id n14mr61287250wrp.368.1636128089560; Fri, 05 Nov 2021 09:01:29 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id d9sm8111685wre.52.2021.11.05.09.01.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Nov 2021 09:01:29 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517]. Date: Fri, 5 Nov 2021 16:01:23 +0000 Message-Id: <20211105160123.15808-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) Reply-To: iain@sandoe.co.uk MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Fri, 05 Nov 2021 16:01:32 -0000 When we query is_capture_proxy(), and the scope of the var is one of the two coroutine helpers, we need to look for the scope information that pertains to the original function (represented by the ramp now). We can look up the ramp function from either helper (in practice, the only caller would be the actor) and if that lookup returns NULL, it means that the coroutine component is the ramp already and handled by the usual code path. tested on x86_64-darwin, linux, OK for master / backports ? thanks Iain Signed-off-by: Iain Sandoe gcc/cp/ChangeLog: PR c++/96517 * lambda.c (is_capture_proxy): When the scope of the var to be tested is a coroutine helper, lookup the scope information from the parent (ramp) function. gcc/testsuite/ChangeLog: PR c++/96517 * g++.dg/coroutines/pr96517.C: New test. --- gcc/cp/lambda.c | 6 ++++- gcc/testsuite/g++.dg/coroutines/pr96517.C | 29 +++++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr96517.C diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 2e9d38bbe83..c1556480e22 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -244,7 +244,11 @@ is_capture_proxy (tree decl) && !(DECL_ARTIFICIAL (decl) && DECL_LANG_SPECIFIC (decl) && DECL_OMP_PRIVATIZED_MEMBER (decl)) - && LAMBDA_FUNCTION_P (DECL_CONTEXT (decl))); + && (LAMBDA_FUNCTION_P (DECL_CONTEXT (decl)) + || (DECL_DECLARES_FUNCTION_P (DECL_CONTEXT (decl)) + && DECL_COROUTINE_P (DECL_CONTEXT (decl)) + && DECL_RAMP_FN (DECL_CONTEXT (decl)) + && LAMBDA_FUNCTION_P (DECL_RAMP_FN (DECL_CONTEXT (decl)))))); } /* Returns true iff DECL is a capture proxy for a normal capture diff --git a/gcc/testsuite/g++.dg/coroutines/pr96517.C b/gcc/testsuite/g++.dg/coroutines/pr96517.C new file mode 100644 index 00000000000..9cbac3ebc0d --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr96517.C @@ -0,0 +1,29 @@ +// { dg-additional-options " -O1 " } +#include + +struct coroutine { + struct promise_type { + coroutine get_return_object() { return {}; } + void return_void() {} + void unhandled_exception() {} + auto initial_suspend() noexcept { return std::suspend_never{}; } + auto final_suspend() noexcept { return std::suspend_never{}; } + }; +}; + +struct data { + constexpr int get() { return 5; } +}; + +struct test { + data _data; + + void foo() { + [this]() -> coroutine { + _data.get(); + co_return; + }; + } +}; + +int main() {} -- 2.24.3 (Apple Git-128)