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() noexcept { 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 %[[COROFIN:.+]] 52 // CHECK: [[COROFIN]]: 53 // CHECK-NEXT: call void @"?final_suspend@promise_type@coro_t@@QEAA?AUsuspend_never@coroutines_v1@experimental@std@@XZ"( 54 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:.+]] 61 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: call void @_ZN6coro_t12promise_type13final_suspendEv( 73