2011-07-06 08:26:06 +08:00
|
|
|
// 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
|
2011-06-16 07:02:42 +08:00
|
|
|
// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
|
|
|
|
// rdar://9503326
|
2011-06-17 14:42:21 +08:00
|
|
|
// rdar://9606600
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2011-06-17 14:42:21 +08:00
|
|
|
extern void use(id);
|
|
|
|
extern void use_block(void (^)(void));
|
2011-06-16 07:02:42 +08:00
|
|
|
@class NSArray;
|
|
|
|
|
2011-06-17 14:42:21 +08:00
|
|
|
void test0(NSArray *array) {
|
|
|
|
// 'x' should be initialized without a retain.
|
|
|
|
// We should actually do a non-constant capture, and that
|
|
|
|
// capture should require a retain.
|
|
|
|
for (id x in array) {
|
|
|
|
use_block(^{ use(x); });
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
}
|
|
|
|
|
2011-06-17 14:42:21 +08:00
|
|
|
// CHECK-LP64: define void @test0(
|
|
|
|
// CHECK-LP64: alloca [[ARRAY_T:%.*]]*,
|
|
|
|
// CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*,
|
|
|
|
// CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]],
|
|
|
|
// CHECK-LP64-NEXT: alloca [16 x i8*], align 8
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]],
|
2011-06-17 14:42:21 +08:00
|
|
|
|
|
|
|
// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1
|
|
|
|
// CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]]
|
|
|
|
// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64
|
|
|
|
// CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]]
|
|
|
|
// CHECK-LP64-NEXT: store i8* [[T3]], i8** [[X]]
|
|
|
|
|
|
|
|
// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
|
|
|
|
// CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[X]]
|
|
|
|
// CHECK-LP64-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
|
|
|
|
// CHECK-LP64-NEXT: store i8* [[T2]], i8** [[T0]]
|
2011-07-10 11:47:27 +08:00
|
|
|
// CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]]
|
|
|
|
// CHECK-LP64-NEXT: call void @use_block({{.*}}* [[T1]])
|
2011-06-17 14:42:21 +08:00
|
|
|
// CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[T0]]
|
|
|
|
// CHECK-LP64-NEXT: call void @objc_release(i8* [[T1]])
|
|
|
|
|
|
|
|
// CHECK-LP64: define internal void @__test0_block_invoke
|
|
|
|
// CHECK-LP64: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]*
|
2011-06-16 07:02:42 +08:00
|
|
|
// CHECK-LP64-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
|
2011-06-17 14:42:21 +08:00
|
|
|
// CHECK-LP64-NEXT: [[T2:%.*]] = load i8** [[T0]], align 8
|
|
|
|
// CHECK-LP64-NEXT: call void @use(i8* [[T2]])
|
|
|
|
|
|
|
|
void test1(NSArray *array) {
|
|
|
|
for (__weak id x in array) {
|
|
|
|
use_block(^{ use(x); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LP64: define void @test1(
|
|
|
|
// CHECK-LP64: alloca [[ARRAY_T:%.*]]*,
|
|
|
|
// CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*,
|
|
|
|
// CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]],
|
|
|
|
// CHECK-LP64-NEXT: alloca [16 x i8*], align 8
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]],
|
2011-06-17 14:42:21 +08:00
|
|
|
|
|
|
|
// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1
|
|
|
|
// CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]]
|
|
|
|
// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64
|
|
|
|
// CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]]
|
|
|
|
// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T3]])
|
|
|
|
|
|
|
|
// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
|
|
|
|
// CHECK-LP64-NEXT: [[T1:%.*]] = call i8* @objc_loadWeak(i8** [[X]])
|
|
|
|
// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[T0]], i8* [[T1]])
|
2011-07-10 11:47:27 +08:00
|
|
|
// CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to
|
|
|
|
// CHECK-LP64-NEXT: call void @use_block({{.*}} [[T1]])
|
2011-06-17 14:42:21 +08:00
|
|
|
// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[T0]])
|
|
|
|
// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[X]])
|