1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks -std=c++1y -emit-pch %s -o %t 2// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks -std=c++1y -include-pch %t -emit-llvm -o - %s | FileCheck %s 3 4#ifndef HEADER_INCLUDED 5#define HEADER_INCLUDED 6 7namespace test_block_retain { 8 typedef void (^BlockTy)(); 9 void foo1(id); 10 11 inline void initialization(id a) { 12 // Call to @llvm.objc.retainBlock isn't needed. 13 BlockTy b0 = ^{ foo1(a); }; 14 b0(); 15 } 16 17 inline void assignmentConditional(id a, bool c) { 18 BlockTy b0; 19 if (c) 20 // @llvm.objc.retainBlock is called since 'b0' is declared in the outer scope. 21 b0 = ^{ foo1(a); }; 22 b0(); 23 } 24} 25 26#else 27 28// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 } 29 30namespace test_block_retain { 31// CHECK-LABEL: define linkonce_odr void @_ZN17test_block_retain14initializationEP11objc_object( 32// CHECK-NOT: call i8* @llvm.objc.retainBlock( 33 34 void test_initialization(id a) { 35 initialization(a); 36 } 37 38// CHECK-LABEL: define void @_ZN17test_block_retain26test_assignmentConditionalEP11objc_objectb( 39// CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8 40// CHECK: %[[V4:.*]] = bitcast <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]] to void ()* 41// CHECK: %[[V5:.*]] = bitcast void ()* %[[V4]] to i8* 42// CHECK: call i8* @llvm.objc.retainBlock(i8* %[[V5]]) 43 44 void test_assignmentConditional(id a, bool c) { 45 assignmentConditional(a, c); 46 } 47} 48 49#endif 50