1 // RUN: %clang_cc1 %s -emit-llvm -o - -fblocks -triple x86_64-apple-darwin10 | FileCheck %s
3 // CHECK: [[AGG:%.*]] = type { i32 }
4 typedef struct { int v
; } Agg
;
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
11 __block Agg a
= {100};
16 // CHECK-LABEL: define{{.*}} void @test0()
17 // CHECK: [[A:%.*]] = alloca [[BYREF:%.*]], align 8
18 // CHECK-NEXT: alloca <{ ptr, i32, i32, ptr, ptr, ptr }>, align 8
19 // CHECK-NEXT: [[TEMP:%.*]] = alloca [[AGG]], align 4
20 // CHECK: [[RESULT:%.*]] = call i32 @makeAgg()
21 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TEMP]], i32 0, i32 0
22 // CHECK-NEXT: store i32 [[RESULT]], ptr [[T0]]
23 // Check that we properly assign into the forwarding pointer.
24 // CHECK-NEXT: [[A_FORWARDING:%.*]] = getelementptr inbounds [[BYREF]], ptr [[A]], i32 0, i32 1
25 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[A_FORWARDING]]
26 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[BYREF]], ptr [[T0]], i32 0, i32 4
27 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[T1]], ptr align 4 [[TEMP]], i64 4, i1 false)
28 // Verify that there's nothing else significant in the function.
29 // CHECK-NEXT: call void @_Block_object_dispose(ptr [[A]], i32 8)
30 // CHECK-NEXT: ret void
32 // When chaining assignments into __block variables, make sure we
33 // propagate the actual value into the outer variable.
37 ^{ (void)a
; (void)b
; };
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: alloca <{ ptr, i32, i32, ptr, ptr, ptr, ptr }>, align 8
44 // CHECK-NEXT: [[TEMP:%.*]] = alloca [[AGG]], align 4
45 // CHECK: [[RESULT:%.*]] = call i32 @makeAgg()
46 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TEMP]], i32 0, i32 0
47 // CHECK-NEXT: store i32 [[RESULT]], ptr [[T0]]
48 // Check that we properly assign into the forwarding pointer, first for b:
49 // CHECK-NEXT: [[B_FORWARDING:%.*]] = getelementptr inbounds [[B_BYREF]], ptr [[B]], i32 0, i32 1
50 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[B_FORWARDING]]
51 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[B_BYREF]], ptr [[T0]], i32 0, i32 4
52 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[T1]], ptr align 4 [[TEMP]], i64 4, i1 false)
54 // CHECK-NEXT: [[A_FORWARDING:%.*]] = getelementptr inbounds [[A_BYREF]], ptr [[A]], i32 0, i32 1
55 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[A_FORWARDING]]
56 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[A_BYREF]], ptr [[T0]], i32 0, i32 4
57 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[T1]], ptr align 4 [[TEMP]], i64 4, i1 false)
58 // Verify that there's nothing else significant in the function.
59 // CHECK-NEXT: call void @_Block_object_dispose(ptr [[B]], i32 8)
60 // CHECK-NEXT: call void @_Block_object_dispose(ptr [[A]], i32 8)
61 // CHECK-NEXT: ret void