* [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517].
@ 2021-11-05 16:01 Iain Sandoe
2021-11-05 20:50 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Iain Sandoe @ 2021-11-05 16:01 UTC (permalink / raw)
To: gcc-patches
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 <iain@sandoe.co.uk>
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 <coroutine>
+
+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)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517].
2021-11-05 16:01 [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517] Iain Sandoe
@ 2021-11-05 20:50 ` Jason Merrill
2021-11-05 21:16 ` Iain Sandoe
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2021-11-05 20:50 UTC (permalink / raw)
To: iain, gcc-patches
On 11/5/21 12:01, Iain Sandoe wrote:
> + || (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))))));
Are there other places that want to look through DECL_RAMP_FN like this,
such that this should be factored into e.g.
LAMBDA_FUNCTION_P (non_coroutine (DECL_CONTEXT (decl)))
?
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517].
2021-11-05 20:50 ` Jason Merrill
@ 2021-11-05 21:16 ` Iain Sandoe
2021-11-05 21:53 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Iain Sandoe @ 2021-11-05 21:16 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi Jason,
> On 5 Nov 2021, at 20:50, Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>
> On 11/5/21 12:01, Iain Sandoe wrote:
>> + || (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))))));
>
> Are there other places that want to look through DECL_RAMP_FN like this, such that this should be factored into e.g.
>
> LAMBDA_FUNCTION_P (non_coroutine (DECL_CONTEXT (decl)))
At present, I am not aware of another use (there are none in my WIP fixes) - but that stack of macros is a bit of a mouthful - maybe a function would be neater anyway.
non_coroutine () doesn’t convey its meaning to me - what we are trying to say “get me the ramp context” but that’s very detailed.
Let me see if I can come up with a function and a name…
Iain
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517].
2021-11-05 21:16 ` Iain Sandoe
@ 2021-11-05 21:53 ` Jason Merrill
2021-11-06 0:48 ` Iain Sandoe
2021-12-17 16:56 ` Iain Sandoe
0 siblings, 2 replies; 6+ messages in thread
From: Jason Merrill @ 2021-11-05 21:53 UTC (permalink / raw)
To: Iain Sandoe; +Cc: gcc-patches
On 11/5/21 17:16, Iain Sandoe wrote:
> Hi Jason,
>
>> On 5 Nov 2021, at 20:50, Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>>
>> On 11/5/21 12:01, Iain Sandoe wrote:
>>> + || (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))))));
>>
>> Are there other places that want to look through DECL_RAMP_FN like this, such that this should be factored into e.g.
>>
>> LAMBDA_FUNCTION_P (non_coroutine (DECL_CONTEXT (decl)))
>
> At present, I am not aware of another use (there are none in my WIP fixes) - but that stack of macros is a bit of a mouthful - maybe a function would be neater anyway.
>
> non_coroutine () doesn’t convey its meaning to me - what we are trying to say “get me the ramp context” but that’s very detailed.
I figured what we want is the user-written function corresponding to the
argument. Hmm, the coroutine helpers don't use DECL_ABSTRACT_ORIGIN, do
they?
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517].
2021-11-05 21:53 ` Jason Merrill
@ 2021-11-06 0:48 ` Iain Sandoe
2021-12-17 16:56 ` Iain Sandoe
1 sibling, 0 replies; 6+ messages in thread
From: Iain Sandoe @ 2021-11-06 0:48 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi Jason
> On 5 Nov 2021, at 21:53, Jason Merrill <jason@redhat.com> wrote:
>
> On 11/5/21 17:16, Iain Sandoe wrote:
>> Hi Jason,
>>> On 5 Nov 2021, at 20:50, Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>>>
>>> On 11/5/21 12:01, Iain Sandoe wrote:
>>>> + || (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))))));
>>>
>>> Are there other places that want to look through DECL_RAMP_FN like this, such that this should be factored into e.g.
>>>
>>> LAMBDA_FUNCTION_P (non_coroutine (DECL_CONTEXT (decl)))
>> At present, I am not aware of another use (there are none in my WIP fixes) - but that stack of macros is a bit of a mouthful - maybe a function would be neater anyway.
>> non_coroutine () doesn’t convey its meaning to me - what we are trying to say “get me the ramp context” but that’s very detailed.
>
> I figured what we want is the user-written function corresponding to the argument.
yes, we want the context of the original function that contained the variable/proxy we’re examining.
- the original function becomes the ramp.
> Hmm, the coroutine helpers don't use DECL_ABSTRACT_ORIGIN, do they?
No, it did not work AFAIR - at the time I figured it was because the helpers are not actually real clones of the original function but outlined portions of it (with a different signature).
Iain
>
> Jason
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517].
2021-11-05 21:53 ` Jason Merrill
2021-11-06 0:48 ` Iain Sandoe
@ 2021-12-17 16:56 ` Iain Sandoe
1 sibling, 0 replies; 6+ messages in thread
From: Iain Sandoe @ 2021-12-17 16:56 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi Jason,
> On 5 Nov 2021, at 21:53, Jason Merrill <jason@redhat.com> wrote:
>
> On 11/5/21 17:16, Iain Sandoe wrote:
>> Hi Jason,
>>> On 5 Nov 2021, at 20:50, Jason Merrill via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>>>
>>> On 11/5/21 12:01, Iain Sandoe wrote:
>>>> + || (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))))));
>>>
>>> Are there other places that want to look through DECL_RAMP_FN like this, such that this should be factored into e.g.
>>>
>>> LAMBDA_FUNCTION_P (non_coroutine (DECL_CONTEXT (decl)))
>> At present, I am not aware of another use (there are none in my WIP fixes) - but that stack of macros is a bit of a mouthful - maybe a function would be neater anyway.
>> non_coroutine () doesn’t convey its meaning to me - what we are trying to say “get me the ramp context” but that’s very detailed.
>
> I figured what we want is the user-written function corresponding to the argument. Hmm, the coroutine helpers don't use DECL_ABSTRACT_ORIGIN, do they?
You fixed this PR with r12-5255-gdaa9c6b015, so my patch is not needed.
I pushed the testcase as r12-6044-g39d2ec41509e.
thanks
Iain
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-17 16:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 16:01 [PATCH] coroutines, c++: Find lambda-ness from the ramp function [PR 96517] Iain Sandoe
2021-11-05 20:50 ` Jason Merrill
2021-11-05 21:16 ` Iain Sandoe
2021-11-05 21:53 ` Jason Merrill
2021-11-06 0:48 ` Iain Sandoe
2021-12-17 16:56 ` Iain Sandoe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).