Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCoroutines / pr65018.cpp
blob2fdfe684b592fbf359a5d2bc7928ebe8b1dda5e0
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
2 // RUN: -O1 -emit-llvm %s -o - | FileCheck %s
4 #include "Inputs/coroutine.h"
6 // A simple awaiter type with an await_suspend method that can't be
7 // inlined.
8 struct Awaiter {
9 const int& x;
11 bool await_ready() { return false; }
12 std::coroutine_handle<> await_suspend(const std::coroutine_handle<> h);
13 void await_resume() {}
16 struct MyTask {
17 // A lazy promise with an await_transform method that supports awaiting
18 // integer references using the Awaiter struct above.
19 struct promise_type {
20 MyTask get_return_object() {
21 return MyTask{
22 std::coroutine_handle<promise_type>::from_promise(*this),
26 std::suspend_always initial_suspend() { return {}; }
27 std::suspend_always final_suspend() noexcept { return {}; }
28 void unhandled_exception();
30 auto await_transform(const int& x) { return Awaiter{x}; }
33 std::coroutine_handle<> h;
36 // A global array of integers.
37 int g_array[32];
39 // A coroutine that awaits each integer in the global array.
40 MyTask FooBar() {
41 for (const int& x : g_array) {
42 co_await x;
46 // CHECK: %[[RET:.+]] = {{.*}}call{{.*}}@_ZN7Awaiter13await_suspendESt16coroutine_handleIvE
47 // CHECK: %[[RESUME_ADDR:.+]] = load ptr, ptr %[[RET]],
48 // CHECK: musttail call fastcc void %[[RESUME_ADDR]]({{.*}}%[[RET]]
49 // CHECK: ret