1 // RUN: %clang_cc1 -std=c++11 -fblocks -fms-extensions %s -triple=x86_64-windows-msvc -emit-llvm \ 2 // RUN: -o - -mconstructor-aliases -fcxx-exceptions -fexceptions | \ 3 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CXXEH 4 // RUN: %clang_cc1 -std=c++11 -fblocks -fms-extensions %s -triple=x86_64-windows-msvc -emit-llvm \ 5 // RUN: -o - -mconstructor-aliases -O1 -disable-llvm-optzns | \ 6 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=NOCXX 7 8 extern "C" unsigned long _exception_code(); 9 extern "C" void might_throw(); 10 11 struct HasCleanup { 12 HasCleanup(); 13 ~HasCleanup(); 14 int padding; 15 }; 16 17 extern "C" void use_cxx() { 18 HasCleanup x; 19 might_throw(); 20 } 21 22 // Make sure we use __CxxFrameHandler3 for C++ EH. 23 24 // CXXEH-LABEL: define void @use_cxx() 25 // CXXEH-SAME: personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) 26 // CXXEH: call %struct.HasCleanup* @"\01??0HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) 27 // CXXEH: invoke void @might_throw() 28 // CXXEH: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] 29 // 30 // CXXEH: [[cont]] 31 // CXXEH: call void @"\01??1HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) 32 // CXXEH: ret void 33 // 34 // CXXEH: [[lpad]] 35 // CXXEH: cleanuppad 36 // CXXEH: call void @"\01??1HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) 37 // CXXEH: cleanupret 38 39 // NOCXX-LABEL: define void @use_cxx() 40 // NOCXX-NOT: invoke 41 // NOCXX: call %struct.HasCleanup* @"\01??0HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) 42 // NOCXX-NOT: invoke 43 // NOCXX: call void @might_throw() 44 // NOCXX-NOT: invoke 45 // NOCXX: call void @"\01??1HasCleanup@@QEAA@XZ"(%struct.HasCleanup* %{{.*}}) 46 // NOCXX-NOT: invoke 47 // NOCXX: ret void 48 49 extern "C" void use_seh() { 50 __try { 51 might_throw(); 52 } __except(1) { 53 } 54 } 55 56 // Make sure we use __C_specific_handler for SEH. 57 58 // CHECK-LABEL: define void @use_seh() 59 // CHECK-SAME: personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) 60 // CHECK: invoke void @might_throw() #[[NOINLINE:[0-9]+]] 61 // CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] 62 // 63 // CHECK: [[lpad]] 64 // CHECK-NEXT: catchpad 65 // CHECK: catchret {{.*}} label %[[except:[^ ]*]] 66 // 67 // CHECK: [[except]] 68 // CHECK: br label %[[ret:[^ ]*]] 69 // 70 // CHECK: [[ret]] 71 // CHECK: ret void 72 // 73 // CHECK: [[cont]] 74 // CHECK: br label %[[ret]] 75 76 void use_seh_in_lambda() { 77 ([]() { 78 __try { 79 might_throw(); 80 } __except(1) { 81 } 82 })(); 83 HasCleanup x; 84 might_throw(); 85 } 86 87 // CXXEH-LABEL: define void @"\01?use_seh_in_lambda@@YAXXZ"() 88 // CXXEH-SAME: personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) 89 // CXXEH: cleanuppad 90 91 // NOCXX-LABEL: define void @"\01?use_seh_in_lambda@@YAXXZ"() 92 // NOCXX-NOT: invoke 93 // NOCXX: ret void 94 95 // CHECK-LABEL: define internal void @"\01??R<lambda_0>@?use_seh_in_lambda@@YAXXZ@QEBAXXZ"(%class.anon* %this) 96 // CXXEH-SAME: personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) 97 // CHECK: invoke void @might_throw() #[[NOINLINE]] 98 // CHECK: catchpad 99 100 static int my_unique_global; 101 102 extern "C" inline void use_seh_in_inline_func() { 103 __try { 104 might_throw(); 105 } __except(_exception_code() == 424242) { 106 } 107 __try { 108 might_throw(); 109 } __finally { 110 my_unique_global = 1234; 111 } 112 } 113 114 void use_inline() { 115 use_seh_in_inline_func(); 116 } 117 118 // CHECK-LABEL: define linkonce_odr void @use_seh_in_inline_func() #{{[0-9]+}} comdat 119 // CHECK-SAME: personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) 120 // CHECK: invoke void @might_throw() 121 // 122 // CHECK: catchpad [i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@use_seh_in_inline_func@@" to i8*)] 123 // 124 // CHECK: invoke void @might_throw() 125 // 126 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.localaddress() 127 // CHECK: call void @"\01?fin$0@0@use_seh_in_inline_func@@"(i8 0, i8* %[[fp]]) 128 // CHECK: ret void 129 // 130 // CHECK: cleanuppad 131 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.localaddress() 132 // CHECK: invoke void @"\01?fin$0@0@use_seh_in_inline_func@@"(i8 1, i8* %[[fp]]) 133 134 // CHECK-LABEL: define internal i32 @"\01?filt$0@0@use_seh_in_inline_func@@"(i8* %exception_pointers, i8* %frame_pointer) #{{[0-9]+}} comdat($use_seh_in_inline_func) 135 // CHECK: icmp eq i32 %{{.*}}, 424242 136 // CHECK: zext i1 %{{.*}} to i32 137 // CHECK: ret i32 138 139 // CHECK-LABEL: define internal void @"\01?fin$0@0@use_seh_in_inline_func@@"(i8 %abnormal_termination, i8* %frame_pointer) #{{[0-9]+}} comdat($use_seh_in_inline_func) 140 // CHECK: store i32 1234, i32* @my_unique_global 141 142 // CHECK: attributes #[[NOINLINE]] = { {{.*noinline.*}} } 143