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