xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/arc-captured-block-var-inlined-layout.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// 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*f4a2713aSLionel Sambuc// RUN: FileCheck --input-file=%t-64.layout %s
3*f4a2713aSLionel Sambuc// 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*f4a2713aSLionel Sambuc// RUN: FileCheck -check-prefix=CHECK-i386 --input-file=%t-32.layout %s
5*f4a2713aSLionel Sambuc// rdar://12184410
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel Sambucvoid x(id y) {}
8*f4a2713aSLionel Sambucvoid y(int a) {}
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambucextern id opaque_id();
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambucvoid f() {
13*f4a2713aSLionel Sambuc    __block int byref_int = 0;
14*f4a2713aSLionel Sambuc    const id bar = (id) opaque_id();
15*f4a2713aSLionel Sambuc    id baz = 0;
16*f4a2713aSLionel Sambuc    __strong id strong_void_sta;
17*f4a2713aSLionel Sambuc    __block id byref_bab = (id)0;
18*f4a2713aSLionel Sambuc    __block id bl_var1;
19*f4a2713aSLionel Sambuc
20*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x0100
21*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x0100
22*f4a2713aSLionel Sambuc    void (^b)() = ^{
23*f4a2713aSLionel Sambuc        x(bar);
24*f4a2713aSLionel Sambuc    };
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x0210
27*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x0210
28*f4a2713aSLionel Sambuc    void (^c)() = ^{
29*f4a2713aSLionel Sambuc        x(bar);
30*f4a2713aSLionel Sambuc        x(baz);
31*f4a2713aSLionel Sambuc        byref_int = 1;
32*f4a2713aSLionel Sambuc    };
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x0230
35*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x0230
36*f4a2713aSLionel Sambuc    void (^d)() = ^{
37*f4a2713aSLionel Sambuc        x(bar);
38*f4a2713aSLionel Sambuc        x(baz);
39*f4a2713aSLionel Sambuc        byref_int = 1;
40*f4a2713aSLionel Sambuc        bl_var1 = 0;
41*f4a2713aSLionel Sambuc        byref_bab = 0;
42*f4a2713aSLionel Sambuc    };
43*f4a2713aSLionel Sambuc
44*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x0231
45*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x0231
46*f4a2713aSLionel Sambuc    __weak id wid;
47*f4a2713aSLionel Sambuc    id (^e)() = ^{
48*f4a2713aSLionel Sambuc        x(bar);
49*f4a2713aSLionel Sambuc        x(baz);
50*f4a2713aSLionel Sambuc        byref_int = 1;
51*f4a2713aSLionel Sambuc        bl_var1 = 0;
52*f4a2713aSLionel Sambuc        byref_bab = 0;
53*f4a2713aSLionel Sambuc        return wid;
54*f4a2713aSLionel Sambuc    };
55*f4a2713aSLionel Sambuc
56*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x0235
57*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x0235
58*f4a2713aSLionel Sambuc    __weak id wid1, wid2, wid3, wid4;
59*f4a2713aSLionel Sambuc    id (^f)() = ^{
60*f4a2713aSLionel Sambuc        x(bar);
61*f4a2713aSLionel Sambuc        x(baz);
62*f4a2713aSLionel Sambuc        byref_int = 1;
63*f4a2713aSLionel Sambuc        bl_var1 = 0;
64*f4a2713aSLionel Sambuc        byref_bab = 0;
65*f4a2713aSLionel Sambuc        x(wid1);
66*f4a2713aSLionel Sambuc        x(wid2);
67*f4a2713aSLionel Sambuc        x(wid3);
68*f4a2713aSLionel Sambuc        x(wid4);
69*f4a2713aSLionel Sambuc        return wid;
70*f4a2713aSLionel Sambuc    };
71*f4a2713aSLionel Sambuc
72*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x035
73*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x035
74*f4a2713aSLionel Sambuc    id (^g)() = ^{
75*f4a2713aSLionel Sambuc        byref_int = 1;
76*f4a2713aSLionel Sambuc        bl_var1 = 0;
77*f4a2713aSLionel Sambuc        byref_bab = 0;
78*f4a2713aSLionel Sambuc        x(wid1);
79*f4a2713aSLionel Sambuc        x(wid2);
80*f4a2713aSLionel Sambuc        x(wid3);
81*f4a2713aSLionel Sambuc        x(wid4);
82*f4a2713aSLionel Sambuc        return wid;
83*f4a2713aSLionel Sambuc    };
84*f4a2713aSLionel Sambuc
85*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x01
86*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x01
87*f4a2713aSLionel Sambuc    id (^h)() = ^{
88*f4a2713aSLionel Sambuc        return wid;
89*f4a2713aSLionel Sambuc    };
90*f4a2713aSLionel Sambuc
91*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x020
92*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x020
93*f4a2713aSLionel Sambuc    void (^ii)() = ^{
94*f4a2713aSLionel Sambuc       byref_int = 1;
95*f4a2713aSLionel Sambuc       byref_bab = 0;
96*f4a2713aSLionel Sambuc    };
97*f4a2713aSLionel Sambuc
98*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x0102
99*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x0102
100*f4a2713aSLionel Sambuc    void (^jj)() = ^{
101*f4a2713aSLionel Sambuc      x(bar);
102*f4a2713aSLionel Sambuc      x(wid1);
103*f4a2713aSLionel Sambuc      x(wid2);
104*f4a2713aSLionel Sambuc    };
105*f4a2713aSLionel Sambuc}
106*f4a2713aSLionel Sambuc
107*f4a2713aSLionel Sambuc// rdar://12752901
108*f4a2713aSLionel Sambuc@class NSString;
109*f4a2713aSLionel Sambucextern void NSLog(NSString *format, ...);
110*f4a2713aSLionel Sambuctypedef void (^dispatch_block_t)(void);
111*f4a2713aSLionel Sambucint main() {
112*f4a2713aSLionel Sambuc        __strong NSString *s1 = 0;
113*f4a2713aSLionel Sambuc        __strong NSString *s2 = 0;
114*f4a2713aSLionel Sambuc        __weak NSString *w1 = 0;
115*f4a2713aSLionel Sambuc
116*f4a2713aSLionel Sambuc
117*f4a2713aSLionel Sambuc// CHECK: Inline instruction for block variable layout: 0x0201
118*f4a2713aSLionel Sambuc// CHECK-i386: Inline instruction for block variable layout: 0x0201
119*f4a2713aSLionel Sambuc        dispatch_block_t block2 = ^{
120*f4a2713aSLionel Sambuc                NSLog(@"%@, %@, %@", s1, w1, s2);
121*f4a2713aSLionel Sambuc        };
122*f4a2713aSLionel Sambuc}
123