[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / CodeGenCoroutines / coro-always-inline.cpp
blobb3685b9b9348497a63bc3825f7ff592e50c4d916
1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -emit-llvm -std=c++20 \
2 // RUN: -O0 %s -o - | FileCheck %s
3 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -emit-llvm -std=c++20 \
4 // RUN: -fno-inline -O0 %s -o - | FileCheck %s
6 namespace std {
8 struct handle {};
10 struct awaitable {
11 bool await_ready() noexcept { return true; }
12 // CHECK-NOT: await_suspend
13 inline void __attribute__((__always_inline__)) await_suspend(handle) noexcept {}
14 bool await_resume() noexcept { return true; }
17 template <typename T>
18 struct coroutine_handle {
19 static handle from_address(void *address) noexcept { return {}; }
22 template <typename T = void>
23 struct coroutine_traits {
24 struct promise_type {
25 awaitable initial_suspend() { return {}; }
26 awaitable final_suspend() noexcept { return {}; }
27 void return_void() {}
28 T get_return_object() { return T(); }
29 void unhandled_exception() {}
32 } // namespace std
34 // CHECK-LABEL: @_Z3foov
35 // CHECK-LABEL: entry:
36 // CHECK: [[CAST0:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
37 // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[CAST0]])
38 // CHECK: [[CAST1:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
39 // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* [[CAST1]])
41 // CHECK: [[CAST2:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
42 // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[CAST2]])
43 // CHECK: [[CAST3:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
44 // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* [[CAST3]])
45 void foo() { co_return; }
47 // Check that bar is not inlined even it's marked as always_inline.
49 // CHECK-LABEL: define {{.*}} void @_Z3bazv()
50 // CHECK: call void @_Z3barv(
51 __attribute__((__always_inline__)) void bar() {
52 co_return;
54 void baz() {
55 bar();
56 co_return;