xref: /llvm-project/clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp (revision 61d418f97154805100dc19ff2ef1338e9de2f27d)
1 // Tests that coroutine passes are added to and run by the new pass manager
2 // pipeline, at -O0 and above.
3 
4 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null \
5 // RUN:   -fdebug-pass-manager -std=c++20 \
6 // RUN:   -O0 %s 2>&1 | FileCheck %s --check-prefixes=CHECK-ALL
7 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null \
8 // RUN:   -fdebug-pass-manager -std=c++20 \
9 // RUN:   -O1 %s 2>&1 | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-OPT
10 //
11 // CHECK-ALL: Running pass:{{.*}}CoroEarlyPass
12 //
13 // CHECK-ALL: Running pass: CoroSplitPass on (_Z3foov)
14 // CHECK-OPT: Running pass:{{.*}}CoroElidePass{{.*}} on {{.*}}_Z3foov{{.*}}
15 //
16 // CHECK-ALL: Running pass:{{.*}}CoroCleanupPass
17 
18 namespace std {
19 
20 struct handle {};
21 
22 struct awaitable {
await_readystd::awaitable23   bool await_ready() noexcept { return false; }
await_suspendstd::awaitable24   void await_suspend(handle) noexcept {}
await_resumestd::awaitable25   bool await_resume() noexcept { return true; }
26 };
27 
28 template <typename T> struct coroutine_handle {
from_addressstd::coroutine_handle29   static handle from_address(void *address) noexcept { return {}; }
30 };
31 
32 template <typename T = void> struct coroutine_traits {
33   struct promise_type {
initial_suspendstd::coroutine_traits::promise_type34     awaitable initial_suspend() { return {}; }
final_suspendstd::coroutine_traits::promise_type35     awaitable final_suspend() noexcept { return {}; }
return_voidstd::coroutine_traits::promise_type36     void return_void() {}
get_return_objectstd::coroutine_traits::promise_type37     T get_return_object() { return T(); }
unhandled_exceptionstd::coroutine_traits::promise_type38     void unhandled_exception() {}
39   };
40 };
41 } // namespace std
42 
foo()43 void foo() { co_return; }
44