1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
2 // RUN: -fexperimental-new-pass-manager -O0 %s -o - | FileCheck %s
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
4 // RUN: -fexperimental-new-pass-manager -fno-inline -O0 %s -o - | FileCheck %s
5
6 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
7 // RUN: -O0 %s -o - | FileCheck %s
8 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
9 // RUN: -fno-inline -O0 %s -o - | FileCheck %s
10
11 namespace std {
12 namespace experimental {
13
14 struct handle {};
15
16 struct awaitable {
await_readystd::experimental::awaitable17 bool await_ready() noexcept { return true; }
18 // CHECK-NOT: await_suspend
await_suspendstd::experimental::awaitable19 inline void __attribute__((__always_inline__)) await_suspend(handle) noexcept {}
await_resumestd::experimental::awaitable20 bool await_resume() noexcept { return true; }
21 };
22
23 template <typename T>
24 struct coroutine_handle {
from_addressstd::experimental::coroutine_handle25 static handle from_address(void *address) noexcept { return {}; }
26 };
27
28 template <typename T = void>
29 struct coroutine_traits {
30 struct promise_type {
initial_suspendstd::experimental::coroutine_traits::promise_type31 awaitable initial_suspend() { return {}; }
final_suspendstd::experimental::coroutine_traits::promise_type32 awaitable final_suspend() noexcept { return {}; }
return_voidstd::experimental::coroutine_traits::promise_type33 void return_void() {}
get_return_objectstd::experimental::coroutine_traits::promise_type34 T get_return_object() { return T(); }
unhandled_exceptionstd::experimental::coroutine_traits::promise_type35 void unhandled_exception() {}
36 };
37 };
38 } // namespace experimental
39 } // namespace std
40
41 // CHECK-LABEL: @_Z3foov
42 // CHECK-LABEL: entry:
43 // CHECK-NEXT: %this.addr.i{{[0-9]*}} = alloca %"struct.std::experimental::awaitable"*, align 8
44 // CHECK-NEXT: %this.addr.i{{[0-9]*}} = alloca %"struct.std::experimental::awaitable"*, align 8
45 // CHECK: [[CAST0:%[0-9]+]] = bitcast %"struct.std::experimental::awaitable"** %this.addr.i{{[0-9]*}} to i8*
46 // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[CAST0]])
47 // CHECK: [[CAST1:%[0-9]+]] = bitcast %"struct.std::experimental::awaitable"** %this.addr.i{{[0-9]*}} to i8*
48 // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[CAST1]])
49
50 // CHECK: [[CAST2:%[0-9]+]] = bitcast %"struct.std::experimental::awaitable"** %this.addr.i{{[0-9]*}} to i8*
51 // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[CAST2]])
52 // CHECK: [[CAST3:%[0-9]+]] = bitcast %"struct.std::experimental::awaitable"** %this.addr.i{{[0-9]*}} to i8*
53 // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* [[CAST3]])
foo()54 void foo() { co_return; }
55