2011-04-30 05:53:21 +08:00
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -fblocks -triple x86_64-apple-darwin10 | FileCheck %s
|
|
|
|
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK: [[AGG:%.*]] = type { i32 }
|
|
|
|
typedef struct { int v; } Agg;
|
|
|
|
Agg makeAgg(void);
|
2011-04-30 05:53:21 +08:00
|
|
|
|
2012-07-03 07:58:38 +08:00
|
|
|
// When assigning into a __block variable, ensure that we compute that
|
|
|
|
// address *after* evaluating the RHS when the RHS has the capacity to
|
|
|
|
// cause a block copy. rdar://9309454
|
|
|
|
void test0() {
|
|
|
|
__block Agg a = {100};
|
2011-04-30 05:53:21 +08:00
|
|
|
|
2012-07-03 07:58:38 +08:00
|
|
|
a = makeAgg();
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test0()
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK: [[A:%.*]] = alloca [[BYREF:%.*]], align 8
|
|
|
|
// CHECK-NEXT: [[TEMP:%.*]] = alloca [[AGG]], align 4
|
|
|
|
// CHECK: [[RESULT:%.*]] = call i32 @makeAgg()
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr [[AGG]], [[AGG]]* [[TEMP]], i32 0, i32 0
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK-NEXT: store i32 [[RESULT]], i32* [[T0]]
|
|
|
|
// Check that we properly assign into the forwarding pointer.
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[A_FORWARDING:%.*]] = getelementptr inbounds [[BYREF]], [[BYREF]]* [[A]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[BYREF]]*, [[BYREF]]** [[A_FORWARDING]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[BYREF]], [[BYREF]]* [[T0]], i32 0, i32 4
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = bitcast [[AGG]]* [[T1]] to i8*
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = bitcast [[AGG]]* [[TEMP]] to i8*
|
|
|
|
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[T2]], i8* [[T3]], i64 4, i32 4, i1 false)
|
|
|
|
// Verify that there's nothing else significant in the function.
|
|
|
|
// CHECK-NEXT: [[T0:%.*]] = bitcast [[BYREF]]* [[A]] to i8*
|
|
|
|
// CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8)
|
|
|
|
// CHECK-NEXT: ret void
|
2011-04-30 05:53:21 +08:00
|
|
|
|
2012-07-03 07:58:38 +08:00
|
|
|
// When chaining assignments into __block variables, make sure we
|
|
|
|
// propagate the actual value into the outer variable.
|
|
|
|
// rdar://11757470
|
|
|
|
void test1() {
|
|
|
|
__block Agg a, b;
|
|
|
|
a = b = makeAgg();
|
2011-04-30 05:53:21 +08:00
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test1()
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK: [[A:%.*]] = alloca [[A_BYREF:%.*]], align 8
|
|
|
|
// CHECK-NEXT: [[B:%.*]] = alloca [[B_BYREF:%.*]], align 8
|
|
|
|
// CHECK-NEXT: [[TEMP:%.*]] = alloca [[AGG]], align 4
|
|
|
|
// CHECK: [[RESULT:%.*]] = call i32 @makeAgg()
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr [[AGG]], [[AGG]]* [[TEMP]], i32 0, i32 0
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK-NEXT: store i32 [[RESULT]], i32* [[T0]]
|
|
|
|
// Check that we properly assign into the forwarding pointer, first for b:
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[B_FORWARDING:%.*]] = getelementptr inbounds [[B_BYREF]], [[B_BYREF]]* [[B]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[B_BYREF]]*, [[B_BYREF]]** [[B_FORWARDING]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[B_BYREF]], [[B_BYREF]]* [[T0]], i32 0, i32 4
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = bitcast [[AGG]]* [[T1]] to i8*
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = bitcast [[AGG]]* [[TEMP]] to i8*
|
|
|
|
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[T2]], i8* [[T3]], i64 4, i32 4, i1 false)
|
|
|
|
// Then for 'a':
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[A_FORWARDING:%.*]] = getelementptr inbounds [[A_BYREF]], [[A_BYREF]]* [[A]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[A_BYREF]]*, [[A_BYREF]]** [[A_FORWARDING]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[A_BYREF]], [[A_BYREF]]* [[T0]], i32 0, i32 4
|
2012-07-03 07:58:38 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = bitcast [[AGG]]* [[T1]] to i8*
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = bitcast [[AGG]]* [[TEMP]] to i8*
|
|
|
|
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[T2]], i8* [[T3]], i64 4, i32 4, i1 false)
|
|
|
|
// Verify that there's nothing else significant in the function.
|
|
|
|
// CHECK-NEXT: [[T0:%.*]] = bitcast [[B_BYREF]]* [[B]] to i8*
|
|
|
|
// CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8)
|
|
|
|
// CHECK-NEXT: [[T0:%.*]] = bitcast [[A_BYREF]]* [[A]] to i8*
|
|
|
|
// CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8)
|
|
|
|
// CHECK-NEXT: ret void
|