Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / testsuite / gcc.dg / compat / struct-layout-1_generate.c
blobcca2954c448100ec105fa4abf61850737afee6c3
1 /* Structure layout test generator.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3 Contributed by Jakub Jelinek <jakub@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
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 COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
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 typedef unsigned int hashval_t;
41 enum TYPE
43 TYPE_INT,
44 TYPE_UINT,
45 TYPE_CINT,
46 TYPE_CUINT,
47 TYPE_FLOAT,
48 TYPE_CFLOAT,
49 TYPE_SENUM,
50 TYPE_UENUM,
51 TYPE_PTR,
52 TYPE_FNPTR,
53 TYPE_OTHER
56 struct types
58 const char *name;
59 enum TYPE type;
60 unsigned long long int maxval;
61 char bitfld;
64 struct types base_types[] = {
65 /* As we don't know whether char will be signed or not, just limit ourselves
66 to unsigned values less than maximum signed char value. */
67 { "char", TYPE_UINT, 127, 'C' },
68 { "signed char", TYPE_INT, 127, 'C' },
69 { "unsigned char", TYPE_UINT, 255, 'C' },
70 { "short int", TYPE_INT, 32767, 'S' },
71 { "unsigned short int", TYPE_UINT, 65535, 'S' },
72 { "int", TYPE_INT, 2147483647, 'I' },
73 { "unsigned int", TYPE_UINT, 4294967295U, 'I' },
74 { "long int", TYPE_INT, 9223372036854775807LL, 'L' },
75 { "unsigned long int", TYPE_UINT, 18446744073709551615ULL, 'L' },
76 { "long long int", TYPE_INT, 9223372036854775807LL, 'Q' },
77 { "unsigned long long int", TYPE_UINT, 18446744073709551615ULL, 'Q' },
78 { "bool", TYPE_UINT, 1, 'B' },
79 { "void *", TYPE_PTR, 0, 0 },
80 { "char *", TYPE_PTR, 0, 0 },
81 { "int *", TYPE_PTR, 0, 0 },
82 { "float", TYPE_FLOAT, 0, 0 },
83 { "double", TYPE_FLOAT, 0, 0 },
84 { "long double", TYPE_FLOAT, 0, 0 },
85 #define NTYPES1 18
86 { "Tchar", TYPE_UINT, 127, 'C' },
87 { "Tschar", TYPE_INT, 127, 'C' },
88 { "Tuchar", TYPE_UINT, 255, 'C' },
89 { "Tshort", TYPE_INT, 32767, 'S' },
90 { "Tushort", TYPE_UINT, 65535, 'S' },
91 { "Tint", TYPE_INT, 2147483647, 'I' },
92 { "Tuint", TYPE_UINT, 4294967295U, 'I' },
93 { "Tlong", TYPE_INT, 9223372036854775807LL, 'L' },
94 { "Tulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
95 { "Tllong", TYPE_INT, 9223372036854775807LL, 'Q' },
96 { "Tullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
97 { "Tbool", TYPE_UINT, 1, 'B' },
98 { "size_t", TYPE_UINT, 18446744073709551615ULL, 0 },
99 { "Tptr", TYPE_PTR, 0, 0 },
100 { "Tcptr", TYPE_PTR, 0, 0 },
101 { "Tiptr", TYPE_PTR, 0, 0 },
102 { "Tfnptr", TYPE_FNPTR, 0, 0 },
103 { "Tfloat", TYPE_FLOAT, 0, 0 },
104 { "Tdouble", TYPE_FLOAT, 0, 0 },
105 { "Tldouble", TYPE_FLOAT, 0, 0 },
106 { "enum E0", TYPE_UENUM, 0, ' ' },
107 { "enum E1", TYPE_UENUM, 1, ' ' },
108 { "enum E2", TYPE_SENUM, 3, ' ' },
109 { "enum E3", TYPE_SENUM, 127, ' ' },
110 { "enum E4", TYPE_UENUM, 255, ' ' },
111 { "enum E5", TYPE_SENUM, 32767, ' ' },
112 { "enum E6", TYPE_UENUM, 65535, ' ' },
113 { "enum E7", TYPE_SENUM, 2147483647, ' ' },
114 { "enum E8", TYPE_UENUM, 4294967295U, ' ' },
115 { "enum E9", TYPE_SENUM, 1099511627775LL, ' ' },
116 { "TE0", TYPE_UENUM, 0, ' ' },
117 { "TE1", TYPE_UENUM, 1, ' ' },
118 { "TE2", TYPE_SENUM, 3, ' ' },
119 { "TE3", TYPE_SENUM, 127, ' ' },
120 { "TE4", TYPE_UENUM, 255, ' ' },
121 { "TE5", TYPE_SENUM, 32767, ' ' },
122 { "TE6", TYPE_UENUM, 65535, ' ' },
123 { "TE7", TYPE_SENUM, 2147483647, ' ' },
124 { "TE8", TYPE_UENUM, 4294967295U, ' ' },
125 { "TE9", TYPE_SENUM, 1099511627775LL, ' ' },
126 /* vector-defs.h typedefs */
127 { "qi", TYPE_INT, 127, 0 },
128 { "hi", TYPE_INT, 32767, 0 },
129 { "si", TYPE_INT, 2147483647, 0 },
130 { "di", TYPE_INT, 9223372036854775807LL, 0 },
131 { "sf", TYPE_FLOAT, 0, 0 },
132 { "df", TYPE_FLOAT, 0, 0 }
133 #define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
135 struct types complex_types[] = {
136 { "_Complex char", TYPE_CUINT, 127, 0 },
137 { "_Complex signed char", TYPE_CINT, 127, 0 },
138 { "_Complex unsigned char", TYPE_CUINT, 255, 0 },
139 { "_Complex short int", TYPE_CINT, 32767, 0 },
140 { "_Complex unsigned short int", TYPE_CUINT, 65535, 0 },
141 { "_Complex int", TYPE_CINT, 2147483647, 0 },
142 { "_Complex unsigned int", TYPE_CUINT, 4294967295U, 0 },
143 { "_Complex long int", TYPE_CINT, 9223372036854775807LL, 0 },
144 { "_Complex unsigned long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
145 { "_Complex long long int", TYPE_CINT, 9223372036854775807LL, 0 },
146 { "_Complex unsigned long long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
147 { "_Complex float", TYPE_CFLOAT, 0, 0 },
148 { "_Complex double", TYPE_CFLOAT, 0, 0 },
149 { "_Complex long double", TYPE_CFLOAT, 0, 0 },
150 { "Tcchar", TYPE_CUINT, 127, 0 },
151 { "Tcschar", TYPE_CINT, 127, 0 },
152 { "Tcuchar", TYPE_CUINT, 255, 0 },
153 { "Tcshort", TYPE_CINT, 32767, 0 },
154 { "Tcushort", TYPE_CUINT, 65535, 0 },
155 { "Tcint", TYPE_CINT, 2147483647, 0 },
156 { "Tcuint", TYPE_CUINT, 4294967295U, 0 },
157 { "Tclong", TYPE_CINT, 9223372036854775807LL, 0 },
158 { "Tculong", TYPE_CUINT, 18446744073709551615ULL, 0 },
159 { "Tcllong", TYPE_CINT, 9223372036854775807LL, 0 },
160 { "Tcullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
161 { "Tcfloat", TYPE_CFLOAT, 0, 0 },
162 { "Tcdouble", TYPE_CFLOAT, 0, 0 },
163 { "Tcldouble", TYPE_CFLOAT, 0, 0 }
164 #define NCTYPES2 (sizeof (complex_types) / sizeof (complex_types[0]))
166 struct types vector_types[] = {
167 /* vector-defs.h typedefs */
168 { "v8qi", TYPE_OTHER, 0, 0 },
169 { "v16qi", TYPE_OTHER, 0, 0 },
170 { "v2hi", TYPE_OTHER, 0, 0 },
171 { "v4hi", TYPE_OTHER, 0, 0 },
172 { "v8hi", TYPE_OTHER, 0, 0 },
173 { "v2si", TYPE_OTHER, 0, 0 },
174 { "v4si", TYPE_OTHER, 0, 0 },
175 { "v1di", TYPE_OTHER, 0, 0 },
176 { "v2di", TYPE_OTHER, 0, 0 },
177 { "v2sf", TYPE_OTHER, 0, 0 },
178 { "v4sf", TYPE_OTHER, 0, 0 },
179 { "v16sf", TYPE_OTHER, 0, 0 },
180 { "v2df", TYPE_OTHER, 0, 0 },
181 { "u8qi", TYPE_OTHER, 0, 0 },
182 { "u16qi", TYPE_OTHER, 0, 0 },
183 { "u2hi", TYPE_OTHER, 0, 0 },
184 { "u4hi", TYPE_OTHER, 0, 0 },
185 { "u8hi", TYPE_OTHER, 0, 0 },
186 { "u2si", TYPE_OTHER, 0, 0 },
187 { "u4si", TYPE_OTHER, 0, 0 },
188 { "u1di", TYPE_OTHER, 0, 0 },
189 { "u2di", TYPE_OTHER, 0, 0 },
190 { "u2sf", TYPE_OTHER, 0, 0 },
191 { "u4sf", TYPE_OTHER, 0, 0 },
192 { "u16sf", TYPE_OTHER, 0, 0 },
193 { "u2df", TYPE_OTHER, 0, 0 },
194 { "__m64", TYPE_OTHER, 0, 0 },
195 { "__m128", TYPE_OTHER, 0, 0 }
196 #define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
198 struct types attrib_types[] = {
199 { "Talchar", TYPE_UINT, 127, 'C' },
200 { "Talschar", TYPE_INT, 127, 'C' },
201 { "Taluchar", TYPE_UINT, 255, 'C' },
202 { "Talshort", TYPE_INT, 32767, 'S' },
203 { "Talushort", TYPE_UINT, 65535, 'S' },
204 { "Talint", TYPE_INT, 2147483647, 'I' },
205 { "Taluint", TYPE_UINT, 4294967295U, 'I' },
206 { "Tallong", TYPE_INT, 9223372036854775807LL, 'L' },
207 { "Talulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
208 { "Talllong", TYPE_INT, 9223372036854775807LL, 'Q' },
209 { "Talullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
210 { "Talbool", TYPE_UINT, 1, 'B' },
211 { "Talptr", TYPE_PTR, 0, 0 },
212 { "Talcptr", TYPE_PTR, 0, 0 },
213 { "Taliptr", TYPE_PTR, 0, 0 },
214 { "Talfloat", TYPE_FLOAT, 0, 0 },
215 { "Taldouble", TYPE_FLOAT, 0, 0 },
216 { "Talldouble", TYPE_FLOAT, 0, 0 },
217 { "TalE0", TYPE_UENUM, 0, ' ' },
218 { "TalE1", TYPE_UENUM, 1, ' ' },
219 { "TalE2", TYPE_SENUM, 3, ' ' },
220 { "TalE3", TYPE_SENUM, 127, ' ' },
221 { "TalE4", TYPE_UENUM, 255, ' ' },
222 { "TalE5", TYPE_SENUM, 32767, ' ' },
223 { "TalE6", TYPE_UENUM, 65535, ' ' },
224 { "TalE7", TYPE_SENUM, 2147483647, ' ' },
225 { "TalE8", TYPE_UENUM, 4294967295U, ' ' },
226 { "TalE9", TYPE_SENUM, 1099511627775LL, ' ' },
227 { "Tal1char", TYPE_UINT, 127, 'C' },
228 { "Tal1schar", TYPE_INT, 127, 'C' },
229 { "Tal1uchar", TYPE_UINT, 255, 'C' },
230 { "Tal1short", TYPE_INT, 32767, 'S' },
231 { "Tal1ushort", TYPE_UINT, 65535, 'S' },
232 { "Tal1int", TYPE_INT, 2147483647, 'I' },
233 { "Tal1uint", TYPE_UINT, 4294967295U, 'I' },
234 { "Tal1long", TYPE_INT, 9223372036854775807LL, 'L' },
235 { "Tal1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
236 { "Tal1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
237 { "Tal1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
238 { "Tal1bool", TYPE_UINT, 1, 'B' },
239 { "Tal1ptr", TYPE_PTR, 0, 0 },
240 { "Tal1cptr", TYPE_PTR, 0, 0 },
241 { "Tal1iptr", TYPE_PTR, 0, 0 },
242 { "Tal1float", TYPE_FLOAT, 0, 0 },
243 { "Tal1double", TYPE_FLOAT, 0, 0 },
244 { "Tal1ldouble", TYPE_FLOAT, 0, 0 },
245 { "Tal1E0", TYPE_UENUM, 0, ' ' },
246 { "Tal1E1", TYPE_UENUM, 1, ' ' },
247 { "Tal1E2", TYPE_SENUM, 3, ' ' },
248 { "Tal1E3", TYPE_SENUM, 127, ' ' },
249 { "Tal1E4", TYPE_UENUM, 255, ' ' },
250 { "Tal1E5", TYPE_SENUM, 32767, ' ' },
251 { "Tal1E6", TYPE_UENUM, 65535, ' ' },
252 { "Tal1E7", TYPE_SENUM, 2147483647, ' ' },
253 { "Tal1E8", TYPE_UENUM, 4294967295U, ' ' },
254 { "Tal1E9", TYPE_SENUM, 1099511627775LL, ' ' },
255 { "Tal2char", TYPE_UINT, 127, 'C' },
256 { "Tal2schar", TYPE_INT, 127, 'C' },
257 { "Tal2uchar", TYPE_UINT, 255, 'C' },
258 { "Tal2short", TYPE_INT, 32767, 'S' },
259 { "Tal2ushort", TYPE_UINT, 65535, 'S' },
260 { "Tal2int", TYPE_INT, 2147483647, 'I' },
261 { "Tal2uint", TYPE_UINT, 4294967295U, 'I' },
262 { "Tal2long", TYPE_INT, 9223372036854775807LL, 'L' },
263 { "Tal2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
264 { "Tal2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
265 { "Tal2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
266 { "Tal2bool", TYPE_UINT, 1, 'B' },
267 { "Tal2ptr", TYPE_PTR, 0, 0 },
268 { "Tal2cptr", TYPE_PTR, 0, 0 },
269 { "Tal2iptr", TYPE_PTR, 0, 0 },
270 { "Tal2float", TYPE_FLOAT, 0, 0 },
271 { "Tal2double", TYPE_FLOAT, 0, 0 },
272 { "Tal2ldouble", TYPE_FLOAT, 0, 0 },
273 { "Tal2E0", TYPE_UENUM, 0, ' ' },
274 { "Tal2E1", TYPE_UENUM, 1, ' ' },
275 { "Tal2E2", TYPE_SENUM, 3, ' ' },
276 { "Tal2E3", TYPE_SENUM, 127, ' ' },
277 { "Tal2E4", TYPE_UENUM, 255, ' ' },
278 { "Tal2E5", TYPE_SENUM, 32767, ' ' },
279 { "Tal2E6", TYPE_UENUM, 65535, ' ' },
280 { "Tal2E7", TYPE_SENUM, 2147483647, ' ' },
281 { "Tal2E8", TYPE_UENUM, 4294967295U, ' ' },
282 { "Tal2E9", TYPE_SENUM, 1099511627775LL, ' ' },
283 { "Tal4char", TYPE_UINT, 127, 'C' },
284 { "Tal4schar", TYPE_INT, 127, 'C' },
285 { "Tal4uchar", TYPE_UINT, 255, 'C' },
286 { "Tal4short", TYPE_INT, 32767, 'S' },
287 { "Tal4ushort", TYPE_UINT, 65535, 'S' },
288 { "Tal4int", TYPE_INT, 2147483647, 'I' },
289 { "Tal4uint", TYPE_UINT, 4294967295U, 'I' },
290 { "Tal4long", TYPE_INT, 9223372036854775807LL, 'L' },
291 { "Tal4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
292 { "Tal4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
293 { "Tal4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
294 { "Tal4bool", TYPE_UINT, 1, 'B' },
295 { "Tal4ptr", TYPE_PTR, 0, 0 },
296 { "Tal4cptr", TYPE_PTR, 0, 0 },
297 { "Tal4iptr", TYPE_PTR, 0, 0 },
298 { "Tal4float", TYPE_FLOAT, 0, 0 },
299 { "Tal4double", TYPE_FLOAT, 0, 0 },
300 { "Tal4ldouble", TYPE_FLOAT, 0, 0 },
301 { "Tal4E0", TYPE_UENUM, 0, ' ' },
302 { "Tal4E1", TYPE_UENUM, 1, ' ' },
303 { "Tal4E2", TYPE_SENUM, 3, ' ' },
304 { "Tal4E3", TYPE_SENUM, 127, ' ' },
305 { "Tal4E4", TYPE_UENUM, 255, ' ' },
306 { "Tal4E5", TYPE_SENUM, 32767, ' ' },
307 { "Tal4E6", TYPE_UENUM, 65535, ' ' },
308 { "Tal4E7", TYPE_SENUM, 2147483647, ' ' },
309 { "Tal4E8", TYPE_UENUM, 4294967295U, ' ' },
310 { "Tal4E9", TYPE_SENUM, 1099511627775LL, ' ' },
311 { "Tal8char", TYPE_UINT, 127, 'C' },
312 { "Tal8schar", TYPE_INT, 127, 'C' },
313 { "Tal8uchar", TYPE_UINT, 255, 'C' },
314 { "Tal8short", TYPE_INT, 32767, 'S' },
315 { "Tal8ushort", TYPE_UINT, 65535, 'S' },
316 { "Tal8int", TYPE_INT, 2147483647, 'I' },
317 { "Tal8uint", TYPE_UINT, 4294967295U, 'I' },
318 { "Tal8long", TYPE_INT, 9223372036854775807LL, 'L' },
319 { "Tal8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
320 { "Tal8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
321 { "Tal8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
322 { "Tal8bool", TYPE_UINT, 1, 'B' },
323 { "Tal8ptr", TYPE_PTR, 0, 0 },
324 { "Tal8cptr", TYPE_PTR, 0, 0 },
325 { "Tal8iptr", TYPE_PTR, 0, 0 },
326 { "Tal8float", TYPE_FLOAT, 0, 0 },
327 { "Tal8double", TYPE_FLOAT, 0, 0 },
328 { "Tal8ldouble", TYPE_FLOAT, 0, 0 },
329 { "Tal8E0", TYPE_UENUM, 0, ' ' },
330 { "Tal8E1", TYPE_UENUM, 1, ' ' },
331 { "Tal8E2", TYPE_SENUM, 3, ' ' },
332 { "Tal8E3", TYPE_SENUM, 127, ' ' },
333 { "Tal8E4", TYPE_UENUM, 255, ' ' },
334 { "Tal8E5", TYPE_SENUM, 32767, ' ' },
335 { "Tal8E6", TYPE_UENUM, 65535, ' ' },
336 { "Tal8E7", TYPE_SENUM, 2147483647, ' ' },
337 { "Tal8E8", TYPE_UENUM, 4294967295U, ' ' },
338 { "Tal8E9", TYPE_SENUM, 1099511627775LL, ' ' },
339 { "Tal16char", TYPE_UINT, 127, 'C' },
340 { "Tal16schar", TYPE_INT, 127, 'C' },
341 { "Tal16uchar", TYPE_UINT, 255, 'C' },
342 { "Tal16short", TYPE_INT, 32767, 'S' },
343 { "Tal16ushort", TYPE_UINT, 65535, 'S' },
344 { "Tal16int", TYPE_INT, 2147483647, 'I' },
345 { "Tal16uint", TYPE_UINT, 4294967295U, 'I' },
346 { "Tal16long", TYPE_INT, 9223372036854775807LL, 'L' },
347 { "Tal16ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
348 { "Tal16llong", TYPE_INT, 9223372036854775807LL, 'Q' },
349 { "Tal16ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
350 { "Tal16bool", TYPE_UINT, 1, 'B' },
351 { "Tal16ptr", TYPE_PTR, 0, 0 },
352 { "Tal16cptr", TYPE_PTR, 0, 0 },
353 { "Tal16iptr", TYPE_PTR, 0, 0 },
354 { "Tal16float", TYPE_FLOAT, 0, 0 },
355 { "Tal16double", TYPE_FLOAT, 0, 0 },
356 { "Tal16ldouble", TYPE_FLOAT, 0, 0 },
357 { "Tal16E0", TYPE_UENUM, 0, ' ' },
358 { "Tal16E1", TYPE_UENUM, 1, ' ' },
359 { "Tal16E2", TYPE_SENUM, 3, ' ' },
360 { "Tal16E3", TYPE_SENUM, 127, ' ' },
361 { "Tal16E4", TYPE_UENUM, 255, ' ' },
362 { "Tal16E5", TYPE_SENUM, 32767, ' ' },
363 { "Tal16E6", TYPE_UENUM, 65535, ' ' },
364 { "Tal16E7", TYPE_SENUM, 2147483647, ' ' },
365 { "Tal16E8", TYPE_UENUM, 4294967295U, ' ' },
366 { "Tal16E9", TYPE_SENUM, 1099511627775LL, ' ' }
367 #define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0]))
369 struct types complex_attrib_types[] = {
370 { "Talcchar", TYPE_CUINT, 127, 0 },
371 { "Talcschar", TYPE_CINT, 127, 0 },
372 { "Talcuchar", TYPE_CUINT, 255, 0 },
373 { "Talcshort", TYPE_CINT, 32767, 0 },
374 { "Talcushort", TYPE_CUINT, 65535, 0 },
375 { "Talcint", TYPE_CINT, 2147483647, 0 },
376 { "Talcuint", TYPE_CUINT, 4294967295U, 0 },
377 { "Talclong", TYPE_CINT, 9223372036854775807LL, 0 },
378 { "Talculong", TYPE_CUINT, 18446744073709551615ULL, 0 },
379 { "Talcllong", TYPE_CINT, 9223372036854775807LL, 0 },
380 { "Talcullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
381 { "Talcfloat", TYPE_CFLOAT, 0, 0 },
382 { "Talcdouble", TYPE_CFLOAT, 0, 0 },
383 { "Talcldouble", TYPE_CFLOAT, 0, 0 },
384 { "Tal1cchar", TYPE_CUINT, 127, 0 },
385 { "Tal1cschar", TYPE_CINT, 127, 0 },
386 { "Tal1cuchar", TYPE_CUINT, 255, 0 },
387 { "Tal1cshort", TYPE_CINT, 32767, 0 },
388 { "Tal1cushort", TYPE_CUINT, 65535, 0 },
389 { "Tal1cint", TYPE_CINT, 2147483647, 0 },
390 { "Tal1cuint", TYPE_CUINT, 4294967295U, 0 },
391 { "Tal1clong", TYPE_CINT, 9223372036854775807LL, 0 },
392 { "Tal1culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
393 { "Tal1cllong", TYPE_CINT, 9223372036854775807LL, 0 },
394 { "Tal1cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
395 { "Tal1cfloat", TYPE_CFLOAT, 0, 0 },
396 { "Tal1cdouble", TYPE_CFLOAT, 0, 0 },
397 { "Tal1cldouble", TYPE_CFLOAT, 0, 0 },
398 { "Tal2cchar", TYPE_CUINT, 127, 0 },
399 { "Tal2cschar", TYPE_CINT, 127, 0 },
400 { "Tal2cuchar", TYPE_CUINT, 255, 0 },
401 { "Tal2cshort", TYPE_CINT, 32767, 0 },
402 { "Tal2cushort", TYPE_CUINT, 65535, 0 },
403 { "Tal2cint", TYPE_CINT, 2147483647, 0 },
404 { "Tal2cuint", TYPE_CUINT, 4294967295U, 0 },
405 { "Tal2clong", TYPE_CINT, 9223372036854775807LL, 0 },
406 { "Tal2culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
407 { "Tal2cllong", TYPE_CINT, 9223372036854775807LL, 0 },
408 { "Tal2cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
409 { "Tal2cfloat", TYPE_CFLOAT, 0, 0 },
410 { "Tal2cdouble", TYPE_CFLOAT, 0, 0 },
411 { "Tal2cldouble", TYPE_CFLOAT, 0, 0 },
412 { "Tal4cchar", TYPE_CUINT, 127, 0 },
413 { "Tal4cschar", TYPE_CINT, 127, 0 },
414 { "Tal4cuchar", TYPE_CUINT, 255, 0 },
415 { "Tal4cshort", TYPE_CINT, 32767, 0 },
416 { "Tal4cushort", TYPE_CUINT, 65535, 0 },
417 { "Tal4cint", TYPE_CINT, 2147483647, 0 },
418 { "Tal4cuint", TYPE_CUINT, 4294967295U, 0 },
419 { "Tal4clong", TYPE_CINT, 9223372036854775807LL, 0 },
420 { "Tal4culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
421 { "Tal4cllong", TYPE_CINT, 9223372036854775807LL, 0 },
422 { "Tal4cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
423 { "Tal4cfloat", TYPE_CFLOAT, 0, 0 },
424 { "Tal4cdouble", TYPE_CFLOAT, 0, 0 },
425 { "Tal4cldouble", TYPE_CFLOAT, 0, 0 },
426 { "Tal8cchar", TYPE_CUINT, 127, 0 },
427 { "Tal8cschar", TYPE_CINT, 127, 0 },
428 { "Tal8cuchar", TYPE_CUINT, 255, 0 },
429 { "Tal8cshort", TYPE_CINT, 32767, 0 },
430 { "Tal8cushort", TYPE_CUINT, 65535, 0 },
431 { "Tal8cint", TYPE_CINT, 2147483647, 0 },
432 { "Tal8cuint", TYPE_CUINT, 4294967295U, 0 },
433 { "Tal8clong", TYPE_CINT, 9223372036854775807LL, 0 },
434 { "Tal8culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
435 { "Tal8cllong", TYPE_CINT, 9223372036854775807LL, 0 },
436 { "Tal8cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
437 { "Tal8cfloat", TYPE_CFLOAT, 0, 0 },
438 { "Tal8cdouble", TYPE_CFLOAT, 0, 0 },
439 { "Tal8cldouble", TYPE_CFLOAT, 0, 0 },
440 { "Tal16cchar", TYPE_CUINT, 127, 0 },
441 { "Tal16cschar", TYPE_CINT, 127, 0 },
442 { "Tal16cuchar", TYPE_CUINT, 255, 0 },
443 { "Tal16cshort", TYPE_CINT, 32767, 0 },
444 { "Tal16cushort", TYPE_CUINT, 65535, 0 },
445 { "Tal16cint", TYPE_CINT, 2147483647, 0 },
446 { "Tal16cuint", TYPE_CUINT, 4294967295U, 0 },
447 { "Tal16clong", TYPE_CINT, 9223372036854775807LL, 0 },
448 { "Tal16culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
449 { "Tal16cllong", TYPE_CINT, 9223372036854775807LL, 0 },
450 { "Tal16cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
451 { "Tal16cfloat", TYPE_CFLOAT, 0, 0 },
452 { "Tal16cdouble", TYPE_CFLOAT, 0, 0 },
453 { "Tal16cldouble", TYPE_CFLOAT, 0, 0 }
454 #define NCATYPES2 (sizeof (complex_attrib_types) / sizeof (complex_attrib_types[0]))
456 struct types attrib_array_types[] = {
457 { "Talx1char", TYPE_UINT, 127, 'C' },
458 { "Talx1schar", TYPE_INT, 127, 'C' },
459 { "Talx1uchar", TYPE_UINT, 255, 'C' },
460 { "Talx1short", TYPE_INT, 32767, 'S' },
461 { "Talx1ushort", TYPE_UINT, 65535, 'S' },
462 { "Talx1int", TYPE_INT, 2147483647, 'I' },
463 { "Talx1uint", TYPE_UINT, 4294967295U, 'I' },
464 { "Talx1long", TYPE_INT, 9223372036854775807LL, 'L' },
465 { "Talx1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
466 { "Talx1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
467 { "Talx1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
468 { "Talx1bool", TYPE_UINT, 1, 'B' },
469 { "Talx1ptr", TYPE_PTR, 0, 0 },
470 { "Talx1cptr", TYPE_PTR, 0, 0 },
471 { "Talx1iptr", TYPE_PTR, 0, 0 },
472 { "Talx1float", TYPE_FLOAT, 0, 0 },
473 { "Talx1double", TYPE_FLOAT, 0, 0 },
474 { "Talx1ldouble", TYPE_FLOAT, 0, 0 },
475 { "Talx1E0", TYPE_UENUM, 0, ' ' },
476 { "Talx1E1", TYPE_UENUM, 1, ' ' },
477 { "Talx1E2", TYPE_SENUM, 3, ' ' },
478 { "Talx1E3", TYPE_SENUM, 127, ' ' },
479 { "Talx1E4", TYPE_UENUM, 255, ' ' },
480 { "Talx1E5", TYPE_SENUM, 32767, ' ' },
481 { "Talx1E6", TYPE_UENUM, 65535, ' ' },
482 { "Talx1E7", TYPE_SENUM, 2147483647, ' ' },
483 { "Talx1E8", TYPE_UENUM, 4294967295U, ' ' },
484 { "Talx1E9", TYPE_SENUM, 1099511627775LL, ' ' },
485 { "Talx2short", TYPE_INT, 32767, 'S' },
486 { "Talx2ushort", TYPE_UINT, 65535, 'S' },
487 { "Talx2int", TYPE_INT, 2147483647, 'I' },
488 { "Talx2uint", TYPE_UINT, 4294967295U, 'I' },
489 { "Talx2long", TYPE_INT, 9223372036854775807LL, 'L' },
490 { "Talx2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
491 { "Talx2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
492 { "Talx2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
493 { "Talx2ptr", TYPE_PTR, 0, 0 },
494 { "Talx2cptr", TYPE_PTR, 0, 0 },
495 { "Talx2iptr", TYPE_PTR, 0, 0 },
496 { "Talx2float", TYPE_FLOAT, 0, 0 },
497 { "Talx2double", TYPE_FLOAT, 0, 0 },
498 { "Talx2ldouble", TYPE_FLOAT, 0, 0 },
499 { "Talx2E0", TYPE_UENUM, 0, ' ' },
500 { "Talx2E1", TYPE_UENUM, 1, ' ' },
501 { "Talx2E2", TYPE_SENUM, 3, ' ' },
502 { "Talx2E3", TYPE_SENUM, 127, ' ' },
503 { "Talx2E4", TYPE_UENUM, 255, ' ' },
504 { "Talx2E5", TYPE_SENUM, 32767, ' ' },
505 { "Talx2E6", TYPE_UENUM, 65535, ' ' },
506 { "Talx2E7", TYPE_SENUM, 2147483647, ' ' },
507 { "Talx2E8", TYPE_UENUM, 4294967295U, ' ' },
508 { "Talx2E9", TYPE_SENUM, 1099511627775LL, ' ' },
509 { "Talx4int", TYPE_INT, 2147483647, 'I' },
510 { "Talx4uint", TYPE_UINT, 4294967295U, 'I' },
511 { "Talx4long", TYPE_INT, 9223372036854775807LL, 'L' },
512 { "Talx4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
513 { "Talx4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
514 { "Talx4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
515 { "Talx4ptr", TYPE_PTR, 0, 0 },
516 { "Talx4cptr", TYPE_PTR, 0, 0 },
517 { "Talx4iptr", TYPE_PTR, 0, 0 },
518 { "Talx4float", TYPE_FLOAT, 0, 0 },
519 { "Talx4double", TYPE_FLOAT, 0, 0 },
520 { "Talx4ldouble", TYPE_FLOAT, 0, 0 },
521 { "Talx4E0", TYPE_UENUM, 0, ' ' },
522 { "Talx4E1", TYPE_UENUM, 1, ' ' },
523 { "Talx4E2", TYPE_SENUM, 3, ' ' },
524 { "Talx4E3", TYPE_SENUM, 127, ' ' },
525 { "Talx4E4", TYPE_UENUM, 255, ' ' },
526 { "Talx4E5", TYPE_SENUM, 32767, ' ' },
527 { "Talx4E6", TYPE_UENUM, 65535, ' ' },
528 { "Talx4E7", TYPE_SENUM, 2147483647, ' ' },
529 { "Talx4E8", TYPE_UENUM, 4294967295U, ' ' },
530 { "Talx4E9", TYPE_SENUM, 1099511627775LL, ' ' },
531 { "Taly8long", TYPE_INT, 9223372036854775807LL, 'L' },
532 { "Taly8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
533 { "Talx8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
534 { "Talx8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
535 { "Taly8ptr", TYPE_PTR, 0, 0 },
536 { "Taly8cptr", TYPE_PTR, 0, 0 },
537 { "Taly8iptr", TYPE_PTR, 0, 0 },
538 { "Talx8double", TYPE_FLOAT, 0, 0 },
539 { "Talx8ldouble", TYPE_FLOAT, 0, 0 }
540 #define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0]))
542 struct types complex_attrib_array_types[] = {
543 { "Talx1cchar", TYPE_CUINT, 127, 0 },
544 { "Talx1cschar", TYPE_CINT, 127, 0 },
545 { "Talx1cuchar", TYPE_CUINT, 255, 0 },
546 { "Talx1cshort", TYPE_CINT, 32767, 0 },
547 { "Talx1cushort", TYPE_CUINT, 65535, 0 },
548 { "Talx1cint", TYPE_CINT, 2147483647, 0 },
549 { "Talx1cuint", TYPE_CUINT, 4294967295U, 0 },
550 { "Talx1clong", TYPE_CINT, 9223372036854775807LL, 0 },
551 { "Talx1culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
552 { "Talx1cllong", TYPE_CINT, 9223372036854775807LL, 0 },
553 { "Talx1cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
554 { "Talx1cfloat", TYPE_CFLOAT, 0, 0 },
555 { "Talx1cdouble", TYPE_CFLOAT, 0, 0 },
556 { "Talx1cldouble", TYPE_CFLOAT, 0, 0 },
557 { "Talx2cchar", TYPE_CUINT, 127, 0 },
558 { "Talx2cschar", TYPE_CINT, 127, 0 },
559 { "Talx2cuchar", TYPE_CUINT, 255, 0 },
560 { "Talx2cshort", TYPE_CINT, 32767, 0 },
561 { "Talx2cushort", TYPE_CUINT, 65535, 0 },
562 { "Talx2cint", TYPE_CINT, 2147483647, 0 },
563 { "Talx2cuint", TYPE_CUINT, 4294967295U, 0 },
564 { "Talx2clong", TYPE_CINT, 9223372036854775807LL, 0 },
565 { "Talx2culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
566 { "Talx2cllong", TYPE_CINT, 9223372036854775807LL, 0 },
567 { "Talx2cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
568 { "Talx2cfloat", TYPE_CFLOAT, 0, 0 },
569 { "Talx2cdouble", TYPE_CFLOAT, 0, 0 },
570 { "Talx2cldouble", TYPE_CFLOAT, 0, 0 },
571 { "Talx4cshort", TYPE_CINT, 32767, 0 },
572 { "Talx4cushort", TYPE_CUINT, 65535, 0 },
573 { "Talx4cint", TYPE_CINT, 2147483647, 0 },
574 { "Talx4cuint", TYPE_CUINT, 4294967295U, 0 },
575 { "Talx4clong", TYPE_CINT, 9223372036854775807LL, 0 },
576 { "Talx4culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
577 { "Talx4cllong", TYPE_CINT, 9223372036854775807LL, 0 },
578 { "Talx4cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
579 { "Talx4cfloat", TYPE_CFLOAT, 0, 0 },
580 { "Talx4cdouble", TYPE_CFLOAT, 0, 0 },
581 { "Talx4cldouble", TYPE_CFLOAT, 0, 0 },
582 { "Talx8cint", TYPE_CINT, 2147483647, 0 },
583 { "Talx8cuint", TYPE_CUINT, 4294967295U, 0 },
584 { "Talx8clong", TYPE_CINT, 9223372036854775807LL, 0 },
585 { "Talx8culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
586 { "Talx8cllong", TYPE_CINT, 9223372036854775807LL, 0 },
587 { "Talx8cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
588 { "Talx8cfloat", TYPE_CFLOAT, 0, 0 },
589 { "Talx8cdouble", TYPE_CFLOAT, 0, 0 },
590 { "Talx8cldouble", TYPE_CFLOAT, 0, 0 },
591 { "Taly16clong", TYPE_CINT, 9223372036854775807LL, 0 },
592 { "Taly16culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
593 { "Talx16cllong", TYPE_CINT, 9223372036854775807LL, 0 },
594 { "Talx16cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
595 { "Talx16cdouble", TYPE_CFLOAT, 0, 0 },
596 { "Talx16cldouble", TYPE_CFLOAT, 0, 0 }
597 #define NCAATYPES2 (sizeof (complex_attrib_array_types) / sizeof (complex_attrib_array_types[0]))
600 struct types bitfld_types[NTYPES2];
601 int n_bitfld_types;
602 struct types aligned_bitfld_types[NATYPES2];
603 int n_aligned_bitfld_types;
605 const char *attributes[] = {
606 "atal",
607 "atpa",
608 "atal1",
609 "atal2",
610 "atal4",
611 "atal8",
612 "atal16",
613 #define NATTRIBS1 7
614 "atalpa",
615 "atpaal",
616 "atal1pa",
617 "atal2pa",
618 "atal4pa",
619 "atal8pa",
620 "atal16pa",
621 "atpaal1",
622 "atpaal2",
623 "atpaal4",
624 "atpaal8",
625 "atpaal16"
626 #define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0]))
629 enum ETYPE
631 ETYPE_TYPE,
632 ETYPE_ARRAY,
633 ETYPE_BITFLD,
634 ETYPE_STRUCT,
635 ETYPE_UNION,
636 ETYPE_STRUCT_ARRAY,
637 ETYPE_UNION_ARRAY
640 struct entry
642 #ifdef __GNUC__
643 enum ETYPE etype : 8;
644 #else
645 unsigned char etype;
646 #endif
647 unsigned short len;
648 unsigned char arr_len;
649 struct types *type;
650 const char *attrib;
651 /* Used to chain together entries in the hash table. */
652 struct entry *next;
655 /* A prime number giving the number of slots in the hash table. */
656 #define HASH_SIZE 32749
657 static struct entry *hash_table[HASH_SIZE];
659 static int idx, limidx, output_one;
660 static const char *destdir;
661 static const char *srcdir;
662 FILE *outfile;
664 void
665 switchfiles (int fields)
667 static int filecnt;
668 static char *destbuf, *destptr;
669 ++filecnt;
670 if (outfile)
671 fclose (outfile);
672 if (output_one)
674 outfile = stdout;
675 return;
677 if (destbuf == NULL)
679 size_t len = strlen (destdir);
680 destbuf = malloc (len + 20);
681 if (!destbuf)
682 abort ();
683 memcpy (destbuf, destdir, len);
684 if (!len || destbuf[len - 1] != '/')
685 destbuf[len++] = '/';
686 destptr = destbuf + len;
688 sprintf (destptr, "t%03d_main.c", filecnt);
689 outfile = fopen (destbuf, "w");
690 if (outfile == NULL)
692 fail:
693 fputs ("failed to create test files\n", stderr);
694 exit (1);
696 fprintf (outfile, "\
697 /* { dg-options \"-I%s\" } */\n\
698 /* { dg-options \"-I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
699 /* { dg-options \"-I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
700 #include \"struct-layout-1.h\"\n\
702 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
703 #include \"t%03d_test.h\"\n\
704 #undef TX\n\
706 int main (void)\n\
707 {\n\
708 #define TX(n, type, attrs, fields, ops) test##n ();\n\
709 #include \"t%03d_test.h\"\n\
710 #undef TX\n\
711 if (fails)\n\
712 {\n\
713 fflush (stdout);\n\
714 abort ();\n\
715 }\n\
716 exit (0);\n\
717 }\n", srcdir, srcdir, srcdir, filecnt, filecnt);
718 fclose (outfile);
719 sprintf (destptr, "t%03d_x.c", filecnt);
720 outfile = fopen (destbuf, "w");
721 if (outfile == NULL)
722 goto fail;
723 fprintf (outfile, "\
724 /* { dg-options \"-w -I%s\" } */\n\
725 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
726 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
727 #include \"struct-layout-1_x1.h\"\n\
728 #include \"t%03d_test.h\"\n\
729 #include \"struct-layout-1_x2.h\"\n\
730 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
731 fclose (outfile);
732 sprintf (destptr, "t%03d_y.c", filecnt);
733 outfile = fopen (destbuf, "w");
734 if (outfile == NULL)
735 goto fail;
736 fprintf (outfile, "\
737 /* { dg-options \"-w -I%s\" } */\n\
738 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
739 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
740 #include \"struct-layout-1_y1.h\"\n\
741 #include \"t%03d_test.h\"\n\
742 #include \"struct-layout-1_y2.h\"\n\
743 #include \"t%03d_test.h\"\n", srcdir, srcdir, srcdir, filecnt, filecnt);
744 fclose (outfile);
745 sprintf (destptr, "t%03d_test.h", filecnt);
746 outfile = fopen (destbuf, "w");
747 if (outfile == NULL)
748 goto fail;
749 if (fields <= 2)
750 limidx = idx + 300;
751 else if (fields <= 4)
752 limidx = idx + 200;
753 else if (fields <= 6)
754 limidx = idx + 100;
755 else
756 limidx = idx + 50;
759 unsigned long long int
760 getrandll (void)
762 unsigned long long int ret;
763 ret = generate_random () & 0xffffff;
764 ret |= (generate_random () & 0xffffffLL) << 24;
765 ret |= ((unsigned long long int) generate_random ()) << 48;
766 return ret;
770 subfield (struct entry *e, char *letter)
772 int i, type;
773 char buf[20];
774 const char *p;
775 switch (e[0].etype)
777 case ETYPE_STRUCT:
778 case ETYPE_UNION:
779 case ETYPE_STRUCT_ARRAY:
780 case ETYPE_UNION_ARRAY:
781 type = e[0].attrib ? 1 + (generate_random () & 3) : 0;
782 if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY)
783 p = "struct";
784 else
785 p = "union";
786 if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY)
788 if (e[0].arr_len == 255)
789 snprintf (buf, 20, "%c[]", *letter);
790 else
791 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
792 /* If this is an array type, do not put aligned attributes on
793 elements. Aligning elements to a value greater than their
794 size will result in a compiler error. */
795 if (type == 1
796 && ((strncmp (e[0].attrib, "atal", 4) == 0)
797 || strncmp (e[0].attrib, "atpaal", 6) == 0))
798 type = 2;
800 else
802 buf[0] = *letter;
803 buf[1] = '\0';
805 ++*letter;
806 switch (type)
808 case 0:
809 case 3:
810 case 4:
811 fprintf (outfile, "%s{", p);
812 break;
813 case 1:
814 fprintf (outfile, "%s %s{", e[0].attrib, p);
815 break;
816 case 2:
817 fprintf (outfile, "%s %s{", p, e[0].attrib);
818 break;
821 for (i = 1; i <= e[0].len; )
822 i += subfield (e + i, letter);
824 switch (type)
826 case 0:
827 case 1:
828 case 2:
829 fprintf (outfile, "}%s;", buf);
830 break;
831 case 3:
832 fprintf (outfile, "}%s %s;", e[0].attrib, buf);
833 break;
834 case 4:
835 fprintf (outfile, "}%s %s;", buf, e[0].attrib);
836 break;
838 return 1 + e[0].len;
839 case ETYPE_TYPE:
840 case ETYPE_ARRAY:
841 if (e[0].etype == ETYPE_ARRAY)
843 if (e[0].arr_len == 255)
844 snprintf (buf, 20, "%c[]", *letter);
845 else
846 snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
848 else
850 buf[0] = *letter;
851 buf[1] = '\0';
853 ++*letter;
854 if (e[0].attrib)
856 /* If this is an array type, do not put aligned attributes on
857 elements. Aligning elements to a value greater than their
858 size will result in a compiler error. */
859 if (e[0].etype == ETYPE_ARRAY
860 && ((strncmp (e[0].attrib, "atal", 4) == 0)
861 || strncmp (e[0].attrib, "atpaal", 6) == 0))
862 type = 2;
863 else
864 type = generate_random () % 3;
865 switch (type)
867 case 0:
868 fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name,
869 buf);
870 break;
871 case 1:
872 fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib,
873 buf);
874 break;
875 case 2:
876 fprintf (outfile, "%s %s %s;", e[0].type->name, buf,
877 e[0].attrib);
878 break;
881 else
882 fprintf (outfile, "%s %s;", e[0].type->name, buf);
883 return 1;
884 case ETYPE_BITFLD:
885 if (e[0].len == 0)
887 if (e[0].attrib)
888 switch (generate_random () % 3)
890 case 0:
891 fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name);
892 break;
893 case 1:
894 fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib);
895 break;
896 case 2:
897 fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib);
898 break;
900 else
901 fprintf (outfile, "%s:0;", e[0].type->name);
902 ++*letter;
903 return 1;
905 switch (e[0].type->bitfld)
907 case 'C':
908 case 'S':
909 case 'I':
910 case 'L':
911 case 'Q':
912 snprintf (buf, 20, "B%cN(%d)", e[0].type->bitfld, e[0].len);
913 break;
914 case 'B':
915 case ' ':
916 snprintf (buf, 20, "%d", e[0].len);
917 break;
918 default:
919 abort ();
921 if (e[0].attrib)
922 switch (generate_random () % 3)
924 case 0:
925 fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name,
926 *letter, buf);
927 break;
928 case 1:
929 fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib,
930 *letter, buf);
931 break;
932 case 2:
933 fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter,
934 buf, e[0].attrib);
935 break;
937 else
938 fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf);
939 ++*letter;
940 return 1;
941 default:
942 abort ();
946 char namebuf[1024];
948 void
949 output_FNB (char mode, struct entry *e)
951 unsigned long long int l1, l2, m;
952 int signs = 0;
953 const char *p, *q;
955 if (e->type->type == TYPE_OTHER)
957 if (mode == 'B')
958 abort ();
959 fprintf (outfile, "N(%d,%s)", idx, namebuf);
960 return;
962 fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf);
963 l1 = getrandll ();
964 l2 = getrandll ();
965 switch (e->type->type)
967 case TYPE_INT:
968 signs = generate_random () & 3;
969 m = e->type->maxval;
970 if (mode == 'B')
971 m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1;
972 l1 &= m;
973 l2 &= m;
974 fprintf (outfile, "%s%llu%s,%s%llu%s",
975 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
976 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
977 break;
978 case TYPE_UINT:
979 m = e->type->maxval;
980 if (mode == 'B')
981 m &= (1ULL << e->len) - 1;
982 l1 &= m;
983 l2 &= m;
984 fprintf (outfile, "%lluU%s,%lluU%s", l1, l1 > 4294967295U ? "LL" : "",
985 l2, l2 > 4294967295U ? "LL" : "");
986 break;
987 case TYPE_FLOAT:
988 l1 &= 0xffffff;
989 l2 &= 0xffffff;
990 signs = generate_random () & 3;
991 fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "",
992 ((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64);
993 break;
994 case TYPE_CINT:
995 signs = generate_random () & 3;
996 l1 &= e->type->maxval;
997 l2 &= e->type->maxval;
998 fprintf (outfile, "CINT(%s%llu%s,%s%llu%s),",
999 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1000 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1001 signs = generate_random () & 3;
1002 l1 = getrandll ();
1003 l2 = getrandll ();
1004 l1 &= e->type->maxval;
1005 l2 &= e->type->maxval;
1006 fprintf (outfile, "CINT(%s%llu%s,%s%llu%s)",
1007 (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1008 (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1009 break;
1010 case TYPE_CUINT:
1011 l1 &= e->type->maxval;
1012 l2 &= e->type->maxval;
1013 fprintf (outfile, "CINT(%lluU%s,%lluU%s),",
1014 l1, l1 > 4294967295U ? "LL" : "",
1015 l2, l2 > 4294967295U ? "LL" : "");
1016 l1 = getrandll ();
1017 l2 = getrandll ();
1018 l1 &= e->type->maxval;
1019 l2 &= e->type->maxval;
1020 fprintf (outfile, "CINT(%lluU%s,%lluU%s)",
1021 l1, l1 > 4294967295U ? "LL" : "",
1022 l2, l2 > 4294967295U ? "LL" : "");
1023 break;
1024 case TYPE_CFLOAT:
1025 l1 &= 0xffffff;
1026 l2 &= 0xffffff;
1027 signs = generate_random () & 3;
1028 fprintf (outfile, "CDBL(%s%f,%s%f),",
1029 (signs & 1) ? "-" : "", ((double) l1) / 64,
1030 (signs & 2) ? "-" : "", ((double) l2) / 64);
1031 l1 = getrandll ();
1032 l2 = getrandll ();
1033 l1 &= 0xffffff;
1034 l2 &= 0xffffff;
1035 signs = generate_random () & 3;
1036 fprintf (outfile, "CDBL(%s%f,%s%f)",
1037 (signs & 1) ? "-" : "", ((double) l1) / 64,
1038 (signs & 2) ? "-" : "", ((double) l2) / 64);
1039 break;
1040 case TYPE_UENUM:
1041 if (e->type->maxval == 0)
1042 fputs ("e0_0,e0_0", outfile);
1043 else if (e->type->maxval == 1)
1044 fprintf (outfile, "e1_%lld,e1_%lld", l1 & 1, l2 & 1);
1045 else
1047 p = strchr (e->type->name, '\0');
1048 while (--p >= e->type->name && *p >= '0' && *p <= '9');
1049 p++;
1050 l1 %= 7;
1051 l2 %= 7;
1052 if (l1 > 3)
1053 l1 += e->type->maxval - 6;
1054 if (l2 > 3)
1055 l2 += e->type->maxval - 6;
1056 fprintf (outfile, "e%s_%lld,e%s_%lld", p, l1, p, l2);
1058 break;
1059 case TYPE_SENUM:
1060 p = strchr (e->type->name, '\0');
1061 while (--p >= e->type->name && *p >= '0' && *p <= '9');
1062 p++;
1063 l1 %= 7;
1064 l2 %= 7;
1065 fprintf (outfile, "e%s_%s%lld,e%s_%s%lld",
1066 p, l1 < 3 ? "m" : "",
1067 l1 == 3 ? 0LL : e->type->maxval - (l1 & 3),
1068 p, l2 < 3 ? "m" : "",
1069 l2 == 3 ? 0LL : e->type->maxval - (l2 & 3));
1070 break;
1071 case TYPE_PTR:
1072 l1 %= 256;
1073 l2 %= 256;
1074 fprintf (outfile, "(%s)&intarray[%lld],(%s)&intarray[%lld]",
1075 e->type->name, l1, e->type->name, l2);
1076 break;
1077 case TYPE_FNPTR:
1078 l1 %= 10;
1079 l2 %= 10;
1080 fprintf (outfile, "fn%lld,fn%lld", l1, l2);
1081 break;
1082 default:
1083 abort ();
1085 fputs (")", outfile);
1089 subvalues (struct entry *e, char *p, char *letter)
1091 int i, j;
1092 char *q;
1093 if (p >= namebuf + sizeof (namebuf) - 32)
1094 abort ();
1095 p[0] = *letter;
1096 p[1] = '\0';
1097 q = p + 1;
1098 switch (e[0].etype)
1100 case ETYPE_STRUCT_ARRAY:
1101 case ETYPE_UNION_ARRAY:
1102 if (e[0].arr_len == 0 || e[0].arr_len == 255)
1104 *letter += 1 + e[0].len;
1105 return 1 + e[0].len;
1107 i = generate_random () % e[0].arr_len;
1108 snprintf (p, sizeof (namebuf) - (p - namebuf) - 1,
1109 "%c[%d]", *letter, i);
1110 q = strchr (p, '\0');
1111 /* FALLTHROUGH */
1112 case ETYPE_STRUCT:
1113 case ETYPE_UNION:
1114 *q++ = '.';
1115 ++*letter;
1116 for (i = 1; i <= e[0].len; )
1118 i += subvalues (e + i, q, letter);
1119 if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY)
1121 *letter += e[0].len - i + 1;
1122 break;
1125 return 1 + e[0].len;
1126 case ETYPE_TYPE:
1127 ++*letter;
1128 output_FNB ('F', e);
1129 return 1;
1130 case ETYPE_ARRAY:
1131 if (e[0].arr_len == 0 || e[0].arr_len == 255)
1133 ++*letter;
1134 return 1;
1136 i = generate_random () % e[0].arr_len;
1137 snprintf (p, sizeof (namebuf) - (p - namebuf),
1138 "%c[%d]", *letter, i);
1139 output_FNB ('F', e);
1140 if ((generate_random () & 7) == 0)
1142 j = generate_random () % e[0].arr_len;
1143 if (i != j)
1145 snprintf (p, sizeof (namebuf) - (p - namebuf),
1146 "%c[%d]", *letter, j);
1147 output_FNB ('F', e);
1150 ++*letter;
1151 return 1;
1152 case ETYPE_BITFLD:
1153 ++*letter;
1154 if (e[0].len != 0)
1155 output_FNB ('B', e);
1156 return 1;
1160 /* DERIVED FROM:
1161 --------------------------------------------------------------------
1162 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
1163 hash(), hash2(), hash3, and mix() are externally useful functions.
1164 Routines to test the hash are included if SELF_TEST is defined.
1165 You can use this free for any purpose. It has no warranty.
1166 --------------------------------------------------------------------
1170 --------------------------------------------------------------------
1171 mix -- mix 3 32-bit values reversibly.
1172 For every delta with one or two bit set, and the deltas of all three
1173 high bits or all three low bits, whether the original value of a,b,c
1174 is almost all zero or is uniformly distributed,
1175 * If mix() is run forward or backward, at least 32 bits in a,b,c
1176 have at least 1/4 probability of changing.
1177 * If mix() is run forward, every bit of c will change between 1/3 and
1178 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
1179 mix() was built out of 36 single-cycle latency instructions in a
1180 structure that could supported 2x parallelism, like so:
1181 a -= b;
1182 a -= c; x = (c>>13);
1183 b -= c; a ^= x;
1184 b -= a; x = (a<<8);
1185 c -= a; b ^= x;
1186 c -= b; x = (b>>13);
1188 Unfortunately, superscalar Pentiums and Sparcs can't take advantage
1189 of that parallelism. They've also turned some of those single-cycle
1190 latency instructions into multi-cycle latency instructions. Still,
1191 this is the fastest good hash I could find. There were about 2^^68
1192 to choose from. I only looked at a billion or so.
1193 --------------------------------------------------------------------
1195 /* same, but slower, works on systems that might have 8 byte hashval_t's */
1196 #define mix(a,b,c) \
1198 a -= b; a -= c; a ^= (c>>13); \
1199 b -= c; b -= a; b ^= (a<< 8); \
1200 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
1201 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
1202 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
1203 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
1204 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
1205 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
1206 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
1210 --------------------------------------------------------------------
1211 hash() -- hash a variable-length key into a 32-bit value
1212 k : the key (the unaligned variable-length array of bytes)
1213 len : the length of the key, counting by bytes
1214 level : can be any 4-byte value
1215 Returns a 32-bit value. Every bit of the key affects every bit of
1216 the return value. Every 1-bit and 2-bit delta achieves avalanche.
1217 About 36+6len instructions.
1219 The best hash table sizes are powers of 2. There is no need to do
1220 mod a prime (mod is sooo slow!). If you need less than 32 bits,
1221 use a bitmask. For example, if you need only 10 bits, do
1222 h = (h & hashmask(10));
1223 In which case, the hash table should have hashsize(10) elements.
1225 If you are hashing n strings (ub1 **)k, do it like this:
1226 for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
1228 By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
1229 code any way you wish, private, educational, or commercial. It's free.
1231 See http://burtleburtle.net/bob/hash/evahash.html
1232 Use for hash table lookup, or anything where one collision in 2^32 is
1233 acceptable. Do NOT use for cryptographic purposes.
1234 --------------------------------------------------------------------
1237 static hashval_t
1238 iterative_hash (const void *k_in /* the key */,
1239 register size_t length /* the length of the key */,
1240 register hashval_t initval /* the previous hash, or
1241 an arbitrary value */)
1243 register const unsigned char *k = (const unsigned char *)k_in;
1244 register hashval_t a,b,c,len;
1246 /* Set up the internal state */
1247 len = length;
1248 a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
1249 c = initval; /* the previous hash value */
1251 /*---------------------------------------- handle most of the key */
1252 while (len >= 12)
1254 a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24));
1255 b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24));
1256 c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24));
1257 mix(a,b,c);
1258 k += 12; len -= 12;
1261 /*------------------------------------- handle the last 11 bytes */
1262 c += length;
1263 switch(len) /* all the case statements fall through */
1265 case 11: c+=((hashval_t)k[10]<<24);
1266 case 10: c+=((hashval_t)k[9]<<16);
1267 case 9 : c+=((hashval_t)k[8]<<8);
1268 /* the first byte of c is reserved for the length */
1269 case 8 : b+=((hashval_t)k[7]<<24);
1270 case 7 : b+=((hashval_t)k[6]<<16);
1271 case 6 : b+=((hashval_t)k[5]<<8);
1272 case 5 : b+=k[4];
1273 case 4 : a+=((hashval_t)k[3]<<24);
1274 case 3 : a+=((hashval_t)k[2]<<16);
1275 case 2 : a+=((hashval_t)k[1]<<8);
1276 case 1 : a+=k[0];
1277 /* case 0: nothing left to add */
1279 mix(a,b,c);
1280 /*-------------------------------------------- report the result */
1281 return c;
1284 hashval_t
1285 e_hash (const void *a)
1287 const struct entry *e = a;
1288 hashval_t ret = 0;
1289 int i;
1291 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1292 abort ();
1293 for (i = 0; i <= e[0].len; ++i)
1295 int attriblen;
1296 ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret);
1297 attriblen = e[i].attrib ? strlen (e[i].attrib) : -1;
1298 ret = iterative_hash (&attriblen, sizeof (int), ret);
1299 if (e[i].attrib)
1300 ret = iterative_hash (e[i].attrib, attriblen, ret);
1302 return ret;
1306 e_eq (const void *a, const void *b)
1308 const struct entry *ea = a, *eb = b;
1309 int i;
1310 if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION)
1311 abort ();
1312 if (ea[0].len != eb[0].len)
1313 return 0;
1314 for (i = 0; i <= ea[0].len; ++i)
1316 if (ea[i].etype != eb[i].etype
1317 || ea[i].len != eb[i].len
1318 || ea[i].arr_len != eb[i].arr_len
1319 || ea[i].type != eb[i].type)
1320 return 0;
1321 if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL))
1322 return 0;
1323 if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0)
1324 return 0;
1326 return 1;
1329 static int
1330 e_exists (const struct entry *e)
1332 struct entry *h;
1333 hashval_t hval;
1335 hval = e_hash (e);
1336 for (h = hash_table[hval % HASH_SIZE]; h; h = h->next)
1337 if (e_eq (e, h))
1338 return 1;
1339 return 0;
1342 static void
1343 e_insert (struct entry *e)
1345 hashval_t hval;
1347 hval = e_hash (e);
1348 e->next = hash_table[hval % HASH_SIZE];
1349 hash_table[hval % HASH_SIZE] = e;
1352 void
1353 output (struct entry *e)
1355 int i;
1356 char c;
1357 struct entry *n;
1358 const char *skip_cint = "";
1360 if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1361 abort ();
1363 if (e_exists (e))
1364 return;
1366 n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry));
1367 memcpy (n, e, (e[0].len + 1) * sizeof (struct entry));
1368 e_insert (n);
1370 if (idx == limidx)
1371 switchfiles (e[0].len);
1373 for (i = 1; i <= e[0].len; ++i)
1374 if ((e[i].etype == ETYPE_TYPE || e[i].etype == ETYPE_ARRAY)
1375 && (e[i].type->type == TYPE_CINT || e[i].type->type == TYPE_CUINT))
1376 break;
1377 if (i <= e[0].len)
1378 skip_cint = "CI";
1379 if (e[0].attrib)
1380 fprintf (outfile, (generate_random () & 1)
1381 ? "TX%s(%d,%s %s,," : "TX%s(%d,%s,%s,", skip_cint,
1382 idx, e[0].etype == ETYPE_STRUCT ? "struct" : "union",
1383 e[0].attrib);
1384 else if (e[0].etype == ETYPE_STRUCT)
1385 fprintf (outfile, "T%s(%d,", skip_cint, idx);
1386 else
1387 fprintf (outfile, "U%s(%d,", skip_cint, idx);
1388 c = 'a';
1389 for (i = 1; i <= e[0].len; )
1390 i += subfield (e + i, &c);
1391 fputs (",", outfile);
1392 c = 'a';
1393 for (i = 1; i <= e[0].len; )
1395 i += subvalues (e + i, namebuf, &c);
1396 if (e[0].etype == ETYPE_UNION)
1397 break;
1399 fputs (")\n", outfile);
1400 if (output_one && idx == limidx)
1401 exit (0);
1402 ++idx;
1405 enum FEATURE
1407 FEATURE_VECTOR = 1,
1408 FEATURE_COMPLEX = 2,
1409 FEATURE_ALIGNEDPACKED = 4,
1410 FEATURE_ZEROARRAY = 8,
1411 FEATURE_ZEROBITFLD = 16,
1412 ALL_FEATURES = FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1413 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD
1416 void
1417 singles (enum FEATURE features)
1419 struct entry e[2];
1420 int i;
1421 memset (e, 0, sizeof (e));
1422 e[0].etype = ETYPE_STRUCT;
1423 output (e);
1424 e[0].etype = ETYPE_UNION;
1425 output (e);
1426 for (i = 0;
1427 i < ((features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1);
1428 ++i)
1430 e[0].attrib = attributes[i];
1431 e[0].etype = ETYPE_STRUCT;
1432 output (e);
1433 e[0].etype = ETYPE_UNION;
1434 output (e);
1436 e[0].len = 1;
1437 e[0].attrib = NULL;
1438 for (i = 0; i < NTYPES2; ++i)
1440 e[0].etype = ETYPE_STRUCT;
1441 e[1].etype = ETYPE_TYPE;
1442 e[1].type = &base_types[i];
1443 output (e);
1444 e[0].etype = ETYPE_UNION;
1445 output (e);
1447 if (features & FEATURE_COMPLEX)
1448 for (i = 0; i < NCTYPES2; ++i)
1450 e[0].etype = ETYPE_STRUCT;
1451 e[1].etype = ETYPE_TYPE;
1452 e[1].type = &complex_types[i];
1453 output (e);
1454 e[0].etype = ETYPE_UNION;
1455 output (e);
1457 if (features & FEATURE_VECTOR)
1458 for (i = 0; i < NVTYPES2; ++i)
1460 e[0].etype = ETYPE_STRUCT;
1461 e[1].etype = ETYPE_TYPE;
1462 e[1].type = &vector_types[i];
1463 output (e);
1464 e[0].etype = ETYPE_UNION;
1465 output (e);
1469 void
1470 choose_type (enum FEATURE features, struct entry *e, int r, int in_array)
1472 int i;
1474 i = NTYPES2 - NTYPES1;
1475 if (features & FEATURE_COMPLEX)
1476 i += NCTYPES2;
1477 if (features & FEATURE_VECTOR)
1478 i += NVTYPES2;
1479 if ((r & 3) == 0)
1481 if (in_array)
1483 i += NAATYPES2;
1484 if (features & FEATURE_COMPLEX)
1485 i += NCAATYPES2;
1487 else
1489 i += NATYPES2;
1490 if (features & FEATURE_COMPLEX)
1491 i += NCATYPES2;
1494 r >>= 2;
1495 r %= i;
1496 if (r < NTYPES2 - NTYPES1)
1497 e->type = &base_types[r + NTYPES1];
1498 r -= NTYPES2 - NTYPES1;
1499 if (e->type == NULL && (features & FEATURE_COMPLEX))
1501 if (r < NCTYPES2)
1502 e->type = &complex_types[r];
1503 r -= NCTYPES2;
1505 if (e->type == NULL && (features & FEATURE_VECTOR))
1507 if (r < NVTYPES2)
1508 e->type = &vector_types[r];
1509 r -= NVTYPES2;
1511 if (e->type == NULL && !in_array)
1513 if (r < NATYPES2)
1514 e->type = &attrib_types[r];
1515 r -= NATYPES2;
1517 if (e->type == NULL && !in_array && (features & FEATURE_COMPLEX))
1519 if (r < NCATYPES2)
1520 e->type = &complex_attrib_types[r];
1521 r -= NCATYPES2;
1523 if (e->type == NULL && in_array)
1525 if (r < NAATYPES2)
1526 e->type = &attrib_array_types[r];
1527 r -= NAATYPES2;
1529 if (e->type == NULL && in_array && (features & FEATURE_COMPLEX))
1531 if (r < NCAATYPES2)
1532 e->type = &complex_attrib_array_types[r];
1533 r -= NCAATYPES2;
1535 if (e->type == NULL)
1536 abort ();
1539 /* This is from gcc.c-torture/execute/builtin-bitops-1.c. */
1540 static int
1541 my_ffsll (unsigned long long x)
1543 int i;
1544 if (x == 0)
1545 return 0;
1546 /* We've tested LLONG_MAX for 64 bits so this should be safe. */
1547 for (i = 0; i < 64; i++)
1548 if (x & (1ULL << i))
1549 break;
1550 return i + 1;
1553 void
1554 generate_fields (enum FEATURE features, struct entry *e, struct entry *parent,
1555 int len)
1557 int r, i, j, ret = 1, n, incr, sametype;
1559 for (n = 0; n < len; n += incr)
1561 r = generate_random ();
1562 /* 50% ETYPE_TYPE base_types NTYPES1
1563 12.5% ETYPE_TYPE other
1564 12.5% ETYPE_ARRAY
1565 12.5% ETYPE_BITFLD
1566 12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1567 i = (r & 7);
1568 r >>= 3;
1569 incr = 1;
1570 switch (i)
1572 case 0:
1573 case 1:
1574 case 2:
1575 case 3:
1576 e[n].etype = ETYPE_TYPE;
1577 e[n].type = &base_types[r % NTYPES1];
1578 break;
1579 case 4:
1580 e[n].etype = ETYPE_TYPE;
1581 choose_type (features, &e[n], r, 0);
1582 break;
1583 case 5:
1584 e[n].etype = ETYPE_ARRAY;
1585 i = r & 1;
1586 r >>= 1;
1587 if (i)
1588 e[n].type = &base_types[r % NTYPES1];
1589 else
1590 choose_type (features, &e[n], r, 1);
1591 r = generate_random ();
1592 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1594 e[n].arr_len = 0;
1595 if (n == len - 1 && (r & 4)
1596 && (parent->etype == ETYPE_STRUCT
1597 || parent->etype == ETYPE_STRUCT_ARRAY))
1599 int k;
1600 for (k = 0; k < n; ++k)
1601 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1603 e[n].arr_len = 255;
1604 break;
1608 else if ((r & 3) != 3)
1609 e[n].arr_len = (r >> 2) & 7;
1610 else
1611 e[n].arr_len = (r >> 2) & 31;
1612 break;
1613 case 6:
1614 sametype = 1;
1615 switch (r & 7)
1617 case 0:
1618 case 1:
1619 case 2:
1620 break;
1621 case 3:
1622 case 4:
1623 case 5:
1624 incr = 1 + (r >> 3) % (len - n);
1625 break;
1626 case 6:
1627 case 7:
1628 sametype = 0;
1629 incr = 1 + (r >> 3) % (len - n);
1630 break;
1632 for (j = n; j < n + incr; ++j)
1634 int mi, ma;
1636 e[j].etype = ETYPE_BITFLD;
1637 if (j == n || !sametype)
1639 int k;
1640 r = generate_random ();
1641 k = r & 3;
1642 r >>= 2;
1643 if (!k)
1644 e[j].type
1645 = &aligned_bitfld_types[r % n_aligned_bitfld_types];
1646 else
1647 e[j].type
1648 = &bitfld_types[r % n_bitfld_types];
1650 else
1651 e[j].type = e[n].type;
1652 r = generate_random ();
1653 mi = 0;
1654 ma = 0;
1655 switch (e[j].type->bitfld)
1657 case 'C': ma = 8; break;
1658 case 'S': ma = 16; break;
1659 case 'I': ma = 32; break;
1660 case 'L':
1661 case 'Q': ma = 64; break;
1662 case 'B': ma = 1; break;
1663 case ' ':
1664 if (e[j].type->type == TYPE_UENUM)
1665 mi = my_ffsll (e[j].type->maxval + 1) - 1;
1666 else if (e[j].type->type == TYPE_SENUM)
1667 mi = my_ffsll (e[j].type->maxval + 1);
1668 else
1669 abort ();
1670 if (!mi)
1671 mi = 1;
1672 if (mi <= 32)
1673 ma = 32;
1674 else
1675 ma = 64;
1676 break;
1677 default:
1678 abort ();
1680 e[j].len = ma + 1;
1681 if (sametype && (r & 3) == 0 && ma > 1)
1683 int sum = 0, k;
1684 for (k = n; k < j; ++k)
1685 sum += e[k].len;
1686 sum %= ma;
1687 e[j].len = sum ? ma - sum : ma;
1689 r >>= 2;
1690 if (! (features & FEATURE_ZEROBITFLD) && mi == 0)
1691 mi = 1;
1692 if (e[j].len < mi || e[j].len > ma)
1693 e[j].len = mi + (r % (ma + 1 - mi));
1694 r >>= 6;
1695 if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0
1696 && mi == 0)
1697 e[j].len = 0;
1699 break;
1700 case 7:
1701 switch (r & 7)
1703 case 0:
1704 case 1:
1705 case 2:
1706 e[n].etype = ETYPE_STRUCT;
1707 break;
1708 case 3:
1709 case 4:
1710 e[n].etype = ETYPE_UNION;
1711 break;
1712 case 5:
1713 case 6:
1714 e[n].etype = ETYPE_STRUCT_ARRAY;
1715 break;
1716 case 7:
1717 e[n].etype = ETYPE_UNION_ARRAY;
1718 break;
1720 r >>= 3;
1721 e[n].len = r % (len - n);
1722 incr = 1 + e[n].len;
1723 generate_fields (features, &e[n + 1], &e[n], e[n].len);
1724 if (e[n].etype == ETYPE_STRUCT_ARRAY
1725 || e[n].etype == ETYPE_UNION_ARRAY)
1727 r = generate_random ();
1728 if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1730 e[n].arr_len = 0;
1731 if (n + incr == len && (r & 4)
1732 && (parent->etype == ETYPE_STRUCT
1733 || parent->etype == ETYPE_STRUCT_ARRAY))
1735 int k;
1736 for (k = 0; k < n; ++k)
1737 if (e[k].etype != ETYPE_BITFLD || e[k].len)
1739 e[n].arr_len = 255;
1740 break;
1744 else if ((r & 3) != 3)
1745 e[n].arr_len = (r >> 2) & 7;
1746 else
1747 e[n].arr_len = (r >> 2) & 31;
1749 break;
1751 r = generate_random ();
1752 if ((r & 7) == 0)
1754 r >>= 3;
1755 i = (features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1;
1756 e[n].attrib = attributes[r % i];
1757 if (! (features & FEATURE_ALIGNEDPACKED)
1758 && strcmp (e[n].attrib, "atpa") == 0
1759 && ((e[n].type >= &attrib_types[0]
1760 && e[n].type < &attrib_types[NATYPES2])
1761 || (e[n].type >= &complex_attrib_types[0]
1762 && e[n].type < &complex_attrib_types[NCATYPES2])
1763 || (e[n].type >= &attrib_array_types[0]
1764 && e[n].type < &attrib_array_types[NAATYPES2])
1765 || (e[n].type >= &complex_attrib_array_types[0]
1766 && e[n].type < &complex_attrib_array_types[NAATYPES2])
1767 || (e[n].type >= &aligned_bitfld_types[0]
1768 && e[n].type < &aligned_bitfld_types[n_aligned_bitfld_types])))
1769 e[n].attrib = NULL;
1774 void
1775 generate_random_tests (enum FEATURE features, int len)
1777 struct entry e[len + 1];
1778 int i, r;
1779 if (len > 'z' - 'a' + 1)
1780 abort ();
1781 memset (e, 0, sizeof (e));
1782 r = generate_random ();
1783 if ((r & 7) == 0)
1784 e[0].etype = ETYPE_UNION;
1785 else
1786 e[0].etype = ETYPE_STRUCT;
1787 r >>= 3;
1788 e[0].len = len;
1789 if ((r & 31) == 0)
1791 r >>= 5;
1792 if (features & FEATURE_ALIGNEDPACKED)
1793 r %= NATTRIBS2;
1794 else
1795 r %= NATTRIBS1;
1796 e[0].attrib = attributes[r];
1798 generate_fields (features, &e[1], &e[0], len);
1799 output (e);
1802 struct { const char *name; enum FEATURE f; }
1803 features[] = {
1804 { "normal", 0 },
1805 { "complex", FEATURE_COMPLEX },
1806 { "vector", FEATURE_VECTOR },
1807 { "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD },
1808 { "complex vector [0]",
1809 FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY },
1810 { "aligned packed complex vector [0] :0",
1811 FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1812 | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD },
1816 main (int argc, char **argv)
1818 int i, j, count, c, n = 3000;
1819 char *optarg;
1821 if (sizeof (int) != 4 || sizeof (long long) != 8)
1822 return 1;
1824 i = 1;
1825 while (i < argc)
1827 c = '\0';
1828 if (argv[i][0] == '-' && argv[i][2] == '\0')
1829 c = argv[i][1];
1830 optarg = argv[i + 1];
1831 if (!optarg)
1832 goto usage;
1833 switch (c)
1835 case 'n':
1836 n = atoi (optarg);
1837 break;
1838 case 'd':
1839 destdir = optarg;
1840 break;
1841 case 's':
1842 srcdir = optarg;
1843 break;
1844 case 'i':
1845 output_one = 1;
1846 limidx = atoi (optarg);
1847 break;
1848 default:
1849 fprintf (stderr, "unrecognized option %s\n", argv[i]);
1850 goto usage;
1852 i += 2;
1855 if (output_one)
1857 outfile = fopen ("/dev/null", "w");
1858 if (outfile == NULL)
1860 fputs ("could not open /dev/null", stderr);
1861 return 1;
1863 n = limidx + 1;
1866 if (destdir == NULL && !output_one)
1868 usage:
1869 fprintf (stderr, "Usage:\n\
1870 %s [-s srcdir -d destdir] [-n count] [-i idx]\n\
1871 Either -s srcdir -d destdir or -i idx must be used\n", argv[0]);
1872 return 1;
1875 if (srcdir == NULL && !output_one)
1876 goto usage;
1878 for (i = 0; i < NTYPES2; ++i)
1879 if (base_types[i].bitfld)
1880 bitfld_types[n_bitfld_types++] = base_types[i];
1881 for (i = 0; i < NATYPES2; ++i)
1882 if (attrib_types[i].bitfld)
1883 aligned_bitfld_types[n_aligned_bitfld_types++] = attrib_types[i];
1884 for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i)
1886 int startidx = idx;
1887 if (! output_one)
1888 limidx = idx;
1889 if (!i)
1890 count = 200;
1891 else
1892 count = 20;
1893 for (j = 1; j <= 9; ++j)
1894 while (idx < startidx + j * count)
1895 generate_random_tests (features[i].f, j);
1896 while (idx < startidx + count * 10)
1897 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
1899 for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i)
1901 int startidx;
1902 startidx = idx;
1903 if (! output_one)
1904 limidx = idx;
1905 singles (features[i].f);
1906 if (!i)
1908 count = 1000;
1909 while (idx < startidx + 1000)
1910 generate_random_tests (features[i].f, 1);
1912 else
1914 startidx = idx;
1915 count = 100;
1916 while (idx < startidx + 100)
1917 generate_random_tests (features[i].f, 1);
1919 startidx = idx;
1920 for (j = 2; j <= 9; ++j)
1921 while (idx < startidx + (j - 1) * count)
1922 generate_random_tests (features[i].f, j);
1923 while (idx < startidx + count * 9)
1924 generate_random_tests (features[i].f, 10 + (generate_random () % 16));
1926 if (! output_one)
1927 limidx = idx;
1928 while (idx < n)
1929 generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25));
1930 fclose (outfile);
1931 return 0;