1 | // RUN: %clang_cc1 -std=c++14 -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++14 -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck --check-prefix=CHECK-LPAD %s |
3 | |
4 | #include "Inputs/coroutine.h" |
5 | |
6 | namespace coro = std::experimental::coroutines_v1; |
7 | |
8 | namespace std { |
9 | using exception_ptr = int; |
10 | exception_ptr current_exception(); |
11 | } |
12 | |
13 | struct coro_t { |
14 | struct promise_type { |
15 | coro_t get_return_object() { |
16 | coro::coroutine_handle<promise_type>{}; |
17 | return {}; |
18 | } |
19 | coro::suspend_never initial_suspend() { return {}; } |
20 | coro::suspend_never final_suspend() { return {}; } |
21 | void return_void(){} |
22 | void unhandled_exception() noexcept; |
23 | }; |
24 | }; |
25 | |
26 | struct Cleanup { ~Cleanup(); }; |
27 | void may_throw(); |
28 | |
29 | coro_t f() { |
30 | Cleanup x; |
31 | may_throw(); |
32 | co_return; |
33 | } |
34 | |
35 | // CHECK: @"?f@@YA?AUcoro_t@@XZ"( |
36 | // CHECK: invoke void @"?may_throw@@YAXXZ"() |
37 | // CHECK: to label %{{.+}} unwind label %[[EHCLEANUP:.+]] |
38 | // CHECK: [[EHCLEANUP]]: |
39 | // CHECK: %[[INNERPAD:.+]] = cleanuppad within none [] |
40 | // CHECK: call void @"??1Cleanup@@QEAA@XZ"( |
41 | // CHECK: cleanupret from %[[INNERPAD]] unwind label %[[CATCHSW:.+]] |
42 | // CHECK: [[CATCHSW]]: |
43 | // CHECK: %[[CATCHSWTOK:.+]] = catchswitch within none [label %[[CATCH:.+]]] unwind label |
44 | // CHECK: [[CATCH]]: |
45 | // CHECK: %[[CATCHTOK:.+]] = catchpad within [[CATCHSWTOK:.+]] |
46 | // CHECK: call void @"?unhandled_exception@promise_type@coro_t@@QEAAXXZ" |
47 | // CHECK: catchret from %[[CATCHTOK]] to label %[[CATCHRETDEST:.+]] |
48 | // CHECK: [[CATCHRETDEST]]: |
49 | // CHECK-NEXT: br label %[[TRYCONT:.+]] |
50 | // CHECK: [[TRYCONT]]: |
51 | // CHECK-NEXT: br label %[[RESUMECONT:.+]] |
52 | // CHECK: [[RESUMECONT]]: |
53 | // CHECK-NEXT: br label %[[COROFIN:.+]] |
54 | // CHECK: [[COROFIN]]: |
55 | // CHECK-NEXT: invoke void @"?final_suspend@promise_type@coro_t@@QEAA?AUsuspend_never@coroutines_v1@experimental@std@@XZ"( |
56 | |
57 | // CHECK-LPAD: @_Z1fv( |
58 | // CHECK-LPAD: invoke void @_Z9may_throwv() |
59 | // CHECK-LPAD: to label %[[CONT:.+]] unwind label %[[CLEANUP:.+]] |
60 | // CHECK-LPAD: [[CLEANUP]]: |
61 | // CHECK-LPAD: call void @_ZN7CleanupD1Ev(%struct.Cleanup* %x) #2 |
62 | // CHECK-LPAD: br label %[[CATCH:.+]] |
63 | |
64 | // CHECK-LPAD: [[CATCH]]: |
65 | // CHECK-LPAD: call i8* @__cxa_begin_catch |
66 | // CHECK-LPAD: call void @_ZN6coro_t12promise_type19unhandled_exceptionEv(%"struct.coro_t::promise_type"* %__promise) #2 |
67 | // CHECK-LPAD: invoke void @__cxa_end_catch() |
68 | // CHECK-LPAD-NEXT: to label %[[CATCHRETDEST:.+]] unwind label |
69 | // CHECK-LPAD: [[CATCHRETDEST]]: |
70 | // CHECK-LPAD-NEXT: br label %[[TRYCONT:.+]] |
71 | // CHECK-LPAD: [[TRYCONT]]: |
72 | // CHECK-LPAD: br label %[[RESUMECONT:.+]] |
73 | // CHECK-LPAD: [[RESUMECONT]]: |
74 | // CHECK-LPAD-NEXT: br label %[[COROFIN:.+]] |
75 | // CHECK-LPAD: [[COROFIN]]: |
76 | // CHECK-LPAD-NEXT: invoke void @_ZN6coro_t12promise_type13final_suspendEv( |
77 | |