Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCoroutines / coro-aligned-alloc.cpp
blobd14c3d372ddb1730c3c403f0e27227e97be10815
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
2 // RUN: -fcoro-aligned-allocation -S -emit-llvm %s -o - -disable-llvm-passes \
3 // RUN: | FileCheck %s
5 #include "Inputs/coroutine.h"
7 namespace std {
8 typedef __SIZE_TYPE__ size_t;
9 enum class align_val_t : size_t {};
12 struct task {
13 struct promise_type {
14 auto initial_suspend() { return std::suspend_always{}; }
15 auto final_suspend() noexcept { return std::suspend_always{}; }
16 auto get_return_object() { return task{}; }
17 void unhandled_exception() {}
18 void return_value(int) {}
22 // CHECK: define{{.*}}@_Z1fv(
23 // CHECK: coro.alloc:
24 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
25 // CHECK: %[[coro_align:.+]] = call{{.*}}@llvm.coro.align
26 // CHECK: %[[aligned_new:.+]] = call{{.*}}@_ZnwmSt11align_val_t({{.*}}%[[coro_size]],{{.*}}%[[coro_align]])
28 // CHECK: coro.free:
29 // CHECK: %[[coro_align_for_free:.+]] = call{{.*}}@llvm.coro.align
30 // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}[[coro_align_for_free]]
32 task f() {
33 co_return 43;
36 struct task2 {
37 struct promise_type {
38 auto initial_suspend() { return std::suspend_always{}; }
39 auto final_suspend() noexcept { return std::suspend_always{}; }
40 auto get_return_object() { return task2{}; }
41 void unhandled_exception() {}
42 void return_value(int) {}
43 static task2 get_return_object_on_allocation_failure() { return task2{}; }
47 namespace std {
48 struct nothrow_t {};
49 constexpr nothrow_t nothrow = {};
52 void *operator new(std::size_t, std::align_val_t, std::nothrow_t) noexcept;
54 // CHECK: define{{.*}}@_Z2f2v(
55 // CHECK: coro.alloc:
56 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
57 // CHECK: %[[coro_align:.+]] = call{{.*}}@llvm.coro.align
58 // CHECK: %[[aligned_new:.+]] = call{{.*}}@_ZnwmSt11align_val_tSt9nothrow_t({{.*}}%[[coro_size]],{{.*}}%[[coro_align]])
60 // CHECK: coro.free:
61 // CHECK: %[[coro_align_for_free:.+]] = call{{.*}}@llvm.coro.align
62 // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}[[coro_align_for_free]]
64 task2 f2() {
65 co_return 43;
68 struct task3 {
69 struct promise_type {
70 auto initial_suspend() { return std::suspend_always{}; }
71 auto final_suspend() noexcept { return std::suspend_always{}; }
72 auto get_return_object() { return task3{}; }
73 void unhandled_exception() {}
74 void return_value(int) {}
75 void operator delete(void *ptr);
79 // CHECK: define{{.*}}@_Z2f3v
80 // CHECK: coro.free:
81 // CHECK: call{{.*}}void @_ZN5task312promise_typedlEPv(
83 task3 f3() {
84 co_return 43;
87 struct task4 {
88 struct promise_type {
89 auto initial_suspend() { return std::suspend_always{}; }
90 auto final_suspend() noexcept { return std::suspend_always{}; }
91 auto get_return_object() { return task4{}; }
92 void unhandled_exception() {}
93 void return_value(int) {}
94 void operator delete(void *ptr, std::align_val_t);
95 void operator delete(void *ptr);
99 // CHECK: define{{.*}}@_Z2f4v
100 // CHECK: coro.free:
101 // CHECK: %[[coro_align_for_free:.+]] = call{{.*}}@llvm.coro.align
102 // CHECK: call{{.*}}void @_ZN5task412promise_typedlEPvSt11align_val_t({{.*}}, i64{{.*}}[[coro_align_for_free]]
104 task4 f4() {
105 co_return 43;
108 struct task5 {
109 struct promise_type {
110 auto initial_suspend() { return std::suspend_always{}; }
111 auto final_suspend() noexcept { return std::suspend_always{}; }
112 auto get_return_object() { return task5{}; }
113 void unhandled_exception() {}
114 void return_value(int) {}
115 void *operator new(std::size_t);
119 // CHECK: define{{.*}}@_Z2f5v
120 // CHECK: coro.alloc:
121 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
122 // CHECK: call{{.*}}ptr @_ZN5task512promise_typenwEm(i64{{.*}}%[[coro_size]])
123 task5 f5() {
124 co_return 43;
127 struct task6 {
128 struct promise_type {
129 auto initial_suspend() { return std::suspend_always{}; }
130 auto final_suspend() noexcept { return std::suspend_always{}; }
131 auto get_return_object() { return task6{}; }
132 void unhandled_exception() {}
133 void return_value(int) {}
134 void *operator new(std::size_t);
135 void *operator new(std::size_t, int i);
139 // CHECK: define{{.*}}@_Z2f6i
140 // CHECK: coro.alloc:
141 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
142 // CHECK: call{{.*}}ptr @_ZN5task612promise_typenwEmi(i64{{.*}}%[[coro_size]],
143 task6 f6(int i) {
144 co_return i;
147 struct task7 {
148 struct promise_type {
149 auto initial_suspend() { return std::suspend_always{}; }
150 auto final_suspend() noexcept { return std::suspend_always{}; }
151 auto get_return_object() { return task7{}; }
152 void unhandled_exception() {}
153 void return_value(int) {}
154 void *operator new(std::size_t);
155 void *operator new(std::size_t, int i);
156 void *operator new(std::size_t, std::align_val_t);
160 // CHECK: define{{.*}}@_Z2f7i
161 // CHECK: coro.alloc:
162 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
163 // CHECK: %[[coro_align:.+]] = call{{.*}}@llvm.coro.align
164 // CHECK: call{{.*}}ptr @_ZN5task712promise_typenwEmSt11align_val_t(i64{{.*}}%[[coro_size]], i64{{.*}}[[coro_align]])
165 task7 f7(int i) {
166 co_return i;
169 struct task8 {
170 struct promise_type {
171 auto initial_suspend() { return std::suspend_always{}; }
172 auto final_suspend() noexcept { return std::suspend_always{}; }
173 auto get_return_object() { return task8{}; }
174 void unhandled_exception() {}
175 void return_value(int) {}
176 void *operator new(std::size_t);
177 void *operator new(std::size_t, int i);
178 void *operator new(std::size_t, std::align_val_t);
179 void *operator new(std::size_t, std::align_val_t, int i);
183 // CHECK: define{{.*}}@_Z2f8i
184 // CHECK: coro.alloc:
185 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
186 // CHECK: %[[coro_align:.+]] = call{{.*}}@llvm.coro.align
187 // CHECK: call{{.*}}ptr @_ZN5task812promise_typenwEmSt11align_val_ti(i64{{.*}}%[[coro_size]], i64{{.*}}[[coro_align]],
188 task8 f8(int i) {
189 co_return i;