Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

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

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

1/* Dwarf2 Call Frame Information helper routines.
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"
25#include "rtl.h"
26#include "tree.h"
27#include "tree-pass.h"
28#include "memmodel.h"
29#include "tm_p.h"
30#include "emit-rtl.h"
31#include "stor-layout.h"
32#include "cfgbuild.h"
33#include "dwarf2out.h"
34#include "dwarf2asm.h"
35#include "common/common-target.h"
36
37#include "except.h" /* expand_builtin_dwarf_sp_column */
38#include "profile-count.h" /* For expr.h */
39#include "expr.h" /* init_return_column_size */
40#include "output.h" /* asm_out_file */
41#include "debug.h" /* dwarf2out_do_frame, dwarf2out_do_cfi_asm */
42
43
44/* ??? Poison these here until it can be done generically. They've been
45 totally replaced in this file; make sure it stays that way. */
46#undef DWARF2_UNWIND_INFO
47#undef DWARF2_FRAME_INFO
48#if (GCC_VERSION(4 * 1000 + 2) >= 3000)
49 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
50#endif
51
52#ifndef INCOMING_RETURN_ADDR_RTXgen_rtx_MEM ((global_options.x_ix86_pmode == PMODE_DI ? (scalar_int_mode
((scalar_int_mode::from_int) E_DImode)) : (scalar_int_mode (
(scalar_int_mode::from_int) E_SImode))), ((this_target_rtl->
x_global_rtl)[GR_STACK_POINTER]))
53#define INCOMING_RETURN_ADDR_RTXgen_rtx_MEM ((global_options.x_ix86_pmode == PMODE_DI ? (scalar_int_mode
((scalar_int_mode::from_int) E_DImode)) : (scalar_int_mode (
(scalar_int_mode::from_int) E_SImode))), ((this_target_rtl->
x_global_rtl)[GR_STACK_POINTER]))
(gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 53, __FUNCTION__))
, NULL_RTX(rtx) 0)
54#endif
55
56#ifndef DEFAULT_INCOMING_FRAME_SP_OFFSET(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 8 : 4)
57#define DEFAULT_INCOMING_FRAME_SP_OFFSET(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 8 : 4)
INCOMING_FRAME_SP_OFFSET((cfun + 0)->machine->func_type == TYPE_EXCEPTION ? 2 *
(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 8 : 4) : (((global_options.x_ix86_isa_flags & (1UL <<
1)) != 0) ? 8 : 4))
58#endif
59
60/* A collected description of an entire row of the abstract CFI table. */
61struct GTY(()) dw_cfi_row
62{
63 /* The expression that computes the CFA, expressed in two different ways.
64 The CFA member for the simple cases, and the full CFI expression for
65 the complex cases. The later will be a DW_CFA_cfa_expression. */
66 dw_cfa_location cfa;
67 dw_cfi_ref cfa_cfi;
68
69 /* The expressions for any register column that is saved. */
70 cfi_vec reg_save;
71
72 /* True if the register window is saved. */
73 bool window_save;
74
75 /* True if the return address is in a mangled state. */
76 bool ra_mangled;
77};
78
79/* The caller's ORIG_REG is saved in SAVED_IN_REG. */
80struct GTY(()) reg_saved_in_data {
81 rtx orig_reg;
82 rtx saved_in_reg;
83};
84
85
86/* Since we no longer have a proper CFG, we're going to create a facsimile
87 of one on the fly while processing the frame-related insns.
88
89 We create dw_trace_info structures for each extended basic block beginning
90 and ending at a "save point". Save points are labels, barriers, certain
91 notes, and of course the beginning and end of the function.
92
93 As we encounter control transfer insns, we propagate the "current"
94 row state across the edges to the starts of traces. When checking is
95 enabled, we validate that we propagate the same data from all sources.
96
97 All traces are members of the TRACE_INFO array, in the order in which
98 they appear in the instruction stream.
99
100 All save points are present in the TRACE_INDEX hash, mapping the insn
101 starting a trace to the dw_trace_info describing the trace. */
102
103struct dw_trace_info
104{
105 /* The insn that begins the trace. */
106 rtx_insn *head;
107
108 /* The row state at the beginning and end of the trace. */
109 dw_cfi_row *beg_row, *end_row;
110
111 /* Tracking for DW_CFA_GNU_args_size. The "true" sizes are those we find
112 while scanning insns. However, the args_size value is irrelevant at
113 any point except can_throw_internal_p insns. Therefore the "delay"
114 sizes the values that must actually be emitted for this trace. */
115 poly_int64_pod beg_true_args_size, end_true_args_size;
116 poly_int64_pod beg_delay_args_size, end_delay_args_size;
117
118 /* The first EH insn in the trace, where beg_delay_args_size must be set. */
119 rtx_insn *eh_head;
120
121 /* The following variables contain data used in interpreting frame related
122 expressions. These are not part of the "real" row state as defined by
123 Dwarf, but it seems like they need to be propagated into a trace in case
124 frame related expressions have been sunk. */
125 /* ??? This seems fragile. These variables are fragments of a larger
126 expression. If we do not keep the entire expression together, we risk
127 not being able to put it together properly. Consider forcing targets
128 to generate self-contained expressions and dropping all of the magic
129 interpretation code in this file. Or at least refusing to shrink wrap
130 any frame related insn that doesn't contain a complete expression. */
131
132 /* The register used for saving registers to the stack, and its offset
133 from the CFA. */
134 dw_cfa_location cfa_store;
135
136 /* A temporary register holding an integral value used in adjusting SP
137 or setting up the store_reg. The "offset" field holds the integer
138 value, not an offset. */
139 dw_cfa_location cfa_temp;
140
141 /* A set of registers saved in other registers. This is the inverse of
142 the row->reg_save info, if the entry is a DW_CFA_register. This is
143 implemented as a flat array because it normally contains zero or 1
144 entry, depending on the target. IA-64 is the big spender here, using
145 a maximum of 5 entries. */
146 vec<reg_saved_in_data> regs_saved_in_regs;
147
148 /* An identifier for this trace. Used only for debugging dumps. */
149 unsigned id;
150
151 /* True if this trace immediately follows NOTE_INSN_SWITCH_TEXT_SECTIONS. */
152 bool switch_sections;
153
154 /* True if we've seen different values incoming to beg_true_args_size. */
155 bool args_size_undefined;
156
157 /* True if we've seen an insn with a REG_ARGS_SIZE note before EH_HEAD. */
158 bool args_size_defined_for_eh;
159};
160
161
162/* Hashtable helpers. */
163
164struct trace_info_hasher : nofree_ptr_hash <dw_trace_info>
165{
166 static inline hashval_t hash (const dw_trace_info *);
167 static inline bool equal (const dw_trace_info *, const dw_trace_info *);
168};
169
170inline hashval_t
171trace_info_hasher::hash (const dw_trace_info *ti)
172{
173 return INSN_UID (ti->head);
174}
175
176inline bool
177trace_info_hasher::equal (const dw_trace_info *a, const dw_trace_info *b)
178{
179 return a->head == b->head;
180}
181
182
183/* The variables making up the pseudo-cfg, as described above. */
184static vec<dw_trace_info> trace_info;
185static vec<dw_trace_info *> trace_work_list;
186static hash_table<trace_info_hasher> *trace_index;
187
188/* A vector of call frame insns for the CIE. */
189cfi_vec cie_cfi_vec;
190
191/* The state of the first row of the FDE table, which includes the
192 state provided by the CIE. */
193static GTY(()) dw_cfi_row *cie_cfi_row;
194
195static GTY(()) reg_saved_in_data *cie_return_save;
196
197static GTY(()) unsigned long dwarf2out_cfi_label_num;
198
199/* The insn after which a new CFI note should be emitted. */
200static rtx_insn *add_cfi_insn;
201
202/* When non-null, add_cfi will add the CFI to this vector. */
203static cfi_vec *add_cfi_vec;
204
205/* The current instruction trace. */
206static dw_trace_info *cur_trace;
207
208/* The current, i.e. most recently generated, row of the CFI table. */
209static dw_cfi_row *cur_row;
210
211/* A copy of the current CFA, for use during the processing of a
212 single insn. */
213static dw_cfa_location *cur_cfa;
214
215/* We delay emitting a register save until either (a) we reach the end
216 of the prologue or (b) the register is clobbered. This clusters
217 register saves so that there are fewer pc advances. */
218
219struct queued_reg_save {
220 rtx reg;
221 rtx saved_reg;
222 poly_int64_pod cfa_offset;
223};
224
225
226static vec<queued_reg_save> queued_reg_saves;
227
228/* True if any CFI directives were emitted at the current insn. */
229static bool any_cfis_emitted;
230
231/* Short-hand for commonly used register numbers. */
232static unsigned dw_stack_pointer_regnum;
233static unsigned dw_frame_pointer_regnum;
234
235/* Hook used by __throw. */
236
237rtx
238expand_builtin_dwarf_sp_column (void)
239{
240 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? dbx64_register_map[7] : svr4_dbx_register_map[7])
;
241 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1))gen_rtx_CONST_INT (((void) 0, E_VOIDmode), ((dwarf_regnum)));
242}
243
244/* MEM is a memory reference for the register size table, each element of
245 which has mode MODE. Initialize column C as a return address column. */
246
247static void
248init_return_column_size (scalar_int_mode mode, rtx mem, unsigned int c)
249{
250 HOST_WIDE_INTlong offset = c * GET_MODE_SIZE (mode);
251 HOST_WIDE_INTlong size = GET_MODE_SIZE (Pmode(global_options.x_ix86_pmode == PMODE_DI ? (scalar_int_mode (
(scalar_int_mode::from_int) E_DImode)) : (scalar_int_mode ((scalar_int_mode
::from_int) E_SImode)))
);
252 emit_move_insn (adjust_address (mem, mode, offset)adjust_address_1 (mem, mode, offset, 1, 1, 0, 0),
253 gen_int_mode (size, mode));
254}
255
256/* Datastructure used by expand_builtin_init_dwarf_reg_sizes and
257 init_one_dwarf_reg_size to communicate on what has been done by the
258 latter. */
259
260struct init_one_dwarf_reg_state
261{
262 /* Whether the dwarf return column was initialized. */
263 bool wrote_return_column;
264
265 /* For each hard register REGNO, whether init_one_dwarf_reg_size
266 was given REGNO to process already. */
267 bool processed_regno [FIRST_PSEUDO_REGISTER76];
268
269};
270
271/* Helper for expand_builtin_init_dwarf_reg_sizes. Generate code to
272 initialize the dwarf register size table entry corresponding to register
273 REGNO in REGMODE. TABLE is the table base address, SLOTMODE is the mode to
274 use for the size entry to initialize, and INIT_STATE is the communication
275 datastructure conveying what we're doing to our caller. */
276
277static
278void init_one_dwarf_reg_size (int regno, machine_mode regmode,
279 rtx table, machine_mode slotmode,
280 init_one_dwarf_reg_state *init_state)
281{
282 const unsigned int dnum = DWARF_FRAME_REGNUM (regno)(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? dbx64_register_map[regno] : svr4_dbx_register_map[regno
])
;
283 const unsigned int rnum = DWARF2_FRAME_REG_OUT (dnum, 1)(dnum);
284 const unsigned int dcol = DWARF_REG_TO_UNWIND_COLUMN (rnum)(rnum);
285
286 poly_int64 slotoffset = dcol * GET_MODE_SIZE (slotmode);
287 poly_int64 regsize = GET_MODE_SIZE (regmode);
288
289 init_state->processed_regno[regno] = true;
290
291 if (rnum >= DWARF_FRAME_REGISTERS17)
292 return;
293
294 if (dnum == DWARF_FRAME_RETURN_COLUMN(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 16 : 8)
)
295 {
296 if (regmode == VOIDmode((void) 0, E_VOIDmode))
297 return;
298 init_state->wrote_return_column = true;
299 }
300
301 /* ??? When is this true? Should it be a test based on DCOL instead? */
302 if (maybe_lt (slotoffset, 0))
303 return;
304
305 emit_move_insn (adjust_address (table, slotmode, slotoffset)adjust_address_1 (table, slotmode, slotoffset, 1, 1, 0, 0),
306 gen_int_mode (regsize, slotmode));
307}
308
309/* Generate code to initialize the dwarf register size table located
310 at the provided ADDRESS. */
311
312void
313expand_builtin_init_dwarf_reg_sizes (tree address)
314{
315 unsigned int i;
316 scalar_int_mode mode = SCALAR_INT_TYPE_MODE (char_type_node)(as_a <scalar_int_mode> ((tree_class_check ((integer_types
[itk_char]), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 316, __FUNCTION__))->type_common.mode))
;
317 rtx addr = expand_normal (address);
318 rtx mem = gen_rtx_MEM (BLKmode((void) 0, E_BLKmode), addr);
319
320 init_one_dwarf_reg_state init_state;
321
322 memset ((char *)&init_state, 0, sizeof (init_state));
323
324 for (i = 0; i < FIRST_PSEUDO_REGISTER76; i++)
325 {
326 machine_mode save_mode;
327 rtx span;
328
329 /* No point in processing a register multiple times. This could happen
330 with register spans, e.g. when a reg is first processed as a piece of
331 a span, then as a register on its own later on. */
332
333 if (init_state.processed_regno[i])
334 continue;
335
336 save_mode = targetm.dwarf_frame_reg_mode (i);
337 span = targetm.dwarf_register_span (gen_rtx_REG (save_mode, i));
338
339 if (!span)
340 init_one_dwarf_reg_size (i, save_mode, mem, mode, &init_state);
341 else
342 {
343 for (int si = 0; si < XVECLEN (span, 0)(((((span)->u.fld[0]).rt_rtvec))->num_elem); si++)
344 {
345 rtx reg = XVECEXP (span, 0, si)(((((span)->u.fld[0]).rt_rtvec))->elem[si]);
346
347 init_one_dwarf_reg_size
348 (REGNO (reg)(rhs_regno(reg)), GET_MODE (reg)((machine_mode) (reg)->mode), mem, mode, &init_state);
349 }
350 }
351 }
352
353 if (!init_state.wrote_return_column)
354 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 16 : 8)
);
355
356#ifdef DWARF_ALT_FRAME_RETURN_COLUMN
357 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
358#endif
359
360 targetm.init_dwarf_reg_sizes_extra (address);
361}
362
363
364static dw_trace_info *
365get_trace_info (rtx_insn *insn)
366{
367 dw_trace_info dummy;
368 dummy.head = insn;
369 return trace_index->find_with_hash (&dummy, INSN_UID (insn));
370}
371
372static bool
373save_point_p (rtx_insn *insn)
374{
375 /* Labels, except those that are really jump tables. */
376 if (LABEL_P (insn)(((enum rtx_code) (insn)->code) == CODE_LABEL))
377 return inside_basic_block_p (insn);
378
379 /* We split traces at the prologue/epilogue notes because those
380 are points at which the unwind info is usually stable. This
381 makes it easier to find spots with identical unwind info so
382 that we can use remember/restore_state opcodes. */
383 if (NOTE_P (insn)(((enum rtx_code) (insn)->code) == NOTE))
384 switch (NOTE_KIND (insn)(((insn)->u.fld[4]).rt_int))
385 {
386 case NOTE_INSN_PROLOGUE_END:
387 case NOTE_INSN_EPILOGUE_BEG:
388 return true;
389 }
390
391 return false;
392}
393
394/* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
395
396static inline HOST_WIDE_INTlong
397div_data_align (HOST_WIDE_INTlong off)
398{
399 HOST_WIDE_INTlong r = off / DWARF_CIE_DATA_ALIGNMENT(-((int) (((global_options.x_ix86_isa_flags & (1UL <<
1)) != 0) ? 8 : 4)))
;
400 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off)((void)(!(r * (-((int) (((global_options.x_ix86_isa_flags &
(1UL << 1)) != 0) ? 8 : 4))) == off) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 400, __FUNCTION__), 0 : 0))
;
401 return r;
402}
403
404/* Return true if we need a signed version of a given opcode
405 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
406
407static inline bool
408need_data_align_sf_opcode (HOST_WIDE_INTlong off)
409{
410 return DWARF_CIE_DATA_ALIGNMENT(-((int) (((global_options.x_ix86_isa_flags & (1UL <<
1)) != 0) ? 8 : 4)))
< 0 ? off > 0 : off < 0;
411}
412
413/* Return a pointer to a newly allocated Call Frame Instruction. */
414
415static inline dw_cfi_ref
416new_cfi (void)
417{
418 dw_cfi_ref cfi = ggc_alloc<dw_cfi_node> ();
419
420 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
421 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
422
423 return cfi;
424}
425
426/* Return a newly allocated CFI row, with no defined data. */
427
428static dw_cfi_row *
429new_cfi_row (void)
430{
431 dw_cfi_row *row = ggc_cleared_alloc<dw_cfi_row> ();
432
433 row->cfa.reg = INVALID_REGNUM(~(unsigned int) 0);
434
435 return row;
436}
437
438/* Return a copy of an existing CFI row. */
439
440static dw_cfi_row *
441copy_cfi_row (dw_cfi_row *src)
442{
443 dw_cfi_row *dst = ggc_alloc<dw_cfi_row> ();
444
445 *dst = *src;
446 dst->reg_save = vec_safe_copy (src->reg_save);
447
448 return dst;
449}
450
451/* Return a copy of an existing CFA location. */
452
453static dw_cfa_location *
454copy_cfa (dw_cfa_location *src)
455{
456 dw_cfa_location *dst = ggc_alloc<dw_cfa_location> ();
457 *dst = *src;
458 return dst;
459}
460
461/* Generate a new label for the CFI info to refer to. */
462
463static char *
464dwarf2out_cfi_label (void)
465{
466 int num = dwarf2out_cfi_label_num++;
467 char label[20];
468
469 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num)do { char *__p; (label)[0] = '*'; (label)[1] = '.'; __p = stpcpy
(&(label)[2], "LCFI"); sprint_ul (__p, (unsigned long) (
num)); } while (0)
;
470
471 return xstrdup (label);
472}
473
474/* Add CFI either to the current insn stream or to a vector, or both. */
475
476static void
477add_cfi (dw_cfi_ref cfi)
478{
479 any_cfis_emitted = true;
480
481 if (add_cfi_insn != NULLnullptr)
482 {
483 add_cfi_insn = emit_note_after (NOTE_INSN_CFI, add_cfi_insn);
484 NOTE_CFI (add_cfi_insn)(((add_cfi_insn)->u.fld[3]).rt_cfi) = cfi;
485 }
486
487 if (add_cfi_vec != NULLnullptr)
488 vec_safe_push (*add_cfi_vec, cfi);
489}
490
491static void
492add_cfi_args_size (poly_int64 size)
493{
494 /* We don't yet have a representation for polynomial sizes. */
495 HOST_WIDE_INTlong const_size = size.to_constant ();
496
497 dw_cfi_ref cfi = new_cfi ();
498
499 /* While we can occasionally have args_size < 0 internally, this state
500 should not persist at a point we actually need an opcode. */
501 gcc_assert (const_size >= 0)((void)(!(const_size >= 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 501, __FUNCTION__), 0 : 0))
;
502
503 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
504 cfi->dw_cfi_oprnd1.dw_cfi_offset = const_size;
505
506 add_cfi (cfi);
507}
508
509static void
510add_cfi_restore (unsigned reg)
511{
512 dw_cfi_ref cfi = new_cfi ();
513
514 cfi->dw_cfi_opc = (reg & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
515 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
516
517 add_cfi (cfi);
518}
519
520/* Perform ROW->REG_SAVE[COLUMN] = CFI. CFI may be null, indicating
521 that the register column is no longer saved. */
522
523static void
524update_row_reg_save (dw_cfi_row *row, unsigned column, dw_cfi_ref cfi)
525{
526 if (vec_safe_length (row->reg_save) <= column)
527 vec_safe_grow_cleared (row->reg_save, column + 1, true);
528 (*row->reg_save)[column] = cfi;
529}
530
531/* This function fills in aa dw_cfa_location structure from a dwarf location
532 descriptor sequence. */
533
534static void
535get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_node *loc)
536{
537 struct dw_loc_descr_node *ptr;
538 cfa->offset = 0;
539 cfa->base_offset = 0;
540 cfa->indirect = 0;
541 cfa->reg = -1;
542
543 for (ptr = loc; ptr != NULLnullptr; ptr = ptr->dw_loc_next)
544 {
545 enum dwarf_location_atom op = ptr->dw_loc_opc;
546
547 switch (op)
548 {
549 case DW_OP_reg0:
550 case DW_OP_reg1:
551 case DW_OP_reg2:
552 case DW_OP_reg3:
553 case DW_OP_reg4:
554 case DW_OP_reg5:
555 case DW_OP_reg6:
556 case DW_OP_reg7:
557 case DW_OP_reg8:
558 case DW_OP_reg9:
559 case DW_OP_reg10:
560 case DW_OP_reg11:
561 case DW_OP_reg12:
562 case DW_OP_reg13:
563 case DW_OP_reg14:
564 case DW_OP_reg15:
565 case DW_OP_reg16:
566 case DW_OP_reg17:
567 case DW_OP_reg18:
568 case DW_OP_reg19:
569 case DW_OP_reg20:
570 case DW_OP_reg21:
571 case DW_OP_reg22:
572 case DW_OP_reg23:
573 case DW_OP_reg24:
574 case DW_OP_reg25:
575 case DW_OP_reg26:
576 case DW_OP_reg27:
577 case DW_OP_reg28:
578 case DW_OP_reg29:
579 case DW_OP_reg30:
580 case DW_OP_reg31:
581 cfa->reg = op - DW_OP_reg0;
582 break;
583 case DW_OP_regx:
584 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
585 break;
586 case DW_OP_breg0:
587 case DW_OP_breg1:
588 case DW_OP_breg2:
589 case DW_OP_breg3:
590 case DW_OP_breg4:
591 case DW_OP_breg5:
592 case DW_OP_breg6:
593 case DW_OP_breg7:
594 case DW_OP_breg8:
595 case DW_OP_breg9:
596 case DW_OP_breg10:
597 case DW_OP_breg11:
598 case DW_OP_breg12:
599 case DW_OP_breg13:
600 case DW_OP_breg14:
601 case DW_OP_breg15:
602 case DW_OP_breg16:
603 case DW_OP_breg17:
604 case DW_OP_breg18:
605 case DW_OP_breg19:
606 case DW_OP_breg20:
607 case DW_OP_breg21:
608 case DW_OP_breg22:
609 case DW_OP_breg23:
610 case DW_OP_breg24:
611 case DW_OP_breg25:
612 case DW_OP_breg26:
613 case DW_OP_breg27:
614 case DW_OP_breg28:
615 case DW_OP_breg29:
616 case DW_OP_breg30:
617 case DW_OP_breg31:
618 cfa->reg = op - DW_OP_breg0;
619 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
620 break;
621 case DW_OP_bregx:
622 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
623 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
624 break;
625 case DW_OP_deref:
626 cfa->indirect = 1;
627 break;
628 case DW_OP_plus_uconst:
629 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
630 break;
631 default:
632 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 632, __FUNCTION__))
;
633 }
634 }
635}
636
637/* Find the previous value for the CFA, iteratively. CFI is the opcode
638 to interpret, *LOC will be updated as necessary, *REMEMBER is used for
639 one level of remember/restore state processing. */
640
641void
642lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
643{
644 switch (cfi->dw_cfi_opc)
645 {
646 case DW_CFA_def_cfa_offset:
647 case DW_CFA_def_cfa_offset_sf:
648 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
649 break;
650 case DW_CFA_def_cfa_register:
651 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
652 break;
653 case DW_CFA_def_cfa:
654 case DW_CFA_def_cfa_sf:
655 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
656 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
657 break;
658 case DW_CFA_def_cfa_expression:
659 if (cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc)
660 *loc = *cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc;
661 else
662 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
663 break;
664
665 case DW_CFA_remember_state:
666 gcc_assert (!remember->in_use)((void)(!(!remember->in_use) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 666, __FUNCTION__), 0 : 0))
;
667 *remember = *loc;
668 remember->in_use = 1;
669 break;
670 case DW_CFA_restore_state:
671 gcc_assert (remember->in_use)((void)(!(remember->in_use) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 671, __FUNCTION__), 0 : 0))
;
672 *loc = *remember;
673 remember->in_use = 0;
674 break;
675
676 default:
677 break;
678 }
679}
680
681/* Determine if two dw_cfa_location structures define the same data. */
682
683bool
684cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
685{
686 return (loc1->reg == loc2->reg
687 && known_eq (loc1->offset, loc2->offset)(!maybe_ne (loc1->offset, loc2->offset))
688 && loc1->indirect == loc2->indirect
689 && (loc1->indirect == 0
690 || known_eq (loc1->base_offset, loc2->base_offset)(!maybe_ne (loc1->base_offset, loc2->base_offset))));
691}
692
693/* Determine if two CFI operands are identical. */
694
695static bool
696cfi_oprnd_equal_p (enum dw_cfi_oprnd_type t, dw_cfi_oprnd *a, dw_cfi_oprnd *b)
697{
698 switch (t)
699 {
700 case dw_cfi_oprnd_unused:
701 return true;
702 case dw_cfi_oprnd_reg_num:
703 return a->dw_cfi_reg_num == b->dw_cfi_reg_num;
704 case dw_cfi_oprnd_offset:
705 return a->dw_cfi_offset == b->dw_cfi_offset;
706 case dw_cfi_oprnd_addr:
707 return (a->dw_cfi_addr == b->dw_cfi_addr
708 || strcmp (a->dw_cfi_addr, b->dw_cfi_addr) == 0);
709 case dw_cfi_oprnd_loc:
710 return loc_descr_equal_p (a->dw_cfi_loc, b->dw_cfi_loc);
711 case dw_cfi_oprnd_cfa_loc:
712 return cfa_equal_p (a->dw_cfi_cfa_loc, b->dw_cfi_cfa_loc);
713 }
714 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 714, __FUNCTION__))
;
715}
716
717/* Determine if two CFI entries are identical. */
718
719static bool
720cfi_equal_p (dw_cfi_ref a, dw_cfi_ref b)
721{
722 enum dwarf_call_frame_info opc;
723
724 /* Make things easier for our callers, including missing operands. */
725 if (a == b)
726 return true;
727 if (a == NULLnullptr || b == NULLnullptr)
728 return false;
729
730 /* Obviously, the opcodes must match. */
731 opc = a->dw_cfi_opc;
732 if (opc != b->dw_cfi_opc)
733 return false;
734
735 /* Compare the two operands, re-using the type of the operands as
736 already exposed elsewhere. */
737 return (cfi_oprnd_equal_p (dw_cfi_oprnd1_desc (opc),
738 &a->dw_cfi_oprnd1, &b->dw_cfi_oprnd1)
739 && cfi_oprnd_equal_p (dw_cfi_oprnd2_desc (opc),
740 &a->dw_cfi_oprnd2, &b->dw_cfi_oprnd2));
741}
742
743/* Determine if two CFI_ROW structures are identical. */
744
745static bool
746cfi_row_equal_p (dw_cfi_row *a, dw_cfi_row *b)
747{
748 size_t i, n_a, n_b, n_max;
749
750 if (a->cfa_cfi)
751 {
752 if (!cfi_equal_p (a->cfa_cfi, b->cfa_cfi))
753 return false;
754 }
755 else if (!cfa_equal_p (&a->cfa, &b->cfa))
756 return false;
757
758 n_a = vec_safe_length (a->reg_save);
759 n_b = vec_safe_length (b->reg_save);
760 n_max = MAX (n_a, n_b)((n_a) > (n_b) ? (n_a) : (n_b));
761
762 for (i = 0; i < n_max; ++i)
763 {
764 dw_cfi_ref r_a = NULLnullptr, r_b = NULLnullptr;
765
766 if (i < n_a)
767 r_a = (*a->reg_save)[i];
768 if (i < n_b)
769 r_b = (*b->reg_save)[i];
770
771 if (!cfi_equal_p (r_a, r_b))
772 return false;
773 }
774
775 if (a->window_save != b->window_save)
776 return false;
777
778 if (a->ra_mangled != b->ra_mangled)
779 return false;
780
781 return true;
782}
783
784/* The CFA is now calculated from NEW_CFA. Consider OLD_CFA in determining
785 what opcode to emit. Returns the CFI opcode to effect the change, or
786 NULL if NEW_CFA == OLD_CFA. */
787
788static dw_cfi_ref
789def_cfa_0 (dw_cfa_location *old_cfa, dw_cfa_location *new_cfa)
790{
791 dw_cfi_ref cfi;
792
793 /* If nothing changed, no need to issue any call frame instructions. */
794 if (cfa_equal_p (old_cfa, new_cfa))
795 return NULLnullptr;
796
797 cfi = new_cfi ();
798
799 HOST_WIDE_INTlong const_offset;
800 if (new_cfa->reg == old_cfa->reg
801 && !new_cfa->indirect
802 && !old_cfa->indirect
803 && new_cfa->offset.is_constant (&const_offset))
804 {
805 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
806 the CFA register did not change but the offset did. The data
807 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
808 in the assembler via the .cfi_def_cfa_offset directive. */
809 if (const_offset < 0)
810 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
811 else
812 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
813 cfi->dw_cfi_oprnd1.dw_cfi_offset = const_offset;
814 }
815 else if (new_cfa->offset.is_constant ()
816 && known_eq (new_cfa->offset, old_cfa->offset)(!maybe_ne (new_cfa->offset, old_cfa->offset))
817 && old_cfa->reg != INVALID_REGNUM(~(unsigned int) 0)
818 && !new_cfa->indirect
819 && !old_cfa->indirect)
820 {
821 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
822 indicating the CFA register has changed to <register> but the
823 offset has not changed. This requires the old CFA to have
824 been set as a register plus offset rather than a general
825 DW_CFA_def_cfa_expression. */
826 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
827 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = new_cfa->reg;
828 }
829 else if (new_cfa->indirect == 0
830 && new_cfa->offset.is_constant (&const_offset))
831 {
832 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
833 indicating the CFA register has changed to <register> with
834 the specified offset. The data factoring for DW_CFA_def_cfa_sf
835 happens in output_cfi, or in the assembler via the .cfi_def_cfa
836 directive. */
837 if (const_offset < 0)
838 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
839 else
840 cfi->dw_cfi_opc = DW_CFA_def_cfa;
841 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = new_cfa->reg;
842 cfi->dw_cfi_oprnd2.dw_cfi_offset = const_offset;
843 }
844 else
845 {
846 /* Construct a DW_CFA_def_cfa_expression instruction to
847 calculate the CFA using a full location expression since no
848 register-offset pair is available. */
849 struct dw_loc_descr_node *loc_list;
850
851 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
852 loc_list = build_cfa_loc (new_cfa, 0);
853 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
854 if (!new_cfa->offset.is_constant ()
855 || !new_cfa->base_offset.is_constant ())
856 /* It's hard to reconstruct the CFA location for a polynomial
857 expression, so just cache it instead. */
858 cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc = copy_cfa (new_cfa);
859 else
860 cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc = NULLnullptr;
861 }
862
863 return cfi;
864}
865
866/* Similarly, but take OLD_CFA from CUR_ROW, and update it after the fact. */
867
868static void
869def_cfa_1 (dw_cfa_location *new_cfa)
870{
871 dw_cfi_ref cfi;
872
873 if (cur_trace->cfa_store.reg == new_cfa->reg && new_cfa->indirect == 0)
874 cur_trace->cfa_store.offset = new_cfa->offset;
875
876 cfi = def_cfa_0 (&cur_row->cfa, new_cfa);
877 if (cfi)
878 {
879 cur_row->cfa = *new_cfa;
880 cur_row->cfa_cfi = (cfi->dw_cfi_opc == DW_CFA_def_cfa_expression
881 ? cfi : NULLnullptr);
882
883 add_cfi (cfi);
884 }
885}
886
887/* Add the CFI for saving a register. REG is the CFA column number.
888 If SREG is -1, the register is saved at OFFSET from the CFA;
889 otherwise it is saved in SREG. */
890
891static void
892reg_save (unsigned int reg, unsigned int sreg, poly_int64 offset)
893{
894 dw_fde_ref fde = cfun(cfun + 0) ? cfun(cfun + 0)->fde : NULLnullptr;
895 dw_cfi_ref cfi = new_cfi ();
896
897 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
898
899 if (sreg == INVALID_REGNUM(~(unsigned int) 0))
900 {
901 HOST_WIDE_INTlong const_offset;
902 /* When stack is aligned, store REG using DW_CFA_expression with FP. */
903 if (fde && fde->stack_realign)
904 {
905 cfi->dw_cfi_opc = DW_CFA_expression;
906 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
907 cfi->dw_cfi_oprnd2.dw_cfi_loc
908 = build_cfa_aligned_loc (&cur_row->cfa, offset,
909 fde->stack_realignment);
910 }
911 else if (offset.is_constant (&const_offset))
912 {
913 if (need_data_align_sf_opcode (const_offset))
914 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
915 else if (reg & ~0x3f)
916 cfi->dw_cfi_opc = DW_CFA_offset_extended;
917 else
918 cfi->dw_cfi_opc = DW_CFA_offset;
919 cfi->dw_cfi_oprnd2.dw_cfi_offset = const_offset;
920 }
921 else
922 {
923 cfi->dw_cfi_opc = DW_CFA_expression;
924 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
925 cfi->dw_cfi_oprnd2.dw_cfi_loc
926 = build_cfa_loc (&cur_row->cfa, offset);
927 }
928 }
929 else if (sreg == reg)
930 {
931 /* While we could emit something like DW_CFA_same_value or
932 DW_CFA_restore, we never expect to see something like that
933 in a prologue. This is more likely to be a bug. A backend
934 can always bypass this by using REG_CFA_RESTORE directly. */
935 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 935, __FUNCTION__))
;
936 }
937 else
938 {
939 cfi->dw_cfi_opc = DW_CFA_register;
940 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
941 }
942
943 add_cfi (cfi);
944 update_row_reg_save (cur_row, reg, cfi);
945}
946
947/* A subroutine of scan_trace. Check INSN for a REG_ARGS_SIZE note
948 and adjust data structures to match. */
949
950static void
951notice_args_size (rtx_insn *insn)
952{
953 poly_int64 args_size, delta;
954 rtx note;
955
956 note = find_reg_note (insn, REG_ARGS_SIZE, NULLnullptr);
957 if (note == NULLnullptr)
958 return;
959
960 if (!cur_trace->eh_head)
961 cur_trace->args_size_defined_for_eh = true;
962
963 args_size = get_args_size (note);
964 delta = args_size - cur_trace->end_true_args_size;
965 if (known_eq (delta, 0)(!maybe_ne (delta, 0)))
966 return;
967
968 cur_trace->end_true_args_size = args_size;
969
970 /* If the CFA is computed off the stack pointer, then we must adjust
971 the computation of the CFA as well. */
972 if (cur_cfa->reg == dw_stack_pointer_regnum)
973 {
974 gcc_assert (!cur_cfa->indirect)((void)(!(!cur_cfa->indirect) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 974, __FUNCTION__), 0 : 0))
;
975
976 /* Convert a change in args_size (always a positive in the
977 direction of stack growth) to a change in stack pointer. */
978 if (!STACK_GROWS_DOWNWARD1)
979 delta = -delta;
980
981 cur_cfa->offset += delta;
982 }
983}
984
985/* A subroutine of scan_trace. INSN is can_throw_internal. Update the
986 data within the trace related to EH insns and args_size. */
987
988static void
989notice_eh_throw (rtx_insn *insn)
990{
991 poly_int64 args_size = cur_trace->end_true_args_size;
992 if (cur_trace->eh_head == NULLnullptr)
993 {
994 cur_trace->eh_head = insn;
995 cur_trace->beg_delay_args_size = args_size;
996 cur_trace->end_delay_args_size = args_size;
997 }
998 else if (maybe_ne (cur_trace->end_delay_args_size, args_size))
999 {
1000 cur_trace->end_delay_args_size = args_size;
1001
1002 /* ??? If the CFA is the stack pointer, search backward for the last
1003 CFI note and insert there. Given that the stack changed for the
1004 args_size change, there *must* be such a note in between here and
1005 the last eh insn. */
1006 add_cfi_args_size (args_size);
1007 }
1008}
1009
1010/* Short-hand inline for the very common D_F_R (REGNO (x)) operation. */
1011/* ??? This ought to go into dwarf2out.h, except that dwarf2out.h is
1012 used in places where rtl is prohibited. */
1013
1014static inline unsigned
1015dwf_regno (const_rtx reg)
1016{
1017 gcc_assert (REGNO (reg) < FIRST_PSEUDO_REGISTER)((void)(!((rhs_regno(reg)) < 76) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1017, __FUNCTION__), 0 : 0))
;
1018 return DWARF_FRAME_REGNUM (REGNO (reg))(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? dbx64_register_map[(rhs_regno(reg))] : svr4_dbx_register_map
[(rhs_regno(reg))])
;
1019}
1020
1021/* Compare X and Y for equivalence. The inputs may be REGs or PC_RTX. */
1022
1023static bool
1024compare_reg_or_pc (rtx x, rtx y)
1025{
1026 if (REG_P (x)(((enum rtx_code) (x)->code) == REG) && REG_P (y)(((enum rtx_code) (y)->code) == REG))
1027 return REGNO (x)(rhs_regno(x)) == REGNO (y)(rhs_regno(y));
1028 return x == y;
1029}
1030
1031/* Record SRC as being saved in DEST. DEST may be null to delete an
1032 existing entry. SRC may be a register or PC_RTX. */
1033
1034static void
1035record_reg_saved_in_reg (rtx dest, rtx src)
1036{
1037 reg_saved_in_data *elt;
1038 size_t i;
1039
1040 FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, i, elt)for (i = 0; (cur_trace->regs_saved_in_regs).iterate ((i), &
(elt)); ++(i))
1041 if (compare_reg_or_pc (elt->orig_reg, src))
1042 {
1043 if (dest == NULLnullptr)
1044 cur_trace->regs_saved_in_regs.unordered_remove (i);
1045 else
1046 elt->saved_in_reg = dest;
1047 return;
1048 }
1049
1050 if (dest == NULLnullptr)
1051 return;
1052
1053 reg_saved_in_data e = {src, dest};
1054 cur_trace->regs_saved_in_regs.safe_push (e);
1055}
1056
1057/* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1058 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1059
1060static void
1061queue_reg_save (rtx reg, rtx sreg, poly_int64 offset)
1062{
1063 queued_reg_save *q;
1064 queued_reg_save e = {reg, sreg, offset};
1065 size_t i;
1066
1067 /* Duplicates waste space, but it's also necessary to remove them
1068 for correctness, since the queue gets output in reverse order. */
1069 FOR_EACH_VEC_ELT (queued_reg_saves, i, q)for (i = 0; (queued_reg_saves).iterate ((i), &(q)); ++(i)
)
1070 if (compare_reg_or_pc (q->reg, reg))
1071 {
1072 *q = e;
1073 return;
1074 }
1075
1076 queued_reg_saves.safe_push (e);
1077}
1078
1079/* Output all the entries in QUEUED_REG_SAVES. */
1080
1081static void
1082dwarf2out_flush_queued_reg_saves (void)
1083{
1084 queued_reg_save *q;
1085 size_t i;
1086
1087 FOR_EACH_VEC_ELT (queued_reg_saves, i, q)for (i = 0; (queued_reg_saves).iterate ((i), &(q)); ++(i)
)
1088 {
1089 unsigned int reg, sreg;
1090
1091 record_reg_saved_in_reg (q->saved_reg, q->reg);
1092
1093 if (q->reg == pc_rtx)
1094 reg = DWARF_FRAME_RETURN_COLUMN(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 16 : 8)
;
1095 else
1096 reg = dwf_regno (q->reg);
1097 if (q->saved_reg)
1098 sreg = dwf_regno (q->saved_reg);
1099 else
1100 sreg = INVALID_REGNUM(~(unsigned int) 0);
1101 reg_save (reg, sreg, q->cfa_offset);
1102 }
1103
1104 queued_reg_saves.truncate (0);
1105}
1106
1107/* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1108 location for? Or, does it clobber a register which we've previously
1109 said that some other register is saved in, and for which we now
1110 have a new location for? */
1111
1112static bool
1113clobbers_queued_reg_save (const_rtx insn)
1114{
1115 queued_reg_save *q;
1116 size_t iq;
1117
1118 FOR_EACH_VEC_ELT (queued_reg_saves, iq, q)for (iq = 0; (queued_reg_saves).iterate ((iq), &(q)); ++(
iq))
1119 {
1120 size_t ir;
1121 reg_saved_in_data *rir;
1122
1123 if (modified_in_p (q->reg, insn))
1124 return true;
1125
1126 FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, ir, rir)for (ir = 0; (cur_trace->regs_saved_in_regs).iterate ((ir)
, &(rir)); ++(ir))
1127 if (compare_reg_or_pc (q->reg, rir->orig_reg)
1128 && modified_in_p (rir->saved_in_reg, insn))
1129 return true;
1130 }
1131
1132 return false;
1133}
1134
1135/* What register, if any, is currently saved in REG? */
1136
1137static rtx
1138reg_saved_in (rtx reg)
1139{
1140 unsigned int regn = REGNO (reg)(rhs_regno(reg));
1141 queued_reg_save *q;
1142 reg_saved_in_data *rir;
1143 size_t i;
1144
1145 FOR_EACH_VEC_ELT (queued_reg_saves, i, q)for (i = 0; (queued_reg_saves).iterate ((i), &(q)); ++(i)
)
1146 if (q->saved_reg && regn == REGNO (q->saved_reg)(rhs_regno(q->saved_reg)))
1147 return q->reg;
1148
1149 FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, i, rir)for (i = 0; (cur_trace->regs_saved_in_regs).iterate ((i), &
(rir)); ++(i))
1150 if (regn == REGNO (rir->saved_in_reg)(rhs_regno(rir->saved_in_reg)))
1151 return rir->orig_reg;
1152
1153 return NULL_RTX(rtx) 0;
1154}
1155
1156/* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1157
1158static void
1159dwarf2out_frame_debug_def_cfa (rtx pat)
1160{
1161 memset (cur_cfa, 0, sizeof (*cur_cfa));
1162
1163 pat = strip_offset (pat, &cur_cfa->offset);
1164 if (MEM_P (pat)(((enum rtx_code) (pat)->code) == MEM))
1165 {
1166 cur_cfa->indirect = 1;
1167 pat = strip_offset (XEXP (pat, 0)(((pat)->u.fld[0]).rt_rtx), &cur_cfa->base_offset);
1168 }
1169 /* ??? If this fails, we could be calling into the _loc functions to
1170 define a full expression. So far no port does that. */
1171 gcc_assert (REG_P (pat))((void)(!((((enum rtx_code) (pat)->code) == REG)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1171, __FUNCTION__), 0 : 0))
;
1172 cur_cfa->reg = dwf_regno (pat);
1173}
1174
1175/* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1176
1177static void
1178dwarf2out_frame_debug_adjust_cfa (rtx pat)
1179{
1180 rtx src, dest;
1181
1182 gcc_assert (GET_CODE (pat) == SET)((void)(!(((enum rtx_code) (pat)->code) == SET) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1182, __FUNCTION__), 0 : 0))
;
1183 dest = XEXP (pat, 0)(((pat)->u.fld[0]).rt_rtx);
1184 src = XEXP (pat, 1)(((pat)->u.fld[1]).rt_rtx);
1185
1186 switch (GET_CODE (src)((enum rtx_code) (src)->code))
1187 {
1188 case PLUS:
1189 gcc_assert (dwf_regno (XEXP (src, 0)) == cur_cfa->reg)((void)(!(dwf_regno ((((src)->u.fld[0]).rt_rtx)) == cur_cfa
->reg) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1189, __FUNCTION__), 0 : 0))
;
1190 cur_cfa->offset -= rtx_to_poly_int64 (XEXP (src, 1)(((src)->u.fld[1]).rt_rtx));
1191 break;
1192
1193 case REG:
1194 break;
1195
1196 default:
1197 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1197, __FUNCTION__))
;
1198 }
1199
1200 cur_cfa->reg = dwf_regno (dest);
1201 gcc_assert (cur_cfa->indirect == 0)((void)(!(cur_cfa->indirect == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1201, __FUNCTION__), 0 : 0))
;
1202}
1203
1204/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1205
1206static void
1207dwarf2out_frame_debug_cfa_offset (rtx set)
1208{
1209 poly_int64 offset;
1210 rtx src, addr, span;
1211 unsigned int sregno;
1212
1213 src = XEXP (set, 1)(((set)->u.fld[1]).rt_rtx);
1214 addr = XEXP (set, 0)(((set)->u.fld[0]).rt_rtx);
1215 gcc_assert (MEM_P (addr))((void)(!((((enum rtx_code) (addr)->code) == MEM)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1215, __FUNCTION__), 0 : 0))
;
1216 addr = XEXP (addr, 0)(((addr)->u.fld[0]).rt_rtx);
1217
1218 /* As documented, only consider extremely simple addresses. */
1219 switch (GET_CODE (addr)((enum rtx_code) (addr)->code))
1220 {
1221 case REG:
1222 gcc_assert (dwf_regno (addr) == cur_cfa->reg)((void)(!(dwf_regno (addr) == cur_cfa->reg) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1222, __FUNCTION__), 0 : 0))
;
1223 offset = -cur_cfa->offset;
1224 break;
1225 case PLUS:
1226 gcc_assert (dwf_regno (XEXP (addr, 0)) == cur_cfa->reg)((void)(!(dwf_regno ((((addr)->u.fld[0]).rt_rtx)) == cur_cfa
->reg) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1226, __FUNCTION__), 0 : 0))
;
1227 offset = rtx_to_poly_int64 (XEXP (addr, 1)(((addr)->u.fld[1]).rt_rtx)) - cur_cfa->offset;
1228 break;
1229 default:
1230 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1230, __FUNCTION__))
;
1231 }
1232
1233 if (src == pc_rtx)
1234 {
1235 span = NULLnullptr;
1236 sregno = DWARF_FRAME_RETURN_COLUMN(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 16 : 8)
;
1237 }
1238 else
1239 {
1240 span = targetm.dwarf_register_span (src);
1241 sregno = dwf_regno (src);
1242 }
1243
1244 /* ??? We'd like to use queue_reg_save, but we need to come up with
1245 a different flushing heuristic for epilogues. */
1246 if (!span)
1247 reg_save (sregno, INVALID_REGNUM(~(unsigned int) 0), offset);
1248 else
1249 {
1250 /* We have a PARALLEL describing where the contents of SRC live.
1251 Adjust the offset for each piece of the PARALLEL. */
1252 poly_int64 span_offset = offset;
1253
1254 gcc_assert (GET_CODE (span) == PARALLEL)((void)(!(((enum rtx_code) (span)->code) == PARALLEL) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1254, __FUNCTION__), 0 : 0))
;
1255
1256 const int par_len = XVECLEN (span, 0)(((((span)->u.fld[0]).rt_rtvec))->num_elem);
1257 for (int par_index = 0; par_index < par_len; par_index++)
1258 {
1259 rtx elem = XVECEXP (span, 0, par_index)(((((span)->u.fld[0]).rt_rtvec))->elem[par_index]);
1260 sregno = dwf_regno (src);
1261 reg_save (sregno, INVALID_REGNUM(~(unsigned int) 0), span_offset);
1262 span_offset += GET_MODE_SIZE (GET_MODE (elem)((machine_mode) (elem)->mode));
1263 }
1264 }
1265}
1266
1267/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1268
1269static void
1270dwarf2out_frame_debug_cfa_register (rtx set)
1271{
1272 rtx src, dest;
1273 unsigned sregno, dregno;
1274
1275 src = XEXP (set, 1)(((set)->u.fld[1]).rt_rtx);
1276 dest = XEXP (set, 0)(((set)->u.fld[0]).rt_rtx);
1277
1278 record_reg_saved_in_reg (dest, src);
1279 if (src == pc_rtx)
1280 sregno = DWARF_FRAME_RETURN_COLUMN(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 16 : 8)
;
1281 else
1282 sregno = dwf_regno (src);
1283
1284 dregno = dwf_regno (dest);
1285
1286 /* ??? We'd like to use queue_reg_save, but we need to come up with
1287 a different flushing heuristic for epilogues. */
1288 reg_save (sregno, dregno, 0);
1289}
1290
1291/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
1292
1293static void
1294dwarf2out_frame_debug_cfa_expression (rtx set)
1295{
1296 rtx src, dest, span;
1297 dw_cfi_ref cfi = new_cfi ();
1298 unsigned regno;
1299
1300 dest = SET_DEST (set)(((set)->u.fld[0]).rt_rtx);
1301 src = SET_SRC (set)(((set)->u.fld[1]).rt_rtx);
1302
1303 gcc_assert (REG_P (src))((void)(!((((enum rtx_code) (src)->code) == REG)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1303, __FUNCTION__), 0 : 0))
;
1304 gcc_assert (MEM_P (dest))((void)(!((((enum rtx_code) (dest)->code) == MEM)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1304, __FUNCTION__), 0 : 0))
;
1305
1306 span = targetm.dwarf_register_span (src);
1307 gcc_assert (!span)((void)(!(!span) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1307, __FUNCTION__), 0 : 0))
;
1308
1309 regno = dwf_regno (src);
1310
1311 cfi->dw_cfi_opc = DW_CFA_expression;
1312 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
1313 cfi->dw_cfi_oprnd2.dw_cfi_loc
1314 = mem_loc_descriptor (XEXP (dest, 0)(((dest)->u.fld[0]).rt_rtx), get_address_mode (dest),
1315 GET_MODE (dest)((machine_mode) (dest)->mode), VAR_INIT_STATUS_INITIALIZED);
1316
1317 /* ??? We'd like to use queue_reg_save, were the interface different,
1318 and, as above, we could manage flushing for epilogues. */
1319 add_cfi (cfi);
1320 update_row_reg_save (cur_row, regno, cfi);
1321}
1322
1323/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_VAL_EXPRESSION
1324 note. */
1325
1326static void
1327dwarf2out_frame_debug_cfa_val_expression (rtx set)
1328{
1329 rtx dest = SET_DEST (set)(((set)->u.fld[0]).rt_rtx);
1330 gcc_assert (REG_P (dest))((void)(!((((enum rtx_code) (dest)->code) == REG)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1330, __FUNCTION__), 0 : 0))
;
1331
1332 rtx span = targetm.dwarf_register_span (dest);
1333 gcc_assert (!span)((void)(!(!span) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1333, __FUNCTION__), 0 : 0))
;
1334
1335 rtx src = SET_SRC (set)(((set)->u.fld[1]).rt_rtx);
1336 dw_cfi_ref cfi = new_cfi ();
1337 cfi->dw_cfi_opc = DW_CFA_val_expression;
1338 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = dwf_regno (dest);
1339 cfi->dw_cfi_oprnd2.dw_cfi_loc
1340 = mem_loc_descriptor (src, GET_MODE (src)((machine_mode) (src)->mode),
1341 GET_MODE (dest)((machine_mode) (dest)->mode), VAR_INIT_STATUS_INITIALIZED);
1342 add_cfi (cfi);
1343 update_row_reg_save (cur_row, dwf_regno (dest), cfi);
1344}
1345
1346/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1347
1348static void
1349dwarf2out_frame_debug_cfa_restore (rtx reg)
1350{
1351 gcc_assert (REG_P (reg))((void)(!((((enum rtx_code) (reg)->code) == REG)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1351, __FUNCTION__), 0 : 0))
;
1352
1353 rtx span = targetm.dwarf_register_span (reg);
1354 if (!span)
1355 {
1356 unsigned int regno = dwf_regno (reg);
1357 add_cfi_restore (regno);
1358 update_row_reg_save (cur_row, regno, NULLnullptr);
1359 }
1360 else
1361 {
1362 /* We have a PARALLEL describing where the contents of REG live.
1363 Restore the register for each piece of the PARALLEL. */
1364 gcc_assert (GET_CODE (span) == PARALLEL)((void)(!(((enum rtx_code) (span)->code) == PARALLEL) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1364, __FUNCTION__), 0 : 0))
;
1365
1366 const int par_len = XVECLEN (span, 0)(((((span)->u.fld[0]).rt_rtvec))->num_elem);
1367 for (int par_index = 0; par_index < par_len; par_index++)
1368 {
1369 reg = XVECEXP (span, 0, par_index)(((((span)->u.fld[0]).rt_rtvec))->elem[par_index]);
1370 gcc_assert (REG_P (reg))((void)(!((((enum rtx_code) (reg)->code) == REG)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1370, __FUNCTION__), 0 : 0))
;
1371 unsigned int regno = dwf_regno (reg);
1372 add_cfi_restore (regno);
1373 update_row_reg_save (cur_row, regno, NULLnullptr);
1374 }
1375 }
1376}
1377
1378/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.
1379
1380 ??? Perhaps we should note in the CIE where windows are saved (instead
1381 of assuming 0(cfa)) and what registers are in the window. */
1382
1383static void
1384dwarf2out_frame_debug_cfa_window_save (void)
1385{
1386 dw_cfi_ref cfi = new_cfi ();
1387
1388 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1389 add_cfi (cfi);
1390 cur_row->window_save = true;
1391}
1392
1393/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_TOGGLE_RA_MANGLE.
1394 Note: DW_CFA_GNU_window_save dwarf opcode is reused for toggling RA mangle
1395 state, this is a target specific operation on AArch64 and can only be used
1396 on other targets if they don't use the window save operation otherwise. */
1397
1398static void
1399dwarf2out_frame_debug_cfa_toggle_ra_mangle (void)
1400{
1401 dw_cfi_ref cfi = new_cfi ();
1402
1403 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1404 add_cfi (cfi);
1405 cur_row->ra_mangled = !cur_row->ra_mangled;
1406}
1407
1408/* Record call frame debugging information for an expression EXPR,
1409 which either sets SP or FP (adjusting how we calculate the frame
1410 address) or saves a register to the stack or another register.
1411 LABEL indicates the address of EXPR.
1412
1413 This function encodes a state machine mapping rtxes to actions on
1414 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1415 users need not read the source code.
1416
1417 The High-Level Picture
1418
1419 Changes in the register we use to calculate the CFA: Currently we
1420 assume that if you copy the CFA register into another register, we
1421 should take the other one as the new CFA register; this seems to
1422 work pretty well. If it's wrong for some target, it's simple
1423 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1424
1425 Changes in the register we use for saving registers to the stack:
1426 This is usually SP, but not always. Again, we deduce that if you
1427 copy SP into another register (and SP is not the CFA register),
1428 then the new register is the one we will be using for register
1429 saves. This also seems to work.
1430
1431 Register saves: There's not much guesswork about this one; if
1432 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1433 register save, and the register used to calculate the destination
1434 had better be the one we think we're using for this purpose.
1435 It's also assumed that a copy from a call-saved register to another
1436 register is saving that register if RTX_FRAME_RELATED_P is set on
1437 that instruction. If the copy is from a call-saved register to
1438 the *same* register, that means that the register is now the same
1439 value as in the caller.
1440
1441 Except: If the register being saved is the CFA register, and the
1442 offset is nonzero, we are saving the CFA, so we assume we have to
1443 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1444 the intent is to save the value of SP from the previous frame.
1445
1446 In addition, if a register has previously been saved to a different
1447 register,
1448
1449 Invariants / Summaries of Rules
1450
1451 cfa current rule for calculating the CFA. It usually
1452 consists of a register and an offset. This is
1453 actually stored in *cur_cfa, but abbreviated
1454 for the purposes of this documentation.
1455 cfa_store register used by prologue code to save things to the stack
1456 cfa_store.offset is the offset from the value of
1457 cfa_store.reg to the actual CFA
1458 cfa_temp register holding an integral value. cfa_temp.offset
1459 stores the value, which will be used to adjust the
1460 stack pointer. cfa_temp is also used like cfa_store,
1461 to track stores to the stack via fp or a temp reg.
1462
1463 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1464 with cfa.reg as the first operand changes the cfa.reg and its
1465 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1466 cfa_temp.offset.
1467
1468 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1469 expression yielding a constant. This sets cfa_temp.reg
1470 and cfa_temp.offset.
1471
1472 Rule 5: Create a new register cfa_store used to save items to the
1473 stack.
1474
1475 Rules 10-14: Save a register to the stack. Define offset as the
1476 difference of the original location and cfa_store's
1477 location (or cfa_temp's location if cfa_temp is used).
1478
1479 Rules 16-20: If AND operation happens on sp in prologue, we assume
1480 stack is realigned. We will use a group of DW_OP_XXX
1481 expressions to represent the location of the stored
1482 register instead of CFA+offset.
1483
1484 The Rules
1485
1486 "{a,b}" indicates a choice of a xor b.
1487 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1488
1489 Rule 1:
1490 (set <reg1> <reg2>:cfa.reg)
1491 effects: cfa.reg = <reg1>
1492 cfa.offset unchanged
1493 cfa_temp.reg = <reg1>
1494 cfa_temp.offset = cfa.offset
1495
1496 Rule 2:
1497 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1498 {<const_int>,<reg>:cfa_temp.reg}))
1499 effects: cfa.reg = sp if fp used
1500 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1501 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1502 if cfa_store.reg==sp
1503
1504 Rule 3:
1505 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1506 effects: cfa.reg = fp
1507 cfa_offset += +/- <const_int>
1508
1509 Rule 4:
1510 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1511 constraints: <reg1> != fp
1512 <reg1> != sp
1513 effects: cfa.reg = <reg1>
1514 cfa_temp.reg = <reg1>
1515 cfa_temp.offset = cfa.offset
1516
1517 Rule 5:
1518 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1519 constraints: <reg1> != fp
1520 <reg1> != sp
1521 effects: cfa_store.reg = <reg1>
1522 cfa_store.offset = cfa.offset - cfa_temp.offset
1523
1524 Rule 6:
1525 (set <reg> <const_int>)
1526 effects: cfa_temp.reg = <reg>
1527 cfa_temp.offset = <const_int>
1528
1529 Rule 7:
1530 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1531 effects: cfa_temp.reg = <reg1>
1532 cfa_temp.offset |= <const_int>
1533
1534 Rule 8:
1535 (set <reg> (high <exp>))
1536 effects: none
1537
1538 Rule 9:
1539 (set <reg> (lo_sum <exp> <const_int>))
1540 effects: cfa_temp.reg = <reg>
1541 cfa_temp.offset = <const_int>
1542
1543 Rule 10:
1544 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1545 effects: cfa_store.offset -= <const_int>
1546 cfa.offset = cfa_store.offset if cfa.reg == sp
1547 cfa.reg = sp
1548 cfa.base_offset = -cfa_store.offset
1549
1550 Rule 11:
1551 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
1552 effects: cfa_store.offset += -/+ mode_size(mem)
1553 cfa.offset = cfa_store.offset if cfa.reg == sp
1554 cfa.reg = sp
1555 cfa.base_offset = -cfa_store.offset
1556
1557 Rule 12:
1558 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1559
1560 <reg2>)
1561 effects: cfa.reg = <reg1>
1562 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1563
1564 Rule 13:
1565 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1566 effects: cfa.reg = <reg1>
1567 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1568
1569 Rule 14:
1570 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
1571 effects: cfa.reg = <reg1>
1572 cfa.base_offset = -cfa_temp.offset
1573 cfa_temp.offset -= mode_size(mem)
1574
1575 Rule 15:
1576 (set <reg> {unspec, unspec_volatile})
1577 effects: target-dependent
1578
1579 Rule 16:
1580 (set sp (and: sp <const_int>))
1581 constraints: cfa_store.reg == sp
1582 effects: cfun->fde.stack_realign = 1
1583 cfa_store.offset = 0
1584 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1585
1586 Rule 17:
1587 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1588 effects: cfa_store.offset += -/+ mode_size(mem)
1589
1590 Rule 18:
1591 (set (mem ({pre_inc, pre_dec} sp)) fp)
1592 constraints: fde->stack_realign == 1
1593 effects: cfa_store.offset = 0
1594 cfa.reg != HARD_FRAME_POINTER_REGNUM
1595
1596 Rule 19:
1597 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1598 constraints: fde->stack_realign == 1
1599 && cfa.offset == 0
1600 && cfa.indirect == 0
1601 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1602 effects: Use DW_CFA_def_cfa_expression to define cfa
1603 cfa.reg == fde->drap_reg */
1604
1605static void
1606dwarf2out_frame_debug_expr (rtx expr)
1607{
1608 rtx src, dest, span;
1609 poly_int64 offset;
1610 dw_fde_ref fde;
1611
1612 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1613 the PARALLEL independently. The first element is always processed if
1614 it is a SET. This is for backward compatibility. Other elements
1615 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1616 flag is set in them. */
1617 if (GET_CODE (expr)((enum rtx_code) (expr)->code) == PARALLEL || GET_CODE (expr)((enum rtx_code) (expr)->code) == SEQUENCE)
1618 {
1619 int par_index;
1620 int limit = XVECLEN (expr, 0)(((((expr)->u.fld[0]).rt_rtvec))->num_elem);
1621 rtx elem;
1622
1623 /* PARALLELs have strict read-modify-write semantics, so we
1624 ought to evaluate every rvalue before changing any lvalue.
1625 It's cumbersome to do that in general, but there's an
1626 easy approximation that is enough for all current users:
1627 handle register saves before register assignments. */
1628 if (GET_CODE (expr)((enum rtx_code) (expr)->code) == PARALLEL)
1629 for (par_index = 0; par_index < limit; par_index++)
1630 {
1631 elem = XVECEXP (expr, 0, par_index)(((((expr)->u.fld[0]).rt_rtvec))->elem[par_index]);
1632 if (GET_CODE (elem)((enum rtx_code) (elem)->code) == SET
1633 && MEM_P (SET_DEST (elem))(((enum rtx_code) ((((elem)->u.fld[0]).rt_rtx))->code) ==
MEM)
1634 && (RTX_FRAME_RELATED_P (elem)(__extension__ ({ __typeof ((elem)) const _rtx = ((elem)); if
(((enum rtx_code) (_rtx)->code) != DEBUG_INSN && (
(enum rtx_code) (_rtx)->code) != INSN && ((enum rtx_code
) (_rtx)->code) != CALL_INSN && ((enum rtx_code) (
_rtx)->code) != JUMP_INSN && ((enum rtx_code) (_rtx
)->code) != BARRIER && ((enum rtx_code) (_rtx)->
code) != SET) rtl_check_failed_flag ("RTX_FRAME_RELATED_P",_rtx
, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1634, __FUNCTION__); _rtx; })->frame_related)
|| par_index == 0))
1635 dwarf2out_frame_debug_expr (elem);
1636 }
1637
1638 for (par_index = 0; par_index < limit; par_index++)
1639 {
1640 elem = XVECEXP (expr, 0, par_index)(((((expr)->u.fld[0]).rt_rtvec))->elem[par_index]);
1641 if (GET_CODE (elem)((enum rtx_code) (elem)->code) == SET
1642 && (!MEM_P (SET_DEST (elem))(((enum rtx_code) ((((elem)->u.fld[0]).rt_rtx))->code) ==
MEM)
|| GET_CODE (expr)((enum rtx_code) (expr)->code) == SEQUENCE)
1643 && (RTX_FRAME_RELATED_P (elem)(__extension__ ({ __typeof ((elem)) const _rtx = ((elem)); if
(((enum rtx_code) (_rtx)->code) != DEBUG_INSN && (
(enum rtx_code) (_rtx)->code) != INSN && ((enum rtx_code
) (_rtx)->code) != CALL_INSN && ((enum rtx_code) (
_rtx)->code) != JUMP_INSN && ((enum rtx_code) (_rtx
)->code) != BARRIER && ((enum rtx_code) (_rtx)->
code) != SET) rtl_check_failed_flag ("RTX_FRAME_RELATED_P",_rtx
, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1643, __FUNCTION__); _rtx; })->frame_related)
|| par_index == 0))
1644 dwarf2out_frame_debug_expr (elem);
1645 }
1646 return;
1647 }
1648
1649 gcc_assert (GET_CODE (expr) == SET)((void)(!(((enum rtx_code) (expr)->code) == SET) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1649, __FUNCTION__), 0 : 0))
;
1650
1651 src = SET_SRC (expr)(((expr)->u.fld[1]).rt_rtx);
1652 dest = SET_DEST (expr)(((expr)->u.fld[0]).rt_rtx);
1653
1654 if (REG_P (src)(((enum rtx_code) (src)->code) == REG))
1655 {
1656 rtx rsi = reg_saved_in (src);
1657 if (rsi)
1658 src = rsi;
1659 }
1660
1661 fde = cfun(cfun + 0)->fde;
1662
1663 switch (GET_CODE (dest)((enum rtx_code) (dest)->code))
1664 {
1665 case REG:
1666 switch (GET_CODE (src)((enum rtx_code) (src)->code))
1667 {
1668 /* Setting FP from SP. */
1669 case REG:
1670 if (cur_cfa->reg == dwf_regno (src))
1671 {
1672 /* Rule 1 */
1673 /* Update the CFA rule wrt SP or FP. Make sure src is
1674 relative to the current CFA register.
1675
1676 We used to require that dest be either SP or FP, but the
1677 ARM copies SP to a temporary register, and from there to
1678 FP. So we just rely on the backends to only set
1679 RTX_FRAME_RELATED_P on appropriate insns. */
1680 cur_cfa->reg = dwf_regno (dest);
1681 cur_trace->cfa_temp.reg = cur_cfa->reg;
1682 cur_trace->cfa_temp.offset = cur_cfa->offset;
1683 }
1684 else
1685 {
1686 /* Saving a register in a register. */
1687 gcc_assert (!fixed_regs [REGNO (dest)]((void)(!(!(this_target_hard_regs->x_fixed_regs) [(rhs_regno
(dest))] || (dwf_regno (src) == (((global_options.x_ix86_isa_flags
& (1UL << 1)) != 0) ? 16 : 8))) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1689, __FUNCTION__), 0 : 0))
1688 /* For the SPARC and its register window. */((void)(!(!(this_target_hard_regs->x_fixed_regs) [(rhs_regno
(dest))] || (dwf_regno (src) == (((global_options.x_ix86_isa_flags
& (1UL << 1)) != 0) ? 16 : 8))) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1689, __FUNCTION__), 0 : 0))
1689 || (dwf_regno (src) == DWARF_FRAME_RETURN_COLUMN))((void)(!(!(this_target_hard_regs->x_fixed_regs) [(rhs_regno
(dest))] || (dwf_regno (src) == (((global_options.x_ix86_isa_flags
& (1UL << 1)) != 0) ? 16 : 8))) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1689, __FUNCTION__), 0 : 0))
;
1690
1691 /* After stack is aligned, we can only save SP in FP
1692 if drap register is used. In this case, we have
1693 to restore stack pointer with the CFA value and we
1694 don't generate this DWARF information. */
1695 if (fde
1696 && fde->stack_realign
1697 && REGNO (src)(rhs_regno(src)) == STACK_POINTER_REGNUM7)
1698 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM((void)(!((rhs_regno(dest)) == 6 && fde->drap_reg !=
(~(unsigned int) 0) && cur_cfa->reg != dwf_regno (
src)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1700, __FUNCTION__), 0 : 0))
1699 && fde->drap_reg != INVALID_REGNUM((void)(!((rhs_regno(dest)) == 6 && fde->drap_reg !=
(~(unsigned int) 0) && cur_cfa->reg != dwf_regno (
src)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1700, __FUNCTION__), 0 : 0))
1700 && cur_cfa->reg != dwf_regno (src))((void)(!((rhs_regno(dest)) == 6 && fde->drap_reg !=
(~(unsigned int) 0) && cur_cfa->reg != dwf_regno (
src)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1700, __FUNCTION__), 0 : 0))
;
1701 else
1702 queue_reg_save (src, dest, 0);
1703 }
1704 break;
1705
1706 case PLUS:
1707 case MINUS:
1708 case LO_SUM:
1709 if (dest == stack_pointer_rtx((this_target_rtl->x_global_rtl)[GR_STACK_POINTER]))
1710 {
1711 /* Rule 2 */
1712 /* Adjusting SP. */
1713 if (REG_P (XEXP (src, 1))(((enum rtx_code) ((((src)->u.fld[1]).rt_rtx))->code) ==
REG)
)
1714 {
1715 gcc_assert (dwf_regno (XEXP (src, 1))((void)(!(dwf_regno ((((src)->u.fld[1]).rt_rtx)) == cur_trace
->cfa_temp.reg) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1716, __FUNCTION__), 0 : 0))
1716 == cur_trace->cfa_temp.reg)((void)(!(dwf_regno ((((src)->u.fld[1]).rt_rtx)) == cur_trace
->cfa_temp.reg) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1716, __FUNCTION__), 0 : 0))
;
1717 offset = cur_trace->cfa_temp.offset;
1718 }
1719 else if (!poly_int_rtx_p (XEXP (src, 1)(((src)->u.fld[1]).rt_rtx), &offset))
1720 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1720, __FUNCTION__))
;
1721
1722 if (XEXP (src, 0)(((src)->u.fld[0]).rt_rtx) == hard_frame_pointer_rtx((this_target_rtl->x_global_rtl)[GR_HARD_FRAME_POINTER]))
1723 {
1724 /* Restoring SP from FP in the epilogue. */
1725 gcc_assert (cur_cfa->reg == dw_frame_pointer_regnum)((void)(!(cur_cfa->reg == dw_frame_pointer_regnum) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1725, __FUNCTION__), 0 : 0))
;
1726 cur_cfa->reg = dw_stack_pointer_regnum;
1727 }
1728 else if (GET_CODE (src)((enum rtx_code) (src)->code) == LO_SUM)
1729 /* Assume we've set the source reg of the LO_SUM from sp. */
1730 ;
1731 else
1732 gcc_assert (XEXP (src, 0) == stack_pointer_rtx)((void)(!((((src)->u.fld[0]).rt_rtx) == ((this_target_rtl->
x_global_rtl)[GR_STACK_POINTER])) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1732, __FUNCTION__), 0 : 0))
;
1733
1734 if (GET_CODE (src)((enum rtx_code) (src)->code) != MINUS)
1735 offset = -offset;
1736 if (cur_cfa->reg == dw_stack_pointer_regnum)
1737 cur_cfa->offset += offset;
1738 if (cur_trace->cfa_store.reg == dw_stack_pointer_regnum)
1739 cur_trace->cfa_store.offset += offset;
1740 }
1741 else if (dest == hard_frame_pointer_rtx((this_target_rtl->x_global_rtl)[GR_HARD_FRAME_POINTER]))
1742 {
1743 /* Rule 3 */
1744 /* Either setting the FP from an offset of the SP,
1745 or adjusting the FP */
1746 gcc_assert (frame_pointer_needed)((void)(!(((&x_rtl)->frame_pointer_needed)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1746, __FUNCTION__), 0 : 0))
;
1747
1748 gcc_assert (REG_P (XEXP (src, 0))((void)(!((((enum rtx_code) ((((src)->u.fld[0]).rt_rtx))->
code) == REG) && dwf_regno ((((src)->u.fld[0]).rt_rtx
)) == cur_cfa->reg) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1749, __FUNCTION__), 0 : 0))
1749 && dwf_regno (XEXP (src, 0)) == cur_cfa->reg)((void)(!((((enum rtx_code) ((((src)->u.fld[0]).rt_rtx))->
code) == REG) && dwf_regno ((((src)->u.fld[0]).rt_rtx
)) == cur_cfa->reg) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1749, __FUNCTION__), 0 : 0))
;
1750 offset = rtx_to_poly_int64 (XEXP (src, 1)(((src)->u.fld[1]).rt_rtx));
1751 if (GET_CODE (src)((enum rtx_code) (src)->code) != MINUS)
1752 offset = -offset;
1753 cur_cfa->offset += offset;
1754 cur_cfa->reg = dw_frame_pointer_regnum;
1755 }
1756 else
1757 {
1758 gcc_assert (GET_CODE (src) != MINUS)((void)(!(((enum rtx_code) (src)->code) != MINUS) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1758, __FUNCTION__), 0 : 0))
;
1759
1760 /* Rule 4 */
1761 if (REG_P (XEXP (src, 0))(((enum rtx_code) ((((src)->u.fld[0]).rt_rtx))->code) ==
REG)
1762 && dwf_regno (XEXP (src, 0)(((src)->u.fld[0]).rt_rtx)) == cur_cfa->reg
1763 && poly_int_rtx_p (XEXP (src, 1)(((src)->u.fld[1]).rt_rtx), &offset))
1764 {
1765 /* Setting a temporary CFA register that will be copied
1766 into the FP later on. */
1767 offset = -offset;
1768 cur_cfa->offset += offset;
1769 cur_cfa->reg = dwf_regno (dest);
1770 /* Or used to save regs to the stack. */
1771 cur_trace->cfa_temp.reg = cur_cfa->reg;
1772 cur_trace->cfa_temp.offset = cur_cfa->offset;
1773 }
1774
1775 /* Rule 5 */
1776 else if (REG_P (XEXP (src, 0))(((enum rtx_code) ((((src)->u.fld[0]).rt_rtx))->code) ==
REG)
1777 && dwf_regno (XEXP (src, 0)(((src)->u.fld[0]).rt_rtx)) == cur_trace->cfa_temp.reg
1778 && XEXP (src, 1)(((src)->u.fld[1]).rt_rtx) == stack_pointer_rtx((this_target_rtl->x_global_rtl)[GR_STACK_POINTER]))
1779 {
1780 /* Setting a scratch register that we will use instead
1781 of SP for saving registers to the stack. */
1782 gcc_assert (cur_cfa->reg == dw_stack_pointer_regnum)((void)(!(cur_cfa->reg == dw_stack_pointer_regnum) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1782, __FUNCTION__), 0 : 0))
;
1783 cur_trace->cfa_store.reg = dwf_regno (dest);
1784 cur_trace->cfa_store.offset
1785 = cur_cfa->offset - cur_trace->cfa_temp.offset;
1786 }
1787
1788 /* Rule 9 */
1789 else if (GET_CODE (src)((enum rtx_code) (src)->code) == LO_SUM
1790 && poly_int_rtx_p (XEXP (src, 1)(((src)->u.fld[1]).rt_rtx),
1791 &cur_trace->cfa_temp.offset))
1792 cur_trace->cfa_temp.reg = dwf_regno (dest);
1793 else
1794 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1794, __FUNCTION__))
;
1795 }
1796 break;
1797
1798 /* Rule 6 */
1799 case CONST_INT:
1800 case CONST_POLY_INT:
1801 cur_trace->cfa_temp.reg = dwf_regno (dest);
1802 cur_trace->cfa_temp.offset = rtx_to_poly_int64 (src);
1803 break;
1804
1805 /* Rule 7 */
1806 case IOR:
1807 gcc_assert (REG_P (XEXP (src, 0))((void)(!((((enum rtx_code) ((((src)->u.fld[0]).rt_rtx))->
code) == REG) && dwf_regno ((((src)->u.fld[0]).rt_rtx
)) == cur_trace->cfa_temp.reg && (((enum rtx_code)
((((src)->u.fld[1]).rt_rtx))->code) == CONST_INT)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1809, __FUNCTION__), 0 : 0))
1808 && dwf_regno (XEXP (src, 0)) == cur_trace->cfa_temp.reg((void)(!((((enum rtx_code) ((((src)->u.fld[0]).rt_rtx))->
code) == REG) && dwf_regno ((((src)->u.fld[0]).rt_rtx
)) == cur_trace->cfa_temp.reg && (((enum rtx_code)
((((src)->u.fld[1]).rt_rtx))->code) == CONST_INT)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1809, __FUNCTION__), 0 : 0))
1809 && CONST_INT_P (XEXP (src, 1)))((void)(!((((enum rtx_code) ((((src)->u.fld[0]).rt_rtx))->
code) == REG) && dwf_regno ((((src)->u.fld[0]).rt_rtx
)) == cur_trace->cfa_temp.reg && (((enum rtx_code)
((((src)->u.fld[1]).rt_rtx))->code) == CONST_INT)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1809, __FUNCTION__), 0 : 0))
;
1810
1811 cur_trace->cfa_temp.reg = dwf_regno (dest);
1812 if (!can_ior_p (cur_trace->cfa_temp.offset, INTVAL (XEXP (src, 1))(((((src)->u.fld[1]).rt_rtx))->u.hwint[0]),
1813 &cur_trace->cfa_temp.offset))
1814 /* The target shouldn't generate this kind of CFI note if we
1815 can't represent it. */
1816 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1816, __FUNCTION__))
;
1817 break;
1818
1819 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1820 which will fill in all of the bits. */
1821 /* Rule 8 */
1822 case HIGH:
1823 break;
1824
1825 /* Rule 15 */
1826 case UNSPEC:
1827 case UNSPEC_VOLATILE:
1828 /* All unspecs should be represented by REG_CFA_* notes. */
1829 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1829, __FUNCTION__))
;
1830 return;
1831
1832 /* Rule 16 */
1833 case AND:
1834 /* If this AND operation happens on stack pointer in prologue,
1835 we assume the stack is realigned and we extract the
1836 alignment. */
1837 if (fde && XEXP (src, 0)(((src)->u.fld[0]).rt_rtx) == stack_pointer_rtx((this_target_rtl->x_global_rtl)[GR_STACK_POINTER]))
1838 {
1839 /* We interpret reg_save differently with stack_realign set.
1840 Thus we must flush whatever we have queued first. */
1841 dwarf2out_flush_queued_reg_saves ();
1842
1843 gcc_assert (cur_trace->cfa_store.reg((void)(!(cur_trace->cfa_store.reg == dwf_regno ((((src)->
u.fld[0]).rt_rtx))) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1844, __FUNCTION__), 0 : 0))
1844 == dwf_regno (XEXP (src, 0)))((void)(!(cur_trace->cfa_store.reg == dwf_regno ((((src)->
u.fld[0]).rt_rtx))) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1844, __FUNCTION__), 0 : 0))
;
1845 fde->stack_realign = 1;
1846 fde->stack_realignment = INTVAL (XEXP (src, 1))(((((src)->u.fld[1]).rt_rtx))->u.hwint[0]);
1847 cur_trace->cfa_store.offset = 0;
1848
1849 if (cur_cfa->reg != dw_stack_pointer_regnum
1850 && cur_cfa->reg != dw_frame_pointer_regnum)
1851 fde->drap_reg = cur_cfa->reg;
1852 }
1853 return;
1854
1855 default:
1856 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1856, __FUNCTION__))
;
1857 }
1858 break;
1859
1860 case MEM:
1861
1862 /* Saving a register to the stack. Make sure dest is relative to the
1863 CFA register. */
1864 switch (GET_CODE (XEXP (dest, 0))((enum rtx_code) ((((dest)->u.fld[0]).rt_rtx))->code))
1865 {
1866 /* Rule 10 */
1867 /* With a push. */
1868 case PRE_MODIFY:
1869 case POST_MODIFY:
1870 /* We can't handle variable size modifications. */
1871 offset = -rtx_to_poly_int64 (XEXP (XEXP (XEXP (dest, 0), 1), 1)(((((((((dest)->u.fld[0]).rt_rtx))->u.fld[1]).rt_rtx))->
u.fld[1]).rt_rtx)
);
1872
1873 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM((void)(!((rhs_regno(((((((dest)->u.fld[0]).rt_rtx))->u
.fld[0]).rt_rtx))) == 7 && cur_trace->cfa_store.reg
== dw_stack_pointer_regnum) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1874, __FUNCTION__), 0 : 0))
1874 && cur_trace->cfa_store.reg == dw_stack_pointer_regnum)((void)(!((rhs_regno(((((((dest)->u.fld[0]).rt_rtx))->u
.fld[0]).rt_rtx))) == 7 && cur_trace->cfa_store.reg
== dw_stack_pointer_regnum) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1874, __FUNCTION__), 0 : 0))
;
1875
1876 cur_trace->cfa_store.offset += offset;
1877 if (cur_cfa->reg == dw_stack_pointer_regnum)
1878 cur_cfa->offset = cur_trace->cfa_store.offset;
1879
1880 if (GET_CODE (XEXP (dest, 0))((enum rtx_code) ((((dest)->u.fld[0]).rt_rtx))->code) == POST_MODIFY)
1881 offset -= cur_trace->cfa_store.offset;
1882 else
1883 offset = -cur_trace->cfa_store.offset;
1884 break;
1885
1886 /* Rule 11 */
1887 case PRE_INC:
1888 case PRE_DEC:
1889 case POST_DEC:
1890 offset = GET_MODE_SIZE (GET_MODE (dest)((machine_mode) (dest)->mode));
1891 if (GET_CODE (XEXP (dest, 0))((enum rtx_code) ((((dest)->u.fld[0]).rt_rtx))->code) == PRE_INC)
1892 offset = -offset;
1893
1894 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))((void)(!(((rhs_regno(((((((dest)->u.fld[0]).rt_rtx))->
u.fld[0]).rt_rtx))) == 7) && cur_trace->cfa_store.
reg == dw_stack_pointer_regnum) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1896, __FUNCTION__), 0 : 0))
1895 == STACK_POINTER_REGNUM)((void)(!(((rhs_regno(((((((dest)->u.fld[0]).rt_rtx))->
u.fld[0]).rt_rtx))) == 7) && cur_trace->cfa_store.
reg == dw_stack_pointer_regnum) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1896, __FUNCTION__), 0 : 0))
1896 && cur_trace->cfa_store.reg == dw_stack_pointer_regnum)((void)(!(((rhs_regno(((((((dest)->u.fld[0]).rt_rtx))->
u.fld[0]).rt_rtx))) == 7) && cur_trace->cfa_store.
reg == dw_stack_pointer_regnum) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1896, __FUNCTION__), 0 : 0))
;
1897
1898 cur_trace->cfa_store.offset += offset;
1899
1900 /* Rule 18: If stack is aligned, we will use FP as a
1901 reference to represent the address of the stored
1902 regiser. */
1903 if (fde
1904 && fde->stack_realign
1905 && REG_P (src)(((enum rtx_code) (src)->code) == REG)
1906 && REGNO (src)(rhs_regno(src)) == HARD_FRAME_POINTER_REGNUM6)
1907 {
1908 gcc_assert (cur_cfa->reg != dw_frame_pointer_regnum)((void)(!(cur_cfa->reg != dw_frame_pointer_regnum) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1908, __FUNCTION__), 0 : 0))
;
1909 cur_trace->cfa_store.offset = 0;
1910 }
1911
1912 if (cur_cfa->reg == dw_stack_pointer_regnum)
1913 cur_cfa->offset = cur_trace->cfa_store.offset;
1914
1915 if (GET_CODE (XEXP (dest, 0))((enum rtx_code) ((((dest)->u.fld[0]).rt_rtx))->code) == POST_DEC)
1916 offset += -cur_trace->cfa_store.offset;
1917 else
1918 offset = -cur_trace->cfa_store.offset;
1919 break;
1920
1921 /* Rule 12 */
1922 /* With an offset. */
1923 case PLUS:
1924 case MINUS:
1925 case LO_SUM:
1926 {
1927 unsigned int regno;
1928
1929 gcc_assert (REG_P (XEXP (XEXP (dest, 0), 0)))((void)(!((((enum rtx_code) (((((((dest)->u.fld[0]).rt_rtx
))->u.fld[0]).rt_rtx))->code) == REG)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1929, __FUNCTION__), 0 : 0))
;
1930 offset = rtx_to_poly_int64 (XEXP (XEXP (dest, 0), 1)((((((dest)->u.fld[0]).rt_rtx))->u.fld[1]).rt_rtx));
1931 if (GET_CODE (XEXP (dest, 0))((enum rtx_code) ((((dest)->u.fld[0]).rt_rtx))->code) == MINUS)
1932 offset = -offset;
1933
1934 regno = dwf_regno (XEXP (XEXP (dest, 0), 0)((((((dest)->u.fld[0]).rt_rtx))->u.fld[0]).rt_rtx));
1935
1936 if (cur_cfa->reg == regno)
1937 offset -= cur_cfa->offset;
1938 else if (cur_trace->cfa_store.reg == regno)
1939 offset -= cur_trace->cfa_store.offset;
1940 else
1941 {
1942 gcc_assert (cur_trace->cfa_temp.reg == regno)((void)(!(cur_trace->cfa_temp.reg == regno) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1942, __FUNCTION__), 0 : 0))
;
1943 offset -= cur_trace->cfa_temp.offset;
1944 }
1945 }
1946 break;
1947
1948 /* Rule 13 */
1949 /* Without an offset. */
1950 case REG:
1951 {
1952 unsigned int regno = dwf_regno (XEXP (dest, 0)(((dest)->u.fld[0]).rt_rtx));
1953
1954 if (cur_cfa->reg == regno)
1955 offset = -cur_cfa->offset;
1956 else if (cur_trace->cfa_store.reg == regno)
1957 offset = -cur_trace->cfa_store.offset;
1958 else
1959 {
1960 gcc_assert (cur_trace->cfa_temp.reg == regno)((void)(!(cur_trace->cfa_temp.reg == regno) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1960, __FUNCTION__), 0 : 0))
;
1961 offset = -cur_trace->cfa_temp.offset;
1962 }
1963 }
1964 break;
1965
1966 /* Rule 14 */
1967 case POST_INC:
1968 gcc_assert (cur_trace->cfa_temp.reg((void)(!(cur_trace->cfa_temp.reg == dwf_regno (((((((dest
)->u.fld[0]).rt_rtx))->u.fld[0]).rt_rtx))) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1969, __FUNCTION__), 0 : 0))
1969 == dwf_regno (XEXP (XEXP (dest, 0), 0)))((void)(!(cur_trace->cfa_temp.reg == dwf_regno (((((((dest
)->u.fld[0]).rt_rtx))->u.fld[0]).rt_rtx))) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1969, __FUNCTION__), 0 : 0))
;
1970 offset = -cur_trace->cfa_temp.offset;
1971 cur_trace->cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)((machine_mode) (dest)->mode));
1972 break;
1973
1974 default:
1975 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 1975, __FUNCTION__))
;
1976 }
1977
1978 /* Rule 17 */
1979 /* If the source operand of this MEM operation is a memory,
1980 we only care how much stack grew. */
1981 if (MEM_P (src)(((enum rtx_code) (src)->code) == MEM))
1982 break;
1983
1984 if (REG_P (src)(((enum rtx_code) (src)->code) == REG)
1985 && REGNO (src)(rhs_regno(src)) != STACK_POINTER_REGNUM7
1986 && REGNO (src)(rhs_regno(src)) != HARD_FRAME_POINTER_REGNUM6
1987 && dwf_regno (src) == cur_cfa->reg)
1988 {
1989 /* We're storing the current CFA reg into the stack. */
1990
1991 if (known_eq (cur_cfa->offset, 0)(!maybe_ne (cur_cfa->offset, 0)))
1992 {
1993 /* Rule 19 */
1994 /* If stack is aligned, putting CFA reg into stack means
1995 we can no longer use reg + offset to represent CFA.
1996 Here we use DW_CFA_def_cfa_expression instead. The
1997 result of this expression equals to the original CFA
1998 value. */
1999 if (fde
2000 && fde->stack_realign
2001 && cur_cfa->indirect == 0
2002 && cur_cfa->reg != dw_frame_pointer_regnum)
2003 {
2004 gcc_assert (fde->drap_reg == cur_cfa->reg)((void)(!(fde->drap_reg == cur_cfa->reg) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2004, __FUNCTION__), 0 : 0))
;
2005
2006 cur_cfa->indirect = 1;
2007 cur_cfa->reg = dw_frame_pointer_regnum;
2008 cur_cfa->base_offset = offset;
2009 cur_cfa->offset = 0;
2010
2011 fde->drap_reg_saved = 1;
2012 break;
2013 }
2014
2015 /* If the source register is exactly the CFA, assume
2016 we're saving SP like any other register; this happens
2017 on the ARM. */
2018 queue_reg_save (stack_pointer_rtx((this_target_rtl->x_global_rtl)[GR_STACK_POINTER]), NULL_RTX(rtx) 0, offset);
2019 break;
2020 }
2021 else
2022 {
2023 /* Otherwise, we'll need to look in the stack to
2024 calculate the CFA. */
2025 rtx x = XEXP (dest, 0)(((dest)->u.fld[0]).rt_rtx);
2026
2027 if (!REG_P (x)(((enum rtx_code) (x)->code) == REG))
2028 x = XEXP (x, 0)(((x)->u.fld[0]).rt_rtx);
2029 gcc_assert (REG_P (x))((void)(!((((enum rtx_code) (x)->code) == REG)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2029, __FUNCTION__), 0 : 0))
;
2030
2031 cur_cfa->reg = dwf_regno (x);
2032 cur_cfa->base_offset = offset;
2033 cur_cfa->indirect = 1;
2034 break;
2035 }
2036 }
2037
2038 if (REG_P (src)(((enum rtx_code) (src)->code) == REG))
2039 span = targetm.dwarf_register_span (src);
2040 else
2041 span = NULLnullptr;
2042
2043 if (!span)
2044 queue_reg_save (src, NULL_RTX(rtx) 0, offset);
2045 else
2046 {
2047 /* We have a PARALLEL describing where the contents of SRC live.
2048 Queue register saves for each piece of the PARALLEL. */
2049 poly_int64 span_offset = offset;
2050
2051 gcc_assert (GET_CODE (span) == PARALLEL)((void)(!(((enum rtx_code) (span)->code) == PARALLEL) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2051, __FUNCTION__), 0 : 0))
;
2052
2053 const int par_len = XVECLEN (span, 0)(((((span)->u.fld[0]).rt_rtvec))->num_elem);
2054 for (int par_index = 0; par_index < par_len; par_index++)
2055 {
2056 rtx elem = XVECEXP (span, 0, par_index)(((((span)->u.fld[0]).rt_rtvec))->elem[par_index]);
2057 queue_reg_save (elem, NULL_RTX(rtx) 0, span_offset);
2058 span_offset += GET_MODE_SIZE (GET_MODE (elem)((machine_mode) (elem)->mode));
2059 }
2060 }
2061 break;
2062
2063 default:
2064 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2064, __FUNCTION__))
;
2065 }
2066}
2067
2068/* Record call frame debugging information for INSN, which either sets
2069 SP or FP (adjusting how we calculate the frame address) or saves a
2070 register to the stack. */
2071
2072static void
2073dwarf2out_frame_debug (rtx_insn *insn)
2074{
2075 rtx note, n, pat;
2076 bool handled_one = false;
2077
2078 for (note = REG_NOTES (insn)(((insn)->u.fld[6]).rt_rtx); note; note = XEXP (note, 1)(((note)->u.fld[1]).rt_rtx))
2079 switch (REG_NOTE_KIND (note)((enum reg_note) ((machine_mode) (note)->mode)))
2080 {
2081 case REG_FRAME_RELATED_EXPR:
2082 pat = XEXP (note, 0)(((note)->u.fld[0]).rt_rtx);
2083 goto do_frame_expr;
2084
2085 case REG_CFA_DEF_CFA:
2086 dwarf2out_frame_debug_def_cfa (XEXP (note, 0)(((note)->u.fld[0]).rt_rtx));
2087 handled_one = true;
2088 break;
2089
2090 case REG_CFA_ADJUST_CFA:
2091 n = XEXP (note, 0)(((note)->u.fld[0]).rt_rtx);
2092 if (n == NULLnullptr)
2093 {
2094 n = PATTERN (insn);
2095 if (GET_CODE (n)((enum rtx_code) (n)->code) == PARALLEL)
2096 n = XVECEXP (n, 0, 0)(((((n)->u.fld[0]).rt_rtvec))->elem[0]);
2097 }
2098 dwarf2out_frame_debug_adjust_cfa (n);
2099 handled_one = true;
2100 break;
2101
2102 case REG_CFA_OFFSET:
2103 n = XEXP (note, 0)(((note)->u.fld[0]).rt_rtx);
2104 if (n == NULLnullptr)
2105 n = single_set (insn);
2106 dwarf2out_frame_debug_cfa_offset (n);
2107 handled_one = true;
2108 break;
2109
2110 case REG_CFA_REGISTER:
2111 n = XEXP (note, 0)(((note)->u.fld[0]).rt_rtx);
2112 if (n == NULLnullptr)
2113 {
2114 n = PATTERN (insn);
2115 if (GET_CODE (n)((enum rtx_code) (n)->code) == PARALLEL)
2116 n = XVECEXP (n, 0, 0)(((((n)->u.fld[0]).rt_rtvec))->elem[0]);
2117 }
2118 dwarf2out_frame_debug_cfa_register (n);
2119 handled_one = true;
2120 break;
2121
2122 case REG_CFA_EXPRESSION:
2123 case REG_CFA_VAL_EXPRESSION:
2124 n = XEXP (note, 0)(((note)->u.fld[0]).rt_rtx);
2125 if (n == NULLnullptr)
2126 n = single_set (insn);
2127
2128 if (REG_NOTE_KIND (note)((enum reg_note) ((machine_mode) (note)->mode)) == REG_CFA_EXPRESSION)
2129 dwarf2out_frame_debug_cfa_expression (n);
2130 else
2131 dwarf2out_frame_debug_cfa_val_expression (n);
2132
2133 handled_one = true;
2134 break;
2135
2136 case REG_CFA_RESTORE:
2137 n = XEXP (note, 0)(((note)->u.fld[0]).rt_rtx);
2138 if (n == NULLnullptr)
2139 {
2140 n = PATTERN (insn);
2141 if (GET_CODE (n)((enum rtx_code) (n)->code) == PARALLEL)
2142 n = XVECEXP (n, 0, 0)(((((n)->u.fld[0]).rt_rtvec))->elem[0]);
2143 n = XEXP (n, 0)(((n)->u.fld[0]).rt_rtx);
2144 }
2145 dwarf2out_frame_debug_cfa_restore (n);
2146 handled_one = true;
2147 break;
2148
2149 case REG_CFA_SET_VDRAP:
2150 n = XEXP (note, 0)(((note)->u.fld[0]).rt_rtx);
2151 if (REG_P (n)(((enum rtx_code) (n)->code) == REG))
2152 {
2153 dw_fde_ref fde = cfun(cfun + 0)->fde;
2154 if (fde)
2155 {
2156 gcc_assert (fde->vdrap_reg == INVALID_REGNUM)((void)(!(fde->vdrap_reg == (~(unsigned int) 0)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2156, __FUNCTION__), 0 : 0))
;
2157 if (REG_P (n)(((enum rtx_code) (n)->code) == REG))
2158 fde->vdrap_reg = dwf_regno (n);
2159 }
2160 }
2161 handled_one = true;
2162 break;
2163
2164 case REG_CFA_TOGGLE_RA_MANGLE:
2165 dwarf2out_frame_debug_cfa_toggle_ra_mangle ();
2166 handled_one = true;
2167 break;
2168
2169 case REG_CFA_WINDOW_SAVE:
2170 dwarf2out_frame_debug_cfa_window_save ();
2171 handled_one = true;
2172 break;
2173
2174 case REG_CFA_FLUSH_QUEUE:
2175 /* The actual flush happens elsewhere. */
2176 handled_one = true;
2177 break;
2178
2179 default:
2180 break;
2181 }
2182
2183 if (!handled_one)
2184 {
2185 pat = PATTERN (insn);
2186 do_frame_expr:
2187 dwarf2out_frame_debug_expr (pat);
2188
2189 /* Check again. A parallel can save and update the same register.
2190 We could probably check just once, here, but this is safer than
2191 removing the check at the start of the function. */
2192 if (clobbers_queued_reg_save (pat))
2193 dwarf2out_flush_queued_reg_saves ();
2194 }
2195}
2196
2197/* Emit CFI info to change the state from OLD_ROW to NEW_ROW. */
2198
2199static void
2200change_cfi_row (dw_cfi_row *old_row, dw_cfi_row *new_row)
2201{
2202 size_t i, n_old, n_new, n_max;
2203 dw_cfi_ref cfi;
2204
2205 if (new_row->cfa_cfi && !cfi_equal_p (old_row->cfa_cfi, new_row->cfa_cfi))
2206 add_cfi (new_row->cfa_cfi);
2207 else
2208 {
2209 cfi = def_cfa_0 (&old_row->cfa, &new_row->cfa);
2210 if (cfi)
2211 add_cfi (cfi);
2212 }
2213
2214 n_old = vec_safe_length (old_row->reg_save);
2215 n_new = vec_safe_length (new_row->reg_save);
2216 n_max = MAX (n_old, n_new)((n_old) > (n_new) ? (n_old) : (n_new));
2217
2218 for (i = 0; i < n_max; ++i)
2219 {
2220 dw_cfi_ref r_old = NULLnullptr, r_new = NULLnullptr;
2221
2222 if (i < n_old)
2223 r_old = (*old_row->reg_save)[i];
2224 if (i < n_new)
2225 r_new = (*new_row->reg_save)[i];
2226
2227 if (r_old == r_new)
2228 ;
2229 else if (r_new == NULLnullptr)
2230 add_cfi_restore (i);
2231 else if (!cfi_equal_p (r_old, r_new))
2232 add_cfi (r_new);
2233 }
2234
2235 if (!old_row->window_save && new_row->window_save)
2236 {
2237 dw_cfi_ref cfi = new_cfi ();
2238
2239 gcc_assert (!old_row->ra_mangled && !new_row->ra_mangled)((void)(!(!old_row->ra_mangled && !new_row->ra_mangled
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2239, __FUNCTION__), 0 : 0))
;
2240 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
2241 add_cfi (cfi);
2242 }
2243
2244 if (old_row->ra_mangled != new_row->ra_mangled)
2245 {
2246 dw_cfi_ref cfi = new_cfi ();
2247
2248 gcc_assert (!old_row->window_save && !new_row->window_save)((void)(!(!old_row->window_save && !new_row->window_save
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2248, __FUNCTION__), 0 : 0))
;
2249 /* DW_CFA_GNU_window_save is reused for toggling RA mangle state. */
2250 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
2251 add_cfi (cfi);
2252 }
2253}
2254
2255/* Examine CFI and return true if a cfi label and set_loc is needed
2256 beforehand. Even when generating CFI assembler instructions, we
2257 still have to add the cfi to the list so that lookup_cfa_1 works
2258 later on. When -g2 and above we even need to force emitting of
2259 CFI labels and add to list a DW_CFA_set_loc for convert_cfa_to_fb_loc_list
2260 purposes. If we're generating DWARF3 output we use DW_OP_call_frame_cfa
2261 and so don't use convert_cfa_to_fb_loc_list. */
2262
2263static bool
2264cfi_label_required_p (dw_cfi_ref cfi)
2265{
2266 if (!dwarf2out_do_cfi_asm ())
2267 return true;
2268
2269 if (dwarf_versionglobal_options.x_dwarf_version == 2
2270 && debug_info_levelglobal_options.x_debug_info_level > DINFO_LEVEL_TERSE
2271 && (write_symbolsglobal_options.x_write_symbols == DWARF2_DEBUG
2272 || write_symbolsglobal_options.x_write_symbols == VMS_AND_DWARF2_DEBUG))
2273 {
2274 switch (cfi->dw_cfi_opc)
2275 {
2276 case DW_CFA_def_cfa_offset:
2277 case DW_CFA_def_cfa_offset_sf:
2278 case DW_CFA_def_cfa_register:
2279 case DW_CFA_def_cfa:
2280 case DW_CFA_def_cfa_sf:
2281 case DW_CFA_def_cfa_expression:
2282 case DW_CFA_restore_state:
2283 return true;
2284 default:
2285 return false;
2286 }
2287 }
2288 return false;
2289}
2290
2291/* Walk the function, looking for NOTE_INSN_CFI notes. Add the CFIs to the
2292 function's FDE, adding CFI labels and set_loc/advance_loc opcodes as
2293 necessary. */
2294static void
2295add_cfis_to_fde (void)
2296{
2297 dw_fde_ref fde = cfun(cfun + 0)->fde;
2298 rtx_insn *insn, *next;
2299
2300 for (insn = get_insns (); insn; insn = next)
7
Loop condition is true. Entering loop body
2301 {
2302 next = NEXT_INSN (insn);
2303
2304 if (NOTE_P (insn)(((enum rtx_code) (insn)->code) == NOTE) && NOTE_KIND (insn)(((insn)->u.fld[4]).rt_int) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
8
Assuming field 'code' is equal to NOTE
9
Assuming field 'rt_int' is not equal to NOTE_INSN_SWITCH_TEXT_SECTIONS
10
Taking false branch
2305 fde->dw_fde_switch_cfi_index = vec_safe_length (fde->dw_fde_cfi);
2306
2307 if (NOTE_P (insn)(((enum rtx_code) (insn)->code) == NOTE) && NOTE_KIND (insn)(((insn)->u.fld[4]).rt_int) == NOTE_INSN_CFI)
11
Assuming field 'rt_int' is equal to NOTE_INSN_CFI
12
Taking true branch
2308 {
2309 bool required = cfi_label_required_p (NOTE_CFI (insn)(((insn)->u.fld[3]).rt_cfi));
2310 while (next)
13
Loop condition is false. Execution continues on line 2322
2311 if (NOTE_P (next)(((enum rtx_code) (next)->code) == NOTE) && NOTE_KIND (next)(((next)->u.fld[4]).rt_int) == NOTE_INSN_CFI)
2312 {
2313 required |= cfi_label_required_p (NOTE_CFI (next)(((next)->u.fld[3]).rt_cfi));
2314 next = NEXT_INSN (next);
2315 }
2316 else if (active_insn_p (next)
2317 || (NOTE_P (next)(((enum rtx_code) (next)->code) == NOTE) && (NOTE_KIND (next)(((next)->u.fld[4]).rt_int)
2318 == NOTE_INSN_SWITCH_TEXT_SECTIONS)))
2319 break;
2320 else
2321 next = NEXT_INSN (next);
2322 if (required
13.1
'required' is false
13.1
'required' is false
)
14
Taking false branch
2323 {
2324 int num = dwarf2out_cfi_label_num;
2325 const char *label = dwarf2out_cfi_label ();
2326 dw_cfi_ref xcfi;
2327
2328 /* Set the location counter to the new label. */
2329 xcfi = new_cfi ();
2330 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
2331 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
2332 vec_safe_push (fde->dw_fde_cfi, xcfi);
2333
2334 rtx_note *tmp = emit_note_before (NOTE_INSN_CFI_LABEL, insn);
2335 NOTE_LABEL_NUMBER (tmp)(((tmp)->u.fld[3]).rt_int) = num;
2336 }
2337
2338 do
2339 {
2340 if (NOTE_P (insn)(((enum rtx_code) (insn)->code) == NOTE) && NOTE_KIND (insn)(((insn)->u.fld[4]).rt_int) == NOTE_INSN_CFI)
15
Taking true branch
2341 vec_safe_push (fde->dw_fde_cfi, NOTE_CFI (insn)(((insn)->u.fld[3]).rt_cfi));
16
Passing value via 1st parameter 'v'
17
Calling 'vec_safe_push<dw_cfi_node *, va_gc>'
2342 insn = NEXT_INSN (insn);
2343 }
2344 while (insn != next);
2345 }
2346 }
2347}
2348
2349static void dump_cfi_row (FILE *f, dw_cfi_row *row);
2350
2351/* If LABEL is the start of a trace, then initialize the state of that
2352 trace from CUR_TRACE and CUR_ROW. */
2353
2354static void
2355maybe_record_trace_start (rtx_insn *start, rtx_insn *origin)
2356{
2357 dw_trace_info *ti;
2358
2359 ti = get_trace_info (start);
2360 gcc_assert (ti != NULL)((void)(!(ti != nullptr) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2360, __FUNCTION__), 0 : 0))
;
2361
2362 if (dump_file)
2363 {
2364 fprintf (dump_file, " saw edge from trace %u to %u (via %s %d)\n",
2365 cur_trace->id, ti->id,
2366 (origin ? rtx_name[(int) GET_CODE (origin)((enum rtx_code) (origin)->code)] : "fallthru"),
2367 (origin ? INSN_UID (origin) : 0));
2368 }
2369
2370 poly_int64 args_size = cur_trace->end_true_args_size;
2371 if (ti->beg_row == NULLnullptr)
2372 {
2373 /* This is the first time we've encountered this trace. Propagate
2374 state across the edge and push the trace onto the work list. */
2375 ti->beg_row = copy_cfi_row (cur_row);
2376 ti->beg_true_args_size = args_size;
2377
2378 ti->cfa_store = cur_trace->cfa_store;
2379 ti->cfa_temp = cur_trace->cfa_temp;
2380 ti->regs_saved_in_regs = cur_trace->regs_saved_in_regs.copy ();
2381
2382 trace_work_list.safe_push (ti);
2383
2384 if (dump_file)
2385 fprintf (dump_file, "\tpush trace %u to worklist\n", ti->id);
2386 }
2387 else
2388 {
2389
2390 /* We ought to have the same state incoming to a given trace no
2391 matter how we arrive at the trace. Anything else means we've
2392 got some kind of optimization error. */
2393#if CHECKING_P1
2394 if (!cfi_row_equal_p (cur_row, ti->beg_row))
2395 {
2396 if (dump_file)
2397 {
2398 fprintf (dump_file, "Inconsistent CFI state!\n");
2399 fprintf (dump_file, "SHOULD have:\n");
2400 dump_cfi_row (dump_file, ti->beg_row);
2401 fprintf (dump_file, "DO have:\n");
2402 dump_cfi_row (dump_file, cur_row);
2403 }
2404
2405 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2405, __FUNCTION__))
;
2406 }
2407#endif
2408
2409 /* The args_size is allowed to conflict if it isn't actually used. */
2410 if (maybe_ne (ti->beg_true_args_size, args_size))
2411 ti->args_size_undefined = true;
2412 }
2413}
2414
2415/* Similarly, but handle the args_size and CFA reset across EH
2416 and non-local goto edges. */
2417
2418static void
2419maybe_record_trace_start_abnormal (rtx_insn *start, rtx_insn *origin)
2420{
2421 poly_int64 save_args_size, delta;
2422 dw_cfa_location save_cfa;
2423
2424 save_args_size = cur_trace->end_true_args_size;
2425 if (known_eq (save_args_size, 0)(!maybe_ne (save_args_size, 0)))
2426 {
2427 maybe_record_trace_start (start, origin);
2428 return;
2429 }
2430
2431 delta = -save_args_size;
2432 cur_trace->end_true_args_size = 0;
2433
2434 save_cfa = cur_row->cfa;
2435 if (cur_row->cfa.reg == dw_stack_pointer_regnum)
2436 {
2437 /* Convert a change in args_size (always a positive in the
2438 direction of stack growth) to a change in stack pointer. */
2439 if (!STACK_GROWS_DOWNWARD1)
2440 delta = -delta;
2441
2442 cur_row->cfa.offset += delta;
2443 }
2444
2445 maybe_record_trace_start (start, origin);
2446
2447 cur_trace->end_true_args_size = save_args_size;
2448 cur_row->cfa = save_cfa;
2449}
2450
2451/* Propagate CUR_TRACE state to the destinations implied by INSN. */
2452/* ??? Sadly, this is in large part a duplicate of make_edges. */
2453
2454static void
2455create_trace_edges (rtx_insn *insn)
2456{
2457 rtx tmp;
2458 int i, n;
2459
2460 if (JUMP_P (insn)(((enum rtx_code) (insn)->code) == JUMP_INSN))
2461 {
2462 rtx_jump_table_data *table;
2463
2464 if (find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX(rtx) 0))
2465 return;
2466
2467 if (tablejump_p (insn, NULLnullptr, &table))
2468 {
2469 rtvec vec = table->get_labels ();
2470
2471 n = GET_NUM_ELEM (vec)((vec)->num_elem);
2472 for (i = 0; i < n; ++i)
2473 {
2474 rtx_insn *lab = as_a <rtx_insn *> (XEXP (RTVEC_ELT (vec, i), 0)(((((vec)->elem[i]))->u.fld[0]).rt_rtx));
2475 maybe_record_trace_start (lab, insn);
2476 }
2477
2478 /* Handle casesi dispatch insns. */
2479 if ((tmp = tablejump_casesi_pattern (insn)) != NULL_RTX(rtx) 0)
2480 {
2481 rtx_insn * lab = label_ref_label (XEXP (SET_SRC (tmp), 2)((((((tmp)->u.fld[1]).rt_rtx))->u.fld[2]).rt_rtx));
2482 maybe_record_trace_start (lab, insn);
2483 }
2484 }
2485 else if (computed_jump_p (insn))
2486 {
2487 rtx_insn *temp;
2488 unsigned int i;
2489 FOR_EACH_VEC_SAFE_ELT (forced_labels, i, temp)for (i = 0; vec_safe_iterate ((((&x_rtl)->expr.x_forced_labels
)), (i), &(temp)); ++(i))
2490 maybe_record_trace_start (temp, insn);
2491 }
2492 else if (returnjump_p (insn))
2493 ;
2494 else if ((tmp = extract_asm_operands (PATTERN (insn))) != NULLnullptr)
2495 {
2496 n = ASM_OPERANDS_LABEL_LENGTH (tmp)(((((tmp)->u.fld[5]).rt_rtvec))->num_elem);
2497 for (i = 0; i < n; ++i)
2498 {
2499 rtx_insn *lab =
2500 as_a <rtx_insn *> (XEXP (ASM_OPERANDS_LABEL (tmp, i), 0)((((((((tmp)->u.fld[5]).rt_rtvec))->elem[i]))->u.fld
[0]).rt_rtx)
);
2501 maybe_record_trace_start (lab, insn);
2502 }
2503 }
2504 else
2505 {
2506 rtx_insn *lab = JUMP_LABEL_AS_INSN (insn);
2507 gcc_assert (lab != NULL)((void)(!(lab != nullptr) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2507, __FUNCTION__), 0 : 0))
;
2508 maybe_record_trace_start (lab, insn);
2509 }
2510 }
2511 else if (CALL_P (insn)(((enum rtx_code) (insn)->code) == CALL_INSN))
2512 {
2513 /* Sibling calls don't have edges inside this function. */
2514 if (SIBLING_CALL_P (insn)(__extension__ ({ __typeof ((insn)) const _rtx = ((insn)); if
(((enum rtx_code) (_rtx)->code) != CALL_INSN) rtl_check_failed_flag
("SIBLING_CALL_P", _rtx, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2514, __FUNCTION__); _rtx; })->jump)
)
2515 return;
2516
2517 /* Process non-local goto edges. */
2518 if (can_nonlocal_goto (insn))
2519 for (rtx_insn_list *lab = nonlocal_goto_handler_labels((&x_rtl)->x_nonlocal_goto_handler_labels);
2520 lab;
2521 lab = lab->next ())
2522 maybe_record_trace_start_abnormal (lab->insn (), insn);
2523 }
2524 else if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
2525 {
2526 int i, n = seq->len ();
2527 for (i = 0; i < n; ++i)
2528 create_trace_edges (seq->insn (i));
2529 return;
2530 }
2531
2532 /* Process EH edges. */
2533 if (CALL_P (insn)(((enum rtx_code) (insn)->code) == CALL_INSN) || cfun(cfun + 0)->can_throw_non_call_exceptions)
2534 {
2535 eh_landing_pad lp = get_eh_landing_pad_from_rtx (insn);
2536 if (lp)
2537 maybe_record_trace_start_abnormal (lp->landing_pad, insn);
2538 }
2539}
2540
2541/* A subroutine of scan_trace. Do what needs to be done "after" INSN. */
2542
2543static void
2544scan_insn_after (rtx_insn *insn)
2545{
2546 if (RTX_FRAME_RELATED_P (insn)(__extension__ ({ __typeof ((insn)) const _rtx = ((insn)); if
(((enum rtx_code) (_rtx)->code) != DEBUG_INSN && (
(enum rtx_code) (_rtx)->code) != INSN && ((enum rtx_code
) (_rtx)->code) != CALL_INSN && ((enum rtx_code) (
_rtx)->code) != JUMP_INSN && ((enum rtx_code) (_rtx
)->code) != BARRIER && ((enum rtx_code) (_rtx)->
code) != SET) rtl_check_failed_flag ("RTX_FRAME_RELATED_P",_rtx
, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2546, __FUNCTION__); _rtx; })->frame_related)
)
2547 dwarf2out_frame_debug (insn);
2548 notice_args_size (insn);
2549}
2550
2551/* Scan the trace beginning at INSN and create the CFI notes for the
2552 instructions therein. */
2553
2554static void
2555scan_trace (dw_trace_info *trace, bool entry)
2556{
2557 rtx_insn *prev, *insn = trace->head;
2558 dw_cfa_location this_cfa;
2559
2560 if (dump_file)
2561 fprintf (dump_file, "Processing trace %u : start at %s %d\n",
2562 trace->id, rtx_name[(int) GET_CODE (insn)((enum rtx_code) (insn)->code)],
2563 INSN_UID (insn));
2564
2565 trace->end_row = copy_cfi_row (trace->beg_row);
2566 trace->end_true_args_size = trace->beg_true_args_size;
2567
2568 cur_trace = trace;
2569 cur_row = trace->end_row;
2570
2571 this_cfa = cur_row->cfa;
2572 cur_cfa = &this_cfa;
2573
2574 /* If the current function starts with a non-standard incoming frame
2575 sp offset, emit a note before the first instruction. */
2576 if (entry
2577 && DEFAULT_INCOMING_FRAME_SP_OFFSET(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 8 : 4)
!= INCOMING_FRAME_SP_OFFSET((cfun + 0)->machine->func_type == TYPE_EXCEPTION ? 2 *
(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 8 : 4) : (((global_options.x_ix86_isa_flags & (1UL <<
1)) != 0) ? 8 : 4))
)
2578 {
2579 add_cfi_insn = insn;
2580 gcc_assert (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_DELETED)((void)(!((((enum rtx_code) (insn)->code) == NOTE) &&
(((insn)->u.fld[4]).rt_int) == NOTE_INSN_DELETED) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2580, __FUNCTION__), 0 : 0))
;
2581 this_cfa.offset = INCOMING_FRAME_SP_OFFSET((cfun + 0)->machine->func_type == TYPE_EXCEPTION ? 2 *
(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 8 : 4) : (((global_options.x_ix86_isa_flags & (1UL <<
1)) != 0) ? 8 : 4))
;
2582 def_cfa_1 (&this_cfa);
2583 }
2584
2585 for (prev = insn, insn = NEXT_INSN (insn);
2586 insn;
2587 prev = insn, insn = NEXT_INSN (insn))
2588 {
2589 rtx_insn *control;
2590
2591 /* Do everything that happens "before" the insn. */
2592 add_cfi_insn = prev;
2593
2594 /* Notice the end of a trace. */
2595 if (BARRIER_P (insn)(((enum rtx_code) (insn)->code) == BARRIER))
2596 {
2597 /* Don't bother saving the unneeded queued registers at all. */
2598 queued_reg_saves.truncate (0);
2599 break;
2600 }
2601 if (save_point_p (insn))
2602 {
2603 /* Propagate across fallthru edges. */
2604 dwarf2out_flush_queued_reg_saves ();
2605 maybe_record_trace_start (insn, NULLnullptr);
2606 break;
2607 }
2608
2609 if (DEBUG_INSN_P (insn)(((enum rtx_code) (insn)->code) == DEBUG_INSN) || !inside_basic_block_p (insn))
2610 continue;
2611
2612 /* Handle all changes to the row state. Sequences require special
2613 handling for the positioning of the notes. */
2614 if (rtx_sequence *pat = dyn_cast <rtx_sequence *> (PATTERN (insn)))
2615 {
2616 rtx_insn *elt;
2617 int i, n = pat->len ();
2618
2619 control = pat->insn (0);
2620 if (can_throw_internal (control))
2621 notice_eh_throw (control);
2622 dwarf2out_flush_queued_reg_saves ();
2623
2624 if (JUMP_P (control)(((enum rtx_code) (control)->code) == JUMP_INSN) && INSN_ANNULLED_BRANCH_P (control)(__extension__ ({ __typeof ((control)) const _rtx = ((control
)); if (((enum rtx_code) (_rtx)->code) != JUMP_INSN) rtl_check_failed_flag
("INSN_ANNULLED_BRANCH_P", _rtx, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2624, __FUNCTION__); _rtx; })->unchanging)
)
2625 {
2626 /* ??? Hopefully multiple delay slots are not annulled. */
2627 gcc_assert (n == 2)((void)(!(n == 2) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2627, __FUNCTION__), 0 : 0))
;
2628 gcc_assert (!RTX_FRAME_RELATED_P (control))((void)(!(!(__extension__ ({ __typeof ((control)) const _rtx =
((control)); if (((enum rtx_code) (_rtx)->code) != DEBUG_INSN
&& ((enum rtx_code) (_rtx)->code) != INSN &&
((enum rtx_code) (_rtx)->code) != CALL_INSN && ((
enum rtx_code) (_rtx)->code) != JUMP_INSN && ((enum
rtx_code) (_rtx)->code) != BARRIER && ((enum rtx_code
) (_rtx)->code) != SET) rtl_check_failed_flag ("RTX_FRAME_RELATED_P"
,_rtx, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2628, __FUNCTION__); _rtx; })->frame_related)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2628, __FUNCTION__), 0 : 0))
;
2629 gcc_assert (!find_reg_note (control, REG_ARGS_SIZE, NULL))((void)(!(!find_reg_note (control, REG_ARGS_SIZE, nullptr)) ?
fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2629, __FUNCTION__), 0 : 0))
;
2630
2631 elt = pat->insn (1);
2632
2633 if (INSN_FROM_TARGET_P (elt)(__extension__ ({ __typeof ((elt)) const _rtx = ((elt)); if (
((enum rtx_code) (_rtx)->code) != INSN && ((enum rtx_code
) (_rtx)->code) != JUMP_INSN && ((enum rtx_code) (
_rtx)->code) != CALL_INSN) rtl_check_failed_flag ("INSN_FROM_TARGET_P"
, _rtx, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2633, __FUNCTION__); _rtx; })->in_struct)
)
2634 {
2635 cfi_vec save_row_reg_save;
2636
2637 /* If ELT is an instruction from target of an annulled
2638 branch, the effects are for the target only and so
2639 the args_size and CFA along the current path
2640 shouldn't change. */
2641 add_cfi_insn = NULLnullptr;
2642 poly_int64 restore_args_size = cur_trace->end_true_args_size;
2643 cur_cfa = &cur_row->cfa;
2644 save_row_reg_save = vec_safe_copy (cur_row->reg_save);
2645
2646 scan_insn_after (elt);
2647
2648 /* ??? Should we instead save the entire row state? */
2649 gcc_assert (!queued_reg_saves.length ())((void)(!(!queued_reg_saves.length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2649, __FUNCTION__), 0 : 0))
;
2650
2651 create_trace_edges (control);
2652
2653 cur_trace->end_true_args_size = restore_args_size;
2654 cur_row->cfa = this_cfa;
2655 cur_row->reg_save = save_row_reg_save;
2656 cur_cfa = &this_cfa;
2657 }
2658 else
2659 {
2660 /* If ELT is a annulled branch-taken instruction (i.e.
2661 executed only when branch is not taken), the args_size
2662 and CFA should not change through the jump. */
2663 create_trace_edges (control);
2664
2665 /* Update and continue with the trace. */
2666 add_cfi_insn = insn;
2667 scan_insn_after (elt);
2668 def_cfa_1 (&this_cfa);
2669 }
2670 continue;
2671 }
2672
2673 /* The insns in the delay slot should all be considered to happen
2674 "before" a call insn. Consider a call with a stack pointer
2675 adjustment in the delay slot. The backtrace from the callee
2676 should include the sp adjustment. Unfortunately, that leaves
2677 us with an unavoidable unwinding error exactly at the call insn
2678 itself. For jump insns we'd prefer to avoid this error by
2679 placing the notes after the sequence. */
2680 if (JUMP_P (control)(((enum rtx_code) (control)->code) == JUMP_INSN))
2681 add_cfi_insn = insn;
2682
2683 for (i = 1; i < n; ++i)
2684 {
2685 elt = pat->insn (i);
2686 scan_insn_after (elt);
2687 }
2688
2689 /* Make sure any register saves are visible at the jump target. */
2690 dwarf2out_flush_queued_reg_saves ();
2691 any_cfis_emitted = false;
2692
2693 /* However, if there is some adjustment on the call itself, e.g.
2694 a call_pop, that action should be considered to happen after
2695 the call returns. */
2696 add_cfi_insn = insn;
2697 scan_insn_after (control);
2698 }
2699 else
2700 {
2701 /* Flush data before calls and jumps, and of course if necessary. */
2702 if (can_throw_internal (insn))
2703 {
2704 notice_eh_throw (insn);
2705 dwarf2out_flush_queued_reg_saves ();
2706 }
2707 else if (!NONJUMP_INSN_P (insn)(((enum rtx_code) (insn)->code) == INSN)
2708 || clobbers_queued_reg_save (insn)
2709 || find_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULLnullptr))
2710 dwarf2out_flush_queued_reg_saves ();
2711 any_cfis_emitted = false;
2712
2713 add_cfi_insn = insn;
2714 scan_insn_after (insn);
2715 control = insn;
2716 }
2717
2718 /* Between frame-related-p and args_size we might have otherwise
2719 emitted two cfa adjustments. Do it now. */
2720 def_cfa_1 (&this_cfa);
2721
2722 /* Minimize the number of advances by emitting the entire queue
2723 once anything is emitted. */
2724 if (any_cfis_emitted
2725 || find_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULLnullptr))
2726 dwarf2out_flush_queued_reg_saves ();
2727
2728 /* Note that a test for control_flow_insn_p does exactly the
2729 same tests as are done to actually create the edges. So
2730 always call the routine and let it not create edges for
2731 non-control-flow insns. */
2732 create_trace_edges (control);
2733 }
2734
2735 add_cfi_insn = NULLnullptr;
2736 cur_row = NULLnullptr;
2737 cur_trace = NULLnullptr;
2738 cur_cfa = NULLnullptr;
2739}
2740
2741/* Scan the function and create the initial set of CFI notes. */
2742
2743static void
2744create_cfi_notes (void)
2745{
2746 dw_trace_info *ti;
2747
2748 gcc_checking_assert (!queued_reg_saves.exists ())((void)(!(!queued_reg_saves.exists ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2748, __FUNCTION__), 0 : 0))
;
2749 gcc_checking_assert (!trace_work_list.exists ())((void)(!(!trace_work_list.exists ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2749, __FUNCTION__), 0 : 0))
;
2750
2751 /* Always begin at the entry trace. */
2752 ti = &trace_info[0];
2753 scan_trace (ti, true);
2754
2755 while (!trace_work_list.is_empty ())
2756 {
2757 ti = trace_work_list.pop ();
2758 scan_trace (ti, false);
2759 }
2760
2761 queued_reg_saves.release ();
2762 trace_work_list.release ();
2763}
2764
2765/* Return the insn before the first NOTE_INSN_CFI after START. */
2766
2767static rtx_insn *
2768before_next_cfi_note (rtx_insn *start)
2769{
2770 rtx_insn *prev = start;
2771 while (start)
2772 {
2773 if (NOTE_P (start)(((enum rtx_code) (start)->code) == NOTE) && NOTE_KIND (start)(((start)->u.fld[4]).rt_int) == NOTE_INSN_CFI)
2774 return prev;
2775 prev = start;
2776 start = NEXT_INSN (start);
2777 }
2778 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2778, __FUNCTION__))
;
2779}
2780
2781/* Insert CFI notes between traces to properly change state between them. */
2782
2783static void
2784connect_traces (void)
2785{
2786 unsigned i, n;
2787 dw_trace_info *prev_ti, *ti;
2788
2789 /* ??? Ideally, we should have both queued and processed every trace.
2790 However the current representation of constant pools on various targets
2791 is indistinguishable from unreachable code. Assume for the moment that
2792 we can simply skip over such traces. */
2793 /* ??? Consider creating a DATA_INSN rtx code to indicate that
2794 these are not "real" instructions, and should not be considered.
2795 This could be generically useful for tablejump data as well. */
2796 /* Remove all unprocessed traces from the list. */
2797 unsigned ix, ix2;
2798 VEC_ORDERED_REMOVE_IF_FROM_TO (trace_info, ix, ix2, ti, 1,{ ((void)(!((trace_info.length ()) <= (trace_info).length (
)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2799, __FUNCTION__), 0 : 0)); for (ix = ix2 = (1); ix < (
trace_info.length ()); ++ix) { ti = &(trace_info)[ix]; bool
remove_p = (ti->beg_row == nullptr); if (remove_p) continue
; if (ix != ix2) (trace_info)[ix2] = (trace_info)[ix]; ix2++;
} if (ix - ix2 > 0) (trace_info).block_remove (ix2, ix - ix2
); }
2799 trace_info.length (), ti->beg_row == NULL){ ((void)(!((trace_info.length ()) <= (trace_info).length (
)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2799, __FUNCTION__), 0 : 0)); for (ix = ix2 = (1); ix < (
trace_info.length ()); ++ix) { ti = &(trace_info)[ix]; bool
remove_p = (ti->beg_row == nullptr); if (remove_p) continue
; if (ix != ix2) (trace_info)[ix2] = (trace_info)[ix]; ix2++;
} if (ix - ix2 > 0) (trace_info).block_remove (ix2, ix - ix2
); }
;
2800 FOR_EACH_VEC_ELT (trace_info, ix, ti)for (ix = 0; (trace_info).iterate ((ix), &(ti)); ++(ix))
2801 gcc_assert (ti->end_row != NULL)((void)(!(ti->end_row != nullptr) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2801, __FUNCTION__), 0 : 0))
;
2802
2803 /* Work from the end back to the beginning. This lets us easily insert
2804 remember/restore_state notes in the correct order wrt other notes. */
2805 n = trace_info.length ();
2806 prev_ti = &trace_info[n - 1];
2807 for (i = n - 1; i > 0; --i)
2808 {
2809 dw_cfi_row *old_row;
2810
2811 ti = prev_ti;
2812 prev_ti = &trace_info[i - 1];
2813
2814 add_cfi_insn = ti->head;
2815
2816 /* In dwarf2out_switch_text_section, we'll begin a new FDE
2817 for the portion of the function in the alternate text
2818 section. The row state at the very beginning of that
2819 new FDE will be exactly the row state from the CIE. */
2820 if (ti->switch_sections)
2821 old_row = cie_cfi_row;
2822 else
2823 {
2824 old_row = prev_ti->end_row;
2825 /* If there's no change from the previous end state, fine. */
2826 if (cfi_row_equal_p (old_row, ti->beg_row))
2827 ;
2828 /* Otherwise check for the common case of sharing state with
2829 the beginning of an epilogue, but not the end. Insert
2830 remember/restore opcodes in that case. */
2831 else if (cfi_row_equal_p (prev_ti->beg_row, ti->beg_row))
2832 {
2833 dw_cfi_ref cfi;
2834
2835 /* Note that if we blindly insert the remember at the
2836 start of the trace, we can wind up increasing the
2837 size of the unwind info due to extra advance opcodes.
2838 Instead, put the remember immediately before the next
2839 state change. We know there must be one, because the
2840 state at the beginning and head of the trace differ. */
2841 add_cfi_insn = before_next_cfi_note (prev_ti->head);
2842 cfi = new_cfi ();
2843 cfi->dw_cfi_opc = DW_CFA_remember_state;
2844 add_cfi (cfi);
2845
2846 add_cfi_insn = ti->head;
2847 cfi = new_cfi ();
2848 cfi->dw_cfi_opc = DW_CFA_restore_state;
2849 add_cfi (cfi);
2850
2851 old_row = prev_ti->beg_row;
2852 }
2853 /* Otherwise, we'll simply change state from the previous end. */
2854 }
2855
2856 change_cfi_row (old_row, ti->beg_row);
2857
2858 if (dump_file && add_cfi_insn != ti->head)
2859 {
2860 rtx_insn *note;
2861
2862 fprintf (dump_file, "Fixup between trace %u and %u:\n",
2863 prev_ti->id, ti->id);
2864
2865 note = ti->head;
2866 do
2867 {
2868 note = NEXT_INSN (note);
2869 gcc_assert (NOTE_P (note) && NOTE_KIND (note) == NOTE_INSN_CFI)((void)(!((((enum rtx_code) (note)->code) == NOTE) &&
(((note)->u.fld[4]).rt_int) == NOTE_INSN_CFI) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2869, __FUNCTION__), 0 : 0))
;
2870 output_cfi_directive (dump_file, NOTE_CFI (note)(((note)->u.fld[3]).rt_cfi));
2871 }
2872 while (note != add_cfi_insn);
2873 }
2874 }
2875
2876 /* Connect args_size between traces that have can_throw_internal insns. */
2877 if (cfun(cfun + 0)->eh->lp_array)
2878 {
2879 poly_int64 prev_args_size = 0;
2880
2881 for (i = 0; i < n; ++i)
2882 {
2883 ti = &trace_info[i];
2884
2885 if (ti->switch_sections)
2886 prev_args_size = 0;
2887
2888 if (ti->eh_head == NULLnullptr)
2889 continue;
2890
2891 /* We require either the incoming args_size values to match or the
2892 presence of an insn setting it before the first EH insn. */
2893 gcc_assert (!ti->args_size_undefined || ti->args_size_defined_for_eh)((void)(!(!ti->args_size_undefined || ti->args_size_defined_for_eh
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2893, __FUNCTION__), 0 : 0))
;
2894
2895 /* In the latter case, we force the creation of a CFI note. */
2896 if (ti->args_size_undefined
2897 || maybe_ne (ti->beg_delay_args_size, prev_args_size))
2898 {
2899 /* ??? Search back to previous CFI note. */
2900 add_cfi_insn = PREV_INSN (ti->eh_head);
2901 add_cfi_args_size (ti->beg_delay_args_size);
2902 }
2903
2904 prev_args_size = ti->end_delay_args_size;
2905 }
2906 }
2907}
2908
2909/* Set up the pseudo-cfg of instruction traces, as described at the
2910 block comment at the top of the file. */
2911
2912static void
2913create_pseudo_cfg (void)
2914{
2915 bool saw_barrier, switch_sections;
2916 dw_trace_info ti;
2917 rtx_insn *insn;
2918 unsigned i;
2919
2920 /* The first trace begins at the start of the function,
2921 and begins with the CIE row state. */
2922 trace_info.create (16);
2923 memset (&ti, 0, sizeof (ti));
2924 ti.head = get_insns ();
2925 ti.beg_row = cie_cfi_row;
2926 ti.cfa_store = cie_cfi_row->cfa;
2927 ti.cfa_temp.reg = INVALID_REGNUM(~(unsigned int) 0);
2928 trace_info.quick_push (ti);
2929
2930 if (cie_return_save)
2931 ti.regs_saved_in_regs.safe_push (*cie_return_save);
2932
2933 /* Walk all the insns, collecting start of trace locations. */
2934 saw_barrier = false;
2935 switch_sections = false;
2936 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2937 {
2938 if (BARRIER_P (insn)(((enum rtx_code) (insn)->code) == BARRIER))
2939 saw_barrier = true;
2940 else if (NOTE_P (insn)(((enum rtx_code) (insn)->code) == NOTE)
2941 && NOTE_KIND (insn)(((insn)->u.fld[4]).rt_int) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
2942 {
2943 /* We should have just seen a barrier. */
2944 gcc_assert (saw_barrier)((void)(!(saw_barrier) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2944, __FUNCTION__), 0 : 0))
;
2945 switch_sections = true;
2946 }
2947 /* Watch out for save_point notes between basic blocks.
2948 In particular, a note after a barrier. Do not record these,
2949 delaying trace creation until the label. */
2950 else if (save_point_p (insn)
2951 && (LABEL_P (insn)(((enum rtx_code) (insn)->code) == CODE_LABEL) || !saw_barrier))
2952 {
2953 memset (&ti, 0, sizeof (ti));
2954 ti.head = insn;
2955 ti.switch_sections = switch_sections;
2956 ti.id = trace_info.length ();
2957 trace_info.safe_push (ti);
2958
2959 saw_barrier = false;
2960 switch_sections = false;
2961 }
2962 }
2963
2964 /* Create the trace index after we've finished building trace_info,
2965 avoiding stale pointer problems due to reallocation. */
2966 trace_index
2967 = new hash_table<trace_info_hasher> (trace_info.length ());
2968 dw_trace_info *tp;
2969 FOR_EACH_VEC_ELT (trace_info, i, tp)for (i = 0; (trace_info).iterate ((i), &(tp)); ++(i))
2970 {
2971 dw_trace_info **slot;
2972
2973 if (dump_file)
2974 fprintf (dump_file, "Creating trace %u : start at %s %d%s\n", tp->id,
2975 rtx_name[(int) GET_CODE (tp->head)((enum rtx_code) (tp->head)->code)], INSN_UID (tp->head),
2976 tp->switch_sections ? " (section switch)" : "");
2977
2978 slot = trace_index->find_slot_with_hash (tp, INSN_UID (tp->head), INSERT);
2979 gcc_assert (*slot == NULL)((void)(!(*slot == nullptr) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 2979, __FUNCTION__), 0 : 0))
;
2980 *slot = tp;
2981 }
2982}
2983
2984/* Record the initial position of the return address. RTL is
2985 INCOMING_RETURN_ADDR_RTX. */
2986
2987static void
2988initial_return_save (rtx rtl)
2989{
2990 unsigned int reg = INVALID_REGNUM(~(unsigned int) 0);
2991 poly_int64 offset = 0;
2992
2993 switch (GET_CODE (rtl)((enum rtx_code) (rtl)->code))
2994 {
2995 case REG:
2996 /* RA is in a register. */
2997 reg = dwf_regno (rtl);
2998 break;
2999
3000 case MEM:
3001 /* RA is on the stack. */
3002 rtl = XEXP (rtl, 0)(((rtl)->u.fld[0]).rt_rtx);
3003 switch (GET_CODE (rtl)((enum rtx_code) (rtl)->code))
3004 {
3005 case REG:
3006 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM)((void)(!((rhs_regno(rtl)) == 7) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3006, __FUNCTION__), 0 : 0))
;
3007 offset = 0;
3008 break;
3009
3010 case PLUS:
3011 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM)((void)(!((rhs_regno((((rtl)->u.fld[0]).rt_rtx))) == 7) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3011, __FUNCTION__), 0 : 0))
;
3012 offset = rtx_to_poly_int64 (XEXP (rtl, 1)(((rtl)->u.fld[1]).rt_rtx));
3013 break;
3014
3015 case MINUS:
3016 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM)((void)(!((rhs_regno((((rtl)->u.fld[0]).rt_rtx))) == 7) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3016, __FUNCTION__), 0 : 0))
;
3017 offset = -rtx_to_poly_int64 (XEXP (rtl, 1)(((rtl)->u.fld[1]).rt_rtx));
3018 break;
3019
3020 default:
3021 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3021, __FUNCTION__))
;
3022 }
3023
3024 break;
3025
3026 case PLUS:
3027 /* The return address is at some offset from any value we can
3028 actually load. For instance, on the SPARC it is in %i7+8. Just
3029 ignore the offset for now; it doesn't matter for unwinding frames. */
3030 gcc_assert (CONST_INT_P (XEXP (rtl, 1)))((void)(!((((enum rtx_code) ((((rtl)->u.fld[1]).rt_rtx))->
code) == CONST_INT)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3030, __FUNCTION__), 0 : 0))
;
3031 initial_return_save (XEXP (rtl, 0)(((rtl)->u.fld[0]).rt_rtx));
3032 return;
3033
3034 default:
3035 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3035, __FUNCTION__))
;
3036 }
3037
3038 if (reg != DWARF_FRAME_RETURN_COLUMN(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 16 : 8)
)
3039 {
3040 if (reg != INVALID_REGNUM(~(unsigned int) 0))
3041 record_reg_saved_in_reg (rtl, pc_rtx);
3042 reg_save (DWARF_FRAME_RETURN_COLUMN(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 16 : 8)
, reg, offset - cur_row->cfa.offset);
3043 }
3044}
3045
3046static void
3047create_cie_data (void)
3048{
3049 dw_cfa_location loc;
3050 dw_trace_info cie_trace;
3051
3052 dw_stack_pointer_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? dbx64_register_map[7] : svr4_dbx_register_map[7])
;
3053
3054 memset (&cie_trace, 0, sizeof (cie_trace));
3055 cur_trace = &cie_trace;
3056
3057 add_cfi_vec = &cie_cfi_vec;
3058 cie_cfi_row = cur_row = new_cfi_row ();
3059
3060 /* On entry, the Canonical Frame Address is at SP. */
3061 memset (&loc, 0, sizeof (loc));
3062 loc.reg = dw_stack_pointer_regnum;
3063 /* create_cie_data is called just once per TU, and when using .cfi_startproc
3064 is even done by the assembler rather than the compiler. If the target
3065 has different incoming frame sp offsets depending on what kind of
3066 function it is, use a single constant offset for the target and
3067 if needed, adjust before the first instruction in insn stream. */
3068 loc.offset = DEFAULT_INCOMING_FRAME_SP_OFFSET(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? 8 : 4)
;
3069 def_cfa_1 (&loc);
3070
3071 if (targetm.debug_unwind_info () == UI_DWARF2
3072 || targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
3073 {
3074 initial_return_save (INCOMING_RETURN_ADDR_RTXgen_rtx_MEM ((global_options.x_ix86_pmode == PMODE_DI ? (scalar_int_mode
((scalar_int_mode::from_int) E_DImode)) : (scalar_int_mode (
(scalar_int_mode::from_int) E_SImode))), ((this_target_rtl->
x_global_rtl)[GR_STACK_POINTER]))
);
3075
3076 /* For a few targets, we have the return address incoming into a
3077 register, but choose a different return column. This will result
3078 in a DW_CFA_register for the return, and an entry in
3079 regs_saved_in_regs to match. If the target later stores that
3080 return address register to the stack, we want to be able to emit
3081 the DW_CFA_offset against the return column, not the intermediate
3082 save register. Save the contents of regs_saved_in_regs so that
3083 we can re-initialize it at the start of each function. */
3084 switch (cie_trace.regs_saved_in_regs.length ())
3085 {
3086 case 0:
3087 break;
3088 case 1:
3089 cie_return_save = ggc_alloc<reg_saved_in_data> ();
3090 *cie_return_save = cie_trace.regs_saved_in_regs[0];
3091 cie_trace.regs_saved_in_regs.release ();
3092 break;
3093 default:
3094 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3094, __FUNCTION__))
;
3095 }
3096 }
3097
3098 add_cfi_vec = NULLnullptr;
3099 cur_row = NULLnullptr;
3100 cur_trace = NULLnullptr;
3101}
3102
3103/* Annotate the function with NOTE_INSN_CFI notes to record the CFI
3104 state at each location within the function. These notes will be
3105 emitted during pass_final. */
3106
3107static unsigned int
3108execute_dwarf2_frame (void)
3109{
3110 /* Different HARD_FRAME_POINTER_REGNUM might coexist in the same file. */
3111 dw_frame_pointer_regnum = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)(((global_options.x_ix86_isa_flags & (1UL << 1)) !=
0) ? dbx64_register_map[6] : svr4_dbx_register_map[6])
;
2
Assuming the condition is false
3
'?' condition is false
3112
3113 /* The first time we're called, compute the incoming frame state. */
3114 if (cie_cfi_vec == NULLnullptr)
4
Assuming the condition is false
5
Taking false branch
3115 create_cie_data ();
3116
3117 dwarf2out_alloc_current_fde ();
3118
3119 create_pseudo_cfg ();
3120
3121 /* Do the work. */
3122 create_cfi_notes ();
3123 connect_traces ();
3124 add_cfis_to_fde ();
6
Calling 'add_cfis_to_fde'
3125
3126 /* Free all the data we allocated. */
3127 {
3128 size_t i;
3129 dw_trace_info *ti;
3130
3131 FOR_EACH_VEC_ELT (trace_info, i, ti)for (i = 0; (trace_info).iterate ((i), &(ti)); ++(i))
3132 ti->regs_saved_in_regs.release ();
3133 }
3134 trace_info.release ();
3135
3136 delete trace_index;
3137 trace_index = NULLnullptr;
3138
3139 return 0;
3140}
3141
3142/* Convert a DWARF call frame info. operation to its string name */
3143
3144static const char *
3145dwarf_cfi_name (unsigned int cfi_opc)
3146{
3147 const char *name = get_DW_CFA_name (cfi_opc);
3148
3149 if (name != NULLnullptr)
3150 return name;
3151
3152 return "DW_CFA_<unknown>";
3153}
3154
3155/* This routine will generate the correct assembly data for a location
3156 description based on a cfi entry with a complex address. */
3157
3158static void
3159output_cfa_loc (dw_cfi_ref cfi, int for_eh)
3160{
3161 dw_loc_descr_ref loc;
3162 unsigned long size;
3163
3164 if (cfi->dw_cfi_opc == DW_CFA_expression
3165 || cfi->dw_cfi_opc == DW_CFA_val_expression)
3166 {
3167 unsigned r =
3168 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3169 dw2_asm_output_data (1, r, NULLnullptr);
3170 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
3171 }
3172 else
3173 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3174
3175 /* Output the size of the block. */
3176 size = size_of_locs (loc);
3177 dw2_asm_output_data_uleb128 (size, NULLnullptr);
3178
3179 /* Now output the operations themselves. */
3180 output_loc_sequence (loc, for_eh);
3181}
3182
3183/* Similar, but used for .cfi_escape. */
3184
3185static void
3186output_cfa_loc_raw (dw_cfi_ref cfi)
3187{
3188 dw_loc_descr_ref loc;
3189 unsigned long size;
3190
3191 if (cfi->dw_cfi_opc == DW_CFA_expression
3192 || cfi->dw_cfi_opc == DW_CFA_val_expression)
3193 {
3194 unsigned r =
3195 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3196 fprintf (asm_out_file, "%#x,", r);
3197 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
3198 }
3199 else
3200 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3201
3202 /* Output the size of the block. */
3203 size = size_of_locs (loc);
3204 dw2_asm_output_data_uleb128_raw (size);
3205 fputc (',', asm_out_file);
3206
3207 /* Now output the operations themselves. */
3208 output_loc_sequence_raw (loc);
3209}
3210
3211/* Output a Call Frame Information opcode and its operand(s). */
3212
3213void
3214output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3215{
3216 unsigned long r;
3217 HOST_WIDE_INTlong off;
3218
3219 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3220 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3221 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3222 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX"%#" "l" "x",
3223 ((unsigned HOST_WIDE_INTlong)
3224 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3225 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3226 {
3227 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3228 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3229 "DW_CFA_offset, column %#lx", r);
3230 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3231 dw2_asm_output_data_uleb128 (off, NULLnullptr);
3232 }
3233 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3234 {
3235 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3236 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3237 "DW_CFA_restore, column %#lx", r);
3238 }
3239 else
3240 {
3241 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3242 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3243
3244 switch (cfi->dw_cfi_opc)
3245 {
3246 case DW_CFA_set_loc:
3247 if (for_eh)
3248 dw2_asm_output_encoded_addr_rtx (
3249 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0)asm_preferred_eh_data_format ((1), (0)),
3250 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr)gen_rtx_fmt_s0_stat ((SYMBOL_REF), (((global_options.x_ix86_pmode
== PMODE_DI ? (scalar_int_mode ((scalar_int_mode::from_int) E_DImode
)) : (scalar_int_mode ((scalar_int_mode::from_int) E_SImode))
))), ((cfi->dw_cfi_oprnd1.dw_cfi_addr)) )
,
3251 false, NULLnullptr);
3252 else
3253 dw2_asm_output_addr (DWARF2_ADDR_SIZE(((((global_options.x_ix86_isa_flags & (1UL << 58))
!= 0) ? 32 : ((8) * (((global_options.x_ix86_isa_flags &
(1UL << 1)) != 0) ? 8 : 4))) + (8) - 1) / (8))
,
3254 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULLnullptr);
3255 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3256 break;
3257
3258 case DW_CFA_advance_loc1:
3259 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3260 fde->dw_fde_current_label, NULLnullptr);
3261 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3262 break;
3263
3264 case DW_CFA_advance_loc2:
3265 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3266 fde->dw_fde_current_label, NULLnullptr);
3267 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3268 break;
3269
3270 case DW_CFA_advance_loc4:
3271 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3272 fde->dw_fde_current_label, NULLnullptr);
3273 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3274 break;
3275
3276 case DW_CFA_MIPS_advance_loc8:
3277 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3278 fde->dw_fde_current_label, NULLnullptr);
3279 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3280 break;
3281
3282 case DW_CFA_offset_extended:
3283 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3284 dw2_asm_output_data_uleb128 (r, NULLnullptr);
3285 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3286 dw2_asm_output_data_uleb128 (off, NULLnullptr);
3287 break;
3288
3289 case DW_CFA_def_cfa:
3290 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3291 dw2_asm_output_data_uleb128 (r, NULLnullptr);
3292 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULLnullptr);
3293 break;
3294
3295 case DW_CFA_offset_extended_sf:
3296 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3297 dw2_asm_output_data_uleb128 (r, NULLnullptr);
3298 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3299 dw2_asm_output_data_sleb128 (off, NULLnullptr);
3300 break;
3301
3302 case DW_CFA_def_cfa_sf:
3303 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3304 dw2_asm_output_data_uleb128 (r, NULLnullptr);
3305 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3306 dw2_asm_output_data_sleb128 (off, NULLnullptr);
3307 break;
3308
3309 case DW_CFA_restore_extended:
3310 case DW_CFA_undefined:
3311 case DW_CFA_same_value:
3312 case DW_CFA_def_cfa_register:
3313 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3314 dw2_asm_output_data_uleb128 (r, NULLnullptr);
3315 break;
3316
3317 case DW_CFA_register:
3318 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3319 dw2_asm_output_data_uleb128 (r, NULLnullptr);
3320 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh)(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3321 dw2_asm_output_data_uleb128 (r, NULLnullptr);
3322 break;
3323
3324 case DW_CFA_def_cfa_offset:
3325 case DW_CFA_GNU_args_size:
3326 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULLnullptr);
3327 break;
3328
3329 case DW_CFA_def_cfa_offset_sf:
3330 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3331 dw2_asm_output_data_sleb128 (off, NULLnullptr);
3332 break;
3333
3334 case DW_CFA_GNU_window_save:
3335 break;
3336
3337 case DW_CFA_def_cfa_expression:
3338 case DW_CFA_expression:
3339 case DW_CFA_val_expression:
3340 output_cfa_loc (cfi, for_eh);
3341 break;
3342
3343 case DW_CFA_GNU_negative_offset_extended:
3344 /* Obsoleted by DW_CFA_offset_extended_sf. */
3345 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3345, __FUNCTION__))
;
3346
3347 default:
3348 break;
3349 }
3350 }
3351}
3352
3353/* Similar, but do it via assembler directives instead. */
3354
3355void
3356output_cfi_directive (FILE *f, dw_cfi_ref cfi)
3357{
3358 unsigned long r, r2;
3359
3360 switch (cfi->dw_cfi_opc)
3361 {
3362 case DW_CFA_advance_loc:
3363 case DW_CFA_advance_loc1:
3364 case DW_CFA_advance_loc2:
3365 case DW_CFA_advance_loc4:
3366 case DW_CFA_MIPS_advance_loc8:
3367 case DW_CFA_set_loc:
3368 /* Should only be created in a code path not followed when emitting
3369 via directives. The assembler is going to take care of this for
3370 us. But this routines is also used for debugging dumps, so
3371 print something. */
3372 gcc_assert (f != asm_out_file)((void)(!(f != asm_out_file) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3372, __FUNCTION__), 0 : 0))
;
3373 fprintf (f, "\t.cfi_advance_loc\n");
3374 break;
3375
3376 case DW_CFA_offset:
3377 case DW_CFA_offset_extended:
3378 case DW_CFA_offset_extended_sf:
3379 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3380 fprintf (f, "\t.cfi_offset %lu, " HOST_WIDE_INT_PRINT_DEC"%" "l" "d""\n",
3381 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3382 break;
3383
3384 case DW_CFA_restore:
3385 case DW_CFA_restore_extended:
3386 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3387 fprintf (f, "\t.cfi_restore %lu\n", r);
3388 break;
3389
3390 case DW_CFA_undefined:
3391 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3392 fprintf (f, "\t.cfi_undefined %lu\n", r);
3393 break;
3394
3395 case DW_CFA_same_value:
3396 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3397 fprintf (f, "\t.cfi_same_value %lu\n", r);
3398 break;
3399
3400 case DW_CFA_def_cfa:
3401 case DW_CFA_def_cfa_sf:
3402 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3403 fprintf (f, "\t.cfi_def_cfa %lu, " HOST_WIDE_INT_PRINT_DEC"%" "l" "d""\n",
3404 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3405 break;
3406
3407 case DW_CFA_def_cfa_register:
3408 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3409 fprintf (f, "\t.cfi_def_cfa_register %lu\n", r);
3410 break;
3411
3412 case DW_CFA_register:
3413 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
3414 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1)(cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
3415 fprintf (f, "\t.cfi_register %lu, %lu\n", r, r2);
3416 break;
3417
3418 case DW_CFA_def_cfa_offset:
3419 case DW_CFA_def_cfa_offset_sf:
3420 fprintf (f, "\t.cfi_def_cfa_offset "
3421 HOST_WIDE_INT_PRINT_DEC"%" "l" "d""\n",
3422 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3423 break;
3424
3425 case DW_CFA_remember_state:
3426 fprintf (f, "\t.cfi_remember_state\n");
3427 break;
3428 case DW_CFA_restore_state:
3429 fprintf (f, "\t.cfi_restore_state\n");
3430 break;
3431
3432 case DW_CFA_GNU_args_size:
3433 if (f == asm_out_file)
3434 {
3435 fprintf (f, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3436 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3437 if (flag_debug_asmglobal_options.x_flag_debug_asm)
3438 fprintf (f, "\t%s args_size " HOST_WIDE_INT_PRINT_DEC"%" "l" "d",
3439 ASM_COMMENT_START"#", cfi->dw_cfi_oprnd1.dw_cfi_offset);
3440 fputc ('\n', f);
3441 }
3442 else
3443 {
3444 fprintf (f, "\t.cfi_GNU_args_size " HOST_WIDE_INT_PRINT_DEC"%" "l" "d" "\n",
3445 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3446 }
3447 break;
3448
3449 case DW_CFA_GNU_window_save:
3450 fprintf (f, "\t.cfi_window_save\n");
3451 break;
3452
3453 case DW_CFA_def_cfa_expression:
3454 case DW_CFA_expression:
3455 case DW_CFA_val_expression:
3456 if (f != asm_out_file)
3457 {
3458 fprintf (f, "\t.cfi_%scfa_%sexpression ...\n",
3459 cfi->dw_cfi_opc == DW_CFA_def_cfa_expression ? "def_" : "",
3460 cfi->dw_cfi_opc == DW_CFA_val_expression ? "val_" : "");
3461 break;
3462 }
3463 fprintf (f, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3464 output_cfa_loc_raw (cfi);
3465 fputc ('\n', f);
3466 break;
3467
3468 default:
3469 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/dwarf2cfi.c"
, 3469, __FUNCTION__))
;
3470 }
3471}
3472
3473void
3474dwarf2out_emit_cfi (dw_cfi_ref cfi)
3475{
3476 if (dwarf2out_do_cfi_asm ())
3477 output_cfi_directive (asm_out_file, cfi);
3478}
3479
3480static void
3481dump_cfi_row (FILE *f, dw_cfi_row *row)
3482{
3483 dw_cfi_ref cfi;
3484 unsigned i;
3485
3486 cfi = row->cfa_cfi;
3487 if (!cfi)
3488 {
3489 dw_cfa_location dummy;
3490 memset (&dummy, 0, sizeof (dummy));
3491 dummy.reg = INVALID_REGNUM(~(unsigned int) 0);
3492 cfi = def_cfa_0 (&dummy, &row->cfa);
3493 }
3494 output_cfi_directive (f, cfi);
3495
3496 FOR_EACH_VEC_SAFE_ELT (row->reg_save, i, cfi)for (i = 0; vec_safe_iterate ((row->reg_save), (i), &(
cfi)); ++(i))
3497 if (cfi)
3498 output_cfi_directive (f, cfi);
3499}
3500
3501void debug_cfi_row (dw_cfi_row *row);
3502
3503void
3504debug_cfi_row (dw_cfi_row *row)
3505{
3506 dump_cfi_row (stderrstderr, row);
3507}
3508
3509
3510/* Save the result of dwarf2out_do_frame across PCH.
3511 This variable is tri-state, with 0 unset, >0 true, <0 false. */
3512static GTY(()) signed char saved_do_cfi_asm = 0;
3513
3514/* Decide whether to emit EH frame unwind information for the current
3515 translation unit. */
3516
3517bool
3518dwarf2out_do_eh_frame (void)
3519{
3520 return
3521 (flag_unwind_tablesglobal_options.x_flag_unwind_tables || flag_exceptionsglobal_options.x_flag_exceptions)
3522 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2;
3523}
3524
3525/* Decide whether we want to emit frame unwind information for the current
3526 translation unit. */
3527
3528bool
3529dwarf2out_do_frame (void)
3530{
3531 /* We want to emit correct CFA location expressions or lists, so we
3532 have to return true if we're going to output debug info, even if
3533 we're not going to output frame or unwind info. */
3534 if (write_symbolsglobal_options.x_write_symbols == DWARF2_DEBUG || write_symbolsglobal_options.x_write_symbols == VMS_AND_DWARF2_DEBUG)
3535 return true;
3536
3537 if (saved_do_cfi_asm > 0)
3538 return true;
3539
3540 if (targetm.debug_unwind_info () == UI_DWARF2)
3541 return true;
3542
3543 if (dwarf2out_do_eh_frame ())
3544 return true;
3545
3546 return false;
3547}
3548
3549/* Decide whether to emit frame unwind via assembler directives. */
3550
3551bool
3552dwarf2out_do_cfi_asm (void)
3553{
3554 int enc;
3555
3556 if (saved_do_cfi_asm != 0)
3557 return saved_do_cfi_asm > 0;
3558
3559 /* Assume failure for a moment. */
3560 saved_do_cfi_asm = -1;
3561
3562 if (!flag_dwarf2_cfi_asmglobal_options.x_flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
3563 return false;
3564 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE1)
3565 return false;
3566
3567 /* Make sure the personality encoding is one the assembler can support.
3568 In particular, aligned addresses can't be handled. */
3569 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1)asm_preferred_eh_data_format ((2), (1));
3570 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel0x10)
3571 return false;
3572 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0)asm_preferred_eh_data_format ((0), (0));
3573 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel0x10)
3574 return false;
3575
3576 /* If we can't get the assembler to emit only .debug_frame, and we don't need
3577 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
3578 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE1 && !dwarf2out_do_eh_frame ())
3579 return false;
3580
3581 /* Success! */
3582 saved_do_cfi_asm = 1;
3583 return true;
3584}
3585
3586namespace {
3587
3588const pass_data pass_data_dwarf2_frame =
3589{
3590 RTL_PASS, /* type */
3591 "dwarf2", /* name */
3592 OPTGROUP_NONE, /* optinfo_flags */
3593 TV_FINAL, /* tv_id */
3594 0, /* properties_required */
3595 0, /* properties_provided */
3596 0, /* properties_destroyed */
3597 0, /* todo_flags_start */
3598 0, /* todo_flags_finish */
3599};
3600
3601class pass_dwarf2_frame : public rtl_opt_pass
3602{
3603public:
3604 pass_dwarf2_frame (gcc::context *ctxt)
3605 : rtl_opt_pass (pass_data_dwarf2_frame, ctxt)
3606 {}
3607
3608 /* opt_pass methods: */
3609 virtual bool gate (function *);
3610 virtual unsigned int execute (function *) { return execute_dwarf2_frame (); }
1
Calling 'execute_dwarf2_frame'
3611
3612}; // class pass_dwarf2_frame
3613
3614bool
3615pass_dwarf2_frame::gate (function *)
3616{
3617 /* Targets which still implement the prologue in assembler text
3618 cannot use the generic dwarf2 unwinding. */
3619 if (!targetm.have_prologue ())
3620 return false;
3621
3622 /* ??? What to do for UI_TARGET unwinding? They might be able to benefit
3623 from the optimized shrink-wrapping annotations that we will compute.
3624 For now, only produce the CFI notes for dwarf2. */
3625 return dwarf2out_do_frame ();
3626}
3627
3628} // anon namespace
3629
3630rtl_opt_pass *
3631make_pass_dwarf2_frame (gcc::context *ctxt)
3632{
3633 return new pass_dwarf2_frame (ctxt);
3634}
3635
3636#include "gt-dwarf2cfi.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
22.1
'v' is non-null
22.1
'v' is non-null
? &v->m_vecpfx : 0, reserve, exact);
23
'?' condition is true
368 if (!alloc)
24
Assuming 'alloc' is 0
25
Taking true branch
369 {
370 ::ggc_free (v);
371 v = NULLnullptr;
26
Null pointer value stored to field 'dw_fde_cfi'
372 return;
373 }
374
375 /* Calculate the amount of space we want. */
376 size_t size = vec<T, A, vl_embed>::embedded_size (alloc);
377
378 /* Ask the allocator how much space it will really give us. */
379 size = ::ggc_round_alloc_size (size);
380
381 /* Adjust the number of slots accordingly. */
382 size_t vec_offset = sizeof (vec_prefix);
383 size_t elt_size = sizeof (T);
384 alloc = (size - vec_offset) / elt_size;
385
386 /* And finally, recalculate the amount of space we ask for. */
387 size = vec_offset + alloc * elt_size;
388
389 unsigned nelem = v ? v->length () : 0;
390 v = static_cast <vec<T, A, vl_embed> *> (::ggc_realloc (v, size
391 PASS_MEM_STAT));
392 v->embedded_init (alloc, nelem);
393}
394
395
396/* Allocator type for GC vectors. This is for vectors of types
397 atomics w.r.t. collection, so allocation and deallocation is
398 completely inherited from va_gc. */
399struct va_gc_atomic : va_gc
400{
401};
402
403
404/* Generic vector template. Default values for A and L indicate the
405 most commonly used strategies.
406
407 FIXME - Ideally, they would all be vl_ptr to encourage using regular
408 instances for vectors, but the existing GTY machinery is limited
409 in that it can only deal with GC objects that are pointers
410 themselves.
411
412 This means that vector operations that need to deal with
413 potentially NULL pointers, must be provided as free
414 functions (see the vec_safe_* functions above). */
415template<typename T,
416 typename A = va_heap,
417 typename L = typename A::default_layout>
418struct GTY((user)) vec
419{
420};
421
422/* Allow C++11 range-based 'for' to work directly on vec<T>*. */
423template<typename T, typename A, typename L>
424T* begin (vec<T,A,L> *v) { return v ? v->begin () : nullptr; }
425template<typename T, typename A, typename L>
426T* end (vec<T,A,L> *v) { return v ? v->end () : nullptr; }
427template<typename T, typename A, typename L>
428const T* begin (const vec<T,A,L> *v) { return v ? v->begin () : nullptr; }
429template<typename T, typename A, typename L>
430const T* end (const vec<T,A,L> *v) { return v ? v->end () : nullptr; }
431
432/* Generic vec<> debug helpers.
433
434 These need to be instantiated for each vec<TYPE> used throughout
435 the compiler like this:
436
437 DEFINE_DEBUG_VEC (TYPE)
438
439 The reason we have a debug_helper() is because GDB can't
440 disambiguate a plain call to debug(some_vec), and it must be called
441 like debug<TYPE>(some_vec). */
442
443template<typename T>
444void
445debug_helper (vec<T> &ref)
446{
447 unsigned i;
448 for (i = 0; i < ref.length (); ++i)
449 {
450 fprintf (stderrstderr, "[%d] = ", i);
451 debug_slim (ref[i]);
452 fputc ('\n', stderrstderr);
453 }
454}
455
456/* We need a separate va_gc variant here because default template
457 argument for functions cannot be used in c++-98. Once this
458 restriction is removed, those variant should be folded with the
459 above debug_helper. */
460
461template<typename T>
462void
463debug_helper (vec<T, va_gc> &ref)
464{
465 unsigned i;
466 for (i = 0; i < ref.length (); ++i)
467 {
468 fprintf (stderrstderr, "[%d] = ", i);
469 debug_slim (ref[i]);
470 fputc ('\n', stderrstderr);
471 }
472}
473
474/* Macro to define debug(vec<T>) and debug(vec<T, va_gc>) helper
475 functions for a type T. */
476
477#define DEFINE_DEBUG_VEC(T)template void debug_helper (vec<T> &); template void
debug_helper (vec<T, va_gc> &); __attribute__ ((__used__
)) void debug (vec<T> &ref) { debug_helper <T>
(ref); } __attribute__ ((__used__)) void debug (vec<T>
*ptr) { if (ptr) debug (*ptr); else fprintf (stderr, "<nil>\n"
); } __attribute__ ((__used__)) void debug (vec<T, va_gc>
&ref) { debug_helper <T> (ref); } __attribute__ ((
__used__)) void debug (vec<T, va_gc> *ptr) { if (ptr) debug
(*ptr); else fprintf (stderr, "<nil>\n"); }
\
478 template void debug_helper (vec<T> &); \
479 template void debug_helper (vec<T, va_gc> &); \
480 /* Define the vec<T> debug functions. */ \
481 DEBUG_FUNCTION__attribute__ ((__used__)) void \
482 debug (vec<T> &ref) \
483 { \
484 debug_helper <T> (ref); \
485 } \
486 DEBUG_FUNCTION__attribute__ ((__used__)) void \
487 debug (vec<T> *ptr) \
488 { \
489 if (ptr) \
490 debug (*ptr); \
491 else \
492 fprintf (stderrstderr, "<nil>\n"); \
493 } \
494 /* Define the vec<T, va_gc> debug functions. */ \
495 DEBUG_FUNCTION__attribute__ ((__used__)) void \
496 debug (vec<T, va_gc> &ref) \
497 { \
498 debug_helper <T> (ref); \
499 } \
500 DEBUG_FUNCTION__attribute__ ((__used__)) void \
501 debug (vec<T, va_gc> *ptr) \
502 { \
503 if (ptr) \
504 debug (*ptr); \
505 else \
506 fprintf (stderrstderr, "<nil>\n"); \
507 }
508
509/* Default-construct N elements in DST. */
510
511template <typename T>
512inline void
513vec_default_construct (T *dst, unsigned n)
514{
515#ifdef BROKEN_VALUE_INITIALIZATION
516 /* Versions of GCC before 4.4 sometimes leave certain objects
517 uninitialized when value initialized, though if the type has
518 user defined default ctor, that ctor is invoked. As a workaround
519 perform clearing first and then the value initialization, which
520 fixes the case when value initialization doesn't initialize due to
521 the bugs and should initialize to all zeros, but still allows
522 vectors for types with user defined default ctor that initializes
523 some or all elements to non-zero. If T has no user defined
524 default ctor and some non-static data members have user defined
525 default ctors that initialize to non-zero the workaround will
526 still not work properly; in that case we just need to provide
527 user defined default ctor. */
528 memset (dst, '\0', sizeof (T) * n);
529#endif
530 for ( ; n; ++dst, --n)
531 ::new (static_cast<void*>(dst)) T ();
532}
533
534/* Copy-construct N elements in DST from *SRC. */
535
536template <typename T>
537inline void
538vec_copy_construct (T *dst, const T *src, unsigned n)
539{
540 for ( ; n; ++dst, ++src, --n)
541 ::new (static_cast<void*>(dst)) T (*src);
542}
543
544/* Type to provide NULL values for vec<T, A, L>. This is used to
545 provide nil initializers for vec instances. Since vec must be
546 a POD, we cannot have proper ctor/dtor for it. To initialize
547 a vec instance, you can assign it the value vNULL. This isn't
548 needed for file-scope and function-local static vectors, which
549 are zero-initialized by default. */
550struct vnull
551{
552 template <typename T, typename A, typename L>
553 CONSTEXPRconstexpr operator vec<T, A, L> () const { return vec<T, A, L>(); }
554};
555extern vnull vNULL;
556
557
558/* Embeddable vector. These vectors are suitable to be embedded
559 in other data structures so that they can be pre-allocated in a
560 contiguous memory block.
561
562 Embeddable vectors are implemented using the trailing array idiom,
563 thus they are not resizeable without changing the address of the
564 vector object itself. This means you cannot have variables or
565 fields of embeddable vector type -- always use a pointer to a
566 vector. The one exception is the final field of a structure, which
567 could be a vector type.
568
569 You will have to use the embedded_size & embedded_init calls to
570 create such objects, and they will not be resizeable (so the 'safe'
571 allocation variants are not available).
572
573 Properties:
574
575 - The whole vector and control data are allocated in a single
576 contiguous block. It uses the trailing-vector idiom, so
577 allocation must reserve enough space for all the elements
578 in the vector plus its control data.
579 - The vector cannot be re-allocated.
580 - The vector cannot grow nor shrink.
581 - No indirections needed for access/manipulation.
582 - It requires 2 words of storage (prior to vector allocation). */
583
584template<typename T, typename A>
585struct GTY((user)) vec<T, A, vl_embed>
586{
587public:
588 unsigned allocated (void) const { return m_vecpfx.m_alloc; }
589 unsigned length (void) const { return m_vecpfx.m_num; }
590 bool is_empty (void) const { return m_vecpfx.m_num == 0; }
591 T *address (void) { return m_vecdata; }
592 const T *address (void) const { return m_vecdata; }
593 T *begin () { return address (); }
594 const T *begin () const { return address (); }
595 T *end () { return address () + length (); }
596 const T *end () const { return address () + length (); }
597 const T &operator[] (unsigned) const;
598 T &operator[] (unsigned);
599 T &last (void);
600 bool space (unsigned) const;
601 bool iterate (unsigned, T *) const;
602 bool iterate (unsigned, T **) const;
603 vec *copy (ALONE_CXX_MEM_STAT_INFO) const;
604 void splice (const vec &);
605 void splice (const vec *src);
606 T *quick_push (const T &);
607 T &pop (void);
608 void truncate (unsigned);
609 void quick_insert (unsigned, const T &);
610 void ordered_remove (unsigned);
611 void unordered_remove (unsigned);
612 void block_remove (unsigned, unsigned);
613 void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *));
614 void sort (int (*) (const void *, const void *, void *), void *);
615 T *bsearch (const void *key, int (*compar)(const void *, const void *));
616 T *bsearch (const void *key,
617 int (*compar)(const void *, const void *, void *), void *);
618 unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
619 bool contains (const T &search) const;
620 static size_t embedded_size (unsigned);
621 void embedded_init (unsigned, unsigned = 0, unsigned = 0);
622 void quick_grow (unsigned len);
623 void quick_grow_cleared (unsigned len);
624
625 /* vec class can access our internal data and functions. */
626 template <typename, typename, typename> friend struct vec;
627
628 /* The allocator types also need access to our internals. */
629 friend struct va_gc;
630 friend struct va_gc_atomic;
631 friend struct va_heap;
632
633 /* FIXME - These fields should be private, but we need to cater to
634 compilers that have stricter notions of PODness for types. */
635 vec_prefix m_vecpfx;
636 T m_vecdata[1];
637};
638
639
640/* Convenience wrapper functions to use when dealing with pointers to
641 embedded vectors. Some functionality for these vectors must be
642 provided via free functions for these reasons:
643
644 1- The pointer may be NULL (e.g., before initial allocation).
645
646 2- When the vector needs to grow, it must be reallocated, so
647 the pointer will change its value.
648
649 Because of limitations with the current GC machinery, all vectors
650 in GC memory *must* be pointers. */
651
652
653/* If V contains no room for NELEMS elements, return false. Otherwise,
654 return true. */
655template<typename T, typename A>
656inline bool
657vec_safe_space (const vec<T, A, vl_embed> *v, unsigned nelems)
658{
659 return v ? v->space (nelems) : nelems == 0;
660}
661
662
663/* If V is NULL, return 0. Otherwise, return V->length(). */
664template<typename T, typename A>
665inline unsigned
666vec_safe_length (const vec<T, A, vl_embed> *v)
667{
668 return v ? v->length () : 0;
669}
670
671
672/* If V is NULL, return NULL. Otherwise, return V->address(). */
673template<typename T, typename A>
674inline T *
675vec_safe_address (vec<T, A, vl_embed> *v)
676{
677 return v ? v->address () : NULLnullptr;
678}
679
680
681/* If V is NULL, return true. Otherwise, return V->is_empty(). */
682template<typename T, typename A>
683inline bool
684vec_safe_is_empty (vec<T, A, vl_embed> *v)
685{
686 return v ? v->is_empty () : true;
687}
688
689/* If V does not have space for NELEMS elements, call
690 V->reserve(NELEMS, EXACT). */
691template<typename T, typename A>
692inline bool
693vec_safe_reserve (vec<T, A, vl_embed> *&v, unsigned nelems, bool exact = false
694 CXX_MEM_STAT_INFO)
695{
696 bool extend = nelems
18.1
'nelems' is 1
18.1
'nelems' is 1
? !vec_safe_space (v, nelems) : false;
19
'?' condition is true
20
Assuming the condition is true
697 if (extend
20.1
'extend' is true
20.1
'extend' is true
)
21
Taking true branch
698 A::reserve (v, nelems, exact PASS_MEM_STAT);
22
Calling 'va_gc::reserve'
27
Returning from 'va_gc::reserve'
699 return extend;
700}
701
702template<typename T, typename A>
703inline bool
704vec_safe_reserve_exact (vec<T, A, vl_embed> *&v, unsigned nelems
705 CXX_MEM_STAT_INFO)
706{
707 return vec_safe_reserve (v, nelems, true PASS_MEM_STAT);
708}
709
710
711/* Allocate GC memory for V with space for NELEMS slots. If NELEMS
712 is 0, V is initialized to NULL. */
713
714template<typename T, typename A>
715inline void
716vec_alloc (vec<T, A, vl_embed> *&v, unsigned nelems CXX_MEM_STAT_INFO)
717{
718 v = NULLnullptr;
719 vec_safe_reserve (v, nelems, false PASS_MEM_STAT);
720}
721
722
723/* Free the GC memory allocated by vector V and set it to NULL. */
724
725template<typename T, typename A>
726inline void
727vec_free (vec<T, A, vl_embed> *&v)
728{
729 A::release (v);
730}
731
732
733/* Grow V to length LEN. Allocate it, if necessary. */
734template<typename T, typename A>
735inline void
736vec_safe_grow (vec<T, A, vl_embed> *&v, unsigned len,
737 bool exact = false CXX_MEM_STAT_INFO)
738{
739 unsigned oldlen = vec_safe_length (v);
740 gcc_checking_assert (len >= oldlen)((void)(!(len >= oldlen) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 740, __FUNCTION__), 0 : 0))
;
741 vec_safe_reserve (v, len - oldlen, exact PASS_MEM_STAT);
742 v->quick_grow (len);
743}
744
745
746/* If V is NULL, allocate it. Call V->safe_grow_cleared(LEN). */
747template<typename T, typename A>
748inline void
749vec_safe_grow_cleared (vec<T, A, vl_embed> *&v, unsigned len,
750 bool exact = false CXX_MEM_STAT_INFO)
751{
752 unsigned oldlen = vec_safe_length (v);
753 vec_safe_grow (v, len, exact PASS_MEM_STAT);
754 vec_default_construct (v->address () + oldlen, len - oldlen);
755}
756
757
758/* Assume V is not NULL. */
759
760template<typename T>
761inline void
762vec_safe_grow_cleared (vec<T, va_heap, vl_ptr> *&v,
763 unsigned len, bool exact = false CXX_MEM_STAT_INFO)
764{
765 v->safe_grow_cleared (len, exact PASS_MEM_STAT);
766}
767
768/* If V does not have space for NELEMS elements, call
769 V->reserve(NELEMS, EXACT). */
770
771template<typename T>
772inline bool
773vec_safe_reserve (vec<T, va_heap, vl_ptr> *&v, unsigned nelems, bool exact = false
774 CXX_MEM_STAT_INFO)
775{
776 return v->reserve (nelems, exact);
777}
778
779
780/* If V is NULL return false, otherwise return V->iterate(IX, PTR). */
781template<typename T, typename A>
782inline bool
783vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T **ptr)
784{
785 if (v)
786 return v->iterate (ix, ptr);
787 else
788 {
789 *ptr = 0;
790 return false;
791 }
792}
793
794template<typename T, typename A>
795inline bool
796vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T *ptr)
797{
798 if (v)
799 return v->iterate (ix, ptr);
800 else
801 {
802 *ptr = 0;
803 return false;
804 }
805}
806
807
808/* If V has no room for one more element, reallocate it. Then call
809 V->quick_push(OBJ). */
810template<typename T, typename A>
811inline T *
812vec_safe_push (vec<T, A, vl_embed> *&v, const T &obj CXX_MEM_STAT_INFO)
813{
814 vec_safe_reserve (v, 1, false PASS_MEM_STAT);
18
Calling 'vec_safe_reserve<dw_cfi_node *, va_gc>'
28
Returning from 'vec_safe_reserve<dw_cfi_node *, va_gc>'
815 return v->quick_push (obj);
29
Called C++ object pointer is null
816}
817
818
819/* if V has no room for one more element, reallocate it. Then call
820 V->quick_insert(IX, OBJ). */
821template<typename T, typename A>
822inline void
823vec_safe_insert (vec<T, A, vl_embed> *&v, unsigned ix, const T &obj
824 CXX_MEM_STAT_INFO)
825{
826 vec_safe_reserve (v, 1, false PASS_MEM_STAT);
827 v->quick_insert (ix, obj);
828}
829
830
831/* If V is NULL, do nothing. Otherwise, call V->truncate(SIZE). */
832template<typename T, typename A>
833inline void
834vec_safe_truncate (vec<T, A, vl_embed> *v, unsigned size)
835{
836 if (v)
837 v->truncate (size);
838}
839
840
841/* If SRC is not NULL, return a pointer to a copy of it. */
842template<typename T, typename A>
843inline vec<T, A, vl_embed> *
844vec_safe_copy (vec<T, A, vl_embed> *src CXX_MEM_STAT_INFO)
845{
846 return src ? src->copy (ALONE_PASS_MEM_STAT) : NULLnullptr;
847}
848
849/* Copy the elements from SRC to the end of DST as if by memcpy.
850 Reallocate DST, if necessary. */
851template<typename T, typename A>
852inline void
853vec_safe_splice (vec<T, A, vl_embed> *&dst, const vec<T, A, vl_embed> *src
854 CXX_MEM_STAT_INFO)
855{
856 unsigned src_len = vec_safe_length (src);
857 if (src_len)
858 {
859 vec_safe_reserve_exact (dst, vec_safe_length (dst) + src_len
860 PASS_MEM_STAT);
861 dst->splice (*src);
862 }
863}
864
865/* Return true if SEARCH is an element of V. Note that this is O(N) in the
866 size of the vector and so should be used with care. */
867
868template<typename T, typename A>
869inline bool
870vec_safe_contains (vec<T, A, vl_embed> *v, const T &search)
871{
872 return v ? v->contains (search) : false;
873}
874
875/* Index into vector. Return the IX'th element. IX must be in the
876 domain of the vector. */
877
878template<typename T, typename A>
879inline const T &
880vec<T, A, vl_embed>::operator[] (unsigned ix) const
881{
882 gcc_checking_assert (ix < m_vecpfx.m_num)((void)(!(ix < m_vecpfx.m_num) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 882, __FUNCTION__), 0 : 0))
;
883 return m_vecdata[ix];
884}
885
886template<typename T, typename A>
887inline T &
888vec<T, A, vl_embed>::operator[] (unsigned ix)
889{
890 gcc_checking_assert (ix < m_vecpfx.m_num)((void)(!(ix < m_vecpfx.m_num) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 890, __FUNCTION__), 0 : 0))
;
891 return m_vecdata[ix];
892}
893
894
895/* Get the final element of the vector, which must not be empty. */
896
897template<typename T, typename A>
898inline T &
899vec<T, A, vl_embed>::last (void)
900{
901 gcc_checking_assert (m_vecpfx.m_num > 0)((void)(!(m_vecpfx.m_num > 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 901, __FUNCTION__), 0 : 0))
;
902 return (*this)[m_vecpfx.m_num - 1];
903}
904
905
906/* If this vector has space for NELEMS additional entries, return
907 true. You usually only need to use this if you are doing your
908 own vector reallocation, for instance on an embedded vector. This
909 returns true in exactly the same circumstances that vec::reserve
910 will. */
911
912template<typename T, typename A>
913inline bool
914vec<T, A, vl_embed>::space (unsigned nelems) const
915{
916 return m_vecpfx.m_alloc - m_vecpfx.m_num >= nelems;
917}
918
919
920/* Return iteration condition and update PTR to point to the IX'th
921 element of this vector. Use this to iterate over the elements of a
922 vector as follows,
923
924 for (ix = 0; vec<T, A>::iterate (v, ix, &ptr); ix++)
925 continue; */
926
927template<typename T, typename A>
928inline bool
929vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const
930{
931 if (ix < m_vecpfx.m_num)
932 {
933 *ptr = m_vecdata[ix];
934 return true;
935 }
936 else
937 {
938 *ptr = 0;
939 return false;
940 }
941}
942
943
944/* Return iteration condition and update *PTR to point to the
945 IX'th element of this vector. Use this to iterate over the
946 elements of a vector as follows,
947
948 for (ix = 0; v->iterate (ix, &ptr); ix++)
949 continue;
950
951 This variant is for vectors of objects. */
952
953template<typename T, typename A>
954inline bool
955vec<T, A, vl_embed>::iterate (unsigned ix, T **ptr) const
956{
957 if (ix < m_vecpfx.m_num)
958 {
959 *ptr = CONST_CAST (T *, &m_vecdata[ix])(const_cast<T *> ((&m_vecdata[ix])));
960 return true;
961 }
962 else
963 {
964 *ptr = 0;
965 return false;
966 }
967}
968
969
970/* Return a pointer to a copy of this vector. */
971
972template<typename T, typename A>
973inline vec<T, A, vl_embed> *
974vec<T, A, vl_embed>::copy (ALONE_MEM_STAT_DECLvoid) const
975{
976 vec<T, A, vl_embed> *new_vec = NULLnullptr;
977 unsigned len = length ();
978 if (len)
979 {
980 vec_alloc (new_vec, len PASS_MEM_STAT);
981 new_vec->embedded_init (len, len);
982 vec_copy_construct (new_vec->address (), m_vecdata, len);
983 }
984 return new_vec;
985}
986
987
988/* Copy the elements from SRC to the end of this vector as if by memcpy.
989 The vector must have sufficient headroom available. */
990
991template<typename T, typename A>
992inline void
993vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> &src)
994{
995 unsigned len = src.length ();
996 if (len)
997 {
998 gcc_checking_assert (space (len))((void)(!(space (len)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 998, __FUNCTION__), 0 : 0))
;
999 vec_copy_construct (end (), src.address (), len);
1000 m_vecpfx.m_num += len;
1001 }
1002}
1003
1004template<typename T, typename A>
1005inline void
1006vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> *src)
1007{
1008 if (src)
1009 splice (*src);
1010}
1011
1012
1013/* Push OBJ (a new element) onto the end of the vector. There must be
1014 sufficient space in the vector. Return a pointer to the slot
1015 where OBJ was inserted. */
1016
1017template<typename T, typename A>
1018inline T *
1019vec<T, A, vl_embed>::quick_push (const T &obj)
1020{
1021 gcc_checking_assert (space (1))((void)(!(space (1)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1021, __FUNCTION__), 0 : 0))
;
1022 T *slot = &m_vecdata[m_vecpfx.m_num++];
1023 *slot = obj;
1024 return slot;
1025}
1026
1027
1028/* Pop and return the last element off the end of the vector. */
1029
1030template<typename T, typename A>
1031inline T &
1032vec<T, A, vl_embed>::pop (void)
1033{
1034 gcc_checking_assert (length () > 0)((void)(!(length () > 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1034, __FUNCTION__), 0 : 0))
;
1035 return m_vecdata[--m_vecpfx.m_num];
1036}
1037
1038
1039/* Set the length of the vector to SIZE. The new length must be less
1040 than or equal to the current length. This is an O(1) operation. */
1041
1042template<typename T, typename A>
1043inline void
1044vec<T, A, vl_embed>::truncate (unsigned size)
1045{
1046 gcc_checking_assert (length () >= size)((void)(!(length () >= size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1046, __FUNCTION__), 0 : 0))
;
1047 m_vecpfx.m_num = size;
1048}
1049
1050
1051/* Insert an element, OBJ, at the IXth position of this vector. There
1052 must be sufficient space. */
1053
1054template<typename T, typename A>
1055inline void
1056vec<T, A, vl_embed>::quick_insert (unsigned ix, const T &obj)
1057{
1058 gcc_checking_assert (length () < allocated ())((void)(!(length () < allocated ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1058, __FUNCTION__), 0 : 0))
;
1059 gcc_checking_assert (ix <= length ())((void)(!(ix <= length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1059, __FUNCTION__), 0 : 0))
;
1060 T *slot = &m_vecdata[ix];
1061 memmove (slot + 1, slot, (m_vecpfx.m_num++ - ix) * sizeof (T));
1062 *slot = obj;
1063}
1064
1065
1066/* Remove an element from the IXth position of this vector. Ordering of
1067 remaining elements is preserved. This is an O(N) operation due to
1068 memmove. */
1069
1070template<typename T, typename A>
1071inline void
1072vec<T, A, vl_embed>::ordered_remove (unsigned ix)
1073{
1074 gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1074, __FUNCTION__), 0 : 0))
;
1075 T *slot = &m_vecdata[ix];
1076 memmove (slot, slot + 1, (--m_vecpfx.m_num - ix) * sizeof (T));
1077}
1078
1079
1080/* Remove elements in [START, END) from VEC for which COND holds. Ordering of
1081 remaining elements is preserved. This is an O(N) operation. */
1082
1083#define VEC_ORDERED_REMOVE_IF_FROM_TO(vec, read_index, write_index, \{ ((void)(!((end) <= (vec).length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1084, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (start); read_index < (end); ++read_index) { elem_ptr =
&(vec)[read_index]; bool remove_p = (cond); if (remove_p
) continue; if (read_index != write_index) (vec)[write_index]
= (vec)[read_index]; write_index++; } if (read_index - write_index
> 0) (vec).block_remove (write_index, read_index - write_index
); }
1084 elem_ptr, start, end, cond){ ((void)(!((end) <= (vec).length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1084, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (start); read_index < (end); ++read_index) { elem_ptr =
&(vec)[read_index]; bool remove_p = (cond); if (remove_p
) continue; if (read_index != write_index) (vec)[write_index]
= (vec)[read_index]; write_index++; } if (read_index - write_index
> 0) (vec).block_remove (write_index, read_index - write_index
); }
\
1085 { \
1086 gcc_assert ((end) <= (vec).length ())((void)(!((end) <= (vec).length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1086, __FUNCTION__), 0 : 0))
; \
1087 for (read_index = write_index = (start); read_index < (end); \
1088 ++read_index) \
1089 { \
1090 elem_ptr = &(vec)[read_index]; \
1091 bool remove_p = (cond); \
1092 if (remove_p) \
1093 continue; \
1094 \
1095 if (read_index != write_index) \
1096 (vec)[write_index] = (vec)[read_index]; \
1097 \
1098 write_index++; \
1099 } \
1100 \
1101 if (read_index - write_index > 0) \
1102 (vec).block_remove (write_index, read_index - write_index); \
1103 }
1104
1105
1106/* Remove elements from VEC for which COND holds. Ordering of remaining
1107 elements is preserved. This is an O(N) operation. */
1108
1109#define VEC_ORDERED_REMOVE_IF(vec, read_index, write_index, elem_ptr, \{ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1110, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
1110 cond){ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1110, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
\
1111 VEC_ORDERED_REMOVE_IF_FROM_TO ((vec), read_index, write_index, \{ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1112, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
1112 elem_ptr, 0, (vec).length (), (cond)){ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1112, __FUNCTION__), 0 : 0)); for (read_index = write_index
= (0); read_index < ((vec).length ()); ++read_index) { elem_ptr
= &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p
) continue; if (read_index != write_index) ((vec))[write_index
] = ((vec))[read_index]; write_index++; } if (read_index - write_index
> 0) ((vec)).block_remove (write_index, read_index - write_index
); }
1113
1114/* Remove an element from the IXth position of this vector. Ordering of
1115 remaining elements is destroyed. This is an O(1) operation. */
1116
1117template<typename T, typename A>
1118inline void
1119vec<T, A, vl_embed>::unordered_remove (unsigned ix)
1120{
1121 gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1121, __FUNCTION__), 0 : 0))
;
1122 m_vecdata[ix] = m_vecdata[--m_vecpfx.m_num];
1123}
1124
1125
1126/* Remove LEN elements starting at the IXth. Ordering is retained.
1127 This is an O(N) operation due to memmove. */
1128
1129template<typename T, typename A>
1130inline void
1131vec<T, A, vl_embed>::block_remove (unsigned ix, unsigned len)
1132{
1133 gcc_checking_assert (ix + len <= length ())((void)(!(ix + len <= length ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1133, __FUNCTION__), 0 : 0))
;
1134 T *slot = &m_vecdata[ix];
1135 m_vecpfx.m_num -= len;
1136 memmove (slot, slot + len, (m_vecpfx.m_num - ix) * sizeof (T));
1137}
1138
1139
1140/* Sort the contents of this vector with qsort. CMP is the comparison
1141 function to pass to qsort. */
1142
1143template<typename T, typename A>
1144inline void
1145vec<T, A, vl_embed>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *))
1146{
1147 if (length () > 1)
1148 gcc_qsort (address (), length (), sizeof (T), cmp);
1149}
1150
1151/* Sort the contents of this vector with qsort. CMP is the comparison
1152 function to pass to qsort. */
1153
1154template<typename T, typename A>
1155inline void
1156vec<T, A, vl_embed>::sort (int (*cmp) (const void *, const void *, void *),
1157 void *data)
1158{
1159 if (length () > 1)
1160 gcc_sort_r (address (), length (), sizeof (T), cmp, data);
1161}
1162
1163
1164/* Search the contents of the sorted vector with a binary search.
1165 CMP is the comparison function to pass to bsearch. */
1166
1167template<typename T, typename A>
1168inline T *
1169vec<T, A, vl_embed>::bsearch (const void *key,
1170 int (*compar) (const void *, const void *))
1171{
1172 const void *base = this->address ();
1173 size_t nmemb = this->length ();
1174 size_t size = sizeof (T);
1175 /* The following is a copy of glibc stdlib-bsearch.h. */
1176 size_t l, u, idx;
1177 const void *p;
1178 int comparison;
1179
1180 l = 0;
1181 u = nmemb;
1182 while (l < u)
1183 {
1184 idx = (l + u) / 2;
1185 p = (const void *) (((const char *) base) + (idx * size));
1186 comparison = (*compar) (key, p);
1187 if (comparison < 0)
1188 u = idx;
1189 else if (comparison > 0)
1190 l = idx + 1;
1191 else
1192 return (T *)const_cast<void *>(p);
1193 }
1194
1195 return NULLnullptr;
1196}
1197
1198/* Search the contents of the sorted vector with a binary search.
1199 CMP is the comparison function to pass to bsearch. */
1200
1201template<typename T, typename A>
1202inline T *
1203vec<T, A, vl_embed>::bsearch (const void *key,
1204 int (*compar) (const void *, const void *,
1205 void *), void *data)
1206{
1207 const void *base = this->address ();
1208 size_t nmemb = this->length ();
1209 size_t size = sizeof (T);
1210 /* The following is a copy of glibc stdlib-bsearch.h. */
1211 size_t l, u, idx;
1212 const void *p;
1213 int comparison;
1214
1215 l = 0;
1216 u = nmemb;
1217 while (l < u)
1218 {
1219 idx = (l + u) / 2;
1220 p = (const void *) (((const char *) base) + (idx * size));
1221 comparison = (*compar) (key, p, data);
1222 if (comparison < 0)
1223 u = idx;
1224 else if (comparison > 0)
1225 l = idx + 1;
1226 else
1227 return (T *)const_cast<void *>(p);
1228 }
1229
1230 return NULLnullptr;
1231}
1232
1233/* Return true if SEARCH is an element of V. Note that this is O(N) in the
1234 size of the vector and so should be used with care. */
1235
1236template<typename T, typename A>
1237inline bool
1238vec<T, A, vl_embed>::contains (const T &search) const
1239{
1240 unsigned int len = length ();
1241 for (unsigned int i = 0; i < len; i++)
1242 if ((*this)[i] == search)
1243 return true;
1244
1245 return false;
1246}
1247
1248/* Find and return the first position in which OBJ could be inserted
1249 without changing the ordering of this vector. LESSTHAN is a
1250 function that returns true if the first argument is strictly less
1251 than the second. */
1252
1253template<typename T, typename A>
1254unsigned
1255vec<T, A, vl_embed>::lower_bound (T obj, bool (*lessthan)(const T &, const T &))
1256 const
1257{
1258 unsigned int len = length ();
1259 unsigned int half, middle;
1260 unsigned int first = 0;
1261 while (len > 0)
1262 {
1263 half = len / 2;
1264 middle = first;
1265 middle += half;
1266 T middle_elem = (*this)[middle];
1267 if (lessthan (middle_elem, obj))
1268 {
1269 first = middle;
1270 ++first;
1271 len = len - half - 1;
1272 }
1273 else
1274 len = half;
1275 }
1276 return first;
1277}
1278
1279
1280/* Return the number of bytes needed to embed an instance of an
1281 embeddable vec inside another data structure.
1282
1283 Use these methods to determine the required size and initialization
1284 of a vector V of type T embedded within another structure (as the
1285 final member):
1286
1287 size_t vec<T, A, vl_embed>::embedded_size (unsigned alloc);
1288 void v->embedded_init (unsigned alloc, unsigned num);
1289
1290 These allow the caller to perform the memory allocation. */
1291
1292template<typename T, typename A>
1293inline size_t
1294vec<T, A, vl_embed>::embedded_size (unsigned alloc)
1295{
1296 struct alignas (T) U { char data[sizeof (T)]; };
1297 typedef vec<U, A, vl_embed> vec_embedded;
1298 typedef typename std::conditional<std::is_standard_layout<T>::value,
1299 vec, vec_embedded>::type vec_stdlayout;
1300 static_assert (sizeof (vec_stdlayout) == sizeof (vec), "");
1301 static_assert (alignof (vec_stdlayout) == alignof (vec), "");
1302 return offsetof (vec_stdlayout, m_vecdata)__builtin_offsetof(vec_stdlayout, m_vecdata) + alloc * sizeof (T);
1303}
1304
1305
1306/* Initialize the vector to contain room for ALLOC elements and
1307 NUM active elements. */
1308
1309template<typename T, typename A>
1310inline void
1311vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num, unsigned aut)
1312{
1313 m_vecpfx.m_alloc = alloc;
1314 m_vecpfx.m_using_auto_storage = aut;
1315 m_vecpfx.m_num = num;
1316}
1317
1318
1319/* Grow the vector to a specific length. LEN must be as long or longer than
1320 the current length. The new elements are uninitialized. */
1321
1322template<typename T, typename A>
1323inline void
1324vec<T, A, vl_embed>::quick_grow (unsigned len)
1325{
1326 gcc_checking_assert (length () <= len && len <= m_vecpfx.m_alloc)((void)(!(length () <= len && len <= m_vecpfx.m_alloc
) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1326, __FUNCTION__), 0 : 0))
;
1327 m_vecpfx.m_num = len;
1328}
1329
1330
1331/* Grow the vector to a specific length. LEN must be as long or longer than
1332 the current length. The new elements are initialized to zero. */
1333
1334template<typename T, typename A>
1335inline void
1336vec<T, A, vl_embed>::quick_grow_cleared (unsigned len)
1337{
1338 unsigned oldlen = length ();
1339 size_t growby = len - oldlen;
1340 quick_grow (len);
1341 if (growby != 0)
1342 vec_default_construct (address () + oldlen, growby);
1343}
1344
1345/* Garbage collection support for vec<T, A, vl_embed>. */
1346
1347template<typename T>
1348void
1349gt_ggc_mx (vec<T, va_gc> *v)
1350{
1351 extern void gt_ggc_mx (T &);
1352 for (unsigned i = 0; i < v->length (); i++)
1353 gt_ggc_mx ((*v)[i]);
1354}
1355
1356template<typename T>
1357void
1358gt_ggc_mx (vec<T, va_gc_atomic, vl_embed> *v ATTRIBUTE_UNUSED__attribute__ ((__unused__)))
1359{
1360 /* Nothing to do. Vectors of atomic types wrt GC do not need to
1361 be traversed. */
1362}
1363
1364
1365/* PCH support for vec<T, A, vl_embed>. */
1366
1367template<typename T, typename A>
1368void
1369gt_pch_nx (vec<T, A, vl_embed> *v)
1370{
1371 extern void gt_pch_nx (T &);
1372 for (unsigned i = 0; i < v->length (); i++)
1373 gt_pch_nx ((*v)[i]);
1374}
1375
1376template<typename T, typename A>
1377void
1378gt_pch_nx (vec<T *, A, vl_embed> *v, gt_pointer_operator op, void *cookie)
1379{
1380 for (unsigned i = 0; i < v->length (); i++)
1381 op (&((*v)[i]), cookie);
1382}
1383
1384template<typename T, typename A>
1385void
1386gt_pch_nx (vec<T, A, vl_embed> *v, gt_pointer_operator op, void *cookie)
1387{
1388 extern void gt_pch_nx (T *, gt_pointer_operator, void *);
1389 for (unsigned i = 0; i < v->length (); i++)
1390 gt_pch_nx (&((*v)[i]), op, cookie);
1391}
1392
1393
1394/* Space efficient vector. These vectors can grow dynamically and are
1395 allocated together with their control data. They are suited to be
1396 included in data structures. Prior to initial allocation, they
1397 only take a single word of storage.
1398
1399 These vectors are implemented as a pointer to an embeddable vector.
1400 The semantics allow for this pointer to be NULL to represent empty
1401 vectors. This way, empty vectors occupy minimal space in the
1402 structure containing them.
1403
1404 Properties:
1405
1406 - The whole vector and control data are allocated in a single
1407 contiguous block.
1408 - The whole vector may be re-allocated.
1409 - Vector data may grow and shrink.
1410 - Access and manipulation requires a pointer test and
1411 indirection.
1412 - It requires 1 word of storage (prior to vector allocation).
1413
1414
1415 Limitations:
1416
1417 These vectors must be PODs because they are stored in unions.
1418 (http://en.wikipedia.org/wiki/Plain_old_data_structures).
1419 As long as we use C++03, we cannot have constructors nor
1420 destructors in classes that are stored in unions. */
1421
1422template<typename T>
1423struct vec<T, va_heap, vl_ptr>
1424{
1425public:
1426 /* Memory allocation and deallocation for the embedded vector.
1427 Needed because we cannot have proper ctors/dtors defined. */
1428 void create (unsigned nelems CXX_MEM_STAT_INFO);
1429 void release (void);
1430
1431 /* Vector operations. */
1432 bool exists (void) const
1433 { return m_vec != NULLnullptr; }
1434
1435 bool is_empty (void) const
1436 { return m_vec ? m_vec->is_empty () : true; }
1437
1438 unsigned length (void) const
1439 { return m_vec ? m_vec->length () : 0; }
1440
1441 T *address (void)
1442 { return m_vec ? m_vec->m_vecdata : NULLnullptr; }
1443
1444 const T *address (void) const
1445 { return m_vec ? m_vec->m_vecdata : NULLnullptr; }
1446
1447 T *begin () { return address (); }
1448 const T *begin () const { return address (); }
1449 T *end () { return begin () + length (); }
1450 const T *end () const { return begin () + length (); }
1451 const T &operator[] (unsigned ix) const
1452 { return (*m_vec)[ix]; }
1453
1454 bool operator!=(const vec &other) const
1455 { return !(*this == other); }
1456
1457 bool operator==(const vec &other) const
1458 { return address () == other.address (); }
1459
1460 T &operator[] (unsigned ix)
1461 { return (*m_vec)[ix]; }
1462
1463 T &last (void)
1464 { return m_vec->last (); }
1465
1466 bool space (int nelems) const
1467 { return m_vec ? m_vec->space (nelems) : nelems == 0; }
1468
1469 bool iterate (unsigned ix, T *p) const;
1470 bool iterate (unsigned ix, T **p) const;
1471 vec copy (ALONE_CXX_MEM_STAT_INFO) const;
1472 bool reserve (unsigned, bool = false CXX_MEM_STAT_INFO);
1473 bool reserve_exact (unsigned CXX_MEM_STAT_INFO);
1474 void splice (const vec &);
1475 void safe_splice (const vec & CXX_MEM_STAT_INFO);
1476 T *quick_push (const T &);
1477 T *safe_push (const T &CXX_MEM_STAT_INFO);
1478 T &pop (void);
1479 void truncate (unsigned);
1480 void safe_grow (unsigned, bool = false CXX_MEM_STAT_INFO);
1481 void safe_grow_cleared (unsigned, bool = false CXX_MEM_STAT_INFO);
1482 void quick_grow (unsigned);
1483 void quick_grow_cleared (unsigned);
1484 void quick_insert (unsigned, const T &);
1485 void safe_insert (unsigned, const T & CXX_MEM_STAT_INFO);
1486 void ordered_remove (unsigned);
1487 void unordered_remove (unsigned);
1488 void block_remove (unsigned, unsigned);
1489 void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *));
1490 void sort (int (*) (const void *, const void *, void *), void *);
1491 T *bsearch (const void *key, int (*compar)(const void *, const void *));
1492 T *bsearch (const void *key,
1493 int (*compar)(const void *, const void *, void *), void *);
1494 unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
1495 bool contains (const T &search) const;
1496 void reverse (void);
1497
1498 bool using_auto_storage () const;
1499
1500 /* FIXME - This field should be private, but we need to cater to
1501 compilers that have stricter notions of PODness for types. */
1502 vec<T, va_heap, vl_embed> *m_vec;
1503};
1504
1505
1506/* auto_vec is a subclass of vec that automatically manages creating and
1507 releasing the internal vector. If N is non zero then it has N elements of
1508 internal storage. The default is no internal storage, and you probably only
1509 want to ask for internal storage for vectors on the stack because if the
1510 size of the vector is larger than the internal storage that space is wasted.
1511 */
1512template<typename T, size_t N = 0>
1513class auto_vec : public vec<T, va_heap>
1514{
1515public:
1516 auto_vec ()
1517 {
1518 m_auto.embedded_init (MAX (N, 2)((N) > (2) ? (N) : (2)), 0, 1);
1519 this->m_vec = &m_auto;
1520 }
1521
1522 auto_vec (size_t s)
1523 {
1524 if (s > N)
1525 {
1526 this->create (s);
1527 return;
1528 }
1529
1530 m_auto.embedded_init (MAX (N, 2)((N) > (2) ? (N) : (2)), 0, 1);
1531 this->m_vec = &m_auto;
1532 }
1533
1534 ~auto_vec ()
1535 {
1536 this->release ();
1537 }
1538
1539private:
1540 vec<T, va_heap, vl_embed> m_auto;
1541 T m_data[MAX (N - 1, 1)((N - 1) > (1) ? (N - 1) : (1))];
1542};
1543
1544/* auto_vec is a sub class of vec whose storage is released when it is
1545 destroyed. */
1546template<typename T>
1547class auto_vec<T, 0> : public vec<T, va_heap>
1548{
1549public:
1550 auto_vec () { this->m_vec = NULLnullptr; }
1551 auto_vec (size_t n) { this->create (n); }
1552 ~auto_vec () { this->release (); }
1553
1554 auto_vec (vec<T, va_heap>&& r)
1555 {
1556 gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1556, __FUNCTION__), 0 : 0))
;
1557 this->m_vec = r.m_vec;
1558 r.m_vec = NULLnullptr;
1559 }
1560 auto_vec& operator= (vec<T, va_heap>&& r)
1561 {
1562 gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1562, __FUNCTION__), 0 : 0))
;
1563 this->release ();
1564 this->m_vec = r.m_vec;
1565 r.m_vec = NULLnullptr;
1566 return *this;
1567 }
1568};
1569
1570
1571/* Allocate heap memory for pointer V and create the internal vector
1572 with space for NELEMS elements. If NELEMS is 0, the internal
1573 vector is initialized to empty. */
1574
1575template<typename T>
1576inline void
1577vec_alloc (vec<T> *&v, unsigned nelems CXX_MEM_STAT_INFO)
1578{
1579 v = new vec<T>;
1580 v->create (nelems PASS_MEM_STAT);
1581}
1582
1583
1584/* A subclass of auto_vec <char *> that frees all of its elements on
1585 deletion. */
1586
1587class auto_string_vec : public auto_vec <char *>
1588{
1589 public:
1590 ~auto_string_vec ();
1591};
1592
1593/* A subclass of auto_vec <T *> that deletes all of its elements on
1594 destruction.
1595
1596 This is a crude way for a vec to "own" the objects it points to
1597 and clean up automatically.
1598
1599 For example, no attempt is made to delete elements when an item
1600 within the vec is overwritten.
1601
1602 We can't rely on gnu::unique_ptr within a container,
1603 since we can't rely on move semantics in C++98. */
1604
1605template <typename T>
1606class auto_delete_vec : public auto_vec <T *>
1607{
1608 public:
1609 auto_delete_vec () {}
1610 auto_delete_vec (size_t s) : auto_vec <T *> (s) {}
1611
1612 ~auto_delete_vec ();
1613
1614private:
1615 DISABLE_COPY_AND_ASSIGN(auto_delete_vec)auto_delete_vec (const auto_delete_vec&) = delete; void operator
= (const auto_delete_vec &) = delete
;
1616};
1617
1618/* Conditionally allocate heap memory for VEC and its internal vector. */
1619
1620template<typename T>
1621inline void
1622vec_check_alloc (vec<T, va_heap> *&vec, unsigned nelems CXX_MEM_STAT_INFO)
1623{
1624 if (!vec)
1625 vec_alloc (vec, nelems PASS_MEM_STAT);
1626}
1627
1628
1629/* Free the heap memory allocated by vector V and set it to NULL. */
1630
1631template<typename T>
1632inline void
1633vec_free (vec<T> *&v)
1634{
1635 if (v == NULLnullptr)
1636 return;
1637
1638 v->release ();
1639 delete v;
1640 v = NULLnullptr;
1641}
1642
1643
1644/* Return iteration condition and update PTR to point to the IX'th
1645 element of this vector. Use this to iterate over the elements of a
1646 vector as follows,
1647
1648 for (ix = 0; v.iterate (ix, &ptr); ix++)
1649 continue; */
1650
1651template<typename T>
1652inline bool
1653vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T *ptr) const
1654{
1655 if (m_vec)
1656 return m_vec->iterate (ix, ptr);
1657 else
1658 {
1659 *ptr = 0;
1660 return false;
1661 }
1662}
1663
1664
1665/* Return iteration condition and update *PTR to point to the
1666 IX'th element of this vector. Use this to iterate over the
1667 elements of a vector as follows,
1668
1669 for (ix = 0; v->iterate (ix, &ptr); ix++)
1670 continue;
1671
1672 This variant is for vectors of objects. */
1673
1674template<typename T>
1675inline bool
1676vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T **ptr) const
1677{
1678 if (m_vec)
1679 return m_vec->iterate (ix, ptr);
1680 else
1681 {
1682 *ptr = 0;
1683 return false;
1684 }
1685}
1686
1687
1688/* Convenience macro for forward iteration. */
1689#define FOR_EACH_VEC_ELT(V, I, P)for (I = 0; (V).iterate ((I), &(P)); ++(I)) \
1690 for (I = 0; (V).iterate ((I), &(P)); ++(I))
1691
1692#define FOR_EACH_VEC_SAFE_ELT(V, I, P)for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I)) \
1693 for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I))
1694
1695/* Likewise, but start from FROM rather than 0. */
1696#define FOR_EACH_VEC_ELT_FROM(V, I, P, FROM)for (I = (FROM); (V).iterate ((I), &(P)); ++(I)) \
1697 for (I = (FROM); (V).iterate ((I), &(P)); ++(I))
1698
1699/* Convenience macro for reverse iteration. */
1700#define FOR_EACH_VEC_ELT_REVERSE(V, I, P)for (I = (V).length () - 1; (V).iterate ((I), &(P)); (I)--
)
\
1701 for (I = (V).length () - 1; \
1702 (V).iterate ((I), &(P)); \
1703 (I)--)
1704
1705#define FOR_EACH_VEC_SAFE_ELT_REVERSE(V, I, P)for (I = vec_safe_length (V) - 1; vec_safe_iterate ((V), (I),
&(P)); (I)--)
\
1706 for (I = vec_safe_length (V) - 1; \
1707 vec_safe_iterate ((V), (I), &(P)); \
1708 (I)--)
1709
1710/* auto_string_vec's dtor, freeing all contained strings, automatically
1711 chaining up to ~auto_vec <char *>, which frees the internal buffer. */
1712
1713inline
1714auto_string_vec::~auto_string_vec ()
1715{
1716 int i;
1717 char *str;
1718 FOR_EACH_VEC_ELT (*this, i, str)for (i = 0; (*this).iterate ((i), &(str)); ++(i))
1719 free (str);
1720}
1721
1722/* auto_delete_vec's dtor, deleting all contained items, automatically
1723 chaining up to ~auto_vec <T*>, which frees the internal buffer. */
1724
1725template <typename T>
1726inline
1727auto_delete_vec<T>::~auto_delete_vec ()
1728{
1729 int i;
1730 T *item;
1731 FOR_EACH_VEC_ELT (*this, i, item)for (i = 0; (*this).iterate ((i), &(item)); ++(i))
1732 delete item;
1733}
1734
1735
1736/* Return a copy of this vector. */
1737
1738template<typename T>
1739inline vec<T, va_heap, vl_ptr>
1740vec<T, va_heap, vl_ptr>::copy (ALONE_MEM_STAT_DECLvoid) const
1741{
1742 vec<T, va_heap, vl_ptr> new_vec = vNULL;
1743 if (length ())
1744 new_vec.m_vec = m_vec->copy (ALONE_PASS_MEM_STAT);
1745 return new_vec;
1746}
1747
1748
1749/* Ensure that the vector has at least RESERVE slots available (if
1750 EXACT is false), or exactly RESERVE slots available (if EXACT is
1751 true).
1752
1753 This may create additional headroom if EXACT is false.
1754
1755 Note that this can cause the embedded vector to be reallocated.
1756 Returns true iff reallocation actually occurred. */
1757
1758template<typename T>
1759inline bool
1760vec<T, va_heap, vl_ptr>::reserve (unsigned nelems, bool exact MEM_STAT_DECL)
1761{
1762 if (space (nelems))
1763 return false;
1764
1765 /* For now play a game with va_heap::reserve to hide our auto storage if any,
1766 this is necessary because it doesn't have enough information to know the
1767 embedded vector is in auto storage, and so should not be freed. */
1768 vec<T, va_heap, vl_embed> *oldvec = m_vec;
1769 unsigned int oldsize = 0;
1770 bool handle_auto_vec = m_vec && using_auto_storage ();
1771 if (handle_auto_vec)
1772 {
1773 m_vec = NULLnullptr;
1774 oldsize = oldvec->length ();
1775 nelems += oldsize;
1776 }
1777
1778 va_heap::reserve (m_vec, nelems, exact PASS_MEM_STAT);
1779 if (handle_auto_vec)
1780 {
1781 vec_copy_construct (m_vec->address (), oldvec->address (), oldsize);
1782 m_vec->m_vecpfx.m_num = oldsize;
1783 }
1784
1785 return true;
1786}
1787
1788
1789/* Ensure that this vector has exactly NELEMS slots available. This
1790 will not create additional headroom. Note this can cause the
1791 embedded vector to be reallocated. Returns true iff reallocation
1792 actually occurred. */
1793
1794template<typename T>
1795inline bool
1796vec<T, va_heap, vl_ptr>::reserve_exact (unsigned nelems MEM_STAT_DECL)
1797{
1798 return reserve (nelems, true PASS_MEM_STAT);
1799}
1800
1801
1802/* Create the internal vector and reserve NELEMS for it. This is
1803 exactly like vec::reserve, but the internal vector is
1804 unconditionally allocated from scratch. The old one, if it
1805 existed, is lost. */
1806
1807template<typename T>
1808inline void
1809vec<T, va_heap, vl_ptr>::create (unsigned nelems MEM_STAT_DECL)
1810{
1811 m_vec = NULLnullptr;
1812 if (nelems > 0)
1813 reserve_exact (nelems PASS_MEM_STAT);
1814}
1815
1816
1817/* Free the memory occupied by the embedded vector. */
1818
1819template<typename T>
1820inline void
1821vec<T, va_heap, vl_ptr>::release (void)
1822{
1823 if (!m_vec)
1824 return;
1825
1826 if (using_auto_storage ())
1827 {
1828 m_vec->m_vecpfx.m_num = 0;
1829 return;
1830 }
1831
1832 va_heap::release (m_vec);
1833}
1834
1835/* Copy the elements from SRC to the end of this vector as if by memcpy.
1836 SRC and this vector must be allocated with the same memory
1837 allocation mechanism. This vector is assumed to have sufficient
1838 headroom available. */
1839
1840template<typename T>
1841inline void
1842vec<T, va_heap, vl_ptr>::splice (const vec<T, va_heap, vl_ptr> &src)
1843{
1844 if (src.length ())
1845 m_vec->splice (*(src.m_vec));
1846}
1847
1848
1849/* Copy the elements in SRC to the end of this vector as if by memcpy.
1850 SRC and this vector must be allocated with the same mechanism.
1851 If there is not enough headroom in this vector, it will be reallocated
1852 as needed. */
1853
1854template<typename T>
1855inline void
1856vec<T, va_heap, vl_ptr>::safe_splice (const vec<T, va_heap, vl_ptr> &src
1857 MEM_STAT_DECL)
1858{
1859 if (src.length ())
1860 {
1861 reserve_exact (src.length ());
1862 splice (src);
1863 }
1864}
1865
1866
1867/* Push OBJ (a new element) onto the end of the vector. There must be
1868 sufficient space in the vector. Return a pointer to the slot
1869 where OBJ was inserted. */
1870
1871template<typename T>
1872inline T *
1873vec<T, va_heap, vl_ptr>::quick_push (const T &obj)
1874{
1875 return m_vec->quick_push (obj);
1876}
1877
1878
1879/* Push a new element OBJ onto the end of this vector. Reallocates
1880 the embedded vector, if needed. Return a pointer to the slot where
1881 OBJ was inserted. */
1882
1883template<typename T>
1884inline T *
1885vec<T, va_heap, vl_ptr>::safe_push (const T &obj MEM_STAT_DECL)
1886{
1887 reserve (1, false PASS_MEM_STAT);
1888 return quick_push (obj);
1889}
1890
1891
1892/* Pop and return the last element off the end of the vector. */
1893
1894template<typename T>
1895inline T &
1896vec<T, va_heap, vl_ptr>::pop (void)
1897{
1898 return m_vec->pop ();
1899}
1900
1901
1902/* Set the length of the vector to LEN. The new length must be less
1903 than or equal to the current length. This is an O(1) operation. */
1904
1905template<typename T>
1906inline void
1907vec<T, va_heap, vl_ptr>::truncate (unsigned size)
1908{
1909 if (m_vec)
1910 m_vec->truncate (size);
1911 else
1912 gcc_checking_assert (size == 0)((void)(!(size == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1912, __FUNCTION__), 0 : 0))
;
1913}
1914
1915
1916/* Grow the vector to a specific length. LEN must be as long or
1917 longer than the current length. The new elements are
1918 uninitialized. Reallocate the internal vector, if needed. */
1919
1920template<typename T>
1921inline void
1922vec<T, va_heap, vl_ptr>::safe_grow (unsigned len, bool exact MEM_STAT_DECL)
1923{
1924 unsigned oldlen = length ();
1925 gcc_checking_assert (oldlen <= len)((void)(!(oldlen <= len) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1925, __FUNCTION__), 0 : 0))
;
1926 reserve (len - oldlen, exact PASS_MEM_STAT);
1927 if (m_vec)
1928 m_vec->quick_grow (len);
1929 else
1930 gcc_checking_assert (len == 0)((void)(!(len == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1930, __FUNCTION__), 0 : 0))
;
1931}
1932
1933
1934/* Grow the embedded vector to a specific length. LEN must be as
1935 long or longer than the current length. The new elements are
1936 initialized to zero. Reallocate the internal vector, if needed. */
1937
1938template<typename T>
1939inline void
1940vec<T, va_heap, vl_ptr>::safe_grow_cleared (unsigned len, bool exact
1941 MEM_STAT_DECL)
1942{
1943 unsigned oldlen = length ();
1944 size_t growby = len - oldlen;
1945 safe_grow (len, exact PASS_MEM_STAT);
1946 if (growby != 0)
1947 vec_default_construct (address () + oldlen, growby);
1948}
1949
1950
1951/* Same as vec::safe_grow but without reallocation of the internal vector.
1952 If the vector cannot be extended, a runtime assertion will be triggered. */
1953
1954template<typename T>
1955inline void
1956vec<T, va_heap, vl_ptr>::quick_grow (unsigned len)
1957{
1958 gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1958, __FUNCTION__), 0 : 0))
;
1959 m_vec->quick_grow (len);
1960}
1961
1962
1963/* Same as vec::quick_grow_cleared but without reallocation of the
1964 internal vector. If the vector cannot be extended, a runtime
1965 assertion will be triggered. */
1966
1967template<typename T>
1968inline void
1969vec<T, va_heap, vl_ptr>::quick_grow_cleared (unsigned len)
1970{
1971 gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 1971, __FUNCTION__), 0 : 0))
;
1972 m_vec->quick_grow_cleared (len);
1973}
1974
1975
1976/* Insert an element, OBJ, at the IXth position of this vector. There
1977 must be sufficient space. */
1978
1979template<typename T>
1980inline void
1981vec<T, va_heap, vl_ptr>::quick_insert (unsigned ix, const T &obj)
1982{
1983 m_vec->quick_insert (ix, obj);
1984}
1985
1986
1987/* Insert an element, OBJ, at the IXth position of the vector.
1988 Reallocate the embedded vector, if necessary. */
1989
1990template<typename T>
1991inline void
1992vec<T, va_heap, vl_ptr>::safe_insert (unsigned ix, const T &obj MEM_STAT_DECL)
1993{
1994 reserve (1, false PASS_MEM_STAT);
1995 quick_insert (ix, obj);
1996}
1997
1998
1999/* Remove an element from the IXth position of this vector. Ordering of
2000 remaining elements is preserved. This is an O(N) operation due to
2001 a memmove. */
2002
2003template<typename T>
2004inline void
2005vec<T, va_heap, vl_ptr>::ordered_remove (unsigned ix)
2006{
2007 m_vec->ordered_remove (ix);
2008}
2009
2010
2011/* Remove an element from the IXth position of this vector. Ordering
2012 of remaining elements is destroyed. This is an O(1) operation. */
2013
2014template<typename T>
2015inline void
2016vec<T, va_heap, vl_ptr>::unordered_remove (unsigned ix)
2017{
2018 m_vec->unordered_remove (ix);
2019}
2020
2021
2022/* Remove LEN elements starting at the IXth. Ordering is retained.
2023 This is an O(N) operation due to memmove. */
2024
2025template<typename T>
2026inline void
2027vec<T, va_heap, vl_ptr>::block_remove (unsigned ix, unsigned len)
2028{
2029 m_vec->block_remove (ix, len);
2030}
2031
2032
2033/* Sort the contents of this vector with qsort. CMP is the comparison
2034 function to pass to qsort. */
2035
2036template<typename T>
2037inline void
2038vec<T, va_heap, vl_ptr>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *))
2039{
2040 if (m_vec)
2041 m_vec->qsort (cmp)qsort (cmp);
2042}
2043
2044/* Sort the contents of this vector with qsort. CMP is the comparison
2045 function to pass to qsort. */
2046
2047template<typename T>
2048inline void
2049vec<T, va_heap, vl_ptr>::sort (int (*cmp) (const void *, const void *,
2050 void *), void *data)
2051{
2052 if (m_vec)
2053 m_vec->sort (cmp, data);
2054}
2055
2056
2057/* Search the contents of the sorted vector with a binary search.
2058 CMP is the comparison function to pass to bsearch. */
2059
2060template<typename T>
2061inline T *
2062vec<T, va_heap, vl_ptr>::bsearch (const void *key,
2063 int (*cmp) (const void *, const void *))
2064{
2065 if (m_vec)
2066 return m_vec->bsearch (key, cmp);
2067 return NULLnullptr;
2068}
2069
2070/* Search the contents of the sorted vector with a binary search.
2071 CMP is the comparison function to pass to bsearch. */
2072
2073template<typename T>
2074inline T *
2075vec<T, va_heap, vl_ptr>::bsearch (const void *key,
2076 int (*cmp) (const void *, const void *,
2077 void *), void *data)
2078{
2079 if (m_vec)
2080 return m_vec->bsearch (key, cmp, data);
2081 return NULLnullptr;
2082}
2083
2084
2085/* Find and return the first position in which OBJ could be inserted
2086 without changing the ordering of this vector. LESSTHAN is a
2087 function that returns true if the first argument is strictly less
2088 than the second. */
2089
2090template<typename T>
2091inline unsigned
2092vec<T, va_heap, vl_ptr>::lower_bound (T obj,
2093 bool (*lessthan)(const T &, const T &))
2094 const
2095{
2096 return m_vec ? m_vec->lower_bound (obj, lessthan) : 0;
2097}
2098
2099/* Return true if SEARCH is an element of V. Note that this is O(N) in the
2100 size of the vector and so should be used with care. */
2101
2102template<typename T>
2103inline bool
2104vec<T, va_heap, vl_ptr>::contains (const T &search) const
2105{
2106 return m_vec ? m_vec->contains (search) : false;
2107}
2108
2109/* Reverse content of the vector. */
2110
2111template<typename T>
2112inline void
2113vec<T, va_heap, vl_ptr>::reverse (void)
2114{
2115 unsigned l = length ();
2116 T *ptr = address ();
2117
2118 for (unsigned i = 0; i < l / 2; i++)
2119 std::swap (ptr[i], ptr[l - i - 1]);
2120}
2121
2122template<typename T>
2123inline bool
2124vec<T, va_heap, vl_ptr>::using_auto_storage () const
2125{
2126 return m_vec->m_vecpfx.m_using_auto_storage;
2127}
2128
2129/* Release VEC and call release of all element vectors. */
2130
2131template<typename T>
2132inline void
2133release_vec_vec (vec<vec<T> > &vec)
2134{
2135 for (unsigned i = 0; i < vec.length (); i++)
2136 vec[i].release ();
2137
2138 vec.release ();
2139}
2140
2141// Provide a subset of the std::span functionality. (We can't use std::span
2142// itself because it's a C++20 feature.)
2143//
2144// In addition, provide an invalid value that is distinct from all valid
2145// sequences (including the empty sequence). This can be used to return
2146// failure without having to use std::optional.
2147//
2148// There is no operator bool because it would be ambiguous whether it is
2149// testing for a valid value or an empty sequence.
2150template<typename T>
2151class array_slice
2152{
2153 template<typename OtherT> friend class array_slice;
2154
2155public:
2156 using value_type = T;
2157 using iterator = T *;
2158 using const_iterator = const T *;
2159
2160 array_slice () : m_base (nullptr), m_size (0) {}
2161
2162 template<typename OtherT>
2163 array_slice (array_slice<OtherT> other)
2164 : m_base (other.m_base), m_size (other.m_size) {}
2165
2166 array_slice (iterator base, unsigned int size)
2167 : m_base (base), m_size (size) {}
2168
2169 template<size_t N>
2170 array_slice (T (&array)[N]) : m_base (array), m_size (N) {}
2171
2172 template<typename OtherT>
2173 array_slice (const vec<OtherT> &v)
2174 : m_base (v.address ()), m_size (v.length ()) {}
2175
2176 iterator begin () { return m_base; }
2177 iterator end () { return m_base + m_size; }
2178
2179 const_iterator begin () const { return m_base; }
2180 const_iterator end () const { return m_base + m_size; }
2181
2182 value_type &front ();
2183 value_type &back ();
2184 value_type &operator[] (unsigned int i);
2185
2186 const value_type &front () const;
2187 const value_type &back () const;
2188 const value_type &operator[] (unsigned int i) const;
2189
2190 size_t size () const { return m_size; }
2191 size_t size_bytes () const { return m_size * sizeof (T); }
2192 bool empty () const { return m_size == 0; }
2193
2194 // An invalid array_slice that represents a failed operation. This is
2195 // distinct from an empty slice, which is a valid result in some contexts.
2196 static array_slice invalid () { return { nullptr, ~0U }; }
2197
2198 // True if the array is valid, false if it is an array like INVALID.
2199 bool is_valid () const { return m_base || m_size == 0; }
2200
2201private:
2202 iterator m_base;
2203 unsigned int m_size;
2204};
2205
2206template<typename T>
2207inline typename array_slice<T>::value_type &
2208array_slice<T>::front ()
2209{
2210 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2210, __FUNCTION__), 0 : 0))
;
2211 return m_base[0];
2212}
2213
2214template<typename T>
2215inline const typename array_slice<T>::value_type &
2216array_slice<T>::front () const
2217{
2218 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2218, __FUNCTION__), 0 : 0))
;
2219 return m_base[0];
2220}
2221
2222template<typename T>
2223inline typename array_slice<T>::value_type &
2224array_slice<T>::back ()
2225{
2226 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2226, __FUNCTION__), 0 : 0))
;
2227 return m_base[m_size - 1];
2228}
2229
2230template<typename T>
2231inline const typename array_slice<T>::value_type &
2232array_slice<T>::back () const
2233{
2234 gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2234, __FUNCTION__), 0 : 0))
;
2235 return m_base[m_size - 1];
2236}
2237
2238template<typename T>
2239inline typename array_slice<T>::value_type &
2240array_slice<T>::operator[] (unsigned int i)
2241{
2242 gcc_checking_assert (i < m_size)((void)(!(i < m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2242, __FUNCTION__), 0 : 0))
;
2243 return m_base[i];
2244}
2245
2246template<typename T>
2247inline const typename array_slice<T>::value_type &
2248array_slice<T>::operator[] (unsigned int i) const
2249{
2250 gcc_checking_assert (i < m_size)((void)(!(i < m_size) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h"
, 2250, __FUNCTION__), 0 : 0))
;
2251 return m_base[i];
2252}
2253
2254template<typename T>
2255array_slice<T>
2256make_array_slice (T *base, unsigned int size)
2257{
2258 return array_slice<T> (base, size);
2259}
2260
2261#if (GCC_VERSION(4 * 1000 + 2) >= 3000)
2262# pragma GCC poison m_vec m_vecpfx m_vecdata
2263#endif
2264
2265#endif // GCC_VEC_H