1 // RUN: %clang_cc1 -no-opaque-pointers -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 -no-opaque-pointers -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: bitcast %"struct.std::suspend_never"* %{{.+}} to i8*
52 // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(
53 // CHECK-NEXT: call void @"?final_suspend@promise_type@coro_t@@QEAA?AUsuspend_never@std@@XZ"(
55 // CHECK-LPAD: @_Z1fv(
56 // CHECK-LPAD: invoke void @_Z9may_throwv()
57 // CHECK-LPAD: to label %[[CONT:.+]] unwind label %[[CLEANUP:.+]]
58 // CHECK-LPAD: [[CLEANUP]]:
59 // CHECK-LPAD: call void @_ZN7CleanupD1Ev(%struct.Cleanup* {{[^,]*}} %x) #2
60 // CHECK-LPAD: br label %[[CATCH:.+]]
62 // CHECK-LPAD: [[CATCH]]:
63 // CHECK-LPAD: call i8* @__cxa_begin_catch
64 // CHECK-LPAD: call void @_ZN6coro_t12promise_type19unhandled_exceptionEv(%"struct.coro_t::promise_type"* {{[^,]*}} %__promise) #2
65 // CHECK-LPAD: invoke void @__cxa_end_catch()
66 // CHECK-LPAD-NEXT: to label %[[CATCHRETDEST:.+]] unwind label
67 // CHECK-LPAD: [[CATCHRETDEST]]:
68 // CHECK-LPAD-NEXT: br label %[[TRYCONT:.+]]
69 // CHECK-LPAD: [[TRYCONT]]:
70 // CHECK-LPAD: br label %[[COROFIN:.+]]
71 // CHECK-LPAD: [[COROFIN]]:
72 // CHECK-LPAD-NEXT: bitcast %"struct.std::suspend_never"* %{{.+}} to i8*
73 // CHECK-LPAD-NEXT: call void @llvm.lifetime.start.p0i8(
74 // CHECK-LPAD-NEXT: call void @_ZN6coro_t12promise_type13final_suspendEv(