1 // RUN: %clang_cc1 -no-opaque-pointers %s -triple x86_64-pc-win32 -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s
2 // RUN: %clang_cc1 -no-opaque-pointers %s -triple i686-pc-win32 -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s
3 // RUN: %clang_cc1 -no-opaque-pointers %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 i8* @llvm.localaddress()
24 // CHECK: call void @"?fin$0@0@basic_finally@@"({{i8 noundef( zeroext)?}} 0, i8* noundef %[[fp]])
25 // CHECK-NEXT: ret void
28 // CHECK-NEXT: %[[pad:[^ ]*]] = cleanuppad
29 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.localaddress()
30 // CHECK: call void @"?fin$0@0@basic_finally@@"({{i8 noundef( zeroext)?}} 1, i8* 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 i8* @llvm.localaddress()
64 // CHECK: call void @"?fin$0@0@label_in_finally@@"({{i8 noundef( zeroext)?}} 0, i8* 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 i8* @llvm.localaddress()
92 // CHECK: call void @"?fin$0@0@use_abnormal_termination@@"({{i8 noundef( zeroext)?}} 0, i8* noundef %[[fp]])
96 // CHECK-NEXT: %[[pad:[^ ]*]] = cleanuppad
97 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.localaddress()
98 // CHECK: call void @"?fin$0@0@use_abnormal_termination@@"({{i8 noundef( zeroext)?}} 1, i8* 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]], i8* noundef %frame_pointer)
102 // CHECK-SAME: [[finally_attrs]]
103 // CHECK: %[[abnormal_zext:[^ ]*]] = zext i8 %[[abnormal]] to i32
104 // CHECK: store i32 %[[abnormal_zext]], i32* @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: call void @"?fin$0@0@finally_with_return@@"({{.*}})
158 // CHECK-NEXT: ret i32 42
160 // CHECK: define internal void @"?fin$0@0@finally_with_return@@"({{.*}})
161 // CHECK-SAME: [[finally_attrs]]
163 // CHECK-NOT: br label
166 int nested___finally___finally(void) {
173 // Intentionally no return here.
178 // CHECK-LABEL: define dso_local i32 @nested___finally___finally
179 // CHECK: invoke void @"?fin$1@0@nested___finally___finally@@"({{.*}})
180 // CHECK: to label %[[outercont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
182 // CHECK: [[outercont]]
183 // CHECK: call void @"?fin$0@0@nested___finally___finally@@"({{.*}})
184 // CHECK-NEXT: ret i32 0
187 // CHECK-NEXT: %[[pad:[^ ]*]] = cleanuppad
188 // CHECK: call void @"?fin$0@0@nested___finally___finally@@"({{.*}})
189 // CHECK-NEXT: cleanupret from %[[pad]] unwind to caller
191 // CHECK-LABEL: define internal void @"?fin$0@0@nested___finally___finally@@"({{.*}})
192 // CHECK-SAME: [[finally_attrs]]
195 // CHECK-LABEL: define internal void @"?fin$1@0@nested___finally___finally@@"({{.*}})
196 // CHECK-SAME: [[finally_attrs]]
197 // CHECK: unreachable
199 // FIXME: Our behavior seems suspiciously different.
201 int nested___finally___finally_with_eh_edge(void) {
209 // Intentionally no return here.
213 // CHECK-LABEL: define dso_local i32 @nested___finally___finally_with_eh_edge
214 // CHECK: invoke void @might_crash()
215 // CHECK-NEXT: to label %[[invokecont:[^ ]*]] unwind label %[[lpad1:[^ ]*]]
218 // CHECK: invoke void @"?fin$1@0@nested___finally___finally_with_eh_edge@@"({{.*}})
219 // CHECK-NEXT: to label %[[outercont:[^ ]*]] unwind label %[[lpad2:[^ ]*]]
221 // CHECK: [[outercont]]
222 // CHECK: call void @"?fin$0@0@nested___finally___finally_with_eh_edge@@"({{.*}})
223 // CHECK-NEXT: ret i32 912
226 // CHECK-NEXT: %[[innerpad:[^ ]*]] = cleanuppad
227 // CHECK: invoke void @"?fin$1@0@nested___finally___finally_with_eh_edge@@"({{.*}})
228 // CHECK-NEXT: label %[[innercleanupretbb:[^ ]*]] unwind label %[[lpad2:[^ ]*]]
230 // CHECK: [[innercleanupretbb]]
231 // CHECK-NEXT: cleanupret from %[[innerpad]] unwind label %[[lpad2]]
234 // CHECK-NEXT: %[[outerpad:[^ ]*]] = cleanuppad
235 // CHECK: call void @"?fin$0@0@nested___finally___finally_with_eh_edge@@"({{.*}})
236 // CHECK-NEXT: cleanupret from %[[outerpad]] unwind to caller
238 // CHECK-LABEL: define internal void @"?fin$0@0@nested___finally___finally_with_eh_edge@@"({{.*}})
239 // CHECK-SAME: [[finally_attrs]]
242 // CHECK-LABEL: define internal void @"?fin$1@0@nested___finally___finally_with_eh_edge@@"({{.*}})
243 // CHECK-SAME: [[finally_attrs]]
244 // CHECK: unreachable
246 void finally_within_finally(void) {
257 // CHECK-LABEL: define dso_local void @finally_within_finally(
258 // CHECK: invoke void @might_crash(
260 // CHECK: call void @"?fin$0@0@finally_within_finally@@"(
261 // CHECK: call void @"?fin$0@0@finally_within_finally@@"({{.*}}) [ "funclet"(
263 // CHECK-LABEL: define internal void @"?fin$0@0@finally_within_finally@@"({{[^)]*}})
264 // CHECK-SAME: [[finally_attrs]]
265 // CHECK: invoke void @might_crash(
267 // CHECK: call void @"?fin$1@0@finally_within_finally@@"(
268 // CHECK: call void @"?fin$1@0@finally_within_finally@@"({{.*}}) [ "funclet"(
270 // CHECK-LABEL: define internal void @"?fin$1@0@finally_within_finally@@"({{[^)]*}})
271 // CHECK-SAME: [[finally_attrs]]
273 void cleanup_with_func(const char *);
274 void finally_with_func(void) {
278 cleanup_with_func(__func__
);
282 // CHECK-LABEL: define internal void @"?fin$0@0@finally_with_func@@"({{[^)]*}})
283 // CHECK: call void @cleanup_with_func(i8* noundef getelementptr inbounds ([18 x i8], [18 x i8]* @"??_C@_0BC@COAGBPGM@finally_with_func?$AA@", i{{32|64}} 0, i{{32|64}} 0))
285 // Look for the absence of noinline. nounwind is expected; any further
286 // attributes should be string attributes.
287 // CHECK: attributes [[finally_attrs]] = { nounwind "{{.*}}" }