[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 Eric Gallager changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 Avi Kivity changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #22 from Avi Kivity --- Certainly, closing as invalid.

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread iains at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #21 from Iain Sandoe --- Avi, If we are agreed that there is no GCC bug here (the change from pointer to reference is already in the queue) I would suggest that new design discussion would be better by putting a paper or suggestions

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #20 from Avi Kivity --- My coroutines do return suspend_never from initial_suspend(); so thanks for the workaround, I'll use it until we have a better fix.

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread iains at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #19 from Iain Sandoe --- (In reply to Ville Voutilainen from comment #17) > (In reply to Ville Voutilainen from comment #16) > > (In reply to Iain Sandoe from comment #14) > > > (In reply to Ville Voutilainen from comment #12) > > >

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #18 from Avi Kivity --- The work-around works if initial_suspend() returns suspend_never or similar. If the lambda is suspended before execution, the reference may dangle.

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #17 from Ville Voutilainen --- (In reply to Ville Voutilainen from comment #16) > (In reply to Iain Sandoe from comment #14) > > (In reply to Ville Voutilainen from comment #12) > > The idea of bringing the lambda's captures into the

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 Ville Voutilainen changed: What|Removed |Added CC||ville.voutilainen at gmail dot com

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #15 from Avi Kivity --- I believe that my suggestion works for mutable lambdas (and for any coroutine called as a member function): - if the object passeed to the member function is an lvalue, then the coroutine captures a

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread iains at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #14 from Iain Sandoe --- (In reply to Ville Voutilainen from comment #12) > It sure seems to me that a coroutine lambda's captures should be copied to > the coroutine state. I don't think the standard says that anywhere. Maybe I am

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #13 from Avi Kivity --- Yes. gcc has a minor bug in that the lambda is reflected as a pointer instead of a reference in coroutine_traits. The major bug is in the standard.

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread ville.voutilainen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #12 from Ville Voutilainen --- It sure seems to me that a coroutine lambda's captures should be copied to the coroutine state. I don't think the standard says that anywhere.

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-14 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #11 from Avi Kivity --- I started a conversation on the std-proposals list about this. Meanwhile, how about a -fnonstandard-coroutines-that-actually-work flag that captures the parameter to a non-static member function coroutine by

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #10 from Avi Kivity --- Well, the standard is useless here. In [foo] () -> lazy { co_return foo; } () a temporary is clearly passed to the lambda body, yet the standard mandates that we capture it by reference. As a result, a

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread iains at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 Iain Sandoe changed: What|Removed |Added Assignee|unassigned at gcc dot gnu.org |iains at gcc dot gnu.org ---

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #7 from Avi Kivity --- I have a simple reproducer. A lambda fails while a fake lambda using structs passes. I don't think gcc is at fault, but the standard is problematic here IMO.

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #8 from Avi Kivity --- Created attachment 48526 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48526=edit less lame testcase

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread iains at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #6 from Iain Sandoe --- (In reply to Avi Kivity from comment #5) > This snippet from cppreference: > > If the coroutine is a non-static member function, such as task > my_class::method1(int x) const;, its Promise type is >

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #5 from Avi Kivity --- This snippet from cppreference: If the coroutine is a non-static member function, such as task my_class::method1(int x) const;, its Promise type is std::coroutine_traits, const my_class&,

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread iains at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #4 from Iain Sandoe --- (In reply to Avi Kivity from comment #3) > The test case I uploaded only shows the failure, it won't work if gcc worked > as I expect it. I'll try to get a better testcase, unfortunately a small > coroutine

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #3 from Avi Kivity --- The test case I uploaded only shows the failure, it won't work if gcc worked as I expect it. I'll try to get a better testcase, unfortunately a small coroutine testcase is still some work.

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread a...@cloudius-systems.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #2 from Avi Kivity --- Created attachment 48524 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48524=edit lame testcase Lame testcase that shows that the lambda is passed as a pointer rather than by value, leading to a leak if

[Bug c++/95111] coroutines use-after-free with lambdas

2020-05-13 Thread iains at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95111 --- Comment #1 from Iain Sandoe --- There are some gotchas with coroutines and references (both regular and rvalue). * there could still be a bug here, so I want to double-check. Please could you expand your snippets of code into a small