Debian Codegraph @

clang/test/CodeGenObjC/arc-captured-block-var-inlined-layout.m

raw
1 // RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -triple x86_64-apple-darwin -print-ivar-layout -emit-llvm -o /dev/null %s > %t-64.layout
2 // RUN: FileCheck --input-file=%t-64.layout %s
3 // RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -triple i386-apple-darwin -print-ivar-layout -emit-llvm -o /dev/null %s > %t-32.layout
4 // RUN: FileCheck --input-file=%t-32.layout %s
5
6 void x(id y) {}
7 void y(int a) {}
8
9 extern id opaque_id(void);
10
11 void f(void) {
12 __block int byref_int = 0;
13 const id bar = (id) opaque_id();
14 id baz = 0;
15 __strong id strong_void_sta;
16 __block id byref_bab = (id)0;
17 __block id bl_var1;
18
19 // CHECK: Inline block variable layout: 0x0100, BL_STRONG:1, BL_OPERATOR:0
20 void (^b)(void) = ^{
21 x(bar);
22 };
23
24 // CHECK: Inline block variable layout: 0x0210, BL_STRONG:2, BL_BYREF:1, BL_OPERATOR:0
25 void (^c)(void) = ^{
26 x(bar);
27 x(baz);
28 byref_int = 1;
29 };
30
31 // CHECK: Inline block variable layout: 0x0230, BL_STRONG:2, BL_BYREF:3, BL_OPERATOR:0
32 void (^d)(void) = ^{
33 x(bar);
34 x(baz);
35 byref_int = 1;
36 bl_var1 = 0;
37 byref_bab = 0;
38 };
39
40 // CHECK: Inline block variable layout: 0x0231, BL_STRONG:2, BL_BYREF:3, BL_WEAK:1, BL_OPERATOR:0
41 __weak id wid;
42 id (^e)(void) = ^{
43 x(bar);
44 x(baz);
45 byref_int = 1;
46 bl_var1 = 0;
47 byref_bab = 0;
48 return wid;
49 };
50
51 // CHECK: Inline block variable layout: 0x0235, BL_STRONG:2, BL_BYREF:3, BL_WEAK:5, BL_OPERATOR:0
52 __weak id wid1, wid2, wid3, wid4;
53 id (^f)(void) = ^{
54 x(bar);
55 x(baz);
56 byref_int = 1;
57 bl_var1 = 0;
58 byref_bab = 0;
59 x(wid1);
60 x(wid2);
61 x(wid3);
62 x(wid4);
63 return wid;
64 };
65
66 // CHECK: Inline block variable layout: 0x035, BL_BYREF:3, BL_WEAK:5, BL_OPERATOR:0
67 id (^g)(void) = ^{
68 byref_int = 1;
69 bl_var1 = 0;
70 byref_bab = 0;
71 x(wid1);
72 x(wid2);
73 x(wid3);
74 x(wid4);
75 return wid;
76 };
77
78 // CHECK: Inline block variable layout: 0x01, BL_WEAK:1, BL_OPERATOR:0
79 id (^h)(void) = ^{
80 return wid;
81 };
82
83 // CHECK: Inline block variable layout: 0x020, BL_BYREF:2, BL_OPERATOR:0
84 void (^ii)(void) = ^{
85 byref_int = 1;
86 byref_bab = 0;
87 };
88
89 // CHECK: Inline block variable layout: 0x0102, BL_STRONG:1, BL_WEAK:2, BL_OPERATOR:0
90 void (^jj)(void) = ^{
91 x(bar);
92 x(wid1);
93 x(wid2);
94 };
95 }
96
97 @class NSString;
98 extern void NSLog(NSString *format, ...);
99 typedef void (^dispatch_block_t)(void);
100 int main(void) {
101 __strong NSString *s1 = 0;
102 __strong NSString *s2 = 0;
103 __weak NSString *w1 = 0;
104
105
106 // CHECK: Inline block variable layout: 0x0201, BL_STRONG:2, BL_WEAK:1, BL_OPERATOR:0
107 dispatch_block_t block2 = ^{
108 NSLog(@"%@, %@, %@", s1, w1, s2);
109 };
110 }