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;
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;
39 struct Cleanup { ~Cleanup(); };
48 // CHECK: @"\01?f@@YA?AUcoro_t@@XZ"(
49 // CHECK: invoke void @"\01?may_throw@@YAXXZ"()
50 // CHECK: to label %[[CONT:.+]] unwind label %[[EHCLEANUP:.+]]
51 // CHECK: [[EHCLEANUP]]:
52 // CHECK: %[[INNERPAD:.+]] = cleanuppad within none []
53 // CHECK: call void @"\01??_DCleanup@@QEAAXXZ"(
54 // CHECK: cleanupret from %[[INNERPAD]] unwind label %[[COROENDBB:.+]]
55 // CHECK: [[COROENDBB]]:
56 // CHECK-NEXT: %[[CLPAD:.+]] = cleanuppad within none
57 // CHECK-NEXT: call i1 @llvm.coro.end(i8* null, i1 true) [ "funclet"(token %[[CLPAD]]) ]
58 // CHECK-NEXT: cleanupret from %[[CLPAD]] unwind label
60 // CHECK-LPAD: @_Z1fv(
61 // CHECK-LPAD: invoke void @_Z9may_throwv()
62 // CHECK-LPAD: to label %[[CONT:.+]] unwind label %[[EHCLEANUP:.+]]
63 // CHECK-LPAD: [[EHCLEANUP]]:
64 // CHECK-LPAD: landingpad { i8*, i32 }
65 // CHECK-LPAD: cleanup
66 // CHECK-LPAD: call void @_ZN7CleanupD1Ev(
67 // CHECK-LPAD: %[[I1RESUME:.+]] = call i1 @llvm.coro.end(i8* null, i1 true)
68 // CHECK-LPAD: br i1 %[[I1RESUME]], label %[[EHRESUME:.+]], label
69 // CHECK-LPAD: [[EHRESUME]]:
70 // CHECK-LPAD-NEXT: %[[exn:.+]] = load i8*, i8** %exn.slot, align 8
71 // CHECK-LPAD-NEXT: %[[sel:.+]] = load i32, i32* %ehselector.slot, align 4
72 // CHECK-LPAD-NEXT: %[[val1:.+]] = insertvalue { i8*, i32 } undef, i8* %[[exn]], 0
73 // CHECK-LPAD-NEXT: %[[val2:.+]] = insertvalue { i8*, i32 } %[[val1]], i32 %[[sel]], 1
74 // CHECK-LPAD-NEXT: resume { i8*, i32 } %[[val2]]