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