Issue 61508
Summary Destroying a coroutine suspended in a list-initializer forgets some destructors
Labels new issue
Assignees
Reporter Alcaro
    ```c++
#include <coroutine>
#include <memory>

struct simple {
  std::coroutine_handle<void> handle;
 struct promise_type {
    simple get_return_object() { return {std::coroutine_handle<promise_type>::from_promise(*this)}; }
    void return_void() {}
    void unhandled_exception() {}
    auto initial_suspend() noexcept { return std::suspend_never{}; }
    auto final_suspend() noexcept { return std::suspend_never{}; }
 };
};
simple struct_compound_expr() {
    std::unique_ptr<int> k[] = {
        std::make_unique<int>(5),
        (co_await std::suspend_always{}, nullptr )
    };
}
int main() {
  auto routine = struct_compound_expr();
  routine.handle.destroy();
  return 0;
}
```
Compile and run with -std=c++20 -fsanitize=address. https://godbolt.org/z/1YTW8nbKr

Expected result: Destruct the unique_ptr; print nothing and return 0.

Actual:
```
==1==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x55677ed6b37d in operator new(unsigned long) /root/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
 #1 0x55677ed71294 in std::__detail::_MakeUniq<int>::__single_object std::make_unique<int, int>(int&&) /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../include/c++/13.0.1/bits/unique_ptr.h:1071:30
 #2 0x55677ed6df05 in struct_compound_expr() /app/example.cpp:16:9
 #3 0x55677ed6e858 in main /app/example.cpp:21:18
    #4 0x7f999389e082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)

SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s).
```

Testcase reduced/modified from <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98401#c7>. The issue reproduces with both array list-initialization (as above) and aggregate-initialization of a struct.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to