Bug Summary

File:build/gcc/vec.h
Warning:line 815, column 10
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name godump.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D IN_GCC -D HAVE_CONFIG_H -I . -I . -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/. -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcpp/include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcody -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber/bid -I ../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libbacktrace -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/x86_64-suse-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-narrowing -Wwrite-strings -Wno-error=format-diag -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fdeprecated-macro -fdebug-compilation-dir /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=plist-html -analyzer-config silence-checkers=core.NullDereference -faddrsig -o /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/clang-static-analyzer/2021-01-16-135054-17580-1/report-Bi0uk2.plist -x c++ /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c

/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c

1/* Output Go language descriptions of types.
2 Copyright (C) 2008-2021 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <iant@google.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21/* This file is used during the build process to emit Go language
22 descriptions of declarations from C header files. It uses the
23 debug info hooks to emit the descriptions. The Go language
24 descriptions then become part of the Go runtime support
25 library.
26
27 All global names are output with a leading underscore, so that they
28 are all hidden in Go. */
29
30#include "config.h"
31#include "system.h"
32#include "coretypes.h"
33#include "tree.h"
34#include "diagnostic-core.h"
35#include "debug.h"
36#include "stor-layout.h"
37
38/* We dump this information from the debug hooks. This gives us a
39 stable and maintainable API to hook into. In order to work
40 correctly when -g is used, we build our own hooks structure which
41 wraps the hooks we need to change. */
42
43/* Our debug hooks. This is initialized by dump_go_spec_init. */
44
45static struct gcc_debug_hooks go_debug_hooks;
46
47/* The real debug hooks. */
48
49static const struct gcc_debug_hooks *real_debug_hooks;
50
51/* The file where we should write information. */
52
53static FILE *go_dump_file;
54
55/* A queue of decls to output. */
56
57static GTY(()) vec<tree, va_gc> *queue;
58
59/* A hash table of macros we have seen. */
60
61static htab_t macro_hash;
62
63/* The type of a value in macro_hash. */
64
65struct macro_hash_value
66{
67 /* The name stored in the hash table. */
68 char *name;
69 /* The value of the macro. */
70 char *value;
71};
72
73/* Returns the number of units necessary to represent an integer with the given
74 PRECISION (in bits). */
75
76static inline unsigned int
77precision_to_units (unsigned int precision)
78{
79 return (precision + BITS_PER_UNIT(8) - 1) / BITS_PER_UNIT(8);
80}
81
82/* Calculate the hash value for an entry in the macro hash table. */
83
84static hashval_t
85macro_hash_hashval (const void *val)
86{
87 const struct macro_hash_value *mhval = (const struct macro_hash_value *) val;
88 return htab_hash_string (mhval->name);
89}
90
91/* Compare values in the macro hash table for equality. */
92
93static int
94macro_hash_eq (const void *v1, const void *v2)
95{
96 const struct macro_hash_value *mhv1 = (const struct macro_hash_value *) v1;
97 const struct macro_hash_value *mhv2 = (const struct macro_hash_value *) v2;
98 return strcmp (mhv1->name, mhv2->name) == 0;
99}
100
101/* Free values deleted from the macro hash table. */
102
103static void
104macro_hash_del (void *v)
105{
106 struct macro_hash_value *mhv = (struct macro_hash_value *) v;
107 XDELETEVEC (mhv->name)free ((void*) (mhv->name));
108 XDELETEVEC (mhv->value)free ((void*) (mhv->value));
109 XDELETE (mhv)free ((void*) (mhv));
110}
111
112/* For the string hash tables. */
113
114static int
115string_hash_eq (const void *y1, const void *y2)
116{
117 return strcmp ((const char *) y1, (const char *) y2) == 0;
118}
119
120/* A macro definition. */
121
122static void
123go_define (unsigned int lineno, const char *buffer)
124{
125 const char *p;
126 const char *name_end;
127 size_t out_len;
128 char *out_buffer;
129 char *q;
130 bool saw_operand;
131 bool need_operand;
132 struct macro_hash_value *mhval;
133 char *copy;
134 hashval_t hashval;
135 void **slot;
136
137 real_debug_hooks->define (lineno, buffer);
138
139 /* Skip macro functions. */
140 for (p = buffer; *p != '\0' && *p != ' '; ++p)
141 if (*p == '(')
142 return;
143
144 if (*p == '\0')
145 return;
146
147 name_end = p;
148
149 ++p;
150 if (*p == '\0')
151 return;
152
153 copy = XNEWVEC (char, name_end - buffer + 1)((char *) xmalloc (sizeof (char) * (name_end - buffer + 1)));
154 memcpy (copy, buffer, name_end - buffer);
155 copy[name_end - buffer] = '\0';
156
157 mhval = XNEW (struct macro_hash_value)((struct macro_hash_value *) xmalloc (sizeof (struct macro_hash_value
)))
;
158 mhval->name = copy;
159 mhval->value = NULLnullptr;
160
161 hashval = htab_hash_string (copy);
162 slot = htab_find_slot_with_hash (macro_hash, mhval, hashval, NO_INSERT);
163
164 /* For simplicity, we force all names to be hidden by adding an
165 initial underscore, and let the user undo this as needed. */
166 out_len = strlen (p) * 2 + 1;
167 out_buffer = XNEWVEC (char, out_len)((char *) xmalloc (sizeof (char) * (out_len)));
168 q = out_buffer;
169 saw_operand = false;
170 need_operand = false;
171 while (*p != '\0')
172 {
173 switch (*p)
174 {
175 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
176 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
177 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
178 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
179 case 'Y': case 'Z':
180 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
181 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
182 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
183 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
184 case 'y': case 'z':
185 case '_':
186 {
187 /* The start of an identifier. Technically we should also
188 worry about UTF-8 identifiers, but they are not a
189 problem for practical uses of -fdump-go-spec so we
190 don't worry about them. */
191 const char *start;
192 char *n;
193 struct macro_hash_value idval;
194
195 if (saw_operand)
196 goto unknown;
197
198 start = p;
199 while (ISALNUM (*p)(_sch_istable[(*p) & 0xff] & (unsigned short)(_sch_isalnum
))
|| *p == '_')
200 ++p;
201 n = XALLOCAVEC (char, p - start + 1)((char *) __builtin_alloca(sizeof (char) * (p - start + 1)));
202 memcpy (n, start, p - start);
203 n[p - start] = '\0';
204 idval.name = n;
205 idval.value = NULLnullptr;
206 if (htab_find (macro_hash, &idval) == NULLnullptr)
207 {
208 /* This is a reference to a name which was not defined
209 as a macro. */
210 goto unknown;
211 }
212
213 *q++ = '_';
214 memcpy (q, start, p - start);
215 q += p - start;
216
217 saw_operand = true;
218 need_operand = false;
219 }
220 break;
221
222 case '.':
223 if (!ISDIGIT (p[1])(_sch_istable[(p[1]) & 0xff] & (unsigned short)(_sch_isdigit
))
)
224 goto unknown;
225 /* Fall through. */
226 case '0': case '1': case '2': case '3': case '4':
227 case '5': case '6': case '7': case '8': case '9':
228 {
229 const char *start;
230 bool is_hex;
231
232 start = p;
233 is_hex = false;
234 if (*p == '0' && (p[1] == 'x' || p[1] == 'X'))
235 {
236 p += 2;
237 is_hex = true;
238 }
239 while (ISDIGIT (*p)(_sch_istable[(*p) & 0xff] & (unsigned short)(_sch_isdigit
))
|| *p == '.' || *p == 'e' || *p == 'E'
240 || (is_hex
241 && ((*p >= 'a' && *p <= 'f')
242 || (*p >= 'A' && *p <= 'F'))))
243 ++p;
244 memcpy (q, start, p - start);
245 q += p - start;
246 while (*p == 'u' || *p == 'U' || *p == 'l' || *p == 'L'
247 || *p == 'f' || *p == 'F'
248 || *p == 'd' || *p == 'D')
249 {
250 /* Go doesn't use any of these trailing type
251 modifiers. */
252 ++p;
253 }
254
255 /* We'll pick up the exponent, if any, as an
256 expression. */
257
258 saw_operand = true;
259 need_operand = false;
260 }
261 break;
262
263 case ' ': case '\t':
264 *q++ = *p++;
265 break;
266
267 case '(':
268 /* Always OK, not part of an operand, presumed to start an
269 operand. */
270 *q++ = *p++;
271 saw_operand = false;
272 need_operand = false;
273 break;
274
275 case ')':
276 /* OK if we don't need an operand, and presumed to indicate
277 an operand. */
278 if (need_operand)
279 goto unknown;
280 *q++ = *p++;
281 saw_operand = true;
282 break;
283
284 case '+': case '-':
285 /* Always OK, but not part of an operand. */
286 *q++ = *p++;
287 saw_operand = false;
288 break;
289
290 case '*': case '/': case '%': case '|': case '&': case '^':
291 /* Must be a binary operator. */
292 if (!saw_operand)
293 goto unknown;
294 *q++ = *p++;
295 saw_operand = false;
296 need_operand = true;
297 break;
298
299 case '=':
300 *q++ = *p++;
301 if (*p != '=')
302 goto unknown;
303 /* Must be a binary operator. */
304 if (!saw_operand)
305 goto unknown;
306 *q++ = *p++;
307 saw_operand = false;
308 need_operand = true;
309 break;
310
311 case '!':
312 *q++ = *p++;
313 if (*p == '=')
314 {
315 /* Must be a binary operator. */
316 if (!saw_operand)
317 goto unknown;
318 *q++ = *p++;
319 saw_operand = false;
320 need_operand = true;
321 }
322 else
323 {
324 /* Must be a unary operator. */
325 if (saw_operand)
326 goto unknown;
327 need_operand = true;
328 }
329 break;
330
331 case '<': case '>':
332 /* Must be a binary operand, may be << or >> or <= or >=. */
333 if (!saw_operand)
334 goto unknown;
335 *q++ = *p++;
336 if (*p == *(p - 1) || *p == '=')
337 *q++ = *p++;
338 saw_operand = false;
339 need_operand = true;
340 break;
341
342 case '~':
343 /* Must be a unary operand, must be translated for Go. */
344 if (saw_operand)
345 goto unknown;
346 *q++ = '^';
347 p++;
348 need_operand = true;
349 break;
350
351 case '"':
352 case '\'':
353 {
354 char quote;
355 int count;
356
357 if (saw_operand)
358 goto unknown;
359 quote = *p;
360 *q++ = *p++;
361 count = 0;
362 while (*p != quote)
363 {
364 int c;
365
366 if (*p == '\0')
367 goto unknown;
368
369 ++count;
370
371 if (*p != '\\')
372 {
373 *q++ = *p++;
374 continue;
375 }
376
377 *q++ = *p++;
378 switch (*p)
379 {
380 case '0': case '1': case '2': case '3':
381 case '4': case '5': case '6': case '7':
382 c = 0;
383 while (*p >= '0' && *p <= '7')
384 {
385 *q++ = *p++;
386 ++c;
387 }
388 /* Go octal characters are always 3
389 digits. */
390 if (c != 3)
391 goto unknown;
392 break;
393
394 case 'x':
395 *q++ = *p++;
396 c = 0;
397 while (ISXDIGIT (*p)(_sch_istable[(*p) & 0xff] & (unsigned short)(_sch_isxdigit
))
)
398 {
399 *q++ = *p++;
400 ++c;
401 }
402 /* Go hex characters are always 2 digits. */
403 if (c != 2)
404 goto unknown;
405 break;
406
407 case 'a': case 'b': case 'f': case 'n': case 'r':
408 case 't': case 'v': case '\\': case '\'': case '"':
409 *q++ = *p++;
410 break;
411
412 default:
413 goto unknown;
414 }
415 }
416
417 *q++ = *p++;
418
419 if (quote == '\'' && count != 1)
420 goto unknown;
421
422 saw_operand = true;
423 need_operand = false;
424
425 break;
426 }
427
428 default:
429 goto unknown;
430 }
431 }
432
433 if (need_operand)
434 goto unknown;
435
436 gcc_assert ((size_t) (q - out_buffer) < out_len)((void)(!((size_t) (q - out_buffer) < out_len) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 436, __FUNCTION__), 0 : 0))
;
437 *q = '\0';
438
439 mhval->value = out_buffer;
440
441 if (slot == NULLnullptr)
442 {
443 slot = htab_find_slot_with_hash (macro_hash, mhval, hashval, INSERT);
444 gcc_assert (slot != NULL && *slot == NULL)((void)(!(slot != nullptr && *slot == nullptr) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 444, __FUNCTION__), 0 : 0))
;
445 }
446 else
447 {
448 if (*slot != NULLnullptr)
449 macro_hash_del (*slot);
450 }
451
452 *slot = mhval;
453
454 return;
455
456 unknown:
457 fprintf (go_dump_file, "// unknowndefine %s\n", buffer);
458 if (slot != NULLnullptr)
459 htab_clear_slot (macro_hash, slot);
460 XDELETEVEC (out_buffer)free ((void*) (out_buffer));
461 XDELETEVEC (copy)free ((void*) (copy));
462}
463
464/* A macro undef. */
465
466static void
467go_undef (unsigned int lineno, const char *buffer)
468{
469 struct macro_hash_value mhval;
470 void **slot;
471
472 real_debug_hooks->undef (lineno, buffer);
473
474 mhval.name = CONST_CAST (char *, buffer)(const_cast<char *> ((buffer)));
475 mhval.value = NULLnullptr;
476 slot = htab_find_slot (macro_hash, &mhval, NO_INSERT);
477 if (slot != NULLnullptr)
478 htab_clear_slot (macro_hash, slot);
479}
480
481/* A function or variable decl. */
482
483static void
484go_decl (tree decl)
485{
486 if (!TREE_PUBLIC (decl)((decl)->base.public_flag)
487 || DECL_IS_UNDECLARED_BUILTIN (decl)(((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 487, __FUNCTION__))->decl_minimal.locus) <= ((location_t
) 1))
488 || DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 488, __FUNCTION__))->decl_minimal.name)
== NULL_TREE(tree) nullptr)
489 return;
490 vec_safe_push (queue, decl);
491}
492
493/* A function decl. */
494
495static void
496go_function_decl (tree decl)
497{
498 real_debug_hooks->function_decl (decl);
499 go_decl (decl);
500}
501
502static void
503go_early_global_decl (tree decl)
504{
505 go_decl (decl);
506 if (TREE_CODE (decl)((enum tree_code) (decl)->base.code) != FUNCTION_DECL || DECL_STRUCT_FUNCTION (decl)((tree_check ((decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 506, __FUNCTION__, (FUNCTION_DECL)))->function_decl.f)
!= NULLnullptr)
507 real_debug_hooks->early_global_decl (decl);
508}
509
510/* A global variable decl. */
511
512static void
513go_late_global_decl (tree decl)
514{
515 real_debug_hooks->late_global_decl (decl);
516}
517
518/* A type declaration. */
519
520static void
521go_type_decl (tree decl, int local)
522{
523 real_debug_hooks->type_decl (decl, local);
1
Value assigned to 'queue'
524
525 if (local || DECL_IS_UNDECLARED_BUILTIN (decl)(((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 525, __FUNCTION__))->decl_minimal.locus) <= ((location_t
) 1))
)
2
Assuming 'local' is 0
3
Assuming field 'locus' is > 1
4
Taking false branch
526 return;
527 if (DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 527, __FUNCTION__))->decl_minimal.name)
== NULL_TREE(tree) nullptr
5
Assuming the condition is false
528 && (TYPE_NAME (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 528, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 528, __FUNCTION__))->type_common.name)
== NULL_TREE(tree) nullptr
529 || TREE_CODE (TYPE_NAME (TREE_TYPE (decl)))((enum tree_code) (((tree_class_check ((((contains_struct_check
((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 529, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 529, __FUNCTION__))->type_common.name))->base.code)
!= IDENTIFIER_NODE)
530 && TREE_CODE (TREE_TYPE (decl))((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 530, __FUNCTION__))->typed.type))->base.code)
!= ENUMERAL_TYPE)
531 return;
532 vec_safe_push (queue, decl);
6
Passing value via 1st parameter 'v'
7
Calling 'vec_safe_push<tree_node *, va_gc>'
533}
534
535/* A container for the data we pass around when generating information
536 at the end of the compilation. */
537
538class godump_container
539{
540public:
541 /* DECLs that we have already seen. */
542 hash_set<tree> decls_seen;
543
544 /* Types which may potentially have to be defined as dummy
545 types. */
546 hash_set<const char *> pot_dummy_types;
547
548 /* Go keywords. */
549 htab_t keyword_hash;
550
551 /* Global type definitions. */
552 htab_t type_hash;
553
554 /* Invalid types. */
555 htab_t invalid_hash;
556
557 /* Obstack used to write out a type definition. */
558 struct obstack type_obstack;
559};
560
561/* Append an IDENTIFIER_NODE to OB. */
562
563static void
564go_append_string (struct obstack *ob, tree id)
565{
566 obstack_grow (ob, IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
((tree_check ((id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 566, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len
)); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, (
(const char *) (tree_check ((id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 566, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
), __len); __o->next_free += __len; (void) 0; })
;
567}
568
569/* Given an integer PRECISION in bits, returns a constant string that is the
570 matching go int or uint type (depending on the IS_UNSIGNED flag). Returns a
571 NULL pointer if there is no matching go type. */
572
573static const char *
574go_get_uinttype_for_precision (unsigned int precision, bool is_unsigned)
575{
576 switch (precision)
577 {
578 case 8:
579 return is_unsigned ? "uint8" : "int8";
580 case 16:
581 return is_unsigned ? "uint16" : "int16";
582 case 32:
583 return is_unsigned ? "uint32" : "int32";
584 case 64:
585 return is_unsigned ? "uint64" : "int64";
586 default:
587 return NULLnullptr;
588 }
589}
590
591/* Append an artificial variable name with the suffix _INDEX to OB. Returns
592 INDEX + 1. */
593
594static unsigned int
595go_append_artificial_name (struct obstack *ob, unsigned int index)
596{
597 char buf[100];
598
599 /* FIXME: identifier may not be unique. */
600 obstack_grow (ob, "Godump_", 7)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
7); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "Godump_"
, __len); __o->next_free += __len; (void) 0; })
;
601 snprintf (buf, sizeof buf, "%u", index);
602 obstack_grow (ob, buf, strlen (buf))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (buf)); if (__extension__ ({ struct obstack const *__o1
= (__o); (size_t) (__o1->chunk_limit - __o1->next_free
); }) < __len) _obstack_newchunk (__o, __len); memcpy (__o
->next_free, buf, __len); __o->next_free += __len; (void
) 0; })
;
603
604 return index + 1;
605}
606
607/* Append the variable name from DECL to OB. If the name is in the
608 KEYWORD_HASH, prepend an '_'. */
609
610static void
611go_append_decl_name (struct obstack *ob, tree decl, htab_t keyword_hash)
612{
613 const char *var_name;
614 void **slot;
615
616 /* Start variable name with an underscore if a keyword. */
617 var_name = IDENTIFIER_POINTER (DECL_NAME (decl))((const char *) (tree_check ((((contains_struct_check ((decl)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 617, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 617, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
618 slot = htab_find_slot (keyword_hash, var_name, NO_INSERT);
619 if (slot != NULLnullptr)
620 obstack_1grow (ob, '_')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('_'))); })
;
621 go_append_string (ob, DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 621, __FUNCTION__))->decl_minimal.name)
);
622}
623
624/* Appends a byte array with the necessary number of elements and the name
625 "Godump_INDEX_pad" to pad from FROM_OFFSET to TO_OFFSET to OB assuming that
626 the next field is automatically aligned to ALIGN_UNITS. Returns INDEX + 1,
627 or INDEX if no padding had to be appended. The resulting offset where the
628 next field is allocated is returned through RET_OFFSET. */
629
630static unsigned int
631go_append_padding (struct obstack *ob, unsigned int from_offset,
632 unsigned int to_offset, unsigned int align_units,
633 unsigned int index, unsigned int *ret_offset)
634{
635 if (from_offset % align_units > 0)
636 from_offset += align_units - (from_offset % align_units);
637 gcc_assert (to_offset >= from_offset)((void)(!(to_offset >= from_offset) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 637, __FUNCTION__), 0 : 0))
;
638 if (to_offset > from_offset)
639 {
640 char buf[100];
641
642 index = go_append_artificial_name (ob, index);
643 snprintf (buf, sizeof buf, "_pad [%u]byte; ", to_offset - from_offset);
644 obstack_grow (ob, buf, strlen (buf))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (buf)); if (__extension__ ({ struct obstack const *__o1
= (__o); (size_t) (__o1->chunk_limit - __o1->next_free
); }) < __len) _obstack_newchunk (__o, __len); memcpy (__o
->next_free, buf, __len); __o->next_free += __len; (void
) 0; })
;
645 }
646 *ret_offset = to_offset;
647
648 return index;
649}
650
651/* Appends an array of type TYPE_STRING with zero elements and the name
652 "Godump_INDEX_align" to OB. If TYPE_STRING is a null pointer, ERROR_STRING
653 is appended instead of the type. Returns INDEX + 1. */
654
655static unsigned int
656go_force_record_alignment (struct obstack *ob, const char *type_string,
657 unsigned int index, const char *error_string)
658{
659 index = go_append_artificial_name (ob, index);
660 obstack_grow (ob, "_align ", 7)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
7); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "_align "
, __len); __o->next_free += __len; (void) 0; })
;
661 if (type_string == NULLnullptr)
662 obstack_grow (ob, error_string, strlen (error_string))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (error_string)); if (__extension__ ({ struct obstack const
*__o1 = (__o); (size_t) (__o1->chunk_limit - __o1->next_free
); }) < __len) _obstack_newchunk (__o, __len); memcpy (__o
->next_free, error_string, __len); __o->next_free += __len
; (void) 0; })
;
663 else
664 {
665 obstack_grow (ob, "[0]", 3)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
3); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "[0]"
, __len); __o->next_free += __len; (void) 0; })
;
666 obstack_grow (ob, type_string, strlen (type_string))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (type_string)); if (__extension__ ({ struct obstack const
*__o1 = (__o); (size_t) (__o1->chunk_limit - __o1->next_free
); }) < __len) _obstack_newchunk (__o, __len); memcpy (__o
->next_free, type_string, __len); __o->next_free += __len
; (void) 0; })
;
667 }
668 obstack_grow (ob, "; ", 2)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
2); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "; "
, __len); __o->next_free += __len; (void) 0; })
;
669
670 return index;
671}
672
673/* Write the Go version of TYPE to CONTAINER->TYPE_OBSTACK.
674 USE_TYPE_NAME is true if we can simply use a type name here without
675 needing to define it. IS_FUNC_OK is true if we can output a func
676 type here; the "func" keyword will already have been added.
677 Return true if the type can be represented in Go, false otherwise.
678 P_ART_I is used for indexing artificial elements in nested structures and
679 should always be a NULL pointer when called, except by certain recursive
680 calls from go_format_type() itself. */
681
682static bool
683go_format_type (class godump_container *container, tree type,
684 bool use_type_name, bool is_func_ok, unsigned int *p_art_i,
685 bool is_anon_record_or_union)
686{
687 bool ret;
688 struct obstack *ob;
689 unsigned int art_i_dummy;
690 bool is_union = false;
691
692 if (p_art_i == NULLnullptr)
693 {
694 art_i_dummy = 0;
695 p_art_i = &art_i_dummy;
696 }
697 ret = true;
698 ob = &container->type_obstack;
699
700 if (use_type_name
701 && TYPE_NAME (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 701, __FUNCTION__))->type_common.name)
!= NULL_TREE(tree) nullptr
702 && (AGGREGATE_TYPE_P (type)(((enum tree_code) (type)->base.code) == ARRAY_TYPE || (((
enum tree_code) (type)->base.code) == RECORD_TYPE || ((enum
tree_code) (type)->base.code) == UNION_TYPE || ((enum tree_code
) (type)->base.code) == QUAL_UNION_TYPE))
703 || POINTER_TYPE_P (type)(((enum tree_code) (type)->base.code) == POINTER_TYPE || (
(enum tree_code) (type)->base.code) == REFERENCE_TYPE)
704 || TREE_CODE (type)((enum tree_code) (type)->base.code) == FUNCTION_TYPE))
705 {
706 tree name;
707 void **slot;
708
709 /* References to complex builtin types cannot be translated to
710 Go. */
711 if (DECL_P (TYPE_NAME (type))(tree_code_type[(int) (((enum tree_code) (((tree_class_check (
(type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 711, __FUNCTION__))->type_common.name))->base.code))]
== tcc_declaration)
712 && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type))(((contains_struct_check ((((tree_class_check ((type), (tcc_type
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 712, __FUNCTION__))->type_common.name)), (TS_DECL_MINIMAL
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 712, __FUNCTION__))->decl_minimal.locus) <= ((location_t
) 1))
)
713 ret = false;
714
715 name = TYPE_IDENTIFIER (type)(((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 715, __FUNCTION__))->type_common.name) && (tree_code_type
[(int) (((enum tree_code) (((tree_class_check ((type), (tcc_type
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 715, __FUNCTION__))->type_common.name))->base.code))]
== tcc_declaration) ? ((contains_struct_check ((((tree_class_check
((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 715, __FUNCTION__))->type_common.name)), (TS_DECL_MINIMAL
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 715, __FUNCTION__))->decl_minimal.name) : ((tree_class_check
((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 715, __FUNCTION__))->type_common.name))
;
716
717 slot = htab_find_slot (container->invalid_hash, IDENTIFIER_POINTER (name)((const char *) (tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 717, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
718 NO_INSERT);
719 if (slot != NULLnullptr)
720 ret = false;
721
722 /* References to incomplete structs are permitted in many
723 contexts, like behind a pointer or inside of a typedef. So
724 consider any referenced struct a potential dummy type. */
725 if (RECORD_OR_UNION_TYPE_P (type)(((enum tree_code) (type)->base.code) == RECORD_TYPE || ((
enum tree_code) (type)->base.code) == UNION_TYPE || ((enum
tree_code) (type)->base.code) == QUAL_UNION_TYPE)
)
726 container->pot_dummy_types.add (IDENTIFIER_POINTER (name)((const char *) (tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 726, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
727
728 obstack_1grow (ob, '_')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('_'))); })
;
729 go_append_string (ob, name);
730 return ret;
731 }
732
733 switch (TREE_CODE (type)((enum tree_code) (type)->base.code))
734 {
735 case TYPE_DECL:
736 {
737 void **slot;
738
739 slot = htab_find_slot (container->invalid_hash,
740 IDENTIFIER_POINTER (DECL_NAME (type))((const char *) (tree_check ((((contains_struct_check ((type)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 740, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 740, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
741 NO_INSERT);
742 if (slot != NULLnullptr)
743 ret = false;
744
745 obstack_1grow (ob, '_')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('_'))); })
;
746 go_append_string (ob, DECL_NAME (type)((contains_struct_check ((type), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 746, __FUNCTION__))->decl_minimal.name)
);
747 }
748 break;
749
750 case ENUMERAL_TYPE:
751 case INTEGER_TYPE:
752 {
753 const char *s;
754 char buf[100];
755
756 s = go_get_uinttype_for_precision (TYPE_PRECISION (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 756, __FUNCTION__))->type_common.precision)
,
757 TYPE_UNSIGNED (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 757, __FUNCTION__))->base.u.bits.unsigned_flag)
);
758 if (s == NULLnullptr)
759 {
760 snprintf (buf, sizeof buf, "INVALID-int-%u%s",
761 TYPE_PRECISION (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 761, __FUNCTION__))->type_common.precision)
,
762 TYPE_UNSIGNED (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 762, __FUNCTION__))->base.u.bits.unsigned_flag)
? "u" : "");
763 s = buf;
764 ret = false;
765 }
766 obstack_grow (ob, s, strlen (s))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (s)); if (__extension__ ({ struct obstack const *__o1 =
(__o); (size_t) (__o1->chunk_limit - __o1->next_free);
}) < __len) _obstack_newchunk (__o, __len); memcpy (__o->
next_free, s, __len); __o->next_free += __len; (void) 0; }
)
;
767 }
768 break;
769
770 case REAL_TYPE:
771 {
772 const char *s;
773 char buf[100];
774
775 switch (TYPE_PRECISION (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 775, __FUNCTION__))->type_common.precision)
)
776 {
777 case 32:
778 s = "float32";
779 break;
780 case 64:
781 s = "float64";
782 break;
783 default:
784 snprintf (buf, sizeof buf, "INVALID-float-%u",
785 TYPE_PRECISION (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 785, __FUNCTION__))->type_common.precision)
);
786 s = buf;
787 ret = false;
788 break;
789 }
790 obstack_grow (ob, s, strlen (s))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (s)); if (__extension__ ({ struct obstack const *__o1 =
(__o); (size_t) (__o1->chunk_limit - __o1->next_free);
}) < __len) _obstack_newchunk (__o, __len); memcpy (__o->
next_free, s, __len); __o->next_free += __len; (void) 0; }
)
;
791 }
792 break;
793
794 case COMPLEX_TYPE:
795 {
796 const char *s;
797 char buf[100];
798 tree real_type;
799
800 real_type = TREE_TYPE (type)((contains_struct_check ((type), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 800, __FUNCTION__))->typed.type)
;
801 if (TREE_CODE (real_type)((enum tree_code) (real_type)->base.code) == REAL_TYPE)
802 {
803 switch (TYPE_PRECISION (real_type)((tree_class_check ((real_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 803, __FUNCTION__))->type_common.precision)
)
804 {
805 case 32:
806 s = "complex64";
807 break;
808 case 64:
809 s = "complex128";
810 break;
811 default:
812 snprintf (buf, sizeof buf, "INVALID-complex-%u",
813 2 * TYPE_PRECISION (real_type)((tree_class_check ((real_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 813, __FUNCTION__))->type_common.precision)
);
814 s = buf;
815 ret = false;
816 break;
817 }
818 }
819 else
820 {
821 s = "INVALID-complex-non-real";
822 ret = false;
823 }
824 obstack_grow (ob, s, strlen (s))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (s)); if (__extension__ ({ struct obstack const *__o1 =
(__o); (size_t) (__o1->chunk_limit - __o1->next_free);
}) < __len) _obstack_newchunk (__o, __len); memcpy (__o->
next_free, s, __len); __o->next_free += __len; (void) 0; }
)
;
825 }
826 break;
827
828 case BOOLEAN_TYPE:
829 obstack_grow (ob, "bool", 4)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
4); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "bool"
, __len); __o->next_free += __len; (void) 0; })
;
830 break;
831
832 case POINTER_TYPE:
833 if (TREE_CODE (TREE_TYPE (type))((enum tree_code) (((contains_struct_check ((type), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 833, __FUNCTION__))->typed.type))->base.code)
== FUNCTION_TYPE)
834 obstack_grow (ob, "func", 4)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
4); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "func"
, __len); __o->next_free += __len; (void) 0; })
;
835 else
836 obstack_1grow (ob, '*')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('*'))); })
;
837 if (VOID_TYPE_P (TREE_TYPE (type))(((enum tree_code) (((contains_struct_check ((type), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 837, __FUNCTION__))->typed.type))->base.code) == VOID_TYPE
)
)
838 obstack_grow (ob, "byte", 4)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
4); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "byte"
, __len); __o->next_free += __len; (void) 0; })
;
839 else
840 {
841 if (!go_format_type (container, TREE_TYPE (type)((contains_struct_check ((type), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 841, __FUNCTION__))->typed.type)
, use_type_name,
842 true, NULLnullptr, false))
843 ret = false;
844 }
845 break;
846
847 case ARRAY_TYPE:
848 obstack_1grow (ob, '[')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('['))); })
;
849 if (TYPE_DOMAIN (type)((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 849, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)
!= NULL_TREE(tree) nullptr
850 && TREE_CODE (TYPE_DOMAIN (type))((enum tree_code) (((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 850, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
))->base.code)
== INTEGER_TYPE
851 && TYPE_MIN_VALUE (TYPE_DOMAIN (type))((tree_check5 ((((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 851, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 851, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
)
!= NULL_TREE(tree) nullptr
852 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))((enum tree_code) (((tree_check5 ((((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 852, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 852, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
))->base.code)
== INTEGER_CST
853 && tree_int_cst_sgn (TYPE_MIN_VALUE (TYPE_DOMAIN (type))((tree_check5 ((((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 853, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 853, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
)
) == 0
854 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))((tree_check5 ((((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 854, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 854, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval
)
!= NULL_TREE(tree) nullptr
855 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))((enum tree_code) (((tree_check5 ((((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 855, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 855, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval
))->base.code)
== INTEGER_CST
856 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type))((tree_check5 ((((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 856, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 856, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval
)
))
857 {
858 char buf[100];
859
860 snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_DEC"%" "l" "d" "+1",
861 tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type))((tree_check5 ((((tree_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 861, __FUNCTION__, (ARRAY_TYPE)))->type_non_common.values
)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 861, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval
)
));
862 obstack_grow (ob, buf, strlen (buf))__extension__ ({ struct obstack *__o = (ob); size_t __len = (
strlen (buf)); if (__extension__ ({ struct obstack const *__o1
= (__o); (size_t) (__o1->chunk_limit - __o1->next_free
); }) < __len) _obstack_newchunk (__o, __len); memcpy (__o
->next_free, buf, __len); __o->next_free += __len; (void
) 0; })
;
863 }
864 else
865 obstack_1grow (ob, '0')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('0'))); })
;
866 obstack_1grow (ob, ']')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = (']'))); })
;
867 if (!go_format_type (container, TREE_TYPE (type)((contains_struct_check ((type), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 867, __FUNCTION__))->typed.type)
, use_type_name, false,
868 NULLnullptr, false))
869 ret = false;
870 break;
871
872 case UNION_TYPE:
873 is_union = true;
874 /* Fall through to RECORD_TYPE case. */
875 gcc_fallthrough ();
876 case RECORD_TYPE:
877 {
878 unsigned int prev_field_end;
879 unsigned int known_alignment;
880 tree field;
881 bool emitted_a_field;
882
883 /* FIXME: Why is this necessary? Without it we can get a core
884 dump on the s390x headers, or from a file containing simply
885 "typedef struct S T;". */
886 layout_type (type);
887
888 prev_field_end = 0;
889 known_alignment = 1;
890 /* Anonymous records and unions are flattened, i.e. they are not put
891 into "struct { ... }". */
892 if (!is_anon_record_or_union)
893 obstack_grow (ob, "struct { ", 9)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
9); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "struct { "
, __len); __o->next_free += __len; (void) 0; })
;
894 for (field = TYPE_FIELDS (type)((tree_check3 ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 894, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE
)))->type_non_common.values)
, emitted_a_field = false;
895 field != NULL_TREE(tree) nullptr;
896 field = TREE_CHAIN (field)((contains_struct_check ((field), (TS_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 896, __FUNCTION__))->common.chain)
)
897 {
898 if (TREE_CODE (field)((enum tree_code) (field)->base.code) != FIELD_DECL)
899 continue;
900 if (DECL_BIT_FIELD (field)((tree_check ((field), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 900, __FUNCTION__, (FIELD_DECL)))->decl_common.decl_flag_1
)
)
901 /* Bit fields are replaced by padding. */
902 continue;
903 /* Only the first non-bitfield field is emitted for unions. */
904 if (!is_union || !emitted_a_field)
905 {
906 /* Emit the field. */
907 bool field_ok;
908 bool is_anon_substructure;
909 unsigned int decl_align_unit;
910 unsigned int decl_offset;
911
912 field_ok = true;
913 emitted_a_field = true;
914 is_anon_substructure =
915 (DECL_NAME (field)((contains_struct_check ((field), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 915, __FUNCTION__))->decl_minimal.name)
== NULLnullptr
916 && (TREE_CODE (TREE_TYPE (field))((enum tree_code) (((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 916, __FUNCTION__))->typed.type))->base.code)
== RECORD_TYPE
917 || TREE_CODE (TREE_TYPE (field))((enum tree_code) (((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 917, __FUNCTION__))->typed.type))->base.code)
== UNION_TYPE));
918 /* Keep track of the alignment of named substructures, either
919 of the whole record, or the alignment of the emitted field
920 (for unions). */
921 decl_align_unit = DECL_ALIGN_UNIT (field)((((contains_struct_check ((field), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 921, __FUNCTION__))->decl_common.align) ? ((unsigned)1) <<
(((contains_struct_check ((field), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 921, __FUNCTION__))->decl_common.align) - 1) : 0) / (8))
;
922 if (!is_anon_substructure && decl_align_unit > known_alignment)
923 known_alignment = decl_align_unit;
924 /* Pad to start of field. */
925 decl_offset =
926 TREE_INT_CST_LOW (DECL_FIELD_OFFSET (field))((unsigned long) (*tree_int_cst_elt_check ((((tree_check ((field
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 926, __FUNCTION__, (FIELD_DECL)))->field_decl.offset)), (
0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 926, __FUNCTION__)))
927 + precision_to_units
928 (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))((unsigned long) (*tree_int_cst_elt_check ((((tree_check ((field
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 928, __FUNCTION__, (FIELD_DECL)))->field_decl.bit_offset
)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 928, __FUNCTION__)))
);
929 {
930 unsigned int align_unit;
931
932 /* For anonymous records and unions there is no automatic
933 structure alignment, so use 1 as the alignment. */
934 align_unit = (is_anon_substructure) ? 1 : decl_align_unit;
935 *p_art_i = go_append_padding
936 (ob, prev_field_end, decl_offset, align_unit, *p_art_i,
937 &prev_field_end);
938 }
939 if (DECL_SIZE_UNIT (field)((contains_struct_check ((field), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 939, __FUNCTION__))->decl_common.size_unit)
)
940 prev_field_end +=
941 TREE_INT_CST_LOW (DECL_SIZE_UNIT (field))((unsigned long) (*tree_int_cst_elt_check ((((contains_struct_check
((field), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 941, __FUNCTION__))->decl_common.size_unit)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 941, __FUNCTION__)))
;
942 /* Emit the field name, but not for anonymous records and
943 unions. */
944 if (!is_anon_substructure)
945 {
946 if (DECL_NAME (field)((contains_struct_check ((field), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 946, __FUNCTION__))->decl_minimal.name)
== NULLnullptr)
947 *p_art_i = go_append_artificial_name (ob, *p_art_i);
948 else
949 go_append_decl_name
950 (ob, field, container->keyword_hash);
951 obstack_1grow (ob, ' ')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = (' '))); })
;
952 }
953 /* Do not expand type if a record or union type or a function
954 pointer. */
955 if (TYPE_NAME (TREE_TYPE (field))((tree_class_check ((((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 955, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 955, __FUNCTION__))->type_common.name)
!= NULL_TREE(tree) nullptr
956 && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))(((enum tree_code) (((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 956, __FUNCTION__))->typed.type))->base.code) == RECORD_TYPE
|| ((enum tree_code) (((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 956, __FUNCTION__))->typed.type))->base.code) == UNION_TYPE
|| ((enum tree_code) (((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 956, __FUNCTION__))->typed.type))->base.code) == QUAL_UNION_TYPE
)
957 || (POINTER_TYPE_P (TREE_TYPE (field))(((enum tree_code) (((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 957, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 957, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
958 && (TREE_CODE (TREE_TYPE (TREE_TYPE (field)))((enum tree_code) (((contains_struct_check ((((contains_struct_check
((field), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 958, __FUNCTION__))->typed.type)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 958, __FUNCTION__))->typed.type))->base.code)
959 == FUNCTION_TYPE))))
960 {
961 tree name;
962 void **slot;
963
964 name = TYPE_IDENTIFIER (TREE_TYPE (field))(((tree_class_check ((((contains_struct_check ((field), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->type_common.name) && (tree_code_type
[(int) (((enum tree_code) (((tree_class_check ((((contains_struct_check
((field), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->type_common.name))->base.code))]
== tcc_declaration) ? ((contains_struct_check ((((tree_class_check
((((contains_struct_check ((field), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->type_common.name)), (TS_DECL_MINIMAL
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->decl_minimal.name) : ((tree_class_check
((((contains_struct_check ((field), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 964, __FUNCTION__))->type_common.name))
;
965
966 slot = htab_find_slot (container->invalid_hash,
967 IDENTIFIER_POINTER (name)((const char *) (tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 967, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
968 NO_INSERT);
969 if (slot != NULLnullptr)
970 field_ok = false;
971
972 obstack_1grow (ob, '_')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('_'))); })
;
973 go_append_string (ob, name);
974 }
975 else
976 {
977 if (!go_format_type (container, TREE_TYPE (field)((contains_struct_check ((field), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 977, __FUNCTION__))->typed.type)
, true,
978 false, p_art_i, is_anon_substructure))
979 field_ok = false;
980 }
981 if (!is_anon_substructure)
982 obstack_grow (ob, "; ", 2)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
2); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "; "
, __len); __o->next_free += __len; (void) 0; })
;
983 if (!field_ok)
984 ret = false;
985 }
986 }
987 /* Padding. */
988 *p_art_i = go_append_padding (ob, prev_field_end,
989 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type))((unsigned long) (*tree_int_cst_elt_check ((((tree_class_check
((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 989, __FUNCTION__))->type_common.size_unit)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 989, __FUNCTION__)))
,
990 1, *p_art_i, &prev_field_end);
991 /* Alignment. */
992 if (!is_anon_record_or_union
993 && known_alignment < TYPE_ALIGN_UNIT (type)(((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 993, __FUNCTION__))->type_common.align ? ((unsigned)1) <<
((type)->type_common.align - 1) : 0) / (8))
)
994 {
995 const char *s;
996 char buf[100];
997
998 /* Enforce proper record alignment. */
999 s = go_get_uinttype_for_precision
1000 (TYPE_ALIGN (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1000, __FUNCTION__))->type_common.align ? ((unsigned)1) <<
((type)->type_common.align - 1) : 0)
, TYPE_UNSIGNED (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1000, __FUNCTION__))->base.u.bits.unsigned_flag)
);
1001 if (s == NULLnullptr)
1002 {
1003 snprintf (buf, sizeof buf, "INVALID-int-%u%s",
1004 TYPE_ALIGN (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1004, __FUNCTION__))->type_common.align ? ((unsigned)1) <<
((type)->type_common.align - 1) : 0)
, TYPE_UNSIGNED (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1004, __FUNCTION__))->base.u.bits.unsigned_flag)
? "u" : "");
1005 s = buf;
1006 ret = false;
1007 }
1008 *p_art_i = go_force_record_alignment (ob, s, *p_art_i, buf);
1009 }
1010 if (!is_anon_record_or_union)
1011 obstack_1grow (ob, '}')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('}'))); })
;
1012 }
1013 break;
1014
1015 case FUNCTION_TYPE:
1016 {
1017 tree arg_type;
1018 bool is_varargs;
1019 tree result;
1020 function_args_iterator iter;
1021 bool seen_arg;
1022
1023 /* Go has no way to write a type which is a function but not a
1024 pointer to a function. */
1025 if (!is_func_ok)
1026 {
1027 obstack_grow (ob, "func*", 5)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
5); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, "func*"
, __len); __o->next_free += __len; (void) 0; })
;
1028 ret = false;
1029 }
1030
1031 obstack_1grow (ob, '(')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('('))); })
;
1032 is_varargs = stdarg_p (type);
1033 seen_arg = false;
1034 FOREACH_FUNCTION_ARGS (type, arg_type, iter)for (function_args_iter_init (&(iter), (type)); (arg_type
= function_args_iter_cond (&(iter))) != (tree) nullptr; function_args_iter_next
(&(iter)))
1035 {
1036 if (VOID_TYPE_P (arg_type)(((enum tree_code) (arg_type)->base.code) == VOID_TYPE))
1037 break;
1038 if (seen_arg)
1039 obstack_grow (ob, ", ", 2)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
2); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, ", "
, __len); __o->next_free += __len; (void) 0; })
;
1040 if (!go_format_type (container, arg_type, true, false, NULLnullptr, false))
1041 ret = false;
1042 seen_arg = true;
1043 }
1044 if (is_varargs)
1045 {
1046 if (prototype_p (type))
1047 obstack_grow (ob, ", ", 2)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
2); if (__extension__ ({ struct obstack const *__o1 = (__o); (
size_t) (__o1->chunk_limit - __o1->next_free); }) < __len
) _obstack_newchunk (__o, __len); memcpy (__o->next_free, ", "
, __len); __o->next_free += __len; (void) 0; })
;
1048 obstack_grow (ob, "...interface{}", 14)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
14); if (__extension__ ({ struct obstack const *__o1 = (__o);
(size_t) (__o1->chunk_limit - __o1->next_free); }) <
__len) _obstack_newchunk (__o, __len); memcpy (__o->next_free
, "...interface{}", __len); __o->next_free += __len; (void
) 0; })
;
1049 }
1050 obstack_1grow (ob, ')')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = (')'))); })
;
1051
1052 result = TREE_TYPE (type)((contains_struct_check ((type), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1052, __FUNCTION__))->typed.type)
;
1053 if (!VOID_TYPE_P (result)(((enum tree_code) (result)->base.code) == VOID_TYPE))
1054 {
1055 obstack_1grow (ob, ' ')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = (' '))); })
;
1056 if (!go_format_type (container, result, use_type_name, false, NULLnullptr,
1057 false))
1058 ret = false;
1059 }
1060 }
1061 break;
1062
1063 default:
1064 obstack_grow (ob, "INVALID-type", 12)__extension__ ({ struct obstack *__o = (ob); size_t __len = (
12); if (__extension__ ({ struct obstack const *__o1 = (__o);
(size_t) (__o1->chunk_limit - __o1->next_free); }) <
__len) _obstack_newchunk (__o, __len); memcpy (__o->next_free
, "INVALID-type", __len); __o->next_free += __len; (void) 0
; })
;
1065 ret = false;
1066 break;
1067 }
1068
1069 return ret;
1070}
1071
1072/* Output the type which was built on the type obstack, and then free
1073 it. */
1074
1075static void
1076go_output_type (class godump_container *container)
1077{
1078 struct obstack *ob;
1079
1080 ob = &container->type_obstack;
1081 obstack_1grow (ob, '\0')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('\0'))); })
;
1082 fputs ((char *) obstack_base (ob)((void *) (ob)->object_base), go_dump_file);
1083 obstack_free (ob, obstack_base (ob))__extension__ ({ struct obstack *__o = (ob); void *__obj = (void
*) (((void *) (ob)->object_base)); if (__obj > (void *
) __o->chunk && __obj < (void *) __o->chunk_limit
) __o->next_free = __o->object_base = (char *) __obj; else
_obstack_free (__o, __obj); })
;
1084}
1085
1086/* Output a function declaration. */
1087
1088static void
1089go_output_fndecl (class godump_container *container, tree decl)
1090{
1091 if (!go_format_type (container, TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1091, __FUNCTION__))->typed.type)
, true, true, NULLnullptr, false))
1092 fprintf (go_dump_file, "// ");
1093 fprintf (go_dump_file, "func _%s ",
1094 IDENTIFIER_POINTER (DECL_NAME (decl))((const char *) (tree_check ((((contains_struct_check ((decl)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1094, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1094, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
1095 go_output_type (container);
1096 fprintf (go_dump_file, " __asm__(\"%s\")\n",
1097 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))((const char *) (tree_check ((decl_assembler_name (decl)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1097, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
1098}
1099
1100/* Output a typedef or something like a struct definition. */
1101
1102static void
1103go_output_typedef (class godump_container *container, tree decl)
1104{
1105 /* If we have an enum type, output the enum constants
1106 separately. */
1107 if (TREE_CODE (TREE_TYPE (decl))((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1107, __FUNCTION__))->typed.type))->base.code)
== ENUMERAL_TYPE
1108 && TYPE_SIZE (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1108, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1108, __FUNCTION__))->type_common.size)
!= 0
1109 && !container->decls_seen.contains (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1109, __FUNCTION__))->typed.type)
)
1110 && (TYPE_CANONICAL (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1110, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1110, __FUNCTION__))->type_common.canonical)
== NULL_TREE(tree) nullptr
1111 || !container->decls_seen.contains
1112 (TYPE_CANONICAL (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1112, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1112, __FUNCTION__))->type_common.canonical)
)))
1113 {
1114 tree element;
1115
1116 for (element = TYPE_VALUES (TREE_TYPE (decl))((tree_check ((((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1116, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1116, __FUNCTION__, (ENUMERAL_TYPE)))->type_non_common.values
)
;
1117 element != NULL_TREE(tree) nullptr;
1118 element = TREE_CHAIN (element)((contains_struct_check ((element), (TS_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1118, __FUNCTION__))->common.chain)
)
1119 {
1120 const char *name;
1121 struct macro_hash_value *mhval;
1122 void **slot;
1123 char buf[WIDE_INT_PRINT_BUFFER_SIZE((((160 + 64) / 64) * 64) / 4 + 4)];
1124
1125 name = IDENTIFIER_POINTER (TREE_PURPOSE (element))((const char *) (tree_check ((((tree_check ((element), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1125, __FUNCTION__, (TREE_LIST)))->list.purpose)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1125, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
1126
1127 /* Sometimes a name will be defined as both an enum constant
1128 and a macro. Avoid duplicate definition errors by
1129 treating enum constants as macros. */
1130 mhval = XNEW (struct macro_hash_value)((struct macro_hash_value *) xmalloc (sizeof (struct macro_hash_value
)))
;
1131 mhval->name = xstrdup (name);
1132 mhval->value = NULLnullptr;
1133 slot = htab_find_slot (macro_hash, mhval, INSERT);
1134 if (*slot != NULLnullptr)
1135 macro_hash_del (*slot);
1136
1137 if (tree_fits_shwi_p (TREE_VALUE (element)((tree_check ((element), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1137, __FUNCTION__, (TREE_LIST)))->list.value)
))
1138 snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_DEC"%" "l" "d",
1139 tree_to_shwi (TREE_VALUE (element)((tree_check ((element), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1139, __FUNCTION__, (TREE_LIST)))->list.value)
));
1140 else if (tree_fits_uhwi_p (TREE_VALUE (element)((tree_check ((element), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1140, __FUNCTION__, (TREE_LIST)))->list.value)
))
1141 snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_UNSIGNED"%" "l" "u",
1142 tree_to_uhwi (TREE_VALUE (element)((tree_check ((element), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1142, __FUNCTION__, (TREE_LIST)))->list.value)
));
1143 else
1144 print_hex (wi::to_wide (element), buf);
1145
1146 mhval->value = xstrdup (buf);
1147 *slot = mhval;
1148 }
1149 container->decls_seen.add (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1149, __FUNCTION__))->typed.type)
);
1150 if (TYPE_CANONICAL (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1150, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1150, __FUNCTION__))->type_common.canonical)
!= NULL_TREE(tree) nullptr)
1151 container->decls_seen.add (TYPE_CANONICAL (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1151, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1151, __FUNCTION__))->type_common.canonical)
);
1152 }
1153
1154 if (DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1154, __FUNCTION__))->decl_minimal.name)
!= NULL_TREE(tree) nullptr)
1155 {
1156 void **slot;
1157 const char *type;
1158 tree original_type;
1159
1160 type = IDENTIFIER_POINTER (DECL_NAME (decl))((const char *) (tree_check ((((contains_struct_check ((decl)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1160, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1160, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
1161 original_type = DECL_ORIGINAL_TYPE (decl)((tree_check ((decl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1161, __FUNCTION__, (TYPE_DECL)))->decl_non_common.result
)
;
1162 if (original_type == NULL_TREE(tree) nullptr)
1163 original_type = TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1163, __FUNCTION__))->typed.type)
;
1164
1165 /* Suppress typedefs where the type name matches the underlying
1166 struct/union/enum tag. This way we'll emit the struct definition
1167 instead of an invalid recursive type. */
1168 if (TYPE_IDENTIFIER (original_type)(((tree_class_check ((original_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1168, __FUNCTION__))->type_common.name) && (tree_code_type
[(int) (((enum tree_code) (((tree_class_check ((original_type
), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1168, __FUNCTION__))->type_common.name))->base.code))
] == tcc_declaration) ? ((contains_struct_check ((((tree_class_check
((original_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1168, __FUNCTION__))->type_common.name)), (TS_DECL_MINIMAL
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1168, __FUNCTION__))->decl_minimal.name) : ((tree_class_check
((original_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1168, __FUNCTION__))->type_common.name))
!= NULLnullptr
1169 && IDENTIFIER_POINTER (TYPE_IDENTIFIER (original_type))((const char *) (tree_check (((((tree_class_check ((original_type
), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1169, __FUNCTION__))->type_common.name) && (tree_code_type
[(int) (((enum tree_code) (((tree_class_check ((original_type
), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1169, __FUNCTION__))->type_common.name))->base.code))
] == tcc_declaration) ? ((contains_struct_check ((((tree_class_check
((original_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1169, __FUNCTION__))->type_common.name)), (TS_DECL_MINIMAL
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1169, __FUNCTION__))->decl_minimal.name) : ((tree_class_check
((original_type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1169, __FUNCTION__))->type_common.name))), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1169, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
== type)
1170 return;
1171
1172 /* If type defined already, skip. */
1173 slot = htab_find_slot (container->type_hash, type, INSERT);
1174 if (*slot != NULLnullptr)
1175 return;
1176 *slot = CONST_CAST (void *, (const void *) type)(const_cast<void *> (((const void *) type)));
1177
1178 if (!go_format_type (container, original_type, true, false,
1179 NULLnullptr, false))
1180 {
1181 fprintf (go_dump_file, "// ");
1182 slot = htab_find_slot (container->invalid_hash, type, INSERT);
1183 *slot = CONST_CAST (void *, (const void *) type)(const_cast<void *> (((const void *) type)));
1184 }
1185 fprintf (go_dump_file, "type _%s ",
1186 IDENTIFIER_POINTER (DECL_NAME (decl))((const char *) (tree_check ((((contains_struct_check ((decl)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1186, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1186, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
1187 go_output_type (container);
1188
1189 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))(((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1189, __FUNCTION__))->typed.type))->base.code) == RECORD_TYPE
|| ((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1189, __FUNCTION__))->typed.type))->base.code) == UNION_TYPE
|| ((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1189, __FUNCTION__))->typed.type))->base.code) == QUAL_UNION_TYPE
)
)
1190 {
1191 HOST_WIDE_INTlong size = int_size_in_bytes (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1191, __FUNCTION__))->typed.type)
);
1192
1193 if (size > 0)
1194 fprintf (go_dump_file,
1195 "\nconst _sizeof_%s = " HOST_WIDE_INT_PRINT_DEC"%" "l" "d",
1196 IDENTIFIER_POINTER (DECL_NAME (decl))((const char *) (tree_check ((((contains_struct_check ((decl)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1196, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1196, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
1197 size);
1198 }
1199
1200 container->decls_seen.add (decl);
1201 }
1202 else if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))(((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1202, __FUNCTION__))->typed.type))->base.code) == RECORD_TYPE
|| ((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1202, __FUNCTION__))->typed.type))->base.code) == UNION_TYPE
|| ((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1202, __FUNCTION__))->typed.type))->base.code) == QUAL_UNION_TYPE
)
1203 || TREE_CODE (TREE_TYPE (decl))((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1203, __FUNCTION__))->typed.type))->base.code)
== ENUMERAL_TYPE)
1204 && TYPE_NAME (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1204, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1204, __FUNCTION__))->type_common.name)
!= NULLnullptr)
1205 {
1206 void **slot;
1207 const char *type;
1208 HOST_WIDE_INTlong size;
1209
1210 type = IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE ((decl))))((const char *) (tree_check ((((tree_class_check ((((contains_struct_check
(((decl)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1210, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1210, __FUNCTION__))->type_common.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1210, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
1211 /* If type defined already, skip. */
1212 slot = htab_find_slot (container->type_hash, type, INSERT);
1213 if (*slot != NULLnullptr)
1214 return;
1215 *slot = CONST_CAST (void *, (const void *) type)(const_cast<void *> (((const void *) type)));
1216
1217 if (!go_format_type (container, TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1217, __FUNCTION__))->typed.type)
, false, false, NULLnullptr,
1218 false))
1219 {
1220 fprintf (go_dump_file, "// ");
1221 slot = htab_find_slot (container->invalid_hash, type, INSERT);
1222 *slot = CONST_CAST (void *, (const void *) type)(const_cast<void *> (((const void *) type)));
1223 }
1224 fprintf (go_dump_file, "type _%s ",
1225 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl)))((const char *) (tree_check ((((tree_class_check ((((contains_struct_check
((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1225, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1225, __FUNCTION__))->type_common.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1225, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
1226 go_output_type (container);
1227
1228 size = int_size_in_bytes (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1228, __FUNCTION__))->typed.type)
);
1229 if (size > 0)
1230 fprintf (go_dump_file,
1231 "\nconst _sizeof_%s = " HOST_WIDE_INT_PRINT_DEC"%" "l" "d",
1232 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl)))((const char *) (tree_check ((((tree_class_check ((((contains_struct_check
((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1232, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1232, __FUNCTION__))->type_common.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1232, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
1233 size);
1234 }
1235 else
1236 return;
1237
1238 fprintf (go_dump_file, "\n");
1239}
1240
1241/* Output a variable. */
1242
1243static void
1244go_output_var (class godump_container *container, tree decl)
1245{
1246 bool is_valid;
1247 tree type_name;
1248 tree id;
1249
1250 if (container->decls_seen.contains (decl)
1251 || container->decls_seen.contains (DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1251, __FUNCTION__))->decl_minimal.name)
))
1252 return;
1253 container->decls_seen.add (decl);
1254 container->decls_seen.add (DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1254, __FUNCTION__))->decl_minimal.name)
);
1255
1256 type_name = TYPE_NAME (TREE_TYPE (decl))((tree_class_check ((((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1256, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1256, __FUNCTION__))->type_common.name)
;
1257 id = NULL_TREE(tree) nullptr;
1258 if (type_name != NULL_TREE(tree) nullptr && TREE_CODE (type_name)((enum tree_code) (type_name)->base.code) == IDENTIFIER_NODE)
1259 id = type_name;
1260 else if (type_name != NULL_TREE(tree) nullptr && TREE_CODE (type_name)((enum tree_code) (type_name)->base.code) == TYPE_DECL
1261 && DECL_SOURCE_LOCATION (type_name)((contains_struct_check ((type_name), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1261, __FUNCTION__))->decl_minimal.locus)
!= BUILTINS_LOCATION((location_t) 1)
1262 && DECL_NAME (type_name)((contains_struct_check ((type_name), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1262, __FUNCTION__))->decl_minimal.name)
)
1263 id = DECL_NAME (type_name)((contains_struct_check ((type_name), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1263, __FUNCTION__))->decl_minimal.name)
;
1264 if (id != NULL_TREE(tree) nullptr
1265 && (!htab_find_slot (container->type_hash, IDENTIFIER_POINTER (id)((const char *) (tree_check ((id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1265, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
1266 NO_INSERT)
1267 || htab_find_slot (container->invalid_hash, IDENTIFIER_POINTER (id)((const char *) (tree_check ((id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1267, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
1268 NO_INSERT)))
1269 id = NULL_TREE(tree) nullptr;
1270 if (id != NULL_TREE(tree) nullptr)
1271 {
1272 struct obstack *ob;
1273
1274 ob = &container->type_obstack;
1275 obstack_1grow (ob, '_')__extension__ ({ struct obstack *__o = (ob); if (__extension__
({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit
- __o1->next_free); }) < 1) _obstack_newchunk (__o, 1)
; ((void) (*((__o)->next_free)++ = ('_'))); })
;
1276 go_append_string (ob, id);
1277 is_valid = htab_find_slot (container->type_hash, IDENTIFIER_POINTER (id)((const char *) (tree_check ((id), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1277, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
1278 NO_INSERT) != NULLnullptr;
1279 }
1280 else
1281 is_valid = go_format_type (container, TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1281, __FUNCTION__))->typed.type)
, true, false, NULLnullptr,
1282 false);
1283 if (is_valid
1284 && htab_find_slot (container->type_hash,
1285 IDENTIFIER_POINTER (DECL_NAME (decl))((const char *) (tree_check ((((contains_struct_check ((decl)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1285, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1285, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
,
1286 NO_INSERT) != NULLnullptr)
1287 {
1288 /* There is already a type with this name, probably from a
1289 struct tag. Prefer the type to the variable. */
1290 is_valid = false;
1291 }
1292 if (!is_valid)
1293 fprintf (go_dump_file, "// ");
1294
1295 fprintf (go_dump_file, "var _%s ",
1296 IDENTIFIER_POINTER (DECL_NAME (decl))((const char *) (tree_check ((((contains_struct_check ((decl)
, (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1296, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1296, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
1297 go_output_type (container);
1298 fprintf (go_dump_file, "\n");
1299
1300 /* Sometimes an extern variable is declared with an unknown struct
1301 type. */
1302 if (type_name != NULL_TREE(tree) nullptr && RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))(((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1302, __FUNCTION__))->typed.type))->base.code) == RECORD_TYPE
|| ((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1302, __FUNCTION__))->typed.type))->base.code) == UNION_TYPE
|| ((enum tree_code) (((contains_struct_check ((decl), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1302, __FUNCTION__))->typed.type))->base.code) == QUAL_UNION_TYPE
)
)
1303 {
1304 if (TREE_CODE (type_name)((enum tree_code) (type_name)->base.code) == IDENTIFIER_NODE)
1305 container->pot_dummy_types.add (IDENTIFIER_POINTER (type_name)((const char *) (tree_check ((type_name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1305, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
1306 else if (TREE_CODE (type_name)((enum tree_code) (type_name)->base.code) == TYPE_DECL)
1307 container->pot_dummy_types.add
1308 (IDENTIFIER_POINTER (DECL_NAME (type_name))((const char *) (tree_check ((((contains_struct_check ((type_name
), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1308, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1308, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
1309 }
1310}
1311
1312/* Output the final value of a preprocessor macro or enum constant.
1313 This is called via htab_traverse_noresize. */
1314
1315static int
1316go_print_macro (void **slot, void *arg ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
1317{
1318 struct macro_hash_value *mhval = (struct macro_hash_value *) *slot;
1319 fprintf (go_dump_file, "const _%s = %s\n", mhval->name, mhval->value);
1320 return 1;
1321}
1322
1323/* Build a hash table with the Go keywords. */
1324
1325static const char * const keywords[] = {
1326 "__asm__", "break", "case", "chan", "const", "continue", "default",
1327 "defer", "else", "fallthrough", "for", "func", "go", "goto", "if",
1328 "import", "interface", "map", "package", "range", "return", "select",
1329 "struct", "switch", "type", "var"
1330};
1331
1332static void
1333keyword_hash_init (class godump_container *container)
1334{
1335 size_t i;
1336 size_t count = sizeof (keywords) / sizeof (keywords[0]);
1337 void **slot;
1338
1339 for (i = 0; i < count; i++)
1340 {
1341 slot = htab_find_slot (container->keyword_hash, keywords[i], INSERT);
1342 *slot = CONST_CAST (void *, (const void *) keywords[i])(const_cast<void *> (((const void *) keywords[i])));
1343 }
1344}
1345
1346/* Traversing the pot_dummy_types and seeing which types are present
1347 in the global types hash table and creating dummy definitions if
1348 not found. This function is invoked by hash_set::traverse. */
1349
1350bool
1351find_dummy_types (const char *const &ptr, godump_container *adata)
1352{
1353 class godump_container *data = (class godump_container *) adata;
1354 const char *type = (const char *) ptr;
1355 void **slot;
1356 void **islot;
1357
1358 slot = htab_find_slot (data->type_hash, type, NO_INSERT);
1359 islot = htab_find_slot (data->invalid_hash, type, NO_INSERT);
1360 if (slot == NULLnullptr || islot != NULLnullptr)
1361 fprintf (go_dump_file, "type _%s struct {}\n", type);
1362 return true;
1363}
1364
1365/* Output symbols. */
1366
1367static void
1368go_finish (const char *filename)
1369{
1370 class godump_container container;
1371 unsigned int ix;
1372 tree decl;
1373
1374 real_debug_hooks->finish (filename);
1375
1376 container.type_hash = htab_create (100, htab_hash_string,
1377 string_hash_eq, NULLnullptr);
1378 container.invalid_hash = htab_create (10, htab_hash_string,
1379 string_hash_eq, NULLnullptr);
1380 container.keyword_hash = htab_create (50, htab_hash_string,
1381 string_hash_eq, NULLnullptr);
1382 obstack_init (&container.type_obstack)_obstack_begin ((&container.type_obstack), 0, 0, (mempool_obstack_chunk_alloc
), (mempool_obstack_chunk_free))
;
1383
1384 keyword_hash_init (&container);
1385
1386 FOR_EACH_VEC_SAFE_ELT (queue, ix, decl)for (ix = 0; vec_safe_iterate ((queue), (ix), &(decl)); ++
(ix))
1387 {
1388 switch (TREE_CODE (decl)((enum tree_code) (decl)->base.code))
1389 {
1390 case FUNCTION_DECL:
1391 go_output_fndecl (&container, decl);
1392 break;
1393
1394 case TYPE_DECL:
1395 go_output_typedef (&container, decl);
1396 break;
1397
1398 case VAR_DECL:
1399 go_output_var (&container, decl);
1400 break;
1401
1402 default:
1403 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/godump.c"
, 1403, __FUNCTION__))
;
1404 }
1405 }
1406
1407 htab_traverse_noresize (macro_hash, go_print_macro, NULLnullptr);
1408
1409 /* To emit dummy definitions. */
1410 container.pot_dummy_types.traverse<godump_container *, find_dummy_types>
1411 (&container);
1412
1413 htab_delete (container.type_hash);
1414 htab_delete (container.invalid_hash);
1415 htab_delete (container.keyword_hash);
1416 obstack_free (&container.type_obstack, NULL)__extension__ ({ struct obstack *__o = (&container.type_obstack
); void *__obj = (void *) (nullptr); if (__obj > (void *) __o
->chunk && __obj < (void *) __o->chunk_limit
) __o->next_free = __o->object_base = (char *) __obj; else
_obstack_free (__o, __obj); })
;
1417
1418 vec_free (queue);
1419
1420 if (fclose (go_dump_file) != 0)
1421 error ("could not close Go dump file: %m");
1422 go_dump_file = NULLnullptr;
1423}
1424
1425/* Set up our hooks. */
1426
1427const struct gcc_debug_hooks *
1428dump_go_spec_init (const char *filename, const struct gcc_debug_hooks *hooks)
1429{
1430 go_dump_file = fopen (filename, "w");
1431 if (go_dump_file == NULLnullptr)
1432 {
1433 error ("could not open Go dump file %qs: %m", filename);
1434 return hooks;
1435 }
1436
1437 go_debug_hooks = *hooks;
1438 real_debug_hooks = hooks;
1439
1440 go_debug_hooks.finish = go_finish;
1441 go_debug_hooks.define = go_define;
1442 go_debug_hooks.undef = go_undef;
1443 go_debug_hooks.function_decl = go_function_decl;
1444 go_debug_hooks.early_global_decl = go_early_global_decl;
1445 go_debug_hooks.late_global_decl = go_late_global_decl;
1446 go_debug_hooks.type_decl = go_type_decl;
1447
1448 macro_hash = htab_create (100, macro_hash_hashval, macro_hash_eq,
1449 macro_hash_del);
1450
1451 return &go_debug_hooks;
1452}
1453
1454#include "gt-godump.h"

/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h

1/* Vector API for GNU compiler.
2 Copyright (C) 2004-2021 Free Software Foundation, Inc.
3 Contributed by Nathan Sidwell <nathan@codesourcery.com>
4 Re-implemented in C++ by Diego Novillo <dnovillo@google.com>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_VEC_H
23#define GCC_VEC_H
24
25/* Some gen* file have no ggc support as the header file gtype-desc.h is
26 missing. Provide these definitions in case ggc.h has not been included.
27 This is not a problem because any code that runs before gengtype is built
28 will never need to use GC vectors.*/
29
30extern void ggc_free (void *);
31extern size_t ggc_round_alloc_size (size_t requested_size);
32extern void *ggc_realloc (void *, size_t MEM_STAT_DECL);
33
34/* Templated vector type and associated interfaces.
35
36 The interface functions are typesafe and use inline functions,
37 sometimes backed by out-of-line generic functions. The vectors are
38 designed to interoperate with the GTY machinery.
39
40 There are both 'index' and 'iterate' accessors. The index accessor
41 is implemented by operator[]. The iterator returns a boolean
42 iteration condition and updates the iteration variable passed by
43 reference. Because the iterator will be inlined, the address-of
44 can be optimized away.
45
46 Each operation that increases the number of active elements is
47 available in 'quick' and 'safe' variants. The former presumes that
48 there is sufficient allocated space for the operation to succeed
49 (it dies if there is not). The latter will reallocate the
50 vector, if needed. Reallocation causes an exponential increase in
51 vector size. If you know you will be adding N elements, it would
52 be more efficient to use the reserve operation before adding the
53 elements with the 'quick' operation. This will ensure there are at
54 least as many elements as you ask for, it will exponentially
55 increase if there are too few spare slots. If you want reserve a
56 specific number of slots, but do not want the exponential increase
57 (for instance, you know this is the last allocation), use the
58 reserve_exact operation. You can also create a vector of a
59 specific size from the get go.
60
61 You should prefer the push and pop operations, as they append and
62 remove from the end of the vector. If you need to remove several
63 items in one go, use the truncate operation. The insert and remove
64 operations allow you to change elements in the middle of the
65 vector. There are two remove operations, one which preserves the
66 element ordering 'ordered_remove', and one which does not
67 'unordered_remove'. The latter function copies the end element
68 into the removed slot, rather than invoke a memmove operation. The
69 'lower_bound' function will determine where to place an item in the
70 array using insert that will maintain sorted order.
71
72 Vectors are template types with three arguments: the type of the
73 elements in the vector, the allocation strategy, and the physical
74 layout to use
75
76 Four allocation strategies are supported:
77
78 - Heap: allocation is done using malloc/free. This is the
79 default allocation strategy.
80
81 - GC: allocation is done using ggc_alloc/ggc_free.
82
83 - GC atomic: same as GC with the exception that the elements
84 themselves are assumed to be of an atomic type that does
85 not need to be garbage collected. This means that marking
86 routines do not need to traverse the array marking the
87 individual elements. This increases the performance of
88 GC activities.
89
90 Two physical layouts are supported:
91
92 - Embedded: The vector is structured using the trailing array
93 idiom. The last member of the structure is an array of size
94 1. When the vector is initially allocated, a single memory
95 block is created to hold the vector's control data and the
96 array of elements. These vectors cannot grow without
97 reallocation (see discussion on embeddable vectors below).
98
99 - Space efficient: The vector is structured as a pointer to an
100 embedded vector. This is the default layout. It means that
101 vectors occupy a single word of storage before initial
102 allocation. Vectors are allowed to grow (the internal
103 pointer is reallocated but the main vector instance does not
104 need to relocate).
105
106 The type, allocation and layout are specified when the vector is
107 declared.
108
109 If you need to directly manipulate a vector, then the 'address'
110 accessor will return the address of the start of the vector. Also
111 the 'space' predicate will tell you whether there is spare capacity
112 in the vector. You will not normally need to use these two functions.
113
114 Notes on the different layout strategies
115
116 * Embeddable vectors (vec<T, A, vl_embed>)
117
118 These vectors are suitable to be embedded in other data
119 structures so that they can be pre-allocated in a contiguous
120 memory block.
121
122 Embeddable vectors are implemented using the trailing array
123 idiom, thus they are not resizeable without changing the address
124 of the vector object itself. This means you cannot have
125 variables or fields of embeddable vector type -- always use a
126 pointer to a vector. The one exception is the final field of a
127 structure, which could be a vector type.
128
129 You will have to use the embedded_size & embedded_init calls to
130 create such objects, and they will not be resizeable (so the
131 'safe' allocation variants are not available).
132
133 Properties of embeddable vectors:
134
135 - The whole vector and control data are allocated in a single
136 contiguous block. It uses the trailing-vector idiom, so
137 allocation must reserve enough space for all the elements
138 in the vector plus its control data.
139 - The vector cannot be re-allocated.
140 - The vector cannot grow nor shrink.
141 - No indirections needed for access/manipulation.
142 - It requires 2 words of storage (prior to vector allocation).
143
144
145 * Space efficient vector (vec<T, A, vl_ptr>)
146
147 These vectors can grow dynamically and are allocated together
148 with their control data. They are suited to be included in data
149 structures. Prior to initial allocation, they only take a single
150 word of storage.
151
152 These vectors are implemented as a pointer to embeddable vectors.
153 The semantics allow for this pointer to be NULL to represent
154 empty vectors. This way, empty vectors occupy minimal space in
155 the structure containing them.
156
157 Properties:
158
159 - The whole vector and control data are allocated in a single
160 contiguous block.
161 - The whole vector may be re-allocated.
162 - Vector data may grow and shrink.
163 - Access and manipulation requires a pointer test and
164 indirection.
165 - It requires 1 word of storage (prior to vector allocation).
166
167 An example of their use would be,
168
169 struct my_struct {
170 // A space-efficient vector of tree pointers in GC memory.
171 vec<tree, va_gc, vl_ptr> v;
172 };
173
174 struct my_struct *s;
175
176 if (s->v.length ()) { we have some contents }
177 s->v.safe_push (decl); // append some decl onto the end
178 for (ix = 0; s->v.iterate (ix, &elt); ix++)
179 { do something with elt }
180*/
181
182/* Support function for statistics. */
183extern void dump_vec_loc_statistics (void);
184
185/* Hashtable mapping vec addresses to descriptors. */
186extern htab_t vec_mem_usage_hash;
187
188/* Control data for vectors. This contains the number of allocated
189 and used slots inside a vector. */
190
191struct vec_prefix
192{
193 /* FIXME - These fields should be private, but we need to cater to
194 compilers that have stricter notions of PODness for types. */
195
196 /* Memory allocation support routines in vec.c. */
197 void register_overhead (void *, size_t, size_t CXX_MEM_STAT_INFO);
198 void release_overhead (void *, size_t, size_t, bool CXX_MEM_STAT_INFO);
199 static unsigned calculate_allocation (vec_prefix *, unsigned, bool);
200 static unsigned calculate_allocation_1 (unsigned, unsigned);
201
202 /* Note that vec_prefix should be a base class for vec, but we use
203 offsetof() on vector fields of tree structures (e.g.,
204 tree_binfo::base_binfos), and offsetof only supports base types.
205
206 To compensate, we make vec_prefix a field inside vec and make
207 vec a friend class of vec_prefix so it can access its fields. */
208 template <typename, typename, typename> friend struct vec;
209
210 /* The allocator types also need access to our internals. */
211 friend struct va_gc;
212 friend struct va_gc_atomic;
213 friend struct va_heap;
214
215 unsigned m_alloc : 31;
216 unsigned m_using_auto_storage : 1;
217 unsigned m_num;
218};
219
220/* Calculate the number of slots to reserve a vector, making sure that
221 RESERVE slots are free. If EXACT grow exactly, otherwise grow
222 exponentially. PFX is the control data for the vector. */
223
224inline unsigned
225vec_prefix::calculate_allocation (vec_prefix *pfx, unsigned reserve,
226 bool exact)
227{
228 if (exact)
229 return (pfx ? pfx->m_num : 0) + reserve;
230 else if (!pfx)
231 return MAX (4, reserve)((4) > (reserve) ? (4) : (reserve));
232 return calculate_allocation_1 (pfx->m_alloc, pfx->m_num + reserve);
233}
234
235template<typename, typename, typename> struct vec;
236
237/* Valid vector layouts
238
239 vl_embed - Embeddable vector that uses the trailing array idiom.
240 vl_ptr - Space efficient vector that uses a pointer to an
241 embeddable vector. */
242struct vl_embed { };
243struct vl_ptr { };
244
245
246/* Types of supported allocations
247
248 va_heap - Allocation uses malloc/free.
249 va_gc - Allocation uses ggc_alloc.
250 va_gc_atomic - Same as GC, but individual elements of the array
251 do not need to be marked during collection. */
252
253/* Allocator type for heap vectors. */
254struct va_heap
255{
256 /* Heap vectors are frequently regular instances, so use the vl_ptr
257 layout for them. */
258 typedef vl_ptr default_layout;
259
260 template<typename T>
261 static void reserve (vec<T, va_heap, vl_embed> *&, unsigned, bool
262 CXX_MEM_STAT_INFO);
263
264 template<typename T>
265 static void release (vec<T, va_heap, vl_embed> *&);
266};
267
268
269/* Allocator for heap memory. Ensure there are at least RESERVE free
270 slots in V. If EXACT is true, grow exactly, else grow
271 exponentially. As a special case, if the vector had not been
272 allocated and RESERVE is 0, no vector will be created. */
273
274template<typename T>
275inline void
276va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact
277 MEM_STAT_DECL)
278{
279 size_t elt_size = sizeof (T);
280 unsigned alloc
281 = vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, exact);
282 gcc_checking_assert (alloc)((void)(!(alloc) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 282, __FUNCTION__), 0 : 0))
;
283
284 if (GATHER_STATISTICS0 && v)
285 v->m_vecpfx.release_overhead (v, elt_size * v->allocated (),
286 v->allocated (), false);
287
288 size_t size = vec<T, va_heap, vl_embed>::embedded_size (alloc);
289 unsigned nelem = v ? v->length () : 0;
290 v = static_cast <vec<T, va_heap, vl_embed> *> (xrealloc (v, size));
291 v->embedded_init (alloc, nelem);
292
293 if (GATHER_STATISTICS0)
294 v->m_vecpfx.register_overhead (v, alloc, elt_size PASS_MEM_STAT);
295}
296
297
298#if GCC_VERSION(4 * 1000 + 2) >= 4007
299#pragma GCC diagnostic push
300#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
301#endif
302
303/* Free the heap space allocated for vector V. */
304
305template<typename T>
306void
307va_heap::release (vec<T, va_heap, vl_embed> *&v)
308{
309 size_t elt_size = sizeof (T);
310 if (v == NULLnullptr)
311 return;
312
313 if (GATHER_STATISTICS0)
314 v->m_vecpfx.release_overhead (v, elt_size * v->allocated (),
315 v->allocated (), true);
316 ::free (v);
317 v = NULLnullptr;
318}
319
320#if GCC_VERSION(4 * 1000 + 2) >= 4007
321#pragma GCC diagnostic pop
322#endif
323
324/* Allocator type for GC vectors. Notice that we need the structure
325 declaration even if GC is not enabled. */
326
327struct va_gc
328{
329 /* Use vl_embed as the default layout for GC vectors. Due to GTY
330 limitations, GC vectors must always be pointers, so it is more
331 efficient to use a pointer to the vl_embed layout, rather than
332 using a pointer to a pointer as would be the case with vl_ptr. */
333 typedef vl_embed default_layout;
334
335 template<typename T, typename A>
336 static void reserve (vec<T, A, vl_embed> *&, unsigned, bool
337 CXX_MEM_STAT_INFO);
338
339 template<typename T, typename A>
340 static void release (vec<T, A, vl_embed> *&v);
341};
342
343
344/* Free GC memory used by V and reset V to NULL. */
345
346template<typename T, typename A>
347inline void
348va_gc::release (vec<T, A, vl_embed> *&v)
349{
350 if (v)
351 ::ggc_free (v);
352 v = NULLnullptr;
353}
354
355
356/* Allocator for GC memory. Ensure there are at least RESERVE free
357 slots in V. If EXACT is true, grow exactly, else grow
358 exponentially. As a special case, if the vector had not been
359 allocated and RESERVE is 0, no vector will be created. */
360
361template<typename T, typename A>
362void
363va_gc::reserve (vec<T, A, vl_embed> *&v, unsigned reserve, bool exact
364 MEM_STAT_DECL)
365{
366 unsigned alloc
367 = vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, exact);
13
Assuming 'v' is non-null
14
'?' condition is true
368 if (!alloc)
15
Assuming 'alloc' is 0
16
Taking true branch
369 {
370 ::ggc_free (v);
371 v = NULLnullptr;
17
Null pointer value stored to 'queue'
372 return;
373 }
374
375 /* Calculate the amount of space we want. */
376 size_t size = vec<T, A, vl_embed>::embedded_size (alloc);
377
378 /* Ask the allocator how much space it will really give us. */
379 size = ::ggc_round_alloc_size (size);
380
381 /* Adjust the number of slots accordingly. */
382 size_t vec_offset = sizeof (vec_prefix);
383 size_t elt_size = sizeof (T);
384 alloc = (size - vec_offset) / elt_size;
385
386 /* And finally, recalculate the amount of space we ask for. */
387 size = vec_offset + alloc * elt_size;
388
389 unsigned nelem = v ? v->length () : 0;
390 v = static_cast <vec<T, A, vl_embed> *> (::ggc_realloc (v, size
391 PASS_MEM_STAT));
392 v->embedded_init (alloc, nelem);
393}
394
395
396/* Allocator type for GC vectors. This is for vectors of types
397 atomics w.r.t. collection, so allocation and deallocation is
398 completely inherited from va_gc. */
399struct va_gc_atomic : va_gc
400{
401};
402
403
404/* Generic vector template. Default values for A and L indicate the
405 most commonly used strategies.
406
407 FIXME - Ideally, they would all be vl_ptr to encourage using regular
408 instances for vectors, but the existing GTY machinery is limited
409 in that it can only deal with GC objects that are pointers
410 themselves.
411
412 This means that vector operations that need to deal with
413 potentially NULL pointers, must be provided as free
414 functions (see the vec_safe_* functions above). */
415template<typename T,
416 typename A = va_heap,
417 typename L = typename A::default_layout>
418struct GTY((user)) vec
419{
420};
421
422/* Allow C++11 range-based 'for' to work directly on vec<T>*. */
423template<typename T, typename A, typename L>
424T* begin (vec<T,A,L> *v) { return v ? v->begin () : nullptr; }
425template<typename T, typename A, typename L>
426T* end (vec<T,A,L> *v) { return v ? v->end () : nullptr; }
427template<typename T, typename A, typename L>
428const T* begin (const vec<T,A,L> *v) { return v ? v->begin () : nullptr; }
429template<typename T, typename A, typename L>
430const T* end (const vec<T,A,L> *v) { return v ? v->end () : nullptr; }
431
432/* Generic vec<> debug helpers.
433
434 These need to be instantiated for each vec<TYPE> used throughout
435 the compiler like this:
436
437 DEFINE_DEBUG_VEC (TYPE)
438
439 The reason we have a debug_helper() is because GDB can't
440 disambiguate a plain call to debug(some_vec), and it must be called
441 like debug<TYPE>(some_vec). */
442
443template<typename T>
444void
445debug_helper (vec<T> &ref)
446{
447 unsigned i;
448 for (i = 0; i < ref.length (); ++i)
449 {
450 fprintf (stderrstderr, "[%d] = ", i);
451 debug_slim (ref[i]);
452 fputc ('\n', stderrstderr);
453 }
454}
455
456/* We need a separate va_gc variant here because default template
457 argument for functions cannot be used in c++-98. Once this
458 restriction is removed, those variant should be folded with the
459 above debug_helper. */
460
461template<typename T>
462void
463debug_helper (vec<T, va_gc> &ref)
464{
465 unsigned i;
466 for (i = 0; i < ref.length (); ++i)
467 {
468 fprintf (stderrstderr, "[%d] = ", i);
469 debug_slim (ref[i]);
470 fputc ('\n', stderrstderr);
471 }
472}
473
474/* Macro to define debug(vec<T>) and debug(vec<T, va_gc>) helper
475 functions for a type T. */
476
477#define DEFINE_DEBUG_VEC(T)template void debug_helper (vec<T> &); template void
debug_helper (vec<T, va_gc> &); __attribute__ ((__used__
)) void debug (vec<T> &ref) { debug_helper <T>
(ref); } __attribute__ ((__used__)) void debug (vec<T>
*ptr) { if (ptr) debug (*ptr); else fprintf (stderr, "<nil>\n"
); } __attribute__ ((__used__)) void debug (vec<T, va_gc>
&ref) { debug_helper <T> (ref); } __attribute__ ((
__used__)) void debug (vec<T, va_gc> *ptr) { if (ptr) debug
(*ptr); else fprintf (stderr, "<nil>\n"); }
\
478 template void debug_helper (vec<T> &); \
479 template void debug_helper (vec<T, va_gc> &); \
480 /* Define the vec<T> debug functions. */ \
481 DEBUG_FUNCTION__attribute__ ((__used__)) void \
482 debug (vec<T> &ref) \
483 { \
484 debug_helper <T> (ref); \
485 } \
486 DEBUG_FUNCTION__attribute__ ((__used__)) void \
487 debug (vec<T> *ptr) \
488 { \
489 if (ptr) \
490 debug (*ptr); \
491 else \
492 fprintf (stderrstderr, "<nil>\n"); \
493 } \
494 /* Define the vec<T, va_gc> debug functions. */ \
495 DEBUG_FUNCTION__attribute__ ((__used__)) void \
496 debug (vec<T, va_gc> &ref) \
497 { \
498 debug_helper <T> (ref); \
499 } \
500 DEBUG_FUNCTION__attribute__ ((__used__)) void \
501 debug (vec<T, va_gc> *ptr) \
502 { \
503 if (ptr) \
504 debug (*ptr); \
505 else \
506 fprintf (stderrstderr, "<nil>\n"); \
507 }
508
509/* Default-construct N elements in DST. */
510
511template <typename T>
512inline void
513vec_default_construct (T *dst, unsigned n)
514{
515#ifdef BROKEN_VALUE_INITIALIZATION
516 /* Versions of GCC before 4.4 sometimes leave certain objects
517 uninitialized when value initialized, though if the type has
518 user defined default ctor, that ctor is invoked. As a workaround
519 perform clearing first and then the value initialization, which
520 fixes the case when value initialization doesn't initialize due to
521 the bugs and should initialize to all zeros, but still allows
522 vectors for types with user defined default ctor that initializes
523 some or all elements to non-zero. If T has no user defined
524 default ctor and some non-static data members have user defined
525 default ctors that initialize to non-zero the workaround will
526 still not work properly; in that case we just need to provide
527 user defined default ctor. */
528 memset (dst, '\0', sizeof (T) * n);
529#endif
530 for ( ; n; ++dst, --n)
531 ::new (static_cast<void*>(dst)) T ();
532}
533
534/* Copy-construct N elements in DST from *SRC. */
535
536template <typename T>
537inline void
538vec_copy_construct (T *dst, const T *src, unsigned n)
539{
540 for ( ; n; ++dst, ++src, --n)
541 ::new (static_cast<void*>(dst)) T (*src);
542}
543
544/* Type to provide NULL values for vec<T, A, L>. This is used to
545 provide nil initializers for vec instances. Since vec must be
546 a POD, we cannot have proper ctor/dtor for it. To initialize
547 a vec instance, you can assign it the value vNULL. This isn't
548 needed for file-scope and function-local static vectors, which
549 are zero-initialized by default. */
550struct vnull
551{
552 template <typename T, typename A, typename L>
553 CONSTEXPRconstexpr operator vec<T, A, L> () const { return vec<T, A, L>(); }
554};
555extern vnull vNULL;
556
557
558/* Embeddable vector. These vectors are suitable to be embedded
559 in other data structures so that they can be pre-allocated in a
560 contiguous memory block.
561
562 Embeddable vectors are implemented using the trailing array idiom,
563 thus they are not resizeable without changing the address of the
564 vector object itself. This means you cannot have variables or
565 fields of embeddable vector type -- always use a pointer to a
566 vector. The one exception is the final field of a structure, which
567 could be a vector type.
568
569 You will have to use the embedded_size & embedded_init calls to
570 create such objects, and they will not be resizeable (so the 'safe'
571 allocation variants are not available).
572
573 Properties:
574
575 - The whole vector and control data are allocated in a single
576 contiguous block. It uses the trailing-vector idiom, so
577 allocation must reserve enough space for all the elements
578 in the vector plus its control data.
579 - The vector cannot be re-allocated.
580 - The vector cannot grow nor shrink.
581 - No indirections needed for access/manipulation.
582 - It requires 2 words of storage (prior to vector allocation). */
583
584template<typename T, typename A>
585struct GTY((user)) vec<T, A, vl_embed>
586{
587public:
588 unsigned allocated (void) const { return m_vecpfx.m_alloc; }
589 unsigned length (void) const { return m_vecpfx.m_num; }
590 bool is_empty (void) const { return m_vecpfx.m_num == 0; }
591 T *address (void) { return m_vecdata; }
592 const T *address (void) const { return m_vecdata; }
593 T *begin () { return address (); }
594 const T *begin () const { return address (); }
595 T *end () { return address () + length (); }
596 const T *end () const { return address () + length (); }
597 const T &operator[] (unsigned) const;
598 T &operator[] (unsigned);
599 T &last (void);
600 bool space (unsigned) const;
601 bool iterate (unsigned, T *) const;
602 bool iterate (unsigned, T **) const;
603 vec *copy (ALONE_CXX_MEM_STAT_INFO) const;
604 void splice (const vec &);
605 void splice (const vec *src);
606 T *quick_push (const T &);
607 T &pop (void);
608 void truncate (unsigned);
609 void quick_insert (unsigned, const T &);
610 void ordered_remove (unsigned);
611 void unordered_remove (unsigned);
612 void block_remove (unsigned, unsigned);
613 void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *));
614 void sort (int (*) (const void *, const void *, void *), void *);
615 T *bsearch (const void *key, int (*compar)(const void *, const void *));
616 T *bsearch (const void *key,
617 int (*compar)(const void *, const void *, void *), void *);
618 unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
619 bool contains (const T &search) const;
620 static size_t embedded_size (unsigned);
621 void embedded_init (unsigned, unsigned = 0, unsigned = 0);
622 void quick_grow (unsigned len);
623 void quick_grow_cleared (unsigned len);
624
625 /* vec class can access our internal data and functions. */
626 template <typename, typename, typename> friend struct vec;
627
628 /* The allocator types also need access to our internals. */
629 friend struct va_gc;
630 friend struct va_gc_atomic;
631 friend struct va_heap;
632
633 /* FIXME - These fields should be private, but we need to cater to
634 compilers that have stricter notions of PODness for types. */
635 vec_prefix m_vecpfx;
636 T m_vecdata[1];
637};
638
639
640/* Convenience wrapper functions to use when dealing with pointers to
641 embedded vectors. Some functionality for these vectors must be
642 provided via free functions for these reasons:
643
644 1- The pointer may be NULL (e.g., before initial allocation).
645
646 2- When the vector needs to grow, it must be reallocated, so
647 the pointer will change its value.
648
649 Because of limitations with the current GC machinery, all vectors
650 in GC memory *must* be pointers. */
651
652
653/* If V contains no room for NELEMS elements, return false. Otherwise,
654 return true. */
655template<typename T, typename A>
656inline bool
657vec_safe_space (const vec<T, A, vl_embed> *v, unsigned nelems)
658{
659 return v ? v->space (nelems) : nelems == 0;
660}
661
662
663/* If V is NULL, return 0. Otherwise, return V->length(). */
664template<typename T, typename A>
665inline unsigned
666vec_safe_length (const vec<T, A, vl_embed> *v)
667{
668 return v ? v->length () : 0;
669}
670
671
672/* If V is NULL, return NULL. Otherwise, return V->address(). */
673template<typename T, typename A>
674inline T *
675vec_safe_address (vec<T, A, vl_embed> *v)
676{
677 return v ? v->address () : NULLnullptr;
678}
679
680
681/* If V is NULL, return true. Otherwise, return V->is_empty(). */
682template<typename T, typename A>
683inline bool
684vec_safe_is_empty (vec<T, A, vl_embed> *v)
685{
686 return v ? v->is_empty () : true;
687}
688
689/* If V does not have space for NELEMS elements, call
690 V->reserve(NELEMS, EXACT). */
691template<typename T, typename A>
692inline bool
693vec_safe_reserve (vec<T, A, vl_embed> *&v, unsigned nelems, bool exact = false
694 CXX_MEM_STAT_INFO)
695{
696 bool extend = nelems
8.1
'nelems' is 1
8.1
'nelems' is 1
? !vec_safe_space (v, nelems) : false;
9
'?' condition is true
10
Assuming the condition is true
697 if (extend
10.1
'extend' is true
10.1
'extend' is true
)
11
Taking true branch
698 A::reserve (v, nelems, exact PASS_MEM_STAT);
12
Calling 'va_gc::reserve'
18
Returning from 'va_gc::reserve'
699 return extend;
700}
701
702template<typename T, typename A>
703inline bool
704vec_safe_reserve_exact (vec<T, A, vl_embed> *&v, unsigned nelems
705 CXX_MEM_STAT_INFO)
706{
707 return vec_safe_reserve (v, nelems, true PASS_MEM_STAT);
708}
709
710
711/* Allocate GC memory for V with space for NELEMS slots. If NELEMS
712 is 0, V is initialized to NULL. */
713
714template<typename T, typename A>
715inline void
716vec_alloc (vec<T, A, vl_embed> *&v, unsigned nelems CXX_MEM_STAT_INFO)
717{
718 v = NULLnullptr;
719 vec_safe_reserve (v, nelems, false PASS_MEM_STAT);
720}
721
722
723/* Free the GC memory allocated by vector V and set it to NULL. */
724
725template<typename T, typename A>
726inline void
727vec_free (vec<T, A, vl_embed> *&v)
728{
729 A::release (v);
730}
731
732
733/* Grow V to length LEN. Allocate it, if necessary. */
734template<typename T, typename A>
735inline void
736vec_safe_grow (vec<T, A, vl_embed> *&v, unsigned len,
737 bool exact = false CXX_MEM_STAT_INFO)
738{
739 unsigned oldlen = vec_safe_length (v);
740 gcc_checking_assert (len >= oldlen)((void)(!(len >= oldlen) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 740, __FUNCTION__), 0 : 0))
;
741 vec_safe_reserve (v, len - oldlen, exact PASS_MEM_STAT);
742 v->quick_grow (len);
743}
744
745
746/* If V is NULL, allocate it. Call V->safe_grow_cleared(LEN). */
747template<typename T, typename A>
748inline void
749vec_safe_grow_cleared (vec<T, A, vl_embed> *&v, unsigned len,
750 bool exact = false CXX_MEM_STAT_INFO)
751{
752 unsigned oldlen = vec_safe_length (v);
753 vec_safe_grow (v, len, exact PASS_MEM_STAT);
754 vec_default_construct (v->address () + oldlen, len - oldlen);
755}
756
757
758/* Assume V is not NULL. */
759
760template<typename T>
761inline void
762vec_safe_grow_cleared (vec<T, va_heap, vl_ptr> *&v,
763 unsigned len, bool exact = false CXX_MEM_STAT_INFO)
764{
765 v->safe_grow_cleared (len, exact PASS_MEM_STAT);
766}
767
768/* If V does not have space for NELEMS elements, call
769 V->reserve(NELEMS, EXACT). */
770
771template<typename T>
772inline bool
773vec_safe_reserve (vec<T, va_heap, vl_ptr> *&v, unsigned nelems, bool exact = false
774 CXX_MEM_STAT_INFO)
775{
776 return v->reserve (nelems, exact);
777}
778
779
780/* If V is NULL return false, otherwise return V->iterate(IX, PTR). */
781template<typename T, typename A>
782inline bool
783vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T **ptr)
784{
785 if (v)
786 return v->iterate (ix, ptr);
787 else
788 {
789 *ptr = 0;
790 return false;
791 }
792}
793
794template<typename T, typename A>
795inline bool
796vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T *ptr)
797{
798 if (v)
799 return v->iterate (ix, ptr);
800 else
801 {
802 *ptr = 0;
803 return false;
804 }
805}
806
807
808/* If V has no room for one more element, reallocate it. Then call
809 V->quick_push(OBJ). */
810template<typename T, typename A>
811inline T *
812vec_safe_push (vec<T, A, vl_embed> *&v, const T &obj CXX_MEM_STAT_INFO)
813{
814 vec_safe_reserve (v, 1, false PASS_MEM_STAT);
8
Calling 'vec_safe_reserve<tree_node *, va_gc>'
19
Returning from 'vec_safe_reserve<tree_node *, va_gc>'
815 return v->quick_push (obj);
20
Called C++ object pointer is null
816}
817
818
819/* if V has no room for one more element, reallocate it. Then call
820 V->quick_insert(IX, OBJ). */
821template<typename T, typename A>
822inline void
823vec_safe_insert (vec<T, A, vl_embed> *&v, unsigned ix, const T &obj
824 CXX_MEM_STAT_INFO)
825{
826 vec_safe_reserve (v, 1, false PASS_MEM_STAT);
827 v->quick_insert (ix, obj);
828}
829
830
831/* If V is NULL, do nothing. Otherwise, call V->truncate(SIZE). */
832template<typename T, typename A>
833inline void
834vec_safe_truncate (vec<T, A, vl_embed> *v, unsigned size)
835{
836 if (v)
837 v->truncate (size);
838}
839
840
841/* If SRC is not NULL, return a pointer to a copy of it. */
842template<typename T, typename A>
843inline vec<T, A, vl_embed> *
844vec_safe_copy (vec<T, A, vl_embed> *src CXX_MEM_STAT_INFO)
845{
846 return src ? src->copy (ALONE_PASS_MEM_STAT) : NULLnullptr;
847}
848
849/* Copy the elements from SRC to the end of DST as if by memcpy.
850 Reallocate DST, if necessary. */
851template<typename T, typename A>
852inline void
853vec_safe_splice (vec<T, A, vl_embed> *&dst, const vec<T, A, vl_embed> *src
854 CXX_MEM_STAT_INFO)
855{
856 unsigned src_len = vec_safe_length (src);
857 if (src_len)
858 {
859 vec_safe_reserve_exact (dst, vec_safe_length (dst) + src_len
860 PASS_MEM_STAT);
861 dst->splice (*src);
862 }
863}
864
865/* Return true if SEARCH is an element of V. Note that this is O(N) in the
866 size of the vector and so should be used with care. */
867
868template<typename T, typename A>
869inline bool
870vec_safe_contains (vec<T, A, vl_embed> *v, const T &search)
871{
872 return v ? v->contains (search) : false;
873}
874
875/* Index into vector. Return the IX'th element. IX must be in the
876 domain of the vector. */
877
878template<typename T, typename A>
879inline const T &
880vec<T, A, vl_embed>::operator[] (unsigned ix) const
881{
882 gcc_checking_assert (ix < m_vecpfx.m_num)((void)(!(ix < m_vecpfx.m_num) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 882, __FUNCTION__), 0 : 0))
;
883 return m_vecdata[ix];
884}
885
886template<typename T, typename A>
887inline T &
888vec<T, A, vl_embed>::operator[] (unsigned ix)
889{
890 gcc_checking_assert (ix < m_vecpfx.m_num)((void)(!(ix < m_vecpfx.m_num) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 890, __FUNCTION__), 0 : 0))
;
891 return m_vecdata[ix];
892}
893
894
895/* Get the final element of the vector, which must not be empty. */
896
897template<typename T, typename A>
898inline T &
899vec<T, A, vl_embed>::last (void)
900{
901 gcc_checking_assert (m_vecpfx.m_num > 0)((void)(!(m_vecpfx.m_num > 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 901, __FUNCTION__), 0 : 0))
;
902 return (*this)[m_vecpfx.m_num - 1];
903}
904
905
906/* If this vector has space for NELEMS additional entries, return
907 true. You usually only need to use this if you are doing your
908 own vector reallocation, for instance on an embedded vector. This
909 returns true in exactly the same circumstances that vec::reserve
910 will. */
911
912template<typename T, typename A>
913inline bool
914vec<T, A, vl_embed>::space (unsigned nelems) const
915{
916 return m_vecpfx.m_alloc - m_vecpfx.m_num >= nelems;
917}
918
919
920/* Return iteration condition and update PTR to point to the IX'th
921 element of this vector. Use this to iterate over the elements of a
922 vector as follows,
923
924 for (ix = 0; vec<T, A>::iterate (v, ix, &ptr); ix++)
925 continue; */
926
927template<typename T, typename A>
928inline bool
929vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const
930{
931 if (ix < m_vecpfx.m_num)
932 {
933 *ptr = m_vecdata[ix];
934 return true;
935 }
936 else
937 {
938 *ptr = 0;
939 return false;
940 }
941}
942
943
944/* Return iteration condition and update *PTR to point to the
945 IX'th element of this vector. Use this to iterate over the
946 elements of a vector as follows,
947
948 for (ix = 0; v->iterate (ix, &ptr); ix++)
949 continue;
950
951 This variant is for vectors of objects. */
952
953template<typename T, typename A>
954inline bool
955vec<T, A, vl_embed>::iterate (unsigned ix, T **ptr) const
956{
957 if (ix < m_vecpfx.m_num)
958 {
959 *ptr = CONST_CAST (T *, &m_vecdata[ix])(const_cast<T *> ((&m_vecdata[ix])));
960 return true;
961 }
962 else
963 {
964 *ptr = 0;
965 return false;
966 }
967}
968
969
970/* Return a pointer to a copy of this vector. */
971
972template<typename T, typename A>
973inline vec<T, A, vl_embed> *
974vec<T, A, vl_embed>::copy (ALONE_MEM_STAT_DECLvoid) const
975{
976 vec<T, A, vl_embed> *new_vec = NULLnullptr;
977 unsigned len = length ();
978 if (len)
979 {
980 vec_alloc (new_vec, len PASS_MEM_STAT);
981 new_vec->embedded_init (len, len);
982 vec_copy_construct (new_vec->address (), m_vecdata, len);
983 }
984 return new_vec;
985}
986
987
988/* Copy the elements from SRC to the end of this vector as if by memcpy.
989 The vector must have sufficient headroom available. */
990
991template<typename T, typename A>
992inline void
993vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> &src)
994{
995 unsigned len = src.length ();
996 if (len)
997 {
998 gcc_checking_assert (space (len))((void)(!(space (len)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 998, __FUNCTION__), 0 : 0))
;
999 vec_copy_construct (end (), src.address (), len);
1000 m_vecpfx.m_num += len;
1001 }
1002}
1003
1004template<typename T, typename A>
1005inline void
1006vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> *src)
1007{
1008 if (src)
1009 splice (*src);
1010}
1011
1012
1013/* Push OBJ (a new element) onto the end of the vector. There must be
1014 sufficient space in the vector. Return a pointer to the slot
1015 where OBJ was inserted. */
1016
1017template<typename T, typename A>
1018inline T *
1019vec<T, A, vl_embed>::quick_push (const T &obj)
1020{
1021 gcc_checking_assert (space (1))((void)(!(space (1)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1021, __FUNCTION__), 0 : 0))
;
1022 T *slot = &m_vecdata[m_vecpfx.m_num++];
1023 *slot = obj;
1024 return slot;
1025}
1026
1027
1028/* Pop and return the last element off the end of the vector. */
1029
1030template<typename T, typename A>
1031inline T &
1032vec<T, A, vl_embed>::pop (void)
1033{
1034 gcc_checking_assert (length () > 0)((void)(!(length () > 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1034, __FUNCTION__), 0 : 0))
;
1035 return m_vecdata[--m_vecpfx.m_num];
1036}
1037
1038
1039/* Set the length of the vector to SIZE. The new length must be less
1040 than or equal to the current length. This is an O(1) operation. */
1041
1042template<typename T, typename A>
1043inline void
1044vec<T, A, vl_embed>::truncate (unsigned size)
1045{
1046 gcc_checking_assert (length () >= size)((void)(!(length () >= size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1046, __FUNCTION__), 0 : 0))
;
1047 m_vecpfx.m_num = size;
1048}
1049
1050
1051/* Insert an element, OBJ, at the IXth position of this vector. There
1052 must be sufficient space. */
1053
1054template<typename T, typename A>
1055inline void
1056vec<T, A, vl_embed>::quick_insert (unsigned ix, const T &obj)
1057{
1058 gcc_checking_assert (length () < allocated ())((void)(!(length () < allocated ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1058, __FUNCTION__), 0 : 0))
;
1059 gcc_checking_assert (ix <= length ())((void)(!(ix <= length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1059, __FUNCTION__), 0 : 0))
;
1060 T *slot = &m_vecdata[ix];
1061 memmove (slot + 1, slot, (m_vecpfx.m_num++ - ix) * sizeof (T));
1062 *slot = obj;
1063}
1064
1065
1066/* Remove an element from the IXth position of this vector. Ordering of
1067 remaining elements is preserved. This is an O(N) operation due to
1068 memmove. */
1069
1070template<typename T, typename A>
1071inline void
1072vec<T, A, vl_embed>::ordered_remove (unsigned ix)
1073{
1074 gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1074, __FUNCTION__), 0 : 0))
;
1075 T *slot = &m_vecdata[ix];
1076 memmove (slot, slot + 1, (--m_vecpfx.m_num - ix) * sizeof (T));
1077}
1078
1079
1080/* Remove elements in [START, END) from VEC for which COND holds. Ordering of
1081 remaining elements is preserved. This is an O(N) operation. */
1082
1083#define VEC_ORDERED_REMOVE_IF_FROM_TO(vec, read_index, write_index, \{ ((void)(!((end) <= (vec).length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1084, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (start); read_index < (end); ++read_index) { elem_ptr =
&(vec)[read_index]; bool remove_p = (cond); if (remove_p
) continue; if (read_index != write_index) (vec)[write_index]
= (vec)[read_index]; write_index++; } if (read_index - write_index
> 0) (vec).block_remove (write_index, read_index - write_index
); }
1084 elem_ptr, start, end, cond){ ((void)(!((end) <= (vec).length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1084, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (start); read_index < (end); ++read_index) { elem_ptr =
&(vec)[read_index]; bool remove_p = (cond); if (remove_p
) continue; if (read_index != write_index) (vec)[write_index]
= (vec)[read_index]; write_index++; } if (read_index - write_index
> 0) (vec).block_remove (write_index, read_index - write_index
); }
\
1085 { \
1086 gcc_assert ((end) <= (vec).length ())((void)(!((end) <= (vec).length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1086, __FUNCTION__), 0 : 0))
; \
1087 for (read_index = write_index = (start); read_index < (end); \
1088 ++read_index) \
1089 { \
1090 elem_ptr = &(vec)[read_index]; \
1091 bool remove_p = (cond); \
1092 if (remove_p) \
1093 continue; \
1094 \
1095 if (read_index != write_index) \
1096 (vec)[write_index] = (vec)[read_index]; \
1097 \
1098 write_index++; \
1099 } \
1100 \
1101 if (read_index - write_index > 0) \
1102 (vec).block_remove (write_index, read_index - write_index); \
1103 }
1104
1105
1106/* Remove elements from VEC for which COND holds. Ordering of remaining
1107 elements is preserved. This is an O(N) operation. */
1108
1109#define VEC_ORDERED_REMOVE_IF(vec, read_index, write_index, elem_ptr, \{ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1110, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
1110 cond){ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1110, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
\
1111 VEC_ORDERED_REMOVE_IF_FROM_TO ((vec), read_index, write_index, \{ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1112, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
1112 elem_ptr, 0, (vec).length (), (cond)){ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1112, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
1113
1114/* Remove an element from the IXth position of this vector. Ordering of
1115 remaining elements is destroyed. This is an O(1) operation. */
1116
1117template<typename T, typename A>
1118inline void
1119vec<T, A, vl_embed>::unordered_remove (unsigned ix)
1120{
1121 gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1121, __FUNCTION__), 0 : 0))
;
1122 m_vecdata[ix] = m_vecdata[--m_vecpfx.m_num];
1123}
1124
1125
1126/* Remove LEN elements starting at the IXth. Ordering is retained.
1127 This is an O(N) operation due to memmove. */
1128
1129template<typename T, typename A>
1130inline void
1131vec<T, A, vl_embed>::block_remove (unsigned ix, unsigned len)
1132{
1133 gcc_checking_assert (ix + len <= length ())((void)(!(ix + len <= length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1133, __FUNCTION__), 0 : 0))
;
1134 T *slot = &m_vecdata[ix];
1135 m_vecpfx.m_num -= len;
1136 memmove (slot, slot + len, (m_vecpfx.m_num - ix) * sizeof (T));
1137}
1138
1139
1140/* Sort the contents of this vector with qsort. CMP is the comparison
1141 function to pass to qsort. */
1142
1143template<typename T, typename A>
1144inline void
1145vec<T, A, vl_embed>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *))
1146{
1147 if (length () > 1)
1148 gcc_qsort (address (), length (), sizeof (T), cmp);
1149}
1150
1151/* Sort the contents of this vector with qsort. CMP is the comparison
1152 function to pass to qsort. */
1153
1154template<typename T, typename A>
1155inline void
1156vec<T, A, vl_embed>::sort (int (*cmp) (const void *, const void *, void *),
1157 void *data)
1158{
1159 if (length () > 1)
1160 gcc_sort_r (address (), length (), sizeof (T), cmp, data);
1161}
1162
1163
1164/* Search the contents of the sorted vector with a binary search.
1165 CMP is the comparison function to pass to bsearch. */
1166
1167template<typename T, typename A>
1168inline T *
1169vec<T, A, vl_embed>::bsearch (const void *key,
1170 int (*compar) (const void *, const void *))
1171{
1172 const void *base = this->address ();
1173 size_t nmemb = this->length ();
1174 size_t size = sizeof (T);
1175 /* The following is a copy of glibc stdlib-bsearch.h. */
1176 size_t l, u, idx;
1177 const void *p;
1178 int comparison;
1179
1180 l = 0;
1181 u = nmemb;
1182 while (l < u)
1183 {
1184 idx = (l + u) / 2;
1185 p = (const void *) (((const char *) base) + (idx * size));
1186 comparison = (*compar) (key, p);
1187 if (comparison < 0)
1188 u = idx;
1189 else if (comparison > 0)
1190 l = idx + 1;
1191 else
1192 return (T *)const_cast<void *>(p);
1193 }
1194
1195 return NULLnullptr;
1196}
1197
1198/* Search the contents of the sorted vector with a binary search.
1199 CMP is the comparison function to pass to bsearch. */
1200
1201template<typename T, typename A>
1202inline T *
1203vec<T, A, vl_embed>::bsearch (const void *key,
1204 int (*compar) (const void *, const void *,
1205 void *), void *data)
1206{
1207 const void *base = this->address ();
1208 size_t nmemb = this->length ();
1209 size_t size = sizeof (T);
1210 /* The following is a copy of glibc stdlib-bsearch.h. */
1211 size_t l, u, idx;
1212 const void *p;
1213 int comparison;
1214
1215 l = 0;
1216 u = nmemb;
1217 while (l < u)
1218 {
1219 idx = (l + u) / 2;
1220 p = (const void *) (((const char *) base) + (idx * size));
1221 comparison = (*compar) (key, p, data);
1222 if (comparison < 0)
1223 u = idx;
1224 else if (comparison > 0)
1225 l = idx + 1;
1226 else
1227 return (T *)const_cast<void *>(p);
1228 }
1229
1230 return NULLnullptr;
1231}
1232
1233/* Return true if SEARCH is an element of V. Note that this is O(N) in the
1234 size of the vector and so should be used with care. */
1235
1236template<typename T, typename A>
1237inline bool
1238vec<T, A, vl_embed>::contains (const T &search) const
1239{
1240 unsigned int len = length ();
1241 for (unsigned int i = 0; i < len; i++)
1242 if ((*this)[i] == search)
1243 return true;
1244
1245 return false;
1246}
1247
1248/* Find and return the first position in which OBJ could be inserted
1249 without changing the ordering of this vector. LESSTHAN is a
1250 function that returns true if the first argument is strictly less
1251 than the second. */
1252
1253template<typename T, typename A>
1254unsigned
1255vec<T, A, vl_embed>::lower_bound (T obj, bool (*lessthan)(const T &, const T &))
1256 const
1257{
1258 unsigned int len = length ();
1259 unsigned int half, middle;
1260 unsigned int first = 0;
1261 while (len > 0)
1262 {
1263 half = len / 2;
1264 middle = first;
1265 middle += half;
1266 T middle_elem = (*this)[middle];
1267 if (lessthan (middle_elem, obj))
1268 {
1269 first = middle;
1270 ++first;
1271 len = len - half - 1;
1272 }
1273 else
1274 len = half;
1275 }
1276 return first;
1277}
1278
1279
1280/* Return the number of bytes needed to embed an instance of an
1281 embeddable vec inside another data structure.
1282
1283 Use these methods to determine the required size and initialization
1284 of a vector V of type T embedded within another structure (as the
1285 final member):
1286
1287 size_t vec<T, A, vl_embed>::embedded_size (unsigned alloc);
1288 void v->embedded_init (unsigned alloc, unsigned num);
1289
1290 These allow the caller to perform the memory allocation. */
1291
1292template<typename T, typename A>
1293inline size_t
1294vec<T, A, vl_embed>::embedded_size (unsigned alloc)
1295{
1296 struct alignas (T) U { char data[sizeof (T)]; };
1297 typedef vec<U, A, vl_embed> vec_embedded;
1298 typedef typename std::conditional<std::is_standard_layout<T>::value,
1299 vec, vec_embedded>::type vec_stdlayout;
1300 static_assert (sizeof (vec_stdlayout) == sizeof (vec), "");
1301 static_assert (alignof (vec_stdlayout) == alignof (vec), "");
1302 return offsetof (vec_stdlayout, m_vecdata)__builtin_offsetof(vec_stdlayout, m_vecdata) + alloc * sizeof (T);
1303}
1304
1305
1306/* Initialize the vector to contain room for ALLOC elements and
1307 NUM active elements. */
1308
1309template<typename T, typename A>
1310inline void
1311vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num, unsigned aut)
1312{
1313 m_vecpfx.m_alloc = alloc;
1314 m_vecpfx.m_using_auto_storage = aut;
1315 m_vecpfx.m_num = num;
1316}
1317
1318
1319/* Grow the vector to a specific length. LEN must be as long or longer than
1320 the current length. The new elements are uninitialized. */
1321
1322template<typename T, typename A>
1323inline void
1324vec<T, A, vl_embed>::quick_grow (unsigned len)
1325{
1326 gcc_checking_assert (length () <= len && len <= m_vecpfx.m_alloc)((void)(!(length () <= len && len <= m_vecpfx.m_alloc
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1326, __FUNCTION__), 0 : 0))
;
1327 m_vecpfx.m_num = len;
1328}
1329
1330
1331/* Grow the vector to a specific length. LEN must be as long or longer than
1332 the current length. The new elements are initialized to zero. */
1333
1334template<typename T, typename A>
1335inline void
1336vec<T, A, vl_embed>::quick_grow_cleared (unsigned len)
1337{
1338 unsigned oldlen = length ();
1339 size_t growby = len - oldlen;
1340 quick_grow (len);
1341 if (growby != 0)
1342 vec_default_construct (address () + oldlen, growby);
1343}
1344
1345/* Garbage collection support for vec<T, A, vl_embed>. */
1346
1347template<typename T>
1348void
1349gt_ggc_mx (vec<T, va_gc> *v)
1350{
1351 extern void gt_ggc_mx (T &);
1352 for (unsigned i = 0; i < v->length (); i++)
1353 gt_ggc_mx ((*v)[i]);
1354}
1355
1356template<typename T>
1357void
1358gt_ggc_mx (vec<T, va_gc_atomic, vl_embed> *v ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
1359{
1360 /* Nothing to do. Vectors of atomic types wrt GC do not need to
1361 be traversed. */
1362}
1363
1364
1365/* PCH support for vec<T, A, vl_embed>. */
1366
1367template<typename T, typename A>
1368void
1369gt_pch_nx (vec<T, A, vl_embed> *v)
1370{
1371 extern void gt_pch_nx (T &);
1372 for (unsigned i = 0; i < v->length (); i++)
1373 gt_pch_nx ((*v)[i]);
1374}
1375
1376template<typename T, typename A>
1377void
1378gt_pch_nx (vec<T *, A, vl_embed> *v, gt_pointer_operator op, void *cookie)
1379{
1380 for (unsigned i = 0; i < v->length (); i++)
1381 op (&((*v)[i]), cookie);
1382}
1383
1384template<typename T, typename A>
1385void
1386gt_pch_nx (vec<T, A, vl_embed> *v, gt_pointer_operator op, void *cookie)
1387{
1388 extern void gt_pch_nx (T *, gt_pointer_operator, void *);
1389 for (unsigned i = 0; i < v->length (); i++)
1390 gt_pch_nx (&((*v)[i]), op, cookie);
1391}
1392
1393
1394/* Space efficient vector. These vectors can grow dynamically and are
1395 allocated together with their control data. They are suited to be
1396 included in data structures. Prior to initial allocation, they
1397 only take a single word of storage.
1398
1399 These vectors are implemented as a pointer to an embeddable vector.
1400 The semantics allow for this pointer to be NULL to represent empty
1401 vectors. This way, empty vectors occupy minimal space in the
1402 structure containing them.
1403
1404 Properties:
1405
1406 - The whole vector and control data are allocated in a single
1407 contiguous block.
1408 - The whole vector may be re-allocated.
1409 - Vector data may grow and shrink.
1410 - Access and manipulation requires a pointer test and
1411 indirection.
1412 - It requires 1 word of storage (prior to vector allocation).
1413
1414
1415 Limitations:
1416
1417 These vectors must be PODs because they are stored in unions.
1418 (http://en.wikipedia.org/wiki/Plain_old_data_structures).
1419 As long as we use C++03, we cannot have constructors nor
1420 destructors in classes that are stored in unions. */
1421
1422template<typename T>
1423struct vec<T, va_heap, vl_ptr>
1424{
1425public:
1426 /* Memory allocation and deallocation for the embedded vector.
1427 Needed because we cannot have proper ctors/dtors defined. */
1428 void create (unsigned nelems CXX_MEM_STAT_INFO);
1429 void release (void);
1430
1431 /* Vector operations. */
1432 bool exists (void) const
1433 { return m_vec != NULLnullptr; }
1434
1435 bool is_empty (void) const
1436 { return m_vec ? m_vec->is_empty () : true; }
1437
1438 unsigned length (void) const
1439 { return m_vec ? m_vec->length () : 0; }
1440
1441 T *address (void)
1442 { return m_vec ? m_vec->m_vecdata : NULLnullptr; }
1443
1444 const T *address (void) const
1445 { return m_vec ? m_vec->m_vecdata : NULLnullptr; }
1446
1447 T *begin () { return address (); }
1448 const T *begin () const { return address (); }
1449 T *end () { return begin () + length (); }
1450 const T *end () const { return begin () + length (); }
1451 const T &operator[] (unsigned ix) const
1452 { return (*m_vec)[ix]; }
1453
1454 bool operator!=(const vec &other) const
1455 { return !(*this == other); }
1456
1457 bool operator==(const vec &other) const
1458 { return address () == other.address (); }
1459
1460 T &operator[] (unsigned ix)
1461 { return (*m_vec)[ix]; }
1462
1463 T &last (void)
1464 { return m_vec->last (); }
1465
1466 bool space (int nelems) const
1467 { return m_vec ? m_vec->space (nelems) : nelems == 0; }
1468
1469 bool iterate (unsigned ix, T *p) const;
1470 bool iterate (unsigned ix, T **p) const;
1471 vec copy (ALONE_CXX_MEM_STAT_INFO) const;
1472 bool reserve (unsigned, bool = false CXX_MEM_STAT_INFO);
1473 bool reserve_exact (unsigned CXX_MEM_STAT_INFO);
1474 void splice (const vec &);
1475 void safe_splice (const vec & CXX_MEM_STAT_INFO);
1476 T *quick_push (const T &);
1477 T *safe_push (const T &CXX_MEM_STAT_INFO);
1478 T &pop (void);
1479 void truncate (unsigned);
1480 void safe_grow (unsigned, bool = false CXX_MEM_STAT_INFO);
1481 void safe_grow_cleared (unsigned, bool = false CXX_MEM_STAT_INFO);
1482 void quick_grow (unsigned);
1483 void quick_grow_cleared (unsigned);
1484 void quick_insert (unsigned, const T &);
1485 void safe_insert (unsigned, const T & CXX_MEM_STAT_INFO);
1486 void ordered_remove (unsigned);
1487 void unordered_remove (unsigned);
1488 void block_remove (unsigned, unsigned);
1489 void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *));
1490 void sort (int (*) (const void *, const void *, void *), void *);
1491 T *bsearch (const void *key, int (*compar)(const void *, const void *));
1492 T *bsearch (const void *key,
1493 int (*compar)(const void *, const void *, void *), void *);
1494 unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
1495 bool contains (const T &search) const;
1496 void reverse (void);
1497
1498 bool using_auto_storage () const;
1499
1500 /* FIXME - This field should be private, but we need to cater to
1501 compilers that have stricter notions of PODness for types. */
1502 vec<T, va_heap, vl_embed> *m_vec;
1503};
1504
1505
1506/* auto_vec is a subclass of vec that automatically manages creating and
1507 releasing the internal vector. If N is non zero then it has N elements of
1508 internal storage. The default is no internal storage, and you probably only
1509 want to ask for internal storage for vectors on the stack because if the
1510 size of the vector is larger than the internal storage that space is wasted.
1511 */
1512template<typename T, size_t N = 0>
1513class auto_vec : public vec<T, va_heap>
1514{
1515public:
1516 auto_vec ()
1517 {
1518 m_auto.embedded_init (MAX (N, 2)((N) > (2) ? (N) : (2)), 0, 1);
1519 this->m_vec = &m_auto;
1520 }
1521
1522 auto_vec (size_t s)
1523 {
1524 if (s > N)
1525 {
1526 this->create (s);
1527 return;
1528 }
1529
1530 m_auto.embedded_init (MAX (N, 2)((N) > (2) ? (N) : (2)), 0, 1);
1531 this->m_vec = &m_auto;
1532 }
1533
1534 ~auto_vec ()
1535 {
1536 this->release ();
1537 }
1538
1539private:
1540 vec<T, va_heap, vl_embed> m_auto;
1541 T m_data[MAX (N - 1, 1)((N - 1) > (1) ? (N - 1) : (1))];
1542};
1543
1544/* auto_vec is a sub class of vec whose storage is released when it is
1545 destroyed. */
1546template<typename T>
1547class auto_vec<T, 0> : public vec<T, va_heap>
1548{
1549public:
1550 auto_vec () { this->m_vec = NULLnullptr; }
1551 auto_vec (size_t n) { this->create (n); }
1552 ~auto_vec () { this->release (); }
1553
1554 auto_vec (vec<T, va_heap>&& r)
1555 {
1556 gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1556, __FUNCTION__), 0 : 0))
;
1557 this->m_vec = r.m_vec;
1558 r.m_vec = NULLnullptr;
1559 }
1560 auto_vec& operator= (vec<T, va_heap>&& r)
1561 {
1562 gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1562, __FUNCTION__), 0 : 0))
;
1563 this->release ();
1564 this->m_vec = r.m_vec;
1565 r.m_vec = NULLnullptr;
1566 return *this;
1567 }
1568};
1569
1570
1571/* Allocate heap memory for pointer V and create the internal vector
1572 with space for NELEMS elements. If NELEMS is 0, the internal
1573 vector is initialized to empty. */
1574
1575template<typename T>
1576inline void
1577vec_alloc (vec<T> *&v, unsigned nelems CXX_MEM_STAT_INFO)
1578{
1579 v = new vec<T>;
1580 v->create (nelems PASS_MEM_STAT);
1581}
1582
1583
1584/* A subclass of auto_vec <char *> that frees all of its elements on
1585 deletion. */
1586
1587class auto_string_vec : public auto_vec <char *>
1588{
1589 public:
1590 ~auto_string_vec ();
1591};
1592
1593/* A subclass of auto_vec <T *> that deletes all of its elements on
1594 destruction.
1595
1596 This is a crude way for a vec to "own" the objects it points to
1597 and clean up automatically.
1598
1599 For example, no attempt is made to delete elements when an item
1600 within the vec is overwritten.
1601
1602 We can't rely on gnu::unique_ptr within a container,
1603 since we can't rely on move semantics in C++98. */
1604
1605template <typename T>
1606class auto_delete_vec : public auto_vec <T *>
1607{
1608 public:
1609 auto_delete_vec () {}
1610 auto_delete_vec (size_t s) : auto_vec <T *> (s) {}
1611
1612 ~auto_delete_vec ();
1613
1614private:
1615 DISABLE_COPY_AND_ASSIGN(auto_delete_vec)auto_delete_vec (const auto_delete_vec&) = delete; void operator
= (const auto_delete_vec &) = delete
;
1616};
1617
1618/* Conditionally allocate heap memory for VEC and its internal vector. */
1619
1620template<typename T>
1621inline void
1622vec_check_alloc (vec<T, va_heap> *&vec, unsigned nelems CXX_MEM_STAT_INFO)
1623{
1624 if (!vec)
1625 vec_alloc (vec, nelems PASS_MEM_STAT);
1626}
1627
1628
1629/* Free the heap memory allocated by vector V and set it to NULL. */
1630
1631template<typename T>
1632inline void
1633vec_free (vec<T> *&v)
1634{
1635 if (v == NULLnullptr)
1636 return;
1637
1638 v->release ();
1639 delete v;
1640 v = NULLnullptr;
1641}
1642
1643
1644/* Return iteration condition and update PTR to point to the IX'th
1645 element of this vector. Use this to iterate over the elements of a
1646 vector as follows,
1647
1648 for (ix = 0; v.iterate (ix, &ptr); ix++)
1649 continue; */
1650
1651template<typename T>
1652inline bool
1653vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T *ptr) const
1654{
1655 if (m_vec)
1656 return m_vec->iterate (ix, ptr);
1657 else
1658 {
1659 *ptr = 0;
1660 return false;
1661 }
1662}
1663
1664
1665/* Return iteration condition and update *PTR to point to the
1666 IX'th element of this vector. Use this to iterate over the
1667 elements of a vector as follows,
1668
1669 for (ix = 0; v->iterate (ix, &ptr); ix++)
1670 continue;
1671
1672 This variant is for vectors of objects. */
1673
1674template<typename T>
1675inline bool
1676vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T **ptr) const
1677{
1678 if (m_vec)
1679 return m_vec->iterate (ix, ptr);
1680 else
1681 {
1682 *ptr = 0;
1683 return false;
1684 }
1685}
1686
1687
1688/* Convenience macro for forward iteration. */
1689#define FOR_EACH_VEC_ELT(V, I, P)for (I = 0; (V).iterate ((I), &(P)); ++(I)) \
1690 for (I = 0; (V).iterate ((I), &(P)); ++(I))
1691
1692#define FOR_EACH_VEC_SAFE_ELT(V, I, P)for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I)) \
1693 for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I))
1694
1695/* Likewise, but start from FROM rather than 0. */
1696#define FOR_EACH_VEC_ELT_FROM(V, I, P, FROM)for (I = (FROM); (V).iterate ((I), &(P)); ++(I)) \
1697 for (I = (FROM); (V).iterate ((I), &(P)); ++(I))
1698
1699/* Convenience macro for reverse iteration. */
1700#define FOR_EACH_VEC_ELT_REVERSE(V, I, P)for (I = (V).length () - 1; (V).iterate ((I), &(P)); (I)--
)
\
1701 for (I = (V).length () - 1; \
1702 (V).iterate ((I), &(P)); \
1703 (I)--)
1704
1705#define FOR_EACH_VEC_SAFE_ELT_REVERSE(V, I, P)for (I = vec_safe_length (V) - 1; vec_safe_iterate ((V), (I),
&(P)); (I)--)
\
1706 for (I = vec_safe_length (V) - 1; \
1707 vec_safe_iterate ((V), (I), &(P)); \
1708 (I)--)
1709
1710/* auto_string_vec's dtor, freeing all contained strings, automatically
1711 chaining up to ~auto_vec <char *>, which frees the internal buffer. */
1712
1713inline
1714auto_string_vec::~auto_string_vec ()
1715{
1716 int i;
1717 char *str;
1718 FOR_EACH_VEC_ELT (*this, i, str)for (i = 0; (*this).iterate ((i), &(str)); ++(i))
1719 free (str);
1720}
1721
1722/* auto_delete_vec's dtor, deleting all contained items, automatically
1723 chaining up to ~auto_vec <T*>, which frees the internal buffer. */
1724
1725template <typename T>
1726inline
1727auto_delete_vec<T>::~auto_delete_vec ()
1728{
1729 int i;
1730 T *item;
1731 FOR_EACH_VEC_ELT (*this, i, item)for (i = 0; (*this).iterate ((i), &(item)); ++(i))
1732 delete item;
1733}
1734
1735
1736/* Return a copy of this vector. */
1737
1738template<typename T>
1739inline vec<T, va_heap, vl_ptr>
1740vec<T, va_heap, vl_ptr>::copy (ALONE_MEM_STAT_DECLvoid) const
1741{
1742 vec<T, va_heap, vl_ptr> new_vec = vNULL;
1743 if (length ())
1744 new_vec.m_vec = m_vec->copy (ALONE_PASS_MEM_STAT);
1745 return new_vec;
1746}
1747
1748
1749/* Ensure that the vector has at least RESERVE slots available (if
1750 EXACT is false), or exactly RESERVE slots available (if EXACT is
1751 true).
1752
1753 This may create additional headroom if EXACT is false.
1754
1755 Note that this can cause the embedded vector to be reallocated.
1756 Returns true iff reallocation actually occurred. */
1757
1758template<typename T>
1759inline bool
1760vec<T, va_heap, vl_ptr>::reserve (unsigned nelems, bool exact MEM_STAT_DECL)
1761{
1762 if (space (nelems))
1763 return false;
1764
1765 /* For now play a game with va_heap::reserve to hide our auto storage if any,
1766 this is necessary because it doesn't have enough information to know the
1767 embedded vector is in auto storage, and so should not be freed. */
1768 vec<T, va_heap, vl_embed> *oldvec = m_vec;
1769 unsigned int oldsize = 0;
1770 bool handle_auto_vec = m_vec && using_auto_storage ();
1771 if (handle_auto_vec)
1772 {
1773 m_vec = NULLnullptr;
1774 oldsize = oldvec->length ();
1775 nelems += oldsize;
1776 }
1777
1778 va_heap::reserve (m_vec, nelems, exact PASS_MEM_STAT);
1779 if (handle_auto_vec)
1780 {
1781 vec_copy_construct (m_vec->address (), oldvec->address (), oldsize);
1782 m_vec->m_vecpfx.m_num = oldsize;
1783 }
1784
1785 return true;
1786}
1787
1788
1789/* Ensure that this vector has exactly NELEMS slots available. This
1790 will not create additional headroom. Note this can cause the
1791 embedded vector to be reallocated. Returns true iff reallocation
1792 actually occurred. */
1793
1794template<typename T>
1795inline bool
1796vec<T, va_heap, vl_ptr>::reserve_exact (unsigned nelems MEM_STAT_DECL)
1797{
1798 return reserve (nelems, true PASS_MEM_STAT);
1799}
1800
1801
1802/* Create the internal vector and reserve NELEMS for it. This is
1803 exactly like vec::reserve, but the internal vector is
1804 unconditionally allocated from scratch. The old one, if it
1805 existed, is lost. */
1806
1807template<typename T>
1808inline void
1809vec<T, va_heap, vl_ptr>::create (unsigned nelems MEM_STAT_DECL)
1810{
1811 m_vec = NULLnullptr;
1812 if (nelems > 0)
1813 reserve_exact (nelems PASS_MEM_STAT);
1814}
1815
1816
1817/* Free the memory occupied by the embedded vector. */
1818
1819template<typename T>
1820inline void
1821vec<T, va_heap, vl_ptr>::release (void)
1822{
1823 if (!m_vec)
1824 return;
1825
1826 if (using_auto_storage ())
1827 {
1828 m_vec->m_vecpfx.m_num = 0;
1829 return;
1830 }
1831
1832 va_heap::release (m_vec);
1833}
1834
1835/* Copy the elements from SRC to the end of this vector as if by memcpy.
1836 SRC and this vector must be allocated with the same memory
1837 allocation mechanism. This vector is assumed to have sufficient
1838 headroom available. */
1839
1840template<typename T>
1841inline void
1842vec<T, va_heap, vl_ptr>::splice (const vec<T, va_heap, vl_ptr> &src)
1843{
1844 if (src.length ())
1845 m_vec->splice (*(src.m_vec));
1846}
1847
1848
1849/* Copy the elements in SRC to the end of this vector as if by memcpy.
1850 SRC and this vector must be allocated with the same mechanism.
1851 If there is not enough headroom in this vector, it will be reallocated
1852 as needed. */
1853
1854template<typename T>
1855inline void
1856vec<T, va_heap, vl_ptr>::safe_splice (const vec<T, va_heap, vl_ptr> &src
1857 MEM_STAT_DECL)
1858{
1859 if (src.length ())
1860 {
1861 reserve_exact (src.length ());
1862 splice (src);
1863 }
1864}
1865
1866
1867/* Push OBJ (a new element) onto the end of the vector. There must be
1868 sufficient space in the vector. Return a pointer to the slot
1869 where OBJ was inserted. */
1870
1871template<typename T>
1872inline T *
1873vec<T, va_heap, vl_ptr>::quick_push (const T &obj)
1874{
1875 return m_vec->quick_push (obj);
1876}
1877
1878
1879/* Push a new element OBJ onto the end of this vector. Reallocates
1880 the embedded vector, if needed. Return a pointer to the slot where
1881 OBJ was inserted. */
1882
1883template<typename T>
1884inline T *
1885vec<T, va_heap, vl_ptr>::safe_push (const T &obj MEM_STAT_DECL)
1886{
1887 reserve (1, false PASS_MEM_STAT);
1888 return quick_push (obj);
1889}
1890
1891
1892/* Pop and return the last element off the end of the vector. */
1893
1894template<typename T>
1895inline T &
1896vec<T, va_heap, vl_ptr>::pop (void)
1897{
1898 return m_vec->pop ();
1899}
1900
1901
1902/* Set the length of the vector to LEN. The new length must be less
1903 than or equal to the current length. This is an O(1) operation. */
1904
1905template<typename T>
1906inline void
1907vec<T, va_heap, vl_ptr>::truncate (unsigned size)
1908{
1909 if (m_vec)
1910 m_vec->truncate (size);
1911 else
1912 gcc_checking_assert (size == 0)((void)(!(size == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1912, __FUNCTION__), 0 : 0))
;
1913}
1914
1915
1916/* Grow the vector to a specific length. LEN must be as long or
1917 longer than the current length. The new elements are
1918 uninitialized. Reallocate the internal vector, if needed. */
1919
1920template<typename T>
1921inline void
1922vec<T, va_heap, vl_ptr>::safe_grow (unsigned len, bool exact MEM_STAT_DECL)
1923{
1924 unsigned oldlen = length ();
1925 gcc_checking_assert (oldlen <= len)((void)(!(oldlen <= len) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1925, __FUNCTION__), 0 : 0))
;
1926 reserve (len - oldlen, exact PASS_MEM_STAT);
1927 if (m_vec)
1928 m_vec->quick_grow (len);
1929 else
1930 gcc_checking_assert (len == 0)((void)(!(len == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1930, __FUNCTION__), 0 : 0))
;
1931}
1932
1933
1934/* Grow the embedded vector to a specific length. LEN must be as
1935 long or longer than the current length. The new elements are
1936 initialized to zero. Reallocate the internal vector, if needed. */
1937
1938template<typename T>
1939inline void
1940vec<T, va_heap, vl_ptr>::safe_grow_cleared (unsigned len, bool exact
1941 MEM_STAT_DECL)
1942{
1943 unsigned oldlen = length ();
1944 size_t growby = len - oldlen;
1945 safe_grow (len, exact PASS_MEM_STAT);
1946 if (growby != 0)
1947 vec_default_construct (address () + oldlen, growby);
1948}
1949
1950
1951/* Same as vec::safe_grow but without reallocation of the internal vector.
1952 If the vector cannot be extended, a runtime assertion will be triggered. */
1953
1954template<typename T>
1955inline void
1956vec<T, va_heap, vl_ptr>::quick_grow (unsigned len)
1957{
1958 gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1958, __FUNCTION__), 0 : 0))
;
1959 m_vec->quick_grow (len);
1960}
1961
1962
1963/* Same as vec::quick_grow_cleared but without reallocation of the
1964 internal vector. If the vector cannot be extended, a runtime
1965 assertion will be triggered. */
1966
1967template<typename T>
1968inline void
1969vec<T, va_heap, vl_ptr>::quick_grow_cleared (unsigned len)
1970{
1971 gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1971, __FUNCTION__), 0 : 0))
;
1972 m_vec->quick_grow_cleared (len);
1973}
1974
1975
1976/* Insert an element, OBJ, at the IXth position of this vector. There
1977 must be sufficient space. */
1978
1979template<typename T>
1980inline void
1981vec<T, va_heap, vl_ptr>::quick_insert (unsigned ix, const T &obj)
1982{
1983 m_vec->quick_insert (ix, obj);
1984}
1985
1986
1987/* Insert an element, OBJ, at the IXth position of the vector.
1988 Reallocate the embedded vector, if necessary. */
1989
1990template<typename T>
1991inline void
1992vec<T, va_heap, vl_ptr>::safe_insert (unsigned ix, const T &obj MEM_STAT_DECL)
1993{
1994 reserve (1, false PASS_MEM_STAT);
1995 quick_insert (ix, obj);
1996}
1997
1998
1999/* Remove an element from the IXth position of this vector. Ordering of
2000 remaining elements is preserved. This is an O(N) operation due to
2001 a memmove. */
2002
2003template<typename T>
2004inline void
2005vec<T, va_heap, vl_ptr>::ordered_remove (unsigned ix)
2006{
2007 m_vec->ordered_remove (ix);
2008}
2009
2010
2011/* Remove an element from the IXth position of this vector. Ordering
2012 of remaining elements is destroyed. This is an O(1) operation. */
2013
2014template<typename T>
2015inline void
2016vec<T, va_heap, vl_ptr>::unordered_remove (unsigned ix)
2017{
2018 m_vec->unordered_remove (ix);
2019}
2020
2021
2022/* Remove LEN elements starting at the IXth. Ordering is retained.
2023 This is an O(N) operation due to memmove. */
2024
2025template<typename T>
2026inline void
2027vec<T, va_heap, vl_ptr>::block_remove (unsigned ix, unsigned len)
2028{
2029 m_vec->block_remove (ix, len);
2030}
2031
2032
2033/* Sort the contents of this vector with qsort. CMP is the comparison
2034 function to pass to qsort. */
2035
2036template<typename T>
2037inline void
2038vec<T, va_heap, vl_ptr>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *))
2039{
2040 if (m_vec)
2041 m_vec->qsort (cmp)qsort (cmp);
2042}
2043
2044/* Sort the contents of this vector with qsort. CMP is the comparison
2045 function to pass to qsort. */
2046
2047template<typename T>
2048inline void
2049vec<T, va_heap, vl_ptr>::sort (int (*cmp) (const void *, const void *,
2050 void *), void *data)
2051{
2052 if (m_vec)
2053 m_vec->sort (cmp, data);
2054}
2055
2056
2057/* Search the contents of the sorted vector with a binary search.
2058 CMP is the comparison function to pass to bsearch. */
2059
2060template<typename T>
2061inline T *
2062vec<T, va_heap, vl_ptr>::bsearch (const void *key,
2063 int (*cmp) (const void *, const void *))
2064{
2065 if (m_vec)
2066 return m_vec->bsearch (key, cmp);
2067 return NULLnullptr;
2068}
2069
2070/* Search the contents of the sorted vector with a binary search.
2071 CMP is the comparison function to pass to bsearch. */
2072
2073template<typename T>
2074inline T *
2075vec<T, va_heap, vl_ptr>::bsearch (const void *key,
2076 int (*cmp) (const void *, const void *,
2077 void *), void *data)
2078{
2079 if (m_vec)
2080 return m_vec->bsearch (key, cmp, data);
2081 return NULLnullptr;
2082}
2083
2084
2085/* Find and return the first position in which OBJ could be inserted
2086 without changing the ordering of this vector. LESSTHAN is a
2087 function that returns true if the first argument is strictly less
2088 than the second. */
2089
2090template<typename T>
2091inline unsigned
2092vec<T, va_heap, vl_ptr>::lower_bound (T obj,
2093 bool (*lessthan)(const T &, const T &))
2094 const
2095{
2096 return m_vec ? m_vec->lower_bound (obj, lessthan) : 0;
2097}
2098
2099/* Return true if SEARCH is an element of V. Note that this is O(N) in the
2100 size of the vector and so should be used with care. */
2101
2102template<typename T>
2103inline bool
2104vec<T, va_heap, vl_ptr>::contains (const T &search) const
2105{
2106 return m_vec ? m_vec->contains (search) : false;
2107}
2108
2109/* Reverse content of the vector. */
2110
2111template<typename T>
2112inline void
2113vec<T, va_heap, vl_ptr>::reverse (void)
2114{
2115 unsigned l = length ();
2116 T *ptr = address ();
2117
2118 for (unsigned i = 0; i < l / 2; i++)
2119 std::swap (ptr[i], ptr[l - i - 1]);
2120}
2121
2122template<typename T>
2123inline bool
2124vec<T, va_heap, vl_ptr>::using_auto_storage () const
2125{
2126 return m_vec->m_vecpfx.m_using_auto_storage;
2127}
2128
2129/* Release VEC and call release of all element vectors. */
2130
2131template<typename T>
2132inline void
2133release_vec_vec (vec<vec<T> > &vec)
2134{
2135 for (unsigned i = 0; i < vec.length (); i++)
2136 vec[i].release ();
2137
2138 vec.release ();
2139}
2140
2141// Provide a subset of the std::span functionality. (We can't use std::span
2142// itself because it's a C++20 feature.)
2143//
2144// In addition, provide an invalid value that is distinct from all valid
2145// sequences (including the empty sequence). This can be used to return
2146// failure without having to use std::optional.
2147//
2148// There is no operator bool because it would be ambiguous whether it is
2149// testing for a valid value or an empty sequence.
2150template<typename T>
2151class array_slice
2152{
2153 template<typename OtherT> friend class array_slice;
2154
2155public:
2156 using value_type = T;
2157 using iterator = T *;
2158 using const_iterator = const T *;
2159
2160 array_slice () : m_base (nullptr), m_size (0) {}
2161
2162 template<typename OtherT>
2163 array_slice (array_slice<OtherT> other)
2164 : m_base (other.m_base), m_size (other.m_size) {}
2165
2166 array_slice (iterator base, unsigned int size)
2167 : m_base (base), m_size (size) {}
2168
2169 template<size_t N>
2170 array_slice (T (&array)[N]) : m_base (array), m_size (N) {}
2171
2172 template<typename OtherT>
2173 array_slice (const vec<OtherT> &v)
2174 : m_base (v.address ()), m_size (v.length ()) {}
2175
2176 iterator begin () { return m_base; }
2177 iterator end () { return m_base + m_size; }
2178
2179 const_iterator begin () const { return m_base; }
2180 const_iterator end () const { return m_base + m_size; }
2181
2182 value_type &front ();
2183 value_type &back ();
2184 value_type &operator[] (unsigned int i);
2185
2186 const value_type &front () const;
2187 const value_type &back () const;
2188 const value_type &operator[] (unsigned int i) const;
2189
2190 size_t size () const { return m_size; }
2191 size_t size_bytes () const { return m_size * sizeof (T); }
2192 bool empty () const { return m_size == 0; }
2193
2194 // An invalid array_slice that represents a failed operation. This is
2195 // distinct from an empty slice, which is a valid result in some contexts.
2196 static array_slice invalid () { return { nullptr, ~0U }; }
2197
2198 // True if the array is valid, false if it is an array like INVALID.
2199 bool is_valid () const { return m_base || m_size == 0; }
2200
2201private:
2202 iterator m_base;
2203 unsigned int m_size;
2204};
2205
2206template<typename T>
2207inline typename array_slice<T>::value_type &
2208array_slice<T>::front ()
2209{
2210 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2210, __FUNCTION__), 0 : 0))
;
2211 return m_base[0];
2212}
2213
2214template<typename T>
2215inline const typename array_slice<T>::value_type &
2216array_slice<T>::front () const
2217{
2218 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2218, __FUNCTION__), 0 : 0))
;
2219 return m_base[0];
2220}
2221
2222template<typename T>
2223inline typename array_slice<T>::value_type &
2224array_slice<T>::back ()
2225{
2226 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2226, __FUNCTION__), 0 : 0))
;
2227 return m_base[m_size - 1];
2228}
2229
2230template<typename T>
2231inline const typename array_slice<T>::value_type &
2232array_slice<T>::back () const
2233{
2234 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2234, __FUNCTION__), 0 : 0))
;
2235 return m_base[m_size - 1];
2236}
2237
2238template<typename T>
2239inline typename array_slice<T>::value_type &
2240array_slice<T>::operator[] (unsigned int i)
2241{
2242 gcc_checking_assert (i < m_size)((void)(!(i < m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2242, __FUNCTION__), 0 : 0))
;
2243 return m_base[i];
2244}
2245
2246template<typename T>
2247inline const typename array_slice<T>::value_type &
2248array_slice<T>::operator[] (unsigned int i) const
2249{
2250 gcc_checking_assert (i < m_size)((void)(!(i < m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2250, __FUNCTION__), 0 : 0))
;
2251 return m_base[i];
2252}
2253
2254template<typename T>
2255array_slice<T>
2256make_array_slice (T *base, unsigned int size)
2257{
2258 return array_slice<T> (base, size);
2259}
2260
2261#if (GCC_VERSION(4 * 1000 + 2) >= 3000)
2262# pragma GCC poison m_vec m_vecpfx m_vecdata
2263#endif
2264
2265#endif // GCC_VEC_H