Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCoroutines / coro-symmetric-transfer-01.cpp
blobc0b9e9ee2c55818fcc8189e2611ba91ff4a706d5
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -O0 -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s
2 // RUN: %clang -std=c++20 -O0 -emit-llvm -c %s -o %t -Xclang -disable-llvm-passes && %clang -c %t
4 #include "Inputs/coroutine.h"
6 struct detached_task {
7 struct promise_type {
8 detached_task get_return_object() noexcept {
9 return detached_task{std::coroutine_handle<promise_type>::from_promise(*this)};
12 void return_void() noexcept {}
14 struct final_awaiter {
15 bool await_ready() noexcept { return false; }
16 std::coroutine_handle<> await_suspend(std::coroutine_handle<promise_type> h) noexcept {
17 h.destroy();
18 return {};
20 void await_resume() noexcept {}
23 void unhandled_exception() noexcept {}
25 final_awaiter final_suspend() noexcept { return {}; }
27 std::suspend_always initial_suspend() noexcept { return {}; }
30 ~detached_task() {
31 if (coro_) {
32 coro_.destroy();
33 coro_ = {};
37 void start() && {
38 auto tmp = coro_;
39 coro_ = {};
40 tmp.resume();
43 std::coroutine_handle<promise_type> coro_;
46 detached_task foo() {
47 co_return;
50 // check that the lifetime of the coroutine handle used to obtain the address is contained within single basic block, and hence does not live across suspension points.
51 // CHECK-LABEL: final.suspend:
52 // CHECK: %{{.+}} = call token @llvm.coro.save(ptr null)
53 // CHECK: call void @llvm.lifetime.start.p0(i64 8, ptr %[[HDL:.+]])
54 // CHECK: %[[CALL:.+]] = call ptr @_ZN13detached_task12promise_type13final_awaiter13await_suspendESt16coroutine_handleIS0_E(
55 // CHECK: %[[HDL_CAST2:.+]] = getelementptr inbounds %"struct.std::coroutine_handle.0", ptr %[[HDL]], i32 0, i32 0
56 // CHECK: store ptr %[[CALL]], ptr %[[HDL_CAST2]], align 8
57 // CHECK: %[[HDL_TRANSFER:.+]] = call noundef ptr @_ZNKSt16coroutine_handleIvE7addressEv(ptr noundef {{.*}}%[[HDL]])
58 // CHECK: call void @llvm.lifetime.end.p0(i64 8, ptr %[[HDL]])
59 // CHECK: call void @llvm.coro.resume(ptr %[[HDL_TRANSFER]])