1 // RUN: %clang_cc1 %s -emit-llvm -o - -fblocks -triple x86_64-apple-darwin10 | FileCheck %s 2 3 // CHECK: [[AGG:%.*]] = type { i32 } 4 typedef struct { int v; } Agg; 5 Agg makeAgg(void); 6 7 // When assigning into a __block variable, ensure that we compute that 8 // address *after* evaluating the RHS when the RHS has the capacity to 9 // cause a block copy. rdar://9309454 10 void test0() { 11 __block Agg a = {100}; 12 13 a = makeAgg(); 14 } 15 // CHECK-LABEL: define void @test0() 16 // CHECK: [[A:%.*]] = alloca [[BYREF:%.*]], align 8 17 // CHECK-NEXT: [[TEMP:%.*]] = alloca [[AGG]], align 4 18 // CHECK: [[RESULT:%.*]] = call i32 @makeAgg() 19 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[TEMP]], i32 0, i32 0 20 // CHECK-NEXT: store i32 [[RESULT]], i32* [[T0]] 21 // Check that we properly assign into the forwarding pointer. 22 // CHECK-NEXT: [[A_FORWARDING:%.*]] = getelementptr inbounds [[BYREF]], [[BYREF]]* [[A]], i32 0, i32 1 23 // CHECK-NEXT: [[T0:%.*]] = load [[BYREF]]*, [[BYREF]]** [[A_FORWARDING]] 24 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[BYREF]], [[BYREF]]* [[T0]], i32 0, i32 4 25 // CHECK-NEXT: [[T2:%.*]] = bitcast [[AGG]]* [[T1]] to i8* 26 // CHECK-NEXT: [[T3:%.*]] = bitcast [[AGG]]* [[TEMP]] to i8* 27 // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[T2]], i8* [[T3]], i64 4, i32 4, i1 false) 28 // Verify that there's nothing else significant in the function. 29 // CHECK-NEXT: [[T0:%.*]] = bitcast [[BYREF]]* [[A]] to i8* 30 // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8) 31 // CHECK-NEXT: ret void 32 33 // When chaining assignments into __block variables, make sure we 34 // propagate the actual value into the outer variable. 35 // rdar://11757470 36 void test1() { 37 __block Agg a, b; 38 a = b = makeAgg(); 39 } 40 // CHECK-LABEL: define void @test1() 41 // CHECK: [[A:%.*]] = alloca [[A_BYREF:%.*]], align 8 42 // CHECK-NEXT: [[B:%.*]] = alloca [[B_BYREF:%.*]], align 8 43 // CHECK-NEXT: [[TEMP:%.*]] = alloca [[AGG]], align 4 44 // CHECK: [[RESULT:%.*]] = call i32 @makeAgg() 45 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[TEMP]], i32 0, i32 0 46 // CHECK-NEXT: store i32 [[RESULT]], i32* [[T0]] 47 // Check that we properly assign into the forwarding pointer, first for b: 48 // CHECK-NEXT: [[B_FORWARDING:%.*]] = getelementptr inbounds [[B_BYREF]], [[B_BYREF]]* [[B]], i32 0, i32 1 49 // CHECK-NEXT: [[T0:%.*]] = load [[B_BYREF]]*, [[B_BYREF]]** [[B_FORWARDING]] 50 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[B_BYREF]], [[B_BYREF]]* [[T0]], i32 0, i32 4 51 // CHECK-NEXT: [[T2:%.*]] = bitcast [[AGG]]* [[T1]] to i8* 52 // CHECK-NEXT: [[T3:%.*]] = bitcast [[AGG]]* [[TEMP]] to i8* 53 // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[T2]], i8* [[T3]], i64 4, i32 4, i1 false) 54 // Then for 'a': 55 // CHECK-NEXT: [[A_FORWARDING:%.*]] = getelementptr inbounds [[A_BYREF]], [[A_BYREF]]* [[A]], i32 0, i32 1 56 // CHECK-NEXT: [[T0:%.*]] = load [[A_BYREF]]*, [[A_BYREF]]** [[A_FORWARDING]] 57 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[A_BYREF]], [[A_BYREF]]* [[T0]], i32 0, i32 4 58 // CHECK-NEXT: [[T2:%.*]] = bitcast [[AGG]]* [[T1]] to i8* 59 // CHECK-NEXT: [[T3:%.*]] = bitcast [[AGG]]* [[TEMP]] to i8* 60 // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[T2]], i8* [[T3]], i64 4, i32 4, i1 false) 61 // Verify that there's nothing else significant in the function. 62 // CHECK-NEXT: [[T0:%.*]] = bitcast [[B_BYREF]]* [[B]] to i8* 63 // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8) 64 // CHECK-NEXT: [[T0:%.*]] = bitcast [[A_BYREF]]* [[A]] to i8* 65 // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8) 66 // CHECK-NEXT: ret void 67