OSDN Git Service

c53c3e8c2bd8f628ad4b33ca6772fbe8a1afa1bc
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / compat / struct-layout-1_generate.c
1 /* Structure layout test generator.
2    Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
3    Contributed by Jakub Jelinek <jakub@redhat.com>.
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>.  */
20
21
22 /* Compile with gcc -o struct-layout-1_generate{,.c} generate_random{,_r}.c */
23
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"
34
35 #if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL
36 # error Need 64-bit long long
37 #endif
38
39 #if defined __MSVCRT__ 
40 #define COMPAT_PRLL "I64"
41 #else 
42 #define COMPAT_PRLL "ll"
43 #endif
44
45 typedef unsigned int hashval_t;
46
47 enum TYPE
48 {
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
61 };
62
63 struct types
64 {
65   const char *name;
66   enum TYPE type;
67   unsigned long long int maxval;
68   char bitfld;
69 };
70
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]))
153 };
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]))
184 };
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]))
216 };
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]))
417 };
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]))
504 };
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]))
609 };
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]))
666 };
667
668 struct types bitfld_types[NTYPES2];
669 int n_bitfld_types;
670 struct types aligned_bitfld_types[NATYPES2];
671 int n_aligned_bitfld_types;
672
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]))
695 };
696
697 enum ETYPE
698 {
699   ETYPE_TYPE,
700   ETYPE_ARRAY,
701   ETYPE_BITFLD,
702   ETYPE_STRUCT,
703   ETYPE_UNION,
704   ETYPE_STRUCT_ARRAY,
705   ETYPE_UNION_ARRAY
706 };
707
708 struct entry
709 {
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;
721 };
722
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];
726
727 static int idx, limidx, output_one, short_enums;
728 static const char *destdir;
729 static const char *srcdir;
730 FILE *outfile;
731
732 void
733 switchfiles (int fields)
734 {
735   static int filecnt;
736   static char *destbuf, *destptr;
737   ++filecnt;
738   if (outfile)
739     fclose (outfile);
740   if (output_one)
741     {
742       outfile = stdout;
743       return;
744     }
745   if (destbuf == NULL)
746     {
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;
755     }
756   sprintf (destptr, "t%03d_main.c", filecnt);
757   outfile = fopen (destbuf, "w");
758   if (outfile == NULL)
759     {
760     fail:
761       fputs ("failed to create test files\n", stderr);
762       exit (1);
763     }
764   fprintf (outfile, "\
765 /* { dg-require-effective-target int32plus } */\n\
766 /* { dg-options \"-I%s\" } */\n\
767 /* { dg-options \"-I%s -fno-common\" { target hppa*-*-hpux* *-*-darwin* *-*-mingw32* *-*-cygwin* } } */\n\
768 /* { dg-options \"-I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
769 #include \"struct-layout-1.h\"\n\
770 \n\
771 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
772 #include \"t%03d_test.h\"\n\
773 #undef TX\n\
774 \n\
775 int main (void)\n\
776 {\n\
777 #define TX(n, type, attrs, fields, ops)   test##n ();\n\
778 #include \"t%03d_test.h\"\n\
779 #undef TX\n\
780   if (fails)\n\
781     {\n\
782       fflush (stdout);\n\
783       abort ();\n\
784     }\n\
785   exit (0);\n\
786 }\n", srcdir, srcdir, srcdir, filecnt, filecnt);
787   fclose (outfile);
788   sprintf (destptr, "t%03d_x.c", filecnt);
789   outfile = fopen (destbuf, "w");
790   if (outfile == NULL)
791     goto fail;
792   fprintf (outfile, "\
793 /* { dg-options \"-w -I%s\" } */\n\
794 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* *-*-darwin* *-*-mingw32* *-*-cygwin* } } */\n\
795 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
796 #include \"struct-layout-1_x1.h\"\n\
797 #include \"t%03d_test.h\"\n\
798 #include \"struct-layout-1_x2.h\"\n\
799 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
800   fclose (outfile);
801   sprintf (destptr, "t%03d_y.c", filecnt);
802   outfile = fopen (destbuf, "w");
803   if (outfile == NULL)
804     goto fail;
805   fprintf (outfile, "\
806 /* { dg-options \"-w -I%s\" } */\n\
807 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* *-*-darwin* *-*-mingw32* *-*-cygwin* } } */\n\
808 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
809 #include \"struct-layout-1_y1.h\"\n\
810 #include \"t%03d_test.h\"\n\
811 #include \"struct-layout-1_y2.h\"\n\
812 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
813   fclose (outfile);
814   sprintf (destptr, "t%03d_test.h", filecnt);
815   outfile = fopen (destbuf, "w");
816   if (outfile == NULL)
817     goto fail;
818   if (fields <= 2)
819     limidx = idx + 300;
820   else if (fields <= 4)
821     limidx = idx + 200;
822   else if (fields <= 6)
823     limidx = idx + 100;
824   else
825     limidx = idx + 50;
826 }
827
828 unsigned long long int
829 getrandll (void)
830 {
831   unsigned long long int ret;
832   ret = generate_random () & 0xffffff;
833   ret |= (generate_random () & 0xffffffLL) << 24;
834   ret |= ((unsigned long long int) generate_random ()) << 48;
835   return ret;
836 }
837
838 int
839 subfield (struct entry *e, char *letter)
840 {
841   int i, type;
842   char buf[20];
843   const char *p;
844   switch (e[0].etype)
845     {
846     case ETYPE_STRUCT:
847     case ETYPE_UNION:
848     case ETYPE_STRUCT_ARRAY:
849     case ETYPE_UNION_ARRAY:
850       type = e[0].attrib ? 1 + (generate_random () & 3) : 0;
851       if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY)
852         p = "struct";
853       else
854         p = "union";
855       if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY)
856         {
857           if (e[0].arr_len == 255)
858             snprintf (buf, 20, "%c[]", *letter);
859           else
860             snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
861           /* If this is an array type, do not put aligned attributes on
862              elements.  Aligning elements to a value greater than their
863              size will result in a compiler error.  */
864           if (type == 1
865               && ((strncmp (e[0].attrib, "atal", 4) == 0)
866                    || strncmp (e[0].attrib, "atpaal", 6) == 0))
867             type = 2;
868         }
869       else
870         {
871           buf[0] = *letter;
872           buf[1] = '\0';
873         }
874       ++*letter;
875       switch (type)
876         {
877         case 0:
878         case 3:
879         case 4:
880           fprintf (outfile, "%s{", p);
881           break;
882         case 1:
883           fprintf (outfile, "%s %s{", e[0].attrib, p);
884           break;
885         case 2:
886           fprintf (outfile, "%s %s{", p, e[0].attrib);
887           break;
888         }
889
890       for (i = 1; i <= e[0].len; )
891         i += subfield (e + i, letter);
892
893       switch (type)
894         {
895         case 0:
896         case 1:
897         case 2:
898           fprintf (outfile, "}%s;", buf);
899           break;
900         case 3:
901           fprintf (outfile, "}%s %s;", e[0].attrib, buf);
902           break;
903         case 4:
904           fprintf (outfile, "}%s %s;", buf, e[0].attrib);
905           break;
906         }
907       return 1 + e[0].len;
908     case ETYPE_TYPE:
909     case ETYPE_ARRAY:
910       if (e[0].etype == ETYPE_ARRAY)
911         {
912           if (e[0].arr_len == 255)
913             snprintf (buf, 20, "%c[]", *letter);
914           else
915             snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
916         }
917       else
918         {
919           buf[0] = *letter;
920           buf[1] = '\0';
921         }
922       ++*letter;
923       if (e[0].attrib)
924         {
925           /* If this is an array type, do not put aligned attributes on
926              elements.  Aligning elements to a value greater than their
927              size will result in a compiler error.  */
928           if (e[0].etype == ETYPE_ARRAY
929               && ((strncmp (e[0].attrib, "atal", 4) == 0)
930                    || strncmp (e[0].attrib, "atpaal", 6) == 0))
931             type = 2;
932           else
933             type = generate_random () % 3;
934           switch (type)
935             {
936             case 0:
937               fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name,
938                        buf);
939               break;
940             case 1:
941               fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib,
942                        buf);
943               break;
944             case 2:
945               fprintf (outfile, "%s %s %s;", e[0].type->name, buf,
946                        e[0].attrib);
947               break;
948             }
949         }
950       else
951         fprintf (outfile, "%s %s;", e[0].type->name, buf);
952       return 1;
953     case ETYPE_BITFLD:
954       if (e[0].len == 0)
955         {
956           if (e[0].attrib)
957             switch (generate_random () % 3)
958               {
959               case 0:
960                 fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name);
961                 break;
962               case 1:
963                 fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib);
964                 break;
965               case 2:
966                 fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib);
967                 break;
968               }
969           else
970             fprintf (outfile, "%s:0;", e[0].type->name);
971           ++*letter;
972           return 1;
973         }
974       switch (e[0].type->bitfld)
975         {
976         case 'C':
977         case 'S':
978         case 'I':
979         case 'L':
980         case 'Q':
981           snprintf (buf, 20, "B%cN(%d)", e[0].type->bitfld, e[0].len);
982           break;
983         case 'B':
984         case ' ':
985           snprintf (buf, 20, "%d", e[0].len);
986           break;
987         default:
988           abort ();
989         }
990       if (e[0].attrib)
991         switch (generate_random () % 3)
992           {
993           case 0:
994             fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name,
995                      *letter, buf);
996             break;
997           case 1:
998             fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib,
999                      *letter, buf);
1000             break;
1001           case 2:
1002             fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter,
1003                      buf, e[0].attrib);
1004             break;
1005           }
1006       else
1007         fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf);
1008       ++*letter;
1009       return 1;
1010     default:
1011       abort ();
1012   }
1013 }
1014
1015 char namebuf[1024];
1016
1017 void
1018 output_FNB (char mode, struct entry *e)
1019 {
1020   unsigned long long int l1, l2, m;
1021   int signs = 0;
1022 #ifndef SKIP_DECIMAL_FLOAT
1023   int suffix = 0;
1024   char DEC_SUFFIX[3][3]={"DF","DD","DL"};
1025 #endif
1026   
1027   const char *p, *q;
1028
1029   if (e->type->type == TYPE_OTHER)
1030     {
1031       if (mode == 'B')
1032         abort ();
1033       fprintf (outfile, "N(%d,%s)", idx, namebuf);
1034       return;
1035     }
1036   fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf);
1037   l1 = getrandll ();
1038   l2 = getrandll ();
1039   switch (e->type->type)
1040     {
1041     case TYPE_INT:
1042       signs = generate_random () & 3;
1043       m = e->type->maxval;
1044       if (mode == 'B')
1045         m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1;
1046       l1 &= m;
1047       l2 &= m;
1048       fprintf (outfile, "%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s",
1049                (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1050                (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1051       break;
1052     case TYPE_UINT:
1053       m = e->type->maxval;
1054       if (mode == 'B')
1055         m &= (1ULL << e->len) - 1;
1056       l1 &= m;
1057       l2 &= m;
1058       fprintf (outfile, "%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s",
1059                l1, l1 > 4294967295U ? "LL" : "",
1060                l2, l2 > 4294967295U ? "LL" : "");
1061       break;
1062     case TYPE_FLOAT:
1063       l1 &= 0xffffff;
1064       l2 &= 0xffffff;
1065       signs = generate_random () & 3;
1066       fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "",
1067                ((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64);
1068       break;
1069 #ifndef SKIP_DECIMAL_FLOAT
1070     case TYPE_DEC_FLOAT:
1071       l1 &= 0xffffff;
1072       l2 &= 0xffffff;
1073       signs = generate_random () & 3;
1074       
1075       /* Get the suffix of Decimal Floting Points per 
1076          e->type->name.  Distinguish these three DFP types by
1077          e->type->name.  */
1078       if (strstr(e->type->name, "Decimal32")) suffix=0;
1079       else if (strstr(e->type->name, "Decimal64")) suffix=1;
1080       else if (strstr(e->type->name, "Decimal128")) suffix=2;
1081       else
1082         abort ();
1083
1084       /* Formatted input/output specifiers for DFP types have not been
1085          implemented in GLIBC.  %f here used in fprintf is just to 
1086          dump the numbers to outfile.  */
1087       fprintf (outfile, "%s%f%s,%s%f%s", 
1088                (signs & 1) ? "-" : "", ((double) l1) / 64, DEC_SUFFIX[suffix], 
1089                (signs & 2) ? "-" : "", ((double) l2) / 64, DEC_SUFFIX[suffix]);
1090       break;
1091 #endif
1092     case TYPE_CINT:
1093       signs = generate_random () & 3;
1094       l1 &= e->type->maxval;
1095       l2 &= e->type->maxval;
1096       fprintf (outfile,
1097                "CINT(%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s),",
1098                (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1099                (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1100       signs = generate_random () & 3;
1101       l1 = getrandll ();
1102       l2 = getrandll ();
1103       l1 &= e->type->maxval;
1104       l2 &= e->type->maxval;
1105       fprintf (outfile,
1106                "CINT(%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s)",
1107                (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1108                (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1109       break;
1110     case TYPE_CUINT:
1111       l1 &= e->type->maxval;
1112       l2 &= e->type->maxval;
1113       fprintf (outfile,
1114                "CINT(%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s),",
1115                l1, l1 > 4294967295U ? "LL" : "",
1116                l2, l2 > 4294967295U ? "LL" : "");
1117       l1 = getrandll ();
1118       l2 = getrandll ();
1119       l1 &= e->type->maxval;
1120       l2 &= e->type->maxval;
1121       fprintf (outfile,
1122                "CINT(%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s)",
1123                l1, l1 > 4294967295U ? "LL" : "",
1124                l2, l2 > 4294967295U ? "LL" : "");
1125       break;
1126     case TYPE_CFLOAT:
1127       l1 &= 0xffffff;
1128       l2 &= 0xffffff;
1129       signs = generate_random () & 3;
1130       fprintf (outfile, "CDBL(%s%f,%s%f),",
1131                (signs & 1) ? "-" : "", ((double) l1) / 64,
1132                (signs & 2) ? "-" : "", ((double) l2) / 64);
1133       l1 = getrandll ();
1134       l2 = getrandll ();
1135       l1 &= 0xffffff;
1136       l2 &= 0xffffff;
1137       signs = generate_random () & 3;
1138       fprintf (outfile, "CDBL(%s%f,%s%f)",
1139                (signs & 1) ? "-" : "", ((double) l1) / 64,
1140                (signs & 2) ? "-" : "", ((double) l2) / 64);
1141       break;
1142     case TYPE_UENUM:
1143       if (e->type->maxval == 0)
1144         fputs ("e0_0,e0_0", outfile);
1145       else if (e->type->maxval == 1)
1146         fprintf (outfile, "e1_%" COMPAT_PRLL "d,e1_%" COMPAT_PRLL "d",
1147                  l1 & 1, l2 & 1);
1148       else
1149         {
1150           p = strchr (e->type->name, '\0');
1151           while (--p >= e->type->name && *p >= '0' && *p <= '9');
1152           p++;
1153           l1 %= 7;
1154           l2 %= 7;
1155           if (l1 > 3)
1156             l1 += e->type->maxval - 6;
1157           if (l2 > 3)
1158             l2 += e->type->maxval - 6;
1159           fprintf (outfile, "e%s_%" COMPAT_PRLL "d,e%s_%" COMPAT_PRLL "d",
1160                    p, l1, p, l2);
1161         }
1162       break;
1163     case TYPE_SENUM:
1164       p = strchr (e->type->name, '\0');
1165       while (--p >= e->type->name && *p >= '0' && *p <= '9');
1166       p++;
1167       l1 %= 7;
1168       l2 %= 7;
1169       fprintf (outfile, "e%s_%s%" COMPAT_PRLL "d,e%s_%s%" COMPAT_PRLL "d",
1170                p, l1 < 3 ? "m" : "",
1171                l1 == 3 ? 0LL : e->type->maxval - (l1 & 3),
1172                p, l2 < 3 ? "m" : "",
1173                l2 == 3 ? 0LL : e->type->maxval - (l2 & 3));
1174       break;
1175     case TYPE_PTR:
1176       l1 %= 256;
1177       l2 %= 256;
1178       fprintf (outfile,
1179                "(%s)&intarray[%" COMPAT_PRLL "d], (%s)&intarray[%" COMPAT_PRLL "d]",
1180                e->type->name, l1, e->type->name, l2);
1181       break;
1182     case TYPE_FNPTR:
1183       l1 %= 10;
1184       l2 %= 10;
1185       fprintf (outfile, "fn%" COMPAT_PRLL "d,fn%" COMPAT_PRLL "d", l1, l2);
1186       break;
1187     default:
1188       abort ();
1189     }
1190   fputs (")", outfile);
1191 }
1192
1193 int
1194 subvalues (struct entry *e, char *p, char *letter)
1195 {
1196   int i, j;
1197   char *q;
1198   if (p >= namebuf + sizeof (namebuf) - 32)
1199     abort ();
1200   p[0] = *letter;
1201   p[1] = '\0';
1202   q = p + 1;
1203   switch (e[0].etype)
1204     {
1205     case ETYPE_STRUCT_ARRAY:
1206     case ETYPE_UNION_ARRAY:
1207       if (e[0].arr_len == 0 || e[0].arr_len == 255)
1208         {
1209           *letter += 1 + e[0].len;
1210           return 1 + e[0].len;
1211         }
1212       i = generate_random () % e[0].arr_len;
1213       snprintf (p, sizeof (namebuf) - (p - namebuf) - 1,
1214                 "%c[%d]", *letter, i);
1215       q = strchr (p, '\0');
1216       /* FALLTHROUGH */
1217     case ETYPE_STRUCT:
1218     case ETYPE_UNION:
1219       *q++ = '.';
1220       ++*letter;
1221       for (i = 1; i <= e[0].len; )
1222         {
1223           i += subvalues (e + i, q, letter);
1224           if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY)
1225             {
1226               *letter += e[0].len - i + 1;
1227               break;
1228             }
1229         }
1230       return 1 + e[0].len;
1231     case ETYPE_TYPE:
1232       ++*letter;
1233       output_FNB ('F', e);
1234       return 1;
1235     case ETYPE_ARRAY:
1236       if (e[0].arr_len == 0 || e[0].arr_len == 255)
1237         {
1238           ++*letter;
1239           return 1;
1240         }
1241       i = generate_random () % e[0].arr_len;
1242       snprintf (p, sizeof (namebuf) - (p - namebuf),
1243                 "%c[%d]", *letter, i);
1244       output_FNB ('F', e);
1245       if ((generate_random () & 7) == 0)
1246         {
1247           j = generate_random () % e[0].arr_len;
1248           if (i != j)
1249             {
1250               snprintf (p, sizeof (namebuf) - (p - namebuf),
1251                         "%c[%d]", *letter, j);
1252               output_FNB ('F', e);
1253             }
1254         }
1255       ++*letter;
1256       return 1;
1257     case ETYPE_BITFLD:
1258       ++*letter;
1259       if (e[0].len != 0)
1260         output_FNB ('B', e);
1261       return 1;
1262     }
1263 }
1264
1265 /* DERIVED FROM:
1266 --------------------------------------------------------------------
1267 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
1268 hash(), hash2(), hash3, and mix() are externally useful functions.
1269 Routines to test the hash are included if SELF_TEST is defined.
1270 You can use this free for any purpose.  It has no warranty.
1271 --------------------------------------------------------------------
1272 */
1273
1274 /*
1275 --------------------------------------------------------------------
1276 mix -- mix 3 32-bit values reversibly.
1277 For every delta with one or two bit set, and the deltas of all three
1278   high bits or all three low bits, whether the original value of a,b,c
1279   is almost all zero or is uniformly distributed,
1280 * If mix() is run forward or backward, at least 32 bits in a,b,c
1281   have at least 1/4 probability of changing.
1282 * If mix() is run forward, every bit of c will change between 1/3 and
1283   2/3 of the time.  (Well, 22/100 and 78/100 for some 2-bit deltas.)
1284 mix() was built out of 36 single-cycle latency instructions in a 
1285   structure that could supported 2x parallelism, like so:
1286       a -= b; 
1287       a -= c; x = (c>>13);
1288       b -= c; a ^= x;
1289       b -= a; x = (a<<8);
1290       c -= a; b ^= x;
1291       c -= b; x = (b>>13);
1292       ...
1293   Unfortunately, superscalar Pentiums and Sparcs can't take advantage 
1294   of that parallelism.  They've also turned some of those single-cycle
1295   latency instructions into multi-cycle latency instructions.  Still,
1296   this is the fastest good hash I could find.  There were about 2^^68
1297   to choose from.  I only looked at a billion or so.
1298 --------------------------------------------------------------------
1299 */
1300 /* same, but slower, works on systems that might have 8 byte hashval_t's */
1301 #define mix(a,b,c) \
1302 { \
1303   a -= b; a -= c; a ^= (c>>13); \
1304   b -= c; b -= a; b ^= (a<< 8); \
1305   c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
1306   a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
1307   b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
1308   c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
1309   a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
1310   b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
1311   c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
1312 }
1313
1314 /*
1315 --------------------------------------------------------------------
1316 hash() -- hash a variable-length key into a 32-bit value
1317   k     : the key (the unaligned variable-length array of bytes)
1318   len   : the length of the key, counting by bytes
1319   level : can be any 4-byte value
1320 Returns a 32-bit value.  Every bit of the key affects every bit of
1321 the return value.  Every 1-bit and 2-bit delta achieves avalanche.
1322 About 36+6len instructions.
1323
1324 The best hash table sizes are powers of 2.  There is no need to do
1325 mod a prime (mod is sooo slow!).  If you need less than 32 bits,
1326 use a bitmask.  For example, if you need only 10 bits, do
1327   h = (h & hashmask(10));
1328 In which case, the hash table should have hashsize(10) elements.
1329
1330 If you are hashing n strings (ub1 **)k, do it like this:
1331   for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
1332
1333 By Bob Jenkins, 1996.  bob_jenkins@burtleburtle.net.  You may use this
1334 code any way you wish, private, educational, or commercial.  It's free.
1335
1336 See http://burtleburtle.net/bob/hash/evahash.html
1337 Use for hash table lookup, or anything where one collision in 2^32 is
1338 acceptable.  Do NOT use for cryptographic purposes.
1339 --------------------------------------------------------------------
1340 */
1341
1342 static hashval_t
1343 iterative_hash (const void *k_in /* the key */,
1344                 register size_t  length /* the length of the key */,
1345                 register hashval_t initval /* the previous hash, or
1346                                               an arbitrary value */)
1347 {
1348   register const unsigned char *k = (const unsigned char *)k_in;
1349   register hashval_t a,b,c,len;
1350
1351   /* Set up the internal state */
1352   len = length;
1353   a = b = 0x9e3779b9;  /* the golden ratio; an arbitrary value */
1354   c = initval;           /* the previous hash value */
1355
1356   /*---------------------------------------- handle most of the key */
1357     while (len >= 12)
1358       {
1359         a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24));
1360         b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24));
1361         c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24));
1362         mix(a,b,c);
1363         k += 12; len -= 12;
1364       }
1365
1366   /*------------------------------------- handle the last 11 bytes */
1367   c += length;
1368   switch(len)              /* all the case statements fall through */
1369     {
1370     case 11: c+=((hashval_t)k[10]<<24);
1371     case 10: c+=((hashval_t)k[9]<<16);
1372     case 9 : c+=((hashval_t)k[8]<<8);
1373       /* the first byte of c is reserved for the length */
1374     case 8 : b+=((hashval_t)k[7]<<24);
1375     case 7 : b+=((hashval_t)k[6]<<16);
1376     case 6 : b+=((hashval_t)k[5]<<8);
1377     case 5 : b+=k[4];
1378     case 4 : a+=((hashval_t)k[3]<<24);
1379     case 3 : a+=((hashval_t)k[2]<<16);
1380     case 2 : a+=((hashval_t)k[1]<<8);
1381     case 1 : a+=k[0];
1382       /* case 0: nothing left to add */
1383     }
1384   mix(a,b,c);
1385   /*-------------------------------------------- report the result */
1386   return c;
1387 }
1388
1389 hashval_t
1390 e_hash (const void *a)
1391 {
1392   const struct entry *e = a;
1393   hashval_t ret = 0;
1394   int i;
1395
1396   if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1397     abort ();
1398   for (i = 0; i <= e[0].len; ++i)
1399     {
1400       int attriblen;
1401       ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret);
1402       attriblen = e[i].attrib ? strlen (e[i].attrib) : -1;
1403       ret = iterative_hash (&attriblen, sizeof (int), ret);
1404       if (e[i].attrib)
1405         ret = iterative_hash (e[i].attrib, attriblen, ret);
1406     }
1407   return ret;
1408 }
1409
1410 int
1411 e_eq (const void *a, const void *b)
1412 {
1413   const struct entry *ea = a, *eb = b;
1414   int i;
1415   if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION)
1416     abort ();
1417   if (ea[0].len != eb[0].len)
1418     return 0;
1419   for (i = 0; i <= ea[0].len; ++i)
1420     {
1421       if (ea[i].etype != eb[i].etype
1422           || ea[i].len != eb[i].len
1423           || ea[i].arr_len != eb[i].arr_len
1424           || ea[i].type != eb[i].type)
1425         return 0;
1426       if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL))
1427         return 0;
1428       if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0)
1429         return 0;
1430     }
1431   return 1;
1432 }
1433
1434 static int 
1435 e_exists (const struct entry *e) 
1436 {
1437   struct entry *h;
1438   hashval_t hval;
1439
1440   hval = e_hash (e);
1441   for (h = hash_table[hval % HASH_SIZE]; h; h = h->next)
1442     if (e_eq (e, h))
1443       return 1;
1444   return 0;
1445 }
1446
1447 static void
1448 e_insert (struct entry *e)
1449 {
1450   hashval_t hval;
1451
1452   hval = e_hash (e);
1453   e->next = hash_table[hval % HASH_SIZE];
1454   hash_table[hval % HASH_SIZE] = e;
1455 }
1456
1457 void
1458 output (struct entry *e)
1459 {
1460   int i;
1461   char c;
1462   struct entry *n;
1463   const char *skip_cint = "";
1464
1465   if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1466     abort ();
1467
1468   if (e_exists (e))
1469     return;
1470
1471   n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry));
1472   memcpy (n, e, (e[0].len + 1) * sizeof (struct entry));
1473   e_insert (n);
1474
1475   if (idx == limidx)
1476     switchfiles (e[0].len);
1477
1478   for (i = 1; i <= e[0].len; ++i)
1479     if ((e[i].etype == ETYPE_TYPE || e[i].etype == ETYPE_ARRAY)
1480         && (e[i].type->type == TYPE_CINT || e[i].type->type == TYPE_CUINT))
1481       break;
1482   if (i <= e[0].len)
1483     skip_cint = "CI";
1484   if (e[0].attrib)
1485     fprintf (outfile, (generate_random () & 1)
1486              ? "TX%s(%d,%s %s,," : "TX%s(%d,%s,%s,", skip_cint,
1487              idx, e[0].etype == ETYPE_STRUCT ? "struct" : "union",
1488              e[0].attrib);
1489   else if (e[0].etype == ETYPE_STRUCT)
1490     fprintf (outfile, "T%s(%d,", skip_cint, idx);
1491   else
1492     fprintf (outfile, "U%s(%d,", skip_cint, idx);
1493   c = 'a';
1494   for (i = 1; i <= e[0].len; )
1495     i += subfield (e + i, &c);
1496   fputs (",", outfile);
1497   c = 'a';
1498   for (i = 1; i <= e[0].len; )
1499     {
1500       i += subvalues (e + i, namebuf, &c);
1501       if (e[0].etype == ETYPE_UNION)
1502         break;
1503     }
1504   fputs (")\n", outfile);
1505   if (output_one && idx == limidx)
1506     exit (0);
1507   ++idx;
1508 }
1509
1510 enum FEATURE
1511 {
1512   FEATURE_VECTOR = 1,
1513   FEATURE_COMPLEX = 2,
1514   FEATURE_ALIGNEDPACKED = 4,
1515   FEATURE_ZEROARRAY = 8,
1516   FEATURE_ZEROBITFLD = 16,
1517   ALL_FEATURES = FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1518                  | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD
1519 };
1520
1521 void
1522 singles (enum FEATURE features)
1523 {
1524   struct entry e[2];
1525   int i;
1526   memset (e, 0, sizeof (e));
1527   e[0].etype = ETYPE_STRUCT;
1528   output (e);
1529   e[0].etype = ETYPE_UNION;
1530   output (e);
1531   for (i = 0;
1532        i < ((features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1);
1533        ++i)
1534     {
1535       e[0].attrib = attributes[i];
1536       e[0].etype = ETYPE_STRUCT;
1537       output (e);
1538       e[0].etype = ETYPE_UNION;
1539       output (e);
1540     }
1541   e[0].len = 1;
1542   e[0].attrib = NULL;
1543   for (i = 0; i < NTYPES2; ++i)
1544     {
1545       e[0].etype = ETYPE_STRUCT;
1546       e[1].etype = ETYPE_TYPE;
1547       e[1].type = &base_types[i];
1548       output (e);
1549       e[0].etype = ETYPE_UNION;
1550       output (e);
1551     }
1552   if (features & FEATURE_COMPLEX)
1553     for (i = 0; i < NCTYPES2; ++i)
1554       {
1555         e[0].etype = ETYPE_STRUCT;
1556         e[1].etype = ETYPE_TYPE;
1557         e[1].type = &complex_types[i];
1558         output (e);
1559         e[0].etype = ETYPE_UNION;
1560         output (e);
1561       }
1562   if (features & FEATURE_VECTOR)
1563     for (i = 0; i < NVTYPES2; ++i)
1564       {
1565         e[0].etype = ETYPE_STRUCT;
1566         e[1].etype = ETYPE_TYPE;
1567         e[1].type = &vector_types[i];
1568         output (e);
1569         e[0].etype = ETYPE_UNION;
1570         output (e);
1571       }
1572 }
1573
1574 void
1575 choose_type (enum FEATURE features, struct entry *e, int r, int in_array)
1576 {
1577   int i;
1578
1579   i = NTYPES2 - NTYPES1;
1580   if (features & FEATURE_COMPLEX)
1581     i += NCTYPES2;
1582   if (features & FEATURE_VECTOR)
1583     i += NVTYPES2;
1584   if ((r & 3) == 0)
1585     {
1586       if (in_array)
1587         {
1588           i += NAATYPES2;
1589           if (features & FEATURE_COMPLEX)
1590             i += NCAATYPES2;
1591         }
1592       else
1593         {
1594           i += NATYPES2;
1595           if (features & FEATURE_COMPLEX)
1596             i += NCATYPES2;
1597         }
1598     }
1599   r >>= 2;
1600   r %= i;
1601   if (r < NTYPES2 - NTYPES1)
1602     e->type = &base_types[r + NTYPES1];
1603   r -= NTYPES2 - NTYPES1;
1604   if (e->type == NULL && (features & FEATURE_COMPLEX))
1605     {
1606       if (r < NCTYPES2)
1607         e->type = &complex_types[r];
1608       r -= NCTYPES2;
1609     }
1610   if (e->type == NULL && (features & FEATURE_VECTOR))
1611     {
1612       if (r < NVTYPES2)
1613         e->type = &vector_types[r];
1614       r -= NVTYPES2;
1615     }
1616   if (e->type == NULL && !in_array)
1617     {
1618       if (r < NATYPES2)
1619         e->type = &attrib_types[r];
1620       r -= NATYPES2;
1621     }
1622   if (e->type == NULL && !in_array && (features & FEATURE_COMPLEX))
1623     {
1624       if (r < NCATYPES2)
1625         e->type = &complex_attrib_types[r];
1626       r -= NCATYPES2;
1627     }
1628   if (e->type == NULL && in_array)
1629     {
1630       if (r < NAATYPES2)
1631         e->type = &attrib_array_types[r];
1632       r -= NAATYPES2;
1633     }
1634   if (e->type == NULL && in_array && (features & FEATURE_COMPLEX))
1635     {
1636       if (r < NCAATYPES2)
1637         e->type = &complex_attrib_array_types[r];
1638       r -= NCAATYPES2;
1639     }
1640   if (e->type == NULL)
1641     abort ();
1642 }
1643
1644 /* This is from gcc.c-torture/execute/builtin-bitops-1.c.  */
1645 static int
1646 my_ffsll (unsigned long long x)
1647 {
1648   int i;
1649   if (x == 0)
1650     return 0;
1651   /* We've tested LLONG_MAX for 64 bits so this should be safe.  */
1652   for (i = 0; i < 64; i++)
1653     if (x & (1ULL << i))
1654       break;
1655   return i + 1;
1656 }
1657
1658 void
1659 generate_fields (enum FEATURE features, struct entry *e, struct entry *parent,
1660                  int len)
1661 {
1662   int r, i, j, ret = 1, n, incr, sametype;
1663
1664   for (n = 0; n < len; n += incr)
1665     {
1666       r = generate_random ();
1667       /* 50% ETYPE_TYPE base_types NTYPES1
1668          12.5% ETYPE_TYPE other
1669          12.5% ETYPE_ARRAY
1670          12.5% ETYPE_BITFLD
1671          12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1672       i = (r & 7);
1673       r >>= 3;
1674       incr = 1;
1675       switch (i)
1676         {
1677         case 0:
1678         case 1:
1679         case 2:
1680         case 3:
1681           e[n].etype = ETYPE_TYPE;
1682           e[n].type = &base_types[r % NTYPES1];
1683           break;
1684         case 4:
1685           e[n].etype = ETYPE_TYPE;
1686           choose_type (features, &e[n], r, 0);
1687           break;
1688         case 5:
1689           e[n].etype = ETYPE_ARRAY;
1690           i = r & 1;
1691           r >>= 1;
1692           if (i)
1693             e[n].type = &base_types[r % NTYPES1];
1694           else
1695             choose_type (features, &e[n], r, 1);
1696           r = generate_random ();
1697           if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1698             {
1699               e[n].arr_len = 0;
1700               if (n == len - 1 && (r & 4)
1701                   && (parent->etype == ETYPE_STRUCT
1702                       || parent->etype == ETYPE_STRUCT_ARRAY))
1703                 {
1704                   int k;
1705                   for (k = 0; k < n; ++k)
1706                     if (e[k].etype != ETYPE_BITFLD || e[k].len)
1707                       {
1708                         e[n].arr_len = 255;
1709                         break;
1710                       }
1711                 }
1712             }
1713           else if ((r & 3) != 3)
1714             e[n].arr_len = (r >> 2) & 7;
1715           else
1716             e[n].arr_len = (r >> 2) & 31;
1717           break;
1718         case 6:
1719           sametype = 1;
1720           switch (r & 7)
1721             {
1722             case 0:
1723             case 1:
1724             case 2:
1725               break;
1726             case 3:
1727             case 4:
1728             case 5:
1729               incr = 1 + (r >> 3) % (len - n);
1730               break;
1731             case 6:
1732             case 7:
1733               sametype = 0;
1734               incr = 1 + (r >> 3) % (len - n);
1735               break;
1736             }
1737           for (j = n; j < n + incr; ++j)
1738             {
1739               int mi, ma;
1740
1741               e[j].etype = ETYPE_BITFLD;
1742               if (j == n || !sametype)
1743                 {
1744                   int k;
1745                   r = generate_random ();
1746                   k = r & 3;
1747                   r >>= 2;
1748                   if (!k)
1749                     e[j].type
1750                       = &aligned_bitfld_types[r % n_aligned_bitfld_types];
1751                   else
1752                     e[j].type
1753                       = &bitfld_types[r % n_bitfld_types];
1754                 }
1755               else
1756                 e[j].type = e[n].type;
1757               r = generate_random ();
1758               mi = 0;
1759               ma = 0;
1760               switch (e[j].type->bitfld)
1761                 {
1762                 case 'C': ma = 8; break;
1763                 case 'S': ma = 16; break;
1764                 case 'I': ma = 32; break;
1765                 case 'L':
1766                 case 'Q': ma = 64; break;
1767                 case 'B': ma = 1; break;
1768                 case ' ':
1769                   if (e[j].type->type == TYPE_UENUM)
1770                     mi = my_ffsll (e[j].type->maxval + 1) - 1;
1771                   else if (e[j].type->type == TYPE_SENUM)
1772                     mi = my_ffsll (e[j].type->maxval + 1);
1773                   else
1774                     abort ();
1775                   if (!mi)
1776                     mi = 1;
1777                   if (mi > 32)
1778                     ma = 64;
1779                   else if (mi > 16 || !short_enums)
1780                     ma = 32;
1781                   else if (mi > 8)
1782                     ma = 16;
1783                   else
1784                     ma = 8;
1785                   break;
1786                 default:
1787                   abort ();
1788                 }
1789               e[j].len = ma + 1;
1790               if (sametype && (r & 3) == 0 && ma > 1)
1791                 {
1792                   int sum = 0, k;
1793                   for (k = n; k < j; ++k)
1794                     sum += e[k].len;
1795                   sum %= ma;
1796                   e[j].len = sum ? ma - sum : ma;
1797                 }
1798               r >>= 2;
1799               if (! (features & FEATURE_ZEROBITFLD) && mi == 0)
1800                 mi = 1;
1801               if (e[j].len < mi || e[j].len > ma)
1802                 e[j].len = mi + (r % (ma + 1 - mi));
1803               r >>= 6;
1804               if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0
1805                   && mi == 0)
1806                 e[j].len = 0;
1807             }
1808           break;
1809         case 7:
1810           switch (r & 7)
1811             {
1812             case 0:
1813             case 1:
1814             case 2:
1815               e[n].etype = ETYPE_STRUCT;
1816               break;
1817             case 3:
1818             case 4:
1819               e[n].etype = ETYPE_UNION;
1820               break;
1821             case 5:
1822             case 6:
1823               e[n].etype = ETYPE_STRUCT_ARRAY;
1824               break;
1825             case 7:
1826               e[n].etype = ETYPE_UNION_ARRAY;
1827               break;
1828             }
1829           r >>= 3;
1830           e[n].len = r % (len - n);
1831           incr = 1 + e[n].len;
1832           generate_fields (features, &e[n + 1], &e[n], e[n].len);
1833           if (e[n].etype == ETYPE_STRUCT_ARRAY
1834               || e[n].etype == ETYPE_UNION_ARRAY)
1835             {
1836               r = generate_random ();
1837               if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1838                 {
1839                   e[n].arr_len = 0;
1840                   if (n + incr == len && (r & 4)
1841                       && (parent->etype == ETYPE_STRUCT
1842                           || parent->etype == ETYPE_STRUCT_ARRAY))
1843                     {
1844                       int k;
1845                       for (k = 0; k < n; ++k)
1846                         if (e[k].etype != ETYPE_BITFLD || e[k].len)
1847                           {
1848                             e[n].arr_len = 255;
1849                             break;
1850                           }
1851                     }
1852                 }
1853               else if ((r & 3) != 3)
1854                 e[n].arr_len = (r >> 2) & 7;
1855               else
1856                 e[n].arr_len = (r >> 2) & 31;
1857             }
1858           break;
1859         }
1860       r = generate_random ();
1861       if ((r & 7) == 0)
1862         {
1863           r >>= 3;
1864           i = (features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1;
1865           e[n].attrib = attributes[r % i];
1866           if (! (features & FEATURE_ALIGNEDPACKED)
1867               && strcmp (e[n].attrib, "atpa") == 0
1868               && ((e[n].type >= &attrib_types[0]
1869                    && e[n].type < &attrib_types[NATYPES2])
1870                   || (e[n].type >= &complex_attrib_types[0]
1871                       && e[n].type < &complex_attrib_types[NCATYPES2])
1872                   || (e[n].type >= &attrib_array_types[0]
1873                       && e[n].type < &attrib_array_types[NAATYPES2])
1874                   || (e[n].type >= &complex_attrib_array_types[0]
1875                       && e[n].type < &complex_attrib_array_types[NAATYPES2])
1876                   || (e[n].type >= &aligned_bitfld_types[0]
1877                       && e[n].type < &aligned_bitfld_types[n_aligned_bitfld_types])))
1878             e[n].attrib = NULL;
1879         }
1880     }
1881 }
1882
1883 void
1884 generate_random_tests (enum FEATURE features, int len)
1885 {
1886   struct entry e[len + 1];
1887   int i, r;
1888   if (len > 'z' - 'a' + 1)
1889     abort ();
1890   memset (e, 0, sizeof (e));
1891   r = generate_random ();
1892   if ((r & 7) == 0)
1893     e[0].etype = ETYPE_UNION;
1894   else
1895     e[0].etype = ETYPE_STRUCT;
1896   r >>= 3;
1897   e[0].len = len;
1898   if ((r & 31) == 0)
1899     {
1900       r >>= 5;
1901       if (features & FEATURE_ALIGNEDPACKED)
1902         r %= NATTRIBS2;
1903       else
1904         r %= NATTRIBS1;
1905       e[0].attrib = attributes[r];
1906     }
1907   generate_fields (features, &e[1], &e[0], len);
1908   output (e);
1909 }
1910
1911 struct { const char *name; enum FEATURE f; }
1912 features[] = {
1913 { "normal", 0 },
1914 { "complex", FEATURE_COMPLEX },
1915 { "vector", FEATURE_VECTOR },
1916 { "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD },
1917 { "complex vector [0]",
1918   FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY },
1919 { "aligned packed complex vector [0] :0",
1920   FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1921   | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD },
1922 };
1923
1924 int
1925 main (int argc, char **argv)
1926 {
1927   int i, j, count, c, n = 3000;
1928   char *optarg;
1929
1930   if (sizeof (int) != 4 || sizeof (long long) != 8)
1931     return 1;
1932   
1933   i = 1;
1934   while (i < argc) 
1935     {
1936       c = '\0';
1937       if (argv[i][0] == '-' && argv[i][2] == '\0')
1938         c = argv[i][1];
1939       optarg = argv[i + 1];
1940       if (!optarg)
1941         goto usage;
1942       switch (c)
1943         {
1944         case 'n':
1945           n = atoi (optarg);
1946           break;
1947         case 'd':
1948           destdir = optarg;
1949           break;
1950         case 's':
1951           srcdir = optarg;
1952           break;
1953         case 'i':
1954           output_one = 1;
1955           limidx = atoi (optarg);
1956           break;
1957         case 'e':
1958           short_enums = 1;
1959           i--;
1960           break;
1961         default:
1962           fprintf (stderr, "unrecognized option %s\n", argv[i]);
1963           goto usage;
1964       }
1965       i += 2;
1966     }
1967
1968   if (output_one)
1969     {
1970       outfile = fopen ("/dev/null", "w");
1971       if (outfile == NULL)
1972         {
1973           fputs ("could not open /dev/null", stderr);
1974           return 1;
1975         }
1976       n = limidx + 1;
1977     }
1978
1979   if (destdir == NULL && !output_one)
1980     {
1981     usage:
1982       fprintf (stderr, "Usage:\n\
1983 %s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\
1984 Either -s srcdir -d destdir or -i idx must be used\n", argv[0]);
1985       return 1;
1986     }
1987
1988   if (srcdir == NULL && !output_one)
1989     goto usage;
1990
1991   for (i = 0; i < NTYPES2; ++i)
1992     if (base_types[i].bitfld)
1993       bitfld_types[n_bitfld_types++] = base_types[i];
1994   for (i = 0; i < NATYPES2; ++i)
1995     if (attrib_types[i].bitfld)
1996       aligned_bitfld_types[n_aligned_bitfld_types++] = attrib_types[i];
1997   for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i)
1998     {
1999       int startidx = idx;
2000       if (! output_one)
2001         limidx = idx;
2002       if (!i)
2003         count = 200;
2004       else
2005         count = 20;
2006       for (j = 1; j <= 9; ++j)
2007         while (idx < startidx + j * count)
2008           generate_random_tests (features[i].f, j);
2009       while (idx < startidx + count * 10)
2010         generate_random_tests (features[i].f, 10 + (generate_random () % 16));
2011     }
2012   for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i)
2013     {
2014       int startidx;
2015       startidx = idx;
2016       if (! output_one)
2017         limidx = idx;
2018       singles (features[i].f);
2019       if (!i)
2020         {
2021           count = 1000;
2022           while (idx < startidx + 1000)
2023             generate_random_tests (features[i].f, 1);
2024         }
2025       else
2026         {
2027           startidx = idx;
2028           count = 100;
2029           while (idx < startidx + 100)
2030             generate_random_tests (features[i].f, 1);
2031         }
2032       startidx = idx;
2033       for (j = 2; j <= 9; ++j)
2034         while (idx < startidx + (j - 1) * count)
2035           generate_random_tests (features[i].f, j);
2036       while (idx < startidx + count * 9)
2037         generate_random_tests (features[i].f, 10 + (generate_random () % 16));
2038     }
2039   if (! output_one)
2040     limidx = idx;
2041   while (idx < n)
2042     generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25));
2043   fclose (outfile);
2044   return 0;
2045 }