Merged with mainline at revision 128810.
[official-gcc.git] / gcc / testsuite / gcc.dg / compat / struct-layout-1_generate.c
blob74236437f237f6ee926ad618728adc7b94aed522
1 /* Structure layout test generator.
2 Copyright (C) 2004, 2005, 2007 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 3, or (at your option) any later
10 version.
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
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
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. */
26 #include <limits.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stddef.h>
31 /* We use our own pseudo-random number generator, so that it gives the same
32 values on all hosts. */
33 #include "generate-random.h"
35 #if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL
36 # error Need 64-bit long long
37 #endif
39 #if defined __MSVCRT__
40 #define COMPAT_PRLL "I64"
41 #else
42 #define COMPAT_PRLL "ll"
43 #endif
45 typedef unsigned int hashval_t;
47 enum TYPE
49 TYPE_INT,
50 TYPE_UINT,
51 TYPE_CINT,
52 TYPE_CUINT,
53 TYPE_FLOAT,
54 TYPE_CFLOAT,
55 TYPE_DEC_FLOAT,
56 TYPE_SENUM,
57 TYPE_UENUM,
58 TYPE_PTR,
59 TYPE_FNPTR,
60 TYPE_OTHER
63 struct types
65 const char *name;
66 enum TYPE type;
67 unsigned long long int maxval;
68 char bitfld;
71 struct types base_types[] = {
72 /* As we don't know whether char will be signed or not, just limit ourselves
73 to unsigned values less than maximum signed char value. */
74 { "char", TYPE_UINT, 127, 'C' },
75 { "signed char", TYPE_INT, 127, 'C' },
76 { "unsigned char", TYPE_UINT, 255, 'C' },
77 { "short int", TYPE_INT, 32767, 'S' },
78 { "unsigned short int", TYPE_UINT, 65535, 'S' },
79 { "int", TYPE_INT, 2147483647, 'I' },
80 { "unsigned int", TYPE_UINT, 4294967295U, 'I' },
81 { "long int", TYPE_INT, 9223372036854775807LL, 'L' },
82 { "unsigned long int", TYPE_UINT, 18446744073709551615ULL, 'L' },
83 { "long long int", TYPE_INT, 9223372036854775807LL, 'Q' },
84 { "unsigned long long int", TYPE_UINT, 18446744073709551615ULL, 'Q' },
85 { "bool", TYPE_UINT, 1, 'B' },
86 { "void *", TYPE_PTR, 0, 0 },
87 { "char *", TYPE_PTR, 0, 0 },
88 { "int *", TYPE_PTR, 0, 0 },
89 { "float", TYPE_FLOAT, 0, 0 },
90 { "double", TYPE_FLOAT, 0, 0 },
91 { "long double", TYPE_FLOAT, 0, 0 },
92 #ifndef SKIP_DECIMAL_FLOAT
93 { "_Decimal32", TYPE_DEC_FLOAT, 0, 0 },
94 { "_Decimal64", TYPE_DEC_FLOAT, 0, 0 },
95 { "_Decimal128", TYPE_DEC_FLOAT, 0, 0 },
96 #define NTYPES1 21
97 #else
98 #define NTYPES1 18
99 #endif
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 #ifndef SKIP_DECIMAL_FLOAT
121 { "TDecimal32", TYPE_DEC_FLOAT, 0, 0 },
122 { "TDecimal64", TYPE_DEC_FLOAT, 0, 0 },
123 { "TDecimal128", TYPE_DEC_FLOAT, 0, 0 },
124 #endif
125 { "enum E0", TYPE_UENUM, 0, ' ' },
126 { "enum E1", TYPE_UENUM, 1, ' ' },
127 { "enum E2", TYPE_SENUM, 3, ' ' },
128 { "enum E3", TYPE_SENUM, 127, ' ' },
129 { "enum E4", TYPE_UENUM, 255, ' ' },
130 { "enum E5", TYPE_SENUM, 32767, ' ' },
131 { "enum E6", TYPE_UENUM, 65535, ' ' },
132 { "enum E7", TYPE_SENUM, 2147483647, ' ' },
133 { "enum E8", TYPE_UENUM, 4294967295U, ' ' },
134 { "enum E9", TYPE_SENUM, 1099511627775LL, ' ' },
135 { "TE0", TYPE_UENUM, 0, ' ' },
136 { "TE1", TYPE_UENUM, 1, ' ' },
137 { "TE2", TYPE_SENUM, 3, ' ' },
138 { "TE3", TYPE_SENUM, 127, ' ' },
139 { "TE4", TYPE_UENUM, 255, ' ' },
140 { "TE5", TYPE_SENUM, 32767, ' ' },
141 { "TE6", TYPE_UENUM, 65535, ' ' },
142 { "TE7", TYPE_SENUM, 2147483647, ' ' },
143 { "TE8", TYPE_UENUM, 4294967295U, ' ' },
144 { "TE9", TYPE_SENUM, 1099511627775LL, ' ' },
145 /* vector-defs.h typedefs */
146 { "qi", TYPE_INT, 127, 0 },
147 { "hi", TYPE_INT, 32767, 0 },
148 { "si", TYPE_INT, 2147483647, 0 },
149 { "di", TYPE_INT, 9223372036854775807LL, 0 },
150 { "sf", TYPE_FLOAT, 0, 0 },
151 { "df", TYPE_FLOAT, 0, 0 }
152 #define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
154 struct types complex_types[] = {
155 { "_Complex char", TYPE_CUINT, 127, 0 },
156 { "_Complex signed char", TYPE_CINT, 127, 0 },
157 { "_Complex unsigned char", TYPE_CUINT, 255, 0 },
158 { "_Complex short int", TYPE_CINT, 32767, 0 },
159 { "_Complex unsigned short int", TYPE_CUINT, 65535, 0 },
160 { "_Complex int", TYPE_CINT, 2147483647, 0 },
161 { "_Complex unsigned int", TYPE_CUINT, 4294967295U, 0 },
162 { "_Complex long int", TYPE_CINT, 9223372036854775807LL, 0 },
163 { "_Complex unsigned long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
164 { "_Complex long long int", TYPE_CINT, 9223372036854775807LL, 0 },
165 { "_Complex unsigned long long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
166 { "_Complex float", TYPE_CFLOAT, 0, 0 },
167 { "_Complex double", TYPE_CFLOAT, 0, 0 },
168 { "_Complex long double", TYPE_CFLOAT, 0, 0 },
169 { "Tcchar", TYPE_CUINT, 127, 0 },
170 { "Tcschar", TYPE_CINT, 127, 0 },
171 { "Tcuchar", TYPE_CUINT, 255, 0 },
172 { "Tcshort", TYPE_CINT, 32767, 0 },
173 { "Tcushort", TYPE_CUINT, 65535, 0 },
174 { "Tcint", TYPE_CINT, 2147483647, 0 },
175 { "Tcuint", TYPE_CUINT, 4294967295U, 0 },
176 { "Tclong", TYPE_CINT, 9223372036854775807LL, 0 },
177 { "Tculong", TYPE_CUINT, 18446744073709551615ULL, 0 },
178 { "Tcllong", TYPE_CINT, 9223372036854775807LL, 0 },
179 { "Tcullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
180 { "Tcfloat", TYPE_CFLOAT, 0, 0 },
181 { "Tcdouble", TYPE_CFLOAT, 0, 0 },
182 { "Tcldouble", TYPE_CFLOAT, 0, 0 }
183 #define NCTYPES2 (sizeof (complex_types) / sizeof (complex_types[0]))
185 struct types vector_types[] = {
186 /* vector-defs.h typedefs */
187 { "v8qi", TYPE_OTHER, 0, 0 },
188 { "v16qi", TYPE_OTHER, 0, 0 },
189 { "v2hi", TYPE_OTHER, 0, 0 },
190 { "v4hi", TYPE_OTHER, 0, 0 },
191 { "v8hi", TYPE_OTHER, 0, 0 },
192 { "v2si", TYPE_OTHER, 0, 0 },
193 { "v4si", TYPE_OTHER, 0, 0 },
194 { "v1di", TYPE_OTHER, 0, 0 },
195 { "v2di", TYPE_OTHER, 0, 0 },
196 { "v2sf", TYPE_OTHER, 0, 0 },
197 { "v4sf", TYPE_OTHER, 0, 0 },
198 { "v16sf", TYPE_OTHER, 0, 0 },
199 { "v2df", TYPE_OTHER, 0, 0 },
200 { "u8qi", TYPE_OTHER, 0, 0 },
201 { "u16qi", TYPE_OTHER, 0, 0 },
202 { "u2hi", TYPE_OTHER, 0, 0 },
203 { "u4hi", TYPE_OTHER, 0, 0 },
204 { "u8hi", TYPE_OTHER, 0, 0 },
205 { "u2si", TYPE_OTHER, 0, 0 },
206 { "u4si", TYPE_OTHER, 0, 0 },
207 { "u1di", TYPE_OTHER, 0, 0 },
208 { "u2di", TYPE_OTHER, 0, 0 },
209 { "u2sf", TYPE_OTHER, 0, 0 },
210 { "u4sf", TYPE_OTHER, 0, 0 },
211 { "u16sf", TYPE_OTHER, 0, 0 },
212 { "u2df", TYPE_OTHER, 0, 0 },
213 { "__m64", TYPE_OTHER, 0, 0 },
214 { "__m128", TYPE_OTHER, 0, 0 }
215 #define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
217 struct types attrib_types[] = {
218 { "Talchar", TYPE_UINT, 127, 'C' },
219 { "Talschar", TYPE_INT, 127, 'C' },
220 { "Taluchar", TYPE_UINT, 255, 'C' },
221 { "Talshort", TYPE_INT, 32767, 'S' },
222 { "Talushort", TYPE_UINT, 65535, 'S' },
223 { "Talint", TYPE_INT, 2147483647, 'I' },
224 { "Taluint", TYPE_UINT, 4294967295U, 'I' },
225 { "Tallong", TYPE_INT, 9223372036854775807LL, 'L' },
226 { "Talulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
227 { "Talllong", TYPE_INT, 9223372036854775807LL, 'Q' },
228 { "Talullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
229 { "Talbool", TYPE_UINT, 1, 'B' },
230 { "Talptr", TYPE_PTR, 0, 0 },
231 { "Talcptr", TYPE_PTR, 0, 0 },
232 { "Taliptr", TYPE_PTR, 0, 0 },
233 { "Talfloat", TYPE_FLOAT, 0, 0 },
234 { "Taldouble", TYPE_FLOAT, 0, 0 },
235 { "Talldouble", TYPE_FLOAT, 0, 0 },
236 #ifndef SKIP_DECIMAL_FLOAT
237 { "TalDecimal32", TYPE_DEC_FLOAT, 0, 0 },
238 { "TalDecimal64", TYPE_DEC_FLOAT, 0, 0 },
239 { "TalDecimal128", TYPE_DEC_FLOAT, 0, 0 },
240 #endif
241 { "TalE0", TYPE_UENUM, 0, ' ' },
242 { "TalE1", TYPE_UENUM, 1, ' ' },
243 { "TalE2", TYPE_SENUM, 3, ' ' },
244 { "TalE3", TYPE_SENUM, 127, ' ' },
245 { "TalE4", TYPE_UENUM, 255, ' ' },
246 { "TalE5", TYPE_SENUM, 32767, ' ' },
247 { "TalE6", TYPE_UENUM, 65535, ' ' },
248 { "TalE7", TYPE_SENUM, 2147483647, ' ' },
249 { "TalE8", TYPE_UENUM, 4294967295U, ' ' },
250 { "TalE9", TYPE_SENUM, 1099511627775LL, ' ' },
251 { "Tal1char", TYPE_UINT, 127, 'C' },
252 { "Tal1schar", TYPE_INT, 127, 'C' },
253 { "Tal1uchar", TYPE_UINT, 255, 'C' },
254 { "Tal1short", TYPE_INT, 32767, 'S' },
255 { "Tal1ushort", TYPE_UINT, 65535, 'S' },
256 { "Tal1int", TYPE_INT, 2147483647, 'I' },
257 { "Tal1uint", TYPE_UINT, 4294967295U, 'I' },
258 { "Tal1long", TYPE_INT, 9223372036854775807LL, 'L' },
259 { "Tal1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
260 { "Tal1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
261 { "Tal1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
262 { "Tal1bool", TYPE_UINT, 1, 'B' },
263 { "Tal1ptr", TYPE_PTR, 0, 0 },
264 { "Tal1cptr", TYPE_PTR, 0, 0 },
265 { "Tal1iptr", TYPE_PTR, 0, 0 },
266 { "Tal1float", TYPE_FLOAT, 0, 0 },
267 { "Tal1double", TYPE_FLOAT, 0, 0 },
268 { "Tal1ldouble", TYPE_FLOAT, 0, 0 },
269 #ifndef SKIP_DECIMAL_FLOAT
270 { "Tal1Decimal32", TYPE_DEC_FLOAT, 0, 0},
271 { "Tal1Decimal64", TYPE_DEC_FLOAT, 0, 0},
272 { "Tal1Decimal128", TYPE_DEC_FLOAT, 0, 0},
273 #endif
274 { "Tal1E0", TYPE_UENUM, 0, ' ' },
275 { "Tal1E1", TYPE_UENUM, 1, ' ' },
276 { "Tal1E2", TYPE_SENUM, 3, ' ' },
277 { "Tal1E3", TYPE_SENUM, 127, ' ' },
278 { "Tal1E4", TYPE_UENUM, 255, ' ' },
279 { "Tal1E5", TYPE_SENUM, 32767, ' ' },
280 { "Tal1E6", TYPE_UENUM, 65535, ' ' },
281 { "Tal1E7", TYPE_SENUM, 2147483647, ' ' },
282 { "Tal1E8", TYPE_UENUM, 4294967295U, ' ' },
283 { "Tal1E9", TYPE_SENUM, 1099511627775LL, ' ' },
284 { "Tal2char", TYPE_UINT, 127, 'C' },
285 { "Tal2schar", TYPE_INT, 127, 'C' },
286 { "Tal2uchar", TYPE_UINT, 255, 'C' },
287 { "Tal2short", TYPE_INT, 32767, 'S' },
288 { "Tal2ushort", TYPE_UINT, 65535, 'S' },
289 { "Tal2int", TYPE_INT, 2147483647, 'I' },
290 { "Tal2uint", TYPE_UINT, 4294967295U, 'I' },
291 { "Tal2long", TYPE_INT, 9223372036854775807LL, 'L' },
292 { "Tal2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
293 { "Tal2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
294 { "Tal2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
295 { "Tal2bool", TYPE_UINT, 1, 'B' },
296 { "Tal2ptr", TYPE_PTR, 0, 0 },
297 { "Tal2cptr", TYPE_PTR, 0, 0 },
298 { "Tal2iptr", TYPE_PTR, 0, 0 },
299 { "Tal2float", TYPE_FLOAT, 0, 0 },
300 { "Tal2double", TYPE_FLOAT, 0, 0 },
301 { "Tal2ldouble", TYPE_FLOAT, 0, 0 },
302 #ifndef SKIP_DECIMAL_FLOAT
303 { "Tal2Decimal32", TYPE_DEC_FLOAT, 0, 0 },
304 { "Tal2Decimal64", TYPE_DEC_FLOAT, 0, 0 },
305 { "Tal2Decimal128", TYPE_DEC_FLOAT, 0, 0 },
306 #endif
307 { "Tal2E0", TYPE_UENUM, 0, ' ' },
308 { "Tal2E1", TYPE_UENUM, 1, ' ' },
309 { "Tal2E2", TYPE_SENUM, 3, ' ' },
310 { "Tal2E3", TYPE_SENUM, 127, ' ' },
311 { "Tal2E4", TYPE_UENUM, 255, ' ' },
312 { "Tal2E5", TYPE_SENUM, 32767, ' ' },
313 { "Tal2E6", TYPE_UENUM, 65535, ' ' },
314 { "Tal2E7", TYPE_SENUM, 2147483647, ' ' },
315 { "Tal2E8", TYPE_UENUM, 4294967295U, ' ' },
316 { "Tal2E9", TYPE_SENUM, 1099511627775LL, ' ' },
317 { "Tal4char", TYPE_UINT, 127, 'C' },
318 { "Tal4schar", TYPE_INT, 127, 'C' },
319 { "Tal4uchar", TYPE_UINT, 255, 'C' },
320 { "Tal4short", TYPE_INT, 32767, 'S' },
321 { "Tal4ushort", TYPE_UINT, 65535, 'S' },
322 { "Tal4int", TYPE_INT, 2147483647, 'I' },
323 { "Tal4uint", TYPE_UINT, 4294967295U, 'I' },
324 { "Tal4long", TYPE_INT, 9223372036854775807LL, 'L' },
325 { "Tal4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
326 { "Tal4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
327 { "Tal4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
328 { "Tal4bool", TYPE_UINT, 1, 'B' },
329 { "Tal4ptr", TYPE_PTR, 0, 0 },
330 { "Tal4cptr", TYPE_PTR, 0, 0 },
331 { "Tal4iptr", TYPE_PTR, 0, 0 },
332 { "Tal4float", TYPE_FLOAT, 0, 0 },
333 { "Tal4double", TYPE_FLOAT, 0, 0 },
334 { "Tal4ldouble", TYPE_FLOAT, 0, 0 },
335 #ifndef SKIP_DECIMAL_FLOAT
336 { "Tal4Decimal32", TYPE_DEC_FLOAT, 0, 0 },
337 { "Tal4Decimal64", TYPE_DEC_FLOAT, 0, 0 },
338 { "Tal4Decimal128", TYPE_DEC_FLOAT, 0, 0 },
339 #endif
340 { "Tal4E0", TYPE_UENUM, 0, ' ' },
341 { "Tal4E1", TYPE_UENUM, 1, ' ' },
342 { "Tal4E2", TYPE_SENUM, 3, ' ' },
343 { "Tal4E3", TYPE_SENUM, 127, ' ' },
344 { "Tal4E4", TYPE_UENUM, 255, ' ' },
345 { "Tal4E5", TYPE_SENUM, 32767, ' ' },
346 { "Tal4E6", TYPE_UENUM, 65535, ' ' },
347 { "Tal4E7", TYPE_SENUM, 2147483647, ' ' },
348 { "Tal4E8", TYPE_UENUM, 4294967295U, ' ' },
349 { "Tal4E9", TYPE_SENUM, 1099511627775LL, ' ' },
350 { "Tal8char", TYPE_UINT, 127, 'C' },
351 { "Tal8schar", TYPE_INT, 127, 'C' },
352 { "Tal8uchar", TYPE_UINT, 255, 'C' },
353 { "Tal8short", TYPE_INT, 32767, 'S' },
354 { "Tal8ushort", TYPE_UINT, 65535, 'S' },
355 { "Tal8int", TYPE_INT, 2147483647, 'I' },
356 { "Tal8uint", TYPE_UINT, 4294967295U, 'I' },
357 { "Tal8long", TYPE_INT, 9223372036854775807LL, 'L' },
358 { "Tal8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
359 { "Tal8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
360 { "Tal8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
361 { "Tal8bool", TYPE_UINT, 1, 'B' },
362 { "Tal8ptr", TYPE_PTR, 0, 0 },
363 { "Tal8cptr", TYPE_PTR, 0, 0 },
364 { "Tal8iptr", TYPE_PTR, 0, 0 },
365 { "Tal8float", TYPE_FLOAT, 0, 0 },
366 { "Tal8double", TYPE_FLOAT, 0, 0 },
367 { "Tal8ldouble", TYPE_FLOAT, 0, 0 },
368 #ifndef SKIP_DECIMAL_FLOAT
369 { "Tal8Decimal32", TYPE_DEC_FLOAT, 0, 0 },
370 { "Tal8Decimal64", TYPE_DEC_FLOAT, 0, 0 },
371 { "Tal8Decimal128", TYPE_DEC_FLOAT, 0, 0 },
372 #endif
373 { "Tal8E0", TYPE_UENUM, 0, ' ' },
374 { "Tal8E1", TYPE_UENUM, 1, ' ' },
375 { "Tal8E2", TYPE_SENUM, 3, ' ' },
376 { "Tal8E3", TYPE_SENUM, 127, ' ' },
377 { "Tal8E4", TYPE_UENUM, 255, ' ' },
378 { "Tal8E5", TYPE_SENUM, 32767, ' ' },
379 { "Tal8E6", TYPE_UENUM, 65535, ' ' },
380 { "Tal8E7", TYPE_SENUM, 2147483647, ' ' },
381 { "Tal8E8", TYPE_UENUM, 4294967295U, ' ' },
382 { "Tal8E9", TYPE_SENUM, 1099511627775LL, ' ' },
383 { "Tal16char", TYPE_UINT, 127, 'C' },
384 { "Tal16schar", TYPE_INT, 127, 'C' },
385 { "Tal16uchar", TYPE_UINT, 255, 'C' },
386 { "Tal16short", TYPE_INT, 32767, 'S' },
387 { "Tal16ushort", TYPE_UINT, 65535, 'S' },
388 { "Tal16int", TYPE_INT, 2147483647, 'I' },
389 { "Tal16uint", TYPE_UINT, 4294967295U, 'I' },
390 { "Tal16long", TYPE_INT, 9223372036854775807LL, 'L' },
391 { "Tal16ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
392 { "Tal16llong", TYPE_INT, 9223372036854775807LL, 'Q' },
393 { "Tal16ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
394 { "Tal16bool", TYPE_UINT, 1, 'B' },
395 { "Tal16ptr", TYPE_PTR, 0, 0 },
396 { "Tal16cptr", TYPE_PTR, 0, 0 },
397 { "Tal16iptr", TYPE_PTR, 0, 0 },
398 { "Tal16float", TYPE_FLOAT, 0, 0 },
399 { "Tal16double", TYPE_FLOAT, 0, 0 },
400 { "Tal16ldouble", TYPE_FLOAT, 0, 0 },
401 #ifndef SKIP_DECIMAL_FLOAT
402 { "Tal16Decimal32", TYPE_DEC_FLOAT, 0, 0 },
403 { "Tal16Decimal64", TYPE_DEC_FLOAT, 0, 0 },
404 { "Tal16Decimal128", TYPE_DEC_FLOAT, 0, 0 },
405 #endif
406 { "Tal16E0", TYPE_UENUM, 0, ' ' },
407 { "Tal16E1", TYPE_UENUM, 1, ' ' },
408 { "Tal16E2", TYPE_SENUM, 3, ' ' },
409 { "Tal16E3", TYPE_SENUM, 127, ' ' },
410 { "Tal16E4", TYPE_UENUM, 255, ' ' },
411 { "Tal16E5", TYPE_SENUM, 32767, ' ' },
412 { "Tal16E6", TYPE_UENUM, 65535, ' ' },
413 { "Tal16E7", TYPE_SENUM, 2147483647, ' ' },
414 { "Tal16E8", TYPE_UENUM, 4294967295U, ' ' },
415 { "Tal16E9", TYPE_SENUM, 1099511627775LL, ' ' }
416 #define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0]))
418 struct types complex_attrib_types[] = {
419 { "Talcchar", TYPE_CUINT, 127, 0 },
420 { "Talcschar", TYPE_CINT, 127, 0 },
421 { "Talcuchar", TYPE_CUINT, 255, 0 },
422 { "Talcshort", TYPE_CINT, 32767, 0 },
423 { "Talcushort", TYPE_CUINT, 65535, 0 },
424 { "Talcint", TYPE_CINT, 2147483647, 0 },
425 { "Talcuint", TYPE_CUINT, 4294967295U, 0 },
426 { "Talclong", TYPE_CINT, 9223372036854775807LL, 0 },
427 { "Talculong", TYPE_CUINT, 18446744073709551615ULL, 0 },
428 { "Talcllong", TYPE_CINT, 9223372036854775807LL, 0 },
429 { "Talcullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
430 { "Talcfloat", TYPE_CFLOAT, 0, 0 },
431 { "Talcdouble", TYPE_CFLOAT, 0, 0 },
432 { "Talcldouble", TYPE_CFLOAT, 0, 0 },
433 { "Tal1cchar", TYPE_CUINT, 127, 0 },
434 { "Tal1cschar", TYPE_CINT, 127, 0 },
435 { "Tal1cuchar", TYPE_CUINT, 255, 0 },
436 { "Tal1cshort", TYPE_CINT, 32767, 0 },
437 { "Tal1cushort", TYPE_CUINT, 65535, 0 },
438 { "Tal1cint", TYPE_CINT, 2147483647, 0 },
439 { "Tal1cuint", TYPE_CUINT, 4294967295U, 0 },
440 { "Tal1clong", TYPE_CINT, 9223372036854775807LL, 0 },
441 { "Tal1culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
442 { "Tal1cllong", TYPE_CINT, 9223372036854775807LL, 0 },
443 { "Tal1cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
444 { "Tal1cfloat", TYPE_CFLOAT, 0, 0 },
445 { "Tal1cdouble", TYPE_CFLOAT, 0, 0 },
446 { "Tal1cldouble", TYPE_CFLOAT, 0, 0 },
447 { "Tal2cchar", TYPE_CUINT, 127, 0 },
448 { "Tal2cschar", TYPE_CINT, 127, 0 },
449 { "Tal2cuchar", TYPE_CUINT, 255, 0 },
450 { "Tal2cshort", TYPE_CINT, 32767, 0 },
451 { "Tal2cushort", TYPE_CUINT, 65535, 0 },
452 { "Tal2cint", TYPE_CINT, 2147483647, 0 },
453 { "Tal2cuint", TYPE_CUINT, 4294967295U, 0 },
454 { "Tal2clong", TYPE_CINT, 9223372036854775807LL, 0 },
455 { "Tal2culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
456 { "Tal2cllong", TYPE_CINT, 9223372036854775807LL, 0 },
457 { "Tal2cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
458 { "Tal2cfloat", TYPE_CFLOAT, 0, 0 },
459 { "Tal2cdouble", TYPE_CFLOAT, 0, 0 },
460 { "Tal2cldouble", TYPE_CFLOAT, 0, 0 },
461 { "Tal4cchar", TYPE_CUINT, 127, 0 },
462 { "Tal4cschar", TYPE_CINT, 127, 0 },
463 { "Tal4cuchar", TYPE_CUINT, 255, 0 },
464 { "Tal4cshort", TYPE_CINT, 32767, 0 },
465 { "Tal4cushort", TYPE_CUINT, 65535, 0 },
466 { "Tal4cint", TYPE_CINT, 2147483647, 0 },
467 { "Tal4cuint", TYPE_CUINT, 4294967295U, 0 },
468 { "Tal4clong", TYPE_CINT, 9223372036854775807LL, 0 },
469 { "Tal4culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
470 { "Tal4cllong", TYPE_CINT, 9223372036854775807LL, 0 },
471 { "Tal4cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
472 { "Tal4cfloat", TYPE_CFLOAT, 0, 0 },
473 { "Tal4cdouble", TYPE_CFLOAT, 0, 0 },
474 { "Tal4cldouble", TYPE_CFLOAT, 0, 0 },
475 { "Tal8cchar", TYPE_CUINT, 127, 0 },
476 { "Tal8cschar", TYPE_CINT, 127, 0 },
477 { "Tal8cuchar", TYPE_CUINT, 255, 0 },
478 { "Tal8cshort", TYPE_CINT, 32767, 0 },
479 { "Tal8cushort", TYPE_CUINT, 65535, 0 },
480 { "Tal8cint", TYPE_CINT, 2147483647, 0 },
481 { "Tal8cuint", TYPE_CUINT, 4294967295U, 0 },
482 { "Tal8clong", TYPE_CINT, 9223372036854775807LL, 0 },
483 { "Tal8culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
484 { "Tal8cllong", TYPE_CINT, 9223372036854775807LL, 0 },
485 { "Tal8cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
486 { "Tal8cfloat", TYPE_CFLOAT, 0, 0 },
487 { "Tal8cdouble", TYPE_CFLOAT, 0, 0 },
488 { "Tal8cldouble", TYPE_CFLOAT, 0, 0 },
489 { "Tal16cchar", TYPE_CUINT, 127, 0 },
490 { "Tal16cschar", TYPE_CINT, 127, 0 },
491 { "Tal16cuchar", TYPE_CUINT, 255, 0 },
492 { "Tal16cshort", TYPE_CINT, 32767, 0 },
493 { "Tal16cushort", TYPE_CUINT, 65535, 0 },
494 { "Tal16cint", TYPE_CINT, 2147483647, 0 },
495 { "Tal16cuint", TYPE_CUINT, 4294967295U, 0 },
496 { "Tal16clong", TYPE_CINT, 9223372036854775807LL, 0 },
497 { "Tal16culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
498 { "Tal16cllong", TYPE_CINT, 9223372036854775807LL, 0 },
499 { "Tal16cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
500 { "Tal16cfloat", TYPE_CFLOAT, 0, 0 },
501 { "Tal16cdouble", TYPE_CFLOAT, 0, 0 },
502 { "Tal16cldouble", TYPE_CFLOAT, 0, 0 }
503 #define NCATYPES2 (sizeof (complex_attrib_types) / sizeof (complex_attrib_types[0]))
505 struct types attrib_array_types[] = {
506 { "Talx1char", TYPE_UINT, 127, 'C' },
507 { "Talx1schar", TYPE_INT, 127, 'C' },
508 { "Talx1uchar", TYPE_UINT, 255, 'C' },
509 { "Talx1short", TYPE_INT, 32767, 'S' },
510 { "Talx1ushort", TYPE_UINT, 65535, 'S' },
511 { "Talx1int", TYPE_INT, 2147483647, 'I' },
512 { "Talx1uint", TYPE_UINT, 4294967295U, 'I' },
513 { "Talx1long", TYPE_INT, 9223372036854775807LL, 'L' },
514 { "Talx1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
515 { "Talx1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
516 { "Talx1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
517 { "Talx1bool", TYPE_UINT, 1, 'B' },
518 { "Talx1ptr", TYPE_PTR, 0, 0 },
519 { "Talx1cptr", TYPE_PTR, 0, 0 },
520 { "Talx1iptr", TYPE_PTR, 0, 0 },
521 { "Talx1float", TYPE_FLOAT, 0, 0 },
522 { "Talx1double", TYPE_FLOAT, 0, 0 },
523 { "Talx1ldouble", TYPE_FLOAT, 0, 0 },
524 #ifndef SKIP_DECIMAL_FLOAT
525 { "Talx1Decimal32", TYPE_DEC_FLOAT, 0 ,0 },
526 { "Talx1Decimal64", TYPE_DEC_FLOAT, 0 ,0 },
527 { "Talx1Decimal128", TYPE_DEC_FLOAT, 0 ,0 },
528 #endif
529 { "Talx1E0", TYPE_UENUM, 0, ' ' },
530 { "Talx1E1", TYPE_UENUM, 1, ' ' },
531 { "Talx1E2", TYPE_SENUM, 3, ' ' },
532 { "Talx1E3", TYPE_SENUM, 127, ' ' },
533 { "Talx1E4", TYPE_UENUM, 255, ' ' },
534 { "Talx1E5", TYPE_SENUM, 32767, ' ' },
535 { "Talx1E6", TYPE_UENUM, 65535, ' ' },
536 { "Talx1E7", TYPE_SENUM, 2147483647, ' ' },
537 { "Talx1E8", TYPE_UENUM, 4294967295U, ' ' },
538 { "Talx1E9", TYPE_SENUM, 1099511627775LL, ' ' },
539 { "Talx2short", TYPE_INT, 32767, 'S' },
540 { "Talx2ushort", TYPE_UINT, 65535, 'S' },
541 { "Talx2int", TYPE_INT, 2147483647, 'I' },
542 { "Talx2uint", TYPE_UINT, 4294967295U, 'I' },
543 { "Talx2long", TYPE_INT, 9223372036854775807LL, 'L' },
544 { "Talx2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
545 { "Talx2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
546 { "Talx2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
547 { "Talx2ptr", TYPE_PTR, 0, 0 },
548 { "Talx2cptr", TYPE_PTR, 0, 0 },
549 { "Talx2iptr", TYPE_PTR, 0, 0 },
550 { "Talx2float", TYPE_FLOAT, 0, 0 },
551 { "Talx2double", TYPE_FLOAT, 0, 0 },
552 { "Talx2ldouble", TYPE_FLOAT, 0, 0 },
553 #ifndef SKIP_DECIMAL_FLOAT
554 { "Talx2Decimal32", TYPE_DEC_FLOAT, 0 , 0 },
555 { "Talx2Decimal64", TYPE_DEC_FLOAT, 0 , 0 },
556 { "Talx2Decimal128", TYPE_DEC_FLOAT, 0 , 0 },
557 #endif
558 { "Talx2E0", TYPE_UENUM, 0, ' ' },
559 { "Talx2E1", TYPE_UENUM, 1, ' ' },
560 { "Talx2E2", TYPE_SENUM, 3, ' ' },
561 { "Talx2E3", TYPE_SENUM, 127, ' ' },
562 { "Talx2E4", TYPE_UENUM, 255, ' ' },
563 { "Talx2E5", TYPE_SENUM, 32767, ' ' },
564 { "Talx2E6", TYPE_UENUM, 65535, ' ' },
565 { "Talx2E7", TYPE_SENUM, 2147483647, ' ' },
566 { "Talx2E8", TYPE_UENUM, 4294967295U, ' ' },
567 { "Talx2E9", TYPE_SENUM, 1099511627775LL, ' ' },
568 { "Talx4int", TYPE_INT, 2147483647, 'I' },
569 { "Talx4uint", TYPE_UINT, 4294967295U, 'I' },
570 { "Talx4long", TYPE_INT, 9223372036854775807LL, 'L' },
571 { "Talx4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
572 { "Talx4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
573 { "Talx4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
574 { "Talx4ptr", TYPE_PTR, 0, 0 },
575 { "Talx4cptr", TYPE_PTR, 0, 0 },
576 { "Talx4iptr", TYPE_PTR, 0, 0 },
577 { "Talx4float", TYPE_FLOAT, 0, 0 },
578 { "Talx4double", TYPE_FLOAT, 0, 0 },
579 { "Talx4ldouble", TYPE_FLOAT, 0, 0 },
580 #ifndef SKIP_DECIMAL_FLOAT
581 { "Talx4Decimal32", TYPE_DEC_FLOAT, 0 , 0 },
582 { "Talx4Decimal64", TYPE_DEC_FLOAT, 0 , 0 },
583 { "Talx4Decimal128", TYPE_DEC_FLOAT, 0 , 0 },
584 #endif
585 { "Talx4E0", TYPE_UENUM, 0, ' ' },
586 { "Talx4E1", TYPE_UENUM, 1, ' ' },
587 { "Talx4E2", TYPE_SENUM, 3, ' ' },
588 { "Talx4E3", TYPE_SENUM, 127, ' ' },
589 { "Talx4E4", TYPE_UENUM, 255, ' ' },
590 { "Talx4E5", TYPE_SENUM, 32767, ' ' },
591 { "Talx4E6", TYPE_UENUM, 65535, ' ' },
592 { "Talx4E7", TYPE_SENUM, 2147483647, ' ' },
593 { "Talx4E8", TYPE_UENUM, 4294967295U, ' ' },
594 { "Talx4E9", TYPE_SENUM, 1099511627775LL, ' ' },
595 { "Taly8long", TYPE_INT, 9223372036854775807LL, 'L' },
596 { "Taly8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
597 { "Talx8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
598 { "Talx8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
599 { "Taly8ptr", TYPE_PTR, 0, 0 },
600 { "Taly8cptr", TYPE_PTR, 0, 0 },
601 { "Taly8iptr", TYPE_PTR, 0, 0 },
602 { "Talx8double", TYPE_FLOAT, 0, 0 },
603 { "Talx8ldouble", TYPE_FLOAT, 0, 0 },
604 #ifndef SKIP_DECIMAL_FLOAT
605 { "Talx8Decimal64", TYPE_DEC_FLOAT, 0, 0 },
606 { "Talx8Decimal128", TYPE_DEC_FLOAT, 0, 0 }
607 #endif
608 #define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0]))
610 struct types complex_attrib_array_types[] = {
611 { "Talx1cchar", TYPE_CUINT, 127, 0 },
612 { "Talx1cschar", TYPE_CINT, 127, 0 },
613 { "Talx1cuchar", TYPE_CUINT, 255, 0 },
614 { "Talx1cshort", TYPE_CINT, 32767, 0 },
615 { "Talx1cushort", TYPE_CUINT, 65535, 0 },
616 { "Talx1cint", TYPE_CINT, 2147483647, 0 },
617 { "Talx1cuint", TYPE_CUINT, 4294967295U, 0 },
618 { "Talx1clong", TYPE_CINT, 9223372036854775807LL, 0 },
619 { "Talx1culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
620 { "Talx1cllong", TYPE_CINT, 9223372036854775807LL, 0 },
621 { "Talx1cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
622 { "Talx1cfloat", TYPE_CFLOAT, 0, 0 },
623 { "Talx1cdouble", TYPE_CFLOAT, 0, 0 },
624 { "Talx1cldouble", TYPE_CFLOAT, 0, 0 },
625 { "Talx2cchar", TYPE_CUINT, 127, 0 },
626 { "Talx2cschar", TYPE_CINT, 127, 0 },
627 { "Talx2cuchar", TYPE_CUINT, 255, 0 },
628 { "Talx2cshort", TYPE_CINT, 32767, 0 },
629 { "Talx2cushort", TYPE_CUINT, 65535, 0 },
630 { "Talx2cint", TYPE_CINT, 2147483647, 0 },
631 { "Talx2cuint", TYPE_CUINT, 4294967295U, 0 },
632 { "Talx2clong", TYPE_CINT, 9223372036854775807LL, 0 },
633 { "Talx2culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
634 { "Talx2cllong", TYPE_CINT, 9223372036854775807LL, 0 },
635 { "Talx2cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
636 { "Talx2cfloat", TYPE_CFLOAT, 0, 0 },
637 { "Talx2cdouble", TYPE_CFLOAT, 0, 0 },
638 { "Talx2cldouble", TYPE_CFLOAT, 0, 0 },
639 { "Talx4cshort", TYPE_CINT, 32767, 0 },
640 { "Talx4cushort", TYPE_CUINT, 65535, 0 },
641 { "Talx4cint", TYPE_CINT, 2147483647, 0 },
642 { "Talx4cuint", TYPE_CUINT, 4294967295U, 0 },
643 { "Talx4clong", TYPE_CINT, 9223372036854775807LL, 0 },
644 { "Talx4culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
645 { "Talx4cllong", TYPE_CINT, 9223372036854775807LL, 0 },
646 { "Talx4cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
647 { "Talx4cfloat", TYPE_CFLOAT, 0, 0 },
648 { "Talx4cdouble", TYPE_CFLOAT, 0, 0 },
649 { "Talx4cldouble", TYPE_CFLOAT, 0, 0 },
650 { "Talx8cint", TYPE_CINT, 2147483647, 0 },
651 { "Talx8cuint", TYPE_CUINT, 4294967295U, 0 },
652 { "Talx8clong", TYPE_CINT, 9223372036854775807LL, 0 },
653 { "Talx8culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
654 { "Talx8cllong", TYPE_CINT, 9223372036854775807LL, 0 },
655 { "Talx8cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
656 { "Talx8cfloat", TYPE_CFLOAT, 0, 0 },
657 { "Talx8cdouble", TYPE_CFLOAT, 0, 0 },
658 { "Talx8cldouble", TYPE_CFLOAT, 0, 0 },
659 { "Taly16clong", TYPE_CINT, 9223372036854775807LL, 0 },
660 { "Taly16culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
661 { "Talx16cllong", TYPE_CINT, 9223372036854775807LL, 0 },
662 { "Talx16cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
663 { "Talx16cdouble", TYPE_CFLOAT, 0, 0 },
664 { "Talx16cldouble", TYPE_CFLOAT, 0, 0 }
665 #define NCAATYPES2 (sizeof (complex_attrib_array_types) / sizeof (complex_attrib_array_types[0]))
668 struct types bitfld_types[NTYPES2];
669 int n_bitfld_types;
670 struct types aligned_bitfld_types[NATYPES2];
671 int n_aligned_bitfld_types;
673 const char *attributes[] = {
674 "atal",
675 "atpa",
676 "atal1",
677 "atal2",
678 "atal4",
679 "atal8",
680 "atal16",
681 #define NATTRIBS1 7
682 "atalpa",
683 "atpaal",
684 "atal1pa",
685 "atal2pa",
686 "atal4pa",
687 "atal8pa",
688 "atal16pa",
689 "atpaal1",
690 "atpaal2",
691 "atpaal4",
692 "atpaal8",
693 "atpaal16"
694 #define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0]))
697 enum ETYPE
699 ETYPE_TYPE,
700 ETYPE_ARRAY,
701 ETYPE_BITFLD,
702 ETYPE_STRUCT,
703 ETYPE_UNION,
704 ETYPE_STRUCT_ARRAY,
705 ETYPE_UNION_ARRAY
708 struct entry
710 #ifdef __GNUC__
711 enum ETYPE etype : 8;
712 #else
713 unsigned char etype;
714 #endif
715 unsigned short len;
716 unsigned char arr_len;
717 struct types *type;
718 const char *attrib;
719 /* Used to chain together entries in the hash table. */
720 struct entry *next;
723 /* A prime number giving the number of slots in the hash table. */
724 #define HASH_SIZE 32749
725 static struct entry *hash_table[HASH_SIZE];
727 static int idx, limidx, output_one, short_enums;
728 static const char *destdir;
729 static const char *srcdir;
730 FILE *outfile;
732 void
733 switchfiles (int fields)
735 static int filecnt;
736 static char *destbuf, *destptr;
737 ++filecnt;
738 if (outfile)
739 fclose (outfile);
740 if (output_one)
742 outfile = stdout;
743 return;
745 if (destbuf == NULL)
747 size_t len = strlen (destdir);
748 destbuf = malloc (len + 20);
749 if (!destbuf)
750 abort ();
751 memcpy (destbuf, destdir, len);
752 if (!len || destbuf[len - 1] != '/')
753 destbuf[len++] = '/';
754 destptr = destbuf + len;
756 sprintf (destptr, "t%03d_main.c", filecnt);
757 outfile = fopen (destbuf, "w");
758 if (outfile == NULL)
760 fail:
761 fputs ("failed to create test files\n", stderr);
762 exit (1);
764 fprintf (outfile, "\
765 /* { dg-options \"-I%s\" } */\n\
766 /* { dg-options \"-I%s -fno-common\" { target hppa*-*-hpux* *-*-darwin* } } */\n\
767 /* { dg-options \"-I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
768 #include \"struct-layout-1.h\"\n\
770 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
771 #include \"t%03d_test.h\"\n\
772 #undef TX\n\
774 int main (void)\n\
775 {\n\
776 #define TX(n, type, attrs, fields, ops) test##n ();\n\
777 #include \"t%03d_test.h\"\n\
778 #undef TX\n\
779 if (fails)\n\
780 {\n\
781 fflush (stdout);\n\
782 abort ();\n\
783 }\n\
784 exit (0);\n\
785 }\n", srcdir, srcdir, srcdir, filecnt, filecnt);
786 fclose (outfile);
787 sprintf (destptr, "t%03d_x.c", filecnt);
788 outfile = fopen (destbuf, "w");
789 if (outfile == NULL)
790 goto fail;
791 fprintf (outfile, "\
792 /* { dg-options \"-w -I%s\" } */\n\
793 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* *-*-darwin* } } */\n\
794 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
795 #include \"struct-layout-1_x1.h\"\n\
796 #include \"t%03d_test.h\"\n\
797 #include \"struct-layout-1_x2.h\"\n\
798 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
799 fclose (outfile);
800 sprintf (destptr, "t%03d_y.c", filecnt);
801 outfile = fopen (destbuf, "w");
802 if (outfile == NULL)
803 goto fail;
804 fprintf (outfile, "\
805 /* { dg-options \"-w -I%s\" } */\n\
806 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* *-*-darwin* } } */\n\
807 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
808 #include \"struct-layout-1_y1.h\"\n\
809 #include \"t%03d_test.h\"\n\
810 #include \"struct-layout-1_y2.h\"\n\
811 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
812 fclose (outfile);
813 sprintf (destptr, "t%03d_test.h", filecnt);
814 outfile = fopen (destbuf, "w");
815 if (outfile == NULL)
816 goto fail;
817 if (fields <= 2)
818 limidx = idx + 300;
819 else if (fields <= 4)
820 limidx = idx + 200;
821 else if (fields <= 6)
822 limidx = idx + 100;
823 else
824 limidx = idx + 50;
827 unsigned long long int
828 getrandll (void)
830 unsigned long long int ret;
831 ret = generate_random () & 0xffffff;
832 ret |= (generate_random () & 0xffffffLL) << 24;
833 ret |= ((unsigned long long int) generate_random ()) << 48;
834 return ret;
838 subfield (struct entry *e, char *letter)
840 int i, type;
841 char buf[20];
842 const char *p;
843 switch (e[0].etype)
845 case ETYPE_STRUCT:
846 case ETYPE_UNION:
847 case ETYPE_STRUCT_ARRAY:
848 case ETYPE_UNION_ARRAY:
849 type = e[0].attrib ? 1 + (generate_random () & 3) : 0;
850 if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY)
851 p = "struct";
852 else
853 p = "union";
854 if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY)
856 if (e[0].arr_len == 255)
857 snprintf (buf, 20, "%c[]", *letter);
858 else
859 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
860 /* If this is an array type, do not put aligned attributes on
861 elements. Aligning elements to a value greater than their
862 size will result in a compiler error. */
863 if (type == 1
864 && ((strncmp (e[0].attrib, "atal", 4) == 0)
865 || strncmp (e[0].attrib, "atpaal", 6) == 0))
866 type = 2;
868 else
870 buf[0] = *letter;
871 buf[1] = '\0';
873 ++*letter;
874 switch (type)
876 case 0:
877 case 3:
878 case 4:
879 fprintf (outfile, "%s{", p);
880 break;
881 case 1:
882 fprintf (outfile, "%s %s{", e[0].attrib, p);
883 break;
884 case 2:
885 fprintf (outfile, "%s %s{", p, e[0].attrib);
886 break;
889 for (i = 1; i <= e[0].len; )
890 i += subfield (e + i, letter);
892 switch (type)
894 case 0:
895 case 1:
896 case 2:
897 fprintf (outfile, "}%s;", buf);
898 break;
899 case 3:
900 fprintf (outfile, "}%s %s;", e[0].attrib, buf);
901 break;
902 case 4:
903 fprintf (outfile, "}%s %s;", buf, e[0].attrib);
904 break;
906 return 1 + e[0].len;
907 case ETYPE_TYPE:
908 case ETYPE_ARRAY:
909 if (e[0].etype == ETYPE_ARRAY)
911 if (e[0].arr_len == 255)
912 snprintf (buf, 20, "%c[]", *letter);
913 else
914 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
916 else
918 buf[0] = *letter;
919 buf[1] = '\0';
921 ++*letter;
922 if (e[0].attrib)
924 /* If this is an array type, do not put aligned attributes on
925 elements. Aligning elements to a value greater than their
926 size will result in a compiler error. */
927 if (e[0].etype == ETYPE_ARRAY
928 && ((strncmp (e[0].attrib, "atal", 4) == 0)
929 || strncmp (e[0].attrib, "atpaal", 6) == 0))
930 type = 2;
931 else
932 type = generate_random () % 3;
933 switch (type)
935 case 0:
936 fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name,
937 buf);
938 break;
939 case 1:
940 fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib,
941 buf);
942 break;
943 case 2:
944 fprintf (outfile, "%s %s %s;", e[0].type->name, buf,
945 e[0].attrib);
946 break;
949 else
950 fprintf (outfile, "%s %s;", e[0].type->name, buf);
951 return 1;
952 case ETYPE_BITFLD:
953 if (e[0].len == 0)
955 if (e[0].attrib)
956 switch (generate_random () % 3)
958 case 0:
959 fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name);
960 break;
961 case 1:
962 fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib);
963 break;
964 case 2:
965 fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib);
966 break;
968 else
969 fprintf (outfile, "%s:0;", e[0].type->name);
970 ++*letter;
971 return 1;
973 switch (e[0].type->bitfld)
975 case 'C':
976 case 'S':
977 case 'I':
978 case 'L':
979 case 'Q':
980 snprintf (buf, 20, "B%cN(%d)", e[0].type->bitfld, e[0].len);
981 break;
982 case 'B':
983 case ' ':
984 snprintf (buf, 20, "%d", e[0].len);
985 break;
986 default:
987 abort ();
989 if (e[0].attrib)
990 switch (generate_random () % 3)
992 case 0:
993 fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name,
994 *letter, buf);
995 break;
996 case 1:
997 fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib,
998 *letter, buf);
999 break;
1000 case 2:
1001 fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter,
1002 buf, e[0].attrib);
1003 break;
1005 else
1006 fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf);
1007 ++*letter;
1008 return 1;
1009 default:
1010 abort ();
1014 char namebuf[1024];
1016 void
1017 output_FNB (char mode, struct entry *e)
1019 unsigned long long int l1, l2, m;
1020 int signs = 0;
1021 #ifndef SKIP_DECIMAL_FLOAT
1022 int suffix = 0;
1023 char DEC_SUFFIX[3][3]={"DF","DD","DL"};
1024 #endif
1026 const char *p, *q;
1028 if (e->type->type == TYPE_OTHER)
1030 if (mode == 'B')
1031 abort ();
1032 fprintf (outfile, "N(%d,%s)", idx, namebuf);
1033 return;
1035 fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf);
1036 l1 = getrandll ();
1037 l2 = getrandll ();
1038 switch (e->type->type)
1040 case TYPE_INT:
1041 signs = generate_random () & 3;
1042 m = e->type->maxval;
1043 if (mode == 'B')
1044 m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1;
1045 l1 &= m;
1046 l2 &= m;
1047 fprintf (outfile, "%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s",
1048 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1049 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1050 break;
1051 case TYPE_UINT:
1052 m = e->type->maxval;
1053 if (mode == 'B')
1054 m &= (1ULL << e->len) - 1;
1055 l1 &= m;
1056 l2 &= m;
1057 fprintf (outfile, "%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s",
1058 l1, l1 > 4294967295U ? "LL" : "",
1059 l2, l2 > 4294967295U ? "LL" : "");
1060 break;
1061 case TYPE_FLOAT:
1062 l1 &= 0xffffff;
1063 l2 &= 0xffffff;
1064 signs = generate_random () & 3;
1065 fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "",
1066 ((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64);
1067 break;
1068 #ifndef SKIP_DECIMAL_FLOAT
1069 case TYPE_DEC_FLOAT:
1070 l1 &= 0xffffff;
1071 l2 &= 0xffffff;
1072 signs = generate_random () & 3;
1074 /* Get the suffix of Decimal Floting Points per
1075 e->type->name. Distinguish these three DFP types by
1076 e->type->name. */
1077 if (strstr(e->type->name, "Decimal32")) suffix=0;
1078 else if (strstr(e->type->name, "Decimal64")) suffix=1;
1079 else if (strstr(e->type->name, "Decimal128")) suffix=2;
1080 else
1081 abort ();
1083 /* Formatted input/output specifiers for DFP types have not been
1084 implemented in GLIBC. %f here used in fprintf is just to
1085 dump the numbers to outfile. */
1086 fprintf (outfile, "%s%f%s,%s%f%s",
1087 (signs & 1) ? "-" : "", ((double) l1) / 64, DEC_SUFFIX[suffix],
1088 (signs & 2) ? "-" : "", ((double) l2) / 64, DEC_SUFFIX[suffix]);
1089 break;
1090 #endif
1091 case TYPE_CINT:
1092 signs = generate_random () & 3;
1093 l1 &= e->type->maxval;
1094 l2 &= e->type->maxval;
1095 fprintf (outfile,
1096 "CINT(%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s),",
1097 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1098 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1099 signs = generate_random () & 3;
1100 l1 = getrandll ();
1101 l2 = getrandll ();
1102 l1 &= e->type->maxval;
1103 l2 &= e->type->maxval;
1104 fprintf (outfile,
1105 "CINT(%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s)",
1106 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1107 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1108 break;
1109 case TYPE_CUINT:
1110 l1 &= e->type->maxval;
1111 l2 &= e->type->maxval;
1112 fprintf (outfile,
1113 "CINT(%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s),",
1114 l1, l1 > 4294967295U ? "LL" : "",
1115 l2, l2 > 4294967295U ? "LL" : "");
1116 l1 = getrandll ();
1117 l2 = getrandll ();
1118 l1 &= e->type->maxval;
1119 l2 &= e->type->maxval;
1120 fprintf (outfile,
1121 "CINT(%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s)",
1122 l1, l1 > 4294967295U ? "LL" : "",
1123 l2, l2 > 4294967295U ? "LL" : "");
1124 break;
1125 case TYPE_CFLOAT:
1126 l1 &= 0xffffff;
1127 l2 &= 0xffffff;
1128 signs = generate_random () & 3;
1129 fprintf (outfile, "CDBL(%s%f,%s%f),",
1130 (signs & 1) ? "-" : "", ((double) l1) / 64,
1131 (signs & 2) ? "-" : "", ((double) l2) / 64);
1132 l1 = getrandll ();
1133 l2 = getrandll ();
1134 l1 &= 0xffffff;
1135 l2 &= 0xffffff;
1136 signs = generate_random () & 3;
1137 fprintf (outfile, "CDBL(%s%f,%s%f)",
1138 (signs & 1) ? "-" : "", ((double) l1) / 64,
1139 (signs & 2) ? "-" : "", ((double) l2) / 64);
1140 break;
1141 case TYPE_UENUM:
1142 if (e->type->maxval == 0)
1143 fputs ("e0_0,e0_0", outfile);
1144 else if (e->type->maxval == 1)
1145 fprintf (outfile, "e1_%" COMPAT_PRLL "d,e1_%" COMPAT_PRLL "d",
1146 l1 & 1, l2 & 1);
1147 else
1149 p = strchr (e->type->name, '\0');
1150 while (--p >= e->type->name && *p >= '0' && *p <= '9');
1151 p++;
1152 l1 %= 7;
1153 l2 %= 7;
1154 if (l1 > 3)
1155 l1 += e->type->maxval - 6;
1156 if (l2 > 3)
1157 l2 += e->type->maxval - 6;
1158 fprintf (outfile, "e%s_%" COMPAT_PRLL "d,e%s_%" COMPAT_PRLL "d",
1159 p, l1, p, l2);
1161 break;
1162 case TYPE_SENUM:
1163 p = strchr (e->type->name, '\0');
1164 while (--p >= e->type->name && *p >= '0' && *p <= '9');
1165 p++;
1166 l1 %= 7;
1167 l2 %= 7;
1168 fprintf (outfile, "e%s_%s%" COMPAT_PRLL "d,e%s_%s%" COMPAT_PRLL "d",
1169 p, l1 < 3 ? "m" : "",
1170 l1 == 3 ? 0LL : e->type->maxval - (l1 & 3),
1171 p, l2 < 3 ? "m" : "",
1172 l2 == 3 ? 0LL : e->type->maxval - (l2 & 3));
1173 break;
1174 case TYPE_PTR:
1175 l1 %= 256;
1176 l2 %= 256;
1177 fprintf (outfile,
1178 "(%s)&intarray[%" COMPAT_PRLL "d], (%s)&intarray[%" COMPAT_PRLL "d]",
1179 e->type->name, l1, e->type->name, l2);
1180 break;
1181 case TYPE_FNPTR:
1182 l1 %= 10;
1183 l2 %= 10;
1184 fprintf (outfile, "fn%" COMPAT_PRLL "d,fn%" COMPAT_PRLL "d", l1, l2);
1185 break;
1186 default:
1187 abort ();
1189 fputs (")", outfile);
1193 subvalues (struct entry *e, char *p, char *letter)
1195 int i, j;
1196 char *q;
1197 if (p >= namebuf + sizeof (namebuf) - 32)
1198 abort ();
1199 p[0] = *letter;
1200 p[1] = '\0';
1201 q = p + 1;
1202 switch (e[0].etype)
1204 case ETYPE_STRUCT_ARRAY:
1205 case ETYPE_UNION_ARRAY:
1206 if (e[0].arr_len == 0 || e[0].arr_len == 255)
1208 *letter += 1 + e[0].len;
1209 return 1 + e[0].len;
1211 i = generate_random () % e[0].arr_len;
1212 snprintf (p, sizeof (namebuf) - (p - namebuf) - 1,
1213 "%c[%d]", *letter, i);
1214 q = strchr (p, '\0');
1215 /* FALLTHROUGH */
1216 case ETYPE_STRUCT:
1217 case ETYPE_UNION:
1218 *q++ = '.';
1219 ++*letter;
1220 for (i = 1; i <= e[0].len; )
1222 i += subvalues (e + i, q, letter);
1223 if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY)
1225 *letter += e[0].len - i + 1;
1226 break;
1229 return 1 + e[0].len;
1230 case ETYPE_TYPE:
1231 ++*letter;
1232 output_FNB ('F', e);
1233 return 1;
1234 case ETYPE_ARRAY:
1235 if (e[0].arr_len == 0 || e[0].arr_len == 255)
1237 ++*letter;
1238 return 1;
1240 i = generate_random () % e[0].arr_len;
1241 snprintf (p, sizeof (namebuf) - (p - namebuf),
1242 "%c[%d]", *letter, i);
1243 output_FNB ('F', e);
1244 if ((generate_random () & 7) == 0)
1246 j = generate_random () % e[0].arr_len;
1247 if (i != j)
1249 snprintf (p, sizeof (namebuf) - (p - namebuf),
1250 "%c[%d]", *letter, j);
1251 output_FNB ('F', e);
1254 ++*letter;
1255 return 1;
1256 case ETYPE_BITFLD:
1257 ++*letter;
1258 if (e[0].len != 0)
1259 output_FNB ('B', e);
1260 return 1;
1264 /* DERIVED FROM:
1265 --------------------------------------------------------------------
1266 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
1267 hash(), hash2(), hash3, and mix() are externally useful functions.
1268 Routines to test the hash are included if SELF_TEST is defined.
1269 You can use this free for any purpose. It has no warranty.
1270 --------------------------------------------------------------------
1274 --------------------------------------------------------------------
1275 mix -- mix 3 32-bit values reversibly.
1276 For every delta with one or two bit set, and the deltas of all three
1277 high bits or all three low bits, whether the original value of a,b,c
1278 is almost all zero or is uniformly distributed,
1279 * If mix() is run forward or backward, at least 32 bits in a,b,c
1280 have at least 1/4 probability of changing.
1281 * If mix() is run forward, every bit of c will change between 1/3 and
1282 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
1283 mix() was built out of 36 single-cycle latency instructions in a
1284 structure that could supported 2x parallelism, like so:
1285 a -= b;
1286 a -= c; x = (c>>13);
1287 b -= c; a ^= x;
1288 b -= a; x = (a<<8);
1289 c -= a; b ^= x;
1290 c -= b; x = (b>>13);
1292 Unfortunately, superscalar Pentiums and Sparcs can't take advantage
1293 of that parallelism. They've also turned some of those single-cycle
1294 latency instructions into multi-cycle latency instructions. Still,
1295 this is the fastest good hash I could find. There were about 2^^68
1296 to choose from. I only looked at a billion or so.
1297 --------------------------------------------------------------------
1299 /* same, but slower, works on systems that might have 8 byte hashval_t's */
1300 #define mix(a,b,c) \
1302 a -= b; a -= c; a ^= (c>>13); \
1303 b -= c; b -= a; b ^= (a<< 8); \
1304 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
1305 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
1306 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
1307 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
1308 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
1309 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
1310 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
1314 --------------------------------------------------------------------
1315 hash() -- hash a variable-length key into a 32-bit value
1316 k : the key (the unaligned variable-length array of bytes)
1317 len : the length of the key, counting by bytes
1318 level : can be any 4-byte value
1319 Returns a 32-bit value. Every bit of the key affects every bit of
1320 the return value. Every 1-bit and 2-bit delta achieves avalanche.
1321 About 36+6len instructions.
1323 The best hash table sizes are powers of 2. There is no need to do
1324 mod a prime (mod is sooo slow!). If you need less than 32 bits,
1325 use a bitmask. For example, if you need only 10 bits, do
1326 h = (h & hashmask(10));
1327 In which case, the hash table should have hashsize(10) elements.
1329 If you are hashing n strings (ub1 **)k, do it like this:
1330 for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
1332 By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
1333 code any way you wish, private, educational, or commercial. It's free.
1335 See http://burtleburtle.net/bob/hash/evahash.html
1336 Use for hash table lookup, or anything where one collision in 2^32 is
1337 acceptable. Do NOT use for cryptographic purposes.
1338 --------------------------------------------------------------------
1341 static hashval_t
1342 iterative_hash (const void *k_in /* the key */,
1343 register size_t length /* the length of the key */,
1344 register hashval_t initval /* the previous hash, or
1345 an arbitrary value */)
1347 register const unsigned char *k = (const unsigned char *)k_in;
1348 register hashval_t a,b,c,len;
1350 /* Set up the internal state */
1351 len = length;
1352 a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
1353 c = initval; /* the previous hash value */
1355 /*---------------------------------------- handle most of the key */
1356 while (len >= 12)
1358 a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24));
1359 b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24));
1360 c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24));
1361 mix(a,b,c);
1362 k += 12; len -= 12;
1365 /*------------------------------------- handle the last 11 bytes */
1366 c += length;
1367 switch(len) /* all the case statements fall through */
1369 case 11: c+=((hashval_t)k[10]<<24);
1370 case 10: c+=((hashval_t)k[9]<<16);
1371 case 9 : c+=((hashval_t)k[8]<<8);
1372 /* the first byte of c is reserved for the length */
1373 case 8 : b+=((hashval_t)k[7]<<24);
1374 case 7 : b+=((hashval_t)k[6]<<16);
1375 case 6 : b+=((hashval_t)k[5]<<8);
1376 case 5 : b+=k[4];
1377 case 4 : a+=((hashval_t)k[3]<<24);
1378 case 3 : a+=((hashval_t)k[2]<<16);
1379 case 2 : a+=((hashval_t)k[1]<<8);
1380 case 1 : a+=k[0];
1381 /* case 0: nothing left to add */
1383 mix(a,b,c);
1384 /*-------------------------------------------- report the result */
1385 return c;
1388 hashval_t
1389 e_hash (const void *a)
1391 const struct entry *e = a;
1392 hashval_t ret = 0;
1393 int i;
1395 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1396 abort ();
1397 for (i = 0; i <= e[0].len; ++i)
1399 int attriblen;
1400 ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret);
1401 attriblen = e[i].attrib ? strlen (e[i].attrib) : -1;
1402 ret = iterative_hash (&attriblen, sizeof (int), ret);
1403 if (e[i].attrib)
1404 ret = iterative_hash (e[i].attrib, attriblen, ret);
1406 return ret;
1410 e_eq (const void *a, const void *b)
1412 const struct entry *ea = a, *eb = b;
1413 int i;
1414 if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION)
1415 abort ();
1416 if (ea[0].len != eb[0].len)
1417 return 0;
1418 for (i = 0; i <= ea[0].len; ++i)
1420 if (ea[i].etype != eb[i].etype
1421 || ea[i].len != eb[i].len
1422 || ea[i].arr_len != eb[i].arr_len
1423 || ea[i].type != eb[i].type)
1424 return 0;
1425 if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL))
1426 return 0;
1427 if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0)
1428 return 0;
1430 return 1;
1433 static int
1434 e_exists (const struct entry *e)
1436 struct entry *h;
1437 hashval_t hval;
1439 hval = e_hash (e);
1440 for (h = hash_table[hval % HASH_SIZE]; h; h = h->next)
1441 if (e_eq (e, h))
1442 return 1;
1443 return 0;
1446 static void
1447 e_insert (struct entry *e)
1449 hashval_t hval;
1451 hval = e_hash (e);
1452 e->next = hash_table[hval % HASH_SIZE];
1453 hash_table[hval % HASH_SIZE] = e;
1456 void
1457 output (struct entry *e)
1459 int i;
1460 char c;
1461 struct entry *n;
1462 const char *skip_cint = "";
1464 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1465 abort ();
1467 if (e_exists (e))
1468 return;
1470 n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry));
1471 memcpy (n, e, (e[0].len + 1) * sizeof (struct entry));
1472 e_insert (n);
1474 if (idx == limidx)
1475 switchfiles (e[0].len);
1477 for (i = 1; i <= e[0].len; ++i)
1478 if ((e[i].etype == ETYPE_TYPE || e[i].etype == ETYPE_ARRAY)
1479 && (e[i].type->type == TYPE_CINT || e[i].type->type == TYPE_CUINT))
1480 break;
1481 if (i <= e[0].len)
1482 skip_cint = "CI";
1483 if (e[0].attrib)
1484 fprintf (outfile, (generate_random () & 1)
1485 ? "TX%s(%d,%s %s,," : "TX%s(%d,%s,%s,", skip_cint,
1486 idx, e[0].etype == ETYPE_STRUCT ? "struct" : "union",
1487 e[0].attrib);
1488 else if (e[0].etype == ETYPE_STRUCT)
1489 fprintf (outfile, "T%s(%d,", skip_cint, idx);
1490 else
1491 fprintf (outfile, "U%s(%d,", skip_cint, idx);
1492 c = 'a';
1493 for (i = 1; i <= e[0].len; )
1494 i += subfield (e + i, &c);
1495 fputs (",", outfile);
1496 c = 'a';
1497 for (i = 1; i <= e[0].len; )
1499 i += subvalues (e + i, namebuf, &c);
1500 if (e[0].etype == ETYPE_UNION)
1501 break;
1503 fputs (")\n", outfile);
1504 if (output_one && idx == limidx)
1505 exit (0);
1506 ++idx;
1509 enum FEATURE
1511 FEATURE_VECTOR = 1,
1512 FEATURE_COMPLEX = 2,
1513 FEATURE_ALIGNEDPACKED = 4,
1514 FEATURE_ZEROARRAY = 8,
1515 FEATURE_ZEROBITFLD = 16,
1516 ALL_FEATURES = FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1517 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD
1520 void
1521 singles (enum FEATURE features)
1523 struct entry e[2];
1524 int i;
1525 memset (e, 0, sizeof (e));
1526 e[0].etype = ETYPE_STRUCT;
1527 output (e);
1528 e[0].etype = ETYPE_UNION;
1529 output (e);
1530 for (i = 0;
1531 i < ((features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1);
1532 ++i)
1534 e[0].attrib = attributes[i];
1535 e[0].etype = ETYPE_STRUCT;
1536 output (e);
1537 e[0].etype = ETYPE_UNION;
1538 output (e);
1540 e[0].len = 1;
1541 e[0].attrib = NULL;
1542 for (i = 0; i < NTYPES2; ++i)
1544 e[0].etype = ETYPE_STRUCT;
1545 e[1].etype = ETYPE_TYPE;
1546 e[1].type = &base_types[i];
1547 output (e);
1548 e[0].etype = ETYPE_UNION;
1549 output (e);
1551 if (features & FEATURE_COMPLEX)
1552 for (i = 0; i < NCTYPES2; ++i)
1554 e[0].etype = ETYPE_STRUCT;
1555 e[1].etype = ETYPE_TYPE;
1556 e[1].type = &complex_types[i];
1557 output (e);
1558 e[0].etype = ETYPE_UNION;
1559 output (e);
1561 if (features & FEATURE_VECTOR)
1562 for (i = 0; i < NVTYPES2; ++i)
1564 e[0].etype = ETYPE_STRUCT;
1565 e[1].etype = ETYPE_TYPE;
1566 e[1].type = &vector_types[i];
1567 output (e);
1568 e[0].etype = ETYPE_UNION;
1569 output (e);
1573 void
1574 choose_type (enum FEATURE features, struct entry *e, int r, int in_array)
1576 int i;
1578 i = NTYPES2 - NTYPES1;
1579 if (features & FEATURE_COMPLEX)
1580 i += NCTYPES2;
1581 if (features & FEATURE_VECTOR)
1582 i += NVTYPES2;
1583 if ((r & 3) == 0)
1585 if (in_array)
1587 i += NAATYPES2;
1588 if (features & FEATURE_COMPLEX)
1589 i += NCAATYPES2;
1591 else
1593 i += NATYPES2;
1594 if (features & FEATURE_COMPLEX)
1595 i += NCATYPES2;
1598 r >>= 2;
1599 r %= i;
1600 if (r < NTYPES2 - NTYPES1)
1601 e->type = &base_types[r + NTYPES1];
1602 r -= NTYPES2 - NTYPES1;
1603 if (e->type == NULL && (features & FEATURE_COMPLEX))
1605 if (r < NCTYPES2)
1606 e->type = &complex_types[r];
1607 r -= NCTYPES2;
1609 if (e->type == NULL && (features & FEATURE_VECTOR))
1611 if (r < NVTYPES2)
1612 e->type = &vector_types[r];
1613 r -= NVTYPES2;
1615 if (e->type == NULL && !in_array)
1617 if (r < NATYPES2)
1618 e->type = &attrib_types[r];
1619 r -= NATYPES2;
1621 if (e->type == NULL && !in_array && (features & FEATURE_COMPLEX))
1623 if (r < NCATYPES2)
1624 e->type = &complex_attrib_types[r];
1625 r -= NCATYPES2;
1627 if (e->type == NULL && in_array)
1629 if (r < NAATYPES2)
1630 e->type = &attrib_array_types[r];
1631 r -= NAATYPES2;
1633 if (e->type == NULL && in_array && (features & FEATURE_COMPLEX))
1635 if (r < NCAATYPES2)
1636 e->type = &complex_attrib_array_types[r];
1637 r -= NCAATYPES2;
1639 if (e->type == NULL)
1640 abort ();
1643 /* This is from gcc.c-torture/execute/builtin-bitops-1.c. */
1644 static int
1645 my_ffsll (unsigned long long x)
1647 int i;
1648 if (x == 0)
1649 return 0;
1650 /* We've tested LLONG_MAX for 64 bits so this should be safe. */
1651 for (i = 0; i < 64; i++)
1652 if (x & (1ULL << i))
1653 break;
1654 return i + 1;
1657 void
1658 generate_fields (enum FEATURE features, struct entry *e, struct entry *parent,
1659 int len)
1661 int r, i, j, ret = 1, n, incr, sametype;
1663 for (n = 0; n < len; n += incr)
1665 r = generate_random ();
1666 /* 50% ETYPE_TYPE base_types NTYPES1
1667 12.5% ETYPE_TYPE other
1668 12.5% ETYPE_ARRAY
1669 12.5% ETYPE_BITFLD
1670 12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1671 i = (r & 7);
1672 r >>= 3;
1673 incr = 1;
1674 switch (i)
1676 case 0:
1677 case 1:
1678 case 2:
1679 case 3:
1680 e[n].etype = ETYPE_TYPE;
1681 e[n].type = &base_types[r % NTYPES1];
1682 break;
1683 case 4:
1684 e[n].etype = ETYPE_TYPE;
1685 choose_type (features, &e[n], r, 0);
1686 break;
1687 case 5:
1688 e[n].etype = ETYPE_ARRAY;
1689 i = r & 1;
1690 r >>= 1;
1691 if (i)
1692 e[n].type = &base_types[r % NTYPES1];
1693 else
1694 choose_type (features, &e[n], r, 1);
1695 r = generate_random ();
1696 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1698 e[n].arr_len = 0;
1699 if (n == len - 1 && (r & 4)
1700 && (parent->etype == ETYPE_STRUCT
1701 || parent->etype == ETYPE_STRUCT_ARRAY))
1703 int k;
1704 for (k = 0; k < n; ++k)
1705 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1707 e[n].arr_len = 255;
1708 break;
1712 else if ((r & 3) != 3)
1713 e[n].arr_len = (r >> 2) & 7;
1714 else
1715 e[n].arr_len = (r >> 2) & 31;
1716 break;
1717 case 6:
1718 sametype = 1;
1719 switch (r & 7)
1721 case 0:
1722 case 1:
1723 case 2:
1724 break;
1725 case 3:
1726 case 4:
1727 case 5:
1728 incr = 1 + (r >> 3) % (len - n);
1729 break;
1730 case 6:
1731 case 7:
1732 sametype = 0;
1733 incr = 1 + (r >> 3) % (len - n);
1734 break;
1736 for (j = n; j < n + incr; ++j)
1738 int mi, ma;
1740 e[j].etype = ETYPE_BITFLD;
1741 if (j == n || !sametype)
1743 int k;
1744 r = generate_random ();
1745 k = r & 3;
1746 r >>= 2;
1747 if (!k)
1748 e[j].type
1749 = &aligned_bitfld_types[r % n_aligned_bitfld_types];
1750 else
1751 e[j].type
1752 = &bitfld_types[r % n_bitfld_types];
1754 else
1755 e[j].type = e[n].type;
1756 r = generate_random ();
1757 mi = 0;
1758 ma = 0;
1759 switch (e[j].type->bitfld)
1761 case 'C': ma = 8; break;
1762 case 'S': ma = 16; break;
1763 case 'I': ma = 32; break;
1764 case 'L':
1765 case 'Q': ma = 64; break;
1766 case 'B': ma = 1; break;
1767 case ' ':
1768 if (e[j].type->type == TYPE_UENUM)
1769 mi = my_ffsll (e[j].type->maxval + 1) - 1;
1770 else if (e[j].type->type == TYPE_SENUM)
1771 mi = my_ffsll (e[j].type->maxval + 1);
1772 else
1773 abort ();
1774 if (!mi)
1775 mi = 1;
1776 if (mi > 32)
1777 ma = 64;
1778 else if (mi > 16 || !short_enums)
1779 ma = 32;
1780 else if (mi > 8)
1781 ma = 16;
1782 else
1783 ma = 8;
1784 break;
1785 default:
1786 abort ();
1788 e[j].len = ma + 1;
1789 if (sametype && (r & 3) == 0 && ma > 1)
1791 int sum = 0, k;
1792 for (k = n; k < j; ++k)
1793 sum += e[k].len;
1794 sum %= ma;
1795 e[j].len = sum ? ma - sum : ma;
1797 r >>= 2;
1798 if (! (features & FEATURE_ZEROBITFLD) && mi == 0)
1799 mi = 1;
1800 if (e[j].len < mi || e[j].len > ma)
1801 e[j].len = mi + (r % (ma + 1 - mi));
1802 r >>= 6;
1803 if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0
1804 && mi == 0)
1805 e[j].len = 0;
1807 break;
1808 case 7:
1809 switch (r & 7)
1811 case 0:
1812 case 1:
1813 case 2:
1814 e[n].etype = ETYPE_STRUCT;
1815 break;
1816 case 3:
1817 case 4:
1818 e[n].etype = ETYPE_UNION;
1819 break;
1820 case 5:
1821 case 6:
1822 e[n].etype = ETYPE_STRUCT_ARRAY;
1823 break;
1824 case 7:
1825 e[n].etype = ETYPE_UNION_ARRAY;
1826 break;
1828 r >>= 3;
1829 e[n].len = r % (len - n);
1830 incr = 1 + e[n].len;
1831 generate_fields (features, &e[n + 1], &e[n], e[n].len);
1832 if (e[n].etype == ETYPE_STRUCT_ARRAY
1833 || e[n].etype == ETYPE_UNION_ARRAY)
1835 r = generate_random ();
1836 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1838 e[n].arr_len = 0;
1839 if (n + incr == len && (r & 4)
1840 && (parent->etype == ETYPE_STRUCT
1841 || parent->etype == ETYPE_STRUCT_ARRAY))
1843 int k;
1844 for (k = 0; k < n; ++k)
1845 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1847 e[n].arr_len = 255;
1848 break;
1852 else if ((r & 3) != 3)
1853 e[n].arr_len = (r >> 2) & 7;
1854 else
1855 e[n].arr_len = (r >> 2) & 31;
1857 break;
1859 r = generate_random ();
1860 if ((r & 7) == 0)
1862 r >>= 3;
1863 i = (features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1;
1864 e[n].attrib = attributes[r % i];
1865 if (! (features & FEATURE_ALIGNEDPACKED)
1866 && strcmp (e[n].attrib, "atpa") == 0
1867 && ((e[n].type >= &attrib_types[0]
1868 && e[n].type < &attrib_types[NATYPES2])
1869 || (e[n].type >= &complex_attrib_types[0]
1870 && e[n].type < &complex_attrib_types[NCATYPES2])
1871 || (e[n].type >= &attrib_array_types[0]
1872 && e[n].type < &attrib_array_types[NAATYPES2])
1873 || (e[n].type >= &complex_attrib_array_types[0]
1874 && e[n].type < &complex_attrib_array_types[NAATYPES2])
1875 || (e[n].type >= &aligned_bitfld_types[0]
1876 && e[n].type < &aligned_bitfld_types[n_aligned_bitfld_types])))
1877 e[n].attrib = NULL;
1882 void
1883 generate_random_tests (enum FEATURE features, int len)
1885 struct entry e[len + 1];
1886 int i, r;
1887 if (len > 'z' - 'a' + 1)
1888 abort ();
1889 memset (e, 0, sizeof (e));
1890 r = generate_random ();
1891 if ((r & 7) == 0)
1892 e[0].etype = ETYPE_UNION;
1893 else
1894 e[0].etype = ETYPE_STRUCT;
1895 r >>= 3;
1896 e[0].len = len;
1897 if ((r & 31) == 0)
1899 r >>= 5;
1900 if (features & FEATURE_ALIGNEDPACKED)
1901 r %= NATTRIBS2;
1902 else
1903 r %= NATTRIBS1;
1904 e[0].attrib = attributes[r];
1906 generate_fields (features, &e[1], &e[0], len);
1907 output (e);
1910 struct { const char *name; enum FEATURE f; }
1911 features[] = {
1912 { "normal", 0 },
1913 { "complex", FEATURE_COMPLEX },
1914 { "vector", FEATURE_VECTOR },
1915 { "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD },
1916 { "complex vector [0]",
1917 FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY },
1918 { "aligned packed complex vector [0] :0",
1919 FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1920 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD },
1924 main (int argc, char **argv)
1926 int i, j, count, c, n = 3000;
1927 char *optarg;
1929 if (sizeof (int) != 4 || sizeof (long long) != 8)
1930 return 1;
1932 i = 1;
1933 while (i < argc)
1935 c = '\0';
1936 if (argv[i][0] == '-' && argv[i][2] == '\0')
1937 c = argv[i][1];
1938 optarg = argv[i + 1];
1939 if (!optarg)
1940 goto usage;
1941 switch (c)
1943 case 'n':
1944 n = atoi (optarg);
1945 break;
1946 case 'd':
1947 destdir = optarg;
1948 break;
1949 case 's':
1950 srcdir = optarg;
1951 break;
1952 case 'i':
1953 output_one = 1;
1954 limidx = atoi (optarg);
1955 break;
1956 case 'e':
1957 short_enums = 1;
1958 i--;
1959 break;
1960 default:
1961 fprintf (stderr, "unrecognized option %s\n", argv[i]);
1962 goto usage;
1964 i += 2;
1967 if (output_one)
1969 outfile = fopen ("/dev/null", "w");
1970 if (outfile == NULL)
1972 fputs ("could not open /dev/null", stderr);
1973 return 1;
1975 n = limidx + 1;
1978 if (destdir == NULL && !output_one)
1980 usage:
1981 fprintf (stderr, "Usage:\n\
1982 %s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\
1983 Either -s srcdir -d destdir or -i idx must be used\n", argv[0]);
1984 return 1;
1987 if (srcdir == NULL && !output_one)
1988 goto usage;
1990 for (i = 0; i < NTYPES2; ++i)
1991 if (base_types[i].bitfld)
1992 bitfld_types[n_bitfld_types++] = base_types[i];
1993 for (i = 0; i < NATYPES2; ++i)
1994 if (attrib_types[i].bitfld)
1995 aligned_bitfld_types[n_aligned_bitfld_types++] = attrib_types[i];
1996 for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i)
1998 int startidx = idx;
1999 if (! output_one)
2000 limidx = idx;
2001 if (!i)
2002 count = 200;
2003 else
2004 count = 20;
2005 for (j = 1; j <= 9; ++j)
2006 while (idx < startidx + j * count)
2007 generate_random_tests (features[i].f, j);
2008 while (idx < startidx + count * 10)
2009 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
2011 for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i)
2013 int startidx;
2014 startidx = idx;
2015 if (! output_one)
2016 limidx = idx;
2017 singles (features[i].f);
2018 if (!i)
2020 count = 1000;
2021 while (idx < startidx + 1000)
2022 generate_random_tests (features[i].f, 1);
2024 else
2026 startidx = idx;
2027 count = 100;
2028 while (idx < startidx + 100)
2029 generate_random_tests (features[i].f, 1);
2031 startidx = idx;
2032 for (j = 2; j <= 9; ++j)
2033 while (idx < startidx + (j - 1) * count)
2034 generate_random_tests (features[i].f, j);
2035 while (idx < startidx + count * 9)
2036 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
2038 if (! output_one)
2039 limidx = idx;
2040 while (idx < n)
2041 generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25));
2042 fclose (outfile);
2043 return 0;