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-passes | \
6 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=NOCXX
8 extern "C" unsigned long _exception_code();
9 extern "C" void might_throw();
17 extern "C" void use_cxx() {
22 // Make sure we use __CxxFrameHandler3 for C++ EH.
24 // CXXEH-LABEL: define dso_local void @use_cxx()
25 // CXXEH-SAME: personality ptr @__CxxFrameHandler3
26 // CXXEH: call noundef ptr @"??0HasCleanup@@QEAA@XZ"(ptr {{[^,]*}} %{{.*}})
27 // CXXEH: invoke void @might_throw()
28 // CXXEH: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
31 // CXXEH: call void @"??1HasCleanup@@QEAA@XZ"(ptr {{[^,]*}} %{{.*}})
36 // CXXEH: call void @"??1HasCleanup@@QEAA@XZ"(ptr {{[^,]*}} %{{.*}})
39 // NOCXX-LABEL: define dso_local void @use_cxx()
41 // NOCXX: call noundef ptr @"??0HasCleanup@@QEAA@XZ"(ptr {{[^,]*}} %{{.*}})
43 // NOCXX: call void @might_throw()
45 // NOCXX: call void @"??1HasCleanup@@QEAA@XZ"(ptr {{[^,]*}} %{{.*}})
49 extern "C" void use_seh() {
56 // Make sure we use __C_specific_handler for SEH.
58 // CHECK-LABEL: define dso_local void @use_seh()
59 // CHECK-SAME: personality ptr @__C_specific_handler
60 // CHECK: invoke void @might_throw() #[[NOINLINE:[0-9]+]]
61 // CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
64 // CHECK-NEXT: %[[switch:.*]] = catchswitch within none [label %[[cpad:.*]]] unwind to caller
67 // CHECK-NEXT: catchpad within %[[switch]]
68 // CHECK: catchret {{.*}} label %[[except:[^ ]*]]
71 // CHECK: br label %[[ret:[^ ]*]]
77 // CHECK: br label %[[ret]]
79 extern "C" void nested_finally() {
90 // CHECK-LABEL: define dso_local void @nested_finally() #{{[0-9]+}}
91 // CHECK-SAME: personality ptr @__C_specific_handler
92 // CHECK: invoke void @might_throw()
93 // CHECK: call void @"?fin$0@0@nested_finally@@"(i8 noundef 1, ptr {{.*}})
95 // CHECK-LABEL: define internal void @"?fin$0@0@nested_finally@@"
96 // CHECK-SAME: personality ptr @__C_specific_handler
97 // CHECK: invoke void @might_throw()
98 // CHECK: call void @"?fin$1@0@nested_finally@@"(i8 noundef 1, ptr {{.*}})
100 void use_seh_in_lambda() {
111 // CXXEH-LABEL: define dso_local void @"?use_seh_in_lambda@@YAXXZ"()
112 // CXXEH-SAME: personality ptr @__CxxFrameHandler3
115 // NOCXX-LABEL: define dso_local void @"?use_seh_in_lambda@@YAXXZ"()
119 // CHECK-LABEL: define internal void @"??R<lambda_0>@?0??use_seh_in_lambda@@YAXXZ@QEBA@XZ"(ptr {{[^,]*}} %this)
120 // CXXEH-SAME: personality ptr @__C_specific_handler
121 // CHECK: invoke void @might_throw() #[[NOINLINE]]
124 class use_seh_in_constructor
{ use_seh_in_constructor(); };
125 use_seh_in_constructor::use_seh_in_constructor(){
131 // CHECK: define internal void @"?fin$0@0@?0use_seh_in_constructor@@"
133 static int my_unique_global
;
135 extern "C" inline void use_seh_in_inline_func() {
138 } __except(_exception_code() == 424242) {
143 my_unique_global
= 1234;
148 use_seh_in_inline_func();
151 // CHECK-LABEL: define linkonce_odr dso_local void @use_seh_in_inline_func() #{{[0-9]+}}
152 // CHECK-SAME: personality ptr @__C_specific_handler
153 // CHECK: invoke void @might_throw()
155 // CHECK: catchpad {{.*}} [ptr @"?filt$0@0@use_seh_in_inline_func@@"]
157 // CHECK: invoke void @might_throw()
159 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
160 // CHECK: call void @"?fin$0@0@use_seh_in_inline_func@@"(i8 noundef 0, ptr noundef %[[fp]])
164 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
165 // CHECK: call void @"?fin$0@0@use_seh_in_inline_func@@"(i8 noundef 1, ptr noundef %[[fp]])
167 // CHECK-LABEL: define internal noundef i32 @"?filt$0@0@use_seh_in_inline_func@@"(ptr noundef %exception_pointers, ptr noundef %frame_pointer) #{{[0-9]+}}
168 // CHECK: icmp eq i32 %{{.*}}, 424242
169 // CHECK: zext i1 %{{.*}} to i32
172 // CHECK-LABEL: define internal void @"?fin$0@0@use_seh_in_inline_func@@"(i8 noundef %abnormal_termination, ptr noundef %frame_pointer) #{{[0-9]+}}
173 // CHECK: store i32 1234, ptr @my_unique_global
175 // CHECK: attributes #[[NOINLINE]] = { {{.*noinline.*}} }
177 void seh_in_noexcept() noexcept
{ __try
{} __finally
{} }