1 /* Structure layout test generator.
2 Copyright (C) 2004, 2005, 2007, 2008, 2009, 2011
3 Free Software Foundation, Inc.
4 Contributed by Jakub Jelinek <jakub@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* Compile with gcc -o struct-layout-1_generate{,.c} generate_random{,_r}.c */
25 /* N.B. -- This program cannot use libiberty as that will not work
26 when testing an installed compiler. */
32 /* We use our own pseudo-random number generator, so that it gives the same
33 values on all hosts. */
34 #include "../../gcc.dg/compat/generate-random.h"
36 #if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL
37 # error Need 64-bit long long
40 #if defined __MSVCRT__
41 #define COMPAT_PRLL "I64"
43 #define COMPAT_PRLL "ll"
46 const char *dg_options[] = {
47 "/* { dg-options \"%s-I%s\" } */\n",
48 "/* { dg-options \"%s-I%s -mno-mmx -Wno-abi\" { target i?86-*-* x86_64-*-* } } */\n",
49 "/* { dg-options \"%s-I%s -fno-common\" { target alpha*-dec-osf* hppa*-*-hpux* powerpc*-*-darwin* *-*-mingw32* *-*-cygwin* } } */\n",
50 "/* { dg-options \"%s-I%s -mno-mmx -fno-common -Wno-abi\" { target i?86-*-darwin* x86_64-*-darwin* i?86-*-mingw32* x86_64-*-mingw32* i?86-*-cygwin* } } */\n",
51 "/* { dg-options \"%s-I%s -mno-base-addresses\" { target mmix-*-* } } */\n",
52 "/* { dg-options \"%s-I%s -mlongcalls -mtext-section-literals\" { target xtensa*-*-* } } */\n"
53 #define NDG_OPTIONS (sizeof (dg_options) / sizeof (dg_options[0]))
56 typedef unsigned int hashval_t;
74 unsigned long long int maxval;
78 struct types base_types[] = {
79 /* As we don't know whether char will be signed or not, just limit ourselves
80 to unsigned values less than maximum signed char value. */
81 { "char", TYPE_UINT, 127, 'C' },
82 { "signed char", TYPE_INT, 127, 'C' },
83 { "unsigned char", TYPE_UINT, 255, 'C' },
84 { "short int", TYPE_INT, 32767, 'S' },
85 { "unsigned short int", TYPE_UINT, 65535, 'S' },
86 { "int", TYPE_INT, 2147483647, 'I' },
87 { "unsigned int", TYPE_UINT, 4294967295U, 'I' },
88 { "long int", TYPE_INT, 9223372036854775807LL, 'L' },
89 { "unsigned long int", TYPE_UINT, 18446744073709551615ULL, 'L' },
90 { "long long int", TYPE_INT, 9223372036854775807LL, 'Q' },
91 { "unsigned long long int", TYPE_UINT, 18446744073709551615ULL, 'Q' },
92 { "bool", TYPE_UINT, 1, 'B' },
93 { "void *", TYPE_PTR, 0, 0 },
94 { "char *", TYPE_PTR, 0, 0 },
95 { "int *", TYPE_PTR, 0, 0 },
96 { "float", TYPE_FLOAT, 0, 0 },
97 { "double", TYPE_FLOAT, 0, 0 },
98 { "long double", TYPE_FLOAT, 0, 0 },
100 { "Tchar", TYPE_UINT, 127, 'C' },
101 { "Tschar", TYPE_INT, 127, 'C' },
102 { "Tuchar", TYPE_UINT, 255, 'C' },
103 { "Tshort", TYPE_INT, 32767, 'S' },
104 { "Tushort", TYPE_UINT, 65535, 'S' },
105 { "Tint", TYPE_INT, 2147483647, 'I' },
106 { "Tuint", TYPE_UINT, 4294967295U, 'I' },
107 { "Tlong", TYPE_INT, 9223372036854775807LL, 'L' },
108 { "Tulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
109 { "Tllong", TYPE_INT, 9223372036854775807LL, 'Q' },
110 { "Tullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
111 { "Tbool", TYPE_UINT, 1, 'B' },
112 { "size_t", TYPE_UINT, 18446744073709551615ULL, 0 },
113 { "Tptr", TYPE_PTR, 0, 0 },
114 { "Tcptr", TYPE_PTR, 0, 0 },
115 { "Tiptr", TYPE_PTR, 0, 0 },
116 { "Tfnptr", TYPE_FNPTR, 0, 0 },
117 { "Tfloat", TYPE_FLOAT, 0, 0 },
118 { "Tdouble", TYPE_FLOAT, 0, 0 },
119 { "Tldouble", TYPE_FLOAT, 0, 0 },
120 { "enum E0", TYPE_UENUM, 0, ' ' },
121 { "enum E1", TYPE_UENUM, 1, ' ' },
122 { "enum E2", TYPE_SENUM, 3, ' ' },
123 { "enum E3", TYPE_SENUM, 127, ' ' },
124 { "enum E4", TYPE_UENUM, 255, ' ' },
125 { "enum E5", TYPE_SENUM, 32767, ' ' },
126 { "enum E6", TYPE_UENUM, 65535, ' ' },
127 { "enum E7", TYPE_SENUM, 2147483647, ' ' },
128 { "enum E8", TYPE_UENUM, 4294967295U, ' ' },
129 { "enum E9", TYPE_SENUM, 1099511627775LL, ' ' },
130 { "TE0", TYPE_UENUM, 0, ' ' },
131 { "TE1", TYPE_UENUM, 1, ' ' },
132 { "TE2", TYPE_SENUM, 3, ' ' },
133 { "TE3", TYPE_SENUM, 127, ' ' },
134 { "TE4", TYPE_UENUM, 255, ' ' },
135 { "TE5", TYPE_SENUM, 32767, ' ' },
136 { "TE6", TYPE_UENUM, 65535, ' ' },
137 { "TE7", TYPE_SENUM, 2147483647, ' ' },
138 { "TE8", TYPE_UENUM, 4294967295U, ' ' },
139 { "TE9", TYPE_SENUM, 1099511627775LL, ' ' },
140 /* vector-defs.h typedefs */
141 { "qi", TYPE_INT, 127, 0 },
142 { "hi", TYPE_INT, 32767, 0 },
143 { "si", TYPE_INT, 2147483647, 0 },
144 { "di", TYPE_INT, 9223372036854775807LL, 0 },
145 { "sf", TYPE_FLOAT, 0, 0 },
146 { "df", TYPE_FLOAT, 0, 0 }
147 #define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
149 struct types vector_types[] = {
150 /* vector-defs.h typedefs */
151 { "v8qi", TYPE_OTHER, 0, 0 },
152 { "v16qi", TYPE_OTHER, 0, 0 },
153 { "v2hi", TYPE_OTHER, 0, 0 },
154 { "v4hi", TYPE_OTHER, 0, 0 },
155 { "v8hi", TYPE_OTHER, 0, 0 },
156 { "v2si", TYPE_OTHER, 0, 0 },
157 { "v4si", TYPE_OTHER, 0, 0 },
158 { "v1di", TYPE_OTHER, 0, 0 },
159 { "v2di", TYPE_OTHER, 0, 0 },
160 { "v2sf", TYPE_OTHER, 0, 0 },
161 { "v4sf", TYPE_OTHER, 0, 0 },
162 { "v16sf", TYPE_OTHER, 0, 0 },
163 { "v2df", TYPE_OTHER, 0, 0 },
164 { "u8qi", TYPE_OTHER, 0, 0 },
165 { "u16qi", TYPE_OTHER, 0, 0 },
166 { "u2hi", TYPE_OTHER, 0, 0 },
167 { "u4hi", TYPE_OTHER, 0, 0 },
168 { "u8hi", TYPE_OTHER, 0, 0 },
169 { "u2si", TYPE_OTHER, 0, 0 },
170 { "u4si", TYPE_OTHER, 0, 0 },
171 { "u1di", TYPE_OTHER, 0, 0 },
172 { "u2di", TYPE_OTHER, 0, 0 },
173 { "u2sf", TYPE_OTHER, 0, 0 },
174 { "u4sf", TYPE_OTHER, 0, 0 },
175 { "u16sf", TYPE_OTHER, 0, 0 },
176 { "u2df", TYPE_OTHER, 0, 0 },
177 { "__m64", TYPE_OTHER, 0, 0 },
178 { "__m128", TYPE_OTHER, 0, 0 }
179 #define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
181 struct types attrib_types[] = {
182 { "Talchar", TYPE_UINT, 127, 'C' },
183 { "Talschar", TYPE_INT, 127, 'C' },
184 { "Taluchar", TYPE_UINT, 255, 'C' },
185 { "Talshort", TYPE_INT, 32767, 'S' },
186 { "Talushort", TYPE_UINT, 65535, 'S' },
187 { "Talint", TYPE_INT, 2147483647, 'I' },
188 { "Taluint", TYPE_UINT, 4294967295U, 'I' },
189 { "Tallong", TYPE_INT, 9223372036854775807LL, 'L' },
190 { "Talulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
191 { "Talllong", TYPE_INT, 9223372036854775807LL, 'Q' },
192 { "Talullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
193 { "Talbool", TYPE_UINT, 1, 'B' },
194 { "Talptr", TYPE_PTR, 0, 0 },
195 { "Talcptr", TYPE_PTR, 0, 0 },
196 { "Taliptr", TYPE_PTR, 0, 0 },
197 { "Talfloat", TYPE_FLOAT, 0, 0 },
198 { "Taldouble", TYPE_FLOAT, 0, 0 },
199 { "Talldouble", TYPE_FLOAT, 0, 0 },
200 { "TalE0", TYPE_UENUM, 0, ' ' },
201 { "TalE1", TYPE_UENUM, 1, ' ' },
202 { "TalE2", TYPE_SENUM, 3, ' ' },
203 { "TalE3", TYPE_SENUM, 127, ' ' },
204 { "TalE4", TYPE_UENUM, 255, ' ' },
205 { "TalE5", TYPE_SENUM, 32767, ' ' },
206 { "TalE6", TYPE_UENUM, 65535, ' ' },
207 { "TalE7", TYPE_SENUM, 2147483647, ' ' },
208 { "TalE8", TYPE_UENUM, 4294967295U, ' ' },
209 { "TalE9", TYPE_SENUM, 1099511627775LL, ' ' },
210 { "Tal1char", TYPE_UINT, 127, 'C' },
211 { "Tal1schar", TYPE_INT, 127, 'C' },
212 { "Tal1uchar", TYPE_UINT, 255, 'C' },
213 { "Tal1short", TYPE_INT, 32767, 'S' },
214 { "Tal1ushort", TYPE_UINT, 65535, 'S' },
215 { "Tal1int", TYPE_INT, 2147483647, 'I' },
216 { "Tal1uint", TYPE_UINT, 4294967295U, 'I' },
217 { "Tal1long", TYPE_INT, 9223372036854775807LL, 'L' },
218 { "Tal1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
219 { "Tal1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
220 { "Tal1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
221 { "Tal1bool", TYPE_UINT, 1, 'B' },
222 { "Tal1ptr", TYPE_PTR, 0, 0 },
223 { "Tal1cptr", TYPE_PTR, 0, 0 },
224 { "Tal1iptr", TYPE_PTR, 0, 0 },
225 { "Tal1float", TYPE_FLOAT, 0, 0 },
226 { "Tal1double", TYPE_FLOAT, 0, 0 },
227 { "Tal1ldouble", TYPE_FLOAT, 0, 0 },
228 { "Tal1E0", TYPE_UENUM, 0, ' ' },
229 { "Tal1E1", TYPE_UENUM, 1, ' ' },
230 { "Tal1E2", TYPE_SENUM, 3, ' ' },
231 { "Tal1E3", TYPE_SENUM, 127, ' ' },
232 { "Tal1E4", TYPE_UENUM, 255, ' ' },
233 { "Tal1E5", TYPE_SENUM, 32767, ' ' },
234 { "Tal1E6", TYPE_UENUM, 65535, ' ' },
235 { "Tal1E7", TYPE_SENUM, 2147483647, ' ' },
236 { "Tal1E8", TYPE_UENUM, 4294967295U, ' ' },
237 { "Tal1E9", TYPE_SENUM, 1099511627775LL, ' ' },
238 { "Tal2char", TYPE_UINT, 127, 'C' },
239 { "Tal2schar", TYPE_INT, 127, 'C' },
240 { "Tal2uchar", TYPE_UINT, 255, 'C' },
241 { "Tal2short", TYPE_INT, 32767, 'S' },
242 { "Tal2ushort", TYPE_UINT, 65535, 'S' },
243 { "Tal2int", TYPE_INT, 2147483647, 'I' },
244 { "Tal2uint", TYPE_UINT, 4294967295U, 'I' },
245 { "Tal2long", TYPE_INT, 9223372036854775807LL, 'L' },
246 { "Tal2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
247 { "Tal2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
248 { "Tal2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
249 { "Tal2bool", TYPE_UINT, 1, 'B' },
250 { "Tal2ptr", TYPE_PTR, 0, 0 },
251 { "Tal2cptr", TYPE_PTR, 0, 0 },
252 { "Tal2iptr", TYPE_PTR, 0, 0 },
253 { "Tal2float", TYPE_FLOAT, 0, 0 },
254 { "Tal2double", TYPE_FLOAT, 0, 0 },
255 { "Tal2ldouble", TYPE_FLOAT, 0, 0 },
256 { "Tal2E0", TYPE_UENUM, 0, ' ' },
257 { "Tal2E1", TYPE_UENUM, 1, ' ' },
258 { "Tal2E2", TYPE_SENUM, 3, ' ' },
259 { "Tal2E3", TYPE_SENUM, 127, ' ' },
260 { "Tal2E4", TYPE_UENUM, 255, ' ' },
261 { "Tal2E5", TYPE_SENUM, 32767, ' ' },
262 { "Tal2E6", TYPE_UENUM, 65535, ' ' },
263 { "Tal2E7", TYPE_SENUM, 2147483647, ' ' },
264 { "Tal2E8", TYPE_UENUM, 4294967295U, ' ' },
265 { "Tal2E9", TYPE_SENUM, 1099511627775LL, ' ' },
266 { "Tal4char", TYPE_UINT, 127, 'C' },
267 { "Tal4schar", TYPE_INT, 127, 'C' },
268 { "Tal4uchar", TYPE_UINT, 255, 'C' },
269 { "Tal4short", TYPE_INT, 32767, 'S' },
270 { "Tal4ushort", TYPE_UINT, 65535, 'S' },
271 { "Tal4int", TYPE_INT, 2147483647, 'I' },
272 { "Tal4uint", TYPE_UINT, 4294967295U, 'I' },
273 { "Tal4long", TYPE_INT, 9223372036854775807LL, 'L' },
274 { "Tal4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
275 { "Tal4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
276 { "Tal4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
277 { "Tal4bool", TYPE_UINT, 1, 'B' },
278 { "Tal4ptr", TYPE_PTR, 0, 0 },
279 { "Tal4cptr", TYPE_PTR, 0, 0 },
280 { "Tal4iptr", TYPE_PTR, 0, 0 },
281 { "Tal4float", TYPE_FLOAT, 0, 0 },
282 { "Tal4double", TYPE_FLOAT, 0, 0 },
283 { "Tal4ldouble", TYPE_FLOAT, 0, 0 },
284 { "Tal4E0", TYPE_UENUM, 0, ' ' },
285 { "Tal4E1", TYPE_UENUM, 1, ' ' },
286 { "Tal4E2", TYPE_SENUM, 3, ' ' },
287 { "Tal4E3", TYPE_SENUM, 127, ' ' },
288 { "Tal4E4", TYPE_UENUM, 255, ' ' },
289 { "Tal4E5", TYPE_SENUM, 32767, ' ' },
290 { "Tal4E6", TYPE_UENUM, 65535, ' ' },
291 { "Tal4E7", TYPE_SENUM, 2147483647, ' ' },
292 { "Tal4E8", TYPE_UENUM, 4294967295U, ' ' },
293 { "Tal4E9", TYPE_SENUM, 1099511627775LL, ' ' },
294 { "Tal8char", TYPE_UINT, 127, 'C' },
295 { "Tal8schar", TYPE_INT, 127, 'C' },
296 { "Tal8uchar", TYPE_UINT, 255, 'C' },
297 { "Tal8short", TYPE_INT, 32767, 'S' },
298 { "Tal8ushort", TYPE_UINT, 65535, 'S' },
299 { "Tal8int", TYPE_INT, 2147483647, 'I' },
300 { "Tal8uint", TYPE_UINT, 4294967295U, 'I' },
301 { "Tal8long", TYPE_INT, 9223372036854775807LL, 'L' },
302 { "Tal8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
303 { "Tal8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
304 { "Tal8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
305 { "Tal8bool", TYPE_UINT, 1, 'B' },
306 { "Tal8ptr", TYPE_PTR, 0, 0 },
307 { "Tal8cptr", TYPE_PTR, 0, 0 },
308 { "Tal8iptr", TYPE_PTR, 0, 0 },
309 { "Tal8float", TYPE_FLOAT, 0, 0 },
310 { "Tal8double", TYPE_FLOAT, 0, 0 },
311 { "Tal8ldouble", TYPE_FLOAT, 0, 0 },
312 { "Tal8E0", TYPE_UENUM, 0, ' ' },
313 { "Tal8E1", TYPE_UENUM, 1, ' ' },
314 { "Tal8E2", TYPE_SENUM, 3, ' ' },
315 { "Tal8E3", TYPE_SENUM, 127, ' ' },
316 { "Tal8E4", TYPE_UENUM, 255, ' ' },
317 { "Tal8E5", TYPE_SENUM, 32767, ' ' },
318 { "Tal8E6", TYPE_UENUM, 65535, ' ' },
319 { "Tal8E7", TYPE_SENUM, 2147483647, ' ' },
320 { "Tal8E8", TYPE_UENUM, 4294967295U, ' ' },
321 { "Tal8E9", TYPE_SENUM, 1099511627775LL, ' ' },
322 { "Tal16char", TYPE_UINT, 127, 'C' },
323 { "Tal16schar", TYPE_INT, 127, 'C' },
324 { "Tal16uchar", TYPE_UINT, 255, 'C' },
325 { "Tal16short", TYPE_INT, 32767, 'S' },
326 { "Tal16ushort", TYPE_UINT, 65535, 'S' },
327 { "Tal16int", TYPE_INT, 2147483647, 'I' },
328 { "Tal16uint", TYPE_UINT, 4294967295U, 'I' },
329 { "Tal16long", TYPE_INT, 9223372036854775807LL, 'L' },
330 { "Tal16ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
331 { "Tal16llong", TYPE_INT, 9223372036854775807LL, 'Q' },
332 { "Tal16ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
333 { "Tal16bool", TYPE_UINT, 1, 'B' },
334 { "Tal16ptr", TYPE_PTR, 0, 0 },
335 { "Tal16cptr", TYPE_PTR, 0, 0 },
336 { "Tal16iptr", TYPE_PTR, 0, 0 },
337 { "Tal16float", TYPE_FLOAT, 0, 0 },
338 { "Tal16double", TYPE_FLOAT, 0, 0 },
339 { "Tal16ldouble", TYPE_FLOAT, 0, 0 },
340 { "Tal16E0", TYPE_UENUM, 0, ' ' },
341 { "Tal16E1", TYPE_UENUM, 1, ' ' },
342 { "Tal16E2", TYPE_SENUM, 3, ' ' },
343 { "Tal16E3", TYPE_SENUM, 127, ' ' },
344 { "Tal16E4", TYPE_UENUM, 255, ' ' },
345 { "Tal16E5", TYPE_SENUM, 32767, ' ' },
346 { "Tal16E6", TYPE_UENUM, 65535, ' ' },
347 { "Tal16E7", TYPE_SENUM, 2147483647, ' ' },
348 { "Tal16E8", TYPE_UENUM, 4294967295U, ' ' },
349 { "Tal16E9", TYPE_SENUM, 1099511627775LL, ' ' }
350 #define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0]))
353 struct types bitfld_types[NTYPES2];
355 struct types aligned_bitfld_types[NATYPES2];
356 int n_aligned_bitfld_types;
358 const char *attributes[] = {
379 #define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0]))
396 enum ETYPE etype : 8;
401 unsigned char arr_len;
404 /* Used to chain together entries in the hash table. */
407 struct types attrib_array_types[] = {
408 { "Talx1char", TYPE_UINT, 127, 'C' },
409 { "Talx1schar", TYPE_INT, 127, 'C' },
410 { "Talx1uchar", TYPE_UINT, 255, 'C' },
411 { "Talx1short", TYPE_INT, 32767, 'S' },
412 { "Talx1ushort", TYPE_UINT, 65535, 'S' },
413 { "Talx1int", TYPE_INT, 2147483647, 'I' },
414 { "Talx1uint", TYPE_UINT, 4294967295U, 'I' },
415 { "Talx1long", TYPE_INT, 9223372036854775807LL, 'L' },
416 { "Talx1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
417 { "Talx1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
418 { "Talx1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
419 { "Talx1bool", TYPE_UINT, 1, 'B' },
420 { "Talx1ptr", TYPE_PTR, 0, 0 },
421 { "Talx1cptr", TYPE_PTR, 0, 0 },
422 { "Talx1iptr", TYPE_PTR, 0, 0 },
423 { "Talx1float", TYPE_FLOAT, 0, 0 },
424 { "Talx1double", TYPE_FLOAT, 0, 0 },
425 { "Talx1ldouble", TYPE_FLOAT, 0, 0 },
426 { "Talx1E0", TYPE_UENUM, 0, ' ' },
427 { "Talx1E1", TYPE_UENUM, 1, ' ' },
428 { "Talx1E2", TYPE_SENUM, 3, ' ' },
429 { "Talx1E3", TYPE_SENUM, 127, ' ' },
430 { "Talx1E4", TYPE_UENUM, 255, ' ' },
431 { "Talx1E5", TYPE_SENUM, 32767, ' ' },
432 { "Talx1E6", TYPE_UENUM, 65535, ' ' },
433 { "Talx1E7", TYPE_SENUM, 2147483647, ' ' },
434 { "Talx1E8", TYPE_UENUM, 4294967295U, ' ' },
435 { "Talx1E9", TYPE_SENUM, 1099511627775LL, ' ' },
436 { "Talx2short", TYPE_INT, 32767, 'S' },
437 { "Talx2ushort", TYPE_UINT, 65535, 'S' },
438 { "Talx2int", TYPE_INT, 2147483647, 'I' },
439 { "Talx2uint", TYPE_UINT, 4294967295U, 'I' },
440 { "Talx2long", TYPE_INT, 9223372036854775807LL, 'L' },
441 { "Talx2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
442 { "Talx2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
443 { "Talx2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
444 { "Talx2ptr", TYPE_PTR, 0, 0 },
445 { "Talx2cptr", TYPE_PTR, 0, 0 },
446 { "Talx2iptr", TYPE_PTR, 0, 0 },
447 { "Talx2float", TYPE_FLOAT, 0, 0 },
448 { "Talx2double", TYPE_FLOAT, 0, 0 },
449 { "Talx2ldouble", TYPE_FLOAT, 0, 0 },
450 { "Talx2E0", TYPE_UENUM, 0, ' ' },
451 { "Talx2E1", TYPE_UENUM, 1, ' ' },
452 { "Talx2E2", TYPE_SENUM, 3, ' ' },
453 { "Talx2E3", TYPE_SENUM, 127, ' ' },
454 { "Talx2E4", TYPE_UENUM, 255, ' ' },
455 { "Talx2E5", TYPE_SENUM, 32767, ' ' },
456 { "Talx2E6", TYPE_UENUM, 65535, ' ' },
457 { "Talx2E7", TYPE_SENUM, 2147483647, ' ' },
458 { "Talx2E8", TYPE_UENUM, 4294967295U, ' ' },
459 { "Talx2E9", TYPE_SENUM, 1099511627775LL, ' ' },
460 { "Talx4int", TYPE_INT, 2147483647, 'I' },
461 { "Talx4uint", TYPE_UINT, 4294967295U, 'I' },
462 { "Talx4long", TYPE_INT, 9223372036854775807LL, 'L' },
463 { "Talx4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
464 { "Talx4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
465 { "Talx4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
466 { "Talx4ptr", TYPE_PTR, 0, 0 },
467 { "Talx4cptr", TYPE_PTR, 0, 0 },
468 { "Talx4iptr", TYPE_PTR, 0, 0 },
469 { "Talx4float", TYPE_FLOAT, 0, 0 },
470 { "Talx4double", TYPE_FLOAT, 0, 0 },
471 { "Talx4ldouble", TYPE_FLOAT, 0, 0 },
472 { "Talx4E0", TYPE_UENUM, 0, ' ' },
473 { "Talx4E1", TYPE_UENUM, 1, ' ' },
474 { "Talx4E2", TYPE_SENUM, 3, ' ' },
475 { "Talx4E3", TYPE_SENUM, 127, ' ' },
476 { "Talx4E4", TYPE_UENUM, 255, ' ' },
477 { "Talx4E5", TYPE_SENUM, 32767, ' ' },
478 { "Talx4E6", TYPE_UENUM, 65535, ' ' },
479 { "Talx4E7", TYPE_SENUM, 2147483647, ' ' },
480 { "Talx4E8", TYPE_UENUM, 4294967295U, ' ' },
481 { "Talx4E9", TYPE_SENUM, 1099511627775LL, ' ' },
482 { "Taly8long", TYPE_INT, 9223372036854775807LL, 'L' },
483 { "Taly8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
484 { "Talx8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
485 { "Talx8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
486 { "Taly8ptr", TYPE_PTR, 0, 0 },
487 { "Taly8cptr", TYPE_PTR, 0, 0 },
488 { "Taly8iptr", TYPE_PTR, 0, 0 },
489 { "Talx8double", TYPE_FLOAT, 0, 0 },
490 { "Talx8ldouble", TYPE_FLOAT, 0, 0 }
491 #define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0]))
494 /* A prime number giving the number of slots in the hash table. */
495 #define HASH_SIZE 32749
496 static struct entry *hash_table[HASH_SIZE];
498 static int idx, limidx, output_one, short_enums;
499 static const char *destdir;
500 static const char *srcdir;
501 static const char *srcdir_safe;
505 switchfiles (int fields)
508 static char *destbuf, *destptr;
521 size_t len = strlen (destdir);
522 destbuf = malloc (len + 20);
525 memcpy (destbuf, destdir, len);
526 if (!len || destbuf[len - 1] != '/')
527 destbuf[len++] = '/';
528 destptr = destbuf + len;
530 sprintf (destptr, "t%03d_main.C", filecnt);
531 outfile = fopen (destbuf, "w");
535 fputs ("failed to create test files\n", stderr);
538 for (i = 0; i < NDG_OPTIONS; i++)
539 fprintf (outfile, dg_options[i], "", srcdir_safe);
540 fprintf (outfile, "\n\
541 #include \"struct-layout-1.h\"\n\
543 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
544 #include \"t%03d_test.h\"\n\
549 #define TX(n, type, attrs, fields, ops) test##n ();\n\
550 #include \"t%03d_test.h\"\n\
558 }\n", filecnt, filecnt);
560 sprintf (destptr, "t%03d_x.C", filecnt);
561 outfile = fopen (destbuf, "w");
564 for (i = 0; i < NDG_OPTIONS; i++)
565 fprintf (outfile, dg_options[i], "-w ", srcdir_safe);
566 fprintf (outfile, "\n\
567 #include \"struct-layout-1_x1.h\"\n\
568 #include \"t%03d_test.h\"\n\
569 #include \"struct-layout-1_x2.h\"\n\
570 #include \"t%03d_test.h\"\n", filecnt, filecnt);
572 sprintf (destptr, "t%03d_y.C", filecnt);
573 outfile = fopen (destbuf, "w");
576 for (i = 0; i < NDG_OPTIONS; i++)
577 fprintf (outfile, dg_options[i], "-w ", srcdir_safe);
578 fprintf (outfile, "\n\
579 #include \"struct-layout-1_y1.h\"\n\
580 #include \"t%03d_test.h\"\n\
581 #include \"struct-layout-1_y2.h\"\n\
582 #include \"t%03d_test.h\"\n", filecnt, filecnt);
584 sprintf (destptr, "t%03d_test.h", filecnt);
585 outfile = fopen (destbuf, "w");
590 else if (fields <= 4)
592 else if (fields <= 6)
598 unsigned long long int
601 unsigned long long int ret;
602 ret = generate_random () & 0xffffff;
603 ret |= (generate_random () & 0xffffffLL) << 24;
604 ret |= ((unsigned long long int) generate_random ()) << 48;
609 subfield (struct entry *e, char *letter)
618 case ETYPE_STRUCT_ARRAY:
619 case ETYPE_UNION_ARRAY:
620 type = e[0].attrib ? 1 + (generate_random () & 3) : 0;
621 if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY)
625 if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY)
627 if (e[0].arr_len == 255)
628 snprintf (buf, 20, "%c[]", *letter);
630 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
631 /* If this is an array type, do not put aligned attributes on
632 elements. Aligning elements to a value greater than their
633 size will result in a compiler error. */
635 && ((strncmp (e[0].attrib, "atal", 4) == 0)
636 || strncmp (e[0].attrib, "atpaal", 6) == 0))
650 fprintf (outfile, "%s{", p);
653 fprintf (outfile, "%s %s{", e[0].attrib, p);
656 fprintf (outfile, "%s %s{", p, e[0].attrib);
660 for (i = 1; i <= e[0].len; )
661 i += subfield (e + i, letter);
668 fprintf (outfile, "}%s;", buf);
671 fprintf (outfile, "}%s %s;", e[0].attrib, buf);
674 fprintf (outfile, "}%s %s;", buf, e[0].attrib);
680 if (e[0].etype == ETYPE_ARRAY)
682 if (e[0].arr_len == 255)
683 snprintf (buf, 20, "%c[]", *letter);
685 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
695 /* If this is an array type, do not put aligned attributes on
696 elements. Aligning elements to a value greater than their
697 size will result in a compiler error. */
698 if (e[0].etype == ETYPE_ARRAY
699 && ((strncmp (e[0].attrib, "atal", 4) == 0)
700 || strncmp (e[0].attrib, "atpaal", 6) == 0))
703 type = generate_random () % 3;
707 fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name,
711 fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib,
715 fprintf (outfile, "%s %s %s;", e[0].type->name, buf,
721 fprintf (outfile, "%s %s;", e[0].type->name, buf);
727 switch (generate_random () % 3)
730 fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name);
733 fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib);
736 fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib);
740 fprintf (outfile, "%s:0;", e[0].type->name);
744 snprintf (buf, 20, "%d", e[0].len);
746 switch (generate_random () % 3)
749 fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name,
753 fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib,
757 fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter,
762 fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf);
773 output_FNB (char mode, struct entry *e)
775 unsigned long long int l1, l2, m;
779 if (e->type->type == TYPE_OTHER)
783 fprintf (outfile, "N(%d,%s)", idx, namebuf);
786 fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf);
789 switch (e->type->type)
792 signs = generate_random () & 3;
795 m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1;
798 fprintf (outfile, "%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s",
799 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
800 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
805 m &= (1ULL << e->len) - 1;
808 fprintf (outfile,"%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s",
809 l1, l1 > 4294967295U ? "LL" : "",
810 l2, l2 > 4294967295U ? "LL" : "");
815 signs = generate_random () & 3;
816 fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "",
817 ((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64);
820 if (e->type->maxval == 0)
821 fputs ("e0_0,e0_0", outfile);
822 else if (e->type->maxval == 1)
823 fprintf (outfile, "e1_%" COMPAT_PRLL "d,e1_%" COMPAT_PRLL "d",
827 p = strchr (e->type->name, '\0');
828 while (--p >= e->type->name && *p >= '0' && *p <= '9');
833 l1 += e->type->maxval - 6;
835 l2 += e->type->maxval - 6;
836 fprintf (outfile, "e%s_%" COMPAT_PRLL "d,e%s_%" COMPAT_PRLL "d",
841 p = strchr (e->type->name, '\0');
842 while (--p >= e->type->name && *p >= '0' && *p <= '9');
846 fprintf (outfile, "e%s_%s%" COMPAT_PRLL "d,e%s_%s%" COMPAT_PRLL "d",
847 p, l1 < 3 ? "m" : "",
848 l1 == 3 ? 0LL : e->type->maxval - (l1 & 3),
849 p, l2 < 3 ? "m" : "",
850 l2 == 3 ? 0LL : e->type->maxval - (l2 & 3));
856 "(%s)&intarray[%" COMPAT_PRLL "d], (%s)&intarray[%" COMPAT_PRLL "d]",
857 e->type->name, l1, e->type->name, l2);
863 "fn%" COMPAT_PRLL "d,fn%" COMPAT_PRLL "d", l1, l2);
868 fputs (")", outfile);
872 subvalues (struct entry *e, char *p, char *letter)
876 if (p >= namebuf + sizeof (namebuf) - 32)
883 case ETYPE_STRUCT_ARRAY:
884 case ETYPE_UNION_ARRAY:
885 if (e[0].arr_len == 0 || e[0].arr_len == 255)
887 *letter += 1 + e[0].len;
890 i = generate_random () % e[0].arr_len;
891 snprintf (p, sizeof (namebuf) - (p - namebuf) - 1,
892 "%c[%d]", *letter, i);
893 q = strchr (p, '\0');
899 for (i = 1; i <= e[0].len; )
901 i += subvalues (e + i, q, letter);
902 if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY)
904 *letter += e[0].len - i + 1;
914 if (e[0].arr_len == 0 || e[0].arr_len == 255)
919 i = generate_random () % e[0].arr_len;
920 snprintf (p, sizeof (namebuf) - (p - namebuf),
921 "%c[%d]", *letter, i);
923 if ((generate_random () & 7) == 0)
925 j = generate_random () % e[0].arr_len;
928 snprintf (p, sizeof (namebuf) - (p - namebuf),
929 "%c[%d]", *letter, j);
944 --------------------------------------------------------------------
945 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
946 hash(), hash2(), hash3, and mix() are externally useful functions.
947 Routines to test the hash are included if SELF_TEST is defined.
948 You can use this free for any purpose. It has no warranty.
949 --------------------------------------------------------------------
953 --------------------------------------------------------------------
954 mix -- mix 3 32-bit values reversibly.
955 For every delta with one or two bit set, and the deltas of all three
956 high bits or all three low bits, whether the original value of a,b,c
957 is almost all zero or is uniformly distributed,
958 * If mix() is run forward or backward, at least 32 bits in a,b,c
959 have at least 1/4 probability of changing.
960 * If mix() is run forward, every bit of c will change between 1/3 and
961 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
962 mix() was built out of 36 single-cycle latency instructions in a
963 structure that could supported 2x parallelism, like so:
971 Unfortunately, superscalar Pentiums and Sparcs can't take advantage
972 of that parallelism. They've also turned some of those single-cycle
973 latency instructions into multi-cycle latency instructions. Still,
974 this is the fastest good hash I could find. There were about 2^^68
975 to choose from. I only looked at a billion or so.
976 --------------------------------------------------------------------
978 /* same, but slower, works on systems that might have 8 byte hashval_t's */
981 a -= b; a -= c; a ^= (c>>13); \
982 b -= c; b -= a; b ^= (a<< 8); \
983 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
984 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
985 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
986 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
987 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
988 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
989 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
993 --------------------------------------------------------------------
994 hash() -- hash a variable-length key into a 32-bit value
995 k : the key (the unaligned variable-length array of bytes)
996 len : the length of the key, counting by bytes
997 level : can be any 4-byte value
998 Returns a 32-bit value. Every bit of the key affects every bit of
999 the return value. Every 1-bit and 2-bit delta achieves avalanche.
1000 About 36+6len instructions.
1002 The best hash table sizes are powers of 2. There is no need to do
1003 mod a prime (mod is sooo slow!). If you need less than 32 bits,
1004 use a bitmask. For example, if you need only 10 bits, do
1005 h = (h & hashmask(10));
1006 In which case, the hash table should have hashsize(10) elements.
1008 If you are hashing n strings (ub1 **)k, do it like this:
1009 for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
1011 By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
1012 code any way you wish, private, educational, or commercial. It's free.
1014 See http://burtleburtle.net/bob/hash/evahash.html
1015 Use for hash table lookup, or anything where one collision in 2^32 is
1016 acceptable. Do NOT use for cryptographic purposes.
1017 --------------------------------------------------------------------
1021 iterative_hash (const void *k_in /* the key */,
1022 register size_t length /* the length of the key */,
1023 register hashval_t initval /* the previous hash, or
1024 an arbitrary value */)
1026 register const unsigned char *k = (const unsigned char *)k_in;
1027 register hashval_t a,b,c,len;
1029 /* Set up the internal state */
1031 a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
1032 c = initval; /* the previous hash value */
1034 /*---------------------------------------- handle most of the key */
1037 a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24));
1038 b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24));
1039 c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24));
1044 /*------------------------------------- handle the last 11 bytes */
1046 switch(len) /* all the case statements fall through */
1048 case 11: c+=((hashval_t)k[10]<<24);
1049 case 10: c+=((hashval_t)k[9]<<16);
1050 case 9 : c+=((hashval_t)k[8]<<8);
1051 /* the first byte of c is reserved for the length */
1052 case 8 : b+=((hashval_t)k[7]<<24);
1053 case 7 : b+=((hashval_t)k[6]<<16);
1054 case 6 : b+=((hashval_t)k[5]<<8);
1056 case 4 : a+=((hashval_t)k[3]<<24);
1057 case 3 : a+=((hashval_t)k[2]<<16);
1058 case 2 : a+=((hashval_t)k[1]<<8);
1060 /* case 0: nothing left to add */
1063 /*-------------------------------------------- report the result */
1068 e_hash (const void *a)
1070 const struct entry *e = a;
1074 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1076 for (i = 0; i <= e[0].len; ++i)
1079 ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret);
1080 attriblen = e[i].attrib ? strlen (e[i].attrib) : -1;
1081 ret = iterative_hash (&attriblen, sizeof (int), ret);
1083 ret = iterative_hash (e[i].attrib, attriblen, ret);
1089 e_eq (const void *a, const void *b)
1091 const struct entry *ea = a, *eb = b;
1093 if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION)
1095 if (ea[0].len != eb[0].len)
1097 for (i = 0; i <= ea[0].len; ++i)
1099 if (ea[i].etype != eb[i].etype
1100 || ea[i].len != eb[i].len
1101 || ea[i].arr_len != eb[i].arr_len
1102 || ea[i].type != eb[i].type)
1104 if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL))
1106 if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0)
1113 e_exists (const struct entry *e)
1119 for (h = hash_table[hval % HASH_SIZE]; h; h = h->next)
1126 e_insert (struct entry *e)
1131 e->next = hash_table[hval % HASH_SIZE];
1132 hash_table[hval % HASH_SIZE] = e;
1136 output (struct entry *e)
1142 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1148 n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry));
1149 memcpy (n, e, (e[0].len + 1) * sizeof (struct entry));
1153 switchfiles (e[0].len);
1155 if (e[0].etype == ETYPE_STRUCT)
1156 fprintf (outfile, "T(%d,", idx);
1158 fprintf (outfile, "U(%d,", idx);
1160 for (i = 1; i <= e[0].len; )
1161 i += subfield (e + i, &c);
1162 fputs (",", outfile);
1164 for (i = 1; i <= e[0].len; )
1166 i += subvalues (e + i, namebuf, &c);
1167 if (e[0].etype == ETYPE_UNION)
1170 fputs (")\n", outfile);
1171 if (output_one && idx == limidx)
1179 FEATURE_ALIGNEDPACKED = 2,
1180 FEATURE_ZEROARRAY = 4,
1181 FEATURE_ZEROBITFLD = 8,
1182 ALL_FEATURES = FEATURE_VECTOR | FEATURE_ZEROARRAY
1183 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD
1187 singles (enum FEATURE features)
1191 memset (e, 0, sizeof (e));
1192 e[0].etype = ETYPE_STRUCT;
1194 e[0].etype = ETYPE_UNION;
1197 for (i = 0; i < NTYPES2; ++i)
1199 e[0].etype = ETYPE_STRUCT;
1200 e[1].etype = ETYPE_TYPE;
1201 e[1].type = &base_types[i];
1203 e[0].etype = ETYPE_UNION;
1206 if (features & FEATURE_VECTOR)
1207 for (i = 0; i < NVTYPES2; ++i)
1209 e[0].etype = ETYPE_STRUCT;
1210 e[1].etype = ETYPE_TYPE;
1211 e[1].type = &vector_types[i];
1213 e[0].etype = ETYPE_UNION;
1219 choose_type (enum FEATURE features, struct entry *e, int r, int in_array)
1223 i = NTYPES2 - NTYPES1;
1224 if (features & FEATURE_VECTOR)
1235 if (r < NTYPES2 - NTYPES1)
1236 e->type = &base_types[r + NTYPES1];
1237 r -= NTYPES2 - NTYPES1;
1238 if (e->type == NULL && (features & FEATURE_VECTOR))
1241 e->type = &vector_types[r];
1244 if (e->type == NULL && !in_array)
1247 e->type = &attrib_types[r];
1250 if (e->type == NULL && in_array)
1253 e->type = &attrib_array_types[r];
1256 if (e->type == NULL)
1260 /* This is from gcc.c-torture/execute/builtin-bitops-1.c. */
1262 my_ffsll (unsigned long long x)
1267 /* We've tested LLONG_MAX for 64 bits so this should be safe. */
1268 for (i = 0; i < 64; i++)
1269 if (x & (1ULL << i))
1275 generate_fields (enum FEATURE features, struct entry *e, struct entry *parent,
1278 int r, i, j, ret = 1, n, incr, sametype;
1280 for (n = 0; n < len; n += incr)
1282 r = generate_random ();
1283 /* 50% ETYPE_TYPE base_types NTYPES1
1284 12.5% ETYPE_TYPE other
1287 12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1297 e[n].etype = ETYPE_TYPE;
1298 e[n].type = &base_types[r % NTYPES1];
1301 e[n].etype = ETYPE_TYPE;
1302 choose_type (features, &e[n], r, 0);
1305 e[n].etype = ETYPE_ARRAY;
1309 e[n].type = &base_types[r % NTYPES1];
1311 choose_type (features, &e[n], r, 1);
1312 r = generate_random ();
1313 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1316 if (n == len - 1 && (r & 4)
1317 && (parent->etype == ETYPE_STRUCT
1318 || parent->etype == ETYPE_STRUCT_ARRAY))
1321 for (k = 0; k < n; ++k)
1322 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1329 else if ((r & 3) != 3)
1330 e[n].arr_len = (r >> 2) & 7;
1332 e[n].arr_len = (r >> 2) & 31;
1345 incr = 1 + (r >> 3) % (len - n);
1350 incr = 1 + (r >> 3) % (len - n);
1353 for (j = n; j < n + incr; ++j)
1357 e[j].etype = ETYPE_BITFLD;
1358 if (j == n || !sametype)
1361 r = generate_random ();
1366 = &aligned_bitfld_types[r % n_aligned_bitfld_types];
1369 = &bitfld_types[r % n_bitfld_types];
1372 e[j].type = e[n].type;
1373 r = generate_random ();
1376 switch (e[j].type->bitfld)
1378 case 'C': ma = 8; break;
1379 case 'S': ma = 16; break;
1380 case 'I': ma = 32; break;
1382 case 'Q': ma = 64; break;
1383 case 'B': ma = 1; break;
1385 if (e[j].type->type == TYPE_UENUM)
1386 mi = my_ffsll (e[j].type->maxval + 1) - 1;
1387 else if (e[j].type->type == TYPE_SENUM)
1388 mi = my_ffsll (e[j].type->maxval + 1);
1395 else if (mi > 16 || !short_enums)
1406 if (sametype && (r & 3) == 0 && ma > 1)
1409 for (k = n; k < j; ++k)
1412 e[j].len = sum ? ma - sum : ma;
1415 if (!sametype && (r & 7) == 0)
1418 if (! (features & FEATURE_ZEROBITFLD) && mi == 0)
1420 if (e[j].len < mi || e[j].len > ma)
1421 e[j].len = mi + (r % (ma + 1 - mi));
1423 if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0
1434 e[n].etype = ETYPE_STRUCT;
1438 e[n].etype = ETYPE_UNION;
1442 e[n].etype = ETYPE_STRUCT_ARRAY;
1445 e[n].etype = ETYPE_UNION_ARRAY;
1449 e[n].len = r % (len - n);
1450 incr = 1 + e[n].len;
1451 generate_fields (features, &e[n + 1], &e[n], e[n].len);
1452 if (e[n].etype == ETYPE_STRUCT_ARRAY
1453 || e[n].etype == ETYPE_UNION_ARRAY)
1455 r = generate_random ();
1456 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1459 if (n + incr == len && (r & 4)
1460 && (parent->etype == ETYPE_STRUCT
1461 || parent->etype == ETYPE_STRUCT_ARRAY))
1464 for (k = 0; k < n; ++k)
1465 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1472 else if ((r & 3) != 3)
1473 e[n].arr_len = (r >> 2) & 7;
1475 e[n].arr_len = (r >> 2) & 31;
1479 r = generate_random ();
1483 i = (features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1;
1484 e[n].attrib = attributes[r % i];
1485 if (! (features & FEATURE_ALIGNEDPACKED)
1486 && strcmp (e[n].attrib, "atpa") == 0
1487 && ((e[n].type >= &attrib_types[0]
1488 && e[n].type < &attrib_types[NATYPES2])
1489 || (e[n].type >= &attrib_array_types[0]
1490 && e[n].type < &attrib_array_types[NAATYPES2])
1491 || (e[n].type >= &aligned_bitfld_types[0]
1492 && e[n].type < &aligned_bitfld_types[n_aligned_bitfld_types])))
1499 generate_random_tests (enum FEATURE features, int len)
1501 struct entry e[len + 1];
1503 if (len > 'z' - 'a' + 1)
1505 memset (e, 0, sizeof (e));
1506 r = generate_random ();
1508 e[0].etype = ETYPE_UNION;
1510 e[0].etype = ETYPE_STRUCT;
1513 generate_fields (features, &e[1], &e[0], len);
1517 struct { const char *name; enum FEATURE f; }
1520 { "vector", FEATURE_VECTOR },
1521 { "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD },
1523 FEATURE_VECTOR | FEATURE_ZEROARRAY },
1524 { "aligned packed vector [0] :0",
1525 FEATURE_VECTOR | FEATURE_ZEROARRAY
1526 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD },
1530 main (int argc, char **argv)
1532 int i, j, count, c, n = 3000;
1535 if (sizeof (int) != 4 || sizeof (long long) != 8)
1542 if (argv[i][0] == '-' && argv[i][2] == '\0')
1544 optarg = argv[i + 1];
1560 limidx = atoi (optarg);
1567 fprintf (stderr, "unrecognized option %s\n", argv[i]);
1575 outfile = fopen ("/dev/null", "w");
1576 if (outfile == NULL)
1578 fputs ("could not open /dev/null", stderr);
1584 if (destdir == NULL && !output_one)
1587 fprintf (stderr, "Usage:\n\
1588 %s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\
1589 Either -s srcdir -d destdir or -i idx must be used\n", argv[0]);
1593 if (srcdir == NULL && !output_one)
1598 const char *s = srcdir;
1600 t = ss = malloc (strlen (srcdir) + 1);
1612 for (i = 0; i < NTYPES2; ++i)
1613 if (base_types[i].bitfld)
1614 bitfld_types[n_bitfld_types++] = base_types[i];
1615 for (i = 0; i < NATYPES2; ++i)
1616 if (attrib_types[i].bitfld)
1617 aligned_bitfld_types[n_aligned_bitfld_types++] = attrib_types[i];
1618 for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i)
1627 for (j = 1; j <= 9; ++j)
1628 while (idx < startidx + j * count)
1629 generate_random_tests (features[i].f, j);
1630 while (idx < startidx + count * 10)
1631 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
1633 for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i)
1639 singles (features[i].f);
1643 while (idx < startidx + 1000)
1644 generate_random_tests (features[i].f, 1);
1650 while (idx < startidx + 100)
1651 generate_random_tests (features[i].f, 1);
1654 for (j = 2; j <= 9; ++j)
1655 while (idx < startidx + (j - 1) * count)
1656 generate_random_tests (features[i].f, j);
1657 while (idx < startidx + count * 9)
1658 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
1663 generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25));