| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \ |
| 2 |
// RUN: -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s |
| 3 |
|
| 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 |
| 6 |
|
| 7 |
#include "Inputs/coroutine.h" |
| 8 |
|
| 9 |
using namespace std; |
| 10 |
|
| 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(); |
| 18 |
|
| 19 |
std::coroutine_handle<> handle; |
| 20 |
}; |
| 21 |
|
| 22 |
struct Awaitable{ |
| 23 |
bool await_ready(); |
| 24 |
int await_resume(); |
| 25 |
template <typename F> |
| 26 |
void await_suspend(F); |
| 27 |
}; |
| 28 |
Awaitable something(); |
| 29 |
|
| 30 |
struct dtor { |
| 31 |
dtor(); |
| 32 |
~dtor(); |
| 33 |
}; |
| 34 |
|
| 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(); |
| 40 |
|
| 41 |
std::coroutine_handle<promise_type> handle; |
| 42 |
}; |
| 43 |
|
| 44 |
A foo() { |
| 45 |
dtor d; |
| 46 |
co_await something(); |
| 47 |
dtor d1; |
| 48 |
co_await something(); |
| 49 |
dtor d2; |
| 50 |
co_return 43; |
| 51 |
} |
| 52 |
|
| 53 |
// CHECK: define{{.*}}@_Z3foov({{.*}}) #[[ATTR_NUM:[0-9]+]] |
| 54 |
// CHECK: attributes #[[ATTR_NUM]] = {{.*}}coro_only_destroy_when_complete |
| 55 |
|
| 56 |
// CHECK-O: define{{.*}}@_Z3foov.destroy |
| 57 |
// CHECK-O: {{^.*}}: |
| 58 |
// CHECK-O-NOT: br |
| 59 |
// CHECK-O: ret void |