1 // RUN: %clang_cc1 -std=c++1z -fcoroutines-ts -triple=x86_64-pc-windows-msvc18.0.0 -emit-llvm %s -o - -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
2 // RUN: %clang_cc1 -std=c++1z -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck --check-prefix=CHECK-LPAD %s
4 namespace std::experimental
{
5 template <typename R
, typename
... T
> struct coroutine_traits
{
6 using promise_type
= typename
R::promise_type
;
9 template <class Promise
= void> struct coroutine_handle
;
11 template <> struct coroutine_handle
<void> {
12 static coroutine_handle
from_address(void *) noexcept
;
13 coroutine_handle() = default;
14 template <class PromiseType
>
15 coroutine_handle(coroutine_handle
<PromiseType
>) noexcept
;
17 template <class Promise
> struct coroutine_handle
: coroutine_handle
<void> {
18 coroutine_handle() = default;
19 static coroutine_handle
from_address(void *) noexcept
;
21 } // namespace std::experimental
23 struct suspend_always
{
24 bool await_ready() noexcept
;
25 void await_suspend(std::experimental::coroutine_handle
<>) noexcept
;
26 void await_resume() noexcept
;
31 coro_t
get_return_object() noexcept
;
32 suspend_always
initial_suspend() noexcept
;
33 suspend_always
final_suspend() noexcept
;
34 void return_void() noexcept
;
35 void unhandled_exception() noexcept
;
50 // CHECK: @"?f@@YA?AUcoro_t@@XZ"(
51 // CHECK: invoke void @"?may_throw@@YAXXZ"()
52 // CHECK: to label %[[CONT:.+]] unwind label %[[EHCLEANUP:.+]]
53 // CHECK: [[EHCLEANUP]]:
54 // CHECK: %[[INNERPAD:.+]] = cleanuppad within none []
55 // CHECK: call void @"??1Cleanup@@QEAA@XZ"(
56 // CHECK: cleanupret from %{{.+}} unwind label %[[CATCHDISPATCH:.+]]
58 // CHECK: [[CATCHDISPATCH]]:
59 // CHECK: catchswitch within none [label %[[CATCHPAD:.+]]] unwind label %[[COROENDBB:.+]]
60 // CHECK: [[CATCHPAD]]:
61 // CHECK: call void @"?unhandled_exception@promise_type@coro_t@@QEAAXXZ"
63 // CHECK: [[COROENDBB]]:
64 // CHECK-NEXT: %[[CLPAD:.+]] = cleanuppad within none
65 // CHECK-NEXT: call i1 @llvm.coro.end(ptr null, i1 true) [ "funclet"(token %[[CLPAD]]) ]
66 // CHECK-NEXT: cleanupret from %[[CLPAD]] unwind label
68 // CHECK-LPAD: @_Z1fv(
69 // CHECK-LPAD: invoke void @_Z9may_throwv()
70 // CHECK-LPAD: to label %[[CONT:.+]] unwind label %[[EHCLEANUP:.+]]
71 // CHECK-LPAD: [[EHCLEANUP]]:
72 // CHECK-LPAD: landingpad { ptr, i32 }
74 // CHECK-LPAD: call void @_ZN7CleanupD1Ev(
75 // CHECK-LPAD: call ptr @__cxa_begin_catch
76 // CHECK-LPAD: call void @_ZN6coro_t12promise_type19unhandled_exceptionEv
77 // CHECK-LPAD: invoke void @__cxa_end_catch()
78 // CHECK-LPAD: to label %{{.+}} unwind label %[[UNWINDBB:.+]]
80 // CHECK-LPAD: [[UNWINDBB]]:
81 // CHECK-LPAD: %[[I1RESUME:.+]] = call i1 @llvm.coro.end(ptr null, i1 true)
82 // CHECK-LPAD: br i1 %[[I1RESUME]], label %[[EHRESUME:.+]], label
83 // CHECK-LPAD: [[EHRESUME]]:
84 // CHECK-LPAD-NEXT: %[[exn:.+]] = load ptr, ptr %exn.slot, align 8
85 // CHECK-LPAD-NEXT: %[[sel:.+]] = load i32, ptr %ehselector.slot, align 4
86 // CHECK-LPAD-NEXT: %[[val1:.+]] = insertvalue { ptr, i32 } poison, ptr %[[exn]], 0
87 // CHECK-LPAD-NEXT: %[[val2:.+]] = insertvalue { ptr, i32 } %[[val1]], i32 %[[sel]], 1
88 // CHECK-LPAD-NEXT: resume { ptr, i32 } %[[val2]]