blob: 06105c17397f69e938e7fbec7557a97f4ecb9f9b [file] [log] [blame]
Dan Gohman00fa9632011-06-16 20:57:14 +00001; RUN: opt -S -objc-arc < %s | FileCheck %s
2
3declare i8* @objc_retain(i8*)
4declare void @objc_release(i8*)
Dan Gohman532fb812012-03-14 23:05:06 +00005declare i8* @objc_retainAutoreleasedReturnValue(i8*)
Dan Gohman00fa9632011-06-16 20:57:14 +00006declare i8* @objc_msgSend(i8*, i8*, ...)
7declare void @use_pointer(i8*)
8declare void @callee()
Dan Gohmane3ed2b02012-03-23 18:09:00 +00009declare i8* @returner()
Dan Gohman00fa9632011-06-16 20:57:14 +000010
11; ARCOpt shouldn't try to move the releases to the block containing the invoke.
12
Stephen Lina76289a2013-07-14 01:50:49 +000013; CHECK-LABEL: define void @test0(
Dan Gohman00fa9632011-06-16 20:57:14 +000014; CHECK: invoke.cont:
Bill Wendlinga0323742013-02-22 09:09:42 +000015; CHECK: call void @objc_release(i8* %zipFile) [[NUW:#[0-9]+]], !clang.imprecise_release !0
Dan Gohman00fa9632011-06-16 20:57:14 +000016; CHECK: ret void
17; CHECK: lpad:
Bill Wendlinga0323742013-02-22 09:09:42 +000018; CHECK: call void @objc_release(i8* %zipFile) [[NUW]], !clang.imprecise_release !0
Dan Gohman00fa9632011-06-16 20:57:14 +000019; CHECK: ret void
Michael Gottesmanb33b6cb2013-04-27 05:25:54 +000020; CHECK-NEXT: }
David Majnemer7fddecc2015-06-17 20:52:32 +000021define void @test0(i8* %zipFile) personality i32 (...)* @__gxx_personality_v0 {
Dan Gohman00fa9632011-06-16 20:57:14 +000022entry:
23 call i8* @objc_retain(i8* %zipFile) nounwind
24 call void @use_pointer(i8* %zipFile)
25 invoke void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*)*)(i8* %zipFile)
26 to label %invoke.cont unwind label %lpad
27
28invoke.cont: ; preds = %entry
29 call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
30 ret void
31
32lpad: ; preds = %entry
David Majnemer7fddecc2015-06-17 20:52:32 +000033 %exn = landingpad {i8*, i32}
Bill Wendlinge6174a22011-08-31 21:04:11 +000034 cleanup
Dan Gohman00fa9632011-06-16 20:57:14 +000035 call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
36 ret void
37}
38
39; ARCOpt should move the release before the callee calls.
40
Stephen Lina76289a2013-07-14 01:50:49 +000041; CHECK-LABEL: define void @test1(
Dan Gohman00fa9632011-06-16 20:57:14 +000042; CHECK: invoke.cont:
Bill Wendlinga0323742013-02-22 09:09:42 +000043; CHECK: call void @objc_release(i8* %zipFile) [[NUW]], !clang.imprecise_release !0
Dan Gohman00fa9632011-06-16 20:57:14 +000044; CHECK: call void @callee()
45; CHECK: br label %done
46; CHECK: lpad:
Bill Wendlinga0323742013-02-22 09:09:42 +000047; CHECK: call void @objc_release(i8* %zipFile) [[NUW]], !clang.imprecise_release !0
Dan Gohman00fa9632011-06-16 20:57:14 +000048; CHECK: call void @callee()
49; CHECK: br label %done
50; CHECK: done:
51; CHECK-NEXT: ret void
Michael Gottesmanb33b6cb2013-04-27 05:25:54 +000052; CHECK-NEXT: }
David Majnemer7fddecc2015-06-17 20:52:32 +000053define void @test1(i8* %zipFile) personality i32 (...)* @__gxx_personality_v0 {
Dan Gohman00fa9632011-06-16 20:57:14 +000054entry:
55 call i8* @objc_retain(i8* %zipFile) nounwind
56 call void @use_pointer(i8* %zipFile)
57 invoke void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*)*)(i8* %zipFile)
58 to label %invoke.cont unwind label %lpad
59
60invoke.cont: ; preds = %entry
61 call void @callee()
62 br label %done
63
64lpad: ; preds = %entry
David Majnemer7fddecc2015-06-17 20:52:32 +000065 %exn = landingpad {i8*, i32}
Bill Wendlinge6174a22011-08-31 21:04:11 +000066 cleanup
Dan Gohman00fa9632011-06-16 20:57:14 +000067 call void @callee()
68 br label %done
69
70done:
71 call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
72 ret void
73}
74
Dan Gohman532fb812012-03-14 23:05:06 +000075; The optimizer should ignore invoke unwind paths consistently.
76; PR12265
77
David Majnemer7fddecc2015-06-17 20:52:32 +000078; CHECK: define void @test2() personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*) {
Dan Gohman532fb812012-03-14 23:05:06 +000079; CHECK: invoke.cont:
80; CHECK-NEXT: call i8* @objc_retain
Benjamin Kramer2f47a3f2012-08-17 12:28:26 +000081; CHECK-NOT: @objc_r
Dan Gohman532fb812012-03-14 23:05:06 +000082; CHECK: finally.cont:
83; CHECK-NEXT: call void @objc_release
Benjamin Kramer2f47a3f2012-08-17 12:28:26 +000084; CHECK-NOT: @objc
Dan Gohman532fb812012-03-14 23:05:06 +000085; CHECK: finally.rethrow:
Benjamin Kramer2f47a3f2012-08-17 12:28:26 +000086; CHECK-NOT: @objc
Dan Gohman532fb812012-03-14 23:05:06 +000087; CHECK: }
David Majnemer7fddecc2015-06-17 20:52:32 +000088define void @test2() personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*) {
Dan Gohman532fb812012-03-14 23:05:06 +000089entry:
90 %call = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* ()*)()
91 to label %invoke.cont unwind label %finally.rethrow, !clang.arc.no_objc_arc_exceptions !0
92
93invoke.cont: ; preds = %entry
94 %tmp1 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
95 call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void ()*)(), !clang.arc.no_objc_arc_exceptions !0
96 invoke void @use_pointer(i8* %call)
97 to label %finally.cont unwind label %finally.rethrow, !clang.arc.no_objc_arc_exceptions !0
98
99finally.cont: ; preds = %invoke.cont
100 tail call void @objc_release(i8* %call) nounwind, !clang.imprecise_release !0
101 ret void
102
103finally.rethrow: ; preds = %invoke.cont, %entry
David Majnemer7fddecc2015-06-17 20:52:32 +0000104 %tmp2 = landingpad { i8*, i32 }
Dan Gohman532fb812012-03-14 23:05:06 +0000105 catch i8* null
106 unreachable
107}
108
Dan Gohman5c70fad2012-03-23 17:47:54 +0000109; Don't try to place code on invoke critical edges.
110
Stephen Lina76289a2013-07-14 01:50:49 +0000111; CHECK-LABEL: define void @test3(
Dan Gohman5c70fad2012-03-23 17:47:54 +0000112; CHECK: if.end:
Bill Wendlinga0323742013-02-22 09:09:42 +0000113; CHECK-NEXT: call void @objc_release(i8* %p) [[NUW]]
Dan Gohman5c70fad2012-03-23 17:47:54 +0000114; CHECK-NEXT: ret void
Michael Gottesmanb33b6cb2013-04-27 05:25:54 +0000115; CHECK-NEXT: }
David Majnemer7fddecc2015-06-17 20:52:32 +0000116define void @test3(i8* %p, i1 %b) personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*) {
Dan Gohman5c70fad2012-03-23 17:47:54 +0000117entry:
118 %0 = call i8* @objc_retain(i8* %p)
119 call void @callee()
120 br i1 %b, label %if.else, label %if.then
121
122if.then:
123 invoke void @use_pointer(i8* %p)
124 to label %if.end unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
125
126if.else:
127 invoke void @use_pointer(i8* %p)
128 to label %if.end unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
129
130lpad:
David Majnemer7fddecc2015-06-17 20:52:32 +0000131 %r = landingpad { i8*, i32 }
Dan Gohman5c70fad2012-03-23 17:47:54 +0000132 cleanup
133 ret void
134
135if.end:
136 call void @objc_release(i8* %p)
137 ret void
138}
139
140; Like test3, but with ARC-relevant exception handling.
141
Stephen Lina76289a2013-07-14 01:50:49 +0000142; CHECK-LABEL: define void @test4(
Dan Gohman5c70fad2012-03-23 17:47:54 +0000143; CHECK: lpad:
David Majnemer7fddecc2015-06-17 20:52:32 +0000144; CHECK-NEXT: %r = landingpad { i8*, i32 }
Dan Gohman5c70fad2012-03-23 17:47:54 +0000145; CHECK-NEXT: cleanup
Bill Wendlinga0323742013-02-22 09:09:42 +0000146; CHECK-NEXT: call void @objc_release(i8* %p) [[NUW]]
Dan Gohman5c70fad2012-03-23 17:47:54 +0000147; CHECK-NEXT: ret void
148; CHECK: if.end:
Bill Wendlinga0323742013-02-22 09:09:42 +0000149; CHECK-NEXT: call void @objc_release(i8* %p) [[NUW]]
Dan Gohman5c70fad2012-03-23 17:47:54 +0000150; CHECK-NEXT: ret void
Michael Gottesmanb33b6cb2013-04-27 05:25:54 +0000151; CHECK-NEXT: }
David Majnemer7fddecc2015-06-17 20:52:32 +0000152define void @test4(i8* %p, i1 %b) personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*) {
Dan Gohman5c70fad2012-03-23 17:47:54 +0000153entry:
154 %0 = call i8* @objc_retain(i8* %p)
155 call void @callee()
156 br i1 %b, label %if.else, label %if.then
157
158if.then:
159 invoke void @use_pointer(i8* %p)
160 to label %if.end unwind label %lpad
161
162if.else:
163 invoke void @use_pointer(i8* %p)
164 to label %if.end unwind label %lpad
165
166lpad:
David Majnemer7fddecc2015-06-17 20:52:32 +0000167 %r = landingpad { i8*, i32 }
Dan Gohman5c70fad2012-03-23 17:47:54 +0000168 cleanup
169 call void @objc_release(i8* %p)
170 ret void
171
172if.end:
173 call void @objc_release(i8* %p)
174 ret void
175}
176
Dan Gohmane3ed2b02012-03-23 18:09:00 +0000177; Don't turn the retainAutoreleaseReturnValue into retain, because it's
178; for an invoke which we can assume codegen will put immediately prior.
179
Stephen Lina76289a2013-07-14 01:50:49 +0000180; CHECK-LABEL: define void @test5(
Dan Gohmane3ed2b02012-03-23 18:09:00 +0000181; CHECK: call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
182; CHECK: }
David Majnemer7fddecc2015-06-17 20:52:32 +0000183define void @test5() personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*) {
Dan Gohmane3ed2b02012-03-23 18:09:00 +0000184entry:
185 %z = invoke i8* @returner()
186 to label %if.end unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
187
188lpad:
David Majnemer7fddecc2015-06-17 20:52:32 +0000189 %r13 = landingpad { i8*, i32 }
Dan Gohmane3ed2b02012-03-23 18:09:00 +0000190 cleanup
191 ret void
192
193if.end:
194 call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
195 ret void
196}
197
198; Like test5, but there's intervening code.
199
Stephen Lina76289a2013-07-14 01:50:49 +0000200; CHECK-LABEL: define void @test6(
Dan Gohmane3ed2b02012-03-23 18:09:00 +0000201; CHECK: call i8* @objc_retain(i8* %z)
202; CHECK: }
David Majnemer7fddecc2015-06-17 20:52:32 +0000203define void @test6() personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*) {
Dan Gohmane3ed2b02012-03-23 18:09:00 +0000204entry:
205 %z = invoke i8* @returner()
206 to label %if.end unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
207
208lpad:
David Majnemer7fddecc2015-06-17 20:52:32 +0000209 %r13 = landingpad { i8*, i32 }
Dan Gohmane3ed2b02012-03-23 18:09:00 +0000210 cleanup
211 ret void
212
213if.end:
214 call void @callee()
215 call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
216 ret void
217}
218
Bill Wendlinge6174a22011-08-31 21:04:11 +0000219declare i32 @__gxx_personality_v0(...)
Dan Gohman532fb812012-03-14 23:05:06 +0000220declare i32 @__objc_personality_v0(...)
Bill Wendlinge6174a22011-08-31 21:04:11 +0000221
Bill Wendlinga0323742013-02-22 09:09:42 +0000222; CHECK: attributes [[NUW]] = { nounwind }
223
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000224!0 = !{}