1 // RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -emit-llvm %s -o %t-64.s 2 // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s 3 // rdar://9503326 4 // rdar://9606600 5 6 extern void use(id); 7 extern void use_block(void (^)(void)); 8 @class NSArray; 9 10 void test0(NSArray *array) { 11 // 'x' should be initialized without a retain. 12 // We should actually do a non-constant capture, and that 13 // capture should require a retain. 14 for (id x in array) { 15 use_block(^{ use(x); }); 16 } 17 } 18 19 // CHECK-LP64: define void @test0( 20 // CHECK-LP64: alloca [[ARRAY_T:%.*]]*, 21 // CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*, 22 // CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], 23 // CHECK-LP64-NEXT: alloca [16 x i8*], align 8 24 // CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], 25 26 // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1 27 // CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]] 28 // CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64 29 // CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]] 30 // CHECK-LP64-NEXT: store i8* [[T3]], i8** [[X]] 31 32 // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 33 // CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[X]] 34 // CHECK-LP64-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) 35 // CHECK-LP64-NEXT: store i8* [[T2]], i8** [[T0]] 36 // CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] 37 // CHECK-LP64: call void @use_block( 38 // CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[T0]] 39 // CHECK-LP64-NEXT: call void @objc_release(i8* [[T1]]) 40 41 // CHECK-LP64: define internal void @__test0_block_invoke 42 // CHECK-LP64: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]* 43 // CHECK-LP64-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 44 // CHECK-LP64-NEXT: [[T2:%.*]] = load i8** [[T0]], align 8 45 // CHECK-LP64-NEXT: call void @use(i8* [[T2]]) 46 47 void test1(NSArray *array) { 48 for (__weak id x in array) { 49 use_block(^{ use(x); }); 50 } 51 } 52 53 // CHECK-LP64: define void @test1( 54 // CHECK-LP64: alloca [[ARRAY_T:%.*]]*, 55 // CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*, 56 // CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], 57 // CHECK-LP64-NEXT: alloca [16 x i8*], align 8 58 // CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], 59 60 // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1 61 // CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]] 62 // CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64 63 // CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]] 64 // CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T3]]) 65 66 // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 67 // CHECK-LP64-NEXT: [[T1:%.*]] = call i8* @objc_loadWeak(i8** [[X]]) 68 // CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[T0]], i8* [[T1]]) 69 // CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to 70 // CHECK-LP64: call void @use_block 71 // CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[T0]]) 72 // CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[X]]) 73