Skip to content

the coroutine transformation does not handle object lifetimes correctly #741

Description

@ARG-Helper

https://compiler-explorer.com/z/eM8snj1o3 transforms into https://compiler-explorer.com/z/G5K9fbqjd
the first outputs

loud_awaiter<0x598253c312c8>()=0x598253c312c8
~loud_awaiter<0x598253c312c8>()=0x598253c312c8
loud_awaiter<0x598253c312d0>()=0x598253c312d0
~loud_awaiter<0x598253c312d0>()=0x598253c312d0

the second outputs

loud_awaiter<0x7ffe0cc33dd8>()=0x7ffe0cc33dd8
loud_awaiter<0x5a29082b42d0>&operator=(loud_awaiter<0x7ffe0cc33dd8>&&)=0x7ffe0cc33dd8
~loud_awaiter<0x7ffe0cc33dd8>()=0
loud_awaiter<0x7ffe0cc33d78>()=0x7ffe0cc33d78
loud_awaiter<0x5a29082b42d8>&operator=(loud_awaiter<0x7ffe0cc33d78>&&)=0x7ffe0cc33d78
~loud_awaiter<0x7ffe0cc33d78>()=0
~loud_awaiter<0x5a29082b42d8>()=0x7ffe0cc33d78
~loud_awaiter<0x5a29082b42d0>()=0x7ffe0cc33dd8
__f->__suspend_62_12 = loud_awaiter{create_tag_t(create_tag)};
    if(!__f->__suspend_62_12.await_ready()) {
      __f->__suspend_index = 2;
      __f->__suspend_62_12.await_suspend(std::coroutine_handle<Task::promise_type>::from_address(static_cast<void *>(__f)).operator std::coroutine_handle<void>());
      return;
    } 
    
    __resume_foo_2:
    __f->__suspend_62_12.await_resume();

should be (ignoring exception-handling)

new(&(__f->__suspend_62_12))loud_awaiter{create_tag_t(create_tag)};
    if(!__f->__suspend_62_12.await_ready()) {
      __f->__suspend_index = 2;
      __f->__suspend_62_12.await_suspend(std::coroutine_handle<Task::promise_type>::from_address(static_cast<void *>(__f)).operator std::coroutine_handle<void>());
      return;
    } 
    
    __resume_foo_2:
    __f->__suspend_62_12.await_resume();
    __f->__suspend_62_12.~loud_awaiter();
    

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions