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