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
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 COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
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 typedef unsigned int hashval_t
;
57 unsigned long long int maxval
;
61 struct types base_types
[] = {
62 /* As we don't know whether char will be signed or not, just limit ourselves
63 to unsigned values less than maximum signed char value. */
64 { "char", TYPE_UINT
, 127, 'C' },
65 { "signed char", TYPE_INT
, 127, 'C' },
66 { "unsigned char", TYPE_UINT
, 255, 'C' },
67 { "short int", TYPE_INT
, 32767, 'S' },
68 { "unsigned short int", TYPE_UINT
, 65535, 'S' },
69 { "int", TYPE_INT
, 2147483647, 'I' },
70 { "unsigned int", TYPE_UINT
, 4294967295U, 'I' },
71 { "long int", TYPE_INT
, 9223372036854775807LL, 'L' },
72 { "unsigned long int", TYPE_UINT
, 18446744073709551615ULL, 'L' },
73 { "long long int", TYPE_INT
, 9223372036854775807LL, 'Q' },
74 { "unsigned long long int", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
75 { "bool", TYPE_UINT
, 1, 'B' },
76 { "void *", TYPE_PTR
, 0, 0 },
77 { "char *", TYPE_PTR
, 0, 0 },
78 { "int *", TYPE_PTR
, 0, 0 },
79 { "float", TYPE_FLOAT
, 0, 0 },
80 { "double", TYPE_FLOAT
, 0, 0 },
81 { "long double", TYPE_FLOAT
, 0, 0 },
83 { "Tchar", TYPE_UINT
, 127, 'C' },
84 { "Tschar", TYPE_INT
, 127, 'C' },
85 { "Tuchar", TYPE_UINT
, 255, 'C' },
86 { "Tshort", TYPE_INT
, 32767, 'S' },
87 { "Tushort", TYPE_UINT
, 65535, 'S' },
88 { "Tint", TYPE_INT
, 2147483647, 'I' },
89 { "Tuint", TYPE_UINT
, 4294967295U, 'I' },
90 { "Tlong", TYPE_INT
, 9223372036854775807LL, 'L' },
91 { "Tulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
92 { "Tllong", TYPE_INT
, 9223372036854775807LL, 'Q' },
93 { "Tullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
94 { "Tbool", TYPE_UINT
, 1, 'B' },
95 { "size_t", TYPE_UINT
, 18446744073709551615ULL, 0 },
96 { "Tptr", TYPE_PTR
, 0, 0 },
97 { "Tcptr", TYPE_PTR
, 0, 0 },
98 { "Tiptr", TYPE_PTR
, 0, 0 },
99 { "Tfnptr", TYPE_FNPTR
, 0, 0 },
100 { "Tfloat", TYPE_FLOAT
, 0, 0 },
101 { "Tdouble", TYPE_FLOAT
, 0, 0 },
102 { "Tldouble", TYPE_FLOAT
, 0, 0 },
103 { "enum E0", TYPE_UENUM
, 0, ' ' },
104 { "enum E1", TYPE_UENUM
, 1, ' ' },
105 { "enum E2", TYPE_SENUM
, 3, ' ' },
106 { "enum E3", TYPE_SENUM
, 127, ' ' },
107 { "enum E4", TYPE_UENUM
, 255, ' ' },
108 { "enum E5", TYPE_SENUM
, 32767, ' ' },
109 { "enum E6", TYPE_UENUM
, 65535, ' ' },
110 { "enum E7", TYPE_SENUM
, 2147483647, ' ' },
111 { "enum E8", TYPE_UENUM
, 4294967295U, ' ' },
112 { "enum E9", TYPE_SENUM
, 1099511627775LL, ' ' },
113 { "TE0", TYPE_UENUM
, 0, ' ' },
114 { "TE1", TYPE_UENUM
, 1, ' ' },
115 { "TE2", TYPE_SENUM
, 3, ' ' },
116 { "TE3", TYPE_SENUM
, 127, ' ' },
117 { "TE4", TYPE_UENUM
, 255, ' ' },
118 { "TE5", TYPE_SENUM
, 32767, ' ' },
119 { "TE6", TYPE_UENUM
, 65535, ' ' },
120 { "TE7", TYPE_SENUM
, 2147483647, ' ' },
121 { "TE8", TYPE_UENUM
, 4294967295U, ' ' },
122 { "TE9", TYPE_SENUM
, 1099511627775LL, ' ' },
123 /* vector-defs.h typedefs */
124 { "qi", TYPE_INT
, 127, 0 },
125 { "hi", TYPE_INT
, 32767, 0 },
126 { "si", TYPE_INT
, 2147483647, 0 },
127 { "di", TYPE_INT
, 9223372036854775807LL, 0 },
128 { "sf", TYPE_FLOAT
, 0, 0 },
129 { "df", TYPE_FLOAT
, 0, 0 }
130 #define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
132 struct types vector_types
[] = {
133 /* vector-defs.h typedefs */
134 { "v8qi", TYPE_OTHER
, 0, 0 },
135 { "v16qi", TYPE_OTHER
, 0, 0 },
136 { "v2hi", TYPE_OTHER
, 0, 0 },
137 { "v4hi", TYPE_OTHER
, 0, 0 },
138 { "v8hi", TYPE_OTHER
, 0, 0 },
139 { "v2si", TYPE_OTHER
, 0, 0 },
140 { "v4si", TYPE_OTHER
, 0, 0 },
141 { "v1di", TYPE_OTHER
, 0, 0 },
142 { "v2di", TYPE_OTHER
, 0, 0 },
143 { "v2sf", TYPE_OTHER
, 0, 0 },
144 { "v4sf", TYPE_OTHER
, 0, 0 },
145 { "v16sf", TYPE_OTHER
, 0, 0 },
146 { "v2df", TYPE_OTHER
, 0, 0 },
147 { "u8qi", TYPE_OTHER
, 0, 0 },
148 { "u16qi", TYPE_OTHER
, 0, 0 },
149 { "u2hi", TYPE_OTHER
, 0, 0 },
150 { "u4hi", TYPE_OTHER
, 0, 0 },
151 { "u8hi", TYPE_OTHER
, 0, 0 },
152 { "u2si", TYPE_OTHER
, 0, 0 },
153 { "u4si", TYPE_OTHER
, 0, 0 },
154 { "u1di", TYPE_OTHER
, 0, 0 },
155 { "u2di", TYPE_OTHER
, 0, 0 },
156 { "u2sf", TYPE_OTHER
, 0, 0 },
157 { "u4sf", TYPE_OTHER
, 0, 0 },
158 { "u16sf", TYPE_OTHER
, 0, 0 },
159 { "u2df", TYPE_OTHER
, 0, 0 },
160 { "__m64", TYPE_OTHER
, 0, 0 },
161 { "__m128", TYPE_OTHER
, 0, 0 }
162 #define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
164 struct types attrib_types
[] = {
165 { "Talchar", TYPE_UINT
, 127, 'C' },
166 { "Talschar", TYPE_INT
, 127, 'C' },
167 { "Taluchar", TYPE_UINT
, 255, 'C' },
168 { "Talshort", TYPE_INT
, 32767, 'S' },
169 { "Talushort", TYPE_UINT
, 65535, 'S' },
170 { "Talint", TYPE_INT
, 2147483647, 'I' },
171 { "Taluint", TYPE_UINT
, 4294967295U, 'I' },
172 { "Tallong", TYPE_INT
, 9223372036854775807LL, 'L' },
173 { "Talulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
174 { "Talllong", TYPE_INT
, 9223372036854775807LL, 'Q' },
175 { "Talullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
176 { "Talbool", TYPE_UINT
, 1, 'B' },
177 { "Talptr", TYPE_PTR
, 0, 0 },
178 { "Talcptr", TYPE_PTR
, 0, 0 },
179 { "Taliptr", TYPE_PTR
, 0, 0 },
180 { "Talfloat", TYPE_FLOAT
, 0, 0 },
181 { "Taldouble", TYPE_FLOAT
, 0, 0 },
182 { "Talldouble", TYPE_FLOAT
, 0, 0 },
183 { "TalE0", TYPE_UENUM
, 0, ' ' },
184 { "TalE1", TYPE_UENUM
, 1, ' ' },
185 { "TalE2", TYPE_SENUM
, 3, ' ' },
186 { "TalE3", TYPE_SENUM
, 127, ' ' },
187 { "TalE4", TYPE_UENUM
, 255, ' ' },
188 { "TalE5", TYPE_SENUM
, 32767, ' ' },
189 { "TalE6", TYPE_UENUM
, 65535, ' ' },
190 { "TalE7", TYPE_SENUM
, 2147483647, ' ' },
191 { "TalE8", TYPE_UENUM
, 4294967295U, ' ' },
192 { "TalE9", TYPE_SENUM
, 1099511627775LL, ' ' },
193 { "Tal1char", TYPE_UINT
, 127, 'C' },
194 { "Tal1schar", TYPE_INT
, 127, 'C' },
195 { "Tal1uchar", TYPE_UINT
, 255, 'C' },
196 { "Tal1short", TYPE_INT
, 32767, 'S' },
197 { "Tal1ushort", TYPE_UINT
, 65535, 'S' },
198 { "Tal1int", TYPE_INT
, 2147483647, 'I' },
199 { "Tal1uint", TYPE_UINT
, 4294967295U, 'I' },
200 { "Tal1long", TYPE_INT
, 9223372036854775807LL, 'L' },
201 { "Tal1ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
202 { "Tal1llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
203 { "Tal1ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
204 { "Tal1bool", TYPE_UINT
, 1, 'B' },
205 { "Tal1ptr", TYPE_PTR
, 0, 0 },
206 { "Tal1cptr", TYPE_PTR
, 0, 0 },
207 { "Tal1iptr", TYPE_PTR
, 0, 0 },
208 { "Tal1float", TYPE_FLOAT
, 0, 0 },
209 { "Tal1double", TYPE_FLOAT
, 0, 0 },
210 { "Tal1ldouble", TYPE_FLOAT
, 0, 0 },
211 { "Tal1E0", TYPE_UENUM
, 0, ' ' },
212 { "Tal1E1", TYPE_UENUM
, 1, ' ' },
213 { "Tal1E2", TYPE_SENUM
, 3, ' ' },
214 { "Tal1E3", TYPE_SENUM
, 127, ' ' },
215 { "Tal1E4", TYPE_UENUM
, 255, ' ' },
216 { "Tal1E5", TYPE_SENUM
, 32767, ' ' },
217 { "Tal1E6", TYPE_UENUM
, 65535, ' ' },
218 { "Tal1E7", TYPE_SENUM
, 2147483647, ' ' },
219 { "Tal1E8", TYPE_UENUM
, 4294967295U, ' ' },
220 { "Tal1E9", TYPE_SENUM
, 1099511627775LL, ' ' },
221 { "Tal2char", TYPE_UINT
, 127, 'C' },
222 { "Tal2schar", TYPE_INT
, 127, 'C' },
223 { "Tal2uchar", TYPE_UINT
, 255, 'C' },
224 { "Tal2short", TYPE_INT
, 32767, 'S' },
225 { "Tal2ushort", TYPE_UINT
, 65535, 'S' },
226 { "Tal2int", TYPE_INT
, 2147483647, 'I' },
227 { "Tal2uint", TYPE_UINT
, 4294967295U, 'I' },
228 { "Tal2long", TYPE_INT
, 9223372036854775807LL, 'L' },
229 { "Tal2ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
230 { "Tal2llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
231 { "Tal2ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
232 { "Tal2bool", TYPE_UINT
, 1, 'B' },
233 { "Tal2ptr", TYPE_PTR
, 0, 0 },
234 { "Tal2cptr", TYPE_PTR
, 0, 0 },
235 { "Tal2iptr", TYPE_PTR
, 0, 0 },
236 { "Tal2float", TYPE_FLOAT
, 0, 0 },
237 { "Tal2double", TYPE_FLOAT
, 0, 0 },
238 { "Tal2ldouble", TYPE_FLOAT
, 0, 0 },
239 { "Tal2E0", TYPE_UENUM
, 0, ' ' },
240 { "Tal2E1", TYPE_UENUM
, 1, ' ' },
241 { "Tal2E2", TYPE_SENUM
, 3, ' ' },
242 { "Tal2E3", TYPE_SENUM
, 127, ' ' },
243 { "Tal2E4", TYPE_UENUM
, 255, ' ' },
244 { "Tal2E5", TYPE_SENUM
, 32767, ' ' },
245 { "Tal2E6", TYPE_UENUM
, 65535, ' ' },
246 { "Tal2E7", TYPE_SENUM
, 2147483647, ' ' },
247 { "Tal2E8", TYPE_UENUM
, 4294967295U, ' ' },
248 { "Tal2E9", TYPE_SENUM
, 1099511627775LL, ' ' },
249 { "Tal4char", TYPE_UINT
, 127, 'C' },
250 { "Tal4schar", TYPE_INT
, 127, 'C' },
251 { "Tal4uchar", TYPE_UINT
, 255, 'C' },
252 { "Tal4short", TYPE_INT
, 32767, 'S' },
253 { "Tal4ushort", TYPE_UINT
, 65535, 'S' },
254 { "Tal4int", TYPE_INT
, 2147483647, 'I' },
255 { "Tal4uint", TYPE_UINT
, 4294967295U, 'I' },
256 { "Tal4long", TYPE_INT
, 9223372036854775807LL, 'L' },
257 { "Tal4ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
258 { "Tal4llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
259 { "Tal4ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
260 { "Tal4bool", TYPE_UINT
, 1, 'B' },
261 { "Tal4ptr", TYPE_PTR
, 0, 0 },
262 { "Tal4cptr", TYPE_PTR
, 0, 0 },
263 { "Tal4iptr", TYPE_PTR
, 0, 0 },
264 { "Tal4float", TYPE_FLOAT
, 0, 0 },
265 { "Tal4double", TYPE_FLOAT
, 0, 0 },
266 { "Tal4ldouble", TYPE_FLOAT
, 0, 0 },
267 { "Tal4E0", TYPE_UENUM
, 0, ' ' },
268 { "Tal4E1", TYPE_UENUM
, 1, ' ' },
269 { "Tal4E2", TYPE_SENUM
, 3, ' ' },
270 { "Tal4E3", TYPE_SENUM
, 127, ' ' },
271 { "Tal4E4", TYPE_UENUM
, 255, ' ' },
272 { "Tal4E5", TYPE_SENUM
, 32767, ' ' },
273 { "Tal4E6", TYPE_UENUM
, 65535, ' ' },
274 { "Tal4E7", TYPE_SENUM
, 2147483647, ' ' },
275 { "Tal4E8", TYPE_UENUM
, 4294967295U, ' ' },
276 { "Tal4E9", TYPE_SENUM
, 1099511627775LL, ' ' },
277 { "Tal8char", TYPE_UINT
, 127, 'C' },
278 { "Tal8schar", TYPE_INT
, 127, 'C' },
279 { "Tal8uchar", TYPE_UINT
, 255, 'C' },
280 { "Tal8short", TYPE_INT
, 32767, 'S' },
281 { "Tal8ushort", TYPE_UINT
, 65535, 'S' },
282 { "Tal8int", TYPE_INT
, 2147483647, 'I' },
283 { "Tal8uint", TYPE_UINT
, 4294967295U, 'I' },
284 { "Tal8long", TYPE_INT
, 9223372036854775807LL, 'L' },
285 { "Tal8ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
286 { "Tal8llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
287 { "Tal8ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
288 { "Tal8bool", TYPE_UINT
, 1, 'B' },
289 { "Tal8ptr", TYPE_PTR
, 0, 0 },
290 { "Tal8cptr", TYPE_PTR
, 0, 0 },
291 { "Tal8iptr", TYPE_PTR
, 0, 0 },
292 { "Tal8float", TYPE_FLOAT
, 0, 0 },
293 { "Tal8double", TYPE_FLOAT
, 0, 0 },
294 { "Tal8ldouble", TYPE_FLOAT
, 0, 0 },
295 { "Tal8E0", TYPE_UENUM
, 0, ' ' },
296 { "Tal8E1", TYPE_UENUM
, 1, ' ' },
297 { "Tal8E2", TYPE_SENUM
, 3, ' ' },
298 { "Tal8E3", TYPE_SENUM
, 127, ' ' },
299 { "Tal8E4", TYPE_UENUM
, 255, ' ' },
300 { "Tal8E5", TYPE_SENUM
, 32767, ' ' },
301 { "Tal8E6", TYPE_UENUM
, 65535, ' ' },
302 { "Tal8E7", TYPE_SENUM
, 2147483647, ' ' },
303 { "Tal8E8", TYPE_UENUM
, 4294967295U, ' ' },
304 { "Tal8E9", TYPE_SENUM
, 1099511627775LL, ' ' },
305 { "Tal16char", TYPE_UINT
, 127, 'C' },
306 { "Tal16schar", TYPE_INT
, 127, 'C' },
307 { "Tal16uchar", TYPE_UINT
, 255, 'C' },
308 { "Tal16short", TYPE_INT
, 32767, 'S' },
309 { "Tal16ushort", TYPE_UINT
, 65535, 'S' },
310 { "Tal16int", TYPE_INT
, 2147483647, 'I' },
311 { "Tal16uint", TYPE_UINT
, 4294967295U, 'I' },
312 { "Tal16long", TYPE_INT
, 9223372036854775807LL, 'L' },
313 { "Tal16ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
314 { "Tal16llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
315 { "Tal16ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
316 { "Tal16bool", TYPE_UINT
, 1, 'B' },
317 { "Tal16ptr", TYPE_PTR
, 0, 0 },
318 { "Tal16cptr", TYPE_PTR
, 0, 0 },
319 { "Tal16iptr", TYPE_PTR
, 0, 0 },
320 { "Tal16float", TYPE_FLOAT
, 0, 0 },
321 { "Tal16double", TYPE_FLOAT
, 0, 0 },
322 { "Tal16ldouble", TYPE_FLOAT
, 0, 0 },
323 { "Tal16E0", TYPE_UENUM
, 0, ' ' },
324 { "Tal16E1", TYPE_UENUM
, 1, ' ' },
325 { "Tal16E2", TYPE_SENUM
, 3, ' ' },
326 { "Tal16E3", TYPE_SENUM
, 127, ' ' },
327 { "Tal16E4", TYPE_UENUM
, 255, ' ' },
328 { "Tal16E5", TYPE_SENUM
, 32767, ' ' },
329 { "Tal16E6", TYPE_UENUM
, 65535, ' ' },
330 { "Tal16E7", TYPE_SENUM
, 2147483647, ' ' },
331 { "Tal16E8", TYPE_UENUM
, 4294967295U, ' ' },
332 { "Tal16E9", TYPE_SENUM
, 1099511627775LL, ' ' }
333 #define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0]))
336 struct types bitfld_types
[NTYPES2
];
338 struct types aligned_bitfld_types
[NATYPES2
];
339 int n_aligned_bitfld_types
;
341 const char *attributes
[] = {
362 #define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0]))
379 enum ETYPE etype
: 8;
384 unsigned char arr_len
;
387 /* Used to chain together entries in the hash table. */
390 struct types attrib_array_types
[] = {
391 { "Talx1char", TYPE_UINT
, 127, 'C' },
392 { "Talx1schar", TYPE_INT
, 127, 'C' },
393 { "Talx1uchar", TYPE_UINT
, 255, 'C' },
394 { "Talx1short", TYPE_INT
, 32767, 'S' },
395 { "Talx1ushort", TYPE_UINT
, 65535, 'S' },
396 { "Talx1int", TYPE_INT
, 2147483647, 'I' },
397 { "Talx1uint", TYPE_UINT
, 4294967295U, 'I' },
398 { "Talx1long", TYPE_INT
, 9223372036854775807LL, 'L' },
399 { "Talx1ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
400 { "Talx1llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
401 { "Talx1ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
402 { "Talx1bool", TYPE_UINT
, 1, 'B' },
403 { "Talx1ptr", TYPE_PTR
, 0, 0 },
404 { "Talx1cptr", TYPE_PTR
, 0, 0 },
405 { "Talx1iptr", TYPE_PTR
, 0, 0 },
406 { "Talx1float", TYPE_FLOAT
, 0, 0 },
407 { "Talx1double", TYPE_FLOAT
, 0, 0 },
408 { "Talx1ldouble", TYPE_FLOAT
, 0, 0 },
409 { "Talx1E0", TYPE_UENUM
, 0, ' ' },
410 { "Talx1E1", TYPE_UENUM
, 1, ' ' },
411 { "Talx1E2", TYPE_SENUM
, 3, ' ' },
412 { "Talx1E3", TYPE_SENUM
, 127, ' ' },
413 { "Talx1E4", TYPE_UENUM
, 255, ' ' },
414 { "Talx1E5", TYPE_SENUM
, 32767, ' ' },
415 { "Talx1E6", TYPE_UENUM
, 65535, ' ' },
416 { "Talx1E7", TYPE_SENUM
, 2147483647, ' ' },
417 { "Talx1E8", TYPE_UENUM
, 4294967295U, ' ' },
418 { "Talx1E9", TYPE_SENUM
, 1099511627775LL, ' ' },
419 { "Talx2short", TYPE_INT
, 32767, 'S' },
420 { "Talx2ushort", TYPE_UINT
, 65535, 'S' },
421 { "Talx2int", TYPE_INT
, 2147483647, 'I' },
422 { "Talx2uint", TYPE_UINT
, 4294967295U, 'I' },
423 { "Talx2long", TYPE_INT
, 9223372036854775807LL, 'L' },
424 { "Talx2ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
425 { "Talx2llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
426 { "Talx2ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
427 { "Talx2ptr", TYPE_PTR
, 0, 0 },
428 { "Talx2cptr", TYPE_PTR
, 0, 0 },
429 { "Talx2iptr", TYPE_PTR
, 0, 0 },
430 { "Talx2float", TYPE_FLOAT
, 0, 0 },
431 { "Talx2double", TYPE_FLOAT
, 0, 0 },
432 { "Talx2ldouble", TYPE_FLOAT
, 0, 0 },
433 { "Talx2E0", TYPE_UENUM
, 0, ' ' },
434 { "Talx2E1", TYPE_UENUM
, 1, ' ' },
435 { "Talx2E2", TYPE_SENUM
, 3, ' ' },
436 { "Talx2E3", TYPE_SENUM
, 127, ' ' },
437 { "Talx2E4", TYPE_UENUM
, 255, ' ' },
438 { "Talx2E5", TYPE_SENUM
, 32767, ' ' },
439 { "Talx2E6", TYPE_UENUM
, 65535, ' ' },
440 { "Talx2E7", TYPE_SENUM
, 2147483647, ' ' },
441 { "Talx2E8", TYPE_UENUM
, 4294967295U, ' ' },
442 { "Talx2E9", TYPE_SENUM
, 1099511627775LL, ' ' },
443 { "Talx4int", TYPE_INT
, 2147483647, 'I' },
444 { "Talx4uint", TYPE_UINT
, 4294967295U, 'I' },
445 { "Talx4long", TYPE_INT
, 9223372036854775807LL, 'L' },
446 { "Talx4ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
447 { "Talx4llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
448 { "Talx4ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
449 { "Talx4ptr", TYPE_PTR
, 0, 0 },
450 { "Talx4cptr", TYPE_PTR
, 0, 0 },
451 { "Talx4iptr", TYPE_PTR
, 0, 0 },
452 { "Talx4float", TYPE_FLOAT
, 0, 0 },
453 { "Talx4double", TYPE_FLOAT
, 0, 0 },
454 { "Talx4ldouble", TYPE_FLOAT
, 0, 0 },
455 { "Talx4E0", TYPE_UENUM
, 0, ' ' },
456 { "Talx4E1", TYPE_UENUM
, 1, ' ' },
457 { "Talx4E2", TYPE_SENUM
, 3, ' ' },
458 { "Talx4E3", TYPE_SENUM
, 127, ' ' },
459 { "Talx4E4", TYPE_UENUM
, 255, ' ' },
460 { "Talx4E5", TYPE_SENUM
, 32767, ' ' },
461 { "Talx4E6", TYPE_UENUM
, 65535, ' ' },
462 { "Talx4E7", TYPE_SENUM
, 2147483647, ' ' },
463 { "Talx4E8", TYPE_UENUM
, 4294967295U, ' ' },
464 { "Talx4E9", TYPE_SENUM
, 1099511627775LL, ' ' },
465 { "Taly8long", TYPE_INT
, 9223372036854775807LL, 'L' },
466 { "Taly8ulong", TYPE_UINT
, 18446744073709551615ULL, 'L' },
467 { "Talx8llong", TYPE_INT
, 9223372036854775807LL, 'Q' },
468 { "Talx8ullong", TYPE_UINT
, 18446744073709551615ULL, 'Q' },
469 { "Taly8ptr", TYPE_PTR
, 0, 0 },
470 { "Taly8cptr", TYPE_PTR
, 0, 0 },
471 { "Taly8iptr", TYPE_PTR
, 0, 0 },
472 { "Talx8double", TYPE_FLOAT
, 0, 0 },
473 { "Talx8ldouble", TYPE_FLOAT
, 0, 0 }
474 #define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0]))
477 /* A prime number giving the number of slots in the hash table. */
478 #define HASH_SIZE 32749
479 static struct entry
*hash_table
[HASH_SIZE
];
481 static int idx
, limidx
, output_one
, short_enums
;
482 static const char *destdir
;
483 static const char *srcdir
;
487 switchfiles (int fields
)
490 static char *destbuf
, *destptr
;
501 size_t len
= strlen (destdir
);
502 destbuf
= malloc (len
+ 20);
505 memcpy (destbuf
, destdir
, len
);
506 if (!len
|| destbuf
[len
- 1] != '/')
507 destbuf
[len
++] = '/';
508 destptr
= destbuf
+ len
;
510 sprintf (destptr
, "t%03d_main.C", filecnt
);
511 outfile
= fopen (destbuf
, "w");
515 fputs ("failed to create test files\n", stderr
);
519 /* { dg-options \"-I%s\" } */\n\
520 /* { dg-options \"-I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
521 /* { dg-options \"-I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
522 #include \"struct-layout-1.h\"\n\
524 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
525 #include \"t%03d_test.h\"\n\
530 #define TX(n, type, attrs, fields, ops) test##n ();\n\
531 #include \"t%03d_test.h\"\n\
539 }\n", srcdir
, srcdir
, srcdir
, filecnt
, filecnt
);
541 sprintf (destptr
, "t%03d_x.C", filecnt
);
542 outfile
= fopen (destbuf
, "w");
546 /* { dg-options \"-w -I%s\" } */\n\
547 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
548 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
549 #include \"struct-layout-1_x1.h\"\n\
550 #include \"t%03d_test.h\"\n\
551 #include \"struct-layout-1_x2.h\"\n\
552 #include \"t%03d_test.h\"\n", srcdir
, srcdir
, srcdir
, filecnt
, filecnt
);
554 sprintf (destptr
, "t%03d_y.C", filecnt
);
555 outfile
= fopen (destbuf
, "w");
559 /* { dg-options \"-w -I%s\" } */\n\
560 /* { dg-options \"-w -I%s -fno-common\" { target hppa*-*-hpux* } } */\n\
561 /* { dg-options \"-w -I%s -mno-base-addresses\" { target mmix-*-* } } */\n\
562 #include \"struct-layout-1_y1.h\"\n\
563 #include \"t%03d_test.h\"\n\
564 #include \"struct-layout-1_y2.h\"\n\
565 #include \"t%03d_test.h\"\n", srcdir
, srcdir
, srcdir
, filecnt
, filecnt
);
567 sprintf (destptr
, "t%03d_test.h", filecnt
);
568 outfile
= fopen (destbuf
, "w");
573 else if (fields
<= 4)
575 else if (fields
<= 6)
581 unsigned long long int
584 unsigned long long int ret
;
585 ret
= generate_random () & 0xffffff;
586 ret
|= (generate_random () & 0xffffffLL
) << 24;
587 ret
|= ((unsigned long long int) generate_random ()) << 48;
592 subfield (struct entry
*e
, char *letter
)
601 case ETYPE_STRUCT_ARRAY
:
602 case ETYPE_UNION_ARRAY
:
603 type
= e
[0].attrib
? 1 + (generate_random () & 3) : 0;
604 if (e
[0].etype
== ETYPE_STRUCT
|| e
[0].etype
== ETYPE_STRUCT_ARRAY
)
608 if (e
[0].etype
== ETYPE_STRUCT_ARRAY
|| e
[0].etype
== ETYPE_UNION_ARRAY
)
610 if (e
[0].arr_len
== 255)
611 snprintf (buf
, 20, "%c[]", *letter
);
613 snprintf (buf
, 20, "%c[%d]", *letter
, e
[0].arr_len
);
614 /* If this is an array type, do not put aligned attributes on
615 elements. Aligning elements to a value greater than their
616 size will result in a compiler error. */
618 && ((strncmp (e
[0].attrib
, "atal", 4) == 0)
619 || strncmp (e
[0].attrib
, "atpaal", 6) == 0))
633 fprintf (outfile
, "%s{", p
);
636 fprintf (outfile
, "%s %s{", e
[0].attrib
, p
);
639 fprintf (outfile
, "%s %s{", p
, e
[0].attrib
);
643 for (i
= 1; i
<= e
[0].len
; )
644 i
+= subfield (e
+ i
, letter
);
651 fprintf (outfile
, "}%s;", buf
);
654 fprintf (outfile
, "}%s %s;", e
[0].attrib
, buf
);
657 fprintf (outfile
, "}%s %s;", buf
, e
[0].attrib
);
663 if (e
[0].etype
== ETYPE_ARRAY
)
665 if (e
[0].arr_len
== 255)
666 snprintf (buf
, 20, "%c[]", *letter
);
668 snprintf (buf
, 20, "%c[%d]", *letter
, e
[0].arr_len
);
678 /* If this is an array type, do not put aligned attributes on
679 elements. Aligning elements to a value greater than their
680 size will result in a compiler error. */
681 if (e
[0].etype
== ETYPE_ARRAY
682 && ((strncmp (e
[0].attrib
, "atal", 4) == 0)
683 || strncmp (e
[0].attrib
, "atpaal", 6) == 0))
686 type
= generate_random () % 3;
690 fprintf (outfile
, "%s %s %s;", e
[0].attrib
, e
[0].type
->name
,
694 fprintf (outfile
, "%s %s %s;", e
[0].type
->name
, e
[0].attrib
,
698 fprintf (outfile
, "%s %s %s;", e
[0].type
->name
, buf
,
704 fprintf (outfile
, "%s %s;", e
[0].type
->name
, buf
);
710 switch (generate_random () % 3)
713 fprintf (outfile
, "%s %s:0;", e
[0].attrib
, e
[0].type
->name
);
716 fprintf (outfile
, "%s %s:0;", e
[0].type
->name
, e
[0].attrib
);
719 fprintf (outfile
, "%s:0 %s;", e
[0].type
->name
, e
[0].attrib
);
723 fprintf (outfile
, "%s:0;", e
[0].type
->name
);
727 snprintf (buf
, 20, "%d", e
[0].len
);
729 switch (generate_random () % 3)
732 fprintf (outfile
, "%s %s %c:%s;", e
[0].attrib
, e
[0].type
->name
,
736 fprintf (outfile
, "%s %s %c:%s;", e
[0].type
->name
, e
[0].attrib
,
740 fprintf (outfile
, "%s %c:%s %s;", e
[0].type
->name
, *letter
,
745 fprintf (outfile
, "%s %c:%s;", e
[0].type
->name
, *letter
, buf
);
756 output_FNB (char mode
, struct entry
*e
)
758 unsigned long long int l1
, l2
, m
;
762 if (e
->type
->type
== TYPE_OTHER
)
766 fprintf (outfile
, "N(%d,%s)", idx
, namebuf
);
769 fprintf (outfile
, "%c(%d,%s,", mode
, idx
, namebuf
);
772 switch (e
->type
->type
)
775 signs
= generate_random () & 3;
778 m
&= e
->len
> 1 ? (1ULL << (e
->len
- 1)) - 1 : 1;
781 fprintf (outfile
, "%s%llu%s,%s%llu%s",
782 (signs
& 1) ? "-" : "", l1
, l1
> 2147483647 ? "LL" : "",
783 (signs
& 2) ? "-" : "", l2
, l2
> 2147483647 ? "LL" : "");
788 m
&= (1ULL << e
->len
) - 1;
791 fprintf (outfile
, "%lluU%s,%lluU%s", l1
, l1
> 4294967295U ? "LL" : "",
792 l2
, l2
> 4294967295U ? "LL" : "");
797 signs
= generate_random () & 3;
798 fprintf (outfile
, "%s%f,%s%f", (signs
& 1) ? "-" : "",
799 ((double) l1
) / 64, (signs
& 2) ? "-" : "", ((double) l2
) / 64);
802 if (e
->type
->maxval
== 0)
803 fputs ("e0_0,e0_0", outfile
);
804 else if (e
->type
->maxval
== 1)
805 fprintf (outfile
, "e1_%lld,e1_%lld", l1
& 1, l2
& 1);
808 p
= strchr (e
->type
->name
, '\0');
809 while (--p
>= e
->type
->name
&& *p
>= '0' && *p
<= '9');
814 l1
+= e
->type
->maxval
- 6;
816 l2
+= e
->type
->maxval
- 6;
817 fprintf (outfile
, "e%s_%lld,e%s_%lld", p
, l1
, p
, l2
);
821 p
= strchr (e
->type
->name
, '\0');
822 while (--p
>= e
->type
->name
&& *p
>= '0' && *p
<= '9');
826 fprintf (outfile
, "e%s_%s%lld,e%s_%s%lld",
827 p
, l1
< 3 ? "m" : "",
828 l1
== 3 ? 0LL : e
->type
->maxval
- (l1
& 3),
829 p
, l2
< 3 ? "m" : "",
830 l2
== 3 ? 0LL : e
->type
->maxval
- (l2
& 3));
835 fprintf (outfile
, "(%s)&intarray[%lld],(%s)&intarray[%lld]",
836 e
->type
->name
, l1
, e
->type
->name
, l2
);
841 fprintf (outfile
, "fn%lld,fn%lld", l1
, l2
);
846 fputs (")", outfile
);
850 subvalues (struct entry
*e
, char *p
, char *letter
)
854 if (p
>= namebuf
+ sizeof (namebuf
) - 32)
861 case ETYPE_STRUCT_ARRAY
:
862 case ETYPE_UNION_ARRAY
:
863 if (e
[0].arr_len
== 0 || e
[0].arr_len
== 255)
865 *letter
+= 1 + e
[0].len
;
868 i
= generate_random () % e
[0].arr_len
;
869 snprintf (p
, sizeof (namebuf
) - (p
- namebuf
) - 1,
870 "%c[%d]", *letter
, i
);
871 q
= strchr (p
, '\0');
877 for (i
= 1; i
<= e
[0].len
; )
879 i
+= subvalues (e
+ i
, q
, letter
);
880 if (e
[0].etype
== ETYPE_UNION
|| e
[0].etype
== ETYPE_UNION_ARRAY
)
882 *letter
+= e
[0].len
- i
+ 1;
892 if (e
[0].arr_len
== 0 || e
[0].arr_len
== 255)
897 i
= generate_random () % e
[0].arr_len
;
898 snprintf (p
, sizeof (namebuf
) - (p
- namebuf
),
899 "%c[%d]", *letter
, i
);
901 if ((generate_random () & 7) == 0)
903 j
= generate_random () % e
[0].arr_len
;
906 snprintf (p
, sizeof (namebuf
) - (p
- namebuf
),
907 "%c[%d]", *letter
, j
);
922 --------------------------------------------------------------------
923 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
924 hash(), hash2(), hash3, and mix() are externally useful functions.
925 Routines to test the hash are included if SELF_TEST is defined.
926 You can use this free for any purpose. It has no warranty.
927 --------------------------------------------------------------------
931 --------------------------------------------------------------------
932 mix -- mix 3 32-bit values reversibly.
933 For every delta with one or two bit set, and the deltas of all three
934 high bits or all three low bits, whether the original value of a,b,c
935 is almost all zero or is uniformly distributed,
936 * If mix() is run forward or backward, at least 32 bits in a,b,c
937 have at least 1/4 probability of changing.
938 * If mix() is run forward, every bit of c will change between 1/3 and
939 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
940 mix() was built out of 36 single-cycle latency instructions in a
941 structure that could supported 2x parallelism, like so:
949 Unfortunately, superscalar Pentiums and Sparcs can't take advantage
950 of that parallelism. They've also turned some of those single-cycle
951 latency instructions into multi-cycle latency instructions. Still,
952 this is the fastest good hash I could find. There were about 2^^68
953 to choose from. I only looked at a billion or so.
954 --------------------------------------------------------------------
956 /* same, but slower, works on systems that might have 8 byte hashval_t's */
959 a -= b; a -= c; a ^= (c>>13); \
960 b -= c; b -= a; b ^= (a<< 8); \
961 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
962 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
963 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
964 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
965 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
966 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
967 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
971 --------------------------------------------------------------------
972 hash() -- hash a variable-length key into a 32-bit value
973 k : the key (the unaligned variable-length array of bytes)
974 len : the length of the key, counting by bytes
975 level : can be any 4-byte value
976 Returns a 32-bit value. Every bit of the key affects every bit of
977 the return value. Every 1-bit and 2-bit delta achieves avalanche.
978 About 36+6len instructions.
980 The best hash table sizes are powers of 2. There is no need to do
981 mod a prime (mod is sooo slow!). If you need less than 32 bits,
982 use a bitmask. For example, if you need only 10 bits, do
983 h = (h & hashmask(10));
984 In which case, the hash table should have hashsize(10) elements.
986 If you are hashing n strings (ub1 **)k, do it like this:
987 for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
989 By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
990 code any way you wish, private, educational, or commercial. It's free.
992 See http://burtleburtle.net/bob/hash/evahash.html
993 Use for hash table lookup, or anything where one collision in 2^32 is
994 acceptable. Do NOT use for cryptographic purposes.
995 --------------------------------------------------------------------
999 iterative_hash (const void *k_in
/* the key */,
1000 register size_t length
/* the length of the key */,
1001 register hashval_t initval
/* the previous hash, or
1002 an arbitrary value */)
1004 register const unsigned char *k
= (const unsigned char *)k_in
;
1005 register hashval_t a
,b
,c
,len
;
1007 /* Set up the internal state */
1009 a
= b
= 0x9e3779b9; /* the golden ratio; an arbitrary value */
1010 c
= initval
; /* the previous hash value */
1012 /*---------------------------------------- handle most of the key */
1015 a
+= (k
[0] +((hashval_t
)k
[1]<<8) +((hashval_t
)k
[2]<<16) +((hashval_t
)k
[3]<<24));
1016 b
+= (k
[4] +((hashval_t
)k
[5]<<8) +((hashval_t
)k
[6]<<16) +((hashval_t
)k
[7]<<24));
1017 c
+= (k
[8] +((hashval_t
)k
[9]<<8) +((hashval_t
)k
[10]<<16)+((hashval_t
)k
[11]<<24));
1022 /*------------------------------------- handle the last 11 bytes */
1024 switch(len
) /* all the case statements fall through */
1026 case 11: c
+=((hashval_t
)k
[10]<<24);
1027 case 10: c
+=((hashval_t
)k
[9]<<16);
1028 case 9 : c
+=((hashval_t
)k
[8]<<8);
1029 /* the first byte of c is reserved for the length */
1030 case 8 : b
+=((hashval_t
)k
[7]<<24);
1031 case 7 : b
+=((hashval_t
)k
[6]<<16);
1032 case 6 : b
+=((hashval_t
)k
[5]<<8);
1034 case 4 : a
+=((hashval_t
)k
[3]<<24);
1035 case 3 : a
+=((hashval_t
)k
[2]<<16);
1036 case 2 : a
+=((hashval_t
)k
[1]<<8);
1038 /* case 0: nothing left to add */
1041 /*-------------------------------------------- report the result */
1046 e_hash (const void *a
)
1048 const struct entry
*e
= a
;
1052 if (e
[0].etype
!= ETYPE_STRUCT
&& e
[0].etype
!= ETYPE_UNION
)
1054 for (i
= 0; i
<= e
[0].len
; ++i
)
1057 ret
= iterative_hash (&e
[i
], offsetof (struct entry
, attrib
), ret
);
1058 attriblen
= e
[i
].attrib
? strlen (e
[i
].attrib
) : -1;
1059 ret
= iterative_hash (&attriblen
, sizeof (int), ret
);
1061 ret
= iterative_hash (e
[i
].attrib
, attriblen
, ret
);
1067 e_eq (const void *a
, const void *b
)
1069 const struct entry
*ea
= a
, *eb
= b
;
1071 if (ea
[0].etype
!= ETYPE_STRUCT
&& ea
[0].etype
!= ETYPE_UNION
)
1073 if (ea
[0].len
!= eb
[0].len
)
1075 for (i
= 0; i
<= ea
[0].len
; ++i
)
1077 if (ea
[i
].etype
!= eb
[i
].etype
1078 || ea
[i
].len
!= eb
[i
].len
1079 || ea
[i
].arr_len
!= eb
[i
].arr_len
1080 || ea
[i
].type
!= eb
[i
].type
)
1082 if ((ea
[i
].attrib
== NULL
) ^ (eb
[i
].attrib
== NULL
))
1084 if (ea
[i
].attrib
&& strcmp (ea
[i
].attrib
, eb
[i
].attrib
) != 0)
1091 e_exists (const struct entry
*e
)
1097 for (h
= hash_table
[hval
% HASH_SIZE
]; h
; h
= h
->next
)
1104 e_insert (struct entry
*e
)
1109 e
->next
= hash_table
[hval
% HASH_SIZE
];
1110 hash_table
[hval
% HASH_SIZE
] = e
;
1114 output (struct entry
*e
)
1120 if (e
[0].etype
!= ETYPE_STRUCT
&& e
[0].etype
!= ETYPE_UNION
)
1126 n
= (struct entry
*) malloc ((e
[0].len
+ 1) * sizeof (struct entry
));
1127 memcpy (n
, e
, (e
[0].len
+ 1) * sizeof (struct entry
));
1131 switchfiles (e
[0].len
);
1133 if (e
[0].etype
== ETYPE_STRUCT
)
1134 fprintf (outfile
, "T(%d,", idx
);
1136 fprintf (outfile
, "U(%d,", idx
);
1138 for (i
= 1; i
<= e
[0].len
; )
1139 i
+= subfield (e
+ i
, &c
);
1140 fputs (",", outfile
);
1142 for (i
= 1; i
<= e
[0].len
; )
1144 i
+= subvalues (e
+ i
, namebuf
, &c
);
1145 if (e
[0].etype
== ETYPE_UNION
)
1148 fputs (")\n", outfile
);
1149 if (output_one
&& idx
== limidx
)
1157 FEATURE_ALIGNEDPACKED
= 2,
1158 FEATURE_ZEROARRAY
= 4,
1159 FEATURE_ZEROBITFLD
= 8,
1160 ALL_FEATURES
= FEATURE_VECTOR
| FEATURE_ZEROARRAY
1161 | FEATURE_ALIGNEDPACKED
| FEATURE_ZEROBITFLD
1165 singles (enum FEATURE features
)
1169 memset (e
, 0, sizeof (e
));
1170 e
[0].etype
= ETYPE_STRUCT
;
1172 e
[0].etype
= ETYPE_UNION
;
1175 for (i
= 0; i
< NTYPES2
; ++i
)
1177 e
[0].etype
= ETYPE_STRUCT
;
1178 e
[1].etype
= ETYPE_TYPE
;
1179 e
[1].type
= &base_types
[i
];
1181 e
[0].etype
= ETYPE_UNION
;
1184 if (features
& FEATURE_VECTOR
)
1185 for (i
= 0; i
< NVTYPES2
; ++i
)
1187 e
[0].etype
= ETYPE_STRUCT
;
1188 e
[1].etype
= ETYPE_TYPE
;
1189 e
[1].type
= &vector_types
[i
];
1191 e
[0].etype
= ETYPE_UNION
;
1197 choose_type (enum FEATURE features
, struct entry
*e
, int r
, int in_array
)
1201 i
= NTYPES2
- NTYPES1
;
1202 if (features
& FEATURE_VECTOR
)
1213 if (r
< NTYPES2
- NTYPES1
)
1214 e
->type
= &base_types
[r
+ NTYPES1
];
1215 r
-= NTYPES2
- NTYPES1
;
1216 if (e
->type
== NULL
&& (features
& FEATURE_VECTOR
))
1219 e
->type
= &vector_types
[r
];
1222 if (e
->type
== NULL
&& !in_array
)
1225 e
->type
= &attrib_types
[r
];
1228 if (e
->type
== NULL
&& in_array
)
1231 e
->type
= &attrib_array_types
[r
];
1234 if (e
->type
== NULL
)
1238 /* This is from gcc.c-torture/execute/builtin-bitops-1.c. */
1240 my_ffsll (unsigned long long x
)
1245 /* We've tested LLONG_MAX for 64 bits so this should be safe. */
1246 for (i
= 0; i
< 64; i
++)
1247 if (x
& (1ULL << i
))
1253 generate_fields (enum FEATURE features
, struct entry
*e
, struct entry
*parent
,
1256 int r
, i
, j
, ret
= 1, n
, incr
, sametype
;
1258 for (n
= 0; n
< len
; n
+= incr
)
1260 r
= generate_random ();
1261 /* 50% ETYPE_TYPE base_types NTYPES1
1262 12.5% ETYPE_TYPE other
1265 12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1275 e
[n
].etype
= ETYPE_TYPE
;
1276 e
[n
].type
= &base_types
[r
% NTYPES1
];
1279 e
[n
].etype
= ETYPE_TYPE
;
1280 choose_type (features
, &e
[n
], r
, 0);
1283 e
[n
].etype
= ETYPE_ARRAY
;
1287 e
[n
].type
= &base_types
[r
% NTYPES1
];
1289 choose_type (features
, &e
[n
], r
, 1);
1290 r
= generate_random ();
1291 if ((features
& FEATURE_ZEROARRAY
) && (r
& 3) == 0)
1294 if (n
== len
- 1 && (r
& 4)
1295 && (parent
->etype
== ETYPE_STRUCT
1296 || parent
->etype
== ETYPE_STRUCT_ARRAY
))
1299 for (k
= 0; k
< n
; ++k
)
1300 if (e
[k
].etype
!= ETYPE_BITFLD
|| e
[k
].len
)
1307 else if ((r
& 3) != 3)
1308 e
[n
].arr_len
= (r
>> 2) & 7;
1310 e
[n
].arr_len
= (r
>> 2) & 31;
1323 incr
= 1 + (r
>> 3) % (len
- n
);
1328 incr
= 1 + (r
>> 3) % (len
- n
);
1331 for (j
= n
; j
< n
+ incr
; ++j
)
1335 e
[j
].etype
= ETYPE_BITFLD
;
1336 if (j
== n
|| !sametype
)
1339 r
= generate_random ();
1344 = &aligned_bitfld_types
[r
% n_aligned_bitfld_types
];
1347 = &bitfld_types
[r
% n_bitfld_types
];
1350 e
[j
].type
= e
[n
].type
;
1351 r
= generate_random ();
1354 switch (e
[j
].type
->bitfld
)
1356 case 'C': ma
= 8; break;
1357 case 'S': ma
= 16; break;
1358 case 'I': ma
= 32; break;
1360 case 'Q': ma
= 64; break;
1361 case 'B': ma
= 1; break;
1363 if (e
[j
].type
->type
== TYPE_UENUM
)
1364 mi
= my_ffsll (e
[j
].type
->maxval
+ 1) - 1;
1365 else if (e
[j
].type
->type
== TYPE_SENUM
)
1366 mi
= my_ffsll (e
[j
].type
->maxval
+ 1);
1373 else if (mi
> 16 || !short_enums
)
1384 if (sametype
&& (r
& 3) == 0 && ma
> 1)
1387 for (k
= n
; k
< j
; ++k
)
1390 e
[j
].len
= sum
? ma
- sum
: ma
;
1393 if (!sametype
&& (r
& 7) == 0)
1396 if (! (features
& FEATURE_ZEROBITFLD
) && mi
== 0)
1398 if (e
[j
].len
< mi
|| e
[j
].len
> ma
)
1399 e
[j
].len
= mi
+ (r
% (ma
+ 1 - mi
));
1401 if ((features
& FEATURE_ZEROBITFLD
) && (r
& 3) == 0
1412 e
[n
].etype
= ETYPE_STRUCT
;
1416 e
[n
].etype
= ETYPE_UNION
;
1420 e
[n
].etype
= ETYPE_STRUCT_ARRAY
;
1423 e
[n
].etype
= ETYPE_UNION_ARRAY
;
1427 e
[n
].len
= r
% (len
- n
);
1428 incr
= 1 + e
[n
].len
;
1429 generate_fields (features
, &e
[n
+ 1], &e
[n
], e
[n
].len
);
1430 if (e
[n
].etype
== ETYPE_STRUCT_ARRAY
1431 || e
[n
].etype
== ETYPE_UNION_ARRAY
)
1433 r
= generate_random ();
1434 if ((features
& FEATURE_ZEROARRAY
) && (r
& 3) == 0)
1437 if (n
+ incr
== len
&& (r
& 4)
1438 && (parent
->etype
== ETYPE_STRUCT
1439 || parent
->etype
== ETYPE_STRUCT_ARRAY
))
1442 for (k
= 0; k
< n
; ++k
)
1443 if (e
[k
].etype
!= ETYPE_BITFLD
|| e
[k
].len
)
1450 else if ((r
& 3) != 3)
1451 e
[n
].arr_len
= (r
>> 2) & 7;
1453 e
[n
].arr_len
= (r
>> 2) & 31;
1457 r
= generate_random ();
1461 i
= (features
& FEATURE_ALIGNEDPACKED
) ? NATTRIBS2
: NATTRIBS1
;
1462 e
[n
].attrib
= attributes
[r
% i
];
1463 if (! (features
& FEATURE_ALIGNEDPACKED
)
1464 && strcmp (e
[n
].attrib
, "atpa") == 0
1465 && ((e
[n
].type
>= &attrib_types
[0]
1466 && e
[n
].type
< &attrib_types
[NATYPES2
])
1467 || (e
[n
].type
>= &attrib_array_types
[0]
1468 && e
[n
].type
< &attrib_array_types
[NAATYPES2
])
1469 || (e
[n
].type
>= &aligned_bitfld_types
[0]
1470 && e
[n
].type
< &aligned_bitfld_types
[n_aligned_bitfld_types
])))
1477 generate_random_tests (enum FEATURE features
, int len
)
1479 struct entry e
[len
+ 1];
1481 if (len
> 'z' - 'a' + 1)
1483 memset (e
, 0, sizeof (e
));
1484 r
= generate_random ();
1486 e
[0].etype
= ETYPE_UNION
;
1488 e
[0].etype
= ETYPE_STRUCT
;
1491 generate_fields (features
, &e
[1], &e
[0], len
);
1495 struct { const char *name
; enum FEATURE f
; }
1498 { "vector", FEATURE_VECTOR
},
1499 { "[0] :0", FEATURE_ZEROARRAY
| FEATURE_ZEROBITFLD
},
1501 FEATURE_VECTOR
| FEATURE_ZEROARRAY
},
1502 { "aligned packed vector [0] :0",
1503 FEATURE_VECTOR
| FEATURE_ZEROARRAY
1504 | FEATURE_ALIGNEDPACKED
| FEATURE_ZEROBITFLD
},
1508 main (int argc
, char **argv
)
1510 int i
, j
, count
, c
, n
= 3000;
1513 if (sizeof (int) != 4 || sizeof (long long) != 8)
1520 if (argv
[i
][0] == '-' && argv
[i
][2] == '\0')
1522 optarg
= argv
[i
+ 1];
1538 limidx
= atoi (optarg
);
1545 fprintf (stderr
, "unrecognized option %s\n", argv
[i
]);
1553 outfile
= fopen ("/dev/null", "w");
1554 if (outfile
== NULL
)
1556 fputs ("could not open /dev/null", stderr
);
1562 if (destdir
== NULL
&& !output_one
)
1565 fprintf (stderr
, "Usage:\n\
1566 %s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\
1567 Either -s srcdir -d destdir or -i idx must be used\n", argv
[0]);
1571 if (srcdir
== NULL
&& !output_one
)
1574 for (i
= 0; i
< NTYPES2
; ++i
)
1575 if (base_types
[i
].bitfld
)
1576 bitfld_types
[n_bitfld_types
++] = base_types
[i
];
1577 for (i
= 0; i
< NATYPES2
; ++i
)
1578 if (attrib_types
[i
].bitfld
)
1579 aligned_bitfld_types
[n_aligned_bitfld_types
++] = attrib_types
[i
];
1580 for (i
= 0; i
< sizeof (features
) / sizeof (features
[0]); ++i
)
1589 for (j
= 1; j
<= 9; ++j
)
1590 while (idx
< startidx
+ j
* count
)
1591 generate_random_tests (features
[i
].f
, j
);
1592 while (idx
< startidx
+ count
* 10)
1593 generate_random_tests (features
[i
].f
, 10 + (generate_random () % 16));
1595 for (i
= 0; n
> 3000 && i
< sizeof (features
) / sizeof (features
[0]); ++i
)
1601 singles (features
[i
].f
);
1605 while (idx
< startidx
+ 1000)
1606 generate_random_tests (features
[i
].f
, 1);
1612 while (idx
< startidx
+ 100)
1613 generate_random_tests (features
[i
].f
, 1);
1616 for (j
= 2; j
<= 9; ++j
)
1617 while (idx
< startidx
+ (j
- 1) * count
)
1618 generate_random_tests (features
[i
].f
, j
);
1619 while (idx
< startidx
+ count
* 9)
1620 generate_random_tests (features
[i
].f
, 10 + (generate_random () % 16));
1625 generate_random_tests (ALL_FEATURES
, 1 + (generate_random () % 25));