1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
2 // RUN: -O0 -disable-llvm-passes -emit-llvm %s -o - \
3 // RUN: | FileCheck %s --check-prefix=FRONTEND
5 // The output of O0 is highly redundant and hard to test. Also it is not good
6 // limit the output of O0. So we test the optimized output from O0. The idea
7 // is the optimizations shouldn't change the semantics of the program.
8 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
9 // RUN: -O0 -emit-llvm %s -o - -disable-O0-optnone \
10 // RUN: | opt -passes='sroa,mem2reg,simplifycfg' -S | FileCheck %s --check-prefix=CHECK-O0
12 #include "Inputs/coroutine.h"
14 // A simple awaiter type with an await_suspend method that can't be
19 bool await_ready() { return false; }
20 std::coroutine_handle
<> await_suspend(const std::coroutine_handle
<> h
);
21 void await_resume() {}
25 // A lazy promise with an await_transform method that supports awaiting
26 // integer references using the Awaiter struct above.
28 MyTask
get_return_object() {
30 std::coroutine_handle
<promise_type
>::from_promise(*this),
34 std::suspend_always
initial_suspend() { return {}; }
35 std::suspend_always
final_suspend() noexcept
{ return {}; }
36 void unhandled_exception();
38 auto await_transform(const int& x
) { return Awaiter
{x
}; }
41 std::coroutine_handle
<> h
;
44 // A global array of integers.
47 // A coroutine that awaits each integer in the global array.
49 for (const int& x
: g_array
) {
54 // FRONTEND: define{{.*}}@_ZNKSt16coroutine_handleIvE7addressEv{{.*}}#[[address_attr:[0-9]+]]
55 // FRONTEND: attributes #[[address_attr]] = {{.*}}alwaysinline
57 // CHECK-O0: define{{.*}}@_Z6FooBarv.resume
58 // CHECK-O0: call{{.*}}@_ZN7Awaiter13await_suspendESt16coroutine_handleIvE
59 // CHECK-O0-NOT: store