1 /* Structure layout test generator.
2 Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
3 Contributed by Jakub Jelinek <jakub@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* Compile with gcc -o struct-layout-1_generate{,.c} generate_random{,_r}.c */
24 /* N.B. -- This program cannot use libiberty as that will not work
25 when testing an installed compiler. */
31 /* We use our own pseudo-random number generator, so that it gives the same
32 values on all hosts. */
33 #include "../../gcc.dg/compat/generate-random.h"
35 #if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL
36 # error Need 64-bit long long
39 #if defined __MSVCRT__
40 #define COMPAT_PRLL "I64"
42 #define COMPAT_PRLL "ll"
45 const char *dg_options
[] = {
46 "/* { dg-options \"%s-I%s\" } */\n",
47 "/* { dg-options \"%s-I%s -mno-mmx\" { target i?86-*-* x86_64-*-* } } */\n",
48 "/* { dg-options \"%s-I%s -fno-common\" { target hppa*-*-hpux* } } */\n",
49 "/* { dg-options \"%s-I%s -mno-base-addresses\" { target mmix-*-* } } */\n"
50 #define NDG_OPTIONS (sizeof (dg_options) / sizeof (dg_options[0]))
53 typedef unsigned int hashval_t
;
71 unsigned long long int maxval
;
75 struct types base_types
[] = {
76 /* As we don't know whether char will be signed or not, just limit ourselves
77 to unsigned values less than maximum signed char value. */
78 { "char", TYPE_UINT
, 127, 'C' },
79 { "signed char", TYPE_INT
, 127, 'C' },
80 { "unsigned char", TYPE_UINT
, 255, 'C' },
81 { "short int", TYPE_INT
, 32767, 'S' },
82 { "unsigned short int", TYPE_UINT
, 65535, 'S' },
83 { "int", TYPE_INT
, 2147483647, 'I' },
84 { "unsigned int", TYPE_UINT
, 4294967295U, 'I' },
85 { "long int", TYPE_INT
, 9223372036854775807LL, 'L' },
86 { "unsigned long int", TYPE_UINT
, 18446744073709551615ULL, 'L' },
87 { "long long int", TYPE_INT
, 9223372036854775807LL, 'Q' },
88 { "unsigned long long int", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
89 { "bool", TYPE_UINT
, 1, 'B' },
90 { "void *", TYPE_PTR
, 0, 0 },
91 { "char *", TYPE_PTR
, 0, 0 },
92 { "int *", TYPE_PTR
, 0, 0 },
93 { "float", TYPE_FLOAT
, 0, 0 },
94 { "double", TYPE_FLOAT
, 0, 0 },
95 { "long double", TYPE_FLOAT
, 0, 0 },
97 { "Tchar", TYPE_UINT
, 127, 'C' },
98 { "Tschar", TYPE_INT
, 127, 'C' },
99 { "Tuchar", TYPE_UINT
, 255, 'C' },
100 { "Tshort", TYPE_INT
, 32767, 'S' },
101 { "Tushort", TYPE_UINT
, 65535, 'S' },
102 { "Tint", TYPE_INT
, 2147483647, 'I' },
103 { "Tuint", TYPE_UINT
, 4294967295U, 'I' },
104 { "Tlong", TYPE_INT
, 9223372036854775807LL, 'L' },
105 { "Tulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
106 { "Tllong", TYPE_INT
, 9223372036854775807LL, 'Q' },
107 { "Tullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
108 { "Tbool", TYPE_UINT
, 1, 'B' },
109 { "size_t", TYPE_UINT
, 18446744073709551615ULL, 0 },
110 { "Tptr", TYPE_PTR
, 0, 0 },
111 { "Tcptr", TYPE_PTR
, 0, 0 },
112 { "Tiptr", TYPE_PTR
, 0, 0 },
113 { "Tfnptr", TYPE_FNPTR
, 0, 0 },
114 { "Tfloat", TYPE_FLOAT
, 0, 0 },
115 { "Tdouble", TYPE_FLOAT
, 0, 0 },
116 { "Tldouble", TYPE_FLOAT
, 0, 0 },
117 { "enum E0", TYPE_UENUM
, 0, ' ' },
118 { "enum E1", TYPE_UENUM
, 1, ' ' },
119 { "enum E2", TYPE_SENUM
, 3, ' ' },
120 { "enum E3", TYPE_SENUM
, 127, ' ' },
121 { "enum E4", TYPE_UENUM
, 255, ' ' },
122 { "enum E5", TYPE_SENUM
, 32767, ' ' },
123 { "enum E6", TYPE_UENUM
, 65535, ' ' },
124 { "enum E7", TYPE_SENUM
, 2147483647, ' ' },
125 { "enum E8", TYPE_UENUM
, 4294967295U, ' ' },
126 { "enum E9", TYPE_SENUM
, 1099511627775LL, ' ' },
127 { "TE0", TYPE_UENUM
, 0, ' ' },
128 { "TE1", TYPE_UENUM
, 1, ' ' },
129 { "TE2", TYPE_SENUM
, 3, ' ' },
130 { "TE3", TYPE_SENUM
, 127, ' ' },
131 { "TE4", TYPE_UENUM
, 255, ' ' },
132 { "TE5", TYPE_SENUM
, 32767, ' ' },
133 { "TE6", TYPE_UENUM
, 65535, ' ' },
134 { "TE7", TYPE_SENUM
, 2147483647, ' ' },
135 { "TE8", TYPE_UENUM
, 4294967295U, ' ' },
136 { "TE9", TYPE_SENUM
, 1099511627775LL, ' ' },
137 /* vector-defs.h typedefs */
138 { "qi", TYPE_INT
, 127, 0 },
139 { "hi", TYPE_INT
, 32767, 0 },
140 { "si", TYPE_INT
, 2147483647, 0 },
141 { "di", TYPE_INT
, 9223372036854775807LL, 0 },
142 { "sf", TYPE_FLOAT
, 0, 0 },
143 { "df", TYPE_FLOAT
, 0, 0 }
144 #define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
146 struct types vector_types
[] = {
147 /* vector-defs.h typedefs */
148 { "v8qi", TYPE_OTHER
, 0, 0 },
149 { "v16qi", TYPE_OTHER
, 0, 0 },
150 { "v2hi", TYPE_OTHER
, 0, 0 },
151 { "v4hi", TYPE_OTHER
, 0, 0 },
152 { "v8hi", TYPE_OTHER
, 0, 0 },
153 { "v2si", TYPE_OTHER
, 0, 0 },
154 { "v4si", TYPE_OTHER
, 0, 0 },
155 { "v1di", TYPE_OTHER
, 0, 0 },
156 { "v2di", TYPE_OTHER
, 0, 0 },
157 { "v2sf", TYPE_OTHER
, 0, 0 },
158 { "v4sf", TYPE_OTHER
, 0, 0 },
159 { "v16sf", TYPE_OTHER
, 0, 0 },
160 { "v2df", TYPE_OTHER
, 0, 0 },
161 { "u8qi", TYPE_OTHER
, 0, 0 },
162 { "u16qi", TYPE_OTHER
, 0, 0 },
163 { "u2hi", TYPE_OTHER
, 0, 0 },
164 { "u4hi", TYPE_OTHER
, 0, 0 },
165 { "u8hi", TYPE_OTHER
, 0, 0 },
166 { "u2si", TYPE_OTHER
, 0, 0 },
167 { "u4si", TYPE_OTHER
, 0, 0 },
168 { "u1di", TYPE_OTHER
, 0, 0 },
169 { "u2di", TYPE_OTHER
, 0, 0 },
170 { "u2sf", TYPE_OTHER
, 0, 0 },
171 { "u4sf", TYPE_OTHER
, 0, 0 },
172 { "u16sf", TYPE_OTHER
, 0, 0 },
173 { "u2df", TYPE_OTHER
, 0, 0 },
174 { "__m64", TYPE_OTHER
, 0, 0 },
175 { "__m128", TYPE_OTHER
, 0, 0 }
176 #define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
178 struct types attrib_types
[] = {
179 { "Talchar", TYPE_UINT
, 127, 'C' },
180 { "Talschar", TYPE_INT
, 127, 'C' },
181 { "Taluchar", TYPE_UINT
, 255, 'C' },
182 { "Talshort", TYPE_INT
, 32767, 'S' },
183 { "Talushort", TYPE_UINT
, 65535, 'S' },
184 { "Talint", TYPE_INT
, 2147483647, 'I' },
185 { "Taluint", TYPE_UINT
, 4294967295U, 'I' },
186 { "Tallong", TYPE_INT
, 9223372036854775807LL, 'L' },
187 { "Talulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
188 { "Talllong", TYPE_INT
, 9223372036854775807LL, 'Q' },
189 { "Talullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
190 { "Talbool", TYPE_UINT
, 1, 'B' },
191 { "Talptr", TYPE_PTR
, 0, 0 },
192 { "Talcptr", TYPE_PTR
, 0, 0 },
193 { "Taliptr", TYPE_PTR
, 0, 0 },
194 { "Talfloat", TYPE_FLOAT
, 0, 0 },
195 { "Taldouble", TYPE_FLOAT
, 0, 0 },
196 { "Talldouble", TYPE_FLOAT
, 0, 0 },
197 { "TalE0", TYPE_UENUM
, 0, ' ' },
198 { "TalE1", TYPE_UENUM
, 1, ' ' },
199 { "TalE2", TYPE_SENUM
, 3, ' ' },
200 { "TalE3", TYPE_SENUM
, 127, ' ' },
201 { "TalE4", TYPE_UENUM
, 255, ' ' },
202 { "TalE5", TYPE_SENUM
, 32767, ' ' },
203 { "TalE6", TYPE_UENUM
, 65535, ' ' },
204 { "TalE7", TYPE_SENUM
, 2147483647, ' ' },
205 { "TalE8", TYPE_UENUM
, 4294967295U, ' ' },
206 { "TalE9", TYPE_SENUM
, 1099511627775LL, ' ' },
207 { "Tal1char", TYPE_UINT
, 127, 'C' },
208 { "Tal1schar", TYPE_INT
, 127, 'C' },
209 { "Tal1uchar", TYPE_UINT
, 255, 'C' },
210 { "Tal1short", TYPE_INT
, 32767, 'S' },
211 { "Tal1ushort", TYPE_UINT
, 65535, 'S' },
212 { "Tal1int", TYPE_INT
, 2147483647, 'I' },
213 { "Tal1uint", TYPE_UINT
, 4294967295U, 'I' },
214 { "Tal1long", TYPE_INT
, 9223372036854775807LL, 'L' },
215 { "Tal1ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
216 { "Tal1llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
217 { "Tal1ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
218 { "Tal1bool", TYPE_UINT
, 1, 'B' },
219 { "Tal1ptr", TYPE_PTR
, 0, 0 },
220 { "Tal1cptr", TYPE_PTR
, 0, 0 },
221 { "Tal1iptr", TYPE_PTR
, 0, 0 },
222 { "Tal1float", TYPE_FLOAT
, 0, 0 },
223 { "Tal1double", TYPE_FLOAT
, 0, 0 },
224 { "Tal1ldouble", TYPE_FLOAT
, 0, 0 },
225 { "Tal1E0", TYPE_UENUM
, 0, ' ' },
226 { "Tal1E1", TYPE_UENUM
, 1, ' ' },
227 { "Tal1E2", TYPE_SENUM
, 3, ' ' },
228 { "Tal1E3", TYPE_SENUM
, 127, ' ' },
229 { "Tal1E4", TYPE_UENUM
, 255, ' ' },
230 { "Tal1E5", TYPE_SENUM
, 32767, ' ' },
231 { "Tal1E6", TYPE_UENUM
, 65535, ' ' },
232 { "Tal1E7", TYPE_SENUM
, 2147483647, ' ' },
233 { "Tal1E8", TYPE_UENUM
, 4294967295U, ' ' },
234 { "Tal1E9", TYPE_SENUM
, 1099511627775LL, ' ' },
235 { "Tal2char", TYPE_UINT
, 127, 'C' },
236 { "Tal2schar", TYPE_INT
, 127, 'C' },
237 { "Tal2uchar", TYPE_UINT
, 255, 'C' },
238 { "Tal2short", TYPE_INT
, 32767, 'S' },
239 { "Tal2ushort", TYPE_UINT
, 65535, 'S' },
240 { "Tal2int", TYPE_INT
, 2147483647, 'I' },
241 { "Tal2uint", TYPE_UINT
, 4294967295U, 'I' },
242 { "Tal2long", TYPE_INT
, 9223372036854775807LL, 'L' },
243 { "Tal2ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
244 { "Tal2llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
245 { "Tal2ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
246 { "Tal2bool", TYPE_UINT
, 1, 'B' },
247 { "Tal2ptr", TYPE_PTR
, 0, 0 },
248 { "Tal2cptr", TYPE_PTR
, 0, 0 },
249 { "Tal2iptr", TYPE_PTR
, 0, 0 },
250 { "Tal2float", TYPE_FLOAT
, 0, 0 },
251 { "Tal2double", TYPE_FLOAT
, 0, 0 },
252 { "Tal2ldouble", TYPE_FLOAT
, 0, 0 },
253 { "Tal2E0", TYPE_UENUM
, 0, ' ' },
254 { "Tal2E1", TYPE_UENUM
, 1, ' ' },
255 { "Tal2E2", TYPE_SENUM
, 3, ' ' },
256 { "Tal2E3", TYPE_SENUM
, 127, ' ' },
257 { "Tal2E4", TYPE_UENUM
, 255, ' ' },
258 { "Tal2E5", TYPE_SENUM
, 32767, ' ' },
259 { "Tal2E6", TYPE_UENUM
, 65535, ' ' },
260 { "Tal2E7", TYPE_SENUM
, 2147483647, ' ' },
261 { "Tal2E8", TYPE_UENUM
, 4294967295U, ' ' },
262 { "Tal2E9", TYPE_SENUM
, 1099511627775LL, ' ' },
263 { "Tal4char", TYPE_UINT
, 127, 'C' },
264 { "Tal4schar", TYPE_INT
, 127, 'C' },
265 { "Tal4uchar", TYPE_UINT
, 255, 'C' },
266 { "Tal4short", TYPE_INT
, 32767, 'S' },
267 { "Tal4ushort", TYPE_UINT
, 65535, 'S' },
268 { "Tal4int", TYPE_INT
, 2147483647, 'I' },
269 { "Tal4uint", TYPE_UINT
, 4294967295U, 'I' },
270 { "Tal4long", TYPE_INT
, 9223372036854775807LL, 'L' },
271 { "Tal4ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
272 { "Tal4llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
273 { "Tal4ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
274 { "Tal4bool", TYPE_UINT
, 1, 'B' },
275 { "Tal4ptr", TYPE_PTR
, 0, 0 },
276 { "Tal4cptr", TYPE_PTR
, 0, 0 },
277 { "Tal4iptr", TYPE_PTR
, 0, 0 },
278 { "Tal4float", TYPE_FLOAT
, 0, 0 },
279 { "Tal4double", TYPE_FLOAT
, 0, 0 },
280 { "Tal4ldouble", TYPE_FLOAT
, 0, 0 },
281 { "Tal4E0", TYPE_UENUM
, 0, ' ' },
282 { "Tal4E1", TYPE_UENUM
, 1, ' ' },
283 { "Tal4E2", TYPE_SENUM
, 3, ' ' },
284 { "Tal4E3", TYPE_SENUM
, 127, ' ' },
285 { "Tal4E4", TYPE_UENUM
, 255, ' ' },
286 { "Tal4E5", TYPE_SENUM
, 32767, ' ' },
287 { "Tal4E6", TYPE_UENUM
, 65535, ' ' },
288 { "Tal4E7", TYPE_SENUM
, 2147483647, ' ' },
289 { "Tal4E8", TYPE_UENUM
, 4294967295U, ' ' },
290 { "Tal4E9", TYPE_SENUM
, 1099511627775LL, ' ' },
291 { "Tal8char", TYPE_UINT
, 127, 'C' },
292 { "Tal8schar", TYPE_INT
, 127, 'C' },
293 { "Tal8uchar", TYPE_UINT
, 255, 'C' },
294 { "Tal8short", TYPE_INT
, 32767, 'S' },
295 { "Tal8ushort", TYPE_UINT
, 65535, 'S' },
296 { "Tal8int", TYPE_INT
, 2147483647, 'I' },
297 { "Tal8uint", TYPE_UINT
, 4294967295U, 'I' },
298 { "Tal8long", TYPE_INT
, 9223372036854775807LL, 'L' },
299 { "Tal8ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
300 { "Tal8llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
301 { "Tal8ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
302 { "Tal8bool", TYPE_UINT
, 1, 'B' },
303 { "Tal8ptr", TYPE_PTR
, 0, 0 },
304 { "Tal8cptr", TYPE_PTR
, 0, 0 },
305 { "Tal8iptr", TYPE_PTR
, 0, 0 },
306 { "Tal8float", TYPE_FLOAT
, 0, 0 },
307 { "Tal8double", TYPE_FLOAT
, 0, 0 },
308 { "Tal8ldouble", TYPE_FLOAT
, 0, 0 },
309 { "Tal8E0", TYPE_UENUM
, 0, ' ' },
310 { "Tal8E1", TYPE_UENUM
, 1, ' ' },
311 { "Tal8E2", TYPE_SENUM
, 3, ' ' },
312 { "Tal8E3", TYPE_SENUM
, 127, ' ' },
313 { "Tal8E4", TYPE_UENUM
, 255, ' ' },
314 { "Tal8E5", TYPE_SENUM
, 32767, ' ' },
315 { "Tal8E6", TYPE_UENUM
, 65535, ' ' },
316 { "Tal8E7", TYPE_SENUM
, 2147483647, ' ' },
317 { "Tal8E8", TYPE_UENUM
, 4294967295U, ' ' },
318 { "Tal8E9", TYPE_SENUM
, 1099511627775LL, ' ' },
319 { "Tal16char", TYPE_UINT
, 127, 'C' },
320 { "Tal16schar", TYPE_INT
, 127, 'C' },
321 { "Tal16uchar", TYPE_UINT
, 255, 'C' },
322 { "Tal16short", TYPE_INT
, 32767, 'S' },
323 { "Tal16ushort", TYPE_UINT
, 65535, 'S' },
324 { "Tal16int", TYPE_INT
, 2147483647, 'I' },
325 { "Tal16uint", TYPE_UINT
, 4294967295U, 'I' },
326 { "Tal16long", TYPE_INT
, 9223372036854775807LL, 'L' },
327 { "Tal16ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
328 { "Tal16llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
329 { "Tal16ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
330 { "Tal16bool", TYPE_UINT
, 1, 'B' },
331 { "Tal16ptr", TYPE_PTR
, 0, 0 },
332 { "Tal16cptr", TYPE_PTR
, 0, 0 },
333 { "Tal16iptr", TYPE_PTR
, 0, 0 },
334 { "Tal16float", TYPE_FLOAT
, 0, 0 },
335 { "Tal16double", TYPE_FLOAT
, 0, 0 },
336 { "Tal16ldouble", TYPE_FLOAT
, 0, 0 },
337 { "Tal16E0", TYPE_UENUM
, 0, ' ' },
338 { "Tal16E1", TYPE_UENUM
, 1, ' ' },
339 { "Tal16E2", TYPE_SENUM
, 3, ' ' },
340 { "Tal16E3", TYPE_SENUM
, 127, ' ' },
341 { "Tal16E4", TYPE_UENUM
, 255, ' ' },
342 { "Tal16E5", TYPE_SENUM
, 32767, ' ' },
343 { "Tal16E6", TYPE_UENUM
, 65535, ' ' },
344 { "Tal16E7", TYPE_SENUM
, 2147483647, ' ' },
345 { "Tal16E8", TYPE_UENUM
, 4294967295U, ' ' },
346 { "Tal16E9", TYPE_SENUM
, 1099511627775LL, ' ' }
347 #define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0]))
350 struct types bitfld_types
[NTYPES2
];
352 struct types aligned_bitfld_types
[NATYPES2
];
353 int n_aligned_bitfld_types
;
355 const char *attributes
[] = {
376 #define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0]))
393 enum ETYPE etype
: 8;
398 unsigned char arr_len
;
401 /* Used to chain together entries in the hash table. */
404 struct types attrib_array_types
[] = {
405 { "Talx1char", TYPE_UINT
, 127, 'C' },
406 { "Talx1schar", TYPE_INT
, 127, 'C' },
407 { "Talx1uchar", TYPE_UINT
, 255, 'C' },
408 { "Talx1short", TYPE_INT
, 32767, 'S' },
409 { "Talx1ushort", TYPE_UINT
, 65535, 'S' },
410 { "Talx1int", TYPE_INT
, 2147483647, 'I' },
411 { "Talx1uint", TYPE_UINT
, 4294967295U, 'I' },
412 { "Talx1long", TYPE_INT
, 9223372036854775807LL, 'L' },
413 { "Talx1ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
414 { "Talx1llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
415 { "Talx1ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
416 { "Talx1bool", TYPE_UINT
, 1, 'B' },
417 { "Talx1ptr", TYPE_PTR
, 0, 0 },
418 { "Talx1cptr", TYPE_PTR
, 0, 0 },
419 { "Talx1iptr", TYPE_PTR
, 0, 0 },
420 { "Talx1float", TYPE_FLOAT
, 0, 0 },
421 { "Talx1double", TYPE_FLOAT
, 0, 0 },
422 { "Talx1ldouble", TYPE_FLOAT
, 0, 0 },
423 { "Talx1E0", TYPE_UENUM
, 0, ' ' },
424 { "Talx1E1", TYPE_UENUM
, 1, ' ' },
425 { "Talx1E2", TYPE_SENUM
, 3, ' ' },
426 { "Talx1E3", TYPE_SENUM
, 127, ' ' },
427 { "Talx1E4", TYPE_UENUM
, 255, ' ' },
428 { "Talx1E5", TYPE_SENUM
, 32767, ' ' },
429 { "Talx1E6", TYPE_UENUM
, 65535, ' ' },
430 { "Talx1E7", TYPE_SENUM
, 2147483647, ' ' },
431 { "Talx1E8", TYPE_UENUM
, 4294967295U, ' ' },
432 { "Talx1E9", TYPE_SENUM
, 1099511627775LL, ' ' },
433 { "Talx2short", TYPE_INT
, 32767, 'S' },
434 { "Talx2ushort", TYPE_UINT
, 65535, 'S' },
435 { "Talx2int", TYPE_INT
, 2147483647, 'I' },
436 { "Talx2uint", TYPE_UINT
, 4294967295U, 'I' },
437 { "Talx2long", TYPE_INT
, 9223372036854775807LL, 'L' },
438 { "Talx2ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
439 { "Talx2llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
440 { "Talx2ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
441 { "Talx2ptr", TYPE_PTR
, 0, 0 },
442 { "Talx2cptr", TYPE_PTR
, 0, 0 },
443 { "Talx2iptr", TYPE_PTR
, 0, 0 },
444 { "Talx2float", TYPE_FLOAT
, 0, 0 },
445 { "Talx2double", TYPE_FLOAT
, 0, 0 },
446 { "Talx2ldouble", TYPE_FLOAT
, 0, 0 },
447 { "Talx2E0", TYPE_UENUM
, 0, ' ' },
448 { "Talx2E1", TYPE_UENUM
, 1, ' ' },
449 { "Talx2E2", TYPE_SENUM
, 3, ' ' },
450 { "Talx2E3", TYPE_SENUM
, 127, ' ' },
451 { "Talx2E4", TYPE_UENUM
, 255, ' ' },
452 { "Talx2E5", TYPE_SENUM
, 32767, ' ' },
453 { "Talx2E6", TYPE_UENUM
, 65535, ' ' },
454 { "Talx2E7", TYPE_SENUM
, 2147483647, ' ' },
455 { "Talx2E8", TYPE_UENUM
, 4294967295U, ' ' },
456 { "Talx2E9", TYPE_SENUM
, 1099511627775LL, ' ' },
457 { "Talx4int", TYPE_INT
, 2147483647, 'I' },
458 { "Talx4uint", TYPE_UINT
, 4294967295U, 'I' },
459 { "Talx4long", TYPE_INT
, 9223372036854775807LL, 'L' },
460 { "Talx4ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
461 { "Talx4llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
462 { "Talx4ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
463 { "Talx4ptr", TYPE_PTR
, 0, 0 },
464 { "Talx4cptr", TYPE_PTR
, 0, 0 },
465 { "Talx4iptr", TYPE_PTR
, 0, 0 },
466 { "Talx4float", TYPE_FLOAT
, 0, 0 },
467 { "Talx4double", TYPE_FLOAT
, 0, 0 },
468 { "Talx4ldouble", TYPE_FLOAT
, 0, 0 },
469 { "Talx4E0", TYPE_UENUM
, 0, ' ' },
470 { "Talx4E1", TYPE_UENUM
, 1, ' ' },
471 { "Talx4E2", TYPE_SENUM
, 3, ' ' },
472 { "Talx4E3", TYPE_SENUM
, 127, ' ' },
473 { "Talx4E4", TYPE_UENUM
, 255, ' ' },
474 { "Talx4E5", TYPE_SENUM
, 32767, ' ' },
475 { "Talx4E6", TYPE_UENUM
, 65535, ' ' },
476 { "Talx4E7", TYPE_SENUM
, 2147483647, ' ' },
477 { "Talx4E8", TYPE_UENUM
, 4294967295U, ' ' },
478 { "Talx4E9", TYPE_SENUM
, 1099511627775LL, ' ' },
479 { "Taly8long", TYPE_INT
, 9223372036854775807LL, 'L' },
480 { "Taly8ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
481 { "Talx8llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
482 { "Talx8ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
483 { "Taly8ptr", TYPE_PTR
, 0, 0 },
484 { "Taly8cptr", TYPE_PTR
, 0, 0 },
485 { "Taly8iptr", TYPE_PTR
, 0, 0 },
486 { "Talx8double", TYPE_FLOAT
, 0, 0 },
487 { "Talx8ldouble", TYPE_FLOAT
, 0, 0 }
488 #define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0]))
491 /* A prime number giving the number of slots in the hash table. */
492 #define HASH_SIZE 32749
493 static struct entry
*hash_table
[HASH_SIZE
];
495 static int idx
, limidx
, output_one
, short_enums
;
496 static const char *destdir
;
497 static const char *srcdir
;
501 switchfiles (int fields
)
504 static char *destbuf
, *destptr
;
517 size_t len
= strlen (destdir
);
518 destbuf
= malloc (len
+ 20);
521 memcpy (destbuf
, destdir
, len
);
522 if (!len
|| destbuf
[len
- 1] != '/')
523 destbuf
[len
++] = '/';
524 destptr
= destbuf
+ len
;
526 sprintf (destptr
, "t%03d_main.C", filecnt
);
527 outfile
= fopen (destbuf
, "w");
531 fputs ("failed to create test files\n", stderr
);
534 for (i
= 0; i
< NDG_OPTIONS
; i
++)
535 fprintf (outfile
, dg_options
[i
], "", srcdir
);
536 fprintf (outfile
, "\n\
537 #include \"struct-layout-1.h\"\n\
539 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
540 #include \"t%03d_test.h\"\n\
545 #define TX(n, type, attrs, fields, ops) test##n ();\n\
546 #include \"t%03d_test.h\"\n\
554 }\n", filecnt
, filecnt
);
556 sprintf (destptr
, "t%03d_x.C", filecnt
);
557 outfile
= fopen (destbuf
, "w");
560 for (i
= 0; i
< NDG_OPTIONS
; i
++)
561 fprintf (outfile
, dg_options
[i
], "-w ", srcdir
);
562 fprintf (outfile
, "\n\
563 #include \"struct-layout-1_x1.h\"\n\
564 #include \"t%03d_test.h\"\n\
565 #include \"struct-layout-1_x2.h\"\n\
566 #include \"t%03d_test.h\"\n", filecnt
, filecnt
);
568 sprintf (destptr
, "t%03d_y.C", filecnt
);
569 outfile
= fopen (destbuf
, "w");
572 for (i
= 0; i
< NDG_OPTIONS
; i
++)
573 fprintf (outfile
, dg_options
[i
], "-w ", srcdir
);
574 fprintf (outfile
, "\n\
575 #include \"struct-layout-1_y1.h\"\n\
576 #include \"t%03d_test.h\"\n\
577 #include \"struct-layout-1_y2.h\"\n\
578 #include \"t%03d_test.h\"\n", filecnt
, filecnt
);
580 sprintf (destptr
, "t%03d_test.h", filecnt
);
581 outfile
= fopen (destbuf
, "w");
586 else if (fields
<= 4)
588 else if (fields
<= 6)
594 unsigned long long int
597 unsigned long long int ret
;
598 ret
= generate_random () & 0xffffff;
599 ret
|= (generate_random () & 0xffffffLL
) << 24;
600 ret
|= ((unsigned long long int) generate_random ()) << 48;
605 subfield (struct entry
*e
, char *letter
)
614 case ETYPE_STRUCT_ARRAY
:
615 case ETYPE_UNION_ARRAY
:
616 type
= e
[0].attrib
? 1 + (generate_random () & 3) : 0;
617 if (e
[0].etype
== ETYPE_STRUCT
|| e
[0].etype
== ETYPE_STRUCT_ARRAY
)
621 if (e
[0].etype
== ETYPE_STRUCT_ARRAY
|| e
[0].etype
== ETYPE_UNION_ARRAY
)
623 if (e
[0].arr_len
== 255)
624 snprintf (buf
, 20, "%c[]", *letter
);
626 snprintf (buf
, 20, "%c[%d]", *letter
, e
[0].arr_len
);
627 /* If this is an array type, do not put aligned attributes on
628 elements. Aligning elements to a value greater than their
629 size will result in a compiler error. */
631 && ((strncmp (e
[0].attrib
, "atal", 4) == 0)
632 || strncmp (e
[0].attrib
, "atpaal", 6) == 0))
646 fprintf (outfile
, "%s{", p
);
649 fprintf (outfile
, "%s %s{", e
[0].attrib
, p
);
652 fprintf (outfile
, "%s %s{", p
, e
[0].attrib
);
656 for (i
= 1; i
<= e
[0].len
; )
657 i
+= subfield (e
+ i
, letter
);
664 fprintf (outfile
, "}%s;", buf
);
667 fprintf (outfile
, "}%s %s;", e
[0].attrib
, buf
);
670 fprintf (outfile
, "}%s %s;", buf
, e
[0].attrib
);
676 if (e
[0].etype
== ETYPE_ARRAY
)
678 if (e
[0].arr_len
== 255)
679 snprintf (buf
, 20, "%c[]", *letter
);
681 snprintf (buf
, 20, "%c[%d]", *letter
, e
[0].arr_len
);
691 /* If this is an array type, do not put aligned attributes on
692 elements. Aligning elements to a value greater than their
693 size will result in a compiler error. */
694 if (e
[0].etype
== ETYPE_ARRAY
695 && ((strncmp (e
[0].attrib
, "atal", 4) == 0)
696 || strncmp (e
[0].attrib
, "atpaal", 6) == 0))
699 type
= generate_random () % 3;
703 fprintf (outfile
, "%s %s %s;", e
[0].attrib
, e
[0].type
->name
,
707 fprintf (outfile
, "%s %s %s;", e
[0].type
->name
, e
[0].attrib
,
711 fprintf (outfile
, "%s %s %s;", e
[0].type
->name
, buf
,
717 fprintf (outfile
, "%s %s;", e
[0].type
->name
, buf
);
723 switch (generate_random () % 3)
726 fprintf (outfile
, "%s %s:0;", e
[0].attrib
, e
[0].type
->name
);
729 fprintf (outfile
, "%s %s:0;", e
[0].type
->name
, e
[0].attrib
);
732 fprintf (outfile
, "%s:0 %s;", e
[0].type
->name
, e
[0].attrib
);
736 fprintf (outfile
, "%s:0;", e
[0].type
->name
);
740 snprintf (buf
, 20, "%d", e
[0].len
);
742 switch (generate_random () % 3)
745 fprintf (outfile
, "%s %s %c:%s;", e
[0].attrib
, e
[0].type
->name
,
749 fprintf (outfile
, "%s %s %c:%s;", e
[0].type
->name
, e
[0].attrib
,
753 fprintf (outfile
, "%s %c:%s %s;", e
[0].type
->name
, *letter
,
758 fprintf (outfile
, "%s %c:%s;", e
[0].type
->name
, *letter
, buf
);
769 output_FNB (char mode
, struct entry
*e
)
771 unsigned long long int l1
, l2
, m
;
775 if (e
->type
->type
== TYPE_OTHER
)
779 fprintf (outfile
, "N(%d,%s)", idx
, namebuf
);
782 fprintf (outfile
, "%c(%d,%s,", mode
, idx
, namebuf
);
785 switch (e
->type
->type
)
788 signs
= generate_random () & 3;
791 m
&= e
->len
> 1 ? (1ULL << (e
->len
- 1)) - 1 : 1;
794 fprintf (outfile
, "%s%" COMPAT_PRLL
"u%s,%s%" COMPAT_PRLL
"u%s",
795 (signs
& 1) ? "-" : "", l1
, l1
> 2147483647 ? "LL" : "",
796 (signs
& 2) ? "-" : "", l2
, l2
> 2147483647 ? "LL" : "");
801 m
&= (1ULL << e
->len
) - 1;
804 fprintf (outfile
,"%" COMPAT_PRLL
"uU%s,%" COMPAT_PRLL
"uU%s",
805 l1
, l1
> 4294967295U ? "LL" : "",
806 l2
, l2
> 4294967295U ? "LL" : "");
811 signs
= generate_random () & 3;
812 fprintf (outfile
, "%s%f,%s%f", (signs
& 1) ? "-" : "",
813 ((double) l1
) / 64, (signs
& 2) ? "-" : "", ((double) l2
) / 64);
816 if (e
->type
->maxval
== 0)
817 fputs ("e0_0,e0_0", outfile
);
818 else if (e
->type
->maxval
== 1)
819 fprintf (outfile
, "e1_%" COMPAT_PRLL
"d,e1_%" COMPAT_PRLL
"d",
823 p
= strchr (e
->type
->name
, '\0');
824 while (--p
>= e
->type
->name
&& *p
>= '0' && *p
<= '9');
829 l1
+= e
->type
->maxval
- 6;
831 l2
+= e
->type
->maxval
- 6;
832 fprintf (outfile
, "e%s_%" COMPAT_PRLL
"d,e%s_%" COMPAT_PRLL
"d",
837 p
= strchr (e
->type
->name
, '\0');
838 while (--p
>= e
->type
->name
&& *p
>= '0' && *p
<= '9');
842 fprintf (outfile
, "e%s_%s%" COMPAT_PRLL
"d,e%s_%s%" COMPAT_PRLL
"d",
843 p
, l1
< 3 ? "m" : "",
844 l1
== 3 ? 0LL : e
->type
->maxval
- (l1
& 3),
845 p
, l2
< 3 ? "m" : "",
846 l2
== 3 ? 0LL : e
->type
->maxval
- (l2
& 3));
852 "(%s)&intarray[%" COMPAT_PRLL
"d], (%s)&intarray[%" COMPAT_PRLL
"d]",
853 e
->type
->name
, l1
, e
->type
->name
, l2
);
859 "fn%" COMPAT_PRLL
"d,fn%" COMPAT_PRLL
"d", l1
, l2
);
864 fputs (")", outfile
);
868 subvalues (struct entry
*e
, char *p
, char *letter
)
872 if (p
>= namebuf
+ sizeof (namebuf
) - 32)
879 case ETYPE_STRUCT_ARRAY
:
880 case ETYPE_UNION_ARRAY
:
881 if (e
[0].arr_len
== 0 || e
[0].arr_len
== 255)
883 *letter
+= 1 + e
[0].len
;
886 i
= generate_random () % e
[0].arr_len
;
887 snprintf (p
, sizeof (namebuf
) - (p
- namebuf
) - 1,
888 "%c[%d]", *letter
, i
);
889 q
= strchr (p
, '\0');
895 for (i
= 1; i
<= e
[0].len
; )
897 i
+= subvalues (e
+ i
, q
, letter
);
898 if (e
[0].etype
== ETYPE_UNION
|| e
[0].etype
== ETYPE_UNION_ARRAY
)
900 *letter
+= e
[0].len
- i
+ 1;
910 if (e
[0].arr_len
== 0 || e
[0].arr_len
== 255)
915 i
= generate_random () % e
[0].arr_len
;
916 snprintf (p
, sizeof (namebuf
) - (p
- namebuf
),
917 "%c[%d]", *letter
, i
);
919 if ((generate_random () & 7) == 0)
921 j
= generate_random () % e
[0].arr_len
;
924 snprintf (p
, sizeof (namebuf
) - (p
- namebuf
),
925 "%c[%d]", *letter
, j
);
940 --------------------------------------------------------------------
941 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
942 hash(), hash2(), hash3, and mix() are externally useful functions.
943 Routines to test the hash are included if SELF_TEST is defined.
944 You can use this free for any purpose. It has no warranty.
945 --------------------------------------------------------------------
949 --------------------------------------------------------------------
950 mix -- mix 3 32-bit values reversibly.
951 For every delta with one or two bit set, and the deltas of all three
952 high bits or all three low bits, whether the original value of a,b,c
953 is almost all zero or is uniformly distributed,
954 * If mix() is run forward or backward, at least 32 bits in a,b,c
955 have at least 1/4 probability of changing.
956 * If mix() is run forward, every bit of c will change between 1/3 and
957 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
958 mix() was built out of 36 single-cycle latency instructions in a
959 structure that could supported 2x parallelism, like so:
967 Unfortunately, superscalar Pentiums and Sparcs can't take advantage
968 of that parallelism. They've also turned some of those single-cycle
969 latency instructions into multi-cycle latency instructions. Still,
970 this is the fastest good hash I could find. There were about 2^^68
971 to choose from. I only looked at a billion or so.
972 --------------------------------------------------------------------
974 /* same, but slower, works on systems that might have 8 byte hashval_t's */
977 a -= b; a -= c; a ^= (c>>13); \
978 b -= c; b -= a; b ^= (a<< 8); \
979 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
980 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
981 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
982 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
983 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
984 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
985 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
989 --------------------------------------------------------------------
990 hash() -- hash a variable-length key into a 32-bit value
991 k : the key (the unaligned variable-length array of bytes)
992 len : the length of the key, counting by bytes
993 level : can be any 4-byte value
994 Returns a 32-bit value. Every bit of the key affects every bit of
995 the return value. Every 1-bit and 2-bit delta achieves avalanche.
996 About 36+6len instructions.
998 The best hash table sizes are powers of 2. There is no need to do
999 mod a prime (mod is sooo slow!). If you need less than 32 bits,
1000 use a bitmask. For example, if you need only 10 bits, do
1001 h = (h & hashmask(10));
1002 In which case, the hash table should have hashsize(10) elements.
1004 If you are hashing n strings (ub1 **)k, do it like this:
1005 for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
1007 By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
1008 code any way you wish, private, educational, or commercial. It's free.
1010 See http://burtleburtle.net/bob/hash/evahash.html
1011 Use for hash table lookup, or anything where one collision in 2^32 is
1012 acceptable. Do NOT use for cryptographic purposes.
1013 --------------------------------------------------------------------
1017 iterative_hash (const void *k_in
/* the key */,
1018 register size_t length
/* the length of the key */,
1019 register hashval_t initval
/* the previous hash, or
1020 an arbitrary value */)
1022 register const unsigned char *k
= (const unsigned char *)k_in
;
1023 register hashval_t a
,b
,c
,len
;
1025 /* Set up the internal state */
1027 a
= b
= 0x9e3779b9; /* the golden ratio; an arbitrary value */
1028 c
= initval
; /* the previous hash value */
1030 /*---------------------------------------- handle most of the key */
1033 a
+= (k
[0] +((hashval_t
)k
[1]<<8) +((hashval_t
)k
[2]<<16) +((hashval_t
)k
[3]<<24));
1034 b
+= (k
[4] +((hashval_t
)k
[5]<<8) +((hashval_t
)k
[6]<<16) +((hashval_t
)k
[7]<<24));
1035 c
+= (k
[8] +((hashval_t
)k
[9]<<8) +((hashval_t
)k
[10]<<16)+((hashval_t
)k
[11]<<24));
1040 /*------------------------------------- handle the last 11 bytes */
1042 switch(len
) /* all the case statements fall through */
1044 case 11: c
+=((hashval_t
)k
[10]<<24);
1045 case 10: c
+=((hashval_t
)k
[9]<<16);
1046 case 9 : c
+=((hashval_t
)k
[8]<<8);
1047 /* the first byte of c is reserved for the length */
1048 case 8 : b
+=((hashval_t
)k
[7]<<24);
1049 case 7 : b
+=((hashval_t
)k
[6]<<16);
1050 case 6 : b
+=((hashval_t
)k
[5]<<8);
1052 case 4 : a
+=((hashval_t
)k
[3]<<24);
1053 case 3 : a
+=((hashval_t
)k
[2]<<16);
1054 case 2 : a
+=((hashval_t
)k
[1]<<8);
1056 /* case 0: nothing left to add */
1059 /*-------------------------------------------- report the result */
1064 e_hash (const void *a
)
1066 const struct entry
*e
= a
;
1070 if (e
[0].etype
!= ETYPE_STRUCT
&& e
[0].etype
!= ETYPE_UNION
)
1072 for (i
= 0; i
<= e
[0].len
; ++i
)
1075 ret
= iterative_hash (&e
[i
], offsetof (struct entry
, attrib
), ret
);
1076 attriblen
= e
[i
].attrib
? strlen (e
[i
].attrib
) : -1;
1077 ret
= iterative_hash (&attriblen
, sizeof (int), ret
);
1079 ret
= iterative_hash (e
[i
].attrib
, attriblen
, ret
);
1085 e_eq (const void *a
, const void *b
)
1087 const struct entry
*ea
= a
, *eb
= b
;
1089 if (ea
[0].etype
!= ETYPE_STRUCT
&& ea
[0].etype
!= ETYPE_UNION
)
1091 if (ea
[0].len
!= eb
[0].len
)
1093 for (i
= 0; i
<= ea
[0].len
; ++i
)
1095 if (ea
[i
].etype
!= eb
[i
].etype
1096 || ea
[i
].len
!= eb
[i
].len
1097 || ea
[i
].arr_len
!= eb
[i
].arr_len
1098 || ea
[i
].type
!= eb
[i
].type
)
1100 if ((ea
[i
].attrib
== NULL
) ^ (eb
[i
].attrib
== NULL
))
1102 if (ea
[i
].attrib
&& strcmp (ea
[i
].attrib
, eb
[i
].attrib
) != 0)
1109 e_exists (const struct entry
*e
)
1115 for (h
= hash_table
[hval
% HASH_SIZE
]; h
; h
= h
->next
)
1122 e_insert (struct entry
*e
)
1127 e
->next
= hash_table
[hval
% HASH_SIZE
];
1128 hash_table
[hval
% HASH_SIZE
] = e
;
1132 output (struct entry
*e
)
1138 if (e
[0].etype
!= ETYPE_STRUCT
&& e
[0].etype
!= ETYPE_UNION
)
1144 n
= (struct entry
*) malloc ((e
[0].len
+ 1) * sizeof (struct entry
));
1145 memcpy (n
, e
, (e
[0].len
+ 1) * sizeof (struct entry
));
1149 switchfiles (e
[0].len
);
1151 if (e
[0].etype
== ETYPE_STRUCT
)
1152 fprintf (outfile
, "T(%d,", idx
);
1154 fprintf (outfile
, "U(%d,", idx
);
1156 for (i
= 1; i
<= e
[0].len
; )
1157 i
+= subfield (e
+ i
, &c
);
1158 fputs (",", outfile
);
1160 for (i
= 1; i
<= e
[0].len
; )
1162 i
+= subvalues (e
+ i
, namebuf
, &c
);
1163 if (e
[0].etype
== ETYPE_UNION
)
1166 fputs (")\n", outfile
);
1167 if (output_one
&& idx
== limidx
)
1175 FEATURE_ALIGNEDPACKED
= 2,
1176 FEATURE_ZEROARRAY
= 4,
1177 FEATURE_ZEROBITFLD
= 8,
1178 ALL_FEATURES
= FEATURE_VECTOR
| FEATURE_ZEROARRAY
1179 | FEATURE_ALIGNEDPACKED
| FEATURE_ZEROBITFLD
1183 singles (enum FEATURE features
)
1187 memset (e
, 0, sizeof (e
));
1188 e
[0].etype
= ETYPE_STRUCT
;
1190 e
[0].etype
= ETYPE_UNION
;
1193 for (i
= 0; i
< NTYPES2
; ++i
)
1195 e
[0].etype
= ETYPE_STRUCT
;
1196 e
[1].etype
= ETYPE_TYPE
;
1197 e
[1].type
= &base_types
[i
];
1199 e
[0].etype
= ETYPE_UNION
;
1202 if (features
& FEATURE_VECTOR
)
1203 for (i
= 0; i
< NVTYPES2
; ++i
)
1205 e
[0].etype
= ETYPE_STRUCT
;
1206 e
[1].etype
= ETYPE_TYPE
;
1207 e
[1].type
= &vector_types
[i
];
1209 e
[0].etype
= ETYPE_UNION
;
1215 choose_type (enum FEATURE features
, struct entry
*e
, int r
, int in_array
)
1219 i
= NTYPES2
- NTYPES1
;
1220 if (features
& FEATURE_VECTOR
)
1231 if (r
< NTYPES2
- NTYPES1
)
1232 e
->type
= &base_types
[r
+ NTYPES1
];
1233 r
-= NTYPES2
- NTYPES1
;
1234 if (e
->type
== NULL
&& (features
& FEATURE_VECTOR
))
1237 e
->type
= &vector_types
[r
];
1240 if (e
->type
== NULL
&& !in_array
)
1243 e
->type
= &attrib_types
[r
];
1246 if (e
->type
== NULL
&& in_array
)
1249 e
->type
= &attrib_array_types
[r
];
1252 if (e
->type
== NULL
)
1256 /* This is from gcc.c-torture/execute/builtin-bitops-1.c. */
1258 my_ffsll (unsigned long long x
)
1263 /* We've tested LLONG_MAX for 64 bits so this should be safe. */
1264 for (i
= 0; i
< 64; i
++)
1265 if (x
& (1ULL << i
))
1271 generate_fields (enum FEATURE features
, struct entry
*e
, struct entry
*parent
,
1274 int r
, i
, j
, ret
= 1, n
, incr
, sametype
;
1276 for (n
= 0; n
< len
; n
+= incr
)
1278 r
= generate_random ();
1279 /* 50% ETYPE_TYPE base_types NTYPES1
1280 12.5% ETYPE_TYPE other
1283 12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1293 e
[n
].etype
= ETYPE_TYPE
;
1294 e
[n
].type
= &base_types
[r
% NTYPES1
];
1297 e
[n
].etype
= ETYPE_TYPE
;
1298 choose_type (features
, &e
[n
], r
, 0);
1301 e
[n
].etype
= ETYPE_ARRAY
;
1305 e
[n
].type
= &base_types
[r
% NTYPES1
];
1307 choose_type (features
, &e
[n
], r
, 1);
1308 r
= generate_random ();
1309 if ((features
& FEATURE_ZEROARRAY
) && (r
& 3) == 0)
1312 if (n
== len
- 1 && (r
& 4)
1313 && (parent
->etype
== ETYPE_STRUCT
1314 || parent
->etype
== ETYPE_STRUCT_ARRAY
))
1317 for (k
= 0; k
< n
; ++k
)
1318 if (e
[k
].etype
!= ETYPE_BITFLD
|| e
[k
].len
)
1325 else if ((r
& 3) != 3)
1326 e
[n
].arr_len
= (r
>> 2) & 7;
1328 e
[n
].arr_len
= (r
>> 2) & 31;
1341 incr
= 1 + (r
>> 3) % (len
- n
);
1346 incr
= 1 + (r
>> 3) % (len
- n
);
1349 for (j
= n
; j
< n
+ incr
; ++j
)
1353 e
[j
].etype
= ETYPE_BITFLD
;
1354 if (j
== n
|| !sametype
)
1357 r
= generate_random ();
1362 = &aligned_bitfld_types
[r
% n_aligned_bitfld_types
];
1365 = &bitfld_types
[r
% n_bitfld_types
];
1368 e
[j
].type
= e
[n
].type
;
1369 r
= generate_random ();
1372 switch (e
[j
].type
->bitfld
)
1374 case 'C': ma
= 8; break;
1375 case 'S': ma
= 16; break;
1376 case 'I': ma
= 32; break;
1378 case 'Q': ma
= 64; break;
1379 case 'B': ma
= 1; break;
1381 if (e
[j
].type
->type
== TYPE_UENUM
)
1382 mi
= my_ffsll (e
[j
].type
->maxval
+ 1) - 1;
1383 else if (e
[j
].type
->type
== TYPE_SENUM
)
1384 mi
= my_ffsll (e
[j
].type
->maxval
+ 1);
1391 else if (mi
> 16 || !short_enums
)
1402 if (sametype
&& (r
& 3) == 0 && ma
> 1)
1405 for (k
= n
; k
< j
; ++k
)
1408 e
[j
].len
= sum
? ma
- sum
: ma
;
1411 if (!sametype
&& (r
& 7) == 0)
1414 if (! (features
& FEATURE_ZEROBITFLD
) && mi
== 0)
1416 if (e
[j
].len
< mi
|| e
[j
].len
> ma
)
1417 e
[j
].len
= mi
+ (r
% (ma
+ 1 - mi
));
1419 if ((features
& FEATURE_ZEROBITFLD
) && (r
& 3) == 0
1430 e
[n
].etype
= ETYPE_STRUCT
;
1434 e
[n
].etype
= ETYPE_UNION
;
1438 e
[n
].etype
= ETYPE_STRUCT_ARRAY
;
1441 e
[n
].etype
= ETYPE_UNION_ARRAY
;
1445 e
[n
].len
= r
% (len
- n
);
1446 incr
= 1 + e
[n
].len
;
1447 generate_fields (features
, &e
[n
+ 1], &e
[n
], e
[n
].len
);
1448 if (e
[n
].etype
== ETYPE_STRUCT_ARRAY
1449 || e
[n
].etype
== ETYPE_UNION_ARRAY
)
1451 r
= generate_random ();
1452 if ((features
& FEATURE_ZEROARRAY
) && (r
& 3) == 0)
1455 if (n
+ incr
== len
&& (r
& 4)
1456 && (parent
->etype
== ETYPE_STRUCT
1457 || parent
->etype
== ETYPE_STRUCT_ARRAY
))
1460 for (k
= 0; k
< n
; ++k
)
1461 if (e
[k
].etype
!= ETYPE_BITFLD
|| e
[k
].len
)
1468 else if ((r
& 3) != 3)
1469 e
[n
].arr_len
= (r
>> 2) & 7;
1471 e
[n
].arr_len
= (r
>> 2) & 31;
1475 r
= generate_random ();
1479 i
= (features
& FEATURE_ALIGNEDPACKED
) ? NATTRIBS2
: NATTRIBS1
;
1480 e
[n
].attrib
= attributes
[r
% i
];
1481 if (! (features
& FEATURE_ALIGNEDPACKED
)
1482 && strcmp (e
[n
].attrib
, "atpa") == 0
1483 && ((e
[n
].type
>= &attrib_types
[0]
1484 && e
[n
].type
< &attrib_types
[NATYPES2
])
1485 || (e
[n
].type
>= &attrib_array_types
[0]
1486 && e
[n
].type
< &attrib_array_types
[NAATYPES2
])
1487 || (e
[n
].type
>= &aligned_bitfld_types
[0]
1488 && e
[n
].type
< &aligned_bitfld_types
[n_aligned_bitfld_types
])))
1495 generate_random_tests (enum FEATURE features
, int len
)
1497 struct entry e
[len
+ 1];
1499 if (len
> 'z' - 'a' + 1)
1501 memset (e
, 0, sizeof (e
));
1502 r
= generate_random ();
1504 e
[0].etype
= ETYPE_UNION
;
1506 e
[0].etype
= ETYPE_STRUCT
;
1509 generate_fields (features
, &e
[1], &e
[0], len
);
1513 struct { const char *name
; enum FEATURE f
; }
1516 { "vector", FEATURE_VECTOR
},
1517 { "[0] :0", FEATURE_ZEROARRAY
| FEATURE_ZEROBITFLD
},
1519 FEATURE_VECTOR
| FEATURE_ZEROARRAY
},
1520 { "aligned packed vector [0] :0",
1521 FEATURE_VECTOR
| FEATURE_ZEROARRAY
1522 | FEATURE_ALIGNEDPACKED
| FEATURE_ZEROBITFLD
},
1526 main (int argc
, char **argv
)
1528 int i
, j
, count
, c
, n
= 3000;
1531 if (sizeof (int) != 4 || sizeof (long long) != 8)
1538 if (argv
[i
][0] == '-' && argv
[i
][2] == '\0')
1540 optarg
= argv
[i
+ 1];
1556 limidx
= atoi (optarg
);
1563 fprintf (stderr
, "unrecognized option %s\n", argv
[i
]);
1571 outfile
= fopen ("/dev/null", "w");
1572 if (outfile
== NULL
)
1574 fputs ("could not open /dev/null", stderr
);
1580 if (destdir
== NULL
&& !output_one
)
1583 fprintf (stderr
, "Usage:\n\
1584 %s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\
1585 Either -s srcdir -d destdir or -i idx must be used\n", argv
[0]);
1589 if (srcdir
== NULL
&& !output_one
)
1592 for (i
= 0; i
< NTYPES2
; ++i
)
1593 if (base_types
[i
].bitfld
)
1594 bitfld_types
[n_bitfld_types
++] = base_types
[i
];
1595 for (i
= 0; i
< NATYPES2
; ++i
)
1596 if (attrib_types
[i
].bitfld
)
1597 aligned_bitfld_types
[n_aligned_bitfld_types
++] = attrib_types
[i
];
1598 for (i
= 0; i
< sizeof (features
) / sizeof (features
[0]); ++i
)
1607 for (j
= 1; j
<= 9; ++j
)
1608 while (idx
< startidx
+ j
* count
)
1609 generate_random_tests (features
[i
].f
, j
);
1610 while (idx
< startidx
+ count
* 10)
1611 generate_random_tests (features
[i
].f
, 10 + (generate_random () % 16));
1613 for (i
= 0; n
> 3000 && i
< sizeof (features
) / sizeof (features
[0]); ++i
)
1619 singles (features
[i
].f
);
1623 while (idx
< startidx
+ 1000)
1624 generate_random_tests (features
[i
].f
, 1);
1630 while (idx
< startidx
+ 100)
1631 generate_random_tests (features
[i
].f
, 1);
1634 for (j
= 2; j
<= 9; ++j
)
1635 while (idx
< startidx
+ (j
- 1) * count
)
1636 generate_random_tests (features
[i
].f
, j
);
1637 while (idx
< startidx
+ count
* 9)
1638 generate_random_tests (features
[i
].f
, 10 + (generate_random () % 16));
1643 generate_random_tests (ALL_FEATURES
, 1 + (generate_random () % 25));