Bug Summary

File:build/gcc/vec.h
Warning:line 814, 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 c-pragma.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 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -resource-dir /usr/lib64/clang/13.0.0 -D IN_GCC_FRONTEND -D IN_GCC_FRONTEND -D IN_GCC -D HAVE_CONFIG_H -I . -I c-family -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/c-family -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/11/../../../../include/c++/11 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/x86_64-suse-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../include/c++/11/backward -internal-isystem /usr/lib64/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/clang-static-analyzer/2021-11-20-133755-20252-1/report-KJs1zO.plist -x c++ /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c

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

1/* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2021 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
23#include "target.h"
24#include "function.h" /* For cfun. */
25#include "c-common.h"
26#include "memmodel.h"
27#include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS. */
28#include "stringpool.h"
29#include "cgraph.h"
30#include "diagnostic.h"
31#include "attribs.h"
32#include "varasm.h"
33#include "c-pragma.h"
34#include "opts.h"
35#include "plugin.h"
36#include "opt-suggestions.h"
37
38#define GCC_BAD(gmsgid)do { warning (OPT_Wpragmas, gmsgid); return; } while (0) \
39 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
40#define GCC_BAD2(gmsgid, arg)do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0) \
41 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
42#define GCC_BAD_AT(loc, gmsgid)do { warning_at (loc, OPT_Wpragmas, gmsgid); return; } while (
0)
\
43 do { warning_at (loc, OPT_Wpragmas, gmsgid); return; } while (0)
44#define GCC_BAD2_AT(loc, gmsgid, arg)do { warning_at (loc, OPT_Wpragmas, gmsgid, arg); return; } while
(0)
\
45 do { warning_at (loc, OPT_Wpragmas, gmsgid, arg); return; } while (0)
46
47struct GTY(()) align_stack {
48 int alignment;
49 tree id;
50 struct align_stack * prev;
51};
52
53static GTY(()) struct align_stack * alignment_stack;
54
55static void handle_pragma_pack (cpp_reader *);
56
57/* If we have a "global" #pragma pack(<n>) in effect when the first
58 #pragma pack(push,<n>) is encountered, this stores the value of
59 maximum_field_alignment in effect. When the final pop_alignment()
60 happens, we restore the value to this, not to a value of 0 for
61 maximum_field_alignment. Value is in bits. */
62static int default_alignment;
63#define SET_GLOBAL_ALIGNMENT(ALIGN)(maximum_field_alignment = *(alignment_stack == nullptr ? &
default_alignment : &alignment_stack->alignment) = (ALIGN
))
(maximum_field_alignment = *(alignment_stack == NULLnullptr \
64 ? &default_alignment \
65 : &alignment_stack->alignment) = (ALIGN))
66
67static void push_alignment (int, tree);
68static void pop_alignment (tree);
69
70/* Push an alignment value onto the stack. */
71static void
72push_alignment (int alignment, tree id)
73{
74 align_stack * entry = ggc_alloc<align_stack> ();
75
76 entry->alignment = alignment;
77 entry->id = id;
78 entry->prev = alignment_stack;
79
80 /* The current value of maximum_field_alignment is not necessarily
81 0 since there may be a #pragma pack(<n>) in effect; remember it
82 so that we can restore it after the final #pragma pop(). */
83 if (alignment_stack == NULLnullptr)
84 default_alignment = maximum_field_alignment;
85
86 alignment_stack = entry;
87
88 maximum_field_alignment = alignment;
89}
90
91/* Undo a push of an alignment onto the stack. */
92static void
93pop_alignment (tree id)
94{
95 align_stack * entry;
96
97 if (alignment_stack == NULLnullptr)
98 GCC_BAD ("%<#pragma pack (pop)%> encountered without matching "do { warning (OPT_Wpragmas, "%<#pragma pack (pop)%> encountered without matching "
"%<#pragma pack (push)%>"); return; } while (0)
99 "%<#pragma pack (push)%>")do { warning (OPT_Wpragmas, "%<#pragma pack (pop)%> encountered without matching "
"%<#pragma pack (push)%>"); return; } while (0)
;
100
101 /* If we got an identifier, strip away everything above the target
102 entry so that the next step will restore the state just below it. */
103 if (id)
104 {
105 for (entry = alignment_stack; entry; entry = entry->prev)
106 if (entry->id == id)
107 {
108 alignment_stack = entry;
109 break;
110 }
111 if (entry == NULLnullptr)
112 warning (OPT_Wpragmas,
113 "%<#pragma pack(pop, %E)%> encountered without matching "
114 "%<#pragma pack(push, %E)%>"
115 , id, id);
116 }
117
118 entry = alignment_stack->prev;
119
120 maximum_field_alignment = entry ? entry->alignment : default_alignment;
121
122 alignment_stack = entry;
123}
124
125/* #pragma pack ()
126 #pragma pack (N)
127
128 #pragma pack (push)
129 #pragma pack (push, N)
130 #pragma pack (push, ID)
131 #pragma pack (push, ID, N)
132 #pragma pack (pop)
133 #pragma pack (pop, ID) */
134static void
135handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy)dummy __attribute__ ((__unused__)))
136{
137 location_t loc;
138 tree x, id = 0;
139 int align = -1;
140 enum cpp_ttype token;
141 enum { set, push, pop } action;
142
143 if (pragma_lex (&x) != CPP_OPEN_PAREN)
144 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored")do { warning (OPT_Wpragmas, "missing %<(%> after %<#pragma pack%> - ignored"
); return; } while (0)
;
145
146 token = pragma_lex (&x, &loc);
147 if (token == CPP_CLOSE_PAREN)
148 {
149 action = set;
150 align = initial_max_fld_alignglobal_options.x_initial_max_fld_align;
151 }
152 else if (token == CPP_NUMBER)
153 {
154 if (TREE_CODE (x)((enum tree_code) (x)->base.code) != INTEGER_CST)
155 GCC_BAD_AT (loc, "invalid constant in %<#pragma pack%> - ignored")do { warning_at (loc, OPT_Wpragmas, "invalid constant in %<#pragma pack%> - ignored"
); return; } while (0)
;
156 align = TREE_INT_CST_LOW (x)((unsigned long) (*tree_int_cst_elt_check ((x), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 156, __FUNCTION__)))
;
157 action = set;
158 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
159 GCC_BAD ("malformed %<#pragma pack%> - ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma pack%> - ignored"
); return; } while (0)
;
160 }
161 else if (token == CPP_NAME)
162 {
163#define GCC_BAD_ACTION do { if (action != pop) \
164 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma pack(push[, id][, <n>])%> - ignored"
); return; } while (0)
; \
165 else \
166 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma pack(pop[, id])%> - ignored"
); return; } while (0)
; \
167 } while (0)
168
169 const char *op = IDENTIFIER_POINTER (x)((const char *) (tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 169, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
170 if (!strcmp (op, "push"))
171 action = push;
172 else if (!strcmp (op, "pop"))
173 action = pop;
174 else
175 GCC_BAD2_AT (loc, "unknown action %qE for %<#pragma pack%> - ignored",do { warning_at (loc, OPT_Wpragmas, "unknown action %qE for %<#pragma pack%> - ignored"
, x); return; } while (0)
176 x)do { warning_at (loc, OPT_Wpragmas, "unknown action %qE for %<#pragma pack%> - ignored"
, x); return; } while (0)
;
177
178 while ((token = pragma_lex (&x)) == CPP_COMMA)
179 {
180 token = pragma_lex (&x, &loc);
181 if (token == CPP_NAME && id == 0)
182 {
183 id = x;
184 }
185 else if (token == CPP_NUMBER && action == push && align == -1)
186 {
187 if (TREE_CODE (x)((enum tree_code) (x)->base.code) != INTEGER_CST)
188 GCC_BAD_AT (loc,do { warning_at (loc, OPT_Wpragmas, "invalid constant in %<#pragma pack%> - ignored"
); return; } while (0)
189 "invalid constant in %<#pragma pack%> - ignored")do { warning_at (loc, OPT_Wpragmas, "invalid constant in %<#pragma pack%> - ignored"
); return; } while (0)
;
190 align = TREE_INT_CST_LOW (x)((unsigned long) (*tree_int_cst_elt_check ((x), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 190, __FUNCTION__)))
;
191 if (align == -1)
192 action = set;
193 }
194 else
195 GCC_BAD_ACTION;
196 }
197
198 if (token != CPP_CLOSE_PAREN)
199 GCC_BAD_ACTION;
200#undef GCC_BAD_ACTION
201 }
202 else
203 GCC_BAD ("malformed %<#pragma pack%> - ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma pack%> - ignored"
); return; } while (0)
;
204
205 if (pragma_lex (&x, &loc) != CPP_EOF)
206 warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma pack%>");
207
208 if (flag_pack_structglobal_options.x_flag_pack_struct)
209 GCC_BAD ("%<#pragma pack%> has no effect with %<-fpack-struct%> - ignored")do { warning (OPT_Wpragmas, "%<#pragma pack%> has no effect with %<-fpack-struct%> - ignored"
); return; } while (0)
;
210
211 if (action != pop)
212 switch (align)
213 {
214 case 0:
215 case 1:
216 case 2:
217 case 4:
218 case 8:
219 case 16:
220 align *= BITS_PER_UNIT(8);
221 break;
222 case -1:
223 if (action == push)
224 {
225 align = maximum_field_alignment;
226 break;
227 }
228 /* FALLTHRU */
229 default:
230 GCC_BAD2 ("alignment must be a small power of two, not %d", align)do { warning (OPT_Wpragmas, "alignment must be a small power of two, not %d"
, align); return; } while (0)
;
231 }
232
233 switch (action)
234 {
235 case set: SET_GLOBAL_ALIGNMENT (align)(maximum_field_alignment = *(alignment_stack == nullptr ? &
default_alignment : &alignment_stack->alignment) = (align
))
; break;
236 case push: push_alignment (align, id); break;
237 case pop: pop_alignment (id); break;
238 }
239}
240
241struct GTY(()) pending_weak
242{
243 tree name;
244 tree value;
245};
246
247
248static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
249
250static void apply_pragma_weak (tree, tree);
251static void handle_pragma_weak (cpp_reader *);
252
253static void
254apply_pragma_weak (tree decl, tree value)
255{
256 if (value)
257 {
258 value = build_string (IDENTIFIER_LENGTH (value)((tree_check ((value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 258, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len
)
,
259 IDENTIFIER_POINTER (value)((const char *) (tree_check ((value), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 259, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
260 decl_attributes (&decl, build_tree_list (get_identifier ("alias")(__builtin_constant_p ("alias") ? get_identifier_with_length (
("alias"), strlen ("alias")) : get_identifier ("alias"))
,
261 build_tree_list (NULLnullptr, value)),
262 0);
263 }
264
265 if (SUPPORTS_WEAK1 && DECL_EXTERNAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 265, __FUNCTION__))->decl_common.decl_flag_1)
&& TREE_USED (decl)((decl)->base.used_flag)
266 && !DECL_WEAK (decl)((contains_struct_check ((decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 266, __FUNCTION__))->decl_with_vis.weak_flag)
/* Don't complain about a redundant #pragma. */
267 && DECL_ASSEMBLER_NAME_SET_P (decl)(((contains_struct_check ((decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 267, __FUNCTION__))->decl_with_vis.assembler_name) != (tree
) nullptr)
268 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))((tree_check ((decl_assembler_name (decl)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 268, __FUNCTION__, (IDENTIFIER_NODE)))->base.static_flag
)
)
269 warning (OPT_Wpragmas, "applying %<#pragma weak %+D%> after first use "
270 "results in unspecified behavior", decl);
271
272 declare_weak (decl);
273}
274
275void
276maybe_apply_pragma_weak (tree decl)
277{
278 tree id;
279 int i;
280 pending_weak *pe;
281
282 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
283
284 /* No weak symbols pending, take the short-cut. */
285 if (vec_safe_is_empty (pending_weaks))
286 return;
287 /* If it's not visible outside this file, it doesn't matter whether
288 it's weak. */
289 if (!DECL_EXTERNAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 289, __FUNCTION__))->decl_common.decl_flag_1)
&& !TREE_PUBLIC (decl)((decl)->base.public_flag))
290 return;
291 /* If it's not a function or a variable, it can't be weak.
292 FIXME: what kinds of things are visible outside this file but
293 aren't functions or variables? Should this be an assert instead? */
294 if (!VAR_OR_FUNCTION_DECL_P (decl)(((enum tree_code) (decl)->base.code) == VAR_DECL || ((enum
tree_code) (decl)->base.code) == FUNCTION_DECL)
)
295 return;
296
297 if (DECL_ASSEMBLER_NAME_SET_P (decl)(((contains_struct_check ((decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 297, __FUNCTION__))->decl_with_vis.assembler_name) != (tree
) nullptr)
)
298 id = DECL_ASSEMBLER_NAME (decl)decl_assembler_name (decl);
299 else
300 {
301 id = DECL_ASSEMBLER_NAME (decl)decl_assembler_name (decl);
302 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE)overwrite_decl_assembler_name (decl, (tree) nullptr);
303 }
304
305 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)for (i = 0; (*pending_weaks).iterate ((i), &(pe)); ++(i))
306 if (id == pe->name)
307 {
308 apply_pragma_weak (decl, pe->value);
309 pending_weaks->unordered_remove (i);
310 break;
311 }
312}
313
314/* Process all "#pragma weak A = B" directives where we have not seen
315 a decl for A. */
316void
317maybe_apply_pending_pragma_weaks (void)
318{
319 tree alias_id, id, decl;
320 int i;
321 pending_weak *pe;
322 symtab_node *target;
323
324 if (vec_safe_is_empty (pending_weaks))
325 return;
326
327 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)for (i = 0; (*pending_weaks).iterate ((i), &(pe)); ++(i))
328 {
329 alias_id = pe->name;
330 id = pe->value;
331
332 if (id == NULLnullptr)
333 continue;
334
335 target = symtab_node::get_for_asmname (id);
336 decl = build_decl (UNKNOWN_LOCATION((location_t) 0),
337 target ? TREE_CODE (target->decl)((enum tree_code) (target->decl)->base.code) : FUNCTION_DECL,
338 alias_id, default_function_typec_global_trees[CTI_DEFAULT_FUNCTION_TYPE]);
339
340 DECL_ARTIFICIAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 340, __FUNCTION__))->decl_common.artificial_flag)
= 1;
341 TREE_PUBLIC (decl)((decl)->base.public_flag) = 1;
342 DECL_WEAK (decl)((contains_struct_check ((decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 342, __FUNCTION__))->decl_with_vis.weak_flag)
= 1;
343 if (VAR_P (decl)(((enum tree_code) (decl)->base.code) == VAR_DECL))
344 TREE_STATIC (decl)((decl)->base.static_flag) = 1;
345 if (!target)
346 {
347 error ("%q+D aliased to undefined symbol %qE",
348 decl, id);
349 continue;
350 }
351
352 assemble_alias (decl, id);
353 }
354}
355
356/* #pragma weak name [= value] */
357static void
358handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy)dummy __attribute__ ((__unused__)))
359{
360 tree name, value, x, decl;
361 enum cpp_ttype t;
362
363 value = 0;
364
365 if (pragma_lex (&name) != CPP_NAME)
1
Assuming the condition is false
2
Taking false branch
366 GCC_BAD ("malformed %<#pragma weak%>, ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma weak%>, ignored"
); return; } while (0)
;
367 t = pragma_lex (&x);
368 if (t == CPP_EQ)
3
Assuming 't' is not equal to CPP_EQ
4
Taking false branch
369 {
370 if (pragma_lex (&value) != CPP_NAME)
371 GCC_BAD ("malformed %<#pragma weak%>, ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma weak%>, ignored"
); return; } while (0)
;
372 t = pragma_lex (&x);
373 }
374 if (t != CPP_EOF)
5
Assuming 't' is equal to CPP_EOF
6
Taking false branch
375 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
376
377 decl = identifier_global_value (name);
7
Value assigned to 'pending_weaks'
378 if (decl && DECL_P (decl)(tree_code_type[(int) (((enum tree_code) (decl)->base.code
))] == tcc_declaration)
)
8
Assuming 'decl' is null
379 {
380 if (!VAR_OR_FUNCTION_DECL_P (decl)(((enum tree_code) (decl)->base.code) == VAR_DECL || ((enum
tree_code) (decl)->base.code) == FUNCTION_DECL)
)
381 GCC_BAD2 ("%<#pragma weak%> declaration of %q+D not allowed,"do { warning (OPT_Wpragmas, "%<#pragma weak%> declaration of %q+D not allowed,"
" ignored", decl); return; } while (0)
382 " ignored", decl)do { warning (OPT_Wpragmas, "%<#pragma weak%> declaration of %q+D not allowed,"
" ignored", decl); return; } while (0)
;
383 apply_pragma_weak (decl, value);
384 if (value)
385 {
386 DECL_EXTERNAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 386, __FUNCTION__))->decl_common.decl_flag_1)
= 0;
387 if (VAR_P (decl)(((enum tree_code) (decl)->base.code) == VAR_DECL))
388 TREE_STATIC (decl)((decl)->base.static_flag) = 1;
389 assemble_alias (decl, value);
390 }
391 }
392 else
393 {
394 pending_weak pe = {name, value};
395 vec_safe_push (pending_weaks, pe);
9
Passing value via 1st parameter 'v'
10
Calling 'vec_safe_push<pending_weak, va_gc>'
396 }
397}
398
399static enum scalar_storage_order_kind global_sso;
400
401void
402maybe_apply_pragma_scalar_storage_order (tree type)
403{
404 if (global_sso == SSO_NATIVE)
405 return;
406
407 gcc_assert (RECORD_OR_UNION_TYPE_P (type))((void)(!((((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)) ?
fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 407, __FUNCTION__), 0 : 0))
;
408
409 if (lookup_attribute ("scalar_storage_order", TYPE_ATTRIBUTES (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 409, __FUNCTION__))->type_common.attributes)
))
410 return;
411
412 if (global_sso == SSO_BIG_ENDIAN)
413 TYPE_REVERSE_STORAGE_ORDER (type)((tree_check4 ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 413, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE
), (ARRAY_TYPE)))->base.u.bits.saturating_flag)
= !BYTES_BIG_ENDIAN0;
414 else if (global_sso == SSO_LITTLE_ENDIAN)
415 TYPE_REVERSE_STORAGE_ORDER (type)((tree_check4 ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 415, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE
), (ARRAY_TYPE)))->base.u.bits.saturating_flag)
= BYTES_BIG_ENDIAN0;
416 else
417 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 417, __FUNCTION__))
;
418}
419
420static void
421handle_pragma_scalar_storage_order (cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
422{
423 const char *kind_string;
424 enum cpp_ttype token;
425 tree x;
426
427 if (BYTES_BIG_ENDIAN0 != WORDS_BIG_ENDIAN0)
428 {
429 error ("%<scalar_storage_order%> is not supported because endianness "
430 "is not uniform");
431 return;
432 }
433
434 if (c_dialect_cxx ()((c_language & clk_cxx) != 0))
435 {
436 if (warn_unknown_pragmasglobal_options.x_warn_unknown_pragmas > in_system_header_at (input_location))
437 warning (OPT_Wunknown_pragmas,
438 "%<#pragma scalar_storage_order%> is not supported for C++");
439 return;
440 }
441
442 token = pragma_lex (&x);
443 if (token != CPP_NAME)
444 GCC_BAD ("missing [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>")do { warning (OPT_Wpragmas, "missing [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>"
); return; } while (0)
;
445 kind_string = IDENTIFIER_POINTER (x)((const char *) (tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 445, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
446 if (strcmp (kind_string, "default") == 0)
447 global_sso = default_ssoglobal_options.x_default_sso;
448 else if (strcmp (kind_string, "big") == 0)
449 global_sso = SSO_BIG_ENDIAN;
450 else if (strcmp (kind_string, "little") == 0)
451 global_sso = SSO_LITTLE_ENDIAN;
452 else
453 GCC_BAD ("expected [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>")do { warning (OPT_Wpragmas, "expected [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>"
); return; } while (0)
;
454}
455
456/* GCC supports two #pragma directives for renaming the external
457 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
458 compatibility with the Solaris and VMS system headers. GCC also
459 has its own notation for this, __asm__("name") annotations.
460
461 Corner cases of these features and their interaction:
462
463 1) Both pragmas silently apply only to declarations with external
464 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
465 do not have this restriction.
466
467 2) In C++, both #pragmas silently apply only to extern "C" declarations.
468 Asm labels do not have this restriction.
469
470 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
471 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
472 new name is different, a warning issues and the name does not change.
473
474 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
475 *not* the DECL_ASSEMBLER_NAME.
476
477 5) If #pragma extern_prefix is in effect and a declaration occurs
478 with an __asm__ name, the #pragma extern_prefix is silently
479 ignored for that declaration.
480
481 6) If #pragma extern_prefix and #pragma redefine_extname apply to
482 the same declaration, whichever triggered first wins, and a warning
483 is issued. (We would like to have #pragma redefine_extname always
484 win, but it can appear either before or after the declaration, and
485 if it appears afterward, we have no way of knowing whether a modified
486 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
487
488struct GTY(()) pending_redefinition {
489 tree oldname;
490 tree newname;
491};
492
493
494static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
495
496static void handle_pragma_redefine_extname (cpp_reader *);
497
498/* #pragma redefine_extname oldname newname */
499static void
500handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy)dummy __attribute__ ((__unused__)))
501{
502 tree oldname, newname, decls, x;
503 enum cpp_ttype t;
504 bool found;
505
506 if (pragma_lex (&oldname) != CPP_NAME)
507 GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma redefine_extname%>, ignored"
); return; } while (0)
;
508 if (pragma_lex (&newname) != CPP_NAME)
509 GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma redefine_extname%>, ignored"
); return; } while (0)
;
510 t = pragma_lex (&x);
511 if (t != CPP_EOF)
512 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
513
514 found = false;
515 for (decls = c_linkage_bindings (oldname);
516 decls; )
517 {
518 tree decl;
519 if (TREE_CODE (decls)((enum tree_code) (decls)->base.code) == TREE_LIST)
520 {
521 decl = TREE_VALUE (decls)((tree_check ((decls), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 521, __FUNCTION__, (TREE_LIST)))->list.value)
;
522 decls = TREE_CHAIN (decls)((contains_struct_check ((decls), (TS_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 522, __FUNCTION__))->common.chain)
;
523 }
524 else
525 {
526 decl = decls;
527 decls = NULL_TREE(tree) nullptr;
528 }
529
530 if ((TREE_PUBLIC (decl)((decl)->base.public_flag) || DECL_EXTERNAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 530, __FUNCTION__))->decl_common.decl_flag_1)
)
531 && VAR_OR_FUNCTION_DECL_P (decl)(((enum tree_code) (decl)->base.code) == VAR_DECL || ((enum
tree_code) (decl)->base.code) == FUNCTION_DECL)
)
532 {
533 found = true;
534 if (DECL_ASSEMBLER_NAME_SET_P (decl)(((contains_struct_check ((decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 534, __FUNCTION__))->decl_with_vis.assembler_name) != (tree
) nullptr)
)
535 {
536 const char *name = 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/c-family/c-pragma.c"
, 536, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
537 name = targetm.strip_name_encoding (name);
538
539 if (!id_equal (newname, name))
540 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> "
541 "ignored due to conflict with previous rename");
542 }
543 else
544 symtab->change_decl_assembler_name (decl, newname);
545 }
546 }
547
548 if (!found)
549 /* We have to add this to the rename list even if there's already
550 a global value that doesn't meet the above criteria, because in
551 C++ "struct foo {...};" puts "foo" in the current namespace but
552 does *not* conflict with a subsequent declaration of a function
553 or variable foo. See g++.dg/other/pragma-re-2.C. */
554 add_to_renaming_pragma_list (oldname, newname);
555}
556
557/* This is called from here and from ia64-c.c. */
558void
559add_to_renaming_pragma_list (tree oldname, tree newname)
560{
561 unsigned ix;
562 pending_redefinition *p;
563
564 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)for (ix = 0; vec_safe_iterate ((pending_redefine_extname), (ix
), &(p)); ++(ix))
565 if (oldname == p->oldname)
566 {
567 if (p->newname != newname)
568 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored due to "
569 "conflict with previous %<#pragma redefine_extname%>");
570 return;
571 }
572
573 pending_redefinition e = {oldname, newname};
574 vec_safe_push (pending_redefine_extname, e);
575}
576
577/* The current prefix set by #pragma extern_prefix. */
578GTY(()) tree pragma_extern_prefix;
579
580/* Hook from the front ends to apply the results of one of the preceding
581 pragmas that rename variables. */
582
583tree
584maybe_apply_renaming_pragma (tree decl, tree asmname)
585{
586 unsigned ix;
587 pending_redefinition *p;
588
589 /* The renaming pragmas are only applied to declarations with
590 external linkage. */
591 if (!VAR_OR_FUNCTION_DECL_P (decl)(((enum tree_code) (decl)->base.code) == VAR_DECL || ((enum
tree_code) (decl)->base.code) == FUNCTION_DECL)
592 || (!TREE_PUBLIC (decl)((decl)->base.public_flag) && !DECL_EXTERNAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 592, __FUNCTION__))->decl_common.decl_flag_1)
)
593 || !has_c_linkage (decl))
594 return asmname;
595
596 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
597 but we may warn about a rename that conflicts. */
598 if (DECL_ASSEMBLER_NAME_SET_P (decl)(((contains_struct_check ((decl), (TS_DECL_WITH_VIS), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 598, __FUNCTION__))->decl_with_vis.assembler_name) != (tree
) nullptr)
)
599 {
600 const char *oldname = 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/c-family/c-pragma.c"
, 600, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
601 oldname = targetm.strip_name_encoding (oldname);
602
603 if (asmname && strcmp (TREE_STRING_POINTER (asmname)((const char *)((tree_check ((asmname), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 603, __FUNCTION__, (STRING_CST)))->string.str))
, oldname))
604 warning (OPT_Wpragmas, "%<asm%> declaration ignored due to "
605 "conflict with previous rename");
606
607 /* Take any pending redefine_extname off the list. */
608 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)for (ix = 0; vec_safe_iterate ((pending_redefine_extname), (ix
), &(p)); ++(ix))
609 if (DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 609, __FUNCTION__))->decl_minimal.name)
== p->oldname)
610 {
611 /* Only warn if there is a conflict. */
612 if (!id_equal (p->newname, oldname))
613 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
614 "due to conflict with previous rename");
615
616 pending_redefine_extname->unordered_remove (ix);
617 break;
618 }
619 return NULL_TREE(tree) nullptr;
620 }
621
622 /* Find out if we have a pending #pragma redefine_extname. */
623 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)for (ix = 0; vec_safe_iterate ((pending_redefine_extname), (ix
), &(p)); ++(ix))
624 if (DECL_NAME (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 624, __FUNCTION__))->decl_minimal.name)
== p->oldname)
625 {
626 tree newname = p->newname;
627 pending_redefine_extname->unordered_remove (ix);
628
629 /* If we already have an asmname, #pragma redefine_extname is
630 ignored (with a warning if it conflicts). */
631 if (asmname)
632 {
633 if (strcmp (TREE_STRING_POINTER (asmname)((const char *)((tree_check ((asmname), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 633, __FUNCTION__, (STRING_CST)))->string.str))
,
634 IDENTIFIER_POINTER (newname)((const char *) (tree_check ((newname), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 634, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
) != 0)
635 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
636 "due to conflict with %<asm%> declaration");
637 return asmname;
638 }
639
640 /* Otherwise we use what we've got; #pragma extern_prefix is
641 silently ignored. */
642 return build_string (IDENTIFIER_LENGTH (newname)((tree_check ((newname), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 642, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len
)
,
643 IDENTIFIER_POINTER (newname)((const char *) (tree_check ((newname), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 643, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
);
644 }
645
646 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
647 if (asmname)
648 return asmname;
649
650 /* If #pragma extern_prefix is in effect, apply it. */
651 if (pragma_extern_prefix)
652 {
653 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix)((const char *)((tree_check ((pragma_extern_prefix), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 653, __FUNCTION__, (STRING_CST)))->string.str))
;
654 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix)((tree_check ((pragma_extern_prefix), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 654, __FUNCTION__, (STRING_CST)))->string.length)
- 1;
655
656 const char *id = 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/c-family/c-pragma.c"
, 656, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 656, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
657 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl))((tree_check ((((contains_struct_check ((decl), (TS_DECL_MINIMAL
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 657, __FUNCTION__))->decl_minimal.name)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 657, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len
)
;
658
659 char *newname = (char *) alloca (plen + ilen + 1)__builtin_alloca(plen + ilen + 1);
660
661 memcpy (newname, prefix, plen);
662 memcpy (newname + plen, id, ilen + 1);
663
664 return build_string (plen + ilen, newname);
665 }
666
667 /* Nada. */
668 return NULL_TREE(tree) nullptr;
669}
670
671
672static void handle_pragma_visibility (cpp_reader *);
673
674static vec<int> visstack;
675
676/* Push the visibility indicated by STR onto the top of the #pragma
677 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
678 C++ namespace with visibility attribute and 2 for C++ builtin
679 ABI namespace. push_visibility/pop_visibility calls must have
680 matching KIND, it is not allowed to push visibility using one
681 KIND and pop using a different one. */
682
683void
684push_visibility (const char *str, int kind)
685{
686 visstack.safe_push (((int) default_visibilityglobal_options.x_default_visibility) | (kind << 8));
687 if (!strcmp (str, "default"))
688 default_visibilityglobal_options.x_default_visibility = VISIBILITY_DEFAULT;
689 else if (!strcmp (str, "internal"))
690 default_visibilityglobal_options.x_default_visibility = VISIBILITY_INTERNAL;
691 else if (!strcmp (str, "hidden"))
692 default_visibilityglobal_options.x_default_visibility = VISIBILITY_HIDDEN;
693 else if (!strcmp (str, "protected"))
694 default_visibilityglobal_options.x_default_visibility = VISIBILITY_PROTECTED;
695 else
696 GCC_BAD ("%<#pragma GCC visibility push()%> must specify %<default%>, "do { warning (OPT_Wpragmas, "%<#pragma GCC visibility push()%> must specify %<default%>, "
"%<internal%>, %<hidden%> or %<protected%>"
); return; } while (0)
697 "%<internal%>, %<hidden%> or %<protected%>")do { warning (OPT_Wpragmas, "%<#pragma GCC visibility push()%> must specify %<default%>, "
"%<internal%>, %<hidden%> or %<protected%>"
); return; } while (0)
;
698 visibility_options.inpragma = 1;
699}
700
701/* Pop a level of the #pragma visibility stack. Return true if
702 successful. */
703
704bool
705pop_visibility (int kind)
706{
707 if (!visstack.length ())
708 return false;
709 if ((visstack.last () >> 8) != kind)
710 return false;
711 default_visibilityglobal_options.x_default_visibility
712 = (enum symbol_visibility) (visstack.pop () & 0xff);
713 visibility_options.inpragma
714 = visstack.length () != 0;
715 return true;
716}
717
718/* Sets the default visibility for symbols to something other than that
719 specified on the command line. */
720
721static void
722handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
723{
724 /* Form is #pragma GCC visibility push(hidden)|pop */
725 tree x;
726 enum cpp_ttype token;
727 enum { bad, push, pop } action = bad;
728
729 token = pragma_lex (&x);
730 if (token == CPP_NAME)
731 {
732 const char *op = IDENTIFIER_POINTER (x)((const char *) (tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 732, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
733 if (!strcmp (op, "push"))
734 action = push;
735 else if (!strcmp (op, "pop"))
736 action = pop;
737 }
738 if (bad == action)
739 GCC_BAD ("%<#pragma GCC visibility%> must be followed by %<push%> "do { warning (OPT_Wpragmas, "%<#pragma GCC visibility%> must be followed by %<push%> "
"or %<pop%>"); return; } while (0)
740 "or %<pop%>")do { warning (OPT_Wpragmas, "%<#pragma GCC visibility%> must be followed by %<push%> "
"or %<pop%>"); return; } while (0)
;
741 else
742 {
743 if (pop == action)
744 {
745 if (! pop_visibility (0))
746 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>")do { warning (OPT_Wpragmas, "no matching push for %<#pragma GCC visibility pop%>"
); return; } while (0)
;
747 }
748 else
749 {
750 if (pragma_lex (&x) != CPP_OPEN_PAREN)
751 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored")do { warning (OPT_Wpragmas, "missing %<(%> after %<#pragma GCC visibility push%> - ignored"
); return; } while (0)
;
752 token = pragma_lex (&x);
753 if (token != CPP_NAME)
754 GCC_BAD ("malformed %<#pragma GCC visibility push%>")do { warning (OPT_Wpragmas, "malformed %<#pragma GCC visibility push%>"
); return; } while (0)
;
755 else
756 push_visibility (IDENTIFIER_POINTER (x)((const char *) (tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 756, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
, 0);
757 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
758 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored")do { warning (OPT_Wpragmas, "missing %<(%> after %<#pragma GCC visibility push%> - ignored"
); return; } while (0)
;
759 }
760 }
761 if (pragma_lex (&x) != CPP_EOF)
762 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
763}
764
765static void
766handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
767{
768 tree x;
769 location_t loc;
770 enum cpp_ttype token = pragma_lex (&x, &loc);
771 if (token != CPP_NAME)
772 {
773 warning_at (loc, OPT_Wpragmas,
774 "missing [error|warning|ignored|push|pop|ignored_attributes]"
775 " after %<#pragma GCC diagnostic%>");
776 return;
777 }
778
779 diagnostic_t kind;
780 const char *kind_string = IDENTIFIER_POINTER (x)((const char *) (tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 780, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
781 if (strcmp (kind_string, "error") == 0)
782 kind = DK_ERROR;
783 else if (strcmp (kind_string, "warning") == 0)
784 kind = DK_WARNING;
785 else if (strcmp (kind_string, "ignored") == 0)
786 kind = DK_IGNORED;
787 else if (strcmp (kind_string, "push") == 0)
788 {
789 diagnostic_push_diagnostics (global_dc, input_location);
790 return;
791 }
792 else if (strcmp (kind_string, "pop") == 0)
793 {
794 diagnostic_pop_diagnostics (global_dc, input_location);
795 return;
796 }
797 else if (strcmp (kind_string, "ignored_attributes") == 0)
798 {
799 token = pragma_lex (&x, &loc);
800 if (token != CPP_STRING)
801 {
802 warning_at (loc, OPT_Wpragmas,
803 "missing attribute name after %<#pragma GCC diagnostic "
804 "ignored_attributes%>");
805 return;
806 }
807 char *args = xstrdup (TREE_STRING_POINTER (x)((const char *)((tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 807, __FUNCTION__, (STRING_CST)))->string.str))
);
808 const size_t l = strlen (args);
809 if (l == 0)
810 {
811 warning_at (loc, OPT_Wpragmas, "missing argument to %<#pragma GCC "
812 "diagnostic ignored_attributes%>");
813 free (args);
814 return;
815 }
816 else if (args[l - 1] == ',')
817 {
818 warning_at (loc, OPT_Wpragmas, "trailing %<,%> in arguments for "
819 "%<#pragma GCC diagnostic ignored_attributes%>");
820 free (args);
821 return;
822 }
823 auto_vec<char *> v;
824 for (char *p = strtok (args, ","); p; p = strtok (NULLnullptr, ","))
825 v.safe_push (p);
826 handle_ignored_attributes_option (&v);
827 free (args);
828 return;
829 }
830 else
831 {
832 warning_at (loc, OPT_Wpragmas,
833 "expected [error|warning|ignored|push|pop|ignored_attributes]"
834 " after %<#pragma GCC diagnostic%>");
835 return;
836 }
837
838 token = pragma_lex (&x, &loc);
839 if (token != CPP_STRING)
840 {
841 warning_at (loc, OPT_Wpragmas,
842 "missing option after %<#pragma GCC diagnostic%> kind");
843 return;
844 }
845
846 const char *option_string = TREE_STRING_POINTER (x)((const char *)((tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 846, __FUNCTION__, (STRING_CST)))->string.str))
;
847 unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON(1U << 21);
848 /* option_string + 1 to skip the initial '-' */
849 unsigned int option_index = find_opt (option_string + 1, lang_mask);
850 if (option_index == OPT_SPECIAL_unknown)
851 {
852 auto_diagnostic_group d;
853 if (warning_at (loc, OPT_Wpragmas,
854 "unknown option after %<#pragma GCC diagnostic%> kind"))
855 {
856 option_proposer op;
857 const char *hint = op.suggest_option (option_string + 1);
858 if (hint)
859 inform (loc, "did you mean %<-%s%>?", hint);
860 }
861 return;
862 }
863 else if (!(cl_options[option_index].flags & CL_WARNING(1U << 17)))
864 {
865 warning_at (loc, OPT_Wpragmas,
866 "%qs is not an option that controls warnings", option_string);
867 return;
868 }
869 else if (!(cl_options[option_index].flags & lang_mask))
870 {
871 char *ok_langs = write_langs (cl_options[option_index].flags);
872 char *bad_lang = write_langs (c_common_option_lang_mask ());
873 warning_at (loc, OPT_Wpragmas,
874 "option %qs is valid for %s but not for %s",
875 option_string, ok_langs, bad_lang);
876 free (ok_langs);
877 free (bad_lang);
878 return;
879 }
880
881 struct cl_option_handlers handlers;
882 set_default_handlers (&handlers, NULLnullptr);
883 const char *arg = NULLnullptr;
884 if (cl_options[option_index].flags & CL_JOINED(1U << 22))
885 arg = option_string + 1 + cl_options[option_index].opt_len;
886 /* FIXME: input_location isn't the best location here, but it is
887 what we used to do here before and changing it breaks e.g.
888 PR69543 and PR69558. */
889 control_warning_option (option_index, (int) kind,
890 arg, kind != DK_IGNORED,
891 input_location, lang_mask, &handlers,
892 &global_options, &global_options_set,
893 global_dc);
894}
895
896/* Parse #pragma GCC target (xxx) to set target specific options. */
897static void
898handle_pragma_target(cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
899{
900 location_t loc;
901 enum cpp_ttype token;
902 tree x;
903 bool close_paren_needed_p = false;
904
905 if (cfun(cfun + 0))
906 {
907 error ("%<#pragma GCC option%> is not allowed inside functions");
908 return;
909 }
910
911 token = pragma_lex (&x, &loc);
912 if (token == CPP_OPEN_PAREN)
913 {
914 close_paren_needed_p = true;
915 token = pragma_lex (&x, &loc);
916 }
917
918 if (token != CPP_STRING)
919 {
920 GCC_BAD_AT (loc, "%<#pragma GCC option%> is not a string")do { warning_at (loc, OPT_Wpragmas, "%<#pragma GCC option%> is not a string"
); return; } while (0)
;
921 return;
922 }
923
924 /* Strings are user options. */
925 else
926 {
927 tree args = NULL_TREE(tree) nullptr;
928
929 do
930 {
931 /* Build up the strings now as a tree linked list. Skip empty
932 strings. */
933 if (TREE_STRING_LENGTH (x)((tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 933, __FUNCTION__, (STRING_CST)))->string.length)
> 0)
934 args = tree_cons (NULL_TREE(tree) nullptr, x, args);
935
936 token = pragma_lex (&x);
937 while (token == CPP_COMMA)
938 token = pragma_lex (&x);
939 }
940 while (token == CPP_STRING);
941
942 if (close_paren_needed_p)
943 {
944 if (token == CPP_CLOSE_PAREN)
945 token = pragma_lex (&x);
946 else
947 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "do { warning (OPT_Wpragmas, "%<#pragma GCC target (string [,string]...)%> does "
"not have a final %<)%>"); return; } while (0)
948 "not have a final %<)%>")do { warning (OPT_Wpragmas, "%<#pragma GCC target (string [,string]...)%> does "
"not have a final %<)%>"); return; } while (0)
;
949 }
950
951 if (token != CPP_EOF)
952 {
953 error ("%<#pragma GCC target%> string is badly formed");
954 return;
955 }
956
957 /* put arguments in the order the user typed them. */
958 args = nreverse (args);
959
960 if (targetm.target_option.pragma_parse (args, NULL_TREE(tree) nullptr))
961 current_target_pragmaglobal_trees[TI_CURRENT_TARGET_PRAGMA] = chainon (current_target_pragmaglobal_trees[TI_CURRENT_TARGET_PRAGMA], args);
962
963 /* A target pragma can also influence optimization options. */
964 tree current_optimize
965 = build_optimization_node (&global_options, &global_options_set);
966 if (current_optimize != optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT])
967 optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT] = current_optimize;
968 }
969}
970
971/* Handle #pragma GCC optimize to set optimization options. */
972static void
973handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
974{
975 enum cpp_ttype token;
976 tree x;
977 bool close_paren_needed_p = false;
978 tree optimization_previous_node = optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT];
979
980 if (cfun(cfun + 0))
981 {
982 error ("%<#pragma GCC optimize%> is not allowed inside functions");
983 return;
984 }
985
986 token = pragma_lex (&x);
987 if (token == CPP_OPEN_PAREN)
988 {
989 close_paren_needed_p = true;
990 token = pragma_lex (&x);
991 }
992
993 if (token != CPP_STRING && token != CPP_NUMBER)
994 {
995 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number")do { warning (OPT_Wpragmas, "%<#pragma GCC optimize%> is not a string or number"
); return; } while (0)
;
996 return;
997 }
998
999 /* Strings/numbers are user options. */
1000 else
1001 {
1002 tree args = NULL_TREE(tree) nullptr;
1003
1004 do
1005 {
1006 /* Build up the numbers/strings now as a list. */
1007 if (token != CPP_STRING || TREE_STRING_LENGTH (x)((tree_check ((x), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1007, __FUNCTION__, (STRING_CST)))->string.length)
> 0)
1008 args = tree_cons (NULL_TREE(tree) nullptr, x, args);
1009
1010 token = pragma_lex (&x);
1011 while (token == CPP_COMMA)
1012 token = pragma_lex (&x);
1013 }
1014 while (token == CPP_STRING || token == CPP_NUMBER);
1015
1016 if (close_paren_needed_p)
1017 {
1018 if (token == CPP_CLOSE_PAREN)
1019 token = pragma_lex (&x);
1020 else
1021 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "do { warning (OPT_Wpragmas, "%<#pragma GCC optimize (string [,string]...)%> does "
"not have a final %<)%>"); return; } while (0)
1022 "not have a final %<)%>")do { warning (OPT_Wpragmas, "%<#pragma GCC optimize (string [,string]...)%> does "
"not have a final %<)%>"); return; } while (0)
;
1023 }
1024
1025 if (token != CPP_EOF)
1026 {
1027 error ("%<#pragma GCC optimize%> string is badly formed");
1028 return;
1029 }
1030
1031 /* put arguments in the order the user typed them. */
1032 args = nreverse (args);
1033
1034 parse_optimize_options (args, false);
1035 current_optimize_pragmaglobal_trees[TI_CURRENT_OPTIMIZE_PRAGMA] = chainon (current_optimize_pragmaglobal_trees[TI_CURRENT_OPTIMIZE_PRAGMA], args);
1036 optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT]
1037 = build_optimization_node (&global_options, &global_options_set);
1038 c_cpp_builtins_optimize_pragma (parse_in,
1039 optimization_previous_node,
1040 optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT]);
1041 }
1042}
1043
1044/* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
1045 both the binary representation of the options and the TREE_LIST of
1046 strings that will be added to the function's attribute list. */
1047struct GTY(()) opt_stack {
1048 struct opt_stack *prev;
1049 tree target_binary;
1050 tree target_strings;
1051 tree optimize_binary;
1052 tree optimize_strings;
1053 gcc_options * GTY ((skip)) saved_global_options;
1054};
1055
1056static GTY(()) struct opt_stack * options_stack;
1057
1058/* Handle #pragma GCC push_options to save the current target and optimization
1059 options. */
1060
1061static void
1062handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
1063{
1064 enum cpp_ttype token;
1065 tree x = 0;
1066
1067 token = pragma_lex (&x);
1068 if (token != CPP_EOF)
1069 {
1070 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1071 return;
1072 }
1073
1074 opt_stack *p = ggc_alloc<opt_stack> ();
1075 p->prev = options_stack;
1076 options_stack = p;
1077
1078 /* Save optimization and target flags in binary format. */
1079 if (flag_checkingglobal_options.x_flag_checking)
1080 {
1081 p->saved_global_options = XNEW (gcc_options)((gcc_options *) xmalloc (sizeof (gcc_options)));
1082 *p->saved_global_options = global_options;
1083 }
1084 p->optimize_binary = build_optimization_node (&global_options,
1085 &global_options_set);
1086 p->target_binary = build_target_option_node (&global_options,
1087 &global_options_set);
1088
1089 /* Save optimization and target flags in string list format. */
1090 p->optimize_strings = copy_list (current_optimize_pragmaglobal_trees[TI_CURRENT_OPTIMIZE_PRAGMA]);
1091 p->target_strings = copy_list (current_target_pragmaglobal_trees[TI_CURRENT_TARGET_PRAGMA]);
1092}
1093
1094/* Handle #pragma GCC pop_options to restore the current target and
1095 optimization options from a previous push_options. */
1096
1097static void
1098handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
1099{
1100 enum cpp_ttype token;
1101 tree x = 0;
1102 opt_stack *p;
1103
1104 token = pragma_lex (&x);
1105 if (token != CPP_EOF)
1106 {
1107 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1108 return;
1109 }
1110
1111 if (! options_stack)
1112 {
1113 warning (OPT_Wpragmas,
1114 "%<#pragma GCC pop_options%> without a corresponding "
1115 "%<#pragma GCC push_options%>");
1116 return;
1117 }
1118
1119 p = options_stack;
1120 options_stack = p->prev;
1121
1122 if (p->target_binary != target_option_current_nodeglobal_trees[TI_TARGET_OPTION_CURRENT])
1123 {
1124 (void) targetm.target_option.pragma_parse (NULL_TREE(tree) nullptr, p->target_binary);
1125 target_option_current_nodeglobal_trees[TI_TARGET_OPTION_CURRENT] = p->target_binary;
1126 }
1127
1128 /* Always restore optimization options as optimization_current_node is
1129 * overwritten by invoke_set_current_function_hook. */
1130 cl_optimization_restore (&global_options, &global_options_set,
1131 TREE_OPTIMIZATION (p->optimize_binary)((tree_check ((p->optimize_binary), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1131, __FUNCTION__, (OPTIMIZATION_NODE)))->optimization.
opts)
);
1132 cl_target_option_restore (&global_options, &global_options_set,
1133 TREE_TARGET_OPTION (p->target_binary)((tree_check ((p->target_binary), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1133, __FUNCTION__, (TARGET_OPTION_NODE)))->target_option
.opts)
);
1134
1135 if (p->optimize_binary != optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT])
1136 {
1137 c_cpp_builtins_optimize_pragma (parse_in, optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT],
1138 p->optimize_binary);
1139 optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT] = p->optimize_binary;
1140 }
1141 if (flag_checkingglobal_options.x_flag_checking)
1142 {
1143 cl_optimization_compare (p->saved_global_options, &global_options);
1144 free (p->saved_global_options);
1145 }
1146
1147 current_target_pragmaglobal_trees[TI_CURRENT_TARGET_PRAGMA] = p->target_strings;
1148 current_optimize_pragmaglobal_trees[TI_CURRENT_OPTIMIZE_PRAGMA] = p->optimize_strings;
1149}
1150
1151/* Handle #pragma GCC reset_options to restore the current target and
1152 optimization options to the original options used on the command line. */
1153
1154static void
1155handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
1156{
1157 enum cpp_ttype token;
1158 tree x = 0;
1159 tree new_optimize = optimization_default_nodeglobal_trees[TI_OPTIMIZATION_DEFAULT];
1160 tree new_target = target_option_default_nodeglobal_trees[TI_TARGET_OPTION_DEFAULT];
1161
1162 token = pragma_lex (&x);
1163 if (token != CPP_EOF)
1164 {
1165 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1166 return;
1167 }
1168
1169 if (new_target != target_option_current_nodeglobal_trees[TI_TARGET_OPTION_CURRENT])
1170 {
1171 (void) targetm.target_option.pragma_parse (NULL_TREE(tree) nullptr, new_target);
1172 target_option_current_nodeglobal_trees[TI_TARGET_OPTION_CURRENT] = new_target;
1173 }
1174
1175 if (new_optimize != optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT])
1176 {
1177 tree old_optimize = optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT];
1178 cl_optimization_restore (&global_options, &global_options_set,
1179 TREE_OPTIMIZATION (new_optimize)((tree_check ((new_optimize), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1179, __FUNCTION__, (OPTIMIZATION_NODE)))->optimization.
opts)
);
1180 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1181 optimization_current_nodeglobal_trees[TI_OPTIMIZATION_CURRENT] = new_optimize;
1182 }
1183
1184 current_target_pragmaglobal_trees[TI_CURRENT_TARGET_PRAGMA] = NULL_TREE(tree) nullptr;
1185 current_optimize_pragmaglobal_trees[TI_CURRENT_OPTIMIZE_PRAGMA] = NULL_TREE(tree) nullptr;
1186}
1187
1188/* Print a plain user-specified message. */
1189
1190static void
1191handle_pragma_message (cpp_reader *ARG_UNUSED(dummy)dummy __attribute__ ((__unused__)))
1192{
1193 location_t loc;
1194 enum cpp_ttype token;
1195 tree x, message = 0;
1196
1197 token = pragma_lex (&x);
1198 if (token == CPP_OPEN_PAREN)
1199 {
1200 token = pragma_lex (&x);
1201 if (token == CPP_STRING)
1202 message = x;
1203 else
1204 GCC_BAD ("expected a string after %<#pragma message%>")do { warning (OPT_Wpragmas, "expected a string after %<#pragma message%>"
); return; } while (0)
;
1205 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1206 GCC_BAD ("malformed %<#pragma message%>, ignored")do { warning (OPT_Wpragmas, "malformed %<#pragma message%>, ignored"
); return; } while (0)
;
1207 }
1208 else if (token == CPP_STRING)
1209 message = x;
1210 else
1211 GCC_BAD ("expected a string after %<#pragma message%>")do { warning (OPT_Wpragmas, "expected a string after %<#pragma message%>"
); return; } while (0)
;
1212
1213 gcc_assert (message)((void)(!(message) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1213, __FUNCTION__), 0 : 0))
;
1214
1215 if (pragma_lex (&x, &loc) != CPP_EOF)
1216 warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma message%>");
1217
1218 if (TREE_STRING_LENGTH (message)((tree_check ((message), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1218, __FUNCTION__, (STRING_CST)))->string.length)
> 1)
1219 inform (input_location, "%<#pragma message: %s%>",
1220 TREE_STRING_POINTER (message)((const char *)((tree_check ((message), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1220, __FUNCTION__, (STRING_CST)))->string.str))
);
1221}
1222
1223/* Mark whether the current location is valid for a STDC pragma. */
1224
1225static bool valid_location_for_stdc_pragma;
1226
1227void
1228mark_valid_location_for_stdc_pragma (bool flag)
1229{
1230 valid_location_for_stdc_pragma = flag;
1231}
1232
1233/* Return true if the current location is valid for a STDC pragma. */
1234
1235bool
1236valid_location_for_stdc_pragma_p (void)
1237{
1238 return valid_location_for_stdc_pragma;
1239}
1240
1241enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1242
1243/* A STDC pragma must appear outside of external declarations or
1244 preceding all explicit declarations and statements inside a compound
1245 statement; its behavior is undefined if used in any other context.
1246 It takes a switch of ON, OFF, or DEFAULT. */
1247
1248static enum pragma_switch_t
1249handle_stdc_pragma (const char *pname)
1250{
1251 const char *arg;
1252 tree t;
1253 enum pragma_switch_t ret;
1254
1255 if (!valid_location_for_stdc_pragma_p ())
1256 {
1257 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1258 pname);
1259 return PRAGMA_BAD;
1260 }
1261
1262 if (pragma_lex (&t) != CPP_NAME)
1263 {
1264 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1265 return PRAGMA_BAD;
1266 }
1267
1268 arg = IDENTIFIER_POINTER (t)((const char *) (tree_check ((t), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1268, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str
)
;
1269
1270 if (!strcmp (arg, "ON"))
1271 ret = PRAGMA_ON;
1272 else if (!strcmp (arg, "OFF"))
1273 ret = PRAGMA_OFF;
1274 else if (!strcmp (arg, "DEFAULT"))
1275 ret = PRAGMA_DEFAULT;
1276 else
1277 {
1278 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1279 return PRAGMA_BAD;
1280 }
1281
1282 if (pragma_lex (&t) != CPP_EOF)
1283 {
1284 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1285 return PRAGMA_BAD;
1286 }
1287
1288 return ret;
1289}
1290
1291/* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1292 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1293 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1294
1295static void
1296handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy)dummy __attribute__ ((__unused__)))
1297{
1298 if (c_dialect_cxx ()((c_language & clk_cxx) != 0))
1299 {
1300 if (warn_unknown_pragmasglobal_options.x_warn_unknown_pragmas > in_system_header_at (input_location))
1301 warning (OPT_Wunknown_pragmas,
1302 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1303 " for C++");
1304 return;
1305 }
1306
1307 if (!targetm.decimal_float_supported_p ())
1308 {
1309 if (warn_unknown_pragmasglobal_options.x_warn_unknown_pragmas > in_system_header_at (input_location))
1310 warning (OPT_Wunknown_pragmas,
1311 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1312 " on this target");
1313 return;
1314 }
1315
1316 pedwarn (input_location, OPT_Wpedantic,
1317 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1318
1319 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1320 {
1321 case PRAGMA_ON:
1322 set_float_const_decimal64 ();
1323 break;
1324 case PRAGMA_OFF:
1325 case PRAGMA_DEFAULT:
1326 clear_float_const_decimal64 ();
1327 break;
1328 case PRAGMA_BAD:
1329 break;
1330 }
1331}
1332
1333/* A vector of registered pragma callbacks, which is never freed. */
1334
1335static vec<internal_pragma_handler> registered_pragmas;
1336
1337struct pragma_ns_name
1338{
1339 const char *space;
1340 const char *name;
1341};
1342
1343
1344static vec<pragma_ns_name> registered_pp_pragmas;
1345
1346struct omp_pragma_def { const char *name; unsigned int id; };
1347static const struct omp_pragma_def oacc_pragmas[] = {
1348 { "atomic", PRAGMA_OACC_ATOMIC },
1349 { "cache", PRAGMA_OACC_CACHE },
1350 { "data", PRAGMA_OACC_DATA },
1351 { "declare", PRAGMA_OACC_DECLARE },
1352 { "enter", PRAGMA_OACC_ENTER_DATA },
1353 { "exit", PRAGMA_OACC_EXIT_DATA },
1354 { "host_data", PRAGMA_OACC_HOST_DATA },
1355 { "kernels", PRAGMA_OACC_KERNELS },
1356 { "loop", PRAGMA_OACC_LOOP },
1357 { "parallel", PRAGMA_OACC_PARALLEL },
1358 { "routine", PRAGMA_OACC_ROUTINE },
1359 { "serial", PRAGMA_OACC_SERIAL },
1360 { "update", PRAGMA_OACC_UPDATE },
1361 { "wait", PRAGMA_OACC_WAIT }
1362};
1363static const struct omp_pragma_def omp_pragmas[] = {
1364 { "allocate", PRAGMA_OMP_ALLOCATE },
1365 { "atomic", PRAGMA_OMP_ATOMIC },
1366 { "barrier", PRAGMA_OMP_BARRIER },
1367 { "cancel", PRAGMA_OMP_CANCEL },
1368 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1369 { "critical", PRAGMA_OMP_CRITICAL },
1370 { "depobj", PRAGMA_OMP_DEPOBJ },
1371 { "error", PRAGMA_OMP_ERROR },
1372 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1373 { "flush", PRAGMA_OMP_FLUSH },
1374 { "nothing", PRAGMA_OMP_NOTHING },
1375 { "requires", PRAGMA_OMP_REQUIRES },
1376 { "scope", PRAGMA_OMP_SCOPE },
1377 { "section", PRAGMA_OMP_SECTION },
1378 { "sections", PRAGMA_OMP_SECTIONS },
1379 { "single", PRAGMA_OMP_SINGLE },
1380 { "task", PRAGMA_OMP_TASK },
1381 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1382 { "taskwait", PRAGMA_OMP_TASKWAIT },
1383 { "taskyield", PRAGMA_OMP_TASKYIELD },
1384 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1385};
1386static const struct omp_pragma_def omp_pragmas_simd[] = {
1387 { "declare", PRAGMA_OMP_DECLARE },
1388 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1389 { "for", PRAGMA_OMP_FOR },
1390 { "loop", PRAGMA_OMP_LOOP },
1391 { "masked", PRAGMA_OMP_MASKED },
1392 { "master", PRAGMA_OMP_MASTER },
1393 { "ordered", PRAGMA_OMP_ORDERED },
1394 { "parallel", PRAGMA_OMP_PARALLEL },
1395 { "scan", PRAGMA_OMP_SCAN },
1396 { "simd", PRAGMA_OMP_SIMD },
1397 { "target", PRAGMA_OMP_TARGET },
1398 { "taskloop", PRAGMA_OMP_TASKLOOP },
1399 { "teams", PRAGMA_OMP_TEAMS },
1400};
1401
1402void
1403c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1404{
1405 const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1406 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1407 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1408 / sizeof (*omp_pragmas);
1409 int i;
1410
1411 for (i = 0; i < n_oacc_pragmas; ++i)
1412 if (oacc_pragmas[i].id == id)
1413 {
1414 *space = "acc";
1415 *name = oacc_pragmas[i].name;
1416 return;
1417 }
1418
1419 for (i = 0; i < n_omp_pragmas; ++i)
1420 if (omp_pragmas[i].id == id)
1421 {
1422 *space = "omp";
1423 *name = omp_pragmas[i].name;
1424 return;
1425 }
1426
1427 for (i = 0; i < n_omp_pragmas_simd; ++i)
1428 if (omp_pragmas_simd[i].id == id)
1429 {
1430 *space = "omp";
1431 *name = omp_pragmas_simd[i].name;
1432 return;
1433 }
1434
1435 if (id >= PRAGMA_FIRST_EXTERNAL
1436 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1437 {
1438 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1439 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1440 return;
1441 }
1442
1443 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1443, __FUNCTION__))
;
1444}
1445
1446/* Front-end wrappers for pragma registration to avoid dragging
1447 cpplib.h in almost everywhere. */
1448
1449static void
1450c_register_pragma_1 (const char *space, const char *name,
1451 internal_pragma_handler ihandler, bool allow_expansion)
1452{
1453 unsigned id;
1454
1455 if (flag_preprocess_onlyglobal_options.x_flag_preprocess_only)
1456 {
1457 pragma_ns_name ns_name;
1458
1459 if (!allow_expansion)
1460 return;
1461
1462 ns_name.space = space;
1463 ns_name.name = name;
1464 registered_pp_pragmas.safe_push (ns_name);
1465 id = registered_pp_pragmas.length ();
1466 id += PRAGMA_FIRST_EXTERNAL - 1;
1467 }
1468 else
1469 {
1470 registered_pragmas.safe_push (ihandler);
1471 id = registered_pragmas.length ();
1472 id += PRAGMA_FIRST_EXTERNAL - 1;
1473
1474 /* The C front end allocates 8 bits in c_token. The C++ front end
1475 keeps the pragma kind in the form of INTEGER_CST, so no small
1476 limit applies. At present this is sufficient. */
1477 gcc_assert (id < 256)((void)(!(id < 256) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/c-family/c-pragma.c"
, 1477, __FUNCTION__), 0 : 0))
;
1478 }
1479
1480 cpp_register_deferred_pragma (parse_in, space, name, id,
1481 allow_expansion, false);
1482}
1483
1484/* Register a C pragma handler, using a space and a name. It disallows pragma
1485 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1486void
1487c_register_pragma (const char *space, const char *name,
1488 pragma_handler_1arg handler)
1489{
1490 internal_pragma_handler ihandler;
1491
1492 ihandler.handler.handler_1arg = handler;
1493 ihandler.extra_data = false;
1494 ihandler.data = NULLnullptr;
1495 c_register_pragma_1 (space, name, ihandler, false);
1496}
1497
1498/* Register a C pragma handler, using a space and a name, it also carries an
1499 extra data field which can be used by the handler. It disallows pragma
1500 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1501 instead). */
1502void
1503c_register_pragma_with_data (const char *space, const char *name,
1504 pragma_handler_2arg handler, void * data)
1505{
1506 internal_pragma_handler ihandler;
1507
1508 ihandler.handler.handler_2arg = handler;
1509 ihandler.extra_data = true;
1510 ihandler.data = data;
1511 c_register_pragma_1 (space, name, ihandler, false);
1512}
1513
1514/* Register a C pragma handler, using a space and a name. It allows pragma
1515 expansion as in the following example:
1516
1517 #define NUMBER 10
1518 #pragma count (NUMBER)
1519
1520 Name expansion is still disallowed. */
1521void
1522c_register_pragma_with_expansion (const char *space, const char *name,
1523 pragma_handler_1arg handler)
1524{
1525 internal_pragma_handler ihandler;
1526
1527 ihandler.handler.handler_1arg = handler;
1528 ihandler.extra_data = false;
1529 ihandler.data = NULLnullptr;
1530 c_register_pragma_1 (space, name, ihandler, true);
1531}
1532
1533/* Register a C pragma handler, using a space and a name, it also carries an
1534 extra data field which can be used by the handler. It allows pragma
1535 expansion as in the following example:
1536
1537 #define NUMBER 10
1538 #pragma count (NUMBER)
1539
1540 Name expansion is still disallowed. */
1541void
1542c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1543 pragma_handler_2arg handler,
1544 void *data)
1545{
1546 internal_pragma_handler ihandler;
1547
1548 ihandler.handler.handler_2arg = handler;
1549 ihandler.extra_data = true;
1550 ihandler.data = data;
1551 c_register_pragma_1 (space, name, ihandler, true);
1552}
1553
1554void
1555c_invoke_pragma_handler (unsigned int id)
1556{
1557 internal_pragma_handler *ihandler;
1558 pragma_handler_1arg handler_1arg;
1559 pragma_handler_2arg handler_2arg;
1560
1561 id -= PRAGMA_FIRST_EXTERNAL;
1562 ihandler = &registered_pragmas[id];
1563 if (ihandler->extra_data)
1564 {
1565 handler_2arg = ihandler->handler.handler_2arg;
1566 handler_2arg (parse_in, ihandler->data);
1567 }
1568 else
1569 {
1570 handler_1arg = ihandler->handler.handler_1arg;
1571 handler_1arg (parse_in);
1572 }
1573}
1574
1575/* Set up front-end pragmas. */
1576void
1577init_pragma (void)
1578{
1579 if (flag_openaccglobal_options.x_flag_openacc)
1580 {
1581 const int n_oacc_pragmas
1582 = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1583 int i;
1584
1585 for (i = 0; i < n_oacc_pragmas; ++i)
1586 cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
1587 oacc_pragmas[i].id, true, true);
1588 }
1589
1590 if (flag_openmpglobal_options.x_flag_openmp)
1591 {
1592 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1593 int i;
1594
1595 for (i = 0; i < n_omp_pragmas; ++i)
1596 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1597 omp_pragmas[i].id, true, true);
1598 }
1599 if (flag_openmpglobal_options.x_flag_openmp || flag_openmp_simdglobal_options.x_flag_openmp_simd)
1600 {
1601 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1602 / sizeof (*omp_pragmas);
1603 int i;
1604
1605 for (i = 0; i < n_omp_pragmas_simd; ++i)
1606 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1607 omp_pragmas_simd[i].id, true, true);
1608 }
1609
1610 if (!flag_preprocess_onlyglobal_options.x_flag_preprocess_only)
1611 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1612 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1613
1614 if (!flag_preprocess_onlyglobal_options.x_flag_preprocess_only)
1615 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1616 false);
1617
1618 if (!flag_preprocess_onlyglobal_options.x_flag_preprocess_only)
1619 cpp_register_deferred_pragma (parse_in, "GCC", "unroll", PRAGMA_UNROLL,
1620 false, false);
1621
1622#ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1623 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1624#else
1625 c_register_pragma (0, "pack", handle_pragma_pack);
1626#endif
1627 c_register_pragma (0, "weak", handle_pragma_weak);
1628
1629 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1630
1631 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1632 c_register_pragma ("GCC", "target", handle_pragma_target);
1633 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1634 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1635 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1636 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1637
1638 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1639 handle_pragma_float_const_decimal64);
1640
1641 c_register_pragma_with_expansion (0, "redefine_extname",
1642 handle_pragma_redefine_extname);
1643
1644 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1645
1646#ifdef REGISTER_TARGET_PRAGMAS
1647 REGISTER_TARGET_PRAGMAS ()ix86_register_pragmas ();
1648#endif
1649
1650 global_sso = default_ssoglobal_options.x_default_sso;
1651 c_register_pragma (0, "scalar_storage_order",
1652 handle_pragma_scalar_storage_order);
1653
1654 /* Allow plugins to register their own pragmas. */
1655 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULLnullptr);
1656}
1657
1658#include "gt-c-family-c-pragma.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);
16
Assuming 'v' is non-null
17
'?' condition is true
368 if (!alloc)
18
Assuming 'alloc' is 0
19
Taking true branch
369 {
370 ::ggc_free (v);
371 v = NULLnullptr;
20
Null pointer value stored to 'pending_weaks'
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 zero-initialized values for vec<T, A, L>. This is
545 used to provide nil initializers for vec instances. Since vec must
546 be a trivially copyable type that can be copied by memcpy and zeroed
547 out by memset, it must have defaulted default and copy ctor and copy
548 assignment. To initialize a vec either use value initialization
549 (e.g., vec() or vec v{ };) or assign it the value vNULL. This isn't
550 needed for file-scope and function-local static vectors, which are
551 zero-initialized by default. */
552struct vnull { };
553constexpr vnull vNULL{ };
554
555
556/* Embeddable vector. These vectors are suitable to be embedded
557 in other data structures so that they can be pre-allocated in a
558 contiguous memory block.
559
560 Embeddable vectors are implemented using the trailing array idiom,
561 thus they are not resizeable without changing the address of the
562 vector object itself. This means you cannot have variables or
563 fields of embeddable vector type -- always use a pointer to a
564 vector. The one exception is the final field of a structure, which
565 could be a vector type.
566
567 You will have to use the embedded_size & embedded_init calls to
568 create such objects, and they will not be resizeable (so the 'safe'
569 allocation variants are not available).
570
571 Properties:
572
573 - The whole vector and control data are allocated in a single
574 contiguous block. It uses the trailing-vector idiom, so
575 allocation must reserve enough space for all the elements
576 in the vector plus its control data.
577 - The vector cannot be re-allocated.
578 - The vector cannot grow nor shrink.
579 - No indirections needed for access/manipulation.
580 - It requires 2 words of storage (prior to vector allocation). */
581
582template<typename T, typename A>
583struct GTY((user)) vec<T, A, vl_embed>
584{
585public:
586 unsigned allocated (void) const { return m_vecpfx.m_alloc; }
587 unsigned length (void) const { return m_vecpfx.m_num; }
588 bool is_empty (void) const { return m_vecpfx.m_num == 0; }
589 T *address (void) { return m_vecdata; }
590 const T *address (void) const { return m_vecdata; }
591 T *begin () { return address (); }
592 const T *begin () const { return address (); }
593 T *end () { return address () + length (); }
594 const T *end () const { return address () + length (); }
595 const T &operator[] (unsigned) const;
596 T &operator[] (unsigned);
597 T &last (void);
598 bool space (unsigned) const;
599 bool iterate (unsigned, T *) const;
600 bool iterate (unsigned, T **) const;
601 vec *copy (ALONE_CXX_MEM_STAT_INFO) const;
602 void splice (const vec &);
603 void splice (const vec *src);
604 T *quick_push (const T &);
605 T &pop (void);
606 void truncate (unsigned);
607 void quick_insert (unsigned, const T &);
608 void ordered_remove (unsigned);
609 void unordered_remove (unsigned);
610 void block_remove (unsigned, unsigned);
611 void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *));
612 void sort (int (*) (const void *, const void *, void *), void *);
613 void stablesort (int (*) (const void *, const void *, void *), void *);
614 T *bsearch (const void *key, int (*compar)(const void *, const void *));
615 T *bsearch (const void *key,
616 int (*compar)(const void *, const void *, void *), void *);
617 unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
618 bool contains (const T &search) const;
619 static size_t embedded_size (unsigned);
620 void embedded_init (unsigned, unsigned = 0, unsigned = 0);
621 void quick_grow (unsigned len);
622 void quick_grow_cleared (unsigned len);
623
624 /* vec class can access our internal data and functions. */
625 template <typename, typename, typename> friend struct vec;
626
627 /* The allocator types also need access to our internals. */
628 friend struct va_gc;
629 friend struct va_gc_atomic;
630 friend struct va_heap;
631
632 /* FIXME - These fields should be private, but we need to cater to
633 compilers that have stricter notions of PODness for types. */
634 vec_prefix m_vecpfx;
635 T m_vecdata[1];
636};
637
638
639/* Convenience wrapper functions to use when dealing with pointers to
640 embedded vectors. Some functionality for these vectors must be
641 provided via free functions for these reasons:
642
643 1- The pointer may be NULL (e.g., before initial allocation).
644
645 2- When the vector needs to grow, it must be reallocated, so
646 the pointer will change its value.
647
648 Because of limitations with the current GC machinery, all vectors
649 in GC memory *must* be pointers. */
650
651
652/* If V contains no room for NELEMS elements, return false. Otherwise,
653 return true. */
654template<typename T, typename A>
655inline bool
656vec_safe_space (const vec<T, A, vl_embed> *v, unsigned nelems)
657{
658 return v ? v->space (nelems) : nelems == 0;
659}
660
661
662/* If V is NULL, return 0. Otherwise, return V->length(). */
663template<typename T, typename A>
664inline unsigned
665vec_safe_length (const vec<T, A, vl_embed> *v)
666{
667 return v ? v->length () : 0;
668}
669
670
671/* If V is NULL, return NULL. Otherwise, return V->address(). */
672template<typename T, typename A>
673inline T *
674vec_safe_address (vec<T, A, vl_embed> *v)
675{
676 return v ? v->address () : NULLnullptr;
677}
678
679
680/* If V is NULL, return true. Otherwise, return V->is_empty(). */
681template<typename T, typename A>
682inline bool
683vec_safe_is_empty (vec<T, A, vl_embed> *v)
684{
685 return v ? v->is_empty () : true;
686}
687
688/* If V does not have space for NELEMS elements, call
689 V->reserve(NELEMS, EXACT). */
690template<typename T, typename A>
691inline bool
692vec_safe_reserve (vec<T, A, vl_embed> *&v, unsigned nelems, bool exact = false
693 CXX_MEM_STAT_INFO)
694{
695 bool extend = nelems
11.1
'nelems' is 1
11.1
'nelems' is 1
? !vec_safe_space (v, nelems) : false;
12
'?' condition is true
13
Assuming the condition is true
696 if (extend
13.1
'extend' is true
13.1
'extend' is true
)
14
Taking true branch
697 A::reserve (v, nelems, exact PASS_MEM_STAT);
15
Calling 'va_gc::reserve'
21
Returning from 'va_gc::reserve'
698 return extend;
699}
700
701template<typename T, typename A>
702inline bool
703vec_safe_reserve_exact (vec<T, A, vl_embed> *&v, unsigned nelems
704 CXX_MEM_STAT_INFO)
705{
706 return vec_safe_reserve (v, nelems, true PASS_MEM_STAT);
707}
708
709
710/* Allocate GC memory for V with space for NELEMS slots. If NELEMS
711 is 0, V is initialized to NULL. */
712
713template<typename T, typename A>
714inline void
715vec_alloc (vec<T, A, vl_embed> *&v, unsigned nelems CXX_MEM_STAT_INFO)
716{
717 v = NULLnullptr;
718 vec_safe_reserve (v, nelems, false PASS_MEM_STAT);
719}
720
721
722/* Free the GC memory allocated by vector V and set it to NULL. */
723
724template<typename T, typename A>
725inline void
726vec_free (vec<T, A, vl_embed> *&v)
727{
728 A::release (v);
729}
730
731
732/* Grow V to length LEN. Allocate it, if necessary. */
733template<typename T, typename A>
734inline void
735vec_safe_grow (vec<T, A, vl_embed> *&v, unsigned len,
736 bool exact = false CXX_MEM_STAT_INFO)
737{
738 unsigned oldlen = vec_safe_length (v);
739 gcc_checking_assert (len >= oldlen)((void)(!(len >= oldlen) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 739, __FUNCTION__), 0 : 0))
;
740 vec_safe_reserve (v, len - oldlen, exact PASS_MEM_STAT);
741 v->quick_grow (len);
742}
743
744
745/* If V is NULL, allocate it. Call V->safe_grow_cleared(LEN). */
746template<typename T, typename A>
747inline void
748vec_safe_grow_cleared (vec<T, A, vl_embed> *&v, unsigned len,
749 bool exact = false CXX_MEM_STAT_INFO)
750{
751 unsigned oldlen = vec_safe_length (v);
752 vec_safe_grow (v, len, exact PASS_MEM_STAT);
753 vec_default_construct (v->address () + oldlen, len - oldlen);
754}
755
756
757/* Assume V is not NULL. */
758
759template<typename T>
760inline void
761vec_safe_grow_cleared (vec<T, va_heap, vl_ptr> *&v,
762 unsigned len, bool exact = false CXX_MEM_STAT_INFO)
763{
764 v->safe_grow_cleared (len, exact PASS_MEM_STAT);
765}
766
767/* If V does not have space for NELEMS elements, call
768 V->reserve(NELEMS, EXACT). */
769
770template<typename T>
771inline bool
772vec_safe_reserve (vec<T, va_heap, vl_ptr> *&v, unsigned nelems, bool exact = false
773 CXX_MEM_STAT_INFO)
774{
775 return v->reserve (nelems, exact);
776}
777
778
779/* If V is NULL return false, otherwise return V->iterate(IX, PTR). */
780template<typename T, typename A>
781inline bool
782vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T **ptr)
783{
784 if (v)
785 return v->iterate (ix, ptr);
786 else
787 {
788 *ptr = 0;
789 return false;
790 }
791}
792
793template<typename T, typename A>
794inline bool
795vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T *ptr)
796{
797 if (v)
798 return v->iterate (ix, ptr);
799 else
800 {
801 *ptr = 0;
802 return false;
803 }
804}
805
806
807/* If V has no room for one more element, reallocate it. Then call
808 V->quick_push(OBJ). */
809template<typename T, typename A>
810inline T *
811vec_safe_push (vec<T, A, vl_embed> *&v, const T &obj CXX_MEM_STAT_INFO)
812{
813 vec_safe_reserve (v, 1, false PASS_MEM_STAT);
11
Calling 'vec_safe_reserve<pending_weak, va_gc>'
22
Returning from 'vec_safe_reserve<pending_weak, va_gc>'
814 return v->quick_push (obj);
23
Called C++ object pointer is null
815}
816
817
818/* if V has no room for one more element, reallocate it. Then call
819 V->quick_insert(IX, OBJ). */
820template<typename T, typename A>
821inline void
822vec_safe_insert (vec<T, A, vl_embed> *&v, unsigned ix, const T &obj
823 CXX_MEM_STAT_INFO)
824{
825 vec_safe_reserve (v, 1, false PASS_MEM_STAT);
826 v->quick_insert (ix, obj);
827}
828
829
830/* If V is NULL, do nothing. Otherwise, call V->truncate(SIZE). */
831template<typename T, typename A>
832inline void
833vec_safe_truncate (vec<T, A, vl_embed> *v, unsigned size)
834{
835 if (v)
836 v->truncate (size);
837}
838
839
840/* If SRC is not NULL, return a pointer to a copy of it. */
841template<typename T, typename A>
842inline vec<T, A, vl_embed> *
843vec_safe_copy (vec<T, A, vl_embed> *src CXX_MEM_STAT_INFO)
844{
845 return src ? src->copy (ALONE_PASS_MEM_STAT) : NULLnullptr;
846}
847
848/* Copy the elements from SRC to the end of DST as if by memcpy.
849 Reallocate DST, if necessary. */
850template<typename T, typename A>
851inline void
852vec_safe_splice (vec<T, A, vl_embed> *&dst, const vec<T, A, vl_embed> *src
853 CXX_MEM_STAT_INFO)
854{
855 unsigned src_len = vec_safe_length (src);
856 if (src_len)
857 {
858 vec_safe_reserve_exact (dst, vec_safe_length (dst) + src_len
859 PASS_MEM_STAT);
860 dst->splice (*src);
861 }
862}
863
864/* Return true if SEARCH is an element of V. Note that this is O(N) in the
865 size of the vector and so should be used with care. */
866
867template<typename T, typename A>
868inline bool
869vec_safe_contains (vec<T, A, vl_embed> *v, const T &search)
870{
871 return v ? v->contains (search) : false;
872}
873
874/* Index into vector. Return the IX'th element. IX must be in the
875 domain of the vector. */
876
877template<typename T, typename A>
878inline const T &
879vec<T, A, vl_embed>::operator[] (unsigned ix) const
880{
881 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"
, 881, __FUNCTION__), 0 : 0))
;
882 return m_vecdata[ix];
883}
884
885template<typename T, typename A>
886inline T &
887vec<T, A, vl_embed>::operator[] (unsigned ix)
888{
889 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"
, 889, __FUNCTION__), 0 : 0))
;
890 return m_vecdata[ix];
891}
892
893
894/* Get the final element of the vector, which must not be empty. */
895
896template<typename T, typename A>
897inline T &
898vec<T, A, vl_embed>::last (void)
899{
900 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"
, 900, __FUNCTION__), 0 : 0))
;
901 return (*this)[m_vecpfx.m_num - 1];
902}
903
904
905/* If this vector has space for NELEMS additional entries, return
906 true. You usually only need to use this if you are doing your
907 own vector reallocation, for instance on an embedded vector. This
908 returns true in exactly the same circumstances that vec::reserve
909 will. */
910
911template<typename T, typename A>
912inline bool
913vec<T, A, vl_embed>::space (unsigned nelems) const
914{
915 return m_vecpfx.m_alloc - m_vecpfx.m_num >= nelems;
916}
917
918
919/* Return iteration condition and update PTR to point to the IX'th
920 element of this vector. Use this to iterate over the elements of a
921 vector as follows,
922
923 for (ix = 0; vec<T, A>::iterate (v, ix, &ptr); ix++)
924 continue; */
925
926template<typename T, typename A>
927inline bool
928vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const
929{
930 if (ix < m_vecpfx.m_num)
931 {
932 *ptr = m_vecdata[ix];
933 return true;
934 }
935 else
936 {
937 *ptr = 0;
938 return false;
939 }
940}
941
942
943/* Return iteration condition and update *PTR to point to the
944 IX'th element of this vector. Use this to iterate over the
945 elements of a vector as follows,
946
947 for (ix = 0; v->iterate (ix, &ptr); ix++)
948 continue;
949
950 This variant is for vectors of objects. */
951
952template<typename T, typename A>
953inline bool
954vec<T, A, vl_embed>::iterate (unsigned ix, T **ptr) const
955{
956 if (ix < m_vecpfx.m_num)
957 {
958 *ptr = CONST_CAST (T *, &m_vecdata[ix])(const_cast<T *> ((&m_vecdata[ix])));
959 return true;
960 }
961 else
962 {
963 *ptr = 0;
964 return false;
965 }
966}
967
968
969/* Return a pointer to a copy of this vector. */
970
971template<typename T, typename A>
972inline vec<T, A, vl_embed> *
973vec<T, A, vl_embed>::copy (ALONE_MEM_STAT_DECLvoid) const
974{
975 vec<T, A, vl_embed> *new_vec = NULLnullptr;
976 unsigned len = length ();
977 if (len)
978 {
979 vec_alloc (new_vec, len PASS_MEM_STAT);
980 new_vec->embedded_init (len, len);
981 vec_copy_construct (new_vec->address (), m_vecdata, len);
982 }
983 return new_vec;
984}
985
986
987/* Copy the elements from SRC to the end of this vector as if by memcpy.
988 The vector must have sufficient headroom available. */
989
990template<typename T, typename A>
991inline void
992vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> &src)
993{
994 unsigned len = src.length ();
995 if (len)
996 {
997 gcc_checking_assert (space (len))((void)(!(space (len)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 997, __FUNCTION__), 0 : 0))
;
998 vec_copy_construct (end (), src.address (), len);
999 m_vecpfx.m_num += len;
1000 }
1001}
1002
1003template<typename T, typename A>
1004inline void
1005vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> *src)
1006{
1007 if (src)
1008 splice (*src);
1009}
1010
1011
1012/* Push OBJ (a new element) onto the end of the vector. There must be
1013 sufficient space in the vector. Return a pointer to the slot
1014 where OBJ was inserted. */
1015
1016template<typename T, typename A>
1017inline T *
1018vec<T, A, vl_embed>::quick_push (const T &obj)
1019{
1020 gcc_checking_assert (space (1))((void)(!(space (1)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1020, __FUNCTION__), 0 : 0))
;
1021 T *slot = &m_vecdata[m_vecpfx.m_num++];
1022 *slot = obj;
1023 return slot;
1024}
1025
1026
1027/* Pop and return the last element off the end of the vector. */
1028
1029template<typename T, typename A>
1030inline T &
1031vec<T, A, vl_embed>::pop (void)
1032{
1033 gcc_checking_assert (length () > 0)((void)(!(length () > 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1033, __FUNCTION__), 0 : 0))
;
1034 return m_vecdata[--m_vecpfx.m_num];
1035}
1036
1037
1038/* Set the length of the vector to SIZE. The new length must be less
1039 than or equal to the current length. This is an O(1) operation. */
1040
1041template<typename T, typename A>
1042inline void
1043vec<T, A, vl_embed>::truncate (unsigned size)
1044{
1045 gcc_checking_assert (length () >= size)((void)(!(length () >= size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1045, __FUNCTION__), 0 : 0))
;
1046 m_vecpfx.m_num = size;
1047}
1048
1049
1050/* Insert an element, OBJ, at the IXth position of this vector. There
1051 must be sufficient space. */
1052
1053template<typename T, typename A>
1054inline void
1055vec<T, A, vl_embed>::quick_insert (unsigned ix, const T &obj)
1056{
1057 gcc_checking_assert (length () < allocated ())((void)(!(length () < allocated ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1057, __FUNCTION__), 0 : 0))
;
1058 gcc_checking_assert (ix <= length ())((void)(!(ix <= length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1058, __FUNCTION__), 0 : 0))
;
1059 T *slot = &m_vecdata[ix];
1060 memmove (slot + 1, slot, (m_vecpfx.m_num++ - ix) * sizeof (T));
1061 *slot = obj;
1062}
1063
1064
1065/* Remove an element from the IXth position of this vector. Ordering of
1066 remaining elements is preserved. This is an O(N) operation due to
1067 memmove. */
1068
1069template<typename T, typename A>
1070inline void
1071vec<T, A, vl_embed>::ordered_remove (unsigned ix)
1072{
1073 gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1073, __FUNCTION__), 0 : 0))
;
1074 T *slot = &m_vecdata[ix];
1075 memmove (slot, slot + 1, (--m_vecpfx.m_num - ix) * sizeof (T));
1076}
1077
1078
1079/* Remove elements in [START, END) from VEC for which COND holds. Ordering of
1080 remaining elements is preserved. This is an O(N) operation. */
1081
1082#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"
, 1083, __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
); }
1083 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"
, 1083, __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 { \
1085 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"
, 1085, __FUNCTION__), 0 : 0))
; \
1086 for (read_index = write_index = (start); read_index < (end); \
1087 ++read_index) \
1088 { \
1089 elem_ptr = &(vec)[read_index]; \
1090 bool remove_p = (cond); \
1091 if (remove_p) \
1092 continue; \
1093 \
1094 if (read_index != write_index) \
1095 (vec)[write_index] = (vec)[read_index]; \
1096 \
1097 write_index++; \
1098 } \
1099 \
1100 if (read_index - write_index > 0) \
1101 (vec).block_remove (write_index, read_index - write_index); \
1102 }
1103
1104
1105/* Remove elements from VEC for which COND holds. Ordering of remaining
1106 elements is preserved. This is an O(N) operation. */
1107
1108#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"
, 1109, __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
); }
1109 cond){ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1109, __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 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"
, 1111, __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 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"
, 1111, __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
1113/* Remove an element from the IXth position of this vector. Ordering of
1114 remaining elements is destroyed. This is an O(1) operation. */
1115
1116template<typename T, typename A>
1117inline void
1118vec<T, A, vl_embed>::unordered_remove (unsigned ix)
1119{
1120 gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1120, __FUNCTION__), 0 : 0))
;
1121 m_vecdata[ix] = m_vecdata[--m_vecpfx.m_num];
1122}
1123
1124
1125/* Remove LEN elements starting at the IXth. Ordering is retained.
1126 This is an O(N) operation due to memmove. */
1127
1128template<typename T, typename A>
1129inline void
1130vec<T, A, vl_embed>::block_remove (unsigned ix, unsigned len)
1131{
1132 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"
, 1132, __FUNCTION__), 0 : 0))
;
1133 T *slot = &m_vecdata[ix];
1134 m_vecpfx.m_num -= len;
1135 memmove (slot, slot + len, (m_vecpfx.m_num - ix) * sizeof (T));
1136}
1137
1138
1139/* Sort the contents of this vector with qsort. CMP is the comparison
1140 function to pass to qsort. */
1141
1142template<typename T, typename A>
1143inline void
1144vec<T, A, vl_embed>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *))
1145{
1146 if (length () > 1)
1147 gcc_qsort (address (), length (), sizeof (T), cmp);
1148}
1149
1150/* Sort the contents of this vector with qsort. CMP is the comparison
1151 function to pass to qsort. */
1152
1153template<typename T, typename A>
1154inline void
1155vec<T, A, vl_embed>::sort (int (*cmp) (const void *, const void *, void *),
1156 void *data)
1157{
1158 if (length () > 1)
1159 gcc_sort_r (address (), length (), sizeof (T), cmp, data);
1160}
1161
1162/* Sort the contents of this vector with gcc_stablesort_r. CMP is the
1163 comparison function to pass to qsort. */
1164
1165template<typename T, typename A>
1166inline void
1167vec<T, A, vl_embed>::stablesort (int (*cmp) (const void *, const void *,
1168 void *), void *data)
1169{
1170 if (length () > 1)
1171 gcc_stablesort_r (address (), length (), sizeof (T), cmp, data);
1172}
1173
1174/* Search the contents of the sorted vector with a binary search.
1175 CMP is the comparison function to pass to bsearch. */
1176
1177template<typename T, typename A>
1178inline T *
1179vec<T, A, vl_embed>::bsearch (const void *key,
1180 int (*compar) (const void *, const void *))
1181{
1182 const void *base = this->address ();
1183 size_t nmemb = this->length ();
1184 size_t size = sizeof (T);
1185 /* The following is a copy of glibc stdlib-bsearch.h. */
1186 size_t l, u, idx;
1187 const void *p;
1188 int comparison;
1189
1190 l = 0;
1191 u = nmemb;
1192 while (l < u)
1193 {
1194 idx = (l + u) / 2;
1195 p = (const void *) (((const char *) base) + (idx * size));
1196 comparison = (*compar) (key, p);
1197 if (comparison < 0)
1198 u = idx;
1199 else if (comparison > 0)
1200 l = idx + 1;
1201 else
1202 return (T *)const_cast<void *>(p);
1203 }
1204
1205 return NULLnullptr;
1206}
1207
1208/* Search the contents of the sorted vector with a binary search.
1209 CMP is the comparison function to pass to bsearch. */
1210
1211template<typename T, typename A>
1212inline T *
1213vec<T, A, vl_embed>::bsearch (const void *key,
1214 int (*compar) (const void *, const void *,
1215 void *), void *data)
1216{
1217 const void *base = this->address ();
1218 size_t nmemb = this->length ();
1219 size_t size = sizeof (T);
1220 /* The following is a copy of glibc stdlib-bsearch.h. */
1221 size_t l, u, idx;
1222 const void *p;
1223 int comparison;
1224
1225 l = 0;
1226 u = nmemb;
1227 while (l < u)
1228 {
1229 idx = (l + u) / 2;
1230 p = (const void *) (((const char *) base) + (idx * size));
1231 comparison = (*compar) (key, p, data);
1232 if (comparison < 0)
1233 u = idx;
1234 else if (comparison > 0)
1235 l = idx + 1;
1236 else
1237 return (T *)const_cast<void *>(p);
1238 }
1239
1240 return NULLnullptr;
1241}
1242
1243/* Return true if SEARCH is an element of V. Note that this is O(N) in the
1244 size of the vector and so should be used with care. */
1245
1246template<typename T, typename A>
1247inline bool
1248vec<T, A, vl_embed>::contains (const T &search) const
1249{
1250 unsigned int len = length ();
1251 for (unsigned int i = 0; i < len; i++)
1252 if ((*this)[i] == search)
1253 return true;
1254
1255 return false;
1256}
1257
1258/* Find and return the first position in which OBJ could be inserted
1259 without changing the ordering of this vector. LESSTHAN is a
1260 function that returns true if the first argument is strictly less
1261 than the second. */
1262
1263template<typename T, typename A>
1264unsigned
1265vec<T, A, vl_embed>::lower_bound (T obj, bool (*lessthan)(const T &, const T &))
1266 const
1267{
1268 unsigned int len = length ();
1269 unsigned int half, middle;
1270 unsigned int first = 0;
1271 while (len > 0)
1272 {
1273 half = len / 2;
1274 middle = first;
1275 middle += half;
1276 T middle_elem = (*this)[middle];
1277 if (lessthan (middle_elem, obj))
1278 {
1279 first = middle;
1280 ++first;
1281 len = len - half - 1;
1282 }
1283 else
1284 len = half;
1285 }
1286 return first;
1287}
1288
1289
1290/* Return the number of bytes needed to embed an instance of an
1291 embeddable vec inside another data structure.
1292
1293 Use these methods to determine the required size and initialization
1294 of a vector V of type T embedded within another structure (as the
1295 final member):
1296
1297 size_t vec<T, A, vl_embed>::embedded_size (unsigned alloc);
1298 void v->embedded_init (unsigned alloc, unsigned num);
1299
1300 These allow the caller to perform the memory allocation. */
1301
1302template<typename T, typename A>
1303inline size_t
1304vec<T, A, vl_embed>::embedded_size (unsigned alloc)
1305{
1306 struct alignas (T) U { char data[sizeof (T)]; };
1307 typedef vec<U, A, vl_embed> vec_embedded;
1308 typedef typename std::conditional<std::is_standard_layout<T>::value,
1309 vec, vec_embedded>::type vec_stdlayout;
1310 static_assert (sizeof (vec_stdlayout) == sizeof (vec), "");
1311 static_assert (alignof (vec_stdlayout) == alignof (vec), "");
1312 return offsetof (vec_stdlayout, m_vecdata)__builtin_offsetof(vec_stdlayout, m_vecdata) + alloc * sizeof (T);
1313}
1314
1315
1316/* Initialize the vector to contain room for ALLOC elements and
1317 NUM active elements. */
1318
1319template<typename T, typename A>
1320inline void
1321vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num, unsigned aut)
1322{
1323 m_vecpfx.m_alloc = alloc;
1324 m_vecpfx.m_using_auto_storage = aut;
1325 m_vecpfx.m_num = num;
1326}
1327
1328
1329/* Grow the vector to a specific length. LEN must be as long or longer than
1330 the current length. The new elements are uninitialized. */
1331
1332template<typename T, typename A>
1333inline void
1334vec<T, A, vl_embed>::quick_grow (unsigned len)
1335{
1336 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"
, 1336, __FUNCTION__), 0 : 0))
;
1337 m_vecpfx.m_num = len;
1338}
1339
1340
1341/* Grow the vector to a specific length. LEN must be as long or longer than
1342 the current length. The new elements are initialized to zero. */
1343
1344template<typename T, typename A>
1345inline void
1346vec<T, A, vl_embed>::quick_grow_cleared (unsigned len)
1347{
1348 unsigned oldlen = length ();
1349 size_t growby = len - oldlen;
1350 quick_grow (len);
1351 if (growby != 0)
1352 vec_default_construct (address () + oldlen, growby);
1353}
1354
1355/* Garbage collection support for vec<T, A, vl_embed>. */
1356
1357template<typename T>
1358void
1359gt_ggc_mx (vec<T, va_gc> *v)
1360{
1361 extern void gt_ggc_mx (T &);
1362 for (unsigned i = 0; i < v->length (); i++)
1363 gt_ggc_mx ((*v)[i]);
1364}
1365
1366template<typename T>
1367void
1368gt_ggc_mx (vec<T, va_gc_atomic, vl_embed> *v ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
1369{
1370 /* Nothing to do. Vectors of atomic types wrt GC do not need to
1371 be traversed. */
1372}
1373
1374
1375/* PCH support for vec<T, A, vl_embed>. */
1376
1377template<typename T, typename A>
1378void
1379gt_pch_nx (vec<T, A, vl_embed> *v)
1380{
1381 extern void gt_pch_nx (T &);
1382 for (unsigned i = 0; i < v->length (); i++)
1383 gt_pch_nx ((*v)[i]);
1384}
1385
1386template<typename T, typename A>
1387void
1388gt_pch_nx (vec<T *, A, vl_embed> *v, gt_pointer_operator op, void *cookie)
1389{
1390 for (unsigned i = 0; i < v->length (); i++)
1391 op (&((*v)[i]), cookie);
1392}
1393
1394template<typename T, typename A>
1395void
1396gt_pch_nx (vec<T, A, vl_embed> *v, gt_pointer_operator op, void *cookie)
1397{
1398 extern void gt_pch_nx (T *, gt_pointer_operator, void *);
1399 for (unsigned i = 0; i < v->length (); i++)
1400 gt_pch_nx (&((*v)[i]), op, cookie);
1401}
1402
1403
1404/* Space efficient vector. These vectors can grow dynamically and are
1405 allocated together with their control data. They are suited to be
1406 included in data structures. Prior to initial allocation, they
1407 only take a single word of storage.
1408
1409 These vectors are implemented as a pointer to an embeddable vector.
1410 The semantics allow for this pointer to be NULL to represent empty
1411 vectors. This way, empty vectors occupy minimal space in the
1412 structure containing them.
1413
1414 Properties:
1415
1416 - The whole vector and control data are allocated in a single
1417 contiguous block.
1418 - The whole vector may be re-allocated.
1419 - Vector data may grow and shrink.
1420 - Access and manipulation requires a pointer test and
1421 indirection.
1422 - It requires 1 word of storage (prior to vector allocation).
1423
1424
1425 Limitations:
1426
1427 These vectors must be PODs because they are stored in unions.
1428 (http://en.wikipedia.org/wiki/Plain_old_data_structures).
1429 As long as we use C++03, we cannot have constructors nor
1430 destructors in classes that are stored in unions. */
1431
1432template<typename T, size_t N = 0>
1433class auto_vec;
1434
1435template<typename T>
1436struct vec<T, va_heap, vl_ptr>
1437{
1438public:
1439 /* Default ctors to ensure triviality. Use value-initialization
1440 (e.g., vec() or vec v{ };) or vNULL to create a zero-initialized
1441 instance. */
1442 vec () = default;
1443 vec (const vec &) = default;
1444 /* Initialization from the generic vNULL. */
1445 vec (vnull): m_vec () { }
1446 /* Same as default ctor: vec storage must be released manually. */
1447 ~vec () = default;
1448
1449 /* Defaulted same as copy ctor. */
1450 vec& operator= (const vec &) = default;
1451
1452 /* Prevent implicit conversion from auto_vec. Use auto_vec::to_vec()
1453 instead. */
1454 template <size_t N>
1455 vec (auto_vec<T, N> &) = delete;
1456
1457 template <size_t N>
1458 void operator= (auto_vec<T, N> &) = delete;
1459
1460 /* Memory allocation and deallocation for the embedded vector.
1461 Needed because we cannot have proper ctors/dtors defined. */
1462 void create (unsigned nelems CXX_MEM_STAT_INFO);
1463 void release (void);
1464
1465 /* Vector operations. */
1466 bool exists (void) const
1467 { return m_vec != NULLnullptr; }
1468
1469 bool is_empty (void) const
1470 { return m_vec ? m_vec->is_empty () : true; }
1471
1472 unsigned length (void) const
1473 { return m_vec ? m_vec->length () : 0; }
1474
1475 T *address (void)
1476 { return m_vec ? m_vec->m_vecdata : NULLnullptr; }
1477
1478 const T *address (void) const
1479 { return m_vec ? m_vec->m_vecdata : NULLnullptr; }
1480
1481 T *begin () { return address (); }
1482 const T *begin () const { return address (); }
1483 T *end () { return begin () + length (); }
1484 const T *end () const { return begin () + length (); }
1485 const T &operator[] (unsigned ix) const
1486 { return (*m_vec)[ix]; }
1487
1488 bool operator!=(const vec &other) const
1489 { return !(*this == other); }
1490
1491 bool operator==(const vec &other) const
1492 { return address () == other.address (); }
1493
1494 T &operator[] (unsigned ix)
1495 { return (*m_vec)[ix]; }
1496
1497 T &last (void)
1498 { return m_vec->last (); }
1499
1500 bool space (int nelems) const
1501 { return m_vec ? m_vec->space (nelems) : nelems == 0; }
1502
1503 bool iterate (unsigned ix, T *p) const;
1504 bool iterate (unsigned ix, T **p) const;
1505 vec copy (ALONE_CXX_MEM_STAT_INFO) const;
1506 bool reserve (unsigned, bool = false CXX_MEM_STAT_INFO);
1507 bool reserve_exact (unsigned CXX_MEM_STAT_INFO);
1508 void splice (const vec &);
1509 void safe_splice (const vec & CXX_MEM_STAT_INFO);
1510 T *quick_push (const T &);
1511 T *safe_push (const T &CXX_MEM_STAT_INFO);
1512 T &pop (void);
1513 void truncate (unsigned);
1514 void safe_grow (unsigned, bool = false CXX_MEM_STAT_INFO);
1515 void safe_grow_cleared (unsigned, bool = false CXX_MEM_STAT_INFO);
1516 void quick_grow (unsigned);
1517 void quick_grow_cleared (unsigned);
1518 void quick_insert (unsigned, const T &);
1519 void safe_insert (unsigned, const T & CXX_MEM_STAT_INFO);
1520 void ordered_remove (unsigned);
1521 void unordered_remove (unsigned);
1522 void block_remove (unsigned, unsigned);
1523 void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *));
1524 void sort (int (*) (const void *, const void *, void *), void *);
1525 void stablesort (int (*) (const void *, const void *, void *), void *);
1526 T *bsearch (const void *key, int (*compar)(const void *, const void *));
1527 T *bsearch (const void *key,
1528 int (*compar)(const void *, const void *, void *), void *);
1529 unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
1530 bool contains (const T &search) const;
1531 void reverse (void);
1532
1533 bool using_auto_storage () const;
1534
1535 /* FIXME - This field should be private, but we need to cater to
1536 compilers that have stricter notions of PODness for types. */
1537 vec<T, va_heap, vl_embed> *m_vec;
1538};
1539
1540
1541/* auto_vec is a subclass of vec that automatically manages creating and
1542 releasing the internal vector. If N is non zero then it has N elements of
1543 internal storage. The default is no internal storage, and you probably only
1544 want to ask for internal storage for vectors on the stack because if the
1545 size of the vector is larger than the internal storage that space is wasted.
1546 */
1547template<typename T, size_t N /* = 0 */>
1548class auto_vec : public vec<T, va_heap>
1549{
1550public:
1551 auto_vec ()
1552 {
1553 m_auto.embedded_init (MAX (N, 2)((N) > (2) ? (N) : (2)), 0, 1);
1554 this->m_vec = &m_auto;
1555 }
1556
1557 auto_vec (size_t s CXX_MEM_STAT_INFO)
1558 {
1559 if (s > N)
1560 {
1561 this->create (s PASS_MEM_STAT);
1562 return;
1563 }
1564
1565 m_auto.embedded_init (MAX (N, 2)((N) > (2) ? (N) : (2)), 0, 1);
1566 this->m_vec = &m_auto;
1567 }
1568
1569 ~auto_vec ()
1570 {
1571 this->release ();
1572 }
1573
1574 /* Explicitly convert to the base class. There is no conversion
1575 from a const auto_vec because a copy of the returned vec can
1576 be used to modify *THIS.
1577 This is a legacy function not to be used in new code. */
1578 vec<T, va_heap> to_vec_legacy () {
1579 return *static_cast<vec<T, va_heap> *>(this);
1580 }
1581
1582private:
1583 vec<T, va_heap, vl_embed> m_auto;
1584 T m_data[MAX (N - 1, 1)((N - 1) > (1) ? (N - 1) : (1))];
1585};
1586
1587/* auto_vec is a sub class of vec whose storage is released when it is
1588 destroyed. */
1589template<typename T>
1590class auto_vec<T, 0> : public vec<T, va_heap>
1591{
1592public:
1593 auto_vec () { this->m_vec = NULLnullptr; }
1594 auto_vec (size_t n CXX_MEM_STAT_INFO) { this->create (n PASS_MEM_STAT); }
1595 ~auto_vec () { this->release (); }
1596
1597 auto_vec (vec<T, va_heap>&& r)
1598 {
1599 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"
, 1599, __FUNCTION__), 0 : 0))
;
1600 this->m_vec = r.m_vec;
1601 r.m_vec = NULLnullptr;
1602 }
1603
1604 auto_vec (auto_vec<T> &&r)
1605 {
1606 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"
, 1606, __FUNCTION__), 0 : 0))
;
1607 this->m_vec = r.m_vec;
1608 r.m_vec = NULLnullptr;
1609 }
1610
1611 auto_vec& operator= (vec<T, va_heap>&& r)
1612 {
1613 if (this == &r)
1614 return *this;
1615
1616 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"
, 1616, __FUNCTION__), 0 : 0))
;
1617 this->release ();
1618 this->m_vec = r.m_vec;
1619 r.m_vec = NULLnullptr;
1620 return *this;
1621 }
1622
1623 auto_vec& operator= (auto_vec<T> &&r)
1624 {
1625 if (this == &r)
1626 return *this;
1627
1628 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"
, 1628, __FUNCTION__), 0 : 0))
;
1629 this->release ();
1630 this->m_vec = r.m_vec;
1631 r.m_vec = NULLnullptr;
1632 return *this;
1633 }
1634
1635 /* Explicitly convert to the base class. There is no conversion
1636 from a const auto_vec because a copy of the returned vec can
1637 be used to modify *THIS.
1638 This is a legacy function not to be used in new code. */
1639 vec<T, va_heap> to_vec_legacy () {
1640 return *static_cast<vec<T, va_heap> *>(this);
1641 }
1642
1643 // You probably don't want to copy a vector, so these are deleted to prevent
1644 // unintentional use. If you really need a copy of the vectors contents you
1645 // can use copy ().
1646 auto_vec(const auto_vec &) = delete;
1647 auto_vec &operator= (const auto_vec &) = delete;
1648};
1649
1650
1651/* Allocate heap memory for pointer V and create the internal vector
1652 with space for NELEMS elements. If NELEMS is 0, the internal
1653 vector is initialized to empty. */
1654
1655template<typename T>
1656inline void
1657vec_alloc (vec<T> *&v, unsigned nelems CXX_MEM_STAT_INFO)
1658{
1659 v = new vec<T>;
1660 v->create (nelems PASS_MEM_STAT);
1661}
1662
1663
1664/* A subclass of auto_vec <char *> that frees all of its elements on
1665 deletion. */
1666
1667class auto_string_vec : public auto_vec <char *>
1668{
1669 public:
1670 ~auto_string_vec ();
1671};
1672
1673/* A subclass of auto_vec <T *> that deletes all of its elements on
1674 destruction.
1675
1676 This is a crude way for a vec to "own" the objects it points to
1677 and clean up automatically.
1678
1679 For example, no attempt is made to delete elements when an item
1680 within the vec is overwritten.
1681
1682 We can't rely on gnu::unique_ptr within a container,
1683 since we can't rely on move semantics in C++98. */
1684
1685template <typename T>
1686class auto_delete_vec : public auto_vec <T *>
1687{
1688 public:
1689 auto_delete_vec () {}
1690 auto_delete_vec (size_t s) : auto_vec <T *> (s) {}
1691
1692 ~auto_delete_vec ();
1693
1694private:
1695 DISABLE_COPY_AND_ASSIGN(auto_delete_vec)auto_delete_vec (const auto_delete_vec&) = delete; void operator
= (const auto_delete_vec &) = delete
;
1696};
1697
1698/* Conditionally allocate heap memory for VEC and its internal vector. */
1699
1700template<typename T>
1701inline void
1702vec_check_alloc (vec<T, va_heap> *&vec, unsigned nelems CXX_MEM_STAT_INFO)
1703{
1704 if (!vec)
1705 vec_alloc (vec, nelems PASS_MEM_STAT);
1706}
1707
1708
1709/* Free the heap memory allocated by vector V and set it to NULL. */
1710
1711template<typename T>
1712inline void
1713vec_free (vec<T> *&v)
1714{
1715 if (v == NULLnullptr)
1716 return;
1717
1718 v->release ();
1719 delete v;
1720 v = NULLnullptr;
1721}
1722
1723
1724/* Return iteration condition and update PTR to point to the IX'th
1725 element of this vector. Use this to iterate over the elements of a
1726 vector as follows,
1727
1728 for (ix = 0; v.iterate (ix, &ptr); ix++)
1729 continue; */
1730
1731template<typename T>
1732inline bool
1733vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T *ptr) const
1734{
1735 if (m_vec)
1736 return m_vec->iterate (ix, ptr);
1737 else
1738 {
1739 *ptr = 0;
1740 return false;
1741 }
1742}
1743
1744
1745/* Return iteration condition and update *PTR to point to the
1746 IX'th element of this vector. Use this to iterate over the
1747 elements of a vector as follows,
1748
1749 for (ix = 0; v->iterate (ix, &ptr); ix++)
1750 continue;
1751
1752 This variant is for vectors of objects. */
1753
1754template<typename T>
1755inline bool
1756vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T **ptr) const
1757{
1758 if (m_vec)
1759 return m_vec->iterate (ix, ptr);
1760 else
1761 {
1762 *ptr = 0;
1763 return false;
1764 }
1765}
1766
1767
1768/* Convenience macro for forward iteration. */
1769#define FOR_EACH_VEC_ELT(V, I, P)for (I = 0; (V).iterate ((I), &(P)); ++(I)) \
1770 for (I = 0; (V).iterate ((I), &(P)); ++(I))
1771
1772#define FOR_EACH_VEC_SAFE_ELT(V, I, P)for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I)) \
1773 for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I))
1774
1775/* Likewise, but start from FROM rather than 0. */
1776#define FOR_EACH_VEC_ELT_FROM(V, I, P, FROM)for (I = (FROM); (V).iterate ((I), &(P)); ++(I)) \
1777 for (I = (FROM); (V).iterate ((I), &(P)); ++(I))
1778
1779/* Convenience macro for reverse iteration. */
1780#define FOR_EACH_VEC_ELT_REVERSE(V, I, P)for (I = (V).length () - 1; (V).iterate ((I), &(P)); (I)--
)
\
1781 for (I = (V).length () - 1; \
1782 (V).iterate ((I), &(P)); \
1783 (I)--)
1784
1785#define FOR_EACH_VEC_SAFE_ELT_REVERSE(V, I, P)for (I = vec_safe_length (V) - 1; vec_safe_iterate ((V), (I),
&(P)); (I)--)
\
1786 for (I = vec_safe_length (V) - 1; \
1787 vec_safe_iterate ((V), (I), &(P)); \
1788 (I)--)
1789
1790/* auto_string_vec's dtor, freeing all contained strings, automatically
1791 chaining up to ~auto_vec <char *>, which frees the internal buffer. */
1792
1793inline
1794auto_string_vec::~auto_string_vec ()
1795{
1796 int i;
1797 char *str;
1798 FOR_EACH_VEC_ELT (*this, i, str)for (i = 0; (*this).iterate ((i), &(str)); ++(i))
1799 free (str);
1800}
1801
1802/* auto_delete_vec's dtor, deleting all contained items, automatically
1803 chaining up to ~auto_vec <T*>, which frees the internal buffer. */
1804
1805template <typename T>
1806inline
1807auto_delete_vec<T>::~auto_delete_vec ()
1808{
1809 int i;
1810 T *item;
1811 FOR_EACH_VEC_ELT (*this, i, item)for (i = 0; (*this).iterate ((i), &(item)); ++(i))
1812 delete item;
1813}
1814
1815
1816/* Return a copy of this vector. */
1817
1818template<typename T>
1819inline vec<T, va_heap, vl_ptr>
1820vec<T, va_heap, vl_ptr>::copy (ALONE_MEM_STAT_DECLvoid) const
1821{
1822 vec<T, va_heap, vl_ptr> new_vec{ };
1823 if (length ())
1824 new_vec.m_vec = m_vec->copy (ALONE_PASS_MEM_STAT);
1825 return new_vec;
1826}
1827
1828
1829/* Ensure that the vector has at least RESERVE slots available (if
1830 EXACT is false), or exactly RESERVE slots available (if EXACT is
1831 true).
1832
1833 This may create additional headroom if EXACT is false.
1834
1835 Note that this can cause the embedded vector to be reallocated.
1836 Returns true iff reallocation actually occurred. */
1837
1838template<typename T>
1839inline bool
1840vec<T, va_heap, vl_ptr>::reserve (unsigned nelems, bool exact MEM_STAT_DECL)
1841{
1842 if (space (nelems))
1843 return false;
1844
1845 /* For now play a game with va_heap::reserve to hide our auto storage if any,
1846 this is necessary because it doesn't have enough information to know the
1847 embedded vector is in auto storage, and so should not be freed. */
1848 vec<T, va_heap, vl_embed> *oldvec = m_vec;
1849 unsigned int oldsize = 0;
1850 bool handle_auto_vec = m_vec && using_auto_storage ();
1851 if (handle_auto_vec)
1852 {
1853 m_vec = NULLnullptr;
1854 oldsize = oldvec->length ();
1855 nelems += oldsize;
1856 }
1857
1858 va_heap::reserve (m_vec, nelems, exact PASS_MEM_STAT);
1859 if (handle_auto_vec)
1860 {
1861 vec_copy_construct (m_vec->address (), oldvec->address (), oldsize);
1862 m_vec->m_vecpfx.m_num = oldsize;
1863 }
1864
1865 return true;
1866}
1867
1868
1869/* Ensure that this vector has exactly NELEMS slots available. This
1870 will not create additional headroom. Note this can cause the
1871 embedded vector to be reallocated. Returns true iff reallocation
1872 actually occurred. */
1873
1874template<typename T>
1875inline bool
1876vec<T, va_heap, vl_ptr>::reserve_exact (unsigned nelems MEM_STAT_DECL)
1877{
1878 return reserve (nelems, true PASS_MEM_STAT);
1879}
1880
1881
1882/* Create the internal vector and reserve NELEMS for it. This is
1883 exactly like vec::reserve, but the internal vector is
1884 unconditionally allocated from scratch. The old one, if it
1885 existed, is lost. */
1886
1887template<typename T>
1888inline void
1889vec<T, va_heap, vl_ptr>::create (unsigned nelems MEM_STAT_DECL)
1890{
1891 m_vec = NULLnullptr;
1892 if (nelems > 0)
1893 reserve_exact (nelems PASS_MEM_STAT);
1894}
1895
1896
1897/* Free the memory occupied by the embedded vector. */
1898
1899template<typename T>
1900inline void
1901vec<T, va_heap, vl_ptr>::release (void)
1902{
1903 if (!m_vec)
1904 return;
1905
1906 if (using_auto_storage ())
1907 {
1908 m_vec->m_vecpfx.m_num = 0;
1909 return;
1910 }
1911
1912 va_heap::release (m_vec);
1913}
1914
1915/* Copy the elements from SRC to the end of this vector as if by memcpy.
1916 SRC and this vector must be allocated with the same memory
1917 allocation mechanism. This vector is assumed to have sufficient
1918 headroom available. */
1919
1920template<typename T>
1921inline void
1922vec<T, va_heap, vl_ptr>::splice (const vec<T, va_heap, vl_ptr> &src)
1923{
1924 if (src.length ())
1925 m_vec->splice (*(src.m_vec));
1926}
1927
1928
1929/* Copy the elements in SRC to the end of this vector as if by memcpy.
1930 SRC and this vector must be allocated with the same mechanism.
1931 If there is not enough headroom in this vector, it will be reallocated
1932 as needed. */
1933
1934template<typename T>
1935inline void
1936vec<T, va_heap, vl_ptr>::safe_splice (const vec<T, va_heap, vl_ptr> &src
1937 MEM_STAT_DECL)
1938{
1939 if (src.length ())
1940 {
1941 reserve_exact (src.length ());
1942 splice (src);
1943 }
1944}
1945
1946
1947/* Push OBJ (a new element) onto the end of the vector. There must be
1948 sufficient space in the vector. Return a pointer to the slot
1949 where OBJ was inserted. */
1950
1951template<typename T>
1952inline T *
1953vec<T, va_heap, vl_ptr>::quick_push (const T &obj)
1954{
1955 return m_vec->quick_push (obj);
1956}
1957
1958
1959/* Push a new element OBJ onto the end of this vector. Reallocates
1960 the embedded vector, if needed. Return a pointer to the slot where
1961 OBJ was inserted. */
1962
1963template<typename T>
1964inline T *
1965vec<T, va_heap, vl_ptr>::safe_push (const T &obj MEM_STAT_DECL)
1966{
1967 reserve (1, false PASS_MEM_STAT);
1968 return quick_push (obj);
1969}
1970
1971
1972/* Pop and return the last element off the end of the vector. */
1973
1974template<typename T>
1975inline T &
1976vec<T, va_heap, vl_ptr>::pop (void)
1977{
1978 return m_vec->pop ();
1979}
1980
1981
1982/* Set the length of the vector to LEN. The new length must be less
1983 than or equal to the current length. This is an O(1) operation. */
1984
1985template<typename T>
1986inline void
1987vec<T, va_heap, vl_ptr>::truncate (unsigned size)
1988{
1989 if (m_vec)
1990 m_vec->truncate (size);
1991 else
1992 gcc_checking_assert (size == 0)((void)(!(size == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1992, __FUNCTION__), 0 : 0))
;
1993}
1994
1995
1996/* Grow the vector to a specific length. LEN must be as long or
1997 longer than the current length. The new elements are
1998 uninitialized. Reallocate the internal vector, if needed. */
1999
2000template<typename T>
2001inline void
2002vec<T, va_heap, vl_ptr>::safe_grow (unsigned len, bool exact MEM_STAT_DECL)
2003{
2004 unsigned oldlen = length ();
2005 gcc_checking_assert (oldlen <= len)((void)(!(oldlen <= len) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2005, __FUNCTION__), 0 : 0))
;
2006 reserve (len - oldlen, exact PASS_MEM_STAT);
2007 if (m_vec)
2008 m_vec->quick_grow (len);
2009 else
2010 gcc_checking_assert (len == 0)((void)(!(len == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2010, __FUNCTION__), 0 : 0))
;
2011}
2012
2013
2014/* Grow the embedded vector to a specific length. LEN must be as
2015 long or longer than the current length. The new elements are
2016 initialized to zero. Reallocate the internal vector, if needed. */
2017
2018template<typename T>
2019inline void
2020vec<T, va_heap, vl_ptr>::safe_grow_cleared (unsigned len, bool exact
2021 MEM_STAT_DECL)
2022{
2023 unsigned oldlen = length ();
2024 size_t growby = len - oldlen;
2025 safe_grow (len, exact PASS_MEM_STAT);
2026 if (growby != 0)
2027 vec_default_construct (address () + oldlen, growby);
2028}
2029
2030
2031/* Same as vec::safe_grow but without reallocation of the internal vector.
2032 If the vector cannot be extended, a runtime assertion will be triggered. */
2033
2034template<typename T>
2035inline void
2036vec<T, va_heap, vl_ptr>::quick_grow (unsigned len)
2037{
2038 gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2038, __FUNCTION__), 0 : 0))
;
2039 m_vec->quick_grow (len);
2040}
2041
2042
2043/* Same as vec::quick_grow_cleared but without reallocation of the
2044 internal vector. If the vector cannot be extended, a runtime
2045 assertion will be triggered. */
2046
2047template<typename T>
2048inline void
2049vec<T, va_heap, vl_ptr>::quick_grow_cleared (unsigned len)
2050{
2051 gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2051, __FUNCTION__), 0 : 0))
;
2052 m_vec->quick_grow_cleared (len);
2053}
2054
2055
2056/* Insert an element, OBJ, at the IXth position of this vector. There
2057 must be sufficient space. */
2058
2059template<typename T>
2060inline void
2061vec<T, va_heap, vl_ptr>::quick_insert (unsigned ix, const T &obj)
2062{
2063 m_vec->quick_insert (ix, obj);
2064}
2065
2066
2067/* Insert an element, OBJ, at the IXth position of the vector.
2068 Reallocate the embedded vector, if necessary. */
2069
2070template<typename T>
2071inline void
2072vec<T, va_heap, vl_ptr>::safe_insert (unsigned ix, const T &obj MEM_STAT_DECL)
2073{
2074 reserve (1, false PASS_MEM_STAT);
2075 quick_insert (ix, obj);
2076}
2077
2078
2079/* Remove an element from the IXth position of this vector. Ordering of
2080 remaining elements is preserved. This is an O(N) operation due to
2081 a memmove. */
2082
2083template<typename T>
2084inline void
2085vec<T, va_heap, vl_ptr>::ordered_remove (unsigned ix)
2086{
2087 m_vec->ordered_remove (ix);
2088}
2089
2090
2091/* Remove an element from the IXth position of this vector. Ordering
2092 of remaining elements is destroyed. This is an O(1) operation. */
2093
2094template<typename T>
2095inline void
2096vec<T, va_heap, vl_ptr>::unordered_remove (unsigned ix)
2097{
2098 m_vec->unordered_remove (ix);
2099}
2100
2101
2102/* Remove LEN elements starting at the IXth. Ordering is retained.
2103 This is an O(N) operation due to memmove. */
2104
2105template<typename T>
2106inline void
2107vec<T, va_heap, vl_ptr>::block_remove (unsigned ix, unsigned len)
2108{
2109 m_vec->block_remove (ix, len);
2110}
2111
2112
2113/* Sort the contents of this vector with qsort. CMP is the comparison
2114 function to pass to qsort. */
2115
2116template<typename T>
2117inline void
2118vec<T, va_heap, vl_ptr>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *))
2119{
2120 if (m_vec)
2121 m_vec->qsort (cmp)qsort (cmp);
2122}
2123
2124/* Sort the contents of this vector with qsort. CMP is the comparison
2125 function to pass to qsort. */
2126
2127template<typename T>
2128inline void
2129vec<T, va_heap, vl_ptr>::sort (int (*cmp) (const void *, const void *,
2130 void *), void *data)
2131{
2132 if (m_vec)
2133 m_vec->sort (cmp, data);
2134}
2135
2136/* Sort the contents of this vector with gcc_stablesort_r. CMP is the
2137 comparison function to pass to qsort. */
2138
2139template<typename T>
2140inline void
2141vec<T, va_heap, vl_ptr>::stablesort (int (*cmp) (const void *, const void *,
2142 void *), void *data)
2143{
2144 if (m_vec)
2145 m_vec->stablesort (cmp, data);
2146}
2147
2148/* Search the contents of the sorted vector with a binary search.
2149 CMP is the comparison function to pass to bsearch. */
2150
2151template<typename T>
2152inline T *
2153vec<T, va_heap, vl_ptr>::bsearch (const void *key,
2154 int (*cmp) (const void *, const void *))
2155{
2156 if (m_vec)
2157 return m_vec->bsearch (key, cmp);
2158 return NULLnullptr;
2159}
2160
2161/* Search the contents of the sorted vector with a binary search.
2162 CMP is the comparison function to pass to bsearch. */
2163
2164template<typename T>
2165inline T *
2166vec<T, va_heap, vl_ptr>::bsearch (const void *key,
2167 int (*cmp) (const void *, const void *,
2168 void *), void *data)
2169{
2170 if (m_vec)
2171 return m_vec->bsearch (key, cmp, data);
2172 return NULLnullptr;
2173}
2174
2175
2176/* Find and return the first position in which OBJ could be inserted
2177 without changing the ordering of this vector. LESSTHAN is a
2178 function that returns true if the first argument is strictly less
2179 than the second. */
2180
2181template<typename T>
2182inline unsigned
2183vec<T, va_heap, vl_ptr>::lower_bound (T obj,
2184 bool (*lessthan)(const T &, const T &))
2185 const
2186{
2187 return m_vec ? m_vec->lower_bound (obj, lessthan) : 0;
2188}
2189
2190/* Return true if SEARCH is an element of V. Note that this is O(N) in the
2191 size of the vector and so should be used with care. */
2192
2193template<typename T>
2194inline bool
2195vec<T, va_heap, vl_ptr>::contains (const T &search) const
2196{
2197 return m_vec ? m_vec->contains (search) : false;
2198}
2199
2200/* Reverse content of the vector. */
2201
2202template<typename T>
2203inline void
2204vec<T, va_heap, vl_ptr>::reverse (void)
2205{
2206 unsigned l = length ();
2207 T *ptr = address ();
2208
2209 for (unsigned i = 0; i < l / 2; i++)
2210 std::swap (ptr[i], ptr[l - i - 1]);
2211}
2212
2213template<typename T>
2214inline bool
2215vec<T, va_heap, vl_ptr>::using_auto_storage () const
2216{
2217 return m_vec ? m_vec->m_vecpfx.m_using_auto_storage : false;
2218}
2219
2220/* Release VEC and call release of all element vectors. */
2221
2222template<typename T>
2223inline void
2224release_vec_vec (vec<vec<T> > &vec)
2225{
2226 for (unsigned i = 0; i < vec.length (); i++)
2227 vec[i].release ();
2228
2229 vec.release ();
2230}
2231
2232// Provide a subset of the std::span functionality. (We can't use std::span
2233// itself because it's a C++20 feature.)
2234//
2235// In addition, provide an invalid value that is distinct from all valid
2236// sequences (including the empty sequence). This can be used to return
2237// failure without having to use std::optional.
2238//
2239// There is no operator bool because it would be ambiguous whether it is
2240// testing for a valid value or an empty sequence.
2241template<typename T>
2242class array_slice
2243{
2244 template<typename OtherT> friend class array_slice;
2245
2246public:
2247 using value_type = T;
2248 using iterator = T *;
2249 using const_iterator = const T *;
2250
2251 array_slice () : m_base (nullptr), m_size (0) {}
2252
2253 template<typename OtherT>
2254 array_slice (array_slice<OtherT> other)
2255 : m_base (other.m_base), m_size (other.m_size) {}
2256
2257 array_slice (iterator base, unsigned int size)
2258 : m_base (base), m_size (size) {}
2259
2260 template<size_t N>
2261 array_slice (T (&array)[N]) : m_base (array), m_size (N) {}
2262
2263 template<typename OtherT>
2264 array_slice (const vec<OtherT> &v)
2265 : m_base (v.address ()), m_size (v.length ()) {}
2266
2267 iterator begin () { return m_base; }
2268 iterator end () { return m_base + m_size; }
2269
2270 const_iterator begin () const { return m_base; }
2271 const_iterator end () const { return m_base + m_size; }
2272
2273 value_type &front ();
2274 value_type &back ();
2275 value_type &operator[] (unsigned int i);
2276
2277 const value_type &front () const;
2278 const value_type &back () const;
2279 const value_type &operator[] (unsigned int i) const;
2280
2281 size_t size () const { return m_size; }
2282 size_t size_bytes () const { return m_size * sizeof (T); }
2283 bool empty () const { return m_size == 0; }
2284
2285 // An invalid array_slice that represents a failed operation. This is
2286 // distinct from an empty slice, which is a valid result in some contexts.
2287 static array_slice invalid () { return { nullptr, ~0U }; }
2288
2289 // True if the array is valid, false if it is an array like INVALID.
2290 bool is_valid () const { return m_base || m_size == 0; }
2291
2292private:
2293 iterator m_base;
2294 unsigned int m_size;
2295};
2296
2297template<typename T>
2298inline typename array_slice<T>::value_type &
2299array_slice<T>::front ()
2300{
2301 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2301, __FUNCTION__), 0 : 0))
;
2302 return m_base[0];
2303}
2304
2305template<typename T>
2306inline const typename array_slice<T>::value_type &
2307array_slice<T>::front () const
2308{
2309 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2309, __FUNCTION__), 0 : 0))
;
2310 return m_base[0];
2311}
2312
2313template<typename T>
2314inline typename array_slice<T>::value_type &
2315array_slice<T>::back ()
2316{
2317 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2317, __FUNCTION__), 0 : 0))
;
2318 return m_base[m_size - 1];
2319}
2320
2321template<typename T>
2322inline const typename array_slice<T>::value_type &
2323array_slice<T>::back () const
2324{
2325 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2325, __FUNCTION__), 0 : 0))
;
2326 return m_base[m_size - 1];
2327}
2328
2329template<typename T>
2330inline typename array_slice<T>::value_type &
2331array_slice<T>::operator[] (unsigned int i)
2332{
2333 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"
, 2333, __FUNCTION__), 0 : 0))
;
2334 return m_base[i];
2335}
2336
2337template<typename T>
2338inline const typename array_slice<T>::value_type &
2339array_slice<T>::operator[] (unsigned int i) const
2340{
2341 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"
, 2341, __FUNCTION__), 0 : 0))
;
2342 return m_base[i];
2343}
2344
2345template<typename T>
2346array_slice<T>
2347make_array_slice (T *base, unsigned int size)
2348{
2349 return array_slice<T> (base, size);
2350}
2351
2352#if (GCC_VERSION(4 * 1000 + 2) >= 3000)
2353# pragma GCC poison m_vec m_vecpfx m_vecdata
2354#endif
2355
2356#endif // GCC_VEC_H