[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGenCoroutines / coro-only-destroy-when-complete.cpp
blob9d4ae85e0585f6058d0e0647d1388dd39f343c02
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
2 // RUN: -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
4 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
5 // RUN: -O3 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O
7 #include "Inputs/coroutine.h"
9 using namespace std;
11 struct A;
12 struct A_promise_type {
13 A get_return_object();
14 suspend_always initial_suspend();
15 suspend_always final_suspend() noexcept;
16 void return_value(int);
17 void unhandled_exception();
19 std::coroutine_handle<> handle;
22 struct Awaitable{
23 bool await_ready();
24 int await_resume();
25 template <typename F>
26 void await_suspend(F);
28 Awaitable something();
30 struct dtor {
31 dtor();
32 ~dtor();
35 struct [[clang::coro_only_destroy_when_complete]] A {
36 using promise_type = A_promise_type;
37 A();
38 A(std::coroutine_handle<>);
39 ~A();
41 std::coroutine_handle<promise_type> handle;
44 A foo() {
45 dtor d;
46 co_await something();
47 dtor d1;
48 co_await something();
49 dtor d2;
50 co_return 43;
53 // CHECK: define{{.*}}@_Z3foov({{.*}}) #[[ATTR_NUM:[0-9]+]]
54 // CHECK: attributes #[[ATTR_NUM]] = {{.*}}coro_only_destroy_when_complete
56 // CHECK-O: define{{.*}}@_Z3foov.destroy
57 // CHECK-O: {{^.*}}:
58 // CHECK-O-NOT: br
59 // CHECK-O: ret void