1 // RUN: %clang_cc1 -std=c++20 -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++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck --check-prefix=CHECK-LPAD %s
4 #include "Inputs/coroutine.h"
7 using exception_ptr
= int;
8 exception_ptr
current_exception();
13 coro_t
get_return_object() {
14 std::coroutine_handle
<promise_type
>{};
17 std::suspend_never
initial_suspend() { return {}; }
18 std::suspend_never
final_suspend() noexcept
{ return {}; }
20 void unhandled_exception() noexcept
;
24 struct Cleanup
{ ~Cleanup(); };
33 // CHECK: @"?f@@YA?AUcoro_t@@XZ"(
34 // CHECK: invoke void @"?may_throw@@YAXXZ"()
35 // CHECK: to label %{{.+}} unwind label %[[EHCLEANUP:.+]]
36 // CHECK: [[EHCLEANUP]]:
37 // CHECK: %[[INNERPAD:.+]] = cleanuppad within none []
38 // CHECK: call void @"??1Cleanup@@QEAA@XZ"(
39 // CHECK: cleanupret from %[[INNERPAD]] unwind label %[[CATCHSW:.+]]
40 // CHECK: [[CATCHSW]]:
41 // CHECK: %[[CATCHSWTOK:.+]] = catchswitch within none [label %[[CATCH:.+]]] unwind label
43 // CHECK: %[[CATCHTOK:.+]] = catchpad within [[CATCHSWTOK:.+]]
44 // CHECK: call void @"?unhandled_exception@promise_type@coro_t@@QEAAXXZ"
45 // CHECK: catchret from %[[CATCHTOK]] to label %[[CATCHRETDEST:.+]]
46 // CHECK: [[CATCHRETDEST]]:
47 // CHECK-NEXT: br label %[[TRYCONT:.+]]
48 // CHECK: [[TRYCONT]]:
49 // CHECK-NEXT: br label %[[COROFIN:.+]]
50 // CHECK: [[COROFIN]]:
51 // CHECK-NEXT: call void @llvm.lifetime.start.p0(
52 // CHECK-NEXT: call void @"?final_suspend@promise_type@coro_t@@QEAA?AUsuspend_never@std@@XZ"(
54 // CHECK-LPAD: @_Z1fv(
55 // CHECK-LPAD: invoke void @_Z9may_throwv()
56 // CHECK-LPAD: to label %[[CONT:.+]] unwind label %[[CLEANUP:.+]]
57 // CHECK-LPAD: [[CLEANUP]]:
58 // CHECK-LPAD: call void @_ZN7CleanupD1Ev(ptr {{[^,]*}} %x) #2
59 // CHECK-LPAD: br label %[[CATCH:.+]]
61 // CHECK-LPAD: [[CATCH]]:
62 // CHECK-LPAD: call ptr @__cxa_begin_catch
63 // CHECK-LPAD: call void @_ZN6coro_t12promise_type19unhandled_exceptionEv(ptr {{[^,]*}} %__promise) #2
64 // CHECK-LPAD: invoke void @__cxa_end_catch()
65 // CHECK-LPAD-NEXT: to label %[[CATCHRETDEST:.+]] unwind label
66 // CHECK-LPAD: [[CATCHRETDEST]]:
67 // CHECK-LPAD-NEXT: br label %[[TRYCONT:.+]]
68 // CHECK-LPAD: [[TRYCONT]]:
69 // CHECK-LPAD: br label %[[COROFIN:.+]]
70 // CHECK-LPAD: [[COROFIN]]:
71 // CHECK-LPAD-NEXT: call void @llvm.lifetime.start.p0(
72 // CHECK-LPAD-NEXT: call void @_ZN6coro_t12promise_type13final_suspendEv(