1 // RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s
3 // RUN: %clang_cc1 %s -triple aarch64-windows -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s
4 // NOTE: we're passing "-O1 -disable-llvm-passes" to avoid adding optnone and noinline everywhere.
6 void abort(void) __attribute__((noreturn
));
7 void might_crash(void);
9 int check_condition(void);
10 void basic_finally(void) {
18 // CHECK-LABEL: define dso_local void @basic_finally()
19 // CHECK: invoke void @might_crash()
20 // CHECK: to label %[[invoke_cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
22 // CHECK: [[invoke_cont]]
23 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
24 // CHECK: call void @"?fin$0@0@basic_finally@@"({{i8 noundef( zeroext)?}} 0, ptr noundef %[[fp]])
25 // CHECK-NEXT: ret void
28 // CHECK-NEXT: %[[pad:[^ ]*]] = cleanuppad
29 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
30 // CHECK: call void @"?fin$0@0@basic_finally@@"({{i8 noundef( zeroext)?}} 1, ptr noundef %[[fp]])
31 // CHECK-NEXT: cleanupret from %[[pad]] unwind to caller
33 // CHECK: define internal void @"?fin$0@0@basic_finally@@"({{.*}})
34 // CHECK-SAME: [[finally_attrs:#[0-9]+]]
35 // CHECK: call void @cleanup()
37 // Mostly check that we don't double emit 'r' which would crash.
38 void decl_in_finally(void) {
46 // Ditto, don't crash double emitting 'l'.
47 void label_in_finally(void) {
53 if (check_condition())
58 // CHECK-LABEL: define dso_local void @label_in_finally()
59 // CHECK: invoke void @might_crash()
60 // CHECK: to label %[[invoke_cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
62 // CHECK: [[invoke_cont]]
63 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
64 // CHECK: call void @"?fin$0@0@label_in_finally@@"({{i8 noundef( zeroext)?}} 0, ptr noundef %[[fp]])
67 // CHECK: define internal void @"?fin$0@0@label_in_finally@@"({{.*}})
68 // CHECK-SAME: [[finally_attrs]]
69 // CHECK: br label %[[l:[^ ]*]]
72 // CHECK: call void @cleanup()
73 // CHECK: call i32 @check_condition()
74 // CHECK: br i1 {{.*}}, label
75 // CHECK: br label %[[l]]
78 void use_abnormal_termination(void) {
82 crashed
= __abnormal_termination();
86 // CHECK-LABEL: define dso_local void @use_abnormal_termination()
87 // CHECK: invoke void @might_crash()
88 // CHECK: to label %[[invoke_cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
90 // CHECK: [[invoke_cont]]
91 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
92 // CHECK: call void @"?fin$0@0@use_abnormal_termination@@"({{i8 noundef( zeroext)?}} 0, ptr noundef %[[fp]])
96 // CHECK-NEXT: %[[pad:[^ ]*]] = cleanuppad
97 // CHECK: %[[fp:[^ ]*]] = call ptr @llvm.localaddress()
98 // CHECK: call void @"?fin$0@0@use_abnormal_termination@@"({{i8 noundef( zeroext)?}} 1, ptr noundef %[[fp]])
99 // CHECK-NEXT: cleanupret from %[[pad]] unwind to caller
101 // CHECK: define internal void @"?fin$0@0@use_abnormal_termination@@"({{i8 noundef( zeroext)?}} %[[abnormal:abnormal_termination]], ptr noundef %frame_pointer)
102 // CHECK-SAME: [[finally_attrs]]
103 // CHECK: %[[abnormal_zext:[^ ]*]] = zext i8 %[[abnormal]] to i32
104 // CHECK: store i32 %[[abnormal_zext]], ptr @crashed
105 // CHECK-NEXT: ret void
107 void noreturn_noop_finally(void) {
115 // CHECK-LABEL: define dso_local void @noreturn_noop_finally()
116 // CHECK: call void @"?fin$0@0@noreturn_noop_finally@@"({{.*}})
119 // CHECK: define internal void @"?fin$0@0@noreturn_noop_finally@@"({{.*}})
120 // CHECK-SAME: [[finally_attrs]]
121 // CHECK: call void @abort()
122 // CHECK: unreachable
124 void noreturn_finally(void) {
132 // CHECK-LABEL: define dso_local void @noreturn_finally()
133 // CHECK: invoke void @might_crash()
134 // CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
137 // CHECK: call void @"?fin$0@0@noreturn_finally@@"({{.*}})
141 // CHECK-NEXT: %[[pad:[^ ]*]] = cleanuppad
142 // CHECK: call void @"?fin$0@0@noreturn_finally@@"({{.*}})
143 // CHECK-NEXT: cleanupret from %[[pad]] unwind to caller
145 // CHECK: define internal void @"?fin$0@0@noreturn_finally@@"({{.*}})
146 // CHECK-SAME: [[finally_attrs]]
147 // CHECK: call void @abort()
148 // CHECK: unreachable
150 int finally_with_return(void) {
156 // CHECK-LABEL: define dso_local i32 @finally_with_return()
157 // CHECK: store i32 1, ptr %cleanup.dest.slot
158 // CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
159 // CHECK: icmp ne i32 %cleanup.dest
160 // CHECK: call void @"?fin$0@0@finally_with_return@@"({{.*}})
163 // CHECK: define internal void @"?fin$0@0@finally_with_return@@"({{.*}})
164 // CHECK-SAME: [[finally_attrs]]
166 // CHECK-NOT: br label
169 int nested___finally___finally(void) {
176 // Intentionally no return here.
181 // CHECK-LABEL: define dso_local i32 @nested___finally___finally
182 // CHECK: invoke void @"?fin$1@0@nested___finally___finally@@"({{.*}})
183 // CHECK: to label %[[outercont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
185 // CHECK: [[outercont]]
186 // CHECK: call void @"?fin$0@0@nested___finally___finally@@"({{.*}})
187 // CHECK-NEXT: ret i32 0
190 // CHECK-NEXT: %[[pad:[^ ]*]] = cleanuppad
191 // CHECK: call void @"?fin$0@0@nested___finally___finally@@"({{.*}})
192 // CHECK-NEXT: cleanupret from %[[pad]] unwind to caller
194 // CHECK-LABEL: define internal void @"?fin$0@0@nested___finally___finally@@"({{.*}})
195 // CHECK-SAME: [[finally_attrs]]
198 // CHECK-LABEL: define internal void @"?fin$1@0@nested___finally___finally@@"({{.*}})
199 // CHECK-SAME: [[finally_attrs]]
200 // CHECK: unreachable
202 // FIXME: Our behavior seems suspiciously different.
204 int nested___finally___finally_with_eh_edge(void) {
212 // Intentionally no return here.
216 // CHECK-LABEL: define dso_local i32 @nested___finally___finally_with_eh_edge
217 // CHECK: invoke void @might_crash()
218 // CHECK-NEXT: to label %[[invokecont:[^ ]*]] unwind label %[[lpad1:[^ ]*]]
221 // CHECK: invoke void @"?fin$1@0@nested___finally___finally_with_eh_edge@@"({{.*}})
222 // CHECK-NEXT: to label %[[outercont:[^ ]*]] unwind label %[[lpad2:[^ ]*]]
224 // CHECK: [[outercont]]
225 // CHECK: call void @"?fin$0@0@nested___finally___finally_with_eh_edge@@"({{.*}})
226 // CHECK-NEXT: ret i32 912
229 // CHECK-NEXT: %[[innerpad:[^ ]*]] = cleanuppad
230 // CHECK: invoke void @"?fin$1@0@nested___finally___finally_with_eh_edge@@"({{.*}})
231 // CHECK-NEXT: label %[[innercleanupretbb:[^ ]*]] unwind label %[[lpad2:[^ ]*]]
233 // CHECK: [[innercleanupretbb]]
234 // CHECK-NEXT: cleanupret from %[[innerpad]] unwind label %[[lpad2]]
237 // CHECK-NEXT: %[[outerpad:[^ ]*]] = cleanuppad
238 // CHECK: call void @"?fin$0@0@nested___finally___finally_with_eh_edge@@"({{.*}})
239 // CHECK-NEXT: cleanupret from %[[outerpad]] unwind to caller
241 // CHECK-LABEL: define internal void @"?fin$0@0@nested___finally___finally_with_eh_edge@@"({{.*}})
242 // CHECK-SAME: [[finally_attrs]]
245 // CHECK-LABEL: define internal void @"?fin$1@0@nested___finally___finally_with_eh_edge@@"({{.*}})
246 // CHECK-SAME: [[finally_attrs]]
247 // CHECK: unreachable
249 void finally_within_finally(void) {
260 // CHECK-LABEL: define dso_local void @finally_within_finally(
261 // CHECK: invoke void @might_crash(
263 // CHECK: call void @"?fin$0@0@finally_within_finally@@"(
264 // CHECK: call void @"?fin$0@0@finally_within_finally@@"({{.*}}) [ "funclet"(
266 // CHECK-LABEL: define internal void @"?fin$0@0@finally_within_finally@@"({{[^)]*}})
267 // CHECK-SAME: [[finally_attrs]]
268 // CHECK: invoke void @might_crash(
270 // CHECK: call void @"?fin$1@0@finally_within_finally@@"(
271 // CHECK: call void @"?fin$1@0@finally_within_finally@@"({{.*}}) [ "funclet"(
273 // CHECK-LABEL: define internal void @"?fin$1@0@finally_within_finally@@"({{[^)]*}})
274 // CHECK-SAME: [[finally_attrs]]
276 void cleanup_with_func(const char *);
277 void finally_with_func(void) {
281 cleanup_with_func(__func__
);
285 // CHECK-LABEL: define internal void @"?fin$0@0@finally_with_func@@"({{[^)]*}})
286 // CHECK: call void @cleanup_with_func(ptr noundef @"??_C@_0BC@COAGBPGM@finally_with_func?$AA@")
288 // Look for the absence of noinline. nounwind is expected; any further
289 // attributes should be string attributes.
290 // CHECK: attributes [[finally_attrs]] = { nounwind "{{.*}}" }