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"
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
{
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 {}; }
43 std::coroutine_handle
<promise_type
> coro_
;
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]])