John McCall | d1e40d5 | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s |
| 2 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-GLOBALS %s |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3 | |
Michael Gottesman | 554b07d | 2013-02-02 00:57:44 +0000 | [diff] [blame] | 4 | // rdar://13129783. Check both native/non-native arc platforms. Here we check |
| 5 | // that they treat nonlazybind differently. |
| 6 | // RUN: %clang_cc1 -fobjc-runtime=macosx-10.6.0 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-ALIEN %s |
| 7 | // RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s |
| 8 | |
Michael Gottesman | 554b07d | 2013-02-02 00:57:44 +0000 | [diff] [blame] | 9 | // ARC-ALIEN: declare extern_weak void @objc_storeStrong(i8**, i8*) |
Fariborz Jahanian | 41a6a3e | 2013-02-21 00:40:10 +0000 | [diff] [blame] | 10 | // ARC-ALIEN: declare extern_weak i8* @objc_retain(i8*) |
Michael Gottesman | 554b07d | 2013-02-02 00:57:44 +0000 | [diff] [blame] | 11 | // ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8*) |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame^] | 12 | // ARC-ALIEN: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB:#[0-9]+]] |
Michael Gottesman | 554b07d | 2013-02-02 00:57:44 +0000 | [diff] [blame] | 13 | // ARC-ALIEN: declare extern_weak void @objc_release(i8*) |
| 14 | // ARC-ALIEN: declare extern_weak i8* @objc_retainAutoreleasedReturnValue(i8*) |
| 15 | // ARC-ALIEN: declare extern_weak i8* @objc_initWeak(i8**, i8*) |
| 16 | // ARC-ALIEN: declare extern_weak i8* @objc_storeWeak(i8**, i8*) |
| 17 | // ARC-ALIEN: declare extern_weak i8* @objc_loadWeakRetained(i8**) |
| 18 | // ARC-ALIEN: declare extern_weak void @objc_destroyWeak(i8**) |
| 19 | // ARC-ALIEN: declare extern_weak i8* @objc_autorelease(i8*) |
| 20 | // ARC-ALIEN: declare extern_weak i8* @objc_retainAutorelease(i8*) |
| 21 | |
Michael Gottesman | 554b07d | 2013-02-02 00:57:44 +0000 | [diff] [blame] | 22 | // ARC-NATIVE: declare void @objc_storeStrong(i8**, i8*) |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame^] | 23 | // ARC-NATIVE: declare i8* @objc_retain(i8*) [[NLB:#[0-9]+]] |
Michael Gottesman | 554b07d | 2013-02-02 00:57:44 +0000 | [diff] [blame] | 24 | // ARC-NATIVE: declare i8* @objc_autoreleaseReturnValue(i8*) |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame^] | 25 | // ARC-NATIVE: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB]] |
| 26 | // ARC-NATIVE: declare void @objc_release(i8*) [[NLB]] |
Michael Gottesman | 554b07d | 2013-02-02 00:57:44 +0000 | [diff] [blame] | 27 | // ARC-NATIVE: declare i8* @objc_retainAutoreleasedReturnValue(i8*) |
| 28 | // ARC-NATIVE: declare i8* @objc_initWeak(i8**, i8*) |
| 29 | // ARC-NATIVE: declare i8* @objc_storeWeak(i8**, i8*) |
| 30 | // ARC-NATIVE: declare i8* @objc_loadWeakRetained(i8**) |
| 31 | // ARC-NATIVE: declare void @objc_destroyWeak(i8**) |
| 32 | // ARC-NATIVE: declare i8* @objc_autorelease(i8*) |
| 33 | // ARC-NATIVE: declare i8* @objc_retainAutorelease(i8*) |
| 34 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 35 | // CHECK: define void @test0 |
| 36 | void test0(id x) { |
| 37 | // CHECK: [[X:%.*]] = alloca i8* |
| 38 | // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{.*}}) |
| 39 | // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] |
| 40 | // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] |
| 41 | // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) |
| 42 | // CHECK-NEXT: ret void |
| 43 | } |
| 44 | |
| 45 | // CHECK: define i8* @test1(i8* |
| 46 | id test1(id x) { |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 47 | // CHECK: [[X:%.*]] = alloca i8* |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 48 | // CHECK-NEXT: [[Y:%.*]] = alloca i8* |
| 49 | // CHECK-NEXT: alloca i32 |
| 50 | // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}}) |
| 51 | // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] |
| 52 | // CHECK-NEXT: store i8* null, i8** [[Y]] |
| 53 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 54 | // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T0]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 55 | // CHECK-NEXT: store i32 |
| 56 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] |
| 57 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
| 58 | // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] |
| 59 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
Chad Rosier | df76f1e | 2012-12-12 17:52:21 +0000 | [diff] [blame] | 60 | // CHECK-NEXT: [[T1:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[RET]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 61 | // CHECK-NEXT: ret i8* [[T1]] |
| 62 | id y; |
| 63 | return y; |
| 64 | } |
| 65 | |
| 66 | @interface Test2 |
| 67 | + (void) class_method; |
| 68 | - (void) inst_method; |
| 69 | @end |
| 70 | @implementation Test2 |
| 71 | |
| 72 | // The self pointer of a class method is not retained. |
| 73 | // CHECK: define internal void @"\01+[Test2 class_method]" |
| 74 | // CHECK: alloca |
| 75 | // CHECK-NEXT: alloca |
| 76 | // CHECK-NEXT: store |
| 77 | // CHECK-NEXT: store |
| 78 | // CHECK-NEXT: ret void |
| 79 | + (void) class_method {} |
| 80 | |
| 81 | // The self pointer of an instance method is not retained. |
| 82 | // CHECK: define internal void @"\01-[Test2 inst_method]" |
| 83 | // CHECK: alloca |
| 84 | // CHECK-NEXT: alloca |
| 85 | // CHECK-NEXT: store |
| 86 | // CHECK-NEXT: store |
| 87 | // CHECK-NEXT: ret void |
| 88 | - (void) inst_method {} |
| 89 | @end |
| 90 | |
| 91 | @interface Test3 |
| 92 | + (id) alloc; |
| 93 | - (id) initWith: (int) x; |
| 94 | - (id) copy; |
| 95 | @end |
| 96 | |
| 97 | // CHECK: define void @test3_unelided() |
| 98 | void test3_unelided() { |
| 99 | extern void test3_helper(void); |
| 100 | |
| 101 | // CHECK: [[X:%.*]] = alloca [[TEST3:%.*]]* |
| 102 | // CHECK-NEXT: store [[TEST3]]* null, [[TEST3]]** [[X]], align |
| 103 | Test3 *x; |
| 104 | |
| 105 | // Call to +alloc. |
| 106 | // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ |
| 107 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 108 | // CHECK-NEXT: bitcast |
| 109 | // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend |
| 110 | // CHECK-NEXT: bitcast |
| 111 | // CHECK-NEXT: bitcast |
| 112 | // CHECK-NEXT: call void @objc_release(i8* |
| 113 | [Test3 alloc]; |
| 114 | |
| 115 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] |
| 116 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 117 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* |
| 118 | // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[T1]], |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 119 | // CHECK-NEXT: call void @objc_release(i8* [[COPY]]) [[NUW:#[0-9]+]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 120 | [x copy]; |
| 121 | |
| 122 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] |
| 123 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 124 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 125 | // CHECK-NEXT: ret void |
| 126 | } |
| 127 | |
| 128 | // CHECK: define void @test3() |
| 129 | void test3() { |
| 130 | // CHECK: [[X:%.*]] = alloca i8* |
| 131 | |
| 132 | id x = [[Test3 alloc] initWith: 5]; |
| 133 | |
| 134 | // Call to +alloc. |
| 135 | // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ |
| 136 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 137 | // CHECK-NEXT: bitcast |
| 138 | // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend |
| 139 | // CHECK-NEXT: bitcast |
| 140 | |
| 141 | // Call to -initWith: with elided retain of consumed argument. |
| 142 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 143 | // CHECK-NEXT: bitcast |
| 144 | // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* |
| 145 | // CHECK-NEXT: bitcast |
| 146 | // CHECK-NEXT: [[INIT:%.*]] = bitcast |
| 147 | // Assignment for initialization, retention elided. |
| 148 | // CHECK-NEXT: store i8* [[INIT]], i8** [[X]] |
| 149 | |
| 150 | // Call to -copy. |
| 151 | // CHECK-NEXT: [[V:%.*]] = load i8** [[X]] |
| 152 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 153 | // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[V]], |
| 154 | |
| 155 | // Assignment to x. |
| 156 | // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] |
| 157 | // CHECK-NEXT: store i8* [[COPY]], i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 158 | // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 159 | |
| 160 | x = [x copy]; |
| 161 | |
| 162 | // Cleanup for x. |
| 163 | // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 164 | // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 165 | |
| 166 | // CHECK-NEXT: ret void |
| 167 | } |
| 168 | |
| 169 | // CHECK: define i8* @test4() |
| 170 | id test4() { |
| 171 | // Call to +alloc. |
| 172 | // CHECK: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ |
| 173 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 174 | // CHECK-NEXT: bitcast |
| 175 | // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend |
| 176 | // CHECK-NEXT: [[ALLOC:%.*]] = bitcast |
| 177 | |
| 178 | // Call to -initWith: with elided retain of consumed argument. |
| 179 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 180 | // CHECK-NEXT: [[ALLOC:%.*]] = bitcast |
| 181 | // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* [[ALLOC]], |
| 182 | |
| 183 | // Initialization of return value, occuring within full-expression. |
| 184 | // Retain/release elided. |
| 185 | // CHECK-NEXT: bitcast |
| 186 | // CHECK-NEXT: [[INIT:%.*]] = bitcast |
Chad Rosier | df76f1e | 2012-12-12 17:52:21 +0000 | [diff] [blame] | 187 | // CHECK-NEXT: [[RET:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[INIT]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 188 | |
| 189 | // CHECK-NEXT: ret i8* [[RET]] |
| 190 | |
| 191 | return [[Test3 alloc] initWith: 6]; |
| 192 | } |
| 193 | |
| 194 | @interface Test5 { |
| 195 | @public |
| 196 | id var; |
| 197 | } |
| 198 | @end |
| 199 | |
| 200 | // CHECK: define void @test5 |
| 201 | void test5(Test5 *x, id y) { |
| 202 | // Prologue. |
| 203 | // CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*, |
| 204 | // CHECK-NEXT: [[Y:%.*]] = alloca i8* |
| 205 | // CHECK-NEXT: bitcast [[TEST5]]* {{%.*}} to i8* |
| 206 | // CHECK-NEXT: call i8* @objc_retain |
| 207 | // CHECK-NEXT: [[PARMX:%.*]] = bitcast i8* {{%.*}} to [[TEST5]]* |
| 208 | // CHECK-NEXT: store [[TEST5]]* [[PARMX]], [[TEST5]]** [[X]] |
| 209 | // CHECK-NEXT: call i8* @objc_retain |
| 210 | // CHECK-NEXT: store |
| 211 | |
| 212 | // CHECK-NEXT: load [[TEST5]]** [[X]] |
| 213 | // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" |
| 214 | // CHECK-NEXT: bitcast |
| 215 | // CHECK-NEXT: getelementptr |
| 216 | // CHECK-NEXT: [[VAR:%.*]] = bitcast |
| 217 | // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] |
| 218 | // CHECK-NEXT: store i8* null, i8** [[VAR]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 219 | // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 220 | x->var = 0; |
| 221 | |
| 222 | // CHECK-NEXT: [[YVAL:%.*]] = load i8** [[Y]] |
| 223 | // CHECK-NEXT: load [[TEST5]]** [[X]] |
| 224 | // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" |
| 225 | // CHECK-NEXT: bitcast |
| 226 | // CHECK-NEXT: getelementptr |
| 227 | // CHECK-NEXT: [[VAR:%.*]] = bitcast |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 228 | // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[YVAL]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 229 | // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] |
| 230 | // CHECK-NEXT: store i8* [[T0]], i8** [[VAR]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 231 | // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 232 | x->var = y; |
| 233 | |
| 234 | // Epilogue. |
| 235 | // CHECK-NEXT: [[TMP:%.*]] = load i8** [[Y]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 236 | // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 237 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[X]] |
| 238 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 239 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 240 | // CHECK-NEXT: ret void |
| 241 | } |
| 242 | |
| 243 | id test6_helper(void) __attribute__((ns_returns_retained)); |
| 244 | // CHECK: define void @test6() |
| 245 | void test6() { |
| 246 | // CHECK: [[X:%.*]] = alloca i8* |
| 247 | // CHECK-NEXT: [[CALL:%.*]] = call i8* @test6_helper() |
| 248 | // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] |
| 249 | // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 250 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 251 | // CHECK-NEXT: ret void |
| 252 | id x = test6_helper(); |
| 253 | } |
| 254 | |
| 255 | void test7_helper(id __attribute__((ns_consumed))); |
| 256 | // CHECK: define void @test7() |
| 257 | void test7() { |
| 258 | // CHECK: [[X:%.*]] = alloca i8* |
| 259 | // CHECK-NEXT: store i8* null, i8** [[X]] |
| 260 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 261 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 262 | // CHECK-NEXT: call void @test7_helper(i8* [[T1]]) |
| 263 | // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 264 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 265 | // CHECK-NEXT: ret void |
| 266 | id x; |
| 267 | test7_helper(x); |
| 268 | } |
| 269 | |
| 270 | id test8_helper(void) __attribute__((ns_returns_retained)); |
| 271 | void test8() { |
| 272 | __unsafe_unretained id x = test8_helper(); |
| 273 | // CHECK: [[X:%.*]] = alloca i8* |
| 274 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test8_helper() |
| 275 | // CHECK-NEXT: store i8* [[T0]], i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 276 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 277 | // CHECK-NOT: imprecise_release |
| 278 | // CHECK-NEXT: ret void |
| 279 | } |
| 280 | |
| 281 | id test9_helper(void) __attribute__((ns_returns_retained)); |
| 282 | void test9() { |
| 283 | id x __attribute__((objc_precise_lifetime)) = test9_helper(); |
| 284 | x = 0; |
| 285 | // CHECK: [[X:%.*]] = alloca i8* |
| 286 | // CHECK-NEXT: [[CALL:%.*]] = call i8* @test9_helper() |
| 287 | // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] |
| 288 | |
| 289 | // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] |
| 290 | // CHECK-NEXT: store i8* null, i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 291 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 292 | |
| 293 | // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 294 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 295 | // CHECK-NOT: clang.imprecise_release |
| 296 | |
| 297 | // CHECK-NEXT: ret void |
| 298 | } |
| 299 | |
| 300 | @interface Test10 |
| 301 | @property (retain) Test10 *me; |
| 302 | @end |
| 303 | void test10() { |
| 304 | Test10 *x; |
| 305 | id y = x.me.me; |
| 306 | |
| 307 | // CHECK: define void @test10() |
| 308 | // CHECK: [[X:%.*]] = alloca [[TEST10:%.*]]*, align |
| 309 | // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align |
| 310 | // CHECK-NEXT: store [[TEST10]]* null, [[TEST10]]** [[X]] |
| 311 | // CHECK-NEXT: load [[TEST10]]** [[X]], align |
| 312 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}" |
| 313 | // CHECK-NEXT: bitcast |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 314 | // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend |
| 315 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* |
| 316 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) |
| 317 | // CHECK-NEXT: [[V:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 318 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}" |
| 319 | // CHECK-NEXT: bitcast |
| 320 | // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend |
| 321 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* |
| 322 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) |
| 323 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* |
| 324 | // CHECK-NEXT: [[T4:%.*]] = bitcast [[TEST10]]* [[T3]] to i8* |
| 325 | // CHECK-NEXT: store i8* [[T4]], i8** [[Y]] |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 326 | // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST10]]* [[V]] to i8* |
| 327 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 328 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] |
| 329 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
| 330 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST10]]** [[X]] |
| 331 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* |
| 332 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
| 333 | // CHECK-NEXT: ret void |
| 334 | } |
| 335 | |
| 336 | void test11(id (*f)(void) __attribute__((ns_returns_retained))) { |
| 337 | // CHECK: define void @test11( |
| 338 | // CHECK: [[F:%.*]] = alloca i8* ()*, align |
| 339 | // CHECK-NEXT: [[X:%.*]] = alloca i8*, align |
| 340 | // CHECK-NEXT: store i8* ()* {{%.*}}, i8* ()** [[F]], align |
| 341 | // CHECK-NEXT: [[T0:%.*]] = load i8* ()** [[F]], align |
| 342 | // CHECK-NEXT: [[T1:%.*]] = call i8* [[T0]]() |
| 343 | // CHECK-NEXT: store i8* [[T1]], i8** [[X]], align |
| 344 | // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 345 | // CHECK-NEXT: call void @objc_release(i8* [[T3]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 346 | // CHECK-NEXT: ret void |
| 347 | id x = f(); |
| 348 | } |
| 349 | |
| 350 | void test12(void) { |
| 351 | extern id test12_helper(void); |
| 352 | |
| 353 | // CHECK: define void @test12() |
| 354 | // CHECK: [[X:%.*]] = alloca i8*, align |
| 355 | // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align |
| 356 | |
| 357 | __weak id x = test12_helper(); |
| 358 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 359 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 360 | // CHECK-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T1]]) |
| 361 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 362 | |
| 363 | x = test12_helper(); |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 364 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() |
| 365 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 366 | // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[X]], i8* [[T1]]) |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 367 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 368 | |
| 369 | id y = x; |
| 370 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_loadWeakRetained(i8** [[X]]) |
| 371 | // CHECK-NEXT: store i8* [[T2]], i8** [[Y]], align |
| 372 | |
| 373 | // CHECK-NEXT: [[T4:%.*]] = load i8** [[Y]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 374 | // CHECK-NEXT: call void @objc_release(i8* [[T4]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 375 | // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) |
| 376 | // CHECK-NEXT: ret void |
| 377 | } |
| 378 | |
| 379 | // Indirect consuming calls. |
| 380 | void test13(void) { |
| 381 | // CHECK: define void @test13() |
| 382 | // CHECK: [[X:%.*]] = alloca i8*, align |
| 383 | // CHECK-NEXT: store i8* null, i8** [[X]], align |
| 384 | id x; |
| 385 | |
| 386 | typedef void fnty(id __attribute__((ns_consumed))); |
| 387 | extern fnty *test13_func; |
| 388 | // CHECK-NEXT: [[FN:%.*]] = load void (i8*)** @test13_func, align |
| 389 | // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 390 | // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 391 | // CHECK-NEXT: call void [[FN]](i8* [[X_TMP]]) |
| 392 | test13_func(x); |
| 393 | |
| 394 | extern fnty ^test13_block; |
| 395 | // CHECK-NEXT: [[TMP:%.*]] = load void (i8*)** @test13_block, align |
| 396 | // CHECK-NEXT: [[BLOCK:%.*]] = bitcast void (i8*)* [[TMP]] to [[BLOCKTY:%.*]]* |
| 397 | // CHECK-NEXT: [[BLOCK_FN_PTR:%.*]] = getelementptr inbounds [[BLOCKTY]]* [[BLOCK]], i32 0, i32 3 |
| 398 | // CHECK-NEXT: [[BLOCK_OPAQUE:%.*]] = bitcast [[BLOCKTY]]* [[BLOCK]] to i8* |
| 399 | // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 400 | // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 401 | // CHECK-NEXT: [[BLOCK_FN_TMP:%.*]] = load i8** [[BLOCK_FN_PTR]] |
| 402 | // CHECK-NEXT: [[BLOCK_FN:%.*]] = bitcast i8* [[BLOCK_FN_TMP]] to void (i8*, i8*)* |
| 403 | // CHECK-NEXT: call void [[BLOCK_FN]](i8* [[BLOCK_OPAQUE]], i8* [[X_TMP]]) |
| 404 | test13_block(x); |
| 405 | |
| 406 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 407 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 408 | // CHECK-NEXT: ret void |
| 409 | } |
| 410 | |
| 411 | @interface Test16_super @end |
| 412 | @interface Test16 : Test16_super { |
| 413 | id z; |
| 414 | } |
| 415 | @property (assign) int x; |
| 416 | @property (retain) id y; |
| 417 | - (void) dealloc; |
| 418 | @end |
| 419 | @implementation Test16 |
| 420 | @synthesize x; |
| 421 | @synthesize y; |
| 422 | - (void) dealloc { |
| 423 | // CHECK: define internal void @"\01-[Test16 dealloc]"( |
| 424 | // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align |
| 425 | // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align |
| 426 | // CHECK-NEXT: alloca |
| 427 | // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align |
| 428 | // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] |
| 429 | // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] |
| 430 | |
| 431 | // Call super. |
| 432 | // CHECK-NEXT: [[BASE2:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* |
| 433 | // CHECK-NEXT: [[T0:%.*]] = getelementptr |
| 434 | // CHECK-NEXT: store i8* [[BASE2]], i8** [[T0]] |
| 435 | // CHECK-NEXT: load {{%.*}}** @"\01L_OBJC_CLASSLIST_SUP_REFS_$_ |
| 436 | // CHECK-NEXT: bitcast |
| 437 | // CHECK-NEXT: getelementptr |
| 438 | // CHECK-NEXT: store |
| 439 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 440 | // CHECK-NEXT: call void bitcast (i8* ({{.*}})* @objc_msgSendSuper2 to void ( |
| 441 | // CHECK-NEXT: ret void |
| 442 | } |
| 443 | |
| 444 | // .cxx_destruct |
| 445 | // CHECK: define internal void @"\01-[Test16 .cxx_destruct]"( |
| 446 | // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align |
| 447 | // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align |
| 448 | // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align |
| 449 | // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] |
| 450 | // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] |
| 451 | |
| 452 | // Destroy y. |
| 453 | // CHECK-NEXT: [[Y_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.y" |
| 454 | // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* |
| 455 | // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Y_OFF]] |
| 456 | // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 457 | // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 458 | |
| 459 | // Destroy z. |
| 460 | // CHECK-NEXT: [[Z_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.z" |
| 461 | // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* |
| 462 | // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Z_OFF]] |
| 463 | // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 464 | // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 465 | |
| 466 | // CHECK-NEXT: ret void |
| 467 | |
| 468 | @end |
| 469 | |
| 470 | // This shouldn't crash. |
| 471 | @interface Test17A |
| 472 | @property (assign) int x; |
| 473 | @end |
| 474 | @interface Test17B : Test17A |
| 475 | @end |
| 476 | @implementation Test17B |
| 477 | - (int) x { return super.x + 1; } |
| 478 | @end |
| 479 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 480 | void test19() { |
| 481 | // CHECK: define void @test19() |
| 482 | // CHECK: [[X:%.*]] = alloca [5 x i8*], align 16 |
| 483 | // CHECK-NEXT: [[T0:%.*]] = bitcast [5 x i8*]* [[X]] to i8* |
| 484 | // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 40, i32 16, i1 false) |
| 485 | id x[5]; |
| 486 | |
| 487 | extern id test19_helper(void); |
| 488 | x[2] = test19_helper(); |
| 489 | |
| 490 | // CHECK-NEXT: [[CALL:%.*]] = call i8* @test19_helper() |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 491 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 492 | // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i64 2 |
| 493 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] |
| 494 | // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 495 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 496 | |
| 497 | // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i32 0 |
| 498 | // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 5 |
| 499 | // CHECK-NEXT: br label |
| 500 | |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 501 | // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] |
| 502 | // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 |
| 503 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 504 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 505 | // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] |
| 506 | // CHECK-NEXT: br i1 [[EQ]], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 507 | |
| 508 | // CHECK: ret void |
| 509 | } |
| 510 | |
| 511 | void test20(unsigned n) { |
| 512 | // CHECK: define void @test20 |
| 513 | // CHECK: [[N:%.*]] = alloca i32, align 4 |
| 514 | // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* |
| 515 | // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 |
| 516 | |
| 517 | id x[n]; |
| 518 | |
| 519 | // Capture the VLA size. |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 520 | // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 |
| 521 | // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 |
| 522 | |
| 523 | // Save the stack pointer. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 524 | // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() |
| 525 | // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 526 | |
| 527 | // Allocate the VLA. |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 528 | // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16 |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 529 | |
| 530 | // Zero-initialize. |
| 531 | // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8* |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 532 | // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8 |
| 533 | // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T1]], i32 8, i1 false) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 534 | |
| 535 | // Destroy. |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 536 | // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[VLA]], i64 [[DIM]] |
John McCall | fbf780a | 2011-07-13 08:09:46 +0000 | [diff] [blame] | 537 | // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[VLA]], [[END]] |
| 538 | // CHECK-NEXT: br i1 [[EMPTY]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 539 | |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 540 | // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] |
| 541 | // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 |
| 542 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 543 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 544 | // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[VLA]] |
| 545 | // CHECK-NEXT: br i1 [[EQ]], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 546 | |
| 547 | // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] |
| 548 | // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) |
| 549 | // CHECK-NEXT: ret void |
| 550 | } |
| 551 | |
| 552 | void test21(unsigned n) { |
| 553 | // CHECK: define void @test21 |
| 554 | // CHECK: [[N:%.*]] = alloca i32, align 4 |
| 555 | // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* |
| 556 | // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 |
| 557 | |
| 558 | id x[2][n][3]; |
| 559 | |
| 560 | // Capture the VLA size. |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 561 | // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 |
| 562 | // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 |
| 563 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 564 | // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() |
| 565 | // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 566 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 567 | |
| 568 | // Allocate the VLA. |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 569 | // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] |
| 570 | // CHECK-NEXT: [[VLA:%.*]] = alloca [3 x i8*], i64 [[T0]], align 16 |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 571 | |
| 572 | // Zero-initialize. |
| 573 | // CHECK-NEXT: [[T0:%.*]] = bitcast [3 x i8*]* [[VLA]] to i8* |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 574 | // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 2, [[DIM]] |
| 575 | // CHECK-NEXT: [[T2:%.*]] = mul nuw i64 [[T1]], 24 |
| 576 | // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T2]], i32 8, i1 false) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 577 | |
| 578 | // Destroy. |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 579 | // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 580 | // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [3 x i8*]* [[VLA]], i32 0, i32 0 |
John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 581 | // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[T0]], 3 |
| 582 | // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[T1]] |
John McCall | fbf780a | 2011-07-13 08:09:46 +0000 | [diff] [blame] | 583 | // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[BEGIN]], [[END]] |
| 584 | // CHECK-NEXT: br i1 [[EMPTY]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 585 | |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 586 | // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] |
| 587 | // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 |
| 588 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 589 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 590 | // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] |
| 591 | // CHECK-NEXT: br i1 [[EQ]], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 592 | |
| 593 | // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] |
| 594 | // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) |
| 595 | // CHECK-NEXT: ret void |
| 596 | } |
| 597 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 598 | // rdar://problem/8922540 |
| 599 | // Note that we no longer emit .release_ivars flags. |
John McCall | b03527a | 2012-10-17 04:53:31 +0000 | [diff] [blame] | 600 | // rdar://problem/12492434 |
| 601 | // Note that we set the flag saying that we need destruction *and* |
| 602 | // the flag saying that we don't also need construction. |
| 603 | // CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test23" = internal global [[RO_T:%.*]] { i32 390, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 604 | @interface Test23 { id x; } @end |
| 605 | @implementation Test23 @end |
| 606 | |
| 607 | // CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test24" = internal global [[RO_T:%.*]] { i32 130, |
| 608 | @interface Test24 {} @end |
| 609 | @implementation Test24 @end |
| 610 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 611 | // rdar://problem/8941012 |
| 612 | @interface Test26 { id x[4]; } @end |
| 613 | @implementation Test26 @end |
| 614 | // CHECK: define internal void @"\01-[Test26 .cxx_destruct]"( |
| 615 | // CHECK: [[SELF:%.*]] = load [[TEST26:%.*]]** |
| 616 | // CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test26.x" |
| 617 | // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST26]]* [[SELF]] to i8* |
| 618 | // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] |
| 619 | // CHECK-NEXT: [[X:%.*]] = bitcast i8* [[T1]] to [4 x i8*]* |
| 620 | // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x i8*]* [[X]], i32 0, i32 0 |
| 621 | // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 4 |
| 622 | // CHECK-NEXT: br label |
John McCall | 9928c48 | 2011-07-12 16:41:08 +0000 | [diff] [blame] | 623 | // CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] |
| 624 | // CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 |
| 625 | // CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null) |
| 626 | // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 627 | // CHECK-NEXT: br i1 [[ISDONE]], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 628 | // CHECK: ret void |
| 629 | |
| 630 | // Check that 'init' retains self. |
| 631 | @interface Test27 |
| 632 | - (id) init; |
| 633 | @end |
| 634 | @implementation Test27 |
| 635 | - (id) init { return self; } |
| 636 | // CHECK: define internal i8* @"\01-[Test27 init]" |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 637 | // CHECK: [[SELF:%.*]] = alloca [[TEST27:%.*]]*, |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 638 | // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, |
| 639 | // CHECK-NEXT: [[DEST:%.*]] = alloca i32 |
| 640 | // CHECK-NEXT: store [[TEST27]]* {{%.*}}, [[TEST27]]** [[SELF]] |
| 641 | // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] |
| 642 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] |
| 643 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* |
Eli Friedman | 38ac243 | 2012-03-30 01:13:43 +0000 | [diff] [blame] | 644 | // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 645 | // CHECK-NEXT: store i32 {{[0-9]+}}, i32* [[DEST]] |
| 646 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] |
| 647 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* |
| 648 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 649 | // CHECK-NEXT: ret i8* [[RET]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 650 | |
| 651 | @end |
| 652 | |
| 653 | // rdar://problem/8087194 |
| 654 | @interface Test28 |
| 655 | @property (copy) id prop; |
| 656 | @end |
| 657 | @implementation Test28 |
| 658 | @synthesize prop; |
| 659 | @end |
| 660 | // CHECK: define internal void @"\01-[Test28 .cxx_destruct]" |
| 661 | // CHECK: [[SELF:%.*]] = load [[TEST28:%.*]]** |
| 662 | // CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test28.prop" |
| 663 | // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST28]]* [[SELF]] to i8* |
| 664 | // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] |
| 665 | // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** |
| 666 | // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) |
| 667 | // CHECK-NEXT: ret void |
| 668 | |
| 669 | @interface Test29_super |
| 670 | - (id) initWithAllocator: (id) allocator; |
| 671 | @end |
| 672 | @interface Test29 : Test29_super |
| 673 | - (id) init; |
| 674 | - (id) initWithAllocator: (id) allocator; |
| 675 | @end |
| 676 | @implementation Test29 |
| 677 | static id _test29_allocator = 0; |
| 678 | - (id) init { |
Bill Wendling | c0dcc2d | 2013-02-15 21:30:01 +0000 | [diff] [blame] | 679 | // CHECK: define internal i8* @"\01-[Test29 init]"([[TEST29:%[^*]*]]* {{%.*}}, |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 680 | // CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 681 | // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 |
| 682 | // CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 |
| 683 | // CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] |
| 684 | // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] |
| 685 | |
| 686 | // Evaluate arguments. Note that the send argument is evaluated |
| 687 | // before the zeroing of self. |
| 688 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]], align 8 |
| 689 | // CHECK-NEXT: [[T1:%.*]] = load i8** @_test29_allocator, align 8 |
| 690 | |
| 691 | // Implicit null of 'self', i.e. direct transfer of ownership. |
| 692 | // CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] |
| 693 | |
| 694 | // Actual message send. |
| 695 | // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 696 | // CHECK-NEXT: [[T3:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* |
| 697 | // CHECK-NEXT: [[CALL:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T3]], i8* [[T2]], i8* [[T1]]) |
| 698 | |
| 699 | // Implicit write of result back into 'self'. This is not supposed to |
| 700 | // be detectable because we're supposed to ban accesses to the old |
| 701 | // self value past the delegate init call. |
| 702 | // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* |
| 703 | // CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] |
| 704 | |
| 705 | // Return statement. |
| 706 | // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[CALL]] |
| 707 | // CHECK-NEXT: [[CALL:%.*]] = bitcast |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 708 | // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[CALL]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 709 | // CHECK-NEXT: store i32 1, i32* [[CLEANUP]] |
| 710 | |
| 711 | // Cleanup. |
| 712 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] |
| 713 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 714 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 715 | |
| 716 | // Return. |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 717 | // CHECK-NEXT: ret i8* [[RET]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 718 | return [self initWithAllocator: _test29_allocator]; |
| 719 | } |
| 720 | - (id) initWithAllocator: (id) allocator { |
| 721 | // CHECK: define internal i8* @"\01-[Test29 initWithAllocator:]"( |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 722 | // CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 723 | // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 |
| 724 | // CHECK-NEXT: [[ALLOCATOR:%.*]] = alloca i8*, align 8 |
| 725 | // CHECK-NEXT: alloca |
| 726 | // CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 |
| 727 | // CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] |
| 728 | // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] |
| 729 | // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}}) |
| 730 | // CHECK-NEXT: store i8* [[T0]], i8** [[ALLOCATOR]] |
| 731 | |
| 732 | // Evaluate arguments. Note that the send argument is evaluated |
| 733 | // before the zeroing of self. |
| 734 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] |
| 735 | // CHECK-NEXT: [[T1:%.*]] = load i8** [[ALLOCATOR]], align 8 |
| 736 | |
| 737 | // Implicit null of 'self', i.e. direct transfer of ownership. |
| 738 | // CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] |
| 739 | |
| 740 | // Actual message send. |
| 741 | // CHECK: [[CALL:%.*]] = call {{.*}} @objc_msgSendSuper2 |
| 742 | |
| 743 | // Implicit write of result back into 'self'. This is not supposed to |
| 744 | // be detectable because we're supposed to ban accesses to the old |
| 745 | // self value past the delegate init call. |
| 746 | // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* |
| 747 | // CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] |
| 748 | |
| 749 | // Assignment. |
| 750 | // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* |
| 751 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 752 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 753 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST29]]* |
| 754 | // CHECK-NEXT: [[T4:%.*]] = load [[TEST29]]** [[SELF]], align |
| 755 | // CHECK-NEXT: store [[TEST29]]* [[T3]], [[TEST29]]** [[SELF]], align |
| 756 | // CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST29]]* [[T4]] to i8* |
| 757 | // CHECK-NEXT: call void @objc_release(i8* [[T5]]) |
| 758 | |
| 759 | // Return statement. |
| 760 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] |
| 761 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 762 | // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 763 | // CHECK-NEXT: store i32 1, i32* [[CLEANUP]] |
| 764 | |
| 765 | // Cleanup. |
| 766 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[ALLOCATOR]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 767 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 768 | |
| 769 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] |
| 770 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 771 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 772 | |
| 773 | // Return. |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 774 | // CHECK-NEXT: ret i8* [[RET]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 775 | self = [super initWithAllocator: allocator]; |
| 776 | return self; |
| 777 | } |
| 778 | @end |
| 779 | |
| 780 | typedef struct Test30_helper Test30_helper; |
| 781 | @interface Test30 |
| 782 | - (id) init; |
| 783 | - (Test30_helper*) initHelper; |
| 784 | @end |
| 785 | @implementation Test30 { |
| 786 | char *helper; |
| 787 | } |
| 788 | - (id) init { |
Bill Wendling | c0dcc2d | 2013-02-15 21:30:01 +0000 | [diff] [blame] | 789 | // CHECK: define internal i8* @"\01-[Test30 init]"([[TEST30:%[^*]*]]* {{%.*}}, |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 790 | // CHECK: [[RET:%.*]] = alloca [[TEST30]]* |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 791 | // CHECK-NEXT: alloca i8* |
| 792 | // CHECK-NEXT: alloca i32 |
| 793 | // CHECK-NEXT: store [[TEST30]]* {{%.*}}, [[TEST30]]** [[SELF]] |
| 794 | // CHECK-NEXT: store |
| 795 | |
| 796 | // Call. |
| 797 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] |
| 798 | // CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 799 | // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* |
| 800 | // CHECK-NEXT: [[CALL:%.*]] = call [[TEST30_HELPER:%.*]]* bitcast {{.*}} @objc_msgSend {{.*}}(i8* [[T2]], i8* [[T1]]) |
| 801 | |
| 802 | // Assignment. |
| 803 | // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST30_HELPER]]* [[CALL]] to i8* |
| 804 | // CHECK-NEXT: [[T1:%.*]] = load [[TEST30]]** [[SELF]] |
| 805 | // CHECK-NEXT: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Test30.helper" |
| 806 | // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T1]] to i8* |
| 807 | // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[IVAR]] |
| 808 | // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** |
| 809 | // CHECK-NEXT#: [[T5:%.*]] = load i8** [[T4]] |
| 810 | // CHECK-NEXT#: [[T6:%.*]] = call i8* @objc_retain(i8* [[T0]]) |
| 811 | // CHECK-NEXT#: call void @objc_release(i8* [[T5]]) |
| 812 | // CHECK-NEXT: store i8* [[T0]], i8** [[T4]] |
| 813 | |
| 814 | // Return. |
| 815 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] |
| 816 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* |
Eli Friedman | 38ac243 | 2012-03-30 01:13:43 +0000 | [diff] [blame] | 817 | // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 818 | // CHECK-NEXT: store i32 1 |
| 819 | |
| 820 | // Cleanup. |
| 821 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] |
| 822 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* |
| 823 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
| 824 | |
| 825 | // Epilogue. |
John McCall | f48f796 | 2012-01-29 02:35:02 +0000 | [diff] [blame] | 826 | // CHECK-NEXT: ret i8* [[RET]] |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 827 | self->helper = [self initHelper]; |
| 828 | return self; |
| 829 | } |
| 830 | - (Test30_helper*) initHelper { |
| 831 | // CHECK: define internal [[TEST30_HELPER]]* @"\01-[Test30 initHelper]"( |
| 832 | // CHECK: alloca |
| 833 | // CHECK-NEXT: alloca |
| 834 | // CHECK-NEXT: store |
| 835 | // CHECK-NEXT: store |
| 836 | // CHECK-NEXT: ret [[TEST30_HELPER]]* null |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | @end |
| 841 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 842 | __attribute__((ns_returns_retained)) id test32(void) { |
| 843 | // CHECK: define i8* @test32() |
| 844 | // CHECK: [[CALL:%.*]] = call i8* @test32_helper() |
| 845 | // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) |
| 846 | // CHECK-NEXT: ret i8* [[T0]] |
| 847 | extern id test32_helper(void); |
| 848 | return test32_helper(); |
| 849 | } |
| 850 | |
| 851 | @class Test33_a; |
| 852 | @interface Test33 |
| 853 | - (void) give: (Test33_a **) x; |
| 854 | - (void) take: (Test33_a **) x; |
| 855 | - (void) giveStrong: (out __strong Test33_a **) x; |
| 856 | - (void) takeStrong: (inout __strong Test33_a **) x; |
| 857 | - (void) giveOut: (out Test33_a **) x; |
| 858 | @end |
| 859 | void test33(Test33 *ptr) { |
| 860 | Test33_a *a; |
| 861 | [ptr give: &a]; |
| 862 | [ptr take: &a]; |
| 863 | [ptr giveStrong: &a]; |
| 864 | [ptr takeStrong: &a]; |
| 865 | [ptr giveOut: &a]; |
| 866 | |
| 867 | // CHECK: define void @test33([[TEST33:%.*]]* |
| 868 | // CHECK: [[PTR:%.*]] = alloca [[TEST33]]* |
| 869 | // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]]* |
| 870 | // CHECK-NEXT: [[TEMP0:%.*]] = alloca [[A_T]]* |
| 871 | // CHECK-NEXT: [[TEMP1:%.*]] = alloca [[A_T]]* |
| 872 | // CHECK-NEXT: [[TEMP2:%.*]] = alloca [[A_T]]* |
| 873 | // CHECK-NEXT: bitcast |
| 874 | // CHECK-NEXT: objc_retain |
| 875 | // CHECK-NEXT: bitcast |
| 876 | // CHECK-NEXT: store |
| 877 | // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[A]] |
| 878 | |
| 879 | // CHECK-NEXT: load [[TEST33]]** [[PTR]] |
| 880 | // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]] |
| 881 | // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP0]] |
| 882 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 883 | // CHECK-NEXT: bitcast |
| 884 | // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP0]]) |
| 885 | // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP0]] |
| 886 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* |
| 887 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) |
| 888 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* |
| 889 | // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] |
| 890 | // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] |
| 891 | // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* |
| 892 | // CHECK-NEXT: call void @objc_release(i8* [[T5]]) |
| 893 | |
| 894 | // CHECK-NEXT: load [[TEST33]]** [[PTR]] |
| 895 | // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]] |
| 896 | // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP1]] |
| 897 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 898 | // CHECK-NEXT: bitcast |
| 899 | // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP1]]) |
| 900 | // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP1]] |
| 901 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* |
| 902 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) |
| 903 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* |
| 904 | // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] |
| 905 | // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] |
| 906 | // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* |
| 907 | // CHECK-NEXT: call void @objc_release(i8* [[T5]]) |
| 908 | |
| 909 | // CHECK-NEXT: load [[TEST33]]** [[PTR]] |
| 910 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 911 | // CHECK-NEXT: bitcast |
| 912 | // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) |
| 913 | |
| 914 | // CHECK-NEXT: load [[TEST33]]** [[PTR]] |
| 915 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 916 | // CHECK-NEXT: bitcast |
| 917 | // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) |
| 918 | |
| 919 | // 'out' |
| 920 | // CHECK-NEXT: load [[TEST33]]** [[PTR]] |
| 921 | // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[TEMP2]] |
| 922 | // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 923 | // CHECK-NEXT: bitcast |
| 924 | // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP2]]) |
| 925 | // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP2]] |
| 926 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* |
| 927 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) |
| 928 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* |
| 929 | // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] |
| 930 | // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] |
| 931 | // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* |
| 932 | // CHECK-NEXT: call void @objc_release(i8* [[T5]]) |
| 933 | |
| 934 | // CHECK-NEXT: load |
| 935 | // CHECK-NEXT: bitcast |
| 936 | // CHECK-NEXT: objc_release |
| 937 | // CHECK-NEXT: load |
| 938 | // CHECK-NEXT: bitcast |
| 939 | // CHECK-NEXT: objc_release |
| 940 | // CHECK-NEXT: ret void |
| 941 | } |
| 942 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 943 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 944 | // CHECK: define void @test36 |
| 945 | void test36(id x) { |
| 946 | // CHECK: [[X:%.*]] = alloca i8* |
| 947 | |
| 948 | // CHECK: call i8* @objc_retain |
| 949 | // CHECK: call i8* @objc_retain |
| 950 | // CHECK: call i8* @objc_retain |
| 951 | id array[3] = { @"A", x, @"y" }; |
| 952 | |
| 953 | // CHECK: [[T0:%.*]] = load i8** [[X]] |
| 954 | // CHECK-NEXT: store i8* null, i8** [[X]] |
| 955 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
| 956 | x = 0; |
| 957 | |
| 958 | // CHECK: br label |
| 959 | // CHECK: call void @objc_release |
John McCall | bdc4d80 | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 960 | // CHECK: br i1 |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 961 | |
| 962 | // CHECK: call void @objc_release |
| 963 | // CHECK-NEXT: ret void |
| 964 | } |
| 965 | |
| 966 | @class Test37; |
| 967 | void test37(void) { |
| 968 | extern void test37_helper(id *); |
| 969 | Test37 *var; |
| 970 | test37_helper(&var); |
| 971 | |
| 972 | // CHECK: define void @test37() |
| 973 | // CHECK: [[VAR:%.*]] = alloca [[TEST37:%.*]]*, |
| 974 | // CHECK-NEXT: [[TEMP:%.*]] = alloca i8* |
| 975 | // CHECK-NEXT: store [[TEST37]]* null, [[TEST37]]** [[VAR]] |
| 976 | |
| 977 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]] |
| 978 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8* |
| 979 | // CHECK-NEXT: store i8* [[T1]], i8** [[TEMP]] |
| 980 | // CHECK-NEXT: call void @test37_helper(i8** [[TEMP]]) |
| 981 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP]] |
| 982 | // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST37]]* |
| 983 | // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST37]]* [[T1]] to i8* |
| 984 | // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) |
| 985 | // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST37]]* |
| 986 | // CHECK-NEXT: [[T5:%.*]] = load [[TEST37]]** [[VAR]] |
| 987 | // CHECK-NEXT: store [[TEST37]]* [[T4]], [[TEST37]]** [[VAR]] |
| 988 | // CHECK-NEXT: [[T6:%.*]] = bitcast [[TEST37]]* [[T5]] to i8* |
| 989 | // CHECK-NEXT: call void @objc_release(i8* [[T6]]) |
| 990 | |
| 991 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]] |
| 992 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8* |
| 993 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
| 994 | // CHECK-NEXT: ret void |
| 995 | } |
| 996 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 997 | @interface Test43 @end |
| 998 | @implementation Test43 |
| 999 | - (id) test __attribute__((ns_returns_retained)) { |
| 1000 | extern id test43_produce(void); |
| 1001 | return test43_produce(); |
| 1002 | // CHECK: call i8* @test43_produce() |
| 1003 | // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue( |
| 1004 | // CHECK-NEXT: ret |
| 1005 | } |
| 1006 | @end |
| 1007 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1008 | @interface Test45 |
| 1009 | @property (retain) id x; |
| 1010 | @end |
| 1011 | @implementation Test45 |
| 1012 | @synthesize x; |
| 1013 | @end |
| 1014 | // CHECK: define internal i8* @"\01-[Test45 x]"( |
| 1015 | // CHECK: [[CALL:%.*]] = call i8* @objc_getProperty( |
| 1016 | // CHECK-NEXT: ret i8* [[CALL]] |
| 1017 | |
| 1018 | // rdar://problem/9315552 |
| 1019 | void test46(__weak id *wp, __weak volatile id *wvp) { |
| 1020 | extern id test46_helper(void); |
| 1021 | |
| 1022 | // TODO: this is sub-optimal, we should retain at the actual call site. |
| 1023 | |
| 1024 | // CHECK: [[T0:%.*]] = call i8* @test46_helper() |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 1025 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1026 | // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 |
| 1027 | // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) |
| 1028 | // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) |
| 1029 | // CHECK-NEXT: store i8* [[T4]], i8** |
| 1030 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1031 | id x = *wp = test46_helper(); |
| 1032 | |
| 1033 | // CHECK: [[T0:%.*]] = call i8* @test46_helper() |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 1034 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1035 | // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 |
| 1036 | // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) |
| 1037 | // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) |
| 1038 | // CHECK-NEXT: store i8* [[T4]], i8** |
| 1039 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1040 | id y = *wvp = test46_helper(); |
| 1041 | } |
| 1042 | |
| 1043 | // rdar://problem/9378887 |
| 1044 | void test47(void) { |
| 1045 | extern id test47_helper(void); |
| 1046 | id x = x = test47_helper(); |
| 1047 | |
| 1048 | // CHECK: define void @test47() |
| 1049 | // CHECK: [[X:%.*]] = alloca i8* |
| 1050 | // CHECK-NEXT: store i8* null, i8** [[X]] |
| 1051 | // CHECK-NEXT: [[CALL:%.*]] = call i8* @test47_helper() |
| 1052 | // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) |
| 1053 | // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] |
| 1054 | // CHECK-NEXT: store i8* [[T0]], i8** [[X]] |
| 1055 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
| 1056 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T0]]) |
| 1057 | // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] |
| 1058 | // CHECK-NEXT: store i8* [[T2]], i8** [[X]] |
| 1059 | // CHECK-NEXT: call void @objc_release(i8* [[T3]]) |
| 1060 | // CHECK-NEXT: [[T4:%.*]] = load i8** [[X]] |
| 1061 | // CHECK-NEXT: call void @objc_release(i8* [[T4]]) |
| 1062 | // CHECK-NEXT: ret void |
| 1063 | } |
| 1064 | |
| 1065 | void test48(void) { |
| 1066 | extern id test48_helper(void); |
| 1067 | __weak id x = x = test48_helper(); |
| 1068 | // CHECK: define void @test48() |
| 1069 | // CHECK: [[X:%.*]] = alloca i8* |
| 1070 | // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_initWeak(i8** [[X]], i8* null) |
| 1071 | // CHECK-NEXT: [[T1:%.*]] = call i8* @test48_helper() |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 1072 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1073 | // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T2]]) |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 1074 | // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T3]]) |
| 1075 | // CHECK-NEXT: call void @objc_release(i8* [[T2]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1076 | // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) |
| 1077 | // CHECK-NEXT: ret void |
| 1078 | } |
| 1079 | |
| 1080 | void test49(void) { |
| 1081 | extern id test49_helper(void); |
| 1082 | __autoreleasing id x = x = test49_helper(); |
| 1083 | // CHECK: define void @test49() |
| 1084 | // CHECK: [[X:%.*]] = alloca i8* |
| 1085 | // CHECK-NEXT: store i8* null, i8** [[X]] |
| 1086 | // CHECK-NEXT: [[CALL:%.*]] = call i8* @test49_helper() |
| 1087 | // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) |
| 1088 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autorelease(i8* [[T0]]) |
| 1089 | // CHECK-NEXT: store i8* [[T2]], i8** [[X]] |
| 1090 | // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]]) |
| 1091 | // CHECK-NEXT: store i8* [[T3]], i8** [[X]] |
| 1092 | // CHECK-NEXT: ret void |
| 1093 | } |
| 1094 | |
| 1095 | // rdar://9380136 |
| 1096 | id x(); |
| 1097 | void test50(id y) { |
| 1098 | ({x();}); |
| 1099 | // CHECK: [[T0:%.*]] = call i8* @objc_retain |
| 1100 | // CHECK: call void @objc_release |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | // rdar://9400762 |
| 1105 | struct CGPoint { |
| 1106 | float x; |
| 1107 | float y; |
| 1108 | }; |
| 1109 | typedef struct CGPoint CGPoint; |
| 1110 | |
| 1111 | @interface Foo |
| 1112 | @property (assign) CGPoint point; |
| 1113 | @end |
| 1114 | |
| 1115 | @implementation Foo |
| 1116 | @synthesize point; |
| 1117 | @end |
| 1118 | |
| 1119 | // rdar://problem/9400398 |
| 1120 | id test52(void) { |
| 1121 | id test52_helper(int) __attribute__((ns_returns_retained)); |
| 1122 | return ({ int x = 5; test52_helper(x); }); |
| 1123 | |
| 1124 | // CHECK: define i8* @test52() |
| 1125 | // CHECK: [[X:%.*]] = alloca i32 |
| 1126 | // CHECK-NEXT: store i32 5, i32* [[X]], |
| 1127 | // CHECK-NEXT: [[T0:%.*]] = load i32* [[X]], |
| 1128 | // CHECK-NEXT: [[T1:%.*]] = call i8* @test52_helper(i32 [[T0]]) |
Chad Rosier | df76f1e | 2012-12-12 17:52:21 +0000 | [diff] [blame] | 1129 | // CHECK-NEXT: [[T2:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T1]]) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1130 | // CHECK-NEXT: ret i8* [[T2]] |
| 1131 | } |
| 1132 | |
| 1133 | // rdar://problem/9400644 |
| 1134 | void test53(void) { |
| 1135 | id test53_helper(void); |
| 1136 | id x = ({ id y = test53_helper(); y; }); |
| 1137 | (void) x; |
| 1138 | // CHECK: define void @test53() |
| 1139 | // CHECK: [[X:%.*]] = alloca i8*, |
| 1140 | // CHECK-NEXT: [[Y:%.*]] = alloca i8*, |
| 1141 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test53_helper() |
| 1142 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1143 | // CHECK-NEXT: store i8* [[T1]], i8** [[Y]], |
| 1144 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]], |
| 1145 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) |
| 1146 | // CHECK-NEXT: [[T2:%.*]] = load i8** [[Y]] |
| 1147 | // CHECK-NEXT: call void @objc_release(i8* [[T2]]) |
| 1148 | // CHECK-NEXT: store i8* [[T1]], i8** [[X]], |
| 1149 | // CHECK-NEXT: load i8** [[X]], |
| 1150 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] |
| 1151 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
| 1152 | // CHECK-NEXT: ret void |
| 1153 | } |
Douglas Gregor | f96e904 | 2011-07-12 17:28:52 +0000 | [diff] [blame] | 1154 | |
| 1155 | // <rdar://problem/9758798> |
| 1156 | // CHECK: define void @test54(i32 %first, ...) |
| 1157 | void test54(int first, ...) { |
| 1158 | __builtin_va_list arglist; |
| 1159 | // CHECK: call void @llvm.va_start |
| 1160 | __builtin_va_start(arglist, first); |
| 1161 | // CHECK: call i8* @objc_retain |
| 1162 | id obj = __builtin_va_arg(arglist, id); |
| 1163 | // CHECK: call void @llvm.va_end |
| 1164 | __builtin_va_end(arglist); |
| 1165 | // CHECK: call void @objc_release |
| 1166 | // CHECK: ret void |
| 1167 | } |
John McCall | 799d34e | 2011-07-13 18:26:47 +0000 | [diff] [blame] | 1168 | |
| 1169 | // PR10228 |
| 1170 | @interface Test55Base @end |
| 1171 | @interface Test55 : Test55Base @end |
| 1172 | @implementation Test55 (Category) |
| 1173 | - (void) dealloc {} |
| 1174 | @end |
| 1175 | // CHECK: define internal void @"\01-[Test55(Category) dealloc]"( |
| 1176 | // CHECK-NOT: ret |
| 1177 | // CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)( |
John McCall | 6c2c250 | 2011-07-22 02:45:48 +0000 | [diff] [blame] | 1178 | |
| 1179 | // rdar://problem/8024350 |
| 1180 | @protocol Test56Protocol |
| 1181 | + (id) make __attribute__((ns_returns_retained)); |
| 1182 | @end |
| 1183 | @interface Test56<Test56Protocol> @end |
| 1184 | @implementation Test56 |
| 1185 | // CHECK: define internal i8* @"\01+[Test56 make]"( |
| 1186 | + (id) make { |
| 1187 | extern id test56_helper(void); |
| 1188 | // CHECK: [[T0:%.*]] = call i8* @test56_helper() |
| 1189 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1190 | // CHECK-NEXT: ret i8* [[T1]] |
| 1191 | return test56_helper(); |
| 1192 | } |
| 1193 | @end |
| 1194 | void test56_test(void) { |
| 1195 | id x = [Test56 make]; |
| 1196 | // CHECK: define void @test56_test() |
| 1197 | // CHECK: [[X:%.*]] = alloca i8*, align 8 |
| 1198 | // CHECK: [[T0:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)( |
| 1199 | // CHECK-NEXT: store i8* [[T0]], i8** [[X]] |
| 1200 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] |
| 1201 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
| 1202 | // CHECK-NEXT: ret void |
| 1203 | } |
John McCall | ba3dd90 | 2011-07-22 05:23:13 +0000 | [diff] [blame] | 1204 | |
| 1205 | // rdar://problem/9784964 |
| 1206 | @interface Test57 |
| 1207 | @property (nonatomic, strong) id strong; |
| 1208 | @property (nonatomic, weak) id weak; |
| 1209 | @property (nonatomic, unsafe_unretained) id unsafe; |
| 1210 | @end |
| 1211 | @implementation Test57 |
| 1212 | @synthesize strong, weak, unsafe; |
| 1213 | @end |
| 1214 | // CHECK: define internal i8* @"\01-[Test57 strong]"( |
| 1215 | // CHECK: [[T0:%.*]] = load [[TEST57:%.*]]** {{%.*}} |
| 1216 | // CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.strong" |
| 1217 | // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8* |
| 1218 | // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] |
| 1219 | // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** |
| 1220 | // CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]] |
| 1221 | // CHECK-NEXT: ret i8* [[T5]] |
| 1222 | |
| 1223 | // CHECK: define internal i8* @"\01-[Test57 weak]"( |
| 1224 | // CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}} |
| 1225 | // CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.weak" |
| 1226 | // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8* |
| 1227 | // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] |
| 1228 | // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** |
| 1229 | // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T4]]) |
Chad Rosier | df76f1e | 2012-12-12 17:52:21 +0000 | [diff] [blame] | 1230 | // CHECK-NEXT: [[T6:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T5]]) |
John McCall | ba3dd90 | 2011-07-22 05:23:13 +0000 | [diff] [blame] | 1231 | // CHECK-NEXT: ret i8* [[T6]] |
| 1232 | |
| 1233 | // CHECK: define internal i8* @"\01-[Test57 unsafe]"( |
| 1234 | // CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}} |
| 1235 | // CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.unsafe" |
| 1236 | // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8* |
| 1237 | // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] |
| 1238 | // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** |
| 1239 | // CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]] |
| 1240 | // CHECK-NEXT: ret i8* [[T5]] |
| 1241 | |
John McCall | dc7c5ad | 2011-07-22 08:53:00 +0000 | [diff] [blame] | 1242 | // rdar://problem/9821110 |
| 1243 | @interface Test58 |
| 1244 | - (char*) interior __attribute__((objc_returns_inner_pointer)); |
| 1245 | // Should we allow this on properties? |
| 1246 | @end |
| 1247 | extern Test58 *test58_helper(void); |
| 1248 | |
| 1249 | // CHECK: define void @test58a() |
| 1250 | void test58a(void) { |
| 1251 | // CHECK: [[T0:%.*]] = call [[TEST58:%.*]]* @test58_helper() |
| 1252 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8* |
| 1253 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) |
| 1254 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]* |
| 1255 | // CHECK-NEXT: store [[TEST58]]* [[T3]] |
| 1256 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]** |
| 1257 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8* |
| 1258 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]]) |
| 1259 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]* |
| 1260 | // CHECK-NEXT: [[T4:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 1261 | // CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST58]]* [[T3]] to i8* |
| 1262 | // CHECK-NEXT: [[T6:%.*]] = call i8* bitcast |
| 1263 | // CHECK-NEXT: store i8* [[T6]], i8** |
| 1264 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]** |
| 1265 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 1266 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release |
John McCall | dc7c5ad | 2011-07-22 08:53:00 +0000 | [diff] [blame] | 1267 | // CHECK-NEXT: ret void |
| 1268 | Test58 *ptr = test58_helper(); |
| 1269 | char *c = [(ptr) interior]; |
| 1270 | } |
| 1271 | |
| 1272 | // CHECK: define void @test58b() |
| 1273 | void test58b(void) { |
| 1274 | // CHECK: [[T0:%.*]] = call [[TEST58:%.*]]* @test58_helper() |
| 1275 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8* |
| 1276 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) |
| 1277 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]* |
| 1278 | // CHECK-NEXT: store [[TEST58]]* [[T3]] |
| 1279 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]** |
| 1280 | // CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 1281 | // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST58]]* [[T0]] to i8* |
| 1282 | // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast |
| 1283 | // CHECK-NEXT: store i8* [[T3]], i8** |
| 1284 | // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]** |
| 1285 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8* |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 1286 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]] |
John McCall | dc7c5ad | 2011-07-22 08:53:00 +0000 | [diff] [blame] | 1287 | // CHECK-NOT: clang.imprecise_release |
| 1288 | // CHECK-NEXT: ret void |
| 1289 | __attribute__((objc_precise_lifetime)) Test58 *ptr = test58_helper(); |
| 1290 | char *c = [ptr interior]; |
| 1291 | } |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1292 | |
| 1293 | // rdar://problem/9842343 |
| 1294 | void test59(void) { |
| 1295 | extern id test59_getlock(void); |
| 1296 | extern void test59_body(void); |
| 1297 | @synchronized (test59_getlock()) { |
| 1298 | test59_body(); |
| 1299 | } |
| 1300 | |
| 1301 | // CHECK: define void @test59() |
| 1302 | // CHECK: [[T0:%.*]] = call i8* @test59_getlock() |
| 1303 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
Aaron Ballman | 2d234d73 | 2012-09-06 16:44:16 +0000 | [diff] [blame] | 1304 | // CHECK-NEXT: call i32 @objc_sync_enter(i8* [[T1]]) |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1305 | // CHECK-NEXT: call void @test59_body() |
Aaron Ballman | 2d234d73 | 2012-09-06 16:44:16 +0000 | [diff] [blame] | 1306 | // CHECK-NEXT: call i32 @objc_sync_exit(i8* [[T1]]) |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1307 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
| 1308 | // CHECK-NEXT: ret void |
| 1309 | } |
John McCall | fb72081 | 2011-07-28 07:23:35 +0000 | [diff] [blame] | 1310 | |
John McCall | fc4b191 | 2011-08-03 07:02:44 +0000 | [diff] [blame] | 1311 | // Verify that we don't try to reclaim the result of performSelector. |
| 1312 | // rdar://problem/9887545 |
| 1313 | @interface Test61 |
| 1314 | - (id) performSelector: (SEL) selector; |
| 1315 | - (void) test61_void; |
| 1316 | - (id) test61_id; |
| 1317 | @end |
| 1318 | void test61(void) { |
| 1319 | // CHECK: define void @test61() |
| 1320 | // CHECK: [[Y:%.*]] = alloca i8*, align 8 |
| 1321 | |
| 1322 | extern id test61_make(void); |
| 1323 | |
| 1324 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make() |
| 1325 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1326 | // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 1327 | // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 1328 | // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]]) |
| 1329 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
| 1330 | [test61_make() performSelector: @selector(test61_void)]; |
| 1331 | |
| 1332 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make() |
| 1333 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1334 | // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 1335 | // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ |
| 1336 | // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]]) |
| 1337 | // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]]) |
| 1338 | // CHECK-NEXT: store i8* [[T5]], i8** [[Y]] |
| 1339 | // CHECK-NEXT: call void @objc_release(i8* [[T1]]) |
| 1340 | id y = [test61_make() performSelector: @selector(test61_id)]; |
| 1341 | |
| 1342 | // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] |
| 1343 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
| 1344 | // CHECK-NEXT: ret void |
| 1345 | } |
John McCall | bddfd87 | 2011-08-03 22:24:24 +0000 | [diff] [blame] | 1346 | |
| 1347 | // rdar://problem/9891815 |
| 1348 | void test62(void) { |
| 1349 | // CHECK: define void @test62() |
| 1350 | // CHECK: [[I:%.*]] = alloca i32, align 4 |
| 1351 | // CHECK-NEXT: [[CLEANUP_VALUE:%.*]] = alloca i8* |
| 1352 | // CHECK-NEXT: [[CLEANUP_REQUIRED:%.*]] = alloca i1 |
| 1353 | extern id test62_make(void); |
| 1354 | extern void test62_body(void); |
| 1355 | |
| 1356 | // CHECK-NEXT: store i32 0, i32* [[I]], align 4 |
| 1357 | // CHECK-NEXT: br label |
| 1358 | |
| 1359 | // CHECK: [[T0:%.*]] = load i32* [[I]], align 4 |
| 1360 | // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 20 |
| 1361 | // CHECK-NEXT: br i1 [[T1]], |
| 1362 | |
| 1363 | for (unsigned i = 0; i != 20; ++i) { |
| 1364 | // CHECK: [[T0:%.*]] = load i32* [[I]], align 4 |
| 1365 | // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 |
| 1366 | // CHECK-NEXT: store i1 false, i1* [[CLEANUP_REQUIRED]] |
| 1367 | // CHECK-NEXT: br i1 [[T1]], |
| 1368 | // CHECK: [[T0:%.*]] = call i8* @test62_make() |
| 1369 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1370 | // CHECK-NEXT: store i8* [[T1]], i8** [[CLEANUP_VALUE]] |
| 1371 | // CHECK-NEXT: store i1 true, i1* [[CLEANUP_REQUIRED]] |
| 1372 | // CHECK-NEXT: [[T2:%.*]] = icmp ne i8* [[T1]], null |
| 1373 | // CHECK-NEXT: br label |
| 1374 | // CHECK: [[COND:%.*]] = phi i1 [ false, {{%.*}} ], [ [[T2]], {{%.*}} ] |
| 1375 | // CHECK-NEXT: [[T0:%.*]] = load i1* [[CLEANUP_REQUIRED]] |
| 1376 | // CHECK-NEXT: br i1 [[T0]], |
| 1377 | // CHECK: [[T0:%.*]] = load i8** [[CLEANUP_VALUE]] |
| 1378 | // CHECK-NEXT: call void @objc_release(i8* [[T0]]) |
| 1379 | // CHECK-NEXT: br label |
| 1380 | // CHECK: br i1 [[COND]] |
| 1381 | // CHECK: call void @test62_body() |
| 1382 | // CHECK-NEXT: br label |
| 1383 | // CHECK: br label |
| 1384 | if (i != 0 && test62_make() != 0) |
| 1385 | test62_body(); |
| 1386 | } |
| 1387 | |
| 1388 | // CHECK: [[T0:%.*]] = load i32* [[I]], align 4 |
| 1389 | // CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], 1 |
| 1390 | // CHECK-NEXT: store i32 [[T1]], i32* [[I]] |
| 1391 | // CHECK-NEXT: br label |
| 1392 | |
| 1393 | // CHECK: ret void |
| 1394 | } |
Fariborz Jahanian | bc03aea | 2011-08-19 19:28:44 +0000 | [diff] [blame] | 1395 | |
| 1396 | // rdar://9971982 |
| 1397 | @class NSString; |
| 1398 | |
| 1399 | @interface Person { |
| 1400 | NSString *name; |
| 1401 | } |
| 1402 | @property NSString *address; |
| 1403 | @end |
| 1404 | |
| 1405 | @implementation Person |
| 1406 | @synthesize address; |
| 1407 | @end |
| 1408 | // CHECK: call i8* @objc_getProperty |
| 1409 | // CHECK: call void @objc_setProperty |
| 1410 | |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 1411 | // Verify that we successfully parse and preserve this attribute in |
| 1412 | // this position. |
| 1413 | @interface Test66 |
| 1414 | - (void) consume: (id __attribute__((ns_consumed))) ptr; |
| 1415 | @end |
| 1416 | void test66(void) { |
| 1417 | extern Test66 *test66_receiver(void); |
| 1418 | extern id test66_arg(void); |
| 1419 | [test66_receiver() consume: test66_arg()]; |
| 1420 | } |
| 1421 | // CHECK: define void @test66() |
| 1422 | // CHECK: [[T0:%.*]] = call [[TEST66:%.*]]* @test66_receiver() |
| 1423 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST66]]* [[T0]] to i8* |
| 1424 | // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) |
| 1425 | // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST66]]* |
Fariborz Jahanian | 4e1524b | 2012-01-29 20:27:13 +0000 | [diff] [blame] | 1426 | // CHECK-NEXT: [[T4:%.*]] = call i8* @test66_arg() |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 1427 | // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]]) |
| 1428 | // CHECK-NEXT: [[T6:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES |
| 1429 | // CHECK-NEXT: [[T7:%.*]] = bitcast [[TEST66]]* [[T3]] to i8* |
Fariborz Jahanian | 3c267e6 | 2012-01-30 21:40:37 +0000 | [diff] [blame] | 1430 | // CHECK-NEXT: [[SIX:%.*]] = icmp eq i8* [[T7]], null |
| 1431 | // CHECK-NEXT: br i1 [[SIX]], label [[NULINIT:%.*]], label [[CALL:%.*]] |
| 1432 | // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* [[T7]], i8* [[T6]], i8* [[T5]]) |
| 1433 | // CHECK-NEXT: br label [[CONT:%.*]] |
Bill Wendling | 4e1125f | 2013-02-22 09:10:20 +0000 | [diff] [blame] | 1434 | // CHECK: call void @objc_release(i8* [[T5]]) [[NUW]] |
Fariborz Jahanian | 3c267e6 | 2012-01-30 21:40:37 +0000 | [diff] [blame] | 1435 | // CHECK-NEXT: br label [[CONT:%.*]] |
| 1436 | // CHECK: [[T8:%.*]] = bitcast [[TEST66]]* [[T3]] to i8* |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 1437 | // CHECK-NEXT: call void @objc_release(i8* [[T8]]) |
| 1438 | // CHECK-NEXT: ret void |
John McCall | 567c586 | 2011-11-14 19:53:16 +0000 | [diff] [blame] | 1439 | |
| 1440 | // rdar://problem/9953540 |
| 1441 | Class test67_helper(void); |
| 1442 | void test67(void) { |
| 1443 | Class cl = test67_helper(); |
| 1444 | } |
| 1445 | // CHECK: define void @test67() |
| 1446 | // CHECK: [[CL:%.*]] = alloca i8*, align 8 |
| 1447 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper() |
| 1448 | // CHECK-NEXT: store i8* [[T0]], i8** [[CL]], align 8 |
| 1449 | // CHECK-NEXT: ret void |
| 1450 | |
| 1451 | Class test68_helper(void); |
| 1452 | void test68(void) { |
| 1453 | __strong Class cl = test67_helper(); |
| 1454 | } |
| 1455 | // CHECK: define void @test68() |
| 1456 | // CHECK: [[CL:%.*]] = alloca i8*, align 8 |
| 1457 | // CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper() |
| 1458 | // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) |
| 1459 | // CHECK-NEXT: store i8* [[T1]], i8** [[CL]], align 8 |
| 1460 | // CHECK-NEXT: [[T2:%.*]] = load i8** [[CL]] |
| 1461 | // CHECK-NEXT: call void @objc_release(i8* [[T2]]) |
| 1462 | // CHECK-NEXT: ret void |
John McCall | 77fe6cd | 2012-01-29 07:46:59 +0000 | [diff] [blame] | 1463 | |
| 1464 | // rdar://problem/10564852 |
| 1465 | @interface Test69 @end |
| 1466 | @implementation Test69 |
| 1467 | - (id) foo { return self; } |
| 1468 | @end |
| 1469 | // CHECK: define internal i8* @"\01-[Test69 foo]"( |
| 1470 | // CHECK: [[SELF:%.*]] = alloca [[TEST69:%.*]]*, align 8 |
| 1471 | // CHECK: [[T0:%.*]] = load [[TEST69]]** [[SELF]], align 8 |
| 1472 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST69]]* [[T0]] to i8* |
| 1473 | // CHECK-NEXT: ret i8* [[T1]] |
Eli Friedman | b1e3f32 | 2012-02-22 05:38:59 +0000 | [diff] [blame] | 1474 | |
| 1475 | // rdar://problem/10907547 |
| 1476 | void test70(id i) { |
| 1477 | // CHECK: define void @test70 |
| 1478 | // CHECK: store i8* null, i8** |
| 1479 | // CHECK: store i8* null, i8** |
| 1480 | // CHECK: [[ID:%.*]] = call i8* @objc_retain(i8* |
| 1481 | // CHECK: store i8* [[ID]], i8** |
| 1482 | id x[3] = { |
| 1483 | [2] = i |
| 1484 | }; |
| 1485 | } |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 1486 | |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame^] | 1487 | // ARC-ALIEN: attributes [[NLB]] = { nonlazybind } |
| 1488 | // ARC-NATIVE: attributes [[NLB]] = { nonlazybind } |