1 // RUN: %clang_cc1 -x c++-header -triple x86_64-apple-darwin11 -emit-pch -fblocks -fexceptions -o %t %S/block-helpers.h
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -include-pch %t -emit-llvm -fblocks -fexceptions -o - %s | FileCheck %s
3 
4 // CHECK: %[[STRUCT_BLOCK_BYREF_X:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_X]]*, i32, i32, i8*, i8*, %[[STRUCT_S0:.*]] }
5 // CHECK: %[[STRUCT_S0]] = type { i32 }
6 // CHECK: %[[STRUCT_BLOCK_BYREF_Y:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_Y]]*, i32, i32, i8*, i8*, %[[STRUCT_S0]] }
7 // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
8 
9 // Check that byref structs are allocated for x and y.
10 
11 // CHECK-LABEL: define linkonce_odr void @_ZN1S1mEv(
12 // CHECK: %[[X:.*]] = alloca %[[STRUCT_BLOCK_BYREF_X]], align 8
13 // CHECK: %[[Y:.*]] = alloca %[[STRUCT_BLOCK_BYREF_Y]], align 8
14 // CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8* }>, align 8
15 // CHECK: %[[BLOCK_CAPTURED:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8* }>* %[[BLOCK]], i32 0, i32 5
16 // CHECK: %[[V0:.*]] = bitcast %[[STRUCT_BLOCK_BYREF_X]]* %[[X]] to i8*
17 // CHECK: store i8* %[[V0]], i8** %[[BLOCK_CAPTURED]], align 8
18 // CHECK: %[[BLOCK_CAPTURED10:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8* }>* %[[BLOCK]], i32 0, i32 6
19 // CHECK: %[[V1:.*]] = bitcast %[[STRUCT_BLOCK_BYREF_Y]]* %[[Y]] to i8*
20 // CHECK: store i8* %[[V1]], i8** %[[BLOCK_CAPTURED10]], align 8
21 
22 // CHECK-LABEL: define internal void @___ZN1S1mEv_block_invoke(
23 
24 // The second call to block_object_assign should be an invoke.
25 
26 // CHECK-LABEL: define linkonce_odr hidden void @__copy_helper_block_e8_32rc40rc(
27 // CHECK: call void @_Block_object_assign(
28 // CHECK: invoke void @_Block_object_assign(
29 // CHECK: call void @_Block_object_dispose(
30 
31 // CHECK-LABEL: define linkonce_odr hidden void @__destroy_helper_block_e8_32r40r(
test()32 void test() {
33   S s;
34   s.m();
35 }
36