blob: 07b194da9435df567ab224ef6f5c8d3b4bae5a14 [file] [log] [blame]
Rafael Espindolaff7cea82013-09-04 04:12:25 +00001// 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
John McCall7f416cc2015-09-08 08:05:57 +00002// RUN: FileCheck -check-prefix=CHECK -check-prefix=CHECK-64 --input-file=%t-64.layout %s
Rafael Espindolaff7cea82013-09-04 04:12:25 +00003// 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
John McCall7f416cc2015-09-08 08:05:57 +00004// RUN: FileCheck -check-prefix=CHECK -check-prefix=CHECK-32 --input-file=%t-32.layout %s
Fariborz Jahanian23290b02012-11-01 18:32:55 +00005// 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
John McCall7f416cc2015-09-08 08:05:57 +000020// CHECK: Inline block variable layout: 0x0100, BL_STRONG:1, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000021 void (^b)() = ^{
22 x(bar);
23 };
24
John McCall7f416cc2015-09-08 08:05:57 +000025// CHECK: Inline block variable layout: 0x0210, BL_STRONG:2, BL_BYREF:1, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000026 void (^c)() = ^{
27 x(bar);
28 x(baz);
29 byref_int = 1;
30 };
31
John McCall7f416cc2015-09-08 08:05:57 +000032// CHECK: Inline block variable layout: 0x0230, BL_STRONG:2, BL_BYREF:3, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000033 void (^d)() = ^{
34 x(bar);
35 x(baz);
36 byref_int = 1;
37 bl_var1 = 0;
38 byref_bab = 0;
39 };
40
John McCall7f416cc2015-09-08 08:05:57 +000041// CHECK: Inline block variable layout: 0x0231, BL_STRONG:2, BL_BYREF:3, BL_WEAK:1, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000042 __weak id wid;
43 id (^e)() = ^{
44 x(bar);
45 x(baz);
46 byref_int = 1;
47 bl_var1 = 0;
48 byref_bab = 0;
49 return wid;
50 };
51
John McCall7f416cc2015-09-08 08:05:57 +000052// CHECK: Inline block variable layout: 0x0235, BL_STRONG:2, BL_BYREF:3, BL_WEAK:5, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000053 __weak id wid1, wid2, wid3, wid4;
54 id (^f)() = ^{
55 x(bar);
56 x(baz);
57 byref_int = 1;
58 bl_var1 = 0;
59 byref_bab = 0;
60 x(wid1);
61 x(wid2);
62 x(wid3);
63 x(wid4);
64 return wid;
65 };
66
John McCall7f416cc2015-09-08 08:05:57 +000067// CHECK: Inline block variable layout: 0x035, BL_BYREF:3, BL_WEAK:5, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000068 id (^g)() = ^{
69 byref_int = 1;
70 bl_var1 = 0;
71 byref_bab = 0;
72 x(wid1);
73 x(wid2);
74 x(wid3);
75 x(wid4);
76 return wid;
77 };
78
John McCall7f416cc2015-09-08 08:05:57 +000079// CHECK: Inline block variable layout: 0x01, BL_WEAK:1, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000080 id (^h)() = ^{
81 return wid;
82 };
83
John McCall7f416cc2015-09-08 08:05:57 +000084// CHECK: Inline block variable layout: 0x020, BL_BYREF:2, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000085 void (^ii)() = ^{
86 byref_int = 1;
87 byref_bab = 0;
88 };
89
John McCall7f416cc2015-09-08 08:05:57 +000090// CHECK: Inline block variable layout: 0x0102, BL_STRONG:1, BL_WEAK:2, BL_OPERATOR:0
Fariborz Jahanian23290b02012-11-01 18:32:55 +000091 void (^jj)() = ^{
92 x(bar);
93 x(wid1);
94 x(wid2);
95 };
96}
Fariborz Jahanianc8892052013-01-17 00:25:06 +000097
98// rdar://12752901
99@class NSString;
100extern void NSLog(NSString *format, ...);
101typedef void (^dispatch_block_t)(void);
102int main() {
103 __strong NSString *s1 = 0;
104 __strong NSString *s2 = 0;
105 __weak NSString *w1 = 0;
106
107
John McCall7f416cc2015-09-08 08:05:57 +0000108// CHECK: Inline block variable layout: 0x0201, BL_STRONG:2, BL_WEAK:1, BL_OPERATOR:0
Fariborz Jahanianc8892052013-01-17 00:25:06 +0000109 dispatch_block_t block2 = ^{
110 NSLog(@"%@, %@, %@", s1, w1, s2);
111 };
112}