On Thu, Mar 12, 2026 at 8:23 AM Jakub Jelinek <[email protected]> wrote:
>
> On Sat, Mar 07, 2026 at 11:28:37AM -0800, Andrew Pinski wrote:
> > So in the end the problem with pr103953.C is the lifetime
> > of a lambda object is not extended past the statement.
> > With sane operator new we are able to delete stores using
> > that object as it is dead afterwards.
> >
> > So the fix to the testcase is to make the lambda its own
> > object and then call it.
> >
> > I also went back to check to make sure the original issue was
> > reproducible with this version too.
> >
> > Tested on x86_64-linux-gnu and the testcase failure is gone.
> >
> >       PR testsuite/119930
> >
> > gcc/testsuite/ChangeLog:
> >
> >       * g++.dg/coroutines/torture/pr103953.C: Store the second
> >       lambda into its own object to extend its lifeime.
> >
> > Signed-off-by: Andrew Pinski <[email protected]>
> > ---
> >  gcc/testsuite/g++.dg/coroutines/torture/pr103953.C | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr103953.C 
> > b/gcc/testsuite/g++.dg/coroutines/torture/pr103953.C
> > index da559f8fa0d..1c6052e3f9f 100644
> > --- a/gcc/testsuite/g++.dg/coroutines/torture/pr103953.C
> > +++ b/gcc/testsuite/g++.dg/coroutines/torture/pr103953.C
> > @@ -63,9 +63,11 @@ int main() {
> >           co_return;
> >       }();
> >
> > -     task coroutine_B = [&coroutine_A]() ->task {
> > +        auto t = [&coroutine_A]() ->task {
>
> Why the tab -> 8 spaces change?

Just a mistake of edtting. changed back over to a tab before pushing.

Thanks,
Andrew

>
> Otherwise LGTM.
>
> >           co_await coroutine_A;
> > -     }();
> > +     };
>
> At least when looking at gimple dump, the unpatched testcase does:
> ...
>               coroutine_B = {CLOBBER(bob)};
>               try
>                 {
>                   D.12223.__coroutine_A = &coroutine_A;
>                   coroutine_B = main()::<lambda()>::operator() (&D.12223); 
> [return slot optimization]
>                 }
>               finally
>                 {
>                   D.12223 = {CLOBBER(eos)};
>                 }
>               try
>                 {
>                   std::__n4861::coroutine_handle<task::promise_type>::resume 
> (&coroutine_B.handle);
>                 }
>               finally
>                 {
>                   task::~task (&coroutine_B);
>                 }
> ...
> so by the time resume is called, D.12223 lambda object is already out of
> scope.
>
>
> > +
> > +     task coroutine_B = t();
> >
> >       coroutine_B.handle.resume();
> >      }
>
>         Jakub
>

Reply via email to