1 /* Structure layout test generator.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3 Contributed by Jakub Jelinek <jakub@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 /* Compile with gcc -o struct-layout-1_generate{,.c} generate_random{,_r}.c */
24 /* N.B. -- This program cannot use libiberty as that will not work
25 when testing an installed compiler. */
31 /* We use our own pseudo-random number generator, so that it gives the same
32 values on all hosts. */
33 #include "../../gcc.dg/compat/generate-random.h"
35 #if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL
36 # error Need 64-bit long long
39 #if defined __MSVCRT__
40 #define COMPAT_PRLL "I64"
42 #define COMPAT_PRLL "ll"
45 typedef unsigned int hashval_t;
63 unsigned long long int maxval;
67 struct types base_types[] = {
68 /* As we don't know whether char will be signed or not, just limit ourselves
69 to unsigned values less than maximum signed char value. */
70 { "char", TYPE_UINT, 127, 'C' },
71 { "signed char", TYPE_INT, 127, 'C' },
72 { "unsigned char", TYPE_UINT, 255, 'C' },
73 { "short int", TYPE_INT, 32767, 'S' },
74 { "unsigned short int", TYPE_UINT, 65535, 'S' },
75 { "int", TYPE_INT, 2147483647, 'I' },
76 { "unsigned int", TYPE_UINT, 4294967295U, 'I' },
77 { "long int", TYPE_INT, 9223372036854775807LL, 'L' },
78 { "unsigned long int", TYPE_UINT, 18446744073709551615ULL, 'L' },
79 { "long long int", TYPE_INT, 9223372036854775807LL, 'Q' },
80 { "unsigned long long int", TYPE_UINT, 18446744073709551615ULL, 'Q' },
81 { "bool", TYPE_UINT, 1, 'B' },
82 { "void *", TYPE_PTR, 0, 0 },
83 { "char *", TYPE_PTR, 0, 0 },
84 { "int *", TYPE_PTR, 0, 0 },
85 { "float", TYPE_FLOAT, 0, 0 },
86 { "double", TYPE_FLOAT, 0, 0 },
87 { "long double", TYPE_FLOAT, 0, 0 },
89 { "Tchar", TYPE_UINT, 127, 'C' },
90 { "Tschar", TYPE_INT, 127, 'C' },
91 { "Tuchar", TYPE_UINT, 255, 'C' },
92 { "Tshort", TYPE_INT, 32767, 'S' },
93 { "Tushort", TYPE_UINT, 65535, 'S' },
94 { "Tint", TYPE_INT, 2147483647, 'I' },
95 { "Tuint", TYPE_UINT, 4294967295U, 'I' },
96 { "Tlong", TYPE_INT, 9223372036854775807LL, 'L' },
97 { "Tulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
98 { "Tllong", TYPE_INT, 9223372036854775807LL, 'Q' },
99 { "Tullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
100 { "Tbool", TYPE_UINT, 1, 'B' },
101 { "size_t", TYPE_UINT, 18446744073709551615ULL, 0 },
102 { "Tptr", TYPE_PTR, 0, 0 },
103 { "Tcptr", TYPE_PTR, 0, 0 },
104 { "Tiptr", TYPE_PTR, 0, 0 },
105 { "Tfnptr", TYPE_FNPTR, 0, 0 },
106 { "Tfloat", TYPE_FLOAT, 0, 0 },
107 { "Tdouble", TYPE_FLOAT, 0, 0 },
108 { "Tldouble", TYPE_FLOAT, 0, 0 },
109 { "enum E0", TYPE_UENUM, 0, ' ' },
110 { "enum E1", TYPE_UENUM, 1, ' ' },
111 { "enum E2", TYPE_SENUM, 3, ' ' },
112 { "enum E3", TYPE_SENUM, 127, ' ' },
113 { "enum E4", TYPE_UENUM, 255, ' ' },
114 { "enum E5", TYPE_SENUM, 32767, ' ' },
115 { "enum E6", TYPE_UENUM, 65535, ' ' },
116 { "enum E7", TYPE_SENUM, 2147483647, ' ' },
117 { "enum E8", TYPE_UENUM, 4294967295U, ' ' },
118 { "enum E9", TYPE_SENUM, 1099511627775LL, ' ' },
119 { "TE0", TYPE_UENUM, 0, ' ' },
120 { "TE1", TYPE_UENUM, 1, ' ' },
121 { "TE2", TYPE_SENUM, 3, ' ' },
122 { "TE3", TYPE_SENUM, 127, ' ' },
123 { "TE4", TYPE_UENUM, 255, ' ' },
124 { "TE5", TYPE_SENUM, 32767, ' ' },
125 { "TE6", TYPE_UENUM, 65535, ' ' },
126 { "TE7", TYPE_SENUM, 2147483647, ' ' },
127 { "TE8", TYPE_UENUM, 4294967295U, ' ' },
128 { "TE9", TYPE_SENUM, 1099511627775LL, ' ' },
129 /* vector-defs.h typedefs */
130 { "qi", TYPE_INT, 127, 0 },
131 { "hi", TYPE_INT, 32767, 0 },
132 { "si", TYPE_INT, 2147483647, 0 },
133 { "di", TYPE_INT, 9223372036854775807LL, 0 },
134 { "sf", TYPE_FLOAT, 0, 0 },
135 { "df", TYPE_FLOAT, 0, 0 }
136 #define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
138 struct types vector_types[] = {
139 /* vector-defs.h typedefs */
140 { "v8qi", TYPE_OTHER, 0, 0 },
141 { "v16qi", TYPE_OTHER, 0, 0 },
142 { "v2hi", TYPE_OTHER, 0, 0 },
143 { "v4hi", TYPE_OTHER, 0, 0 },
144 { "v8hi", TYPE_OTHER, 0, 0 },
145 { "v2si", TYPE_OTHER, 0, 0 },
146 { "v4si", TYPE_OTHER, 0, 0 },
147 { "v1di", TYPE_OTHER, 0, 0 },
148 { "v2di", TYPE_OTHER, 0, 0 },
149 { "v2sf", TYPE_OTHER, 0, 0 },
150 { "v4sf", TYPE_OTHER, 0, 0 },
151 { "v16sf", TYPE_OTHER, 0, 0 },
152 { "v2df", TYPE_OTHER, 0, 0 },
153 { "u8qi", TYPE_OTHER, 0, 0 },
154 { "u16qi", TYPE_OTHER, 0, 0 },
155 { "u2hi", TYPE_OTHER, 0, 0 },
156 { "u4hi", TYPE_OTHER, 0, 0 },
157 { "u8hi", TYPE_OTHER, 0, 0 },
158 { "u2si", TYPE_OTHER, 0, 0 },
159 { "u4si", TYPE_OTHER, 0, 0 },
160 { "u1di", TYPE_OTHER, 0, 0 },
161 { "u2di", TYPE_OTHER, 0, 0 },
162 { "u2sf", TYPE_OTHER, 0, 0 },
163 { "u4sf", TYPE_OTHER, 0, 0 },
164 { "u16sf", TYPE_OTHER, 0, 0 },
165 { "u2df", TYPE_OTHER, 0, 0 },
166 { "__m64", TYPE_OTHER, 0, 0 },
167 { "__m128", TYPE_OTHER, 0, 0 }
168 #define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
170 struct types attrib_types[] = {
171 { "Talchar", TYPE_UINT, 127, 'C' },
172 { "Talschar", TYPE_INT, 127, 'C' },
173 { "Taluchar", TYPE_UINT, 255, 'C' },
174 { "Talshort", TYPE_INT, 32767, 'S' },
175 { "Talushort", TYPE_UINT, 65535, 'S' },
176 { "Talint", TYPE_INT, 2147483647, 'I' },
177 { "Taluint", TYPE_UINT, 4294967295U, 'I' },
178 { "Tallong", TYPE_INT, 9223372036854775807LL, 'L' },
179 { "Talulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
180 { "Talllong", TYPE_INT, 9223372036854775807LL, 'Q' },
181 { "Talullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
182 { "Talbool", TYPE_UINT, 1, 'B' },
183 { "Talptr", TYPE_PTR, 0, 0 },
184 { "Talcptr", TYPE_PTR, 0, 0 },
185 { "Taliptr", TYPE_PTR, 0, 0 },
186 { "Talfloat", TYPE_FLOAT, 0, 0 },
187 { "Taldouble", TYPE_FLOAT, 0, 0 },
188 { "Talldouble", TYPE_FLOAT, 0, 0 },
189 { "TalE0", TYPE_UENUM, 0, ' ' },
190 { "TalE1", TYPE_UENUM, 1, ' ' },
191 { "TalE2", TYPE_SENUM, 3, ' ' },
192 { "TalE3", TYPE_SENUM, 127, ' ' },
193 { "TalE4", TYPE_UENUM, 255, ' ' },
194 { "TalE5", TYPE_SENUM, 32767, ' ' },
195 { "TalE6", TYPE_UENUM, 65535, ' ' },
196 { "TalE7", TYPE_SENUM, 2147483647, ' ' },
197 { "TalE8", TYPE_UENUM, 4294967295U, ' ' },
198 { "TalE9", TYPE_SENUM, 1099511627775LL, ' ' },
199 { "Tal1char", TYPE_UINT, 127, 'C' },
200 { "Tal1schar", TYPE_INT, 127, 'C' },
201 { "Tal1uchar", TYPE_UINT, 255, 'C' },
202 { "Tal1short", TYPE_INT, 32767, 'S' },
203 { "Tal1ushort", TYPE_UINT, 65535, 'S' },
204 { "Tal1int", TYPE_INT, 2147483647, 'I' },
205 { "Tal1uint", TYPE_UINT, 4294967295U, 'I' },
206 { "Tal1long", TYPE_INT, 9223372036854775807LL, 'L' },
207 { "Tal1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
208 { "Tal1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
209 { "Tal1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
210 { "Tal1bool", TYPE_UINT, 1, 'B' },
211 { "Tal1ptr", TYPE_PTR, 0, 0 },
212 { "Tal1cptr", TYPE_PTR, 0, 0 },
213 { "Tal1iptr", TYPE_PTR, 0, 0 },
214 { "Tal1float", TYPE_FLOAT, 0, 0 },
215 { "Tal1double", TYPE_FLOAT, 0, 0 },
216 { "Tal1ldouble", TYPE_FLOAT, 0, 0 },
217 { "Tal1E0", TYPE_UENUM, 0, ' ' },
218 { "Tal1E1", TYPE_UENUM, 1, ' ' },
219 { "Tal1E2", TYPE_SENUM, 3, ' ' },
220 { "Tal1E3", TYPE_SENUM, 127, ' ' },
221 { "Tal1E4", TYPE_UENUM, 255, ' ' },
222 { "Tal1E5", TYPE_SENUM, 32767, ' ' },
223 { "Tal1E6", TYPE_UENUM, 65535, ' ' },
224 { "Tal1E7", TYPE_SENUM, 2147483647, ' ' },
225 { "Tal1E8", TYPE_UENUM, 4294967295U, ' ' },
226 { "Tal1E9", TYPE_SENUM, 1099511627775LL, ' ' },
227 { "Tal2char", TYPE_UINT, 127, 'C' },
228 { "Tal2schar", TYPE_INT, 127, 'C' },
229 { "Tal2uchar", TYPE_UINT, 255, 'C' },
230 { "Tal2short", TYPE_INT, 32767, 'S' },
231 { "Tal2ushort", TYPE_UINT, 65535, 'S' },
232 { "Tal2int", TYPE_INT, 2147483647, 'I' },
233 { "Tal2uint", TYPE_UINT, 4294967295U, 'I' },
234 { "Tal2long", TYPE_INT, 9223372036854775807LL, 'L' },
235 { "Tal2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
236 { "Tal2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
237 { "Tal2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
238 { "Tal2bool", TYPE_UINT, 1, 'B' },
239 { "Tal2ptr", TYPE_PTR, 0, 0 },
240 { "Tal2cptr", TYPE_PTR, 0, 0 },
241 { "Tal2iptr", TYPE_PTR, 0, 0 },
242 { "Tal2float", TYPE_FLOAT, 0, 0 },
243 { "Tal2double", TYPE_FLOAT, 0, 0 },
244 { "Tal2ldouble", TYPE_FLOAT, 0, 0 },
245 { "Tal2E0", TYPE_UENUM, 0, ' ' },
246 { "Tal2E1", TYPE_UENUM, 1, ' ' },
247 { "Tal2E2", TYPE_SENUM, 3, ' ' },
248 { "Tal2E3", TYPE_SENUM, 127, ' ' },
249 { "Tal2E4", TYPE_UENUM, 255, ' ' },
250 { "Tal2E5", TYPE_SENUM, 32767, ' ' },
251 { "Tal2E6", TYPE_UENUM, 65535, ' ' },
252 { "Tal2E7", TYPE_SENUM, 2147483647, ' ' },
253 { "Tal2E8", TYPE_UENUM, 4294967295U, ' ' },
254 { "Tal2E9", TYPE_SENUM, 1099511627775LL, ' ' },
255 { "Tal4char", TYPE_UINT, 127, 'C' },
256 { "Tal4schar", TYPE_INT, 127, 'C' },
257 { "Tal4uchar", TYPE_UINT, 255, 'C' },
258 { "Tal4short", TYPE_INT, 32767, 'S' },
259 { "Tal4ushort", TYPE_UINT, 65535, 'S' },
260 { "Tal4int", TYPE_INT, 2147483647, 'I' },
261 { "Tal4uint", TYPE_UINT, 4294967295U, 'I' },
262 { "Tal4long", TYPE_INT, 9223372036854775807LL, 'L' },
263 { "Tal4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
264 { "Tal4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
265 { "Tal4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
266 { "Tal4bool", TYPE_UINT, 1, 'B' },
267 { "Tal4ptr", TYPE_PTR, 0, 0 },
268 { "Tal4cptr", TYPE_PTR, 0, 0 },
269 { "Tal4iptr", TYPE_PTR, 0, 0 },
270 { "Tal4float", TYPE_FLOAT, 0, 0 },
271 { "Tal4double", TYPE_FLOAT, 0, 0 },
272 { "Tal4ldouble", TYPE_FLOAT, 0, 0 },
273 { "Tal4E0", TYPE_UENUM, 0, ' ' },
274 { "Tal4E1", TYPE_UENUM, 1, ' ' },
275 { "Tal4E2", TYPE_SENUM, 3, ' ' },
276 { "Tal4E3", TYPE_SENUM, 127, ' ' },
277 { "Tal4E4", TYPE_UENUM, 255, ' ' },
278 { "Tal4E5", TYPE_SENUM, 32767, ' ' },
279 { "Tal4E6", TYPE_UENUM, 65535, ' ' },
280 { "Tal4E7", TYPE_SENUM, 2147483647, ' ' },
281 { "Tal4E8", TYPE_UENUM, 4294967295U, ' ' },
282 { "Tal4E9", TYPE_SENUM, 1099511627775LL, ' ' },
283 { "Tal8char", TYPE_UINT, 127, 'C' },
284 { "Tal8schar", TYPE_INT, 127, 'C' },
285 { "Tal8uchar", TYPE_UINT, 255, 'C' },
286 { "Tal8short", TYPE_INT, 32767, 'S' },
287 { "Tal8ushort", TYPE_UINT, 65535, 'S' },
288 { "Tal8int", TYPE_INT, 2147483647, 'I' },
289 { "Tal8uint", TYPE_UINT, 4294967295U, 'I' },
290 { "Tal8long", TYPE_INT, 9223372036854775807LL, 'L' },
291 { "Tal8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
292 { "Tal8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
293 { "Tal8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
294 { "Tal8bool", TYPE_UINT, 1, 'B' },
295 { "Tal8ptr", TYPE_PTR, 0, 0 },
296 { "Tal8cptr", TYPE_PTR, 0, 0 },
297 { "Tal8iptr", TYPE_PTR, 0, 0 },
298 { "Tal8float", TYPE_FLOAT, 0, 0 },
299 { "Tal8double", TYPE_FLOAT, 0, 0 },
300 { "Tal8ldouble", TYPE_FLOAT, 0, 0 },
301 { "Tal8E0", TYPE_UENUM, 0, ' ' },
302 { "Tal8E1", TYPE_UENUM, 1, ' ' },
303 { "Tal8E2", TYPE_SENUM, 3, ' ' },
304 { "Tal8E3", TYPE_SENUM, 127, ' ' },
305 { "Tal8E4", TYPE_UENUM, 255, ' ' },
306 { "Tal8E5", TYPE_SENUM, 32767, ' ' },
307 { "Tal8E6", TYPE_UENUM, 65535, ' ' },
308 { "Tal8E7", TYPE_SENUM, 2147483647, ' ' },
309 { "Tal8E8", TYPE_UENUM, 4294967295U, ' ' },
310 { "Tal8E9", TYPE_SENUM, 1099511627775LL, ' ' },
311 { "Tal16char", TYPE_UINT, 127, 'C' },
312 { "Tal16schar", TYPE_INT, 127, 'C' },
313 { "Tal16uchar", TYPE_UINT, 255, 'C' },
314 { "Tal16short", TYPE_INT, 32767, 'S' },
315 { "Tal16ushort", TYPE_UINT, 65535, 'S' },
316 { "Tal16int", TYPE_INT, 2147483647, 'I' },
317 { "Tal16uint", TYPE_UINT, 4294967295U, 'I' },
318 { "Tal16long", TYPE_INT, 9223372036854775807LL, 'L' },
319 { "Tal16ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
320 { "Tal16llong", TYPE_INT, 9223372036854775807LL, 'Q' },
321 { "Tal16ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
322 { "Tal16bool", TYPE_UINT, 1, 'B' },
323 { "Tal16ptr", TYPE_PTR, 0, 0 },
324 { "Tal16cptr", TYPE_PTR, 0, 0 },
325 { "Tal16iptr", TYPE_PTR, 0, 0 },
326 { "Tal16float", TYPE_FLOAT, 0, 0 },
327 { "Tal16double", TYPE_FLOAT, 0, 0 },
328 { "Tal16ldouble", TYPE_FLOAT, 0, 0 },
329 { "Tal16E0", TYPE_UENUM, 0, ' ' },
330 { "Tal16E1", TYPE_UENUM, 1, ' ' },
331 { "Tal16E2", TYPE_SENUM, 3, ' ' },
332 { "Tal16E3", TYPE_SENUM, 127, ' ' },
333 { "Tal16E4", TYPE_UENUM, 255, ' ' },
334 { "Tal16E5", TYPE_SENUM, 32767, ' ' },
335 { "Tal16E6", TYPE_UENUM, 65535, ' ' },
336 { "Tal16E7", TYPE_SENUM, 2147483647, ' ' },
337 { "Tal16E8", TYPE_UENUM, 4294967295U, ' ' },
338 { "Tal16E9", TYPE_SENUM, 1099511627775LL, ' ' }
339 #define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0]))
342 struct types bitfld_types[NTYPES2];
344 struct types aligned_bitfld_types[NATYPES2];
345 int n_aligned_bitfld_types;
347 const char *attributes[] = {
368 #define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0]))
385 enum ETYPE etype : 8;
390 unsigned char arr_len;
393 /* Used to chain together entries in the hash table. */
396 struct types attrib_array_types[] = {
397 { "Talx1char", TYPE_UINT, 127, 'C' },
398 { "Talx1schar", TYPE_INT, 127, 'C' },
399 { "Talx1uchar", TYPE_UINT, 255, 'C' },
400 { "Talx1short", TYPE_INT, 32767, 'S' },
401 { "Talx1ushort", TYPE_UINT, 65535, 'S' },
402 { "Talx1int", TYPE_INT, 2147483647, 'I' },
403 { "Talx1uint", TYPE_UINT, 4294967295U, 'I' },
404 { "Talx1long", TYPE_INT, 9223372036854775807LL, 'L' },
405 { "Talx1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
406 { "Talx1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
407 { "Talx1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
408 { "Talx1bool", TYPE_UINT, 1, 'B' },
409 { "Talx1ptr", TYPE_PTR, 0, 0 },
410 { "Talx1cptr", TYPE_PTR, 0, 0 },
411 { "Talx1iptr", TYPE_PTR, 0, 0 },
412 { "Talx1float", TYPE_FLOAT, 0, 0 },
413 { "Talx1double", TYPE_FLOAT, 0, 0 },
414 { "Talx1ldouble", TYPE_FLOAT, 0, 0 },
415 { "Talx1E0", TYPE_UENUM, 0, ' ' },
416 { "Talx1E1", TYPE_UENUM, 1, ' ' },
417 { "Talx1E2", TYPE_SENUM, 3, ' ' },
418 { "Talx1E3", TYPE_SENUM, 127, ' ' },
419 { "Talx1E4", TYPE_UENUM, 255, ' ' },
420 { "Talx1E5", TYPE_SENUM, 32767, ' ' },
421 { "Talx1E6", TYPE_UENUM, 65535, ' ' },
422 { "Talx1E7", TYPE_SENUM, 2147483647, ' ' },
423 { "Talx1E8", TYPE_UENUM, 4294967295U, ' ' },
424 { "Talx1E9", TYPE_SENUM, 1099511627775LL, ' ' },
425 { "Talx2short", TYPE_INT, 32767, 'S' },
426 { "Talx2ushort", TYPE_UINT, 65535, 'S' },
427 { "Talx2int", TYPE_INT, 2147483647, 'I' },
428 { "Talx2uint", TYPE_UINT, 4294967295U, 'I' },
429 { "Talx2long", TYPE_INT, 9223372036854775807LL, 'L' },
430 { "Talx2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
431 { "Talx2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
432 { "Talx2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
433 { "Talx2ptr", TYPE_PTR, 0, 0 },
434 { "Talx2cptr", TYPE_PTR, 0, 0 },
435 { "Talx2iptr", TYPE_PTR, 0, 0 },
436 { "Talx2float", TYPE_FLOAT, 0, 0 },
437 { "Talx2double", TYPE_FLOAT, 0, 0 },
438 { "Talx2ldouble", TYPE_FLOAT, 0, 0 },
439 { "Talx2E0", TYPE_UENUM, 0, ' ' },
440 { "Talx2E1", TYPE_UENUM, 1, ' ' },
441 { "Talx2E2", TYPE_SENUM, 3, ' ' },
442 { "Talx2E3", TYPE_SENUM, 127, ' ' },
443 { "Talx2E4", TYPE_UENUM, 255, ' ' },
444 { "Talx2E5", TYPE_SENUM, 32767, ' ' },
445 { "Talx2E6", TYPE_UENUM, 65535, ' ' },
446 { "Talx2E7", TYPE_SENUM, 2147483647, ' ' },
447 { "Talx2E8", TYPE_UENUM, 4294967295U, ' ' },
448 { "Talx2E9", TYPE_SENUM, 1099511627775LL, ' ' },
449 { "Talx4int", TYPE_INT, 2147483647, 'I' },
450 { "Talx4uint", TYPE_UINT, 4294967295U, 'I' },
451 { "Talx4long", TYPE_INT, 9223372036854775807LL, 'L' },
452 { "Talx4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
453 { "Talx4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
454 { "Talx4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
455 { "Talx4ptr", TYPE_PTR, 0, 0 },
456 { "Talx4cptr", TYPE_PTR, 0, 0 },
457 { "Talx4iptr", TYPE_PTR, 0, 0 },
458 { "Talx4float", TYPE_FLOAT, 0, 0 },
459 { "Talx4double", TYPE_FLOAT, 0, 0 },
460 { "Talx4ldouble", TYPE_FLOAT, 0, 0 },
461 { "Talx4E0", TYPE_UENUM, 0, ' ' },
462 { "Talx4E1", TYPE_UENUM, 1, ' ' },
463 { "Talx4E2", TYPE_SENUM, 3, ' ' },
464 { "Talx4E3", TYPE_SENUM, 127, ' ' },
465 { "Talx4E4", TYPE_UENUM, 255, ' ' },
466 { "Talx4E5", TYPE_SENUM, 32767, ' ' },
467 { "Talx4E6", TYPE_UENUM, 65535, ' ' },
468 { "Talx4E7", TYPE_SENUM, 2147483647, ' ' },
469 { "Talx4E8", TYPE_UENUM, 4294967295U, ' ' },
470 { "Talx4E9", TYPE_SENUM, 1099511627775LL, ' ' },
471 { "Taly8long", TYPE_INT, 9223372036854775807LL, 'L' },
472 { "Taly8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
473 { "Talx8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
474 { "Talx8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
475 { "Taly8ptr", TYPE_PTR, 0, 0 },
476 { "Taly8cptr", TYPE_PTR, 0, 0 },
477 { "Taly8iptr", TYPE_PTR, 0, 0 },
478 { "Talx8double", TYPE_FLOAT, 0, 0 },
479 { "Talx8ldouble", TYPE_FLOAT, 0, 0 }
480 #define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0]))
483 /* A prime number giving the number of slots in the hash table. */
484 #define HASH_SIZE 32749
485 static struct entry *hash_table[HASH_SIZE];
487 static int idx, limidx, output_one, short_enums;
488 static const char *destdir;
489 static const char *srcdir;
493 switchfiles (int fields)
496 static char *destbuf, *destptr;
507 size_t len = strlen (destdir);
508 destbuf = malloc (len + 20);
511 memcpy (destbuf, destdir, len);
512 if (!len || destbuf[len - 1] != '/')
513 destbuf[len++] = '/';
514 destptr = destbuf + len;
516 sprintf (destptr, "t%03d_main.C", filecnt);
517 outfile = fopen (destbuf, "w");
521 fputs ("failed to create test files\n", stderr);
525 /* { dg-options \"-I%s\" } */\n\
526 /* { dg-options \"-I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
527 /* { dg-options \"-I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
528 #include \"struct-layout-1.h\"\n\
530 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
531 #include \"t%03d_test.h\"\n\
536 #define TX(n, type, attrs, fields, ops) test##n ();\n\
537 #include \"t%03d_test.h\"\n\
545 }\n", srcdir, srcdir, srcdir, filecnt, filecnt);
547 sprintf (destptr, "t%03d_x.C", filecnt);
548 outfile = fopen (destbuf, "w");
552 /* { dg-options \"-w -I%s\" } */\n\
553 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
554 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
555 #include \"struct-layout-1_x1.h\"\n\
556 #include \"t%03d_test.h\"\n\
557 #include \"struct-layout-1_x2.h\"\n\
558 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
560 sprintf (destptr, "t%03d_y.C", filecnt);
561 outfile = fopen (destbuf, "w");
565 /* { dg-options \"-w -I%s\" } */\n\
566 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
567 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
568 #include \"struct-layout-1_y1.h\"\n\
569 #include \"t%03d_test.h\"\n\
570 #include \"struct-layout-1_y2.h\"\n\
571 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
573 sprintf (destptr, "t%03d_test.h", filecnt);
574 outfile = fopen (destbuf, "w");
579 else if (fields <= 4)
581 else if (fields <= 6)
587 unsigned long long int
590 unsigned long long int ret;
591 ret = generate_random () & 0xffffff;
592 ret |= (generate_random () & 0xffffffLL) << 24;
593 ret |= ((unsigned long long int) generate_random ()) << 48;
598 subfield (struct entry *e, char *letter)
607 case ETYPE_STRUCT_ARRAY:
608 case ETYPE_UNION_ARRAY:
609 type = e[0].attrib ? 1 + (generate_random () & 3) : 0;
610 if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY)
614 if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY)
616 if (e[0].arr_len == 255)
617 snprintf (buf, 20, "%c[]", *letter);
619 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
620 /* If this is an array type, do not put aligned attributes on
621 elements. Aligning elements to a value greater than their
622 size will result in a compiler error. */
624 && ((strncmp (e[0].attrib, "atal", 4) == 0)
625 || strncmp (e[0].attrib, "atpaal", 6) == 0))
639 fprintf (outfile, "%s{", p);
642 fprintf (outfile, "%s %s{", e[0].attrib, p);
645 fprintf (outfile, "%s %s{", p, e[0].attrib);
649 for (i = 1; i <= e[0].len; )
650 i += subfield (e + i, letter);
657 fprintf (outfile, "}%s;", buf);
660 fprintf (outfile, "}%s %s;", e[0].attrib, buf);
663 fprintf (outfile, "}%s %s;", buf, e[0].attrib);
669 if (e[0].etype == ETYPE_ARRAY)
671 if (e[0].arr_len == 255)
672 snprintf (buf, 20, "%c[]", *letter);
674 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
684 /* If this is an array type, do not put aligned attributes on
685 elements. Aligning elements to a value greater than their
686 size will result in a compiler error. */
687 if (e[0].etype == ETYPE_ARRAY
688 && ((strncmp (e[0].attrib, "atal", 4) == 0)
689 || strncmp (e[0].attrib, "atpaal", 6) == 0))
692 type = generate_random () % 3;
696 fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name,
700 fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib,
704 fprintf (outfile, "%s %s %s;", e[0].type->name, buf,
710 fprintf (outfile, "%s %s;", e[0].type->name, buf);
716 switch (generate_random () % 3)
719 fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name);
722 fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib);
725 fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib);
729 fprintf (outfile, "%s:0;", e[0].type->name);
733 snprintf (buf, 20, "%d", e[0].len);
735 switch (generate_random () % 3)
738 fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name,
742 fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib,
746 fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter,
751 fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf);
762 output_FNB (char mode, struct entry *e)
764 unsigned long long int l1, l2, m;
768 if (e->type->type == TYPE_OTHER)
772 fprintf (outfile, "N(%d,%s)", idx, namebuf);
775 fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf);
778 switch (e->type->type)
781 signs = generate_random () & 3;
784 m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1;
787 fprintf (outfile, "%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s",
788 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
789 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
794 m &= (1ULL << e->len) - 1;
797 fprintf (outfile,"%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s",
798 l1, l1 > 4294967295U ? "LL" : "",
799 l2, l2 > 4294967295U ? "LL" : "");
804 signs = generate_random () & 3;
805 fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "",
806 ((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64);
809 if (e->type->maxval == 0)
810 fputs ("e0_0,e0_0", outfile);
811 else if (e->type->maxval == 1)
812 fprintf (outfile, "e1_%" COMPAT_PRLL "d,e1_%" COMPAT_PRLL "d",
816 p = strchr (e->type->name, '\0');
817 while (--p >= e->type->name && *p >= '0' && *p <= '9');
822 l1 += e->type->maxval - 6;
824 l2 += e->type->maxval - 6;
825 fprintf (outfile, "e%s_%" COMPAT_PRLL "d,e%s_%" COMPAT_PRLL "d",
830 p = strchr (e->type->name, '\0');
831 while (--p >= e->type->name && *p >= '0' && *p <= '9');
835 fprintf (outfile, "e%s_%s%" COMPAT_PRLL "d,e%s_%s%" COMPAT_PRLL "d",
836 p, l1 < 3 ? "m" : "",
837 l1 == 3 ? 0LL : e->type->maxval - (l1 & 3),
838 p, l2 < 3 ? "m" : "",
839 l2 == 3 ? 0LL : e->type->maxval - (l2 & 3));
845 "(%s)&intarray[%" COMPAT_PRLL "d], (%s)&intarray[%" COMPAT_PRLL "d]",
846 e->type->name, l1, e->type->name, l2);
852 "fn%" COMPAT_PRLL "d,fn%" COMPAT_PRLL "d", l1, l2);
857 fputs (")", outfile);
861 subvalues (struct entry *e, char *p, char *letter)
865 if (p >= namebuf + sizeof (namebuf) - 32)
872 case ETYPE_STRUCT_ARRAY:
873 case ETYPE_UNION_ARRAY:
874 if (e[0].arr_len == 0 || e[0].arr_len == 255)
876 *letter += 1 + e[0].len;
879 i = generate_random () % e[0].arr_len;
880 snprintf (p, sizeof (namebuf) - (p - namebuf) - 1,
881 "%c[%d]", *letter, i);
882 q = strchr (p, '\0');
888 for (i = 1; i <= e[0].len; )
890 i += subvalues (e + i, q, letter);
891 if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY)
893 *letter += e[0].len - i + 1;
903 if (e[0].arr_len == 0 || e[0].arr_len == 255)
908 i = generate_random () % e[0].arr_len;
909 snprintf (p, sizeof (namebuf) - (p - namebuf),
910 "%c[%d]", *letter, i);
912 if ((generate_random () & 7) == 0)
914 j = generate_random () % e[0].arr_len;
917 snprintf (p, sizeof (namebuf) - (p - namebuf),
918 "%c[%d]", *letter, j);
933 --------------------------------------------------------------------
934 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
935 hash(), hash2(), hash3, and mix() are externally useful functions.
936 Routines to test the hash are included if SELF_TEST is defined.
937 You can use this free for any purpose. It has no warranty.
938 --------------------------------------------------------------------
942 --------------------------------------------------------------------
943 mix -- mix 3 32-bit values reversibly.
944 For every delta with one or two bit set, and the deltas of all three
945 high bits or all three low bits, whether the original value of a,b,c
946 is almost all zero or is uniformly distributed,
947 * If mix() is run forward or backward, at least 32 bits in a,b,c
948 have at least 1/4 probability of changing.
949 * If mix() is run forward, every bit of c will change between 1/3 and
950 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
951 mix() was built out of 36 single-cycle latency instructions in a
952 structure that could supported 2x parallelism, like so:
960 Unfortunately, superscalar Pentiums and Sparcs can't take advantage
961 of that parallelism. They've also turned some of those single-cycle
962 latency instructions into multi-cycle latency instructions. Still,
963 this is the fastest good hash I could find. There were about 2^^68
964 to choose from. I only looked at a billion or so.
965 --------------------------------------------------------------------
967 /* same, but slower, works on systems that might have 8 byte hashval_t's */
970 a -= b; a -= c; a ^= (c>>13); \
971 b -= c; b -= a; b ^= (a<< 8); \
972 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
973 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
974 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
975 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
976 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
977 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
978 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
982 --------------------------------------------------------------------
983 hash() -- hash a variable-length key into a 32-bit value
984 k : the key (the unaligned variable-length array of bytes)
985 len : the length of the key, counting by bytes
986 level : can be any 4-byte value
987 Returns a 32-bit value. Every bit of the key affects every bit of
988 the return value. Every 1-bit and 2-bit delta achieves avalanche.
989 About 36+6len instructions.
991 The best hash table sizes are powers of 2. There is no need to do
992 mod a prime (mod is sooo slow!). If you need less than 32 bits,
993 use a bitmask. For example, if you need only 10 bits, do
994 h = (h & hashmask(10));
995 In which case, the hash table should have hashsize(10) elements.
997 If you are hashing n strings (ub1 **)k, do it like this:
998 for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
1000 By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
1001 code any way you wish, private, educational, or commercial. It's free.
1003 See http://burtleburtle.net/bob/hash/evahash.html
1004 Use for hash table lookup, or anything where one collision in 2^32 is
1005 acceptable. Do NOT use for cryptographic purposes.
1006 --------------------------------------------------------------------
1010 iterative_hash (const void *k_in /* the key */,
1011 register size_t length /* the length of the key */,
1012 register hashval_t initval /* the previous hash, or
1013 an arbitrary value */)
1015 register const unsigned char *k = (const unsigned char *)k_in;
1016 register hashval_t a,b,c,len;
1018 /* Set up the internal state */
1020 a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
1021 c = initval; /* the previous hash value */
1023 /*---------------------------------------- handle most of the key */
1026 a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24));
1027 b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24));
1028 c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24));
1033 /*------------------------------------- handle the last 11 bytes */
1035 switch(len) /* all the case statements fall through */
1037 case 11: c+=((hashval_t)k[10]<<24);
1038 case 10: c+=((hashval_t)k[9]<<16);
1039 case 9 : c+=((hashval_t)k[8]<<8);
1040 /* the first byte of c is reserved for the length */
1041 case 8 : b+=((hashval_t)k[7]<<24);
1042 case 7 : b+=((hashval_t)k[6]<<16);
1043 case 6 : b+=((hashval_t)k[5]<<8);
1045 case 4 : a+=((hashval_t)k[3]<<24);
1046 case 3 : a+=((hashval_t)k[2]<<16);
1047 case 2 : a+=((hashval_t)k[1]<<8);
1049 /* case 0: nothing left to add */
1052 /*-------------------------------------------- report the result */
1057 e_hash (const void *a)
1059 const struct entry *e = a;
1063 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1065 for (i = 0; i <= e[0].len; ++i)
1068 ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret);
1069 attriblen = e[i].attrib ? strlen (e[i].attrib) : -1;
1070 ret = iterative_hash (&attriblen, sizeof (int), ret);
1072 ret = iterative_hash (e[i].attrib, attriblen, ret);
1078 e_eq (const void *a, const void *b)
1080 const struct entry *ea = a, *eb = b;
1082 if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION)
1084 if (ea[0].len != eb[0].len)
1086 for (i = 0; i <= ea[0].len; ++i)
1088 if (ea[i].etype != eb[i].etype
1089 || ea[i].len != eb[i].len
1090 || ea[i].arr_len != eb[i].arr_len
1091 || ea[i].type != eb[i].type)
1093 if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL))
1095 if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0)
1102 e_exists (const struct entry *e)
1108 for (h = hash_table[hval % HASH_SIZE]; h; h = h->next)
1115 e_insert (struct entry *e)
1120 e->next = hash_table[hval % HASH_SIZE];
1121 hash_table[hval % HASH_SIZE] = e;
1125 output (struct entry *e)
1131 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1137 n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry));
1138 memcpy (n, e, (e[0].len + 1) * sizeof (struct entry));
1142 switchfiles (e[0].len);
1144 if (e[0].etype == ETYPE_STRUCT)
1145 fprintf (outfile, "T(%d,", idx);
1147 fprintf (outfile, "U(%d,", idx);
1149 for (i = 1; i <= e[0].len; )
1150 i += subfield (e + i, &c);
1151 fputs (",", outfile);
1153 for (i = 1; i <= e[0].len; )
1155 i += subvalues (e + i, namebuf, &c);
1156 if (e[0].etype == ETYPE_UNION)
1159 fputs (")\n", outfile);
1160 if (output_one && idx == limidx)
1168 FEATURE_ALIGNEDPACKED = 2,
1169 FEATURE_ZEROARRAY = 4,
1170 FEATURE_ZEROBITFLD = 8,
1171 ALL_FEATURES = FEATURE_VECTOR | FEATURE_ZEROARRAY
1172 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD
1176 singles (enum FEATURE features)
1180 memset (e, 0, sizeof (e));
1181 e[0].etype = ETYPE_STRUCT;
1183 e[0].etype = ETYPE_UNION;
1186 for (i = 0; i < NTYPES2; ++i)
1188 e[0].etype = ETYPE_STRUCT;
1189 e[1].etype = ETYPE_TYPE;
1190 e[1].type = &base_types[i];
1192 e[0].etype = ETYPE_UNION;
1195 if (features & FEATURE_VECTOR)
1196 for (i = 0; i < NVTYPES2; ++i)
1198 e[0].etype = ETYPE_STRUCT;
1199 e[1].etype = ETYPE_TYPE;
1200 e[1].type = &vector_types[i];
1202 e[0].etype = ETYPE_UNION;
1208 choose_type (enum FEATURE features, struct entry *e, int r, int in_array)
1212 i = NTYPES2 - NTYPES1;
1213 if (features & FEATURE_VECTOR)
1224 if (r < NTYPES2 - NTYPES1)
1225 e->type = &base_types[r + NTYPES1];
1226 r -= NTYPES2 - NTYPES1;
1227 if (e->type == NULL && (features & FEATURE_VECTOR))
1230 e->type = &vector_types[r];
1233 if (e->type == NULL && !in_array)
1236 e->type = &attrib_types[r];
1239 if (e->type == NULL && in_array)
1242 e->type = &attrib_array_types[r];
1245 if (e->type == NULL)
1249 /* This is from gcc.c-torture/execute/builtin-bitops-1.c. */
1251 my_ffsll (unsigned long long x)
1256 /* We've tested LLONG_MAX for 64 bits so this should be safe. */
1257 for (i = 0; i < 64; i++)
1258 if (x & (1ULL << i))
1264 generate_fields (enum FEATURE features, struct entry *e, struct entry *parent,
1267 int r, i, j, ret = 1, n, incr, sametype;
1269 for (n = 0; n < len; n += incr)
1271 r = generate_random ();
1272 /* 50% ETYPE_TYPE base_types NTYPES1
1273 12.5% ETYPE_TYPE other
1276 12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1286 e[n].etype = ETYPE_TYPE;
1287 e[n].type = &base_types[r % NTYPES1];
1290 e[n].etype = ETYPE_TYPE;
1291 choose_type (features, &e[n], r, 0);
1294 e[n].etype = ETYPE_ARRAY;
1298 e[n].type = &base_types[r % NTYPES1];
1300 choose_type (features, &e[n], r, 1);
1301 r = generate_random ();
1302 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1305 if (n == len - 1 && (r & 4)
1306 && (parent->etype == ETYPE_STRUCT
1307 || parent->etype == ETYPE_STRUCT_ARRAY))
1310 for (k = 0; k < n; ++k)
1311 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1318 else if ((r & 3) != 3)
1319 e[n].arr_len = (r >> 2) & 7;
1321 e[n].arr_len = (r >> 2) & 31;
1334 incr = 1 + (r >> 3) % (len - n);
1339 incr = 1 + (r >> 3) % (len - n);
1342 for (j = n; j < n + incr; ++j)
1346 e[j].etype = ETYPE_BITFLD;
1347 if (j == n || !sametype)
1350 r = generate_random ();
1355 = &aligned_bitfld_types[r % n_aligned_bitfld_types];
1358 = &bitfld_types[r % n_bitfld_types];
1361 e[j].type = e[n].type;
1362 r = generate_random ();
1365 switch (e[j].type->bitfld)
1367 case 'C': ma = 8; break;
1368 case 'S': ma = 16; break;
1369 case 'I': ma = 32; break;
1371 case 'Q': ma = 64; break;
1372 case 'B': ma = 1; break;
1374 if (e[j].type->type == TYPE_UENUM)
1375 mi = my_ffsll (e[j].type->maxval + 1) - 1;
1376 else if (e[j].type->type == TYPE_SENUM)
1377 mi = my_ffsll (e[j].type->maxval + 1);
1384 else if (mi > 16 || !short_enums)
1395 if (sametype && (r & 3) == 0 && ma > 1)
1398 for (k = n; k < j; ++k)
1401 e[j].len = sum ? ma - sum : ma;
1404 if (!sametype && (r & 7) == 0)
1407 if (! (features & FEATURE_ZEROBITFLD) && mi == 0)
1409 if (e[j].len < mi || e[j].len > ma)
1410 e[j].len = mi + (r % (ma + 1 - mi));
1412 if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0
1423 e[n].etype = ETYPE_STRUCT;
1427 e[n].etype = ETYPE_UNION;
1431 e[n].etype = ETYPE_STRUCT_ARRAY;
1434 e[n].etype = ETYPE_UNION_ARRAY;
1438 e[n].len = r % (len - n);
1439 incr = 1 + e[n].len;
1440 generate_fields (features, &e[n + 1], &e[n], e[n].len);
1441 if (e[n].etype == ETYPE_STRUCT_ARRAY
1442 || e[n].etype == ETYPE_UNION_ARRAY)
1444 r = generate_random ();
1445 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1448 if (n + incr == len && (r & 4)
1449 && (parent->etype == ETYPE_STRUCT
1450 || parent->etype == ETYPE_STRUCT_ARRAY))
1453 for (k = 0; k < n; ++k)
1454 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1461 else if ((r & 3) != 3)
1462 e[n].arr_len = (r >> 2) & 7;
1464 e[n].arr_len = (r >> 2) & 31;
1468 r = generate_random ();
1472 i = (features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1;
1473 e[n].attrib = attributes[r % i];
1474 if (! (features & FEATURE_ALIGNEDPACKED)
1475 && strcmp (e[n].attrib, "atpa") == 0
1476 && ((e[n].type >= &attrib_types[0]
1477 && e[n].type < &attrib_types[NATYPES2])
1478 || (e[n].type >= &attrib_array_types[0]
1479 && e[n].type < &attrib_array_types[NAATYPES2])
1480 || (e[n].type >= &aligned_bitfld_types[0]
1481 && e[n].type < &aligned_bitfld_types[n_aligned_bitfld_types])))
1488 generate_random_tests (enum FEATURE features, int len)
1490 struct entry e[len + 1];
1492 if (len > 'z' - 'a' + 1)
1494 memset (e, 0, sizeof (e));
1495 r = generate_random ();
1497 e[0].etype = ETYPE_UNION;
1499 e[0].etype = ETYPE_STRUCT;
1502 generate_fields (features, &e[1], &e[0], len);
1506 struct { const char *name; enum FEATURE f; }
1509 { "vector", FEATURE_VECTOR },
1510 { "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD },
1512 FEATURE_VECTOR | FEATURE_ZEROARRAY },
1513 { "aligned packed vector [0] :0",
1514 FEATURE_VECTOR | FEATURE_ZEROARRAY
1515 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD },
1519 main (int argc, char **argv)
1521 int i, j, count, c, n = 3000;
1524 if (sizeof (int) != 4 || sizeof (long long) != 8)
1531 if (argv[i][0] == '-' && argv[i][2] == '\0')
1533 optarg = argv[i + 1];
1549 limidx = atoi (optarg);
1556 fprintf (stderr, "unrecognized option %s\n", argv[i]);
1564 outfile = fopen ("/dev/null", "w");
1565 if (outfile == NULL)
1567 fputs ("could not open /dev/null", stderr);
1573 if (destdir == NULL && !output_one)
1576 fprintf (stderr, "Usage:\n\
1577 %s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\
1578 Either -s srcdir -d destdir or -i idx must be used\n", argv[0]);
1582 if (srcdir == NULL && !output_one)
1585 for (i = 0; i < NTYPES2; ++i)
1586 if (base_types[i].bitfld)
1587 bitfld_types[n_bitfld_types++] = base_types[i];
1588 for (i = 0; i < NATYPES2; ++i)
1589 if (attrib_types[i].bitfld)
1590 aligned_bitfld_types[n_aligned_bitfld_types++] = attrib_types[i];
1591 for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i)
1600 for (j = 1; j <= 9; ++j)
1601 while (idx < startidx + j * count)
1602 generate_random_tests (features[i].f, j);
1603 while (idx < startidx + count * 10)
1604 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
1606 for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i)
1612 singles (features[i].f);
1616 while (idx < startidx + 1000)
1617 generate_random_tests (features[i].f, 1);
1623 while (idx < startidx + 100)
1624 generate_random_tests (features[i].f, 1);
1627 for (j = 2; j <= 9; ++j)
1628 while (idx < startidx + (j - 1) * count)
1629 generate_random_tests (features[i].f, j);
1630 while (idx < startidx + count * 9)
1631 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
1636 generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25));