1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 
3 /*
4  * BTF-to-C dumper tests for implicit and explicit padding between fields and
5  * at the end of a struct.
6  *
7  * Copyright (c) 2019 Facebook
8  */
9 /* ----- START-EXPECTED-OUTPUT ----- */
10 struct padded_implicitly {
11 	int a;
12 	long b;
13 	char c;
14 };
15 
16 /* ------ END-EXPECTED-OUTPUT ------ */
17 
18 /* ----- START-EXPECTED-OUTPUT ----- */
19 /*
20  *struct padded_explicitly {
21  *	int a;
22  *	long: 0;
23  *	int b;
24  *};
25  *
26  */
27 /* ------ END-EXPECTED-OUTPUT ------ */
28 
29 struct padded_explicitly {
30 	int a;
31 	int: 1; /* algo will emit aligning `long: 0;` here */
32 	int b;
33 };
34 
35 /* ----- START-EXPECTED-OUTPUT ----- */
36 struct padded_a_lot {
37 	int a;
38 	long: 64;
39 	long: 64;
40 	int b;
41 };
42 
43 /* ------ END-EXPECTED-OUTPUT ------ */
44 
45 /* ----- START-EXPECTED-OUTPUT ----- */
46 /*
47  *struct padded_cache_line {
48  *	int a;
49  *	long: 64;
50  *	long: 64;
51  *	long: 64;
52  *	int b;
53  *	long: 64;
54  *	long: 64;
55  *	long: 64;
56  *};
57  *
58  */
59 /* ------ END-EXPECTED-OUTPUT ------ */
60 
61 struct padded_cache_line {
62 	int a;
63 	int b __attribute__((aligned(32)));
64 };
65 
66 /* ----- START-EXPECTED-OUTPUT ----- */
67 /*
68  *struct zone_padding {
69  *	char x[0];
70  *};
71  *
72  *struct zone {
73  *	int a;
74  *	short b;
75  *	long: 0;
76  *	struct zone_padding __pad__;
77  *};
78  *
79  */
80 /* ------ END-EXPECTED-OUTPUT ------ */
81 
82 struct zone_padding {
83 	char x[0];
84 } __attribute__((__aligned__(8)));
85 
86 struct zone {
87 	int a;
88 	short b;
89 	struct zone_padding __pad__;
90 };
91 
92 /* ----- START-EXPECTED-OUTPUT ----- */
93 struct padding_wo_named_members {
94 	long: 64;
95 	long: 64;
96 };
97 
98 struct padding_weird_1 {
99 	int a;
100 	long: 64;
101 	short: 16;
102 	short b;
103 };
104 
105 /* ------ END-EXPECTED-OUTPUT ------ */
106 
107 /* ----- START-EXPECTED-OUTPUT ----- */
108 /*
109  *struct padding_weird_2 {
110  *	long: 56;
111  *	char a;
112  *	long: 56;
113  *	char b;
114  *	char: 8;
115  *};
116  *
117  */
118 /* ------ END-EXPECTED-OUTPUT ------ */
119 struct padding_weird_2 {
120 	int: 32;	/* these paddings will be collapsed into `long: 56;` */
121 	short: 16;
122 	char: 8;
123 	char a;
124 	int: 32;	/* these paddings will be collapsed into `long: 56;` */
125 	short: 16;
126 	char: 8;
127 	char b;
128 	char: 8;
129 };
130 
131 /* ----- START-EXPECTED-OUTPUT ----- */
132 struct exact_1byte {
133 	char x;
134 };
135 
136 struct padded_1byte {
137 	char: 8;
138 };
139 
140 struct exact_2bytes {
141 	short x;
142 };
143 
144 struct padded_2bytes {
145 	short: 16;
146 };
147 
148 struct exact_4bytes {
149 	int x;
150 };
151 
152 struct padded_4bytes {
153 	int: 32;
154 };
155 
156 struct exact_8bytes {
157 	long x;
158 };
159 
160 struct padded_8bytes {
161 	long: 64;
162 };
163 
164 struct ff_periodic_effect {
165 	int: 32;
166 	short magnitude;
167 	long: 0;
168 	short phase;
169 	long: 0;
170 	int: 32;
171 	int custom_len;
172 	short *custom_data;
173 };
174 
175 struct ib_wc {
176 	long: 64;
177 	long: 64;
178 	int: 32;
179 	int byte_len;
180 	void *qp;
181 	union {} ex;
182 	long: 64;
183 	int slid;
184 	int wc_flags;
185 	long: 64;
186 	char smac[6];
187 	long: 0;
188 	char network_hdr_type;
189 };
190 
191 struct acpi_object_method {
192 	long: 64;
193 	char: 8;
194 	char type;
195 	short reference_count;
196 	char flags;
197 	short: 0;
198 	char: 8;
199 	char sync_level;
200 	long: 64;
201 	void *node;
202 	void *aml_start;
203 	union {} dispatch;
204 	long: 64;
205 	int aml_length;
206 };
207 
208 struct nested_unpacked {
209 	int x;
210 };
211 
212 struct nested_packed {
213 	struct nested_unpacked a;
214 	char c;
215 } __attribute__((packed));
216 
217 struct outer_mixed_but_unpacked {
218 	struct nested_packed b1;
219 	short a1;
220 	struct nested_packed b2;
221 };
222 
223 /* ------ END-EXPECTED-OUTPUT ------ */
224 
f(struct{ struct padded_implicitly _1; struct padded_explicitly _2; struct padded_a_lot _3; struct padded_cache_line _4; struct zone _5; struct padding_wo_named_members _6; struct padding_weird_1 _7; struct padding_weird_2 _8; struct exact_1byte _100; struct padded_1byte _101; struct exact_2bytes _102; struct padded_2bytes _103; struct exact_4bytes _104; struct padded_4bytes _105; struct exact_8bytes _106; struct padded_8bytes _107; struct ff_periodic_effect _200; struct ib_wc _201; struct acpi_object_method _202; struct outer_mixed_but_unpacked _203; } * _)225 int f(struct {
226 	struct padded_implicitly _1;
227 	struct padded_explicitly _2;
228 	struct padded_a_lot _3;
229 	struct padded_cache_line _4;
230 	struct zone _5;
231 	struct padding_wo_named_members _6;
232 	struct padding_weird_1 _7;
233 	struct padding_weird_2 _8;
234 	struct exact_1byte _100;
235 	struct padded_1byte _101;
236 	struct exact_2bytes _102;
237 	struct padded_2bytes _103;
238 	struct exact_4bytes _104;
239 	struct padded_4bytes _105;
240 	struct exact_8bytes _106;
241 	struct padded_8bytes _107;
242 	struct ff_periodic_effect _200;
243 	struct ib_wc _201;
244 	struct acpi_object_method _202;
245 	struct outer_mixed_but_unpacked _203;
246 } *_)
247 {
248 	return 0;
249 }
250