llvm-project
171 строка · 4.0 Кб
1// RUN: %clang_cc1 -fblocks -fobjc-gc -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 -print-ivar-layout -emit-llvm -o /dev/null %s > %t-64.layout
2// RUN: FileCheck -check-prefix CHECK-LP64 --input-file=%t-64.layout %s
3
4struct S {
5int i1;
6id o1;
7struct V {
8int i2;
9id o2;
10} v1;
11int i3;
12id o3;
13};
14
15__weak id wid;
16void x(id y) {}
17void y(int a) {}
18
19extern id opaque_id(void);
20
21void f(void) {
22__block int byref_int = 0;
23char ch = 'a';
24char ch1 = 'b';
25char ch2 = 'c';
26short sh = 2;
27const id bar = (id) opaque_id();
28id baz = 0;
29__strong void *strong_void_sta;
30__block id byref_bab = (id)0;
31__block void *bl_var1;
32int i; double dob;
33
34// The patterns here are a sequence of bytes, each saying first how
35// many sizeof(void*) chunks to skip (high nibble) and then how many
36// to scan (low nibble). A zero byte says that we've reached the end
37// of the pattern.
38//
39// All of these patterns start with 01 3x because the block header on
40// LP64 consists of an isa pointer (which we're supposed to scan for
41// some reason) followed by three words (2 ints, a function pointer,
42// and a descriptor pointer).
43
44// FIXME: do these really have to be named L_OBJC_CLASS_NAME_xxx?
45// FIXME: sequences should never end in x0 00 instead of just 00
46
47// Test 1
48// byref int, short, char, char, char, id, id, strong void*, byref id
49// CHECK-LP64: block variable layout for block: 0x01, 0x35, 0x10, 0x00
50void (^b)(void) = ^{
51byref_int = sh + ch+ch1+ch2 ;
52x(bar);
53x(baz);
54x((id)strong_void_sta);
55x(byref_bab);
56};
57b();
58
59// Test 2
60// byref int, short, char, char, char, id, id, strong void*, byref void*, byref id
61// 01 36 10 00
62// CHECK-LP64: block variable layout for block: 0x01, 0x36, 0x10, 0x00
63void (^c)(void) = ^{
64byref_int = sh + ch+ch1+ch2 ;
65x(bar);
66x(baz);
67x((id)strong_void_sta);
68x(wid);
69bl_var1 = 0;
70x(byref_bab);
71};
72c();
73
74// Test 3
75// byref int, short, char, char, char, id, id, byref void*, int, double, byref id
76// 01 34 11 30 00
77// FIXME: we'd get a better format here if we sorted by scannability, not just alignment
78// CHECK-LP64: block variable layout for block: 0x01, 0x35, 0x30, 0x00
79void (^d)(void) = ^{
80byref_int = sh + ch+ch1+ch2 ;
81x(bar);
82x(baz);
83x(wid);
84bl_var1 = 0;
85y(i + dob);
86x(byref_bab);
87};
88d();
89
90// Test 4
91// struct S (int, id, int, id, int, id)
92// 01 41 11 11 00
93// CHECK-LP64: block variable layout for block: 0x01, 0x41, 0x11, 0x11, 0x00
94struct S s2;
95void (^e)(void) = ^{
96x(s2.o1);
97};
98e();
99}
100
101// Test 5 (unions/structs and their nesting):
102void Test5(void) {
103struct S5 {
104int i1;
105id o1;
106struct V {
107int i2;
108id o2;
109} v1;
110int i3;
111union UI {
112void * i1;
113id o1;
114int i3;
115id o3;
116}ui;
117};
118
119union U {
120void * i1;
121id o1;
122int i3;
123id o3;
124}ui;
125
126struct S5 s2;
127union U u2;
128
129// struct s2 (int, id, int, id, int, id?), union u2 (id?)
130// 01 41 11 12 00
131// CHECK-LP64: block variable layout for block: 0x01, 0x41, 0x11, 0x12, 0x00
132void (^c)(void) = ^{
133x(s2.ui.o1);
134x(u2.o1);
135};
136c();
137}
138
139void CFRelease(id);
140void notifyBlock(id dependentBlock) {
141id singleObservationToken;
142id token;
143void (^b)(void);
144
145// id, id, void(^)(void)
146// 01 33 00
147// CHECK-LP64: block variable layout for block: 0x01, 0x33, 0x00
148void (^wrapperBlock)(void) = ^(void) {
149CFRelease(singleObservationToken);
150CFRelease(singleObservationToken);
151CFRelease(token);
152CFRelease(singleObservationToken);
153b();
154};
155wrapperBlock();
156}
157
158void test_empty_block(void) {
159// 01 00
160// CHECK-LP64: block variable layout for block: 0x01, 0x30, 0x00
161void (^wrapperBlock)(void) = ^(void) {
162};
163wrapperBlock();
164}
165
166typedef union { char ch[8]; } SS;
167typedef struct { SS s[4]; } CS;
168void test_union_in_layout(void) {
169CS cs;
170^{ cs; };
171}
172