1 // RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s
5 //////////////////////////////////////////////////////////////////////////////
6 // __leave with __except
8 // Nothing in the __try block can trap, so __try.cont isn't created.
9 int __leave_with___except_simple(void) {
20 // CHECK-LABEL: define dso_local i32 @__leave_with___except_simple()
21 // CHECK: store i32 15, ptr %myres
22 // CHECK-NEXT: br label %[[tryleave:[^ ]*]]
23 // CHECK-NOT: store i32 23
24 // CHECK: [[tryleave]]
25 // CHECK-NEXT: ret i32 1
29 int __leave_with___except(void) {
40 // CHECK-LABEL: define dso_local i32 @__leave_with___except()
41 // CHECK: invoke void @g()
42 // CHECK-NEXT: to label %[[cont:.*]] unwind label %{{.*}}
43 // For __excepts, instead of an explicit __try.__leave label, we could use
44 // use invoke.cont as __leave jump target instead. However, not doing this
45 // keeps the CodeGen code simpler, __leave is very rare, and SimplifyCFG will
46 // simplify this anyways.
48 // CHECK-NEXT: br label %[[tryleave:[^ ]*]]
49 // CHECK-NOT: store i32 23
50 // CHECK: [[tryleave]]
51 // CHECK-NEXT: br label %
54 //////////////////////////////////////////////////////////////////////////////
55 // __leave with __finally
57 void abort(void) __attribute__((noreturn
));
59 // Nothing in the __try block can trap, so __finally.cont and friends aren't
61 int __leave_with___finally_simple(void) {
72 // CHECK-LABEL: define dso_local i32 @__leave_with___finally_simple()
73 // CHECK: store i32 15, ptr %myres
74 // CHECK-NEXT: br label %[[tryleave:[^ ]*]]
75 // CHECK-NOT: store i32 23
76 // CHECK: [[tryleave]]
77 // CHECK-NEXT: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
78 // CHECK-NEXT: call void @"?fin$0@0@__leave_with___finally_simple@@"(i8 noundef 0, ptr noundef %[[fp]])
80 // __finally block doesn't return, __finally.cont doesn't exist.
81 int __leave_with___finally_noreturn(void) {
92 // CHECK-LABEL: define dso_local i32 @__leave_with___finally_noreturn()
93 // CHECK: store i32 15, ptr %myres
94 // CHECK-NEXT: br label %[[tryleave:[^ ]*]]
95 // CHECK-NOT: store i32 23
96 // CHECK: [[tryleave]]
97 // CHECK-NEXT: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
98 // CHECK-NEXT: call void @"?fin$0@0@__leave_with___finally_noreturn@@"(i8 noundef 0, ptr noundef %[[fp]])
100 // The "normal" case.
101 int __leave_with___finally(void) {
112 // CHECK-LABEL: define dso_local i32 @__leave_with___finally()
113 // CHECK: invoke void @g()
114 // CHECK-NEXT: to label %[[cont:.*]] unwind label %{{.*}}
115 // For __finally, there needs to be an explicit __try.__leave, because
116 // abnormal.termination.slot needs to be set there.
118 // CHECK-NEXT: br label %[[tryleave:[^ ]*]]
119 // CHECK-NOT: store i32 23
120 // CHECK: [[tryleave]]
121 // CHECK-NEXT: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
122 // CHECK-NEXT: call void @"?fin$0@0@__leave_with___finally@@"(i8 noundef 0, ptr noundef %[[fp]])
125 //////////////////////////////////////////////////////////////////////////////
126 // Mixed, nested cases.
128 int nested___except___finally(void) {
135 __leave
; // Refers to the outer __try, not the __finally!
145 // CHECK-LABEL: define dso_local i32 @nested___except___finally()
147 // CHECK-LABEL: invoke void @g()
148 // CHECK-NEXT: to label %[[g1_cont1:.*]] unwind label %[[g1_lpad:.*]]
150 // CHECK: [[g1_cont1]]
151 // CHECK-NEXT: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
152 // CHECK-NEXT: invoke void @"?fin$0@0@nested___except___finally@@"(i8 noundef 0, ptr noundef %[[fp]])
153 // CHECK-NEXT: to label %[[fin_cont:.*]] unwind label %[[g2_lpad:.*]]
155 // CHECK: [[fin_cont]]
156 // CHECK: store i32 51, ptr %
157 // CHECK-NEXT: br label %[[trycont:[^ ]*]]
159 // CHECK: [[g1_lpad]]
160 // CHECK-NEXT: cleanuppad
161 // CHECK-NEXT: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
162 // CHECK-NEXT: invoke void @"?fin$0@0@nested___except___finally@@"(i8 noundef 1, ptr noundef %[[fp]])
163 // CHECK-NEXT: to label %[[g1_resume:.*]] unwind label %[[g2_lpad]]
164 // CHECK: cleanupret {{.*}} unwind label %[[g2_lpad]]
166 // CHECK: [[g2_lpad]]
167 // CHECK: catchpad {{.*}} [ptr null]
169 // CHECK: br label %[[trycont]]
171 // CHECK: [[trycont]]
172 // CHECK-NEXT: ret i32 1
174 // CHECK-LABEL: define internal void @"?fin$0@0@nested___except___finally@@"(i8 noundef %abnormal_termination, ptr noundef %frame_pointer)
175 // CHECK: call void @g()
176 // CHECK: unreachable
178 int nested___except___except(void) {
186 __leave
; // Refers to the outer __try, not the __except we're in!
196 // The order of basic blocks in the below doesn't matter.
197 // CHECK-LABEL: define dso_local i32 @nested___except___except()
199 // CHECK-LABEL: invoke void @g()
200 // CHECK-NEXT: to label %[[g1_cont:.*]] unwind label %[[g1_lpad:.*]]
202 // CHECK: [[g1_lpad]]
203 // CHECK: catchpad {{.*}} [ptr null]
204 // CHECK: catchret {{.*}} to label %[[except:[^ ]*]]
206 // CHECK: invoke void @g()
207 // CHECK-NEXT: to label %[[g2_cont:.*]] unwind label %[[g2_lpad:.*]]
209 // CHECK: [[g2_lpad]]
210 // CHECK: catchpad {{.*}} [ptr null]
212 // CHECK: br label %[[trycont4:[^ ]*]]
214 // CHECK: [[trycont4]]
215 // CHECK-NEXT: ret i32 1
217 // CHECK: [[g2_cont]]
218 // CHECK-NEXT: br label %[[tryleave:[^ ]*]]
219 // CHECK-NOT: store i32 23
221 // CHECK: [[g1_cont]]
222 // CHECK: store i32 16, ptr %myres
223 // CHECK-NEXT: br label %[[trycont:[^ ]*]]
225 // CHECK: [[trycont]]
226 // CHECK-NEXT: store i32 51, ptr %myres
227 // CHECK-NEXT: br label %[[tryleave]]
229 // CHECK: [[tryleave]]
230 // CHECK-NEXT: br label %[[trycont4]]
232 int nested___finally___except(void) {
239 __leave
; // Refers to the outer __try, not the __except!
249 // The order of basic blocks in the below doesn't matter.
250 // CHECK-LABEL: define dso_local i32 @nested___finally___except()
252 // CHECK-LABEL: invoke void @g()
253 // CHECK-NEXT: to label %[[g1_cont:.*]] unwind label %[[g1_lpad:.*]]
255 // CHECK: [[g1_lpad]]
258 // CHECK: invoke void @g()
259 // CHECK-NEXT: to label %[[g2_cont:.*]] unwind label %[[g2_lpad:.*]]
261 // CHECK: [[g2_cont]]
262 // CHECK: br label %[[tryleave:[^ ]*]]
265 // CHECK: [[g1_cont]]
266 // CHECK-NEXT: br label %[[trycont:[^ ]*]]
268 // CHECK: [[trycont]]
269 // CHECK: store i32 51, ptr %
270 // CHECK-NEXT: br label %[[tryleave]]
272 // CHECK: [[tryleave]]
273 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
274 // CHECK-NEXT: call void @"?fin$0@0@nested___finally___except@@"(i8 noundef 0, ptr noundef %[[fp]])
275 // CHECK-NEXT: ret i32 1
277 // CHECK: [[g2_lpad]]
279 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
280 // CHECK-NEXT: call void @"?fin$0@0@nested___finally___except@@"(i8 noundef 1, ptr noundef %[[fp]])
281 // CHECK: cleanupret {{.*}} unwind to caller
283 // CHECK-LABEL: define internal void @"?fin$0@0@nested___finally___except@@"(i8 noundef %abnormal_termination, ptr noundef %frame_pointer)
286 int nested___finally___finally(void) {
294 __leave
; // Refers to the outer __try, not the __finally we're in!
304 // The order of basic blocks in the below doesn't matter.
305 // CHECK-LABEL: define dso_local i32 @nested___finally___finally()
307 // CHECK: invoke void @g()
308 // CHECK-NEXT: to label %[[g1_cont:.*]] unwind label %[[g1_lpad:.*]]
310 // CHECK: [[g1_cont]]
311 // CHECK: store i32 16, ptr %[[myres:[^ ]*]],
312 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
313 // CHECK-NEXT: invoke void @"?fin$1@0@nested___finally___finally@@"(i8 noundef 0, ptr noundef %[[fp]])
314 // CHECK-NEXT: to label %[[finally_cont:.*]] unwind label %[[g2_lpad:.*]]
316 // CHECK: [[finally_cont]]
317 // CHECK: store i32 51, ptr %[[myres]]
318 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
319 // CHECK-NEXT: call void @"?fin$0@0@nested___finally___finally@@"(i8 noundef 0, ptr noundef %[[fp]])
320 // CHECK-NEXT: ret i32 1
322 // CHECK: [[g1_lpad]]
323 // CHECK-NEXT: %[[padtoken:[^ ]*]] = cleanuppad within none []
324 // CHECK-NEXT: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
325 // CHECK-NEXT: invoke void @"?fin$1@0@nested___finally___finally@@"(i8 noundef 1, ptr noundef %[[fp]])
326 // CHECK-NEXT: to label %[[finally_cont2:.*]] unwind label %[[g2_lpad]]
327 // CHECK: [[finally_cont2]]
328 // CHECK: cleanupret from %[[padtoken]] unwind label %[[g2_lpad]]
330 // CHECK: [[g2_lpad]]
331 // CHECK-NEXT: %[[padtoken:[^ ]*]] = cleanuppad within none []
332 // CHECK-NEXT: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
333 // CHECK-NEXT: call void @"?fin$0@0@nested___finally___finally@@"(i8 noundef 1, ptr noundef %[[fp]])
334 // CHECK: cleanupret from %[[padtoken]] unwind to caller
336 // CHECK-LABEL: define internal void @"?fin$0@0@nested___finally___finally@@"(i8 noundef %abnormal_termination, ptr noundef %frame_pointer)
339 // CHECK-LABEL: define internal void @"?fin$1@0@nested___finally___finally@@"(i8 noundef %abnormal_termination, ptr noundef %frame_pointer)
340 // CHECK: call void @g()
341 // CHECK: unreachable