Line data Source code
1 : /* Output Dwarf2 format symbol table information from GCC.
2 : Copyright (C) 1992-2026 Free Software Foundation, Inc.
3 : Contributed by Gary Funck (gary@intrepid.com).
4 : Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 : Extensively modified by Jason Merrill (jason@cygnus.com).
6 :
7 : This file is part of GCC.
8 :
9 : GCC is free software; you can redistribute it and/or modify it under
10 : the terms of the GNU General Public License as published by the Free
11 : Software Foundation; either version 3, or (at your option) any later
12 : version.
13 :
14 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 : for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with GCC; see the file COPYING3. If not see
21 : <http://www.gnu.org/licenses/>. */
22 :
23 : /* TODO: Emit .debug_line header even when there are no functions, since
24 : the file numbers are used by .debug_info. Alternately, leave
25 : out locations for types and decls.
26 : Avoid talking about ctors and op= for PODs.
27 : Factor out common prologue sequences into multiple CIEs. */
28 :
29 : /* The first part of this file deals with the DWARF 2 frame unwind
30 : information, which is also used by the GCC efficient exception handling
31 : mechanism. The second part, controlled only by an #ifdef
32 : DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
33 : information. */
34 :
35 : /* DWARF2 Abbreviation Glossary:
36 :
37 : CFA = Canonical Frame Address
38 : a fixed address on the stack which identifies a call frame.
39 : We define it to be the value of SP just before the call insn.
40 : The CFA register and offset, which may change during the course
41 : of the function, are used to calculate its value at runtime.
42 :
43 : CFI = Call Frame Instruction
44 : an instruction for the DWARF2 abstract machine
45 :
46 : CIE = Common Information Entry
47 : information describing information common to one or more FDEs
48 :
49 : DIE = Debugging Information Entry
50 :
51 : FDE = Frame Description Entry
52 : information describing the stack call frame, in particular,
53 : how to restore registers
54 :
55 : DW_CFA_... = DWARF2 CFA call frame instruction
56 : DW_TAG_... = DWARF2 DIE tag */
57 :
58 : #include "config.h"
59 : #include "system.h"
60 : #include "coretypes.h"
61 : #include "target.h"
62 : #include "function.h"
63 : #include "rtl.h"
64 : #include "tree.h"
65 : #include "memmodel.h"
66 : #include "tm_p.h"
67 : #include "stringpool.h"
68 : #include "insn-config.h"
69 : #include "ira.h"
70 : #include "cgraph.h"
71 : #include "diagnostic.h"
72 : #include "fold-const.h"
73 : #include "stor-layout.h"
74 : #include "varasm.h"
75 : #include "version.h"
76 : #include "flags.h"
77 : #include "rtlhash.h"
78 : #include "reload.h"
79 : #include "output.h"
80 : #include "expr.h"
81 : #include "dwarf2out.h"
82 : #include "dwarf2ctf.h"
83 : #include "dwarf2codeview.h"
84 : #include "dwarf2asm.h"
85 : #include "toplev.h"
86 : #include "md5.h"
87 : #include "tree-pretty-print.h"
88 : #include "print-rtl.h"
89 : #include "debug.h"
90 : #include "common/common-target.h"
91 : #include "langhooks.h"
92 : #include "lra.h"
93 : #include "dumpfile.h"
94 : #include "opts.h"
95 : #include "tree-dfa.h"
96 : #include "gdb/gdb-index.h"
97 : #include "rtl-iter.h"
98 : #include "stringpool.h"
99 : #include "attribs.h"
100 : #include "file-prefix-map.h" /* remap_debug_filename() */
101 :
102 : static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
103 : int, bool);
104 : static rtx_insn *last_var_location_insn;
105 : static rtx_insn *cached_next_real_insn;
106 : static void dwarf2out_decl (tree);
107 : static bool is_redundant_typedef (const_tree);
108 :
109 : #ifndef XCOFF_DEBUGGING_INFO
110 : #define XCOFF_DEBUGGING_INFO 0
111 : #endif
112 :
113 : #ifndef HAVE_XCOFF_DWARF_EXTRAS
114 : #define HAVE_XCOFF_DWARF_EXTRAS 0
115 : #endif
116 :
117 : #ifdef VMS_DEBUGGING_INFO
118 : int vms_file_stats_name (const char *, long long *, long *, char *, int *);
119 :
120 : /* Define this macro to be a nonzero value if the directory specifications
121 : which are output in the debug info should end with a separator. */
122 : #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
123 : /* Define this macro to evaluate to a nonzero value if GCC should refrain
124 : from generating indirect strings in DWARF2 debug information, for instance
125 : if your target is stuck with an old version of GDB that is unable to
126 : process them properly or uses VMS Debug. */
127 : #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
128 : #else
129 : #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
130 : #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
131 : #endif
132 :
133 : /* ??? Poison these here until it can be done generically. They've been
134 : totally replaced in this file; make sure it stays that way. */
135 : #undef DWARF2_UNWIND_INFO
136 : #undef DWARF2_FRAME_INFO
137 : #if (GCC_VERSION >= 3000)
138 : #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
139 : #endif
140 :
141 : /* The size of the target's pointer type. */
142 : #ifndef PTR_SIZE
143 : #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
144 : #endif
145 :
146 : /* Array of RTXes referenced by the debugging information, which therefore
147 : must be kept around forever. */
148 : static GTY(()) vec<rtx, va_gc> *used_rtx_array;
149 :
150 : /* A pointer to the base of a list of incomplete types which might be
151 : completed at some later time. incomplete_types_list needs to be a
152 : vec<tree, va_gc> *because we want to tell the garbage collector about
153 : it. */
154 : static GTY(()) vec<tree, va_gc> *incomplete_types;
155 :
156 : /* Pointers to various DWARF2 sections. */
157 : static GTY(()) section *debug_info_section;
158 : static GTY(()) section *debug_skeleton_info_section;
159 : static GTY(()) section *debug_abbrev_section;
160 : static GTY(()) section *debug_skeleton_abbrev_section;
161 : static GTY(()) section *debug_aranges_section;
162 : static GTY(()) section *debug_addr_section;
163 : static GTY(()) section *debug_macinfo_section;
164 : static const char *debug_macinfo_section_name;
165 : static unsigned macinfo_label_base = 1;
166 : static GTY(()) section *debug_line_section;
167 : static GTY(()) section *debug_skeleton_line_section;
168 : static GTY(()) section *debug_loc_section;
169 : static GTY(()) section *debug_pubnames_section;
170 : static GTY(()) section *debug_pubtypes_section;
171 : static GTY(()) section *debug_str_section;
172 : static GTY(()) section *debug_line_str_section;
173 : static GTY(()) section *debug_str_dwo_section;
174 : static GTY(()) section *debug_str_offsets_section;
175 : static GTY(()) section *debug_ranges_section;
176 : static GTY(()) section *debug_ranges_dwo_section;
177 : static GTY(()) section *debug_frame_section;
178 :
179 : /* Maximum size (in bytes) of an artificially generated label. */
180 : #define MAX_ARTIFICIAL_LABEL_BYTES 40
181 :
182 : /* According to the (draft) DWARF 3 specification, the initial length
183 : should either be 4 or 12 bytes. When it's 12 bytes, the first 4
184 : bytes are 0xffffffff, followed by the length stored in the next 8
185 : bytes.
186 :
187 : However, the SGI/MIPS ABI uses an initial length which is equal to
188 : dwarf_offset_size. It is defined (elsewhere) accordingly. */
189 :
190 : #ifndef DWARF_INITIAL_LENGTH_SIZE
191 : #define DWARF_INITIAL_LENGTH_SIZE (dwarf_offset_size == 4 ? 4 : 12)
192 : #endif
193 :
194 : #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
195 : #define DWARF_INITIAL_LENGTH_SIZE_STR (dwarf_offset_size == 4 ? "-4" : "-12")
196 : #endif
197 :
198 : /* Round SIZE up to the nearest BOUNDARY. */
199 : #define DWARF_ROUND(SIZE,BOUNDARY) \
200 : ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 :
202 : /* CIE identifier. */
203 : #if HOST_BITS_PER_WIDE_INT >= 64
204 : #define DWARF_CIE_ID \
205 : (unsigned HOST_WIDE_INT) (dwarf_offset_size == 4 ? DW_CIE_ID : DW64_CIE_ID)
206 : #else
207 : #define DWARF_CIE_ID DW_CIE_ID
208 : #endif
209 :
210 :
211 : /* A vector for a table that contains frame description
212 : information for each routine. */
213 : #define NOT_INDEXED (-1U)
214 : #define NO_INDEX_ASSIGNED (-2U)
215 :
216 : static GTY(()) vec<dw_fde_ref, va_gc> *fde_vec;
217 :
218 : struct GTY((for_user)) indirect_string_node {
219 : const char *str;
220 : unsigned int refcount;
221 : enum dwarf_form form;
222 : char *label;
223 : unsigned int index;
224 : };
225 :
226 : struct indirect_string_hasher : ggc_ptr_hash<indirect_string_node>
227 : {
228 : typedef const char *compare_type;
229 :
230 : static hashval_t hash (indirect_string_node *);
231 : static bool equal (indirect_string_node *, const char *);
232 : };
233 :
234 : static GTY (()) hash_table<indirect_string_hasher> *debug_str_hash;
235 :
236 : static GTY (()) hash_table<indirect_string_hasher> *debug_line_str_hash;
237 :
238 : /* With split_debug_info, both the comp_dir and dwo_name go in the
239 : main object file, rather than the dwo, similar to the force_direct
240 : parameter elsewhere but with additional complications:
241 :
242 : 1) The string is needed in both the main object file and the dwo.
243 : That is, the comp_dir and dwo_name will appear in both places.
244 :
245 : 2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
246 : DW_FORM_line_strp or DW_FORM_strx/GNU_str_index.
247 :
248 : 3) GCC chooses the form to use late, depending on the size and
249 : reference count.
250 :
251 : Rather than forcing the all debug string handling functions and
252 : callers to deal with these complications, simply use a separate,
253 : special-cased string table for any attribute that should go in the
254 : main object file. This limits the complexity to just the places
255 : that need it. */
256 :
257 : static GTY (()) hash_table<indirect_string_hasher> *skeleton_debug_str_hash;
258 :
259 : static GTY(()) int dw2_string_counter;
260 :
261 : /* True if the compilation unit places functions in more than one section. */
262 : static GTY(()) bool have_multiple_function_sections = false;
263 :
264 : /* The default cold text section. */
265 : static GTY(()) section *cold_text_section;
266 :
267 : /* True if currently in text section. */
268 : static GTY(()) bool in_text_section_p = false;
269 :
270 : /* Last debug-on location in corresponding section. */
271 : static GTY(()) const char *last_text_label;
272 : static GTY(()) const char *last_cold_label;
273 :
274 : /* Mark debug-on/off locations per section.
275 : NULL means the section is not used at all. */
276 : static GTY(()) vec<const char *, va_gc> *switch_text_ranges;
277 : static GTY(()) vec<const char *, va_gc> *switch_cold_ranges;
278 :
279 : /* The DIE for C++14 'auto' in a function return type. */
280 : static GTY(()) dw_die_ref auto_die;
281 :
282 : /* The DIE for C++14 'decltype(auto)' in a function return type. */
283 : static GTY(()) dw_die_ref decltype_auto_die;
284 :
285 : /* Forward declarations for functions defined in this file. */
286 :
287 : static void output_call_frame_info (int);
288 :
289 : /* Personality decl of current unit. Used only when assembler does not support
290 : personality CFI. */
291 : static GTY(()) rtx current_unit_personality;
292 :
293 : /* Whether an eh_frame section is required. */
294 : static GTY(()) bool do_eh_frame = false;
295 :
296 : /* .debug_rnglists next index. */
297 : static unsigned int rnglist_idx;
298 :
299 : /* Data and reference forms for relocatable data. */
300 : #define DW_FORM_data (dwarf_offset_size == 8 ? DW_FORM_data8 : DW_FORM_data4)
301 : #define DW_FORM_ref (dwarf_offset_size == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
302 :
303 : #ifndef DEBUG_FRAME_SECTION
304 : #define DEBUG_FRAME_SECTION ".debug_frame"
305 : #endif
306 :
307 : #ifndef FUNC_BEGIN_LABEL
308 : #define FUNC_BEGIN_LABEL "LFB"
309 : #endif
310 :
311 : #ifndef FUNC_SECOND_SECT_LABEL
312 : #define FUNC_SECOND_SECT_LABEL "LFSB"
313 : #endif
314 :
315 : #ifndef FUNC_END_LABEL
316 : #define FUNC_END_LABEL "LFE"
317 : #endif
318 :
319 : #ifndef PROLOGUE_END_LABEL
320 : #define PROLOGUE_END_LABEL "LPE"
321 : #endif
322 :
323 : #ifndef EPILOGUE_BEGIN_LABEL
324 : #define EPILOGUE_BEGIN_LABEL "LEB"
325 : #endif
326 :
327 : #ifndef FRAME_BEGIN_LABEL
328 : #define FRAME_BEGIN_LABEL "Lframe"
329 : #endif
330 : #define CIE_AFTER_SIZE_LABEL "LSCIE"
331 : #define CIE_END_LABEL "LECIE"
332 : #define FDE_LABEL "LSFDE"
333 : #define FDE_AFTER_SIZE_LABEL "LASFDE"
334 : #define FDE_END_LABEL "LEFDE"
335 : #define LINE_NUMBER_BEGIN_LABEL "LSLT"
336 : #define LINE_NUMBER_END_LABEL "LELT"
337 : #define LN_PROLOG_AS_LABEL "LASLTP"
338 : #define LN_PROLOG_END_LABEL "LELTP"
339 : #define DIE_LABEL_PREFIX "DW"
340 :
341 : /* Match the base name of a file to the base name of a compilation unit. */
342 :
343 : static bool
344 620 : matches_main_base (const char *path)
345 : {
346 : /* Cache the last query. */
347 620 : static const char *last_path = NULL;
348 620 : static bool last_match = false;
349 620 : if (path != last_path)
350 : {
351 113 : const char *base;
352 113 : int length = base_of_path (path, &base);
353 113 : last_path = path;
354 113 : last_match = (length == main_input_baselength
355 113 : && memcmp (base, main_input_basename, length) == 0);
356 : }
357 620 : return last_match;
358 : }
359 :
360 : #ifdef DEBUG_DEBUG_STRUCT
361 :
362 : static bool
363 : dump_struct_debug (tree type, enum debug_info_usage usage,
364 : enum debug_struct_file criterion, int generic,
365 : bool matches, bool result)
366 : {
367 : /* Find the type name. */
368 : tree type_decl = TYPE_STUB_DECL (type);
369 : tree t = type_decl;
370 : const char *name = 0;
371 : if (TREE_CODE (t) == TYPE_DECL)
372 : t = DECL_NAME (t);
373 : if (t)
374 : name = IDENTIFIER_POINTER (t);
375 :
376 : fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
377 : criterion,
378 : DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
379 : matches ? "bas" : "hdr",
380 : generic ? "gen" : "ord",
381 : usage == DINFO_USAGE_DFN ? ";" :
382 : usage == DINFO_USAGE_DIR_USE ? "." : "*",
383 : result,
384 : (void*) type_decl, name);
385 : return result;
386 : }
387 : #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
388 : dump_struct_debug (type, usage, criterion, generic, matches, result)
389 :
390 : #else
391 :
392 : #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
393 : (result)
394 :
395 : #endif
396 :
397 : /* Get the number of HOST_WIDE_INTs needed to represent the precision
398 : of the number. */
399 :
400 : static unsigned int
401 1779 : get_full_len (const dw_wide_int &op)
402 : {
403 1779 : return CEIL (op.get_precision (), HOST_BITS_PER_WIDE_INT);
404 : }
405 :
406 : static bool
407 149801613 : should_emit_struct_debug (tree type, enum debug_info_usage usage)
408 : {
409 149801613 : if (debug_info_level <= DINFO_LEVEL_TERSE)
410 : return false;
411 :
412 149801610 : enum debug_struct_file criterion;
413 149801610 : tree type_decl;
414 149801610 : bool generic = lang_hooks.types.generic_p (type);
415 :
416 149801610 : if (generic)
417 123194780 : criterion = debug_struct_generic[usage];
418 : else
419 26606830 : criterion = debug_struct_ordinary[usage];
420 :
421 149801610 : if (criterion == DINFO_STRUCT_FILE_NONE)
422 : return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
423 149801399 : if (criterion == DINFO_STRUCT_FILE_ANY)
424 : return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
425 :
426 640 : type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
427 :
428 640 : if (type_decl != NULL)
429 : {
430 636 : if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
431 : return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
432 :
433 620 : if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
434 : return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
435 : }
436 :
437 : return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
438 : }
439 :
440 : /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
441 : switch to the data section instead, and write out a synthetic start label
442 : for collect2 the first time around. */
443 :
444 : static void
445 10 : switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED)
446 : {
447 10 : if (eh_frame_section == 0)
448 : {
449 10 : int flags;
450 :
451 10 : if (EH_TABLES_CAN_BE_READ_ONLY)
452 : {
453 10 : int fde_encoding;
454 10 : int per_encoding;
455 10 : int lsda_encoding;
456 :
457 10 : fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
458 : /*global=*/0);
459 10 : per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
460 : /*global=*/1);
461 10 : lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
462 : /*global=*/0);
463 20 : flags = ((! flag_pic
464 0 : || ((fde_encoding & 0x70) != DW_EH_PE_absptr
465 0 : && (fde_encoding & 0x70) != DW_EH_PE_aligned
466 0 : && (per_encoding & 0x70) != DW_EH_PE_absptr
467 0 : && (per_encoding & 0x70) != DW_EH_PE_aligned
468 0 : && (lsda_encoding & 0x70) != DW_EH_PE_absptr
469 0 : && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
470 10 : ? 0 : SECTION_WRITE);
471 : }
472 : else
473 : flags = SECTION_WRITE;
474 :
475 : #ifdef EH_FRAME_SECTION_NAME
476 10 : eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
477 : #else
478 : eh_frame_section = ((flags == SECTION_WRITE)
479 : ? data_section : readonly_data_section);
480 : #endif /* EH_FRAME_SECTION_NAME */
481 : }
482 :
483 10 : switch_to_section (eh_frame_section);
484 :
485 : #ifdef EH_FRAME_THROUGH_COLLECT2
486 : /* We have no special eh_frame section. Emit special labels to guide
487 : collect2. */
488 : if (!back)
489 : {
490 : tree label = get_file_function_name ("F");
491 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
492 : targetm.asm_out.globalize_label (asm_out_file,
493 : IDENTIFIER_POINTER (label));
494 : ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
495 : }
496 : #endif
497 10 : }
498 :
499 : /* Switch [BACK] to the eh or debug frame table section, depending on
500 : FOR_EH. */
501 :
502 : static void
503 19 : switch_to_frame_table_section (int for_eh, bool back)
504 : {
505 19 : if (for_eh)
506 10 : switch_to_eh_frame_section (back);
507 : else
508 : {
509 9 : if (!debug_frame_section)
510 9 : debug_frame_section = get_section (DEBUG_FRAME_SECTION,
511 : SECTION_DEBUG, NULL);
512 9 : switch_to_section (debug_frame_section);
513 : }
514 19 : }
515 :
516 : /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
517 :
518 : enum dw_cfi_oprnd_type
519 40617792 : dw_cfi_oprnd1_desc (dwarf_call_frame_info cfi)
520 : {
521 40617792 : switch (cfi)
522 : {
523 : case DW_CFA_nop:
524 : case DW_CFA_remember_state:
525 : case DW_CFA_restore_state:
526 : return dw_cfi_oprnd_unused;
527 :
528 76 : case DW_CFA_set_loc:
529 76 : case DW_CFA_advance_loc1:
530 76 : case DW_CFA_advance_loc2:
531 76 : case DW_CFA_advance_loc4:
532 76 : case DW_CFA_MIPS_advance_loc8:
533 76 : return dw_cfi_oprnd_addr;
534 :
535 13226194 : case DW_CFA_offset:
536 13226194 : case DW_CFA_offset_extended:
537 13226194 : case DW_CFA_def_cfa:
538 13226194 : case DW_CFA_offset_extended_sf:
539 13226194 : case DW_CFA_def_cfa_sf:
540 13226194 : case DW_CFA_restore:
541 13226194 : case DW_CFA_restore_extended:
542 13226194 : case DW_CFA_undefined:
543 13226194 : case DW_CFA_same_value:
544 13226194 : case DW_CFA_def_cfa_register:
545 13226194 : case DW_CFA_register:
546 13226194 : case DW_CFA_expression:
547 13226194 : case DW_CFA_val_expression:
548 13226194 : return dw_cfi_oprnd_reg_num;
549 :
550 25119370 : case DW_CFA_def_cfa_offset:
551 25119370 : case DW_CFA_GNU_args_size:
552 25119370 : case DW_CFA_def_cfa_offset_sf:
553 25119370 : return dw_cfi_oprnd_offset;
554 :
555 13690 : case DW_CFA_def_cfa_expression:
556 13690 : return dw_cfi_oprnd_loc;
557 :
558 0 : default:
559 0 : {
560 0 : dw_cfi_oprnd_type oprnd_type;
561 0 : if (targetm.dw_cfi_oprnd1_desc (cfi, oprnd_type))
562 0 : return oprnd_type;
563 : else
564 0 : gcc_unreachable ();
565 : }
566 : }
567 : }
568 :
569 : /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
570 :
571 : enum dw_cfi_oprnd_type
572 40617792 : dw_cfi_oprnd2_desc (dwarf_call_frame_info cfi)
573 : {
574 40617792 : switch (cfi)
575 : {
576 : case DW_CFA_def_cfa:
577 : case DW_CFA_def_cfa_sf:
578 : case DW_CFA_offset:
579 : case DW_CFA_offset_extended_sf:
580 : case DW_CFA_offset_extended:
581 : return dw_cfi_oprnd_offset;
582 :
583 0 : case DW_CFA_register:
584 0 : return dw_cfi_oprnd_reg_num;
585 :
586 204890 : case DW_CFA_expression:
587 204890 : case DW_CFA_val_expression:
588 204890 : return dw_cfi_oprnd_loc;
589 :
590 13690 : case DW_CFA_def_cfa_expression:
591 13690 : return dw_cfi_oprnd_cfa_loc;
592 :
593 33715435 : default:
594 33715435 : return dw_cfi_oprnd_unused;
595 : }
596 : }
597 :
598 : /* Output one FDE. */
599 :
600 : static void
601 52 : output_fde (dw_fde_ref fde, bool for_eh, bool second,
602 : char *section_start_label, int fde_encoding, char *augmentation,
603 : bool any_lsda_needed, int lsda_encoding)
604 : {
605 52 : const char *begin, *end;
606 52 : static unsigned int j;
607 52 : char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
608 :
609 52 : targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
610 : /* empty */ 0);
611 52 : targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
612 52 : for_eh + j);
613 52 : ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
614 52 : ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
615 52 : if (!XCOFF_DEBUGGING_INFO || for_eh)
616 : {
617 52 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
618 0 : dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
619 : " indicating 64-bit DWARF extension");
620 80 : dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
621 : "FDE Length");
622 : }
623 52 : ASM_OUTPUT_LABEL (asm_out_file, l1);
624 :
625 52 : if (for_eh)
626 28 : dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
627 : else
628 24 : dw2_asm_output_offset (dwarf_offset_size, section_start_label,
629 : debug_frame_section, "FDE CIE offset");
630 :
631 52 : begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
632 52 : end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
633 :
634 52 : if (for_eh)
635 : {
636 28 : rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
637 28 : SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
638 28 : dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
639 : "FDE initial location");
640 28 : dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
641 : end, begin, "FDE address range");
642 : }
643 : else
644 : {
645 24 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
646 24 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
647 : }
648 :
649 52 : if (augmentation[0])
650 : {
651 28 : if (any_lsda_needed)
652 : {
653 28 : int size = size_of_encoded_value (lsda_encoding);
654 :
655 28 : if (lsda_encoding == DW_EH_PE_aligned)
656 : {
657 0 : int offset = ( 4 /* Length */
658 : + 4 /* CIE offset */
659 0 : + 2 * size_of_encoded_value (fde_encoding)
660 0 : + 1 /* Augmentation size */ );
661 0 : int pad = -offset & (PTR_SIZE - 1);
662 :
663 0 : size += pad;
664 0 : gcc_assert (size_of_uleb128 (size) == 1);
665 : }
666 :
667 28 : dw2_asm_output_data_uleb128 (size, "Augmentation size");
668 :
669 28 : if (fde->uses_eh_lsda)
670 : {
671 28 : ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
672 : fde->funcdef_number);
673 17 : dw2_asm_output_encoded_addr_rtx (lsda_encoding,
674 17 : gen_rtx_SYMBOL_REF (Pmode, l1),
675 : false,
676 : "Language Specific Data Area");
677 : }
678 : else
679 : {
680 11 : if (lsda_encoding == DW_EH_PE_aligned)
681 0 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
682 11 : dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
683 : "Language Specific Data Area (none)");
684 : }
685 : }
686 : else
687 0 : dw2_asm_output_data_uleb128 (0, "Augmentation size");
688 : }
689 :
690 : /* Loop through the Call Frame Instructions associated with this FDE. */
691 52 : fde->dw_fde_current_label = begin;
692 52 : {
693 52 : size_t from, until, i;
694 :
695 52 : from = 0;
696 52 : until = vec_safe_length (fde->dw_fde_cfi);
697 :
698 52 : if (fde->dw_fde_second_begin == NULL)
699 : ;
700 24 : else if (!second)
701 12 : until = fde->dw_fde_switch_cfi_index;
702 : else
703 12 : from = fde->dw_fde_switch_cfi_index;
704 :
705 280 : for (i = from; i < until; i++)
706 228 : output_cfi ((*fde->dw_fde_cfi)[i], fde, for_eh);
707 : }
708 :
709 : /* If we are to emit a ref/link from function bodies to their frame tables,
710 : do it now. This is typically performed to make sure that tables
711 : associated with functions are dragged with them and not discarded in
712 : garbage collecting links. We need to do this on a per function basis to
713 : cope with -ffunction-sections. */
714 :
715 : #ifdef ASM_OUTPUT_DWARF_TABLE_REF
716 : /* Switch to the function section, emit the ref to the tables, and
717 : switch *back* into the table section. */
718 : switch_to_section (function_section (fde->decl));
719 : ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
720 : switch_to_frame_table_section (for_eh, true);
721 : #endif
722 :
723 : /* Pad the FDE out to an address sized boundary. */
724 52 : ASM_OUTPUT_ALIGN (asm_out_file,
725 : floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
726 52 : ASM_OUTPUT_LABEL (asm_out_file, l2);
727 :
728 52 : j += 2;
729 52 : }
730 :
731 : /* Return true if frame description entry FDE is needed for EH. */
732 :
733 : static bool
734 35 : fde_needed_for_eh_p (dw_fde_ref fde)
735 : {
736 35 : if (flag_asynchronous_unwind_tables)
737 : return true;
738 :
739 8 : if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
740 : return true;
741 :
742 8 : if (fde->uses_eh_lsda)
743 : return true;
744 :
745 : /* If exceptions are enabled, we have collected nothrow info. */
746 6 : if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
747 2 : return false;
748 :
749 : return true;
750 : }
751 :
752 : /* Output the call frame information used to record information
753 : that relates to calculating the frame pointer, and records the
754 : location of saved registers. */
755 :
756 : static void
757 263207 : output_call_frame_info (int for_eh)
758 : {
759 263207 : unsigned int i;
760 263207 : dw_fde_ref fde;
761 263207 : dw_cfi_ref cfi;
762 263207 : char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
763 263207 : char section_start_label[MAX_ARTIFICIAL_LABEL_BYTES];
764 263207 : bool any_lsda_needed = false;
765 263207 : char augmentation[6];
766 263207 : int augmentation_size;
767 263207 : int fde_encoding = DW_EH_PE_absptr;
768 263207 : int per_encoding = DW_EH_PE_absptr;
769 263207 : int lsda_encoding = DW_EH_PE_absptr;
770 263207 : int return_reg;
771 263207 : rtx personality = NULL;
772 263207 : int dw_cie_version;
773 :
774 : /* Don't emit a CIE if there won't be any FDEs. */
775 263207 : if (!fde_vec)
776 263188 : return;
777 :
778 : /* Nothing to do if the assembler's doing it all. */
779 258698 : if (dwarf2out_do_cfi_asm ())
780 : return;
781 :
782 : /* If we don't have any functions we'll want to unwind out of, don't emit
783 : any EH unwind information. If we make FDEs linkonce, we may have to
784 : emit an empty label for an FDE that wouldn't otherwise be emitted. We
785 : want to avoid having an FDE kept around when the function it refers to
786 : is discarded. Example where this matters: a primary function template
787 : in C++ requires EH information, an explicit specialization doesn't. */
788 19 : if (for_eh)
789 : {
790 : bool any_eh_needed = false;
791 :
792 33 : FOR_EACH_VEC_ELT (*fde_vec, i, fde)
793 : {
794 23 : if (fde->uses_eh_lsda)
795 : any_eh_needed = any_lsda_needed = true;
796 12 : else if (fde_needed_for_eh_p (fde))
797 11 : any_eh_needed = true;
798 : else if (TARGET_USES_WEAK_UNWIND_INFO)
799 : targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
800 : }
801 :
802 10 : if (!any_eh_needed)
803 : return;
804 : }
805 :
806 : /* We're going to be generating comments, so turn on app. */
807 19 : if (flag_debug_asm)
808 0 : app_enable ();
809 :
810 : /* Switch to the proper frame section, first time. */
811 19 : switch_to_frame_table_section (for_eh, false);
812 :
813 19 : ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
814 19 : ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
815 :
816 : /* Output the CIE. */
817 19 : ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
818 19 : ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
819 19 : if (!XCOFF_DEBUGGING_INFO || for_eh)
820 : {
821 19 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
822 0 : dw2_asm_output_data (4, 0xffffffff,
823 : "Initial length escape value indicating 64-bit DWARF extension");
824 29 : dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
825 : "Length of Common Information Entry");
826 : }
827 19 : ASM_OUTPUT_LABEL (asm_out_file, l1);
828 :
829 : /* Now that the CIE pointer is PC-relative for EH,
830 : use 0 to identify the CIE. */
831 28 : dw2_asm_output_data ((for_eh ? 4 : dwarf_offset_size),
832 9 : (for_eh ? 0 : DWARF_CIE_ID),
833 : "CIE Identifier Tag");
834 :
835 : /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
836 : use CIE version 1, unless that would produce incorrect results
837 : due to overflowing the return register column. */
838 19 : return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
839 19 : dw_cie_version = 1;
840 19 : if (return_reg >= 256 || dwarf_version > 2)
841 1 : dw_cie_version = 3;
842 19 : dw2_asm_output_data (1, dw_cie_version, "CIE Version");
843 :
844 19 : augmentation[0] = 0;
845 19 : augmentation_size = 0;
846 :
847 19 : personality = current_unit_personality;
848 19 : if (for_eh)
849 : {
850 10 : char *p;
851 :
852 : /* Augmentation:
853 : z Indicates that a uleb128 is present to size the
854 : augmentation section.
855 : L Indicates the encoding (and thus presence) of
856 : an LSDA pointer in the FDE augmentation.
857 : R Indicates a non-default pointer encoding for
858 : FDE code pointers.
859 : P Indicates the presence of an encoding + language
860 : personality routine in the CIE augmentation. */
861 :
862 10 : fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
863 10 : per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
864 10 : lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
865 :
866 10 : p = augmentation + 1;
867 10 : if (personality)
868 : {
869 10 : *p++ = 'P';
870 10 : augmentation_size += 1 + size_of_encoded_value (per_encoding);
871 10 : assemble_external_libcall (personality);
872 : }
873 10 : if (any_lsda_needed)
874 : {
875 10 : *p++ = 'L';
876 10 : augmentation_size += 1;
877 : }
878 10 : if (fde_encoding != DW_EH_PE_absptr)
879 : {
880 10 : *p++ = 'R';
881 10 : augmentation_size += 1;
882 : }
883 10 : if (p > augmentation + 1)
884 : {
885 10 : augmentation[0] = 'z';
886 10 : *p = '\0';
887 : }
888 :
889 : /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
890 10 : if (personality && per_encoding == DW_EH_PE_aligned)
891 : {
892 0 : int offset = ( 4 /* Length */
893 : + 4 /* CIE Id */
894 : + 1 /* CIE version */
895 0 : + strlen (augmentation) + 1 /* Augmentation */
896 0 : + size_of_uleb128 (1) /* Code alignment */
897 0 : + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
898 : + 1 /* RA column */
899 : + 1 /* Augmentation size */
900 0 : + 1 /* Personality encoding */ );
901 0 : int pad = -offset & (PTR_SIZE - 1);
902 :
903 0 : augmentation_size += pad;
904 :
905 : /* Augmentations should be small, so there's scarce need to
906 : iterate for a solution. Die if we exceed one uleb128 byte. */
907 0 : gcc_assert (size_of_uleb128 (augmentation_size) == 1);
908 : }
909 : }
910 :
911 19 : dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
912 19 : if (dw_cie_version >= 4)
913 : {
914 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
915 : dw2_asm_output_data (1, 0, "CIE Segment Size");
916 : }
917 19 : dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
918 19 : dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
919 : "CIE Data Alignment Factor");
920 :
921 19 : if (dw_cie_version == 1)
922 18 : dw2_asm_output_data (1, return_reg, "CIE RA Column");
923 : else
924 1 : dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
925 :
926 19 : if (augmentation[0])
927 : {
928 10 : dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
929 10 : if (personality)
930 : {
931 10 : dw2_asm_output_data (1, per_encoding, "Personality (%s)",
932 : eh_data_format_name (per_encoding));
933 10 : dw2_asm_output_encoded_addr_rtx (per_encoding,
934 : personality,
935 : true, NULL);
936 : }
937 :
938 10 : if (any_lsda_needed)
939 10 : dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
940 : eh_data_format_name (lsda_encoding));
941 :
942 10 : if (fde_encoding != DW_EH_PE_absptr)
943 10 : dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
944 : eh_data_format_name (fde_encoding));
945 : }
946 :
947 57 : FOR_EACH_VEC_ELT (*cie_cfi_vec, i, cfi)
948 38 : output_cfi (cfi, NULL, for_eh);
949 :
950 : /* Pad the CIE out to an address sized boundary. */
951 19 : ASM_OUTPUT_ALIGN (asm_out_file,
952 : floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
953 19 : ASM_OUTPUT_LABEL (asm_out_file, l2);
954 :
955 : /* Loop through all of the FDE's. */
956 60 : FOR_EACH_VEC_ELT (*fde_vec, i, fde)
957 : {
958 41 : unsigned int k;
959 :
960 : /* Don't emit EH unwind info for leaf functions that don't need it. */
961 41 : if (for_eh && !fde_needed_for_eh_p (fde))
962 1 : continue;
963 :
964 148 : for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
965 52 : output_fde (fde, for_eh, k, section_start_label, fde_encoding,
966 : augmentation, any_lsda_needed, lsda_encoding);
967 : }
968 :
969 19 : if (for_eh && targetm.terminate_dw2_eh_frame_info)
970 0 : dw2_asm_output_data (4, 0, "End of Table");
971 :
972 : /* Turn off app to make assembly quicker. */
973 19 : if (flag_debug_asm)
974 0 : app_disable ();
975 : }
976 :
977 : /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
978 :
979 : static void
980 1549949 : dwarf2out_do_cfi_startproc (bool second)
981 : {
982 1549949 : int enc;
983 1549949 : rtx ref;
984 :
985 1549949 : fprintf (asm_out_file, "\t.cfi_startproc\n");
986 :
987 1549949 : targetm.asm_out.post_cfi_startproc (asm_out_file, current_function_decl);
988 :
989 : /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
990 : eh unwinders. */
991 1549949 : if (targetm_common.except_unwind_info (&global_options) != UI_DWARF2)
992 : return;
993 :
994 1549949 : rtx personality = get_personality_function (current_function_decl);
995 :
996 1549949 : if (personality)
997 : {
998 75358 : enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
999 75358 : ref = personality;
1000 :
1001 : /* ??? The GAS support isn't entirely consistent. We have to
1002 : handle indirect support ourselves, but PC-relative is done
1003 : in the assembler. Further, the assembler can't handle any
1004 : of the weirder relocation types. */
1005 75358 : if (enc & DW_EH_PE_indirect)
1006 : {
1007 6108 : if (targetm.asm_out.make_eh_symbol_indirect != NULL)
1008 0 : ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
1009 : else
1010 6108 : ref = dw2_force_const_mem (ref, true);
1011 : }
1012 :
1013 75358 : fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
1014 75358 : output_addr_const (asm_out_file, ref);
1015 75358 : fputc ('\n', asm_out_file);
1016 : }
1017 :
1018 1549949 : if (crtl->uses_eh_lsda)
1019 : {
1020 75290 : char lab[MAX_ARTIFICIAL_LABEL_BYTES];
1021 :
1022 75290 : enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1023 137125 : ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
1024 : current_function_funcdef_no);
1025 81067 : ref = gen_rtx_SYMBOL_REF (Pmode, lab);
1026 75290 : SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
1027 :
1028 75290 : if (enc & DW_EH_PE_indirect)
1029 : {
1030 0 : if (targetm.asm_out.make_eh_symbol_indirect != NULL)
1031 0 : ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
1032 : else
1033 0 : ref = dw2_force_const_mem (ref, true);
1034 : }
1035 :
1036 75290 : fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
1037 75290 : output_addr_const (asm_out_file, ref);
1038 75290 : fputc ('\n', asm_out_file);
1039 : }
1040 : }
1041 :
1042 : /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1043 : this allocation may be done before pass_final. */
1044 :
1045 : dw_fde_ref
1046 1486238 : dwarf2out_alloc_current_fde (void)
1047 : {
1048 1486238 : dw_fde_ref fde;
1049 :
1050 1486238 : fde = ggc_cleared_alloc<dw_fde_node> ();
1051 1486238 : fde->decl = current_function_decl;
1052 1486238 : fde->funcdef_number = current_function_funcdef_no;
1053 1486238 : fde->fde_index = vec_safe_length (fde_vec);
1054 1486238 : fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1055 1486238 : fde->uses_eh_lsda = crtl->uses_eh_lsda;
1056 1486238 : fde->nothrow = crtl->nothrow;
1057 1486238 : fde->drap_reg = INVALID_REGNUM;
1058 1486238 : fde->vdrap_reg = INVALID_REGNUM;
1059 :
1060 : /* Record the FDE associated with this function. */
1061 1486238 : cfun->fde = fde;
1062 1486238 : vec_safe_push (fde_vec, fde);
1063 :
1064 1486238 : return fde;
1065 : }
1066 :
1067 : /* Output a marker (i.e. a label) for the beginning of a function, before
1068 : the prologue. */
1069 :
1070 : void
1071 1486293 : dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1072 : unsigned int column ATTRIBUTE_UNUSED,
1073 : const char *file ATTRIBUTE_UNUSED)
1074 : {
1075 1486293 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1076 1486293 : char * dup_label;
1077 1486293 : dw_fde_ref fde;
1078 1486293 : section *fnsec;
1079 1486293 : bool do_frame;
1080 :
1081 1486293 : current_function_func_begin_label = NULL;
1082 :
1083 1486293 : do_frame = dwarf2out_do_frame ();
1084 :
1085 : /* ??? current_function_func_begin_label is also used by except.cc for
1086 : call-site information. We must emit this label if it might be used. */
1087 1486293 : if (!do_frame
1088 1486293 : && (!flag_exceptions
1089 0 : || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
1090 55 : return;
1091 :
1092 1486238 : fnsec = function_section (current_function_decl);
1093 1486238 : switch_to_section (fnsec);
1094 1486238 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1095 : current_function_funcdef_no);
1096 1486238 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1097 : current_function_funcdef_no);
1098 1486238 : dup_label = xstrdup (label);
1099 1486238 : current_function_func_begin_label = dup_label;
1100 :
1101 : /* We can elide FDE allocation if we're not emitting frame unwind info. */
1102 1486238 : if (!do_frame)
1103 : return;
1104 :
1105 : /* Unlike the debug version, the EH version of frame unwind info is a per-
1106 : function setting so we need to record whether we need it for the unit. */
1107 1486238 : do_eh_frame |= dwarf2out_do_eh_frame ();
1108 :
1109 : /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1110 : emit insns as rtx but bypass the bulk of rest_of_compilation, which
1111 : would include pass_dwarf2_frame. If we've not created the FDE yet,
1112 : do so now. */
1113 1486238 : fde = cfun->fde;
1114 1486238 : if (fde == NULL)
1115 5343 : fde = dwarf2out_alloc_current_fde ();
1116 :
1117 : /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1118 1486238 : fde->dw_fde_begin = dup_label;
1119 1486238 : fde->dw_fde_current_label = dup_label;
1120 2972476 : fde->in_std_section = (fnsec == text_section
1121 1486238 : || (cold_text_section && fnsec == cold_text_section));
1122 1486238 : fde->ignored_debug = DECL_IGNORED_P (current_function_decl);
1123 1486238 : in_text_section_p = fnsec == text_section;
1124 :
1125 : /* We only want to output line number information for the genuine dwarf2
1126 : prologue case, not the eh frame case. */
1127 : #ifdef DWARF2_DEBUGGING_INFO
1128 1486238 : if (file)
1129 463524 : dwarf2out_source_line (line, column, file, 0, true);
1130 : #endif
1131 :
1132 1486238 : if (dwarf2out_do_cfi_asm ())
1133 1486215 : dwarf2out_do_cfi_startproc (false);
1134 : else
1135 : {
1136 23 : rtx personality = get_personality_function (current_function_decl);
1137 23 : if (!current_unit_personality)
1138 13 : current_unit_personality = personality;
1139 :
1140 : /* We cannot keep a current personality per function as without CFI
1141 : asm, at the point where we emit the CFI data, there is no current
1142 : function anymore. */
1143 23 : if (personality && current_unit_personality != personality)
1144 0 : sorry ("multiple EH personalities are supported only with assemblers "
1145 : "supporting %<.cfi_personality%> directive");
1146 : }
1147 : }
1148 :
1149 : /* Output a marker (i.e. a label) for the end of the generated code
1150 : for a function prologue. This gets called *after* the prologue code has
1151 : been generated. */
1152 :
1153 : void
1154 0 : dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
1155 : const char *file ATTRIBUTE_UNUSED)
1156 : {
1157 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1158 :
1159 : /* Output a label to mark the endpoint of the code generated for this
1160 : function. */
1161 0 : ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
1162 : current_function_funcdef_no);
1163 0 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
1164 : current_function_funcdef_no);
1165 0 : cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
1166 0 : }
1167 :
1168 : /* Output a marker (i.e. a label) for the beginning of the generated code
1169 : for a function epilogue. This gets called *before* the prologue code has
1170 : been generated. */
1171 :
1172 : void
1173 0 : dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1174 : const char *file ATTRIBUTE_UNUSED)
1175 : {
1176 0 : dw_fde_ref fde = cfun->fde;
1177 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1178 :
1179 0 : if (fde->dw_fde_vms_begin_epilogue)
1180 0 : return;
1181 :
1182 : /* Output a label to mark the endpoint of the code generated for this
1183 : function. */
1184 0 : ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
1185 : current_function_funcdef_no);
1186 0 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
1187 : current_function_funcdef_no);
1188 0 : fde->dw_fde_vms_begin_epilogue = xstrdup (label);
1189 : }
1190 :
1191 : /* Mark the ranges of non-debug subsections in the std text sections. */
1192 :
1193 : static void
1194 1549978 : mark_ignored_debug_section (dw_fde_ref fde, bool second)
1195 : {
1196 1549978 : bool std_section;
1197 1549978 : const char *begin_label, *end_label;
1198 1549978 : const char **last_end_label;
1199 1549978 : vec<const char *, va_gc> **switch_ranges;
1200 :
1201 1549978 : if (second)
1202 : {
1203 63740 : std_section = fde->second_in_std_section;
1204 63740 : begin_label = fde->dw_fde_second_begin;
1205 63740 : end_label = fde->dw_fde_second_end;
1206 : }
1207 : else
1208 : {
1209 1486238 : std_section = fde->in_std_section;
1210 1486238 : begin_label = fde->dw_fde_begin;
1211 1486238 : end_label = fde->dw_fde_end;
1212 : }
1213 :
1214 1549978 : if (!std_section)
1215 368104 : return;
1216 :
1217 1181874 : if (in_text_section_p)
1218 : {
1219 : last_end_label = &last_text_label;
1220 : switch_ranges = &switch_text_ranges;
1221 : }
1222 : else
1223 : {
1224 11517 : last_end_label = &last_cold_label;
1225 11517 : switch_ranges = &switch_cold_ranges;
1226 : }
1227 :
1228 1181874 : if (fde->ignored_debug)
1229 : {
1230 14789 : if (*switch_ranges && !(vec_safe_length (*switch_ranges) & 1))
1231 6467 : vec_safe_push (*switch_ranges, *last_end_label);
1232 : }
1233 : else
1234 : {
1235 1167085 : *last_end_label = end_label;
1236 :
1237 1167085 : if (!*switch_ranges)
1238 185920 : vec_alloc (*switch_ranges, 16);
1239 981165 : else if (vec_safe_length (*switch_ranges) & 1)
1240 4065 : vec_safe_push (*switch_ranges, begin_label);
1241 : }
1242 : }
1243 :
1244 : /* Output a marker (i.e. a label) for the absolute end of the generated code
1245 : for a function definition. This gets called *after* the epilogue code has
1246 : been generated. */
1247 :
1248 : void
1249 1486238 : dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1250 : const char *file ATTRIBUTE_UNUSED)
1251 : {
1252 1486238 : dw_fde_ref fde;
1253 1486238 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1254 :
1255 1486238 : last_var_location_insn = NULL;
1256 1486238 : cached_next_real_insn = NULL;
1257 :
1258 1486238 : if (dwarf2out_do_cfi_asm ())
1259 1486215 : fprintf (asm_out_file, "\t.cfi_endproc\n");
1260 :
1261 : #ifdef CODEVIEW_DEBUGGING_INFO
1262 : if (codeview_debuginfo_p ())
1263 : codeview_end_epilogue ();
1264 : #endif
1265 :
1266 : /* Output a label to mark the endpoint of the code generated for this
1267 : function. */
1268 1486238 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1269 : current_function_funcdef_no);
1270 1486238 : ASM_OUTPUT_LABEL (asm_out_file, label);
1271 1486238 : fde = cfun->fde;
1272 1486238 : gcc_assert (fde != NULL);
1273 1486238 : if (fde->dw_fde_second_begin == NULL)
1274 1422498 : fde->dw_fde_end = xstrdup (label);
1275 :
1276 1486238 : mark_ignored_debug_section (fde, fde->dw_fde_second_begin != NULL);
1277 1486238 : }
1278 :
1279 : void
1280 232352 : dwarf2out_frame_finish (void)
1281 : {
1282 : /* Output call frame information. */
1283 232352 : if (targetm.debug_unwind_info () == UI_DWARF2)
1284 52080 : output_call_frame_info (0);
1285 :
1286 : /* Output another copy for the unwinder. */
1287 232352 : if (do_eh_frame)
1288 211127 : output_call_frame_info (1);
1289 232352 : }
1290 :
1291 : static void var_location_switch_text_section (void);
1292 : static void set_cur_line_info_table (section *);
1293 :
1294 : void
1295 63740 : dwarf2out_switch_text_section (void)
1296 : {
1297 63740 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1298 63740 : section *sect;
1299 63740 : dw_fde_ref fde = cfun->fde;
1300 :
1301 63740 : gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1302 :
1303 63740 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_SECOND_SECT_LABEL,
1304 : current_function_funcdef_no);
1305 :
1306 63740 : fde->dw_fde_second_begin = ggc_strdup (label);
1307 63740 : if (!in_cold_section_p)
1308 : {
1309 0 : fde->dw_fde_end = crtl->subsections.cold_section_end_label;
1310 0 : fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
1311 : }
1312 : else
1313 : {
1314 63740 : fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1315 63740 : fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1316 : }
1317 63740 : have_multiple_function_sections = true;
1318 :
1319 : #ifdef CODEVIEW_DEBUGGING_INFO
1320 : if (codeview_debuginfo_p ())
1321 : codeview_switch_text_section ();
1322 : #endif
1323 :
1324 63740 : if (dwarf2out_do_cfi_asm ())
1325 63734 : fprintf (asm_out_file, "\t.cfi_endproc\n");
1326 :
1327 63740 : mark_ignored_debug_section (fde, false);
1328 :
1329 : /* Now do the real section switch. */
1330 63740 : sect = current_function_section ();
1331 63740 : switch_to_section (sect);
1332 :
1333 63740 : fde->second_in_std_section
1334 127480 : = (sect == text_section
1335 63740 : || (cold_text_section && sect == cold_text_section));
1336 63740 : in_text_section_p = sect == text_section;
1337 :
1338 63740 : if (dwarf2out_do_cfi_asm ())
1339 63734 : dwarf2out_do_cfi_startproc (true);
1340 :
1341 63740 : var_location_switch_text_section ();
1342 :
1343 63740 : if (cold_text_section != NULL)
1344 20942 : set_cur_line_info_table (sect);
1345 63740 : }
1346 :
1347 : /* And now, the subset of the debugging information support code necessary
1348 : for emitting location expressions. */
1349 :
1350 : /* Describe an entry into the .debug_addr section. */
1351 :
1352 : enum ate_kind {
1353 : ate_kind_rtx,
1354 : ate_kind_rtx_dtprel,
1355 : ate_kind_label
1356 : };
1357 :
1358 : struct GTY((for_user)) addr_table_entry {
1359 : enum ate_kind kind;
1360 : unsigned int refcount;
1361 : unsigned int index;
1362 : union addr_table_entry_struct_union
1363 : {
1364 : rtx GTY ((tag ("0"))) rtl;
1365 : char * GTY ((tag ("1"))) label;
1366 : }
1367 : GTY ((desc ("%1.kind"))) addr;
1368 : };
1369 :
1370 : static dw_loc_descr_ref int_loc_descriptor (poly_int64);
1371 : static dw_loc_descr_ref uint_loc_descriptor (unsigned HOST_WIDE_INT);
1372 :
1373 : /* Convert a DWARF stack opcode into its string name. */
1374 :
1375 : static const char *
1376 61552698 : dwarf_stack_op_name (unsigned int op)
1377 : {
1378 0 : const char *name = get_DW_OP_name (op);
1379 :
1380 61552698 : if (name != NULL)
1381 61552698 : return name;
1382 :
1383 : return "OP_<unknown>";
1384 : }
1385 :
1386 : /* Return TRUE iff we're to output location view lists as a separate
1387 : attribute next to the location lists, as an extension compatible
1388 : with DWARF 2 and above. */
1389 :
1390 : static inline bool
1391 56954268 : dwarf2out_locviews_in_attribute ()
1392 : {
1393 56954268 : return debug_variable_location_views == 1;
1394 : }
1395 :
1396 : /* Return TRUE iff we're to output location view lists as part of the
1397 : location lists, as proposed for standardization after DWARF 5. */
1398 :
1399 : static inline bool
1400 24101081 : dwarf2out_locviews_in_loclist ()
1401 : {
1402 : #ifndef DW_LLE_view_pair
1403 : return false;
1404 : #else
1405 24101081 : return debug_variable_location_views == -1;
1406 : #endif
1407 : }
1408 :
1409 : /* Return a pointer to a newly allocated location description. Location
1410 : descriptions are simple expression terms that can be strung
1411 : together to form more complicated location (address) descriptions. */
1412 :
1413 : static inline dw_loc_descr_ref
1414 64580141 : new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1415 : unsigned HOST_WIDE_INT oprnd2)
1416 : {
1417 64580141 : dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
1418 :
1419 64580141 : descr->dw_loc_opc = op;
1420 64580141 : descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1421 64580141 : descr->dw_loc_oprnd1.val_entry = NULL;
1422 64580141 : descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1423 64580141 : descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1424 64580141 : descr->dw_loc_oprnd2.val_entry = NULL;
1425 64580141 : descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1426 :
1427 64580141 : return descr;
1428 : }
1429 :
1430 : /* Add a location description term to a location description expression. */
1431 :
1432 : static inline void
1433 21613227 : add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1434 : {
1435 21613227 : dw_loc_descr_ref *d;
1436 :
1437 : /* Find the end of the chain. */
1438 126544451 : for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1439 : ;
1440 :
1441 21828225 : *d = descr;
1442 15893306 : }
1443 :
1444 : /* Compare two location operands for exact equality. */
1445 :
1446 : static bool
1447 19904658 : dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1448 : {
1449 19904658 : if (a->val_class != b->val_class)
1450 : return false;
1451 19904658 : switch (a->val_class)
1452 : {
1453 : case dw_val_class_none:
1454 : return true;
1455 0 : case dw_val_class_addr:
1456 0 : return rtx_equal_p (a->v.val_addr, b->v.val_addr);
1457 :
1458 13538153 : case dw_val_class_offset:
1459 13538153 : case dw_val_class_unsigned_const:
1460 13538153 : case dw_val_class_const:
1461 13538153 : case dw_val_class_unsigned_const_implicit:
1462 13538153 : case dw_val_class_const_implicit:
1463 13538153 : case dw_val_class_range_list:
1464 : /* These are all HOST_WIDE_INT, signed or unsigned. */
1465 13538153 : return a->v.val_unsigned == b->v.val_unsigned;
1466 :
1467 0 : case dw_val_class_loc:
1468 0 : return a->v.val_loc == b->v.val_loc;
1469 0 : case dw_val_class_loc_list:
1470 0 : return a->v.val_loc_list == b->v.val_loc_list;
1471 0 : case dw_val_class_view_list:
1472 0 : return a->v.val_view_list == b->v.val_view_list;
1473 0 : case dw_val_class_die_ref:
1474 0 : return a->v.val_die_ref.die == b->v.val_die_ref.die;
1475 0 : case dw_val_class_fde_ref:
1476 0 : return a->v.val_fde_index == b->v.val_fde_index;
1477 0 : case dw_val_class_symview:
1478 0 : return strcmp (a->v.val_symbolic_view, b->v.val_symbolic_view) == 0;
1479 0 : case dw_val_class_lbl_id:
1480 0 : case dw_val_class_lineptr:
1481 0 : case dw_val_class_macptr:
1482 0 : case dw_val_class_loclistsptr:
1483 0 : case dw_val_class_high_pc:
1484 0 : return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
1485 0 : case dw_val_class_str:
1486 0 : return a->v.val_str == b->v.val_str;
1487 0 : case dw_val_class_flag:
1488 0 : return a->v.val_flag == b->v.val_flag;
1489 6366505 : case dw_val_class_file:
1490 6366505 : case dw_val_class_file_implicit:
1491 6366505 : return a->v.val_file == b->v.val_file;
1492 0 : case dw_val_class_decl_ref:
1493 0 : return a->v.val_decl_ref == b->v.val_decl_ref;
1494 :
1495 0 : case dw_val_class_const_double:
1496 0 : return (a->v.val_double.high == b->v.val_double.high
1497 0 : && a->v.val_double.low == b->v.val_double.low);
1498 :
1499 0 : case dw_val_class_wide_int:
1500 0 : return *a->v.val_wide == *b->v.val_wide;
1501 :
1502 0 : case dw_val_class_vec:
1503 0 : {
1504 0 : size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
1505 0 : size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
1506 :
1507 0 : return (a_len == b_len
1508 0 : && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
1509 : }
1510 :
1511 0 : case dw_val_class_data8:
1512 0 : return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
1513 :
1514 0 : case dw_val_class_vms_delta:
1515 0 : return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
1516 0 : && !strcmp (a->v.val_vms_delta.lbl2, b->v.val_vms_delta.lbl2));
1517 :
1518 0 : case dw_val_class_discr_value:
1519 0 : return (a->v.val_discr_value.pos == b->v.val_discr_value.pos
1520 0 : && a->v.val_discr_value.v.uval == b->v.val_discr_value.v.uval);
1521 : case dw_val_class_discr_list:
1522 : /* It makes no sense comparing two discriminant value lists. */
1523 : return false;
1524 : }
1525 0 : gcc_unreachable ();
1526 : }
1527 :
1528 : /* Compare two location atoms for exact equality. */
1529 :
1530 : static bool
1531 36 : loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
1532 : {
1533 36 : if (a->dw_loc_opc != b->dw_loc_opc)
1534 : return false;
1535 :
1536 : /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1537 : address size, but since we always allocate cleared storage it
1538 : should be zero for other types of locations. */
1539 36 : if (a->dw_loc_dtprel != b->dw_loc_dtprel)
1540 : return false;
1541 :
1542 36 : return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
1543 36 : && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
1544 : }
1545 :
1546 : /* Compare two complete location expressions for exact equality. */
1547 :
1548 : bool
1549 24 : loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
1550 : {
1551 96 : while (1)
1552 : {
1553 60 : if (a == b)
1554 : return true;
1555 36 : if (a == NULL || b == NULL)
1556 : return false;
1557 36 : if (!loc_descr_equal_p_1 (a, b))
1558 : return false;
1559 :
1560 36 : a = a->dw_loc_next;
1561 36 : b = b->dw_loc_next;
1562 : }
1563 : }
1564 :
1565 :
1566 : /* Add a constant POLY_OFFSET to a location expression. */
1567 :
1568 : static void
1569 835999 : loc_descr_plus_const (dw_loc_descr_ref *list_head, poly_int64 poly_offset)
1570 : {
1571 835999 : dw_loc_descr_ref loc;
1572 835999 : HOST_WIDE_INT *p;
1573 :
1574 835999 : gcc_assert (*list_head != NULL);
1575 :
1576 835999 : if (known_eq (poly_offset, 0))
1577 835999 : return;
1578 :
1579 : /* Find the end of the chain. */
1580 2771736 : for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1581 : ;
1582 :
1583 828916 : HOST_WIDE_INT offset;
1584 828916 : if (!poly_offset.is_constant (&offset))
1585 : {
1586 : loc->dw_loc_next = int_loc_descriptor (poly_offset);
1587 : add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
1588 : return;
1589 : }
1590 :
1591 828916 : p = NULL;
1592 828916 : if (loc->dw_loc_opc == DW_OP_fbreg
1593 828916 : || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
1594 0 : p = &loc->dw_loc_oprnd1.v.val_int;
1595 828916 : else if (loc->dw_loc_opc == DW_OP_bregx)
1596 0 : p = &loc->dw_loc_oprnd2.v.val_int;
1597 :
1598 : /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1599 : offset. Don't optimize if an signed integer overflow would happen. */
1600 0 : if (p != NULL
1601 0 : && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
1602 0 : || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
1603 0 : *p += offset;
1604 :
1605 828916 : else if (offset > 0)
1606 703304 : loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1607 :
1608 : else
1609 : {
1610 125612 : loc->dw_loc_next
1611 125612 : = uint_loc_descriptor (-(unsigned HOST_WIDE_INT) offset);
1612 251224 : add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
1613 : }
1614 : }
1615 :
1616 : /* Return a pointer to a newly allocated location description for
1617 : REG and OFFSET. */
1618 :
1619 : static inline dw_loc_descr_ref
1620 4975177 : new_reg_loc_descr (unsigned int reg, poly_int64 offset)
1621 : {
1622 4975177 : HOST_WIDE_INT const_offset;
1623 4975177 : if (offset.is_constant (&const_offset))
1624 : {
1625 4975177 : if (reg <= 31)
1626 4975177 : return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1627 4975177 : const_offset, 0);
1628 : else
1629 0 : return new_loc_descr (DW_OP_bregx, reg, const_offset);
1630 : }
1631 : else
1632 : {
1633 : dw_loc_descr_ref ret = new_reg_loc_descr (reg, 0);
1634 : loc_descr_plus_const (&ret, offset);
1635 : return ret;
1636 : }
1637 : }
1638 :
1639 : /* Add a constant OFFSET to a location list. */
1640 :
1641 : static void
1642 75980 : loc_list_plus_const (dw_loc_list_ref list_head, poly_int64 offset)
1643 : {
1644 75980 : dw_loc_list_ref d;
1645 151960 : for (d = list_head; d != NULL; d = d->dw_loc_next)
1646 75980 : loc_descr_plus_const (&d->expr, offset);
1647 0 : }
1648 :
1649 : #define DWARF_REF_SIZE \
1650 : (dwarf_version == 2 ? DWARF2_ADDR_SIZE : dwarf_offset_size)
1651 :
1652 : /* The number of bits that can be encoded by largest DW_FORM_dataN.
1653 : In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
1654 : DW_FORM_data16 with 128 bits. */
1655 : #define DWARF_LARGEST_DATA_FORM_BITS \
1656 : (dwarf_version >= 5 ? 128 : 64)
1657 :
1658 : /* Utility inline function for construction of ops that were GNU extension
1659 : before DWARF 5. */
1660 : static inline enum dwarf_location_atom
1661 3662267 : dwarf_OP (enum dwarf_location_atom op)
1662 : {
1663 1727453 : switch (op)
1664 : {
1665 1919709 : case DW_OP_implicit_pointer:
1666 0 : if (dwarf_version < 5)
1667 466 : return DW_OP_GNU_implicit_pointer;
1668 : break;
1669 :
1670 1355892 : case DW_OP_entry_value:
1671 1355892 : if (dwarf_version < 5)
1672 806 : return DW_OP_GNU_entry_value;
1673 : break;
1674 :
1675 46477 : case DW_OP_const_type:
1676 46477 : if (dwarf_version < 5)
1677 9 : return DW_OP_GNU_const_type;
1678 : break;
1679 :
1680 109312 : case DW_OP_regval_type:
1681 109312 : if (dwarf_version < 5)
1682 111 : return DW_OP_GNU_regval_type;
1683 : break;
1684 :
1685 55980 : case DW_OP_deref_type:
1686 55980 : if (dwarf_version < 5)
1687 0 : return DW_OP_GNU_deref_type;
1688 : break;
1689 :
1690 173295 : case DW_OP_convert:
1691 158193 : if (dwarf_version < 5)
1692 0 : return DW_OP_GNU_convert;
1693 : break;
1694 :
1695 1599 : case DW_OP_reinterpret:
1696 1599 : if (dwarf_version < 5)
1697 0 : return DW_OP_GNU_reinterpret;
1698 : break;
1699 :
1700 3 : case DW_OP_addrx:
1701 3 : if (dwarf_version < 5)
1702 0 : return DW_OP_GNU_addr_index;
1703 : break;
1704 :
1705 0 : case DW_OP_constx:
1706 0 : if (dwarf_version < 5)
1707 0 : return DW_OP_GNU_const_index;
1708 : break;
1709 :
1710 : default:
1711 : break;
1712 : }
1713 : return op;
1714 : }
1715 :
1716 : /* Similarly for attributes. */
1717 : static inline enum dwarf_attribute
1718 9206380 : dwarf_AT (enum dwarf_attribute at)
1719 : {
1720 9206380 : switch (at)
1721 : {
1722 2842874 : case DW_AT_call_return_pc:
1723 2842874 : if (dwarf_version < 5)
1724 1855 : return DW_AT_low_pc;
1725 : break;
1726 :
1727 54637 : case DW_AT_call_tail_call:
1728 54637 : if (dwarf_version < 5)
1729 90 : return DW_AT_GNU_tail_call;
1730 : break;
1731 :
1732 2773654 : case DW_AT_call_origin:
1733 2773654 : if (dwarf_version < 5)
1734 1833 : return DW_AT_abstract_origin;
1735 : break;
1736 :
1737 5077 : case DW_AT_call_target:
1738 5077 : if (dwarf_version < 5)
1739 12 : return DW_AT_GNU_call_site_target;
1740 : break;
1741 :
1742 0 : case DW_AT_call_target_clobbered:
1743 0 : if (dwarf_version < 5)
1744 0 : return DW_AT_GNU_call_site_target_clobbered;
1745 : break;
1746 :
1747 32106 : case DW_AT_call_parameter:
1748 32106 : if (dwarf_version < 5)
1749 6 : return DW_AT_abstract_origin;
1750 : break;
1751 :
1752 2934315 : case DW_AT_call_value:
1753 2934315 : if (dwarf_version < 5)
1754 1491 : return DW_AT_GNU_call_site_value;
1755 : break;
1756 :
1757 6504 : case DW_AT_call_data_value:
1758 6504 : if (dwarf_version < 5)
1759 0 : return DW_AT_GNU_call_site_data_value;
1760 : break;
1761 :
1762 255259 : case DW_AT_call_all_calls:
1763 255259 : if (dwarf_version < 5)
1764 2338 : return DW_AT_GNU_all_call_sites;
1765 : break;
1766 :
1767 301461 : case DW_AT_call_all_tail_calls:
1768 301461 : if (dwarf_version < 5)
1769 1014 : return DW_AT_GNU_all_tail_call_sites;
1770 : break;
1771 :
1772 249 : case DW_AT_dwo_name:
1773 249 : if (dwarf_version < 5)
1774 1 : return DW_AT_GNU_dwo_name;
1775 : break;
1776 :
1777 244 : case DW_AT_addr_base:
1778 244 : if (dwarf_version < 5)
1779 0 : return DW_AT_GNU_addr_base;
1780 : break;
1781 :
1782 : default:
1783 : break;
1784 : }
1785 : return at;
1786 : }
1787 :
1788 : /* And similarly for tags. */
1789 : static inline enum dwarf_tag
1790 5777189 : dwarf_TAG (enum dwarf_tag tag)
1791 : {
1792 5777189 : switch (tag)
1793 : {
1794 2842874 : case DW_TAG_call_site:
1795 2842874 : if (dwarf_version < 5)
1796 1855 : return DW_TAG_GNU_call_site;
1797 : break;
1798 :
1799 2934315 : case DW_TAG_call_site_parameter:
1800 2934315 : if (dwarf_version < 5)
1801 1491 : return DW_TAG_GNU_call_site_parameter;
1802 : break;
1803 :
1804 : default:
1805 : break;
1806 : }
1807 : return tag;
1808 : }
1809 :
1810 : /* And similarly for forms. */
1811 : static inline enum dwarf_form
1812 25746173 : dwarf_FORM (enum dwarf_form form)
1813 : {
1814 25746173 : switch (form)
1815 : {
1816 506 : case DW_FORM_addrx:
1817 506 : if (dwarf_version < 5)
1818 : return DW_FORM_GNU_addr_index;
1819 : break;
1820 :
1821 25745667 : case DW_FORM_strx:
1822 25745667 : if (dwarf_version < 5)
1823 273990 : return DW_FORM_GNU_str_index;
1824 : break;
1825 :
1826 : default:
1827 : break;
1828 : }
1829 : return form;
1830 : }
1831 :
1832 : static unsigned long int get_base_type_offset (dw_die_ref);
1833 :
1834 : /* Return the size of a location descriptor. */
1835 :
1836 : static unsigned long
1837 186328740 : size_of_loc_descr (dw_loc_descr_ref loc)
1838 : {
1839 186328740 : unsigned long size = 1;
1840 :
1841 186328740 : switch (loc->dw_loc_opc)
1842 : {
1843 3469711 : case DW_OP_addr:
1844 3469711 : size += DWARF2_ADDR_SIZE;
1845 3469711 : break;
1846 6 : case DW_OP_GNU_addr_index:
1847 6 : case DW_OP_addrx:
1848 6 : case DW_OP_GNU_const_index:
1849 6 : case DW_OP_constx:
1850 6 : gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
1851 6 : size += size_of_uleb128 (loc->dw_loc_oprnd1.val_entry->index);
1852 6 : break;
1853 : case DW_OP_const1u:
1854 : case DW_OP_const1s:
1855 3688640 : size += 1;
1856 : break;
1857 : case DW_OP_const2u:
1858 : case DW_OP_const2s:
1859 1182926 : size += 2;
1860 : break;
1861 : case DW_OP_const4u:
1862 : case DW_OP_const4s:
1863 650315 : size += 4;
1864 : break;
1865 8759 : case DW_OP_const8u:
1866 8759 : case DW_OP_const8s:
1867 8759 : size += 8;
1868 8759 : break;
1869 445850 : case DW_OP_constu:
1870 445850 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1871 445850 : break;
1872 233579 : case DW_OP_consts:
1873 233579 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1874 233579 : break;
1875 : case DW_OP_pick:
1876 3688640 : size += 1;
1877 : break;
1878 4860214 : case DW_OP_plus_uconst:
1879 4860214 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1880 4860214 : break;
1881 : case DW_OP_skip:
1882 : case DW_OP_bra:
1883 1182926 : size += 2;
1884 : break;
1885 14425313 : case DW_OP_breg0:
1886 14425313 : case DW_OP_breg1:
1887 14425313 : case DW_OP_breg2:
1888 14425313 : case DW_OP_breg3:
1889 14425313 : case DW_OP_breg4:
1890 14425313 : case DW_OP_breg5:
1891 14425313 : case DW_OP_breg6:
1892 14425313 : case DW_OP_breg7:
1893 14425313 : case DW_OP_breg8:
1894 14425313 : case DW_OP_breg9:
1895 14425313 : case DW_OP_breg10:
1896 14425313 : case DW_OP_breg11:
1897 14425313 : case DW_OP_breg12:
1898 14425313 : case DW_OP_breg13:
1899 14425313 : case DW_OP_breg14:
1900 14425313 : case DW_OP_breg15:
1901 14425313 : case DW_OP_breg16:
1902 14425313 : case DW_OP_breg17:
1903 14425313 : case DW_OP_breg18:
1904 14425313 : case DW_OP_breg19:
1905 14425313 : case DW_OP_breg20:
1906 14425313 : case DW_OP_breg21:
1907 14425313 : case DW_OP_breg22:
1908 14425313 : case DW_OP_breg23:
1909 14425313 : case DW_OP_breg24:
1910 14425313 : case DW_OP_breg25:
1911 14425313 : case DW_OP_breg26:
1912 14425313 : case DW_OP_breg27:
1913 14425313 : case DW_OP_breg28:
1914 14425313 : case DW_OP_breg29:
1915 14425313 : case DW_OP_breg30:
1916 14425313 : case DW_OP_breg31:
1917 14425313 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1918 14425313 : break;
1919 52363 : case DW_OP_regx:
1920 52363 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1921 52363 : break;
1922 22313883 : case DW_OP_fbreg:
1923 22313883 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1924 22313883 : break;
1925 0 : case DW_OP_bregx:
1926 0 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1927 0 : size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1928 0 : break;
1929 15071196 : case DW_OP_piece:
1930 15071196 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1931 15071196 : break;
1932 510726 : case DW_OP_bit_piece:
1933 510726 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1934 510726 : size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1935 510726 : break;
1936 : case DW_OP_deref_size:
1937 : case DW_OP_xderef_size:
1938 3688640 : size += 1;
1939 : break;
1940 : case DW_OP_call2:
1941 1182926 : size += 2;
1942 : break;
1943 : case DW_OP_call4:
1944 650315 : size += 4;
1945 : break;
1946 262 : case DW_OP_call_ref:
1947 262 : case DW_OP_GNU_variable_value:
1948 262 : size += DWARF_REF_SIZE;
1949 262 : break;
1950 310104 : case DW_OP_implicit_value:
1951 310104 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1952 310104 : + loc->dw_loc_oprnd1.v.val_unsigned;
1953 310104 : break;
1954 3594494 : case DW_OP_implicit_pointer:
1955 3594494 : case DW_OP_GNU_implicit_pointer:
1956 3594494 : size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1957 3594494 : break;
1958 3858601 : case DW_OP_entry_value:
1959 3858601 : case DW_OP_GNU_entry_value:
1960 3858601 : {
1961 3858601 : unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1962 3858601 : size += size_of_uleb128 (op_size) + op_size;
1963 3858601 : break;
1964 : }
1965 113736 : case DW_OP_const_type:
1966 113736 : case DW_OP_GNU_const_type:
1967 113736 : {
1968 113736 : unsigned long o
1969 113736 : = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1970 113736 : size += size_of_uleb128 (o) + 1;
1971 113736 : switch (loc->dw_loc_oprnd2.val_class)
1972 : {
1973 85836 : case dw_val_class_vec:
1974 85836 : size += loc->dw_loc_oprnd2.v.val_vec.length
1975 85836 : * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1976 85836 : break;
1977 27114 : case dw_val_class_const:
1978 27114 : size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1979 27114 : break;
1980 470 : case dw_val_class_const_double:
1981 470 : size += HOST_BITS_PER_DOUBLE_INT / BITS_PER_UNIT;
1982 470 : break;
1983 316 : case dw_val_class_wide_int:
1984 316 : size += (get_full_len (*loc->dw_loc_oprnd2.v.val_wide)
1985 316 : * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
1986 316 : break;
1987 0 : default:
1988 0 : gcc_unreachable ();
1989 : }
1990 : break;
1991 : }
1992 369013 : case DW_OP_regval_type:
1993 369013 : case DW_OP_GNU_regval_type:
1994 369013 : {
1995 369013 : unsigned long o
1996 369013 : = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1997 369013 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1998 369013 : + size_of_uleb128 (o);
1999 : }
2000 369013 : break;
2001 155332 : case DW_OP_deref_type:
2002 155332 : case DW_OP_GNU_deref_type:
2003 155332 : {
2004 155332 : unsigned long o
2005 155332 : = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
2006 155332 : size += 1 + size_of_uleb128 (o);
2007 : }
2008 155332 : break;
2009 512001 : case DW_OP_convert:
2010 512001 : case DW_OP_reinterpret:
2011 512001 : case DW_OP_GNU_convert:
2012 512001 : case DW_OP_GNU_reinterpret:
2013 512001 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2014 82378 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2015 : else
2016 : {
2017 429623 : unsigned long o
2018 429623 : = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
2019 429623 : size += size_of_uleb128 (o);
2020 : }
2021 : break;
2022 : case DW_OP_GNU_parameter_ref:
2023 650315 : size += 4;
2024 : break;
2025 : default:
2026 : break;
2027 : }
2028 :
2029 186328740 : return size;
2030 : }
2031 :
2032 : /* Return the size of a series of location descriptors. */
2033 :
2034 : unsigned long
2035 92480749 : size_of_locs (dw_loc_descr_ref loc)
2036 : {
2037 92480749 : dw_loc_descr_ref l;
2038 92480749 : unsigned long size;
2039 :
2040 : /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
2041 : field, to avoid writing to a PCH file. */
2042 266667732 : for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2043 : {
2044 174617269 : if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
2045 : break;
2046 174186983 : size += size_of_loc_descr (l);
2047 : }
2048 92480749 : if (! l)
2049 : return size;
2050 :
2051 11509990 : for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2052 : {
2053 11079704 : l->dw_loc_addr = size;
2054 11079704 : size += size_of_loc_descr (l);
2055 : }
2056 :
2057 : return size;
2058 : }
2059 :
2060 : /* Return the size of the value in a DW_AT_discr_value attribute. */
2061 :
2062 : static int
2063 0 : size_of_discr_value (dw_discr_value *discr_value)
2064 : {
2065 0 : if (discr_value->pos)
2066 0 : return size_of_uleb128 (discr_value->v.uval);
2067 : else
2068 0 : return size_of_sleb128 (discr_value->v.sval);
2069 : }
2070 :
2071 : /* Return the size of the value in a DW_AT_discr_list attribute. */
2072 :
2073 : static int
2074 0 : size_of_discr_list (dw_discr_list_ref discr_list)
2075 : {
2076 0 : int size = 0;
2077 :
2078 0 : for (dw_discr_list_ref list = discr_list;
2079 0 : list != NULL;
2080 0 : list = list->dw_discr_next)
2081 : {
2082 : /* One byte for the discriminant value descriptor, and then one or two
2083 : LEB128 numbers, depending on whether it's a single case label or a
2084 : range label. */
2085 0 : size += 1;
2086 0 : size += size_of_discr_value (&list->dw_discr_lower_bound);
2087 0 : if (list->dw_discr_range != 0)
2088 0 : size += size_of_discr_value (&list->dw_discr_upper_bound);
2089 : }
2090 0 : return size;
2091 : }
2092 :
2093 : static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
2094 : static void get_ref_die_offset_label (char *, dw_die_ref);
2095 : static unsigned long int get_ref_die_offset (dw_die_ref);
2096 :
2097 : /* Output location description stack opcode's operands (if any).
2098 : The for_eh_or_skip parameter controls whether register numbers are
2099 : converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2100 : hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2101 : info). This should be suppressed for the cases that have not been converted
2102 : (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2103 :
2104 : static void
2105 61552670 : output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
2106 : {
2107 61552670 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
2108 61552670 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
2109 :
2110 61552670 : switch (loc->dw_loc_opc)
2111 : {
2112 : #ifdef DWARF2_DEBUGGING_INFO
2113 149581 : case DW_OP_const2u:
2114 149581 : case DW_OP_const2s:
2115 149581 : dw2_asm_output_data (2, val1->v.val_int, NULL);
2116 149581 : break;
2117 178020 : case DW_OP_const4u:
2118 178020 : if (loc->dw_loc_dtprel)
2119 : {
2120 119 : gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2121 119 : targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
2122 : val1->v.val_addr);
2123 119 : fputc ('\n', asm_out_file);
2124 119 : break;
2125 : }
2126 : /* FALLTHRU */
2127 177901 : case DW_OP_const4s:
2128 177901 : dw2_asm_output_data (4, val1->v.val_int, NULL);
2129 177901 : break;
2130 2598 : case DW_OP_const8u:
2131 2598 : if (loc->dw_loc_dtprel)
2132 : {
2133 548 : gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2134 548 : targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
2135 : val1->v.val_addr);
2136 548 : fputc ('\n', asm_out_file);
2137 548 : break;
2138 : }
2139 : /* FALLTHRU */
2140 2050 : case DW_OP_const8s:
2141 2050 : gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2142 2050 : dw2_asm_output_data (8, val1->v.val_int, NULL);
2143 2050 : break;
2144 196987 : case DW_OP_skip:
2145 196987 : case DW_OP_bra:
2146 196987 : {
2147 196987 : int offset;
2148 :
2149 196987 : gcc_assert (val1->val_class == dw_val_class_loc);
2150 196987 : offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2151 :
2152 196987 : dw2_asm_output_data (2, offset, NULL);
2153 : }
2154 196987 : break;
2155 104388 : case DW_OP_implicit_value:
2156 104388 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2157 104388 : switch (val2->val_class)
2158 : {
2159 43759 : case dw_val_class_const:
2160 43759 : dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
2161 43759 : break;
2162 60147 : case dw_val_class_vec:
2163 60147 : {
2164 60147 : unsigned int elt_size = val2->v.val_vec.elt_size;
2165 60147 : unsigned int len = val2->v.val_vec.length;
2166 60147 : unsigned int i;
2167 60147 : unsigned char *p;
2168 :
2169 60147 : if (elt_size > sizeof (HOST_WIDE_INT))
2170 : {
2171 0 : elt_size /= 2;
2172 0 : len *= 2;
2173 : }
2174 60147 : for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
2175 274704 : i < len;
2176 214557 : i++, p += elt_size)
2177 429114 : dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2178 : "fp or vector constant word %u", i);
2179 : }
2180 : break;
2181 0 : case dw_val_class_const_double:
2182 0 : {
2183 0 : unsigned HOST_WIDE_INT first, second;
2184 :
2185 0 : if (WORDS_BIG_ENDIAN)
2186 : {
2187 : first = val2->v.val_double.high;
2188 : second = val2->v.val_double.low;
2189 : }
2190 : else
2191 : {
2192 0 : first = val2->v.val_double.low;
2193 0 : second = val2->v.val_double.high;
2194 : }
2195 0 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2196 : first, NULL);
2197 0 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2198 : second, NULL);
2199 : }
2200 0 : break;
2201 482 : case dw_val_class_wide_int:
2202 482 : {
2203 482 : int i;
2204 482 : int len = get_full_len (*val2->v.val_wide);
2205 482 : if (WORDS_BIG_ENDIAN)
2206 : for (i = len - 1; i >= 0; --i)
2207 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2208 : val2->v.val_wide->elt (i), NULL);
2209 : else
2210 1446 : for (i = 0; i < len; ++i)
2211 964 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2212 964 : val2->v.val_wide->elt (i), NULL);
2213 : }
2214 : break;
2215 0 : case dw_val_class_addr:
2216 0 : gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
2217 0 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
2218 0 : break;
2219 0 : default:
2220 0 : gcc_unreachable ();
2221 : }
2222 : break;
2223 : #else
2224 : case DW_OP_const2u:
2225 : case DW_OP_const2s:
2226 : case DW_OP_const4u:
2227 : case DW_OP_const4s:
2228 : case DW_OP_const8u:
2229 : case DW_OP_const8s:
2230 : case DW_OP_skip:
2231 : case DW_OP_bra:
2232 : case DW_OP_implicit_value:
2233 : /* We currently don't make any attempt to make sure these are
2234 : aligned properly like we do for the main unwind info, so
2235 : don't support emitting things larger than a byte if we're
2236 : only doing unwinding. */
2237 : gcc_unreachable ();
2238 : #endif
2239 1030320 : case DW_OP_const1u:
2240 1030320 : case DW_OP_const1s:
2241 1030320 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2242 1030320 : break;
2243 153836 : case DW_OP_constu:
2244 153836 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2245 153836 : break;
2246 42543 : case DW_OP_consts:
2247 42543 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2248 42543 : break;
2249 177 : case DW_OP_pick:
2250 177 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2251 177 : break;
2252 970377 : case DW_OP_plus_uconst:
2253 970377 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2254 970377 : break;
2255 4836282 : case DW_OP_breg0:
2256 4836282 : case DW_OP_breg1:
2257 4836282 : case DW_OP_breg2:
2258 4836282 : case DW_OP_breg3:
2259 4836282 : case DW_OP_breg4:
2260 4836282 : case DW_OP_breg5:
2261 4836282 : case DW_OP_breg6:
2262 4836282 : case DW_OP_breg7:
2263 4836282 : case DW_OP_breg8:
2264 4836282 : case DW_OP_breg9:
2265 4836282 : case DW_OP_breg10:
2266 4836282 : case DW_OP_breg11:
2267 4836282 : case DW_OP_breg12:
2268 4836282 : case DW_OP_breg13:
2269 4836282 : case DW_OP_breg14:
2270 4836282 : case DW_OP_breg15:
2271 4836282 : case DW_OP_breg16:
2272 4836282 : case DW_OP_breg17:
2273 4836282 : case DW_OP_breg18:
2274 4836282 : case DW_OP_breg19:
2275 4836282 : case DW_OP_breg20:
2276 4836282 : case DW_OP_breg21:
2277 4836282 : case DW_OP_breg22:
2278 4836282 : case DW_OP_breg23:
2279 4836282 : case DW_OP_breg24:
2280 4836282 : case DW_OP_breg25:
2281 4836282 : case DW_OP_breg26:
2282 4836282 : case DW_OP_breg27:
2283 4836282 : case DW_OP_breg28:
2284 4836282 : case DW_OP_breg29:
2285 4836282 : case DW_OP_breg30:
2286 4836282 : case DW_OP_breg31:
2287 4836282 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2288 4836282 : break;
2289 17450 : case DW_OP_regx:
2290 17450 : {
2291 17450 : unsigned r = val1->v.val_unsigned;
2292 17450 : if (for_eh_or_skip >= 0)
2293 17450 : r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2294 17450 : gcc_assert (size_of_uleb128 (r)
2295 : == size_of_uleb128 (val1->v.val_unsigned));
2296 17450 : dw2_asm_output_data_uleb128 (r, NULL);
2297 : }
2298 17450 : break;
2299 7791101 : case DW_OP_fbreg:
2300 7791101 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2301 7791101 : break;
2302 0 : case DW_OP_bregx:
2303 0 : {
2304 0 : unsigned r = val1->v.val_unsigned;
2305 0 : if (for_eh_or_skip >= 0)
2306 0 : r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2307 0 : gcc_assert (size_of_uleb128 (r)
2308 : == size_of_uleb128 (val1->v.val_unsigned));
2309 0 : dw2_asm_output_data_uleb128 (r, NULL);
2310 0 : dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2311 : }
2312 0 : break;
2313 5019874 : case DW_OP_piece:
2314 5019874 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2315 5019874 : break;
2316 170242 : case DW_OP_bit_piece:
2317 170242 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2318 170242 : dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2319 170242 : break;
2320 166982 : case DW_OP_deref_size:
2321 166982 : case DW_OP_xderef_size:
2322 166982 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2323 166982 : break;
2324 :
2325 1442805 : case DW_OP_addr:
2326 1442805 : if (loc->dw_loc_dtprel)
2327 : {
2328 0 : if (targetm.asm_out.output_dwarf_dtprel)
2329 : {
2330 0 : targetm.asm_out.output_dwarf_dtprel (asm_out_file,
2331 0 : DWARF2_ADDR_SIZE,
2332 : val1->v.val_addr);
2333 0 : fputc ('\n', asm_out_file);
2334 : }
2335 : else
2336 0 : gcc_unreachable ();
2337 : }
2338 : else
2339 : {
2340 : #ifdef DWARF2_DEBUGGING_INFO
2341 1523612 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2342 : #else
2343 : gcc_unreachable ();
2344 : #endif
2345 : }
2346 : break;
2347 :
2348 3 : case DW_OP_GNU_addr_index:
2349 3 : case DW_OP_addrx:
2350 3 : case DW_OP_GNU_const_index:
2351 3 : case DW_OP_constx:
2352 3 : gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
2353 3 : dw2_asm_output_data_uleb128 (loc->dw_loc_oprnd1.val_entry->index,
2354 : "(index into .debug_addr)");
2355 3 : break;
2356 :
2357 3 : case DW_OP_call2:
2358 3 : case DW_OP_call4:
2359 3 : {
2360 3 : unsigned long die_offset
2361 3 : = get_ref_die_offset (val1->v.val_die_ref.die);
2362 : /* Make sure the offset has been computed and that we can encode it as
2363 : an operand. */
2364 6 : gcc_assert (die_offset > 0
2365 : && die_offset <= (loc->dw_loc_opc == DW_OP_call2
2366 : ? 0xffff
2367 : : 0xffffffff));
2368 3 : dw2_asm_output_data ((loc->dw_loc_opc == DW_OP_call2) ? 2 : 4,
2369 : die_offset, NULL);
2370 : }
2371 3 : break;
2372 :
2373 125 : case DW_OP_call_ref:
2374 125 : case DW_OP_GNU_variable_value:
2375 125 : {
2376 125 : char label[MAX_ARTIFICIAL_LABEL_BYTES
2377 : + HOST_BITS_PER_WIDE_INT / 2 + 2];
2378 125 : gcc_assert (val1->val_class == dw_val_class_die_ref);
2379 125 : get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2380 125 : dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2381 : }
2382 125 : break;
2383 :
2384 1197274 : case DW_OP_implicit_pointer:
2385 1197274 : case DW_OP_GNU_implicit_pointer:
2386 1197274 : {
2387 1197274 : char label[MAX_ARTIFICIAL_LABEL_BYTES
2388 : + HOST_BITS_PER_WIDE_INT / 2 + 2];
2389 1197274 : gcc_assert (val1->val_class == dw_val_class_die_ref);
2390 1197274 : get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2391 1197274 : dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2392 1197274 : dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2393 : }
2394 1197274 : break;
2395 :
2396 1355307 : case DW_OP_entry_value:
2397 1355307 : case DW_OP_GNU_entry_value:
2398 1355307 : dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2399 1355307 : output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2400 1355307 : break;
2401 :
2402 40736 : case DW_OP_const_type:
2403 40736 : case DW_OP_GNU_const_type:
2404 40736 : {
2405 40736 : unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2406 40736 : gcc_assert (o);
2407 40736 : dw2_asm_output_data_uleb128 (o, NULL);
2408 40736 : switch (val2->val_class)
2409 : {
2410 8976 : case dw_val_class_const:
2411 8976 : l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2412 8976 : dw2_asm_output_data (1, l, NULL);
2413 8976 : dw2_asm_output_data (l, val2->v.val_int, NULL);
2414 8976 : break;
2415 31488 : case dw_val_class_vec:
2416 31488 : {
2417 31488 : unsigned int elt_size = val2->v.val_vec.elt_size;
2418 31488 : unsigned int len = val2->v.val_vec.length;
2419 31488 : unsigned int i;
2420 31488 : unsigned char *p;
2421 :
2422 31488 : l = len * elt_size;
2423 31488 : dw2_asm_output_data (1, l, NULL);
2424 31488 : if (elt_size > sizeof (HOST_WIDE_INT))
2425 : {
2426 0 : elt_size /= 2;
2427 0 : len *= 2;
2428 : }
2429 31488 : for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
2430 98714 : i < len;
2431 67226 : i++, p += elt_size)
2432 134452 : dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2433 : "fp or vector constant word %u", i);
2434 : }
2435 : break;
2436 157 : case dw_val_class_const_double:
2437 157 : {
2438 157 : unsigned HOST_WIDE_INT first, second;
2439 157 : l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2440 :
2441 157 : dw2_asm_output_data (1, 2 * l, NULL);
2442 157 : if (WORDS_BIG_ENDIAN)
2443 : {
2444 : first = val2->v.val_double.high;
2445 : second = val2->v.val_double.low;
2446 : }
2447 : else
2448 : {
2449 157 : first = val2->v.val_double.low;
2450 157 : second = val2->v.val_double.high;
2451 : }
2452 157 : dw2_asm_output_data (l, first, NULL);
2453 157 : dw2_asm_output_data (l, second, NULL);
2454 : }
2455 157 : break;
2456 115 : case dw_val_class_wide_int:
2457 115 : {
2458 115 : int i;
2459 115 : int len = get_full_len (*val2->v.val_wide);
2460 115 : l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2461 :
2462 115 : dw2_asm_output_data (1, len * l, NULL);
2463 115 : if (WORDS_BIG_ENDIAN)
2464 : for (i = len - 1; i >= 0; --i)
2465 : dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2466 : else
2467 460 : for (i = 0; i < len; ++i)
2468 230 : dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
2469 : }
2470 : break;
2471 0 : default:
2472 0 : gcc_unreachable ();
2473 : }
2474 : }
2475 : break;
2476 107366 : case DW_OP_regval_type:
2477 107366 : case DW_OP_GNU_regval_type:
2478 107366 : {
2479 107366 : unsigned r = val1->v.val_unsigned;
2480 107366 : unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2481 107366 : gcc_assert (o);
2482 107366 : if (for_eh_or_skip >= 0)
2483 : {
2484 0 : r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2485 0 : gcc_assert (size_of_uleb128 (r)
2486 : == size_of_uleb128 (val1->v.val_unsigned));
2487 : }
2488 107366 : dw2_asm_output_data_uleb128 (r, NULL);
2489 107366 : dw2_asm_output_data_uleb128 (o, NULL);
2490 : }
2491 107366 : break;
2492 54367 : case DW_OP_deref_type:
2493 54367 : case DW_OP_GNU_deref_type:
2494 54367 : {
2495 54367 : unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2496 54367 : gcc_assert (o);
2497 54367 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2498 54367 : dw2_asm_output_data_uleb128 (o, NULL);
2499 : }
2500 54367 : break;
2501 168110 : case DW_OP_convert:
2502 168110 : case DW_OP_reinterpret:
2503 168110 : case DW_OP_GNU_convert:
2504 168110 : case DW_OP_GNU_reinterpret:
2505 168110 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2506 26732 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2507 : else
2508 : {
2509 141378 : unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2510 141378 : gcc_assert (o);
2511 141378 : dw2_asm_output_data_uleb128 (o, NULL);
2512 : }
2513 : break;
2514 :
2515 29724 : case DW_OP_GNU_parameter_ref:
2516 29724 : {
2517 29724 : unsigned long o;
2518 29724 : gcc_assert (val1->val_class == dw_val_class_die_ref);
2519 29724 : o = get_ref_die_offset (val1->v.val_die_ref.die);
2520 29724 : dw2_asm_output_data (4, o, NULL);
2521 : }
2522 29724 : break;
2523 :
2524 : default:
2525 : /* Other codes have no operands. */
2526 : break;
2527 : }
2528 61552670 : }
2529 :
2530 : /* Output a sequence of location operations.
2531 : The for_eh_or_skip parameter controls whether register numbers are
2532 : converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2533 : hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2534 : info). This should be suppressed for the cases that have not been converted
2535 : (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2536 :
2537 : void
2538 32990129 : output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2539 : {
2540 94542799 : for (; loc != NULL; loc = loc->dw_loc_next)
2541 : {
2542 61552670 : enum dwarf_location_atom opc = loc->dw_loc_opc;
2543 : /* Output the opcode. */
2544 61552670 : if (for_eh_or_skip >= 0
2545 : && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2546 : {
2547 : unsigned r = (opc - DW_OP_breg0);
2548 : r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2549 : gcc_assert (r <= 31);
2550 : opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2551 : }
2552 61552670 : else if (for_eh_or_skip >= 0
2553 : && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2554 : {
2555 : unsigned r = (opc - DW_OP_reg0);
2556 : r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2557 : gcc_assert (r <= 31);
2558 : opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2559 : }
2560 :
2561 123105340 : dw2_asm_output_data (1, opc,
2562 : "%s", dwarf_stack_op_name (opc));
2563 :
2564 : /* Output the operand(s) (if any). */
2565 61552670 : output_loc_operands (loc, for_eh_or_skip);
2566 : }
2567 32990129 : }
2568 :
2569 : /* Output location description stack opcode's operands (if any).
2570 : The output is single bytes on a line, suitable for .cfi_escape. */
2571 :
2572 : static void
2573 64280 : output_loc_operands_raw (dw_loc_descr_ref loc)
2574 : {
2575 64280 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
2576 64280 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
2577 :
2578 64280 : switch (loc->dw_loc_opc)
2579 : {
2580 0 : case DW_OP_addr:
2581 0 : case DW_OP_GNU_addr_index:
2582 0 : case DW_OP_addrx:
2583 0 : case DW_OP_GNU_const_index:
2584 0 : case DW_OP_constx:
2585 0 : case DW_OP_implicit_value:
2586 : /* We cannot output addresses in .cfi_escape, only bytes. */
2587 0 : gcc_unreachable ();
2588 :
2589 0 : case DW_OP_const1u:
2590 0 : case DW_OP_const1s:
2591 0 : case DW_OP_pick:
2592 0 : case DW_OP_deref_size:
2593 0 : case DW_OP_xderef_size:
2594 0 : fputc (',', asm_out_file);
2595 0 : dw2_asm_output_data_raw (1, val1->v.val_int);
2596 0 : break;
2597 :
2598 0 : case DW_OP_const2u:
2599 0 : case DW_OP_const2s:
2600 0 : fputc (',', asm_out_file);
2601 0 : dw2_asm_output_data_raw (2, val1->v.val_int);
2602 0 : break;
2603 :
2604 0 : case DW_OP_const4u:
2605 0 : case DW_OP_const4s:
2606 0 : fputc (',', asm_out_file);
2607 0 : dw2_asm_output_data_raw (4, val1->v.val_int);
2608 0 : break;
2609 :
2610 0 : case DW_OP_const8u:
2611 0 : case DW_OP_const8s:
2612 0 : gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2613 0 : fputc (',', asm_out_file);
2614 0 : dw2_asm_output_data_raw (8, val1->v.val_int);
2615 0 : break;
2616 :
2617 0 : case DW_OP_skip:
2618 0 : case DW_OP_bra:
2619 0 : {
2620 0 : int offset;
2621 :
2622 0 : gcc_assert (val1->val_class == dw_val_class_loc);
2623 0 : offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2624 :
2625 0 : fputc (',', asm_out_file);
2626 0 : dw2_asm_output_data_raw (2, offset);
2627 : }
2628 0 : break;
2629 :
2630 0 : case DW_OP_regx:
2631 0 : {
2632 0 : unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2633 0 : gcc_assert (size_of_uleb128 (r)
2634 : == size_of_uleb128 (val1->v.val_unsigned));
2635 0 : fputc (',', asm_out_file);
2636 0 : dw2_asm_output_data_uleb128_raw (r);
2637 : }
2638 0 : break;
2639 :
2640 0 : case DW_OP_constu:
2641 0 : case DW_OP_plus_uconst:
2642 0 : case DW_OP_piece:
2643 0 : fputc (',', asm_out_file);
2644 0 : dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2645 0 : break;
2646 :
2647 0 : case DW_OP_bit_piece:
2648 0 : fputc (',', asm_out_file);
2649 0 : dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
2650 0 : dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
2651 0 : break;
2652 :
2653 55315 : case DW_OP_consts:
2654 55315 : case DW_OP_breg0:
2655 55315 : case DW_OP_breg1:
2656 55315 : case DW_OP_breg2:
2657 55315 : case DW_OP_breg3:
2658 55315 : case DW_OP_breg4:
2659 55315 : case DW_OP_breg5:
2660 55315 : case DW_OP_breg6:
2661 55315 : case DW_OP_breg7:
2662 55315 : case DW_OP_breg8:
2663 55315 : case DW_OP_breg9:
2664 55315 : case DW_OP_breg10:
2665 55315 : case DW_OP_breg11:
2666 55315 : case DW_OP_breg12:
2667 55315 : case DW_OP_breg13:
2668 55315 : case DW_OP_breg14:
2669 55315 : case DW_OP_breg15:
2670 55315 : case DW_OP_breg16:
2671 55315 : case DW_OP_breg17:
2672 55315 : case DW_OP_breg18:
2673 55315 : case DW_OP_breg19:
2674 55315 : case DW_OP_breg20:
2675 55315 : case DW_OP_breg21:
2676 55315 : case DW_OP_breg22:
2677 55315 : case DW_OP_breg23:
2678 55315 : case DW_OP_breg24:
2679 55315 : case DW_OP_breg25:
2680 55315 : case DW_OP_breg26:
2681 55315 : case DW_OP_breg27:
2682 55315 : case DW_OP_breg28:
2683 55315 : case DW_OP_breg29:
2684 55315 : case DW_OP_breg30:
2685 55315 : case DW_OP_breg31:
2686 55315 : case DW_OP_fbreg:
2687 55315 : fputc (',', asm_out_file);
2688 55315 : dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2689 55315 : break;
2690 :
2691 0 : case DW_OP_bregx:
2692 0 : {
2693 0 : unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
2694 0 : gcc_assert (size_of_uleb128 (r)
2695 : == size_of_uleb128 (val1->v.val_unsigned));
2696 0 : fputc (',', asm_out_file);
2697 0 : dw2_asm_output_data_uleb128_raw (r);
2698 0 : fputc (',', asm_out_file);
2699 0 : dw2_asm_output_data_sleb128_raw (val2->v.val_int);
2700 : }
2701 0 : break;
2702 :
2703 0 : case DW_OP_implicit_pointer:
2704 0 : case DW_OP_entry_value:
2705 0 : case DW_OP_const_type:
2706 0 : case DW_OP_regval_type:
2707 0 : case DW_OP_deref_type:
2708 0 : case DW_OP_convert:
2709 0 : case DW_OP_reinterpret:
2710 0 : case DW_OP_GNU_implicit_pointer:
2711 0 : case DW_OP_GNU_entry_value:
2712 0 : case DW_OP_GNU_const_type:
2713 0 : case DW_OP_GNU_regval_type:
2714 0 : case DW_OP_GNU_deref_type:
2715 0 : case DW_OP_GNU_convert:
2716 0 : case DW_OP_GNU_reinterpret:
2717 0 : case DW_OP_GNU_parameter_ref:
2718 0 : gcc_unreachable ();
2719 : break;
2720 :
2721 : default:
2722 : /* Other codes have no operands. */
2723 : break;
2724 : }
2725 64280 : }
2726 :
2727 : void
2728 55315 : output_loc_sequence_raw (dw_loc_descr_ref loc)
2729 : {
2730 73245 : while (1)
2731 : {
2732 64280 : enum dwarf_location_atom opc = loc->dw_loc_opc;
2733 : /* Output the opcode. */
2734 64280 : if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
2735 : {
2736 : unsigned r = (opc - DW_OP_breg0);
2737 : r = DWARF2_FRAME_REG_OUT (r, 1);
2738 : gcc_assert (r <= 31);
2739 : opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
2740 : }
2741 64280 : else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
2742 : {
2743 : unsigned r = (opc - DW_OP_reg0);
2744 : r = DWARF2_FRAME_REG_OUT (r, 1);
2745 : gcc_assert (r <= 31);
2746 : opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
2747 : }
2748 : /* Output the opcode. */
2749 64280 : fprintf (asm_out_file, "%#x", opc);
2750 64280 : output_loc_operands_raw (loc);
2751 :
2752 64280 : if (!loc->dw_loc_next)
2753 : break;
2754 8965 : loc = loc->dw_loc_next;
2755 :
2756 8965 : fputc (',', asm_out_file);
2757 8965 : }
2758 55315 : }
2759 :
2760 : static void
2761 0 : build_breg_loc (struct dw_loc_descr_node **head, unsigned int regno)
2762 : {
2763 0 : if (regno <= 31)
2764 0 : add_loc_descr (head, new_loc_descr ((enum dwarf_location_atom)
2765 0 : (DW_OP_breg0 + regno), 0, 0));
2766 : else
2767 0 : add_loc_descr (head, new_loc_descr (DW_OP_bregx, regno, 0));
2768 0 : }
2769 :
2770 : /* Build a dwarf location for a cfa_reg spanning multiple
2771 : consecutive registers. */
2772 :
2773 : struct dw_loc_descr_node *
2774 0 : build_span_loc (struct cfa_reg reg)
2775 : {
2776 0 : struct dw_loc_descr_node *head = NULL;
2777 :
2778 0 : gcc_assert (reg.span_width > 0);
2779 0 : gcc_assert (reg.span > 1);
2780 :
2781 : /* Start from the highest number register as it goes in the upper bits. */
2782 0 : unsigned int regno = reg.reg + reg.span - 1;
2783 0 : build_breg_loc (&head, regno);
2784 :
2785 : /* Deal with the remaining registers in the span. */
2786 0 : for (int i = reg.span - 2; i >= 0; i--)
2787 : {
2788 0 : add_loc_descr (&head, int_loc_descriptor (reg.span_width * 8));
2789 0 : add_loc_descr (&head, new_loc_descr (DW_OP_shl, 0, 0));
2790 0 : regno--;
2791 0 : build_breg_loc (&head, regno);
2792 0 : add_loc_descr (&head, new_loc_descr (DW_OP_plus, 0, 0));
2793 : }
2794 0 : return head;
2795 : }
2796 :
2797 : /* This function builds a dwarf location descriptor sequence from a
2798 : dw_cfa_location, adding the given OFFSET to the result of the
2799 : expression. */
2800 :
2801 : struct dw_loc_descr_node *
2802 16342 : build_cfa_loc (dw_cfa_location *cfa, poly_int64 offset)
2803 : {
2804 16342 : struct dw_loc_descr_node *head, *tmp;
2805 :
2806 16342 : offset += cfa->offset;
2807 :
2808 16342 : if (cfa->reg.span > 1)
2809 : {
2810 0 : head = build_span_loc (cfa->reg);
2811 :
2812 0 : if (maybe_ne (offset, 0))
2813 0 : loc_descr_plus_const (&head, offset);
2814 : }
2815 16342 : else if (cfa->indirect)
2816 : {
2817 7083 : head = new_reg_loc_descr (cfa->reg.reg, cfa->base_offset);
2818 7083 : head->dw_loc_oprnd1.val_class = dw_val_class_const;
2819 7083 : head->dw_loc_oprnd1.val_entry = NULL;
2820 7083 : tmp = new_loc_descr (DW_OP_deref, 0, 0);
2821 7083 : add_loc_descr (&head, tmp);
2822 7083 : loc_descr_plus_const (&head, offset);
2823 : }
2824 : else
2825 9259 : head = new_reg_loc_descr (cfa->reg.reg, offset);
2826 :
2827 16342 : return head;
2828 : }
2829 :
2830 : /* This function builds a dwarf location descriptor sequence for
2831 : the address at OFFSET from the CFA when stack is aligned to
2832 : ALIGNMENT byte. */
2833 :
2834 : struct dw_loc_descr_node *
2835 17994 : build_cfa_aligned_loc (dw_cfa_location *cfa,
2836 : poly_int64 offset, HOST_WIDE_INT alignment)
2837 : {
2838 17994 : struct dw_loc_descr_node *head;
2839 17994 : unsigned int dwarf_fp
2840 17994 : = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2841 :
2842 : /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2843 17994 : if (cfa->reg.reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
2844 : {
2845 0 : head = new_reg_loc_descr (dwarf_fp, 0);
2846 0 : add_loc_descr (&head, int_loc_descriptor (alignment));
2847 0 : add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
2848 0 : loc_descr_plus_const (&head, offset);
2849 : }
2850 : else
2851 17994 : head = new_reg_loc_descr (dwarf_fp, offset);
2852 17994 : return head;
2853 : }
2854 :
2855 : /* And now, the support for symbolic debugging information. */
2856 :
2857 : /* .debug_str support. */
2858 :
2859 : static void dwarf2out_init (const char *);
2860 : static void dwarf2out_finish (const char *);
2861 : static void dwarf2out_early_finish (const char *);
2862 : static void dwarf2out_assembly_start (void);
2863 : static void dwarf2out_define (unsigned int, const char *);
2864 : static void dwarf2out_undef (unsigned int, const char *);
2865 : static void dwarf2out_start_source_file (unsigned, const char *);
2866 : static void dwarf2out_end_source_file (unsigned);
2867 : static void dwarf2out_function_decl (tree);
2868 : static void dwarf2out_begin_block (unsigned, unsigned, tree);
2869 : static void dwarf2out_end_block (unsigned, unsigned);
2870 : static bool dwarf2out_ignore_block (const_tree);
2871 : static void dwarf2out_set_ignored_loc (unsigned, unsigned, const char *);
2872 : static void dwarf2out_early_global_decl (tree);
2873 : static void dwarf2out_late_global_decl (tree);
2874 : static void dwarf2out_type_decl (tree, int);
2875 : static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool, bool);
2876 : static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
2877 : dw_die_ref);
2878 : static void dwarf2out_abstract_function (tree);
2879 : static void dwarf2out_var_location (rtx_insn *);
2880 : static void dwarf2out_inline_entry (tree);
2881 : static void dwarf2out_size_function (tree);
2882 : static void dwarf2out_begin_function (tree);
2883 : static void dwarf2out_end_function (unsigned int);
2884 : static void dwarf2out_register_main_translation_unit (tree unit);
2885 : static void dwarf2out_set_name (tree, tree);
2886 : static void dwarf2out_register_external_die (tree decl, const char *sym,
2887 : unsigned HOST_WIDE_INT off);
2888 : static bool dwarf2out_die_ref_for_decl (tree decl, const char **sym,
2889 : unsigned HOST_WIDE_INT *off);
2890 :
2891 : /* The debug hooks structure. */
2892 :
2893 : const struct gcc_debug_hooks dwarf2_debug_hooks =
2894 : {
2895 : dwarf2out_init,
2896 : dwarf2out_finish,
2897 : dwarf2out_early_finish,
2898 : dwarf2out_assembly_start,
2899 : dwarf2out_define,
2900 : dwarf2out_undef,
2901 : dwarf2out_start_source_file,
2902 : dwarf2out_end_source_file,
2903 : dwarf2out_begin_block,
2904 : dwarf2out_end_block,
2905 : dwarf2out_ignore_block,
2906 : dwarf2out_source_line,
2907 : dwarf2out_set_ignored_loc,
2908 : dwarf2out_begin_prologue,
2909 : #if VMS_DEBUGGING_INFO
2910 : dwarf2out_vms_end_prologue,
2911 : dwarf2out_vms_begin_epilogue,
2912 : #else
2913 : debug_nothing_int_charstar,
2914 : debug_nothing_int_charstar,
2915 : #endif
2916 : dwarf2out_end_epilogue,
2917 : dwarf2out_begin_function,
2918 : dwarf2out_end_function, /* end_function */
2919 : dwarf2out_register_main_translation_unit,
2920 : dwarf2out_function_decl, /* function_decl */
2921 : dwarf2out_early_global_decl,
2922 : dwarf2out_late_global_decl,
2923 : dwarf2out_type_decl, /* type_decl */
2924 : dwarf2out_imported_module_or_decl,
2925 : dwarf2out_die_ref_for_decl,
2926 : dwarf2out_register_external_die,
2927 : debug_nothing_tree, /* deferred_inline_function */
2928 : /* The DWARF 2 backend tries to reduce debugging bloat by not
2929 : emitting the abstract description of inline functions until
2930 : something tries to reference them. */
2931 : dwarf2out_abstract_function, /* outlining_inline_function */
2932 : debug_nothing_rtx_code_label, /* label */
2933 : debug_nothing_int, /* handle_pch */
2934 : dwarf2out_var_location,
2935 : dwarf2out_inline_entry, /* inline_entry */
2936 : dwarf2out_size_function, /* size_function */
2937 : dwarf2out_switch_text_section,
2938 : dwarf2out_set_name,
2939 : 1, /* start_end_main_source_file */
2940 : TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
2941 : };
2942 :
2943 : const struct gcc_debug_hooks dwarf2_lineno_debug_hooks =
2944 : {
2945 : dwarf2out_init,
2946 : debug_nothing_charstar,
2947 : debug_nothing_charstar,
2948 : dwarf2out_assembly_start,
2949 : debug_nothing_int_charstar,
2950 : debug_nothing_int_charstar,
2951 : debug_nothing_int_charstar,
2952 : debug_nothing_int,
2953 : debug_nothing_int_int_tree, /* begin_block */
2954 : debug_nothing_int_int, /* end_block */
2955 : debug_true_const_tree, /* ignore_block */
2956 : dwarf2out_source_line, /* source_line */
2957 : debug_nothing_int_int_charstar, /* set_ignored_loc */
2958 : debug_nothing_int_int_charstar, /* begin_prologue */
2959 : debug_nothing_int_charstar, /* end_prologue */
2960 : debug_nothing_int_charstar, /* begin_epilogue */
2961 : debug_nothing_int_charstar, /* end_epilogue */
2962 : debug_nothing_tree, /* begin_function */
2963 : debug_nothing_int, /* end_function */
2964 : debug_nothing_tree, /* register_main_translation_unit */
2965 : debug_nothing_tree, /* function_decl */
2966 : debug_nothing_tree, /* early_global_decl */
2967 : debug_nothing_tree, /* late_global_decl */
2968 : debug_nothing_tree_int, /* type_decl */
2969 : debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
2970 : debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */
2971 : debug_nothing_tree_charstar_uhwi, /* register_external_die */
2972 : debug_nothing_tree, /* deferred_inline_function */
2973 : debug_nothing_tree, /* outlining_inline_function */
2974 : debug_nothing_rtx_code_label, /* label */
2975 : debug_nothing_int, /* handle_pch */
2976 : debug_nothing_rtx_insn, /* var_location */
2977 : debug_nothing_tree, /* inline_entry */
2978 : debug_nothing_tree, /* size_function */
2979 : debug_nothing_void, /* switch_text_section */
2980 : debug_nothing_tree_tree, /* set_name */
2981 : 0, /* start_end_main_source_file */
2982 : TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */
2983 : };
2984 :
2985 : /* NOTE: In the comments in this file, many references are made to
2986 : "Debugging Information Entries". This term is abbreviated as `DIE'
2987 : throughout the remainder of this file. */
2988 :
2989 : /* An internal representation of the DWARF output is built, and then
2990 : walked to generate the DWARF debugging info. The walk of the internal
2991 : representation is done after the entire program has been compiled.
2992 : The types below are used to describe the internal representation. */
2993 :
2994 : /* Whether to put type DIEs into their own section .debug_types instead
2995 : of making them part of the .debug_info section. Only supported for
2996 : Dwarf V4 or higher and the user didn't disable them through
2997 : -fno-debug-types-section. It is more efficient to put them in a
2998 : separate comdat sections since the linker will then be able to
2999 : remove duplicates. But not all tools support .debug_types sections
3000 : yet. For Dwarf V5 or higher .debug_types doesn't exist any more,
3001 : it is DW_UT_type unit type in .debug_info section. For late LTO
3002 : debug there should be almost no types emitted so avoid enabling
3003 : -fdebug-types-section there. */
3004 :
3005 : #define use_debug_types (dwarf_version >= 4 \
3006 : && flag_debug_types_section \
3007 : && !in_lto_p)
3008 :
3009 : /* Various DIE's use offsets relative to the beginning of the
3010 : .debug_info section to refer to each other. */
3011 :
3012 : typedef long int dw_offset;
3013 :
3014 : struct comdat_type_node;
3015 :
3016 : /* The entries in the line_info table more-or-less mirror the opcodes
3017 : that are used in the real dwarf line table. Arrays of these entries
3018 : are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
3019 : supported. */
3020 :
3021 : enum dw_line_info_opcode {
3022 : /* Emit DW_LNE_set_address; the operand is the label index. */
3023 : LI_set_address,
3024 :
3025 : /* Emit a row to the matrix with the given line. This may be done
3026 : via any combination of DW_LNS_copy, DW_LNS_advance_line, and
3027 : special opcodes. */
3028 : LI_set_line,
3029 :
3030 : /* Emit a DW_LNS_set_file. */
3031 : LI_set_file,
3032 :
3033 : /* Emit a DW_LNS_set_column. */
3034 : LI_set_column,
3035 :
3036 : /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
3037 : LI_negate_stmt,
3038 :
3039 : /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
3040 : LI_set_prologue_end,
3041 : LI_set_epilogue_begin,
3042 :
3043 : /* Emit a DW_LNE_set_discriminator. */
3044 : LI_set_discriminator,
3045 :
3046 : /* Output a Fixed Advance PC; the target PC is the label index; the
3047 : base PC is the previous LI_adv_address or LI_set_address entry.
3048 : We only use this when emitting debug views without assembler
3049 : support, at explicit user request. Ideally, we should only use
3050 : it when the offset might be zero but we can't tell: it's the only
3051 : way to maybe change the PC without resetting the view number. */
3052 : LI_adv_address
3053 : };
3054 :
3055 : typedef struct GTY(()) dw_line_info_struct {
3056 : enum dw_line_info_opcode opcode;
3057 : unsigned int val;
3058 : } dw_line_info_entry;
3059 :
3060 :
3061 : struct GTY(()) dw_line_info_table {
3062 : /* The label that marks the end of this section. */
3063 : const char *end_label;
3064 :
3065 : /* The values for the last row of the matrix, as collected in the table.
3066 : These are used to minimize the changes to the next row. */
3067 : unsigned int file_num;
3068 : unsigned int line_num;
3069 : unsigned int column_num;
3070 : int discrim_num;
3071 : bool is_stmt;
3072 : bool in_use;
3073 :
3074 : /* This denotes the NEXT view number.
3075 :
3076 : If it is 0, it is known that the NEXT view will be the first view
3077 : at the given PC.
3078 :
3079 : If it is -1, we're forcing the view number to be reset, e.g. at a
3080 : function entry.
3081 :
3082 : The meaning of other nonzero values depends on whether we're
3083 : computing views internally or leaving it for the assembler to do
3084 : so. If we're emitting them internally, view denotes the view
3085 : number since the last known advance of PC. If we're leaving it
3086 : for the assembler, it denotes the LVU label number that we're
3087 : going to ask the assembler to assign. */
3088 : var_loc_view view;
3089 :
3090 : /* This counts the number of symbolic views emitted in this table
3091 : since the latest view reset. Its max value, over all tables,
3092 : sets symview_upper_bound. */
3093 : var_loc_view symviews_since_reset;
3094 :
3095 : #define FORCE_RESET_NEXT_VIEW(x) ((x) = (var_loc_view)-1)
3096 : #define RESET_NEXT_VIEW(x) ((x) = (var_loc_view)0)
3097 : #define FORCE_RESETTING_VIEW_P(x) ((x) == (var_loc_view)-1)
3098 : #define RESETTING_VIEW_P(x) ((x) == (var_loc_view)0 || FORCE_RESETTING_VIEW_P (x))
3099 :
3100 : vec<dw_line_info_entry, va_gc> *entries;
3101 : };
3102 :
3103 : /* This is an upper bound for view numbers that the assembler may
3104 : assign to symbolic views output in this translation. It is used to
3105 : decide how big a field to use to represent view numbers in
3106 : symview-classed attributes. */
3107 :
3108 : static var_loc_view symview_upper_bound;
3109 :
3110 : /* If we're keep track of location views and their reset points, and
3111 : INSN is a reset point (i.e., it necessarily advances the PC), mark
3112 : the next view in TABLE as reset. */
3113 :
3114 : static void
3115 42057241 : maybe_reset_location_view (rtx_insn *insn, dw_line_info_table *table)
3116 : {
3117 42057241 : if (!debug_internal_reset_location_views)
3118 : return;
3119 :
3120 : /* Maybe turn (part of?) this test into a default target hook. */
3121 0 : int reset = 0;
3122 :
3123 0 : if (targetm.reset_location_view)
3124 0 : reset = targetm.reset_location_view (insn);
3125 :
3126 0 : if (reset)
3127 : ;
3128 0 : else if (JUMP_TABLE_DATA_P (insn))
3129 : reset = 1;
3130 0 : else if (GET_CODE (insn) == USE
3131 0 : || GET_CODE (insn) == CLOBBER
3132 0 : || GET_CODE (insn) == ASM_INPUT
3133 0 : || asm_noperands (insn) >= 0)
3134 : ;
3135 0 : else if (get_attr_min_length (insn) > 0)
3136 : reset = 1;
3137 :
3138 0 : if (reset > 0 && !RESETTING_VIEW_P (table->view))
3139 0 : RESET_NEXT_VIEW (table->view);
3140 : }
3141 :
3142 : /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3143 : The children of each node form a circular list linked by
3144 : die_sib. die_child points to the node *before* the "first" child node. */
3145 :
3146 : typedef struct GTY((chain_circular ("%h.die_sib"), for_user)) die_struct {
3147 : union die_symbol_or_type_node
3148 : {
3149 : const char * GTY ((tag ("0"))) die_symbol;
3150 : comdat_type_node *GTY ((tag ("1"))) die_type_node;
3151 : }
3152 : GTY ((desc ("%0.comdat_type_p"))) die_id;
3153 : vec<dw_attr_node, va_gc> *die_attr;
3154 : dw_die_ref die_parent;
3155 : dw_die_ref die_child;
3156 : dw_die_ref die_sib;
3157 : dw_die_ref die_definition; /* ref from a specification to its definition */
3158 : dw_offset die_offset;
3159 : unsigned long die_abbrev;
3160 : int die_mark;
3161 : unsigned int decl_id;
3162 : enum dwarf_tag die_tag;
3163 : /* Die is used and must not be pruned as unused. */
3164 : BOOL_BITFIELD die_perennial_p : 1;
3165 : BOOL_BITFIELD comdat_type_p : 1; /* DIE has a type signature */
3166 : /* For an external ref to die_symbol if die_offset contains an extra
3167 : offset to that symbol. */
3168 : BOOL_BITFIELD with_offset : 1;
3169 : /* Whether this DIE was removed from the DIE tree, for example via
3170 : prune_unused_types. We don't consider those present from the
3171 : DIE lookup routines. */
3172 : BOOL_BITFIELD removed : 1;
3173 : /* Lots of spare bits. */
3174 : }
3175 : die_node;
3176 :
3177 : /* Set to TRUE while dwarf2out_early_global_decl is running. */
3178 : static bool early_dwarf;
3179 : static bool early_dwarf_finished;
3180 : class set_early_dwarf {
3181 : public:
3182 : bool saved;
3183 106995932 : set_early_dwarf () : saved(early_dwarf)
3184 : {
3185 106995932 : gcc_assert (! early_dwarf_finished);
3186 106995932 : early_dwarf = true;
3187 106995932 : }
3188 106995932 : ~set_early_dwarf () { early_dwarf = saved; }
3189 : };
3190 :
3191 : /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3192 : #define FOR_EACH_CHILD(die, c, expr) do { \
3193 : c = die->die_child; \
3194 : if (c) do { \
3195 : c = c->die_sib; \
3196 : expr; \
3197 : } while (c != die->die_child); \
3198 : } while (0)
3199 :
3200 : /* The pubname structure */
3201 :
3202 : typedef struct GTY(()) pubname_struct {
3203 : dw_die_ref die;
3204 : const char *name;
3205 : }
3206 : pubname_entry;
3207 :
3208 :
3209 : struct GTY(()) dw_ranges {
3210 : const char *label;
3211 : /* If this is positive, it's a block number, otherwise it's a
3212 : bitwise-negated index into dw_ranges_by_label. */
3213 : int num;
3214 : /* If idx is equal to DW_RANGES_IDX_SKELETON, it should be emitted
3215 : into .debug_rnglists section rather than .debug_rnglists.dwo
3216 : for -gsplit-dwarf and DWARF >= 5. */
3217 : #define DW_RANGES_IDX_SKELETON ((1U << 31) - 1)
3218 : /* Index for the range list for DW_FORM_rnglistx. */
3219 : unsigned int idx : 31;
3220 : /* True if this range might be possibly in a different section
3221 : from previous entry. */
3222 : unsigned int maybe_new_sec : 1;
3223 : addr_table_entry *begin_entry;
3224 : addr_table_entry *end_entry;
3225 : };
3226 :
3227 : /* A structure to hold a macinfo entry. */
3228 :
3229 : typedef struct GTY(()) macinfo_struct {
3230 : unsigned char code;
3231 : unsigned HOST_WIDE_INT lineno;
3232 : const char *info;
3233 : }
3234 : macinfo_entry;
3235 :
3236 :
3237 : struct GTY(()) dw_ranges_by_label {
3238 : const char *begin;
3239 : const char *end;
3240 : };
3241 :
3242 : /* The comdat type node structure. */
3243 : struct GTY(()) comdat_type_node
3244 : {
3245 : dw_die_ref root_die;
3246 : dw_die_ref type_die;
3247 : dw_die_ref skeleton_die;
3248 : char signature[DWARF_TYPE_SIGNATURE_SIZE];
3249 : comdat_type_node *next;
3250 : };
3251 :
3252 : /* A list of DIEs for which we can't determine ancestry (parent_die
3253 : field) just yet. Later in dwarf2out_finish we will fill in the
3254 : missing bits. */
3255 : typedef struct GTY(()) limbo_die_struct {
3256 : dw_die_ref die;
3257 : /* The tree for which this DIE was created. We use this to
3258 : determine ancestry later. */
3259 : tree created_for;
3260 : struct limbo_die_struct *next;
3261 : }
3262 : limbo_die_node;
3263 :
3264 : typedef struct skeleton_chain_struct
3265 : {
3266 : dw_die_ref old_die;
3267 : dw_die_ref new_die;
3268 : struct skeleton_chain_struct *parent;
3269 : }
3270 : skeleton_chain_node;
3271 :
3272 : /* Define a macro which returns nonzero for a TYPE_DECL which was
3273 : implicitly generated for a type.
3274 :
3275 : Note that, unlike the C front-end (which generates a NULL named
3276 : TYPE_DECL node for each complete tagged type, each array type,
3277 : and each function type node created) the C++ front-end generates
3278 : a _named_ TYPE_DECL node for each tagged type node created.
3279 : These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3280 : generate a DW_TAG_typedef DIE for them. Likewise with the Ada
3281 : front-end, but for each type, tagged or not. */
3282 :
3283 : #define TYPE_DECL_IS_STUB(decl) \
3284 : (DECL_NAME (decl) == NULL_TREE \
3285 : || (DECL_ARTIFICIAL (decl) \
3286 : && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3287 : /* This is necessary for stub decls that \
3288 : appear in nested inline functions. */ \
3289 : || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3290 : && (decl_ultimate_origin (decl) \
3291 : == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3292 :
3293 : /* Information concerning the compilation unit's programming
3294 : language, and compiler version. */
3295 :
3296 : /* Fixed size portion of the DWARF compilation unit header. */
3297 : #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3298 : (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size \
3299 : + (dwarf_version >= 5 ? 4 : 3))
3300 :
3301 : /* Fixed size portion of the DWARF comdat type unit header. */
3302 : #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
3303 : (DWARF_COMPILE_UNIT_HEADER_SIZE \
3304 : + DWARF_TYPE_SIGNATURE_SIZE + dwarf_offset_size)
3305 :
3306 : /* Fixed size portion of the DWARF skeleton compilation unit header. */
3307 : #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
3308 : (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
3309 :
3310 : /* Fixed size portion of public names info. */
3311 : #define DWARF_PUBNAMES_HEADER_SIZE (2 * dwarf_offset_size + 2)
3312 :
3313 : /* Fixed size portion of the address range info. */
3314 : #define DWARF_ARANGES_HEADER_SIZE \
3315 : (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3316 : DWARF2_ADDR_SIZE * 2) \
3317 : - DWARF_INITIAL_LENGTH_SIZE)
3318 :
3319 : /* Size of padding portion in the address range info. It must be
3320 : aligned to twice the pointer size. */
3321 : #define DWARF_ARANGES_PAD_SIZE \
3322 : (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
3323 : DWARF2_ADDR_SIZE * 2) \
3324 : - (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4))
3325 :
3326 : /* Use assembler line directives if available. */
3327 : #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3328 : #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3329 : #define DWARF2_ASM_LINE_DEBUG_INFO 1
3330 : #else
3331 : #define DWARF2_ASM_LINE_DEBUG_INFO 0
3332 : #endif
3333 : #endif
3334 :
3335 : /* Use assembler views in line directives if available. */
3336 : #ifndef DWARF2_ASM_VIEW_DEBUG_INFO
3337 : #ifdef HAVE_AS_DWARF2_DEBUG_VIEW
3338 : #define DWARF2_ASM_VIEW_DEBUG_INFO 1
3339 : #else
3340 : #define DWARF2_ASM_VIEW_DEBUG_INFO 0
3341 : #endif
3342 : #endif
3343 :
3344 : /* Return true if GCC configure detected assembler support for .loc. */
3345 :
3346 : bool
3347 287794 : dwarf2out_default_as_loc_support (void)
3348 : {
3349 287794 : return DWARF2_ASM_LINE_DEBUG_INFO;
3350 : #if (GCC_VERSION >= 3000)
3351 : # undef DWARF2_ASM_LINE_DEBUG_INFO
3352 : # pragma GCC poison DWARF2_ASM_LINE_DEBUG_INFO
3353 : #endif
3354 : }
3355 :
3356 : /* Return true if GCC configure detected assembler support for views
3357 : in .loc directives. */
3358 :
3359 : bool
3360 287800 : dwarf2out_default_as_locview_support (void)
3361 : {
3362 287800 : return DWARF2_ASM_VIEW_DEBUG_INFO;
3363 : #if (GCC_VERSION >= 3000)
3364 : # undef DWARF2_ASM_VIEW_DEBUG_INFO
3365 : # pragma GCC poison DWARF2_ASM_VIEW_DEBUG_INFO
3366 : #endif
3367 : }
3368 :
3369 : /* A bit is set in ZERO_VIEW_P if we are using the assembler-supported
3370 : view computation, and it refers to a view identifier for which we
3371 : will not emit a label because it is known to map to a view number
3372 : zero. We won't allocate the bitmap if we're not using assembler
3373 : support for location views, but we have to make the variable
3374 : visible for GGC and for code that will be optimized out for lack of
3375 : support but that's still parsed and compiled. We could abstract it
3376 : out with macros, but it's not worth it. */
3377 : static GTY(()) bitmap zero_view_p;
3378 :
3379 : /* Evaluate to TRUE iff N is known to identify the first location view
3380 : at its PC. When not using assembler location view computation,
3381 : that must be view number zero. Otherwise, ZERO_VIEW_P is allocated
3382 : and views label numbers recorded in it are the ones known to be
3383 : zero. */
3384 : #define ZERO_VIEW_P(N) ((N) == (var_loc_view)0 \
3385 : || (N) == (var_loc_view)-1 \
3386 : || (zero_view_p \
3387 : && bitmap_bit_p (zero_view_p, (N))))
3388 :
3389 : /* Return true iff we're to emit .loc directives for the assembler to
3390 : generate line number sections.
3391 :
3392 : When we're not emitting views, all we need from the assembler is
3393 : support for .loc directives.
3394 :
3395 : If we are emitting views, we can only use the assembler's .loc
3396 : support if it also supports views.
3397 :
3398 : When the compiler is emitting the line number programs and
3399 : computing view numbers itself, it resets view numbers at known PC
3400 : changes and counts from that, and then it emits view numbers as
3401 : literal constants in locviewlists. There are cases in which the
3402 : compiler is not sure about PC changes, e.g. when extra alignment is
3403 : requested for a label. In these cases, the compiler may not reset
3404 : the view counter, and the potential PC advance in the line number
3405 : program will use an opcode that does not reset the view counter
3406 : even if the PC actually changes, so that compiler and debug info
3407 : consumer can keep view numbers in sync.
3408 :
3409 : When the compiler defers view computation to the assembler, it
3410 : emits symbolic view numbers in locviewlists, with the exception of
3411 : views known to be zero (forced resets, or reset after
3412 : compiler-visible PC changes): instead of emitting symbols for
3413 : these, we emit literal zero and assert the assembler agrees with
3414 : the compiler's assessment. We could use symbolic views everywhere,
3415 : instead of special-casing zero views, but then we'd be unable to
3416 : optimize out locviewlists that contain only zeros. */
3417 :
3418 : static bool
3419 43727930 : output_asm_line_debug_info (void)
3420 : {
3421 43727930 : return (dwarf2out_as_loc_support
3422 43727930 : && (dwarf2out_as_locview_support
3423 0 : || !debug_variable_location_views));
3424 : }
3425 :
3426 : static bool asm_outputs_debug_line_str (void);
3427 :
3428 : /* Minimum line offset in a special line info. opcode.
3429 : This value was chosen to give a reasonable range of values. */
3430 : #define DWARF_LINE_BASE -10
3431 :
3432 : /* First special line opcode - leave room for the standard opcodes. */
3433 : #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
3434 :
3435 : /* Range of line offsets in a special line info. opcode. */
3436 : #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3437 :
3438 : /* Flag that indicates the initial value of the is_stmt_start flag.
3439 : In the present implementation, we do not mark any lines as
3440 : the beginning of a source statement, because that information
3441 : is not made available by the GCC front-end. */
3442 : #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3443 :
3444 : /* Maximum number of operations per instruction bundle. */
3445 : #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
3446 : #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
3447 : #endif
3448 :
3449 : /* This location is used by calc_die_sizes() to keep track
3450 : the offset of each DIE within the .debug_info section. */
3451 : static unsigned long next_die_offset;
3452 :
3453 : /* Record the root of the DIE's built for the current compilation unit. */
3454 : static GTY(()) dw_die_ref single_comp_unit_die;
3455 :
3456 : /* A list of type DIEs that have been separated into comdat sections. */
3457 : static GTY(()) comdat_type_node *comdat_type_list;
3458 :
3459 : /* A list of CU DIEs that have been separated. */
3460 : static GTY(()) limbo_die_node *cu_die_list;
3461 :
3462 : /* A list of DIEs with a NULL parent waiting to be relocated. */
3463 : static GTY(()) limbo_die_node *limbo_die_list;
3464 :
3465 : /* A list of DIEs for which we may have to generate
3466 : DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
3467 : static GTY(()) limbo_die_node *deferred_asm_name;
3468 :
3469 : struct dwarf_file_hasher : ggc_ptr_hash<dwarf_file_data>
3470 : {
3471 : typedef const char *compare_type;
3472 :
3473 : static hashval_t hash (dwarf_file_data *);
3474 : static bool equal (dwarf_file_data *, const char *);
3475 : };
3476 :
3477 : /* Filenames referenced by this compilation unit. */
3478 : static GTY(()) hash_table<dwarf_file_hasher> *file_table;
3479 :
3480 : struct decl_die_hasher : ggc_ptr_hash<die_node>
3481 : {
3482 : typedef tree compare_type;
3483 :
3484 : static hashval_t hash (die_node *);
3485 : static bool equal (die_node *, tree);
3486 : };
3487 : /* A hash table of references to DIE's that describe declarations.
3488 : The key is a DECL_UID() which is a unique number identifying each decl. */
3489 : static GTY (()) hash_table<decl_die_hasher> *decl_die_table;
3490 :
3491 : struct GTY ((for_user)) variable_value_struct {
3492 : unsigned int decl_id;
3493 : vec<dw_die_ref, va_gc> *dies;
3494 : };
3495 :
3496 : struct variable_value_hasher : ggc_ptr_hash<variable_value_struct>
3497 : {
3498 : typedef tree compare_type;
3499 :
3500 : static hashval_t hash (variable_value_struct *);
3501 : static bool equal (variable_value_struct *, tree);
3502 : };
3503 : /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
3504 : dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
3505 : DECL_CONTEXT of the referenced VAR_DECLs. */
3506 : static GTY (()) hash_table<variable_value_hasher> *variable_value_hash;
3507 :
3508 : struct block_die_hasher : ggc_ptr_hash<die_struct>
3509 : {
3510 : static hashval_t hash (die_struct *);
3511 : static bool equal (die_struct *, die_struct *);
3512 : };
3513 :
3514 : /* A hash table of references to DIE's that describe COMMON blocks.
3515 : The key is DECL_UID() ^ die_parent. */
3516 : static GTY (()) hash_table<block_die_hasher> *common_block_die_table;
3517 :
3518 : typedef struct GTY(()) die_arg_entry_struct {
3519 : dw_die_ref die;
3520 : tree arg;
3521 : } die_arg_entry;
3522 :
3523 :
3524 : /* Node of the variable location list. */
3525 : struct GTY ((chain_next ("%h.next"))) var_loc_node {
3526 : /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
3527 : EXPR_LIST chain. For small bitsizes, bitsize is encoded
3528 : in mode of the EXPR_LIST node and first EXPR_LIST operand
3529 : is either NOTE_INSN_VAR_LOCATION for a piece with a known
3530 : location or NULL for padding. For larger bitsizes,
3531 : mode is 0 and first operand is a CONCAT with bitsize
3532 : as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
3533 : NULL as second operand. */
3534 : rtx GTY (()) loc;
3535 : const char * GTY (()) label;
3536 : struct var_loc_node * GTY (()) next;
3537 : var_loc_view view;
3538 : };
3539 :
3540 : /* Variable location list. */
3541 : struct GTY ((for_user)) var_loc_list_def {
3542 : struct var_loc_node * GTY (()) first;
3543 :
3544 : /* Pointer to the last but one or last element of the
3545 : chained list. If the list is empty, both first and
3546 : last are NULL, if the list contains just one node
3547 : or the last node certainly is not redundant, it points
3548 : to the last node, otherwise points to the last but one.
3549 : Do not mark it for GC because it is marked through the chain. */
3550 : struct var_loc_node * GTY ((skip ("%h"))) last;
3551 :
3552 : /* Pointer to the last element before section switch,
3553 : if NULL, either sections weren't switched or first
3554 : is after section switch. */
3555 : struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
3556 :
3557 : /* DECL_UID of the variable decl. */
3558 : unsigned int decl_id;
3559 : };
3560 : typedef struct var_loc_list_def var_loc_list;
3561 :
3562 : /* Call argument location list. */
3563 : struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
3564 : rtx_insn * GTY (()) call_insn;
3565 : const char * GTY (()) label;
3566 : tree GTY (()) block;
3567 : bool tail_call_p;
3568 : rtx GTY (()) symbol_ref;
3569 : struct call_arg_loc_node * GTY (()) next;
3570 : };
3571 :
3572 :
3573 : struct decl_loc_hasher : ggc_ptr_hash<var_loc_list>
3574 : {
3575 : typedef const_tree compare_type;
3576 :
3577 : static hashval_t hash (var_loc_list *);
3578 : static bool equal (var_loc_list *, const_tree);
3579 : };
3580 :
3581 : /* Table of decl location linked lists. */
3582 : static GTY (()) hash_table<decl_loc_hasher> *decl_loc_table;
3583 :
3584 : /* Head and tail of call_arg_loc chain. */
3585 : static GTY (()) struct call_arg_loc_node *call_arg_locations;
3586 : static struct call_arg_loc_node *call_arg_loc_last;
3587 :
3588 : /* Number of call sites in the current function. */
3589 : static int call_site_count = -1;
3590 : /* Number of tail call sites in the current function. */
3591 : static int tail_call_site_count = -1;
3592 :
3593 : /* A cached location list. */
3594 : struct GTY ((for_user)) cached_dw_loc_list_def {
3595 : /* The DECL_UID of the decl that this entry describes. */
3596 : unsigned int decl_id;
3597 :
3598 : /* The cached location list. */
3599 : dw_loc_list_ref loc_list;
3600 : };
3601 : typedef struct cached_dw_loc_list_def cached_dw_loc_list;
3602 :
3603 : struct dw_loc_list_hasher : ggc_ptr_hash<cached_dw_loc_list>
3604 : {
3605 :
3606 : typedef const_tree compare_type;
3607 :
3608 : static hashval_t hash (cached_dw_loc_list *);
3609 : static bool equal (cached_dw_loc_list *, const_tree);
3610 : };
3611 :
3612 : /* Table of cached location lists. */
3613 : static GTY (()) hash_table<dw_loc_list_hasher> *cached_dw_loc_list_table;
3614 :
3615 : /* A vector of references to DIE's that are uniquely identified by their tag,
3616 : presence/absence of children DIE's, and list of attribute/value pairs. */
3617 : static GTY(()) vec<dw_die_ref, va_gc> *abbrev_die_table;
3618 :
3619 : /* A hash map to remember the stack usage for DWARF procedures. The value
3620 : stored is the stack size difference between before the DWARF procedure
3621 : invocation and after it returned. In other words, for a DWARF procedure
3622 : that consumes N stack slots and that pushes M ones, this stores M - N. */
3623 : static hash_map<dw_die_ref, int> *dwarf_proc_stack_usage_map;
3624 :
3625 : /* A global counter for generating labels for line number data. */
3626 : static unsigned int line_info_label_num;
3627 :
3628 : /* The current table to which we should emit line number information
3629 : for the current function. This will be set up at the beginning of
3630 : assembly for the function. */
3631 : static GTY(()) dw_line_info_table *cur_line_info_table;
3632 :
3633 : /* The two default tables of line number info. */
3634 : static GTY(()) dw_line_info_table *text_section_line_info;
3635 : static GTY(()) dw_line_info_table *cold_text_section_line_info;
3636 :
3637 : /* The set of all non-default tables of line number info. */
3638 : static GTY(()) vec<dw_line_info_table *, va_gc> *separate_line_info;
3639 :
3640 : /* A flag to tell pubnames/types export if there is an info section to
3641 : refer to. */
3642 : static bool info_section_emitted;
3643 :
3644 : /* A pointer to the base of a table that contains a list of publicly
3645 : accessible names. */
3646 : static GTY (()) vec<pubname_entry, va_gc> *pubname_table;
3647 :
3648 : /* A pointer to the base of a table that contains a list of publicly
3649 : accessible types. */
3650 : static GTY (()) vec<pubname_entry, va_gc> *pubtype_table;
3651 :
3652 : /* A pointer to the base of a table that contains a list of macro
3653 : defines/undefines (and file start/end markers). */
3654 : static GTY (()) vec<macinfo_entry, va_gc> *macinfo_table;
3655 :
3656 : /* True if .debug_macinfo or .debug_macros section is going to be
3657 : emitted. */
3658 : #define have_macinfo \
3659 : ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3660 : && debug_info_level >= DINFO_LEVEL_VERBOSE \
3661 : && !macinfo_table->is_empty ())
3662 :
3663 : /* Vector of dies for which we should generate .debug_ranges info. */
3664 : static GTY (()) vec<dw_ranges, va_gc> *ranges_table;
3665 :
3666 : /* Vector of pairs of labels referenced in ranges_table. */
3667 : static GTY (()) vec<dw_ranges_by_label, va_gc> *ranges_by_label;
3668 :
3669 : /* Whether we have location lists that need outputting */
3670 : static GTY(()) bool have_location_lists;
3671 :
3672 : /* Unique label counter. */
3673 : static GTY(()) unsigned int loclabel_num;
3674 :
3675 : /* Unique label counter for point-of-call tables. */
3676 : static GTY(()) unsigned int poc_label_num;
3677 :
3678 : /* The last file entry emitted by maybe_emit_file(). */
3679 : static GTY(()) struct dwarf_file_data * last_emitted_file;
3680 :
3681 : /* Number of internal labels generated by gen_internal_sym(). */
3682 : static GTY(()) int label_num;
3683 :
3684 : static GTY(()) vec<die_arg_entry, va_gc> *tmpl_value_parm_die_table;
3685 :
3686 : /* Instances of generic types for which we need to generate debug
3687 : info that describe their generic parameters and arguments. That
3688 : generation needs to happen once all types are properly laid out so
3689 : we do it at the end of compilation. */
3690 : static GTY(()) vec<tree, va_gc> *generic_type_instances;
3691 :
3692 : /* Offset from the "steady-state frame pointer" to the frame base,
3693 : within the current function. */
3694 : static poly_int64 frame_pointer_fb_offset;
3695 : static bool frame_pointer_fb_offset_valid;
3696 :
3697 : static vec<dw_die_ref> base_types;
3698 :
3699 : /* A cached btf_type_tag or btf_decl_tag user annotation. */
3700 : struct GTY ((for_user)) annotation_node
3701 : {
3702 : const char *name;
3703 : const char *value;
3704 : hashval_t hash;
3705 : dw_die_ref die;
3706 : struct annotation_node *next;
3707 : };
3708 :
3709 : /* Hasher for btf_type_tag and btf_decl_tag annotation nodes. */
3710 : struct annotation_node_hasher : ggc_ptr_hash<annotation_node>
3711 : {
3712 : typedef const struct annotation_node *compare_type;
3713 :
3714 : static hashval_t hash (struct annotation_node *);
3715 : static bool equal (const struct annotation_node *,
3716 : const struct annotation_node *);
3717 : };
3718 :
3719 : /* A hash table of tag annotation nodes for btf_type_tag and btf_decl_tag C
3720 : attributes. DIEs for these user annotations may be reused if they are
3721 : structurally equivalent; this hash table is used to ensure the DIEs are
3722 : reused wherever possible. */
3723 : static GTY (()) hash_table<annotation_node_hasher> *btf_tag_htab;
3724 :
3725 :
3726 : /* Flags to represent a set of attribute classes for attributes that represent
3727 : a scalar value (bounds, pointers, ...). */
3728 : enum dw_scalar_form
3729 : {
3730 : dw_scalar_form_constant = 0x01,
3731 : dw_scalar_form_exprloc = 0x02,
3732 : dw_scalar_form_reference = 0x04
3733 : };
3734 :
3735 : /* Forward declarations for functions defined in this file. */
3736 :
3737 : static bool is_pseudo_reg (const_rtx);
3738 : static tree type_main_variant (tree);
3739 : static bool is_tagged_type (const_tree);
3740 : static const char *dwarf_tag_name (unsigned);
3741 : static const char *dwarf_attr_name (unsigned);
3742 : static const char *dwarf_form_name (unsigned);
3743 : static tree decl_ultimate_origin (const_tree);
3744 : static tree decl_class_context (tree);
3745 : static void add_dwarf_attr (dw_die_ref, dw_attr_node *);
3746 : static inline unsigned int AT_index (dw_attr_node *);
3747 : static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3748 : static inline unsigned AT_flag (dw_attr_node *);
3749 : static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3750 : static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3751 : static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3752 : HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3753 : static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3754 : unsigned int, unsigned char *);
3755 : static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3756 : static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3757 : static inline const char *AT_string (dw_attr_node *);
3758 : static enum dwarf_form AT_string_form (dw_attr_node *);
3759 : static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3760 : static void add_AT_specification (dw_die_ref, dw_die_ref);
3761 : static inline dw_die_ref AT_ref (dw_attr_node *);
3762 : static inline int AT_ref_external (dw_attr_node *);
3763 : static inline void set_AT_ref_external (dw_attr_node *, int);
3764 : static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3765 : static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3766 : dw_loc_list_ref);
3767 : static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
3768 : static void add_AT_view_list (dw_die_ref, enum dwarf_attribute);
3769 : static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
3770 : static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
3771 : static void remove_addr_table_entry (addr_table_entry *);
3772 : static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
3773 : static inline rtx AT_addr (dw_attr_node *);
3774 : static void add_AT_symview (dw_die_ref, enum dwarf_attribute, const char *);
3775 : static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *,
3776 : int = 0);
3777 : static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3778 : static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3779 : static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3780 : unsigned long, bool);
3781 : static inline const char *AT_lbl (dw_attr_node *);
3782 : static const char *get_AT_low_pc (dw_die_ref);
3783 : static bool is_c (void);
3784 : static bool is_cxx (void);
3785 : static bool is_cxx (const_tree);
3786 : static bool is_fortran (void);
3787 : static bool is_ada (void);
3788 : static bool remove_AT (dw_die_ref, enum dwarf_attribute);
3789 : static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3790 : static void add_child_die (dw_die_ref, dw_die_ref);
3791 : static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3792 : static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3793 : static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3794 : static void equate_type_number_to_die (tree, dw_die_ref);
3795 : static var_loc_list *lookup_decl_loc (const_tree);
3796 : static void equate_decl_number_to_die (tree, dw_die_ref);
3797 : static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *, var_loc_view);
3798 : static void print_spaces (FILE *);
3799 : static void print_die (dw_die_ref, FILE *);
3800 : static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3801 : static void attr_checksum (dw_attr_node *, struct md5_ctx *, int *);
3802 : static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3803 : static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3804 : static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3805 : static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3806 : static void attr_checksum_ordered (enum dwarf_tag, dw_attr_node *,
3807 : struct md5_ctx *, int *);
3808 : struct checksum_attributes;
3809 : static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3810 : static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3811 : static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3812 : static void generate_type_signature (dw_die_ref, comdat_type_node *);
3813 : static bool same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3814 : static bool same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3815 : static bool same_attr_p (dw_attr_node *, dw_attr_node *, int *);
3816 : static bool same_die_p (dw_die_ref, dw_die_ref, int *);
3817 : static bool is_type_die (dw_die_ref);
3818 : static inline bool is_template_instantiation (dw_die_ref);
3819 : static bool is_declaration_die (dw_die_ref);
3820 : static bool should_move_die_to_comdat (dw_die_ref);
3821 : static dw_die_ref clone_as_declaration (dw_die_ref);
3822 : static dw_die_ref clone_die (dw_die_ref);
3823 : static dw_die_ref clone_tree (dw_die_ref);
3824 : static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3825 : static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3826 : static void generate_skeleton_bottom_up (skeleton_chain_node *);
3827 : static dw_die_ref generate_skeleton (dw_die_ref);
3828 : static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3829 : dw_die_ref,
3830 : dw_die_ref);
3831 : static void break_out_comdat_types (dw_die_ref);
3832 : static void copy_decls_for_unworthy_types (dw_die_ref);
3833 :
3834 : static void add_sibling_attributes (dw_die_ref);
3835 : static void output_location_lists (dw_die_ref);
3836 : static int constant_size (unsigned HOST_WIDE_INT);
3837 : static unsigned long size_of_die (dw_die_ref);
3838 : static void calc_die_sizes (dw_die_ref);
3839 : static void calc_base_type_die_sizes (void);
3840 : static void mark_dies (dw_die_ref);
3841 : static void unmark_dies (dw_die_ref);
3842 : static void unmark_all_dies (dw_die_ref);
3843 : static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
3844 : static unsigned long size_of_aranges (void);
3845 : static enum dwarf_form value_format (dw_attr_node *);
3846 : static void output_value_format (dw_attr_node *);
3847 : static void output_abbrev_section (void);
3848 : static void output_die_abbrevs (unsigned long, dw_die_ref);
3849 : static void output_die (dw_die_ref);
3850 : static void output_compilation_unit_header (enum dwarf_unit_type);
3851 : static void output_comp_unit (dw_die_ref, int, const unsigned char *);
3852 : static void output_comdat_type_unit (comdat_type_node *, bool);
3853 : static const char *dwarf2_name (tree, int);
3854 : static void add_pubname (tree, dw_die_ref);
3855 : static void add_enumerator_pubname (const char *, dw_die_ref);
3856 : static void add_pubname_string (const char *, dw_die_ref);
3857 : static void add_pubtype (tree, dw_die_ref);
3858 : static void output_pubnames (vec<pubname_entry, va_gc> *);
3859 : static void output_aranges (void);
3860 : static unsigned int add_ranges (const_tree, bool = false);
3861 : static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3862 : bool *, bool);
3863 : static void output_ranges (void);
3864 : static dw_line_info_table *new_line_info_table (void);
3865 : static void output_line_info (bool);
3866 : static void output_file_names (void);
3867 : static bool is_base_type (tree);
3868 : static dw_die_ref subrange_type_die (tree, tree, tree, tree, dw_die_ref);
3869 : static int decl_quals (const_tree);
3870 : static dw_die_ref modified_type_die (tree, int, tree, bool, dw_die_ref);
3871 : static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3872 : static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3873 : static unsigned int debugger_reg_number (const_rtx);
3874 : static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3875 : static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3876 : static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3877 : enum var_init_status);
3878 : static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3879 : enum var_init_status);
3880 : static dw_loc_descr_ref based_loc_descr (rtx, poly_int64,
3881 : enum var_init_status);
3882 : static bool is_based_loc (const_rtx);
3883 : static bool resolve_one_addr (rtx *);
3884 : static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3885 : enum var_init_status);
3886 : static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
3887 : enum var_init_status);
3888 : struct loc_descr_context;
3889 : static void add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref);
3890 : static void add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list);
3891 : static dw_loc_list_ref loc_list_from_tree (tree, int,
3892 : struct loc_descr_context *);
3893 : static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
3894 : struct loc_descr_context *);
3895 : static tree field_type (const_tree);
3896 : static unsigned int simple_type_align_in_bits (const_tree);
3897 : static unsigned int simple_decl_align_in_bits (const_tree);
3898 : static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3899 : struct vlr_context;
3900 : static dw_loc_descr_ref field_byte_offset (const_tree, struct vlr_context *,
3901 : HOST_WIDE_INT *);
3902 : static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3903 : dw_loc_list_ref);
3904 : static void add_data_member_location_attribute (dw_die_ref, tree,
3905 : struct vlr_context *);
3906 : static bool add_const_value_attribute (dw_die_ref, machine_mode, rtx);
3907 : static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3908 : static void insert_wide_int (const wide_int_ref &, unsigned char *, int);
3909 : static unsigned insert_float (const_rtx, unsigned char *);
3910 : static rtx rtl_for_decl_location (tree);
3911 : static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
3912 : static bool tree_add_const_value_attribute (dw_die_ref, tree);
3913 : static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3914 : static void add_desc_attribute (dw_die_ref, tree);
3915 : static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3916 : static void add_comp_dir_attribute (dw_die_ref);
3917 : static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
3918 : struct loc_descr_context *);
3919 : static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
3920 : struct loc_descr_context *);
3921 : static void add_subscript_info (dw_die_ref, tree, bool);
3922 : static void add_byte_size_attribute (dw_die_ref, tree);
3923 : static void add_alignment_attribute (dw_die_ref, tree);
3924 : static void add_bit_offset_attribute (dw_die_ref, tree);
3925 : static void add_bit_size_attribute (dw_die_ref, tree);
3926 : static void add_prototyped_attribute (dw_die_ref, tree);
3927 : static void add_abstract_origin_attribute (dw_die_ref, tree);
3928 : static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3929 : static void add_src_coords_attributes (dw_die_ref, tree);
3930 : static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool = false);
3931 : static void add_discr_value (dw_die_ref, dw_discr_value *);
3932 : static void add_discr_list (dw_die_ref, dw_discr_list_ref);
3933 : static inline dw_discr_list_ref AT_discr_list (dw_attr_node *);
3934 : static dw_die_ref scope_die_for (tree, dw_die_ref);
3935 : static inline bool local_scope_p (dw_die_ref);
3936 : static inline bool class_scope_p (dw_die_ref);
3937 : static inline bool class_or_namespace_scope_p (dw_die_ref);
3938 : static void add_type_attribute (dw_die_ref, tree, int, bool, dw_die_ref);
3939 : static void add_calling_convention_attribute (dw_die_ref, tree);
3940 : static const char *type_tag (const_tree);
3941 : static tree member_declared_type (const_tree);
3942 : #if 0
3943 : static const char *decl_start_label (tree);
3944 : #endif
3945 : static void gen_array_type_die (tree, dw_die_ref);
3946 : static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3947 : #if 0
3948 : static void gen_entry_point_die (tree, dw_die_ref);
3949 : #endif
3950 : static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref, bool);
3951 : static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3952 : static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3953 : static void gen_unspecified_parameters_die (tree, dw_die_ref);
3954 : static void gen_formal_types_die (tree, dw_die_ref);
3955 : static void gen_subprogram_die (tree, dw_die_ref);
3956 : static void gen_variable_die (tree, tree, dw_die_ref);
3957 : static void gen_const_die (tree, dw_die_ref);
3958 : static void gen_label_die (tree, dw_die_ref);
3959 : static void gen_lexical_block_die (tree, dw_die_ref);
3960 : static void gen_inlined_subroutine_die (tree, dw_die_ref);
3961 : static void gen_field_die (tree, struct vlr_context *, dw_die_ref);
3962 : static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3963 : static dw_die_ref gen_compile_unit_die (const char *);
3964 : static void gen_inheritance_die (tree, tree, tree, dw_die_ref);
3965 : static void gen_member_die (tree, dw_die_ref);
3966 : static void gen_struct_or_union_type_die (tree, dw_die_ref,
3967 : enum debug_info_usage);
3968 : static void gen_subroutine_type_die (tree, dw_die_ref);
3969 : static void gen_typedef_die (tree, dw_die_ref);
3970 : static void gen_type_die (tree, dw_die_ref, bool = false);
3971 : static void gen_block_die (tree, dw_die_ref);
3972 : static void decls_for_scope (tree, dw_die_ref, bool = true);
3973 : static bool is_naming_typedef_decl (const_tree);
3974 : static inline dw_die_ref get_context_die (tree);
3975 : static void gen_namespace_die (tree, dw_die_ref);
3976 : static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
3977 : static dw_die_ref gen_decl_die (tree, tree, struct vlr_context *, dw_die_ref);
3978 : static dw_die_ref force_decl_die (tree);
3979 : static dw_die_ref force_type_die (tree);
3980 : static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3981 : static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3982 : static struct dwarf_file_data * lookup_filename (const char *);
3983 : static void retry_incomplete_types (void);
3984 : static void gen_type_die_for_member (tree, tree, dw_die_ref);
3985 : static void gen_generic_params_dies (tree);
3986 : static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage,
3987 : bool = false);
3988 : static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage,
3989 : bool = false);
3990 : static void splice_child_die (dw_die_ref, dw_die_ref);
3991 : static int file_info_cmp (const void *, const void *);
3992 : static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *, var_loc_view,
3993 : const char *, var_loc_view, const char *);
3994 : static void output_loc_list (dw_loc_list_ref);
3995 : static char *gen_internal_sym (const char *);
3996 : static bool want_pubnames (void);
3997 :
3998 : static void prune_unmark_dies (dw_die_ref);
3999 : static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
4000 : static void prune_unused_types_mark (dw_die_ref, int);
4001 : static void prune_unused_types_walk (dw_die_ref);
4002 : static void prune_unused_types_walk_attribs (dw_die_ref);
4003 : static void prune_unused_types_prune (dw_die_ref);
4004 : static void prune_unused_types (void);
4005 : static int maybe_emit_file (struct dwarf_file_data *fd);
4006 : static inline const char *AT_vms_delta1 (dw_attr_node *);
4007 : static inline const char *AT_vms_delta2 (dw_attr_node *);
4008 : #if VMS_DEBUGGING_INFO
4009 : static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
4010 : const char *, const char *);
4011 : #endif
4012 : static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
4013 : static void gen_remaining_tmpl_value_param_die_attribute (void);
4014 : static bool generic_type_p (tree);
4015 : static void schedule_generic_params_dies_gen (tree t);
4016 : static void gen_scheduled_generic_parms_dies (void);
4017 : static void resolve_variable_values (void);
4018 :
4019 : static const char *comp_dir_string (void);
4020 :
4021 : static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
4022 :
4023 : /* enum for tracking thread-local variables whose address is really an offset
4024 : relative to the TLS pointer, which will need link-time relocation, but will
4025 : not need relocation by the DWARF consumer. */
4026 :
4027 : enum dtprel_bool
4028 : {
4029 : dtprel_false = 0,
4030 : dtprel_true = 1
4031 : };
4032 :
4033 : /* Return the operator to use for an address of a variable. For dtprel_true, we
4034 : use DW_OP_const*. For regular variables, which need both link-time
4035 : relocation and consumer-level relocation (e.g., to account for shared objects
4036 : loaded at a random address), we use DW_OP_addr*. */
4037 :
4038 : static inline enum dwarf_location_atom
4039 1604084 : dw_addr_op (enum dtprel_bool dtprel)
4040 : {
4041 1604084 : if (dtprel == dtprel_true)
4042 5290 : return (dwarf_split_debug_info ? dwarf_OP (DW_OP_constx)
4043 5290 : : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
4044 : else
4045 1598794 : return dwarf_split_debug_info ? dwarf_OP (DW_OP_addrx) : DW_OP_addr;
4046 : }
4047 :
4048 : /* Return a pointer to a newly allocated address location description. If
4049 : dwarf_split_debug_info is true, then record the address with the appropriate
4050 : relocation. */
4051 : static inline dw_loc_descr_ref
4052 1604084 : new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
4053 : {
4054 1604084 : dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
4055 :
4056 1604084 : ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
4057 1604084 : ref->dw_loc_oprnd1.v.val_addr = addr;
4058 1604084 : ref->dw_loc_dtprel = dtprel;
4059 1604084 : if (dwarf_split_debug_info)
4060 3 : ref->dw_loc_oprnd1.val_entry
4061 6 : = add_addr_table_entry (addr,
4062 : dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
4063 : else
4064 1604081 : ref->dw_loc_oprnd1.val_entry = NULL;
4065 :
4066 1604084 : return ref;
4067 : }
4068 :
4069 : /* Section names used to hold DWARF debugging information. */
4070 :
4071 : #ifndef DEBUG_INFO_SECTION
4072 : #define DEBUG_INFO_SECTION ".debug_info"
4073 : #endif
4074 : #ifndef DEBUG_DWO_INFO_SECTION
4075 : #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
4076 : #endif
4077 : #ifndef DEBUG_LTO_INFO_SECTION
4078 : #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
4079 : #endif
4080 : #ifndef DEBUG_LTO_DWO_INFO_SECTION
4081 : #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
4082 : #endif
4083 : #ifndef DEBUG_ABBREV_SECTION
4084 : #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4085 : #endif
4086 : #ifndef DEBUG_LTO_ABBREV_SECTION
4087 : #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
4088 : #endif
4089 : #ifndef DEBUG_DWO_ABBREV_SECTION
4090 : #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
4091 : #endif
4092 : #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
4093 : #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
4094 : #endif
4095 : #ifndef DEBUG_ARANGES_SECTION
4096 : #define DEBUG_ARANGES_SECTION ".debug_aranges"
4097 : #endif
4098 : #ifndef DEBUG_ADDR_SECTION
4099 : #define DEBUG_ADDR_SECTION ".debug_addr"
4100 : #endif
4101 : #ifndef DEBUG_MACINFO_SECTION
4102 : #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4103 : #endif
4104 : #ifndef DEBUG_LTO_MACINFO_SECTION
4105 : #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
4106 : #endif
4107 : #ifndef DEBUG_DWO_MACINFO_SECTION
4108 : #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
4109 : #endif
4110 : #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
4111 : #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
4112 : #endif
4113 : #ifndef DEBUG_MACRO_SECTION
4114 : #define DEBUG_MACRO_SECTION ".debug_macro"
4115 : #endif
4116 : #ifndef DEBUG_LTO_MACRO_SECTION
4117 : #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
4118 : #endif
4119 : #ifndef DEBUG_DWO_MACRO_SECTION
4120 : #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
4121 : #endif
4122 : #ifndef DEBUG_LTO_DWO_MACRO_SECTION
4123 : #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
4124 : #endif
4125 : #ifndef DEBUG_LINE_SECTION
4126 : #define DEBUG_LINE_SECTION ".debug_line"
4127 : #endif
4128 : #ifndef DEBUG_LTO_LINE_SECTION
4129 : #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
4130 : #endif
4131 : #ifndef DEBUG_DWO_LINE_SECTION
4132 : #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
4133 : #endif
4134 : #ifndef DEBUG_LTO_DWO_LINE_SECTION
4135 : #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
4136 : #endif
4137 : #ifndef DEBUG_LOC_SECTION
4138 : #define DEBUG_LOC_SECTION ".debug_loc"
4139 : #endif
4140 : #ifndef DEBUG_DWO_LOC_SECTION
4141 : #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
4142 : #endif
4143 : #ifndef DEBUG_LOCLISTS_SECTION
4144 : #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
4145 : #endif
4146 : #ifndef DEBUG_DWO_LOCLISTS_SECTION
4147 : #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
4148 : #endif
4149 : #ifndef DEBUG_PUBNAMES_SECTION
4150 : #define DEBUG_PUBNAMES_SECTION \
4151 : ((debug_generate_pub_sections == 2) \
4152 : ? ".debug_gnu_pubnames" : ".debug_pubnames")
4153 : #endif
4154 : #ifndef DEBUG_PUBTYPES_SECTION
4155 : #define DEBUG_PUBTYPES_SECTION \
4156 : ((debug_generate_pub_sections == 2) \
4157 : ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
4158 : #endif
4159 : #ifndef DEBUG_STR_OFFSETS_SECTION
4160 : #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
4161 : #endif
4162 : #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
4163 : #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
4164 : #endif
4165 : #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
4166 : #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
4167 : #endif
4168 : #ifndef DEBUG_STR_SECTION
4169 : #define DEBUG_STR_SECTION ".debug_str"
4170 : #endif
4171 : #ifndef DEBUG_LTO_STR_SECTION
4172 : #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
4173 : #endif
4174 : #ifndef DEBUG_STR_DWO_SECTION
4175 : #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
4176 : #endif
4177 : #ifndef DEBUG_LTO_STR_DWO_SECTION
4178 : #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
4179 : #endif
4180 : #ifndef DEBUG_RANGES_SECTION
4181 : #define DEBUG_RANGES_SECTION ".debug_ranges"
4182 : #endif
4183 : #ifndef DEBUG_RNGLISTS_SECTION
4184 : #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
4185 : #endif
4186 : #ifndef DEBUG_DWO_RNGLISTS_SECTION
4187 : #define DEBUG_DWO_RNGLISTS_SECTION ".debug_rnglists.dwo"
4188 : #endif
4189 : #ifndef DEBUG_LINE_STR_SECTION
4190 : #define DEBUG_LINE_STR_SECTION ".debug_line_str"
4191 : #endif
4192 : #ifndef DEBUG_LTO_LINE_STR_SECTION
4193 : #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
4194 : #endif
4195 :
4196 : /* Section flags for .debug_str section. */
4197 : #define DEBUG_STR_SECTION_FLAGS \
4198 : (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4199 : ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4200 : : SECTION_DEBUG)
4201 :
4202 : /* Section flags for .debug_str.dwo section. */
4203 : #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
4204 :
4205 : /* Attribute used to refer to the macro section. */
4206 : #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
4207 : : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
4208 :
4209 : /* Labels we insert at beginning sections we can reference instead of
4210 : the section names themselves. */
4211 :
4212 : #ifndef TEXT_SECTION_LABEL
4213 : #define TEXT_SECTION_LABEL "Ltext"
4214 : #endif
4215 : #ifndef COLD_TEXT_SECTION_LABEL
4216 : #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4217 : #endif
4218 : #ifndef DEBUG_LINE_SECTION_LABEL
4219 : #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4220 : #endif
4221 : #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
4222 : #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
4223 : #endif
4224 : #ifndef DEBUG_INFO_SECTION_LABEL
4225 : #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4226 : #endif
4227 : #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
4228 : #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
4229 : #endif
4230 : #ifndef DEBUG_ABBREV_SECTION_LABEL
4231 : #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4232 : #endif
4233 : #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
4234 : #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
4235 : #endif
4236 : #ifndef DEBUG_ADDR_SECTION_LABEL
4237 : #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
4238 : #endif
4239 : #ifndef DEBUG_LOC_SECTION_LABEL
4240 : #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4241 : #endif
4242 : #ifndef DEBUG_RANGES_SECTION_LABEL
4243 : #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4244 : #endif
4245 : #ifndef DEBUG_MACINFO_SECTION_LABEL
4246 : #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4247 : #endif
4248 : #ifndef DEBUG_MACRO_SECTION_LABEL
4249 : #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
4250 : #endif
4251 : #define SKELETON_COMP_DIE_ABBREV 1
4252 : #define SKELETON_TYPE_DIE_ABBREV 2
4253 :
4254 : /* Definitions of defaults for formats and names of various special
4255 : (artificial) labels which may be generated within this file (when the -g
4256 : options is used and DWARF2_DEBUGGING_INFO is in effect.
4257 : If necessary, these may be overridden from within the tm.h file, but
4258 : typically, overriding these defaults is unnecessary. */
4259 :
4260 : static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4261 : static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4262 : static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4263 : static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4264 : static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4265 : static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4266 : static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4267 : static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4268 : static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4269 : static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4270 : static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4271 : static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4272 : static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4273 : static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4274 : static char ranges_base_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4275 :
4276 : #ifndef TEXT_END_LABEL
4277 : #define TEXT_END_LABEL "Letext"
4278 : #endif
4279 : #ifndef COLD_END_LABEL
4280 : #define COLD_END_LABEL "Letext_cold"
4281 : #endif
4282 : #ifndef BLOCK_BEGIN_LABEL
4283 : #define BLOCK_BEGIN_LABEL "LBB"
4284 : #endif
4285 : #ifndef BLOCK_INLINE_ENTRY_LABEL
4286 : #define BLOCK_INLINE_ENTRY_LABEL "LBI"
4287 : #endif
4288 : #ifndef BLOCK_END_LABEL
4289 : #define BLOCK_END_LABEL "LBE"
4290 : #endif
4291 : #ifndef LINE_CODE_LABEL
4292 : #define LINE_CODE_LABEL "LM"
4293 : #endif
4294 :
4295 :
4296 : /* Return the root of the DIE's built for the current compilation unit. */
4297 : static dw_die_ref
4298 597003475 : comp_unit_die (void)
4299 : {
4300 597003475 : if (!single_comp_unit_die)
4301 56922 : single_comp_unit_die = gen_compile_unit_die (NULL);
4302 597003475 : return single_comp_unit_die;
4303 : }
4304 :
4305 : /* We allow a language front-end to designate a function that is to be
4306 : called to "demangle" any name before it is put into a DIE. */
4307 :
4308 : static const char *(*demangle_name_func) (const char *);
4309 :
4310 : void
4311 0 : dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4312 : {
4313 0 : demangle_name_func = func;
4314 0 : }
4315 :
4316 : /* Test if rtl node points to a pseudo register. */
4317 :
4318 : static inline bool
4319 1354488 : is_pseudo_reg (const_rtx rtl)
4320 : {
4321 913024 : return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4322 1499408 : || (GET_CODE (rtl) == SUBREG
4323 525 : && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4324 : }
4325 :
4326 : /* Return a reference to a type, with its const and volatile qualifiers
4327 : removed. */
4328 :
4329 : static inline tree
4330 845485174 : type_main_variant (tree type)
4331 : {
4332 845485174 : type = TYPE_MAIN_VARIANT (type);
4333 :
4334 : /* ??? There really should be only one main variant among any group of
4335 : variants of a given type (and all of the MAIN_VARIANT values for all
4336 : members of the group should point to that one type) but sometimes the C
4337 : front-end messes this up for array types, so we work around that bug
4338 : here. */
4339 845485174 : if (TREE_CODE (type) == ARRAY_TYPE)
4340 0 : while (type != TYPE_MAIN_VARIANT (type))
4341 0 : type = TYPE_MAIN_VARIANT (type);
4342 :
4343 845485174 : return type;
4344 : }
4345 :
4346 : /* Return true if the given type node represents a tagged type. */
4347 :
4348 : static inline bool
4349 978878434 : is_tagged_type (const_tree type)
4350 : {
4351 978878434 : enum tree_code code = TREE_CODE (type);
4352 :
4353 978878434 : return (code == RECORD_TYPE || code == UNION_TYPE
4354 978878434 : || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4355 : }
4356 :
4357 : /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4358 :
4359 : static void
4360 1197399 : get_ref_die_offset_label (char *label, dw_die_ref ref)
4361 : {
4362 1197399 : sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
4363 0 : }
4364 :
4365 : /* Return die_offset of a DIE reference to a base type. */
4366 :
4367 : static unsigned long int
4368 1411551 : get_base_type_offset (dw_die_ref ref)
4369 : {
4370 1411551 : if (ref->die_offset)
4371 1077827 : return ref->die_offset;
4372 333724 : if (comp_unit_die ()->die_abbrev)
4373 : {
4374 9 : calc_base_type_die_sizes ();
4375 9 : gcc_assert (ref->die_offset);
4376 : }
4377 333724 : return ref->die_offset;
4378 : }
4379 :
4380 : /* Return die_offset of a DIE reference other than base type. */
4381 :
4382 : static unsigned long int
4383 29727 : get_ref_die_offset (dw_die_ref ref)
4384 : {
4385 29727 : gcc_assert (ref->die_offset);
4386 29727 : return ref->die_offset;
4387 : }
4388 :
4389 : /* Convert a DIE tag into its string name. */
4390 :
4391 : static const char *
4392 81713452 : dwarf_tag_name (unsigned int tag)
4393 : {
4394 0 : const char *name = get_DW_TAG_name (tag);
4395 :
4396 81713452 : if (name != NULL)
4397 81713452 : return name;
4398 :
4399 : return "DW_TAG_<unknown>";
4400 : }
4401 :
4402 : /* Convert a DWARF attribute code into its string name. */
4403 :
4404 : static const char *
4405 365256168 : dwarf_attr_name (unsigned int attr)
4406 : {
4407 365256168 : const char *name;
4408 :
4409 365256168 : switch (attr)
4410 : {
4411 : #if VMS_DEBUGGING_INFO
4412 : case DW_AT_HP_prologue:
4413 : return "DW_AT_HP_prologue";
4414 : #else
4415 : case DW_AT_MIPS_loop_unroll_factor:
4416 : return "DW_AT_MIPS_loop_unroll_factor";
4417 : #endif
4418 :
4419 : #if VMS_DEBUGGING_INFO
4420 : case DW_AT_HP_epilogue:
4421 : return "DW_AT_HP_epilogue";
4422 : #else
4423 0 : case DW_AT_MIPS_stride:
4424 0 : return "DW_AT_MIPS_stride";
4425 : #endif
4426 : }
4427 :
4428 365256168 : name = get_DW_AT_name (attr);
4429 :
4430 365256168 : if (name != NULL)
4431 365256168 : return name;
4432 :
4433 : return "DW_AT_<unknown>";
4434 : }
4435 :
4436 : /* Convert a DWARF value form code into its string name. */
4437 :
4438 : static const char *
4439 15826924 : dwarf_form_name (unsigned int form)
4440 : {
4441 0 : const char *name = get_DW_FORM_name (form);
4442 :
4443 15826924 : if (name != NULL)
4444 15826924 : return name;
4445 :
4446 : return "DW_FORM_<unknown>";
4447 : }
4448 :
4449 : /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4450 : instance of an inlined instance of a decl which is local to an inline
4451 : function, so we have to trace all of the way back through the origin chain
4452 : to find out what sort of node actually served as the original seed for the
4453 : given block. */
4454 :
4455 : static tree
4456 404737154 : decl_ultimate_origin (const_tree decl)
4457 : {
4458 404737154 : if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4459 : return NULL_TREE;
4460 :
4461 : /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4462 : we're trying to output the abstract instance of this function. */
4463 404737154 : if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4464 : return NULL_TREE;
4465 :
4466 : /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4467 : most distant ancestor, this should never happen. */
4468 446427299 : gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4469 :
4470 404733838 : return DECL_ABSTRACT_ORIGIN (decl);
4471 : }
4472 :
4473 : /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4474 : of a virtual function may refer to a base class, so we check the 'this'
4475 : parameter. */
4476 :
4477 : static tree
4478 158986295 : decl_class_context (tree decl)
4479 : {
4480 158986295 : tree context = NULL_TREE;
4481 :
4482 158986295 : if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4483 157801510 : context = DECL_CONTEXT (decl);
4484 : else
4485 1184785 : context = TYPE_MAIN_VARIANT
4486 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4487 :
4488 158986295 : if (context && !TYPE_P (context))
4489 41476333 : context = NULL_TREE;
4490 :
4491 158986295 : return context;
4492 : }
4493 :
4494 : /* Add an attribute/value pair to a DIE. */
4495 :
4496 : static inline void
4497 2660187359 : add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
4498 : {
4499 : /* Maybe this should be an assert? */
4500 2660187359 : if (die == NULL)
4501 : return;
4502 :
4503 2660004872 : if (flag_checking)
4504 : {
4505 : /* Check we do not add duplicate attrs. Can't use get_AT here
4506 : because that recurses to the specification/abstract origin DIE. */
4507 : dw_attr_node *a;
4508 : unsigned ix;
4509 10018600253 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4510 7358595628 : gcc_assert (a->dw_attr != attr->dw_attr);
4511 : }
4512 :
4513 2660004872 : vec_safe_reserve (die->die_attr, 1);
4514 2660004872 : vec_safe_push (die->die_attr, *attr);
4515 : }
4516 :
4517 : enum dw_val_class
4518 6458217572 : AT_class (dw_attr_node *a)
4519 : {
4520 6458217572 : return a->dw_attr_val.val_class;
4521 : }
4522 :
4523 : /* Return the index for any attribute that will be referenced with a
4524 : DW_FORM_addrx/GNU_addr_index or DW_FORM_strx/GNU_str_index. String
4525 : indices are stored in dw_attr_val.v.val_str for reference counting
4526 : pruning. */
4527 :
4528 : static inline unsigned int
4529 49559874 : AT_index (dw_attr_node *a)
4530 : {
4531 49559874 : if (AT_class (a) == dw_val_class_str)
4532 1870 : return a->dw_attr_val.v.val_str->index;
4533 49558004 : else if (a->dw_attr_val.val_entry != NULL)
4534 1771 : return a->dw_attr_val.val_entry->index;
4535 : return NOT_INDEXED;
4536 : }
4537 :
4538 : /* Add a flag value attribute to a DIE. */
4539 :
4540 : static inline void
4541 430149270 : add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4542 : {
4543 430149270 : dw_attr_node attr;
4544 :
4545 430149270 : attr.dw_attr = attr_kind;
4546 430149270 : attr.dw_attr_val.val_class = dw_val_class_flag;
4547 430149270 : attr.dw_attr_val.val_entry = NULL;
4548 430149270 : attr.dw_attr_val.v.val_flag = flag;
4549 430149270 : add_dwarf_attr (die, &attr);
4550 198003330 : }
4551 :
4552 : static inline unsigned
4553 88536659 : AT_flag (dw_attr_node *a)
4554 : {
4555 88536659 : gcc_assert (a && AT_class (a) == dw_val_class_flag);
4556 88536659 : return a->dw_attr_val.v.val_flag;
4557 : }
4558 :
4559 : /* Add a signed integer attribute value to a DIE. */
4560 :
4561 : static inline void
4562 412336 : add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4563 : {
4564 412336 : dw_attr_node attr;
4565 :
4566 412336 : attr.dw_attr = attr_kind;
4567 412336 : attr.dw_attr_val.val_class = dw_val_class_const;
4568 412336 : attr.dw_attr_val.val_entry = NULL;
4569 412336 : attr.dw_attr_val.v.val_int = int_val;
4570 412336 : add_dwarf_attr (die, &attr);
4571 203105 : }
4572 :
4573 : HOST_WIDE_INT
4574 29706 : AT_int (dw_attr_node *a)
4575 : {
4576 29706 : gcc_assert (a && (AT_class (a) == dw_val_class_const
4577 : || AT_class (a) == dw_val_class_const_implicit));
4578 29706 : return a->dw_attr_val.v.val_int;
4579 : }
4580 :
4581 : /* Add an unsigned integer attribute value to a DIE. */
4582 :
4583 : static inline void
4584 814721534 : add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4585 : unsigned HOST_WIDE_INT unsigned_val)
4586 : {
4587 814721534 : dw_attr_node attr;
4588 :
4589 814721534 : attr.dw_attr = attr_kind;
4590 814721534 : attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4591 814721534 : attr.dw_attr_val.val_entry = NULL;
4592 814721534 : attr.dw_attr_val.v.val_unsigned = unsigned_val;
4593 1821765 : add_dwarf_attr (die, &attr);
4594 480083507 : }
4595 :
4596 : unsigned HOST_WIDE_INT
4597 889676802 : AT_unsigned (dw_attr_node *a)
4598 : {
4599 889676802 : gcc_assert (a && (AT_class (a) == dw_val_class_unsigned_const
4600 : || AT_class (a) == dw_val_class_unsigned_const_implicit));
4601 889676802 : return a->dw_attr_val.v.val_unsigned;
4602 : }
4603 :
4604 : dw_wide_int *
4605 784 : alloc_dw_wide_int (const wide_int_ref &w)
4606 : {
4607 784 : dw_wide_int *p
4608 784 : = (dw_wide_int *) ggc_internal_alloc (sizeof (dw_wide_int)
4609 784 : + ((w.get_len () - 1)
4610 : * sizeof (HOST_WIDE_INT)));
4611 784 : p->precision = w.get_precision ();
4612 784 : p->len = w.get_len ();
4613 784 : memcpy (p->val, w.get_val (), p->len * sizeof (HOST_WIDE_INT));
4614 784 : return p;
4615 : }
4616 :
4617 : /* Add an unsigned wide integer attribute value to a DIE. */
4618 :
4619 : static inline void
4620 43 : add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
4621 : const wide_int_ref &w)
4622 : {
4623 43 : dw_attr_node attr;
4624 :
4625 43 : attr.dw_attr = attr_kind;
4626 43 : attr.dw_attr_val.val_class = dw_val_class_wide_int;
4627 43 : attr.dw_attr_val.val_entry = NULL;
4628 43 : attr.dw_attr_val.v.val_wide = alloc_dw_wide_int (w);
4629 43 : add_dwarf_attr (die, &attr);
4630 43 : }
4631 :
4632 : /* Add an unsigned double integer attribute value to a DIE. */
4633 :
4634 : static inline void
4635 : add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4636 : HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4637 : {
4638 : dw_attr_node attr;
4639 :
4640 : attr.dw_attr = attr_kind;
4641 : attr.dw_attr_val.val_class = dw_val_class_const_double;
4642 : attr.dw_attr_val.val_entry = NULL;
4643 : attr.dw_attr_val.v.val_double.high = high;
4644 : attr.dw_attr_val.v.val_double.low = low;
4645 : add_dwarf_attr (die, &attr);
4646 : }
4647 :
4648 : /* Add a floating point attribute value to a DIE and return it. */
4649 :
4650 : static inline void
4651 2282381 : add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4652 : unsigned int length, unsigned int elt_size, unsigned char *array)
4653 : {
4654 2282381 : dw_attr_node attr;
4655 :
4656 2282381 : attr.dw_attr = attr_kind;
4657 2282381 : attr.dw_attr_val.val_class = dw_val_class_vec;
4658 2282381 : attr.dw_attr_val.val_entry = NULL;
4659 2282381 : attr.dw_attr_val.v.val_vec.length = length;
4660 2282381 : attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4661 2282381 : attr.dw_attr_val.v.val_vec.array = array;
4662 2282381 : add_dwarf_attr (die, &attr);
4663 : }
4664 :
4665 : /* Add an 8-byte data attribute value to a DIE. */
4666 :
4667 : static inline void
4668 71 : add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4669 : unsigned char data8[8])
4670 : {
4671 71 : dw_attr_node attr;
4672 :
4673 71 : attr.dw_attr = attr_kind;
4674 71 : attr.dw_attr_val.val_class = dw_val_class_data8;
4675 71 : attr.dw_attr_val.val_entry = NULL;
4676 71 : memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4677 71 : add_dwarf_attr (die, &attr);
4678 71 : }
4679 :
4680 : /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4681 : dwarf_split_debug_info, address attributes in dies destined for the
4682 : final executable have force_direct set to avoid using indexed
4683 : references. */
4684 :
4685 : static inline void
4686 4413161 : add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
4687 : bool force_direct)
4688 : {
4689 4413161 : dw_attr_node attr;
4690 4413161 : char * lbl_id;
4691 :
4692 4413161 : lbl_id = xstrdup (lbl_low);
4693 4413161 : attr.dw_attr = DW_AT_low_pc;
4694 4413161 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4695 4413161 : attr.dw_attr_val.v.val_lbl_id = lbl_id;
4696 4413161 : if (dwarf_split_debug_info && !force_direct)
4697 242 : attr.dw_attr_val.val_entry
4698 242 : = add_addr_table_entry (lbl_id, ate_kind_label);
4699 : else
4700 4412919 : attr.dw_attr_val.val_entry = NULL;
4701 4413161 : add_dwarf_attr (die, &attr);
4702 :
4703 4413161 : attr.dw_attr = DW_AT_high_pc;
4704 4413161 : if (dwarf_version < 4)
4705 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4706 : else
4707 4407458 : attr.dw_attr_val.val_class = dw_val_class_high_pc;
4708 4413161 : lbl_id = xstrdup (lbl_high);
4709 4413161 : attr.dw_attr_val.v.val_lbl_id = lbl_id;
4710 4413161 : if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
4711 5703 : && dwarf_split_debug_info && !force_direct)
4712 0 : attr.dw_attr_val.val_entry
4713 0 : = add_addr_table_entry (lbl_id, ate_kind_label);
4714 : else
4715 4413161 : attr.dw_attr_val.val_entry = NULL;
4716 4413161 : add_dwarf_attr (die, &attr);
4717 4413161 : }
4718 :
4719 : /* Hash and equality functions for debug_str_hash. */
4720 :
4721 : hashval_t
4722 3074351343 : indirect_string_hasher::hash (indirect_string_node *x)
4723 : {
4724 3074351343 : return htab_hash_string (x->str);
4725 : }
4726 :
4727 : bool
4728 3478908523 : indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
4729 : {
4730 3478908523 : return strcmp (x1->str, x2) == 0;
4731 : }
4732 :
4733 : /* Add STR to the given string hash table. */
4734 :
4735 : static struct indirect_string_node *
4736 448564445 : find_AT_string_in_table (const char *str,
4737 : hash_table<indirect_string_hasher> *table,
4738 : enum insert_option insert = INSERT)
4739 : {
4740 448564445 : struct indirect_string_node *node;
4741 :
4742 448564445 : indirect_string_node **slot
4743 448564445 : = table->find_slot_with_hash (str, htab_hash_string (str), insert);
4744 448564445 : if (*slot == NULL)
4745 : {
4746 224935030 : node = ggc_cleared_alloc<indirect_string_node> ();
4747 224935030 : node->str = ggc_strdup (str);
4748 224935030 : *slot = node;
4749 : }
4750 : else
4751 : node = *slot;
4752 :
4753 448564445 : node->refcount++;
4754 448564445 : return node;
4755 : }
4756 :
4757 : /* Add STR to the indirect string hash table. */
4758 :
4759 : static struct indirect_string_node *
4760 448452162 : find_AT_string (const char *str, enum insert_option insert = INSERT)
4761 : {
4762 448452162 : if (! debug_str_hash)
4763 56922 : debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
4764 :
4765 448452162 : return find_AT_string_in_table (str, debug_str_hash, insert);
4766 : }
4767 :
4768 : /* Add a string attribute value to a DIE. */
4769 :
4770 : static inline void
4771 447917045 : add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4772 : {
4773 447917045 : dw_attr_node attr;
4774 447917045 : struct indirect_string_node *node;
4775 :
4776 447917045 : node = find_AT_string (str);
4777 :
4778 447917045 : attr.dw_attr = attr_kind;
4779 447917045 : attr.dw_attr_val.val_class = dw_val_class_str;
4780 447917045 : attr.dw_attr_val.val_entry = NULL;
4781 447917045 : attr.dw_attr_val.v.val_str = node;
4782 447917045 : add_dwarf_attr (die, &attr);
4783 447917045 : }
4784 :
4785 : static inline const char *
4786 32974106 : AT_string (dw_attr_node *a)
4787 : {
4788 32974106 : gcc_assert (a && AT_class (a) == dw_val_class_str);
4789 32974106 : return a->dw_attr_val.v.val_str->str;
4790 : }
4791 :
4792 : /* Call this function directly to bypass AT_string_form's logic to put
4793 : the string inline in the die. */
4794 :
4795 : static void
4796 19520934 : set_indirect_string (struct indirect_string_node *node)
4797 : {
4798 19520934 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
4799 : /* Already indirect is a no op. */
4800 19520934 : if (node->form == DW_FORM_strp
4801 19520137 : || node->form == DW_FORM_line_strp
4802 39281761 : || node->form == dwarf_FORM (DW_FORM_strx))
4803 : {
4804 3632 : gcc_assert (node->label);
4805 3632 : return;
4806 : }
4807 19517302 : ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4808 19517302 : ++dw2_string_counter;
4809 19517302 : node->label = xstrdup (label);
4810 :
4811 19517302 : if (!dwarf_split_debug_info)
4812 : {
4813 19514194 : node->form = DW_FORM_strp;
4814 19514194 : node->index = NOT_INDEXED;
4815 : }
4816 : else
4817 : {
4818 3108 : node->form = dwarf_FORM (DW_FORM_strx);
4819 3108 : node->index = NO_INDEX_ASSIGNED;
4820 : }
4821 : }
4822 :
4823 : /* A helper function for dwarf2out_finish, called to reset indirect
4824 : string decisions done for early LTO dwarf output before fat object
4825 : dwarf output. */
4826 :
4827 : int
4828 18700 : reset_indirect_string (indirect_string_node **h, void *)
4829 : {
4830 18700 : struct indirect_string_node *node = *h;
4831 18700 : if (node->form == DW_FORM_strp
4832 6323 : || node->form == DW_FORM_line_strp
4833 21971 : || node->form == dwarf_FORM (DW_FORM_strx))
4834 : {
4835 15459 : free (node->label);
4836 15459 : node->label = NULL;
4837 15459 : node->form = (dwarf_form) 0;
4838 15459 : node->index = 0;
4839 : }
4840 18700 : return 1;
4841 : }
4842 :
4843 : /* Add a string representing a file or filepath attribute value to a DIE. */
4844 :
4845 : static inline void
4846 106404 : add_filepath_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
4847 : const char *str)
4848 : {
4849 106404 : if (! asm_outputs_debug_line_str ())
4850 4580 : add_AT_string (die, attr_kind, str);
4851 : else
4852 : {
4853 101824 : dw_attr_node attr;
4854 101824 : struct indirect_string_node *node;
4855 :
4856 101824 : if (!debug_line_str_hash)
4857 50912 : debug_line_str_hash
4858 50912 : = hash_table<indirect_string_hasher>::create_ggc (10);
4859 :
4860 101824 : node = find_AT_string_in_table (str, debug_line_str_hash);
4861 101824 : set_indirect_string (node);
4862 101824 : node->form = DW_FORM_line_strp;
4863 :
4864 101824 : attr.dw_attr = attr_kind;
4865 101824 : attr.dw_attr_val.val_class = dw_val_class_str;
4866 101824 : attr.dw_attr_val.val_entry = NULL;
4867 101824 : attr.dw_attr_val.v.val_str = node;
4868 101824 : add_dwarf_attr (die, &attr);
4869 : }
4870 106404 : }
4871 :
4872 : /* Find out whether a string should be output inline in DIE
4873 : or out-of-line in .debug_str section. */
4874 :
4875 : static enum dwarf_form
4876 205738934 : find_string_form (struct indirect_string_node *node)
4877 : {
4878 205738934 : unsigned int len;
4879 :
4880 205738934 : if (node->form)
4881 : return node->form;
4882 :
4883 19860792 : len = strlen (node->str) + 1;
4884 :
4885 : /* If the string is shorter or equal to the size of the reference, it is
4886 : always better to put it inline. */
4887 19860792 : if (len <= (unsigned) dwarf_offset_size || node->refcount == 0)
4888 692093 : return node->form = DW_FORM_string;
4889 :
4890 : /* If we cannot expect the linker to merge strings in .debug_str
4891 : section, only put it into .debug_str if it is worth even in this
4892 : single module. */
4893 19168699 : if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4894 19168699 : || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4895 759 : && (len - dwarf_offset_size) * node->refcount <= len))
4896 734 : return node->form = DW_FORM_string;
4897 :
4898 19167965 : set_indirect_string (node);
4899 :
4900 19167965 : return node->form;
4901 : }
4902 :
4903 : /* Find out whether the string referenced from the attribute should be
4904 : output inline in DIE or out-of-line in .debug_str section. */
4905 :
4906 : static enum dwarf_form
4907 185526844 : AT_string_form (dw_attr_node *a)
4908 : {
4909 185526844 : gcc_assert (a && AT_class (a) == dw_val_class_str);
4910 185526844 : return find_string_form (a->dw_attr_val.v.val_str);
4911 : }
4912 :
4913 : /* Add a DIE reference attribute value to a DIE. */
4914 :
4915 : static inline void
4916 640507547 : add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4917 : {
4918 640507547 : dw_attr_node attr;
4919 640507547 : gcc_checking_assert (targ_die != NULL);
4920 640507547 : gcc_assert (targ_die != die
4921 : || (attr_kind != DW_AT_abstract_origin
4922 : && attr_kind != DW_AT_specification));
4923 :
4924 : /* With LTO we can end up trying to reference something we didn't create
4925 : a DIE for. Avoid crashing later on a NULL referenced DIE. */
4926 640507547 : if (targ_die == NULL)
4927 : return;
4928 :
4929 640507547 : attr.dw_attr = attr_kind;
4930 640507547 : attr.dw_attr_val.val_class = dw_val_class_die_ref;
4931 640507547 : attr.dw_attr_val.val_entry = NULL;
4932 640507547 : attr.dw_attr_val.v.val_die_ref.die = targ_die;
4933 640507547 : attr.dw_attr_val.v.val_die_ref.external = 0;
4934 640507547 : add_dwarf_attr (die, &attr);
4935 : }
4936 :
4937 : /* Change DIE reference REF to point to NEW_DIE instead. */
4938 :
4939 : static inline void
4940 139 : change_AT_die_ref (dw_attr_node *ref, dw_die_ref new_die)
4941 : {
4942 139 : gcc_assert (ref->dw_attr_val.val_class == dw_val_class_die_ref);
4943 139 : ref->dw_attr_val.v.val_die_ref.die = new_die;
4944 139 : ref->dw_attr_val.v.val_die_ref.external = 0;
4945 139 : }
4946 :
4947 : /* Add an AT_specification attribute to a DIE, and also make the back
4948 : pointer from the specification to the definition. */
4949 :
4950 : static inline void
4951 30144260 : add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4952 : {
4953 30144260 : add_AT_die_ref (die, DW_AT_specification, targ_die);
4954 30144260 : gcc_assert (!targ_die->die_definition);
4955 30144260 : targ_die->die_definition = die;
4956 30144260 : }
4957 :
4958 : static inline dw_die_ref
4959 634440531 : AT_ref (dw_attr_node *a)
4960 : {
4961 634440531 : gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4962 634440531 : return a->dw_attr_val.v.val_die_ref.die;
4963 : }
4964 :
4965 : static inline int
4966 383370237 : AT_ref_external (dw_attr_node *a)
4967 : {
4968 383370237 : if (a && AT_class (a) == dw_val_class_die_ref)
4969 383370237 : return a->dw_attr_val.v.val_die_ref.external;
4970 :
4971 : return 0;
4972 : }
4973 :
4974 : static inline void
4975 29659 : set_AT_ref_external (dw_attr_node *a, int i)
4976 : {
4977 29659 : gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4978 29659 : a->dw_attr_val.v.val_die_ref.external = i;
4979 29659 : }
4980 :
4981 : /* Add a location description attribute value to a DIE. */
4982 :
4983 : static inline void
4984 8363081 : add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4985 : {
4986 8363081 : dw_attr_node attr;
4987 :
4988 8363081 : attr.dw_attr = attr_kind;
4989 8363081 : attr.dw_attr_val.val_class = dw_val_class_loc;
4990 8363081 : attr.dw_attr_val.val_entry = NULL;
4991 8363081 : attr.dw_attr_val.v.val_loc = loc;
4992 8363081 : add_dwarf_attr (die, &attr);
4993 4360614 : }
4994 :
4995 : dw_loc_descr_ref
4996 30353494 : AT_loc (dw_attr_node *a)
4997 : {
4998 30353494 : gcc_assert (a && AT_class (a) == dw_val_class_loc);
4999 30353494 : return a->dw_attr_val.v.val_loc;
5000 : }
5001 :
5002 : static inline void
5003 11819942 : add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5004 : {
5005 11819942 : dw_attr_node attr;
5006 :
5007 11819942 : if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
5008 : return;
5009 :
5010 11819942 : attr.dw_attr = attr_kind;
5011 11819942 : attr.dw_attr_val.val_class = dw_val_class_loc_list;
5012 11819942 : attr.dw_attr_val.val_entry = NULL;
5013 11819942 : attr.dw_attr_val.v.val_loc_list = loc_list;
5014 11819942 : add_dwarf_attr (die, &attr);
5015 11819942 : have_location_lists = true;
5016 : }
5017 :
5018 : static inline dw_loc_list_ref
5019 33945725 : AT_loc_list (dw_attr_node *a)
5020 : {
5021 33945725 : gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5022 33945725 : return a->dw_attr_val.v.val_loc_list;
5023 : }
5024 :
5025 : /* Add a view list attribute to DIE. It must have a DW_AT_location
5026 : attribute, because the view list complements the location list. */
5027 :
5028 : static inline void
5029 11643741 : add_AT_view_list (dw_die_ref die, enum dwarf_attribute attr_kind)
5030 : {
5031 11643741 : dw_attr_node attr;
5032 :
5033 11643741 : if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
5034 : return;
5035 :
5036 11643741 : attr.dw_attr = attr_kind;
5037 11643741 : attr.dw_attr_val.val_class = dw_val_class_view_list;
5038 11643741 : attr.dw_attr_val.val_entry = NULL;
5039 11643741 : attr.dw_attr_val.v.val_view_list = die;
5040 11643741 : add_dwarf_attr (die, &attr);
5041 11643741 : gcc_checking_assert (get_AT (die, DW_AT_location));
5042 11643741 : gcc_assert (have_location_lists);
5043 : }
5044 :
5045 : /* Return a pointer to the location list referenced by the attribute.
5046 : If the named attribute is a view list, look up the corresponding
5047 : DW_AT_location attribute and return its location list. */
5048 :
5049 : static inline dw_loc_list_ref *
5050 22958979 : AT_loc_list_ptr (dw_attr_node *a)
5051 : {
5052 34098001 : gcc_assert (a);
5053 34098001 : switch (AT_class (a))
5054 : {
5055 22958979 : case dw_val_class_loc_list:
5056 22958979 : return &a->dw_attr_val.v.val_loc_list;
5057 11139022 : case dw_val_class_view_list:
5058 11139022 : {
5059 11139022 : dw_attr_node *l;
5060 11139022 : l = get_AT (a->dw_attr_val.v.val_view_list, DW_AT_location);
5061 11139022 : if (!l)
5062 : return NULL;
5063 11139022 : gcc_checking_assert (l + 1 == a);
5064 : return AT_loc_list_ptr (l);
5065 : }
5066 0 : default:
5067 0 : gcc_unreachable ();
5068 : }
5069 : }
5070 :
5071 : /* Return the location attribute value associated with a view list
5072 : attribute value. */
5073 :
5074 : static inline dw_val_node *
5075 11643777 : view_list_to_loc_list_val_node (dw_val_node *val)
5076 : {
5077 11643777 : gcc_assert (val->val_class == dw_val_class_view_list);
5078 11643777 : dw_attr_node *loc = get_AT (val->v.val_view_list, DW_AT_location);
5079 11643777 : if (!loc)
5080 : return NULL;
5081 11139058 : gcc_checking_assert (&(loc + 1)->dw_attr_val == val);
5082 11139058 : gcc_assert (AT_class (loc) == dw_val_class_loc_list);
5083 11139058 : return &loc->dw_attr_val;
5084 : }
5085 :
5086 : struct addr_hasher : ggc_ptr_hash<addr_table_entry>
5087 : {
5088 : static hashval_t hash (addr_table_entry *);
5089 : static bool equal (addr_table_entry *, addr_table_entry *);
5090 : };
5091 :
5092 : /* Table of entries into the .debug_addr section. */
5093 :
5094 : static GTY (()) hash_table<addr_hasher> *addr_index_table;
5095 :
5096 : /* Hash an address_table_entry. */
5097 :
5098 : hashval_t
5099 342 : addr_hasher::hash (addr_table_entry *a)
5100 : {
5101 342 : inchash::hash hstate;
5102 342 : switch (a->kind)
5103 : {
5104 21 : case ate_kind_rtx:
5105 21 : hstate.add_int (0);
5106 21 : break;
5107 0 : case ate_kind_rtx_dtprel:
5108 0 : hstate.add_int (1);
5109 0 : break;
5110 321 : case ate_kind_label:
5111 321 : return htab_hash_string (a->addr.label);
5112 0 : default:
5113 0 : gcc_unreachable ();
5114 : }
5115 21 : inchash::add_rtx (a->addr.rtl, hstate);
5116 21 : return hstate.end ();
5117 : }
5118 :
5119 : /* Determine equality for two address_table_entries. */
5120 :
5121 : bool
5122 77 : addr_hasher::equal (addr_table_entry *a1, addr_table_entry *a2)
5123 : {
5124 77 : if (a1->kind != a2->kind)
5125 : return false;
5126 47 : switch (a1->kind)
5127 : {
5128 3 : case ate_kind_rtx:
5129 3 : case ate_kind_rtx_dtprel:
5130 3 : return rtx_equal_p (a1->addr.rtl, a2->addr.rtl);
5131 44 : case ate_kind_label:
5132 44 : return strcmp (a1->addr.label, a2->addr.label) == 0;
5133 0 : default:
5134 0 : gcc_unreachable ();
5135 : }
5136 : }
5137 :
5138 : /* Initialize an addr_table_entry. */
5139 :
5140 : void
5141 535 : init_addr_table_entry (addr_table_entry *e, enum ate_kind kind, void *addr)
5142 : {
5143 535 : e->kind = kind;
5144 535 : switch (kind)
5145 : {
5146 9 : case ate_kind_rtx:
5147 9 : case ate_kind_rtx_dtprel:
5148 9 : e->addr.rtl = (rtx) addr;
5149 9 : break;
5150 526 : case ate_kind_label:
5151 526 : e->addr.label = (char *) addr;
5152 526 : break;
5153 : }
5154 535 : e->refcount = 0;
5155 535 : e->index = NO_INDEX_ASSIGNED;
5156 535 : }
5157 :
5158 : /* Add attr to the address table entry to the table. Defer setting an
5159 : index until output time. */
5160 :
5161 : static addr_table_entry *
5162 271 : add_addr_table_entry (void *addr, enum ate_kind kind)
5163 : {
5164 271 : addr_table_entry *node;
5165 271 : addr_table_entry finder;
5166 :
5167 271 : gcc_assert (dwarf_split_debug_info);
5168 271 : if (! addr_index_table)
5169 244 : addr_index_table = hash_table<addr_hasher>::create_ggc (10);
5170 271 : init_addr_table_entry (&finder, kind, addr);
5171 271 : addr_table_entry **slot = addr_index_table->find_slot (&finder, INSERT);
5172 :
5173 271 : if (*slot == HTAB_EMPTY_ENTRY)
5174 : {
5175 264 : node = ggc_cleared_alloc<addr_table_entry> ();
5176 264 : init_addr_table_entry (node, kind, addr);
5177 264 : *slot = node;
5178 : }
5179 : else
5180 : node = *slot;
5181 :
5182 271 : node->refcount++;
5183 271 : return node;
5184 : }
5185 :
5186 : /* Remove an entry from the addr table by decrementing its refcount.
5187 : Strictly, decrementing the refcount would be enough, but the
5188 : assertion that the entry is actually in the table has found
5189 : bugs. */
5190 :
5191 : static void
5192 3 : remove_addr_table_entry (addr_table_entry *entry)
5193 : {
5194 3 : gcc_assert (dwarf_split_debug_info && addr_index_table);
5195 : /* After an index is assigned, the table is frozen. */
5196 3 : gcc_assert (entry->refcount > 0 && entry->index == NO_INDEX_ASSIGNED);
5197 3 : entry->refcount--;
5198 3 : }
5199 :
5200 : /* Given a location list, remove all addresses it refers to from the
5201 : address_table. */
5202 :
5203 : static void
5204 426 : remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
5205 : {
5206 3383 : for (; descr; descr = descr->dw_loc_next)
5207 2957 : if (descr->dw_loc_oprnd1.val_entry != NULL)
5208 : {
5209 0 : gcc_assert (descr->dw_loc_oprnd1.val_entry->index == NO_INDEX_ASSIGNED);
5210 0 : remove_addr_table_entry (descr->dw_loc_oprnd1.val_entry);
5211 : }
5212 426 : }
5213 :
5214 : /* A helper function for dwarf2out_finish called through
5215 : htab_traverse. Assign an addr_table_entry its index. All entries
5216 : must be collected into the table when this function is called,
5217 : because the indexing code relies on htab_traverse to traverse nodes
5218 : in the same order for each run. */
5219 :
5220 : int
5221 264 : index_addr_table_entry (addr_table_entry **h, unsigned int *index)
5222 : {
5223 264 : addr_table_entry *node = *h;
5224 :
5225 : /* Don't index unreferenced nodes. */
5226 264 : if (node->refcount == 0)
5227 : return 1;
5228 :
5229 264 : gcc_assert (node->index == NO_INDEX_ASSIGNED);
5230 264 : node->index = *index;
5231 264 : *index += 1;
5232 :
5233 264 : return 1;
5234 : }
5235 :
5236 : /* Return the tag of a given DIE. */
5237 :
5238 : enum dwarf_tag
5239 6215 : dw_get_die_tag (dw_die_ref die)
5240 : {
5241 6215 : return die->die_tag;
5242 : }
5243 :
5244 : /* Return a reference to the children list of a given DIE. */
5245 :
5246 : dw_die_ref
5247 1813 : dw_get_die_child (dw_die_ref die)
5248 : {
5249 1813 : return die->die_child;
5250 : }
5251 :
5252 : /* Return a reference to the sibling of a given DIE. */
5253 :
5254 : dw_die_ref
5255 1112 : dw_get_die_sib (dw_die_ref die)
5256 : {
5257 1112 : return die->die_sib;
5258 : }
5259 :
5260 : /* Add an address constant attribute value to a DIE. When using
5261 : dwarf_split_debug_info, address attributes in dies destined for the
5262 : final executable should be direct references--setting the parameter
5263 : force_direct ensures this behavior. */
5264 :
5265 : static inline void
5266 1503884 : add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
5267 : bool force_direct)
5268 : {
5269 1503884 : dw_attr_node attr;
5270 :
5271 1503884 : attr.dw_attr = attr_kind;
5272 1503884 : attr.dw_attr_val.val_class = dw_val_class_addr;
5273 1503884 : attr.dw_attr_val.v.val_addr = addr;
5274 1503884 : if (dwarf_split_debug_info && !force_direct)
5275 0 : attr.dw_attr_val.val_entry = add_addr_table_entry (addr, ate_kind_rtx);
5276 : else
5277 1503884 : attr.dw_attr_val.val_entry = NULL;
5278 1503884 : add_dwarf_attr (die, &attr);
5279 1503884 : }
5280 :
5281 : /* Get the RTX from to an address DIE attribute. */
5282 :
5283 : static inline rtx
5284 28582 : AT_addr (dw_attr_node *a)
5285 : {
5286 28582 : gcc_assert (a && AT_class (a) == dw_val_class_addr);
5287 28582 : return a->dw_attr_val.v.val_addr;
5288 : }
5289 :
5290 : /* Add a file attribute value to a DIE. */
5291 :
5292 : static inline void
5293 263348571 : add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5294 : struct dwarf_file_data *fd)
5295 : {
5296 263348571 : dw_attr_node attr;
5297 :
5298 263348571 : attr.dw_attr = attr_kind;
5299 263348571 : attr.dw_attr_val.val_class = dw_val_class_file;
5300 263348571 : attr.dw_attr_val.val_entry = NULL;
5301 263348571 : attr.dw_attr_val.v.val_file = fd;
5302 263348571 : add_dwarf_attr (die, &attr);
5303 51221 : }
5304 :
5305 : /* Get the dwarf_file_data from a file DIE attribute. */
5306 :
5307 : static inline struct dwarf_file_data *
5308 30746404 : AT_file (dw_attr_node *a)
5309 : {
5310 30746404 : gcc_assert (a && (AT_class (a) == dw_val_class_file
5311 : || AT_class (a) == dw_val_class_file_implicit));
5312 30746404 : return a->dw_attr_val.v.val_file;
5313 : }
5314 :
5315 : #if VMS_DEBUGGING_INFO
5316 : /* Add a vms delta attribute value to a DIE. */
5317 :
5318 : static inline void
5319 : add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
5320 : const char *lbl1, const char *lbl2)
5321 : {
5322 : dw_attr_node attr;
5323 :
5324 : attr.dw_attr = attr_kind;
5325 : attr.dw_attr_val.val_class = dw_val_class_vms_delta;
5326 : attr.dw_attr_val.val_entry = NULL;
5327 : attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
5328 : attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
5329 : add_dwarf_attr (die, &attr);
5330 : }
5331 : #endif
5332 :
5333 : /* Add a symbolic view identifier attribute value to a DIE. */
5334 :
5335 : static inline void
5336 6211432 : add_AT_symview (dw_die_ref die, enum dwarf_attribute attr_kind,
5337 : const char *view_label)
5338 : {
5339 6211432 : dw_attr_node attr;
5340 :
5341 6211432 : attr.dw_attr = attr_kind;
5342 6211432 : attr.dw_attr_val.val_class = dw_val_class_symview;
5343 6211432 : attr.dw_attr_val.val_entry = NULL;
5344 6211432 : attr.dw_attr_val.v.val_symbolic_view = xstrdup (view_label);
5345 6211432 : add_dwarf_attr (die, &attr);
5346 6211432 : }
5347 :
5348 : /* Add a label identifier attribute value to a DIE. */
5349 :
5350 : static inline void
5351 9109802 : add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
5352 : const char *lbl_id, int offset)
5353 : {
5354 9109802 : dw_attr_node attr;
5355 :
5356 9109802 : attr.dw_attr = attr_kind;
5357 9109802 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5358 9109802 : attr.dw_attr_val.val_entry = NULL;
5359 9109802 : if (!offset)
5360 9109802 : attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5361 : else
5362 0 : attr.dw_attr_val.v.val_lbl_id = xasprintf ("%s%+i", lbl_id, offset);
5363 9109802 : if (dwarf_split_debug_info)
5364 11 : attr.dw_attr_val.val_entry
5365 11 : = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id,
5366 : ate_kind_label);
5367 9109802 : add_dwarf_attr (die, &attr);
5368 9109802 : }
5369 :
5370 : /* Add a section offset attribute value to a DIE, an offset into the
5371 : debug_line section. */
5372 :
5373 : static inline void
5374 53732 : add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5375 : const char *label)
5376 : {
5377 53732 : dw_attr_node attr;
5378 :
5379 53732 : attr.dw_attr = attr_kind;
5380 53732 : attr.dw_attr_val.val_class = dw_val_class_lineptr;
5381 53732 : attr.dw_attr_val.val_entry = NULL;
5382 53732 : attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5383 53732 : add_dwarf_attr (die, &attr);
5384 53732 : }
5385 :
5386 : /* Add a section offset attribute value to a DIE, an offset into the
5387 : debug_macinfo section. */
5388 :
5389 : static inline void
5390 527 : add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5391 : const char *label)
5392 : {
5393 527 : dw_attr_node attr;
5394 :
5395 527 : attr.dw_attr = attr_kind;
5396 527 : attr.dw_attr_val.val_class = dw_val_class_macptr;
5397 527 : attr.dw_attr_val.val_entry = NULL;
5398 527 : attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5399 527 : add_dwarf_attr (die, &attr);
5400 527 : }
5401 :
5402 : /* Add a range_list attribute value to a DIE. When using
5403 : dwarf_split_debug_info, address attributes in dies destined for the
5404 : final executable should be direct references--setting the parameter
5405 : force_direct ensures this behavior. */
5406 :
5407 : #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
5408 : #define RELOCATED_OFFSET (NULL)
5409 :
5410 : static void
5411 3212559 : add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5412 : long unsigned int offset, bool force_direct)
5413 : {
5414 3212559 : dw_attr_node attr;
5415 :
5416 3212559 : attr.dw_attr = attr_kind;
5417 3212559 : attr.dw_attr_val.val_class = dw_val_class_range_list;
5418 : /* For the range_list attribute, use val_entry to store whether the
5419 : offset should follow split-debug-info or normal semantics. This
5420 : value is read in output_range_list_offset. */
5421 3212559 : if (dwarf_split_debug_info && !force_direct)
5422 3 : attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
5423 : else
5424 3212556 : attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
5425 3212559 : attr.dw_attr_val.v.val_offset = offset;
5426 3212559 : add_dwarf_attr (die, &attr);
5427 3212559 : }
5428 :
5429 : /* Return the start label of a delta attribute. */
5430 :
5431 : static inline const char *
5432 0 : AT_vms_delta1 (dw_attr_node *a)
5433 : {
5434 0 : gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5435 0 : return a->dw_attr_val.v.val_vms_delta.lbl1;
5436 : }
5437 :
5438 : /* Return the end label of a delta attribute. */
5439 :
5440 : static inline const char *
5441 0 : AT_vms_delta2 (dw_attr_node *a)
5442 : {
5443 0 : gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5444 0 : return a->dw_attr_val.v.val_vms_delta.lbl2;
5445 : }
5446 :
5447 : static inline const char *
5448 22395621 : AT_lbl (dw_attr_node *a)
5449 : {
5450 22395621 : gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5451 : || AT_class (a) == dw_val_class_lineptr
5452 : || AT_class (a) == dw_val_class_macptr
5453 : || AT_class (a) == dw_val_class_loclistsptr
5454 : || AT_class (a) == dw_val_class_high_pc));
5455 22395621 : return a->dw_attr_val.v.val_lbl_id;
5456 : }
5457 :
5458 : /* Get the attribute of type attr_kind. */
5459 :
5460 : dw_attr_node *
5461 1106041226 : get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5462 : {
5463 1253609229 : dw_attr_node *a;
5464 1253609229 : unsigned ix;
5465 1253609229 : dw_die_ref spec = NULL;
5466 :
5467 1253609229 : if (! die)
5468 : return NULL;
5469 :
5470 4842862705 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5471 4502957139 : if (a->dw_attr == attr_kind)
5472 : return a;
5473 3589253476 : else if (a->dw_attr == DW_AT_specification
5474 3466981910 : || a->dw_attr == DW_AT_abstract_origin)
5475 186965917 : spec = AT_ref (a);
5476 :
5477 339905566 : if (spec)
5478 : return get_AT (spec, attr_kind);
5479 :
5480 : return NULL;
5481 : }
5482 :
5483 : /* Returns the parent of the declaration of DIE. */
5484 :
5485 : dw_die_ref
5486 81 : dw_get_die_parent (dw_die_ref die)
5487 : {
5488 81 : dw_die_ref t;
5489 :
5490 81 : if (!die)
5491 : return NULL;
5492 :
5493 81 : if ((t = get_AT_ref (die, DW_AT_abstract_origin))
5494 81 : || (t = get_AT_ref (die, DW_AT_specification)))
5495 : die = t;
5496 :
5497 81 : return die->die_parent;
5498 : }
5499 :
5500 : /* Return the "low pc" attribute value, typically associated with a subprogram
5501 : DIE. Return null if the "low pc" attribute is either not present, or if it
5502 : cannot be represented as an assembler label identifier. */
5503 :
5504 : static inline const char *
5505 4407151 : get_AT_low_pc (dw_die_ref die)
5506 : {
5507 4407151 : dw_attr_node *a = get_AT (die, DW_AT_low_pc);
5508 :
5509 4407151 : return a ? AT_lbl (a) : NULL;
5510 : }
5511 :
5512 : /* Return the value of the string attribute designated by ATTR_KIND, or
5513 : NULL if it is not present. */
5514 :
5515 : const char *
5516 57283 : get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5517 : {
5518 57283 : dw_attr_node *a = get_AT (die, attr_kind);
5519 :
5520 57283 : return a ? AT_string (a) : NULL;
5521 : }
5522 :
5523 : /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5524 : if it is not present. */
5525 :
5526 : int
5527 78117660 : get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5528 : {
5529 78117660 : dw_attr_node *a = get_AT (die, attr_kind);
5530 :
5531 78117660 : return a ? AT_flag (a) : 0;
5532 : }
5533 :
5534 : /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5535 : if it is not present. */
5536 :
5537 : unsigned
5538 454748360 : get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5539 : {
5540 454748360 : dw_attr_node *a = get_AT (die, attr_kind);
5541 :
5542 454748360 : return a ? AT_unsigned (a) : 0;
5543 : }
5544 :
5545 : dw_die_ref
5546 48539494 : get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5547 : {
5548 48539494 : dw_attr_node *a = get_AT (die, attr_kind);
5549 :
5550 48539494 : return a ? AT_ref (a) : NULL;
5551 : }
5552 :
5553 : struct dwarf_file_data *
5554 30608724 : get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5555 : {
5556 30608724 : dw_attr_node *a = get_AT (die, attr_kind);
5557 :
5558 30608724 : return a ? AT_file (a) : NULL;
5559 : }
5560 :
5561 : /* Return TRUE if the language is C. */
5562 :
5563 : static inline bool
5564 6519 : is_c (void)
5565 : {
5566 6519 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5567 :
5568 6519 : return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_C99
5569 6519 : || lang == DW_LANG_C11 || lang == DW_LANG_ObjC);
5570 :
5571 :
5572 : }
5573 :
5574 : /* Return TRUE if the language is C++. */
5575 :
5576 : static inline bool
5577 25000203 : is_cxx (void)
5578 : {
5579 25000203 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5580 :
5581 25000203 : return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
5582 25000203 : || lang == DW_LANG_C_plus_plus_11 || lang == DW_LANG_C_plus_plus_14);
5583 : }
5584 :
5585 : /* Return TRUE if DECL was created by the C++ frontend. */
5586 :
5587 : static bool
5588 23560976 : is_cxx (const_tree decl)
5589 : {
5590 23560976 : if (in_lto_p)
5591 : {
5592 16 : const_tree context = get_ultimate_context (decl);
5593 32 : if (context && TRANSLATION_UNIT_LANGUAGE (context))
5594 16 : return startswith (TRANSLATION_UNIT_LANGUAGE (context), "GNU C++");
5595 : }
5596 23560960 : return is_cxx ();
5597 : }
5598 :
5599 : /* Return TRUE if the language is Fortran. */
5600 :
5601 : static inline bool
5602 183165389 : is_fortran (void)
5603 : {
5604 183165389 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5605 :
5606 183165389 : return (lang == DW_LANG_Fortran77
5607 183165389 : || lang == DW_LANG_Fortran90
5608 183165389 : || lang == DW_LANG_Fortran95
5609 : || lang == DW_LANG_Fortran03
5610 183165389 : || lang == DW_LANG_Fortran08);
5611 : }
5612 :
5613 : static inline bool
5614 109 : is_fortran (const_tree decl)
5615 : {
5616 109 : if (in_lto_p)
5617 : {
5618 109 : const_tree context = get_ultimate_context (decl);
5619 218 : if (context && TRANSLATION_UNIT_LANGUAGE (context))
5620 109 : return (strncmp (TRANSLATION_UNIT_LANGUAGE (context),
5621 : "GNU Fortran", 11) == 0
5622 109 : || strcmp (TRANSLATION_UNIT_LANGUAGE (context),
5623 : "GNU F77") == 0);
5624 : }
5625 0 : return is_fortran ();
5626 : }
5627 :
5628 : /* Return TRUE if the language is Rust.
5629 : Note, returns FALSE for dwarf_version < 5 && dwarf_strict. */
5630 :
5631 : static inline bool
5632 78131 : is_rust (void)
5633 : {
5634 78131 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5635 :
5636 78131 : return lang == DW_LANG_Rust;
5637 : }
5638 :
5639 : /* Return TRUE if the language is Ada. */
5640 :
5641 : static inline bool
5642 2856493 : is_ada (void)
5643 : {
5644 2856493 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5645 :
5646 2856493 : return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5647 : }
5648 :
5649 : /* Return TRUE if the language is D. */
5650 :
5651 : static inline bool
5652 84201133 : is_dlang (void)
5653 : {
5654 84201133 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5655 :
5656 84201133 : return lang == DW_LANG_D;
5657 : }
5658 :
5659 : /* Remove the specified attribute if present. Return TRUE if removal
5660 : was successful. */
5661 :
5662 : static bool
5663 52682629 : remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5664 : {
5665 52682629 : dw_attr_node *a;
5666 52682629 : unsigned ix;
5667 :
5668 52682629 : if (! die)
5669 : return false;
5670 :
5671 111866912 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5672 111365871 : if (a->dw_attr == attr_kind)
5673 : {
5674 52181588 : if (AT_class (a) == dw_val_class_str)
5675 249 : if (a->dw_attr_val.v.val_str->refcount)
5676 249 : a->dw_attr_val.v.val_str->refcount--;
5677 :
5678 : /* vec::ordered_remove should help reduce the number of abbrevs
5679 : that are needed. */
5680 52181588 : die->die_attr->ordered_remove (ix);
5681 52181588 : return true;
5682 : }
5683 : return false;
5684 : }
5685 :
5686 : /* Remove CHILD from its parent. PREV must have the property that
5687 : PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5688 :
5689 : static void
5690 7611233 : remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5691 : {
5692 7611233 : gcc_assert (child->die_parent == prev->die_parent);
5693 7611233 : gcc_assert (prev->die_sib == child);
5694 7611233 : if (prev == child)
5695 : {
5696 17883 : gcc_assert (child->die_parent->die_child == child);
5697 : prev = NULL;
5698 : }
5699 : else
5700 7593350 : prev->die_sib = child->die_sib;
5701 7611233 : if (child->die_parent->die_child == child)
5702 361616 : child->die_parent->die_child = prev;
5703 7611233 : child->die_sib = NULL;
5704 7611233 : }
5705 :
5706 : /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5707 : PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5708 :
5709 : static void
5710 139 : replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
5711 : {
5712 139 : dw_die_ref parent = old_child->die_parent;
5713 :
5714 139 : gcc_assert (parent == prev->die_parent);
5715 139 : gcc_assert (prev->die_sib == old_child);
5716 :
5717 139 : new_child->die_parent = parent;
5718 139 : if (prev == old_child)
5719 : {
5720 19 : gcc_assert (parent->die_child == old_child);
5721 19 : new_child->die_sib = new_child;
5722 : }
5723 : else
5724 : {
5725 120 : prev->die_sib = new_child;
5726 120 : new_child->die_sib = old_child->die_sib;
5727 : }
5728 139 : if (old_child->die_parent->die_child == old_child)
5729 25 : old_child->die_parent->die_child = new_child;
5730 139 : old_child->die_sib = NULL;
5731 139 : }
5732 :
5733 : /* Move all children from OLD_PARENT to NEW_PARENT. */
5734 :
5735 : static void
5736 76 : move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
5737 : {
5738 76 : dw_die_ref c;
5739 76 : new_parent->die_child = old_parent->die_child;
5740 76 : old_parent->die_child = NULL;
5741 85 : FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
5742 0 : }
5743 :
5744 : /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5745 : matches TAG. */
5746 :
5747 : static void
5748 44205 : remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5749 : {
5750 44205 : dw_die_ref c;
5751 :
5752 44205 : c = die->die_child;
5753 44205 : if (c) do {
5754 72672 : dw_die_ref prev = c;
5755 72672 : c = c->die_sib;
5756 134297 : while (c->die_tag == tag)
5757 : {
5758 79507 : remove_child_with_prev (c, prev);
5759 79507 : c->die_parent = NULL;
5760 : /* Might have removed every child. */
5761 79507 : if (die->die_child == NULL)
5762 : return;
5763 61625 : c = prev->die_sib;
5764 : }
5765 54790 : } while (c != die->die_child);
5766 : }
5767 :
5768 : /* Add a CHILD_DIE as the last child of DIE. */
5769 :
5770 : static void
5771 646296525 : add_child_die (dw_die_ref die, dw_die_ref child_die)
5772 : {
5773 : /* FIXME this should probably be an assert. */
5774 646296525 : if (! die || ! child_die)
5775 : return;
5776 646012595 : gcc_assert (die != child_die);
5777 :
5778 646012595 : child_die->die_parent = die;
5779 646012595 : if (die->die_child)
5780 : {
5781 487684632 : child_die->die_sib = die->die_child->die_sib;
5782 487684632 : die->die_child->die_sib = child_die;
5783 : }
5784 : else
5785 158327963 : child_die->die_sib = child_die;
5786 646012595 : die->die_child = child_die;
5787 : }
5788 :
5789 : /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5790 :
5791 : static void
5792 12801279 : add_child_die_after (dw_die_ref die, dw_die_ref child_die,
5793 : dw_die_ref after_die)
5794 : {
5795 12801279 : gcc_assert (die
5796 : && child_die
5797 : && after_die
5798 : && die->die_child
5799 : && die != child_die);
5800 :
5801 12801279 : child_die->die_parent = die;
5802 12801279 : child_die->die_sib = after_die->die_sib;
5803 12801279 : after_die->die_sib = child_die;
5804 12801279 : if (die->die_child == after_die)
5805 7726610 : die->die_child = child_die;
5806 12801279 : }
5807 :
5808 : /* Unassociate CHILD from its parent, and make its parent be
5809 : NEW_PARENT. */
5810 :
5811 : static void
5812 7525121 : reparent_child (dw_die_ref child, dw_die_ref new_parent)
5813 : {
5814 7525121 : for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
5815 6488976906 : if (p->die_sib == child)
5816 : {
5817 7525121 : remove_child_with_prev (child, p);
5818 7525121 : break;
5819 : }
5820 7525121 : add_child_die (new_parent, child);
5821 7525121 : }
5822 :
5823 : /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5824 : is the specification, to the end of PARENT's list of children.
5825 : This is done by removing and re-adding it. */
5826 :
5827 : static void
5828 17792 : splice_child_die (dw_die_ref parent, dw_die_ref child)
5829 : {
5830 : /* We want the declaration DIE from inside the class, not the
5831 : specification DIE at toplevel. */
5832 17792 : if (child->die_parent != parent)
5833 : {
5834 517 : dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5835 :
5836 517 : if (tmp)
5837 17792 : child = tmp;
5838 : }
5839 :
5840 17792 : gcc_assert (child->die_parent == parent
5841 : || (child->die_parent
5842 : == get_AT_ref (parent, DW_AT_specification)));
5843 :
5844 17792 : reparent_child (child, parent);
5845 17792 : }
5846 :
5847 : /* Create and return a new die with TAG_VALUE as tag. */
5848 :
5849 : dw_die_ref
5850 651376692 : new_die_raw (enum dwarf_tag tag_value)
5851 : {
5852 651376692 : dw_die_ref die = ggc_cleared_alloc<die_node> ();
5853 651376692 : die->die_tag = tag_value;
5854 651376692 : return die;
5855 : }
5856 :
5857 : /* Create and return a new die with a parent of PARENT_DIE. If
5858 : PARENT_DIE is NULL, the new DIE is placed in limbo and an
5859 : associated tree T must be supplied to determine parenthood
5860 : later. */
5861 :
5862 : static inline dw_die_ref
5863 637960180 : new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5864 : {
5865 637960180 : dw_die_ref die = new_die_raw (tag_value);
5866 :
5867 637960180 : if (parent_die != NULL)
5868 637603384 : add_child_die (parent_die, die);
5869 : else
5870 : {
5871 356796 : limbo_die_node *limbo_node;
5872 :
5873 : /* No DIEs created after early dwarf should end up in limbo,
5874 : because the limbo list should not persist past LTO
5875 : streaming. */
5876 356796 : if (tag_value != DW_TAG_compile_unit
5877 : /* These are allowed because they're generated while
5878 : breaking out COMDAT units late. */
5879 356796 : && tag_value != DW_TAG_type_unit
5880 299544 : && tag_value != DW_TAG_skeleton_unit
5881 299544 : && !early_dwarf
5882 : /* Allow nested functions to live in limbo because they will
5883 : only temporarily live there, as decls_for_scope will fix
5884 : them up. */
5885 3028 : && (TREE_CODE (t) != FUNCTION_DECL
5886 0 : || !decl_function_context (t))
5887 : /* Same as nested functions above but for types. Types that
5888 : are local to a function will be fixed in
5889 : decls_for_scope. */
5890 3028 : && (!RECORD_OR_UNION_TYPE_P (t)
5891 2 : || !TYPE_CONTEXT (t)
5892 2 : || TREE_CODE (TYPE_CONTEXT (t)) != FUNCTION_DECL)
5893 : /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5894 : especially in the ltrans stage, but once we implement LTO
5895 : dwarf streaming, we should remove this exception. */
5896 359822 : && !in_lto_p)
5897 : {
5898 0 : fprintf (stderr, "symbol ended up in limbo too late:");
5899 0 : debug_generic_stmt (t);
5900 0 : gcc_unreachable ();
5901 : }
5902 :
5903 356796 : limbo_node = ggc_cleared_alloc<limbo_die_node> ();
5904 356796 : limbo_node->die = die;
5905 356796 : limbo_node->created_for = t;
5906 356796 : limbo_node->next = limbo_die_list;
5907 356796 : limbo_die_list = limbo_node;
5908 : }
5909 :
5910 637960180 : return die;
5911 : }
5912 :
5913 : /* Return the DIE associated with the given type specifier. */
5914 :
5915 : dw_die_ref
5916 1771743117 : lookup_type_die (tree type)
5917 : {
5918 1771743117 : dw_die_ref die = TYPE_SYMTAB_DIE (type);
5919 1771743117 : if (die && die->removed)
5920 : {
5921 2055 : TYPE_SYMTAB_DIE (type) = NULL;
5922 2055 : TREE_ASM_WRITTEN (type) = 0;
5923 2055 : return NULL;
5924 : }
5925 : return die;
5926 : }
5927 :
5928 : /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5929 : anonymous type named by the typedef TYPE_DIE, return the DIE of the
5930 : anonymous type instead the one of the naming typedef. */
5931 :
5932 : static inline dw_die_ref
5933 20695825 : strip_naming_typedef (tree type, dw_die_ref type_die)
5934 : {
5935 20695825 : if (type
5936 20695825 : && TREE_CODE (type) == RECORD_TYPE
5937 20548230 : && type_die
5938 20548230 : && type_die->die_tag == DW_TAG_typedef
5939 20695843 : && is_naming_typedef_decl (TYPE_NAME (type)))
5940 18 : type_die = get_AT_ref (type_die, DW_AT_type);
5941 20695825 : return type_die;
5942 : }
5943 :
5944 : /* Like lookup_type_die, but if type is an anonymous type named by a
5945 : typedef[1], return the DIE of the anonymous type instead the one of
5946 : the naming typedef. This is because in gen_typedef_die, we did
5947 : equate the anonymous struct named by the typedef with the DIE of
5948 : the naming typedef. So by default, lookup_type_die on an anonymous
5949 : struct yields the DIE of the naming typedef.
5950 :
5951 : [1]: Read the comment of is_naming_typedef_decl to learn about what
5952 : a naming typedef is. */
5953 :
5954 : static inline dw_die_ref
5955 107950 : lookup_type_die_strip_naming_typedef (tree type)
5956 : {
5957 107950 : dw_die_ref die = lookup_type_die (type);
5958 107950 : return strip_naming_typedef (type, die);
5959 : }
5960 :
5961 : /* Equate a DIE to a given type specifier. */
5962 :
5963 : static inline void
5964 153999776 : equate_type_number_to_die (tree type, dw_die_ref type_die)
5965 : {
5966 153999776 : TYPE_SYMTAB_DIE (type) = type_die;
5967 153999776 : }
5968 :
5969 : static dw_die_ref maybe_create_die_with_external_ref (tree);
5970 : struct GTY(()) sym_off_pair
5971 : {
5972 : const char *sym;
5973 : unsigned HOST_WIDE_INT off;
5974 : };
5975 : static GTY(()) hash_map<tree, sym_off_pair> *external_die_map;
5976 :
5977 : /* Returns a hash value for X (which really is a die_struct). */
5978 :
5979 : inline hashval_t
5980 11651409098 : decl_die_hasher::hash (die_node *x)
5981 : {
5982 11651409098 : return (hashval_t) x->decl_id;
5983 : }
5984 :
5985 : /* Return true if decl_id of die_struct X is the same as UID of decl *Y. */
5986 :
5987 : inline bool
5988 13544684136 : decl_die_hasher::equal (die_node *x, tree y)
5989 : {
5990 13544684136 : return (x->decl_id == DECL_UID (y));
5991 : }
5992 :
5993 : /* Return the DIE associated with a given declaration. */
5994 :
5995 : dw_die_ref
5996 1458569201 : lookup_decl_die (tree decl)
5997 : {
5998 1458569201 : dw_die_ref *die = decl_die_table->find_slot_with_hash (decl, DECL_UID (decl),
5999 : NO_INSERT);
6000 1458569201 : if (!die)
6001 : {
6002 674364426 : if (in_lto_p)
6003 38887 : return maybe_create_die_with_external_ref (decl);
6004 : return NULL;
6005 : }
6006 784204775 : if ((*die)->removed)
6007 : {
6008 401 : decl_die_table->clear_slot (die);
6009 401 : return NULL;
6010 : }
6011 : return *die;
6012 : }
6013 :
6014 :
6015 : /* Return the DIE associated with BLOCK. */
6016 :
6017 : static inline dw_die_ref
6018 18221358 : lookup_block_die (tree block)
6019 : {
6020 18221358 : dw_die_ref die = BLOCK_DIE (block);
6021 18221358 : if (!die && in_lto_p)
6022 9420 : return maybe_create_die_with_external_ref (block);
6023 : return die;
6024 : }
6025 :
6026 : /* Associate DIE with BLOCK. */
6027 :
6028 : static inline void
6029 7177110 : equate_block_to_die (tree block, dw_die_ref die)
6030 : {
6031 7177110 : BLOCK_DIE (block) = die;
6032 7177110 : }
6033 : #undef BLOCK_DIE
6034 :
6035 :
6036 : /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
6037 : style reference. Return true if we found one referring to a DIE for
6038 : DECL, otherwise return false. */
6039 :
6040 : static bool
6041 139552 : dwarf2out_die_ref_for_decl (tree decl, const char **sym,
6042 : unsigned HOST_WIDE_INT *off)
6043 : {
6044 139552 : dw_die_ref die;
6045 :
6046 139552 : if (in_lto_p)
6047 : {
6048 : /* During WPA stage and incremental linking we use a hash-map
6049 : to store the decl <-> label + offset map. */
6050 27587 : if (!external_die_map)
6051 : return false;
6052 26270 : sym_off_pair *desc = external_die_map->get (decl);
6053 26270 : if (!desc)
6054 : return false;
6055 11212 : *sym = desc->sym;
6056 11212 : *off = desc->off;
6057 11212 : return true;
6058 : }
6059 :
6060 111965 : if (TREE_CODE (decl) == BLOCK)
6061 27053 : die = lookup_block_die (decl);
6062 : else
6063 84912 : die = lookup_decl_die (decl);
6064 111965 : if (!die)
6065 : return false;
6066 :
6067 : /* Similar to get_ref_die_offset_label, but using the "correct"
6068 : label. */
6069 37891 : *off = die->die_offset;
6070 99857 : while (die->die_parent)
6071 : die = die->die_parent;
6072 : /* For the containing CU DIE we compute a die_symbol in
6073 : compute_comp_unit_symbol. */
6074 37891 : if (die->die_tag == DW_TAG_compile_unit)
6075 : {
6076 37888 : gcc_assert (die->die_id.die_symbol != NULL);
6077 37888 : *sym = die->die_id.die_symbol;
6078 37888 : return true;
6079 : }
6080 : /* While we can gracefully handle running into say a type unit
6081 : we don't really want and consider this a bug. */
6082 3 : if (flag_checking)
6083 0 : gcc_unreachable ();
6084 : return false;
6085 : }
6086 :
6087 : /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
6088 :
6089 : static void
6090 29311 : add_AT_external_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind,
6091 : const char *symbol, HOST_WIDE_INT offset)
6092 : {
6093 : /* Create a fake DIE that contains the reference. Don't use
6094 : new_die because we don't want to end up in the limbo list. */
6095 : /* ??? We probably want to share these, thus put a ref to the DIE
6096 : we create here to the external_die_map entry. */
6097 29311 : dw_die_ref ref = new_die_raw (die->die_tag);
6098 29311 : ref->die_id.die_symbol = symbol;
6099 29311 : ref->die_offset = offset;
6100 29311 : ref->with_offset = 1;
6101 29311 : add_AT_die_ref (die, attr_kind, ref);
6102 29311 : }
6103 :
6104 : /* Create a DIE for DECL if required and add a reference to a DIE
6105 : at SYMBOL + OFFSET which contains attributes dumped early. */
6106 :
6107 : static void
6108 44152 : dwarf2out_register_external_die (tree decl, const char *sym,
6109 : unsigned HOST_WIDE_INT off)
6110 : {
6111 44152 : if (debug_info_level == DINFO_LEVEL_NONE)
6112 0 : return;
6113 :
6114 44152 : if (!external_die_map)
6115 1272 : external_die_map = hash_map<tree, sym_off_pair>::create_ggc (1000);
6116 44152 : gcc_checking_assert (!external_die_map->get (decl));
6117 44152 : sym_off_pair p = { IDENTIFIER_POINTER (get_identifier (sym)), off };
6118 44152 : external_die_map->put (decl, p);
6119 : }
6120 :
6121 : /* If we have a registered external DIE for DECL return a new DIE for
6122 : the concrete instance with an appropriate abstract origin. */
6123 :
6124 : static dw_die_ref
6125 48307 : maybe_create_die_with_external_ref (tree decl)
6126 : {
6127 48307 : if (!external_die_map)
6128 : return NULL;
6129 48149 : sym_off_pair *desc = external_die_map->get (decl);
6130 48149 : if (!desc)
6131 : return NULL;
6132 :
6133 20434 : const char *sym = desc->sym;
6134 20434 : unsigned HOST_WIDE_INT off = desc->off;
6135 20434 : external_die_map->remove (decl);
6136 :
6137 20434 : in_lto_p = false;
6138 20434 : dw_die_ref die = (TREE_CODE (decl) == BLOCK
6139 20434 : ? lookup_block_die (decl) : lookup_decl_die (decl));
6140 20434 : gcc_assert (!die);
6141 20434 : in_lto_p = true;
6142 :
6143 20434 : tree ctx;
6144 20434 : dw_die_ref parent = NULL;
6145 : /* Need to lookup a DIE for the decls context - the containing
6146 : function or translation unit. */
6147 20434 : if (TREE_CODE (decl) == BLOCK)
6148 : {
6149 428 : ctx = BLOCK_SUPERCONTEXT (decl);
6150 : /* ??? We do not output DIEs for all scopes thus skip as
6151 : many DIEs as needed. */
6152 428 : while (TREE_CODE (ctx) == BLOCK
6153 1099 : && !lookup_block_die (ctx))
6154 671 : ctx = BLOCK_SUPERCONTEXT (ctx);
6155 : }
6156 : else
6157 20006 : ctx = DECL_CONTEXT (decl);
6158 : /* Peel types in the context stack. */
6159 20962 : while (ctx && TYPE_P (ctx))
6160 528 : ctx = TYPE_CONTEXT (ctx);
6161 : /* Likewise namespaces in case we do not want to emit DIEs for them. */
6162 20434 : if (debug_info_level <= DINFO_LEVEL_TERSE)
6163 998 : while (ctx && TREE_CODE (ctx) == NAMESPACE_DECL)
6164 5 : ctx = DECL_CONTEXT (ctx);
6165 20434 : if (ctx)
6166 : {
6167 20293 : if (TREE_CODE (ctx) == BLOCK)
6168 60 : parent = lookup_block_die (ctx);
6169 20233 : else if (TREE_CODE (ctx) == TRANSLATION_UNIT_DECL
6170 : /* Keep the 1:1 association during WPA. */
6171 3762 : && !flag_wpa
6172 3762 : && flag_incremental_link != INCREMENTAL_LINK_LTO)
6173 : /* Otherwise all late annotations go to the main CU which
6174 : imports the original CUs. */
6175 3762 : parent = comp_unit_die ();
6176 16471 : else if (TREE_CODE (ctx) == FUNCTION_DECL
6177 12212 : && TREE_CODE (decl) != FUNCTION_DECL
6178 : && TREE_CODE (decl) != PARM_DECL
6179 : && TREE_CODE (decl) != RESULT_DECL
6180 : && TREE_CODE (decl) != BLOCK)
6181 : /* Leave function local entities parent determination to when
6182 : we process scope vars. */
6183 : ;
6184 : else
6185 13445 : parent = lookup_decl_die (ctx);
6186 : }
6187 : else
6188 : /* In some cases the FEs fail to set DECL_CONTEXT properly.
6189 : Handle this case gracefully by globalizing stuff. */
6190 141 : parent = comp_unit_die ();
6191 : /* Create a DIE "stub". */
6192 20434 : switch (TREE_CODE (decl))
6193 : {
6194 141 : case TRANSLATION_UNIT_DECL:
6195 141 : {
6196 141 : die = comp_unit_die ();
6197 : /* We re-target all CU decls to the LTRANS CU DIE, so no need
6198 : to create a DIE for the original CUs. */
6199 141 : return die;
6200 : }
6201 109 : case NAMESPACE_DECL:
6202 109 : if (is_fortran (decl))
6203 6 : die = new_die (DW_TAG_module, parent, decl);
6204 : else
6205 103 : die = new_die (DW_TAG_namespace, parent, decl);
6206 : break;
6207 7241 : case FUNCTION_DECL:
6208 7241 : die = new_die (DW_TAG_subprogram, parent, decl);
6209 7241 : break;
6210 3730 : case VAR_DECL:
6211 3730 : die = new_die (DW_TAG_variable, parent, decl);
6212 3730 : break;
6213 0 : case RESULT_DECL:
6214 0 : die = new_die (DW_TAG_variable, parent, decl);
6215 0 : break;
6216 8777 : case PARM_DECL:
6217 8777 : die = new_die (DW_TAG_formal_parameter, parent, decl);
6218 8777 : break;
6219 0 : case CONST_DECL:
6220 0 : die = new_die (DW_TAG_constant, parent, decl);
6221 0 : break;
6222 8 : case LABEL_DECL:
6223 8 : die = new_die (DW_TAG_label, parent, decl);
6224 8 : break;
6225 428 : case BLOCK:
6226 428 : die = new_die (DW_TAG_lexical_block, parent, decl);
6227 428 : break;
6228 0 : default:
6229 0 : gcc_unreachable ();
6230 : }
6231 20293 : if (TREE_CODE (decl) == BLOCK)
6232 428 : equate_block_to_die (decl, die);
6233 : else
6234 19865 : equate_decl_number_to_die (decl, die);
6235 :
6236 20293 : add_desc_attribute (die, decl);
6237 :
6238 : /* Add a reference to the DIE providing early debug at $sym + off. */
6239 20293 : add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
6240 :
6241 20293 : return die;
6242 : }
6243 :
6244 : /* Returns a hash value for X (which really is a var_loc_list). */
6245 :
6246 : inline hashval_t
6247 373548390 : decl_loc_hasher::hash (var_loc_list *x)
6248 : {
6249 373548390 : return (hashval_t) x->decl_id;
6250 : }
6251 :
6252 : /* Return true if decl_id of var_loc_list X is the same as
6253 : UID of decl *Y. */
6254 :
6255 : inline bool
6256 452573410 : decl_loc_hasher::equal (var_loc_list *x, const_tree y)
6257 : {
6258 452573410 : return (x->decl_id == DECL_UID (y));
6259 : }
6260 :
6261 : /* Return the var_loc list associated with a given declaration. */
6262 :
6263 : static inline var_loc_list *
6264 31386469 : lookup_decl_loc (const_tree decl)
6265 : {
6266 31386469 : if (!decl_loc_table)
6267 : return NULL;
6268 31386469 : return decl_loc_table->find_with_hash (decl, DECL_UID (decl));
6269 : }
6270 :
6271 : /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
6272 :
6273 : inline hashval_t
6274 0 : dw_loc_list_hasher::hash (cached_dw_loc_list *x)
6275 : {
6276 0 : return (hashval_t) x->decl_id;
6277 : }
6278 :
6279 : /* Return true if decl_id of cached_dw_loc_list X is the same as
6280 : UID of decl *Y. */
6281 :
6282 : inline bool
6283 0 : dw_loc_list_hasher::equal (cached_dw_loc_list *x, const_tree y)
6284 : {
6285 0 : return (x->decl_id == DECL_UID (y));
6286 : }
6287 :
6288 : /* Equate a DIE to a particular declaration. */
6289 :
6290 : static void
6291 209194495 : equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6292 : {
6293 209194495 : unsigned int decl_id = DECL_UID (decl);
6294 :
6295 209194495 : *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
6296 209194495 : decl_die->decl_id = decl_id;
6297 209194495 : }
6298 :
6299 : /* Return how many bits covers PIECE EXPR_LIST. */
6300 :
6301 : static HOST_WIDE_INT
6302 32150027 : decl_piece_bitsize (rtx piece)
6303 : {
6304 32150027 : int ret = (int) GET_MODE (piece);
6305 32150027 : if (ret)
6306 31900218 : return ret;
6307 249809 : gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
6308 : && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
6309 249809 : return INTVAL (XEXP (XEXP (piece, 0), 0));
6310 : }
6311 :
6312 : /* Return pointer to the location of location note in PIECE EXPR_LIST. */
6313 :
6314 : static rtx *
6315 16829789 : decl_piece_varloc_ptr (rtx piece)
6316 : {
6317 0 : if ((int) GET_MODE (piece))
6318 16716208 : return &XEXP (piece, 0);
6319 : else
6320 113581 : return &XEXP (XEXP (piece, 0), 1);
6321 : }
6322 :
6323 : /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
6324 : Next is the chain of following piece nodes. */
6325 :
6326 : static rtx_expr_list *
6327 7732390 : decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
6328 : {
6329 7732390 : if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
6330 7659217 : return alloc_EXPR_LIST (bitsize, loc_note, next);
6331 : else
6332 73173 : return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
6333 : GEN_INT (bitsize),
6334 73173 : loc_note), next);
6335 : }
6336 :
6337 : /* Return rtx that should be stored into loc field for
6338 : LOC_NOTE and BITPOS/BITSIZE. */
6339 :
6340 : static rtx
6341 47401998 : construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
6342 : HOST_WIDE_INT bitsize)
6343 : {
6344 47401998 : if (bitsize != -1)
6345 : {
6346 582623 : loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
6347 582623 : if (bitpos != 0)
6348 87624 : loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
6349 : }
6350 47401998 : return loc_note;
6351 : }
6352 :
6353 : /* This function either modifies location piece list *DEST in
6354 : place (if SRC and INNER is NULL), or copies location piece list
6355 : *SRC to *DEST while modifying it. Location BITPOS is modified
6356 : to contain LOC_NOTE, any pieces overlapping it are removed resp.
6357 : not copied and if needed some padding around it is added.
6358 : When modifying in place, DEST should point to EXPR_LIST where
6359 : earlier pieces cover PIECE_BITPOS bits, when copying SRC points
6360 : to the start of the whole list and INNER points to the EXPR_LIST
6361 : where earlier pieces cover PIECE_BITPOS bits. */
6362 :
6363 : static void
6364 6022245 : adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
6365 : HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
6366 : HOST_WIDE_INT bitsize, rtx loc_note)
6367 : {
6368 6022245 : HOST_WIDE_INT diff;
6369 6022245 : bool copy = inner != NULL;
6370 :
6371 6022245 : if (copy)
6372 : {
6373 : /* First copy all nodes preceding the current bitpos. */
6374 4350523 : while (src != inner)
6375 : {
6376 2640014 : *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
6377 : decl_piece_bitsize (*src), NULL_RTX);
6378 1320007 : dest = &XEXP (*dest, 1);
6379 1320007 : src = &XEXP (*src, 1);
6380 : }
6381 : }
6382 : /* Add padding if needed. */
6383 6022245 : if (bitpos != piece_bitpos)
6384 : {
6385 18546 : *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
6386 : copy ? NULL_RTX : *dest);
6387 18546 : dest = &XEXP (*dest, 1);
6388 : }
6389 6003699 : else if (*dest && decl_piece_bitsize (*dest) == bitsize)
6390 : {
6391 2655635 : gcc_assert (!copy);
6392 : /* A piece with correct bitpos and bitsize already exist,
6393 : just update the location for it and return. */
6394 2655635 : *decl_piece_varloc_ptr (*dest) = loc_note;
6395 2655635 : return;
6396 : }
6397 : /* Add the piece that changed. */
6398 3366610 : *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
6399 3366610 : dest = &XEXP (*dest, 1);
6400 : /* Skip over pieces that overlap it. */
6401 3366610 : diff = bitpos - piece_bitpos + bitsize;
6402 3366610 : if (!copy)
6403 336094 : src = dest;
6404 6378179 : while (diff > 0 && *src)
6405 : {
6406 3011569 : rtx piece = *src;
6407 3011569 : diff -= decl_piece_bitsize (piece);
6408 3011569 : if (copy)
6409 3002023 : src = &XEXP (piece, 1);
6410 : else
6411 : {
6412 9546 : *src = XEXP (piece, 1);
6413 9546 : free_EXPR_LIST_node (piece);
6414 : }
6415 : }
6416 : /* Add padding if needed. */
6417 3366610 : if (diff < 0 && *src)
6418 : {
6419 7872 : if (!copy)
6420 5376 : dest = src;
6421 7872 : *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
6422 7872 : dest = &XEXP (*dest, 1);
6423 : }
6424 3366610 : if (!copy)
6425 : return;
6426 : /* Finally copy all nodes following it. */
6427 5379624 : while (*src)
6428 : {
6429 4698216 : *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
6430 : decl_piece_bitsize (*src), NULL_RTX);
6431 2349108 : dest = &XEXP (*dest, 1);
6432 2349108 : src = &XEXP (*src, 1);
6433 : }
6434 : }
6435 :
6436 : /* Add a variable location node to the linked list for DECL. */
6437 :
6438 : static struct var_loc_node *
6439 58749014 : add_var_loc_to_decl (tree decl, rtx loc_note, const char *label, var_loc_view view)
6440 : {
6441 58749014 : unsigned int decl_id;
6442 58749014 : var_loc_list *temp;
6443 58749014 : struct var_loc_node *loc = NULL;
6444 58749014 : HOST_WIDE_INT bitsize = -1, bitpos = -1;
6445 :
6446 58749014 : if (VAR_P (decl) && DECL_HAS_DEBUG_EXPR_P (decl))
6447 : {
6448 7503284 : tree realdecl = DECL_DEBUG_EXPR (decl);
6449 7503284 : if (handled_component_p (realdecl)
6450 845486 : || (TREE_CODE (realdecl) == MEM_REF
6451 845486 : && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
6452 : {
6453 7503284 : bool reverse;
6454 7503284 : tree innerdecl = get_ref_base_and_extent_hwi (realdecl, &bitpos,
6455 : &bitsize, &reverse);
6456 7503284 : if (!innerdecl
6457 7503284 : || !DECL_P (innerdecl)
6458 7503284 : || DECL_IGNORED_P (innerdecl)
6459 7503284 : || TREE_STATIC (innerdecl)
6460 7503284 : || bitsize == 0
6461 15006568 : || bitpos + bitsize > 256)
6462 0 : return NULL;
6463 7503284 : decl = innerdecl;
6464 : }
6465 : }
6466 :
6467 58749014 : decl_id = DECL_UID (decl);
6468 58749014 : var_loc_list **slot
6469 58749014 : = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
6470 58749014 : if (*slot == NULL)
6471 : {
6472 13474016 : temp = ggc_cleared_alloc<var_loc_list> ();
6473 13474016 : temp->decl_id = decl_id;
6474 13474016 : *slot = temp;
6475 : }
6476 : else
6477 : temp = *slot;
6478 :
6479 : /* For PARM_DECLs try to keep around the original incoming value,
6480 : even if that means we'll emit a zero-range .debug_loc entry. */
6481 58749014 : if (temp->last
6482 45274998 : && temp->first == temp->last
6483 21206548 : && TREE_CODE (decl) == PARM_DECL
6484 1017497 : && NOTE_P (temp->first->loc)
6485 979384 : && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
6486 979384 : && DECL_INCOMING_RTL (decl)
6487 979384 : && NOTE_VAR_LOCATION_LOC (temp->first->loc)
6488 978200 : && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
6489 978200 : == GET_CODE (DECL_INCOMING_RTL (decl))
6490 978154 : && prev_real_insn (as_a<rtx_insn *> (temp->first->loc)) == NULL_RTX
6491 59727160 : && (bitsize != -1
6492 978021 : || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
6493 978021 : NOTE_VAR_LOCATION_LOC (loc_note))
6494 407212 : || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
6495 407212 : != NOTE_VAR_LOCATION_STATUS (loc_note))))
6496 : {
6497 571568 : loc = ggc_cleared_alloc<var_loc_node> ();
6498 571568 : temp->first->next = loc;
6499 571568 : temp->last = loc;
6500 571568 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6501 : }
6502 58177446 : else if (temp->last)
6503 : {
6504 44703430 : struct var_loc_node *last = temp->last, *unused = NULL;
6505 44703430 : rtx *piece_loc = NULL, last_loc_note;
6506 44703430 : HOST_WIDE_INT piece_bitpos = 0;
6507 44703430 : if (last->next)
6508 : {
6509 29362988 : last = last->next;
6510 29362988 : gcc_assert (last->next == NULL);
6511 : }
6512 44703430 : if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
6513 : {
6514 6920661 : piece_loc = &last->loc;
6515 12300804 : do
6516 : {
6517 12300804 : HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
6518 12300804 : if (piece_bitpos + cur_bitsize > bitpos)
6519 : break;
6520 5735610 : piece_bitpos += cur_bitsize;
6521 5735610 : piece_loc = &XEXP (*piece_loc, 1);
6522 : }
6523 5735610 : while (*piece_loc);
6524 : }
6525 : /* TEMP->LAST here is either pointer to the last but one or
6526 : last element in the chained list, LAST is pointer to the
6527 : last element. */
6528 44703430 : if (label && strcmp (last->label, label) == 0 && last->view == view)
6529 : {
6530 : /* For SRA optimized variables if there weren't any real
6531 : insns since last note, just modify the last node. */
6532 4173745 : if (piece_loc != NULL)
6533 : {
6534 2991729 : adjust_piece_list (piece_loc, NULL, NULL,
6535 : bitpos, piece_bitpos, bitsize, loc_note);
6536 2991729 : return NULL;
6537 : }
6538 : /* If the last note doesn't cover any instructions, remove it. */
6539 1182016 : if (temp->last != last)
6540 : {
6541 1073571 : temp->last->next = NULL;
6542 1073571 : unused = last;
6543 1073571 : last = temp->last;
6544 1073571 : gcc_assert (strcmp (last->label, label) != 0 || last->view != view);
6545 : }
6546 : else
6547 : {
6548 108445 : gcc_assert (temp->first == temp->last
6549 : || (temp->first->next == temp->last
6550 : && TREE_CODE (decl) == PARM_DECL));
6551 108445 : memset (temp->last, '\0', sizeof (*temp->last));
6552 108445 : temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
6553 108445 : return temp->last;
6554 : }
6555 : }
6556 41603256 : if (bitsize == -1 && NOTE_P (last->loc))
6557 : last_loc_note = last->loc;
6558 4171387 : else if (piece_loc != NULL
6559 3928932 : && *piece_loc != NULL_RTX
6560 3900209 : && piece_bitpos == bitpos
6561 8070962 : && decl_piece_bitsize (*piece_loc) == bitsize)
6562 3896898 : last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
6563 : else
6564 : last_loc_note = NULL_RTX;
6565 : /* If the current location is the same as the end of the list,
6566 : and either both or neither of the locations is uninitialized,
6567 : we have nothing to do. */
6568 41328767 : if (last_loc_note == NULL_RTX
6569 41318744 : || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
6570 41318744 : NOTE_VAR_LOCATION_LOC (loc_note)))
6571 50867198 : || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6572 9538431 : != NOTE_VAR_LOCATION_STATUS (loc_note))
6573 4213717 : && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6574 : == VAR_INIT_STATUS_UNINITIALIZED)
6575 3399556 : || (NOTE_VAR_LOCATION_STATUS (loc_note)
6576 : == VAR_INIT_STATUS_UNINITIALIZED))))
6577 : {
6578 : /* Add LOC to the end of list and update LAST. If the last
6579 : element of the list has been removed above, reuse its
6580 : memory for the new node, otherwise allocate a new one. */
6581 36278485 : if (unused)
6582 : {
6583 716977 : loc = unused;
6584 716977 : memset (loc, '\0', sizeof (*loc));
6585 : }
6586 : else
6587 35561508 : loc = ggc_cleared_alloc<var_loc_node> ();
6588 36278485 : if (bitsize == -1 || piece_loc == NULL)
6589 33247969 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6590 : else
6591 3030516 : adjust_piece_list (&loc->loc, &last->loc, piece_loc,
6592 : bitpos, piece_bitpos, bitsize, loc_note);
6593 36278485 : last->next = loc;
6594 : /* Ensure TEMP->LAST will point either to the new last but one
6595 : element of the chain, or to the last element in it. */
6596 36278485 : if (last != temp->last)
6597 22469659 : temp->last = last;
6598 : }
6599 5324771 : else if (unused)
6600 356594 : ggc_free (unused);
6601 : }
6602 : else
6603 : {
6604 13474016 : loc = ggc_cleared_alloc<var_loc_node> ();
6605 13474016 : temp->first = loc;
6606 13474016 : temp->last = loc;
6607 13474016 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6608 : }
6609 : return loc;
6610 : }
6611 :
6612 : /* Keep track of the number of spaces used to indent the
6613 : output of the debugging routines that print the structure of
6614 : the DIE internal representation. */
6615 : static int print_indent;
6616 :
6617 : /* Indent the line the number of spaces given by print_indent. */
6618 :
6619 : static inline void
6620 1812 : print_spaces (FILE *outfile)
6621 : {
6622 1812 : fprintf (outfile, "%*s", print_indent, "");
6623 1812 : }
6624 :
6625 : /* Print a type signature in hex. */
6626 :
6627 : static inline void
6628 0 : print_signature (FILE *outfile, char *sig)
6629 : {
6630 0 : int i;
6631 :
6632 0 : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
6633 0 : fprintf (outfile, "%02x", sig[i] & 0xff);
6634 0 : }
6635 :
6636 : static inline void
6637 0 : print_discr_value (FILE *outfile, dw_discr_value *discr_value)
6638 : {
6639 0 : if (discr_value->pos)
6640 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, discr_value->v.sval);
6641 : else
6642 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, discr_value->v.uval);
6643 0 : }
6644 :
6645 : static void print_loc_descr (dw_loc_descr_ref, FILE *);
6646 :
6647 : /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6648 : RECURSE, output location descriptor operations. */
6649 :
6650 : static void
6651 1272 : print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
6652 : {
6653 1272 : switch (val->val_class)
6654 : {
6655 12 : case dw_val_class_addr:
6656 12 : fprintf (outfile, "address");
6657 12 : break;
6658 0 : case dw_val_class_offset:
6659 0 : fprintf (outfile, "offset");
6660 0 : break;
6661 28 : case dw_val_class_loc:
6662 28 : fprintf (outfile, "location descriptor");
6663 28 : if (val->v.val_loc == NULL)
6664 0 : fprintf (outfile, " -> <null>");
6665 28 : else if (recurse)
6666 : {
6667 28 : fprintf (outfile, ":\n");
6668 28 : print_indent += 4;
6669 28 : print_loc_descr (val->v.val_loc, outfile);
6670 28 : print_indent -= 4;
6671 : }
6672 : else
6673 : {
6674 0 : if (flag_dump_noaddr || flag_dump_unnumbered)
6675 0 : fprintf (outfile, " #");
6676 : else
6677 0 : fprintf (outfile, " (%p)", (void *) val->v.val_loc);
6678 : }
6679 : break;
6680 36 : case dw_val_class_loc_list:
6681 36 : fprintf (outfile, "location list -> label:%s",
6682 36 : val->v.val_loc_list->ll_symbol);
6683 36 : break;
6684 36 : case dw_val_class_view_list:
6685 36 : val = view_list_to_loc_list_val_node (val);
6686 36 : fprintf (outfile, "location list with views -> labels:%s and %s",
6687 : val->v.val_loc_list->ll_symbol,
6688 36 : val->v.val_loc_list->vl_symbol);
6689 36 : break;
6690 0 : case dw_val_class_range_list:
6691 0 : fprintf (outfile, "range list");
6692 0 : break;
6693 0 : case dw_val_class_const:
6694 0 : case dw_val_class_const_implicit:
6695 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
6696 0 : break;
6697 484 : case dw_val_class_unsigned_const:
6698 484 : case dw_val_class_unsigned_const_implicit:
6699 484 : fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
6700 484 : break;
6701 0 : case dw_val_class_const_double:
6702 0 : fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_DEC","\
6703 : HOST_WIDE_INT_PRINT_UNSIGNED")",
6704 : val->v.val_double.high,
6705 : val->v.val_double.low);
6706 0 : break;
6707 0 : case dw_val_class_wide_int:
6708 0 : {
6709 0 : int i = val->v.val_wide->get_len ();
6710 0 : fprintf (outfile, "constant (");
6711 0 : gcc_assert (i > 0);
6712 0 : if (val->v.val_wide->elt (i - 1) == 0)
6713 0 : fprintf (outfile, "0x");
6714 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
6715 0 : val->v.val_wide->elt (--i));
6716 0 : while (--i >= 0)
6717 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
6718 0 : val->v.val_wide->elt (i));
6719 0 : fprintf (outfile, ")");
6720 0 : break;
6721 : }
6722 0 : case dw_val_class_vec:
6723 0 : fprintf (outfile, "floating-point or vector constant");
6724 0 : break;
6725 88 : case dw_val_class_flag:
6726 88 : fprintf (outfile, "%u", val->v.val_flag);
6727 88 : break;
6728 224 : case dw_val_class_die_ref:
6729 224 : if (val->v.val_die_ref.die != NULL)
6730 : {
6731 224 : dw_die_ref die = val->v.val_die_ref.die;
6732 :
6733 224 : if (die->comdat_type_p)
6734 : {
6735 0 : fprintf (outfile, "die -> signature: ");
6736 0 : print_signature (outfile,
6737 0 : die->die_id.die_type_node->signature);
6738 : }
6739 224 : else if (die->die_id.die_symbol)
6740 : {
6741 0 : fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
6742 0 : if (die->with_offset)
6743 0 : fprintf (outfile, " + %ld", die->die_offset);
6744 : }
6745 : else
6746 224 : fprintf (outfile, "die -> %ld", die->die_offset);
6747 224 : if (flag_dump_noaddr || flag_dump_unnumbered)
6748 224 : fprintf (outfile, " #");
6749 : else
6750 0 : fprintf (outfile, " (%p)", (void *) die);
6751 : }
6752 : else
6753 0 : fprintf (outfile, "die -> <null>");
6754 : break;
6755 0 : case dw_val_class_vms_delta:
6756 0 : fprintf (outfile, "delta: @slotcount(%s-%s)",
6757 : val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
6758 0 : break;
6759 0 : case dw_val_class_symview:
6760 0 : fprintf (outfile, "view: %s", val->v.val_symbolic_view);
6761 0 : break;
6762 20 : case dw_val_class_lbl_id:
6763 20 : case dw_val_class_lineptr:
6764 20 : case dw_val_class_macptr:
6765 20 : case dw_val_class_loclistsptr:
6766 20 : case dw_val_class_high_pc:
6767 20 : fprintf (outfile, "label: %s", val->v.val_lbl_id);
6768 20 : break;
6769 192 : case dw_val_class_str:
6770 192 : if (val->v.val_str->str != NULL)
6771 192 : fprintf (outfile, "\"%s\"", val->v.val_str->str);
6772 : else
6773 0 : fprintf (outfile, "<null>");
6774 : break;
6775 152 : case dw_val_class_file:
6776 152 : case dw_val_class_file_implicit:
6777 152 : fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
6778 152 : val->v.val_file->emitted_number);
6779 152 : break;
6780 : case dw_val_class_data8:
6781 : {
6782 : int i;
6783 :
6784 0 : for (i = 0; i < 8; i++)
6785 0 : fprintf (outfile, "%02x", val->v.val_data8[i]);
6786 : break;
6787 : }
6788 0 : case dw_val_class_discr_value:
6789 0 : print_discr_value (outfile, &val->v.val_discr_value);
6790 0 : break;
6791 0 : case dw_val_class_discr_list:
6792 0 : for (dw_discr_list_ref node = val->v.val_discr_list;
6793 0 : node != NULL;
6794 0 : node = node->dw_discr_next)
6795 : {
6796 0 : if (node->dw_discr_range)
6797 : {
6798 0 : fprintf (outfile, " .. ");
6799 0 : print_discr_value (outfile, &node->dw_discr_lower_bound);
6800 0 : print_discr_value (outfile, &node->dw_discr_upper_bound);
6801 : }
6802 : else
6803 0 : print_discr_value (outfile, &node->dw_discr_lower_bound);
6804 :
6805 0 : if (node->dw_discr_next != NULL)
6806 0 : fprintf (outfile, " | ");
6807 : }
6808 : default:
6809 : break;
6810 : }
6811 1272 : }
6812 :
6813 : /* Likewise, for a DIE attribute. */
6814 :
6815 : static void
6816 1216 : print_attribute (dw_attr_node *a, bool recurse, FILE *outfile)
6817 : {
6818 0 : print_dw_val (&a->dw_attr_val, recurse, outfile);
6819 0 : }
6820 :
6821 :
6822 : /* Print the list of operands in the LOC location description to OUTFILE. This
6823 : routine is a debugging aid only. */
6824 :
6825 : static void
6826 28 : print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
6827 : {
6828 28 : dw_loc_descr_ref l = loc;
6829 :
6830 28 : if (loc == NULL)
6831 : {
6832 0 : print_spaces (outfile);
6833 0 : fprintf (outfile, "<null>\n");
6834 0 : return;
6835 : }
6836 :
6837 56 : for (l = loc; l != NULL; l = l->dw_loc_next)
6838 : {
6839 28 : print_spaces (outfile);
6840 28 : if (flag_dump_noaddr || flag_dump_unnumbered)
6841 28 : fprintf (outfile, "#");
6842 : else
6843 0 : fprintf (outfile, "(%p)", (void *) l);
6844 28 : fprintf (outfile, " %s",
6845 28 : dwarf_stack_op_name (l->dw_loc_opc));
6846 28 : if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
6847 : {
6848 28 : fprintf (outfile, " ");
6849 28 : print_dw_val (&l->dw_loc_oprnd1, false, outfile);
6850 : }
6851 28 : if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
6852 : {
6853 28 : fprintf (outfile, ", ");
6854 28 : print_dw_val (&l->dw_loc_oprnd2, false, outfile);
6855 : }
6856 28 : fprintf (outfile, "\n");
6857 : }
6858 : }
6859 :
6860 : /* Print the information associated with a given DIE, and its children.
6861 : This routine is a debugging aid only. */
6862 :
6863 : static void
6864 284 : print_die (dw_die_ref die, FILE *outfile)
6865 : {
6866 284 : dw_attr_node *a;
6867 284 : dw_die_ref c;
6868 284 : unsigned ix;
6869 :
6870 284 : print_spaces (outfile);
6871 284 : fprintf (outfile, "DIE %4ld: %s ",
6872 284 : die->die_offset, dwarf_tag_name (die->die_tag));
6873 284 : if (flag_dump_noaddr || flag_dump_unnumbered)
6874 284 : fprintf (outfile, "#\n");
6875 : else
6876 0 : fprintf (outfile, "(%p)\n", (void*) die);
6877 284 : print_spaces (outfile);
6878 284 : fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6879 284 : fprintf (outfile, " offset: %ld", die->die_offset);
6880 284 : fprintf (outfile, " mark: %d\n", die->die_mark);
6881 :
6882 284 : if (die->comdat_type_p)
6883 : {
6884 0 : print_spaces (outfile);
6885 0 : fprintf (outfile, " signature: ");
6886 0 : print_signature (outfile, die->die_id.die_type_node->signature);
6887 0 : fprintf (outfile, "\n");
6888 : }
6889 :
6890 1500 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6891 : {
6892 1216 : print_spaces (outfile);
6893 1216 : fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6894 :
6895 1216 : print_attribute (a, true, outfile);
6896 1216 : fprintf (outfile, "\n");
6897 : }
6898 :
6899 284 : if (die->die_child != NULL)
6900 : {
6901 52 : print_indent += 4;
6902 276 : FOR_EACH_CHILD (die, c, print_die (c, outfile));
6903 52 : print_indent -= 4;
6904 : }
6905 284 : if (print_indent == 0)
6906 8 : fprintf (outfile, "\n");
6907 284 : }
6908 :
6909 : /* Print the list of operations in the LOC location description. */
6910 :
6911 : DEBUG_FUNCTION void
6912 0 : debug_dwarf_loc_descr (dw_loc_descr_ref loc)
6913 : {
6914 0 : print_loc_descr (loc, stderr);
6915 0 : }
6916 :
6917 : /* Print the information collected for a given DIE. */
6918 :
6919 : DEBUG_FUNCTION void
6920 0 : debug_dwarf_die (dw_die_ref die)
6921 : {
6922 0 : print_die (die, stderr);
6923 0 : }
6924 :
6925 : DEBUG_FUNCTION void
6926 0 : debug (die_struct &ref)
6927 : {
6928 0 : print_die (&ref, stderr);
6929 0 : }
6930 :
6931 : DEBUG_FUNCTION void
6932 0 : debug (die_struct *ptr)
6933 : {
6934 0 : if (ptr)
6935 0 : debug (*ptr);
6936 : else
6937 0 : fprintf (stderr, "<nil>\n");
6938 0 : }
6939 :
6940 :
6941 : /* Print all DWARF information collected for the compilation unit.
6942 : This routine is a debugging aid only. */
6943 :
6944 : DEBUG_FUNCTION void
6945 0 : debug_dwarf (void)
6946 : {
6947 0 : print_indent = 0;
6948 0 : print_die (comp_unit_die (), stderr);
6949 0 : }
6950 :
6951 : /* Verify the DIE tree structure. */
6952 :
6953 : DEBUG_FUNCTION void
6954 52079 : verify_die (dw_die_ref die)
6955 : {
6956 52079 : gcc_assert (!die->die_mark);
6957 52079 : if (die->die_parent == NULL
6958 52079 : && die->die_sib == NULL)
6959 : return;
6960 : /* Verify the die_sib list is cyclic. */
6961 : dw_die_ref x = die;
6962 0 : do
6963 : {
6964 0 : x->die_mark = 1;
6965 0 : x = x->die_sib;
6966 : }
6967 0 : while (x && !x->die_mark);
6968 0 : gcc_assert (x == die);
6969 : x = die;
6970 0 : do
6971 : {
6972 : /* Verify all dies have the same parent. */
6973 0 : gcc_assert (x->die_parent == die->die_parent);
6974 0 : if (x->die_child)
6975 : {
6976 : /* Verify the child has the proper parent and recurse. */
6977 0 : gcc_assert (x->die_child->die_parent == x);
6978 0 : verify_die (x->die_child);
6979 : }
6980 0 : x->die_mark = 0;
6981 0 : x = x->die_sib;
6982 : }
6983 0 : while (x && x->die_mark);
6984 : }
6985 :
6986 : /* Sanity checks on DIEs. */
6987 :
6988 : static void
6989 742185006 : check_die (dw_die_ref die)
6990 : {
6991 742185006 : unsigned ix;
6992 742185006 : dw_attr_node *a;
6993 742185006 : bool inline_found = false;
6994 742185006 : int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0;
6995 742185006 : int n_decl_line = 0, n_decl_column = 0, n_decl_file = 0;
6996 3545373581 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6997 : {
6998 2803188575 : switch (a->dw_attr)
6999 : {
7000 7687381 : case DW_AT_inline:
7001 7687381 : if (a->dw_attr_val.v.val_unsigned)
7002 2803188575 : inline_found = true;
7003 : break;
7004 178 : case DW_AT_location:
7005 178 : ++n_location;
7006 178 : break;
7007 490836 : case DW_AT_low_pc:
7008 490836 : ++n_low_pc;
7009 490836 : break;
7010 490836 : case DW_AT_high_pc:
7011 490836 : ++n_high_pc;
7012 490836 : break;
7013 120976 : case DW_AT_artificial:
7014 120976 : ++n_artificial;
7015 120976 : break;
7016 409944927 : case DW_AT_decl_column:
7017 409944927 : ++n_decl_column;
7018 409944927 : break;
7019 410490917 : case DW_AT_decl_line:
7020 410490917 : ++n_decl_line;
7021 410490917 : break;
7022 410358644 : case DW_AT_decl_file:
7023 410358644 : ++n_decl_file;
7024 410358644 : break;
7025 : default:
7026 : break;
7027 : }
7028 : }
7029 742185006 : if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1
7030 742185006 : || n_decl_column > 1 || n_decl_line > 1 || n_decl_file > 1)
7031 : {
7032 0 : fprintf (stderr, "Duplicate attributes in DIE:\n");
7033 0 : debug_dwarf_die (die);
7034 0 : gcc_unreachable ();
7035 : }
7036 742185006 : if (inline_found)
7037 : {
7038 : /* A debugging information entry that is a member of an abstract
7039 : instance tree [that has DW_AT_inline] should not contain any
7040 : attributes which describe aspects of the subroutine which vary
7041 : between distinct inlined expansions or distinct out-of-line
7042 : expansions. */
7043 84458556 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7044 76774364 : gcc_assert (a->dw_attr != DW_AT_low_pc
7045 : && a->dw_attr != DW_AT_high_pc
7046 : && a->dw_attr != DW_AT_location
7047 : && a->dw_attr != DW_AT_frame_base
7048 : && a->dw_attr != DW_AT_call_all_calls
7049 : && a->dw_attr != DW_AT_GNU_all_call_sites);
7050 : }
7051 742185006 : }
7052 :
7053 : #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7054 : #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7055 : #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7056 :
7057 : /* Calculate the checksum of a location expression. */
7058 :
7059 : static inline void
7060 610 : loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7061 : {
7062 610 : int tem;
7063 610 : inchash::hash hstate;
7064 610 : hashval_t hash;
7065 :
7066 610 : tem = (loc->dw_loc_dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7067 610 : CHECKSUM (tem);
7068 610 : hash_loc_operands (loc, hstate);
7069 610 : hash = hstate.end();
7070 610 : CHECKSUM (hash);
7071 610 : }
7072 :
7073 : /* Calculate the checksum of an attribute. */
7074 :
7075 : static void
7076 923902 : attr_checksum (dw_attr_node *at, struct md5_ctx *ctx, int *mark)
7077 : {
7078 923902 : dw_loc_descr_ref loc;
7079 923902 : rtx r;
7080 :
7081 923902 : CHECKSUM (at->dw_attr);
7082 :
7083 : /* We don't care that this was compiled with a different compiler
7084 : snapshot; if the output is the same, that's what matters. */
7085 923902 : if (at->dw_attr == DW_AT_producer)
7086 : return;
7087 :
7088 922326 : switch (AT_class (at))
7089 : {
7090 20 : case dw_val_class_const:
7091 20 : case dw_val_class_const_implicit:
7092 20 : CHECKSUM (at->dw_attr_val.v.val_int);
7093 20 : break;
7094 256860 : case dw_val_class_unsigned_const:
7095 256860 : case dw_val_class_unsigned_const_implicit:
7096 256860 : CHECKSUM (at->dw_attr_val.v.val_unsigned);
7097 256860 : break;
7098 0 : case dw_val_class_const_double:
7099 0 : CHECKSUM (at->dw_attr_val.v.val_double);
7100 0 : break;
7101 0 : case dw_val_class_wide_int:
7102 0 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
7103 : get_full_len (*at->dw_attr_val.v.val_wide)
7104 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
7105 0 : break;
7106 7 : case dw_val_class_vec:
7107 7 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
7108 : (at->dw_attr_val.v.val_vec.length
7109 : * at->dw_attr_val.v.val_vec.elt_size));
7110 7 : break;
7111 130431 : case dw_val_class_flag:
7112 130431 : CHECKSUM (at->dw_attr_val.v.val_flag);
7113 130431 : break;
7114 147709 : case dw_val_class_str:
7115 147709 : CHECKSUM_STRING (AT_string (at));
7116 147709 : break;
7117 :
7118 0 : case dw_val_class_addr:
7119 0 : r = AT_addr (at);
7120 0 : gcc_assert (GET_CODE (r) == SYMBOL_REF);
7121 0 : CHECKSUM_STRING (XSTR (r, 0));
7122 0 : break;
7123 :
7124 0 : case dw_val_class_offset:
7125 0 : CHECKSUM (at->dw_attr_val.v.val_offset);
7126 0 : break;
7127 :
7128 490 : case dw_val_class_loc:
7129 1100 : for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7130 610 : loc_checksum (loc, ctx);
7131 : break;
7132 :
7133 294734 : case dw_val_class_die_ref:
7134 294734 : die_checksum (AT_ref (at), ctx, mark);
7135 294734 : break;
7136 :
7137 : case dw_val_class_fde_ref:
7138 : case dw_val_class_vms_delta:
7139 : case dw_val_class_symview:
7140 : case dw_val_class_lbl_id:
7141 : case dw_val_class_lineptr:
7142 : case dw_val_class_macptr:
7143 : case dw_val_class_loclistsptr:
7144 : case dw_val_class_high_pc:
7145 : break;
7146 :
7147 90227 : case dw_val_class_file:
7148 90227 : case dw_val_class_file_implicit:
7149 90227 : CHECKSUM_STRING (AT_file (at)->filename);
7150 90227 : break;
7151 :
7152 0 : case dw_val_class_data8:
7153 0 : CHECKSUM (at->dw_attr_val.v.val_data8);
7154 0 : break;
7155 :
7156 : default:
7157 : break;
7158 : }
7159 : }
7160 :
7161 : /* Calculate the checksum of a DIE. */
7162 :
7163 : static void
7164 530042 : die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7165 : {
7166 530042 : dw_die_ref c;
7167 530042 : dw_attr_node *a;
7168 530042 : unsigned ix;
7169 :
7170 : /* To avoid infinite recursion. */
7171 530042 : if (die->die_mark)
7172 : {
7173 294724 : CHECKSUM (die->die_mark);
7174 294724 : return;
7175 : }
7176 235318 : die->die_mark = ++(*mark);
7177 :
7178 235318 : CHECKSUM (die->die_tag);
7179 :
7180 1394538 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7181 923902 : attr_checksum (a, ctx, mark);
7182 :
7183 408835 : FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7184 : }
7185 :
7186 : #undef CHECKSUM
7187 : #undef CHECKSUM_BLOCK
7188 : #undef CHECKSUM_STRING
7189 :
7190 : /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
7191 : #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7192 : #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7193 : #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
7194 : #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
7195 : #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
7196 : #define CHECKSUM_ATTR(FOO) \
7197 : if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
7198 :
7199 : /* Calculate the checksum of a number in signed LEB128 format. */
7200 :
7201 : static void
7202 310 : checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
7203 : {
7204 318 : unsigned char byte;
7205 318 : bool more;
7206 :
7207 318 : while (1)
7208 : {
7209 318 : byte = (value & 0x7f);
7210 318 : value >>= 7;
7211 318 : more = !((value == 0 && (byte & 0x40) == 0)
7212 0 : || (value == -1 && (byte & 0x40) != 0));
7213 : if (more)
7214 8 : byte |= 0x80;
7215 318 : CHECKSUM (byte);
7216 318 : if (!more)
7217 : break;
7218 : }
7219 310 : }
7220 :
7221 : /* Calculate the checksum of a number in unsigned LEB128 format. */
7222 :
7223 : static void
7224 242213 : checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
7225 : {
7226 252837 : while (1)
7227 : {
7228 247525 : unsigned char byte = (value & 0x7f);
7229 247525 : value >>= 7;
7230 247525 : if (value != 0)
7231 : /* More bytes to follow. */
7232 5312 : byte |= 0x80;
7233 247525 : CHECKSUM (byte);
7234 247525 : if (value == 0)
7235 : break;
7236 5312 : }
7237 242213 : }
7238 :
7239 : /* Checksum the context of the DIE. This adds the names of any
7240 : surrounding namespaces or structures to the checksum. */
7241 :
7242 : static void
7243 330 : checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
7244 : {
7245 330 : const char *name;
7246 330 : dw_die_ref spec;
7247 330 : int tag = die->die_tag;
7248 :
7249 330 : if (tag != DW_TAG_namespace
7250 330 : && tag != DW_TAG_structure_type
7251 249 : && tag != DW_TAG_class_type)
7252 : return;
7253 :
7254 87 : name = get_AT_string (die, DW_AT_name);
7255 :
7256 87 : spec = get_AT_ref (die, DW_AT_specification);
7257 87 : if (spec != NULL)
7258 0 : die = spec;
7259 :
7260 87 : if (die->die_parent != NULL)
7261 87 : checksum_die_context (die->die_parent, ctx);
7262 :
7263 87 : CHECKSUM_ULEB128 ('C');
7264 87 : CHECKSUM_ULEB128 (tag);
7265 87 : if (name != NULL)
7266 72 : CHECKSUM_STRING (name);
7267 : }
7268 :
7269 : /* Calculate the checksum of a location expression. */
7270 :
7271 : static inline void
7272 0 : loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7273 : {
7274 : /* Special case for lone DW_OP_plus_uconst: checksum as if the location
7275 : were emitted as a DW_FORM_sdata instead of a location expression. */
7276 0 : if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
7277 : {
7278 0 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7279 0 : CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
7280 0 : return;
7281 : }
7282 :
7283 : /* Otherwise, just checksum the raw location expression. */
7284 0 : while (loc != NULL)
7285 : {
7286 0 : inchash::hash hstate;
7287 0 : hashval_t hash;
7288 :
7289 0 : CHECKSUM_ULEB128 (loc->dw_loc_dtprel);
7290 0 : CHECKSUM_ULEB128 (loc->dw_loc_opc);
7291 0 : hash_loc_operands (loc, hstate);
7292 0 : hash = hstate.end ();
7293 0 : CHECKSUM (hash);
7294 0 : loc = loc->dw_loc_next;
7295 : }
7296 : }
7297 :
7298 : /* Calculate the checksum of an attribute. */
7299 :
7300 : static void
7301 650 : attr_checksum_ordered (enum dwarf_tag tag, dw_attr_node *at,
7302 : struct md5_ctx *ctx, int *mark)
7303 : {
7304 650 : dw_loc_descr_ref loc;
7305 650 : rtx r;
7306 :
7307 650 : if (AT_class (at) == dw_val_class_die_ref)
7308 : {
7309 112 : dw_die_ref target_die = AT_ref (at);
7310 :
7311 : /* For pointer and reference types, we checksum only the (qualified)
7312 : name of the target type (if there is a name). For friend entries,
7313 : we checksum only the (qualified) name of the target type or function.
7314 : This allows the checksum to remain the same whether the target type
7315 : is complete or not. */
7316 112 : if ((at->dw_attr == DW_AT_type
7317 : && (tag == DW_TAG_pointer_type
7318 106 : || tag == DW_TAG_reference_type
7319 106 : || tag == DW_TAG_rvalue_reference_type
7320 : || tag == DW_TAG_ptr_to_member_type))
7321 101 : || (at->dw_attr == DW_AT_friend
7322 0 : && tag == DW_TAG_friend))
7323 : {
7324 11 : dw_attr_node *name_attr = get_AT (target_die, DW_AT_name);
7325 :
7326 11 : if (name_attr != NULL)
7327 : {
7328 1 : dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
7329 :
7330 1 : if (decl == NULL)
7331 1 : decl = target_die;
7332 1 : CHECKSUM_ULEB128 ('N');
7333 1 : CHECKSUM_ULEB128 (at->dw_attr);
7334 1 : if (decl->die_parent != NULL)
7335 1 : checksum_die_context (decl->die_parent, ctx);
7336 1 : CHECKSUM_ULEB128 ('E');
7337 1 : CHECKSUM_STRING (AT_string (name_attr));
7338 1 : return;
7339 : }
7340 : }
7341 :
7342 : /* For all other references to another DIE, we check to see if the
7343 : target DIE has already been visited. If it has, we emit a
7344 : backward reference; if not, we descend recursively. */
7345 111 : if (target_die->die_mark > 0)
7346 : {
7347 19 : CHECKSUM_ULEB128 ('R');
7348 19 : CHECKSUM_ULEB128 (at->dw_attr);
7349 19 : CHECKSUM_ULEB128 (target_die->die_mark);
7350 : }
7351 : else
7352 : {
7353 92 : dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
7354 :
7355 92 : if (decl == NULL)
7356 89 : decl = target_die;
7357 92 : target_die->die_mark = ++(*mark);
7358 92 : CHECKSUM_ULEB128 ('T');
7359 92 : CHECKSUM_ULEB128 (at->dw_attr);
7360 92 : if (decl->die_parent != NULL)
7361 92 : checksum_die_context (decl->die_parent, ctx);
7362 92 : die_checksum_ordered (target_die, ctx, mark);
7363 : }
7364 111 : return;
7365 : }
7366 :
7367 538 : CHECKSUM_ULEB128 ('A');
7368 538 : CHECKSUM_ULEB128 (at->dw_attr);
7369 :
7370 538 : switch (AT_class (at))
7371 : {
7372 0 : case dw_val_class_const:
7373 0 : case dw_val_class_const_implicit:
7374 0 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7375 0 : CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
7376 0 : break;
7377 :
7378 310 : case dw_val_class_unsigned_const:
7379 310 : case dw_val_class_unsigned_const_implicit:
7380 310 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7381 310 : CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
7382 310 : break;
7383 :
7384 0 : case dw_val_class_const_double:
7385 0 : CHECKSUM_ULEB128 (DW_FORM_block);
7386 0 : CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
7387 0 : CHECKSUM (at->dw_attr_val.v.val_double);
7388 0 : break;
7389 :
7390 0 : case dw_val_class_wide_int:
7391 0 : CHECKSUM_ULEB128 (DW_FORM_block);
7392 0 : CHECKSUM_ULEB128 (get_full_len (*at->dw_attr_val.v.val_wide)
7393 : * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
7394 0 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
7395 : get_full_len (*at->dw_attr_val.v.val_wide)
7396 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
7397 0 : break;
7398 :
7399 0 : case dw_val_class_vec:
7400 0 : CHECKSUM_ULEB128 (DW_FORM_block);
7401 0 : CHECKSUM_ULEB128 (at->dw_attr_val.v.val_vec.length
7402 : * at->dw_attr_val.v.val_vec.elt_size);
7403 0 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
7404 : (at->dw_attr_val.v.val_vec.length
7405 : * at->dw_attr_val.v.val_vec.elt_size));
7406 0 : break;
7407 :
7408 3 : case dw_val_class_flag:
7409 3 : CHECKSUM_ULEB128 (DW_FORM_flag);
7410 3 : CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
7411 3 : break;
7412 :
7413 225 : case dw_val_class_str:
7414 225 : CHECKSUM_ULEB128 (DW_FORM_string);
7415 225 : CHECKSUM_STRING (AT_string (at));
7416 225 : break;
7417 :
7418 0 : case dw_val_class_addr:
7419 0 : r = AT_addr (at);
7420 0 : gcc_assert (GET_CODE (r) == SYMBOL_REF);
7421 0 : CHECKSUM_ULEB128 (DW_FORM_string);
7422 0 : CHECKSUM_STRING (XSTR (r, 0));
7423 0 : break;
7424 :
7425 0 : case dw_val_class_offset:
7426 0 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7427 0 : CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
7428 0 : break;
7429 :
7430 0 : case dw_val_class_loc:
7431 0 : for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7432 0 : loc_checksum_ordered (loc, ctx);
7433 : break;
7434 :
7435 : case dw_val_class_fde_ref:
7436 : case dw_val_class_symview:
7437 : case dw_val_class_lbl_id:
7438 : case dw_val_class_lineptr:
7439 : case dw_val_class_macptr:
7440 : case dw_val_class_loclistsptr:
7441 : case dw_val_class_high_pc:
7442 : break;
7443 :
7444 0 : case dw_val_class_file:
7445 0 : case dw_val_class_file_implicit:
7446 0 : CHECKSUM_ULEB128 (DW_FORM_string);
7447 0 : CHECKSUM_STRING (AT_file (at)->filename);
7448 0 : break;
7449 :
7450 0 : case dw_val_class_data8:
7451 0 : CHECKSUM (at->dw_attr_val.v.val_data8);
7452 0 : break;
7453 :
7454 : default:
7455 : break;
7456 : }
7457 : }
7458 :
7459 : struct checksum_attributes
7460 : {
7461 : dw_attr_node *at_name;
7462 : dw_attr_node *at_type;
7463 : dw_attr_node *at_friend;
7464 : dw_attr_node *at_accessibility;
7465 : dw_attr_node *at_address_class;
7466 : dw_attr_node *at_alignment;
7467 : dw_attr_node *at_allocated;
7468 : dw_attr_node *at_artificial;
7469 : dw_attr_node *at_associated;
7470 : dw_attr_node *at_binary_scale;
7471 : dw_attr_node *at_bit_offset;
7472 : dw_attr_node *at_bit_size;
7473 : dw_attr_node *at_bit_stride;
7474 : dw_attr_node *at_byte_size;
7475 : dw_attr_node *at_byte_stride;
7476 : dw_attr_node *at_const_value;
7477 : dw_attr_node *at_containing_type;
7478 : dw_attr_node *at_count;
7479 : dw_attr_node *at_data_location;
7480 : dw_attr_node *at_data_member_location;
7481 : dw_attr_node *at_decimal_scale;
7482 : dw_attr_node *at_decimal_sign;
7483 : dw_attr_node *at_default_value;
7484 : dw_attr_node *at_digit_count;
7485 : dw_attr_node *at_discr;
7486 : dw_attr_node *at_discr_list;
7487 : dw_attr_node *at_discr_value;
7488 : dw_attr_node *at_encoding;
7489 : dw_attr_node *at_endianity;
7490 : dw_attr_node *at_explicit;
7491 : dw_attr_node *at_is_optional;
7492 : dw_attr_node *at_location;
7493 : dw_attr_node *at_lower_bound;
7494 : dw_attr_node *at_mutable;
7495 : dw_attr_node *at_ordering;
7496 : dw_attr_node *at_picture_string;
7497 : dw_attr_node *at_prototyped;
7498 : dw_attr_node *at_small;
7499 : dw_attr_node *at_segment;
7500 : dw_attr_node *at_string_length;
7501 : dw_attr_node *at_string_length_bit_size;
7502 : dw_attr_node *at_string_length_byte_size;
7503 : dw_attr_node *at_threads_scaled;
7504 : dw_attr_node *at_upper_bound;
7505 : dw_attr_node *at_use_location;
7506 : dw_attr_node *at_use_UTF8;
7507 : dw_attr_node *at_variable_parameter;
7508 : dw_attr_node *at_virtuality;
7509 : dw_attr_node *at_visibility;
7510 : dw_attr_node *at_vtable_elem_location;
7511 : };
7512 :
7513 : /* Collect the attributes that we will want to use for the checksum. */
7514 :
7515 : static void
7516 281 : collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
7517 : {
7518 281 : dw_attr_node *a;
7519 281 : unsigned ix;
7520 :
7521 1341 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7522 : {
7523 1060 : switch (a->dw_attr)
7524 : {
7525 225 : case DW_AT_name:
7526 225 : attrs->at_name = a;
7527 225 : break;
7528 106 : case DW_AT_type:
7529 106 : attrs->at_type = a;
7530 106 : break;
7531 0 : case DW_AT_friend:
7532 0 : attrs->at_friend = a;
7533 0 : break;
7534 15 : case DW_AT_accessibility:
7535 15 : attrs->at_accessibility = a;
7536 15 : break;
7537 0 : case DW_AT_address_class:
7538 0 : attrs->at_address_class = a;
7539 0 : break;
7540 0 : case DW_AT_alignment:
7541 0 : attrs->at_alignment = a;
7542 0 : break;
7543 0 : case DW_AT_allocated:
7544 0 : attrs->at_allocated = a;
7545 0 : break;
7546 3 : case DW_AT_artificial:
7547 3 : attrs->at_artificial = a;
7548 3 : break;
7549 0 : case DW_AT_associated:
7550 0 : attrs->at_associated = a;
7551 0 : break;
7552 0 : case DW_AT_binary_scale:
7553 0 : attrs->at_binary_scale = a;
7554 0 : break;
7555 0 : case DW_AT_bit_offset:
7556 0 : attrs->at_bit_offset = a;
7557 0 : break;
7558 0 : case DW_AT_bit_size:
7559 0 : attrs->at_bit_size = a;
7560 0 : break;
7561 0 : case DW_AT_bit_stride:
7562 0 : attrs->at_bit_stride = a;
7563 0 : break;
7564 152 : case DW_AT_byte_size:
7565 152 : attrs->at_byte_size = a;
7566 152 : break;
7567 0 : case DW_AT_byte_stride:
7568 0 : attrs->at_byte_stride = a;
7569 0 : break;
7570 37 : case DW_AT_const_value:
7571 37 : attrs->at_const_value = a;
7572 37 : break;
7573 6 : case DW_AT_containing_type:
7574 6 : attrs->at_containing_type = a;
7575 6 : break;
7576 0 : case DW_AT_count:
7577 0 : attrs->at_count = a;
7578 0 : break;
7579 0 : case DW_AT_data_location:
7580 0 : attrs->at_data_location = a;
7581 0 : break;
7582 31 : case DW_AT_data_member_location:
7583 31 : attrs->at_data_member_location = a;
7584 31 : break;
7585 0 : case DW_AT_decimal_scale:
7586 0 : attrs->at_decimal_scale = a;
7587 0 : break;
7588 0 : case DW_AT_decimal_sign:
7589 0 : attrs->at_decimal_sign = a;
7590 0 : break;
7591 0 : case DW_AT_default_value:
7592 0 : attrs->at_default_value = a;
7593 0 : break;
7594 0 : case DW_AT_digit_count:
7595 0 : attrs->at_digit_count = a;
7596 0 : break;
7597 0 : case DW_AT_discr:
7598 0 : attrs->at_discr = a;
7599 0 : break;
7600 0 : case DW_AT_discr_list:
7601 0 : attrs->at_discr_list = a;
7602 0 : break;
7603 0 : case DW_AT_discr_value:
7604 0 : attrs->at_discr_value = a;
7605 0 : break;
7606 68 : case DW_AT_encoding:
7607 68 : attrs->at_encoding = a;
7608 68 : break;
7609 2 : case DW_AT_endianity:
7610 2 : attrs->at_endianity = a;
7611 2 : break;
7612 0 : case DW_AT_explicit:
7613 0 : attrs->at_explicit = a;
7614 0 : break;
7615 0 : case DW_AT_is_optional:
7616 0 : attrs->at_is_optional = a;
7617 0 : break;
7618 0 : case DW_AT_location:
7619 0 : attrs->at_location = a;
7620 0 : break;
7621 0 : case DW_AT_lower_bound:
7622 0 : attrs->at_lower_bound = a;
7623 0 : break;
7624 0 : case DW_AT_mutable:
7625 0 : attrs->at_mutable = a;
7626 0 : break;
7627 0 : case DW_AT_ordering:
7628 0 : attrs->at_ordering = a;
7629 0 : break;
7630 0 : case DW_AT_picture_string:
7631 0 : attrs->at_picture_string = a;
7632 0 : break;
7633 0 : case DW_AT_prototyped:
7634 0 : attrs->at_prototyped = a;
7635 0 : break;
7636 0 : case DW_AT_small:
7637 0 : attrs->at_small = a;
7638 0 : break;
7639 0 : case DW_AT_segment:
7640 0 : attrs->at_segment = a;
7641 0 : break;
7642 0 : case DW_AT_string_length:
7643 0 : attrs->at_string_length = a;
7644 0 : break;
7645 0 : case DW_AT_string_length_bit_size:
7646 0 : attrs->at_string_length_bit_size = a;
7647 0 : break;
7648 0 : case DW_AT_string_length_byte_size:
7649 0 : attrs->at_string_length_byte_size = a;
7650 0 : break;
7651 0 : case DW_AT_threads_scaled:
7652 0 : attrs->at_threads_scaled = a;
7653 0 : break;
7654 5 : case DW_AT_upper_bound:
7655 5 : attrs->at_upper_bound = a;
7656 5 : break;
7657 0 : case DW_AT_use_location:
7658 0 : attrs->at_use_location = a;
7659 0 : break;
7660 0 : case DW_AT_use_UTF8:
7661 0 : attrs->at_use_UTF8 = a;
7662 0 : break;
7663 0 : case DW_AT_variable_parameter:
7664 0 : attrs->at_variable_parameter = a;
7665 0 : break;
7666 0 : case DW_AT_virtuality:
7667 0 : attrs->at_virtuality = a;
7668 0 : break;
7669 0 : case DW_AT_visibility:
7670 0 : attrs->at_visibility = a;
7671 0 : break;
7672 0 : case DW_AT_vtable_elem_location:
7673 0 : attrs->at_vtable_elem_location = a;
7674 0 : break;
7675 : default:
7676 : break;
7677 : }
7678 : }
7679 281 : }
7680 :
7681 : /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7682 :
7683 : static void
7684 278 : die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7685 : {
7686 278 : dw_die_ref c;
7687 278 : dw_die_ref decl;
7688 278 : struct checksum_attributes attrs;
7689 :
7690 278 : CHECKSUM_ULEB128 ('D');
7691 278 : CHECKSUM_ULEB128 (die->die_tag);
7692 :
7693 278 : memset (&attrs, 0, sizeof (attrs));
7694 :
7695 278 : decl = get_AT_ref (die, DW_AT_specification);
7696 278 : if (decl != NULL)
7697 3 : collect_checksum_attributes (&attrs, decl);
7698 278 : collect_checksum_attributes (&attrs, die);
7699 :
7700 278 : CHECKSUM_ATTR (attrs.at_name);
7701 278 : CHECKSUM_ATTR (attrs.at_accessibility);
7702 278 : CHECKSUM_ATTR (attrs.at_address_class);
7703 278 : CHECKSUM_ATTR (attrs.at_allocated);
7704 278 : CHECKSUM_ATTR (attrs.at_artificial);
7705 278 : CHECKSUM_ATTR (attrs.at_associated);
7706 278 : CHECKSUM_ATTR (attrs.at_binary_scale);
7707 278 : CHECKSUM_ATTR (attrs.at_bit_offset);
7708 278 : CHECKSUM_ATTR (attrs.at_bit_size);
7709 278 : CHECKSUM_ATTR (attrs.at_bit_stride);
7710 278 : CHECKSUM_ATTR (attrs.at_byte_size);
7711 278 : CHECKSUM_ATTR (attrs.at_byte_stride);
7712 278 : CHECKSUM_ATTR (attrs.at_const_value);
7713 278 : CHECKSUM_ATTR (attrs.at_containing_type);
7714 278 : CHECKSUM_ATTR (attrs.at_count);
7715 278 : CHECKSUM_ATTR (attrs.at_data_location);
7716 278 : CHECKSUM_ATTR (attrs.at_data_member_location);
7717 278 : CHECKSUM_ATTR (attrs.at_decimal_scale);
7718 278 : CHECKSUM_ATTR (attrs.at_decimal_sign);
7719 278 : CHECKSUM_ATTR (attrs.at_default_value);
7720 278 : CHECKSUM_ATTR (attrs.at_digit_count);
7721 278 : CHECKSUM_ATTR (attrs.at_discr);
7722 278 : CHECKSUM_ATTR (attrs.at_discr_list);
7723 278 : CHECKSUM_ATTR (attrs.at_discr_value);
7724 278 : CHECKSUM_ATTR (attrs.at_encoding);
7725 278 : CHECKSUM_ATTR (attrs.at_endianity);
7726 278 : CHECKSUM_ATTR (attrs.at_explicit);
7727 278 : CHECKSUM_ATTR (attrs.at_is_optional);
7728 278 : CHECKSUM_ATTR (attrs.at_location);
7729 278 : CHECKSUM_ATTR (attrs.at_lower_bound);
7730 278 : CHECKSUM_ATTR (attrs.at_mutable);
7731 278 : CHECKSUM_ATTR (attrs.at_ordering);
7732 278 : CHECKSUM_ATTR (attrs.at_picture_string);
7733 278 : CHECKSUM_ATTR (attrs.at_prototyped);
7734 278 : CHECKSUM_ATTR (attrs.at_small);
7735 278 : CHECKSUM_ATTR (attrs.at_segment);
7736 278 : CHECKSUM_ATTR (attrs.at_string_length);
7737 278 : CHECKSUM_ATTR (attrs.at_string_length_bit_size);
7738 278 : CHECKSUM_ATTR (attrs.at_string_length_byte_size);
7739 278 : CHECKSUM_ATTR (attrs.at_threads_scaled);
7740 278 : CHECKSUM_ATTR (attrs.at_upper_bound);
7741 278 : CHECKSUM_ATTR (attrs.at_use_location);
7742 278 : CHECKSUM_ATTR (attrs.at_use_UTF8);
7743 278 : CHECKSUM_ATTR (attrs.at_variable_parameter);
7744 278 : CHECKSUM_ATTR (attrs.at_virtuality);
7745 278 : CHECKSUM_ATTR (attrs.at_visibility);
7746 278 : CHECKSUM_ATTR (attrs.at_vtable_elem_location);
7747 278 : CHECKSUM_ATTR (attrs.at_type);
7748 278 : CHECKSUM_ATTR (attrs.at_friend);
7749 278 : CHECKSUM_ATTR (attrs.at_alignment);
7750 :
7751 : /* Checksum the child DIEs. */
7752 278 : c = die->die_child;
7753 278 : if (c) do {
7754 216 : dw_attr_node *name_attr;
7755 :
7756 216 : c = c->die_sib;
7757 216 : name_attr = get_AT (c, DW_AT_name);
7758 216 : if (is_template_instantiation (c))
7759 : {
7760 : /* Ignore instantiations of member type and function templates. */
7761 : }
7762 212 : else if (name_attr != NULL
7763 212 : && (is_type_die (c) || c->die_tag == DW_TAG_subprogram))
7764 : {
7765 : /* Use a shallow checksum for named nested types and member
7766 : functions. */
7767 107 : CHECKSUM_ULEB128 ('S');
7768 107 : CHECKSUM_ULEB128 (c->die_tag);
7769 107 : CHECKSUM_STRING (AT_string (name_attr));
7770 : }
7771 : else
7772 : {
7773 : /* Use a deep checksum for other children. */
7774 : /* Mark this DIE so it gets processed when unmarking. */
7775 105 : if (c->die_mark == 0)
7776 105 : c->die_mark = -1;
7777 105 : die_checksum_ordered (c, ctx, mark);
7778 : }
7779 216 : } while (c != die->die_child);
7780 :
7781 278 : CHECKSUM_ULEB128 (0);
7782 278 : }
7783 :
7784 : /* Add a type name and tag to a hash. */
7785 : static void
7786 69 : die_odr_checksum (int tag, const char *name, md5_ctx *ctx)
7787 : {
7788 69 : CHECKSUM_ULEB128 (tag);
7789 69 : CHECKSUM_STRING (name);
7790 69 : }
7791 :
7792 : #undef CHECKSUM
7793 : #undef CHECKSUM_STRING
7794 : #undef CHECKSUM_ATTR
7795 : #undef CHECKSUM_LEB128
7796 : #undef CHECKSUM_ULEB128
7797 :
7798 : /* Generate the type signature for DIE. This is computed by generating an
7799 : MD5 checksum over the DIE's tag, its relevant attributes, and its
7800 : children. Attributes that are references to other DIEs are processed
7801 : by recursion, using the MARK field to prevent infinite recursion.
7802 : If the DIE is nested inside a namespace or another type, we also
7803 : need to include that context in the signature. The lower 64 bits
7804 : of the resulting MD5 checksum comprise the signature. */
7805 :
7806 : static void
7807 81 : generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
7808 : {
7809 81 : int mark;
7810 81 : const char *name;
7811 81 : unsigned char checksum[16];
7812 81 : struct md5_ctx ctx;
7813 81 : dw_die_ref decl;
7814 81 : dw_die_ref parent;
7815 :
7816 81 : name = get_AT_string (die, DW_AT_name);
7817 81 : decl = get_AT_ref (die, DW_AT_specification);
7818 81 : parent = dw_get_die_parent (die);
7819 :
7820 : /* First, compute a signature for just the type name (and its surrounding
7821 : context, if any. This is stored in the type unit DIE for link-time
7822 : ODR (one-definition rule) checking. */
7823 :
7824 81 : if (is_cxx () && name != NULL)
7825 : {
7826 69 : md5_init_ctx (&ctx);
7827 :
7828 : /* Checksum the names of surrounding namespaces and structures. */
7829 69 : if (parent != NULL)
7830 69 : checksum_die_context (parent, &ctx);
7831 :
7832 : /* Checksum the current DIE. */
7833 69 : die_odr_checksum (die->die_tag, name, &ctx);
7834 69 : md5_finish_ctx (&ctx, checksum);
7835 :
7836 69 : add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
7837 : }
7838 :
7839 : /* Next, compute the complete type signature. */
7840 :
7841 81 : md5_init_ctx (&ctx);
7842 81 : mark = 1;
7843 81 : die->die_mark = mark;
7844 :
7845 : /* Checksum the names of surrounding namespaces and structures. */
7846 81 : if (parent != NULL)
7847 81 : checksum_die_context (parent, &ctx);
7848 :
7849 : /* Checksum the DIE and its children. */
7850 81 : die_checksum_ordered (die, &ctx, &mark);
7851 81 : unmark_all_dies (die);
7852 81 : md5_finish_ctx (&ctx, checksum);
7853 :
7854 : /* Store the signature in the type node and link the type DIE and the
7855 : type node together. */
7856 81 : memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
7857 : DWARF_TYPE_SIGNATURE_SIZE);
7858 81 : die->comdat_type_p = true;
7859 81 : die->die_id.die_type_node = type_node;
7860 81 : type_node->type_die = die;
7861 :
7862 : /* If the DIE is a specification, link its declaration to the type node
7863 : as well. */
7864 81 : if (decl != NULL)
7865 : {
7866 0 : decl->comdat_type_p = true;
7867 0 : decl->die_id.die_type_node = type_node;
7868 : }
7869 81 : }
7870 :
7871 : /* Do the location expressions look same? */
7872 : static inline bool
7873 0 : same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7874 : {
7875 0 : return loc1->dw_loc_opc == loc2->dw_loc_opc
7876 0 : && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7877 0 : && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7878 : }
7879 :
7880 : /* Do the values look the same? */
7881 : static bool
7882 0 : same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7883 : {
7884 0 : dw_loc_descr_ref loc1, loc2;
7885 0 : rtx r1, r2;
7886 :
7887 0 : if (v1->val_class != v2->val_class)
7888 : return false;
7889 :
7890 0 : switch (v1->val_class)
7891 : {
7892 0 : case dw_val_class_const:
7893 0 : case dw_val_class_const_implicit:
7894 0 : return v1->v.val_int == v2->v.val_int;
7895 0 : case dw_val_class_unsigned_const:
7896 0 : case dw_val_class_unsigned_const_implicit:
7897 0 : return v1->v.val_unsigned == v2->v.val_unsigned;
7898 0 : case dw_val_class_const_double:
7899 0 : return v1->v.val_double.high == v2->v.val_double.high
7900 0 : && v1->v.val_double.low == v2->v.val_double.low;
7901 0 : case dw_val_class_wide_int:
7902 0 : return *v1->v.val_wide == *v2->v.val_wide;
7903 0 : case dw_val_class_vec:
7904 0 : if (v1->v.val_vec.length != v2->v.val_vec.length
7905 0 : || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7906 : return false;
7907 0 : if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7908 0 : v1->v.val_vec.length * v1->v.val_vec.elt_size))
7909 : return false;
7910 : return true;
7911 0 : case dw_val_class_flag:
7912 0 : return v1->v.val_flag == v2->v.val_flag;
7913 0 : case dw_val_class_str:
7914 0 : return !strcmp (v1->v.val_str->str, v2->v.val_str->str);
7915 :
7916 0 : case dw_val_class_addr:
7917 0 : r1 = v1->v.val_addr;
7918 0 : r2 = v2->v.val_addr;
7919 0 : if (GET_CODE (r1) != GET_CODE (r2))
7920 : return false;
7921 0 : return !rtx_equal_p (r1, r2);
7922 :
7923 0 : case dw_val_class_offset:
7924 0 : return v1->v.val_offset == v2->v.val_offset;
7925 :
7926 0 : case dw_val_class_loc:
7927 0 : for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7928 0 : loc1 && loc2;
7929 0 : loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7930 0 : if (!same_loc_p (loc1, loc2, mark))
7931 : return false;
7932 0 : return !loc1 && !loc2;
7933 :
7934 0 : case dw_val_class_die_ref:
7935 0 : return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7936 :
7937 0 : case dw_val_class_symview:
7938 0 : return strcmp (v1->v.val_symbolic_view, v2->v.val_symbolic_view) == 0;
7939 :
7940 : case dw_val_class_fde_ref:
7941 : case dw_val_class_vms_delta:
7942 : case dw_val_class_lbl_id:
7943 : case dw_val_class_lineptr:
7944 : case dw_val_class_macptr:
7945 : case dw_val_class_loclistsptr:
7946 : case dw_val_class_high_pc:
7947 : return true;
7948 :
7949 0 : case dw_val_class_file:
7950 0 : case dw_val_class_file_implicit:
7951 0 : return v1->v.val_file == v2->v.val_file;
7952 :
7953 0 : case dw_val_class_data8:
7954 0 : return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
7955 :
7956 : default:
7957 : return true;
7958 : }
7959 : }
7960 :
7961 : /* Do the attributes look the same? */
7962 :
7963 : static bool
7964 0 : same_attr_p (dw_attr_node *at1, dw_attr_node *at2, int *mark)
7965 : {
7966 0 : if (at1->dw_attr != at2->dw_attr)
7967 : return false;
7968 :
7969 : /* We don't care that this was compiled with a different compiler
7970 : snapshot; if the output is the same, that's what matters. */
7971 0 : if (at1->dw_attr == DW_AT_producer)
7972 : return true;
7973 :
7974 0 : return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7975 : }
7976 :
7977 : /* Do the dies look the same? */
7978 :
7979 : static bool
7980 0 : same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7981 : {
7982 0 : dw_die_ref c1, c2;
7983 0 : dw_attr_node *a1;
7984 0 : unsigned ix;
7985 :
7986 : /* To avoid infinite recursion. */
7987 0 : if (die1->die_mark)
7988 0 : return die1->die_mark == die2->die_mark;
7989 0 : die1->die_mark = die2->die_mark = ++(*mark);
7990 :
7991 0 : if (die1->die_tag != die2->die_tag)
7992 : return false;
7993 :
7994 0 : if (vec_safe_length (die1->die_attr) != vec_safe_length (die2->die_attr))
7995 : return false;
7996 :
7997 0 : FOR_EACH_VEC_SAFE_ELT (die1->die_attr, ix, a1)
7998 0 : if (!same_attr_p (a1, &(*die2->die_attr)[ix], mark))
7999 : return false;
8000 :
8001 0 : c1 = die1->die_child;
8002 0 : c2 = die2->die_child;
8003 0 : if (! c1)
8004 : {
8005 0 : if (c2)
8006 : return false;
8007 : }
8008 : else
8009 0 : for (;;)
8010 : {
8011 0 : if (!same_die_p (c1, c2, mark))
8012 : return false;
8013 0 : c1 = c1->die_sib;
8014 0 : c2 = c2->die_sib;
8015 0 : if (c1 == die1->die_child)
8016 : {
8017 0 : if (c2 == die2->die_child)
8018 : break;
8019 : else
8020 : return false;
8021 : }
8022 : }
8023 :
8024 : return true;
8025 : }
8026 :
8027 : /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8028 : children, and set die_symbol. */
8029 :
8030 : static void
8031 1327 : compute_comp_unit_symbol (dw_die_ref unit_die)
8032 : {
8033 1327 : const char *die_name = get_AT_string (unit_die, DW_AT_name);
8034 1327 : const char *base = die_name ? lbasename (die_name) : "anonymous";
8035 1327 : char *name = XALLOCAVEC (char, strlen (base) + 64);
8036 1327 : char *p;
8037 1327 : int i, mark;
8038 1327 : unsigned char checksum[16];
8039 1327 : struct md5_ctx ctx;
8040 :
8041 : /* Compute the checksum of the DIE, then append part of it as hex digits to
8042 : the name filename of the unit. */
8043 :
8044 1327 : md5_init_ctx (&ctx);
8045 1327 : mark = 0;
8046 1327 : die_checksum (unit_die, &ctx, &mark);
8047 1327 : unmark_all_dies (unit_die);
8048 1327 : md5_finish_ctx (&ctx, checksum);
8049 :
8050 : /* When we this for comp_unit_die () we have a DW_AT_name that might
8051 : not start with a letter but with anything valid for filenames and
8052 : clean_symbol_name doesn't fix that up. Prepend 'g' if the first
8053 : character is not a letter. */
8054 1327 : sprintf (name, "%s%s.", ISALPHA (*base) ? "" : "g", base);
8055 1327 : clean_symbol_name (name);
8056 :
8057 1327 : p = name + strlen (name);
8058 6635 : for (i = 0; i < 4; i++)
8059 : {
8060 5308 : sprintf (p, "%.2x", checksum[i]);
8061 5308 : p += 2;
8062 : }
8063 :
8064 1327 : unit_die->die_id.die_symbol = xstrdup (name);
8065 1327 : }
8066 :
8067 : /* Returns true if DIE represents a type, in the sense of TYPE_P. */
8068 :
8069 : static bool
8070 78965290 : is_type_die (dw_die_ref die)
8071 : {
8072 78965290 : switch (die->die_tag)
8073 : {
8074 : case DW_TAG_array_type:
8075 : case DW_TAG_class_type:
8076 : case DW_TAG_interface_type:
8077 : case DW_TAG_enumeration_type:
8078 : case DW_TAG_pointer_type:
8079 : case DW_TAG_reference_type:
8080 : case DW_TAG_rvalue_reference_type:
8081 : case DW_TAG_string_type:
8082 : case DW_TAG_structure_type:
8083 : case DW_TAG_subroutine_type:
8084 : case DW_TAG_union_type:
8085 : case DW_TAG_ptr_to_member_type:
8086 : case DW_TAG_set_type:
8087 : case DW_TAG_subrange_type:
8088 : case DW_TAG_base_type:
8089 : case DW_TAG_const_type:
8090 : case DW_TAG_file_type:
8091 : case DW_TAG_packed_type:
8092 : case DW_TAG_volatile_type:
8093 : case DW_TAG_typedef:
8094 : return true;
8095 71054208 : default:
8096 71054208 : return false;
8097 : }
8098 : }
8099 :
8100 : /* Returns true iff C is a compile-unit DIE. */
8101 :
8102 : static inline bool
8103 50260483 : is_cu_die (dw_die_ref c)
8104 : {
8105 49928924 : return c && (c->die_tag == DW_TAG_compile_unit
8106 50207218 : || c->die_tag == DW_TAG_skeleton_unit);
8107 : }
8108 :
8109 : /* Returns true iff C is a unit DIE of some sort. */
8110 :
8111 : static inline bool
8112 1796784 : is_unit_die (dw_die_ref c)
8113 : {
8114 1796784 : return c && (c->die_tag == DW_TAG_compile_unit
8115 : || c->die_tag == DW_TAG_partial_unit
8116 : || c->die_tag == DW_TAG_type_unit
8117 1796784 : || c->die_tag == DW_TAG_skeleton_unit);
8118 : }
8119 :
8120 : /* Returns true iff C is a namespace DIE. */
8121 :
8122 : static inline bool
8123 165 : is_namespace_die (dw_die_ref c)
8124 : {
8125 165 : return c && c->die_tag == DW_TAG_namespace;
8126 : }
8127 :
8128 : /* Return true if this DIE is a template parameter. */
8129 :
8130 : static inline bool
8131 19231168 : is_template_parameter (dw_die_ref die)
8132 : {
8133 19231168 : switch (die->die_tag)
8134 : {
8135 : case DW_TAG_template_type_param:
8136 : case DW_TAG_template_value_param:
8137 : case DW_TAG_GNU_template_template_param:
8138 : case DW_TAG_GNU_template_parameter_pack:
8139 : return true;
8140 216 : default:
8141 216 : return false;
8142 : }
8143 : }
8144 :
8145 : /* Return true if this DIE represents a template instantiation. */
8146 :
8147 : static inline bool
8148 320 : is_template_instantiation (dw_die_ref die)
8149 : {
8150 320 : dw_die_ref c;
8151 :
8152 320 : if (!is_type_die (die) && die->die_tag != DW_TAG_subprogram)
8153 : return false;
8154 263 : FOR_EACH_CHILD (die, c, if (is_template_parameter (c)) return true);
8155 : return false;
8156 : }
8157 :
8158 : static char *
8159 26149683 : gen_internal_sym (const char *prefix)
8160 : {
8161 26149683 : char buf[MAX_ARTIFICIAL_LABEL_BYTES];
8162 :
8163 26149683 : ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
8164 26149683 : return xstrdup (buf);
8165 : }
8166 :
8167 : /* Return true if this DIE is a declaration. */
8168 :
8169 : static bool
8170 31775073 : is_declaration_die (dw_die_ref die)
8171 : {
8172 31775073 : dw_attr_node *a;
8173 31775073 : unsigned ix;
8174 :
8175 222832694 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8176 222105067 : if (a->dw_attr == DW_AT_declaration)
8177 : return true;
8178 :
8179 : return false;
8180 : }
8181 :
8182 : /* Return true if this DIE is nested inside a subprogram. */
8183 :
8184 : static bool
8185 82 : is_nested_in_subprogram (dw_die_ref die)
8186 : {
8187 82 : dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
8188 :
8189 82 : if (decl == NULL)
8190 82 : decl = die;
8191 82 : return local_scope_p (decl);
8192 : }
8193 :
8194 : /* Return true if this DIE contains a defining declaration of a
8195 : subprogram. */
8196 :
8197 : static bool
8198 392 : contains_subprogram_definition (dw_die_ref die)
8199 : {
8200 392 : dw_die_ref c;
8201 :
8202 392 : if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
8203 : return true;
8204 536 : FOR_EACH_CHILD (die, c, if (contains_subprogram_definition (c)) return 1);
8205 : return false;
8206 : }
8207 :
8208 : /* Return true if this is a type DIE that should be moved to a
8209 : COMDAT .debug_types section or .debug_info section with DW_UT_*type
8210 : unit type. */
8211 :
8212 : static bool
8213 766 : should_move_die_to_comdat (dw_die_ref die)
8214 : {
8215 766 : switch (die->die_tag)
8216 : {
8217 87 : case DW_TAG_class_type:
8218 87 : case DW_TAG_structure_type:
8219 87 : case DW_TAG_enumeration_type:
8220 87 : case DW_TAG_union_type:
8221 : /* Don't move declarations, inlined instances, types nested in a
8222 : subprogram, or types that contain subprogram definitions. */
8223 87 : if (is_declaration_die (die)
8224 82 : || get_AT (die, DW_AT_abstract_origin)
8225 82 : || is_nested_in_subprogram (die)
8226 169 : || contains_subprogram_definition (die))
8227 5 : return false;
8228 82 : if (die->die_tag != DW_TAG_enumeration_type)
8229 : {
8230 : /* Don't move non-constant size aggregates. */
8231 68 : dw_attr_node *sz = get_AT (die, DW_AT_byte_size);
8232 68 : if (sz == NULL
8233 68 : || (AT_class (sz) != dw_val_class_unsigned_const
8234 0 : && AT_class (sz) != dw_val_class_unsigned_const_implicit))
8235 1 : return false;
8236 : }
8237 : return true;
8238 : case DW_TAG_array_type:
8239 : case DW_TAG_interface_type:
8240 : case DW_TAG_pointer_type:
8241 : case DW_TAG_reference_type:
8242 : case DW_TAG_rvalue_reference_type:
8243 : case DW_TAG_string_type:
8244 : case DW_TAG_subroutine_type:
8245 : case DW_TAG_ptr_to_member_type:
8246 : case DW_TAG_set_type:
8247 : case DW_TAG_subrange_type:
8248 : case DW_TAG_base_type:
8249 : case DW_TAG_const_type:
8250 : case DW_TAG_file_type:
8251 : case DW_TAG_packed_type:
8252 : case DW_TAG_volatile_type:
8253 : case DW_TAG_typedef:
8254 : default:
8255 : return false;
8256 : }
8257 : }
8258 :
8259 : /* Make a clone of DIE. */
8260 :
8261 : static dw_die_ref
8262 275 : clone_die (dw_die_ref die)
8263 : {
8264 275 : dw_die_ref clone = new_die_raw (die->die_tag);
8265 275 : dw_attr_node *a;
8266 275 : unsigned ix;
8267 :
8268 1656 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8269 1106 : add_dwarf_attr (clone, a);
8270 :
8271 275 : return clone;
8272 : }
8273 :
8274 : /* Make a clone of the tree rooted at DIE. */
8275 :
8276 : static dw_die_ref
8277 0 : clone_tree (dw_die_ref die)
8278 : {
8279 0 : dw_die_ref c;
8280 0 : dw_die_ref clone = clone_die (die);
8281 :
8282 0 : FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree (c)));
8283 :
8284 0 : return clone;
8285 : }
8286 :
8287 : /* Make a clone of DIE as a declaration. */
8288 :
8289 : static dw_die_ref
8290 147 : clone_as_declaration (dw_die_ref die)
8291 : {
8292 147 : dw_die_ref clone;
8293 147 : dw_die_ref decl;
8294 147 : dw_attr_node *a;
8295 147 : unsigned ix;
8296 :
8297 : /* If the DIE is already a declaration, just clone it. */
8298 147 : if (is_declaration_die (die))
8299 0 : return clone_die (die);
8300 :
8301 : /* If the DIE is a specification, just clone its declaration DIE. */
8302 147 : decl = get_AT_ref (die, DW_AT_specification);
8303 147 : if (decl != NULL)
8304 : {
8305 30 : clone = clone_die (decl);
8306 30 : if (die->comdat_type_p)
8307 30 : add_AT_die_ref (clone, DW_AT_signature, die);
8308 30 : return clone;
8309 : }
8310 :
8311 117 : clone = new_die_raw (die->die_tag);
8312 :
8313 759 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8314 : {
8315 : /* We don't want to copy over all attributes.
8316 : For example we don't want DW_AT_byte_size because otherwise we will no
8317 : longer have a declaration and GDB will treat it as a definition. */
8318 :
8319 525 : switch (a->dw_attr)
8320 : {
8321 111 : case DW_AT_abstract_origin:
8322 111 : case DW_AT_artificial:
8323 111 : case DW_AT_containing_type:
8324 111 : case DW_AT_external:
8325 111 : case DW_AT_name:
8326 111 : case DW_AT_type:
8327 111 : case DW_AT_virtuality:
8328 111 : case DW_AT_linkage_name:
8329 111 : case DW_AT_MIPS_linkage_name:
8330 111 : add_dwarf_attr (clone, a);
8331 111 : break;
8332 : case DW_AT_byte_size:
8333 : case DW_AT_alignment:
8334 : default:
8335 : break;
8336 : }
8337 : }
8338 :
8339 117 : if (die->comdat_type_p)
8340 66 : add_AT_die_ref (clone, DW_AT_signature, die);
8341 :
8342 117 : add_AT_flag (clone, DW_AT_declaration, 1);
8343 117 : return clone;
8344 : }
8345 :
8346 :
8347 : /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
8348 :
8349 : struct decl_table_entry
8350 : {
8351 : dw_die_ref orig;
8352 : dw_die_ref copy;
8353 : };
8354 :
8355 : /* Helpers to manipulate hash table of copied declarations. */
8356 :
8357 : /* Hashtable helpers. */
8358 :
8359 : struct decl_table_entry_hasher : free_ptr_hash <decl_table_entry>
8360 : {
8361 : typedef die_struct *compare_type;
8362 : static inline hashval_t hash (const decl_table_entry *);
8363 : static inline bool equal (const decl_table_entry *, const die_struct *);
8364 : };
8365 :
8366 : inline hashval_t
8367 399 : decl_table_entry_hasher::hash (const decl_table_entry *entry)
8368 : {
8369 399 : return htab_hash_pointer (entry->orig);
8370 : }
8371 :
8372 : inline bool
8373 450 : decl_table_entry_hasher::equal (const decl_table_entry *entry1,
8374 : const die_struct *entry2)
8375 : {
8376 450 : return entry1->orig == entry2;
8377 : }
8378 :
8379 : typedef hash_table<decl_table_entry_hasher> decl_hash_type;
8380 :
8381 : /* Copy DIE and its ancestors, up to, but not including, the compile unit
8382 : or type unit entry, to a new tree. Adds the new tree to UNIT and returns
8383 : a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
8384 : to check if the ancestor has already been copied into UNIT. */
8385 :
8386 : static dw_die_ref
8387 99 : copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
8388 : decl_hash_type *decl_table)
8389 : {
8390 99 : dw_die_ref parent = die->die_parent;
8391 99 : dw_die_ref new_parent = unit;
8392 99 : dw_die_ref copy;
8393 99 : decl_table_entry **slot = NULL;
8394 99 : struct decl_table_entry *entry = NULL;
8395 :
8396 : /* If DIE refers to a stub unfold that so we get the appropriate
8397 : DIE registered as orig in decl_table. */
8398 99 : if (dw_die_ref c = get_AT_ref (die, DW_AT_signature))
8399 0 : die = c;
8400 :
8401 99 : if (decl_table)
8402 : {
8403 : /* Check if the entry has already been copied to UNIT. */
8404 9 : slot = decl_table->find_slot_with_hash (die, htab_hash_pointer (die),
8405 : INSERT);
8406 9 : if (*slot != HTAB_EMPTY_ENTRY)
8407 : {
8408 3 : entry = *slot;
8409 3 : return entry->copy;
8410 : }
8411 :
8412 : /* Record in DECL_TABLE that DIE has been copied to UNIT. */
8413 6 : entry = XCNEW (struct decl_table_entry);
8414 6 : entry->orig = die;
8415 6 : entry->copy = NULL;
8416 6 : *slot = entry;
8417 : }
8418 :
8419 96 : if (parent != NULL)
8420 : {
8421 96 : dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
8422 96 : if (spec != NULL)
8423 0 : parent = spec;
8424 96 : if (!is_unit_die (parent))
8425 48 : new_parent = copy_ancestor_tree (unit, parent, decl_table);
8426 : }
8427 :
8428 96 : copy = clone_as_declaration (die);
8429 96 : add_child_die (new_parent, copy);
8430 :
8431 96 : if (decl_table)
8432 : {
8433 : /* Record the pointer to the copy. */
8434 6 : entry->copy = copy;
8435 : }
8436 :
8437 : return copy;
8438 : }
8439 : /* Copy the declaration context to the new type unit DIE. This includes
8440 : any surrounding namespace or type declarations. If the DIE has an
8441 : AT_specification attribute, it also includes attributes and children
8442 : attached to the specification, and returns a pointer to the original
8443 : parent of the declaration DIE. Returns NULL otherwise. */
8444 :
8445 : static dw_die_ref
8446 81 : copy_declaration_context (dw_die_ref unit, dw_die_ref die)
8447 : {
8448 81 : dw_die_ref decl;
8449 81 : dw_die_ref new_decl;
8450 81 : dw_die_ref orig_parent = NULL;
8451 :
8452 81 : decl = get_AT_ref (die, DW_AT_specification);
8453 81 : if (decl == NULL)
8454 : decl = die;
8455 : else
8456 : {
8457 0 : unsigned ix;
8458 0 : dw_die_ref c;
8459 0 : dw_attr_node *a;
8460 :
8461 : /* The original DIE will be changed to a declaration, and must
8462 : be moved to be a child of the original declaration DIE. */
8463 0 : orig_parent = decl->die_parent;
8464 :
8465 : /* Copy the type node pointer from the new DIE to the original
8466 : declaration DIE so we can forward references later. */
8467 0 : decl->comdat_type_p = true;
8468 0 : decl->die_id.die_type_node = die->die_id.die_type_node;
8469 :
8470 0 : remove_AT (die, DW_AT_specification);
8471 :
8472 0 : FOR_EACH_VEC_SAFE_ELT (decl->die_attr, ix, a)
8473 : {
8474 0 : if (a->dw_attr != DW_AT_name
8475 : && a->dw_attr != DW_AT_declaration
8476 : && a->dw_attr != DW_AT_external)
8477 0 : add_dwarf_attr (die, a);
8478 : }
8479 :
8480 0 : FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree (c)));
8481 : }
8482 :
8483 81 : if (decl->die_parent != NULL
8484 81 : && !is_unit_die (decl->die_parent))
8485 : {
8486 42 : new_decl = copy_ancestor_tree (unit, decl, NULL);
8487 42 : if (new_decl != NULL)
8488 : {
8489 42 : remove_AT (new_decl, DW_AT_signature);
8490 42 : add_AT_specification (die, new_decl);
8491 : }
8492 : }
8493 :
8494 81 : return orig_parent;
8495 : }
8496 :
8497 : /* Generate the skeleton ancestor tree for the given NODE, then clone
8498 : the DIE and add the clone into the tree. */
8499 :
8500 : static void
8501 92 : generate_skeleton_ancestor_tree (skeleton_chain_node *node)
8502 : {
8503 92 : if (node->new_die != NULL)
8504 : return;
8505 :
8506 39 : node->new_die = clone_as_declaration (node->old_die);
8507 :
8508 39 : if (node->parent != NULL)
8509 : {
8510 0 : generate_skeleton_ancestor_tree (node->parent);
8511 0 : add_child_die (node->parent->new_die, node->new_die);
8512 : }
8513 : }
8514 :
8515 : /* Generate a skeleton tree of DIEs containing any declarations that are
8516 : found in the original tree. We traverse the tree looking for declaration
8517 : DIEs, and construct the skeleton from the bottom up whenever we find one. */
8518 :
8519 : static void
8520 348 : generate_skeleton_bottom_up (skeleton_chain_node *parent)
8521 : {
8522 348 : skeleton_chain_node node;
8523 348 : dw_die_ref c;
8524 348 : dw_die_ref first;
8525 348 : dw_die_ref prev = NULL;
8526 348 : dw_die_ref next = NULL;
8527 :
8528 348 : node.parent = parent;
8529 :
8530 348 : first = c = parent->old_die->die_child;
8531 348 : if (c)
8532 147 : next = c->die_sib;
8533 147 : if (c) do {
8534 279 : if (prev == NULL || prev->die_sib == c)
8535 279 : prev = c;
8536 279 : c = next;
8537 279 : next = (c == first ? NULL : c->die_sib);
8538 279 : node.old_die = c;
8539 279 : node.new_die = NULL;
8540 279 : if (is_declaration_die (c))
8541 : {
8542 92 : if (is_template_instantiation (c))
8543 : {
8544 : /* Instantiated templates do not need to be cloned into the
8545 : type unit. Just move the DIE and its children back to
8546 : the skeleton tree (in the main CU). */
8547 4 : remove_child_with_prev (c, prev);
8548 4 : generate_skeleton_ancestor_tree (parent);
8549 4 : add_child_die (parent->new_die, c);
8550 4 : c = prev;
8551 : }
8552 88 : else if (c->comdat_type_p)
8553 : {
8554 : /* This is the skeleton of earlier break_out_comdat_types
8555 : type. Clone the existing DIE, but keep the children
8556 : under the original (which is in the main CU). */
8557 12 : dw_die_ref clone = clone_die (c);
8558 :
8559 12 : replace_child (c, clone, prev);
8560 12 : generate_skeleton_ancestor_tree (parent);
8561 12 : add_child_die (parent->new_die, c);
8562 12 : c = clone;
8563 12 : continue;
8564 12 : }
8565 : else
8566 : {
8567 : /* Clone the existing DIE, move the original to the skeleton
8568 : tree (which is in the main CU), and put the clone, with
8569 : all the original's children, where the original came from
8570 : (which is about to be moved to the type unit). */
8571 76 : dw_die_ref clone = clone_die (c);
8572 76 : move_all_children (c, clone);
8573 :
8574 : /* If the original has a DW_AT_object_pointer attribute,
8575 : it would now point to a child DIE just moved to the
8576 : cloned tree, so we need to remove that attribute from
8577 : the original. */
8578 76 : remove_AT (c, DW_AT_object_pointer);
8579 :
8580 76 : replace_child (c, clone, prev);
8581 76 : generate_skeleton_ancestor_tree (parent);
8582 76 : add_child_die (parent->new_die, c);
8583 76 : node.old_die = clone;
8584 76 : node.new_die = c;
8585 76 : c = clone;
8586 : }
8587 : }
8588 267 : generate_skeleton_bottom_up (&node);
8589 279 : } while (next != NULL);
8590 348 : }
8591 :
8592 : /* Wrapper function for generate_skeleton_bottom_up. */
8593 :
8594 : static dw_die_ref
8595 81 : generate_skeleton (dw_die_ref die)
8596 : {
8597 81 : skeleton_chain_node node;
8598 :
8599 81 : node.old_die = die;
8600 81 : node.new_die = NULL;
8601 81 : node.parent = NULL;
8602 :
8603 : /* If this type definition is nested inside another type,
8604 : and is not an instantiation of a template, always leave
8605 : at least a declaration in its place. */
8606 81 : if (die->die_parent != NULL
8607 81 : && is_type_die (die->die_parent)
8608 93 : && !is_template_instantiation (die))
8609 12 : node.new_die = clone_as_declaration (die);
8610 :
8611 81 : generate_skeleton_bottom_up (&node);
8612 81 : return node.new_die;
8613 : }
8614 :
8615 : /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8616 : declaration. The original DIE is moved to a new compile unit so that
8617 : existing references to it follow it to the new location. If any of the
8618 : original DIE's descendants is a declaration, we need to replace the
8619 : original DIE with a skeleton tree and move the declarations back into the
8620 : skeleton tree. */
8621 :
8622 : static dw_die_ref
8623 81 : remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
8624 : dw_die_ref prev)
8625 : {
8626 81 : dw_die_ref skeleton, orig_parent;
8627 :
8628 : /* Copy the declaration context to the type unit DIE. If the returned
8629 : ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8630 : that DIE. */
8631 81 : orig_parent = copy_declaration_context (unit, child);
8632 :
8633 81 : skeleton = generate_skeleton (child);
8634 81 : if (skeleton == NULL)
8635 30 : remove_child_with_prev (child, prev);
8636 : else
8637 : {
8638 51 : skeleton->comdat_type_p = true;
8639 51 : skeleton->die_id.die_type_node = child->die_id.die_type_node;
8640 :
8641 : /* If the original DIE was a specification, we need to put
8642 : the skeleton under the parent DIE of the declaration.
8643 : This leaves the original declaration in the tree, but
8644 : it will be pruned later since there are no longer any
8645 : references to it. */
8646 51 : if (orig_parent != NULL)
8647 : {
8648 0 : remove_child_with_prev (child, prev);
8649 0 : add_child_die (orig_parent, skeleton);
8650 : }
8651 : else
8652 51 : replace_child (child, skeleton, prev);
8653 : }
8654 :
8655 81 : return skeleton;
8656 : }
8657 :
8658 : static void
8659 : copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
8660 : comdat_type_node *type_node,
8661 : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs);
8662 :
8663 : /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8664 : procedure, put it under TYPE_NODE and return the copy. Continue looking for
8665 : DWARF procedure references in the DW_AT_location attribute. */
8666 :
8667 : static dw_die_ref
8668 0 : copy_dwarf_procedure (dw_die_ref die,
8669 : comdat_type_node *type_node,
8670 : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
8671 : {
8672 0 : gcc_assert (die->die_tag == DW_TAG_dwarf_procedure);
8673 :
8674 : /* DWARF procedures are not supposed to have children... */
8675 0 : gcc_assert (die->die_child == NULL);
8676 :
8677 : /* ... and they are supposed to have only one attribute: DW_AT_location. */
8678 0 : gcc_assert (vec_safe_length (die->die_attr) == 1
8679 : && ((*die->die_attr)[0].dw_attr == DW_AT_location));
8680 :
8681 : /* Do not copy more than once DWARF procedures. */
8682 0 : bool existed;
8683 0 : dw_die_ref &die_copy = copied_dwarf_procs.get_or_insert (die, &existed);
8684 0 : if (existed)
8685 0 : return die_copy;
8686 :
8687 0 : die_copy = clone_die (die);
8688 0 : add_child_die (type_node->root_die, die_copy);
8689 0 : copy_dwarf_procs_ref_in_attrs (die_copy, type_node, copied_dwarf_procs);
8690 0 : return die_copy;
8691 : }
8692 :
8693 : /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8694 : procedures in DIE's attributes. */
8695 :
8696 : static void
8697 344 : copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
8698 : comdat_type_node *type_node,
8699 : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
8700 : {
8701 344 : dw_attr_node *a;
8702 344 : unsigned i;
8703 :
8704 1960 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, i, a)
8705 : {
8706 1616 : dw_loc_descr_ref loc;
8707 :
8708 1616 : if (a->dw_attr_val.val_class != dw_val_class_loc)
8709 1616 : continue;
8710 :
8711 0 : for (loc = a->dw_attr_val.v.val_loc; loc != NULL; loc = loc->dw_loc_next)
8712 : {
8713 0 : switch (loc->dw_loc_opc)
8714 : {
8715 0 : case DW_OP_call2:
8716 0 : case DW_OP_call4:
8717 0 : case DW_OP_call_ref:
8718 0 : gcc_assert (loc->dw_loc_oprnd1.val_class
8719 : == dw_val_class_die_ref);
8720 0 : loc->dw_loc_oprnd1.v.val_die_ref.die
8721 0 : = copy_dwarf_procedure (loc->dw_loc_oprnd1.v.val_die_ref.die,
8722 : type_node,
8723 : copied_dwarf_procs);
8724 :
8725 0 : default:
8726 0 : break;
8727 : }
8728 : }
8729 : }
8730 344 : }
8731 :
8732 : /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8733 : rewrite references to point to the copies.
8734 :
8735 : References are looked for in DIE's attributes and recursively in all its
8736 : children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8737 : mapping from old DWARF procedures to their copy. It is used not to copy
8738 : twice the same DWARF procedure under TYPE_NODE. */
8739 :
8740 : static void
8741 344 : copy_dwarf_procs_ref_in_dies (dw_die_ref die,
8742 : comdat_type_node *type_node,
8743 : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
8744 : {
8745 344 : dw_die_ref c;
8746 :
8747 344 : copy_dwarf_procs_ref_in_attrs (die, type_node, copied_dwarf_procs);
8748 607 : FOR_EACH_CHILD (die, c, copy_dwarf_procs_ref_in_dies (c,
8749 : type_node,
8750 : copied_dwarf_procs));
8751 344 : }
8752 :
8753 : /* Traverse the DIE and set up additional .debug_types or .debug_info
8754 : DW_UT_*type sections for each type worthy of being placed in a COMDAT
8755 : section. */
8756 :
8757 : static void
8758 150 : break_out_comdat_types (dw_die_ref die)
8759 : {
8760 150 : dw_die_ref c;
8761 150 : dw_die_ref first;
8762 150 : dw_die_ref prev = NULL;
8763 150 : dw_die_ref next = NULL;
8764 150 : dw_die_ref unit = NULL;
8765 :
8766 150 : first = c = die->die_child;
8767 150 : if (c)
8768 144 : next = c->die_sib;
8769 144 : if (c) do {
8770 766 : if (prev == NULL || prev->die_sib == c)
8771 736 : prev = c;
8772 766 : c = next;
8773 766 : next = (c == first ? NULL : c->die_sib);
8774 766 : if (should_move_die_to_comdat (c))
8775 : {
8776 81 : dw_die_ref replacement;
8777 81 : comdat_type_node *type_node;
8778 :
8779 : /* Break out nested types into their own type units. */
8780 81 : break_out_comdat_types (c);
8781 :
8782 : /* Create a new type unit DIE as the root for the new tree. */
8783 81 : unit = new_die (DW_TAG_type_unit, NULL, NULL);
8784 81 : add_AT_unsigned (unit, DW_AT_language,
8785 81 : get_AT_unsigned (comp_unit_die (), DW_AT_language));
8786 81 : if (unsigned lname = get_AT_unsigned (comp_unit_die (),
8787 : DW_AT_language_name))
8788 : {
8789 16 : add_AT_unsigned (unit, DW_AT_language_name, lname);
8790 16 : add_AT_unsigned (unit, DW_AT_language_version,
8791 16 : get_AT_unsigned (comp_unit_die (),
8792 : DW_AT_language_version));
8793 : }
8794 :
8795 : /* Add the new unit's type DIE into the comdat type list. */
8796 81 : type_node = ggc_cleared_alloc<comdat_type_node> ();
8797 81 : type_node->root_die = unit;
8798 81 : type_node->next = comdat_type_list;
8799 81 : comdat_type_list = type_node;
8800 :
8801 : /* Generate the type signature. */
8802 81 : generate_type_signature (c, type_node);
8803 :
8804 : /* Copy the declaration context, attributes, and children of the
8805 : declaration into the new type unit DIE, then remove this DIE
8806 : from the main CU (or replace it with a skeleton if necessary). */
8807 81 : replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
8808 81 : type_node->skeleton_die = replacement;
8809 :
8810 : /* Add the DIE to the new compunit. */
8811 81 : add_child_die (unit, c);
8812 :
8813 : /* Types can reference DWARF procedures for type size or data location
8814 : expressions. Calls in DWARF expressions cannot target procedures
8815 : that are not in the same section. So we must copy DWARF procedures
8816 : along with this type and then rewrite references to them. */
8817 81 : hash_map<dw_die_ref, dw_die_ref> copied_dwarf_procs;
8818 81 : copy_dwarf_procs_ref_in_dies (c, type_node, copied_dwarf_procs);
8819 :
8820 81 : if (replacement != NULL)
8821 51 : c = replacement;
8822 81 : }
8823 685 : else if (c->die_tag == DW_TAG_namespace
8824 : || c->die_tag == DW_TAG_class_type
8825 : || c->die_tag == DW_TAG_structure_type
8826 : || c->die_tag == DW_TAG_union_type)
8827 : {
8828 : /* Look for nested types that can be broken out. */
8829 33 : break_out_comdat_types (c);
8830 : }
8831 766 : } while (next != NULL);
8832 150 : }
8833 :
8834 : /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8835 : Enter all the cloned children into the hash table decl_table. */
8836 :
8837 : static dw_die_ref
8838 8 : clone_tree_partial (dw_die_ref die, decl_hash_type *decl_table)
8839 : {
8840 8 : dw_die_ref c;
8841 8 : dw_die_ref clone;
8842 8 : struct decl_table_entry *entry;
8843 8 : decl_table_entry **slot;
8844 :
8845 8 : if (die->die_tag == DW_TAG_subprogram)
8846 0 : clone = clone_as_declaration (die);
8847 : else
8848 8 : clone = clone_die (die);
8849 :
8850 8 : slot = decl_table->find_slot_with_hash (die,
8851 : htab_hash_pointer (die), INSERT);
8852 :
8853 : /* Assert that DIE isn't in the hash table yet. If it would be there
8854 : before, the ancestors would be necessarily there as well, therefore
8855 : clone_tree_partial wouldn't be called. */
8856 8 : gcc_assert (*slot == HTAB_EMPTY_ENTRY);
8857 :
8858 8 : entry = XCNEW (struct decl_table_entry);
8859 8 : entry->orig = die;
8860 8 : entry->copy = clone;
8861 8 : *slot = entry;
8862 :
8863 8 : if (die->die_tag != DW_TAG_subprogram)
8864 8 : FOR_EACH_CHILD (die, c,
8865 : add_child_die (clone, clone_tree_partial (c, decl_table)));
8866 :
8867 8 : return clone;
8868 : }
8869 :
8870 : /* Walk the DIE and its children, looking for references to incomplete
8871 : or trivial types that are unmarked (i.e., that are not in the current
8872 : type_unit). */
8873 :
8874 : static void
8875 1712 : copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
8876 : {
8877 1712 : dw_die_ref c;
8878 1712 : dw_attr_node *a;
8879 1712 : unsigned ix;
8880 :
8881 7573 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8882 : {
8883 5861 : if (AT_class (a) == dw_val_class_die_ref)
8884 : {
8885 1353 : dw_die_ref targ = AT_ref (a);
8886 1353 : decl_table_entry **slot;
8887 1353 : struct decl_table_entry *entry;
8888 :
8889 1353 : if (targ->die_mark != 0 || targ->comdat_type_p)
8890 1118 : continue;
8891 :
8892 235 : slot = decl_table->find_slot_with_hash (targ,
8893 : htab_hash_pointer (targ),
8894 : INSERT);
8895 :
8896 235 : if (*slot != HTAB_EMPTY_ENTRY)
8897 : {
8898 : /* TARG has already been copied, so we just need to
8899 : modify the reference to point to the copy. */
8900 88 : entry = *slot;
8901 88 : a->dw_attr_val.v.val_die_ref.die = entry->copy;
8902 : }
8903 : else
8904 : {
8905 147 : dw_die_ref parent = unit;
8906 147 : dw_die_ref copy = clone_die (targ);
8907 :
8908 : /* Record in DECL_TABLE that TARG has been copied.
8909 : Need to do this now, before the recursive call,
8910 : because DECL_TABLE may be expanded and SLOT
8911 : would no longer be a valid pointer. */
8912 147 : entry = XCNEW (struct decl_table_entry);
8913 147 : entry->orig = targ;
8914 147 : entry->copy = copy;
8915 147 : *slot = entry;
8916 :
8917 : /* If TARG is not a declaration DIE, we need to copy its
8918 : children. */
8919 147 : if (!is_declaration_die (targ))
8920 : {
8921 144 : FOR_EACH_CHILD (
8922 : targ, c,
8923 : add_child_die (copy,
8924 : clone_tree_partial (c, decl_table)));
8925 : }
8926 :
8927 : /* Make sure the cloned tree is marked as part of the
8928 : type unit. */
8929 147 : mark_dies (copy);
8930 :
8931 : /* If TARG has surrounding context, copy its ancestor tree
8932 : into the new type unit. */
8933 147 : if (targ->die_parent != NULL
8934 147 : && !is_unit_die (targ->die_parent))
8935 9 : parent = copy_ancestor_tree (unit, targ->die_parent,
8936 : decl_table);
8937 :
8938 147 : add_child_die (parent, copy);
8939 147 : a->dw_attr_val.v.val_die_ref.die = copy;
8940 :
8941 : /* Make sure the newly-copied DIE is walked. If it was
8942 : installed in a previously-added context, it won't
8943 : get visited otherwise. */
8944 147 : if (parent != unit)
8945 : {
8946 : /* Find the highest point of the newly-added tree,
8947 : mark each node along the way, and walk from there. */
8948 9 : parent->die_mark = 1;
8949 9 : while (parent->die_parent
8950 9 : && parent->die_parent->die_mark == 0)
8951 : {
8952 0 : parent = parent->die_parent;
8953 0 : parent->die_mark = 1;
8954 : }
8955 9 : copy_decls_walk (unit, parent, decl_table);
8956 : }
8957 : }
8958 : }
8959 : }
8960 :
8961 2678 : FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
8962 1712 : }
8963 :
8964 : /* Collect skeleton dies in DIE created by break_out_comdat_types already
8965 : and record them in DECL_TABLE. */
8966 :
8967 : static void
8968 1533 : collect_skeleton_dies (dw_die_ref die, decl_hash_type *decl_table)
8969 : {
8970 1533 : dw_die_ref c;
8971 :
8972 1533 : if (dw_attr_node *a = get_AT (die, DW_AT_signature))
8973 : {
8974 63 : dw_die_ref targ = AT_ref (a);
8975 63 : gcc_assert (targ->die_mark == 0 && targ->comdat_type_p);
8976 63 : decl_table_entry **slot
8977 63 : = decl_table->find_slot_with_hash (targ,
8978 : htab_hash_pointer (targ),
8979 : INSERT);
8980 63 : gcc_assert (*slot == HTAB_EMPTY_ENTRY);
8981 : /* Record in DECL_TABLE that TARG has been already copied
8982 : by remove_child_or_replace_with_skeleton. */
8983 63 : decl_table_entry *entry = XCNEW (struct decl_table_entry);
8984 63 : entry->orig = targ;
8985 63 : entry->copy = die;
8986 63 : *slot = entry;
8987 : }
8988 2949 : FOR_EACH_CHILD (die, c, collect_skeleton_dies (c, decl_table));
8989 1533 : }
8990 :
8991 : /* Copy declarations for "unworthy" types into the new comdat section.
8992 : Incomplete types, modified types, and certain other types aren't broken
8993 : out into comdat sections of their own, so they don't have a signature,
8994 : and we need to copy the declaration into the same section so that we
8995 : don't have an external reference. */
8996 :
8997 : static void
8998 117 : copy_decls_for_unworthy_types (dw_die_ref unit)
8999 : {
9000 117 : mark_dies (unit);
9001 117 : decl_hash_type decl_table (10);
9002 117 : collect_skeleton_dies (unit, &decl_table);
9003 117 : copy_decls_walk (unit, unit, &decl_table);
9004 117 : unmark_dies (unit);
9005 117 : }
9006 :
9007 : /* Traverse the DIE and add a sibling attribute if it may have the
9008 : effect of speeding up access to siblings. To save some space,
9009 : avoid generating sibling attributes for DIE's without children. */
9010 :
9011 : static void
9012 78904675 : add_sibling_attributes (dw_die_ref die)
9013 : {
9014 78904675 : dw_die_ref c;
9015 :
9016 78904675 : if (! die->die_child)
9017 : return;
9018 :
9019 20663817 : if (die->die_parent && die != die->die_parent->die_child)
9020 15800265 : add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
9021 :
9022 78851185 : FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
9023 : }
9024 :
9025 : /* Output all location lists for the DIE and its children. */
9026 :
9027 : static void
9028 72036785 : output_location_lists (dw_die_ref die)
9029 : {
9030 72036785 : dw_die_ref c;
9031 72036785 : dw_attr_node *a;
9032 72036785 : unsigned ix;
9033 :
9034 354682569 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9035 282645784 : if (AT_class (a) == dw_val_class_loc_list)
9036 11315230 : output_loc_list (AT_loc_list (a));
9037 :
9038 144040901 : FOR_EACH_CHILD (die, c, output_location_lists (c));
9039 72036785 : }
9040 :
9041 : /* During assign_location_list_indexes and output_loclists_offset the
9042 : current index, after it the number of assigned indexes (i.e. how
9043 : large the .debug_loclists* offset table should be). */
9044 : static unsigned int loc_list_idx;
9045 :
9046 : /* Output all location list offsets for the DIE and its children. */
9047 :
9048 : static void
9049 26 : output_loclists_offsets (dw_die_ref die)
9050 : {
9051 26 : dw_die_ref c;
9052 26 : dw_attr_node *a;
9053 26 : unsigned ix;
9054 :
9055 155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9056 129 : if (AT_class (a) == dw_val_class_loc_list)
9057 : {
9058 2 : dw_loc_list_ref l = AT_loc_list (a);
9059 2 : if (l->offset_emitted)
9060 0 : continue;
9061 2 : dw2_asm_output_delta (dwarf_offset_size, l->ll_symbol,
9062 : loc_section_label, NULL);
9063 2 : gcc_assert (l->hash == loc_list_idx);
9064 2 : loc_list_idx++;
9065 2 : l->offset_emitted = true;
9066 : }
9067 :
9068 50 : FOR_EACH_CHILD (die, c, output_loclists_offsets (c));
9069 26 : }
9070 :
9071 : /* Recursively set indexes of location lists. */
9072 :
9073 : static void
9074 26 : assign_location_list_indexes (dw_die_ref die)
9075 : {
9076 26 : dw_die_ref c;
9077 26 : dw_attr_node *a;
9078 26 : unsigned ix;
9079 :
9080 155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9081 129 : if (AT_class (a) == dw_val_class_loc_list)
9082 : {
9083 2 : dw_loc_list_ref list = AT_loc_list (a);
9084 2 : if (!list->num_assigned)
9085 : {
9086 2 : list->num_assigned = true;
9087 2 : list->hash = loc_list_idx++;
9088 : }
9089 : }
9090 :
9091 50 : FOR_EACH_CHILD (die, c, assign_location_list_indexes (c));
9092 26 : }
9093 :
9094 : /* We want to limit the number of external references, because they are
9095 : larger than local references: a relocation takes multiple words, and
9096 : even a sig8 reference is always eight bytes, whereas a local reference
9097 : can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
9098 : So if we encounter multiple external references to the same type DIE, we
9099 : make a local typedef stub for it and redirect all references there.
9100 :
9101 : This is the element of the hash table for keeping track of these
9102 : references. */
9103 :
9104 : struct external_ref
9105 : {
9106 : dw_die_ref type;
9107 : dw_die_ref stub;
9108 : unsigned n_refs;
9109 : };
9110 :
9111 : /* Hashtable helpers. */
9112 :
9113 : struct external_ref_hasher : free_ptr_hash <external_ref>
9114 : {
9115 : static inline hashval_t hash (const external_ref *);
9116 : static inline bool equal (const external_ref *, const external_ref *);
9117 : };
9118 :
9119 : inline hashval_t
9120 1373 : external_ref_hasher::hash (const external_ref *r)
9121 : {
9122 1373 : dw_die_ref die = r->type;
9123 1373 : hashval_t h = 0;
9124 :
9125 : /* We can't use the address of the DIE for hashing, because
9126 : that will make the order of the stub DIEs non-deterministic. */
9127 1373 : if (! die->comdat_type_p)
9128 : /* We have a symbol; use it to compute a hash. */
9129 0 : h = htab_hash_string (die->die_id.die_symbol);
9130 : else
9131 : {
9132 : /* We have a type signature; use a subset of the bits as the hash.
9133 : The 8-byte signature is at least as large as hashval_t. */
9134 1373 : comdat_type_node *type_node = die->die_id.die_type_node;
9135 1373 : memcpy (&h, type_node->signature, sizeof (h));
9136 : }
9137 1373 : return h;
9138 : }
9139 :
9140 : inline bool
9141 1031 : external_ref_hasher::equal (const external_ref *r1, const external_ref *r2)
9142 : {
9143 1031 : return r1->type == r2->type;
9144 : }
9145 :
9146 : typedef hash_table<external_ref_hasher> external_ref_hash_type;
9147 :
9148 : /* Return a pointer to the external_ref for references to DIE. */
9149 :
9150 : static struct external_ref *
9151 493 : lookup_external_ref (external_ref_hash_type *map, dw_die_ref die)
9152 : {
9153 493 : struct external_ref ref, *ref_p;
9154 493 : external_ref **slot;
9155 :
9156 493 : ref.type = die;
9157 493 : slot = map->find_slot (&ref, INSERT);
9158 493 : if (*slot != HTAB_EMPTY_ENTRY)
9159 : return *slot;
9160 :
9161 88 : ref_p = XCNEW (struct external_ref);
9162 88 : ref_p->type = die;
9163 88 : *slot = ref_p;
9164 88 : return ref_p;
9165 : }
9166 :
9167 : /* Subroutine of optimize_external_refs, below.
9168 :
9169 : If we see a type skeleton, record it as our stub. If we see external
9170 : references, remember how many we've seen. */
9171 :
9172 : static void
9173 78903615 : optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
9174 : {
9175 78903615 : dw_die_ref c;
9176 78903615 : dw_attr_node *a;
9177 78903615 : unsigned ix;
9178 78903615 : struct external_ref *ref_p;
9179 :
9180 78903615 : if (is_type_die (die)
9181 78903615 : && (c = get_AT_ref (die, DW_AT_signature)))
9182 : {
9183 : /* This is a local skeleton; use it for local references. */
9184 51 : ref_p = lookup_external_ref (map, c);
9185 51 : ref_p->stub = die;
9186 : }
9187 :
9188 : /* Scan the DIE references, and remember any that refer to DIEs from
9189 : other CUs (i.e. those which are not marked). */
9190 389106155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9191 310202540 : if (AT_class (a) == dw_val_class_die_ref
9192 90668795 : && (c = AT_ref (a))->die_mark == 0
9193 310232326 : && is_type_die (c))
9194 : {
9195 215 : ref_p = lookup_external_ref (map, c);
9196 215 : ref_p->n_refs++;
9197 : }
9198 :
9199 137090973 : FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
9200 78903615 : }
9201 :
9202 : /* htab_traverse callback function for optimize_external_refs, below. SLOT
9203 : points to an external_ref, DATA is the CU we're processing. If we don't
9204 : already have a local stub, and we have multiple refs, build a stub. */
9205 :
9206 : int
9207 88 : dwarf2_build_local_stub (external_ref **slot, dw_die_ref data)
9208 : {
9209 88 : struct external_ref *ref_p = *slot;
9210 :
9211 88 : if (ref_p->stub == NULL && ref_p->n_refs > 1 && !dwarf_strict)
9212 : {
9213 : /* We have multiple references to this type, so build a small stub.
9214 : Both of these forms are a bit dodgy from the perspective of the
9215 : DWARF standard, since technically they should have names. */
9216 12 : dw_die_ref cu = data;
9217 12 : dw_die_ref type = ref_p->type;
9218 12 : dw_die_ref stub = NULL;
9219 :
9220 12 : if (type->comdat_type_p)
9221 : {
9222 : /* If we refer to this type via sig8, use AT_signature. */
9223 12 : stub = new_die (type->die_tag, cu, NULL_TREE);
9224 12 : add_AT_die_ref (stub, DW_AT_signature, type);
9225 : }
9226 : else
9227 : {
9228 : /* Otherwise, use a typedef with no name. */
9229 0 : stub = new_die (DW_TAG_typedef, cu, NULL_TREE);
9230 0 : add_AT_die_ref (stub, DW_AT_type, type);
9231 : }
9232 :
9233 12 : stub->die_mark++;
9234 12 : ref_p->stub = stub;
9235 : }
9236 88 : return 1;
9237 : }
9238 :
9239 : /* DIE is a unit; look through all the DIE references to see if there are
9240 : any external references to types, and if so, create local stubs for
9241 : them which will be applied in build_abbrev_table. This is useful because
9242 : references to local DIEs are smaller. */
9243 :
9244 : static external_ref_hash_type *
9245 52446 : optimize_external_refs (dw_die_ref die)
9246 : {
9247 52446 : external_ref_hash_type *map = new external_ref_hash_type (10);
9248 52446 : optimize_external_refs_1 (die, map);
9249 52534 : map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
9250 52446 : return map;
9251 : }
9252 :
9253 : /* The following 3 variables are temporaries that are computed only during the
9254 : build_abbrev_table call and used and released during the following
9255 : optimize_abbrev_table call. */
9256 :
9257 : /* First abbrev_id that can be optimized based on usage. */
9258 : static unsigned int abbrev_opt_start;
9259 :
9260 : /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
9261 : abbrev_id smaller than this, because they must be already sized
9262 : during build_abbrev_table). */
9263 : static unsigned int abbrev_opt_base_type_end;
9264 :
9265 : /* Vector of usage counts during build_abbrev_table. Indexed by
9266 : abbrev_id - abbrev_opt_start. */
9267 : static vec<unsigned int> abbrev_usage_count;
9268 :
9269 : /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
9270 : static vec<dw_die_ref> sorted_abbrev_dies;
9271 :
9272 : /* The format of each DIE (and its attribute value pairs) is encoded in an
9273 : abbreviation table. This routine builds the abbreviation table and assigns
9274 : a unique abbreviation id for each abbreviation entry. The children of each
9275 : die are visited recursively. */
9276 :
9277 : static void
9278 78903627 : build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
9279 : {
9280 78903627 : unsigned int abbrev_id = 0;
9281 78903627 : dw_die_ref c;
9282 78903627 : dw_attr_node *a;
9283 78903627 : unsigned ix;
9284 78903627 : dw_die_ref abbrev;
9285 :
9286 : /* Scan the DIE references, and replace any that refer to
9287 : DIEs from other CUs (i.e. those which are not marked) with
9288 : the local stubs we built in optimize_external_refs. */
9289 389106179 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9290 310202552 : if (AT_class (a) == dw_val_class_die_ref
9291 310202552 : && (c = AT_ref (a))->die_mark == 0)
9292 : {
9293 29798 : struct external_ref *ref_p;
9294 29798 : gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
9295 :
9296 29798 : if (is_type_die (c)
9297 227 : && (ref_p = lookup_external_ref (extern_map, c))
9298 30025 : && ref_p->stub && ref_p->stub != die)
9299 : {
9300 139 : gcc_assert (a->dw_attr != DW_AT_signature);
9301 139 : change_AT_die_ref (a, ref_p->stub);
9302 : }
9303 : else
9304 : /* We aren't changing this reference, so mark it external. */
9305 29659 : set_AT_ref_external (a, 1);
9306 : }
9307 :
9308 8349188227 : FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
9309 : {
9310 8346386656 : dw_attr_node *die_a, *abbrev_a;
9311 8346386656 : unsigned ix;
9312 8346386656 : bool ok = true;
9313 :
9314 8346386656 : if (abbrev_id == 0)
9315 78903627 : continue;
9316 8267483029 : if (abbrev->die_tag != die->die_tag)
9317 7656664487 : continue;
9318 610818542 : if ((abbrev->die_child != NULL) != (die->die_child != NULL))
9319 40690449 : continue;
9320 :
9321 1709411629 : if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
9322 429777483 : continue;
9323 :
9324 584893170 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
9325 : {
9326 508791114 : abbrev_a = &(*abbrev->die_attr)[ix];
9327 508791114 : if ((abbrev_a->dw_attr != die_a->dw_attr)
9328 508791114 : || (value_format (abbrev_a) != value_format (die_a)))
9329 : {
9330 : ok = false;
9331 : break;
9332 : }
9333 : }
9334 140350610 : if (ok)
9335 : break;
9336 : }
9337 :
9338 78903627 : if (abbrev_id >= vec_safe_length (abbrev_die_table))
9339 : {
9340 2801571 : vec_safe_push (abbrev_die_table, die);
9341 2801571 : if (abbrev_opt_start)
9342 2801201 : abbrev_usage_count.safe_push (0);
9343 : }
9344 78903627 : if (abbrev_opt_start && abbrev_id >= abbrev_opt_start)
9345 : {
9346 78875534 : abbrev_usage_count[abbrev_id - abbrev_opt_start]++;
9347 78875534 : sorted_abbrev_dies.safe_push (die);
9348 : }
9349 :
9350 78903627 : die->die_abbrev = abbrev_id;
9351 137090997 : FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
9352 78903627 : }
9353 :
9354 : /* Callback function for sorted_abbrev_dies vector sorting. We sort
9355 : by die_abbrev's usage count, from the most commonly used
9356 : abbreviation to the least. */
9357 :
9358 : static int
9359 4915952111 : die_abbrev_cmp (const void *p1, const void *p2)
9360 : {
9361 4915952111 : dw_die_ref die1 = *(const dw_die_ref *) p1;
9362 4915952111 : dw_die_ref die2 = *(const dw_die_ref *) p2;
9363 :
9364 4915952111 : gcc_checking_assert (die1->die_abbrev >= abbrev_opt_start);
9365 4915952111 : gcc_checking_assert (die2->die_abbrev >= abbrev_opt_start);
9366 :
9367 4915952111 : if (die1->die_abbrev >= abbrev_opt_base_type_end
9368 4915952111 : && die2->die_abbrev >= abbrev_opt_base_type_end)
9369 : {
9370 4915952111 : if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
9371 4915952111 : > abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
9372 : return -1;
9373 2768422724 : if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
9374 2768422724 : < abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
9375 : return 1;
9376 : }
9377 :
9378 : /* Stabilize the sort. */
9379 983572155 : if (die1->die_abbrev < die2->die_abbrev)
9380 : return -1;
9381 833200765 : if (die1->die_abbrev > die2->die_abbrev)
9382 153221681 : return 1;
9383 :
9384 : return 0;
9385 : }
9386 :
9387 : /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
9388 : of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
9389 : into dw_val_class_const_implicit or
9390 : dw_val_class_unsigned_const_implicit. */
9391 :
9392 : static void
9393 2778355 : optimize_implicit_const (unsigned int first_id, unsigned int end,
9394 : vec<bool> &implicit_consts)
9395 : {
9396 : /* It never makes sense if there is just one DIE using the abbreviation. */
9397 2778355 : if (end < first_id + 2)
9398 2778355 : return;
9399 :
9400 1679675 : dw_attr_node *a;
9401 1679675 : unsigned ix, i;
9402 1679675 : dw_die_ref die = sorted_abbrev_dies[first_id];
9403 10944159 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9404 9264484 : if (implicit_consts[ix])
9405 : {
9406 1144793 : enum dw_val_class new_class = dw_val_class_none;
9407 1144793 : switch (AT_class (a))
9408 : {
9409 733537 : case dw_val_class_unsigned_const:
9410 733537 : if ((HOST_WIDE_INT) AT_unsigned (a) < 0)
9411 979 : continue;
9412 :
9413 : /* The .debug_abbrev section will grow by
9414 : size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
9415 : in all the DIEs using that abbreviation. */
9416 732558 : if (constant_size (AT_unsigned (a)) * (end - first_id)
9417 732558 : <= (unsigned) size_of_sleb128 (AT_unsigned (a)))
9418 13033 : continue;
9419 :
9420 : new_class = dw_val_class_unsigned_const_implicit;
9421 : break;
9422 :
9423 : case dw_val_class_const:
9424 : new_class = dw_val_class_const_implicit;
9425 : break;
9426 :
9427 409319 : case dw_val_class_file:
9428 409319 : new_class = dw_val_class_file_implicit;
9429 409319 : break;
9430 :
9431 0 : default:
9432 0 : continue;
9433 : }
9434 13559894 : for (i = first_id; i < end; i++)
9435 12429113 : (*sorted_abbrev_dies[i]->die_attr)[ix].dw_attr_val.val_class
9436 24858226 : = new_class;
9437 : }
9438 : }
9439 :
9440 : /* Attempt to optimize abbreviation table from abbrev_opt_start
9441 : abbreviation above. */
9442 :
9443 : static void
9444 52365 : optimize_abbrev_table (void)
9445 : {
9446 52365 : if (abbrev_opt_start
9447 52365 : && vec_safe_length (abbrev_die_table) > abbrev_opt_start
9448 104658 : && (dwarf_version >= 5 || vec_safe_length (abbrev_die_table) > 127))
9449 : {
9450 50325 : auto_vec<bool, 32> implicit_consts;
9451 50325 : sorted_abbrev_dies.qsort (die_abbrev_cmp);
9452 :
9453 50325 : unsigned int abbrev_id = abbrev_opt_start - 1;
9454 50325 : unsigned int first_id = ~0U;
9455 50325 : unsigned int last_abbrev_id = 0;
9456 50325 : unsigned int i;
9457 50325 : dw_die_ref die;
9458 50325 : if (abbrev_opt_base_type_end > abbrev_opt_start)
9459 0 : abbrev_id = abbrev_opt_base_type_end - 1;
9460 : /* Reassign abbreviation ids from abbrev_opt_start above, so that
9461 : most commonly used abbreviations come first. */
9462 78874049 : FOR_EACH_VEC_ELT (sorted_abbrev_dies, i, die)
9463 : {
9464 78823724 : dw_attr_node *a;
9465 78823724 : unsigned ix;
9466 :
9467 : /* If calc_base_type_die_sizes has been called, the CU and
9468 : base types after it can't be optimized, because we've already
9469 : calculated their DIE offsets. We've sorted them first. */
9470 78823724 : if (die->die_abbrev < abbrev_opt_base_type_end)
9471 0 : continue;
9472 78823724 : if (die->die_abbrev != last_abbrev_id)
9473 : {
9474 2778355 : last_abbrev_id = die->die_abbrev;
9475 2778355 : if (dwarf_version >= 5 && first_id != ~0U)
9476 2728030 : optimize_implicit_const (first_id, i, implicit_consts);
9477 2778355 : abbrev_id++;
9478 2778355 : (*abbrev_die_table)[abbrev_id] = die;
9479 2778355 : if (dwarf_version >= 5)
9480 : {
9481 2778355 : first_id = i;
9482 2778355 : implicit_consts.truncate (0);
9483 :
9484 21223309 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9485 15666599 : switch (AT_class (a))
9486 : {
9487 6619411 : case dw_val_class_const:
9488 6619411 : case dw_val_class_unsigned_const:
9489 6619411 : case dw_val_class_file:
9490 6619411 : implicit_consts.safe_push (true);
9491 6619411 : break;
9492 9047188 : default:
9493 9047188 : implicit_consts.safe_push (false);
9494 9047188 : break;
9495 : }
9496 : }
9497 : }
9498 76045369 : else if (dwarf_version >= 5)
9499 : {
9500 370237463 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9501 294192094 : if (!implicit_consts[ix])
9502 274287508 : continue;
9503 : else
9504 : {
9505 19904586 : dw_attr_node *other_a
9506 19904586 : = &(*(*abbrev_die_table)[abbrev_id]->die_attr)[ix];
9507 19904586 : if (!dw_val_equal_p (&a->dw_attr_val,
9508 : &other_a->dw_attr_val))
9509 2746134 : implicit_consts[ix] = false;
9510 : }
9511 : }
9512 78823724 : die->die_abbrev = abbrev_id;
9513 : }
9514 100650 : gcc_assert (abbrev_id == vec_safe_length (abbrev_die_table) - 1);
9515 50325 : if (dwarf_version >= 5 && first_id != ~0U)
9516 50325 : optimize_implicit_const (first_id, i, implicit_consts);
9517 50325 : }
9518 :
9519 52365 : abbrev_opt_start = 0;
9520 52365 : abbrev_opt_base_type_end = 0;
9521 52365 : abbrev_usage_count.release ();
9522 52365 : sorted_abbrev_dies.release ();
9523 52365 : }
9524 :
9525 : /* Return the power-of-two number of bytes necessary to represent VALUE. */
9526 :
9527 : static int
9528 539967028 : constant_size (unsigned HOST_WIDE_INT value)
9529 : {
9530 539967028 : int log;
9531 :
9532 539967028 : if (value == 0)
9533 : log = 0;
9534 : else
9535 532249510 : log = floor_log2 (value);
9536 :
9537 1072216538 : log = log / 8;
9538 532249510 : log = 1 << (floor_log2 (log) + 1);
9539 :
9540 539967028 : return log;
9541 : }
9542 :
9543 : /* Return the size of a DIE as it is represented in the
9544 : .debug_info section. */
9545 :
9546 : static unsigned long
9547 78903894 : size_of_die (dw_die_ref die)
9548 : {
9549 78903894 : unsigned long size = 0;
9550 78903894 : dw_attr_node *a;
9551 78903894 : unsigned ix;
9552 78903894 : enum dwarf_form form;
9553 :
9554 78903894 : size += size_of_uleb128 (die->die_abbrev);
9555 389108277 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9556 : {
9557 310204383 : switch (AT_class (a))
9558 : {
9559 28600 : case dw_val_class_addr:
9560 28600 : if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
9561 : {
9562 0 : gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
9563 0 : size += size_of_uleb128 (AT_index (a));
9564 : }
9565 : else
9566 31640 : size += DWARF2_ADDR_SIZE;
9567 : break;
9568 0 : case dw_val_class_offset:
9569 0 : size += dwarf_offset_size;
9570 0 : break;
9571 7520231 : case dw_val_class_loc:
9572 7520231 : {
9573 7520231 : unsigned long lsize = size_of_locs (AT_loc (a));
9574 :
9575 : /* Block length. */
9576 7520231 : if (dwarf_version >= 4)
9577 7509292 : size += size_of_uleb128 (lsize);
9578 : else
9579 10939 : size += constant_size (lsize);
9580 7520231 : size += lsize;
9581 : }
9582 7520231 : break;
9583 11315230 : case dw_val_class_loc_list:
9584 11315230 : if (dwarf_split_debug_info && dwarf_version >= 5)
9585 : {
9586 2 : gcc_assert (AT_loc_list (a)->num_assigned);
9587 2 : size += size_of_uleb128 (AT_loc_list (a)->hash);
9588 : }
9589 : else
9590 11315228 : size += dwarf_offset_size;
9591 : break;
9592 11139022 : case dw_val_class_view_list:
9593 11139022 : size += dwarf_offset_size;
9594 11139022 : break;
9595 3212567 : case dw_val_class_range_list:
9596 3212567 : if (value_format (a) == DW_FORM_rnglistx)
9597 : {
9598 3 : gcc_assert (rnglist_idx);
9599 3 : dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
9600 3 : size += size_of_uleb128 (r->idx);
9601 : }
9602 : else
9603 3212564 : size += dwarf_offset_size;
9604 : break;
9605 14852 : case dw_val_class_const:
9606 14852 : size += size_of_sleb128 (AT_int (a));
9607 14852 : break;
9608 66151725 : case dw_val_class_unsigned_const:
9609 66151725 : {
9610 66151725 : int csize = constant_size (AT_unsigned (a));
9611 66151725 : if (dwarf_version == 3
9612 690 : && a->dw_attr == DW_AT_data_member_location
9613 15 : && csize >= 4)
9614 1 : size += size_of_uleb128 (AT_unsigned (a));
9615 : else
9616 66151724 : size += csize;
9617 : }
9618 : break;
9619 6211432 : case dw_val_class_symview:
9620 6211432 : if (symview_upper_bound <= 0xff)
9621 338026 : size += 1;
9622 5873406 : else if (symview_upper_bound <= 0xffff)
9623 5873406 : size += 2;
9624 0 : else if (symview_upper_bound <= 0xffffffff)
9625 0 : size += 4;
9626 : else
9627 : size += 8;
9628 : break;
9629 : case dw_val_class_const_implicit:
9630 : case dw_val_class_unsigned_const_implicit:
9631 : case dw_val_class_file_implicit:
9632 : /* These occupy no size in the DIE, just an extra sleb128 in
9633 : .debug_abbrev. */
9634 : break;
9635 0 : case dw_val_class_const_double:
9636 0 : size += HOST_BITS_PER_DOUBLE_INT / HOST_BITS_PER_CHAR;
9637 0 : if (HOST_BITS_PER_WIDE_INT >= DWARF_LARGEST_DATA_FORM_BITS)
9638 0 : size++; /* block */
9639 : break;
9640 37 : case dw_val_class_wide_int:
9641 37 : size += (get_full_len (*a->dw_attr_val.v.val_wide)
9642 37 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
9643 37 : if (get_full_len (*a->dw_attr_val.v.val_wide)
9644 37 : * HOST_BITS_PER_WIDE_INT > DWARF_LARGEST_DATA_FORM_BITS)
9645 0 : size++; /* block */
9646 : break;
9647 16472 : case dw_val_class_vec:
9648 16472 : size += constant_size (a->dw_attr_val.v.val_vec.length
9649 16472 : * a->dw_attr_val.v.val_vec.elt_size)
9650 16472 : + a->dw_attr_val.v.val_vec.length
9651 : * a->dw_attr_val.v.val_vec.elt_size; /* block */
9652 16472 : break;
9653 25602666 : case dw_val_class_flag:
9654 25602666 : if (dwarf_version >= 4)
9655 : /* Currently all add_AT_flag calls pass in 1 as last argument,
9656 : so DW_FORM_flag_present can be used. If that ever changes,
9657 : we'll need to use DW_FORM_flag and have some optimization
9658 : in build_abbrev_table that will change those to
9659 : DW_FORM_flag_present if it is set to 1 in all DIEs using
9660 : the same abbrev entry. */
9661 25581464 : gcc_assert (a->dw_attr_val.v.val_flag == 1);
9662 : else
9663 21202 : size += 1;
9664 : break;
9665 90668807 : case dw_val_class_die_ref:
9666 90668807 : if (AT_ref_external (a))
9667 : {
9668 : /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9669 : we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9670 : is sized by target address length, whereas in DWARF3
9671 : it's always sized as an offset. */
9672 29659 : if (AT_ref (a)->comdat_type_p)
9673 88 : size += DWARF_TYPE_SIGNATURE_SIZE;
9674 29571 : else if (dwarf_version == 2)
9675 30 : size += DWARF2_ADDR_SIZE;
9676 : else
9677 29541 : size += dwarf_offset_size;
9678 : }
9679 : else
9680 90639148 : size += dwarf_offset_size;
9681 : break;
9682 0 : case dw_val_class_fde_ref:
9683 0 : size += dwarf_offset_size;
9684 0 : break;
9685 13528355 : case dw_val_class_lbl_id:
9686 13528355 : if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
9687 : {
9688 253 : gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
9689 253 : size += size_of_uleb128 (AT_index (a));
9690 : }
9691 : else
9692 14666860 : size += DWARF2_ADDR_SIZE;
9693 : break;
9694 53229 : case dw_val_class_lineptr:
9695 53229 : case dw_val_class_macptr:
9696 53229 : case dw_val_class_loclistsptr:
9697 53229 : size += dwarf_offset_size;
9698 53229 : break;
9699 32620872 : case dw_val_class_str:
9700 32620872 : form = AT_string_form (a);
9701 32620872 : if (form == DW_FORM_strp || form == DW_FORM_line_strp)
9702 29516596 : size += dwarf_offset_size;
9703 3118461 : else if (form == dwarf_FORM (DW_FORM_strx))
9704 935 : size += size_of_uleb128 (AT_index (a));
9705 : else
9706 3103341 : size += strlen (a->dw_attr_val.v.val_str->str) + 1;
9707 : break;
9708 25275565 : case dw_val_class_file:
9709 25275565 : size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
9710 25275565 : break;
9711 71 : case dw_val_class_data8:
9712 71 : size += 8;
9713 71 : break;
9714 0 : case dw_val_class_vms_delta:
9715 0 : size += dwarf_offset_size;
9716 0 : break;
9717 4407151 : case dw_val_class_high_pc:
9718 4407151 : size += DWARF2_ADDR_SIZE;
9719 4407151 : break;
9720 0 : case dw_val_class_discr_value:
9721 0 : size += size_of_discr_value (&a->dw_attr_val.v.val_discr_value);
9722 0 : break;
9723 0 : case dw_val_class_discr_list:
9724 0 : {
9725 0 : unsigned block_size = size_of_discr_list (AT_discr_list (a));
9726 :
9727 : /* This is a block, so we have the block length and then its
9728 : data. */
9729 0 : size += constant_size (block_size) + block_size;
9730 : }
9731 0 : break;
9732 0 : default:
9733 0 : gcc_unreachable ();
9734 : }
9735 : }
9736 :
9737 78903894 : return size;
9738 : }
9739 :
9740 : /* Size the debugging information associated with a given DIE. Visits the
9741 : DIE's children recursively. Updates the global variable next_die_offset, on
9742 : each time through. Uses the current value of next_die_offset to update the
9743 : die_offset field in each DIE. */
9744 :
9745 : static void
9746 78903627 : calc_die_sizes (dw_die_ref die)
9747 : {
9748 78903627 : dw_die_ref c;
9749 :
9750 78903627 : gcc_assert (die->die_offset == 0
9751 : || (unsigned long int) die->die_offset == next_die_offset);
9752 78903627 : die->die_offset = next_die_offset;
9753 78903627 : next_die_offset += size_of_die (die);
9754 :
9755 157754808 : FOR_EACH_CHILD (die, c, calc_die_sizes (c));
9756 :
9757 78903627 : if (die->die_child != NULL)
9758 : /* Count the null byte used to terminate sibling lists. */
9759 20663811 : next_die_offset += 1;
9760 78903627 : }
9761 :
9762 : /* Size just the base type children at the start of the CU.
9763 : This is needed because build_abbrev needs to size locs
9764 : and sizing of type based stack ops needs to know die_offset
9765 : values for the base types. */
9766 :
9767 : static void
9768 9 : calc_base_type_die_sizes (void)
9769 : {
9770 18 : unsigned long die_offset = (dwarf_split_debug_info
9771 9 : ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9772 18 : : DWARF_COMPILE_UNIT_HEADER_SIZE);
9773 9 : unsigned int i;
9774 9 : dw_die_ref base_type;
9775 : #if ENABLE_ASSERT_CHECKING
9776 9 : dw_die_ref prev = comp_unit_die ()->die_child;
9777 : #endif
9778 :
9779 9 : die_offset += size_of_die (comp_unit_die ());
9780 18 : for (i = 0; base_types.iterate (i, &base_type); i++)
9781 : {
9782 : #if ENABLE_ASSERT_CHECKING
9783 9 : gcc_assert (base_type->die_offset == 0
9784 : && prev->die_sib == base_type
9785 : && base_type->die_child == NULL
9786 : && base_type->die_abbrev);
9787 9 : prev = base_type;
9788 : #endif
9789 9 : if (abbrev_opt_start
9790 9 : && base_type->die_abbrev >= abbrev_opt_base_type_end)
9791 9 : abbrev_opt_base_type_end = base_type->die_abbrev + 1;
9792 9 : base_type->die_offset = die_offset;
9793 9 : die_offset += size_of_die (base_type);
9794 : }
9795 9 : }
9796 :
9797 : /* Set the marks for a die and its children. We do this so
9798 : that we know whether or not a reference needs to use FORM_ref_addr; only
9799 : DIEs in the same CU will be marked. We used to clear out the offset
9800 : and use that as the flag, but ran into ordering problems. */
9801 :
9802 : static void
9803 78905303 : mark_dies (dw_die_ref die)
9804 : {
9805 78905303 : dw_die_ref c;
9806 :
9807 78905303 : gcc_assert (!die->die_mark);
9808 :
9809 78905303 : die->die_mark = 1;
9810 157757896 : FOR_EACH_CHILD (die, c, mark_dies (c));
9811 78905303 : }
9812 :
9813 : /* Clear the marks for a die and its children. */
9814 :
9815 : static void
9816 236887 : unmark_dies (dw_die_ref die)
9817 : {
9818 236887 : dw_die_ref c;
9819 :
9820 236887 : if (! use_debug_types)
9821 234484 : gcc_assert (die->die_mark);
9822 :
9823 236887 : die->die_mark = 0;
9824 472249 : FOR_EACH_CHILD (die, c, unmark_dies (c));
9825 236887 : }
9826 :
9827 : /* Clear the marks for a die, its children and referred dies. */
9828 :
9829 : static void
9830 530462 : unmark_all_dies (dw_die_ref die)
9831 : {
9832 530462 : dw_die_ref c;
9833 530462 : dw_attr_node *a;
9834 530462 : unsigned ix;
9835 :
9836 530462 : if (!die->die_mark)
9837 530462 : return;
9838 235596 : die->die_mark = 0;
9839 :
9840 409230 : FOR_EACH_CHILD (die, c, unmark_all_dies (c));
9841 :
9842 1160555 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9843 924959 : if (AT_class (a) == dw_val_class_die_ref)
9844 294857 : unmark_all_dies (AT_ref (a));
9845 : }
9846 :
9847 : /* Calculate if the entry should appear in the final output file. It may be
9848 : from a pruned a type. */
9849 :
9850 : static bool
9851 1724 : include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
9852 : {
9853 : /* By limiting gnu pubnames to definitions only, gold can generate a
9854 : gdb index without entries for declarations, which don't include
9855 : enough information to be useful. */
9856 1724 : if (debug_generate_pub_sections == 2 && is_declaration_die (p->die))
9857 : return false;
9858 :
9859 1594 : if (table == pubname_table)
9860 : {
9861 : /* Enumerator names are part of the pubname table, but the
9862 : parent DW_TAG_enumeration_type die may have been pruned.
9863 : Don't output them if that is the case. */
9864 1014 : if (p->die->die_tag == DW_TAG_enumerator &&
9865 72 : (p->die->die_parent == NULL
9866 72 : || !p->die->die_parent->die_perennial_p))
9867 : return false;
9868 :
9869 : /* Everything else in the pubname table is included. */
9870 : return true;
9871 : }
9872 :
9873 : /* The pubtypes table shouldn't include types that have been
9874 : pruned. */
9875 580 : return (p->die->die_offset != 0
9876 580 : || !flag_eliminate_unused_debug_types);
9877 : }
9878 :
9879 : /* Return the size of the .debug_pubnames or .debug_pubtypes table
9880 : generated for the compilation unit. */
9881 :
9882 : static unsigned long
9883 512 : size_of_pubnames (vec<pubname_entry, va_gc> *names)
9884 : {
9885 512 : unsigned long size;
9886 512 : unsigned i;
9887 512 : pubname_entry *p;
9888 512 : int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0;
9889 :
9890 512 : size = DWARF_PUBNAMES_HEADER_SIZE;
9891 1374 : FOR_EACH_VEC_ELT (*names, i, p)
9892 862 : if (include_pubname_in_output (names, p))
9893 791 : size += strlen (p->name) + dwarf_offset_size + 1 + space_for_flags;
9894 :
9895 512 : size += dwarf_offset_size;
9896 512 : return size;
9897 : }
9898 :
9899 : /* Return the size of the information in the .debug_aranges section. */
9900 :
9901 : static unsigned long
9902 51038 : size_of_aranges (void)
9903 : {
9904 51038 : unsigned long size;
9905 :
9906 63708 : size = DWARF_ARANGES_HEADER_SIZE;
9907 :
9908 : /* Count the address/length pair for this compilation unit. */
9909 51038 : if (switch_text_ranges)
9910 32573 : size += 2 * DWARF2_ADDR_SIZE
9911 29518 : * (vec_safe_length (switch_text_ranges) / 2 + 1);
9912 51038 : if (switch_cold_ranges)
9913 8987 : size += 2 * DWARF2_ADDR_SIZE
9914 8667 : * (vec_safe_length (switch_cold_ranges) / 2 + 1);
9915 51038 : if (have_multiple_function_sections)
9916 : {
9917 : unsigned fde_idx;
9918 : dw_fde_ref fde;
9919 :
9920 287376 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
9921 : {
9922 259222 : if (fde->ignored_debug)
9923 2917 : continue;
9924 256305 : if (!fde->in_std_section)
9925 194722 : size += 2 * DWARF2_ADDR_SIZE;
9926 256305 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
9927 10152 : size += 2 * DWARF2_ADDR_SIZE;
9928 : }
9929 : }
9930 :
9931 : /* Count the two zero words used to terminated the address range table. */
9932 51038 : size += 2 * DWARF2_ADDR_SIZE;
9933 51038 : return size;
9934 : }
9935 :
9936 : /* Select the encoding of an attribute value. */
9937 :
9938 : static enum dwarf_form
9939 986856775 : value_format (dw_attr_node *a)
9940 : {
9941 986856775 : switch (AT_class (a))
9942 : {
9943 57854 : case dw_val_class_addr:
9944 : /* Only very few attributes allow DW_FORM_addr. */
9945 57854 : switch (a->dw_attr)
9946 : {
9947 57854 : case DW_AT_low_pc:
9948 57854 : case DW_AT_high_pc:
9949 57854 : case DW_AT_entry_pc:
9950 57854 : case DW_AT_trampoline:
9951 57854 : return (AT_index (a) == NOT_INDEXED
9952 57854 : ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
9953 0 : default:
9954 0 : break;
9955 : }
9956 0 : switch (DWARF2_ADDR_SIZE)
9957 : {
9958 : case 1:
9959 : return DW_FORM_data1;
9960 : case 2:
9961 : return DW_FORM_data2;
9962 : case 4:
9963 : return DW_FORM_data4;
9964 : case 8:
9965 : return DW_FORM_data8;
9966 : default:
9967 : gcc_unreachable ();
9968 : }
9969 22635780 : case dw_val_class_loc_list:
9970 22635780 : if (dwarf_split_debug_info
9971 4 : && dwarf_version >= 5
9972 22635784 : && AT_loc_list (a)->num_assigned)
9973 : return DW_FORM_loclistx;
9974 : /* FALLTHRU */
9975 57520943 : case dw_val_class_view_list:
9976 57520943 : case dw_val_class_range_list:
9977 : /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9978 : but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9979 : care about sizes of .debug* sections in shared libraries and
9980 : executables and don't take into account relocations that affect just
9981 : relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9982 : table in the .debug_rnglists section. */
9983 57520943 : if (dwarf_split_debug_info
9984 19 : && dwarf_version >= 5
9985 19 : && AT_class (a) == dw_val_class_range_list
9986 15 : && rnglist_idx
9987 57520958 : && a->dw_attr_val.val_entry != RELOCATED_OFFSET)
9988 : return DW_FORM_rnglistx;
9989 57520934 : if (dwarf_version >= 4)
9990 : return DW_FORM_sec_offset;
9991 : /* FALLTHRU */
9992 18097 : case dw_val_class_vms_delta:
9993 18097 : case dw_val_class_offset:
9994 18097 : switch (dwarf_offset_size)
9995 : {
9996 : case 4:
9997 : return DW_FORM_data4;
9998 : case 8:
9999 : return DW_FORM_data8;
10000 0 : default:
10001 0 : gcc_unreachable ();
10002 : }
10003 15084180 : case dw_val_class_loc:
10004 15084180 : if (dwarf_version >= 4)
10005 : return DW_FORM_exprloc;
10006 22051 : switch (constant_size (size_of_locs (AT_loc (a))))
10007 : {
10008 : case 1:
10009 : return DW_FORM_block1;
10010 : case 2:
10011 : return DW_FORM_block2;
10012 : case 4:
10013 : return DW_FORM_block4;
10014 0 : default:
10015 0 : gcc_unreachable ();
10016 : }
10017 : case dw_val_class_const:
10018 : return DW_FORM_sdata;
10019 234346722 : case dw_val_class_unsigned_const:
10020 234346722 : switch (constant_size (AT_unsigned (a)))
10021 : {
10022 : case 1:
10023 : return DW_FORM_data1;
10024 : case 2:
10025 : return DW_FORM_data2;
10026 217118 : case 4:
10027 : /* In DWARF3 DW_AT_data_member_location with
10028 : DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
10029 : constant, so we need to use DW_FORM_udata if we need
10030 : a large constant. */
10031 217118 : if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
10032 : return DW_FORM_udata;
10033 : return DW_FORM_data4;
10034 38806 : case 8:
10035 38806 : if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
10036 : return DW_FORM_udata;
10037 : return DW_FORM_data8;
10038 0 : default:
10039 0 : gcc_unreachable ();
10040 : }
10041 : case dw_val_class_const_implicit:
10042 : case dw_val_class_unsigned_const_implicit:
10043 : case dw_val_class_file_implicit:
10044 : return DW_FORM_implicit_const;
10045 0 : case dw_val_class_const_double:
10046 0 : switch (HOST_BITS_PER_WIDE_INT)
10047 : {
10048 : case 8:
10049 : return DW_FORM_data2;
10050 : case 16:
10051 : return DW_FORM_data4;
10052 : case 32:
10053 : return DW_FORM_data8;
10054 0 : case 64:
10055 0 : if (dwarf_version >= 5)
10056 : return DW_FORM_data16;
10057 : /* FALLTHRU */
10058 : default:
10059 : return DW_FORM_block1;
10060 : }
10061 80 : case dw_val_class_wide_int:
10062 80 : switch (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT)
10063 : {
10064 : case 8:
10065 : return DW_FORM_data1;
10066 : case 16:
10067 : return DW_FORM_data2;
10068 : case 32:
10069 : return DW_FORM_data4;
10070 : case 64:
10071 : return DW_FORM_data8;
10072 80 : case 128:
10073 80 : if (dwarf_version >= 5)
10074 : return DW_FORM_data16;
10075 : /* FALLTHRU */
10076 : default:
10077 : return DW_FORM_block1;
10078 : }
10079 29379446 : case dw_val_class_symview:
10080 : /* ??? We might use uleb128, but then we'd have to compute
10081 : .debug_info offsets in the assembler. */
10082 29379446 : if (symview_upper_bound <= 0xff)
10083 : return DW_FORM_data1;
10084 27962552 : else if (symview_upper_bound <= 0xffff)
10085 : return DW_FORM_data2;
10086 : else if (symview_upper_bound <= 0xffffffff)
10087 : return DW_FORM_data4;
10088 : else
10089 : return DW_FORM_data8;
10090 46220 : case dw_val_class_vec:
10091 46220 : switch (constant_size (a->dw_attr_val.v.val_vec.length
10092 46220 : * a->dw_attr_val.v.val_vec.elt_size))
10093 : {
10094 : case 1:
10095 : return DW_FORM_block1;
10096 : case 2:
10097 : return DW_FORM_block2;
10098 : case 4:
10099 : return DW_FORM_block4;
10100 0 : default:
10101 0 : gcc_unreachable ();
10102 : }
10103 107937186 : case dw_val_class_flag:
10104 107937186 : if (dwarf_version >= 4)
10105 : {
10106 : /* Currently all add_AT_flag calls pass in 1 as last argument,
10107 : so DW_FORM_flag_present can be used. If that ever changes,
10108 : we'll need to use DW_FORM_flag and have some optimization
10109 : in build_abbrev_table that will change those to
10110 : DW_FORM_flag_present if it is set to 1 in all DIEs using
10111 : the same abbrev entry. */
10112 107890626 : gcc_assert (a->dw_attr_val.v.val_flag == 1);
10113 : return DW_FORM_flag_present;
10114 : }
10115 : return DW_FORM_flag;
10116 202032623 : case dw_val_class_die_ref:
10117 202032623 : if (AT_ref_external (a))
10118 : {
10119 70889 : if (AT_ref (a)->comdat_type_p)
10120 : return DW_FORM_ref_sig8;
10121 : else
10122 70708 : return DW_FORM_ref_addr;
10123 : }
10124 : else
10125 403923468 : return DW_FORM_ref;
10126 0 : case dw_val_class_fde_ref:
10127 0 : return DW_FORM_data;
10128 49427658 : case dw_val_class_lbl_id:
10129 49427658 : return (AT_index (a) == NOT_INDEXED
10130 49427658 : ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
10131 107546 : case dw_val_class_lineptr:
10132 107546 : case dw_val_class_macptr:
10133 107546 : case dw_val_class_loclistsptr:
10134 107546 : return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10135 152905972 : case dw_val_class_str:
10136 152905972 : return AT_string_form (a);
10137 121910102 : case dw_val_class_file:
10138 121910102 : switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
10139 : {
10140 : case 1:
10141 : return DW_FORM_data1;
10142 : case 2:
10143 : return DW_FORM_data2;
10144 : case 4:
10145 : return DW_FORM_data4;
10146 0 : default:
10147 0 : gcc_unreachable ();
10148 : }
10149 :
10150 : case dw_val_class_data8:
10151 : return DW_FORM_data8;
10152 :
10153 13740142 : case dw_val_class_high_pc:
10154 13740142 : switch (DWARF2_ADDR_SIZE)
10155 : {
10156 : case 1:
10157 : return DW_FORM_data1;
10158 : case 2:
10159 : return DW_FORM_data2;
10160 : case 4:
10161 : return DW_FORM_data4;
10162 : case 8:
10163 : return DW_FORM_data8;
10164 : default:
10165 : gcc_unreachable ();
10166 : }
10167 :
10168 0 : case dw_val_class_discr_value:
10169 0 : return (a->dw_attr_val.v.val_discr_value.pos
10170 0 : ? DW_FORM_udata
10171 : : DW_FORM_sdata);
10172 0 : case dw_val_class_discr_list:
10173 0 : switch (constant_size (size_of_discr_list (AT_discr_list (a))))
10174 : {
10175 : case 1:
10176 : return DW_FORM_block1;
10177 : case 2:
10178 : return DW_FORM_block2;
10179 : case 4:
10180 : return DW_FORM_block4;
10181 0 : default:
10182 0 : gcc_unreachable ();
10183 : }
10184 :
10185 0 : default:
10186 0 : gcc_unreachable ();
10187 : }
10188 : }
10189 :
10190 : /* Output the encoding of an attribute value. */
10191 :
10192 : static void
10193 15826924 : output_value_format (dw_attr_node *a)
10194 : {
10195 15826924 : enum dwarf_form form = value_format (a);
10196 :
10197 31653848 : dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10198 15826924 : }
10199 :
10200 : /* Given a die and id, produce the appropriate abbreviations. */
10201 :
10202 : static void
10203 2809292 : output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
10204 : {
10205 2809292 : unsigned ix;
10206 2809292 : dw_attr_node *a_attr;
10207 :
10208 2809292 : dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10209 2809292 : dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10210 2809292 : dwarf_tag_name (abbrev->die_tag));
10211 :
10212 2809292 : if (abbrev->die_child != NULL)
10213 1365762 : dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10214 : else
10215 1443530 : dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10216 :
10217 18636216 : for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
10218 : {
10219 15826924 : dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10220 15826924 : dwarf_attr_name (a_attr->dw_attr));
10221 15826924 : output_value_format (a_attr);
10222 15826924 : if (value_format (a_attr) == DW_FORM_implicit_const)
10223 : {
10224 1133222 : if (AT_class (a_attr) == dw_val_class_file_implicit)
10225 : {
10226 410721 : int f = maybe_emit_file (a_attr->dw_attr_val.v.val_file);
10227 410721 : const char *filename = a_attr->dw_attr_val.v.val_file->filename;
10228 410721 : dw2_asm_output_data_sleb128 (f, "(%s)", filename);
10229 : }
10230 : else
10231 722501 : dw2_asm_output_data_sleb128 (a_attr->dw_attr_val.v.val_int, NULL);
10232 : }
10233 : }
10234 :
10235 2809292 : dw2_asm_output_data (1, 0, NULL);
10236 2809292 : dw2_asm_output_data (1, 0, NULL);
10237 2809292 : }
10238 :
10239 :
10240 : /* Output the .debug_abbrev section which defines the DIE abbreviation
10241 : table. */
10242 :
10243 : static void
10244 52367 : output_abbrev_section (void)
10245 : {
10246 52367 : unsigned int abbrev_id;
10247 52367 : dw_die_ref abbrev;
10248 :
10249 2913777 : FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
10250 2861410 : if (abbrev_id != 0)
10251 2809043 : output_die_abbrevs (abbrev_id, abbrev);
10252 :
10253 : /* Terminate the table. */
10254 52367 : dw2_asm_output_data (1, 0, NULL);
10255 52367 : }
10256 :
10257 : /* Return a new location list, given the begin and end range, and the
10258 : expression. */
10259 :
10260 : static inline dw_loc_list_ref
10261 26248288 : new_loc_list (dw_loc_descr_ref expr, const char *begin, var_loc_view vbegin,
10262 : const char *end, var_loc_view vend,
10263 : const char *section)
10264 : {
10265 52496576 : dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
10266 :
10267 26248288 : retlist->begin = begin;
10268 26248288 : retlist->begin_entry = NULL;
10269 26248288 : retlist->end = end;
10270 26248288 : retlist->end_entry = NULL;
10271 26248288 : retlist->expr = expr;
10272 26248288 : retlist->section = section;
10273 26248288 : retlist->vbegin = vbegin;
10274 26248288 : retlist->vend = vend;
10275 :
10276 26248288 : return retlist;
10277 : }
10278 :
10279 : /* Return true iff there's any nonzero view number in the loc list.
10280 :
10281 : ??? When views are not enabled, we'll often extend a single range
10282 : to the entire function, so that we emit a single location
10283 : expression rather than a location list. With views, even with a
10284 : single range, we'll output a list if start or end have a nonzero
10285 : view. If we change this, we may want to stop splitting a single
10286 : range in dw_loc_list just because of a nonzero view, even if it
10287 : straddles across hot/cold partitions. */
10288 :
10289 : static bool
10290 23393594 : loc_list_has_views (dw_loc_list_ref list)
10291 : {
10292 23393594 : if (!debug_variable_location_views)
10293 : return false;
10294 :
10295 1415384 : for (dw_loc_list_ref loc = list;
10296 24805010 : loc != NULL; loc = loc->dw_loc_next)
10297 24113882 : if (!ZERO_VIEW_P (loc->vbegin) || !ZERO_VIEW_P (loc->vend))
10298 22698498 : return true;
10299 :
10300 : return false;
10301 : }
10302 :
10303 : /* Generate a new internal symbol for this location list node, if it
10304 : hasn't got one yet. */
10305 :
10306 : static inline void
10307 11820337 : gen_llsym (dw_loc_list_ref list)
10308 : {
10309 11820337 : gcc_assert (!list->ll_symbol);
10310 11820337 : list->ll_symbol = gen_internal_sym ("LLST");
10311 :
10312 11820337 : if (!loc_list_has_views (list))
10313 : return;
10314 :
10315 11645002 : if (dwarf2out_locviews_in_attribute ())
10316 : {
10317 : /* Use the same label_num for the view list. */
10318 11645002 : label_num--;
10319 11645002 : list->vl_symbol = gen_internal_sym ("LVUS");
10320 : }
10321 : else
10322 0 : list->vl_symbol = list->ll_symbol;
10323 : }
10324 :
10325 : /* Generate a symbol for the list, but only if we really want to emit
10326 : it as a list. */
10327 :
10328 : static inline void
10329 1286898 : maybe_gen_llsym (dw_loc_list_ref list)
10330 : {
10331 1286898 : if (!list || (!list->dw_loc_next && !loc_list_has_views (list)))
10332 1237976 : return;
10333 :
10334 48922 : gen_llsym (list);
10335 : }
10336 :
10337 : /* Determine whether or not to skip loc_list entry CURR. If SIZEP is
10338 : NULL, don't consider size of the location expression. If we're not
10339 : to skip it, and SIZEP is non-null, store the size of CURR->expr's
10340 : representation in *SIZEP. */
10341 :
10342 : static bool
10343 47689972 : skip_loc_list_entry (dw_loc_list_ref curr, unsigned long *sizep = NULL)
10344 : {
10345 : /* Don't output an entry that starts and ends at the same address. */
10346 47689972 : if (strcmp (curr->begin, curr->end) == 0
10347 6360681 : && curr->vbegin == curr->vend && !curr->force)
10348 : return true;
10349 :
10350 47689951 : if (!sizep)
10351 : return false;
10352 :
10353 47689947 : unsigned long size = size_of_locs (curr->expr);
10354 :
10355 : /* If the expression is too large, drop it on the floor. We could
10356 : perhaps put it into DW_TAG_dwarf_procedure and refer to that
10357 : in the expression, but >= 64KB expressions for a single value
10358 : in a single range are unlikely very useful. */
10359 47689947 : if (dwarf_version < 5 && size > 0xffff)
10360 : return true;
10361 :
10362 47689947 : *sizep = size;
10363 :
10364 47689947 : return false;
10365 : }
10366 :
10367 : /* Output a view pair loclist entry for CURR, if it requires one. */
10368 :
10369 : static void
10370 24101081 : dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr)
10371 : {
10372 24101081 : if (!dwarf2out_locviews_in_loclist ())
10373 : return;
10374 :
10375 0 : if (ZERO_VIEW_P (curr->vbegin) && ZERO_VIEW_P (curr->vend))
10376 0 : return;
10377 :
10378 : #ifdef DW_LLE_view_pair
10379 0 : dw2_asm_output_data (1, DW_LLE_view_pair, "DW_LLE_view_pair");
10380 :
10381 0 : if (dwarf2out_as_locview_support)
10382 : {
10383 0 : if (ZERO_VIEW_P (curr->vbegin))
10384 0 : dw2_asm_output_data_uleb128 (0, "Location view begin");
10385 : else
10386 : {
10387 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
10388 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vbegin);
10389 0 : dw2_asm_output_symname_uleb128 (label, "Location view begin");
10390 : }
10391 :
10392 0 : if (ZERO_VIEW_P (curr->vend))
10393 0 : dw2_asm_output_data_uleb128 (0, "Location view end");
10394 : else
10395 : {
10396 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
10397 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vend);
10398 0 : dw2_asm_output_symname_uleb128 (label, "Location view end");
10399 : }
10400 : }
10401 : else
10402 : {
10403 0 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
10404 0 : ? 0 : curr->vbegin, "Location view begin");
10405 0 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
10406 0 : ? 0 : curr->vend, "Location view end");
10407 : }
10408 : #endif /* DW_LLE_view_pair */
10409 :
10410 : return;
10411 : }
10412 :
10413 : /* Output the location list given to us. */
10414 :
10415 : static void
10416 11315230 : output_loc_list (dw_loc_list_ref list_head)
10417 : {
10418 11315230 : int vcount = 0, lcount = 0;
10419 :
10420 11315230 : if (list_head->emitted)
10421 : return;
10422 11186207 : list_head->emitted = true;
10423 :
10424 11186207 : if (list_head->vl_symbol && dwarf2out_locviews_in_attribute ())
10425 : {
10426 11010892 : ASM_OUTPUT_LABEL (asm_out_file, list_head->vl_symbol);
10427 :
10428 34586248 : for (dw_loc_list_ref curr = list_head; curr != NULL;
10429 23575356 : curr = curr->dw_loc_next)
10430 : {
10431 23575356 : unsigned long size;
10432 :
10433 23575356 : if (skip_loc_list_entry (curr, &size))
10434 0 : continue;
10435 :
10436 23575356 : vcount++;
10437 :
10438 : /* ?? dwarf_split_debug_info? */
10439 23575356 : if (dwarf2out_as_locview_support)
10440 : {
10441 23574126 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
10442 :
10443 23574126 : if (!ZERO_VIEW_P (curr->vbegin))
10444 : {
10445 23001055 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vbegin);
10446 23001055 : dw2_asm_output_symname_uleb128 (label,
10447 : "View list begin (%s)",
10448 : list_head->vl_symbol);
10449 : }
10450 : else
10451 573071 : dw2_asm_output_data_uleb128 (0,
10452 : "View list begin (%s)",
10453 : list_head->vl_symbol);
10454 :
10455 23574126 : if (!ZERO_VIEW_P (curr->vend))
10456 : {
10457 22549618 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vend);
10458 22549618 : dw2_asm_output_symname_uleb128 (label,
10459 : "View list end (%s)",
10460 : list_head->vl_symbol);
10461 : }
10462 : else
10463 1024508 : dw2_asm_output_data_uleb128 (0,
10464 : "View list end (%s)",
10465 : list_head->vl_symbol);
10466 : }
10467 : else
10468 : {
10469 2460 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
10470 1191 : ? 0 : curr->vbegin,
10471 : "View list begin (%s)",
10472 : list_head->vl_symbol);
10473 2460 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
10474 1183 : ? 0 : curr->vend,
10475 : "View list end (%s)",
10476 : list_head->vl_symbol);
10477 : }
10478 : }
10479 : }
10480 :
10481 11186207 : ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
10482 :
10483 11186207 : const char *last_section = NULL;
10484 11186207 : const char *base_label = NULL;
10485 :
10486 : /* Walk the location list, and output each range + expression. */
10487 35300819 : for (dw_loc_list_ref curr = list_head; curr != NULL;
10488 24114612 : curr = curr->dw_loc_next)
10489 : {
10490 24114612 : unsigned long size;
10491 :
10492 : /* Skip this entry? If we skip it here, we must skip it in the
10493 : view list above as well. */
10494 24114612 : if (skip_loc_list_entry (curr, &size))
10495 21 : continue;
10496 :
10497 24114591 : lcount++;
10498 :
10499 24114591 : if (dwarf_version >= 5)
10500 : {
10501 24101081 : if (dwarf_split_debug_info && HAVE_AS_LEB128)
10502 : {
10503 4 : dwarf2out_maybe_output_loclist_view_pair (curr);
10504 : /* For -gsplit-dwarf, emit DW_LLE_startx_length, which has
10505 : uleb128 index into .debug_addr and uleb128 length. */
10506 4 : dw2_asm_output_data (1, DW_LLE_startx_length,
10507 : "DW_LLE_startx_length (%s)",
10508 : list_head->ll_symbol);
10509 4 : dw2_asm_output_data_uleb128 (curr->begin_entry->index,
10510 : "Location list range start index "
10511 : "(%s)", curr->begin);
10512 4 : dw2_asm_output_delta_uleb128 (curr->end, curr->begin,
10513 : "Location list length (%s)",
10514 : list_head->ll_symbol);
10515 : }
10516 24101077 : else if (dwarf_split_debug_info)
10517 : {
10518 : dwarf2out_maybe_output_loclist_view_pair (curr);
10519 : /* For -gsplit-dwarf without usable .uleb128 support, emit
10520 : DW_LLE_startx_endx, which has two uleb128 indexes into
10521 : .debug_addr. */
10522 : dw2_asm_output_data (1, DW_LLE_startx_endx,
10523 : "DW_LLE_startx_endx (%s)",
10524 : list_head->ll_symbol);
10525 : dw2_asm_output_data_uleb128 (curr->begin_entry->index,
10526 : "Location list range start index "
10527 : "(%s)", curr->begin);
10528 : dw2_asm_output_data_uleb128 (curr->end_entry->index,
10529 : "Location list range end index "
10530 : "(%s)", curr->end);
10531 : }
10532 24101077 : else if (!have_multiple_function_sections && HAVE_AS_LEB128)
10533 : {
10534 3803640 : dwarf2out_maybe_output_loclist_view_pair (curr);
10535 : /* If all code is in .text section, the base address is
10536 : already provided by the CU attributes. Use
10537 : DW_LLE_offset_pair where both addresses are uleb128 encoded
10538 : offsets against that base. */
10539 3803640 : dw2_asm_output_data (1, DW_LLE_offset_pair,
10540 : "DW_LLE_offset_pair (%s)",
10541 : list_head->ll_symbol);
10542 3803640 : dw2_asm_output_delta_uleb128 (curr->begin, curr->section,
10543 : "Location list begin address (%s)",
10544 : list_head->ll_symbol);
10545 3803640 : dw2_asm_output_delta_uleb128 (curr->end, curr->section,
10546 : "Location list end address (%s)",
10547 : list_head->ll_symbol);
10548 : }
10549 20297437 : else if (HAVE_AS_LEB128)
10550 : {
10551 : /* Otherwise, find out how many consecutive entries could share
10552 : the same base entry. If just one, emit DW_LLE_start_length,
10553 : otherwise emit DW_LLE_base_address for the base address
10554 : followed by a series of DW_LLE_offset_pair. */
10555 20297437 : if (last_section == NULL || curr->section != last_section)
10556 : {
10557 10663695 : dw_loc_list_ref curr2;
10558 11066559 : for (curr2 = curr->dw_loc_next; curr2 != NULL;
10559 402864 : curr2 = curr2->dw_loc_next)
10560 : {
10561 3988013 : if (strcmp (curr2->begin, curr2->end) == 0
10562 402864 : && !curr2->force)
10563 402864 : continue;
10564 : break;
10565 : }
10566 10663695 : if (curr2 == NULL || curr->section != curr2->section)
10567 : last_section = NULL;
10568 : else
10569 : {
10570 3560452 : last_section = curr->section;
10571 3560452 : base_label = curr->begin;
10572 3560452 : dw2_asm_output_data (1, DW_LLE_base_address,
10573 : "DW_LLE_base_address (%s)",
10574 : list_head->ll_symbol);
10575 3761519 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, base_label,
10576 : "Base address (%s)",
10577 : list_head->ll_symbol);
10578 : }
10579 : }
10580 : /* Only one entry with the same base address. Use
10581 : DW_LLE_start_length with absolute address and uleb128
10582 : length. */
10583 13194194 : if (last_section == NULL)
10584 : {
10585 7103243 : dwarf2out_maybe_output_loclist_view_pair (curr);
10586 7103243 : dw2_asm_output_data (1, DW_LLE_start_length,
10587 : "DW_LLE_start_length (%s)",
10588 : list_head->ll_symbol);
10589 7324272 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10590 : "Location list begin address (%s)",
10591 : list_head->ll_symbol);
10592 7103243 : dw2_asm_output_delta_uleb128 (curr->end, curr->begin,
10593 : "Location list length "
10594 : "(%s)", list_head->ll_symbol);
10595 : }
10596 : /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
10597 : DW_LLE_base_address. */
10598 : else
10599 : {
10600 13194194 : dwarf2out_maybe_output_loclist_view_pair (curr);
10601 13194194 : dw2_asm_output_data (1, DW_LLE_offset_pair,
10602 : "DW_LLE_offset_pair (%s)",
10603 : list_head->ll_symbol);
10604 13194194 : dw2_asm_output_delta_uleb128 (curr->begin, base_label,
10605 : "Location list begin address "
10606 : "(%s)", list_head->ll_symbol);
10607 13194194 : dw2_asm_output_delta_uleb128 (curr->end, base_label,
10608 : "Location list end address "
10609 : "(%s)", list_head->ll_symbol);
10610 : }
10611 : }
10612 : /* The assembler does not support .uleb128 directive. Emit
10613 : DW_LLE_start_end with a pair of absolute addresses. */
10614 : else
10615 : {
10616 : dwarf2out_maybe_output_loclist_view_pair (curr);
10617 : dw2_asm_output_data (1, DW_LLE_start_end,
10618 : "DW_LLE_start_end (%s)",
10619 : list_head->ll_symbol);
10620 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10621 : "Location list begin address (%s)",
10622 : list_head->ll_symbol);
10623 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
10624 : "Location list end address (%s)",
10625 : list_head->ll_symbol);
10626 : }
10627 : }
10628 13510 : else if (dwarf_split_debug_info)
10629 : {
10630 : /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
10631 : and 4 byte length. */
10632 0 : dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry,
10633 : "Location list start/length entry (%s)",
10634 : list_head->ll_symbol);
10635 0 : dw2_asm_output_data_uleb128 (curr->begin_entry->index,
10636 : "Location list range start index (%s)",
10637 : curr->begin);
10638 : /* The length field is 4 bytes. If we ever need to support
10639 : an 8-byte length, we can add a new DW_LLE code or fall back
10640 : to DW_LLE_GNU_start_end_entry. */
10641 0 : dw2_asm_output_delta (4, curr->end, curr->begin,
10642 : "Location list range length (%s)",
10643 : list_head->ll_symbol);
10644 : }
10645 13510 : else if (!have_multiple_function_sections)
10646 : {
10647 : /* Pair of relative addresses against start of text section. */
10648 6717 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
10649 : "Location list begin address (%s)",
10650 : list_head->ll_symbol);
10651 6717 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
10652 : "Location list end address (%s)",
10653 : list_head->ll_symbol);
10654 : }
10655 : else
10656 : {
10657 : /* Pair of absolute addresses. */
10658 6793 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10659 : "Location list begin address (%s)",
10660 : list_head->ll_symbol);
10661 6793 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
10662 : "Location list end address (%s)",
10663 : list_head->ll_symbol);
10664 : }
10665 :
10666 : /* Output the block length for this list of location operations. */
10667 24114591 : if (dwarf_version >= 5)
10668 24101081 : dw2_asm_output_data_uleb128 (size, "Location expression size");
10669 : else
10670 : {
10671 13510 : gcc_assert (size <= 0xffff);
10672 13510 : dw2_asm_output_data (2, size, "Location expression size");
10673 : }
10674 :
10675 24114591 : output_loc_sequence (curr->expr, -1);
10676 : }
10677 :
10678 : /* And finally list termination. */
10679 11186207 : if (dwarf_version >= 5)
10680 11181863 : dw2_asm_output_data (1, DW_LLE_end_of_list,
10681 : "DW_LLE_end_of_list (%s)", list_head->ll_symbol);
10682 4344 : else if (dwarf_split_debug_info)
10683 0 : dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry,
10684 : "Location list terminator (%s)",
10685 : list_head->ll_symbol);
10686 : else
10687 : {
10688 4344 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10689 : "Location list terminator begin (%s)",
10690 : list_head->ll_symbol);
10691 4344 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10692 : "Location list terminator end (%s)",
10693 : list_head->ll_symbol);
10694 : }
10695 :
10696 11186207 : gcc_assert (!list_head->vl_symbol
10697 : || vcount == lcount * (dwarf2out_locviews_in_attribute () ? 1 : 0));
10698 : }
10699 :
10700 : /* Output a range_list offset into the .debug_ranges or .debug_rnglists
10701 : section. Emit a relocated reference if val_entry is NULL, otherwise,
10702 : emit an indirect reference. */
10703 :
10704 : static void
10705 3212558 : output_range_list_offset (dw_attr_node *a)
10706 : {
10707 3212558 : const char *name = dwarf_attr_name (a->dw_attr);
10708 :
10709 3212558 : if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
10710 : {
10711 3212555 : if (dwarf_version >= 5)
10712 : {
10713 3211224 : dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
10714 3211224 : dw2_asm_output_offset (dwarf_offset_size, r->label,
10715 : debug_ranges_section, "%s", name);
10716 : }
10717 : else
10718 : {
10719 1331 : char *p = strchr (ranges_section_label, '\0');
10720 2662 : sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
10721 1331 : a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE);
10722 1331 : dw2_asm_output_offset (dwarf_offset_size, ranges_section_label,
10723 : debug_ranges_section, "%s", name);
10724 1331 : *p = '\0';
10725 : }
10726 : }
10727 3 : else if (dwarf_version >= 5)
10728 : {
10729 3 : dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
10730 3 : gcc_assert (rnglist_idx);
10731 3 : dw2_asm_output_data_uleb128 (r->idx, "%s", name);
10732 : }
10733 : else
10734 0 : dw2_asm_output_data (dwarf_offset_size,
10735 0 : a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE,
10736 : "%s (offset from %s)", name, ranges_section_label);
10737 3212558 : }
10738 :
10739 : /* Output the offset into the debug_loc section. */
10740 :
10741 : static void
10742 11315230 : output_loc_list_offset (dw_attr_node *a)
10743 : {
10744 11315230 : char *sym = AT_loc_list (a)->ll_symbol;
10745 :
10746 11315230 : gcc_assert (sym);
10747 11315230 : if (!dwarf_split_debug_info)
10748 11315228 : dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
10749 11315228 : "%s", dwarf_attr_name (a->dw_attr));
10750 2 : else if (dwarf_version >= 5)
10751 : {
10752 2 : gcc_assert (AT_loc_list (a)->num_assigned);
10753 2 : dw2_asm_output_data_uleb128 (AT_loc_list (a)->hash, "%s (%s)",
10754 2 : dwarf_attr_name (a->dw_attr),
10755 : sym);
10756 : }
10757 : else
10758 0 : dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
10759 0 : "%s", dwarf_attr_name (a->dw_attr));
10760 11315230 : }
10761 :
10762 : /* Output the offset into the debug_loc section. */
10763 :
10764 : static void
10765 11139022 : output_view_list_offset (dw_attr_node *a)
10766 : {
10767 11139022 : char *sym = (*AT_loc_list_ptr (a))->vl_symbol;
10768 :
10769 11139022 : gcc_assert (sym);
10770 11139022 : if (dwarf_split_debug_info)
10771 2 : dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
10772 2 : "%s", dwarf_attr_name (a->dw_attr));
10773 : else
10774 11139020 : dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
10775 11139020 : "%s", dwarf_attr_name (a->dw_attr));
10776 11139022 : }
10777 :
10778 : /* Output an attribute's index or value appropriately. */
10779 :
10780 : static void
10781 13556937 : output_attr_index_or_value (dw_attr_node *a)
10782 : {
10783 13556937 : const char *name = dwarf_attr_name (a->dw_attr);
10784 :
10785 13556937 : if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
10786 : {
10787 253 : dw2_asm_output_data_uleb128 (AT_index (a), "%s", name);
10788 253 : return;
10789 : }
10790 13556684 : switch (AT_class (a))
10791 : {
10792 28582 : case dw_val_class_addr:
10793 28582 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
10794 28582 : break;
10795 13528102 : case dw_val_class_high_pc:
10796 13528102 : case dw_val_class_lbl_id:
10797 13528102 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
10798 13528102 : break;
10799 0 : default:
10800 0 : gcc_unreachable ();
10801 : }
10802 : }
10803 :
10804 : /* Output a type signature. */
10805 :
10806 : static inline void
10807 169 : output_signature (const char *sig, const char *name)
10808 : {
10809 169 : int i;
10810 :
10811 1521 : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
10812 2535 : dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
10813 169 : }
10814 :
10815 : /* Output a discriminant value. */
10816 :
10817 : static inline void
10818 0 : output_discr_value (dw_discr_value *discr_value, const char *name)
10819 : {
10820 0 : if (discr_value->pos)
10821 0 : dw2_asm_output_data_uleb128 (discr_value->v.uval, "%s", name);
10822 : else
10823 0 : dw2_asm_output_data_sleb128 (discr_value->v.sval, "%s", name);
10824 0 : }
10825 :
10826 : /* Output the DIE and its attributes. Called recursively to generate
10827 : the definitions of each child DIE. */
10828 :
10829 : static void
10830 78903876 : output_die (dw_die_ref die)
10831 : {
10832 78903876 : dw_attr_node *a;
10833 78903876 : dw_die_ref c;
10834 78903876 : unsigned long size;
10835 78903876 : unsigned ix;
10836 :
10837 157807752 : dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
10838 78903876 : (unsigned long)die->die_offset,
10839 78903876 : dwarf_tag_name (die->die_tag));
10840 :
10841 389108157 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
10842 : {
10843 310204281 : const char *name = dwarf_attr_name (a->dw_attr);
10844 :
10845 310204281 : switch (AT_class (a))
10846 : {
10847 28582 : case dw_val_class_addr:
10848 28582 : output_attr_index_or_value (a);
10849 28582 : break;
10850 :
10851 0 : case dw_val_class_offset:
10852 0 : dw2_asm_output_data (dwarf_offset_size, a->dw_attr_val.v.val_offset,
10853 : "%s", name);
10854 0 : break;
10855 :
10856 3212558 : case dw_val_class_range_list:
10857 3212558 : output_range_list_offset (a);
10858 3212558 : break;
10859 :
10860 7520231 : case dw_val_class_loc:
10861 7520231 : size = size_of_locs (AT_loc (a));
10862 :
10863 : /* Output the block length for this list of location operations. */
10864 7520231 : if (dwarf_version >= 4)
10865 7509292 : dw2_asm_output_data_uleb128 (size, "%s", name);
10866 : else
10867 10939 : dw2_asm_output_data (constant_size (size), size, "%s", name);
10868 :
10869 7520231 : output_loc_sequence (AT_loc (a), -1);
10870 7520231 : break;
10871 :
10872 14852 : case dw_val_class_const:
10873 : /* ??? It would be slightly more efficient to use a scheme like is
10874 : used for unsigned constants below, but gdb 4.x does not sign
10875 : extend. Gdb 5.x does sign extend. */
10876 14852 : dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
10877 14852 : break;
10878 :
10879 66151698 : case dw_val_class_unsigned_const:
10880 66151698 : {
10881 66151698 : int csize = constant_size (AT_unsigned (a));
10882 66151698 : if (dwarf_version == 3
10883 690 : && a->dw_attr == DW_AT_data_member_location
10884 15 : && csize >= 4)
10885 1 : dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
10886 : else
10887 66151697 : dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
10888 : }
10889 : break;
10890 :
10891 6211432 : case dw_val_class_symview:
10892 6211432 : {
10893 6211432 : int vsize;
10894 6211432 : if (symview_upper_bound <= 0xff)
10895 : vsize = 1;
10896 5873406 : else if (symview_upper_bound <= 0xffff)
10897 : vsize = 2;
10898 0 : else if (symview_upper_bound <= 0xffffffff)
10899 0 : vsize = 4;
10900 : else
10901 : vsize = 8;
10902 6211432 : dw2_asm_output_addr (vsize, a->dw_attr_val.v.val_symbolic_view,
10903 : "%s", name);
10904 : }
10905 6211432 : break;
10906 :
10907 5059 : case dw_val_class_const_implicit:
10908 5059 : if (flag_debug_asm)
10909 0 : fprintf (asm_out_file, "\t\t\t%s %s ("
10910 : HOST_WIDE_INT_PRINT_DEC ")\n",
10911 : ASM_COMMENT_START, name, AT_int (a));
10912 : break;
10913 :
10914 8721546 : case dw_val_class_unsigned_const_implicit:
10915 8721546 : if (flag_debug_asm)
10916 365 : fprintf (asm_out_file, "\t\t\t%s %s ("
10917 : HOST_WIDE_INT_PRINT_HEX ")\n",
10918 : ASM_COMMENT_START, name, AT_unsigned (a));
10919 : break;
10920 :
10921 0 : case dw_val_class_const_double:
10922 0 : {
10923 0 : unsigned HOST_WIDE_INT first, second;
10924 :
10925 0 : if (HOST_BITS_PER_WIDE_INT >= DWARF_LARGEST_DATA_FORM_BITS)
10926 0 : dw2_asm_output_data (1,
10927 : HOST_BITS_PER_DOUBLE_INT
10928 : / HOST_BITS_PER_CHAR,
10929 : NULL);
10930 :
10931 0 : if (WORDS_BIG_ENDIAN)
10932 : {
10933 : first = a->dw_attr_val.v.val_double.high;
10934 : second = a->dw_attr_val.v.val_double.low;
10935 : }
10936 : else
10937 : {
10938 0 : first = a->dw_attr_val.v.val_double.low;
10939 0 : second = a->dw_attr_val.v.val_double.high;
10940 : }
10941 :
10942 0 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10943 : first, "%s", name);
10944 0 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10945 : second, NULL);
10946 : }
10947 0 : break;
10948 :
10949 37 : case dw_val_class_wide_int:
10950 37 : {
10951 37 : int i;
10952 37 : int len = get_full_len (*a->dw_attr_val.v.val_wide);
10953 37 : int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10954 37 : if (len * HOST_BITS_PER_WIDE_INT > DWARF_LARGEST_DATA_FORM_BITS)
10955 0 : dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide)
10956 0 : * l, NULL);
10957 :
10958 : if (WORDS_BIG_ENDIAN)
10959 : for (i = len - 1; i >= 0; --i)
10960 : {
10961 : dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
10962 : "%s", name);
10963 : name = "";
10964 : }
10965 : else
10966 111 : for (i = 0; i < len; ++i)
10967 : {
10968 74 : dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
10969 : "%s", name);
10970 74 : name = "";
10971 : }
10972 : }
10973 : break;
10974 :
10975 16472 : case dw_val_class_vec:
10976 16472 : {
10977 16472 : unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
10978 16472 : unsigned int len = a->dw_attr_val.v.val_vec.length;
10979 16472 : unsigned int i;
10980 16472 : unsigned char *p;
10981 :
10982 16472 : dw2_asm_output_data (constant_size (len * elt_size),
10983 16472 : len * elt_size, "%s", name);
10984 16472 : if (elt_size > sizeof (HOST_WIDE_INT))
10985 : {
10986 0 : elt_size /= 2;
10987 0 : len *= 2;
10988 : }
10989 16472 : for (i = 0, p = (unsigned char *) a->dw_attr_val.v.val_vec.array;
10990 3511305 : i < len;
10991 3494833 : i++, p += elt_size)
10992 6989666 : dw2_asm_output_data (elt_size, extract_int (p, elt_size),
10993 : "fp or vector constant word %u", i);
10994 : break;
10995 : }
10996 :
10997 25602666 : case dw_val_class_flag:
10998 25602666 : if (dwarf_version >= 4)
10999 : {
11000 : /* Currently all add_AT_flag calls pass in 1 as last argument,
11001 : so DW_FORM_flag_present can be used. If that ever changes,
11002 : we'll need to use DW_FORM_flag and have some optimization
11003 : in build_abbrev_table that will change those to
11004 : DW_FORM_flag_present if it is set to 1 in all DIEs using
11005 : the same abbrev entry. */
11006 25581464 : gcc_assert (AT_flag (a) == 1);
11007 25581464 : if (flag_debug_asm)
11008 2175 : fprintf (asm_out_file, "\t\t\t%s %s\n",
11009 : ASM_COMMENT_START, name);
11010 : break;
11011 : }
11012 21202 : dw2_asm_output_data (1, AT_flag (a), "%s", name);
11013 21202 : break;
11014 :
11015 11315230 : case dw_val_class_loc_list:
11016 11315230 : output_loc_list_offset (a);
11017 11315230 : break;
11018 :
11019 11139022 : case dw_val_class_view_list:
11020 11139022 : output_view_list_offset (a);
11021 11139022 : break;
11022 :
11023 90668807 : case dw_val_class_die_ref:
11024 90668807 : if (AT_ref_external (a))
11025 : {
11026 29659 : if (AT_ref (a)->comdat_type_p)
11027 : {
11028 88 : comdat_type_node *type_node
11029 88 : = AT_ref (a)->die_id.die_type_node;
11030 :
11031 88 : gcc_assert (type_node);
11032 88 : output_signature (type_node->signature, name);
11033 : }
11034 : else
11035 : {
11036 29571 : const char *sym = AT_ref (a)->die_id.die_symbol;
11037 29571 : int size;
11038 :
11039 29571 : gcc_assert (sym);
11040 : /* In DWARF2, DW_FORM_ref_addr is sized by target address
11041 : length, whereas in DWARF3 it's always sized as an
11042 : offset. */
11043 29571 : if (dwarf_version == 2)
11044 30 : size = DWARF2_ADDR_SIZE;
11045 : else
11046 29541 : size = dwarf_offset_size;
11047 : /* ??? We cannot unconditionally output die_offset if
11048 : non-zero - others might create references to those
11049 : DIEs via symbols.
11050 : And we do not clear its DIE offset after outputting it
11051 : (and the label refers to the actual DIEs, not the
11052 : DWARF CU unit header which is when using label + offset
11053 : would be the correct thing to do).
11054 : ??? This is the reason for the with_offset flag. */
11055 29571 : if (AT_ref (a)->with_offset)
11056 29571 : dw2_asm_output_offset (size, sym, AT_ref (a)->die_offset,
11057 : debug_info_section, "%s", name);
11058 : else
11059 0 : dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11060 : name);
11061 : }
11062 : }
11063 : else
11064 : {
11065 90639148 : gcc_assert (AT_ref (a)->die_offset);
11066 90639148 : dw2_asm_output_data (dwarf_offset_size, AT_ref (a)->die_offset,
11067 : "%s", name);
11068 : }
11069 : break;
11070 :
11071 0 : case dw_val_class_fde_ref:
11072 0 : {
11073 0 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
11074 :
11075 0 : ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11076 : a->dw_attr_val.v.val_fde_index * 2);
11077 0 : dw2_asm_output_offset (dwarf_offset_size, l1, debug_frame_section,
11078 : "%s", name);
11079 : }
11080 0 : break;
11081 :
11082 0 : case dw_val_class_vms_delta:
11083 : #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
11084 : dw2_asm_output_vms_delta (dwarf_offset_size,
11085 : AT_vms_delta2 (a), AT_vms_delta1 (a),
11086 : "%s", name);
11087 : #else
11088 0 : dw2_asm_output_delta (dwarf_offset_size,
11089 : AT_vms_delta2 (a), AT_vms_delta1 (a),
11090 : "%s", name);
11091 : #endif
11092 0 : break;
11093 :
11094 13528355 : case dw_val_class_lbl_id:
11095 13528355 : output_attr_index_or_value (a);
11096 13528355 : break;
11097 :
11098 52690 : case dw_val_class_lineptr:
11099 52690 : dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
11100 : debug_line_section, "%s", name);
11101 52690 : break;
11102 :
11103 527 : case dw_val_class_macptr:
11104 527 : dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
11105 : debug_macinfo_section, "%s", name);
11106 527 : break;
11107 :
11108 0 : case dw_val_class_loclistsptr:
11109 0 : dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
11110 : debug_loc_section, "%s", name);
11111 0 : break;
11112 :
11113 32620836 : case dw_val_class_str:
11114 32620836 : if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
11115 29416280 : dw2_asm_output_offset (dwarf_offset_size,
11116 29416280 : a->dw_attr_val.v.val_str->label,
11117 : debug_str_section,
11118 : "%s: \"%s\"", name, AT_string (a));
11119 3204556 : else if (a->dw_attr_val.v.val_str->form == DW_FORM_line_strp)
11120 100280 : dw2_asm_output_offset (dwarf_offset_size,
11121 100280 : a->dw_attr_val.v.val_str->label,
11122 : debug_line_str_section,
11123 : "%s: \"%s\"", name, AT_string (a));
11124 3118461 : else if (a->dw_attr_val.v.val_str->form == dwarf_FORM (DW_FORM_strx))
11125 935 : dw2_asm_output_data_uleb128 (AT_index (a),
11126 : "%s: \"%s\"", name, AT_string (a));
11127 : else
11128 3103341 : dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11129 : break;
11130 :
11131 25275565 : case dw_val_class_file:
11132 25275565 : {
11133 25275565 : int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11134 :
11135 25275565 : dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11136 25275565 : a->dw_attr_val.v.val_file->filename);
11137 25275565 : break;
11138 : }
11139 :
11140 3710894 : case dw_val_class_file_implicit:
11141 3710894 : if (flag_debug_asm)
11142 531 : fprintf (asm_out_file, "\t\t\t%s %s (%d, %s)\n",
11143 : ASM_COMMENT_START, name,
11144 : maybe_emit_file (a->dw_attr_val.v.val_file),
11145 531 : a->dw_attr_val.v.val_file->filename);
11146 : break;
11147 :
11148 : case dw_val_class_data8:
11149 : {
11150 : int i;
11151 :
11152 639 : for (i = 0; i < 8; i++)
11153 1065 : dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11154 : i == 0 ? "%s" : NULL, name);
11155 : break;
11156 : }
11157 :
11158 4407151 : case dw_val_class_high_pc:
11159 4407151 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
11160 : get_AT_low_pc (die), "DW_AT_high_pc");
11161 4407151 : break;
11162 :
11163 0 : case dw_val_class_discr_value:
11164 0 : output_discr_value (&a->dw_attr_val.v.val_discr_value, name);
11165 0 : break;
11166 :
11167 0 : case dw_val_class_discr_list:
11168 0 : {
11169 0 : dw_discr_list_ref list = AT_discr_list (a);
11170 0 : const int size = size_of_discr_list (list);
11171 :
11172 : /* This is a block, so output its length first. */
11173 0 : dw2_asm_output_data (constant_size (size), size,
11174 : "%s: block size", name);
11175 :
11176 0 : for (; list != NULL; list = list->dw_discr_next)
11177 : {
11178 : /* One byte for the discriminant value descriptor, and then as
11179 : many LEB128 numbers as required. */
11180 0 : if (list->dw_discr_range)
11181 0 : dw2_asm_output_data (1, DW_DSC_range,
11182 : "%s: DW_DSC_range", name);
11183 : else
11184 0 : dw2_asm_output_data (1, DW_DSC_label,
11185 : "%s: DW_DSC_label", name);
11186 :
11187 0 : output_discr_value (&list->dw_discr_lower_bound, name);
11188 0 : if (list->dw_discr_range)
11189 0 : output_discr_value (&list->dw_discr_upper_bound, name);
11190 : }
11191 : break;
11192 : }
11193 :
11194 0 : default:
11195 0 : gcc_unreachable ();
11196 : }
11197 : }
11198 :
11199 137091246 : FOR_EACH_CHILD (die, c, output_die (c));
11200 :
11201 : /* Add null byte to terminate sibling list. */
11202 78903876 : if (die->die_child != NULL)
11203 20663811 : dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11204 20663811 : (unsigned long) die->die_offset);
11205 78903876 : }
11206 :
11207 : /* Output the dwarf version number. */
11208 :
11209 : static void
11210 118259 : output_dwarf_version ()
11211 : {
11212 : /* ??? For now, if -gdwarf-6 is specified, we output version 5 with
11213 : views in loclist. That will change eventually. */
11214 118259 : if (dwarf_version == 6)
11215 : {
11216 0 : static bool once;
11217 0 : if (!once)
11218 : {
11219 0 : warning (0, "%<-gdwarf-6%> is output as version 5 with "
11220 : "incompatibilities");
11221 0 : once = true;
11222 : }
11223 0 : dw2_asm_output_data (2, 5, "DWARF version number");
11224 : }
11225 : else
11226 118259 : dw2_asm_output_data (2, dwarf_version, "DWARF version number");
11227 118259 : }
11228 :
11229 : /* Output the compilation unit that appears at the beginning of the
11230 : .debug_info section, and precedes the DIE descriptions. */
11231 :
11232 : static void
11233 52446 : output_compilation_unit_header (enum dwarf_unit_type ut)
11234 : {
11235 52446 : if (!XCOFF_DEBUGGING_INFO)
11236 : {
11237 52446 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11238 0 : dw2_asm_output_data (4, 0xffffffff,
11239 : "Initial length escape value indicating 64-bit DWARF extension");
11240 52446 : dw2_asm_output_data (dwarf_offset_size,
11241 52446 : next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11242 : "Length of Compilation Unit Info");
11243 : }
11244 :
11245 52446 : output_dwarf_version ();
11246 52446 : if (dwarf_version >= 5)
11247 : {
11248 50409 : const char *name;
11249 50409 : switch (ut)
11250 : {
11251 : case DW_UT_compile: name = "DW_UT_compile"; break;
11252 21 : case DW_UT_type: name = "DW_UT_type"; break;
11253 248 : case DW_UT_split_compile: name = "DW_UT_split_compile"; break;
11254 0 : case DW_UT_split_type: name = "DW_UT_split_type"; break;
11255 0 : default: gcc_unreachable ();
11256 : }
11257 50409 : dw2_asm_output_data (1, ut, "%s", name);
11258 56744 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11259 : }
11260 52446 : dw2_asm_output_offset (dwarf_offset_size, abbrev_section_label,
11261 : debug_abbrev_section,
11262 : "Offset Into Abbrev. Section");
11263 52446 : if (dwarf_version < 5)
11264 2037 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11265 52446 : }
11266 :
11267 : /* Output the compilation unit DIE and its children. */
11268 :
11269 : static void
11270 53656 : output_comp_unit (dw_die_ref die, int output_if_empty,
11271 : const unsigned char *dwo_id)
11272 : {
11273 53656 : const char *secname, *oldsym;
11274 53656 : char *tmp;
11275 :
11276 : /* Unless we are outputting main CU, we may throw away empty ones. */
11277 53656 : if (!output_if_empty && die->die_child == NULL)
11278 : return;
11279 :
11280 : /* Even if there are no children of this DIE, we must output the information
11281 : about the compilation unit. Otherwise, on an empty translation unit, we
11282 : will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11283 : will then complain when examining the file. First mark all the DIEs in
11284 : this CU so we know which get local refs. */
11285 52365 : mark_dies (die);
11286 :
11287 52365 : external_ref_hash_type *extern_map = optimize_external_refs (die);
11288 :
11289 : /* For now, optimize only the main CU, in order to optimize the rest
11290 : we'd need to see all of them earlier. Leave the rest for post-linking
11291 : tools like DWZ. */
11292 52365 : if (die == comp_unit_die ())
11293 104730 : abbrev_opt_start = vec_safe_length (abbrev_die_table);
11294 :
11295 52365 : build_abbrev_table (die, extern_map);
11296 :
11297 52365 : optimize_abbrev_table ();
11298 :
11299 52365 : delete extern_map;
11300 :
11301 : /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11302 104730 : next_die_offset = (dwo_id
11303 52367 : ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11304 54092 : : DWARF_COMPILE_UNIT_HEADER_SIZE);
11305 52365 : calc_die_sizes (die);
11306 :
11307 52365 : oldsym = die->die_id.die_symbol;
11308 52365 : if (oldsym && die->comdat_type_p)
11309 : {
11310 0 : tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11311 :
11312 0 : sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11313 0 : secname = tmp;
11314 0 : die->die_id.die_symbol = NULL;
11315 0 : switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11316 : }
11317 : else
11318 : {
11319 52365 : switch_to_section (debug_info_section);
11320 52365 : ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11321 52365 : info_section_emitted = true;
11322 : }
11323 :
11324 : /* For LTO cross unit DIE refs we want a symbol on the start of the
11325 : debuginfo section, not on the CU DIE. */
11326 52365 : if ((flag_generate_lto || flag_generate_offload) && oldsym)
11327 : {
11328 : /* ??? No way to get visibility assembled without a decl. */
11329 1327 : tree decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
11330 : get_identifier (oldsym), char_type_node);
11331 1327 : TREE_PUBLIC (decl) = true;
11332 1327 : TREE_STATIC (decl) = true;
11333 1327 : DECL_ARTIFICIAL (decl) = true;
11334 1327 : DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
11335 1327 : DECL_VISIBILITY_SPECIFIED (decl) = true;
11336 1327 : targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN);
11337 : #ifdef ASM_WEAKEN_LABEL
11338 : /* We prefer a .weak because that handles duplicates from duplicate
11339 : archive members in a graceful way. */
11340 1327 : ASM_WEAKEN_LABEL (asm_out_file, oldsym);
11341 : #else
11342 : targetm.asm_out.globalize_label (asm_out_file, oldsym);
11343 : #endif
11344 1327 : ASM_OUTPUT_LABEL (asm_out_file, oldsym);
11345 : }
11346 :
11347 : /* Output debugging information. */
11348 104481 : output_compilation_unit_header (dwo_id
11349 : ? DW_UT_split_compile : DW_UT_compile);
11350 52365 : if (dwarf_version >= 5)
11351 : {
11352 50388 : if (dwo_id != NULL)
11353 2232 : for (int i = 0; i < 8; i++)
11354 3720 : dw2_asm_output_data (1, dwo_id[i], i == 0 ? "DWO id" : NULL);
11355 : }
11356 52365 : output_die (die);
11357 :
11358 : /* Leave the marks on the main CU, so we can check them in
11359 : output_pubnames. */
11360 52365 : if (oldsym)
11361 : {
11362 1327 : unmark_dies (die);
11363 1327 : die->die_id.die_symbol = oldsym;
11364 : }
11365 : }
11366 :
11367 : /* Whether to generate the DWARF accelerator tables in .debug_pubnames
11368 : and .debug_pubtypes. This is configured per-target, but can be
11369 : overridden by the -gpubnames or -gno-pubnames options. */
11370 :
11371 : static inline bool
11372 287362794 : want_pubnames (void)
11373 : {
11374 287362794 : if (debug_info_level <= DINFO_LEVEL_TERSE
11375 : /* Names and types go to the early debug part only. */
11376 287345541 : || in_lto_p)
11377 : return false;
11378 287344649 : if (debug_generate_pub_sections != -1)
11379 1449 : return debug_generate_pub_sections;
11380 287343200 : return targetm.want_debug_pub_sections;
11381 : }
11382 :
11383 : /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
11384 :
11385 : static void
11386 52425 : add_AT_pubnames (dw_die_ref die)
11387 : {
11388 52425 : if (want_pubnames ())
11389 256 : add_AT_flag (die, DW_AT_GNU_pubnames, 1);
11390 52425 : }
11391 :
11392 : /* Add a string attribute value to a skeleton DIE. */
11393 :
11394 : static inline void
11395 498 : add_skeleton_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
11396 : const char *str)
11397 : {
11398 498 : dw_attr_node attr;
11399 498 : struct indirect_string_node *node;
11400 :
11401 498 : if (! skeleton_debug_str_hash)
11402 249 : skeleton_debug_str_hash
11403 249 : = hash_table<indirect_string_hasher>::create_ggc (10);
11404 :
11405 498 : node = find_AT_string_in_table (str, skeleton_debug_str_hash);
11406 498 : find_string_form (node);
11407 500 : if (node->form == dwarf_FORM (DW_FORM_strx))
11408 498 : node->form = DW_FORM_strp;
11409 :
11410 498 : attr.dw_attr = attr_kind;
11411 498 : attr.dw_attr_val.val_class = dw_val_class_str;
11412 498 : attr.dw_attr_val.val_entry = NULL;
11413 498 : attr.dw_attr_val.v.val_str = node;
11414 498 : add_dwarf_attr (die, &attr);
11415 498 : }
11416 :
11417 : /* Helper function to generate top-level dies for skeleton debug_info and
11418 : debug_types. */
11419 :
11420 : static void
11421 249 : add_top_level_skeleton_die_attrs (dw_die_ref die)
11422 : {
11423 249 : const char *dwo_file_name = concat (aux_base_name, ".dwo", NULL);
11424 249 : const char *comp_dir = comp_dir_string ();
11425 :
11426 250 : add_skeleton_AT_string (die, dwarf_AT (DW_AT_dwo_name), dwo_file_name);
11427 249 : if (comp_dir != NULL)
11428 249 : add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
11429 249 : add_AT_pubnames (die);
11430 249 : if (addr_index_table != NULL && addr_index_table->size () > 0)
11431 244 : add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label);
11432 249 : }
11433 :
11434 : /* Output skeleton debug sections that point to the dwo file. */
11435 :
11436 : static void
11437 249 : output_skeleton_debug_sections (dw_die_ref comp_unit,
11438 : const unsigned char *dwo_id)
11439 : {
11440 : /* These attributes will be found in the full debug_info section. */
11441 249 : remove_AT (comp_unit, DW_AT_producer);
11442 249 : remove_AT (comp_unit, DW_AT_language);
11443 249 : remove_AT (comp_unit, DW_AT_language_name);
11444 249 : remove_AT (comp_unit, DW_AT_language_version);
11445 :
11446 249 : switch_to_section (debug_skeleton_info_section);
11447 249 : ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
11448 :
11449 : /* Produce the skeleton compilation-unit header. This one differs enough from
11450 : a normal CU header that it's better not to call output_compilation_unit
11451 : header. */
11452 249 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11453 0 : dw2_asm_output_data (4, 0xffffffff,
11454 : "Initial length escape value indicating 64-bit "
11455 : "DWARF extension");
11456 :
11457 249 : dw2_asm_output_data (dwarf_offset_size,
11458 250 : DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11459 249 : - DWARF_INITIAL_LENGTH_SIZE
11460 249 : + size_of_die (comp_unit),
11461 : "Length of Compilation Unit Info");
11462 249 : output_dwarf_version ();
11463 249 : if (dwarf_version >= 5)
11464 : {
11465 248 : dw2_asm_output_data (1, DW_UT_skeleton, "DW_UT_skeleton");
11466 248 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11467 : }
11468 249 : dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_abbrev_section_label,
11469 : debug_skeleton_abbrev_section,
11470 : "Offset Into Abbrev. Section");
11471 249 : if (dwarf_version < 5)
11472 1 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11473 : else
11474 2232 : for (int i = 0; i < 8; i++)
11475 3720 : dw2_asm_output_data (1, dwo_id[i], i == 0 ? "DWO id" : NULL);
11476 :
11477 249 : comp_unit->die_abbrev = SKELETON_COMP_DIE_ABBREV;
11478 249 : output_die (comp_unit);
11479 :
11480 : /* Build the skeleton debug_abbrev section. */
11481 249 : switch_to_section (debug_skeleton_abbrev_section);
11482 249 : ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
11483 :
11484 249 : output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
11485 :
11486 249 : dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
11487 249 : }
11488 :
11489 : /* Output a comdat type unit DIE and its children. */
11490 :
11491 : static void
11492 81 : output_comdat_type_unit (comdat_type_node *node,
11493 : bool early_lto_debug ATTRIBUTE_UNUSED)
11494 : {
11495 81 : const char *secname;
11496 81 : char *tmp;
11497 81 : int i;
11498 : #if defined (OBJECT_FORMAT_ELF)
11499 81 : tree comdat_key;
11500 : #endif
11501 :
11502 : /* First mark all the DIEs in this CU so we know which get local refs. */
11503 81 : mark_dies (node->root_die);
11504 :
11505 81 : external_ref_hash_type *extern_map = optimize_external_refs (node->root_die);
11506 :
11507 81 : build_abbrev_table (node->root_die, extern_map);
11508 :
11509 81 : delete extern_map;
11510 81 : extern_map = NULL;
11511 :
11512 : /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11513 81 : next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11514 81 : calc_die_sizes (node->root_die);
11515 :
11516 : #if defined (OBJECT_FORMAT_ELF)
11517 81 : if (dwarf_version >= 5)
11518 : {
11519 21 : if (!dwarf_split_debug_info)
11520 21 : secname = early_lto_debug ? DEBUG_LTO_INFO_SECTION : DEBUG_INFO_SECTION;
11521 : else
11522 0 : secname = (early_lto_debug
11523 0 : ? DEBUG_LTO_DWO_INFO_SECTION : DEBUG_DWO_INFO_SECTION);
11524 : }
11525 60 : else if (!dwarf_split_debug_info)
11526 60 : secname = early_lto_debug ? ".gnu.debuglto_.debug_types" : ".debug_types";
11527 : else
11528 0 : secname = (early_lto_debug
11529 0 : ? ".gnu.debuglto_.debug_types.dwo" : ".debug_types.dwo");
11530 :
11531 81 : tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11532 81 : sprintf (tmp, dwarf_version >= 5 ? "wi." : "wt.");
11533 729 : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11534 648 : sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11535 81 : comdat_key = get_identifier (tmp);
11536 81 : targetm.asm_out.named_section (secname,
11537 : SECTION_DEBUG | SECTION_LINKONCE,
11538 : comdat_key);
11539 : #else
11540 : tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11541 : sprintf (tmp, (dwarf_version >= 5
11542 : ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
11543 : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11544 : sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11545 : secname = tmp;
11546 : switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11547 : #endif
11548 :
11549 : /* Output debugging information. */
11550 162 : output_compilation_unit_header (dwarf_split_debug_info
11551 : ? DW_UT_split_type : DW_UT_type);
11552 81 : output_signature (node->signature, "Type Signature");
11553 81 : dw2_asm_output_data (dwarf_offset_size, node->type_die->die_offset,
11554 : "Offset to Type DIE");
11555 81 : output_die (node->root_die);
11556 :
11557 81 : unmark_dies (node->root_die);
11558 81 : }
11559 :
11560 : /* Return the DWARF2/3 pubname associated with a decl. */
11561 :
11562 : static const char *
11563 207164222 : dwarf2_name (tree decl, int scope)
11564 : {
11565 207164222 : if (DECL_NAMELESS (decl))
11566 : return NULL;
11567 414170342 : return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11568 : }
11569 :
11570 : /* Add a new entry to .debug_pubnames if appropriate. */
11571 :
11572 : static void
11573 536 : add_pubname_string (const char *str, dw_die_ref die)
11574 : {
11575 536 : pubname_entry e;
11576 :
11577 536 : e.die = die;
11578 536 : e.name = xstrdup (str);
11579 536 : vec_safe_push (pubname_table, e);
11580 536 : }
11581 :
11582 : static void
11583 130111729 : add_pubname (tree decl, dw_die_ref die)
11584 : {
11585 130111729 : if (!want_pubnames ())
11586 : return;
11587 :
11588 : /* Don't add items to the table when we expect that the consumer will have
11589 : just read the enclosing die. For example, if the consumer is looking at a
11590 : class_member, it will either be inside the class already, or will have just
11591 : looked up the class to find the member. Either way, searching the class is
11592 : faster than searching the index. */
11593 527 : if ((TREE_PUBLIC (decl) && !class_scope_p (die->die_parent))
11594 749 : || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
11595 : {
11596 503 : const char *name = dwarf2_name (decl, 1);
11597 :
11598 503 : if (name)
11599 503 : add_pubname_string (name, die);
11600 : }
11601 : }
11602 :
11603 : /* Add an enumerator to the pubnames section. */
11604 :
11605 : static void
11606 36 : add_enumerator_pubname (const char *scope_name, dw_die_ref die)
11607 : {
11608 36 : pubname_entry e;
11609 :
11610 36 : gcc_assert (scope_name);
11611 36 : e.name = concat (scope_name, get_AT_string (die, DW_AT_name), NULL);
11612 36 : e.die = die;
11613 36 : vec_safe_push (pubname_table, e);
11614 36 : }
11615 :
11616 : /* Add a new entry to .debug_pubtypes if appropriate. */
11617 :
11618 : static void
11619 156657554 : add_pubtype (tree decl, dw_die_ref die)
11620 : {
11621 156657554 : pubname_entry e;
11622 :
11623 156657554 : if (!want_pubnames ())
11624 156657240 : return;
11625 :
11626 314 : if ((TREE_PUBLIC (decl)
11627 494 : || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
11628 404 : && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11629 : {
11630 290 : tree scope = NULL;
11631 290 : const char *scope_name = "";
11632 290 : const char *sep = is_cxx () ? "::" : ".";
11633 290 : const char *name;
11634 :
11635 290 : scope = TYPE_P (decl) ? TYPE_CONTEXT (decl) : NULL;
11636 290 : if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
11637 : {
11638 60 : scope_name = lang_hooks.dwarf_name (scope, 1);
11639 60 : if (scope_name != NULL && scope_name[0] != '\0')
11640 60 : scope_name = concat (scope_name, sep, NULL);
11641 : else
11642 : scope_name = "";
11643 : }
11644 :
11645 290 : if (TYPE_P (decl))
11646 290 : name = type_tag (decl);
11647 : else
11648 0 : name = lang_hooks.dwarf_name (decl, 1);
11649 :
11650 : /* If we don't have a name for the type, there's no point in adding
11651 : it to the table. */
11652 290 : if (name != NULL && name[0] != '\0')
11653 : {
11654 290 : e.die = die;
11655 290 : e.name = concat (scope_name, name, NULL);
11656 290 : vec_safe_push (pubtype_table, e);
11657 : }
11658 :
11659 : /* Although it might be more consistent to add the pubinfo for the
11660 : enumerators as their dies are created, they should only be added if the
11661 : enum type meets the criteria above. So rather than re-check the parent
11662 : enum type whenever an enumerator die is created, just output them all
11663 : here. This isn't protected by the name conditional because anonymous
11664 : enums don't have names. */
11665 290 : if (die->die_tag == DW_TAG_enumeration_type)
11666 : {
11667 12 : dw_die_ref c;
11668 :
11669 36 : FOR_EACH_CHILD (die, c, add_enumerator_pubname (scope_name, c));
11670 : }
11671 : }
11672 : }
11673 :
11674 : /* Output a single entry in the pubnames table. */
11675 :
11676 : static void
11677 791 : output_pubname (dw_offset die_offset, pubname_entry *entry)
11678 : {
11679 791 : dw_die_ref die = entry->die;
11680 791 : int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
11681 :
11682 791 : dw2_asm_output_data (dwarf_offset_size, die_offset, "DIE offset");
11683 :
11684 791 : if (debug_generate_pub_sections == 2)
11685 : {
11686 : /* This logic follows gdb's method for determining the value of the flag
11687 : byte. */
11688 445 : uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE;
11689 445 : switch (die->die_tag)
11690 : {
11691 : case DW_TAG_typedef:
11692 : case DW_TAG_base_type:
11693 : case DW_TAG_subrange_type:
11694 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
11695 192 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
11696 : break;
11697 0 : case DW_TAG_enumerator:
11698 0 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11699 : GDB_INDEX_SYMBOL_KIND_VARIABLE);
11700 0 : if (!is_cxx ())
11701 0 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
11702 : break;
11703 244 : case DW_TAG_subprogram:
11704 244 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11705 : GDB_INDEX_SYMBOL_KIND_FUNCTION);
11706 244 : if (!is_ada ())
11707 244 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
11708 : break;
11709 0 : case DW_TAG_constant:
11710 0 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11711 : GDB_INDEX_SYMBOL_KIND_VARIABLE);
11712 0 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
11713 0 : break;
11714 6 : case DW_TAG_variable:
11715 6 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11716 : GDB_INDEX_SYMBOL_KIND_VARIABLE);
11717 6 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
11718 6 : break;
11719 : case DW_TAG_namespace:
11720 : case DW_TAG_imported_declaration:
11721 3 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
11722 : break;
11723 0 : case DW_TAG_class_type:
11724 0 : case DW_TAG_interface_type:
11725 0 : case DW_TAG_structure_type:
11726 0 : case DW_TAG_union_type:
11727 0 : case DW_TAG_enumeration_type:
11728 0 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
11729 0 : if (!is_cxx ())
11730 192 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
11731 : break;
11732 : default:
11733 : /* An unusual tag. Leave the flag-byte empty. */
11734 : break;
11735 : }
11736 445 : dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE,
11737 : "GDB-index flags");
11738 : }
11739 :
11740 791 : dw2_asm_output_nstring (entry->name, -1, "external name");
11741 791 : }
11742 :
11743 :
11744 : /* Output the public names table used to speed up access to externally
11745 : visible names; or the public types table used to find type definitions. */
11746 :
11747 : static void
11748 512 : output_pubnames (vec<pubname_entry, va_gc> *names)
11749 : {
11750 512 : unsigned i;
11751 512 : unsigned long pubnames_length = size_of_pubnames (names);
11752 512 : pubname_entry *pub;
11753 :
11754 512 : if (!XCOFF_DEBUGGING_INFO)
11755 : {
11756 512 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11757 0 : dw2_asm_output_data (4, 0xffffffff,
11758 : "Initial length escape value indicating 64-bit DWARF extension");
11759 512 : dw2_asm_output_data (dwarf_offset_size, pubnames_length,
11760 : "Pub Info Length");
11761 : }
11762 :
11763 : /* Version number for pubnames/pubtypes is independent of dwarf version. */
11764 512 : dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
11765 :
11766 512 : if (dwarf_split_debug_info)
11767 498 : dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
11768 : debug_skeleton_info_section,
11769 : "Offset of Compilation Unit Info");
11770 : else
11771 14 : dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
11772 : debug_info_section,
11773 : "Offset of Compilation Unit Info");
11774 512 : dw2_asm_output_data (dwarf_offset_size, next_die_offset,
11775 : "Compilation Unit Length");
11776 :
11777 1374 : FOR_EACH_VEC_ELT (*names, i, pub)
11778 : {
11779 862 : if (include_pubname_in_output (names, pub))
11780 : {
11781 791 : dw_offset die_offset = pub->die->die_offset;
11782 :
11783 : /* We shouldn't see pubnames for DIEs outside of the main CU. */
11784 791 : if (names == pubname_table && pub->die->die_tag != DW_TAG_enumerator)
11785 471 : gcc_assert (pub->die->die_mark);
11786 :
11787 : /* If we're putting types in their own .debug_types sections,
11788 : the .debug_pubtypes table will still point to the compile
11789 : unit (not the type unit), so we want to use the offset of
11790 : the skeleton DIE (if there is one). */
11791 791 : if (pub->die->comdat_type_p && names == pubtype_table)
11792 : {
11793 33 : comdat_type_node *type_node = pub->die->die_id.die_type_node;
11794 :
11795 33 : if (type_node != NULL)
11796 33 : die_offset = (type_node->skeleton_die != NULL
11797 33 : ? type_node->skeleton_die->die_offset
11798 6 : : comp_unit_die ()->die_offset);
11799 : }
11800 :
11801 791 : output_pubname (die_offset, pub);
11802 : }
11803 : }
11804 :
11805 512 : dw2_asm_output_data (dwarf_offset_size, 0, NULL);
11806 512 : }
11807 :
11808 : /* Output public names and types tables if necessary. */
11809 :
11810 : static void
11811 52080 : output_pubtables (void)
11812 : {
11813 52080 : if (!want_pubnames () || !info_section_emitted)
11814 : return;
11815 :
11816 256 : switch_to_section (debug_pubnames_section);
11817 256 : output_pubnames (pubname_table);
11818 : /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
11819 : It shouldn't hurt to emit it always, since pure DWARF2 consumers
11820 : simply won't look for the section. */
11821 256 : switch_to_section (debug_pubtypes_section);
11822 256 : output_pubnames (pubtype_table);
11823 : }
11824 :
11825 :
11826 : /* Output the information that goes into the .debug_aranges table.
11827 : Namely, define the beginning and ending address range of the
11828 : text section generated for this compilation unit. */
11829 :
11830 : static void
11831 51038 : output_aranges (void)
11832 : {
11833 51038 : unsigned i;
11834 51038 : unsigned long aranges_length = size_of_aranges ();
11835 :
11836 51038 : if (!XCOFF_DEBUGGING_INFO)
11837 : {
11838 51038 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11839 0 : dw2_asm_output_data (4, 0xffffffff,
11840 : "Initial length escape value indicating 64-bit DWARF extension");
11841 51038 : dw2_asm_output_data (dwarf_offset_size, aranges_length,
11842 : "Length of Address Ranges Info");
11843 : }
11844 :
11845 : /* Version number for aranges is still 2, even up to DWARF5. */
11846 51038 : dw2_asm_output_data (2, 2, "DWARF aranges version");
11847 51038 : if (dwarf_split_debug_info)
11848 249 : dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
11849 : debug_skeleton_info_section,
11850 : "Offset of Compilation Unit Info");
11851 : else
11852 50789 : dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
11853 : debug_info_section,
11854 : "Offset of Compilation Unit Info");
11855 57373 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11856 51038 : dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11857 :
11858 : /* We need to align to twice the pointer size here. */
11859 70043 : if (DWARF_ARANGES_PAD_SIZE)
11860 : {
11861 : /* Pad using a 2 byte words so that padding is correct for any
11862 : pointer size. */
11863 51038 : dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11864 51036 : 2 * DWARF2_ADDR_SIZE);
11865 191124 : for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11866 51038 : dw2_asm_output_data (2, 0, NULL);
11867 : }
11868 :
11869 : /* It is necessary not to output these entries if the sections were
11870 : not used; if the sections were not used, the length will be 0 and
11871 : the address may end up as 0 if the section is discarded by ld
11872 : --gc-sections, leaving an invalid (0, 0) entry that can be
11873 : confused with the terminator. */
11874 51038 : if (switch_text_ranges)
11875 : {
11876 : const char *prev_loc = text_section_label;
11877 : const char *loc;
11878 : unsigned idx;
11879 :
11880 30514 : FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
11881 996 : if (prev_loc)
11882 : {
11883 795 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11884 589 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, loc, prev_loc, "Length");
11885 589 : prev_loc = NULL;
11886 : }
11887 : else
11888 : prev_loc = loc;
11889 :
11890 29518 : if (prev_loc)
11891 : {
11892 32367 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11893 32367 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11894 : prev_loc, "Length");
11895 : }
11896 : }
11897 :
11898 51038 : if (switch_cold_ranges)
11899 : {
11900 : const char *prev_loc = cold_text_section_label;
11901 : const char *loc;
11902 : unsigned idx;
11903 :
11904 8667 : FOR_EACH_VEC_ELT (*switch_cold_ranges, idx, loc)
11905 0 : if (prev_loc)
11906 : {
11907 0 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11908 0 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, loc, prev_loc, "Length");
11909 0 : prev_loc = NULL;
11910 : }
11911 : else
11912 : prev_loc = loc;
11913 :
11914 8667 : if (prev_loc)
11915 : {
11916 8987 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11917 8987 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11918 : prev_loc, "Length");
11919 : }
11920 : }
11921 :
11922 51038 : if (have_multiple_function_sections)
11923 : {
11924 : unsigned fde_idx;
11925 : dw_fde_ref fde;
11926 :
11927 287376 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
11928 : {
11929 259222 : if (fde->ignored_debug)
11930 2917 : continue;
11931 256305 : if (!fde->in_std_section)
11932 : {
11933 194722 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
11934 : "Address");
11935 194722 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
11936 : fde->dw_fde_begin, "Length");
11937 : }
11938 256305 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11939 : {
11940 10152 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
11941 : "Address");
11942 10152 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
11943 : fde->dw_fde_second_begin, "Length");
11944 : }
11945 : }
11946 : }
11947 :
11948 : /* Output the terminator words. */
11949 57373 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11950 57373 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11951 51038 : }
11952 :
11953 : /* Add a new entry to .debug_ranges. Return its index into
11954 : ranges_table vector. */
11955 :
11956 : static unsigned int
11957 10830637 : add_ranges_num (int num, bool maybe_new_sec)
11958 : {
11959 10830637 : dw_ranges r = { NULL, num, 0, maybe_new_sec, NULL, NULL };
11960 10830637 : vec_safe_push (ranges_table, r);
11961 10830637 : return vec_safe_length (ranges_table) - 1;
11962 : }
11963 :
11964 : /* Add a new entry to .debug_ranges corresponding to a block, or a
11965 : range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11966 : this entry might be in a different section from previous range. */
11967 :
11968 : static unsigned int
11969 10576439 : add_ranges (const_tree block, bool maybe_new_sec)
11970 : {
11971 15792746 : return add_ranges_num (block ? BLOCK_NUMBER (block) : 0, maybe_new_sec);
11972 : }
11973 :
11974 : /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11975 : chain, or middle entry of a chain that will be directly referred to. */
11976 :
11977 : static void
11978 3212559 : note_rnglist_head (unsigned int offset)
11979 : {
11980 3212559 : if (dwarf_version < 5 || (*ranges_table)[offset].label)
11981 : return;
11982 2684344 : (*ranges_table)[offset].label = gen_internal_sym ("LLRL");
11983 : }
11984 :
11985 : /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11986 : When using dwarf_split_debug_info, address attributes in dies destined
11987 : for the final executable should be direct references--setting the
11988 : parameter force_direct ensures this behavior. */
11989 :
11990 : static void
11991 254198 : add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11992 : bool *added, bool force_direct)
11993 : {
11994 254198 : unsigned int in_use = vec_safe_length (ranges_by_label);
11995 254198 : unsigned int offset;
11996 254198 : dw_ranges_by_label rbl = { begin, end };
11997 254198 : vec_safe_push (ranges_by_label, rbl);
11998 254198 : offset = add_ranges_num (-(int)in_use - 1, true);
11999 254198 : if (!*added)
12000 : {
12001 49035 : add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
12002 49035 : *added = true;
12003 49035 : note_rnglist_head (offset);
12004 49035 : if (dwarf_split_debug_info && force_direct)
12005 2 : (*ranges_table)[offset].idx = DW_RANGES_IDX_SKELETON;
12006 : }
12007 254198 : }
12008 :
12009 : /* Emit .debug_ranges section. */
12010 :
12011 : static void
12012 524 : output_ranges (void)
12013 : {
12014 524 : unsigned i;
12015 524 : static const char *const start_fmt = "Offset %#x";
12016 524 : const char *fmt = start_fmt;
12017 524 : dw_ranges *r;
12018 :
12019 524 : switch_to_section (debug_ranges_section);
12020 524 : ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12021 4589 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12022 : {
12023 4065 : int block_num = r->num;
12024 :
12025 4065 : if (block_num > 0)
12026 : {
12027 1710 : char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12028 1710 : char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12029 :
12030 1710 : ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12031 1710 : ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12032 :
12033 : /* If all code is in the text section, then the compilation
12034 : unit base address defaults to DW_AT_low_pc, which is the
12035 : base of the text section. */
12036 1710 : if (!have_multiple_function_sections)
12037 : {
12038 418 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
12039 : text_section_label,
12040 418 : fmt, i * 2 * DWARF2_ADDR_SIZE);
12041 418 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
12042 : text_section_label, NULL);
12043 : }
12044 :
12045 : /* Otherwise, the compilation unit base address is zero,
12046 : which allows us to use absolute addresses, and not worry
12047 : about whether the target supports cross-section
12048 : arithmetic. */
12049 : else
12050 : {
12051 1292 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12052 1292 : fmt, i * 2 * DWARF2_ADDR_SIZE);
12053 1292 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
12054 : }
12055 :
12056 1710 : fmt = NULL;
12057 : }
12058 :
12059 : /* Negative block_num stands for an index into ranges_by_label. */
12060 2355 : else if (block_num < 0)
12061 : {
12062 1265 : int lab_idx = - block_num - 1;
12063 :
12064 1265 : if (!have_multiple_function_sections)
12065 : {
12066 0 : gcc_unreachable ();
12067 : #if 0
12068 : /* If we ever use add_ranges_by_labels () for a single
12069 : function section, all we have to do is to take out
12070 : the #if 0 above. */
12071 : dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12072 : (*ranges_by_label)[lab_idx].begin,
12073 : text_section_label,
12074 : fmt, i * 2 * DWARF2_ADDR_SIZE);
12075 : dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12076 : (*ranges_by_label)[lab_idx].end,
12077 : text_section_label, NULL);
12078 : #endif
12079 : }
12080 : else
12081 : {
12082 1265 : dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12083 1265 : (*ranges_by_label)[lab_idx].begin,
12084 1265 : fmt, i * 2 * DWARF2_ADDR_SIZE);
12085 1265 : dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12086 1265 : (*ranges_by_label)[lab_idx].end,
12087 : NULL);
12088 : }
12089 : }
12090 : else
12091 : {
12092 1090 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12093 1090 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12094 1090 : fmt = start_fmt;
12095 : }
12096 : }
12097 524 : }
12098 :
12099 : /* Non-zero if .debug_line_str should be used for .debug_line section
12100 : strings or strings that are likely shareable with those. */
12101 : #define DWARF5_USE_DEBUG_LINE_STR \
12102 : (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
12103 : && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
12104 : /* FIXME: there is no .debug_line_str.dwo section, \
12105 : for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
12106 : && !dwarf_split_debug_info)
12107 :
12108 :
12109 : /* Returns TRUE if we are outputting DWARF5 and the assembler supports
12110 : DWARF5 .debug_line tables using .debug_line_str or we generate
12111 : it ourselves, except for split-dwarf which doesn't have a
12112 : .debug_line_str. */
12113 : static bool
12114 159020 : asm_outputs_debug_line_str (void)
12115 : {
12116 159020 : if (dwarf_version >= 5
12117 152934 : && ! output_asm_line_debug_info ()
12118 159026 : && DWARF5_USE_DEBUG_LINE_STR)
12119 : return true;
12120 : else
12121 : {
12122 : #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
12123 165844 : return !dwarf_split_debug_info && dwarf_version >= 5;
12124 : #else
12125 : return false;
12126 : #endif
12127 : }
12128 : }
12129 :
12130 : /* Return true if it is beneficial to use DW_RLE_base_address{,x}.
12131 : I is index of the following range. */
12132 :
12133 : static bool
12134 2518370 : use_distinct_base_address_for_range (unsigned int i)
12135 : {
12136 2673258 : if (i >= vec_safe_length (ranges_table))
12137 : return false;
12138 :
12139 2518370 : dw_ranges *r2 = &(*ranges_table)[i];
12140 : /* Use DW_RLE_base_address{,x} if there is a next range in the
12141 : range list and is guaranteed to be in the same section. */
12142 2518370 : return r2->num != 0 && r2->label == NULL && !r2->maybe_new_sec;
12143 : }
12144 :
12145 : /* Assign .debug_rnglists indexes and unique indexes into the debug_addr
12146 : section when needed. */
12147 :
12148 : static void
12149 3 : index_rnglists (void)
12150 : {
12151 3 : unsigned i;
12152 3 : dw_ranges *r;
12153 3 : bool base = false;
12154 :
12155 19 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12156 : {
12157 16 : if (r->label && r->idx != DW_RANGES_IDX_SKELETON)
12158 3 : r->idx = rnglist_idx++;
12159 :
12160 16 : int block_num = r->num;
12161 20 : if ((HAVE_AS_LEB128 || block_num < 0)
12162 16 : && !have_multiple_function_sections)
12163 4 : continue;
12164 12 : if (HAVE_AS_LEB128 && (r->label || r->maybe_new_sec))
12165 8 : base = false;
12166 12 : if (block_num > 0)
12167 : {
12168 0 : char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12169 0 : char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12170 :
12171 0 : ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12172 0 : ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12173 :
12174 0 : if (HAVE_AS_LEB128)
12175 : {
12176 0 : if (!base && use_distinct_base_address_for_range (i + 1))
12177 : {
12178 0 : r->begin_entry = add_addr_table_entry (xstrdup (blabel),
12179 : ate_kind_label);
12180 0 : base = true;
12181 : }
12182 0 : if (base)
12183 : /* If we have a base, no need for further
12184 : begin_entry/end_entry, as DW_RLE_offset_pair will be
12185 : used. */
12186 0 : continue;
12187 0 : r->begin_entry
12188 0 : = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
12189 : /* No need for end_entry, DW_RLE_start{,x}_length will use
12190 : length as opposed to a pair of addresses. */
12191 : }
12192 : else
12193 : {
12194 : r->begin_entry
12195 : = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
12196 : r->end_entry
12197 : = add_addr_table_entry (xstrdup (elabel), ate_kind_label);
12198 : }
12199 : }
12200 :
12201 : /* Negative block_num stands for an index into ranges_by_label. */
12202 12 : else if (block_num < 0)
12203 : {
12204 8 : int lab_idx = - block_num - 1;
12205 8 : const char *blabel = (*ranges_by_label)[lab_idx].begin;
12206 8 : const char *elabel = (*ranges_by_label)[lab_idx].end;
12207 :
12208 8 : r->begin_entry
12209 8 : = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
12210 8 : if (!HAVE_AS_LEB128)
12211 : r->end_entry
12212 : = add_addr_table_entry (xstrdup (elabel), ate_kind_label);
12213 : }
12214 : }
12215 3 : }
12216 :
12217 : /* Emit .debug_rnglists or (when DWO is true) .debug_rnglists.dwo section. */
12218 :
12219 : static bool
12220 32375 : output_rnglists (unsigned generation, bool dwo)
12221 : {
12222 32375 : unsigned i;
12223 32375 : dw_ranges *r;
12224 32375 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
12225 32375 : char l2[MAX_ARTIFICIAL_LABEL_BYTES];
12226 32375 : char basebuf[MAX_ARTIFICIAL_LABEL_BYTES];
12227 :
12228 32375 : if (dwo)
12229 3 : switch_to_section (debug_ranges_dwo_section);
12230 : else
12231 : {
12232 32372 : switch_to_section (debug_ranges_section);
12233 32372 : ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12234 : }
12235 : /* There are up to 4 unique ranges labels per generation.
12236 : See also init_sections_and_labels. */
12237 32375 : ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_RANGES_SECTION_LABEL,
12238 : 2 + 2 * dwo + generation * 6);
12239 32375 : ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_RANGES_SECTION_LABEL,
12240 : 3 + 2 * dwo + generation * 6);
12241 32375 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
12242 0 : dw2_asm_output_data (4, 0xffffffff,
12243 : "Initial length escape value indicating "
12244 : "64-bit DWARF extension");
12245 32375 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
12246 : "Length of Range Lists");
12247 32375 : ASM_OUTPUT_LABEL (asm_out_file, l1);
12248 32375 : output_dwarf_version ();
12249 36881 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
12250 32375 : dw2_asm_output_data (1, 0, "Segment Size");
12251 : /* Emit the offset table only for -gsplit-dwarf. If we don't care
12252 : about relocation sizes and primarily care about the size of .debug*
12253 : sections in linked shared libraries and executables, then
12254 : the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
12255 : into it are usually larger than just DW_FORM_sec_offset offsets
12256 : into the .debug_rnglists section. */
12257 32375 : dw2_asm_output_data (4, dwo ? rnglist_idx : 0,
12258 : "Offset Entry Count");
12259 32375 : if (dwo)
12260 : {
12261 3 : ASM_OUTPUT_LABEL (asm_out_file, ranges_base_label);
12262 22 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12263 16 : if (r->label && r->idx != DW_RANGES_IDX_SKELETON)
12264 3 : dw2_asm_output_delta (dwarf_offset_size, r->label,
12265 : ranges_base_label, NULL);
12266 : }
12267 :
12268 : const char *lab = "";
12269 : const char *base = NULL;
12270 : bool skipping = false;
12271 : bool ret = false;
12272 10858956 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12273 : {
12274 10826581 : int block_num = r->num;
12275 :
12276 10826581 : if (r->label)
12277 : {
12278 2684347 : if (dwarf_split_debug_info
12279 9 : && (r->idx == DW_RANGES_IDX_SKELETON) == dwo)
12280 : {
12281 4 : ret = true;
12282 4 : skipping = true;
12283 4 : continue;
12284 : }
12285 2684343 : ASM_OUTPUT_LABEL (asm_out_file, r->label);
12286 2684343 : lab = r->label;
12287 : }
12288 10826577 : if (skipping)
12289 : {
12290 8 : if (block_num == 0)
12291 4 : skipping = false;
12292 8 : continue;
12293 : }
12294 10826569 : if (HAVE_AS_LEB128 && (r->label || r->maybe_new_sec))
12295 3016728 : base = NULL;
12296 10826569 : if (block_num > 0)
12297 : {
12298 7894661 : char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12299 7894661 : char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12300 :
12301 7894661 : ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12302 7894661 : ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12303 :
12304 7894661 : if (HAVE_AS_LEB128)
12305 : {
12306 : /* If all code is in the text section, then the compilation
12307 : unit base address defaults to DW_AT_low_pc, which is the
12308 : base of the text section. */
12309 7894661 : if (!have_multiple_function_sections)
12310 : {
12311 831637 : dw2_asm_output_data (1, DW_RLE_offset_pair,
12312 : "DW_RLE_offset_pair (%s)", lab);
12313 831637 : dw2_asm_output_delta_uleb128 (blabel, text_section_label,
12314 : "Range begin address (%s)", lab);
12315 831637 : dw2_asm_output_delta_uleb128 (elabel, text_section_label,
12316 : "Range end address (%s)", lab);
12317 7739773 : continue;
12318 : }
12319 7063024 : if (base == NULL && use_distinct_base_address_for_range (i + 1))
12320 : {
12321 2363482 : if (dwarf_split_debug_info)
12322 : {
12323 0 : dw2_asm_output_data (1, DW_RLE_base_addressx,
12324 : "DW_RLE_base_addressx (%s)", lab);
12325 0 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12326 : "Base address index (%s)",
12327 : blabel);
12328 : }
12329 : else
12330 : {
12331 2363482 : dw2_asm_output_data (1, DW_RLE_base_address,
12332 : "DW_RLE_base_address (%s)", lab);
12333 2463055 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12334 : "Base address (%s)", lab);
12335 : }
12336 2363482 : strcpy (basebuf, blabel);
12337 2363482 : base = basebuf;
12338 : }
12339 7063024 : if (base)
12340 : {
12341 6908136 : dw2_asm_output_data (1, DW_RLE_offset_pair,
12342 : "DW_RLE_offset_pair (%s)", lab);
12343 6908136 : dw2_asm_output_delta_uleb128 (blabel, base,
12344 : "Range begin address (%s)", lab);
12345 6908136 : dw2_asm_output_delta_uleb128 (elabel, base,
12346 : "Range end address (%s)", lab);
12347 6908136 : continue;
12348 : }
12349 154888 : if (dwarf_split_debug_info)
12350 : {
12351 0 : dw2_asm_output_data (1, DW_RLE_startx_length,
12352 : "DW_RLE_startx_length (%s)", lab);
12353 0 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12354 : "Range begin address index "
12355 : "(%s)", blabel);
12356 : }
12357 : else
12358 : {
12359 154888 : dw2_asm_output_data (1, DW_RLE_start_length,
12360 : "DW_RLE_start_length (%s)", lab);
12361 158803 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12362 : "Range begin address (%s)", lab);
12363 : }
12364 154888 : dw2_asm_output_delta_uleb128 (elabel, blabel,
12365 : "Range length (%s)", lab);
12366 : }
12367 : else if (dwarf_split_debug_info)
12368 : {
12369 : dw2_asm_output_data (1, DW_RLE_startx_endx,
12370 : "DW_RLE_startx_endx (%s)", lab);
12371 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12372 : "Range begin address index "
12373 : "(%s)", blabel);
12374 : dw2_asm_output_data_uleb128 (r->end_entry->index,
12375 : "Range end address index "
12376 : "(%s)", elabel);
12377 : }
12378 : else
12379 : {
12380 : dw2_asm_output_data (1, DW_RLE_start_end,
12381 : "DW_RLE_start_end (%s)", lab);
12382 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12383 : "Range begin address (%s)", lab);
12384 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel,
12385 : "Range end address (%s)", lab);
12386 : }
12387 : }
12388 :
12389 : /* Negative block_num stands for an index into ranges_by_label. */
12390 2931908 : else if (block_num < 0)
12391 : {
12392 252933 : int lab_idx = - block_num - 1;
12393 252933 : const char *blabel = (*ranges_by_label)[lab_idx].begin;
12394 252933 : const char *elabel = (*ranges_by_label)[lab_idx].end;
12395 :
12396 252933 : if (!have_multiple_function_sections)
12397 0 : gcc_unreachable ();
12398 252933 : if (HAVE_AS_LEB128)
12399 : {
12400 252933 : if (dwarf_split_debug_info)
12401 : {
12402 8 : dw2_asm_output_data (1, DW_RLE_startx_length,
12403 : "DW_RLE_startx_length (%s)", lab);
12404 8 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12405 : "Range begin address index "
12406 : "(%s)", blabel);
12407 : }
12408 : else
12409 : {
12410 252925 : dw2_asm_output_data (1, DW_RLE_start_length,
12411 : "DW_RLE_start_length (%s)", lab);
12412 268183 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12413 : "Range begin address (%s)", lab);
12414 : }
12415 252933 : dw2_asm_output_delta_uleb128 (elabel, blabel,
12416 : "Range length (%s)", lab);
12417 : }
12418 : else if (dwarf_split_debug_info)
12419 : {
12420 : dw2_asm_output_data (1, DW_RLE_startx_endx,
12421 : "DW_RLE_startx_endx (%s)", lab);
12422 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12423 : "Range begin address index "
12424 : "(%s)", blabel);
12425 : dw2_asm_output_data_uleb128 (r->end_entry->index,
12426 : "Range end address index "
12427 : "(%s)", elabel);
12428 : }
12429 : else
12430 : {
12431 : dw2_asm_output_data (1, DW_RLE_start_end,
12432 : "DW_RLE_start_end (%s)", lab);
12433 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12434 : "Range begin address (%s)", lab);
12435 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel,
12436 : "Range end address (%s)", lab);
12437 : }
12438 : }
12439 : else
12440 2678975 : dw2_asm_output_data (1, DW_RLE_end_of_list,
12441 : "DW_RLE_end_of_list (%s)", lab);
12442 : }
12443 32375 : ASM_OUTPUT_LABEL (asm_out_file, l2);
12444 32375 : return ret;
12445 : }
12446 :
12447 : /* Data structure containing information about input files. */
12448 : struct file_info
12449 : {
12450 : const char *path; /* Complete file name. */
12451 : const char *fname; /* File name part. */
12452 : int length; /* Length of entire string. */
12453 : struct dwarf_file_data * file_idx; /* Index in input file table. */
12454 : int dir_idx; /* Index in directory table. */
12455 : };
12456 :
12457 : /* Data structure containing information about directories with source
12458 : files. */
12459 : struct dir_info
12460 : {
12461 : const char *path; /* Path including directory name. */
12462 : int length; /* Path length. */
12463 : int prefix; /* Index of directory entry which is a prefix. */
12464 : int count; /* Number of files in this directory. */
12465 : int dir_idx; /* Index of directory used as base. */
12466 : };
12467 :
12468 : /* Callback function for file_info comparison. We sort by looking at
12469 : the directories in the path. */
12470 :
12471 : static int
12472 103382 : file_info_cmp (const void *p1, const void *p2)
12473 : {
12474 103382 : const struct file_info *const s1 = (const struct file_info *) p1;
12475 103382 : const struct file_info *const s2 = (const struct file_info *) p2;
12476 103382 : const unsigned char *cp1;
12477 103382 : const unsigned char *cp2;
12478 :
12479 : /* Take care of file names without directories. We need to make sure that
12480 : we return consistent values to qsort since some will get confused if
12481 : we return the same value when identical operands are passed in opposite
12482 : orders. So if neither has a directory, return 0 and otherwise return
12483 : 1 or -1 depending on which one has the directory. We want the one with
12484 : the directory to sort after the one without, so all no directory files
12485 : are at the start (normally only the compilation unit file). */
12486 103382 : if ((s1->path == s1->fname || s2->path == s2->fname))
12487 1866 : return (s2->path == s2->fname) - (s1->path == s1->fname);
12488 :
12489 : cp1 = (const unsigned char *) s1->path;
12490 : cp2 = (const unsigned char *) s2->path;
12491 :
12492 4448529 : while (1)
12493 : {
12494 4448529 : ++cp1;
12495 4448529 : ++cp2;
12496 : /* Reached the end of the first path? If so, handle like above,
12497 : but now we want longer directory prefixes before shorter ones. */
12498 4448529 : if ((cp1 == (const unsigned char *) s1->fname)
12499 4409619 : || (cp2 == (const unsigned char *) s2->fname))
12500 56280 : return ((cp1 == (const unsigned char *) s1->fname)
12501 56280 : - (cp2 == (const unsigned char *) s2->fname));
12502 :
12503 : /* Character of current path component the same? */
12504 4392249 : else if (*cp1 != *cp2)
12505 45236 : return *cp1 - *cp2;
12506 : }
12507 : }
12508 :
12509 : struct file_name_acquire_data
12510 : {
12511 : struct file_info *files;
12512 : int used_files;
12513 : int max_files;
12514 : };
12515 :
12516 : /* Traversal function for the hash table. */
12517 :
12518 : int
12519 9443 : file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
12520 : {
12521 9443 : struct dwarf_file_data *d = *slot;
12522 9443 : struct file_info *fi;
12523 9443 : const char *f;
12524 :
12525 9443 : gcc_assert (fnad->max_files >= d->emitted_number);
12526 :
12527 9443 : if (! d->emitted_number)
12528 : return 1;
12529 :
12530 4686 : gcc_assert (fnad->max_files != fnad->used_files);
12531 :
12532 4686 : fi = fnad->files + fnad->used_files++;
12533 :
12534 4686 : f = d->filename;
12535 :
12536 : /* Skip all leading "./". */
12537 4686 : while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12538 0 : f += 2;
12539 :
12540 : /* Create a new array entry. */
12541 4686 : fi->path = f;
12542 4686 : fi->length = strlen (f);
12543 4686 : fi->file_idx = d;
12544 :
12545 : /* Search for the file name part. */
12546 4686 : f = strrchr (f, DIR_SEPARATOR);
12547 : #if defined (DIR_SEPARATOR_2)
12548 : {
12549 : const char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12550 :
12551 : if (g != NULL)
12552 : {
12553 : if (f == NULL || f < g)
12554 : f = g;
12555 : }
12556 : }
12557 : #endif
12558 :
12559 4686 : fi->fname = f == NULL ? fi->path : f + 1;
12560 4686 : return 1;
12561 : }
12562 :
12563 : /* Helper function for output_file_names. Emit a FORM encoded
12564 : string STR, with assembly comment start ENTRY_KIND and
12565 : index IDX */
12566 :
12567 : static void
12568 9440 : output_line_string (enum dwarf_form form, const char *str,
12569 : const char *entry_kind, unsigned int idx)
12570 : {
12571 9440 : switch (form)
12572 : {
12573 563 : case DW_FORM_string:
12574 563 : dw2_asm_output_nstring (str, -1, "%s: %#x", entry_kind, idx);
12575 563 : break;
12576 8877 : case DW_FORM_line_strp:
12577 8877 : if (!debug_line_str_hash)
12578 0 : debug_line_str_hash
12579 0 : = hash_table<indirect_string_hasher>::create_ggc (10);
12580 :
12581 8877 : struct indirect_string_node *node;
12582 8877 : node = find_AT_string_in_table (str, debug_line_str_hash);
12583 8877 : set_indirect_string (node);
12584 8877 : node->form = form;
12585 8877 : dw2_asm_output_offset (dwarf_offset_size, node->label,
12586 : debug_line_str_section, "%s: %#x: \"%s\"",
12587 : entry_kind, 0, node->str);
12588 8877 : break;
12589 0 : default:
12590 0 : gcc_unreachable ();
12591 : }
12592 9440 : }
12593 :
12594 : /* Output the directory table and the file name table. We try to minimize
12595 : the total amount of memory needed. A heuristic is used to avoid large
12596 : slowdowns with many input files. */
12597 :
12598 : static void
12599 1582 : output_file_names (void)
12600 : {
12601 1582 : struct file_name_acquire_data fnad;
12602 1582 : int numfiles;
12603 1582 : struct file_info *files;
12604 1582 : struct dir_info *dirs;
12605 1582 : int *saved;
12606 1582 : int *savehere;
12607 1582 : int *backmap;
12608 1582 : int ndirs;
12609 1582 : int idx_offset;
12610 1582 : int i;
12611 :
12612 1582 : if (!last_emitted_file)
12613 : {
12614 17 : if (dwarf_version >= 5)
12615 : {
12616 17 : const char *comp_dir = comp_dir_string ();
12617 17 : if (comp_dir == NULL)
12618 0 : comp_dir = "";
12619 17 : dw2_asm_output_data (1, 1, "Directory entry format count");
12620 17 : enum dwarf_form str_form = DW_FORM_string;
12621 17 : if (DWARF5_USE_DEBUG_LINE_STR)
12622 17 : str_form = DW_FORM_line_strp;
12623 17 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12624 17 : dw2_asm_output_data_uleb128 (str_form, "%s",
12625 : get_DW_FORM_name (str_form));
12626 17 : dw2_asm_output_data_uleb128 (1, "Directories count");
12627 17 : if (str_form == DW_FORM_string)
12628 3 : dw2_asm_output_nstring (comp_dir, -1, "Directory Entry: %#x", 0);
12629 : else
12630 14 : output_line_string (str_form, comp_dir, "Directory Entry", 0);
12631 17 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
12632 17 : if (filename0 == NULL)
12633 0 : filename0 = "";
12634 : #ifdef VMS_DEBUGGING_INFO
12635 : dw2_asm_output_data (1, 4, "File name entry format count");
12636 : #else
12637 17 : dw2_asm_output_data (1, 2, "File name entry format count");
12638 : #endif
12639 17 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12640 17 : dw2_asm_output_data_uleb128 (str_form, "%s",
12641 : get_DW_FORM_name (str_form));
12642 17 : dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
12643 : "DW_LNCT_directory_index");
12644 17 : dw2_asm_output_data_uleb128 (DW_FORM_data1, "%s",
12645 : get_DW_FORM_name (DW_FORM_data1));
12646 : #ifdef VMS_DEBUGGING_INFO
12647 : dw2_asm_output_data_uleb128 (DW_LNCT_timestamp, "DW_LNCT_timestamp");
12648 : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12649 : dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
12650 : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12651 : #endif
12652 17 : dw2_asm_output_data_uleb128 (1, "File names count");
12653 :
12654 17 : output_line_string (str_form, filename0, "File Entry", 0);
12655 17 : dw2_asm_output_data (1, 0, NULL);
12656 : #ifdef VMS_DEBUGGING_INFO
12657 : dw2_asm_output_data_uleb128 (0, NULL);
12658 : dw2_asm_output_data_uleb128 (0, NULL);
12659 : #endif
12660 : }
12661 : else
12662 : {
12663 0 : dw2_asm_output_data (1, 0, "End directory table");
12664 0 : dw2_asm_output_data (1, 0, "End file name table");
12665 : }
12666 17 : return;
12667 : }
12668 :
12669 1565 : numfiles = last_emitted_file->emitted_number;
12670 :
12671 : /* Allocate the various arrays we need. */
12672 1565 : files = XALLOCAVEC (struct file_info, numfiles);
12673 1565 : dirs = XALLOCAVEC (struct dir_info, numfiles);
12674 :
12675 1565 : fnad.files = files;
12676 1565 : fnad.used_files = 0;
12677 1565 : fnad.max_files = numfiles;
12678 11008 : file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
12679 1565 : gcc_assert (fnad.used_files == fnad.max_files);
12680 :
12681 1565 : qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12682 :
12683 : /* Find all the different directories used. */
12684 1565 : dirs[0].path = files[0].path;
12685 1565 : dirs[0].length = files[0].fname - files[0].path;
12686 1565 : dirs[0].prefix = -1;
12687 1565 : dirs[0].count = 1;
12688 1565 : dirs[0].dir_idx = 0;
12689 1565 : files[0].dir_idx = 0;
12690 1565 : ndirs = 1;
12691 :
12692 4686 : for (i = 1; i < numfiles; i++)
12693 3121 : if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12694 2190 : && memcmp (dirs[ndirs - 1].path, files[i].path,
12695 : dirs[ndirs - 1].length) == 0)
12696 : {
12697 : /* Same directory as last entry. */
12698 2187 : files[i].dir_idx = ndirs - 1;
12699 2187 : ++dirs[ndirs - 1].count;
12700 : }
12701 : else
12702 : {
12703 934 : int j;
12704 :
12705 : /* This is a new directory. */
12706 934 : dirs[ndirs].path = files[i].path;
12707 934 : dirs[ndirs].length = files[i].fname - files[i].path;
12708 934 : dirs[ndirs].count = 1;
12709 934 : dirs[ndirs].dir_idx = ndirs;
12710 934 : files[i].dir_idx = ndirs;
12711 :
12712 : /* Search for a prefix. */
12713 934 : dirs[ndirs].prefix = -1;
12714 4852 : for (j = 0; j < ndirs; j++)
12715 3918 : if (dirs[j].length < dirs[ndirs].length
12716 1396 : && dirs[j].length > 1
12717 949 : && (dirs[ndirs].prefix == -1
12718 0 : || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12719 949 : && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12720 0 : dirs[ndirs].prefix = j;
12721 :
12722 934 : ++ndirs;
12723 : }
12724 :
12725 : /* Now to the actual work. We have to find a subset of the directories which
12726 : allow expressing the file name using references to the directory table
12727 : with the least amount of characters. We do not do an exhaustive search
12728 : where we would have to check out every combination of every single
12729 : possible prefix. Instead we use a heuristic which provides nearly optimal
12730 : results in most cases and never is much off. */
12731 1565 : saved = XALLOCAVEC (int, ndirs);
12732 1565 : savehere = XALLOCAVEC (int, ndirs);
12733 :
12734 1565 : memset (saved, '\0', ndirs * sizeof (saved[0]));
12735 4064 : for (i = 0; i < ndirs; i++)
12736 : {
12737 2499 : int j;
12738 2499 : int total;
12739 :
12740 : /* We can always save some space for the current directory. But this
12741 : does not mean it will be enough to justify adding the directory. */
12742 2499 : savehere[i] = dirs[i].length;
12743 2499 : total = (savehere[i] - saved[i]) * dirs[i].count;
12744 :
12745 6417 : for (j = i + 1; j < ndirs; j++)
12746 : {
12747 3918 : savehere[j] = 0;
12748 3918 : if (saved[j] < dirs[i].length)
12749 : {
12750 : /* Determine whether the dirs[i] path is a prefix of the
12751 : dirs[j] path. */
12752 3471 : int k;
12753 :
12754 3471 : k = dirs[j].prefix;
12755 3471 : while (k != -1 && k != (int) i)
12756 0 : k = dirs[k].prefix;
12757 :
12758 3471 : if (k == (int) i)
12759 : {
12760 : /* Yes it is. We can possibly save some memory by
12761 : writing the filenames in dirs[j] relative to
12762 : dirs[i]. */
12763 0 : savehere[j] = dirs[i].length;
12764 0 : total += (savehere[j] - saved[j]) * dirs[j].count;
12765 : }
12766 : }
12767 : }
12768 :
12769 : /* Check whether we can save enough to justify adding the dirs[i]
12770 : directory. */
12771 2499 : if (total > dirs[i].length + 1)
12772 : {
12773 : /* It's worthwhile adding. */
12774 2266 : for (j = i; j < ndirs; j++)
12775 1832 : if (savehere[j] > 0)
12776 : {
12777 : /* Remember how much we saved for this directory so far. */
12778 434 : saved[j] = savehere[j];
12779 :
12780 : /* Remember the prefix directory. */
12781 434 : dirs[j].dir_idx = i;
12782 : }
12783 : }
12784 : }
12785 :
12786 : /* Emit the directory name table. */
12787 1565 : idx_offset = dirs[0].length > 0 ? 1 : 0;
12788 1565 : enum dwarf_form str_form = DW_FORM_string;
12789 1565 : enum dwarf_form idx_form = DW_FORM_udata;
12790 1565 : if (dwarf_version >= 5)
12791 : {
12792 1514 : const char *comp_dir = comp_dir_string ();
12793 1514 : if (comp_dir == NULL)
12794 0 : comp_dir = "";
12795 1514 : dw2_asm_output_data (1, 1, "Directory entry format count");
12796 1514 : if (DWARF5_USE_DEBUG_LINE_STR)
12797 1514 : str_form = DW_FORM_line_strp;
12798 1514 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12799 1514 : dw2_asm_output_data_uleb128 (str_form, "%s",
12800 : get_DW_FORM_name (str_form));
12801 1514 : dw2_asm_output_data_uleb128 (ndirs + idx_offset, "Directories count");
12802 1514 : if (str_form == DW_FORM_string)
12803 : {
12804 245 : dw2_asm_output_nstring (comp_dir, -1, "Directory Entry: %#x", 0);
12805 492 : for (i = 1 - idx_offset; i < ndirs; i++)
12806 247 : dw2_asm_output_nstring (dirs[i].path,
12807 247 : dirs[i].length
12808 247 : - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12809 : "Directory Entry: %#x", i + idx_offset);
12810 : }
12811 : else
12812 : {
12813 1269 : output_line_string (str_form, comp_dir, "Directory Entry", 0);
12814 3209 : for (i = 1 - idx_offset; i < ndirs; i++)
12815 : {
12816 1940 : const char *str
12817 3880 : = ggc_alloc_string (dirs[i].path,
12818 1940 : dirs[i].length
12819 : - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR);
12820 1940 : output_line_string (str_form, str, "Directory Entry",
12821 1940 : (unsigned) i + idx_offset);
12822 : }
12823 : }
12824 : }
12825 : else
12826 : {
12827 118 : for (i = 1 - idx_offset; i < ndirs; i++)
12828 67 : dw2_asm_output_nstring (dirs[i].path,
12829 67 : dirs[i].length
12830 67 : - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12831 : "Directory Entry: %#x", i + idx_offset);
12832 :
12833 51 : dw2_asm_output_data (1, 0, "End directory table");
12834 : }
12835 :
12836 : /* We have to emit them in the order of emitted_number since that's
12837 : used in the debug info generation. To do this efficiently we
12838 : generate a back-mapping of the indices first. */
12839 1565 : backmap = XALLOCAVEC (int, numfiles);
12840 6251 : for (i = 0; i < numfiles; i++)
12841 4686 : backmap[files[i].file_idx->emitted_number - 1] = i;
12842 :
12843 1565 : if (dwarf_version >= 5)
12844 : {
12845 1514 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
12846 1514 : if (filename0 == NULL)
12847 0 : filename0 = "";
12848 : /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
12849 : DW_FORM_data2. Choose one based on the number of directories
12850 : and how much space would they occupy in each encoding.
12851 : If we have at most 256 directories, all indexes fit into
12852 : a single byte, so DW_FORM_data1 is most compact (if there
12853 : are at most 128 directories, DW_FORM_udata would be as
12854 : compact as that, but not shorter and slower to decode). */
12855 1514 : if (ndirs + idx_offset <= 256)
12856 : idx_form = DW_FORM_data1;
12857 : /* If there are more than 65536 directories, we have to use
12858 : DW_FORM_udata, DW_FORM_data2 can't refer to them.
12859 : Otherwise, compute what space would occupy if all the indexes
12860 : used DW_FORM_udata - sum - and compare that to how large would
12861 : be DW_FORM_data2 encoding, and pick the more efficient one. */
12862 0 : else if (ndirs + idx_offset <= 65536)
12863 : {
12864 : unsigned HOST_WIDE_INT sum = 1;
12865 0 : for (i = 0; i < numfiles; i++)
12866 : {
12867 0 : int file_idx = backmap[i];
12868 0 : int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12869 0 : sum += size_of_uleb128 (dir_idx);
12870 : }
12871 0 : if (sum >= HOST_WIDE_INT_UC (2) * (numfiles + 1))
12872 1514 : idx_form = DW_FORM_data2;
12873 : }
12874 : #ifdef VMS_DEBUGGING_INFO
12875 : dw2_asm_output_data (1, 4, "File name entry format count");
12876 : #else
12877 1514 : dw2_asm_output_data (1, 2, "File name entry format count");
12878 : #endif
12879 1514 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12880 1514 : dw2_asm_output_data_uleb128 (str_form, "%s",
12881 : get_DW_FORM_name (str_form));
12882 1514 : dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
12883 : "DW_LNCT_directory_index");
12884 1514 : dw2_asm_output_data_uleb128 (idx_form, "%s",
12885 : get_DW_FORM_name (idx_form));
12886 : #ifdef VMS_DEBUGGING_INFO
12887 : dw2_asm_output_data_uleb128 (DW_LNCT_timestamp, "DW_LNCT_timestamp");
12888 : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12889 : dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
12890 : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12891 : #endif
12892 1514 : dw2_asm_output_data_uleb128 (numfiles + 1, "File names count");
12893 :
12894 1514 : output_line_string (str_form, filename0, "File Entry", 0);
12895 :
12896 : /* Include directory index. */
12897 1514 : if (idx_form != DW_FORM_udata)
12898 1514 : dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
12899 : 0, NULL);
12900 : else
12901 0 : dw2_asm_output_data_uleb128 (0, NULL);
12902 :
12903 : #ifdef VMS_DEBUGGING_INFO
12904 : dw2_asm_output_data_uleb128 (0, NULL);
12905 : dw2_asm_output_data_uleb128 (0, NULL);
12906 : #endif
12907 : }
12908 :
12909 : /* Now write all the file names. */
12910 6251 : for (i = 0; i < numfiles; i++)
12911 : {
12912 4686 : int file_idx = backmap[i];
12913 4686 : int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12914 :
12915 : #ifdef VMS_DEBUGGING_INFO
12916 : #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12917 :
12918 : /* Setting these fields can lead to debugger miscomparisons,
12919 : but VMS Debug requires them to be set correctly. */
12920 :
12921 : int ver;
12922 : long long cdt;
12923 : long siz;
12924 : int maxfilelen = (strlen (files[file_idx].path)
12925 : + dirs[dir_idx].length
12926 : + MAX_VMS_VERSION_LEN + 1);
12927 : char *filebuf = XALLOCAVEC (char, maxfilelen);
12928 :
12929 : vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12930 : snprintf (filebuf, maxfilelen, "%s;%d",
12931 : files[file_idx].path + dirs[dir_idx].length, ver);
12932 :
12933 : output_line_string (str_form, filebuf, "File Entry", (unsigned) i + 1);
12934 :
12935 : /* Include directory index. */
12936 : if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
12937 : dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
12938 : dir_idx + idx_offset, NULL);
12939 : else
12940 : dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12941 :
12942 : /* Modification time. */
12943 : dw2_asm_output_data_uleb128 ((vms_file_stats_name (files[file_idx].path,
12944 : &cdt, 0, 0, 0) == 0)
12945 : ? cdt : 0, NULL);
12946 :
12947 : /* File length in bytes. */
12948 : dw2_asm_output_data_uleb128 ((vms_file_stats_name (files[file_idx].path,
12949 : 0, &siz, 0, 0) == 0)
12950 : ? siz : 0, NULL);
12951 : #else
12952 4686 : output_line_string (str_form,
12953 4686 : files[file_idx].path + dirs[dir_idx].length,
12954 4686 : "File Entry", (unsigned) i + 1);
12955 :
12956 : /* Include directory index. */
12957 4686 : if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
12958 4619 : dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
12959 4619 : dir_idx + idx_offset, NULL);
12960 : else
12961 67 : dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12962 :
12963 4686 : if (dwarf_version >= 5)
12964 4619 : continue;
12965 :
12966 : /* Modification time. */
12967 67 : dw2_asm_output_data_uleb128 (0, NULL);
12968 :
12969 : /* File length in bytes. */
12970 67 : dw2_asm_output_data_uleb128 (0, NULL);
12971 : #endif /* VMS_DEBUGGING_INFO */
12972 : }
12973 :
12974 1565 : if (dwarf_version < 5)
12975 51 : dw2_asm_output_data (1, 0, "End file name table");
12976 : }
12977 :
12978 :
12979 : /* Output one line number table into the .debug_line section. */
12980 :
12981 : static void
12982 43 : output_one_line_info_table (dw_line_info_table *table)
12983 : {
12984 43 : char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12985 43 : unsigned int current_line = 1;
12986 43 : bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12987 43 : dw_line_info_entry *ent, *prev_addr = NULL;
12988 43 : size_t i;
12989 43 : unsigned int view;
12990 :
12991 43 : view = 0;
12992 :
12993 5790 : FOR_EACH_VEC_SAFE_ELT (table->entries, i, ent)
12994 : {
12995 5747 : switch (ent->opcode)
12996 : {
12997 90 : case LI_set_address:
12998 : /* ??? Unfortunately, we have little choice here currently, and
12999 : must always use the most general form. GCC does not know the
13000 : address delta itself, so we can't use DW_LNS_advance_pc. Many
13001 : ports do have length attributes which will give an upper bound
13002 : on the address range. We could perhaps use length attributes
13003 : to determine when it is safe to use DW_LNS_fixed_advance_pc. */
13004 90 : ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
13005 :
13006 90 : view = 0;
13007 :
13008 : /* This can handle any delta. This takes
13009 : 4+DWARF2_ADDR_SIZE bytes. */
13010 90 : dw2_asm_output_data (1, 0, "set address %s%s", line_label,
13011 90 : debug_variable_location_views
13012 : ? ", reset view to 0" : "");
13013 105 : dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
13014 90 : dw2_asm_output_data (1, DW_LNE_set_address, NULL);
13015 90 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
13016 :
13017 90 : prev_addr = ent;
13018 90 : break;
13019 :
13020 1451 : case LI_adv_address:
13021 1451 : {
13022 1451 : ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
13023 1451 : char prev_label[MAX_ARTIFICIAL_LABEL_BYTES];
13024 1451 : ASM_GENERATE_INTERNAL_LABEL (prev_label, LINE_CODE_LABEL, prev_addr->val);
13025 :
13026 1451 : view++;
13027 :
13028 1451 : if (HAVE_AS_LEB128)
13029 : {
13030 : /* Using DW_LNS_advance_pc with label delta is only valid if
13031 : Minimum Instruction Length in the header is 1, but that is
13032 : what we use on all targets. */
13033 1451 : dw2_asm_output_data (1, DW_LNS_advance_pc,
13034 : "advance PC, increment view to %i", view);
13035 1451 : dw2_asm_output_delta_uleb128 (line_label, prev_label,
13036 : "from %s to %s", prev_label,
13037 : line_label);
13038 : }
13039 : else
13040 : {
13041 : dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
13042 : "fixed advance PC, increment view to %i",
13043 : view);
13044 : dw2_asm_output_delta (2, line_label, prev_label,
13045 : "from %s to %s", prev_label, line_label);
13046 : }
13047 :
13048 1451 : prev_addr = ent;
13049 1451 : break;
13050 : }
13051 :
13052 1541 : case LI_set_line:
13053 1541 : if (ent->val == current_line)
13054 : {
13055 : /* We still need to start a new row, so output a copy insn. */
13056 683 : dw2_asm_output_data (1, DW_LNS_copy,
13057 : "copy line %u", current_line);
13058 : }
13059 : else
13060 : {
13061 858 : int line_offset = ent->val - current_line;
13062 858 : int line_delta = line_offset - DWARF_LINE_BASE;
13063 :
13064 858 : current_line = ent->val;
13065 858 : if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
13066 : {
13067 : /* This can handle deltas from -10 to 234, using the current
13068 : definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
13069 : This takes 1 byte. */
13070 457 : dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
13071 : "line %u", current_line);
13072 : }
13073 : else
13074 : {
13075 : /* This can handle any delta. This takes at least 4 bytes,
13076 : depending on the value being encoded. */
13077 401 : dw2_asm_output_data (1, DW_LNS_advance_line,
13078 : "advance to line %u", current_line);
13079 401 : dw2_asm_output_data_sleb128 (line_offset, NULL);
13080 401 : dw2_asm_output_data (1, DW_LNS_copy, NULL);
13081 : }
13082 : }
13083 : break;
13084 :
13085 280 : case LI_set_file:
13086 280 : dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
13087 280 : dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
13088 280 : break;
13089 :
13090 1541 : case LI_set_column:
13091 1541 : dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
13092 1541 : dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
13093 1541 : break;
13094 :
13095 573 : case LI_negate_stmt:
13096 573 : current_is_stmt = !current_is_stmt;
13097 573 : dw2_asm_output_data (1, DW_LNS_negate_stmt,
13098 : "is_stmt %d", current_is_stmt);
13099 573 : break;
13100 :
13101 0 : case LI_set_prologue_end:
13102 0 : dw2_asm_output_data (1, DW_LNS_set_prologue_end,
13103 : "set prologue end");
13104 0 : break;
13105 :
13106 0 : case LI_set_epilogue_begin:
13107 0 : dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
13108 : "set epilogue begin");
13109 0 : break;
13110 :
13111 271 : case LI_set_discriminator:
13112 271 : dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
13113 271 : dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
13114 271 : dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
13115 271 : dw2_asm_output_data_uleb128 (ent->val, NULL);
13116 271 : break;
13117 : }
13118 : }
13119 :
13120 : /* Emit debug info for the address of the end of the table. */
13121 43 : dw2_asm_output_data (1, 0, "set address %s", table->end_label);
13122 58 : dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
13123 43 : dw2_asm_output_data (1, DW_LNE_set_address, NULL);
13124 58 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
13125 :
13126 43 : dw2_asm_output_data (1, 0, "end sequence");
13127 43 : dw2_asm_output_data_uleb128 (1, NULL);
13128 43 : dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
13129 43 : }
13130 :
13131 : static unsigned int output_line_info_generation;
13132 :
13133 : /* Output the source line number correspondence information. This
13134 : information goes into the .debug_line section. */
13135 :
13136 : static void
13137 1582 : output_line_info (bool prologue_only)
13138 : {
13139 1582 : char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
13140 1582 : char p1[MAX_ARTIFICIAL_LABEL_BYTES], p2[MAX_ARTIFICIAL_LABEL_BYTES];
13141 1582 : bool saw_one = false;
13142 1582 : int opc;
13143 :
13144 1582 : ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL,
13145 : output_line_info_generation);
13146 1582 : ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL,
13147 : output_line_info_generation);
13148 1582 : ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL,
13149 : output_line_info_generation);
13150 1582 : ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL,
13151 : output_line_info_generation++);
13152 :
13153 1582 : if (!XCOFF_DEBUGGING_INFO)
13154 : {
13155 1582 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
13156 0 : dw2_asm_output_data (4, 0xffffffff,
13157 : "Initial length escape value indicating 64-bit DWARF extension");
13158 1582 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
13159 : "Length of Source Line Info");
13160 : }
13161 :
13162 1582 : ASM_OUTPUT_LABEL (asm_out_file, l1);
13163 :
13164 1582 : output_dwarf_version ();
13165 1582 : if (dwarf_version >= 5)
13166 : {
13167 1532 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
13168 1531 : dw2_asm_output_data (1, 0, "Segment Size");
13169 : }
13170 1582 : dw2_asm_output_delta (dwarf_offset_size, p2, p1, "Prolog Length");
13171 1582 : ASM_OUTPUT_LABEL (asm_out_file, p1);
13172 :
13173 : /* Define the architecture-dependent minimum instruction length (in bytes).
13174 : In this implementation of DWARF, this field is used for information
13175 : purposes only. Since GCC generates assembly language, we have no
13176 : a priori knowledge of how many instruction bytes are generated for each
13177 : source line, and therefore can use only the DW_LNE_set_address and
13178 : DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
13179 : this as '1', which is "correct enough" for all architectures,
13180 : and don't let the target override. */
13181 1582 : dw2_asm_output_data (1, 1, "Minimum Instruction Length");
13182 :
13183 1582 : if (dwarf_version >= 4)
13184 1532 : dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
13185 : "Maximum Operations Per Instruction");
13186 1582 : dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
13187 : "Default is_stmt_start flag");
13188 1582 : dw2_asm_output_data (1, DWARF_LINE_BASE,
13189 : "Line Base Value (Special Opcodes)");
13190 1582 : dw2_asm_output_data (1, DWARF_LINE_RANGE,
13191 : "Line Range Value (Special Opcodes)");
13192 1582 : dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
13193 : "Special Opcode Base");
13194 :
13195 20566 : for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
13196 : {
13197 18984 : int n_op_args;
13198 18984 : switch (opc)
13199 : {
13200 : case DW_LNS_advance_pc:
13201 : case DW_LNS_advance_line:
13202 : case DW_LNS_set_file:
13203 : case DW_LNS_set_column:
13204 : case DW_LNS_fixed_advance_pc:
13205 : case DW_LNS_set_isa:
13206 : n_op_args = 1;
13207 : break;
13208 9492 : default:
13209 9492 : n_op_args = 0;
13210 9492 : break;
13211 : }
13212 :
13213 18984 : dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
13214 : opc, n_op_args);
13215 : }
13216 :
13217 : /* Write out the information about the files we use. */
13218 1582 : output_file_names ();
13219 1582 : ASM_OUTPUT_LABEL (asm_out_file, p2);
13220 1582 : if (prologue_only)
13221 : {
13222 : /* Output the marker for the end of the line number info. */
13223 1576 : ASM_OUTPUT_LABEL (asm_out_file, l2);
13224 1576 : return;
13225 : }
13226 :
13227 6 : if (separate_line_info)
13228 : {
13229 : dw_line_info_table *table;
13230 : size_t i;
13231 :
13232 42 : FOR_EACH_VEC_ELT (*separate_line_info, i, table)
13233 37 : if (table->in_use)
13234 : {
13235 37 : output_one_line_info_table (table);
13236 37 : saw_one = true;
13237 : }
13238 : }
13239 6 : if (cold_text_section_line_info && cold_text_section_line_info->in_use)
13240 : {
13241 2 : output_one_line_info_table (cold_text_section_line_info);
13242 2 : saw_one = true;
13243 : }
13244 :
13245 : /* ??? Some Darwin linkers crash on a .debug_line section with no
13246 : sequences. Further, merely a DW_LNE_end_sequence entry is not
13247 : sufficient -- the address column must also be initialized.
13248 : Make sure to output at least one set_address/end_sequence pair,
13249 : choosing .text since that section is always present. */
13250 6 : if (text_section_line_info->in_use || !saw_one)
13251 4 : output_one_line_info_table (text_section_line_info);
13252 :
13253 : /* Output the marker for the end of the line number info. */
13254 6 : ASM_OUTPUT_LABEL (asm_out_file, l2);
13255 : }
13256 :
13257 : /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
13258 :
13259 : static inline bool
13260 511057609 : need_endianity_attribute_p (bool reverse)
13261 : {
13262 269 : return reverse && (dwarf_version >= 3 || !dwarf_strict);
13263 : }
13264 :
13265 : /* Given a pointer to a tree node for some base type, return a pointer to
13266 : a DIE that describes the given type. REVERSE is true if the type is
13267 : to be interpreted in the reverse storage order wrt the target order.
13268 :
13269 : This routine must only be called for GCC type nodes that correspond to
13270 : Dwarf base (fundamental) types. */
13271 :
13272 : dw_die_ref
13273 585049 : base_type_die (tree type, bool reverse)
13274 : {
13275 585049 : dw_die_ref base_type_result;
13276 585049 : enum dwarf_type encoding;
13277 585049 : bool fpt_used = false;
13278 585049 : struct fixed_point_type_info fpt_info;
13279 585049 : tree type_bias = NULL_TREE;
13280 :
13281 : /* If this is a subtype that should not be emitted as a subrange type,
13282 : use the base type. See subrange_type_for_debug_p. */
13283 585049 : if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
13284 0 : type = TREE_TYPE (type);
13285 :
13286 585049 : switch (TREE_CODE (type))
13287 : {
13288 377580 : case INTEGER_TYPE:
13289 3422 : if ((dwarf_version >= 4 || !dwarf_strict)
13290 377580 : && TYPE_NAME (type)
13291 376311 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13292 367004 : && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type))
13293 744584 : && DECL_NAME (TYPE_NAME (type)))
13294 : {
13295 367004 : const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
13296 367004 : if (strcmp (name, "char16_t") == 0
13297 355823 : || strcmp (name, "char8_t") == 0
13298 345054 : || strcmp (name, "char32_t") == 0)
13299 : {
13300 : encoding = DW_ATE_UTF;
13301 : break;
13302 : }
13303 : }
13304 344449 : if ((dwarf_version >= 3 || !dwarf_strict)
13305 344449 : && lang_hooks.types.get_fixed_point_type_info)
13306 : {
13307 0 : memset (&fpt_info, 0, sizeof (fpt_info));
13308 0 : if (lang_hooks.types.get_fixed_point_type_info (type, &fpt_info))
13309 : {
13310 0 : fpt_used = true;
13311 0 : encoding = ((TYPE_UNSIGNED (type))
13312 0 : ? DW_ATE_unsigned_fixed
13313 : : DW_ATE_signed_fixed);
13314 : break;
13315 : }
13316 : }
13317 344449 : if (TYPE_STRING_FLAG (type))
13318 : {
13319 597 : if ((dwarf_version >= 4 || !dwarf_strict)
13320 78131 : && is_rust ()
13321 78256 : && int_size_in_bytes (type) == 4)
13322 : encoding = DW_ATE_UTF;
13323 78120 : else if (TYPE_UNSIGNED (type))
13324 : encoding = DW_ATE_unsigned_char;
13325 : else
13326 48279 : encoding = DW_ATE_signed_char;
13327 : }
13328 266318 : else if (TYPE_UNSIGNED (type))
13329 : encoding = DW_ATE_unsigned;
13330 : else
13331 146507 : encoding = DW_ATE_signed;
13332 :
13333 344449 : if (!dwarf_strict
13334 344445 : && lang_hooks.types.get_type_bias)
13335 0 : type_bias = lang_hooks.types.get_type_bias (type);
13336 : break;
13337 :
13338 142602 : case REAL_TYPE:
13339 142602 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
13340 : {
13341 862 : if (dwarf_version >= 3 || !dwarf_strict)
13342 : encoding = DW_ATE_decimal_float;
13343 : else
13344 64 : encoding = DW_ATE_lo_user;
13345 : }
13346 : else
13347 : encoding = DW_ATE_float;
13348 : break;
13349 :
13350 0 : case FIXED_POINT_TYPE:
13351 0 : if (!(dwarf_version >= 3 || !dwarf_strict))
13352 : encoding = DW_ATE_lo_user;
13353 0 : else if (TYPE_UNSIGNED (type))
13354 : encoding = DW_ATE_unsigned_fixed;
13355 : else
13356 0 : encoding = DW_ATE_signed_fixed;
13357 : break;
13358 :
13359 : /* Dwarf2 doesn't know anything about complex ints, so use
13360 : a user defined type for it. */
13361 45228 : case COMPLEX_TYPE:
13362 45228 : if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type)))
13363 : encoding = DW_ATE_complex_float;
13364 : else
13365 64 : encoding = DW_ATE_lo_user;
13366 : break;
13367 :
13368 : case BOOLEAN_TYPE:
13369 : /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
13370 : encoding = DW_ATE_boolean;
13371 : break;
13372 :
13373 57 : case BITINT_TYPE:
13374 : /* C23 _BitInt(N). */
13375 57 : if (TYPE_UNSIGNED (type))
13376 : encoding = DW_ATE_unsigned;
13377 : else
13378 41 : encoding = DW_ATE_signed;
13379 : break;
13380 :
13381 0 : default:
13382 : /* No other TREE_CODEs are Dwarf fundamental types. */
13383 0 : gcc_unreachable ();
13384 : }
13385 :
13386 585049 : base_type_result = new_die_raw (DW_TAG_base_type);
13387 :
13388 585049 : add_AT_unsigned (base_type_result, DW_AT_byte_size,
13389 585049 : int_size_in_bytes (type));
13390 585049 : add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
13391 585049 : if (TREE_CODE (type) == BITINT_TYPE)
13392 57 : add_AT_unsigned (base_type_result, DW_AT_bit_size, TYPE_PRECISION (type));
13393 :
13394 585049 : if (need_endianity_attribute_p (reverse))
13395 57 : add_AT_unsigned (base_type_result, DW_AT_endianity,
13396 : BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
13397 :
13398 585049 : add_alignment_attribute (base_type_result, type);
13399 :
13400 585049 : if (fpt_used)
13401 : {
13402 0 : switch (fpt_info.scale_factor_kind)
13403 : {
13404 0 : case fixed_point_scale_factor_binary:
13405 0 : add_AT_int (base_type_result, DW_AT_binary_scale,
13406 0 : fpt_info.scale_factor.binary);
13407 0 : break;
13408 :
13409 0 : case fixed_point_scale_factor_decimal:
13410 0 : add_AT_int (base_type_result, DW_AT_decimal_scale,
13411 0 : fpt_info.scale_factor.decimal);
13412 0 : break;
13413 :
13414 0 : case fixed_point_scale_factor_arbitrary:
13415 : /* Arbitrary scale factors cannot be described in standard DWARF. */
13416 0 : if (!dwarf_strict)
13417 : {
13418 : /* Describe the scale factor as a rational constant. */
13419 0 : const dw_die_ref scale_factor
13420 0 : = new_die (DW_TAG_constant, comp_unit_die (), type);
13421 :
13422 0 : add_scalar_info (scale_factor, DW_AT_GNU_numerator,
13423 : fpt_info.scale_factor.arbitrary.numerator,
13424 : dw_scalar_form_constant, NULL);
13425 0 : add_scalar_info (scale_factor, DW_AT_GNU_denominator,
13426 : fpt_info.scale_factor.arbitrary.denominator,
13427 : dw_scalar_form_constant, NULL);
13428 :
13429 0 : add_AT_die_ref (base_type_result, DW_AT_small, scale_factor);
13430 : }
13431 : break;
13432 :
13433 0 : default:
13434 0 : gcc_unreachable ();
13435 : }
13436 : }
13437 :
13438 585049 : if (type_bias)
13439 0 : add_scalar_info (base_type_result, DW_AT_GNU_bias, type_bias,
13440 : dw_scalar_form_constant
13441 : | dw_scalar_form_exprloc
13442 : | dw_scalar_form_reference,
13443 : NULL);
13444 :
13445 585049 : return base_type_result;
13446 : }
13447 :
13448 : /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
13449 : named 'auto' in its type: return true for it, false otherwise. */
13450 :
13451 : static inline bool
13452 147336 : is_cxx_auto (tree type)
13453 : {
13454 147336 : if (is_cxx ())
13455 : {
13456 147336 : tree name = TYPE_IDENTIFIER (type);
13457 147336 : if (name == get_identifier ("auto")
13458 147336 : || name == get_identifier ("decltype(auto)"))
13459 147330 : return true;
13460 : }
13461 : return false;
13462 : }
13463 :
13464 : /* Given a pointer to an arbitrary ..._TYPE tree node, return true if the
13465 : given input type is a Dwarf "fundamental" type. Otherwise return null. */
13466 :
13467 : static inline bool
13468 5623178 : is_base_type (tree type)
13469 : {
13470 5623178 : switch (TREE_CODE (type))
13471 : {
13472 : case INTEGER_TYPE:
13473 : case REAL_TYPE:
13474 : case FIXED_POINT_TYPE:
13475 : case COMPLEX_TYPE:
13476 : case BOOLEAN_TYPE:
13477 : case BITINT_TYPE:
13478 : return true;
13479 :
13480 : case VOID_TYPE:
13481 : case OPAQUE_TYPE:
13482 : case ARRAY_TYPE:
13483 : case RECORD_TYPE:
13484 : case UNION_TYPE:
13485 : case QUAL_UNION_TYPE:
13486 : case ENUMERAL_TYPE:
13487 : case FUNCTION_TYPE:
13488 : case METHOD_TYPE:
13489 : case POINTER_TYPE:
13490 : case REFERENCE_TYPE:
13491 : case NULLPTR_TYPE:
13492 : case OFFSET_TYPE:
13493 : case LANG_TYPE:
13494 : case VECTOR_TYPE:
13495 : return false;
13496 :
13497 9 : default:
13498 9 : if (is_cxx ()
13499 9 : && TREE_CODE (type) >= LAST_AND_UNUSED_TREE_CODE
13500 9 : && TYPE_P (type)
13501 18 : && TYPE_IDENTIFIER (type))
13502 : return false;
13503 0 : gcc_unreachable ();
13504 : }
13505 : }
13506 :
13507 : /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
13508 : node, return the size in bits for the type if it is a constant, or else
13509 : return the alignment for the type if the type's size is not constant, or
13510 : else return BITS_PER_WORD if the type actually turns out to be an
13511 : ERROR_MARK node. */
13512 :
13513 : static inline unsigned HOST_WIDE_INT
13514 46403564 : simple_type_size_in_bits (const_tree type)
13515 : {
13516 46403564 : if (TREE_CODE (type) == ERROR_MARK)
13517 0 : return BITS_PER_WORD;
13518 46403564 : else if (TYPE_SIZE (type) == NULL_TREE)
13519 : return 0;
13520 46403564 : else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
13521 46403564 : return tree_to_uhwi (TYPE_SIZE (type));
13522 : else
13523 0 : return TYPE_ALIGN (type);
13524 : }
13525 :
13526 : /* Similarly, but return an offset_int instead of UHWI. */
13527 :
13528 : static inline offset_int
13529 975360 : offset_int_type_size_in_bits (const_tree type)
13530 : {
13531 975360 : if (TREE_CODE (type) == ERROR_MARK)
13532 0 : return BITS_PER_WORD;
13533 975360 : else if (TYPE_SIZE (type) == NULL_TREE)
13534 0 : return 0;
13535 975360 : else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
13536 975360 : return wi::to_offset (TYPE_SIZE (type));
13537 : else
13538 0 : return TYPE_ALIGN (type);
13539 : }
13540 :
13541 : /* Given a pointer to a tree node for a subrange type, return a pointer
13542 : to a DIE that describes the given type. */
13543 :
13544 : static dw_die_ref
13545 18 : subrange_type_die (tree type, tree low, tree high, tree bias,
13546 : dw_die_ref context_die)
13547 : {
13548 18 : dw_die_ref subrange_die;
13549 18 : const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
13550 :
13551 18 : if (context_die == NULL)
13552 0 : context_die = comp_unit_die ();
13553 :
13554 18 : subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
13555 :
13556 18 : if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
13557 : {
13558 : /* The size of the subrange type and its base type do not match,
13559 : so we need to generate a size attribute for the subrange type. */
13560 0 : add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
13561 : }
13562 :
13563 18 : add_alignment_attribute (subrange_die, type);
13564 :
13565 18 : if (low)
13566 18 : add_bound_info (subrange_die, DW_AT_lower_bound, low, NULL);
13567 18 : if (high)
13568 18 : add_bound_info (subrange_die, DW_AT_upper_bound, high, NULL);
13569 18 : if (bias && !dwarf_strict)
13570 0 : add_scalar_info (subrange_die, DW_AT_GNU_bias, bias,
13571 : dw_scalar_form_constant
13572 : | dw_scalar_form_exprloc
13573 : | dw_scalar_form_reference,
13574 : NULL);
13575 :
13576 18 : return subrange_die;
13577 : }
13578 :
13579 : /* Returns the (const and/or volatile) cv_qualifiers associated with
13580 : the decl node. This will normally be augmented with the
13581 : cv_qualifiers of the underlying type in add_type_attribute. */
13582 :
13583 : static int
13584 134012828 : decl_quals (const_tree decl)
13585 : {
13586 134012828 : return ((TREE_READONLY (decl)
13587 : /* The C++ front-end correctly marks reference-typed
13588 : variables as readonly, but from a language (and debug
13589 : info) standpoint they are not const-qualified. */
13590 61598954 : && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
13591 134012828 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
13592 134012828 : | (TREE_THIS_VOLATILE (decl)
13593 134012828 : ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
13594 : }
13595 :
13596 : /* Determine the TYPE whose qualifiers match the largest strict subset
13597 : of the given TYPE_QUALS, and return its qualifiers. Ignore all
13598 : qualifiers outside QUAL_MASK. */
13599 :
13600 : static int
13601 13186401 : get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
13602 : {
13603 13186401 : tree t;
13604 13186401 : int best_rank = 0, best_qual = 0, max_rank;
13605 :
13606 13186401 : type_quals &= qual_mask;
13607 13186401 : max_rank = popcount_hwi (type_quals) - 1;
13608 :
13609 13943988 : for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
13610 757587 : t = TYPE_NEXT_VARIANT (t))
13611 : {
13612 757587 : int q = TYPE_QUALS (t) & qual_mask;
13613 :
13614 757550 : if ((q & type_quals) == q && q != type_quals
13615 1458250 : && check_base_type (t, type))
13616 : {
13617 484940 : int rank = popcount_hwi (q);
13618 :
13619 484940 : if (rank > best_rank)
13620 : {
13621 757587 : best_rank = rank;
13622 757587 : best_qual = q;
13623 : }
13624 : }
13625 : }
13626 :
13627 13186401 : return best_qual;
13628 : }
13629 :
13630 : struct dwarf_qual_info_t { int q; enum dwarf_tag t; };
13631 : static const dwarf_qual_info_t dwarf_qual_info[] =
13632 : {
13633 : { TYPE_QUAL_CONST, DW_TAG_const_type },
13634 : { TYPE_QUAL_VOLATILE, DW_TAG_volatile_type },
13635 : { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
13636 : { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
13637 : };
13638 : static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
13639 :
13640 : /* If DIE is a qualified DIE of some base DIE with the same parent,
13641 : return the base DIE, otherwise return NULL. Set MASK to the
13642 : qualifiers added compared to the returned DIE. */
13643 :
13644 : static dw_die_ref
13645 22225185 : qualified_die_p (dw_die_ref die, int *mask, unsigned int depth)
13646 : {
13647 22225185 : unsigned int i;
13648 103062444 : for (i = 0; i < dwarf_qual_info_size; i++)
13649 83071865 : if (die->die_tag == dwarf_qual_info[i].t)
13650 : break;
13651 22225185 : if (i == dwarf_qual_info_size)
13652 : return NULL;
13653 22227636 : if (vec_safe_length (die->die_attr) != 1)
13654 : return NULL;
13655 2223747 : dw_die_ref type = get_AT_ref (die, DW_AT_type);
13656 2223747 : if (type == NULL || type->die_parent != die->die_parent)
13657 : return NULL;
13658 2221296 : *mask |= dwarf_qual_info[i].q;
13659 2221296 : if (depth)
13660 : {
13661 2221296 : dw_die_ref ret = qualified_die_p (type, mask, depth - 1);
13662 2221296 : if (ret)
13663 : return ret;
13664 : }
13665 : return type;
13666 : }
13667 :
13668 : /* If TYPE is long double or complex long double that
13669 : should be emitted as artificial typedef to _Float128 or
13670 : complex _Float128, return the type it should be emitted as.
13671 : This is done in case the target already supports 16-byte
13672 : composite floating point type (ibm_extended_format). */
13673 :
13674 : static tree
13675 584780 : long_double_as_float128 (tree type)
13676 : {
13677 584780 : if (type != long_double_type_node
13678 565835 : && type != complex_long_double_type_node)
13679 : return NULL_TREE;
13680 :
13681 31369 : machine_mode mode, fmode;
13682 31369 : if (TREE_CODE (type) == COMPLEX_TYPE)
13683 12424 : mode = TYPE_MODE (TREE_TYPE (type));
13684 : else
13685 18945 : mode = TYPE_MODE (type);
13686 221696 : if (known_eq (GET_MODE_SIZE (mode), 16) && !MODE_COMPOSITE_P (mode))
13687 185451 : FOR_EACH_MODE_IN_CLASS (fmode, MODE_FLOAT)
13688 158958 : if (known_eq (GET_MODE_SIZE (fmode), 16)
13689 476874 : && MODE_COMPOSITE_P (fmode))
13690 : {
13691 0 : if (type == long_double_type_node)
13692 : {
13693 0 : if (float128_type_node
13694 0 : && (TYPE_MODE (float128_type_node)
13695 0 : == TYPE_MODE (type)))
13696 0 : return float128_type_node;
13697 0 : return NULL_TREE;
13698 : }
13699 0 : for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
13700 0 : if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
13701 0 : && (TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i))
13702 0 : == TYPE_MODE (type)))
13703 0 : return COMPLEX_FLOATN_NX_TYPE_NODE (i);
13704 : }
13705 :
13706 : return NULL_TREE;
13707 : }
13708 :
13709 : /* Hash function for struct annotation_node. The hash value is computed when
13710 : the annotation node is created based on the name, value and chain of any
13711 : further annotations on the same entity. */
13712 :
13713 : hashval_t
13714 486 : annotation_node_hasher::hash (struct annotation_node *node)
13715 : {
13716 486 : return node->hash;
13717 : }
13718 :
13719 : /* Return whether two annotation nodes represent the same annotation and
13720 : can therefore share a DIE. Beware of hash value collisions. */
13721 :
13722 : bool
13723 348 : annotation_node_hasher::equal (const struct annotation_node *node1,
13724 : const struct annotation_node *node2)
13725 : {
13726 348 : return (node1->hash == node2->hash
13727 97 : && (node1->name == node2->name
13728 0 : || !strcmp (node1->name, node2->name))
13729 97 : && (node1->value == node2->value
13730 41 : || !strcmp (node1->value, node2->value))
13731 445 : && node1->next == node2->next);
13732 : }
13733 :
13734 : /* Return an appropriate entry in the btf tag hash table for a given btf tag.
13735 : If a structurally equivalent tag (one with the same name, value, and
13736 : subsequent chain of further tags) has already been processed, then the
13737 : existing entry for that tag is returned and should be reused.
13738 : Otherwise, a new entry is added to the hash table and returned. */
13739 :
13740 : static struct annotation_node *
13741 297 : hash_btf_tag (tree attr)
13742 : {
13743 297 : if (attr == NULL_TREE || TREE_CODE (attr) != TREE_LIST)
13744 : return NULL;
13745 :
13746 167 : if (!btf_tag_htab)
13747 26 : btf_tag_htab = hash_table<annotation_node_hasher>::create_ggc (10);
13748 :
13749 167 : const char * name = IDENTIFIER_POINTER (get_attribute_name (attr));
13750 167 : const char * value = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
13751 167 : tree chain = lookup_attribute (name, TREE_CHAIN (attr));
13752 :
13753 : /* Hash for one tag depends on hash of next tag in the chain, because
13754 : the chain is part of structural equivalence. */
13755 167 : struct annotation_node *chain_node = hash_btf_tag (chain);
13756 167 : gcc_checking_assert (chain == NULL_TREE || chain_node != NULL);
13757 :
13758 : /* Skip any non-btf-tag attributes that might be in the chain. */
13759 167 : if (strcmp (name, "btf_type_tag") != 0 && strcmp (name, "btf_decl_tag") != 0)
13760 : return chain_node;
13761 :
13762 : /* Hash for a given tag is determined by the name, value, and chain of
13763 : further tags. */
13764 167 : inchash::hash h;
13765 167 : h.merge_hash (htab_hash_string (name));
13766 167 : h.merge_hash (htab_hash_string (value));
13767 167 : h.merge_hash (chain_node ? chain_node->hash : 0);
13768 :
13769 167 : struct annotation_node node;
13770 167 : node.name = name;
13771 167 : node.value = value;
13772 167 : node.hash = h.end ();
13773 167 : node.next = chain_node;
13774 :
13775 167 : struct annotation_node **slot = btf_tag_htab->find_slot (&node, INSERT);
13776 167 : if (*slot == NULL)
13777 : {
13778 : /* Create new htab entry for this annotation. */
13779 70 : struct annotation_node *new_slot
13780 70 : = ggc_cleared_alloc<struct annotation_node> ();
13781 70 : new_slot->name = name;
13782 70 : new_slot->value = value;
13783 70 : new_slot->hash = node.hash;
13784 70 : new_slot->next = chain_node;
13785 :
13786 70 : *slot = new_slot;
13787 70 : return new_slot;
13788 : }
13789 : else
13790 : {
13791 : /* This node is already in the hash table. */
13792 : return *slot;
13793 : }
13794 : }
13795 :
13796 : /* Generate (or reuse) DW_TAG_GNU_annotation DIEs representing the btf_type_tag
13797 : or btf_decl_tag user annotations in ATTR, and update DIE to refer to them
13798 : via DW_AT_GNU_annotation. If there are multiple type_tag or decl_tag
13799 : annotations in ATTR, they are all processed recursively by this function to
13800 : build a chain of annotation DIEs.
13801 : A single chain of annotation DIEs can be shared among all occurrences of
13802 : equivalent sets of attributes appearing on different types or declarations.
13803 : Return the first annotation DIE in the created (or reused) chain. */
13804 :
13805 : static dw_die_ref
13806 130 : gen_btf_tag_dies (tree attr, dw_die_ref die)
13807 : {
13808 130 : if (attr == NULL_TREE)
13809 : return die;
13810 :
13811 130 : const char * name = IDENTIFIER_POINTER (get_attribute_name (attr));
13812 130 : const char * value = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
13813 :
13814 130 : dw_die_ref tag_die, prev = NULL;
13815 :
13816 : /* Multiple annotations on the same item form a singly-linked list of
13817 : annotation DIEs; generate recursively backward from the end so we can
13818 : chain each created DIE to the next, which has already been created. */
13819 130 : tree rest = lookup_attribute (name, TREE_CHAIN (attr));
13820 130 : if (rest)
13821 33 : prev = gen_btf_tag_dies (rest, NULL);
13822 :
13823 : /* Calculate a hash value for the tag based on its structure, find the
13824 : existing entry for it (if any) in the hash table, or create a new entry
13825 : which can be reused by structurally-equivalent tags. */
13826 130 : struct annotation_node *entry = hash_btf_tag (attr);
13827 130 : if (!entry)
13828 : return die;
13829 :
13830 : /* If the node already has an associated DIE, reuse it.
13831 : Otherwise, create the new annotation DIE, and associate it with
13832 : the hash table entry for future reuse. Any structurally-equivalent
13833 : tag we process later will find and share the same DIE. */
13834 130 : if (entry->die)
13835 : tag_die = entry->die;
13836 : else
13837 : {
13838 70 : tag_die = new_die (DW_TAG_GNU_annotation, comp_unit_die (), NULL);
13839 70 : add_name_attribute (tag_die, name);
13840 70 : add_AT_string (tag_die, DW_AT_const_value, value);
13841 70 : if (prev)
13842 21 : add_AT_die_ref (tag_die, DW_AT_GNU_annotation, prev);
13843 :
13844 70 : entry->die = tag_die;
13845 : }
13846 :
13847 130 : if (die)
13848 : {
13849 : /* Add (or replace) AT_GNU_annotation referring to the annotation DIE.
13850 : Replacement may happen for example when 'die' is a global variable
13851 : which has been re-declared multiple times. In any case, the set of
13852 : input attributes is the one that ought to be reflected. For global
13853 : variable re-declarations which add additional decl tags, they will
13854 : have been accumulated in the variable's DECL_ATTRIBUTES for us. */
13855 97 : remove_AT (die, DW_AT_GNU_annotation);
13856 97 : add_AT_die_ref (die, DW_AT_GNU_annotation, tag_die);
13857 : }
13858 :
13859 : return tag_die;
13860 : }
13861 :
13862 : /* Generate (or reuse) annotation DIEs representing the type_tags on T, if
13863 : any, and update DIE to refer to them as appropriate. */
13864 :
13865 : static void
13866 137991018 : maybe_gen_btf_type_tag_dies (tree t, dw_die_ref target)
13867 : {
13868 137991018 : if (t == NULL_TREE || !TYPE_P (t) || !target)
13869 : return;
13870 :
13871 137991018 : tree attr = lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (t));
13872 137991018 : if (attr == NULL_TREE)
13873 : return;
13874 :
13875 5 : gen_btf_tag_dies (attr, target);
13876 : }
13877 :
13878 : /* Generate (or reuse) annotation DIEs representing any decl_tags in ATTR that
13879 : apply to TARGET. */
13880 :
13881 : static void
13882 552928698 : maybe_gen_btf_decl_tag_dies (tree t, dw_die_ref target)
13883 : {
13884 552928698 : if (t == NULL_TREE || !DECL_P (t) || !target)
13885 : return;
13886 :
13887 208736004 : tree attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t));
13888 208736004 : if (attr == NULL_TREE)
13889 : return;
13890 :
13891 61 : gen_btf_tag_dies (attr, target);
13892 : }
13893 :
13894 : /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
13895 : entry that chains the modifiers specified by CV_QUALS in front of the
13896 : given type. Also handle any type attributes in TYPE_ATTRS which have
13897 : a representation in DWARF. REVERSE is true if the type is to be interpreted
13898 : in the reverse storage order wrt the target order. */
13899 :
13900 : static dw_die_ref
13901 510472560 : modified_type_die (tree type, int cv_quals, tree type_attrs, bool reverse,
13902 : dw_die_ref context_die)
13903 : {
13904 510472560 : enum tree_code code = TREE_CODE (type);
13905 510472560 : dw_die_ref mod_type_die;
13906 510472560 : dw_die_ref sub_die = NULL;
13907 510472560 : tree item_type = NULL;
13908 510472560 : tree qualified_type;
13909 510472560 : tree name, low, high;
13910 510472560 : tree btf_tags;
13911 510472560 : dw_die_ref mod_scope;
13912 510472560 : struct array_descr_info info;
13913 : /* Only these cv-qualifiers are currently handled. */
13914 510472560 : const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE
13915 : | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC);
13916 : /* DW_AT_endianity is specified only for base types in the standard. */
13917 510472560 : const bool reverse_type
13918 510472772 : = need_endianity_attribute_p (reverse)
13919 212 : && (is_base_type (type)
13920 45 : || (TREE_CODE (type) == ENUMERAL_TYPE && !dwarf_strict));
13921 :
13922 510472560 : if (code == ERROR_MARK)
13923 : return NULL;
13924 :
13925 510472560 : if (lang_hooks.types.get_debug_type)
13926 : {
13927 501686968 : tree debug_type = lang_hooks.types.get_debug_type (type);
13928 :
13929 501686968 : if (debug_type != NULL_TREE && debug_type != type)
13930 226820 : return modified_type_die (debug_type, cv_quals, type_attrs, reverse,
13931 226820 : context_die);
13932 : }
13933 :
13934 510245740 : cv_quals &= cv_qual_mask;
13935 :
13936 : /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
13937 : tag modifier (and not an attribute) old consumers won't be able
13938 : to handle it. */
13939 510245740 : if (dwarf_version < 3)
13940 55512 : cv_quals &= ~TYPE_QUAL_RESTRICT;
13941 :
13942 : /* Likewise for DW_TAG_atomic_type for DWARFv5. */
13943 510245740 : if (dwarf_version < 5)
13944 57345 : cv_quals &= ~TYPE_QUAL_ATOMIC;
13945 :
13946 : /* See if we already have the appropriately qualified variant of
13947 : this type. */
13948 510245740 : qualified_type = get_qualified_type (type, cv_quals);
13949 :
13950 510245740 : if (qualified_type == sizetype)
13951 : {
13952 : /* Try not to expose the internal sizetype type's name. */
13953 925816 : if (TYPE_NAME (qualified_type)
13954 925816 : && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
13955 : {
13956 0 : tree t = TREE_TYPE (TYPE_NAME (qualified_type));
13957 :
13958 0 : gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
13959 : && (TYPE_PRECISION (t)
13960 : == TYPE_PRECISION (qualified_type))
13961 : && (TYPE_UNSIGNED (t)
13962 : == TYPE_UNSIGNED (qualified_type)));
13963 : qualified_type = t;
13964 : }
13965 925816 : else if (qualified_type == sizetype
13966 925816 : && TREE_CODE (sizetype) == TREE_CODE (size_type_node)
13967 925816 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (size_type_node)
13968 925816 : && TYPE_UNSIGNED (sizetype) == TYPE_UNSIGNED (size_type_node))
13969 : qualified_type = size_type_node;
13970 925816 : if (type == sizetype)
13971 925816 : type = qualified_type;
13972 : }
13973 :
13974 : /* If we do, then we can just use its DIE, if it exists. */
13975 510245740 : if (qualified_type)
13976 : {
13977 510029104 : mod_type_die = lookup_type_die (qualified_type);
13978 :
13979 : /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
13980 : dealt with specially: the DIE with the attribute, if it exists, is
13981 : placed immediately after the regular DIE for the same type. */
13982 510029104 : if (mod_type_die
13983 510029104 : && (!reverse_type
13984 160 : || ((mod_type_die = mod_type_die->die_sib) != NULL
13985 160 : && get_AT_unsigned (mod_type_die, DW_AT_endianity))))
13986 452963365 : return mod_type_die;
13987 : }
13988 :
13989 57065739 : name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13990 :
13991 : /* Handle C typedef types. */
13992 57065739 : if (name
13993 24637328 : && TREE_CODE (name) == TYPE_DECL
13994 24585103 : && DECL_ORIGINAL_TYPE (name)
13995 67036272 : && !DECL_ARTIFICIAL (name))
13996 : {
13997 9959173 : tree dtype = TREE_TYPE (name);
13998 :
13999 : /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
14000 9959173 : if (qualified_type == dtype && !reverse_type)
14001 : {
14002 7060921 : tree origin = decl_ultimate_origin (name);
14003 :
14004 : /* Typedef variants that have an abstract origin don't get their own
14005 : type DIE (see gen_typedef_die), so fall back on the ultimate
14006 : abstract origin instead. */
14007 7060921 : if (origin != NULL && origin != name)
14008 0 : return modified_type_die (TREE_TYPE (origin), cv_quals, type_attrs,
14009 0 : reverse, context_die);
14010 :
14011 : /* For a named type, use the typedef. */
14012 7060921 : gen_type_die (qualified_type, context_die);
14013 7060921 : return lookup_type_die (qualified_type);
14014 : }
14015 : else
14016 : {
14017 2898252 : int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
14018 2898252 : dquals &= cv_qual_mask;
14019 2898252 : if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
14020 2898252 : || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
14021 : {
14022 13292 : tree tags = lookup_attribute ("btf_type_tag", type_attrs);
14023 13292 : tree dtags = lookup_attribute ("btf_type_tag",
14024 13292 : TYPE_ATTRIBUTES (dtype));
14025 13292 : if (tags && !attribute_list_equal (tags, dtags))
14026 : {
14027 : /* Use of a typedef with additional btf_type_tags.
14028 : Create a new typedef DIE to which we can attach the
14029 : additional type_tag DIEs without disturbing other users of
14030 : the underlying typedef. */
14031 2 : dw_die_ref mod_die
14032 2 : = modified_type_die (dtype, cv_quals, NULL_TREE, reverse,
14033 : context_die);
14034 :
14035 2 : mod_die = clone_die (mod_die);
14036 2 : add_child_die (comp_unit_die (), mod_die);
14037 2 : if (!lookup_type_die (type))
14038 2 : equate_type_number_to_die (type, mod_die);
14039 :
14040 : /* Now generate the type_tag DIEs only for the new
14041 : type_tags appearing in the use of the typedef, and
14042 : attach them to the cloned typedef DIE. */
14043 2 : gen_btf_tag_dies (tags, mod_die);
14044 2 : return mod_die;
14045 : }
14046 : /* cv-unqualified version of named type. Just use
14047 : the unnamed type to which it refers. */
14048 13290 : return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals,
14049 13290 : type_attrs, reverse, context_die);
14050 : }
14051 : /* Else cv-qualified version of named type; fall through. */
14052 : }
14053 : }
14054 :
14055 50208162 : mod_scope = scope_die_for (type, context_die);
14056 :
14057 50208162 : if (cv_quals)
14058 : {
14059 13186401 : int sub_quals = 0, first_quals = 0;
14060 13186401 : unsigned i;
14061 13186401 : dw_die_ref first = NULL, last = NULL;
14062 :
14063 : /* Determine a lesser qualified type that most closely matches
14064 : this one. Then generate DW_TAG_* entries for the remaining
14065 : qualifiers. */
14066 13186401 : sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
14067 : cv_qual_mask);
14068 13186401 : if (sub_quals && use_debug_types)
14069 : {
14070 : bool needed = false;
14071 : /* If emitting type units, make sure the order of qualifiers
14072 : is canonical. Thus, start from unqualified type if
14073 : an earlier qualifier is missing in sub_quals, but some later
14074 : one is present there. */
14075 0 : for (i = 0; i < dwarf_qual_info_size; i++)
14076 0 : if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
14077 : needed = true;
14078 0 : else if (needed && (dwarf_qual_info[i].q & cv_quals))
14079 : {
14080 : sub_quals = 0;
14081 : break;
14082 : }
14083 : }
14084 13186401 : mod_type_die = modified_type_die (type, sub_quals, type_attrs,
14085 : reverse, context_die);
14086 13186401 : if (mod_scope && mod_type_die && mod_type_die->die_parent == mod_scope)
14087 : {
14088 : /* As not all intermediate qualified DIEs have corresponding
14089 : tree types, ensure that qualified DIEs in the same scope
14090 : as their DW_AT_type are emitted after their DW_AT_type,
14091 : only with other qualified DIEs for the same type possibly
14092 : in between them. Determine the range of such qualified
14093 : DIEs now (first being the base type, last being corresponding
14094 : last qualified DIE for it). */
14095 12885087 : unsigned int count = 0;
14096 12885087 : first = qualified_die_p (mod_type_die, &first_quals,
14097 : dwarf_qual_info_size);
14098 12885087 : if (first == NULL)
14099 12660461 : first = mod_type_die;
14100 12885087 : gcc_assert ((first_quals & ~sub_quals) == 0);
14101 : for (count = 0, last = first;
14102 13858381 : count < (1U << dwarf_qual_info_size);
14103 973294 : count++, last = last->die_sib)
14104 : {
14105 13858381 : int quals = 0;
14106 13858381 : if (last == mod_scope->die_child)
14107 : break;
14108 6131660 : if (qualified_die_p (last->die_sib, &quals, dwarf_qual_info_size)
14109 : != first)
14110 : break;
14111 : }
14112 : }
14113 :
14114 65932005 : for (i = 0; i < dwarf_qual_info_size; i++)
14115 52745604 : if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
14116 : {
14117 13200380 : dw_die_ref d;
14118 13200380 : if (first && first != last)
14119 : {
14120 753757 : for (d = first->die_sib; ; d = d->die_sib)
14121 : {
14122 987142 : int quals = 0;
14123 987142 : qualified_die_p (d, &quals, dwarf_qual_info_size);
14124 987142 : if (quals == (first_quals | dwarf_qual_info[i].q))
14125 : break;
14126 889296 : if (d == last)
14127 : {
14128 : d = NULL;
14129 : break;
14130 : }
14131 233385 : }
14132 753757 : if (d)
14133 : {
14134 97846 : mod_type_die = d;
14135 97846 : continue;
14136 : }
14137 : }
14138 13102534 : if (first)
14139 : {
14140 12801220 : d = new_die_raw (dwarf_qual_info[i].t);
14141 12801220 : add_child_die_after (mod_scope, d, last);
14142 12801220 : last = d;
14143 : }
14144 : else
14145 301314 : d = new_die (dwarf_qual_info[i].t, mod_scope, type);
14146 13102534 : if (mod_type_die)
14147 13074205 : add_AT_die_ref (d, DW_AT_type, mod_type_die);
14148 13102534 : mod_type_die = d;
14149 13102534 : first_quals |= dwarf_qual_info[i].q;
14150 : }
14151 : }
14152 37021761 : else if (type_attrs
14153 37021761 : && (btf_tags = lookup_attribute ("btf_type_tag", type_attrs)))
14154 : {
14155 : /* First create a DIE for the type without any type_tag attribute.
14156 : Then generate TAG_GNU_annotation DIEs for the type_tags. */
14157 29 : dw_die_ref mod_die = modified_type_die (type, cv_quals, NULL_TREE,
14158 : reverse, context_die);
14159 29 : gen_btf_tag_dies (btf_tags, mod_die);
14160 29 : return mod_die;
14161 : }
14162 37021732 : else if (code == POINTER_TYPE || code == REFERENCE_TYPE)
14163 : {
14164 31228301 : dwarf_tag tag = DW_TAG_pointer_type;
14165 31228301 : if (code == REFERENCE_TYPE)
14166 : {
14167 16260778 : if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
14168 : tag = DW_TAG_rvalue_reference_type;
14169 : else
14170 : tag = DW_TAG_reference_type;
14171 : }
14172 31228301 : mod_type_die = new_die (tag, mod_scope, type);
14173 :
14174 31228301 : add_AT_unsigned (mod_type_die, DW_AT_byte_size,
14175 31228301 : simple_type_size_in_bits (type) / BITS_PER_UNIT);
14176 31228301 : add_alignment_attribute (mod_type_die, type);
14177 31228301 : item_type = TREE_TYPE (type);
14178 :
14179 31228301 : addr_space_t as = TYPE_ADDR_SPACE (item_type);
14180 31228301 : if (!ADDR_SPACE_GENERIC_P (as))
14181 : {
14182 3 : int action = targetm.addr_space.debug (as);
14183 3 : if (action >= 0)
14184 : {
14185 : /* Positive values indicate an address_class. */
14186 3 : add_AT_unsigned (mod_type_die, DW_AT_address_class, action);
14187 : }
14188 : else
14189 : {
14190 : /* Negative values indicate an (inverted) segment base reg. */
14191 0 : dw_loc_descr_ref d
14192 0 : = one_reg_loc_descriptor (~action, VAR_INIT_STATUS_INITIALIZED);
14193 0 : add_AT_loc (mod_type_die, DW_AT_segment, d);
14194 : }
14195 : }
14196 : }
14197 5793431 : else if (code == ARRAY_TYPE
14198 5793431 : || (lang_hooks.types.get_array_descr_info
14199 21926 : && lang_hooks.types.get_array_descr_info (type, &info)))
14200 : {
14201 170447 : gen_type_die (type, mod_scope);
14202 170447 : return lookup_type_die (type);
14203 : }
14204 5622984 : else if (code == INTEGER_TYPE
14205 377329 : && TREE_TYPE (type) != NULL_TREE
14206 5623002 : && subrange_type_for_debug_p (type, &low, &high))
14207 : {
14208 18 : tree bias = NULL_TREE;
14209 18 : if (lang_hooks.types.get_type_bias)
14210 0 : bias = lang_hooks.types.get_type_bias (type);
14211 18 : mod_type_die = subrange_type_die (type, low, high, bias, mod_scope);
14212 18 : item_type = TREE_TYPE (type);
14213 : }
14214 5622966 : else if (is_base_type (type))
14215 : {
14216 : /* If a target supports long double as different floating point
14217 : modes with the same 16-byte size, use normal DW_TAG_base_type
14218 : only for the composite (ibm_extended_real_format) type and
14219 : for the other for the time being emit instead a "_Float128"
14220 : or "complex _Float128" DW_TAG_base_type and a "long double"
14221 : or "complex long double" typedef to it. */
14222 584780 : if (tree other_type = long_double_as_float128 (type))
14223 : {
14224 0 : dw_die_ref other_die;
14225 0 : if (TYPE_NAME (other_type))
14226 : {
14227 0 : other_die
14228 0 : = modified_type_die (other_type, TYPE_UNQUALIFIED,
14229 0 : TYPE_ATTRIBUTES (other_type),
14230 : reverse, context_die);
14231 : }
14232 : else
14233 : {
14234 0 : other_die = base_type_die (type, reverse);
14235 0 : add_child_die (comp_unit_die (), other_die);
14236 0 : add_name_attribute (other_die,
14237 0 : TREE_CODE (type) == COMPLEX_TYPE
14238 : ? "complex _Float128" : "_Float128");
14239 : }
14240 0 : mod_type_die = new_die_raw (DW_TAG_typedef);
14241 0 : add_AT_die_ref (mod_type_die, DW_AT_type, other_die);
14242 : }
14243 : else
14244 584780 : mod_type_die = base_type_die (type, reverse);
14245 :
14246 : /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
14247 584780 : if (reverse_type)
14248 : {
14249 57 : dw_die_ref after_die = modified_type_die (type, cv_quals, type_attrs,
14250 : false, context_die);
14251 57 : add_child_die_after (mod_scope, mod_type_die, after_die);
14252 : }
14253 : else
14254 584723 : add_child_die (mod_scope, mod_type_die);
14255 :
14256 584780 : add_pubtype (type, mod_type_die);
14257 : }
14258 : else
14259 : {
14260 : /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
14261 5038186 : if (reverse_type)
14262 : {
14263 2 : dw_die_ref after_die = modified_type_die (type, cv_quals, type_attrs,
14264 : false, context_die);
14265 2 : gen_type_die (type, context_die, true);
14266 2 : gcc_assert (after_die->die_sib
14267 : && get_AT_unsigned (after_die->die_sib, DW_AT_endianity));
14268 2 : return after_die->die_sib;
14269 : }
14270 :
14271 5038184 : gen_type_die (type, context_die);
14272 :
14273 : /* We have to get the type_main_variant here (and pass that to the
14274 : `lookup_type_die' routine) because the ..._TYPE node we have
14275 : might simply be a *copy* of some original type node (where the
14276 : copy was created to help us keep track of typedef names) and
14277 : that copy might have a different TYPE_UID from the original
14278 : ..._TYPE node. */
14279 5038184 : if (code == FUNCTION_TYPE || code == METHOD_TYPE)
14280 : {
14281 : /* For function/method types, can't just use type_main_variant here,
14282 : because that can have different ref-qualifiers for C++,
14283 : but try to canonicalize. */
14284 259819 : tree main = TYPE_MAIN_VARIANT (type);
14285 282177 : for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
14286 282165 : if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
14287 282002 : && check_base_type (t, main)
14288 554539 : && check_lang_type (t, type))
14289 259807 : return lookup_type_die (t);
14290 12 : return lookup_type_die (type);
14291 : }
14292 : /* Vectors have the debugging information in the type,
14293 : not the main variant. */
14294 4778365 : else if (code == VECTOR_TYPE)
14295 19900 : return lookup_type_die (type);
14296 : else
14297 4758465 : return lookup_type_die (type_main_variant (type));
14298 : }
14299 :
14300 : /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
14301 : don't output a DW_TAG_typedef, since there isn't one in the
14302 : user's program; just attach a DW_AT_name to the type.
14303 : Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
14304 : if the base type already has the same name. */
14305 44999500 : if (name
14306 44999500 : && ((TREE_CODE (name) != TYPE_DECL
14307 18163 : && (qualified_type == TYPE_MAIN_VARIANT (type)
14308 4441 : || (cv_quals == TYPE_UNQUALIFIED)))
14309 12940534 : || (TREE_CODE (name) == TYPE_DECL
14310 12936093 : && DECL_NAME (name)
14311 12936058 : && !DECL_NAMELESS (name)
14312 12935181 : && (TREE_TYPE (name) == qualified_type
14313 12353910 : || (lang_hooks.types.get_debug_type
14314 12295524 : && (lang_hooks.types.get_debug_type (TREE_TYPE (name))
14315 : == qualified_type))))))
14316 : {
14317 594993 : if (TREE_CODE (name) == TYPE_DECL)
14318 : /* Could just call add_name_and_src_coords_attributes here,
14319 : but since this is a builtin type it doesn't have any
14320 : useful source coordinates anyway. */
14321 581271 : name = DECL_NAME (name);
14322 594993 : add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
14323 : }
14324 44404507 : else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
14325 : {
14326 5771 : if (TREE_CODE (type) == BITINT_TYPE)
14327 : {
14328 57 : char name_buf[sizeof ("unsigned _BitInt(2147483647)")];
14329 228 : snprintf (name_buf, sizeof (name_buf),
14330 57 : "%s_BitInt(%d)", TYPE_UNSIGNED (type) ? "unsigned " : "",
14331 57 : TYPE_PRECISION (type));
14332 57 : add_name_attribute (mod_type_die, name_buf);
14333 : }
14334 : else
14335 : {
14336 : /* This probably indicates a bug. */
14337 5714 : name = TYPE_IDENTIFIER (type);
14338 6730 : add_name_attribute (mod_type_die,
14339 : name
14340 1016 : ? IDENTIFIER_POINTER (name) : "__unknown__");
14341 : }
14342 : }
14343 :
14344 44999500 : if (qualified_type && !reverse_type)
14345 44782857 : equate_type_number_to_die (qualified_type, mod_type_die);
14346 :
14347 44999500 : if (item_type)
14348 : /* We must do this after the equate_type_number_to_die call, in case
14349 : this is a recursive type. This ensures that the modified_type_die
14350 : recursion will terminate even if the type is recursive. Recursive
14351 : types are possible in Ada. */
14352 93684957 : sub_die = modified_type_die (item_type,
14353 31228319 : TYPE_QUALS_NO_ADDR_SPACE (item_type),
14354 31228319 : TYPE_ATTRIBUTES (item_type),
14355 : reverse, context_die);
14356 :
14357 31228319 : if (sub_die != NULL)
14358 31194892 : add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
14359 :
14360 44999500 : add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
14361 44999500 : if (TYPE_ARTIFICIAL (type))
14362 885 : add_AT_flag (mod_type_die, DW_AT_artificial, 1);
14363 :
14364 : return mod_type_die;
14365 : }
14366 :
14367 : /* Generate DIEs for the generic parameters of T.
14368 : T must be either a generic type or a generic function.
14369 : See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
14370 :
14371 : static void
14372 140311138 : gen_generic_params_dies (tree t)
14373 : {
14374 140311138 : tree parms, args;
14375 140311138 : int parms_num, i;
14376 140311138 : dw_die_ref die = NULL;
14377 140311138 : int non_default;
14378 :
14379 140311138 : if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
14380 : return;
14381 :
14382 140311138 : if (TYPE_P (t))
14383 42503775 : die = lookup_type_die (t);
14384 97807363 : else if (DECL_P (t))
14385 97807363 : die = lookup_decl_die (t);
14386 :
14387 140311138 : gcc_assert (die);
14388 :
14389 140311138 : parms = lang_hooks.get_innermost_generic_parms (t);
14390 140311138 : if (!parms)
14391 : /* T has no generic parameter. It means T is neither a generic type
14392 : or function. End of story. */
14393 : return;
14394 :
14395 43388903 : parms_num = TREE_VEC_LENGTH (parms);
14396 43388903 : args = lang_hooks.get_innermost_generic_args (t);
14397 43388903 : if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
14398 43388634 : non_default = int_cst_value (TREE_CHAIN (args));
14399 : else
14400 269 : non_default = TREE_VEC_LENGTH (args);
14401 110236889 : for (i = 0; i < parms_num; i++)
14402 : {
14403 66847986 : tree parm, arg, arg_pack_elems;
14404 66847986 : dw_die_ref parm_die;
14405 :
14406 66847986 : parm = TREE_VEC_ELT (parms, i);
14407 66847986 : arg = TREE_VEC_ELT (args, i);
14408 66847986 : arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
14409 133695972 : gcc_assert (parm && TREE_VALUE (parm) && arg);
14410 :
14411 66847986 : if (parm && TREE_VALUE (parm) && arg)
14412 : {
14413 : /* If PARM represents a template parameter pack,
14414 : emit a DW_TAG_GNU_template_parameter_pack DIE, followed
14415 : by DW_TAG_template_*_parameter DIEs for the argument
14416 : pack elements of ARG. Note that ARG would then be
14417 : an argument pack. */
14418 66847986 : if (arg_pack_elems)
14419 5348669 : parm_die = template_parameter_pack_die (TREE_VALUE (parm),
14420 : arg_pack_elems,
14421 : die);
14422 : else
14423 61499317 : parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
14424 : true /* emit name */, die);
14425 66847986 : if (i >= non_default)
14426 918815 : add_AT_flag (parm_die, DW_AT_default_value, 1);
14427 : }
14428 : }
14429 : }
14430 :
14431 : /* Create and return a DIE for PARM which should be
14432 : the representation of a generic type parameter.
14433 : For instance, in the C++ front end, PARM would be a template parameter.
14434 : ARG is the argument to PARM.
14435 : EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
14436 : name of the PARM.
14437 : PARENT_DIE is the parent DIE which the new created DIE should be added to,
14438 : as a child node. */
14439 :
14440 : static dw_die_ref
14441 72276731 : generic_parameter_die (tree parm, tree arg,
14442 : bool emit_name_p,
14443 : dw_die_ref parent_die)
14444 : {
14445 72276731 : dw_die_ref tmpl_die = NULL;
14446 72276731 : const char *name = NULL;
14447 :
14448 : /* C++20 accepts class literals as template parameters, and var
14449 : decls with initializers represent them. The VAR_DECLs would be
14450 : rejected, but we can take the DECL_INITIAL constructor and
14451 : attempt to expand it. */
14452 72276731 : if (arg && VAR_P (arg))
14453 3832 : arg = DECL_INITIAL (arg);
14454 :
14455 72276731 : if (!parm || !DECL_NAME (parm) || !arg)
14456 : return NULL;
14457 :
14458 : /* We support non-type generic parameters and arguments,
14459 : type generic parameters and arguments, as well as
14460 : generic generic parameters (a.k.a. template template parameters in C++)
14461 : and arguments. */
14462 62368400 : if (TREE_CODE (parm) == PARM_DECL)
14463 : /* PARM is a nontype generic parameter */
14464 10977381 : tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
14465 51391019 : else if (TREE_CODE (parm) == TYPE_DECL)
14466 : /* PARM is a type generic parameter. */
14467 51246314 : tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
14468 144705 : else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
14469 : /* PARM is a generic generic parameter.
14470 : Its DIE is a GNU extension. It shall have a
14471 : DW_AT_name attribute to represent the name of the template template
14472 : parameter, and a DW_AT_GNU_template_name attribute to represent the
14473 : name of the template template argument. */
14474 144705 : tmpl_die = new_die (DW_TAG_GNU_template_template_param,
14475 : parent_die, parm);
14476 : else
14477 0 : gcc_unreachable ();
14478 :
14479 62368400 : if (tmpl_die)
14480 : {
14481 62368400 : tree tmpl_type;
14482 :
14483 : /* If PARM is a generic parameter pack, it means we are
14484 : emitting debug info for a template argument pack element.
14485 : In other terms, ARG is a template argument pack element.
14486 : In that case, we don't emit any DW_AT_name attribute for
14487 : the die. */
14488 62368400 : if (emit_name_p)
14489 : {
14490 51923133 : name = IDENTIFIER_POINTER (DECL_NAME (parm));
14491 51923133 : gcc_assert (name);
14492 51923133 : add_AT_string (tmpl_die, DW_AT_name, name);
14493 : }
14494 :
14495 62368400 : if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
14496 : {
14497 : /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
14498 : TMPL_DIE should have a child DW_AT_type attribute that is set
14499 : to the type of the argument to PARM, which is ARG.
14500 : If PARM is a type generic parameter, TMPL_DIE should have a
14501 : child DW_AT_type that is set to ARG. */
14502 62223695 : tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
14503 62223695 : add_type_attribute (tmpl_die, tmpl_type,
14504 62223695 : (TREE_THIS_VOLATILE (tmpl_type)
14505 62223695 : ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED),
14506 : false, parent_die);
14507 : }
14508 : else
14509 : {
14510 : /* So TMPL_DIE is a DIE representing a
14511 : a generic generic template parameter, a.k.a template template
14512 : parameter in C++ and arg is a template. */
14513 :
14514 : /* The DW_AT_GNU_template_name attribute of the DIE must be set
14515 : to the name of the argument. */
14516 144705 : name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
14517 144705 : if (name)
14518 144705 : add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
14519 : }
14520 :
14521 62368400 : if (TREE_CODE (parm) == PARM_DECL)
14522 : /* So PARM is a non-type generic parameter.
14523 : DWARF3 5.6.8 says we must set a DW_AT_const_value child
14524 : attribute of TMPL_DIE which value represents the value
14525 : of ARG.
14526 : We must be careful here:
14527 : The value of ARG might reference some function decls.
14528 : We might currently be emitting debug info for a generic
14529 : type and types are emitted before function decls, we don't
14530 : know if the function decls referenced by ARG will actually be
14531 : emitted after cgraph computations.
14532 : So must defer the generation of the DW_AT_const_value to
14533 : after cgraph is ready. */
14534 10977381 : append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
14535 : }
14536 :
14537 : return tmpl_die;
14538 : }
14539 :
14540 : /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
14541 : PARM_PACK must be a template parameter pack. The returned DIE
14542 : will be child DIE of PARENT_DIE. */
14543 :
14544 : static dw_die_ref
14545 5348669 : template_parameter_pack_die (tree parm_pack,
14546 : tree parm_pack_args,
14547 : dw_die_ref parent_die)
14548 : {
14549 5348669 : dw_die_ref die;
14550 5348669 : int j;
14551 :
14552 5348669 : gcc_assert (parent_die && parm_pack);
14553 :
14554 5348669 : die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
14555 5348669 : add_name_and_src_coords_attributes (die, parm_pack);
14556 21474752 : for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
14557 10777414 : generic_parameter_die (parm_pack,
14558 10777414 : TREE_VEC_ELT (parm_pack_args, j),
14559 : false /* Don't emit DW_AT_name */,
14560 : die);
14561 5348669 : return die;
14562 : }
14563 :
14564 : /* Return the debugger register number described by a given RTL node. */
14565 :
14566 : static unsigned int
14567 15624137 : debugger_reg_number (const_rtx rtl)
14568 : {
14569 15624137 : unsigned regno = REGNO (rtl);
14570 :
14571 15624137 : gcc_assert (regno < FIRST_PSEUDO_REGISTER);
14572 :
14573 : #ifdef LEAF_REG_REMAP
14574 : if (crtl->uses_only_leaf_regs)
14575 : {
14576 : int leaf_reg = LEAF_REG_REMAP (regno);
14577 : if (leaf_reg != -1)
14578 : regno = (unsigned) leaf_reg;
14579 : }
14580 : #endif
14581 :
14582 15624137 : regno = DEBUGGER_REGNO (regno);
14583 15624137 : gcc_assert (regno != INVALID_REGNUM);
14584 15624137 : return regno;
14585 : }
14586 :
14587 : /* Optionally add a DW_OP_piece term to a location description expression.
14588 : DW_OP_piece is only added if the location description expression already
14589 : doesn't end with DW_OP_piece. */
14590 :
14591 : static void
14592 568492 : add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
14593 : {
14594 568492 : dw_loc_descr_ref loc;
14595 :
14596 568492 : if (*list_head != NULL)
14597 : {
14598 : /* Find the end of the chain. */
14599 1297829 : for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
14600 : ;
14601 :
14602 568492 : if (loc->dw_loc_opc != DW_OP_piece)
14603 568474 : loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
14604 : }
14605 568492 : }
14606 :
14607 : /* Return a location descriptor that designates a machine register or
14608 : zero if there is none. */
14609 :
14610 : static dw_loc_descr_ref
14611 14250095 : reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
14612 : {
14613 14250095 : rtx regs;
14614 :
14615 14250095 : if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
14616 : return 0;
14617 :
14618 : /* We only use "frame base" when we're sure we're talking about the
14619 : post-prologue local stack frame. We do this by *not* running
14620 : register elimination until this point, and recognizing the special
14621 : argument pointer and soft frame pointer rtx's.
14622 : Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
14623 14201911 : if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
14624 14206877 : && (ira_use_lra_p
14625 2483 : ? lra_eliminate_regs (rtl, VOIDmode, NULL_RTX)
14626 0 : : eliminate_regs (rtl, VOIDmode, NULL_RTX)) != rtl)
14627 : {
14628 2483 : dw_loc_descr_ref result = NULL;
14629 :
14630 2483 : if (dwarf_version >= 4 || !dwarf_strict)
14631 : {
14632 2483 : result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
14633 : initialized);
14634 2483 : if (result)
14635 4966 : add_loc_descr (&result,
14636 : new_loc_descr (DW_OP_stack_value, 0, 0));
14637 : }
14638 2483 : return result;
14639 : }
14640 :
14641 14201911 : regs = targetm.dwarf_register_span (rtl);
14642 :
14643 14201911 : if (REG_NREGS (rtl) > 1 || regs)
14644 92949 : return multiple_reg_loc_descriptor (rtl, regs, initialized);
14645 : else
14646 : {
14647 14108962 : unsigned int debugger_regnum = debugger_reg_number (rtl);
14648 14108962 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
14649 : return 0;
14650 14108962 : return one_reg_loc_descriptor (debugger_regnum, initialized);
14651 : }
14652 : }
14653 :
14654 : /* Return a location descriptor that designates a machine register for
14655 : a given hard register number. */
14656 :
14657 : static dw_loc_descr_ref
14658 15607774 : one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
14659 : {
14660 15607774 : dw_loc_descr_ref reg_loc_descr;
14661 :
14662 15607774 : if (regno <= 31)
14663 15590282 : reg_loc_descr
14664 15590282 : = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
14665 : else
14666 17492 : reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
14667 :
14668 15607774 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14669 204154 : add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14670 :
14671 15607774 : return reg_loc_descr;
14672 : }
14673 :
14674 : /* Given an RTL of a register, return a location descriptor that
14675 : designates a value that spans more than one register. */
14676 :
14677 : static dw_loc_descr_ref
14678 92949 : multiple_reg_loc_descriptor (rtx rtl, rtx regs,
14679 : enum var_init_status initialized)
14680 : {
14681 92949 : int size, i;
14682 92949 : dw_loc_descr_ref loc_result = NULL;
14683 :
14684 : /* Simple, contiguous registers. */
14685 92949 : if (regs == NULL_RTX)
14686 : {
14687 92949 : unsigned reg = REGNO (rtl);
14688 92949 : int nregs;
14689 :
14690 : #ifdef LEAF_REG_REMAP
14691 : if (crtl->uses_only_leaf_regs)
14692 : {
14693 : int leaf_reg = LEAF_REG_REMAP (reg);
14694 : if (leaf_reg != -1)
14695 : reg = (unsigned) leaf_reg;
14696 : }
14697 : #endif
14698 :
14699 92949 : gcc_assert ((unsigned) DEBUGGER_REGNO (reg) == debugger_reg_number (rtl));
14700 92949 : nregs = REG_NREGS (rtl);
14701 :
14702 : /* At present we only track constant-sized pieces. */
14703 185898 : if (!GET_MODE_SIZE (GET_MODE (rtl)).is_constant (&size))
14704 : return NULL;
14705 92949 : size /= nregs;
14706 :
14707 92949 : loc_result = NULL;
14708 278847 : while (nregs--)
14709 : {
14710 185898 : dw_loc_descr_ref t;
14711 :
14712 185898 : t = one_reg_loc_descriptor (DEBUGGER_REGNO (reg),
14713 : VAR_INIT_STATUS_INITIALIZED);
14714 185898 : add_loc_descr (&loc_result, t);
14715 185898 : add_loc_descr_op_piece (&loc_result, size);
14716 185898 : ++reg;
14717 : }
14718 92949 : return loc_result;
14719 : }
14720 :
14721 : /* Now onto stupid register sets in non contiguous locations. */
14722 :
14723 0 : gcc_assert (GET_CODE (regs) == PARALLEL);
14724 :
14725 : /* At present we only track constant-sized pieces. */
14726 0 : if (!GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))).is_constant (&size))
14727 : return NULL;
14728 0 : loc_result = NULL;
14729 :
14730 0 : for (i = 0; i < XVECLEN (regs, 0); ++i)
14731 : {
14732 0 : dw_loc_descr_ref t;
14733 :
14734 0 : t = one_reg_loc_descriptor (debugger_reg_number (XVECEXP (regs, 0, i)),
14735 : VAR_INIT_STATUS_INITIALIZED);
14736 0 : add_loc_descr (&loc_result, t);
14737 0 : add_loc_descr_op_piece (&loc_result, size);
14738 : }
14739 :
14740 0 : if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14741 0 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14742 0 : return loc_result;
14743 : }
14744 :
14745 : static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
14746 :
14747 : /* Return a location descriptor that designates a constant i,
14748 : as a compound operation from constant (i >> shift), constant shift
14749 : and DW_OP_shl. */
14750 :
14751 : static dw_loc_descr_ref
14752 35962 : int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
14753 : {
14754 35962 : dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
14755 35962 : add_loc_descr (&ret, int_loc_descriptor (shift));
14756 35962 : add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14757 35962 : return ret;
14758 : }
14759 :
14760 : /* Return a location descriptor that designates constant POLY_I. */
14761 :
14762 : static dw_loc_descr_ref
14763 5587820 : int_loc_descriptor (poly_int64 poly_i)
14764 : {
14765 5587820 : enum dwarf_location_atom op;
14766 :
14767 5587820 : HOST_WIDE_INT i;
14768 5587820 : if (!poly_i.is_constant (&i))
14769 : {
14770 : /* Create location descriptions for the non-constant part and
14771 : add any constant offset at the end. */
14772 : dw_loc_descr_ref ret = NULL;
14773 : HOST_WIDE_INT constant = poly_i.coeffs[0];
14774 : for (unsigned int j = 1; j < NUM_POLY_INT_COEFFS; ++j)
14775 : {
14776 : HOST_WIDE_INT coeff = poly_i.coeffs[j];
14777 : if (coeff != 0)
14778 : {
14779 : dw_loc_descr_ref start = ret;
14780 : unsigned int factor;
14781 : int bias;
14782 : unsigned int regno = targetm.dwarf_poly_indeterminate_value
14783 : (j, &factor, &bias);
14784 :
14785 : /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
14786 : add COEFF * (REGNO / FACTOR) now and subtract
14787 : COEFF * BIAS from the final constant part. */
14788 : constant -= coeff * bias;
14789 : add_loc_descr (&ret, new_reg_loc_descr (regno, 0));
14790 : if (coeff % factor == 0)
14791 : coeff /= factor;
14792 : else
14793 : {
14794 : int amount = exact_log2 (factor);
14795 : gcc_assert (amount >= 0);
14796 : add_loc_descr (&ret, int_loc_descriptor (amount));
14797 : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14798 : }
14799 : if (coeff != 1)
14800 : {
14801 : add_loc_descr (&ret, int_loc_descriptor (coeff));
14802 : add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
14803 : }
14804 : if (start)
14805 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
14806 : }
14807 : }
14808 : loc_descr_plus_const (&ret, constant);
14809 : return ret;
14810 : }
14811 :
14812 : /* Pick the smallest representation of a constant, rather than just
14813 : defaulting to the LEB encoding. */
14814 5587820 : if (i >= 0)
14815 : {
14816 5297946 : int clz = clz_hwi (i);
14817 3467033 : int ctz = ctz_hwi (i);
14818 5297946 : if (i <= 31)
14819 3924070 : op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
14820 1373876 : else if (i <= 0xff)
14821 : op = DW_OP_const1u;
14822 457620 : else if (i <= 0xffff)
14823 : op = DW_OP_const2u;
14824 299444 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
14825 : && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
14826 : /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
14827 : DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
14828 : while DW_OP_const4u is 5 bytes. */
14829 33574 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
14830 265870 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
14831 1613 : && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
14832 : /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
14833 : while DW_OP_const4u is 5 bytes. */
14834 1186 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
14835 :
14836 264684 : else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
14837 3668 : && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
14838 : <= 4)
14839 : {
14840 : /* As i >= 2**31, the double cast above will yield a negative number.
14841 : Since wrapping is defined in DWARF expressions we can output big
14842 : positive integers as small negative ones, regardless of the size
14843 : of host wide ints.
14844 :
14845 : Here, since the evaluator will handle 32-bit values and since i >=
14846 : 2**31, we know it's going to be interpreted as a negative literal:
14847 : store it this way if we can do better than 5 bytes this way. */
14848 0 : return int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
14849 : }
14850 264684 : else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
14851 : op = DW_OP_const4u;
14852 :
14853 : /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
14854 : least 6 bytes: see if we can do better before falling back to it. */
14855 78388 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
14856 : && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
14857 : /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
14858 427 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
14859 77961 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
14860 77961 : && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
14861 : >= HOST_BITS_PER_WIDE_INT)
14862 : /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
14863 : DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
14864 550 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
14865 77411 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
14866 : && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
14867 77411 : && size_of_uleb128 (i) > 6)
14868 : /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
14869 225 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
14870 : else
14871 : op = DW_OP_constu;
14872 : }
14873 : else
14874 : {
14875 289874 : if (i >= -0x80)
14876 : op = DW_OP_const1s;
14877 52566 : else if (i >= -0x8000)
14878 : op = DW_OP_const2s;
14879 48018 : else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
14880 : {
14881 : if (size_of_int_loc_descriptor (i) < 5)
14882 : {
14883 : dw_loc_descr_ref ret = int_loc_descriptor (-i);
14884 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14885 : return ret;
14886 : }
14887 : op = DW_OP_const4s;
14888 : }
14889 : else
14890 : {
14891 48018 : if (size_of_int_loc_descriptor (i)
14892 48018 : < (unsigned long) 1 + size_of_sleb128 (i))
14893 : {
14894 4051 : dw_loc_descr_ref ret = int_loc_descriptor (-i);
14895 4051 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14896 4051 : return ret;
14897 : }
14898 : op = DW_OP_consts;
14899 : }
14900 : }
14901 :
14902 5547807 : return new_loc_descr (op, i, 0);
14903 : }
14904 :
14905 : /* Likewise, for unsigned constants. */
14906 :
14907 : static dw_loc_descr_ref
14908 125616 : uint_loc_descriptor (unsigned HOST_WIDE_INT i)
14909 : {
14910 125616 : const unsigned HOST_WIDE_INT max_int = INTTYPE_MAXIMUM (HOST_WIDE_INT);
14911 125616 : const unsigned HOST_WIDE_INT max_uint
14912 : = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT);
14913 :
14914 : /* If possible, use the clever signed constants handling. */
14915 125616 : if (i <= max_int)
14916 125608 : return int_loc_descriptor ((HOST_WIDE_INT) i);
14917 :
14918 : /* Here, we are left with positive numbers that cannot be represented as
14919 : HOST_WIDE_INT, i.e.:
14920 : max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
14921 :
14922 : Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
14923 : whereas may be better to output a negative integer: thanks to integer
14924 : wrapping, we know that:
14925 : x = x - 2 ** DWARF2_ADDR_SIZE
14926 : = x - 2 * (max (HOST_WIDE_INT) + 1)
14927 : So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
14928 : small negative integers. Let's try that in cases it will clearly improve
14929 : the encoding: there is no gain turning DW_OP_const4u into
14930 : DW_OP_const4s. */
14931 8 : if (DWARF2_ADDR_SIZE * 8 == HOST_BITS_PER_WIDE_INT
14932 : && ((DWARF2_ADDR_SIZE == 4 && i > max_uint - 0x8000)
14933 8 : || (DWARF2_ADDR_SIZE == 8 && i > max_uint - 0x80000000)))
14934 : {
14935 4 : const unsigned HOST_WIDE_INT first_shift = i - max_int - 1;
14936 :
14937 : /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
14938 : i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
14939 4 : const HOST_WIDE_INT second_shift
14940 : = (HOST_WIDE_INT) first_shift - (HOST_WIDE_INT) max_int - 1;
14941 :
14942 : /* So we finally have:
14943 : -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
14944 : i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
14945 4 : return int_loc_descriptor (second_shift);
14946 : }
14947 :
14948 : /* Last chance: fallback to a simple constant operation. */
14949 4 : return new_loc_descr
14950 4 : ((HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
14951 : ? DW_OP_const4u
14952 : : DW_OP_const8u,
14953 4 : i, 0);
14954 : }
14955 :
14956 : /* Generate and return a location description that computes the unsigned
14957 : comparison of the two stack top entries (a OP b where b is the top-most
14958 : entry and a is the second one). The KIND of comparison can be LT_EXPR,
14959 : LE_EXPR, GT_EXPR or GE_EXPR. */
14960 :
14961 : static dw_loc_descr_ref
14962 0 : uint_comparison_loc_list (enum tree_code kind)
14963 : {
14964 0 : enum dwarf_location_atom op, flip_op;
14965 0 : dw_loc_descr_ref ret, bra_node, jmp_node, tmp;
14966 :
14967 0 : switch (kind)
14968 : {
14969 : case LT_EXPR:
14970 : op = DW_OP_lt;
14971 : break;
14972 : case LE_EXPR:
14973 : op = DW_OP_le;
14974 : break;
14975 : case GT_EXPR:
14976 : op = DW_OP_gt;
14977 : break;
14978 : case GE_EXPR:
14979 : op = DW_OP_ge;
14980 : break;
14981 0 : default:
14982 0 : gcc_unreachable ();
14983 : }
14984 :
14985 0 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14986 0 : jmp_node = new_loc_descr (DW_OP_skip, 0, 0);
14987 :
14988 : /* Until DWARFv4, operations all work on signed integers. It is nevertheless
14989 : possible to perform unsigned comparisons: we just have to distinguish
14990 : three cases:
14991 :
14992 : 1. when a and b have the same sign (as signed integers); then we should
14993 : return: a OP(signed) b;
14994 :
14995 : 2. when a is a negative signed integer while b is a positive one, then a
14996 : is a greater unsigned integer than b; likewise when a and b's roles
14997 : are flipped.
14998 :
14999 : So first, compare the sign of the two operands. */
15000 0 : ret = new_loc_descr (DW_OP_over, 0, 0);
15001 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
15002 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_xor, 0, 0));
15003 : /* If they have different signs (i.e. they have different sign bits), then
15004 : the stack top value has now the sign bit set and thus it's smaller than
15005 : zero. */
15006 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_lit0, 0, 0));
15007 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_lt, 0, 0));
15008 0 : add_loc_descr (&ret, bra_node);
15009 :
15010 : /* We are in case 1. At this point, we know both operands have the same
15011 : sign, to it's safe to use the built-in signed comparison. */
15012 0 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
15013 0 : add_loc_descr (&ret, jmp_node);
15014 :
15015 : /* We are in case 2. Here, we know both operands do not have the same sign,
15016 : so we have to flip the signed comparison. */
15017 0 : flip_op = (kind == LT_EXPR || kind == LE_EXPR) ? DW_OP_gt : DW_OP_lt;
15018 0 : tmp = new_loc_descr (flip_op, 0, 0);
15019 0 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15020 0 : bra_node->dw_loc_oprnd1.v.val_loc = tmp;
15021 0 : add_loc_descr (&ret, tmp);
15022 :
15023 : /* This dummy operation is necessary to make the two branches join. */
15024 0 : tmp = new_loc_descr (DW_OP_nop, 0, 0);
15025 0 : jmp_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15026 0 : jmp_node->dw_loc_oprnd1.v.val_loc = tmp;
15027 0 : add_loc_descr (&ret, tmp);
15028 :
15029 0 : return ret;
15030 : }
15031 :
15032 : /* Likewise, but takes the location description lists (might be destructive on
15033 : them). Return NULL if either is NULL or if concatenation fails. */
15034 :
15035 : static dw_loc_list_ref
15036 0 : loc_list_from_uint_comparison (dw_loc_list_ref left, dw_loc_list_ref right,
15037 : enum tree_code kind)
15038 : {
15039 0 : if (left == NULL || right == NULL)
15040 : return NULL;
15041 :
15042 0 : add_loc_list (&left, right);
15043 0 : if (left == NULL)
15044 : return NULL;
15045 :
15046 0 : add_loc_descr_to_each (left, uint_comparison_loc_list (kind));
15047 0 : return left;
15048 : }
15049 :
15050 : /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
15051 : without actually allocating it. */
15052 :
15053 : static unsigned long
15054 30471 : size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
15055 : {
15056 30471 : return size_of_int_loc_descriptor (i >> shift)
15057 30471 : + size_of_int_loc_descriptor (shift)
15058 30471 : + 1;
15059 : }
15060 :
15061 : /* Return size_of_locs (int_loc_descriptor (i)) without
15062 : actually allocating it. */
15063 :
15064 : static unsigned long
15065 4195308 : size_of_int_loc_descriptor (HOST_WIDE_INT i)
15066 : {
15067 4196815 : unsigned long s;
15068 :
15069 4196815 : if (i >= 0)
15070 : {
15071 3757301 : int clz, ctz;
15072 3757301 : if (i <= 31)
15073 : return 1;
15074 590544 : else if (i <= 0xff)
15075 : return 2;
15076 205077 : else if (i <= 0xffff)
15077 : return 3;
15078 127570 : clz = clz_hwi (i);
15079 127570 : ctz = ctz_hwi (i);
15080 127570 : if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
15081 : && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
15082 27699 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15083 27699 : - clz - 5);
15084 99871 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
15085 2140 : && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
15086 1238 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15087 1238 : - clz - 8);
15088 98633 : else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
15089 2825 : && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
15090 : <= 4)
15091 : return size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
15092 97126 : else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
15093 : return 5;
15094 50129 : s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
15095 50129 : if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
15096 : && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
15097 899 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15098 899 : - clz - 8);
15099 49230 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
15100 410 : && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
15101 410 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15102 410 : - clz - 16);
15103 48820 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
15104 : && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
15105 381 : && s > 6)
15106 225 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15107 225 : - clz - 32);
15108 : else
15109 48595 : return 1 + s;
15110 : }
15111 : else
15112 : {
15113 439514 : if (i >= -0x80)
15114 : return 2;
15115 342620 : else if (i >= -0x8000)
15116 : return 3;
15117 340342 : else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
15118 : {
15119 : if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
15120 : {
15121 : s = size_of_int_loc_descriptor (-i) + 1;
15122 : if (s < 5)
15123 : return s;
15124 : }
15125 : return 5;
15126 : }
15127 : else
15128 : {
15129 340342 : unsigned long r = 1 + size_of_sleb128 (i);
15130 340342 : if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
15131 : {
15132 56442 : s = size_of_int_loc_descriptor (-i) + 1;
15133 56442 : if (s < r)
15134 : return s;
15135 : }
15136 333592 : return r;
15137 : }
15138 : }
15139 : }
15140 :
15141 : /* Return loc description representing "address" of integer value.
15142 : This can appear only as toplevel expression. */
15143 :
15144 : static dw_loc_descr_ref
15145 2911291 : address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
15146 : {
15147 2911291 : int litsize;
15148 2911291 : dw_loc_descr_ref loc_result = NULL;
15149 :
15150 2911291 : if (!(dwarf_version >= 4 || !dwarf_strict))
15151 : return NULL;
15152 :
15153 2911291 : litsize = size_of_int_loc_descriptor (i);
15154 : /* Determine if DW_OP_stack_value or DW_OP_implicit_value
15155 : is more compact. For DW_OP_stack_value we need:
15156 : litsize + 1 (DW_OP_stack_value)
15157 : and for DW_OP_implicit_value:
15158 : 1 (DW_OP_implicit_value) + 1 (length) + size. */
15159 3463797 : if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
15160 : {
15161 2862416 : loc_result = int_loc_descriptor (i);
15162 2862416 : add_loc_descr (&loc_result,
15163 : new_loc_descr (DW_OP_stack_value, 0, 0));
15164 2862416 : return loc_result;
15165 : }
15166 :
15167 48875 : loc_result = new_loc_descr (DW_OP_implicit_value,
15168 : size, 0);
15169 48875 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
15170 48875 : loc_result->dw_loc_oprnd2.v.val_int = i;
15171 48875 : return loc_result;
15172 : }
15173 :
15174 : /* Return a location descriptor that designates a base+offset location. */
15175 :
15176 : static dw_loc_descr_ref
15177 12797332 : based_loc_descr (rtx reg, poly_int64 offset,
15178 : enum var_init_status initialized)
15179 : {
15180 12797332 : unsigned int regno;
15181 12797332 : dw_loc_descr_ref result;
15182 12797332 : dw_fde_ref fde = cfun->fde;
15183 :
15184 : /* We only use "frame base" when we're sure we're talking about the
15185 : post-prologue local stack frame. We do this by *not* running
15186 : register elimination until this point, and recognizing the special
15187 : argument pointer and soft frame pointer rtx's. */
15188 12797332 : if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
15189 : {
15190 7858351 : rtx elim = (ira_use_lra_p
15191 7858351 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
15192 7858351 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
15193 :
15194 7858351 : if (elim != reg)
15195 : {
15196 : /* Allow hard frame pointer here even if frame pointer
15197 : isn't used since hard frame pointer is encoded with
15198 : DW_OP_fbreg which uses the DW_AT_frame_base attribute,
15199 : not hard frame pointer directly. */
15200 7858351 : elim = strip_offset_and_add (elim, &offset);
15201 7858351 : gcc_assert (elim == hard_frame_pointer_rtx
15202 : || elim == stack_pointer_rtx);
15203 :
15204 : /* If drap register is used to align stack, use frame
15205 : pointer + offset to access stack variables. If stack
15206 : is aligned without drap, use stack pointer + offset to
15207 : access stack variables. */
15208 7858351 : if (crtl->stack_realign_tried
15209 11930 : && reg == frame_pointer_rtx)
15210 : {
15211 4942 : int base_reg
15212 4942 : = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
15213 : ? HARD_FRAME_POINTER_REGNUM
15214 : : REGNO (elim));
15215 4942 : return new_reg_loc_descr (base_reg, offset);
15216 : }
15217 :
15218 7853409 : gcc_assert (frame_pointer_fb_offset_valid);
15219 7853409 : offset += frame_pointer_fb_offset;
15220 7853409 : HOST_WIDE_INT const_offset;
15221 7853409 : if (offset.is_constant (&const_offset))
15222 7853409 : return new_loc_descr (DW_OP_fbreg, const_offset, 0);
15223 : else
15224 : {
15225 : dw_loc_descr_ref ret = new_loc_descr (DW_OP_fbreg, 0, 0);
15226 : loc_descr_plus_const (&ret, offset);
15227 : return ret;
15228 : }
15229 : }
15230 : }
15231 :
15232 4938981 : regno = REGNO (reg);
15233 : #ifdef LEAF_REG_REMAP
15234 : if (crtl->uses_only_leaf_regs)
15235 : {
15236 : int leaf_reg = LEAF_REG_REMAP (regno);
15237 : if (leaf_reg != -1)
15238 : regno = (unsigned) leaf_reg;
15239 : }
15240 : #endif
15241 4938981 : regno = DWARF_FRAME_REGNUM (regno);
15242 :
15243 4938981 : HOST_WIDE_INT const_offset;
15244 16245 : if (!optimize && fde
15245 16245 : && (fde->drap_reg == regno || fde->vdrap_reg == regno)
15246 4938981 : && offset.is_constant (&const_offset))
15247 : {
15248 : /* Use cfa+offset to represent the location of arguments passed
15249 : on the stack when drap is used to align stack.
15250 : Only do this when not optimizing, for optimized code var-tracking
15251 : is supposed to track where the arguments live and the register
15252 : used as vdrap or drap in some spot might be used for something
15253 : else in other part of the routine. */
15254 3082 : return new_loc_descr (DW_OP_fbreg, const_offset, 0);
15255 : }
15256 :
15257 4935899 : result = new_reg_loc_descr (regno, offset);
15258 :
15259 4935899 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
15260 0 : add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15261 :
15262 4935899 : return result;
15263 : }
15264 :
15265 : /* Return true if this RTL expression describes a base+offset calculation. */
15266 :
15267 : static inline bool
15268 11211098 : is_based_loc (const_rtx rtl)
15269 : {
15270 11211098 : return (GET_CODE (rtl) == PLUS
15271 11211098 : && ((REG_P (XEXP (rtl, 0))
15272 9932758 : && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
15273 9930886 : && CONST_INT_P (XEXP (rtl, 1)))));
15274 : }
15275 :
15276 : /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
15277 : failed. */
15278 :
15279 : static dw_loc_descr_ref
15280 18350 : tls_mem_loc_descriptor (rtx mem)
15281 : {
15282 18350 : tree base;
15283 18350 : dw_loc_descr_ref loc_result;
15284 :
15285 18350 : if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
15286 : return NULL;
15287 :
15288 16930 : base = get_base_address (MEM_EXPR (mem));
15289 16930 : if (base == NULL
15290 16930 : || !VAR_P (base)
15291 31967 : || !DECL_THREAD_LOCAL_P (base))
15292 16930 : return NULL;
15293 :
15294 0 : loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1, NULL);
15295 0 : if (loc_result == NULL)
15296 : return NULL;
15297 :
15298 0 : if (maybe_ne (MEM_OFFSET (mem), 0))
15299 0 : loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
15300 :
15301 : return loc_result;
15302 : }
15303 :
15304 : /* Output debug info about reason why we failed to expand expression as dwarf
15305 : expression. */
15306 :
15307 : static void
15308 2259192 : expansion_failed (tree expr, rtx rtl, char const *reason)
15309 : {
15310 2259192 : if (dump_file && (dump_flags & TDF_DETAILS))
15311 : {
15312 0 : fprintf (dump_file, "Failed to expand as dwarf: ");
15313 0 : if (expr)
15314 0 : print_generic_expr (dump_file, expr, dump_flags);
15315 0 : if (rtl)
15316 : {
15317 0 : fprintf (dump_file, "\n");
15318 0 : print_rtl (dump_file, rtl);
15319 : }
15320 0 : fprintf (dump_file, "\nReason: %s\n", reason);
15321 : }
15322 2259192 : }
15323 :
15324 : /* Helper function for const_ok_for_output. */
15325 :
15326 : static bool
15327 1872633 : const_ok_for_output_1 (rtx rtl)
15328 : {
15329 1872633 : if (targetm.const_not_ok_for_debug_p (rtl))
15330 : {
15331 20 : if (GET_CODE (rtl) != UNSPEC)
15332 : {
15333 0 : expansion_failed (NULL_TREE, rtl,
15334 : "Expression rejected for debug by the backend.\n");
15335 0 : return false;
15336 : }
15337 :
15338 : /* If delegitimize_address couldn't do anything with the UNSPEC, and
15339 : the target hook doesn't explicitly allow it in debug info, assume
15340 : we can't express it in the debug info. */
15341 : /* Don't complain about TLS UNSPECs, those are just too hard to
15342 : delegitimize. Note this could be a non-decl SYMBOL_REF such as
15343 : one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
15344 : rather than DECL_THREAD_LOCAL_P is not just an optimization. */
15345 20 : if (flag_checking
15346 20 : && (XVECLEN (rtl, 0) == 0
15347 20 : || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
15348 20 : || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl, 0, 0)) == TLS_MODEL_NONE))
15349 0 : inform (current_function_decl
15350 0 : ? DECL_SOURCE_LOCATION (current_function_decl)
15351 : : UNKNOWN_LOCATION,
15352 : #if NUM_UNSPEC_VALUES > 0
15353 : "non-delegitimized UNSPEC %s (%d) found in variable location",
15354 0 : ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
15355 : ? unspec_strings[XINT (rtl, 1)] : "unknown"),
15356 : #else
15357 : "non-delegitimized UNSPEC %d found in variable location",
15358 : #endif
15359 : XINT (rtl, 1));
15360 20 : expansion_failed (NULL_TREE, rtl,
15361 : "UNSPEC hasn't been delegitimized.\n");
15362 20 : return false;
15363 : }
15364 :
15365 1872613 : if (CONST_POLY_INT_P (rtl))
15366 : return false;
15367 :
15368 : /* FIXME: Refer to PR60655. It is possible for simplification
15369 : of rtl expressions in var tracking to produce such expressions.
15370 : We should really identify / validate expressions
15371 : enclosed in CONST that can be handled by assemblers on various
15372 : targets and only handle legitimate cases here. */
15373 1872613 : switch (GET_CODE (rtl))
15374 : {
15375 1606938 : case SYMBOL_REF:
15376 1606938 : break;
15377 : case NOT:
15378 : case NEG:
15379 : return false;
15380 142053 : case PLUS:
15381 142053 : {
15382 : /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
15383 : operands. */
15384 142053 : subrtx_var_iterator::array_type array;
15385 142053 : bool first = false;
15386 142053 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
15387 142053 : if (SYMBOL_REF_P (*iter)
15388 : || LABEL_P (*iter)
15389 : || GET_CODE (*iter) == UNSPEC)
15390 : {
15391 : first = true;
15392 : break;
15393 : }
15394 142053 : if (!first)
15395 : return true;
15396 284106 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
15397 142053 : if (SYMBOL_REF_P (*iter)
15398 : || LABEL_P (*iter)
15399 : || GET_CODE (*iter) == UNSPEC)
15400 0 : return false;
15401 142053 : return true;
15402 142053 : }
15403 0 : case MINUS:
15404 0 : {
15405 : /* Disallow negation of SYMBOL_REFs or UNSPECs when they
15406 : appear in the second operand of MINUS. */
15407 0 : subrtx_var_iterator::array_type array;
15408 0 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
15409 0 : if (SYMBOL_REF_P (*iter)
15410 : || LABEL_P (*iter)
15411 : || GET_CODE (*iter) == UNSPEC)
15412 0 : return false;
15413 0 : return true;
15414 0 : }
15415 : default:
15416 : return true;
15417 : }
15418 :
15419 1606938 : if (CONSTANT_POOL_ADDRESS_P (rtl))
15420 : {
15421 0 : bool marked;
15422 0 : get_pool_constant_mark (rtl, &marked);
15423 : /* If all references to this pool constant were optimized away,
15424 : it was not output and thus we can't represent it. */
15425 0 : if (!marked)
15426 : {
15427 0 : expansion_failed (NULL_TREE, rtl,
15428 : "Constant was removed from constant pool.\n");
15429 0 : return false;
15430 : }
15431 : }
15432 :
15433 1606938 : if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
15434 : return false;
15435 :
15436 : /* Avoid references to external symbols in debug info, on several targets
15437 : the linker might even refuse to link when linking a shared library,
15438 : and in many other cases the relocations for .debug_info/.debug_loc are
15439 : dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
15440 : to be defined within the same shared library or executable are fine. */
15441 1599223 : if (SYMBOL_REF_EXTERNAL_P (rtl))
15442 : {
15443 127353 : tree decl = SYMBOL_REF_DECL (rtl);
15444 :
15445 127353 : if (decl == NULL || !targetm.binds_local_p (decl))
15446 : {
15447 121157 : expansion_failed (NULL_TREE, rtl,
15448 : "Symbol not defined in current TU.\n");
15449 121157 : return false;
15450 : }
15451 : }
15452 :
15453 : return true;
15454 : }
15455 :
15456 : /* Return true if constant RTL can be emitted in DW_OP_addr or
15457 : DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
15458 : non-marked constant pool SYMBOL_REFs can't be referenced in it. */
15459 :
15460 : static bool
15461 1611764 : const_ok_for_output (rtx rtl)
15462 : {
15463 1611764 : if (GET_CODE (rtl) == SYMBOL_REF)
15464 1464272 : return const_ok_for_output_1 (rtl);
15465 :
15466 147492 : if (GET_CODE (rtl) == CONST)
15467 : {
15468 142676 : subrtx_var_iterator::array_type array;
15469 530930 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
15470 408351 : if (!const_ok_for_output_1 (*iter))
15471 20097 : return false;
15472 122579 : return true;
15473 142676 : }
15474 :
15475 : return true;
15476 : }
15477 :
15478 : /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
15479 : if possible, NULL otherwise. */
15480 :
15481 : static dw_die_ref
15482 365664 : base_type_for_mode (machine_mode mode, bool unsignedp)
15483 : {
15484 365664 : dw_die_ref type_die;
15485 365664 : tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
15486 :
15487 365664 : if (type == NULL)
15488 : return NULL;
15489 364490 : switch (TREE_CODE (type))
15490 : {
15491 355007 : case INTEGER_TYPE:
15492 355007 : case REAL_TYPE:
15493 355007 : break;
15494 : default:
15495 : return NULL;
15496 : }
15497 355007 : type_die = lookup_type_die (type);
15498 355007 : if (!type_die)
15499 385 : type_die = modified_type_die (type, TYPE_UNQUALIFIED, NULL_TREE,
15500 : false, comp_unit_die ());
15501 355007 : if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
15502 0 : return NULL;
15503 : return type_die;
15504 : }
15505 :
15506 : /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
15507 : type matching MODE, or, if MODE is narrower than or as wide as
15508 : DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
15509 : possible. */
15510 :
15511 : static dw_loc_descr_ref
15512 5418 : convert_descriptor_to_mode (scalar_int_mode mode, dw_loc_descr_ref op)
15513 : {
15514 5418 : machine_mode outer_mode = mode;
15515 5418 : dw_die_ref type_die;
15516 5418 : dw_loc_descr_ref cvt;
15517 :
15518 12206 : if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
15519 : {
15520 5141 : add_loc_descr (&op, new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0));
15521 5141 : return op;
15522 : }
15523 277 : type_die = base_type_for_mode (outer_mode, 1);
15524 277 : if (type_die == NULL)
15525 : return NULL;
15526 277 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15527 277 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15528 277 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15529 277 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15530 277 : add_loc_descr (&op, cvt);
15531 277 : return op;
15532 : }
15533 :
15534 : /* Return location descriptor for comparison OP with operands OP0 and OP1. */
15535 :
15536 : static dw_loc_descr_ref
15537 122014 : compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
15538 : dw_loc_descr_ref op1)
15539 : {
15540 122014 : dw_loc_descr_ref ret = op0;
15541 122014 : add_loc_descr (&ret, op1);
15542 122014 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
15543 122014 : if (STORE_FLAG_VALUE != 1)
15544 : {
15545 : add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
15546 : add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
15547 : }
15548 122014 : return ret;
15549 : }
15550 :
15551 : /* Subroutine of scompare_loc_descriptor for the case in which we're
15552 : comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15553 : and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
15554 :
15555 : static dw_loc_descr_ref
15556 1013 : scompare_loc_descriptor_wide (enum dwarf_location_atom op,
15557 : scalar_int_mode op_mode,
15558 : dw_loc_descr_ref op0, dw_loc_descr_ref op1)
15559 : {
15560 1013 : dw_die_ref type_die = base_type_for_mode (op_mode, 0);
15561 1013 : dw_loc_descr_ref cvt;
15562 :
15563 1013 : if (type_die == NULL)
15564 : return NULL;
15565 1013 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15566 1013 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15567 1013 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15568 1013 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15569 1013 : add_loc_descr (&op0, cvt);
15570 1013 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15571 1013 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15572 1013 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15573 1013 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15574 1013 : add_loc_descr (&op1, cvt);
15575 1013 : return compare_loc_descriptor (op, op0, op1);
15576 : }
15577 :
15578 : /* Subroutine of scompare_loc_descriptor for the case in which we're
15579 : comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15580 : and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
15581 :
15582 : static dw_loc_descr_ref
15583 37379 : scompare_loc_descriptor_narrow (enum dwarf_location_atom op, rtx rtl,
15584 : scalar_int_mode op_mode,
15585 : dw_loc_descr_ref op0, dw_loc_descr_ref op1)
15586 : {
15587 37379 : int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
15588 : /* For eq/ne, if the operands are known to be zero-extended,
15589 : there is no need to do the fancy shifting up. */
15590 37379 : if (op == DW_OP_eq || op == DW_OP_ne)
15591 : {
15592 34380 : dw_loc_descr_ref last0, last1;
15593 97208 : for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
15594 : ;
15595 43730 : for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
15596 : ;
15597 : /* deref_size zero extends, and for constants we can check
15598 : whether they are zero extended or not. */
15599 34380 : if (((last0->dw_loc_opc == DW_OP_deref_size
15600 12124 : && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
15601 28318 : || (CONST_INT_P (XEXP (rtl, 0))
15602 361 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
15603 361 : == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
15604 40704 : && ((last1->dw_loc_opc == DW_OP_deref_size
15605 1258 : && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
15606 5695 : || (CONST_INT_P (XEXP (rtl, 1))
15607 5247 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
15608 5247 : == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
15609 5793 : return compare_loc_descriptor (op, op0, op1);
15610 :
15611 : /* EQ/NE comparison against constant in narrower type than
15612 : DWARF2_ADDR_SIZE can be performed either as
15613 : DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
15614 : DW_OP_{eq,ne}
15615 : or
15616 : DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
15617 : DW_OP_{eq,ne}. Pick whatever is shorter. */
15618 28587 : if (CONST_INT_P (XEXP (rtl, 1))
15619 25664 : && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
15620 54251 : && (size_of_int_loc_descriptor (shift) + 1
15621 25664 : + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift)
15622 25664 : >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
15623 25664 : + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
15624 25664 : & GET_MODE_MASK (op_mode))))
15625 : {
15626 10667 : add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
15627 10667 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15628 21334 : op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
15629 10667 : & GET_MODE_MASK (op_mode));
15630 10667 : return compare_loc_descriptor (op, op0, op1);
15631 : }
15632 : }
15633 20919 : add_loc_descr (&op0, int_loc_descriptor (shift));
15634 20919 : add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
15635 20919 : if (CONST_INT_P (XEXP (rtl, 1)))
15636 17250 : op1 = int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift);
15637 : else
15638 : {
15639 3669 : add_loc_descr (&op1, int_loc_descriptor (shift));
15640 7338 : add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
15641 : }
15642 20919 : return compare_loc_descriptor (op, op0, op1);
15643 : }
15644 :
15645 : /* Return location descriptor for signed comparison OP RTL. */
15646 :
15647 : static dw_loc_descr_ref
15648 98722 : scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
15649 : machine_mode mem_mode)
15650 : {
15651 98722 : machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
15652 98722 : dw_loc_descr_ref op0, op1;
15653 :
15654 98722 : if (op_mode == VOIDmode)
15655 450 : op_mode = GET_MODE (XEXP (rtl, 1));
15656 98722 : if (op_mode == VOIDmode)
15657 : return NULL;
15658 :
15659 98722 : scalar_int_mode int_op_mode;
15660 98722 : if (dwarf_strict
15661 0 : && dwarf_version < 5
15662 105836 : && (!is_a <scalar_int_mode> (op_mode, &int_op_mode)
15663 0 : || GET_MODE_SIZE (int_op_mode) > DWARF2_ADDR_SIZE))
15664 : return NULL;
15665 :
15666 98722 : op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
15667 : VAR_INIT_STATUS_INITIALIZED);
15668 98722 : op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
15669 : VAR_INIT_STATUS_INITIALIZED);
15670 :
15671 98722 : if (op0 == NULL || op1 == NULL)
15672 : return NULL;
15673 :
15674 91608 : if (is_a <scalar_int_mode> (op_mode, &int_op_mode))
15675 : {
15676 193935 : if (GET_MODE_SIZE (int_op_mode) < DWARF2_ADDR_SIZE)
15677 37379 : return scompare_loc_descriptor_narrow (op, rtl, int_op_mode, op0, op1);
15678 :
15679 116362 : if (GET_MODE_SIZE (int_op_mode) > DWARF2_ADDR_SIZE)
15680 1013 : return scompare_loc_descriptor_wide (op, int_op_mode, op0, op1);
15681 : }
15682 53216 : return compare_loc_descriptor (op, op0, op1);
15683 : }
15684 :
15685 : /* Return location descriptor for unsigned comparison OP RTL. */
15686 :
15687 : static dw_loc_descr_ref
15688 32216 : ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
15689 : machine_mode mem_mode)
15690 : {
15691 32216 : dw_loc_descr_ref op0, op1;
15692 :
15693 32216 : machine_mode test_op_mode = GET_MODE (XEXP (rtl, 0));
15694 32216 : if (test_op_mode == VOIDmode)
15695 68 : test_op_mode = GET_MODE (XEXP (rtl, 1));
15696 :
15697 32216 : scalar_int_mode op_mode;
15698 32401 : if (!is_a <scalar_int_mode> (test_op_mode, &op_mode))
15699 : return NULL;
15700 :
15701 30591 : if (dwarf_strict
15702 0 : && dwarf_version < 5
15703 30591 : && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
15704 : return NULL;
15705 :
15706 30591 : op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
15707 : VAR_INIT_STATUS_INITIALIZED);
15708 30591 : op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
15709 : VAR_INIT_STATUS_INITIALIZED);
15710 :
15711 30591 : if (op0 == NULL || op1 == NULL)
15712 : return NULL;
15713 :
15714 65666 : if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
15715 : {
15716 9840 : HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
15717 9840 : dw_loc_descr_ref last0, last1;
15718 19542 : for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
15719 : ;
15720 10115 : for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
15721 : ;
15722 9840 : if (CONST_INT_P (XEXP (rtl, 0)))
15723 0 : op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
15724 : /* deref_size zero extends, so no need to mask it again. */
15725 9840 : else if (last0->dw_loc_opc != DW_OP_deref_size
15726 12966 : || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
15727 : {
15728 6714 : add_loc_descr (&op0, int_loc_descriptor (mask));
15729 13428 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15730 : }
15731 9840 : if (CONST_INT_P (XEXP (rtl, 1)))
15732 9646 : op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
15733 : /* deref_size zero extends, so no need to mask it again. */
15734 194 : else if (last1->dw_loc_opc != DW_OP_deref_size
15735 251 : || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
15736 : {
15737 137 : add_loc_descr (&op1, int_loc_descriptor (mask));
15738 274 : add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
15739 : }
15740 : }
15741 45829 : else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
15742 : {
15743 20083 : HOST_WIDE_INT bias = 1;
15744 20083 : bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
15745 20083 : add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15746 20083 : if (CONST_INT_P (XEXP (rtl, 1)))
15747 7373 : op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
15748 7373 : + INTVAL (XEXP (rtl, 1)));
15749 : else
15750 25420 : add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
15751 : bias, 0));
15752 : }
15753 30406 : return compare_loc_descriptor (op, op0, op1);
15754 : }
15755 :
15756 : /* Return location descriptor for {U,S}{MIN,MAX}. */
15757 :
15758 : static dw_loc_descr_ref
15759 146699 : minmax_loc_descriptor (rtx rtl, machine_mode mode,
15760 : machine_mode mem_mode)
15761 : {
15762 146699 : enum dwarf_location_atom op;
15763 146699 : dw_loc_descr_ref op0, op1, ret;
15764 146699 : dw_loc_descr_ref bra_node, drop_node;
15765 :
15766 146699 : scalar_int_mode int_mode;
15767 146699 : if (dwarf_strict
15768 0 : && dwarf_version < 5
15769 146836 : && (!is_a <scalar_int_mode> (mode, &int_mode)
15770 0 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE))
15771 : return NULL;
15772 :
15773 146699 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15774 : VAR_INIT_STATUS_INITIALIZED);
15775 146699 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15776 : VAR_INIT_STATUS_INITIALIZED);
15777 :
15778 146699 : if (op0 == NULL || op1 == NULL)
15779 : return NULL;
15780 :
15781 146562 : add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
15782 146562 : add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
15783 146562 : add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
15784 146562 : if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
15785 : {
15786 : /* Checked by the caller. */
15787 128778 : int_mode = as_a <scalar_int_mode> (mode);
15788 258776 : if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
15789 : {
15790 382 : HOST_WIDE_INT mask = GET_MODE_MASK (int_mode);
15791 382 : add_loc_descr (&op0, int_loc_descriptor (mask));
15792 382 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15793 382 : add_loc_descr (&op1, int_loc_descriptor (mask));
15794 764 : add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
15795 : }
15796 257950 : else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
15797 : {
15798 128391 : HOST_WIDE_INT bias = 1;
15799 128391 : bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
15800 128391 : add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15801 256782 : add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15802 : }
15803 : }
15804 17784 : else if (is_a <scalar_int_mode> (mode, &int_mode)
15805 26403 : && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
15806 : {
15807 1113 : int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (int_mode)) * BITS_PER_UNIT;
15808 1113 : add_loc_descr (&op0, int_loc_descriptor (shift));
15809 1113 : add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
15810 1113 : add_loc_descr (&op1, int_loc_descriptor (shift));
15811 2226 : add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
15812 : }
15813 16671 : else if (is_a <scalar_int_mode> (mode, &int_mode)
15814 25290 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
15815 : {
15816 47 : dw_die_ref type_die = base_type_for_mode (int_mode, 0);
15817 47 : dw_loc_descr_ref cvt;
15818 47 : if (type_die == NULL)
15819 : return NULL;
15820 47 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15821 47 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15822 47 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15823 47 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15824 47 : add_loc_descr (&op0, cvt);
15825 47 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15826 47 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15827 47 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15828 47 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15829 94 : add_loc_descr (&op1, cvt);
15830 : }
15831 :
15832 146562 : if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
15833 : op = DW_OP_lt;
15834 : else
15835 146562 : op = DW_OP_gt;
15836 146562 : ret = op0;
15837 146562 : add_loc_descr (&ret, op1);
15838 146562 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
15839 146562 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15840 146562 : add_loc_descr (&ret, bra_node);
15841 146562 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15842 146562 : drop_node = new_loc_descr (DW_OP_drop, 0, 0);
15843 146562 : add_loc_descr (&ret, drop_node);
15844 146562 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15845 146562 : bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
15846 146562 : if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
15847 17784 : && is_a <scalar_int_mode> (mode, &int_mode)
15848 172965 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
15849 47 : ret = convert_descriptor_to_mode (int_mode, ret);
15850 146562 : return ret;
15851 : }
15852 :
15853 : /* Helper function for mem_loc_descriptor. Perform OP binary op,
15854 : but after converting arguments to type_die, afterwards
15855 : convert back to unsigned. */
15856 :
15857 : static dw_loc_descr_ref
15858 3837 : typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
15859 : scalar_int_mode mode, machine_mode mem_mode)
15860 : {
15861 3837 : dw_loc_descr_ref cvt, op0, op1;
15862 :
15863 3837 : if (type_die == NULL)
15864 : return NULL;
15865 3837 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15866 : VAR_INIT_STATUS_INITIALIZED);
15867 3837 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15868 : VAR_INIT_STATUS_INITIALIZED);
15869 3837 : if (op0 == NULL || op1 == NULL)
15870 : return NULL;
15871 3782 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15872 3782 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15873 3782 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15874 3782 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15875 3782 : add_loc_descr (&op0, cvt);
15876 3782 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15877 3782 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15878 3782 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15879 3782 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15880 3782 : add_loc_descr (&op1, cvt);
15881 3782 : add_loc_descr (&op0, op1);
15882 3782 : add_loc_descr (&op0, new_loc_descr (op, 0, 0));
15883 3782 : return convert_descriptor_to_mode (mode, op0);
15884 : }
15885 :
15886 : /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
15887 : const0 is DW_OP_lit0 or corresponding typed constant,
15888 : const1 is DW_OP_lit1 or corresponding typed constant
15889 : and constMSB is constant with just the MSB bit set
15890 : for the mode):
15891 : DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15892 : L1: const0 DW_OP_swap
15893 : L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
15894 : DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15895 : L3: DW_OP_drop
15896 : L4: DW_OP_nop
15897 :
15898 : CTZ is similar:
15899 : DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15900 : L1: const0 DW_OP_swap
15901 : L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15902 : DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15903 : L3: DW_OP_drop
15904 : L4: DW_OP_nop
15905 :
15906 : FFS is similar:
15907 : DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
15908 : L1: const1 DW_OP_swap
15909 : L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15910 : DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15911 : L3: DW_OP_drop
15912 : L4: DW_OP_nop */
15913 :
15914 : static dw_loc_descr_ref
15915 5254 : clz_loc_descriptor (rtx rtl, scalar_int_mode mode,
15916 : machine_mode mem_mode)
15917 : {
15918 5254 : dw_loc_descr_ref op0, ret, tmp;
15919 5254 : HOST_WIDE_INT valv;
15920 5254 : dw_loc_descr_ref l1jump, l1label;
15921 5254 : dw_loc_descr_ref l2jump, l2label;
15922 5254 : dw_loc_descr_ref l3jump, l3label;
15923 5254 : dw_loc_descr_ref l4jump, l4label;
15924 5254 : rtx msb;
15925 :
15926 5254 : if (GET_MODE (XEXP (rtl, 0)) != mode)
15927 : return NULL;
15928 :
15929 5254 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15930 : VAR_INIT_STATUS_INITIALIZED);
15931 5254 : if (op0 == NULL)
15932 : return NULL;
15933 5245 : ret = op0;
15934 5245 : if (GET_CODE (rtl) == CLZ)
15935 : {
15936 9612 : if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
15937 9612 : valv = GET_MODE_BITSIZE (mode);
15938 : }
15939 439 : else if (GET_CODE (rtl) == FFS)
15940 : valv = 0;
15941 878 : else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
15942 878 : valv = GET_MODE_BITSIZE (mode);
15943 5245 : add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
15944 5245 : l1jump = new_loc_descr (DW_OP_bra, 0, 0);
15945 5245 : add_loc_descr (&ret, l1jump);
15946 5245 : add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
15947 5245 : tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
15948 : VAR_INIT_STATUS_INITIALIZED);
15949 5245 : if (tmp == NULL)
15950 : return NULL;
15951 5245 : add_loc_descr (&ret, tmp);
15952 5245 : l4jump = new_loc_descr (DW_OP_skip, 0, 0);
15953 5245 : add_loc_descr (&ret, l4jump);
15954 5245 : l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
15955 : ? const1_rtx : const0_rtx,
15956 : mode, mem_mode,
15957 : VAR_INIT_STATUS_INITIALIZED);
15958 5245 : if (l1label == NULL)
15959 : return NULL;
15960 5245 : add_loc_descr (&ret, l1label);
15961 5245 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15962 5245 : l2label = new_loc_descr (DW_OP_dup, 0, 0);
15963 5245 : add_loc_descr (&ret, l2label);
15964 5245 : if (GET_CODE (rtl) != CLZ)
15965 439 : msb = const1_rtx;
15966 9612 : else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
15967 9612 : msb = GEN_INT (HOST_WIDE_INT_1U
15968 : << (GET_MODE_BITSIZE (mode) - 1));
15969 : else
15970 0 : msb = immed_wide_int_const
15971 0 : (wi::set_bit_in_zero (GET_MODE_PRECISION (mode) - 1,
15972 0 : GET_MODE_PRECISION (mode)), mode);
15973 5245 : if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
15974 2046 : tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
15975 : ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
15976 : ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
15977 : else
15978 3199 : tmp = mem_loc_descriptor (msb, mode, mem_mode,
15979 : VAR_INIT_STATUS_INITIALIZED);
15980 5245 : if (tmp == NULL)
15981 : return NULL;
15982 5245 : add_loc_descr (&ret, tmp);
15983 5245 : add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
15984 5245 : l3jump = new_loc_descr (DW_OP_bra, 0, 0);
15985 5245 : add_loc_descr (&ret, l3jump);
15986 5245 : tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
15987 : VAR_INIT_STATUS_INITIALIZED);
15988 5245 : if (tmp == NULL)
15989 : return NULL;
15990 5245 : add_loc_descr (&ret, tmp);
15991 5684 : add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
15992 : ? DW_OP_shl : DW_OP_shr, 0, 0));
15993 5245 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15994 5245 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
15995 5245 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15996 5245 : l2jump = new_loc_descr (DW_OP_skip, 0, 0);
15997 5245 : add_loc_descr (&ret, l2jump);
15998 5245 : l3label = new_loc_descr (DW_OP_drop, 0, 0);
15999 5245 : add_loc_descr (&ret, l3label);
16000 5245 : l4label = new_loc_descr (DW_OP_nop, 0, 0);
16001 5245 : add_loc_descr (&ret, l4label);
16002 5245 : l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16003 5245 : l1jump->dw_loc_oprnd1.v.val_loc = l1label;
16004 5245 : l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16005 5245 : l2jump->dw_loc_oprnd1.v.val_loc = l2label;
16006 5245 : l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16007 5245 : l3jump->dw_loc_oprnd1.v.val_loc = l3label;
16008 5245 : l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16009 5245 : l4jump->dw_loc_oprnd1.v.val_loc = l4label;
16010 5245 : return ret;
16011 : }
16012 :
16013 : /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
16014 : const1 is DW_OP_lit1 or corresponding typed constant):
16015 : const0 DW_OP_swap
16016 : L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
16017 : DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
16018 : L2: DW_OP_drop
16019 :
16020 : PARITY is similar:
16021 : L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
16022 : DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
16023 : L2: DW_OP_drop */
16024 :
16025 : static dw_loc_descr_ref
16026 0 : popcount_loc_descriptor (rtx rtl, scalar_int_mode mode,
16027 : machine_mode mem_mode)
16028 : {
16029 0 : dw_loc_descr_ref op0, ret, tmp;
16030 0 : dw_loc_descr_ref l1jump, l1label;
16031 0 : dw_loc_descr_ref l2jump, l2label;
16032 :
16033 0 : if (GET_MODE (XEXP (rtl, 0)) != mode)
16034 : return NULL;
16035 :
16036 0 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16037 : VAR_INIT_STATUS_INITIALIZED);
16038 0 : if (op0 == NULL)
16039 : return NULL;
16040 0 : ret = op0;
16041 0 : tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
16042 : VAR_INIT_STATUS_INITIALIZED);
16043 0 : if (tmp == NULL)
16044 : return NULL;
16045 0 : add_loc_descr (&ret, tmp);
16046 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
16047 0 : l1label = new_loc_descr (DW_OP_dup, 0, 0);
16048 0 : add_loc_descr (&ret, l1label);
16049 0 : l2jump = new_loc_descr (DW_OP_bra, 0, 0);
16050 0 : add_loc_descr (&ret, l2jump);
16051 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
16052 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
16053 0 : tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
16054 : VAR_INIT_STATUS_INITIALIZED);
16055 0 : if (tmp == NULL)
16056 : return NULL;
16057 0 : add_loc_descr (&ret, tmp);
16058 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
16059 0 : add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
16060 : ? DW_OP_plus : DW_OP_xor, 0, 0));
16061 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
16062 0 : tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
16063 : VAR_INIT_STATUS_INITIALIZED);
16064 0 : add_loc_descr (&ret, tmp);
16065 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
16066 0 : l1jump = new_loc_descr (DW_OP_skip, 0, 0);
16067 0 : add_loc_descr (&ret, l1jump);
16068 0 : l2label = new_loc_descr (DW_OP_drop, 0, 0);
16069 0 : add_loc_descr (&ret, l2label);
16070 0 : l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16071 0 : l1jump->dw_loc_oprnd1.v.val_loc = l1label;
16072 0 : l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16073 0 : l2jump->dw_loc_oprnd1.v.val_loc = l2label;
16074 0 : return ret;
16075 : }
16076 :
16077 : /* BSWAP (constS is initial shift count, either 56 or 24):
16078 : constS const0
16079 : L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
16080 : const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
16081 : DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
16082 : DW_OP_minus DW_OP_swap DW_OP_skip <L1>
16083 : L2: DW_OP_drop DW_OP_swap DW_OP_drop */
16084 :
16085 : static dw_loc_descr_ref
16086 164 : bswap_loc_descriptor (rtx rtl, scalar_int_mode mode,
16087 : machine_mode mem_mode)
16088 : {
16089 164 : dw_loc_descr_ref op0, ret, tmp;
16090 164 : dw_loc_descr_ref l1jump, l1label;
16091 164 : dw_loc_descr_ref l2jump, l2label;
16092 :
16093 164 : if (BITS_PER_UNIT != 8
16094 133 : || (GET_MODE_BITSIZE (mode) != 32
16095 297 : && GET_MODE_BITSIZE (mode) != 64))
16096 : return NULL;
16097 :
16098 72 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16099 : VAR_INIT_STATUS_INITIALIZED);
16100 72 : if (op0 == NULL)
16101 : return NULL;
16102 :
16103 72 : ret = op0;
16104 144 : tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
16105 : mode, mem_mode,
16106 : VAR_INIT_STATUS_INITIALIZED);
16107 72 : if (tmp == NULL)
16108 : return NULL;
16109 72 : add_loc_descr (&ret, tmp);
16110 72 : tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
16111 : VAR_INIT_STATUS_INITIALIZED);
16112 72 : if (tmp == NULL)
16113 : return NULL;
16114 72 : add_loc_descr (&ret, tmp);
16115 72 : l1label = new_loc_descr (DW_OP_pick, 2, 0);
16116 72 : add_loc_descr (&ret, l1label);
16117 144 : tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
16118 : mode, mem_mode,
16119 : VAR_INIT_STATUS_INITIALIZED);
16120 72 : add_loc_descr (&ret, tmp);
16121 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
16122 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
16123 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
16124 72 : tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
16125 : VAR_INIT_STATUS_INITIALIZED);
16126 72 : if (tmp == NULL)
16127 : return NULL;
16128 72 : add_loc_descr (&ret, tmp);
16129 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
16130 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
16131 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
16132 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
16133 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
16134 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
16135 72 : tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
16136 : VAR_INIT_STATUS_INITIALIZED);
16137 72 : add_loc_descr (&ret, tmp);
16138 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
16139 72 : l2jump = new_loc_descr (DW_OP_bra, 0, 0);
16140 72 : add_loc_descr (&ret, l2jump);
16141 72 : tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
16142 : VAR_INIT_STATUS_INITIALIZED);
16143 72 : add_loc_descr (&ret, tmp);
16144 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
16145 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
16146 72 : l1jump = new_loc_descr (DW_OP_skip, 0, 0);
16147 72 : add_loc_descr (&ret, l1jump);
16148 72 : l2label = new_loc_descr (DW_OP_drop, 0, 0);
16149 72 : add_loc_descr (&ret, l2label);
16150 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
16151 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
16152 72 : l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16153 72 : l1jump->dw_loc_oprnd1.v.val_loc = l1label;
16154 72 : l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16155 72 : l2jump->dw_loc_oprnd1.v.val_loc = l2label;
16156 72 : return ret;
16157 : }
16158 :
16159 : /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
16160 : DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
16161 : [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
16162 : DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
16163 :
16164 : ROTATERT is similar:
16165 : DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
16166 : DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
16167 : [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
16168 :
16169 : static dw_loc_descr_ref
16170 3697 : rotate_loc_descriptor (rtx rtl, scalar_int_mode mode,
16171 : machine_mode mem_mode)
16172 : {
16173 3697 : rtx rtlop1 = XEXP (rtl, 1);
16174 3697 : dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
16175 3697 : int i;
16176 :
16177 3697 : if (is_narrower_int_mode (GET_MODE (rtlop1), mode))
16178 58 : rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
16179 3697 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16180 : VAR_INIT_STATUS_INITIALIZED);
16181 3697 : op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
16182 : VAR_INIT_STATUS_INITIALIZED);
16183 3697 : if (op0 == NULL || op1 == NULL)
16184 : return NULL;
16185 8407 : if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
16186 3306 : for (i = 0; i < 2; i++)
16187 : {
16188 4408 : if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
16189 2204 : mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
16190 : mode, mem_mode,
16191 : VAR_INIT_STATUS_INITIALIZED);
16192 0 : else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
16193 0 : mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
16194 : ? DW_OP_const4u
16195 : : HOST_BITS_PER_WIDE_INT == 64
16196 : ? DW_OP_const8u : DW_OP_constu,
16197 0 : GET_MODE_MASK (mode), 0);
16198 : else
16199 0 : mask[i] = NULL;
16200 2204 : if (mask[i] == NULL)
16201 : return NULL;
16202 4408 : add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
16203 : }
16204 3694 : ret = op0;
16205 3694 : add_loc_descr (&ret, op1);
16206 3694 : add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
16207 3694 : add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
16208 3694 : if (GET_CODE (rtl) == ROTATERT)
16209 : {
16210 194 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
16211 582 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
16212 194 : GET_MODE_BITSIZE (mode), 0));
16213 : }
16214 3694 : add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
16215 3694 : if (mask[0] != NULL)
16216 2204 : add_loc_descr (&ret, mask[0]);
16217 3694 : add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
16218 3694 : if (mask[1] != NULL)
16219 : {
16220 1102 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
16221 1102 : add_loc_descr (&ret, mask[1]);
16222 2204 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
16223 : }
16224 3694 : if (GET_CODE (rtl) == ROTATE)
16225 : {
16226 3500 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
16227 10500 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
16228 3500 : GET_MODE_BITSIZE (mode), 0));
16229 : }
16230 3694 : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
16231 3694 : add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
16232 3694 : return ret;
16233 : }
16234 :
16235 : /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
16236 : for DEBUG_PARAMETER_REF RTL. */
16237 :
16238 : static dw_loc_descr_ref
16239 29873 : parameter_ref_descriptor (rtx rtl)
16240 : {
16241 29873 : dw_loc_descr_ref ret;
16242 29873 : dw_die_ref ref;
16243 :
16244 29873 : if (dwarf_strict)
16245 : return NULL;
16246 29873 : gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
16247 : /* With LTO during LTRANS we get the late DIE that refers to the early
16248 : DIE, thus we add another indirection here. This seems to confuse
16249 : gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
16250 29873 : ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
16251 29873 : ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
16252 29873 : if (ref)
16253 : {
16254 29873 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16255 29873 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
16256 29873 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
16257 : }
16258 : else
16259 : {
16260 0 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
16261 0 : ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
16262 : }
16263 : return ret;
16264 : }
16265 :
16266 : /* The following routine converts the RTL for a variable or parameter
16267 : (resident in memory) into an equivalent Dwarf representation of a
16268 : mechanism for getting the address of that same variable onto the top of a
16269 : hypothetical "address evaluation" stack.
16270 :
16271 : When creating memory location descriptors, we are effectively transforming
16272 : the RTL for a memory-resident object into its Dwarf postfix expression
16273 : equivalent. This routine recursively descends an RTL tree, turning
16274 : it into Dwarf postfix code as it goes.
16275 :
16276 : MODE is the mode that should be assumed for the rtl if it is VOIDmode.
16277 :
16278 : MEM_MODE is the mode of the memory reference, needed to handle some
16279 : autoincrement addressing modes.
16280 :
16281 : Return 0 if we can't represent the location. */
16282 :
16283 : dw_loc_descr_ref
16284 23888674 : mem_loc_descriptor (rtx rtl, machine_mode mode,
16285 : machine_mode mem_mode,
16286 : enum var_init_status initialized)
16287 : {
16288 23888674 : dw_loc_descr_ref mem_loc_result = NULL;
16289 23888674 : enum dwarf_location_atom op;
16290 23888674 : dw_loc_descr_ref op0, op1;
16291 23888674 : rtx inner = NULL_RTX;
16292 :
16293 23888674 : if (mode == VOIDmode)
16294 859 : mode = GET_MODE (rtl);
16295 :
16296 : /* Note that for a dynamically sized array, the location we will generate a
16297 : description of here will be the lowest numbered location which is
16298 : actually within the array. That's *not* necessarily the same as the
16299 : zeroth element of the array. */
16300 :
16301 23888674 : rtl = targetm.delegitimize_address (rtl);
16302 :
16303 23888674 : if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
16304 : return NULL;
16305 :
16306 23888674 : scalar_int_mode int_mode = BImode, inner_mode, op1_mode;
16307 23888674 : switch (GET_CODE (rtl))
16308 : {
16309 0 : case POST_INC:
16310 0 : case POST_DEC:
16311 0 : case POST_MODIFY:
16312 0 : return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
16313 :
16314 226353 : case SUBREG:
16315 : /* The case of a subreg may arise when we have a local (register)
16316 : variable or a formal (register) parameter which doesn't quite fill
16317 : up an entire register. For now, just assume that it is
16318 : legitimate to make the Dwarf info refer to the whole register which
16319 : contains the given subreg. */
16320 226353 : if (!subreg_lowpart_p (rtl))
16321 : break;
16322 213203 : inner = SUBREG_REG (rtl);
16323 : /* FALLTHRU */
16324 213203 : case TRUNCATE:
16325 213203 : if (inner == NULL_RTX)
16326 5754 : inner = XEXP (rtl, 0);
16327 218957 : if (is_a <scalar_int_mode> (mode, &int_mode)
16328 218345 : && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
16329 239883 : && (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16330 : #ifdef POINTERS_EXTEND_UNSIGNED
16331 108 : || (int_mode == Pmode && mem_mode != VOIDmode)
16332 : #endif
16333 : )
16334 458732 : && GET_MODE_SIZE (inner_mode) <= DWARF2_ADDR_SIZE)
16335 : {
16336 186742 : mem_loc_result = mem_loc_descriptor (inner,
16337 : inner_mode,
16338 : mem_mode, initialized);
16339 186742 : break;
16340 : }
16341 32215 : if (dwarf_strict && dwarf_version < 5)
16342 : break;
16343 32215 : if (is_a <scalar_int_mode> (mode, &int_mode)
16344 31603 : && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
16345 92981 : ? GET_MODE_SIZE (int_mode) <= GET_MODE_SIZE (inner_mode)
16346 35879 : : known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
16347 : {
16348 32025 : dw_die_ref type_die;
16349 32025 : dw_loc_descr_ref cvt;
16350 :
16351 64050 : mem_loc_result = mem_loc_descriptor (inner,
16352 32025 : GET_MODE (inner),
16353 : mem_mode, initialized);
16354 32025 : if (mem_loc_result == NULL)
16355 : break;
16356 22557 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16357 22557 : if (type_die == NULL)
16358 : {
16359 2 : mem_loc_result = NULL;
16360 2 : break;
16361 : }
16362 67665 : if (maybe_ne (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
16363 20956 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16364 : else
16365 1599 : cvt = new_loc_descr (dwarf_OP (DW_OP_reinterpret), 0, 0);
16366 22555 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16367 22555 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16368 22555 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16369 22555 : add_loc_descr (&mem_loc_result, cvt);
16370 22555 : if (is_a <scalar_int_mode> (mode, &int_mode)
16371 65865 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
16372 : {
16373 : /* Convert it to untyped afterwards. */
16374 21728 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16375 21728 : add_loc_descr (&mem_loc_result, cvt);
16376 : }
16377 : }
16378 : break;
16379 :
16380 3191477 : case REG:
16381 3191477 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16382 6703744 : || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
16383 45185 : && rtl != arg_pointer_rtx
16384 45183 : && rtl != frame_pointer_rtx
16385 : #ifdef POINTERS_EXTEND_UNSIGNED
16386 88132 : && (int_mode != Pmode || mem_mode == VOIDmode)
16387 : #endif
16388 : ))
16389 : {
16390 117304 : dw_die_ref type_die;
16391 117304 : unsigned int debugger_regnum;
16392 :
16393 117304 : if (dwarf_strict && dwarf_version < 5)
16394 : break;
16395 117304 : if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
16396 : break;
16397 117304 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16398 117304 : if (type_die == NULL)
16399 : break;
16400 :
16401 109312 : debugger_regnum = debugger_reg_number (rtl);
16402 109312 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
16403 : break;
16404 109312 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_regval_type),
16405 : debugger_regnum, 0);
16406 109312 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
16407 109312 : mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
16408 109312 : mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
16409 109312 : break;
16410 : }
16411 : /* Whenever a register number forms a part of the description of the
16412 : method for calculating the (dynamic) address of a memory resident
16413 : object, DWARF rules require the register number be referred to as
16414 : a "base register". This distinction is not based in any way upon
16415 : what category of register the hardware believes the given register
16416 : belongs to. This is strictly DWARF terminology we're dealing with
16417 : here. Note that in cases where the location of a memory-resident
16418 : data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
16419 : OP_CONST (0)) the actual DWARF location descriptor that we generate
16420 : may just be OP_BASEREG (basereg). This may look deceptively like
16421 : the object in question was allocated to a register (rather than in
16422 : memory) so DWARF consumers need to be aware of the subtle
16423 : distinction between OP_REG and OP_BASEREG. */
16424 3074173 : if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
16425 3072289 : mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
16426 98 : else if (stack_realign_drap
16427 0 : && crtl->drap_reg
16428 0 : && crtl->args.internal_arg_pointer == rtl
16429 1884 : && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
16430 : {
16431 : /* If RTL is internal_arg_pointer, which has been optimized
16432 : out, use DRAP instead. */
16433 0 : mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
16434 : VAR_INIT_STATUS_INITIALIZED);
16435 : }
16436 : break;
16437 :
16438 258694 : case SIGN_EXTEND:
16439 258694 : case ZERO_EXTEND:
16440 258694 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16441 258694 : || !is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &inner_mode))
16442 : break;
16443 258694 : op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
16444 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
16445 258694 : if (op0 == 0)
16446 : break;
16447 254286 : else if (GET_CODE (rtl) == ZERO_EXTEND
16448 245348 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16449 178014 : && GET_MODE_BITSIZE (inner_mode) < HOST_BITS_PER_WIDE_INT
16450 : /* If DW_OP_const{1,2,4}u won't be used, it is shorter
16451 : to expand zero extend as two shifts instead of
16452 : masking. */
16453 459447 : && GET_MODE_SIZE (inner_mode) <= 4)
16454 : {
16455 178014 : mem_loc_result = op0;
16456 178014 : add_loc_descr (&mem_loc_result,
16457 178014 : int_loc_descriptor (GET_MODE_MASK (inner_mode)));
16458 178014 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
16459 : }
16460 184518 : else if (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
16461 : {
16462 44941 : int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (inner_mode);
16463 44941 : shift *= BITS_PER_UNIT;
16464 44941 : if (GET_CODE (rtl) == SIGN_EXTEND)
16465 : op = DW_OP_shra;
16466 : else
16467 0 : op = DW_OP_shr;
16468 44941 : mem_loc_result = op0;
16469 44941 : add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
16470 44941 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
16471 44941 : add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
16472 44941 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16473 : }
16474 31331 : else if (!dwarf_strict || dwarf_version >= 5)
16475 : {
16476 31331 : dw_die_ref type_die1, type_die2;
16477 31331 : dw_loc_descr_ref cvt;
16478 :
16479 31331 : type_die1 = base_type_for_mode (inner_mode,
16480 : GET_CODE (rtl) == ZERO_EXTEND);
16481 31331 : if (type_die1 == NULL)
16482 : break;
16483 31331 : type_die2 = base_type_for_mode (int_mode, 1);
16484 31331 : if (type_die2 == NULL)
16485 : break;
16486 31331 : mem_loc_result = op0;
16487 31331 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16488 31331 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16489 31331 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
16490 31331 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16491 31331 : add_loc_descr (&mem_loc_result, cvt);
16492 31331 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16493 31331 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16494 31331 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
16495 31331 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16496 31331 : add_loc_descr (&mem_loc_result, cvt);
16497 : }
16498 : break;
16499 :
16500 1732745 : case MEM:
16501 1732745 : {
16502 1732745 : rtx new_rtl = avoid_constant_pool_reference (rtl);
16503 1732745 : if (new_rtl != rtl)
16504 : {
16505 0 : mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
16506 : initialized);
16507 0 : if (mem_loc_result != NULL)
16508 : return mem_loc_result;
16509 : }
16510 : }
16511 1732745 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
16512 1732745 : get_address_mode (rtl), mode,
16513 : VAR_INIT_STATUS_INITIALIZED);
16514 1732745 : if (mem_loc_result == NULL)
16515 7888 : mem_loc_result = tls_mem_loc_descriptor (rtl);
16516 1732745 : if (mem_loc_result != NULL)
16517 : {
16518 1724857 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16519 3709966 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16520 : {
16521 58643 : dw_die_ref type_die;
16522 58643 : dw_loc_descr_ref deref;
16523 58643 : HOST_WIDE_INT size;
16524 :
16525 58643 : if (dwarf_strict && dwarf_version < 5)
16526 2663 : return NULL;
16527 117286 : if (!GET_MODE_SIZE (mode).is_constant (&size))
16528 : return NULL;
16529 58643 : type_die
16530 58643 : = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16531 58643 : if (type_die == NULL)
16532 : return NULL;
16533 55980 : deref = new_loc_descr (dwarf_OP (DW_OP_deref_type), size, 0);
16534 55980 : deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
16535 55980 : deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
16536 55980 : deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
16537 55980 : add_loc_descr (&mem_loc_result, deref);
16538 : }
16539 3599517 : else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
16540 1495168 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
16541 : else
16542 342092 : add_loc_descr (&mem_loc_result,
16543 : new_loc_descr (DW_OP_deref_size,
16544 171046 : GET_MODE_SIZE (int_mode), 0));
16545 : }
16546 : break;
16547 :
16548 0 : case LO_SUM:
16549 0 : return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
16550 :
16551 1077820 : case LABEL_REF:
16552 : /* Some ports can transform a symbol ref into a label ref, because
16553 : the symbol ref is too far away and has to be dumped into a constant
16554 : pool. */
16555 1077820 : case CONST:
16556 1077820 : case SYMBOL_REF:
16557 1077820 : case UNSPEC:
16558 1077820 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16559 2211696 : || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
16560 : #ifdef POINTERS_EXTEND_UNSIGNED
16561 0 : && (int_mode != Pmode || mem_mode == VOIDmode)
16562 : #endif
16563 : ))
16564 : break;
16565 :
16566 1077665 : if (GET_CODE (rtl) == UNSPEC)
16567 : {
16568 : /* If delegitimize_address couldn't do anything with the UNSPEC, we
16569 : can't express it in the debug info. This can happen e.g. with some
16570 : TLS UNSPECs. Allow UNSPECs formerly from CONST that the backend
16571 : approves. */
16572 166 : bool not_ok = false;
16573 166 : subrtx_var_iterator::array_type array;
16574 342 : FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
16575 332 : if (*iter != rtl && !CONSTANT_P (*iter))
16576 : {
16577 : not_ok = true;
16578 : break;
16579 : }
16580 :
16581 166 : if (not_ok)
16582 : break;
16583 :
16584 10 : FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
16585 10 : if (!const_ok_for_output_1 (*iter))
16586 : {
16587 : not_ok = true;
16588 : break;
16589 : }
16590 :
16591 10 : if (not_ok)
16592 : break;
16593 :
16594 0 : rtl = gen_rtx_CONST (GET_MODE (rtl), rtl);
16595 0 : goto symref;
16596 166 : }
16597 :
16598 1077499 : if (GET_CODE (rtl) == SYMBOL_REF
16599 1077499 : && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
16600 : {
16601 4817 : dw_loc_descr_ref temp;
16602 :
16603 : /* If this is not defined, we have no way to emit the data. */
16604 4817 : if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
16605 : break;
16606 :
16607 4817 : temp = new_addr_loc_descr (rtl, dtprel_true);
16608 :
16609 : /* We check for DWARF 5 here because gdb did not implement
16610 : DW_OP_form_tls_address until after 7.12. */
16611 4821 : mem_loc_result = new_loc_descr ((dwarf_version >= 5
16612 : ? DW_OP_form_tls_address
16613 : : DW_OP_GNU_push_tls_address),
16614 : 0, 0);
16615 4817 : add_loc_descr (&mem_loc_result, temp);
16616 :
16617 4817 : break;
16618 : }
16619 :
16620 1072682 : if (!const_ok_for_output (rtl))
16621 : {
16622 87949 : if (GET_CODE (rtl) == CONST)
16623 8373 : switch (GET_CODE (XEXP (rtl, 0)))
16624 : {
16625 0 : case NOT:
16626 0 : op = DW_OP_not;
16627 0 : goto try_const_unop;
16628 0 : case NEG:
16629 0 : op = DW_OP_neg;
16630 0 : goto try_const_unop;
16631 0 : try_const_unop:
16632 0 : rtx arg;
16633 0 : arg = XEXP (XEXP (rtl, 0), 0);
16634 0 : if (!CONSTANT_P (arg))
16635 0 : arg = gen_rtx_CONST (int_mode, arg);
16636 0 : op0 = mem_loc_descriptor (arg, int_mode, mem_mode,
16637 : initialized);
16638 0 : if (op0)
16639 : {
16640 0 : mem_loc_result = op0;
16641 0 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16642 : }
16643 : break;
16644 8373 : default:
16645 8373 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), int_mode,
16646 : mem_mode, initialized);
16647 8373 : break;
16648 : }
16649 : break;
16650 : }
16651 :
16652 984733 : symref:
16653 1100377 : mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
16654 1100377 : vec_safe_push (used_rtx_array, rtl);
16655 1100377 : break;
16656 :
16657 166561 : case CONCAT:
16658 166561 : case CONCATN:
16659 166561 : case VAR_LOCATION:
16660 166561 : case DEBUG_IMPLICIT_PTR:
16661 166561 : expansion_failed (NULL_TREE, rtl,
16662 : "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
16663 166561 : return 0;
16664 :
16665 1357230 : case ENTRY_VALUE:
16666 1357230 : if (dwarf_strict && dwarf_version < 5)
16667 : return NULL;
16668 1357230 : if (REG_P (ENTRY_VALUE_EXP (rtl)))
16669 : {
16670 1356017 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16671 2709281 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16672 43103 : op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
16673 : VOIDmode, VAR_INIT_STATUS_INITIALIZED);
16674 : else
16675 : {
16676 1312914 : unsigned int debugger_regnum = debugger_reg_number (ENTRY_VALUE_EXP (rtl));
16677 1312914 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
16678 : return NULL;
16679 1312914 : op0 = one_reg_loc_descriptor (debugger_regnum,
16680 : VAR_INIT_STATUS_INITIALIZED);
16681 : }
16682 : }
16683 1213 : else if (MEM_P (ENTRY_VALUE_EXP (rtl))
16684 1213 : && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
16685 : {
16686 1213 : op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
16687 : VOIDmode, VAR_INIT_STATUS_INITIALIZED);
16688 1213 : if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
16689 : return NULL;
16690 : }
16691 : else
16692 0 : gcc_unreachable ();
16693 1357208 : if (op0 == NULL)
16694 : return NULL;
16695 1355892 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_entry_value), 0, 0);
16696 1355892 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
16697 1355892 : mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
16698 1355892 : break;
16699 :
16700 29873 : case DEBUG_PARAMETER_REF:
16701 29873 : mem_loc_result = parameter_ref_descriptor (rtl);
16702 29873 : break;
16703 :
16704 0 : case PRE_MODIFY:
16705 : /* Extract the PLUS expression nested inside and fall into
16706 : PLUS code below. */
16707 0 : rtl = XEXP (rtl, 1);
16708 0 : goto plus;
16709 :
16710 0 : case PRE_INC:
16711 0 : case PRE_DEC:
16712 : /* Turn these into a PLUS expression and fall into the PLUS code
16713 : below. */
16714 0 : rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
16715 : gen_int_mode (GET_CODE (rtl) == PRE_INC
16716 : ? GET_MODE_UNIT_SIZE (mem_mode)
16717 : : -GET_MODE_UNIT_SIZE (mem_mode),
16718 : mode));
16719 :
16720 : /* fall through */
16721 :
16722 11211098 : case PLUS:
16723 11211098 : plus:
16724 11211098 : if (is_based_loc (rtl)
16725 9726148 : && is_a <scalar_int_mode> (mode, &int_mode)
16726 22312898 : && (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16727 1106 : || XEXP (rtl, 0) == arg_pointer_rtx
16728 1106 : || XEXP (rtl, 0) == frame_pointer_rtx))
16729 9725043 : mem_loc_result = based_loc_descr (XEXP (rtl, 0),
16730 9725043 : INTVAL (XEXP (rtl, 1)),
16731 : VAR_INIT_STATUS_INITIALIZED);
16732 : else
16733 : {
16734 1486055 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16735 : VAR_INIT_STATUS_INITIALIZED);
16736 1486055 : if (mem_loc_result == 0)
16737 : break;
16738 :
16739 1473281 : if (CONST_INT_P (XEXP (rtl, 1))
16740 2228412 : && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
16741 755131 : <= DWARF2_ADDR_SIZE))
16742 752936 : loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
16743 : else
16744 : {
16745 720345 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16746 : VAR_INIT_STATUS_INITIALIZED);
16747 720345 : if (op1 == 0)
16748 : return NULL;
16749 706432 : add_loc_descr (&mem_loc_result, op1);
16750 706432 : add_loc_descr (&mem_loc_result,
16751 : new_loc_descr (DW_OP_plus, 0, 0));
16752 : }
16753 : }
16754 : break;
16755 :
16756 : /* If a pseudo-reg is optimized away, it is possible for it to
16757 : be replaced with a MEM containing a multiply or shift. */
16758 432923 : case MINUS:
16759 432923 : op = DW_OP_minus;
16760 432923 : goto do_binop;
16761 :
16762 221741 : case MULT:
16763 221741 : op = DW_OP_mul;
16764 221741 : goto do_binop;
16765 :
16766 258945 : case DIV:
16767 0 : if ((!dwarf_strict || dwarf_version >= 5)
16768 258945 : && is_a <scalar_int_mode> (mode, &int_mode)
16769 514161 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16770 : {
16771 63 : mem_loc_result = typed_binop (DW_OP_div, rtl,
16772 : base_type_for_mode (mode, 0),
16773 : int_mode, mem_mode);
16774 63 : break;
16775 : }
16776 258882 : op = DW_OP_div;
16777 258882 : goto do_binop;
16778 :
16779 4001 : case UMOD:
16780 4001 : op = DW_OP_mod;
16781 4001 : goto do_binop;
16782 :
16783 322107 : case ASHIFT:
16784 322107 : op = DW_OP_shl;
16785 322107 : goto do_shift;
16786 :
16787 125981 : case ASHIFTRT:
16788 125981 : op = DW_OP_shra;
16789 125981 : goto do_shift;
16790 :
16791 251685 : case LSHIFTRT:
16792 251685 : op = DW_OP_shr;
16793 251685 : goto do_shift;
16794 :
16795 699773 : do_shift:
16796 699773 : if (!is_a <scalar_int_mode> (mode, &int_mode))
16797 : break;
16798 699727 : op0 = mem_loc_descriptor (XEXP (rtl, 0), int_mode, mem_mode,
16799 : VAR_INIT_STATUS_INITIALIZED);
16800 699727 : {
16801 699727 : rtx rtlop1 = XEXP (rtl, 1);
16802 699727 : if (is_a <scalar_int_mode> (GET_MODE (rtlop1), &op1_mode)
16803 717727 : && GET_MODE_BITSIZE (op1_mode) < GET_MODE_BITSIZE (int_mode))
16804 6720 : rtlop1 = gen_rtx_ZERO_EXTEND (int_mode, rtlop1);
16805 699727 : op1 = mem_loc_descriptor (rtlop1, int_mode, mem_mode,
16806 : VAR_INIT_STATUS_INITIALIZED);
16807 : }
16808 :
16809 699727 : if (op0 == 0 || op1 == 0)
16810 : break;
16811 :
16812 693866 : mem_loc_result = op0;
16813 693866 : add_loc_descr (&mem_loc_result, op1);
16814 693866 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16815 693866 : break;
16816 :
16817 210941 : case AND:
16818 210941 : op = DW_OP_and;
16819 210941 : goto do_binop;
16820 :
16821 80014 : case IOR:
16822 80014 : op = DW_OP_or;
16823 80014 : goto do_binop;
16824 :
16825 16048 : case XOR:
16826 16048 : op = DW_OP_xor;
16827 16048 : goto do_binop;
16828 :
16829 1228377 : do_binop:
16830 1228377 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16831 : VAR_INIT_STATUS_INITIALIZED);
16832 1228377 : if (XEXP (rtl, 0) == XEXP (rtl, 1))
16833 : {
16834 16496 : if (op0 == 0)
16835 : break;
16836 16478 : mem_loc_result = op0;
16837 16478 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_dup, 0, 0));
16838 16478 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16839 16478 : break;
16840 : }
16841 1211881 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16842 : VAR_INIT_STATUS_INITIALIZED);
16843 :
16844 1211881 : if (op0 == 0 || op1 == 0)
16845 : break;
16846 :
16847 1194192 : mem_loc_result = op0;
16848 1194192 : add_loc_descr (&mem_loc_result, op1);
16849 1194192 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16850 1194192 : break;
16851 :
16852 1905 : case MOD:
16853 0 : if ((!dwarf_strict || dwarf_version >= 5)
16854 1905 : && is_a <scalar_int_mode> (mode, &int_mode)
16855 4029 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16856 : {
16857 14 : mem_loc_result = typed_binop (DW_OP_mod, rtl,
16858 : base_type_for_mode (mode, 0),
16859 : int_mode, mem_mode);
16860 14 : break;
16861 : }
16862 :
16863 1891 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16864 : VAR_INIT_STATUS_INITIALIZED);
16865 1891 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16866 : VAR_INIT_STATUS_INITIALIZED);
16867 :
16868 1891 : if (op0 == 0 || op1 == 0)
16869 : break;
16870 :
16871 1882 : mem_loc_result = op0;
16872 1882 : add_loc_descr (&mem_loc_result, op1);
16873 1882 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
16874 1882 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
16875 1882 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
16876 1882 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
16877 1882 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
16878 1882 : break;
16879 :
16880 7587 : case UDIV:
16881 0 : if ((!dwarf_strict || dwarf_version >= 5)
16882 7587 : && is_a <scalar_int_mode> (mode, &int_mode))
16883 : {
16884 : /* We can use a signed divide if the sign bit is not set. */
16885 16315 : if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
16886 : {
16887 3827 : op = DW_OP_div;
16888 3827 : goto do_binop;
16889 : }
16890 :
16891 3760 : mem_loc_result = typed_binop (DW_OP_div, rtl,
16892 : base_type_for_mode (int_mode, 1),
16893 : int_mode, mem_mode);
16894 : }
16895 : break;
16896 :
16897 42259 : case NOT:
16898 42259 : op = DW_OP_not;
16899 42259 : goto do_unop;
16900 :
16901 2362 : case ABS:
16902 2362 : op = DW_OP_abs;
16903 2362 : goto do_unop;
16904 :
16905 87993 : case NEG:
16906 87993 : op = DW_OP_neg;
16907 87993 : goto do_unop;
16908 :
16909 132614 : do_unop:
16910 132614 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16911 : VAR_INIT_STATUS_INITIALIZED);
16912 :
16913 132614 : if (op0 == 0)
16914 : break;
16915 :
16916 131614 : mem_loc_result = op0;
16917 131614 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16918 131614 : break;
16919 :
16920 2065735 : case CONST_INT:
16921 2065735 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16922 2258886 : || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16923 : #ifdef POINTERS_EXTEND_UNSIGNED
16924 2140403 : || (int_mode == Pmode
16925 0 : && mem_mode != VOIDmode
16926 0 : && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
16927 : #endif
16928 : )
16929 : {
16930 2027591 : mem_loc_result = int_loc_descriptor (INTVAL (rtl));
16931 2027591 : break;
16932 : }
16933 0 : if ((!dwarf_strict || dwarf_version >= 5)
16934 76288 : && (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT
16935 1620 : || GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_DOUBLE_INT))
16936 : {
16937 38144 : dw_die_ref type_die = base_type_for_mode (int_mode, 1);
16938 38144 : scalar_int_mode amode;
16939 38144 : if (type_die == NULL)
16940 23409 : return NULL;
16941 38144 : if (INTVAL (rtl) >= 0
16942 107086 : && (int_mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT, 0)
16943 36183 : .exists (&amode))
16944 36183 : && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
16945 : /* const DW_OP_convert <XXX> vs.
16946 : DW_OP_const_type <XXX, 1, const>. */
16947 61553 : && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
16948 23409 : < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode))
16949 : {
16950 23409 : mem_loc_result = int_loc_descriptor (INTVAL (rtl));
16951 23409 : op0 = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16952 23409 : op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16953 23409 : op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16954 23409 : op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
16955 23409 : add_loc_descr (&mem_loc_result, op0);
16956 23409 : return mem_loc_result;
16957 : }
16958 29470 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0,
16959 14735 : INTVAL (rtl));
16960 14735 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16961 14735 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16962 14735 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
16963 29470 : if (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT)
16964 14578 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
16965 : else
16966 : {
16967 157 : mem_loc_result->dw_loc_oprnd2.val_class
16968 157 : = dw_val_class_const_double;
16969 157 : mem_loc_result->dw_loc_oprnd2.v.val_double
16970 157 : = double_int::from_shwi (INTVAL (rtl));
16971 : }
16972 : }
16973 : break;
16974 :
16975 31627 : case CONST_DOUBLE:
16976 31627 : if (!dwarf_strict || dwarf_version >= 5)
16977 : {
16978 31627 : dw_die_ref type_die;
16979 :
16980 : /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
16981 : CONST_DOUBLE rtx could represent either a large integer
16982 : or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
16983 : the value is always a floating point constant.
16984 :
16985 : When it is an integer, a CONST_DOUBLE is used whenever
16986 : the constant requires 2 HWIs to be adequately represented.
16987 : We output CONST_DOUBLEs as blocks. */
16988 31627 : if (mode == VOIDmode
16989 31627 : || (GET_MODE (rtl) == VOIDmode
16990 0 : && maybe_ne (GET_MODE_BITSIZE (mode),
16991 0 : HOST_BITS_PER_DOUBLE_INT)))
16992 : break;
16993 31627 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16994 31627 : if (type_die == NULL)
16995 : return NULL;
16996 31627 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0, 0);
16997 31627 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16998 31627 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16999 31627 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
17000 : #if TARGET_SUPPORTS_WIDE_INT == 0
17001 : if (!SCALAR_FLOAT_MODE_P (mode))
17002 : {
17003 : mem_loc_result->dw_loc_oprnd2.val_class
17004 : = dw_val_class_const_double;
17005 : mem_loc_result->dw_loc_oprnd2.v.val_double
17006 : = rtx_to_double_int (rtl);
17007 : }
17008 : else
17009 : #endif
17010 31627 : {
17011 31627 : scalar_float_mode float_mode = as_a <scalar_float_mode> (mode);
17012 31627 : unsigned int length = GET_MODE_SIZE (float_mode);
17013 31627 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
17014 31627 : unsigned int elt_size = insert_float (rtl, array);
17015 :
17016 31627 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17017 31627 : mem_loc_result->dw_loc_oprnd2.v.val_vec.length
17018 31627 : = length / elt_size;
17019 31627 : mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17020 31627 : mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
17021 : }
17022 : }
17023 : break;
17024 :
17025 115 : case CONST_WIDE_INT:
17026 115 : if (!dwarf_strict || dwarf_version >= 5)
17027 : {
17028 115 : dw_die_ref type_die;
17029 :
17030 115 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
17031 115 : if (type_die == NULL)
17032 : return NULL;
17033 115 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0, 0);
17034 115 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17035 115 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
17036 115 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
17037 115 : mem_loc_result->dw_loc_oprnd2.val_class
17038 115 : = dw_val_class_wide_int;
17039 115 : mem_loc_result->dw_loc_oprnd2.v.val_wide
17040 115 : = alloc_dw_wide_int (rtx_mode_t (rtl, mode));
17041 : }
17042 : break;
17043 :
17044 0 : case CONST_POLY_INT:
17045 0 : mem_loc_result = int_loc_descriptor (rtx_to_poly_int64 (rtl));
17046 0 : break;
17047 :
17048 33707 : case EQ:
17049 33707 : mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
17050 33707 : break;
17051 :
17052 5112 : case GE:
17053 5112 : mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
17054 5112 : break;
17055 :
17056 4340 : case GT:
17057 4340 : mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
17058 4340 : break;
17059 :
17060 2475 : case LE:
17061 2475 : mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
17062 2475 : break;
17063 :
17064 5397 : case LT:
17065 5397 : mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
17066 5397 : break;
17067 :
17068 47691 : case NE:
17069 47691 : mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
17070 47691 : break;
17071 :
17072 5698 : case GEU:
17073 5698 : mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
17074 5698 : break;
17075 :
17076 7346 : case GTU:
17077 7346 : mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
17078 7346 : break;
17079 :
17080 16135 : case LEU:
17081 16135 : mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
17082 16135 : break;
17083 :
17084 3037 : case LTU:
17085 3037 : mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
17086 3037 : break;
17087 :
17088 128797 : case UMIN:
17089 128797 : case UMAX:
17090 128797 : if (!SCALAR_INT_MODE_P (mode))
17091 : break;
17092 : /* FALLTHRU */
17093 146699 : case SMIN:
17094 146699 : case SMAX:
17095 146699 : mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
17096 146699 : break;
17097 :
17098 4112 : case ZERO_EXTRACT:
17099 4112 : case SIGN_EXTRACT:
17100 4112 : if (CONST_INT_P (XEXP (rtl, 1))
17101 4112 : && CONST_INT_P (XEXP (rtl, 2))
17102 4112 : && is_a <scalar_int_mode> (mode, &int_mode)
17103 4104 : && is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &inner_mode)
17104 3060 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
17105 3060 : && GET_MODE_SIZE (inner_mode) <= DWARF2_ADDR_SIZE
17106 4112 : && ((unsigned) INTVAL (XEXP (rtl, 1))
17107 2722 : + (unsigned) INTVAL (XEXP (rtl, 2))
17108 2722 : <= GET_MODE_BITSIZE (int_mode)))
17109 : {
17110 2619 : int shift, size;
17111 2619 : op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
17112 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
17113 2619 : if (op0 == 0)
17114 : break;
17115 2619 : if (GET_CODE (rtl) == SIGN_EXTRACT)
17116 : op = DW_OP_shra;
17117 : else
17118 421 : op = DW_OP_shr;
17119 2619 : mem_loc_result = op0;
17120 2619 : size = INTVAL (XEXP (rtl, 1));
17121 2619 : shift = INTVAL (XEXP (rtl, 2));
17122 2619 : if (BITS_BIG_ENDIAN)
17123 : shift = GET_MODE_BITSIZE (inner_mode) - shift - size;
17124 2789 : if (shift + size != (int) DWARF2_ADDR_SIZE)
17125 : {
17126 2564 : add_loc_descr (&mem_loc_result,
17127 2564 : int_loc_descriptor (DWARF2_ADDR_SIZE
17128 2564 : - shift - size));
17129 2564 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
17130 : }
17131 2789 : if (size != (int) DWARF2_ADDR_SIZE)
17132 : {
17133 2390 : add_loc_descr (&mem_loc_result,
17134 2558 : int_loc_descriptor (DWARF2_ADDR_SIZE - size));
17135 2390 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
17136 : }
17137 : }
17138 : break;
17139 :
17140 30532 : case IF_THEN_ELSE:
17141 30532 : {
17142 30532 : dw_loc_descr_ref op2, bra_node, drop_node;
17143 30532 : op0 = mem_loc_descriptor (XEXP (rtl, 0),
17144 30532 : GET_MODE (XEXP (rtl, 0)) == VOIDmode
17145 28680 : ? word_mode : GET_MODE (XEXP (rtl, 0)),
17146 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
17147 30532 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
17148 : VAR_INIT_STATUS_INITIALIZED);
17149 30532 : op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
17150 : VAR_INIT_STATUS_INITIALIZED);
17151 30532 : if (op0 == NULL || op1 == NULL || op2 == NULL)
17152 : break;
17153 :
17154 29851 : mem_loc_result = op1;
17155 29851 : add_loc_descr (&mem_loc_result, op2);
17156 29851 : add_loc_descr (&mem_loc_result, op0);
17157 29851 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
17158 29851 : add_loc_descr (&mem_loc_result, bra_node);
17159 29851 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
17160 29851 : drop_node = new_loc_descr (DW_OP_drop, 0, 0);
17161 29851 : add_loc_descr (&mem_loc_result, drop_node);
17162 29851 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
17163 29851 : bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
17164 : }
17165 29851 : break;
17166 :
17167 24392 : case FLOAT_EXTEND:
17168 24392 : case FLOAT_TRUNCATE:
17169 24392 : case FLOAT:
17170 24392 : case UNSIGNED_FLOAT:
17171 24392 : case FIX:
17172 24392 : case UNSIGNED_FIX:
17173 24392 : if (!dwarf_strict || dwarf_version >= 5)
17174 : {
17175 24392 : dw_die_ref type_die;
17176 24392 : dw_loc_descr_ref cvt;
17177 :
17178 24392 : op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
17179 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
17180 24392 : if (op0 == NULL)
17181 : break;
17182 24199 : if (is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &int_mode)
17183 24199 : && (GET_CODE (rtl) == FLOAT
17184 1495 : || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE))
17185 : {
17186 5239 : type_die = base_type_for_mode (int_mode,
17187 : GET_CODE (rtl) == UNSIGNED_FLOAT);
17188 5239 : if (type_die == NULL)
17189 : break;
17190 5239 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
17191 5239 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17192 5239 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
17193 5239 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
17194 5239 : add_loc_descr (&op0, cvt);
17195 : }
17196 24199 : type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
17197 24199 : if (type_die == NULL)
17198 : break;
17199 24199 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
17200 24199 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17201 24199 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
17202 24199 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
17203 24199 : add_loc_descr (&op0, cvt);
17204 24199 : if (is_a <scalar_int_mode> (mode, &int_mode)
17205 24199 : && (GET_CODE (rtl) == FIX
17206 59 : || GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE))
17207 : {
17208 1589 : op0 = convert_descriptor_to_mode (int_mode, op0);
17209 1589 : if (op0 == NULL)
17210 : break;
17211 : }
17212 24199 : mem_loc_result = op0;
17213 : }
17214 : break;
17215 :
17216 5254 : case CLZ:
17217 5254 : case CTZ:
17218 5254 : case FFS:
17219 5254 : if (is_a <scalar_int_mode> (mode, &int_mode))
17220 5254 : mem_loc_result = clz_loc_descriptor (rtl, int_mode, mem_mode);
17221 : break;
17222 :
17223 0 : case POPCOUNT:
17224 0 : case PARITY:
17225 0 : if (is_a <scalar_int_mode> (mode, &int_mode))
17226 0 : mem_loc_result = popcount_loc_descriptor (rtl, int_mode, mem_mode);
17227 : break;
17228 :
17229 164 : case BSWAP:
17230 164 : if (is_a <scalar_int_mode> (mode, &int_mode))
17231 164 : mem_loc_result = bswap_loc_descriptor (rtl, int_mode, mem_mode);
17232 : break;
17233 :
17234 3697 : case ROTATE:
17235 3697 : case ROTATERT:
17236 3697 : if (is_a <scalar_int_mode> (mode, &int_mode))
17237 3697 : mem_loc_result = rotate_loc_descriptor (rtl, int_mode, mem_mode);
17238 : break;
17239 :
17240 : case COMPARE:
17241 : /* In theory, we could implement the above. */
17242 : /* DWARF cannot represent the unsigned compare operations
17243 : natively. */
17244 : case SS_MULT:
17245 : case US_MULT:
17246 : case SS_DIV:
17247 : case US_DIV:
17248 : case SS_PLUS:
17249 : case US_PLUS:
17250 : case SS_MINUS:
17251 : case US_MINUS:
17252 : case SS_NEG:
17253 : case US_NEG:
17254 : case SS_ABS:
17255 : case SS_ASHIFT:
17256 : case US_ASHIFT:
17257 : case SS_TRUNCATE:
17258 : case US_TRUNCATE:
17259 : case UNORDERED:
17260 : case ORDERED:
17261 : case UNEQ:
17262 : case UNGE:
17263 : case UNGT:
17264 : case UNLE:
17265 : case UNLT:
17266 : case LTGT:
17267 : case FRACT_CONVERT:
17268 : case UNSIGNED_FRACT_CONVERT:
17269 : case SAT_FRACT:
17270 : case UNSIGNED_SAT_FRACT:
17271 : case SQRT:
17272 : case ASM_OPERANDS:
17273 : case VEC_MERGE:
17274 : case VEC_SELECT:
17275 : case VEC_CONCAT:
17276 : case VEC_DUPLICATE:
17277 : case VEC_SERIES:
17278 : case HIGH:
17279 : case FMA:
17280 : case STRICT_LOW_PART:
17281 : case CONST_VECTOR:
17282 : case CONST_FIXED:
17283 : case CLRSB:
17284 : case CLOBBER:
17285 : case SMUL_HIGHPART:
17286 : case UMUL_HIGHPART:
17287 : case BITREVERSE:
17288 : case COPYSIGN:
17289 : break;
17290 :
17291 115644 : case CONST_STRING:
17292 115644 : resolve_one_addr (&rtl);
17293 115644 : goto symref;
17294 :
17295 : /* RTL sequences inside PARALLEL record a series of DWARF operations for
17296 : the expression. An UNSPEC rtx represents a raw DWARF operation,
17297 : new_loc_descr is called for it to build the operation directly.
17298 : Otherwise mem_loc_descriptor is called recursively. */
17299 : case PARALLEL:
17300 : {
17301 : int index = 0;
17302 0 : dw_loc_descr_ref exp_result = NULL;
17303 :
17304 0 : for (; index < XVECLEN (rtl, 0); index++)
17305 : {
17306 0 : rtx elem = XVECEXP (rtl, 0, index);
17307 0 : if (GET_CODE (elem) == UNSPEC)
17308 : {
17309 : /* Each DWARF operation UNSPEC contain two operands, if
17310 : one operand is not used for the operation, const0_rtx is
17311 : passed. */
17312 0 : gcc_assert (XVECLEN (elem, 0) == 2);
17313 :
17314 0 : HOST_WIDE_INT dw_op = XINT (elem, 1);
17315 0 : HOST_WIDE_INT oprnd1 = INTVAL (XVECEXP (elem, 0, 0));
17316 0 : HOST_WIDE_INT oprnd2 = INTVAL (XVECEXP (elem, 0, 1));
17317 0 : exp_result
17318 0 : = new_loc_descr ((enum dwarf_location_atom) dw_op, oprnd1,
17319 : oprnd2);
17320 : }
17321 : else
17322 0 : exp_result
17323 0 : = mem_loc_descriptor (elem, mode, mem_mode,
17324 : VAR_INIT_STATUS_INITIALIZED);
17325 :
17326 0 : if (!mem_loc_result)
17327 0 : mem_loc_result = exp_result;
17328 : else
17329 0 : add_loc_descr (&mem_loc_result, exp_result);
17330 : }
17331 :
17332 : break;
17333 : }
17334 :
17335 0 : default:
17336 0 : if (flag_checking)
17337 : {
17338 0 : print_rtl (stderr, rtl);
17339 0 : gcc_unreachable ();
17340 : }
17341 : break;
17342 : }
17343 :
17344 23680790 : if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
17345 10859 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
17346 :
17347 23680790 : return mem_loc_result;
17348 : }
17349 :
17350 : /* Return a descriptor that describes the concatenation of two locations.
17351 : This is typically a complex variable. */
17352 :
17353 : static dw_loc_descr_ref
17354 21434 : concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
17355 : {
17356 : /* At present we only track constant-sized pieces. */
17357 21434 : unsigned int size0, size1;
17358 42868 : if (!GET_MODE_SIZE (GET_MODE (x0)).is_constant (&size0)
17359 42868 : || !GET_MODE_SIZE (GET_MODE (x1)).is_constant (&size1))
17360 : return 0;
17361 :
17362 21434 : dw_loc_descr_ref cc_loc_result = NULL;
17363 21434 : dw_loc_descr_ref x0_ref
17364 21434 : = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
17365 21434 : dw_loc_descr_ref x1_ref
17366 21434 : = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
17367 :
17368 21434 : if (x0_ref == 0 || x1_ref == 0)
17369 : return 0;
17370 :
17371 20307 : cc_loc_result = x0_ref;
17372 20307 : add_loc_descr_op_piece (&cc_loc_result, size0);
17373 :
17374 20307 : add_loc_descr (&cc_loc_result, x1_ref);
17375 20307 : add_loc_descr_op_piece (&cc_loc_result, size1);
17376 :
17377 20307 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
17378 0 : add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
17379 :
17380 20307 : return cc_loc_result;
17381 : }
17382 :
17383 : /* Return a descriptor that describes the concatenation of N
17384 : locations. */
17385 :
17386 : static dw_loc_descr_ref
17387 37953 : concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
17388 : {
17389 37953 : unsigned int i;
17390 37953 : dw_loc_descr_ref cc_loc_result = NULL;
17391 37953 : unsigned int n = XVECLEN (concatn, 0);
17392 37953 : unsigned int size;
17393 :
17394 82809 : for (i = 0; i < n; ++i)
17395 : {
17396 63775 : dw_loc_descr_ref ref;
17397 63775 : rtx x = XVECEXP (concatn, 0, i);
17398 :
17399 : /* At present we only track constant-sized pieces. */
17400 127550 : if (!GET_MODE_SIZE (GET_MODE (x)).is_constant (&size))
17401 : return NULL;
17402 :
17403 63775 : ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
17404 63775 : if (ref == NULL)
17405 : return NULL;
17406 :
17407 44856 : add_loc_descr (&cc_loc_result, ref);
17408 44856 : add_loc_descr_op_piece (&cc_loc_result, size);
17409 : }
17410 :
17411 19034 : if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
17412 0 : add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
17413 :
17414 19034 : return cc_loc_result;
17415 : }
17416 :
17417 : /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
17418 : for DEBUG_IMPLICIT_PTR RTL. */
17419 :
17420 : static dw_loc_descr_ref
17421 1828707 : implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
17422 : {
17423 1828707 : dw_loc_descr_ref ret;
17424 1828707 : dw_die_ref ref;
17425 :
17426 1828707 : if (dwarf_strict && dwarf_version < 5)
17427 : return NULL;
17428 1828707 : gcc_assert (VAR_P (DEBUG_IMPLICIT_PTR_DECL (rtl))
17429 : || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
17430 : || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
17431 1828707 : ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
17432 1829110 : ret = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
17433 1828707 : ret->dw_loc_oprnd2.val_class = dw_val_class_const;
17434 1828707 : if (ref)
17435 : {
17436 1109272 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17437 1109272 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
17438 1109272 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
17439 : }
17440 : else
17441 : {
17442 719435 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
17443 719435 : ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
17444 : }
17445 : return ret;
17446 : }
17447 :
17448 : /* Output a proper Dwarf location descriptor for a variable or parameter
17449 : which is either allocated in a register or in a memory location. For a
17450 : register, we just generate an OP_REG and the register number. For a
17451 : memory location we provide a Dwarf postfix expression describing how to
17452 : generate the (dynamic) address of the object onto the address stack.
17453 :
17454 : MODE is mode of the decl if this loc_descriptor is going to be used in
17455 : .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
17456 : allowed, VOIDmode otherwise.
17457 :
17458 : If we don't know how to describe it, return 0. */
17459 :
17460 : static dw_loc_descr_ref
17461 55076883 : loc_descriptor (rtx rtl, machine_mode mode,
17462 : enum var_init_status initialized)
17463 : {
17464 55076883 : dw_loc_descr_ref loc_result = NULL;
17465 55076883 : scalar_int_mode int_mode;
17466 :
17467 55076883 : switch (GET_CODE (rtl))
17468 : {
17469 141516 : case SUBREG:
17470 : /* The case of a subreg may arise when we have a local (register)
17471 : variable or a formal (register) parameter which doesn't quite fill
17472 : up an entire register. For now, just assume that it is
17473 : legitimate to make the Dwarf info refer to the whole register which
17474 : contains the given subreg. */
17475 141516 : if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
17476 32 : loc_result = loc_descriptor (SUBREG_REG (rtl),
17477 16 : GET_MODE (SUBREG_REG (rtl)), initialized);
17478 : else
17479 141500 : goto do_default;
17480 16 : break;
17481 :
17482 11287158 : case REG:
17483 11287158 : loc_result = reg_loc_descriptor (rtl, initialized);
17484 11287158 : break;
17485 :
17486 3783062 : case MEM:
17487 3783062 : loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
17488 3783062 : GET_MODE (rtl), initialized);
17489 3783062 : if (loc_result == NULL)
17490 10462 : loc_result = tls_mem_loc_descriptor (rtl);
17491 3783062 : if (loc_result == NULL)
17492 : {
17493 10462 : rtx new_rtl = avoid_constant_pool_reference (rtl);
17494 10462 : if (new_rtl != rtl)
17495 0 : loc_result = loc_descriptor (new_rtl, mode, initialized);
17496 : }
17497 : break;
17498 :
17499 21434 : case CONCAT:
17500 21434 : loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
17501 : initialized);
17502 21434 : break;
17503 :
17504 37953 : case CONCATN:
17505 37953 : loc_result = concatn_loc_descriptor (rtl, initialized);
17506 37953 : break;
17507 :
17508 27075449 : case VAR_LOCATION:
17509 : /* Single part. */
17510 27075449 : if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
17511 : {
17512 26927217 : rtx loc = PAT_VAR_LOCATION_LOC (rtl);
17513 26927217 : if (GET_CODE (loc) == EXPR_LIST)
17514 0 : loc = XEXP (loc, 0);
17515 26927217 : loc_result = loc_descriptor (loc, mode, initialized);
17516 26927217 : break;
17517 : }
17518 :
17519 148232 : rtl = XEXP (rtl, 1);
17520 : /* FALLTHRU */
17521 :
17522 148551 : case PARALLEL:
17523 148551 : {
17524 148551 : rtvec par_elems = XVEC (rtl, 0);
17525 148551 : int num_elem = GET_NUM_ELEM (par_elems);
17526 148551 : machine_mode mode;
17527 148551 : int i, size;
17528 :
17529 : /* Create the first one, so we have something to add to. */
17530 148551 : loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
17531 : VOIDmode, initialized);
17532 148551 : if (loc_result == NULL)
17533 55076883 : return NULL;
17534 148551 : mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
17535 : /* At present we only track constant-sized pieces. */
17536 297102 : if (!GET_MODE_SIZE (mode).is_constant (&size))
17537 : return NULL;
17538 148551 : add_loc_descr_op_piece (&loc_result, size);
17539 297124 : for (i = 1; i < num_elem; i++)
17540 : {
17541 148573 : dw_loc_descr_ref temp;
17542 :
17543 148573 : temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
17544 : VOIDmode, initialized);
17545 148573 : if (temp == NULL)
17546 : return NULL;
17547 148573 : add_loc_descr (&loc_result, temp);
17548 148573 : mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
17549 : /* At present we only track constant-sized pieces. */
17550 297146 : if (!GET_MODE_SIZE (mode).is_constant (&size))
17551 : return NULL;
17552 148573 : add_loc_descr_op_piece (&loc_result, size);
17553 : }
17554 : }
17555 : break;
17556 :
17557 2918295 : case CONST_INT:
17558 2918295 : if (mode != VOIDmode && mode != BLKmode)
17559 : {
17560 2911254 : int_mode = as_a <scalar_int_mode> (mode);
17561 5822508 : loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode),
17562 : INTVAL (rtl));
17563 : }
17564 : break;
17565 :
17566 51920 : case CONST_DOUBLE:
17567 51920 : if (mode == VOIDmode)
17568 12811 : mode = GET_MODE (rtl);
17569 :
17570 51920 : if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
17571 : {
17572 51920 : gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
17573 :
17574 : /* Note that a CONST_DOUBLE rtx could represent either an integer
17575 : or a floating-point constant. A CONST_DOUBLE is used whenever
17576 : the constant requires more than one word in order to be
17577 : adequately represented. We output CONST_DOUBLEs as blocks. */
17578 51920 : scalar_mode smode = as_a <scalar_mode> (mode);
17579 51920 : loc_result = new_loc_descr (DW_OP_implicit_value,
17580 51920 : GET_MODE_SIZE (smode), 0);
17581 : #if TARGET_SUPPORTS_WIDE_INT == 0
17582 : if (!SCALAR_FLOAT_MODE_P (smode))
17583 : {
17584 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
17585 : loc_result->dw_loc_oprnd2.v.val_double
17586 : = rtx_to_double_int (rtl);
17587 : }
17588 : else
17589 : #endif
17590 51920 : {
17591 51920 : unsigned int length = GET_MODE_SIZE (smode);
17592 51920 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
17593 51920 : unsigned int elt_size = insert_float (rtl, array);
17594 :
17595 51920 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17596 51920 : loc_result->dw_loc_oprnd2.v.val_vec.length = length / elt_size;
17597 51920 : loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17598 51920 : loc_result->dw_loc_oprnd2.v.val_vec.array = array;
17599 : }
17600 : }
17601 : break;
17602 :
17603 630 : case CONST_WIDE_INT:
17604 630 : if (mode == VOIDmode)
17605 4 : mode = GET_MODE (rtl);
17606 :
17607 630 : if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
17608 : {
17609 626 : int_mode = as_a <scalar_int_mode> (mode);
17610 626 : loc_result = new_loc_descr (DW_OP_implicit_value,
17611 626 : GET_MODE_SIZE (int_mode), 0);
17612 626 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
17613 626 : loc_result->dw_loc_oprnd2.v.val_wide
17614 626 : = alloc_dw_wide_int (rtx_mode_t (rtl, int_mode));
17615 : }
17616 : break;
17617 :
17618 7 : case CONST_VECTOR:
17619 7 : if (mode == VOIDmode)
17620 0 : mode = GET_MODE (rtl);
17621 :
17622 0 : if (mode != VOIDmode
17623 : /* The combination of a length and byte elt_size doesn't extend
17624 : naturally to boolean vectors, where several elements are packed
17625 : into the same byte. */
17626 7 : && GET_MODE_CLASS (mode) != MODE_VECTOR_BOOL
17627 7 : && (dwarf_version >= 4 || !dwarf_strict))
17628 : {
17629 7 : unsigned int length;
17630 14 : if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
17631 : return NULL;
17632 :
17633 7 : unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
17634 7 : unsigned char *array
17635 7 : = ggc_vec_alloc<unsigned char> (length * elt_size);
17636 7 : unsigned int i;
17637 7 : unsigned char *p;
17638 7 : machine_mode imode = GET_MODE_INNER (mode);
17639 :
17640 7 : gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
17641 7 : switch (GET_MODE_CLASS (mode))
17642 : {
17643 : case MODE_VECTOR_INT:
17644 25 : for (i = 0, p = array; i < length; i++, p += elt_size)
17645 : {
17646 20 : rtx elt = CONST_VECTOR_ELT (rtl, i);
17647 20 : insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
17648 : }
17649 : break;
17650 :
17651 : case MODE_VECTOR_FLOAT:
17652 10 : for (i = 0, p = array; i < length; i++, p += elt_size)
17653 : {
17654 8 : rtx elt = CONST_VECTOR_ELT (rtl, i);
17655 8 : insert_float (elt, p);
17656 : }
17657 : break;
17658 :
17659 0 : default:
17660 0 : gcc_unreachable ();
17661 : }
17662 :
17663 7 : loc_result = new_loc_descr (DW_OP_implicit_value,
17664 : length * elt_size, 0);
17665 7 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17666 7 : loc_result->dw_loc_oprnd2.v.val_vec.length = length;
17667 7 : loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17668 7 : loc_result->dw_loc_oprnd2.v.val_vec.array = array;
17669 : }
17670 : break;
17671 :
17672 96550 : case CONST:
17673 96550 : if (mode == VOIDmode
17674 96550 : || CONST_SCALAR_INT_P (XEXP (rtl, 0))
17675 96550 : || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
17676 96550 : || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
17677 : {
17678 0 : loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
17679 0 : break;
17680 : }
17681 : /* FALLTHROUGH */
17682 528960 : case SYMBOL_REF:
17683 528960 : if (!const_ok_for_output (rtl))
17684 : break;
17685 : /* FALLTHROUGH */
17686 489834 : case LABEL_REF:
17687 489834 : if (is_a <scalar_int_mode> (mode, &int_mode)
17688 524175 : && GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE
17689 489832 : && (dwarf_version >= 4 || !dwarf_strict))
17690 : {
17691 489832 : loc_result = new_addr_loc_descr (rtl, dtprel_false);
17692 489832 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
17693 489832 : vec_safe_push (used_rtx_array, rtl);
17694 : }
17695 : break;
17696 :
17697 1723278 : case DEBUG_IMPLICIT_PTR:
17698 1723278 : loc_result = implicit_ptr_descriptor (rtl, 0);
17699 1723278 : break;
17700 :
17701 5557866 : case PLUS:
17702 5557866 : if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
17703 105429 : && CONST_INT_P (XEXP (rtl, 1)))
17704 : {
17705 105429 : loc_result
17706 105429 : = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
17707 105429 : break;
17708 : }
17709 : /* FALLTHRU */
17710 5452437 : do_default:
17711 7542965 : default:
17712 7542965 : if ((is_a <scalar_int_mode> (mode, &int_mode)
17713 7489128 : && GET_MODE (rtl) == int_mode
17714 7869663 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
17715 7441352 : && dwarf_version >= 4)
17716 104108 : || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
17717 : {
17718 : /* Value expression. */
17719 7539763 : loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
17720 7539763 : if (loc_result)
17721 14971872 : add_loc_descr (&loc_result,
17722 : new_loc_descr (DW_OP_stack_value, 0, 0));
17723 : }
17724 : break;
17725 : }
17726 :
17727 55076883 : return loc_result;
17728 : }
17729 :
17730 : /* We need to figure out what section we should use as the base for the
17731 : address ranges where a given location is valid.
17732 : 1. If this particular DECL has a section associated with it, use that.
17733 : 2. If this function has a section associated with it, use that.
17734 : 3. Otherwise, use the text section.
17735 : XXX: If you split a variable across multiple sections, we won't notice. */
17736 :
17737 : static const char *
17738 16340495 : secname_for_decl (const_tree decl)
17739 : {
17740 16340495 : const char *secname;
17741 :
17742 944374 : if (VAR_OR_FUNCTION_DECL_P (decl)
17743 15399566 : && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
17744 16343940 : && DECL_SECTION_NAME (decl))
17745 496 : secname = DECL_SECTION_NAME (decl);
17746 16339999 : else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
17747 : {
17748 14198524 : if (in_cold_section_p)
17749 : {
17750 3474527 : section *sec = current_function_section ();
17751 3474527 : if (sec->common.flags & SECTION_NAMED)
17752 3474527 : return sec->named.name;
17753 : }
17754 10723997 : secname = DECL_SECTION_NAME (current_function_decl);
17755 : }
17756 2141475 : else if (cfun && in_cold_section_p)
17757 63664 : secname = crtl->subsections.cold_section_label;
17758 : else
17759 : secname = text_section_label;
17760 :
17761 : return secname;
17762 : }
17763 :
17764 : /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
17765 :
17766 : static bool
17767 144576581 : decl_by_reference_p (tree decl)
17768 : {
17769 144576581 : return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
17770 : || VAR_P (decl))
17771 144576581 : && DECL_BY_REFERENCE (decl));
17772 : }
17773 :
17774 : /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17775 : for VARLOC. */
17776 :
17777 : static dw_loc_descr_ref
17778 27396893 : dw_loc_list_1 (tree loc, rtx varloc, int want_address,
17779 : enum var_init_status initialized)
17780 : {
17781 27396893 : int have_address = 0;
17782 27396893 : dw_loc_descr_ref descr;
17783 27396893 : machine_mode mode;
17784 :
17785 27396893 : if (want_address != 2)
17786 : {
17787 321444 : gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
17788 : /* Single part. */
17789 321444 : if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
17790 : {
17791 321444 : varloc = PAT_VAR_LOCATION_LOC (varloc);
17792 321444 : if (GET_CODE (varloc) == EXPR_LIST)
17793 0 : varloc = XEXP (varloc, 0);
17794 321444 : mode = GET_MODE (varloc);
17795 321444 : if (MEM_P (varloc))
17796 : {
17797 11995 : rtx addr = XEXP (varloc, 0);
17798 11995 : descr = mem_loc_descriptor (addr, get_address_mode (varloc),
17799 : mode, initialized);
17800 11995 : if (descr)
17801 : have_address = 1;
17802 : else
17803 : {
17804 0 : rtx x = avoid_constant_pool_reference (varloc);
17805 0 : if (x != varloc)
17806 0 : descr = mem_loc_descriptor (x, mode, VOIDmode,
17807 : initialized);
17808 : }
17809 : }
17810 : else
17811 309449 : descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
17812 : }
17813 : else
17814 : return 0;
17815 : }
17816 : else
17817 : {
17818 27075449 : if (GET_CODE (varloc) == VAR_LOCATION)
17819 27075449 : mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
17820 : else
17821 0 : mode = DECL_MODE (loc);
17822 27075449 : descr = loc_descriptor (varloc, mode, initialized);
17823 27075449 : have_address = 1;
17824 : }
17825 :
17826 27396893 : if (!descr)
17827 : return 0;
17828 :
17829 27156641 : if (want_address == 2 && !have_address
17830 0 : && (dwarf_version >= 4 || !dwarf_strict))
17831 : {
17832 0 : if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
17833 : {
17834 0 : expansion_failed (loc, NULL_RTX,
17835 : "DWARF address size mismatch");
17836 0 : return 0;
17837 : }
17838 0 : add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
17839 0 : have_address = 1;
17840 : }
17841 : /* Show if we can't fill the request for an address. */
17842 27156641 : if (want_address && !have_address)
17843 : {
17844 0 : expansion_failed (loc, NULL_RTX,
17845 : "Want address and only have value");
17846 0 : return 0;
17847 : }
17848 :
17849 : /* If we've got an address and don't want one, dereference. */
17850 27156641 : if (!want_address && have_address)
17851 : {
17852 11995 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
17853 11995 : enum dwarf_location_atom op;
17854 :
17855 14023 : if (size > DWARF2_ADDR_SIZE || size == -1)
17856 : {
17857 0 : expansion_failed (loc, NULL_RTX,
17858 : "DWARF address size mismatch");
17859 0 : return 0;
17860 : }
17861 14023 : else if (size == DWARF2_ADDR_SIZE)
17862 : op = DW_OP_deref;
17863 : else
17864 0 : op = DW_OP_deref_size;
17865 :
17866 23990 : add_loc_descr (&descr, new_loc_descr (op, size, 0));
17867 : }
17868 :
17869 27156641 : return descr;
17870 : }
17871 :
17872 : /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
17873 : if it is not possible. */
17874 :
17875 : static dw_loc_descr_ref
17876 4652794 : new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
17877 : {
17878 4652794 : if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
17879 4482552 : return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
17880 170242 : else if (dwarf_version >= 3 || !dwarf_strict)
17881 170242 : return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
17882 : else
17883 : return NULL;
17884 : }
17885 :
17886 : /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17887 : for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
17888 :
17889 : static dw_loc_descr_ref
17890 2961908 : dw_sra_loc_expr (tree decl, rtx loc)
17891 : {
17892 2961908 : rtx p;
17893 2961908 : unsigned HOST_WIDE_INT padsize = 0;
17894 2961908 : dw_loc_descr_ref descr, *descr_tail;
17895 2961908 : unsigned HOST_WIDE_INT decl_size;
17896 2961908 : rtx varloc;
17897 2961908 : enum var_init_status initialized;
17898 :
17899 2961908 : if (DECL_SIZE (decl) == NULL
17900 2961908 : || !tree_fits_uhwi_p (DECL_SIZE (decl)))
17901 : return NULL;
17902 :
17903 2961908 : decl_size = tree_to_uhwi (DECL_SIZE (decl));
17904 2961908 : descr = NULL;
17905 2961908 : descr_tail = &descr;
17906 :
17907 9569623 : for (p = loc; p; p = XEXP (p, 1))
17908 : {
17909 6608141 : unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
17910 6608141 : rtx loc_note = *decl_piece_varloc_ptr (p);
17911 6608141 : dw_loc_descr_ref cur_descr;
17912 6608141 : dw_loc_descr_ref *tail, last = NULL;
17913 6608141 : unsigned HOST_WIDE_INT opsize = 0;
17914 :
17915 6608141 : if (loc_note == NULL_RTX
17916 6168150 : || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
17917 : {
17918 3010345 : padsize += bitsize;
17919 3022936 : continue;
17920 : }
17921 3597796 : initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
17922 3597796 : varloc = NOTE_VAR_LOCATION (loc_note);
17923 3597796 : cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
17924 3597796 : if (cur_descr == NULL)
17925 : {
17926 12591 : padsize += bitsize;
17927 12591 : continue;
17928 : }
17929 :
17930 : /* Check that cur_descr either doesn't use
17931 : DW_OP_*piece operations, or their sum is equal
17932 : to bitsize. Otherwise we can't embed it. */
17933 8580202 : for (tail = &cur_descr; *tail != NULL;
17934 4994997 : tail = &(*tail)->dw_loc_next)
17935 4994997 : if ((*tail)->dw_loc_opc == DW_OP_piece)
17936 : {
17937 16772 : opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
17938 16772 : * BITS_PER_UNIT;
17939 16772 : last = *tail;
17940 : }
17941 4978225 : else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
17942 : {
17943 0 : opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
17944 0 : last = *tail;
17945 : }
17946 :
17947 3585205 : if (last != NULL && opsize != bitsize)
17948 : {
17949 0 : padsize += bitsize;
17950 : /* Discard the current piece of the descriptor and release any
17951 : addr_table entries it uses. */
17952 0 : remove_loc_list_addr_table_entries (cur_descr);
17953 0 : continue;
17954 : }
17955 :
17956 : /* If there is a hole, add DW_OP_*piece after empty DWARF
17957 : expression, which means that those bits are optimized out. */
17958 3585205 : if (padsize)
17959 : {
17960 496489 : if (padsize > decl_size)
17961 : {
17962 0 : remove_loc_list_addr_table_entries (cur_descr);
17963 426 : goto discard_descr;
17964 : }
17965 496489 : decl_size -= padsize;
17966 496489 : *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
17967 496489 : if (*descr_tail == NULL)
17968 : {
17969 0 : remove_loc_list_addr_table_entries (cur_descr);
17970 0 : goto discard_descr;
17971 : }
17972 496489 : descr_tail = &(*descr_tail)->dw_loc_next;
17973 496489 : padsize = 0;
17974 : }
17975 3585205 : *descr_tail = cur_descr;
17976 3585205 : descr_tail = tail;
17977 3585205 : if (bitsize > decl_size)
17978 0 : goto discard_descr;
17979 3585205 : decl_size -= bitsize;
17980 3585205 : if (last == NULL)
17981 : {
17982 3576819 : HOST_WIDE_INT offset = 0;
17983 3576819 : if (GET_CODE (varloc) == VAR_LOCATION
17984 3576819 : && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
17985 : {
17986 3576819 : varloc = PAT_VAR_LOCATION_LOC (varloc);
17987 3576819 : if (GET_CODE (varloc) == EXPR_LIST)
17988 0 : varloc = XEXP (varloc, 0);
17989 : }
17990 3580016 : do
17991 : {
17992 3580016 : if (GET_CODE (varloc) == CONST
17993 3579008 : || GET_CODE (varloc) == SIGN_EXTEND
17994 3578660 : || GET_CODE (varloc) == ZERO_EXTEND)
17995 1994 : varloc = XEXP (varloc, 0);
17996 3578022 : else if (GET_CODE (varloc) == SUBREG)
17997 1203 : varloc = SUBREG_REG (varloc);
17998 : else
17999 : break;
18000 : }
18001 : while (1);
18002 : /* DW_OP_bit_size offset should be zero for register
18003 : or implicit location descriptions and empty location
18004 : descriptions, but for memory addresses needs big endian
18005 : adjustment. */
18006 3576819 : if (MEM_P (varloc))
18007 : {
18008 1017498 : unsigned HOST_WIDE_INT memsize;
18009 1017501 : if (!poly_uint64 (MEM_SIZE (varloc)).is_constant (&memsize))
18010 426 : goto discard_descr;
18011 1017498 : memsize *= BITS_PER_UNIT;
18012 1017498 : if (memsize != bitsize)
18013 : {
18014 2702 : if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
18015 : && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
18016 : goto discard_descr;
18017 2702 : if (memsize < bitsize)
18018 426 : goto discard_descr;
18019 : if (BITS_BIG_ENDIAN)
18020 : offset = memsize - bitsize;
18021 : }
18022 : }
18023 :
18024 3576393 : *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
18025 3576393 : if (*descr_tail == NULL)
18026 0 : goto discard_descr;
18027 3576393 : descr_tail = &(*descr_tail)->dw_loc_next;
18028 : }
18029 : }
18030 :
18031 : /* If there were any non-empty expressions, add padding till the end of
18032 : the decl. */
18033 2961482 : if (descr != NULL && decl_size != 0)
18034 : {
18035 579912 : *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
18036 579912 : if (*descr_tail == NULL)
18037 0 : goto discard_descr;
18038 : }
18039 2961482 : return descr;
18040 :
18041 426 : discard_descr:
18042 : /* Discard the descriptor and release any addr_table entries it uses. */
18043 426 : remove_loc_list_addr_table_entries (descr);
18044 426 : return NULL;
18045 : }
18046 :
18047 : /* Return the dwarf representation of the location list LOC_LIST of
18048 : DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
18049 : function. */
18050 :
18051 : static dw_loc_list_ref
18052 13054861 : dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
18053 : {
18054 13054861 : const char *endname, *secname;
18055 13054861 : var_loc_view endview;
18056 13054861 : rtx varloc;
18057 13054861 : enum var_init_status initialized;
18058 13054861 : struct var_loc_node *node;
18059 13054861 : dw_loc_descr_ref descr;
18060 13054861 : char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
18061 13054861 : dw_loc_list_ref list = NULL;
18062 13054861 : dw_loc_list_ref *listp = &list;
18063 :
18064 : /* Now that we know what section we are using for a base,
18065 : actually construct the list of locations.
18066 : The first location information is what is passed to the
18067 : function that creates the location list, and the remaining
18068 : locations just get added on to that list.
18069 : Note that we only know the start address for a location
18070 : (IE location changes), so to build the range, we use
18071 : the range [current location start, next location start].
18072 : This means we have to special case the last node, and generate
18073 : a range of [last location start, end of function label]. */
18074 :
18075 13054861 : if (cfun && crtl->has_bb_partition)
18076 : {
18077 3538134 : bool save_in_cold_section_p = in_cold_section_p;
18078 3538134 : in_cold_section_p = first_function_block_is_cold;
18079 3538134 : if (loc_list->last_before_switch == NULL)
18080 255945 : in_cold_section_p = !in_cold_section_p;
18081 3538134 : secname = secname_for_decl (decl);
18082 3538134 : in_cold_section_p = save_in_cold_section_p;
18083 3538134 : }
18084 : else
18085 9516727 : secname = secname_for_decl (decl);
18086 :
18087 60403894 : for (node = loc_list->first; node; node = node->next)
18088 : {
18089 47349033 : bool range_across_switch = false;
18090 47349033 : if (GET_CODE (node->loc) == EXPR_LIST
18091 44392399 : || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
18092 : {
18093 26639523 : if (GET_CODE (node->loc) == EXPR_LIST)
18094 : {
18095 2956634 : descr = NULL;
18096 : /* This requires DW_OP_{,bit_}piece, which is not usable
18097 : inside DWARF expressions. */
18098 2956634 : if (want_address == 2)
18099 2956634 : descr = dw_sra_loc_expr (decl, node->loc);
18100 : }
18101 : else
18102 : {
18103 23682889 : initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
18104 23682889 : varloc = NOTE_VAR_LOCATION (node->loc);
18105 23682889 : descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
18106 : }
18107 26639523 : if (descr)
18108 : {
18109 : /* If section switch happens in between node->label
18110 : and node->next->label (or end of function) and
18111 : we can't emit it as a single entry list,
18112 : emit two ranges, first one ending at the end
18113 : of first partition and second one starting at the
18114 : beginning of second partition. */
18115 25331453 : if (node == loc_list->last_before_switch
18116 124139 : && (node != loc_list->first || loc_list->first->next
18117 : /* If we are to emit a view number, we will emit
18118 : a loclist rather than a single location
18119 : expression for the entire function (see
18120 : loc_list_has_views), so we have to split the
18121 : range that straddles across partitions. */
18122 7097 : || !ZERO_VIEW_P (node->view))
18123 25452935 : && current_function_decl)
18124 : {
18125 121482 : endname = cfun->fde->dw_fde_end;
18126 121482 : endview = 0;
18127 121482 : range_across_switch = true;
18128 : }
18129 : /* The variable has a location between NODE->LABEL and
18130 : NODE->NEXT->LABEL. */
18131 25209971 : else if (node->next)
18132 23859185 : endname = node->next->label, endview = node->next->view;
18133 : /* If the variable has a location at the last label
18134 : it keeps its location until the end of function. */
18135 1350786 : else if (!current_function_decl)
18136 : endname = text_end_label, endview = 0;
18137 : else
18138 : {
18139 1350786 : ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
18140 : current_function_funcdef_no);
18141 1350786 : endname = ggc_strdup (label_id);
18142 1350786 : endview = 0;
18143 : }
18144 :
18145 25331453 : *listp = new_loc_list (descr, node->label, node->view,
18146 : endname, endview, secname);
18147 25331453 : if (TREE_CODE (decl) == PARM_DECL
18148 3170318 : && node == loc_list->first
18149 907610 : && NOTE_P (node->loc)
18150 898905 : && strcmp (node->label, endname) == 0)
18151 411 : (*listp)->force = true;
18152 25331453 : listp = &(*listp)->dw_loc_next;
18153 : }
18154 : }
18155 :
18156 47349033 : if (cfun
18157 47349033 : && crtl->has_bb_partition
18158 12839930 : && node == loc_list->last_before_switch)
18159 : {
18160 3282189 : bool save_in_cold_section_p = in_cold_section_p;
18161 3282189 : in_cold_section_p = !first_function_block_is_cold;
18162 3282189 : secname = secname_for_decl (decl);
18163 3282189 : in_cold_section_p = save_in_cold_section_p;
18164 : }
18165 :
18166 47349033 : if (range_across_switch)
18167 : {
18168 121482 : if (GET_CODE (node->loc) == EXPR_LIST)
18169 5274 : descr = dw_sra_loc_expr (decl, node->loc);
18170 : else
18171 : {
18172 116208 : initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
18173 116208 : varloc = NOTE_VAR_LOCATION (node->loc);
18174 116208 : descr = dw_loc_list_1 (decl, varloc, want_address,
18175 : initialized);
18176 : }
18177 121482 : gcc_assert (descr);
18178 : /* The variable has a location between NODE->LABEL and
18179 : NODE->NEXT->LABEL. */
18180 121482 : if (node->next)
18181 85634 : endname = node->next->label, endview = node->next->view;
18182 : else
18183 35848 : endname = cfun->fde->dw_fde_second_end, endview = 0;
18184 121482 : *listp = new_loc_list (descr, cfun->fde->dw_fde_second_begin, 0,
18185 : endname, endview, secname);
18186 121482 : listp = &(*listp)->dw_loc_next;
18187 : }
18188 : }
18189 :
18190 : /* Try to avoid the overhead of a location list emitting a location
18191 : expression instead, but only if we didn't have more than one
18192 : location entry in the first place. If some entries were not
18193 : representable, we don't want to pretend a single entry that was
18194 : applies to the entire scope in which the variable is
18195 : available. */
18196 13054861 : if (list && loc_list->first->next)
18197 11771408 : gen_llsym (list);
18198 : else
18199 1283453 : maybe_gen_llsym (list);
18200 :
18201 13054861 : return list;
18202 : }
18203 :
18204 : /* Return true if the loc_list has only single element and thus
18205 : can be represented as location description. */
18206 :
18207 : static bool
18208 12898180 : single_element_loc_list_p (dw_loc_list_ref list)
18209 : {
18210 12898180 : gcc_assert (!list->dw_loc_next || list->ll_symbol);
18211 12898180 : return !list->ll_symbol;
18212 : }
18213 :
18214 : /* Duplicate a single element of location list. */
18215 :
18216 : static inline dw_loc_descr_ref
18217 43381 : copy_loc_descr (dw_loc_descr_ref ref)
18218 : {
18219 43381 : dw_loc_descr_ref copy = ggc_alloc<dw_loc_descr_node> ();
18220 43381 : memcpy (copy, ref, sizeof (dw_loc_descr_node));
18221 43381 : return copy;
18222 : }
18223 :
18224 : /* To each location in list LIST append loc descr REF. */
18225 :
18226 : static void
18227 257185 : add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
18228 : {
18229 257185 : dw_loc_descr_ref copy;
18230 257185 : add_loc_descr (&list->expr, ref);
18231 257185 : list = list->dw_loc_next;
18232 300566 : while (list)
18233 : {
18234 43381 : copy = copy_loc_descr (ref);
18235 43381 : add_loc_descr (&list->expr, copy);
18236 43381 : while (copy->dw_loc_next)
18237 0 : copy = copy->dw_loc_next = copy_loc_descr (copy->dw_loc_next);
18238 43381 : list = list->dw_loc_next;
18239 : }
18240 257185 : }
18241 :
18242 : /* To each location in list LIST prepend loc descr REF. */
18243 :
18244 : static void
18245 0 : prepend_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
18246 : {
18247 0 : dw_loc_descr_ref copy;
18248 0 : dw_loc_descr_ref ref_end = list->expr;
18249 0 : add_loc_descr (&ref, list->expr);
18250 0 : list->expr = ref;
18251 0 : list = list->dw_loc_next;
18252 0 : while (list)
18253 : {
18254 0 : dw_loc_descr_ref end = list->expr;
18255 0 : list->expr = copy = copy_loc_descr (ref);
18256 0 : while (copy->dw_loc_next != ref_end)
18257 0 : copy = copy->dw_loc_next = copy_loc_descr (copy->dw_loc_next);
18258 0 : copy->dw_loc_next = end;
18259 0 : list = list->dw_loc_next;
18260 : }
18261 0 : }
18262 :
18263 : /* Given two lists RET and LIST
18264 : produce location list that is result of adding expression in LIST
18265 : to expression in RET on each position in program.
18266 : Might be destructive on both RET and LIST.
18267 :
18268 : TODO: We handle only simple cases of RET or LIST having at most one
18269 : element. General case would involve sorting the lists in program order
18270 : and merging them that will need some additional work.
18271 : Adding that will improve quality of debug info especially for SRA-ed
18272 : structures. */
18273 :
18274 : static void
18275 48598 : add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
18276 : {
18277 48598 : if (!list)
18278 : return;
18279 48598 : if (!*ret)
18280 : {
18281 0 : *ret = list;
18282 0 : return;
18283 : }
18284 48598 : if (!list->dw_loc_next)
18285 : {
18286 48598 : add_loc_descr_to_each (*ret, list->expr);
18287 48598 : return;
18288 : }
18289 0 : if (!(*ret)->dw_loc_next)
18290 : {
18291 0 : prepend_loc_descr_to_each (list, (*ret)->expr);
18292 0 : *ret = list;
18293 0 : return;
18294 : }
18295 0 : expansion_failed (NULL_TREE, NULL_RTX,
18296 : "Don't know how to merge two non-trivial"
18297 : " location lists.\n");
18298 0 : *ret = NULL;
18299 0 : return;
18300 : }
18301 :
18302 : /* LOC is constant expression. Try a luck, look it up in constant
18303 : pool and return its loc_descr of its address. */
18304 :
18305 : static dw_loc_descr_ref
18306 11935 : cst_pool_loc_descr (tree loc)
18307 : {
18308 : /* Get an RTL for this, if something has been emitted. */
18309 11935 : rtx rtl = lookup_constant_def (loc);
18310 :
18311 11935 : if (!rtl || !MEM_P (rtl))
18312 : {
18313 0 : gcc_assert (!rtl);
18314 : return 0;
18315 : }
18316 10186 : gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
18317 :
18318 : /* TODO: We might get more coverage if we was actually delaying expansion
18319 : of all expressions till end of compilation when constant pools are fully
18320 : populated. */
18321 10186 : if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
18322 : {
18323 0 : expansion_failed (loc, NULL_RTX,
18324 : "CST value in contant pool but not marked.");
18325 0 : return 0;
18326 : }
18327 10186 : return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
18328 10186 : GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
18329 : }
18330 :
18331 : /* Return dw_loc_list representing address of addr_expr LOC
18332 : by looking for inner INDIRECT_REF expression and turning
18333 : it into simple arithmetics.
18334 :
18335 : See loc_list_from_tree for the meaning of CONTEXT. */
18336 :
18337 : static dw_loc_list_ref
18338 786 : loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
18339 : loc_descr_context *context)
18340 : {
18341 786 : tree obj, offset;
18342 786 : poly_int64 bitsize, bitpos, bytepos;
18343 786 : machine_mode mode;
18344 786 : int unsignedp, reversep, volatilep = 0;
18345 786 : dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
18346 :
18347 786 : obj = get_inner_reference (TREE_OPERAND (loc, 0),
18348 : &bitsize, &bitpos, &offset, &mode,
18349 : &unsignedp, &reversep, &volatilep);
18350 786 : STRIP_NOPS (obj);
18351 1572 : if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
18352 : {
18353 0 : expansion_failed (loc, NULL_RTX, "bitfield access");
18354 0 : return 0;
18355 : }
18356 786 : if (!INDIRECT_REF_P (obj))
18357 : {
18358 786 : expansion_failed (obj,
18359 : NULL_RTX, "no indirect ref in inner refrence");
18360 786 : return 0;
18361 : }
18362 0 : if (!offset && known_eq (bitpos, 0))
18363 0 : list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1,
18364 : context);
18365 0 : else if (toplev
18366 0 : && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
18367 0 : && (dwarf_version >= 4 || !dwarf_strict))
18368 : {
18369 0 : list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0, context);
18370 0 : if (!list_ret)
18371 786 : return 0;
18372 0 : if (offset)
18373 : {
18374 : /* Variable offset. */
18375 0 : list_ret1 = loc_list_from_tree (offset, 0, context);
18376 0 : if (list_ret1 == 0)
18377 : return 0;
18378 0 : add_loc_list (&list_ret, list_ret1);
18379 0 : if (!list_ret)
18380 : return 0;
18381 0 : add_loc_descr_to_each (list_ret,
18382 : new_loc_descr (DW_OP_plus, 0, 0));
18383 : }
18384 0 : HOST_WIDE_INT value;
18385 0 : if (bytepos.is_constant (&value) && value > 0)
18386 0 : add_loc_descr_to_each (list_ret,
18387 : new_loc_descr (DW_OP_plus_uconst, value, 0));
18388 0 : else if (maybe_ne (bytepos, 0))
18389 0 : loc_list_plus_const (list_ret, bytepos);
18390 0 : add_loc_descr_to_each (list_ret,
18391 : new_loc_descr (DW_OP_stack_value, 0, 0));
18392 : }
18393 0 : return list_ret;
18394 : }
18395 :
18396 : /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
18397 : all operations from LOC are nops, move to the last one. Insert in NOPS all
18398 : operations that are skipped. */
18399 :
18400 : static void
18401 56526662 : loc_descr_to_next_no_nop (dw_loc_descr_ref &loc,
18402 : hash_set<dw_loc_descr_ref> &nops)
18403 : {
18404 56536394 : while (loc->dw_loc_next != NULL && loc->dw_loc_opc == DW_OP_nop)
18405 : {
18406 9732 : nops.add (loc);
18407 9732 : loc = loc->dw_loc_next;
18408 : }
18409 56526662 : }
18410 :
18411 : /* Helper for loc_descr_without_nops: free the location description operation
18412 : P. */
18413 :
18414 : bool
18415 4866 : free_loc_descr (const dw_loc_descr_ref &loc, void *data ATTRIBUTE_UNUSED)
18416 : {
18417 4866 : ggc_free (loc);
18418 4866 : return true;
18419 : }
18420 :
18421 : /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
18422 : finishes LOC. */
18423 :
18424 : static void
18425 26190064 : loc_descr_without_nops (dw_loc_descr_ref &loc)
18426 : {
18427 26190064 : if (loc->dw_loc_opc == DW_OP_nop && loc->dw_loc_next == NULL)
18428 0 : return;
18429 :
18430 : /* Set of all DW_OP_nop operations we remove. */
18431 26190064 : hash_set<dw_loc_descr_ref> nops;
18432 :
18433 : /* First, strip all prefix NOP operations in order to keep the head of the
18434 : operations list. */
18435 26190064 : loc_descr_to_next_no_nop (loc, nops);
18436 :
18437 81236423 : for (dw_loc_descr_ref cur = loc; cur != NULL;)
18438 : {
18439 : /* For control flow operations: strip "prefix" nops in destination
18440 : labels. */
18441 55046359 : if (cur->dw_loc_oprnd1.val_class == dw_val_class_loc)
18442 1480303 : loc_descr_to_next_no_nop (cur->dw_loc_oprnd1.v.val_loc, nops);
18443 55046359 : if (cur->dw_loc_oprnd2.val_class == dw_val_class_loc)
18444 0 : loc_descr_to_next_no_nop (cur->dw_loc_oprnd2.v.val_loc, nops);
18445 :
18446 : /* Do the same for the operations that follow, then move to the next
18447 : iteration. */
18448 55046359 : if (cur->dw_loc_next != NULL)
18449 28856295 : loc_descr_to_next_no_nop (cur->dw_loc_next, nops);
18450 55046359 : cur = cur->dw_loc_next;
18451 : }
18452 :
18453 26194930 : nops.traverse<void *, free_loc_descr> (NULL);
18454 26190064 : }
18455 :
18456 :
18457 : struct dwarf_procedure_info;
18458 :
18459 : /* Helper structure for location descriptions generation. */
18460 : struct loc_descr_context
18461 : {
18462 : /* The type that is implicitly referenced by DW_OP_push_object_address, or
18463 : NULL_TREE if DW_OP_push_object_address in invalid for this location
18464 : description. This is used when processing PLACEHOLDER_EXPR nodes. */
18465 : tree context_type;
18466 : /* The ..._DECL node that should be translated as a
18467 : DW_OP_push_object_address operation. */
18468 : tree base_decl;
18469 : /* Information about the DWARF procedure we are currently generating. NULL if
18470 : we are not generating a DWARF procedure. */
18471 : struct dwarf_procedure_info *dpi;
18472 : /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
18473 : by consumer. Used for DW_TAG_generic_subrange attributes. */
18474 : bool placeholder_arg;
18475 : /* True if PLACEHOLDER_EXPR has been seen. */
18476 : bool placeholder_seen;
18477 : /* True if strict preservation of signedness has been requested. */
18478 : bool strict_signedness;
18479 : };
18480 :
18481 : /* DWARF procedures generation
18482 :
18483 : DWARF expressions (aka. location descriptions) are used to encode variable
18484 : things such as sizes or offsets. Such computations can have redundant parts
18485 : that can be factorized in order to reduce the size of the output debug
18486 : information. This is the whole point of DWARF procedures.
18487 :
18488 : Thanks to stor-layout.cc, size and offset expressions in GENERIC trees are
18489 : already factorized into functions ("size functions") in order to handle very
18490 : big and complex types. Such functions are quite simple: they have integral
18491 : arguments, they return an integral result and their body contains only a
18492 : return statement with arithmetic expressions. This is the only kind of
18493 : function we are interested in translating into DWARF procedures, here.
18494 :
18495 : DWARF expressions and DWARF procedure are executed using a stack, so we have
18496 : to define some calling convention for them to interact. Let's say that:
18497 :
18498 : - Before calling a DWARF procedure, DWARF expressions must push on the stack
18499 : all arguments in reverse order (right-to-left) so that when the DWARF
18500 : procedure execution starts, the first argument is the top of the stack.
18501 :
18502 : - Then, when returning, the DWARF procedure must have consumed all arguments
18503 : on the stack, must have pushed the result and touched nothing else.
18504 :
18505 : - Each integral argument and the result are integral types can be hold in a
18506 : single stack slot.
18507 :
18508 : - We call "frame offset" the number of stack slots that are "under DWARF
18509 : procedure control": it includes the arguments slots, the temporaries and
18510 : the result slot. Thus, it is equal to the number of arguments when the
18511 : procedure execution starts and must be equal to one (the result) when it
18512 : returns. */
18513 :
18514 : /* Helper structure used when generating operations for a DWARF procedure. */
18515 : struct dwarf_procedure_info
18516 : {
18517 : /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
18518 : currently translated. */
18519 : tree fndecl;
18520 : /* The number of arguments FNDECL takes. */
18521 : unsigned args_count;
18522 : };
18523 :
18524 : /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
18525 : LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
18526 : equate it to this DIE. */
18527 :
18528 : static dw_die_ref
18529 0 : new_dwarf_proc_die (dw_loc_descr_ref location, tree fndecl,
18530 : dw_die_ref parent_die)
18531 : {
18532 0 : dw_die_ref dwarf_proc_die;
18533 :
18534 0 : if ((dwarf_version < 3 && dwarf_strict)
18535 0 : || location == NULL)
18536 : return NULL;
18537 :
18538 0 : dwarf_proc_die = new_die (DW_TAG_dwarf_procedure, parent_die, fndecl);
18539 0 : if (fndecl)
18540 0 : equate_decl_number_to_die (fndecl, dwarf_proc_die);
18541 0 : add_AT_loc (dwarf_proc_die, DW_AT_location, location);
18542 0 : return dwarf_proc_die;
18543 : }
18544 :
18545 : /* Return whether TYPE is a supported type as a DWARF procedure argument
18546 : type or return type (we handle only scalar types and pointer types that
18547 : aren't wider than the DWARF expression evaluation stack). */
18548 :
18549 : static bool
18550 36 : is_handled_procedure_type (tree type)
18551 : {
18552 36 : return ((INTEGRAL_TYPE_P (type)
18553 36 : || TREE_CODE (type) == OFFSET_TYPE
18554 0 : || TREE_CODE (type) == POINTER_TYPE)
18555 36 : && int_size_in_bytes (type) <= DWARF2_ADDR_SIZE);
18556 : }
18557 :
18558 : /* Helper for resolve_args_picking: do the same but stop when coming across
18559 : visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
18560 : offset *before* evaluating the corresponding operation. */
18561 :
18562 : static bool
18563 3093 : resolve_args_picking_1 (dw_loc_descr_ref loc, unsigned initial_frame_offset,
18564 : struct dwarf_procedure_info *dpi,
18565 : hash_map<dw_loc_descr_ref, unsigned> &frame_offsets)
18566 : {
18567 : /* The "frame_offset" identifier is already used to name a macro... */
18568 3093 : unsigned frame_offset_ = initial_frame_offset;
18569 3093 : dw_loc_descr_ref l;
18570 :
18571 29996 : for (l = loc; l != NULL;)
18572 : {
18573 26903 : bool existed;
18574 26903 : unsigned &l_frame_offset = frame_offsets.get_or_insert (l, &existed);
18575 :
18576 : /* If we already met this node, there is nothing to compute anymore. */
18577 26903 : if (existed)
18578 : {
18579 : /* Make sure that the stack size is consistent wherever the execution
18580 : flow comes from. */
18581 0 : gcc_assert ((unsigned) l_frame_offset == frame_offset_);
18582 0 : break;
18583 : }
18584 26903 : l_frame_offset = frame_offset_;
18585 :
18586 : /* If needed, relocate the picking offset with respect to the frame
18587 : offset. */
18588 26903 : if (l->dw_loc_frame_offset_rel)
18589 : {
18590 3093 : unsigned HOST_WIDE_INT off;
18591 3093 : switch (l->dw_loc_opc)
18592 : {
18593 3093 : case DW_OP_pick:
18594 3093 : off = l->dw_loc_oprnd1.v.val_unsigned;
18595 3093 : break;
18596 : case DW_OP_dup:
18597 : off = 0;
18598 : break;
18599 0 : case DW_OP_over:
18600 0 : off = 1;
18601 0 : break;
18602 0 : default:
18603 0 : gcc_unreachable ();
18604 : }
18605 : /* frame_offset_ is the size of the current stack frame, including
18606 : incoming arguments. Besides, the arguments are pushed
18607 : right-to-left. Thus, in order to access the Nth argument from
18608 : this operation node, the picking has to skip temporaries *plus*
18609 : one stack slot per argument (0 for the first one, 1 for the second
18610 : one, etc.).
18611 :
18612 : The targetted argument number (N) is already set as the operand,
18613 : and the number of temporaries can be computed with:
18614 : frame_offsets_ - dpi->args_count */
18615 3093 : off += frame_offset_ - dpi->args_count;
18616 :
18617 : /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
18618 3093 : if (off > 255)
18619 0 : return false;
18620 :
18621 3093 : if (off == 0)
18622 : {
18623 0 : l->dw_loc_opc = DW_OP_dup;
18624 0 : l->dw_loc_oprnd1.v.val_unsigned = 0;
18625 : }
18626 3093 : else if (off == 1)
18627 : {
18628 3093 : l->dw_loc_opc = DW_OP_over;
18629 3093 : l->dw_loc_oprnd1.v.val_unsigned = 0;
18630 : }
18631 : else
18632 : {
18633 0 : l->dw_loc_opc = DW_OP_pick;
18634 0 : l->dw_loc_oprnd1.v.val_unsigned = off;
18635 : }
18636 : }
18637 :
18638 : /* Update frame_offset according to the effect the current operation has
18639 : on the stack. */
18640 26903 : switch (l->dw_loc_opc)
18641 : {
18642 : case DW_OP_deref:
18643 : case DW_OP_swap:
18644 : case DW_OP_rot:
18645 : case DW_OP_abs:
18646 : case DW_OP_neg:
18647 : case DW_OP_not:
18648 : case DW_OP_plus_uconst:
18649 : case DW_OP_skip:
18650 : case DW_OP_reg0:
18651 : case DW_OP_reg1:
18652 : case DW_OP_reg2:
18653 : case DW_OP_reg3:
18654 : case DW_OP_reg4:
18655 : case DW_OP_reg5:
18656 : case DW_OP_reg6:
18657 : case DW_OP_reg7:
18658 : case DW_OP_reg8:
18659 : case DW_OP_reg9:
18660 : case DW_OP_reg10:
18661 : case DW_OP_reg11:
18662 : case DW_OP_reg12:
18663 : case DW_OP_reg13:
18664 : case DW_OP_reg14:
18665 : case DW_OP_reg15:
18666 : case DW_OP_reg16:
18667 : case DW_OP_reg17:
18668 : case DW_OP_reg18:
18669 : case DW_OP_reg19:
18670 : case DW_OP_reg20:
18671 : case DW_OP_reg21:
18672 : case DW_OP_reg22:
18673 : case DW_OP_reg23:
18674 : case DW_OP_reg24:
18675 : case DW_OP_reg25:
18676 : case DW_OP_reg26:
18677 : case DW_OP_reg27:
18678 : case DW_OP_reg28:
18679 : case DW_OP_reg29:
18680 : case DW_OP_reg30:
18681 : case DW_OP_reg31:
18682 : case DW_OP_bregx:
18683 : case DW_OP_piece:
18684 : case DW_OP_deref_size:
18685 : case DW_OP_nop:
18686 : case DW_OP_bit_piece:
18687 : case DW_OP_implicit_value:
18688 : case DW_OP_stack_value:
18689 : case DW_OP_deref_type:
18690 : case DW_OP_convert:
18691 : case DW_OP_reinterpret:
18692 : case DW_OP_GNU_deref_type:
18693 : case DW_OP_GNU_convert:
18694 : case DW_OP_GNU_reinterpret:
18695 : break;
18696 :
18697 10310 : case DW_OP_addr:
18698 10310 : case DW_OP_const1u:
18699 10310 : case DW_OP_const1s:
18700 10310 : case DW_OP_const2u:
18701 10310 : case DW_OP_const2s:
18702 10310 : case DW_OP_const4u:
18703 10310 : case DW_OP_const4s:
18704 10310 : case DW_OP_const8u:
18705 10310 : case DW_OP_const8s:
18706 10310 : case DW_OP_constu:
18707 10310 : case DW_OP_consts:
18708 10310 : case DW_OP_dup:
18709 10310 : case DW_OP_over:
18710 10310 : case DW_OP_pick:
18711 10310 : case DW_OP_lit0:
18712 10310 : case DW_OP_lit1:
18713 10310 : case DW_OP_lit2:
18714 10310 : case DW_OP_lit3:
18715 10310 : case DW_OP_lit4:
18716 10310 : case DW_OP_lit5:
18717 10310 : case DW_OP_lit6:
18718 10310 : case DW_OP_lit7:
18719 10310 : case DW_OP_lit8:
18720 10310 : case DW_OP_lit9:
18721 10310 : case DW_OP_lit10:
18722 10310 : case DW_OP_lit11:
18723 10310 : case DW_OP_lit12:
18724 10310 : case DW_OP_lit13:
18725 10310 : case DW_OP_lit14:
18726 10310 : case DW_OP_lit15:
18727 10310 : case DW_OP_lit16:
18728 10310 : case DW_OP_lit17:
18729 10310 : case DW_OP_lit18:
18730 10310 : case DW_OP_lit19:
18731 10310 : case DW_OP_lit20:
18732 10310 : case DW_OP_lit21:
18733 10310 : case DW_OP_lit22:
18734 10310 : case DW_OP_lit23:
18735 10310 : case DW_OP_lit24:
18736 10310 : case DW_OP_lit25:
18737 10310 : case DW_OP_lit26:
18738 10310 : case DW_OP_lit27:
18739 10310 : case DW_OP_lit28:
18740 10310 : case DW_OP_lit29:
18741 10310 : case DW_OP_lit30:
18742 10310 : case DW_OP_lit31:
18743 10310 : case DW_OP_breg0:
18744 10310 : case DW_OP_breg1:
18745 10310 : case DW_OP_breg2:
18746 10310 : case DW_OP_breg3:
18747 10310 : case DW_OP_breg4:
18748 10310 : case DW_OP_breg5:
18749 10310 : case DW_OP_breg6:
18750 10310 : case DW_OP_breg7:
18751 10310 : case DW_OP_breg8:
18752 10310 : case DW_OP_breg9:
18753 10310 : case DW_OP_breg10:
18754 10310 : case DW_OP_breg11:
18755 10310 : case DW_OP_breg12:
18756 10310 : case DW_OP_breg13:
18757 10310 : case DW_OP_breg14:
18758 10310 : case DW_OP_breg15:
18759 10310 : case DW_OP_breg16:
18760 10310 : case DW_OP_breg17:
18761 10310 : case DW_OP_breg18:
18762 10310 : case DW_OP_breg19:
18763 10310 : case DW_OP_breg20:
18764 10310 : case DW_OP_breg21:
18765 10310 : case DW_OP_breg22:
18766 10310 : case DW_OP_breg23:
18767 10310 : case DW_OP_breg24:
18768 10310 : case DW_OP_breg25:
18769 10310 : case DW_OP_breg26:
18770 10310 : case DW_OP_breg27:
18771 10310 : case DW_OP_breg28:
18772 10310 : case DW_OP_breg29:
18773 10310 : case DW_OP_breg30:
18774 10310 : case DW_OP_breg31:
18775 10310 : case DW_OP_fbreg:
18776 10310 : case DW_OP_push_object_address:
18777 10310 : case DW_OP_call_frame_cfa:
18778 10310 : case DW_OP_GNU_variable_value:
18779 10310 : case DW_OP_GNU_addr_index:
18780 10310 : case DW_OP_GNU_const_index:
18781 10310 : ++frame_offset_;
18782 10310 : break;
18783 :
18784 7217 : case DW_OP_drop:
18785 7217 : case DW_OP_xderef:
18786 7217 : case DW_OP_and:
18787 7217 : case DW_OP_div:
18788 7217 : case DW_OP_minus:
18789 7217 : case DW_OP_mod:
18790 7217 : case DW_OP_mul:
18791 7217 : case DW_OP_or:
18792 7217 : case DW_OP_plus:
18793 7217 : case DW_OP_shl:
18794 7217 : case DW_OP_shr:
18795 7217 : case DW_OP_shra:
18796 7217 : case DW_OP_xor:
18797 7217 : case DW_OP_bra:
18798 7217 : case DW_OP_eq:
18799 7217 : case DW_OP_ge:
18800 7217 : case DW_OP_gt:
18801 7217 : case DW_OP_le:
18802 7217 : case DW_OP_lt:
18803 7217 : case DW_OP_ne:
18804 7217 : case DW_OP_regx:
18805 7217 : case DW_OP_xderef_size:
18806 7217 : --frame_offset_;
18807 7217 : break;
18808 :
18809 0 : case DW_OP_call2:
18810 0 : case DW_OP_call4:
18811 0 : case DW_OP_call_ref:
18812 0 : {
18813 0 : dw_die_ref dwarf_proc = l->dw_loc_oprnd1.v.val_die_ref.die;
18814 0 : int *stack_usage = dwarf_proc_stack_usage_map->get (dwarf_proc);
18815 :
18816 0 : if (stack_usage == NULL)
18817 0 : return false;
18818 0 : frame_offset_ += *stack_usage;
18819 0 : break;
18820 : }
18821 :
18822 0 : case DW_OP_implicit_pointer:
18823 0 : case DW_OP_entry_value:
18824 0 : case DW_OP_const_type:
18825 0 : case DW_OP_regval_type:
18826 0 : case DW_OP_form_tls_address:
18827 0 : case DW_OP_GNU_push_tls_address:
18828 0 : case DW_OP_GNU_uninit:
18829 0 : case DW_OP_GNU_encoded_addr:
18830 0 : case DW_OP_GNU_implicit_pointer:
18831 0 : case DW_OP_GNU_entry_value:
18832 0 : case DW_OP_GNU_const_type:
18833 0 : case DW_OP_GNU_regval_type:
18834 0 : case DW_OP_GNU_parameter_ref:
18835 : /* loc_list_from_tree will probably not output these operations for
18836 : size functions, so assume they will not appear here. */
18837 : /* Fall through... */
18838 :
18839 0 : default:
18840 0 : gcc_unreachable ();
18841 : }
18842 :
18843 : /* Now, follow the control flow (except subroutine calls). */
18844 26903 : switch (l->dw_loc_opc)
18845 : {
18846 0 : case DW_OP_bra:
18847 0 : if (!resolve_args_picking_1 (l->dw_loc_next, frame_offset_, dpi,
18848 : frame_offsets))
18849 : return false;
18850 : /* Fall through. */
18851 :
18852 0 : case DW_OP_skip:
18853 0 : l = l->dw_loc_oprnd1.v.val_loc;
18854 0 : break;
18855 :
18856 : case DW_OP_stack_value:
18857 : return true;
18858 :
18859 26903 : default:
18860 26903 : l = l->dw_loc_next;
18861 26903 : break;
18862 : }
18863 : }
18864 :
18865 : return true;
18866 : }
18867 :
18868 : /* Make a DFS over operations reachable through LOC (i.e. follow branch
18869 : operations) in order to resolve the operand of DW_OP_pick operations that
18870 : target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
18871 : offset *before* LOC is executed. Return if all relocations were
18872 : successful. */
18873 :
18874 : static bool
18875 3093 : resolve_args_picking (dw_loc_descr_ref loc, unsigned initial_frame_offset,
18876 : struct dwarf_procedure_info *dpi)
18877 : {
18878 : /* Associate to all visited operations the frame offset *before* evaluating
18879 : this operation. */
18880 3093 : hash_map<dw_loc_descr_ref, unsigned> frame_offsets;
18881 :
18882 3093 : return
18883 3093 : resolve_args_picking_1 (loc, initial_frame_offset, dpi, frame_offsets);
18884 3093 : }
18885 :
18886 : /* Try to generate a DWARF procedure that computes the same result as FNDECL.
18887 : Return NULL if it is not possible. */
18888 :
18889 : static dw_die_ref
18890 36 : function_to_dwarf_procedure (tree fndecl)
18891 : {
18892 36 : struct dwarf_procedure_info dpi;
18893 36 : struct loc_descr_context ctx = {
18894 : NULL_TREE, /* context_type */
18895 : NULL_TREE, /* base_decl */
18896 : &dpi, /* dpi */
18897 : false, /* placeholder_arg */
18898 : false, /* placeholder_seen */
18899 : true /* strict_signedness */
18900 36 : };
18901 36 : dw_die_ref dwarf_proc_die;
18902 36 : tree tree_body = DECL_SAVED_TREE (fndecl);
18903 36 : dw_loc_descr_ref loc_body, epilogue;
18904 :
18905 36 : tree cursor;
18906 36 : unsigned i;
18907 :
18908 : /* Do not generate multiple DWARF procedures for the same function
18909 : declaration. */
18910 36 : dwarf_proc_die = lookup_decl_die (fndecl);
18911 36 : if (dwarf_proc_die != NULL)
18912 : return dwarf_proc_die;
18913 :
18914 : /* DWARF procedures are available starting with the DWARFv3 standard. */
18915 32 : if (dwarf_version < 3 && dwarf_strict)
18916 : return NULL;
18917 :
18918 : /* We handle only functions for which we still have a body, that return a
18919 : supported type and that takes arguments with supported types. Note that
18920 : there is no point translating functions that return nothing. */
18921 32 : if (tree_body == NULL_TREE
18922 0 : || DECL_RESULT (fndecl) == NULL_TREE
18923 32 : || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl))))
18924 32 : return NULL;
18925 :
18926 0 : for (cursor = DECL_ARGUMENTS (fndecl);
18927 0 : cursor != NULL_TREE;
18928 0 : cursor = TREE_CHAIN (cursor))
18929 0 : if (!is_handled_procedure_type (TREE_TYPE (cursor)))
18930 : return NULL;
18931 :
18932 : /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
18933 0 : if (TREE_CODE (tree_body) != RETURN_EXPR)
18934 : return NULL;
18935 0 : tree_body = TREE_OPERAND (tree_body, 0);
18936 0 : if (TREE_CODE (tree_body) != MODIFY_EXPR
18937 0 : || TREE_OPERAND (tree_body, 0) != DECL_RESULT (fndecl))
18938 : return NULL;
18939 0 : tree_body = TREE_OPERAND (tree_body, 1);
18940 :
18941 : /* Try to translate the body expression itself. Note that this will probably
18942 : cause an infinite recursion if its call graph has a cycle. This is very
18943 : unlikely for size functions, however, so don't bother with such things at
18944 : the moment. */
18945 0 : dpi.fndecl = fndecl;
18946 0 : dpi.args_count = list_length (DECL_ARGUMENTS (fndecl));
18947 0 : loc_body = loc_descriptor_from_tree (tree_body, 0, &ctx);
18948 0 : if (!loc_body)
18949 : return NULL;
18950 :
18951 : /* After evaluating all operands in "loc_body", we should still have on the
18952 : stack all arguments plus the desired function result (top of the stack).
18953 : Generate code in order to keep only the result in our stack frame. */
18954 : epilogue = NULL;
18955 0 : for (i = 0; i < dpi.args_count; ++i)
18956 : {
18957 0 : dw_loc_descr_ref op_couple = new_loc_descr (DW_OP_swap, 0, 0);
18958 0 : op_couple->dw_loc_next = new_loc_descr (DW_OP_drop, 0, 0);
18959 0 : op_couple->dw_loc_next->dw_loc_next = epilogue;
18960 0 : epilogue = op_couple;
18961 : }
18962 0 : add_loc_descr (&loc_body, epilogue);
18963 0 : if (!resolve_args_picking (loc_body, dpi.args_count, &dpi))
18964 : return NULL;
18965 :
18966 : /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
18967 : because they are considered useful. Now there is an epilogue, they are
18968 : not anymore, so give it another try. */
18969 0 : loc_descr_without_nops (loc_body);
18970 :
18971 : /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
18972 : a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
18973 : though, given that size functions do not come from source, so they should
18974 : not have a dedicated DW_TAG_subprogram DIE. */
18975 0 : dwarf_proc_die
18976 0 : = new_dwarf_proc_die (loc_body, fndecl,
18977 0 : get_context_die (DECL_CONTEXT (fndecl)));
18978 :
18979 : /* The called DWARF procedure consumes one stack slot per argument and
18980 : returns one stack slot. */
18981 0 : dwarf_proc_stack_usage_map->put (dwarf_proc_die, 1 - dpi.args_count);
18982 :
18983 0 : return dwarf_proc_die;
18984 : }
18985 :
18986 : /* Helper function for loc_list_from_tree. Perform OP binary op,
18987 : but after converting arguments to type_die, afterwards convert
18988 : back to unsigned. */
18989 :
18990 : static dw_loc_list_ref
18991 0 : typed_binop_from_tree (enum dwarf_location_atom op, tree loc,
18992 : dw_die_ref type_die, scalar_int_mode mode,
18993 : struct loc_descr_context *context)
18994 : {
18995 0 : dw_loc_list_ref op0, op1;
18996 0 : dw_loc_descr_ref cvt, binop;
18997 :
18998 0 : if (type_die == NULL)
18999 : return NULL;
19000 :
19001 0 : op0 = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
19002 0 : op1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
19003 0 : if (op0 == NULL || op1 == NULL)
19004 : return NULL;
19005 :
19006 0 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
19007 0 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19008 0 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
19009 0 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
19010 0 : add_loc_descr_to_each (op0, cvt);
19011 :
19012 0 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
19013 0 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19014 0 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
19015 0 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
19016 0 : add_loc_descr_to_each (op1, cvt);
19017 :
19018 0 : add_loc_list (&op0, op1);
19019 0 : if (op0 == NULL)
19020 : return NULL;
19021 :
19022 0 : binop = new_loc_descr (op, 0, 0);
19023 0 : convert_descriptor_to_mode (mode, binop);
19024 0 : add_loc_descr_to_each (op0, binop);
19025 :
19026 0 : return op0;
19027 : }
19028 :
19029 : /* Generate Dwarf location list representing LOC.
19030 : If WANT_ADDRESS is false, expression computing LOC will be computed
19031 : If WANT_ADDRESS is 1, expression computing address of LOC will be returned
19032 : if WANT_ADDRESS is 2, expression computing address useable in location
19033 : will be returned (i.e. DW_OP_reg can be used
19034 : to refer to register values).
19035 :
19036 : CONTEXT provides information to customize the location descriptions
19037 : generation. Its context_type field specifies what type is implicitly
19038 : referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
19039 : will not be generated.
19040 :
19041 : Its DPI field determines whether we are generating a DWARF expression for a
19042 : DWARF procedure, so PARM_DECL references are processed specifically.
19043 :
19044 : If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
19045 : and dpi fields were null. */
19046 :
19047 : static dw_loc_list_ref
19048 16300296 : loc_list_from_tree_1 (tree loc, int want_address,
19049 : struct loc_descr_context *context)
19050 : {
19051 16497250 : dw_loc_descr_ref ret = NULL, ret1 = NULL;
19052 16497250 : dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
19053 16497250 : int have_address = 0;
19054 16497250 : enum dwarf_location_atom op;
19055 :
19056 : /* ??? Most of the time we do not take proper care for sign/zero
19057 : extending the values properly. Hopefully this won't be a real
19058 : problem... */
19059 :
19060 16497250 : if (context != NULL
19061 389454 : && context->base_decl == loc
19062 97500 : && want_address == 0)
19063 : {
19064 97500 : if (dwarf_version >= 3 || !dwarf_strict)
19065 97500 : return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
19066 97500 : NULL, 0, NULL, 0, NULL);
19067 : else
19068 : return NULL;
19069 : }
19070 :
19071 16399750 : switch (TREE_CODE (loc))
19072 : {
19073 0 : case ERROR_MARK:
19074 0 : expansion_failed (loc, NULL_RTX, "ERROR_MARK");
19075 0 : return 0;
19076 :
19077 6186 : case PLACEHOLDER_EXPR:
19078 : /* This case involves extracting fields from an object to determine the
19079 : position of other fields. It is supposed to appear only as the first
19080 : operand of COMPONENT_REF nodes and to reference precisely the type
19081 : that the context allows or its enclosing type. */
19082 6186 : if (context != NULL
19083 6186 : && (TREE_TYPE (loc) == context->context_type
19084 6186 : || TREE_TYPE (loc) == TYPE_CONTEXT (context->context_type))
19085 6186 : && want_address >= 1)
19086 : {
19087 0 : if (dwarf_version >= 3 || !dwarf_strict)
19088 : {
19089 0 : ret = new_loc_descr (DW_OP_push_object_address, 0, 0);
19090 0 : have_address = 1;
19091 0 : break;
19092 : }
19093 : else
19094 : return NULL;
19095 : }
19096 : /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
19097 : the single argument passed by consumer. */
19098 6186 : else if (context != NULL
19099 6186 : && context->placeholder_arg
19100 6186 : && INTEGRAL_TYPE_P (TREE_TYPE (loc))
19101 12372 : && want_address == 0)
19102 : {
19103 6186 : ret = new_loc_descr (DW_OP_pick, 0, 0);
19104 6186 : ret->dw_loc_frame_offset_rel = 1;
19105 6186 : context->placeholder_seen = true;
19106 6186 : break;
19107 : }
19108 : else
19109 0 : expansion_failed (loc, NULL_RTX,
19110 : "PLACEHOLDER_EXPR for an unexpected type");
19111 0 : break;
19112 :
19113 36 : case CALL_EXPR:
19114 36 : {
19115 36 : tree callee = get_callee_fndecl (loc);
19116 36 : dw_die_ref dwarf_proc;
19117 :
19118 36 : if (callee
19119 36 : && is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee)))
19120 72 : && (dwarf_proc = function_to_dwarf_procedure (callee)))
19121 : {
19122 : /* DWARF procedures are used for size functions, which are built
19123 : when size expressions contain conditional constructs, so we
19124 : request strict preservation of signedness for comparisons. */
19125 4 : bool old_strict_signedness;
19126 4 : if (context)
19127 : {
19128 0 : old_strict_signedness = context->strict_signedness;
19129 0 : context->strict_signedness = true;
19130 : }
19131 :
19132 : /* Evaluate arguments right-to-left so that the first argument
19133 : will be the top-most one on the stack. */
19134 4 : for (int i = call_expr_nargs (loc) - 1; i >= 0; --i)
19135 : {
19136 0 : tree arg = CALL_EXPR_ARG (loc, i);
19137 0 : ret1 = loc_descriptor_from_tree (arg, 0, context);
19138 0 : if (!ret1)
19139 : {
19140 0 : expansion_failed (arg, NULL_RTX, "CALL_EXPR argument");
19141 0 : return NULL;
19142 : }
19143 0 : add_loc_descr (&ret, ret1);
19144 : }
19145 :
19146 4 : ret1 = new_loc_descr (DW_OP_call4, 0, 0);
19147 4 : ret1->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19148 4 : ret1->dw_loc_oprnd1.v.val_die_ref.die = dwarf_proc;
19149 4 : ret1->dw_loc_oprnd1.v.val_die_ref.external = 0;
19150 4 : add_loc_descr (&ret, ret1);
19151 4 : if (context)
19152 0 : context->strict_signedness = old_strict_signedness;
19153 : }
19154 : else
19155 32 : expansion_failed (loc, NULL_RTX, "CALL_EXPR target");
19156 : break;
19157 : }
19158 :
19159 0 : case PREINCREMENT_EXPR:
19160 0 : case PREDECREMENT_EXPR:
19161 0 : case POSTINCREMENT_EXPR:
19162 0 : case POSTDECREMENT_EXPR:
19163 0 : expansion_failed (loc, NULL_RTX, "PRE/POST INCREMENT/DECREMENT");
19164 : /* There are no opcodes for these operations. */
19165 0 : return 0;
19166 :
19167 787 : case ADDR_EXPR:
19168 : /* If we already want an address, see if there is INDIRECT_REF inside
19169 : e.g. for &this->field. */
19170 787 : if (want_address)
19171 : {
19172 1572 : list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
19173 786 : (loc, want_address == 2, context);
19174 786 : if (list_ret)
19175 : have_address = 1;
19176 786 : else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
19177 786 : && (ret = cst_pool_loc_descr (loc)))
19178 : have_address = 1;
19179 : }
19180 : /* Otherwise, process the argument and look for the address. */
19181 787 : if (!list_ret && !ret)
19182 787 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 1, context);
19183 : else
19184 : {
19185 0 : if (want_address)
19186 0 : expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
19187 0 : return NULL;
19188 : }
19189 787 : break;
19190 :
19191 14784823 : case VAR_DECL:
19192 14784823 : if (DECL_THREAD_LOCAL_P (loc))
19193 : {
19194 473 : rtx rtl;
19195 473 : enum dwarf_location_atom tls_op;
19196 473 : enum dtprel_bool dtprel = dtprel_false;
19197 :
19198 473 : if (targetm.have_tls)
19199 : {
19200 : /* If this is not defined, we have no way to emit the
19201 : data. */
19202 473 : if (!targetm.asm_out.output_dwarf_dtprel)
19203 : return 0;
19204 :
19205 : /* The way DW_OP_GNU_push_tls_address is specified, we
19206 : can only look up addresses of objects in the current
19207 : module. We used DW_OP_addr as first op, but that's
19208 : wrong, because DW_OP_addr is relocated by the debug
19209 : info consumer, while DW_OP_GNU_push_tls_address
19210 : operand shouldn't be. */
19211 473 : if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
19212 : return 0;
19213 473 : dtprel = dtprel_true;
19214 : /* We check for DWARF 5 here because gdb did not implement
19215 : DW_OP_form_tls_address until after 7.12. */
19216 473 : tls_op = (dwarf_version >= 5 ? DW_OP_form_tls_address
19217 : : DW_OP_GNU_push_tls_address);
19218 : }
19219 : else
19220 : {
19221 0 : if (!targetm.emutls.debug_form_tls_address
19222 0 : || !(dwarf_version >= 3 || !dwarf_strict))
19223 : return 0;
19224 : /* We stuffed the control variable into the DECL_VALUE_EXPR
19225 : to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
19226 : no longer appear in gimple code. We used the control
19227 : variable in specific so that we could pick it up here. */
19228 0 : loc = DECL_VALUE_EXPR (loc);
19229 0 : tls_op = DW_OP_form_tls_address;
19230 : }
19231 :
19232 473 : rtl = rtl_for_decl_location (loc);
19233 473 : if (rtl == NULL_RTX)
19234 : return 0;
19235 :
19236 473 : if (!MEM_P (rtl))
19237 : return 0;
19238 473 : rtl = XEXP (rtl, 0);
19239 473 : if (! CONSTANT_P (rtl))
19240 : return 0;
19241 :
19242 473 : ret = new_addr_loc_descr (rtl, dtprel);
19243 473 : ret1 = new_loc_descr (tls_op, 0, 0);
19244 473 : add_loc_descr (&ret, ret1);
19245 :
19246 473 : have_address = 1;
19247 473 : break;
19248 : }
19249 : /* FALLTHRU */
19250 :
19251 15818077 : case PARM_DECL:
19252 268 : if (context != NULL && context->dpi != NULL
19253 15818077 : && DECL_CONTEXT (loc) == context->dpi->fndecl)
19254 : {
19255 : /* We are generating code for a DWARF procedure and we want to access
19256 : one of its arguments: find the appropriate argument offset and let
19257 : the resolve_args_picking pass compute the offset that complies
19258 : with the stack frame size. */
19259 0 : unsigned i = 0;
19260 0 : tree cursor;
19261 :
19262 0 : for (cursor = DECL_ARGUMENTS (context->dpi->fndecl);
19263 0 : cursor != NULL_TREE && cursor != loc;
19264 0 : cursor = TREE_CHAIN (cursor), ++i)
19265 : ;
19266 : /* If we are translating a DWARF procedure, all referenced parameters
19267 : must belong to the current function. */
19268 0 : gcc_assert (cursor != NULL_TREE);
19269 :
19270 0 : ret = new_loc_descr (DW_OP_pick, i, 0);
19271 0 : ret->dw_loc_frame_offset_rel = 1;
19272 0 : break;
19273 : }
19274 : /* FALLTHRU */
19275 :
19276 15820392 : case RESULT_DECL:
19277 15820392 : if (DECL_HAS_VALUE_EXPR_P (loc))
19278 : {
19279 143318 : tree value_expr = DECL_VALUE_EXPR (loc);
19280 :
19281 : /* Non-local frame structures are DECL_IGNORED_P variables so we need
19282 : to wait until they get an RTX in order to reference them. */
19283 143318 : if (early_dwarf
19284 21 : && TREE_CODE (value_expr) == COMPONENT_REF
19285 21 : && VAR_P (TREE_OPERAND (value_expr, 0))
19286 143337 : && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr, 0)))
19287 : ;
19288 : else
19289 : return loc_list_from_tree_1 (value_expr, want_address, context);
19290 : }
19291 :
19292 : /* FALLTHRU */
19293 :
19294 15677249 : case FUNCTION_DECL:
19295 15677249 : {
19296 15677249 : rtx rtl;
19297 15677249 : var_loc_list *loc_list = lookup_decl_loc (loc);
19298 :
19299 15677249 : if (loc_list && loc_list->first)
19300 : {
19301 13054861 : list_ret = dw_loc_list (loc_list, loc, want_address);
19302 13054861 : have_address = want_address != 0;
19303 13054861 : break;
19304 : }
19305 2622388 : rtl = rtl_for_decl_location (loc);
19306 2622388 : if (rtl == NULL_RTX)
19307 : {
19308 1931882 : if (TREE_CODE (loc) != FUNCTION_DECL
19309 1931881 : && early_dwarf
19310 9689 : && want_address != 1
19311 9689 : && ! DECL_IGNORED_P (loc)
19312 9400 : && (INTEGRAL_TYPE_P (TREE_TYPE (loc))
19313 62 : || POINTER_TYPE_P (TREE_TYPE (loc)))
19314 9400 : && TYPE_MODE (TREE_TYPE (loc)) != BLKmode
19315 1950674 : && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc)))
19316 9396 : <= DWARF2_ADDR_SIZE))
19317 : {
19318 9396 : dw_die_ref ref = lookup_decl_die (loc);
19319 9396 : if (ref)
19320 : {
19321 5585 : ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
19322 5585 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19323 5585 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
19324 5585 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
19325 : }
19326 3811 : else if (current_function_decl
19327 3811 : && DECL_CONTEXT (loc) == current_function_decl)
19328 : {
19329 3648 : ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
19330 3648 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
19331 3648 : ret->dw_loc_oprnd1.v.val_decl_ref = loc;
19332 : }
19333 : break;
19334 : }
19335 1922486 : expansion_failed (loc, NULL_RTX, "DECL has no RTL");
19336 1922486 : return 0;
19337 : }
19338 690506 : else if (CONST_INT_P (rtl))
19339 : {
19340 0 : HOST_WIDE_INT val = INTVAL (rtl);
19341 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
19342 0 : val &= GET_MODE_MASK (DECL_MODE (loc));
19343 0 : ret = int_loc_descriptor (val);
19344 : }
19345 690506 : else if (GET_CODE (rtl) == CONST_STRING)
19346 : {
19347 0 : expansion_failed (loc, NULL_RTX, "CONST_STRING");
19348 0 : return 0;
19349 : }
19350 690506 : else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
19351 0 : ret = new_addr_loc_descr (rtl, dtprel_false);
19352 : else
19353 : {
19354 690506 : machine_mode mode, mem_mode;
19355 :
19356 : /* Certain constructs can only be represented at top-level. */
19357 690506 : if (want_address == 2)
19358 : {
19359 670434 : ret = loc_descriptor (rtl, VOIDmode,
19360 : VAR_INIT_STATUS_INITIALIZED);
19361 670434 : have_address = 1;
19362 : }
19363 : else
19364 : {
19365 20072 : mode = GET_MODE (rtl);
19366 20072 : mem_mode = VOIDmode;
19367 20072 : if (MEM_P (rtl))
19368 : {
19369 5562 : mem_mode = mode;
19370 5562 : mode = get_address_mode (rtl);
19371 5562 : rtl = XEXP (rtl, 0);
19372 5562 : have_address = 1;
19373 : }
19374 20072 : ret = mem_loc_descriptor (rtl, mode, mem_mode,
19375 : VAR_INIT_STATUS_INITIALIZED);
19376 : }
19377 690506 : if (!ret)
19378 47110 : expansion_failed (loc, rtl,
19379 : "failed to produce loc descriptor for rtl");
19380 : }
19381 : }
19382 : break;
19383 :
19384 5253 : case MEM_REF:
19385 5253 : if (!integer_zerop (TREE_OPERAND (loc, 1)))
19386 : {
19387 0 : have_address = 1;
19388 0 : goto do_plus;
19389 : }
19390 : /* Fallthru. */
19391 242553 : case INDIRECT_REF:
19392 242553 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19393 242553 : have_address = 1;
19394 242553 : break;
19395 :
19396 : case TARGET_MEM_REF:
19397 : case SSA_NAME:
19398 : case DEBUG_EXPR_DECL:
19399 : return NULL;
19400 :
19401 0 : case COMPOUND_EXPR:
19402 0 : return loc_list_from_tree_1 (TREE_OPERAND (loc, 1), want_address,
19403 0 : context);
19404 :
19405 53655 : CASE_CONVERT:
19406 53655 : case VIEW_CONVERT_EXPR:
19407 53655 : case SAVE_EXPR:
19408 53655 : case MODIFY_EXPR:
19409 53655 : case NON_LVALUE_EXPR:
19410 53655 : return loc_list_from_tree_1 (TREE_OPERAND (loc, 0), want_address,
19411 53655 : context);
19412 :
19413 120596 : case COMPONENT_REF:
19414 120596 : case BIT_FIELD_REF:
19415 120596 : case ARRAY_REF:
19416 120596 : case ARRAY_RANGE_REF:
19417 120596 : case REALPART_EXPR:
19418 120596 : case IMAGPART_EXPR:
19419 120596 : {
19420 120596 : tree obj, offset;
19421 120596 : poly_int64 bitsize, bitpos, bytepos;
19422 120596 : machine_mode mode;
19423 120596 : int unsignedp, reversep, volatilep = 0;
19424 :
19425 120596 : obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
19426 : &unsignedp, &reversep, &volatilep);
19427 :
19428 120596 : gcc_assert (obj != loc);
19429 :
19430 241192 : list_ret = loc_list_from_tree_1 (obj,
19431 : want_address == 2
19432 103843 : && known_eq (bitpos, 0)
19433 46485 : && !offset ? 2 : 1,
19434 : context);
19435 : /* TODO: We can extract value of the small expression via shifting even
19436 : for nonzero bitpos. */
19437 120596 : if (list_ret == 0)
19438 80573 : return 0;
19439 40102 : if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
19440 : {
19441 0 : expansion_failed (loc, NULL_RTX, "bitfield access");
19442 0 : return 0;
19443 : }
19444 :
19445 40102 : if (offset != NULL_TREE)
19446 : {
19447 : /* Variable offset. */
19448 79 : list_ret1 = loc_list_from_tree_1 (offset, 0, context);
19449 79 : if (list_ret1 == 0)
19450 : return 0;
19451 0 : add_loc_list (&list_ret, list_ret1);
19452 0 : if (!list_ret)
19453 : return 0;
19454 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
19455 : }
19456 :
19457 40023 : HOST_WIDE_INT value;
19458 40023 : if (bytepos.is_constant (&value) && value > 0)
19459 29911 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst,
19460 : value, 0));
19461 10112 : else if (maybe_ne (bytepos, 0))
19462 0 : loc_list_plus_const (list_ret, bytepos);
19463 :
19464 40023 : have_address = 1;
19465 40023 : break;
19466 : }
19467 :
19468 19030 : case INTEGER_CST:
19469 18993 : if ((want_address || !tree_fits_shwi_p (loc))
19470 19034 : && (ret = cst_pool_loc_descr (loc)))
19471 : have_address = 1;
19472 19030 : else if (want_address == 2
19473 37 : && tree_fits_shwi_p (loc)
19474 19067 : && (ret = address_of_int_loc_descriptor
19475 37 : (int_size_in_bytes (TREE_TYPE (loc)),
19476 : tree_to_shwi (loc))))
19477 : have_address = 1;
19478 18993 : else if (tree_fits_shwi_p (loc))
19479 18989 : ret = int_loc_descriptor (tree_to_shwi (loc));
19480 4 : else if (tree_fits_uhwi_p (loc))
19481 4 : ret = uint_loc_descriptor (tree_to_uhwi (loc));
19482 : else
19483 : {
19484 0 : expansion_failed (loc, NULL_RTX,
19485 : "Integer operand is not host integer");
19486 0 : return 0;
19487 : }
19488 : break;
19489 :
19490 0 : case POLY_INT_CST:
19491 0 : {
19492 0 : if (want_address)
19493 : {
19494 0 : expansion_failed (loc, NULL_RTX,
19495 : "constant address with a runtime component");
19496 0 : return 0;
19497 : }
19498 0 : poly_int64 value;
19499 0 : if (!poly_int_tree_p (loc, &value))
19500 : {
19501 0 : expansion_failed (loc, NULL_RTX, "constant too big");
19502 0 : return 0;
19503 : }
19504 0 : ret = int_loc_descriptor (value);
19505 : }
19506 0 : break;
19507 :
19508 11109 : case CONSTRUCTOR:
19509 11109 : case REAL_CST:
19510 11109 : case STRING_CST:
19511 11109 : case COMPLEX_CST:
19512 11109 : if ((ret = cst_pool_loc_descr (loc)))
19513 : have_address = 1;
19514 923 : else if (TREE_CODE (loc) == CONSTRUCTOR)
19515 : {
19516 41 : tree type = TREE_TYPE (loc);
19517 41 : unsigned HOST_WIDE_INT size = int_size_in_bytes (type);
19518 41 : unsigned HOST_WIDE_INT offset = 0;
19519 41 : unsigned HOST_WIDE_INT cnt;
19520 41 : constructor_elt *ce;
19521 :
19522 41 : if (TREE_CODE (type) == RECORD_TYPE)
19523 : {
19524 : /* This is very limited, but it's enough to output
19525 : pointers to member functions, as long as the
19526 : referenced function is defined in the current
19527 : translation unit. */
19528 115 : FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc), cnt, ce)
19529 : {
19530 78 : tree val = ce->value;
19531 :
19532 78 : tree field = ce->index;
19533 :
19534 78 : if (val)
19535 78 : STRIP_NOPS (val);
19536 :
19537 156 : if (!field || DECL_BIT_FIELD (field))
19538 : {
19539 0 : expansion_failed (loc, NULL_RTX,
19540 : "bitfield in record type constructor");
19541 0 : size = offset = (unsigned HOST_WIDE_INT)-1;
19542 0 : ret = NULL;
19543 0 : break;
19544 : }
19545 :
19546 78 : HOST_WIDE_INT fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
19547 78 : unsigned HOST_WIDE_INT pos = int_byte_position (field);
19548 78 : gcc_assert (pos + fieldsize <= size);
19549 78 : if (pos < offset)
19550 : {
19551 0 : expansion_failed (loc, NULL_RTX,
19552 : "out-of-order fields in record constructor");
19553 0 : size = offset = (unsigned HOST_WIDE_INT)-1;
19554 0 : ret = NULL;
19555 0 : break;
19556 : }
19557 78 : if (pos > offset)
19558 : {
19559 0 : ret1 = new_loc_descr (DW_OP_piece, pos - offset, 0);
19560 0 : add_loc_descr (&ret, ret1);
19561 0 : offset = pos;
19562 : }
19563 78 : if (val && fieldsize != 0)
19564 : {
19565 78 : ret1 = loc_descriptor_from_tree (val, want_address, context);
19566 78 : if (!ret1)
19567 : {
19568 4 : expansion_failed (loc, NULL_RTX,
19569 : "unsupported expression in field");
19570 4 : size = offset = (unsigned HOST_WIDE_INT)-1;
19571 4 : ret = NULL;
19572 4 : break;
19573 : }
19574 74 : add_loc_descr (&ret, ret1);
19575 : }
19576 74 : if (fieldsize)
19577 : {
19578 74 : ret1 = new_loc_descr (DW_OP_piece, fieldsize, 0);
19579 74 : add_loc_descr (&ret, ret1);
19580 74 : offset = pos + fieldsize;
19581 : }
19582 : }
19583 :
19584 41 : if (offset != size)
19585 : {
19586 0 : ret1 = new_loc_descr (DW_OP_piece, size - offset, 0);
19587 0 : add_loc_descr (&ret, ret1);
19588 0 : offset = size;
19589 : }
19590 :
19591 41 : have_address = !!want_address;
19592 : }
19593 : else
19594 0 : expansion_failed (loc, NULL_RTX,
19595 : "constructor of non-record type");
19596 : }
19597 : else
19598 : /* We can construct small constants here using int_loc_descriptor. */
19599 882 : expansion_failed (loc, NULL_RTX,
19600 : "constructor or constant not in constant pool");
19601 : break;
19602 :
19603 4 : case TRUTH_AND_EXPR:
19604 4 : case TRUTH_ANDIF_EXPR:
19605 4 : case BIT_AND_EXPR:
19606 4 : op = DW_OP_and;
19607 4 : goto do_binop;
19608 :
19609 0 : case TRUTH_XOR_EXPR:
19610 0 : case BIT_XOR_EXPR:
19611 0 : op = DW_OP_xor;
19612 0 : goto do_binop;
19613 :
19614 0 : case TRUTH_OR_EXPR:
19615 0 : case TRUTH_ORIF_EXPR:
19616 0 : case BIT_IOR_EXPR:
19617 0 : op = DW_OP_or;
19618 0 : goto do_binop;
19619 :
19620 0 : case EXACT_DIV_EXPR:
19621 0 : case FLOOR_DIV_EXPR:
19622 0 : case TRUNC_DIV_EXPR:
19623 : /* Turn a divide by a power of 2 into a shift when possible. */
19624 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc))
19625 0 : && tree_fits_uhwi_p (TREE_OPERAND (loc, 1)))
19626 : {
19627 0 : const int log2 = exact_log2 (tree_to_uhwi (TREE_OPERAND (loc, 1)));
19628 0 : if (log2 > 0)
19629 : {
19630 0 : list_ret
19631 0 : = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19632 0 : if (list_ret == 0)
19633 : return 0;
19634 :
19635 0 : add_loc_descr_to_each (list_ret, uint_loc_descriptor (log2));
19636 0 : add_loc_descr_to_each (list_ret,
19637 : new_loc_descr (DW_OP_shr, 0, 0));
19638 0 : break;
19639 : }
19640 : }
19641 :
19642 : /* fall through */
19643 :
19644 0 : case CEIL_DIV_EXPR:
19645 0 : case ROUND_DIV_EXPR:
19646 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
19647 : {
19648 0 : const enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19649 0 : scalar_int_mode int_mode;
19650 :
19651 0 : if ((dwarf_strict && dwarf_version < 5)
19652 0 : || !is_a <scalar_int_mode> (mode, &int_mode))
19653 3028087 : return 0;
19654 :
19655 : /* We can use a signed divide if the sign bit is not set. */
19656 0 : if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
19657 : {
19658 0 : op = DW_OP_div;
19659 0 : goto do_binop;
19660 : }
19661 :
19662 0 : list_ret = typed_binop_from_tree (DW_OP_div, loc,
19663 : base_type_for_mode (int_mode, 1),
19664 : int_mode, context);
19665 0 : break;
19666 : }
19667 0 : op = DW_OP_div;
19668 0 : goto do_binop;
19669 :
19670 5054 : case MINUS_EXPR:
19671 5054 : op = DW_OP_minus;
19672 5054 : goto do_binop;
19673 :
19674 0 : case FLOOR_MOD_EXPR:
19675 0 : case CEIL_MOD_EXPR:
19676 0 : case ROUND_MOD_EXPR:
19677 0 : case TRUNC_MOD_EXPR:
19678 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
19679 : {
19680 0 : op = DW_OP_mod;
19681 0 : goto do_binop;
19682 : }
19683 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19684 0 : list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
19685 0 : if (list_ret == 0 || list_ret1 == 0)
19686 : return 0;
19687 :
19688 0 : add_loc_list (&list_ret, list_ret1);
19689 0 : if (list_ret == 0)
19690 : return 0;
19691 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
19692 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
19693 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
19694 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
19695 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
19696 0 : break;
19697 :
19698 24749 : case MULT_EXPR:
19699 24749 : op = DW_OP_mul;
19700 24749 : goto do_binop;
19701 :
19702 0 : case LSHIFT_EXPR:
19703 0 : op = DW_OP_shl;
19704 0 : goto do_binop;
19705 :
19706 0 : case RSHIFT_EXPR:
19707 0 : op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
19708 0 : goto do_binop;
19709 :
19710 87308 : case POINTER_PLUS_EXPR:
19711 87308 : case PLUS_EXPR:
19712 87308 : do_plus:
19713 87308 : if (tree_fits_shwi_p (TREE_OPERAND (loc, 1)))
19714 : {
19715 : /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
19716 : smarter to encode their opposite. The DW_OP_plus_uconst operation
19717 : takes 1 + X bytes, X being the size of the ULEB128 addend. On the
19718 : other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
19719 : bytes, Y being the size of the operation that pushes the opposite
19720 : of the addend. So let's choose the smallest representation. */
19721 76046 : const tree tree_addend = TREE_OPERAND (loc, 1);
19722 76046 : offset_int wi_addend;
19723 76046 : HOST_WIDE_INT shwi_addend;
19724 76046 : dw_loc_descr_ref loc_naddend;
19725 :
19726 76046 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19727 76046 : if (list_ret == 0)
19728 50 : return 0;
19729 :
19730 : /* Try to get the literal to push. It is the opposite of the addend,
19731 : so as we rely on wrapping during DWARF evaluation, first decode
19732 : the literal as a "DWARF-sized" signed number. */
19733 75996 : wi_addend = wi::to_offset (tree_addend);
19734 76732 : wi_addend = wi::sext (wi_addend, DWARF2_ADDR_SIZE * 8);
19735 75996 : shwi_addend = wi_addend.to_shwi ();
19736 75996 : loc_naddend = (shwi_addend != INTTYPE_MINIMUM (HOST_WIDE_INT))
19737 75996 : ? int_loc_descriptor (-shwi_addend)
19738 : : NULL;
19739 :
19740 0 : if (loc_naddend != NULL
19741 151992 : && ((unsigned) size_of_uleb128 (shwi_addend)
19742 75996 : > size_of_loc_descr (loc_naddend)))
19743 : {
19744 16 : add_loc_descr_to_each (list_ret, loc_naddend);
19745 16 : add_loc_descr_to_each (list_ret,
19746 : new_loc_descr (DW_OP_minus, 0, 0));
19747 : }
19748 : else
19749 : {
19750 151960 : for (dw_loc_descr_ref loc_cur = loc_naddend; loc_cur != NULL; )
19751 : {
19752 75980 : loc_naddend = loc_cur;
19753 75980 : loc_cur = loc_cur->dw_loc_next;
19754 75980 : ggc_free (loc_naddend);
19755 : }
19756 151960 : loc_list_plus_const (list_ret, wi_addend.to_shwi ());
19757 : }
19758 75996 : break;
19759 : }
19760 :
19761 11262 : op = DW_OP_plus;
19762 11262 : goto do_binop;
19763 :
19764 0 : case LE_EXPR:
19765 0 : op = DW_OP_le;
19766 0 : goto do_comp_binop;
19767 :
19768 0 : case GE_EXPR:
19769 0 : op = DW_OP_ge;
19770 0 : goto do_comp_binop;
19771 :
19772 0 : case LT_EXPR:
19773 0 : op = DW_OP_lt;
19774 0 : goto do_comp_binop;
19775 :
19776 0 : case GT_EXPR:
19777 0 : op = DW_OP_gt;
19778 0 : goto do_comp_binop;
19779 :
19780 0 : do_comp_binop:
19781 0 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
19782 : {
19783 0 : const enum machine_mode mode
19784 0 : = TYPE_MODE (TREE_TYPE (TREE_OPERAND (loc, 0)));
19785 0 : scalar_int_mode int_mode;
19786 :
19787 : /* We can use a signed comparison if the sign bit is not set. */
19788 0 : if (is_a <scalar_int_mode> (mode, &int_mode)
19789 0 : && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
19790 0 : goto do_binop;
19791 :
19792 0 : list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
19793 0 : list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
19794 0 : list_ret = loc_list_from_uint_comparison (list_ret, list_ret1,
19795 0 : TREE_CODE (loc));
19796 0 : break;
19797 : }
19798 : else
19799 0 : goto do_binop;
19800 :
19801 0 : case EQ_EXPR:
19802 0 : op = DW_OP_eq;
19803 0 : goto do_binop;
19804 :
19805 7662 : case NE_EXPR:
19806 7662 : op = DW_OP_ne;
19807 7662 : goto do_binop;
19808 :
19809 48731 : do_binop:
19810 48731 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19811 48731 : list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
19812 48731 : if (list_ret == 0 || list_ret1 == 0)
19813 : return 0;
19814 :
19815 48598 : add_loc_list (&list_ret, list_ret1);
19816 48598 : if (list_ret == 0)
19817 : return 0;
19818 :
19819 48598 : add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
19820 48598 : break;
19821 :
19822 0 : case TRUTH_NOT_EXPR:
19823 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19824 0 : if (list_ret == 0)
19825 : return 0;
19826 :
19827 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_lit0, 0, 0));
19828 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_eq, 0, 0));
19829 0 : break;
19830 :
19831 0 : case BIT_NOT_EXPR:
19832 0 : op = DW_OP_not;
19833 0 : goto do_unop;
19834 :
19835 0 : case ABS_EXPR:
19836 0 : op = DW_OP_abs;
19837 0 : goto do_unop;
19838 :
19839 0 : case NEGATE_EXPR:
19840 0 : op = DW_OP_neg;
19841 0 : goto do_unop;
19842 :
19843 0 : do_unop:
19844 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19845 0 : if (list_ret == 0)
19846 : return 0;
19847 :
19848 0 : add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
19849 0 : break;
19850 :
19851 0 : case MIN_EXPR:
19852 0 : case MAX_EXPR:
19853 0 : {
19854 0 : const enum tree_code code =
19855 0 : TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
19856 :
19857 0 : loc = build3 (COND_EXPR, TREE_TYPE (loc),
19858 : build2 (code, integer_type_node,
19859 0 : TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
19860 0 : TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
19861 : }
19862 :
19863 : /* fall through */
19864 :
19865 0 : case COND_EXPR:
19866 0 : {
19867 0 : dw_loc_descr_ref lhs
19868 0 : = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0, context);
19869 0 : dw_loc_list_ref rhs
19870 0 : = loc_list_from_tree_1 (TREE_OPERAND (loc, 2), 0, context);
19871 0 : dw_loc_descr_ref bra_node, jump_node, tmp;
19872 :
19873 : /* DW_OP_bra is branch-on-nonzero so avoid doing useless work. */
19874 0 : if (TREE_CODE (TREE_OPERAND (loc, 0)) == NE_EXPR
19875 0 : && integer_zerop (TREE_OPERAND (TREE_OPERAND (loc, 0), 1)))
19876 0 : list_ret
19877 0 : = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0),
19878 : 0, context);
19879 : /* Likewise, swap the operands for a logically negated condition. */
19880 0 : else if (TREE_CODE (TREE_OPERAND (loc, 0)) == TRUTH_NOT_EXPR)
19881 : {
19882 0 : lhs = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0, context);
19883 0 : rhs = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
19884 0 : list_ret
19885 0 : = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0),
19886 : 0, context);
19887 : }
19888 : else
19889 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19890 0 : if (list_ret == 0 || lhs == 0 || rhs == 0)
19891 : return 0;
19892 :
19893 0 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
19894 0 : add_loc_descr_to_each (list_ret, bra_node);
19895 :
19896 0 : add_loc_list (&list_ret, rhs);
19897 0 : jump_node = new_loc_descr (DW_OP_skip, 0, 0);
19898 0 : add_loc_descr_to_each (list_ret, jump_node);
19899 :
19900 0 : add_loc_descr_to_each (list_ret, lhs);
19901 0 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
19902 0 : bra_node->dw_loc_oprnd1.v.val_loc = lhs;
19903 :
19904 : /* ??? Need a node to point the skip at. Use a nop. */
19905 0 : tmp = new_loc_descr (DW_OP_nop, 0, 0);
19906 0 : add_loc_descr_to_each (list_ret, tmp);
19907 0 : jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
19908 0 : jump_node->dw_loc_oprnd1.v.val_loc = tmp;
19909 : }
19910 0 : break;
19911 :
19912 : case FIX_TRUNC_EXPR:
19913 : return 0;
19914 :
19915 0 : case COMPOUND_LITERAL_EXPR:
19916 0 : return loc_list_from_tree_1 (COMPOUND_LITERAL_EXPR_DECL (loc),
19917 0 : 0, context);
19918 :
19919 0 : default:
19920 : /* Leave front-end specific codes as simply unknown. This comes
19921 : up, for instance, with the C STMT_EXPR. */
19922 0 : if ((unsigned int) TREE_CODE (loc)
19923 : >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
19924 : {
19925 0 : expansion_failed (loc, NULL_RTX,
19926 : "language specific tree node");
19927 0 : return 0;
19928 : }
19929 :
19930 : /* Otherwise this is a generic code; we should just lists all of
19931 : these explicitly. We forgot one. */
19932 0 : if (flag_checking)
19933 0 : gcc_unreachable ();
19934 :
19935 : /* In a release build, we want to degrade gracefully: better to
19936 : generate incomplete debugging information than to crash. */
19937 : return NULL;
19938 : }
19939 :
19940 14199554 : if (!ret && !list_ret)
19941 : return 0;
19942 :
19943 : /* Implement wrap-around arithmetics for small integer types. */
19944 13174863 : if ((TREE_CODE (loc) == PLUS_EXPR
19945 : || TREE_CODE (loc) == MINUS_EXPR
19946 13174863 : || TREE_CODE (loc) == MULT_EXPR
19947 : || TREE_CODE (loc) == NEGATE_EXPR
19948 : || TREE_CODE (loc) == LSHIFT_EXPR)
19949 40966 : && INTEGRAL_TYPE_P (TREE_TYPE (loc))
19950 40966 : && TYPE_OVERFLOW_WRAPS (TREE_TYPE (loc)))
19951 : {
19952 12404 : const enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19953 12404 : scalar_int_mode int_mode;
19954 :
19955 12404 : if (is_a <scalar_int_mode> (mode, &int_mode)
19956 13268 : && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
19957 : {
19958 0 : const unsigned HOST_WIDE_INT mask
19959 0 : = (HOST_WIDE_INT_1U << GET_MODE_BITSIZE (int_mode)) - 1;
19960 0 : add_loc_descr_to_each (list_ret, uint_loc_descriptor (mask));
19961 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_and, 0, 0));
19962 : }
19963 : }
19964 :
19965 13174863 : if (want_address == 2 && !have_address
19966 21519 : && (dwarf_version >= 4 || !dwarf_strict))
19967 : {
19968 21674 : if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
19969 : {
19970 0 : expansion_failed (loc, NULL_RTX,
19971 : "DWARF address size mismatch");
19972 0 : return 0;
19973 : }
19974 21519 : if (ret)
19975 10264 : add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
19976 : else
19977 16387 : add_loc_descr_to_each (list_ret,
19978 : new_loc_descr (DW_OP_stack_value, 0, 0));
19979 : have_address = 1;
19980 : }
19981 : /* Show if we can't fill the request for an address. */
19982 13174863 : if (want_address && !have_address)
19983 : {
19984 20 : expansion_failed (loc, NULL_RTX,
19985 : "Want address and only have value");
19986 20 : return 0;
19987 : }
19988 :
19989 13174843 : gcc_assert (!ret || !list_ret);
19990 :
19991 : /* If we've got an address and don't want one, dereference. */
19992 13174843 : if (!want_address && have_address)
19993 : {
19994 115058 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
19995 115058 : enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19996 115058 : scalar_int_mode int_mode;
19997 115058 : dw_die_ref type_die;
19998 115058 : dw_loc_descr_ref deref;
19999 :
20000 : /* Bail out if the size is variable or greater than DWARF2_ADDR_SIZE. */
20001 121999 : if (size < 0 || size > DWARF2_ADDR_SIZE)
20002 : {
20003 134 : expansion_failed (loc, NULL_RTX, "DWARF address size mismatch");
20004 134 : return 0;
20005 : }
20006 :
20007 : /* If it is equal to DWARF2_ADDR_SIZE, extension does not matter. */
20008 121808 : else if (size == DWARF2_ADDR_SIZE)
20009 113865 : deref = new_loc_descr (DW_OP_deref, size, 0);
20010 :
20011 : /* If it is lower than DWARF2_ADDR_SIZE, DW_OP_deref_size will zero-
20012 : extend the value, which is really OK for unsigned types only. */
20013 1031 : else if (!(context && context->strict_signedness)
20014 0 : || TYPE_UNSIGNED (TREE_TYPE (loc))
20015 0 : || (dwarf_strict && dwarf_version < 5)
20016 1059 : || !is_a <scalar_int_mode> (mode, &int_mode)
20017 1059 : || !(type_die = base_type_for_mode (mode, false)))
20018 1059 : deref = new_loc_descr (DW_OP_deref_size, size, 0);
20019 :
20020 : /* Use DW_OP_deref_type for signed integral types if possible, but
20021 : convert back to the generic type to avoid type mismatches later. */
20022 : else
20023 : {
20024 0 : deref = new_loc_descr (dwarf_OP (DW_OP_deref_type), size, 0);
20025 0 : deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
20026 0 : deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
20027 0 : deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
20028 0 : add_loc_descr (&deref,
20029 : new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0));
20030 : }
20031 :
20032 : /* Deal with bit-fields whose size is not a multiple of a byte. */
20033 114924 : if (TREE_CODE (loc) == COMPONENT_REF
20034 114924 : && DECL_BIT_FIELD (TREE_OPERAND (loc, 1)))
20035 : {
20036 0 : const unsigned HOST_WIDE_INT bitsize
20037 0 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (loc, 1)));
20038 0 : if (bitsize < (unsigned HOST_WIDE_INT)size * BITS_PER_UNIT)
20039 : {
20040 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
20041 : {
20042 0 : if (BYTES_BIG_ENDIAN)
20043 : {
20044 : const unsigned HOST_WIDE_INT shift
20045 : = size * BITS_PER_UNIT - bitsize;
20046 : add_loc_descr (&deref, uint_loc_descriptor (shift));
20047 : add_loc_descr (&deref, new_loc_descr (DW_OP_shr, 0, 0));
20048 : }
20049 : else
20050 : {
20051 0 : const unsigned HOST_WIDE_INT mask
20052 0 : = (HOST_WIDE_INT_1U << bitsize) - 1;
20053 0 : add_loc_descr (&deref, uint_loc_descriptor (mask));
20054 0 : add_loc_descr (&deref, new_loc_descr (DW_OP_and, 0, 0));
20055 : }
20056 : }
20057 : else
20058 : {
20059 0 : const unsigned HOST_WIDE_INT shiftr
20060 0 : = DWARF2_ADDR_SIZE * BITS_PER_UNIT - bitsize;
20061 0 : const unsigned HOST_WIDE_INT shiftl
20062 : = BYTES_BIG_ENDIAN
20063 : ? (DWARF2_ADDR_SIZE - size) * BITS_PER_UNIT
20064 : : shiftr;
20065 0 : if (shiftl > 0)
20066 : {
20067 0 : add_loc_descr (&deref, uint_loc_descriptor (shiftl));
20068 0 : add_loc_descr (&deref, new_loc_descr (DW_OP_shl, 0, 0));
20069 : }
20070 0 : add_loc_descr (&deref, uint_loc_descriptor (shiftr));
20071 0 : add_loc_descr (&deref, new_loc_descr (DW_OP_shra, 0, 0));
20072 : }
20073 : }
20074 : }
20075 :
20076 114924 : if (ret)
20077 2536 : add_loc_descr (&ret, deref);
20078 : else
20079 113656 : add_loc_descr_to_each (list_ret, deref);
20080 : }
20081 :
20082 13174709 : if (ret)
20083 688525 : list_ret = new_loc_list (ret, NULL, 0, NULL, 0, NULL);
20084 :
20085 13174709 : return list_ret;
20086 : }
20087 :
20088 : /* Likewise, but strip useless DW_OP_nop operations in the resulting
20089 : expressions. */
20090 :
20091 : static dw_loc_list_ref
20092 15762773 : loc_list_from_tree (tree loc, int want_address,
20093 : struct loc_descr_context *context)
20094 : {
20095 15762773 : dw_loc_list_ref result = loc_list_from_tree_1 (loc, want_address, context);
20096 :
20097 15762773 : for (dw_loc_list_ref loc_cur = result;
20098 41952837 : loc_cur != NULL; loc_cur = loc_cur->dw_loc_next)
20099 26190064 : loc_descr_without_nops (loc_cur->expr);
20100 15762773 : return result;
20101 : }
20102 :
20103 : /* Same as above but return only single location expression. */
20104 : static dw_loc_descr_ref
20105 864 : loc_descriptor_from_tree (tree loc, int want_address,
20106 : struct loc_descr_context *context)
20107 : {
20108 864 : dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
20109 864 : if (!ret)
20110 : return NULL;
20111 854 : if (ret->dw_loc_next)
20112 : {
20113 0 : expansion_failed (loc, NULL_RTX,
20114 : "Location list where only loc descriptor needed");
20115 0 : return NULL;
20116 : }
20117 854 : return ret->expr;
20118 : }
20119 :
20120 : /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
20121 : pointer to the declared type for the relevant field variable, or return
20122 : `integer_type_node' if the given node turns out to be an
20123 : ERROR_MARK node. */
20124 :
20125 : static inline tree
20126 1463062 : field_type (const_tree decl)
20127 : {
20128 1463062 : tree type;
20129 :
20130 1463062 : if (TREE_CODE (decl) == ERROR_MARK)
20131 0 : return integer_type_node;
20132 :
20133 1463062 : type = DECL_BIT_FIELD_TYPE (decl);
20134 1463062 : if (type == NULL_TREE)
20135 0 : type = TREE_TYPE (decl);
20136 :
20137 : return type;
20138 : }
20139 :
20140 : /* Given a pointer to a tree node, return the alignment in bits for
20141 : it, or else return BITS_PER_WORD if the node actually turns out to
20142 : be an ERROR_MARK node. */
20143 :
20144 : static inline unsigned
20145 975360 : simple_type_align_in_bits (const_tree type)
20146 : {
20147 975360 : return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
20148 : }
20149 :
20150 : static inline unsigned
20151 975360 : simple_decl_align_in_bits (const_tree decl)
20152 : {
20153 975360 : return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
20154 : }
20155 :
20156 : /* Return the result of rounding T up to ALIGN. */
20157 :
20158 : static inline offset_int
20159 975428 : round_up_to_align (const offset_int &t, unsigned int align)
20160 : {
20161 975428 : return wi::udiv_trunc (t + align - 1, align) * align;
20162 : }
20163 :
20164 : /* Helper structure for RECORD_TYPE processing. */
20165 : struct vlr_context
20166 : {
20167 : /* Root RECORD_TYPE. It is needed to generate data member location
20168 : descriptions in variable-length records (VLR), but also to cope with
20169 : variants, which are composed of nested structures multiplexed with
20170 : QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
20171 : function processing a FIELD_DECL, it is required to be non null. */
20172 : tree struct_type;
20173 :
20174 : /* When generating a variant part in a RECORD_TYPE (i.e. a nested
20175 : QUAL_UNION_TYPE), this holds an expression that computes the offset for
20176 : this variant part as part of the root record (in storage units). For
20177 : regular records, it must be NULL_TREE. */
20178 : tree variant_part_offset;
20179 : };
20180 :
20181 : /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
20182 : addressed byte of the "containing object" for the given FIELD_DECL. If
20183 : possible, return a native constant through CST_OFFSET (in which case NULL is
20184 : returned); otherwise return a DWARF expression that computes the offset.
20185 :
20186 : Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
20187 : that offset is, either because the argument turns out to be a pointer to an
20188 : ERROR_MARK node, or because the offset expression is too complex for us.
20189 :
20190 : CTX is required: see the comment for VLR_CONTEXT. */
20191 :
20192 : static dw_loc_descr_ref
20193 15989413 : field_byte_offset (const_tree decl, struct vlr_context *ctx,
20194 : HOST_WIDE_INT *cst_offset)
20195 : {
20196 15989413 : tree tree_result;
20197 15989413 : dw_loc_list_ref loc_result;
20198 :
20199 15989413 : *cst_offset = 0;
20200 :
20201 15989413 : if (TREE_CODE (decl) == ERROR_MARK)
20202 : return NULL;
20203 : else
20204 15989413 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
20205 :
20206 : /* We cannot handle variable bit offsets at the moment, so abort if it's the
20207 : case. */
20208 15989413 : if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl)) != INTEGER_CST)
20209 : return NULL;
20210 :
20211 : /* We used to handle only constant offsets in all cases. Now, we handle
20212 : properly dynamic byte offsets only when PCC bitfield type doesn't
20213 : matter. */
20214 15989413 : if (PCC_BITFIELD_TYPE_MATTERS
20215 15989413 : && DECL_BIT_FIELD_TYPE (decl)
20216 15989413 : && TREE_CODE (DECL_FIELD_OFFSET (decl)) == INTEGER_CST)
20217 : {
20218 975360 : offset_int object_offset_in_bits;
20219 975360 : offset_int object_offset_in_bytes;
20220 975360 : offset_int bitpos_int;
20221 975360 : tree type;
20222 975360 : tree field_size_tree;
20223 975360 : offset_int deepest_bitpos;
20224 975360 : offset_int field_size_in_bits;
20225 975360 : unsigned int type_align_in_bits;
20226 975360 : unsigned int decl_align_in_bits;
20227 975360 : offset_int type_size_in_bits;
20228 :
20229 975360 : bitpos_int = wi::to_offset (bit_position (decl));
20230 975360 : type = field_type (decl);
20231 975360 : type_size_in_bits = offset_int_type_size_in_bits (type);
20232 975360 : type_align_in_bits = simple_type_align_in_bits (type);
20233 :
20234 975360 : field_size_tree = DECL_SIZE (decl);
20235 :
20236 : /* The size could be unspecified if there was an error, or for
20237 : a flexible array member. */
20238 975360 : if (!field_size_tree)
20239 0 : field_size_tree = bitsize_zero_node;
20240 :
20241 : /* If the size of the field is not constant, use the type size. */
20242 975360 : if (TREE_CODE (field_size_tree) == INTEGER_CST)
20243 975360 : field_size_in_bits = wi::to_offset (field_size_tree);
20244 : else
20245 0 : field_size_in_bits = type_size_in_bits;
20246 :
20247 975360 : decl_align_in_bits = simple_decl_align_in_bits (decl);
20248 :
20249 : /* The GCC front-end doesn't make any attempt to keep track of the
20250 : starting bit offset (relative to the start of the containing
20251 : structure type) of the hypothetical "containing object" for a
20252 : bit-field. Thus, when computing the byte offset value for the
20253 : start of the "containing object" of a bit-field, we must deduce
20254 : this information on our own. This can be rather tricky to do in
20255 : some cases. For example, handling the following structure type
20256 : definition when compiling for an i386/i486 target (which only
20257 : aligns long long's to 32-bit boundaries) can be very tricky:
20258 :
20259 : struct S { int field1; long long field2:31; };
20260 :
20261 : Fortunately, there is a simple rule-of-thumb which can be used
20262 : in such cases. When compiling for an i386/i486, GCC will
20263 : allocate 8 bytes for the structure shown above. It decides to
20264 : do this based upon one simple rule for bit-field allocation.
20265 : GCC allocates each "containing object" for each bit-field at
20266 : the first (i.e. lowest addressed) legitimate alignment boundary
20267 : (based upon the required minimum alignment for the declared
20268 : type of the field) which it can possibly use, subject to the
20269 : condition that there is still enough available space remaining
20270 : in the containing object (when allocated at the selected point)
20271 : to fully accommodate all of the bits of the bit-field itself.
20272 :
20273 : This simple rule makes it obvious why GCC allocates 8 bytes for
20274 : each object of the structure type shown above. When looking
20275 : for a place to allocate the "containing object" for `field2',
20276 : the compiler simply tries to allocate a 64-bit "containing
20277 : object" at each successive 32-bit boundary (starting at zero)
20278 : until it finds a place to allocate that 64- bit field such that
20279 : at least 31 contiguous (and previously unallocated) bits remain
20280 : within that selected 64 bit field. (As it turns out, for the
20281 : example above, the compiler finds it is OK to allocate the
20282 : "containing object" 64-bit field at bit-offset zero within the
20283 : structure type.)
20284 :
20285 : Here we attempt to work backwards from the limited set of facts
20286 : we're given, and we try to deduce from those facts, where GCC
20287 : must have believed that the containing object started (within
20288 : the structure type). The value we deduce is then used (by the
20289 : callers of this routine) to generate DW_AT_location and
20290 : DW_AT_bit_offset attributes for fields (both bit-fields and, in
20291 : the case of DW_AT_location, regular fields as well). */
20292 :
20293 : /* Figure out the bit-distance from the start of the structure to
20294 : the "deepest" bit of the bit-field. */
20295 975360 : deepest_bitpos = bitpos_int + field_size_in_bits;
20296 :
20297 : /* This is the tricky part. Use some fancy footwork to deduce
20298 : where the lowest addressed bit of the containing object must
20299 : be. */
20300 975360 : object_offset_in_bits = deepest_bitpos - type_size_in_bits;
20301 :
20302 : /* Round up to type_align by default. This works best for
20303 : bitfields. */
20304 975360 : object_offset_in_bits
20305 975360 : = round_up_to_align (object_offset_in_bits, type_align_in_bits);
20306 :
20307 975360 : if (wi::gtu_p (object_offset_in_bits, bitpos_int))
20308 : {
20309 68 : object_offset_in_bits = deepest_bitpos - type_size_in_bits;
20310 :
20311 : /* Round up to decl_align instead. */
20312 68 : object_offset_in_bits
20313 68 : = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
20314 : }
20315 :
20316 975360 : object_offset_in_bytes
20317 975360 : = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
20318 975360 : if (ctx->variant_part_offset == NULL_TREE)
20319 : {
20320 975360 : *cst_offset = object_offset_in_bytes.to_shwi ();
20321 975360 : return NULL;
20322 : }
20323 0 : tree_result = wide_int_to_tree (sizetype, object_offset_in_bytes);
20324 : }
20325 : else
20326 15014053 : tree_result = byte_position (decl);
20327 :
20328 15014053 : if (ctx->variant_part_offset != NULL_TREE)
20329 0 : tree_result = fold_build2 (PLUS_EXPR, TREE_TYPE (tree_result),
20330 : ctx->variant_part_offset, tree_result);
20331 :
20332 : /* If the byte offset is a constant, it's simpler to handle a native
20333 : constant rather than a DWARF expression. */
20334 15014053 : if (TREE_CODE (tree_result) == INTEGER_CST)
20335 : {
20336 15014013 : *cst_offset = wi::to_offset (tree_result).to_shwi ();
20337 15014013 : return NULL;
20338 : }
20339 :
20340 40 : struct loc_descr_context loc_ctx = {
20341 40 : ctx->struct_type, /* context_type */
20342 : NULL_TREE, /* base_decl */
20343 : NULL, /* dpi */
20344 : false, /* placeholder_arg */
20345 : false, /* placeholder_seen */
20346 : false /* strict_signedness */
20347 40 : };
20348 40 : loc_result = loc_list_from_tree (tree_result, 0, &loc_ctx);
20349 :
20350 : /* We want a DWARF expression: abort if we only have a location list with
20351 : multiple elements. */
20352 40 : if (!loc_result || !single_element_loc_list_p (loc_result))
20353 : return NULL;
20354 : else
20355 40 : return loc_result->expr;
20356 : }
20357 :
20358 : /* The following routines define various Dwarf attributes and any data
20359 : associated with them. */
20360 :
20361 : /* Add a location description attribute value to a DIE.
20362 :
20363 : This emits location attributes suitable for whole variables and
20364 : whole parameters. Note that the location attributes for struct fields are
20365 : generated by the routine `data_member_location_attribute' below. */
20366 :
20367 : static inline void
20368 12814969 : add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
20369 : dw_loc_list_ref descr)
20370 : {
20371 12814969 : bool check_no_locviews = true;
20372 12814969 : if (descr == 0)
20373 : return;
20374 12814835 : if (single_element_loc_list_p (descr))
20375 996771 : add_AT_loc (die, attr_kind, descr->expr);
20376 : else
20377 : {
20378 11818064 : add_AT_loc_list (die, attr_kind, descr);
20379 11818064 : gcc_assert (descr->ll_symbol);
20380 11817198 : if (attr_kind == DW_AT_location && descr->vl_symbol
20381 23461805 : && dwarf2out_locviews_in_attribute ())
20382 : {
20383 11643741 : add_AT_view_list (die, DW_AT_GNU_locviews);
20384 11643741 : check_no_locviews = false;
20385 : }
20386 : }
20387 :
20388 12640512 : if (check_no_locviews)
20389 1171094 : gcc_assert (!get_AT (die, DW_AT_GNU_locviews));
20390 : }
20391 :
20392 : /* Add DW_AT_accessibility attribute to DIE if needed. */
20393 :
20394 : static void
20395 249977892 : add_accessibility_attribute (dw_die_ref die, tree decl)
20396 : {
20397 : /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20398 : children, otherwise the default is DW_ACCESS_public. In DWARF2
20399 : the default has always been DW_ACCESS_public. */
20400 249977892 : if (TREE_PROTECTED (decl))
20401 4893721 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20402 245084171 : else if (TREE_PRIVATE (decl))
20403 : {
20404 18324040 : if (dwarf_version == 2
20405 18323893 : || die->die_parent == NULL
20406 18323893 : || die->die_parent->die_tag != DW_TAG_class_type)
20407 3285968 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20408 : }
20409 226760131 : else if (dwarf_version > 2
20410 226716767 : && die->die_parent
20411 226432860 : && die->die_parent->die_tag == DW_TAG_class_type)
20412 61381931 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20413 249977892 : }
20414 :
20415 : /* Attach the specialized form of location attribute used for data members of
20416 : struct and union types. In the special case of a FIELD_DECL node which
20417 : represents a bit-field, the "offset" part of this special location
20418 : descriptor must indicate the distance in bytes from the lowest-addressed
20419 : byte of the containing struct or union type to the lowest-addressed byte of
20420 : the "containing object" for the bit-field. (See the `field_byte_offset'
20421 : function above).
20422 :
20423 : For any given bit-field, the "containing object" is a hypothetical object
20424 : (of some integral or enum type) within which the given bit-field lives. The
20425 : type of this hypothetical "containing object" is always the same as the
20426 : declared type of the individual bit-field itself (for GCC anyway... the
20427 : DWARF spec doesn't actually mandate this). Note that it is the size (in
20428 : bytes) of the hypothetical "containing object" which will be given in the
20429 : DW_AT_byte_size attribute for this bit-field. (See the
20430 : `byte_size_attribute' function below.) It is also used when calculating the
20431 : value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
20432 : function below.)
20433 :
20434 : CTX is required: see the comment for VLR_CONTEXT. */
20435 :
20436 : static void
20437 38630826 : add_data_member_location_attribute (dw_die_ref die,
20438 : tree decl,
20439 : struct vlr_context *ctx)
20440 : {
20441 38630826 : HOST_WIDE_INT offset;
20442 38630826 : dw_loc_descr_ref loc_descr = 0;
20443 :
20444 38630826 : if (TREE_CODE (decl) == TREE_BINFO)
20445 : {
20446 : /* We're working on the TAG_inheritance for a base class. */
20447 23129115 : if (BINFO_VIRTUAL_P (decl) && is_cxx ())
20448 : {
20449 : /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
20450 : aren't at a fixed offset from all (sub)objects of the same
20451 : type. We need to extract the appropriate offset from our
20452 : vtable. The following dwarf expression means
20453 :
20454 : BaseAddr = ObAddr + *((*ObAddr) - Offset)
20455 :
20456 : This is specific to the V3 ABI, of course. */
20457 :
20458 299 : dw_loc_descr_ref tmp;
20459 :
20460 : /* Make a copy of the object address. */
20461 299 : tmp = new_loc_descr (DW_OP_dup, 0, 0);
20462 299 : add_loc_descr (&loc_descr, tmp);
20463 :
20464 : /* Extract the vtable address. */
20465 299 : tmp = new_loc_descr (DW_OP_deref, 0, 0);
20466 299 : add_loc_descr (&loc_descr, tmp);
20467 :
20468 : /* Calculate the address of the offset. */
20469 299 : offset = tree_to_shwi (BINFO_VPTR_FIELD (decl));
20470 299 : gcc_assert (offset < 0);
20471 :
20472 299 : tmp = int_loc_descriptor (-offset);
20473 299 : add_loc_descr (&loc_descr, tmp);
20474 299 : tmp = new_loc_descr (DW_OP_minus, 0, 0);
20475 299 : add_loc_descr (&loc_descr, tmp);
20476 :
20477 : /* Extract the offset. */
20478 299 : tmp = new_loc_descr (DW_OP_deref, 0, 0);
20479 299 : add_loc_descr (&loc_descr, tmp);
20480 :
20481 : /* Add it to the object address. */
20482 299 : tmp = new_loc_descr (DW_OP_plus, 0, 0);
20483 598 : add_loc_descr (&loc_descr, tmp);
20484 : }
20485 : else
20486 23128816 : offset = tree_to_shwi (BINFO_OFFSET (decl));
20487 : }
20488 : else
20489 : {
20490 15501711 : loc_descr = field_byte_offset (decl, ctx, &offset);
20491 :
20492 15501711 : if (!loc_descr)
20493 : ;
20494 :
20495 : /* If loc_descr is available, then we know the offset is dynamic. */
20496 24 : else if (gnat_encodings == DWARF_GNAT_ENCODINGS_ALL)
20497 : {
20498 0 : loc_descr = NULL;
20499 0 : offset = 0;
20500 : }
20501 :
20502 : /* Data member location evaluation starts with the base address on the
20503 : stack. Compute the field offset and add it to this base address. */
20504 : else
20505 48 : add_loc_descr (&loc_descr, new_loc_descr (DW_OP_plus, 0, 0));
20506 : }
20507 :
20508 38630826 : if (!loc_descr)
20509 : {
20510 : /* While DW_AT_data_bit_offset has been added already in DWARF4,
20511 : e.g. GDB only added support to it in November 2016. For DWARF5
20512 : we need newer debug info consumers anyway. We might change this
20513 : to dwarf_version >= 4 once most consumers caught up. */
20514 38630503 : if (dwarf_version >= 5
20515 38618620 : && TREE_CODE (decl) == FIELD_DECL
20516 15490256 : && DECL_BIT_FIELD_TYPE (decl)
20517 39118109 : && (ctx->variant_part_offset == NULL_TREE
20518 0 : || TREE_CODE (ctx->variant_part_offset) == INTEGER_CST))
20519 : {
20520 487606 : tree off = bit_position (decl);
20521 487606 : if (ctx->variant_part_offset)
20522 0 : off = bit_from_pos (ctx->variant_part_offset, off);
20523 487606 : if (tree_fits_uhwi_p (off) && get_AT (die, DW_AT_bit_size))
20524 : {
20525 487606 : remove_AT (die, DW_AT_byte_size);
20526 487606 : remove_AT (die, DW_AT_bit_offset);
20527 487606 : add_AT_unsigned (die, DW_AT_data_bit_offset, tree_to_uhwi (off));
20528 38618742 : return;
20529 : }
20530 : }
20531 38142897 : if (dwarf_version > 2)
20532 : {
20533 : /* Don't need to output a location expression, just the constant. */
20534 38131136 : if (offset < 0)
20535 0 : add_AT_int (die, DW_AT_data_member_location, offset);
20536 : else
20537 38131136 : add_AT_unsigned (die, DW_AT_data_member_location, offset);
20538 38131136 : return;
20539 : }
20540 : else
20541 : {
20542 11761 : enum dwarf_location_atom op;
20543 :
20544 : /* The DWARF2 standard says that we should assume that the structure
20545 : address is already on the stack, so we can specify a structure
20546 : field address by using DW_OP_plus_uconst. */
20547 11761 : op = DW_OP_plus_uconst;
20548 11761 : loc_descr = new_loc_descr (op, offset, 0);
20549 : }
20550 : }
20551 :
20552 12084 : add_AT_loc (die, DW_AT_data_member_location, loc_descr);
20553 : }
20554 :
20555 : /* Writes integer values to dw_vec_const array. */
20556 :
20557 : static void
20558 198071 : insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
20559 : {
20560 988013 : while (size != 0)
20561 : {
20562 789942 : *dest++ = val & 0xff;
20563 789942 : val >>= 8;
20564 789942 : --size;
20565 : }
20566 0 : }
20567 :
20568 : /* Reads integers from dw_vec_const array. Inverse of insert_int. */
20569 :
20570 : static HOST_WIDE_INT
20571 3776616 : extract_int (const unsigned char *src, unsigned int size)
20572 : {
20573 3776616 : HOST_WIDE_INT val = 0;
20574 :
20575 3776616 : src += size;
20576 8135183 : while (size != 0)
20577 : {
20578 4358567 : val <<= 8;
20579 4358567 : val |= *--src & 0xff;
20580 4358567 : --size;
20581 : }
20582 3776616 : return val;
20583 : }
20584 :
20585 : /* Writes wide_int values to dw_vec_const array. */
20586 :
20587 : static void
20588 292 : insert_wide_int (const wide_int_ref &val, unsigned char *dest, int elt_size)
20589 : {
20590 292 : int i;
20591 :
20592 292 : if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
20593 : {
20594 292 : insert_int ((HOST_WIDE_INT) val.elt (0), elt_size, dest);
20595 : return;
20596 : }
20597 :
20598 : /* We'd have to extend this code to support odd sizes. */
20599 0 : gcc_assert (elt_size % (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) == 0);
20600 :
20601 0 : int n = elt_size / (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
20602 :
20603 0 : if (WORDS_BIG_ENDIAN)
20604 : for (i = n - 1; i >= 0; i--)
20605 : {
20606 : insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
20607 : dest += sizeof (HOST_WIDE_INT);
20608 : }
20609 : else
20610 0 : for (i = 0; i < n; i++)
20611 : {
20612 0 : insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
20613 0 : dest += sizeof (HOST_WIDE_INT);
20614 : }
20615 : }
20616 :
20617 : /* Writes floating point values to dw_vec_const array. */
20618 :
20619 : static unsigned
20620 90430 : insert_float (const_rtx rtl, unsigned char *array)
20621 : {
20622 90430 : long val[4];
20623 90430 : int i;
20624 90430 : scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
20625 :
20626 90430 : real_to_target (val, CONST_DOUBLE_REAL_VALUE (rtl), mode);
20627 :
20628 : /* real_to_target puts 32-bit pieces in each long. Pack them. */
20629 180860 : if (GET_MODE_SIZE (mode) < 4)
20630 : {
20631 1774 : gcc_assert (GET_MODE_SIZE (mode) == 2);
20632 887 : insert_int (val[0], 2, array);
20633 : return 2;
20634 : }
20635 :
20636 572870 : for (i = 0; i < GET_MODE_SIZE (mode) / 4; i++)
20637 : {
20638 196892 : insert_int (val[i], 4, array);
20639 196892 : array += 4;
20640 : }
20641 : return 4;
20642 : }
20643 :
20644 : /* Attach a DW_AT_const_value attribute for a variable or a parameter which
20645 : does not have a "location" either in memory or in a register. These
20646 : things can arise in GNU C when a constant is passed as an actual parameter
20647 : to an inlined function. They can also arise in C++ where declared
20648 : constants do not necessarily get memory "homes". */
20649 :
20650 : static bool
20651 54259 : add_const_value_attribute (dw_die_ref die, machine_mode mode, rtx rtl)
20652 : {
20653 54259 : scalar_mode int_mode;
20654 :
20655 54259 : switch (GET_CODE (rtl))
20656 : {
20657 36894 : case CONST_INT:
20658 36894 : {
20659 36894 : HOST_WIDE_INT val = INTVAL (rtl);
20660 :
20661 36894 : if (val < 0)
20662 1343 : add_AT_int (die, DW_AT_const_value, val);
20663 : else
20664 35551 : add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
20665 : }
20666 : return true;
20667 :
20668 41 : case CONST_WIDE_INT:
20669 41 : if (is_int_mode (mode, &int_mode)
20670 41 : && (GET_MODE_PRECISION (int_mode)
20671 : & (HOST_BITS_PER_WIDE_INT - 1)) == 0)
20672 : {
20673 41 : add_AT_wide (die, DW_AT_const_value, rtx_mode_t (rtl, int_mode));
20674 41 : return true;
20675 : }
20676 : return false;
20677 :
20678 6811 : case CONST_DOUBLE:
20679 : /* Note that a CONST_DOUBLE rtx could represent either an integer or a
20680 : floating-point constant. A CONST_DOUBLE is used whenever the
20681 : constant requires more than one word in order to be adequately
20682 : represented. */
20683 6811 : if (TARGET_SUPPORTS_WIDE_INT == 0
20684 : && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl)))
20685 : add_AT_double (die, DW_AT_const_value,
20686 : CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
20687 : else
20688 : {
20689 6811 : scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
20690 6811 : unsigned int length = GET_MODE_SIZE (mode);
20691 6811 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
20692 6811 : unsigned int elt_size = insert_float (rtl, array);
20693 :
20694 6811 : add_AT_vec (die, DW_AT_const_value, length / elt_size, elt_size,
20695 : array);
20696 : }
20697 6811 : return true;
20698 :
20699 54 : case CONST_VECTOR:
20700 54 : {
20701 54 : unsigned int length;
20702 108 : if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
20703 1803 : return false;
20704 :
20705 54 : machine_mode mode = GET_MODE (rtl);
20706 : /* The combination of a length and byte elt_size doesn't extend
20707 : naturally to boolean vectors, where several elements are packed
20708 : into the same byte. */
20709 54 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL)
20710 : return false;
20711 :
20712 54 : unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
20713 54 : unsigned char *array
20714 54 : = ggc_vec_alloc<unsigned char> (length * elt_size);
20715 54 : unsigned int i;
20716 54 : unsigned char *p;
20717 54 : machine_mode imode = GET_MODE_INNER (mode);
20718 :
20719 54 : switch (GET_MODE_CLASS (mode))
20720 : {
20721 : case MODE_VECTOR_INT:
20722 309 : for (i = 0, p = array; i < length; i++, p += elt_size)
20723 : {
20724 272 : rtx elt = CONST_VECTOR_ELT (rtl, i);
20725 272 : insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
20726 : }
20727 : break;
20728 :
20729 : case MODE_VECTOR_FLOAT:
20730 81 : for (i = 0, p = array; i < length; i++, p += elt_size)
20731 : {
20732 64 : rtx elt = CONST_VECTOR_ELT (rtl, i);
20733 64 : insert_float (elt, p);
20734 : }
20735 : break;
20736 :
20737 0 : default:
20738 0 : gcc_unreachable ();
20739 : }
20740 :
20741 54 : add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
20742 : }
20743 54 : return true;
20744 :
20745 262 : case CONST_STRING:
20746 262 : if (dwarf_version >= 4 || !dwarf_strict)
20747 : {
20748 262 : dw_loc_descr_ref loc_result;
20749 262 : resolve_one_addr (&rtl);
20750 8585 : rtl_addr:
20751 8585 : loc_result = new_addr_loc_descr (rtl, dtprel_false);
20752 8585 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
20753 8585 : add_AT_loc (die, DW_AT_location, loc_result);
20754 8585 : vec_safe_push (used_rtx_array, rtl);
20755 8585 : return true;
20756 : }
20757 : return false;
20758 :
20759 502 : case CONST:
20760 502 : if (CONSTANT_P (XEXP (rtl, 0)))
20761 0 : return add_const_value_attribute (die, mode, XEXP (rtl, 0));
20762 : /* FALLTHROUGH */
20763 10122 : case SYMBOL_REF:
20764 10122 : if (!const_ok_for_output (rtl))
20765 : return false;
20766 : /* FALLTHROUGH */
20767 8323 : case LABEL_REF:
20768 8323 : if (dwarf_version >= 4 || !dwarf_strict)
20769 8323 : goto rtl_addr;
20770 : return false;
20771 :
20772 : case PLUS:
20773 : /* In cases where an inlined instance of an inline function is passed
20774 : the address of an `auto' variable (which is local to the caller) we
20775 : can get a situation where the DECL_RTL of the artificial local
20776 : variable (for the inlining) which acts as a stand-in for the
20777 : corresponding formal parameter (of the inline function) will look
20778 : like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
20779 : exactly a compile-time constant expression, but it isn't the address
20780 : of the (artificial) local variable either. Rather, it represents the
20781 : *value* which the artificial local variable always has during its
20782 : lifetime. We currently have no way to represent such quasi-constant
20783 : values in Dwarf, so for now we just punt and generate nothing. */
20784 : return false;
20785 :
20786 : case HIGH:
20787 : case CONST_FIXED:
20788 : case MINUS:
20789 : case SIGN_EXTEND:
20790 : case ZERO_EXTEND:
20791 : case CONST_POLY_INT:
20792 : return false;
20793 :
20794 71 : case MEM:
20795 71 : if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
20796 71 : && MEM_READONLY_P (rtl)
20797 142 : && GET_MODE (rtl) == BLKmode)
20798 : {
20799 71 : add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
20800 71 : return true;
20801 : }
20802 : return false;
20803 :
20804 0 : default:
20805 : /* No other kinds of rtx should be possible here. */
20806 0 : gcc_unreachable ();
20807 : }
20808 : }
20809 :
20810 : /* Determine whether the evaluation of EXPR references any variables
20811 : or functions which aren't otherwise used (and therefore may not be
20812 : output). */
20813 : static tree
20814 7837 : reference_to_unused (tree * tp, int * walk_subtrees,
20815 : void * data ATTRIBUTE_UNUSED)
20816 : {
20817 7837 : if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
20818 1236 : *walk_subtrees = 0;
20819 :
20820 7837 : if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
20821 17 : && ! TREE_ASM_WRITTEN (*tp))
20822 : return *tp;
20823 : /* ??? The C++ FE emits debug information for using decls, so
20824 : putting gcc_unreachable here falls over. See PR31899. For now
20825 : be conservative. */
20826 7820 : else if (!symtab->global_info_ready && VAR_P (*tp))
20827 : return *tp;
20828 7410 : else if (VAR_P (*tp))
20829 : {
20830 635 : varpool_node *node = varpool_node::get (*tp);
20831 635 : if (!node || !node->definition)
20832 630 : return *tp;
20833 : }
20834 6775 : else if (TREE_CODE (*tp) == FUNCTION_DECL
20835 6775 : && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
20836 : {
20837 : /* The call graph machinery must have finished analyzing,
20838 : optimizing and gimplifying the CU by now.
20839 : So if *TP has no call graph node associated
20840 : to it, it means *TP will not be emitted. */
20841 163 : if (!symtab->global_info_ready || !cgraph_node::get (*tp))
20842 115 : return *tp;
20843 : }
20844 6612 : else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
20845 321 : return *tp;
20846 :
20847 : return NULL_TREE;
20848 : }
20849 :
20850 : /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
20851 : for use in a later add_const_value_attribute call. */
20852 :
20853 : static rtx
20854 147024 : rtl_for_decl_init (tree init, tree type)
20855 : {
20856 147024 : rtx rtl = NULL_RTX;
20857 :
20858 147024 : STRIP_NOPS (init);
20859 :
20860 : /* If a variable is initialized with a string constant without embedded
20861 : zeros, build CONST_STRING. */
20862 147024 : if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
20863 : {
20864 461 : tree enttype = TREE_TYPE (type);
20865 461 : tree domain = TYPE_DOMAIN (type);
20866 461 : scalar_int_mode mode;
20867 :
20868 922 : if (is_int_mode (TYPE_MODE (enttype), &mode)
20869 461 : && GET_MODE_SIZE (mode) == 1
20870 450 : && domain
20871 450 : && TYPE_MAX_VALUE (domain)
20872 414 : && TREE_CODE (TYPE_MAX_VALUE (domain)) == INTEGER_CST
20873 414 : && integer_zerop (TYPE_MIN_VALUE (domain))
20874 405 : && compare_tree_int (TYPE_MAX_VALUE (domain),
20875 405 : TREE_STRING_LENGTH (init) - 1) == 0
20876 263 : && ((size_t) TREE_STRING_LENGTH (init)
20877 263 : == strlen (TREE_STRING_POINTER (init)) + 1))
20878 : {
20879 213 : rtl = gen_rtx_CONST_STRING (VOIDmode,
20880 : ggc_strdup (TREE_STRING_POINTER (init)));
20881 213 : rtl = gen_rtx_MEM (BLKmode, rtl);
20882 213 : MEM_READONLY_P (rtl) = 1;
20883 : }
20884 : }
20885 : /* Other aggregates, and complex values, could be represented using
20886 : CONCAT: FIXME!
20887 : If this changes, please adjust tree_add_const_value_attribute
20888 : so that for early_dwarf it will for such initializers mangle referenced
20889 : decls. */
20890 146563 : else if (AGGREGATE_TYPE_P (type)
20891 5256 : || (TREE_CODE (init) == VIEW_CONVERT_EXPR
20892 0 : && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
20893 151819 : || TREE_CODE (type) == COMPLEX_TYPE)
20894 : ;
20895 : /* Vectors only work if their mode is supported by the target.
20896 : FIXME: generic vectors ought to work too. */
20897 5239 : else if (TREE_CODE (type) == VECTOR_TYPE
20898 5239 : && !VECTOR_MODE_P (TYPE_MODE (type)))
20899 : ;
20900 : /* If the initializer is something that we know will expand into an
20901 : immediate RTL constant, expand it now. We must be careful not to
20902 : reference variables which won't be output. */
20903 5235 : else if (initializer_constant_valid_p (init, type)
20904 5235 : && ! walk_tree (&init, reference_to_unused, NULL, NULL))
20905 : {
20906 : /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
20907 : possible. */
20908 3741 : if (TREE_CODE (type) == VECTOR_TYPE)
20909 51 : switch (TREE_CODE (init))
20910 : {
20911 : case VECTOR_CST:
20912 : break;
20913 0 : case CONSTRUCTOR:
20914 0 : if (TREE_CONSTANT (init))
20915 : {
20916 0 : vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (init);
20917 0 : bool constant_p = true;
20918 0 : tree value;
20919 0 : unsigned HOST_WIDE_INT ix;
20920 :
20921 : /* Even when ctor is constant, it might contain non-*_CST
20922 : elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
20923 : belong into VECTOR_CST nodes. */
20924 0 : FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
20925 0 : if (!CONSTANT_CLASS_P (value))
20926 : {
20927 : constant_p = false;
20928 : break;
20929 : }
20930 :
20931 0 : if (constant_p)
20932 : {
20933 0 : init = build_vector_from_ctor (type, elts);
20934 0 : break;
20935 : }
20936 : }
20937 : /* FALLTHRU */
20938 :
20939 0 : default:
20940 0 : return NULL;
20941 : }
20942 :
20943 : /* Large _BitInt BLKmode INTEGER_CSTs would yield a MEM. */
20944 3741 : if (TREE_CODE (init) == INTEGER_CST
20945 298 : && TREE_CODE (TREE_TYPE (init)) == BITINT_TYPE
20946 3741 : && TYPE_MODE (TREE_TYPE (init)) == BLKmode)
20947 : {
20948 0 : if (tree_fits_shwi_p (init))
20949 0 : return GEN_INT (tree_to_shwi (init));
20950 : else
20951 : return NULL;
20952 : }
20953 :
20954 3741 : rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
20955 :
20956 : /* If expand_expr returns a MEM, it wasn't immediate. */
20957 3741 : gcc_assert (!rtl || !MEM_P (rtl));
20958 : }
20959 :
20960 : return rtl;
20961 : }
20962 :
20963 : /* Generate RTL for the variable DECL to represent its location. */
20964 :
20965 : static rtx
20966 18332480 : rtl_for_decl_location (tree decl)
20967 : {
20968 18332480 : rtx rtl;
20969 :
20970 : /* Here we have to decide where we are going to say the parameter "lives"
20971 : (as far as the debugger is concerned). We only have a couple of
20972 : choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
20973 :
20974 : DECL_RTL normally indicates where the parameter lives during most of the
20975 : activation of the function. If optimization is enabled however, this
20976 : could be either NULL or else a pseudo-reg. Both of those cases indicate
20977 : that the parameter doesn't really live anywhere (as far as the code
20978 : generation parts of GCC are concerned) during most of the function's
20979 : activation. That will happen (for example) if the parameter is never
20980 : referenced within the function.
20981 :
20982 : We could just generate a location descriptor here for all non-NULL
20983 : non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
20984 : a little nicer than that if we also consider DECL_INCOMING_RTL in cases
20985 : where DECL_RTL is NULL or is a pseudo-reg.
20986 :
20987 : Note however that we can only get away with using DECL_INCOMING_RTL as
20988 : a backup substitute for DECL_RTL in certain limited cases. In cases
20989 : where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
20990 : we can be sure that the parameter was passed using the same type as it is
20991 : declared to have within the function, and that its DECL_INCOMING_RTL
20992 : points us to a place where a value of that type is passed.
20993 :
20994 : In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
20995 : we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
20996 : because in these cases DECL_INCOMING_RTL points us to a value of some
20997 : type which is *different* from the type of the parameter itself. Thus,
20998 : if we tried to use DECL_INCOMING_RTL to generate a location attribute in
20999 : such cases, the debugger would end up (for example) trying to fetch a
21000 : `float' from a place which actually contains the first part of a
21001 : `double'. That would lead to really incorrect and confusing
21002 : output at debug-time.
21003 :
21004 : So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
21005 : in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
21006 : are a couple of exceptions however. On little-endian machines we can
21007 : get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
21008 : not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
21009 : an integral type that is smaller than TREE_TYPE (decl). These cases arise
21010 : when (on a little-endian machine) a non-prototyped function has a
21011 : parameter declared to be of type `short' or `char'. In such cases,
21012 : TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
21013 : be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
21014 : passed `int' value. If the debugger then uses that address to fetch
21015 : a `short' or a `char' (on a little-endian machine) the result will be
21016 : the correct data, so we allow for such exceptional cases below.
21017 :
21018 : Note that our goal here is to describe the place where the given formal
21019 : parameter lives during most of the function's activation (i.e. between the
21020 : end of the prologue and the start of the epilogue). We'll do that as best
21021 : as we can. Note however that if the given formal parameter is modified
21022 : sometime during the execution of the function, then a stack backtrace (at
21023 : debug-time) will show the function as having been called with the *new*
21024 : value rather than the value which was originally passed in. This happens
21025 : rarely enough that it is not a major problem, but it *is* a problem, and
21026 : I'd like to fix it.
21027 :
21028 : A future version of dwarf2out.cc may generate two additional attributes for
21029 : any given DW_TAG_formal_parameter DIE which will describe the "passed
21030 : type" and the "passed location" for the given formal parameter in addition
21031 : to the attributes we now generate to indicate the "declared type" and the
21032 : "active location" for each parameter. This additional set of attributes
21033 : could be used by debuggers for stack backtraces. Separately, note that
21034 : sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
21035 : This happens (for example) for inlined-instances of inline function formal
21036 : parameters which are never referenced. This really shouldn't be
21037 : happening. All PARM_DECL nodes should get valid non-NULL
21038 : DECL_INCOMING_RTL values. FIXME. */
21039 :
21040 : /* Use DECL_RTL as the "location" unless we find something better. */
21041 18332480 : rtl = DECL_RTL_IF_SET (decl);
21042 :
21043 : /* When generating abstract instances, ignore everything except
21044 : constants, symbols living in memory, and symbols living in
21045 : fixed registers. */
21046 18332480 : if (! reload_completed)
21047 : {
21048 462537 : if (rtl
21049 452682 : && (CONSTANT_P (rtl)
21050 452682 : || (MEM_P (rtl)
21051 452682 : && CONSTANT_P (XEXP (rtl, 0)))
21052 0 : || (REG_P (rtl)
21053 0 : && VAR_P (decl)
21054 0 : && TREE_STATIC (decl))))
21055 : {
21056 452682 : rtl = targetm.delegitimize_address (rtl);
21057 452682 : return rtl;
21058 : }
21059 : rtl = NULL_RTX;
21060 : }
21061 17869943 : else if (TREE_CODE (decl) == PARM_DECL)
21062 : {
21063 1131836 : if (rtl == NULL_RTX
21064 1131832 : || is_pseudo_reg (rtl)
21065 1496047 : || (MEM_P (rtl)
21066 221869 : && is_pseudo_reg (XEXP (rtl, 0))
21067 22 : && DECL_INCOMING_RTL (decl)
21068 22 : && MEM_P (DECL_INCOMING_RTL (decl))
21069 22 : && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
21070 : {
21071 767647 : tree declared_type = TREE_TYPE (decl);
21072 767647 : tree passed_type = DECL_ARG_TYPE (decl);
21073 767647 : machine_mode dmode = TYPE_MODE (declared_type);
21074 767647 : machine_mode pmode = TYPE_MODE (passed_type);
21075 :
21076 : /* This decl represents a formal parameter which was optimized out.
21077 : Note that DECL_INCOMING_RTL may be NULL in here, but we handle
21078 : all cases where (rtl == NULL_RTX) just below. */
21079 767647 : if (dmode == pmode)
21080 766860 : rtl = DECL_INCOMING_RTL (decl);
21081 787 : else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
21082 787 : && SCALAR_INT_MODE_P (dmode)
21083 1402 : && known_le (GET_MODE_SIZE (dmode), GET_MODE_SIZE (pmode))
21084 1488 : && DECL_INCOMING_RTL (decl))
21085 : {
21086 701 : rtx inc = DECL_INCOMING_RTL (decl);
21087 701 : if (REG_P (inc))
21088 : rtl = inc;
21089 0 : else if (MEM_P (inc))
21090 : {
21091 : if (BYTES_BIG_ENDIAN)
21092 : rtl = adjust_address_nv (inc, dmode,
21093 : GET_MODE_SIZE (pmode)
21094 : - GET_MODE_SIZE (dmode));
21095 : else
21096 : rtl = inc;
21097 : }
21098 : }
21099 : }
21100 :
21101 : /* If the parm was passed in registers, but lives on the stack, then
21102 : make a big endian correction if the mode of the type of the
21103 : parameter is not the same as the mode of the rtl. */
21104 : /* ??? This is the same series of checks that are made in dbxout.cc before
21105 : we reach the big endian correction code there. It isn't clear if all
21106 : of these checks are necessary here, but keeping them all is the safe
21107 : thing to do. */
21108 : else if (MEM_P (rtl)
21109 : && XEXP (rtl, 0) != const0_rtx
21110 : && ! CONSTANT_P (XEXP (rtl, 0))
21111 : /* Not passed in memory. */
21112 : && !MEM_P (DECL_INCOMING_RTL (decl))
21113 : /* Not passed by invisible reference. */
21114 : && (!REG_P (XEXP (rtl, 0))
21115 : || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
21116 : || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
21117 : #if !HARD_FRAME_POINTER_IS_ARG_POINTER
21118 : || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
21119 : #endif
21120 : )
21121 : /* Big endian correction check. */
21122 : && BYTES_BIG_ENDIAN
21123 : && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
21124 : && known_lt (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))),
21125 : UNITS_PER_WORD))
21126 : {
21127 : machine_mode addr_mode = get_address_mode (rtl);
21128 : poly_int64 offset = (UNITS_PER_WORD
21129 : - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
21130 :
21131 : rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
21132 : plus_constant (addr_mode, XEXP (rtl, 0), offset));
21133 : }
21134 : }
21135 16738107 : else if (VAR_P (decl)
21136 16738107 : && rtl
21137 1264485 : && MEM_P (rtl)
21138 17267322 : && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)))
21139 : {
21140 4 : machine_mode addr_mode = get_address_mode (rtl);
21141 4 : poly_int64 offset = byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl)),
21142 4 : GET_MODE (rtl));
21143 :
21144 : /* If a variable is declared "register" yet is smaller than
21145 : a register, then if we store the variable to memory, it
21146 : looks like we're storing a register-sized value, when in
21147 : fact we are not. We need to adjust the offset of the
21148 : storage location to reflect the actual value's bytes,
21149 : else gdb will not be able to display it. */
21150 4 : if (maybe_ne (offset, 0))
21151 0 : rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
21152 : plus_constant (addr_mode, XEXP (rtl, 0), offset));
21153 : }
21154 :
21155 : /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
21156 : and will have been substituted directly into all expressions that use it.
21157 : C does not have such a concept, but C++ and other languages do. */
21158 17879097 : if (!rtl && VAR_P (decl) && DECL_INITIAL (decl))
21159 4776 : rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
21160 :
21161 17879798 : if (rtl)
21162 2396858 : rtl = targetm.delegitimize_address (rtl);
21163 :
21164 : /* If we don't look past the constant pool, we risk emitting a
21165 : reference to a constant pool entry that isn't referenced from
21166 : code, and thus is not emitted. */
21167 2396858 : if (rtl)
21168 2396858 : rtl = avoid_constant_pool_reference (rtl);
21169 :
21170 : /* Try harder to get a rtl. If this symbol ends up not being emitted
21171 : in the current CU, resolve_addr will remove the expression referencing
21172 : it. */
21173 2396858 : if (rtl == NULL_RTX
21174 15482940 : && !(early_dwarf && (flag_generate_lto || flag_generate_offload))
21175 15482786 : && VAR_P (decl)
21176 15481785 : && !DECL_EXTERNAL (decl)
21177 15481785 : && TREE_STATIC (decl)
21178 15964 : && DECL_NAME (decl)
21179 15964 : && !DECL_HARD_REGISTER (decl)
21180 2412822 : && DECL_MODE (decl) != VOIDmode)
21181 : {
21182 15964 : rtl = make_decl_rtl_for_debug (decl);
21183 15964 : if (!MEM_P (rtl)
21184 15964 : || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
21185 31928 : || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
21186 : rtl = NULL_RTX;
21187 : }
21188 :
21189 : return rtl;
21190 : }
21191 :
21192 : /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
21193 : returned. If so, the decl for the COMMON block is returned, and the
21194 : value is the offset into the common block for the symbol. */
21195 :
21196 : static tree
21197 66451819 : fortran_common (tree decl, HOST_WIDE_INT *value)
21198 : {
21199 66451819 : tree val_expr, cvar;
21200 66451819 : machine_mode mode;
21201 66451819 : poly_int64 bitsize, bitpos;
21202 66451819 : tree offset;
21203 66451819 : HOST_WIDE_INT cbitpos;
21204 66451819 : int unsignedp, reversep, volatilep = 0;
21205 :
21206 : /* If the decl isn't a VAR_DECL, or if it isn't static, or if
21207 : it does not have a value (the offset into the common area), or if it
21208 : is thread local (as opposed to global) then it isn't common, and shouldn't
21209 : be handled as such. */
21210 66451819 : if (!VAR_P (decl)
21211 66451819 : || !TREE_STATIC (decl)
21212 61150022 : || !DECL_HAS_VALUE_EXPR_P (decl)
21213 66483578 : || !is_fortran ())
21214 66450697 : return NULL_TREE;
21215 :
21216 1122 : val_expr = DECL_VALUE_EXPR (decl);
21217 1122 : if (TREE_CODE (val_expr) != COMPONENT_REF)
21218 : return NULL_TREE;
21219 :
21220 1122 : cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset, &mode,
21221 : &unsignedp, &reversep, &volatilep);
21222 :
21223 1122 : if (cvar == NULL_TREE
21224 1122 : || !VAR_P (cvar)
21225 1122 : || DECL_ARTIFICIAL (cvar)
21226 1061 : || !TREE_PUBLIC (cvar)
21227 : /* We don't expect to have to cope with variable offsets,
21228 : since at present all static data must have a constant size. */
21229 1122 : || !bitpos.is_constant (&cbitpos))
21230 : return NULL_TREE;
21231 :
21232 1061 : *value = 0;
21233 1061 : if (offset != NULL)
21234 : {
21235 0 : if (!tree_fits_shwi_p (offset))
21236 : return NULL_TREE;
21237 0 : *value = tree_to_shwi (offset);
21238 : }
21239 1061 : if (cbitpos != 0)
21240 719 : *value += cbitpos / BITS_PER_UNIT;
21241 :
21242 : return cvar;
21243 : }
21244 :
21245 : /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
21246 : data attribute for a variable or a parameter. We generate the
21247 : DW_AT_const_value attribute only in those cases where the given variable
21248 : or parameter does not have a true "location" either in memory or in a
21249 : register. This can happen (for example) when a constant is passed as an
21250 : actual argument in a call to an inline function. (It's possible that
21251 : these things can crop up in other ways also.) Note that one type of
21252 : constant value which can be passed into an inlined function is a constant
21253 : pointer. This can happen for example if an actual argument in an inlined
21254 : function call evaluates to a compile-time constant address.
21255 :
21256 : CACHE_P is true if it is worth caching the location list for DECL,
21257 : so that future calls can reuse it rather than regenerate it from scratch.
21258 : This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
21259 : since we will need to refer to them each time the function is inlined. */
21260 :
21261 : static bool
21262 19694488 : add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p)
21263 : {
21264 19694488 : rtx rtl;
21265 19694488 : dw_loc_list_ref list;
21266 19694488 : var_loc_list *loc_list;
21267 19694488 : cached_dw_loc_list *cache;
21268 :
21269 19694488 : if (early_dwarf)
21270 : return false;
21271 :
21272 15726078 : if (TREE_CODE (decl) == ERROR_MARK)
21273 : return false;
21274 :
21275 15726078 : if (get_AT (die, DW_AT_location)
21276 15726078 : || get_AT (die, DW_AT_const_value))
21277 16459 : return true;
21278 :
21279 15709619 : gcc_assert (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL
21280 : || TREE_CODE (decl) == RESULT_DECL);
21281 :
21282 : /* Try to get some constant RTL for this decl, and use that as the value of
21283 : the location. */
21284 :
21285 15709619 : rtl = rtl_for_decl_location (decl);
21286 2174525 : if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
21287 15710018 : && add_const_value_attribute (die, DECL_MODE (decl), rtl))
21288 : return true;
21289 :
21290 : /* See if we have single element location list that is equivalent to
21291 : a constant value. That way we are better to use add_const_value_attribute
21292 : rather than expanding constant value equivalent. */
21293 15709220 : loc_list = lookup_decl_loc (decl);
21294 15709220 : if (loc_list
21295 13022059 : && loc_list->first
21296 13022059 : && loc_list->first->next == NULL
21297 486299 : && NOTE_P (loc_list->first->loc)
21298 482319 : && NOTE_VAR_LOCATION (loc_list->first->loc)
21299 482319 : && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
21300 : {
21301 435214 : struct var_loc_node *node;
21302 :
21303 435214 : node = loc_list->first;
21304 435214 : rtl = NOTE_VAR_LOCATION_LOC (node->loc);
21305 435214 : if (GET_CODE (rtl) == EXPR_LIST)
21306 0 : rtl = XEXP (rtl, 0);
21307 385029 : if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
21308 435476 : && add_const_value_attribute (die, DECL_MODE (decl), rtl))
21309 : return true;
21310 : }
21311 : /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
21312 : list several times. See if we've already cached the contents. */
21313 12973408 : list = NULL;
21314 12973408 : if (loc_list == NULL || cached_dw_loc_list_table == NULL)
21315 : cache_p = false;
21316 12973408 : if (cache_p)
21317 : {
21318 0 : cache = cached_dw_loc_list_table->find_with_hash (decl, DECL_UID (decl));
21319 0 : if (cache)
21320 0 : list = cache->loc_list;
21321 : }
21322 0 : if (list == NULL)
21323 : {
21324 31253736 : list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2,
21325 : NULL);
21326 : /* It is usually worth caching this result if the decl is from
21327 : BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
21328 15660569 : if (cache_p && list && list->dw_loc_next)
21329 : {
21330 0 : cached_dw_loc_list **slot
21331 0 : = cached_dw_loc_list_table->find_slot_with_hash (decl,
21332 0 : DECL_UID (decl),
21333 : INSERT);
21334 0 : cache = ggc_cleared_alloc<cached_dw_loc_list> ();
21335 0 : cache->decl_id = DECL_UID (decl);
21336 0 : cache->loc_list = list;
21337 0 : *slot = cache;
21338 : }
21339 : }
21340 15660569 : if (list)
21341 : {
21342 12797246 : add_AT_location_description (die, DW_AT_location, list);
21343 12797246 : return true;
21344 : }
21345 : /* None of that worked, so it must not really have a location;
21346 : try adding a constant value attribute from the DECL_INITIAL. */
21347 2863323 : return tree_add_const_value_attribute_for_decl (die, decl);
21348 : }
21349 :
21350 : /* Mangle referenced decls. */
21351 : static tree
21352 46484616 : mangle_referenced_decls (tree *tp, int *walk_subtrees, void *)
21353 : {
21354 46484616 : if (! EXPR_P (*tp)
21355 45607898 : && ! CONSTANT_CLASS_P (*tp)
21356 2156119 : && TREE_CODE (*tp) != CONSTRUCTOR)
21357 1688 : *walk_subtrees = 0;
21358 :
21359 46484616 : if (VAR_OR_FUNCTION_DECL_P (*tp))
21360 1318 : assign_assembler_name_if_needed (*tp);
21361 :
21362 46484616 : return NULL_TREE;
21363 : }
21364 :
21365 : /* Attach a DW_AT_const_value attribute to DIE. The value of the
21366 : attribute is the const value T. */
21367 :
21368 : static bool
21369 39709508 : tree_add_const_value_attribute (dw_die_ref die, tree t)
21370 : {
21371 39709508 : tree init;
21372 39709508 : tree type = TREE_TYPE (t);
21373 :
21374 39709508 : if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
21375 : return false;
21376 :
21377 39709507 : init = t;
21378 39709507 : gcc_assert (!DECL_P (init));
21379 :
21380 39709507 : if (TREE_CODE (init) == INTEGER_CST)
21381 : {
21382 37416606 : if (tree_fits_uhwi_p (init))
21383 : {
21384 37207356 : add_AT_unsigned (die, DW_AT_const_value, tree_to_uhwi (init));
21385 37207356 : return true;
21386 : }
21387 209250 : if (tree_fits_shwi_p (init))
21388 : {
21389 209231 : add_AT_int (die, DW_AT_const_value, tree_to_shwi (init));
21390 209231 : return true;
21391 : }
21392 : }
21393 2292920 : if (!early_dwarf)
21394 : {
21395 142248 : rtx rtl = rtl_for_decl_init (init, type);
21396 142248 : if (rtl)
21397 3413 : return add_const_value_attribute (die, TYPE_MODE (type), rtl);
21398 : }
21399 : else
21400 : {
21401 : /* For early_dwarf force mangling of all referenced symbols. */
21402 2150672 : tree initializer = init;
21403 2150672 : STRIP_NOPS (initializer);
21404 2150672 : if (initializer_constant_valid_p (initializer, type))
21405 2150671 : walk_tree (&initializer, mangle_referenced_decls, NULL, NULL);
21406 : }
21407 : /* If the host and target are sane, try harder. */
21408 2289507 : if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
21409 2289507 : && initializer_constant_valid_p (init, type))
21410 : {
21411 2289505 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
21412 2289505 : if (size > 0 && (int) size == size)
21413 : {
21414 2289446 : unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
21415 :
21416 2289446 : if (native_encode_initializer (init, array, size) == size)
21417 : {
21418 2275516 : add_AT_vec (die, DW_AT_const_value, size, 1, array);
21419 2275516 : return true;
21420 : }
21421 13930 : ggc_free (array);
21422 : }
21423 : }
21424 : return false;
21425 : }
21426 :
21427 : /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
21428 : attribute is the const value of T, where T is an integral constant
21429 : variable with static storage duration
21430 : (so it can't be a PARM_DECL or a RESULT_DECL). */
21431 :
21432 : static bool
21433 63948670 : tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
21434 : {
21435 :
21436 63948670 : if (!decl
21437 63948670 : || (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
21438 63948035 : || (VAR_P (decl) && !TREE_STATIC (decl)))
21439 : return false;
21440 :
21441 60482471 : if (TREE_READONLY (decl)
21442 60227020 : && ! TREE_THIS_VOLATILE (decl)
21443 120709325 : && DECL_INITIAL (decl))
21444 : /* OK */;
21445 : else
21446 : return false;
21447 :
21448 : /* Don't add DW_AT_const_value if abstract origin already has one. */
21449 56099622 : if (get_AT (var_die, DW_AT_const_value))
21450 : return false;
21451 :
21452 28730841 : return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
21453 : }
21454 :
21455 : /* Convert the CFI instructions for the current function into a
21456 : location list. This is used for DW_AT_frame_base when we targeting
21457 : a dwarf2 consumer that does not support the dwarf3
21458 : DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
21459 : expressions. */
21460 :
21461 : static dw_loc_list_ref
21462 3445 : convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
21463 : {
21464 3445 : int ix;
21465 3445 : dw_fde_ref fde;
21466 3445 : dw_loc_list_ref list, *list_tail;
21467 3445 : dw_cfi_ref cfi;
21468 3445 : dw_cfa_location last_cfa, next_cfa;
21469 3445 : const char *start_label, *last_label, *section;
21470 3445 : dw_cfa_location remember;
21471 :
21472 3445 : fde = cfun->fde;
21473 3445 : gcc_assert (fde != NULL);
21474 :
21475 3445 : section = secname_for_decl (current_function_decl);
21476 3445 : list_tail = &list;
21477 3445 : list = NULL;
21478 :
21479 3445 : memset (&next_cfa, 0, sizeof (next_cfa));
21480 :
21481 : #ifdef CODEVIEW_DEBUGGING_INFO
21482 : /* We can write simplified frame base information for CodeView, as we're
21483 : not using it for rewinding. */
21484 : if (codeview_debuginfo_p ())
21485 : {
21486 : int dwreg = DEBUGGER_REGNO (cfun->machine->fs.cfa_reg->u.reg.regno);
21487 :
21488 : next_cfa.reg.set_by_dwreg (dwreg);
21489 : next_cfa.offset = cfun->machine->fs.fp_valid
21490 : ? cfun->machine->fs.fp_offset : cfun->machine->fs.sp_offset;
21491 :
21492 : *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
21493 : fde->dw_fde_begin, 0,
21494 : fde->dw_fde_second_begin
21495 : ? fde->dw_fde_second_end : fde->dw_fde_end, 0,
21496 : section);
21497 : maybe_gen_llsym (list);
21498 :
21499 : return list;
21500 : }
21501 : #endif
21502 :
21503 3445 : next_cfa.reg.set_by_dwreg (INVALID_REGNUM);
21504 3445 : remember = next_cfa;
21505 :
21506 3445 : start_label = fde->dw_fde_begin;
21507 :
21508 : /* ??? Bald assumption that the CIE opcode list does not contain
21509 : advance opcodes. */
21510 10335 : FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
21511 6890 : lookup_cfa_1 (cfi, &next_cfa, &remember);
21512 :
21513 3445 : last_cfa = next_cfa;
21514 3445 : last_label = start_label;
21515 :
21516 3445 : if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
21517 : {
21518 : /* If the first partition contained no CFI adjustments, the
21519 : CIE opcodes apply to the whole first partition. */
21520 0 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21521 : fde->dw_fde_begin, 0, fde->dw_fde_end, 0, section);
21522 0 : list_tail =&(*list_tail)->dw_loc_next;
21523 0 : start_label = last_label = fde->dw_fde_second_begin;
21524 : }
21525 :
21526 19709 : FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
21527 : {
21528 16264 : switch (cfi->dw_cfi_opc)
21529 : {
21530 5794 : case DW_CFA_set_loc:
21531 5794 : case DW_CFA_advance_loc1:
21532 5794 : case DW_CFA_advance_loc2:
21533 5794 : case DW_CFA_advance_loc4:
21534 5794 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21535 : {
21536 3886 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21537 : start_label, 0, last_label, 0, section);
21538 :
21539 3886 : list_tail = &(*list_tail)->dw_loc_next;
21540 3886 : last_cfa = next_cfa;
21541 3886 : start_label = last_label;
21542 : }
21543 5794 : last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
21544 5794 : break;
21545 :
21546 0 : case DW_CFA_advance_loc:
21547 : /* The encoding is complex enough that we should never emit this. */
21548 0 : gcc_unreachable ();
21549 :
21550 10470 : default:
21551 10470 : lookup_cfa_1 (cfi, &next_cfa, &remember);
21552 10470 : break;
21553 : }
21554 16264 : if (ix + 1 == fde->dw_fde_switch_cfi_index)
21555 : {
21556 57 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21557 : {
21558 47 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21559 : start_label, 0, last_label, 0, section);
21560 :
21561 47 : list_tail = &(*list_tail)->dw_loc_next;
21562 47 : last_cfa = next_cfa;
21563 47 : start_label = last_label;
21564 : }
21565 57 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21566 : start_label, 0, fde->dw_fde_end, 0, section);
21567 57 : list_tail = &(*list_tail)->dw_loc_next;
21568 57 : start_label = last_label = fde->dw_fde_second_begin;
21569 : }
21570 : }
21571 :
21572 3445 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21573 : {
21574 1824 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21575 : start_label, 0, last_label, 0, section);
21576 1824 : list_tail = &(*list_tail)->dw_loc_next;
21577 1824 : start_label = last_label;
21578 : }
21579 :
21580 3445 : *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
21581 : start_label, 0,
21582 3445 : fde->dw_fde_second_begin
21583 : ? fde->dw_fde_second_end : fde->dw_fde_end, 0,
21584 : section);
21585 :
21586 3445 : maybe_gen_llsym (list);
21587 :
21588 3445 : return list;
21589 : }
21590 :
21591 : /* Compute a displacement from the "steady-state frame pointer" to the
21592 : frame base (often the same as the CFA), and store it in
21593 : frame_pointer_fb_offset. OFFSET is added to the displacement
21594 : before the latter is negated. */
21595 :
21596 : static void
21597 560209 : compute_frame_pointer_to_fb_displacement (poly_int64 offset)
21598 : {
21599 560209 : rtx reg, elim;
21600 :
21601 : #ifdef FRAME_POINTER_CFA_OFFSET
21602 : reg = frame_pointer_rtx;
21603 : offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
21604 : #else
21605 560209 : reg = arg_pointer_rtx;
21606 560209 : offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
21607 : #endif
21608 :
21609 560209 : elim = (ira_use_lra_p
21610 560209 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
21611 0 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
21612 560209 : elim = strip_offset_and_add (elim, &offset);
21613 :
21614 560209 : frame_pointer_fb_offset = -offset;
21615 :
21616 : /* ??? AVR doesn't set up valid eliminations when there is no stack frame
21617 : in which to eliminate. This is because it's stack pointer isn't
21618 : directly accessible as a register within the ISA. To work around
21619 : this, assume that while we cannot provide a proper value for
21620 : frame_pointer_fb_offset, we won't need one either. We can use
21621 : hard frame pointer in debug info even if frame pointer isn't used
21622 : since hard frame pointer in debug info is encoded with DW_OP_fbreg
21623 : which uses the DW_AT_frame_base attribute, not hard frame pointer
21624 : directly. */
21625 560209 : frame_pointer_fb_offset_valid
21626 560209 : = (elim == hard_frame_pointer_rtx || elim == stack_pointer_rtx);
21627 560209 : }
21628 :
21629 : /* Generate a DW_AT_name attribute given some string value to be included as
21630 : the value of the attribute. */
21631 :
21632 : void
21633 277963351 : add_name_attribute (dw_die_ref die, const char *name_string)
21634 : {
21635 277963351 : if (name_string != NULL && *name_string != 0)
21636 : {
21637 274348827 : if (demangle_name_func)
21638 0 : name_string = (*demangle_name_func) (name_string);
21639 :
21640 274348827 : add_AT_string (die, DW_AT_name, name_string);
21641 : }
21642 277963351 : }
21643 :
21644 : /* Generate a DW_AT_name attribute given some string value representing a
21645 : file or filepath to be included as value of the attribute. */
21646 : static void
21647 53202 : add_filename_attribute (dw_die_ref die, const char *name_string)
21648 : {
21649 53202 : if (name_string != NULL && *name_string != 0)
21650 53202 : add_filepath_AT_string (die, DW_AT_name, name_string);
21651 53202 : }
21652 :
21653 : /* Generate a DW_AT_description attribute given some string value to be included
21654 : as the value of the attribute. */
21655 :
21656 : static void
21657 0 : add_desc_attribute (dw_die_ref die, const char *name_string)
21658 : {
21659 0 : if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
21660 : return;
21661 :
21662 0 : if (name_string == NULL || *name_string == 0)
21663 : return;
21664 :
21665 0 : if (demangle_name_func)
21666 0 : name_string = (*demangle_name_func) (name_string);
21667 :
21668 0 : add_AT_string (die, DW_AT_description, name_string);
21669 : }
21670 :
21671 : /* Generate a DW_AT_description attribute given some decl to be included
21672 : as the value of the attribute. */
21673 :
21674 : static void
21675 3447716 : add_desc_attribute (dw_die_ref die, tree decl)
21676 : {
21677 3447716 : tree decl_name;
21678 :
21679 3447716 : if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
21680 : return;
21681 :
21682 0 : if (decl == NULL_TREE || !DECL_P (decl))
21683 : return;
21684 0 : decl_name = DECL_NAME (decl);
21685 :
21686 0 : if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
21687 : {
21688 0 : const char *name = dwarf2_name (decl, 0);
21689 0 : add_desc_attribute (die, name ? name : IDENTIFIER_POINTER (decl_name));
21690 : }
21691 : else
21692 : {
21693 0 : char *desc = print_generic_expr_to_str (decl);
21694 0 : add_desc_attribute (die, desc);
21695 0 : free (desc);
21696 : }
21697 : }
21698 :
21699 : /* Retrieve the descriptive type of TYPE, if any, make sure it has a
21700 : DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
21701 : of TYPE accordingly.
21702 :
21703 : ??? This is a temporary measure until after we're able to generate
21704 : regular DWARF for the complex Ada type system. */
21705 :
21706 : static void
21707 98274030 : add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
21708 : dw_die_ref context_die)
21709 : {
21710 98274030 : tree dtype;
21711 98274030 : dw_die_ref dtype_die;
21712 :
21713 98274030 : if (!lang_hooks.types.descriptive_type)
21714 : return;
21715 :
21716 0 : dtype = lang_hooks.types.descriptive_type (type);
21717 0 : if (!dtype)
21718 : return;
21719 :
21720 0 : dtype_die = lookup_type_die (dtype);
21721 0 : if (!dtype_die)
21722 : {
21723 0 : gen_type_die (dtype, context_die);
21724 0 : dtype_die = lookup_type_die (dtype);
21725 0 : gcc_assert (dtype_die);
21726 : }
21727 :
21728 0 : add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
21729 : }
21730 :
21731 : /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
21732 :
21733 : static const char *
21734 105385 : comp_dir_string (void)
21735 : {
21736 105385 : const char *wd;
21737 105385 : char *wd_plus_sep = NULL;
21738 105385 : static const char *cached_wd = NULL;
21739 :
21740 105385 : if (cached_wd != NULL)
21741 : return cached_wd;
21742 :
21743 52498 : wd = get_src_pwd ();
21744 52498 : if (wd == NULL)
21745 : return NULL;
21746 :
21747 52498 : if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
21748 : {
21749 : size_t wdlen = strlen (wd);
21750 : wd_plus_sep = XNEWVEC (char, wdlen + 2);
21751 : strcpy (wd_plus_sep, wd);
21752 : wd_plus_sep [wdlen] = DIR_SEPARATOR;
21753 : wd_plus_sep [wdlen + 1] = 0;
21754 : wd = wd_plus_sep;
21755 : }
21756 :
21757 52498 : cached_wd = remap_debug_filename (wd);
21758 :
21759 : /* remap_debug_filename can just pass through wd or return a new gc string.
21760 : These two types can't be both stored in a GTY(())-tagged string, but since
21761 : the cached value lives forever just copy it if needed. */
21762 52498 : if (cached_wd != wd)
21763 : {
21764 184 : cached_wd = xstrdup (cached_wd);
21765 184 : if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR && wd_plus_sep != NULL)
21766 : free (wd_plus_sep);
21767 : }
21768 :
21769 52498 : return cached_wd;
21770 : }
21771 :
21772 : /* Generate a DW_AT_comp_dir attribute for DIE. */
21773 :
21774 : static void
21775 53202 : add_comp_dir_attribute (dw_die_ref die)
21776 : {
21777 53202 : const char * wd = comp_dir_string ();
21778 53202 : if (wd != NULL)
21779 53202 : add_filepath_AT_string (die, DW_AT_comp_dir, wd);
21780 53202 : }
21781 :
21782 : /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
21783 : pointer computation, ...), output a representation for that bound according
21784 : to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
21785 : loc_list_from_tree for the meaning of CONTEXT. */
21786 :
21787 : static void
21788 1008094 : add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
21789 : int forms, struct loc_descr_context *context)
21790 : {
21791 1008094 : dw_die_ref context_die, decl_die = NULL;
21792 1008094 : dw_loc_list_ref list;
21793 1008094 : bool strip_conversions = true;
21794 1008094 : bool placeholder_seen = false;
21795 :
21796 1008094 : while (strip_conversions)
21797 1008094 : switch (TREE_CODE (value))
21798 : {
21799 : case ERROR_MARK:
21800 : case SAVE_EXPR:
21801 : return;
21802 :
21803 0 : CASE_CONVERT:
21804 0 : case VIEW_CONVERT_EXPR:
21805 0 : value = TREE_OPERAND (value, 0);
21806 0 : break;
21807 :
21808 : default:
21809 : strip_conversions = false;
21810 : break;
21811 : }
21812 :
21813 : /* If possible and permitted, output the attribute as a constant. */
21814 1008094 : if ((forms & dw_scalar_form_constant) != 0
21815 1001158 : && TREE_CODE (value) == INTEGER_CST)
21816 : {
21817 965881 : unsigned int prec = simple_type_size_in_bits (TREE_TYPE (value));
21818 :
21819 : /* If HOST_WIDE_INT is big enough then represent the bound as
21820 : a constant value. We need to choose a form based on
21821 : whether the type is signed or unsigned. We cannot just
21822 : call add_AT_unsigned if the value itself is positive
21823 : (add_AT_unsigned might add the unsigned value encoded as
21824 : DW_FORM_data[1248]). Some DWARF consumers will lookup the
21825 : bounds type and then sign extend any unsigned values found
21826 : for signed types. This is needed only for
21827 : DW_AT_{lower,upper}_bound, since for most other attributes,
21828 : consumers will treat DW_FORM_data[1248] as unsigned values,
21829 : regardless of the underlying type. */
21830 965881 : if (prec <= HOST_BITS_PER_WIDE_INT
21831 0 : || tree_fits_uhwi_p (value))
21832 : {
21833 965881 : if (TYPE_UNSIGNED (TREE_TYPE (value)))
21834 948982 : add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
21835 : else
21836 16899 : add_AT_int (die, attr, TREE_INT_CST_LOW (value));
21837 : }
21838 0 : else if (dwarf_version >= 5
21839 0 : && TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (value))) == 128)
21840 : /* Otherwise represent the bound as an unsigned value with
21841 : the precision of its type. The precision and signedness
21842 : of the type will be necessary to re-interpret it
21843 : unambiguously. */
21844 0 : add_AT_wide (die, attr, wi::to_wide (value));
21845 : else
21846 : {
21847 0 : rtx v = immed_wide_int_const (wi::to_wide (value),
21848 0 : TYPE_MODE (TREE_TYPE (value)));
21849 0 : dw_loc_descr_ref loc
21850 0 : = loc_descriptor (v, TYPE_MODE (TREE_TYPE (value)),
21851 : VAR_INIT_STATUS_INITIALIZED);
21852 0 : if (loc)
21853 0 : add_AT_loc (die, attr, loc);
21854 : }
21855 965881 : return;
21856 : }
21857 :
21858 : /* Otherwise, if it's possible and permitted too, output a reference to
21859 : another DIE. */
21860 42213 : if ((forms & dw_scalar_form_reference) != 0)
21861 : {
21862 34246 : tree decl = NULL_TREE;
21863 :
21864 : /* Some type attributes reference an outer type. For instance, the upper
21865 : bound of an array may reference an embedding record (this happens in
21866 : Ada). */
21867 34246 : if (TREE_CODE (value) == COMPONENT_REF
21868 0 : && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
21869 34246 : && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
21870 0 : decl = TREE_OPERAND (value, 1);
21871 :
21872 34246 : else if (VAR_P (value)
21873 : || TREE_CODE (value) == PARM_DECL
21874 : || TREE_CODE (value) == RESULT_DECL)
21875 : decl = value;
21876 :
21877 0 : if (decl != NULL_TREE)
21878 : {
21879 5155 : decl_die = lookup_decl_die (decl);
21880 :
21881 : /* ??? Can this happen, or should the variable have been bound
21882 : first? Probably it can, since I imagine that we try to create
21883 : the types of parameters in the order in which they exist in
21884 : the list, and won't have created a forward reference to a
21885 : later parameter. */
21886 5155 : if (decl_die != NULL)
21887 : {
21888 3158 : if (get_AT (decl_die, DW_AT_location)
21889 3131 : || get_AT (decl_die, DW_AT_data_member_location)
21890 3131 : || get_AT (decl_die, DW_AT_data_bit_offset)
21891 6289 : || get_AT (decl_die, DW_AT_const_value))
21892 : {
21893 42 : add_AT_die_ref (die, attr, decl_die);
21894 42 : return;
21895 : }
21896 : }
21897 : }
21898 : }
21899 :
21900 : /* Last chance: try to create a stack operation procedure to evaluate the
21901 : value. Do nothing if even that is not possible or permitted. */
21902 42171 : if ((forms & dw_scalar_form_exprloc) == 0)
21903 : return;
21904 :
21905 42171 : list = loc_list_from_tree (value, 2, context);
21906 42171 : if (context && context->placeholder_arg)
21907 : {
21908 3093 : placeholder_seen = context->placeholder_seen;
21909 3093 : context->placeholder_seen = false;
21910 : }
21911 42171 : if (list == NULL || single_element_loc_list_p (list))
21912 : {
21913 : /* If this attribute is not a reference nor constant, it is
21914 : a DWARF expression rather than location description. For that
21915 : loc_list_from_tree (value, 0, &context) is needed. */
21916 41398 : dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
21917 41398 : if (list2 && single_element_loc_list_p (list2))
21918 : {
21919 41126 : if (placeholder_seen)
21920 : {
21921 3093 : struct dwarf_procedure_info dpi;
21922 3093 : dpi.fndecl = NULL_TREE;
21923 3093 : dpi.args_count = 1;
21924 3093 : if (!resolve_args_picking (list2->expr, 1, &dpi))
21925 0 : return;
21926 : }
21927 41126 : add_AT_loc (die, attr, list2->expr);
21928 41126 : return;
21929 : }
21930 : }
21931 :
21932 : /* If that failed to give a single element location list, fall back to
21933 : outputting this as a reference... still if permitted. */
21934 1045 : if (list == NULL
21935 773 : || (forms & dw_scalar_form_reference) == 0
21936 773 : || placeholder_seen)
21937 : return;
21938 :
21939 773 : if (!decl_die)
21940 : {
21941 422 : if (current_function_decl == 0)
21942 0 : context_die = comp_unit_die ();
21943 : else
21944 422 : context_die = lookup_decl_die (current_function_decl);
21945 :
21946 422 : decl_die = new_die (DW_TAG_variable, context_die, value);
21947 422 : add_AT_flag (decl_die, DW_AT_artificial, 1);
21948 422 : add_type_attribute (decl_die, TREE_TYPE (value), TYPE_QUAL_CONST, false,
21949 : context_die);
21950 : }
21951 :
21952 773 : add_AT_location_description (decl_die, DW_AT_location, list);
21953 773 : add_AT_die_ref (die, attr, decl_die);
21954 : }
21955 :
21956 : /* Return the default for DW_AT_lower_bound, or -1 if there is not any
21957 : default. */
21958 :
21959 : static int
21960 987634 : lower_bound_default (void)
21961 : {
21962 987634 : switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
21963 : {
21964 : case DW_LANG_C:
21965 : case DW_LANG_C89:
21966 : case DW_LANG_C99:
21967 : case DW_LANG_C11:
21968 : case DW_LANG_C_plus_plus:
21969 : case DW_LANG_C_plus_plus_11:
21970 : case DW_LANG_C_plus_plus_14:
21971 : case DW_LANG_ObjC:
21972 : case DW_LANG_ObjC_plus_plus:
21973 : return 0;
21974 : case DW_LANG_Fortran77:
21975 : case DW_LANG_Fortran90:
21976 : case DW_LANG_Fortran95:
21977 : case DW_LANG_Fortran03:
21978 : case DW_LANG_Fortran08:
21979 : return 1;
21980 0 : case DW_LANG_UPC:
21981 0 : case DW_LANG_D:
21982 0 : case DW_LANG_Python:
21983 0 : return dwarf_version >= 4 ? 0 : -1;
21984 2413 : case DW_LANG_Ada95:
21985 2413 : case DW_LANG_Ada83:
21986 2413 : case DW_LANG_Cobol74:
21987 2413 : case DW_LANG_Cobol85:
21988 2413 : case DW_LANG_Modula2:
21989 2413 : case DW_LANG_PLI:
21990 2413 : return dwarf_version >= 4 ? 1 : -1;
21991 : default:
21992 : return -1;
21993 : }
21994 : }
21995 :
21996 : /* Given a tree node describing an array bound (either lower or upper) output
21997 : a representation for that bound. */
21998 :
21999 : static void
22000 1938379 : add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
22001 : tree bound, struct loc_descr_context *context)
22002 : {
22003 1938419 : int dflt;
22004 :
22005 1938459 : while (1)
22006 1938419 : switch (TREE_CODE (bound))
22007 : {
22008 : /* Strip all conversions. */
22009 40 : CASE_CONVERT:
22010 40 : case VIEW_CONVERT_EXPR:
22011 40 : bound = TREE_OPERAND (bound, 0);
22012 40 : break;
22013 :
22014 : /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
22015 : are even omitted when they are the default. */
22016 1917293 : case INTEGER_CST:
22017 : /* If the value for this bound is the default one, we can even omit the
22018 : attribute. */
22019 1917293 : if (bound_attr == DW_AT_lower_bound
22020 967289 : && tree_fits_shwi_p (bound)
22021 967289 : && (dflt = lower_bound_default ()) != -1
22022 2874825 : && tree_to_shwi (bound) == dflt)
22023 : return;
22024 :
22025 : /* FALLTHRU */
22026 :
22027 986967 : default:
22028 : /* Let GNAT encodings do the magic for self-referential bounds. */
22029 986967 : if (is_ada ()
22030 0 : && gnat_encodings == DWARF_GNAT_ENCODINGS_ALL
22031 986967 : && contains_placeholder_p (bound))
22032 : return;
22033 :
22034 986967 : add_scalar_info (subrange_die, bound_attr, bound,
22035 : dw_scalar_form_constant
22036 : | dw_scalar_form_exprloc
22037 : | dw_scalar_form_reference,
22038 : context);
22039 986967 : return;
22040 : }
22041 : }
22042 :
22043 : /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
22044 : possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
22045 :
22046 : This function reuses previously set type and bound information if
22047 : available. */
22048 :
22049 : static void
22050 1015882 : add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
22051 : {
22052 1015882 : dw_die_ref child = type_die->die_child;
22053 1015882 : struct array_descr_info info;
22054 1015882 : int dimension_number;
22055 :
22056 1015882 : if (lang_hooks.types.get_array_descr_info)
22057 : {
22058 13962 : memset (&info, 0, sizeof (info));
22059 13962 : if (lang_hooks.types.get_array_descr_info (type, &info))
22060 : /* Fortran sometimes emits array types with no dimension. */
22061 0 : gcc_assert (info.ndimensions >= 0
22062 : && info.ndimensions
22063 : <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN);
22064 : }
22065 : else
22066 1001920 : info.ndimensions = 0;
22067 :
22068 : for (dimension_number = 0;
22069 2036747 : TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
22070 1020865 : type = TREE_TYPE (type), dimension_number++)
22071 : {
22072 1022001 : tree domain = TYPE_DOMAIN (type);
22073 :
22074 1022001 : if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
22075 : break;
22076 :
22077 : /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
22078 : and (in GNU C only) variable bounds. Handle all three forms
22079 : here. */
22080 :
22081 : /* Find and reuse a previously generated DW_TAG_subrange_type if
22082 : available.
22083 :
22084 : For multi-dimensional arrays, as we iterate through the
22085 : various dimensions in the enclosing for loop above, we also
22086 : iterate through the DIE children and pick at each
22087 : DW_TAG_subrange_type previously generated (if available).
22088 : Each child DW_TAG_subrange_type DIE describes the range of
22089 : the current dimension. At this point we should have as many
22090 : DW_TAG_subrange_type's as we have dimensions in the
22091 : array. */
22092 1020865 : dw_die_ref subrange_die = NULL;
22093 1020865 : if (child)
22094 5083 : while (1)
22095 : {
22096 5083 : child = child->die_sib;
22097 5083 : if (child->die_tag == DW_TAG_subrange_type)
22098 5083 : subrange_die = child;
22099 5083 : if (child == type_die->die_child)
22100 : {
22101 : /* If we wrapped around, stop looking next time. */
22102 : child = NULL;
22103 : break;
22104 : }
22105 843 : if (child->die_tag == DW_TAG_subrange_type)
22106 : break;
22107 : }
22108 5083 : if (!subrange_die)
22109 1015782 : subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
22110 :
22111 1020865 : if (domain)
22112 : {
22113 : /* We have an array type with specified bounds. */
22114 945162 : tree lower = TYPE_MIN_VALUE (domain);
22115 945162 : tree upper = TYPE_MAX_VALUE (domain);
22116 945162 : tree index_type = TREE_TYPE (domain);
22117 :
22118 945162 : if (dimension_number <= info.ndimensions - 1)
22119 : {
22120 0 : lower = info.dimen[dimension_number].lower_bound;
22121 0 : upper = info.dimen[dimension_number].upper_bound;
22122 0 : index_type = info.dimen[dimension_number].bounds_type;
22123 : }
22124 :
22125 : /* Define the index type. */
22126 945162 : if (index_type && !get_AT (subrange_die, DW_AT_type))
22127 940080 : add_type_attribute (subrange_die, index_type, TYPE_UNQUALIFIED,
22128 : false, type_die);
22129 :
22130 : /* ??? If upper is NULL, the array has unspecified length,
22131 : but it does have a lower bound. This happens with Fortran
22132 : dimension arr(N:*)
22133 : Since the debugger is definitely going to need to know N
22134 : to produce useful results, go ahead and output the lower
22135 : bound solo, and hope the debugger can cope. */
22136 :
22137 945162 : if (lower && !get_AT (subrange_die, DW_AT_lower_bound))
22138 944484 : add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
22139 :
22140 945162 : if (!get_AT (subrange_die, DW_AT_upper_bound)
22141 945162 : && !get_AT (subrange_die, DW_AT_count))
22142 : {
22143 940150 : if (upper)
22144 933631 : add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
22145 6519 : else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type))
22146 : /* Zero-length array. */
22147 1062 : add_bound_info (subrange_die, DW_AT_count,
22148 1062 : build_int_cst (TREE_TYPE (lower), 0), NULL);
22149 : }
22150 : }
22151 :
22152 : /* Otherwise we have an array type with an unspecified length. The
22153 : DWARF-2 spec does not say how to handle this; let's just leave out the
22154 : bounds. */
22155 : }
22156 1015882 : }
22157 :
22158 : /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
22159 :
22160 : static void
22161 52723782 : add_byte_size_attribute (dw_die_ref die, tree tree_node)
22162 : {
22163 52723782 : dw_die_ref decl_die;
22164 52723782 : HOST_WIDE_INT size;
22165 :
22166 52723782 : switch (TREE_CODE (tree_node))
22167 : {
22168 : case ERROR_MARK:
22169 : size = 0;
22170 : break;
22171 52236080 : case ENUMERAL_TYPE:
22172 52236080 : case RECORD_TYPE:
22173 52236080 : case UNION_TYPE:
22174 52236080 : case QUAL_UNION_TYPE:
22175 52236080 : if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
22176 52236080 : && (decl_die = lookup_decl_die (TYPE_SIZE_UNIT (tree_node))))
22177 : {
22178 0 : add_AT_die_ref (die, DW_AT_byte_size, decl_die);
22179 0 : return;
22180 : }
22181 52236080 : size = int_size_in_bytes (tree_node);
22182 52236080 : break;
22183 487702 : case FIELD_DECL:
22184 : /* For a data member of a struct or union, the DW_AT_byte_size is
22185 : generally given as the number of bytes normally allocated for an
22186 : object of the *declared* type of the member itself. This is true
22187 : even for bit-fields. */
22188 487702 : size = int_size_in_bytes (field_type (tree_node));
22189 487702 : break;
22190 0 : default:
22191 0 : gcc_unreachable ();
22192 : }
22193 :
22194 : /* Note that `size' might be -1 when we get to this point. If it is, that
22195 : indicates that the byte size of the entity in question is variable. */
22196 52723782 : if (size >= 0)
22197 52723691 : add_AT_unsigned (die, DW_AT_byte_size, size);
22198 :
22199 : /* Support for dynamically-sized objects was introduced in DWARF3. */
22200 91 : else if (TYPE_P (tree_node)
22201 91 : && (dwarf_version >= 3 || !dwarf_strict)
22202 91 : && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL)
22203 : {
22204 91 : struct loc_descr_context ctx = {
22205 : const_cast<tree> (tree_node), /* context_type */
22206 : NULL_TREE, /* base_decl */
22207 : NULL, /* dpi */
22208 : false, /* placeholder_arg */
22209 : false, /* placeholder_seen */
22210 : false /* strict_signedness */
22211 91 : };
22212 :
22213 91 : tree tree_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (tree_node));
22214 91 : add_scalar_info (die, DW_AT_byte_size, tree_size,
22215 : dw_scalar_form_constant
22216 : | dw_scalar_form_exprloc
22217 : | dw_scalar_form_reference,
22218 : &ctx);
22219 : }
22220 : }
22221 :
22222 : /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
22223 : alignment. */
22224 :
22225 : static void
22226 283485820 : add_alignment_attribute (dw_die_ref die, tree tree_node)
22227 : {
22228 283485820 : if (dwarf_version < 5 && dwarf_strict)
22229 : return;
22230 :
22231 283485761 : unsigned align;
22232 :
22233 283485761 : if (DECL_P (tree_node))
22234 : {
22235 145937421 : if (!DECL_USER_ALIGN (tree_node))
22236 : return;
22237 :
22238 429878 : align = DECL_ALIGN_UNIT (tree_node);
22239 : }
22240 137548340 : else if (TYPE_P (tree_node))
22241 : {
22242 137548340 : if (!TYPE_USER_ALIGN (tree_node))
22243 : return;
22244 :
22245 1035661 : align = TYPE_ALIGN_UNIT (tree_node);
22246 : }
22247 : else
22248 0 : gcc_unreachable ();
22249 :
22250 1465539 : add_AT_unsigned (die, DW_AT_alignment, align);
22251 : }
22252 :
22253 : /* For a FIELD_DECL node which represents a bit-field, output an attribute
22254 : which specifies the distance in bits from the highest order bit of the
22255 : "containing object" for the bit-field to the highest order bit of the
22256 : bit-field itself.
22257 :
22258 : For any given bit-field, the "containing object" is a hypothetical object
22259 : (of some integral or enum type) within which the given bit-field lives. The
22260 : type of this hypothetical "containing object" is always the same as the
22261 : declared type of the individual bit-field itself. The determination of the
22262 : exact location of the "containing object" for a bit-field is rather
22263 : complicated. It's handled by the `field_byte_offset' function (above).
22264 :
22265 : Note that it is the size (in bytes) of the hypothetical "containing object"
22266 : which will be given in the DW_AT_byte_size attribute for this bit-field.
22267 : (See `byte_size_attribute' above). */
22268 :
22269 : static inline void
22270 487702 : add_bit_offset_attribute (dw_die_ref die, tree decl)
22271 : {
22272 487702 : HOST_WIDE_INT object_offset_in_bytes;
22273 487702 : tree original_type = DECL_BIT_FIELD_TYPE (decl);
22274 487702 : HOST_WIDE_INT bitpos_int;
22275 487702 : HOST_WIDE_INT highest_order_object_bit_offset;
22276 487702 : HOST_WIDE_INT highest_order_field_bit_offset;
22277 487702 : HOST_WIDE_INT bit_offset;
22278 :
22279 : /* The containing object is within the DECL_CONTEXT. */
22280 487702 : struct vlr_context ctx = { DECL_CONTEXT (decl), NULL_TREE };
22281 :
22282 487702 : field_byte_offset (decl, &ctx, &object_offset_in_bytes);
22283 :
22284 : /* Must be a field and a bit field. */
22285 487702 : gcc_assert (original_type && TREE_CODE (decl) == FIELD_DECL);
22286 :
22287 : /* We can't yet handle bit-fields whose offsets are variable, so if we
22288 : encounter such things, just return without generating any attribute
22289 : whatsoever. Likewise for variable or too large size. */
22290 487702 : if (! tree_fits_shwi_p (bit_position (decl))
22291 487702 : || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
22292 16 : return;
22293 :
22294 487686 : bitpos_int = int_bit_position (decl);
22295 :
22296 : /* Note that the bit offset is always the distance (in bits) from the
22297 : highest-order bit of the "containing object" to the highest-order bit of
22298 : the bit-field itself. Since the "high-order end" of any object or field
22299 : is different on big-endian and little-endian machines, the computation
22300 : below must take account of these differences. */
22301 487686 : highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
22302 487686 : highest_order_field_bit_offset = bitpos_int;
22303 :
22304 487686 : if (! BYTES_BIG_ENDIAN)
22305 : {
22306 487686 : highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
22307 975372 : highest_order_object_bit_offset +=
22308 487686 : simple_type_size_in_bits (original_type);
22309 : }
22310 :
22311 487686 : bit_offset
22312 487686 : = (! BYTES_BIG_ENDIAN
22313 : ? highest_order_object_bit_offset - highest_order_field_bit_offset
22314 : : highest_order_field_bit_offset - highest_order_object_bit_offset);
22315 :
22316 487686 : if (bit_offset < 0)
22317 32 : add_AT_int (die, DW_AT_bit_offset, bit_offset);
22318 : else
22319 487654 : add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
22320 : }
22321 :
22322 : /* For a FIELD_DECL node which represents a bit field, output an attribute
22323 : which specifies the length in bits of the given field. */
22324 :
22325 : static inline void
22326 487702 : add_bit_size_attribute (dw_die_ref die, tree decl)
22327 : {
22328 : /* Must be a field and a bit field. */
22329 487702 : gcc_assert (TREE_CODE (decl) == FIELD_DECL
22330 : && DECL_BIT_FIELD_TYPE (decl));
22331 :
22332 487702 : if (tree_fits_uhwi_p (DECL_SIZE (decl)))
22333 487702 : add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
22334 487702 : }
22335 :
22336 : /* If the compiled language is ANSI C, then add a 'prototyped'
22337 : attribute, if arg types are given for the parameters of a function. */
22338 :
22339 : static inline void
22340 96564912 : add_prototyped_attribute (dw_die_ref die, tree func_type)
22341 : {
22342 96564912 : switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
22343 : {
22344 272307 : case DW_LANG_C:
22345 272307 : case DW_LANG_C89:
22346 272307 : case DW_LANG_C99:
22347 272307 : case DW_LANG_C11:
22348 272307 : case DW_LANG_ObjC:
22349 272307 : if (prototype_p (func_type))
22350 268916 : add_AT_flag (die, DW_AT_prototyped, 1);
22351 : break;
22352 : default:
22353 : break;
22354 : }
22355 96564912 : }
22356 :
22357 : /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
22358 : by looking in the type declaration, the object declaration equate table or
22359 : the block mapping. */
22360 :
22361 : static inline void
22362 21179340 : add_abstract_origin_attribute (dw_die_ref die, tree origin)
22363 : {
22364 21179340 : dw_die_ref origin_die = NULL;
22365 :
22366 : /* For late LTO debug output we want to refer directly to the abstract
22367 : DIE in the early debug rather to the possibly existing concrete
22368 : instance and avoid creating that just for this purpose. */
22369 21179340 : sym_off_pair *desc;
22370 21179340 : if (in_lto_p
22371 9289 : && external_die_map
22372 21188628 : && (desc = external_die_map->get (origin)))
22373 : {
22374 9018 : add_AT_external_die_ref (die, DW_AT_abstract_origin,
22375 9018 : desc->sym, desc->off);
22376 9018 : return;
22377 : }
22378 :
22379 21170322 : if (DECL_P (origin))
22380 20826336 : origin_die = lookup_decl_die (origin);
22381 343986 : else if (TYPE_P (origin))
22382 0 : origin_die = lookup_type_die (origin);
22383 343986 : else if (TREE_CODE (origin) == BLOCK)
22384 343986 : origin_die = lookup_block_die (origin);
22385 :
22386 : /* XXX: Functions that are never lowered don't always have correct block
22387 : trees (in the case of java, they simply have no block tree, in some other
22388 : languages). For these functions, there is nothing we can really do to
22389 : output correct debug info for inlined functions in all cases. Rather
22390 : than die, we'll just produce deficient debug info now, in that we will
22391 : have variables without a proper abstract origin. In the future, when all
22392 : functions are lowered, we should re-add a gcc_assert (origin_die)
22393 : here. */
22394 :
22395 21170322 : if (origin_die)
22396 : {
22397 21162650 : dw_attr_node *a;
22398 : /* Like above, if we already created a concrete instance DIE
22399 : do not use that for the abstract origin but the early DIE
22400 : if present. */
22401 21162650 : if (in_lto_p
22402 21162650 : && (a = get_AT (origin_die, DW_AT_abstract_origin)))
22403 260 : origin_die = AT_ref (a);
22404 21162650 : add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
22405 : }
22406 : }
22407 :
22408 : /* We do not currently support the pure_virtual attribute. */
22409 :
22410 : static inline void
22411 96157482 : add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
22412 : {
22413 96157482 : if (DECL_VINDEX (func_decl))
22414 : {
22415 1155624 : add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
22416 :
22417 1155624 : if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
22418 887255 : add_AT_loc (die, DW_AT_vtable_elem_location,
22419 : new_loc_descr (DW_OP_constu,
22420 887255 : tree_to_shwi (DECL_VINDEX (func_decl)),
22421 : 0));
22422 :
22423 : /* GNU extension: Record what type this method came from originally. */
22424 1155624 : if (debug_info_level > DINFO_LEVEL_TERSE
22425 1155624 : && DECL_CONTEXT (func_decl))
22426 1155586 : add_AT_die_ref (die, DW_AT_containing_type,
22427 1155586 : lookup_type_die (DECL_CONTEXT (func_decl)));
22428 : }
22429 96157482 : }
22430 :
22431 : /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
22432 : given decl. This used to be a vendor extension until after DWARF 4
22433 : standardized it. */
22434 :
22435 : static void
22436 121438210 : add_linkage_attr (dw_die_ref die, tree decl)
22437 : {
22438 121438210 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
22439 :
22440 : /* Mimic what assemble_name_raw does with a leading '*'. */
22441 121438210 : if (name[0] == '*')
22442 422291 : name = &name[1];
22443 :
22444 121438210 : if (dwarf_version >= 4)
22445 121433382 : add_AT_string (die, DW_AT_linkage_name, name);
22446 : else
22447 4828 : add_AT_string (die, DW_AT_MIPS_linkage_name, name);
22448 121438210 : }
22449 :
22450 : /* Add source coordinate attributes for the given decl. */
22451 :
22452 : static void
22453 251072421 : add_src_coords_attributes (dw_die_ref die, tree decl)
22454 : {
22455 251072421 : expanded_location s;
22456 :
22457 251072421 : if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
22458 112943 : return;
22459 250959478 : s = expand_location (DECL_SOURCE_LOCATION (decl));
22460 250959478 : add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
22461 250959478 : add_AT_unsigned (die, DW_AT_decl_line, s.line);
22462 250959478 : if (debug_column_info && s.column)
22463 250159070 : add_AT_unsigned (die, DW_AT_decl_column, s.column);
22464 : }
22465 :
22466 : /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
22467 :
22468 : static void
22469 127592360 : add_linkage_name_raw (dw_die_ref die, tree decl)
22470 : {
22471 : /* Defer until we have an assembler name set. */
22472 127592360 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
22473 : {
22474 125635275 : limbo_die_node *asm_name;
22475 :
22476 125635275 : asm_name = ggc_cleared_alloc<limbo_die_node> ();
22477 125635275 : asm_name->die = die;
22478 125635275 : asm_name->created_for = decl;
22479 125635275 : asm_name->next = deferred_asm_name;
22480 125635275 : deferred_asm_name = asm_name;
22481 : }
22482 1957085 : else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22483 1536448 : add_linkage_attr (die, decl);
22484 127592360 : }
22485 :
22486 : /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
22487 :
22488 : static void
22489 207158121 : add_linkage_name (dw_die_ref die, tree decl)
22490 : {
22491 207158121 : if (debug_info_level > DINFO_LEVEL_NONE
22492 207158112 : && VAR_OR_FUNCTION_DECL_P (decl)
22493 129407715 : && TREE_PUBLIC (decl)
22494 127285662 : && !(VAR_P (decl) && DECL_REGISTER (decl))
22495 334443777 : && die->die_tag != DW_TAG_member)
22496 127285548 : add_linkage_name_raw (die, decl);
22497 207158121 : }
22498 :
22499 : /* Add a DW_AT_name attribute and source coordinate attribute for the
22500 : given decl, but only if it actually has a name. */
22501 :
22502 : static void
22503 207505457 : add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
22504 : bool no_linkage_name)
22505 : {
22506 207505457 : tree decl_name;
22507 :
22508 207505457 : decl_name = DECL_NAME (decl);
22509 414524287 : if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
22510 : {
22511 207018830 : const char *name = dwarf2_name (decl, 0);
22512 207018830 : if (name)
22513 207012349 : add_name_attribute (die, name);
22514 : else
22515 6481 : add_desc_attribute (die, decl);
22516 :
22517 207018830 : if (! DECL_ARTIFICIAL (decl))
22518 199041092 : add_src_coords_attributes (die, decl);
22519 :
22520 207018830 : if (!no_linkage_name)
22521 206757240 : add_linkage_name (die, decl);
22522 : }
22523 : else
22524 486627 : add_desc_attribute (die, decl);
22525 :
22526 : #ifdef VMS_DEBUGGING_INFO
22527 : /* Get the function's name, as described by its RTL. This may be different
22528 : from the DECL_NAME name used in the source file. */
22529 : if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
22530 : {
22531 : add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
22532 : XEXP (DECL_RTL (decl), 0), false);
22533 : vec_safe_push (used_rtx_array, XEXP (DECL_RTL (decl), 0));
22534 : }
22535 : #endif /* VMS_DEBUGGING_INFO */
22536 207505457 : }
22537 :
22538 : /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
22539 :
22540 : static void
22541 0 : add_discr_value (dw_die_ref die, dw_discr_value *value)
22542 : {
22543 0 : dw_attr_node attr;
22544 :
22545 0 : attr.dw_attr = DW_AT_discr_value;
22546 0 : attr.dw_attr_val.val_class = dw_val_class_discr_value;
22547 0 : attr.dw_attr_val.val_entry = NULL;
22548 0 : attr.dw_attr_val.v.val_discr_value.pos = value->pos;
22549 0 : if (value->pos)
22550 0 : attr.dw_attr_val.v.val_discr_value.v.uval = value->v.uval;
22551 : else
22552 0 : attr.dw_attr_val.v.val_discr_value.v.sval = value->v.sval;
22553 0 : add_dwarf_attr (die, &attr);
22554 0 : }
22555 :
22556 : /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
22557 :
22558 : static void
22559 0 : add_discr_list (dw_die_ref die, dw_discr_list_ref discr_list)
22560 : {
22561 0 : dw_attr_node attr;
22562 :
22563 0 : attr.dw_attr = DW_AT_discr_list;
22564 0 : attr.dw_attr_val.val_class = dw_val_class_discr_list;
22565 0 : attr.dw_attr_val.val_entry = NULL;
22566 0 : attr.dw_attr_val.v.val_discr_list = discr_list;
22567 0 : add_dwarf_attr (die, &attr);
22568 0 : }
22569 :
22570 : static inline dw_discr_list_ref
22571 0 : AT_discr_list (dw_attr_node *attr)
22572 : {
22573 0 : return attr->dw_attr_val.v.val_discr_list;
22574 : }
22575 :
22576 : #ifdef VMS_DEBUGGING_INFO
22577 : /* Output the debug main pointer die for VMS */
22578 :
22579 : void
22580 : dwarf2out_vms_debug_main_pointer (void)
22581 : {
22582 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
22583 : dw_die_ref die;
22584 :
22585 : /* Allocate the VMS debug main subprogram die. */
22586 : die = new_die_raw (DW_TAG_subprogram);
22587 : add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
22588 : ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
22589 : current_function_funcdef_no);
22590 : add_AT_lbl_id (die, DW_AT_entry_pc, label);
22591 :
22592 : /* Make it the first child of comp_unit_die (). */
22593 : die->die_parent = comp_unit_die ();
22594 : if (comp_unit_die ()->die_child)
22595 : {
22596 : die->die_sib = comp_unit_die ()->die_child->die_sib;
22597 : comp_unit_die ()->die_child->die_sib = die;
22598 : }
22599 : else
22600 : {
22601 : die->die_sib = die;
22602 : comp_unit_die ()->die_child = die;
22603 : }
22604 : }
22605 : #endif /* VMS_DEBUGGING_INFO */
22606 :
22607 : /* walk_tree helper function for uses_local_type, below. */
22608 :
22609 : static tree
22610 2193311 : uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
22611 : {
22612 2193311 : if (!TYPE_P (*tp))
22613 0 : *walk_subtrees = 0;
22614 : else
22615 : {
22616 2193311 : tree name = TYPE_NAME (*tp);
22617 2193311 : if (name && DECL_P (name) && decl_function_context (name))
22618 86229 : return *tp;
22619 : }
22620 : return NULL_TREE;
22621 : }
22622 :
22623 : /* If TYPE involves a function-local type (including a local typedef to a
22624 : non-local type), returns that type; otherwise returns NULL_TREE. */
22625 :
22626 : static tree
22627 1122157 : uses_local_type (tree type)
22628 : {
22629 1122157 : tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
22630 1122157 : return used;
22631 : }
22632 :
22633 : /* Return the DIE for the scope that immediately contains this type.
22634 : Non-named types that do not involve a function-local type get global
22635 : scope. Named types nested in namespaces or other types get their
22636 : containing scope. All other types (i.e. function-local named types) get
22637 : the current active scope. */
22638 :
22639 : static dw_die_ref
22640 171383665 : scope_die_for (tree t, dw_die_ref context_die)
22641 : {
22642 171383665 : dw_die_ref scope_die = NULL;
22643 171383665 : tree containing_scope;
22644 :
22645 : /* Non-types always go in the current scope. */
22646 171383665 : gcc_assert (TYPE_P (t));
22647 :
22648 : /* Use the scope of the typedef, rather than the scope of the type
22649 : it refers to. */
22650 171383665 : if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
22651 136369148 : containing_scope = DECL_CONTEXT (TYPE_NAME (t));
22652 : else
22653 35014517 : containing_scope = TYPE_CONTEXT (t);
22654 :
22655 : /* Use the containing namespace if there is one. */
22656 171383665 : if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
22657 : {
22658 114793734 : if (context_die == lookup_decl_die (containing_scope))
22659 : /* OK */;
22660 59681513 : else if (debug_info_level > DINFO_LEVEL_TERSE)
22661 59681513 : context_die = get_context_die (containing_scope);
22662 : else
22663 : containing_scope = NULL_TREE;
22664 : }
22665 :
22666 : /* Ignore function type "scopes" from the C frontend. They mean that
22667 : a tagged type is local to a parmlist of a function declarator, but
22668 : that isn't useful to DWARF. */
22669 135257308 : if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
22670 : containing_scope = NULL_TREE;
22671 :
22672 135257277 : if (SCOPE_FILE_SCOPE_P (containing_scope))
22673 : {
22674 : /* If T uses a local type keep it local as well, to avoid references
22675 : to function-local DIEs from outside the function. */
22676 38918776 : if (current_function_decl && uses_local_type (t))
22677 : scope_die = context_die;
22678 : else
22679 37710390 : scope_die = comp_unit_die ();
22680 : }
22681 133587046 : else if (TYPE_P (containing_scope))
22682 : {
22683 : /* For types, we can just look up the appropriate DIE. */
22684 17732409 : if (debug_info_level > DINFO_LEVEL_TERSE)
22685 17732409 : scope_die = get_context_die (containing_scope);
22686 : else
22687 : {
22688 0 : scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
22689 0 : if (scope_die == NULL)
22690 0 : scope_die = comp_unit_die ();
22691 : }
22692 : }
22693 : else
22694 : scope_die = context_die;
22695 :
22696 171383665 : return scope_die;
22697 : }
22698 :
22699 : /* Returns true if CONTEXT_DIE is internal to a function. */
22700 :
22701 : static inline bool
22702 : local_scope_p (dw_die_ref context_die)
22703 : {
22704 417893636 : for (; context_die; context_die = context_die->die_parent)
22705 320541604 : if (context_die->die_tag == DW_TAG_inlined_subroutine
22706 320541603 : || context_die->die_tag == DW_TAG_subprogram)
22707 : return true;
22708 :
22709 : return false;
22710 : }
22711 :
22712 : /* Returns true if CONTEXT_DIE is a class. */
22713 :
22714 : static inline bool
22715 236166063 : class_scope_p (dw_die_ref context_die)
22716 : {
22717 236166063 : return (context_die
22718 236166063 : && (context_die->die_tag == DW_TAG_structure_type
22719 : || context_die->die_tag == DW_TAG_class_type
22720 : || context_die->die_tag == DW_TAG_interface_type
22721 236166063 : || context_die->die_tag == DW_TAG_union_type));
22722 : }
22723 :
22724 : /* Returns true if CONTEXT_DIE is a class or namespace, for deciding
22725 : whether or not to treat a DIE in this context as a declaration. */
22726 :
22727 : static inline bool
22728 139245408 : class_or_namespace_scope_p (dw_die_ref context_die)
22729 : {
22730 139245408 : return (class_scope_p (context_die)
22731 139245408 : || (context_die && context_die->die_tag == DW_TAG_namespace));
22732 : }
22733 :
22734 : /* Many forms of DIEs require a "type description" attribute. This
22735 : routine locates the proper "type descriptor" die for the type given
22736 : by 'type' plus any additional qualifiers given by 'cv_quals', and
22737 : adds a DW_AT_type attribute below the given die. */
22738 :
22739 : static void
22740 468966192 : add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
22741 : bool reverse, dw_die_ref context_die)
22742 : {
22743 468966192 : enum tree_code code = TREE_CODE (type);
22744 468966192 : dw_die_ref type_die = NULL;
22745 :
22746 468966192 : if (debug_info_level <= DINFO_LEVEL_TERSE)
22747 : return;
22748 :
22749 : /* ??? If this type is an unnamed subrange type of an integral, floating-point
22750 : or fixed-point type, use the inner type. This is because we have no
22751 : support for unnamed types in base_type_die. This can happen if this is
22752 : an Ada subrange type. Correct solution is emit a subrange type die. */
22753 468965074 : if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
22754 103675354 : && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
22755 655 : type = TREE_TYPE (type), code = TREE_CODE (type);
22756 :
22757 468965074 : if (code == ERROR_MARK
22758 : /* Handle a special case. For functions whose return type is void, we
22759 : generate *no* type attribute. (Note that no object may have type
22760 : `void', so this only applies to function return types). */
22761 468965074 : || code == VOID_TYPE)
22762 : return;
22763 :
22764 1745871064 : type_die = modified_type_die (type,
22765 436467766 : cv_quals | TYPE_QUALS (type),
22766 436467766 : TYPE_ATTRIBUTES (type),
22767 : reverse,
22768 : context_die);
22769 :
22770 436467766 : if (type_die != NULL)
22771 436467654 : add_AT_die_ref (object_die, DW_AT_type, type_die);
22772 : }
22773 :
22774 : /* Given an object die, add the calling convention attribute for the
22775 : function call type. */
22776 : static void
22777 97849044 : add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
22778 : {
22779 97849044 : enum dwarf_calling_convention value = DW_CC_normal;
22780 :
22781 195698088 : value = ((enum dwarf_calling_convention)
22782 97849044 : targetm.dwarf_calling_convention (TREE_TYPE (decl)));
22783 :
22784 97849044 : if (is_fortran ()
22785 97849044 : && id_equal (DECL_ASSEMBLER_NAME (decl), "MAIN__"))
22786 : {
22787 : /* DWARF 2 doesn't provide a way to identify a program's source-level
22788 : entry point. DW_AT_calling_convention attributes are only meant
22789 : to describe functions' calling conventions. However, lacking a
22790 : better way to signal the Fortran main program, we used this for
22791 : a long time, following existing custom. Now, DWARF 4 has
22792 : DW_AT_main_subprogram, which we add below, but some tools still
22793 : rely on the old way, which we thus keep. */
22794 4287 : value = DW_CC_program;
22795 :
22796 4287 : if (dwarf_version >= 4 || !dwarf_strict)
22797 4287 : add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
22798 : }
22799 :
22800 : /* Only add the attribute if the backend requests it, and
22801 : is not DW_CC_normal. */
22802 97849044 : if (value && (value != DW_CC_normal))
22803 4287 : add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
22804 97849044 : }
22805 :
22806 : /* Given a tree pointer to a struct, class, union, or enum type node, return
22807 : a pointer to the (string) tag name for the given type, or zero if the type
22808 : was declared without a tag. */
22809 :
22810 : static const char *
22811 56595559 : type_tag (const_tree type)
22812 : {
22813 56595559 : const char *name = 0;
22814 :
22815 56595559 : if (TYPE_NAME (type) != 0)
22816 : {
22817 55025792 : tree t = 0;
22818 :
22819 : /* Find the IDENTIFIER_NODE for the type name. */
22820 55025792 : if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
22821 55025792 : && !TYPE_NAMELESS (type))
22822 273357 : t = TYPE_NAME (type);
22823 :
22824 : /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
22825 : a TYPE_DECL node, regardless of whether or not a `typedef' was
22826 : involved. */
22827 54752435 : else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
22828 54752435 : && ! DECL_IGNORED_P (TYPE_NAME (type)))
22829 : {
22830 : /* We want to be extra verbose. Don't call dwarf_name if
22831 : DECL_NAME isn't set. The default hook for decl_printable_name
22832 : doesn't like that, and in this context it's correct to return
22833 : 0, instead of "<anonymous>" or the like. */
22834 54738570 : if (DECL_NAME (TYPE_NAME (type))
22835 54738570 : && !DECL_NAMELESS (TYPE_NAME (type)))
22836 54736704 : name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
22837 : }
22838 :
22839 : /* Now get the name as a string, or invent one. */
22840 55025792 : if (!name && t != 0)
22841 273357 : name = IDENTIFIER_POINTER (t);
22842 : }
22843 :
22844 55025792 : return (name == 0 || *name == '\0') ? 0 : name;
22845 : }
22846 :
22847 : /* Return the type associated with a data member, make a special check
22848 : for bit field types. */
22849 :
22850 : static inline tree
22851 34042593 : member_declared_type (const_tree member)
22852 : {
22853 34042593 : return (DECL_BIT_FIELD_TYPE (member)
22854 34042593 : ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
22855 : }
22856 :
22857 : /* Get the decl's label, as described by its RTL. This may be different
22858 : from the DECL_NAME name used in the source file. */
22859 :
22860 : #if 0
22861 : static const char *
22862 : decl_start_label (tree decl)
22863 : {
22864 : rtx x;
22865 : const char *fnname;
22866 :
22867 : x = DECL_RTL (decl);
22868 : gcc_assert (MEM_P (x));
22869 :
22870 : x = XEXP (x, 0);
22871 : gcc_assert (GET_CODE (x) == SYMBOL_REF);
22872 :
22873 : fnname = XSTR (x, 0);
22874 : return fnname;
22875 : }
22876 : #endif
22877 :
22878 : /* For variable-length arrays that have been previously generated, but
22879 : may be incomplete due to missing subscript info, fill the subscript
22880 : info. Return TRUE if this is one of those cases. */
22881 :
22882 : static bool
22883 10917221 : fill_variable_array_bounds (tree type)
22884 : {
22885 10917221 : if (TREE_ASM_WRITTEN (type)
22886 3943639 : && TREE_CODE (type) == ARRAY_TYPE
22887 10921965 : && variably_modified_type_p (type, NULL))
22888 : {
22889 4715 : dw_die_ref array_die = lookup_type_die (type);
22890 4715 : if (!array_die)
22891 : return false;
22892 4715 : add_subscript_info (array_die, type, !is_ada ());
22893 4715 : return true;
22894 : }
22895 : return false;
22896 : }
22897 :
22898 : /* These routines generate the internal representation of the DIE's for
22899 : the compilation unit. Debugging information is collected by walking
22900 : the declaration trees passed in from dwarf2out_decl(). */
22901 :
22902 : static void
22903 1040231 : gen_array_type_die (tree type, dw_die_ref context_die)
22904 : {
22905 1040231 : dw_die_ref array_die;
22906 :
22907 : /* GNU compilers represent multidimensional array types as sequences of one
22908 : dimensional array types whose element types are themselves array types.
22909 : We sometimes squish that down to a single array_type DIE with multiple
22910 : subscripts in the Dwarf debugging info. The draft Dwarf specification
22911 : say that we are allowed to do this kind of compression in C, because
22912 : there is no difference between an array of arrays and a multidimensional
22913 : array. We don't do this for Ada to remain as close as possible to the
22914 : actual representation, which is especially important against the language
22915 : flexibilty wrt arrays of variable size. */
22916 :
22917 1040231 : bool collapse_nested_arrays = !is_ada ();
22918 :
22919 1040231 : if (fill_variable_array_bounds (type))
22920 : return;
22921 :
22922 1035598 : dw_die_ref scope_die = scope_die_for (type, context_die);
22923 1035598 : tree element_type;
22924 :
22925 : /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
22926 : DW_TAG_string_type doesn't have DW_AT_type attribute). */
22927 1035598 : if (TREE_CODE (type) == ARRAY_TYPE
22928 1015253 : && TYPE_STRING_FLAG (type)
22929 4471 : && is_fortran ()
22930 1040069 : && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
22931 : {
22932 4086 : HOST_WIDE_INT size;
22933 :
22934 4086 : array_die = new_die (DW_TAG_string_type, scope_die, type);
22935 4086 : add_name_attribute (array_die, type_tag (type));
22936 4086 : equate_type_number_to_die (type, array_die);
22937 4086 : size = int_size_in_bytes (type);
22938 4086 : if (size >= 0)
22939 1612 : add_AT_unsigned (array_die, DW_AT_byte_size, size);
22940 : /* ??? We can't annotate types late, but for LTO we may not
22941 : generate a location early either (gfortran.dg/save_6.f90). */
22942 1500 : else if (! (early_dwarf && (flag_generate_lto || flag_generate_offload))
22943 2474 : && TYPE_DOMAIN (type) != NULL_TREE
22944 4948 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE)
22945 : {
22946 2265 : tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
22947 2265 : tree rszdecl = szdecl;
22948 :
22949 2265 : size = int_size_in_bytes (TREE_TYPE (szdecl));
22950 2265 : if (!DECL_P (szdecl))
22951 : {
22952 82 : if (INDIRECT_REF_P (szdecl)
22953 82 : && DECL_P (TREE_OPERAND (szdecl, 0)))
22954 : {
22955 72 : rszdecl = TREE_OPERAND (szdecl, 0);
22956 144 : if (int_size_in_bytes (TREE_TYPE (rszdecl))
22957 72 : != DWARF2_ADDR_SIZE)
22958 : size = 0;
22959 : }
22960 : else
22961 : size = 0;
22962 : }
22963 2255 : if (size > 0)
22964 : {
22965 2255 : dw_loc_list_ref loc
22966 2327 : = loc_list_from_tree (rszdecl, szdecl == rszdecl ? 2 : 0,
22967 : NULL);
22968 2255 : if (loc)
22969 : {
22970 2074 : add_AT_location_description (array_die, DW_AT_string_length,
22971 : loc);
22972 2086 : if (size != DWARF2_ADDR_SIZE)
22973 0 : add_AT_unsigned (array_die, dwarf_version >= 5
22974 : ? DW_AT_string_length_byte_size
22975 : : DW_AT_byte_size, size);
22976 : }
22977 : }
22978 : }
22979 4086 : return;
22980 : }
22981 :
22982 1031512 : array_die = new_die (DW_TAG_array_type, scope_die, type);
22983 1031512 : add_name_attribute (array_die, type_tag (type));
22984 1031512 : equate_type_number_to_die (type, array_die);
22985 :
22986 1031512 : if (VECTOR_TYPE_P (type))
22987 20345 : add_AT_flag (array_die, DW_AT_GNU_vector, 1);
22988 :
22989 : /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
22990 1031512 : if (is_fortran ()
22991 9853 : && TREE_CODE (type) == ARRAY_TYPE
22992 9853 : && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
22993 1033792 : && !TYPE_STRING_FLAG (TREE_TYPE (type)))
22994 1667 : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
22995 :
22996 : #if 0
22997 : /* We default the array ordering. Debuggers will probably do the right
22998 : things even if DW_AT_ordering is not present. It's not even an issue
22999 : until we start to get into multidimensional arrays anyway. If a debugger
23000 : is ever caught doing the Wrong Thing for multi-dimensional arrays,
23001 : then we'll have to put the DW_AT_ordering attribute back in. (But if
23002 : and when we find out that we need to put these in, we will only do so
23003 : for multidimensional arrays. */
23004 : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
23005 : #endif
23006 :
23007 1031512 : if (VECTOR_TYPE_P (type))
23008 : {
23009 : /* For VECTOR_TYPEs we use an array DIE with appropriate bounds. */
23010 20345 : dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
23011 20345 : int lb = lower_bound_default ();
23012 20345 : if (lb == -1)
23013 : lb = 0;
23014 20345 : add_bound_info (subrange_die, DW_AT_lower_bound, size_int (lb), NULL);
23015 20345 : add_bound_info (subrange_die, DW_AT_upper_bound,
23016 40690 : size_int (lb + TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
23017 : }
23018 : else
23019 1011167 : add_subscript_info (array_die, type, collapse_nested_arrays);
23020 :
23021 : /* Add representation of the type of the elements of this array type and
23022 : emit the corresponding DIE if we haven't done it already. */
23023 1031512 : element_type = TREE_TYPE (type);
23024 1031512 : if (collapse_nested_arrays)
23025 1035652 : while (TREE_CODE (element_type) == ARRAY_TYPE)
23026 : {
23027 4913 : if (TYPE_STRING_FLAG (element_type) && is_fortran ())
23028 : break;
23029 4140 : element_type = TREE_TYPE (element_type);
23030 : }
23031 :
23032 1031512 : add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED,
23033 1031512 : TREE_CODE (type) == ARRAY_TYPE
23034 1031512 : && TYPE_REVERSE_STORAGE_ORDER (type),
23035 : context_die);
23036 :
23037 : /* Add bit stride information to boolean vectors of single bits so that
23038 : elements can be correctly read and displayed by a debugger. */
23039 1031512 : if (VECTOR_BOOLEAN_TYPE_P (type))
23040 : {
23041 0 : enum machine_mode tmode = TYPE_MODE_RAW (type);
23042 0 : if (GET_MODE_CLASS (tmode) == MODE_VECTOR_BOOL)
23043 : {
23044 : /* Calculate bit-size of element based on mnode. */
23045 0 : poly_uint16 bit_size = exact_div (GET_MODE_BITSIZE (tmode),
23046 0 : GET_MODE_NUNITS (tmode));
23047 : /* Set bit stride in the array type DIE. */
23048 0 : add_AT_unsigned (array_die, DW_AT_bit_stride, bit_size.coeffs[0]);
23049 : /* Find DIE corresponding to the element type so that we could
23050 : add DW_AT_bit_size to it. */
23051 0 : dw_die_ref elem_die = get_AT_ref (array_die, DW_AT_type);
23052 : /* Avoid adding DW_AT_bit_size twice. */
23053 0 : if (get_AT (elem_die, DW_AT_bit_size) == NULL)
23054 0 : add_AT_unsigned (elem_die, DW_AT_bit_size,
23055 0 : TYPE_PRECISION (element_type));
23056 : }
23057 : }
23058 :
23059 1031512 : add_gnat_descriptive_type_attribute (array_die, type, context_die);
23060 1031512 : if (TYPE_ARTIFICIAL (type))
23061 0 : add_AT_flag (array_die, DW_AT_artificial, 1);
23062 :
23063 1031512 : if (get_AT (array_die, DW_AT_name))
23064 60 : add_pubtype (type, array_die);
23065 :
23066 1031512 : add_alignment_attribute (array_die, type);
23067 1031512 : maybe_gen_btf_type_tag_dies (type, array_die);
23068 : }
23069 :
23070 : /* This routine generates DIE for array with hidden descriptor, details
23071 : are filled into *info by a langhook. */
23072 :
23073 : static void
23074 6936 : gen_descr_array_type_die (tree type, struct array_descr_info *info,
23075 : dw_die_ref context_die)
23076 : {
23077 6936 : const dw_die_ref scope_die = scope_die_for (type, context_die);
23078 6936 : const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
23079 6936 : struct loc_descr_context context = {
23080 : type, /* context_type */
23081 6936 : info->base_decl, /* base_decl */
23082 : NULL, /* dpi */
23083 : false, /* placeholder_arg */
23084 : false, /* placeholder_seen */
23085 : false /* strict_signedness */
23086 6936 : };
23087 6936 : enum dwarf_tag subrange_tag = DW_TAG_subrange_type;
23088 6936 : int dim;
23089 :
23090 6936 : add_name_attribute (array_die, type_tag (type));
23091 6936 : equate_type_number_to_die (type, array_die);
23092 :
23093 6936 : if (info->ndimensions > 1)
23094 1680 : switch (info->ordering)
23095 : {
23096 0 : case array_descr_ordering_row_major:
23097 0 : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
23098 0 : break;
23099 1680 : case array_descr_ordering_column_major:
23100 1680 : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
23101 1680 : break;
23102 : default:
23103 : break;
23104 : }
23105 :
23106 6936 : if (dwarf_version >= 3 || !dwarf_strict)
23107 : {
23108 6936 : if (info->data_location)
23109 6936 : add_scalar_info (array_die, DW_AT_data_location, info->data_location,
23110 : dw_scalar_form_exprloc, &context);
23111 6936 : if (info->associated)
23112 1312 : add_scalar_info (array_die, DW_AT_associated, info->associated,
23113 : dw_scalar_form_constant
23114 : | dw_scalar_form_exprloc
23115 : | dw_scalar_form_reference, &context);
23116 6936 : if (info->allocated)
23117 2519 : add_scalar_info (array_die, DW_AT_allocated, info->allocated,
23118 : dw_scalar_form_constant
23119 : | dw_scalar_form_exprloc
23120 : | dw_scalar_form_reference, &context);
23121 6936 : if (info->stride)
23122 : {
23123 0 : const enum dwarf_attribute attr
23124 0 : = (info->stride_in_bits) ? DW_AT_bit_stride : DW_AT_byte_stride;
23125 0 : const int forms
23126 : = (info->stride_in_bits)
23127 0 : ? dw_scalar_form_constant
23128 : : (dw_scalar_form_constant
23129 : | dw_scalar_form_exprloc
23130 : | dw_scalar_form_reference);
23131 :
23132 0 : add_scalar_info (array_die, attr, info->stride, forms, &context);
23133 : }
23134 : }
23135 6936 : if (dwarf_version >= 5)
23136 : {
23137 6936 : if (info->rank)
23138 : {
23139 1031 : add_scalar_info (array_die, DW_AT_rank, info->rank,
23140 : dw_scalar_form_constant
23141 : | dw_scalar_form_exprloc, &context);
23142 1031 : subrange_tag = DW_TAG_generic_subrange;
23143 1031 : context.placeholder_arg = true;
23144 : }
23145 : }
23146 :
23147 6936 : add_gnat_descriptive_type_attribute (array_die, type, context_die);
23148 :
23149 16174 : for (dim = 0; dim < info->ndimensions; dim++)
23150 : {
23151 9238 : dw_die_ref subrange_die = new_die (subrange_tag, array_die, NULL);
23152 :
23153 9238 : if (info->dimen[dim].bounds_type)
23154 0 : add_type_attribute (subrange_die,
23155 : info->dimen[dim].bounds_type, TYPE_UNQUALIFIED,
23156 : false, context_die);
23157 9238 : if (info->dimen[dim].lower_bound)
23158 9238 : add_bound_info (subrange_die, DW_AT_lower_bound,
23159 : info->dimen[dim].lower_bound, &context);
23160 9238 : if (info->dimen[dim].upper_bound)
23161 9238 : add_bound_info (subrange_die, DW_AT_upper_bound,
23162 : info->dimen[dim].upper_bound, &context);
23163 9238 : if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
23164 9238 : add_scalar_info (subrange_die, DW_AT_byte_stride,
23165 : info->dimen[dim].stride,
23166 : dw_scalar_form_constant
23167 : | dw_scalar_form_exprloc
23168 : | dw_scalar_form_reference,
23169 : &context);
23170 : }
23171 :
23172 6936 : gen_type_die (info->element_type, context_die);
23173 6936 : add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
23174 6936 : TREE_CODE (type) == ARRAY_TYPE
23175 6936 : && TYPE_REVERSE_STORAGE_ORDER (type),
23176 : context_die);
23177 :
23178 6936 : if (get_AT (array_die, DW_AT_name))
23179 0 : add_pubtype (type, array_die);
23180 :
23181 6936 : add_alignment_attribute (array_die, type);
23182 6936 : }
23183 :
23184 : #if 0
23185 : static void
23186 : gen_entry_point_die (tree decl, dw_die_ref context_die)
23187 : {
23188 : tree origin = decl_ultimate_origin (decl);
23189 : dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
23190 :
23191 : if (origin != NULL)
23192 : add_abstract_origin_attribute (decl_die, origin);
23193 : else
23194 : {
23195 : add_name_and_src_coords_attributes (decl_die, decl);
23196 : add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
23197 : TYPE_UNQUALIFIED, false, context_die);
23198 : }
23199 :
23200 : if (DECL_ABSTRACT_P (decl))
23201 : equate_decl_number_to_die (decl, decl_die);
23202 : else
23203 : add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
23204 : }
23205 : #endif
23206 :
23207 : /* Walk through the list of incomplete types again, trying once more to
23208 : emit full debugging info for them. */
23209 :
23210 : static void
23211 52425 : retry_incomplete_types (void)
23212 : {
23213 52425 : set_early_dwarf s;
23214 52425 : int i;
23215 :
23216 50939791 : for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
23217 50834941 : if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
23218 50834644 : gen_type_die ((*incomplete_types)[i], comp_unit_die ());
23219 52425 : vec_safe_truncate (incomplete_types, 0);
23220 52425 : }
23221 :
23222 : /* Determine what tag to use for a record type. */
23223 :
23224 : static enum dwarf_tag
23225 53273220 : record_type_tag (tree type)
23226 : {
23227 53273220 : if (! lang_hooks.types.classify_record)
23228 : return DW_TAG_structure_type;
23229 :
23230 52636249 : switch (lang_hooks.types.classify_record (type))
23231 : {
23232 : case RECORD_IS_STRUCT:
23233 : return DW_TAG_structure_type;
23234 :
23235 : case RECORD_IS_CLASS:
23236 : return DW_TAG_class_type;
23237 :
23238 0 : case RECORD_IS_INTERFACE:
23239 0 : if (dwarf_version >= 3 || !dwarf_strict)
23240 : return DW_TAG_interface_type;
23241 : return DW_TAG_structure_type;
23242 :
23243 0 : default:
23244 0 : gcc_unreachable ();
23245 : }
23246 : }
23247 :
23248 : /* Generate a DIE to represent an enumeration type. Note that these DIEs
23249 : include all of the information about the enumeration values also. Each
23250 : enumerated type name/value is listed as a child of the enumerated type
23251 : DIE. REVERSE is true if the type is to be interpreted in the reverse
23252 : storage order wrt the target order. */
23253 :
23254 : static dw_die_ref
23255 1822178 : gen_enumeration_type_die (tree type, dw_die_ref context_die, bool reverse)
23256 : {
23257 1822178 : dw_die_ref type_die = lookup_type_die (type);
23258 1822178 : dw_die_ref orig_type_die = type_die;
23259 :
23260 1822178 : if (type_die == NULL || reverse)
23261 : {
23262 1821765 : dw_die_ref scope_die = scope_die_for (type, context_die);
23263 :
23264 : /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
23265 1821765 : if (reverse)
23266 : {
23267 2 : gcc_assert (type_die);
23268 2 : dw_die_ref after_die = type_die;
23269 2 : type_die = new_die_raw (DW_TAG_enumeration_type);
23270 2 : add_child_die_after (scope_die, type_die, after_die);
23271 : }
23272 : else
23273 : {
23274 1821763 : type_die = new_die (DW_TAG_enumeration_type, scope_die, type);
23275 1821763 : equate_type_number_to_die (type, type_die);
23276 : }
23277 1821765 : add_name_attribute (type_die, type_tag (type));
23278 816 : if ((dwarf_version >= 4 || !dwarf_strict)
23279 3643530 : && ENUM_IS_SCOPED (type))
23280 352413 : add_AT_flag (type_die, DW_AT_enum_class, 1);
23281 1821765 : if (ENUM_IS_OPAQUE (type) && TYPE_SIZE (type))
23282 332 : add_AT_flag (type_die, DW_AT_declaration, 1);
23283 1821765 : if (!dwarf_strict)
23284 1821765 : add_AT_unsigned (type_die, DW_AT_encoding,
23285 1821765 : TYPE_UNSIGNED (type)
23286 : ? DW_ATE_unsigned
23287 : : DW_ATE_signed);
23288 1821765 : if (reverse)
23289 2 : add_AT_unsigned (type_die, DW_AT_endianity,
23290 : BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
23291 : }
23292 825 : else if (! TYPE_SIZE (type) || ENUM_IS_OPAQUE (type))
23293 : return type_die;
23294 : else
23295 7 : remove_AT (type_die, DW_AT_declaration);
23296 :
23297 : /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
23298 : given enum type is incomplete, do not generate the DW_AT_byte_size
23299 : attribute or the DW_AT_element_list attribute. */
23300 1821772 : if (TYPE_SIZE (type))
23301 : {
23302 1821764 : tree link;
23303 :
23304 1821764 : if (!ENUM_IS_OPAQUE (type))
23305 1821432 : TREE_ASM_WRITTEN (type) = 1;
23306 1821764 : if (!orig_type_die || !get_AT (type_die, DW_AT_byte_size))
23307 1821762 : add_byte_size_attribute (type_die, type);
23308 1821764 : if (!orig_type_die || !get_AT (type_die, DW_AT_alignment))
23309 1821764 : add_alignment_attribute (type_die, type);
23310 816 : if ((dwarf_version >= 3 || !dwarf_strict)
23311 1822580 : && (!orig_type_die || !get_AT (type_die, DW_AT_type)))
23312 : {
23313 1821762 : tree underlying = lang_hooks.types.enum_underlying_base_type (type);
23314 1821762 : add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED, false,
23315 : context_die);
23316 : }
23317 1821764 : if (TYPE_STUB_DECL (type) != NULL_TREE)
23318 : {
23319 1821734 : if (!orig_type_die || !get_AT (type_die, DW_AT_decl_file))
23320 1821732 : add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
23321 1821734 : if (!orig_type_die || !get_AT (type_die, DW_AT_accessibility))
23322 1821734 : add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
23323 : }
23324 :
23325 : /* If the first reference to this type was as the return type of an
23326 : inline function, then it may not have a parent. Fix this now. */
23327 1821764 : if (type_die->die_parent == NULL)
23328 5 : add_child_die (scope_die_for (type, context_die), type_die);
23329 :
23330 1821764 : for (link = TYPE_VALUES (type);
23331 15543460 : link != NULL; link = TREE_CHAIN (link))
23332 : {
23333 13721696 : dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
23334 13721696 : tree value = TREE_VALUE (link);
23335 :
23336 13721696 : if (DECL_P (value))
23337 13712683 : equate_decl_number_to_die (value, enum_die);
23338 :
23339 13721696 : gcc_assert (!ENUM_IS_OPAQUE (type));
23340 13721696 : add_name_attribute (enum_die,
23341 13721696 : IDENTIFIER_POINTER (TREE_PURPOSE (link)));
23342 :
23343 13721696 : if (TREE_CODE (value) == CONST_DECL)
23344 13712683 : value = DECL_INITIAL (value);
23345 :
23346 13721696 : if (simple_type_size_in_bits (TREE_TYPE (value))
23347 13721696 : <= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
23348 : {
23349 : /* For constant forms created by add_AT_unsigned DWARF
23350 : consumers (GDB, elfutils, etc.) always zero extend
23351 : the value. Only when the actual value is negative
23352 : do we need to use add_AT_int to generate a constant
23353 : form that can represent negative values. */
23354 13721694 : HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
23355 13721694 : if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
23356 13536863 : add_AT_unsigned (enum_die, DW_AT_const_value,
23357 : (unsigned HOST_WIDE_INT) val);
23358 : else
23359 184831 : add_AT_int (enum_die, DW_AT_const_value, val);
23360 : }
23361 : else
23362 : /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
23363 : that here. TODO: This should be re-worked to use correct
23364 : signed/unsigned double tags for all cases. */
23365 2 : add_AT_wide (enum_die, DW_AT_const_value, wi::to_wide (value));
23366 : }
23367 :
23368 1821764 : add_gnat_descriptive_type_attribute (type_die, type, context_die);
23369 1821764 : if (TYPE_ARTIFICIAL (type)
23370 1821764 : && (!orig_type_die || !get_AT (type_die, DW_AT_artificial)))
23371 0 : add_AT_flag (type_die, DW_AT_artificial, 1);
23372 : }
23373 : else
23374 8 : add_AT_flag (type_die, DW_AT_declaration, 1);
23375 :
23376 1821772 : add_pubtype (type, type_die);
23377 :
23378 1821772 : return type_die;
23379 : }
23380 :
23381 : /* Generate a DIE to represent either a real live formal parameter decl or to
23382 : represent just the type of some formal parameter position in some function
23383 : type.
23384 :
23385 : Note that this routine is a bit unusual because its argument may be a
23386 : ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
23387 : represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
23388 : node. If it's the former then this function is being called to output a
23389 : DIE to represent a formal parameter object (or some inlining thereof). If
23390 : it's the latter, then this function is only being called to output a
23391 : DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
23392 : argument type of some subprogram type.
23393 : If EMIT_NAME_P is true, name and source coordinate attributes
23394 : are emitted. */
23395 :
23396 : static dw_die_ref
23397 194684930 : gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
23398 : dw_die_ref context_die)
23399 : {
23400 194684930 : tree node_or_origin = node ? node : origin;
23401 194684930 : tree ultimate_origin;
23402 194684930 : dw_die_ref parm_die = NULL;
23403 :
23404 194684930 : if (DECL_P (node_or_origin))
23405 : {
23406 16794577 : parm_die = lookup_decl_die (node);
23407 :
23408 : /* If the contexts differ, we may not be talking about the same
23409 : thing.
23410 : ??? When in LTO the DIE parent is the "abstract" copy and the
23411 : context_die is the specification "copy". */
23412 16794577 : if (parm_die
23413 970870 : && parm_die->die_parent != context_die
23414 86147 : && (parm_die->die_parent->die_tag != DW_TAG_GNU_formal_parameter_pack
23415 2769 : || parm_die->die_parent->die_parent != context_die)
23416 83793 : && !in_lto_p)
23417 : {
23418 83793 : gcc_assert (!DECL_ABSTRACT_P (node));
23419 : /* This can happen when creating a concrete instance, in
23420 : which case we need to create a new DIE that will get
23421 : annotated with DW_AT_abstract_origin. */
23422 : parm_die = NULL;
23423 : }
23424 :
23425 887077 : if (parm_die && parm_die->die_parent == NULL)
23426 : {
23427 : /* Check that parm_die already has the right attributes that
23428 : we would have added below. If any attributes are
23429 : missing, fall through to add them. */
23430 0 : if (! DECL_ABSTRACT_P (node_or_origin)
23431 0 : && !get_AT (parm_die, DW_AT_location)
23432 0 : && !get_AT (parm_die, DW_AT_const_value))
23433 : /* We are missing location info, and are about to add it. */
23434 : ;
23435 : else
23436 : {
23437 0 : add_child_die (context_die, parm_die);
23438 0 : maybe_gen_btf_decl_tag_dies (node_or_origin, parm_die);
23439 0 : return parm_die;
23440 : }
23441 : }
23442 : }
23443 :
23444 : /* If we have a previously generated DIE, use it, unless this is an
23445 : concrete instance (origin != NULL), in which case we need a new
23446 : DIE with a corresponding DW_AT_abstract_origin. */
23447 194684930 : bool reusing_die;
23448 194684930 : if (parm_die && origin == NULL)
23449 : reusing_die = true;
23450 : else
23451 : {
23452 193797853 : parm_die = new_die (DW_TAG_formal_parameter, context_die, node);
23453 193797853 : reusing_die = false;
23454 : }
23455 :
23456 194684930 : switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
23457 : {
23458 16794577 : case tcc_declaration:
23459 16794577 : ultimate_origin = decl_ultimate_origin (node_or_origin);
23460 16794577 : if (node || ultimate_origin)
23461 16794577 : origin = ultimate_origin;
23462 :
23463 16794577 : if (reusing_die)
23464 887077 : goto add_location;
23465 :
23466 15907500 : if (origin != NULL)
23467 12501048 : add_abstract_origin_attribute (parm_die, origin);
23468 3406452 : else if (emit_name_p)
23469 3301019 : add_name_and_src_coords_attributes (parm_die, node);
23470 15907500 : if (origin == NULL
23471 15907500 : || (! DECL_ABSTRACT_P (node_or_origin)
23472 12501048 : && variably_modified_type_p (TREE_TYPE (node_or_origin),
23473 : decl_function_context
23474 : (node_or_origin))))
23475 : {
23476 3408191 : tree type = TREE_TYPE (node_or_origin);
23477 3408191 : if (decl_by_reference_p (node_or_origin))
23478 40400 : add_type_attribute (parm_die, TREE_TYPE (type),
23479 : TYPE_UNQUALIFIED,
23480 : false, context_die);
23481 : else
23482 3367791 : add_type_attribute (parm_die, type,
23483 : decl_quals (node_or_origin),
23484 : false, context_die);
23485 : }
23486 15907500 : if (origin == NULL && DECL_ARTIFICIAL (node))
23487 961034 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23488 16794577 : add_location:
23489 16794577 : if (node && node != origin)
23490 16710732 : equate_decl_number_to_die (node, parm_die);
23491 16794577 : if (! DECL_ABSTRACT_P (node_or_origin))
23492 16794577 : add_location_or_const_value_attribute (parm_die, node_or_origin,
23493 : node == NULL);
23494 :
23495 : break;
23496 :
23497 177890353 : case tcc_type:
23498 : /* We were called with some kind of a ..._TYPE node. */
23499 177890353 : add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED, false,
23500 : context_die);
23501 177890353 : break;
23502 :
23503 0 : default:
23504 0 : gcc_unreachable ();
23505 : }
23506 :
23507 194684930 : maybe_gen_btf_decl_tag_dies (node_or_origin, parm_die);
23508 :
23509 194684930 : return parm_die;
23510 : }
23511 :
23512 : /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
23513 : children DW_TAG_formal_parameter DIEs representing the arguments of the
23514 : parameter pack.
23515 :
23516 : PARM_PACK must be a function parameter pack.
23517 : PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
23518 : must point to the subsequent arguments of the function PACK_ARG belongs to.
23519 : SUBR_DIE is the DIE of the function PACK_ARG belongs to.
23520 : If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
23521 : following the last one for which a DIE was generated. */
23522 :
23523 : static dw_die_ref
23524 84319 : gen_formal_parameter_pack_die (tree parm_pack,
23525 : tree pack_arg,
23526 : dw_die_ref subr_die,
23527 : tree *next_arg)
23528 : {
23529 84319 : tree arg;
23530 84319 : dw_die_ref parm_pack_die;
23531 :
23532 84319 : gcc_assert (parm_pack
23533 : && lang_hooks.function_parameter_pack_p (parm_pack)
23534 : && subr_die);
23535 :
23536 84319 : parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
23537 84319 : add_name_and_src_coords_attributes (parm_pack_die, parm_pack);
23538 :
23539 289610 : for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
23540 : {
23541 120972 : if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
23542 : parm_pack))
23543 : break;
23544 120972 : gen_formal_parameter_die (arg, NULL,
23545 : false /* Don't emit name attribute. */,
23546 : parm_pack_die);
23547 : }
23548 84319 : if (next_arg)
23549 84319 : *next_arg = arg;
23550 84319 : return parm_pack_die;
23551 : }
23552 :
23553 : /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
23554 : at the end of an (ANSI prototyped) formal parameters list. */
23555 :
23556 : static void
23557 87975 : gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
23558 : {
23559 0 : new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
23560 87975 : }
23561 :
23562 : /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
23563 : DW_TAG_unspecified_parameters DIE) to represent the types of the formal
23564 : parameters as specified in some function type specification (except for
23565 : those which appear as part of a function *definition*). */
23566 :
23567 : static void
23568 96113855 : gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
23569 : {
23570 96113855 : tree link;
23571 96113855 : tree formal_type = NULL;
23572 96113855 : tree first_parm_type;
23573 96113855 : tree arg;
23574 :
23575 96113855 : if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
23576 : {
23577 95692650 : arg = DECL_ARGUMENTS (function_or_method_type);
23578 95692650 : function_or_method_type = TREE_TYPE (function_or_method_type);
23579 : }
23580 : else
23581 : arg = NULL_TREE;
23582 :
23583 96113855 : first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
23584 :
23585 : /* Make our first pass over the list of formal parameter types and output a
23586 : DW_TAG_formal_parameter DIE for each one. */
23587 274004208 : for (link = first_parm_type; link; )
23588 : {
23589 273920755 : dw_die_ref parm_die;
23590 :
23591 273920755 : formal_type = TREE_VALUE (link);
23592 273920755 : if (formal_type == void_type_node)
23593 : break;
23594 :
23595 : /* Output a (nameless) DIE to represent the formal parameter itself. */
23596 177890353 : parm_die = gen_formal_parameter_die (formal_type, NULL,
23597 : true /* Emit name attribute. */,
23598 : context_die);
23599 177890353 : if (TREE_CODE (function_or_method_type) == METHOD_TYPE
23600 162479881 : && link == first_parm_type)
23601 : {
23602 82579907 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23603 82579907 : if (dwarf_version >= 3 || !dwarf_strict)
23604 82579907 : add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
23605 : }
23606 95310446 : else if (arg && DECL_ARTIFICIAL (arg))
23607 21423 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23608 :
23609 177890353 : link = TREE_CHAIN (link);
23610 177890353 : if (arg)
23611 177107087 : arg = DECL_CHAIN (arg);
23612 : }
23613 :
23614 : /* If this function type has an ellipsis, add a
23615 : DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
23616 96113855 : if (formal_type != void_type_node)
23617 83453 : gen_unspecified_parameters_die (function_or_method_type, context_die);
23618 :
23619 : /* Make our second (and final) pass over the list of formal parameter types
23620 : and output DIEs to represent those types (as necessary). */
23621 96113855 : for (link = TYPE_ARG_TYPES (function_or_method_type);
23622 643955365 : link && TREE_VALUE (link);
23623 273920755 : link = TREE_CHAIN (link))
23624 273920755 : gen_type_die (TREE_VALUE (link), context_die);
23625 96113855 : }
23626 :
23627 : /* We want to generate the DIE for TYPE so that we can generate the
23628 : die for MEMBER, which has been defined; we will need to refer back
23629 : to the member declaration nested within TYPE. If we're trying to
23630 : generate minimal debug info for TYPE, processing TYPE won't do the
23631 : trick; we need to attach the member declaration by hand. */
23632 :
23633 : static void
23634 117509968 : gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
23635 : {
23636 117509968 : gen_type_die (type, context_die);
23637 :
23638 : /* If we're trying to avoid duplicate debug info, we may not have
23639 : emitted the member decl for this function. Emit it now. */
23640 117509968 : if (TYPE_STUB_DECL (type)
23641 117509968 : && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
23642 117640853 : && ! lookup_decl_die (member))
23643 : {
23644 107950 : dw_die_ref type_die;
23645 107950 : gcc_assert (!decl_ultimate_origin (member));
23646 :
23647 107950 : type_die = lookup_type_die_strip_naming_typedef (type);
23648 107950 : if (TREE_CODE (member) == FUNCTION_DECL)
23649 107235 : gen_subprogram_die (member, type_die);
23650 715 : else if (TREE_CODE (member) == FIELD_DECL)
23651 : {
23652 : /* Ignore the nameless fields that are used to skip bits but handle
23653 : C++ anonymous unions and structs. */
23654 6 : if (DECL_NAME (member) != NULL_TREE
23655 0 : || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
23656 6 : || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
23657 : {
23658 6 : struct vlr_context vlr_ctx = {
23659 6 : DECL_CONTEXT (member), /* struct_type */
23660 : NULL_TREE /* variant_part_offset */
23661 6 : };
23662 6 : gen_type_die (member_declared_type (member), type_die);
23663 6 : gen_field_die (member, &vlr_ctx, type_die);
23664 : }
23665 : }
23666 : else
23667 709 : gen_variable_die (member, NULL_TREE, type_die);
23668 : }
23669 117509968 : }
23670 :
23671 : /* Forward declare these functions, because they are mutually recursive
23672 : with their set_block_* pairing functions. */
23673 : static void set_decl_origin_self (tree);
23674 :
23675 : /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
23676 : given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
23677 : that it points to the node itself, thus indicating that the node is its
23678 : own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
23679 : the given node is NULL, recursively descend the decl/block tree which
23680 : it is the root of, and for each other ..._DECL or BLOCK node contained
23681 : therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
23682 : still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
23683 : values to point to themselves. */
23684 :
23685 : static void
23686 2773017 : set_block_origin_self (tree stmt)
23687 : {
23688 2773017 : if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
23689 : {
23690 1674124 : BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
23691 :
23692 1674124 : {
23693 1674124 : tree local_decl;
23694 :
23695 1674124 : for (local_decl = BLOCK_VARS (stmt);
23696 2423974 : local_decl != NULL_TREE;
23697 749850 : local_decl = DECL_CHAIN (local_decl))
23698 : /* Do not recurse on nested functions since the inlining status
23699 : of parent and child can be different as per the DWARF spec. */
23700 749850 : if (TREE_CODE (local_decl) != FUNCTION_DECL
23701 749850 : && !DECL_EXTERNAL (local_decl))
23702 746546 : set_decl_origin_self (local_decl);
23703 : }
23704 :
23705 1674124 : {
23706 1674124 : tree subblock;
23707 :
23708 3138394 : for (subblock = BLOCK_SUBBLOCKS (stmt);
23709 3138394 : subblock != NULL_TREE;
23710 1464270 : subblock = BLOCK_CHAIN (subblock))
23711 1464270 : set_block_origin_self (subblock); /* Recurse. */
23712 : }
23713 : }
23714 2773017 : }
23715 :
23716 : /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
23717 : the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
23718 : node to so that it points to the node itself, thus indicating that the
23719 : node represents its own (abstract) origin. Additionally, if the
23720 : DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
23721 : the decl/block tree of which the given node is the root of, and for
23722 : each other ..._DECL or BLOCK node contained therein whose
23723 : DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
23724 : set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
23725 : point to themselves. */
23726 :
23727 : static void
23728 2070676 : set_decl_origin_self (tree decl)
23729 : {
23730 2070676 : if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
23731 : {
23732 2070676 : DECL_ABSTRACT_ORIGIN (decl) = decl;
23733 2070676 : if (TREE_CODE (decl) == FUNCTION_DECL)
23734 : {
23735 1324130 : tree arg;
23736 :
23737 3830414 : for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
23738 2506284 : DECL_ABSTRACT_ORIGIN (arg) = arg;
23739 1324130 : if (DECL_INITIAL (decl) != NULL_TREE
23740 1324130 : && DECL_INITIAL (decl) != error_mark_node)
23741 1308747 : set_block_origin_self (DECL_INITIAL (decl));
23742 : }
23743 : }
23744 2070676 : }
23745 :
23746 : /* Mark the early DIE for DECL as the abstract instance. */
23747 :
23748 : static void
23749 4263411 : dwarf2out_abstract_function (tree decl)
23750 : {
23751 4263411 : dw_die_ref old_die;
23752 :
23753 : /* Make sure we have the actual abstract inline, not a clone. */
23754 4263411 : decl = DECL_ORIGIN (decl);
23755 :
23756 4263411 : if (DECL_IGNORED_P (decl))
23757 : return;
23758 :
23759 : #ifdef CODEVIEW_DEBUGGING_INFO
23760 : if (codeview_debuginfo_p ())
23761 : codeview_abstract_function (decl);
23762 : #endif
23763 :
23764 : /* In LTO we're all set. We already created abstract instances
23765 : early and we want to avoid creating a concrete instance of that
23766 : if we don't output it. */
23767 4263276 : if (in_lto_p)
23768 : return;
23769 :
23770 4262858 : old_die = lookup_decl_die (decl);
23771 4262858 : gcc_assert (old_die != NULL);
23772 4262858 : if (get_AT (old_die, DW_AT_inline))
23773 : /* We've already generated the abstract instance. */
23774 : return;
23775 :
23776 : /* Go ahead and put DW_AT_inline on the DIE. */
23777 1324130 : if (DECL_DECLARED_INLINE_P (decl))
23778 : {
23779 1209371 : if (cgraph_function_possibly_inlined_p (decl))
23780 918217 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_inlined);
23781 : else
23782 291154 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_not_inlined);
23783 : }
23784 : else
23785 : {
23786 114759 : if (cgraph_function_possibly_inlined_p (decl))
23787 94699 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_inlined);
23788 : else
23789 20060 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_not_inlined);
23790 : }
23791 :
23792 1324130 : if (DECL_DECLARED_INLINE_P (decl)
23793 1209371 : && !DECL_ARTIFICIAL (decl)
23794 2476286 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
23795 1267 : add_AT_flag (old_die, DW_AT_artificial, 1);
23796 :
23797 1324130 : set_decl_origin_self (decl);
23798 : }
23799 :
23800 : /* Helper function of premark_used_types() which gets called through
23801 : htab_traverse.
23802 :
23803 : Marks the DIE of a given type in *SLOT as perennial, so it never gets
23804 : marked as unused by prune_unused_types. */
23805 :
23806 : bool
23807 1193596 : premark_used_types_helper (tree const &type, void *)
23808 : {
23809 1193596 : dw_die_ref die;
23810 :
23811 1193596 : die = lookup_type_die (type);
23812 1193596 : if (die != NULL)
23813 1038936 : die->die_perennial_p = 1;
23814 1193596 : return true;
23815 : }
23816 :
23817 : /* Helper function of premark_types_used_by_global_vars which gets called
23818 : through htab_traverse.
23819 :
23820 : Marks the DIE of a given type in *SLOT as perennial, so it never gets
23821 : marked as unused by prune_unused_types. The DIE of the type is marked
23822 : only if the global variable using the type will actually be emitted. */
23823 :
23824 : int
23825 8423743 : premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
23826 : void *)
23827 : {
23828 8423743 : struct types_used_by_vars_entry *entry;
23829 8423743 : dw_die_ref die;
23830 :
23831 8423743 : entry = (struct types_used_by_vars_entry *) *slot;
23832 8423743 : gcc_assert (entry->type != NULL
23833 : && entry->var_decl != NULL);
23834 8423743 : die = lookup_type_die (entry->type);
23835 8423743 : if (die)
23836 : {
23837 : /* Ask cgraph if the global variable really is to be emitted.
23838 : If yes, then we'll keep the DIE of ENTRY->TYPE. */
23839 7664025 : varpool_node *node = varpool_node::get (entry->var_decl);
23840 7664025 : if (node && node->definition)
23841 : {
23842 10036 : die->die_perennial_p = 1;
23843 : /* Keep the parent DIEs as well. */
23844 17892 : while ((die = die->die_parent) && die->die_perennial_p == 0)
23845 7856 : die->die_perennial_p = 1;
23846 : }
23847 : }
23848 8423743 : return 1;
23849 : }
23850 :
23851 : /* Mark all members of used_types_hash as perennial. */
23852 :
23853 : static void
23854 98381538 : premark_used_types (struct function *fun)
23855 : {
23856 98381538 : if (fun && fun->used_types_hash)
23857 2032314 : fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
23858 98381538 : }
23859 :
23860 : /* Mark all members of types_used_by_vars_entry as perennial. */
23861 :
23862 : static void
23863 52458 : premark_types_used_by_global_vars (void)
23864 : {
23865 52458 : if (types_used_by_vars_hash)
23866 13717 : types_used_by_vars_hash
23867 8437460 : ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
23868 52458 : }
23869 :
23870 : /* Mark all variables used by the symtab as perennial. */
23871 :
23872 : static void
23873 52426 : premark_used_variables (void)
23874 : {
23875 : /* Mark DIEs in the symtab as used. */
23876 52426 : varpool_node *var;
23877 2010973 : FOR_EACH_VARIABLE (var)
23878 : {
23879 1958547 : dw_die_ref die = lookup_decl_die (var->decl);
23880 1958547 : if (die)
23881 : {
23882 270169 : die->die_perennial_p = 1;
23883 270169 : if (tree attr = lookup_attribute ("structured bindings",
23884 270169 : DECL_ATTRIBUTES (var->decl)))
23885 166 : for (tree d = TREE_VALUE (attr); d; d = TREE_CHAIN (d))
23886 : {
23887 128 : die = lookup_decl_die (TREE_VALUE (d));
23888 128 : if (die)
23889 128 : die->die_perennial_p = 1;
23890 : }
23891 : }
23892 : }
23893 52426 : }
23894 :
23895 : /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
23896 : for CA_LOC call arg loc node. */
23897 :
23898 : static dw_die_ref
23899 2842874 : gen_call_site_die (tree decl, dw_die_ref subr_die,
23900 : struct call_arg_loc_node *ca_loc)
23901 : {
23902 2842874 : dw_die_ref stmt_die = NULL, die;
23903 2842874 : tree block = ca_loc->block;
23904 :
23905 2842874 : while (block
23906 5381707 : && block != DECL_INITIAL (decl)
23907 9827400 : && TREE_CODE (block) == BLOCK)
23908 : {
23909 4381710 : stmt_die = lookup_block_die (block);
23910 4381710 : if (stmt_die)
23911 : break;
23912 2602816 : block = BLOCK_SUPERCONTEXT (block);
23913 : }
23914 2842874 : if (stmt_die == NULL)
23915 1063980 : stmt_die = subr_die;
23916 2844729 : die = new_die (dwarf_TAG (DW_TAG_call_site), stmt_die, NULL_TREE);
23917 2844729 : add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc),
23918 : ca_loc->label,
23919 2842874 : targetm.calls.call_offset_return_label (ca_loc->call_insn));
23920 2842874 : if (ca_loc->tail_call_p)
23921 54727 : add_AT_flag (die, dwarf_AT (DW_AT_call_tail_call), 1);
23922 2842874 : if (ca_loc->symbol_ref)
23923 : {
23924 2773654 : dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
23925 2773654 : if (tdie)
23926 1299631 : add_AT_die_ref (die, dwarf_AT (DW_AT_call_origin), tdie);
23927 : else
23928 1475856 : add_AT_addr (die, dwarf_AT (DW_AT_call_origin), ca_loc->symbol_ref,
23929 : false);
23930 : }
23931 2842874 : return die;
23932 : }
23933 :
23934 : /* Generate a DIE to represent a declared function (either file-scope or
23935 : block-local). */
23936 :
23937 : static void
23938 98505569 : gen_subprogram_die (tree decl, dw_die_ref context_die)
23939 : {
23940 98505569 : tree origin = decl_ultimate_origin (decl);
23941 98505569 : dw_die_ref subr_die;
23942 98505569 : dw_die_ref old_die = lookup_decl_die (decl);
23943 98505569 : bool old_die_had_no_children = false;
23944 :
23945 : /* This function gets called multiple times for different stages of
23946 : the debug process. For example, for func() in this code:
23947 :
23948 : namespace S
23949 : {
23950 : void func() { ... }
23951 : }
23952 :
23953 : ...we get called 4 times. Twice in early debug and twice in
23954 : late debug:
23955 :
23956 : Early debug
23957 : -----------
23958 :
23959 : 1. Once while generating func() within the namespace. This is
23960 : the declaration. The declaration bit below is set, as the
23961 : context is the namespace.
23962 :
23963 : A new DIE will be generated with DW_AT_declaration set.
23964 :
23965 : 2. Once for func() itself. This is the specification. The
23966 : declaration bit below is clear as the context is the CU.
23967 :
23968 : We will use the cached DIE from (1) to create a new DIE with
23969 : DW_AT_specification pointing to the declaration in (1).
23970 :
23971 : Late debug via rest_of_handle_final()
23972 : -------------------------------------
23973 :
23974 : 3. Once generating func() within the namespace. This is also the
23975 : declaration, as in (1), but this time we will early exit below
23976 : as we have a cached DIE and a declaration needs no additional
23977 : annotations (no locations), as the source declaration line
23978 : info is enough.
23979 :
23980 : 4. Once for func() itself. As in (2), this is the specification,
23981 : but this time we will re-use the cached DIE, and just annotate
23982 : it with the location information that should now be available.
23983 :
23984 : For something without namespaces, but with abstract instances, we
23985 : are also called a multiple times:
23986 :
23987 : class Base
23988 : {
23989 : public:
23990 : Base (); // constructor declaration (1)
23991 : };
23992 :
23993 : Base::Base () { } // constructor specification (2)
23994 :
23995 : Early debug
23996 : -----------
23997 :
23998 : 1. Once for the Base() constructor by virtue of it being a
23999 : member of the Base class. This is done via
24000 : rest_of_type_compilation.
24001 :
24002 : This is a declaration, so a new DIE will be created with
24003 : DW_AT_declaration.
24004 :
24005 : 2. Once for the Base() constructor definition, but this time
24006 : while generating the abstract instance of the base
24007 : constructor (__base_ctor) which is being generated via early
24008 : debug of reachable functions.
24009 :
24010 : Even though we have a cached version of the declaration (1),
24011 : we will create a DW_AT_specification of the declaration DIE
24012 : in (1).
24013 :
24014 : 3. Once for the __base_ctor itself, but this time, we generate
24015 : an DW_AT_abstract_origin version of the DW_AT_specification in
24016 : (2).
24017 :
24018 : Late debug via rest_of_handle_final
24019 : -----------------------------------
24020 :
24021 : 4. One final time for the __base_ctor (which will have a cached
24022 : DIE with DW_AT_abstract_origin created in (3). This time,
24023 : we will just annotate the location information now
24024 : available.
24025 : */
24026 98505569 : int declaration = (current_function_decl != decl
24027 3372825 : || (!DECL_INITIAL (decl) && !origin)
24028 101498798 : || class_or_namespace_scope_p (context_die));
24029 :
24030 : /* A declaration that has been previously dumped needs no
24031 : additional information. */
24032 98505569 : if (old_die && declaration)
24033 : return;
24034 :
24035 98381538 : if (in_lto_p && old_die && old_die->die_child == NULL)
24036 98381538 : old_die_had_no_children = true;
24037 :
24038 : /* Now that the C++ front end lazily declares artificial member fns, we
24039 : might need to retrofit the declaration into its class. */
24040 2261092 : if (!declaration && !origin && !old_die
24041 695115 : && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
24042 230718 : && !class_or_namespace_scope_p (context_die)
24043 98612256 : && debug_info_level > DINFO_LEVEL_TERSE)
24044 230483 : old_die = force_decl_die (decl);
24045 :
24046 : /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
24047 98381538 : if (origin != NULL)
24048 : {
24049 427596 : gcc_assert (!declaration || local_scope_p (context_die));
24050 :
24051 : /* Fixup die_parent for the abstract instance of a nested
24052 : inline function. */
24053 427596 : if (old_die && old_die->die_parent == NULL)
24054 0 : add_child_die (context_die, old_die);
24055 :
24056 76425 : if (old_die && get_AT_ref (old_die, DW_AT_abstract_origin))
24057 : {
24058 : /* If we have a DW_AT_abstract_origin we have a working
24059 : cached version. */
24060 : subr_die = old_die;
24061 : }
24062 : else
24063 : {
24064 400811 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
24065 400811 : add_abstract_origin_attribute (subr_die, origin);
24066 : /* This is where the actual code for a cloned function is.
24067 : Let's emit linkage name attribute for it. This helps
24068 : debuggers to e.g, set breakpoints into
24069 : constructors/destructors when the user asks "break
24070 : K::K". */
24071 400811 : add_linkage_name (subr_die, decl);
24072 : }
24073 : }
24074 : /* A cached copy, possibly from early dwarf generation. Reuse as
24075 : much as possible. */
24076 97953942 : else if (old_die)
24077 : {
24078 1796460 : if (!get_AT_flag (old_die, DW_AT_declaration)
24079 : /* We can have a normal definition following an inline one in the
24080 : case of redefinition of GNU C extern inlines.
24081 : It seems reasonable to use AT_specification in this case. */
24082 1796460 : && !get_AT (old_die, DW_AT_inline))
24083 : {
24084 : /* Detect and ignore this case, where we are trying to output
24085 : something we have already output. */
24086 387934 : if (get_AT (old_die, DW_AT_low_pc)
24087 387934 : || get_AT (old_die, DW_AT_ranges))
24088 0 : return;
24089 :
24090 : /* If we have no location information, this must be a
24091 : partially generated DIE from early dwarf generation.
24092 : Fall through and generate it. */
24093 : }
24094 :
24095 : /* If the definition comes from the same place as the declaration,
24096 : maybe use the old DIE. We always want the DIE for this function
24097 : that has the *_pc attributes to be under comp_unit_die so the
24098 : debugger can find it. We also need to do this for abstract
24099 : instances of inlines, since the spec requires the out-of-line copy
24100 : to have the same parent. For local class methods, this doesn't
24101 : apply; we just use the old DIE. */
24102 1796460 : expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
24103 1796460 : struct dwarf_file_data * file_index = lookup_filename (s.file);
24104 1796460 : if (((is_unit_die (old_die->die_parent)
24105 : /* This condition fixes the inconsistency/ICE with the
24106 : following Fortran test (or some derivative thereof) while
24107 : building libgfortran:
24108 :
24109 : module some_m
24110 : contains
24111 : logical function funky (FLAG)
24112 : funky = .true.
24113 : end function
24114 : end module
24115 : */
24116 1343445 : || (old_die->die_parent
24117 1343445 : && old_die->die_parent->die_tag == DW_TAG_module)
24118 1340685 : || local_scope_p (old_die->die_parent)
24119 1294165 : || context_die == NULL)
24120 502325 : && (DECL_ARTIFICIAL (decl)
24121 464525 : || (get_AT_file (old_die, DW_AT_decl_file) == file_index
24122 461982 : && (get_AT_unsigned (old_die, DW_AT_decl_line)
24123 461982 : == (unsigned) s.line)
24124 461982 : && (!debug_column_info
24125 461978 : || s.column == 0
24126 368195 : || (get_AT_unsigned (old_die, DW_AT_decl_column)
24127 368195 : == (unsigned) s.column)))))
24128 : /* With LTO if there's an abstract instance for
24129 : the old DIE, this is a concrete instance and
24130 : thus re-use the DIE. */
24131 3093138 : || get_AT (old_die, DW_AT_abstract_origin))
24132 : {
24133 505709 : subr_die = old_die;
24134 :
24135 : /* Clear out the declaration attribute, but leave the
24136 : parameters so they can be augmented with location
24137 : information later. Unless this was a declaration, in
24138 : which case, wipe out the nameless parameters and recreate
24139 : them further down. */
24140 505709 : if (remove_AT (subr_die, DW_AT_declaration))
24141 : {
24142 :
24143 44205 : remove_AT (subr_die, DW_AT_object_pointer);
24144 44205 : remove_child_TAG (subr_die, DW_TAG_formal_parameter);
24145 : }
24146 : }
24147 : /* Make a specification pointing to the previously built
24148 : declaration. */
24149 : else
24150 : {
24151 1290751 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
24152 1290751 : add_AT_specification (subr_die, old_die);
24153 1290751 : add_pubname (decl, subr_die);
24154 1290751 : if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
24155 46868 : add_AT_file (subr_die, DW_AT_decl_file, file_index);
24156 1290751 : if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
24157 51396 : add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
24158 1290751 : if (debug_column_info
24159 1290739 : && s.column
24160 2581490 : && (get_AT_unsigned (old_die, DW_AT_decl_column)
24161 1290739 : != (unsigned) s.column))
24162 51386 : add_AT_unsigned (subr_die, DW_AT_decl_column, s.column);
24163 :
24164 : /* If the prototype had an 'auto' or 'decltype(auto)' in
24165 : the return type, emit the real type on the definition die. */
24166 1290751 : if (is_cxx () && debug_info_level > DINFO_LEVEL_TERSE)
24167 : {
24168 1290751 : dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
24169 1290751 : while (die
24170 1622904 : && (die->die_tag == DW_TAG_reference_type
24171 : || die->die_tag == DW_TAG_rvalue_reference_type
24172 : || die->die_tag == DW_TAG_pointer_type
24173 : || die->die_tag == DW_TAG_const_type
24174 : || die->die_tag == DW_TAG_volatile_type
24175 : || die->die_tag == DW_TAG_restrict_type
24176 : || die->die_tag == DW_TAG_array_type
24177 : || die->die_tag == DW_TAG_ptr_to_member_type
24178 : || die->die_tag == DW_TAG_subroutine_type))
24179 332153 : die = get_AT_ref (die, DW_AT_type);
24180 1290751 : if (die == auto_die || die == decltype_auto_die)
24181 107558 : add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
24182 : TYPE_UNQUALIFIED, false, context_die);
24183 : }
24184 :
24185 : /* When we process the method declaration, we haven't seen
24186 : the out-of-class defaulted definition yet, so we have to
24187 : recheck now. */
24188 1294 : if ((dwarf_version >= 5 || ! dwarf_strict)
24189 1292033 : && !get_AT (subr_die, DW_AT_defaulted))
24190 : {
24191 1269740 : int defaulted
24192 1269740 : = lang_hooks.decls.decl_dwarf_attribute (decl,
24193 : DW_AT_defaulted);
24194 1269740 : if (defaulted != -1)
24195 : {
24196 : /* Other values must have been handled before. */
24197 318 : gcc_assert (defaulted == DW_DEFAULTED_out_of_class);
24198 318 : add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
24199 : }
24200 : }
24201 : }
24202 : }
24203 : /* Create a fresh DIE for anything else. */
24204 : else
24205 : {
24206 96157482 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
24207 :
24208 96157482 : if (TREE_PUBLIC (decl))
24209 95967945 : add_AT_flag (subr_die, DW_AT_external, 1);
24210 :
24211 96157482 : add_name_and_src_coords_attributes (subr_die, decl);
24212 96157482 : add_pubname (decl, subr_die);
24213 96157482 : if (debug_info_level > DINFO_LEVEL_TERSE)
24214 : {
24215 96143707 : add_prototyped_attribute (subr_die, TREE_TYPE (decl));
24216 96143707 : add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
24217 : TYPE_UNQUALIFIED, false, context_die);
24218 : }
24219 :
24220 96157482 : add_pure_or_virtual_attribute (subr_die, decl);
24221 96157482 : if (DECL_ARTIFICIAL (decl))
24222 2019959 : add_AT_flag (subr_die, DW_AT_artificial, 1);
24223 :
24224 96157482 : if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
24225 69645 : add_AT_flag (subr_die, DW_AT_noreturn, 1);
24226 :
24227 96157482 : add_alignment_attribute (subr_die, decl);
24228 :
24229 96157482 : add_accessibility_attribute (subr_die, decl);
24230 : }
24231 :
24232 : /* Unless we have an existing non-declaration DIE, equate the new
24233 : DIE. */
24234 98381538 : if (!old_die || is_declaration_die (old_die))
24235 97799392 : equate_decl_number_to_die (decl, subr_die);
24236 :
24237 98381538 : if (declaration)
24238 : {
24239 95692850 : if (!old_die || !get_AT (old_die, DW_AT_inline))
24240 : {
24241 95692850 : add_AT_flag (subr_die, DW_AT_declaration, 1);
24242 :
24243 : /* If this is an explicit function declaration then generate
24244 : a DW_AT_explicit attribute. */
24245 2994 : if ((dwarf_version >= 3 || !dwarf_strict)
24246 95695844 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24247 : DW_AT_explicit) == 1)
24248 2922925 : add_AT_flag (subr_die, DW_AT_explicit, 1);
24249 :
24250 : /* If this is a C++11 deleted special function member then generate
24251 : a DW_AT_deleted attribute. */
24252 3216 : if ((dwarf_version >= 5 || !dwarf_strict)
24253 95696048 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24254 : DW_AT_deleted) == 1)
24255 3151580 : add_AT_flag (subr_die, DW_AT_deleted, 1);
24256 :
24257 : /* If this is a C++11 defaulted special function member then
24258 : generate a DW_AT_defaulted attribute. */
24259 95692850 : if (dwarf_version >= 5 || !dwarf_strict)
24260 : {
24261 95692832 : int defaulted
24262 95692832 : = lang_hooks.decls.decl_dwarf_attribute (decl,
24263 : DW_AT_defaulted);
24264 95692832 : if (defaulted != -1)
24265 5943334 : add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
24266 : }
24267 :
24268 : /* If this is a C++11 non-static member function with & ref-qualifier
24269 : then generate a DW_AT_reference attribute. */
24270 3216 : if ((dwarf_version >= 5 || !dwarf_strict)
24271 95696048 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24272 : DW_AT_reference) == 1)
24273 41010 : add_AT_flag (subr_die, DW_AT_reference, 1);
24274 :
24275 : /* If this is a C++11 non-static member function with &&
24276 : ref-qualifier then generate a DW_AT_reference attribute. */
24277 3216 : if ((dwarf_version >= 5 || !dwarf_strict)
24278 95696048 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24279 : DW_AT_rvalue_reference)
24280 : == 1)
24281 63400 : add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
24282 : }
24283 : }
24284 : /* For non DECL_EXTERNALs, if range information is available, fill
24285 : the DIE with it. */
24286 2688688 : else if (!DECL_EXTERNAL (decl) && !early_dwarf)
24287 : {
24288 560209 : HOST_WIDE_INT cfa_fb_offset;
24289 :
24290 560209 : struct function *fun = DECL_STRUCT_FUNCTION (decl);
24291 :
24292 560209 : if (!crtl->has_bb_partition)
24293 : {
24294 539328 : dw_fde_ref fde = fun->fde;
24295 539328 : if (fde->dw_fde_begin)
24296 : {
24297 : /* We have already generated the labels. */
24298 539328 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
24299 : fde->dw_fde_end, false);
24300 : }
24301 : else
24302 : {
24303 : /* Create start/end labels and add the range. */
24304 0 : char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
24305 0 : char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
24306 0 : ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
24307 : current_function_funcdef_no);
24308 0 : ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
24309 : current_function_funcdef_no);
24310 0 : add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
24311 : false);
24312 : }
24313 :
24314 : #if VMS_DEBUGGING_INFO
24315 : /* HP OpenVMS Industry Standard 64: DWARF Extensions
24316 : Section 2.3 Prologue and Epilogue Attributes:
24317 : When a breakpoint is set on entry to a function, it is generally
24318 : desirable for execution to be suspended, not on the very first
24319 : instruction of the function, but rather at a point after the
24320 : function's frame has been set up, after any language defined local
24321 : declaration processing has been completed, and before execution of
24322 : the first statement of the function begins. Debuggers generally
24323 : cannot properly determine where this point is. Similarly for a
24324 : breakpoint set on exit from a function. The prologue and epilogue
24325 : attributes allow a compiler to communicate the location(s) to use. */
24326 :
24327 : {
24328 : if (fde->dw_fde_vms_end_prologue)
24329 : add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
24330 : fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
24331 :
24332 : if (fde->dw_fde_vms_begin_epilogue)
24333 : add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
24334 : fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
24335 : }
24336 : #endif
24337 :
24338 : }
24339 : else
24340 : {
24341 : /* Generate pubnames entries for the split function code ranges. */
24342 20881 : dw_fde_ref fde = fun->fde;
24343 :
24344 20881 : if (fde->dw_fde_second_begin)
24345 : {
24346 20881 : if (dwarf_version >= 3 || !dwarf_strict)
24347 : {
24348 : /* We should use ranges for non-contiguous code section
24349 : addresses. Use the actual code range for the initial
24350 : section, since the HOT/COLD labels might precede an
24351 : alignment offset. */
24352 20881 : bool range_list_added = false;
24353 20881 : add_ranges_by_labels (subr_die, fde->dw_fde_begin,
24354 : fde->dw_fde_end, &range_list_added,
24355 : false);
24356 20881 : add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
24357 : fde->dw_fde_second_end,
24358 : &range_list_added, false);
24359 20881 : if (range_list_added)
24360 20881 : add_ranges (NULL);
24361 20881 : }
24362 : else
24363 : {
24364 : /* There is no real support in DW2 for this .. so we make
24365 : a work-around. First, emit the pub name for the segment
24366 : containing the function label. Then make and emit a
24367 : simplified subprogram DIE for the second segment with the
24368 : name pre-fixed by __hot/cold_sect_of_. We use the same
24369 : linkage name for the second die so that gdb will find both
24370 : sections when given "b foo". */
24371 0 : const char *name = NULL;
24372 0 : tree decl_name = DECL_NAME (decl);
24373 0 : dw_die_ref seg_die;
24374 :
24375 : /* Do the 'primary' section. */
24376 0 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
24377 : fde->dw_fde_end, false);
24378 :
24379 : /* Build a minimal DIE for the secondary section. */
24380 0 : seg_die = new_die (DW_TAG_subprogram,
24381 : subr_die->die_parent, decl);
24382 :
24383 0 : if (TREE_PUBLIC (decl))
24384 0 : add_AT_flag (seg_die, DW_AT_external, 1);
24385 :
24386 0 : if (decl_name != NULL
24387 0 : && IDENTIFIER_POINTER (decl_name) != NULL)
24388 : {
24389 0 : name = dwarf2_name (decl, 1);
24390 0 : if (! DECL_ARTIFICIAL (decl))
24391 0 : add_src_coords_attributes (seg_die, decl);
24392 :
24393 0 : add_linkage_name (seg_die, decl);
24394 : }
24395 0 : gcc_assert (name != NULL);
24396 0 : add_pure_or_virtual_attribute (seg_die, decl);
24397 0 : if (DECL_ARTIFICIAL (decl))
24398 0 : add_AT_flag (seg_die, DW_AT_artificial, 1);
24399 :
24400 0 : name = concat ("__second_sect_of_", name, NULL);
24401 0 : add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
24402 : fde->dw_fde_second_end, false);
24403 0 : add_name_attribute (seg_die, name);
24404 0 : if (want_pubnames ())
24405 0 : add_pubname_string (name, seg_die);
24406 : }
24407 : }
24408 : else
24409 0 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
24410 : false);
24411 : }
24412 :
24413 560209 : cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
24414 :
24415 : /* We define the "frame base" as the function's CFA. This is more
24416 : convenient for several reasons: (1) It's stable across the prologue
24417 : and epilogue, which makes it better than just a frame pointer,
24418 : (2) With dwarf3, there exists a one-byte encoding that allows us
24419 : to reference the .debug_frame data by proxy, but failing that,
24420 : (3) We can at least reuse the code inspection and interpretation
24421 : code that determines the CFA position at various points in the
24422 : function. */
24423 560209 : if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
24424 : {
24425 556764 : dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
24426 556764 : add_AT_loc (subr_die, DW_AT_frame_base, op);
24427 : }
24428 : else
24429 : {
24430 3445 : dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
24431 3445 : if (list->dw_loc_next)
24432 1878 : add_AT_loc_list (subr_die, DW_AT_frame_base, list);
24433 : else
24434 1567 : add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
24435 : }
24436 :
24437 : /* Compute a displacement from the "steady-state frame pointer" to
24438 : the CFA. The former is what all stack slots and argument slots
24439 : will reference in the rtl; the latter is what we've told the
24440 : debugger about. We'll need to adjust all frame_base references
24441 : by this displacement. */
24442 560209 : compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
24443 :
24444 560209 : if (fun->static_chain_decl)
24445 : {
24446 : /* DWARF requires here a location expression that computes the
24447 : address of the enclosing subprogram's frame base. The machinery
24448 : in tree-nested.cc is supposed to store this specific address in the
24449 : last field of the FRAME record. */
24450 14527 : const tree frame_type
24451 14527 : = TREE_TYPE (TREE_TYPE (fun->static_chain_decl));
24452 14527 : const tree fb_decl = tree_last (TYPE_FIELDS (frame_type));
24453 :
24454 14527 : tree fb_expr
24455 14527 : = build1 (INDIRECT_REF, frame_type, fun->static_chain_decl);
24456 14527 : fb_expr = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
24457 : fb_expr, fb_decl, NULL_TREE);
24458 :
24459 14527 : add_AT_location_description (subr_die, DW_AT_static_link,
24460 : loc_list_from_tree (fb_expr, 0, NULL));
24461 : }
24462 :
24463 560209 : resolve_variable_values ();
24464 : }
24465 :
24466 : /* Generate child dies for template parameters. */
24467 98381538 : if (early_dwarf && debug_info_level > DINFO_LEVEL_TERSE)
24468 97807363 : gen_generic_params_dies (decl);
24469 :
24470 : /* Now output descriptions of the arguments for this function. This gets
24471 : (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
24472 : for a FUNCTION_DECL doesn't indicate cases where there was a trailing
24473 : `...' at the end of the formal parameter list. In order to find out if
24474 : there was a trailing ellipsis or not, we must instead look at the type
24475 : associated with the FUNCTION_DECL. This will be a node of type
24476 : FUNCTION_TYPE. If the chain of type nodes hanging off of this
24477 : FUNCTION_TYPE node ends with a void_type_node then there should *not* be
24478 : an ellipsis at the end. */
24479 :
24480 : /* In the case where we are describing a mere function declaration, all we
24481 : need to do here (and all we *can* do here) is to describe the *types* of
24482 : its formal parameters. */
24483 98381538 : if (debug_info_level <= DINFO_LEVEL_TERSE)
24484 : ;
24485 98354443 : else if (declaration)
24486 95692650 : gen_formal_types_die (decl, subr_die);
24487 : else
24488 : {
24489 : /* Generate DIEs to represent all known formal parameters. */
24490 2661793 : tree parm = DECL_ARGUMENTS (decl);
24491 2661793 : tree generic_decl = early_dwarf
24492 2661793 : ? lang_hooks.decls.get_generic_function_decl (decl) : NULL;
24493 2114730 : tree generic_decl_parm = generic_decl
24494 2114730 : ? DECL_ARGUMENTS (generic_decl)
24495 473858 : : NULL;
24496 :
24497 : /* Now we want to walk the list of parameters of the function and
24498 : emit their relevant DIEs.
24499 :
24500 : We consider the case of DECL being an instance of a generic function
24501 : as well as it being a normal function.
24502 :
24503 : If DECL is an instance of a generic function we walk the
24504 : parameters of the generic function declaration _and_ the parameters of
24505 : DECL itself. This is useful because we want to emit specific DIEs for
24506 : function parameter packs and those are declared as part of the
24507 : generic function declaration. In that particular case,
24508 : the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
24509 : That DIE has children DIEs representing the set of arguments
24510 : of the pack. Note that the set of pack arguments can be empty.
24511 : In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
24512 : children DIE.
24513 :
24514 : Otherwise, we just consider the parameters of DECL. */
24515 7610847 : while (generic_decl_parm || parm)
24516 : {
24517 : if (generic_decl_parm
24518 1095633 : && lang_hooks.function_parameter_pack_p (generic_decl_parm))
24519 84319 : gen_formal_parameter_pack_die (generic_decl_parm,
24520 : parm, subr_die,
24521 : &parm);
24522 4864735 : else if (parm)
24523 : {
24524 4864735 : dw_die_ref parm_die = gen_decl_die (parm, NULL, NULL, subr_die);
24525 :
24526 4864735 : if (early_dwarf
24527 3847438 : && parm == DECL_ARGUMENTS (decl)
24528 2000863 : && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
24529 1249650 : && parm_die
24530 6114385 : && (dwarf_version >= 3 || !dwarf_strict))
24531 1249650 : add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
24532 :
24533 4864735 : parm = DECL_CHAIN (parm);
24534 : }
24535 :
24536 4949054 : if (generic_decl_parm)
24537 1095633 : generic_decl_parm = DECL_CHAIN (generic_decl_parm);
24538 : }
24539 :
24540 : /* Decide whether we need an unspecified_parameters DIE at the end.
24541 : There are 2 more cases to do this for: 1) the ansi ... declaration -
24542 : this is detectable when the end of the arg list is not a
24543 : void_type_node 2) an unprototyped function declaration (not a
24544 : definition). This just means that we have no info about the
24545 : parameters at all. */
24546 2661793 : if (early_dwarf)
24547 : {
24548 2114730 : if (prototype_p (TREE_TYPE (decl)))
24549 : {
24550 : /* This is the prototyped case, check for.... */
24551 2112476 : if (stdarg_p (TREE_TYPE (decl)))
24552 4326 : gen_unspecified_parameters_die (decl, subr_die);
24553 : }
24554 2254 : else if (DECL_INITIAL (decl) == NULL_TREE)
24555 0 : gen_unspecified_parameters_die (decl, subr_die);
24556 : }
24557 547063 : else if ((subr_die != old_die || old_die_had_no_children)
24558 77550 : && prototype_p (TREE_TYPE (decl))
24559 624306 : && stdarg_p (TREE_TYPE (decl)))
24560 196 : gen_unspecified_parameters_die (decl, subr_die);
24561 : }
24562 :
24563 98381538 : if (subr_die != old_die)
24564 : /* Add the calling convention attribute if requested. */
24565 97849044 : add_calling_convention_attribute (subr_die, decl);
24566 :
24567 : /* Output Dwarf info for all of the stuff within the body of the function
24568 : (if it has one - it may be just a declaration).
24569 :
24570 : OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
24571 : a function. This BLOCK actually represents the outermost binding contour
24572 : for the function, i.e. the contour in which the function's formal
24573 : parameters and labels get declared. Curiously, it appears that the front
24574 : end doesn't actually put the PARM_DECL nodes for the current function onto
24575 : the BLOCK_VARS list for this outer scope, but are strung off of the
24576 : DECL_ARGUMENTS list for the function instead.
24577 :
24578 : The BLOCK_VARS list for the `outer_scope' does provide us with a list of
24579 : the LABEL_DECL nodes for the function however, and we output DWARF info
24580 : for those in decls_for_scope. Just within the `outer_scope' there will be
24581 : a BLOCK node representing the function's outermost pair of curly braces,
24582 : and any blocks used for the base and member initializers of a C++
24583 : constructor function. */
24584 98381538 : tree outer_scope = DECL_INITIAL (decl);
24585 98381538 : if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
24586 : {
24587 2669989 : int call_site_note_count = 0;
24588 2669989 : int tail_call_site_note_count = 0;
24589 :
24590 : /* Emit a DW_TAG_variable DIE for a named return value. */
24591 2669989 : if (DECL_NAME (DECL_RESULT (decl)))
24592 9355 : gen_decl_die (DECL_RESULT (decl), NULL, NULL, subr_die);
24593 :
24594 : /* The first time through decls_for_scope we will generate the
24595 : DIEs for the locals. The second time, we fill in the
24596 : location info. */
24597 2669989 : decls_for_scope (outer_scope, subr_die);
24598 :
24599 2669989 : if (call_arg_locations && (!dwarf_strict || dwarf_version >= 5))
24600 : {
24601 : struct call_arg_loc_node *ca_loc;
24602 3611949 : for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
24603 : {
24604 3169698 : dw_die_ref die = NULL;
24605 3169698 : rtx tloc = NULL_RTX, tlocc = NULL_RTX;
24606 3169698 : rtx call_arg_loc_note
24607 3169698 : = find_reg_note (ca_loc->call_insn,
24608 : REG_CALL_ARG_LOCATION, NULL_RTX);
24609 3169698 : rtx arg, next_arg;
24610 3169698 : tree arg_decl = NULL_TREE;
24611 :
24612 3133935 : for (arg = (call_arg_loc_note != NULL_RTX
24613 3169698 : ? XEXP (call_arg_loc_note, 0)
24614 : : NULL_RTX);
24615 6189230 : arg; arg = next_arg)
24616 : {
24617 3019532 : dw_loc_descr_ref reg, val;
24618 3019532 : machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
24619 3019532 : dw_die_ref cdie, tdie = NULL;
24620 :
24621 3019532 : next_arg = XEXP (arg, 1);
24622 3019532 : if (REG_P (XEXP (XEXP (arg, 0), 0))
24623 2962931 : && next_arg
24624 1319327 : && MEM_P (XEXP (XEXP (next_arg, 0), 0))
24625 7083 : && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
24626 3026584 : && REGNO (XEXP (XEXP (arg, 0), 0))
24627 7052 : == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
24628 6504 : next_arg = XEXP (next_arg, 1);
24629 3019532 : if (mode == VOIDmode)
24630 : {
24631 544813 : mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
24632 544813 : if (mode == VOIDmode)
24633 1032 : mode = GET_MODE (XEXP (arg, 0));
24634 : }
24635 3019532 : if (mode == VOIDmode || mode == BLKmode)
24636 0 : continue;
24637 : /* Get dynamic information about call target only if we
24638 : have no static information: we cannot generate both
24639 : DW_AT_call_origin and DW_AT_call_target
24640 : attributes. */
24641 3019532 : if (ca_loc->symbol_ref == NULL_RTX)
24642 : {
24643 120427 : if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
24644 : {
24645 5081 : tloc = XEXP (XEXP (arg, 0), 1);
24646 5081 : continue;
24647 : }
24648 115346 : else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
24649 0 : && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
24650 : {
24651 0 : tlocc = XEXP (XEXP (arg, 0), 1);
24652 0 : continue;
24653 : }
24654 : }
24655 3014451 : reg = NULL;
24656 3014451 : if (REG_P (XEXP (XEXP (arg, 0), 0)))
24657 2962931 : reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
24658 : VAR_INIT_STATUS_INITIALIZED);
24659 51520 : else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
24660 : {
24661 1949 : rtx mem = XEXP (XEXP (arg, 0), 0);
24662 1949 : reg = mem_loc_descriptor (XEXP (mem, 0),
24663 1949 : get_address_mode (mem),
24664 1949 : GET_MODE (mem),
24665 : VAR_INIT_STATUS_INITIALIZED);
24666 : }
24667 49571 : else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
24668 : == DEBUG_PARAMETER_REF)
24669 : {
24670 49571 : tree tdecl
24671 : = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
24672 49571 : tdie = lookup_decl_die (tdecl);
24673 49571 : if (tdie == NULL)
24674 0 : continue;
24675 : arg_decl = tdecl;
24676 : }
24677 : else
24678 0 : continue;
24679 2964880 : if (reg == NULL
24680 49571 : && GET_CODE (XEXP (XEXP (arg, 0), 0))
24681 : != DEBUG_PARAMETER_REF)
24682 0 : continue;
24683 3014451 : val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
24684 : VOIDmode,
24685 : VAR_INIT_STATUS_INITIALIZED);
24686 3014451 : if (val == NULL)
24687 80136 : continue;
24688 2934315 : if (die == NULL)
24689 1660949 : die = gen_call_site_die (decl, subr_die, ca_loc);
24690 2935806 : cdie = new_die (dwarf_TAG (DW_TAG_call_site_parameter), die,
24691 : NULL_TREE);
24692 2934315 : add_desc_attribute (cdie, arg_decl);
24693 2934315 : if (reg != NULL)
24694 2902209 : add_AT_loc (cdie, DW_AT_location, reg);
24695 32106 : else if (tdie != NULL)
24696 32112 : add_AT_die_ref (cdie, dwarf_AT (DW_AT_call_parameter),
24697 : tdie);
24698 2935806 : add_AT_loc (cdie, dwarf_AT (DW_AT_call_value), val);
24699 2934315 : if (next_arg != XEXP (arg, 1))
24700 : {
24701 6504 : mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
24702 6504 : if (mode == VOIDmode)
24703 5384 : mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
24704 6504 : val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
24705 : 0), 1),
24706 : mode, VOIDmode,
24707 : VAR_INIT_STATUS_INITIALIZED);
24708 6504 : if (val != NULL)
24709 6504 : add_AT_loc (cdie, dwarf_AT (DW_AT_call_data_value),
24710 : val);
24711 : }
24712 : }
24713 3169698 : if (die == NULL
24714 1508749 : && (ca_loc->symbol_ref || tloc))
24715 1181925 : die = gen_call_site_die (decl, subr_die, ca_loc);
24716 3169698 : if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
24717 : {
24718 5081 : dw_loc_descr_ref tval = NULL;
24719 :
24720 5081 : if (tloc != NULL_RTX)
24721 5081 : tval = mem_loc_descriptor (tloc,
24722 5081 : GET_MODE (tloc) == VOIDmode
24723 1032 : ? Pmode : GET_MODE (tloc),
24724 : VOIDmode,
24725 : VAR_INIT_STATUS_INITIALIZED);
24726 5081 : if (tval)
24727 5089 : add_AT_loc (die, dwarf_AT (DW_AT_call_target), tval);
24728 4 : else if (tlocc != NULL_RTX)
24729 : {
24730 0 : tval = mem_loc_descriptor (tlocc,
24731 0 : GET_MODE (tlocc) == VOIDmode
24732 0 : ? Pmode : GET_MODE (tlocc),
24733 : VOIDmode,
24734 : VAR_INIT_STATUS_INITIALIZED);
24735 0 : if (tval)
24736 0 : add_AT_loc (die,
24737 : dwarf_AT (DW_AT_call_target_clobbered),
24738 : tval);
24739 : }
24740 : }
24741 2842874 : if (die != NULL)
24742 : {
24743 2842874 : call_site_note_count++;
24744 2842874 : if (ca_loc->tail_call_p)
24745 54637 : tail_call_site_note_count++;
24746 : }
24747 : }
24748 : }
24749 2669989 : call_arg_locations = NULL;
24750 2669989 : call_arg_loc_last = NULL;
24751 2669989 : if (tail_call_site_count >= 0
24752 560209 : && tail_call_site_count == tail_call_site_note_count
24753 556736 : && (!dwarf_strict || dwarf_version >= 5))
24754 : {
24755 556720 : if (call_site_count >= 0
24756 556720 : && call_site_count == call_site_note_count)
24757 257597 : add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_calls), 1);
24758 : else
24759 302475 : add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_tail_calls), 1);
24760 : }
24761 2669989 : call_site_count = -1;
24762 2669989 : tail_call_site_count = -1;
24763 : }
24764 :
24765 : /* Mark used types after we have created DIEs for the functions scopes. */
24766 98381538 : premark_used_types (DECL_STRUCT_FUNCTION (decl));
24767 : }
24768 :
24769 : /* Returns a hash value for X (which really is a die_struct). */
24770 :
24771 : hashval_t
24772 2750 : block_die_hasher::hash (die_struct *d)
24773 : {
24774 2750 : return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
24775 : }
24776 :
24777 : /* Return true if decl_id and die_parent of die_struct X is the same
24778 : as decl_id and die_parent of die_struct Y. */
24779 :
24780 : bool
24781 2146 : block_die_hasher::equal (die_struct *x, die_struct *y)
24782 : {
24783 2146 : return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
24784 : }
24785 :
24786 : /* Hold information about markers for inlined entry points. */
24787 : struct GTY ((for_user)) inline_entry_data
24788 : {
24789 : /* The block that's the inlined_function_outer_scope for an inlined
24790 : function. */
24791 : tree block;
24792 :
24793 : /* The label at the inlined entry point. */
24794 : const char *label_pfx;
24795 : unsigned int label_num;
24796 :
24797 : /* The view number to be used as the inlined entry point. */
24798 : var_loc_view view;
24799 : };
24800 :
24801 : struct inline_entry_data_hasher : ggc_ptr_hash <inline_entry_data>
24802 : {
24803 : typedef tree compare_type;
24804 : static inline hashval_t hash (const inline_entry_data *);
24805 : static inline bool equal (const inline_entry_data *, const_tree);
24806 : };
24807 :
24808 : /* Hash table routines for inline_entry_data. */
24809 :
24810 : inline hashval_t
24811 36538397 : inline_entry_data_hasher::hash (const inline_entry_data *data)
24812 : {
24813 36538397 : return htab_hash_pointer (data->block);
24814 : }
24815 :
24816 : inline bool
24817 44309048 : inline_entry_data_hasher::equal (const inline_entry_data *data,
24818 : const_tree block)
24819 : {
24820 44309048 : return data->block == block;
24821 : }
24822 :
24823 : /* Inlined entry points pending DIE creation in this compilation unit. */
24824 :
24825 : static GTY(()) hash_table<inline_entry_data_hasher> *inline_entry_data_table;
24826 :
24827 :
24828 : /* Return TRUE if DECL, which may have been previously generated as
24829 : OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
24830 : true if decl (or its origin) is either an extern declaration or a
24831 : class/namespace scoped declaration.
24832 :
24833 : The declare_in_namespace support causes us to get two DIEs for one
24834 : variable, both of which are declarations. We want to avoid
24835 : considering one to be a specification, so we must test for
24836 : DECLARATION and DW_AT_declaration. */
24837 : static inline bool
24838 93579622 : decl_will_get_specification_p (dw_die_ref old_die, tree decl, bool declaration)
24839 : {
24840 60725726 : return (old_die && TREE_STATIC (decl) && !declaration
24841 153079549 : && get_AT_flag (old_die, DW_AT_declaration) == 1);
24842 : }
24843 :
24844 : /* Return true if DECL is a local static. */
24845 :
24846 : static inline bool
24847 32341021 : local_function_static (tree decl)
24848 : {
24849 32341021 : gcc_assert (VAR_P (decl));
24850 32341021 : return TREE_STATIC (decl)
24851 31743919 : && DECL_CONTEXT (decl)
24852 63884831 : && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
24853 : }
24854 :
24855 : /* Return true iff DECL overrides (presumably completes) the type of
24856 : OLD_DIE within CONTEXT_DIE. */
24857 :
24858 : static bool
24859 28853467 : override_type_for_decl_p (tree decl, dw_die_ref old_die,
24860 : dw_die_ref context_die)
24861 : {
24862 28853467 : tree type = TREE_TYPE (decl);
24863 28853467 : int cv_quals;
24864 :
24865 28853467 : if (decl_by_reference_p (decl))
24866 : {
24867 0 : type = TREE_TYPE (type);
24868 0 : cv_quals = TYPE_UNQUALIFIED;
24869 : }
24870 : else
24871 28853467 : cv_quals = decl_quals (decl);
24872 :
24873 28853467 : dw_die_ref type_die
24874 86560401 : = modified_type_die (type,
24875 28853467 : cv_quals | TYPE_QUALS (type),
24876 28853467 : TYPE_ATTRIBUTES (type),
24877 : false,
24878 : context_die);
24879 :
24880 28853467 : dw_die_ref old_type_die = get_AT_ref (old_die, DW_AT_type);
24881 :
24882 28853467 : return type_die != old_type_die;
24883 : }
24884 :
24885 : /* Generate a DIE to represent a declared data object.
24886 : Either DECL or ORIGIN must be non-null. */
24887 :
24888 : static void
24889 66451819 : gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
24890 : {
24891 66451819 : HOST_WIDE_INT off = 0;
24892 66451819 : tree com_decl;
24893 66451819 : tree decl_or_origin = decl ? decl : origin;
24894 66451804 : tree ultimate_origin;
24895 66451804 : dw_die_ref var_die;
24896 66451804 : dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
24897 66451819 : bool declaration = (DECL_EXTERNAL (decl_or_origin)
24898 66451819 : || class_or_namespace_scope_p (context_die));
24899 66451819 : bool specialization_p = false;
24900 66451819 : bool no_linkage_name = false;
24901 :
24902 : /* While C++ inline static data members have definitions inside of the
24903 : class, force the first DIE to be a declaration, then let gen_member_die
24904 : reparent it to the class context and call gen_variable_die again
24905 : to create the outside of the class DIE for the definition. */
24906 66451819 : if (!declaration
24907 66451819 : && old_die == NULL
24908 11084337 : && decl
24909 11084337 : && DECL_CONTEXT (decl)
24910 10886983 : && TYPE_P (DECL_CONTEXT (decl))
24911 74085978 : && lang_hooks.decls.decl_dwarf_attribute (decl, DW_AT_inline) != -1)
24912 : {
24913 7634156 : declaration = true;
24914 7634156 : if (dwarf_version < 5)
24915 32 : no_linkage_name = true;
24916 : }
24917 :
24918 66451819 : ultimate_origin = decl_ultimate_origin (decl_or_origin);
24919 66451819 : if (decl || ultimate_origin)
24920 66451804 : origin = ultimate_origin;
24921 66451819 : com_decl = fortran_common (decl_or_origin, &off);
24922 :
24923 : /* Symbol in common gets emitted as a child of the common block, in the form
24924 : of a data member. */
24925 66451819 : if (com_decl)
24926 : {
24927 1061 : dw_die_ref com_die;
24928 1061 : dw_loc_list_ref loc = NULL;
24929 1061 : die_node com_die_arg;
24930 :
24931 1061 : var_die = lookup_decl_die (decl_or_origin);
24932 1061 : if (var_die)
24933 : {
24934 357 : if (! early_dwarf && get_AT (var_die, DW_AT_location) == NULL)
24935 : {
24936 418 : loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
24937 349 : if (loc)
24938 : {
24939 349 : if (off)
24940 : {
24941 : /* Optimize the common case. */
24942 280 : if (single_element_loc_list_p (loc)
24943 280 : && loc->expr->dw_loc_opc == DW_OP_addr
24944 280 : && loc->expr->dw_loc_next == NULL
24945 560 : && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
24946 : == SYMBOL_REF)
24947 : {
24948 280 : rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
24949 280 : loc->expr->dw_loc_oprnd1.v.val_addr
24950 280 : = plus_constant (GET_MODE (x), x , off);
24951 : }
24952 : else
24953 0 : loc_list_plus_const (loc, off);
24954 : }
24955 349 : add_AT_location_description (var_die, DW_AT_location, loc);
24956 349 : remove_AT (var_die, DW_AT_declaration);
24957 : }
24958 : }
24959 357 : return;
24960 : }
24961 :
24962 704 : if (common_block_die_table == NULL)
24963 99 : common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
24964 :
24965 704 : com_die_arg.decl_id = DECL_UID (com_decl);
24966 704 : com_die_arg.die_parent = context_die;
24967 704 : com_die = common_block_die_table->find (&com_die_arg);
24968 704 : if (! early_dwarf)
24969 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24970 704 : if (com_die == NULL)
24971 : {
24972 247 : const char *cnam
24973 247 : = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
24974 247 : die_node **slot;
24975 :
24976 247 : com_die = new_die (DW_TAG_common_block, context_die, decl);
24977 247 : add_name_and_src_coords_attributes (com_die, com_decl);
24978 247 : if (loc)
24979 : {
24980 0 : add_AT_location_description (com_die, DW_AT_location, loc);
24981 : /* Avoid sharing the same loc descriptor between
24982 : DW_TAG_common_block and DW_TAG_variable. */
24983 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24984 : }
24985 247 : else if (DECL_EXTERNAL (decl_or_origin))
24986 7 : add_AT_flag (com_die, DW_AT_declaration, 1);
24987 247 : if (want_pubnames ())
24988 0 : add_pubname_string (cnam, com_die); /* ??? needed? */
24989 247 : com_die->decl_id = DECL_UID (com_decl);
24990 247 : slot = common_block_die_table->find_slot (com_die, INSERT);
24991 247 : *slot = com_die;
24992 : }
24993 457 : else if (get_AT (com_die, DW_AT_location) == NULL && loc)
24994 : {
24995 0 : add_AT_location_description (com_die, DW_AT_location, loc);
24996 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24997 0 : remove_AT (com_die, DW_AT_declaration);
24998 : }
24999 704 : var_die = new_die (DW_TAG_variable, com_die, decl);
25000 704 : add_name_and_src_coords_attributes (var_die, decl_or_origin);
25001 704 : add_type_attribute (var_die, TREE_TYPE (decl_or_origin),
25002 : decl_quals (decl_or_origin), false,
25003 : context_die);
25004 704 : add_alignment_attribute (var_die, decl);
25005 704 : add_AT_flag (var_die, DW_AT_external, 1);
25006 704 : if (loc)
25007 : {
25008 0 : if (off)
25009 : {
25010 : /* Optimize the common case. */
25011 0 : if (single_element_loc_list_p (loc)
25012 0 : && loc->expr->dw_loc_opc == DW_OP_addr
25013 0 : && loc->expr->dw_loc_next == NULL
25014 0 : && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
25015 : {
25016 0 : rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
25017 0 : loc->expr->dw_loc_oprnd1.v.val_addr
25018 0 : = plus_constant (GET_MODE (x), x, off);
25019 : }
25020 : else
25021 0 : loc_list_plus_const (loc, off);
25022 : }
25023 0 : add_AT_location_description (var_die, DW_AT_location, loc);
25024 : }
25025 704 : else if (DECL_EXTERNAL (decl_or_origin))
25026 8 : add_AT_flag (var_die, DW_AT_declaration, 1);
25027 704 : if (decl)
25028 704 : equate_decl_number_to_die (decl, var_die);
25029 704 : return;
25030 : }
25031 :
25032 66450758 : if (old_die)
25033 : {
25034 32177733 : if (declaration)
25035 : {
25036 : /* A declaration that has been previously dumped, needs no
25037 : further annotations, since it doesn't need location on
25038 : the second pass. */
25039 : return;
25040 : }
25041 31872259 : else if (decl_will_get_specification_p (old_die, decl, declaration)
25042 31872259 : && !get_AT (old_die, DW_AT_specification))
25043 : {
25044 : /* Fall-thru so we can make a new variable die along with a
25045 : DW_AT_specification. */
25046 : }
25047 3018792 : else if (origin && old_die->die_parent != context_die)
25048 : {
25049 : /* If we will be creating an inlined instance, we need a
25050 : new DIE that will get annotated with
25051 : DW_AT_abstract_origin. */
25052 58874 : gcc_assert (!DECL_ABSTRACT_P (decl));
25053 : }
25054 : else
25055 : {
25056 : /* If a DIE was dumped early, it still needs location info.
25057 : Skip to where we fill the location bits. */
25058 2959918 : var_die = old_die;
25059 :
25060 : /* ??? In LTRANS we cannot annotate early created variably
25061 : modified type DIEs without copying them and adjusting all
25062 : references to them. Thus we dumped them again. Also add a
25063 : reference to them but beware of -g0 compile and -g link
25064 : in which case the reference will be already present. */
25065 2959918 : tree type = TREE_TYPE (decl_or_origin);
25066 2959918 : if (in_lto_p
25067 2899 : && ! get_AT (var_die, DW_AT_type)
25068 2962817 : && variably_modified_type_p
25069 2899 : (type, decl_function_context (decl_or_origin)))
25070 : {
25071 45 : if (decl_by_reference_p (decl_or_origin))
25072 4 : add_type_attribute (var_die, TREE_TYPE (type),
25073 : TYPE_UNQUALIFIED, false, context_die);
25074 : else
25075 41 : add_type_attribute (var_die, type, decl_quals (decl_or_origin),
25076 : false, context_die);
25077 : }
25078 :
25079 2959918 : goto gen_variable_die_location;
25080 : }
25081 : }
25082 :
25083 : /* For static data members, the declaration in the class is supposed
25084 : to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
25085 : also in DWARF2; the specification should still be DW_TAG_variable
25086 : referencing the DW_TAG_member DIE. */
25087 63185366 : if (declaration && class_scope_p (context_die) && dwarf_version < 5)
25088 120 : var_die = new_die (DW_TAG_member, context_die, decl);
25089 : else
25090 63185246 : var_die = new_die (DW_TAG_variable, context_die, decl);
25091 :
25092 63185366 : if (origin != NULL)
25093 1478003 : add_abstract_origin_attribute (var_die, origin);
25094 :
25095 : /* Loop unrolling can create multiple blocks that refer to the same
25096 : static variable, so we must test for the DW_AT_declaration flag.
25097 :
25098 : ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
25099 : copy decls and set the DECL_ABSTRACT_P flag on them instead of
25100 : sharing them.
25101 :
25102 : ??? Duplicated blocks have been rewritten to use .debug_ranges. */
25103 61707363 : else if (decl_will_get_specification_p (old_die, decl, declaration))
25104 : {
25105 : /* This is a definition of a C++ class level static. */
25106 28853467 : add_AT_specification (var_die, old_die);
25107 28853467 : specialization_p = true;
25108 28853467 : if (DECL_NAME (decl))
25109 : {
25110 28853448 : expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
25111 28853448 : struct dwarf_file_data * file_index = lookup_filename (s.file);
25112 :
25113 28853448 : if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
25114 4353 : add_AT_file (var_die, DW_AT_decl_file, file_index);
25115 :
25116 28853448 : if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
25117 131256 : add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
25118 :
25119 28853448 : if (debug_column_info
25120 28853448 : && s.column
25121 57706896 : && (get_AT_unsigned (old_die, DW_AT_decl_column)
25122 28853448 : != (unsigned) s.column))
25123 131194 : add_AT_unsigned (var_die, DW_AT_decl_column, s.column);
25124 :
25125 28853448 : if (old_die->die_tag == DW_TAG_member)
25126 70 : add_linkage_name (var_die, decl);
25127 : }
25128 : }
25129 : else
25130 32853896 : add_name_and_src_coords_attributes (var_die, decl, no_linkage_name);
25131 :
25132 63185366 : if ((origin == NULL && !specialization_p)
25133 30331470 : || (origin != NULL
25134 1478003 : && !DECL_ABSTRACT_P (decl_or_origin)
25135 1478003 : && variably_modified_type_p (TREE_TYPE (decl_or_origin),
25136 : decl_function_context
25137 : (decl_or_origin)))
25138 93513817 : || (old_die && specialization_p
25139 28853467 : && override_type_for_decl_p (decl_or_origin, old_die, context_die)))
25140 : {
25141 32857165 : tree type = TREE_TYPE (decl_or_origin);
25142 :
25143 32857165 : if (decl_by_reference_p (decl_or_origin))
25144 1523 : add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
25145 : context_die);
25146 : else
25147 32855642 : add_type_attribute (var_die, type, decl_quals (decl_or_origin), false,
25148 : context_die);
25149 : }
25150 :
25151 63185366 : if (origin == NULL && !specialization_p)
25152 : {
25153 32853896 : if (TREE_PUBLIC (decl))
25154 30949289 : add_AT_flag (var_die, DW_AT_external, 1);
25155 :
25156 32853896 : if (DECL_ARTIFICIAL (decl))
25157 138940 : add_AT_flag (var_die, DW_AT_artificial, 1);
25158 :
25159 32853896 : add_alignment_attribute (var_die, decl);
25160 :
25161 32853896 : add_accessibility_attribute (var_die, decl);
25162 : }
25163 :
25164 63185366 : if (declaration)
25165 30823540 : add_AT_flag (var_die, DW_AT_declaration, 1);
25166 :
25167 63185366 : if (decl && (DECL_ABSTRACT_P (decl)
25168 63185351 : || !old_die || is_declaration_die (old_die)))
25169 63126477 : equate_decl_number_to_die (decl, var_die);
25170 :
25171 66145284 : gen_variable_die_location:
25172 66145284 : if (! declaration
25173 66145284 : && (! DECL_ABSTRACT_P (decl_or_origin)
25174 : /* Local static vars are shared between all clones/inlines,
25175 : so emit DW_AT_location on the abstract DIE if DECL_RTL is
25176 : already set. */
25177 0 : || (VAR_P (decl_or_origin)
25178 0 : && TREE_STATIC (decl_or_origin)
25179 0 : && DECL_RTL_SET_P (decl_or_origin))))
25180 : {
25181 35321744 : if (early_dwarf)
25182 : {
25183 32663496 : add_pubname (decl_or_origin, var_die);
25184 : /* For global register variables, emit DW_AT_location if possible
25185 : already during early_dwarf, as late_global_decl won't be usually
25186 : called. */
25187 32663496 : if (DECL_HARD_REGISTER (decl_or_origin)
25188 76 : && TREE_STATIC (decl_or_origin)
25189 12 : && !decl_by_reference_p (decl_or_origin)
25190 12 : && !get_AT (var_die, DW_AT_location)
25191 6 : && !get_AT (var_die, DW_AT_const_value)
25192 6 : && DECL_RTL_SET_P (decl_or_origin)
25193 32663502 : && REG_P (DECL_RTL (decl_or_origin)))
25194 : {
25195 6 : dw_loc_descr_ref descr
25196 6 : = reg_loc_descriptor (DECL_RTL (decl_or_origin),
25197 : VAR_INIT_STATUS_INITIALIZED);
25198 6 : if (descr)
25199 6 : add_AT_loc (var_die, DW_AT_location, descr);
25200 : }
25201 : }
25202 : else
25203 2658248 : add_location_or_const_value_attribute (var_die, decl_or_origin,
25204 : decl == NULL);
25205 : }
25206 : else
25207 30823540 : tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
25208 :
25209 9113 : if ((dwarf_version >= 4 || !dwarf_strict)
25210 66145284 : && lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
25211 : DW_AT_const_expr) == 1
25212 58285190 : && !get_AT (var_die, DW_AT_const_expr)
25213 94588721 : && !specialization_p)
25214 28326474 : add_AT_flag (var_die, DW_AT_const_expr, 1);
25215 :
25216 66145284 : if (!dwarf_strict)
25217 : {
25218 66145282 : int inl = lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
25219 : DW_AT_inline);
25220 66145282 : if (inl != -1
25221 56313064 : && !get_AT (var_die, DW_AT_inline)
25222 93604560 : && !specialization_p)
25223 27333256 : add_AT_unsigned (var_die, DW_AT_inline, inl);
25224 : }
25225 : }
25226 :
25227 : /* Generate a DIE to represent a named constant. */
25228 :
25229 : static void
25230 26061 : gen_const_die (tree decl, dw_die_ref context_die)
25231 : {
25232 26061 : dw_die_ref const_die;
25233 26061 : tree type = TREE_TYPE (decl);
25234 :
25235 26061 : const_die = lookup_decl_die (decl);
25236 26061 : if (const_die)
25237 : return;
25238 :
25239 19107 : const_die = new_die (DW_TAG_constant, context_die, decl);
25240 19107 : equate_decl_number_to_die (decl, const_die);
25241 19107 : add_name_and_src_coords_attributes (const_die, decl);
25242 19107 : add_type_attribute (const_die, type, TYPE_QUAL_CONST, false, context_die);
25243 19107 : if (TREE_PUBLIC (decl))
25244 357 : add_AT_flag (const_die, DW_AT_external, 1);
25245 19107 : if (DECL_ARTIFICIAL (decl))
25246 0 : add_AT_flag (const_die, DW_AT_artificial, 1);
25247 19107 : tree_add_const_value_attribute_for_decl (const_die, decl);
25248 : }
25249 :
25250 : /* Generate a DIE to represent a label identifier. */
25251 :
25252 : static void
25253 119025 : gen_label_die (tree decl, dw_die_ref context_die)
25254 : {
25255 119025 : tree origin = decl_ultimate_origin (decl);
25256 119025 : dw_die_ref lbl_die = lookup_decl_die (decl);
25257 119025 : rtx insn;
25258 119025 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
25259 :
25260 119025 : if (!lbl_die)
25261 : {
25262 70266 : lbl_die = new_die (DW_TAG_label, context_die, decl);
25263 70266 : equate_decl_number_to_die (decl, lbl_die);
25264 :
25265 70266 : if (origin != NULL)
25266 15568 : add_abstract_origin_attribute (lbl_die, origin);
25267 : else
25268 54698 : add_name_and_src_coords_attributes (lbl_die, decl);
25269 : }
25270 :
25271 119025 : if (DECL_ABSTRACT_P (decl))
25272 0 : equate_decl_number_to_die (decl, lbl_die);
25273 119025 : else if (! early_dwarf)
25274 : {
25275 64327 : insn = DECL_RTL_IF_SET (decl);
25276 :
25277 : /* Deleted labels are programmer specified labels which have been
25278 : eliminated because of various optimizations. We still emit them
25279 : here so that it is possible to put breakpoints on them. */
25280 54703 : if (insn
25281 54703 : && (LABEL_P (insn)
25282 29240 : || ((NOTE_P (insn)
25283 29240 : && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
25284 : {
25285 : /* When optimization is enabled (via -O) some parts of the compiler
25286 : (e.g. jump.cc and cse.cc) may try to delete CODE_LABEL insns which
25287 : represent source-level labels which were explicitly declared by
25288 : the user. This really shouldn't be happening though, so catch
25289 : it if it ever does happen. */
25290 47911 : gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
25291 :
25292 47911 : ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
25293 47911 : add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
25294 47911 : }
25295 : else if (insn
25296 6792 : && NOTE_P (insn)
25297 6792 : && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
25298 6792 : && CODE_LABEL_NUMBER (insn) != -1)
25299 : {
25300 6792 : ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
25301 6792 : add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
25302 : }
25303 : }
25304 119025 : }
25305 :
25306 : /* A helper function for gen_inlined_subroutine_die. Add source coordinate
25307 : attributes to the DIE for a block STMT, to describe where the inlined
25308 : function was called from. This is similar to add_src_coords_attributes. */
25309 :
25310 : static inline void
25311 6439837 : add_call_src_coords_attributes (tree stmt, dw_die_ref die)
25312 : {
25313 : /* We can end up with BUILTINS_LOCATION here. */
25314 6439837 : if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt)))
25315 61 : return;
25316 :
25317 6439776 : location_t locus = BLOCK_SOURCE_LOCATION (stmt);
25318 6439776 : expanded_location s = expand_location (locus);
25319 :
25320 6439776 : if (dwarf_version >= 3 || !dwarf_strict)
25321 : {
25322 6439776 : add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
25323 6439776 : add_AT_unsigned (die, DW_AT_call_line, s.line);
25324 6439776 : if (debug_column_info && s.column)
25325 6431723 : add_AT_unsigned (die, DW_AT_call_column, s.column);
25326 6439776 : unsigned discr = get_discriminator_from_loc (locus);
25327 6439776 : if (discr != 0)
25328 2011500 : add_AT_unsigned (die, DW_AT_GNU_discriminator, discr);
25329 : }
25330 : }
25331 :
25332 :
25333 : /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
25334 : Add low_pc and high_pc attributes to the DIE for a block STMT. */
25335 :
25336 : static inline void
25337 7017979 : add_high_low_attributes (tree stmt, dw_die_ref die)
25338 : {
25339 7017979 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
25340 :
25341 6611916 : if (inline_entry_data **iedp
25342 7017979 : = !inline_entry_data_table ? NULL
25343 6611916 : : inline_entry_data_table->find_slot_with_hash (stmt,
25344 : htab_hash_pointer (stmt),
25345 : NO_INSERT))
25346 : {
25347 6212119 : inline_entry_data *ied = *iedp;
25348 6212119 : gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS);
25349 6212119 : gcc_assert (debug_inline_points);
25350 6212119 : gcc_assert (inlined_function_outer_scope_p (stmt));
25351 :
25352 6212119 : ASM_GENERATE_INTERNAL_LABEL (label, ied->label_pfx, ied->label_num);
25353 6212119 : add_AT_lbl_id (die, DW_AT_entry_pc, label);
25354 :
25355 6212119 : if (debug_variable_location_views && !ZERO_VIEW_P (ied->view)
25356 12423985 : && !dwarf_strict)
25357 : {
25358 6211866 : if (!output_asm_line_debug_info ())
25359 434 : add_AT_unsigned (die, DW_AT_GNU_entry_view, ied->view);
25360 : else
25361 : {
25362 6211432 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", ied->view);
25363 : /* FIXME: this will resolve to a small number. Could we
25364 : possibly emit smaller data? Ideally we'd emit a
25365 : uleb128, but that would make the size of DIEs
25366 : impossible for the compiler to compute, since it's
25367 : the assembler that computes the value of the view
25368 : label in this case. Ideally, we'd have a single form
25369 : encompassing both the address and the view, and
25370 : indirecting them through a table might make things
25371 : easier, but even that would be more wasteful,
25372 : space-wise, than what we have now. */
25373 6211432 : add_AT_symview (die, DW_AT_GNU_entry_view, label);
25374 : }
25375 : }
25376 :
25377 6212119 : inline_entry_data_table->clear_slot (iedp);
25378 : }
25379 :
25380 7017979 : if (BLOCK_FRAGMENT_CHAIN (stmt)
25381 7017979 : && (dwarf_version >= 3 || !dwarf_strict))
25382 : {
25383 3163524 : tree chain, superblock = NULL_TREE;
25384 3163524 : dw_die_ref pdie;
25385 3163524 : dw_attr_node *attr = NULL;
25386 :
25387 3163524 : if (!debug_inline_points && inlined_function_outer_scope_p (stmt))
25388 : {
25389 106 : ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
25390 : BLOCK_NUMBER (stmt));
25391 106 : add_AT_lbl_id (die, DW_AT_entry_pc, label);
25392 : }
25393 :
25394 : /* Optimize duplicate .debug_ranges lists or even tails of
25395 : lists. If this BLOCK has same ranges as its supercontext,
25396 : lookup DW_AT_ranges attribute in the supercontext (and
25397 : recursively so), verify that the ranges_table contains the
25398 : right values and use it instead of adding a new .debug_range. */
25399 1935025 : for (chain = stmt, pdie = die;
25400 5098549 : BLOCK_SAME_RANGE (chain);
25401 1935025 : chain = BLOCK_SUPERCONTEXT (chain))
25402 : {
25403 2026589 : dw_attr_node *new_attr;
25404 :
25405 2026589 : pdie = pdie->die_parent;
25406 2026589 : if (pdie == NULL)
25407 : break;
25408 2026589 : if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
25409 : break;
25410 2026589 : new_attr = get_AT (pdie, DW_AT_ranges);
25411 2026589 : if (new_attr == NULL
25412 1935025 : || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
25413 : break;
25414 1935025 : attr = new_attr;
25415 1935025 : superblock = BLOCK_SUPERCONTEXT (chain);
25416 : }
25417 3163524 : if (attr != NULL
25418 912085 : && ((*ranges_table)[attr->dw_attr_val.v.val_offset].num
25419 912085 : == (int)BLOCK_NUMBER (superblock))
25420 3696017 : && BLOCK_FRAGMENT_CHAIN (superblock))
25421 : {
25422 : unsigned long off = attr->dw_attr_val.v.val_offset;
25423 1542994 : unsigned long supercnt = 0, thiscnt = 0;
25424 1010501 : for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
25425 1542994 : chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
25426 : {
25427 1010501 : ++supercnt;
25428 1010501 : gcc_checking_assert ((*ranges_table)[off + supercnt].num
25429 : == (int)BLOCK_NUMBER (chain));
25430 : }
25431 532493 : gcc_checking_assert ((*ranges_table)[off + supercnt + 1].num == 0);
25432 532493 : for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
25433 1523617 : chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
25434 991124 : ++thiscnt;
25435 532493 : gcc_assert (supercnt >= thiscnt);
25436 532493 : add_AT_range_list (die, DW_AT_ranges, off + supercnt - thiscnt,
25437 : false);
25438 532493 : note_rnglist_head (off + supercnt - thiscnt);
25439 532493 : return;
25440 : }
25441 :
25442 2631031 : unsigned int offset = add_ranges (stmt, true);
25443 2631031 : add_AT_range_list (die, DW_AT_ranges, offset, false);
25444 2631031 : note_rnglist_head (offset);
25445 :
25446 2631031 : bool prev_in_cold = BLOCK_IN_COLD_SECTION_P (stmt);
25447 2631031 : chain = BLOCK_FRAGMENT_CHAIN (stmt);
25448 5265342 : do
25449 : {
25450 5265342 : add_ranges (chain, prev_in_cold != BLOCK_IN_COLD_SECTION_P (chain));
25451 5265342 : prev_in_cold = BLOCK_IN_COLD_SECTION_P (chain);
25452 5265342 : chain = BLOCK_FRAGMENT_CHAIN (chain);
25453 : }
25454 5265342 : while (chain);
25455 2631031 : add_ranges (NULL);
25456 : }
25457 : else
25458 : {
25459 3854455 : char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
25460 3854455 : ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
25461 : BLOCK_NUMBER (stmt));
25462 3854455 : ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
25463 : BLOCK_NUMBER (stmt));
25464 3854455 : add_AT_low_high_pc (die, label, label_high, false);
25465 : }
25466 : }
25467 :
25468 : /* Generate a DIE for a lexical block. */
25469 :
25470 : static void
25471 1004916 : gen_lexical_block_die (tree stmt, dw_die_ref context_die)
25472 : {
25473 1004916 : dw_die_ref old_die = lookup_block_die (stmt);
25474 1004916 : dw_die_ref stmt_die = NULL;
25475 1004916 : if (!old_die)
25476 : {
25477 744774 : stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
25478 744774 : equate_block_to_die (stmt, stmt_die);
25479 : }
25480 :
25481 1004916 : if (BLOCK_ABSTRACT_ORIGIN (stmt))
25482 : {
25483 : /* If this is an inlined or concrete instance, create a new lexical
25484 : die for anything below to attach DW_AT_abstract_origin to. */
25485 344801 : if (old_die)
25486 10344 : stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
25487 :
25488 344801 : tree origin = block_ultimate_origin (stmt);
25489 344801 : if (origin != NULL_TREE && (origin != stmt || old_die))
25490 344073 : add_abstract_origin_attribute (stmt_die, origin);
25491 :
25492 : old_die = NULL;
25493 : }
25494 :
25495 660115 : if (old_die)
25496 249798 : stmt_die = old_die;
25497 :
25498 : /* A non abstract block whose blocks have already been reordered
25499 : should have the instruction range for this block. If so, set the
25500 : high/low attributes. */
25501 1004916 : if (!early_dwarf && TREE_ASM_WRITTEN (stmt))
25502 : {
25503 578142 : gcc_assert (stmt_die);
25504 578142 : add_high_low_attributes (stmt, stmt_die);
25505 : }
25506 :
25507 1004916 : decls_for_scope (stmt, stmt_die);
25508 1004916 : }
25509 :
25510 : /* Generate a DIE for an inlined subprogram. */
25511 :
25512 : static void
25513 6439837 : gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
25514 : {
25515 6439837 : tree decl = block_ultimate_origin (stmt);
25516 :
25517 : /* Make sure any inlined functions are known to be inlineable. */
25518 6439837 : gcc_checking_assert (DECL_ABSTRACT_P (decl)
25519 : || cgraph_function_possibly_inlined_p (decl));
25520 :
25521 6439837 : dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
25522 :
25523 6439837 : if (call_arg_locations || debug_inline_points)
25524 6431908 : equate_block_to_die (stmt, subr_die);
25525 6439837 : add_abstract_origin_attribute (subr_die, decl);
25526 6439837 : if (TREE_ASM_WRITTEN (stmt))
25527 6439837 : add_high_low_attributes (stmt, subr_die);
25528 6439837 : add_call_src_coords_attributes (stmt, subr_die);
25529 :
25530 : /* The inliner creates an extra BLOCK for the parameter setup,
25531 : we want to merge that with the actual outermost BLOCK of the
25532 : inlined function to avoid duplicate locals in consumers.
25533 : Do that by doing the recursion to subblocks on the single subblock
25534 : of STMT. */
25535 6439837 : bool unwrap_one = false;
25536 6439837 : tree sub = BLOCK_SUBBLOCKS (stmt);
25537 6439837 : if (sub)
25538 : {
25539 5104597 : tree origin = block_ultimate_origin (sub);
25540 5104597 : if (origin
25541 5104597 : && TREE_CODE (origin) == BLOCK
25542 8322509 : && BLOCK_SUPERCONTEXT (origin) == decl)
25543 : unwrap_one = true;
25544 8258434 : for (tree next = BLOCK_CHAIN (sub); unwrap_one && next;
25545 3153837 : next = BLOCK_CHAIN (next))
25546 3153837 : if (BLOCK_FRAGMENT_ORIGIN (next) != sub)
25547 5935 : unwrap_one = false;
25548 : }
25549 6439837 : decls_for_scope (stmt, subr_die, !unwrap_one);
25550 6439837 : if (unwrap_one)
25551 : {
25552 3114833 : decls_for_scope (sub, subr_die);
25553 6258981 : for (sub = BLOCK_CHAIN (sub); sub; sub = BLOCK_CHAIN (sub))
25554 3144148 : gen_block_die (sub, subr_die);
25555 : }
25556 6439837 : }
25557 :
25558 : /* Generate a DIE for a field in a record, or structure. CTX is required: see
25559 : the comment for VLR_CONTEXT. */
25560 :
25561 : static void
25562 16925365 : gen_field_die (tree decl, struct vlr_context *ctx, dw_die_ref context_die)
25563 : {
25564 16925365 : dw_die_ref decl_die;
25565 :
25566 16925365 : if (TREE_TYPE (decl) == error_mark_node)
25567 : return;
25568 :
25569 16925365 : decl_die = new_die (DW_TAG_member, context_die, decl);
25570 16925365 : add_name_and_src_coords_attributes (decl_die, decl);
25571 33850730 : add_type_attribute (decl_die, member_declared_type (decl), decl_quals (decl),
25572 16925365 : TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl)),
25573 : context_die);
25574 :
25575 16925365 : if (DECL_BIT_FIELD_TYPE (decl))
25576 : {
25577 487702 : add_byte_size_attribute (decl_die, decl);
25578 487702 : add_bit_size_attribute (decl_die, decl);
25579 487702 : add_bit_offset_attribute (decl_die, decl);
25580 : }
25581 :
25582 16925365 : add_alignment_attribute (decl_die, decl);
25583 :
25584 16925365 : if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
25585 15501711 : add_data_member_location_attribute (decl_die, decl, ctx);
25586 :
25587 16925365 : if (DECL_ARTIFICIAL (decl))
25588 70701 : add_AT_flag (decl_die, DW_AT_artificial, 1);
25589 :
25590 16925365 : add_accessibility_attribute (decl_die, decl);
25591 :
25592 : /* Add DW_AT_export_symbols to anonymous unions or structs. */
25593 16925365 : if ((dwarf_version >= 5 || !dwarf_strict) && DECL_NAME (decl) == NULL_TREE)
25594 191863 : if (tree type = member_declared_type (decl))
25595 191863 : if (lang_hooks.types.type_dwarf_attribute (TYPE_MAIN_VARIANT (type),
25596 : DW_AT_export_symbols) != -1)
25597 : {
25598 191763 : dw_die_ref type_die = lookup_type_die (TYPE_MAIN_VARIANT (type));
25599 191763 : if (type_die && get_AT (type_die, DW_AT_export_symbols) == NULL)
25600 191763 : add_AT_flag (type_die, DW_AT_export_symbols, 1);
25601 : }
25602 :
25603 : /* Equate decl number to die, so that we can look up this decl later on. */
25604 16925365 : equate_decl_number_to_die (decl, decl_die);
25605 : }
25606 :
25607 : /* Generate a DIE for a pointer to a member type. TYPE can be an
25608 : OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
25609 : pointer to member function. */
25610 :
25611 : static void
25612 29452 : gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
25613 : {
25614 29452 : if (lookup_type_die (type))
25615 : return;
25616 :
25617 29452 : dw_die_ref ptr_die = new_die (DW_TAG_ptr_to_member_type,
25618 : scope_die_for (type, context_die), type);
25619 :
25620 29452 : equate_type_number_to_die (type, ptr_die);
25621 58904 : add_AT_die_ref (ptr_die, DW_AT_containing_type,
25622 29452 : lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
25623 29452 : add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
25624 : context_die);
25625 29452 : add_alignment_attribute (ptr_die, type);
25626 :
25627 29452 : if (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
25628 29452 : && TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)
25629 : {
25630 448 : dw_loc_descr_ref op = new_loc_descr (DW_OP_plus, 0, 0);
25631 448 : add_AT_loc (ptr_die, DW_AT_use_location, op);
25632 : }
25633 : }
25634 :
25635 : static char *producer_string;
25636 :
25637 : /* Given a C and/or C++ language/version string return the "highest".
25638 : C++ is assumed to be "higher" than C in this case. Used for merging
25639 : LTO translation unit languages. */
25640 : static const char *
25641 1 : highest_c_language (const char *lang1, const char *lang2)
25642 : {
25643 1 : if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
25644 : return "GNU C++26";
25645 1 : if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
25646 : return "GNU C++23";
25647 1 : if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
25648 : return "GNU C++20";
25649 0 : if (strcmp ("GNU C++17", lang1) == 0 || strcmp ("GNU C++17", lang2) == 0)
25650 : return "GNU C++17";
25651 0 : if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
25652 : return "GNU C++14";
25653 0 : if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
25654 : return "GNU C++11";
25655 0 : if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
25656 : return "GNU C++98";
25657 :
25658 0 : if (strcmp ("GNU C2Y", lang1) == 0 || strcmp ("GNU C2Y", lang2) == 0)
25659 : return "GNU C2Y";
25660 0 : if (strcmp ("GNU C23", lang1) == 0 || strcmp ("GNU C23", lang2) == 0)
25661 : return "GNU C23";
25662 0 : if (strcmp ("GNU C17", lang1) == 0 || strcmp ("GNU C17", lang2) == 0)
25663 : return "GNU C17";
25664 0 : if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
25665 : return "GNU C11";
25666 0 : if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
25667 : return "GNU C99";
25668 0 : if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
25669 : return "GNU C89";
25670 :
25671 0 : gcc_unreachable ();
25672 : }
25673 :
25674 :
25675 : /* Generate the DIE for the compilation unit. */
25676 :
25677 : static dw_die_ref
25678 57171 : gen_compile_unit_die (const char *filename)
25679 : {
25680 57171 : dw_die_ref die;
25681 57171 : const char *language_string = lang_hooks.name;
25682 57171 : int language, lname, lversion;
25683 :
25684 57171 : die = new_die (DW_TAG_compile_unit, NULL, NULL);
25685 :
25686 57171 : if (filename)
25687 : {
25688 0 : add_filename_attribute (die, filename);
25689 : /* Don't add cwd for <built-in>. */
25690 0 : if (filename[0] != '<')
25691 0 : add_comp_dir_attribute (die);
25692 : }
25693 :
25694 57420 : add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
25695 :
25696 : /* If our producer is LTO try to figure out a common language to use
25697 : from the global list of translation units. */
25698 57171 : if (strcmp (language_string, "GNU GIMPLE") == 0)
25699 : {
25700 : unsigned i;
25701 : tree t;
25702 : const char *common_lang = NULL;
25703 :
25704 1577 : FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
25705 : {
25706 800 : if (!TRANSLATION_UNIT_LANGUAGE (t))
25707 0 : continue;
25708 800 : if (!common_lang)
25709 : common_lang = TRANSLATION_UNIT_LANGUAGE (t);
25710 23 : else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
25711 : ;
25712 1 : else if (startswith (common_lang, "GNU C")
25713 1 : && startswith (TRANSLATION_UNIT_LANGUAGE (t), "GNU C"))
25714 : /* Mixing C and C++ is ok, use C++ in that case. */
25715 1 : common_lang = highest_c_language (common_lang,
25716 1 : TRANSLATION_UNIT_LANGUAGE (t));
25717 : else
25718 : {
25719 : /* Fall back to C. */
25720 : common_lang = NULL;
25721 : break;
25722 : }
25723 : }
25724 :
25725 777 : if (common_lang)
25726 57171 : language_string = common_lang;
25727 : }
25728 :
25729 57171 : language = DW_LANG_C;
25730 57171 : lname = 0;
25731 57171 : lversion = 0;
25732 57171 : if (startswith (language_string, "GNU C")
25733 57171 : && ISDIGIT (language_string[5]))
25734 : {
25735 24174 : language = DW_LANG_C89;
25736 24174 : if (dwarf_version >= 3 || !dwarf_strict)
25737 : {
25738 24174 : if (strcmp (language_string, "GNU C89") != 0)
25739 22782 : language = DW_LANG_C99;
25740 :
25741 24174 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25742 : {
25743 23281 : if (strcmp (language_string, "GNU C11") == 0)
25744 : language = DW_LANG_C11;
25745 19585 : else if (strcmp (language_string, "GNU C17") == 0)
25746 : {
25747 : language = DW_LANG_C11;
25748 : lname = DW_LNAME_C;
25749 : lversion = 201710;
25750 : }
25751 19475 : else if (strcmp (language_string, "GNU C23") == 0)
25752 : {
25753 : language = DW_LANG_C11;
25754 : lname = DW_LNAME_C;
25755 : lversion = 202311;
25756 : }
25757 1472 : else if (strcmp (language_string, "GNU C2Y") == 0)
25758 : {
25759 57171 : language = DW_LANG_C11;
25760 57171 : lname = DW_LNAME_C;
25761 57171 : lversion = 202500;
25762 : }
25763 : }
25764 : }
25765 : }
25766 32997 : else if (startswith (language_string, "GNU C++"))
25767 : {
25768 18354 : language = DW_LANG_C_plus_plus;
25769 18354 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25770 : {
25771 17138 : if (strcmp (language_string, "GNU C++11") == 0)
25772 : language = DW_LANG_C_plus_plus_11;
25773 16711 : else if (strcmp (language_string, "GNU C++14") == 0)
25774 : language = DW_LANG_C_plus_plus_14;
25775 16693 : else if (strcmp (language_string, "GNU C++17") == 0)
25776 : {
25777 : language = DW_LANG_C_plus_plus_14;
25778 : lname = DW_LNAME_C_plus_plus;
25779 : lversion = 201703;
25780 : }
25781 15915 : else if (strcmp (language_string, "GNU C++20") == 0)
25782 : {
25783 : language = DW_LANG_C_plus_plus_14;
25784 : lname = DW_LNAME_C_plus_plus;
25785 : lversion = 202002;
25786 : }
25787 1503 : else if (strcmp (language_string, "GNU C++23") == 0)
25788 : {
25789 : language = DW_LANG_C_plus_plus_14;
25790 : lname = DW_LNAME_C_plus_plus;
25791 : lversion = 202302;
25792 : }
25793 1188 : else if (strcmp (language_string, "GNU C++26") == 0)
25794 : {
25795 57171 : language = DW_LANG_C_plus_plus_14;
25796 57171 : lname = DW_LNAME_C_plus_plus;
25797 57171 : lversion = 202400;
25798 : }
25799 : }
25800 : }
25801 14643 : else if (strcmp (language_string, "GNU F77") == 0)
25802 : language = DW_LANG_Fortran77;
25803 14643 : else if (strcmp (language_string, "GCC COBOL") == 0)
25804 : language = DW_LANG_Cobol85;
25805 14643 : else if (strcmp (language_string, "GNU Modula-2") == 0)
25806 : language = DW_LANG_Modula2;
25807 10729 : else if (dwarf_version >= 3 || !dwarf_strict)
25808 : {
25809 10729 : if (strcmp (language_string, "GNU Ada") == 0)
25810 : language = DW_LANG_Ada95;
25811 10729 : else if (startswith (language_string, "GNU Fortran"))
25812 : {
25813 5140 : language = DW_LANG_Fortran95;
25814 5140 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25815 : {
25816 5111 : if (strcmp (language_string, "GNU Fortran2003") == 0)
25817 : language = DW_LANG_Fortran03;
25818 5088 : else if (strcmp (language_string, "GNU Fortran2008") == 0)
25819 57171 : language = DW_LANG_Fortran08;
25820 : }
25821 : }
25822 5589 : else if (strcmp (language_string, "GNU Objective-C") == 0)
25823 : language = DW_LANG_ObjC;
25824 5589 : else if (strcmp (language_string, "GNU Objective-C++") == 0)
25825 : language = DW_LANG_ObjC_plus_plus;
25826 5589 : else if (strcmp (language_string, "GNU D") == 0)
25827 : language = DW_LANG_D;
25828 5589 : else if (dwarf_version >= 5 || !dwarf_strict)
25829 : {
25830 5588 : if (strcmp (language_string, "GNU Go") == 0)
25831 : language = DW_LANG_Go;
25832 1328 : else if (strcmp (language_string, "GNU Rust") == 0)
25833 : language = DW_LANG_Rust;
25834 812 : else if (strcmp (language_string, "GNU Algol 68") == 0)
25835 : {
25836 57171 : language = DW_LANG_Algol68;
25837 57171 : lname = DW_LNAME_Algol68;
25838 57171 : lversion = 1978; /* Not a typo. The revised language of the
25839 : Revised Report. */
25840 : }
25841 : }
25842 : }
25843 : /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
25844 0 : else if (startswith (language_string, "GNU Fortran"))
25845 : language = DW_LANG_Fortran90;
25846 : /* Likewise for Ada. */
25847 0 : else if (strcmp (language_string, "GNU Ada") == 0)
25848 57171 : language = DW_LANG_Ada83;
25849 :
25850 57171 : add_AT_unsigned (die, DW_AT_language, language);
25851 57171 : if (lname && dwarf_version >= 5 && !dwarf_strict)
25852 : {
25853 34424 : add_AT_unsigned (die, DW_AT_language_name, lname);
25854 34424 : add_AT_unsigned (die, DW_AT_language_version, lversion);
25855 : }
25856 :
25857 57171 : switch (language)
25858 : {
25859 5140 : case DW_LANG_Fortran77:
25860 5140 : case DW_LANG_Fortran90:
25861 5140 : case DW_LANG_Fortran95:
25862 5140 : case DW_LANG_Fortran03:
25863 5140 : case DW_LANG_Fortran08:
25864 : /* Fortran has case insensitive identifiers and the front-end
25865 : lowercases everything. */
25866 5140 : add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
25867 5140 : break;
25868 0 : case DW_LANG_Cobol85:
25869 0 : add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_case_insensitive);
25870 0 : break;
25871 : default:
25872 : /* The default DW_ID_case_sensitive doesn't need to be specified. */
25873 : break;
25874 : }
25875 57171 : return die;
25876 : }
25877 :
25878 : /* Generate the DIE for a base class. */
25879 :
25880 : static void
25881 23129115 : gen_inheritance_die (tree binfo, tree access, tree type,
25882 : dw_die_ref context_die)
25883 : {
25884 23129115 : dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
25885 23129115 : struct vlr_context ctx = { type, NULL };
25886 :
25887 23129115 : add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, false,
25888 : context_die);
25889 23129115 : add_data_member_location_attribute (die, binfo, &ctx);
25890 :
25891 23129115 : if (BINFO_VIRTUAL_P (binfo))
25892 299 : add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
25893 :
25894 : /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
25895 : children, otherwise the default is DW_ACCESS_public. In DWARF2
25896 : the default has always been DW_ACCESS_private. */
25897 23129115 : if (access == access_public_node)
25898 : {
25899 22590400 : if (dwarf_version == 2
25900 22589986 : || context_die->die_tag == DW_TAG_class_type)
25901 1041635 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
25902 : }
25903 538715 : else if (access == access_protected_node)
25904 84639 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
25905 454076 : else if (dwarf_version > 2
25906 454070 : && context_die->die_tag != DW_TAG_class_type)
25907 240393 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
25908 23129115 : }
25909 :
25910 : /* Return whether DECL is a FIELD_DECL that represents the variant part of a
25911 : structure. */
25912 :
25913 : static bool
25914 264302380 : is_variant_part (tree decl)
25915 : {
25916 264302380 : return (TREE_CODE (decl) == FIELD_DECL
25917 264302380 : && TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
25918 : }
25919 :
25920 : /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
25921 : return the FIELD_DECL. Return NULL_TREE otherwise. */
25922 :
25923 : static tree
25924 0 : analyze_discr_in_predicate (tree operand, tree struct_type)
25925 : {
25926 0 : while (CONVERT_EXPR_P (operand))
25927 0 : operand = TREE_OPERAND (operand, 0);
25928 :
25929 : /* Match field access to members of struct_type only. */
25930 0 : if (TREE_CODE (operand) == COMPONENT_REF
25931 0 : && TREE_CODE (TREE_OPERAND (operand, 0)) == PLACEHOLDER_EXPR
25932 0 : && TREE_TYPE (TREE_OPERAND (operand, 0)) == struct_type
25933 0 : && TREE_CODE (TREE_OPERAND (operand, 1)) == FIELD_DECL)
25934 0 : return TREE_OPERAND (operand, 1);
25935 : else
25936 : return NULL_TREE;
25937 : }
25938 :
25939 : /* Check that SRC is a constant integer that can be represented as a native
25940 : integer constant (either signed or unsigned). If so, store it into DEST and
25941 : return true. Return false otherwise. */
25942 :
25943 : static bool
25944 0 : get_discr_value (tree src, dw_discr_value *dest)
25945 : {
25946 0 : tree discr_type = TREE_TYPE (src);
25947 :
25948 0 : if (lang_hooks.types.get_debug_type)
25949 : {
25950 0 : tree debug_type = lang_hooks.types.get_debug_type (discr_type);
25951 0 : if (debug_type != NULL)
25952 0 : discr_type = debug_type;
25953 : }
25954 :
25955 0 : if (TREE_CODE (src) != INTEGER_CST || !INTEGRAL_TYPE_P (discr_type))
25956 : return false;
25957 :
25958 : /* Signedness can vary between the original type and the debug type. This
25959 : can happen for character types in Ada for instance: the character type
25960 : used for code generation can be signed, to be compatible with the C one,
25961 : but from a debugger point of view, it must be unsigned. */
25962 0 : bool is_orig_unsigned = TYPE_UNSIGNED (TREE_TYPE (src));
25963 0 : bool is_debug_unsigned = TYPE_UNSIGNED (discr_type);
25964 :
25965 0 : if (is_orig_unsigned != is_debug_unsigned)
25966 0 : src = fold_convert (discr_type, src);
25967 :
25968 0 : if (!(is_debug_unsigned ? tree_fits_uhwi_p (src) : tree_fits_shwi_p (src)))
25969 : return false;
25970 :
25971 0 : dest->pos = is_debug_unsigned;
25972 0 : if (is_debug_unsigned)
25973 0 : dest->v.uval = tree_to_uhwi (src);
25974 : else
25975 0 : dest->v.sval = tree_to_shwi (src);
25976 :
25977 : return true;
25978 : }
25979 :
25980 : /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
25981 : FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
25982 : store NULL_TREE in DISCR_DECL. Otherwise:
25983 :
25984 : - store the discriminant field in STRUCT_TYPE that controls the variant
25985 : part to *DISCR_DECL
25986 :
25987 : - put in *DISCR_LISTS_P an array where for each variant, the item
25988 : represents the corresponding matching list of discriminant values.
25989 :
25990 : - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
25991 : the above array.
25992 :
25993 : Note that when the array is allocated (i.e. when the analysis is
25994 : successful), it is up to the caller to free the array. */
25995 :
25996 : static void
25997 0 : analyze_variants_discr (tree variant_part_decl,
25998 : tree struct_type,
25999 : tree *discr_decl,
26000 : dw_discr_list_ref **discr_lists_p,
26001 : unsigned *discr_lists_length)
26002 : {
26003 0 : tree variant_part_type = TREE_TYPE (variant_part_decl);
26004 0 : tree variant;
26005 0 : dw_discr_list_ref *discr_lists;
26006 0 : unsigned i;
26007 :
26008 : /* Compute how many variants there are in this variant part. */
26009 0 : *discr_lists_length = 0;
26010 0 : for (variant = TYPE_FIELDS (variant_part_type);
26011 0 : variant != NULL_TREE;
26012 0 : variant = DECL_CHAIN (variant))
26013 0 : ++*discr_lists_length;
26014 :
26015 0 : *discr_decl = NULL_TREE;
26016 0 : *discr_lists_p
26017 0 : = (dw_discr_list_ref *) xcalloc (*discr_lists_length,
26018 : sizeof (**discr_lists_p));
26019 0 : discr_lists = *discr_lists_p;
26020 :
26021 : /* And then analyze all variants to extract discriminant information for all
26022 : of them. This analysis is conservative: as soon as we detect something we
26023 : do not support, abort everything and pretend we found nothing. */
26024 0 : for (variant = TYPE_FIELDS (variant_part_type), i = 0;
26025 0 : variant != NULL_TREE;
26026 0 : variant = DECL_CHAIN (variant), ++i)
26027 : {
26028 0 : tree match_expr = DECL_QUALIFIER (variant);
26029 :
26030 : /* Now, try to analyze the predicate and deduce a discriminant for
26031 : it. */
26032 0 : if (match_expr == boolean_true_node)
26033 : /* Typically happens for the default variant: it matches all cases that
26034 : previous variants rejected. Don't output any matching value for
26035 : this one. */
26036 0 : continue;
26037 :
26038 : /* The following loop tries to iterate over each discriminant
26039 : possibility: single values or ranges. */
26040 0 : while (match_expr != NULL_TREE)
26041 : {
26042 0 : tree next_round_match_expr;
26043 0 : tree candidate_discr = NULL_TREE;
26044 0 : dw_discr_list_ref new_node = NULL;
26045 :
26046 : /* Possibilities are matched one after the other by nested
26047 : TRUTH_ORIF_EXPR expressions. Process the current possibility and
26048 : continue with the rest at next iteration. */
26049 0 : if (TREE_CODE (match_expr) == TRUTH_ORIF_EXPR)
26050 : {
26051 0 : next_round_match_expr = TREE_OPERAND (match_expr, 0);
26052 0 : match_expr = TREE_OPERAND (match_expr, 1);
26053 : }
26054 : else
26055 : next_round_match_expr = NULL_TREE;
26056 :
26057 0 : if (match_expr == boolean_false_node)
26058 : /* This sub-expression matches nothing: just wait for the next
26059 : one. */
26060 : ;
26061 :
26062 0 : else if (TREE_CODE (match_expr) == EQ_EXPR)
26063 : {
26064 : /* We are matching: <discr_field> == <integer_cst>
26065 : This sub-expression matches a single value. */
26066 0 : tree integer_cst = TREE_OPERAND (match_expr, 1);
26067 :
26068 0 : candidate_discr
26069 0 : = analyze_discr_in_predicate (TREE_OPERAND (match_expr, 0),
26070 : struct_type);
26071 :
26072 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
26073 0 : if (!get_discr_value (integer_cst,
26074 : &new_node->dw_discr_lower_bound))
26075 0 : goto abort;
26076 0 : new_node->dw_discr_range = false;
26077 : }
26078 :
26079 0 : else if (TREE_CODE (match_expr) == TRUTH_ANDIF_EXPR)
26080 : {
26081 : /* We are matching:
26082 : <discr_field> > <integer_cst>
26083 : && <discr_field> < <integer_cst>.
26084 : This sub-expression matches the range of values between the
26085 : two matched integer constants. Note that comparisons can be
26086 : inclusive or exclusive. */
26087 0 : tree candidate_discr_1, candidate_discr_2;
26088 0 : tree lower_cst, upper_cst;
26089 0 : bool lower_cst_included, upper_cst_included;
26090 0 : tree lower_op = TREE_OPERAND (match_expr, 0);
26091 0 : tree upper_op = TREE_OPERAND (match_expr, 1);
26092 :
26093 : /* When the comparison is exclusive, the integer constant is not
26094 : the discriminant range bound we are looking for: we will have
26095 : to increment or decrement it. */
26096 0 : if (TREE_CODE (lower_op) == GE_EXPR)
26097 : lower_cst_included = true;
26098 0 : else if (TREE_CODE (lower_op) == GT_EXPR)
26099 : lower_cst_included = false;
26100 : else
26101 0 : goto abort;
26102 :
26103 0 : if (TREE_CODE (upper_op) == LE_EXPR)
26104 : upper_cst_included = true;
26105 0 : else if (TREE_CODE (upper_op) == LT_EXPR)
26106 : upper_cst_included = false;
26107 : else
26108 0 : goto abort;
26109 :
26110 : /* Extract the discriminant from the first operand and check it
26111 : is consistent with the same analysis in the second
26112 : operand. */
26113 0 : candidate_discr_1
26114 0 : = analyze_discr_in_predicate (TREE_OPERAND (lower_op, 0),
26115 : struct_type);
26116 0 : candidate_discr_2
26117 0 : = analyze_discr_in_predicate (TREE_OPERAND (upper_op, 0),
26118 : struct_type);
26119 0 : if (candidate_discr_1 == candidate_discr_2)
26120 0 : candidate_discr = candidate_discr_1;
26121 : else
26122 0 : goto abort;
26123 :
26124 : /* Extract bounds from both. */
26125 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
26126 0 : lower_cst = TREE_OPERAND (lower_op, 1);
26127 0 : upper_cst = TREE_OPERAND (upper_op, 1);
26128 :
26129 0 : if (!lower_cst_included)
26130 0 : lower_cst
26131 0 : = fold_build2 (PLUS_EXPR, TREE_TYPE (lower_cst), lower_cst,
26132 : build_int_cst (TREE_TYPE (lower_cst), 1));
26133 0 : if (!upper_cst_included)
26134 0 : upper_cst
26135 0 : = fold_build2 (MINUS_EXPR, TREE_TYPE (upper_cst), upper_cst,
26136 : build_int_cst (TREE_TYPE (upper_cst), 1));
26137 :
26138 0 : if (!get_discr_value (lower_cst,
26139 : &new_node->dw_discr_lower_bound)
26140 0 : || !get_discr_value (upper_cst,
26141 : &new_node->dw_discr_upper_bound))
26142 0 : goto abort;
26143 :
26144 0 : new_node->dw_discr_range = true;
26145 : }
26146 :
26147 0 : else if ((candidate_discr
26148 0 : = analyze_discr_in_predicate (match_expr, struct_type))
26149 0 : && (TREE_TYPE (candidate_discr) == boolean_type_node
26150 0 : || TREE_TYPE (TREE_TYPE (candidate_discr))
26151 : == boolean_type_node))
26152 : {
26153 : /* We are matching: <discr_field> for a boolean discriminant.
26154 : This sub-expression matches boolean_true_node. */
26155 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
26156 0 : if (!get_discr_value (boolean_true_node,
26157 : &new_node->dw_discr_lower_bound))
26158 0 : goto abort;
26159 0 : new_node->dw_discr_range = false;
26160 : }
26161 :
26162 : else
26163 : /* Unsupported sub-expression: we cannot determine the set of
26164 : matching discriminant values. Abort everything. */
26165 0 : goto abort;
26166 :
26167 : /* If the discriminant info is not consistent with what we saw so
26168 : far, consider the analysis failed and abort everything. */
26169 0 : if (candidate_discr == NULL_TREE
26170 0 : || (*discr_decl != NULL_TREE && candidate_discr != *discr_decl))
26171 0 : goto abort;
26172 : else
26173 0 : *discr_decl = candidate_discr;
26174 :
26175 0 : if (new_node != NULL)
26176 : {
26177 0 : new_node->dw_discr_next = discr_lists[i];
26178 0 : discr_lists[i] = new_node;
26179 : }
26180 0 : match_expr = next_round_match_expr;
26181 : }
26182 : }
26183 :
26184 : /* If we reach this point, we could match everything we were interested
26185 : in. */
26186 : return;
26187 :
26188 0 : abort:
26189 : /* Clean all data structure and return no result. */
26190 0 : free (*discr_lists_p);
26191 0 : *discr_lists_p = NULL;
26192 0 : *discr_decl = NULL_TREE;
26193 : }
26194 :
26195 : /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
26196 : of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
26197 : under CONTEXT_DIE.
26198 :
26199 : Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
26200 : QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
26201 : this type, which are record types, represent the available variants and each
26202 : has a DECL_QUALIFIER attribute. The discriminant and the discriminant
26203 : values are inferred from these attributes.
26204 :
26205 : In trees, the offsets for the fields inside these sub-records are relative
26206 : to the variant part itself, whereas the corresponding DIEs should have
26207 : offset attributes that are relative to the embedding record base address.
26208 : This is why the caller must provide a VARIANT_PART_OFFSET expression: it
26209 : must be an expression that computes the offset of the variant part to
26210 : describe in DWARF. */
26211 :
26212 : static void
26213 0 : gen_variant_part (tree variant_part_decl, struct vlr_context *vlr_ctx,
26214 : dw_die_ref context_die)
26215 : {
26216 0 : const tree variant_part_type = TREE_TYPE (variant_part_decl);
26217 0 : tree variant_part_offset = vlr_ctx->variant_part_offset;
26218 :
26219 : /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
26220 : NULL_TREE if there is no such field. */
26221 0 : tree discr_decl = NULL_TREE;
26222 0 : dw_discr_list_ref *discr_lists;
26223 0 : unsigned discr_lists_length = 0;
26224 0 : unsigned i;
26225 :
26226 0 : dw_die_ref dwarf_proc_die = NULL;
26227 0 : dw_die_ref variant_part_die
26228 0 : = new_die (DW_TAG_variant_part, context_die, variant_part_type);
26229 :
26230 0 : equate_decl_number_to_die (variant_part_decl, variant_part_die);
26231 :
26232 0 : analyze_variants_discr (variant_part_decl, vlr_ctx->struct_type,
26233 : &discr_decl, &discr_lists, &discr_lists_length);
26234 :
26235 0 : if (discr_decl != NULL_TREE)
26236 : {
26237 0 : dw_die_ref discr_die = lookup_decl_die (discr_decl);
26238 :
26239 0 : if (discr_die)
26240 0 : add_AT_die_ref (variant_part_die, DW_AT_discr, discr_die);
26241 : else
26242 : /* We have no DIE for the discriminant, so just discard all
26243 : discrimimant information in the output. */
26244 0 : discr_decl = NULL_TREE;
26245 : }
26246 :
26247 : /* If the offset for this variant part is more complex than a constant,
26248 : create a DWARF procedure for it so that we will not have to generate
26249 : DWARF expressions for it for each member. */
26250 0 : if (TREE_CODE (variant_part_offset) != INTEGER_CST
26251 0 : && (dwarf_version >= 3 || !dwarf_strict))
26252 : {
26253 0 : struct loc_descr_context ctx = {
26254 0 : vlr_ctx->struct_type, /* context_type */
26255 : NULL_TREE, /* base_decl */
26256 : NULL, /* dpi */
26257 : false, /* placeholder_arg */
26258 : false, /* placeholder_seen */
26259 : false /* strict_signedness */
26260 0 : };
26261 0 : const tree dwarf_proc_fndecl
26262 0 : = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
26263 0 : build_function_type (TREE_TYPE (variant_part_offset),
26264 : NULL_TREE));
26265 0 : const tree dwarf_proc_call = build_call_expr (dwarf_proc_fndecl, 0);
26266 0 : const dw_loc_descr_ref dwarf_proc_body
26267 0 : = loc_descriptor_from_tree (variant_part_offset, 0, &ctx);
26268 :
26269 0 : dwarf_proc_die = new_dwarf_proc_die (dwarf_proc_body,
26270 : dwarf_proc_fndecl, context_die);
26271 0 : if (dwarf_proc_die != NULL)
26272 0 : variant_part_offset = dwarf_proc_call;
26273 : }
26274 :
26275 : /* Output DIEs for all variants. */
26276 0 : i = 0;
26277 0 : for (tree variant = TYPE_FIELDS (variant_part_type);
26278 0 : variant != NULL_TREE;
26279 0 : variant = DECL_CHAIN (variant), ++i)
26280 : {
26281 0 : tree variant_type = TREE_TYPE (variant);
26282 0 : dw_die_ref variant_die;
26283 :
26284 : /* All variants (i.e. members of a variant part) are supposed to be
26285 : encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
26286 : under these records. */
26287 0 : gcc_assert (TREE_CODE (variant_type) == RECORD_TYPE);
26288 :
26289 0 : variant_die = new_die (DW_TAG_variant, variant_part_die, variant_type);
26290 0 : equate_decl_number_to_die (variant, variant_die);
26291 :
26292 : /* Output discriminant values this variant matches, if any. */
26293 0 : if (discr_decl == NULL || discr_lists[i] == NULL)
26294 : /* In the case we have discriminant information at all, this is
26295 : probably the default variant: as the standard says, don't
26296 : output any discriminant value/list attribute. */
26297 : ;
26298 0 : else if (discr_lists[i]->dw_discr_next == NULL
26299 0 : && !discr_lists[i]->dw_discr_range)
26300 : /* If there is only one accepted value, don't bother outputting a
26301 : list. */
26302 0 : add_discr_value (variant_die, &discr_lists[i]->dw_discr_lower_bound);
26303 : else
26304 0 : add_discr_list (variant_die, discr_lists[i]);
26305 :
26306 0 : for (tree member = TYPE_FIELDS (variant_type);
26307 0 : member != NULL_TREE;
26308 0 : member = DECL_CHAIN (member))
26309 : {
26310 0 : struct vlr_context vlr_sub_ctx = {
26311 0 : vlr_ctx->struct_type, /* struct_type */
26312 : NULL /* variant_part_offset */
26313 0 : };
26314 0 : if (is_variant_part (member))
26315 : {
26316 : /* All offsets for fields inside variant parts are relative to
26317 : the top-level embedding RECORD_TYPE's base address. On the
26318 : other hand, offsets in GCC's types are relative to the
26319 : nested-most variant part. So we have to sum offsets each time
26320 : we recurse. */
26321 :
26322 0 : vlr_sub_ctx.variant_part_offset
26323 0 : = fold_build2 (PLUS_EXPR, TREE_TYPE (variant_part_offset),
26324 : variant_part_offset, byte_position (member));
26325 0 : gen_variant_part (member, &vlr_sub_ctx, variant_die);
26326 : }
26327 : else
26328 : {
26329 0 : vlr_sub_ctx.variant_part_offset = variant_part_offset;
26330 0 : gen_decl_die (member, NULL, &vlr_sub_ctx, variant_die);
26331 : }
26332 : }
26333 : }
26334 :
26335 0 : free (discr_lists);
26336 0 : }
26337 :
26338 : /* Generate a DIE for a class member. */
26339 :
26340 : static void
26341 50414318 : gen_member_die (tree type, dw_die_ref context_die)
26342 : {
26343 50414318 : tree member;
26344 50414318 : tree binfo = TYPE_BINFO (type);
26345 :
26346 50414318 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
26347 :
26348 : /* If this is not an incomplete type, output descriptions of each of its
26349 : members. Note that as we output the DIEs necessary to represent the
26350 : members of this record or union type, we will also be trying to output
26351 : DIEs to represent the *types* of those members. However the `type'
26352 : function (above) will specifically avoid generating type DIEs for member
26353 : types *within* the list of member DIEs for this (containing) type except
26354 : for those types (of members) which are explicitly marked as also being
26355 : members of this (containing) type themselves. The g++ front- end can
26356 : force any given type to be treated as a member of some other (containing)
26357 : type by setting the TYPE_CONTEXT of the given (member) type to point to
26358 : the TREE node representing the appropriate (containing) type. */
26359 :
26360 : /* First output info about the base classes. */
26361 50414318 : if (binfo && early_dwarf)
26362 : {
26363 49715344 : vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
26364 49715344 : int i;
26365 49715344 : tree base;
26366 :
26367 72844459 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
26368 46258230 : gen_inheritance_die (base,
26369 23129115 : (accesses ? (*accesses)[i] : access_public_node),
26370 : type,
26371 : context_die);
26372 : }
26373 :
26374 : /* Now output info about the members. */
26375 378954549 : for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
26376 : {
26377 : /* Ignore clones. */
26378 328540231 : if (DECL_ABSTRACT_ORIGIN (member))
26379 55507868 : continue;
26380 :
26381 273032363 : struct vlr_context vlr_ctx = { type, NULL_TREE };
26382 273032363 : bool static_inline_p
26383 273032363 : = (VAR_P (member)
26384 11508479 : && TREE_STATIC (member)
26385 284540842 : && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
26386 273032363 : != -1));
26387 :
26388 : /* If we thought we were generating minimal debug info for TYPE
26389 : and then changed our minds, some of the member declarations
26390 : may have already been defined. Don't define them again, but
26391 : do put them in the right order. */
26392 :
26393 273032363 : if (dw_die_ref child = lookup_decl_die (member))
26394 : {
26395 : /* Handle inline static data members, which only have in-class
26396 : declarations. */
26397 8729983 : bool splice = true;
26398 :
26399 8729983 : dw_die_ref ref = NULL;
26400 8729983 : if (child->die_tag == DW_TAG_variable
26401 8729983 : && child->die_parent == comp_unit_die ())
26402 : {
26403 7507846 : ref = get_AT_ref (child, DW_AT_specification);
26404 :
26405 : /* For C++17 inline static data members followed by redundant
26406 : out of class redeclaration, we might get here with
26407 : child being the DIE created for the out of class
26408 : redeclaration and with its DW_AT_specification being
26409 : the DIE created for in-class definition. We want to
26410 : reparent the latter, and don't want to create another
26411 : DIE with DW_AT_specification in that case, because
26412 : we already have one. */
26413 7507846 : if (ref
26414 7507846 : && static_inline_p
26415 6 : && ref->die_tag == DW_TAG_variable
26416 6 : && ref->die_parent == comp_unit_die ()
26417 7507852 : && get_AT (ref, DW_AT_specification) == NULL)
26418 : {
26419 : child = ref;
26420 : ref = NULL;
26421 : static_inline_p = false;
26422 : }
26423 :
26424 7507840 : if (!ref)
26425 : {
26426 7507329 : reparent_child (child, context_die);
26427 7507329 : if (dwarf_version < 5)
26428 14 : child->die_tag = DW_TAG_member;
26429 : splice = false;
26430 : }
26431 : }
26432 1222137 : else if (child->die_tag == DW_TAG_enumerator)
26433 : /* Enumerators remain under their enumeration even if
26434 : their names are introduced in the enclosing scope. */
26435 : splice = false;
26436 :
26437 : if (splice)
26438 17792 : splice_child_die (context_die, child);
26439 : }
26440 :
26441 : /* Do not generate DWARF for variant parts if we are generating the
26442 : corresponding GNAT encodings: DIEs generated for the two schemes
26443 : would conflict in our mappings. */
26444 264302380 : else if (is_variant_part (member)
26445 264302380 : && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL)
26446 : {
26447 0 : vlr_ctx.variant_part_offset = byte_position (member);
26448 0 : gen_variant_part (member, &vlr_ctx, context_die);
26449 : }
26450 : else
26451 : {
26452 264302380 : vlr_ctx.variant_part_offset = NULL_TREE;
26453 264302380 : gen_decl_die (member, NULL, &vlr_ctx, context_die);
26454 : }
26455 :
26456 : /* For C++ inline static data members emit immediately a DW_TAG_variable
26457 : DIE that will refer to that DW_TAG_member/DW_TAG_variable through
26458 : DW_AT_specification. */
26459 273032363 : if (static_inline_p)
26460 : {
26461 9804316 : int old_extern = DECL_EXTERNAL (member);
26462 9804316 : DECL_EXTERNAL (member) = 0;
26463 9804316 : gen_decl_die (member, NULL, NULL, comp_unit_die ());
26464 9804316 : DECL_EXTERNAL (member) = old_extern;
26465 : }
26466 : }
26467 50414318 : }
26468 :
26469 : /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
26470 : is set, we pretend that the type was never defined, so we only get the
26471 : member DIEs needed by later specification DIEs. */
26472 :
26473 : static void
26474 134637713 : gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
26475 : enum debug_info_usage usage)
26476 : {
26477 134637713 : if (TREE_ASM_WRITTEN (type))
26478 : {
26479 : /* Fill in the bound of variable-length fields in late dwarf if
26480 : still incomplete. */
26481 180 : if (!early_dwarf && variably_modified_type_p (type, NULL))
26482 84 : for (tree member = TYPE_FIELDS (type);
26483 203 : member;
26484 119 : member = DECL_CHAIN (member))
26485 119 : fill_variable_array_bounds (TREE_TYPE (member));
26486 180 : return;
26487 : }
26488 :
26489 134637533 : dw_die_ref type_die = lookup_type_die (type);
26490 134637533 : dw_die_ref scope_die = 0;
26491 134637533 : bool nested = false;
26492 134637533 : bool complete = (TYPE_SIZE (type)
26493 134637533 : && (! TYPE_STUB_DECL (type)
26494 98952959 : || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
26495 134637533 : bool ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
26496 134637533 : complete = complete && should_emit_struct_debug (type, usage);
26497 :
26498 134637533 : if (type_die && ! complete)
26499 : return;
26500 :
26501 103758851 : if (TYPE_CONTEXT (type) != NULL_TREE
26502 103758851 : && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
26503 99778717 : || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
26504 : nested = true;
26505 :
26506 103758851 : scope_die = scope_die_for (type, context_die);
26507 :
26508 : /* Generate child dies for template parameters. */
26509 103758851 : if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
26510 53730967 : schedule_generic_params_dies_gen (type);
26511 :
26512 50027881 : if (! type_die || (nested && is_cu_die (scope_die)))
26513 : /* First occurrence of type or toplevel definition of nested class. */
26514 : {
26515 53730970 : dw_die_ref old_die = type_die;
26516 :
26517 107004190 : type_die = new_die (TREE_CODE (type) == RECORD_TYPE
26518 53273220 : ? record_type_tag (type) : DW_TAG_union_type,
26519 : scope_die, type);
26520 53730970 : equate_type_number_to_die (type, type_die);
26521 53730970 : if (old_die)
26522 0 : add_AT_specification (type_die, old_die);
26523 : else
26524 53730970 : add_name_attribute (type_die, type_tag (type));
26525 : }
26526 : else
26527 50027881 : remove_AT (type_die, DW_AT_declaration);
26528 :
26529 : /* If this type has been completed, then give it a byte_size attribute and
26530 : then give a list of members. */
26531 103758851 : if (complete && !ns_decl)
26532 : {
26533 : /* Prevent infinite recursion in cases where the type of some member of
26534 : this type is expressed in terms of this type itself. */
26535 50414318 : TREE_ASM_WRITTEN (type) = 1;
26536 50414318 : add_byte_size_attribute (type_die, type);
26537 50414318 : add_alignment_attribute (type_die, type);
26538 50414318 : if (TYPE_STUB_DECL (type) != NULL_TREE)
26539 : {
26540 50209597 : add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
26541 50209597 : add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
26542 : }
26543 :
26544 : /* If the first reference to this type was as the return type of an
26545 : inline function, then it may not have a parent. Fix this now. */
26546 50414318 : if (type_die->die_parent == NULL)
26547 283925 : add_child_die (scope_die, type_die);
26548 :
26549 50414318 : gen_member_die (type, type_die);
26550 :
26551 50414318 : add_gnat_descriptive_type_attribute (type_die, type, context_die);
26552 50414318 : if (TYPE_ARTIFICIAL (type))
26553 1459 : add_AT_flag (type_die, DW_AT_artificial, 1);
26554 :
26555 : /* GNU extension: Record what type our vtable lives in. */
26556 50414318 : if (TYPE_VFIELD (type))
26557 : {
26558 378641 : tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
26559 :
26560 378641 : gen_type_die (vtype, context_die);
26561 378641 : add_AT_die_ref (type_die, DW_AT_containing_type,
26562 : lookup_type_die (vtype));
26563 : }
26564 : }
26565 : else
26566 : {
26567 53344533 : add_AT_flag (type_die, DW_AT_declaration, 1);
26568 :
26569 : /* We don't need to do this for function-local types. */
26570 53344533 : if (TYPE_STUB_DECL (type)
26571 53344533 : && ! decl_function_context (TYPE_STUB_DECL (type)))
26572 53343779 : vec_safe_push (incomplete_types, type);
26573 : }
26574 :
26575 103758851 : if (get_AT (type_die, DW_AT_name))
26576 102241158 : add_pubtype (type, type_die);
26577 : }
26578 :
26579 : /* Generate a DIE for a subroutine _type_. */
26580 :
26581 : static void
26582 421205 : gen_subroutine_type_die (tree type, dw_die_ref context_die)
26583 : {
26584 421205 : tree return_type = TREE_TYPE (type);
26585 421205 : dw_die_ref subr_die
26586 421205 : = new_die (DW_TAG_subroutine_type,
26587 : scope_die_for (type, context_die), type);
26588 :
26589 421205 : equate_type_number_to_die (type, subr_die);
26590 421205 : add_prototyped_attribute (subr_die, type);
26591 421205 : add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, false,
26592 : context_die);
26593 421205 : add_alignment_attribute (subr_die, type);
26594 421205 : gen_formal_types_die (type, subr_die);
26595 :
26596 421205 : if (get_AT (subr_die, DW_AT_name))
26597 0 : add_pubtype (type, subr_die);
26598 775 : if ((dwarf_version >= 5 || !dwarf_strict)
26599 421974 : && lang_hooks.types.type_dwarf_attribute (type, DW_AT_reference) != -1)
26600 90 : add_AT_flag (subr_die, DW_AT_reference, 1);
26601 775 : if ((dwarf_version >= 5 || !dwarf_strict)
26602 421974 : && lang_hooks.types.type_dwarf_attribute (type,
26603 : DW_AT_rvalue_reference) != -1)
26604 38 : add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
26605 421205 : }
26606 :
26607 : /* Generate a DIE for a type definition. */
26608 :
26609 : static void
26610 62022256 : gen_typedef_die (tree decl, dw_die_ref context_die)
26611 : {
26612 62022256 : dw_die_ref type_die;
26613 62022256 : tree type;
26614 :
26615 62022256 : if (TREE_ASM_WRITTEN (decl))
26616 : {
26617 10012438 : if (DECL_ORIGINAL_TYPE (decl))
26618 9876871 : fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl));
26619 10012438 : return;
26620 : }
26621 :
26622 : /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
26623 : checks in process_scope_var and modified_type_die), this should be called
26624 : only for original types. */
26625 52009818 : gcc_assert (decl_ultimate_origin (decl) == NULL
26626 : || decl_ultimate_origin (decl) == decl);
26627 :
26628 52009818 : TREE_ASM_WRITTEN (decl) = 1;
26629 52009818 : type_die = new_die (DW_TAG_typedef, context_die, decl);
26630 :
26631 52009818 : add_name_and_src_coords_attributes (type_die, decl);
26632 52009818 : if (DECL_ORIGINAL_TYPE (decl))
26633 : {
26634 51702517 : type = DECL_ORIGINAL_TYPE (decl);
26635 51702517 : if (type == error_mark_node)
26636 : return;
26637 :
26638 51702517 : gcc_assert (type != TREE_TYPE (decl));
26639 51702517 : equate_type_number_to_die (TREE_TYPE (decl), type_die);
26640 : }
26641 : else
26642 : {
26643 307301 : type = TREE_TYPE (decl);
26644 307301 : if (type == error_mark_node)
26645 : return;
26646 :
26647 307301 : if (is_naming_typedef_decl (TYPE_NAME (type)))
26648 : {
26649 : /* Here, we are in the case of decl being a typedef naming
26650 : an anonymous type, e.g:
26651 : typedef struct {...} foo;
26652 : In that case TREE_TYPE (decl) is not a typedef variant
26653 : type and TYPE_NAME of the anonymous type is set to the
26654 : TYPE_DECL of the typedef. This construct is emitted by
26655 : the C++ FE.
26656 :
26657 : TYPE is the anonymous struct named by the typedef
26658 : DECL. As we need the DW_AT_type attribute of the
26659 : DW_TAG_typedef to point to the DIE of TYPE, let's
26660 : generate that DIE right away. add_type_attribute
26661 : called below will then pick (via lookup_type_die) that
26662 : anonymous struct DIE. */
26663 306812 : if (!TREE_ASM_WRITTEN (type))
26664 65 : gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
26665 :
26666 : /* This is a GNU Extension. We are adding a
26667 : DW_AT_linkage_name attribute to the DIE of the
26668 : anonymous struct TYPE. The value of that attribute
26669 : is the name of the typedef decl naming the anonymous
26670 : struct. This greatly eases the work of consumers of
26671 : this debug info. */
26672 306812 : add_linkage_name_raw (lookup_type_die (type), decl);
26673 : }
26674 : }
26675 :
26676 52009818 : add_type_attribute (type_die, type, decl_quals (decl), false,
26677 : context_die);
26678 :
26679 52009818 : if (is_naming_typedef_decl (decl))
26680 : /* We want that all subsequent calls to lookup_type_die with
26681 : TYPE in argument yield the DW_TAG_typedef we have just
26682 : created. */
26683 306812 : equate_type_number_to_die (type, type_die);
26684 :
26685 52009818 : add_alignment_attribute (type_die, TREE_TYPE (decl));
26686 :
26687 52009818 : add_accessibility_attribute (type_die, decl);
26688 :
26689 52009818 : if (DECL_ABSTRACT_P (decl))
26690 5802 : equate_decl_number_to_die (decl, type_die);
26691 :
26692 52009818 : if (get_AT (type_die, DW_AT_name))
26693 52009784 : add_pubtype (decl, type_die);
26694 : }
26695 :
26696 : /* Generate a DIE for a struct, class, enum or union type. */
26697 :
26698 : static void
26699 136959506 : gen_tagged_type_die (tree type,
26700 : dw_die_ref context_die,
26701 : enum debug_info_usage usage,
26702 : bool reverse)
26703 : {
26704 136959506 : if (type == NULL_TREE
26705 136959506 : || !is_tagged_type (type))
26706 : return;
26707 :
26708 136959506 : if (TREE_ASM_WRITTEN (type))
26709 : ;
26710 : /* If this is a nested type whose containing class hasn't been written
26711 : out yet, writing it out will cover this one, too. This does not apply
26712 : to instantiations of member class templates; they need to be added to
26713 : the containing class as they are generated. FIXME: This hurts the
26714 : idea of combining type decls from multiple TUs, since we can't predict
26715 : what set of template instantiations we'll get. */
26716 136959324 : else if (TYPE_CONTEXT (type)
26717 136074058 : && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
26718 142292393 : && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
26719 : {
26720 2410592 : gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
26721 :
26722 2410592 : if (TREE_ASM_WRITTEN (type))
26723 : return;
26724 :
26725 : /* If that failed, attach ourselves to the stub. */
26726 2410592 : context_die = lookup_type_die (TYPE_CONTEXT (type));
26727 : }
26728 134548732 : else if (TYPE_CONTEXT (type) != NULL_TREE
26729 134548732 : && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
26730 : {
26731 : /* If this type is local to a function that hasn't been written
26732 : out yet, use a NULL context for now; it will be fixed up in
26733 : decls_for_scope. */
26734 308806 : context_die = lookup_decl_die (TYPE_CONTEXT (type));
26735 : /* A declaration DIE doesn't count; nested types need to go in the
26736 : specification. */
26737 308806 : if (context_die && is_declaration_die (context_die))
26738 : context_die = NULL;
26739 : }
26740 : else
26741 134239926 : context_die = declare_in_namespace (type, context_die);
26742 :
26743 136959506 : if (TREE_CODE (type) == ENUMERAL_TYPE)
26744 : {
26745 : /* This might have been written out by the call to
26746 : declare_in_namespace. */
26747 2321793 : if (!TREE_ASM_WRITTEN (type) || reverse)
26748 1822178 : gen_enumeration_type_die (type, context_die, reverse);
26749 : }
26750 : else
26751 134637713 : gen_struct_or_union_type_die (type, context_die, usage);
26752 :
26753 136959506 : dw_die_ref die = lookup_type_die (type);
26754 136959506 : if (die)
26755 136959506 : maybe_gen_btf_type_tag_dies (type, die);
26756 :
26757 : /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
26758 : it up if it is ever completed. gen_*_type_die will set it for us
26759 : when appropriate. */
26760 : }
26761 :
26762 : /* Generate a type description DIE. */
26763 :
26764 : static void
26765 929272233 : gen_type_die_with_usage (tree type, dw_die_ref context_die,
26766 : enum debug_info_usage usage, bool reverse)
26767 : {
26768 929272233 : struct array_descr_info info;
26769 :
26770 929272233 : if (type == NULL_TREE || type == error_mark_node)
26771 898326740 : return;
26772 :
26773 929272233 : if (flag_checking && type)
26774 929272210 : verify_type (type);
26775 :
26776 929272233 : if (TYPE_NAME (type) != NULL_TREE
26777 776682621 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
26778 776044899 : && is_redundant_typedef (TYPE_NAME (type))
26779 1415602251 : && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
26780 : /* The DECL of this type is a typedef we don't want to emit debug
26781 : info for but we want debug info for its underlying typedef.
26782 : This can happen for e.g, the injected-class-name of a C++
26783 : type. */
26784 49751648 : type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
26785 :
26786 : /* If TYPE is a typedef type variant, let's generate debug info
26787 : for the parent typedef which TYPE is a type of. */
26788 929272233 : if (typedef_variant_p (type))
26789 : {
26790 86291358 : tree name = TYPE_NAME (type);
26791 86291358 : if (TREE_ASM_WRITTEN (name))
26792 : return;
26793 :
26794 13690229 : tree origin = decl_ultimate_origin (name);
26795 13690229 : if (origin != NULL && origin != name)
26796 : {
26797 0 : gen_decl_die (origin, NULL, NULL, context_die);
26798 0 : return;
26799 : }
26800 :
26801 : /* Prevent broken recursion; we can't hand off to the same type. */
26802 13690229 : gcc_assert (DECL_ORIGINAL_TYPE (name) != type);
26803 :
26804 : /* Give typedefs the right scope. */
26805 13690229 : context_die = scope_die_for (type, context_die);
26806 :
26807 13690229 : gen_decl_die (name, NULL, NULL, context_die);
26808 13690229 : return;
26809 : }
26810 :
26811 : /* If type is an anonymous tagged type named by a typedef, let's
26812 : generate debug info for the typedef. */
26813 842980875 : if (is_naming_typedef_decl (TYPE_NAME (type)))
26814 : {
26815 : /* Give typedefs the right scope. */
26816 135939 : context_die = scope_die_for (type, context_die);
26817 :
26818 135939 : gen_decl_die (TYPE_NAME (type), NULL, NULL, context_die);
26819 135939 : return;
26820 : }
26821 :
26822 842844936 : if (lang_hooks.types.get_debug_type)
26823 : {
26824 836657926 : tree debug_type = lang_hooks.types.get_debug_type (type);
26825 :
26826 836657926 : if (debug_type != NULL_TREE && debug_type != type)
26827 : {
26828 12866 : gen_type_die_with_usage (debug_type, context_die, usage, reverse);
26829 12866 : return;
26830 : }
26831 : }
26832 :
26833 : /* We are going to output a DIE to represent the unqualified version
26834 : of this type (i.e. without any const or volatile qualifiers) so
26835 : get the main variant (i.e. the unqualified version) of this type
26836 : now. (Vectors and arrays are special because the debugging info is in the
26837 : cloned type itself. Similarly function/method types can contain extra
26838 : ref-qualification). */
26839 842832070 : if (FUNC_OR_METHOD_TYPE_P (type))
26840 : {
26841 : /* For function/method types, can't use type_main_variant here,
26842 : because that can have different ref-qualifiers for C++,
26843 : but try to canonicalize. */
26844 473619 : tree main = TYPE_MAIN_VARIANT (type);
26845 496391 : for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
26846 496379 : if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
26847 496212 : && check_base_type (t, main)
26848 982912 : && check_lang_type (t, type))
26849 : {
26850 : type = t;
26851 : break;
26852 : }
26853 : }
26854 842358451 : else if (TREE_CODE (type) != VECTOR_TYPE
26855 842358451 : && TREE_CODE (type) != ARRAY_TYPE)
26856 840726709 : type = type_main_variant (type);
26857 :
26858 : /* If this is an array type with hidden descriptor, handle it first. */
26859 842832070 : if (!TREE_ASM_WRITTEN (type)
26860 167907055 : && lang_hooks.types.get_array_descr_info)
26861 : {
26862 88722 : memset (&info, 0, sizeof (info));
26863 88722 : if (lang_hooks.types.get_array_descr_info (type, &info))
26864 : {
26865 : /* Fortran sometimes emits array types with no dimension. */
26866 6936 : gcc_assert (info.ndimensions >= 0
26867 : && (info.ndimensions
26868 : <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN));
26869 6936 : gen_descr_array_type_die (type, &info, context_die);
26870 6936 : TREE_ASM_WRITTEN (type) = 1;
26871 6936 : return;
26872 : }
26873 : }
26874 :
26875 842825134 : if (TREE_ASM_WRITTEN (type) && !reverse)
26876 : {
26877 : /* Variable-length types may be incomplete even if
26878 : TREE_ASM_WRITTEN. For such types, fall through to
26879 : gen_array_type_die() and possibly fill in
26880 : DW_AT_{upper,lower}_bound attributes. */
26881 674925013 : if ((TREE_CODE (type) != ARRAY_TYPE
26882 : && TREE_CODE (type) != RECORD_TYPE
26883 : && TREE_CODE (type) != UNION_TYPE
26884 674925013 : && TREE_CODE (type) != QUAL_UNION_TYPE)
26885 674925013 : || !variably_modified_type_p (type, NULL))
26886 674920200 : return;
26887 : }
26888 :
26889 167904934 : switch (TREE_CODE (type))
26890 : {
26891 : case ERROR_MARK:
26892 : break;
26893 :
26894 28771911 : case POINTER_TYPE:
26895 28771911 : case REFERENCE_TYPE:
26896 : /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
26897 : ensures that the gen_type_die recursion will terminate even if the
26898 : type is recursive. Recursive types are possible in Ada. */
26899 : /* ??? We could perhaps do this for all types before the switch
26900 : statement. */
26901 28771911 : TREE_ASM_WRITTEN (type) = 1;
26902 :
26903 : /* For these types, all that is required is that we output a DIE (or a
26904 : set of DIEs) to represent the "basis" type. */
26905 28771911 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26906 : DINFO_USAGE_IND_USE);
26907 28771911 : break;
26908 :
26909 29452 : case OFFSET_TYPE:
26910 : /* This code is used for C++ pointer-to-data-member types.
26911 : Output a description of the relevant class type. */
26912 29452 : gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
26913 : DINFO_USAGE_IND_USE);
26914 :
26915 : /* Output a description of the type of the object pointed to. */
26916 29452 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26917 : DINFO_USAGE_IND_USE);
26918 :
26919 : /* Now output a DIE to represent this pointer-to-data-member type
26920 : itself. */
26921 29452 : gen_ptr_to_mbr_type_die (type, context_die);
26922 29452 : break;
26923 :
26924 392201 : case FUNCTION_TYPE:
26925 : /* Force out return type (in case it wasn't forced out already). */
26926 392201 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26927 : DINFO_USAGE_DIR_USE);
26928 392201 : gen_subroutine_type_die (type, context_die);
26929 392201 : break;
26930 :
26931 29004 : case METHOD_TYPE:
26932 : /* Force out return type (in case it wasn't forced out already). */
26933 29004 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26934 : DINFO_USAGE_DIR_USE);
26935 29004 : gen_subroutine_type_die (type, context_die);
26936 29004 : break;
26937 :
26938 1040231 : case ARRAY_TYPE:
26939 1040231 : case VECTOR_TYPE:
26940 1040231 : gen_array_type_die (type, context_die);
26941 1040231 : break;
26942 :
26943 136959441 : case ENUMERAL_TYPE:
26944 136959441 : case RECORD_TYPE:
26945 136959441 : case UNION_TYPE:
26946 136959441 : case QUAL_UNION_TYPE:
26947 136959441 : gen_tagged_type_die (type, context_die, usage, reverse);
26948 136959441 : return;
26949 :
26950 : case VOID_TYPE:
26951 : case OPAQUE_TYPE:
26952 : case INTEGER_TYPE:
26953 : case REAL_TYPE:
26954 : case FIXED_POINT_TYPE:
26955 : case COMPLEX_TYPE:
26956 : case BOOLEAN_TYPE:
26957 : case BITINT_TYPE:
26958 : /* No DIEs needed for fundamental types. */
26959 : break;
26960 :
26961 14334 : case NULLPTR_TYPE:
26962 14334 : case LANG_TYPE:
26963 14334 : unspecified_type:
26964 : /* Just use DW_TAG_unspecified_type. */
26965 14334 : {
26966 14334 : dw_die_ref type_die = lookup_type_die (type);
26967 14334 : if (type_die == NULL)
26968 : {
26969 14334 : tree name = TYPE_IDENTIFIER (type);
26970 14334 : type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
26971 : type);
26972 14334 : add_name_attribute (type_die, IDENTIFIER_POINTER (name));
26973 14334 : equate_type_number_to_die (type, type_die);
26974 : }
26975 : }
26976 : break;
26977 :
26978 147336 : default:
26979 147336 : if (is_cxx_auto (type))
26980 : {
26981 147330 : tree name = TYPE_IDENTIFIER (type);
26982 147330 : dw_die_ref *die = (name == get_identifier ("auto")
26983 147330 : ? &auto_die : &decltype_auto_die);
26984 147330 : if (!*die)
26985 : {
26986 17878 : *die = new_die (DW_TAG_unspecified_type,
26987 : comp_unit_die (), NULL_TREE);
26988 17878 : add_name_attribute (*die, IDENTIFIER_POINTER (name));
26989 : }
26990 147330 : equate_type_number_to_die (type, *die);
26991 147330 : break;
26992 : }
26993 6 : if (is_cxx ()
26994 6 : && TREE_CODE (type) >= LAST_AND_UNUSED_TREE_CODE
26995 6 : && TYPE_P (type)
26996 12 : && TYPE_IDENTIFIER (type))
26997 6 : goto unspecified_type;
26998 0 : gcc_unreachable ();
26999 : }
27000 :
27001 30945493 : TREE_ASM_WRITTEN (type) = 1;
27002 : }
27003 :
27004 : static void
27005 897596770 : gen_type_die (tree type, dw_die_ref context_die, bool reverse)
27006 : {
27007 897596770 : if (type != error_mark_node)
27008 : {
27009 897596755 : gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE, reverse);
27010 897596755 : if (flag_checking)
27011 : {
27012 897596732 : dw_die_ref die = lookup_type_die (type);
27013 897596732 : if (die)
27014 709440588 : check_die (die);
27015 : }
27016 : }
27017 897596770 : }
27018 :
27019 : /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
27020 : things which are local to the given block. */
27021 :
27022 : static void
27023 23046162 : gen_block_die (tree stmt, dw_die_ref context_die)
27024 : {
27025 23046162 : int must_output_die = 0;
27026 23046162 : bool inlined_func;
27027 :
27028 : /* Ignore blocks that are NULL. */
27029 23046162 : if (stmt == NULL_TREE)
27030 : return;
27031 :
27032 23046162 : inlined_func = inlined_function_outer_scope_p (stmt);
27033 :
27034 : /* If the block is one fragment of a non-contiguous block, do not
27035 : process the variables, since they will have been done by the
27036 : origin block. Do process subblocks. */
27037 23046162 : if (BLOCK_FRAGMENT_ORIGIN (stmt))
27038 : {
27039 10902734 : tree sub;
27040 :
27041 10902734 : for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
27042 0 : gen_block_die (sub, context_die);
27043 :
27044 : return;
27045 : }
27046 :
27047 : /* Determine if we need to output any Dwarf DIEs at all to represent this
27048 : block. */
27049 12143428 : if (inlined_func)
27050 : /* The outer scopes for inlinings *must* always be represented. We
27051 : generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
27052 : must_output_die = 1;
27053 5703591 : else if (lookup_block_die (stmt))
27054 : /* If we already have a DIE then it was filled early. Meanwhile
27055 : we might have pruned all BLOCK_VARS as optimized out but we
27056 : still want to generate high/low PC attributes so output it. */
27057 : must_output_die = 1;
27058 5443449 : else if (TREE_USED (stmt)
27059 8294 : || TREE_ASM_WRITTEN (stmt))
27060 : {
27061 : /* Determine if this block directly contains any "significant"
27062 : local declarations which we will need to output DIEs for. */
27063 5441574 : if (debug_info_level > DINFO_LEVEL_TERSE)
27064 : {
27065 : /* We are not in terse mode so any local declaration that
27066 : is not ignored for debug purposes counts as being a
27067 : "significant" one. */
27068 5356194 : if (BLOCK_NUM_NONLOCALIZED_VARS (stmt))
27069 : must_output_die = 1;
27070 : else
27071 5596467 : for (tree var = BLOCK_VARS (stmt); var; var = DECL_CHAIN (var))
27072 984994 : if (!DECL_IGNORED_P (var))
27073 : {
27074 : must_output_die = 1;
27075 : break;
27076 : }
27077 : }
27078 85380 : else if (!dwarf2out_ignore_block (stmt))
27079 : must_output_die = 1;
27080 : }
27081 :
27082 : /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
27083 : DIE for any block which contains no significant local declarations at
27084 : all. Rather, in such cases we just call `decls_for_scope' so that any
27085 : needed Dwarf info for any sub-blocks will get properly generated. Note
27086 : that in terse mode, our definition of what constitutes a "significant"
27087 : local declaration gets restricted to include only inlined function
27088 : instances and local (nested) function definitions. */
27089 5350164 : if (must_output_die)
27090 : {
27091 7444753 : if (inlined_func)
27092 6439837 : gen_inlined_subroutine_die (stmt, context_die);
27093 : else
27094 1004916 : gen_lexical_block_die (stmt, context_die);
27095 : }
27096 : else
27097 4698675 : decls_for_scope (stmt, context_die);
27098 : }
27099 :
27100 : /* Process variable DECL (or variable with origin ORIGIN) within
27101 : block STMT and add it to CONTEXT_DIE. */
27102 : static void
27103 17871672 : process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
27104 : {
27105 17871672 : dw_die_ref die;
27106 17871672 : tree decl_or_origin = decl ? decl : origin;
27107 :
27108 17871672 : if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
27109 15619 : die = lookup_decl_die (decl_or_origin);
27110 17856053 : else if (TREE_CODE (decl_or_origin) == TYPE_DECL)
27111 : {
27112 720453 : if (TYPE_DECL_IS_STUB (decl_or_origin))
27113 139032 : die = lookup_type_die (TREE_TYPE (decl_or_origin));
27114 : else
27115 581421 : die = lookup_decl_die (decl_or_origin);
27116 : /* Avoid re-creating the DIE late if it was optimized as unused early. */
27117 720453 : if (! die && ! early_dwarf)
27118 : return;
27119 : }
27120 : else
27121 : die = NULL;
27122 :
27123 : /* Avoid creating DIEs for local typedefs and concrete static variables that
27124 : will only be pruned later. */
27125 17385992 : if ((origin || decl_ultimate_origin (decl))
27126 30831510 : && (TREE_CODE (decl_or_origin) == TYPE_DECL
27127 13387860 : || (VAR_P (decl_or_origin) && TREE_STATIC (decl_or_origin))))
27128 : {
27129 115612 : origin = decl_ultimate_origin (decl_or_origin);
27130 115612 : if (decl && VAR_P (decl) && die != NULL)
27131 : {
27132 0 : die = lookup_decl_die (origin);
27133 0 : if (die != NULL)
27134 0 : equate_decl_number_to_die (decl, die);
27135 : }
27136 115612 : return;
27137 : }
27138 :
27139 17326315 : if (die != NULL && die->die_parent == NULL)
27140 7817 : add_child_die (context_die, die);
27141 :
27142 17326315 : if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
27143 : {
27144 12404 : if (early_dwarf)
27145 5800 : dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
27146 : stmt, context_die);
27147 : }
27148 : else
27149 : {
27150 17313911 : if (decl && DECL_P (decl))
27151 : {
27152 17313896 : die = lookup_decl_die (decl);
27153 :
27154 : /* Early created DIEs do not have a parent as the decls refer
27155 : to the function as DECL_CONTEXT rather than the BLOCK. */
27156 17313896 : if (die && die->die_parent == NULL)
27157 : {
27158 2907 : gcc_assert (in_lto_p);
27159 2907 : add_child_die (context_die, die);
27160 : }
27161 : }
27162 :
27163 17313911 : gen_decl_die (decl, origin, NULL, context_die);
27164 : }
27165 : }
27166 :
27167 : /* Generate all of the decls declared within a given scope and (recursively)
27168 : all of its sub-blocks. */
27169 :
27170 : static void
27171 17928250 : decls_for_scope (tree stmt, dw_die_ref context_die, bool recurse)
27172 : {
27173 17928250 : tree decl;
27174 17928250 : unsigned int i;
27175 17928250 : tree subblocks;
27176 :
27177 : /* Ignore NULL blocks. */
27178 17928250 : if (stmt == NULL_TREE)
27179 : return;
27180 :
27181 : /* Output the DIEs to represent all of the data objects and typedefs
27182 : declared directly within this block but not within any nested
27183 : sub-blocks. Also, nested function and tag DIEs have been
27184 : generated with a parent of NULL; fix that up now. We don't
27185 : have to do this if we're at -g1. */
27186 17928250 : if (debug_info_level > DINFO_LEVEL_TERSE)
27187 : {
27188 35627780 : for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
27189 17812190 : process_scope_var (stmt, decl, NULL_TREE, context_die);
27190 : /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
27191 : origin - avoid doing this twice as we have no good way to see
27192 : if we've done it once already. */
27193 17815590 : if (! early_dwarf)
27194 12485603 : for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
27195 : {
27196 59486 : decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
27197 59486 : if (decl == current_function_decl)
27198 : /* Ignore declarations of the current function, while they
27199 : are declarations, gen_subprogram_die would treat them
27200 : as definitions again, because they are equal to
27201 : current_function_decl and endlessly recurse. */;
27202 59482 : else if (TREE_CODE (decl) == FUNCTION_DECL)
27203 3547 : process_scope_var (stmt, decl, NULL_TREE, context_die);
27204 : else
27205 55935 : process_scope_var (stmt, NULL_TREE, decl, context_die);
27206 : }
27207 : }
27208 :
27209 : /* Even if we're at -g1, we need to process the subblocks in order to get
27210 : inlined call information. */
27211 :
27212 : /* Output the DIEs to represent all sub-blocks (and the items declared
27213 : therein) of this block. */
27214 17928250 : if (recurse)
27215 34715431 : for (subblocks = BLOCK_SUBBLOCKS (stmt);
27216 34715431 : subblocks != NULL;
27217 19902014 : subblocks = BLOCK_CHAIN (subblocks))
27218 19902014 : gen_block_die (subblocks, context_die);
27219 : }
27220 :
27221 : /* Is this a typedef we can avoid emitting? */
27222 :
27223 : static bool
27224 1450480294 : is_redundant_typedef (const_tree decl)
27225 : {
27226 1450480294 : if (TYPE_DECL_IS_STUB (decl))
27227 : return true;
27228 :
27229 474750820 : if (DECL_ARTIFICIAL (decl)
27230 300171859 : && DECL_CONTEXT (decl)
27231 99864227 : && is_tagged_type (DECL_CONTEXT (decl))
27232 99452775 : && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
27233 574203595 : && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
27234 : /* Also ignore the artificial member typedef for the class name. */
27235 99452707 : return true;
27236 :
27237 : return false;
27238 : }
27239 :
27240 : /* Return TRUE if TYPE is a typedef that names a type for linkage
27241 : purposes. This kind of typedefs is produced by the C++ FE for
27242 : constructs like:
27243 :
27244 : typedef struct {...} foo;
27245 :
27246 : In that case, there is no typedef variant type produced for foo.
27247 : Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
27248 : struct type. */
27249 :
27250 : static bool
27251 895298012 : is_naming_typedef_decl (const_tree decl)
27252 : {
27253 895298012 : if (decl == NULL_TREE
27254 742693969 : || TREE_CODE (decl) != TYPE_DECL
27255 742056165 : || DECL_NAMELESS (decl)
27256 742054701 : || !is_tagged_type (TREE_TYPE (decl))
27257 508945795 : || DECL_IS_UNDECLARED_BUILTIN (decl)
27258 508894026 : || is_redundant_typedef (decl)
27259 : /* It looks like Ada produces TYPE_DECLs that are very similar
27260 : to C++ naming typedefs but that have different
27261 : semantics. Let's be specific to c++ for now. */
27262 918858988 : || !is_cxx (decl))
27263 872201518 : return false;
27264 :
27265 23096494 : return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
27266 749587 : && TYPE_NAME (TREE_TYPE (decl)) == decl
27267 23846075 : && (TYPE_STUB_DECL (TREE_TYPE (decl))
27268 749581 : != TYPE_NAME (TREE_TYPE (decl))));
27269 : }
27270 :
27271 : /* Looks up the DIE for a context. */
27272 :
27273 : static inline dw_die_ref
27274 296524 : lookup_context_die (tree context)
27275 : {
27276 296524 : if (context)
27277 : {
27278 : /* Find die that represents this context. */
27279 71521 : if (TYPE_P (context))
27280 : {
27281 13 : context = TYPE_MAIN_VARIANT (context);
27282 13 : dw_die_ref ctx = lookup_type_die (context);
27283 13 : if (!ctx)
27284 : return NULL;
27285 12 : return strip_naming_typedef (context, ctx);
27286 : }
27287 : else
27288 71508 : return lookup_decl_die (context);
27289 : }
27290 225003 : return comp_unit_die ();
27291 : }
27292 :
27293 : /* Returns the DIE for a context. */
27294 :
27295 : static inline dw_die_ref
27296 86576057 : get_context_die (tree context)
27297 : {
27298 86576057 : if (context)
27299 : {
27300 : /* Find die that represents this context. */
27301 86464223 : if (TYPE_P (context))
27302 : {
27303 20587863 : context = TYPE_MAIN_VARIANT (context);
27304 20587863 : return strip_naming_typedef (context, force_type_die (context));
27305 : }
27306 : else
27307 65876360 : return force_decl_die (context);
27308 : }
27309 111834 : return comp_unit_die ();
27310 : }
27311 :
27312 : /* Returns the DIE for decl. A DIE will always be returned. */
27313 :
27314 : static dw_die_ref
27315 235957691 : force_decl_die (tree decl)
27316 : {
27317 235957691 : dw_die_ref decl_die;
27318 235957691 : unsigned saved_external_flag;
27319 235957691 : tree save_fn = NULL_TREE;
27320 235957691 : decl_die = lookup_decl_die (decl);
27321 235957691 : if (!decl_die)
27322 : {
27323 2770962 : dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
27324 :
27325 2770962 : decl_die = lookup_decl_die (decl);
27326 2770962 : if (decl_die)
27327 : return decl_die;
27328 :
27329 2770962 : switch (TREE_CODE (decl))
27330 : {
27331 2292452 : case FUNCTION_DECL:
27332 : /* Clear current_function_decl, so that gen_subprogram_die thinks
27333 : that this is a declaration. At this point, we just want to force
27334 : declaration die. */
27335 2292452 : save_fn = current_function_decl;
27336 2292452 : current_function_decl = NULL_TREE;
27337 2292452 : gen_subprogram_die (decl, context_die);
27338 2292452 : current_function_decl = save_fn;
27339 2292452 : break;
27340 :
27341 563 : case VAR_DECL:
27342 : /* Set external flag to force declaration die. Restore it after
27343 : gen_decl_die() call. */
27344 563 : saved_external_flag = DECL_EXTERNAL (decl);
27345 563 : DECL_EXTERNAL (decl) = 1;
27346 563 : gen_decl_die (decl, NULL, NULL, context_die);
27347 563 : DECL_EXTERNAL (decl) = saved_external_flag;
27348 563 : break;
27349 :
27350 477941 : case NAMESPACE_DECL:
27351 477941 : if (dwarf_version >= 3 || !dwarf_strict)
27352 477941 : dwarf2out_decl (decl);
27353 : else
27354 : /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
27355 0 : decl_die = comp_unit_die ();
27356 : break;
27357 :
27358 0 : case CONST_DECL:
27359 : /* Enumerators shouldn't need force_decl_die. */
27360 0 : gcc_assert (DECL_CONTEXT (decl) == NULL_TREE
27361 : || TREE_CODE (DECL_CONTEXT (decl)) != ENUMERAL_TYPE);
27362 0 : gen_decl_die (decl, NULL, NULL, context_die);
27363 0 : break;
27364 :
27365 6 : case TRANSLATION_UNIT_DECL:
27366 6 : decl_die = comp_unit_die ();
27367 6 : break;
27368 :
27369 0 : default:
27370 0 : gcc_unreachable ();
27371 : }
27372 :
27373 : /* We should be able to find the DIE now. */
27374 2770962 : if (!decl_die)
27375 2770956 : decl_die = lookup_decl_die (decl);
27376 2770956 : gcc_assert (decl_die);
27377 : }
27378 :
27379 : return decl_die;
27380 : }
27381 :
27382 : /* Returns the DIE for TYPE, that must not be a base type. A DIE is
27383 : always returned. */
27384 :
27385 : static dw_die_ref
27386 21184047 : force_type_die (tree type)
27387 : {
27388 21184047 : dw_die_ref type_die;
27389 :
27390 21184047 : type_die = lookup_type_die (type);
27391 21184047 : if (!type_die)
27392 : {
27393 496022 : dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
27394 :
27395 496022 : type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
27396 496022 : TYPE_ATTRIBUTES (type),
27397 : false, context_die);
27398 496022 : gcc_assert (type_die);
27399 : }
27400 21184047 : return type_die;
27401 : }
27402 :
27403 : /* Force out any required namespaces to be able to output DECL,
27404 : and return the new context_die for it, if it's changed. */
27405 :
27406 : static dw_die_ref
27407 293675188 : setup_namespace_context (tree thing, dw_die_ref context_die)
27408 : {
27409 293675188 : tree context = (DECL_P (thing)
27410 293675188 : ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
27411 293675188 : if (context && TREE_CODE (context) == NAMESPACE_DECL)
27412 : /* Force out the namespace. */
27413 167758232 : context_die = force_decl_die (context);
27414 :
27415 293675188 : return context_die;
27416 : }
27417 :
27418 : /* Emit a declaration DIE for THING (which is either a DECL or a tagged
27419 : type) within its namespace, if appropriate.
27420 :
27421 : For compatibility with older debuggers, namespace DIEs only contain
27422 : declarations; all definitions are emitted at CU scope, with
27423 : DW_AT_specification pointing to the declaration (like with class
27424 : members). */
27425 :
27426 : static dw_die_ref
27427 293252282 : declare_in_namespace (tree thing, dw_die_ref context_die)
27428 : {
27429 293252282 : dw_die_ref ns_context;
27430 :
27431 293252282 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27432 : return context_die;
27433 :
27434 : /* External declarations in the local scope only need to be emitted
27435 : once, not once in the namespace and once in the scope.
27436 :
27437 : This avoids declaring the `extern' below in the
27438 : namespace DIE as well as in the innermost scope:
27439 :
27440 : namespace S
27441 : {
27442 : int i=5;
27443 : int foo()
27444 : {
27445 : int i=8;
27446 : extern int i;
27447 : return i;
27448 : }
27449 : }
27450 : */
27451 389356856 : if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
27452 : return context_die;
27453 :
27454 : /* If this decl is from an inlined function, then don't try to emit it in its
27455 : namespace, as we will get confused. It would have already been emitted
27456 : when the abstract instance of the inline function was emitted anyways. */
27457 293205487 : if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
27458 : return context_die;
27459 :
27460 293186470 : ns_context = setup_namespace_context (thing, context_die);
27461 :
27462 293186470 : if (ns_context != context_die)
27463 : {
27464 83390583 : if (is_fortran () || is_dlang ())
27465 13786 : return ns_context;
27466 83376797 : if (DECL_P (thing))
27467 19176719 : gen_decl_die (thing, NULL, NULL, ns_context);
27468 : else
27469 64200078 : gen_type_die (thing, ns_context);
27470 : }
27471 : return context_die;
27472 : }
27473 :
27474 : /* Generate a DIE for a namespace or namespace alias. */
27475 :
27476 : static void
27477 488759 : gen_namespace_die (tree decl, dw_die_ref context_die)
27478 : {
27479 488759 : dw_die_ref namespace_die;
27480 :
27481 : /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
27482 : they are an alias of. */
27483 488759 : if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
27484 : {
27485 : /* Output a real namespace or module. */
27486 477941 : context_die = setup_namespace_context (decl, comp_unit_die ());
27487 479520 : namespace_die = new_die (is_fortran () || is_dlang () || is_ada ()
27488 : ? DW_TAG_module : DW_TAG_namespace,
27489 : context_die, decl);
27490 : /* For Fortran modules defined in different CU don't add src coords. */
27491 477941 : if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
27492 : {
27493 184 : const char *name = dwarf2_name (decl, 0);
27494 184 : if (name)
27495 184 : add_name_attribute (namespace_die, name);
27496 : }
27497 : else
27498 477757 : add_name_and_src_coords_attributes (namespace_die, decl);
27499 477941 : if (DECL_EXTERNAL (decl))
27500 184 : add_AT_flag (namespace_die, DW_AT_declaration, 1);
27501 477941 : equate_decl_number_to_die (decl, namespace_die);
27502 : }
27503 : else
27504 : {
27505 : /* Output a namespace alias. */
27506 :
27507 : /* Force out the namespace we are an alias of, if necessary. */
27508 10818 : dw_die_ref origin_die
27509 10818 : = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
27510 :
27511 21636 : if (DECL_FILE_SCOPE_P (decl)
27512 19865 : || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
27513 10777 : context_die = setup_namespace_context (decl, comp_unit_die ());
27514 : /* Now create the namespace alias DIE. */
27515 10818 : namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
27516 10818 : add_name_and_src_coords_attributes (namespace_die, decl);
27517 10818 : add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
27518 10818 : equate_decl_number_to_die (decl, namespace_die);
27519 : }
27520 313 : if ((dwarf_version >= 5 || !dwarf_strict)
27521 489072 : && lang_hooks.decls.decl_dwarf_attribute (decl,
27522 : DW_AT_export_symbols) == 1)
27523 106965 : add_AT_flag (namespace_die, DW_AT_export_symbols, 1);
27524 :
27525 : /* Bypass dwarf2_name's check for DECL_NAMELESS. */
27526 488759 : if (want_pubnames ())
27527 33 : add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
27528 488759 : }
27529 :
27530 : /* Generate Dwarf debug information for a decl described by DECL.
27531 : The return value is currently only meaningful for PARM_DECLs,
27532 : for all other decls it returns NULL.
27533 :
27534 : If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
27535 : It can be NULL otherwise. */
27536 :
27537 : static dw_die_ref
27538 421287325 : gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
27539 : dw_die_ref context_die)
27540 : {
27541 421287325 : tree decl_or_origin = decl ? decl : origin;
27542 421287325 : tree class_origin = NULL, ultimate_origin;
27543 :
27544 421287325 : if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
27545 : return NULL;
27546 :
27547 363098747 : switch (TREE_CODE (decl_or_origin))
27548 : {
27549 : case ERROR_MARK:
27550 : break;
27551 :
27552 374033 : case CONST_DECL:
27553 374033 : if (!is_fortran () && !is_ada () && !is_dlang ())
27554 : {
27555 : /* The individual enumerators of an enum type get output when we output
27556 : the Dwarf representation of the relevant enum type itself. */
27557 : break;
27558 : }
27559 :
27560 : /* Emit its type. */
27561 26061 : gen_type_die (TREE_TYPE (decl), context_die);
27562 :
27563 : /* And its containing namespace. */
27564 26061 : context_die = declare_in_namespace (decl, context_die);
27565 :
27566 26061 : gen_const_die (decl, context_die);
27567 26061 : break;
27568 :
27569 96105882 : case FUNCTION_DECL:
27570 : #if 0
27571 : /* FIXME */
27572 : /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
27573 : on local redeclarations of global functions. That seems broken. */
27574 : if (current_function_decl != decl)
27575 : /* This is only a declaration. */;
27576 : #endif
27577 :
27578 : /* We should have abstract copies already and should not generate
27579 : stray type DIEs in late LTO dumping. */
27580 96105882 : if (! early_dwarf)
27581 : ;
27582 :
27583 : /* If we're emitting a clone, emit info for the abstract instance. */
27584 95869929 : else if (origin || DECL_ORIGIN (decl) != decl)
27585 657896 : dwarf2out_abstract_function (origin
27586 0 : ? DECL_ORIGIN (origin)
27587 328948 : : DECL_ABSTRACT_ORIGIN (decl));
27588 :
27589 : /* If we're emitting a possibly inlined function emit it as
27590 : abstract instance. */
27591 95208717 : else if (cgraph_function_possibly_inlined_p (decl)
27592 92672578 : && ! DECL_ABSTRACT_P (decl)
27593 73564792 : && ! class_or_namespace_scope_p (context_die)
27594 : /* dwarf2out_abstract_function won't emit a die if this is just
27595 : a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
27596 : that case, because that works only if we have a die. */
27597 95208717 : && DECL_INITIAL (decl) != NULL_TREE)
27598 0 : dwarf2out_abstract_function (decl);
27599 :
27600 : /* Otherwise we're emitting the primary DIE for this decl. */
27601 95208717 : else if (debug_info_level > DINFO_LEVEL_TERSE)
27602 : {
27603 : /* Before we describe the FUNCTION_DECL itself, make sure that we
27604 : have its containing type. */
27605 95194942 : if (!origin)
27606 95194942 : origin = decl_class_context (decl);
27607 95194942 : if (origin != NULL_TREE)
27608 93980332 : gen_type_die (origin, context_die);
27609 :
27610 : /* And its return type. */
27611 95194942 : gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
27612 :
27613 : /* And its virtual context. */
27614 95194942 : if (DECL_VINDEX (decl) != NULL_TREE)
27615 1184785 : gen_type_die (DECL_CONTEXT (decl), context_die);
27616 :
27617 : /* Make sure we have a member DIE for decl. */
27618 95194942 : if (origin != NULL_TREE)
27619 93980332 : gen_type_die_for_member (origin, decl, context_die);
27620 :
27621 : /* And its containing namespace. */
27622 95194942 : context_die = declare_in_namespace (decl, context_die);
27623 : }
27624 :
27625 : /* Now output a DIE to represent the function itself. */
27626 96105882 : if (decl)
27627 96105882 : gen_subprogram_die (decl, context_die);
27628 : break;
27629 :
27630 165541369 : case TYPE_DECL:
27631 : /* If we are in terse mode, don't generate any DIEs to represent any
27632 : actual typedefs. */
27633 165541369 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27634 : break;
27635 :
27636 : /* In the special case of a TYPE_DECL node representing the declaration
27637 : of some type tag, if the given TYPE_DECL is marked as having been
27638 : instantiated from some other (original) TYPE_DECL node (e.g. one which
27639 : was generated within the original definition of an inline function) we
27640 : used to generate a special (abbreviated) DW_TAG_structure_type,
27641 : DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
27642 : should be actually referencing those DIEs, as variable DIEs with that
27643 : type would be emitted already in the abstract origin, so it was always
27644 : removed during unused type pruning. Don't add anything in this
27645 : case. */
27646 165541369 : if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
27647 : break;
27648 :
27649 165541369 : if (is_redundant_typedef (decl))
27650 103519113 : gen_type_die (TREE_TYPE (decl), context_die);
27651 : else
27652 : /* Output a DIE to represent the typedef itself. */
27653 62022256 : gen_typedef_die (decl, context_die);
27654 : break;
27655 :
27656 119025 : case LABEL_DECL:
27657 119025 : if (debug_info_level >= DINFO_LEVEL_NORMAL)
27658 119025 : gen_label_die (decl, context_die);
27659 : break;
27660 :
27661 78269736 : case VAR_DECL:
27662 78269736 : case RESULT_DECL:
27663 : /* If we are in terse mode, don't generate any DIEs to represent any
27664 : variable declarations or definitions unless it is external. */
27665 78269736 : if (debug_info_level < DINFO_LEVEL_TERSE
27666 78269736 : || (debug_info_level == DINFO_LEVEL_TERSE
27667 1218 : && !TREE_PUBLIC (decl_or_origin)))
27668 : break;
27669 :
27670 78269736 : if (debug_info_level > DINFO_LEVEL_TERSE)
27671 : {
27672 : /* Avoid generating stray type DIEs during late dwarf dumping.
27673 : All types have been dumped early. */
27674 78268518 : if (early_dwarf
27675 : /* ??? But in LTRANS we cannot annotate early created variably
27676 : modified type DIEs without copying them and adjusting all
27677 : references to them. Dump them again as happens for inlining
27678 : which copies both the decl and the types. */
27679 : /* ??? And even non-LTO needs to re-visit type DIEs to fill
27680 : in VLA bound information for example. */
27681 78268518 : || (decl && variably_modified_type_p (TREE_TYPE (decl),
27682 : current_function_decl)))
27683 : {
27684 : /* Output any DIEs that are needed to specify the type of this data
27685 : object. */
27686 63797132 : if (decl_by_reference_p (decl_or_origin))
27687 3235 : gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
27688 : else
27689 63793897 : gen_type_die (TREE_TYPE (decl_or_origin), context_die);
27690 : }
27691 :
27692 78268518 : if (early_dwarf)
27693 : {
27694 : /* And its containing type. */
27695 63791353 : class_origin = decl_class_context (decl_or_origin);
27696 63791353 : if (class_origin != NULL_TREE)
27697 23529630 : gen_type_die_for_member (class_origin, decl_or_origin, context_die);
27698 :
27699 : /* And its containing namespace. */
27700 63791353 : context_die = declare_in_namespace (decl_or_origin, context_die);
27701 : }
27702 : }
27703 :
27704 : /* Now output the DIE to represent the data object itself. This gets
27705 : complicated because of the possibility that the VAR_DECL really
27706 : represents an inlined instance of a formal parameter for an inline
27707 : function. */
27708 78269736 : ultimate_origin = decl_ultimate_origin (decl_or_origin);
27709 78269736 : if (ultimate_origin != NULL_TREE
27710 13296678 : && TREE_CODE (ultimate_origin) == PARM_DECL)
27711 11818626 : gen_formal_parameter_die (decl, origin,
27712 : true /* Emit name attribute. */,
27713 : context_die);
27714 : else
27715 66451110 : gen_variable_die (decl, origin, context_die);
27716 : break;
27717 :
27718 17056012 : case FIELD_DECL:
27719 17056012 : gcc_assert (ctx != NULL && ctx->struct_type != NULL);
27720 : /* Ignore the nameless fields that are used to skip bits but handle C++
27721 : anonymous unions and structs. */
27722 17056012 : if (DECL_NAME (decl) != NULL_TREE
27723 322516 : || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
27724 17223605 : || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
27725 : {
27726 16925359 : gen_type_die (member_declared_type (decl), context_die);
27727 16925359 : gen_field_die (decl, ctx, context_die);
27728 : }
27729 : break;
27730 :
27731 4854979 : case PARM_DECL:
27732 : /* Avoid generating stray type DIEs during late dwarf dumping.
27733 : All types have been dumped early. */
27734 4854979 : if (early_dwarf
27735 : /* ??? But in LTRANS we cannot annotate early created variably
27736 : modified type DIEs without copying them and adjusting all
27737 : references to them. Dump them again as happens for inlining
27738 : which copies both the decl and the types. */
27739 : /* ??? And even non-LTO needs to re-visit type DIEs to fill
27740 : in VLA bound information for example. */
27741 4854979 : || (decl && variably_modified_type_p (TREE_TYPE (decl),
27742 : current_function_decl)))
27743 : {
27744 3848464 : if (DECL_BY_REFERENCE (decl_or_origin))
27745 42118 : gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
27746 : else
27747 3806346 : gen_type_die (TREE_TYPE (decl_or_origin), context_die);
27748 : }
27749 4854979 : return gen_formal_parameter_die (decl, origin,
27750 : true /* Emit name attribute. */,
27751 4854979 : context_die);
27752 :
27753 488759 : case NAMESPACE_DECL:
27754 488759 : if (dwarf_version >= 3 || !dwarf_strict)
27755 488759 : gen_namespace_die (decl, context_die);
27756 : break;
27757 :
27758 0 : case IMPORTED_DECL:
27759 0 : dwarf2out_imported_module_or_decl_1 (decl, DECL_NAME (decl),
27760 0 : DECL_CONTEXT (decl), context_die);
27761 0 : break;
27762 :
27763 245 : case NAMELIST_DECL:
27764 245 : gen_namelist_decl (DECL_NAME (decl), context_die,
27765 245 : NAMELIST_DECL_ASSOCIATED_DECL (decl));
27766 245 : break;
27767 :
27768 288707 : default:
27769 : /* Probably some frontend-internal decl. Assume we don't care. */
27770 288707 : gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
27771 : break;
27772 : }
27773 :
27774 358243768 : maybe_gen_btf_decl_tag_dies (decl_or_origin,
27775 : lookup_decl_die (decl_or_origin));
27776 :
27777 358243768 : return NULL;
27778 : }
27779 :
27780 : /* Output initial debug information for global DECL. Called at the
27781 : end of the parsing process.
27782 :
27783 : This is the initial debug generation process. As such, the DIEs
27784 : generated may be incomplete. A later debug generation pass
27785 : (dwarf2out_late_global_decl) will augment the information generated
27786 : in this pass (e.g., with complete location info). */
27787 :
27788 : static void
27789 41371286 : dwarf2out_early_global_decl (tree decl)
27790 : {
27791 41371286 : set_early_dwarf s;
27792 :
27793 : /* gen_decl_die() will set DECL_ABSTRACT because
27794 : cgraph_function_possibly_inlined_p() returns true. This is in
27795 : turn will cause DW_AT_inline attributes to be set.
27796 :
27797 : This happens because at early dwarf generation, there is no
27798 : cgraph information, causing cgraph_function_possibly_inlined_p()
27799 : to return true. Trick cgraph_function_possibly_inlined_p()
27800 : while we generate dwarf early. */
27801 41371286 : bool save = symtab->global_info_ready;
27802 41371286 : symtab->global_info_ready = true;
27803 :
27804 : /* We don't handle TYPE_DECLs. If required, they'll be reached via
27805 : other DECLs and they can point to template types or other things
27806 : that dwarf2out can't handle when done via dwarf2out_decl. */
27807 41371286 : if (TREE_CODE (decl) != TYPE_DECL
27808 41371286 : && TREE_CODE (decl) != PARM_DECL)
27809 : {
27810 34465712 : if (TREE_CODE (decl) == FUNCTION_DECL)
27811 : {
27812 2113982 : tree save_fndecl = current_function_decl;
27813 :
27814 : /* For nested functions, make sure we have DIEs for the parents first
27815 : so that all nested DIEs are generated at the proper scope in the
27816 : first shot. */
27817 2113982 : tree context = decl_function_context (decl);
27818 2113982 : if (context != NULL)
27819 : {
27820 43248 : dw_die_ref context_die = lookup_decl_die (context);
27821 43248 : current_function_decl = context;
27822 :
27823 : /* Avoid emitting DIEs multiple times, but still process CONTEXT
27824 : enough so that it lands in its own context. This avoids type
27825 : pruning issues later on. */
27826 43248 : if (context_die == NULL || is_declaration_die (context_die))
27827 3288 : dwarf2out_early_global_decl (context);
27828 : }
27829 :
27830 : /* Emit an abstract origin of a function first. This happens
27831 : with C++ constructor clones for example and makes
27832 : dwarf2out_abstract_function happy which requires the early
27833 : DIE of the abstract instance to be present. */
27834 2113982 : tree origin = DECL_ABSTRACT_ORIGIN (decl);
27835 2113982 : dw_die_ref origin_die;
27836 2113982 : if (origin != NULL
27837 : /* Do not emit the DIE multiple times but make sure to
27838 : process it fully here in case we just saw a declaration. */
27839 2113982 : && ((origin_die = lookup_decl_die (origin)) == NULL
27840 226316 : || is_declaration_die (origin_die)))
27841 : {
27842 314452 : current_function_decl = origin;
27843 314452 : dwarf2out_decl (origin);
27844 : }
27845 :
27846 : /* Emit the DIE for decl but avoid doing that multiple times. */
27847 2113982 : dw_die_ref old_die;
27848 2113982 : if ((old_die = lookup_decl_die (decl)) == NULL
27849 2113982 : || is_declaration_die (old_die))
27850 : {
27851 2109737 : current_function_decl = decl;
27852 2109737 : dwarf2out_decl (decl);
27853 : }
27854 :
27855 2113982 : current_function_decl = save_fndecl;
27856 : }
27857 : else
27858 32351730 : dwarf2out_decl (decl);
27859 : }
27860 41371286 : symtab->global_info_ready = save;
27861 41371286 : }
27862 :
27863 : /* Return whether EXPR is an expression with the following pattern:
27864 : INDIRECT_REF (NOP_EXPR (INTEGER_CST)). */
27865 :
27866 : static bool
27867 52 : is_trivial_indirect_ref (tree expr)
27868 : {
27869 52 : if (expr == NULL_TREE || TREE_CODE (expr) != INDIRECT_REF)
27870 : return false;
27871 :
27872 0 : tree nop = TREE_OPERAND (expr, 0);
27873 0 : if (nop == NULL_TREE || TREE_CODE (nop) != NOP_EXPR)
27874 : return false;
27875 :
27876 0 : tree int_cst = TREE_OPERAND (nop, 0);
27877 0 : return int_cst != NULL_TREE && TREE_CODE (int_cst) == INTEGER_CST;
27878 : }
27879 :
27880 : /* Output debug information for global decl DECL. Called from
27881 : toplev.cc after compilation proper has finished. */
27882 :
27883 : static void
27884 35783725 : dwarf2out_late_global_decl (tree decl)
27885 : {
27886 : /* Fill-in any location information we were unable to determine
27887 : on the first pass. */
27888 35783725 : if (VAR_P (decl))
27889 : {
27890 35783725 : dw_die_ref die = lookup_decl_die (decl);
27891 :
27892 : /* We may have to generate full debug late for LTO in case debug
27893 : was not enabled at compile-time or the target doesn't support
27894 : the LTO early debug scheme. */
27895 5299503 : if (! die && in_lto_p
27896 : /* Function scope variables are emitted when emitting the
27897 : DIE for the function. */
27898 35785403 : && ! local_function_static (decl))
27899 1653 : dwarf2out_decl (decl);
27900 35782072 : else if (die)
27901 : {
27902 : /* We get called via the symtab code invoking late_global_decl
27903 : for symbols that are optimized out.
27904 :
27905 : Do not add locations for those, except if they have a
27906 : DECL_VALUE_EXPR, in which case they are relevant for debuggers.
27907 : Still don't add a location if the DECL_VALUE_EXPR is not a trivial
27908 : INDIRECT_REF expression, as this could generate relocations to
27909 : text symbols in LTO object files, which is invalid. */
27910 30484222 : varpool_node *node = varpool_node::get (decl);
27911 30484222 : if ((! node || ! node->definition)
27912 60726974 : && ! (DECL_HAS_VALUE_EXPR_P (decl)
27913 52 : && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl))))
27914 30242700 : tree_add_const_value_attribute_for_decl (die, decl);
27915 : else
27916 : {
27917 241522 : add_location_or_const_value_attribute (die, decl, false);
27918 : /* For C++ structured bindings at namespace scope when processing
27919 : the underlying variable also add locations on the structured
27920 : bindings which refer to it (unless they are tuple-based, then
27921 : they are separate VAR_DECLs registered in varpool). */
27922 241522 : if (tree attr = lookup_attribute ("structured bindings",
27923 241522 : DECL_ATTRIBUTES (decl)))
27924 183 : for (tree d = TREE_VALUE (attr); d; d = TREE_CHAIN (d))
27925 : {
27926 141 : die = lookup_decl_die (TREE_VALUE (d));
27927 141 : if (die)
27928 141 : add_location_or_const_value_attribute (die,
27929 141 : TREE_VALUE (d),
27930 : false);
27931 : }
27932 : }
27933 : }
27934 : }
27935 35783725 : }
27936 :
27937 : /* Output debug information for type decl DECL. Called from toplev.cc
27938 : and from language front ends (to record built-in types). */
27939 : static void
27940 67820898 : dwarf2out_type_decl (tree decl, int local)
27941 : {
27942 67820898 : if (!local)
27943 : {
27944 59626721 : set_early_dwarf s;
27945 59626721 : dwarf2out_decl (decl);
27946 59626721 : }
27947 67820898 : }
27948 :
27949 : /* Output debug information for imported module or decl DECL.
27950 : NAME is non-NULL name in the lexical block if the decl has been renamed.
27951 : LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
27952 : that DECL belongs to.
27953 : LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
27954 : static void
27955 5898098 : dwarf2out_imported_module_or_decl_1 (tree decl,
27956 : tree name,
27957 : tree lexical_block,
27958 : dw_die_ref lexical_block_die)
27959 : {
27960 5898098 : expanded_location xloc;
27961 5898098 : dw_die_ref imported_die = NULL;
27962 5898098 : dw_die_ref at_import_die;
27963 :
27964 5898098 : if (TREE_CODE (decl) == IMPORTED_DECL)
27965 : {
27966 5800 : xloc = expand_location (DECL_SOURCE_LOCATION (decl));
27967 5800 : decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
27968 5800 : gcc_assert (decl);
27969 : }
27970 : else
27971 5892298 : xloc = expand_location (input_location);
27972 :
27973 5898098 : if (TREE_CODE (decl) == TYPE_DECL)
27974 : {
27975 596184 : at_import_die = force_type_die (TREE_TYPE (decl));
27976 : /* For namespace N { typedef void T; } using N::T; base_type_die
27977 : returns NULL, but DW_TAG_imported_declaration requires
27978 : the DW_AT_import tag. Force creation of DW_TAG_typedef. */
27979 596184 : if (!at_import_die)
27980 : {
27981 0 : gcc_assert (TREE_CODE (decl) == TYPE_DECL);
27982 0 : gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
27983 0 : at_import_die = lookup_type_die (TREE_TYPE (decl));
27984 0 : gcc_assert (at_import_die);
27985 : }
27986 : }
27987 : else
27988 : {
27989 5301914 : at_import_die = lookup_decl_die (decl);
27990 5301914 : if (!at_import_die)
27991 : {
27992 : /* If we're trying to avoid duplicate debug info, we may not have
27993 : emitted the member decl for this field. Emit it now. */
27994 2081546 : if (TREE_CODE (decl) == FIELD_DECL)
27995 : {
27996 6 : tree type = DECL_CONTEXT (decl);
27997 :
27998 6 : if (TYPE_CONTEXT (type)
27999 6 : && TYPE_P (TYPE_CONTEXT (type))
28000 6 : && !should_emit_struct_debug (TYPE_CONTEXT (type),
28001 : DINFO_USAGE_DIR_USE))
28002 2 : return;
28003 6 : gen_type_die_for_member (type, decl,
28004 6 : get_context_die (TYPE_CONTEXT (type)));
28005 : }
28006 2081546 : if (TREE_CODE (decl) == CONST_DECL)
28007 : {
28008 : /* Individual enumerators of an enum type do not get output here
28009 : (see gen_decl_die), so we cannot call force_decl_die. */
28010 2 : if (!is_fortran () && !is_ada () && !is_dlang ())
28011 : return;
28012 : }
28013 2081544 : if (TREE_CODE (decl) == NAMELIST_DECL)
28014 4 : at_import_die = gen_namelist_decl (DECL_NAME (decl),
28015 4 : get_context_die (DECL_CONTEXT (decl)),
28016 : NULL_TREE);
28017 : else
28018 2081540 : at_import_die = force_decl_die (decl);
28019 : }
28020 : }
28021 :
28022 5898096 : if (TREE_CODE (decl) == NAMESPACE_DECL)
28023 : {
28024 33848 : if (dwarf_version >= 3 || !dwarf_strict)
28025 33848 : imported_die = new_die (DW_TAG_imported_module,
28026 : lexical_block_die,
28027 : lexical_block);
28028 : else
28029 : return;
28030 : }
28031 : else
28032 5864248 : imported_die = new_die (DW_TAG_imported_declaration,
28033 : lexical_block_die,
28034 : lexical_block);
28035 :
28036 5898096 : add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
28037 5898096 : add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
28038 5898096 : if (debug_column_info && xloc.column)
28039 5898096 : add_AT_unsigned (imported_die, DW_AT_decl_column, xloc.column);
28040 5898096 : if (name)
28041 29 : add_AT_string (imported_die, DW_AT_name,
28042 29 : IDENTIFIER_POINTER (name));
28043 5898096 : add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
28044 : }
28045 :
28046 : /* Output debug information for imported module or decl DECL.
28047 : NAME is non-NULL name in context if the decl has been renamed.
28048 : CHILD is true if decl is one of the renamed decls as part of
28049 : importing whole module.
28050 : IMPLICIT is set if this hook is called for an implicit import
28051 : such as inline namespace. */
28052 :
28053 : static void
28054 6043333 : dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
28055 : bool child, bool implicit)
28056 : {
28057 : /* dw_die_ref at_import_die; */
28058 6043333 : dw_die_ref scope_die;
28059 :
28060 6043333 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28061 151035 : return;
28062 :
28063 6043258 : gcc_assert (decl);
28064 :
28065 : /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
28066 : should be enough, for DWARF4 and older even if we emit as extension
28067 : DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
28068 : for the benefit of consumers unaware of DW_AT_export_symbols. */
28069 6043258 : if (implicit
28070 151035 : && dwarf_version >= 5
28071 6194218 : && lang_hooks.decls.decl_dwarf_attribute (decl,
28072 : DW_AT_export_symbols) == 1)
28073 : return;
28074 :
28075 5892298 : set_early_dwarf s;
28076 :
28077 : /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
28078 : We need decl DIE for reference and scope die. First, get DIE for the decl
28079 : itself. */
28080 :
28081 : /* Get the scope die for decl context. Use comp_unit_die for global module
28082 : or decl. If die is not found for non globals, force new die. */
28083 5892298 : if (context
28084 5782340 : && TYPE_P (context)
28085 8434880 : && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
28086 : return;
28087 :
28088 5892298 : scope_die = get_context_die (context);
28089 :
28090 5892298 : if (child)
28091 : {
28092 : /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
28093 : there is nothing we can do, here. */
28094 13 : if (dwarf_version < 3 && dwarf_strict)
28095 : return;
28096 :
28097 13 : gcc_assert (scope_die->die_child);
28098 13 : gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
28099 13 : gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
28100 : scope_die = scope_die->die_child;
28101 : }
28102 :
28103 : /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
28104 5892298 : dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
28105 5892298 : }
28106 :
28107 : /* Output debug information for namelists. */
28108 :
28109 : static dw_die_ref
28110 249 : gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
28111 : {
28112 249 : dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
28113 249 : tree value;
28114 249 : unsigned i;
28115 :
28116 249 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28117 : return NULL;
28118 :
28119 249 : gcc_assert (scope_die != NULL);
28120 249 : nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
28121 249 : add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
28122 :
28123 : /* If there are no item_decls, we have a nondefining namelist, e.g.
28124 : with USE association; hence, set DW_AT_declaration. */
28125 249 : if (item_decls == NULL_TREE)
28126 : {
28127 4 : add_AT_flag (nml_die, DW_AT_declaration, 1);
28128 4 : return nml_die;
28129 : }
28130 :
28131 906 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
28132 : {
28133 661 : nml_item_ref_die = lookup_decl_die (value);
28134 661 : if (!nml_item_ref_die)
28135 258 : nml_item_ref_die = force_decl_die (value);
28136 :
28137 661 : nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
28138 661 : add_AT_die_ref (nml_item_die, DW_AT_namelist_item, nml_item_ref_die);
28139 : }
28140 : return nml_die;
28141 : }
28142 :
28143 :
28144 : /* Write the debugging output for DECL and return the DIE. */
28145 :
28146 : static void
28147 95442443 : dwarf2out_decl (tree decl)
28148 : {
28149 95442443 : dw_die_ref context_die = comp_unit_die ();
28150 :
28151 95442443 : switch (TREE_CODE (decl))
28152 : {
28153 : case ERROR_MARK:
28154 : return;
28155 :
28156 2984398 : case FUNCTION_DECL:
28157 : /* If we're a nested function, initially use a parent of NULL; if we're
28158 : a plain function, this will be fixed up in decls_for_scope. If
28159 : we're a method, it will be ignored, since we already have a DIE.
28160 : Avoid doing this late though since clones of class methods may
28161 : otherwise end up in limbo and create type DIEs late. */
28162 2984398 : if (early_dwarf
28163 2424189 : && decl_function_context (decl)
28164 : /* But if we're in terse mode, we don't care about scope. */
28165 3036631 : && debug_info_level > DINFO_LEVEL_TERSE)
28166 : context_die = NULL;
28167 : break;
28168 :
28169 32339343 : case VAR_DECL:
28170 : /* For local statics lookup proper context die. */
28171 32339343 : if (local_function_static (decl))
28172 34 : context_die = lookup_decl_die (DECL_CONTEXT (decl));
28173 :
28174 : /* If we are in terse mode, don't generate any DIEs to represent any
28175 : variable declarations or definitions unless it is external. */
28176 32339343 : if (debug_info_level < DINFO_LEVEL_TERSE
28177 32339338 : || (debug_info_level == DINFO_LEVEL_TERSE
28178 2414 : && !TREE_PUBLIC (decl)))
28179 : return;
28180 : break;
28181 :
28182 3243 : case CONST_DECL:
28183 3243 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28184 : return;
28185 3243 : if (!is_fortran () && !is_ada () && !is_dlang ())
28186 : return;
28187 3243 : if (TREE_STATIC (decl) && decl_function_context (decl))
28188 2886 : context_die = lookup_decl_die (DECL_CONTEXT (decl));
28189 : break;
28190 :
28191 488722 : case NAMESPACE_DECL:
28192 488722 : case IMPORTED_DECL:
28193 488722 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28194 : return;
28195 488719 : if (lookup_decl_die (decl) != NULL)
28196 : return;
28197 : break;
28198 :
28199 59626721 : case TYPE_DECL:
28200 : /* Don't emit stubs for types unless they are needed by other DIEs. */
28201 59626721 : if (TYPE_DECL_SUPPRESS_DEBUG (decl))
28202 : return;
28203 :
28204 : /* Don't bother trying to generate any DIEs to represent any of the
28205 : normal built-in types for the language we are compiling. */
28206 57921429 : if (DECL_IS_UNDECLARED_BUILTIN (decl))
28207 : return;
28208 :
28209 : /* If we are in terse mode, don't generate any DIEs for types. */
28210 56174776 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28211 : return;
28212 :
28213 : /* If we're a function-scope tag, initially use a parent of NULL;
28214 : this will be fixed up in decls_for_scope. */
28215 56174173 : if (decl_function_context (decl))
28216 52321 : context_die = NULL;
28217 :
28218 : break;
28219 :
28220 : case NAMELIST_DECL:
28221 : break;
28222 :
28223 : default:
28224 : return;
28225 : }
28226 :
28227 91988864 : gen_decl_die (decl, NULL, NULL, context_die);
28228 :
28229 91988864 : if (flag_checking)
28230 : {
28231 91988842 : dw_die_ref die = lookup_decl_die (decl);
28232 91988842 : if (die)
28233 32744418 : check_die (die);
28234 : }
28235 : }
28236 :
28237 : /* Write the debugging output for DECL. */
28238 :
28239 : static void
28240 560209 : dwarf2out_function_decl (tree decl)
28241 : {
28242 560209 : dwarf2out_decl (decl);
28243 560209 : call_arg_locations = NULL;
28244 560209 : call_arg_loc_last = NULL;
28245 560209 : call_site_count = -1;
28246 560209 : tail_call_site_count = -1;
28247 560209 : decl_loc_table->empty ();
28248 560209 : cached_dw_loc_list_table->empty ();
28249 560209 : }
28250 :
28251 : /* Output a marker (i.e. a label) for the beginning of the generated code for
28252 : a lexical block. */
28253 :
28254 : static void
28255 22808099 : dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
28256 : unsigned int blocknum,
28257 : tree block ATTRIBUTE_UNUSED)
28258 : {
28259 : #ifdef CODEVIEW_DEBUGGING_INFO
28260 : if (codeview_debuginfo_p ())
28261 : codeview_begin_block (line, blocknum, block);
28262 : #endif
28263 :
28264 22808099 : switch_to_section (current_function_section ());
28265 22808099 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
28266 22808099 : }
28267 :
28268 : /* Output a marker (i.e. a label) for the end of the generated code for a
28269 : lexical block. */
28270 :
28271 : static void
28272 22808099 : dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
28273 : {
28274 : #ifdef CODEVIEW_DEBUGGING_INFO
28275 : if (codeview_debuginfo_p ())
28276 : codeview_end_block (line, blocknum);
28277 : #endif
28278 :
28279 22808099 : switch_to_section (current_function_section ());
28280 22808099 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
28281 22808099 : }
28282 :
28283 : /* Returns true if it is appropriate not to emit any debugging
28284 : information for BLOCK, because it doesn't contain any instructions.
28285 :
28286 : Don't allow this for blocks with nested functions or local classes
28287 : as we would end up with orphans, and in the presence of scheduling
28288 : we may end up calling them anyway. */
28289 :
28290 : static bool
28291 102017152 : dwarf2out_ignore_block (const_tree block)
28292 : {
28293 102017152 : tree decl;
28294 102017152 : unsigned int i;
28295 :
28296 209682850 : for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
28297 108206065 : if (TREE_CODE (decl) == FUNCTION_DECL
28298 108206065 : || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
28299 : return false;
28300 101773869 : for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
28301 : {
28302 313071 : decl = BLOCK_NONLOCALIZED_VAR (block, i);
28303 313071 : if (TREE_CODE (decl) == FUNCTION_DECL
28304 313071 : || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
28305 : return false;
28306 : }
28307 :
28308 : return true;
28309 : }
28310 :
28311 : /* Hash table routines for file_hash. */
28312 :
28313 : bool
28314 2068469953 : dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
28315 : {
28316 2068469953 : return filename_cmp (p1->key, p2) == 0;
28317 : }
28318 :
28319 : hashval_t
28320 1529815547 : dwarf_file_hasher::hash (dwarf_file_data *p)
28321 : {
28322 1529815547 : return htab_hash_string (p->key);
28323 : }
28324 :
28325 : /* Lookup FILE_NAME (in the list of filenames that we know about here in
28326 : dwarf2out.cc) and return its "index". The index of each (known) filename is
28327 : just a unique number which is associated with only that one filename. We
28328 : need such numbers for the sake of generating labels (in the .debug_sfnames
28329 : section) and references to those files numbers (in the .debug_srcinfo
28330 : and .debug_macinfo sections). If the filename given as an argument is not
28331 : found in our current list, add it to the list and assign it the next
28332 : available unique index number. */
28333 :
28334 : static struct dwarf_file_data *
28335 328843637 : lookup_filename (const char *file_name)
28336 : {
28337 328843637 : struct dwarf_file_data * created;
28338 :
28339 328843637 : if (!file_name)
28340 : return NULL;
28341 :
28342 328833884 : if (!file_name[0])
28343 244 : file_name = "<stdin>";
28344 :
28345 328833884 : dwarf_file_data **slot
28346 328833884 : = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
28347 : INSERT);
28348 328833884 : if (*slot)
28349 : return *slot;
28350 :
28351 3031194 : created = ggc_alloc<dwarf_file_data> ();
28352 3031194 : created->key = file_name;
28353 3031194 : created->filename = remap_debug_filename (file_name);
28354 3031194 : created->emitted_number = 0;
28355 3031194 : *slot = created;
28356 3031194 : return created;
28357 : }
28358 :
28359 : /* If the assembler will construct the file table, then translate the compiler
28360 : internal file table number into the assembler file table number, and emit
28361 : a .file directive if we haven't already emitted one yet. The file table
28362 : numbers are different because we prune debug info for unused variables and
28363 : types, which may include filenames. */
28364 :
28365 : static int
28366 207768863 : maybe_emit_file (struct dwarf_file_data * fd)
28367 : {
28368 207768863 : if (! fd->emitted_number)
28369 : {
28370 1175385 : if (last_emitted_file)
28371 1125448 : fd->emitted_number = last_emitted_file->emitted_number + 1;
28372 : else
28373 49937 : fd->emitted_number = 1;
28374 1175385 : last_emitted_file = fd;
28375 :
28376 1175385 : if (output_asm_line_debug_info ())
28377 : {
28378 1175273 : fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
28379 1175273 : output_quoted_string (asm_out_file, fd->filename);
28380 1175273 : fputc ('\n', asm_out_file);
28381 : }
28382 : }
28383 :
28384 207768863 : return fd->emitted_number;
28385 : }
28386 :
28387 : /* Schedule generation of a DW_AT_const_value attribute to DIE.
28388 : That generation should happen after function debug info has been
28389 : generated. The value of the attribute is the constant value of ARG. */
28390 :
28391 : static void
28392 10977381 : append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
28393 : {
28394 10977381 : die_arg_entry entry;
28395 :
28396 10977381 : if (!die || !arg)
28397 0 : return;
28398 :
28399 10977381 : gcc_assert (early_dwarf);
28400 :
28401 10977381 : if (!tmpl_value_parm_die_table)
28402 11511 : vec_alloc (tmpl_value_parm_die_table, 32);
28403 :
28404 10977381 : entry.die = die;
28405 10977381 : entry.arg = arg;
28406 10977381 : vec_safe_push (tmpl_value_parm_die_table, entry);
28407 : }
28408 :
28409 : /* Return TRUE if T is an instance of generic type, FALSE
28410 : otherwise. */
28411 :
28412 : static bool
28413 53730967 : generic_type_p (tree t)
28414 : {
28415 53730967 : if (t == NULL_TREE || !TYPE_P (t))
28416 : return false;
28417 53730967 : return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
28418 : }
28419 :
28420 : /* Schedule the generation of the generic parameter dies for the
28421 : instance of generic type T. The proper generation itself is later
28422 : done by gen_scheduled_generic_parms_dies. */
28423 :
28424 : static void
28425 53730967 : schedule_generic_params_dies_gen (tree t)
28426 : {
28427 53730967 : if (!generic_type_p (t))
28428 : return;
28429 :
28430 46211186 : gcc_assert (early_dwarf);
28431 :
28432 46211186 : if (!generic_type_instances)
28433 12469 : vec_alloc (generic_type_instances, 256);
28434 :
28435 46211186 : vec_safe_push (generic_type_instances, t);
28436 : }
28437 :
28438 : /* Add a DW_AT_const_value attribute to DIEs that were scheduled
28439 : by append_entry_to_tmpl_value_parm_die_table. This function must
28440 : be called after function DIEs have been generated. */
28441 :
28442 : static void
28443 104505 : gen_remaining_tmpl_value_param_die_attribute (void)
28444 : {
28445 104505 : if (tmpl_value_parm_die_table)
28446 : {
28447 : unsigned i, j;
28448 : die_arg_entry *e;
28449 :
28450 : /* We do this in two phases - first get the cases we can
28451 : handle during early-finish, preserving those we cannot
28452 : (containing symbolic constants where we don't yet know
28453 : whether we are going to output the referenced symbols).
28454 : For those we try again at late-finish. */
28455 : j = 0;
28456 11001213 : FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
28457 : {
28458 10978227 : if (!e->die->removed
28459 10978227 : && !tree_add_const_value_attribute (e->die, e->arg))
28460 : {
28461 1635 : dw_loc_descr_ref loc = NULL;
28462 1635 : if (! early_dwarf
28463 789 : && (dwarf_version >= 5 || !dwarf_strict))
28464 786 : loc = loc_descriptor_from_tree (e->arg, 2, NULL);
28465 786 : if (loc)
28466 780 : add_AT_loc (e->die, DW_AT_location, loc);
28467 : else
28468 855 : (*tmpl_value_parm_die_table)[j++] = *e;
28469 : }
28470 : }
28471 22986 : tmpl_value_parm_die_table->truncate (j);
28472 : }
28473 104505 : }
28474 :
28475 : /* Generate generic parameters DIEs for instances of generic types
28476 : that have been previously scheduled by
28477 : schedule_generic_params_dies_gen. This function must be called
28478 : after all the types of the CU have been laid out. */
28479 :
28480 : static void
28481 52425 : gen_scheduled_generic_parms_dies (void)
28482 : {
28483 52425 : unsigned i;
28484 52425 : tree t;
28485 :
28486 52425 : if (!generic_type_instances)
28487 52425 : return;
28488 :
28489 44891915 : FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
28490 44879912 : if (COMPLETE_TYPE_P (t))
28491 42503775 : gen_generic_params_dies (t);
28492 :
28493 12003 : generic_type_instances = NULL;
28494 : }
28495 :
28496 :
28497 : /* Replace DW_AT_name for the decl with name. */
28498 :
28499 : static void
28500 0 : dwarf2out_set_name (tree decl, tree name)
28501 : {
28502 0 : dw_die_ref die;
28503 0 : dw_attr_node *attr;
28504 0 : const char *dname;
28505 :
28506 0 : die = TYPE_SYMTAB_DIE (decl);
28507 0 : if (!die)
28508 : return;
28509 :
28510 0 : dname = dwarf2_name (name, 0);
28511 0 : if (!dname)
28512 : return;
28513 :
28514 0 : attr = get_AT (die, DW_AT_name);
28515 0 : if (attr)
28516 : {
28517 0 : struct indirect_string_node *node;
28518 :
28519 0 : node = find_AT_string (dname);
28520 : /* replace the string. */
28521 0 : attr->dw_attr_val.v.val_str = node;
28522 : }
28523 :
28524 : else
28525 0 : add_name_attribute (die, dname);
28526 : }
28527 :
28528 : /* True if before or during processing of the first function being emitted. */
28529 : static bool in_first_function_p = true;
28530 : /* True if loc_note during dwarf2out_var_location call might still be
28531 : before first real instruction at address equal to .Ltext0. */
28532 : static bool maybe_at_text_label_p = true;
28533 : /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
28534 : static unsigned int first_loclabel_num_not_at_text_label;
28535 :
28536 : /* Look ahead for a real insn. */
28537 :
28538 : static rtx_insn *
28539 13760369 : dwarf2out_next_real_insn (rtx_insn *loc_note)
28540 : {
28541 13760369 : rtx_insn *next_real = NEXT_INSN (loc_note);
28542 :
28543 149301502 : while (next_real)
28544 135280924 : if (INSN_P (next_real))
28545 : break;
28546 : else
28547 121780764 : next_real = NEXT_INSN (next_real);
28548 :
28549 13760369 : return next_real;
28550 : }
28551 :
28552 : /* Called by the final INSN scan whenever we see a var location. We
28553 : use it to drop labels in the right places, and throw the location in
28554 : our lookup table. */
28555 :
28556 : static void
28557 100806416 : dwarf2out_var_location (rtx_insn *loc_note)
28558 : {
28559 100806416 : char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
28560 100806416 : struct var_loc_node *newloc;
28561 100806416 : rtx_insn *next_real;
28562 100806416 : rtx_insn *call_insn = NULL;
28563 100806416 : static const char *last_label;
28564 100806416 : static const char *last_postcall_label;
28565 100806416 : static bool last_in_cold_section_p;
28566 100806416 : static rtx_insn *expected_next_loc_note;
28567 100806416 : tree decl;
28568 100806416 : bool var_loc_p;
28569 100806416 : var_loc_view view = 0;
28570 :
28571 100806416 : if (!NOTE_P (loc_note))
28572 : {
28573 42057241 : if (CALL_P (loc_note))
28574 : {
28575 3517271 : maybe_reset_location_view (loc_note, cur_line_info_table);
28576 3517271 : call_site_count++;
28577 3517271 : if (SIBLING_CALL_P (loc_note))
28578 58646 : tail_call_site_count++;
28579 3517271 : if (find_reg_note (loc_note, REG_CALL_ARG_LOCATION, NULL_RTX))
28580 : {
28581 3133935 : call_insn = loc_note;
28582 3133935 : loc_note = NULL;
28583 3133935 : var_loc_p = false;
28584 :
28585 3133935 : next_real = dwarf2out_next_real_insn (call_insn);
28586 3133935 : cached_next_real_insn = NULL;
28587 3133935 : goto create_label;
28588 : }
28589 383336 : if (optimize == 0 && !flag_var_tracking)
28590 : {
28591 : /* When the var-tracking pass is not running, there is no note
28592 : for indirect calls whose target is compile-time known. In this
28593 : case, process such calls specifically so that we generate call
28594 : sites for them anyway. */
28595 358454 : rtx x = PATTERN (loc_note);
28596 358454 : if (GET_CODE (x) == PARALLEL)
28597 1 : x = XVECEXP (x, 0, 0);
28598 358454 : if (GET_CODE (x) == SET)
28599 110564 : x = SET_SRC (x);
28600 358454 : if (GET_CODE (x) == CALL)
28601 358454 : x = XEXP (x, 0);
28602 358454 : if (!MEM_P (x)
28603 358454 : || GET_CODE (XEXP (x, 0)) != SYMBOL_REF
28604 337985 : || !SYMBOL_REF_DECL (XEXP (x, 0))
28605 681145 : || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0)))
28606 : != FUNCTION_DECL))
28607 : {
28608 35763 : call_insn = loc_note;
28609 35763 : loc_note = NULL;
28610 35763 : var_loc_p = false;
28611 :
28612 35763 : next_real = dwarf2out_next_real_insn (call_insn);
28613 35763 : cached_next_real_insn = NULL;
28614 35763 : goto create_label;
28615 : }
28616 : }
28617 : }
28618 38539970 : else if (!debug_variable_location_views)
28619 0 : gcc_unreachable ();
28620 : else
28621 38539970 : maybe_reset_location_view (loc_note, cur_line_info_table);
28622 :
28623 47204204 : return;
28624 : }
28625 :
28626 58749175 : var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
28627 58749175 : if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
28628 : return;
28629 :
28630 : /* Optimize processing a large consecutive sequence of location
28631 : notes so we don't spend too much time in next_real_insn. If the
28632 : next insn is another location note, remember the next_real_insn
28633 : calculation for next time. */
28634 58749175 : next_real = cached_next_real_insn;
28635 58749175 : if (next_real)
28636 : {
28637 48158504 : if (expected_next_loc_note != loc_note)
28638 : next_real = NULL;
28639 : }
28640 :
28641 : if (! next_real)
28642 10590671 : next_real = dwarf2out_next_real_insn (loc_note);
28643 :
28644 10590671 : if (next_real)
28645 : {
28646 58623794 : rtx_insn *next_note = NEXT_INSN (loc_note);
28647 169108192 : while (next_note != next_real)
28648 : {
28649 100019108 : if (! next_note->deleted ()
28650 100019108 : && NOTE_P (next_note)
28651 197027699 : && NOTE_KIND (next_note) == NOTE_INSN_VAR_LOCATION)
28652 : break;
28653 51860604 : next_note = NEXT_INSN (next_note);
28654 : }
28655 :
28656 58623794 : if (next_note == next_real)
28657 10465290 : cached_next_real_insn = NULL;
28658 : else
28659 : {
28660 48158504 : expected_next_loc_note = next_note;
28661 48158504 : cached_next_real_insn = next_real;
28662 : }
28663 : }
28664 : else
28665 125381 : cached_next_real_insn = NULL;
28666 :
28667 : /* If there are no instructions which would be affected by this note,
28668 : don't do anything. */
28669 58749175 : if (var_loc_p
28670 58749175 : && next_real == NULL_RTX
28671 58749175 : && !NOTE_DURING_CALL_P (loc_note))
28672 : return;
28673 :
28674 61918712 : create_label:
28675 :
28676 61918712 : if (next_real == NULL_RTX)
28677 260048 : next_real = get_last_insn ();
28678 :
28679 : /* If there were any real insns between note we processed last time
28680 : and this note (or if it is the first note), clear
28681 : last_{,postcall_}label so that they are not reused this time. */
28682 61918712 : if (last_var_location_insn == NULL_RTX
28683 61418380 : || last_var_location_insn != next_real
28684 48182548 : || last_in_cold_section_p != in_cold_section_p)
28685 : {
28686 13739302 : last_label = NULL;
28687 13739302 : last_postcall_label = NULL;
28688 : }
28689 :
28690 61918712 : if (var_loc_p)
28691 : {
28692 58749014 : const char *label
28693 58749014 : = NOTE_DURING_CALL_P (loc_note) ? last_postcall_label : last_label;
28694 58749014 : view = cur_line_info_table->view;
28695 58749014 : decl = NOTE_VAR_LOCATION_DECL (loc_note);
28696 58749014 : newloc = add_var_loc_to_decl (decl, loc_note, label, view);
28697 58749014 : if (newloc == NULL)
28698 : return;
28699 : }
28700 : else
28701 : {
28702 : decl = NULL_TREE;
28703 : newloc = NULL;
28704 : }
28705 :
28706 : /* If there were no real insns between note we processed last time
28707 : and this note, use the label we emitted last time. Otherwise
28708 : create a new label and emit it. */
28709 53602212 : if (last_label == NULL)
28710 : {
28711 11550853 : ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
28712 11550853 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
28713 11550853 : loclabel_num++;
28714 11550853 : last_label = ggc_strdup (loclabel);
28715 : /* See if loclabel might be equal to .Ltext0. If yes,
28716 : bump first_loclabel_num_not_at_text_label. */
28717 11550853 : if (!have_multiple_function_sections
28718 4729523 : && in_first_function_p
28719 261044 : && maybe_at_text_label_p)
28720 : {
28721 : static rtx_insn *last_start;
28722 : rtx_insn *insn;
28723 128847 : for (insn = loc_note; insn; insn = previous_insn (insn))
28724 83803 : if (insn == last_start)
28725 : break;
28726 83623 : else if (!NONDEBUG_INSN_P (insn))
28727 71209 : continue;
28728 : else
28729 : {
28730 12414 : rtx body = PATTERN (insn);
28731 12414 : if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
28732 3 : continue;
28733 : /* Inline asm could occupy zero bytes. */
28734 12655 : else if (GET_CODE (body) == ASM_INPUT
28735 12411 : || asm_noperands (body) >= 0)
28736 244 : continue;
28737 : #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h. */
28738 : else if (HAVE_ATTR_length && get_attr_min_length (insn) == 0)
28739 : continue;
28740 : #endif
28741 : else
28742 : {
28743 : /* Assume insn has non-zero length. */
28744 12167 : maybe_at_text_label_p = false;
28745 12167 : break;
28746 : }
28747 : }
28748 57391 : if (maybe_at_text_label_p)
28749 : {
28750 45224 : last_start = loc_note;
28751 45224 : first_loclabel_num_not_at_text_label = loclabel_num;
28752 : }
28753 : }
28754 : }
28755 :
28756 53602212 : gcc_assert ((loc_note == NULL_RTX && call_insn != NULL_RTX)
28757 : || (loc_note != NULL_RTX && call_insn == NULL_RTX));
28758 :
28759 53602212 : if (!var_loc_p)
28760 : {
28761 3169698 : struct call_arg_loc_node *ca_loc
28762 3169698 : = ggc_cleared_alloc<call_arg_loc_node> ();
28763 3169698 : rtx_insn *prev = call_insn;
28764 :
28765 3169698 : ca_loc->call_insn = call_insn;
28766 3169698 : ca_loc->next = NULL;
28767 3169698 : ca_loc->label = last_label;
28768 3169698 : gcc_assert (prev
28769 : && (CALL_P (prev)
28770 : || (NONJUMP_INSN_P (prev)
28771 : && GET_CODE (PATTERN (prev)) == SEQUENCE
28772 : && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
28773 3169698 : if (!CALL_P (prev))
28774 0 : prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
28775 3169698 : ca_loc->tail_call_p = SIBLING_CALL_P (prev);
28776 :
28777 : /* Look for a SYMBOL_REF in the "prev" instruction. */
28778 3169698 : rtx x = get_call_rtx_from (prev);
28779 3169698 : if (x)
28780 : {
28781 : /* Try to get the call symbol, if any. */
28782 3169698 : if (MEM_P (XEXP (x, 0)))
28783 3169698 : x = XEXP (x, 0);
28784 : /* First, look for a memory access to a symbol_ref. */
28785 3169698 : if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
28786 3023402 : && SYMBOL_REF_DECL (XEXP (x, 0))
28787 5943355 : && TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0))) == FUNCTION_DECL)
28788 2773654 : ca_loc->symbol_ref = XEXP (x, 0);
28789 : /* Otherwise, look at a compile-time known user-level function
28790 : declaration. */
28791 396044 : else if (MEM_P (x)
28792 396044 : && MEM_EXPR (x)
28793 536014 : && TREE_CODE (MEM_EXPR (x)) == FUNCTION_DECL)
28794 0 : ca_loc->symbol_ref = XEXP (DECL_RTL (MEM_EXPR (x)), 0);
28795 : }
28796 :
28797 3169698 : ca_loc->block = insn_scope (prev);
28798 3169698 : if (call_arg_locations)
28799 2727447 : call_arg_loc_last->next = ca_loc;
28800 : else
28801 442251 : call_arg_locations = ca_loc;
28802 3169698 : call_arg_loc_last = ca_loc;
28803 : }
28804 50432514 : else if (loc_note != NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
28805 : {
28806 47381733 : newloc->label = last_label;
28807 47381733 : newloc->view = view;
28808 : }
28809 : else
28810 : {
28811 3050781 : if (!last_postcall_label)
28812 : {
28813 1056986 : sprintf (loclabel, "%s-1", last_label);
28814 1056986 : last_postcall_label = ggc_strdup (loclabel);
28815 : }
28816 3050781 : newloc->label = last_postcall_label;
28817 : /* ??? This view is at last_label, not last_label-1, but we
28818 : could only assume view at last_label-1 is zero if we could
28819 : assume calls always have length greater than one. This is
28820 : probably true in general, though there might be a rare
28821 : exception to this rule, e.g. if a call insn is optimized out
28822 : by target magic. Then, even the -1 in the label will be
28823 : wrong, which might invalidate the range. Anyway, using view,
28824 : though technically possibly incorrect, will work as far as
28825 : ranges go: since L-1 is in the middle of the call insn,
28826 : (L-1).0 and (L-1).V shouldn't make any difference, and having
28827 : the loclist entry refer to the .loc entry might be useful, so
28828 : leave it like this. */
28829 3050781 : newloc->view = view;
28830 : }
28831 :
28832 53602212 : if (var_loc_p && flag_debug_asm)
28833 : {
28834 396 : const char *name, *sep, *patstr;
28835 396 : if (decl && DECL_NAME (decl))
28836 385 : name = IDENTIFIER_POINTER (DECL_NAME (decl));
28837 : else
28838 : name = "";
28839 396 : if (NOTE_VAR_LOCATION_LOC (loc_note))
28840 : {
28841 295 : sep = " => ";
28842 295 : patstr = str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note));
28843 : }
28844 : else
28845 : {
28846 : sep = " ";
28847 : patstr = "RESET";
28848 : }
28849 396 : fprintf (asm_out_file, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START,
28850 : name, sep, patstr);
28851 : }
28852 :
28853 53602212 : last_var_location_insn = next_real;
28854 53602212 : last_in_cold_section_p = in_cold_section_p;
28855 : }
28856 :
28857 : /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
28858 : OUTER itself. If BOTHWAYS, check not only that BLOCK can reach
28859 : OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
28860 : path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
28861 : BLOCK_FRAGMENT_ORIGIN links. */
28862 : static bool
28863 6758883 : block_within_block_p (tree block, tree outer, bool bothways)
28864 : {
28865 6758883 : if (block == outer)
28866 : return true;
28867 :
28868 : /* Quickly check that OUTER is up BLOCK's supercontext chain. */
28869 6758883 : for (tree context = BLOCK_SUPERCONTEXT (block);
28870 47768933 : context != outer;
28871 41010050 : context = BLOCK_SUPERCONTEXT (context))
28872 41010050 : if (!context || TREE_CODE (context) != BLOCK)
28873 : return false;
28874 :
28875 6758883 : if (!bothways)
28876 : return true;
28877 :
28878 : /* Now check that each block is actually referenced by its
28879 : parent. */
28880 41010050 : for (tree context = BLOCK_SUPERCONTEXT (block); ;
28881 41010050 : context = BLOCK_SUPERCONTEXT (context))
28882 : {
28883 47768933 : if (BLOCK_FRAGMENT_ORIGIN (context))
28884 : {
28885 2123858 : gcc_assert (!BLOCK_SUBBLOCKS (context));
28886 : context = BLOCK_FRAGMENT_ORIGIN (context);
28887 : }
28888 210531936 : for (tree sub = BLOCK_SUBBLOCKS (context);
28889 210531936 : sub != block;
28890 162763003 : sub = BLOCK_CHAIN (sub))
28891 162763003 : if (!sub)
28892 : return false;
28893 47768933 : if (context == outer)
28894 : return true;
28895 : else
28896 41010050 : block = context;
28897 41010050 : }
28898 : }
28899 :
28900 : /* Called during final while assembling the marker of the entry point
28901 : for an inlined function. */
28902 :
28903 : static void
28904 6758883 : dwarf2out_inline_entry (tree block)
28905 : {
28906 6758883 : gcc_assert (debug_inline_points);
28907 :
28908 : /* If we can't represent it, don't bother. */
28909 6758883 : if (!(dwarf_version >= 3 || !dwarf_strict))
28910 : return;
28911 :
28912 6758883 : gcc_assert (DECL_P (block_ultimate_origin (block)));
28913 :
28914 : /* Sanity check the block tree. This would catch a case in which
28915 : BLOCK got removed from the tree reachable from the outermost
28916 : lexical block, but got retained in markers. It would still link
28917 : back to its parents, but some ancestor would be missing a link
28918 : down the path to the sub BLOCK. If the block got removed, its
28919 : BLOCK_NUMBER will not be a usable value. */
28920 6758883 : if (flag_checking)
28921 6758883 : gcc_assert (block_within_block_p (block,
28922 : DECL_INITIAL (current_function_decl),
28923 : true));
28924 :
28925 6758883 : gcc_assert (inlined_function_outer_scope_p (block));
28926 6758883 : gcc_assert (!lookup_block_die (block));
28927 :
28928 6758883 : if (BLOCK_FRAGMENT_ORIGIN (block))
28929 0 : block = BLOCK_FRAGMENT_ORIGIN (block);
28930 : /* Can the entry point ever not be at the beginning of an
28931 : unfragmented lexical block? */
28932 6758883 : else if (!(BLOCK_FRAGMENT_CHAIN (block)
28933 3544666 : || (cur_line_info_table
28934 3544666 : && !ZERO_VIEW_P (cur_line_info_table->view))))
28935 662 : return;
28936 :
28937 6758221 : if (!inline_entry_data_table)
28938 12666 : inline_entry_data_table
28939 12666 : = hash_table<inline_entry_data_hasher>::create_ggc (10);
28940 :
28941 :
28942 6758221 : inline_entry_data **iedp
28943 6758221 : = inline_entry_data_table->find_slot_with_hash (block,
28944 : htab_hash_pointer (block),
28945 : INSERT);
28946 6758221 : if (*iedp)
28947 : /* ??? Ideally, we'd record all entry points for the same inlined
28948 : function (some may have been duplicated by e.g. unrolling), but
28949 : we have no way to represent that ATM. */
28950 : return;
28951 :
28952 6212119 : inline_entry_data *ied = *iedp = ggc_cleared_alloc<inline_entry_data> ();
28953 6212119 : ied->block = block;
28954 6212119 : ied->label_pfx = BLOCK_INLINE_ENTRY_LABEL;
28955 6212119 : ied->label_num = BLOCK_NUMBER (block);
28956 6212119 : if (cur_line_info_table)
28957 6212119 : ied->view = cur_line_info_table->view;
28958 :
28959 6212119 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_INLINE_ENTRY_LABEL,
28960 : BLOCK_NUMBER (block));
28961 : }
28962 :
28963 : /* Called from finalize_size_functions for size functions so that their body
28964 : can be encoded in the debug info to describe the layout of variable-length
28965 : structures. */
28966 :
28967 : static void
28968 0 : dwarf2out_size_function (tree decl)
28969 : {
28970 0 : set_early_dwarf s;
28971 0 : function_to_dwarf_procedure (decl);
28972 0 : }
28973 :
28974 : /* Note in one location list that text section has changed. */
28975 :
28976 : int
28977 3341209 : var_location_switch_text_section_1 (var_loc_list **slot, void *)
28978 : {
28979 3341209 : var_loc_list *list = *slot;
28980 3341209 : if (list->first)
28981 3341209 : list->last_before_switch
28982 3393374 : = list->last->next ? list->last->next : list->last;
28983 3341209 : return 1;
28984 : }
28985 :
28986 : /* Note in all location lists that text section has changed. */
28987 :
28988 : static void
28989 63740 : var_location_switch_text_section (void)
28990 : {
28991 63740 : if (decl_loc_table == NULL)
28992 : return;
28993 :
28994 3362151 : decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
28995 : }
28996 :
28997 : /* Create a new line number table. */
28998 :
28999 : static dw_line_info_table *
29000 254995 : new_line_info_table (void)
29001 : {
29002 254995 : dw_line_info_table *table;
29003 :
29004 254995 : table = ggc_cleared_alloc<dw_line_info_table> ();
29005 254995 : table->file_num = 1;
29006 254995 : table->line_num = 1;
29007 254995 : table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
29008 254995 : FORCE_RESET_NEXT_VIEW (table->view);
29009 254995 : table->symviews_since_reset = 0;
29010 :
29011 254995 : return table;
29012 : }
29013 :
29014 : /* Lookup the "current" table into which we emit line info, so
29015 : that we don't have to do it for every source line. */
29016 :
29017 : static void
29018 589163 : set_cur_line_info_table (section *sec)
29019 : {
29020 589163 : dw_line_info_table *table;
29021 :
29022 589163 : if (sec == text_section)
29023 383681 : table = text_section_line_info;
29024 205482 : else if (sec == cold_text_section)
29025 : {
29026 11565 : table = cold_text_section_line_info;
29027 11565 : if (!table)
29028 : {
29029 8667 : cold_text_section_line_info = table = new_line_info_table ();
29030 8667 : table->end_label = cold_end_label;
29031 : }
29032 : }
29033 : else
29034 : {
29035 193917 : const char *end_label;
29036 :
29037 193917 : if (crtl->has_bb_partition)
29038 : {
29039 26126 : if (in_cold_section_p)
29040 9492 : end_label = crtl->subsections.cold_section_end_label;
29041 : else
29042 16634 : end_label = crtl->subsections.hot_section_end_label;
29043 : }
29044 : else
29045 : {
29046 167791 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29047 167791 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
29048 : current_function_funcdef_no);
29049 167791 : end_label = ggc_strdup (label);
29050 : }
29051 :
29052 193917 : table = new_line_info_table ();
29053 193917 : table->end_label = end_label;
29054 :
29055 193917 : vec_safe_push (separate_line_info, table);
29056 : }
29057 :
29058 589163 : if (output_asm_line_debug_info ())
29059 1178234 : table->is_stmt = (cur_line_info_table
29060 589117 : ? cur_line_info_table->is_stmt
29061 : : DWARF_LINE_DEFAULT_IS_STMT_START);
29062 589163 : cur_line_info_table = table;
29063 589163 : }
29064 :
29065 :
29066 : /* We need to reset the locations at the beginning of each
29067 : function. We can't do this in the end_function hook, because the
29068 : declarations that use the locations won't have been output when
29069 : that hook is called. Also compute have_multiple_function_sections here. */
29070 :
29071 : static void
29072 560253 : dwarf2out_begin_function (tree fun)
29073 : {
29074 560253 : section *sec = function_section (fun);
29075 :
29076 560253 : if (sec != text_section)
29077 181151 : have_multiple_function_sections = true;
29078 :
29079 560253 : if (crtl->has_bb_partition && !cold_text_section)
29080 : {
29081 8667 : gcc_assert (current_function_decl == fun);
29082 8667 : cold_text_section = unlikely_text_section ();
29083 8667 : switch_to_section (cold_text_section);
29084 8667 : ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
29085 8667 : switch_to_section (sec);
29086 : }
29087 :
29088 560253 : call_site_count = 0;
29089 560253 : tail_call_site_count = 0;
29090 :
29091 560253 : set_cur_line_info_table (sec);
29092 560253 : FORCE_RESET_NEXT_VIEW (cur_line_info_table->view);
29093 560253 : }
29094 :
29095 : /* Helper function of dwarf2out_end_function, called only after emitting
29096 : the very first function into assembly. Check if some .debug_loc range
29097 : might end with a .LVL* label that could be equal to .Ltext0.
29098 : In that case we must force using absolute addresses in .debug_loc ranges,
29099 : because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
29100 : .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
29101 : list terminator.
29102 : Set have_multiple_function_sections to true in that case and
29103 : terminate htab traversal. */
29104 :
29105 : int
29106 182224 : find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
29107 : {
29108 182224 : var_loc_list *entry = *slot;
29109 182224 : struct var_loc_node *node;
29110 :
29111 182224 : node = entry->first;
29112 182224 : if (node && node->next && node->next->label)
29113 : {
29114 : unsigned int i;
29115 : const char *label = node->next->label;
29116 : char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
29117 :
29118 131645 : for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
29119 : {
29120 76809 : ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
29121 76809 : if (strcmp (label, loclabel) == 0)
29122 : {
29123 701 : have_multiple_function_sections = true;
29124 701 : return 0;
29125 : }
29126 : }
29127 : }
29128 : return 1;
29129 : }
29130 :
29131 : /* Hook called after emitting a function into assembly.
29132 : This does something only for the very first function emitted. */
29133 :
29134 : static void
29135 560253 : dwarf2out_end_function (unsigned int)
29136 : {
29137 560253 : if (in_first_function_p
29138 47143 : && !have_multiple_function_sections
29139 27307 : && first_loclabel_num_not_at_text_label
29140 19284 : && decl_loc_table)
29141 201508 : decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
29142 560253 : in_first_function_p = false;
29143 560253 : maybe_at_text_label_p = false;
29144 560253 : }
29145 :
29146 : /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
29147 : front-ends register a translation unit even before dwarf2out_init is
29148 : called. */
29149 : static tree main_translation_unit = NULL_TREE;
29150 :
29151 : /* Hook called by front-ends after they built their main translation unit.
29152 : Associate comp_unit_die to UNIT. */
29153 :
29154 : static void
29155 44772 : dwarf2out_register_main_translation_unit (tree unit)
29156 : {
29157 44772 : gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
29158 : && main_translation_unit == NULL_TREE);
29159 44772 : main_translation_unit = unit;
29160 : /* If dwarf2out_init has not been called yet, it will perform the association
29161 : itself looking at main_translation_unit. */
29162 44772 : if (decl_die_table != NULL)
29163 26749 : equate_decl_number_to_die (unit, comp_unit_die ());
29164 44772 : }
29165 :
29166 : /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
29167 :
29168 : static void
29169 5747 : push_dw_line_info_entry (dw_line_info_table *table,
29170 : enum dw_line_info_opcode opcode, unsigned int val)
29171 : {
29172 5747 : dw_line_info_entry e;
29173 5747 : e.opcode = opcode;
29174 5747 : e.val = val;
29175 0 : vec_safe_push (table->entries, e);
29176 4206 : }
29177 :
29178 : /* Output a label to mark the beginning of a source code line entry
29179 : and record information relating to this source line, in
29180 : 'line_info_table' for later output of the .debug_line section. */
29181 : /* ??? The discriminator parameter ought to be unsigned. */
29182 :
29183 : static void
29184 35480662 : dwarf2out_source_line (unsigned int line, unsigned int column,
29185 : const char *filename,
29186 : int discriminator, bool is_stmt)
29187 : {
29188 35480662 : unsigned int file_num;
29189 35480662 : dw_line_info_table *table;
29190 35480662 : static var_loc_view lvugid;
29191 :
29192 : #ifdef CODEVIEW_DEBUGGING_INFO
29193 : if (codeview_debuginfo_p ())
29194 : codeview_source_line (line, filename);
29195 : #endif
29196 :
29197 : /* 'line_info_table' information gathering is not needed when the debug
29198 : info level is set to the lowest value. Also, the current DWARF-based
29199 : debug formats do not use this info. */
29200 35480662 : if (debug_info_level < DINFO_LEVEL_TERSE || !dwarf_debuginfo_p ())
29201 1270 : return;
29202 :
29203 35479392 : table = cur_line_info_table;
29204 :
29205 35479392 : if (line == 0)
29206 : {
29207 586848 : if (debug_variable_location_views
29208 549716 : && output_asm_line_debug_info ()
29209 1136564 : && table && !RESETTING_VIEW_P (table->view))
29210 : {
29211 : /* If we're using the assembler to compute view numbers, we
29212 : can't issue a .loc directive for line zero, so we can't
29213 : get a view number at this point. We might attempt to
29214 : compute it from the previous view, or equate it to a
29215 : subsequent view (though it might not be there!), but
29216 : since we're omitting the line number entry, we might as
29217 : well omit the view number as well. That means pretending
29218 : it's a view number zero, which might very well turn out
29219 : to be correct. ??? Extend the assembler so that the
29220 : compiler could emit e.g. ".locview .LVU#", to output a
29221 : view without changing line number information. We'd then
29222 : have to count it in symviews_since_reset; when it's omitted,
29223 : it doesn't count. */
29224 4051 : if (!zero_view_p)
29225 0 : zero_view_p = BITMAP_GGC_ALLOC ();
29226 4051 : bitmap_set_bit (zero_view_p, table->view);
29227 4051 : if (flag_debug_asm)
29228 : {
29229 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29230 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
29231 0 : fprintf (asm_out_file, "\t%s line 0, omitted view ",
29232 : ASM_COMMENT_START);
29233 0 : assemble_name (asm_out_file, label);
29234 0 : putc ('\n', asm_out_file);
29235 : }
29236 4051 : table->view = ++lvugid;
29237 : }
29238 586848 : return;
29239 : }
29240 :
29241 : /* The discriminator column was added in dwarf4. Simplify the below
29242 : by simply removing it if we're not supposed to output it. */
29243 34892544 : if (dwarf_version < 4 && dwarf_strict)
29244 34892544 : discriminator = 0;
29245 :
29246 34892544 : if (!debug_column_info)
29247 82 : column = 0;
29248 :
29249 34892544 : file_num = maybe_emit_file (lookup_filename (filename));
29250 :
29251 : /* ??? TODO: Elide duplicate line number entries. Traditionally,
29252 : the debugger has used the second (possibly duplicate) line number
29253 : at the beginning of the function to mark the end of the prologue.
29254 : We could eliminate any other duplicates within the function. For
29255 : Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
29256 : that second line number entry. */
29257 : /* Recall that this end-of-prologue indication is *not* the same thing
29258 : as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
29259 : to which the hook corresponds, follows the last insn that was
29260 : emitted by gen_prologue. What we need is to precede the first insn
29261 : that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
29262 : insn that corresponds to something the user wrote. These may be
29263 : very different locations once scheduling is enabled. */
29264 :
29265 34892544 : if (0 && file_num == table->file_num
29266 : && line == table->line_num
29267 : && column == table->column_num
29268 : && discriminator == table->discrim_num
29269 : && is_stmt == table->is_stmt)
29270 : return;
29271 :
29272 34892544 : switch_to_section (current_function_section ());
29273 :
29274 : /* If requested, emit something human-readable. */
29275 34892544 : if (flag_debug_asm)
29276 : {
29277 6638 : if (debug_column_info)
29278 6581 : fprintf (asm_out_file, "\t%s %s:%d:%d\n", ASM_COMMENT_START,
29279 : filename, line, column);
29280 : else
29281 57 : fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
29282 : filename, line);
29283 : }
29284 :
29285 34892544 : if (output_asm_line_debug_info ())
29286 : {
29287 : /* Emit the .loc directive understood by GNU as. */
29288 : /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
29289 : file_num, line, is_stmt, discriminator */
29290 34891003 : fputs ("\t.loc ", asm_out_file);
29291 34891003 : fprint_ul (asm_out_file, file_num);
29292 34891003 : putc (' ', asm_out_file);
29293 34891003 : fprint_ul (asm_out_file, line);
29294 34891003 : putc (' ', asm_out_file);
29295 34891003 : fprint_ul (asm_out_file, column);
29296 :
29297 34891003 : if (is_stmt != table->is_stmt)
29298 : {
29299 : #if HAVE_GAS_LOC_STMT
29300 13386817 : fputs (" is_stmt ", asm_out_file);
29301 20096155 : putc (is_stmt ? '1' : '0', asm_out_file);
29302 : #endif
29303 : }
29304 34891003 : if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
29305 : {
29306 9726063 : gcc_assert (discriminator > 0);
29307 9726063 : fputs (" discriminator ", asm_out_file);
29308 9726063 : fprint_ul (asm_out_file, (unsigned long) discriminator);
29309 : }
29310 34891003 : if (debug_variable_location_views)
29311 : {
29312 33992663 : if (!RESETTING_VIEW_P (table->view))
29313 : {
29314 33559121 : table->symviews_since_reset++;
29315 33559121 : if (table->symviews_since_reset > symview_upper_bound)
29316 6989669 : symview_upper_bound = table->symviews_since_reset;
29317 : /* When we're using the assembler to compute view
29318 : numbers, we output symbolic labels after "view" in
29319 : .loc directives, and the assembler will set them for
29320 : us, so that we can refer to the view numbers in
29321 : location lists. The only exceptions are when we know
29322 : a view will be zero: "-0" is a forced reset, used
29323 : e.g. in the beginning of functions, whereas "0" tells
29324 : the assembler to check that there was a PC change
29325 : since the previous view, in a way that implicitly
29326 : resets the next view. */
29327 33559121 : fputs (" view ", asm_out_file);
29328 33559121 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29329 33559121 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
29330 33559121 : assemble_name (asm_out_file, label);
29331 33559121 : table->view = ++lvugid;
29332 : }
29333 : else
29334 : {
29335 433542 : table->symviews_since_reset = 0;
29336 433542 : if (FORCE_RESETTING_VIEW_P (table->view))
29337 433542 : fputs (" view -0", asm_out_file);
29338 : else
29339 0 : fputs (" view 0", asm_out_file);
29340 : /* Mark the present view as a zero view. Earlier debug
29341 : binds may have already added its id to loclists to be
29342 : emitted later, so we can't reuse the id for something
29343 : else. However, it's good to know whether a view is
29344 : known to be zero, because then we may be able to
29345 : optimize out locviews that are all zeros, so take
29346 : note of it in zero_view_p. */
29347 433542 : if (!zero_view_p)
29348 40982 : zero_view_p = BITMAP_GGC_ALLOC ();
29349 433542 : bitmap_set_bit (zero_view_p, lvugid);
29350 433542 : table->view = ++lvugid;
29351 : }
29352 : }
29353 34891003 : putc ('\n', asm_out_file);
29354 : }
29355 : else
29356 : {
29357 1541 : unsigned int label_num = ++line_info_label_num;
29358 :
29359 1541 : targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
29360 :
29361 1541 : if (debug_variable_location_views && !RESETTING_VIEW_P (table->view))
29362 1451 : push_dw_line_info_entry (table, LI_adv_address, label_num);
29363 : else
29364 90 : push_dw_line_info_entry (table, LI_set_address, label_num);
29365 1541 : if (debug_variable_location_views)
29366 : {
29367 1485 : bool resetting = FORCE_RESETTING_VIEW_P (table->view);
29368 1485 : if (resetting)
29369 34 : table->view = 0;
29370 :
29371 1485 : if (flag_debug_asm)
29372 88 : fprintf (asm_out_file, "\t%s view %s%d\n",
29373 : ASM_COMMENT_START,
29374 : resetting ? "-" : "",
29375 : table->view);
29376 :
29377 1485 : table->view++;
29378 : }
29379 1541 : if (file_num != table->file_num)
29380 280 : push_dw_line_info_entry (table, LI_set_file, file_num);
29381 1541 : if (discriminator != table->discrim_num)
29382 271 : push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
29383 1541 : if (is_stmt != table->is_stmt)
29384 573 : push_dw_line_info_entry (table, LI_negate_stmt, 0);
29385 1541 : push_dw_line_info_entry (table, LI_set_line, line);
29386 1541 : if (debug_column_info)
29387 1541 : push_dw_line_info_entry (table, LI_set_column, column);
29388 : }
29389 :
29390 34892544 : table->file_num = file_num;
29391 34892544 : table->line_num = line;
29392 34892544 : table->column_num = column;
29393 34892544 : table->discrim_num = discriminator;
29394 34892544 : table->is_stmt = is_stmt;
29395 34892544 : table->in_use = true;
29396 : }
29397 :
29398 : /* Record a source file location for a DECL_IGNORED_P function. */
29399 :
29400 : static void
29401 7968 : dwarf2out_set_ignored_loc (unsigned int line, unsigned int column,
29402 : const char *filename)
29403 : {
29404 7968 : dw_fde_ref fde = cfun->fde;
29405 :
29406 7968 : fde->ignored_debug = false;
29407 7968 : set_cur_line_info_table (current_function_section ());
29408 :
29409 7968 : dwarf2out_source_line (line, column, filename, 0, true);
29410 7968 : }
29411 :
29412 : /* Record the beginning of a new source file. */
29413 :
29414 : static void
29415 7217471 : dwarf2out_start_source_file (unsigned int lineno, const char *filename)
29416 : {
29417 : #ifdef CODEVIEW_DEBUGGING_INFO
29418 : if (codeview_debuginfo_p ())
29419 : codeview_start_source_file (filename);
29420 : #endif
29421 :
29422 7217471 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29423 : {
29424 1843 : macinfo_entry e;
29425 1843 : e.code = DW_MACINFO_start_file;
29426 1843 : e.lineno = lineno;
29427 1843 : e.info = ggc_strdup (filename);
29428 1843 : vec_safe_push (macinfo_table, e);
29429 : }
29430 7217471 : }
29431 :
29432 : /* Record the end of a source file. */
29433 :
29434 : static void
29435 7217355 : dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
29436 : {
29437 7217355 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29438 : {
29439 1843 : macinfo_entry e;
29440 1843 : e.code = DW_MACINFO_end_file;
29441 1843 : e.lineno = lineno;
29442 1843 : e.info = NULL;
29443 1843 : vec_safe_push (macinfo_table, e);
29444 : }
29445 7217355 : }
29446 :
29447 : /* Called from debug_define in toplev.cc. The `buffer' parameter contains
29448 : the tail part of the directive line, i.e. the part which is past the
29449 : initial whitespace, #, whitespace, directive-name, whitespace part. */
29450 :
29451 : static void
29452 242118 : dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
29453 : const char *buffer ATTRIBUTE_UNUSED)
29454 : {
29455 242118 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29456 : {
29457 242118 : macinfo_entry e;
29458 : /* Insert a dummy first entry to be able to optimize the whole
29459 : predefined macro block using DW_MACRO_import. */
29460 242118 : if (macinfo_table->is_empty () && lineno <= 1)
29461 : {
29462 521 : e.code = 0;
29463 521 : e.lineno = 0;
29464 521 : e.info = NULL;
29465 521 : vec_safe_push (macinfo_table, e);
29466 : }
29467 242118 : e.code = DW_MACINFO_define;
29468 242118 : e.lineno = lineno;
29469 242118 : e.info = ggc_strdup (buffer);
29470 242118 : vec_safe_push (macinfo_table, e);
29471 : }
29472 242118 : }
29473 :
29474 : /* Called from debug_undef in toplev.cc. The `buffer' parameter contains
29475 : the tail part of the directive line, i.e. the part which is past the
29476 : initial whitespace, #, whitespace, directive-name, whitespace part. */
29477 :
29478 : static void
29479 755 : dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
29480 : const char *buffer ATTRIBUTE_UNUSED)
29481 : {
29482 755 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29483 : {
29484 755 : macinfo_entry e;
29485 : /* Insert a dummy first entry to be able to optimize the whole
29486 : predefined macro block using DW_MACRO_import. */
29487 755 : if (macinfo_table->is_empty () && lineno <= 1)
29488 : {
29489 0 : e.code = 0;
29490 0 : e.lineno = 0;
29491 0 : e.info = NULL;
29492 0 : vec_safe_push (macinfo_table, e);
29493 : }
29494 755 : e.code = DW_MACINFO_undef;
29495 755 : e.lineno = lineno;
29496 755 : e.info = ggc_strdup (buffer);
29497 755 : vec_safe_push (macinfo_table, e);
29498 : }
29499 755 : }
29500 :
29501 : /* Helpers to manipulate hash table of CUs. */
29502 :
29503 : struct macinfo_entry_hasher : nofree_ptr_hash <macinfo_entry>
29504 : {
29505 : static inline hashval_t hash (const macinfo_entry *);
29506 : static inline bool equal (const macinfo_entry *, const macinfo_entry *);
29507 : };
29508 :
29509 : inline hashval_t
29510 6501 : macinfo_entry_hasher::hash (const macinfo_entry *entry)
29511 : {
29512 6501 : return htab_hash_string (entry->info);
29513 : }
29514 :
29515 : inline bool
29516 5156 : macinfo_entry_hasher::equal (const macinfo_entry *entry1,
29517 : const macinfo_entry *entry2)
29518 : {
29519 5156 : return !strcmp (entry1->info, entry2->info);
29520 : }
29521 :
29522 : typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
29523 :
29524 : /* Output a single .debug_macinfo entry. */
29525 :
29526 : static void
29527 246045 : output_macinfo_op (macinfo_entry *ref)
29528 : {
29529 486776 : int file_num;
29530 486776 : size_t len;
29531 486776 : struct indirect_string_node *node;
29532 486776 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29533 486776 : struct dwarf_file_data *fd;
29534 :
29535 486776 : switch (ref->code)
29536 : {
29537 1837 : case DW_MACINFO_start_file:
29538 1837 : fd = lookup_filename (ref->info);
29539 1837 : file_num = maybe_emit_file (fd);
29540 1837 : dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
29541 1837 : dw2_asm_output_data_uleb128 (ref->lineno,
29542 : "Included from line number "
29543 : HOST_WIDE_INT_PRINT_UNSIGNED,
29544 : ref->lineno);
29545 1837 : dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
29546 1837 : break;
29547 1837 : case DW_MACINFO_end_file:
29548 1837 : dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
29549 1837 : break;
29550 240747 : case DW_MACINFO_define:
29551 240747 : case DW_MACINFO_undef:
29552 240747 : len = strlen (ref->info) + 1;
29553 240747 : if ((!dwarf_strict || dwarf_version >= 5)
29554 240747 : && len > (size_t) dwarf_offset_size
29555 : && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29556 240731 : && (debug_str_section->common.flags & SECTION_MERGE) != 0)
29557 : {
29558 240731 : if (dwarf_split_debug_info)
29559 1671 : ref->code = ref->code == DW_MACINFO_define
29560 : ? DW_MACRO_define_strx : DW_MACRO_undef_strx;
29561 : else
29562 239638 : ref->code = ref->code == DW_MACINFO_define
29563 : ? DW_MACRO_define_strp : DW_MACRO_undef_strp;
29564 240731 : output_macinfo_op (ref);
29565 : return;
29566 : }
29567 30 : dw2_asm_output_data (1, ref->code,
29568 : ref->code == DW_MACINFO_define
29569 : ? "Define macro" : "Undefine macro");
29570 16 : dw2_asm_output_data_uleb128 (ref->lineno,
29571 : "At line number "
29572 : HOST_WIDE_INT_PRINT_UNSIGNED,
29573 : ref->lineno);
29574 16 : dw2_asm_output_nstring (ref->info, -1, "The macro");
29575 16 : break;
29576 238482 : case DW_MACRO_define_strp:
29577 238482 : dw2_asm_output_data (1, ref->code, "Define macro strp");
29578 238482 : goto do_DW_MACRO_define_strpx;
29579 578 : case DW_MACRO_undef_strp:
29580 578 : dw2_asm_output_data (1, ref->code, "Undefine macro strp");
29581 578 : goto do_DW_MACRO_define_strpx;
29582 1671 : case DW_MACRO_define_strx:
29583 1671 : dw2_asm_output_data (1, ref->code, "Define macro strx");
29584 1671 : goto do_DW_MACRO_define_strpx;
29585 0 : case DW_MACRO_undef_strx:
29586 0 : dw2_asm_output_data (1, ref->code, "Undefine macro strx");
29587 : /* FALLTHRU */
29588 240731 : do_DW_MACRO_define_strpx:
29589 : /* NB: dwarf2out_finish performs:
29590 : 1. save_macinfo_strings
29591 : 2. hash table traverse of index_string
29592 : 3. output_macinfo -> output_macinfo_op
29593 : 4. output_indirect_strings
29594 : -> hash table traverse of output_index_string
29595 :
29596 : When output_macinfo_op is called, all index strings have been
29597 : added to hash table by save_macinfo_strings and we can't pass
29598 : INSERT to find_slot_with_hash which may expand hash table, even
29599 : if no insertion is needed, and change hash table traverse order
29600 : between index_string and output_index_string. */
29601 240731 : node = find_AT_string (ref->info, NO_INSERT);
29602 241140 : gcc_assert (node
29603 : && (node->form == DW_FORM_strp
29604 : || node->form == dwarf_FORM (DW_FORM_strx)));
29605 240731 : dw2_asm_output_data_uleb128 (ref->lineno,
29606 : "At line number "
29607 : HOST_WIDE_INT_PRINT_UNSIGNED,
29608 : ref->lineno);
29609 240731 : if (node->form == DW_FORM_strp)
29610 : {
29611 239060 : gcc_assert (ref->code == DW_MACRO_define_strp
29612 : || ref->code == DW_MACRO_undef_strp);
29613 239060 : dw2_asm_output_offset (dwarf_offset_size, node->label,
29614 : debug_str_section, "The macro: \"%s\"",
29615 : ref->info);
29616 : }
29617 : else
29618 : {
29619 1671 : gcc_assert (ref->code == DW_MACRO_define_strx
29620 : || ref->code == DW_MACRO_undef_strx);
29621 1671 : dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
29622 : ref->info);
29623 : }
29624 : break;
29625 1624 : case DW_MACRO_import:
29626 1624 : dw2_asm_output_data (1, ref->code, "Import");
29627 1624 : ASM_GENERATE_INTERNAL_LABEL (label,
29628 : DEBUG_MACRO_SECTION_LABEL,
29629 : ref->lineno + macinfo_label_base);
29630 1624 : dw2_asm_output_offset (dwarf_offset_size, label, NULL, NULL);
29631 1624 : break;
29632 0 : default:
29633 0 : fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
29634 : ASM_COMMENT_START, (unsigned long) ref->code);
29635 0 : break;
29636 : }
29637 : }
29638 :
29639 : /* Attempt to make a sequence of define/undef macinfo ops shareable with
29640 : other compilation unit .debug_macinfo sections. IDX is the first
29641 : index of a define/undef, return the number of ops that should be
29642 : emitted in a comdat .debug_macinfo section and emit
29643 : a DW_MACRO_import entry referencing it.
29644 : If the define/undef entry should be emitted normally, return 0. */
29645 :
29646 : static unsigned
29647 2004 : optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
29648 : macinfo_hash_type **macinfo_htab)
29649 : {
29650 2004 : macinfo_entry *first, *second, *cur, *inc;
29651 2004 : char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
29652 2004 : unsigned char checksum[16];
29653 2004 : struct md5_ctx ctx;
29654 2004 : char *grp_name, *tail;
29655 2004 : const char *base;
29656 2004 : unsigned int i, count, encoded_filename_len, linebuf_len;
29657 2004 : macinfo_entry **slot;
29658 :
29659 2004 : first = &(*macinfo_table)[idx];
29660 2004 : second = &(*macinfo_table)[idx + 1];
29661 :
29662 : /* Optimize only if there are at least two consecutive define/undef ops,
29663 : and either all of them are before first DW_MACINFO_start_file
29664 : with lineno {0,1} (i.e. predefined macro block), or all of them are
29665 : in some included header file. */
29666 2004 : if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
29667 : return 0;
29668 1624 : if (vec_safe_is_empty (files))
29669 : {
29670 514 : if (first->lineno > 1 || second->lineno > 1)
29671 : return 0;
29672 : }
29673 1110 : else if (first->lineno == 0)
29674 : return 0;
29675 :
29676 : /* Find the last define/undef entry that can be grouped together
29677 : with first and at the same time compute md5 checksum of their
29678 : codes, linenumbers and strings. */
29679 1624 : md5_init_ctx (&ctx);
29680 240685 : for (i = idx; macinfo_table->iterate (i, &cur); i++)
29681 240685 : if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
29682 : break;
29683 239061 : else if (vec_safe_is_empty (files) && cur->lineno > 1)
29684 : break;
29685 : else
29686 : {
29687 239061 : unsigned char code = cur->code;
29688 239061 : md5_process_bytes (&code, 1, &ctx);
29689 239061 : checksum_uleb128 (cur->lineno, &ctx);
29690 239061 : md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
29691 : }
29692 1624 : md5_finish_ctx (&ctx, checksum);
29693 1624 : count = i - idx;
29694 :
29695 : /* From the containing include filename (if any) pick up just
29696 : usable characters from its basename. */
29697 1624 : if (vec_safe_is_empty (files))
29698 : base = "";
29699 : else
29700 1110 : base = lbasename (files->last ().info);
29701 14282 : for (encoded_filename_len = 0, i = 0; base[i]; i++)
29702 12658 : if (ISIDNUM (base[i]) || base[i] == '.')
29703 12034 : encoded_filename_len++;
29704 : /* Count . at the end. */
29705 1624 : if (encoded_filename_len)
29706 1110 : encoded_filename_len++;
29707 :
29708 1624 : sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
29709 1624 : linebuf_len = strlen (linebuf);
29710 :
29711 : /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
29712 1624 : grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
29713 : + 16 * 2 + 1);
29714 1624 : memcpy (grp_name, dwarf_offset_size == 4 ? "wm4." : "wm8.", 4);
29715 1624 : tail = grp_name + 4;
29716 1624 : if (encoded_filename_len)
29717 : {
29718 13768 : for (i = 0; base[i]; i++)
29719 12658 : if (ISIDNUM (base[i]) || base[i] == '.')
29720 12034 : *tail++ = base[i];
29721 1110 : *tail++ = '.';
29722 : }
29723 1624 : memcpy (tail, linebuf, linebuf_len);
29724 1624 : tail += linebuf_len;
29725 1624 : *tail++ = '.';
29726 27608 : for (i = 0; i < 16; i++)
29727 25984 : sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
29728 :
29729 : /* Construct a macinfo_entry for DW_MACRO_import
29730 : in the empty vector entry before the first define/undef. */
29731 1624 : inc = &(*macinfo_table)[idx - 1];
29732 1624 : inc->code = DW_MACRO_import;
29733 1624 : inc->lineno = 0;
29734 1624 : inc->info = ggc_strdup (grp_name);
29735 1624 : if (!*macinfo_htab)
29736 515 : *macinfo_htab = new macinfo_hash_type (10);
29737 : /* Avoid emitting duplicates. */
29738 1624 : slot = (*macinfo_htab)->find_slot (inc, INSERT);
29739 1624 : if (*slot != NULL)
29740 : {
29741 107 : inc->code = 0;
29742 107 : inc->info = NULL;
29743 : /* If such an entry has been used before, just emit
29744 : a DW_MACRO_import op. */
29745 107 : inc = *slot;
29746 107 : output_macinfo_op (inc);
29747 : /* And clear all macinfo_entry in the range to avoid emitting them
29748 : in the second pass. */
29749 660 : for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
29750 : {
29751 446 : cur->code = 0;
29752 446 : cur->info = NULL;
29753 : }
29754 : }
29755 : else
29756 : {
29757 1517 : *slot = inc;
29758 1517 : inc->lineno = (*macinfo_htab)->elements ();
29759 1517 : output_macinfo_op (inc);
29760 : }
29761 : return count;
29762 : }
29763 :
29764 : /* Save any strings needed by the macinfo table in the debug str
29765 : table. All strings must be collected into the table by the time
29766 : index_string is called. */
29767 :
29768 : static void
29769 53407 : save_macinfo_strings (void)
29770 : {
29771 53407 : unsigned len;
29772 53407 : unsigned i;
29773 53407 : macinfo_entry *ref;
29774 :
29775 298792 : for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
29776 : {
29777 245385 : switch (ref->code)
29778 : {
29779 : /* Match the logic in output_macinfo_op to decide on
29780 : indirect strings. */
29781 241193 : case DW_MACINFO_define:
29782 241193 : case DW_MACINFO_undef:
29783 241193 : len = strlen (ref->info) + 1;
29784 241193 : if ((!dwarf_strict || dwarf_version >= 5)
29785 241193 : && len > (unsigned) dwarf_offset_size
29786 : && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29787 241176 : && (debug_str_section->common.flags & SECTION_MERGE) != 0)
29788 241176 : set_indirect_string (find_AT_string (ref->info));
29789 : break;
29790 1837 : case DW_MACINFO_start_file:
29791 : /* -gsplit-dwarf -g3 will also output filename as indirect
29792 : string. */
29793 1837 : if (!dwarf_split_debug_info)
29794 : break;
29795 : /* Fall through. */
29796 8 : case DW_MACRO_define_strp:
29797 8 : case DW_MACRO_undef_strp:
29798 8 : case DW_MACRO_define_strx:
29799 8 : case DW_MACRO_undef_strx:
29800 8 : set_indirect_string (find_AT_string (ref->info));
29801 8 : break;
29802 : default:
29803 : break;
29804 : }
29805 : }
29806 53407 : }
29807 :
29808 : /* Output macinfo section(s). */
29809 :
29810 : static void
29811 527 : output_macinfo (const char *debug_line_label, bool early_lto_debug)
29812 : {
29813 527 : unsigned i;
29814 527 : unsigned long length = vec_safe_length (macinfo_table);
29815 527 : macinfo_entry *ref;
29816 527 : vec<macinfo_entry, va_gc> *files = NULL;
29817 527 : macinfo_hash_type *macinfo_htab = NULL;
29818 527 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
29819 :
29820 527 : if (! length)
29821 12 : return;
29822 :
29823 : /* output_macinfo* uses these interchangeably. */
29824 527 : gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_define
29825 : && (int) DW_MACINFO_undef == (int) DW_MACRO_undef
29826 : && (int) DW_MACINFO_start_file == (int) DW_MACRO_start_file
29827 : && (int) DW_MACINFO_end_file == (int) DW_MACRO_end_file);
29828 :
29829 : /* AIX Assembler inserts the length, so adjust the reference to match the
29830 : offset expected by debuggers. */
29831 527 : strcpy (dl_section_ref, debug_line_label);
29832 527 : if (XCOFF_DEBUGGING_INFO)
29833 : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
29834 :
29835 : /* For .debug_macro emit the section header. */
29836 527 : if (!dwarf_strict || dwarf_version >= 5)
29837 : {
29838 1032 : dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
29839 : "DWARF macro version number");
29840 527 : if (dwarf_offset_size == 8)
29841 0 : dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
29842 : else
29843 527 : dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
29844 527 : dw2_asm_output_offset (dwarf_offset_size, debug_line_label,
29845 : debug_line_section, NULL);
29846 : }
29847 :
29848 : /* In the first loop, it emits the primary .debug_macinfo section
29849 : and after each emitted op the macinfo_entry is cleared.
29850 : If a longer range of define/undef ops can be optimized using
29851 : DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
29852 : the vector before the first define/undef in the range and the
29853 : whole range of define/undef ops is not emitted and kept. */
29854 8475 : for (i = 0; macinfo_table->iterate (i, &ref); i++)
29855 : {
29856 7948 : switch (ref->code)
29857 : {
29858 1837 : case DW_MACINFO_start_file:
29859 1837 : vec_safe_push (files, *ref);
29860 1837 : break;
29861 1837 : case DW_MACINFO_end_file:
29862 1837 : if (!vec_safe_is_empty (files))
29863 1837 : files->pop ();
29864 : break;
29865 3756 : case DW_MACINFO_define:
29866 3756 : case DW_MACINFO_undef:
29867 0 : if ((!dwarf_strict || dwarf_version >= 5)
29868 3756 : && !dwarf_split_debug_info
29869 : && HAVE_COMDAT_GROUP
29870 2085 : && vec_safe_length (files) != 1
29871 2004 : && i > 0
29872 2004 : && i + 1 < length
29873 5760 : && (*macinfo_table)[i - 1].code == 0)
29874 : {
29875 2004 : unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
29876 2004 : if (count)
29877 : {
29878 1624 : i += count - 1;
29879 1624 : continue;
29880 : }
29881 : }
29882 : break;
29883 518 : case 0:
29884 : /* A dummy entry may be inserted at the beginning to be able
29885 : to optimize the whole block of predefined macros. */
29886 518 : if (i == 0)
29887 518 : continue;
29888 : default:
29889 : break;
29890 : }
29891 5806 : output_macinfo_op (ref);
29892 5806 : ref->info = NULL;
29893 5806 : ref->code = 0;
29894 : }
29895 :
29896 527 : if (!macinfo_htab)
29897 : return;
29898 :
29899 : /* Save the number of transparent includes so we can adjust the
29900 : label number for the fat LTO object DWARF. */
29901 515 : unsigned macinfo_label_base_adj = macinfo_htab->elements ();
29902 :
29903 515 : delete macinfo_htab;
29904 515 : macinfo_htab = NULL;
29905 :
29906 : /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
29907 : terminate the current chain and switch to a new comdat .debug_macinfo
29908 : section and emit the define/undef entries within it. */
29909 244161 : for (i = 0; macinfo_table->iterate (i, &ref); i++)
29910 243646 : switch (ref->code)
29911 : {
29912 3514 : case 0:
29913 3514 : continue;
29914 1517 : case DW_MACRO_import:
29915 1517 : {
29916 1517 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29917 1517 : tree comdat_key = get_identifier (ref->info);
29918 : /* Terminate the previous .debug_macinfo section. */
29919 1517 : dw2_asm_output_data (1, 0, "End compilation unit");
29920 3004 : targetm.asm_out.named_section (debug_macinfo_section_name,
29921 : SECTION_DEBUG
29922 : | SECTION_LINKONCE
29923 : | (early_lto_debug
29924 : ? SECTION_EXCLUDE : 0),
29925 : comdat_key);
29926 1517 : ASM_GENERATE_INTERNAL_LABEL (label,
29927 : DEBUG_MACRO_SECTION_LABEL,
29928 : ref->lineno + macinfo_label_base);
29929 1517 : ASM_OUTPUT_LABEL (asm_out_file, label);
29930 1517 : ref->code = 0;
29931 1517 : ref->info = NULL;
29932 2515 : dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
29933 : "DWARF macro version number");
29934 1517 : if (dwarf_offset_size == 8)
29935 0 : dw2_asm_output_data (1, 1, "Flags: 64-bit");
29936 : else
29937 1517 : dw2_asm_output_data (1, 0, "Flags: 32-bit");
29938 : }
29939 1517 : break;
29940 238615 : case DW_MACINFO_define:
29941 238615 : case DW_MACINFO_undef:
29942 238615 : output_macinfo_op (ref);
29943 238615 : ref->code = 0;
29944 238615 : ref->info = NULL;
29945 238615 : break;
29946 0 : default:
29947 0 : gcc_unreachable ();
29948 3514 : }
29949 :
29950 515 : macinfo_label_base += macinfo_label_base_adj;
29951 : }
29952 :
29953 : /* As init_sections_and_labels may get called multiple times, have a
29954 : generation count for labels. */
29955 : static unsigned init_sections_and_labels_generation;
29956 :
29957 : /* Initialize the various sections and labels for dwarf output and prefix
29958 : them with PREFIX if non-NULL. Returns the generation (zero based
29959 : number of times function was called). */
29960 :
29961 : static unsigned
29962 53407 : init_sections_and_labels (bool early_lto_debug)
29963 : {
29964 53407 : if (early_lto_debug)
29965 : {
29966 1327 : if (!dwarf_split_debug_info)
29967 : {
29968 1327 : debug_info_section = get_section (DEBUG_LTO_INFO_SECTION,
29969 : SECTION_DEBUG | SECTION_EXCLUDE,
29970 : NULL);
29971 1327 : debug_abbrev_section = get_section (DEBUG_LTO_ABBREV_SECTION,
29972 : SECTION_DEBUG | SECTION_EXCLUDE,
29973 : NULL);
29974 1327 : debug_macinfo_section_name
29975 0 : = ((dwarf_strict && dwarf_version < 5)
29976 1327 : ? DEBUG_LTO_MACINFO_SECTION : DEBUG_LTO_MACRO_SECTION);
29977 1327 : debug_macinfo_section = get_section (debug_macinfo_section_name,
29978 : SECTION_DEBUG
29979 : | SECTION_EXCLUDE, NULL);
29980 : }
29981 : else
29982 : {
29983 : /* ??? Which of the following do we need early? */
29984 0 : debug_info_section = get_section (DEBUG_LTO_DWO_INFO_SECTION,
29985 : SECTION_DEBUG | SECTION_EXCLUDE,
29986 : NULL);
29987 0 : debug_abbrev_section = get_section (DEBUG_LTO_DWO_ABBREV_SECTION,
29988 : SECTION_DEBUG | SECTION_EXCLUDE,
29989 : NULL);
29990 0 : debug_skeleton_info_section = get_section (DEBUG_LTO_INFO_SECTION,
29991 : SECTION_DEBUG
29992 : | SECTION_EXCLUDE, NULL);
29993 0 : debug_skeleton_abbrev_section
29994 0 : = get_section (DEBUG_LTO_ABBREV_SECTION,
29995 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29996 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
29997 : DEBUG_SKELETON_ABBREV_SECTION_LABEL,
29998 : init_sections_and_labels_generation);
29999 :
30000 : /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
30001 : stay in the main .o, but the skeleton_line goes into the split
30002 : off dwo. */
30003 0 : debug_skeleton_line_section
30004 0 : = get_section (DEBUG_LTO_LINE_SECTION,
30005 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30006 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
30007 : DEBUG_SKELETON_LINE_SECTION_LABEL,
30008 : init_sections_and_labels_generation);
30009 0 : debug_str_offsets_section
30010 0 : = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION,
30011 : SECTION_DEBUG | SECTION_EXCLUDE,
30012 : NULL);
30013 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
30014 : DEBUG_SKELETON_INFO_SECTION_LABEL,
30015 : init_sections_and_labels_generation);
30016 0 : debug_str_dwo_section = get_section (DEBUG_LTO_STR_DWO_SECTION,
30017 : DEBUG_STR_DWO_SECTION_FLAGS,
30018 : NULL);
30019 0 : debug_macinfo_section_name
30020 0 : = ((dwarf_strict && dwarf_version < 5)
30021 0 : ? DEBUG_LTO_DWO_MACINFO_SECTION : DEBUG_LTO_DWO_MACRO_SECTION);
30022 0 : debug_macinfo_section = get_section (debug_macinfo_section_name,
30023 : SECTION_DEBUG | SECTION_EXCLUDE,
30024 : NULL);
30025 : }
30026 : /* For macro info and the file table we have to refer to a
30027 : debug_line section. */
30028 1327 : debug_line_section = get_section (DEBUG_LTO_LINE_SECTION,
30029 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30030 1327 : ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
30031 : DEBUG_LINE_SECTION_LABEL,
30032 : init_sections_and_labels_generation);
30033 :
30034 1327 : debug_str_section = get_section (DEBUG_LTO_STR_SECTION,
30035 1327 : DEBUG_STR_SECTION_FLAGS
30036 : | SECTION_EXCLUDE, NULL);
30037 1327 : if (!dwarf_split_debug_info)
30038 1327 : debug_line_str_section
30039 1327 : = get_section (DEBUG_LTO_LINE_STR_SECTION,
30040 1327 : DEBUG_STR_SECTION_FLAGS | SECTION_EXCLUDE, NULL);
30041 : }
30042 : else
30043 : {
30044 52080 : if (!dwarf_split_debug_info)
30045 : {
30046 51831 : debug_info_section = get_section (DEBUG_INFO_SECTION,
30047 : SECTION_DEBUG, NULL);
30048 51831 : debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
30049 : SECTION_DEBUG, NULL);
30050 53835 : debug_loc_section = get_section (dwarf_version >= 5
30051 : ? DEBUG_LOCLISTS_SECTION
30052 : : DEBUG_LOC_SECTION,
30053 : SECTION_DEBUG, NULL);
30054 51831 : debug_macinfo_section_name
30055 5 : = ((dwarf_strict && dwarf_version < 5)
30056 51831 : ? DEBUG_MACINFO_SECTION : DEBUG_MACRO_SECTION);
30057 51831 : debug_macinfo_section = get_section (debug_macinfo_section_name,
30058 : SECTION_DEBUG, NULL);
30059 : }
30060 : else
30061 : {
30062 249 : debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
30063 : SECTION_DEBUG | SECTION_EXCLUDE,
30064 : NULL);
30065 249 : debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
30066 : SECTION_DEBUG | SECTION_EXCLUDE,
30067 : NULL);
30068 249 : debug_addr_section = get_section (DEBUG_ADDR_SECTION,
30069 : SECTION_DEBUG, NULL);
30070 249 : debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
30071 : SECTION_DEBUG, NULL);
30072 249 : debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
30073 : SECTION_DEBUG, NULL);
30074 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
30075 : DEBUG_SKELETON_ABBREV_SECTION_LABEL,
30076 : init_sections_and_labels_generation);
30077 :
30078 : /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
30079 : stay in the main .o, but the skeleton_line goes into the
30080 : split off dwo. */
30081 249 : debug_skeleton_line_section
30082 249 : = get_section (DEBUG_DWO_LINE_SECTION,
30083 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30084 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
30085 : DEBUG_SKELETON_LINE_SECTION_LABEL,
30086 : init_sections_and_labels_generation);
30087 249 : debug_str_offsets_section
30088 249 : = get_section (DEBUG_DWO_STR_OFFSETS_SECTION,
30089 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30090 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
30091 : DEBUG_SKELETON_INFO_SECTION_LABEL,
30092 : init_sections_and_labels_generation);
30093 250 : debug_loc_section = get_section (dwarf_version >= 5
30094 : ? DEBUG_DWO_LOCLISTS_SECTION
30095 : : DEBUG_DWO_LOC_SECTION,
30096 : SECTION_DEBUG | SECTION_EXCLUDE,
30097 : NULL);
30098 249 : debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
30099 : DEBUG_STR_DWO_SECTION_FLAGS,
30100 : NULL);
30101 249 : debug_macinfo_section_name
30102 0 : = ((dwarf_strict && dwarf_version < 5)
30103 249 : ? DEBUG_DWO_MACINFO_SECTION : DEBUG_DWO_MACRO_SECTION);
30104 249 : debug_macinfo_section = get_section (debug_macinfo_section_name,
30105 : SECTION_DEBUG | SECTION_EXCLUDE,
30106 : NULL);
30107 249 : if (dwarf_version >= 5)
30108 248 : debug_ranges_dwo_section
30109 248 : = get_section (DEBUG_DWO_RNGLISTS_SECTION,
30110 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30111 : }
30112 52080 : debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
30113 : SECTION_DEBUG, NULL);
30114 52080 : debug_line_section = get_section (DEBUG_LINE_SECTION,
30115 : SECTION_DEBUG, NULL);
30116 103911 : debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
30117 : SECTION_DEBUG, NULL);
30118 103911 : debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
30119 : SECTION_DEBUG, NULL);
30120 52080 : debug_str_section = get_section (DEBUG_STR_SECTION,
30121 52080 : DEBUG_STR_SECTION_FLAGS, NULL);
30122 51831 : if ((!dwarf_split_debug_info && !output_asm_line_debug_info ())
30123 103905 : || asm_outputs_debug_line_str ())
30124 49830 : debug_line_str_section = get_section (DEBUG_LINE_STR_SECTION,
30125 49830 : DEBUG_STR_SECTION_FLAGS, NULL);
30126 :
30127 54085 : debug_ranges_section = get_section (dwarf_version >= 5
30128 : ? DEBUG_RNGLISTS_SECTION
30129 : : DEBUG_RANGES_SECTION,
30130 : SECTION_DEBUG, NULL);
30131 52080 : debug_frame_section = get_section (DEBUG_FRAME_SECTION,
30132 : SECTION_DEBUG, NULL);
30133 : }
30134 :
30135 53407 : ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
30136 : DEBUG_ABBREV_SECTION_LABEL,
30137 : init_sections_and_labels_generation);
30138 53407 : ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
30139 : DEBUG_INFO_SECTION_LABEL,
30140 : init_sections_and_labels_generation);
30141 53407 : info_section_emitted = false;
30142 53407 : ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
30143 : DEBUG_LINE_SECTION_LABEL,
30144 : init_sections_and_labels_generation);
30145 : /* There are up to 6 unique ranges labels per generation.
30146 : See also output_rnglists. */
30147 53407 : ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
30148 : DEBUG_RANGES_SECTION_LABEL,
30149 : init_sections_and_labels_generation * 6);
30150 53407 : if (dwarf_version >= 5 && dwarf_split_debug_info)
30151 248 : ASM_GENERATE_INTERNAL_LABEL (ranges_base_label,
30152 : DEBUG_RANGES_SECTION_LABEL,
30153 : 1 + init_sections_and_labels_generation * 6);
30154 53407 : ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
30155 : DEBUG_ADDR_SECTION_LABEL,
30156 : init_sections_and_labels_generation);
30157 106809 : ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
30158 : (dwarf_strict && dwarf_version < 5)
30159 : ? DEBUG_MACINFO_SECTION_LABEL
30160 : : DEBUG_MACRO_SECTION_LABEL,
30161 : init_sections_and_labels_generation);
30162 53407 : ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL,
30163 : init_sections_and_labels_generation);
30164 :
30165 53407 : ++init_sections_and_labels_generation;
30166 53407 : return init_sections_and_labels_generation - 1;
30167 : }
30168 :
30169 : /* Set up for Dwarf output at the start of compilation. */
30170 :
30171 : static void
30172 55489 : dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
30173 : {
30174 : /* Allocate the file_table. */
30175 55489 : file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
30176 :
30177 : #ifndef DWARF2_LINENO_DEBUGGING_INFO
30178 : /* Allocate the decl_die_table. */
30179 55489 : decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
30180 :
30181 : /* Allocate the decl_loc_table. */
30182 55489 : decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
30183 :
30184 : /* Allocate the cached_dw_loc_list_table. */
30185 55489 : cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
30186 :
30187 : /* Allocate the initial hunk of the abbrev_die_table. */
30188 55489 : vec_alloc (abbrev_die_table, 256);
30189 : /* Zero-th entry is allocated, but unused. */
30190 55489 : abbrev_die_table->quick_push (NULL);
30191 :
30192 : /* Allocate the dwarf_proc_stack_usage_map. */
30193 55489 : dwarf_proc_stack_usage_map = new hash_map<dw_die_ref, int>;
30194 :
30195 : /* Allocate the pubtypes and pubnames vectors. */
30196 55489 : vec_alloc (pubname_table, 32);
30197 55489 : vec_alloc (pubtype_table, 32);
30198 :
30199 55489 : vec_alloc (incomplete_types, 64);
30200 :
30201 55489 : vec_alloc (used_rtx_array, 32);
30202 :
30203 55489 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
30204 533 : vec_alloc (macinfo_table, 64);
30205 : #endif
30206 :
30207 : /* If front-ends already registered a main translation unit but we were not
30208 : ready to perform the association, do this now. */
30209 55489 : if (main_translation_unit != NULL_TREE)
30210 17450 : equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
30211 55489 : }
30212 :
30213 : /* Called before compile () starts outputtting functions, variables
30214 : and toplevel asms into assembly. */
30215 :
30216 : static void
30217 52412 : dwarf2out_assembly_start (void)
30218 : {
30219 52412 : if (text_section_line_info)
30220 : return;
30221 :
30222 : #ifndef DWARF2_LINENO_DEBUGGING_INFO
30223 52411 : ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
30224 52411 : ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
30225 52411 : ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
30226 : COLD_TEXT_SECTION_LABEL, 0);
30227 52411 : ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
30228 :
30229 52411 : switch_to_section (text_section);
30230 52411 : ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
30231 : #endif
30232 :
30233 : /* Make sure the line number table for .text always exists. */
30234 52411 : text_section_line_info = new_line_info_table ();
30235 52411 : text_section_line_info->end_label = text_end_label;
30236 :
30237 : #ifdef DWARF2_LINENO_DEBUGGING_INFO
30238 : cur_line_info_table = text_section_line_info;
30239 : #endif
30240 :
30241 52411 : if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
30242 52411 : && dwarf2out_do_cfi_asm ()
30243 52411 : && !dwarf2out_do_eh_frame ())
30244 5 : fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
30245 :
30246 : #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
30247 52411 : if (output_asm_line_debug_info () && dwarf_version >= 5)
30248 : {
30249 : /* When gas outputs DWARF5 .debug_line[_str] then we have to
30250 : tell it the comp_dir and main file name for the zero entry
30251 : line table. */
30252 50403 : const char *comp_dir, *filename0;
30253 :
30254 50403 : comp_dir = comp_dir_string ();
30255 50403 : if (comp_dir == NULL)
30256 0 : comp_dir = "";
30257 :
30258 50403 : filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
30259 50403 : if (filename0 == NULL)
30260 1 : filename0 = "";
30261 :
30262 50403 : fprintf (asm_out_file, "\t.file 0 ");
30263 50403 : output_quoted_string (asm_out_file, remap_debug_filename (comp_dir));
30264 50403 : fputc (' ', asm_out_file);
30265 50403 : output_quoted_string (asm_out_file, remap_debug_filename (filename0));
30266 50403 : fputc ('\n', asm_out_file);
30267 : }
30268 : else
30269 : #endif
30270 : /* Work around for PR101575: output a dummy .file directive. */
30271 1998 : if (!last_emitted_file && dwarf_debuginfo_p ()
30272 4006 : && debug_info_level >= DINFO_LEVEL_TERSE)
30273 : {
30274 1998 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
30275 :
30276 1998 : if (filename0 == NULL)
30277 0 : filename0 = "<dummy>";
30278 1998 : maybe_emit_file (lookup_filename (filename0));
30279 : }
30280 : }
30281 :
30282 : /* A helper function for dwarf2out_finish called through
30283 : htab_traverse. Assign a string its index. All strings must be
30284 : collected into the table by the time index_string is called,
30285 : because the indexing code relies on htab_traverse to traverse nodes
30286 : in the same order for each run. */
30287 :
30288 : int
30289 2927 : index_string (indirect_string_node **h, unsigned int *index)
30290 : {
30291 2927 : indirect_string_node *node = *h;
30292 :
30293 2927 : find_string_form (node);
30294 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30295 : {
30296 2610 : gcc_assert (node->index == NO_INDEX_ASSIGNED);
30297 2610 : node->index = *index;
30298 2610 : *index += 1;
30299 : }
30300 2927 : return 1;
30301 : }
30302 :
30303 : /* A helper function for output_indirect_strings called through
30304 : htab_traverse. Output the offset to a string and update the
30305 : current offset. */
30306 :
30307 : int
30308 2927 : output_index_string_offset (indirect_string_node **h, unsigned int *offset)
30309 : {
30310 2927 : indirect_string_node *node = *h;
30311 :
30312 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30313 : {
30314 : /* Assert that this node has been assigned an index. */
30315 2610 : gcc_assert (node->index != NO_INDEX_ASSIGNED
30316 : && node->index != NOT_INDEXED);
30317 2610 : dw2_asm_output_data (dwarf_offset_size, *offset,
30318 : "indexed string 0x%x: %s", node->index, node->str);
30319 2610 : *offset += strlen (node->str) + 1;
30320 : }
30321 2927 : return 1;
30322 : }
30323 :
30324 : /* A helper function for dwarf2out_finish called through
30325 : htab_traverse. Output the indexed string. */
30326 :
30327 : int
30328 2927 : output_index_string (indirect_string_node **h, unsigned int *cur_idx)
30329 : {
30330 2927 : struct indirect_string_node *node = *h;
30331 :
30332 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30333 : {
30334 : /* Assert that the strings are output in the same order as their
30335 : indexes were assigned. */
30336 2610 : gcc_assert (*cur_idx == node->index);
30337 2610 : assemble_string (node->str, strlen (node->str) + 1);
30338 2610 : *cur_idx += 1;
30339 : }
30340 2927 : return 1;
30341 : }
30342 :
30343 : /* A helper function for output_indirect_strings. Counts the number
30344 : of index strings offsets. Must match the logic of the functions
30345 : output_index_string[_offsets] above. */
30346 : int
30347 2514 : count_index_strings (indirect_string_node **h, unsigned int *last_idx)
30348 : {
30349 2514 : struct indirect_string_node *node = *h;
30350 :
30351 2514 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30352 2197 : *last_idx += 1;
30353 2514 : return 1;
30354 : }
30355 :
30356 : /* A helper function for dwarf2out_finish called through
30357 : htab_traverse. Emit one queued .debug_str string. */
30358 :
30359 : int
30360 20208665 : output_indirect_string (indirect_string_node **h, enum dwarf_form form)
30361 : {
30362 20208665 : struct indirect_string_node *node = *h;
30363 :
30364 20208665 : node->form = find_string_form (node);
30365 20208665 : if (node->form == form && node->refcount > 0)
30366 : {
30367 19513998 : ASM_OUTPUT_LABEL (asm_out_file, node->label);
30368 19513998 : assemble_string (node->str, strlen (node->str) + 1);
30369 : }
30370 :
30371 20208665 : return 1;
30372 : }
30373 :
30374 : /* Output the indexed string table. */
30375 :
30376 : static void
30377 53407 : output_indirect_strings (void)
30378 : {
30379 53407 : switch_to_section (debug_str_section);
30380 53407 : if (!dwarf_split_debug_info)
30381 53158 : debug_str_hash->traverse<enum dwarf_form,
30382 20261823 : output_indirect_string> (DW_FORM_strp);
30383 : else
30384 : {
30385 249 : unsigned int offset = 0;
30386 249 : unsigned int cur_idx = 0;
30387 :
30388 249 : if (skeleton_debug_str_hash)
30389 249 : skeleton_debug_str_hash->traverse<enum dwarf_form,
30390 249 : output_indirect_string> (DW_FORM_strp);
30391 :
30392 249 : switch_to_section (debug_str_offsets_section);
30393 : /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
30394 : header. Note that we don't need to generate a label to the
30395 : actual index table following the header here, because this is
30396 : for the split dwarf case only. In an .dwo file there is only
30397 : one string offsets table (and one debug info section). But
30398 : if we would start using string offset tables for the main (or
30399 : skeleton) unit, then we have to add a DW_AT_str_offsets_base
30400 : pointing to the actual index after the header. Split dwarf
30401 : units will never have a string offsets base attribute. When
30402 : a split unit is moved into a .dwp file the string offsets can
30403 : be found through the .debug_cu_index section table. */
30404 249 : if (dwarf_version >= 5)
30405 : {
30406 248 : unsigned int last_idx = 0;
30407 248 : unsigned long str_offsets_length;
30408 :
30409 248 : debug_str_hash->traverse_noresize
30410 2762 : <unsigned int *, count_index_strings> (&last_idx);
30411 248 : str_offsets_length = last_idx * dwarf_offset_size + 4;
30412 248 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
30413 0 : dw2_asm_output_data (4, 0xffffffff,
30414 : "Escape value for 64-bit DWARF extension");
30415 248 : dw2_asm_output_data (dwarf_offset_size, str_offsets_length,
30416 : "Length of string offsets unit");
30417 248 : dw2_asm_output_data (2, 5, "DWARF string offsets version");
30418 248 : dw2_asm_output_data (2, 0, "Header zero padding");
30419 : }
30420 249 : debug_str_hash->traverse_noresize
30421 3176 : <unsigned int *, output_index_string_offset> (&offset);
30422 249 : switch_to_section (debug_str_dwo_section);
30423 249 : debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
30424 3176 : (&cur_idx);
30425 : }
30426 53407 : }
30427 :
30428 : /* Callback for htab_traverse to assign an index to an entry in the
30429 : table, and to write that entry to the .debug_addr section. */
30430 :
30431 : int
30432 264 : output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
30433 : {
30434 264 : addr_table_entry *entry = *slot;
30435 :
30436 264 : if (entry->refcount == 0)
30437 : {
30438 0 : gcc_assert (entry->index == NO_INDEX_ASSIGNED
30439 : || entry->index == NOT_INDEXED);
30440 : return 1;
30441 : }
30442 :
30443 264 : gcc_assert (entry->index == *cur_index);
30444 264 : (*cur_index)++;
30445 :
30446 264 : switch (entry->kind)
30447 : {
30448 3 : case ate_kind_rtx:
30449 3 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
30450 : "0x%x", entry->index);
30451 3 : break;
30452 0 : case ate_kind_rtx_dtprel:
30453 0 : gcc_assert (targetm.asm_out.output_dwarf_dtprel);
30454 0 : targetm.asm_out.output_dwarf_dtprel (asm_out_file,
30455 0 : DWARF2_ADDR_SIZE,
30456 : entry->addr.rtl);
30457 0 : fputc ('\n', asm_out_file);
30458 0 : break;
30459 261 : case ate_kind_label:
30460 261 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
30461 : "0x%x", entry->index);
30462 261 : break;
30463 0 : default:
30464 0 : gcc_unreachable ();
30465 : }
30466 : return 1;
30467 : }
30468 :
30469 : /* A helper function for dwarf2out_finish. Counts the number
30470 : of indexed addresses. Must match the logic of the functions
30471 : output_addr_table_entry above. */
30472 : int
30473 264 : count_index_addrs (addr_table_entry **slot, unsigned int *last_idx)
30474 : {
30475 264 : addr_table_entry *entry = *slot;
30476 :
30477 264 : if (entry->refcount > 0)
30478 264 : *last_idx += 1;
30479 264 : return 1;
30480 : }
30481 :
30482 : /* Produce the .debug_addr section. */
30483 :
30484 : static void
30485 249 : output_addr_table (void)
30486 : {
30487 249 : unsigned int index = 0;
30488 249 : if (addr_index_table == NULL || addr_index_table->size () == 0)
30489 5 : return;
30490 :
30491 244 : switch_to_section (debug_addr_section);
30492 : /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
30493 : which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
30494 : before DWARF5, didn't have a header for .debug_addr units.
30495 : DWARF5 specifies a small header when address tables are used. */
30496 244 : if (dwarf_version >= 5)
30497 : {
30498 244 : unsigned int last_idx = 0;
30499 244 : unsigned long addrs_length;
30500 :
30501 244 : addr_index_table->traverse_noresize
30502 508 : <unsigned int *, count_index_addrs> (&last_idx);
30503 244 : addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
30504 :
30505 244 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
30506 0 : dw2_asm_output_data (4, 0xffffffff,
30507 : "Escape value for 64-bit DWARF extension");
30508 244 : dw2_asm_output_data (dwarf_offset_size, addrs_length,
30509 : "Length of Address Unit");
30510 244 : dw2_asm_output_data (2, 5, "DWARF addr version");
30511 244 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
30512 244 : dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
30513 : }
30514 244 : ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
30515 :
30516 244 : addr_index_table
30517 508 : ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
30518 : }
30519 :
30520 : #if ENABLE_ASSERT_CHECKING
30521 : /* Verify that all marks are clear. */
30522 :
30523 : static void
30524 605680162 : verify_marks_clear (dw_die_ref die)
30525 : {
30526 605680162 : dw_die_ref c;
30527 :
30528 605680162 : gcc_assert (! die->die_mark);
30529 1066563365 : FOR_EACH_CHILD (die, c, verify_marks_clear (c));
30530 605680162 : }
30531 : #endif /* ENABLE_ASSERT_CHECKING */
30532 :
30533 : /* Clear the marks for a die and its children.
30534 : Be cool if the mark isn't set. */
30535 :
30536 : static void
30537 52540599 : prune_unmark_dies (dw_die_ref die)
30538 : {
30539 52540599 : dw_die_ref c;
30540 :
30541 52540599 : if (die->die_mark)
30542 52540599 : die->die_mark = 0;
30543 105028659 : FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
30544 52540599 : }
30545 :
30546 : /* Given LOC that is referenced by a DIE we're marking as used, find all
30547 : referenced DWARF procedures it references and mark them as used. */
30548 :
30549 : static void
30550 116015 : prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc)
30551 : {
30552 347760 : for (; loc != NULL; loc = loc->dw_loc_next)
30553 231745 : switch (loc->dw_loc_opc)
30554 : {
30555 0 : case DW_OP_implicit_pointer:
30556 0 : case DW_OP_convert:
30557 0 : case DW_OP_reinterpret:
30558 0 : case DW_OP_GNU_implicit_pointer:
30559 0 : case DW_OP_GNU_convert:
30560 0 : case DW_OP_GNU_reinterpret:
30561 0 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref)
30562 0 : prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
30563 : break;
30564 5207 : case DW_OP_GNU_variable_value:
30565 5207 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
30566 : {
30567 2255 : dw_die_ref ref
30568 2255 : = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
30569 2255 : if (ref == NULL)
30570 : break;
30571 1445 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
30572 1445 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
30573 1445 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
30574 : }
30575 : /* FALLTHRU */
30576 4399 : case DW_OP_call2:
30577 4399 : case DW_OP_call4:
30578 4399 : case DW_OP_call_ref:
30579 4399 : case DW_OP_const_type:
30580 4399 : case DW_OP_GNU_const_type:
30581 4399 : case DW_OP_GNU_parameter_ref:
30582 4399 : gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref);
30583 4399 : prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
30584 4399 : break;
30585 0 : case DW_OP_regval_type:
30586 0 : case DW_OP_deref_type:
30587 0 : case DW_OP_GNU_regval_type:
30588 0 : case DW_OP_GNU_deref_type:
30589 0 : gcc_assert (loc->dw_loc_oprnd2.val_class == dw_val_class_die_ref);
30590 0 : prune_unused_types_mark (loc->dw_loc_oprnd2.v.val_die_ref.die, 1);
30591 0 : break;
30592 0 : case DW_OP_entry_value:
30593 0 : case DW_OP_GNU_entry_value:
30594 0 : gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_loc);
30595 0 : prune_unused_types_walk_loc_descr (loc->dw_loc_oprnd1.v.val_loc);
30596 0 : break;
30597 : default:
30598 : break;
30599 : }
30600 116015 : }
30601 :
30602 : /* Given DIE that we're marking as used, find any other dies
30603 : it references as attributes and mark them as used. */
30604 :
30605 : static void
30606 52540599 : prune_unused_types_walk_attribs (dw_die_ref die)
30607 : {
30608 52540599 : dw_attr_node *a;
30609 52540599 : unsigned ix;
30610 :
30611 242040604 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
30612 : {
30613 189500005 : switch (AT_class (a))
30614 : {
30615 : /* Make sure DWARF procedures referenced by location descriptions will
30616 : get emitted. */
30617 116015 : case dw_val_class_loc:
30618 116015 : prune_unused_types_walk_loc_descr (AT_loc (a));
30619 116015 : break;
30620 0 : case dw_val_class_loc_list:
30621 0 : for (dw_loc_list_ref list = AT_loc_list (a);
30622 0 : list != NULL;
30623 0 : list = list->dw_loc_next)
30624 0 : prune_unused_types_walk_loc_descr (list->expr);
30625 : break;
30626 :
30627 : case dw_val_class_view_list:
30628 : /* This points to a loc_list in another attribute, so it's
30629 : already covered. */
30630 : break;
30631 :
30632 51820449 : case dw_val_class_die_ref:
30633 : /* A reference to another DIE.
30634 : Make sure that it will get emitted.
30635 : If it was broken out into a comdat group, don't follow it. */
30636 51820449 : if (! AT_ref (a)->comdat_type_p
30637 51820449 : || a->dw_attr == DW_AT_specification)
30638 51820192 : prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
30639 : break;
30640 :
30641 32050156 : case dw_val_class_str:
30642 : /* Set the string's refcount to 0 so that prune_unused_types_mark
30643 : accounts properly for it. */
30644 32050156 : a->dw_attr_val.v.val_str->refcount = 0;
30645 32050156 : break;
30646 :
30647 : default:
30648 : break;
30649 : }
30650 : }
30651 52540599 : }
30652 :
30653 : /* Mark the generic parameters and arguments children DIEs of DIE. */
30654 :
30655 : static void
30656 16759425 : prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
30657 : {
30658 16759425 : dw_die_ref c;
30659 :
30660 16759425 : if (die == NULL || die->die_child == NULL)
30661 : return;
30662 : c = die->die_child;
30663 19230944 : do
30664 : {
30665 19230944 : if (is_template_parameter (c))
30666 810179 : prune_unused_types_mark (c, 1);
30667 19230944 : c = c->die_sib;
30668 19230944 : } while (c && c != die->die_child);
30669 : }
30670 :
30671 : /* Mark DIE as being used. If DOKIDS is true, then walk down
30672 : to DIE's children. */
30673 :
30674 : static void
30675 69671156 : prune_unused_types_mark (dw_die_ref die, int dokids)
30676 : {
30677 69671156 : dw_die_ref c;
30678 :
30679 69671156 : if (die->die_mark == 0)
30680 : {
30681 : /* We haven't done this node yet. Mark it as used. */
30682 16759425 : die->die_mark = 1;
30683 : /* If this is the DIE of a generic type instantiation,
30684 : mark the children DIEs that describe its generic parms and
30685 : args. */
30686 16759425 : prune_unused_types_mark_generic_parms_dies (die);
30687 :
30688 : /* We also have to mark its parents as used.
30689 : (But we don't want to mark our parent's kids due to this,
30690 : unless it is a class.) */
30691 16759425 : if (die->die_parent)
30692 16759425 : prune_unused_types_mark (die->die_parent,
30693 16759425 : class_scope_p (die->die_parent));
30694 :
30695 : /* Mark any referenced nodes. */
30696 16759425 : prune_unused_types_walk_attribs (die);
30697 :
30698 : /* If this node is a specification,
30699 : also mark the definition, if it exists. */
30700 16759425 : if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
30701 95990 : prune_unused_types_mark (die->die_definition, 1);
30702 : }
30703 :
30704 69671156 : if (dokids && die->die_mark != 2)
30705 : {
30706 : /* We need to walk the children, but haven't done so yet.
30707 : Remember that we've walked the kids. */
30708 16236097 : die->die_mark = 2;
30709 :
30710 : /* If this is an array type, we need to make sure our
30711 : kids get marked, even if they're types. If we're
30712 : breaking out types into comdat sections, do this
30713 : for all type definitions. */
30714 16236097 : if (die->die_tag == DW_TAG_array_type
30715 16236097 : || (use_debug_types
30716 1492 : && is_type_die (die) && ! is_declaration_die (die)))
30717 164204 : FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
30718 : else
30719 29582916 : FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
30720 : }
30721 69671156 : }
30722 :
30723 : /* For local classes, look if any static member functions were emitted
30724 : and if so, mark them. */
30725 :
30726 : static void
30727 122891 : prune_unused_types_walk_local_classes (dw_die_ref die)
30728 : {
30729 122891 : dw_die_ref c;
30730 :
30731 122891 : if (die->die_mark == 2)
30732 : return;
30733 :
30734 99026 : switch (die->die_tag)
30735 : {
30736 18661 : case DW_TAG_structure_type:
30737 18661 : case DW_TAG_union_type:
30738 18661 : case DW_TAG_class_type:
30739 18661 : case DW_TAG_interface_type:
30740 18661 : break;
30741 :
30742 60182 : case DW_TAG_subprogram:
30743 60182 : if (!get_AT_flag (die, DW_AT_declaration)
30744 60182 : || die->die_definition != NULL)
30745 16319 : prune_unused_types_mark (die, 1);
30746 : return;
30747 :
30748 : default:
30749 : return;
30750 : }
30751 :
30752 : /* Mark children. */
30753 104260 : FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
30754 : }
30755 :
30756 : /* Walk the tree DIE and mark types that we actually use. */
30757 :
30758 : static void
30759 193447291 : prune_unused_types_walk (dw_die_ref die)
30760 : {
30761 193447291 : dw_die_ref c;
30762 :
30763 : /* Don't do anything if this node is already marked and
30764 : children have been marked as well. */
30765 193447291 : if (die->die_mark == 2)
30766 : return;
30767 :
30768 181197031 : switch (die->die_tag)
30769 : {
30770 48942578 : case DW_TAG_structure_type:
30771 48942578 : case DW_TAG_union_type:
30772 48942578 : case DW_TAG_class_type:
30773 48942578 : case DW_TAG_interface_type:
30774 48942578 : if (die->die_perennial_p)
30775 : break;
30776 :
30777 151806933 : for (c = die->die_parent; c; c = c->die_parent)
30778 102930303 : if (c->die_tag == DW_TAG_subprogram)
30779 : break;
30780 :
30781 : /* Finding used static member functions inside of classes
30782 : is needed just for local classes, because for other classes
30783 : static member function DIEs with DW_AT_specification
30784 : are emitted outside of the DW_TAG_*_type. If we ever change
30785 : it, we'd need to call this even for non-local classes. */
30786 48895287 : if (c)
30787 18657 : prune_unused_types_walk_local_classes (die);
30788 :
30789 : /* It's a type node --- don't mark it. */
30790 : return;
30791 :
30792 48690543 : case DW_TAG_const_type:
30793 48690543 : case DW_TAG_packed_type:
30794 48690543 : case DW_TAG_pointer_type:
30795 48690543 : case DW_TAG_reference_type:
30796 48690543 : case DW_TAG_rvalue_reference_type:
30797 48690543 : case DW_TAG_volatile_type:
30798 48690543 : case DW_TAG_restrict_type:
30799 48690543 : case DW_TAG_shared_type:
30800 48690543 : case DW_TAG_atomic_type:
30801 48690543 : case DW_TAG_immutable_type:
30802 48690543 : case DW_TAG_typedef:
30803 48690543 : case DW_TAG_array_type:
30804 48690543 : case DW_TAG_coarray_type:
30805 48690543 : case DW_TAG_friend:
30806 48690543 : case DW_TAG_enumeration_type:
30807 48690543 : case DW_TAG_subroutine_type:
30808 48690543 : case DW_TAG_string_type:
30809 48690543 : case DW_TAG_set_type:
30810 48690543 : case DW_TAG_subrange_type:
30811 48690543 : case DW_TAG_ptr_to_member_type:
30812 48690543 : case DW_TAG_file_type:
30813 48690543 : case DW_TAG_unspecified_type:
30814 48690543 : case DW_TAG_dynamic_type:
30815 : /* Type nodes are useful only when other DIEs reference them --- don't
30816 : mark them. */
30817 : /* FALLTHROUGH */
30818 :
30819 48690543 : case DW_TAG_dwarf_procedure:
30820 : /* Likewise for DWARF procedures. */
30821 :
30822 48690543 : if (die->die_perennial_p)
30823 : break;
30824 :
30825 : return;
30826 :
30827 49610438 : case DW_TAG_variable:
30828 49610438 : if (flag_debug_only_used_symbols)
30829 : {
30830 49610197 : if (die->die_perennial_p)
30831 : break;
30832 :
30833 : /* For static data members, the declaration in the class is supposed
30834 : to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
30835 : DWARF5. DW_TAG_member will be marked, so mark even such
30836 : DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
30837 : attribute. */
30838 49340277 : if (dwarf_version >= 5
30839 49337163 : && class_scope_p (die->die_parent)
30840 49502434 : && get_AT (die, DW_AT_const_value))
30841 : break;
30842 :
30843 : /* premark_used_variables marks external variables --- don't mark
30844 : them here. But function-local externals are always considered
30845 : used. */
30846 49261882 : if (get_AT (die, DW_AT_external))
30847 : {
30848 118567424 : for (c = die->die_parent; c; c = c->die_parent)
30849 71199647 : if (c->die_tag == DW_TAG_subprogram)
30850 : break;
30851 47369334 : if (!c)
30852 : return;
30853 : }
30854 : }
30855 : /* FALLTHROUGH */
30856 :
30857 : default:
30858 : /* Mark everything else. */
30859 : break;
30860 : }
30861 :
30862 36329766 : if (die->die_mark == 0)
30863 : {
30864 35781174 : die->die_mark = 1;
30865 :
30866 : /* Now, mark any dies referenced from here. */
30867 35781174 : prune_unused_types_walk_attribs (die);
30868 : }
30869 :
30870 36329766 : die->die_mark = 2;
30871 :
30872 : /* Mark children. */
30873 203944196 : FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
30874 : }
30875 :
30876 : /* Increment the string counts on strings referred to from DIE's
30877 : attributes. */
30878 :
30879 : static void
30880 52540599 : prune_unused_types_update_strings (dw_die_ref die)
30881 : {
30882 52540599 : dw_attr_node *a;
30883 52540599 : unsigned ix;
30884 :
30885 242040604 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
30886 189500005 : if (AT_class (a) == dw_val_class_str)
30887 : {
30888 32050156 : struct indirect_string_node *s = a->dw_attr_val.v.val_str;
30889 32050156 : s->refcount++;
30890 : /* Avoid unnecessarily putting strings that are used less than
30891 : twice in the hash table. */
30892 32050156 : if (s->form != DW_FORM_line_strp
30893 31949834 : && (s->refcount
30894 31949834 : == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2)))
30895 : {
30896 19546065 : indirect_string_node **slot
30897 19546065 : = debug_str_hash->find_slot_with_hash (s->str,
30898 19546065 : htab_hash_string (s->str),
30899 : INSERT);
30900 19546065 : gcc_assert (*slot == NULL);
30901 19546065 : *slot = s;
30902 : }
30903 : }
30904 52540599 : }
30905 :
30906 : /* Mark DIE and its children as removed. */
30907 :
30908 : static void
30909 553139563 : mark_removed (dw_die_ref die)
30910 : {
30911 553139563 : dw_die_ref c;
30912 553139563 : die->removed = true;
30913 964871803 : FOR_EACH_CHILD (die, c, mark_removed (c));
30914 553139563 : }
30915 :
30916 : /* Remove from the tree DIE any dies that aren't marked. */
30917 :
30918 : static void
30919 52540599 : prune_unused_types_prune (dw_die_ref die)
30920 : {
30921 52540599 : dw_die_ref c;
30922 :
30923 52540599 : gcc_assert (die->die_mark);
30924 52540599 : prune_unused_types_update_strings (die);
30925 :
30926 52540599 : if (! die->die_child)
30927 : return;
30928 :
30929 : c = die->die_child;
30930 52937968 : do {
30931 52937968 : dw_die_ref prev = c, next;
30932 193895383 : for (c = c->die_sib; ! c->die_mark; c = next)
30933 141407323 : if (c == die->die_child)
30934 : {
30935 : /* No marked children between 'prev' and the end of the list. */
30936 449908 : if (prev == c)
30937 : /* No marked children at all. */
30938 274678 : die->die_child = NULL;
30939 : else
30940 : {
30941 175230 : prev->die_sib = c->die_sib;
30942 175230 : die->die_child = prev;
30943 : }
30944 449908 : c->die_sib = NULL;
30945 449908 : mark_removed (c);
30946 449908 : return;
30947 : }
30948 : else
30949 : {
30950 140957415 : next = c->die_sib;
30951 140957415 : c->die_sib = NULL;
30952 140957415 : mark_removed (c);
30953 : }
30954 :
30955 52488060 : if (c != prev->die_sib)
30956 2303140 : prev->die_sib = c;
30957 52488060 : prune_unused_types_prune (c);
30958 52488060 : } while (c != die->die_child);
30959 : }
30960 :
30961 : /* Remove dies representing declarations that we never use. */
30962 :
30963 : static void
30964 52458 : prune_unused_types (void)
30965 : {
30966 52458 : unsigned int i;
30967 52458 : limbo_die_node *node;
30968 52458 : comdat_type_node *ctnode;
30969 52458 : pubname_entry *pub;
30970 52458 : dw_die_ref base_type;
30971 :
30972 : #if ENABLE_ASSERT_CHECKING
30973 : /* All the marks should already be clear. */
30974 52458 : verify_marks_clear (comp_unit_die ());
30975 52458 : for (node = limbo_die_list; node; node = node->next)
30976 0 : verify_marks_clear (node->die);
30977 52539 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30978 81 : verify_marks_clear (ctnode->root_die);
30979 : #endif /* ENABLE_ASSERT_CHECKING */
30980 :
30981 : /* Mark types that are used in global variables. */
30982 52458 : premark_types_used_by_global_vars ();
30983 :
30984 : /* Mark variables used in the symtab. */
30985 52458 : if (flag_debug_only_used_symbols)
30986 52426 : premark_used_variables ();
30987 :
30988 : /* Set the mark on nodes that are actually used. */
30989 52458 : prune_unused_types_walk (comp_unit_die ());
30990 52458 : for (node = limbo_die_list; node; node = node->next)
30991 0 : prune_unused_types_walk (node->die);
30992 52539 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30993 : {
30994 81 : prune_unused_types_walk (ctnode->root_die);
30995 81 : prune_unused_types_mark (ctnode->type_die, 1);
30996 : }
30997 :
30998 : /* Also set the mark on nodes referenced from the pubname_table. Enumerators
30999 : are unusual in that they are pubnames that are the children of pubtypes.
31000 : They should only be marked via their parent DW_TAG_enumeration_type die,
31001 : not as roots in themselves. */
31002 53156 : FOR_EACH_VEC_ELT (*pubname_table, i, pub)
31003 698 : if (pub->die->die_tag != DW_TAG_enumerator)
31004 644 : prune_unused_types_mark (pub->die, 1);
31005 52458 : for (i = 0; base_types.iterate (i, &base_type); i++)
31006 0 : prune_unused_types_mark (base_type, 1);
31007 :
31008 : /* Also set the mark on nodes that could be referenced by
31009 : DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
31010 : by DW_TAG_inlined_subroutine origins. */
31011 52458 : cgraph_node *cnode;
31012 2810175 : FOR_EACH_FUNCTION (cnode)
31013 2757717 : if (cnode->referred_to_p (false))
31014 : {
31015 2575145 : dw_die_ref die = lookup_decl_die (cnode->decl);
31016 2575145 : if (die == NULL || die->die_mark)
31017 2574969 : continue;
31018 176 : for (cgraph_edge *e = cnode->callers; e; e = e->next_caller)
31019 154 : if (e->caller != cnode)
31020 : {
31021 154 : prune_unused_types_mark (die, 1);
31022 154 : break;
31023 : }
31024 : }
31025 :
31026 52458 : if (debug_str_hash)
31027 52458 : debug_str_hash->empty ();
31028 52458 : if (skeleton_debug_str_hash)
31029 0 : skeleton_debug_str_hash->empty ();
31030 52458 : prune_unused_types_prune (comp_unit_die ());
31031 52458 : for (limbo_die_node **pnode = &limbo_die_list; *pnode; )
31032 : {
31033 0 : node = *pnode;
31034 0 : if (!node->die->die_mark)
31035 0 : *pnode = node->next;
31036 : else
31037 : {
31038 0 : prune_unused_types_prune (node->die);
31039 0 : pnode = &node->next;
31040 : }
31041 : }
31042 52539 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
31043 81 : prune_unused_types_prune (ctnode->root_die);
31044 :
31045 : /* Leave the marks clear. */
31046 52458 : prune_unmark_dies (comp_unit_die ());
31047 52458 : for (node = limbo_die_list; node; node = node->next)
31048 0 : prune_unmark_dies (node->die);
31049 52539 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
31050 81 : prune_unmark_dies (ctnode->root_die);
31051 52458 : }
31052 :
31053 : /* Helpers to manipulate hash table of comdat type units. */
31054 :
31055 : struct comdat_type_hasher : nofree_ptr_hash <comdat_type_node>
31056 : {
31057 : static inline hashval_t hash (const comdat_type_node *);
31058 : static inline bool equal (const comdat_type_node *, const comdat_type_node *);
31059 : };
31060 :
31061 : inline hashval_t
31062 86 : comdat_type_hasher::hash (const comdat_type_node *type_node)
31063 : {
31064 86 : hashval_t h;
31065 86 : memcpy (&h, type_node->signature, sizeof (h));
31066 86 : return h;
31067 : }
31068 :
31069 : inline bool
31070 5 : comdat_type_hasher::equal (const comdat_type_node *type_node_1,
31071 : const comdat_type_node *type_node_2)
31072 : {
31073 5 : return (! memcmp (type_node_1->signature, type_node_2->signature,
31074 : DWARF_TYPE_SIGNATURE_SIZE));
31075 : }
31076 :
31077 : /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
31078 : to the location it would have been added, should we know its
31079 : DECL_ASSEMBLER_NAME when we added other attributes. This will
31080 : probably improve compactness of debug info, removing equivalent
31081 : abbrevs, and hide any differences caused by deferring the
31082 : computation of the assembler name, triggered by e.g. PCH. */
31083 :
31084 : static inline void
31085 119640204 : move_linkage_attr (dw_die_ref die)
31086 : {
31087 119640204 : unsigned ix = vec_safe_length (die->die_attr);
31088 119640204 : dw_attr_node linkage = (*die->die_attr)[ix - 1];
31089 :
31090 119640204 : gcc_assert (linkage.dw_attr == DW_AT_linkage_name
31091 : || linkage.dw_attr == DW_AT_MIPS_linkage_name);
31092 :
31093 587248111 : while (--ix > 0)
31094 : {
31095 587248063 : dw_attr_node *prev = &(*die->die_attr)[ix - 1];
31096 :
31097 587248063 : if (prev->dw_attr == DW_AT_decl_line
31098 : || prev->dw_attr == DW_AT_decl_column
31099 : || prev->dw_attr == DW_AT_name)
31100 : break;
31101 : }
31102 :
31103 119640204 : if (ix != vec_safe_length (die->die_attr) - 1)
31104 : {
31105 119345702 : die->die_attr->pop ();
31106 119345702 : die->die_attr->quick_insert (ix, linkage);
31107 : }
31108 119640204 : }
31109 :
31110 : /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
31111 : referenced from typed stack ops and count how often they are used. */
31112 :
31113 : static void
31114 33234112 : mark_base_types (dw_loc_descr_ref loc)
31115 : {
31116 33234112 : dw_die_ref base_type = NULL;
31117 :
31118 95454580 : for (; loc; loc = loc->dw_loc_next)
31119 : {
31120 62220468 : switch (loc->dw_loc_opc)
31121 : {
31122 163099 : case DW_OP_regval_type:
31123 163099 : case DW_OP_deref_type:
31124 163099 : case DW_OP_GNU_regval_type:
31125 163099 : case DW_OP_GNU_deref_type:
31126 163099 : base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
31127 163099 : break;
31128 168845 : case DW_OP_convert:
31129 168845 : case DW_OP_reinterpret:
31130 168845 : case DW_OP_GNU_convert:
31131 168845 : case DW_OP_GNU_reinterpret:
31132 168845 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
31133 26738 : continue;
31134 : /* FALLTHRU */
31135 183052 : case DW_OP_const_type:
31136 183052 : case DW_OP_GNU_const_type:
31137 183052 : base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
31138 183052 : break;
31139 1355307 : case DW_OP_entry_value:
31140 1355307 : case DW_OP_GNU_entry_value:
31141 1355307 : mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
31142 1355307 : continue;
31143 60492272 : default:
31144 60492272 : continue;
31145 : }
31146 346151 : gcc_assert (base_type->die_parent == comp_unit_die ());
31147 346151 : if (base_type->die_mark)
31148 339580 : base_type->die_mark++;
31149 : else
31150 : {
31151 6571 : base_types.safe_push (base_type);
31152 6571 : base_type->die_mark = 1;
31153 : }
31154 : }
31155 33234112 : }
31156 :
31157 : /* Stripped-down variant of resolve_addr, mark DW_TAG_base_type nodes
31158 : referenced from typed stack ops and count how often they are used. */
31159 :
31160 : static void
31161 234558 : mark_base_types (dw_die_ref die)
31162 : {
31163 234558 : dw_die_ref c;
31164 234558 : dw_attr_node *a;
31165 234558 : dw_loc_list_ref *curr;
31166 234558 : unsigned ix;
31167 :
31168 1095632 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
31169 861074 : switch (AT_class (a))
31170 : {
31171 0 : case dw_val_class_loc_list:
31172 0 : curr = AT_loc_list_ptr (a);
31173 0 : while (*curr)
31174 : {
31175 0 : mark_base_types ((*curr)->expr);
31176 0 : curr = &(*curr)->dw_loc_next;
31177 : }
31178 : break;
31179 :
31180 240 : case dw_val_class_loc:
31181 240 : mark_base_types (AT_loc (a));
31182 240 : break;
31183 :
31184 : default:
31185 : break;
31186 : }
31187 :
31188 467783 : FOR_EACH_CHILD (die, c, mark_base_types (c));
31189 234558 : }
31190 :
31191 : /* Comparison function for sorting marked base types. */
31192 :
31193 : static int
31194 17500 : base_type_cmp (const void *x, const void *y)
31195 : {
31196 17500 : dw_die_ref dx = *(const dw_die_ref *) x;
31197 17500 : dw_die_ref dy = *(const dw_die_ref *) y;
31198 17500 : unsigned int byte_size1, byte_size2;
31199 17500 : unsigned int encoding1, encoding2;
31200 17500 : unsigned int align1, align2;
31201 17500 : if (dx->die_mark > dy->die_mark)
31202 : return -1;
31203 10137 : if (dx->die_mark < dy->die_mark)
31204 : return 1;
31205 3753 : byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
31206 3753 : byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
31207 3753 : if (byte_size1 < byte_size2)
31208 : return 1;
31209 2325 : if (byte_size1 > byte_size2)
31210 : return -1;
31211 460 : encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
31212 460 : encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
31213 460 : if (encoding1 < encoding2)
31214 : return 1;
31215 288 : if (encoding1 > encoding2)
31216 : return -1;
31217 9 : align1 = get_AT_unsigned (dx, DW_AT_alignment);
31218 9 : align2 = get_AT_unsigned (dy, DW_AT_alignment);
31219 9 : if (align1 < align2)
31220 : return 1;
31221 9 : if (align1 > align2)
31222 : return -1;
31223 : return 0;
31224 : }
31225 :
31226 : /* Move base types marked by mark_base_types as early as possible
31227 : in the CU, sorted by decreasing usage count both to make the
31228 : uleb128 references as small as possible and to make sure they
31229 : will have die_offset already computed by calc_die_sizes when
31230 : sizes of typed stack loc ops is computed. */
31231 :
31232 : static void
31233 53407 : move_marked_base_types (void)
31234 : {
31235 53407 : unsigned int i;
31236 53407 : dw_die_ref base_type, die, c;
31237 :
31238 53407 : if (base_types.is_empty ())
31239 53407 : return;
31240 :
31241 : /* Sort by decreasing usage count, they will be added again in that
31242 : order later on. */
31243 3636 : base_types.qsort (base_type_cmp);
31244 3636 : die = comp_unit_die ();
31245 3636 : c = die->die_child;
31246 1417139 : do
31247 : {
31248 1417139 : dw_die_ref prev = c;
31249 1417139 : c = c->die_sib;
31250 1423710 : while (c->die_mark)
31251 : {
31252 6571 : remove_child_with_prev (c, prev);
31253 : /* As base types got marked, there must be at least
31254 : one node other than DW_TAG_base_type. */
31255 6571 : gcc_assert (die->die_child != NULL);
31256 6571 : c = prev->die_sib;
31257 : }
31258 : }
31259 1417139 : while (c != die->die_child);
31260 3636 : gcc_assert (die->die_child);
31261 : c = die->die_child;
31262 10207 : for (i = 0; base_types.iterate (i, &base_type); i++)
31263 : {
31264 6571 : base_type->die_mark = 0;
31265 6571 : base_type->die_sib = c->die_sib;
31266 6571 : c->die_sib = base_type;
31267 6571 : c = base_type;
31268 : }
31269 : }
31270 :
31271 : /* Helper function for resolve_addr, attempt to resolve
31272 : one CONST_STRING, return true if successful. Similarly verify that
31273 : SYMBOL_REFs refer to variables emitted in the current CU. */
31274 :
31275 : static bool
31276 2084169 : resolve_one_addr (rtx *addr)
31277 : {
31278 2084169 : rtx rtl = *addr;
31279 :
31280 2084169 : if (GET_CODE (rtl) == CONST_STRING)
31281 : {
31282 231784 : size_t len = strlen (XSTR (rtl, 0)) + 1;
31283 231784 : tree t = build_string (len, XSTR (rtl, 0));
31284 231784 : tree tlen = size_int (len - 1);
31285 231784 : TREE_TYPE (t)
31286 231784 : = build_array_type (char_type_node, build_index_type (tlen));
31287 231784 : rtl = lookup_constant_def (t);
31288 231784 : if (!rtl || !MEM_P (rtl))
31289 : return false;
31290 106184 : rtl = XEXP (rtl, 0);
31291 106184 : if (GET_CODE (rtl) == SYMBOL_REF
31292 106184 : && SYMBOL_REF_DECL (rtl)
31293 212368 : && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
31294 : return false;
31295 4770 : vec_safe_push (used_rtx_array, rtl);
31296 4770 : *addr = rtl;
31297 4770 : return true;
31298 : }
31299 :
31300 1852385 : if (GET_CODE (rtl) == SYMBOL_REF
31301 1852385 : && SYMBOL_REF_DECL (rtl))
31302 : {
31303 1482237 : if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
31304 : {
31305 595848 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
31306 : return false;
31307 : }
31308 886389 : else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
31309 : return false;
31310 : }
31311 :
31312 1817557 : if (GET_CODE (rtl) == CONST)
31313 : {
31314 122474 : subrtx_ptr_iterator::array_type array;
31315 485616 : FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
31316 365324 : if (!resolve_one_addr (*iter))
31317 2182 : return false;
31318 122474 : }
31319 :
31320 : return true;
31321 : }
31322 :
31323 : /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
31324 : if possible, and create DW_TAG_dwarf_procedure that can be referenced
31325 : from DW_OP_implicit_pointer if the string hasn't been seen yet. */
31326 :
31327 : static rtx
31328 79433 : string_cst_pool_decl (tree t)
31329 : {
31330 79433 : rtx rtl = output_constant_def (t, 1);
31331 79433 : unsigned char *array;
31332 79433 : dw_loc_descr_ref l;
31333 79433 : tree decl;
31334 79433 : size_t len;
31335 79433 : dw_die_ref ref;
31336 :
31337 79433 : if (!rtl || !MEM_P (rtl))
31338 : return NULL_RTX;
31339 79433 : rtl = XEXP (rtl, 0);
31340 79433 : if (GET_CODE (rtl) != SYMBOL_REF
31341 79433 : || SYMBOL_REF_DECL (rtl) == NULL_TREE)
31342 : return NULL_RTX;
31343 :
31344 79433 : decl = SYMBOL_REF_DECL (rtl);
31345 79433 : if (!lookup_decl_die (decl))
31346 : {
31347 9586 : len = TREE_STRING_LENGTH (t);
31348 9586 : vec_safe_push (used_rtx_array, rtl);
31349 9586 : ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
31350 9586 : array = ggc_vec_alloc<unsigned char> (len);
31351 9586 : memcpy (array, TREE_STRING_POINTER (t), len);
31352 9586 : l = new_loc_descr (DW_OP_implicit_value, len, 0);
31353 9586 : l->dw_loc_oprnd2.val_class = dw_val_class_vec;
31354 9586 : l->dw_loc_oprnd2.v.val_vec.length = len;
31355 9586 : l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
31356 9586 : l->dw_loc_oprnd2.v.val_vec.array = array;
31357 9586 : add_AT_loc (ref, DW_AT_location, l);
31358 9586 : equate_decl_number_to_die (decl, ref);
31359 : }
31360 : return rtl;
31361 : }
31362 :
31363 : /* Helper function of resolve_addr_in_expr. LOC is
31364 : a DW_OP_addr followed by DW_OP_stack_value, either at the start
31365 : of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
31366 : resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
31367 : with DW_OP_implicit_pointer if possible
31368 : and return true, if unsuccessful, return false. */
31369 :
31370 : static bool
31371 99356 : optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
31372 : {
31373 99356 : rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
31374 99356 : HOST_WIDE_INT offset = 0;
31375 99356 : dw_die_ref ref = NULL;
31376 99356 : tree decl;
31377 :
31378 99356 : if (GET_CODE (rtl) == CONST
31379 2135 : && GET_CODE (XEXP (rtl, 0)) == PLUS
31380 2135 : && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
31381 : {
31382 2135 : offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
31383 2135 : rtl = XEXP (XEXP (rtl, 0), 0);
31384 : }
31385 99356 : if (GET_CODE (rtl) == CONST_STRING)
31386 : {
31387 79429 : size_t len = strlen (XSTR (rtl, 0)) + 1;
31388 79429 : tree t = build_string (len, XSTR (rtl, 0));
31389 79429 : tree tlen = size_int (len - 1);
31390 :
31391 79429 : TREE_TYPE (t)
31392 79429 : = build_array_type (char_type_node, build_index_type (tlen));
31393 79429 : rtl = string_cst_pool_decl (t);
31394 79429 : if (!rtl)
31395 : return false;
31396 : }
31397 99356 : if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
31398 : {
31399 99356 : decl = SYMBOL_REF_DECL (rtl);
31400 99356 : if (VAR_P (decl) && !DECL_EXTERNAL (decl))
31401 : {
31402 98918 : ref = lookup_decl_die (decl);
31403 98918 : if (ref && (get_AT (ref, DW_AT_location)
31404 11970 : || get_AT (ref, DW_AT_const_value)))
31405 : {
31406 90998 : loc->dw_loc_opc = dwarf_OP (DW_OP_implicit_pointer);
31407 90998 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31408 90998 : loc->dw_loc_oprnd1.val_entry = NULL;
31409 90998 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
31410 90998 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
31411 90998 : loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
31412 90998 : loc->dw_loc_oprnd2.v.val_int = offset;
31413 90998 : return true;
31414 : }
31415 : }
31416 : }
31417 : return false;
31418 : }
31419 :
31420 : /* Helper function for resolve_addr, handle one location
31421 : expression, return false if at least one CONST_STRING or SYMBOL_REF in
31422 : the location list couldn't be resolved. */
31423 :
31424 : static bool
31425 32650975 : resolve_addr_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
31426 : {
31427 32650975 : dw_loc_descr_ref keep = NULL;
31428 93526100 : for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
31429 61652976 : switch (loc->dw_loc_opc)
31430 : {
31431 1597937 : case DW_OP_addr:
31432 1597937 : if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
31433 : {
31434 141604 : if ((prev == NULL
31435 172 : || prev->dw_loc_opc == DW_OP_piece
31436 26 : || prev->dw_loc_opc == DW_OP_bit_piece)
31437 141578 : && loc->dw_loc_next
31438 133696 : && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
31439 99356 : && (!dwarf_strict || dwarf_version >= 5)
31440 240960 : && optimize_one_addr_into_implicit_ptr (loc))
31441 : break;
31442 50606 : return false;
31443 : }
31444 : break;
31445 3 : case DW_OP_GNU_addr_index:
31446 3 : case DW_OP_addrx:
31447 3 : case DW_OP_GNU_const_index:
31448 3 : case DW_OP_constx:
31449 3 : if ((loc->dw_loc_opc == DW_OP_GNU_addr_index
31450 3 : || loc->dw_loc_opc == DW_OP_addrx)
31451 : || ((loc->dw_loc_opc == DW_OP_GNU_const_index
31452 : || loc->dw_loc_opc == DW_OP_constx)
31453 0 : && loc->dw_loc_dtprel))
31454 : {
31455 3 : rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
31456 3 : if (!resolve_one_addr (&rtl))
31457 0 : return false;
31458 3 : remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
31459 3 : loc->dw_loc_oprnd1.val_entry
31460 3 : = add_addr_table_entry (rtl, loc->dw_loc_dtprel
31461 : ? ate_kind_rtx_dtprel : ate_kind_rtx);
31462 : }
31463 : break;
31464 191360 : case DW_OP_const4u:
31465 191360 : case DW_OP_const8u:
31466 191360 : if (loc->dw_loc_dtprel
31467 191360 : && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
31468 : return false;
31469 : break;
31470 986057 : case DW_OP_plus_uconst:
31471 986057 : if (size_of_loc_descr (loc)
31472 986057 : > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
31473 986057 : + 1
31474 986057 : && loc->dw_loc_oprnd1.v.val_unsigned > 0)
31475 : {
31476 14651 : dw_loc_descr_ref repl
31477 14651 : = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
31478 14651 : add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
31479 14651 : add_loc_descr (&repl, loc->dw_loc_next);
31480 14651 : *loc = *repl;
31481 : }
31482 : break;
31483 110998 : case DW_OP_implicit_value:
31484 110998 : if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
31485 110998 : && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
31486 : return false;
31487 : break;
31488 1863492 : case DW_OP_implicit_pointer:
31489 1863492 : case DW_OP_GNU_implicit_pointer:
31490 1863492 : case DW_OP_GNU_parameter_ref:
31491 1863492 : case DW_OP_GNU_variable_value:
31492 1863492 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
31493 : {
31494 719697 : dw_die_ref ref
31495 719697 : = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
31496 719697 : if (ref == NULL)
31497 : return false;
31498 239 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31499 239 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
31500 239 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
31501 : }
31502 1144034 : if (loc->dw_loc_opc == DW_OP_GNU_variable_value)
31503 : {
31504 4661 : if (prev == NULL
31505 4661 : && loc->dw_loc_next == NULL
31506 8150 : && AT_class (a) == dw_val_class_loc)
31507 3489 : switch (a->dw_attr)
31508 : {
31509 : /* Following attributes allow both exprloc and reference,
31510 : so if the whole expression is DW_OP_GNU_variable_value
31511 : alone we could transform it into reference. */
31512 3455 : case DW_AT_byte_size:
31513 3455 : case DW_AT_bit_size:
31514 3455 : case DW_AT_lower_bound:
31515 3455 : case DW_AT_upper_bound:
31516 3455 : case DW_AT_bit_stride:
31517 3455 : case DW_AT_count:
31518 3455 : case DW_AT_allocated:
31519 3455 : case DW_AT_associated:
31520 3455 : case DW_AT_byte_stride:
31521 3455 : a->dw_attr_val.val_class = dw_val_class_die_ref;
31522 3455 : a->dw_attr_val.val_entry = NULL;
31523 3455 : a->dw_attr_val.v.val_die_ref.die
31524 3455 : = loc->dw_loc_oprnd1.v.val_die_ref.die;
31525 3455 : a->dw_attr_val.v.val_die_ref.external = 0;
31526 3455 : return true;
31527 : default:
31528 : break;
31529 : }
31530 1206 : if (dwarf_strict)
31531 : return false;
31532 : }
31533 : break;
31534 : case DW_OP_const_type:
31535 : case DW_OP_regval_type:
31536 : case DW_OP_deref_type:
31537 : case DW_OP_convert:
31538 : case DW_OP_reinterpret:
31539 : case DW_OP_GNU_const_type:
31540 : case DW_OP_GNU_regval_type:
31541 : case DW_OP_GNU_deref_type:
31542 : case DW_OP_GNU_convert:
31543 : case DW_OP_GNU_reinterpret:
31544 333131 : while (loc->dw_loc_next
31545 333131 : && (loc->dw_loc_next->dw_loc_opc == DW_OP_convert
31546 242386 : || loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert))
31547 : {
31548 72350 : dw_die_ref base1, base2;
31549 72350 : unsigned enc1, enc2, size1, size2;
31550 72350 : if (loc->dw_loc_opc == DW_OP_regval_type
31551 72350 : || loc->dw_loc_opc == DW_OP_deref_type
31552 65671 : || loc->dw_loc_opc == DW_OP_GNU_regval_type
31553 65671 : || loc->dw_loc_opc == DW_OP_GNU_deref_type)
31554 6679 : base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
31555 65671 : else if (loc->dw_loc_oprnd1.val_class
31556 : == dw_val_class_unsigned_const)
31557 : break;
31558 : else
31559 64817 : base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
31560 71496 : if (loc->dw_loc_next->dw_loc_oprnd1.val_class
31561 : == dw_val_class_unsigned_const)
31562 : break;
31563 48225 : base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
31564 48225 : gcc_assert (base1->die_tag == DW_TAG_base_type
31565 : && base2->die_tag == DW_TAG_base_type);
31566 48225 : enc1 = get_AT_unsigned (base1, DW_AT_encoding);
31567 48225 : enc2 = get_AT_unsigned (base2, DW_AT_encoding);
31568 48225 : size1 = get_AT_unsigned (base1, DW_AT_byte_size);
31569 48225 : size2 = get_AT_unsigned (base2, DW_AT_byte_size);
31570 48225 : if (size1 == size2
31571 4730 : && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
31572 4605 : && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
31573 1995 : && loc != keep)
31574 2761 : || enc1 == enc2))
31575 : {
31576 : /* Optimize away next DW_OP_convert after
31577 : adjusting LOC's base type die reference. */
31578 1969 : if (loc->dw_loc_opc == DW_OP_regval_type
31579 1969 : || loc->dw_loc_opc == DW_OP_deref_type
31580 1191 : || loc->dw_loc_opc == DW_OP_GNU_regval_type
31581 1191 : || loc->dw_loc_opc == DW_OP_GNU_deref_type)
31582 778 : loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
31583 : else
31584 1191 : loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
31585 1969 : loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
31586 1969 : continue;
31587 : }
31588 : /* Don't change integer DW_OP_convert after e.g. floating
31589 : point typed stack entry. */
31590 46256 : else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
31591 17830 : keep = loc->dw_loc_next;
31592 : break;
31593 : }
31594 : break;
31595 : default:
31596 : break;
31597 : }
31598 : return true;
31599 : }
31600 :
31601 : /* Helper function of resolve_addr. DIE had DW_AT_location of
31602 : DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
31603 : and DW_OP_addr couldn't be resolved. resolve_addr has already
31604 : removed the DW_AT_location attribute. This function attempts to
31605 : add a new DW_AT_location attribute with DW_OP_implicit_pointer
31606 : to it or DW_AT_const_value attribute, if possible. */
31607 :
31608 : static void
31609 1112 : optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
31610 : {
31611 1112 : if (!VAR_P (decl)
31612 1112 : || lookup_decl_die (decl) != die
31613 612 : || DECL_EXTERNAL (decl)
31614 612 : || !TREE_STATIC (decl)
31615 612 : || DECL_INITIAL (decl) == NULL_TREE
31616 446 : || DECL_P (DECL_INITIAL (decl))
31617 1558 : || get_AT (die, DW_AT_const_value))
31618 666 : return;
31619 :
31620 446 : tree init = DECL_INITIAL (decl);
31621 446 : HOST_WIDE_INT offset = 0;
31622 : /* For variables that have been optimized away and thus
31623 : don't have a memory location, see if we can emit
31624 : DW_AT_const_value instead. */
31625 446 : if (tree_add_const_value_attribute (die, init))
31626 : return;
31627 195 : if (dwarf_strict && dwarf_version < 5)
31628 : return;
31629 : /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
31630 : and ADDR_EXPR refers to a decl that has DW_AT_location or
31631 : DW_AT_const_value (but isn't addressable, otherwise
31632 : resolving the original DW_OP_addr wouldn't fail), see if
31633 : we can add DW_OP_implicit_pointer. */
31634 195 : STRIP_NOPS (init);
31635 195 : if (TREE_CODE (init) == POINTER_PLUS_EXPR
31636 195 : && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
31637 : {
31638 0 : offset = tree_to_shwi (TREE_OPERAND (init, 1));
31639 0 : init = TREE_OPERAND (init, 0);
31640 0 : STRIP_NOPS (init);
31641 : }
31642 195 : if (TREE_CODE (init) != ADDR_EXPR)
31643 : return;
31644 5 : if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
31645 4 : && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
31646 5 : || (VAR_P (TREE_OPERAND (init, 0))
31647 0 : && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
31648 0 : && TREE_OPERAND (init, 0) != decl))
31649 : {
31650 4 : dw_die_ref ref;
31651 4 : dw_loc_descr_ref l;
31652 :
31653 4 : if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
31654 : {
31655 4 : rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
31656 4 : if (!rtl)
31657 : return;
31658 4 : decl = SYMBOL_REF_DECL (rtl);
31659 : }
31660 : else
31661 0 : decl = TREE_OPERAND (init, 0);
31662 4 : ref = lookup_decl_die (decl);
31663 4 : if (ref == NULL
31664 4 : || (!get_AT (ref, DW_AT_location)
31665 0 : && !get_AT (ref, DW_AT_const_value)))
31666 0 : return;
31667 4 : l = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
31668 4 : l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31669 4 : l->dw_loc_oprnd1.v.val_die_ref.die = ref;
31670 4 : l->dw_loc_oprnd1.v.val_die_ref.external = 0;
31671 4 : add_AT_loc (die, DW_AT_location, l);
31672 : }
31673 : }
31674 :
31675 : /* Return NULL if l is a DWARF expression, or first op that is not
31676 : valid DWARF expression. */
31677 :
31678 : static dw_loc_descr_ref
31679 139 : non_dwarf_expression (dw_loc_descr_ref l)
31680 : {
31681 182 : while (l)
31682 : {
31683 181 : if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
31684 : return l;
31685 85 : switch (l->dw_loc_opc)
31686 : {
31687 : case DW_OP_regx:
31688 : case DW_OP_implicit_value:
31689 : case DW_OP_stack_value:
31690 : case DW_OP_implicit_pointer:
31691 : case DW_OP_GNU_implicit_pointer:
31692 : case DW_OP_GNU_parameter_ref:
31693 : case DW_OP_piece:
31694 : case DW_OP_bit_piece:
31695 : return l;
31696 43 : default:
31697 43 : break;
31698 : }
31699 43 : l = l->dw_loc_next;
31700 : }
31701 : return NULL;
31702 : }
31703 :
31704 : /* Return adjusted copy of EXPR:
31705 : If it is empty DWARF expression, return it.
31706 : If it is valid non-empty DWARF expression,
31707 : return copy of EXPR with DW_OP_deref appended to it.
31708 : If it is DWARF expression followed by DW_OP_reg{N,x}, return
31709 : copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
31710 : If it is DWARF expression followed by DW_OP_stack_value, return
31711 : copy of the DWARF expression without anything appended.
31712 : Otherwise, return NULL. */
31713 :
31714 : static dw_loc_descr_ref
31715 69 : copy_deref_exprloc (dw_loc_descr_ref expr)
31716 : {
31717 69 : dw_loc_descr_ref tail = NULL;
31718 :
31719 69 : if (expr == NULL)
31720 : return NULL;
31721 :
31722 69 : dw_loc_descr_ref l = non_dwarf_expression (expr);
31723 69 : if (l && l->dw_loc_next)
31724 : return NULL;
31725 :
31726 69 : if (l)
31727 : {
31728 69 : if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
31729 48 : tail = new_loc_descr ((enum dwarf_location_atom)
31730 48 : (DW_OP_breg0 + (l->dw_loc_opc - DW_OP_reg0)),
31731 : 0, 0);
31732 : else
31733 21 : switch (l->dw_loc_opc)
31734 : {
31735 0 : case DW_OP_regx:
31736 0 : tail = new_loc_descr (DW_OP_bregx,
31737 : l->dw_loc_oprnd1.v.val_unsigned, 0);
31738 0 : break;
31739 : case DW_OP_stack_value:
31740 : break;
31741 : default:
31742 : return NULL;
31743 : }
31744 : }
31745 : else
31746 0 : tail = new_loc_descr (DW_OP_deref, 0, 0);
31747 :
31748 69 : dw_loc_descr_ref ret = NULL, *p = &ret;
31749 90 : while (expr != l)
31750 : {
31751 21 : *p = new_loc_descr (expr->dw_loc_opc, 0, 0);
31752 21 : (*p)->dw_loc_oprnd1.val_class = expr->dw_loc_oprnd1.val_class;
31753 21 : (*p)->dw_loc_oprnd1.val_entry = expr->dw_loc_oprnd1.val_entry;
31754 21 : (*p)->dw_loc_oprnd1.v = expr->dw_loc_oprnd1.v;
31755 21 : (*p)->dw_loc_oprnd2.val_class = expr->dw_loc_oprnd2.val_class;
31756 21 : (*p)->dw_loc_oprnd2.val_entry = expr->dw_loc_oprnd2.val_entry;
31757 21 : (*p)->dw_loc_oprnd2.v = expr->dw_loc_oprnd2.v;
31758 21 : p = &(*p)->dw_loc_next;
31759 21 : expr = expr->dw_loc_next;
31760 : }
31761 69 : *p = tail;
31762 69 : return ret;
31763 : }
31764 :
31765 : /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
31766 : reference to a variable or argument, adjust it if needed and return:
31767 : -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
31768 : attribute if present should be removed
31769 : 0 keep the attribute perhaps with minor modifications, no need to rescan
31770 : 1 if the attribute has been successfully adjusted. */
31771 :
31772 : static int
31773 1195 : optimize_string_length (dw_attr_node *a)
31774 : {
31775 1195 : dw_loc_descr_ref l = AT_loc (a), lv;
31776 1195 : dw_die_ref die;
31777 1195 : if (l->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
31778 : {
31779 0 : tree decl = l->dw_loc_oprnd1.v.val_decl_ref;
31780 0 : die = lookup_decl_die (decl);
31781 0 : if (die)
31782 : {
31783 0 : l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31784 0 : l->dw_loc_oprnd1.v.val_die_ref.die = die;
31785 0 : l->dw_loc_oprnd1.v.val_die_ref.external = 0;
31786 : }
31787 : else
31788 : return -1;
31789 : }
31790 : else
31791 1195 : die = l->dw_loc_oprnd1.v.val_die_ref.die;
31792 :
31793 : /* DWARF5 allows reference class, so we can then reference the DIE.
31794 : Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
31795 1195 : if (l->dw_loc_next != NULL && dwarf_version >= 5)
31796 : {
31797 1153 : a->dw_attr_val.val_class = dw_val_class_die_ref;
31798 1153 : a->dw_attr_val.val_entry = NULL;
31799 1153 : a->dw_attr_val.v.val_die_ref.die = die;
31800 1153 : a->dw_attr_val.v.val_die_ref.external = 0;
31801 1153 : return 0;
31802 : }
31803 :
31804 42 : dw_attr_node *av = get_AT (die, DW_AT_location);
31805 42 : dw_loc_list_ref d;
31806 42 : bool non_dwarf_expr = false;
31807 :
31808 42 : if (av == NULL)
31809 68 : return dwarf_strict ? -1 : 0;
31810 8 : switch (AT_class (av))
31811 : {
31812 7 : case dw_val_class_loc_list:
31813 76 : for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
31814 69 : if (d->expr && non_dwarf_expression (d->expr))
31815 : non_dwarf_expr = true;
31816 : break;
31817 0 : case dw_val_class_view_list:
31818 0 : gcc_unreachable ();
31819 1 : case dw_val_class_loc:
31820 1 : lv = AT_loc (av);
31821 1 : if (lv == NULL)
31822 0 : return dwarf_strict ? -1 : 0;
31823 1 : if (non_dwarf_expression (lv))
31824 : non_dwarf_expr = true;
31825 : break;
31826 0 : default:
31827 0 : return dwarf_strict ? -1 : 0;
31828 : }
31829 :
31830 : /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
31831 : into DW_OP_call4 or DW_OP_GNU_variable_value into
31832 : DW_OP_call4 DW_OP_deref, do so. */
31833 7 : if (!non_dwarf_expr
31834 8 : && (l->dw_loc_next != NULL || AT_class (av) == dw_val_class_loc))
31835 : {
31836 1 : l->dw_loc_opc = DW_OP_call4;
31837 1 : if (l->dw_loc_next)
31838 0 : l->dw_loc_next = NULL;
31839 : else
31840 1 : l->dw_loc_next = new_loc_descr (DW_OP_deref, 0, 0);
31841 1 : return 0;
31842 : }
31843 :
31844 : /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
31845 : copy over the DW_AT_location attribute from die to a. */
31846 7 : if (l->dw_loc_next != NULL)
31847 : {
31848 0 : a->dw_attr_val.val_class = av->dw_attr_val.val_class;
31849 0 : a->dw_attr_val.val_entry = av->dw_attr_val.val_entry;
31850 0 : a->dw_attr_val.v = av->dw_attr_val.v;
31851 0 : return 1;
31852 : }
31853 :
31854 7 : dw_loc_list_ref list, *p;
31855 7 : switch (AT_class (av))
31856 : {
31857 7 : case dw_val_class_loc_list:
31858 7 : p = &list;
31859 7 : list = NULL;
31860 76 : for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
31861 : {
31862 69 : lv = copy_deref_exprloc (d->expr);
31863 69 : if (lv)
31864 : {
31865 69 : *p = new_loc_list (lv, d->begin, d->vbegin, d->end, d->vend, d->section);
31866 69 : p = &(*p)->dw_loc_next;
31867 : }
31868 0 : else if (!dwarf_strict && d->expr)
31869 : return 0;
31870 : }
31871 7 : if (list == NULL)
31872 0 : return dwarf_strict ? -1 : 0;
31873 7 : a->dw_attr_val.val_class = dw_val_class_loc_list;
31874 7 : gen_llsym (list);
31875 7 : *AT_loc_list_ptr (a) = list;
31876 7 : return 1;
31877 0 : case dw_val_class_loc:
31878 0 : lv = copy_deref_exprloc (AT_loc (av));
31879 0 : if (lv == NULL)
31880 0 : return dwarf_strict ? -1 : 0;
31881 0 : a->dw_attr_val.v.val_loc = lv;
31882 0 : return 1;
31883 0 : default:
31884 0 : gcc_unreachable ();
31885 : }
31886 : }
31887 :
31888 : /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
31889 : an address in .rodata section if the string literal is emitted there,
31890 : or remove the containing location list or replace DW_AT_const_value
31891 : with DW_AT_location and empty location expression, if it isn't found
31892 : in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
31893 : to something that has been emitted in the current CU. */
31894 :
31895 : static void
31896 78669985 : resolve_addr (dw_die_ref die)
31897 : {
31898 78669985 : dw_die_ref c;
31899 78669985 : dw_attr_node *a;
31900 78669985 : dw_loc_list_ref *curr, *start, loc;
31901 78669985 : unsigned ix;
31902 78669985 : bool remove_AT_byte_size = false;
31903 :
31904 373160152 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
31905 294490167 : switch (AT_class (a))
31906 : {
31907 11819950 : case dw_val_class_loc_list:
31908 11819950 : start = curr = AT_loc_list_ptr (a);
31909 11819950 : loc = *curr;
31910 11819950 : gcc_assert (loc);
31911 : /* The same list can be referenced more than once. See if we have
31912 : already recorded the result from a previous pass. */
31913 11819950 : if (loc->replaced)
31914 0 : *curr = loc->dw_loc_next;
31915 11819950 : else if (!loc->resolved_addr)
31916 : {
31917 : /* As things stand, we do not expect or allow one die to
31918 : reference a suffix of another die's location list chain.
31919 : References must be identical or completely separate.
31920 : There is therefore no need to cache the result of this
31921 : pass on any list other than the first; doing so
31922 : would lead to unnecessary writes. */
31923 36936730 : while (*curr)
31924 : {
31925 25116780 : gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
31926 25116780 : if (!resolve_addr_in_expr (a, (*curr)->expr))
31927 : {
31928 762814 : dw_loc_list_ref next = (*curr)->dw_loc_next;
31929 762814 : dw_loc_descr_ref l = (*curr)->expr;
31930 :
31931 762814 : if (next && (*curr)->ll_symbol)
31932 : {
31933 251116 : gcc_assert (!next->ll_symbol);
31934 251116 : next->ll_symbol = (*curr)->ll_symbol;
31935 251116 : next->vl_symbol = (*curr)->vl_symbol;
31936 : }
31937 762814 : if (dwarf_split_debug_info)
31938 0 : remove_loc_list_addr_table_entries (l);
31939 762814 : *curr = next;
31940 : }
31941 : else
31942 : {
31943 24353966 : mark_base_types ((*curr)->expr);
31944 24353966 : curr = &(*curr)->dw_loc_next;
31945 : }
31946 : }
31947 11819950 : if (loc == *start)
31948 11315067 : loc->resolved_addr = 1;
31949 : else
31950 : {
31951 504883 : loc->replaced = 1;
31952 504883 : loc->dw_loc_next = *start;
31953 : }
31954 : }
31955 11819950 : if (!*start)
31956 : {
31957 504720 : remove_AT (die, a->dw_attr);
31958 504720 : ix--;
31959 : }
31960 : break;
31961 11643741 : case dw_val_class_view_list:
31962 11643741 : {
31963 11643741 : gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
31964 11643741 : gcc_checking_assert (dwarf2out_locviews_in_attribute ());
31965 11643741 : dw_val_node *llnode
31966 11643741 : = view_list_to_loc_list_val_node (&a->dw_attr_val);
31967 : /* If we no longer have a loclist, or it no longer needs
31968 : views, drop this attribute. */
31969 11643741 : if (!llnode || !llnode->v.val_loc_list->vl_symbol)
31970 : {
31971 504719 : remove_AT (die, a->dw_attr);
31972 504719 : ix--;
31973 : }
31974 : break;
31975 : }
31976 7536188 : case dw_val_class_loc:
31977 7536188 : {
31978 7536188 : dw_loc_descr_ref l = AT_loc (a);
31979 : /* DW_OP_GNU_variable_value DW_OP_stack_value or
31980 : DW_OP_GNU_variable_value in DW_AT_string_length can be converted
31981 : into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
31982 : DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
31983 : DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
31984 : with DW_FORM_ref referencing the same DIE as
31985 : DW_OP_GNU_variable_value used to reference. */
31986 7536188 : if (a->dw_attr == DW_AT_string_length
31987 1208 : && l
31988 1208 : && l->dw_loc_opc == DW_OP_GNU_variable_value
31989 1195 : && (l->dw_loc_next == NULL
31990 1153 : || (l->dw_loc_next->dw_loc_next == NULL
31991 1153 : && l->dw_loc_next->dw_loc_opc == DW_OP_stack_value)))
31992 : {
31993 1195 : switch (optimize_string_length (a))
31994 : {
31995 0 : case -1:
31996 0 : remove_AT (die, a->dw_attr);
31997 0 : ix--;
31998 : /* If we drop DW_AT_string_length, we need to drop also
31999 : DW_AT_{string_length_,}byte_size. */
32000 0 : remove_AT_byte_size = true;
32001 0 : continue;
32002 : default:
32003 : break;
32004 7 : case 1:
32005 : /* Even if we keep the optimized DW_AT_string_length,
32006 : it might have changed AT_class, so process it again. */
32007 7 : ix--;
32008 7 : continue;
32009 : }
32010 : }
32011 : /* For -gdwarf-2 don't attempt to optimize
32012 : DW_AT_data_member_location containing
32013 : DW_OP_plus_uconst - older consumers might
32014 : rely on it being that op instead of a more complex,
32015 : but shorter, location description. */
32016 7536181 : if ((dwarf_version > 2
32017 10750 : || a->dw_attr != DW_AT_data_member_location
32018 1992 : || l == NULL
32019 1992 : || l->dw_loc_opc != DW_OP_plus_uconst
32020 1986 : || l->dw_loc_next != NULL)
32021 7544945 : && !resolve_addr_in_expr (a, l))
32022 : {
32023 11582 : if (dwarf_split_debug_info)
32024 0 : remove_loc_list_addr_table_entries (l);
32025 11582 : if (l != NULL
32026 11582 : && l->dw_loc_next == NULL
32027 7997 : && l->dw_loc_opc == DW_OP_addr
32028 7735 : && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
32029 7629 : && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
32030 19211 : && a->dw_attr == DW_AT_location)
32031 : {
32032 1112 : tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
32033 1112 : remove_AT (die, a->dw_attr);
32034 1112 : ix--;
32035 1112 : optimize_location_into_implicit_ptr (die, decl);
32036 1112 : break;
32037 : }
32038 10470 : if (a->dw_attr == DW_AT_string_length)
32039 : /* If we drop DW_AT_string_length, we need to drop also
32040 : DW_AT_{string_length_,}byte_size. */
32041 0 : remove_AT_byte_size = true;
32042 10470 : remove_AT (die, a->dw_attr);
32043 10470 : ix--;
32044 : }
32045 : else
32046 7524599 : mark_base_types (l);
32047 : }
32048 : break;
32049 1475302 : case dw_val_class_addr:
32050 1475302 : if (a->dw_attr == DW_AT_const_value
32051 1475302 : && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
32052 : {
32053 0 : if (AT_index (a) != NOT_INDEXED)
32054 0 : remove_addr_table_entry (a->dw_attr_val.val_entry);
32055 0 : remove_AT (die, a->dw_attr);
32056 0 : ix--;
32057 : }
32058 1475302 : if ((die->die_tag == DW_TAG_call_site
32059 1474748 : && a->dw_attr == DW_AT_call_origin)
32060 554 : || (die->die_tag == DW_TAG_GNU_call_site
32061 554 : && a->dw_attr == DW_AT_abstract_origin))
32062 : {
32063 1475302 : tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
32064 1475302 : dw_die_ref tdie = lookup_decl_die (tdecl);
32065 1475302 : dw_die_ref cdie;
32066 1475302 : if (tdie == NULL
32067 332297 : && DECL_EXTERNAL (tdecl)
32068 297336 : && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
32069 1771826 : && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
32070 : {
32071 : dw_die_ref pdie = cdie;
32072 : /* Make sure we don't add these DIEs into type units.
32073 : We could emit skeleton DIEs for context (namespaces,
32074 : outer structs/classes) and a skeleton DIE for the
32075 : innermost context with DW_AT_signature pointing to the
32076 : type unit. See PR78835. */
32077 523280 : while (pdie && pdie->die_tag != DW_TAG_type_unit)
32078 261722 : pdie = pdie->die_parent;
32079 261558 : if (pdie == NULL)
32080 : {
32081 : /* Creating a full DIE for tdecl is overly expensive and
32082 : at this point even wrong when in the LTO phase
32083 : as it can end up generating new type DIEs we didn't
32084 : output and thus optimize_external_refs will crash. */
32085 261558 : tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
32086 261558 : add_AT_flag (tdie, DW_AT_external, 1);
32087 261558 : add_AT_flag (tdie, DW_AT_declaration, 1);
32088 261558 : add_linkage_attr (tdie, tdecl);
32089 261558 : add_name_and_src_coords_attributes (tdie, tdecl, true);
32090 261558 : equate_decl_number_to_die (tdecl, tdie);
32091 : }
32092 : }
32093 1475302 : if (tdie)
32094 : {
32095 1404563 : a->dw_attr_val.val_class = dw_val_class_die_ref;
32096 1404563 : a->dw_attr_val.v.val_die_ref.die = tdie;
32097 1404563 : a->dw_attr_val.v.val_die_ref.external = 0;
32098 : }
32099 : else
32100 : {
32101 70739 : if (AT_index (a) != NOT_INDEXED)
32102 0 : remove_addr_table_entry (a->dw_attr_val.val_entry);
32103 70739 : remove_AT (die, a->dw_attr);
32104 70739 : ix--;
32105 : }
32106 : }
32107 : break;
32108 : default:
32109 : break;
32110 : }
32111 :
32112 78669985 : if (remove_AT_byte_size)
32113 0 : remove_AT (die, dwarf_version >= 5
32114 : ? DW_AT_string_length_byte_size
32115 : : DW_AT_byte_size);
32116 :
32117 136683961 : FOR_EACH_CHILD (die, c, resolve_addr (c));
32118 78669985 : }
32119 :
32120 : /* Helper routines for optimize_location_lists.
32121 : This pass tries to share identical local lists in .debug_loc
32122 : section. */
32123 :
32124 : /* Iteratively hash operands of LOC opcode into HSTATE. */
32125 :
32126 : static void
32127 52715279 : hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
32128 : {
32129 52715279 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
32130 52715279 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
32131 :
32132 52715279 : switch (loc->dw_loc_opc)
32133 : {
32134 181172 : case DW_OP_const4u:
32135 181172 : case DW_OP_const8u:
32136 181172 : if (loc->dw_loc_dtprel)
32137 195 : goto hash_addr;
32138 : /* FALLTHRU */
32139 17828106 : case DW_OP_const1u:
32140 17828106 : case DW_OP_const1s:
32141 17828106 : case DW_OP_const2u:
32142 17828106 : case DW_OP_const2s:
32143 17828106 : case DW_OP_const4s:
32144 17828106 : case DW_OP_const8s:
32145 17828106 : case DW_OP_constu:
32146 17828106 : case DW_OP_consts:
32147 17828106 : case DW_OP_pick:
32148 17828106 : case DW_OP_plus_uconst:
32149 17828106 : case DW_OP_breg0:
32150 17828106 : case DW_OP_breg1:
32151 17828106 : case DW_OP_breg2:
32152 17828106 : case DW_OP_breg3:
32153 17828106 : case DW_OP_breg4:
32154 17828106 : case DW_OP_breg5:
32155 17828106 : case DW_OP_breg6:
32156 17828106 : case DW_OP_breg7:
32157 17828106 : case DW_OP_breg8:
32158 17828106 : case DW_OP_breg9:
32159 17828106 : case DW_OP_breg10:
32160 17828106 : case DW_OP_breg11:
32161 17828106 : case DW_OP_breg12:
32162 17828106 : case DW_OP_breg13:
32163 17828106 : case DW_OP_breg14:
32164 17828106 : case DW_OP_breg15:
32165 17828106 : case DW_OP_breg16:
32166 17828106 : case DW_OP_breg17:
32167 17828106 : case DW_OP_breg18:
32168 17828106 : case DW_OP_breg19:
32169 17828106 : case DW_OP_breg20:
32170 17828106 : case DW_OP_breg21:
32171 17828106 : case DW_OP_breg22:
32172 17828106 : case DW_OP_breg23:
32173 17828106 : case DW_OP_breg24:
32174 17828106 : case DW_OP_breg25:
32175 17828106 : case DW_OP_breg26:
32176 17828106 : case DW_OP_breg27:
32177 17828106 : case DW_OP_breg28:
32178 17828106 : case DW_OP_breg29:
32179 17828106 : case DW_OP_breg30:
32180 17828106 : case DW_OP_breg31:
32181 17828106 : case DW_OP_regx:
32182 17828106 : case DW_OP_fbreg:
32183 17828106 : case DW_OP_piece:
32184 17828106 : case DW_OP_deref_size:
32185 17828106 : case DW_OP_xderef_size:
32186 17828106 : hstate.add_object (val1->v.val_int);
32187 17828106 : break;
32188 189043 : case DW_OP_skip:
32189 189043 : case DW_OP_bra:
32190 189043 : {
32191 189043 : int offset;
32192 :
32193 189043 : gcc_assert (val1->val_class == dw_val_class_loc);
32194 189043 : offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
32195 189043 : hstate.add_object (offset);
32196 : }
32197 189043 : break;
32198 101412 : case DW_OP_implicit_value:
32199 101412 : hstate.add_object (val1->v.val_unsigned);
32200 101412 : switch (val2->val_class)
32201 : {
32202 48874 : case dw_val_class_const:
32203 48874 : hstate.add_object (val2->v.val_int);
32204 48874 : break;
32205 51912 : case dw_val_class_vec:
32206 51912 : {
32207 51912 : unsigned int elt_size = val2->v.val_vec.elt_size;
32208 51912 : unsigned int len = val2->v.val_vec.length;
32209 :
32210 51912 : hstate.add_int (elt_size);
32211 51912 : hstate.add_int (len);
32212 51912 : hstate.add (val2->v.val_vec.array, len * elt_size);
32213 : }
32214 51912 : break;
32215 0 : case dw_val_class_const_double:
32216 0 : hstate.add_object (val2->v.val_double.low);
32217 0 : hstate.add_object (val2->v.val_double.high);
32218 0 : break;
32219 626 : case dw_val_class_wide_int:
32220 1252 : hstate.add (val2->v.val_wide->get_val (),
32221 626 : get_full_len (*val2->v.val_wide)
32222 626 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
32223 626 : break;
32224 0 : case dw_val_class_addr:
32225 0 : inchash::add_rtx (val2->v.val_addr, hstate);
32226 0 : break;
32227 0 : default:
32228 0 : gcc_unreachable ();
32229 : }
32230 : break;
32231 170242 : case DW_OP_bregx:
32232 170242 : case DW_OP_bit_piece:
32233 170242 : hstate.add_object (val1->v.val_int);
32234 170242 : hstate.add_object (val2->v.val_int);
32235 170242 : break;
32236 566022 : case DW_OP_addr:
32237 566022 : hash_addr:
32238 566022 : if (loc->dw_loc_dtprel)
32239 : {
32240 195 : unsigned char dtprel = 0xd1;
32241 195 : hstate.add_object (dtprel);
32242 : }
32243 566022 : inchash::add_rtx (val1->v.val_addr, hstate);
32244 566022 : break;
32245 3 : case DW_OP_GNU_addr_index:
32246 3 : case DW_OP_addrx:
32247 3 : case DW_OP_GNU_const_index:
32248 3 : case DW_OP_constx:
32249 3 : {
32250 3 : if (loc->dw_loc_dtprel)
32251 : {
32252 0 : unsigned char dtprel = 0xd1;
32253 0 : hstate.add_object (dtprel);
32254 : }
32255 3 : inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
32256 : }
32257 3 : break;
32258 1199946 : case DW_OP_implicit_pointer:
32259 1199946 : case DW_OP_GNU_implicit_pointer:
32260 1199946 : hstate.add_int (val2->v.val_int);
32261 1199946 : break;
32262 1291019 : case DW_OP_entry_value:
32263 1291019 : case DW_OP_GNU_entry_value:
32264 1291019 : hstate.add_object (val1->v.val_loc);
32265 1291019 : break;
32266 111580 : case DW_OP_regval_type:
32267 111580 : case DW_OP_deref_type:
32268 111580 : case DW_OP_GNU_regval_type:
32269 111580 : case DW_OP_GNU_deref_type:
32270 111580 : {
32271 111580 : unsigned int byte_size
32272 111580 : = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
32273 111580 : unsigned int encoding
32274 111580 : = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
32275 111580 : hstate.add_object (val1->v.val_int);
32276 111580 : hstate.add_object (byte_size);
32277 111580 : hstate.add_object (encoding);
32278 : }
32279 111580 : break;
32280 168152 : case DW_OP_convert:
32281 168152 : case DW_OP_reinterpret:
32282 168152 : case DW_OP_GNU_convert:
32283 168152 : case DW_OP_GNU_reinterpret:
32284 168152 : if (val1->val_class == dw_val_class_unsigned_const)
32285 : {
32286 26426 : hstate.add_object (val1->v.val_unsigned);
32287 26426 : break;
32288 : }
32289 : /* FALLTHRU */
32290 172029 : case DW_OP_const_type:
32291 172029 : case DW_OP_GNU_const_type:
32292 172029 : {
32293 172029 : unsigned int byte_size
32294 172029 : = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
32295 172029 : unsigned int encoding
32296 172029 : = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
32297 172029 : hstate.add_object (byte_size);
32298 172029 : hstate.add_object (encoding);
32299 172029 : if (loc->dw_loc_opc != DW_OP_const_type
32300 141726 : && loc->dw_loc_opc != DW_OP_GNU_const_type)
32301 : break;
32302 30303 : hstate.add_object (val2->val_class);
32303 30303 : switch (val2->val_class)
32304 : {
32305 9125 : case dw_val_class_const:
32306 9125 : hstate.add_object (val2->v.val_int);
32307 9125 : break;
32308 20936 : case dw_val_class_vec:
32309 20936 : {
32310 20936 : unsigned int elt_size = val2->v.val_vec.elt_size;
32311 20936 : unsigned int len = val2->v.val_vec.length;
32312 :
32313 20936 : hstate.add_object (elt_size);
32314 20936 : hstate.add_object (len);
32315 20936 : hstate.add (val2->v.val_vec.array, len * elt_size);
32316 : }
32317 20936 : break;
32318 156 : case dw_val_class_const_double:
32319 156 : hstate.add_object (val2->v.val_double.low);
32320 156 : hstate.add_object (val2->v.val_double.high);
32321 156 : break;
32322 86 : case dw_val_class_wide_int:
32323 172 : hstate.add (val2->v.val_wide->get_val (),
32324 86 : get_full_len (*val2->v.val_wide)
32325 86 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
32326 86 : break;
32327 0 : default:
32328 0 : gcc_unreachable ();
32329 : }
32330 : }
32331 30303 : break;
32332 :
32333 : default:
32334 : /* Other codes have no operands. */
32335 : break;
32336 : }
32337 52715279 : }
32338 :
32339 : /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
32340 :
32341 : static inline void
32342 24353966 : hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
32343 : {
32344 24353966 : dw_loc_descr_ref l;
32345 24353966 : bool sizes_computed = false;
32346 : /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
32347 24353966 : size_of_locs (loc);
32348 :
32349 77068635 : for (l = loc; l != NULL; l = l->dw_loc_next)
32350 : {
32351 52714669 : enum dwarf_location_atom opc = l->dw_loc_opc;
32352 52714669 : hstate.add_object (opc);
32353 52714669 : if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
32354 : {
32355 105100 : size_of_locs (loc);
32356 105100 : sizes_computed = true;
32357 : }
32358 52714669 : hash_loc_operands (l, hstate);
32359 : }
32360 24353966 : }
32361 :
32362 : /* Compute hash of the whole location list LIST_HEAD. */
32363 :
32364 : static inline void
32365 11315230 : hash_loc_list (dw_loc_list_ref list_head)
32366 : {
32367 11315230 : dw_loc_list_ref curr = list_head;
32368 11315230 : inchash::hash hstate;
32369 :
32370 35669196 : for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
32371 : {
32372 24353966 : hstate.add (curr->begin, strlen (curr->begin) + 1);
32373 24353966 : hstate.add (curr->end, strlen (curr->end) + 1);
32374 24353966 : hstate.add_object (curr->vbegin);
32375 24353966 : hstate.add_object (curr->vend);
32376 24353966 : if (curr->section)
32377 24353966 : hstate.add (curr->section, strlen (curr->section) + 1);
32378 24353966 : hash_locs (curr->expr, hstate);
32379 : }
32380 11315230 : list_head->hash = hstate.end ();
32381 11315230 : }
32382 :
32383 : /* Return true if X and Y opcodes have the same operands. */
32384 :
32385 : static inline bool
32386 730755 : compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
32387 : {
32388 730755 : dw_val_ref valx1 = &x->dw_loc_oprnd1;
32389 730755 : dw_val_ref valx2 = &x->dw_loc_oprnd2;
32390 730755 : dw_val_ref valy1 = &y->dw_loc_oprnd1;
32391 730755 : dw_val_ref valy2 = &y->dw_loc_oprnd2;
32392 :
32393 730755 : switch (x->dw_loc_opc)
32394 : {
32395 6405 : case DW_OP_const4u:
32396 6405 : case DW_OP_const8u:
32397 6405 : if (x->dw_loc_dtprel)
32398 0 : goto hash_addr;
32399 : /* FALLTHRU */
32400 173775 : case DW_OP_const1u:
32401 173775 : case DW_OP_const1s:
32402 173775 : case DW_OP_const2u:
32403 173775 : case DW_OP_const2s:
32404 173775 : case DW_OP_const4s:
32405 173775 : case DW_OP_const8s:
32406 173775 : case DW_OP_constu:
32407 173775 : case DW_OP_consts:
32408 173775 : case DW_OP_pick:
32409 173775 : case DW_OP_plus_uconst:
32410 173775 : case DW_OP_breg0:
32411 173775 : case DW_OP_breg1:
32412 173775 : case DW_OP_breg2:
32413 173775 : case DW_OP_breg3:
32414 173775 : case DW_OP_breg4:
32415 173775 : case DW_OP_breg5:
32416 173775 : case DW_OP_breg6:
32417 173775 : case DW_OP_breg7:
32418 173775 : case DW_OP_breg8:
32419 173775 : case DW_OP_breg9:
32420 173775 : case DW_OP_breg10:
32421 173775 : case DW_OP_breg11:
32422 173775 : case DW_OP_breg12:
32423 173775 : case DW_OP_breg13:
32424 173775 : case DW_OP_breg14:
32425 173775 : case DW_OP_breg15:
32426 173775 : case DW_OP_breg16:
32427 173775 : case DW_OP_breg17:
32428 173775 : case DW_OP_breg18:
32429 173775 : case DW_OP_breg19:
32430 173775 : case DW_OP_breg20:
32431 173775 : case DW_OP_breg21:
32432 173775 : case DW_OP_breg22:
32433 173775 : case DW_OP_breg23:
32434 173775 : case DW_OP_breg24:
32435 173775 : case DW_OP_breg25:
32436 173775 : case DW_OP_breg26:
32437 173775 : case DW_OP_breg27:
32438 173775 : case DW_OP_breg28:
32439 173775 : case DW_OP_breg29:
32440 173775 : case DW_OP_breg30:
32441 173775 : case DW_OP_breg31:
32442 173775 : case DW_OP_regx:
32443 173775 : case DW_OP_fbreg:
32444 173775 : case DW_OP_piece:
32445 173775 : case DW_OP_deref_size:
32446 173775 : case DW_OP_xderef_size:
32447 173775 : return valx1->v.val_int == valy1->v.val_int;
32448 270 : case DW_OP_skip:
32449 270 : case DW_OP_bra:
32450 : /* If splitting debug info, the use of DW_OP_GNU_addr_index
32451 : can cause irrelevant differences in dw_loc_addr. */
32452 270 : gcc_assert (valx1->val_class == dw_val_class_loc
32453 : && valy1->val_class == dw_val_class_loc
32454 : && (dwarf_split_debug_info
32455 : || x->dw_loc_addr == y->dw_loc_addr));
32456 270 : return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
32457 6610 : case DW_OP_implicit_value:
32458 6610 : if (valx1->v.val_unsigned != valy1->v.val_unsigned
32459 6610 : || valx2->val_class != valy2->val_class)
32460 : return false;
32461 6610 : switch (valx2->val_class)
32462 : {
32463 5115 : case dw_val_class_const:
32464 5115 : return valx2->v.val_int == valy2->v.val_int;
32465 1351 : case dw_val_class_vec:
32466 1351 : return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
32467 1351 : && valx2->v.val_vec.length == valy2->v.val_vec.length
32468 1351 : && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
32469 : valx2->v.val_vec.elt_size
32470 1351 : * valx2->v.val_vec.length) == 0;
32471 0 : case dw_val_class_const_double:
32472 0 : return valx2->v.val_double.low == valy2->v.val_double.low
32473 0 : && valx2->v.val_double.high == valy2->v.val_double.high;
32474 144 : case dw_val_class_wide_int:
32475 144 : return *valx2->v.val_wide == *valy2->v.val_wide;
32476 0 : case dw_val_class_addr:
32477 0 : return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
32478 0 : default:
32479 0 : gcc_unreachable ();
32480 : }
32481 0 : case DW_OP_bregx:
32482 0 : case DW_OP_bit_piece:
32483 0 : return valx1->v.val_int == valy1->v.val_int
32484 0 : && valx2->v.val_int == valy2->v.val_int;
32485 13505 : case DW_OP_addr:
32486 13505 : hash_addr:
32487 13505 : return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
32488 0 : case DW_OP_GNU_addr_index:
32489 0 : case DW_OP_addrx:
32490 0 : case DW_OP_GNU_const_index:
32491 0 : case DW_OP_constx:
32492 0 : {
32493 0 : rtx ax1 = valx1->val_entry->addr.rtl;
32494 0 : rtx ay1 = valy1->val_entry->addr.rtl;
32495 0 : return rtx_equal_p (ax1, ay1);
32496 : }
32497 67487 : case DW_OP_implicit_pointer:
32498 67487 : case DW_OP_GNU_implicit_pointer:
32499 67487 : return valx1->val_class == dw_val_class_die_ref
32500 67487 : && valx1->val_class == valy1->val_class
32501 67487 : && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
32502 70709 : && valx2->v.val_int == valy2->v.val_int;
32503 0 : case DW_OP_entry_value:
32504 0 : case DW_OP_GNU_entry_value:
32505 0 : return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
32506 209 : case DW_OP_const_type:
32507 209 : case DW_OP_GNU_const_type:
32508 209 : if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
32509 209 : || valx2->val_class != valy2->val_class)
32510 : return false;
32511 209 : switch (valx2->val_class)
32512 : {
32513 149 : case dw_val_class_const:
32514 149 : return valx2->v.val_int == valy2->v.val_int;
32515 60 : case dw_val_class_vec:
32516 60 : return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
32517 60 : && valx2->v.val_vec.length == valy2->v.val_vec.length
32518 60 : && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
32519 : valx2->v.val_vec.elt_size
32520 60 : * valx2->v.val_vec.length) == 0;
32521 0 : case dw_val_class_const_double:
32522 0 : return valx2->v.val_double.low == valy2->v.val_double.low
32523 0 : && valx2->v.val_double.high == valy2->v.val_double.high;
32524 0 : case dw_val_class_wide_int:
32525 0 : return *valx2->v.val_wide == *valy2->v.val_wide;
32526 0 : default:
32527 0 : gcc_unreachable ();
32528 : }
32529 1366 : case DW_OP_regval_type:
32530 1366 : case DW_OP_deref_type:
32531 1366 : case DW_OP_GNU_regval_type:
32532 1366 : case DW_OP_GNU_deref_type:
32533 1366 : return valx1->v.val_int == valy1->v.val_int
32534 1366 : && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
32535 735 : case DW_OP_convert:
32536 735 : case DW_OP_reinterpret:
32537 735 : case DW_OP_GNU_convert:
32538 735 : case DW_OP_GNU_reinterpret:
32539 735 : if (valx1->val_class != valy1->val_class)
32540 : return false;
32541 735 : if (valx1->val_class == dw_val_class_unsigned_const)
32542 6 : return valx1->v.val_unsigned == valy1->v.val_unsigned;
32543 729 : return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
32544 4621 : case DW_OP_GNU_parameter_ref:
32545 4621 : return valx1->val_class == dw_val_class_die_ref
32546 4621 : && valx1->val_class == valy1->val_class
32547 9242 : && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
32548 : default:
32549 : /* Other codes have no operands. */
32550 : return true;
32551 : }
32552 : }
32553 :
32554 : /* Return true if DWARF location expressions X and Y are the same. */
32555 :
32556 : static inline bool
32557 308091 : compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
32558 : {
32559 970109 : for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
32560 730755 : if (x->dw_loc_opc != y->dw_loc_opc
32561 730755 : || x->dw_loc_dtprel != y->dw_loc_dtprel
32562 1461510 : || !compare_loc_operands (x, y))
32563 : break;
32564 308091 : return x == NULL && y == NULL;
32565 : }
32566 :
32567 : /* Hashtable helpers. */
32568 :
32569 : struct loc_list_hasher : nofree_ptr_hash <dw_loc_list_struct>
32570 : {
32571 : static inline hashval_t hash (const dw_loc_list_struct *);
32572 : static inline bool equal (const dw_loc_list_struct *,
32573 : const dw_loc_list_struct *);
32574 : };
32575 :
32576 : /* Return precomputed hash of location list X. */
32577 :
32578 : inline hashval_t
32579 68081520 : loc_list_hasher::hash (const dw_loc_list_struct *x)
32580 : {
32581 68081520 : return x->hash;
32582 : }
32583 :
32584 : /* Return true if location lists A and B are the same. */
32585 :
32586 : inline bool
32587 67755343 : loc_list_hasher::equal (const dw_loc_list_struct *a,
32588 : const dw_loc_list_struct *b)
32589 : {
32590 67755343 : if (a == b)
32591 : return true;
32592 67755343 : if (a->hash != b->hash)
32593 : return false;
32594 437135 : for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
32595 308112 : if (strcmp (a->begin, b->begin) != 0
32596 308091 : || strcmp (a->end, b->end) != 0
32597 308091 : || (a->section == NULL) != (b->section == NULL)
32598 308091 : || (a->section && strcmp (a->section, b->section) != 0)
32599 308091 : || a->vbegin != b->vbegin || a->vend != b->vend
32600 616203 : || !compare_locs (a->expr, b->expr))
32601 : break;
32602 197781 : return a == NULL && b == NULL;
32603 : }
32604 :
32605 : typedef hash_table<loc_list_hasher> loc_list_hash_type;
32606 :
32607 :
32608 : /* Recursively optimize location lists referenced from DIE
32609 : children and share them whenever possible. */
32610 :
32611 : static void
32612 72036785 : optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
32613 : {
32614 72036785 : dw_die_ref c;
32615 72036785 : dw_attr_node *a;
32616 72036785 : unsigned ix;
32617 72036785 : dw_loc_list_struct **slot;
32618 72036785 : bool drop_locviews = false;
32619 72036785 : bool has_locviews = false;
32620 :
32621 354682569 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
32622 282645784 : if (AT_class (a) == dw_val_class_loc_list)
32623 : {
32624 11315230 : dw_loc_list_ref list = AT_loc_list (a);
32625 : /* TODO: perform some optimizations here, before hashing
32626 : it and storing into the hash table. */
32627 11315230 : hash_loc_list (list);
32628 11315230 : slot = htab->find_slot_with_hash (list, list->hash, INSERT);
32629 11315230 : if (*slot == NULL)
32630 : {
32631 11186207 : *slot = list;
32632 11186207 : if (loc_list_has_views (list))
32633 11010892 : gcc_assert (list->vl_symbol);
32634 175315 : else if (list->vl_symbol)
32635 : {
32636 0 : drop_locviews = true;
32637 0 : list->vl_symbol = NULL;
32638 : }
32639 : }
32640 : else
32641 : {
32642 129023 : if (list->vl_symbol && !(*slot)->vl_symbol)
32643 129023 : drop_locviews = true;
32644 129023 : a->dw_attr_val.v.val_loc_list = *slot;
32645 : }
32646 : }
32647 271330554 : else if (AT_class (a) == dw_val_class_view_list)
32648 : {
32649 11139022 : gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
32650 : has_locviews = true;
32651 : }
32652 :
32653 :
32654 72036785 : if (drop_locviews && has_locviews)
32655 0 : remove_AT (die, DW_AT_GNU_locviews);
32656 :
32657 144040901 : FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
32658 72036785 : }
32659 :
32660 :
32661 : /* Recursively assign each location list a unique index into the debug_addr
32662 : section. */
32663 :
32664 : static void
32665 26 : index_location_lists (dw_die_ref die)
32666 : {
32667 26 : dw_die_ref c;
32668 26 : dw_attr_node *a;
32669 26 : unsigned ix;
32670 :
32671 155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
32672 129 : if (AT_class (a) == dw_val_class_loc_list)
32673 : {
32674 2 : dw_loc_list_ref list = AT_loc_list (a);
32675 2 : dw_loc_list_ref curr;
32676 8 : for (curr = list; curr != NULL; curr = curr->dw_loc_next)
32677 : {
32678 : /* Don't index an entry that has already been indexed
32679 : or won't be output. Make sure skip_loc_list_entry doesn't
32680 : call size_of_locs, because that might cause circular dependency,
32681 : index_location_lists requiring address table indexes to be
32682 : computed, but adding new indexes through add_addr_table_entry
32683 : and address table index computation requiring no new additions
32684 : to the hash table. In the rare case of DWARF[234] >= 64KB
32685 : location expression, we'll just waste unused address table entry
32686 : for it. */
32687 4 : if (curr->begin_entry != NULL || skip_loc_list_entry (curr))
32688 0 : continue;
32689 :
32690 4 : curr->begin_entry
32691 4 : = add_addr_table_entry (xstrdup (curr->begin), ate_kind_label);
32692 4 : if (dwarf_version >= 5 && !HAVE_AS_LEB128)
32693 : curr->end_entry
32694 : = add_addr_table_entry (xstrdup (curr->end), ate_kind_label);
32695 : }
32696 : }
32697 :
32698 50 : FOR_EACH_CHILD (die, c, index_location_lists (c));
32699 26 : }
32700 :
32701 : /* Optimize location lists referenced from DIE
32702 : children and share them whenever possible. */
32703 :
32704 : static void
32705 32669 : optimize_location_lists (dw_die_ref die)
32706 : {
32707 32669 : loc_list_hash_type htab (500);
32708 32669 : optimize_location_lists_1 (die, &htab);
32709 32669 : }
32710 :
32711 : /* Traverse the limbo die list, and add parent/child links. The only
32712 : dies without parents that should be here are concrete instances of
32713 : inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
32714 : For concrete instances, we can get the parent die from the abstract
32715 : instance. */
32716 :
32717 : static void
32718 104505 : flush_limbo_die_list (void)
32719 : {
32720 104505 : limbo_die_node *node;
32721 :
32722 : /* get_context_die calls force_decl_die, which can put new DIEs on the
32723 : limbo list in LTO mode when nested functions are put in a different
32724 : partition than that of their parent function. */
32725 104505 : while ((node = limbo_die_list))
32726 : {
32727 352134 : dw_die_ref die = node->die;
32728 352134 : limbo_die_list = node->next;
32729 :
32730 352134 : if (die->die_parent == NULL)
32731 : {
32732 341410 : dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
32733 :
32734 341410 : if (origin && origin->die_parent)
32735 9851 : add_child_die (origin->die_parent, die);
32736 788198 : else if (is_cu_die (die))
32737 : ;
32738 278366 : else if (seen_error ())
32739 : /* It's OK to be confused by errors in the input. */
32740 0 : add_child_die (comp_unit_die (), die);
32741 : else
32742 : {
32743 : /* In certain situations, the lexical block containing a
32744 : nested function can be optimized away, which results
32745 : in the nested function die being orphaned. Likewise
32746 : with the return type of that nested function. Force
32747 : this to be a child of the containing function.
32748 :
32749 : It may happen that even the containing function got fully
32750 : inlined and optimized out. In that case we are lost and
32751 : assign the empty child. This should not be big issue as
32752 : the function is likely unreachable too. */
32753 278366 : gcc_assert (node->created_for);
32754 :
32755 278366 : if (DECL_P (node->created_for))
32756 2843 : origin = get_context_die (DECL_CONTEXT (node->created_for));
32757 275523 : else if (TYPE_P (node->created_for))
32758 275523 : origin = scope_die_for (node->created_for, comp_unit_die ());
32759 : else
32760 0 : origin = comp_unit_die ();
32761 :
32762 278366 : add_child_die (origin, die);
32763 : }
32764 : }
32765 : }
32766 104505 : }
32767 :
32768 : /* Reset DIEs so we can output them again. */
32769 :
32770 : static void
32771 35738 : reset_dies (dw_die_ref die)
32772 : {
32773 35738 : dw_die_ref c;
32774 :
32775 : /* Remove stuff we re-generate. */
32776 35738 : die->die_mark = 0;
32777 35738 : die->die_offset = 0;
32778 35738 : die->die_abbrev = 0;
32779 35738 : remove_AT (die, DW_AT_sibling);
32780 :
32781 70922 : FOR_EACH_CHILD (die, c, reset_dies (c));
32782 35738 : }
32783 :
32784 : /* reset_indirect_string removed the references coming from DW_AT_name
32785 : and DW_AT_comp_dir attributes on compilation unit DIEs. Readd them as
32786 : .debug_line_str strings again. */
32787 :
32788 : static void
32789 542 : adjust_name_comp_dir (dw_die_ref die)
32790 : {
32791 1626 : for (int i = 0; i < 2; i++)
32792 : {
32793 1084 : dwarf_attribute attr_kind = i ? DW_AT_comp_dir : DW_AT_name;
32794 1084 : dw_attr_node *a = get_AT (die, attr_kind);
32795 1084 : if (a == NULL || a->dw_attr_val.val_class != dw_val_class_str)
32796 0 : continue;
32797 :
32798 1084 : if (!debug_line_str_hash)
32799 542 : debug_line_str_hash
32800 542 : = hash_table<indirect_string_hasher>::create_ggc (10);
32801 :
32802 1084 : struct indirect_string_node *node
32803 1084 : = find_AT_string_in_table (a->dw_attr_val.v.val_str->str,
32804 : debug_line_str_hash);
32805 1084 : set_indirect_string (node);
32806 1084 : node->form = DW_FORM_line_strp;
32807 1084 : a->dw_attr_val.v.val_str = node;
32808 : }
32809 542 : }
32810 :
32811 : /* Output stuff that dwarf requires at the end of every file,
32812 : and generate the DWARF-2 debugging info. */
32813 :
32814 : static void
32815 52399 : dwarf2out_finish (const char *filename)
32816 : {
32817 52399 : comdat_type_node *ctnode;
32818 52399 : dw_die_ref main_comp_unit_die;
32819 52399 : unsigned char checksum[16];
32820 52399 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
32821 :
32822 : /* Generate CTF/BTF debug info. */
32823 52399 : if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
32824 52399 : || btf_debuginfo_p ()) && lang_GNU_C ())
32825 267 : ctf_debug_finish ();
32826 :
32827 : #ifdef CODEVIEW_DEBUGGING_INFO
32828 : if (codeview_debuginfo_p ())
32829 : codeview_debug_finish ();
32830 : #endif
32831 :
32832 : /* Skip emitting DWARF if not required. */
32833 52399 : if (!dwarf_debuginfo_p ())
32834 319 : return;
32835 :
32836 : /* Flush out any latecomers to the limbo party. */
32837 52080 : flush_limbo_die_list ();
32838 :
32839 52080 : if (btf_tag_htab)
32840 15 : btf_tag_htab->empty ();
32841 :
32842 52080 : if (inline_entry_data_table)
32843 12666 : gcc_assert (inline_entry_data_table->is_empty ());
32844 :
32845 52080 : if (flag_checking)
32846 : {
32847 52079 : verify_die (comp_unit_die ());
32848 52079 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32849 0 : verify_die (node->die);
32850 : }
32851 :
32852 : /* We shouldn't have any symbols with delayed asm names for
32853 : DIEs generated after early finish. */
32854 52080 : gcc_assert (deferred_asm_name == NULL);
32855 :
32856 52080 : gen_remaining_tmpl_value_param_die_attribute ();
32857 :
32858 52080 : if (flag_generate_lto || flag_generate_offload)
32859 : {
32860 552 : gcc_assert (flag_fat_lto_objects || flag_generate_offload);
32861 :
32862 : /* Prune stuff so that dwarf2out_finish runs successfully
32863 : for the fat part of the object. */
32864 552 : reset_dies (comp_unit_die ());
32865 552 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32866 0 : reset_dies (node->die);
32867 554 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32868 : {
32869 : /* Remove the pointer to the line table. */
32870 2 : remove_AT (ctnode->root_die, DW_AT_stmt_list);
32871 2 : if (debug_info_level >= DINFO_LEVEL_TERSE)
32872 2 : reset_dies (ctnode->root_die);
32873 : }
32874 :
32875 : /* Reset die CU symbol so we don't output it twice. */
32876 552 : comp_unit_die ()->die_id.die_symbol = NULL;
32877 :
32878 : /* Remove DW_AT_macro and DW_AT_stmt_list from the early output. */
32879 552 : remove_AT (comp_unit_die (), DW_AT_stmt_list);
32880 552 : if (have_macinfo)
32881 6 : remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE);
32882 :
32883 : /* Remove indirect string decisions. */
32884 19252 : debug_str_hash->traverse<void *, reset_indirect_string> (NULL);
32885 552 : if (debug_line_str_hash)
32886 : {
32887 542 : debug_line_str_hash->traverse<void *, reset_indirect_string> (NULL);
32888 542 : debug_line_str_hash = NULL;
32889 542 : if (asm_outputs_debug_line_str ())
32890 : {
32891 542 : adjust_name_comp_dir (comp_unit_die ());
32892 542 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32893 0 : adjust_name_comp_dir (node->die);
32894 : }
32895 : }
32896 : }
32897 :
32898 : #if ENABLE_ASSERT_CHECKING
32899 52080 : {
32900 52080 : dw_die_ref die = comp_unit_die (), c;
32901 9546109 : FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
32902 : }
32903 : #endif
32904 52080 : base_types.truncate (0);
32905 52157 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32906 77 : resolve_addr (ctnode->root_die);
32907 52080 : resolve_addr (comp_unit_die ());
32908 52080 : move_marked_base_types ();
32909 :
32910 52080 : if (dump_file)
32911 : {
32912 4 : fprintf (dump_file, "DWARF for %s\n", filename);
32913 4 : print_die (comp_unit_die (), dump_file);
32914 : }
32915 :
32916 : /* Initialize sections and labels used for actual assembler output. */
32917 52080 : unsigned generation = init_sections_and_labels (false);
32918 :
32919 : /* Traverse the DIE's and add sibling attributes to those DIE's that
32920 : have children. */
32921 52080 : add_sibling_attributes (comp_unit_die ());
32922 52080 : limbo_die_node *node;
32923 52080 : for (node = cu_die_list; node; node = node->next)
32924 0 : add_sibling_attributes (node->die);
32925 52157 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32926 77 : add_sibling_attributes (ctnode->root_die);
32927 :
32928 : /* When splitting DWARF info, we put some attributes in the
32929 : skeleton compile_unit DIE that remains in the .o, while
32930 : most attributes go in the DWO compile_unit_die. */
32931 52080 : if (dwarf_split_debug_info)
32932 : {
32933 249 : limbo_die_node *cu;
32934 249 : main_comp_unit_die = gen_compile_unit_die (NULL);
32935 249 : if (dwarf_version >= 5)
32936 248 : main_comp_unit_die->die_tag = DW_TAG_skeleton_unit;
32937 249 : cu = limbo_die_list;
32938 249 : gcc_assert (cu->die == main_comp_unit_die);
32939 249 : limbo_die_list = limbo_die_list->next;
32940 249 : cu->next = cu_die_list;
32941 249 : cu_die_list = cu;
32942 : }
32943 : else
32944 51831 : main_comp_unit_die = comp_unit_die ();
32945 :
32946 : /* Output a terminator label for the .text section. */
32947 52080 : switch_to_section (text_section);
32948 52080 : targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
32949 52080 : if (cold_text_section)
32950 : {
32951 8667 : switch_to_section (cold_text_section);
32952 8667 : targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
32953 : }
32954 :
32955 : /* We can only use the low/high_pc attributes if all of the code was
32956 : in .text. */
32957 52080 : if ((!have_multiple_function_sections
32958 23945 : && vec_safe_length (switch_text_ranges) < 2)
32959 52099 : || (dwarf_version < 3 && dwarf_strict))
32960 : {
32961 23926 : const char *end_label = text_end_label;
32962 23926 : if (vec_safe_length (switch_text_ranges) == 1)
32963 138 : end_label = (*switch_text_ranges)[0];
32964 : /* Don't add if the CU has no associated code. */
32965 23926 : if (switch_text_ranges)
32966 19378 : add_AT_low_high_pc (main_comp_unit_die, text_section_label,
32967 : end_label, true);
32968 : }
32969 : else
32970 : {
32971 28154 : unsigned fde_idx;
32972 28154 : dw_fde_ref fde;
32973 28154 : bool range_list_added = false;
32974 28154 : if (switch_text_ranges)
32975 : {
32976 : const char *prev_loc = text_section_label;
32977 : const char *loc;
32978 : unsigned idx;
32979 :
32980 11002 : FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
32981 858 : if (prev_loc)
32982 : {
32983 451 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32984 : loc, &range_list_added, true);
32985 451 : prev_loc = NULL;
32986 : }
32987 : else
32988 : prev_loc = loc;
32989 :
32990 10144 : if (prev_loc)
32991 10100 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32992 : text_end_label, &range_list_added, true);
32993 : }
32994 :
32995 28154 : if (switch_cold_ranges)
32996 : {
32997 : const char *prev_loc = cold_text_section_label;
32998 : const char *loc;
32999 : unsigned idx;
33000 :
33001 8667 : FOR_EACH_VEC_ELT (*switch_cold_ranges, idx, loc)
33002 0 : if (prev_loc)
33003 : {
33004 0 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
33005 : loc, &range_list_added, true);
33006 0 : prev_loc = NULL;
33007 : }
33008 : else
33009 : prev_loc = loc;
33010 :
33011 8667 : if (prev_loc)
33012 8667 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
33013 : cold_end_label, &range_list_added, true);
33014 : }
33015 :
33016 287376 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
33017 : {
33018 259222 : if (fde->ignored_debug)
33019 2917 : continue;
33020 256305 : if (!fde->in_std_section)
33021 183739 : add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
33022 : fde->dw_fde_end, &range_list_added,
33023 : true);
33024 256305 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
33025 9479 : add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
33026 : fde->dw_fde_second_end, &range_list_added,
33027 : true);
33028 : }
33029 :
33030 28154 : if (range_list_added)
33031 : {
33032 : /* We need to give .debug_loc and .debug_ranges an appropriate
33033 : "base address". Use zero so that these addresses become
33034 : absolute. Historically, we've emitted the unexpected
33035 : DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
33036 : Emit both to give time for other tools to adapt. */
33037 28154 : add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
33038 28154 : if (! dwarf_strict && dwarf_version < 4)
33039 428 : add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
33040 :
33041 28154 : add_ranges (NULL);
33042 28154 : have_multiple_function_sections = true;
33043 : }
33044 : }
33045 :
33046 : /* AIX Assembler inserts the length, so adjust the reference to match the
33047 : offset expected by debuggers. */
33048 52080 : strcpy (dl_section_ref, debug_line_section_label);
33049 52080 : if (XCOFF_DEBUGGING_INFO)
33050 : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
33051 :
33052 52080 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33053 52080 : add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
33054 : dl_section_ref);
33055 :
33056 52080 : if (have_macinfo)
33057 1002 : add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
33058 : macinfo_section_label);
33059 :
33060 52080 : if (dwarf_split_debug_info)
33061 : {
33062 249 : if (have_location_lists)
33063 : {
33064 : /* Since we generate the loclists in the split DWARF .dwo
33065 : file itself, we don't need to generate a loclists_base
33066 : attribute for the split compile unit DIE. That attribute
33067 : (and using relocatable sec_offset FORMs) isn't allowed
33068 : for a split compile unit. Only if the .debug_loclists
33069 : section was in the main file, would we need to generate a
33070 : loclists_base attribute here (for the full or skeleton
33071 : unit DIE). */
33072 :
33073 : /* optimize_location_lists calculates the size of the lists,
33074 : so index them first, and assign indices to the entries.
33075 : Although optimize_location_lists will remove entries from
33076 : the table, it only does so for duplicates, and therefore
33077 : only reduces ref_counts to 1. */
33078 2 : index_location_lists (comp_unit_die ());
33079 : }
33080 :
33081 249 : if (dwarf_version >= 5 && !vec_safe_is_empty (ranges_table))
33082 3 : index_rnglists ();
33083 :
33084 249 : if (addr_index_table != NULL)
33085 : {
33086 244 : unsigned int index = 0;
33087 244 : addr_index_table
33088 : ->traverse_noresize<unsigned int *, index_addr_table_entry>
33089 508 : (&index);
33090 : }
33091 : }
33092 :
33093 52080 : loc_list_idx = 0;
33094 52080 : if (have_location_lists)
33095 : {
33096 32669 : optimize_location_lists (comp_unit_die ());
33097 : /* And finally assign indexes to the entries for -gsplit-dwarf. */
33098 32669 : if (dwarf_version >= 5 && dwarf_split_debug_info)
33099 2 : assign_location_list_indexes (comp_unit_die ());
33100 : }
33101 :
33102 52080 : save_macinfo_strings ();
33103 :
33104 52080 : if (dwarf_split_debug_info)
33105 : {
33106 249 : unsigned int index = 0;
33107 :
33108 : /* Add attributes common to skeleton compile_units and
33109 : type_units. Because these attributes include strings, it
33110 : must be done before freezing the string table. Top-level
33111 : skeleton die attrs are added when the skeleton type unit is
33112 : created, so ensure it is created by this point. */
33113 249 : add_top_level_skeleton_die_attrs (main_comp_unit_die);
33114 3176 : debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
33115 : }
33116 :
33117 : /* Output all of the compilation units. We put the main one last so that
33118 : the offsets are available to output_pubnames. */
33119 52329 : for (node = cu_die_list; node; node = node->next)
33120 249 : output_comp_unit (node->die, 0, NULL);
33121 :
33122 52080 : hash_table<comdat_type_hasher> comdat_type_table (100);
33123 52157 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33124 : {
33125 77 : comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
33126 :
33127 : /* Don't output duplicate types. */
33128 77 : if (*slot != HTAB_EMPTY_ENTRY)
33129 1 : continue;
33130 :
33131 : /* Add a pointer to the line table for the main compilation unit
33132 : so that the debugger can make sense of DW_AT_decl_file
33133 : attributes. */
33134 76 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33135 76 : add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
33136 76 : (!dwarf_split_debug_info
33137 : ? dl_section_ref
33138 : : debug_skeleton_line_section_label));
33139 :
33140 76 : output_comdat_type_unit (ctnode, false);
33141 76 : *slot = ctnode;
33142 : }
33143 :
33144 52080 : if (dwarf_split_debug_info)
33145 : {
33146 249 : int mark;
33147 249 : struct md5_ctx ctx;
33148 :
33149 : /* Compute a checksum of the comp_unit to use as the dwo_id. */
33150 249 : md5_init_ctx (&ctx);
33151 249 : mark = 0;
33152 249 : die_checksum (comp_unit_die (), &ctx, &mark);
33153 249 : unmark_all_dies (comp_unit_die ());
33154 249 : md5_finish_ctx (&ctx, checksum);
33155 :
33156 249 : if (dwarf_version < 5)
33157 : {
33158 : /* Use the first 8 bytes of the checksum as the dwo_id,
33159 : and add it to both comp-unit DIEs. */
33160 1 : add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
33161 1 : add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
33162 : }
33163 :
33164 : /* Add the base offset of the ranges table to the skeleton
33165 : comp-unit DIE. */
33166 249 : if (!vec_safe_is_empty (ranges_table))
33167 : {
33168 3 : if (dwarf_version < 5)
33169 0 : add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
33170 : ranges_section_label);
33171 : }
33172 :
33173 249 : output_addr_table ();
33174 : }
33175 :
33176 : /* Output the main compilation unit if non-empty or if .debug_macinfo
33177 : or .debug_macro will be emitted. */
33178 103648 : output_comp_unit (comp_unit_die (), have_macinfo,
33179 52080 : dwarf_split_debug_info ? checksum : NULL);
33180 :
33181 52080 : if (dwarf_split_debug_info && info_section_emitted)
33182 249 : output_skeleton_debug_sections (main_comp_unit_die, checksum);
33183 :
33184 : /* Output the abbreviation table. */
33185 52080 : if (vec_safe_length (abbrev_die_table) != 1)
33186 : {
33187 51040 : switch_to_section (debug_abbrev_section);
33188 51040 : ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
33189 51040 : output_abbrev_section ();
33190 : }
33191 :
33192 : /* Output location list section if necessary. */
33193 52080 : if (have_location_lists)
33194 : {
33195 32669 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
33196 32669 : char l2[MAX_ARTIFICIAL_LABEL_BYTES];
33197 : /* Output the location lists info. */
33198 32669 : switch_to_section (debug_loc_section);
33199 32669 : if (dwarf_version >= 5)
33200 : {
33201 31607 : ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_LOC_SECTION_LABEL, 2);
33202 31607 : ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_LOC_SECTION_LABEL, 3);
33203 31607 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
33204 0 : dw2_asm_output_data (4, 0xffffffff,
33205 : "Initial length escape value indicating "
33206 : "64-bit DWARF extension");
33207 31607 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
33208 : "Length of Location Lists");
33209 31607 : ASM_OUTPUT_LABEL (asm_out_file, l1);
33210 31607 : output_dwarf_version ();
33211 35557 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
33212 31607 : dw2_asm_output_data (1, 0, "Segment Size");
33213 31607 : dw2_asm_output_data (4, dwarf_split_debug_info ? loc_list_idx : 0,
33214 : "Offset Entry Count");
33215 : }
33216 32669 : ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
33217 32669 : if (dwarf_version >= 5 && dwarf_split_debug_info)
33218 : {
33219 2 : unsigned int save_loc_list_idx = loc_list_idx;
33220 2 : loc_list_idx = 0;
33221 2 : output_loclists_offsets (comp_unit_die ());
33222 2 : gcc_assert (save_loc_list_idx == loc_list_idx);
33223 : }
33224 32669 : output_location_lists (comp_unit_die ());
33225 32669 : if (dwarf_version >= 5)
33226 31607 : ASM_OUTPUT_LABEL (asm_out_file, l2);
33227 : }
33228 :
33229 52080 : output_pubtables ();
33230 :
33231 : /* Output the address range information if a CU (.debug_info section)
33232 : was emitted. We output an empty table even if we had no functions
33233 : to put in it. This because the consumer has no way to tell the
33234 : difference between an empty table that we omitted and failure to
33235 : generate a table that would have contained data. */
33236 52080 : if (info_section_emitted)
33237 : {
33238 51038 : switch_to_section (debug_aranges_section);
33239 51038 : output_aranges ();
33240 : }
33241 :
33242 : /* Output ranges section if necessary. */
33243 52080 : if (!vec_safe_is_empty (ranges_table))
33244 : {
33245 32897 : if (dwarf_version >= 5)
33246 : {
33247 32373 : if (dwarf_split_debug_info)
33248 : {
33249 : /* We don't know right now whether there are any
33250 : ranges for .debug_rnglists and any for .debug_rnglists.dwo.
33251 : Depending on into which of those two belongs the first
33252 : ranges_table entry, emit that section first and that
33253 : output_rnglists call will return true if the other kind of
33254 : ranges needs to be emitted as well. */
33255 3 : bool dwo = (*ranges_table)[0].idx != DW_RANGES_IDX_SKELETON;
33256 3 : if (output_rnglists (generation, dwo))
33257 2 : output_rnglists (generation, !dwo);
33258 : }
33259 : else
33260 32370 : output_rnglists (generation, false);
33261 : }
33262 : else
33263 524 : output_ranges ();
33264 : }
33265 :
33266 : /* Have to end the macro section. */
33267 52080 : if (have_macinfo)
33268 : {
33269 512 : switch_to_section (debug_macinfo_section);
33270 512 : ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
33271 516 : output_macinfo (!dwarf_split_debug_info ? debug_line_section_label
33272 : : debug_skeleton_line_section_label, false);
33273 512 : dw2_asm_output_data (1, 0, "End compilation unit");
33274 : }
33275 :
33276 : /* Output the source line correspondence table. We must do this
33277 : even if there is no line information. Otherwise, on an empty
33278 : translation unit, we will generate a present, but empty,
33279 : .debug_info section. IRIX 6.5 `nm' will then complain when
33280 : examining the file. This is done late so that any filenames
33281 : used by the debug_info section are marked as 'used'. */
33282 52080 : switch_to_section (debug_line_section);
33283 52080 : ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
33284 52080 : if (! output_asm_line_debug_info ())
33285 6 : output_line_info (false);
33286 :
33287 52080 : if (dwarf_split_debug_info && info_section_emitted)
33288 : {
33289 249 : switch_to_section (debug_skeleton_line_section);
33290 249 : ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
33291 249 : output_line_info (true);
33292 : }
33293 :
33294 : /* If we emitted any indirect strings, output the string table too. */
33295 52080 : if (debug_str_hash || skeleton_debug_str_hash)
33296 52080 : output_indirect_strings ();
33297 52080 : if (debug_line_str_hash)
33298 : {
33299 49827 : switch_to_section (debug_line_str_section);
33300 49827 : const enum dwarf_form form = DW_FORM_line_strp;
33301 49827 : debug_line_str_hash->traverse<enum dwarf_form,
33302 49827 : output_indirect_string> (form);
33303 : }
33304 :
33305 : /* ??? Move lvugid out of dwarf2out_source_line and reset it too? */
33306 52080 : symview_upper_bound = 0;
33307 52080 : if (zero_view_p)
33308 40980 : bitmap_clear (zero_view_p);
33309 52080 : }
33310 :
33311 : /* Returns a hash value for X (which really is a variable_value_struct). */
33312 :
33313 : inline hashval_t
33314 5364 : variable_value_hasher::hash (variable_value_struct *x)
33315 : {
33316 5364 : return (hashval_t) x->decl_id;
33317 : }
33318 :
33319 : /* Return true if decl_id of variable_value_struct X is the same as
33320 : UID of decl Y. */
33321 :
33322 : inline bool
33323 5946 : variable_value_hasher::equal (variable_value_struct *x, tree y)
33324 : {
33325 5946 : return x->decl_id == DECL_UID (y);
33326 : }
33327 :
33328 : /* Helper function for resolve_variable_value, handle
33329 : DW_OP_GNU_variable_value in one location expression.
33330 : Return true if exprloc has been changed into loclist. */
33331 :
33332 : static bool
33333 610 : resolve_variable_value_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
33334 : {
33335 610 : dw_loc_descr_ref next;
33336 2121 : for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = next)
33337 : {
33338 1514 : next = loc->dw_loc_next;
33339 1514 : if (loc->dw_loc_opc != DW_OP_GNU_variable_value
33340 600 : || loc->dw_loc_oprnd1.val_class != dw_val_class_decl_ref)
33341 914 : continue;
33342 :
33343 600 : tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
33344 600 : if (DECL_CONTEXT (decl) != current_function_decl)
33345 0 : continue;
33346 :
33347 600 : dw_die_ref ref = lookup_decl_die (decl);
33348 600 : if (ref)
33349 : {
33350 0 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33351 0 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33352 0 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33353 0 : continue;
33354 : }
33355 600 : dw_loc_list_ref l = loc_list_from_tree (decl, 0, NULL);
33356 600 : if (l == NULL)
33357 121 : continue;
33358 479 : if (l->dw_loc_next)
33359 : {
33360 250 : if (AT_class (a) != dw_val_class_loc)
33361 0 : continue;
33362 250 : switch (a->dw_attr)
33363 : {
33364 : /* Following attributes allow both exprloc and loclist
33365 : classes, so we can change them into a loclist. */
33366 3 : case DW_AT_location:
33367 3 : case DW_AT_string_length:
33368 3 : case DW_AT_return_addr:
33369 3 : case DW_AT_data_member_location:
33370 3 : case DW_AT_frame_base:
33371 3 : case DW_AT_segment:
33372 3 : case DW_AT_static_link:
33373 3 : case DW_AT_use_location:
33374 3 : case DW_AT_vtable_elem_location:
33375 3 : if (prev)
33376 : {
33377 0 : prev->dw_loc_next = NULL;
33378 0 : prepend_loc_descr_to_each (l, AT_loc (a));
33379 : }
33380 3 : if (next)
33381 3 : add_loc_descr_to_each (l, next);
33382 3 : a->dw_attr_val.val_class = dw_val_class_loc_list;
33383 3 : a->dw_attr_val.val_entry = NULL;
33384 3 : a->dw_attr_val.v.val_loc_list = l;
33385 3 : have_location_lists = true;
33386 3 : return true;
33387 : /* Following attributes allow both exprloc and reference,
33388 : so if the whole expression is DW_OP_GNU_variable_value alone
33389 : we could transform it into reference. */
33390 247 : case DW_AT_byte_size:
33391 247 : case DW_AT_bit_size:
33392 247 : case DW_AT_lower_bound:
33393 247 : case DW_AT_upper_bound:
33394 247 : case DW_AT_bit_stride:
33395 247 : case DW_AT_count:
33396 247 : case DW_AT_allocated:
33397 247 : case DW_AT_associated:
33398 247 : case DW_AT_byte_stride:
33399 247 : if (prev == NULL && next == NULL)
33400 : break;
33401 : /* FALLTHRU */
33402 0 : default:
33403 0 : if (dwarf_strict)
33404 0 : continue;
33405 : break;
33406 : }
33407 : /* Create DW_TAG_variable that we can refer to. */
33408 247 : gen_decl_die (decl, NULL_TREE, NULL,
33409 : lookup_decl_die (current_function_decl));
33410 247 : ref = lookup_decl_die (decl);
33411 247 : if (ref)
33412 : {
33413 247 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33414 247 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33415 247 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33416 : }
33417 247 : continue;
33418 : }
33419 229 : if (prev)
33420 : {
33421 0 : prev->dw_loc_next = l->expr;
33422 0 : add_loc_descr (&prev->dw_loc_next, next);
33423 0 : free_loc_descr (loc, NULL);
33424 0 : next = prev->dw_loc_next;
33425 : }
33426 : else
33427 : {
33428 229 : memcpy (loc, l->expr, sizeof (dw_loc_descr_node));
33429 229 : add_loc_descr (&loc, next);
33430 229 : next = loc;
33431 : }
33432 229 : loc = prev;
33433 : }
33434 : return false;
33435 : }
33436 :
33437 : /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
33438 :
33439 : static void
33440 600 : resolve_variable_value (dw_die_ref die)
33441 : {
33442 600 : dw_attr_node *a;
33443 600 : dw_loc_list_ref loc;
33444 600 : unsigned ix;
33445 :
33446 1896 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
33447 1296 : switch (AT_class (a))
33448 : {
33449 600 : case dw_val_class_loc:
33450 600 : if (!resolve_variable_value_in_expr (a, AT_loc (a)))
33451 : break;
33452 : /* FALLTHRU */
33453 3 : case dw_val_class_loc_list:
33454 3 : loc = AT_loc_list (a);
33455 3 : gcc_assert (loc);
33456 13 : for (; loc; loc = loc->dw_loc_next)
33457 10 : resolve_variable_value_in_expr (a, loc->expr);
33458 : break;
33459 : default:
33460 : break;
33461 : }
33462 600 : }
33463 :
33464 : /* Attempt to optimize DW_OP_GNU_variable_value referring to
33465 : temporaries in the current function. */
33466 :
33467 : static void
33468 560209 : resolve_variable_values (void)
33469 : {
33470 560209 : if (!variable_value_hash || !current_function_decl)
33471 : return;
33472 :
33473 2984 : struct variable_value_struct *node
33474 2984 : = variable_value_hash->find_with_hash (current_function_decl,
33475 2984 : DECL_UID (current_function_decl));
33476 :
33477 2984 : if (node == NULL)
33478 : return;
33479 :
33480 : unsigned int i;
33481 : dw_die_ref die;
33482 1055 : FOR_EACH_VEC_SAFE_ELT (node->dies, i, die)
33483 600 : resolve_variable_value (die);
33484 : }
33485 :
33486 : /* Helper function for note_variable_value, handle one location
33487 : expression. */
33488 :
33489 : static void
33490 116019 : note_variable_value_in_expr (dw_die_ref die, dw_loc_descr_ref loc)
33491 : {
33492 347768 : for (; loc; loc = loc->dw_loc_next)
33493 231749 : if (loc->dw_loc_opc == DW_OP_GNU_variable_value
33494 5206 : && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
33495 : {
33496 809 : tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
33497 809 : dw_die_ref ref = lookup_decl_die (decl);
33498 809 : if (! ref && (flag_generate_lto || flag_generate_offload))
33499 : {
33500 : /* ??? This is somewhat a hack because we do not create DIEs
33501 : for variables not in BLOCK trees early but when generating
33502 : early LTO output we need the dw_val_class_decl_ref to be
33503 : fully resolved. For fat LTO objects we'd also like to
33504 : undo this after LTO dwarf output. */
33505 67 : gcc_assert (DECL_CONTEXT (decl));
33506 67 : dw_die_ref ctx = lookup_decl_die (DECL_CONTEXT (decl));
33507 67 : gcc_assert (ctx != NULL);
33508 67 : gen_decl_die (decl, NULL_TREE, NULL, ctx);
33509 67 : ref = lookup_decl_die (decl);
33510 67 : gcc_assert (ref != NULL);
33511 : }
33512 809 : if (ref)
33513 : {
33514 67 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33515 67 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33516 67 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33517 67 : continue;
33518 : }
33519 742 : if (VAR_P (decl)
33520 742 : && DECL_CONTEXT (decl)
33521 742 : && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
33522 1484 : && lookup_decl_die (DECL_CONTEXT (decl)))
33523 : {
33524 742 : if (!variable_value_hash)
33525 431 : variable_value_hash
33526 431 : = hash_table<variable_value_hasher>::create_ggc (10);
33527 :
33528 742 : tree fndecl = DECL_CONTEXT (decl);
33529 742 : struct variable_value_struct *node;
33530 742 : struct variable_value_struct **slot
33531 2226 : = variable_value_hash->find_slot_with_hash (fndecl,
33532 742 : DECL_UID (fndecl),
33533 : INSERT);
33534 742 : if (*slot == NULL)
33535 : {
33536 586 : node = ggc_cleared_alloc<variable_value_struct> ();
33537 586 : node->decl_id = DECL_UID (fndecl);
33538 586 : *slot = node;
33539 : }
33540 : else
33541 : node = *slot;
33542 :
33543 742 : vec_safe_push (node->dies, die);
33544 : }
33545 : }
33546 116019 : }
33547 :
33548 : /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
33549 : with dw_val_class_decl_ref operand. */
33550 :
33551 : static void
33552 52539398 : note_variable_value (dw_die_ref die)
33553 : {
33554 52539398 : dw_die_ref c;
33555 52539398 : dw_attr_node *a;
33556 52539398 : dw_loc_list_ref loc;
33557 52539398 : unsigned ix;
33558 :
33559 242035213 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
33560 189495815 : switch (AT_class (a))
33561 : {
33562 0 : case dw_val_class_loc_list:
33563 0 : loc = AT_loc_list (a);
33564 0 : gcc_assert (loc);
33565 0 : if (!loc->noted_variable_value)
33566 : {
33567 0 : loc->noted_variable_value = 1;
33568 0 : for (; loc; loc = loc->dw_loc_next)
33569 0 : note_variable_value_in_expr (die, loc->expr);
33570 : }
33571 : break;
33572 116019 : case dw_val_class_loc:
33573 116019 : note_variable_value_in_expr (die, AT_loc (a));
33574 116019 : break;
33575 : default:
33576 : break;
33577 : }
33578 :
33579 : /* Mark children. */
33580 105026290 : FOR_EACH_CHILD (die, c, note_variable_value (c));
33581 52539398 : }
33582 :
33583 : /* Process DWARF dies for CTF generation. */
33584 :
33585 : static void
33586 269 : ctf_debug_do_cu (dw_die_ref die)
33587 : {
33588 269 : dw_die_ref c;
33589 :
33590 269 : if (!ctf_do_die (die))
33591 : return;
33592 :
33593 1554 : FOR_EACH_CHILD (die, c, ctf_do_die (c));
33594 : }
33595 :
33596 : /* Perform any cleanups needed after the early debug generation pass
33597 : has run. */
33598 :
33599 : static void
33600 53202 : dwarf2out_early_finish (const char *filename)
33601 : {
33602 53202 : comdat_type_node *ctnode;
33603 53202 : set_early_dwarf s;
33604 53202 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
33605 :
33606 : /* PCH might result in DW_AT_producer string being restored from the
33607 : header compilation, so always fill it with empty string initially
33608 : and overwrite only here. */
33609 53202 : dw_attr_node *producer = get_AT (comp_unit_die (), DW_AT_producer);
33610 :
33611 53202 : if (dwarf_record_gcc_switches)
33612 52671 : producer_string = gen_producer_string (lang_hooks.name,
33613 : save_decoded_options,
33614 : save_decoded_options_count);
33615 : else
33616 531 : producer_string = concat (lang_hooks.name, " ", version_string, NULL);
33617 :
33618 53202 : producer->dw_attr_val.v.val_str->refcount--;
33619 53202 : producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
33620 :
33621 : /* Add the name for the main input file now. We delayed this from
33622 : dwarf2out_init to avoid complications with PCH. */
33623 53202 : add_filename_attribute (comp_unit_die (), remap_debug_filename (filename));
33624 53202 : add_comp_dir_attribute (comp_unit_die ());
33625 :
33626 : /* With LTO early dwarf was really finished at compile-time, so make
33627 : sure to adjust the phase after annotating the LTRANS CU DIE. */
33628 53202 : if (in_lto_p)
33629 : {
33630 777 : early_dwarf_finished = true;
33631 777 : if (dump_file)
33632 : {
33633 0 : fprintf (dump_file, "LTO EARLY DWARF for %s\n", filename);
33634 0 : print_die (comp_unit_die (), dump_file);
33635 : }
33636 777 : return;
33637 : }
33638 :
33639 : /* Walk through the list of incomplete types again, trying once more to
33640 : emit full debugging info for them. */
33641 52425 : retry_incomplete_types ();
33642 :
33643 52425 : gen_scheduled_generic_parms_dies ();
33644 52425 : gen_remaining_tmpl_value_param_die_attribute ();
33645 :
33646 : /* The point here is to flush out the limbo list so that it is empty
33647 : and we don't need to stream it for LTO. */
33648 52425 : flush_limbo_die_list ();
33649 :
33650 : /* Add DW_AT_linkage_name for all deferred DIEs. */
33651 121292478 : for (limbo_die_node *node = deferred_asm_name; node; node = node->next)
33652 : {
33653 121240053 : tree decl = node->created_for;
33654 121240053 : if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
33655 : /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
33656 : ended up in deferred_asm_name before we knew it was
33657 : constant and never written to disk. */
33658 121240053 : && DECL_ASSEMBLER_NAME (decl))
33659 : {
33660 119640204 : add_linkage_attr (node->die, decl);
33661 119640204 : move_linkage_attr (node->die);
33662 : }
33663 : }
33664 52425 : deferred_asm_name = NULL;
33665 :
33666 52425 : if (flag_eliminate_unused_debug_types)
33667 52422 : prune_unused_types ();
33668 :
33669 : /* Generate separate COMDAT sections for type DIEs. */
33670 52425 : if (use_debug_types)
33671 : {
33672 36 : break_out_comdat_types (comp_unit_die ());
33673 :
33674 : /* Each new type_unit DIE was added to the limbo die list when created.
33675 : Since these have all been added to comdat_type_list, clear the
33676 : limbo die list. */
33677 36 : limbo_die_list = NULL;
33678 :
33679 : /* For each new comdat type unit, copy declarations for incomplete
33680 : types to make the new unit self-contained (i.e., no direct
33681 : references to the main compile unit). */
33682 117 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33683 81 : copy_decls_for_unworthy_types (ctnode->root_die);
33684 36 : copy_decls_for_unworthy_types (comp_unit_die ());
33685 :
33686 : /* In the process of copying declarations from one unit to another,
33687 : we may have left some declarations behind that are no longer
33688 : referenced. Prune them. */
33689 36 : prune_unused_types ();
33690 : }
33691 :
33692 : /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
33693 : with dw_val_class_decl_ref operand. */
33694 52425 : note_variable_value (comp_unit_die ());
33695 52425 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
33696 0 : note_variable_value (node->die);
33697 52506 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33698 81 : note_variable_value (ctnode->root_die);
33699 52425 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33700 0 : note_variable_value (node->die);
33701 :
33702 : /* The AT_pubnames attribute needs to go in all skeleton dies, including
33703 : both the main_cu and all skeleton TUs. Making this call unconditional
33704 : would end up either adding a second copy of the AT_pubnames attribute, or
33705 : requiring a special case in add_top_level_skeleton_die_attrs. */
33706 52425 : if (!dwarf_split_debug_info)
33707 52176 : add_AT_pubnames (comp_unit_die ());
33708 :
33709 : /* The early debug phase is now finished. */
33710 52425 : early_dwarf_finished = true;
33711 52425 : if (dump_file)
33712 : {
33713 4 : fprintf (dump_file, "EARLY DWARF for %s\n", filename);
33714 4 : print_die (comp_unit_die (), dump_file);
33715 : }
33716 :
33717 : /* Generate CTF/BTF debug info. */
33718 52425 : if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
33719 52425 : || btf_debuginfo_p ()) && lang_GNU_C ())
33720 : {
33721 269 : ctf_debug_init ();
33722 269 : ctf_debug_do_cu (comp_unit_die ());
33723 269 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33724 0 : ctf_debug_do_cu (node->die);
33725 :
33726 269 : ctf_debug_early_finish (filename);
33727 : }
33728 :
33729 : #ifdef CODEVIEW_DEBUGGING_INFO
33730 : if (codeview_debuginfo_p ())
33731 : codeview_debug_early_finish (comp_unit_die ());
33732 : #endif
33733 :
33734 : /* Do not generate DWARF assembler now when not producing LTO bytecode. */
33735 52425 : if ((!flag_generate_lto && !flag_generate_offload)
33736 : /* FIXME: Disable debug info generation for (PE-)COFF targets since the
33737 : copy_lto_debug_sections operation of the simple object support in
33738 : libiberty is not implemented for them yet. */
33739 : || TARGET_PECOFF || TARGET_COFF)
33740 : return;
33741 :
33742 : /* Now as we are going to output for LTO initialize sections and labels
33743 : to the LTO variants. We don't need a random-seed postfix as other
33744 : LTO sections as linking the LTO debug sections into one in a partial
33745 : link is fine. */
33746 1327 : init_sections_and_labels (true);
33747 :
33748 : /* The output below is modeled after dwarf2out_finish with all
33749 : location related output removed and some LTO specific changes.
33750 : Some refactoring might make both smaller and easier to match up. */
33751 :
33752 1327 : base_types.truncate (0);
33753 1333 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33754 6 : mark_base_types (ctnode->root_die);
33755 1327 : mark_base_types (comp_unit_die ());
33756 1327 : move_marked_base_types ();
33757 :
33758 : /* Traverse the DIE's and add sibling attributes to those DIE's
33759 : that have children. */
33760 1327 : add_sibling_attributes (comp_unit_die ());
33761 1327 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33762 0 : add_sibling_attributes (node->die);
33763 1333 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33764 6 : add_sibling_attributes (ctnode->root_die);
33765 :
33766 : /* AIX Assembler inserts the length, so adjust the reference to match the
33767 : offset expected by debuggers. */
33768 1327 : strcpy (dl_section_ref, debug_line_section_label);
33769 1327 : if (XCOFF_DEBUGGING_INFO)
33770 : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
33771 :
33772 1327 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33773 1327 : add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list, dl_section_ref);
33774 :
33775 1327 : if (have_macinfo)
33776 30 : add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
33777 : macinfo_section_label);
33778 :
33779 1327 : save_macinfo_strings ();
33780 :
33781 1327 : if (dwarf_split_debug_info)
33782 : {
33783 0 : unsigned int index = 0;
33784 0 : debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
33785 : }
33786 :
33787 : /* Output all of the compilation units. We put the main one last so that
33788 : the offsets are available to output_pubnames. */
33789 1327 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33790 0 : output_comp_unit (node->die, 0, NULL);
33791 :
33792 1327 : hash_table<comdat_type_hasher> comdat_type_table (100);
33793 1333 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33794 : {
33795 6 : comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
33796 :
33797 : /* Don't output duplicate types. */
33798 6 : if (*slot != HTAB_EMPTY_ENTRY)
33799 1 : continue;
33800 :
33801 : /* Add a pointer to the line table for the main compilation unit
33802 : so that the debugger can make sense of DW_AT_decl_file
33803 : attributes. */
33804 5 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33805 5 : add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
33806 5 : (!dwarf_split_debug_info
33807 : ? debug_line_section_label
33808 : : debug_skeleton_line_section_label));
33809 :
33810 5 : output_comdat_type_unit (ctnode, true);
33811 5 : *slot = ctnode;
33812 : }
33813 :
33814 : /* Stick a unique symbol to the main debuginfo section. */
33815 1327 : compute_comp_unit_symbol (comp_unit_die ());
33816 :
33817 : /* Output the main compilation unit. We always need it if only for
33818 : the CU symbol. */
33819 1327 : output_comp_unit (comp_unit_die (), true, NULL);
33820 :
33821 : /* Output the abbreviation table. */
33822 1327 : if (vec_safe_length (abbrev_die_table) != 1)
33823 : {
33824 1327 : switch_to_section (debug_abbrev_section);
33825 1327 : ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
33826 1327 : output_abbrev_section ();
33827 : }
33828 :
33829 : /* Have to end the macro section. */
33830 1327 : if (have_macinfo)
33831 : {
33832 : /* We have to save macinfo state if we need to output it again
33833 : for the FAT part of the object. */
33834 15 : vec<macinfo_entry, va_gc> *saved_macinfo_table = macinfo_table;
33835 15 : if (flag_fat_lto_objects)
33836 3 : macinfo_table = macinfo_table->copy ();
33837 :
33838 15 : switch_to_section (debug_macinfo_section);
33839 15 : ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
33840 15 : output_macinfo (debug_line_section_label, true);
33841 15 : dw2_asm_output_data (1, 0, "End compilation unit");
33842 :
33843 15 : if (flag_fat_lto_objects)
33844 : {
33845 3 : vec_free (macinfo_table);
33846 3 : macinfo_table = saved_macinfo_table;
33847 : }
33848 : }
33849 :
33850 : /* Emit a skeleton debug_line section. */
33851 1327 : switch_to_section (debug_line_section);
33852 1327 : ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
33853 1327 : output_line_info (true);
33854 :
33855 : /* If we emitted any indirect strings, output the string table too. */
33856 1327 : if (debug_str_hash || skeleton_debug_str_hash)
33857 1327 : output_indirect_strings ();
33858 1327 : if (debug_line_str_hash)
33859 : {
33860 1280 : switch_to_section (debug_line_str_section);
33861 1280 : const enum dwarf_form form = DW_FORM_line_strp;
33862 1280 : debug_line_str_hash->traverse<enum dwarf_form,
33863 1280 : output_indirect_string> (form);
33864 : }
33865 :
33866 : /* Switch back to the text section. */
33867 1327 : switch_to_section (text_section);
33868 53202 : }
33869 :
33870 : /* Reset all state within dwarf2out.cc so that we can rerun the compiler
33871 : within the same process. For use by toplev::finalize. */
33872 :
33873 : void
33874 258766 : dwarf2out_cc_finalize (void)
33875 : {
33876 258766 : last_var_location_insn = NULL;
33877 258766 : cached_next_real_insn = NULL;
33878 258766 : used_rtx_array = NULL;
33879 258766 : incomplete_types = NULL;
33880 258766 : debug_info_section = NULL;
33881 258766 : debug_skeleton_info_section = NULL;
33882 258766 : debug_abbrev_section = NULL;
33883 258766 : debug_skeleton_abbrev_section = NULL;
33884 258766 : debug_aranges_section = NULL;
33885 258766 : debug_addr_section = NULL;
33886 258766 : debug_macinfo_section = NULL;
33887 258766 : debug_line_section = NULL;
33888 258766 : debug_skeleton_line_section = NULL;
33889 258766 : debug_loc_section = NULL;
33890 258766 : debug_pubnames_section = NULL;
33891 258766 : debug_pubtypes_section = NULL;
33892 258766 : debug_str_section = NULL;
33893 258766 : debug_line_str_section = NULL;
33894 258766 : debug_str_dwo_section = NULL;
33895 258766 : debug_str_offsets_section = NULL;
33896 258766 : debug_ranges_section = NULL;
33897 258766 : debug_ranges_dwo_section = NULL;
33898 258766 : debug_frame_section = NULL;
33899 258766 : fde_vec = NULL;
33900 258766 : debug_str_hash = NULL;
33901 258766 : debug_line_str_hash = NULL;
33902 258766 : skeleton_debug_str_hash = NULL;
33903 258766 : dw2_string_counter = 0;
33904 258766 : have_multiple_function_sections = false;
33905 258766 : in_text_section_p = false;
33906 258766 : cold_text_section = NULL;
33907 258766 : last_text_label = NULL;
33908 258766 : last_cold_label = NULL;
33909 258766 : switch_text_ranges = NULL;
33910 258766 : switch_cold_ranges = NULL;
33911 258766 : current_unit_personality = NULL;
33912 258766 : btf_tag_htab = NULL;
33913 :
33914 258766 : early_dwarf = false;
33915 258766 : early_dwarf_finished = false;
33916 :
33917 258766 : next_die_offset = 0;
33918 258766 : single_comp_unit_die = NULL;
33919 258766 : comdat_type_list = NULL;
33920 258766 : limbo_die_list = NULL;
33921 258766 : file_table = NULL;
33922 258766 : decl_die_table = NULL;
33923 258766 : common_block_die_table = NULL;
33924 258766 : decl_loc_table = NULL;
33925 258766 : call_arg_locations = NULL;
33926 258766 : call_arg_loc_last = NULL;
33927 258766 : call_site_count = -1;
33928 258766 : tail_call_site_count = -1;
33929 258766 : cached_dw_loc_list_table = NULL;
33930 258766 : abbrev_die_table = NULL;
33931 312127 : delete dwarf_proc_stack_usage_map;
33932 258766 : dwarf_proc_stack_usage_map = NULL;
33933 258766 : line_info_label_num = 0;
33934 258766 : cur_line_info_table = NULL;
33935 258766 : text_section_line_info = NULL;
33936 258766 : cold_text_section_line_info = NULL;
33937 258766 : separate_line_info = NULL;
33938 258766 : info_section_emitted = false;
33939 258766 : pubname_table = NULL;
33940 258766 : pubtype_table = NULL;
33941 258766 : macinfo_table = NULL;
33942 258766 : ranges_table = NULL;
33943 258766 : ranges_by_label = NULL;
33944 258766 : rnglist_idx = 0;
33945 258766 : have_location_lists = false;
33946 258766 : loclabel_num = 0;
33947 258766 : poc_label_num = 0;
33948 258766 : last_emitted_file = NULL;
33949 258766 : label_num = 0;
33950 258766 : tmpl_value_parm_die_table = NULL;
33951 258766 : generic_type_instances = NULL;
33952 258766 : frame_pointer_fb_offset = 0;
33953 258766 : frame_pointer_fb_offset_valid = false;
33954 258766 : base_types.release ();
33955 258766 : XDELETEVEC (producer_string);
33956 258766 : producer_string = NULL;
33957 258766 : output_line_info_generation = 0;
33958 258766 : init_sections_and_labels_generation = 0;
33959 258766 : }
33960 :
33961 : #include "gt-dwarf2out.h"
|