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 150830847 : should_emit_struct_debug (tree type, enum debug_info_usage usage)
408 : {
409 150830847 : if (debug_info_level <= DINFO_LEVEL_TERSE)
410 : return false;
411 :
412 150830844 : enum debug_struct_file criterion;
413 150830844 : tree type_decl;
414 150830844 : bool generic = lang_hooks.types.generic_p (type);
415 :
416 150830844 : if (generic)
417 124003841 : criterion = debug_struct_generic[usage];
418 : else
419 26827003 : criterion = debug_struct_ordinary[usage];
420 :
421 150830844 : if (criterion == DINFO_STRUCT_FILE_NONE)
422 : return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
423 150830633 : 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 40662669 : dw_cfi_oprnd1_desc (dwarf_call_frame_info cfi)
520 : {
521 40662669 : 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 13245813 : case DW_CFA_offset:
536 13245813 : case DW_CFA_offset_extended:
537 13245813 : case DW_CFA_def_cfa:
538 13245813 : case DW_CFA_offset_extended_sf:
539 13245813 : case DW_CFA_def_cfa_sf:
540 13245813 : case DW_CFA_restore:
541 13245813 : case DW_CFA_restore_extended:
542 13245813 : case DW_CFA_undefined:
543 13245813 : case DW_CFA_same_value:
544 13245813 : case DW_CFA_def_cfa_register:
545 13245813 : case DW_CFA_register:
546 13245813 : case DW_CFA_expression:
547 13245813 : case DW_CFA_val_expression:
548 13245813 : return dw_cfi_oprnd_reg_num;
549 :
550 25139285 : case DW_CFA_def_cfa_offset:
551 25139285 : case DW_CFA_GNU_args_size:
552 25139285 : case DW_CFA_def_cfa_offset_sf:
553 25139285 : return dw_cfi_oprnd_offset;
554 :
555 13813 : case DW_CFA_def_cfa_expression:
556 13813 : 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 40662669 : dw_cfi_oprnd2_desc (dwarf_call_frame_info cfi)
573 : {
574 40662669 : 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 205116 : case DW_CFA_expression:
587 205116 : case DW_CFA_val_expression:
588 205116 : return dw_cfi_oprnd_loc;
589 :
590 13813 : case DW_CFA_def_cfa_expression:
591 13813 : return dw_cfi_oprnd_cfa_loc;
592 :
593 33750794 : default:
594 33750794 : 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 260914 : output_call_frame_info (int for_eh)
758 : {
759 260914 : unsigned int i;
760 260914 : dw_fde_ref fde;
761 260914 : dw_cfi_ref cfi;
762 260914 : char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
763 260914 : char section_start_label[MAX_ARTIFICIAL_LABEL_BYTES];
764 260914 : bool any_lsda_needed = false;
765 260914 : char augmentation[6];
766 260914 : int augmentation_size;
767 260914 : int fde_encoding = DW_EH_PE_absptr;
768 260914 : int per_encoding = DW_EH_PE_absptr;
769 260914 : int lsda_encoding = DW_EH_PE_absptr;
770 260914 : int return_reg;
771 260914 : rtx personality = NULL;
772 260914 : int dw_cie_version;
773 :
774 : /* Don't emit a CIE if there won't be any FDEs. */
775 260914 : if (!fde_vec)
776 260895 : return;
777 :
778 : /* Nothing to do if the assembler's doing it all. */
779 256405 : 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 1540968 : dwarf2out_do_cfi_startproc (bool second)
981 : {
982 1540968 : int enc;
983 1540968 : rtx ref;
984 :
985 1540968 : fprintf (asm_out_file, "\t.cfi_startproc\n");
986 :
987 1540968 : 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 1540968 : if (targetm_common.except_unwind_info (&global_options) != UI_DWARF2)
992 : return;
993 :
994 1540968 : rtx personality = get_personality_function (current_function_decl);
995 :
996 1540968 : if (personality)
997 : {
998 76034 : enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
999 76034 : 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 76034 : if (enc & DW_EH_PE_indirect)
1006 : {
1007 6259 : if (targetm.asm_out.make_eh_symbol_indirect != NULL)
1008 0 : ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
1009 : else
1010 6259 : ref = dw2_force_const_mem (ref, true);
1011 : }
1012 :
1013 76034 : fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
1014 76034 : output_addr_const (asm_out_file, ref);
1015 76034 : fputc ('\n', asm_out_file);
1016 : }
1017 :
1018 1540968 : if (crtl->uses_eh_lsda)
1019 : {
1020 75967 : char lab[MAX_ARTIFICIAL_LABEL_BYTES];
1021 :
1022 75967 : enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1023 138185 : ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
1024 : current_function_funcdef_no);
1025 81742 : ref = gen_rtx_SYMBOL_REF (Pmode, lab);
1026 75967 : SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
1027 :
1028 75967 : 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 75967 : fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
1037 75967 : output_addr_const (asm_out_file, ref);
1038 75967 : 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 1476657 : dwarf2out_alloc_current_fde (void)
1047 : {
1048 1476657 : dw_fde_ref fde;
1049 :
1050 1476657 : fde = ggc_cleared_alloc<dw_fde_node> ();
1051 1476657 : fde->decl = current_function_decl;
1052 1476657 : fde->funcdef_number = current_function_funcdef_no;
1053 1476657 : fde->fde_index = vec_safe_length (fde_vec);
1054 1476657 : fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1055 1476657 : fde->uses_eh_lsda = crtl->uses_eh_lsda;
1056 1476657 : fde->nothrow = crtl->nothrow;
1057 1476657 : fde->drap_reg = INVALID_REGNUM;
1058 1476657 : fde->vdrap_reg = INVALID_REGNUM;
1059 :
1060 : /* Record the FDE associated with this function. */
1061 1476657 : cfun->fde = fde;
1062 1476657 : vec_safe_push (fde_vec, fde);
1063 :
1064 1476657 : 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 1476712 : dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1072 : unsigned int column ATTRIBUTE_UNUSED,
1073 : const char *file ATTRIBUTE_UNUSED)
1074 : {
1075 1476712 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1076 1476712 : char * dup_label;
1077 1476712 : dw_fde_ref fde;
1078 1476712 : section *fnsec;
1079 1476712 : bool do_frame;
1080 :
1081 1476712 : current_function_func_begin_label = NULL;
1082 :
1083 1476712 : 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 1476712 : if (!do_frame
1088 1476712 : && (!flag_exceptions
1089 0 : || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
1090 55 : return;
1091 :
1092 1476657 : fnsec = function_section (current_function_decl);
1093 1476657 : switch_to_section (fnsec);
1094 1476657 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1095 : current_function_funcdef_no);
1096 1476657 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1097 : current_function_funcdef_no);
1098 1476657 : dup_label = xstrdup (label);
1099 1476657 : current_function_func_begin_label = dup_label;
1100 :
1101 : /* We can elide FDE allocation if we're not emitting frame unwind info. */
1102 1476657 : 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 1476657 : 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 1476657 : fde = cfun->fde;
1114 1476657 : if (fde == NULL)
1115 5347 : fde = dwarf2out_alloc_current_fde ();
1116 :
1117 : /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1118 1476657 : fde->dw_fde_begin = dup_label;
1119 1476657 : fde->dw_fde_current_label = dup_label;
1120 2953314 : fde->in_std_section = (fnsec == text_section
1121 1476657 : || (cold_text_section && fnsec == cold_text_section));
1122 1476657 : fde->ignored_debug = DECL_IGNORED_P (current_function_decl);
1123 1476657 : 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 1476657 : if (file)
1129 464436 : dwarf2out_source_line (line, column, file, 0, true);
1130 : #endif
1131 :
1132 1476657 : if (dwarf2out_do_cfi_asm ())
1133 1476634 : 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 1540997 : mark_ignored_debug_section (dw_fde_ref fde, bool second)
1195 : {
1196 1540997 : bool std_section;
1197 1540997 : const char *begin_label, *end_label;
1198 1540997 : const char **last_end_label;
1199 1540997 : vec<const char *, va_gc> **switch_ranges;
1200 :
1201 1540997 : if (second)
1202 : {
1203 64340 : std_section = fde->second_in_std_section;
1204 64340 : begin_label = fde->dw_fde_second_begin;
1205 64340 : end_label = fde->dw_fde_second_end;
1206 : }
1207 : else
1208 : {
1209 1476657 : std_section = fde->in_std_section;
1210 1476657 : begin_label = fde->dw_fde_begin;
1211 1476657 : end_label = fde->dw_fde_end;
1212 : }
1213 :
1214 1540997 : if (!std_section)
1215 372084 : return;
1216 :
1217 1168913 : if (in_text_section_p)
1218 : {
1219 : last_end_label = &last_text_label;
1220 : switch_ranges = &switch_text_ranges;
1221 : }
1222 : else
1223 : {
1224 11635 : last_end_label = &last_cold_label;
1225 11635 : switch_ranges = &switch_cold_ranges;
1226 : }
1227 :
1228 1168913 : if (fde->ignored_debug)
1229 : {
1230 14751 : if (*switch_ranges && !(vec_safe_length (*switch_ranges) & 1))
1231 6434 : vec_safe_push (*switch_ranges, *last_end_label);
1232 : }
1233 : else
1234 : {
1235 1154162 : *last_end_label = end_label;
1236 :
1237 1154162 : if (!*switch_ranges)
1238 183525 : vec_alloc (*switch_ranges, 16);
1239 970637 : else if (vec_safe_length (*switch_ranges) & 1)
1240 4064 : 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 1476657 : dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1250 : const char *file ATTRIBUTE_UNUSED)
1251 : {
1252 1476657 : dw_fde_ref fde;
1253 1476657 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1254 :
1255 1476657 : last_var_location_insn = NULL;
1256 1476657 : cached_next_real_insn = NULL;
1257 :
1258 1476657 : if (dwarf2out_do_cfi_asm ())
1259 1476634 : 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 1476657 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1269 : current_function_funcdef_no);
1270 1476657 : ASM_OUTPUT_LABEL (asm_out_file, label);
1271 1476657 : fde = cfun->fde;
1272 1476657 : gcc_assert (fde != NULL);
1273 1476657 : if (fde->dw_fde_second_begin == NULL)
1274 1412317 : fde->dw_fde_end = xstrdup (label);
1275 :
1276 1476657 : mark_ignored_debug_section (fde, fde->dw_fde_second_begin != NULL);
1277 1476657 : }
1278 :
1279 : void
1280 230133 : dwarf2out_frame_finish (void)
1281 : {
1282 : /* Output call frame information. */
1283 230133 : if (targetm.debug_unwind_info () == UI_DWARF2)
1284 52035 : output_call_frame_info (0);
1285 :
1286 : /* Output another copy for the unwinder. */
1287 230133 : if (do_eh_frame)
1288 208879 : output_call_frame_info (1);
1289 230133 : }
1290 :
1291 : static void var_location_switch_text_section (void);
1292 : static void set_cur_line_info_table (section *);
1293 :
1294 : void
1295 64340 : dwarf2out_switch_text_section (void)
1296 : {
1297 64340 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1298 64340 : section *sect;
1299 64340 : dw_fde_ref fde = cfun->fde;
1300 :
1301 64340 : gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1302 :
1303 64340 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_SECOND_SECT_LABEL,
1304 : current_function_funcdef_no);
1305 :
1306 64340 : fde->dw_fde_second_begin = ggc_strdup (label);
1307 64340 : 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 64340 : fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1315 64340 : fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1316 : }
1317 64340 : 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 64340 : if (dwarf2out_do_cfi_asm ())
1325 64334 : fprintf (asm_out_file, "\t.cfi_endproc\n");
1326 :
1327 64340 : mark_ignored_debug_section (fde, false);
1328 :
1329 : /* Now do the real section switch. */
1330 64340 : sect = current_function_section ();
1331 64340 : switch_to_section (sect);
1332 :
1333 64340 : fde->second_in_std_section
1334 128680 : = (sect == text_section
1335 64340 : || (cold_text_section && sect == cold_text_section));
1336 64340 : in_text_section_p = sect == text_section;
1337 :
1338 64340 : if (dwarf2out_do_cfi_asm ())
1339 64334 : dwarf2out_do_cfi_startproc (true);
1340 :
1341 64340 : var_location_switch_text_section ();
1342 :
1343 64340 : if (cold_text_section != NULL)
1344 21575 : set_cur_line_info_table (sect);
1345 64340 : }
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 61831495 : dwarf_stack_op_name (unsigned int op)
1377 : {
1378 0 : const char *name = get_DW_OP_name (op);
1379 :
1380 61831495 : if (name != NULL)
1381 61831495 : 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 57460687 : dwarf2out_locviews_in_attribute ()
1392 : {
1393 57460687 : 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 24255847 : dwarf2out_locviews_in_loclist ()
1401 : {
1402 : #ifndef DW_LLE_view_pair
1403 : return false;
1404 : #else
1405 24255847 : 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 64900096 : new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1415 : unsigned HOST_WIDE_INT oprnd2)
1416 : {
1417 64900096 : dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
1418 :
1419 64900096 : descr->dw_loc_opc = op;
1420 64900096 : descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1421 64900096 : descr->dw_loc_oprnd1.val_entry = NULL;
1422 64900096 : descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1423 64900096 : descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1424 64900096 : descr->dw_loc_oprnd2.val_entry = NULL;
1425 64900096 : descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1426 :
1427 64900096 : return descr;
1428 : }
1429 :
1430 : /* Add a location description term to a location description expression. */
1431 :
1432 : static inline void
1433 21672141 : add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1434 : {
1435 21672141 : dw_loc_descr_ref *d;
1436 :
1437 : /* Find the end of the chain. */
1438 126646023 : for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1439 : ;
1440 :
1441 21886973 : *d = descr;
1442 16018296 : }
1443 :
1444 : /* Compare two location operands for exact equality. */
1445 :
1446 : static bool
1447 19975284 : dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1448 : {
1449 19975284 : if (a->val_class != b->val_class)
1450 : return false;
1451 19975284 : 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 13598072 : case dw_val_class_offset:
1459 13598072 : case dw_val_class_unsigned_const:
1460 13598072 : case dw_val_class_const:
1461 13598072 : case dw_val_class_unsigned_const_implicit:
1462 13598072 : case dw_val_class_const_implicit:
1463 13598072 : case dw_val_class_range_list:
1464 : /* These are all HOST_WIDE_INT, signed or unsigned. */
1465 13598072 : 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 6377212 : case dw_val_class_file:
1490 6377212 : case dw_val_class_file_implicit:
1491 6377212 : 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 848160 : loc_descr_plus_const (dw_loc_descr_ref *list_head, poly_int64 poly_offset)
1570 : {
1571 848160 : dw_loc_descr_ref loc;
1572 848160 : HOST_WIDE_INT *p;
1573 :
1574 848160 : gcc_assert (*list_head != NULL);
1575 :
1576 848160 : if (known_eq (poly_offset, 0))
1577 848160 : return;
1578 :
1579 : /* Find the end of the chain. */
1580 2805097 : for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1581 : ;
1582 :
1583 841093 : HOST_WIDE_INT offset;
1584 841093 : 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 841093 : p = NULL;
1592 841093 : if (loc->dw_loc_opc == DW_OP_fbreg
1593 841093 : || (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 841093 : 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 841093 : else if (offset > 0)
1606 718096 : loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1607 :
1608 : else
1609 : {
1610 122997 : loc->dw_loc_next
1611 122997 : = uint_loc_descriptor (-(unsigned HOST_WIDE_INT) offset);
1612 245994 : 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 5045274 : new_reg_loc_descr (unsigned int reg, poly_int64 offset)
1621 : {
1622 5045274 : HOST_WIDE_INT const_offset;
1623 5045274 : if (offset.is_constant (&const_offset))
1624 : {
1625 5045274 : if (reg <= 31)
1626 5045274 : return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1627 5045274 : 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 75816 : loc_list_plus_const (dw_loc_list_ref list_head, poly_int64 offset)
1643 : {
1644 75816 : dw_loc_list_ref d;
1645 151632 : for (d = list_head; d != NULL; d = d->dw_loc_next)
1646 75816 : 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 3671509 : dwarf_OP (enum dwarf_location_atom op)
1662 : {
1663 1724215 : switch (op)
1664 : {
1665 1932443 : case DW_OP_implicit_pointer:
1666 0 : if (dwarf_version < 5)
1667 466 : return DW_OP_GNU_implicit_pointer;
1668 : break;
1669 :
1670 1353484 : case DW_OP_entry_value:
1671 1353484 : if (dwarf_version < 5)
1672 806 : return DW_OP_GNU_entry_value;
1673 : break;
1674 :
1675 46449 : case DW_OP_const_type:
1676 46449 : if (dwarf_version < 5)
1677 9 : return DW_OP_GNU_const_type;
1678 : break;
1679 :
1680 108726 : case DW_OP_regval_type:
1681 108726 : if (dwarf_version < 5)
1682 111 : return DW_OP_GNU_regval_type;
1683 : break;
1684 :
1685 55982 : case DW_OP_deref_type:
1686 55982 : if (dwarf_version < 5)
1687 0 : return DW_OP_GNU_deref_type;
1688 : break;
1689 :
1690 172831 : case DW_OP_convert:
1691 157983 : if (dwarf_version < 5)
1692 0 : return DW_OP_GNU_convert;
1693 : break;
1694 :
1695 1591 : case DW_OP_reinterpret:
1696 1591 : 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 9246727 : dwarf_AT (enum dwarf_attribute at)
1719 : {
1720 9246727 : switch (at)
1721 : {
1722 2858538 : case DW_AT_call_return_pc:
1723 2858538 : if (dwarf_version < 5)
1724 1855 : return DW_AT_low_pc;
1725 : break;
1726 :
1727 56349 : case DW_AT_call_tail_call:
1728 56349 : if (dwarf_version < 5)
1729 90 : return DW_AT_GNU_tail_call;
1730 : break;
1731 :
1732 2786880 : case DW_AT_call_origin:
1733 2786880 : if (dwarf_version < 5)
1734 1833 : return DW_AT_abstract_origin;
1735 : break;
1736 :
1737 5082 : case DW_AT_call_target:
1738 5082 : 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 32290 : case DW_AT_call_parameter:
1748 32290 : if (dwarf_version < 5)
1749 6 : return DW_AT_abstract_origin;
1750 : break;
1751 :
1752 2943620 : case DW_AT_call_value:
1753 2943620 : if (dwarf_version < 5)
1754 1491 : return DW_AT_GNU_call_site_value;
1755 : break;
1756 :
1757 6186 : case DW_AT_call_data_value:
1758 6186 : if (dwarf_version < 5)
1759 0 : return DW_AT_GNU_call_site_data_value;
1760 : break;
1761 :
1762 258265 : case DW_AT_call_all_calls:
1763 258265 : if (dwarf_version < 5)
1764 2305 : return DW_AT_GNU_all_call_sites;
1765 : break;
1766 :
1767 299024 : case DW_AT_call_all_tail_calls:
1768 299024 : if (dwarf_version < 5)
1769 1003 : 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 5802158 : dwarf_TAG (enum dwarf_tag tag)
1791 : {
1792 5802158 : switch (tag)
1793 : {
1794 2858538 : case DW_TAG_call_site:
1795 2858538 : if (dwarf_version < 5)
1796 1855 : return DW_TAG_GNU_call_site;
1797 : break;
1798 :
1799 2943620 : case DW_TAG_call_site_parameter:
1800 2943620 : 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 25829184 : dwarf_FORM (enum dwarf_form form)
1813 : {
1814 25829184 : 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 25828678 : case DW_FORM_strx:
1822 25828678 : if (dwarf_version < 5)
1823 273606 : 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 187127407 : size_of_loc_descr (dw_loc_descr_ref loc)
1838 : {
1839 187127407 : unsigned long size = 1;
1840 :
1841 187127407 : switch (loc->dw_loc_opc)
1842 : {
1843 3441075 : case DW_OP_addr:
1844 3441075 : size += DWARF2_ADDR_SIZE;
1845 3441075 : 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 3650441 : size += 1;
1856 : break;
1857 : case DW_OP_const2u:
1858 : case DW_OP_const2s:
1859 1178881 : size += 2;
1860 : break;
1861 : case DW_OP_const4u:
1862 : case DW_OP_const4s:
1863 645851 : size += 4;
1864 : break;
1865 8651 : case DW_OP_const8u:
1866 8651 : case DW_OP_const8s:
1867 8651 : size += 8;
1868 8651 : break;
1869 450514 : case DW_OP_constu:
1870 450514 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1871 450514 : break;
1872 243169 : case DW_OP_consts:
1873 243169 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1874 243169 : break;
1875 : case DW_OP_pick:
1876 3650441 : size += 1;
1877 : break;
1878 4895670 : case DW_OP_plus_uconst:
1879 4895670 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1880 4895670 : break;
1881 : case DW_OP_skip:
1882 : case DW_OP_bra:
1883 1178881 : size += 2;
1884 : break;
1885 14615816 : case DW_OP_breg0:
1886 14615816 : case DW_OP_breg1:
1887 14615816 : case DW_OP_breg2:
1888 14615816 : case DW_OP_breg3:
1889 14615816 : case DW_OP_breg4:
1890 14615816 : case DW_OP_breg5:
1891 14615816 : case DW_OP_breg6:
1892 14615816 : case DW_OP_breg7:
1893 14615816 : case DW_OP_breg8:
1894 14615816 : case DW_OP_breg9:
1895 14615816 : case DW_OP_breg10:
1896 14615816 : case DW_OP_breg11:
1897 14615816 : case DW_OP_breg12:
1898 14615816 : case DW_OP_breg13:
1899 14615816 : case DW_OP_breg14:
1900 14615816 : case DW_OP_breg15:
1901 14615816 : case DW_OP_breg16:
1902 14615816 : case DW_OP_breg17:
1903 14615816 : case DW_OP_breg18:
1904 14615816 : case DW_OP_breg19:
1905 14615816 : case DW_OP_breg20:
1906 14615816 : case DW_OP_breg21:
1907 14615816 : case DW_OP_breg22:
1908 14615816 : case DW_OP_breg23:
1909 14615816 : case DW_OP_breg24:
1910 14615816 : case DW_OP_breg25:
1911 14615816 : case DW_OP_breg26:
1912 14615816 : case DW_OP_breg27:
1913 14615816 : case DW_OP_breg28:
1914 14615816 : case DW_OP_breg29:
1915 14615816 : case DW_OP_breg30:
1916 14615816 : case DW_OP_breg31:
1917 14615816 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1918 14615816 : break;
1919 52327 : case DW_OP_regx:
1920 52327 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1921 52327 : break;
1922 22441721 : case DW_OP_fbreg:
1923 22441721 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1924 22441721 : 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 15147441 : case DW_OP_piece:
1930 15147441 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1931 15147441 : break;
1932 525978 : case DW_OP_bit_piece:
1933 525978 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1934 525978 : size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1935 525978 : break;
1936 : case DW_OP_deref_size:
1937 : case DW_OP_xderef_size:
1938 3650441 : size += 1;
1939 : break;
1940 : case DW_OP_call2:
1941 1178881 : size += 2;
1942 : break;
1943 : case DW_OP_call4:
1944 645851 : 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 310743 : case DW_OP_implicit_value:
1951 310743 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1952 310743 : + loc->dw_loc_oprnd1.v.val_unsigned;
1953 310743 : break;
1954 3591578 : case DW_OP_implicit_pointer:
1955 3591578 : case DW_OP_GNU_implicit_pointer:
1956 3591578 : size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1957 3591578 : break;
1958 3850511 : case DW_OP_entry_value:
1959 3850511 : case DW_OP_GNU_entry_value:
1960 3850511 : {
1961 3850511 : unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1962 3850511 : size += size_of_uleb128 (op_size) + op_size;
1963 3850511 : break;
1964 : }
1965 113625 : case DW_OP_const_type:
1966 113625 : case DW_OP_GNU_const_type:
1967 113625 : {
1968 113625 : unsigned long o
1969 113625 : = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1970 113625 : size += size_of_uleb128 (o) + 1;
1971 113625 : switch (loc->dw_loc_oprnd2.val_class)
1972 : {
1973 85725 : case dw_val_class_vec:
1974 85725 : size += loc->dw_loc_oprnd2.v.val_vec.length
1975 85725 : * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1976 85725 : 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 367383 : case DW_OP_regval_type:
1993 367383 : case DW_OP_GNU_regval_type:
1994 367383 : {
1995 367383 : unsigned long o
1996 367383 : = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1997 367383 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1998 367383 : + size_of_uleb128 (o);
1999 : }
2000 367383 : break;
2001 155371 : case DW_OP_deref_type:
2002 155371 : case DW_OP_GNU_deref_type:
2003 155371 : {
2004 155371 : unsigned long o
2005 155371 : = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
2006 155371 : size += 1 + size_of_uleb128 (o);
2007 : }
2008 155371 : break;
2009 510896 : case DW_OP_convert:
2010 510896 : case DW_OP_reinterpret:
2011 510896 : case DW_OP_GNU_convert:
2012 510896 : case DW_OP_GNU_reinterpret:
2013 510896 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2014 82491 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2015 : else
2016 : {
2017 428405 : unsigned long o
2018 428405 : = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
2019 428405 : size += size_of_uleb128 (o);
2020 : }
2021 : break;
2022 : case DW_OP_GNU_parameter_ref:
2023 645851 : size += 4;
2024 : break;
2025 : default:
2026 : break;
2027 : }
2028 :
2029 187127407 : return size;
2030 : }
2031 :
2032 : /* Return the size of a series of location descriptors. */
2033 :
2034 : unsigned long
2035 92954347 : size_of_locs (dw_loc_descr_ref loc)
2036 : {
2037 92954347 : dw_loc_descr_ref l;
2038 92954347 : 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 267971769 : for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2043 : {
2044 175444884 : if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
2045 : break;
2046 175017422 : size += size_of_loc_descr (l);
2047 : }
2048 92954347 : if (! l)
2049 : return size;
2050 :
2051 11465224 : for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2052 : {
2053 11037762 : l->dw_loc_addr = size;
2054 11037762 : 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 61831467 : output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
2106 : {
2107 61831467 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
2108 61831467 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
2109 :
2110 61831467 : switch (loc->dw_loc_opc)
2111 : {
2112 : #ifdef DWARF2_DEBUGGING_INFO
2113 149702 : case DW_OP_const2u:
2114 149702 : case DW_OP_const2s:
2115 149702 : dw2_asm_output_data (2, val1->v.val_int, NULL);
2116 149702 : break;
2117 175518 : case DW_OP_const4u:
2118 175518 : 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 175399 : case DW_OP_const4s:
2128 175399 : dw2_asm_output_data (4, val1->v.val_int, NULL);
2129 175399 : break;
2130 2571 : case DW_OP_const8u:
2131 2571 : 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 2023 : case DW_OP_const8s:
2141 2023 : gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2142 2023 : dw2_asm_output_data (8, val1->v.val_int, NULL);
2143 2023 : break;
2144 195668 : case DW_OP_skip:
2145 195668 : case DW_OP_bra:
2146 195668 : {
2147 195668 : int offset;
2148 :
2149 195668 : gcc_assert (val1->val_class == dw_val_class_loc);
2150 195668 : offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2151 :
2152 195668 : dw2_asm_output_data (2, offset, NULL);
2153 : }
2154 195668 : break;
2155 104859 : case DW_OP_implicit_value:
2156 104859 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2157 104859 : switch (val2->val_class)
2158 : {
2159 43663 : case dw_val_class_const:
2160 43663 : dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
2161 43663 : break;
2162 60714 : case dw_val_class_vec:
2163 60714 : {
2164 60714 : unsigned int elt_size = val2->v.val_vec.elt_size;
2165 60714 : unsigned int len = val2->v.val_vec.length;
2166 60714 : unsigned int i;
2167 60714 : unsigned char *p;
2168 :
2169 60714 : if (elt_size > sizeof (HOST_WIDE_INT))
2170 : {
2171 0 : elt_size /= 2;
2172 0 : len *= 2;
2173 : }
2174 60714 : for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
2175 286953 : i < len;
2176 226239 : i++, p += elt_size)
2177 452478 : 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 1019073 : case DW_OP_const1u:
2240 1019073 : case DW_OP_const1s:
2241 1019073 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2242 1019073 : break;
2243 156785 : case DW_OP_constu:
2244 156785 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2245 156785 : break;
2246 44196 : case DW_OP_consts:
2247 44196 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2248 44196 : break;
2249 177 : case DW_OP_pick:
2250 177 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2251 177 : break;
2252 980784 : case DW_OP_plus_uconst:
2253 980784 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2254 980784 : break;
2255 4904394 : case DW_OP_breg0:
2256 4904394 : case DW_OP_breg1:
2257 4904394 : case DW_OP_breg2:
2258 4904394 : case DW_OP_breg3:
2259 4904394 : case DW_OP_breg4:
2260 4904394 : case DW_OP_breg5:
2261 4904394 : case DW_OP_breg6:
2262 4904394 : case DW_OP_breg7:
2263 4904394 : case DW_OP_breg8:
2264 4904394 : case DW_OP_breg9:
2265 4904394 : case DW_OP_breg10:
2266 4904394 : case DW_OP_breg11:
2267 4904394 : case DW_OP_breg12:
2268 4904394 : case DW_OP_breg13:
2269 4904394 : case DW_OP_breg14:
2270 4904394 : case DW_OP_breg15:
2271 4904394 : case DW_OP_breg16:
2272 4904394 : case DW_OP_breg17:
2273 4904394 : case DW_OP_breg18:
2274 4904394 : case DW_OP_breg19:
2275 4904394 : case DW_OP_breg20:
2276 4904394 : case DW_OP_breg21:
2277 4904394 : case DW_OP_breg22:
2278 4904394 : case DW_OP_breg23:
2279 4904394 : case DW_OP_breg24:
2280 4904394 : case DW_OP_breg25:
2281 4904394 : case DW_OP_breg26:
2282 4904394 : case DW_OP_breg27:
2283 4904394 : case DW_OP_breg28:
2284 4904394 : case DW_OP_breg29:
2285 4904394 : case DW_OP_breg30:
2286 4904394 : case DW_OP_breg31:
2287 4904394 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2288 4904394 : break;
2289 17438 : case DW_OP_regx:
2290 17438 : {
2291 17438 : unsigned r = val1->v.val_unsigned;
2292 17438 : if (for_eh_or_skip >= 0)
2293 17438 : r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2294 17438 : gcc_assert (size_of_uleb128 (r)
2295 : == size_of_uleb128 (val1->v.val_unsigned));
2296 17438 : dw2_asm_output_data_uleb128 (r, NULL);
2297 : }
2298 17438 : break;
2299 7830255 : case DW_OP_fbreg:
2300 7830255 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2301 7830255 : 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 5045385 : case DW_OP_piece:
2314 5045385 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2315 5045385 : break;
2316 175326 : case DW_OP_bit_piece:
2317 175326 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2318 175326 : dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2319 175326 : break;
2320 165764 : case DW_OP_deref_size:
2321 165764 : case DW_OP_xderef_size:
2322 165764 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2323 165764 : break;
2324 :
2325 1431706 : case DW_OP_addr:
2326 1431706 : 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 1512505 : 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 1196659 : case DW_OP_implicit_pointer:
2385 1196659 : case DW_OP_GNU_implicit_pointer:
2386 1196659 : {
2387 1196659 : char label[MAX_ARTIFICIAL_LABEL_BYTES
2388 : + HOST_BITS_PER_WIDE_INT / 2 + 2];
2389 1196659 : gcc_assert (val1->val_class == dw_val_class_die_ref);
2390 1196659 : get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2391 1196659 : dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2392 1196659 : dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2393 : }
2394 1196659 : break;
2395 :
2396 1352889 : case DW_OP_entry_value:
2397 1352889 : case DW_OP_GNU_entry_value:
2398 1352889 : dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2399 1352889 : output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2400 1352889 : break;
2401 :
2402 40699 : case DW_OP_const_type:
2403 40699 : case DW_OP_GNU_const_type:
2404 40699 : {
2405 40699 : unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2406 40699 : gcc_assert (o);
2407 40699 : dw2_asm_output_data_uleb128 (o, NULL);
2408 40699 : 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 31451 : case dw_val_class_vec:
2416 31451 : {
2417 31451 : unsigned int elt_size = val2->v.val_vec.elt_size;
2418 31451 : unsigned int len = val2->v.val_vec.length;
2419 31451 : unsigned int i;
2420 31451 : unsigned char *p;
2421 :
2422 31451 : l = len * elt_size;
2423 31451 : dw2_asm_output_data (1, l, NULL);
2424 31451 : if (elt_size > sizeof (HOST_WIDE_INT))
2425 : {
2426 0 : elt_size /= 2;
2427 0 : len *= 2;
2428 : }
2429 31451 : for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
2430 98640 : i < len;
2431 67189 : i++, p += elt_size)
2432 134378 : 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 106795 : case DW_OP_regval_type:
2477 106795 : case DW_OP_GNU_regval_type:
2478 106795 : {
2479 106795 : unsigned r = val1->v.val_unsigned;
2480 106795 : unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2481 106795 : gcc_assert (o);
2482 106795 : 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 106795 : dw2_asm_output_data_uleb128 (r, NULL);
2489 106795 : dw2_asm_output_data_uleb128 (o, NULL);
2490 : }
2491 106795 : break;
2492 54368 : case DW_OP_deref_type:
2493 54368 : case DW_OP_GNU_deref_type:
2494 54368 : {
2495 54368 : unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2496 54368 : gcc_assert (o);
2497 54368 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2498 54368 : dw2_asm_output_data_uleb128 (o, NULL);
2499 : }
2500 54368 : break;
2501 167652 : case DW_OP_convert:
2502 167652 : case DW_OP_reinterpret:
2503 167652 : case DW_OP_GNU_convert:
2504 167652 : case DW_OP_GNU_reinterpret:
2505 167652 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2506 26723 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2507 : else
2508 : {
2509 140929 : unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2510 140929 : gcc_assert (o);
2511 140929 : dw2_asm_output_data_uleb128 (o, NULL);
2512 : }
2513 : break;
2514 :
2515 30788 : case DW_OP_GNU_parameter_ref:
2516 30788 : {
2517 30788 : unsigned long o;
2518 30788 : gcc_assert (val1->val_class == dw_val_class_die_ref);
2519 30788 : o = get_ref_die_offset (val1->v.val_die_ref.die);
2520 30788 : dw2_asm_output_data (4, o, NULL);
2521 : }
2522 30788 : break;
2523 :
2524 : default:
2525 : /* Other codes have no operands. */
2526 : break;
2527 : }
2528 61831467 : }
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 33155363 : output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2539 : {
2540 94986830 : for (; loc != NULL; loc = loc->dw_loc_next)
2541 : {
2542 61831467 : enum dwarf_location_atom opc = loc->dw_loc_opc;
2543 : /* Output the opcode. */
2544 61831467 : 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 61831467 : 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 123662934 : dw2_asm_output_data (1, opc,
2562 : "%s", dwarf_stack_op_name (opc));
2563 :
2564 : /* Output the operand(s) (if any). */
2565 61831467 : output_loc_operands (loc, for_eh_or_skip);
2566 : }
2567 33155363 : }
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 64209 : output_loc_operands_raw (dw_loc_descr_ref loc)
2574 : {
2575 64209 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
2576 64209 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
2577 :
2578 64209 : 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 55260 : case DW_OP_consts:
2654 55260 : case DW_OP_breg0:
2655 55260 : case DW_OP_breg1:
2656 55260 : case DW_OP_breg2:
2657 55260 : case DW_OP_breg3:
2658 55260 : case DW_OP_breg4:
2659 55260 : case DW_OP_breg5:
2660 55260 : case DW_OP_breg6:
2661 55260 : case DW_OP_breg7:
2662 55260 : case DW_OP_breg8:
2663 55260 : case DW_OP_breg9:
2664 55260 : case DW_OP_breg10:
2665 55260 : case DW_OP_breg11:
2666 55260 : case DW_OP_breg12:
2667 55260 : case DW_OP_breg13:
2668 55260 : case DW_OP_breg14:
2669 55260 : case DW_OP_breg15:
2670 55260 : case DW_OP_breg16:
2671 55260 : case DW_OP_breg17:
2672 55260 : case DW_OP_breg18:
2673 55260 : case DW_OP_breg19:
2674 55260 : case DW_OP_breg20:
2675 55260 : case DW_OP_breg21:
2676 55260 : case DW_OP_breg22:
2677 55260 : case DW_OP_breg23:
2678 55260 : case DW_OP_breg24:
2679 55260 : case DW_OP_breg25:
2680 55260 : case DW_OP_breg26:
2681 55260 : case DW_OP_breg27:
2682 55260 : case DW_OP_breg28:
2683 55260 : case DW_OP_breg29:
2684 55260 : case DW_OP_breg30:
2685 55260 : case DW_OP_breg31:
2686 55260 : case DW_OP_fbreg:
2687 55260 : fputc (',', asm_out_file);
2688 55260 : dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2689 55260 : 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 64209 : }
2726 :
2727 : void
2728 55260 : output_loc_sequence_raw (dw_loc_descr_ref loc)
2729 : {
2730 73158 : while (1)
2731 : {
2732 64209 : enum dwarf_location_atom opc = loc->dw_loc_opc;
2733 : /* Output the opcode. */
2734 64209 : 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 64209 : 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 64209 : fprintf (asm_out_file, "%#x", opc);
2750 64209 : output_loc_operands_raw (loc);
2751 :
2752 64209 : if (!loc->dw_loc_next)
2753 : break;
2754 8949 : loc = loc->dw_loc_next;
2755 :
2756 8949 : fputc (',', asm_out_file);
2757 8949 : }
2758 55260 : }
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 16167 : build_cfa_loc (dw_cfa_location *cfa, poly_int64 offset)
2803 : {
2804 16167 : struct dw_loc_descr_node *head, *tmp;
2805 :
2806 16167 : offset += cfa->offset;
2807 :
2808 16167 : 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 16167 : else if (cfa->indirect)
2816 : {
2817 7067 : head = new_reg_loc_descr (cfa->reg.reg, cfa->base_offset);
2818 7067 : head->dw_loc_oprnd1.val_class = dw_val_class_const;
2819 7067 : head->dw_loc_oprnd1.val_entry = NULL;
2820 7067 : tmp = new_loc_descr (DW_OP_deref, 0, 0);
2821 7067 : add_loc_descr (&head, tmp);
2822 7067 : loc_descr_plus_const (&head, offset);
2823 : }
2824 : else
2825 9100 : head = new_reg_loc_descr (cfa->reg.reg, offset);
2826 :
2827 16167 : 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 17955 : build_cfa_aligned_loc (dw_cfa_location *cfa,
2836 : poly_int64 offset, HOST_WIDE_INT alignment)
2837 : {
2838 17955 : struct dw_loc_descr_node *head;
2839 17955 : unsigned int dwarf_fp
2840 17955 : = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2841 :
2842 : /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2843 17955 : 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 17955 : head = new_reg_loc_descr (dwarf_fp, offset);
2852 17955 : 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 42089724 : maybe_reset_location_view (rtx_insn *insn, dw_line_info_table *table)
3116 : {
3117 42089724 : 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 107951343 : set_early_dwarf () : saved(early_dwarf)
3184 : {
3185 107951343 : gcc_assert (! early_dwarf_finished);
3186 107951343 : early_dwarf = true;
3187 107951343 : }
3188 107951343 : ~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 285637 : dwarf2out_default_as_loc_support (void)
3348 : {
3349 285637 : 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 285643 : dwarf2out_default_as_locview_support (void)
3361 : {
3362 285643 : 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 43924956 : output_asm_line_debug_info (void)
3420 : {
3421 43924956 : return (dwarf2out_as_loc_support
3422 43924956 : && (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 1596336 : dw_addr_op (enum dtprel_bool dtprel)
4040 : {
4041 1596336 : 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 1591046 : 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 1596336 : new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
4053 : {
4054 1596336 : dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
4055 :
4056 1596336 : ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
4057 1596336 : ref->dw_loc_oprnd1.v.val_addr = addr;
4058 1596336 : ref->dw_loc_dtprel = dtprel;
4059 1596336 : 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 1596333 : ref->dw_loc_oprnd1.val_entry = NULL;
4065 :
4066 1596336 : 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 601403415 : comp_unit_die (void)
4299 : {
4300 601403415 : if (!single_comp_unit_die)
4301 56856 : single_comp_unit_die = gen_compile_unit_die (NULL);
4302 601403415 : 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 1336816 : is_pseudo_reg (const_rtx rtl)
4320 : {
4321 918711 : return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4322 1481432 : || (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 851511136 : type_main_variant (tree type)
4331 : {
4332 851511136 : 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 851511136 : if (TREE_CODE (type) == ARRAY_TYPE)
4340 0 : while (type != TYPE_MAIN_VARIANT (type))
4341 0 : type = TYPE_MAIN_VARIANT (type);
4342 :
4343 851511136 : return type;
4344 : }
4345 :
4346 : /* Return true if the given type node represents a tagged type. */
4347 :
4348 : static inline bool
4349 985949306 : is_tagged_type (const_tree type)
4350 : {
4351 985949306 : enum tree_code code = TREE_CODE (type);
4352 :
4353 985949306 : return (code == RECORD_TYPE || code == UNION_TYPE
4354 985949306 : || 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 1196784 : get_ref_die_offset_label (char *label, dw_die_ref ref)
4361 : {
4362 1196784 : 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 1407575 : get_base_type_offset (dw_die_ref ref)
4369 : {
4370 1407575 : if (ref->die_offset)
4371 1074764 : return ref->die_offset;
4372 332811 : if (comp_unit_die ()->die_abbrev)
4373 : {
4374 9 : calc_base_type_die_sizes ();
4375 9 : gcc_assert (ref->die_offset);
4376 : }
4377 332811 : 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 30791 : get_ref_die_offset (dw_die_ref ref)
4384 : {
4385 30791 : gcc_assert (ref->die_offset);
4386 30791 : return ref->die_offset;
4387 : }
4388 :
4389 : /* Convert a DIE tag into its string name. */
4390 :
4391 : static const char *
4392 82156742 : dwarf_tag_name (unsigned int tag)
4393 : {
4394 0 : const char *name = get_DW_TAG_name (tag);
4395 :
4396 82156742 : if (name != NULL)
4397 82156742 : 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 367534359 : dwarf_attr_name (unsigned int attr)
4406 : {
4407 367534359 : const char *name;
4408 :
4409 367534359 : 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 367534359 : name = get_DW_AT_name (attr);
4429 :
4430 367534359 : if (name != NULL)
4431 367534359 : 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 16014824 : dwarf_form_name (unsigned int form)
4440 : {
4441 0 : const char *name = get_DW_FORM_name (form);
4442 :
4443 16014824 : if (name != NULL)
4444 16014824 : 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 407456346 : decl_ultimate_origin (const_tree decl)
4457 : {
4458 407456346 : 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 407456346 : 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 449308375 : gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4469 :
4470 407452928 : 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 160219011 : decl_class_context (tree decl)
4479 : {
4480 160219011 : tree context = NULL_TREE;
4481 :
4482 160219011 : if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4483 158990004 : context = DECL_CONTEXT (decl);
4484 : else
4485 1229007 : context = TYPE_MAIN_VARIANT
4486 : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4487 :
4488 160219011 : if (context && !TYPE_P (context))
4489 41865288 : context = NULL_TREE;
4490 :
4491 160219011 : return context;
4492 : }
4493 :
4494 : /* Add an attribute/value pair to a DIE. */
4495 :
4496 : static inline void
4497 2678852063 : add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
4498 : {
4499 : /* Maybe this should be an assert? */
4500 2678852063 : if (die == NULL)
4501 : return;
4502 :
4503 2678668666 : 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 10093875704 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4510 7415207285 : gcc_assert (a->dw_attr != attr->dw_attr);
4511 : }
4512 :
4513 2678668666 : vec_safe_reserve (die->die_attr, 1);
4514 2678668666 : vec_safe_push (die->die_attr, *attr);
4515 : }
4516 :
4517 : enum dw_val_class
4518 6494718783 : AT_class (dw_attr_node *a)
4519 : {
4520 6494718783 : 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 49851177 : AT_index (dw_attr_node *a)
4530 : {
4531 49851177 : if (AT_class (a) == dw_val_class_str)
4532 1870 : return a->dw_attr_val.v.val_str->index;
4533 49849307 : 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 433374104 : add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4542 : {
4543 433374104 : dw_attr_node attr;
4544 :
4545 433374104 : attr.dw_attr = attr_kind;
4546 433374104 : attr.dw_attr_val.val_class = dw_val_class_flag;
4547 433374104 : attr.dw_attr_val.val_entry = NULL;
4548 433374104 : attr.dw_attr_val.v.val_flag = flag;
4549 433374104 : add_dwarf_attr (die, &attr);
4550 199746900 : }
4551 :
4552 : static inline unsigned
4553 89313994 : AT_flag (dw_attr_node *a)
4554 : {
4555 89313994 : gcc_assert (a && AT_class (a) == dw_val_class_flag);
4556 89313994 : 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 415982 : add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4563 : {
4564 415982 : dw_attr_node attr;
4565 :
4566 415982 : attr.dw_attr = attr_kind;
4567 415982 : attr.dw_attr_val.val_class = dw_val_class_const;
4568 415982 : attr.dw_attr_val.val_entry = NULL;
4569 415982 : attr.dw_attr_val.v.val_int = int_val;
4570 415982 : add_dwarf_attr (die, &attr);
4571 204138 : }
4572 :
4573 : HOST_WIDE_INT
4574 29108 : AT_int (dw_attr_node *a)
4575 : {
4576 29108 : gcc_assert (a && (AT_class (a) == dw_val_class_const
4577 : || AT_class (a) == dw_val_class_const_implicit));
4578 29108 : 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 820561550 : add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4585 : unsigned HOST_WIDE_INT unsigned_val)
4586 : {
4587 820561550 : dw_attr_node attr;
4588 :
4589 820561550 : attr.dw_attr = attr_kind;
4590 820561550 : attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4591 820561550 : attr.dw_attr_val.val_entry = NULL;
4592 820561550 : attr.dw_attr_val.v.val_unsigned = unsigned_val;
4593 1855204 : add_dwarf_attr (die, &attr);
4594 483610404 : }
4595 :
4596 : unsigned HOST_WIDE_INT
4597 895293601 : AT_unsigned (dw_attr_node *a)
4598 : {
4599 895293601 : gcc_assert (a && (AT_class (a) == dw_val_class_unsigned_const
4600 : || AT_class (a) == dw_val_class_unsigned_const_implicit));
4601 895293601 : 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 2315056 : 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 2315056 : dw_attr_node attr;
4655 :
4656 2315056 : attr.dw_attr = attr_kind;
4657 2315056 : attr.dw_attr_val.val_class = dw_val_class_vec;
4658 2315056 : attr.dw_attr_val.val_entry = NULL;
4659 2315056 : attr.dw_attr_val.v.val_vec.length = length;
4660 2315056 : attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4661 2315056 : attr.dw_attr_val.v.val_vec.array = array;
4662 2315056 : 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 4446394 : add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
4687 : bool force_direct)
4688 : {
4689 4446394 : dw_attr_node attr;
4690 4446394 : char * lbl_id;
4691 :
4692 4446394 : lbl_id = xstrdup (lbl_low);
4693 4446394 : attr.dw_attr = DW_AT_low_pc;
4694 4446394 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4695 4446394 : attr.dw_attr_val.v.val_lbl_id = lbl_id;
4696 4446394 : 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 4446152 : attr.dw_attr_val.val_entry = NULL;
4701 4446394 : add_dwarf_attr (die, &attr);
4702 :
4703 4446394 : attr.dw_attr = DW_AT_high_pc;
4704 4446394 : if (dwarf_version < 4)
4705 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4706 : else
4707 4440813 : attr.dw_attr_val.val_class = dw_val_class_high_pc;
4708 4446394 : lbl_id = xstrdup (lbl_high);
4709 4446394 : attr.dw_attr_val.v.val_lbl_id = lbl_id;
4710 4446394 : if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
4711 5581 : && 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 4446394 : attr.dw_attr_val.val_entry = NULL;
4716 4446394 : add_dwarf_attr (die, &attr);
4717 4446394 : }
4718 :
4719 : /* Hash and equality functions for debug_str_hash. */
4720 :
4721 : hashval_t
4722 3004431649 : indirect_string_hasher::hash (indirect_string_node *x)
4723 : {
4724 3004431649 : return htab_hash_string (x->str);
4725 : }
4726 :
4727 : bool
4728 3413014279 : indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
4729 : {
4730 3413014279 : 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 451652032 : find_AT_string_in_table (const char *str,
4737 : hash_table<indirect_string_hasher> *table,
4738 : enum insert_option insert = INSERT)
4739 : {
4740 451652032 : struct indirect_string_node *node;
4741 :
4742 451652032 : indirect_string_node **slot
4743 451652032 : = table->find_slot_with_hash (str, htab_hash_string (str), insert);
4744 451652032 : if (*slot == NULL)
4745 : {
4746 226590540 : node = ggc_cleared_alloc<indirect_string_node> ();
4747 226590540 : node->str = ggc_strdup (str);
4748 226590540 : *slot = node;
4749 : }
4750 : else
4751 : node = *slot;
4752 :
4753 451652032 : node->refcount++;
4754 451652032 : return node;
4755 : }
4756 :
4757 : /* Add STR to the indirect string hash table. */
4758 :
4759 : static struct indirect_string_node *
4760 451540062 : find_AT_string (const char *str, enum insert_option insert = INSERT)
4761 : {
4762 451540062 : if (! debug_str_hash)
4763 56856 : debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
4764 :
4765 451540062 : 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 451005016 : add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4772 : {
4773 451005016 : dw_attr_node attr;
4774 451005016 : struct indirect_string_node *node;
4775 :
4776 451005016 : node = find_AT_string (str);
4777 :
4778 451005016 : attr.dw_attr = attr_kind;
4779 451005016 : attr.dw_attr_val.val_class = dw_val_class_str;
4780 451005016 : attr.dw_attr_val.val_entry = NULL;
4781 451005016 : attr.dw_attr_val.v.val_str = node;
4782 451005016 : add_dwarf_attr (die, &attr);
4783 451005016 : }
4784 :
4785 : static inline const char *
4786 33080797 : AT_string (dw_attr_node *a)
4787 : {
4788 33080797 : gcc_assert (a && AT_class (a) == dw_val_class_str);
4789 33080797 : 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 19640393 : set_indirect_string (struct indirect_string_node *node)
4797 : {
4798 19640393 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
4799 : /* Already indirect is a no op. */
4800 19640393 : if (node->form == DW_FORM_strp
4801 19639596 : || node->form == DW_FORM_line_strp
4802 39520411 : || node->form == dwarf_FORM (DW_FORM_strx))
4803 : {
4804 3578 : gcc_assert (node->label);
4805 3578 : return;
4806 : }
4807 19636815 : ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4808 19636815 : ++dw2_string_counter;
4809 19636815 : node->label = xstrdup (label);
4810 :
4811 19636815 : if (!dwarf_split_debug_info)
4812 : {
4813 19633707 : node->form = DW_FORM_strp;
4814 19633707 : 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 18706 : reset_indirect_string (indirect_string_node **h, void *)
4829 : {
4830 18706 : struct indirect_string_node *node = *h;
4831 18706 : if (node->form == DW_FORM_strp
4832 6323 : || node->form == DW_FORM_line_strp
4833 21977 : || node->form == dwarf_FORM (DW_FORM_strx))
4834 : {
4835 15465 : free (node->label);
4836 15465 : node->label = NULL;
4837 15465 : node->form = (dwarf_form) 0;
4838 15465 : node->index = 0;
4839 : }
4840 18706 : return 1;
4841 : }
4842 :
4843 : /* Add a string representing a file or filepath attribute value to a DIE. */
4844 :
4845 : static inline void
4846 106262 : add_filepath_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
4847 : const char *str)
4848 : {
4849 106262 : if (! asm_outputs_debug_line_str ())
4850 4496 : add_AT_string (die, attr_kind, str);
4851 : else
4852 : {
4853 101766 : dw_attr_node attr;
4854 101766 : struct indirect_string_node *node;
4855 :
4856 101766 : if (!debug_line_str_hash)
4857 50883 : debug_line_str_hash
4858 50883 : = hash_table<indirect_string_hasher>::create_ggc (10);
4859 :
4860 101766 : node = find_AT_string_in_table (str, debug_line_str_hash);
4861 101766 : set_indirect_string (node);
4862 101766 : node->form = DW_FORM_line_strp;
4863 :
4864 101766 : attr.dw_attr = attr_kind;
4865 101766 : attr.dw_attr_val.val_class = dw_val_class_str;
4866 101766 : attr.dw_attr_val.val_entry = NULL;
4867 101766 : attr.dw_attr_val.v.val_str = node;
4868 101766 : add_dwarf_attr (die, &attr);
4869 : }
4870 106262 : }
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 206259545 : find_string_form (struct indirect_string_node *node)
4877 : {
4878 206259545 : unsigned int len;
4879 :
4880 206259545 : if (node->form)
4881 : return node->form;
4882 :
4883 19983808 : 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 19983808 : if (len <= (unsigned) dwarf_offset_size || node->refcount == 0)
4888 695337 : 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 19288471 : if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4894 19288471 : || ((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 19287737 : set_indirect_string (node);
4899 :
4900 19287737 : 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 185924678 : AT_string_form (dw_attr_node *a)
4908 : {
4909 185924678 : gcc_assert (a && AT_class (a) == dw_val_class_str);
4910 185924678 : 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 644738625 : add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4917 : {
4918 644738625 : dw_attr_node attr;
4919 644738625 : gcc_checking_assert (targ_die != NULL);
4920 644738625 : 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 644738625 : if (targ_die == NULL)
4927 : return;
4928 :
4929 644738625 : attr.dw_attr = attr_kind;
4930 644738625 : attr.dw_attr_val.val_class = dw_val_class_die_ref;
4931 644738625 : attr.dw_attr_val.val_entry = NULL;
4932 644738625 : attr.dw_attr_val.v.val_die_ref.die = targ_die;
4933 644738625 : attr.dw_attr_val.v.val_die_ref.external = 0;
4934 644738625 : 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 30466481 : add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4952 : {
4953 30466481 : add_AT_die_ref (die, DW_AT_specification, targ_die);
4954 30466481 : gcc_assert (!targ_die->die_definition);
4955 30466481 : targ_die->die_definition = die;
4956 30466481 : }
4957 :
4958 : static inline dw_die_ref
4959 638843787 : AT_ref (dw_attr_node *a)
4960 : {
4961 638843787 : gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4962 638843787 : return a->dw_attr_val.v.val_die_ref.die;
4963 : }
4964 :
4965 : static inline int
4966 385502431 : AT_ref_external (dw_attr_node *a)
4967 : {
4968 385502431 : if (a && AT_class (a) == dw_val_class_die_ref)
4969 385502431 : return a->dw_attr_val.v.val_die_ref.external;
4970 :
4971 : return 0;
4972 : }
4973 :
4974 : static inline void
4975 29582 : set_AT_ref_external (dw_attr_node *a, int i)
4976 : {
4977 29582 : gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4978 29582 : a->dw_attr_val.v.val_die_ref.external = i;
4979 29582 : }
4980 :
4981 : /* Add a location description attribute value to a DIE. */
4982 :
4983 : static inline void
4984 8410162 : add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4985 : {
4986 8410162 : dw_attr_node attr;
4987 :
4988 8410162 : attr.dw_attr = attr_kind;
4989 8410162 : attr.dw_attr_val.val_class = dw_val_class_loc;
4990 8410162 : attr.dw_attr_val.val_entry = NULL;
4991 8410162 : attr.dw_attr_val.v.val_loc = loc;
4992 8410162 : add_dwarf_attr (die, &attr);
4993 4410895 : }
4994 :
4995 : dw_loc_descr_ref
4996 30408545 : AT_loc (dw_attr_node *a)
4997 : {
4998 30408545 : gcc_assert (a && AT_class (a) == dw_val_class_loc);
4999 30408545 : return a->dw_attr_val.v.val_loc;
5000 : }
5001 :
5002 : static inline void
5003 11923973 : add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5004 : {
5005 11923973 : dw_attr_node attr;
5006 :
5007 11923973 : if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
5008 : return;
5009 :
5010 11923973 : attr.dw_attr = attr_kind;
5011 11923973 : attr.dw_attr_val.val_class = dw_val_class_loc_list;
5012 11923973 : attr.dw_attr_val.val_entry = NULL;
5013 11923973 : attr.dw_attr_val.v.val_loc_list = loc_list;
5014 11923973 : add_dwarf_attr (die, &attr);
5015 11923973 : have_location_lists = true;
5016 : }
5017 :
5018 : static inline dw_loc_list_ref
5019 34230515 : AT_loc_list (dw_attr_node *a)
5020 : {
5021 34230515 : gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5022 34230515 : 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 11747807 : add_AT_view_list (dw_die_ref die, enum dwarf_attribute attr_kind)
5030 : {
5031 11747807 : dw_attr_node attr;
5032 :
5033 11747807 : if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
5034 : return;
5035 :
5036 11747807 : attr.dw_attr = attr_kind;
5037 11747807 : attr.dw_attr_val.val_class = dw_val_class_view_list;
5038 11747807 : attr.dw_attr_val.val_entry = NULL;
5039 11747807 : attr.dw_attr_val.v.val_view_list = die;
5040 11747807 : add_dwarf_attr (die, &attr);
5041 11747807 : gcc_checking_assert (get_AT (die, DW_AT_location));
5042 11747807 : 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 23157975 : AT_loc_list_ptr (dw_attr_node *a)
5051 : {
5052 34391962 : gcc_assert (a);
5053 34391962 : switch (AT_class (a))
5054 : {
5055 23157975 : case dw_val_class_loc_list:
5056 23157975 : return &a->dw_attr_val.v.val_loc_list;
5057 11233987 : case dw_val_class_view_list:
5058 11233987 : {
5059 11233987 : dw_attr_node *l;
5060 11233987 : l = get_AT (a->dw_attr_val.v.val_view_list, DW_AT_location);
5061 11233987 : if (!l)
5062 : return NULL;
5063 11233987 : 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 11747843 : view_list_to_loc_list_val_node (dw_val_node *val)
5076 : {
5077 11747843 : gcc_assert (val->val_class == dw_val_class_view_list);
5078 11747843 : dw_attr_node *loc = get_AT (val->v.val_view_list, DW_AT_location);
5079 11747843 : if (!loc)
5080 : return NULL;
5081 11234023 : gcc_checking_assert (&(loc + 1)->dw_attr_val == val);
5082 11234023 : gcc_assert (AT_class (loc) == dw_val_class_loc_list);
5083 11234023 : 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 384 : remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
5205 : {
5206 3146 : for (; descr; descr = descr->dw_loc_next)
5207 2762 : 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 384 : }
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 6439 : dw_get_die_tag (dw_die_ref die)
5240 : {
5241 6439 : return die->die_tag;
5242 : }
5243 :
5244 : /* Return a reference to the children list of a given DIE. */
5245 :
5246 : dw_die_ref
5247 1869 : dw_get_die_child (dw_die_ref die)
5248 : {
5249 1869 : 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 1510349 : add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
5267 : bool force_direct)
5268 : {
5269 1510349 : dw_attr_node attr;
5270 :
5271 1510349 : attr.dw_attr = attr_kind;
5272 1510349 : attr.dw_attr_val.val_class = dw_val_class_addr;
5273 1510349 : attr.dw_attr_val.v.val_addr = addr;
5274 1510349 : 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 1510349 : attr.dw_attr_val.val_entry = NULL;
5278 1510349 : add_dwarf_attr (die, &attr);
5279 1510349 : }
5280 :
5281 : /* Get the RTX from to an address DIE attribute. */
5282 :
5283 : static inline rtx
5284 28830 : AT_addr (dw_attr_node *a)
5285 : {
5286 28830 : gcc_assert (a && AT_class (a) == dw_val_class_addr);
5287 28830 : 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 265120641 : add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5294 : struct dwarf_file_data *fd)
5295 : {
5296 265120641 : dw_attr_node attr;
5297 :
5298 265120641 : attr.dw_attr = attr_kind;
5299 265120641 : attr.dw_attr_val.val_class = dw_val_class_file;
5300 265120641 : attr.dw_attr_val.val_entry = NULL;
5301 265120641 : attr.dw_attr_val.v.val_file = fd;
5302 265120641 : add_dwarf_attr (die, &attr);
5303 51873 : }
5304 :
5305 : /* Get the dwarf_file_data from a file DIE attribute. */
5306 :
5307 : static inline struct dwarf_file_data *
5308 31063363 : AT_file (dw_attr_node *a)
5309 : {
5310 31063363 : gcc_assert (a && (AT_class (a) == dw_val_class_file
5311 : || AT_class (a) == dw_val_class_file_implicit));
5312 31063363 : 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 6270655 : add_AT_symview (dw_die_ref die, enum dwarf_attribute attr_kind,
5337 : const char *view_label)
5338 : {
5339 6270655 : dw_attr_node attr;
5340 :
5341 6270655 : attr.dw_attr = attr_kind;
5342 6270655 : attr.dw_attr_val.val_class = dw_val_class_symview;
5343 6270655 : attr.dw_attr_val.val_entry = NULL;
5344 6270655 : attr.dw_attr_val.v.val_symbolic_view = xstrdup (view_label);
5345 6270655 : add_dwarf_attr (die, &attr);
5346 6270655 : }
5347 :
5348 : /* Add a label identifier attribute value to a DIE. */
5349 :
5350 : static inline void
5351 9175477 : add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
5352 : const char *lbl_id, int offset)
5353 : {
5354 9175477 : dw_attr_node attr;
5355 :
5356 9175477 : attr.dw_attr = attr_kind;
5357 9175477 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5358 9175477 : attr.dw_attr_val.val_entry = NULL;
5359 9175477 : if (!offset)
5360 9175477 : 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 9175477 : 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 9175477 : add_dwarf_attr (die, &attr);
5368 9175477 : }
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 53671 : add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5375 : const char *label)
5376 : {
5377 53671 : dw_attr_node attr;
5378 :
5379 53671 : attr.dw_attr = attr_kind;
5380 53671 : attr.dw_attr_val.val_class = dw_val_class_lineptr;
5381 53671 : attr.dw_attr_val.val_entry = NULL;
5382 53671 : attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5383 53671 : add_dwarf_attr (die, &attr);
5384 53671 : }
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 3232085 : add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5412 : long unsigned int offset, bool force_direct)
5413 : {
5414 3232085 : dw_attr_node attr;
5415 :
5416 3232085 : attr.dw_attr = attr_kind;
5417 3232085 : 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 3232085 : if (dwarf_split_debug_info && !force_direct)
5422 3 : attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
5423 : else
5424 3232082 : attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
5425 3232085 : attr.dw_attr_val.v.val_offset = offset;
5426 3232085 : add_dwarf_attr (die, &attr);
5427 3232085 : }
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 22561084 : AT_lbl (dw_attr_node *a)
5449 : {
5450 22561084 : 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 22561084 : 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 1115168222 : get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5462 : {
5463 1264179781 : dw_attr_node *a;
5464 1264179781 : unsigned ix;
5465 1264179781 : dw_die_ref spec = NULL;
5466 :
5467 1264179781 : if (! die)
5468 : return NULL;
5469 :
5470 4889059889 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5471 4546048245 : if (a->dw_attr == attr_kind)
5472 : return a;
5473 3624880108 : else if (a->dw_attr == DW_AT_specification
5474 3501288894 : || a->dw_attr == DW_AT_abstract_origin)
5475 188759056 : spec = AT_ref (a);
5476 :
5477 343011644 : 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 4440516 : get_AT_low_pc (dw_die_ref die)
5506 : {
5507 4440516 : dw_attr_node *a = get_AT (die, DW_AT_low_pc);
5508 :
5509 4440516 : 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 57252 : get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5517 : {
5518 57252 : dw_attr_node *a = get_AT (die, attr_kind);
5519 :
5520 57252 : 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 78840104 : get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5528 : {
5529 78840104 : dw_attr_node *a = get_AT (die, attr_kind);
5530 :
5531 78840104 : 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 458133452 : get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5539 : {
5540 458133452 : dw_attr_node *a = get_AT (die, attr_kind);
5541 :
5542 458133452 : return a ? AT_unsigned (a) : 0;
5543 : }
5544 :
5545 : dw_die_ref
5546 49017242 : get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5547 : {
5548 49017242 : dw_attr_node *a = get_AT (die, attr_kind);
5549 :
5550 49017242 : return a ? AT_ref (a) : NULL;
5551 : }
5552 :
5553 : struct dwarf_file_data *
5554 30930751 : get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5555 : {
5556 30930751 : dw_attr_node *a = get_AT (die, attr_kind);
5557 :
5558 30930751 : 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 25109833 : is_cxx (void)
5578 : {
5579 25109833 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5580 :
5581 25109833 : return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
5582 25109833 : || 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 23657967 : is_cxx (const_tree decl)
5589 : {
5590 23657967 : 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 23657951 : return is_cxx ();
5597 : }
5598 :
5599 : /* Return TRUE if the language is Fortran. */
5600 :
5601 : static inline bool
5602 184488327 : is_fortran (void)
5603 : {
5604 184488327 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5605 :
5606 184488327 : return (lang == DW_LANG_Fortran77
5607 184488327 : || lang == DW_LANG_Fortran90
5608 184488327 : || lang == DW_LANG_Fortran95
5609 : || lang == DW_LANG_Fortran03
5610 184488327 : || lang == DW_LANG_Fortran08);
5611 : }
5612 :
5613 : static inline bool
5614 106 : is_fortran (const_tree decl)
5615 : {
5616 106 : if (in_lto_p)
5617 : {
5618 106 : const_tree context = get_ultimate_context (decl);
5619 212 : if (context && TRANSLATION_UNIT_LANGUAGE (context))
5620 106 : return (strncmp (TRANSLATION_UNIT_LANGUAGE (context),
5621 : "GNU Fortran", 11) == 0
5622 106 : || 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 78734 : is_rust (void)
5633 : {
5634 78734 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5635 :
5636 78734 : return lang == DW_LANG_Rust;
5637 : }
5638 :
5639 : /* Return TRUE if the language is Ada. */
5640 :
5641 : static inline bool
5642 2875599 : is_ada (void)
5643 : {
5644 2875599 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5645 :
5646 2875599 : 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 84913576 : is_dlang (void)
5653 : {
5654 84913576 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5655 :
5656 84913576 : 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 53081007 : remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5664 : {
5665 53081007 : dw_attr_node *a;
5666 53081007 : unsigned ix;
5667 :
5668 53081007 : if (! die)
5669 : return false;
5670 :
5671 112660229 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5672 112160453 : if (a->dw_attr == attr_kind)
5673 : {
5674 52581231 : 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 52581231 : die->die_attr->ordered_remove (ix);
5681 52581231 : 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 7718821 : remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5691 : {
5692 7718821 : gcc_assert (child->die_parent == prev->die_parent);
5693 7718821 : gcc_assert (prev->die_sib == child);
5694 7718821 : if (prev == child)
5695 : {
5696 18249 : gcc_assert (child->die_parent->die_child == child);
5697 : prev = NULL;
5698 : }
5699 : else
5700 7700572 : prev->die_sib = child->die_sib;
5701 7718821 : if (child->die_parent->die_child == child)
5702 364539 : child->die_parent->die_child = prev;
5703 7718821 : child->die_sib = NULL;
5704 7718821 : }
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 42612 : remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5749 : {
5750 42612 : dw_die_ref c;
5751 :
5752 42612 : c = die->die_child;
5753 42612 : if (c) do {
5754 69342 : dw_die_ref prev = c;
5755 69342 : c = c->die_sib;
5756 128672 : while (c->die_tag == tag)
5757 : {
5758 77578 : remove_child_with_prev (c, prev);
5759 77578 : c->die_parent = NULL;
5760 : /* Might have removed every child. */
5761 77578 : if (die->die_child == NULL)
5762 : return;
5763 59330 : c = prev->die_sib;
5764 : }
5765 51094 : } while (c != die->die_child);
5766 : }
5767 :
5768 : /* Add a CHILD_DIE as the last child of DIE. */
5769 :
5770 : static void
5771 650574666 : add_child_die (dw_die_ref die, dw_die_ref child_die)
5772 : {
5773 : /* FIXME this should probably be an assert. */
5774 650574666 : if (! die || ! child_die)
5775 : return;
5776 650290806 : gcc_assert (die != child_die);
5777 :
5778 650290806 : child_die->die_parent = die;
5779 650290806 : if (die->die_child)
5780 : {
5781 490998558 : child_die->die_sib = die->die_child->die_sib;
5782 490998558 : die->die_child->die_sib = child_die;
5783 : }
5784 : else
5785 159292248 : child_die->die_sib = child_die;
5786 650290806 : die->die_child = child_die;
5787 : }
5788 :
5789 : /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5790 :
5791 : static void
5792 12880945 : add_child_die_after (dw_die_ref die, dw_die_ref child_die,
5793 : dw_die_ref after_die)
5794 : {
5795 12880945 : gcc_assert (die
5796 : && child_die
5797 : && after_die
5798 : && die->die_child
5799 : && die != child_die);
5800 :
5801 12880945 : child_die->die_parent = die;
5802 12880945 : child_die->die_sib = after_die->die_sib;
5803 12880945 : after_die->die_sib = child_die;
5804 12880945 : if (die->die_child == after_die)
5805 7751635 : die->die_child = child_die;
5806 12880945 : }
5807 :
5808 : /* Unassociate CHILD from its parent, and make its parent be
5809 : NEW_PARENT. */
5810 :
5811 : static void
5812 7634630 : reparent_child (dw_die_ref child, dw_die_ref new_parent)
5813 : {
5814 7634630 : for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
5815 6574039524 : if (p->die_sib == child)
5816 : {
5817 7634630 : remove_child_with_prev (child, p);
5818 7634630 : break;
5819 : }
5820 7634630 : add_child_die (new_parent, child);
5821 7634630 : }
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 17934 : 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 17934 : if (child->die_parent != parent)
5833 : {
5834 621 : dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5835 :
5836 621 : if (tmp)
5837 17934 : child = tmp;
5838 : }
5839 :
5840 17934 : gcc_assert (child->die_parent == parent
5841 : || (child->die_parent
5842 : == get_AT_ref (parent, DW_AT_specification)));
5843 :
5844 17934 : reparent_child (child, parent);
5845 17934 : }
5846 :
5847 : /* Create and return a new die with TAG_VALUE as tag. */
5848 :
5849 : dw_die_ref
5850 655624980 : new_die_raw (enum dwarf_tag tag_value)
5851 : {
5852 655624980 : dw_die_ref die = ggc_cleared_alloc<die_node> ();
5853 655624980 : die->die_tag = tag_value;
5854 655624980 : 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 642124740 : new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5864 : {
5865 642124740 : dw_die_ref die = new_die_raw (tag_value);
5866 :
5867 642124740 : if (parent_die != NULL)
5868 641767702 : add_child_die (parent_die, die);
5869 : else
5870 : {
5871 357038 : 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 357038 : if (tag_value != DW_TAG_compile_unit
5877 : /* These are allowed because they're generated while
5878 : breaking out COMDAT units late. */
5879 357038 : && tag_value != DW_TAG_type_unit
5880 299852 : && tag_value != DW_TAG_skeleton_unit
5881 299852 : && !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 3025 : && (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 3025 : && (!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 360061 : && !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 357038 : limbo_node = ggc_cleared_alloc<limbo_die_node> ();
5904 357038 : limbo_node->die = die;
5905 357038 : limbo_node->created_for = t;
5906 357038 : limbo_node->next = limbo_die_list;
5907 357038 : limbo_die_list = limbo_node;
5908 : }
5909 :
5910 642124740 : return die;
5911 : }
5912 :
5913 : /* Return the DIE associated with the given type specifier. */
5914 :
5915 : dw_die_ref
5916 1784443515 : lookup_type_die (tree type)
5917 : {
5918 1784443515 : dw_die_ref die = TYPE_SYMTAB_DIE (type);
5919 1784443515 : if (die && die->removed)
5920 : {
5921 1631 : TYPE_SYMTAB_DIE (type) = NULL;
5922 1631 : TREE_ASM_WRITTEN (type) = 0;
5923 1631 : 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 20847117 : strip_naming_typedef (tree type, dw_die_ref type_die)
5934 : {
5935 20847117 : if (type
5936 20847117 : && TREE_CODE (type) == RECORD_TYPE
5937 20699113 : && type_die
5938 20699113 : && type_die->die_tag == DW_TAG_typedef
5939 20847135 : && is_naming_typedef_decl (TYPE_NAME (type)))
5940 18 : type_die = get_AT_ref (type_die, DW_AT_type);
5941 20847117 : 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 111803 : lookup_type_die_strip_naming_typedef (tree type)
5956 : {
5957 111803 : dw_die_ref die = lookup_type_die (type);
5958 111803 : return strip_naming_typedef (type, die);
5959 : }
5960 :
5961 : /* Equate a DIE to a given type specifier. */
5962 :
5963 : static inline void
5964 154856156 : equate_type_number_to_die (tree type, dw_die_ref type_die)
5965 : {
5966 154856156 : TYPE_SYMTAB_DIE (type) = type_die;
5967 154856156 : }
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 11761638006 : decl_die_hasher::hash (die_node *x)
5981 : {
5982 11761638006 : 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 13654189682 : decl_die_hasher::equal (die_node *x, tree y)
5989 : {
5990 13654189682 : return (x->decl_id == DECL_UID (y));
5991 : }
5992 :
5993 : /* Return the DIE associated with a given declaration. */
5994 :
5995 : dw_die_ref
5996 1469082931 : lookup_decl_die (tree decl)
5997 : {
5998 1469082931 : dw_die_ref *die = decl_die_table->find_slot_with_hash (decl, DECL_UID (decl),
5999 : NO_INSERT);
6000 1469082931 : if (!die)
6001 : {
6002 678652023 : if (in_lto_p)
6003 38786 : return maybe_create_die_with_external_ref (decl);
6004 : return NULL;
6005 : }
6006 790430908 : if ((*die)->removed)
6007 : {
6008 131 : decl_die_table->clear_slot (die);
6009 131 : return NULL;
6010 : }
6011 : return *die;
6012 : }
6013 :
6014 :
6015 : /* Return the DIE associated with BLOCK. */
6016 :
6017 : static inline dw_die_ref
6018 18320848 : lookup_block_die (tree block)
6019 : {
6020 18320848 : dw_die_ref die = BLOCK_DIE (block);
6021 18320848 : if (!die && in_lto_p)
6022 9411 : return maybe_create_die_with_external_ref (block);
6023 : return die;
6024 : }
6025 :
6026 : /* Associate DIE with BLOCK. */
6027 :
6028 : static inline void
6029 7238078 : equate_block_to_die (tree block, dw_die_ref die)
6030 : {
6031 7238078 : BLOCK_DIE (block) = die;
6032 7238078 : }
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 139308 : dwarf2out_die_ref_for_decl (tree decl, const char **sym,
6042 : unsigned HOST_WIDE_INT *off)
6043 : {
6044 139308 : dw_die_ref die;
6045 :
6046 139308 : 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 27340 : if (!external_die_map)
6051 : return false;
6052 26081 : sym_off_pair *desc = external_die_map->get (decl);
6053 26081 : if (!desc)
6054 : return false;
6055 11115 : *sym = desc->sym;
6056 11115 : *off = desc->off;
6057 11115 : return true;
6058 : }
6059 :
6060 111968 : if (TREE_CODE (decl) == BLOCK)
6061 27120 : die = lookup_block_die (decl);
6062 : else
6063 84848 : die = lookup_decl_die (decl);
6064 111968 : if (!die)
6065 : return false;
6066 :
6067 : /* Similar to get_ref_die_offset_label, but using the "correct"
6068 : label. */
6069 37898 : *off = die->die_offset;
6070 100009 : 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 37898 : if (die->die_tag == DW_TAG_compile_unit)
6075 : {
6076 37895 : gcc_assert (die->die_id.die_symbol != NULL);
6077 37895 : *sym = die->die_id.die_symbol;
6078 37895 : 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 29234 : 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 29234 : dw_die_ref ref = new_die_raw (die->die_tag);
6098 29234 : ref->die_id.die_symbol = symbol;
6099 29234 : ref->die_offset = offset;
6100 29234 : ref->with_offset = 1;
6101 29234 : add_AT_die_ref (die, attr_kind, ref);
6102 29234 : }
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 44034 : dwarf2out_register_external_die (tree decl, const char *sym,
6109 : unsigned HOST_WIDE_INT off)
6110 : {
6111 44034 : if (debug_info_level == DINFO_LEVEL_NONE)
6112 0 : return;
6113 :
6114 44034 : if (!external_die_map)
6115 1214 : external_die_map = hash_map<tree, sym_off_pair>::create_ggc (1000);
6116 44034 : gcc_checking_assert (!external_die_map->get (decl));
6117 44034 : sym_off_pair p = { IDENTIFIER_POINTER (get_identifier (sym)), off };
6118 44034 : 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 48197 : maybe_create_die_with_external_ref (tree decl)
6126 : {
6127 48197 : if (!external_die_map)
6128 : return NULL;
6129 48039 : sym_off_pair *desc = external_die_map->get (decl);
6130 48039 : if (!desc)
6131 : return NULL;
6132 :
6133 20372 : const char *sym = desc->sym;
6134 20372 : unsigned HOST_WIDE_INT off = desc->off;
6135 20372 : external_die_map->remove (decl);
6136 :
6137 20372 : in_lto_p = false;
6138 20372 : dw_die_ref die = (TREE_CODE (decl) == BLOCK
6139 20372 : ? lookup_block_die (decl) : lookup_decl_die (decl));
6140 20372 : gcc_assert (!die);
6141 20372 : in_lto_p = true;
6142 :
6143 20372 : tree ctx;
6144 20372 : dw_die_ref parent = NULL;
6145 : /* Need to lookup a DIE for the decls context - the containing
6146 : function or translation unit. */
6147 20372 : 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 19944 : ctx = DECL_CONTEXT (decl);
6158 : /* Peel types in the context stack. */
6159 20897 : while (ctx && TYPE_P (ctx))
6160 525 : ctx = TYPE_CONTEXT (ctx);
6161 : /* Likewise namespaces in case we do not want to emit DIEs for them. */
6162 20372 : if (debug_info_level <= DINFO_LEVEL_TERSE)
6163 998 : while (ctx && TREE_CODE (ctx) == NAMESPACE_DECL)
6164 5 : ctx = DECL_CONTEXT (ctx);
6165 20372 : if (ctx)
6166 : {
6167 20234 : if (TREE_CODE (ctx) == BLOCK)
6168 60 : parent = lookup_block_die (ctx);
6169 20174 : else if (TREE_CODE (ctx) == TRANSLATION_UNIT_DECL
6170 : /* Keep the 1:1 association during WPA. */
6171 3715 : && !flag_wpa
6172 3715 : && flag_incremental_link != INCREMENTAL_LINK_LTO)
6173 : /* Otherwise all late annotations go to the main CU which
6174 : imports the original CUs. */
6175 3715 : parent = comp_unit_die ();
6176 16459 : else if (TREE_CODE (ctx) == FUNCTION_DECL
6177 12207 : && 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 13436 : 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 138 : parent = comp_unit_die ();
6191 : /* Create a DIE "stub". */
6192 20372 : switch (TREE_CODE (decl))
6193 : {
6194 138 : case TRANSLATION_UNIT_DECL:
6195 138 : {
6196 138 : 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 138 : return die;
6200 : }
6201 106 : case NAMESPACE_DECL:
6202 106 : if (is_fortran (decl))
6203 6 : die = new_die (DW_TAG_module, parent, decl);
6204 : else
6205 100 : die = new_die (DW_TAG_namespace, parent, decl);
6206 : break;
6207 7190 : case FUNCTION_DECL:
6208 7190 : die = new_die (DW_TAG_subprogram, parent, decl);
6209 7190 : break;
6210 3727 : case VAR_DECL:
6211 3727 : die = new_die (DW_TAG_variable, parent, decl);
6212 3727 : break;
6213 0 : case RESULT_DECL:
6214 0 : die = new_die (DW_TAG_variable, parent, decl);
6215 0 : break;
6216 8775 : case PARM_DECL:
6217 8775 : die = new_die (DW_TAG_formal_parameter, parent, decl);
6218 8775 : 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 20234 : if (TREE_CODE (decl) == BLOCK)
6232 428 : equate_block_to_die (decl, die);
6233 : else
6234 19806 : equate_decl_number_to_die (decl, die);
6235 :
6236 20234 : add_desc_attribute (die, decl);
6237 :
6238 : /* Add a reference to the DIE providing early debug at $sym + off. */
6239 20234 : add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
6240 :
6241 20234 : return die;
6242 : }
6243 :
6244 : /* Returns a hash value for X (which really is a var_loc_list). */
6245 :
6246 : inline hashval_t
6247 379962091 : decl_loc_hasher::hash (var_loc_list *x)
6248 : {
6249 379962091 : 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 459522391 : decl_loc_hasher::equal (var_loc_list *x, const_tree y)
6257 : {
6258 459522391 : 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 31532431 : lookup_decl_loc (const_tree decl)
6265 : {
6266 31532431 : if (!decl_loc_table)
6267 : return NULL;
6268 31532431 : 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 210820411 : equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6292 : {
6293 210820411 : unsigned int decl_id = DECL_UID (decl);
6294 :
6295 210820411 : *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
6296 210820411 : decl_die->decl_id = decl_id;
6297 210820411 : }
6298 :
6299 : /* Return how many bits covers PIECE EXPR_LIST. */
6300 :
6301 : static HOST_WIDE_INT
6302 32372574 : decl_piece_bitsize (rtx piece)
6303 : {
6304 32372574 : int ret = (int) GET_MODE (piece);
6305 32372574 : if (ret)
6306 32146709 : return ret;
6307 225865 : gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
6308 : && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
6309 225865 : 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 16952326 : decl_piece_varloc_ptr (rtx piece)
6316 : {
6317 0 : if ((int) GET_MODE (piece))
6318 16849504 : return &XEXP (piece, 0);
6319 : else
6320 102822 : 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 7764958 : decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
6328 : {
6329 7764958 : if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
6330 7699427 : return alloc_EXPR_LIST (bitsize, loc_note, next);
6331 : else
6332 65531 : return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
6333 : GEN_INT (bitsize),
6334 65531 : 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 47701238 : construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
6342 : HOST_WIDE_INT bitsize)
6343 : {
6344 47701238 : if (bitsize != -1)
6345 : {
6346 582437 : loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
6347 582437 : if (bitpos != 0)
6348 88538 : loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
6349 : }
6350 47701238 : 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 6054241 : 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 6054241 : HOST_WIDE_INT diff;
6369 6054241 : bool copy = inner != NULL;
6370 :
6371 6054241 : if (copy)
6372 : {
6373 : /* First copy all nodes preceding the current bitpos. */
6374 4371401 : while (src != inner)
6375 : {
6376 2653676 : *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
6377 : decl_piece_bitsize (*src), NULL_RTX);
6378 1326838 : dest = &XEXP (*dest, 1);
6379 1326838 : src = &XEXP (*src, 1);
6380 : }
6381 : }
6382 : /* Add padding if needed. */
6383 6054241 : if (bitpos != piece_bitpos)
6384 : {
6385 18372 : *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
6386 : copy ? NULL_RTX : *dest);
6387 18372 : dest = &XEXP (*dest, 1);
6388 : }
6389 6035869 : else if (*dest && decl_piece_bitsize (*dest) == bitsize)
6390 : {
6391 2673410 : gcc_assert (!copy);
6392 : /* A piece with correct bitpos and bitsize already exist,
6393 : just update the location for it and return. */
6394 2673410 : *decl_piece_varloc_ptr (*dest) = loc_note;
6395 2673410 : return;
6396 : }
6397 : /* Add the piece that changed. */
6398 3380831 : *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
6399 3380831 : dest = &XEXP (*dest, 1);
6400 : /* Skip over pieces that overlap it. */
6401 3380831 : diff = bitpos - piece_bitpos + bitsize;
6402 3380831 : if (!copy)
6403 336268 : src = dest;
6404 6408020 : while (diff > 0 && *src)
6405 : {
6406 3027189 : rtx piece = *src;
6407 3027189 : diff -= decl_piece_bitsize (piece);
6408 3027189 : if (copy)
6409 3016184 : src = &XEXP (piece, 1);
6410 : else
6411 : {
6412 11005 : *src = XEXP (piece, 1);
6413 11005 : free_EXPR_LIST_node (piece);
6414 : }
6415 : }
6416 : /* Add padding if needed. */
6417 3380831 : if (diff < 0 && *src)
6418 : {
6419 7920 : if (!copy)
6420 6840 : dest = src;
6421 7920 : *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
6422 7920 : dest = &XEXP (*dest, 1);
6423 : }
6424 3380831 : if (!copy)
6425 : return;
6426 : /* Finally copy all nodes following it. */
6427 5404585 : while (*src)
6428 : {
6429 4720044 : *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
6430 : decl_piece_bitsize (*src), NULL_RTX);
6431 2360022 : dest = &XEXP (*dest, 1);
6432 2360022 : 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 59120076 : add_var_loc_to_decl (tree decl, rtx loc_note, const char *label, var_loc_view view)
6440 : {
6441 59120076 : unsigned int decl_id;
6442 59120076 : var_loc_list *temp;
6443 59120076 : struct var_loc_node *loc = NULL;
6444 59120076 : HOST_WIDE_INT bitsize = -1, bitpos = -1;
6445 :
6446 59120076 : if (VAR_P (decl) && DECL_HAS_DEBUG_EXPR_P (decl))
6447 : {
6448 7550372 : tree realdecl = DECL_DEBUG_EXPR (decl);
6449 7550372 : if (handled_component_p (realdecl)
6450 846535 : || (TREE_CODE (realdecl) == MEM_REF
6451 846535 : && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
6452 : {
6453 7550372 : bool reverse;
6454 7550372 : tree innerdecl = get_ref_base_and_extent_hwi (realdecl, &bitpos,
6455 : &bitsize, &reverse);
6456 7550372 : if (!innerdecl
6457 7550372 : || !DECL_P (innerdecl)
6458 7550372 : || DECL_IGNORED_P (innerdecl)
6459 7550372 : || TREE_STATIC (innerdecl)
6460 7550372 : || bitsize == 0
6461 15100744 : || bitpos + bitsize > 256)
6462 0 : return NULL;
6463 7550372 : decl = innerdecl;
6464 : }
6465 : }
6466 :
6467 59120076 : decl_id = DECL_UID (decl);
6468 59120076 : var_loc_list **slot
6469 59120076 : = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
6470 59120076 : if (*slot == NULL)
6471 : {
6472 13584297 : temp = ggc_cleared_alloc<var_loc_list> ();
6473 13584297 : temp->decl_id = decl_id;
6474 13584297 : *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 59120076 : if (temp->last
6482 45535779 : && temp->first == temp->last
6483 21364713 : && TREE_CODE (decl) == PARM_DECL
6484 1020848 : && NOTE_P (temp->first->loc)
6485 982776 : && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
6486 982776 : && DECL_INCOMING_RTL (decl)
6487 982776 : && NOTE_VAR_LOCATION_LOC (temp->first->loc)
6488 981592 : && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
6489 981592 : == GET_CODE (DECL_INCOMING_RTL (decl))
6490 981546 : && prev_real_insn (as_a<rtx_insn *> (temp->first->loc)) == NULL_RTX
6491 60101614 : && (bitsize != -1
6492 981413 : || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
6493 981413 : NOTE_VAR_LOCATION_LOC (loc_note))
6494 406773 : || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
6495 406773 : != NOTE_VAR_LOCATION_STATUS (loc_note))))
6496 : {
6497 575399 : loc = ggc_cleared_alloc<var_loc_node> ();
6498 575399 : temp->first->next = loc;
6499 575399 : temp->last = loc;
6500 575399 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6501 : }
6502 58544677 : else if (temp->last)
6503 : {
6504 44960380 : struct var_loc_node *last = temp->last, *unused = NULL;
6505 44960380 : rtx *piece_loc = NULL, last_loc_note;
6506 44960380 : HOST_WIDE_INT piece_bitpos = 0;
6507 44960380 : if (last->next)
6508 : {
6509 29492149 : last = last->next;
6510 29492149 : gcc_assert (last->next == NULL);
6511 : }
6512 44960380 : if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
6513 : {
6514 6967935 : piece_loc = &last->loc;
6515 12385025 : do
6516 : {
6517 12385025 : HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
6518 12385025 : if (piece_bitpos + cur_bitsize > bitpos)
6519 : break;
6520 5771158 : piece_bitpos += cur_bitsize;
6521 5771158 : piece_loc = &XEXP (*piece_loc, 1);
6522 : }
6523 5771158 : 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 44960380 : 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 4193526 : if (piece_loc != NULL)
6533 : {
6534 3009678 : adjust_piece_list (piece_loc, NULL, NULL,
6535 : bitpos, piece_bitpos, bitsize, loc_note);
6536 3009678 : return NULL;
6537 : }
6538 : /* If the last note doesn't cover any instructions, remove it. */
6539 1183848 : if (temp->last != last)
6540 : {
6541 1075982 : temp->last->next = NULL;
6542 1075982 : unused = last;
6543 1075982 : last = temp->last;
6544 1075982 : gcc_assert (strcmp (last->label, label) != 0 || last->view != view);
6545 : }
6546 : else
6547 : {
6548 107866 : gcc_assert (temp->first == temp->last
6549 : || (temp->first->next == temp->last
6550 : && TREE_CODE (decl) == PARM_DECL));
6551 107866 : memset (temp->last, '\0', sizeof (*temp->last));
6552 107866 : temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
6553 107866 : return temp->last;
6554 : }
6555 : }
6556 41842836 : if (bitsize == -1 && NOTE_P (last->loc))
6557 : last_loc_note = last->loc;
6558 4200092 : else if (piece_loc != NULL
6559 3958257 : && *piece_loc != NULL_RTX
6560 3929648 : && piece_bitpos == bitpos
6561 8129105 : && decl_piece_bitsize (*piece_loc) == bitsize)
6562 3927748 : 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 41570492 : if (last_loc_note == NULL_RTX
6569 41560410 : || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
6570 41560410 : NOTE_VAR_LOCATION_LOC (loc_note)))
6571 51199877 : || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6572 9629385 : != NOTE_VAR_LOCATION_STATUS (loc_note))
6573 4264845 : && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6574 : == VAR_INIT_STATUS_UNINITIALIZED)
6575 3444412 : || (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 36478239 : if (unused)
6582 : {
6583 718513 : loc = unused;
6584 718513 : memset (loc, '\0', sizeof (*loc));
6585 : }
6586 : else
6587 35759726 : loc = ggc_cleared_alloc<var_loc_node> ();
6588 36478239 : if (bitsize == -1 || piece_loc == NULL)
6589 33433676 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6590 : else
6591 3044563 : adjust_piece_list (&loc->loc, &last->loc, piece_loc,
6592 : bitpos, piece_bitpos, bitsize, loc_note);
6593 36478239 : 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 36478239 : if (last != temp->last)
6597 22556868 : temp->last = last;
6598 : }
6599 5364597 : else if (unused)
6600 357469 : ggc_free (unused);
6601 : }
6602 : else
6603 : {
6604 13584297 : loc = ggc_cleared_alloc<var_loc_node> ();
6605 13584297 : temp->first = loc;
6606 13584297 : temp->last = loc;
6607 13584297 : 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 52034 : verify_die (dw_die_ref die)
6955 : {
6956 52034 : gcc_assert (!die->die_mark);
6957 52034 : if (die->die_parent == NULL
6958 52034 : && 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 747712023 : check_die (dw_die_ref die)
6990 : {
6991 747712023 : unsigned ix;
6992 747712023 : dw_attr_node *a;
6993 747712023 : bool inline_found = false;
6994 747712023 : int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0;
6995 747712023 : int n_decl_line = 0, n_decl_column = 0, n_decl_file = 0;
6996 3571447698 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6997 : {
6998 2823735675 : switch (a->dw_attr)
6999 : {
7000 7814718 : case DW_AT_inline:
7001 7814718 : if (a->dw_attr_val.v.val_unsigned)
7002 2823735675 : inline_found = true;
7003 : break;
7004 178 : case DW_AT_location:
7005 178 : ++n_location;
7006 178 : break;
7007 490621 : case DW_AT_low_pc:
7008 490621 : ++n_low_pc;
7009 490621 : break;
7010 490621 : case DW_AT_high_pc:
7011 490621 : ++n_high_pc;
7012 490621 : break;
7013 118742 : case DW_AT_artificial:
7014 118742 : ++n_artificial;
7015 118742 : break;
7016 412846427 : case DW_AT_decl_column:
7017 412846427 : ++n_decl_column;
7018 412846427 : break;
7019 413392636 : case DW_AT_decl_line:
7020 413392636 : ++n_decl_line;
7021 413392636 : break;
7022 413258575 : case DW_AT_decl_file:
7023 413258575 : ++n_decl_file;
7024 413258575 : break;
7025 : default:
7026 : break;
7027 : }
7028 : }
7029 747712023 : if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1
7030 747712023 : || 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 747712023 : 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 85875499 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7044 78064072 : 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 747712023 : }
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 896790 : attr_checksum (dw_attr_node *at, struct md5_ctx *ctx, int *mark)
7077 : {
7078 896790 : dw_loc_descr_ref loc;
7079 896790 : rtx r;
7080 :
7081 896790 : 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 896790 : if (at->dw_attr == DW_AT_producer)
7086 : return;
7087 :
7088 895230 : 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 249315 : case dw_val_class_unsigned_const:
7095 249315 : case dw_val_class_unsigned_const_implicit:
7096 249315 : CHECKSUM (at->dw_attr_val.v.val_unsigned);
7097 249315 : 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 126227 : case dw_val_class_flag:
7112 126227 : CHECKSUM (at->dw_attr_val.v.val_flag);
7113 126227 : break;
7114 144018 : case dw_val_class_str:
7115 144018 : CHECKSUM_STRING (AT_string (at));
7116 144018 : 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 285915 : case dw_val_class_die_ref:
7134 285915 : die_checksum (AT_ref (at), ctx, mark);
7135 285915 : 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 87406 : case dw_val_class_file:
7148 87406 : case dw_val_class_file_implicit:
7149 87406 : CHECKSUM_STRING (AT_file (at)->filename);
7150 87406 : 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 514400 : die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7165 : {
7166 514400 : dw_die_ref c;
7167 514400 : dw_attr_node *a;
7168 514400 : unsigned ix;
7169 :
7170 : /* To avoid infinite recursion. */
7171 514400 : if (die->die_mark)
7172 : {
7173 285905 : CHECKSUM (die->die_mark);
7174 285905 : return;
7175 : }
7176 228495 : die->die_mark = ++(*mark);
7177 :
7178 228495 : CHECKSUM (die->die_tag);
7179 :
7180 1353780 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7181 896790 : attr_checksum (a, ctx, mark);
7182 :
7183 396808 : 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 1311 : compute_comp_unit_symbol (dw_die_ref unit_die)
8032 : {
8033 1311 : const char *die_name = get_AT_string (unit_die, DW_AT_name);
8034 1311 : const char *base = die_name ? lbasename (die_name) : "anonymous";
8035 1311 : char *name = XALLOCAVEC (char, strlen (base) + 64);
8036 1311 : char *p;
8037 1311 : int i, mark;
8038 1311 : unsigned char checksum[16];
8039 1311 : 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 1311 : md5_init_ctx (&ctx);
8045 1311 : mark = 0;
8046 1311 : die_checksum (unit_die, &ctx, &mark);
8047 1311 : unmark_all_dies (unit_die);
8048 1311 : 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 1311 : sprintf (name, "%s%s.", ISALPHA (*base) ? "" : "g", base);
8055 1311 : clean_symbol_name (name);
8056 :
8057 1311 : p = name + strlen (name);
8058 6555 : for (i = 0; i < 4; i++)
8059 : {
8060 5244 : sprintf (p, "%.2x", checksum[i]);
8061 5244 : p += 2;
8062 : }
8063 :
8064 1311 : unit_die->die_id.die_symbol = xstrdup (name);
8065 1311 : }
8066 :
8067 : /* Returns true if DIE represents a type, in the sense of TYPE_P. */
8068 :
8069 : static bool
8070 79377616 : is_type_die (dw_die_ref die)
8071 : {
8072 79377616 : 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 71425804 : default:
8096 71425804 : return false;
8097 : }
8098 : }
8099 :
8100 : /* Returns true iff C is a compile-unit DIE. */
8101 :
8102 : static inline bool
8103 50642367 : is_cu_die (dw_die_ref c)
8104 : {
8105 50310213 : return c && (c->die_tag == DW_TAG_compile_unit
8106 50589173 : || 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 1806698 : is_unit_die (dw_die_ref c)
8113 : {
8114 1806698 : 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 1806698 : || 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 19398940 : is_template_parameter (dw_die_ref die)
8132 : {
8133 19398940 : 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 26368594 : gen_internal_sym (const char *prefix)
8160 : {
8161 26368594 : char buf[MAX_ARTIFICIAL_LABEL_BYTES];
8162 :
8163 26368594 : ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
8164 26368594 : return xstrdup (buf);
8165 : }
8166 :
8167 : /* Return true if this DIE is a declaration. */
8168 :
8169 : static bool
8170 32103937 : is_declaration_die (dw_die_ref die)
8171 : {
8172 32103937 : dw_attr_node *a;
8173 32103937 : unsigned ix;
8174 :
8175 225151582 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8176 224429374 : 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 438 : decl_table_entry_hasher::hash (const decl_table_entry *entry)
8368 : {
8369 438 : return htab_hash_pointer (entry->orig);
8370 : }
8371 :
8372 : inline bool
8373 491 : decl_table_entry_hasher::equal (const decl_table_entry *entry1,
8374 : const die_struct *entry2)
8375 : {
8376 491 : 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 79317157 : add_sibling_attributes (dw_die_ref die)
9013 : {
9014 79317157 : dw_die_ref c;
9015 :
9016 79317157 : if (! die->die_child)
9017 : return;
9018 :
9019 20793560 : if (die->die_parent && die != die->die_parent->die_child)
9020 15897578 : add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
9021 :
9022 79263728 : 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 72450617 : output_location_lists (dw_die_ref die)
9029 : {
9030 72450617 : dw_die_ref c;
9031 72450617 : dw_attr_node *a;
9032 72450617 : unsigned ix;
9033 :
9034 356944704 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9035 284494087 : if (AT_class (a) == dw_val_class_loc_list)
9036 11410160 : output_loc_list (AT_loc_list (a));
9037 :
9038 144868404 : FOR_EACH_CHILD (die, c, output_location_lists (c));
9039 72450617 : }
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 79316095 : optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
9174 : {
9175 79316095 : dw_die_ref c;
9176 79316095 : dw_attr_node *a;
9177 79316095 : unsigned ix;
9178 79316095 : struct external_ref *ref_p;
9179 :
9180 79316095 : if (is_type_die (die)
9181 79316095 : && (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 391300461 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9191 311984366 : if (AT_class (a) == dw_val_class_die_ref
9192 91178622 : && (c = AT_ref (a))->die_mark == 0
9193 312014075 : && is_type_die (c))
9194 : {
9195 215 : ref_p = lookup_external_ref (map, c);
9196 215 : ref_p->n_refs++;
9197 : }
9198 :
9199 137786253 : FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
9200 79316095 : }
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 52383 : optimize_external_refs (dw_die_ref die)
9246 : {
9247 52383 : external_ref_hash_type *map = new external_ref_hash_type (10);
9248 52383 : optimize_external_refs_1 (die, map);
9249 52471 : map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
9250 52383 : 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 79316107 : build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
9279 : {
9280 79316107 : unsigned int abbrev_id = 0;
9281 79316107 : dw_die_ref c;
9282 79316107 : dw_attr_node *a;
9283 79316107 : unsigned ix;
9284 79316107 : 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 391300485 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9290 311984378 : if (AT_class (a) == dw_val_class_die_ref
9291 311984378 : && (c = AT_ref (a))->die_mark == 0)
9292 : {
9293 29721 : struct external_ref *ref_p;
9294 29721 : gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
9295 :
9296 29721 : if (is_type_die (c)
9297 227 : && (ref_p = lookup_external_ref (extern_map, c))
9298 29948 : && 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 29582 : set_AT_ref_external (a, 1);
9306 : }
9307 :
9308 8421681975 : FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
9309 : {
9310 8418849598 : dw_attr_node *die_a, *abbrev_a;
9311 8418849598 : unsigned ix;
9312 8418849598 : bool ok = true;
9313 :
9314 8418849598 : if (abbrev_id == 0)
9315 79316107 : continue;
9316 8339533491 : if (abbrev->die_tag != die->die_tag)
9317 7726040062 : continue;
9318 613493429 : if ((abbrev->die_child != NULL) != (die->die_child != NULL))
9319 41109709 : continue;
9320 :
9321 1716162337 : if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
9322 431160030 : continue;
9323 :
9324 587499503 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
9325 : {
9326 511015773 : abbrev_a = &(*abbrev->die_attr)[ix];
9327 511015773 : if ((abbrev_a->dw_attr != die_a->dw_attr)
9328 511015773 : || (value_format (abbrev_a) != value_format (die_a)))
9329 : {
9330 : ok = false;
9331 : break;
9332 : }
9333 : }
9334 141223690 : if (ok)
9335 : break;
9336 : }
9337 :
9338 79316107 : if (abbrev_id >= vec_safe_length (abbrev_die_table))
9339 : {
9340 2832377 : vec_safe_push (abbrev_die_table, die);
9341 2832377 : if (abbrev_opt_start)
9342 2832007 : abbrev_usage_count.safe_push (0);
9343 : }
9344 79316107 : if (abbrev_opt_start && abbrev_id >= abbrev_opt_start)
9345 : {
9346 79288002 : abbrev_usage_count[abbrev_id - abbrev_opt_start]++;
9347 79288002 : sorted_abbrev_dies.safe_push (die);
9348 : }
9349 :
9350 79316107 : die->die_abbrev = abbrev_id;
9351 137786277 : FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
9352 79316107 : }
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 4937900052 : die_abbrev_cmp (const void *p1, const void *p2)
9360 : {
9361 4937900052 : dw_die_ref die1 = *(const dw_die_ref *) p1;
9362 4937900052 : dw_die_ref die2 = *(const dw_die_ref *) p2;
9363 :
9364 4937900052 : gcc_checking_assert (die1->die_abbrev >= abbrev_opt_start);
9365 4937900052 : gcc_checking_assert (die2->die_abbrev >= abbrev_opt_start);
9366 :
9367 4937900052 : if (die1->die_abbrev >= abbrev_opt_base_type_end
9368 4937900052 : && die2->die_abbrev >= abbrev_opt_base_type_end)
9369 : {
9370 4937900052 : if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
9371 4937900052 : > abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
9372 : return -1;
9373 2781002292 : if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
9374 2781002292 : < abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
9375 : return 1;
9376 : }
9377 :
9378 : /* Stabilize the sort. */
9379 988205044 : if (die1->die_abbrev < die2->die_abbrev)
9380 : return -1;
9381 837441068 : if (die1->die_abbrev > die2->die_abbrev)
9382 153814521 : 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 2809349 : 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 2809349 : if (end < first_id + 2)
9398 2809349 : return;
9399 :
9400 1697727 : dw_attr_node *a;
9401 1697727 : unsigned ix, i;
9402 1697727 : dw_die_ref die = sorted_abbrev_dies[first_id];
9403 11063719 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9404 9365992 : if (implicit_consts[ix])
9405 : {
9406 1152834 : enum dw_val_class new_class = dw_val_class_none;
9407 1152834 : switch (AT_class (a))
9408 : {
9409 739996 : case dw_val_class_unsigned_const:
9410 739996 : if ((HOST_WIDE_INT) AT_unsigned (a) < 0)
9411 940 : 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 739056 : if (constant_size (AT_unsigned (a)) * (end - first_id)
9417 739056 : <= (unsigned) size_of_sleb128 (AT_unsigned (a)))
9418 13347 : 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 410898 : case dw_val_class_file:
9428 410898 : new_class = dw_val_class_file_implicit;
9429 410898 : break;
9430 :
9431 0 : default:
9432 0 : continue;
9433 : }
9434 13568721 : for (i = first_id; i < end; i++)
9435 12430174 : (*sorted_abbrev_dies[i]->die_attr)[ix].dw_attr_val.val_class
9436 24860348 : = new_class;
9437 : }
9438 : }
9439 :
9440 : /* Attempt to optimize abbreviation table from abbrev_opt_start
9441 : abbreviation above. */
9442 :
9443 : static void
9444 52302 : optimize_abbrev_table (void)
9445 : {
9446 52302 : if (abbrev_opt_start
9447 52302 : && vec_safe_length (abbrev_die_table) > abbrev_opt_start
9448 104532 : && (dwarf_version >= 5 || vec_safe_length (abbrev_die_table) > 127))
9449 : {
9450 50304 : auto_vec<bool, 32> implicit_consts;
9451 50304 : sorted_abbrev_dies.qsort (die_abbrev_cmp);
9452 :
9453 50304 : unsigned int abbrev_id = abbrev_opt_start - 1;
9454 50304 : unsigned int first_id = ~0U;
9455 50304 : unsigned int last_abbrev_id = 0;
9456 50304 : unsigned int i;
9457 50304 : dw_die_ref die;
9458 50304 : 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 79286742 : FOR_EACH_VEC_ELT (sorted_abbrev_dies, i, die)
9463 : {
9464 79236438 : dw_attr_node *a;
9465 79236438 : 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 79236438 : if (die->die_abbrev < abbrev_opt_base_type_end)
9471 0 : continue;
9472 79236438 : if (die->die_abbrev != last_abbrev_id)
9473 : {
9474 2809349 : last_abbrev_id = die->die_abbrev;
9475 2809349 : if (dwarf_version >= 5 && first_id != ~0U)
9476 2759045 : optimize_implicit_const (first_id, i, implicit_consts);
9477 2809349 : abbrev_id++;
9478 2809349 : (*abbrev_die_table)[abbrev_id] = die;
9479 2809349 : if (dwarf_version >= 5)
9480 : {
9481 2809349 : first_id = i;
9482 2809349 : implicit_consts.truncate (0);
9483 :
9484 21474396 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9485 15855698 : switch (AT_class (a))
9486 : {
9487 6708277 : case dw_val_class_const:
9488 6708277 : case dw_val_class_unsigned_const:
9489 6708277 : case dw_val_class_file:
9490 6708277 : implicit_consts.safe_push (true);
9491 6708277 : break;
9492 9147421 : default:
9493 9147421 : implicit_consts.safe_push (false);
9494 9147421 : break;
9495 : }
9496 : }
9497 : }
9498 76427089 : else if (dwarf_version >= 5)
9499 : {
9500 372213382 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9501 295786293 : if (!implicit_consts[ix])
9502 275811081 : continue;
9503 : else
9504 : {
9505 19975212 : dw_attr_node *other_a
9506 19975212 : = &(*(*abbrev_die_table)[abbrev_id]->die_attr)[ix];
9507 19975212 : if (!dw_val_equal_p (&a->dw_attr_val,
9508 : &other_a->dw_attr_val))
9509 2779854 : implicit_consts[ix] = false;
9510 : }
9511 : }
9512 79236438 : die->die_abbrev = abbrev_id;
9513 : }
9514 100608 : gcc_assert (abbrev_id == vec_safe_length (abbrev_die_table) - 1);
9515 50304 : if (dwarf_version >= 5 && first_id != ~0U)
9516 50304 : optimize_implicit_const (first_id, i, implicit_consts);
9517 50304 : }
9518 :
9519 52302 : abbrev_opt_start = 0;
9520 52302 : abbrev_opt_base_type_end = 0;
9521 52302 : abbrev_usage_count.release ();
9522 52302 : sorted_abbrev_dies.release ();
9523 52302 : }
9524 :
9525 : /* Return the power-of-two number of bytes necessary to represent VALUE. */
9526 :
9527 : static int
9528 542335415 : constant_size (unsigned HOST_WIDE_INT value)
9529 : {
9530 542335415 : int log;
9531 :
9532 542335415 : if (value == 0)
9533 : log = 0;
9534 : else
9535 534604289 : log = floor_log2 (value);
9536 :
9537 1076939704 : log = log / 8;
9538 534604289 : log = 1 << (floor_log2 (log) + 1);
9539 :
9540 542335415 : 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 79316374 : size_of_die (dw_die_ref die)
9548 : {
9549 79316374 : unsigned long size = 0;
9550 79316374 : dw_attr_node *a;
9551 79316374 : unsigned ix;
9552 79316374 : enum dwarf_form form;
9553 :
9554 79316374 : size += size_of_uleb128 (die->die_abbrev);
9555 391302583 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9556 : {
9557 311986209 : switch (AT_class (a))
9558 : {
9559 28848 : case dw_val_class_addr:
9560 28848 : 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 31885 : size += DWARF2_ADDR_SIZE;
9567 : break;
9568 0 : case dw_val_class_offset:
9569 0 : size += dwarf_offset_size;
9570 0 : break;
9571 7533257 : case dw_val_class_loc:
9572 7533257 : {
9573 7533257 : unsigned long lsize = size_of_locs (AT_loc (a));
9574 :
9575 : /* Block length. */
9576 7533257 : if (dwarf_version >= 4)
9577 7522331 : size += size_of_uleb128 (lsize);
9578 : else
9579 10926 : size += constant_size (lsize);
9580 7533257 : size += lsize;
9581 : }
9582 7533257 : break;
9583 11410160 : case dw_val_class_loc_list:
9584 11410160 : 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 11410158 : size += dwarf_offset_size;
9591 : break;
9592 11233987 : case dw_val_class_view_list:
9593 11233987 : size += dwarf_offset_size;
9594 11233987 : break;
9595 3232093 : case dw_val_class_range_list:
9596 3232093 : 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 3232090 : size += dwarf_offset_size;
9604 : break;
9605 14553 : case dw_val_class_const:
9606 14553 : size += size_of_sleb128 (AT_int (a));
9607 14553 : break;
9608 66598728 : case dw_val_class_unsigned_const:
9609 66598728 : {
9610 66598728 : int csize = constant_size (AT_unsigned (a));
9611 66598728 : 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 66598727 : size += csize;
9617 : }
9618 : break;
9619 6270655 : case dw_val_class_symview:
9620 6270655 : if (symview_upper_bound <= 0xff)
9621 342134 : size += 1;
9622 5928521 : else if (symview_upper_bound <= 0xffff)
9623 5928521 : 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 15194 : case dw_val_class_vec:
9648 15194 : size += constant_size (a->dw_attr_val.v.val_vec.length
9649 15194 : * a->dw_attr_val.v.val_vec.elt_size)
9650 15194 : + a->dw_attr_val.v.val_vec.length
9651 : * a->dw_attr_val.v.val_vec.elt_size; /* block */
9652 15194 : break;
9653 25713724 : case dw_val_class_flag:
9654 25713724 : 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 25692693 : gcc_assert (a->dw_attr_val.v.val_flag == 1);
9662 : else
9663 21031 : size += 1;
9664 : break;
9665 91178634 : case dw_val_class_die_ref:
9666 91178634 : 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 29582 : if (AT_ref (a)->comdat_type_p)
9673 88 : size += DWARF_TYPE_SIGNATURE_SIZE;
9674 29494 : else if (dwarf_version == 2)
9675 30 : size += DWARF2_ADDR_SIZE;
9676 : else
9677 29464 : size += dwarf_offset_size;
9678 : }
9679 : else
9680 91149052 : size += dwarf_offset_size;
9681 : break;
9682 0 : case dw_val_class_fde_ref:
9683 0 : size += dwarf_offset_size;
9684 0 : break;
9685 13627151 : case dw_val_class_lbl_id:
9686 13627151 : 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 14765838 : size += DWARF2_ADDR_SIZE;
9693 : break;
9694 53166 : case dw_val_class_lineptr:
9695 53166 : case dw_val_class_macptr:
9696 53166 : case dw_val_class_loclistsptr:
9697 53166 : size += dwarf_offset_size;
9698 53166 : break;
9699 32734976 : case dw_val_class_str:
9700 32734976 : form = AT_string_form (a);
9701 32734976 : if (form == DW_FORM_strp || form == DW_FORM_line_strp)
9702 29648951 : size += dwarf_offset_size;
9703 3100179 : else if (form == dwarf_FORM (DW_FORM_strx))
9704 935 : size += size_of_uleb128 (AT_index (a));
9705 : else
9706 3085090 : size += strlen (a->dw_attr_val.v.val_str->str) + 1;
9707 : break;
9708 25461899 : case dw_val_class_file:
9709 25461899 : size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
9710 25461899 : 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 4440516 : case dw_val_class_high_pc:
9718 4440516 : size += DWARF2_ADDR_SIZE;
9719 4440516 : 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 79316374 : 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 79316107 : calc_die_sizes (dw_die_ref die)
9747 : {
9748 79316107 : dw_die_ref c;
9749 :
9750 79316107 : gcc_assert (die->die_offset == 0
9751 : || (unsigned long int) die->die_offset == next_die_offset);
9752 79316107 : die->die_offset = next_die_offset;
9753 79316107 : next_die_offset += size_of_die (die);
9754 :
9755 158579831 : FOR_EACH_CHILD (die, c, calc_die_sizes (c));
9756 :
9757 79316107 : if (die->die_child != NULL)
9758 : /* Count the null byte used to terminate sibling lists. */
9759 20793554 : next_die_offset += 1;
9760 79316107 : }
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 79317783 : mark_dies (dw_die_ref die)
9804 : {
9805 79317783 : dw_die_ref c;
9806 :
9807 79317783 : gcc_assert (!die->die_mark);
9808 :
9809 79317783 : die->die_mark = 1;
9810 158582919 : FOR_EACH_CHILD (die, c, mark_dies (c));
9811 79317783 : }
9812 :
9813 : /* Clear the marks for a die and its children. */
9814 :
9815 : static void
9816 230064 : unmark_dies (dw_die_ref die)
9817 : {
9818 230064 : dw_die_ref c;
9819 :
9820 230064 : if (! use_debug_types)
9821 227661 : gcc_assert (die->die_mark);
9822 :
9823 230064 : die->die_mark = 0;
9824 458619 : FOR_EACH_CHILD (die, c, unmark_dies (c));
9825 230064 : }
9826 :
9827 : /* Clear the marks for a die, its children and referred dies. */
9828 :
9829 : static void
9830 514820 : unmark_all_dies (dw_die_ref die)
9831 : {
9832 514820 : dw_die_ref c;
9833 514820 : dw_attr_node *a;
9834 514820 : unsigned ix;
9835 :
9836 514820 : if (!die->die_mark)
9837 514820 : return;
9838 228773 : die->die_mark = 0;
9839 :
9840 397203 : FOR_EACH_CHILD (die, c, unmark_all_dies (c));
9841 :
9842 1126620 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9843 897847 : if (AT_class (a) == dw_val_class_die_ref)
9844 286038 : 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 50991 : size_of_aranges (void)
9903 : {
9904 50991 : unsigned long size;
9905 :
9906 63659 : size = DWARF_ARANGES_HEADER_SIZE;
9907 :
9908 : /* Count the address/length pair for this compilation unit. */
9909 50991 : if (switch_text_ranges)
9910 32258 : size += 2 * DWARF2_ADDR_SIZE
9911 29203 : * (vec_safe_length (switch_text_ranges) / 2 + 1);
9912 50991 : if (switch_cold_ranges)
9913 9110 : size += 2 * DWARF2_ADDR_SIZE
9914 8792 : * (vec_safe_length (switch_cold_ranges) / 2 + 1);
9915 50991 : if (have_multiple_function_sections)
9916 : {
9917 : unsigned fde_idx;
9918 : dw_fde_ref fde;
9919 :
9920 291531 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
9921 : {
9922 263129 : if (fde->ignored_debug)
9923 2920 : continue;
9924 260209 : if (!fde->in_std_section)
9925 198695 : size += 2 * DWARF2_ADDR_SIZE;
9926 260209 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
9927 10663 : size += 2 * DWARF2_ADDR_SIZE;
9928 : }
9929 : }
9930 :
9931 : /* Count the two zero words used to terminated the address range table. */
9932 50991 : size += 2 * DWARF2_ADDR_SIZE;
9933 50991 : return size;
9934 : }
9935 :
9936 : /* Select the encoding of an attribute value. */
9937 :
9938 : static enum dwarf_form
9939 990586379 : value_format (dw_attr_node *a)
9940 : {
9941 990586379 : switch (AT_class (a))
9942 : {
9943 58350 : case dw_val_class_addr:
9944 : /* Only very few attributes allow DW_FORM_addr. */
9945 58350 : switch (a->dw_attr)
9946 : {
9947 58350 : case DW_AT_low_pc:
9948 58350 : case DW_AT_high_pc:
9949 58350 : case DW_AT_entry_pc:
9950 58350 : case DW_AT_trampoline:
9951 58350 : return (AT_index (a) == NOT_INDEXED
9952 58350 : ? 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 22825640 : case dw_val_class_loc_list:
9970 22825640 : if (dwarf_split_debug_info
9971 4 : && dwarf_version >= 5
9972 22825644 : && AT_loc_list (a)->num_assigned)
9973 : return DW_FORM_loclistx;
9974 : /* FALLTHRU */
9975 57934039 : case dw_val_class_view_list:
9976 57934039 : 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 57934039 : 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 57934054 : && a->dw_attr_val.val_entry != RELOCATED_OFFSET)
9988 : return DW_FORM_rnglistx;
9989 57934030 : if (dwarf_version >= 4)
9990 : return DW_FORM_sec_offset;
9991 : /* FALLTHRU */
9992 18027 : case dw_val_class_vms_delta:
9993 18027 : case dw_val_class_offset:
9994 18027 : 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 15110152 : case dw_val_class_loc:
10004 15110152 : if (dwarf_version >= 4)
10005 : return DW_FORM_exprloc;
10006 22025 : 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 235217183 : case dw_val_class_unsigned_const:
10020 235217183 : switch (constant_size (AT_unsigned (a)))
10021 : {
10022 : case 1:
10023 : return DW_FORM_data1;
10024 : case 2:
10025 : return DW_FORM_data2;
10026 218152 : 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 218152 : if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
10032 : return DW_FORM_udata;
10033 : return DW_FORM_data4;
10034 36654 : case 8:
10035 36654 : 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 29654590 : 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 29654590 : if (symview_upper_bound <= 0xff)
10083 : return DW_FORM_data1;
10084 28218006 : 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 42581 : case dw_val_class_vec:
10091 42581 : switch (constant_size (a->dw_attr_val.v.val_vec.length
10092 42581 : * 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 108150208 : case dw_val_class_flag:
10104 108150208 : 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 108104044 : gcc_assert (a->dw_attr_val.v.val_flag == 1);
10113 : return DW_FORM_flag_present;
10114 : }
10115 : return DW_FORM_flag;
10116 203145163 : case dw_val_class_die_ref:
10117 203145163 : if (AT_ref_external (a))
10118 : {
10119 70733 : if (AT_ref (a)->comdat_type_p)
10120 : return DW_FORM_ref_sig8;
10121 : else
10122 70552 : return DW_FORM_ref_addr;
10123 : }
10124 : else
10125 406148860 : return DW_FORM_ref;
10126 0 : case dw_val_class_fde_ref:
10127 0 : return DW_FORM_data;
10128 49716348 : case dw_val_class_lbl_id:
10129 49716348 : return (AT_index (a) == NOT_INDEXED
10130 49716348 : ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
10131 107420 : case dw_val_class_lineptr:
10132 107420 : case dw_val_class_macptr:
10133 107420 : case dw_val_class_loclistsptr:
10134 107420 : return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10135 153189702 : case dw_val_class_str:
10136 153189702 : return AT_string_form (a);
10137 122141103 : case dw_val_class_file:
10138 122141103 : 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 13744496 : case dw_val_class_high_pc:
10154 13744496 : 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 16014824 : output_value_format (dw_attr_node *a)
10194 : {
10195 16014824 : enum dwarf_form form = value_format (a);
10196 :
10197 32029648 : dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10198 16014824 : }
10199 :
10200 : /* Given a die and id, produce the appropriate abbreviations. */
10201 :
10202 : static void
10203 2840102 : output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
10204 : {
10205 2840102 : unsigned ix;
10206 2840102 : dw_attr_node *a_attr;
10207 :
10208 2840102 : dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10209 2840102 : dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10210 2840102 : dwarf_tag_name (abbrev->die_tag));
10211 :
10212 2840102 : if (abbrev->die_child != NULL)
10213 1380917 : dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10214 : else
10215 1459185 : dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10216 :
10217 18854926 : for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
10218 : {
10219 16014824 : dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10220 16014824 : dwarf_attr_name (a_attr->dw_attr));
10221 16014824 : output_value_format (a_attr);
10222 16014824 : if (value_format (a_attr) == DW_FORM_implicit_const)
10223 : {
10224 1140988 : if (AT_class (a_attr) == dw_val_class_file_implicit)
10225 : {
10226 412300 : int f = maybe_emit_file (a_attr->dw_attr_val.v.val_file);
10227 412300 : const char *filename = a_attr->dw_attr_val.v.val_file->filename;
10228 412300 : dw2_asm_output_data_sleb128 (f, "(%s)", filename);
10229 : }
10230 : else
10231 728688 : dw2_asm_output_data_sleb128 (a_attr->dw_attr_val.v.val_int, NULL);
10232 : }
10233 : }
10234 :
10235 2840102 : dw2_asm_output_data (1, 0, NULL);
10236 2840102 : dw2_asm_output_data (1, 0, NULL);
10237 2840102 : }
10238 :
10239 :
10240 : /* Output the .debug_abbrev section which defines the DIE abbreviation
10241 : table. */
10242 :
10243 : static void
10244 52304 : output_abbrev_section (void)
10245 : {
10246 52304 : unsigned int abbrev_id;
10247 52304 : dw_die_ref abbrev;
10248 :
10249 2944461 : FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
10250 2892157 : if (abbrev_id != 0)
10251 2839853 : output_die_abbrevs (abbrev_id, abbrev);
10252 :
10253 : /* Terminate the table. */
10254 52304 : dw2_asm_output_data (1, 0, NULL);
10255 52304 : }
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 26400079 : 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 52800158 : dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
10266 :
10267 26400079 : retlist->begin = begin;
10268 26400079 : retlist->begin_entry = NULL;
10269 26400079 : retlist->end = end;
10270 26400079 : retlist->end_entry = NULL;
10271 26400079 : retlist->expr = expr;
10272 26400079 : retlist->section = section;
10273 26400079 : retlist->vbegin = vbegin;
10274 26400079 : retlist->vend = vend;
10275 :
10276 26400079 : 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 23597311 : loc_list_has_views (dw_loc_list_ref list)
10291 : {
10292 23597311 : if (!debug_variable_location_views)
10293 : return false;
10294 :
10295 1417160 : for (dw_loc_list_ref loc = list;
10296 25010592 : loc != NULL; loc = loc->dw_loc_next)
10297 24317856 : if (!ZERO_VIEW_P (loc->vbegin) || !ZERO_VIEW_P (loc->vend))
10298 22900696 : 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 11924367 : gen_llsym (dw_loc_list_ref list)
10308 : {
10309 11924367 : gcc_assert (!list->ll_symbol);
10310 11924367 : list->ll_symbol = gen_internal_sym ("LLST");
10311 :
10312 11924367 : if (!loc_list_has_views (list))
10313 : return;
10314 :
10315 11749067 : if (dwarf2out_locviews_in_attribute ())
10316 : {
10317 : /* Use the same label_num for the view list. */
10318 11749067 : label_num--;
10319 11749067 : 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 1297509 : maybe_gen_llsym (dw_loc_list_ref list)
10330 : {
10331 1297509 : if (!list || (!list->dw_loc_next && !loc_list_has_views (list)))
10332 1247640 : return;
10333 :
10334 49869 : 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 47999364 : 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 47999364 : if (strcmp (curr->begin, curr->end) == 0
10347 6384937 : && curr->vbegin == curr->vend && !curr->force)
10348 : return true;
10349 :
10350 47999343 : if (!sizep)
10351 : return false;
10352 :
10353 47999339 : 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 47999339 : if (dwarf_version < 5 && size > 0xffff)
10360 : return true;
10361 :
10362 47999339 : *sizep = size;
10363 :
10364 47999339 : return false;
10365 : }
10366 :
10367 : /* Output a view pair loclist entry for CURR, if it requires one. */
10368 :
10369 : static void
10370 24255847 : dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr)
10371 : {
10372 24255847 : 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 11410160 : output_loc_list (dw_loc_list_ref list_head)
10417 : {
10418 11410160 : int vcount = 0, lcount = 0;
10419 :
10420 11410160 : if (list_head->emitted)
10421 : return;
10422 11283283 : list_head->emitted = true;
10423 :
10424 11283283 : if (list_head->vl_symbol && dwarf2out_locviews_in_attribute ())
10425 : {
10426 11108003 : ASM_OUTPUT_LABEL (asm_out_file, list_head->vl_symbol);
10427 :
10428 34838125 : for (dw_loc_list_ref curr = list_head; curr != NULL;
10429 23730122 : curr = curr->dw_loc_next)
10430 : {
10431 23730122 : unsigned long size;
10432 :
10433 23730122 : if (skip_loc_list_entry (curr, &size))
10434 0 : continue;
10435 :
10436 23730122 : vcount++;
10437 :
10438 : /* ?? dwarf_split_debug_info? */
10439 23730122 : if (dwarf2out_as_locview_support)
10440 : {
10441 23728892 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
10442 :
10443 23728892 : if (!ZERO_VIEW_P (curr->vbegin))
10444 : {
10445 23150305 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vbegin);
10446 23150305 : dw2_asm_output_symname_uleb128 (label,
10447 : "View list begin (%s)",
10448 : list_head->vl_symbol);
10449 : }
10450 : else
10451 578587 : dw2_asm_output_data_uleb128 (0,
10452 : "View list begin (%s)",
10453 : list_head->vl_symbol);
10454 :
10455 23728892 : if (!ZERO_VIEW_P (curr->vend))
10456 : {
10457 22702832 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vend);
10458 22702832 : dw2_asm_output_symname_uleb128 (label,
10459 : "View list end (%s)",
10460 : list_head->vl_symbol);
10461 : }
10462 : else
10463 1026060 : 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 11283283 : ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
10482 :
10483 11283283 : const char *last_section = NULL;
10484 11283283 : const char *base_label = NULL;
10485 :
10486 : /* Walk the location list, and output each range + expression. */
10487 35552521 : for (dw_loc_list_ref curr = list_head; curr != NULL;
10488 24269238 : curr = curr->dw_loc_next)
10489 : {
10490 24269238 : 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 24269238 : if (skip_loc_list_entry (curr, &size))
10495 21 : continue;
10496 :
10497 24269217 : lcount++;
10498 :
10499 24269217 : if (dwarf_version >= 5)
10500 : {
10501 24255847 : 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 24255843 : 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 24255843 : else if (!have_multiple_function_sections && HAVE_AS_LEB128)
10533 : {
10534 3805638 : 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 3805638 : dw2_asm_output_data (1, DW_LLE_offset_pair,
10540 : "DW_LLE_offset_pair (%s)",
10541 : list_head->ll_symbol);
10542 3805638 : dw2_asm_output_delta_uleb128 (curr->begin, curr->section,
10543 : "Location list begin address (%s)",
10544 : list_head->ll_symbol);
10545 3805638 : dw2_asm_output_delta_uleb128 (curr->end, curr->section,
10546 : "Location list end address (%s)",
10547 : list_head->ll_symbol);
10548 : }
10549 20450205 : 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 20450205 : if (last_section == NULL || curr->section != last_section)
10556 : {
10557 10776583 : dw_loc_list_ref curr2;
10558 11192323 : for (curr2 = curr->dw_loc_next; curr2 != NULL;
10559 415740 : curr2 = curr2->dw_loc_next)
10560 : {
10561 4024991 : if (strcmp (curr2->begin, curr2->end) == 0
10562 415740 : && !curr2->force)
10563 415740 : continue;
10564 : break;
10565 : }
10566 10776583 : if (curr2 == NULL || curr->section != curr2->section)
10567 : last_section = NULL;
10568 : else
10569 : {
10570 3583315 : last_section = curr->section;
10571 3583315 : base_label = curr->begin;
10572 3583315 : dw2_asm_output_data (1, DW_LLE_base_address,
10573 : "DW_LLE_base_address (%s)",
10574 : list_head->ll_symbol);
10575 3784314 : 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 13256937 : if (last_section == NULL)
10584 : {
10585 7193268 : dwarf2out_maybe_output_loclist_view_pair (curr);
10586 7193268 : dw2_asm_output_data (1, DW_LLE_start_length,
10587 : "DW_LLE_start_length (%s)",
10588 : list_head->ll_symbol);
10589 7414162 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10590 : "Location list begin address (%s)",
10591 : list_head->ll_symbol);
10592 7193268 : 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 13256937 : dwarf2out_maybe_output_loclist_view_pair (curr);
10601 13256937 : dw2_asm_output_data (1, DW_LLE_offset_pair,
10602 : "DW_LLE_offset_pair (%s)",
10603 : list_head->ll_symbol);
10604 13256937 : dw2_asm_output_delta_uleb128 (curr->begin, base_label,
10605 : "Location list begin address "
10606 : "(%s)", list_head->ll_symbol);
10607 13256937 : 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 13370 : 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 13370 : else if (!have_multiple_function_sections)
10646 : {
10647 : /* Pair of relative addresses against start of text section. */
10648 6577 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
10649 : "Location list begin address (%s)",
10650 : list_head->ll_symbol);
10651 6577 : 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 24269217 : if (dwarf_version >= 5)
10668 24255847 : dw2_asm_output_data_uleb128 (size, "Location expression size");
10669 : else
10670 : {
10671 13370 : gcc_assert (size <= 0xffff);
10672 13370 : dw2_asm_output_data (2, size, "Location expression size");
10673 : }
10674 :
10675 24269217 : output_loc_sequence (curr->expr, -1);
10676 : }
10677 :
10678 : /* And finally list termination. */
10679 11283283 : if (dwarf_version >= 5)
10680 11278974 : dw2_asm_output_data (1, DW_LLE_end_of_list,
10681 : "DW_LLE_end_of_list (%s)", list_head->ll_symbol);
10682 4309 : 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 4309 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10689 : "Location list terminator begin (%s)",
10690 : list_head->ll_symbol);
10691 4309 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10692 : "Location list terminator end (%s)",
10693 : list_head->ll_symbol);
10694 : }
10695 :
10696 11283283 : 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 3232084 : output_range_list_offset (dw_attr_node *a)
10706 : {
10707 3232084 : const char *name = dwarf_attr_name (a->dw_attr);
10708 :
10709 3232084 : if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
10710 : {
10711 3232081 : if (dwarf_version >= 5)
10712 : {
10713 3230750 : dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
10714 3230750 : 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 3232084 : }
10738 :
10739 : /* Output the offset into the debug_loc section. */
10740 :
10741 : static void
10742 11410160 : output_loc_list_offset (dw_attr_node *a)
10743 : {
10744 11410160 : char *sym = AT_loc_list (a)->ll_symbol;
10745 :
10746 11410160 : gcc_assert (sym);
10747 11410160 : if (!dwarf_split_debug_info)
10748 11410158 : dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
10749 11410158 : "%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 11410160 : }
10761 :
10762 : /* Output the offset into the debug_loc section. */
10763 :
10764 : static void
10765 11233987 : output_view_list_offset (dw_attr_node *a)
10766 : {
10767 11233987 : char *sym = (*AT_loc_list_ptr (a))->vl_symbol;
10768 :
10769 11233987 : gcc_assert (sym);
10770 11233987 : 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 11233985 : dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
10775 11233985 : "%s", dwarf_attr_name (a->dw_attr));
10776 11233987 : }
10777 :
10778 : /* Output an attribute's index or value appropriately. */
10779 :
10780 : static void
10781 13655981 : output_attr_index_or_value (dw_attr_node *a)
10782 : {
10783 13655981 : const char *name = dwarf_attr_name (a->dw_attr);
10784 :
10785 13655981 : 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 13655728 : switch (AT_class (a))
10791 : {
10792 28830 : case dw_val_class_addr:
10793 28830 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
10794 28830 : break;
10795 13626898 : case dw_val_class_high_pc:
10796 13626898 : case dw_val_class_lbl_id:
10797 13626898 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
10798 13626898 : 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 79316356 : output_die (dw_die_ref die)
10831 : {
10832 79316356 : dw_attr_node *a;
10833 79316356 : dw_die_ref c;
10834 79316356 : unsigned long size;
10835 79316356 : unsigned ix;
10836 :
10837 158632712 : dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
10838 79316356 : (unsigned long)die->die_offset,
10839 79316356 : dwarf_tag_name (die->die_tag));
10840 :
10841 391302463 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
10842 : {
10843 311986107 : const char *name = dwarf_attr_name (a->dw_attr);
10844 :
10845 311986107 : switch (AT_class (a))
10846 : {
10847 28830 : case dw_val_class_addr:
10848 28830 : output_attr_index_or_value (a);
10849 28830 : 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 3232084 : case dw_val_class_range_list:
10857 3232084 : output_range_list_offset (a);
10858 3232084 : break;
10859 :
10860 7533257 : case dw_val_class_loc:
10861 7533257 : size = size_of_locs (AT_loc (a));
10862 :
10863 : /* Output the block length for this list of location operations. */
10864 7533257 : if (dwarf_version >= 4)
10865 7522331 : dw2_asm_output_data_uleb128 (size, "%s", name);
10866 : else
10867 10926 : dw2_asm_output_data (constant_size (size), size, "%s", name);
10868 :
10869 7533257 : output_loc_sequence (AT_loc (a), -1);
10870 7533257 : break;
10871 :
10872 14553 : 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 14553 : dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
10877 14553 : break;
10878 :
10879 66598701 : case dw_val_class_unsigned_const:
10880 66598701 : {
10881 66598701 : int csize = constant_size (AT_unsigned (a));
10882 66598701 : 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 66598700 : dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
10888 : }
10889 : break;
10890 :
10891 6270655 : case dw_val_class_symview:
10892 6270655 : {
10893 6270655 : int vsize;
10894 6270655 : if (symview_upper_bound <= 0xff)
10895 : vsize = 1;
10896 5928521 : 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 6270655 : dw2_asm_output_addr (vsize, a->dw_attr_val.v.val_symbolic_view,
10903 : "%s", name);
10904 : }
10905 6270655 : break;
10906 :
10907 5010 : case dw_val_class_const_implicit:
10908 5010 : 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 8737261 : case dw_val_class_unsigned_const_implicit:
10915 8737261 : 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 15194 : case dw_val_class_vec:
10976 15194 : {
10977 15194 : unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
10978 15194 : unsigned int len = a->dw_attr_val.v.val_vec.length;
10979 15194 : unsigned int i;
10980 15194 : unsigned char *p;
10981 :
10982 15194 : dw2_asm_output_data (constant_size (len * elt_size),
10983 15194 : len * elt_size, "%s", name);
10984 15194 : if (elt_size > sizeof (HOST_WIDE_INT))
10985 : {
10986 0 : elt_size /= 2;
10987 0 : len *= 2;
10988 : }
10989 15194 : for (i = 0, p = (unsigned char *) a->dw_attr_val.v.val_vec.array;
10990 3497293 : i < len;
10991 3482099 : i++, p += elt_size)
10992 6964198 : dw2_asm_output_data (elt_size, extract_int (p, elt_size),
10993 : "fp or vector constant word %u", i);
10994 : break;
10995 : }
10996 :
10997 25713724 : case dw_val_class_flag:
10998 25713724 : 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 25692693 : gcc_assert (AT_flag (a) == 1);
11007 25692693 : 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 21031 : dw2_asm_output_data (1, AT_flag (a), "%s", name);
11013 21031 : break;
11014 :
11015 11410160 : case dw_val_class_loc_list:
11016 11410160 : output_loc_list_offset (a);
11017 11410160 : break;
11018 :
11019 11233987 : case dw_val_class_view_list:
11020 11233987 : output_view_list_offset (a);
11021 11233987 : break;
11022 :
11023 91178634 : case dw_val_class_die_ref:
11024 91178634 : if (AT_ref_external (a))
11025 : {
11026 29582 : 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 29494 : const char *sym = AT_ref (a)->die_id.die_symbol;
11037 29494 : int size;
11038 :
11039 29494 : 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 29494 : if (dwarf_version == 2)
11044 30 : size = DWARF2_ADDR_SIZE;
11045 : else
11046 29464 : 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 29494 : if (AT_ref (a)->with_offset)
11056 29494 : 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 91149052 : gcc_assert (AT_ref (a)->die_offset);
11066 91149052 : 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 13627151 : case dw_val_class_lbl_id:
11095 13627151 : output_attr_index_or_value (a);
11096 13627151 : break;
11097 :
11098 52627 : case dw_val_class_lineptr:
11099 52627 : dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
11100 : debug_line_section, "%s", name);
11101 52627 : 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 32734940 : case dw_val_class_str:
11114 32734940 : if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
11115 29548677 : dw2_asm_output_offset (dwarf_offset_size,
11116 29548677 : a->dw_attr_val.v.val_str->label,
11117 : debug_str_section,
11118 : "%s: \"%s\"", name, AT_string (a));
11119 3186263 : else if (a->dw_attr_val.v.val_str->form == DW_FORM_line_strp)
11120 100238 : dw2_asm_output_offset (dwarf_offset_size,
11121 100238 : a->dw_attr_val.v.val_str->label,
11122 : debug_line_str_section,
11123 : "%s: \"%s\"", name, AT_string (a));
11124 3100179 : 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 3085090 : dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11129 : break;
11130 :
11131 25461899 : case dw_val_class_file:
11132 25461899 : {
11133 25461899 : int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11134 :
11135 25461899 : dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11136 25461899 : a->dw_attr_val.v.val_file->filename);
11137 25461899 : break;
11138 : }
11139 :
11140 3696289 : case dw_val_class_file_implicit:
11141 3696289 : 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 4440516 : case dw_val_class_high_pc:
11159 4440516 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
11160 : get_AT_low_pc (die), "DW_AT_high_pc");
11161 4440516 : 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 137786526 : FOR_EACH_CHILD (die, c, output_die (c));
11200 :
11201 : /* Add null byte to terminate sibling list. */
11202 79316356 : if (die->die_child != NULL)
11203 20793554 : dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11204 20793554 : (unsigned long) die->die_offset);
11205 79316356 : }
11206 :
11207 : /* Output the dwarf version number. */
11208 :
11209 : static void
11210 118621 : 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 118621 : 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 118621 : dw2_asm_output_data (2, dwarf_version, "DWARF version number");
11227 118621 : }
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 52383 : output_compilation_unit_header (enum dwarf_unit_type ut)
11234 : {
11235 52383 : if (!XCOFF_DEBUGGING_INFO)
11236 : {
11237 52383 : 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 52383 : dw2_asm_output_data (dwarf_offset_size,
11241 52383 : next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11242 : "Length of Compilation Unit Info");
11243 : }
11244 :
11245 52383 : output_dwarf_version ();
11246 52383 : if (dwarf_version >= 5)
11247 : {
11248 50388 : const char *name;
11249 50388 : 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 50388 : dw2_asm_output_data (1, ut, "%s", name);
11258 56722 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11259 : }
11260 52383 : dw2_asm_output_offset (dwarf_offset_size, abbrev_section_label,
11261 : debug_abbrev_section,
11262 : "Offset Into Abbrev. Section");
11263 52383 : if (dwarf_version < 5)
11264 1995 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11265 52383 : }
11266 :
11267 : /* Output the compilation unit DIE and its children. */
11268 :
11269 : static void
11270 53595 : output_comp_unit (dw_die_ref die, int output_if_empty,
11271 : const unsigned char *dwo_id)
11272 : {
11273 53595 : const char *secname, *oldsym;
11274 53595 : char *tmp;
11275 :
11276 : /* Unless we are outputting main CU, we may throw away empty ones. */
11277 53595 : 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 52302 : mark_dies (die);
11286 :
11287 52302 : 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 52302 : if (die == comp_unit_die ())
11293 104604 : abbrev_opt_start = vec_safe_length (abbrev_die_table);
11294 :
11295 52302 : build_abbrev_table (die, extern_map);
11296 :
11297 52302 : optimize_abbrev_table ();
11298 :
11299 52302 : delete extern_map;
11300 :
11301 : /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11302 104604 : next_die_offset = (dwo_id
11303 52304 : ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11304 53987 : : DWARF_COMPILE_UNIT_HEADER_SIZE);
11305 52302 : calc_die_sizes (die);
11306 :
11307 52302 : oldsym = die->die_id.die_symbol;
11308 52302 : 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 52302 : switch_to_section (debug_info_section);
11320 52302 : ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11321 52302 : 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 52302 : if ((flag_generate_lto || flag_generate_offload) && oldsym)
11327 : {
11328 : /* ??? No way to get visibility assembled without a decl. */
11329 1311 : tree decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
11330 : get_identifier (oldsym), char_type_node);
11331 1311 : TREE_PUBLIC (decl) = true;
11332 1311 : TREE_STATIC (decl) = true;
11333 1311 : DECL_ARTIFICIAL (decl) = true;
11334 1311 : DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
11335 1311 : DECL_VISIBILITY_SPECIFIED (decl) = true;
11336 1311 : 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 1311 : ASM_WEAKEN_LABEL (asm_out_file, oldsym);
11341 : #else
11342 : targetm.asm_out.globalize_label (asm_out_file, oldsym);
11343 : #endif
11344 1311 : ASM_OUTPUT_LABEL (asm_out_file, oldsym);
11345 : }
11346 :
11347 : /* Output debugging information. */
11348 104355 : output_compilation_unit_header (dwo_id
11349 : ? DW_UT_split_compile : DW_UT_compile);
11350 52302 : if (dwarf_version >= 5)
11351 : {
11352 50367 : 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 52302 : output_die (die);
11357 :
11358 : /* Leave the marks on the main CU, so we can check them in
11359 : output_pubnames. */
11360 52302 : if (oldsym)
11361 : {
11362 1311 : unmark_dies (die);
11363 1311 : 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 289268731 : want_pubnames (void)
11373 : {
11374 289268731 : if (debug_info_level <= DINFO_LEVEL_TERSE
11375 : /* Names and types go to the early debug part only. */
11376 289251566 : || in_lto_p)
11377 : return false;
11378 289250703 : if (debug_generate_pub_sections != -1)
11379 1449 : return debug_generate_pub_sections;
11380 289249254 : 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 52383 : add_AT_pubnames (dw_die_ref die)
11387 : {
11388 52383 : if (want_pubnames ())
11389 256 : add_AT_flag (die, DW_AT_GNU_pubnames, 1);
11390 52383 : }
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 208537380 : dwarf2_name (tree decl, int scope)
11564 : {
11565 208537380 : if (DECL_NAMELESS (decl))
11566 : return NULL;
11567 416916001 : 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 131023203 : add_pubname (tree decl, dw_die_ref die)
11584 : {
11585 131023203 : 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 157647735 : add_pubtype (tree decl, dw_die_ref die)
11620 : {
11621 157647735 : pubname_entry e;
11622 :
11623 157647735 : if (!want_pubnames ())
11624 157647421 : 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 52035 : output_pubtables (void)
11812 : {
11813 52035 : 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 50991 : output_aranges (void)
11832 : {
11833 50991 : unsigned i;
11834 50991 : unsigned long aranges_length = size_of_aranges ();
11835 :
11836 50991 : if (!XCOFF_DEBUGGING_INFO)
11837 : {
11838 50991 : 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 50991 : 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 50991 : dw2_asm_output_data (2, 2, "DWARF aranges version");
11847 50991 : 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 50742 : dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
11853 : debug_info_section,
11854 : "Offset of Compilation Unit Info");
11855 57325 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11856 50991 : dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11857 :
11858 : /* We need to align to twice the pointer size here. */
11859 69993 : if (DWARF_ARANGES_PAD_SIZE)
11860 : {
11861 : /* Pad using a 2 byte words so that padding is correct for any
11862 : pointer size. */
11863 50991 : dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11864 50989 : 2 * DWARF2_ADDR_SIZE);
11865 190977 : for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11866 50991 : 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 50991 : if (switch_text_ranges)
11875 : {
11876 : const char *prev_loc = text_section_label;
11877 : const char *loc;
11878 : unsigned idx;
11879 :
11880 30173 : FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
11881 970 : if (prev_loc)
11882 : {
11883 769 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11884 563 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, loc, prev_loc, "Length");
11885 563 : prev_loc = NULL;
11886 : }
11887 : else
11888 : prev_loc = loc;
11889 :
11890 29203 : if (prev_loc)
11891 : {
11892 32078 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11893 32078 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11894 : prev_loc, "Length");
11895 : }
11896 : }
11897 :
11898 50991 : if (switch_cold_ranges)
11899 : {
11900 : const char *prev_loc = cold_text_section_label;
11901 : const char *loc;
11902 : unsigned idx;
11903 :
11904 8792 : 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 8792 : if (prev_loc)
11915 : {
11916 9110 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11917 9110 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11918 : prev_loc, "Length");
11919 : }
11920 : }
11921 :
11922 50991 : if (have_multiple_function_sections)
11923 : {
11924 : unsigned fde_idx;
11925 : dw_fde_ref fde;
11926 :
11927 291531 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
11928 : {
11929 263129 : if (fde->ignored_debug)
11930 2920 : continue;
11931 260209 : if (!fde->in_std_section)
11932 : {
11933 198695 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
11934 : "Address");
11935 198695 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
11936 : fde->dw_fde_begin, "Length");
11937 : }
11938 260209 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11939 : {
11940 10663 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
11941 : "Address");
11942 10663 : 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 57325 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11950 57325 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11951 50991 : }
11952 :
11953 : /* Add a new entry to .debug_ranges. Return its index into
11954 : ranges_table vector. */
11955 :
11956 : static unsigned int
11957 10848693 : add_ranges_num (int num, bool maybe_new_sec)
11958 : {
11959 10848693 : dw_ranges r = { NULL, num, 0, maybe_new_sec, NULL, NULL };
11960 10848693 : vec_safe_push (ranges_table, r);
11961 10848693 : 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 10588637 : add_ranges (const_tree block, bool maybe_new_sec)
11970 : {
11971 15795576 : 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 3232085 : note_rnglist_head (unsigned int offset)
11979 : {
11980 3232085 : if (dwarf_version < 5 || (*ranges_table)[offset].label)
11981 : return;
11982 2695160 : (*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 260056 : add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11992 : bool *added, bool force_direct)
11993 : {
11994 260056 : unsigned int in_use = vec_safe_length (ranges_by_label);
11995 260056 : unsigned int offset;
11996 260056 : dw_ranges_by_label rbl = { begin, end };
11997 260056 : vec_safe_push (ranges_by_label, rbl);
11998 260056 : offset = add_ranges_num (-(int)in_use - 1, true);
11999 260056 : if (!*added)
12000 : {
12001 49916 : add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
12002 49916 : *added = true;
12003 49916 : note_rnglist_head (offset);
12004 49916 : if (dwarf_split_debug_info && force_direct)
12005 2 : (*ranges_table)[offset].idx = DW_RANGES_IDX_SKELETON;
12006 : }
12007 260056 : }
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 158833 : asm_outputs_debug_line_str (void)
12115 : {
12116 158833 : if (dwarf_version >= 5
12117 152873 : && ! output_asm_line_debug_info ()
12118 158839 : && 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 165531 : 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 2534130 : use_distinct_base_address_for_range (unsigned int i)
12135 : {
12136 2696149 : if (i >= vec_safe_length (ranges_table))
12137 : return false;
12138 :
12139 2534130 : 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 2534130 : 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 32622 : output_rnglists (unsigned generation, bool dwo)
12221 : {
12222 32622 : unsigned i;
12223 32622 : dw_ranges *r;
12224 32622 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
12225 32622 : char l2[MAX_ARTIFICIAL_LABEL_BYTES];
12226 32622 : char basebuf[MAX_ARTIFICIAL_LABEL_BYTES];
12227 :
12228 32622 : if (dwo)
12229 3 : switch_to_section (debug_ranges_dwo_section);
12230 : else
12231 : {
12232 32619 : switch_to_section (debug_ranges_section);
12233 32619 : 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 32622 : ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_RANGES_SECTION_LABEL,
12238 : 2 + 2 * dwo + generation * 6);
12239 32622 : ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_RANGES_SECTION_LABEL,
12240 : 3 + 2 * dwo + generation * 6);
12241 32622 : 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 32622 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
12246 : "Length of Range Lists");
12247 32622 : ASM_OUTPUT_LABEL (asm_out_file, l1);
12248 32622 : output_dwarf_version ();
12249 37127 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
12250 32622 : 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 32622 : dw2_asm_output_data (4, dwo ? rnglist_idx : 0,
12258 : "Offset Entry Count");
12259 32622 : 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 10877259 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12273 : {
12274 10844637 : int block_num = r->num;
12275 :
12276 10844637 : if (r->label)
12277 : {
12278 2695163 : 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 2695159 : ASM_OUTPUT_LABEL (asm_out_file, r->label);
12286 2695159 : lab = r->label;
12287 : }
12288 10844633 : if (skipping)
12289 : {
12290 8 : if (block_num == 0)
12291 4 : skipping = false;
12292 8 : continue;
12293 : }
12294 10844625 : if (HAVE_AS_LEB128 && (r->label || r->maybe_new_sec))
12295 3038315 : base = NULL;
12296 10844625 : if (block_num > 0)
12297 : {
12298 7896076 : char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12299 7896076 : char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12300 :
12301 7896076 : ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12302 7896076 : ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12303 :
12304 7896076 : 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 7896076 : if (!have_multiple_function_sections)
12310 : {
12311 831621 : dw2_asm_output_data (1, DW_RLE_offset_pair,
12312 : "DW_RLE_offset_pair (%s)", lab);
12313 831621 : dw2_asm_output_delta_uleb128 (blabel, text_section_label,
12314 : "Range begin address (%s)", lab);
12315 831621 : dw2_asm_output_delta_uleb128 (elabel, text_section_label,
12316 : "Range end address (%s)", lab);
12317 7734057 : continue;
12318 : }
12319 7064455 : if (base == NULL && use_distinct_base_address_for_range (i + 1))
12320 : {
12321 2372111 : 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 2372111 : dw2_asm_output_data (1, DW_RLE_base_address,
12332 : "DW_RLE_base_address (%s)", lab);
12333 2471651 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12334 : "Base address (%s)", lab);
12335 : }
12336 2372111 : strcpy (basebuf, blabel);
12337 2372111 : base = basebuf;
12338 : }
12339 7064455 : if (base)
12340 : {
12341 6902436 : dw2_asm_output_data (1, DW_RLE_offset_pair,
12342 : "DW_RLE_offset_pair (%s)", lab);
12343 6902436 : dw2_asm_output_delta_uleb128 (blabel, base,
12344 : "Range begin address (%s)", lab);
12345 6902436 : dw2_asm_output_delta_uleb128 (elabel, base,
12346 : "Range end address (%s)", lab);
12347 6902436 : continue;
12348 : }
12349 162019 : 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 162019 : dw2_asm_output_data (1, DW_RLE_start_length,
12360 : "DW_RLE_start_length (%s)", lab);
12361 165936 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12362 : "Range begin address (%s)", lab);
12363 : }
12364 162019 : 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 2948549 : else if (block_num < 0)
12391 : {
12392 258791 : int lab_idx = - block_num - 1;
12393 258791 : const char *blabel = (*ranges_by_label)[lab_idx].begin;
12394 258791 : const char *elabel = (*ranges_by_label)[lab_idx].end;
12395 :
12396 258791 : if (!have_multiple_function_sections)
12397 0 : gcc_unreachable ();
12398 258791 : if (HAVE_AS_LEB128)
12399 : {
12400 258791 : 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 258783 : dw2_asm_output_data (1, DW_RLE_start_length,
12411 : "DW_RLE_start_length (%s)", lab);
12412 274018 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12413 : "Range begin address (%s)", lab);
12414 : }
12415 258791 : 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 2689758 : dw2_asm_output_data (1, DW_RLE_end_of_list,
12441 : "DW_RLE_end_of_list (%s)", lab);
12442 : }
12443 32622 : ASM_OUTPUT_LABEL (asm_out_file, l2);
12444 32622 : 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 96236 : file_info_cmp (const void *p1, const void *p2)
12473 : {
12474 96236 : const struct file_info *const s1 = (const struct file_info *) p1;
12475 96236 : const struct file_info *const s2 = (const struct file_info *) p2;
12476 96236 : const unsigned char *cp1;
12477 96236 : 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 96236 : if ((s1->path == s1->fname || s2->path == s2->fname))
12487 1608 : 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 4168677 : while (1)
12493 : {
12494 4168677 : ++cp1;
12495 4168677 : ++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 4168677 : if ((cp1 == (const unsigned char *) s1->fname)
12499 4132863 : || (cp2 == (const unsigned char *) s2->fname))
12500 51789 : return ((cp1 == (const unsigned char *) s1->fname)
12501 51789 : - (cp2 == (const unsigned char *) s2->fname));
12502 :
12503 : /* Character of current path component the same? */
12504 4116888 : else if (*cp1 != *cp2)
12505 42839 : 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 9070 : file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
12520 : {
12521 9070 : struct dwarf_file_data *d = *slot;
12522 9070 : struct file_info *fi;
12523 9070 : const char *f;
12524 :
12525 9070 : gcc_assert (fnad->max_files >= d->emitted_number);
12526 :
12527 9070 : if (! d->emitted_number)
12528 : return 1;
12529 :
12530 4493 : gcc_assert (fnad->max_files != fnad->used_files);
12531 :
12532 4493 : fi = fnad->files + fnad->used_files++;
12533 :
12534 4493 : f = d->filename;
12535 :
12536 : /* Skip all leading "./". */
12537 4493 : while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12538 0 : f += 2;
12539 :
12540 : /* Create a new array entry. */
12541 4493 : fi->path = f;
12542 4493 : fi->length = strlen (f);
12543 4493 : fi->file_idx = d;
12544 :
12545 : /* Search for the file name part. */
12546 4493 : 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 4493 : fi->fname = f == NULL ? fi->path : f + 1;
12560 4493 : 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 9185 : output_line_string (enum dwarf_form form, const char *str,
12569 : const char *entry_kind, unsigned int idx)
12570 : {
12571 9185 : 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 8622 : case DW_FORM_line_strp:
12577 8622 : if (!debug_line_str_hash)
12578 0 : debug_line_str_hash
12579 0 : = hash_table<indirect_string_hasher>::create_ggc (10);
12580 :
12581 8622 : struct indirect_string_node *node;
12582 8622 : node = find_AT_string_in_table (str, debug_line_str_hash);
12583 8622 : set_indirect_string (node);
12584 8622 : node->form = form;
12585 8622 : dw2_asm_output_offset (dwarf_offset_size, node->label,
12586 : debug_line_str_section, "%s: %#x: \"%s\"",
12587 : entry_kind, 0, node->str);
12588 8622 : break;
12589 0 : default:
12590 0 : gcc_unreachable ();
12591 : }
12592 9185 : }
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 1566 : output_file_names (void)
12600 : {
12601 1566 : struct file_name_acquire_data fnad;
12602 1566 : int numfiles;
12603 1566 : struct file_info *files;
12604 1566 : struct dir_info *dirs;
12605 1566 : int *saved;
12606 1566 : int *savehere;
12607 1566 : int *backmap;
12608 1566 : int ndirs;
12609 1566 : int idx_offset;
12610 1566 : int i;
12611 :
12612 1566 : 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 1549 : numfiles = last_emitted_file->emitted_number;
12670 :
12671 : /* Allocate the various arrays we need. */
12672 1549 : files = XALLOCAVEC (struct file_info, numfiles);
12673 1549 : dirs = XALLOCAVEC (struct dir_info, numfiles);
12674 :
12675 1549 : fnad.files = files;
12676 1549 : fnad.used_files = 0;
12677 1549 : fnad.max_files = numfiles;
12678 10619 : file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
12679 1549 : gcc_assert (fnad.used_files == fnad.max_files);
12680 :
12681 1549 : qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12682 :
12683 : /* Find all the different directories used. */
12684 1549 : dirs[0].path = files[0].path;
12685 1549 : dirs[0].length = files[0].fname - files[0].path;
12686 1549 : dirs[0].prefix = -1;
12687 1549 : dirs[0].count = 1;
12688 1549 : dirs[0].dir_idx = 0;
12689 1549 : files[0].dir_idx = 0;
12690 1549 : ndirs = 1;
12691 :
12692 4493 : for (i = 1; i < numfiles; i++)
12693 2944 : if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12694 2043 : && memcmp (dirs[ndirs - 1].path, files[i].path,
12695 : dirs[ndirs - 1].length) == 0)
12696 : {
12697 : /* Same directory as last entry. */
12698 2040 : files[i].dir_idx = ndirs - 1;
12699 2040 : ++dirs[ndirs - 1].count;
12700 : }
12701 : else
12702 : {
12703 904 : int j;
12704 :
12705 : /* This is a new directory. */
12706 904 : dirs[ndirs].path = files[i].path;
12707 904 : dirs[ndirs].length = files[i].fname - files[i].path;
12708 904 : dirs[ndirs].count = 1;
12709 904 : dirs[ndirs].dir_idx = ndirs;
12710 904 : files[i].dir_idx = ndirs;
12711 :
12712 : /* Search for a prefix. */
12713 904 : dirs[ndirs].prefix = -1;
12714 4657 : for (j = 0; j < ndirs; j++)
12715 3753 : if (dirs[j].length < dirs[ndirs].length
12716 1324 : && dirs[j].length > 1
12717 907 : && (dirs[ndirs].prefix == -1
12718 0 : || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12719 907 : && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12720 0 : dirs[ndirs].prefix = j;
12721 :
12722 904 : ++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 1549 : saved = XALLOCAVEC (int, ndirs);
12732 1549 : savehere = XALLOCAVEC (int, ndirs);
12733 :
12734 1549 : memset (saved, '\0', ndirs * sizeof (saved[0]));
12735 4002 : for (i = 0; i < ndirs; i++)
12736 : {
12737 2453 : int j;
12738 2453 : 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 2453 : savehere[i] = dirs[i].length;
12743 2453 : total = (savehere[i] - saved[i]) * dirs[i].count;
12744 :
12745 6206 : for (j = i + 1; j < ndirs; j++)
12746 : {
12747 3753 : savehere[j] = 0;
12748 3753 : if (saved[j] < dirs[i].length)
12749 : {
12750 : /* Determine whether the dirs[i] path is a prefix of the
12751 : dirs[j] path. */
12752 3336 : int k;
12753 :
12754 3336 : k = dirs[j].prefix;
12755 3336 : while (k != -1 && k != (int) i)
12756 0 : k = dirs[k].prefix;
12757 :
12758 3336 : 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 2453 : if (total > dirs[i].length + 1)
12772 : {
12773 : /* It's worthwhile adding. */
12774 2146 : for (j = i; j < ndirs; j++)
12775 1733 : if (savehere[j] > 0)
12776 : {
12777 : /* Remember how much we saved for this directory so far. */
12778 413 : saved[j] = savehere[j];
12779 :
12780 : /* Remember the prefix directory. */
12781 413 : dirs[j].dir_idx = i;
12782 : }
12783 : }
12784 : }
12785 :
12786 : /* Emit the directory name table. */
12787 1549 : idx_offset = dirs[0].length > 0 ? 1 : 0;
12788 1549 : enum dwarf_form str_form = DW_FORM_string;
12789 1549 : enum dwarf_form idx_form = DW_FORM_udata;
12790 1549 : if (dwarf_version >= 5)
12791 : {
12792 1498 : const char *comp_dir = comp_dir_string ();
12793 1498 : if (comp_dir == NULL)
12794 0 : comp_dir = "";
12795 1498 : dw2_asm_output_data (1, 1, "Directory entry format count");
12796 1498 : if (DWARF5_USE_DEBUG_LINE_STR)
12797 1498 : str_form = DW_FORM_line_strp;
12798 1498 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12799 1498 : dw2_asm_output_data_uleb128 (str_form, "%s",
12800 : get_DW_FORM_name (str_form));
12801 1498 : dw2_asm_output_data_uleb128 (ndirs + idx_offset, "Directories count");
12802 1498 : 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 1253 : output_line_string (str_form, comp_dir, "Directory Entry", 0);
12814 3163 : for (i = 1 - idx_offset; i < ndirs; i++)
12815 : {
12816 1910 : const char *str
12817 3820 : = ggc_alloc_string (dirs[i].path,
12818 1910 : dirs[i].length
12819 : - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR);
12820 1910 : output_line_string (str_form, str, "Directory Entry",
12821 1910 : (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 1549 : backmap = XALLOCAVEC (int, numfiles);
12840 6042 : for (i = 0; i < numfiles; i++)
12841 4493 : backmap[files[i].file_idx->emitted_number - 1] = i;
12842 :
12843 1549 : if (dwarf_version >= 5)
12844 : {
12845 1498 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
12846 1498 : 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 1498 : 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 1498 : 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 1498 : dw2_asm_output_data (1, 2, "File name entry format count");
12878 : #endif
12879 1498 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12880 1498 : dw2_asm_output_data_uleb128 (str_form, "%s",
12881 : get_DW_FORM_name (str_form));
12882 1498 : dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
12883 : "DW_LNCT_directory_index");
12884 1498 : 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 1498 : dw2_asm_output_data_uleb128 (numfiles + 1, "File names count");
12893 :
12894 1498 : output_line_string (str_form, filename0, "File Entry", 0);
12895 :
12896 : /* Include directory index. */
12897 1498 : if (idx_form != DW_FORM_udata)
12898 1498 : 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 6042 : for (i = 0; i < numfiles; i++)
12911 : {
12912 4493 : int file_idx = backmap[i];
12913 4493 : 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 4493 : output_line_string (str_form,
12953 4493 : files[file_idx].path + dirs[dir_idx].length,
12954 4493 : "File Entry", (unsigned) i + 1);
12955 :
12956 : /* Include directory index. */
12957 4493 : if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
12958 4426 : dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
12959 4426 : dir_idx + idx_offset, NULL);
12960 : else
12961 67 : dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12962 :
12963 4493 : if (dwarf_version >= 5)
12964 4426 : 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 1549 : 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 1566 : output_line_info (bool prologue_only)
13138 : {
13139 1566 : char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
13140 1566 : char p1[MAX_ARTIFICIAL_LABEL_BYTES], p2[MAX_ARTIFICIAL_LABEL_BYTES];
13141 1566 : bool saw_one = false;
13142 1566 : int opc;
13143 :
13144 1566 : ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL,
13145 : output_line_info_generation);
13146 1566 : ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL,
13147 : output_line_info_generation);
13148 1566 : ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL,
13149 : output_line_info_generation);
13150 1566 : ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL,
13151 : output_line_info_generation++);
13152 :
13153 1566 : if (!XCOFF_DEBUGGING_INFO)
13154 : {
13155 1566 : 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 1566 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
13159 : "Length of Source Line Info");
13160 : }
13161 :
13162 1566 : ASM_OUTPUT_LABEL (asm_out_file, l1);
13163 :
13164 1566 : output_dwarf_version ();
13165 1566 : if (dwarf_version >= 5)
13166 : {
13167 1516 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
13168 1515 : dw2_asm_output_data (1, 0, "Segment Size");
13169 : }
13170 1566 : dw2_asm_output_delta (dwarf_offset_size, p2, p1, "Prolog Length");
13171 1566 : 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 1566 : dw2_asm_output_data (1, 1, "Minimum Instruction Length");
13182 :
13183 1566 : if (dwarf_version >= 4)
13184 1516 : dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
13185 : "Maximum Operations Per Instruction");
13186 1566 : dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
13187 : "Default is_stmt_start flag");
13188 1566 : dw2_asm_output_data (1, DWARF_LINE_BASE,
13189 : "Line Base Value (Special Opcodes)");
13190 1566 : dw2_asm_output_data (1, DWARF_LINE_RANGE,
13191 : "Line Range Value (Special Opcodes)");
13192 1566 : dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
13193 : "Special Opcode Base");
13194 :
13195 20358 : for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
13196 : {
13197 18792 : int n_op_args;
13198 18792 : 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 9396 : default:
13209 9396 : n_op_args = 0;
13210 9396 : break;
13211 : }
13212 :
13213 18792 : 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 1566 : output_file_names ();
13219 1566 : ASM_OUTPUT_LABEL (asm_out_file, p2);
13220 1566 : if (prologue_only)
13221 : {
13222 : /* Output the marker for the end of the line number info. */
13223 1560 : ASM_OUTPUT_LABEL (asm_out_file, l2);
13224 1560 : 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 514438961 : 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 589132 : base_type_die (tree type, bool reverse)
13274 : {
13275 589132 : dw_die_ref base_type_result;
13276 589132 : enum dwarf_type encoding;
13277 589132 : bool fpt_used = false;
13278 589132 : struct fixed_point_type_info fpt_info;
13279 589132 : 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 589132 : if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
13284 0 : type = TREE_TYPE (type);
13285 :
13286 589132 : switch (TREE_CODE (type))
13287 : {
13288 380406 : case INTEGER_TYPE:
13289 3387 : if ((dwarf_version >= 4 || !dwarf_strict)
13290 380406 : && TYPE_NAME (type)
13291 379144 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13292 370341 : && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type))
13293 750747 : && DECL_NAME (TYPE_NAME (type)))
13294 : {
13295 370341 : const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
13296 370341 : if (strcmp (name, "char16_t") == 0
13297 358994 : || strcmp (name, "char8_t") == 0
13298 348059 : || strcmp (name, "char32_t") == 0)
13299 : {
13300 : encoding = DW_ATE_UTF;
13301 : break;
13302 : }
13303 : }
13304 346777 : if ((dwarf_version >= 3 || !dwarf_strict)
13305 346777 : && 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 346777 : if (TYPE_STRING_FLAG (type))
13318 : {
13319 595 : if ((dwarf_version >= 4 || !dwarf_strict)
13320 78734 : && is_rust ()
13321 78859 : && int_size_in_bytes (type) == 4)
13322 : encoding = DW_ATE_UTF;
13323 78723 : else if (TYPE_UNSIGNED (type))
13324 : encoding = DW_ATE_unsigned_char;
13325 : else
13326 48698 : encoding = DW_ATE_signed_char;
13327 : }
13328 268043 : else if (TYPE_UNSIGNED (type))
13329 : encoding = DW_ATE_unsigned;
13330 : else
13331 147495 : encoding = DW_ATE_signed;
13332 :
13333 346777 : if (!dwarf_strict
13334 346773 : && lang_hooks.types.get_type_bias)
13335 0 : type_bias = lang_hooks.types.get_type_bias (type);
13336 : break;
13337 :
13338 143925 : case REAL_TYPE:
13339 143925 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
13340 : {
13341 861 : 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 45136 : case COMPLEX_TYPE:
13362 45136 : 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 41 : case BITINT_TYPE:
13374 : /* C23 _BitInt(N). */
13375 41 : if (TYPE_UNSIGNED (type))
13376 : encoding = DW_ATE_unsigned;
13377 : else
13378 25 : 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 589132 : base_type_result = new_die_raw (DW_TAG_base_type);
13387 :
13388 589132 : add_AT_unsigned (base_type_result, DW_AT_byte_size,
13389 589132 : int_size_in_bytes (type));
13390 589132 : add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
13391 589132 : if (TREE_CODE (type) == BITINT_TYPE)
13392 41 : add_AT_unsigned (base_type_result, DW_AT_bit_size, TYPE_PRECISION (type));
13393 :
13394 589132 : 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 589132 : add_alignment_attribute (base_type_result, type);
13399 :
13400 589132 : 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 589132 : 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 589132 : 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 147407 : is_cxx_auto (tree type)
13453 : {
13454 147407 : if (is_cxx ())
13455 : {
13456 147407 : tree name = TYPE_IDENTIFIER (type);
13457 147407 : if (name == get_identifier ("auto")
13458 147407 : || name == get_identifier ("decltype(auto)"))
13459 147401 : 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 5665937 : is_base_type (tree type)
13469 : {
13470 5665937 : 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 46670720 : simple_type_size_in_bits (const_tree type)
13515 : {
13516 46670720 : if (TREE_CODE (type) == ERROR_MARK)
13517 0 : return BITS_PER_WORD;
13518 46670720 : else if (TYPE_SIZE (type) == NULL_TREE)
13519 : return 0;
13520 46670720 : else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
13521 46670720 : 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 979482 : offset_int_type_size_in_bits (const_tree type)
13530 : {
13531 979482 : if (TREE_CODE (type) == ERROR_MARK)
13532 0 : return BITS_PER_WORD;
13533 979482 : else if (TYPE_SIZE (type) == NULL_TREE)
13534 0 : return 0;
13535 979482 : else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
13536 979482 : 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 135099123 : decl_quals (const_tree decl)
13585 : {
13586 135099123 : 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 62250163 : && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
13591 135099123 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
13592 135099123 : | (TREE_THIS_VOLATILE (decl)
13593 135099123 : ? 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 13264654 : get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
13602 : {
13603 13264654 : tree t;
13604 13264654 : int best_rank = 0, best_qual = 0, max_rank;
13605 :
13606 13264654 : type_quals &= qual_mask;
13607 13264654 : max_rank = popcount_hwi (type_quals) - 1;
13608 :
13609 14025984 : for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
13610 761330 : t = TYPE_NEXT_VARIANT (t))
13611 : {
13612 761330 : int q = TYPE_QUALS (t) & qual_mask;
13613 :
13614 761293 : if ((q & type_quals) == q && q != type_quals
13615 1465154 : && check_base_type (t, type))
13616 : {
13617 486130 : int rank = popcount_hwi (q);
13618 :
13619 486130 : if (rank > best_rank)
13620 : {
13621 761330 : best_rank = rank;
13622 761330 : best_qual = q;
13623 : }
13624 : }
13625 : }
13626 :
13627 13264654 : 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 22365337 : qualified_die_p (dw_die_ref die, int *mask, unsigned int depth)
13646 : {
13647 22365337 : unsigned int i;
13648 103754081 : for (i = 0; i < dwarf_qual_info_size; i++)
13649 83625978 : if (die->die_tag == dwarf_qual_info[i].t)
13650 : break;
13651 22365337 : if (i == dwarf_qual_info_size)
13652 : return NULL;
13653 22366855 : if (vec_safe_length (die->die_attr) != 1)
13654 : return NULL;
13655 2226209 : dw_die_ref type = get_AT_ref (die, DW_AT_type);
13656 2226209 : if (type == NULL || type->die_parent != die->die_parent)
13657 : return NULL;
13658 2224691 : *mask |= dwarf_qual_info[i].q;
13659 2224691 : if (depth)
13660 : {
13661 2224691 : dw_die_ref ret = qualified_die_p (type, mask, depth - 1);
13662 2224691 : 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 588835 : long_double_as_float128 (tree type)
13676 : {
13677 588835 : if (type != long_double_type_node
13678 569692 : && type != complex_long_double_type_node)
13679 : return NULL_TREE;
13680 :
13681 31583 : machine_mode mode, fmode;
13682 31583 : if (TREE_CODE (type) == COMPLEX_TYPE)
13683 12440 : mode = TYPE_MODE (TREE_TYPE (type));
13684 : else
13685 19143 : mode = TYPE_MODE (type);
13686 223408 : if (known_eq (GET_MODE_SIZE (mode), 16) && !MODE_COMPOSITE_P (mode))
13687 186949 : FOR_EACH_MODE_IN_CLASS (fmode, MODE_FLOAT)
13688 160242 : if (known_eq (GET_MODE_SIZE (fmode), 16)
13689 480726 : && 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 139120697 : maybe_gen_btf_type_tag_dies (tree t, dw_die_ref target)
13867 : {
13868 139120697 : if (t == NULL_TREE || !TYPE_P (t) || !target)
13869 : return;
13870 :
13871 139120697 : tree attr = lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (t));
13872 139120697 : 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 556686891 : maybe_gen_btf_decl_tag_dies (tree t, dw_die_ref target)
13883 : {
13884 556686891 : if (t == NULL_TREE || !DECL_P (t) || !target)
13885 : return;
13886 :
13887 210359311 : tree attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t));
13888 210359311 : 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 513849829 : modified_type_die (tree type, int cv_quals, tree type_attrs, bool reverse,
13902 : dw_die_ref context_die)
13903 : {
13904 513849829 : enum tree_code code = TREE_CODE (type);
13905 513849829 : dw_die_ref mod_type_die;
13906 513849829 : dw_die_ref sub_die = NULL;
13907 513849829 : tree item_type = NULL;
13908 513849829 : tree qualified_type;
13909 513849829 : tree name, low, high;
13910 513849829 : tree btf_tags;
13911 513849829 : dw_die_ref mod_scope;
13912 513849829 : struct array_descr_info info;
13913 : /* Only these cv-qualifiers are currently handled. */
13914 513849829 : 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 513849829 : const bool reverse_type
13918 513850041 : = need_endianity_attribute_p (reverse)
13919 212 : && (is_base_type (type)
13920 45 : || (TREE_CODE (type) == ENUMERAL_TYPE && !dwarf_strict));
13921 :
13922 513849829 : if (code == ERROR_MARK)
13923 : return NULL;
13924 :
13925 513849829 : if (lang_hooks.types.get_debug_type)
13926 : {
13927 505077996 : tree debug_type = lang_hooks.types.get_debug_type (type);
13928 :
13929 505077996 : if (debug_type != NULL_TREE && debug_type != type)
13930 227252 : return modified_type_die (debug_type, cv_quals, type_attrs, reverse,
13931 227252 : context_die);
13932 : }
13933 :
13934 513622577 : 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 513622577 : if (dwarf_version < 3)
13940 55471 : cv_quals &= ~TYPE_QUAL_RESTRICT;
13941 :
13942 : /* Likewise for DW_TAG_atomic_type for DWARFv5. */
13943 513622577 : if (dwarf_version < 5)
13944 57304 : cv_quals &= ~TYPE_QUAL_ATOMIC;
13945 :
13946 : /* See if we already have the appropriately qualified variant of
13947 : this type. */
13948 513622577 : qualified_type = get_qualified_type (type, cv_quals);
13949 :
13950 513622577 : if (qualified_type == sizetype)
13951 : {
13952 : /* Try not to expose the internal sizetype type's name. */
13953 931298 : if (TYPE_NAME (qualified_type)
13954 931298 : && 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 931298 : else if (qualified_type == sizetype
13966 931298 : && TREE_CODE (sizetype) == TREE_CODE (size_type_node)
13967 931298 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (size_type_node)
13968 931298 : && TYPE_UNSIGNED (sizetype) == TYPE_UNSIGNED (size_type_node))
13969 : qualified_type = size_type_node;
13970 931298 : if (type == sizetype)
13971 931298 : type = qualified_type;
13972 : }
13973 :
13974 : /* If we do, then we can just use its DIE, if it exists. */
13975 513622577 : if (qualified_type)
13976 : {
13977 513406099 : 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 513406099 : if (mod_type_die
13983 513406099 : && (!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 455987914 : return mod_type_die;
13987 : }
13988 :
13989 57418185 : name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13990 :
13991 : /* Handle C typedef types. */
13992 57418185 : if (name
13993 24824113 : && TREE_CODE (name) == TYPE_DECL
13994 24772711 : && DECL_ORIGINAL_TYPE (name)
13995 67460156 : && !DECL_ARTIFICIAL (name))
13996 : {
13997 10030593 : tree dtype = TREE_TYPE (name);
13998 :
13999 : /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
14000 10030593 : if (qualified_type == dtype && !reverse_type)
14001 : {
14002 7115045 : 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 7115045 : 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 7115045 : gen_type_die (qualified_type, context_die);
14013 7115045 : return lookup_type_die (qualified_type);
14014 : }
14015 : else
14016 : {
14017 2915548 : int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
14018 2915548 : dquals &= cv_qual_mask;
14019 2915548 : if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
14020 2915548 : || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
14021 : {
14022 13234 : tree tags = lookup_attribute ("btf_type_tag", type_attrs);
14023 13234 : tree dtags = lookup_attribute ("btf_type_tag",
14024 13234 : TYPE_ATTRIBUTES (dtype));
14025 13234 : 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 13232 : return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals,
14049 13232 : type_attrs, reverse, context_die);
14050 : }
14051 : /* Else cv-qualified version of named type; fall through. */
14052 : }
14053 : }
14054 :
14055 50506384 : mod_scope = scope_die_for (type, context_die);
14056 :
14057 50506384 : if (cv_quals)
14058 : {
14059 13264654 : int sub_quals = 0, first_quals = 0;
14060 13264654 : unsigned i;
14061 13264654 : 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 13264654 : sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
14067 : cv_qual_mask);
14068 13264654 : 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 13264654 : mod_type_die = modified_type_die (type, sub_quals, type_attrs,
14085 : reverse, context_die);
14086 13264654 : 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 12964523 : unsigned int count = 0;
14096 12964523 : first = qualified_die_p (mod_type_die, &first_quals,
14097 : dwarf_qual_info_size);
14098 12964523 : if (first == NULL)
14099 12739476 : first = mod_type_die;
14100 12964523 : gcc_assert ((first_quals & ~sub_quals) == 0);
14101 : for (count = 0, last = first;
14102 13939264 : count < (1U << dwarf_qual_info_size);
14103 974741 : count++, last = last->die_sib)
14104 : {
14105 13939264 : int quals = 0;
14106 13939264 : if (last == mod_scope->die_child)
14107 : break;
14108 6187518 : if (qualified_die_p (last->die_sib, &quals, dwarf_qual_info_size)
14109 : != first)
14110 : break;
14111 : }
14112 : }
14113 :
14114 66323270 : for (i = 0; i < dwarf_qual_info_size; i++)
14115 53058616 : if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
14116 : {
14117 13278649 : dw_die_ref d;
14118 13278649 : if (first && first != last)
14119 : {
14120 754783 : for (d = first->die_sib; ; d = d->die_sib)
14121 : {
14122 988605 : int quals = 0;
14123 988605 : qualified_die_p (d, &quals, dwarf_qual_info_size);
14124 988605 : if (quals == (first_quals | dwarf_qual_info[i].q))
14125 : break;
14126 890973 : if (d == last)
14127 : {
14128 : d = NULL;
14129 : break;
14130 : }
14131 233822 : }
14132 754783 : if (d)
14133 : {
14134 97632 : mod_type_die = d;
14135 97632 : continue;
14136 : }
14137 : }
14138 13181017 : if (first)
14139 : {
14140 12880886 : d = new_die_raw (dwarf_qual_info[i].t);
14141 12880886 : add_child_die_after (mod_scope, d, last);
14142 12880886 : last = d;
14143 : }
14144 : else
14145 300131 : d = new_die (dwarf_qual_info[i].t, mod_scope, type);
14146 13181017 : if (mod_type_die)
14147 13152461 : add_AT_die_ref (d, DW_AT_type, mod_type_die);
14148 13181017 : mod_type_die = d;
14149 13181017 : first_quals |= dwarf_qual_info[i].q;
14150 : }
14151 : }
14152 37241730 : else if (type_attrs
14153 37241730 : && (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 37241701 : else if (code == POINTER_TYPE || code == REFERENCE_TYPE)
14163 : {
14164 31405109 : dwarf_tag tag = DW_TAG_pointer_type;
14165 31405109 : if (code == REFERENCE_TYPE)
14166 : {
14167 16360687 : 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 31405109 : mod_type_die = new_die (tag, mod_scope, type);
14173 :
14174 31405109 : add_AT_unsigned (mod_type_die, DW_AT_byte_size,
14175 31405109 : simple_type_size_in_bits (type) / BITS_PER_UNIT);
14176 31405109 : add_alignment_attribute (mod_type_die, type);
14177 31405109 : item_type = TREE_TYPE (type);
14178 :
14179 31405109 : addr_space_t as = TYPE_ADDR_SPACE (item_type);
14180 31405109 : 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 5836592 : else if (code == ARRAY_TYPE
14198 5836592 : || (lang_hooks.types.get_array_descr_info
14199 21875 : && lang_hooks.types.get_array_descr_info (type, &info)))
14200 : {
14201 170849 : gen_type_die (type, mod_scope);
14202 170849 : return lookup_type_die (type);
14203 : }
14204 5665743 : else if (code == INTEGER_TYPE
14205 380127 : && TREE_TYPE (type) != NULL_TREE
14206 5665761 : && 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 5665725 : 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 588835 : 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 588835 : mod_type_die = base_type_die (type, reverse);
14245 :
14246 : /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
14247 588835 : 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 588778 : add_child_die (mod_scope, mod_type_die);
14255 :
14256 588835 : 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 5076890 : 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 5076888 : 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 5076888 : 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 244406 : tree main = TYPE_MAIN_VARIANT (type);
14285 266684 : for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
14286 266672 : if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
14287 266509 : && check_base_type (t, main)
14288 523565 : && check_lang_type (t, type))
14289 244394 : 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 4832482 : else if (code == VECTOR_TYPE)
14295 19568 : return lookup_type_die (type);
14296 : else
14297 4812914 : 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 45258616 : if (name
14306 45258616 : && ((TREE_CODE (name) != TYPE_DECL
14307 17486 : && (qualified_type == TYPE_MAIN_VARIANT (type)
14308 4443 : || (cv_quals == TYPE_UNQUALIFIED)))
14309 13019399 : || (TREE_CODE (name) == TYPE_DECL
14310 13014956 : && DECL_NAME (name)
14311 13014921 : && !DECL_NAMELESS (name)
14312 13014044 : && (TREE_TYPE (name) == qualified_type
14313 12428031 : || (lang_hooks.types.get_debug_type
14314 12369623 : && (lang_hooks.types.get_debug_type (TREE_TYPE (name))
14315 : == qualified_type))))))
14316 : {
14317 599056 : 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 586013 : name = DECL_NAME (name);
14322 599056 : add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
14323 : }
14324 44659560 : else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
14325 : {
14326 5606 : if (TREE_CODE (type) == BITINT_TYPE)
14327 : {
14328 41 : char name_buf[sizeof ("unsigned _BitInt(2147483647)")];
14329 164 : snprintf (name_buf, sizeof (name_buf),
14330 41 : "%s_BitInt(%d)", TYPE_UNSIGNED (type) ? "unsigned " : "",
14331 41 : TYPE_PRECISION (type));
14332 41 : add_name_attribute (mod_type_die, name_buf);
14333 : }
14334 : else
14335 : {
14336 : /* This probably indicates a bug. */
14337 5565 : name = TYPE_IDENTIFIER (type);
14338 6579 : add_name_attribute (mod_type_die,
14339 : name
14340 1014 : ? IDENTIFIER_POINTER (name) : "__unknown__");
14341 : }
14342 : }
14343 :
14344 45258616 : if (qualified_type && !reverse_type)
14345 45042131 : equate_type_number_to_die (qualified_type, mod_type_die);
14346 :
14347 45258616 : 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 94215381 : sub_die = modified_type_die (item_type,
14353 31405127 : TYPE_QUALS_NO_ADDR_SPACE (item_type),
14354 31405127 : TYPE_ATTRIBUTES (item_type),
14355 : reverse, context_die);
14356 :
14357 31405127 : if (sub_die != NULL)
14358 31371661 : add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
14359 :
14360 45258616 : add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
14361 45258616 : 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 141177142 : gen_generic_params_dies (tree t)
14373 : {
14374 141177142 : tree parms, args;
14375 141177142 : int parms_num, i;
14376 141177142 : dw_die_ref die = NULL;
14377 141177142 : int non_default;
14378 :
14379 141177142 : if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
14380 : return;
14381 :
14382 141177142 : if (TYPE_P (t))
14383 42766576 : die = lookup_type_die (t);
14384 98410566 : else if (DECL_P (t))
14385 98410566 : die = lookup_decl_die (t);
14386 :
14387 141177142 : gcc_assert (die);
14388 :
14389 141177142 : parms = lang_hooks.get_innermost_generic_parms (t);
14390 141177142 : 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 43645354 : parms_num = TREE_VEC_LENGTH (parms);
14396 43645354 : args = lang_hooks.get_innermost_generic_args (t);
14397 43645354 : if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
14398 43645085 : non_default = int_cst_value (TREE_CHAIN (args));
14399 : else
14400 269 : non_default = TREE_VEC_LENGTH (args);
14401 110900640 : for (i = 0; i < parms_num; i++)
14402 : {
14403 67255286 : tree parm, arg, arg_pack_elems;
14404 67255286 : dw_die_ref parm_die;
14405 :
14406 67255286 : parm = TREE_VEC_ELT (parms, i);
14407 67255286 : arg = TREE_VEC_ELT (args, i);
14408 67255286 : arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
14409 134510572 : gcc_assert (parm && TREE_VALUE (parm) && arg);
14410 :
14411 67255286 : 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 67255286 : if (arg_pack_elems)
14419 5361004 : parm_die = template_parameter_pack_die (TREE_VALUE (parm),
14420 : arg_pack_elems,
14421 : die);
14422 : else
14423 61894282 : parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
14424 : true /* emit name */, die);
14425 67255286 : if (i >= non_default)
14426 924457 : 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 72687791 : generic_parameter_die (tree parm, tree arg,
14442 : bool emit_name_p,
14443 : dw_die_ref parent_die)
14444 : {
14445 72687791 : dw_die_ref tmpl_die = NULL;
14446 72687791 : 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 72687791 : if (arg && VAR_P (arg))
14453 1949 : arg = DECL_INITIAL (arg);
14454 :
14455 72687791 : 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 62708576 : if (TREE_CODE (parm) == PARM_DECL)
14463 : /* PARM is a nontype generic parameter */
14464 10982361 : tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
14465 51726215 : else if (TREE_CODE (parm) == TYPE_DECL)
14466 : /* PARM is a type generic parameter. */
14467 51580819 : tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
14468 145396 : 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 145396 : tmpl_die = new_die (DW_TAG_GNU_template_template_param,
14475 : parent_die, parm);
14476 : else
14477 0 : gcc_unreachable ();
14478 :
14479 62708576 : if (tmpl_die)
14480 : {
14481 62708576 : 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 62708576 : if (emit_name_p)
14489 : {
14490 52250450 : name = IDENTIFIER_POINTER (DECL_NAME (parm));
14491 52250450 : gcc_assert (name);
14492 52250450 : add_AT_string (tmpl_die, DW_AT_name, name);
14493 : }
14494 :
14495 62708576 : 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 62563180 : tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
14503 62563180 : add_type_attribute (tmpl_die, tmpl_type,
14504 62563180 : (TREE_THIS_VOLATILE (tmpl_type)
14505 62563180 : ? 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 145396 : name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
14517 145396 : if (name)
14518 145396 : add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
14519 : }
14520 :
14521 62708576 : 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 10982361 : 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 5361004 : template_parameter_pack_die (tree parm_pack,
14546 : tree parm_pack_args,
14547 : dw_die_ref parent_die)
14548 : {
14549 5361004 : dw_die_ref die;
14550 5361004 : int j;
14551 :
14552 5361004 : gcc_assert (parent_die && parm_pack);
14553 :
14554 5361004 : die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
14555 5361004 : add_name_and_src_coords_attributes (die, parm_pack);
14556 21515517 : for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
14557 10793509 : generic_parameter_die (parm_pack,
14558 10793509 : TREE_VEC_ELT (parm_pack_args, j),
14559 : false /* Don't emit DW_AT_name */,
14560 : die);
14561 5361004 : return die;
14562 : }
14563 :
14564 : /* Return the debugger register number described by a given RTL node. */
14565 :
14566 : static unsigned int
14567 15733718 : debugger_reg_number (const_rtx rtl)
14568 : {
14569 15733718 : unsigned regno = REGNO (rtl);
14570 :
14571 15733718 : 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 15733718 : regno = DEBUGGER_REGNO (regno);
14583 15733718 : gcc_assert (regno != INVALID_REGNUM);
14584 15733718 : 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 565393 : add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
14593 : {
14594 565393 : dw_loc_descr_ref loc;
14595 :
14596 565393 : if (*list_head != NULL)
14597 : {
14598 : /* Find the end of the chain. */
14599 1289623 : for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
14600 : ;
14601 :
14602 565393 : if (loc->dw_loc_opc != DW_OP_piece)
14603 565375 : loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
14604 : }
14605 565393 : }
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 14359008 : reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
14612 : {
14613 14359008 : rtx regs;
14614 :
14615 14359008 : 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 14314475 : if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
14624 14317911 : && (ira_use_lra_p
14625 1718 : ? lra_eliminate_regs (rtl, VOIDmode, NULL_RTX)
14626 0 : : eliminate_regs (rtl, VOIDmode, NULL_RTX)) != rtl)
14627 : {
14628 1718 : dw_loc_descr_ref result = NULL;
14629 :
14630 1718 : if (dwarf_version >= 4 || !dwarf_strict)
14631 : {
14632 1718 : result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
14633 : initialized);
14634 1718 : if (result)
14635 3436 : add_loc_descr (&result,
14636 : new_loc_descr (DW_OP_stack_value, 0, 0));
14637 : }
14638 1718 : return result;
14639 : }
14640 :
14641 14314475 : regs = targetm.dwarf_register_span (rtl);
14642 :
14643 14314475 : if (REG_NREGS (rtl) > 1 || regs)
14644 91710 : return multiple_reg_loc_descriptor (rtl, regs, initialized);
14645 : else
14646 : {
14647 14222765 : unsigned int debugger_regnum = debugger_reg_number (rtl);
14648 14222765 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
14649 : return 0;
14650 14222765 : 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 15716702 : one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
14659 : {
14660 15716702 : dw_loc_descr_ref reg_loc_descr;
14661 :
14662 15716702 : if (regno <= 31)
14663 15699222 : reg_loc_descr
14664 15699222 : = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
14665 : else
14666 17480 : reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
14667 :
14668 15716702 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14669 202506 : add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14670 :
14671 15716702 : 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 91710 : multiple_reg_loc_descriptor (rtx rtl, rtx regs,
14679 : enum var_init_status initialized)
14680 : {
14681 91710 : int size, i;
14682 91710 : dw_loc_descr_ref loc_result = NULL;
14683 :
14684 : /* Simple, contiguous registers. */
14685 91710 : if (regs == NULL_RTX)
14686 : {
14687 91710 : unsigned reg = REGNO (rtl);
14688 91710 : 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 91710 : gcc_assert ((unsigned) DEBUGGER_REGNO (reg) == debugger_reg_number (rtl));
14700 91710 : nregs = REG_NREGS (rtl);
14701 :
14702 : /* At present we only track constant-sized pieces. */
14703 183420 : if (!GET_MODE_SIZE (GET_MODE (rtl)).is_constant (&size))
14704 : return NULL;
14705 91710 : size /= nregs;
14706 :
14707 91710 : loc_result = NULL;
14708 275130 : while (nregs--)
14709 : {
14710 183420 : dw_loc_descr_ref t;
14711 :
14712 183420 : t = one_reg_loc_descriptor (DEBUGGER_REGNO (reg),
14713 : VAR_INIT_STATUS_INITIALIZED);
14714 183420 : add_loc_descr (&loc_result, t);
14715 183420 : add_loc_descr_op_piece (&loc_result, size);
14716 183420 : ++reg;
14717 : }
14718 91710 : 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 35684 : int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
14753 : {
14754 35684 : dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
14755 35684 : add_loc_descr (&ret, int_loc_descriptor (shift));
14756 35684 : add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14757 35684 : return ret;
14758 : }
14759 :
14760 : /* Return a location descriptor that designates constant POLY_I. */
14761 :
14762 : static dw_loc_descr_ref
14763 5548025 : int_loc_descriptor (poly_int64 poly_i)
14764 : {
14765 5548025 : enum dwarf_location_atom op;
14766 :
14767 5548025 : HOST_WIDE_INT i;
14768 5548025 : 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 5548025 : if (i >= 0)
14815 : {
14816 5256264 : int clz = clz_hwi (i);
14817 3429218 : int ctz = ctz_hwi (i);
14818 5256264 : if (i <= 31)
14819 3898314 : op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
14820 1357950 : else if (i <= 0xff)
14821 : op = DW_OP_const1u;
14822 454341 : else if (i <= 0xffff)
14823 : op = DW_OP_const2u;
14824 296087 : 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 33225 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
14830 262862 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
14831 1692 : && 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 1265 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
14835 :
14836 261597 : else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
14837 3660 : && 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 261597 : 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 77800 : 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 77373 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
14860 77373 : && 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 544 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
14865 76829 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
14866 : && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
14867 76829 : && size_of_uleb128 (i) > 6)
14868 : /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
14869 223 : 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 291761 : if (i >= -0x80)
14876 : op = DW_OP_const1s;
14877 54173 : else if (i >= -0x8000)
14878 : op = DW_OP_const2s;
14879 49653 : 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 49653 : if (size_of_int_loc_descriptor (i)
14892 49653 : < (unsigned long) 1 + size_of_sleb128 (i))
14893 : {
14894 4046 : dw_loc_descr_ref ret = int_loc_descriptor (-i);
14895 4046 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14896 4046 : return ret;
14897 : }
14898 : op = DW_OP_consts;
14899 : }
14900 : }
14901 :
14902 5508295 : return new_loc_descr (op, i, 0);
14903 : }
14904 :
14905 : /* Likewise, for unsigned constants. */
14906 :
14907 : static dw_loc_descr_ref
14908 123001 : uint_loc_descriptor (unsigned HOST_WIDE_INT i)
14909 : {
14910 123001 : const unsigned HOST_WIDE_INT max_int = INTTYPE_MAXIMUM (HOST_WIDE_INT);
14911 123001 : 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 123001 : if (i <= max_int)
14916 122993 : 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 29828 : size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
15055 : {
15056 29828 : return size_of_int_loc_descriptor (i >> shift)
15057 29828 : + size_of_int_loc_descriptor (shift)
15058 29828 : + 1;
15059 : }
15060 :
15061 : /* Return size_of_locs (int_loc_descriptor (i)) without
15062 : actually allocating it. */
15063 :
15064 : static unsigned long
15065 4169960 : size_of_int_loc_descriptor (HOST_WIDE_INT i)
15066 : {
15067 4171476 : unsigned long s;
15068 :
15069 4171476 : if (i >= 0)
15070 : {
15071 3732558 : int clz, ctz;
15072 3732558 : if (i <= 31)
15073 : return 1;
15074 580053 : else if (i <= 0xff)
15075 : return 2;
15076 199552 : else if (i <= 0xffff)
15077 : return 3;
15078 126748 : clz = clz_hwi (i);
15079 126748 : ctz = ctz_hwi (i);
15080 126748 : if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
15081 : && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
15082 27054 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15083 27054 : - clz - 5);
15084 99694 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
15085 2144 : && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
15086 1317 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15087 1317 : - clz - 8);
15088 98377 : else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
15089 2844 : && 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 96861 : else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
15093 : return 5;
15094 51781 : s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
15095 51781 : if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
15096 : && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
15097 824 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15098 824 : - clz - 8);
15099 50957 : 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 50547 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
15104 : && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
15105 379 : && s > 6)
15106 223 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
15107 223 : - clz - 32);
15108 : else
15109 50324 : return 1 + s;
15110 : }
15111 : else
15112 : {
15113 438918 : if (i >= -0x80)
15114 : return 2;
15115 341564 : else if (i >= -0x8000)
15116 : return 3;
15117 339321 : 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 339321 : unsigned long r = 1 + size_of_sleb128 (i);
15130 339321 : if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
15131 : {
15132 58032 : s = size_of_int_loc_descriptor (-i) + 1;
15133 58032 : if (s < r)
15134 : return s;
15135 : }
15136 332581 : 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 2878129 : address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
15146 : {
15147 2878129 : int litsize;
15148 2878129 : dw_loc_descr_ref loc_result = NULL;
15149 :
15150 2878129 : if (!(dwarf_version >= 4 || !dwarf_strict))
15151 : return NULL;
15152 :
15153 2878129 : 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 3430705 : if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
15160 : {
15161 2829350 : loc_result = int_loc_descriptor (i);
15162 2829350 : add_loc_descr (&loc_result,
15163 : new_loc_descr (DW_OP_stack_value, 0, 0));
15164 2829350 : return loc_result;
15165 : }
15166 :
15167 48779 : loc_result = new_loc_descr (DW_OP_implicit_value,
15168 : size, 0);
15169 48779 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
15170 48779 : loc_result->dw_loc_oprnd2.v.val_int = i;
15171 48779 : return loc_result;
15172 : }
15173 :
15174 : /* Return a location descriptor that designates a base+offset location. */
15175 :
15176 : static dw_loc_descr_ref
15177 12904273 : based_loc_descr (rtx reg, poly_int64 offset,
15178 : enum var_init_status initialized)
15179 : {
15180 12904273 : unsigned int regno;
15181 12904273 : dw_loc_descr_ref result;
15182 12904273 : 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 12904273 : if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
15189 : {
15190 7894901 : rtx elim = (ira_use_lra_p
15191 7894901 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
15192 7894901 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
15193 :
15194 7894901 : 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 7894901 : elim = strip_offset_and_add (elim, &offset);
15201 7894901 : 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 7894901 : if (crtl->stack_realign_tried
15209 11850 : && reg == frame_pointer_rtx)
15210 : {
15211 4862 : int base_reg
15212 4862 : = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
15213 : ? HARD_FRAME_POINTER_REGNUM
15214 : : REGNO (elim));
15215 4862 : return new_reg_loc_descr (base_reg, offset);
15216 : }
15217 :
15218 7890039 : gcc_assert (frame_pointer_fb_offset_valid);
15219 7890039 : offset += frame_pointer_fb_offset;
15220 7890039 : HOST_WIDE_INT const_offset;
15221 7890039 : if (offset.is_constant (&const_offset))
15222 7890039 : 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 5009372 : 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 5009372 : regno = DWARF_FRAME_REGNUM (regno);
15242 :
15243 5009372 : HOST_WIDE_INT const_offset;
15244 16244 : if (!optimize && fde
15245 16244 : && (fde->drap_reg == regno || fde->vdrap_reg == regno)
15246 5009372 : && 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 5006290 : result = new_reg_loc_descr (regno, offset);
15258 :
15259 5006290 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
15260 0 : add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
15261 :
15262 5006290 : return result;
15263 : }
15264 :
15265 : /* Return true if this RTL expression describes a base+offset calculation. */
15266 :
15267 : static inline bool
15268 11296746 : is_based_loc (const_rtx rtl)
15269 : {
15270 11296746 : return (GET_CODE (rtl) == PLUS
15271 11296746 : && ((REG_P (XEXP (rtl, 0))
15272 10007514 : && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
15273 10005642 : && 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 18073 : tls_mem_loc_descriptor (rtx mem)
15281 : {
15282 18073 : tree base;
15283 18073 : dw_loc_descr_ref loc_result;
15284 :
15285 18073 : if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
15286 : return NULL;
15287 :
15288 16653 : base = get_base_address (MEM_EXPR (mem));
15289 16653 : if (base == NULL
15290 16653 : || !VAR_P (base)
15291 31697 : || !DECL_THREAD_LOCAL_P (base))
15292 16653 : 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 2224956 : expansion_failed (tree expr, rtx rtl, char const *reason)
15309 : {
15310 2224956 : 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 2224956 : }
15323 :
15324 : /* Helper function for const_ok_for_output. */
15325 :
15326 : static bool
15327 1847445 : const_ok_for_output_1 (rtx rtl)
15328 : {
15329 1847445 : 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 1847425 : 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 1847425 : switch (GET_CODE (rtl))
15374 : {
15375 1586013 : case SYMBOL_REF:
15376 1586013 : break;
15377 : case NOT:
15378 : case NEG:
15379 : return false;
15380 139867 : case PLUS:
15381 139867 : {
15382 : /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
15383 : operands. */
15384 139867 : subrtx_var_iterator::array_type array;
15385 139867 : bool first = false;
15386 139867 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
15387 139867 : if (SYMBOL_REF_P (*iter)
15388 : || LABEL_P (*iter)
15389 : || GET_CODE (*iter) == UNSPEC)
15390 : {
15391 : first = true;
15392 : break;
15393 : }
15394 139867 : if (!first)
15395 : return true;
15396 279734 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
15397 139867 : if (SYMBOL_REF_P (*iter)
15398 : || LABEL_P (*iter)
15399 : || GET_CODE (*iter) == UNSPEC)
15400 0 : return false;
15401 139867 : return true;
15402 139867 : }
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 1586013 : 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 1586013 : 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 1578298 : if (SYMBOL_REF_EXTERNAL_P (rtl))
15442 : {
15443 120928 : tree decl = SYMBOL_REF_DECL (rtl);
15444 :
15445 120928 : if (decl == NULL || !targetm.binds_local_p (decl))
15446 : {
15447 114721 : expansion_failed (NULL_TREE, rtl,
15448 : "Symbol not defined in current TU.\n");
15449 114721 : 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 1590839 : const_ok_for_output (rtx rtl)
15462 : {
15463 1590839 : if (GET_CODE (rtl) == SYMBOL_REF)
15464 1445532 : return const_ok_for_output_1 (rtl);
15465 :
15466 145307 : if (GET_CODE (rtl) == CONST)
15467 : {
15468 140491 : subrtx_var_iterator::array_type array;
15469 522405 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
15470 401903 : if (!const_ok_for_output_1 (*iter))
15471 19989 : return false;
15472 120502 : return true;
15473 140491 : }
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 359850 : base_type_for_mode (machine_mode mode, bool unsignedp)
15483 : {
15484 359850 : dw_die_ref type_die;
15485 359850 : tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
15486 :
15487 359850 : if (type == NULL)
15488 : return NULL;
15489 358676 : switch (TREE_CODE (type))
15490 : {
15491 354034 : case INTEGER_TYPE:
15492 354034 : case REAL_TYPE:
15493 354034 : break;
15494 : default:
15495 : return NULL;
15496 : }
15497 354034 : type_die = lookup_type_die (type);
15498 354034 : if (!type_die)
15499 385 : type_die = modified_type_die (type, TYPE_UNQUALIFIED, NULL_TREE,
15500 : false, comp_unit_die ());
15501 354034 : 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 5360 : convert_descriptor_to_mode (scalar_int_mode mode, dw_loc_descr_ref op)
15513 : {
15514 5360 : machine_mode outer_mode = mode;
15515 5360 : dw_die_ref type_die;
15516 5360 : dw_loc_descr_ref cvt;
15517 :
15518 12110 : if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
15519 : {
15520 5083 : add_loc_descr (&op, new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0));
15521 5083 : 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 119607 : compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
15538 : dw_loc_descr_ref op1)
15539 : {
15540 119607 : dw_loc_descr_ref ret = op0;
15541 119607 : add_loc_descr (&ret, op1);
15542 119607 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
15543 119607 : 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 119607 : 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 35206 : 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 35206 : 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 35206 : if (op == DW_OP_eq || op == DW_OP_ne)
15591 : {
15592 32229 : dw_loc_descr_ref last0, last1;
15593 93087 : for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
15594 : ;
15595 40804 : 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 32229 : if (((last0->dw_loc_opc == DW_OP_deref_size
15600 11550 : && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
15601 26454 : || (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 38266 : && ((last1->dw_loc_opc == DW_OP_deref_size
15605 1166 : && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
15606 5454 : || (CONST_INT_P (XEXP (rtl, 1))
15607 5135 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
15608 5135 : == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
15609 5627 : 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 26602 : if (CONST_INT_P (XEXP (rtl, 1))
15619 24649 : && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
15620 51251 : && (size_of_int_loc_descriptor (shift) + 1
15621 24649 : + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift)
15622 24649 : >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
15623 24649 : + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
15624 24649 : & GET_MODE_MASK (op_mode))))
15625 : {
15626 10472 : add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
15627 10472 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15628 20944 : op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
15629 10472 : & GET_MODE_MASK (op_mode));
15630 10472 : return compare_loc_descriptor (op, op0, op1);
15631 : }
15632 : }
15633 19107 : add_loc_descr (&op0, int_loc_descriptor (shift));
15634 19107 : add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
15635 19107 : if (CONST_INT_P (XEXP (rtl, 1)))
15636 16408 : op1 = int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift);
15637 : else
15638 : {
15639 2699 : add_loc_descr (&op1, int_loc_descriptor (shift));
15640 5398 : add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
15641 : }
15642 19107 : 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 93520 : scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
15649 : machine_mode mem_mode)
15650 : {
15651 93520 : machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
15652 93520 : dw_loc_descr_ref op0, op1;
15653 :
15654 93520 : if (op_mode == VOIDmode)
15655 419 : op_mode = GET_MODE (XEXP (rtl, 1));
15656 93520 : if (op_mode == VOIDmode)
15657 : return NULL;
15658 :
15659 93520 : scalar_int_mode int_op_mode;
15660 93520 : if (dwarf_strict
15661 0 : && dwarf_version < 5
15662 98010 : && (!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 93520 : op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
15667 : VAR_INIT_STATUS_INITIALIZED);
15668 93520 : op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
15669 : VAR_INIT_STATUS_INITIALIZED);
15670 :
15671 93520 : if (op0 == NULL || op1 == NULL)
15672 : return NULL;
15673 :
15674 89030 : if (is_a <scalar_int_mode> (op_mode, &int_op_mode))
15675 : {
15676 189005 : if (GET_MODE_SIZE (int_op_mode) < DWARF2_ADDR_SIZE)
15677 35206 : return scompare_loc_descriptor_narrow (op, rtl, int_op_mode, op0, op1);
15678 :
15679 115777 : 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 52811 : 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 32348 : ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
15689 : machine_mode mem_mode)
15690 : {
15691 32348 : dw_loc_descr_ref op0, op1;
15692 :
15693 32348 : machine_mode test_op_mode = GET_MODE (XEXP (rtl, 0));
15694 32348 : if (test_op_mode == VOIDmode)
15695 55 : test_op_mode = GET_MODE (XEXP (rtl, 1));
15696 :
15697 32348 : scalar_int_mode op_mode;
15698 32533 : if (!is_a <scalar_int_mode> (test_op_mode, &op_mode))
15699 : return NULL;
15700 :
15701 30762 : if (dwarf_strict
15702 0 : && dwarf_version < 5
15703 30762 : && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
15704 : return NULL;
15705 :
15706 30762 : op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
15707 : VAR_INIT_STATUS_INITIALIZED);
15708 30762 : op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
15709 : VAR_INIT_STATUS_INITIALIZED);
15710 :
15711 30762 : if (op0 == NULL || op1 == NULL)
15712 : return NULL;
15713 :
15714 66000 : if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
15715 : {
15716 9934 : HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
15717 9934 : dw_loc_descr_ref last0, last1;
15718 19506 : for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
15719 : ;
15720 10209 : for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
15721 : ;
15722 9934 : 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 9934 : else if (last0->dw_loc_opc != DW_OP_deref_size
15726 13060 : || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
15727 : {
15728 6808 : add_loc_descr (&op0, int_loc_descriptor (mask));
15729 13616 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15730 : }
15731 9934 : if (CONST_INT_P (XEXP (rtl, 1)))
15732 9740 : 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 45975 : else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
15742 : {
15743 20160 : HOST_WIDE_INT bias = 1;
15744 20160 : bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
15745 20160 : add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15746 20160 : if (CONST_INT_P (XEXP (rtl, 1)))
15747 7477 : op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
15748 7477 : + INTVAL (XEXP (rtl, 1)));
15749 : else
15750 25366 : add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
15751 : bias, 0));
15752 : }
15753 30577 : 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 145324 : minmax_loc_descriptor (rtx rtl, machine_mode mode,
15760 : machine_mode mem_mode)
15761 : {
15762 145324 : enum dwarf_location_atom op;
15763 145324 : dw_loc_descr_ref op0, op1, ret;
15764 145324 : dw_loc_descr_ref bra_node, drop_node;
15765 :
15766 145324 : scalar_int_mode int_mode;
15767 145324 : if (dwarf_strict
15768 0 : && dwarf_version < 5
15769 145428 : && (!is_a <scalar_int_mode> (mode, &int_mode)
15770 0 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE))
15771 : return NULL;
15772 :
15773 145324 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15774 : VAR_INIT_STATUS_INITIALIZED);
15775 145324 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15776 : VAR_INIT_STATUS_INITIALIZED);
15777 :
15778 145324 : if (op0 == NULL || op1 == NULL)
15779 : return NULL;
15780 :
15781 145220 : add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
15782 145220 : add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
15783 145220 : add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
15784 145220 : if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
15785 : {
15786 : /* Checked by the caller. */
15787 127420 : int_mode = as_a <scalar_int_mode> (mode);
15788 256035 : 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 255209 : else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
15797 : {
15798 127033 : HOST_WIDE_INT bias = 1;
15799 127033 : bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
15800 127033 : add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15801 254066 : add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15802 : }
15803 : }
15804 17800 : else if (is_a <scalar_int_mode> (mode, &int_mode)
15805 26424 : && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
15806 : {
15807 1091 : int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (int_mode)) * BITS_PER_UNIT;
15808 1091 : add_loc_descr (&op0, int_loc_descriptor (shift));
15809 1091 : add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
15810 1091 : add_loc_descr (&op1, int_loc_descriptor (shift));
15811 2182 : add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
15812 : }
15813 16709 : else if (is_a <scalar_int_mode> (mode, &int_mode)
15814 25333 : && 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 145220 : if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
15833 : op = DW_OP_lt;
15834 : else
15835 145220 : op = DW_OP_gt;
15836 145220 : ret = op0;
15837 145220 : add_loc_descr (&ret, op1);
15838 145220 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
15839 145220 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15840 145220 : add_loc_descr (&ret, bra_node);
15841 145220 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15842 145220 : drop_node = new_loc_descr (DW_OP_drop, 0, 0);
15843 145220 : add_loc_descr (&ret, drop_node);
15844 145220 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15845 145220 : bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
15846 145220 : if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
15847 17800 : && is_a <scalar_int_mode> (mode, &int_mode)
15848 171644 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
15849 47 : ret = convert_descriptor_to_mode (int_mode, ret);
15850 145220 : 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 3739 : 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 3739 : dw_loc_descr_ref cvt, op0, op1;
15862 :
15863 3739 : if (type_die == NULL)
15864 : return NULL;
15865 3739 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15866 : VAR_INIT_STATUS_INITIALIZED);
15867 3739 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15868 : VAR_INIT_STATUS_INITIALIZED);
15869 3739 : if (op0 == NULL || op1 == NULL)
15870 : return NULL;
15871 3684 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15872 3684 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15873 3684 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15874 3684 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15875 3684 : add_loc_descr (&op0, cvt);
15876 3684 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15877 3684 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15878 3684 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15879 3684 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15880 3684 : add_loc_descr (&op1, cvt);
15881 3684 : add_loc_descr (&op0, op1);
15882 3684 : add_loc_descr (&op0, new_loc_descr (op, 0, 0));
15883 3684 : 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 5265 : clz_loc_descriptor (rtx rtl, scalar_int_mode mode,
15916 : machine_mode mem_mode)
15917 : {
15918 5265 : dw_loc_descr_ref op0, ret, tmp;
15919 5265 : HOST_WIDE_INT valv;
15920 5265 : dw_loc_descr_ref l1jump, l1label;
15921 5265 : dw_loc_descr_ref l2jump, l2label;
15922 5265 : dw_loc_descr_ref l3jump, l3label;
15923 5265 : dw_loc_descr_ref l4jump, l4label;
15924 5265 : rtx msb;
15925 :
15926 5265 : if (GET_MODE (XEXP (rtl, 0)) != mode)
15927 : return NULL;
15928 :
15929 5265 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15930 : VAR_INIT_STATUS_INITIALIZED);
15931 5265 : if (op0 == NULL)
15932 : return NULL;
15933 5265 : ret = op0;
15934 5265 : if (GET_CODE (rtl) == CLZ)
15935 : {
15936 9938 : if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
15937 9938 : valv = GET_MODE_BITSIZE (mode);
15938 : }
15939 296 : else if (GET_CODE (rtl) == FFS)
15940 : valv = 0;
15941 592 : else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
15942 592 : valv = GET_MODE_BITSIZE (mode);
15943 5265 : add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
15944 5265 : l1jump = new_loc_descr (DW_OP_bra, 0, 0);
15945 5265 : add_loc_descr (&ret, l1jump);
15946 5265 : add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
15947 5265 : tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
15948 : VAR_INIT_STATUS_INITIALIZED);
15949 5265 : if (tmp == NULL)
15950 : return NULL;
15951 5265 : add_loc_descr (&ret, tmp);
15952 5265 : l4jump = new_loc_descr (DW_OP_skip, 0, 0);
15953 5265 : add_loc_descr (&ret, l4jump);
15954 5265 : l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
15955 : ? const1_rtx : const0_rtx,
15956 : mode, mem_mode,
15957 : VAR_INIT_STATUS_INITIALIZED);
15958 5265 : if (l1label == NULL)
15959 : return NULL;
15960 5265 : add_loc_descr (&ret, l1label);
15961 5265 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15962 5265 : l2label = new_loc_descr (DW_OP_dup, 0, 0);
15963 5265 : add_loc_descr (&ret, l2label);
15964 5265 : if (GET_CODE (rtl) != CLZ)
15965 296 : msb = const1_rtx;
15966 9938 : else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
15967 9938 : 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 5265 : if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
15974 2019 : 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 3246 : tmp = mem_loc_descriptor (msb, mode, mem_mode,
15979 : VAR_INIT_STATUS_INITIALIZED);
15980 5265 : if (tmp == NULL)
15981 : return NULL;
15982 5265 : add_loc_descr (&ret, tmp);
15983 5265 : add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
15984 5265 : l3jump = new_loc_descr (DW_OP_bra, 0, 0);
15985 5265 : add_loc_descr (&ret, l3jump);
15986 5265 : tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
15987 : VAR_INIT_STATUS_INITIALIZED);
15988 5265 : if (tmp == NULL)
15989 : return NULL;
15990 5265 : add_loc_descr (&ret, tmp);
15991 5561 : add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
15992 : ? DW_OP_shl : DW_OP_shr, 0, 0));
15993 5265 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15994 5265 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
15995 5265 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15996 5265 : l2jump = new_loc_descr (DW_OP_skip, 0, 0);
15997 5265 : add_loc_descr (&ret, l2jump);
15998 5265 : l3label = new_loc_descr (DW_OP_drop, 0, 0);
15999 5265 : add_loc_descr (&ret, l3label);
16000 5265 : l4label = new_loc_descr (DW_OP_nop, 0, 0);
16001 5265 : add_loc_descr (&ret, l4label);
16002 5265 : l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16003 5265 : l1jump->dw_loc_oprnd1.v.val_loc = l1label;
16004 5265 : l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16005 5265 : l2jump->dw_loc_oprnd1.v.val_loc = l2label;
16006 5265 : l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16007 5265 : l3jump->dw_loc_oprnd1.v.val_loc = l3label;
16008 5265 : l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
16009 5265 : l4jump->dw_loc_oprnd1.v.val_loc = l4label;
16010 5265 : 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 168 : bswap_loc_descriptor (rtx rtl, scalar_int_mode mode,
16087 : machine_mode mem_mode)
16088 : {
16089 168 : dw_loc_descr_ref op0, ret, tmp;
16090 168 : dw_loc_descr_ref l1jump, l1label;
16091 168 : dw_loc_descr_ref l2jump, l2label;
16092 :
16093 168 : if (BITS_PER_UNIT != 8
16094 137 : || (GET_MODE_BITSIZE (mode) != 32
16095 305 : && 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 30955 : parameter_ref_descriptor (rtx rtl)
16240 : {
16241 30955 : dw_loc_descr_ref ret;
16242 30955 : dw_die_ref ref;
16243 :
16244 30955 : if (dwarf_strict)
16245 : return NULL;
16246 30955 : 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 30955 : ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
16251 30955 : ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
16252 30955 : if (ref)
16253 : {
16254 30955 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16255 30955 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
16256 30955 : 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 24023259 : mem_loc_descriptor (rtx rtl, machine_mode mode,
16285 : machine_mode mem_mode,
16286 : enum var_init_status initialized)
16287 : {
16288 24023259 : dw_loc_descr_ref mem_loc_result = NULL;
16289 24023259 : enum dwarf_location_atom op;
16290 24023259 : dw_loc_descr_ref op0, op1;
16291 24023259 : rtx inner = NULL_RTX;
16292 :
16293 24023259 : if (mode == VOIDmode)
16294 863 : 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 24023259 : rtl = targetm.delegitimize_address (rtl);
16302 :
16303 24023259 : if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
16304 : return NULL;
16305 :
16306 24023259 : scalar_int_mode int_mode = BImode, inner_mode, op1_mode;
16307 24023259 : 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 225845 : 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 225845 : if (!subreg_lowpart_p (rtl))
16321 : break;
16322 212936 : inner = SUBREG_REG (rtl);
16323 : /* FALLTHRU */
16324 212936 : case TRUNCATE:
16325 212936 : if (inner == NULL_RTX)
16326 5754 : inner = XEXP (rtl, 0);
16327 218690 : if (is_a <scalar_int_mode> (mode, &int_mode)
16328 218140 : && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
16329 239815 : && (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 458397 : && GET_MODE_SIZE (inner_mode) <= DWARF2_ADDR_SIZE)
16335 : {
16336 186535 : mem_loc_result = mem_loc_descriptor (inner,
16337 : inner_mode,
16338 : mem_mode, initialized);
16339 186535 : break;
16340 : }
16341 32155 : if (dwarf_strict && dwarf_version < 5)
16342 : break;
16343 32155 : if (is_a <scalar_int_mode> (mode, &int_mode)
16344 31605 : && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
16345 92929 : ? GET_MODE_SIZE (int_mode) <= GET_MODE_SIZE (inner_mode)
16346 35691 : : known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
16347 : {
16348 31969 : dw_die_ref type_die;
16349 31969 : dw_loc_descr_ref cvt;
16350 :
16351 63938 : mem_loc_result = mem_loc_descriptor (inner,
16352 31969 : GET_MODE (inner),
16353 : mem_mode, initialized);
16354 31969 : if (mem_loc_result == NULL)
16355 : break;
16356 22594 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16357 22594 : if (type_die == NULL)
16358 : {
16359 0 : mem_loc_result = NULL;
16360 0 : break;
16361 : }
16362 67782 : if (maybe_ne (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
16363 21003 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16364 : else
16365 1591 : cvt = new_loc_descr (dwarf_OP (DW_OP_reinterpret), 0, 0);
16366 22594 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16367 22594 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16368 22594 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16369 22594 : add_loc_descr (&mem_loc_result, cvt);
16370 22594 : if (is_a <scalar_int_mode> (mode, &int_mode)
16371 65996 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
16372 : {
16373 : /* Convert it to untyped afterwards. */
16374 21773 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16375 21773 : add_loc_descr (&mem_loc_result, cvt);
16376 : }
16377 : }
16378 : break;
16379 :
16380 3221897 : case REG:
16381 3221897 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16382 6768302 : || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
16383 44844 : && rtl != arg_pointer_rtx
16384 44842 : && rtl != frame_pointer_rtx
16385 : #ifdef POINTERS_EXTEND_UNSIGNED
16386 87837 : && (int_mode != Pmode || mem_mode == VOIDmode)
16387 : #endif
16388 : ))
16389 : {
16390 113338 : dw_die_ref type_die;
16391 113338 : unsigned int debugger_regnum;
16392 :
16393 113338 : if (dwarf_strict && dwarf_version < 5)
16394 : break;
16395 113338 : if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
16396 : break;
16397 113338 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16398 113338 : if (type_die == NULL)
16399 : break;
16400 :
16401 108726 : debugger_regnum = debugger_reg_number (rtl);
16402 108726 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
16403 : break;
16404 108726 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_regval_type),
16405 : debugger_regnum, 0);
16406 108726 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
16407 108726 : mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
16408 108726 : mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
16409 108726 : 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 3108559 : if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
16425 3106675 : 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 257716 : case SIGN_EXTEND:
16439 257716 : case ZERO_EXTEND:
16440 257716 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16441 257716 : || !is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &inner_mode))
16442 : break;
16443 257716 : op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
16444 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
16445 257716 : if (op0 == 0)
16446 : break;
16447 253361 : else if (GET_CODE (rtl) == ZERO_EXTEND
16448 244999 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16449 177566 : && 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 458112 : && GET_MODE_SIZE (inner_mode) <= 4)
16454 : {
16455 177566 : mem_loc_result = op0;
16456 177566 : add_loc_descr (&mem_loc_result,
16457 177566 : int_loc_descriptor (GET_MODE_MASK (inner_mode)));
16458 177566 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
16459 : }
16460 183604 : else if (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
16461 : {
16462 44428 : int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (inner_mode);
16463 44428 : shift *= BITS_PER_UNIT;
16464 44428 : if (GET_CODE (rtl) == SIGN_EXTEND)
16465 : op = DW_OP_shra;
16466 : else
16467 0 : op = DW_OP_shr;
16468 44428 : mem_loc_result = op0;
16469 44428 : add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
16470 44428 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
16471 44428 : add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
16472 44428 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16473 : }
16474 31367 : else if (!dwarf_strict || dwarf_version >= 5)
16475 : {
16476 31367 : dw_die_ref type_die1, type_die2;
16477 31367 : dw_loc_descr_ref cvt;
16478 :
16479 31367 : type_die1 = base_type_for_mode (inner_mode,
16480 : GET_CODE (rtl) == ZERO_EXTEND);
16481 31367 : if (type_die1 == NULL)
16482 : break;
16483 31367 : type_die2 = base_type_for_mode (int_mode, 1);
16484 31367 : if (type_die2 == NULL)
16485 : break;
16486 31367 : mem_loc_result = op0;
16487 31367 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16488 31367 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16489 31367 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
16490 31367 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16491 31367 : add_loc_descr (&mem_loc_result, cvt);
16492 31367 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16493 31367 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16494 31367 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
16495 31367 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16496 31367 : add_loc_descr (&mem_loc_result, cvt);
16497 : }
16498 : break;
16499 :
16500 1759848 : case MEM:
16501 1759848 : {
16502 1759848 : rtx new_rtl = avoid_constant_pool_reference (rtl);
16503 1759848 : 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 1759848 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
16512 1759848 : get_address_mode (rtl), mode,
16513 : VAR_INIT_STATUS_INITIALIZED);
16514 1759848 : if (mem_loc_result == NULL)
16515 7894 : mem_loc_result = tls_mem_loc_descriptor (rtl);
16516 1759848 : if (mem_loc_result != NULL)
16517 : {
16518 1751954 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16519 3765571 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16520 : {
16521 57186 : dw_die_ref type_die;
16522 57186 : dw_loc_descr_ref deref;
16523 57186 : HOST_WIDE_INT size;
16524 :
16525 57186 : if (dwarf_strict && dwarf_version < 5)
16526 1204 : return NULL;
16527 114372 : if (!GET_MODE_SIZE (mode).is_constant (&size))
16528 : return NULL;
16529 57186 : type_die
16530 57186 : = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16531 57186 : if (type_die == NULL)
16532 : return NULL;
16533 55982 : deref = new_loc_descr (dwarf_OP (DW_OP_deref_type), size, 0);
16534 55982 : deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
16535 55982 : deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
16536 55982 : deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
16537 55982 : add_loc_descr (&mem_loc_result, deref);
16538 : }
16539 3656579 : else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
16540 1524994 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
16541 : else
16542 339548 : add_loc_descr (&mem_loc_result,
16543 : new_loc_descr (DW_OP_deref_size,
16544 169774 : 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 1062410 : 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 1062410 : case CONST:
16556 1062410 : case SYMBOL_REF:
16557 1062410 : case UNSPEC:
16558 1062410 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16559 2180860 : || (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 1062255 : 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 44 : bool not_ok = false;
16573 44 : subrtx_var_iterator::array_type array;
16574 98 : FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
16575 88 : if (*iter != rtl && !CONSTANT_P (*iter))
16576 : {
16577 : not_ok = true;
16578 : break;
16579 : }
16580 :
16581 44 : 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 44 : }
16597 :
16598 1062211 : if (GET_CODE (rtl) == SYMBOL_REF
16599 1062211 : && 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 1057394 : if (!const_ok_for_output (rtl))
16621 : {
16622 83019 : if (GET_CODE (rtl) == CONST)
16623 7938 : 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 7938 : default:
16645 7938 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), int_mode,
16646 : mem_mode, initialized);
16647 7938 : break;
16648 : }
16649 : break;
16650 : }
16651 :
16652 974375 : symref:
16653 1096764 : mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
16654 1096764 : vec_safe_push (used_rtx_array, rtl);
16655 1096764 : break;
16656 :
16657 164543 : case CONCAT:
16658 164543 : case CONCATN:
16659 164543 : case VAR_LOCATION:
16660 164543 : case DEBUG_IMPLICIT_PTR:
16661 164543 : expansion_failed (NULL_TREE, rtl,
16662 : "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
16663 164543 : return 0;
16664 :
16665 1354835 : case ENTRY_VALUE:
16666 1354835 : if (dwarf_strict && dwarf_version < 5)
16667 : return NULL;
16668 1354835 : if (REG_P (ENTRY_VALUE_EXP (rtl)))
16669 : {
16670 1353622 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16671 2704583 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16672 43105 : op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
16673 : VOIDmode, VAR_INIT_STATUS_INITIALIZED);
16674 : else
16675 : {
16676 1310517 : unsigned int debugger_regnum = debugger_reg_number (ENTRY_VALUE_EXP (rtl));
16677 1310517 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
16678 : return NULL;
16679 1310517 : 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 1354813 : if (op0 == NULL)
16694 : return NULL;
16695 1353484 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_entry_value), 0, 0);
16696 1353484 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
16697 1353484 : mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
16698 1353484 : break;
16699 :
16700 30955 : case DEBUG_PARAMETER_REF:
16701 30955 : mem_loc_result = parameter_ref_descriptor (rtl);
16702 30955 : 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 11296746 : case PLUS:
16723 11296746 : plus:
16724 11296746 : if (is_based_loc (rtl)
16725 9798696 : && is_a <scalar_int_mode> (mode, &int_mode)
16726 22472614 : && (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16727 1099 : || XEXP (rtl, 0) == arg_pointer_rtx
16728 1099 : || XEXP (rtl, 0) == frame_pointer_rtx))
16729 9797598 : mem_loc_result = based_loc_descr (XEXP (rtl, 0),
16730 9797598 : INTVAL (XEXP (rtl, 1)),
16731 : VAR_INIT_STATUS_INITIALIZED);
16732 : else
16733 : {
16734 1499148 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16735 : VAR_INIT_STATUS_INITIALIZED);
16736 1499148 : if (mem_loc_result == 0)
16737 : break;
16738 :
16739 1486770 : if (CONST_INT_P (XEXP (rtl, 1))
16740 2254235 : && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
16741 767465 : <= DWARF2_ADDR_SIZE))
16742 765277 : loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
16743 : else
16744 : {
16745 721493 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16746 : VAR_INIT_STATUS_INITIALIZED);
16747 721493 : if (op1 == 0)
16748 : return NULL;
16749 708005 : add_loc_descr (&mem_loc_result, op1);
16750 708005 : 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 437667 : case MINUS:
16759 437667 : op = DW_OP_minus;
16760 437667 : goto do_binop;
16761 :
16762 222498 : case MULT:
16763 222498 : op = DW_OP_mul;
16764 222498 : goto do_binop;
16765 :
16766 263949 : case DIV:
16767 0 : if ((!dwarf_strict || dwarf_version >= 5)
16768 263949 : && is_a <scalar_int_mode> (mode, &int_mode)
16769 524265 : && 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 263886 : op = DW_OP_div;
16777 263886 : goto do_binop;
16778 :
16779 4022 : case UMOD:
16780 4022 : op = DW_OP_mod;
16781 4022 : goto do_binop;
16782 :
16783 321422 : case ASHIFT:
16784 321422 : op = DW_OP_shl;
16785 321422 : goto do_shift;
16786 :
16787 126025 : case ASHIFTRT:
16788 126025 : op = DW_OP_shra;
16789 126025 : goto do_shift;
16790 :
16791 252017 : case LSHIFTRT:
16792 252017 : op = DW_OP_shr;
16793 252017 : goto do_shift;
16794 :
16795 699464 : do_shift:
16796 699464 : if (!is_a <scalar_int_mode> (mode, &int_mode))
16797 : break;
16798 699437 : op0 = mem_loc_descriptor (XEXP (rtl, 0), int_mode, mem_mode,
16799 : VAR_INIT_STATUS_INITIALIZED);
16800 699437 : {
16801 699437 : rtx rtlop1 = XEXP (rtl, 1);
16802 699437 : if (is_a <scalar_int_mode> (GET_MODE (rtlop1), &op1_mode)
16803 717335 : && GET_MODE_BITSIZE (op1_mode) < GET_MODE_BITSIZE (int_mode))
16804 6665 : rtlop1 = gen_rtx_ZERO_EXTEND (int_mode, rtlop1);
16805 699437 : op1 = mem_loc_descriptor (rtlop1, int_mode, mem_mode,
16806 : VAR_INIT_STATUS_INITIALIZED);
16807 : }
16808 :
16809 699437 : if (op0 == 0 || op1 == 0)
16810 : break;
16811 :
16812 693563 : mem_loc_result = op0;
16813 693563 : add_loc_descr (&mem_loc_result, op1);
16814 693563 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16815 693563 : break;
16816 :
16817 210899 : case AND:
16818 210899 : op = DW_OP_and;
16819 210899 : goto do_binop;
16820 :
16821 79731 : case IOR:
16822 79731 : op = DW_OP_or;
16823 79731 : goto do_binop;
16824 :
16825 15783 : case XOR:
16826 15783 : op = DW_OP_xor;
16827 15783 : goto do_binop;
16828 :
16829 1238609 : do_binop:
16830 1238609 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16831 : VAR_INIT_STATUS_INITIALIZED);
16832 1238609 : if (XEXP (rtl, 0) == XEXP (rtl, 1))
16833 : {
16834 16465 : if (op0 == 0)
16835 : break;
16836 16462 : mem_loc_result = op0;
16837 16462 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_dup, 0, 0));
16838 16462 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16839 16462 : break;
16840 : }
16841 1222144 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16842 : VAR_INIT_STATUS_INITIALIZED);
16843 :
16844 1222144 : if (op0 == 0 || op1 == 0)
16845 : break;
16846 :
16847 1204869 : mem_loc_result = op0;
16848 1204869 : add_loc_descr (&mem_loc_result, op1);
16849 1204869 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16850 1204869 : break;
16851 :
16852 1819 : case MOD:
16853 0 : if ((!dwarf_strict || dwarf_version >= 5)
16854 1819 : && is_a <scalar_int_mode> (mode, &int_mode)
16855 3859 : && 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 1805 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16864 : VAR_INIT_STATUS_INITIALIZED);
16865 1805 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16866 : VAR_INIT_STATUS_INITIALIZED);
16867 :
16868 1805 : if (op0 == 0 || op1 == 0)
16869 : break;
16870 :
16871 1796 : mem_loc_result = op0;
16872 1796 : add_loc_descr (&mem_loc_result, op1);
16873 1796 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
16874 1796 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
16875 1796 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
16876 1796 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
16877 1796 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
16878 1796 : break;
16879 :
16880 7785 : case UDIV:
16881 0 : if ((!dwarf_strict || dwarf_version >= 5)
16882 7785 : && is_a <scalar_int_mode> (mode, &int_mode))
16883 : {
16884 : /* We can use a signed divide if the sign bit is not set. */
16885 16711 : if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
16886 : {
16887 4123 : op = DW_OP_div;
16888 4123 : goto do_binop;
16889 : }
16890 :
16891 3662 : 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 41936 : case NOT:
16898 41936 : op = DW_OP_not;
16899 41936 : goto do_unop;
16900 :
16901 2333 : case ABS:
16902 2333 : op = DW_OP_abs;
16903 2333 : goto do_unop;
16904 :
16905 87913 : case NEG:
16906 87913 : op = DW_OP_neg;
16907 87913 : goto do_unop;
16908 :
16909 132182 : do_unop:
16910 132182 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16911 : VAR_INIT_STATUS_INITIALIZED);
16912 :
16913 132182 : if (op0 == 0)
16914 : break;
16915 :
16916 131560 : mem_loc_result = op0;
16917 131560 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16918 131560 : break;
16919 :
16920 2067983 : case CONST_INT:
16921 2067983 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16922 2261133 : || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16923 : #ifdef POINTERS_EXTEND_UNSIGNED
16924 2142253 : || (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 2030240 : mem_loc_result = int_loc_descriptor (INTVAL (rtl));
16931 2030240 : break;
16932 : }
16933 0 : if ((!dwarf_strict || dwarf_version >= 5)
16934 75486 : && (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT
16935 1216 : || GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_DOUBLE_INT))
16936 : {
16937 37743 : dw_die_ref type_die = base_type_for_mode (int_mode, 1);
16938 37743 : scalar_int_mode amode;
16939 37743 : if (type_die == NULL)
16940 22999 : return NULL;
16941 37743 : if (INTVAL (rtl) >= 0
16942 106287 : && (int_mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT, 0)
16943 35782 : .exists (&amode))
16944 35782 : && 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 60742 : && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
16948 22999 : < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode))
16949 : {
16950 22999 : mem_loc_result = int_loc_descriptor (INTVAL (rtl));
16951 22999 : op0 = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16952 22999 : op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16953 22999 : op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16954 22999 : op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
16955 22999 : add_loc_descr (&mem_loc_result, op0);
16956 22999 : return mem_loc_result;
16957 : }
16958 29488 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0,
16959 14744 : INTVAL (rtl));
16960 14744 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16961 14744 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16962 14744 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
16963 29488 : if (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT)
16964 14587 : 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 31590 : case CONST_DOUBLE:
16976 31590 : if (!dwarf_strict || dwarf_version >= 5)
16977 : {
16978 31590 : 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 31590 : if (mode == VOIDmode
16989 31590 : || (GET_MODE (rtl) == VOIDmode
16990 0 : && maybe_ne (GET_MODE_BITSIZE (mode),
16991 0 : HOST_BITS_PER_DOUBLE_INT)))
16992 : break;
16993 31590 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16994 31590 : if (type_die == NULL)
16995 : return NULL;
16996 31590 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0, 0);
16997 31590 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16998 31590 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16999 31590 : 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 31590 : {
17011 31590 : scalar_float_mode float_mode = as_a <scalar_float_mode> (mode);
17012 31590 : unsigned int length = GET_MODE_SIZE (float_mode);
17013 31590 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
17014 31590 : unsigned int elt_size = insert_float (rtl, array);
17015 :
17016 31590 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17017 31590 : mem_loc_result->dw_loc_oprnd2.v.val_vec.length
17018 31590 : = length / elt_size;
17019 31590 : mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17020 31590 : 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 28889 : case EQ:
17049 28889 : mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
17050 28889 : break;
17051 :
17052 4884 : case GE:
17053 4884 : mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
17054 4884 : break;
17055 :
17056 4316 : case GT:
17057 4316 : mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
17058 4316 : break;
17059 :
17060 2273 : case LE:
17061 2273 : mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
17062 2273 : break;
17063 :
17064 5369 : case LT:
17065 5369 : mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
17066 5369 : break;
17067 :
17068 47789 : case NE:
17069 47789 : mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
17070 47789 : break;
17071 :
17072 5747 : case GEU:
17073 5747 : mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
17074 5747 : break;
17075 :
17076 7459 : case GTU:
17077 7459 : mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
17078 7459 : break;
17079 :
17080 16095 : case LEU:
17081 16095 : mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
17082 16095 : break;
17083 :
17084 3047 : case LTU:
17085 3047 : mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
17086 3047 : break;
17087 :
17088 127432 : case UMIN:
17089 127432 : case UMAX:
17090 127432 : if (!SCALAR_INT_MODE_P (mode))
17091 : break;
17092 : /* FALLTHRU */
17093 145324 : case SMIN:
17094 145324 : case SMAX:
17095 145324 : mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
17096 145324 : break;
17097 :
17098 4054 : case ZERO_EXTRACT:
17099 4054 : case SIGN_EXTRACT:
17100 4054 : if (CONST_INT_P (XEXP (rtl, 1))
17101 4054 : && CONST_INT_P (XEXP (rtl, 2))
17102 4054 : && is_a <scalar_int_mode> (mode, &int_mode)
17103 4046 : && 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 4054 : && ((unsigned) INTVAL (XEXP (rtl, 1))
17107 2621 : + (unsigned) INTVAL (XEXP (rtl, 2))
17108 2621 : <= GET_MODE_BITSIZE (int_mode)))
17109 : {
17110 2518 : int shift, size;
17111 2518 : op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
17112 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
17113 2518 : if (op0 == 0)
17114 : break;
17115 2518 : if (GET_CODE (rtl) == SIGN_EXTRACT)
17116 : op = DW_OP_shra;
17117 : else
17118 578 : op = DW_OP_shr;
17119 2518 : mem_loc_result = op0;
17120 2518 : size = INTVAL (XEXP (rtl, 1));
17121 2518 : shift = INTVAL (XEXP (rtl, 2));
17122 2518 : if (BITS_BIG_ENDIAN)
17123 : shift = GET_MODE_BITSIZE (inner_mode) - shift - size;
17124 2767 : if (shift + size != (int) DWARF2_ADDR_SIZE)
17125 : {
17126 2469 : add_loc_descr (&mem_loc_result,
17127 2469 : int_loc_descriptor (DWARF2_ADDR_SIZE
17128 2469 : - shift - size));
17129 2469 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
17130 : }
17131 2767 : if (size != (int) DWARF2_ADDR_SIZE)
17132 : {
17133 2211 : add_loc_descr (&mem_loc_result,
17134 2458 : int_loc_descriptor (DWARF2_ADDR_SIZE - size));
17135 2211 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
17136 : }
17137 : }
17138 : break;
17139 :
17140 30470 : case IF_THEN_ELSE:
17141 30470 : {
17142 30470 : dw_loc_descr_ref op2, bra_node, drop_node;
17143 30470 : op0 = mem_loc_descriptor (XEXP (rtl, 0),
17144 30470 : GET_MODE (XEXP (rtl, 0)) == VOIDmode
17145 28618 : ? word_mode : GET_MODE (XEXP (rtl, 0)),
17146 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
17147 30470 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
17148 : VAR_INIT_STATUS_INITIALIZED);
17149 30470 : op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
17150 : VAR_INIT_STATUS_INITIALIZED);
17151 30470 : if (op0 == NULL || op1 == NULL || op2 == NULL)
17152 : break;
17153 :
17154 29792 : mem_loc_result = op1;
17155 29792 : add_loc_descr (&mem_loc_result, op2);
17156 29792 : add_loc_descr (&mem_loc_result, op0);
17157 29792 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
17158 29792 : add_loc_descr (&mem_loc_result, bra_node);
17159 29792 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
17160 29792 : drop_node = new_loc_descr (DW_OP_drop, 0, 0);
17161 29792 : add_loc_descr (&mem_loc_result, drop_node);
17162 29792 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
17163 29792 : bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
17164 : }
17165 29792 : break;
17166 :
17167 24400 : case FLOAT_EXTEND:
17168 24400 : case FLOAT_TRUNCATE:
17169 24400 : case FLOAT:
17170 24400 : case UNSIGNED_FLOAT:
17171 24400 : case FIX:
17172 24400 : case UNSIGNED_FIX:
17173 24400 : if (!dwarf_strict || dwarf_version >= 5)
17174 : {
17175 24400 : dw_die_ref type_die;
17176 24400 : dw_loc_descr_ref cvt;
17177 :
17178 24400 : op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
17179 : mem_mode, VAR_INIT_STATUS_INITIALIZED);
17180 24400 : if (op0 == NULL)
17181 : break;
17182 24237 : if (is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &int_mode)
17183 24237 : && (GET_CODE (rtl) == FLOAT
17184 1487 : || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE))
17185 : {
17186 5237 : type_die = base_type_for_mode (int_mode,
17187 : GET_CODE (rtl) == UNSIGNED_FLOAT);
17188 5237 : if (type_die == NULL)
17189 : break;
17190 5237 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
17191 5237 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17192 5237 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
17193 5237 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
17194 5237 : add_loc_descr (&op0, cvt);
17195 : }
17196 24237 : type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
17197 24237 : if (type_die == NULL)
17198 : break;
17199 24237 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
17200 24237 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17201 24237 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
17202 24237 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
17203 24237 : add_loc_descr (&op0, cvt);
17204 24237 : if (is_a <scalar_int_mode> (mode, &int_mode)
17205 24237 : && (GET_CODE (rtl) == FIX
17206 59 : || GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE))
17207 : {
17208 1629 : op0 = convert_descriptor_to_mode (int_mode, op0);
17209 1629 : if (op0 == NULL)
17210 : break;
17211 : }
17212 24237 : mem_loc_result = op0;
17213 : }
17214 : break;
17215 :
17216 5265 : case CLZ:
17217 5265 : case CTZ:
17218 5265 : case FFS:
17219 5265 : if (is_a <scalar_int_mode> (mode, &int_mode))
17220 5265 : 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 168 : case BSWAP:
17230 168 : if (is_a <scalar_int_mode> (mode, &int_mode))
17231 168 : 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 122389 : case CONST_STRING:
17292 122389 : resolve_one_addr (&rtl);
17293 122389 : 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 23819674 : if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
17345 10616 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
17346 :
17347 23819674 : 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 37385 : concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
17388 : {
17389 37385 : unsigned int i;
17390 37385 : dw_loc_descr_ref cc_loc_result = NULL;
17391 37385 : unsigned int n = XVECLEN (concatn, 0);
17392 37385 : unsigned int size;
17393 :
17394 82394 : for (i = 0; i < n; ++i)
17395 : {
17396 63251 : dw_loc_descr_ref ref;
17397 63251 : rtx x = XVECEXP (concatn, 0, i);
17398 :
17399 : /* At present we only track constant-sized pieces. */
17400 126502 : if (!GET_MODE_SIZE (GET_MODE (x)).is_constant (&size))
17401 : return NULL;
17402 :
17403 63251 : ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
17404 63251 : if (ref == NULL)
17405 : return NULL;
17406 :
17407 45009 : add_loc_descr (&cc_loc_result, ref);
17408 45009 : add_loc_descr_op_piece (&cc_loc_result, size);
17409 : }
17410 :
17411 19143 : 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 19143 : 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 1836346 : implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
17422 : {
17423 1836346 : dw_loc_descr_ref ret;
17424 1836346 : dw_die_ref ref;
17425 :
17426 1836346 : if (dwarf_strict && dwarf_version < 5)
17427 : return NULL;
17428 1836346 : 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 1836346 : ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
17432 1836749 : ret = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
17433 1836346 : ret->dw_loc_oprnd2.val_class = dw_val_class_const;
17434 1836346 : if (ref)
17435 : {
17436 1102491 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17437 1102491 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
17438 1102491 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
17439 : }
17440 : else
17441 : {
17442 733855 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
17443 733855 : 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 55414521 : loc_descriptor (rtx rtl, machine_mode mode,
17462 : enum var_init_status initialized)
17463 : {
17464 55414521 : dw_loc_descr_ref loc_result = NULL;
17465 55414521 : scalar_int_mode int_mode;
17466 :
17467 55414521 : switch (GET_CODE (rtl))
17468 : {
17469 141585 : 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 141585 : 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 141569 : goto do_default;
17480 16 : break;
17481 :
17482 11391517 : case REG:
17483 11391517 : loc_result = reg_loc_descriptor (rtl, initialized);
17484 11391517 : break;
17485 :
17486 3792024 : case MEM:
17487 3792024 : loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
17488 3792024 : GET_MODE (rtl), initialized);
17489 3792024 : if (loc_result == NULL)
17490 10179 : loc_result = tls_mem_loc_descriptor (rtl);
17491 3792024 : if (loc_result == NULL)
17492 : {
17493 10179 : rtx new_rtl = avoid_constant_pool_reference (rtl);
17494 10179 : 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 37385 : case CONCATN:
17505 37385 : loc_result = concatn_loc_descriptor (rtl, initialized);
17506 37385 : break;
17507 :
17508 27252174 : case VAR_LOCATION:
17509 : /* Single part. */
17510 27252174 : if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
17511 : {
17512 27104317 : rtx loc = PAT_VAR_LOCATION_LOC (rtl);
17513 27104317 : if (GET_CODE (loc) == EXPR_LIST)
17514 0 : loc = XEXP (loc, 0);
17515 27104317 : loc_result = loc_descriptor (loc, mode, initialized);
17516 27104317 : break;
17517 : }
17518 :
17519 147857 : rtl = XEXP (rtl, 1);
17520 : /* FALLTHRU */
17521 :
17522 148176 : case PARALLEL:
17523 148176 : {
17524 148176 : rtvec par_elems = XVEC (rtl, 0);
17525 148176 : int num_elem = GET_NUM_ELEM (par_elems);
17526 148176 : machine_mode mode;
17527 148176 : int i, size;
17528 :
17529 : /* Create the first one, so we have something to add to. */
17530 148176 : loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
17531 : VOIDmode, initialized);
17532 148176 : if (loc_result == NULL)
17533 55414521 : return NULL;
17534 148176 : mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
17535 : /* At present we only track constant-sized pieces. */
17536 296352 : if (!GET_MODE_SIZE (mode).is_constant (&size))
17537 : return NULL;
17538 148176 : add_loc_descr_op_piece (&loc_result, size);
17539 296350 : for (i = 1; i < num_elem; i++)
17540 : {
17541 148174 : dw_loc_descr_ref temp;
17542 :
17543 148174 : temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
17544 : VOIDmode, initialized);
17545 148174 : if (temp == NULL)
17546 : return NULL;
17547 148174 : add_loc_descr (&loc_result, temp);
17548 148174 : mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
17549 : /* At present we only track constant-sized pieces. */
17550 296348 : if (!GET_MODE_SIZE (mode).is_constant (&size))
17551 : return NULL;
17552 148174 : add_loc_descr_op_piece (&loc_result, size);
17553 : }
17554 : }
17555 : break;
17556 :
17557 2884752 : case CONST_INT:
17558 2884752 : if (mode != VOIDmode && mode != BLKmode)
17559 : {
17560 2878092 : int_mode = as_a <scalar_int_mode> (mode);
17561 5756184 : loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode),
17562 : INTVAL (rtl));
17563 : }
17564 : break;
17565 :
17566 51716 : case CONST_DOUBLE:
17567 51716 : if (mode == VOIDmode)
17568 12757 : mode = GET_MODE (rtl);
17569 :
17570 51716 : if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
17571 : {
17572 51716 : 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 51716 : scalar_mode smode = as_a <scalar_mode> (mode);
17579 51716 : loc_result = new_loc_descr (DW_OP_implicit_value,
17580 51716 : 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 51716 : {
17591 51716 : unsigned int length = GET_MODE_SIZE (smode);
17592 51716 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
17593 51716 : unsigned int elt_size = insert_float (rtl, array);
17594 :
17595 51716 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17596 51716 : loc_result->dw_loc_oprnd2.v.val_vec.length = length / elt_size;
17597 51716 : loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17598 51716 : 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 4 : case CONST_VECTOR:
17619 4 : 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 4 : && GET_MODE_CLASS (mode) != MODE_VECTOR_BOOL
17627 4 : && (dwarf_version >= 4 || !dwarf_strict))
17628 : {
17629 4 : unsigned int length;
17630 8 : if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
17631 : return NULL;
17632 :
17633 4 : unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
17634 4 : unsigned char *array
17635 4 : = ggc_vec_alloc<unsigned char> (length * elt_size);
17636 4 : unsigned int i;
17637 4 : unsigned char *p;
17638 4 : machine_mode imode = GET_MODE_INNER (mode);
17639 :
17640 4 : gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
17641 4 : switch (GET_MODE_CLASS (mode))
17642 : {
17643 : case MODE_VECTOR_INT:
17644 10 : for (i = 0, p = array; i < length; i++, p += elt_size)
17645 : {
17646 8 : rtx elt = CONST_VECTOR_ELT (rtl, i);
17647 8 : 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 4 : loc_result = new_loc_descr (DW_OP_implicit_value,
17664 : length * elt_size, 0);
17665 4 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17666 4 : loc_result->dw_loc_oprnd2.v.val_vec.length = length;
17667 4 : loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17668 4 : loc_result->dw_loc_oprnd2.v.val_vec.array = array;
17669 : }
17670 : break;
17671 :
17672 95920 : case CONST:
17673 95920 : if (mode == VOIDmode
17674 95920 : || CONST_SCALAR_INT_P (XEXP (rtl, 0))
17675 95920 : || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
17676 95920 : || 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 523421 : case SYMBOL_REF:
17683 523421 : if (!const_ok_for_output (rtl))
17684 : break;
17685 : /* FALLTHROUGH */
17686 485796 : case LABEL_REF:
17687 485796 : if (is_a <scalar_int_mode> (mode, &int_mode)
17688 520129 : && GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE
17689 485794 : && (dwarf_version >= 4 || !dwarf_strict))
17690 : {
17691 485794 : loc_result = new_addr_loc_descr (rtl, dtprel_false);
17692 485794 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
17693 485794 : vec_safe_push (used_rtx_array, rtl);
17694 : }
17695 : break;
17696 :
17697 1732028 : case DEBUG_IMPLICIT_PTR:
17698 1732028 : loc_result = implicit_ptr_descriptor (rtl, 0);
17699 1732028 : break;
17700 :
17701 5625699 : case PLUS:
17702 5625699 : if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
17703 104318 : && CONST_INT_P (XEXP (rtl, 1)))
17704 : {
17705 104318 : loc_result
17706 104318 : = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
17707 104318 : break;
17708 : }
17709 : /* FALLTHRU */
17710 5521381 : do_default:
17711 7622775 : default:
17712 7622775 : if ((is_a <scalar_int_mode> (mode, &int_mode)
17713 7572359 : && GET_MODE (rtl) == int_mode
17714 7953001 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
17715 7524942 : && dwarf_version >= 4)
17716 100328 : || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
17717 : {
17718 : /* Value expression. */
17719 7619688 : loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
17720 7619688 : if (loc_result)
17721 15139228 : add_loc_descr (&loc_result,
17722 : new_loc_descr (DW_OP_stack_value, 0, 0));
17723 : }
17724 : break;
17725 : }
17726 :
17727 55414521 : 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 16606217 : secname_for_decl (const_tree decl)
17739 : {
17740 16606217 : const char *secname;
17741 :
17742 951051 : if (VAR_OR_FUNCTION_DECL_P (decl)
17743 15658557 : && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
17744 16609608 : && DECL_SECTION_NAME (decl))
17745 496 : secname = DECL_SECTION_NAME (decl);
17746 16605721 : else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
17747 : {
17748 14465486 : if (in_cold_section_p)
17749 : {
17750 3630569 : section *sec = current_function_section ();
17751 3630569 : if (sec->common.flags & SECTION_NAMED)
17752 3630569 : return sec->named.name;
17753 : }
17754 10834917 : secname = DECL_SECTION_NAME (current_function_decl);
17755 : }
17756 2140235 : else if (cfun && in_cold_section_p)
17757 63146 : 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 145964397 : decl_by_reference_p (tree decl)
17768 : {
17769 145964397 : return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
17770 : || VAR_P (decl))
17771 145964397 : && 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 27572932 : dw_loc_list_1 (tree loc, rtx varloc, int want_address,
17779 : enum var_init_status initialized)
17780 : {
17781 27572932 : int have_address = 0;
17782 27572932 : dw_loc_descr_ref descr;
17783 27572932 : machine_mode mode;
17784 :
17785 27572932 : if (want_address != 2)
17786 : {
17787 320758 : gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
17788 : /* Single part. */
17789 320758 : if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
17790 : {
17791 320758 : varloc = PAT_VAR_LOCATION_LOC (varloc);
17792 320758 : if (GET_CODE (varloc) == EXPR_LIST)
17793 0 : varloc = XEXP (varloc, 0);
17794 320758 : mode = GET_MODE (varloc);
17795 320758 : if (MEM_P (varloc))
17796 : {
17797 12072 : rtx addr = XEXP (varloc, 0);
17798 12072 : descr = mem_loc_descriptor (addr, get_address_mode (varloc),
17799 : mode, initialized);
17800 12072 : 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 308686 : descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
17812 : }
17813 : else
17814 : return 0;
17815 : }
17816 : else
17817 : {
17818 27252174 : if (GET_CODE (varloc) == VAR_LOCATION)
17819 27252174 : mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
17820 : else
17821 0 : mode = DECL_MODE (loc);
17822 27252174 : descr = loc_descriptor (varloc, mode, initialized);
17823 27252174 : have_address = 1;
17824 : }
17825 :
17826 27572932 : if (!descr)
17827 : return 0;
17828 :
17829 27339010 : 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 27339010 : 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 27339010 : if (!want_address && have_address)
17851 : {
17852 12072 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
17853 12072 : enum dwarf_location_atom op;
17854 :
17855 14085 : 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 14085 : else if (size == DWARF2_ADDR_SIZE)
17862 : op = DW_OP_deref;
17863 : else
17864 0 : op = DW_OP_deref_size;
17865 :
17866 24144 : add_loc_descr (&descr, new_loc_descr (op, size, 0));
17867 : }
17868 :
17869 27339010 : 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 4686149 : new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
17877 : {
17878 4686149 : if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
17879 4510823 : return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
17880 175326 : else if (dwarf_version >= 3 || !dwarf_strict)
17881 175326 : 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 2986726 : dw_sra_loc_expr (tree decl, rtx loc)
17891 : {
17892 2986726 : rtx p;
17893 2986726 : unsigned HOST_WIDE_INT padsize = 0;
17894 2986726 : dw_loc_descr_ref descr, *descr_tail;
17895 2986726 : unsigned HOST_WIDE_INT decl_size;
17896 2986726 : rtx varloc;
17897 2986726 : enum var_init_status initialized;
17898 :
17899 2986726 : if (DECL_SIZE (decl) == NULL
17900 2986726 : || !tree_fits_uhwi_p (DECL_SIZE (decl)))
17901 : return NULL;
17902 :
17903 2986726 : decl_size = tree_to_uhwi (DECL_SIZE (decl));
17904 2986726 : descr = NULL;
17905 2986726 : descr_tail = &descr;
17906 :
17907 9650650 : for (p = loc; p; p = XEXP (p, 1))
17908 : {
17909 6664308 : unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
17910 6664308 : rtx loc_note = *decl_piece_varloc_ptr (p);
17911 6664308 : dw_loc_descr_ref cur_descr;
17912 6664308 : dw_loc_descr_ref *tail, last = NULL;
17913 6664308 : unsigned HOST_WIDE_INT opsize = 0;
17914 :
17915 6664308 : if (loc_note == NULL_RTX
17916 6224475 : || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
17917 : {
17918 3036597 : padsize += bitsize;
17919 3048805 : continue;
17920 : }
17921 3627711 : initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
17922 3627711 : varloc = NOTE_VAR_LOCATION (loc_note);
17923 3627711 : cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
17924 3627711 : if (cur_descr == NULL)
17925 : {
17926 12208 : padsize += bitsize;
17927 12208 : 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 8645688 : for (tail = &cur_descr; *tail != NULL;
17934 5030185 : tail = &(*tail)->dw_loc_next)
17935 5030185 : if ((*tail)->dw_loc_opc == DW_OP_piece)
17936 : {
17937 16756 : opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
17938 16756 : * BITS_PER_UNIT;
17939 16756 : last = *tail;
17940 : }
17941 5013429 : 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 3615503 : 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 3615503 : if (padsize)
17959 : {
17960 501351 : if (padsize > decl_size)
17961 : {
17962 0 : remove_loc_list_addr_table_entries (cur_descr);
17963 384 : goto discard_descr;
17964 : }
17965 501351 : decl_size -= padsize;
17966 501351 : *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
17967 501351 : if (*descr_tail == NULL)
17968 : {
17969 0 : remove_loc_list_addr_table_entries (cur_descr);
17970 0 : goto discard_descr;
17971 : }
17972 501351 : descr_tail = &(*descr_tail)->dw_loc_next;
17973 501351 : padsize = 0;
17974 : }
17975 3615503 : *descr_tail = cur_descr;
17976 3615503 : descr_tail = tail;
17977 3615503 : if (bitsize > decl_size)
17978 0 : goto discard_descr;
17979 3615503 : decl_size -= bitsize;
17980 3615503 : if (last == NULL)
17981 : {
17982 3607125 : HOST_WIDE_INT offset = 0;
17983 3607125 : if (GET_CODE (varloc) == VAR_LOCATION
17984 3607125 : && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
17985 : {
17986 3607125 : varloc = PAT_VAR_LOCATION_LOC (varloc);
17987 3607125 : if (GET_CODE (varloc) == EXPR_LIST)
17988 0 : varloc = XEXP (varloc, 0);
17989 : }
17990 3610527 : do
17991 : {
17992 3610527 : if (GET_CODE (varloc) == CONST
17993 3609448 : || GET_CODE (varloc) == SIGN_EXTEND
17994 3609076 : || GET_CODE (varloc) == ZERO_EXTEND)
17995 2050 : varloc = XEXP (varloc, 0);
17996 3608477 : else if (GET_CODE (varloc) == SUBREG)
17997 1352 : 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 3607125 : if (MEM_P (varloc))
18007 : {
18008 1029451 : unsigned HOST_WIDE_INT memsize;
18009 1029454 : if (!poly_uint64 (MEM_SIZE (varloc)).is_constant (&memsize))
18010 384 : goto discard_descr;
18011 1029451 : memsize *= BITS_PER_UNIT;
18012 1029451 : if (memsize != bitsize)
18013 : {
18014 2558 : if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
18015 : && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
18016 : goto discard_descr;
18017 2558 : if (memsize < bitsize)
18018 384 : goto discard_descr;
18019 : if (BITS_BIG_ENDIAN)
18020 : offset = memsize - bitsize;
18021 : }
18022 : }
18023 :
18024 3606741 : *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
18025 3606741 : if (*descr_tail == NULL)
18026 0 : goto discard_descr;
18027 3606741 : 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 2986342 : if (descr != NULL && decl_size != 0)
18034 : {
18035 578057 : *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
18036 578057 : if (*descr_tail == NULL)
18037 0 : goto discard_descr;
18038 : }
18039 2986342 : return descr;
18040 :
18041 384 : discard_descr:
18042 : /* Discard the descriptor and release any addr_table entries it uses. */
18043 384 : remove_loc_list_addr_table_entries (descr);
18044 384 : 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 13168609 : dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
18053 : {
18054 13168609 : const char *endname, *secname;
18055 13168609 : var_loc_view endview;
18056 13168609 : rtx varloc;
18057 13168609 : enum var_init_status initialized;
18058 13168609 : struct var_loc_node *node;
18059 13168609 : dw_loc_descr_ref descr;
18060 13168609 : char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
18061 13168609 : dw_loc_list_ref list = NULL;
18062 13168609 : 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 13168609 : if (cfun && crtl->has_bb_partition)
18076 : {
18077 3693658 : bool save_in_cold_section_p = in_cold_section_p;
18078 3693658 : in_cold_section_p = first_function_block_is_cold;
18079 3693658 : if (loc_list->last_before_switch == NULL)
18080 259441 : in_cold_section_p = !in_cold_section_p;
18081 3693658 : secname = secname_for_decl (decl);
18082 3693658 : in_cold_section_p = save_in_cold_section_p;
18083 3693658 : }
18084 : else
18085 9474951 : secname = secname_for_decl (decl);
18086 :
18087 60855640 : for (node = loc_list->first; node; node = node->next)
18088 : {
18089 47687031 : bool range_across_switch = false;
18090 47687031 : if (GET_CODE (node->loc) == EXPR_LIST
18091 44705567 : || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
18092 : {
18093 26809455 : if (GET_CODE (node->loc) == EXPR_LIST)
18094 : {
18095 2981464 : descr = NULL;
18096 : /* This requires DW_OP_{,bit_}piece, which is not usable
18097 : inside DWARF expressions. */
18098 2981464 : if (want_address == 2)
18099 2981464 : descr = dw_sra_loc_expr (decl, node->loc);
18100 : }
18101 : else
18102 : {
18103 23827991 : initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
18104 23827991 : varloc = NOTE_VAR_LOCATION (node->loc);
18105 23827991 : descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
18106 : }
18107 26809455 : 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 25498047 : if (node == loc_list->last_before_switch
18116 125143 : && (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 7051 : || !ZERO_VIEW_P (node->view))
18123 25620539 : && current_function_decl)
18124 : {
18125 122492 : endname = cfun->fde->dw_fde_end;
18126 122492 : endview = 0;
18127 122492 : range_across_switch = true;
18128 : }
18129 : /* The variable has a location between NODE->LABEL and
18130 : NODE->NEXT->LABEL. */
18131 25375555 : else if (node->next)
18132 24024329 : 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 1351226 : else if (!current_function_decl)
18136 : endname = text_end_label, endview = 0;
18137 : else
18138 : {
18139 1351226 : ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
18140 : current_function_funcdef_no);
18141 1351226 : endname = ggc_strdup (label_id);
18142 1351226 : endview = 0;
18143 : }
18144 :
18145 25498047 : *listp = new_loc_list (descr, node->label, node->view,
18146 : endname, endview, secname);
18147 25498047 : if (TREE_CODE (decl) == PARM_DECL
18148 3185807 : && node == loc_list->first
18149 912996 : && NOTE_P (node->loc)
18150 904292 : && strcmp (node->label, endname) == 0)
18151 410 : (*listp)->force = true;
18152 25498047 : listp = &(*listp)->dw_loc_next;
18153 : }
18154 : }
18155 :
18156 47687031 : if (cfun
18157 47687031 : && crtl->has_bb_partition
18158 13441051 : && node == loc_list->last_before_switch)
18159 : {
18160 3434217 : bool save_in_cold_section_p = in_cold_section_p;
18161 3434217 : in_cold_section_p = !first_function_block_is_cold;
18162 3434217 : secname = secname_for_decl (decl);
18163 3434217 : in_cold_section_p = save_in_cold_section_p;
18164 : }
18165 :
18166 47687031 : if (range_across_switch)
18167 : {
18168 122492 : if (GET_CODE (node->loc) == EXPR_LIST)
18169 5262 : descr = dw_sra_loc_expr (decl, node->loc);
18170 : else
18171 : {
18172 117230 : initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
18173 117230 : varloc = NOTE_VAR_LOCATION (node->loc);
18174 117230 : descr = dw_loc_list_1 (decl, varloc, want_address,
18175 : initialized);
18176 : }
18177 122492 : gcc_assert (descr);
18178 : /* The variable has a location between NODE->LABEL and
18179 : NODE->NEXT->LABEL. */
18180 122492 : if (node->next)
18181 85922 : endname = node->next->label, endview = node->next->view;
18182 : else
18183 36570 : endname = cfun->fde->dw_fde_second_end, endview = 0;
18184 122492 : *listp = new_loc_list (descr, cfun->fde->dw_fde_second_begin, 0,
18185 : endname, endview, secname);
18186 122492 : 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 13168609 : if (list && loc_list->first->next)
18197 11874491 : gen_llsym (list);
18198 : else
18199 1294118 : maybe_gen_llsym (list);
18200 :
18201 13168609 : 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 12988962 : single_element_loc_list_p (dw_loc_list_ref list)
18209 : {
18210 12988962 : gcc_assert (!list->dw_loc_next || list->ll_symbol);
18211 12988962 : return !list->ll_symbol;
18212 : }
18213 :
18214 : /* Duplicate a single element of location list. */
18215 :
18216 : static inline dw_loc_descr_ref
18217 43491 : copy_loc_descr (dw_loc_descr_ref ref)
18218 : {
18219 43491 : dw_loc_descr_ref copy = ggc_alloc<dw_loc_descr_node> ();
18220 43491 : memcpy (copy, ref, sizeof (dw_loc_descr_node));
18221 43491 : return copy;
18222 : }
18223 :
18224 : /* To each location in list LIST append loc descr REF. */
18225 :
18226 : static void
18227 253438 : add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
18228 : {
18229 253438 : dw_loc_descr_ref copy;
18230 253438 : add_loc_descr (&list->expr, ref);
18231 253438 : list = list->dw_loc_next;
18232 296929 : while (list)
18233 : {
18234 43491 : copy = copy_loc_descr (ref);
18235 43491 : add_loc_descr (&list->expr, copy);
18236 43491 : while (copy->dw_loc_next)
18237 0 : copy = copy->dw_loc_next = copy_loc_descr (copy->dw_loc_next);
18238 43491 : list = list->dw_loc_next;
18239 : }
18240 253438 : }
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 48466 : add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
18276 : {
18277 48466 : if (!list)
18278 : return;
18279 48466 : if (!*ret)
18280 : {
18281 0 : *ret = list;
18282 0 : return;
18283 : }
18284 48466 : if (!list->dw_loc_next)
18285 : {
18286 48466 : add_loc_descr_to_each (*ret, list->expr);
18287 48466 : 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 11296 : cst_pool_loc_descr (tree loc)
18307 : {
18308 : /* Get an RTL for this, if something has been emitted. */
18309 11296 : rtx rtl = lookup_constant_def (loc);
18310 :
18311 11296 : if (!rtl || !MEM_P (rtl))
18312 : {
18313 0 : gcc_assert (!rtl);
18314 : return 0;
18315 : }
18316 10179 : 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 10179 : 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 10179 : return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
18328 10179 : 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 156 : loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
18339 : loc_descr_context *context)
18340 : {
18341 156 : tree obj, offset;
18342 156 : poly_int64 bitsize, bitpos, bytepos;
18343 156 : machine_mode mode;
18344 156 : int unsignedp, reversep, volatilep = 0;
18345 156 : dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
18346 :
18347 156 : obj = get_inner_reference (TREE_OPERAND (loc, 0),
18348 : &bitsize, &bitpos, &offset, &mode,
18349 : &unsignedp, &reversep, &volatilep);
18350 156 : STRIP_NOPS (obj);
18351 312 : if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
18352 : {
18353 0 : expansion_failed (loc, NULL_RTX, "bitfield access");
18354 0 : return 0;
18355 : }
18356 156 : if (!INDIRECT_REF_P (obj))
18357 : {
18358 156 : expansion_failed (obj,
18359 : NULL_RTX, "no indirect ref in inner refrence");
18360 156 : 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 156 : 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 56790139 : loc_descr_to_next_no_nop (dw_loc_descr_ref &loc,
18402 : hash_set<dw_loc_descr_ref> &nops)
18403 : {
18404 56799967 : while (loc->dw_loc_next != NULL && loc->dw_loc_opc == DW_OP_nop)
18405 : {
18406 9828 : nops.add (loc);
18407 9828 : loc = loc->dw_loc_next;
18408 : }
18409 56790139 : }
18410 :
18411 : /* Helper for loc_descr_without_nops: free the location description operation
18412 : P. */
18413 :
18414 : bool
18415 4914 : free_loc_descr (const dw_loc_descr_ref &loc, void *data ATTRIBUTE_UNUSED)
18416 : {
18417 4914 : ggc_free (loc);
18418 4914 : 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 26342146 : loc_descr_without_nops (dw_loc_descr_ref &loc)
18426 : {
18427 26342146 : 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 26342146 : 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 26342146 : loc_descr_to_next_no_nop (loc, nops);
18436 :
18437 81656706 : for (dw_loc_descr_ref cur = loc; cur != NULL;)
18438 : {
18439 : /* For control flow operations: strip "prefix" nops in destination
18440 : labels. */
18441 55314560 : if (cur->dw_loc_oprnd1.val_class == dw_val_class_loc)
18442 1475579 : loc_descr_to_next_no_nop (cur->dw_loc_oprnd1.v.val_loc, nops);
18443 55314560 : 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 55314560 : if (cur->dw_loc_next != NULL)
18449 28972414 : loc_descr_to_next_no_nop (cur->dw_loc_next, nops);
18450 55314560 : cur = cur->dw_loc_next;
18451 : }
18452 :
18453 26347060 : nops.traverse<void *, free_loc_descr> (NULL);
18454 26342146 : }
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 3075 : 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 3075 : unsigned frame_offset_ = initial_frame_offset;
18569 3075 : dw_loc_descr_ref l;
18570 :
18571 29824 : for (l = loc; l != NULL;)
18572 : {
18573 26749 : bool existed;
18574 26749 : 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 26749 : 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 26749 : l_frame_offset = frame_offset_;
18585 :
18586 : /* If needed, relocate the picking offset with respect to the frame
18587 : offset. */
18588 26749 : if (l->dw_loc_frame_offset_rel)
18589 : {
18590 3075 : unsigned HOST_WIDE_INT off;
18591 3075 : switch (l->dw_loc_opc)
18592 : {
18593 3075 : case DW_OP_pick:
18594 3075 : off = l->dw_loc_oprnd1.v.val_unsigned;
18595 3075 : 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 3075 : off += frame_offset_ - dpi->args_count;
18616 :
18617 : /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
18618 3075 : if (off > 255)
18619 0 : return false;
18620 :
18621 3075 : 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 3075 : else if (off == 1)
18627 : {
18628 3075 : l->dw_loc_opc = DW_OP_over;
18629 3075 : 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 26749 : 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 10250 : case DW_OP_addr:
18698 10250 : case DW_OP_const1u:
18699 10250 : case DW_OP_const1s:
18700 10250 : case DW_OP_const2u:
18701 10250 : case DW_OP_const2s:
18702 10250 : case DW_OP_const4u:
18703 10250 : case DW_OP_const4s:
18704 10250 : case DW_OP_const8u:
18705 10250 : case DW_OP_const8s:
18706 10250 : case DW_OP_constu:
18707 10250 : case DW_OP_consts:
18708 10250 : case DW_OP_dup:
18709 10250 : case DW_OP_over:
18710 10250 : case DW_OP_pick:
18711 10250 : case DW_OP_lit0:
18712 10250 : case DW_OP_lit1:
18713 10250 : case DW_OP_lit2:
18714 10250 : case DW_OP_lit3:
18715 10250 : case DW_OP_lit4:
18716 10250 : case DW_OP_lit5:
18717 10250 : case DW_OP_lit6:
18718 10250 : case DW_OP_lit7:
18719 10250 : case DW_OP_lit8:
18720 10250 : case DW_OP_lit9:
18721 10250 : case DW_OP_lit10:
18722 10250 : case DW_OP_lit11:
18723 10250 : case DW_OP_lit12:
18724 10250 : case DW_OP_lit13:
18725 10250 : case DW_OP_lit14:
18726 10250 : case DW_OP_lit15:
18727 10250 : case DW_OP_lit16:
18728 10250 : case DW_OP_lit17:
18729 10250 : case DW_OP_lit18:
18730 10250 : case DW_OP_lit19:
18731 10250 : case DW_OP_lit20:
18732 10250 : case DW_OP_lit21:
18733 10250 : case DW_OP_lit22:
18734 10250 : case DW_OP_lit23:
18735 10250 : case DW_OP_lit24:
18736 10250 : case DW_OP_lit25:
18737 10250 : case DW_OP_lit26:
18738 10250 : case DW_OP_lit27:
18739 10250 : case DW_OP_lit28:
18740 10250 : case DW_OP_lit29:
18741 10250 : case DW_OP_lit30:
18742 10250 : case DW_OP_lit31:
18743 10250 : case DW_OP_breg0:
18744 10250 : case DW_OP_breg1:
18745 10250 : case DW_OP_breg2:
18746 10250 : case DW_OP_breg3:
18747 10250 : case DW_OP_breg4:
18748 10250 : case DW_OP_breg5:
18749 10250 : case DW_OP_breg6:
18750 10250 : case DW_OP_breg7:
18751 10250 : case DW_OP_breg8:
18752 10250 : case DW_OP_breg9:
18753 10250 : case DW_OP_breg10:
18754 10250 : case DW_OP_breg11:
18755 10250 : case DW_OP_breg12:
18756 10250 : case DW_OP_breg13:
18757 10250 : case DW_OP_breg14:
18758 10250 : case DW_OP_breg15:
18759 10250 : case DW_OP_breg16:
18760 10250 : case DW_OP_breg17:
18761 10250 : case DW_OP_breg18:
18762 10250 : case DW_OP_breg19:
18763 10250 : case DW_OP_breg20:
18764 10250 : case DW_OP_breg21:
18765 10250 : case DW_OP_breg22:
18766 10250 : case DW_OP_breg23:
18767 10250 : case DW_OP_breg24:
18768 10250 : case DW_OP_breg25:
18769 10250 : case DW_OP_breg26:
18770 10250 : case DW_OP_breg27:
18771 10250 : case DW_OP_breg28:
18772 10250 : case DW_OP_breg29:
18773 10250 : case DW_OP_breg30:
18774 10250 : case DW_OP_breg31:
18775 10250 : case DW_OP_fbreg:
18776 10250 : case DW_OP_push_object_address:
18777 10250 : case DW_OP_call_frame_cfa:
18778 10250 : case DW_OP_GNU_variable_value:
18779 10250 : case DW_OP_GNU_addr_index:
18780 10250 : case DW_OP_GNU_const_index:
18781 10250 : ++frame_offset_;
18782 10250 : break;
18783 :
18784 7175 : case DW_OP_drop:
18785 7175 : case DW_OP_xderef:
18786 7175 : case DW_OP_and:
18787 7175 : case DW_OP_div:
18788 7175 : case DW_OP_minus:
18789 7175 : case DW_OP_mod:
18790 7175 : case DW_OP_mul:
18791 7175 : case DW_OP_or:
18792 7175 : case DW_OP_plus:
18793 7175 : case DW_OP_shl:
18794 7175 : case DW_OP_shr:
18795 7175 : case DW_OP_shra:
18796 7175 : case DW_OP_xor:
18797 7175 : case DW_OP_bra:
18798 7175 : case DW_OP_eq:
18799 7175 : case DW_OP_ge:
18800 7175 : case DW_OP_gt:
18801 7175 : case DW_OP_le:
18802 7175 : case DW_OP_lt:
18803 7175 : case DW_OP_ne:
18804 7175 : case DW_OP_regx:
18805 7175 : case DW_OP_xderef_size:
18806 7175 : --frame_offset_;
18807 7175 : 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 26749 : 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 26749 : default:
18860 26749 : l = l->dw_loc_next;
18861 26749 : 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 3075 : 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 3075 : hash_map<dw_loc_descr_ref, unsigned> frame_offsets;
18881 :
18882 3075 : return
18883 3075 : resolve_args_picking_1 (loc, initial_frame_offset, dpi, frame_offsets);
18884 3075 : }
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 16358195 : loc_list_from_tree_1 (tree loc, int want_address,
19049 : struct loc_descr_context *context)
19050 : {
19051 16545228 : dw_loc_descr_ref ret = NULL, ret1 = NULL;
19052 16545228 : dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
19053 16545228 : int have_address = 0;
19054 16545228 : 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 16545228 : if (context != NULL
19061 388526 : && context->base_decl == loc
19062 97280 : && want_address == 0)
19063 : {
19064 97280 : if (dwarf_version >= 3 || !dwarf_strict)
19065 97280 : return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
19066 97280 : NULL, 0, NULL, 0, NULL);
19067 : else
19068 : return NULL;
19069 : }
19070 :
19071 16447948 : 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 6150 : 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 6150 : if (context != NULL
19083 6150 : && (TREE_TYPE (loc) == context->context_type
19084 6150 : || TREE_TYPE (loc) == TYPE_CONTEXT (context->context_type))
19085 6150 : && 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 6150 : else if (context != NULL
19099 6150 : && context->placeholder_arg
19100 6150 : && INTEGRAL_TYPE_P (TREE_TYPE (loc))
19101 12300 : && want_address == 0)
19102 : {
19103 6150 : ret = new_loc_descr (DW_OP_pick, 0, 0);
19104 6150 : ret->dw_loc_frame_offset_rel = 1;
19105 6150 : context->placeholder_seen = true;
19106 6150 : 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 157 : case ADDR_EXPR:
19168 : /* If we already want an address, see if there is INDIRECT_REF inside
19169 : e.g. for &this->field. */
19170 157 : if (want_address)
19171 : {
19172 312 : list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
19173 156 : (loc, want_address == 2, context);
19174 156 : if (list_ret)
19175 : have_address = 1;
19176 156 : else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
19177 156 : && (ret = cst_pool_loc_descr (loc)))
19178 : have_address = 1;
19179 : }
19180 : /* Otherwise, process the argument and look for the address. */
19181 157 : if (!list_ret && !ret)
19182 157 : 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 157 : break;
19190 :
19191 14849047 : case VAR_DECL:
19192 14849047 : 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 15882056 : case PARM_DECL:
19252 268 : if (context != NULL && context->dpi != NULL
19253 15882056 : && 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 15884427 : case RESULT_DECL:
19277 15884427 : if (DECL_HAS_VALUE_EXPR_P (loc))
19278 : {
19279 134090 : 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 134090 : if (early_dwarf
19284 21 : && TREE_CODE (value_expr) == COMPONENT_REF
19285 21 : && VAR_P (TREE_OPERAND (value_expr, 0))
19286 134109 : && 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 15750512 : case FUNCTION_DECL:
19295 15750512 : {
19296 15750512 : rtx rtl;
19297 15750512 : var_loc_list *loc_list = lookup_decl_loc (loc);
19298 :
19299 15750512 : if (loc_list && loc_list->first)
19300 : {
19301 13168609 : list_ret = dw_loc_list (loc_list, loc, want_address);
19302 13168609 : have_address = want_address != 0;
19303 13168609 : break;
19304 : }
19305 2581903 : rtl = rtl_for_decl_location (loc);
19306 2581903 : if (rtl == NULL_RTX)
19307 : {
19308 1909593 : if (TREE_CODE (loc) != FUNCTION_DECL
19309 1909592 : && early_dwarf
19310 9665 : && want_address != 1
19311 9665 : && ! DECL_IGNORED_P (loc)
19312 9376 : && (INTEGRAL_TYPE_P (TREE_TYPE (loc))
19313 62 : || POINTER_TYPE_P (TREE_TYPE (loc)))
19314 9376 : && TYPE_MODE (TREE_TYPE (loc)) != BLKmode
19315 1928337 : && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc)))
19316 9372 : <= DWARF2_ADDR_SIZE))
19317 : {
19318 9372 : dw_die_ref ref = lookup_decl_die (loc);
19319 9372 : if (ref)
19320 : {
19321 5563 : ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
19322 5563 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19323 5563 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
19324 5563 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
19325 : }
19326 3809 : else if (current_function_decl
19327 3809 : && DECL_CONTEXT (loc) == current_function_decl)
19328 : {
19329 3646 : ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
19330 3646 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
19331 3646 : ret->dw_loc_oprnd1.v.val_decl_ref = loc;
19332 : }
19333 : break;
19334 : }
19335 1900221 : expansion_failed (loc, NULL_RTX, "DECL has no RTL");
19336 1900221 : return 0;
19337 : }
19338 672310 : 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 672310 : else if (GET_CODE (rtl) == CONST_STRING)
19346 : {
19347 0 : expansion_failed (loc, NULL_RTX, "CONST_STRING");
19348 0 : return 0;
19349 : }
19350 672310 : else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
19351 0 : ret = new_addr_loc_descr (rtl, dtprel_false);
19352 : else
19353 : {
19354 672310 : machine_mode mode, mem_mode;
19355 :
19356 : /* Certain constructs can only be represented at top-level. */
19357 672310 : if (want_address == 2)
19358 : {
19359 655545 : ret = loc_descriptor (rtl, VOIDmode,
19360 : VAR_INIT_STATUS_INITIALIZED);
19361 655545 : have_address = 1;
19362 : }
19363 : else
19364 : {
19365 16765 : mode = GET_MODE (rtl);
19366 16765 : mem_mode = VOIDmode;
19367 16765 : if (MEM_P (rtl))
19368 : {
19369 2254 : mem_mode = mode;
19370 2254 : mode = get_address_mode (rtl);
19371 2254 : rtl = XEXP (rtl, 0);
19372 2254 : have_address = 1;
19373 : }
19374 16765 : ret = mem_loc_descriptor (rtl, mode, mem_mode,
19375 : VAR_INIT_STATUS_INITIALIZED);
19376 : }
19377 672310 : if (!ret)
19378 44225 : expansion_failed (loc, rtl,
19379 : "failed to produce loc descriptor for rtl");
19380 : }
19381 : }
19382 : break;
19383 :
19384 5252 : case MEM_REF:
19385 5252 : if (!integer_zerop (TREE_OPERAND (loc, 1)))
19386 : {
19387 0 : have_address = 1;
19388 0 : goto do_plus;
19389 : }
19390 : /* Fallthru. */
19391 237650 : case INDIRECT_REF:
19392 237650 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19393 237650 : have_address = 1;
19394 237650 : 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 52962 : CASE_CONVERT:
19406 52962 : case VIEW_CONVERT_EXPR:
19407 52962 : case SAVE_EXPR:
19408 52962 : case MODIFY_EXPR:
19409 52962 : case NON_LVALUE_EXPR:
19410 52962 : return loc_list_from_tree_1 (TREE_OPERAND (loc, 0), want_address,
19411 52962 : context);
19412 :
19413 111382 : case COMPONENT_REF:
19414 111382 : case BIT_FIELD_REF:
19415 111382 : case ARRAY_REF:
19416 111382 : case ARRAY_RANGE_REF:
19417 111382 : case REALPART_EXPR:
19418 111382 : case IMAGPART_EXPR:
19419 111382 : {
19420 111382 : tree obj, offset;
19421 111382 : poly_int64 bitsize, bitpos, bytepos;
19422 111382 : machine_mode mode;
19423 111382 : int unsignedp, reversep, volatilep = 0;
19424 :
19425 111382 : obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
19426 : &unsignedp, &reversep, &volatilep);
19427 :
19428 111382 : gcc_assert (obj != loc);
19429 :
19430 222764 : list_ret = loc_list_from_tree_1 (obj,
19431 : want_address == 2
19432 94629 : && known_eq (bitpos, 0)
19433 41788 : && !offset ? 2 : 1,
19434 : context);
19435 : /* TODO: We can extract value of the small expression via shifting even
19436 : for nonzero bitpos. */
19437 111382 : if (list_ret == 0)
19438 74399 : return 0;
19439 37062 : 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 37062 : 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 36983 : HOST_WIDE_INT value;
19458 36983 : if (bytepos.is_constant (&value) && value > 0)
19459 27278 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst,
19460 : value, 0));
19461 9705 : else if (maybe_ne (bytepos, 0))
19462 0 : loc_list_plus_const (list_ret, bytepos);
19463 :
19464 36983 : have_address = 1;
19465 36983 : break;
19466 : }
19467 :
19468 18974 : case INTEGER_CST:
19469 18937 : if ((want_address || !tree_fits_shwi_p (loc))
19470 18978 : && (ret = cst_pool_loc_descr (loc)))
19471 : have_address = 1;
19472 18974 : else if (want_address == 2
19473 37 : && tree_fits_shwi_p (loc)
19474 19011 : && (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 18937 : else if (tree_fits_shwi_p (loc))
19479 18933 : 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 11100 : case CONSTRUCTOR:
19509 11100 : case REAL_CST:
19510 11100 : case STRING_CST:
19511 11100 : case COMPLEX_CST:
19512 11100 : if ((ret = cst_pool_loc_descr (loc)))
19513 : have_address = 1;
19514 921 : 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 880 : 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 2999986 : 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 5052 : case MINUS_EXPR:
19671 5052 : op = DW_OP_minus;
19672 5052 : 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 24675 : case MULT_EXPR:
19699 24675 : op = DW_OP_mul;
19700 24675 : 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 87106 : case POINTER_PLUS_EXPR:
19711 87106 : case PLUS_EXPR:
19712 87106 : do_plus:
19713 87106 : 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 75882 : const tree tree_addend = TREE_OPERAND (loc, 1);
19722 75882 : offset_int wi_addend;
19723 75882 : HOST_WIDE_INT shwi_addend;
19724 75882 : dw_loc_descr_ref loc_naddend;
19725 :
19726 75882 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19727 75882 : 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 75832 : wi_addend = wi::to_offset (tree_addend);
19734 76568 : wi_addend = wi::sext (wi_addend, DWARF2_ADDR_SIZE * 8);
19735 75832 : shwi_addend = wi_addend.to_shwi ();
19736 75832 : loc_naddend = (shwi_addend != INTTYPE_MINIMUM (HOST_WIDE_INT))
19737 75832 : ? int_loc_descriptor (-shwi_addend)
19738 : : NULL;
19739 :
19740 0 : if (loc_naddend != NULL
19741 151664 : && ((unsigned) size_of_uleb128 (shwi_addend)
19742 75832 : > 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 151632 : for (dw_loc_descr_ref loc_cur = loc_naddend; loc_cur != NULL; )
19751 : {
19752 75816 : loc_naddend = loc_cur;
19753 75816 : loc_cur = loc_cur->dw_loc_next;
19754 75816 : ggc_free (loc_naddend);
19755 : }
19756 151632 : loc_list_plus_const (list_ret, wi_addend.to_shwi ());
19757 : }
19758 75832 : break;
19759 : }
19760 :
19761 11224 : op = DW_OP_plus;
19762 11224 : 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 7644 : case NE_EXPR:
19806 7644 : op = DW_OP_ne;
19807 7644 : goto do_binop;
19808 :
19809 48599 : do_binop:
19810 48599 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19811 48599 : list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
19812 48599 : if (list_ret == 0 || list_ret1 == 0)
19813 : return 0;
19814 :
19815 48466 : add_loc_list (&list_ret, list_ret1);
19816 48466 : if (list_ret == 0)
19817 : return 0;
19818 :
19819 48466 : add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
19820 48466 : 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 14286112 : if (!ret && !list_ret)
19941 : return 0;
19942 :
19943 : /* Implement wrap-around arithmetics for small integer types. */
19944 13261083 : if ((TREE_CODE (loc) == PLUS_EXPR
19945 : || TREE_CODE (loc) == MINUS_EXPR
19946 13261083 : || TREE_CODE (loc) == MULT_EXPR
19947 : || TREE_CODE (loc) == NEGATE_EXPR
19948 : || TREE_CODE (loc) == LSHIFT_EXPR)
19949 40852 : && INTEGRAL_TYPE_P (TREE_TYPE (loc))
19950 40852 : && TYPE_OVERFLOW_WRAPS (TREE_TYPE (loc)))
19951 : {
19952 12332 : const enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19953 12332 : scalar_int_mode int_mode;
19954 :
19955 12332 : if (is_a <scalar_int_mode> (mode, &int_mode)
19956 13196 : && 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 13261083 : if (want_address == 2 && !have_address
19966 20848 : && (dwarf_version >= 4 || !dwarf_strict))
19967 : {
19968 21003 : 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 20848 : if (ret)
19975 10240 : add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
19976 : else
19977 15728 : 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 13261083 : 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 13261063 : gcc_assert (!ret || !list_ret);
19990 :
19991 : /* If we've got an address and don't want one, dereference. */
19992 13261063 : if (!want_address && have_address)
19993 : {
19994 114873 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
19995 114873 : enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19996 114873 : scalar_int_mode int_mode;
19997 114873 : dw_die_ref type_die;
19998 114873 : dw_loc_descr_ref deref;
19999 :
20000 : /* Bail out if the size is variable or greater than DWARF2_ADDR_SIZE. */
20001 121814 : 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 121623 : else if (size == DWARF2_ADDR_SIZE)
20009 113686 : 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 1025 : else if (!(context && context->strict_signedness)
20014 0 : || TYPE_UNSIGNED (TREE_TYPE (loc))
20015 0 : || (dwarf_strict && dwarf_version < 5)
20016 1053 : || !is_a <scalar_int_mode> (mode, &int_mode)
20017 1053 : || !(type_die = base_type_for_mode (mode, false)))
20018 1053 : 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 114739 : if (TREE_CODE (loc) == COMPONENT_REF
20034 114739 : && 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 114739 : if (ret)
20077 2548 : add_loc_descr (&ret, deref);
20078 : else
20079 113465 : add_loc_descr_to_each (list_ret, deref);
20080 : }
20081 :
20082 13260929 : if (ret)
20083 673091 : list_ret = new_loc_list (ret, NULL, 0, NULL, 0, NULL);
20084 :
20085 13260929 : 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 15835847 : loc_list_from_tree (tree loc, int want_address,
20093 : struct loc_descr_context *context)
20094 : {
20095 15835847 : dw_loc_list_ref result = loc_list_from_tree_1 (loc, want_address, context);
20096 :
20097 15835847 : for (dw_loc_list_ref loc_cur = result;
20098 42177993 : loc_cur != NULL; loc_cur = loc_cur->dw_loc_next)
20099 26342146 : loc_descr_without_nops (loc_cur->expr);
20100 15835847 : return result;
20101 : }
20102 :
20103 : /* Same as above but return only single location expression. */
20104 : static dw_loc_descr_ref
20105 234 : loc_descriptor_from_tree (tree loc, int want_address,
20106 : struct loc_descr_context *context)
20107 : {
20108 234 : dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
20109 234 : if (!ret)
20110 : return NULL;
20111 224 : 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 224 : 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 1469245 : field_type (const_tree decl)
20127 : {
20128 1469245 : tree type;
20129 :
20130 1469245 : if (TREE_CODE (decl) == ERROR_MARK)
20131 0 : return integer_type_node;
20132 :
20133 1469245 : type = DECL_BIT_FIELD_TYPE (decl);
20134 1469245 : 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 979482 : simple_type_align_in_bits (const_tree type)
20146 : {
20147 979482 : return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
20148 : }
20149 :
20150 : static inline unsigned
20151 979482 : simple_decl_align_in_bits (const_tree decl)
20152 : {
20153 979482 : 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 979550 : round_up_to_align (const offset_int &t, unsigned int align)
20160 : {
20161 979550 : 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 16180883 : field_byte_offset (const_tree decl, struct vlr_context *ctx,
20194 : HOST_WIDE_INT *cst_offset)
20195 : {
20196 16180883 : tree tree_result;
20197 16180883 : dw_loc_list_ref loc_result;
20198 :
20199 16180883 : *cst_offset = 0;
20200 :
20201 16180883 : if (TREE_CODE (decl) == ERROR_MARK)
20202 : return NULL;
20203 : else
20204 16180883 : 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 16180883 : 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 16180883 : if (PCC_BITFIELD_TYPE_MATTERS
20215 16180883 : && DECL_BIT_FIELD_TYPE (decl)
20216 16180883 : && TREE_CODE (DECL_FIELD_OFFSET (decl)) == INTEGER_CST)
20217 : {
20218 979482 : offset_int object_offset_in_bits;
20219 979482 : offset_int object_offset_in_bytes;
20220 979482 : offset_int bitpos_int;
20221 979482 : tree type;
20222 979482 : tree field_size_tree;
20223 979482 : offset_int deepest_bitpos;
20224 979482 : offset_int field_size_in_bits;
20225 979482 : unsigned int type_align_in_bits;
20226 979482 : unsigned int decl_align_in_bits;
20227 979482 : offset_int type_size_in_bits;
20228 :
20229 979482 : bitpos_int = wi::to_offset (bit_position (decl));
20230 979482 : type = field_type (decl);
20231 979482 : type_size_in_bits = offset_int_type_size_in_bits (type);
20232 979482 : type_align_in_bits = simple_type_align_in_bits (type);
20233 :
20234 979482 : 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 979482 : 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 979482 : if (TREE_CODE (field_size_tree) == INTEGER_CST)
20243 979482 : field_size_in_bits = wi::to_offset (field_size_tree);
20244 : else
20245 0 : field_size_in_bits = type_size_in_bits;
20246 :
20247 979482 : 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 979482 : 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 979482 : 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 979482 : object_offset_in_bits
20305 979482 : = round_up_to_align (object_offset_in_bits, type_align_in_bits);
20306 :
20307 979482 : 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 979482 : object_offset_in_bytes
20317 979482 : = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
20318 979482 : if (ctx->variant_part_offset == NULL_TREE)
20319 : {
20320 979482 : *cst_offset = object_offset_in_bytes.to_shwi ();
20321 979482 : return NULL;
20322 : }
20323 0 : tree_result = wide_int_to_tree (sizetype, object_offset_in_bytes);
20324 : }
20325 : else
20326 15201401 : tree_result = byte_position (decl);
20327 :
20328 15201401 : 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 15201401 : if (TREE_CODE (tree_result) == INTEGER_CST)
20335 : {
20336 15201361 : *cst_offset = wi::to_offset (tree_result).to_shwi ();
20337 15201361 : 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 12905955 : add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
20369 : dw_loc_list_ref descr)
20370 : {
20371 12905955 : bool check_no_locviews = true;
20372 12905955 : if (descr == 0)
20373 : return;
20374 12905821 : if (single_element_loc_list_p (descr))
20375 983691 : add_AT_loc (die, attr_kind, descr->expr);
20376 : else
20377 : {
20378 11922130 : add_AT_loc_list (die, attr_kind, descr);
20379 11922130 : gcc_assert (descr->ll_symbol);
20380 11921264 : if (attr_kind == DW_AT_location && descr->vl_symbol
20381 23669937 : && dwarf2out_locviews_in_attribute ())
20382 : {
20383 11747807 : add_AT_view_list (die, DW_AT_GNU_locviews);
20384 11747807 : check_no_locviews = false;
20385 : }
20386 : }
20387 :
20388 12731498 : if (check_no_locviews)
20389 1158014 : 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 251689270 : 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 251689270 : if (TREE_PROTECTED (decl))
20401 4968025 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20402 246721245 : else if (TREE_PRIVATE (decl))
20403 : {
20404 18400983 : if (dwarf_version == 2
20405 18400836 : || die->die_parent == NULL
20406 18400836 : || die->die_parent->die_tag != DW_TAG_class_type)
20407 3309494 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20408 : }
20409 228320262 : else if (dwarf_version > 2
20410 228277014 : && die->die_parent
20411 227993177 : && die->die_parent->die_tag == DW_TAG_class_type)
20412 61791260 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20413 251689270 : }
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 38971870 : add_data_member_location_attribute (dw_die_ref die,
20438 : tree decl,
20439 : struct vlr_context *ctx)
20440 : {
20441 38971870 : HOST_WIDE_INT offset;
20442 38971870 : dw_loc_descr_ref loc_descr = 0;
20443 :
20444 38971870 : if (TREE_CODE (decl) == TREE_BINFO)
20445 : {
20446 : /* We're working on the TAG_inheritance for a base class. */
20447 23280750 : 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 23280451 : offset = tree_to_shwi (BINFO_OFFSET (decl));
20487 : }
20488 : else
20489 : {
20490 15691120 : loc_descr = field_byte_offset (decl, ctx, &offset);
20491 :
20492 15691120 : 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 38971870 : 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 38971547 : if (dwarf_version >= 5
20515 38959664 : && TREE_CODE (decl) == FIELD_DECL
20516 15679665 : && DECL_BIT_FIELD_TYPE (decl)
20517 39461214 : && (ctx->variant_part_offset == NULL_TREE
20518 0 : || TREE_CODE (ctx->variant_part_offset) == INTEGER_CST))
20519 : {
20520 489667 : tree off = bit_position (decl);
20521 489667 : if (ctx->variant_part_offset)
20522 0 : off = bit_from_pos (ctx->variant_part_offset, off);
20523 489667 : if (tree_fits_uhwi_p (off) && get_AT (die, DW_AT_bit_size))
20524 : {
20525 489667 : remove_AT (die, DW_AT_byte_size);
20526 489667 : remove_AT (die, DW_AT_bit_offset);
20527 489667 : add_AT_unsigned (die, DW_AT_data_bit_offset, tree_to_uhwi (off));
20528 38959786 : return;
20529 : }
20530 : }
20531 38481880 : if (dwarf_version > 2)
20532 : {
20533 : /* Don't need to output a location expression, just the constant. */
20534 38470119 : if (offset < 0)
20535 0 : add_AT_int (die, DW_AT_data_member_location, offset);
20536 : else
20537 38470119 : add_AT_unsigned (die, DW_AT_data_member_location, offset);
20538 38470119 : 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 197388 : insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
20559 : {
20560 985086 : while (size != 0)
20561 : {
20562 787698 : *dest++ = val & 0xff;
20563 787698 : val >>= 8;
20564 787698 : --size;
20565 : }
20566 0 : }
20567 :
20568 : /* Reads integers from dw_vec_const array. Inverse of insert_int. */
20569 :
20570 : static HOST_WIDE_INT
20571 3775527 : extract_int (const unsigned char *src, unsigned int size)
20572 : {
20573 3775527 : HOST_WIDE_INT val = 0;
20574 :
20575 3775527 : src += size;
20576 8131808 : while (size != 0)
20577 : {
20578 4356281 : val <<= 8;
20579 4356281 : val |= *--src & 0xff;
20580 4356281 : --size;
20581 : }
20582 3775527 : return val;
20583 : }
20584 :
20585 : /* Writes wide_int values to dw_vec_const array. */
20586 :
20587 : static void
20588 48 : insert_wide_int (const wide_int_ref &val, unsigned char *dest, int elt_size)
20589 : {
20590 48 : int i;
20591 :
20592 48 : if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
20593 : {
20594 48 : 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 90151 : insert_float (const_rtx rtl, unsigned char *array)
20621 : {
20622 90151 : long val[4];
20623 90151 : int i;
20624 90151 : scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
20625 :
20626 90151 : 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 180302 : 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 571434 : for (i = 0; i < GET_MODE_SIZE (mode) / 4; i++)
20637 : {
20638 196453 : insert_int (val[i], 4, array);
20639 196453 : 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 52977 : add_const_value_attribute (dw_die_ref die, machine_mode mode, rtx rtl)
20652 : {
20653 52977 : scalar_mode int_mode;
20654 :
20655 52977 : switch (GET_CODE (rtl))
20656 : {
20657 35783 : case CONST_INT:
20658 35783 : {
20659 35783 : HOST_WIDE_INT val = INTVAL (rtl);
20660 :
20661 35783 : if (val < 0)
20662 1362 : add_AT_int (die, DW_AT_const_value, val);
20663 : else
20664 34421 : 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 6773 : 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 6773 : 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 6773 : scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
20690 6773 : unsigned int length = GET_MODE_SIZE (mode);
20691 6773 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
20692 6773 : unsigned int elt_size = insert_float (rtl, array);
20693 :
20694 6773 : add_AT_vec (die, DW_AT_const_value, length / elt_size, elt_size,
20695 : array);
20696 : }
20697 6773 : return true;
20698 :
20699 23 : case CONST_VECTOR:
20700 23 : {
20701 23 : unsigned int length;
20702 46 : if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
20703 1798 : return false;
20704 :
20705 23 : 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 23 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL)
20710 : return false;
20711 :
20712 23 : unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
20713 23 : unsigned char *array
20714 23 : = ggc_vec_alloc<unsigned char> (length * elt_size);
20715 23 : unsigned int i;
20716 23 : unsigned char *p;
20717 23 : machine_mode imode = GET_MODE_INNER (mode);
20718 :
20719 23 : switch (GET_MODE_CLASS (mode))
20720 : {
20721 : case MODE_VECTOR_INT:
20722 46 : for (i = 0, p = array; i < length; i++, p += elt_size)
20723 : {
20724 40 : rtx elt = CONST_VECTOR_ELT (rtl, i);
20725 40 : 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 23 : add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
20742 : }
20743 23 : return true;
20744 :
20745 258 : case CONST_STRING:
20746 258 : if (dwarf_version >= 4 || !dwarf_strict)
20747 : {
20748 258 : dw_loc_descr_ref loc_result;
20749 258 : resolve_one_addr (&rtl);
20750 8488 : rtl_addr:
20751 8488 : loc_result = new_addr_loc_descr (rtl, dtprel_false);
20752 8488 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
20753 8488 : add_AT_loc (die, DW_AT_location, loc_result);
20754 8488 : vec_safe_push (used_rtx_array, rtl);
20755 8488 : return true;
20756 : }
20757 : return false;
20758 :
20759 487 : case CONST:
20760 487 : if (CONSTANT_P (XEXP (rtl, 0)))
20761 0 : return add_const_value_attribute (die, mode, XEXP (rtl, 0));
20762 : /* FALLTHROUGH */
20763 10024 : case SYMBOL_REF:
20764 10024 : if (!const_ok_for_output (rtl))
20765 : return false;
20766 : /* FALLTHROUGH */
20767 8230 : case LABEL_REF:
20768 8230 : if (dwarf_version >= 4 || !dwarf_strict)
20769 8230 : 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 6125 : reference_to_unused (tree * tp, int * walk_subtrees,
20815 : void * data ATTRIBUTE_UNUSED)
20816 : {
20817 6125 : if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
20818 518 : *walk_subtrees = 0;
20819 :
20820 6125 : 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 6108 : else if (!symtab->global_info_ready && VAR_P (*tp))
20827 : return *tp;
20828 5786 : else if (VAR_P (*tp))
20829 : {
20830 5 : varpool_node *node = varpool_node::get (*tp);
20831 5 : if (!node || !node->definition)
20832 0 : return *tp;
20833 : }
20834 5781 : else if (TREE_CODE (*tp) == FUNCTION_DECL
20835 5781 : && (!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 5618 : 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 144435 : rtl_for_decl_init (tree init, tree type)
20855 : {
20856 144435 : rtx rtl = NULL_RTX;
20857 :
20858 144435 : STRIP_NOPS (init);
20859 :
20860 : /* If a variable is initialized with a string constant without embedded
20861 : zeros, build CONST_STRING. */
20862 144435 : 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 143974 : else if (AGGREGATE_TYPE_P (type)
20891 4471 : || (TREE_CODE (init) == VIEW_CONVERT_EXPR
20892 0 : && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
20893 148445 : || 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 4454 : else if (TREE_CODE (type) == VECTOR_TYPE
20898 4454 : && !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 4450 : else if (initializer_constant_valid_p (init, type)
20904 4450 : && ! walk_tree (&init, reference_to_unused, NULL, NULL))
20905 : {
20906 : /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
20907 : possible. */
20908 3674 : if (TREE_CODE (type) == VECTOR_TYPE)
20909 21 : 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 3674 : if (TREE_CODE (init) == INTEGER_CST
20945 298 : && TREE_CODE (TREE_TYPE (init)) == BITINT_TYPE
20946 3674 : && 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 3674 : rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
20955 :
20956 : /* If expand_expr returns a MEM, it wasn't immediate. */
20957 3674 : 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 18364694 : rtl_for_decl_location (tree decl)
20967 : {
20968 18364694 : 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 18364694 : 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 18364694 : if (! reload_completed)
21047 : {
21048 461205 : if (rtl
21049 451374 : && (CONSTANT_P (rtl)
21050 451374 : || (MEM_P (rtl)
21051 451374 : && CONSTANT_P (XEXP (rtl, 0)))
21052 0 : || (REG_P (rtl)
21053 0 : && VAR_P (decl)
21054 0 : && TREE_STATIC (decl))))
21055 : {
21056 451374 : rtl = targetm.delegitimize_address (rtl);
21057 451374 : return rtl;
21058 : }
21059 : rtl = NULL_RTX;
21060 : }
21061 17903489 : else if (TREE_CODE (decl) == PARM_DECL)
21062 : {
21063 1125902 : if (rtl == NULL_RTX
21064 1125898 : || is_pseudo_reg (rtl)
21065 1478188 : || (MEM_P (rtl)
21066 210131 : && 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 773638 : tree declared_type = TREE_TYPE (decl);
21072 773638 : tree passed_type = DECL_ARG_TYPE (decl);
21073 773638 : machine_mode dmode = TYPE_MODE (declared_type);
21074 773638 : 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 773638 : if (dmode == pmode)
21080 772851 : 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 16777587 : else if (VAR_P (decl)
21136 16777587 : && rtl
21137 1246022 : && MEM_P (rtl)
21138 17295506 : && 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 17912619 : if (!rtl && VAR_P (decl) && DECL_INITIAL (decl))
21159 1446 : rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
21160 :
21161 17913320 : if (rtl)
21162 2372461 : 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 2372461 : if (rtl)
21168 2372461 : 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 2372461 : if (rtl == NULL_RTX
21174 15540859 : && !(early_dwarf && (flag_generate_lto || flag_generate_offload))
21175 15540705 : && VAR_P (decl)
21176 15539704 : && !DECL_EXTERNAL (decl)
21177 15539704 : && TREE_STATIC (decl)
21178 12625 : && DECL_NAME (decl)
21179 12625 : && !DECL_HARD_REGISTER (decl)
21180 2385086 : && DECL_MODE (decl) != VOIDmode)
21181 : {
21182 12625 : rtl = make_decl_rtl_for_debug (decl);
21183 12625 : if (!MEM_P (rtl)
21184 12625 : || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
21185 25250 : || 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 67067865 : fortran_common (tree decl, HOST_WIDE_INT *value)
21198 : {
21199 67067865 : tree val_expr, cvar;
21200 67067865 : machine_mode mode;
21201 67067865 : poly_int64 bitsize, bitpos;
21202 67067865 : tree offset;
21203 67067865 : HOST_WIDE_INT cbitpos;
21204 67067865 : 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 67067865 : if (!VAR_P (decl)
21211 67067865 : || !TREE_STATIC (decl)
21212 61805397 : || !DECL_HAS_VALUE_EXPR_P (decl)
21213 67099570 : || !is_fortran ())
21214 67066743 : 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 19784153 : add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p)
21263 : {
21264 19784153 : rtx rtl;
21265 19784153 : dw_loc_list_ref list;
21266 19784153 : var_loc_list *loc_list;
21267 19784153 : cached_dw_loc_list *cache;
21268 :
21269 19784153 : if (early_dwarf)
21270 : return false;
21271 :
21272 15798879 : if (TREE_CODE (decl) == ERROR_MARK)
21273 : return false;
21274 :
21275 15798879 : if (get_AT (die, DW_AT_location)
21276 15798879 : || get_AT (die, DW_AT_const_value))
21277 16561 : return true;
21278 :
21279 15782318 : 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 15782318 : rtl = rtl_for_decl_location (decl);
21286 2163677 : if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
21287 15782717 : && 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 15781919 : loc_list = lookup_decl_loc (decl);
21294 15781919 : if (loc_list
21295 13136297 : && loc_list->first
21296 13136297 : && loc_list->first->next == NULL
21297 486618 : && NOTE_P (loc_list->first->loc)
21298 482702 : && NOTE_VAR_LOCATION (loc_list->first->loc)
21299 482702 : && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
21300 : {
21301 436664 : struct var_loc_node *node;
21302 :
21303 436664 : node = loc_list->first;
21304 436664 : rtl = NOTE_VAR_LOCATION_LOC (node->loc);
21305 436664 : if (GET_CODE (rtl) == EXPR_LIST)
21306 0 : rtl = XEXP (rtl, 0);
21307 387690 : if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
21308 436922 : && 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 13088856 : list = NULL;
21314 13088856 : if (loc_list == NULL || cached_dw_loc_list_table == NULL)
21315 : cache_p = false;
21316 13088856 : 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 31398079 : 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 15734478 : 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 15734478 : if (list)
21341 : {
21342 12888232 : add_AT_location_description (die, DW_AT_location, list);
21343 12888232 : 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 2846246 : return tree_add_const_value_attribute_for_decl (die, decl);
21348 : }
21349 :
21350 : /* Mangle referenced decls. */
21351 : static tree
21352 46469438 : mangle_referenced_decls (tree *tp, int *walk_subtrees, void *)
21353 : {
21354 46469438 : if (! EXPR_P (*tp)
21355 45638300 : && ! CONSTANT_CLASS_P (*tp)
21356 2156406 : && TREE_CODE (*tp) != CONSTRUCTOR)
21357 908 : *walk_subtrees = 0;
21358 :
21359 46469438 : if (VAR_OR_FUNCTION_DECL_P (*tp))
21360 626 : assign_assembler_name_if_needed (*tp);
21361 :
21362 46469438 : 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 40054622 : tree_add_const_value_attribute (dw_die_ref die, tree t)
21370 : {
21371 40054622 : tree init;
21372 40054622 : tree type = TREE_TYPE (t);
21373 :
21374 40054622 : if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
21375 : return false;
21376 :
21377 40054621 : init = t;
21378 40054621 : gcc_assert (!DECL_P (init));
21379 :
21380 40054621 : if (TREE_CODE (init) == INTEGER_CST)
21381 : {
21382 37730530 : if (tree_fits_uhwi_p (init))
21383 : {
21384 37518667 : add_AT_unsigned (die, DW_AT_const_value, tree_to_uhwi (init));
21385 37518667 : return true;
21386 : }
21387 211863 : if (tree_fits_shwi_p (init))
21388 : {
21389 211844 : add_AT_int (die, DW_AT_const_value, tree_to_shwi (init));
21390 211844 : return true;
21391 : }
21392 : }
21393 2324110 : if (!early_dwarf)
21394 : {
21395 142989 : rtx rtl = rtl_for_decl_init (init, type);
21396 142989 : if (rtl)
21397 3346 : 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 2181121 : tree initializer = init;
21403 2181121 : STRIP_NOPS (initializer);
21404 2181121 : if (initializer_constant_valid_p (initializer, type))
21405 2181120 : walk_tree (&initializer, mangle_referenced_decls, NULL, NULL);
21406 : }
21407 : /* If the host and target are sane, try harder. */
21408 2320764 : if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
21409 2320764 : && initializer_constant_valid_p (init, type))
21410 : {
21411 2320762 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
21412 2320762 : if (size > 0 && (int) size == size)
21413 : {
21414 2320711 : unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
21415 :
21416 2320711 : if (native_encode_initializer (init, array, size) == size)
21417 : {
21418 2308260 : add_AT_vec (die, DW_AT_const_value, size, 1, array);
21419 2308260 : return true;
21420 : }
21421 12451 : 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 64614748 : tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
21434 : {
21435 :
21436 64614748 : if (!decl
21437 64614748 : || (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
21438 64614113 : || (VAR_P (decl) && !TREE_STATIC (decl)))
21439 : return false;
21440 :
21441 61161607 : if (TREE_READONLY (decl)
21442 60902881 : && ! TREE_THIS_VOLATILE (decl)
21443 122064322 : && 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 56766045 : if (get_AT (var_die, DW_AT_const_value))
21450 : return false;
21451 :
21452 29071678 : 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 3391 : convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
21463 : {
21464 3391 : int ix;
21465 3391 : dw_fde_ref fde;
21466 3391 : dw_loc_list_ref list, *list_tail;
21467 3391 : dw_cfi_ref cfi;
21468 3391 : dw_cfa_location last_cfa, next_cfa;
21469 3391 : const char *start_label, *last_label, *section;
21470 3391 : dw_cfa_location remember;
21471 :
21472 3391 : fde = cfun->fde;
21473 3391 : gcc_assert (fde != NULL);
21474 :
21475 3391 : section = secname_for_decl (current_function_decl);
21476 3391 : list_tail = &list;
21477 3391 : list = NULL;
21478 :
21479 3391 : 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 3391 : next_cfa.reg.set_by_dwreg (INVALID_REGNUM);
21504 3391 : remember = next_cfa;
21505 :
21506 3391 : start_label = fde->dw_fde_begin;
21507 :
21508 : /* ??? Bald assumption that the CIE opcode list does not contain
21509 : advance opcodes. */
21510 10173 : FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
21511 6782 : lookup_cfa_1 (cfi, &next_cfa, &remember);
21512 :
21513 3391 : last_cfa = next_cfa;
21514 3391 : last_label = start_label;
21515 :
21516 3391 : 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 19352 : FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
21527 : {
21528 15961 : switch (cfi->dw_cfi_opc)
21529 : {
21530 5689 : case DW_CFA_set_loc:
21531 5689 : case DW_CFA_advance_loc1:
21532 5689 : case DW_CFA_advance_loc2:
21533 5689 : case DW_CFA_advance_loc4:
21534 5689 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21535 : {
21536 3816 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21537 : start_label, 0, last_label, 0, section);
21538 :
21539 3816 : list_tail = &(*list_tail)->dw_loc_next;
21540 3816 : last_cfa = next_cfa;
21541 3816 : start_label = last_label;
21542 : }
21543 5689 : last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
21544 5689 : 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 10272 : default:
21551 10272 : lookup_cfa_1 (cfi, &next_cfa, &remember);
21552 10272 : break;
21553 : }
21554 15961 : 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 3391 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21573 : {
21574 1789 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21575 : start_label, 0, last_label, 0, section);
21576 1789 : list_tail = &(*list_tail)->dw_loc_next;
21577 1789 : start_label = last_label;
21578 : }
21579 :
21580 3391 : *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
21581 : start_label, 0,
21582 3391 : fde->dw_fde_second_begin
21583 : ? fde->dw_fde_second_end : fde->dw_fde_end, 0,
21584 : section);
21585 :
21586 3391 : maybe_gen_llsym (list);
21587 :
21588 3391 : 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 560785 : compute_frame_pointer_to_fb_displacement (poly_int64 offset)
21598 : {
21599 560785 : 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 560785 : reg = arg_pointer_rtx;
21606 560785 : offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
21607 : #endif
21608 :
21609 560785 : elim = (ira_use_lra_p
21610 560785 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
21611 0 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
21612 560785 : elim = strip_offset_and_add (elim, &offset);
21613 :
21614 560785 : 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 560785 : frame_pointer_fb_offset_valid
21626 560785 : = (elim == hard_frame_pointer_rtx || elim == stack_pointer_rtx);
21627 560785 : }
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 279806225 : add_name_attribute (dw_die_ref die, const char *name_string)
21634 : {
21635 279806225 : if (name_string != NULL && *name_string != 0)
21636 : {
21637 276153273 : if (demangle_name_func)
21638 0 : name_string = (*demangle_name_func) (name_string);
21639 :
21640 276153273 : add_AT_string (die, DW_AT_name, name_string);
21641 : }
21642 279806225 : }
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 53131 : add_filename_attribute (dw_die_ref die, const char *name_string)
21648 : {
21649 53131 : if (name_string != NULL && *name_string != 0)
21650 53131 : add_filepath_AT_string (die, DW_AT_name, name_string);
21651 53131 : }
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 3460064 : add_desc_attribute (dw_die_ref die, tree decl)
21676 : {
21677 3460064 : tree decl_name;
21678 :
21679 3460064 : 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 98896790 : add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
21708 : dw_die_ref context_die)
21709 : {
21710 98896790 : tree dtype;
21711 98896790 : dw_die_ref dtype_die;
21712 :
21713 98896790 : 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 105285 : comp_dir_string (void)
21735 : {
21736 105285 : const char *wd;
21737 105285 : char *wd_plus_sep = NULL;
21738 105285 : static const char *cached_wd = NULL;
21739 :
21740 105285 : if (cached_wd != NULL)
21741 : return cached_wd;
21742 :
21743 52427 : wd = get_src_pwd ();
21744 52427 : if (wd == NULL)
21745 : return NULL;
21746 :
21747 52427 : 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 52427 : 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 52427 : 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 52427 : return cached_wd;
21770 : }
21771 :
21772 : /* Generate a DW_AT_comp_dir attribute for DIE. */
21773 :
21774 : static void
21775 53131 : add_comp_dir_attribute (dw_die_ref die)
21776 : {
21777 53131 : const char * wd = comp_dir_string ();
21778 53131 : if (wd != NULL)
21779 53131 : add_filepath_AT_string (die, DW_AT_comp_dir, wd);
21780 53131 : }
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 1012455 : add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
21789 : int forms, struct loc_descr_context *context)
21790 : {
21791 1012455 : dw_die_ref context_die, decl_die = NULL;
21792 1012455 : dw_loc_list_ref list;
21793 1012455 : bool strip_conversions = true;
21794 1012455 : bool placeholder_seen = false;
21795 :
21796 1012455 : while (strip_conversions)
21797 1012455 : 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 1012455 : if ((forms & dw_scalar_form_constant) != 0
21815 1005538 : && TREE_CODE (value) == INTEGER_CST)
21816 : {
21817 970344 : 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 970344 : if (prec <= HOST_BITS_PER_WIDE_INT
21831 0 : || tree_fits_uhwi_p (value))
21832 : {
21833 970344 : if (TYPE_UNSIGNED (TREE_TYPE (value)))
21834 953943 : add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
21835 : else
21836 16401 : 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 970344 : return;
21856 : }
21857 :
21858 : /* Otherwise, if it's possible and permitted too, output a reference to
21859 : another DIE. */
21860 42111 : if ((forms & dw_scalar_form_reference) != 0)
21861 : {
21862 34169 : 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 34169 : if (TREE_CODE (value) == COMPONENT_REF
21868 0 : && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
21869 34169 : && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
21870 0 : decl = TREE_OPERAND (value, 1);
21871 :
21872 34169 : 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 5143 : 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 5143 : if (decl_die != NULL)
21887 : {
21888 3147 : if (get_AT (decl_die, DW_AT_location)
21889 3120 : || get_AT (decl_die, DW_AT_data_member_location)
21890 3120 : || get_AT (decl_die, DW_AT_data_bit_offset)
21891 6267 : || 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 42069 : if ((forms & dw_scalar_form_exprloc) == 0)
21903 : return;
21904 :
21905 42069 : list = loc_list_from_tree (value, 2, context);
21906 42069 : if (context && context->placeholder_arg)
21907 : {
21908 3075 : placeholder_seen = context->placeholder_seen;
21909 3075 : context->placeholder_seen = false;
21910 : }
21911 42069 : 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 41296 : dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
21917 41296 : if (list2 && single_element_loc_list_p (list2))
21918 : {
21919 41024 : if (placeholder_seen)
21920 : {
21921 3075 : struct dwarf_procedure_info dpi;
21922 3075 : dpi.fndecl = NULL_TREE;
21923 3075 : dpi.args_count = 1;
21924 3075 : if (!resolve_args_picking (list2->expr, 1, &dpi))
21925 0 : return;
21926 : }
21927 41024 : add_AT_loc (die, attr, list2->expr);
21928 41024 : 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 991735 : lower_bound_default (void)
21961 : {
21962 991735 : 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 2112 : case DW_LANG_Ada95:
21985 2112 : case DW_LANG_Ada83:
21986 2112 : case DW_LANG_Cobol74:
21987 2112 : case DW_LANG_Cobol85:
21988 2112 : case DW_LANG_Modula2:
21989 2112 : case DW_LANG_PLI:
21990 2112 : 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 1947602 : add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
22001 : tree bound, struct loc_descr_context *context)
22002 : {
22003 1947642 : int dflt;
22004 :
22005 1947682 : while (1)
22006 1947642 : 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 1926565 : case INTEGER_CST:
22017 : /* If the value for this bound is the default one, we can even omit the
22018 : attribute. */
22019 1926565 : if (bound_attr == DW_AT_lower_bound
22020 971915 : && tree_fits_shwi_p (bound)
22021 971915 : && (dflt = lower_bound_default ()) != -1
22022 2888723 : && tree_to_shwi (bound) == dflt)
22023 : return;
22024 :
22025 : /* FALLTHRU */
22026 :
22027 991381 : default:
22028 : /* Let GNAT encodings do the magic for self-referential bounds. */
22029 991381 : if (is_ada ()
22030 0 : && gnat_encodings == DWARF_GNAT_ENCODINGS_ALL
22031 991381 : && contains_placeholder_p (bound))
22032 : return;
22033 :
22034 991381 : 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 991381 : 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 1021434 : add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
22051 : {
22052 1021434 : dw_die_ref child = type_die->die_child;
22053 1021434 : struct array_descr_info info;
22054 1021434 : int dimension_number;
22055 :
22056 1021434 : if (lang_hooks.types.get_array_descr_info)
22057 : {
22058 13928 : memset (&info, 0, sizeof (info));
22059 13928 : 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 1007506 : info.ndimensions = 0;
22067 :
22068 : for (dimension_number = 0;
22069 2047842 : TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
22070 1026408 : type = TREE_TYPE (type), dimension_number++)
22071 : {
22072 1027544 : tree domain = TYPE_DOMAIN (type);
22073 :
22074 1027544 : 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 1026408 : dw_die_ref subrange_die = NULL;
22093 1026408 : if (child)
22094 5072 : while (1)
22095 : {
22096 5072 : child = child->die_sib;
22097 5072 : if (child->die_tag == DW_TAG_subrange_type)
22098 5072 : subrange_die = child;
22099 5072 : 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 5072 : if (!subrange_die)
22109 1021336 : subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
22110 :
22111 1026408 : if (domain)
22112 : {
22113 : /* We have an array type with specified bounds. */
22114 950310 : tree lower = TYPE_MIN_VALUE (domain);
22115 950310 : tree upper = TYPE_MAX_VALUE (domain);
22116 950310 : tree index_type = TREE_TYPE (domain);
22117 :
22118 950310 : 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 950310 : if (index_type && !get_AT (subrange_die, DW_AT_type))
22127 945239 : 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 950310 : if (lower && !get_AT (subrange_die, DW_AT_lower_bound))
22138 949636 : add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
22139 :
22140 950310 : if (!get_AT (subrange_die, DW_AT_upper_bound)
22141 950310 : && !get_AT (subrange_die, DW_AT_count))
22142 : {
22143 945309 : if (upper)
22144 938790 : 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 1021434 : }
22157 :
22158 : /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
22159 :
22160 : static void
22161 53084468 : add_byte_size_attribute (dw_die_ref die, tree tree_node)
22162 : {
22163 53084468 : dw_die_ref decl_die;
22164 53084468 : HOST_WIDE_INT size;
22165 :
22166 53084468 : switch (TREE_CODE (tree_node))
22167 : {
22168 : case ERROR_MARK:
22169 : size = 0;
22170 : break;
22171 52594705 : case ENUMERAL_TYPE:
22172 52594705 : case RECORD_TYPE:
22173 52594705 : case UNION_TYPE:
22174 52594705 : case QUAL_UNION_TYPE:
22175 52594705 : if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
22176 52594705 : && (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 52594705 : size = int_size_in_bytes (tree_node);
22182 52594705 : break;
22183 489763 : 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 489763 : size = int_size_in_bytes (field_type (tree_node));
22189 489763 : 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 53084468 : if (size >= 0)
22197 53084377 : 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 285367955 : add_alignment_attribute (dw_die_ref die, tree tree_node)
22227 : {
22228 285367955 : if (dwarf_version < 5 && dwarf_strict)
22229 : return;
22230 :
22231 285367896 : unsigned align;
22232 :
22233 285367896 : if (DECL_P (tree_node))
22234 : {
22235 147060539 : if (!DECL_USER_ALIGN (tree_node))
22236 : return;
22237 :
22238 430424 : align = DECL_ALIGN_UNIT (tree_node);
22239 : }
22240 138307357 : else if (TYPE_P (tree_node))
22241 : {
22242 138307357 : if (!TYPE_USER_ALIGN (tree_node))
22243 : return;
22244 :
22245 1036085 : align = TYPE_ALIGN_UNIT (tree_node);
22246 : }
22247 : else
22248 0 : gcc_unreachable ();
22249 :
22250 1466509 : 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 489763 : add_bit_offset_attribute (dw_die_ref die, tree decl)
22271 : {
22272 489763 : HOST_WIDE_INT object_offset_in_bytes;
22273 489763 : tree original_type = DECL_BIT_FIELD_TYPE (decl);
22274 489763 : HOST_WIDE_INT bitpos_int;
22275 489763 : HOST_WIDE_INT highest_order_object_bit_offset;
22276 489763 : HOST_WIDE_INT highest_order_field_bit_offset;
22277 489763 : HOST_WIDE_INT bit_offset;
22278 :
22279 : /* The containing object is within the DECL_CONTEXT. */
22280 489763 : struct vlr_context ctx = { DECL_CONTEXT (decl), NULL_TREE };
22281 :
22282 489763 : field_byte_offset (decl, &ctx, &object_offset_in_bytes);
22283 :
22284 : /* Must be a field and a bit field. */
22285 489763 : 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 489763 : if (! tree_fits_shwi_p (bit_position (decl))
22291 489763 : || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
22292 16 : return;
22293 :
22294 489747 : 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 489747 : highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
22302 489747 : highest_order_field_bit_offset = bitpos_int;
22303 :
22304 489747 : if (! BYTES_BIG_ENDIAN)
22305 : {
22306 489747 : highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
22307 979494 : highest_order_object_bit_offset +=
22308 489747 : simple_type_size_in_bits (original_type);
22309 : }
22310 :
22311 489747 : bit_offset
22312 489747 : = (! 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 489747 : if (bit_offset < 0)
22317 32 : add_AT_int (die, DW_AT_bit_offset, bit_offset);
22318 : else
22319 489715 : 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 489763 : add_bit_size_attribute (dw_die_ref die, tree decl)
22327 : {
22328 : /* Must be a field and a bit field. */
22329 489763 : gcc_assert (TREE_CODE (decl) == FIELD_DECL
22330 : && DECL_BIT_FIELD_TYPE (decl));
22331 :
22332 489763 : if (tree_fits_uhwi_p (DECL_SIZE (decl)))
22333 489763 : add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
22334 489763 : }
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 97138501 : add_prototyped_attribute (dw_die_ref die, tree func_type)
22341 : {
22342 97138501 : switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
22343 : {
22344 272478 : case DW_LANG_C:
22345 272478 : case DW_LANG_C89:
22346 272478 : case DW_LANG_C99:
22347 272478 : case DW_LANG_C11:
22348 272478 : case DW_LANG_ObjC:
22349 272478 : if (prototype_p (func_type))
22350 269089 : add_AT_flag (die, DW_AT_prototyped, 1);
22351 : break;
22352 : default:
22353 : break;
22354 : }
22355 97138501 : }
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 21319914 : add_abstract_origin_attribute (dw_die_ref die, tree origin)
22363 : {
22364 21319914 : 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 21319914 : sym_off_pair *desc;
22370 21319914 : if (in_lto_p
22371 9271 : && external_die_map
22372 21329184 : && (desc = external_die_map->get (origin)))
22373 : {
22374 9000 : add_AT_external_die_ref (die, DW_AT_abstract_origin,
22375 9000 : desc->sym, desc->off);
22376 9000 : return;
22377 : }
22378 :
22379 21310914 : if (DECL_P (origin))
22380 20973480 : origin_die = lookup_decl_die (origin);
22381 337434 : else if (TYPE_P (origin))
22382 0 : origin_die = lookup_type_die (origin);
22383 337434 : else if (TREE_CODE (origin) == BLOCK)
22384 337434 : 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 21310914 : if (origin_die)
22396 : {
22397 21303970 : 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 21303970 : if (in_lto_p
22402 21303970 : && (a = get_AT (origin_die, DW_AT_abstract_origin)))
22403 260 : origin_die = AT_ref (a);
22404 21303970 : 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 96746177 : add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
22412 : {
22413 96746177 : if (DECL_VINDEX (func_decl))
22414 : {
22415 1198916 : add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
22416 :
22417 1198916 : if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
22418 928749 : add_AT_loc (die, DW_AT_vtable_elem_location,
22419 : new_loc_descr (DW_OP_constu,
22420 928749 : tree_to_shwi (DECL_VINDEX (func_decl)),
22421 : 0));
22422 :
22423 : /* GNU extension: Record what type this method came from originally. */
22424 1198916 : if (debug_info_level > DINFO_LEVEL_TERSE
22425 1198916 : && DECL_CONTEXT (func_decl))
22426 1198878 : add_AT_die_ref (die, DW_AT_containing_type,
22427 1198878 : lookup_type_die (DECL_CONTEXT (func_decl)));
22428 : }
22429 96746177 : }
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 122393877 : add_linkage_attr (dw_die_ref die, tree decl)
22437 : {
22438 122393877 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
22439 :
22440 : /* Mimic what assemble_name_raw does with a leading '*'. */
22441 122393877 : if (name[0] == '*')
22442 427563 : name = &name[1];
22443 :
22444 122393877 : if (dwarf_version >= 4)
22445 122389139 : add_AT_string (die, DW_AT_linkage_name, name);
22446 : else
22447 4738 : add_AT_string (die, DW_AT_MIPS_linkage_name, name);
22448 122393877 : }
22449 :
22450 : /* Add source coordinate attributes for the given decl. */
22451 :
22452 : static void
22453 252732317 : add_src_coords_attributes (dw_die_ref die, tree decl)
22454 : {
22455 252732317 : expanded_location s;
22456 :
22457 252732317 : if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
22458 111375 : return;
22459 252620942 : s = expand_location (DECL_SOURCE_LOCATION (decl));
22460 252620942 : add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
22461 252620942 : add_AT_unsigned (die, DW_AT_decl_line, s.line);
22462 252620942 : if (debug_column_info && s.column)
22463 251819542 : 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 128534750 : add_linkage_name_raw (dw_die_ref die, tree decl)
22470 : {
22471 : /* Defer until we have an assembler name set. */
22472 128534750 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
22473 : {
22474 126570038 : limbo_die_node *asm_name;
22475 :
22476 126570038 : asm_name = ggc_cleared_alloc<limbo_die_node> ();
22477 126570038 : asm_name->die = die;
22478 126570038 : asm_name->created_for = decl;
22479 126570038 : asm_name->next = deferred_asm_name;
22480 126570038 : deferred_asm_name = asm_name;
22481 : }
22482 1964712 : else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22483 1544945 : add_linkage_attr (die, decl);
22484 128534750 : }
22485 :
22486 : /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
22487 :
22488 : static void
22489 208534507 : add_linkage_name (dw_die_ref die, tree decl)
22490 : {
22491 208534507 : if (debug_info_level > DINFO_LEVEL_NONE
22492 208534498 : && VAR_OR_FUNCTION_DECL_P (decl)
22493 130337454 : && TREE_PUBLIC (decl)
22494 128223776 : && !(VAR_P (decl) && DECL_REGISTER (decl))
22495 336758277 : && die->die_tag != DW_TAG_member)
22496 128223662 : add_linkage_name_raw (die, decl);
22497 208534507 : }
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 208881043 : add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
22504 : bool no_linkage_name)
22505 : {
22506 208881043 : tree decl_name;
22507 :
22508 208881043 : decl_name = DECL_NAME (decl);
22509 417272340 : if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
22510 : {
22511 208391297 : const char *name = dwarf2_name (decl, 0);
22512 208391297 : if (name)
22513 208384833 : add_name_attribute (die, name);
22514 : else
22515 6464 : add_desc_attribute (die, decl);
22516 :
22517 208391297 : if (! DECL_ARTIFICIAL (decl))
22518 200342362 : add_src_coords_attributes (die, decl);
22519 :
22520 208391297 : if (!no_linkage_name)
22521 208129307 : add_linkage_name (die, decl);
22522 : }
22523 : else
22524 489746 : 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 208881043 : }
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 2195672 : uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
22611 : {
22612 2195672 : if (!TYPE_P (*tp))
22613 0 : *walk_subtrees = 0;
22614 : else
22615 : {
22616 2195672 : tree name = TYPE_NAME (*tp);
22617 2195672 : if (name && DECL_P (name) && decl_function_context (name))
22618 82077 : 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 1121408 : uses_local_type (tree type)
22628 : {
22629 1121408 : tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
22630 1121408 : 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 172515174 : scope_die_for (tree t, dw_die_ref context_die)
22641 : {
22642 172515174 : dw_die_ref scope_die = NULL;
22643 172515174 : tree containing_scope;
22644 :
22645 : /* Non-types always go in the current scope. */
22646 172515174 : 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 172515174 : if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
22651 137346510 : containing_scope = DECL_CONTEXT (TYPE_NAME (t));
22652 : else
22653 35168664 : containing_scope = TYPE_CONTEXT (t);
22654 :
22655 : /* Use the containing namespace if there is one. */
22656 172515174 : if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
22657 : {
22658 115618745 : if (context_die == lookup_decl_die (containing_scope))
22659 : /* OK */;
22660 60082133 : else if (debug_info_level > DINFO_LEVEL_TERSE)
22661 60082133 : 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 136225393 : if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
22670 : containing_scope = NULL_TREE;
22671 :
22672 136225362 : 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 39097378 : if (current_function_decl && uses_local_type (t))
22677 : scope_die = context_die;
22678 : else
22679 37893893 : scope_die = comp_unit_die ();
22680 : }
22681 134539204 : else if (TYPE_P (containing_scope))
22682 : {
22683 : /* For types, we can just look up the appropriate DIE. */
22684 17861667 : if (debug_info_level > DINFO_LEVEL_TERSE)
22685 17861667 : 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 172515174 : 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 420488572 : for (; context_die; context_die = context_die->die_parent)
22705 322543047 : if (context_die->die_tag == DW_TAG_inlined_subroutine
22706 322543046 : || 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 238153612 : class_scope_p (dw_die_ref context_die)
22716 : {
22717 238153612 : return (context_die
22718 238153612 : && (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 238153612 : || 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 140274083 : class_or_namespace_scope_p (dw_die_ref context_die)
22729 : {
22730 140274083 : return (class_scope_p (context_die)
22731 140274083 : || (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 471980650 : add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
22741 : bool reverse, dw_die_ref context_die)
22742 : {
22743 471980650 : enum tree_code code = TREE_CODE (type);
22744 471980650 : dw_die_ref type_die = NULL;
22745 :
22746 471980650 : 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 471979550 : if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
22754 104382819 : && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
22755 655 : type = TREE_TYPE (type), code = TREE_CODE (type);
22756 :
22757 471979550 : 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 471979550 : || code == VOID_TYPE)
22762 : return;
22763 :
22764 1757048108 : type_die = modified_type_die (type,
22765 439262027 : cv_quals | TYPE_QUALS (type),
22766 439262027 : TYPE_ATTRIBUTES (type),
22767 : reverse,
22768 : context_die);
22769 :
22770 439262027 : if (type_die != NULL)
22771 439261915 : 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 98454626 : add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
22778 : {
22779 98454626 : enum dwarf_calling_convention value = DW_CC_normal;
22780 :
22781 196909252 : value = ((enum dwarf_calling_convention)
22782 98454626 : targetm.dwarf_calling_convention (TREE_TYPE (decl)));
22783 :
22784 98454626 : if (is_fortran ()
22785 98454626 : && 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 4279 : value = DW_CC_program;
22795 :
22796 4279 : if (dwarf_version >= 4 || !dwarf_strict)
22797 4279 : 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 98454626 : if (value && (value != DW_CC_normal))
22803 4279 : add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
22804 98454626 : }
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 56977946 : type_tag (const_tree type)
22812 : {
22813 56977946 : const char *name = 0;
22814 :
22815 56977946 : if (TYPE_NAME (type) != 0)
22816 : {
22817 55403574 : tree t = 0;
22818 :
22819 : /* Find the IDENTIFIER_NODE for the type name. */
22820 55403574 : if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
22821 55403574 : && !TYPE_NAMELESS (type))
22822 273374 : 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 55130200 : else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
22828 55130200 : && ! 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 55116349 : if (DECL_NAME (TYPE_NAME (type))
22835 55116349 : && !DECL_NAMELESS (TYPE_NAME (type)))
22836 55114485 : name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
22837 : }
22838 :
22839 : /* Now get the name as a string, or invent one. */
22840 55403574 : if (!name && t != 0)
22841 273374 : name = IDENTIFIER_POINTER (t);
22842 : }
22843 :
22844 55403574 : 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 34441235 : member_declared_type (const_tree member)
22852 : {
22853 34441235 : return (DECL_BIT_FIELD_TYPE (member)
22854 34441235 : ? 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 10955892 : fill_variable_array_bounds (tree type)
22884 : {
22885 10955892 : if (TREE_ASM_WRITTEN (type)
22886 3964481 : && TREE_CODE (type) == ARRAY_TYPE
22887 10960628 : && variably_modified_type_p (type, NULL))
22888 : {
22889 4704 : dw_die_ref array_die = lookup_type_die (type);
22890 4704 : if (!array_die)
22891 : return false;
22892 4704 : add_subscript_info (array_die, type, !is_ada ());
22893 4704 : 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 1045258 : gen_array_type_die (tree type, dw_die_ref context_die)
22904 : {
22905 1045258 : 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 1045258 : bool collapse_nested_arrays = !is_ada ();
22918 :
22919 1045258 : if (fill_variable_array_bounds (type))
22920 : return;
22921 :
22922 1040636 : dw_die_ref scope_die = scope_die_for (type, context_die);
22923 1040636 : 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 1040636 : if (TREE_CODE (type) == ARRAY_TYPE
22928 1020816 : && TYPE_STRING_FLAG (type)
22929 4471 : && is_fortran ()
22930 1045107 : && 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 1036550 : array_die = new_die (DW_TAG_array_type, scope_die, type);
22983 1036550 : add_name_attribute (array_die, type_tag (type));
22984 1036550 : equate_type_number_to_die (type, array_die);
22985 :
22986 1036550 : if (VECTOR_TYPE_P (type))
22987 19820 : add_AT_flag (array_die, DW_AT_GNU_vector, 1);
22988 :
22989 : /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
22990 1036550 : if (is_fortran ()
22991 9829 : && TREE_CODE (type) == ARRAY_TYPE
22992 9829 : && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
22993 1038829 : && !TYPE_STRING_FLAG (TREE_TYPE (type)))
22994 1666 : 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 1036550 : if (VECTOR_TYPE_P (type))
23008 : {
23009 : /* For VECTOR_TYPEs we use an array DIE with appropriate bounds. */
23010 19820 : dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
23011 19820 : int lb = lower_bound_default ();
23012 19820 : if (lb == -1)
23013 : lb = 0;
23014 19820 : add_bound_info (subrange_die, DW_AT_lower_bound, size_int (lb), NULL);
23015 19820 : add_bound_info (subrange_die, DW_AT_upper_bound,
23016 39640 : size_int (lb + TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
23017 : }
23018 : else
23019 1016730 : 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 1036550 : element_type = TREE_TYPE (type);
23024 1036550 : if (collapse_nested_arrays)
23025 1040681 : while (TREE_CODE (element_type) == ARRAY_TYPE)
23026 : {
23027 4904 : if (TYPE_STRING_FLAG (element_type) && is_fortran ())
23028 : break;
23029 4131 : element_type = TREE_TYPE (element_type);
23030 : }
23031 :
23032 1036550 : add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED,
23033 1036550 : TREE_CODE (type) == ARRAY_TYPE
23034 1036550 : && 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 1036550 : 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 1036550 : add_gnat_descriptive_type_attribute (array_die, type, context_die);
23060 1036550 : if (TYPE_ARTIFICIAL (type))
23061 0 : add_AT_flag (array_die, DW_AT_artificial, 1);
23062 :
23063 1036550 : if (get_AT (array_die, DW_AT_name))
23064 60 : add_pubtype (type, array_die);
23065 :
23066 1036550 : add_alignment_attribute (array_die, type);
23067 1036550 : 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 6917 : gen_descr_array_type_die (tree type, struct array_descr_info *info,
23075 : dw_die_ref context_die)
23076 : {
23077 6917 : const dw_die_ref scope_die = scope_die_for (type, context_die);
23078 6917 : const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
23079 6917 : struct loc_descr_context context = {
23080 : type, /* context_type */
23081 6917 : info->base_decl, /* base_decl */
23082 : NULL, /* dpi */
23083 : false, /* placeholder_arg */
23084 : false, /* placeholder_seen */
23085 : false /* strict_signedness */
23086 6917 : };
23087 6917 : enum dwarf_tag subrange_tag = DW_TAG_subrange_type;
23088 6917 : int dim;
23089 :
23090 6917 : add_name_attribute (array_die, type_tag (type));
23091 6917 : equate_type_number_to_die (type, array_die);
23092 :
23093 6917 : 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 6917 : if (dwarf_version >= 3 || !dwarf_strict)
23107 : {
23108 6917 : if (info->data_location)
23109 6917 : add_scalar_info (array_die, DW_AT_data_location, info->data_location,
23110 : dw_scalar_form_exprloc, &context);
23111 6917 : 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 6917 : if (info->allocated)
23117 2510 : 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 6917 : 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 6917 : if (dwarf_version >= 5)
23136 : {
23137 6917 : if (info->rank)
23138 : {
23139 1025 : add_scalar_info (array_die, DW_AT_rank, info->rank,
23140 : dw_scalar_form_constant
23141 : | dw_scalar_form_exprloc, &context);
23142 1025 : subrange_tag = DW_TAG_generic_subrange;
23143 1025 : context.placeholder_arg = true;
23144 : }
23145 : }
23146 :
23147 6917 : add_gnat_descriptive_type_attribute (array_die, type, context_die);
23148 :
23149 16136 : for (dim = 0; dim < info->ndimensions; dim++)
23150 : {
23151 9219 : dw_die_ref subrange_die = new_die (subrange_tag, array_die, NULL);
23152 :
23153 9219 : 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 9219 : if (info->dimen[dim].lower_bound)
23158 9219 : add_bound_info (subrange_die, DW_AT_lower_bound,
23159 : info->dimen[dim].lower_bound, &context);
23160 9219 : if (info->dimen[dim].upper_bound)
23161 9219 : add_bound_info (subrange_die, DW_AT_upper_bound,
23162 : info->dimen[dim].upper_bound, &context);
23163 9219 : if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
23164 9219 : 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 6917 : gen_type_die (info->element_type, context_die);
23173 6917 : add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
23174 6917 : TREE_CODE (type) == ARRAY_TYPE
23175 6917 : && TYPE_REVERSE_STORAGE_ORDER (type),
23176 : context_die);
23177 :
23178 6917 : if (get_AT (array_die, DW_AT_name))
23179 0 : add_pubtype (type, array_die);
23180 :
23181 6917 : add_alignment_attribute (array_die, type);
23182 6917 : }
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 52383 : retry_incomplete_types (void)
23212 : {
23213 52383 : set_early_dwarf s;
23214 52383 : int i;
23215 :
23216 51332515 : for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
23217 51227749 : if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
23218 51227452 : gen_type_die ((*incomplete_types)[i], comp_unit_die ());
23219 52383 : vec_safe_truncate (incomplete_types, 0);
23220 52383 : }
23221 :
23222 : /* Determine what tag to use for a record type. */
23223 :
23224 : static enum dwarf_tag
23225 53613302 : record_type_tag (tree type)
23226 : {
23227 53613302 : if (! lang_hooks.types.classify_record)
23228 : return DW_TAG_structure_type;
23229 :
23230 52976656 : 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 1855618 : gen_enumeration_type_die (tree type, dw_die_ref context_die, bool reverse)
23256 : {
23257 1855618 : dw_die_ref type_die = lookup_type_die (type);
23258 1855618 : dw_die_ref orig_type_die = type_die;
23259 :
23260 1855618 : if (type_die == NULL || reverse)
23261 : {
23262 1855204 : 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 1855204 : 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 1855202 : type_die = new_die (DW_TAG_enumeration_type, scope_die, type);
23275 1855202 : equate_type_number_to_die (type, type_die);
23276 : }
23277 1855204 : add_name_attribute (type_die, type_tag (type));
23278 816 : if ((dwarf_version >= 4 || !dwarf_strict)
23279 3710408 : && ENUM_IS_SCOPED (type))
23280 352893 : add_AT_flag (type_die, DW_AT_enum_class, 1);
23281 1855204 : if (ENUM_IS_OPAQUE (type) && TYPE_SIZE (type))
23282 333 : add_AT_flag (type_die, DW_AT_declaration, 1);
23283 1855204 : if (!dwarf_strict)
23284 1855204 : add_AT_unsigned (type_die, DW_AT_encoding,
23285 1855204 : TYPE_UNSIGNED (type)
23286 : ? DW_ATE_unsigned
23287 : : DW_ATE_signed);
23288 1855204 : if (reverse)
23289 2 : add_AT_unsigned (type_die, DW_AT_endianity,
23290 : BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
23291 : }
23292 827 : 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 1855211 : if (TYPE_SIZE (type))
23301 : {
23302 1855203 : tree link;
23303 :
23304 1855203 : if (!ENUM_IS_OPAQUE (type))
23305 1854870 : TREE_ASM_WRITTEN (type) = 1;
23306 1855203 : if (!orig_type_die || !get_AT (type_die, DW_AT_byte_size))
23307 1855201 : add_byte_size_attribute (type_die, type);
23308 1855203 : if (!orig_type_die || !get_AT (type_die, DW_AT_alignment))
23309 1855203 : add_alignment_attribute (type_die, type);
23310 816 : if ((dwarf_version >= 3 || !dwarf_strict)
23311 1856019 : && (!orig_type_die || !get_AT (type_die, DW_AT_type)))
23312 : {
23313 1855201 : tree underlying = lang_hooks.types.enum_underlying_base_type (type);
23314 1855201 : add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED, false,
23315 : context_die);
23316 : }
23317 1855203 : if (TYPE_STUB_DECL (type) != NULL_TREE)
23318 : {
23319 1855173 : if (!orig_type_die || !get_AT (type_die, DW_AT_decl_file))
23320 1855171 : add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
23321 1855173 : if (!orig_type_die || !get_AT (type_die, DW_AT_accessibility))
23322 1855173 : 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 1855203 : if (type_die->die_parent == NULL)
23328 5 : add_child_die (scope_die_for (type, context_die), type_die);
23329 :
23330 1855203 : for (link = TYPE_VALUES (type);
23331 15660723 : link != NULL; link = TREE_CHAIN (link))
23332 : {
23333 13805520 : dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
23334 13805520 : tree value = TREE_VALUE (link);
23335 :
23336 13805520 : if (DECL_P (value))
23337 13797004 : equate_decl_number_to_die (value, enum_die);
23338 :
23339 13805520 : gcc_assert (!ENUM_IS_OPAQUE (type));
23340 13805520 : add_name_attribute (enum_die,
23341 13805520 : IDENTIFIER_POINTER (TREE_PURPOSE (link)));
23342 :
23343 13805520 : if (TREE_CODE (value) == CONST_DECL)
23344 13797004 : value = DECL_INITIAL (value);
23345 :
23346 13805520 : if (simple_type_size_in_bits (TREE_TYPE (value))
23347 13805520 : <= 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 13805518 : HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
23355 13805518 : if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
23356 13619175 : add_AT_unsigned (enum_die, DW_AT_const_value,
23357 : (unsigned HOST_WIDE_INT) val);
23358 : else
23359 186343 : 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 1855203 : add_gnat_descriptive_type_attribute (type_die, type, context_die);
23369 1855203 : if (TYPE_ARTIFICIAL (type)
23370 1855203 : && (!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 1855211 : add_pubtype (type, type_die);
23377 :
23378 1855211 : 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 195932454 : gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
23398 : dw_die_ref context_die)
23399 : {
23400 195932454 : tree node_or_origin = node ? node : origin;
23401 195932454 : tree ultimate_origin;
23402 195932454 : dw_die_ref parm_die = NULL;
23403 :
23404 195932454 : if (DECL_P (node_or_origin))
23405 : {
23406 16923814 : 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 16923814 : if (parm_die
23413 970436 : && parm_die->die_parent != context_die
23414 86035 : && (parm_die->die_parent->die_tag != DW_TAG_GNU_formal_parameter_pack
23415 2223 : || parm_die->die_parent->die_parent != context_die)
23416 84228 : && !in_lto_p)
23417 : {
23418 84228 : 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 886208 : 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 195932454 : bool reusing_die;
23448 195932454 : if (parm_die && origin == NULL)
23449 : reusing_die = true;
23450 : else
23451 : {
23452 195046246 : parm_die = new_die (DW_TAG_formal_parameter, context_die, node);
23453 195046246 : reusing_die = false;
23454 : }
23455 :
23456 195932454 : switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
23457 : {
23458 16923814 : case tcc_declaration:
23459 16923814 : ultimate_origin = decl_ultimate_origin (node_or_origin);
23460 16923814 : if (node || ultimate_origin)
23461 16923814 : origin = ultimate_origin;
23462 :
23463 16923814 : if (reusing_die)
23464 886208 : goto add_location;
23465 :
23466 16037606 : if (origin != NULL)
23467 12618081 : add_abstract_origin_attribute (parm_die, origin);
23468 3419525 : else if (emit_name_p)
23469 3317579 : add_name_and_src_coords_attributes (parm_die, node);
23470 16037606 : if (origin == NULL
23471 16037606 : || (! DECL_ABSTRACT_P (node_or_origin)
23472 12618081 : && variably_modified_type_p (TREE_TYPE (node_or_origin),
23473 : decl_function_context
23474 : (node_or_origin))))
23475 : {
23476 3421264 : tree type = TREE_TYPE (node_or_origin);
23477 3421264 : if (decl_by_reference_p (node_or_origin))
23478 40891 : add_type_attribute (parm_die, TREE_TYPE (type),
23479 : TYPE_UNQUALIFIED,
23480 : false, context_die);
23481 : else
23482 3380373 : add_type_attribute (parm_die, type,
23483 : decl_quals (node_or_origin),
23484 : false, context_die);
23485 : }
23486 16037606 : if (origin == NULL && DECL_ARTIFICIAL (node))
23487 972266 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23488 16923814 : add_location:
23489 16923814 : if (node && node != origin)
23490 16839534 : equate_decl_number_to_die (node, parm_die);
23491 16923814 : if (! DECL_ABSTRACT_P (node_or_origin))
23492 16923814 : add_location_or_const_value_attribute (parm_die, node_or_origin,
23493 : node == NULL);
23494 :
23495 : break;
23496 :
23497 179008640 : case tcc_type:
23498 : /* We were called with some kind of a ..._TYPE node. */
23499 179008640 : add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED, false,
23500 : context_die);
23501 179008640 : break;
23502 :
23503 0 : default:
23504 0 : gcc_unreachable ();
23505 : }
23506 :
23507 195932454 : maybe_gen_btf_decl_tag_dies (node_or_origin, parm_die);
23508 :
23509 195932454 : 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 82864 : gen_formal_parameter_pack_die (tree parm_pack,
23525 : tree pack_arg,
23526 : dw_die_ref subr_die,
23527 : tree *next_arg)
23528 : {
23529 82864 : tree arg;
23530 82864 : dw_die_ref parm_pack_die;
23531 :
23532 82864 : gcc_assert (parm_pack
23533 : && lang_hooks.function_parameter_pack_p (parm_pack)
23534 : && subr_die);
23535 :
23536 82864 : parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
23537 82864 : add_name_and_src_coords_attributes (parm_pack_die, parm_pack);
23538 :
23539 282474 : for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
23540 : {
23541 116746 : if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
23542 : parm_pack))
23543 : break;
23544 116746 : gen_formal_parameter_die (arg, NULL,
23545 : false /* Don't emit name attribute. */,
23546 : parm_pack_die);
23547 : }
23548 82864 : if (next_arg)
23549 82864 : *next_arg = arg;
23550 82864 : 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 89352 : 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 89352 : }
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 96691908 : gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
23569 : {
23570 96691908 : tree link;
23571 96691908 : tree formal_type = NULL;
23572 96691908 : tree first_parm_type;
23573 96691908 : tree arg;
23574 :
23575 96691908 : if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
23576 : {
23577 96285876 : arg = DECL_ARGUMENTS (function_or_method_type);
23578 96285876 : function_or_method_type = TREE_TYPE (function_or_method_type);
23579 : }
23580 : else
23581 : arg = NULL_TREE;
23582 :
23583 96691908 : 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 275700548 : for (link = first_parm_type; link; )
23588 : {
23589 275615717 : dw_die_ref parm_die;
23590 :
23591 275615717 : formal_type = TREE_VALUE (link);
23592 275615717 : if (formal_type == void_type_node)
23593 : break;
23594 :
23595 : /* Output a (nameless) DIE to represent the formal parameter itself. */
23596 179008640 : parm_die = gen_formal_parameter_die (formal_type, NULL,
23597 : true /* Emit name attribute. */,
23598 : context_die);
23599 179008640 : if (TREE_CODE (function_or_method_type) == METHOD_TYPE
23600 163532857 : && link == first_parm_type)
23601 : {
23602 83066343 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23603 83066343 : if (dwarf_version >= 3 || !dwarf_strict)
23604 83066343 : add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
23605 : }
23606 95942297 : else if (arg && DECL_ARTIFICIAL (arg))
23607 22107 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23608 :
23609 179008640 : link = TREE_CHAIN (link);
23610 179008640 : if (arg)
23611 178273545 : 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 96691908 : if (formal_type != void_type_node)
23617 84831 : 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 96691908 : for (link = TYPE_ARG_TYPES (function_or_method_type);
23622 647923342 : link && TREE_VALUE (link);
23623 275615717 : link = TREE_CHAIN (link))
23624 275615717 : gen_type_die (TREE_VALUE (link), context_die);
23625 96691908 : }
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 118353729 : gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
23635 : {
23636 118353729 : 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 118353729 : if (TYPE_STUB_DECL (type)
23641 118353729 : && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
23642 118489751 : && ! lookup_decl_die (member))
23643 : {
23644 111803 : dw_die_ref type_die;
23645 111803 : gcc_assert (!decl_ultimate_origin (member));
23646 :
23647 111803 : type_die = lookup_type_die_strip_naming_typedef (type);
23648 111803 : if (TREE_CODE (member) == FUNCTION_DECL)
23649 110984 : gen_subprogram_die (member, type_die);
23650 819 : 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 813 : gen_variable_die (member, NULL_TREE, type_die);
23668 : }
23669 118353729 : }
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 2767988 : set_block_origin_self (tree stmt)
23687 : {
23688 2767988 : if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
23689 : {
23690 1677786 : BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
23691 :
23692 1677786 : {
23693 1677786 : tree local_decl;
23694 :
23695 1677786 : for (local_decl = BLOCK_VARS (stmt);
23696 2409045 : local_decl != NULL_TREE;
23697 731259 : 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 731259 : if (TREE_CODE (local_decl) != FUNCTION_DECL
23701 731259 : && !DECL_EXTERNAL (local_decl))
23702 727960 : set_decl_origin_self (local_decl);
23703 : }
23704 :
23705 1677786 : {
23706 1677786 : tree subblock;
23707 :
23708 3131544 : for (subblock = BLOCK_SUBBLOCKS (stmt);
23709 3131544 : subblock != NULL_TREE;
23710 1453758 : subblock = BLOCK_CHAIN (subblock))
23711 1453758 : set_block_origin_self (subblock); /* Recurse. */
23712 : }
23713 : }
23714 2767988 : }
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 2057882 : set_decl_origin_self (tree decl)
23729 : {
23730 2057882 : if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
23731 : {
23732 2057882 : DECL_ABSTRACT_ORIGIN (decl) = decl;
23733 2057882 : if (TREE_CODE (decl) == FUNCTION_DECL)
23734 : {
23735 1329922 : tree arg;
23736 :
23737 3847152 : for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
23738 2517230 : DECL_ABSTRACT_ORIGIN (arg) = arg;
23739 1329922 : if (DECL_INITIAL (decl) != NULL_TREE
23740 1329922 : && DECL_INITIAL (decl) != error_mark_node)
23741 1314230 : set_block_origin_self (DECL_INITIAL (decl));
23742 : }
23743 : }
23744 2057882 : }
23745 :
23746 : /* Mark the early DIE for DECL as the abstract instance. */
23747 :
23748 : static void
23749 4287188 : dwarf2out_abstract_function (tree decl)
23750 : {
23751 4287188 : dw_die_ref old_die;
23752 :
23753 : /* Make sure we have the actual abstract inline, not a clone. */
23754 4287188 : decl = DECL_ORIGIN (decl);
23755 :
23756 4287188 : 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 4287053 : if (in_lto_p)
23768 : return;
23769 :
23770 4286641 : old_die = lookup_decl_die (decl);
23771 4286641 : gcc_assert (old_die != NULL);
23772 4286641 : 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 1329922 : if (DECL_DECLARED_INLINE_P (decl))
23778 : {
23779 1215270 : if (cgraph_function_possibly_inlined_p (decl))
23780 921624 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_inlined);
23781 : else
23782 293646 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_not_inlined);
23783 : }
23784 : else
23785 : {
23786 114652 : if (cgraph_function_possibly_inlined_p (decl))
23787 94086 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_inlined);
23788 : else
23789 20566 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_not_inlined);
23790 : }
23791 :
23792 1329922 : if (DECL_DECLARED_INLINE_P (decl)
23793 1329922 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
23794 1290 : add_AT_flag (old_die, DW_AT_artificial, 1);
23795 :
23796 1329922 : set_decl_origin_self (decl);
23797 : }
23798 :
23799 : /* Helper function of premark_used_types() which gets called through
23800 : htab_traverse.
23801 :
23802 : Marks the DIE of a given type in *SLOT as perennial, so it never gets
23803 : marked as unused by prune_unused_types. */
23804 :
23805 : bool
23806 1216795 : premark_used_types_helper (tree const &type, void *)
23807 : {
23808 1216795 : dw_die_ref die;
23809 :
23810 1216795 : die = lookup_type_die (type);
23811 1216795 : if (die != NULL)
23812 1061459 : die->die_perennial_p = 1;
23813 1216795 : return true;
23814 : }
23815 :
23816 : /* Helper function of premark_types_used_by_global_vars which gets called
23817 : through htab_traverse.
23818 :
23819 : Marks the DIE of a given type in *SLOT as perennial, so it never gets
23820 : marked as unused by prune_unused_types. The DIE of the type is marked
23821 : only if the global variable using the type will actually be emitted. */
23822 :
23823 : int
23824 8534891 : premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
23825 : void *)
23826 : {
23827 8534891 : struct types_used_by_vars_entry *entry;
23828 8534891 : dw_die_ref die;
23829 :
23830 8534891 : entry = (struct types_used_by_vars_entry *) *slot;
23831 8534891 : gcc_assert (entry->type != NULL
23832 : && entry->var_decl != NULL);
23833 8534891 : die = lookup_type_die (entry->type);
23834 8534891 : if (die)
23835 : {
23836 : /* Ask cgraph if the global variable really is to be emitted.
23837 : If yes, then we'll keep the DIE of ENTRY->TYPE. */
23838 7750401 : varpool_node *node = varpool_node::get (entry->var_decl);
23839 7750401 : if (node && node->definition)
23840 : {
23841 10160 : die->die_perennial_p = 1;
23842 : /* Keep the parent DIEs as well. */
23843 18230 : while ((die = die->die_parent) && die->die_perennial_p == 0)
23844 8070 : die->die_perennial_p = 1;
23845 : }
23846 : }
23847 8534891 : return 1;
23848 : }
23849 :
23850 : /* Mark all members of used_types_hash as perennial. */
23851 :
23852 : static void
23853 98985223 : premark_used_types (struct function *fun)
23854 : {
23855 98985223 : if (fun && fun->used_types_hash)
23856 2067983 : fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
23857 98985223 : }
23858 :
23859 : /* Mark all members of types_used_by_vars_entry as perennial. */
23860 :
23861 : static void
23862 52416 : premark_types_used_by_global_vars (void)
23863 : {
23864 52416 : if (types_used_by_vars_hash)
23865 13895 : types_used_by_vars_hash
23866 8548786 : ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
23867 52416 : }
23868 :
23869 : /* Mark all variables used by the symtab as perennial. */
23870 :
23871 : static void
23872 52384 : premark_used_variables (void)
23873 : {
23874 : /* Mark DIEs in the symtab as used. */
23875 52384 : varpool_node *var;
23876 2009872 : FOR_EACH_VARIABLE (var)
23877 : {
23878 1957488 : dw_die_ref die = lookup_decl_die (var->decl);
23879 1957488 : if (die)
23880 : {
23881 270153 : die->die_perennial_p = 1;
23882 270153 : if (tree attr = lookup_attribute ("structured bindings",
23883 270153 : DECL_ATTRIBUTES (var->decl)))
23884 166 : for (tree d = TREE_VALUE (attr); d; d = TREE_CHAIN (d))
23885 : {
23886 128 : die = lookup_decl_die (TREE_VALUE (d));
23887 128 : if (die)
23888 128 : die->die_perennial_p = 1;
23889 : }
23890 : }
23891 : }
23892 52384 : }
23893 :
23894 : /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
23895 : for CA_LOC call arg loc node. */
23896 :
23897 : static dw_die_ref
23898 2858538 : gen_call_site_die (tree decl, dw_die_ref subr_die,
23899 : struct call_arg_loc_node *ca_loc)
23900 : {
23901 2858538 : dw_die_ref stmt_die = NULL, die;
23902 2858538 : tree block = ca_loc->block;
23903 :
23904 2858538 : while (block
23905 5405951 : && block != DECL_INITIAL (decl)
23906 9871539 : && TREE_CODE (block) == BLOCK)
23907 : {
23908 4399534 : stmt_die = lookup_block_die (block);
23909 4399534 : if (stmt_die)
23910 : break;
23911 2613467 : block = BLOCK_SUPERCONTEXT (block);
23912 : }
23913 2858538 : if (stmt_die == NULL)
23914 1072471 : stmt_die = subr_die;
23915 2860393 : die = new_die (dwarf_TAG (DW_TAG_call_site), stmt_die, NULL_TREE);
23916 2860393 : add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc),
23917 : ca_loc->label,
23918 2858538 : targetm.calls.call_offset_return_label (ca_loc->call_insn));
23919 2858538 : if (ca_loc->tail_call_p)
23920 56439 : add_AT_flag (die, dwarf_AT (DW_AT_call_tail_call), 1);
23921 2858538 : if (ca_loc->symbol_ref)
23922 : {
23923 2786880 : dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
23924 2786880 : if (tdie)
23925 1306640 : add_AT_die_ref (die, dwarf_AT (DW_AT_call_origin), tdie);
23926 : else
23927 1482073 : add_AT_addr (die, dwarf_AT (DW_AT_call_origin), ca_loc->symbol_ref,
23928 : false);
23929 : }
23930 2858538 : return die;
23931 : }
23932 :
23933 : /* Generate a DIE to represent a declared function (either file-scope or
23934 : block-local). */
23935 :
23936 : static void
23937 99112677 : gen_subprogram_die (tree decl, dw_die_ref context_die)
23938 : {
23939 99112677 : tree origin = decl_ultimate_origin (decl);
23940 99112677 : dw_die_ref subr_die;
23941 99112677 : dw_die_ref old_die = lookup_decl_die (decl);
23942 99112677 : bool old_die_had_no_children = false;
23943 :
23944 : /* This function gets called multiple times for different stages of
23945 : the debug process. For example, for func() in this code:
23946 :
23947 : namespace S
23948 : {
23949 : void func() { ... }
23950 : }
23951 :
23952 : ...we get called 4 times. Twice in early debug and twice in
23953 : late debug:
23954 :
23955 : Early debug
23956 : -----------
23957 :
23958 : 1. Once while generating func() within the namespace. This is
23959 : the declaration. The declaration bit below is set, as the
23960 : context is the namespace.
23961 :
23962 : A new DIE will be generated with DW_AT_declaration set.
23963 :
23964 : 2. Once for func() itself. This is the specification. The
23965 : declaration bit below is clear as the context is the CU.
23966 :
23967 : We will use the cached DIE from (1) to create a new DIE with
23968 : DW_AT_specification pointing to the declaration in (1).
23969 :
23970 : Late debug via rest_of_handle_final()
23971 : -------------------------------------
23972 :
23973 : 3. Once generating func() within the namespace. This is also the
23974 : declaration, as in (1), but this time we will early exit below
23975 : as we have a cached DIE and a declaration needs no additional
23976 : annotations (no locations), as the source declaration line
23977 : info is enough.
23978 :
23979 : 4. Once for func() itself. As in (2), this is the specification,
23980 : but this time we will re-use the cached DIE, and just annotate
23981 : it with the location information that should now be available.
23982 :
23983 : For something without namespaces, but with abstract instances, we
23984 : are also called a multiple times:
23985 :
23986 : class Base
23987 : {
23988 : public:
23989 : Base (); // constructor declaration (1)
23990 : };
23991 :
23992 : Base::Base () { } // constructor specification (2)
23993 :
23994 : Early debug
23995 : -----------
23996 :
23997 : 1. Once for the Base() constructor by virtue of it being a
23998 : member of the Base class. This is done via
23999 : rest_of_type_compilation.
24000 :
24001 : This is a declaration, so a new DIE will be created with
24002 : DW_AT_declaration.
24003 :
24004 : 2. Once for the Base() constructor definition, but this time
24005 : while generating the abstract instance of the base
24006 : constructor (__base_ctor) which is being generated via early
24007 : debug of reachable functions.
24008 :
24009 : Even though we have a cached version of the declaration (1),
24010 : we will create a DW_AT_specification of the declaration DIE
24011 : in (1).
24012 :
24013 : 3. Once for the __base_ctor itself, but this time, we generate
24014 : an DW_AT_abstract_origin version of the DW_AT_specification in
24015 : (2).
24016 :
24017 : Late debug via rest_of_handle_final
24018 : -----------------------------------
24019 :
24020 : 4. One final time for the __base_ctor (which will have a cached
24021 : DIE with DW_AT_abstract_origin created in (3). This time,
24022 : we will just annotate the location information now
24023 : available.
24024 : */
24025 99112677 : int declaration = (current_function_decl != decl
24026 3392122 : || (!DECL_INITIAL (decl) && !origin)
24027 102118239 : || class_or_namespace_scope_p (context_die));
24028 :
24029 : /* A declaration that has been previously dumped needs no
24030 : additional information. */
24031 99112677 : if (old_die && declaration)
24032 : return;
24033 :
24034 98985223 : if (in_lto_p && old_die && old_die->die_child == NULL)
24035 98985223 : old_die_had_no_children = true;
24036 :
24037 : /* Now that the C++ front end lazily declares artificial member fns, we
24038 : might need to retrofit the declaration into its class. */
24039 2266495 : if (!declaration && !origin && !old_die
24040 688403 : && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
24041 228481 : && !class_or_namespace_scope_p (context_die)
24042 99213704 : && debug_info_level > DINFO_LEVEL_TERSE)
24043 228282 : old_die = force_decl_die (decl);
24044 :
24045 : /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
24046 98985223 : if (origin != NULL)
24047 : {
24048 432672 : gcc_assert (!declaration || local_scope_p (context_die));
24049 :
24050 : /* Fixup die_parent for the abstract instance of a nested
24051 : inline function. */
24052 432672 : if (old_die && old_die->die_parent == NULL)
24053 0 : add_child_die (context_die, old_die);
24054 :
24055 77366 : if (old_die && get_AT_ref (old_die, DW_AT_abstract_origin))
24056 : {
24057 : /* If we have a DW_AT_abstract_origin we have a working
24058 : cached version. */
24059 : subr_die = old_die;
24060 : }
24061 : else
24062 : {
24063 405130 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
24064 405130 : add_abstract_origin_attribute (subr_die, origin);
24065 : /* This is where the actual code for a cloned function is.
24066 : Let's emit linkage name attribute for it. This helps
24067 : debuggers to e.g, set breakpoints into
24068 : constructors/destructors when the user asks "break
24069 : K::K". */
24070 405130 : add_linkage_name (subr_die, decl);
24071 : }
24072 : }
24073 : /* A cached copy, possibly from early dwarf generation. Reuse as
24074 : much as possible. */
24075 98552551 : else if (old_die)
24076 : {
24077 1806374 : if (!get_AT_flag (old_die, DW_AT_declaration)
24078 : /* We can have a normal definition following an inline one in the
24079 : case of redefinition of GNU C extern inlines.
24080 : It seems reasonable to use AT_specification in this case. */
24081 1806374 : && !get_AT (old_die, DW_AT_inline))
24082 : {
24083 : /* Detect and ignore this case, where we are trying to output
24084 : something we have already output. */
24085 384014 : if (get_AT (old_die, DW_AT_low_pc)
24086 384014 : || get_AT (old_die, DW_AT_ranges))
24087 0 : return;
24088 :
24089 : /* If we have no location information, this must be a
24090 : partially generated DIE from early dwarf generation.
24091 : Fall through and generate it. */
24092 : }
24093 :
24094 : /* If the definition comes from the same place as the declaration,
24095 : maybe use the old DIE. We always want the DIE for this function
24096 : that has the *_pc attributes to be under comp_unit_die so the
24097 : debugger can find it. We also need to do this for abstract
24098 : instances of inlines, since the spec requires the out-of-line copy
24099 : to have the same parent. For local class methods, this doesn't
24100 : apply; we just use the old DIE. */
24101 1806374 : expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
24102 1806374 : struct dwarf_file_data * file_index = lookup_filename (s.file);
24103 1806374 : if (((is_unit_die (old_die->die_parent)
24104 : /* This condition fixes the inconsistency/ICE with the
24105 : following Fortran test (or some derivative thereof) while
24106 : building libgfortran:
24107 :
24108 : module some_m
24109 : contains
24110 : logical function funky (FLAG)
24111 : funky = .true.
24112 : end function
24113 : end module
24114 : */
24115 1354093 : || (old_die->die_parent
24116 1354093 : && old_die->die_parent->die_tag == DW_TAG_module)
24117 1351352 : || local_scope_p (old_die->die_parent)
24118 1306732 : || context_die == NULL)
24119 499672 : && (DECL_ARTIFICIAL (decl)
24120 464331 : || (get_AT_file (old_die, DW_AT_decl_file) == file_index
24121 461817 : && (get_AT_unsigned (old_die, DW_AT_decl_line)
24122 461817 : == (unsigned) s.line)
24123 461817 : && (!debug_column_info
24124 461813 : || s.column == 0
24125 368366 : || (get_AT_unsigned (old_die, DW_AT_decl_column)
24126 368366 : == (unsigned) s.column)))))
24127 : /* With LTO if there's an abstract instance for
24128 : the old DIE, this is a concrete instance and
24129 : thus re-use the DIE. */
24130 3115590 : || get_AT (old_die, DW_AT_abstract_origin))
24131 : {
24132 503055 : subr_die = old_die;
24133 :
24134 : /* Clear out the declaration attribute, but leave the
24135 : parameters so they can be augmented with location
24136 : information later. Unless this was a declaration, in
24137 : which case, wipe out the nameless parameters and recreate
24138 : them further down. */
24139 503055 : if (remove_AT (subr_die, DW_AT_declaration))
24140 : {
24141 :
24142 42612 : remove_AT (subr_die, DW_AT_object_pointer);
24143 42612 : remove_child_TAG (subr_die, DW_TAG_formal_parameter);
24144 : }
24145 : }
24146 : /* Make a specification pointing to the previously built
24147 : declaration. */
24148 : else
24149 : {
24150 1303319 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
24151 1303319 : add_AT_specification (subr_die, old_die);
24152 1303319 : add_pubname (decl, subr_die);
24153 1303319 : if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
24154 47234 : add_AT_file (subr_die, DW_AT_decl_file, file_index);
24155 1303319 : if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
24156 51708 : add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
24157 1303319 : if (debug_column_info
24158 1303307 : && s.column
24159 2606626 : && (get_AT_unsigned (old_die, DW_AT_decl_column)
24160 1303307 : != (unsigned) s.column))
24161 51698 : add_AT_unsigned (subr_die, DW_AT_decl_column, s.column);
24162 :
24163 : /* If the prototype had an 'auto' or 'decltype(auto)' in
24164 : the return type, emit the real type on the definition die. */
24165 1303319 : if (is_cxx () && debug_info_level > DINFO_LEVEL_TERSE)
24166 : {
24167 1303319 : dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
24168 1303319 : while (die
24169 1636280 : && (die->die_tag == DW_TAG_reference_type
24170 : || die->die_tag == DW_TAG_rvalue_reference_type
24171 : || die->die_tag == DW_TAG_pointer_type
24172 : || die->die_tag == DW_TAG_const_type
24173 : || die->die_tag == DW_TAG_volatile_type
24174 : || die->die_tag == DW_TAG_restrict_type
24175 : || die->die_tag == DW_TAG_array_type
24176 : || die->die_tag == DW_TAG_ptr_to_member_type
24177 : || die->die_tag == DW_TAG_subroutine_type))
24178 332961 : die = get_AT_ref (die, DW_AT_type);
24179 1303319 : if (die == auto_die || die == decltype_auto_die)
24180 118265 : add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
24181 : TYPE_UNQUALIFIED, false, context_die);
24182 : }
24183 :
24184 : /* When we process the method declaration, we haven't seen
24185 : the out-of-class defaulted definition yet, so we have to
24186 : recheck now. */
24187 1294 : if ((dwarf_version >= 5 || ! dwarf_strict)
24188 1304601 : && !get_AT (subr_die, DW_AT_defaulted))
24189 : {
24190 1282274 : int defaulted
24191 1282274 : = lang_hooks.decls.decl_dwarf_attribute (decl,
24192 : DW_AT_defaulted);
24193 1282274 : if (defaulted != -1)
24194 : {
24195 : /* Other values must have been handled before. */
24196 318 : gcc_assert (defaulted == DW_DEFAULTED_out_of_class);
24197 318 : add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
24198 : }
24199 : }
24200 : }
24201 : }
24202 : /* Create a fresh DIE for anything else. */
24203 : else
24204 : {
24205 96746177 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
24206 :
24207 96746177 : if (TREE_PUBLIC (decl))
24208 96558989 : add_AT_flag (subr_die, DW_AT_external, 1);
24209 :
24210 96746177 : add_name_and_src_coords_attributes (subr_die, decl);
24211 96746177 : add_pubname (decl, subr_die);
24212 96746177 : if (debug_info_level > DINFO_LEVEL_TERSE)
24213 : {
24214 96732469 : add_prototyped_attribute (subr_die, TREE_TYPE (decl));
24215 96732469 : add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
24216 : TYPE_UNQUALIFIED, false, context_die);
24217 : }
24218 :
24219 96746177 : add_pure_or_virtual_attribute (subr_die, decl);
24220 96746177 : if (DECL_ARTIFICIAL (decl))
24221 2070190 : add_AT_flag (subr_die, DW_AT_artificial, 1);
24222 :
24223 96746177 : if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
24224 70529 : add_AT_flag (subr_die, DW_AT_noreturn, 1);
24225 :
24226 96746177 : add_alignment_attribute (subr_die, decl);
24227 :
24228 96746177 : add_accessibility_attribute (subr_die, decl);
24229 : }
24230 :
24231 : /* Unless we have an existing non-declaration DIE, equate the new
24232 : DIE. */
24233 98985223 : if (!old_die || is_declaration_die (old_die))
24234 98404790 : equate_decl_number_to_die (decl, subr_die);
24235 :
24236 98985223 : if (declaration)
24237 : {
24238 96286056 : if (!old_die || !get_AT (old_die, DW_AT_inline))
24239 : {
24240 96286056 : add_AT_flag (subr_die, DW_AT_declaration, 1);
24241 :
24242 : /* If this is an explicit function declaration then generate
24243 : a DW_AT_explicit attribute. */
24244 2976 : if ((dwarf_version >= 3 || !dwarf_strict)
24245 96289032 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24246 : DW_AT_explicit) == 1)
24247 2953481 : add_AT_flag (subr_die, DW_AT_explicit, 1);
24248 :
24249 : /* If this is a C++11 deleted special function member then generate
24250 : a DW_AT_deleted attribute. */
24251 3198 : if ((dwarf_version >= 5 || !dwarf_strict)
24252 96289236 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24253 : DW_AT_deleted) == 1)
24254 3190946 : add_AT_flag (subr_die, DW_AT_deleted, 1);
24255 :
24256 : /* If this is a C++11 defaulted special function member then
24257 : generate a DW_AT_defaulted attribute. */
24258 96286056 : if (dwarf_version >= 5 || !dwarf_strict)
24259 : {
24260 96286038 : int defaulted
24261 96286038 : = lang_hooks.decls.decl_dwarf_attribute (decl,
24262 : DW_AT_defaulted);
24263 96286038 : if (defaulted != -1)
24264 5974304 : add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
24265 : }
24266 :
24267 : /* If this is a C++11 non-static member function with & ref-qualifier
24268 : then generate a DW_AT_reference attribute. */
24269 3198 : if ((dwarf_version >= 5 || !dwarf_strict)
24270 96289236 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24271 : DW_AT_reference) == 1)
24272 40981 : add_AT_flag (subr_die, DW_AT_reference, 1);
24273 :
24274 : /* If this is a C++11 non-static member function with &&
24275 : ref-qualifier then generate a DW_AT_reference attribute. */
24276 3198 : if ((dwarf_version >= 5 || !dwarf_strict)
24277 96289236 : && lang_hooks.decls.decl_dwarf_attribute (decl,
24278 : DW_AT_rvalue_reference)
24279 : == 1)
24280 80280 : add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
24281 : }
24282 : }
24283 : /* For non DECL_EXTERNALs, if range information is available, fill
24284 : the DIE with it. */
24285 2699167 : else if (!DECL_EXTERNAL (decl) && !early_dwarf)
24286 : {
24287 560785 : HOST_WIDE_INT cfa_fb_offset;
24288 :
24289 560785 : struct function *fun = DECL_STRUCT_FUNCTION (decl);
24290 :
24291 560785 : if (!crtl->has_bb_partition)
24292 : {
24293 539271 : dw_fde_ref fde = fun->fde;
24294 539271 : if (fde->dw_fde_begin)
24295 : {
24296 : /* We have already generated the labels. */
24297 539271 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
24298 : fde->dw_fde_end, false);
24299 : }
24300 : else
24301 : {
24302 : /* Create start/end labels and add the range. */
24303 0 : char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
24304 0 : char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
24305 0 : ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
24306 : current_function_funcdef_no);
24307 0 : ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
24308 : current_function_funcdef_no);
24309 0 : add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
24310 : false);
24311 : }
24312 :
24313 : #if VMS_DEBUGGING_INFO
24314 : /* HP OpenVMS Industry Standard 64: DWARF Extensions
24315 : Section 2.3 Prologue and Epilogue Attributes:
24316 : When a breakpoint is set on entry to a function, it is generally
24317 : desirable for execution to be suspended, not on the very first
24318 : instruction of the function, but rather at a point after the
24319 : function's frame has been set up, after any language defined local
24320 : declaration processing has been completed, and before execution of
24321 : the first statement of the function begins. Debuggers generally
24322 : cannot properly determine where this point is. Similarly for a
24323 : breakpoint set on exit from a function. The prologue and epilogue
24324 : attributes allow a compiler to communicate the location(s) to use. */
24325 :
24326 : {
24327 : if (fde->dw_fde_vms_end_prologue)
24328 : add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
24329 : fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
24330 :
24331 : if (fde->dw_fde_vms_begin_epilogue)
24332 : add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
24333 : fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
24334 : }
24335 : #endif
24336 :
24337 : }
24338 : else
24339 : {
24340 : /* Generate pubnames entries for the split function code ranges. */
24341 21514 : dw_fde_ref fde = fun->fde;
24342 :
24343 21514 : if (fde->dw_fde_second_begin)
24344 : {
24345 21514 : if (dwarf_version >= 3 || !dwarf_strict)
24346 : {
24347 : /* We should use ranges for non-contiguous code section
24348 : addresses. Use the actual code range for the initial
24349 : section, since the HOT/COLD labels might precede an
24350 : alignment offset. */
24351 21514 : bool range_list_added = false;
24352 21514 : add_ranges_by_labels (subr_die, fde->dw_fde_begin,
24353 : fde->dw_fde_end, &range_list_added,
24354 : false);
24355 21514 : add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
24356 : fde->dw_fde_second_end,
24357 : &range_list_added, false);
24358 21514 : if (range_list_added)
24359 21514 : add_ranges (NULL);
24360 21514 : }
24361 : else
24362 : {
24363 : /* There is no real support in DW2 for this .. so we make
24364 : a work-around. First, emit the pub name for the segment
24365 : containing the function label. Then make and emit a
24366 : simplified subprogram DIE for the second segment with the
24367 : name pre-fixed by __hot/cold_sect_of_. We use the same
24368 : linkage name for the second die so that gdb will find both
24369 : sections when given "b foo". */
24370 0 : const char *name = NULL;
24371 0 : tree decl_name = DECL_NAME (decl);
24372 0 : dw_die_ref seg_die;
24373 :
24374 : /* Do the 'primary' section. */
24375 0 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
24376 : fde->dw_fde_end, false);
24377 :
24378 : /* Build a minimal DIE for the secondary section. */
24379 0 : seg_die = new_die (DW_TAG_subprogram,
24380 : subr_die->die_parent, decl);
24381 :
24382 0 : if (TREE_PUBLIC (decl))
24383 0 : add_AT_flag (seg_die, DW_AT_external, 1);
24384 :
24385 0 : if (decl_name != NULL
24386 0 : && IDENTIFIER_POINTER (decl_name) != NULL)
24387 : {
24388 0 : name = dwarf2_name (decl, 1);
24389 0 : if (! DECL_ARTIFICIAL (decl))
24390 0 : add_src_coords_attributes (seg_die, decl);
24391 :
24392 0 : add_linkage_name (seg_die, decl);
24393 : }
24394 0 : gcc_assert (name != NULL);
24395 0 : add_pure_or_virtual_attribute (seg_die, decl);
24396 0 : if (DECL_ARTIFICIAL (decl))
24397 0 : add_AT_flag (seg_die, DW_AT_artificial, 1);
24398 :
24399 0 : name = concat ("__second_sect_of_", name, NULL);
24400 0 : add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
24401 : fde->dw_fde_second_end, false);
24402 0 : add_name_attribute (seg_die, name);
24403 0 : if (want_pubnames ())
24404 0 : add_pubname_string (name, seg_die);
24405 : }
24406 : }
24407 : else
24408 0 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
24409 : false);
24410 : }
24411 :
24412 560785 : cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
24413 :
24414 : /* We define the "frame base" as the function's CFA. This is more
24415 : convenient for several reasons: (1) It's stable across the prologue
24416 : and epilogue, which makes it better than just a frame pointer,
24417 : (2) With dwarf3, there exists a one-byte encoding that allows us
24418 : to reference the .debug_frame data by proxy, but failing that,
24419 : (3) We can at least reuse the code inspection and interpretation
24420 : code that determines the CFA position at various points in the
24421 : function. */
24422 560785 : if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
24423 : {
24424 557394 : dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
24425 557394 : add_AT_loc (subr_die, DW_AT_frame_base, op);
24426 : }
24427 : else
24428 : {
24429 3391 : dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
24430 3391 : if (list->dw_loc_next)
24431 1843 : add_AT_loc_list (subr_die, DW_AT_frame_base, list);
24432 : else
24433 1548 : add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
24434 : }
24435 :
24436 : /* Compute a displacement from the "steady-state frame pointer" to
24437 : the CFA. The former is what all stack slots and argument slots
24438 : will reference in the rtl; the latter is what we've told the
24439 : debugger about. We'll need to adjust all frame_base references
24440 : by this displacement. */
24441 560785 : compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
24442 :
24443 560785 : if (fun->static_chain_decl)
24444 : {
24445 : /* DWARF requires here a location expression that computes the
24446 : address of the enclosing subprogram's frame base. The machinery
24447 : in tree-nested.cc is supposed to store this specific address in the
24448 : last field of the FRAME record. */
24449 14527 : const tree frame_type
24450 14527 : = TREE_TYPE (TREE_TYPE (fun->static_chain_decl));
24451 14527 : const tree fb_decl = tree_last (TYPE_FIELDS (frame_type));
24452 :
24453 14527 : tree fb_expr
24454 14527 : = build1 (INDIRECT_REF, frame_type, fun->static_chain_decl);
24455 14527 : fb_expr = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
24456 : fb_expr, fb_decl, NULL_TREE);
24457 :
24458 14527 : add_AT_location_description (subr_die, DW_AT_static_link,
24459 : loc_list_from_tree (fb_expr, 0, NULL));
24460 : }
24461 :
24462 560785 : resolve_variable_values ();
24463 : }
24464 :
24465 : /* Generate child dies for template parameters. */
24466 98985223 : if (early_dwarf && debug_info_level > DINFO_LEVEL_TERSE)
24467 98410566 : gen_generic_params_dies (decl);
24468 :
24469 : /* Now output descriptions of the arguments for this function. This gets
24470 : (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
24471 : for a FUNCTION_DECL doesn't indicate cases where there was a trailing
24472 : `...' at the end of the formal parameter list. In order to find out if
24473 : there was a trailing ellipsis or not, we must instead look at the type
24474 : associated with the FUNCTION_DECL. This will be a node of type
24475 : FUNCTION_TYPE. If the chain of type nodes hanging off of this
24476 : FUNCTION_TYPE node ends with a void_type_node then there should *not* be
24477 : an ellipsis at the end. */
24478 :
24479 : /* In the case where we are describing a mere function declaration, all we
24480 : need to do here (and all we *can* do here) is to describe the *types* of
24481 : its formal parameters. */
24482 98985223 : if (debug_info_level <= DINFO_LEVEL_TERSE)
24483 : ;
24484 98958232 : else if (declaration)
24485 96285876 : gen_formal_types_die (decl, subr_die);
24486 : else
24487 : {
24488 : /* Generate DIEs to represent all known formal parameters. */
24489 2672356 : tree parm = DECL_ARGUMENTS (decl);
24490 2672356 : tree generic_decl = early_dwarf
24491 2672356 : ? lang_hooks.decls.get_generic_function_decl (decl) : NULL;
24492 2124707 : tree generic_decl_parm = generic_decl
24493 2124707 : ? DECL_ARGUMENTS (generic_decl)
24494 469537 : : NULL;
24495 :
24496 : /* Now we want to walk the list of parameters of the function and
24497 : emit their relevant DIEs.
24498 :
24499 : We consider the case of DECL being an instance of a generic function
24500 : as well as it being a normal function.
24501 :
24502 : If DECL is an instance of a generic function we walk the
24503 : parameters of the generic function declaration _and_ the parameters of
24504 : DECL itself. This is useful because we want to emit specific DIEs for
24505 : function parameter packs and those are declared as part of the
24506 : generic function declaration. In that particular case,
24507 : the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
24508 : That DIE has children DIEs representing the set of arguments
24509 : of the pack. Note that the set of pack arguments can be empty.
24510 : In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
24511 : children DIE.
24512 :
24513 : Otherwise, we just consider the parameters of DECL. */
24514 7641598 : while (generic_decl_parm || parm)
24515 : {
24516 : if (generic_decl_parm
24517 1088250 : && lang_hooks.function_parameter_pack_p (generic_decl_parm))
24518 82864 : gen_formal_parameter_pack_die (generic_decl_parm,
24519 : parm, subr_die,
24520 : &parm);
24521 4886378 : else if (parm)
24522 : {
24523 4886378 : dw_die_ref parm_die = gen_decl_die (parm, NULL, NULL, subr_die);
24524 :
24525 4886378 : if (early_dwarf
24526 3868528 : && parm == DECL_ARGUMENTS (decl)
24527 2012095 : && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
24528 1263246 : && parm_die
24529 6149624 : && (dwarf_version >= 3 || !dwarf_strict))
24530 1263246 : add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
24531 :
24532 4886378 : parm = DECL_CHAIN (parm);
24533 : }
24534 :
24535 4969242 : if (generic_decl_parm)
24536 1088250 : generic_decl_parm = DECL_CHAIN (generic_decl_parm);
24537 : }
24538 :
24539 : /* Decide whether we need an unspecified_parameters DIE at the end.
24540 : There are 2 more cases to do this for: 1) the ansi ... declaration -
24541 : this is detectable when the end of the arg list is not a
24542 : void_type_node 2) an unprototyped function declaration (not a
24543 : definition). This just means that we have no info about the
24544 : parameters at all. */
24545 2672356 : if (early_dwarf)
24546 : {
24547 2124707 : if (prototype_p (TREE_TYPE (decl)))
24548 : {
24549 : /* This is the prototyped case, check for.... */
24550 2122455 : if (stdarg_p (TREE_TYPE (decl)))
24551 4325 : gen_unspecified_parameters_die (decl, subr_die);
24552 : }
24553 2252 : else if (DECL_INITIAL (decl) == NULL_TREE)
24554 0 : gen_unspecified_parameters_die (decl, subr_die);
24555 : }
24556 547649 : else if ((subr_die != old_die || old_die_had_no_children)
24557 78400 : && prototype_p (TREE_TYPE (decl))
24558 625742 : && stdarg_p (TREE_TYPE (decl)))
24559 196 : gen_unspecified_parameters_die (decl, subr_die);
24560 : }
24561 :
24562 98985223 : if (subr_die != old_die)
24563 : /* Add the calling convention attribute if requested. */
24564 98454626 : add_calling_convention_attribute (subr_die, decl);
24565 :
24566 : /* Output Dwarf info for all of the stuff within the body of the function
24567 : (if it has one - it may be just a declaration).
24568 :
24569 : OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
24570 : a function. This BLOCK actually represents the outermost binding contour
24571 : for the function, i.e. the contour in which the function's formal
24572 : parameters and labels get declared. Curiously, it appears that the front
24573 : end doesn't actually put the PARM_DECL nodes for the current function onto
24574 : the BLOCK_VARS list for this outer scope, but are strung off of the
24575 : DECL_ARGUMENTS list for the function instead.
24576 :
24577 : The BLOCK_VARS list for the `outer_scope' does provide us with a list of
24578 : the LABEL_DECL nodes for the function however, and we output DWARF info
24579 : for those in decls_for_scope. Just within the `outer_scope' there will be
24580 : a BLOCK node representing the function's outermost pair of curly braces,
24581 : and any blocks used for the base and member initializers of a C++
24582 : constructor function. */
24583 98985223 : tree outer_scope = DECL_INITIAL (decl);
24584 98985223 : if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
24585 : {
24586 2680057 : int call_site_note_count = 0;
24587 2680057 : int tail_call_site_note_count = 0;
24588 :
24589 : /* Emit a DW_TAG_variable DIE for a named return value. */
24590 2680057 : if (DECL_NAME (DECL_RESULT (decl)))
24591 9463 : gen_decl_die (DECL_RESULT (decl), NULL, NULL, subr_die);
24592 :
24593 : /* The first time through decls_for_scope we will generate the
24594 : DIEs for the locals. The second time, we fill in the
24595 : location info. */
24596 2680057 : decls_for_scope (outer_scope, subr_die);
24597 :
24598 2680057 : if (call_arg_locations && (!dwarf_strict || dwarf_version >= 5))
24599 : {
24600 : struct call_arg_loc_node *ca_loc;
24601 3630457 : for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
24602 : {
24603 3185417 : dw_die_ref die = NULL;
24604 3185417 : rtx tloc = NULL_RTX, tlocc = NULL_RTX;
24605 3185417 : rtx call_arg_loc_note
24606 3185417 : = find_reg_note (ca_loc->call_insn,
24607 : REG_CALL_ARG_LOCATION, NULL_RTX);
24608 3185417 : rtx arg, next_arg;
24609 3185417 : tree arg_decl = NULL_TREE;
24610 :
24611 3149654 : for (arg = (call_arg_loc_note != NULL_RTX
24612 3185417 : ? XEXP (call_arg_loc_note, 0)
24613 : : NULL_RTX);
24614 6209918 : arg; arg = next_arg)
24615 : {
24616 3024501 : dw_loc_descr_ref reg, val;
24617 3024501 : machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
24618 3024501 : dw_die_ref cdie, tdie = NULL;
24619 :
24620 3024501 : next_arg = XEXP (arg, 1);
24621 3024501 : if (REG_P (XEXP (XEXP (arg, 0), 0))
24622 2967485 : && next_arg
24623 1314455 : && MEM_P (XEXP (XEXP (next_arg, 0), 0))
24624 6765 : && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
24625 3031235 : && REGNO (XEXP (XEXP (arg, 0), 0))
24626 6734 : == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
24627 6186 : next_arg = XEXP (next_arg, 1);
24628 3024501 : if (mode == VOIDmode)
24629 : {
24630 543640 : mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
24631 543640 : if (mode == VOIDmode)
24632 1032 : mode = GET_MODE (XEXP (arg, 0));
24633 : }
24634 3024501 : if (mode == VOIDmode || mode == BLKmode)
24635 0 : continue;
24636 : /* Get dynamic information about call target only if we
24637 : have no static information: we cannot generate both
24638 : DW_AT_call_origin and DW_AT_call_target
24639 : attributes. */
24640 3024501 : if (ca_loc->symbol_ref == NULL_RTX)
24641 : {
24642 123916 : if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
24643 : {
24644 5086 : tloc = XEXP (XEXP (arg, 0), 1);
24645 5086 : continue;
24646 : }
24647 118830 : else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
24648 0 : && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
24649 : {
24650 0 : tlocc = XEXP (XEXP (arg, 0), 1);
24651 0 : continue;
24652 : }
24653 : }
24654 3019415 : reg = NULL;
24655 3019415 : if (REG_P (XEXP (XEXP (arg, 0), 0)))
24656 2967485 : reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
24657 : VAR_INIT_STATUS_INITIALIZED);
24658 51930 : else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
24659 : {
24660 1949 : rtx mem = XEXP (XEXP (arg, 0), 0);
24661 1949 : reg = mem_loc_descriptor (XEXP (mem, 0),
24662 1949 : get_address_mode (mem),
24663 1949 : GET_MODE (mem),
24664 : VAR_INIT_STATUS_INITIALIZED);
24665 : }
24666 49981 : else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
24667 : == DEBUG_PARAMETER_REF)
24668 : {
24669 49981 : tree tdecl
24670 : = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
24671 49981 : tdie = lookup_decl_die (tdecl);
24672 49981 : if (tdie == NULL)
24673 0 : continue;
24674 : arg_decl = tdecl;
24675 : }
24676 : else
24677 0 : continue;
24678 2969434 : if (reg == NULL
24679 49981 : && GET_CODE (XEXP (XEXP (arg, 0), 0))
24680 : != DEBUG_PARAMETER_REF)
24681 0 : continue;
24682 3019415 : val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
24683 : VOIDmode,
24684 : VAR_INIT_STATUS_INITIALIZED);
24685 3019415 : if (val == NULL)
24686 75795 : continue;
24687 2943620 : if (die == NULL)
24688 1671951 : die = gen_call_site_die (decl, subr_die, ca_loc);
24689 2945111 : cdie = new_die (dwarf_TAG (DW_TAG_call_site_parameter), die,
24690 : NULL_TREE);
24691 2943620 : add_desc_attribute (cdie, arg_decl);
24692 2943620 : if (reg != NULL)
24693 2911330 : add_AT_loc (cdie, DW_AT_location, reg);
24694 32290 : else if (tdie != NULL)
24695 32296 : add_AT_die_ref (cdie, dwarf_AT (DW_AT_call_parameter),
24696 : tdie);
24697 2945111 : add_AT_loc (cdie, dwarf_AT (DW_AT_call_value), val);
24698 2943620 : if (next_arg != XEXP (arg, 1))
24699 : {
24700 6186 : mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
24701 6186 : if (mode == VOIDmode)
24702 5214 : mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
24703 6186 : val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
24704 : 0), 1),
24705 : mode, VOIDmode,
24706 : VAR_INIT_STATUS_INITIALIZED);
24707 6186 : if (val != NULL)
24708 6186 : add_AT_loc (cdie, dwarf_AT (DW_AT_call_data_value),
24709 : val);
24710 : }
24711 : }
24712 3185417 : if (die == NULL
24713 1513466 : && (ca_loc->symbol_ref || tloc))
24714 1186587 : die = gen_call_site_die (decl, subr_die, ca_loc);
24715 3185417 : if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
24716 : {
24717 5086 : dw_loc_descr_ref tval = NULL;
24718 :
24719 5086 : if (tloc != NULL_RTX)
24720 5086 : tval = mem_loc_descriptor (tloc,
24721 5086 : GET_MODE (tloc) == VOIDmode
24722 1032 : ? Pmode : GET_MODE (tloc),
24723 : VOIDmode,
24724 : VAR_INIT_STATUS_INITIALIZED);
24725 5086 : if (tval)
24726 5094 : add_AT_loc (die, dwarf_AT (DW_AT_call_target), tval);
24727 4 : else if (tlocc != NULL_RTX)
24728 : {
24729 0 : tval = mem_loc_descriptor (tlocc,
24730 0 : GET_MODE (tlocc) == VOIDmode
24731 0 : ? Pmode : GET_MODE (tlocc),
24732 : VOIDmode,
24733 : VAR_INIT_STATUS_INITIALIZED);
24734 0 : if (tval)
24735 0 : add_AT_loc (die,
24736 : dwarf_AT (DW_AT_call_target_clobbered),
24737 : tval);
24738 : }
24739 : }
24740 2858538 : if (die != NULL)
24741 : {
24742 2858538 : call_site_note_count++;
24743 2858538 : if (ca_loc->tail_call_p)
24744 56349 : tail_call_site_note_count++;
24745 : }
24746 : }
24747 : }
24748 2680057 : call_arg_locations = NULL;
24749 2680057 : call_arg_loc_last = NULL;
24750 2680057 : if (tail_call_site_count >= 0
24751 560785 : && tail_call_site_count == tail_call_site_note_count
24752 557305 : && (!dwarf_strict || dwarf_version >= 5))
24753 : {
24754 557289 : if (call_site_count >= 0
24755 557289 : && call_site_count == call_site_note_count)
24756 260570 : add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_calls), 1);
24757 : else
24758 300027 : add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_tail_calls), 1);
24759 : }
24760 2680057 : call_site_count = -1;
24761 2680057 : tail_call_site_count = -1;
24762 : }
24763 :
24764 : /* Mark used types after we have created DIEs for the functions scopes. */
24765 98985223 : premark_used_types (DECL_STRUCT_FUNCTION (decl));
24766 : }
24767 :
24768 : /* Returns a hash value for X (which really is a die_struct). */
24769 :
24770 : hashval_t
24771 2996 : block_die_hasher::hash (die_struct *d)
24772 : {
24773 2996 : return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
24774 : }
24775 :
24776 : /* Return true if decl_id and die_parent of die_struct X is the same
24777 : as decl_id and die_parent of die_struct Y. */
24778 :
24779 : bool
24780 2335 : block_die_hasher::equal (die_struct *x, die_struct *y)
24781 : {
24782 2335 : return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
24783 : }
24784 :
24785 : /* Hold information about markers for inlined entry points. */
24786 : struct GTY ((for_user)) inline_entry_data
24787 : {
24788 : /* The block that's the inlined_function_outer_scope for an inlined
24789 : function. */
24790 : tree block;
24791 :
24792 : /* The label at the inlined entry point. */
24793 : const char *label_pfx;
24794 : unsigned int label_num;
24795 :
24796 : /* The view number to be used as the inlined entry point. */
24797 : var_loc_view view;
24798 : };
24799 :
24800 : struct inline_entry_data_hasher : ggc_ptr_hash <inline_entry_data>
24801 : {
24802 : typedef tree compare_type;
24803 : static inline hashval_t hash (const inline_entry_data *);
24804 : static inline bool equal (const inline_entry_data *, const_tree);
24805 : };
24806 :
24807 : /* Hash table routines for inline_entry_data. */
24808 :
24809 : inline hashval_t
24810 36768424 : inline_entry_data_hasher::hash (const inline_entry_data *data)
24811 : {
24812 36768424 : return htab_hash_pointer (data->block);
24813 : }
24814 :
24815 : inline bool
24816 44624580 : inline_entry_data_hasher::equal (const inline_entry_data *data,
24817 : const_tree block)
24818 : {
24819 44624580 : return data->block == block;
24820 : }
24821 :
24822 : /* Inlined entry points pending DIE creation in this compilation unit. */
24823 :
24824 : static GTY(()) hash_table<inline_entry_data_hasher> *inline_entry_data_table;
24825 :
24826 :
24827 : /* Return TRUE if DECL, which may have been previously generated as
24828 : OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
24829 : true if decl (or its origin) is either an extern declaration or a
24830 : class/namespace scoped declaration.
24831 :
24832 : The declare_in_namespace support causes us to get two DIEs for one
24833 : variable, both of which are declarations. We want to avoid
24834 : considering one to be a specification, so we must test for
24835 : DECLARATION and DW_AT_declaration. */
24836 : static inline bool
24837 94537047 : decl_will_get_specification_p (dw_die_ref old_die, tree decl, bool declaration)
24838 : {
24839 61347244 : return (old_die && TREE_STATIC (decl) && !declaration
24840 154663835 : && get_AT_flag (old_die, DW_AT_declaration) == 1);
24841 : }
24842 :
24843 : /* Return true if DECL is a local static. */
24844 :
24845 : static inline bool
24846 32771594 : local_function_static (tree decl)
24847 : {
24848 32771594 : gcc_assert (VAR_P (decl));
24849 32771594 : return TREE_STATIC (decl)
24850 32170507 : && DECL_CONTEXT (decl)
24851 64741989 : && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
24852 : }
24853 :
24854 : /* Return true iff DECL overrides (presumably completes) the type of
24855 : OLD_DIE within CONTEXT_DIE. */
24856 :
24857 : static bool
24858 29163120 : override_type_for_decl_p (tree decl, dw_die_ref old_die,
24859 : dw_die_ref context_die)
24860 : {
24861 29163120 : tree type = TREE_TYPE (decl);
24862 29163120 : int cv_quals;
24863 :
24864 29163120 : if (decl_by_reference_p (decl))
24865 : {
24866 0 : type = TREE_TYPE (type);
24867 0 : cv_quals = TYPE_UNQUALIFIED;
24868 : }
24869 : else
24870 29163120 : cv_quals = decl_quals (decl);
24871 :
24872 29163120 : dw_die_ref type_die
24873 87489360 : = modified_type_die (type,
24874 29163120 : cv_quals | TYPE_QUALS (type),
24875 29163120 : TYPE_ATTRIBUTES (type),
24876 : false,
24877 : context_die);
24878 :
24879 29163120 : dw_die_ref old_type_die = get_AT_ref (old_die, DW_AT_type);
24880 :
24881 29163120 : return type_die != old_type_die;
24882 : }
24883 :
24884 : /* Generate a DIE to represent a declared data object.
24885 : Either DECL or ORIGIN must be non-null. */
24886 :
24887 : static void
24888 67067865 : gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
24889 : {
24890 67067865 : HOST_WIDE_INT off = 0;
24891 67067865 : tree com_decl;
24892 67067865 : tree decl_or_origin = decl ? decl : origin;
24893 67067850 : tree ultimate_origin;
24894 67067850 : dw_die_ref var_die;
24895 67067850 : dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
24896 67067865 : bool declaration = (DECL_EXTERNAL (decl_or_origin)
24897 67067865 : || class_or_namespace_scope_p (context_die));
24898 67067865 : bool specialization_p = false;
24899 67067865 : bool no_linkage_name = false;
24900 :
24901 : /* While C++ inline static data members have definitions inside of the
24902 : class, force the first DIE to be a declaration, then let gen_member_die
24903 : reparent it to the class context and call gen_variable_die again
24904 : to create the outside of the class DIE for the definition. */
24905 67067865 : if (!declaration
24906 67067865 : && old_die == NULL
24907 11170594 : && decl
24908 11170594 : && DECL_CONTEXT (decl)
24909 10973237 : && TYPE_P (DECL_CONTEXT (decl))
24910 74829270 : && lang_hooks.decls.decl_dwarf_attribute (decl, DW_AT_inline) != -1)
24911 : {
24912 7761402 : declaration = true;
24913 7761402 : if (dwarf_version < 5)
24914 14 : no_linkage_name = true;
24915 : }
24916 :
24917 67067865 : ultimate_origin = decl_ultimate_origin (decl_or_origin);
24918 67067865 : if (decl || ultimate_origin)
24919 67067850 : origin = ultimate_origin;
24920 67067865 : com_decl = fortran_common (decl_or_origin, &off);
24921 :
24922 : /* Symbol in common gets emitted as a child of the common block, in the form
24923 : of a data member. */
24924 67067865 : if (com_decl)
24925 : {
24926 1061 : dw_die_ref com_die;
24927 1061 : dw_loc_list_ref loc = NULL;
24928 1061 : die_node com_die_arg;
24929 :
24930 1061 : var_die = lookup_decl_die (decl_or_origin);
24931 1061 : if (var_die)
24932 : {
24933 357 : if (! early_dwarf && get_AT (var_die, DW_AT_location) == NULL)
24934 : {
24935 418 : loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
24936 349 : if (loc)
24937 : {
24938 349 : if (off)
24939 : {
24940 : /* Optimize the common case. */
24941 280 : if (single_element_loc_list_p (loc)
24942 280 : && loc->expr->dw_loc_opc == DW_OP_addr
24943 280 : && loc->expr->dw_loc_next == NULL
24944 560 : && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
24945 : == SYMBOL_REF)
24946 : {
24947 280 : rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
24948 280 : loc->expr->dw_loc_oprnd1.v.val_addr
24949 280 : = plus_constant (GET_MODE (x), x , off);
24950 : }
24951 : else
24952 0 : loc_list_plus_const (loc, off);
24953 : }
24954 349 : add_AT_location_description (var_die, DW_AT_location, loc);
24955 349 : remove_AT (var_die, DW_AT_declaration);
24956 : }
24957 : }
24958 357 : return;
24959 : }
24960 :
24961 704 : if (common_block_die_table == NULL)
24962 99 : common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
24963 :
24964 704 : com_die_arg.decl_id = DECL_UID (com_decl);
24965 704 : com_die_arg.die_parent = context_die;
24966 704 : com_die = common_block_die_table->find (&com_die_arg);
24967 704 : if (! early_dwarf)
24968 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24969 704 : if (com_die == NULL)
24970 : {
24971 247 : const char *cnam
24972 247 : = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
24973 247 : die_node **slot;
24974 :
24975 247 : com_die = new_die (DW_TAG_common_block, context_die, decl);
24976 247 : add_name_and_src_coords_attributes (com_die, com_decl);
24977 247 : if (loc)
24978 : {
24979 0 : add_AT_location_description (com_die, DW_AT_location, loc);
24980 : /* Avoid sharing the same loc descriptor between
24981 : DW_TAG_common_block and DW_TAG_variable. */
24982 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24983 : }
24984 247 : else if (DECL_EXTERNAL (decl_or_origin))
24985 7 : add_AT_flag (com_die, DW_AT_declaration, 1);
24986 247 : if (want_pubnames ())
24987 0 : add_pubname_string (cnam, com_die); /* ??? needed? */
24988 247 : com_die->decl_id = DECL_UID (com_decl);
24989 247 : slot = common_block_die_table->find_slot (com_die, INSERT);
24990 247 : *slot = com_die;
24991 : }
24992 457 : else if (get_AT (com_die, DW_AT_location) == NULL && loc)
24993 : {
24994 0 : add_AT_location_description (com_die, DW_AT_location, loc);
24995 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24996 0 : remove_AT (com_die, DW_AT_declaration);
24997 : }
24998 704 : var_die = new_die (DW_TAG_variable, com_die, decl);
24999 704 : add_name_and_src_coords_attributes (var_die, decl_or_origin);
25000 704 : add_type_attribute (var_die, TREE_TYPE (decl_or_origin),
25001 : decl_quals (decl_or_origin), false,
25002 : context_die);
25003 704 : add_alignment_attribute (var_die, decl);
25004 704 : add_AT_flag (var_die, DW_AT_external, 1);
25005 704 : if (loc)
25006 : {
25007 0 : if (off)
25008 : {
25009 : /* Optimize the common case. */
25010 0 : if (single_element_loc_list_p (loc)
25011 0 : && loc->expr->dw_loc_opc == DW_OP_addr
25012 0 : && loc->expr->dw_loc_next == NULL
25013 0 : && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
25014 : {
25015 0 : rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
25016 0 : loc->expr->dw_loc_oprnd1.v.val_addr
25017 0 : = plus_constant (GET_MODE (x), x, off);
25018 : }
25019 : else
25020 0 : loc_list_plus_const (loc, off);
25021 : }
25022 0 : add_AT_location_description (var_die, DW_AT_location, loc);
25023 : }
25024 704 : else if (DECL_EXTERNAL (decl_or_origin))
25025 8 : add_AT_flag (var_die, DW_AT_declaration, 1);
25026 704 : if (decl)
25027 704 : equate_decl_number_to_die (decl, var_die);
25028 704 : return;
25029 : }
25030 :
25031 67066804 : if (old_die)
25032 : {
25033 32490773 : if (declaration)
25034 : {
25035 : /* A declaration that has been previously dumped, needs no
25036 : further annotations, since it doesn't need location on
25037 : the second pass. */
25038 : return;
25039 : }
25040 32184124 : else if (decl_will_get_specification_p (old_die, decl, declaration)
25041 32184124 : && !get_AT (old_die, DW_AT_specification))
25042 : {
25043 : /* Fall-thru so we can make a new variable die along with a
25044 : DW_AT_specification. */
25045 : }
25046 3021004 : else if (origin && old_die->die_parent != context_die)
25047 : {
25048 : /* If we will be creating an inlined instance, we need a
25049 : new DIE that will get annotated with
25050 : DW_AT_abstract_origin. */
25051 59152 : gcc_assert (!DECL_ABSTRACT_P (decl));
25052 : }
25053 : else
25054 : {
25055 : /* If a DIE was dumped early, it still needs location info.
25056 : Skip to where we fill the location bits. */
25057 2961852 : var_die = old_die;
25058 :
25059 : /* ??? In LTRANS we cannot annotate early created variably
25060 : modified type DIEs without copying them and adjusting all
25061 : references to them. Thus we dumped them again. Also add a
25062 : reference to them but beware of -g0 compile and -g link
25063 : in which case the reference will be already present. */
25064 2961852 : tree type = TREE_TYPE (decl_or_origin);
25065 2961852 : if (in_lto_p
25066 2896 : && ! get_AT (var_die, DW_AT_type)
25067 2964748 : && variably_modified_type_p
25068 2896 : (type, decl_function_context (decl_or_origin)))
25069 : {
25070 45 : if (decl_by_reference_p (decl_or_origin))
25071 4 : add_type_attribute (var_die, TREE_TYPE (type),
25072 : TYPE_UNQUALIFIED, false, context_die);
25073 : else
25074 41 : add_type_attribute (var_die, type, decl_quals (decl_or_origin),
25075 : false, context_die);
25076 : }
25077 :
25078 2961852 : goto gen_variable_die_location;
25079 : }
25080 : }
25081 :
25082 : /* For static data members, the declaration in the class is supposed
25083 : to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
25084 : also in DWARF2; the specification should still be DW_TAG_variable
25085 : referencing the DW_TAG_member DIE. */
25086 63798303 : if (declaration && class_scope_p (context_die) && dwarf_version < 5)
25087 120 : var_die = new_die (DW_TAG_member, context_die, decl);
25088 : else
25089 63798183 : var_die = new_die (DW_TAG_variable, context_die, decl);
25090 :
25091 63798303 : if (origin != NULL)
25092 1445380 : add_abstract_origin_attribute (var_die, origin);
25093 :
25094 : /* Loop unrolling can create multiple blocks that refer to the same
25095 : static variable, so we must test for the DW_AT_declaration flag.
25096 :
25097 : ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
25098 : copy decls and set the DECL_ABSTRACT_P flag on them instead of
25099 : sharing them.
25100 :
25101 : ??? Duplicated blocks have been rewritten to use .debug_ranges. */
25102 62352923 : else if (decl_will_get_specification_p (old_die, decl, declaration))
25103 : {
25104 : /* This is a definition of a C++ class level static. */
25105 29163120 : add_AT_specification (var_die, old_die);
25106 29163120 : specialization_p = true;
25107 29163120 : if (DECL_NAME (decl))
25108 : {
25109 29163101 : expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
25110 29163101 : struct dwarf_file_data * file_index = lookup_filename (s.file);
25111 :
25112 29163101 : if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
25113 4639 : add_AT_file (var_die, DW_AT_decl_file, file_index);
25114 :
25115 29163101 : if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
25116 133384 : add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
25117 :
25118 29163101 : if (debug_column_info
25119 29163101 : && s.column
25120 58326202 : && (get_AT_unsigned (old_die, DW_AT_decl_column)
25121 29163101 : != (unsigned) s.column))
25122 133322 : add_AT_unsigned (var_die, DW_AT_decl_column, s.column);
25123 :
25124 29163101 : if (old_die->die_tag == DW_TAG_member)
25125 70 : add_linkage_name (var_die, decl);
25126 : }
25127 : }
25128 : else
25129 33189803 : add_name_and_src_coords_attributes (var_die, decl, no_linkage_name);
25130 :
25131 63798303 : if ((origin == NULL && !specialization_p)
25132 30608500 : || (origin != NULL
25133 1445380 : && !DECL_ABSTRACT_P (decl_or_origin)
25134 1445380 : && variably_modified_type_p (TREE_TYPE (decl_or_origin),
25135 : decl_function_context
25136 : (decl_or_origin)))
25137 94403791 : || (old_die && specialization_p
25138 29163120 : && override_type_for_decl_p (decl_or_origin, old_die, context_die)))
25139 : {
25140 33193065 : tree type = TREE_TYPE (decl_or_origin);
25141 :
25142 33193065 : if (decl_by_reference_p (decl_or_origin))
25143 1513 : add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
25144 : context_die);
25145 : else
25146 33191552 : add_type_attribute (var_die, type, decl_quals (decl_or_origin), false,
25147 : context_die);
25148 : }
25149 :
25150 63798303 : if (origin == NULL && !specialization_p)
25151 : {
25152 33189803 : if (TREE_PUBLIC (decl))
25153 31292721 : add_AT_flag (var_die, DW_AT_external, 1);
25154 :
25155 33189803 : if (DECL_ARTIFICIAL (decl))
25156 136014 : add_AT_flag (var_die, DW_AT_artificial, 1);
25157 :
25158 33189803 : add_alignment_attribute (var_die, decl);
25159 :
25160 33189803 : add_accessibility_attribute (var_die, decl);
25161 : }
25162 :
25163 63798303 : if (declaration)
25164 31167535 : add_AT_flag (var_die, DW_AT_declaration, 1);
25165 :
25166 63798303 : if (decl && (DECL_ABSTRACT_P (decl)
25167 63798288 : || !old_die || is_declaration_die (old_die)))
25168 63739136 : equate_decl_number_to_die (decl, var_die);
25169 :
25170 66760155 : gen_variable_die_location:
25171 66760155 : if (! declaration
25172 66760155 : && (! DECL_ABSTRACT_P (decl_or_origin)
25173 : /* Local static vars are shared between all clones/inlines,
25174 : so emit DW_AT_location on the abstract DIE if DECL_RTL is
25175 : already set. */
25176 0 : || (VAR_P (decl_or_origin)
25177 0 : && TREE_STATIC (decl_or_origin)
25178 0 : && DECL_RTL_SET_P (decl_or_origin))))
25179 : {
25180 35592620 : if (early_dwarf)
25181 : {
25182 32973707 : add_pubname (decl_or_origin, var_die);
25183 : /* For global register variables, emit DW_AT_location if possible
25184 : already during early_dwarf, as late_global_decl won't be usually
25185 : called. */
25186 32973707 : if (DECL_HARD_REGISTER (decl_or_origin)
25187 76 : && TREE_STATIC (decl_or_origin)
25188 12 : && !decl_by_reference_p (decl_or_origin)
25189 12 : && !get_AT (var_die, DW_AT_location)
25190 6 : && !get_AT (var_die, DW_AT_const_value)
25191 6 : && DECL_RTL_SET_P (decl_or_origin)
25192 32973713 : && REG_P (DECL_RTL (decl_or_origin)))
25193 : {
25194 6 : dw_loc_descr_ref descr
25195 6 : = reg_loc_descriptor (DECL_RTL (decl_or_origin),
25196 : VAR_INIT_STATUS_INITIALIZED);
25197 6 : if (descr)
25198 6 : add_AT_loc (var_die, DW_AT_location, descr);
25199 : }
25200 : }
25201 : else
25202 2618913 : add_location_or_const_value_attribute (var_die, decl_or_origin,
25203 : decl == NULL);
25204 : }
25205 : else
25206 31167535 : tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
25207 :
25208 9095 : if ((dwarf_version >= 4 || !dwarf_strict)
25209 66760155 : && lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
25210 : DW_AT_const_expr) == 1
25211 58883247 : && !get_AT (var_die, DW_AT_const_expr)
25212 95512870 : && !specialization_p)
25213 28633926 : add_AT_flag (var_die, DW_AT_const_expr, 1);
25214 :
25215 66760155 : if (!dwarf_strict)
25216 : {
25217 66760153 : int inl = lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
25218 : DW_AT_inline);
25219 66760153 : if (inl != -1
25220 56943974 : && !get_AT (var_die, DW_AT_inline)
25221 94540894 : && !specialization_p)
25222 27652877 : add_AT_unsigned (var_die, DW_AT_inline, inl);
25223 : }
25224 : }
25225 :
25226 : /* Generate a DIE to represent a named constant. */
25227 :
25228 : static void
25229 26050 : gen_const_die (tree decl, dw_die_ref context_die)
25230 : {
25231 26050 : dw_die_ref const_die;
25232 26050 : tree type = TREE_TYPE (decl);
25233 :
25234 26050 : const_die = lookup_decl_die (decl);
25235 26050 : if (const_die)
25236 : return;
25237 :
25238 19101 : const_die = new_die (DW_TAG_constant, context_die, decl);
25239 19101 : equate_decl_number_to_die (decl, const_die);
25240 19101 : add_name_and_src_coords_attributes (const_die, decl);
25241 19101 : add_type_attribute (const_die, type, TYPE_QUAL_CONST, false, context_die);
25242 19101 : if (TREE_PUBLIC (decl))
25243 357 : add_AT_flag (const_die, DW_AT_external, 1);
25244 19101 : if (DECL_ARTIFICIAL (decl))
25245 0 : add_AT_flag (const_die, DW_AT_artificial, 1);
25246 19101 : tree_add_const_value_attribute_for_decl (const_die, decl);
25247 : }
25248 :
25249 : /* Generate a DIE to represent a label identifier. */
25250 :
25251 : static void
25252 100242 : gen_label_die (tree decl, dw_die_ref context_die)
25253 : {
25254 100242 : tree origin = decl_ultimate_origin (decl);
25255 100242 : dw_die_ref lbl_die = lookup_decl_die (decl);
25256 100242 : rtx insn;
25257 100242 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
25258 :
25259 100242 : if (!lbl_die)
25260 : {
25261 60870 : lbl_die = new_die (DW_TAG_label, context_die, decl);
25262 60870 : equate_decl_number_to_die (decl, lbl_die);
25263 :
25264 60870 : if (origin != NULL)
25265 15559 : add_abstract_origin_attribute (lbl_die, origin);
25266 : else
25267 45311 : add_name_and_src_coords_attributes (lbl_die, decl);
25268 : }
25269 :
25270 100242 : if (DECL_ABSTRACT_P (decl))
25271 0 : equate_decl_number_to_die (decl, lbl_die);
25272 100242 : else if (! early_dwarf)
25273 : {
25274 54931 : insn = DECL_RTL_IF_SET (decl);
25275 :
25276 : /* Deleted labels are programmer specified labels which have been
25277 : eliminated because of various optimizations. We still emit them
25278 : here so that it is possible to put breakpoints on them. */
25279 45497 : if (insn
25280 45497 : && (LABEL_P (insn)
25281 25603 : || ((NOTE_P (insn)
25282 25603 : && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
25283 : {
25284 : /* When optimization is enabled (via -O) some parts of the compiler
25285 : (e.g. jump.cc and cse.cc) may try to delete CODE_LABEL insns which
25286 : represent source-level labels which were explicitly declared by
25287 : the user. This really shouldn't be happening though, so catch
25288 : it if it ever does happen. */
25289 38705 : gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
25290 :
25291 38705 : ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
25292 38705 : add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
25293 38705 : }
25294 : else if (insn
25295 6792 : && NOTE_P (insn)
25296 6792 : && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
25297 6792 : && CODE_LABEL_NUMBER (insn) != -1)
25298 : {
25299 6792 : ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
25300 6792 : add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
25301 : }
25302 : }
25303 100242 : }
25304 :
25305 : /* A helper function for gen_inlined_subroutine_die. Add source coordinate
25306 : attributes to the DIE for a block STMT, to describe where the inlined
25307 : function was called from. This is similar to add_src_coords_attributes. */
25308 :
25309 : static inline void
25310 6498243 : add_call_src_coords_attributes (tree stmt, dw_die_ref die)
25311 : {
25312 : /* We can end up with BUILTINS_LOCATION here. */
25313 6498243 : if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt)))
25314 61 : return;
25315 :
25316 6498182 : location_t locus = BLOCK_SOURCE_LOCATION (stmt);
25317 6498182 : expanded_location s = expand_location (locus);
25318 :
25319 6498182 : if (dwarf_version >= 3 || !dwarf_strict)
25320 : {
25321 6498182 : add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
25322 6498182 : add_AT_unsigned (die, DW_AT_call_line, s.line);
25323 6498182 : if (debug_column_info && s.column)
25324 6490126 : add_AT_unsigned (die, DW_AT_call_column, s.column);
25325 6498182 : unsigned discr = get_discriminator_from_loc (locus);
25326 6498182 : if (discr != 0)
25327 2036775 : add_AT_unsigned (die, DW_AT_GNU_discriminator, discr);
25328 : }
25329 : }
25330 :
25331 :
25332 : /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
25333 : Add low_pc and high_pc attributes to the DIE for a block STMT. */
25334 :
25335 : static inline void
25336 7070207 : add_high_low_attributes (tree stmt, dw_die_ref die)
25337 : {
25338 7070207 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
25339 :
25340 6664195 : if (inline_entry_data **iedp
25341 7070207 : = !inline_entry_data_table ? NULL
25342 6664195 : : inline_entry_data_table->find_slot_with_hash (stmt,
25343 : htab_hash_pointer (stmt),
25344 : NO_INSERT))
25345 : {
25346 6271336 : inline_entry_data *ied = *iedp;
25347 6271336 : gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS);
25348 6271336 : gcc_assert (debug_inline_points);
25349 6271336 : gcc_assert (inlined_function_outer_scope_p (stmt));
25350 :
25351 6271336 : ASM_GENERATE_INTERNAL_LABEL (label, ied->label_pfx, ied->label_num);
25352 6271336 : add_AT_lbl_id (die, DW_AT_entry_pc, label);
25353 :
25354 6271336 : if (debug_variable_location_views && !ZERO_VIEW_P (ied->view)
25355 12542425 : && !dwarf_strict)
25356 : {
25357 6271089 : if (!output_asm_line_debug_info ())
25358 434 : add_AT_unsigned (die, DW_AT_GNU_entry_view, ied->view);
25359 : else
25360 : {
25361 6270655 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", ied->view);
25362 : /* FIXME: this will resolve to a small number. Could we
25363 : possibly emit smaller data? Ideally we'd emit a
25364 : uleb128, but that would make the size of DIEs
25365 : impossible for the compiler to compute, since it's
25366 : the assembler that computes the value of the view
25367 : label in this case. Ideally, we'd have a single form
25368 : encompassing both the address and the view, and
25369 : indirecting them through a table might make things
25370 : easier, but even that would be more wasteful,
25371 : space-wise, than what we have now. */
25372 6270655 : add_AT_symview (die, DW_AT_GNU_entry_view, label);
25373 : }
25374 : }
25375 :
25376 6271336 : inline_entry_data_table->clear_slot (iedp);
25377 : }
25378 :
25379 7070207 : if (BLOCK_FRAGMENT_CHAIN (stmt)
25380 7070207 : && (dwarf_version >= 3 || !dwarf_strict))
25381 : {
25382 3182169 : tree chain, superblock = NULL_TREE;
25383 3182169 : dw_die_ref pdie;
25384 3182169 : dw_attr_node *attr = NULL;
25385 :
25386 3182169 : if (!debug_inline_points && inlined_function_outer_scope_p (stmt))
25387 : {
25388 106 : ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
25389 : BLOCK_NUMBER (stmt));
25390 106 : add_AT_lbl_id (die, DW_AT_entry_pc, label);
25391 : }
25392 :
25393 : /* Optimize duplicate .debug_ranges lists or even tails of
25394 : lists. If this BLOCK has same ranges as its supercontext,
25395 : lookup DW_AT_ranges attribute in the supercontext (and
25396 : recursively so), verify that the ranges_table contains the
25397 : right values and use it instead of adding a new .debug_range. */
25398 1936879 : for (chain = stmt, pdie = die;
25399 5119048 : BLOCK_SAME_RANGE (chain);
25400 1936879 : chain = BLOCK_SUPERCONTEXT (chain))
25401 : {
25402 2027126 : dw_attr_node *new_attr;
25403 :
25404 2027126 : pdie = pdie->die_parent;
25405 2027126 : if (pdie == NULL)
25406 : break;
25407 2027126 : if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
25408 : break;
25409 2027126 : new_attr = get_AT (pdie, DW_AT_ranges);
25410 2027126 : if (new_attr == NULL
25411 1936879 : || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
25412 : break;
25413 1936879 : attr = new_attr;
25414 1936879 : superblock = BLOCK_SUPERCONTEXT (chain);
25415 : }
25416 3182169 : if (attr != NULL
25417 917078 : && ((*ranges_table)[attr->dw_attr_val.v.val_offset].num
25418 917078 : == (int)BLOCK_NUMBER (superblock))
25419 3723405 : && BLOCK_FRAGMENT_CHAIN (superblock))
25420 : {
25421 : unsigned long off = attr->dw_attr_val.v.val_offset;
25422 1568488 : unsigned long supercnt = 0, thiscnt = 0;
25423 1027252 : for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
25424 1568488 : chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
25425 : {
25426 1027252 : ++supercnt;
25427 1027252 : gcc_checking_assert ((*ranges_table)[off + supercnt].num
25428 : == (int)BLOCK_NUMBER (chain));
25429 : }
25430 541236 : gcc_checking_assert ((*ranges_table)[off + supercnt + 1].num == 0);
25431 541236 : for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
25432 1548855 : chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
25433 1007619 : ++thiscnt;
25434 541236 : gcc_assert (supercnt >= thiscnt);
25435 541236 : add_AT_range_list (die, DW_AT_ranges, off + supercnt - thiscnt,
25436 : false);
25437 541236 : note_rnglist_head (off + supercnt - thiscnt);
25438 541236 : return;
25439 : }
25440 :
25441 2640933 : unsigned int offset = add_ranges (stmt, true);
25442 2640933 : add_AT_range_list (die, DW_AT_ranges, offset, false);
25443 2640933 : note_rnglist_head (offset);
25444 :
25445 2640933 : bool prev_in_cold = BLOCK_IN_COLD_SECTION_P (stmt);
25446 2640933 : chain = BLOCK_FRAGMENT_CHAIN (stmt);
25447 5256855 : do
25448 : {
25449 5256855 : add_ranges (chain, prev_in_cold != BLOCK_IN_COLD_SECTION_P (chain));
25450 5256855 : prev_in_cold = BLOCK_IN_COLD_SECTION_P (chain);
25451 5256855 : chain = BLOCK_FRAGMENT_CHAIN (chain);
25452 : }
25453 5256855 : while (chain);
25454 2640933 : add_ranges (NULL);
25455 : }
25456 : else
25457 : {
25458 3888038 : char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
25459 3888038 : ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
25460 : BLOCK_NUMBER (stmt));
25461 3888038 : ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
25462 : BLOCK_NUMBER (stmt));
25463 3888038 : add_AT_low_high_pc (die, label, label_high, false);
25464 : }
25465 : }
25466 :
25467 : /* Generate a DIE for a lexical block. */
25468 :
25469 : static void
25470 1008260 : gen_lexical_block_die (tree stmt, dw_die_ref context_die)
25471 : {
25472 1008260 : dw_die_ref old_die = lookup_block_die (stmt);
25473 1008260 : dw_die_ref stmt_die = NULL;
25474 1008260 : if (!old_die)
25475 : {
25476 747282 : stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
25477 747282 : equate_block_to_die (stmt, stmt_die);
25478 : }
25479 :
25480 1008260 : if (BLOCK_ABSTRACT_ORIGIN (stmt))
25481 : {
25482 : /* If this is an inlined or concrete instance, create a new lexical
25483 : die for anything below to attach DW_AT_abstract_origin to. */
25484 338249 : if (old_die)
25485 10418 : stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
25486 :
25487 338249 : tree origin = block_ultimate_origin (stmt);
25488 338249 : if (origin != NULL_TREE && (origin != stmt || old_die))
25489 337521 : add_abstract_origin_attribute (stmt_die, origin);
25490 :
25491 : old_die = NULL;
25492 : }
25493 :
25494 670011 : if (old_die)
25495 250560 : stmt_die = old_die;
25496 :
25497 : /* A non abstract block whose blocks have already been reordered
25498 : should have the instruction range for this block. If so, set the
25499 : high/low attributes. */
25500 1008260 : if (!early_dwarf && TREE_ASM_WRITTEN (stmt))
25501 : {
25502 571964 : gcc_assert (stmt_die);
25503 571964 : add_high_low_attributes (stmt, stmt_die);
25504 : }
25505 :
25506 1008260 : decls_for_scope (stmt, stmt_die);
25507 1008260 : }
25508 :
25509 : /* Generate a DIE for an inlined subprogram. */
25510 :
25511 : static void
25512 6498243 : gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
25513 : {
25514 6498243 : tree decl = block_ultimate_origin (stmt);
25515 :
25516 : /* Make sure any inlined functions are known to be inlineable. */
25517 6498243 : gcc_checking_assert (DECL_ABSTRACT_P (decl)
25518 : || cgraph_function_possibly_inlined_p (decl));
25519 :
25520 6498243 : dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
25521 :
25522 6498243 : if (call_arg_locations || debug_inline_points)
25523 6490368 : equate_block_to_die (stmt, subr_die);
25524 6498243 : add_abstract_origin_attribute (subr_die, decl);
25525 6498243 : if (TREE_ASM_WRITTEN (stmt))
25526 6498243 : add_high_low_attributes (stmt, subr_die);
25527 6498243 : add_call_src_coords_attributes (stmt, subr_die);
25528 :
25529 : /* The inliner creates an extra BLOCK for the parameter setup,
25530 : we want to merge that with the actual outermost BLOCK of the
25531 : inlined function to avoid duplicate locals in consumers.
25532 : Do that by doing the recursion to subblocks on the single subblock
25533 : of STMT. */
25534 6498243 : bool unwrap_one = false;
25535 6498243 : tree sub = BLOCK_SUBBLOCKS (stmt);
25536 6498243 : if (sub)
25537 : {
25538 5148874 : tree origin = block_ultimate_origin (sub);
25539 5148874 : if (origin
25540 5148874 : && TREE_CODE (origin) == BLOCK
25541 8390999 : && BLOCK_SUPERCONTEXT (origin) == decl)
25542 : unwrap_one = true;
25543 8292030 : for (tree next = BLOCK_CHAIN (sub); unwrap_one && next;
25544 3143156 : next = BLOCK_CHAIN (next))
25545 3143156 : if (BLOCK_FRAGMENT_ORIGIN (next) != sub)
25546 5922 : unwrap_one = false;
25547 : }
25548 6498243 : decls_for_scope (stmt, subr_die, !unwrap_one);
25549 6498243 : if (unwrap_one)
25550 : {
25551 3141080 : decls_for_scope (sub, subr_die);
25552 6274624 : for (sub = BLOCK_CHAIN (sub); sub; sub = BLOCK_CHAIN (sub))
25553 3133544 : gen_block_die (sub, subr_die);
25554 : }
25555 6498243 : }
25556 :
25557 : /* Generate a DIE for a field in a record, or structure. CTX is required: see
25558 : the comment for VLR_CONTEXT. */
25559 :
25560 : static void
25561 17123881 : gen_field_die (tree decl, struct vlr_context *ctx, dw_die_ref context_die)
25562 : {
25563 17123881 : dw_die_ref decl_die;
25564 :
25565 17123881 : if (TREE_TYPE (decl) == error_mark_node)
25566 : return;
25567 :
25568 17123881 : decl_die = new_die (DW_TAG_member, context_die, decl);
25569 17123881 : add_name_and_src_coords_attributes (decl_die, decl);
25570 34247762 : add_type_attribute (decl_die, member_declared_type (decl), decl_quals (decl),
25571 17123881 : TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl)),
25572 : context_die);
25573 :
25574 17123881 : if (DECL_BIT_FIELD_TYPE (decl))
25575 : {
25576 489763 : add_byte_size_attribute (decl_die, decl);
25577 489763 : add_bit_size_attribute (decl_die, decl);
25578 489763 : add_bit_offset_attribute (decl_die, decl);
25579 : }
25580 :
25581 17123881 : add_alignment_attribute (decl_die, decl);
25582 :
25583 17123881 : if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
25584 15691120 : add_data_member_location_attribute (decl_die, decl, ctx);
25585 :
25586 17123881 : if (DECL_ARTIFICIAL (decl))
25587 70850 : add_AT_flag (decl_die, DW_AT_artificial, 1);
25588 :
25589 17123881 : add_accessibility_attribute (decl_die, decl);
25590 :
25591 : /* Add DW_AT_export_symbols to anonymous unions or structs. */
25592 17123881 : if ((dwarf_version >= 5 || !dwarf_strict) && DECL_NAME (decl) == NULL_TREE)
25593 193473 : if (tree type = member_declared_type (decl))
25594 193473 : if (lang_hooks.types.type_dwarf_attribute (TYPE_MAIN_VARIANT (type),
25595 : DW_AT_export_symbols) != -1)
25596 : {
25597 193373 : dw_die_ref type_die = lookup_type_die (TYPE_MAIN_VARIANT (type));
25598 193373 : if (type_die && get_AT (type_die, DW_AT_export_symbols) == NULL)
25599 193373 : add_AT_flag (type_die, DW_AT_export_symbols, 1);
25600 : }
25601 :
25602 : /* Equate decl number to die, so that we can look up this decl later on. */
25603 17123881 : equate_decl_number_to_die (decl, decl_die);
25604 : }
25605 :
25606 : /* Generate a DIE for a pointer to a member type. TYPE can be an
25607 : OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
25608 : pointer to member function. */
25609 :
25610 : static void
25611 29473 : gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
25612 : {
25613 29473 : if (lookup_type_die (type))
25614 : return;
25615 :
25616 29473 : dw_die_ref ptr_die = new_die (DW_TAG_ptr_to_member_type,
25617 : scope_die_for (type, context_die), type);
25618 :
25619 29473 : equate_type_number_to_die (type, ptr_die);
25620 58946 : add_AT_die_ref (ptr_die, DW_AT_containing_type,
25621 29473 : lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
25622 29473 : add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
25623 : context_die);
25624 29473 : add_alignment_attribute (ptr_die, type);
25625 :
25626 29473 : if (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
25627 29473 : && TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)
25628 : {
25629 446 : dw_loc_descr_ref op = new_loc_descr (DW_OP_plus, 0, 0);
25630 446 : add_AT_loc (ptr_die, DW_AT_use_location, op);
25631 : }
25632 : }
25633 :
25634 : static char *producer_string;
25635 :
25636 : /* Given a C and/or C++ language/version string return the "highest".
25637 : C++ is assumed to be "higher" than C in this case. Used for merging
25638 : LTO translation unit languages. */
25639 : static const char *
25640 1 : highest_c_language (const char *lang1, const char *lang2)
25641 : {
25642 1 : if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
25643 : return "GNU C++26";
25644 1 : if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
25645 : return "GNU C++23";
25646 1 : if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
25647 : return "GNU C++20";
25648 0 : if (strcmp ("GNU C++17", lang1) == 0 || strcmp ("GNU C++17", lang2) == 0)
25649 : return "GNU C++17";
25650 0 : if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
25651 : return "GNU C++14";
25652 0 : if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
25653 : return "GNU C++11";
25654 0 : if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
25655 : return "GNU C++98";
25656 :
25657 0 : if (strcmp ("GNU C2Y", lang1) == 0 || strcmp ("GNU C2Y", lang2) == 0)
25658 : return "GNU C2Y";
25659 0 : if (strcmp ("GNU C23", lang1) == 0 || strcmp ("GNU C23", lang2) == 0)
25660 : return "GNU C23";
25661 0 : if (strcmp ("GNU C17", lang1) == 0 || strcmp ("GNU C17", lang2) == 0)
25662 : return "GNU C17";
25663 0 : if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
25664 : return "GNU C11";
25665 0 : if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
25666 : return "GNU C99";
25667 0 : if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
25668 : return "GNU C89";
25669 :
25670 0 : gcc_unreachable ();
25671 : }
25672 :
25673 :
25674 : /* Generate the DIE for the compilation unit. */
25675 :
25676 : static dw_die_ref
25677 57105 : gen_compile_unit_die (const char *filename)
25678 : {
25679 57105 : dw_die_ref die;
25680 57105 : const char *language_string = lang_hooks.name;
25681 57105 : int language, lname, lversion;
25682 :
25683 57105 : die = new_die (DW_TAG_compile_unit, NULL, NULL);
25684 :
25685 57105 : if (filename)
25686 : {
25687 0 : add_filename_attribute (die, filename);
25688 : /* Don't add cwd for <built-in>. */
25689 0 : if (filename[0] != '<')
25690 0 : add_comp_dir_attribute (die);
25691 : }
25692 :
25693 57354 : add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
25694 :
25695 : /* If our producer is LTO try to figure out a common language to use
25696 : from the global list of translation units. */
25697 57105 : if (strcmp (language_string, "GNU GIMPLE") == 0)
25698 : {
25699 : unsigned i;
25700 : tree t;
25701 : const char *common_lang = NULL;
25702 :
25703 1519 : FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
25704 : {
25705 771 : if (!TRANSLATION_UNIT_LANGUAGE (t))
25706 0 : continue;
25707 771 : if (!common_lang)
25708 : common_lang = TRANSLATION_UNIT_LANGUAGE (t);
25709 23 : else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
25710 : ;
25711 1 : else if (startswith (common_lang, "GNU C")
25712 1 : && startswith (TRANSLATION_UNIT_LANGUAGE (t), "GNU C"))
25713 : /* Mixing C and C++ is ok, use C++ in that case. */
25714 1 : common_lang = highest_c_language (common_lang,
25715 1 : TRANSLATION_UNIT_LANGUAGE (t));
25716 : else
25717 : {
25718 : /* Fall back to C. */
25719 : common_lang = NULL;
25720 : break;
25721 : }
25722 : }
25723 :
25724 748 : if (common_lang)
25725 57105 : language_string = common_lang;
25726 : }
25727 :
25728 57105 : language = DW_LANG_C;
25729 57105 : lname = 0;
25730 57105 : lversion = 0;
25731 57105 : if (startswith (language_string, "GNU C")
25732 57105 : && ISDIGIT (language_string[5]))
25733 : {
25734 24245 : language = DW_LANG_C89;
25735 24245 : if (dwarf_version >= 3 || !dwarf_strict)
25736 : {
25737 24245 : if (strcmp (language_string, "GNU C89") != 0)
25738 22853 : language = DW_LANG_C99;
25739 :
25740 24245 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25741 : {
25742 23345 : if (strcmp (language_string, "GNU C11") == 0)
25743 : language = DW_LANG_C11;
25744 19649 : else if (strcmp (language_string, "GNU C17") == 0)
25745 : {
25746 : language = DW_LANG_C11;
25747 : lname = DW_LNAME_C;
25748 : lversion = 201710;
25749 : }
25750 19539 : else if (strcmp (language_string, "GNU C23") == 0)
25751 : {
25752 : language = DW_LANG_C11;
25753 : lname = DW_LNAME_C;
25754 : lversion = 202311;
25755 : }
25756 1472 : else if (strcmp (language_string, "GNU C2Y") == 0)
25757 : {
25758 57105 : language = DW_LANG_C11;
25759 57105 : lname = DW_LNAME_C;
25760 57105 : lversion = 202500;
25761 : }
25762 : }
25763 : }
25764 : }
25765 32860 : else if (startswith (language_string, "GNU C++"))
25766 : {
25767 18398 : language = DW_LANG_C_plus_plus;
25768 18398 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25769 : {
25770 17229 : if (strcmp (language_string, "GNU C++11") == 0)
25771 : language = DW_LANG_C_plus_plus_11;
25772 16802 : else if (strcmp (language_string, "GNU C++14") == 0)
25773 : language = DW_LANG_C_plus_plus_14;
25774 16784 : else if (strcmp (language_string, "GNU C++17") == 0)
25775 : {
25776 : language = DW_LANG_C_plus_plus_14;
25777 : lname = DW_LNAME_C_plus_plus;
25778 : lversion = 201703;
25779 : }
25780 16006 : else if (strcmp (language_string, "GNU C++20") == 0)
25781 : {
25782 : language = DW_LANG_C_plus_plus_14;
25783 : lname = DW_LNAME_C_plus_plus;
25784 : lversion = 202002;
25785 : }
25786 1501 : else if (strcmp (language_string, "GNU C++23") == 0)
25787 : {
25788 : language = DW_LANG_C_plus_plus_14;
25789 : lname = DW_LNAME_C_plus_plus;
25790 : lversion = 202302;
25791 : }
25792 1189 : else if (strcmp (language_string, "GNU C++26") == 0)
25793 : {
25794 57105 : language = DW_LANG_C_plus_plus_14;
25795 57105 : lname = DW_LNAME_C_plus_plus;
25796 57105 : lversion = 202400;
25797 : }
25798 : }
25799 : }
25800 14462 : else if (strcmp (language_string, "GNU F77") == 0)
25801 : language = DW_LANG_Fortran77;
25802 14462 : else if (strcmp (language_string, "GCC COBOL") == 0)
25803 : language = DW_LANG_Cobol85;
25804 14462 : else if (strcmp (language_string, "GNU Modula-2") == 0)
25805 : language = DW_LANG_Modula2;
25806 10723 : else if (dwarf_version >= 3 || !dwarf_strict)
25807 : {
25808 10723 : if (strcmp (language_string, "GNU Ada") == 0)
25809 : language = DW_LANG_Ada95;
25810 10723 : else if (startswith (language_string, "GNU Fortran"))
25811 : {
25812 5132 : language = DW_LANG_Fortran95;
25813 5132 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25814 : {
25815 5105 : if (strcmp (language_string, "GNU Fortran2003") == 0)
25816 : language = DW_LANG_Fortran03;
25817 5082 : else if (strcmp (language_string, "GNU Fortran2008") == 0)
25818 57105 : language = DW_LANG_Fortran08;
25819 : }
25820 : }
25821 5591 : else if (strcmp (language_string, "GNU Objective-C") == 0)
25822 : language = DW_LANG_ObjC;
25823 5591 : else if (strcmp (language_string, "GNU Objective-C++") == 0)
25824 : language = DW_LANG_ObjC_plus_plus;
25825 5591 : else if (strcmp (language_string, "GNU D") == 0)
25826 : language = DW_LANG_D;
25827 5591 : else if (dwarf_version >= 5 || !dwarf_strict)
25828 : {
25829 5590 : if (strcmp (language_string, "GNU Go") == 0)
25830 : language = DW_LANG_Go;
25831 1328 : else if (strcmp (language_string, "GNU Rust") == 0)
25832 : language = DW_LANG_Rust;
25833 812 : else if (strcmp (language_string, "GNU Algol 68") == 0)
25834 : {
25835 57105 : language = DW_LANG_Algol68;
25836 57105 : lname = DW_LNAME_Algol68;
25837 57105 : lversion = 1978; /* Not a typo. The revised language of the
25838 : Revised Report. */
25839 : }
25840 : }
25841 : }
25842 : /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
25843 0 : else if (startswith (language_string, "GNU Fortran"))
25844 : language = DW_LANG_Fortran90;
25845 : /* Likewise for Ada. */
25846 0 : else if (strcmp (language_string, "GNU Ada") == 0)
25847 57105 : language = DW_LANG_Ada83;
25848 :
25849 57105 : add_AT_unsigned (die, DW_AT_language, language);
25850 57105 : if (lname && dwarf_version >= 5 && !dwarf_strict)
25851 : {
25852 34553 : add_AT_unsigned (die, DW_AT_language_name, lname);
25853 34553 : add_AT_unsigned (die, DW_AT_language_version, lversion);
25854 : }
25855 :
25856 57105 : switch (language)
25857 : {
25858 5132 : case DW_LANG_Fortran77:
25859 5132 : case DW_LANG_Fortran90:
25860 5132 : case DW_LANG_Fortran95:
25861 5132 : case DW_LANG_Fortran03:
25862 5132 : case DW_LANG_Fortran08:
25863 : /* Fortran has case insensitive identifiers and the front-end
25864 : lowercases everything. */
25865 5132 : add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
25866 5132 : break;
25867 0 : case DW_LANG_Cobol85:
25868 0 : add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_case_insensitive);
25869 0 : break;
25870 : default:
25871 : /* The default DW_ID_case_sensitive doesn't need to be specified. */
25872 : break;
25873 : }
25874 57105 : return die;
25875 : }
25876 :
25877 : /* Generate the DIE for a base class. */
25878 :
25879 : static void
25880 23280750 : gen_inheritance_die (tree binfo, tree access, tree type,
25881 : dw_die_ref context_die)
25882 : {
25883 23280750 : dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
25884 23280750 : struct vlr_context ctx = { type, NULL };
25885 :
25886 23280750 : add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, false,
25887 : context_die);
25888 23280750 : add_data_member_location_attribute (die, binfo, &ctx);
25889 :
25890 23280750 : if (BINFO_VIRTUAL_P (binfo))
25891 299 : add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
25892 :
25893 : /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
25894 : children, otherwise the default is DW_ACCESS_public. In DWARF2
25895 : the default has always been DW_ACCESS_private. */
25896 23280750 : if (access == access_public_node)
25897 : {
25898 22740653 : if (dwarf_version == 2
25899 22740239 : || context_die->die_tag == DW_TAG_class_type)
25900 1079822 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
25901 : }
25902 540097 : else if (access == access_protected_node)
25903 84874 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
25904 455223 : else if (dwarf_version > 2
25905 455217 : && context_die->die_tag != DW_TAG_class_type)
25906 240309 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
25907 23280750 : }
25908 :
25909 : /* Return whether DECL is a FIELD_DECL that represents the variant part of a
25910 : structure. */
25911 :
25912 : static bool
25913 265921248 : is_variant_part (tree decl)
25914 : {
25915 265921248 : return (TREE_CODE (decl) == FIELD_DECL
25916 265921248 : && TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
25917 : }
25918 :
25919 : /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
25920 : return the FIELD_DECL. Return NULL_TREE otherwise. */
25921 :
25922 : static tree
25923 0 : analyze_discr_in_predicate (tree operand, tree struct_type)
25924 : {
25925 0 : while (CONVERT_EXPR_P (operand))
25926 0 : operand = TREE_OPERAND (operand, 0);
25927 :
25928 : /* Match field access to members of struct_type only. */
25929 0 : if (TREE_CODE (operand) == COMPONENT_REF
25930 0 : && TREE_CODE (TREE_OPERAND (operand, 0)) == PLACEHOLDER_EXPR
25931 0 : && TREE_TYPE (TREE_OPERAND (operand, 0)) == struct_type
25932 0 : && TREE_CODE (TREE_OPERAND (operand, 1)) == FIELD_DECL)
25933 0 : return TREE_OPERAND (operand, 1);
25934 : else
25935 : return NULL_TREE;
25936 : }
25937 :
25938 : /* Check that SRC is a constant integer that can be represented as a native
25939 : integer constant (either signed or unsigned). If so, store it into DEST and
25940 : return true. Return false otherwise. */
25941 :
25942 : static bool
25943 0 : get_discr_value (tree src, dw_discr_value *dest)
25944 : {
25945 0 : tree discr_type = TREE_TYPE (src);
25946 :
25947 0 : if (lang_hooks.types.get_debug_type)
25948 : {
25949 0 : tree debug_type = lang_hooks.types.get_debug_type (discr_type);
25950 0 : if (debug_type != NULL)
25951 0 : discr_type = debug_type;
25952 : }
25953 :
25954 0 : if (TREE_CODE (src) != INTEGER_CST || !INTEGRAL_TYPE_P (discr_type))
25955 : return false;
25956 :
25957 : /* Signedness can vary between the original type and the debug type. This
25958 : can happen for character types in Ada for instance: the character type
25959 : used for code generation can be signed, to be compatible with the C one,
25960 : but from a debugger point of view, it must be unsigned. */
25961 0 : bool is_orig_unsigned = TYPE_UNSIGNED (TREE_TYPE (src));
25962 0 : bool is_debug_unsigned = TYPE_UNSIGNED (discr_type);
25963 :
25964 0 : if (is_orig_unsigned != is_debug_unsigned)
25965 0 : src = fold_convert (discr_type, src);
25966 :
25967 0 : if (!(is_debug_unsigned ? tree_fits_uhwi_p (src) : tree_fits_shwi_p (src)))
25968 : return false;
25969 :
25970 0 : dest->pos = is_debug_unsigned;
25971 0 : if (is_debug_unsigned)
25972 0 : dest->v.uval = tree_to_uhwi (src);
25973 : else
25974 0 : dest->v.sval = tree_to_shwi (src);
25975 :
25976 : return true;
25977 : }
25978 :
25979 : /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
25980 : FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
25981 : store NULL_TREE in DISCR_DECL. Otherwise:
25982 :
25983 : - store the discriminant field in STRUCT_TYPE that controls the variant
25984 : part to *DISCR_DECL
25985 :
25986 : - put in *DISCR_LISTS_P an array where for each variant, the item
25987 : represents the corresponding matching list of discriminant values.
25988 :
25989 : - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
25990 : the above array.
25991 :
25992 : Note that when the array is allocated (i.e. when the analysis is
25993 : successful), it is up to the caller to free the array. */
25994 :
25995 : static void
25996 0 : analyze_variants_discr (tree variant_part_decl,
25997 : tree struct_type,
25998 : tree *discr_decl,
25999 : dw_discr_list_ref **discr_lists_p,
26000 : unsigned *discr_lists_length)
26001 : {
26002 0 : tree variant_part_type = TREE_TYPE (variant_part_decl);
26003 0 : tree variant;
26004 0 : dw_discr_list_ref *discr_lists;
26005 0 : unsigned i;
26006 :
26007 : /* Compute how many variants there are in this variant part. */
26008 0 : *discr_lists_length = 0;
26009 0 : for (variant = TYPE_FIELDS (variant_part_type);
26010 0 : variant != NULL_TREE;
26011 0 : variant = DECL_CHAIN (variant))
26012 0 : ++*discr_lists_length;
26013 :
26014 0 : *discr_decl = NULL_TREE;
26015 0 : *discr_lists_p
26016 0 : = (dw_discr_list_ref *) xcalloc (*discr_lists_length,
26017 : sizeof (**discr_lists_p));
26018 0 : discr_lists = *discr_lists_p;
26019 :
26020 : /* And then analyze all variants to extract discriminant information for all
26021 : of them. This analysis is conservative: as soon as we detect something we
26022 : do not support, abort everything and pretend we found nothing. */
26023 0 : for (variant = TYPE_FIELDS (variant_part_type), i = 0;
26024 0 : variant != NULL_TREE;
26025 0 : variant = DECL_CHAIN (variant), ++i)
26026 : {
26027 0 : tree match_expr = DECL_QUALIFIER (variant);
26028 :
26029 : /* Now, try to analyze the predicate and deduce a discriminant for
26030 : it. */
26031 0 : if (match_expr == boolean_true_node)
26032 : /* Typically happens for the default variant: it matches all cases that
26033 : previous variants rejected. Don't output any matching value for
26034 : this one. */
26035 0 : continue;
26036 :
26037 : /* The following loop tries to iterate over each discriminant
26038 : possibility: single values or ranges. */
26039 0 : while (match_expr != NULL_TREE)
26040 : {
26041 0 : tree next_round_match_expr;
26042 0 : tree candidate_discr = NULL_TREE;
26043 0 : dw_discr_list_ref new_node = NULL;
26044 :
26045 : /* Possibilities are matched one after the other by nested
26046 : TRUTH_ORIF_EXPR expressions. Process the current possibility and
26047 : continue with the rest at next iteration. */
26048 0 : if (TREE_CODE (match_expr) == TRUTH_ORIF_EXPR)
26049 : {
26050 0 : next_round_match_expr = TREE_OPERAND (match_expr, 0);
26051 0 : match_expr = TREE_OPERAND (match_expr, 1);
26052 : }
26053 : else
26054 : next_round_match_expr = NULL_TREE;
26055 :
26056 0 : if (match_expr == boolean_false_node)
26057 : /* This sub-expression matches nothing: just wait for the next
26058 : one. */
26059 : ;
26060 :
26061 0 : else if (TREE_CODE (match_expr) == EQ_EXPR)
26062 : {
26063 : /* We are matching: <discr_field> == <integer_cst>
26064 : This sub-expression matches a single value. */
26065 0 : tree integer_cst = TREE_OPERAND (match_expr, 1);
26066 :
26067 0 : candidate_discr
26068 0 : = analyze_discr_in_predicate (TREE_OPERAND (match_expr, 0),
26069 : struct_type);
26070 :
26071 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
26072 0 : if (!get_discr_value (integer_cst,
26073 : &new_node->dw_discr_lower_bound))
26074 0 : goto abort;
26075 0 : new_node->dw_discr_range = false;
26076 : }
26077 :
26078 0 : else if (TREE_CODE (match_expr) == TRUTH_ANDIF_EXPR)
26079 : {
26080 : /* We are matching:
26081 : <discr_field> > <integer_cst>
26082 : && <discr_field> < <integer_cst>.
26083 : This sub-expression matches the range of values between the
26084 : two matched integer constants. Note that comparisons can be
26085 : inclusive or exclusive. */
26086 0 : tree candidate_discr_1, candidate_discr_2;
26087 0 : tree lower_cst, upper_cst;
26088 0 : bool lower_cst_included, upper_cst_included;
26089 0 : tree lower_op = TREE_OPERAND (match_expr, 0);
26090 0 : tree upper_op = TREE_OPERAND (match_expr, 1);
26091 :
26092 : /* When the comparison is exclusive, the integer constant is not
26093 : the discriminant range bound we are looking for: we will have
26094 : to increment or decrement it. */
26095 0 : if (TREE_CODE (lower_op) == GE_EXPR)
26096 : lower_cst_included = true;
26097 0 : else if (TREE_CODE (lower_op) == GT_EXPR)
26098 : lower_cst_included = false;
26099 : else
26100 0 : goto abort;
26101 :
26102 0 : if (TREE_CODE (upper_op) == LE_EXPR)
26103 : upper_cst_included = true;
26104 0 : else if (TREE_CODE (upper_op) == LT_EXPR)
26105 : upper_cst_included = false;
26106 : else
26107 0 : goto abort;
26108 :
26109 : /* Extract the discriminant from the first operand and check it
26110 : is consistent with the same analysis in the second
26111 : operand. */
26112 0 : candidate_discr_1
26113 0 : = analyze_discr_in_predicate (TREE_OPERAND (lower_op, 0),
26114 : struct_type);
26115 0 : candidate_discr_2
26116 0 : = analyze_discr_in_predicate (TREE_OPERAND (upper_op, 0),
26117 : struct_type);
26118 0 : if (candidate_discr_1 == candidate_discr_2)
26119 0 : candidate_discr = candidate_discr_1;
26120 : else
26121 0 : goto abort;
26122 :
26123 : /* Extract bounds from both. */
26124 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
26125 0 : lower_cst = TREE_OPERAND (lower_op, 1);
26126 0 : upper_cst = TREE_OPERAND (upper_op, 1);
26127 :
26128 0 : if (!lower_cst_included)
26129 0 : lower_cst
26130 0 : = fold_build2 (PLUS_EXPR, TREE_TYPE (lower_cst), lower_cst,
26131 : build_int_cst (TREE_TYPE (lower_cst), 1));
26132 0 : if (!upper_cst_included)
26133 0 : upper_cst
26134 0 : = fold_build2 (MINUS_EXPR, TREE_TYPE (upper_cst), upper_cst,
26135 : build_int_cst (TREE_TYPE (upper_cst), 1));
26136 :
26137 0 : if (!get_discr_value (lower_cst,
26138 : &new_node->dw_discr_lower_bound)
26139 0 : || !get_discr_value (upper_cst,
26140 : &new_node->dw_discr_upper_bound))
26141 0 : goto abort;
26142 :
26143 0 : new_node->dw_discr_range = true;
26144 : }
26145 :
26146 0 : else if ((candidate_discr
26147 0 : = analyze_discr_in_predicate (match_expr, struct_type))
26148 0 : && (TREE_TYPE (candidate_discr) == boolean_type_node
26149 0 : || TREE_TYPE (TREE_TYPE (candidate_discr))
26150 : == boolean_type_node))
26151 : {
26152 : /* We are matching: <discr_field> for a boolean discriminant.
26153 : This sub-expression matches boolean_true_node. */
26154 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
26155 0 : if (!get_discr_value (boolean_true_node,
26156 : &new_node->dw_discr_lower_bound))
26157 0 : goto abort;
26158 0 : new_node->dw_discr_range = false;
26159 : }
26160 :
26161 : else
26162 : /* Unsupported sub-expression: we cannot determine the set of
26163 : matching discriminant values. Abort everything. */
26164 0 : goto abort;
26165 :
26166 : /* If the discriminant info is not consistent with what we saw so
26167 : far, consider the analysis failed and abort everything. */
26168 0 : if (candidate_discr == NULL_TREE
26169 0 : || (*discr_decl != NULL_TREE && candidate_discr != *discr_decl))
26170 0 : goto abort;
26171 : else
26172 0 : *discr_decl = candidate_discr;
26173 :
26174 0 : if (new_node != NULL)
26175 : {
26176 0 : new_node->dw_discr_next = discr_lists[i];
26177 0 : discr_lists[i] = new_node;
26178 : }
26179 0 : match_expr = next_round_match_expr;
26180 : }
26181 : }
26182 :
26183 : /* If we reach this point, we could match everything we were interested
26184 : in. */
26185 : return;
26186 :
26187 0 : abort:
26188 : /* Clean all data structure and return no result. */
26189 0 : free (*discr_lists_p);
26190 0 : *discr_lists_p = NULL;
26191 0 : *discr_decl = NULL_TREE;
26192 : }
26193 :
26194 : /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
26195 : of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
26196 : under CONTEXT_DIE.
26197 :
26198 : Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
26199 : QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
26200 : this type, which are record types, represent the available variants and each
26201 : has a DECL_QUALIFIER attribute. The discriminant and the discriminant
26202 : values are inferred from these attributes.
26203 :
26204 : In trees, the offsets for the fields inside these sub-records are relative
26205 : to the variant part itself, whereas the corresponding DIEs should have
26206 : offset attributes that are relative to the embedding record base address.
26207 : This is why the caller must provide a VARIANT_PART_OFFSET expression: it
26208 : must be an expression that computes the offset of the variant part to
26209 : describe in DWARF. */
26210 :
26211 : static void
26212 0 : gen_variant_part (tree variant_part_decl, struct vlr_context *vlr_ctx,
26213 : dw_die_ref context_die)
26214 : {
26215 0 : const tree variant_part_type = TREE_TYPE (variant_part_decl);
26216 0 : tree variant_part_offset = vlr_ctx->variant_part_offset;
26217 :
26218 : /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
26219 : NULL_TREE if there is no such field. */
26220 0 : tree discr_decl = NULL_TREE;
26221 0 : dw_discr_list_ref *discr_lists;
26222 0 : unsigned discr_lists_length = 0;
26223 0 : unsigned i;
26224 :
26225 0 : dw_die_ref dwarf_proc_die = NULL;
26226 0 : dw_die_ref variant_part_die
26227 0 : = new_die (DW_TAG_variant_part, context_die, variant_part_type);
26228 :
26229 0 : equate_decl_number_to_die (variant_part_decl, variant_part_die);
26230 :
26231 0 : analyze_variants_discr (variant_part_decl, vlr_ctx->struct_type,
26232 : &discr_decl, &discr_lists, &discr_lists_length);
26233 :
26234 0 : if (discr_decl != NULL_TREE)
26235 : {
26236 0 : dw_die_ref discr_die = lookup_decl_die (discr_decl);
26237 :
26238 0 : if (discr_die)
26239 0 : add_AT_die_ref (variant_part_die, DW_AT_discr, discr_die);
26240 : else
26241 : /* We have no DIE for the discriminant, so just discard all
26242 : discrimimant information in the output. */
26243 0 : discr_decl = NULL_TREE;
26244 : }
26245 :
26246 : /* If the offset for this variant part is more complex than a constant,
26247 : create a DWARF procedure for it so that we will not have to generate
26248 : DWARF expressions for it for each member. */
26249 0 : if (TREE_CODE (variant_part_offset) != INTEGER_CST
26250 0 : && (dwarf_version >= 3 || !dwarf_strict))
26251 : {
26252 0 : struct loc_descr_context ctx = {
26253 0 : vlr_ctx->struct_type, /* context_type */
26254 : NULL_TREE, /* base_decl */
26255 : NULL, /* dpi */
26256 : false, /* placeholder_arg */
26257 : false, /* placeholder_seen */
26258 : false /* strict_signedness */
26259 0 : };
26260 0 : const tree dwarf_proc_fndecl
26261 0 : = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
26262 0 : build_function_type (TREE_TYPE (variant_part_offset),
26263 : NULL_TREE));
26264 0 : const tree dwarf_proc_call = build_call_expr (dwarf_proc_fndecl, 0);
26265 0 : const dw_loc_descr_ref dwarf_proc_body
26266 0 : = loc_descriptor_from_tree (variant_part_offset, 0, &ctx);
26267 :
26268 0 : dwarf_proc_die = new_dwarf_proc_die (dwarf_proc_body,
26269 : dwarf_proc_fndecl, context_die);
26270 0 : if (dwarf_proc_die != NULL)
26271 0 : variant_part_offset = dwarf_proc_call;
26272 : }
26273 :
26274 : /* Output DIEs for all variants. */
26275 0 : i = 0;
26276 0 : for (tree variant = TYPE_FIELDS (variant_part_type);
26277 0 : variant != NULL_TREE;
26278 0 : variant = DECL_CHAIN (variant), ++i)
26279 : {
26280 0 : tree variant_type = TREE_TYPE (variant);
26281 0 : dw_die_ref variant_die;
26282 :
26283 : /* All variants (i.e. members of a variant part) are supposed to be
26284 : encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
26285 : under these records. */
26286 0 : gcc_assert (TREE_CODE (variant_type) == RECORD_TYPE);
26287 :
26288 0 : variant_die = new_die (DW_TAG_variant, variant_part_die, variant_type);
26289 0 : equate_decl_number_to_die (variant, variant_die);
26290 :
26291 : /* Output discriminant values this variant matches, if any. */
26292 0 : if (discr_decl == NULL || discr_lists[i] == NULL)
26293 : /* In the case we have discriminant information at all, this is
26294 : probably the default variant: as the standard says, don't
26295 : output any discriminant value/list attribute. */
26296 : ;
26297 0 : else if (discr_lists[i]->dw_discr_next == NULL
26298 0 : && !discr_lists[i]->dw_discr_range)
26299 : /* If there is only one accepted value, don't bother outputting a
26300 : list. */
26301 0 : add_discr_value (variant_die, &discr_lists[i]->dw_discr_lower_bound);
26302 : else
26303 0 : add_discr_list (variant_die, discr_lists[i]);
26304 :
26305 0 : for (tree member = TYPE_FIELDS (variant_type);
26306 0 : member != NULL_TREE;
26307 0 : member = DECL_CHAIN (member))
26308 : {
26309 0 : struct vlr_context vlr_sub_ctx = {
26310 0 : vlr_ctx->struct_type, /* struct_type */
26311 : NULL /* variant_part_offset */
26312 0 : };
26313 0 : if (is_variant_part (member))
26314 : {
26315 : /* All offsets for fields inside variant parts are relative to
26316 : the top-level embedding RECORD_TYPE's base address. On the
26317 : other hand, offsets in GCC's types are relative to the
26318 : nested-most variant part. So we have to sum offsets each time
26319 : we recurse. */
26320 :
26321 0 : vlr_sub_ctx.variant_part_offset
26322 0 : = fold_build2 (PLUS_EXPR, TREE_TYPE (variant_part_offset),
26323 : variant_part_offset, byte_position (member));
26324 0 : gen_variant_part (member, &vlr_sub_ctx, variant_die);
26325 : }
26326 : else
26327 : {
26328 0 : vlr_sub_ctx.variant_part_offset = variant_part_offset;
26329 0 : gen_decl_die (member, NULL, &vlr_sub_ctx, variant_die);
26330 : }
26331 : }
26332 : }
26333 :
26334 0 : free (discr_lists);
26335 0 : }
26336 :
26337 : /* Generate a DIE for a class member. */
26338 :
26339 : static void
26340 50739504 : gen_member_die (tree type, dw_die_ref context_die)
26341 : {
26342 50739504 : tree member;
26343 50739504 : tree binfo = TYPE_BINFO (type);
26344 :
26345 50739504 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
26346 :
26347 : /* If this is not an incomplete type, output descriptions of each of its
26348 : members. Note that as we output the DIEs necessary to represent the
26349 : members of this record or union type, we will also be trying to output
26350 : DIEs to represent the *types* of those members. However the `type'
26351 : function (above) will specifically avoid generating type DIEs for member
26352 : types *within* the list of member DIEs for this (containing) type except
26353 : for those types (of members) which are explicitly marked as also being
26354 : members of this (containing) type themselves. The g++ front- end can
26355 : force any given type to be treated as a member of some other (containing)
26356 : type by setting the TYPE_CONTEXT of the given (member) type to point to
26357 : the TREE node representing the appropriate (containing) type. */
26358 :
26359 : /* First output info about the base classes. */
26360 50739504 : if (binfo && early_dwarf)
26361 : {
26362 50040671 : vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
26363 50040671 : int i;
26364 50040671 : tree base;
26365 :
26366 73321421 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
26367 46561500 : gen_inheritance_die (base,
26368 23280750 : (accesses ? (*accesses)[i] : access_public_node),
26369 : type,
26370 : context_die);
26371 : }
26372 :
26373 : /* Now output info about the members. */
26374 381297854 : for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
26375 : {
26376 : /* Ignore clones. */
26377 330558350 : if (DECL_ABSTRACT_ORIGIN (member))
26378 55769147 : continue;
26379 :
26380 274789203 : struct vlr_context vlr_ctx = { type, NULL_TREE };
26381 274789203 : bool static_inline_p
26382 274789203 : = (VAR_P (member)
26383 11634386 : && TREE_STATIC (member)
26384 286423589 : && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
26385 274789203 : != -1));
26386 :
26387 : /* If we thought we were generating minimal debug info for TYPE
26388 : and then changed our minds, some of the member declarations
26389 : may have already been defined. Don't define them again, but
26390 : do put them in the right order. */
26391 :
26392 274789203 : if (dw_die_ref child = lookup_decl_die (member))
26393 : {
26394 : /* Handle inline static data members, which only have in-class
26395 : declarations. */
26396 8867955 : bool splice = true;
26397 :
26398 8867955 : dw_die_ref ref = NULL;
26399 8867955 : if (child->die_tag == DW_TAG_variable
26400 8867955 : && child->die_parent == comp_unit_die ())
26401 : {
26402 7617317 : ref = get_AT_ref (child, DW_AT_specification);
26403 :
26404 : /* For C++17 inline static data members followed by redundant
26405 : out of class redeclaration, we might get here with
26406 : child being the DIE created for the out of class
26407 : redeclaration and with its DW_AT_specification being
26408 : the DIE created for in-class definition. We want to
26409 : reparent the latter, and don't want to create another
26410 : DIE with DW_AT_specification in that case, because
26411 : we already have one. */
26412 7617317 : if (ref
26413 7617317 : && static_inline_p
26414 6 : && ref->die_tag == DW_TAG_variable
26415 6 : && ref->die_parent == comp_unit_die ()
26416 7617323 : && get_AT (ref, DW_AT_specification) == NULL)
26417 : {
26418 : child = ref;
26419 : ref = NULL;
26420 : static_inline_p = false;
26421 : }
26422 :
26423 7617311 : if (!ref)
26424 : {
26425 7616696 : reparent_child (child, context_die);
26426 7616696 : if (dwarf_version < 5)
26427 14 : child->die_tag = DW_TAG_member;
26428 : splice = false;
26429 : }
26430 : }
26431 1250638 : else if (child->die_tag == DW_TAG_enumerator)
26432 : /* Enumerators remain under their enumeration even if
26433 : their names are introduced in the enclosing scope. */
26434 : splice = false;
26435 :
26436 : if (splice)
26437 17934 : splice_child_die (context_die, child);
26438 : }
26439 :
26440 : /* Do not generate DWARF for variant parts if we are generating the
26441 : corresponding GNAT encodings: DIEs generated for the two schemes
26442 : would conflict in our mappings. */
26443 265921248 : else if (is_variant_part (member)
26444 265921248 : && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL)
26445 : {
26446 0 : vlr_ctx.variant_part_offset = byte_position (member);
26447 0 : gen_variant_part (member, &vlr_ctx, context_die);
26448 : }
26449 : else
26450 : {
26451 265921248 : vlr_ctx.variant_part_offset = NULL_TREE;
26452 265921248 : gen_decl_die (member, NULL, &vlr_ctx, context_die);
26453 : }
26454 :
26455 : /* For C++ inline static data members emit immediately a DW_TAG_variable
26456 : DIE that will refer to that DW_TAG_member/DW_TAG_variable through
26457 : DW_AT_specification. */
26458 274789203 : if (static_inline_p)
26459 : {
26460 9911262 : int old_extern = DECL_EXTERNAL (member);
26461 9911262 : DECL_EXTERNAL (member) = 0;
26462 9911262 : gen_decl_die (member, NULL, NULL, comp_unit_die ());
26463 9911262 : DECL_EXTERNAL (member) = old_extern;
26464 : }
26465 : }
26466 50739504 : }
26467 :
26468 : /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
26469 : is set, we pretend that the type was never defined, so we only get the
26470 : member DIEs needed by later specification DIEs. */
26471 :
26472 : static void
26473 135727203 : gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
26474 : enum debug_info_usage usage)
26475 : {
26476 135727203 : if (TREE_ASM_WRITTEN (type))
26477 : {
26478 : /* Fill in the bound of variable-length fields in late dwarf if
26479 : still incomplete. */
26480 180 : if (!early_dwarf && variably_modified_type_p (type, NULL))
26481 84 : for (tree member = TYPE_FIELDS (type);
26482 203 : member;
26483 119 : member = DECL_CHAIN (member))
26484 119 : fill_variable_array_bounds (TREE_TYPE (member));
26485 180 : return;
26486 : }
26487 :
26488 135727023 : dw_die_ref type_die = lookup_type_die (type);
26489 135727023 : dw_die_ref scope_die = 0;
26490 135727023 : bool nested = false;
26491 135727023 : bool complete = (TYPE_SIZE (type)
26492 135727023 : && (! TYPE_STUB_DECL (type)
26493 99639756 : || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
26494 135727023 : bool ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
26495 135727023 : complete = complete && should_emit_struct_debug (type, usage);
26496 :
26497 135727023 : if (type_die && ! complete)
26498 : return;
26499 :
26500 104484831 : if (TYPE_CONTEXT (type) != NULL_TREE
26501 104484831 : && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
26502 100457604 : || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
26503 : nested = true;
26504 :
26505 104484831 : scope_die = scope_die_for (type, context_die);
26506 :
26507 : /* Generate child dies for template parameters. */
26508 104484831 : if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
26509 54074896 : schedule_generic_params_dies_gen (type);
26510 :
26511 50409932 : if (! type_die || (nested && is_cu_die (scope_die)))
26512 : /* First occurrence of type or toplevel definition of nested class. */
26513 : {
26514 54074899 : dw_die_ref old_die = type_die;
26515 :
26516 107688201 : type_die = new_die (TREE_CODE (type) == RECORD_TYPE
26517 53613302 : ? record_type_tag (type) : DW_TAG_union_type,
26518 : scope_die, type);
26519 54074899 : equate_type_number_to_die (type, type_die);
26520 54074899 : if (old_die)
26521 0 : add_AT_specification (type_die, old_die);
26522 : else
26523 54074899 : add_name_attribute (type_die, type_tag (type));
26524 : }
26525 : else
26526 50409932 : remove_AT (type_die, DW_AT_declaration);
26527 :
26528 : /* If this type has been completed, then give it a byte_size attribute and
26529 : then give a list of members. */
26530 104484831 : if (complete && !ns_decl)
26531 : {
26532 : /* Prevent infinite recursion in cases where the type of some member of
26533 : this type is expressed in terms of this type itself. */
26534 50739504 : TREE_ASM_WRITTEN (type) = 1;
26535 50739504 : add_byte_size_attribute (type_die, type);
26536 50739504 : add_alignment_attribute (type_die, type);
26537 50739504 : if (TYPE_STUB_DECL (type) != NULL_TREE)
26538 : {
26539 50534784 : add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
26540 50534784 : add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
26541 : }
26542 :
26543 : /* If the first reference to this type was as the return type of an
26544 : inline function, then it may not have a parent. Fix this now. */
26545 50739504 : if (type_die->die_parent == NULL)
26546 283855 : add_child_die (scope_die, type_die);
26547 :
26548 50739504 : gen_member_die (type, type_die);
26549 :
26550 50739504 : add_gnat_descriptive_type_attribute (type_die, type, context_die);
26551 50739504 : if (TYPE_ARTIFICIAL (type))
26552 1458 : add_AT_flag (type_die, DW_AT_artificial, 1);
26553 :
26554 : /* GNU extension: Record what type our vtable lives in. */
26555 50739504 : if (TYPE_VFIELD (type))
26556 : {
26557 397471 : tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
26558 :
26559 397471 : gen_type_die (vtype, context_die);
26560 397471 : add_AT_die_ref (type_die, DW_AT_containing_type,
26561 : lookup_type_die (vtype));
26562 : }
26563 : }
26564 : else
26565 : {
26566 53745327 : add_AT_flag (type_die, DW_AT_declaration, 1);
26567 :
26568 : /* We don't need to do this for function-local types. */
26569 53745327 : if (TYPE_STUB_DECL (type)
26570 53745327 : && ! decl_function_context (TYPE_STUB_DECL (type)))
26571 53744573 : vec_safe_push (incomplete_types, type);
26572 : }
26573 :
26574 104484831 : if (get_AT (type_die, DW_AT_name))
26575 102964211 : add_pubtype (type, type_die);
26576 : }
26577 :
26578 : /* Generate a DIE for a subroutine _type_. */
26579 :
26580 : static void
26581 406032 : gen_subroutine_type_die (tree type, dw_die_ref context_die)
26582 : {
26583 406032 : tree return_type = TREE_TYPE (type);
26584 406032 : dw_die_ref subr_die
26585 406032 : = new_die (DW_TAG_subroutine_type,
26586 : scope_die_for (type, context_die), type);
26587 :
26588 406032 : equate_type_number_to_die (type, subr_die);
26589 406032 : add_prototyped_attribute (subr_die, type);
26590 406032 : add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, false,
26591 : context_die);
26592 406032 : add_alignment_attribute (subr_die, type);
26593 406032 : gen_formal_types_die (type, subr_die);
26594 :
26595 406032 : if (get_AT (subr_die, DW_AT_name))
26596 0 : add_pubtype (type, subr_die);
26597 775 : if ((dwarf_version >= 5 || !dwarf_strict)
26598 406801 : && lang_hooks.types.type_dwarf_attribute (type, DW_AT_reference) != -1)
26599 90 : add_AT_flag (subr_die, DW_AT_reference, 1);
26600 775 : if ((dwarf_version >= 5 || !dwarf_strict)
26601 406801 : && lang_hooks.types.type_dwarf_attribute (type,
26602 : DW_AT_rvalue_reference) != -1)
26603 38 : add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
26604 406032 : }
26605 :
26606 : /* Generate a DIE for a type definition. */
26607 :
26608 : static void
26609 62286970 : gen_typedef_die (tree decl, dw_die_ref context_die)
26610 : {
26611 62286970 : dw_die_ref type_die;
26612 62286970 : tree type;
26613 :
26614 62286970 : if (TREE_ASM_WRITTEN (decl))
26615 : {
26616 10047518 : if (DECL_ORIGINAL_TYPE (decl))
26617 9910515 : fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl));
26618 10047518 : return;
26619 : }
26620 :
26621 : /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
26622 : checks in process_scope_var and modified_type_die), this should be called
26623 : only for original types. */
26624 52239452 : gcc_assert (decl_ultimate_origin (decl) == NULL
26625 : || decl_ultimate_origin (decl) == decl);
26626 :
26627 52239452 : TREE_ASM_WRITTEN (decl) = 1;
26628 52239452 : type_die = new_die (DW_TAG_typedef, context_die, decl);
26629 :
26630 52239452 : add_name_and_src_coords_attributes (type_die, decl);
26631 52239452 : if (DECL_ORIGINAL_TYPE (decl))
26632 : {
26633 51927875 : type = DECL_ORIGINAL_TYPE (decl);
26634 51927875 : if (type == error_mark_node)
26635 : return;
26636 :
26637 51927875 : gcc_assert (type != TREE_TYPE (decl));
26638 51927875 : equate_type_number_to_die (TREE_TYPE (decl), type_die);
26639 : }
26640 : else
26641 : {
26642 311577 : type = TREE_TYPE (decl);
26643 311577 : if (type == error_mark_node)
26644 : return;
26645 :
26646 311577 : if (is_naming_typedef_decl (TYPE_NAME (type)))
26647 : {
26648 : /* Here, we are in the case of decl being a typedef naming
26649 : an anonymous type, e.g:
26650 : typedef struct {...} foo;
26651 : In that case TREE_TYPE (decl) is not a typedef variant
26652 : type and TYPE_NAME of the anonymous type is set to the
26653 : TYPE_DECL of the typedef. This construct is emitted by
26654 : the C++ FE.
26655 :
26656 : TYPE is the anonymous struct named by the typedef
26657 : DECL. As we need the DW_AT_type attribute of the
26658 : DW_TAG_typedef to point to the DIE of TYPE, let's
26659 : generate that DIE right away. add_type_attribute
26660 : called below will then pick (via lookup_type_die) that
26661 : anonymous struct DIE. */
26662 311088 : if (!TREE_ASM_WRITTEN (type))
26663 65 : gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
26664 :
26665 : /* This is a GNU Extension. We are adding a
26666 : DW_AT_linkage_name attribute to the DIE of the
26667 : anonymous struct TYPE. The value of that attribute
26668 : is the name of the typedef decl naming the anonymous
26669 : struct. This greatly eases the work of consumers of
26670 : this debug info. */
26671 311088 : add_linkage_name_raw (lookup_type_die (type), decl);
26672 : }
26673 : }
26674 :
26675 52239452 : add_type_attribute (type_die, type, decl_quals (decl), false,
26676 : context_die);
26677 :
26678 52239452 : if (is_naming_typedef_decl (decl))
26679 : /* We want that all subsequent calls to lookup_type_die with
26680 : TYPE in argument yield the DW_TAG_typedef we have just
26681 : created. */
26682 311088 : equate_type_number_to_die (type, type_die);
26683 :
26684 52239452 : add_alignment_attribute (type_die, TREE_TYPE (decl));
26685 :
26686 52239452 : add_accessibility_attribute (type_die, decl);
26687 :
26688 52239452 : if (DECL_ABSTRACT_P (decl))
26689 5800 : equate_decl_number_to_die (decl, type_die);
26690 :
26691 52239452 : if (get_AT (type_die, DW_AT_name))
26692 52239418 : add_pubtype (decl, type_die);
26693 : }
26694 :
26695 : /* Generate a DIE for a struct, class, enum or union type. */
26696 :
26697 : static void
26698 138084147 : gen_tagged_type_die (tree type,
26699 : dw_die_ref context_die,
26700 : enum debug_info_usage usage,
26701 : bool reverse)
26702 : {
26703 138084147 : if (type == NULL_TREE
26704 138084147 : || !is_tagged_type (type))
26705 : return;
26706 :
26707 138084147 : if (TREE_ASM_WRITTEN (type))
26708 : ;
26709 : /* If this is a nested type whose containing class hasn't been written
26710 : out yet, writing it out will cover this one, too. This does not apply
26711 : to instantiations of member class templates; they need to be added to
26712 : the containing class as they are generated. FIXME: This hurts the
26713 : idea of combining type decls from multiple TUs, since we can't predict
26714 : what set of template instantiations we'll get. */
26715 138083965 : else if (TYPE_CONTEXT (type)
26716 137198888 : && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
26717 143500138 : && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
26718 : {
26719 2439579 : gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
26720 :
26721 2439579 : if (TREE_ASM_WRITTEN (type))
26722 : return;
26723 :
26724 : /* If that failed, attach ourselves to the stub. */
26725 2439579 : context_die = lookup_type_die (TYPE_CONTEXT (type));
26726 : }
26727 135644386 : else if (TYPE_CONTEXT (type) != NULL_TREE
26728 135644386 : && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
26729 : {
26730 : /* If this type is local to a function that hasn't been written
26731 : out yet, use a NULL context for now; it will be fixed up in
26732 : decls_for_scope. */
26733 307531 : context_die = lookup_decl_die (TYPE_CONTEXT (type));
26734 : /* A declaration DIE doesn't count; nested types need to go in the
26735 : specification. */
26736 307531 : if (context_die && is_declaration_die (context_die))
26737 : context_die = NULL;
26738 : }
26739 : else
26740 135336855 : context_die = declare_in_namespace (type, context_die);
26741 :
26742 138084147 : if (TREE_CODE (type) == ENUMERAL_TYPE)
26743 : {
26744 : /* This might have been written out by the call to
26745 : declare_in_namespace. */
26746 2356944 : if (!TREE_ASM_WRITTEN (type) || reverse)
26747 1855618 : gen_enumeration_type_die (type, context_die, reverse);
26748 : }
26749 : else
26750 135727203 : gen_struct_or_union_type_die (type, context_die, usage);
26751 :
26752 138084147 : dw_die_ref die = lookup_type_die (type);
26753 138084147 : if (die)
26754 138084147 : maybe_gen_btf_type_tag_dies (type, die);
26755 :
26756 : /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
26757 : it up if it is ever completed. gen_*_type_die will set it for us
26758 : when appropriate. */
26759 : }
26760 :
26761 : /* Generate a type description DIE. */
26762 :
26763 : static void
26764 935813304 : gen_type_die_with_usage (tree type, dw_die_ref context_die,
26765 : enum debug_info_usage usage, bool reverse)
26766 : {
26767 935813304 : struct array_descr_info info;
26768 :
26769 935813304 : if (type == NULL_TREE || type == error_mark_node)
26770 904695771 : return;
26771 :
26772 935813304 : if (flag_checking && type)
26773 935813281 : verify_type (type);
26774 :
26775 935813304 : if (TYPE_NAME (type) != NULL_TREE
26776 782306583 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
26777 781681731 : && is_redundant_typedef (TYPE_NAME (type))
26778 1425662862 : && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
26779 : /* The DECL of this type is a typedef we don't want to emit debug
26780 : info for but we want debug info for its underlying typedef.
26781 : This can happen for e.g, the injected-class-name of a C++
26782 : type. */
26783 50076987 : type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
26784 :
26785 : /* If TYPE is a typedef type variant, let's generate debug info
26786 : for the parent typedef which TYPE is a type of. */
26787 935813304 : if (typedef_variant_p (type))
26788 : {
26789 86871692 : tree name = TYPE_NAME (type);
26790 86871692 : if (TREE_ASM_WRITTEN (name))
26791 : return;
26792 :
26793 13772128 : tree origin = decl_ultimate_origin (name);
26794 13772128 : if (origin != NULL && origin != name)
26795 : {
26796 0 : gen_decl_die (origin, NULL, NULL, context_die);
26797 0 : return;
26798 : }
26799 :
26800 : /* Prevent broken recursion; we can't hand off to the same type. */
26801 13772128 : gcc_assert (DECL_ORIGINAL_TYPE (name) != type);
26802 :
26803 : /* Give typedefs the right scope. */
26804 13772128 : context_die = scope_die_for (type, context_die);
26805 :
26806 13772128 : gen_decl_die (name, NULL, NULL, context_die);
26807 13772128 : return;
26808 : }
26809 :
26810 : /* If type is an anonymous tagged type named by a typedef, let's
26811 : generate debug info for the typedef. */
26812 848941612 : if (is_naming_typedef_decl (TYPE_NAME (type)))
26813 : {
26814 : /* Give typedefs the right scope. */
26815 137375 : context_die = scope_die_for (type, context_die);
26816 :
26817 137375 : gen_decl_die (TYPE_NAME (type), NULL, NULL, context_die);
26818 137375 : return;
26819 : }
26820 :
26821 848804237 : if (lang_hooks.types.get_debug_type)
26822 : {
26823 842638646 : tree debug_type = lang_hooks.types.get_debug_type (type);
26824 :
26825 842638646 : if (debug_type != NULL_TREE && debug_type != type)
26826 : {
26827 12854 : gen_type_die_with_usage (debug_type, context_die, usage, reverse);
26828 12854 : return;
26829 : }
26830 : }
26831 :
26832 : /* We are going to output a DIE to represent the unqualified version
26833 : of this type (i.e. without any const or volatile qualifiers) so
26834 : get the main variant (i.e. the unqualified version) of this type
26835 : now. (Vectors and arrays are special because the debugging info is in the
26836 : cloned type itself. Similarly function/method types can contain extra
26837 : ref-qualification). */
26838 848791383 : if (FUNC_OR_METHOD_TYPE_P (type))
26839 : {
26840 : /* For function/method types, can't use type_main_variant here,
26841 : because that can have different ref-qualifiers for C++,
26842 : but try to canonicalize. */
26843 458901 : tree main = TYPE_MAIN_VARIANT (type);
26844 481593 : for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
26845 481581 : if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
26846 481414 : && check_base_type (t, main)
26847 953328 : && check_lang_type (t, type))
26848 : {
26849 : type = t;
26850 : break;
26851 : }
26852 : }
26853 848332482 : else if (TREE_CODE (type) != VECTOR_TYPE
26854 848332482 : && TREE_CODE (type) != ARRAY_TYPE)
26855 846698222 : type = type_main_variant (type);
26856 :
26857 : /* If this is an array type with hidden descriptor, handle it first. */
26858 848791383 : if (!TREE_ASM_WRITTEN (type)
26859 169203728 : && lang_hooks.types.get_array_descr_info)
26860 : {
26861 88500 : memset (&info, 0, sizeof (info));
26862 88500 : if (lang_hooks.types.get_array_descr_info (type, &info))
26863 : {
26864 : /* Fortran sometimes emits array types with no dimension. */
26865 6917 : gcc_assert (info.ndimensions >= 0
26866 : && (info.ndimensions
26867 : <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN));
26868 6917 : gen_descr_array_type_die (type, &info, context_die);
26869 6917 : TREE_ASM_WRITTEN (type) = 1;
26870 6917 : return;
26871 : }
26872 : }
26873 :
26874 848784466 : if (TREE_ASM_WRITTEN (type) && !reverse)
26875 : {
26876 : /* Variable-length types may be incomplete even if
26877 : TREE_ASM_WRITTEN. For such types, fall through to
26878 : gen_array_type_die() and possibly fill in
26879 : DW_AT_{upper,lower}_bound attributes. */
26880 679587653 : if ((TREE_CODE (type) != ARRAY_TYPE
26881 : && TREE_CODE (type) != RECORD_TYPE
26882 : && TREE_CODE (type) != UNION_TYPE
26883 679587653 : && TREE_CODE (type) != QUAL_UNION_TYPE)
26884 679587653 : || !variably_modified_type_p (type, NULL))
26885 679582851 : return;
26886 : }
26887 :
26888 169201615 : switch (TREE_CODE (type))
26889 : {
26890 : case ERROR_MARK:
26891 : break;
26892 :
26893 28950071 : case POINTER_TYPE:
26894 28950071 : case REFERENCE_TYPE:
26895 : /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
26896 : ensures that the gen_type_die recursion will terminate even if the
26897 : type is recursive. Recursive types are possible in Ada. */
26898 : /* ??? We could perhaps do this for all types before the switch
26899 : statement. */
26900 28950071 : TREE_ASM_WRITTEN (type) = 1;
26901 :
26902 : /* For these types, all that is required is that we output a DIE (or a
26903 : set of DIEs) to represent the "basis" type. */
26904 28950071 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26905 : DINFO_USAGE_IND_USE);
26906 28950071 : break;
26907 :
26908 29473 : case OFFSET_TYPE:
26909 : /* This code is used for C++ pointer-to-data-member types.
26910 : Output a description of the relevant class type. */
26911 29473 : gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
26912 : DINFO_USAGE_IND_USE);
26913 :
26914 : /* Output a description of the type of the object pointed to. */
26915 29473 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26916 : DINFO_USAGE_IND_USE);
26917 :
26918 : /* Now output a DIE to represent this pointer-to-data-member type
26919 : itself. */
26920 29473 : gen_ptr_to_mbr_type_die (type, context_die);
26921 29473 : break;
26922 :
26923 377006 : case FUNCTION_TYPE:
26924 : /* Force out return type (in case it wasn't forced out already). */
26925 377006 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26926 : DINFO_USAGE_DIR_USE);
26927 377006 : gen_subroutine_type_die (type, context_die);
26928 377006 : break;
26929 :
26930 29026 : case METHOD_TYPE:
26931 : /* Force out return type (in case it wasn't forced out already). */
26932 29026 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26933 : DINFO_USAGE_DIR_USE);
26934 29026 : gen_subroutine_type_die (type, context_die);
26935 29026 : break;
26936 :
26937 1045258 : case ARRAY_TYPE:
26938 1045258 : case VECTOR_TYPE:
26939 1045258 : gen_array_type_die (type, context_die);
26940 1045258 : break;
26941 :
26942 138084082 : case ENUMERAL_TYPE:
26943 138084082 : case RECORD_TYPE:
26944 138084082 : case UNION_TYPE:
26945 138084082 : case QUAL_UNION_TYPE:
26946 138084082 : gen_tagged_type_die (type, context_die, usage, reverse);
26947 138084082 : return;
26948 :
26949 : case VOID_TYPE:
26950 : case OPAQUE_TYPE:
26951 : case INTEGER_TYPE:
26952 : case REAL_TYPE:
26953 : case FIXED_POINT_TYPE:
26954 : case COMPLEX_TYPE:
26955 : case BOOLEAN_TYPE:
26956 : case BITINT_TYPE:
26957 : /* No DIEs needed for fundamental types. */
26958 : break;
26959 :
26960 14500 : case NULLPTR_TYPE:
26961 14500 : case LANG_TYPE:
26962 14500 : unspecified_type:
26963 : /* Just use DW_TAG_unspecified_type. */
26964 14500 : {
26965 14500 : dw_die_ref type_die = lookup_type_die (type);
26966 14500 : if (type_die == NULL)
26967 : {
26968 14500 : tree name = TYPE_IDENTIFIER (type);
26969 14500 : type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
26970 : type);
26971 14500 : add_name_attribute (type_die, IDENTIFIER_POINTER (name));
26972 14500 : equate_type_number_to_die (type, type_die);
26973 : }
26974 : }
26975 : break;
26976 :
26977 147407 : default:
26978 147407 : if (is_cxx_auto (type))
26979 : {
26980 147401 : tree name = TYPE_IDENTIFIER (type);
26981 147401 : dw_die_ref *die = (name == get_identifier ("auto")
26982 147401 : ? &auto_die : &decltype_auto_die);
26983 147401 : if (!*die)
26984 : {
26985 17909 : *die = new_die (DW_TAG_unspecified_type,
26986 : comp_unit_die (), NULL_TREE);
26987 17909 : add_name_attribute (*die, IDENTIFIER_POINTER (name));
26988 : }
26989 147401 : equate_type_number_to_die (type, *die);
26990 147401 : break;
26991 : }
26992 6 : if (is_cxx ()
26993 6 : && TREE_CODE (type) >= LAST_AND_UNUSED_TREE_CODE
26994 6 : && TYPE_P (type)
26995 12 : && TYPE_IDENTIFIER (type))
26996 6 : goto unspecified_type;
26997 0 : gcc_unreachable ();
26998 : }
26999 :
27000 31117533 : TREE_ASM_WRITTEN (type) = 1;
27001 : }
27002 :
27003 : static void
27004 903945822 : gen_type_die (tree type, dw_die_ref context_die, bool reverse)
27005 : {
27006 903945822 : if (type != error_mark_node)
27007 : {
27008 903945822 : gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE, reverse);
27009 903945822 : if (flag_checking)
27010 : {
27011 903945799 : dw_die_ref die = lookup_type_die (type);
27012 903945799 : if (die)
27013 714608375 : check_die (die);
27014 : }
27015 : }
27016 903945822 : }
27017 :
27018 : /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
27019 : things which are local to the given block. */
27020 :
27021 : static void
27022 23120845 : gen_block_die (tree stmt, dw_die_ref context_die)
27023 : {
27024 23120845 : int must_output_die = 0;
27025 23120845 : bool inlined_func;
27026 :
27027 : /* Ignore blocks that are NULL. */
27028 23120845 : if (stmt == NULL_TREE)
27029 : return;
27030 :
27031 23120845 : inlined_func = inlined_function_outer_scope_p (stmt);
27032 :
27033 : /* If the block is one fragment of a non-contiguous block, do not
27034 : process the variables, since they will have been done by the
27035 : origin block. Do process subblocks. */
27036 23120845 : if (BLOCK_FRAGMENT_ORIGIN (stmt))
27037 : {
27038 10904584 : tree sub;
27039 :
27040 10904584 : for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
27041 0 : gen_block_die (sub, context_die);
27042 :
27043 : return;
27044 : }
27045 :
27046 : /* Determine if we need to output any Dwarf DIEs at all to represent this
27047 : block. */
27048 12216261 : if (inlined_func)
27049 : /* The outer scopes for inlinings *must* always be represented. We
27050 : generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
27051 : must_output_die = 1;
27052 5718018 : else if (lookup_block_die (stmt))
27053 : /* If we already have a DIE then it was filled early. Meanwhile
27054 : we might have pruned all BLOCK_VARS as optimized out but we
27055 : still want to generate high/low PC attributes so output it. */
27056 : must_output_die = 1;
27057 5457040 : else if (TREE_USED (stmt)
27058 8293 : || TREE_ASM_WRITTEN (stmt))
27059 : {
27060 : /* Determine if this block directly contains any "significant"
27061 : local declarations which we will need to output DIEs for. */
27062 5455166 : if (debug_info_level > DINFO_LEVEL_TERSE)
27063 : {
27064 : /* We are not in terse mode so any local declaration that
27065 : is not ignored for debug purposes counts as being a
27066 : "significant" one. */
27067 5369804 : if (BLOCK_NUM_NONLOCALIZED_VARS (stmt))
27068 : must_output_die = 1;
27069 : else
27070 5609538 : for (tree var = BLOCK_VARS (stmt); var; var = DECL_CHAIN (var))
27071 986963 : if (!DECL_IGNORED_P (var))
27072 : {
27073 : must_output_die = 1;
27074 : break;
27075 : }
27076 : }
27077 85362 : else if (!dwarf2out_ignore_block (stmt))
27078 : must_output_die = 1;
27079 : }
27080 :
27081 : /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
27082 : DIE for any block which contains no significant local declarations at
27083 : all. Rather, in such cases we just call `decls_for_scope' so that any
27084 : needed Dwarf info for any sub-blocks will get properly generated. Note
27085 : that in terse mode, our definition of what constitutes a "significant"
27086 : local declaration gets restricted to include only inlined function
27087 : instances and local (nested) function definitions. */
27088 5364190 : if (must_output_die)
27089 : {
27090 7506503 : if (inlined_func)
27091 6498243 : gen_inlined_subroutine_die (stmt, context_die);
27092 : else
27093 1008260 : gen_lexical_block_die (stmt, context_die);
27094 : }
27095 : else
27096 4709758 : decls_for_scope (stmt, context_die);
27097 : }
27098 :
27099 : /* Process variable DECL (or variable with origin ORIGIN) within
27100 : block STMT and add it to CONTEXT_DIE. */
27101 : static void
27102 17828896 : process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
27103 : {
27104 17828896 : dw_die_ref die;
27105 17828896 : tree decl_or_origin = decl ? decl : origin;
27106 :
27107 17828896 : if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
27108 15607 : die = lookup_decl_die (decl_or_origin);
27109 17813289 : else if (TREE_CODE (decl_or_origin) == TYPE_DECL)
27110 : {
27111 693720 : if (TYPE_DECL_IS_STUB (decl_or_origin))
27112 124869 : die = lookup_type_die (TREE_TYPE (decl_or_origin));
27113 : else
27114 568851 : die = lookup_decl_die (decl_or_origin);
27115 : /* Avoid re-creating the DIE late if it was optimized as unused early. */
27116 693720 : if (! die && ! early_dwarf)
27117 : return;
27118 : }
27119 : else
27120 : die = NULL;
27121 :
27122 : /* Avoid creating DIEs for local typedefs and concrete static variables that
27123 : will only be pruned later. */
27124 17356110 : if ((origin || decl_ultimate_origin (decl))
27125 30875099 : && (TREE_CODE (decl_or_origin) == TYPE_DECL
27126 13465422 : || (VAR_P (decl_or_origin) && TREE_STATIC (decl_or_origin))))
27127 : {
27128 110788 : origin = decl_ultimate_origin (decl_or_origin);
27129 110788 : if (decl && VAR_P (decl) && die != NULL)
27130 : {
27131 0 : die = lookup_decl_die (origin);
27132 0 : if (die != NULL)
27133 0 : equate_decl_number_to_die (decl, die);
27134 : }
27135 110788 : return;
27136 : }
27137 :
27138 17300531 : if (die != NULL && die->die_parent == NULL)
27139 7102 : add_child_die (context_die, die);
27140 :
27141 17300531 : if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
27142 : {
27143 12495 : if (early_dwarf)
27144 5858 : dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
27145 : stmt, context_die);
27146 : }
27147 : else
27148 : {
27149 17288036 : if (decl && DECL_P (decl))
27150 : {
27151 17288021 : die = lookup_decl_die (decl);
27152 :
27153 : /* Early created DIEs do not have a parent as the decls refer
27154 : to the function as DECL_CONTEXT rather than the BLOCK. */
27155 17288021 : if (die && die->die_parent == NULL)
27156 : {
27157 2904 : gcc_assert (in_lto_p);
27158 2904 : add_child_die (context_die, die);
27159 : }
27160 : }
27161 :
27162 17288036 : gen_decl_die (decl, origin, NULL, context_die);
27163 : }
27164 : }
27165 :
27166 : /* Generate all of the decls declared within a given scope and (recursively)
27167 : all of its sub-blocks. */
27168 :
27169 : static void
27170 18037398 : decls_for_scope (tree stmt, dw_die_ref context_die, bool recurse)
27171 : {
27172 18037398 : tree decl;
27173 18037398 : unsigned int i;
27174 18037398 : tree subblocks;
27175 :
27176 : /* Ignore NULL blocks. */
27177 18037398 : if (stmt == NULL_TREE)
27178 : return;
27179 :
27180 : /* Output the DIEs to represent all of the data objects and typedefs
27181 : declared directly within this block but not within any nested
27182 : sub-blocks. Also, nested function and tag DIEs have been
27183 : generated with a parent of NULL; fix that up now. We don't
27184 : have to do this if we're at -g1. */
27185 18037398 : if (debug_info_level > DINFO_LEVEL_TERSE)
27186 : {
27187 35695039 : for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
27188 17770145 : process_scope_var (stmt, decl, NULL_TREE, context_die);
27189 : /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
27190 : origin - avoid doing this twice as we have no good way to see
27191 : if we've done it once already. */
27192 17924894 : if (! early_dwarf)
27193 12564049 : for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
27194 : {
27195 58755 : decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
27196 58755 : if (decl == current_function_decl)
27197 : /* Ignore declarations of the current function, while they
27198 : are declarations, gen_subprogram_die would treat them
27199 : as definitions again, because they are equal to
27200 : current_function_decl and endlessly recurse. */;
27201 58751 : else if (TREE_CODE (decl) == FUNCTION_DECL)
27202 3542 : process_scope_var (stmt, decl, NULL_TREE, context_die);
27203 : else
27204 55209 : process_scope_var (stmt, NULL_TREE, decl, context_die);
27205 : }
27206 : }
27207 :
27208 : /* Even if we're at -g1, we need to process the subblocks in order to get
27209 : inlined call information. */
27210 :
27211 : /* Output the DIEs to represent all sub-blocks (and the items declared
27212 : therein) of this block. */
27213 18037398 : if (recurse)
27214 34883619 : for (subblocks = BLOCK_SUBBLOCKS (stmt);
27215 34883619 : subblocks != NULL;
27216 19987301 : subblocks = BLOCK_CHAIN (subblocks))
27217 19987301 : gen_block_die (subblocks, context_die);
27218 : }
27219 :
27220 : /* Is this a typedef we can avoid emitting? */
27221 :
27222 : static bool
27223 1460724613 : is_redundant_typedef (const_tree decl)
27224 : {
27225 1460724613 : if (TYPE_DECL_IS_STUB (decl))
27226 : return true;
27227 :
27228 477880507 : if (DECL_ARTIFICIAL (decl)
27229 302357619 : && DECL_CONTEXT (decl)
27230 100520025 : && is_tagged_type (DECL_CONTEXT (decl))
27231 100103465 : && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
27232 577983972 : && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
27233 : /* Also ignore the artificial member typedef for the class name. */
27234 100103397 : return true;
27235 :
27236 : return false;
27237 : }
27238 :
27239 : /* Return TRUE if TYPE is a typedef that names a type for linkage
27240 : purposes. This kind of typedefs is produced by the C++ FE for
27241 : constructs like:
27242 :
27243 : typedef struct {...} foo;
27244 :
27245 : In that case, there is no typedef variant type produced for foo.
27246 : Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
27247 : struct type. */
27248 :
27249 : static bool
27250 901492659 : is_naming_typedef_decl (const_tree decl)
27251 : {
27252 901492659 : if (decl == NULL_TREE
27253 747971531 : || TREE_CODE (decl) != TYPE_DECL
27254 747346597 : || DECL_NAMELESS (decl)
27255 747345134 : || !is_tagged_type (TREE_TYPE (decl))
27256 512563769 : || DECL_IS_UNDECLARED_BUILTIN (decl)
27257 512511368 : || is_redundant_typedef (decl)
27258 : /* It looks like Ada produces TYPE_DECLs that are very similar
27259 : to C++ naming typedefs but that have different
27260 : semantics. Let's be specific to c++ for now. */
27261 925150626 : || !is_cxx (decl))
27262 878299241 : return false;
27263 :
27264 23193418 : return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
27265 759575 : && TYPE_NAME (TREE_TYPE (decl)) == decl
27266 23952987 : && (TYPE_STUB_DECL (TREE_TYPE (decl))
27267 759569 : != TYPE_NAME (TREE_TYPE (decl))));
27268 : }
27269 :
27270 : /* Looks up the DIE for a context. */
27271 :
27272 : static inline dw_die_ref
27273 296931 : lookup_context_die (tree context)
27274 : {
27275 296931 : if (context)
27276 : {
27277 : /* Find die that represents this context. */
27278 71975 : if (TYPE_P (context))
27279 : {
27280 13 : context = TYPE_MAIN_VARIANT (context);
27281 13 : dw_die_ref ctx = lookup_type_die (context);
27282 13 : if (!ctx)
27283 : return NULL;
27284 12 : return strip_naming_typedef (context, ctx);
27285 : }
27286 : else
27287 71962 : return lookup_decl_die (context);
27288 : }
27289 224956 : return comp_unit_die ();
27290 : }
27291 :
27292 : /* Returns the DIE for a context. */
27293 :
27294 : static inline dw_die_ref
27295 87201610 : get_context_die (tree context)
27296 : {
27297 87201610 : if (context)
27298 : {
27299 : /* Find die that represents this context. */
27300 87093232 : if (TYPE_P (context))
27301 : {
27302 20735302 : context = TYPE_MAIN_VARIANT (context);
27303 20735302 : return strip_naming_typedef (context, force_type_die (context));
27304 : }
27305 : else
27306 66357930 : return force_decl_die (context);
27307 : }
27308 108378 : return comp_unit_die ();
27309 : }
27310 :
27311 : /* Returns the DIE for decl. A DIE will always be returned. */
27312 :
27313 : static dw_die_ref
27314 237890564 : force_decl_die (tree decl)
27315 : {
27316 237890564 : dw_die_ref decl_die;
27317 237890564 : unsigned saved_external_flag;
27318 237890564 : tree save_fn = NULL_TREE;
27319 237890564 : decl_die = lookup_decl_die (decl);
27320 237890564 : if (!decl_die)
27321 : {
27322 2797227 : dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
27323 :
27324 2797227 : decl_die = lookup_decl_die (decl);
27325 2797227 : if (decl_die)
27326 : return decl_die;
27327 :
27328 2797227 : switch (TREE_CODE (decl))
27329 : {
27330 2314448 : case FUNCTION_DECL:
27331 : /* Clear current_function_decl, so that gen_subprogram_die thinks
27332 : that this is a declaration. At this point, we just want to force
27333 : declaration die. */
27334 2314448 : save_fn = current_function_decl;
27335 2314448 : current_function_decl = NULL_TREE;
27336 2314448 : gen_subprogram_die (decl, context_die);
27337 2314448 : current_function_decl = save_fn;
27338 2314448 : break;
27339 :
27340 562 : case VAR_DECL:
27341 : /* Set external flag to force declaration die. Restore it after
27342 : gen_decl_die() call. */
27343 562 : saved_external_flag = DECL_EXTERNAL (decl);
27344 562 : DECL_EXTERNAL (decl) = 1;
27345 562 : gen_decl_die (decl, NULL, NULL, context_die);
27346 562 : DECL_EXTERNAL (decl) = saved_external_flag;
27347 562 : break;
27348 :
27349 482211 : case NAMESPACE_DECL:
27350 482211 : if (dwarf_version >= 3 || !dwarf_strict)
27351 482211 : dwarf2out_decl (decl);
27352 : else
27353 : /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
27354 0 : decl_die = comp_unit_die ();
27355 : break;
27356 :
27357 0 : case CONST_DECL:
27358 : /* Enumerators shouldn't need force_decl_die. */
27359 0 : gcc_assert (DECL_CONTEXT (decl) == NULL_TREE
27360 : || TREE_CODE (DECL_CONTEXT (decl)) != ENUMERAL_TYPE);
27361 0 : gen_decl_die (decl, NULL, NULL, context_die);
27362 0 : break;
27363 :
27364 6 : case TRANSLATION_UNIT_DECL:
27365 6 : decl_die = comp_unit_die ();
27366 6 : break;
27367 :
27368 0 : default:
27369 0 : gcc_unreachable ();
27370 : }
27371 :
27372 : /* We should be able to find the DIE now. */
27373 2797227 : if (!decl_die)
27374 2797221 : decl_die = lookup_decl_die (decl);
27375 2797221 : gcc_assert (decl_die);
27376 : }
27377 :
27378 : return decl_die;
27379 : }
27380 :
27381 : /* Returns the DIE for TYPE, that must not be a base type. A DIE is
27382 : always returned. */
27383 :
27384 : static dw_die_ref
27385 21334525 : force_type_die (tree type)
27386 : {
27387 21334525 : dw_die_ref type_die;
27388 :
27389 21334525 : type_die = lookup_type_die (type);
27390 21334525 : if (!type_die)
27391 : {
27392 513942 : dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
27393 :
27394 513942 : type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
27395 513942 : TYPE_ATTRIBUTES (type),
27396 : false, context_die);
27397 513942 : gcc_assert (type_die);
27398 : }
27399 21334525 : return type_die;
27400 : }
27401 :
27402 : /* Force out any required namespaces to be able to output DECL,
27403 : and return the new context_die for it, if it's changed. */
27404 :
27405 : static dw_die_ref
27406 296009549 : setup_namespace_context (tree thing, dw_die_ref context_die)
27407 : {
27408 296009549 : tree context = (DECL_P (thing)
27409 296009549 : ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
27410 296009549 : if (context && TREE_CODE (context) == NAMESPACE_DECL)
27411 : /* Force out the namespace. */
27412 169187187 : context_die = force_decl_die (context);
27413 :
27414 296009549 : return context_die;
27415 : }
27416 :
27417 : /* Emit a declaration DIE for THING (which is either a DECL or a tagged
27418 : type) within its namespace, if appropriate.
27419 :
27420 : For compatibility with older debuggers, namespace DIEs only contain
27421 : declarations; all definitions are emitted at CU scope, with
27422 : DW_AT_specification pointing to the declaration (like with class
27423 : members). */
27424 :
27425 : static dw_die_ref
27426 295581916 : declare_in_namespace (tree thing, dw_die_ref context_die)
27427 : {
27428 295581916 : dw_die_ref ns_context;
27429 :
27430 295581916 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27431 : return context_die;
27432 :
27433 : /* External declarations in the local scope only need to be emitted
27434 : once, not once in the namespace and once in the scope.
27435 :
27436 : This avoids declaring the `extern' below in the
27437 : namespace DIE as well as in the innermost scope:
27438 :
27439 : namespace S
27440 : {
27441 : int i=5;
27442 : int foo()
27443 : {
27444 : int i=8;
27445 : extern int i;
27446 : return i;
27447 : }
27448 : }
27449 : */
27450 392265830 : if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
27451 : return context_die;
27452 :
27453 : /* If this decl is from an inlined function, then don't try to emit it in its
27454 : namespace, as we will get confused. It would have already been emitted
27455 : when the abstract instance of the inline function was emitted anyways. */
27456 295536707 : if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
27457 : return context_die;
27458 :
27459 295516462 : ns_context = setup_namespace_context (thing, context_die);
27460 :
27461 295516462 : if (ns_context != context_die)
27462 : {
27463 84093295 : if (is_fortran () || is_dlang ())
27464 13731 : return ns_context;
27465 84079564 : if (DECL_P (thing))
27466 19375078 : gen_decl_die (thing, NULL, NULL, ns_context);
27467 : else
27468 64704486 : gen_type_die (thing, ns_context);
27469 : }
27470 : return context_die;
27471 : }
27472 :
27473 : /* Generate a DIE for a namespace or namespace alias. */
27474 :
27475 : static void
27476 493128 : gen_namespace_die (tree decl, dw_die_ref context_die)
27477 : {
27478 493128 : dw_die_ref namespace_die;
27479 :
27480 : /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
27481 : they are an alias of. */
27482 493128 : if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
27483 : {
27484 : /* Output a real namespace or module. */
27485 482211 : context_die = setup_namespace_context (decl, comp_unit_die ());
27486 483785 : namespace_die = new_die (is_fortran () || is_dlang () || is_ada ()
27487 : ? DW_TAG_module : DW_TAG_namespace,
27488 : context_die, decl);
27489 : /* For Fortran modules defined in different CU don't add src coords. */
27490 482211 : if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
27491 : {
27492 184 : const char *name = dwarf2_name (decl, 0);
27493 184 : if (name)
27494 184 : add_name_attribute (namespace_die, name);
27495 : }
27496 : else
27497 482027 : add_name_and_src_coords_attributes (namespace_die, decl);
27498 482211 : if (DECL_EXTERNAL (decl))
27499 184 : add_AT_flag (namespace_die, DW_AT_declaration, 1);
27500 482211 : equate_decl_number_to_die (decl, namespace_die);
27501 : }
27502 : else
27503 : {
27504 : /* Output a namespace alias. */
27505 :
27506 : /* Force out the namespace we are an alias of, if necessary. */
27507 10917 : dw_die_ref origin_die
27508 10917 : = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
27509 :
27510 21834 : if (DECL_FILE_SCOPE_P (decl)
27511 19980 : || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
27512 10876 : context_die = setup_namespace_context (decl, comp_unit_die ());
27513 : /* Now create the namespace alias DIE. */
27514 10917 : namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
27515 10917 : add_name_and_src_coords_attributes (namespace_die, decl);
27516 10917 : add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
27517 10917 : equate_decl_number_to_die (decl, namespace_die);
27518 : }
27519 313 : if ((dwarf_version >= 5 || !dwarf_strict)
27520 493441 : && lang_hooks.decls.decl_dwarf_attribute (decl,
27521 : DW_AT_export_symbols) == 1)
27522 107901 : add_AT_flag (namespace_die, DW_AT_export_symbols, 1);
27523 :
27524 : /* Bypass dwarf2_name's check for DECL_NAMELESS. */
27525 493128 : if (want_pubnames ())
27526 33 : add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
27527 493128 : }
27528 :
27529 : /* Generate Dwarf debug information for a decl described by DECL.
27530 : The return value is currently only meaningful for PARM_DECLs,
27531 : for all other decls it returns NULL.
27532 :
27533 : If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
27534 : It can be NULL otherwise. */
27535 :
27536 : static dw_die_ref
27537 424128166 : gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
27538 : dw_die_ref context_die)
27539 : {
27540 424128166 : tree decl_or_origin = decl ? decl : origin;
27541 424128166 : tree class_origin = NULL, ultimate_origin;
27542 :
27543 424128166 : if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
27544 : return NULL;
27545 :
27546 365630203 : switch (TREE_CODE (decl_or_origin))
27547 : {
27548 : case ERROR_MARK:
27549 : break;
27550 :
27551 379423 : case CONST_DECL:
27552 379423 : if (!is_fortran () && !is_ada () && !is_dlang ())
27553 : {
27554 : /* The individual enumerators of an enum type get output when we output
27555 : the Dwarf representation of the relevant enum type itself. */
27556 : break;
27557 : }
27558 :
27559 : /* Emit its type. */
27560 26050 : gen_type_die (TREE_TYPE (decl), context_die);
27561 :
27562 : /* And its containing namespace. */
27563 26050 : context_die = declare_in_namespace (decl, context_die);
27564 :
27565 26050 : gen_const_die (decl, context_die);
27566 26050 : break;
27567 :
27568 96687245 : case FUNCTION_DECL:
27569 : #if 0
27570 : /* FIXME */
27571 : /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
27572 : on local redeclarations of global functions. That seems broken. */
27573 : if (current_function_decl != decl)
27574 : /* This is only a declaration. */;
27575 : #endif
27576 :
27577 : /* We should have abstract copies already and should not generate
27578 : stray type DIEs in late LTO dumping. */
27579 96687245 : if (! early_dwarf)
27580 : ;
27581 :
27582 : /* If we're emitting a clone, emit info for the abstract instance. */
27583 96454263 : else if (origin || DECL_ORIGIN (decl) != decl)
27584 664774 : dwarf2out_abstract_function (origin
27585 0 : ? DECL_ORIGIN (origin)
27586 332387 : : DECL_ABSTRACT_ORIGIN (decl));
27587 :
27588 : /* If we're emitting a possibly inlined function emit it as
27589 : abstract instance. */
27590 95786071 : else if (cgraph_function_possibly_inlined_p (decl)
27591 93240206 : && ! DECL_ABSTRACT_P (decl)
27592 73991285 : && ! class_or_namespace_scope_p (context_die)
27593 : /* dwarf2out_abstract_function won't emit a die if this is just
27594 : a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
27595 : that case, because that works only if we have a die. */
27596 95786071 : && DECL_INITIAL (decl) != NULL_TREE)
27597 0 : dwarf2out_abstract_function (decl);
27598 :
27599 : /* Otherwise we're emitting the primary DIE for this decl. */
27600 95786071 : else if (debug_info_level > DINFO_LEVEL_TERSE)
27601 : {
27602 : /* Before we describe the FUNCTION_DECL itself, make sure that we
27603 : have its containing type. */
27604 95772363 : if (!origin)
27605 95772363 : origin = decl_class_context (decl);
27606 95772363 : if (origin != NULL_TREE)
27607 94559454 : gen_type_die (origin, context_die);
27608 :
27609 : /* And its return type. */
27610 95772363 : gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
27611 :
27612 : /* And its virtual context. */
27613 95772363 : if (DECL_VINDEX (decl) != NULL_TREE)
27614 1229007 : gen_type_die (DECL_CONTEXT (decl), context_die);
27615 :
27616 : /* Make sure we have a member DIE for decl. */
27617 95772363 : if (origin != NULL_TREE)
27618 94559454 : gen_type_die_for_member (origin, decl, context_die);
27619 :
27620 : /* And its containing namespace. */
27621 95772363 : context_die = declare_in_namespace (decl, context_die);
27622 : }
27623 :
27624 : /* Now output a DIE to represent the function itself. */
27625 96687245 : if (decl)
27626 96687245 : gen_subprogram_die (decl, context_die);
27627 : break;
27628 :
27629 166531514 : case TYPE_DECL:
27630 : /* If we are in terse mode, don't generate any DIEs to represent any
27631 : actual typedefs. */
27632 166531514 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27633 : break;
27634 :
27635 : /* In the special case of a TYPE_DECL node representing the declaration
27636 : of some type tag, if the given TYPE_DECL is marked as having been
27637 : instantiated from some other (original) TYPE_DECL node (e.g. one which
27638 : was generated within the original definition of an inline function) we
27639 : used to generate a special (abbreviated) DW_TAG_structure_type,
27640 : DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
27641 : should be actually referencing those DIEs, as variable DIEs with that
27642 : type would be emitted already in the abstract origin, so it was always
27643 : removed during unused type pruning. Don't add anything in this
27644 : case. */
27645 166531514 : if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
27646 : break;
27647 :
27648 166531514 : if (is_redundant_typedef (decl))
27649 104244544 : gen_type_die (TREE_TYPE (decl), context_die);
27650 : else
27651 : /* Output a DIE to represent the typedef itself. */
27652 62286970 : gen_typedef_die (decl, context_die);
27653 : break;
27654 :
27655 100242 : case LABEL_DECL:
27656 100242 : if (debug_info_level >= DINFO_LEVEL_NORMAL)
27657 100242 : gen_label_die (decl, context_die);
27658 : break;
27659 :
27660 78998354 : case VAR_DECL:
27661 78998354 : case RESULT_DECL:
27662 : /* If we are in terse mode, don't generate any DIEs to represent any
27663 : variable declarations or definitions unless it is external. */
27664 78998354 : if (debug_info_level < DINFO_LEVEL_TERSE
27665 78998354 : || (debug_info_level == DINFO_LEVEL_TERSE
27666 1200 : && !TREE_PUBLIC (decl_or_origin)))
27667 : break;
27668 :
27669 78998354 : if (debug_info_level > DINFO_LEVEL_TERSE)
27670 : {
27671 : /* Avoid generating stray type DIEs during late dwarf dumping.
27672 : All types have been dumped early. */
27673 78997154 : if (early_dwarf
27674 : /* ??? But in LTRANS we cannot annotate early created variably
27675 : modified type DIEs without copying them and adjusting all
27676 : references to them. Dump them again as happens for inlining
27677 : which copies both the decl and the types. */
27678 : /* ??? And even non-LTO needs to re-visit type DIEs to fill
27679 : in VLA bound information for example. */
27680 78997154 : || (decl && variably_modified_type_p (TREE_TYPE (decl),
27681 : current_function_decl)))
27682 : {
27683 : /* Output any DIEs that are needed to specify the type of this data
27684 : object. */
27685 64452413 : if (decl_by_reference_p (decl_or_origin))
27686 3219 : gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
27687 : else
27688 64449194 : gen_type_die (TREE_TYPE (decl_or_origin), context_die);
27689 : }
27690 :
27691 78997154 : if (early_dwarf)
27692 : {
27693 : /* And its containing type. */
27694 64446648 : class_origin = decl_class_context (decl_or_origin);
27695 64446648 : if (class_origin != NULL_TREE)
27696 23794269 : gen_type_die_for_member (class_origin, decl_or_origin, context_die);
27697 :
27698 : /* And its containing namespace. */
27699 64446648 : context_die = declare_in_namespace (decl_or_origin, context_die);
27700 : }
27701 : }
27702 :
27703 : /* Now output the DIE to represent the data object itself. This gets
27704 : complicated because of the possibility that the VAR_DECL really
27705 : represents an inlined instance of a formal parameter for an inline
27706 : function. */
27707 78998354 : ultimate_origin = decl_ultimate_origin (decl_or_origin);
27708 78998354 : if (ultimate_origin != NULL_TREE
27709 13376731 : && TREE_CODE (ultimate_origin) == PARM_DECL)
27710 11931302 : gen_formal_parameter_die (decl, origin,
27711 : true /* Emit name attribute. */,
27712 : context_die);
27713 : else
27714 67067052 : gen_variable_die (decl, origin, context_die);
27715 : break;
27716 :
27717 17256629 : case FIELD_DECL:
27718 17256629 : gcc_assert (ctx != NULL && ctx->struct_type != NULL);
27719 : /* Ignore the nameless fields that are used to skip bits but handle C++
27720 : anonymous unions and structs. */
27721 17256629 : if (DECL_NAME (decl) != NULL_TREE
27722 326227 : || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
27723 17426382 : || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
27724 : {
27725 17123875 : gen_type_die (member_declared_type (decl), context_die);
27726 17123875 : gen_field_die (decl, ctx, context_die);
27727 : }
27728 : break;
27729 :
27730 4875766 : case PARM_DECL:
27731 : /* Avoid generating stray type DIEs during late dwarf dumping.
27732 : All types have been dumped early. */
27733 4875766 : if (early_dwarf
27734 : /* ??? But in LTRANS we cannot annotate early created variably
27735 : modified type DIEs without copying them and adjusting all
27736 : references to them. Dump them again as happens for inlining
27737 : which copies both the decl and the types. */
27738 : /* ??? And even non-LTO needs to re-visit type DIEs to fill
27739 : in VLA bound information for example. */
27740 4875766 : || (decl && variably_modified_type_p (TREE_TYPE (decl),
27741 : current_function_decl)))
27742 : {
27743 3869554 : if (DECL_BY_REFERENCE (decl_or_origin))
27744 42624 : gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
27745 : else
27746 3826930 : gen_type_die (TREE_TYPE (decl_or_origin), context_die);
27747 : }
27748 4875766 : return gen_formal_parameter_die (decl, origin,
27749 : true /* Emit name attribute. */,
27750 4875766 : context_die);
27751 :
27752 493128 : case NAMESPACE_DECL:
27753 493128 : if (dwarf_version >= 3 || !dwarf_strict)
27754 493128 : gen_namespace_die (decl, context_die);
27755 : break;
27756 :
27757 0 : case IMPORTED_DECL:
27758 0 : dwarf2out_imported_module_or_decl_1 (decl, DECL_NAME (decl),
27759 0 : DECL_CONTEXT (decl), context_die);
27760 0 : break;
27761 :
27762 245 : case NAMELIST_DECL:
27763 245 : gen_namelist_decl (DECL_NAME (decl), context_die,
27764 245 : NAMELIST_DECL_ASSOCIATED_DECL (decl));
27765 245 : break;
27766 :
27767 307657 : default:
27768 : /* Probably some frontend-internal decl. Assume we don't care. */
27769 307657 : gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
27770 : break;
27771 : }
27772 :
27773 360754437 : maybe_gen_btf_decl_tag_dies (decl_or_origin,
27774 : lookup_decl_die (decl_or_origin));
27775 :
27776 360754437 : return NULL;
27777 : }
27778 :
27779 : /* Output initial debug information for global DECL. Called at the
27780 : end of the parsing process.
27781 :
27782 : This is the initial debug generation process. As such, the DIEs
27783 : generated may be incomplete. A later debug generation pass
27784 : (dwarf2out_late_global_decl) will augment the information generated
27785 : in this pass (e.g., with complete location info). */
27786 :
27787 : static void
27788 41860083 : dwarf2out_early_global_decl (tree decl)
27789 : {
27790 41860083 : set_early_dwarf s;
27791 :
27792 : /* gen_decl_die() will set DECL_ABSTRACT because
27793 : cgraph_function_possibly_inlined_p() returns true. This is in
27794 : turn will cause DW_AT_inline attributes to be set.
27795 :
27796 : This happens because at early dwarf generation, there is no
27797 : cgraph information, causing cgraph_function_possibly_inlined_p()
27798 : to return true. Trick cgraph_function_possibly_inlined_p()
27799 : while we generate dwarf early. */
27800 41860083 : bool save = symtab->global_info_ready;
27801 41860083 : symtab->global_info_ready = true;
27802 :
27803 : /* We don't handle TYPE_DECLs. If required, they'll be reached via
27804 : other DECLs and they can point to template types or other things
27805 : that dwarf2out can't handle when done via dwarf2out_decl. */
27806 41860083 : if (TREE_CODE (decl) != TYPE_DECL
27807 41860083 : && TREE_CODE (decl) != PARM_DECL)
27808 : {
27809 34906559 : if (TREE_CODE (decl) == FUNCTION_DECL)
27810 : {
27811 2124158 : tree save_fndecl = current_function_decl;
27812 :
27813 : /* For nested functions, make sure we have DIEs for the parents first
27814 : so that all nested DIEs are generated at the proper scope in the
27815 : first shot. */
27816 2124158 : tree context = decl_function_context (decl);
27817 2124158 : if (context != NULL)
27818 : {
27819 41610 : dw_die_ref context_die = lookup_decl_die (context);
27820 41610 : current_function_decl = context;
27821 :
27822 : /* Avoid emitting DIEs multiple times, but still process CONTEXT
27823 : enough so that it lands in its own context. This avoids type
27824 : pruning issues later on. */
27825 41610 : if (context_die == NULL || is_declaration_die (context_die))
27826 3291 : dwarf2out_early_global_decl (context);
27827 : }
27828 :
27829 : /* Emit an abstract origin of a function first. This happens
27830 : with C++ constructor clones for example and makes
27831 : dwarf2out_abstract_function happy which requires the early
27832 : DIE of the abstract instance to be present. */
27833 2124158 : tree origin = DECL_ABSTRACT_ORIGIN (decl);
27834 2124158 : dw_die_ref origin_die;
27835 2124158 : if (origin != NULL
27836 : /* Do not emit the DIE multiple times but make sure to
27837 : process it fully here in case we just saw a declaration. */
27838 2124158 : && ((origin_die = lookup_decl_die (origin)) == NULL
27839 228772 : || is_declaration_die (origin_die)))
27840 : {
27841 317553 : current_function_decl = origin;
27842 317553 : dwarf2out_decl (origin);
27843 : }
27844 :
27845 : /* Emit the DIE for decl but avoid doing that multiple times. */
27846 2124158 : dw_die_ref old_die;
27847 2124158 : if ((old_die = lookup_decl_die (decl)) == NULL
27848 2124158 : || is_declaration_die (old_die))
27849 : {
27850 2120649 : current_function_decl = decl;
27851 2120649 : dwarf2out_decl (decl);
27852 : }
27853 :
27854 2124158 : current_function_decl = save_fndecl;
27855 : }
27856 : else
27857 32782401 : dwarf2out_decl (decl);
27858 : }
27859 41860083 : symtab->global_info_ready = save;
27860 41860083 : }
27861 :
27862 : /* Return whether EXPR is an expression with the following pattern:
27863 : INDIRECT_REF (NOP_EXPR (INTEGER_CST)). */
27864 :
27865 : static bool
27866 52 : is_trivial_indirect_ref (tree expr)
27867 : {
27868 52 : if (expr == NULL_TREE || TREE_CODE (expr) != INDIRECT_REF)
27869 : return false;
27870 :
27871 0 : tree nop = TREE_OPERAND (expr, 0);
27872 0 : if (nop == NULL_TREE || TREE_CODE (nop) != NOP_EXPR)
27873 : return false;
27874 :
27875 0 : tree int_cst = TREE_OPERAND (nop, 0);
27876 0 : return int_cst != NULL_TREE && TREE_CODE (int_cst) == INTEGER_CST;
27877 : }
27878 :
27879 : /* Output debug information for global decl DECL. Called from
27880 : toplev.cc after compilation proper has finished. */
27881 :
27882 : static void
27883 36183041 : dwarf2out_late_global_decl (tree decl)
27884 : {
27885 : /* Fill-in any location information we were unable to determine
27886 : on the first pass. */
27887 36183041 : if (VAR_P (decl))
27888 : {
27889 36183041 : dw_die_ref die = lookup_decl_die (decl);
27890 :
27891 : /* We may have to generate full debug late for LTO in case debug
27892 : was not enabled at compile-time or the target doesn't support
27893 : the LTO early debug scheme. */
27894 5359890 : if (! die && in_lto_p
27895 : /* Function scope variables are emitted when emitting the
27896 : DIE for the function. */
27897 36184719 : && ! local_function_static (decl))
27898 1653 : dwarf2out_decl (decl);
27899 36181388 : else if (die)
27900 : {
27901 : /* We get called via the symtab code invoking late_global_decl
27902 : for symbols that are optimized out.
27903 :
27904 : Do not add locations for those, except if they have a
27905 : DECL_VALUE_EXPR, in which case they are relevant for debuggers.
27906 : Still don't add a location if the DECL_VALUE_EXPR is not a trivial
27907 : INDIRECT_REF expression, as this could generate relocations to
27908 : text symbols in LTO object files, which is invalid. */
27909 30823151 : varpool_node *node = varpool_node::get (decl);
27910 30823151 : if ((! node || ! node->definition)
27911 61405069 : && ! (DECL_HAS_VALUE_EXPR_P (decl)
27912 52 : && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl))))
27913 30581866 : tree_add_const_value_attribute_for_decl (die, decl);
27914 : else
27915 : {
27916 241285 : add_location_or_const_value_attribute (die, decl, false);
27917 : /* For C++ structured bindings at namespace scope when processing
27918 : the underlying variable also add locations on the structured
27919 : bindings which refer to it (unless they are tuple-based, then
27920 : they are separate VAR_DECLs registered in varpool). */
27921 241285 : if (tree attr = lookup_attribute ("structured bindings",
27922 241285 : DECL_ATTRIBUTES (decl)))
27923 183 : for (tree d = TREE_VALUE (attr); d; d = TREE_CHAIN (d))
27924 : {
27925 141 : die = lookup_decl_die (TREE_VALUE (d));
27926 141 : if (die)
27927 141 : add_location_or_const_value_attribute (die,
27928 141 : TREE_VALUE (d),
27929 : false);
27930 : }
27931 : }
27932 : }
27933 : }
27934 36183041 : }
27935 :
27936 : /* Output debug information for type decl DECL. Called from toplev.cc
27937 : and from language front ends (to record built-in types). */
27938 : static void
27939 68276067 : dwarf2out_type_decl (tree decl, int local)
27940 : {
27941 68276067 : if (!local)
27942 : {
27943 60041958 : set_early_dwarf s;
27944 60041958 : dwarf2out_decl (decl);
27945 60041958 : }
27946 68276067 : }
27947 :
27948 : /* Output debug information for imported module or decl DECL.
27949 : NAME is non-NULL name in the lexical block if the decl has been renamed.
27950 : LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
27951 : that DECL belongs to.
27952 : LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
27953 : static void
27954 5949646 : dwarf2out_imported_module_or_decl_1 (tree decl,
27955 : tree name,
27956 : tree lexical_block,
27957 : dw_die_ref lexical_block_die)
27958 : {
27959 5949646 : expanded_location xloc;
27960 5949646 : dw_die_ref imported_die = NULL;
27961 5949646 : dw_die_ref at_import_die;
27962 :
27963 5949646 : if (TREE_CODE (decl) == IMPORTED_DECL)
27964 : {
27965 5858 : xloc = expand_location (DECL_SOURCE_LOCATION (decl));
27966 5858 : decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
27967 5858 : gcc_assert (decl);
27968 : }
27969 : else
27970 5943788 : xloc = expand_location (input_location);
27971 :
27972 5949646 : if (TREE_CODE (decl) == TYPE_DECL)
27973 : {
27974 599223 : at_import_die = force_type_die (TREE_TYPE (decl));
27975 : /* For namespace N { typedef void T; } using N::T; base_type_die
27976 : returns NULL, but DW_TAG_imported_declaration requires
27977 : the DW_AT_import tag. Force creation of DW_TAG_typedef. */
27978 599223 : if (!at_import_die)
27979 : {
27980 0 : gcc_assert (TREE_CODE (decl) == TYPE_DECL);
27981 0 : gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
27982 0 : at_import_die = lookup_type_die (TREE_TYPE (decl));
27983 0 : gcc_assert (at_import_die);
27984 : }
27985 : }
27986 : else
27987 : {
27988 5350423 : at_import_die = lookup_decl_die (decl);
27989 5350423 : if (!at_import_die)
27990 : {
27991 : /* If we're trying to avoid duplicate debug info, we may not have
27992 : emitted the member decl for this field. Emit it now. */
27993 2105996 : if (TREE_CODE (decl) == FIELD_DECL)
27994 : {
27995 6 : tree type = DECL_CONTEXT (decl);
27996 :
27997 6 : if (TYPE_CONTEXT (type)
27998 6 : && TYPE_P (TYPE_CONTEXT (type))
27999 6 : && !should_emit_struct_debug (TYPE_CONTEXT (type),
28000 : DINFO_USAGE_DIR_USE))
28001 2 : return;
28002 6 : gen_type_die_for_member (type, decl,
28003 6 : get_context_die (TYPE_CONTEXT (type)));
28004 : }
28005 2105996 : if (TREE_CODE (decl) == CONST_DECL)
28006 : {
28007 : /* Individual enumerators of an enum type do not get output here
28008 : (see gen_decl_die), so we cannot call force_decl_die. */
28009 2 : if (!is_fortran () && !is_ada () && !is_dlang ())
28010 : return;
28011 : }
28012 2105994 : if (TREE_CODE (decl) == NAMELIST_DECL)
28013 4 : at_import_die = gen_namelist_decl (DECL_NAME (decl),
28014 4 : get_context_die (DECL_CONTEXT (decl)),
28015 : NULL_TREE);
28016 : else
28017 2105990 : at_import_die = force_decl_die (decl);
28018 : }
28019 : }
28020 :
28021 5949644 : if (TREE_CODE (decl) == NAMESPACE_DECL)
28022 : {
28023 34166 : if (dwarf_version >= 3 || !dwarf_strict)
28024 34166 : imported_die = new_die (DW_TAG_imported_module,
28025 : lexical_block_die,
28026 : lexical_block);
28027 : else
28028 : return;
28029 : }
28030 : else
28031 5915478 : imported_die = new_die (DW_TAG_imported_declaration,
28032 : lexical_block_die,
28033 : lexical_block);
28034 :
28035 5949644 : add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
28036 5949644 : add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
28037 5949644 : if (debug_column_info && xloc.column)
28038 5949644 : add_AT_unsigned (imported_die, DW_AT_decl_column, xloc.column);
28039 5949644 : if (name)
28040 29 : add_AT_string (imported_die, DW_AT_name,
28041 29 : IDENTIFIER_POINTER (name));
28042 5949644 : add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
28043 : }
28044 :
28045 : /* Output debug information for imported module or decl DECL.
28046 : NAME is non-NULL name in context if the decl has been renamed.
28047 : CHILD is true if decl is one of the renamed decls as part of
28048 : importing whole module.
28049 : IMPLICIT is set if this hook is called for an implicit import
28050 : such as inline namespace. */
28051 :
28052 : static void
28053 6096437 : dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
28054 : bool child, bool implicit)
28055 : {
28056 : /* dw_die_ref at_import_die; */
28057 6096437 : dw_die_ref scope_die;
28058 :
28059 6096437 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28060 152649 : return;
28061 :
28062 6096362 : gcc_assert (decl);
28063 :
28064 : /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
28065 : should be enough, for DWARF4 and older even if we emit as extension
28066 : DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
28067 : for the benefit of consumers unaware of DW_AT_export_symbols. */
28068 6096362 : if (implicit
28069 152649 : && dwarf_version >= 5
28070 6248936 : && lang_hooks.decls.decl_dwarf_attribute (decl,
28071 : DW_AT_export_symbols) == 1)
28072 : return;
28073 :
28074 5943788 : set_early_dwarf s;
28075 :
28076 : /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
28077 : We need decl DIE for reference and scope die. First, get DIE for the decl
28078 : itself. */
28079 :
28080 : /* Get the scope die for decl context. Use comp_unit_die for global module
28081 : or decl. If die is not found for non globals, force new die. */
28082 5943788 : if (context
28083 5837277 : && TYPE_P (context)
28084 8506607 : && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
28085 : return;
28086 :
28087 5943788 : scope_die = get_context_die (context);
28088 :
28089 5943788 : if (child)
28090 : {
28091 : /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
28092 : there is nothing we can do, here. */
28093 13 : if (dwarf_version < 3 && dwarf_strict)
28094 : return;
28095 :
28096 13 : gcc_assert (scope_die->die_child);
28097 13 : gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
28098 13 : gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
28099 : scope_die = scope_die->die_child;
28100 : }
28101 :
28102 : /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
28103 5943788 : dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
28104 5943788 : }
28105 :
28106 : /* Output debug information for namelists. */
28107 :
28108 : static dw_die_ref
28109 249 : gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
28110 : {
28111 249 : dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
28112 249 : tree value;
28113 249 : unsigned i;
28114 :
28115 249 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28116 : return NULL;
28117 :
28118 249 : gcc_assert (scope_die != NULL);
28119 249 : nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
28120 249 : add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
28121 :
28122 : /* If there are no item_decls, we have a nondefining namelist, e.g.
28123 : with USE association; hence, set DW_AT_declaration. */
28124 249 : if (item_decls == NULL_TREE)
28125 : {
28126 4 : add_AT_flag (nml_die, DW_AT_declaration, 1);
28127 4 : return nml_die;
28128 : }
28129 :
28130 906 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
28131 : {
28132 661 : nml_item_ref_die = lookup_decl_die (value);
28133 661 : if (!nml_item_ref_die)
28134 258 : nml_item_ref_die = force_decl_die (value);
28135 :
28136 661 : nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
28137 661 : add_AT_die_ref (nml_item_die, DW_AT_namelist_item, nml_item_ref_die);
28138 : }
28139 : return nml_die;
28140 : }
28141 :
28142 :
28143 : /* Write the debugging output for DECL and return the DIE. */
28144 :
28145 : static void
28146 96307210 : dwarf2out_decl (tree decl)
28147 : {
28148 96307210 : dw_die_ref context_die = comp_unit_die ();
28149 :
28150 96307210 : switch (TREE_CODE (decl))
28151 : {
28152 : case ERROR_MARK:
28153 : return;
28154 :
28155 2998987 : case FUNCTION_DECL:
28156 : /* If we're a nested function, initially use a parent of NULL; if we're
28157 : a plain function, this will be fixed up in decls_for_scope. If
28158 : we're a method, it will be ignored, since we already have a DIE.
28159 : Avoid doing this late though since clones of class methods may
28160 : otherwise end up in limbo and create type DIEs late. */
28161 2998987 : if (early_dwarf
28162 2438202 : && decl_function_context (decl)
28163 : /* But if we're in terse mode, we don't care about scope. */
28164 3049963 : && debug_info_level > DINFO_LEVEL_TERSE)
28165 : context_die = NULL;
28166 : break;
28167 :
28168 32769916 : case VAR_DECL:
28169 : /* For local statics lookup proper context die. */
28170 32769916 : if (local_function_static (decl))
28171 34 : context_die = lookup_decl_die (DECL_CONTEXT (decl));
28172 :
28173 : /* If we are in terse mode, don't generate any DIEs to represent any
28174 : variable declarations or definitions unless it is external. */
28175 32769916 : if (debug_info_level < DINFO_LEVEL_TERSE
28176 32769911 : || (debug_info_level == DINFO_LEVEL_TERSE
28177 2386 : && !TREE_PUBLIC (decl)))
28178 : return;
28179 : break;
28180 :
28181 3243 : case CONST_DECL:
28182 3243 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28183 : return;
28184 3243 : if (!is_fortran () && !is_ada () && !is_dlang ())
28185 : return;
28186 3243 : if (TREE_STATIC (decl) && decl_function_context (decl))
28187 2886 : context_die = lookup_decl_die (DECL_CONTEXT (decl));
28188 : break;
28189 :
28190 493090 : case NAMESPACE_DECL:
28191 493090 : case IMPORTED_DECL:
28192 493090 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28193 : return;
28194 493087 : if (lookup_decl_die (decl) != NULL)
28195 : return;
28196 : break;
28197 :
28198 60041958 : case TYPE_DECL:
28199 : /* Don't emit stubs for types unless they are needed by other DIEs. */
28200 60041958 : if (TYPE_DECL_SUPPRESS_DEBUG (decl))
28201 : return;
28202 :
28203 : /* Don't bother trying to generate any DIEs to represent any of the
28204 : normal built-in types for the language we are compiling. */
28205 58303847 : if (DECL_IS_UNDECLARED_BUILTIN (decl))
28206 : return;
28207 :
28208 : /* If we are in terse mode, don't generate any DIEs for types. */
28209 56562508 : if (debug_info_level <= DINFO_LEVEL_TERSE)
28210 : return;
28211 :
28212 : /* If we're a function-scope tag, initially use a parent of NULL;
28213 : this will be fixed up in decls_for_scope. */
28214 56562094 : if (decl_function_context (decl))
28215 51064 : context_die = NULL;
28216 :
28217 : break;
28218 :
28219 : case NAMELIST_DECL:
28220 : break;
28221 :
28222 : default:
28223 : return;
28224 : }
28225 :
28226 92826325 : gen_decl_die (decl, NULL, NULL, context_die);
28227 :
28228 92826325 : if (flag_checking)
28229 : {
28230 92826303 : dw_die_ref die = lookup_decl_die (decl);
28231 92826303 : if (die)
28232 33103648 : check_die (die);
28233 : }
28234 : }
28235 :
28236 : /* Write the debugging output for DECL. */
28237 :
28238 : static void
28239 560785 : dwarf2out_function_decl (tree decl)
28240 : {
28241 560785 : dwarf2out_decl (decl);
28242 560785 : call_arg_locations = NULL;
28243 560785 : call_arg_loc_last = NULL;
28244 560785 : call_site_count = -1;
28245 560785 : tail_call_site_count = -1;
28246 560785 : decl_loc_table->empty ();
28247 560785 : cached_dw_loc_list_table->empty ();
28248 560785 : }
28249 :
28250 : /* Output a marker (i.e. a label) for the beginning of the generated code for
28251 : a lexical block. */
28252 :
28253 : static void
28254 22888477 : dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
28255 : unsigned int blocknum,
28256 : tree block ATTRIBUTE_UNUSED)
28257 : {
28258 : #ifdef CODEVIEW_DEBUGGING_INFO
28259 : if (codeview_debuginfo_p ())
28260 : codeview_begin_block (line, blocknum, block);
28261 : #endif
28262 :
28263 22888477 : switch_to_section (current_function_section ());
28264 22888477 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
28265 22888477 : }
28266 :
28267 : /* Output a marker (i.e. a label) for the end of the generated code for a
28268 : lexical block. */
28269 :
28270 : static void
28271 22888477 : dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
28272 : {
28273 : #ifdef CODEVIEW_DEBUGGING_INFO
28274 : if (codeview_debuginfo_p ())
28275 : codeview_end_block (line, blocknum);
28276 : #endif
28277 :
28278 22888477 : switch_to_section (current_function_section ());
28279 22888477 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
28280 22888477 : }
28281 :
28282 : /* Returns true if it is appropriate not to emit any debugging
28283 : information for BLOCK, because it doesn't contain any instructions.
28284 :
28285 : Don't allow this for blocks with nested functions or local classes
28286 : as we would end up with orphans, and in the presence of scheduling
28287 : we may end up calling them anyway. */
28288 :
28289 : static bool
28290 101532757 : dwarf2out_ignore_block (const_tree block)
28291 : {
28292 101532757 : tree decl;
28293 101532757 : unsigned int i;
28294 :
28295 208080195 : for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
28296 107012752 : if (TREE_CODE (decl) == FUNCTION_DECL
28297 107012752 : || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
28298 : return false;
28299 101356864 : for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
28300 : {
28301 305392 : decl = BLOCK_NONLOCALIZED_VAR (block, i);
28302 305392 : if (TREE_CODE (decl) == FUNCTION_DECL
28303 305392 : || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
28304 : return false;
28305 : }
28306 :
28307 : return true;
28308 : }
28309 :
28310 : /* Hash table routines for file_hash. */
28311 :
28312 : bool
28313 2083298022 : dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
28314 : {
28315 2083298022 : return filename_cmp (p1->key, p2) == 0;
28316 : }
28317 :
28318 : hashval_t
28319 1540500332 : dwarf_file_hasher::hash (dwarf_file_data *p)
28320 : {
28321 1540500332 : return htab_hash_string (p->key);
28322 : }
28323 :
28324 : /* Lookup FILE_NAME (in the list of filenames that we know about here in
28325 : dwarf2out.cc) and return its "index". The index of each (known) filename is
28326 : just a unique number which is associated with only that one filename. We
28327 : need such numbers for the sake of generating labels (in the .debug_sfnames
28328 : section) and references to those files numbers (in the .debug_srcinfo
28329 : and .debug_macinfo sections). If the filename given as an argument is not
28330 : found in our current list, add it to the list and assign it the next
28331 : available unique index number. */
28332 :
28333 : static struct dwarf_file_data *
28334 331058554 : lookup_filename (const char *file_name)
28335 : {
28336 331058554 : struct dwarf_file_data * created;
28337 :
28338 331058554 : if (!file_name)
28339 : return NULL;
28340 :
28341 331049137 : if (!file_name[0])
28342 244 : file_name = "<stdin>";
28343 :
28344 331049137 : dwarf_file_data **slot
28345 331049137 : = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
28346 : INSERT);
28347 331049137 : if (*slot)
28348 : return *slot;
28349 :
28350 3057540 : created = ggc_alloc<dwarf_file_data> ();
28351 3057540 : created->key = file_name;
28352 3057540 : created->filename = remap_debug_filename (file_name);
28353 3057540 : created->emitted_number = 0;
28354 3057540 : *slot = created;
28355 3057540 : return created;
28356 : }
28357 :
28358 : /* If the assembler will construct the file table, then translate the compiler
28359 : internal file table number into the assembler file table number, and emit
28360 : a .file directive if we haven't already emitted one yet. The file table
28361 : numbers are different because we prune debug info for unused variables and
28362 : types, which may include filenames. */
28363 :
28364 : static int
28365 208498043 : maybe_emit_file (struct dwarf_file_data * fd)
28366 : {
28367 208498043 : if (! fd->emitted_number)
28368 : {
28369 1188261 : if (last_emitted_file)
28370 1138387 : fd->emitted_number = last_emitted_file->emitted_number + 1;
28371 : else
28372 49874 : fd->emitted_number = 1;
28373 1188261 : last_emitted_file = fd;
28374 :
28375 1188261 : if (output_asm_line_debug_info ())
28376 : {
28377 1188149 : fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
28378 1188149 : output_quoted_string (asm_out_file, fd->filename);
28379 1188149 : fputc ('\n', asm_out_file);
28380 : }
28381 : }
28382 :
28383 208498043 : return fd->emitted_number;
28384 : }
28385 :
28386 : /* Schedule generation of a DW_AT_const_value attribute to DIE.
28387 : That generation should happen after function debug info has been
28388 : generated. The value of the attribute is the constant value of ARG. */
28389 :
28390 : static void
28391 10982361 : append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
28392 : {
28393 10982361 : die_arg_entry entry;
28394 :
28395 10982361 : if (!die || !arg)
28396 0 : return;
28397 :
28398 10982361 : gcc_assert (early_dwarf);
28399 :
28400 10982361 : if (!tmpl_value_parm_die_table)
28401 11706 : vec_alloc (tmpl_value_parm_die_table, 32);
28402 :
28403 10982361 : entry.die = die;
28404 10982361 : entry.arg = arg;
28405 10982361 : vec_safe_push (tmpl_value_parm_die_table, entry);
28406 : }
28407 :
28408 : /* Return TRUE if T is an instance of generic type, FALSE
28409 : otherwise. */
28410 :
28411 : static bool
28412 54074896 : generic_type_p (tree t)
28413 : {
28414 54074896 : if (t == NULL_TREE || !TYPE_P (t))
28415 : return false;
28416 54074896 : return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
28417 : }
28418 :
28419 : /* Schedule the generation of the generic parameter dies for the
28420 : instance of generic type T. The proper generation itself is later
28421 : done by gen_scheduled_generic_parms_dies. */
28422 :
28423 : static void
28424 54074896 : schedule_generic_params_dies_gen (tree t)
28425 : {
28426 54074896 : if (!generic_type_p (t))
28427 : return;
28428 :
28429 46495341 : gcc_assert (early_dwarf);
28430 :
28431 46495341 : if (!generic_type_instances)
28432 12661 : vec_alloc (generic_type_instances, 256);
28433 :
28434 46495341 : vec_safe_push (generic_type_instances, t);
28435 : }
28436 :
28437 : /* Add a DW_AT_const_value attribute to DIEs that were scheduled
28438 : by append_entry_to_tmpl_value_parm_die_table. This function must
28439 : be called after function DIEs have been generated. */
28440 :
28441 : static void
28442 104418 : gen_remaining_tmpl_value_param_die_attribute (void)
28443 : {
28444 104418 : if (tmpl_value_parm_die_table)
28445 : {
28446 : unsigned i, j;
28447 : die_arg_entry *e;
28448 :
28449 : /* We do this in two phases - first get the cases we can
28450 : handle during early-finish, preserving those we cannot
28451 : (containing symbolic constants where we don't yet know
28452 : whether we are going to output the referenced symbols).
28453 : For those we try again at late-finish. */
28454 : j = 0;
28455 11005956 : FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
28456 : {
28457 10982577 : if (!e->die->removed
28458 10982577 : && !tree_add_const_value_attribute (e->die, e->arg))
28459 : {
28460 375 : dw_loc_descr_ref loc = NULL;
28461 375 : if (! early_dwarf
28462 159 : && (dwarf_version >= 5 || !dwarf_strict))
28463 156 : loc = loc_descriptor_from_tree (e->arg, 2, NULL);
28464 156 : if (loc)
28465 150 : add_AT_loc (e->die, DW_AT_location, loc);
28466 : else
28467 225 : (*tmpl_value_parm_die_table)[j++] = *e;
28468 : }
28469 : }
28470 23379 : tmpl_value_parm_die_table->truncate (j);
28471 : }
28472 104418 : }
28473 :
28474 : /* Generate generic parameters DIEs for instances of generic types
28475 : that have been previously scheduled by
28476 : schedule_generic_params_dies_gen. This function must be called
28477 : after all the types of the CU have been laid out. */
28478 :
28479 : static void
28480 52383 : gen_scheduled_generic_parms_dies (void)
28481 : {
28482 52383 : unsigned i;
28483 52383 : tree t;
28484 :
28485 52383 : if (!generic_type_instances)
28486 52383 : return;
28487 :
28488 45170119 : FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
28489 45157921 : if (COMPLETE_TYPE_P (t))
28490 42766576 : gen_generic_params_dies (t);
28491 :
28492 12198 : generic_type_instances = NULL;
28493 : }
28494 :
28495 :
28496 : /* Replace DW_AT_name for the decl with name. */
28497 :
28498 : static void
28499 0 : dwarf2out_set_name (tree decl, tree name)
28500 : {
28501 0 : dw_die_ref die;
28502 0 : dw_attr_node *attr;
28503 0 : const char *dname;
28504 :
28505 0 : die = TYPE_SYMTAB_DIE (decl);
28506 0 : if (!die)
28507 : return;
28508 :
28509 0 : dname = dwarf2_name (name, 0);
28510 0 : if (!dname)
28511 : return;
28512 :
28513 0 : attr = get_AT (die, DW_AT_name);
28514 0 : if (attr)
28515 : {
28516 0 : struct indirect_string_node *node;
28517 :
28518 0 : node = find_AT_string (dname);
28519 : /* replace the string. */
28520 0 : attr->dw_attr_val.v.val_str = node;
28521 : }
28522 :
28523 : else
28524 0 : add_name_attribute (die, dname);
28525 : }
28526 :
28527 : /* True if before or during processing of the first function being emitted. */
28528 : static bool in_first_function_p = true;
28529 : /* True if loc_note during dwarf2out_var_location call might still be
28530 : before first real instruction at address equal to .Ltext0. */
28531 : static bool maybe_at_text_label_p = true;
28532 : /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
28533 : static unsigned int first_loclabel_num_not_at_text_label;
28534 :
28535 : /* Look ahead for a real insn. */
28536 :
28537 : static rtx_insn *
28538 13826468 : dwarf2out_next_real_insn (rtx_insn *loc_note)
28539 : {
28540 13826468 : rtx_insn *next_real = NEXT_INSN (loc_note);
28541 :
28542 150517007 : while (next_real)
28543 136428853 : if (INSN_P (next_real))
28544 : break;
28545 : else
28546 122864071 : next_real = NEXT_INSN (next_real);
28547 :
28548 13826468 : return next_real;
28549 : }
28550 :
28551 : /* Called by the final INSN scan whenever we see a var location. We
28552 : use it to drop labels in the right places, and throw the location in
28553 : our lookup table. */
28554 :
28555 : static void
28556 101209961 : dwarf2out_var_location (rtx_insn *loc_note)
28557 : {
28558 101209961 : char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
28559 101209961 : struct var_loc_node *newloc;
28560 101209961 : rtx_insn *next_real;
28561 101209961 : rtx_insn *call_insn = NULL;
28562 101209961 : static const char *last_label;
28563 101209961 : static const char *last_postcall_label;
28564 101209961 : static bool last_in_cold_section_p;
28565 101209961 : static rtx_insn *expected_next_loc_note;
28566 101209961 : tree decl;
28567 101209961 : bool var_loc_p;
28568 101209961 : var_loc_view view = 0;
28569 :
28570 101209961 : if (!NOTE_P (loc_note))
28571 : {
28572 42089724 : if (CALL_P (loc_note))
28573 : {
28574 3515180 : maybe_reset_location_view (loc_note, cur_line_info_table);
28575 3515180 : call_site_count++;
28576 3515180 : if (SIBLING_CALL_P (loc_note))
28577 60359 : tail_call_site_count++;
28578 3515180 : if (find_reg_note (loc_note, REG_CALL_ARG_LOCATION, NULL_RTX))
28579 : {
28580 3149654 : call_insn = loc_note;
28581 3149654 : loc_note = NULL;
28582 3149654 : var_loc_p = false;
28583 :
28584 3149654 : next_real = dwarf2out_next_real_insn (call_insn);
28585 3149654 : cached_next_real_insn = NULL;
28586 3149654 : goto create_label;
28587 : }
28588 365526 : if (optimize == 0 && !flag_var_tracking)
28589 : {
28590 : /* When the var-tracking pass is not running, there is no note
28591 : for indirect calls whose target is compile-time known. In this
28592 : case, process such calls specifically so that we generate call
28593 : sites for them anyway. */
28594 340662 : rtx x = PATTERN (loc_note);
28595 340662 : if (GET_CODE (x) == PARALLEL)
28596 1 : x = XVECEXP (x, 0, 0);
28597 340662 : if (GET_CODE (x) == SET)
28598 105200 : x = SET_SRC (x);
28599 340662 : if (GET_CODE (x) == CALL)
28600 340662 : x = XEXP (x, 0);
28601 340662 : if (!MEM_P (x)
28602 340662 : || GET_CODE (XEXP (x, 0)) != SYMBOL_REF
28603 320193 : || !SYMBOL_REF_DECL (XEXP (x, 0))
28604 645561 : || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0)))
28605 : != FUNCTION_DECL))
28606 : {
28607 35763 : call_insn = loc_note;
28608 35763 : loc_note = NULL;
28609 35763 : var_loc_p = false;
28610 :
28611 35763 : next_real = dwarf2out_next_real_insn (call_insn);
28612 35763 : cached_next_real_insn = NULL;
28613 35763 : goto create_label;
28614 : }
28615 : }
28616 : }
28617 38574544 : else if (!debug_variable_location_views)
28618 0 : gcc_unreachable ();
28619 : else
28620 38574544 : maybe_reset_location_view (loc_note, cur_line_info_table);
28621 :
28622 47278743 : return;
28623 : }
28624 :
28625 59120237 : var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
28626 59120237 : if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
28627 : return;
28628 :
28629 : /* Optimize processing a large consecutive sequence of location
28630 : notes so we don't spend too much time in next_real_insn. If the
28631 : next insn is another location note, remember the next_real_insn
28632 : calculation for next time. */
28633 59120237 : next_real = cached_next_real_insn;
28634 59120237 : if (next_real)
28635 : {
28636 48479186 : if (expected_next_loc_note != loc_note)
28637 : next_real = NULL;
28638 : }
28639 :
28640 : if (! next_real)
28641 10641051 : next_real = dwarf2out_next_real_insn (loc_note);
28642 :
28643 10641051 : if (next_real)
28644 : {
28645 58994883 : rtx_insn *next_note = NEXT_INSN (loc_note);
28646 170248998 : while (next_note != next_real)
28647 : {
28648 100738418 : if (! next_note->deleted ()
28649 100738418 : && NOTE_P (next_note)
28650 198451774 : && NOTE_KIND (next_note) == NOTE_INSN_VAR_LOCATION)
28651 : break;
28652 52259232 : next_note = NEXT_INSN (next_note);
28653 : }
28654 :
28655 58994883 : if (next_note == next_real)
28656 10515697 : cached_next_real_insn = NULL;
28657 : else
28658 : {
28659 48479186 : expected_next_loc_note = next_note;
28660 48479186 : cached_next_real_insn = next_real;
28661 : }
28662 : }
28663 : else
28664 125354 : cached_next_real_insn = NULL;
28665 :
28666 : /* If there are no instructions which would be affected by this note,
28667 : don't do anything. */
28668 59120237 : if (var_loc_p
28669 59120237 : && next_real == NULL_RTX
28670 59120237 : && !NOTE_DURING_CALL_P (loc_note))
28671 : return;
28672 :
28673 62305493 : create_label:
28674 :
28675 62305493 : if (next_real == NULL_RTX)
28676 261525 : next_real = get_last_insn ();
28677 :
28678 : /* If there were any real insns between note we processed last time
28679 : and this note (or if it is the first note), clear
28680 : last_{,postcall_}label so that they are not reused this time. */
28681 62305493 : if (last_var_location_insn == NULL_RTX
28682 61801285 : || last_var_location_insn != next_real
28683 48495538 : || last_in_cold_section_p != in_cold_section_p)
28684 : {
28685 13813135 : last_label = NULL;
28686 13813135 : last_postcall_label = NULL;
28687 : }
28688 :
28689 62305493 : if (var_loc_p)
28690 : {
28691 59120076 : const char *label
28692 59120076 : = NOTE_DURING_CALL_P (loc_note) ? last_postcall_label : last_label;
28693 59120076 : view = cur_line_info_table->view;
28694 59120076 : decl = NOTE_VAR_LOCATION_DECL (loc_note);
28695 59120076 : newloc = add_var_loc_to_decl (decl, loc_note, label, view);
28696 59120076 : if (newloc == NULL)
28697 : return;
28698 : }
28699 : else
28700 : {
28701 : decl = NULL_TREE;
28702 : newloc = NULL;
28703 : }
28704 :
28705 : /* If there were no real insns between note we processed last time
28706 : and this note, use the label we emitted last time. Otherwise
28707 : create a new label and emit it. */
28708 53931218 : if (last_label == NULL)
28709 : {
28710 11603871 : ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
28711 11603871 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
28712 11603871 : loclabel_num++;
28713 11603871 : last_label = ggc_strdup (loclabel);
28714 : /* See if loclabel might be equal to .Ltext0. If yes,
28715 : bump first_loclabel_num_not_at_text_label. */
28716 11603871 : if (!have_multiple_function_sections
28717 4729642 : && in_first_function_p
28718 261242 : && maybe_at_text_label_p)
28719 : {
28720 : static rtx_insn *last_start;
28721 : rtx_insn *insn;
28722 128714 : for (insn = loc_note; insn; insn = previous_insn (insn))
28723 83688 : if (insn == last_start)
28724 : break;
28725 83508 : else if (!NONDEBUG_INSN_P (insn))
28726 71109 : continue;
28727 : else
28728 : {
28729 12399 : rtx body = PATTERN (insn);
28730 12399 : if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
28731 3 : continue;
28732 : /* Inline asm could occupy zero bytes. */
28733 12640 : else if (GET_CODE (body) == ASM_INPUT
28734 12396 : || asm_noperands (body) >= 0)
28735 244 : continue;
28736 : #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h. */
28737 : else if (HAVE_ATTR_length && get_attr_min_length (insn) == 0)
28738 : continue;
28739 : #endif
28740 : else
28741 : {
28742 : /* Assume insn has non-zero length. */
28743 12152 : maybe_at_text_label_p = false;
28744 12152 : break;
28745 : }
28746 : }
28747 57358 : if (maybe_at_text_label_p)
28748 : {
28749 45206 : last_start = loc_note;
28750 45206 : first_loclabel_num_not_at_text_label = loclabel_num;
28751 : }
28752 : }
28753 : }
28754 :
28755 53931218 : gcc_assert ((loc_note == NULL_RTX && call_insn != NULL_RTX)
28756 : || (loc_note != NULL_RTX && call_insn == NULL_RTX));
28757 :
28758 53931218 : if (!var_loc_p)
28759 : {
28760 3185417 : struct call_arg_loc_node *ca_loc
28761 3185417 : = ggc_cleared_alloc<call_arg_loc_node> ();
28762 3185417 : rtx_insn *prev = call_insn;
28763 :
28764 3185417 : ca_loc->call_insn = call_insn;
28765 3185417 : ca_loc->next = NULL;
28766 3185417 : ca_loc->label = last_label;
28767 3185417 : gcc_assert (prev
28768 : && (CALL_P (prev)
28769 : || (NONJUMP_INSN_P (prev)
28770 : && GET_CODE (PATTERN (prev)) == SEQUENCE
28771 : && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
28772 3185417 : if (!CALL_P (prev))
28773 0 : prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
28774 3185417 : ca_loc->tail_call_p = SIBLING_CALL_P (prev);
28775 :
28776 : /* Look for a SYMBOL_REF in the "prev" instruction. */
28777 3185417 : rtx x = get_call_rtx_from (prev);
28778 3185417 : if (x)
28779 : {
28780 : /* Try to get the call symbol, if any. */
28781 3185417 : if (MEM_P (XEXP (x, 0)))
28782 3185417 : x = XEXP (x, 0);
28783 : /* First, look for a memory access to a symbol_ref. */
28784 3185417 : if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
28785 3036628 : && SYMBOL_REF_DECL (XEXP (x, 0))
28786 5972300 : && TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0))) == FUNCTION_DECL)
28787 2786880 : ca_loc->symbol_ref = XEXP (x, 0);
28788 : /* Otherwise, look at a compile-time known user-level function
28789 : declaration. */
28790 398537 : else if (MEM_P (x)
28791 398537 : && MEM_EXPR (x)
28792 540901 : && TREE_CODE (MEM_EXPR (x)) == FUNCTION_DECL)
28793 0 : ca_loc->symbol_ref = XEXP (DECL_RTL (MEM_EXPR (x)), 0);
28794 : }
28795 :
28796 3185417 : ca_loc->block = insn_scope (prev);
28797 3185417 : if (call_arg_locations)
28798 2740377 : call_arg_loc_last->next = ca_loc;
28799 : else
28800 445040 : call_arg_locations = ca_loc;
28801 3185417 : call_arg_loc_last = ca_loc;
28802 : }
28803 50745801 : else if (loc_note != NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
28804 : {
28805 47666725 : newloc->label = last_label;
28806 47666725 : newloc->view = view;
28807 : }
28808 : else
28809 : {
28810 3079076 : if (!last_postcall_label)
28811 : {
28812 1067255 : sprintf (loclabel, "%s-1", last_label);
28813 1067255 : last_postcall_label = ggc_strdup (loclabel);
28814 : }
28815 3079076 : newloc->label = last_postcall_label;
28816 : /* ??? This view is at last_label, not last_label-1, but we
28817 : could only assume view at last_label-1 is zero if we could
28818 : assume calls always have length greater than one. This is
28819 : probably true in general, though there might be a rare
28820 : exception to this rule, e.g. if a call insn is optimized out
28821 : by target magic. Then, even the -1 in the label will be
28822 : wrong, which might invalidate the range. Anyway, using view,
28823 : though technically possibly incorrect, will work as far as
28824 : ranges go: since L-1 is in the middle of the call insn,
28825 : (L-1).0 and (L-1).V shouldn't make any difference, and having
28826 : the loclist entry refer to the .loc entry might be useful, so
28827 : leave it like this. */
28828 3079076 : newloc->view = view;
28829 : }
28830 :
28831 53931218 : if (var_loc_p && flag_debug_asm)
28832 : {
28833 396 : const char *name, *sep, *patstr;
28834 396 : if (decl && DECL_NAME (decl))
28835 385 : name = IDENTIFIER_POINTER (DECL_NAME (decl));
28836 : else
28837 : name = "";
28838 396 : if (NOTE_VAR_LOCATION_LOC (loc_note))
28839 : {
28840 295 : sep = " => ";
28841 295 : patstr = str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note));
28842 : }
28843 : else
28844 : {
28845 : sep = " ";
28846 : patstr = "RESET";
28847 : }
28848 396 : fprintf (asm_out_file, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START,
28849 : name, sep, patstr);
28850 : }
28851 :
28852 53931218 : last_var_location_insn = next_real;
28853 53931218 : last_in_cold_section_p = in_cold_section_p;
28854 : }
28855 :
28856 : /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
28857 : OUTER itself. If BOTHWAYS, check not only that BLOCK can reach
28858 : OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
28859 : path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
28860 : BLOCK_FRAGMENT_ORIGIN links. */
28861 : static bool
28862 6829263 : block_within_block_p (tree block, tree outer, bool bothways)
28863 : {
28864 6829263 : if (block == outer)
28865 : return true;
28866 :
28867 : /* Quickly check that OUTER is up BLOCK's supercontext chain. */
28868 6829263 : for (tree context = BLOCK_SUPERCONTEXT (block);
28869 48280467 : context != outer;
28870 41451204 : context = BLOCK_SUPERCONTEXT (context))
28871 41451204 : if (!context || TREE_CODE (context) != BLOCK)
28872 : return false;
28873 :
28874 6829263 : if (!bothways)
28875 : return true;
28876 :
28877 : /* Now check that each block is actually referenced by its
28878 : parent. */
28879 41451204 : for (tree context = BLOCK_SUPERCONTEXT (block); ;
28880 41451204 : context = BLOCK_SUPERCONTEXT (context))
28881 : {
28882 48280467 : if (BLOCK_FRAGMENT_ORIGIN (context))
28883 : {
28884 2154086 : gcc_assert (!BLOCK_SUBBLOCKS (context));
28885 : context = BLOCK_FRAGMENT_ORIGIN (context);
28886 : }
28887 218721127 : for (tree sub = BLOCK_SUBBLOCKS (context);
28888 218721127 : sub != block;
28889 170440660 : sub = BLOCK_CHAIN (sub))
28890 170440660 : if (!sub)
28891 : return false;
28892 48280467 : if (context == outer)
28893 : return true;
28894 : else
28895 41451204 : block = context;
28896 41451204 : }
28897 : }
28898 :
28899 : /* Called during final while assembling the marker of the entry point
28900 : for an inlined function. */
28901 :
28902 : static void
28903 6829263 : dwarf2out_inline_entry (tree block)
28904 : {
28905 6829263 : gcc_assert (debug_inline_points);
28906 :
28907 : /* If we can't represent it, don't bother. */
28908 6829263 : if (!(dwarf_version >= 3 || !dwarf_strict))
28909 : return;
28910 :
28911 6829263 : gcc_assert (DECL_P (block_ultimate_origin (block)));
28912 :
28913 : /* Sanity check the block tree. This would catch a case in which
28914 : BLOCK got removed from the tree reachable from the outermost
28915 : lexical block, but got retained in markers. It would still link
28916 : back to its parents, but some ancestor would be missing a link
28917 : down the path to the sub BLOCK. If the block got removed, its
28918 : BLOCK_NUMBER will not be a usable value. */
28919 6829263 : if (flag_checking)
28920 6829263 : gcc_assert (block_within_block_p (block,
28921 : DECL_INITIAL (current_function_decl),
28922 : true));
28923 :
28924 6829263 : gcc_assert (inlined_function_outer_scope_p (block));
28925 6829263 : gcc_assert (!lookup_block_die (block));
28926 :
28927 6829263 : if (BLOCK_FRAGMENT_ORIGIN (block))
28928 0 : block = BLOCK_FRAGMENT_ORIGIN (block);
28929 : /* Can the entry point ever not be at the beginning of an
28930 : unfragmented lexical block? */
28931 6829263 : else if (!(BLOCK_FRAGMENT_CHAIN (block)
28932 3582359 : || (cur_line_info_table
28933 3582359 : && !ZERO_VIEW_P (cur_line_info_table->view))))
28934 675 : return;
28935 :
28936 6828588 : if (!inline_entry_data_table)
28937 12846 : inline_entry_data_table
28938 12846 : = hash_table<inline_entry_data_hasher>::create_ggc (10);
28939 :
28940 :
28941 6828588 : inline_entry_data **iedp
28942 6828588 : = inline_entry_data_table->find_slot_with_hash (block,
28943 : htab_hash_pointer (block),
28944 : INSERT);
28945 6828588 : if (*iedp)
28946 : /* ??? Ideally, we'd record all entry points for the same inlined
28947 : function (some may have been duplicated by e.g. unrolling), but
28948 : we have no way to represent that ATM. */
28949 : return;
28950 :
28951 6271336 : inline_entry_data *ied = *iedp = ggc_cleared_alloc<inline_entry_data> ();
28952 6271336 : ied->block = block;
28953 6271336 : ied->label_pfx = BLOCK_INLINE_ENTRY_LABEL;
28954 6271336 : ied->label_num = BLOCK_NUMBER (block);
28955 6271336 : if (cur_line_info_table)
28956 6271336 : ied->view = cur_line_info_table->view;
28957 :
28958 6271336 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_INLINE_ENTRY_LABEL,
28959 : BLOCK_NUMBER (block));
28960 : }
28961 :
28962 : /* Called from finalize_size_functions for size functions so that their body
28963 : can be encoded in the debug info to describe the layout of variable-length
28964 : structures. */
28965 :
28966 : static void
28967 0 : dwarf2out_size_function (tree decl)
28968 : {
28969 0 : set_early_dwarf s;
28970 0 : function_to_dwarf_procedure (decl);
28971 0 : }
28972 :
28973 : /* Note in one location list that text section has changed. */
28974 :
28975 : int
28976 3493728 : var_location_switch_text_section_1 (var_loc_list **slot, void *)
28977 : {
28978 3493728 : var_loc_list *list = *slot;
28979 3493728 : if (list->first)
28980 3493728 : list->last_before_switch
28981 3547802 : = list->last->next ? list->last->next : list->last;
28982 3493728 : return 1;
28983 : }
28984 :
28985 : /* Note in all location lists that text section has changed. */
28986 :
28987 : static void
28988 64340 : var_location_switch_text_section (void)
28989 : {
28990 64340 : if (decl_loc_table == NULL)
28991 : return;
28992 :
28993 3515303 : decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
28994 : }
28995 :
28996 : /* Create a new line number table. */
28997 :
28998 : static dw_line_info_table *
28999 259553 : new_line_info_table (void)
29000 : {
29001 259553 : dw_line_info_table *table;
29002 :
29003 259553 : table = ggc_cleared_alloc<dw_line_info_table> ();
29004 259553 : table->file_num = 1;
29005 259553 : table->line_num = 1;
29006 259553 : table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
29007 259553 : FORCE_RESET_NEXT_VIEW (table->view);
29008 259553 : table->symviews_since_reset = 0;
29009 :
29010 259553 : return table;
29011 : }
29012 :
29013 : /* Lookup the "current" table into which we emit line info, so
29014 : that we don't have to do it for every source line. */
29015 :
29016 : static void
29017 590322 : set_cur_line_info_table (section *sec)
29018 : {
29019 590322 : dw_line_info_table *table;
29020 :
29021 590322 : if (sec == text_section)
29022 380234 : table = text_section_line_info;
29023 210088 : else if (sec == cold_text_section)
29024 : {
29025 11683 : table = cold_text_section_line_info;
29026 11683 : if (!table)
29027 : {
29028 8792 : cold_text_section_line_info = table = new_line_info_table ();
29029 8792 : table->end_label = cold_end_label;
29030 : }
29031 : }
29032 : else
29033 : {
29034 198405 : const char *end_label;
29035 :
29036 198405 : if (crtl->has_bb_partition)
29037 : {
29038 27285 : if (in_cold_section_p)
29039 10006 : end_label = crtl->subsections.cold_section_end_label;
29040 : else
29041 17279 : end_label = crtl->subsections.hot_section_end_label;
29042 : }
29043 : else
29044 : {
29045 171120 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29046 171120 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
29047 : current_function_funcdef_no);
29048 171120 : end_label = ggc_strdup (label);
29049 : }
29050 :
29051 198405 : table = new_line_info_table ();
29052 198405 : table->end_label = end_label;
29053 :
29054 198405 : vec_safe_push (separate_line_info, table);
29055 : }
29056 :
29057 590322 : if (output_asm_line_debug_info ())
29058 1180552 : table->is_stmt = (cur_line_info_table
29059 590276 : ? cur_line_info_table->is_stmt
29060 : : DWARF_LINE_DEFAULT_IS_STMT_START);
29061 590322 : cur_line_info_table = table;
29062 590322 : }
29063 :
29064 :
29065 : /* We need to reset the locations at the beginning of each
29066 : function. We can't do this in the end_function hook, because the
29067 : declarations that use the locations won't have been output when
29068 : that hook is called. Also compute have_multiple_function_sections here. */
29069 :
29070 : static void
29071 560829 : dwarf2out_begin_function (tree fun)
29072 : {
29073 560829 : section *sec = function_section (fun);
29074 :
29075 560829 : if (sec != text_section)
29076 185125 : have_multiple_function_sections = true;
29077 :
29078 560829 : if (crtl->has_bb_partition && !cold_text_section)
29079 : {
29080 8792 : gcc_assert (current_function_decl == fun);
29081 8792 : cold_text_section = unlikely_text_section ();
29082 8792 : switch_to_section (cold_text_section);
29083 8792 : ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
29084 8792 : switch_to_section (sec);
29085 : }
29086 :
29087 560829 : call_site_count = 0;
29088 560829 : tail_call_site_count = 0;
29089 :
29090 560829 : set_cur_line_info_table (sec);
29091 560829 : FORCE_RESET_NEXT_VIEW (cur_line_info_table->view);
29092 560829 : }
29093 :
29094 : /* Helper function of dwarf2out_end_function, called only after emitting
29095 : the very first function into assembly. Check if some .debug_loc range
29096 : might end with a .LVL* label that could be equal to .Ltext0.
29097 : In that case we must force using absolute addresses in .debug_loc ranges,
29098 : because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
29099 : .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
29100 : list terminator.
29101 : Set have_multiple_function_sections to true in that case and
29102 : terminate htab traversal. */
29103 :
29104 : int
29105 182252 : find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
29106 : {
29107 182252 : var_loc_list *entry = *slot;
29108 182252 : struct var_loc_node *node;
29109 :
29110 182252 : node = entry->first;
29111 182252 : if (node && node->next && node->next->label)
29112 : {
29113 : unsigned int i;
29114 : const char *label = node->next->label;
29115 : char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
29116 :
29117 131879 : for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
29118 : {
29119 76990 : ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
29120 76990 : if (strcmp (label, loclabel) == 0)
29121 : {
29122 702 : have_multiple_function_sections = true;
29123 702 : return 0;
29124 : }
29125 : }
29126 : }
29127 : return 1;
29128 : }
29129 :
29130 : /* Hook called after emitting a function into assembly.
29131 : This does something only for the very first function emitted. */
29132 :
29133 : static void
29134 560829 : dwarf2out_end_function (unsigned int)
29135 : {
29136 560829 : if (in_first_function_p
29137 47088 : && !have_multiple_function_sections
29138 26990 : && first_loclabel_num_not_at_text_label
29139 19267 : && decl_loc_table)
29140 201519 : decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
29141 560829 : in_first_function_p = false;
29142 560829 : maybe_at_text_label_p = false;
29143 560829 : }
29144 :
29145 : /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
29146 : front-ends register a translation unit even before dwarf2out_init is
29147 : called. */
29148 : static tree main_translation_unit = NULL_TREE;
29149 :
29150 : /* Hook called by front-ends after they built their main translation unit.
29151 : Associate comp_unit_die to UNIT. */
29152 :
29153 : static void
29154 44918 : dwarf2out_register_main_translation_unit (tree unit)
29155 : {
29156 44918 : gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
29157 : && main_translation_unit == NULL_TREE);
29158 44918 : main_translation_unit = unit;
29159 : /* If dwarf2out_init has not been called yet, it will perform the association
29160 : itself looking at main_translation_unit. */
29161 44918 : if (decl_die_table != NULL)
29162 26810 : equate_decl_number_to_die (unit, comp_unit_die ());
29163 44918 : }
29164 :
29165 : /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
29166 :
29167 : static void
29168 5747 : push_dw_line_info_entry (dw_line_info_table *table,
29169 : enum dw_line_info_opcode opcode, unsigned int val)
29170 : {
29171 5747 : dw_line_info_entry e;
29172 5747 : e.opcode = opcode;
29173 5747 : e.val = val;
29174 0 : vec_safe_push (table->entries, e);
29175 4206 : }
29176 :
29177 : /* Output a label to mark the beginning of a source code line entry
29178 : and record information relating to this source line, in
29179 : 'line_info_table' for later output of the .debug_line section. */
29180 : /* ??? The discriminator parameter ought to be unsigned. */
29181 :
29182 : static void
29183 35604606 : dwarf2out_source_line (unsigned int line, unsigned int column,
29184 : const char *filename,
29185 : int discriminator, bool is_stmt)
29186 : {
29187 35604606 : unsigned int file_num;
29188 35604606 : dw_line_info_table *table;
29189 35604606 : static var_loc_view lvugid;
29190 :
29191 : #ifdef CODEVIEW_DEBUGGING_INFO
29192 : if (codeview_debuginfo_p ())
29193 : codeview_source_line (line, filename);
29194 : #endif
29195 :
29196 : /* 'line_info_table' information gathering is not needed when the debug
29197 : info level is set to the lowest value. Also, the current DWARF-based
29198 : debug formats do not use this info. */
29199 35604606 : if (debug_info_level < DINFO_LEVEL_TERSE || !dwarf_debuginfo_p ())
29200 1240 : return;
29201 :
29202 35603366 : table = cur_line_info_table;
29203 :
29204 35603366 : if (line == 0)
29205 : {
29206 586848 : if (debug_variable_location_views
29207 549716 : && output_asm_line_debug_info ()
29208 1136564 : && table && !RESETTING_VIEW_P (table->view))
29209 : {
29210 : /* If we're using the assembler to compute view numbers, we
29211 : can't issue a .loc directive for line zero, so we can't
29212 : get a view number at this point. We might attempt to
29213 : compute it from the previous view, or equate it to a
29214 : subsequent view (though it might not be there!), but
29215 : since we're omitting the line number entry, we might as
29216 : well omit the view number as well. That means pretending
29217 : it's a view number zero, which might very well turn out
29218 : to be correct. ??? Extend the assembler so that the
29219 : compiler could emit e.g. ".locview .LVU#", to output a
29220 : view without changing line number information. We'd then
29221 : have to count it in symviews_since_reset; when it's omitted,
29222 : it doesn't count. */
29223 4051 : if (!zero_view_p)
29224 0 : zero_view_p = BITMAP_GGC_ALLOC ();
29225 4051 : bitmap_set_bit (zero_view_p, table->view);
29226 4051 : if (flag_debug_asm)
29227 : {
29228 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29229 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
29230 0 : fprintf (asm_out_file, "\t%s line 0, omitted view ",
29231 : ASM_COMMENT_START);
29232 0 : assemble_name (asm_out_file, label);
29233 0 : putc ('\n', asm_out_file);
29234 : }
29235 4051 : table->view = ++lvugid;
29236 : }
29237 586848 : return;
29238 : }
29239 :
29240 : /* The discriminator column was added in dwarf4. Simplify the below
29241 : by simply removing it if we're not supposed to output it. */
29242 35016518 : if (dwarf_version < 4 && dwarf_strict)
29243 35016518 : discriminator = 0;
29244 :
29245 35016518 : if (!debug_column_info)
29246 82 : column = 0;
29247 :
29248 35016518 : file_num = maybe_emit_file (lookup_filename (filename));
29249 :
29250 : /* ??? TODO: Elide duplicate line number entries. Traditionally,
29251 : the debugger has used the second (possibly duplicate) line number
29252 : at the beginning of the function to mark the end of the prologue.
29253 : We could eliminate any other duplicates within the function. For
29254 : Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
29255 : that second line number entry. */
29256 : /* Recall that this end-of-prologue indication is *not* the same thing
29257 : as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
29258 : to which the hook corresponds, follows the last insn that was
29259 : emitted by gen_prologue. What we need is to precede the first insn
29260 : that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
29261 : insn that corresponds to something the user wrote. These may be
29262 : very different locations once scheduling is enabled. */
29263 :
29264 35016518 : if (0 && file_num == table->file_num
29265 : && line == table->line_num
29266 : && column == table->column_num
29267 : && discriminator == table->discrim_num
29268 : && is_stmt == table->is_stmt)
29269 : return;
29270 :
29271 35016518 : switch_to_section (current_function_section ());
29272 :
29273 : /* If requested, emit something human-readable. */
29274 35016518 : if (flag_debug_asm)
29275 : {
29276 6638 : if (debug_column_info)
29277 6581 : fprintf (asm_out_file, "\t%s %s:%d:%d\n", ASM_COMMENT_START,
29278 : filename, line, column);
29279 : else
29280 57 : fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
29281 : filename, line);
29282 : }
29283 :
29284 35016518 : if (output_asm_line_debug_info ())
29285 : {
29286 : /* Emit the .loc directive understood by GNU as. */
29287 : /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
29288 : file_num, line, is_stmt, discriminator */
29289 35014977 : fputs ("\t.loc ", asm_out_file);
29290 35014977 : fprint_ul (asm_out_file, file_num);
29291 35014977 : putc (' ', asm_out_file);
29292 35014977 : fprint_ul (asm_out_file, line);
29293 35014977 : putc (' ', asm_out_file);
29294 35014977 : fprint_ul (asm_out_file, column);
29295 :
29296 35014977 : if (is_stmt != table->is_stmt)
29297 : {
29298 : #if HAVE_GAS_LOC_STMT
29299 13479089 : fputs (" is_stmt ", asm_out_file);
29300 20234589 : putc (is_stmt ? '1' : '0', asm_out_file);
29301 : #endif
29302 : }
29303 35014977 : if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
29304 : {
29305 9720907 : gcc_assert (discriminator > 0);
29306 9720907 : fputs (" discriminator ", asm_out_file);
29307 9720907 : fprint_ul (asm_out_file, (unsigned long) discriminator);
29308 : }
29309 35014977 : if (debug_variable_location_views)
29310 : {
29311 34188827 : if (!RESETTING_VIEW_P (table->view))
29312 : {
29313 33750743 : table->symviews_since_reset++;
29314 33750743 : if (table->symviews_since_reset > symview_upper_bound)
29315 7067660 : symview_upper_bound = table->symviews_since_reset;
29316 : /* When we're using the assembler to compute view
29317 : numbers, we output symbolic labels after "view" in
29318 : .loc directives, and the assembler will set them for
29319 : us, so that we can refer to the view numbers in
29320 : location lists. The only exceptions are when we know
29321 : a view will be zero: "-0" is a forced reset, used
29322 : e.g. in the beginning of functions, whereas "0" tells
29323 : the assembler to check that there was a PC change
29324 : since the previous view, in a way that implicitly
29325 : resets the next view. */
29326 33750743 : fputs (" view ", asm_out_file);
29327 33750743 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29328 33750743 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
29329 33750743 : assemble_name (asm_out_file, label);
29330 33750743 : table->view = ++lvugid;
29331 : }
29332 : else
29333 : {
29334 438084 : table->symviews_since_reset = 0;
29335 438084 : if (FORCE_RESETTING_VIEW_P (table->view))
29336 438084 : fputs (" view -0", asm_out_file);
29337 : else
29338 0 : fputs (" view 0", asm_out_file);
29339 : /* Mark the present view as a zero view. Earlier debug
29340 : binds may have already added its id to loclists to be
29341 : emitted later, so we can't reuse the id for something
29342 : else. However, it's good to know whether a view is
29343 : known to be zero, because then we may be able to
29344 : optimize out locviews that are all zeros, so take
29345 : note of it in zero_view_p. */
29346 438084 : if (!zero_view_p)
29347 41228 : zero_view_p = BITMAP_GGC_ALLOC ();
29348 438084 : bitmap_set_bit (zero_view_p, lvugid);
29349 438084 : table->view = ++lvugid;
29350 : }
29351 : }
29352 35014977 : putc ('\n', asm_out_file);
29353 : }
29354 : else
29355 : {
29356 1541 : unsigned int label_num = ++line_info_label_num;
29357 :
29358 1541 : targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
29359 :
29360 1541 : if (debug_variable_location_views && !RESETTING_VIEW_P (table->view))
29361 1451 : push_dw_line_info_entry (table, LI_adv_address, label_num);
29362 : else
29363 90 : push_dw_line_info_entry (table, LI_set_address, label_num);
29364 1541 : if (debug_variable_location_views)
29365 : {
29366 1485 : bool resetting = FORCE_RESETTING_VIEW_P (table->view);
29367 1485 : if (resetting)
29368 34 : table->view = 0;
29369 :
29370 1485 : if (flag_debug_asm)
29371 88 : fprintf (asm_out_file, "\t%s view %s%d\n",
29372 : ASM_COMMENT_START,
29373 : resetting ? "-" : "",
29374 : table->view);
29375 :
29376 1485 : table->view++;
29377 : }
29378 1541 : if (file_num != table->file_num)
29379 280 : push_dw_line_info_entry (table, LI_set_file, file_num);
29380 1541 : if (discriminator != table->discrim_num)
29381 271 : push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
29382 1541 : if (is_stmt != table->is_stmt)
29383 573 : push_dw_line_info_entry (table, LI_negate_stmt, 0);
29384 1541 : push_dw_line_info_entry (table, LI_set_line, line);
29385 1541 : if (debug_column_info)
29386 1541 : push_dw_line_info_entry (table, LI_set_column, column);
29387 : }
29388 :
29389 35016518 : table->file_num = file_num;
29390 35016518 : table->line_num = line;
29391 35016518 : table->column_num = column;
29392 35016518 : table->discrim_num = discriminator;
29393 35016518 : table->is_stmt = is_stmt;
29394 35016518 : table->in_use = true;
29395 : }
29396 :
29397 : /* Record a source file location for a DECL_IGNORED_P function. */
29398 :
29399 : static void
29400 7918 : dwarf2out_set_ignored_loc (unsigned int line, unsigned int column,
29401 : const char *filename)
29402 : {
29403 7918 : dw_fde_ref fde = cfun->fde;
29404 :
29405 7918 : fde->ignored_debug = false;
29406 7918 : set_cur_line_info_table (current_function_section ());
29407 :
29408 7918 : dwarf2out_source_line (line, column, filename, 0, true);
29409 7918 : }
29410 :
29411 : /* Record the beginning of a new source file. */
29412 :
29413 : static void
29414 7263154 : dwarf2out_start_source_file (unsigned int lineno, const char *filename)
29415 : {
29416 : #ifdef CODEVIEW_DEBUGGING_INFO
29417 : if (codeview_debuginfo_p ())
29418 : codeview_start_source_file (filename);
29419 : #endif
29420 :
29421 7263154 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29422 : {
29423 1843 : macinfo_entry e;
29424 1843 : e.code = DW_MACINFO_start_file;
29425 1843 : e.lineno = lineno;
29426 1843 : e.info = ggc_strdup (filename);
29427 1843 : vec_safe_push (macinfo_table, e);
29428 : }
29429 7263154 : }
29430 :
29431 : /* Record the end of a source file. */
29432 :
29433 : static void
29434 7263038 : dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
29435 : {
29436 7263038 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29437 : {
29438 1843 : macinfo_entry e;
29439 1843 : e.code = DW_MACINFO_end_file;
29440 1843 : e.lineno = lineno;
29441 1843 : e.info = NULL;
29442 1843 : vec_safe_push (macinfo_table, e);
29443 : }
29444 7263038 : }
29445 :
29446 : /* Called from debug_define in toplev.cc. The `buffer' parameter contains
29447 : the tail part of the directive line, i.e. the part which is past the
29448 : initial whitespace, #, whitespace, directive-name, whitespace part. */
29449 :
29450 : static void
29451 242118 : dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
29452 : const char *buffer ATTRIBUTE_UNUSED)
29453 : {
29454 242118 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29455 : {
29456 242118 : macinfo_entry e;
29457 : /* Insert a dummy first entry to be able to optimize the whole
29458 : predefined macro block using DW_MACRO_import. */
29459 242118 : if (macinfo_table->is_empty () && lineno <= 1)
29460 : {
29461 521 : e.code = 0;
29462 521 : e.lineno = 0;
29463 521 : e.info = NULL;
29464 521 : vec_safe_push (macinfo_table, e);
29465 : }
29466 242118 : e.code = DW_MACINFO_define;
29467 242118 : e.lineno = lineno;
29468 242118 : e.info = ggc_strdup (buffer);
29469 242118 : vec_safe_push (macinfo_table, e);
29470 : }
29471 242118 : }
29472 :
29473 : /* Called from debug_undef in toplev.cc. The `buffer' parameter contains
29474 : the tail part of the directive line, i.e. the part which is past the
29475 : initial whitespace, #, whitespace, directive-name, whitespace part. */
29476 :
29477 : static void
29478 755 : dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
29479 : const char *buffer ATTRIBUTE_UNUSED)
29480 : {
29481 755 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29482 : {
29483 755 : macinfo_entry e;
29484 : /* Insert a dummy first entry to be able to optimize the whole
29485 : predefined macro block using DW_MACRO_import. */
29486 755 : if (macinfo_table->is_empty () && lineno <= 1)
29487 : {
29488 0 : e.code = 0;
29489 0 : e.lineno = 0;
29490 0 : e.info = NULL;
29491 0 : vec_safe_push (macinfo_table, e);
29492 : }
29493 755 : e.code = DW_MACINFO_undef;
29494 755 : e.lineno = lineno;
29495 755 : e.info = ggc_strdup (buffer);
29496 755 : vec_safe_push (macinfo_table, e);
29497 : }
29498 755 : }
29499 :
29500 : /* Helpers to manipulate hash table of CUs. */
29501 :
29502 : struct macinfo_entry_hasher : nofree_ptr_hash <macinfo_entry>
29503 : {
29504 : static inline hashval_t hash (const macinfo_entry *);
29505 : static inline bool equal (const macinfo_entry *, const macinfo_entry *);
29506 : };
29507 :
29508 : inline hashval_t
29509 6447 : macinfo_entry_hasher::hash (const macinfo_entry *entry)
29510 : {
29511 6447 : return htab_hash_string (entry->info);
29512 : }
29513 :
29514 : inline bool
29515 5157 : macinfo_entry_hasher::equal (const macinfo_entry *entry1,
29516 : const macinfo_entry *entry2)
29517 : {
29518 5157 : return !strcmp (entry1->info, entry2->info);
29519 : }
29520 :
29521 : typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
29522 :
29523 : /* Output a single .debug_macinfo entry. */
29524 :
29525 : static void
29526 246045 : output_macinfo_op (macinfo_entry *ref)
29527 : {
29528 486776 : int file_num;
29529 486776 : size_t len;
29530 486776 : struct indirect_string_node *node;
29531 486776 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29532 486776 : struct dwarf_file_data *fd;
29533 :
29534 486776 : switch (ref->code)
29535 : {
29536 1837 : case DW_MACINFO_start_file:
29537 1837 : fd = lookup_filename (ref->info);
29538 1837 : file_num = maybe_emit_file (fd);
29539 1837 : dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
29540 1837 : dw2_asm_output_data_uleb128 (ref->lineno,
29541 : "Included from line number "
29542 : HOST_WIDE_INT_PRINT_UNSIGNED,
29543 : ref->lineno);
29544 1837 : dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
29545 1837 : break;
29546 1837 : case DW_MACINFO_end_file:
29547 1837 : dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
29548 1837 : break;
29549 240747 : case DW_MACINFO_define:
29550 240747 : case DW_MACINFO_undef:
29551 240747 : len = strlen (ref->info) + 1;
29552 240747 : if ((!dwarf_strict || dwarf_version >= 5)
29553 240747 : && len > (size_t) dwarf_offset_size
29554 : && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29555 240731 : && (debug_str_section->common.flags & SECTION_MERGE) != 0)
29556 : {
29557 240731 : if (dwarf_split_debug_info)
29558 1671 : ref->code = ref->code == DW_MACINFO_define
29559 : ? DW_MACRO_define_strx : DW_MACRO_undef_strx;
29560 : else
29561 239638 : ref->code = ref->code == DW_MACINFO_define
29562 : ? DW_MACRO_define_strp : DW_MACRO_undef_strp;
29563 240731 : output_macinfo_op (ref);
29564 : return;
29565 : }
29566 30 : dw2_asm_output_data (1, ref->code,
29567 : ref->code == DW_MACINFO_define
29568 : ? "Define macro" : "Undefine macro");
29569 16 : dw2_asm_output_data_uleb128 (ref->lineno,
29570 : "At line number "
29571 : HOST_WIDE_INT_PRINT_UNSIGNED,
29572 : ref->lineno);
29573 16 : dw2_asm_output_nstring (ref->info, -1, "The macro");
29574 16 : break;
29575 238482 : case DW_MACRO_define_strp:
29576 238482 : dw2_asm_output_data (1, ref->code, "Define macro strp");
29577 238482 : goto do_DW_MACRO_define_strpx;
29578 578 : case DW_MACRO_undef_strp:
29579 578 : dw2_asm_output_data (1, ref->code, "Undefine macro strp");
29580 578 : goto do_DW_MACRO_define_strpx;
29581 1671 : case DW_MACRO_define_strx:
29582 1671 : dw2_asm_output_data (1, ref->code, "Define macro strx");
29583 1671 : goto do_DW_MACRO_define_strpx;
29584 0 : case DW_MACRO_undef_strx:
29585 0 : dw2_asm_output_data (1, ref->code, "Undefine macro strx");
29586 : /* FALLTHRU */
29587 240731 : do_DW_MACRO_define_strpx:
29588 : /* NB: dwarf2out_finish performs:
29589 : 1. save_macinfo_strings
29590 : 2. hash table traverse of index_string
29591 : 3. output_macinfo -> output_macinfo_op
29592 : 4. output_indirect_strings
29593 : -> hash table traverse of output_index_string
29594 :
29595 : When output_macinfo_op is called, all index strings have been
29596 : added to hash table by save_macinfo_strings and we can't pass
29597 : INSERT to find_slot_with_hash which may expand hash table, even
29598 : if no insertion is needed, and change hash table traverse order
29599 : between index_string and output_index_string. */
29600 240731 : node = find_AT_string (ref->info, NO_INSERT);
29601 241140 : gcc_assert (node
29602 : && (node->form == DW_FORM_strp
29603 : || node->form == dwarf_FORM (DW_FORM_strx)));
29604 240731 : dw2_asm_output_data_uleb128 (ref->lineno,
29605 : "At line number "
29606 : HOST_WIDE_INT_PRINT_UNSIGNED,
29607 : ref->lineno);
29608 240731 : if (node->form == DW_FORM_strp)
29609 : {
29610 239060 : gcc_assert (ref->code == DW_MACRO_define_strp
29611 : || ref->code == DW_MACRO_undef_strp);
29612 239060 : dw2_asm_output_offset (dwarf_offset_size, node->label,
29613 : debug_str_section, "The macro: \"%s\"",
29614 : ref->info);
29615 : }
29616 : else
29617 : {
29618 1671 : gcc_assert (ref->code == DW_MACRO_define_strx
29619 : || ref->code == DW_MACRO_undef_strx);
29620 1671 : dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
29621 : ref->info);
29622 : }
29623 : break;
29624 1624 : case DW_MACRO_import:
29625 1624 : dw2_asm_output_data (1, ref->code, "Import");
29626 1624 : ASM_GENERATE_INTERNAL_LABEL (label,
29627 : DEBUG_MACRO_SECTION_LABEL,
29628 : ref->lineno + macinfo_label_base);
29629 1624 : dw2_asm_output_offset (dwarf_offset_size, label, NULL, NULL);
29630 1624 : break;
29631 0 : default:
29632 0 : fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
29633 : ASM_COMMENT_START, (unsigned long) ref->code);
29634 0 : break;
29635 : }
29636 : }
29637 :
29638 : /* Attempt to make a sequence of define/undef macinfo ops shareable with
29639 : other compilation unit .debug_macinfo sections. IDX is the first
29640 : index of a define/undef, return the number of ops that should be
29641 : emitted in a comdat .debug_macinfo section and emit
29642 : a DW_MACRO_import entry referencing it.
29643 : If the define/undef entry should be emitted normally, return 0. */
29644 :
29645 : static unsigned
29646 2004 : optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
29647 : macinfo_hash_type **macinfo_htab)
29648 : {
29649 2004 : macinfo_entry *first, *second, *cur, *inc;
29650 2004 : char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
29651 2004 : unsigned char checksum[16];
29652 2004 : struct md5_ctx ctx;
29653 2004 : char *grp_name, *tail;
29654 2004 : const char *base;
29655 2004 : unsigned int i, count, encoded_filename_len, linebuf_len;
29656 2004 : macinfo_entry **slot;
29657 :
29658 2004 : first = &(*macinfo_table)[idx];
29659 2004 : second = &(*macinfo_table)[idx + 1];
29660 :
29661 : /* Optimize only if there are at least two consecutive define/undef ops,
29662 : and either all of them are before first DW_MACINFO_start_file
29663 : with lineno {0,1} (i.e. predefined macro block), or all of them are
29664 : in some included header file. */
29665 2004 : if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
29666 : return 0;
29667 1624 : if (vec_safe_is_empty (files))
29668 : {
29669 514 : if (first->lineno > 1 || second->lineno > 1)
29670 : return 0;
29671 : }
29672 1110 : else if (first->lineno == 0)
29673 : return 0;
29674 :
29675 : /* Find the last define/undef entry that can be grouped together
29676 : with first and at the same time compute md5 checksum of their
29677 : codes, linenumbers and strings. */
29678 1624 : md5_init_ctx (&ctx);
29679 240685 : for (i = idx; macinfo_table->iterate (i, &cur); i++)
29680 240685 : if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
29681 : break;
29682 239061 : else if (vec_safe_is_empty (files) && cur->lineno > 1)
29683 : break;
29684 : else
29685 : {
29686 239061 : unsigned char code = cur->code;
29687 239061 : md5_process_bytes (&code, 1, &ctx);
29688 239061 : checksum_uleb128 (cur->lineno, &ctx);
29689 239061 : md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
29690 : }
29691 1624 : md5_finish_ctx (&ctx, checksum);
29692 1624 : count = i - idx;
29693 :
29694 : /* From the containing include filename (if any) pick up just
29695 : usable characters from its basename. */
29696 1624 : if (vec_safe_is_empty (files))
29697 : base = "";
29698 : else
29699 1110 : base = lbasename (files->last ().info);
29700 14282 : for (encoded_filename_len = 0, i = 0; base[i]; i++)
29701 12658 : if (ISIDNUM (base[i]) || base[i] == '.')
29702 12034 : encoded_filename_len++;
29703 : /* Count . at the end. */
29704 1624 : if (encoded_filename_len)
29705 1110 : encoded_filename_len++;
29706 :
29707 1624 : sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
29708 1624 : linebuf_len = strlen (linebuf);
29709 :
29710 : /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
29711 1624 : grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
29712 : + 16 * 2 + 1);
29713 1624 : memcpy (grp_name, dwarf_offset_size == 4 ? "wm4." : "wm8.", 4);
29714 1624 : tail = grp_name + 4;
29715 1624 : if (encoded_filename_len)
29716 : {
29717 13768 : for (i = 0; base[i]; i++)
29718 12658 : if (ISIDNUM (base[i]) || base[i] == '.')
29719 12034 : *tail++ = base[i];
29720 1110 : *tail++ = '.';
29721 : }
29722 1624 : memcpy (tail, linebuf, linebuf_len);
29723 1624 : tail += linebuf_len;
29724 1624 : *tail++ = '.';
29725 27608 : for (i = 0; i < 16; i++)
29726 25984 : sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
29727 :
29728 : /* Construct a macinfo_entry for DW_MACRO_import
29729 : in the empty vector entry before the first define/undef. */
29730 1624 : inc = &(*macinfo_table)[idx - 1];
29731 1624 : inc->code = DW_MACRO_import;
29732 1624 : inc->lineno = 0;
29733 1624 : inc->info = ggc_strdup (grp_name);
29734 1624 : if (!*macinfo_htab)
29735 515 : *macinfo_htab = new macinfo_hash_type (10);
29736 : /* Avoid emitting duplicates. */
29737 1624 : slot = (*macinfo_htab)->find_slot (inc, INSERT);
29738 1624 : if (*slot != NULL)
29739 : {
29740 107 : inc->code = 0;
29741 107 : inc->info = NULL;
29742 : /* If such an entry has been used before, just emit
29743 : a DW_MACRO_import op. */
29744 107 : inc = *slot;
29745 107 : output_macinfo_op (inc);
29746 : /* And clear all macinfo_entry in the range to avoid emitting them
29747 : in the second pass. */
29748 660 : for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
29749 : {
29750 446 : cur->code = 0;
29751 446 : cur->info = NULL;
29752 : }
29753 : }
29754 : else
29755 : {
29756 1517 : *slot = inc;
29757 1517 : inc->lineno = (*macinfo_htab)->elements ();
29758 1517 : output_macinfo_op (inc);
29759 : }
29760 : return count;
29761 : }
29762 :
29763 : /* Save any strings needed by the macinfo table in the debug str
29764 : table. All strings must be collected into the table by the time
29765 : index_string is called. */
29766 :
29767 : static void
29768 53346 : save_macinfo_strings (void)
29769 : {
29770 53346 : unsigned len;
29771 53346 : unsigned i;
29772 53346 : macinfo_entry *ref;
29773 :
29774 298731 : for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
29775 : {
29776 245385 : switch (ref->code)
29777 : {
29778 : /* Match the logic in output_macinfo_op to decide on
29779 : indirect strings. */
29780 241193 : case DW_MACINFO_define:
29781 241193 : case DW_MACINFO_undef:
29782 241193 : len = strlen (ref->info) + 1;
29783 241193 : if ((!dwarf_strict || dwarf_version >= 5)
29784 241193 : && len > (unsigned) dwarf_offset_size
29785 : && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29786 241176 : && (debug_str_section->common.flags & SECTION_MERGE) != 0)
29787 241176 : set_indirect_string (find_AT_string (ref->info));
29788 : break;
29789 1837 : case DW_MACINFO_start_file:
29790 : /* -gsplit-dwarf -g3 will also output filename as indirect
29791 : string. */
29792 1837 : if (!dwarf_split_debug_info)
29793 : break;
29794 : /* Fall through. */
29795 8 : case DW_MACRO_define_strp:
29796 8 : case DW_MACRO_undef_strp:
29797 8 : case DW_MACRO_define_strx:
29798 8 : case DW_MACRO_undef_strx:
29799 8 : set_indirect_string (find_AT_string (ref->info));
29800 8 : break;
29801 : default:
29802 : break;
29803 : }
29804 : }
29805 53346 : }
29806 :
29807 : /* Output macinfo section(s). */
29808 :
29809 : static void
29810 527 : output_macinfo (const char *debug_line_label, bool early_lto_debug)
29811 : {
29812 527 : unsigned i;
29813 527 : unsigned long length = vec_safe_length (macinfo_table);
29814 527 : macinfo_entry *ref;
29815 527 : vec<macinfo_entry, va_gc> *files = NULL;
29816 527 : macinfo_hash_type *macinfo_htab = NULL;
29817 527 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
29818 :
29819 527 : if (! length)
29820 12 : return;
29821 :
29822 : /* output_macinfo* uses these interchangeably. */
29823 527 : gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_define
29824 : && (int) DW_MACINFO_undef == (int) DW_MACRO_undef
29825 : && (int) DW_MACINFO_start_file == (int) DW_MACRO_start_file
29826 : && (int) DW_MACINFO_end_file == (int) DW_MACRO_end_file);
29827 :
29828 : /* AIX Assembler inserts the length, so adjust the reference to match the
29829 : offset expected by debuggers. */
29830 527 : strcpy (dl_section_ref, debug_line_label);
29831 527 : if (XCOFF_DEBUGGING_INFO)
29832 : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
29833 :
29834 : /* For .debug_macro emit the section header. */
29835 527 : if (!dwarf_strict || dwarf_version >= 5)
29836 : {
29837 1032 : dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
29838 : "DWARF macro version number");
29839 527 : if (dwarf_offset_size == 8)
29840 0 : dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
29841 : else
29842 527 : dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
29843 527 : dw2_asm_output_offset (dwarf_offset_size, debug_line_label,
29844 : debug_line_section, NULL);
29845 : }
29846 :
29847 : /* In the first loop, it emits the primary .debug_macinfo section
29848 : and after each emitted op the macinfo_entry is cleared.
29849 : If a longer range of define/undef ops can be optimized using
29850 : DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
29851 : the vector before the first define/undef in the range and the
29852 : whole range of define/undef ops is not emitted and kept. */
29853 8475 : for (i = 0; macinfo_table->iterate (i, &ref); i++)
29854 : {
29855 7948 : switch (ref->code)
29856 : {
29857 1837 : case DW_MACINFO_start_file:
29858 1837 : vec_safe_push (files, *ref);
29859 1837 : break;
29860 1837 : case DW_MACINFO_end_file:
29861 1837 : if (!vec_safe_is_empty (files))
29862 1837 : files->pop ();
29863 : break;
29864 3756 : case DW_MACINFO_define:
29865 3756 : case DW_MACINFO_undef:
29866 0 : if ((!dwarf_strict || dwarf_version >= 5)
29867 3756 : && !dwarf_split_debug_info
29868 : && HAVE_COMDAT_GROUP
29869 2085 : && vec_safe_length (files) != 1
29870 2004 : && i > 0
29871 2004 : && i + 1 < length
29872 5760 : && (*macinfo_table)[i - 1].code == 0)
29873 : {
29874 2004 : unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
29875 2004 : if (count)
29876 : {
29877 1624 : i += count - 1;
29878 1624 : continue;
29879 : }
29880 : }
29881 : break;
29882 518 : case 0:
29883 : /* A dummy entry may be inserted at the beginning to be able
29884 : to optimize the whole block of predefined macros. */
29885 518 : if (i == 0)
29886 518 : continue;
29887 : default:
29888 : break;
29889 : }
29890 5806 : output_macinfo_op (ref);
29891 5806 : ref->info = NULL;
29892 5806 : ref->code = 0;
29893 : }
29894 :
29895 527 : if (!macinfo_htab)
29896 : return;
29897 :
29898 : /* Save the number of transparent includes so we can adjust the
29899 : label number for the fat LTO object DWARF. */
29900 515 : unsigned macinfo_label_base_adj = macinfo_htab->elements ();
29901 :
29902 515 : delete macinfo_htab;
29903 515 : macinfo_htab = NULL;
29904 :
29905 : /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
29906 : terminate the current chain and switch to a new comdat .debug_macinfo
29907 : section and emit the define/undef entries within it. */
29908 244161 : for (i = 0; macinfo_table->iterate (i, &ref); i++)
29909 243646 : switch (ref->code)
29910 : {
29911 3514 : case 0:
29912 3514 : continue;
29913 1517 : case DW_MACRO_import:
29914 1517 : {
29915 1517 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29916 1517 : tree comdat_key = get_identifier (ref->info);
29917 : /* Terminate the previous .debug_macinfo section. */
29918 1517 : dw2_asm_output_data (1, 0, "End compilation unit");
29919 3004 : targetm.asm_out.named_section (debug_macinfo_section_name,
29920 : SECTION_DEBUG
29921 : | SECTION_LINKONCE
29922 : | (early_lto_debug
29923 : ? SECTION_EXCLUDE : 0),
29924 : comdat_key);
29925 1517 : ASM_GENERATE_INTERNAL_LABEL (label,
29926 : DEBUG_MACRO_SECTION_LABEL,
29927 : ref->lineno + macinfo_label_base);
29928 1517 : ASM_OUTPUT_LABEL (asm_out_file, label);
29929 1517 : ref->code = 0;
29930 1517 : ref->info = NULL;
29931 2515 : dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
29932 : "DWARF macro version number");
29933 1517 : if (dwarf_offset_size == 8)
29934 0 : dw2_asm_output_data (1, 1, "Flags: 64-bit");
29935 : else
29936 1517 : dw2_asm_output_data (1, 0, "Flags: 32-bit");
29937 : }
29938 1517 : break;
29939 238615 : case DW_MACINFO_define:
29940 238615 : case DW_MACINFO_undef:
29941 238615 : output_macinfo_op (ref);
29942 238615 : ref->code = 0;
29943 238615 : ref->info = NULL;
29944 238615 : break;
29945 0 : default:
29946 0 : gcc_unreachable ();
29947 3514 : }
29948 :
29949 515 : macinfo_label_base += macinfo_label_base_adj;
29950 : }
29951 :
29952 : /* As init_sections_and_labels may get called multiple times, have a
29953 : generation count for labels. */
29954 : static unsigned init_sections_and_labels_generation;
29955 :
29956 : /* Initialize the various sections and labels for dwarf output and prefix
29957 : them with PREFIX if non-NULL. Returns the generation (zero based
29958 : number of times function was called). */
29959 :
29960 : static unsigned
29961 53346 : init_sections_and_labels (bool early_lto_debug)
29962 : {
29963 53346 : if (early_lto_debug)
29964 : {
29965 1311 : if (!dwarf_split_debug_info)
29966 : {
29967 1311 : debug_info_section = get_section (DEBUG_LTO_INFO_SECTION,
29968 : SECTION_DEBUG | SECTION_EXCLUDE,
29969 : NULL);
29970 1311 : debug_abbrev_section = get_section (DEBUG_LTO_ABBREV_SECTION,
29971 : SECTION_DEBUG | SECTION_EXCLUDE,
29972 : NULL);
29973 1311 : debug_macinfo_section_name
29974 0 : = ((dwarf_strict && dwarf_version < 5)
29975 1311 : ? DEBUG_LTO_MACINFO_SECTION : DEBUG_LTO_MACRO_SECTION);
29976 1311 : debug_macinfo_section = get_section (debug_macinfo_section_name,
29977 : SECTION_DEBUG
29978 : | SECTION_EXCLUDE, NULL);
29979 : }
29980 : else
29981 : {
29982 : /* ??? Which of the following do we need early? */
29983 0 : debug_info_section = get_section (DEBUG_LTO_DWO_INFO_SECTION,
29984 : SECTION_DEBUG | SECTION_EXCLUDE,
29985 : NULL);
29986 0 : debug_abbrev_section = get_section (DEBUG_LTO_DWO_ABBREV_SECTION,
29987 : SECTION_DEBUG | SECTION_EXCLUDE,
29988 : NULL);
29989 0 : debug_skeleton_info_section = get_section (DEBUG_LTO_INFO_SECTION,
29990 : SECTION_DEBUG
29991 : | SECTION_EXCLUDE, NULL);
29992 0 : debug_skeleton_abbrev_section
29993 0 : = get_section (DEBUG_LTO_ABBREV_SECTION,
29994 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29995 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
29996 : DEBUG_SKELETON_ABBREV_SECTION_LABEL,
29997 : init_sections_and_labels_generation);
29998 :
29999 : /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
30000 : stay in the main .o, but the skeleton_line goes into the split
30001 : off dwo. */
30002 0 : debug_skeleton_line_section
30003 0 : = get_section (DEBUG_LTO_LINE_SECTION,
30004 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30005 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
30006 : DEBUG_SKELETON_LINE_SECTION_LABEL,
30007 : init_sections_and_labels_generation);
30008 0 : debug_str_offsets_section
30009 0 : = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION,
30010 : SECTION_DEBUG | SECTION_EXCLUDE,
30011 : NULL);
30012 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
30013 : DEBUG_SKELETON_INFO_SECTION_LABEL,
30014 : init_sections_and_labels_generation);
30015 0 : debug_str_dwo_section = get_section (DEBUG_LTO_STR_DWO_SECTION,
30016 : DEBUG_STR_DWO_SECTION_FLAGS,
30017 : NULL);
30018 0 : debug_macinfo_section_name
30019 0 : = ((dwarf_strict && dwarf_version < 5)
30020 0 : ? DEBUG_LTO_DWO_MACINFO_SECTION : DEBUG_LTO_DWO_MACRO_SECTION);
30021 0 : debug_macinfo_section = get_section (debug_macinfo_section_name,
30022 : SECTION_DEBUG | SECTION_EXCLUDE,
30023 : NULL);
30024 : }
30025 : /* For macro info and the file table we have to refer to a
30026 : debug_line section. */
30027 1311 : debug_line_section = get_section (DEBUG_LTO_LINE_SECTION,
30028 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30029 1311 : ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
30030 : DEBUG_LINE_SECTION_LABEL,
30031 : init_sections_and_labels_generation);
30032 :
30033 1311 : debug_str_section = get_section (DEBUG_LTO_STR_SECTION,
30034 1311 : DEBUG_STR_SECTION_FLAGS
30035 : | SECTION_EXCLUDE, NULL);
30036 1311 : if (!dwarf_split_debug_info)
30037 1311 : debug_line_str_section
30038 1311 : = get_section (DEBUG_LTO_LINE_STR_SECTION,
30039 1311 : DEBUG_STR_SECTION_FLAGS | SECTION_EXCLUDE, NULL);
30040 : }
30041 : else
30042 : {
30043 52035 : if (!dwarf_split_debug_info)
30044 : {
30045 51786 : debug_info_section = get_section (DEBUG_INFO_SECTION,
30046 : SECTION_DEBUG, NULL);
30047 51786 : debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
30048 : SECTION_DEBUG, NULL);
30049 53748 : debug_loc_section = get_section (dwarf_version >= 5
30050 : ? DEBUG_LOCLISTS_SECTION
30051 : : DEBUG_LOC_SECTION,
30052 : SECTION_DEBUG, NULL);
30053 51786 : debug_macinfo_section_name
30054 5 : = ((dwarf_strict && dwarf_version < 5)
30055 51786 : ? DEBUG_MACINFO_SECTION : DEBUG_MACRO_SECTION);
30056 51786 : debug_macinfo_section = get_section (debug_macinfo_section_name,
30057 : SECTION_DEBUG, NULL);
30058 : }
30059 : else
30060 : {
30061 249 : debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
30062 : SECTION_DEBUG | SECTION_EXCLUDE,
30063 : NULL);
30064 249 : debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
30065 : SECTION_DEBUG | SECTION_EXCLUDE,
30066 : NULL);
30067 249 : debug_addr_section = get_section (DEBUG_ADDR_SECTION,
30068 : SECTION_DEBUG, NULL);
30069 249 : debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
30070 : SECTION_DEBUG, NULL);
30071 249 : debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
30072 : SECTION_DEBUG, NULL);
30073 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
30074 : DEBUG_SKELETON_ABBREV_SECTION_LABEL,
30075 : init_sections_and_labels_generation);
30076 :
30077 : /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
30078 : stay in the main .o, but the skeleton_line goes into the
30079 : split off dwo. */
30080 249 : debug_skeleton_line_section
30081 249 : = get_section (DEBUG_DWO_LINE_SECTION,
30082 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30083 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
30084 : DEBUG_SKELETON_LINE_SECTION_LABEL,
30085 : init_sections_and_labels_generation);
30086 249 : debug_str_offsets_section
30087 249 : = get_section (DEBUG_DWO_STR_OFFSETS_SECTION,
30088 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30089 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
30090 : DEBUG_SKELETON_INFO_SECTION_LABEL,
30091 : init_sections_and_labels_generation);
30092 250 : debug_loc_section = get_section (dwarf_version >= 5
30093 : ? DEBUG_DWO_LOCLISTS_SECTION
30094 : : DEBUG_DWO_LOC_SECTION,
30095 : SECTION_DEBUG | SECTION_EXCLUDE,
30096 : NULL);
30097 249 : debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
30098 : DEBUG_STR_DWO_SECTION_FLAGS,
30099 : NULL);
30100 249 : debug_macinfo_section_name
30101 0 : = ((dwarf_strict && dwarf_version < 5)
30102 249 : ? DEBUG_DWO_MACINFO_SECTION : DEBUG_DWO_MACRO_SECTION);
30103 249 : debug_macinfo_section = get_section (debug_macinfo_section_name,
30104 : SECTION_DEBUG | SECTION_EXCLUDE,
30105 : NULL);
30106 249 : if (dwarf_version >= 5)
30107 248 : debug_ranges_dwo_section
30108 248 : = get_section (DEBUG_DWO_RNGLISTS_SECTION,
30109 : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
30110 : }
30111 52035 : debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
30112 : SECTION_DEBUG, NULL);
30113 52035 : debug_line_section = get_section (DEBUG_LINE_SECTION,
30114 : SECTION_DEBUG, NULL);
30115 103821 : debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
30116 : SECTION_DEBUG, NULL);
30117 103821 : debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
30118 : SECTION_DEBUG, NULL);
30119 52035 : debug_str_section = get_section (DEBUG_STR_SECTION,
30120 52035 : DEBUG_STR_SECTION_FLAGS, NULL);
30121 51786 : if ((!dwarf_split_debug_info && !output_asm_line_debug_info ())
30122 103815 : || asm_outputs_debug_line_str ())
30123 49827 : debug_line_str_section = get_section (DEBUG_LINE_STR_SECTION,
30124 49827 : DEBUG_STR_SECTION_FLAGS, NULL);
30125 :
30126 53998 : debug_ranges_section = get_section (dwarf_version >= 5
30127 : ? DEBUG_RNGLISTS_SECTION
30128 : : DEBUG_RANGES_SECTION,
30129 : SECTION_DEBUG, NULL);
30130 52035 : debug_frame_section = get_section (DEBUG_FRAME_SECTION,
30131 : SECTION_DEBUG, NULL);
30132 : }
30133 :
30134 53346 : ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
30135 : DEBUG_ABBREV_SECTION_LABEL,
30136 : init_sections_and_labels_generation);
30137 53346 : ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
30138 : DEBUG_INFO_SECTION_LABEL,
30139 : init_sections_and_labels_generation);
30140 53346 : info_section_emitted = false;
30141 53346 : ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
30142 : DEBUG_LINE_SECTION_LABEL,
30143 : init_sections_and_labels_generation);
30144 : /* There are up to 6 unique ranges labels per generation.
30145 : See also output_rnglists. */
30146 53346 : ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
30147 : DEBUG_RANGES_SECTION_LABEL,
30148 : init_sections_and_labels_generation * 6);
30149 53346 : if (dwarf_version >= 5 && dwarf_split_debug_info)
30150 248 : ASM_GENERATE_INTERNAL_LABEL (ranges_base_label,
30151 : DEBUG_RANGES_SECTION_LABEL,
30152 : 1 + init_sections_and_labels_generation * 6);
30153 53346 : ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
30154 : DEBUG_ADDR_SECTION_LABEL,
30155 : init_sections_and_labels_generation);
30156 106687 : ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
30157 : (dwarf_strict && dwarf_version < 5)
30158 : ? DEBUG_MACINFO_SECTION_LABEL
30159 : : DEBUG_MACRO_SECTION_LABEL,
30160 : init_sections_and_labels_generation);
30161 53346 : ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL,
30162 : init_sections_and_labels_generation);
30163 :
30164 53346 : ++init_sections_and_labels_generation;
30165 53346 : return init_sections_and_labels_generation - 1;
30166 : }
30167 :
30168 : /* Set up for Dwarf output at the start of compilation. */
30169 :
30170 : static void
30171 55397 : dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
30172 : {
30173 : /* Allocate the file_table. */
30174 55397 : file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
30175 :
30176 : #ifndef DWARF2_LINENO_DEBUGGING_INFO
30177 : /* Allocate the decl_die_table. */
30178 55397 : decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
30179 :
30180 : /* Allocate the decl_loc_table. */
30181 55397 : decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
30182 :
30183 : /* Allocate the cached_dw_loc_list_table. */
30184 55397 : cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
30185 :
30186 : /* Allocate the initial hunk of the abbrev_die_table. */
30187 55397 : vec_alloc (abbrev_die_table, 256);
30188 : /* Zero-th entry is allocated, but unused. */
30189 55397 : abbrev_die_table->quick_push (NULL);
30190 :
30191 : /* Allocate the dwarf_proc_stack_usage_map. */
30192 55397 : dwarf_proc_stack_usage_map = new hash_map<dw_die_ref, int>;
30193 :
30194 : /* Allocate the pubtypes and pubnames vectors. */
30195 55397 : vec_alloc (pubname_table, 32);
30196 55397 : vec_alloc (pubtype_table, 32);
30197 :
30198 55397 : vec_alloc (incomplete_types, 64);
30199 :
30200 55397 : vec_alloc (used_rtx_array, 32);
30201 :
30202 55397 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
30203 533 : vec_alloc (macinfo_table, 64);
30204 : #endif
30205 :
30206 : /* If front-ends already registered a main translation unit but we were not
30207 : ready to perform the association, do this now. */
30208 55397 : if (main_translation_unit != NULL_TREE)
30209 17511 : equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
30210 55397 : }
30211 :
30212 : /* Called before compile () starts outputtting functions, variables
30213 : and toplevel asms into assembly. */
30214 :
30215 : static void
30216 52357 : dwarf2out_assembly_start (void)
30217 : {
30218 52357 : if (text_section_line_info)
30219 : return;
30220 :
30221 : #ifndef DWARF2_LINENO_DEBUGGING_INFO
30222 52356 : ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
30223 52356 : ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
30224 52356 : ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
30225 : COLD_TEXT_SECTION_LABEL, 0);
30226 52356 : ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
30227 :
30228 52356 : switch_to_section (text_section);
30229 52356 : ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
30230 : #endif
30231 :
30232 : /* Make sure the line number table for .text always exists. */
30233 52356 : text_section_line_info = new_line_info_table ();
30234 52356 : text_section_line_info->end_label = text_end_label;
30235 :
30236 : #ifdef DWARF2_LINENO_DEBUGGING_INFO
30237 : cur_line_info_table = text_section_line_info;
30238 : #endif
30239 :
30240 52356 : if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
30241 52356 : && dwarf2out_do_cfi_asm ()
30242 52356 : && !dwarf2out_do_eh_frame ())
30243 5 : fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
30244 :
30245 : #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
30246 52356 : if (output_asm_line_debug_info () && dwarf_version >= 5)
30247 : {
30248 : /* When gas outputs DWARF5 .debug_line[_str] then we have to
30249 : tell it the comp_dir and main file name for the zero entry
30250 : line table. */
30251 50390 : const char *comp_dir, *filename0;
30252 :
30253 50390 : comp_dir = comp_dir_string ();
30254 50390 : if (comp_dir == NULL)
30255 0 : comp_dir = "";
30256 :
30257 50390 : filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
30258 50390 : if (filename0 == NULL)
30259 1 : filename0 = "";
30260 :
30261 50390 : fprintf (asm_out_file, "\t.file 0 ");
30262 50390 : output_quoted_string (asm_out_file, remap_debug_filename (comp_dir));
30263 50390 : fputc (' ', asm_out_file);
30264 50390 : output_quoted_string (asm_out_file, remap_debug_filename (filename0));
30265 50390 : fputc ('\n', asm_out_file);
30266 : }
30267 : else
30268 : #endif
30269 : /* Work around for PR101575: output a dummy .file directive. */
30270 1956 : if (!last_emitted_file && dwarf_debuginfo_p ()
30271 3922 : && debug_info_level >= DINFO_LEVEL_TERSE)
30272 : {
30273 1956 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
30274 :
30275 1956 : if (filename0 == NULL)
30276 0 : filename0 = "<dummy>";
30277 1956 : maybe_emit_file (lookup_filename (filename0));
30278 : }
30279 : }
30280 :
30281 : /* A helper function for dwarf2out_finish called through
30282 : htab_traverse. Assign a string its index. All strings must be
30283 : collected into the table by the time index_string is called,
30284 : because the indexing code relies on htab_traverse to traverse nodes
30285 : in the same order for each run. */
30286 :
30287 : int
30288 2927 : index_string (indirect_string_node **h, unsigned int *index)
30289 : {
30290 2927 : indirect_string_node *node = *h;
30291 :
30292 2927 : find_string_form (node);
30293 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30294 : {
30295 2610 : gcc_assert (node->index == NO_INDEX_ASSIGNED);
30296 2610 : node->index = *index;
30297 2610 : *index += 1;
30298 : }
30299 2927 : return 1;
30300 : }
30301 :
30302 : /* A helper function for output_indirect_strings called through
30303 : htab_traverse. Output the offset to a string and update the
30304 : current offset. */
30305 :
30306 : int
30307 2927 : output_index_string_offset (indirect_string_node **h, unsigned int *offset)
30308 : {
30309 2927 : indirect_string_node *node = *h;
30310 :
30311 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30312 : {
30313 : /* Assert that this node has been assigned an index. */
30314 2610 : gcc_assert (node->index != NO_INDEX_ASSIGNED
30315 : && node->index != NOT_INDEXED);
30316 2610 : dw2_asm_output_data (dwarf_offset_size, *offset,
30317 : "indexed string 0x%x: %s", node->index, node->str);
30318 2610 : *offset += strlen (node->str) + 1;
30319 : }
30320 2927 : return 1;
30321 : }
30322 :
30323 : /* A helper function for dwarf2out_finish called through
30324 : htab_traverse. Output the indexed string. */
30325 :
30326 : int
30327 2927 : output_index_string (indirect_string_node **h, unsigned int *cur_idx)
30328 : {
30329 2927 : struct indirect_string_node *node = *h;
30330 :
30331 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30332 : {
30333 : /* Assert that the strings are output in the same order as their
30334 : indexes were assigned. */
30335 2610 : gcc_assert (*cur_idx == node->index);
30336 2610 : assemble_string (node->str, strlen (node->str) + 1);
30337 2610 : *cur_idx += 1;
30338 : }
30339 2927 : return 1;
30340 : }
30341 :
30342 : /* A helper function for output_indirect_strings. Counts the number
30343 : of index strings offsets. Must match the logic of the functions
30344 : output_index_string[_offsets] above. */
30345 : int
30346 2514 : count_index_strings (indirect_string_node **h, unsigned int *last_idx)
30347 : {
30348 2514 : struct indirect_string_node *node = *h;
30349 :
30350 2514 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30351 2197 : *last_idx += 1;
30352 2514 : return 1;
30353 : }
30354 :
30355 : /* A helper function for dwarf2out_finish called through
30356 : htab_traverse. Emit one queued .debug_str string. */
30357 :
30358 : int
30359 20331442 : output_indirect_string (indirect_string_node **h, enum dwarf_form form)
30360 : {
30361 20331442 : struct indirect_string_node *node = *h;
30362 :
30363 20331442 : node->form = find_string_form (node);
30364 20331442 : if (node->form == form && node->refcount > 0)
30365 : {
30366 19633531 : ASM_OUTPUT_LABEL (asm_out_file, node->label);
30367 19633531 : assemble_string (node->str, strlen (node->str) + 1);
30368 : }
30369 :
30370 20331442 : return 1;
30371 : }
30372 :
30373 : /* Output the indexed string table. */
30374 :
30375 : static void
30376 53346 : output_indirect_strings (void)
30377 : {
30378 53346 : switch_to_section (debug_str_section);
30379 53346 : if (!dwarf_split_debug_info)
30380 53097 : debug_str_hash->traverse<enum dwarf_form,
30381 20384539 : output_indirect_string> (DW_FORM_strp);
30382 : else
30383 : {
30384 249 : unsigned int offset = 0;
30385 249 : unsigned int cur_idx = 0;
30386 :
30387 249 : if (skeleton_debug_str_hash)
30388 249 : skeleton_debug_str_hash->traverse<enum dwarf_form,
30389 249 : output_indirect_string> (DW_FORM_strp);
30390 :
30391 249 : switch_to_section (debug_str_offsets_section);
30392 : /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
30393 : header. Note that we don't need to generate a label to the
30394 : actual index table following the header here, because this is
30395 : for the split dwarf case only. In an .dwo file there is only
30396 : one string offsets table (and one debug info section). But
30397 : if we would start using string offset tables for the main (or
30398 : skeleton) unit, then we have to add a DW_AT_str_offsets_base
30399 : pointing to the actual index after the header. Split dwarf
30400 : units will never have a string offsets base attribute. When
30401 : a split unit is moved into a .dwp file the string offsets can
30402 : be found through the .debug_cu_index section table. */
30403 249 : if (dwarf_version >= 5)
30404 : {
30405 248 : unsigned int last_idx = 0;
30406 248 : unsigned long str_offsets_length;
30407 :
30408 248 : debug_str_hash->traverse_noresize
30409 2762 : <unsigned int *, count_index_strings> (&last_idx);
30410 248 : str_offsets_length = last_idx * dwarf_offset_size + 4;
30411 248 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
30412 0 : dw2_asm_output_data (4, 0xffffffff,
30413 : "Escape value for 64-bit DWARF extension");
30414 248 : dw2_asm_output_data (dwarf_offset_size, str_offsets_length,
30415 : "Length of string offsets unit");
30416 248 : dw2_asm_output_data (2, 5, "DWARF string offsets version");
30417 248 : dw2_asm_output_data (2, 0, "Header zero padding");
30418 : }
30419 249 : debug_str_hash->traverse_noresize
30420 3176 : <unsigned int *, output_index_string_offset> (&offset);
30421 249 : switch_to_section (debug_str_dwo_section);
30422 249 : debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
30423 3176 : (&cur_idx);
30424 : }
30425 53346 : }
30426 :
30427 : /* Callback for htab_traverse to assign an index to an entry in the
30428 : table, and to write that entry to the .debug_addr section. */
30429 :
30430 : int
30431 264 : output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
30432 : {
30433 264 : addr_table_entry *entry = *slot;
30434 :
30435 264 : if (entry->refcount == 0)
30436 : {
30437 0 : gcc_assert (entry->index == NO_INDEX_ASSIGNED
30438 : || entry->index == NOT_INDEXED);
30439 : return 1;
30440 : }
30441 :
30442 264 : gcc_assert (entry->index == *cur_index);
30443 264 : (*cur_index)++;
30444 :
30445 264 : switch (entry->kind)
30446 : {
30447 3 : case ate_kind_rtx:
30448 3 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
30449 : "0x%x", entry->index);
30450 3 : break;
30451 0 : case ate_kind_rtx_dtprel:
30452 0 : gcc_assert (targetm.asm_out.output_dwarf_dtprel);
30453 0 : targetm.asm_out.output_dwarf_dtprel (asm_out_file,
30454 0 : DWARF2_ADDR_SIZE,
30455 : entry->addr.rtl);
30456 0 : fputc ('\n', asm_out_file);
30457 0 : break;
30458 261 : case ate_kind_label:
30459 261 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
30460 : "0x%x", entry->index);
30461 261 : break;
30462 0 : default:
30463 0 : gcc_unreachable ();
30464 : }
30465 : return 1;
30466 : }
30467 :
30468 : /* A helper function for dwarf2out_finish. Counts the number
30469 : of indexed addresses. Must match the logic of the functions
30470 : output_addr_table_entry above. */
30471 : int
30472 264 : count_index_addrs (addr_table_entry **slot, unsigned int *last_idx)
30473 : {
30474 264 : addr_table_entry *entry = *slot;
30475 :
30476 264 : if (entry->refcount > 0)
30477 264 : *last_idx += 1;
30478 264 : return 1;
30479 : }
30480 :
30481 : /* Produce the .debug_addr section. */
30482 :
30483 : static void
30484 249 : output_addr_table (void)
30485 : {
30486 249 : unsigned int index = 0;
30487 249 : if (addr_index_table == NULL || addr_index_table->size () == 0)
30488 5 : return;
30489 :
30490 244 : switch_to_section (debug_addr_section);
30491 : /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
30492 : which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
30493 : before DWARF5, didn't have a header for .debug_addr units.
30494 : DWARF5 specifies a small header when address tables are used. */
30495 244 : if (dwarf_version >= 5)
30496 : {
30497 244 : unsigned int last_idx = 0;
30498 244 : unsigned long addrs_length;
30499 :
30500 244 : addr_index_table->traverse_noresize
30501 508 : <unsigned int *, count_index_addrs> (&last_idx);
30502 244 : addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
30503 :
30504 244 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
30505 0 : dw2_asm_output_data (4, 0xffffffff,
30506 : "Escape value for 64-bit DWARF extension");
30507 244 : dw2_asm_output_data (dwarf_offset_size, addrs_length,
30508 : "Length of Address Unit");
30509 244 : dw2_asm_output_data (2, 5, "DWARF addr version");
30510 244 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
30511 244 : dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
30512 : }
30513 244 : ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
30514 :
30515 244 : addr_index_table
30516 508 : ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
30517 : }
30518 :
30519 : #if ENABLE_ASSERT_CHECKING
30520 : /* Verify that all marks are clear. */
30521 :
30522 : static void
30523 609885084 : verify_marks_clear (dw_die_ref die)
30524 : {
30525 609885084 : dw_die_ref c;
30526 :
30527 609885084 : gcc_assert (! die->die_mark);
30528 1074049605 : FOR_EACH_CHILD (die, c, verify_marks_clear (c));
30529 609885084 : }
30530 : #endif /* ENABLE_ASSERT_CHECKING */
30531 :
30532 : /* Clear the marks for a die and its children.
30533 : Be cool if the mark isn't set. */
30534 :
30535 : static void
30536 52795146 : prune_unmark_dies (dw_die_ref die)
30537 : {
30538 52795146 : dw_die_ref c;
30539 :
30540 52795146 : if (die->die_mark)
30541 52795146 : die->die_mark = 0;
30542 105537795 : FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
30543 52795146 : }
30544 :
30545 : /* Given LOC that is referenced by a DIE we're marking as used, find all
30546 : referenced DWARF procedures it references and mark them as used. */
30547 :
30548 : static void
30549 119448 : prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc)
30550 : {
30551 354328 : for (; loc != NULL; loc = loc->dw_loc_next)
30552 234880 : switch (loc->dw_loc_opc)
30553 : {
30554 0 : case DW_OP_implicit_pointer:
30555 0 : case DW_OP_convert:
30556 0 : case DW_OP_reinterpret:
30557 0 : case DW_OP_GNU_implicit_pointer:
30558 0 : case DW_OP_GNU_convert:
30559 0 : case DW_OP_GNU_reinterpret:
30560 0 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref)
30561 0 : prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
30562 : break;
30563 5195 : case DW_OP_GNU_variable_value:
30564 5195 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
30565 : {
30566 2254 : dw_die_ref ref
30567 2254 : = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
30568 2254 : if (ref == NULL)
30569 : break;
30570 1445 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
30571 1445 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
30572 1445 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
30573 : }
30574 : /* FALLTHRU */
30575 4388 : case DW_OP_call2:
30576 4388 : case DW_OP_call4:
30577 4388 : case DW_OP_call_ref:
30578 4388 : case DW_OP_const_type:
30579 4388 : case DW_OP_GNU_const_type:
30580 4388 : case DW_OP_GNU_parameter_ref:
30581 4388 : gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref);
30582 4388 : prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
30583 4388 : break;
30584 0 : case DW_OP_regval_type:
30585 0 : case DW_OP_deref_type:
30586 0 : case DW_OP_GNU_regval_type:
30587 0 : case DW_OP_GNU_deref_type:
30588 0 : gcc_assert (loc->dw_loc_oprnd2.val_class == dw_val_class_die_ref);
30589 0 : prune_unused_types_mark (loc->dw_loc_oprnd2.v.val_die_ref.die, 1);
30590 0 : break;
30591 0 : case DW_OP_entry_value:
30592 0 : case DW_OP_GNU_entry_value:
30593 0 : gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_loc);
30594 0 : prune_unused_types_walk_loc_descr (loc->dw_loc_oprnd1.v.val_loc);
30595 0 : break;
30596 : default:
30597 : break;
30598 : }
30599 119448 : }
30600 :
30601 : /* Given DIE that we're marking as used, find any other dies
30602 : it references as attributes and mark them as used. */
30603 :
30604 : static void
30605 52795146 : prune_unused_types_walk_attribs (dw_die_ref die)
30606 : {
30607 52795146 : dw_attr_node *a;
30608 52795146 : unsigned ix;
30609 :
30610 243219943 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
30611 : {
30612 190424797 : switch (AT_class (a))
30613 : {
30614 : /* Make sure DWARF procedures referenced by location descriptions will
30615 : get emitted. */
30616 119448 : case dw_val_class_loc:
30617 119448 : prune_unused_types_walk_loc_descr (AT_loc (a));
30618 119448 : break;
30619 0 : case dw_val_class_loc_list:
30620 0 : for (dw_loc_list_ref list = AT_loc_list (a);
30621 0 : list != NULL;
30622 0 : list = list->dw_loc_next)
30623 0 : prune_unused_types_walk_loc_descr (list->expr);
30624 : break;
30625 :
30626 : case dw_val_class_view_list:
30627 : /* This points to a loc_list in another attribute, so it's
30628 : already covered. */
30629 : break;
30630 :
30631 52089915 : case dw_val_class_die_ref:
30632 : /* A reference to another DIE.
30633 : Make sure that it will get emitted.
30634 : If it was broken out into a comdat group, don't follow it. */
30635 52089915 : if (! AT_ref (a)->comdat_type_p
30636 52089915 : || a->dw_attr == DW_AT_specification)
30637 52089658 : prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
30638 : break;
30639 :
30640 32163275 : case dw_val_class_str:
30641 : /* Set the string's refcount to 0 so that prune_unused_types_mark
30642 : accounts properly for it. */
30643 32163275 : a->dw_attr_val.v.val_str->refcount = 0;
30644 32163275 : break;
30645 :
30646 : default:
30647 : break;
30648 : }
30649 : }
30650 52795146 : }
30651 :
30652 : /* Mark the generic parameters and arguments children DIEs of DIE. */
30653 :
30654 : static void
30655 16848636 : prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
30656 : {
30657 16848636 : dw_die_ref c;
30658 :
30659 16848636 : if (die == NULL || die->die_child == NULL)
30660 : return;
30661 : c = die->die_child;
30662 19398716 : do
30663 : {
30664 19398716 : if (is_template_parameter (c))
30665 805723 : prune_unused_types_mark (c, 1);
30666 19398716 : c = c->die_sib;
30667 19398716 : } while (c && c != die->die_child);
30668 : }
30669 :
30670 : /* Mark DIE as being used. If DOKIDS is true, then walk down
30671 : to DIE's children. */
30672 :
30673 : static void
30674 70025304 : prune_unused_types_mark (dw_die_ref die, int dokids)
30675 : {
30676 70025304 : dw_die_ref c;
30677 :
30678 70025304 : if (die->die_mark == 0)
30679 : {
30680 : /* We haven't done this node yet. Mark it as used. */
30681 16848636 : die->die_mark = 1;
30682 : /* If this is the DIE of a generic type instantiation,
30683 : mark the children DIEs that describe its generic parms and
30684 : args. */
30685 16848636 : prune_unused_types_mark_generic_parms_dies (die);
30686 :
30687 : /* We also have to mark its parents as used.
30688 : (But we don't want to mark our parent's kids due to this,
30689 : unless it is a class.) */
30690 16848636 : if (die->die_parent)
30691 16848636 : prune_unused_types_mark (die->die_parent,
30692 16848636 : class_scope_p (die->die_parent));
30693 :
30694 : /* Mark any referenced nodes. */
30695 16848636 : prune_unused_types_walk_attribs (die);
30696 :
30697 : /* If this node is a specification,
30698 : also mark the definition, if it exists. */
30699 16848636 : if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
30700 96929 : prune_unused_types_mark (die->die_definition, 1);
30701 : }
30702 :
30703 70025304 : if (dokids && die->die_mark != 2)
30704 : {
30705 : /* We need to walk the children, but haven't done so yet.
30706 : Remember that we've walked the kids. */
30707 16326365 : die->die_mark = 2;
30708 :
30709 : /* If this is an array type, we need to make sure our
30710 : kids get marked, even if they're types. If we're
30711 : breaking out types into comdat sections, do this
30712 : for all type definitions. */
30713 16326365 : if (die->die_tag == DW_TAG_array_type
30714 16326365 : || (use_debug_types
30715 1492 : && is_type_die (die) && ! is_declaration_die (die)))
30716 164298 : FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
30717 : else
30718 29773349 : FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
30719 : }
30720 70025304 : }
30721 :
30722 : /* For local classes, look if any static member functions were emitted
30723 : and if so, mark them. */
30724 :
30725 : static void
30726 116166 : prune_unused_types_walk_local_classes (dw_die_ref die)
30727 : {
30728 116166 : dw_die_ref c;
30729 :
30730 116166 : if (die->die_mark == 2)
30731 : return;
30732 :
30733 92388 : switch (die->die_tag)
30734 : {
30735 16988 : case DW_TAG_structure_type:
30736 16988 : case DW_TAG_union_type:
30737 16988 : case DW_TAG_class_type:
30738 16988 : case DW_TAG_interface_type:
30739 16988 : break;
30740 :
30741 56612 : case DW_TAG_subprogram:
30742 56612 : if (!get_AT_flag (die, DW_AT_declaration)
30743 56612 : || die->die_definition != NULL)
30744 15224 : prune_unused_types_mark (die, 1);
30745 : return;
30746 :
30747 : default:
30748 : return;
30749 : }
30750 :
30751 : /* Mark children. */
30752 99208 : FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
30753 : }
30754 :
30755 : /* Walk the tree DIE and mark types that we actually use. */
30756 :
30757 : static void
30758 194851361 : prune_unused_types_walk (dw_die_ref die)
30759 : {
30760 194851361 : dw_die_ref c;
30761 :
30762 : /* Don't do anything if this node is already marked and
30763 : children have been marked as well. */
30764 194851361 : if (die->die_mark == 2)
30765 : return;
30766 :
30767 182527083 : switch (die->die_tag)
30768 : {
30769 49252981 : case DW_TAG_structure_type:
30770 49252981 : case DW_TAG_union_type:
30771 49252981 : case DW_TAG_class_type:
30772 49252981 : case DW_TAG_interface_type:
30773 49252981 : if (die->die_perennial_p)
30774 : break;
30775 :
30776 152835790 : for (c = die->die_parent; c; c = c->die_parent)
30777 103647176 : if (c->die_tag == DW_TAG_subprogram)
30778 : break;
30779 :
30780 : /* Finding used static member functions inside of classes
30781 : is needed just for local classes, because for other classes
30782 : static member function DIEs with DW_AT_specification
30783 : are emitted outside of the DW_TAG_*_type. If we ever change
30784 : it, we'd need to call this even for non-local classes. */
30785 49205598 : if (c)
30786 16984 : prune_unused_types_walk_local_classes (die);
30787 :
30788 : /* It's a type node --- don't mark it. */
30789 : return;
30790 :
30791 49016575 : case DW_TAG_const_type:
30792 49016575 : case DW_TAG_packed_type:
30793 49016575 : case DW_TAG_pointer_type:
30794 49016575 : case DW_TAG_reference_type:
30795 49016575 : case DW_TAG_rvalue_reference_type:
30796 49016575 : case DW_TAG_volatile_type:
30797 49016575 : case DW_TAG_restrict_type:
30798 49016575 : case DW_TAG_shared_type:
30799 49016575 : case DW_TAG_atomic_type:
30800 49016575 : case DW_TAG_immutable_type:
30801 49016575 : case DW_TAG_typedef:
30802 49016575 : case DW_TAG_array_type:
30803 49016575 : case DW_TAG_coarray_type:
30804 49016575 : case DW_TAG_friend:
30805 49016575 : case DW_TAG_enumeration_type:
30806 49016575 : case DW_TAG_subroutine_type:
30807 49016575 : case DW_TAG_string_type:
30808 49016575 : case DW_TAG_set_type:
30809 49016575 : case DW_TAG_subrange_type:
30810 49016575 : case DW_TAG_ptr_to_member_type:
30811 49016575 : case DW_TAG_file_type:
30812 49016575 : case DW_TAG_unspecified_type:
30813 49016575 : case DW_TAG_dynamic_type:
30814 : /* Type nodes are useful only when other DIEs reference them --- don't
30815 : mark them. */
30816 : /* FALLTHROUGH */
30817 :
30818 49016575 : case DW_TAG_dwarf_procedure:
30819 : /* Likewise for DWARF procedures. */
30820 :
30821 49016575 : if (die->die_perennial_p)
30822 : break;
30823 :
30824 : return;
30825 :
30826 50136020 : case DW_TAG_variable:
30827 50136020 : if (flag_debug_only_used_symbols)
30828 : {
30829 50135779 : if (die->die_perennial_p)
30830 : break;
30831 :
30832 : /* For static data members, the declaration in the class is supposed
30833 : to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
30834 : DWARF5. DW_TAG_member will be marked, so mark even such
30835 : DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
30836 : attribute. */
30837 49865927 : if (dwarf_version >= 5
30838 49862831 : && class_scope_p (die->die_parent)
30839 50027261 : && get_AT (die, DW_AT_const_value))
30840 : break;
30841 :
30842 : /* premark_used_variables marks external variables --- don't mark
30843 : them here. But function-local externals are always considered
30844 : used. */
30845 49788721 : if (get_AT (die, DW_AT_external))
30846 : {
30847 120130974 : for (c = die->die_parent; c; c = c->die_parent)
30848 72230157 : if (c->die_tag == DW_TAG_subprogram)
30849 : break;
30850 47902374 : if (!c)
30851 : return;
30852 : }
30853 : }
30854 : /* FALLTHROUGH */
30855 :
30856 : default:
30857 : /* Mark everything else. */
30858 : break;
30859 : }
30860 :
30861 36495091 : if (die->die_mark == 0)
30862 : {
30863 35946510 : die->die_mark = 1;
30864 :
30865 : /* Now, mark any dies referenced from here. */
30866 35946510 : prune_unused_types_walk_attribs (die);
30867 : }
30868 :
30869 36495091 : die->die_mark = 2;
30870 :
30871 : /* Mark children. */
30872 205344251 : FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
30873 : }
30874 :
30875 : /* Increment the string counts on strings referred to from DIE's
30876 : attributes. */
30877 :
30878 : static void
30879 52795146 : prune_unused_types_update_strings (dw_die_ref die)
30880 : {
30881 52795146 : dw_attr_node *a;
30882 52795146 : unsigned ix;
30883 :
30884 243219943 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
30885 190424797 : if (AT_class (a) == dw_val_class_str)
30886 : {
30887 32163275 : struct indirect_string_node *s = a->dw_attr_val.v.val_str;
30888 32163275 : s->refcount++;
30889 : /* Avoid unnecessarily putting strings that are used less than
30890 : twice in the hash table. */
30891 32163275 : if (s->form != DW_FORM_line_strp
30892 32062953 : && (s->refcount
30893 32062953 : == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2)))
30894 : {
30895 19668268 : indirect_string_node **slot
30896 19668268 : = debug_str_hash->find_slot_with_hash (s->str,
30897 19668268 : htab_hash_string (s->str),
30898 : INSERT);
30899 19668268 : gcc_assert (*slot == NULL);
30900 19668268 : *slot = s;
30901 : }
30902 : }
30903 52795146 : }
30904 :
30905 : /* Mark DIE and its children as removed. */
30906 :
30907 : static void
30908 557089938 : mark_removed (dw_die_ref die)
30909 : {
30910 557089938 : dw_die_ref c;
30911 557089938 : die->removed = true;
30912 971622493 : FOR_EACH_CHILD (die, c, mark_removed (c));
30913 557089938 : }
30914 :
30915 : /* Remove from the tree DIE any dies that aren't marked. */
30916 :
30917 : static void
30918 52795146 : prune_unused_types_prune (dw_die_ref die)
30919 : {
30920 52795146 : dw_die_ref c;
30921 :
30922 52795146 : gcc_assert (die->die_mark);
30923 52795146 : prune_unused_types_update_strings (die);
30924 :
30925 52795146 : if (! die->die_child)
30926 : return;
30927 :
30928 : c = die->die_child;
30929 53195938 : do {
30930 53195938 : dw_die_ref prev = c, next;
30931 195300032 : for (c = c->die_sib; ! c->die_mark; c = next)
30932 142557383 : if (c == die->die_child)
30933 : {
30934 : /* No marked children between 'prev' and the end of the list. */
30935 453289 : if (prev == c)
30936 : /* No marked children at all. */
30937 276845 : die->die_child = NULL;
30938 : else
30939 : {
30940 176444 : prev->die_sib = c->die_sib;
30941 176444 : die->die_child = prev;
30942 : }
30943 453289 : c->die_sib = NULL;
30944 453289 : mark_removed (c);
30945 453289 : return;
30946 : }
30947 : else
30948 : {
30949 142104094 : next = c->die_sib;
30950 142104094 : c->die_sib = NULL;
30951 142104094 : mark_removed (c);
30952 : }
30953 :
30954 52742649 : if (c != prev->die_sib)
30955 2318531 : prev->die_sib = c;
30956 52742649 : prune_unused_types_prune (c);
30957 52742649 : } while (c != die->die_child);
30958 : }
30959 :
30960 : /* Remove dies representing declarations that we never use. */
30961 :
30962 : static void
30963 52416 : prune_unused_types (void)
30964 : {
30965 52416 : unsigned int i;
30966 52416 : limbo_die_node *node;
30967 52416 : comdat_type_node *ctnode;
30968 52416 : pubname_entry *pub;
30969 52416 : dw_die_ref base_type;
30970 :
30971 : #if ENABLE_ASSERT_CHECKING
30972 : /* All the marks should already be clear. */
30973 52416 : verify_marks_clear (comp_unit_die ());
30974 52416 : for (node = limbo_die_list; node; node = node->next)
30975 0 : verify_marks_clear (node->die);
30976 52497 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30977 81 : verify_marks_clear (ctnode->root_die);
30978 : #endif /* ENABLE_ASSERT_CHECKING */
30979 :
30980 : /* Mark types that are used in global variables. */
30981 52416 : premark_types_used_by_global_vars ();
30982 :
30983 : /* Mark variables used in the symtab. */
30984 52416 : if (flag_debug_only_used_symbols)
30985 52384 : premark_used_variables ();
30986 :
30987 : /* Set the mark on nodes that are actually used. */
30988 52416 : prune_unused_types_walk (comp_unit_die ());
30989 52416 : for (node = limbo_die_list; node; node = node->next)
30990 0 : prune_unused_types_walk (node->die);
30991 52497 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30992 : {
30993 81 : prune_unused_types_walk (ctnode->root_die);
30994 81 : prune_unused_types_mark (ctnode->type_die, 1);
30995 : }
30996 :
30997 : /* Also set the mark on nodes referenced from the pubname_table. Enumerators
30998 : are unusual in that they are pubnames that are the children of pubtypes.
30999 : They should only be marked via their parent DW_TAG_enumeration_type die,
31000 : not as roots in themselves. */
31001 53114 : FOR_EACH_VEC_ELT (*pubname_table, i, pub)
31002 698 : if (pub->die->die_tag != DW_TAG_enumerator)
31003 644 : prune_unused_types_mark (pub->die, 1);
31004 52416 : for (i = 0; base_types.iterate (i, &base_type); i++)
31005 0 : prune_unused_types_mark (base_type, 1);
31006 :
31007 : /* Also set the mark on nodes that could be referenced by
31008 : DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
31009 : by DW_TAG_inlined_subroutine origins. */
31010 52416 : cgraph_node *cnode;
31011 2820171 : FOR_EACH_FUNCTION (cnode)
31012 2767755 : if (cnode->referred_to_p (false))
31013 : {
31014 2585615 : dw_die_ref die = lookup_decl_die (cnode->decl);
31015 2585615 : if (die == NULL || die->die_mark)
31016 2585439 : continue;
31017 176 : for (cgraph_edge *e = cnode->callers; e; e = e->next_caller)
31018 154 : if (e->caller != cnode)
31019 : {
31020 154 : prune_unused_types_mark (die, 1);
31021 154 : break;
31022 : }
31023 : }
31024 :
31025 52416 : if (debug_str_hash)
31026 52416 : debug_str_hash->empty ();
31027 52416 : if (skeleton_debug_str_hash)
31028 0 : skeleton_debug_str_hash->empty ();
31029 52416 : prune_unused_types_prune (comp_unit_die ());
31030 52416 : for (limbo_die_node **pnode = &limbo_die_list; *pnode; )
31031 : {
31032 0 : node = *pnode;
31033 0 : if (!node->die->die_mark)
31034 0 : *pnode = node->next;
31035 : else
31036 : {
31037 0 : prune_unused_types_prune (node->die);
31038 0 : pnode = &node->next;
31039 : }
31040 : }
31041 52497 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
31042 81 : prune_unused_types_prune (ctnode->root_die);
31043 :
31044 : /* Leave the marks clear. */
31045 52416 : prune_unmark_dies (comp_unit_die ());
31046 52416 : for (node = limbo_die_list; node; node = node->next)
31047 0 : prune_unmark_dies (node->die);
31048 52497 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
31049 81 : prune_unmark_dies (ctnode->root_die);
31050 52416 : }
31051 :
31052 : /* Helpers to manipulate hash table of comdat type units. */
31053 :
31054 : struct comdat_type_hasher : nofree_ptr_hash <comdat_type_node>
31055 : {
31056 : static inline hashval_t hash (const comdat_type_node *);
31057 : static inline bool equal (const comdat_type_node *, const comdat_type_node *);
31058 : };
31059 :
31060 : inline hashval_t
31061 86 : comdat_type_hasher::hash (const comdat_type_node *type_node)
31062 : {
31063 86 : hashval_t h;
31064 86 : memcpy (&h, type_node->signature, sizeof (h));
31065 86 : return h;
31066 : }
31067 :
31068 : inline bool
31069 5 : comdat_type_hasher::equal (const comdat_type_node *type_node_1,
31070 : const comdat_type_node *type_node_2)
31071 : {
31072 5 : return (! memcmp (type_node_1->signature, type_node_2->signature,
31073 : DWARF_TYPE_SIGNATURE_SIZE));
31074 : }
31075 :
31076 : /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
31077 : to the location it would have been added, should we know its
31078 : DECL_ASSEMBLER_NAME when we added other attributes. This will
31079 : probably improve compactness of debug info, removing equivalent
31080 : abbrevs, and hide any differences caused by deferring the
31081 : computation of the assembler name, triggered by e.g. PCH. */
31082 :
31083 : static inline void
31084 120586956 : move_linkage_attr (dw_die_ref die)
31085 : {
31086 120586956 : unsigned ix = vec_safe_length (die->die_attr);
31087 120586956 : dw_attr_node linkage = (*die->die_attr)[ix - 1];
31088 :
31089 120586956 : gcc_assert (linkage.dw_attr == DW_AT_linkage_name
31090 : || linkage.dw_attr == DW_AT_MIPS_linkage_name);
31091 :
31092 592426189 : while (--ix > 0)
31093 : {
31094 592426141 : dw_attr_node *prev = &(*die->die_attr)[ix - 1];
31095 :
31096 592426141 : if (prev->dw_attr == DW_AT_decl_line
31097 : || prev->dw_attr == DW_AT_decl_column
31098 : || prev->dw_attr == DW_AT_name)
31099 : break;
31100 : }
31101 :
31102 120586956 : if (ix != vec_safe_length (die->die_attr) - 1)
31103 : {
31104 120288094 : die->die_attr->pop ();
31105 120288094 : die->die_attr->quick_insert (ix, linkage);
31106 : }
31107 120586956 : }
31108 :
31109 : /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
31110 : referenced from typed stack ops and count how often they are used. */
31111 :
31112 : static void
31113 33394076 : mark_base_types (dw_loc_descr_ref loc)
31114 : {
31115 33394076 : dw_die_ref base_type = NULL;
31116 :
31117 95885408 : for (; loc; loc = loc->dw_loc_next)
31118 : {
31119 62491332 : switch (loc->dw_loc_opc)
31120 : {
31121 162518 : case DW_OP_regval_type:
31122 162518 : case DW_OP_deref_type:
31123 162518 : case DW_OP_GNU_regval_type:
31124 162518 : case DW_OP_GNU_deref_type:
31125 162518 : base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
31126 162518 : break;
31127 168376 : case DW_OP_convert:
31128 168376 : case DW_OP_reinterpret:
31129 168376 : case DW_OP_GNU_convert:
31130 168376 : case DW_OP_GNU_reinterpret:
31131 168376 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
31132 26729 : continue;
31133 : /* FALLTHRU */
31134 182555 : case DW_OP_const_type:
31135 182555 : case DW_OP_GNU_const_type:
31136 182555 : base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
31137 182555 : break;
31138 1352889 : case DW_OP_entry_value:
31139 1352889 : case DW_OP_GNU_entry_value:
31140 1352889 : mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
31141 1352889 : continue;
31142 60766641 : default:
31143 60766641 : continue;
31144 : }
31145 345073 : gcc_assert (base_type->die_parent == comp_unit_die ());
31146 345073 : if (base_type->die_mark)
31147 338494 : base_type->die_mark++;
31148 : else
31149 : {
31150 6579 : base_types.safe_push (base_type);
31151 6579 : base_type->die_mark = 1;
31152 : }
31153 : }
31154 33394076 : }
31155 :
31156 : /* Stripped-down variant of resolve_addr, mark DW_TAG_base_type nodes
31157 : referenced from typed stack ops and count how often they are used. */
31158 :
31159 : static void
31160 227735 : mark_base_types (dw_die_ref die)
31161 : {
31162 227735 : dw_die_ref c;
31163 227735 : dw_attr_node *a;
31164 227735 : dw_loc_list_ref *curr;
31165 227735 : unsigned ix;
31166 :
31167 1063338 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
31168 835603 : switch (AT_class (a))
31169 : {
31170 0 : case dw_val_class_loc_list:
31171 0 : curr = AT_loc_list_ptr (a);
31172 0 : while (*curr)
31173 : {
31174 0 : mark_base_types ((*curr)->expr);
31175 0 : curr = &(*curr)->dw_loc_next;
31176 : }
31177 : break;
31178 :
31179 240 : case dw_val_class_loc:
31180 240 : mark_base_types (AT_loc (a));
31181 240 : break;
31182 :
31183 : default:
31184 : break;
31185 : }
31186 :
31187 454153 : FOR_EACH_CHILD (die, c, mark_base_types (c));
31188 227735 : }
31189 :
31190 : /* Comparison function for sorting marked base types. */
31191 :
31192 : static int
31193 17089 : base_type_cmp (const void *x, const void *y)
31194 : {
31195 17089 : dw_die_ref dx = *(const dw_die_ref *) x;
31196 17089 : dw_die_ref dy = *(const dw_die_ref *) y;
31197 17089 : unsigned int byte_size1, byte_size2;
31198 17089 : unsigned int encoding1, encoding2;
31199 17089 : unsigned int align1, align2;
31200 17089 : if (dx->die_mark > dy->die_mark)
31201 : return -1;
31202 9931 : if (dx->die_mark < dy->die_mark)
31203 : return 1;
31204 3790 : byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
31205 3790 : byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
31206 3790 : if (byte_size1 < byte_size2)
31207 : return 1;
31208 2339 : if (byte_size1 > byte_size2)
31209 : return -1;
31210 460 : encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
31211 460 : encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
31212 460 : if (encoding1 < encoding2)
31213 : return 1;
31214 288 : if (encoding1 > encoding2)
31215 : return -1;
31216 9 : align1 = get_AT_unsigned (dx, DW_AT_alignment);
31217 9 : align2 = get_AT_unsigned (dy, DW_AT_alignment);
31218 9 : if (align1 < align2)
31219 : return 1;
31220 9 : if (align1 > align2)
31221 : return -1;
31222 : return 0;
31223 : }
31224 :
31225 : /* Move base types marked by mark_base_types as early as possible
31226 : in the CU, sorted by decreasing usage count both to make the
31227 : uleb128 references as small as possible and to make sure they
31228 : will have die_offset already computed by calc_die_sizes when
31229 : sizes of typed stack loc ops is computed. */
31230 :
31231 : static void
31232 53346 : move_marked_base_types (void)
31233 : {
31234 53346 : unsigned int i;
31235 53346 : dw_die_ref base_type, die, c;
31236 :
31237 53346 : if (base_types.is_empty ())
31238 53346 : return;
31239 :
31240 : /* Sort by decreasing usage count, they will be added again in that
31241 : order later on. */
31242 3689 : base_types.qsort (base_type_cmp);
31243 3689 : die = comp_unit_die ();
31244 3689 : c = die->die_child;
31245 1430608 : do
31246 : {
31247 1430608 : dw_die_ref prev = c;
31248 1430608 : c = c->die_sib;
31249 1437187 : while (c->die_mark)
31250 : {
31251 6579 : remove_child_with_prev (c, prev);
31252 : /* As base types got marked, there must be at least
31253 : one node other than DW_TAG_base_type. */
31254 6579 : gcc_assert (die->die_child != NULL);
31255 6579 : c = prev->die_sib;
31256 : }
31257 : }
31258 1430608 : while (c != die->die_child);
31259 3689 : gcc_assert (die->die_child);
31260 : c = die->die_child;
31261 10268 : for (i = 0; base_types.iterate (i, &base_type); i++)
31262 : {
31263 6579 : base_type->die_mark = 0;
31264 6579 : base_type->die_sib = c->die_sib;
31265 6579 : c->die_sib = base_type;
31266 6579 : c = base_type;
31267 : }
31268 : }
31269 :
31270 : /* Helper function for resolve_addr, attempt to resolve
31271 : one CONST_STRING, return true if successful. Similarly verify that
31272 : SYMBOL_REFs refer to variables emitted in the current CU. */
31273 :
31274 : static bool
31275 2076908 : resolve_one_addr (rtx *addr)
31276 : {
31277 2076908 : rtx rtl = *addr;
31278 :
31279 2076908 : if (GET_CODE (rtl) == CONST_STRING)
31280 : {
31281 245266 : size_t len = strlen (XSTR (rtl, 0)) + 1;
31282 245266 : tree t = build_string (len, XSTR (rtl, 0));
31283 245266 : tree tlen = size_int (len - 1);
31284 245266 : TREE_TYPE (t)
31285 245266 : = build_array_type (char_type_node, build_index_type (tlen));
31286 245266 : rtl = lookup_constant_def (t);
31287 245266 : if (!rtl || !MEM_P (rtl))
31288 : return false;
31289 112151 : rtl = XEXP (rtl, 0);
31290 112151 : if (GET_CODE (rtl) == SYMBOL_REF
31291 112151 : && SYMBOL_REF_DECL (rtl)
31292 224302 : && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
31293 : return false;
31294 4289 : vec_safe_push (used_rtx_array, rtl);
31295 4289 : *addr = rtl;
31296 4289 : return true;
31297 : }
31298 :
31299 1831642 : if (GET_CODE (rtl) == SYMBOL_REF
31300 1831642 : && SYMBOL_REF_DECL (rtl))
31301 : {
31302 1467748 : if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
31303 : {
31304 587676 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
31305 : return false;
31306 : }
31307 880072 : else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
31308 : return false;
31309 : }
31310 :
31311 1800741 : if (GET_CODE (rtl) == CONST)
31312 : {
31313 120397 : subrtx_ptr_iterator::array_type array;
31314 477263 : FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
31315 359070 : if (!resolve_one_addr (*iter))
31316 2204 : return false;
31317 120397 : }
31318 :
31319 : return true;
31320 : }
31321 :
31322 : /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
31323 : if possible, and create DW_TAG_dwarf_procedure that can be referenced
31324 : from DW_OP_implicit_pointer if the string hasn't been seen yet. */
31325 :
31326 : static rtx
31327 84605 : string_cst_pool_decl (tree t)
31328 : {
31329 84605 : rtx rtl = output_constant_def (t, 1);
31330 84605 : unsigned char *array;
31331 84605 : dw_loc_descr_ref l;
31332 84605 : tree decl;
31333 84605 : size_t len;
31334 84605 : dw_die_ref ref;
31335 :
31336 84605 : if (!rtl || !MEM_P (rtl))
31337 : return NULL_RTX;
31338 84605 : rtl = XEXP (rtl, 0);
31339 84605 : if (GET_CODE (rtl) != SYMBOL_REF
31340 84605 : || SYMBOL_REF_DECL (rtl) == NULL_TREE)
31341 : return NULL_RTX;
31342 :
31343 84605 : decl = SYMBOL_REF_DECL (rtl);
31344 84605 : if (!lookup_decl_die (decl))
31345 : {
31346 10360 : len = TREE_STRING_LENGTH (t);
31347 10360 : vec_safe_push (used_rtx_array, rtl);
31348 10360 : ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
31349 10360 : array = ggc_vec_alloc<unsigned char> (len);
31350 10360 : memcpy (array, TREE_STRING_POINTER (t), len);
31351 10360 : l = new_loc_descr (DW_OP_implicit_value, len, 0);
31352 10360 : l->dw_loc_oprnd2.val_class = dw_val_class_vec;
31353 10360 : l->dw_loc_oprnd2.v.val_vec.length = len;
31354 10360 : l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
31355 10360 : l->dw_loc_oprnd2.v.val_vec.array = array;
31356 10360 : add_AT_loc (ref, DW_AT_location, l);
31357 10360 : equate_decl_number_to_die (decl, ref);
31358 : }
31359 : return rtl;
31360 : }
31361 :
31362 : /* Helper function of resolve_addr_in_expr. LOC is
31363 : a DW_OP_addr followed by DW_OP_stack_value, either at the start
31364 : of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
31365 : resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
31366 : with DW_OP_implicit_pointer if possible
31367 : and return true, if unsuccessful, return false. */
31368 :
31369 : static bool
31370 103849 : optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
31371 : {
31372 103849 : rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
31373 103849 : HOST_WIDE_INT offset = 0;
31374 103849 : dw_die_ref ref = NULL;
31375 103849 : tree decl;
31376 :
31377 103849 : if (GET_CODE (rtl) == CONST
31378 2157 : && GET_CODE (XEXP (rtl, 0)) == PLUS
31379 2157 : && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
31380 : {
31381 2157 : offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
31382 2157 : rtl = XEXP (XEXP (rtl, 0), 0);
31383 : }
31384 103849 : if (GET_CODE (rtl) == CONST_STRING)
31385 : {
31386 84601 : size_t len = strlen (XSTR (rtl, 0)) + 1;
31387 84601 : tree t = build_string (len, XSTR (rtl, 0));
31388 84601 : tree tlen = size_int (len - 1);
31389 :
31390 84601 : TREE_TYPE (t)
31391 84601 : = build_array_type (char_type_node, build_index_type (tlen));
31392 84601 : rtl = string_cst_pool_decl (t);
31393 84601 : if (!rtl)
31394 : return false;
31395 : }
31396 103849 : if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
31397 : {
31398 103849 : decl = SYMBOL_REF_DECL (rtl);
31399 103849 : if (VAR_P (decl) && !DECL_EXTERNAL (decl))
31400 : {
31401 103411 : ref = lookup_decl_die (decl);
31402 103411 : if (ref && (get_AT (ref, DW_AT_location)
31403 11893 : || get_AT (ref, DW_AT_const_value)))
31404 : {
31405 96093 : loc->dw_loc_opc = dwarf_OP (DW_OP_implicit_pointer);
31406 96093 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31407 96093 : loc->dw_loc_oprnd1.val_entry = NULL;
31408 96093 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
31409 96093 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
31410 96093 : loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
31411 96093 : loc->dw_loc_oprnd2.v.val_int = offset;
31412 96093 : return true;
31413 : }
31414 : }
31415 : }
31416 : return false;
31417 : }
31418 :
31419 : /* Helper function for resolve_addr, handle one location
31420 : expression, return false if at least one CONST_STRING or SYMBOL_REF in
31421 : the location list couldn't be resolved. */
31422 :
31423 : static bool
31424 32825981 : resolve_addr_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
31425 : {
31426 32825981 : dw_loc_descr_ref keep = NULL;
31427 93974471 : for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
31428 61938951 : switch (loc->dw_loc_opc)
31429 : {
31430 1590189 : case DW_OP_addr:
31431 1590189 : if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
31432 : {
31433 144899 : if ((prev == NULL
31434 134 : || prev->dw_loc_opc == DW_OP_piece
31435 26 : || prev->dw_loc_opc == DW_OP_bit_piece)
31436 144873 : && loc->dw_loc_next
31437 137555 : && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
31438 103849 : && (!dwarf_strict || dwarf_version >= 5)
31439 248748 : && optimize_one_addr_into_implicit_ptr (loc))
31440 : break;
31441 48806 : return false;
31442 : }
31443 : break;
31444 3 : case DW_OP_GNU_addr_index:
31445 3 : case DW_OP_addrx:
31446 3 : case DW_OP_GNU_const_index:
31447 3 : case DW_OP_constx:
31448 3 : if ((loc->dw_loc_opc == DW_OP_GNU_addr_index
31449 3 : || loc->dw_loc_opc == DW_OP_addrx)
31450 : || ((loc->dw_loc_opc == DW_OP_GNU_const_index
31451 : || loc->dw_loc_opc == DW_OP_constx)
31452 0 : && loc->dw_loc_dtprel))
31453 : {
31454 3 : rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
31455 3 : if (!resolve_one_addr (&rtl))
31456 0 : return false;
31457 3 : remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
31458 3 : loc->dw_loc_oprnd1.val_entry
31459 3 : = add_addr_table_entry (rtl, loc->dw_loc_dtprel
31460 : ? ate_kind_rtx_dtprel : ate_kind_rtx);
31461 : }
31462 : break;
31463 188831 : case DW_OP_const4u:
31464 188831 : case DW_OP_const8u:
31465 188831 : if (loc->dw_loc_dtprel
31466 188831 : && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
31467 : return false;
31468 : break;
31469 996391 : case DW_OP_plus_uconst:
31470 996391 : if (size_of_loc_descr (loc)
31471 996391 : > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
31472 996391 : + 1
31473 996391 : && loc->dw_loc_oprnd1.v.val_unsigned > 0)
31474 : {
31475 14593 : dw_loc_descr_ref repl
31476 14593 : = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
31477 14593 : add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
31478 14593 : add_loc_descr (&repl, loc->dw_loc_next);
31479 14593 : *loc = *repl;
31480 : }
31481 : break;
31482 111469 : case DW_OP_implicit_value:
31483 111469 : if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
31484 111469 : && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
31485 : return false;
31486 : break;
31487 1872199 : case DW_OP_implicit_pointer:
31488 1872199 : case DW_OP_GNU_implicit_pointer:
31489 1872199 : case DW_OP_GNU_parameter_ref:
31490 1872199 : case DW_OP_GNU_variable_value:
31491 1872199 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
31492 : {
31493 734117 : dw_die_ref ref
31494 734117 : = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
31495 734117 : if (ref == NULL)
31496 : return false;
31497 235 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31498 235 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
31499 235 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
31500 : }
31501 1138317 : if (loc->dw_loc_opc == DW_OP_GNU_variable_value)
31502 : {
31503 4647 : if (prev == NULL
31504 4647 : && loc->dw_loc_next == NULL
31505 8122 : && AT_class (a) == dw_val_class_loc)
31506 3475 : switch (a->dw_attr)
31507 : {
31508 : /* Following attributes allow both exprloc and reference,
31509 : so if the whole expression is DW_OP_GNU_variable_value
31510 : alone we could transform it into reference. */
31511 3441 : case DW_AT_byte_size:
31512 3441 : case DW_AT_bit_size:
31513 3441 : case DW_AT_lower_bound:
31514 3441 : case DW_AT_upper_bound:
31515 3441 : case DW_AT_bit_stride:
31516 3441 : case DW_AT_count:
31517 3441 : case DW_AT_allocated:
31518 3441 : case DW_AT_associated:
31519 3441 : case DW_AT_byte_stride:
31520 3441 : a->dw_attr_val.val_class = dw_val_class_die_ref;
31521 3441 : a->dw_attr_val.val_entry = NULL;
31522 3441 : a->dw_attr_val.v.val_die_ref.die
31523 3441 : = loc->dw_loc_oprnd1.v.val_die_ref.die;
31524 3441 : a->dw_attr_val.v.val_die_ref.external = 0;
31525 3441 : return true;
31526 : default:
31527 : break;
31528 : }
31529 1206 : if (dwarf_strict)
31530 : return false;
31531 : }
31532 : break;
31533 : case DW_OP_const_type:
31534 : case DW_OP_regval_type:
31535 : case DW_OP_deref_type:
31536 : case DW_OP_convert:
31537 : case DW_OP_reinterpret:
31538 : case DW_OP_GNU_const_type:
31539 : case DW_OP_GNU_regval_type:
31540 : case DW_OP_GNU_deref_type:
31541 : case DW_OP_GNU_convert:
31542 : case DW_OP_GNU_reinterpret:
31543 332051 : while (loc->dw_loc_next
31544 332051 : && (loc->dw_loc_next->dw_loc_opc == DW_OP_convert
31545 241149 : || loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert))
31546 : {
31547 72509 : dw_die_ref base1, base2;
31548 72509 : unsigned enc1, enc2, size1, size2;
31549 72509 : if (loc->dw_loc_opc == DW_OP_regval_type
31550 72509 : || loc->dw_loc_opc == DW_OP_deref_type
31551 65790 : || loc->dw_loc_opc == DW_OP_GNU_regval_type
31552 65790 : || loc->dw_loc_opc == DW_OP_GNU_deref_type)
31553 6719 : base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
31554 65790 : else if (loc->dw_loc_oprnd1.val_class
31555 : == dw_val_class_unsigned_const)
31556 : break;
31557 : else
31558 64936 : base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
31559 71655 : if (loc->dw_loc_next->dw_loc_oprnd1.val_class
31560 : == dw_val_class_unsigned_const)
31561 : break;
31562 48295 : base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
31563 48295 : gcc_assert (base1->die_tag == DW_TAG_base_type
31564 : && base2->die_tag == DW_TAG_base_type);
31565 48295 : enc1 = get_AT_unsigned (base1, DW_AT_encoding);
31566 48295 : enc2 = get_AT_unsigned (base2, DW_AT_encoding);
31567 48295 : size1 = get_AT_unsigned (base1, DW_AT_byte_size);
31568 48295 : size2 = get_AT_unsigned (base2, DW_AT_byte_size);
31569 48295 : if (size1 == size2
31570 4726 : && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
31571 4601 : && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
31572 1995 : && loc != keep)
31573 2757 : || enc1 == enc2))
31574 : {
31575 : /* Optimize away next DW_OP_convert after
31576 : adjusting LOC's base type die reference. */
31577 1969 : if (loc->dw_loc_opc == DW_OP_regval_type
31578 1969 : || loc->dw_loc_opc == DW_OP_deref_type
31579 1191 : || loc->dw_loc_opc == DW_OP_GNU_regval_type
31580 1191 : || loc->dw_loc_opc == DW_OP_GNU_deref_type)
31581 778 : loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
31582 : else
31583 1191 : loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
31584 1969 : loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
31585 1969 : continue;
31586 : }
31587 : /* Don't change integer DW_OP_convert after e.g. floating
31588 : point typed stack entry. */
31589 46326 : else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
31590 17870 : keep = loc->dw_loc_next;
31591 : break;
31592 : }
31593 : break;
31594 : default:
31595 : break;
31596 : }
31597 : return true;
31598 : }
31599 :
31600 : /* Helper function of resolve_addr. DIE had DW_AT_location of
31601 : DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
31602 : and DW_OP_addr couldn't be resolved. resolve_addr has already
31603 : removed the DW_AT_location attribute. This function attempts to
31604 : add a new DW_AT_location attribute with DW_OP_implicit_pointer
31605 : to it or DW_AT_const_value attribute, if possible. */
31606 :
31607 : static void
31608 539 : optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
31609 : {
31610 539 : if (!VAR_P (decl)
31611 539 : || lookup_decl_die (decl) != die
31612 539 : || DECL_EXTERNAL (decl)
31613 539 : || !TREE_STATIC (decl)
31614 539 : || DECL_INITIAL (decl) == NULL_TREE
31615 373 : || DECL_P (DECL_INITIAL (decl))
31616 912 : || get_AT (die, DW_AT_const_value))
31617 166 : return;
31618 :
31619 373 : tree init = DECL_INITIAL (decl);
31620 373 : HOST_WIDE_INT offset = 0;
31621 : /* For variables that have been optimized away and thus
31622 : don't have a memory location, see if we can emit
31623 : DW_AT_const_value instead. */
31624 373 : if (tree_add_const_value_attribute (die, init))
31625 : return;
31626 188 : if (dwarf_strict && dwarf_version < 5)
31627 : return;
31628 : /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
31629 : and ADDR_EXPR refers to a decl that has DW_AT_location or
31630 : DW_AT_const_value (but isn't addressable, otherwise
31631 : resolving the original DW_OP_addr wouldn't fail), see if
31632 : we can add DW_OP_implicit_pointer. */
31633 188 : STRIP_NOPS (init);
31634 188 : if (TREE_CODE (init) == POINTER_PLUS_EXPR
31635 188 : && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
31636 : {
31637 0 : offset = tree_to_shwi (TREE_OPERAND (init, 1));
31638 0 : init = TREE_OPERAND (init, 0);
31639 0 : STRIP_NOPS (init);
31640 : }
31641 188 : if (TREE_CODE (init) != ADDR_EXPR)
31642 : return;
31643 5 : if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
31644 4 : && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
31645 5 : || (VAR_P (TREE_OPERAND (init, 0))
31646 0 : && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
31647 0 : && TREE_OPERAND (init, 0) != decl))
31648 : {
31649 4 : dw_die_ref ref;
31650 4 : dw_loc_descr_ref l;
31651 :
31652 4 : if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
31653 : {
31654 4 : rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
31655 4 : if (!rtl)
31656 : return;
31657 4 : decl = SYMBOL_REF_DECL (rtl);
31658 : }
31659 : else
31660 0 : decl = TREE_OPERAND (init, 0);
31661 4 : ref = lookup_decl_die (decl);
31662 4 : if (ref == NULL
31663 4 : || (!get_AT (ref, DW_AT_location)
31664 0 : && !get_AT (ref, DW_AT_const_value)))
31665 0 : return;
31666 4 : l = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
31667 4 : l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31668 4 : l->dw_loc_oprnd1.v.val_die_ref.die = ref;
31669 4 : l->dw_loc_oprnd1.v.val_die_ref.external = 0;
31670 4 : add_AT_loc (die, DW_AT_location, l);
31671 : }
31672 : }
31673 :
31674 : /* Return NULL if l is a DWARF expression, or first op that is not
31675 : valid DWARF expression. */
31676 :
31677 : static dw_loc_descr_ref
31678 139 : non_dwarf_expression (dw_loc_descr_ref l)
31679 : {
31680 182 : while (l)
31681 : {
31682 181 : if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
31683 : return l;
31684 85 : switch (l->dw_loc_opc)
31685 : {
31686 : case DW_OP_regx:
31687 : case DW_OP_implicit_value:
31688 : case DW_OP_stack_value:
31689 : case DW_OP_implicit_pointer:
31690 : case DW_OP_GNU_implicit_pointer:
31691 : case DW_OP_GNU_parameter_ref:
31692 : case DW_OP_piece:
31693 : case DW_OP_bit_piece:
31694 : return l;
31695 43 : default:
31696 43 : break;
31697 : }
31698 43 : l = l->dw_loc_next;
31699 : }
31700 : return NULL;
31701 : }
31702 :
31703 : /* Return adjusted copy of EXPR:
31704 : If it is empty DWARF expression, return it.
31705 : If it is valid non-empty DWARF expression,
31706 : return copy of EXPR with DW_OP_deref appended to it.
31707 : If it is DWARF expression followed by DW_OP_reg{N,x}, return
31708 : copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
31709 : If it is DWARF expression followed by DW_OP_stack_value, return
31710 : copy of the DWARF expression without anything appended.
31711 : Otherwise, return NULL. */
31712 :
31713 : static dw_loc_descr_ref
31714 69 : copy_deref_exprloc (dw_loc_descr_ref expr)
31715 : {
31716 69 : dw_loc_descr_ref tail = NULL;
31717 :
31718 69 : if (expr == NULL)
31719 : return NULL;
31720 :
31721 69 : dw_loc_descr_ref l = non_dwarf_expression (expr);
31722 69 : if (l && l->dw_loc_next)
31723 : return NULL;
31724 :
31725 69 : if (l)
31726 : {
31727 69 : if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
31728 48 : tail = new_loc_descr ((enum dwarf_location_atom)
31729 48 : (DW_OP_breg0 + (l->dw_loc_opc - DW_OP_reg0)),
31730 : 0, 0);
31731 : else
31732 21 : switch (l->dw_loc_opc)
31733 : {
31734 0 : case DW_OP_regx:
31735 0 : tail = new_loc_descr (DW_OP_bregx,
31736 : l->dw_loc_oprnd1.v.val_unsigned, 0);
31737 0 : break;
31738 : case DW_OP_stack_value:
31739 : break;
31740 : default:
31741 : return NULL;
31742 : }
31743 : }
31744 : else
31745 0 : tail = new_loc_descr (DW_OP_deref, 0, 0);
31746 :
31747 69 : dw_loc_descr_ref ret = NULL, *p = &ret;
31748 90 : while (expr != l)
31749 : {
31750 21 : *p = new_loc_descr (expr->dw_loc_opc, 0, 0);
31751 21 : (*p)->dw_loc_oprnd1.val_class = expr->dw_loc_oprnd1.val_class;
31752 21 : (*p)->dw_loc_oprnd1.val_entry = expr->dw_loc_oprnd1.val_entry;
31753 21 : (*p)->dw_loc_oprnd1.v = expr->dw_loc_oprnd1.v;
31754 21 : (*p)->dw_loc_oprnd2.val_class = expr->dw_loc_oprnd2.val_class;
31755 21 : (*p)->dw_loc_oprnd2.val_entry = expr->dw_loc_oprnd2.val_entry;
31756 21 : (*p)->dw_loc_oprnd2.v = expr->dw_loc_oprnd2.v;
31757 21 : p = &(*p)->dw_loc_next;
31758 21 : expr = expr->dw_loc_next;
31759 : }
31760 69 : *p = tail;
31761 69 : return ret;
31762 : }
31763 :
31764 : /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
31765 : reference to a variable or argument, adjust it if needed and return:
31766 : -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
31767 : attribute if present should be removed
31768 : 0 keep the attribute perhaps with minor modifications, no need to rescan
31769 : 1 if the attribute has been successfully adjusted. */
31770 :
31771 : static int
31772 1195 : optimize_string_length (dw_attr_node *a)
31773 : {
31774 1195 : dw_loc_descr_ref l = AT_loc (a), lv;
31775 1195 : dw_die_ref die;
31776 1195 : if (l->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
31777 : {
31778 0 : tree decl = l->dw_loc_oprnd1.v.val_decl_ref;
31779 0 : die = lookup_decl_die (decl);
31780 0 : if (die)
31781 : {
31782 0 : l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31783 0 : l->dw_loc_oprnd1.v.val_die_ref.die = die;
31784 0 : l->dw_loc_oprnd1.v.val_die_ref.external = 0;
31785 : }
31786 : else
31787 : return -1;
31788 : }
31789 : else
31790 1195 : die = l->dw_loc_oprnd1.v.val_die_ref.die;
31791 :
31792 : /* DWARF5 allows reference class, so we can then reference the DIE.
31793 : Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
31794 1195 : if (l->dw_loc_next != NULL && dwarf_version >= 5)
31795 : {
31796 1153 : a->dw_attr_val.val_class = dw_val_class_die_ref;
31797 1153 : a->dw_attr_val.val_entry = NULL;
31798 1153 : a->dw_attr_val.v.val_die_ref.die = die;
31799 1153 : a->dw_attr_val.v.val_die_ref.external = 0;
31800 1153 : return 0;
31801 : }
31802 :
31803 42 : dw_attr_node *av = get_AT (die, DW_AT_location);
31804 42 : dw_loc_list_ref d;
31805 42 : bool non_dwarf_expr = false;
31806 :
31807 42 : if (av == NULL)
31808 68 : return dwarf_strict ? -1 : 0;
31809 8 : switch (AT_class (av))
31810 : {
31811 7 : case dw_val_class_loc_list:
31812 76 : for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
31813 69 : if (d->expr && non_dwarf_expression (d->expr))
31814 : non_dwarf_expr = true;
31815 : break;
31816 0 : case dw_val_class_view_list:
31817 0 : gcc_unreachable ();
31818 1 : case dw_val_class_loc:
31819 1 : lv = AT_loc (av);
31820 1 : if (lv == NULL)
31821 0 : return dwarf_strict ? -1 : 0;
31822 1 : if (non_dwarf_expression (lv))
31823 : non_dwarf_expr = true;
31824 : break;
31825 0 : default:
31826 0 : return dwarf_strict ? -1 : 0;
31827 : }
31828 :
31829 : /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
31830 : into DW_OP_call4 or DW_OP_GNU_variable_value into
31831 : DW_OP_call4 DW_OP_deref, do so. */
31832 7 : if (!non_dwarf_expr
31833 8 : && (l->dw_loc_next != NULL || AT_class (av) == dw_val_class_loc))
31834 : {
31835 1 : l->dw_loc_opc = DW_OP_call4;
31836 1 : if (l->dw_loc_next)
31837 0 : l->dw_loc_next = NULL;
31838 : else
31839 1 : l->dw_loc_next = new_loc_descr (DW_OP_deref, 0, 0);
31840 1 : return 0;
31841 : }
31842 :
31843 : /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
31844 : copy over the DW_AT_location attribute from die to a. */
31845 7 : if (l->dw_loc_next != NULL)
31846 : {
31847 0 : a->dw_attr_val.val_class = av->dw_attr_val.val_class;
31848 0 : a->dw_attr_val.val_entry = av->dw_attr_val.val_entry;
31849 0 : a->dw_attr_val.v = av->dw_attr_val.v;
31850 0 : return 1;
31851 : }
31852 :
31853 7 : dw_loc_list_ref list, *p;
31854 7 : switch (AT_class (av))
31855 : {
31856 7 : case dw_val_class_loc_list:
31857 7 : p = &list;
31858 7 : list = NULL;
31859 76 : for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
31860 : {
31861 69 : lv = copy_deref_exprloc (d->expr);
31862 69 : if (lv)
31863 : {
31864 69 : *p = new_loc_list (lv, d->begin, d->vbegin, d->end, d->vend, d->section);
31865 69 : p = &(*p)->dw_loc_next;
31866 : }
31867 0 : else if (!dwarf_strict && d->expr)
31868 : return 0;
31869 : }
31870 7 : if (list == NULL)
31871 0 : return dwarf_strict ? -1 : 0;
31872 7 : a->dw_attr_val.val_class = dw_val_class_loc_list;
31873 7 : gen_llsym (list);
31874 7 : *AT_loc_list_ptr (a) = list;
31875 7 : return 1;
31876 0 : case dw_val_class_loc:
31877 0 : lv = copy_deref_exprloc (AT_loc (av));
31878 0 : if (lv == NULL)
31879 0 : return dwarf_strict ? -1 : 0;
31880 0 : a->dw_attr_val.v.val_loc = lv;
31881 0 : return 1;
31882 0 : default:
31883 0 : gcc_unreachable ();
31884 : }
31885 : }
31886 :
31887 : /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
31888 : an address in .rodata section if the string literal is emitted there,
31889 : or remove the containing location list or replace DW_AT_const_value
31890 : with DW_AT_location and empty location expression, if it isn't found
31891 : in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
31892 : to something that has been emitted in the current CU. */
31893 :
31894 : static void
31895 79089264 : resolve_addr (dw_die_ref die)
31896 : {
31897 79089264 : dw_die_ref c;
31898 79089264 : dw_attr_node *a;
31899 79089264 : dw_loc_list_ref *curr, *start, loc;
31900 79089264 : unsigned ix;
31901 79089264 : bool remove_AT_byte_size = false;
31902 :
31903 375305913 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
31904 296216649 : switch (AT_class (a))
31905 : {
31906 11923981 : case dw_val_class_loc_list:
31907 11923981 : start = curr = AT_loc_list_ptr (a);
31908 11923981 : loc = *curr;
31909 11923981 : gcc_assert (loc);
31910 : /* The same list can be referenced more than once. See if we have
31911 : already recorded the result from a previous pass. */
31912 11923981 : if (loc->replaced)
31913 0 : *curr = loc->dw_loc_next;
31914 11923981 : else if (!loc->resolved_addr)
31915 : {
31916 : /* As things stand, we do not expect or allow one die to
31917 : reference a suffix of another die's location list chain.
31918 : References must be identical or completely separate.
31919 : There is therefore no need to cache the result of this
31920 : pass on any list other than the first; doing so
31921 : would lead to unnecessary writes. */
31922 37206633 : while (*curr)
31923 : {
31924 25282652 : gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
31925 25282652 : if (!resolve_addr_in_expr (a, (*curr)->expr))
31926 : {
31927 779316 : dw_loc_list_ref next = (*curr)->dw_loc_next;
31928 779316 : dw_loc_descr_ref l = (*curr)->expr;
31929 :
31930 779316 : if (next && (*curr)->ll_symbol)
31931 : {
31932 258655 : gcc_assert (!next->ll_symbol);
31933 258655 : next->ll_symbol = (*curr)->ll_symbol;
31934 258655 : next->vl_symbol = (*curr)->vl_symbol;
31935 : }
31936 779316 : if (dwarf_split_debug_info)
31937 0 : remove_loc_list_addr_table_entries (l);
31938 779316 : *curr = next;
31939 : }
31940 : else
31941 : {
31942 24503336 : mark_base_types ((*curr)->expr);
31943 24503336 : curr = &(*curr)->dw_loc_next;
31944 : }
31945 : }
31946 11923981 : if (loc == *start)
31947 11409997 : loc->resolved_addr = 1;
31948 : else
31949 : {
31950 513984 : loc->replaced = 1;
31951 513984 : loc->dw_loc_next = *start;
31952 : }
31953 : }
31954 11923981 : if (!*start)
31955 : {
31956 513821 : remove_AT (die, a->dw_attr);
31957 513821 : ix--;
31958 : }
31959 : break;
31960 11747807 : case dw_val_class_view_list:
31961 11747807 : {
31962 11747807 : gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
31963 11747807 : gcc_checking_assert (dwarf2out_locviews_in_attribute ());
31964 11747807 : dw_val_node *llnode
31965 11747807 : = view_list_to_loc_list_val_node (&a->dw_attr_val);
31966 : /* If we no longer have a loclist, or it no longer needs
31967 : views, drop this attribute. */
31968 11747807 : if (!llnode || !llnode->v.val_loc_list->vl_symbol)
31969 : {
31970 513820 : remove_AT (die, a->dw_attr);
31971 513820 : ix--;
31972 : }
31973 : break;
31974 : }
31975 7545322 : case dw_val_class_loc:
31976 7545322 : {
31977 7545322 : dw_loc_descr_ref l = AT_loc (a);
31978 : /* DW_OP_GNU_variable_value DW_OP_stack_value or
31979 : DW_OP_GNU_variable_value in DW_AT_string_length can be converted
31980 : into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
31981 : DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
31982 : DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
31983 : with DW_FORM_ref referencing the same DIE as
31984 : DW_OP_GNU_variable_value used to reference. */
31985 7545322 : if (a->dw_attr == DW_AT_string_length
31986 1208 : && l
31987 1208 : && l->dw_loc_opc == DW_OP_GNU_variable_value
31988 1195 : && (l->dw_loc_next == NULL
31989 1153 : || (l->dw_loc_next->dw_loc_next == NULL
31990 1153 : && l->dw_loc_next->dw_loc_opc == DW_OP_stack_value)))
31991 : {
31992 1195 : switch (optimize_string_length (a))
31993 : {
31994 0 : case -1:
31995 0 : remove_AT (die, a->dw_attr);
31996 0 : ix--;
31997 : /* If we drop DW_AT_string_length, we need to drop also
31998 : DW_AT_{string_length_,}byte_size. */
31999 0 : remove_AT_byte_size = true;
32000 0 : continue;
32001 : default:
32002 : break;
32003 7 : case 1:
32004 : /* Even if we keep the optimized DW_AT_string_length,
32005 : it might have changed AT_class, so process it again. */
32006 7 : ix--;
32007 7 : continue;
32008 : }
32009 : }
32010 : /* For -gdwarf-2 don't attempt to optimize
32011 : DW_AT_data_member_location containing
32012 : DW_OP_plus_uconst - older consumers might
32013 : rely on it being that op instead of a more complex,
32014 : but shorter, location description. */
32015 7545315 : if ((dwarf_version > 2
32016 10737 : || a->dw_attr != DW_AT_data_member_location
32017 1992 : || l == NULL
32018 1992 : || l->dw_loc_opc != DW_OP_plus_uconst
32019 1986 : || l->dw_loc_next != NULL)
32020 7554066 : && !resolve_addr_in_expr (a, l))
32021 : {
32022 7704 : if (dwarf_split_debug_info)
32023 0 : remove_loc_list_addr_table_entries (l);
32024 7704 : if (l != NULL
32025 7704 : && l->dw_loc_next == NULL
32026 7433 : && l->dw_loc_opc == DW_OP_addr
32027 7171 : && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
32028 7065 : && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
32029 14769 : && a->dw_attr == DW_AT_location)
32030 : {
32031 539 : tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
32032 539 : remove_AT (die, a->dw_attr);
32033 539 : ix--;
32034 539 : optimize_location_into_implicit_ptr (die, decl);
32035 539 : break;
32036 : }
32037 7165 : if (a->dw_attr == DW_AT_string_length)
32038 : /* If we drop DW_AT_string_length, we need to drop also
32039 : DW_AT_{string_length_,}byte_size. */
32040 0 : remove_AT_byte_size = true;
32041 7165 : remove_AT (die, a->dw_attr);
32042 7165 : ix--;
32043 : }
32044 : else
32045 7537611 : mark_base_types (l);
32046 : }
32047 : break;
32048 1481519 : case dw_val_class_addr:
32049 1481519 : if (a->dw_attr == DW_AT_const_value
32050 1481519 : && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
32051 : {
32052 0 : if (AT_index (a) != NOT_INDEXED)
32053 0 : remove_addr_table_entry (a->dw_attr_val.val_entry);
32054 0 : remove_AT (die, a->dw_attr);
32055 0 : ix--;
32056 : }
32057 1481519 : if ((die->die_tag == DW_TAG_call_site
32058 1480965 : && a->dw_attr == DW_AT_call_origin)
32059 554 : || (die->die_tag == DW_TAG_GNU_call_site
32060 554 : && a->dw_attr == DW_AT_abstract_origin))
32061 : {
32062 1481519 : tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
32063 1481519 : dw_die_ref tdie = lookup_decl_die (tdecl);
32064 1481519 : dw_die_ref cdie;
32065 1481519 : if (tdie == NULL
32066 334832 : && DECL_EXTERNAL (tdecl)
32067 297813 : && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
32068 1778450 : && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
32069 : {
32070 : dw_die_ref pdie = cdie;
32071 : /* Make sure we don't add these DIEs into type units.
32072 : We could emit skeleton DIEs for context (namespaces,
32073 : outer structs/classes) and a skeleton DIE for the
32074 : innermost context with DW_AT_signature pointing to the
32075 : type unit. See PR78835. */
32076 524142 : while (pdie && pdie->die_tag != DW_TAG_type_unit)
32077 262166 : pdie = pdie->die_parent;
32078 261976 : if (pdie == NULL)
32079 : {
32080 : /* Creating a full DIE for tdecl is overly expensive and
32081 : at this point even wrong when in the LTO phase
32082 : as it can end up generating new type DIEs we didn't
32083 : output and thus optimize_external_refs will crash. */
32084 261976 : tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
32085 261976 : add_AT_flag (tdie, DW_AT_external, 1);
32086 261976 : add_AT_flag (tdie, DW_AT_declaration, 1);
32087 261976 : add_linkage_attr (tdie, tdecl);
32088 261976 : add_name_and_src_coords_attributes (tdie, tdecl, true);
32089 261976 : equate_decl_number_to_die (tdecl, tdie);
32090 : }
32091 : }
32092 1481519 : if (tdie)
32093 : {
32094 1408663 : a->dw_attr_val.val_class = dw_val_class_die_ref;
32095 1408663 : a->dw_attr_val.v.val_die_ref.die = tdie;
32096 1408663 : a->dw_attr_val.v.val_die_ref.external = 0;
32097 : }
32098 : else
32099 : {
32100 72856 : if (AT_index (a) != NOT_INDEXED)
32101 0 : remove_addr_table_entry (a->dw_attr_val.val_entry);
32102 72856 : remove_AT (die, a->dw_attr);
32103 72856 : ix--;
32104 : }
32105 : }
32106 : break;
32107 : default:
32108 : break;
32109 : }
32110 :
32111 79089264 : if (remove_AT_byte_size)
32112 0 : remove_AT (die, dwarf_version >= 5
32113 : ? DW_AT_string_length_byte_size
32114 : : DW_AT_byte_size);
32115 :
32116 137391218 : FOR_EACH_CHILD (die, c, resolve_addr (c));
32117 79089264 : }
32118 :
32119 : /* Helper routines for optimize_location_lists.
32120 : This pass tries to share identical local lists in .debug_loc
32121 : section. */
32122 :
32123 : /* Iteratively hash operands of LOC opcode into HSTATE. */
32124 :
32125 : static void
32126 52975308 : hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
32127 : {
32128 52975308 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
32129 52975308 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
32130 :
32131 52975308 : switch (loc->dw_loc_opc)
32132 : {
32133 178613 : case DW_OP_const4u:
32134 178613 : case DW_OP_const8u:
32135 178613 : if (loc->dw_loc_dtprel)
32136 195 : goto hash_addr;
32137 : /* FALLTHRU */
32138 17957536 : case DW_OP_const1u:
32139 17957536 : case DW_OP_const1s:
32140 17957536 : case DW_OP_const2u:
32141 17957536 : case DW_OP_const2s:
32142 17957536 : case DW_OP_const4s:
32143 17957536 : case DW_OP_const8s:
32144 17957536 : case DW_OP_constu:
32145 17957536 : case DW_OP_consts:
32146 17957536 : case DW_OP_pick:
32147 17957536 : case DW_OP_plus_uconst:
32148 17957536 : case DW_OP_breg0:
32149 17957536 : case DW_OP_breg1:
32150 17957536 : case DW_OP_breg2:
32151 17957536 : case DW_OP_breg3:
32152 17957536 : case DW_OP_breg4:
32153 17957536 : case DW_OP_breg5:
32154 17957536 : case DW_OP_breg6:
32155 17957536 : case DW_OP_breg7:
32156 17957536 : case DW_OP_breg8:
32157 17957536 : case DW_OP_breg9:
32158 17957536 : case DW_OP_breg10:
32159 17957536 : case DW_OP_breg11:
32160 17957536 : case DW_OP_breg12:
32161 17957536 : case DW_OP_breg13:
32162 17957536 : case DW_OP_breg14:
32163 17957536 : case DW_OP_breg15:
32164 17957536 : case DW_OP_breg16:
32165 17957536 : case DW_OP_breg17:
32166 17957536 : case DW_OP_breg18:
32167 17957536 : case DW_OP_breg19:
32168 17957536 : case DW_OP_breg20:
32169 17957536 : case DW_OP_breg21:
32170 17957536 : case DW_OP_breg22:
32171 17957536 : case DW_OP_breg23:
32172 17957536 : case DW_OP_breg24:
32173 17957536 : case DW_OP_breg25:
32174 17957536 : case DW_OP_breg26:
32175 17957536 : case DW_OP_breg27:
32176 17957536 : case DW_OP_breg28:
32177 17957536 : case DW_OP_breg29:
32178 17957536 : case DW_OP_breg30:
32179 17957536 : case DW_OP_breg31:
32180 17957536 : case DW_OP_regx:
32181 17957536 : case DW_OP_fbreg:
32182 17957536 : case DW_OP_piece:
32183 17957536 : case DW_OP_deref_size:
32184 17957536 : case DW_OP_xderef_size:
32185 17957536 : hstate.add_object (val1->v.val_int);
32186 17957536 : break;
32187 187981 : case DW_OP_skip:
32188 187981 : case DW_OP_bra:
32189 187981 : {
32190 187981 : int offset;
32191 :
32192 187981 : gcc_assert (val1->val_class == dw_val_class_loc);
32193 187981 : offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
32194 187981 : hstate.add_object (offset);
32195 : }
32196 187981 : break;
32197 101109 : case DW_OP_implicit_value:
32198 101109 : hstate.add_object (val1->v.val_unsigned);
32199 101109 : switch (val2->val_class)
32200 : {
32201 48778 : case dw_val_class_const:
32202 48778 : hstate.add_object (val2->v.val_int);
32203 48778 : break;
32204 51705 : case dw_val_class_vec:
32205 51705 : {
32206 51705 : unsigned int elt_size = val2->v.val_vec.elt_size;
32207 51705 : unsigned int len = val2->v.val_vec.length;
32208 :
32209 51705 : hstate.add_int (elt_size);
32210 51705 : hstate.add_int (len);
32211 51705 : hstate.add (val2->v.val_vec.array, len * elt_size);
32212 : }
32213 51705 : break;
32214 0 : case dw_val_class_const_double:
32215 0 : hstate.add_object (val2->v.val_double.low);
32216 0 : hstate.add_object (val2->v.val_double.high);
32217 0 : break;
32218 626 : case dw_val_class_wide_int:
32219 1252 : hstate.add (val2->v.val_wide->get_val (),
32220 626 : get_full_len (*val2->v.val_wide)
32221 626 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
32222 626 : break;
32223 0 : case dw_val_class_addr:
32224 0 : inchash::add_rtx (val2->v.val_addr, hstate);
32225 0 : break;
32226 0 : default:
32227 0 : gcc_unreachable ();
32228 : }
32229 : break;
32230 175326 : case DW_OP_bregx:
32231 175326 : case DW_OP_bit_piece:
32232 175326 : hstate.add_object (val1->v.val_int);
32233 175326 : hstate.add_object (val2->v.val_int);
32234 175326 : break;
32235 559642 : case DW_OP_addr:
32236 559642 : hash_addr:
32237 559642 : if (loc->dw_loc_dtprel)
32238 : {
32239 195 : unsigned char dtprel = 0xd1;
32240 195 : hstate.add_object (dtprel);
32241 : }
32242 559642 : inchash::add_rtx (val1->v.val_addr, hstate);
32243 559642 : break;
32244 3 : case DW_OP_GNU_addr_index:
32245 3 : case DW_OP_addrx:
32246 3 : case DW_OP_GNU_const_index:
32247 3 : case DW_OP_constx:
32248 3 : {
32249 3 : if (loc->dw_loc_dtprel)
32250 : {
32251 0 : unsigned char dtprel = 0xd1;
32252 0 : hstate.add_object (dtprel);
32253 : }
32254 3 : inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
32255 : }
32256 3 : break;
32257 1198260 : case DW_OP_implicit_pointer:
32258 1198260 : case DW_OP_GNU_implicit_pointer:
32259 1198260 : hstate.add_int (val2->v.val_int);
32260 1198260 : break;
32261 1287351 : case DW_OP_entry_value:
32262 1287351 : case DW_OP_GNU_entry_value:
32263 1287351 : hstate.add_object (val1->v.val_loc);
32264 1287351 : break;
32265 111003 : case DW_OP_regval_type:
32266 111003 : case DW_OP_deref_type:
32267 111003 : case DW_OP_GNU_regval_type:
32268 111003 : case DW_OP_GNU_deref_type:
32269 111003 : {
32270 111003 : unsigned int byte_size
32271 111003 : = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
32272 111003 : unsigned int encoding
32273 111003 : = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
32274 111003 : hstate.add_object (val1->v.val_int);
32275 111003 : hstate.add_object (byte_size);
32276 111003 : hstate.add_object (encoding);
32277 : }
32278 111003 : break;
32279 167683 : case DW_OP_convert:
32280 167683 : case DW_OP_reinterpret:
32281 167683 : case DW_OP_GNU_convert:
32282 167683 : case DW_OP_GNU_reinterpret:
32283 167683 : if (val1->val_class == dw_val_class_unsigned_const)
32284 : {
32285 26417 : hstate.add_object (val1->v.val_unsigned);
32286 26417 : break;
32287 : }
32288 : /* FALLTHRU */
32289 171532 : case DW_OP_const_type:
32290 171532 : case DW_OP_GNU_const_type:
32291 171532 : {
32292 171532 : unsigned int byte_size
32293 171532 : = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
32294 171532 : unsigned int encoding
32295 171532 : = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
32296 171532 : hstate.add_object (byte_size);
32297 171532 : hstate.add_object (encoding);
32298 171532 : if (loc->dw_loc_opc != DW_OP_const_type
32299 141266 : && loc->dw_loc_opc != DW_OP_GNU_const_type)
32300 : break;
32301 30266 : hstate.add_object (val2->val_class);
32302 30266 : switch (val2->val_class)
32303 : {
32304 9125 : case dw_val_class_const:
32305 9125 : hstate.add_object (val2->v.val_int);
32306 9125 : break;
32307 20899 : case dw_val_class_vec:
32308 20899 : {
32309 20899 : unsigned int elt_size = val2->v.val_vec.elt_size;
32310 20899 : unsigned int len = val2->v.val_vec.length;
32311 :
32312 20899 : hstate.add_object (elt_size);
32313 20899 : hstate.add_object (len);
32314 20899 : hstate.add (val2->v.val_vec.array, len * elt_size);
32315 : }
32316 20899 : break;
32317 156 : case dw_val_class_const_double:
32318 156 : hstate.add_object (val2->v.val_double.low);
32319 156 : hstate.add_object (val2->v.val_double.high);
32320 156 : break;
32321 86 : case dw_val_class_wide_int:
32322 172 : hstate.add (val2->v.val_wide->get_val (),
32323 86 : get_full_len (*val2->v.val_wide)
32324 86 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
32325 86 : break;
32326 0 : default:
32327 0 : gcc_unreachable ();
32328 : }
32329 : }
32330 30266 : break;
32331 :
32332 : default:
32333 : /* Other codes have no operands. */
32334 : break;
32335 : }
32336 52975308 : }
32337 :
32338 : /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
32339 :
32340 : static inline void
32341 24503336 : hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
32342 : {
32343 24503336 : dw_loc_descr_ref l;
32344 24503336 : bool sizes_computed = false;
32345 : /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
32346 24503336 : size_of_locs (loc);
32347 :
32348 77478034 : for (l = loc; l != NULL; l = l->dw_loc_next)
32349 : {
32350 52974698 : enum dwarf_location_atom opc = l->dw_loc_opc;
32351 52974698 : hstate.add_object (opc);
32352 52974698 : if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
32353 : {
32354 104473 : size_of_locs (loc);
32355 104473 : sizes_computed = true;
32356 : }
32357 52974698 : hash_loc_operands (l, hstate);
32358 : }
32359 24503336 : }
32360 :
32361 : /* Compute hash of the whole location list LIST_HEAD. */
32362 :
32363 : static inline void
32364 11410160 : hash_loc_list (dw_loc_list_ref list_head)
32365 : {
32366 11410160 : dw_loc_list_ref curr = list_head;
32367 11410160 : inchash::hash hstate;
32368 :
32369 35913496 : for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
32370 : {
32371 24503336 : hstate.add (curr->begin, strlen (curr->begin) + 1);
32372 24503336 : hstate.add (curr->end, strlen (curr->end) + 1);
32373 24503336 : hstate.add_object (curr->vbegin);
32374 24503336 : hstate.add_object (curr->vend);
32375 24503336 : if (curr->section)
32376 24503336 : hstate.add (curr->section, strlen (curr->section) + 1);
32377 24503336 : hash_locs (curr->expr, hstate);
32378 : }
32379 11410160 : list_head->hash = hstate.end ();
32380 11410160 : }
32381 :
32382 : /* Return true if X and Y opcodes have the same operands. */
32383 :
32384 : static inline bool
32385 722628 : compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
32386 : {
32387 722628 : dw_val_ref valx1 = &x->dw_loc_oprnd1;
32388 722628 : dw_val_ref valx2 = &x->dw_loc_oprnd2;
32389 722628 : dw_val_ref valy1 = &y->dw_loc_oprnd1;
32390 722628 : dw_val_ref valy2 = &y->dw_loc_oprnd2;
32391 :
32392 722628 : switch (x->dw_loc_opc)
32393 : {
32394 6405 : case DW_OP_const4u:
32395 6405 : case DW_OP_const8u:
32396 6405 : if (x->dw_loc_dtprel)
32397 0 : goto hash_addr;
32398 : /* FALLTHRU */
32399 173571 : case DW_OP_const1u:
32400 173571 : case DW_OP_const1s:
32401 173571 : case DW_OP_const2u:
32402 173571 : case DW_OP_const2s:
32403 173571 : case DW_OP_const4s:
32404 173571 : case DW_OP_const8s:
32405 173571 : case DW_OP_constu:
32406 173571 : case DW_OP_consts:
32407 173571 : case DW_OP_pick:
32408 173571 : case DW_OP_plus_uconst:
32409 173571 : case DW_OP_breg0:
32410 173571 : case DW_OP_breg1:
32411 173571 : case DW_OP_breg2:
32412 173571 : case DW_OP_breg3:
32413 173571 : case DW_OP_breg4:
32414 173571 : case DW_OP_breg5:
32415 173571 : case DW_OP_breg6:
32416 173571 : case DW_OP_breg7:
32417 173571 : case DW_OP_breg8:
32418 173571 : case DW_OP_breg9:
32419 173571 : case DW_OP_breg10:
32420 173571 : case DW_OP_breg11:
32421 173571 : case DW_OP_breg12:
32422 173571 : case DW_OP_breg13:
32423 173571 : case DW_OP_breg14:
32424 173571 : case DW_OP_breg15:
32425 173571 : case DW_OP_breg16:
32426 173571 : case DW_OP_breg17:
32427 173571 : case DW_OP_breg18:
32428 173571 : case DW_OP_breg19:
32429 173571 : case DW_OP_breg20:
32430 173571 : case DW_OP_breg21:
32431 173571 : case DW_OP_breg22:
32432 173571 : case DW_OP_breg23:
32433 173571 : case DW_OP_breg24:
32434 173571 : case DW_OP_breg25:
32435 173571 : case DW_OP_breg26:
32436 173571 : case DW_OP_breg27:
32437 173571 : case DW_OP_breg28:
32438 173571 : case DW_OP_breg29:
32439 173571 : case DW_OP_breg30:
32440 173571 : case DW_OP_breg31:
32441 173571 : case DW_OP_regx:
32442 173571 : case DW_OP_fbreg:
32443 173571 : case DW_OP_piece:
32444 173571 : case DW_OP_deref_size:
32445 173571 : case DW_OP_xderef_size:
32446 173571 : return valx1->v.val_int == valy1->v.val_int;
32447 268 : case DW_OP_skip:
32448 268 : case DW_OP_bra:
32449 : /* If splitting debug info, the use of DW_OP_GNU_addr_index
32450 : can cause irrelevant differences in dw_loc_addr. */
32451 268 : gcc_assert (valx1->val_class == dw_val_class_loc
32452 : && valy1->val_class == dw_val_class_loc
32453 : && (dwarf_split_debug_info
32454 : || x->dw_loc_addr == y->dw_loc_addr));
32455 268 : return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
32456 6610 : case DW_OP_implicit_value:
32457 6610 : if (valx1->v.val_unsigned != valy1->v.val_unsigned
32458 6610 : || valx2->val_class != valy2->val_class)
32459 : return false;
32460 6610 : switch (valx2->val_class)
32461 : {
32462 5115 : case dw_val_class_const:
32463 5115 : return valx2->v.val_int == valy2->v.val_int;
32464 1351 : case dw_val_class_vec:
32465 1351 : return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
32466 1351 : && valx2->v.val_vec.length == valy2->v.val_vec.length
32467 1351 : && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
32468 : valx2->v.val_vec.elt_size
32469 1351 : * valx2->v.val_vec.length) == 0;
32470 0 : case dw_val_class_const_double:
32471 0 : return valx2->v.val_double.low == valy2->v.val_double.low
32472 0 : && valx2->v.val_double.high == valy2->v.val_double.high;
32473 144 : case dw_val_class_wide_int:
32474 144 : return *valx2->v.val_wide == *valy2->v.val_wide;
32475 0 : case dw_val_class_addr:
32476 0 : return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
32477 0 : default:
32478 0 : gcc_unreachable ();
32479 : }
32480 0 : case DW_OP_bregx:
32481 0 : case DW_OP_bit_piece:
32482 0 : return valx1->v.val_int == valy1->v.val_int
32483 0 : && valx2->v.val_int == valy2->v.val_int;
32484 13561 : case DW_OP_addr:
32485 13561 : hash_addr:
32486 13561 : return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
32487 0 : case DW_OP_GNU_addr_index:
32488 0 : case DW_OP_addrx:
32489 0 : case DW_OP_GNU_const_index:
32490 0 : case DW_OP_constx:
32491 0 : {
32492 0 : rtx ax1 = valx1->val_entry->addr.rtl;
32493 0 : rtx ay1 = valy1->val_entry->addr.rtl;
32494 0 : return rtx_equal_p (ax1, ay1);
32495 : }
32496 66030 : case DW_OP_implicit_pointer:
32497 66030 : case DW_OP_GNU_implicit_pointer:
32498 66030 : return valx1->val_class == dw_val_class_die_ref
32499 66030 : && valx1->val_class == valy1->val_class
32500 66030 : && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
32501 68177 : && valx2->v.val_int == valy2->v.val_int;
32502 0 : case DW_OP_entry_value:
32503 0 : case DW_OP_GNU_entry_value:
32504 0 : return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
32505 209 : case DW_OP_const_type:
32506 209 : case DW_OP_GNU_const_type:
32507 209 : if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
32508 209 : || valx2->val_class != valy2->val_class)
32509 : return false;
32510 209 : switch (valx2->val_class)
32511 : {
32512 149 : case dw_val_class_const:
32513 149 : return valx2->v.val_int == valy2->v.val_int;
32514 60 : case dw_val_class_vec:
32515 60 : return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
32516 60 : && valx2->v.val_vec.length == valy2->v.val_vec.length
32517 60 : && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
32518 : valx2->v.val_vec.elt_size
32519 60 : * valx2->v.val_vec.length) == 0;
32520 0 : case dw_val_class_const_double:
32521 0 : return valx2->v.val_double.low == valy2->v.val_double.low
32522 0 : && valx2->v.val_double.high == valy2->v.val_double.high;
32523 0 : case dw_val_class_wide_int:
32524 0 : return *valx2->v.val_wide == *valy2->v.val_wide;
32525 0 : default:
32526 0 : gcc_unreachable ();
32527 : }
32528 1355 : case DW_OP_regval_type:
32529 1355 : case DW_OP_deref_type:
32530 1355 : case DW_OP_GNU_regval_type:
32531 1355 : case DW_OP_GNU_deref_type:
32532 1355 : return valx1->v.val_int == valy1->v.val_int
32533 1355 : && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
32534 724 : case DW_OP_convert:
32535 724 : case DW_OP_reinterpret:
32536 724 : case DW_OP_GNU_convert:
32537 724 : case DW_OP_GNU_reinterpret:
32538 724 : if (valx1->val_class != valy1->val_class)
32539 : return false;
32540 724 : if (valx1->val_class == dw_val_class_unsigned_const)
32541 6 : return valx1->v.val_unsigned == valy1->v.val_unsigned;
32542 718 : return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
32543 4813 : case DW_OP_GNU_parameter_ref:
32544 4813 : return valx1->val_class == dw_val_class_die_ref
32545 4813 : && valx1->val_class == valy1->val_class
32546 9626 : && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
32547 : default:
32548 : /* Other codes have no operands. */
32549 : return true;
32550 : }
32551 : }
32552 :
32553 : /* Return true if DWARF location expressions X and Y are the same. */
32554 :
32555 : static inline bool
32556 302627 : compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
32557 : {
32558 956726 : for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
32559 722628 : if (x->dw_loc_opc != y->dw_loc_opc
32560 722628 : || x->dw_loc_dtprel != y->dw_loc_dtprel
32561 1445256 : || !compare_loc_operands (x, y))
32562 : break;
32563 302627 : return x == NULL && y == NULL;
32564 : }
32565 :
32566 : /* Hashtable helpers. */
32567 :
32568 : struct loc_list_hasher : nofree_ptr_hash <dw_loc_list_struct>
32569 : {
32570 : static inline hashval_t hash (const dw_loc_list_struct *);
32571 : static inline bool equal (const dw_loc_list_struct *,
32572 : const dw_loc_list_struct *);
32573 : };
32574 :
32575 : /* Return precomputed hash of location list X. */
32576 :
32577 : inline hashval_t
32578 68262409 : loc_list_hasher::hash (const dw_loc_list_struct *x)
32579 : {
32580 68262409 : return x->hash;
32581 : }
32582 :
32583 : /* Return true if location lists A and B are the same. */
32584 :
32585 : inline bool
32586 67897076 : loc_list_hasher::equal (const dw_loc_list_struct *a,
32587 : const dw_loc_list_struct *b)
32588 : {
32589 67897076 : if (a == b)
32590 : return true;
32591 67897076 : if (a->hash != b->hash)
32592 : return false;
32593 429511 : for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
32594 302634 : if (strcmp (a->begin, b->begin) != 0
32595 302627 : || strcmp (a->end, b->end) != 0
32596 302627 : || (a->section == NULL) != (b->section == NULL)
32597 302627 : || (a->section && strcmp (a->section, b->section) != 0)
32598 302627 : || a->vbegin != b->vbegin || a->vend != b->vend
32599 605261 : || !compare_locs (a->expr, b->expr))
32600 : break;
32601 195413 : return a == NULL && b == NULL;
32602 : }
32603 :
32604 : typedef hash_table<loc_list_hasher> loc_list_hash_type;
32605 :
32606 :
32607 : /* Recursively optimize location lists referenced from DIE
32608 : children and share them whenever possible. */
32609 :
32610 : static void
32611 72450617 : optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
32612 : {
32613 72450617 : dw_die_ref c;
32614 72450617 : dw_attr_node *a;
32615 72450617 : unsigned ix;
32616 72450617 : dw_loc_list_struct **slot;
32617 72450617 : bool drop_locviews = false;
32618 72450617 : bool has_locviews = false;
32619 :
32620 356944704 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
32621 284494087 : if (AT_class (a) == dw_val_class_loc_list)
32622 : {
32623 11410160 : dw_loc_list_ref list = AT_loc_list (a);
32624 : /* TODO: perform some optimizations here, before hashing
32625 : it and storing into the hash table. */
32626 11410160 : hash_loc_list (list);
32627 11410160 : slot = htab->find_slot_with_hash (list, list->hash, INSERT);
32628 11410160 : if (*slot == NULL)
32629 : {
32630 11283283 : *slot = list;
32631 11283283 : if (loc_list_has_views (list))
32632 11108003 : gcc_assert (list->vl_symbol);
32633 175280 : else if (list->vl_symbol)
32634 : {
32635 0 : drop_locviews = true;
32636 0 : list->vl_symbol = NULL;
32637 : }
32638 : }
32639 : else
32640 : {
32641 126877 : if (list->vl_symbol && !(*slot)->vl_symbol)
32642 126877 : drop_locviews = true;
32643 126877 : a->dw_attr_val.v.val_loc_list = *slot;
32644 : }
32645 : }
32646 273083927 : else if (AT_class (a) == dw_val_class_view_list)
32647 : {
32648 11233987 : gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
32649 : has_locviews = true;
32650 : }
32651 :
32652 :
32653 72450617 : if (drop_locviews && has_locviews)
32654 0 : remove_AT (die, DW_AT_GNU_locviews);
32655 :
32656 144868404 : FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
32657 72450617 : }
32658 :
32659 :
32660 : /* Recursively assign each location list a unique index into the debug_addr
32661 : section. */
32662 :
32663 : static void
32664 26 : index_location_lists (dw_die_ref die)
32665 : {
32666 26 : dw_die_ref c;
32667 26 : dw_attr_node *a;
32668 26 : unsigned ix;
32669 :
32670 155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
32671 129 : if (AT_class (a) == dw_val_class_loc_list)
32672 : {
32673 2 : dw_loc_list_ref list = AT_loc_list (a);
32674 2 : dw_loc_list_ref curr;
32675 8 : for (curr = list; curr != NULL; curr = curr->dw_loc_next)
32676 : {
32677 : /* Don't index an entry that has already been indexed
32678 : or won't be output. Make sure skip_loc_list_entry doesn't
32679 : call size_of_locs, because that might cause circular dependency,
32680 : index_location_lists requiring address table indexes to be
32681 : computed, but adding new indexes through add_addr_table_entry
32682 : and address table index computation requiring no new additions
32683 : to the hash table. In the rare case of DWARF[234] >= 64KB
32684 : location expression, we'll just waste unused address table entry
32685 : for it. */
32686 4 : if (curr->begin_entry != NULL || skip_loc_list_entry (curr))
32687 0 : continue;
32688 :
32689 4 : curr->begin_entry
32690 4 : = add_addr_table_entry (xstrdup (curr->begin), ate_kind_label);
32691 4 : if (dwarf_version >= 5 && !HAVE_AS_LEB128)
32692 : curr->end_entry
32693 : = add_addr_table_entry (xstrdup (curr->end), ate_kind_label);
32694 : }
32695 : }
32696 :
32697 50 : FOR_EACH_CHILD (die, c, index_location_lists (c));
32698 26 : }
32699 :
32700 : /* Optimize location lists referenced from DIE
32701 : children and share them whenever possible. */
32702 :
32703 : static void
32704 32830 : optimize_location_lists (dw_die_ref die)
32705 : {
32706 32830 : loc_list_hash_type htab (500);
32707 32830 : optimize_location_lists_1 (die, &htab);
32708 32830 : }
32709 :
32710 : /* Traverse the limbo die list, and add parent/child links. The only
32711 : dies without parents that should be here are concrete instances of
32712 : inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
32713 : For concrete instances, we can get the parent die from the abstract
32714 : instance. */
32715 :
32716 : static void
32717 104418 : flush_limbo_die_list (void)
32718 : {
32719 104418 : limbo_die_node *node;
32720 :
32721 : /* get_context_die calls force_decl_die, which can put new DIEs on the
32722 : limbo list in LTO mode when nested functions are put in a different
32723 : partition than that of their parent function. */
32724 104418 : while ((node = limbo_die_list))
32725 : {
32726 352392 : dw_die_ref die = node->die;
32727 352392 : limbo_die_list = node->next;
32728 :
32729 352392 : if (die->die_parent == NULL)
32730 : {
32731 342386 : dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
32732 :
32733 342386 : if (origin && origin->die_parent)
32734 10232 : add_child_die (origin->die_parent, die);
32735 788964 : else if (is_cu_die (die))
32736 : ;
32737 279032 : else if (seen_error ())
32738 : /* It's OK to be confused by errors in the input. */
32739 0 : add_child_die (comp_unit_die (), die);
32740 : else
32741 : {
32742 : /* In certain situations, the lexical block containing a
32743 : nested function can be optimized away, which results
32744 : in the nested function die being orphaned. Likewise
32745 : with the return type of that nested function. Force
32746 : this to be a child of the containing function.
32747 :
32748 : It may happen that even the containing function got fully
32749 : inlined and optimized out. In that case we are lost and
32750 : assign the empty child. This should not be big issue as
32751 : the function is likely unreachable too. */
32752 279032 : gcc_assert (node->created_for);
32753 :
32754 279032 : if (DECL_P (node->created_for))
32755 2843 : origin = get_context_die (DECL_CONTEXT (node->created_for));
32756 276189 : else if (TYPE_P (node->created_for))
32757 276189 : origin = scope_die_for (node->created_for, comp_unit_die ());
32758 : else
32759 0 : origin = comp_unit_die ();
32760 :
32761 279032 : add_child_die (origin, die);
32762 : }
32763 : }
32764 : }
32765 104418 : }
32766 :
32767 : /* Reset DIEs so we can output them again. */
32768 :
32769 : static void
32770 35749 : reset_dies (dw_die_ref die)
32771 : {
32772 35749 : dw_die_ref c;
32773 :
32774 : /* Remove stuff we re-generate. */
32775 35749 : die->die_mark = 0;
32776 35749 : die->die_offset = 0;
32777 35749 : die->die_abbrev = 0;
32778 35749 : remove_AT (die, DW_AT_sibling);
32779 :
32780 70944 : FOR_EACH_CHILD (die, c, reset_dies (c));
32781 35749 : }
32782 :
32783 : /* reset_indirect_string removed the references coming from DW_AT_name
32784 : and DW_AT_comp_dir attributes on compilation unit DIEs. Readd them as
32785 : .debug_line_str strings again. */
32786 :
32787 : static void
32788 542 : adjust_name_comp_dir (dw_die_ref die)
32789 : {
32790 1626 : for (int i = 0; i < 2; i++)
32791 : {
32792 1084 : dwarf_attribute attr_kind = i ? DW_AT_comp_dir : DW_AT_name;
32793 1084 : dw_attr_node *a = get_AT (die, attr_kind);
32794 1084 : if (a == NULL || a->dw_attr_val.val_class != dw_val_class_str)
32795 0 : continue;
32796 :
32797 1084 : if (!debug_line_str_hash)
32798 542 : debug_line_str_hash
32799 542 : = hash_table<indirect_string_hasher>::create_ggc (10);
32800 :
32801 1084 : struct indirect_string_node *node
32802 1084 : = find_AT_string_in_table (a->dw_attr_val.v.val_str->str,
32803 : debug_line_str_hash);
32804 1084 : set_indirect_string (node);
32805 1084 : node->form = DW_FORM_line_strp;
32806 1084 : a->dw_attr_val.v.val_str = node;
32807 : }
32808 542 : }
32809 :
32810 : /* Output stuff that dwarf requires at the end of every file,
32811 : and generate the DWARF-2 debugging info. */
32812 :
32813 : static void
32814 52344 : dwarf2out_finish (const char *filename)
32815 : {
32816 52344 : comdat_type_node *ctnode;
32817 52344 : dw_die_ref main_comp_unit_die;
32818 52344 : unsigned char checksum[16];
32819 52344 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
32820 :
32821 : /* Generate CTF/BTF debug info. */
32822 52344 : if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
32823 52344 : || btf_debuginfo_p ()) && lang_GNU_C ())
32824 295 : ctf_debug_finish ();
32825 :
32826 : #ifdef CODEVIEW_DEBUGGING_INFO
32827 : if (codeview_debuginfo_p ())
32828 : codeview_debug_finish ();
32829 : #endif
32830 :
32831 : /* Skip emitting DWARF if not required. */
32832 52344 : if (!dwarf_debuginfo_p ())
32833 309 : return;
32834 :
32835 : /* Flush out any latecomers to the limbo party. */
32836 52035 : flush_limbo_die_list ();
32837 :
32838 52035 : if (btf_tag_htab)
32839 15 : btf_tag_htab->empty ();
32840 :
32841 52035 : if (inline_entry_data_table)
32842 12846 : gcc_assert (inline_entry_data_table->is_empty ());
32843 :
32844 52035 : if (flag_checking)
32845 : {
32846 52034 : verify_die (comp_unit_die ());
32847 52034 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32848 0 : verify_die (node->die);
32849 : }
32850 :
32851 : /* We shouldn't have any symbols with delayed asm names for
32852 : DIEs generated after early finish. */
32853 52035 : gcc_assert (deferred_asm_name == NULL);
32854 :
32855 52035 : gen_remaining_tmpl_value_param_die_attribute ();
32856 :
32857 52035 : if (flag_generate_lto || flag_generate_offload)
32858 : {
32859 552 : gcc_assert (flag_fat_lto_objects || flag_generate_offload);
32860 :
32861 : /* Prune stuff so that dwarf2out_finish runs successfully
32862 : for the fat part of the object. */
32863 552 : reset_dies (comp_unit_die ());
32864 552 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32865 0 : reset_dies (node->die);
32866 554 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32867 : {
32868 : /* Remove the pointer to the line table. */
32869 2 : remove_AT (ctnode->root_die, DW_AT_stmt_list);
32870 2 : if (debug_info_level >= DINFO_LEVEL_TERSE)
32871 2 : reset_dies (ctnode->root_die);
32872 : }
32873 :
32874 : /* Reset die CU symbol so we don't output it twice. */
32875 552 : comp_unit_die ()->die_id.die_symbol = NULL;
32876 :
32877 : /* Remove DW_AT_macro and DW_AT_stmt_list from the early output. */
32878 552 : remove_AT (comp_unit_die (), DW_AT_stmt_list);
32879 552 : if (have_macinfo)
32880 6 : remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE);
32881 :
32882 : /* Remove indirect string decisions. */
32883 19258 : debug_str_hash->traverse<void *, reset_indirect_string> (NULL);
32884 552 : if (debug_line_str_hash)
32885 : {
32886 542 : debug_line_str_hash->traverse<void *, reset_indirect_string> (NULL);
32887 542 : debug_line_str_hash = NULL;
32888 542 : if (asm_outputs_debug_line_str ())
32889 : {
32890 542 : adjust_name_comp_dir (comp_unit_die ());
32891 542 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32892 0 : adjust_name_comp_dir (node->die);
32893 : }
32894 : }
32895 : }
32896 :
32897 : #if ENABLE_ASSERT_CHECKING
32898 52035 : {
32899 52035 : dw_die_ref die = comp_unit_die (), c;
32900 9612930 : FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
32901 : }
32902 : #endif
32903 52035 : base_types.truncate (0);
32904 52112 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32905 77 : resolve_addr (ctnode->root_die);
32906 52035 : resolve_addr (comp_unit_die ());
32907 52035 : move_marked_base_types ();
32908 :
32909 52035 : if (dump_file)
32910 : {
32911 4 : fprintf (dump_file, "DWARF for %s\n", filename);
32912 4 : print_die (comp_unit_die (), dump_file);
32913 : }
32914 :
32915 : /* Initialize sections and labels used for actual assembler output. */
32916 52035 : unsigned generation = init_sections_and_labels (false);
32917 :
32918 : /* Traverse the DIE's and add sibling attributes to those DIE's that
32919 : have children. */
32920 52035 : add_sibling_attributes (comp_unit_die ());
32921 52035 : limbo_die_node *node;
32922 52035 : for (node = cu_die_list; node; node = node->next)
32923 0 : add_sibling_attributes (node->die);
32924 52112 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32925 77 : add_sibling_attributes (ctnode->root_die);
32926 :
32927 : /* When splitting DWARF info, we put some attributes in the
32928 : skeleton compile_unit DIE that remains in the .o, while
32929 : most attributes go in the DWO compile_unit_die. */
32930 52035 : if (dwarf_split_debug_info)
32931 : {
32932 249 : limbo_die_node *cu;
32933 249 : main_comp_unit_die = gen_compile_unit_die (NULL);
32934 249 : if (dwarf_version >= 5)
32935 248 : main_comp_unit_die->die_tag = DW_TAG_skeleton_unit;
32936 249 : cu = limbo_die_list;
32937 249 : gcc_assert (cu->die == main_comp_unit_die);
32938 249 : limbo_die_list = limbo_die_list->next;
32939 249 : cu->next = cu_die_list;
32940 249 : cu_die_list = cu;
32941 : }
32942 : else
32943 51786 : main_comp_unit_die = comp_unit_die ();
32944 :
32945 : /* Output a terminator label for the .text section. */
32946 52035 : switch_to_section (text_section);
32947 52035 : targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
32948 52035 : if (cold_text_section)
32949 : {
32950 8792 : switch_to_section (cold_text_section);
32951 8792 : targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
32952 : }
32953 :
32954 : /* We can only use the low/high_pc attributes if all of the code was
32955 : in .text. */
32956 52035 : if ((!have_multiple_function_sections
32957 23652 : && vec_safe_length (switch_text_ranges) < 2)
32958 52054 : || (dwarf_version < 3 && dwarf_strict))
32959 : {
32960 23633 : const char *end_label = text_end_label;
32961 23633 : if (vec_safe_length (switch_text_ranges) == 1)
32962 112 : end_label = (*switch_text_ranges)[0];
32963 : /* Don't add if the CU has no associated code. */
32964 23633 : if (switch_text_ranges)
32965 19085 : add_AT_low_high_pc (main_comp_unit_die, text_section_label,
32966 : end_label, true);
32967 : }
32968 : else
32969 : {
32970 28402 : unsigned fde_idx;
32971 28402 : dw_fde_ref fde;
32972 28402 : bool range_list_added = false;
32973 28402 : if (switch_text_ranges)
32974 : {
32975 : const char *prev_loc = text_section_label;
32976 : const char *loc;
32977 : unsigned idx;
32978 :
32979 10980 : FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
32980 858 : if (prev_loc)
32981 : {
32982 451 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32983 : loc, &range_list_added, true);
32984 451 : prev_loc = NULL;
32985 : }
32986 : else
32987 : prev_loc = loc;
32988 :
32989 10122 : if (prev_loc)
32990 10078 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32991 : text_end_label, &range_list_added, true);
32992 : }
32993 :
32994 28402 : if (switch_cold_ranges)
32995 : {
32996 : const char *prev_loc = cold_text_section_label;
32997 : const char *loc;
32998 : unsigned idx;
32999 :
33000 8792 : FOR_EACH_VEC_ELT (*switch_cold_ranges, idx, loc)
33001 0 : if (prev_loc)
33002 : {
33003 0 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
33004 : loc, &range_list_added, true);
33005 0 : prev_loc = NULL;
33006 : }
33007 : else
33008 : prev_loc = loc;
33009 :
33010 8792 : if (prev_loc)
33011 8792 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
33012 : cold_end_label, &range_list_added, true);
33013 : }
33014 :
33015 291531 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
33016 : {
33017 263129 : if (fde->ignored_debug)
33018 2920 : continue;
33019 260209 : if (!fde->in_std_section)
33020 187714 : add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
33021 : fde->dw_fde_end, &range_list_added,
33022 : true);
33023 260209 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
33024 9993 : add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
33025 : fde->dw_fde_second_end, &range_list_added,
33026 : true);
33027 : }
33028 :
33029 28402 : if (range_list_added)
33030 : {
33031 : /* We need to give .debug_loc and .debug_ranges an appropriate
33032 : "base address". Use zero so that these addresses become
33033 : absolute. Historically, we've emitted the unexpected
33034 : DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
33035 : Emit both to give time for other tools to adapt. */
33036 28402 : add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
33037 28402 : if (! dwarf_strict && dwarf_version < 4)
33038 428 : add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
33039 :
33040 28402 : add_ranges (NULL);
33041 28402 : have_multiple_function_sections = true;
33042 : }
33043 : }
33044 :
33045 : /* AIX Assembler inserts the length, so adjust the reference to match the
33046 : offset expected by debuggers. */
33047 52035 : strcpy (dl_section_ref, debug_line_section_label);
33048 52035 : if (XCOFF_DEBUGGING_INFO)
33049 : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
33050 :
33051 52035 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33052 52035 : add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
33053 : dl_section_ref);
33054 :
33055 52035 : if (have_macinfo)
33056 1002 : add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
33057 : macinfo_section_label);
33058 :
33059 52035 : if (dwarf_split_debug_info)
33060 : {
33061 249 : if (have_location_lists)
33062 : {
33063 : /* Since we generate the loclists in the split DWARF .dwo
33064 : file itself, we don't need to generate a loclists_base
33065 : attribute for the split compile unit DIE. That attribute
33066 : (and using relocatable sec_offset FORMs) isn't allowed
33067 : for a split compile unit. Only if the .debug_loclists
33068 : section was in the main file, would we need to generate a
33069 : loclists_base attribute here (for the full or skeleton
33070 : unit DIE). */
33071 :
33072 : /* optimize_location_lists calculates the size of the lists,
33073 : so index them first, and assign indices to the entries.
33074 : Although optimize_location_lists will remove entries from
33075 : the table, it only does so for duplicates, and therefore
33076 : only reduces ref_counts to 1. */
33077 2 : index_location_lists (comp_unit_die ());
33078 : }
33079 :
33080 249 : if (dwarf_version >= 5 && !vec_safe_is_empty (ranges_table))
33081 3 : index_rnglists ();
33082 :
33083 249 : if (addr_index_table != NULL)
33084 : {
33085 244 : unsigned int index = 0;
33086 244 : addr_index_table
33087 : ->traverse_noresize<unsigned int *, index_addr_table_entry>
33088 508 : (&index);
33089 : }
33090 : }
33091 :
33092 52035 : loc_list_idx = 0;
33093 52035 : if (have_location_lists)
33094 : {
33095 32830 : optimize_location_lists (comp_unit_die ());
33096 : /* And finally assign indexes to the entries for -gsplit-dwarf. */
33097 32830 : if (dwarf_version >= 5 && dwarf_split_debug_info)
33098 2 : assign_location_list_indexes (comp_unit_die ());
33099 : }
33100 :
33101 52035 : save_macinfo_strings ();
33102 :
33103 52035 : if (dwarf_split_debug_info)
33104 : {
33105 249 : unsigned int index = 0;
33106 :
33107 : /* Add attributes common to skeleton compile_units and
33108 : type_units. Because these attributes include strings, it
33109 : must be done before freezing the string table. Top-level
33110 : skeleton die attrs are added when the skeleton type unit is
33111 : created, so ensure it is created by this point. */
33112 249 : add_top_level_skeleton_die_attrs (main_comp_unit_die);
33113 3176 : debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
33114 : }
33115 :
33116 : /* Output all of the compilation units. We put the main one last so that
33117 : the offsets are available to output_pubnames. */
33118 52284 : for (node = cu_die_list; node; node = node->next)
33119 249 : output_comp_unit (node->die, 0, NULL);
33120 :
33121 52035 : hash_table<comdat_type_hasher> comdat_type_table (100);
33122 52112 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33123 : {
33124 77 : comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
33125 :
33126 : /* Don't output duplicate types. */
33127 77 : if (*slot != HTAB_EMPTY_ENTRY)
33128 1 : continue;
33129 :
33130 : /* Add a pointer to the line table for the main compilation unit
33131 : so that the debugger can make sense of DW_AT_decl_file
33132 : attributes. */
33133 76 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33134 76 : add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
33135 76 : (!dwarf_split_debug_info
33136 : ? dl_section_ref
33137 : : debug_skeleton_line_section_label));
33138 :
33139 76 : output_comdat_type_unit (ctnode, false);
33140 76 : *slot = ctnode;
33141 : }
33142 :
33143 52035 : if (dwarf_split_debug_info)
33144 : {
33145 249 : int mark;
33146 249 : struct md5_ctx ctx;
33147 :
33148 : /* Compute a checksum of the comp_unit to use as the dwo_id. */
33149 249 : md5_init_ctx (&ctx);
33150 249 : mark = 0;
33151 249 : die_checksum (comp_unit_die (), &ctx, &mark);
33152 249 : unmark_all_dies (comp_unit_die ());
33153 249 : md5_finish_ctx (&ctx, checksum);
33154 :
33155 249 : if (dwarf_version < 5)
33156 : {
33157 : /* Use the first 8 bytes of the checksum as the dwo_id,
33158 : and add it to both comp-unit DIEs. */
33159 1 : add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
33160 1 : add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
33161 : }
33162 :
33163 : /* Add the base offset of the ranges table to the skeleton
33164 : comp-unit DIE. */
33165 249 : if (!vec_safe_is_empty (ranges_table))
33166 : {
33167 3 : if (dwarf_version < 5)
33168 0 : add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
33169 : ranges_section_label);
33170 : }
33171 :
33172 249 : output_addr_table ();
33173 : }
33174 :
33175 : /* Output the main compilation unit if non-empty or if .debug_macinfo
33176 : or .debug_macro will be emitted. */
33177 103558 : output_comp_unit (comp_unit_die (), have_macinfo,
33178 52035 : dwarf_split_debug_info ? checksum : NULL);
33179 :
33180 52035 : if (dwarf_split_debug_info && info_section_emitted)
33181 249 : output_skeleton_debug_sections (main_comp_unit_die, checksum);
33182 :
33183 : /* Output the abbreviation table. */
33184 52035 : if (vec_safe_length (abbrev_die_table) != 1)
33185 : {
33186 50993 : switch_to_section (debug_abbrev_section);
33187 50993 : ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
33188 50993 : output_abbrev_section ();
33189 : }
33190 :
33191 : /* Output location list section if necessary. */
33192 52035 : if (have_location_lists)
33193 : {
33194 32830 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
33195 32830 : char l2[MAX_ARTIFICIAL_LABEL_BYTES];
33196 : /* Output the location lists info. */
33197 32830 : switch_to_section (debug_loc_section);
33198 32830 : if (dwarf_version >= 5)
33199 : {
33200 31801 : ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_LOC_SECTION_LABEL, 2);
33201 31801 : ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_LOC_SECTION_LABEL, 3);
33202 31801 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
33203 0 : dw2_asm_output_data (4, 0xffffffff,
33204 : "Initial length escape value indicating "
33205 : "64-bit DWARF extension");
33206 31801 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
33207 : "Length of Location Lists");
33208 31801 : ASM_OUTPUT_LABEL (asm_out_file, l1);
33209 31801 : output_dwarf_version ();
33210 35751 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
33211 31801 : dw2_asm_output_data (1, 0, "Segment Size");
33212 31801 : dw2_asm_output_data (4, dwarf_split_debug_info ? loc_list_idx : 0,
33213 : "Offset Entry Count");
33214 : }
33215 32830 : ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
33216 32830 : if (dwarf_version >= 5 && dwarf_split_debug_info)
33217 : {
33218 2 : unsigned int save_loc_list_idx = loc_list_idx;
33219 2 : loc_list_idx = 0;
33220 2 : output_loclists_offsets (comp_unit_die ());
33221 2 : gcc_assert (save_loc_list_idx == loc_list_idx);
33222 : }
33223 32830 : output_location_lists (comp_unit_die ());
33224 32830 : if (dwarf_version >= 5)
33225 31801 : ASM_OUTPUT_LABEL (asm_out_file, l2);
33226 : }
33227 :
33228 52035 : output_pubtables ();
33229 :
33230 : /* Output the address range information if a CU (.debug_info section)
33231 : was emitted. We output an empty table even if we had no functions
33232 : to put in it. This because the consumer has no way to tell the
33233 : difference between an empty table that we omitted and failure to
33234 : generate a table that would have contained data. */
33235 52035 : if (info_section_emitted)
33236 : {
33237 50991 : switch_to_section (debug_aranges_section);
33238 50991 : output_aranges ();
33239 : }
33240 :
33241 : /* Output ranges section if necessary. */
33242 52035 : if (!vec_safe_is_empty (ranges_table))
33243 : {
33244 33144 : if (dwarf_version >= 5)
33245 : {
33246 32620 : if (dwarf_split_debug_info)
33247 : {
33248 : /* We don't know right now whether there are any
33249 : ranges for .debug_rnglists and any for .debug_rnglists.dwo.
33250 : Depending on into which of those two belongs the first
33251 : ranges_table entry, emit that section first and that
33252 : output_rnglists call will return true if the other kind of
33253 : ranges needs to be emitted as well. */
33254 3 : bool dwo = (*ranges_table)[0].idx != DW_RANGES_IDX_SKELETON;
33255 3 : if (output_rnglists (generation, dwo))
33256 2 : output_rnglists (generation, !dwo);
33257 : }
33258 : else
33259 32617 : output_rnglists (generation, false);
33260 : }
33261 : else
33262 524 : output_ranges ();
33263 : }
33264 :
33265 : /* Have to end the macro section. */
33266 52035 : if (have_macinfo)
33267 : {
33268 512 : switch_to_section (debug_macinfo_section);
33269 512 : ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
33270 516 : output_macinfo (!dwarf_split_debug_info ? debug_line_section_label
33271 : : debug_skeleton_line_section_label, false);
33272 512 : dw2_asm_output_data (1, 0, "End compilation unit");
33273 : }
33274 :
33275 : /* Output the source line correspondence table. We must do this
33276 : even if there is no line information. Otherwise, on an empty
33277 : translation unit, we will generate a present, but empty,
33278 : .debug_info section. IRIX 6.5 `nm' will then complain when
33279 : examining the file. This is done late so that any filenames
33280 : used by the debug_info section are marked as 'used'. */
33281 52035 : switch_to_section (debug_line_section);
33282 52035 : ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
33283 52035 : if (! output_asm_line_debug_info ())
33284 6 : output_line_info (false);
33285 :
33286 52035 : if (dwarf_split_debug_info && info_section_emitted)
33287 : {
33288 249 : switch_to_section (debug_skeleton_line_section);
33289 249 : ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
33290 249 : output_line_info (true);
33291 : }
33292 :
33293 : /* If we emitted any indirect strings, output the string table too. */
33294 52035 : if (debug_str_hash || skeleton_debug_str_hash)
33295 52035 : output_indirect_strings ();
33296 52035 : if (debug_line_str_hash)
33297 : {
33298 49824 : switch_to_section (debug_line_str_section);
33299 49824 : const enum dwarf_form form = DW_FORM_line_strp;
33300 49824 : debug_line_str_hash->traverse<enum dwarf_form,
33301 49824 : output_indirect_string> (form);
33302 : }
33303 :
33304 : /* ??? Move lvugid out of dwarf2out_source_line and reset it too? */
33305 52035 : symview_upper_bound = 0;
33306 52035 : if (zero_view_p)
33307 41226 : bitmap_clear (zero_view_p);
33308 52035 : }
33309 :
33310 : /* Returns a hash value for X (which really is a variable_value_struct). */
33311 :
33312 : inline hashval_t
33313 5872 : variable_value_hasher::hash (variable_value_struct *x)
33314 : {
33315 5872 : return (hashval_t) x->decl_id;
33316 : }
33317 :
33318 : /* Return true if decl_id of variable_value_struct X is the same as
33319 : UID of decl Y. */
33320 :
33321 : inline bool
33322 6489 : variable_value_hasher::equal (variable_value_struct *x, tree y)
33323 : {
33324 6489 : return x->decl_id == DECL_UID (y);
33325 : }
33326 :
33327 : /* Helper function for resolve_variable_value, handle
33328 : DW_OP_GNU_variable_value in one location expression.
33329 : Return true if exprloc has been changed into loclist. */
33330 :
33331 : static bool
33332 609 : resolve_variable_value_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
33333 : {
33334 609 : dw_loc_descr_ref next;
33335 2121 : for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = next)
33336 : {
33337 1515 : next = loc->dw_loc_next;
33338 1515 : if (loc->dw_loc_opc != DW_OP_GNU_variable_value
33339 599 : || loc->dw_loc_oprnd1.val_class != dw_val_class_decl_ref)
33340 916 : continue;
33341 :
33342 599 : tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
33343 599 : if (DECL_CONTEXT (decl) != current_function_decl)
33344 0 : continue;
33345 :
33346 599 : dw_die_ref ref = lookup_decl_die (decl);
33347 599 : if (ref)
33348 : {
33349 0 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33350 0 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33351 0 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33352 0 : continue;
33353 : }
33354 599 : dw_loc_list_ref l = loc_list_from_tree (decl, 0, NULL);
33355 599 : if (l == NULL)
33356 121 : continue;
33357 478 : if (l->dw_loc_next)
33358 : {
33359 247 : if (AT_class (a) != dw_val_class_loc)
33360 0 : continue;
33361 247 : switch (a->dw_attr)
33362 : {
33363 : /* Following attributes allow both exprloc and loclist
33364 : classes, so we can change them into a loclist. */
33365 3 : case DW_AT_location:
33366 3 : case DW_AT_string_length:
33367 3 : case DW_AT_return_addr:
33368 3 : case DW_AT_data_member_location:
33369 3 : case DW_AT_frame_base:
33370 3 : case DW_AT_segment:
33371 3 : case DW_AT_static_link:
33372 3 : case DW_AT_use_location:
33373 3 : case DW_AT_vtable_elem_location:
33374 3 : if (prev)
33375 : {
33376 0 : prev->dw_loc_next = NULL;
33377 0 : prepend_loc_descr_to_each (l, AT_loc (a));
33378 : }
33379 3 : if (next)
33380 3 : add_loc_descr_to_each (l, next);
33381 3 : a->dw_attr_val.val_class = dw_val_class_loc_list;
33382 3 : a->dw_attr_val.val_entry = NULL;
33383 3 : a->dw_attr_val.v.val_loc_list = l;
33384 3 : have_location_lists = true;
33385 3 : return true;
33386 : /* Following attributes allow both exprloc and reference,
33387 : so if the whole expression is DW_OP_GNU_variable_value alone
33388 : we could transform it into reference. */
33389 244 : case DW_AT_byte_size:
33390 244 : case DW_AT_bit_size:
33391 244 : case DW_AT_lower_bound:
33392 244 : case DW_AT_upper_bound:
33393 244 : case DW_AT_bit_stride:
33394 244 : case DW_AT_count:
33395 244 : case DW_AT_allocated:
33396 244 : case DW_AT_associated:
33397 244 : case DW_AT_byte_stride:
33398 244 : if (prev == NULL && next == NULL)
33399 : break;
33400 : /* FALLTHRU */
33401 0 : default:
33402 0 : if (dwarf_strict)
33403 0 : continue;
33404 : break;
33405 : }
33406 : /* Create DW_TAG_variable that we can refer to. */
33407 244 : gen_decl_die (decl, NULL_TREE, NULL,
33408 : lookup_decl_die (current_function_decl));
33409 244 : ref = lookup_decl_die (decl);
33410 244 : if (ref)
33411 : {
33412 244 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33413 244 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33414 244 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33415 : }
33416 244 : continue;
33417 : }
33418 231 : if (prev)
33419 : {
33420 0 : prev->dw_loc_next = l->expr;
33421 0 : add_loc_descr (&prev->dw_loc_next, next);
33422 0 : free_loc_descr (loc, NULL);
33423 0 : next = prev->dw_loc_next;
33424 : }
33425 : else
33426 : {
33427 231 : memcpy (loc, l->expr, sizeof (dw_loc_descr_node));
33428 231 : add_loc_descr (&loc, next);
33429 231 : next = loc;
33430 : }
33431 231 : loc = prev;
33432 : }
33433 : return false;
33434 : }
33435 :
33436 : /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
33437 :
33438 : static void
33439 599 : resolve_variable_value (dw_die_ref die)
33440 : {
33441 599 : dw_attr_node *a;
33442 599 : dw_loc_list_ref loc;
33443 599 : unsigned ix;
33444 :
33445 1893 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
33446 1294 : switch (AT_class (a))
33447 : {
33448 599 : case dw_val_class_loc:
33449 599 : if (!resolve_variable_value_in_expr (a, AT_loc (a)))
33450 : break;
33451 : /* FALLTHRU */
33452 3 : case dw_val_class_loc_list:
33453 3 : loc = AT_loc_list (a);
33454 3 : gcc_assert (loc);
33455 13 : for (; loc; loc = loc->dw_loc_next)
33456 10 : resolve_variable_value_in_expr (a, loc->expr);
33457 : break;
33458 : default:
33459 : break;
33460 : }
33461 599 : }
33462 :
33463 : /* Attempt to optimize DW_OP_GNU_variable_value referring to
33464 : temporaries in the current function. */
33465 :
33466 : static void
33467 560785 : resolve_variable_values (void)
33468 : {
33469 560785 : if (!variable_value_hash || !current_function_decl)
33470 : return;
33471 :
33472 2973 : struct variable_value_struct *node
33473 2973 : = variable_value_hash->find_with_hash (current_function_decl,
33474 2973 : DECL_UID (current_function_decl));
33475 :
33476 2973 : if (node == NULL)
33477 : return;
33478 :
33479 : unsigned int i;
33480 : dw_die_ref die;
33481 1053 : FOR_EACH_VEC_SAFE_ELT (node->dies, i, die)
33482 599 : resolve_variable_value (die);
33483 : }
33484 :
33485 : /* Helper function for note_variable_value, handle one location
33486 : expression. */
33487 :
33488 : static void
33489 119452 : note_variable_value_in_expr (dw_die_ref die, dw_loc_descr_ref loc)
33490 : {
33491 354336 : for (; loc; loc = loc->dw_loc_next)
33492 234884 : if (loc->dw_loc_opc == DW_OP_GNU_variable_value
33493 5194 : && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
33494 : {
33495 808 : tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
33496 808 : dw_die_ref ref = lookup_decl_die (decl);
33497 808 : if (! ref && (flag_generate_lto || flag_generate_offload))
33498 : {
33499 : /* ??? This is somewhat a hack because we do not create DIEs
33500 : for variables not in BLOCK trees early but when generating
33501 : early LTO output we need the dw_val_class_decl_ref to be
33502 : fully resolved. For fat LTO objects we'd also like to
33503 : undo this after LTO dwarf output. */
33504 67 : gcc_assert (DECL_CONTEXT (decl));
33505 67 : dw_die_ref ctx = lookup_decl_die (DECL_CONTEXT (decl));
33506 67 : gcc_assert (ctx != NULL);
33507 67 : gen_decl_die (decl, NULL_TREE, NULL, ctx);
33508 67 : ref = lookup_decl_die (decl);
33509 67 : gcc_assert (ref != NULL);
33510 : }
33511 808 : if (ref)
33512 : {
33513 67 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33514 67 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33515 67 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33516 67 : continue;
33517 : }
33518 741 : if (VAR_P (decl)
33519 741 : && DECL_CONTEXT (decl)
33520 741 : && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
33521 1482 : && lookup_decl_die (DECL_CONTEXT (decl)))
33522 : {
33523 741 : if (!variable_value_hash)
33524 430 : variable_value_hash
33525 430 : = hash_table<variable_value_hasher>::create_ggc (10);
33526 :
33527 741 : tree fndecl = DECL_CONTEXT (decl);
33528 741 : struct variable_value_struct *node;
33529 741 : struct variable_value_struct **slot
33530 2223 : = variable_value_hash->find_slot_with_hash (fndecl,
33531 741 : DECL_UID (fndecl),
33532 : INSERT);
33533 741 : if (*slot == NULL)
33534 : {
33535 585 : node = ggc_cleared_alloc<variable_value_struct> ();
33536 585 : node->decl_id = DECL_UID (fndecl);
33537 585 : *slot = node;
33538 : }
33539 : else
33540 : node = *slot;
33541 :
33542 741 : vec_safe_push (node->dies, die);
33543 : }
33544 : }
33545 119452 : }
33546 :
33547 : /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
33548 : with dw_val_class_decl_ref operand. */
33549 :
33550 : static void
33551 52793945 : note_variable_value (dw_die_ref die)
33552 : {
33553 52793945 : dw_die_ref c;
33554 52793945 : dw_attr_node *a;
33555 52793945 : dw_loc_list_ref loc;
33556 52793945 : unsigned ix;
33557 :
33558 243214552 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
33559 190420607 : switch (AT_class (a))
33560 : {
33561 0 : case dw_val_class_loc_list:
33562 0 : loc = AT_loc_list (a);
33563 0 : gcc_assert (loc);
33564 0 : if (!loc->noted_variable_value)
33565 : {
33566 0 : loc->noted_variable_value = 1;
33567 0 : for (; loc; loc = loc->dw_loc_next)
33568 0 : note_variable_value_in_expr (die, loc->expr);
33569 : }
33570 : break;
33571 119452 : case dw_val_class_loc:
33572 119452 : note_variable_value_in_expr (die, AT_loc (a));
33573 119452 : break;
33574 : default:
33575 : break;
33576 : }
33577 :
33578 : /* Mark children. */
33579 105535426 : FOR_EACH_CHILD (die, c, note_variable_value (c));
33580 52793945 : }
33581 :
33582 : /* Process DWARF dies for CTF generation. */
33583 :
33584 : static void
33585 297 : ctf_debug_do_cu (dw_die_ref die)
33586 : {
33587 297 : dw_die_ref c;
33588 :
33589 297 : if (!ctf_do_die (die))
33590 : return;
33591 :
33592 1610 : FOR_EACH_CHILD (die, c, ctf_do_die (c));
33593 : }
33594 :
33595 : /* Perform any cleanups needed after the early debug generation pass
33596 : has run. */
33597 :
33598 : static void
33599 53131 : dwarf2out_early_finish (const char *filename)
33600 : {
33601 53131 : comdat_type_node *ctnode;
33602 53131 : set_early_dwarf s;
33603 53131 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
33604 :
33605 : /* PCH might result in DW_AT_producer string being restored from the
33606 : header compilation, so always fill it with empty string initially
33607 : and overwrite only here. */
33608 53131 : dw_attr_node *producer = get_AT (comp_unit_die (), DW_AT_producer);
33609 :
33610 53131 : if (dwarf_record_gcc_switches)
33611 52598 : producer_string = gen_producer_string (lang_hooks.name,
33612 : save_decoded_options,
33613 : save_decoded_options_count);
33614 : else
33615 533 : producer_string = concat (lang_hooks.name, " ", version_string, NULL);
33616 :
33617 53131 : producer->dw_attr_val.v.val_str->refcount--;
33618 53131 : producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
33619 :
33620 : /* Add the name for the main input file now. We delayed this from
33621 : dwarf2out_init to avoid complications with PCH. */
33622 53131 : add_filename_attribute (comp_unit_die (), remap_debug_filename (filename));
33623 53131 : add_comp_dir_attribute (comp_unit_die ());
33624 :
33625 : /* With LTO early dwarf was really finished at compile-time, so make
33626 : sure to adjust the phase after annotating the LTRANS CU DIE. */
33627 53131 : if (in_lto_p)
33628 : {
33629 748 : early_dwarf_finished = true;
33630 748 : if (dump_file)
33631 : {
33632 0 : fprintf (dump_file, "LTO EARLY DWARF for %s\n", filename);
33633 0 : print_die (comp_unit_die (), dump_file);
33634 : }
33635 748 : return;
33636 : }
33637 :
33638 : /* Walk through the list of incomplete types again, trying once more to
33639 : emit full debugging info for them. */
33640 52383 : retry_incomplete_types ();
33641 :
33642 52383 : gen_scheduled_generic_parms_dies ();
33643 52383 : gen_remaining_tmpl_value_param_die_attribute ();
33644 :
33645 : /* The point here is to flush out the limbo list so that it is empty
33646 : and we don't need to stream it for LTO. */
33647 52383 : flush_limbo_die_list ();
33648 :
33649 : /* Add DW_AT_linkage_name for all deferred DIEs. */
33650 122262493 : for (limbo_die_node *node = deferred_asm_name; node; node = node->next)
33651 : {
33652 122210110 : tree decl = node->created_for;
33653 122210110 : if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
33654 : /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
33655 : ended up in deferred_asm_name before we knew it was
33656 : constant and never written to disk. */
33657 122210110 : && DECL_ASSEMBLER_NAME (decl))
33658 : {
33659 120586956 : add_linkage_attr (node->die, decl);
33660 120586956 : move_linkage_attr (node->die);
33661 : }
33662 : }
33663 52383 : deferred_asm_name = NULL;
33664 :
33665 52383 : if (flag_eliminate_unused_debug_types)
33666 52380 : prune_unused_types ();
33667 :
33668 : /* Generate separate COMDAT sections for type DIEs. */
33669 52383 : if (use_debug_types)
33670 : {
33671 36 : break_out_comdat_types (comp_unit_die ());
33672 :
33673 : /* Each new type_unit DIE was added to the limbo die list when created.
33674 : Since these have all been added to comdat_type_list, clear the
33675 : limbo die list. */
33676 36 : limbo_die_list = NULL;
33677 :
33678 : /* For each new comdat type unit, copy declarations for incomplete
33679 : types to make the new unit self-contained (i.e., no direct
33680 : references to the main compile unit). */
33681 117 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33682 81 : copy_decls_for_unworthy_types (ctnode->root_die);
33683 36 : copy_decls_for_unworthy_types (comp_unit_die ());
33684 :
33685 : /* In the process of copying declarations from one unit to another,
33686 : we may have left some declarations behind that are no longer
33687 : referenced. Prune them. */
33688 36 : prune_unused_types ();
33689 : }
33690 :
33691 : /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
33692 : with dw_val_class_decl_ref operand. */
33693 52383 : note_variable_value (comp_unit_die ());
33694 52383 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
33695 0 : note_variable_value (node->die);
33696 52464 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33697 81 : note_variable_value (ctnode->root_die);
33698 52383 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33699 0 : note_variable_value (node->die);
33700 :
33701 : /* The AT_pubnames attribute needs to go in all skeleton dies, including
33702 : both the main_cu and all skeleton TUs. Making this call unconditional
33703 : would end up either adding a second copy of the AT_pubnames attribute, or
33704 : requiring a special case in add_top_level_skeleton_die_attrs. */
33705 52383 : if (!dwarf_split_debug_info)
33706 52134 : add_AT_pubnames (comp_unit_die ());
33707 :
33708 : /* The early debug phase is now finished. */
33709 52383 : early_dwarf_finished = true;
33710 52383 : if (dump_file)
33711 : {
33712 4 : fprintf (dump_file, "EARLY DWARF for %s\n", filename);
33713 4 : print_die (comp_unit_die (), dump_file);
33714 : }
33715 :
33716 : /* Generate CTF/BTF debug info. */
33717 52383 : if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
33718 52383 : || btf_debuginfo_p ()) && lang_GNU_C ())
33719 : {
33720 297 : ctf_debug_init ();
33721 297 : ctf_debug_do_cu (comp_unit_die ());
33722 297 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33723 0 : ctf_debug_do_cu (node->die);
33724 :
33725 297 : ctf_debug_early_finish (filename);
33726 : }
33727 :
33728 : #ifdef CODEVIEW_DEBUGGING_INFO
33729 : if (codeview_debuginfo_p ())
33730 : codeview_debug_early_finish (comp_unit_die ());
33731 : #endif
33732 :
33733 : /* Do not generate DWARF assembler now when not producing LTO bytecode. */
33734 52383 : if ((!flag_generate_lto && !flag_generate_offload)
33735 : /* FIXME: Disable debug info generation for (PE-)COFF targets since the
33736 : copy_lto_debug_sections operation of the simple object support in
33737 : libiberty is not implemented for them yet. */
33738 : || TARGET_PECOFF || TARGET_COFF)
33739 : return;
33740 :
33741 : /* Now as we are going to output for LTO initialize sections and labels
33742 : to the LTO variants. We don't need a random-seed postfix as other
33743 : LTO sections as linking the LTO debug sections into one in a partial
33744 : link is fine. */
33745 1311 : init_sections_and_labels (true);
33746 :
33747 : /* The output below is modeled after dwarf2out_finish with all
33748 : location related output removed and some LTO specific changes.
33749 : Some refactoring might make both smaller and easier to match up. */
33750 :
33751 1311 : base_types.truncate (0);
33752 1317 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33753 6 : mark_base_types (ctnode->root_die);
33754 1311 : mark_base_types (comp_unit_die ());
33755 1311 : move_marked_base_types ();
33756 :
33757 : /* Traverse the DIE's and add sibling attributes to those DIE's
33758 : that have children. */
33759 1311 : add_sibling_attributes (comp_unit_die ());
33760 1311 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33761 0 : add_sibling_attributes (node->die);
33762 1317 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33763 6 : add_sibling_attributes (ctnode->root_die);
33764 :
33765 : /* AIX Assembler inserts the length, so adjust the reference to match the
33766 : offset expected by debuggers. */
33767 1311 : strcpy (dl_section_ref, debug_line_section_label);
33768 1311 : if (XCOFF_DEBUGGING_INFO)
33769 : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
33770 :
33771 1311 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33772 1311 : add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list, dl_section_ref);
33773 :
33774 1311 : if (have_macinfo)
33775 30 : add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
33776 : macinfo_section_label);
33777 :
33778 1311 : save_macinfo_strings ();
33779 :
33780 1311 : if (dwarf_split_debug_info)
33781 : {
33782 0 : unsigned int index = 0;
33783 0 : debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
33784 : }
33785 :
33786 : /* Output all of the compilation units. We put the main one last so that
33787 : the offsets are available to output_pubnames. */
33788 1311 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33789 0 : output_comp_unit (node->die, 0, NULL);
33790 :
33791 1311 : hash_table<comdat_type_hasher> comdat_type_table (100);
33792 1317 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33793 : {
33794 6 : comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
33795 :
33796 : /* Don't output duplicate types. */
33797 6 : if (*slot != HTAB_EMPTY_ENTRY)
33798 1 : continue;
33799 :
33800 : /* Add a pointer to the line table for the main compilation unit
33801 : so that the debugger can make sense of DW_AT_decl_file
33802 : attributes. */
33803 5 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33804 5 : add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
33805 5 : (!dwarf_split_debug_info
33806 : ? debug_line_section_label
33807 : : debug_skeleton_line_section_label));
33808 :
33809 5 : output_comdat_type_unit (ctnode, true);
33810 5 : *slot = ctnode;
33811 : }
33812 :
33813 : /* Stick a unique symbol to the main debuginfo section. */
33814 1311 : compute_comp_unit_symbol (comp_unit_die ());
33815 :
33816 : /* Output the main compilation unit. We always need it if only for
33817 : the CU symbol. */
33818 1311 : output_comp_unit (comp_unit_die (), true, NULL);
33819 :
33820 : /* Output the abbreviation table. */
33821 1311 : if (vec_safe_length (abbrev_die_table) != 1)
33822 : {
33823 1311 : switch_to_section (debug_abbrev_section);
33824 1311 : ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
33825 1311 : output_abbrev_section ();
33826 : }
33827 :
33828 : /* Have to end the macro section. */
33829 1311 : if (have_macinfo)
33830 : {
33831 : /* We have to save macinfo state if we need to output it again
33832 : for the FAT part of the object. */
33833 15 : vec<macinfo_entry, va_gc> *saved_macinfo_table = macinfo_table;
33834 15 : if (flag_fat_lto_objects)
33835 3 : macinfo_table = macinfo_table->copy ();
33836 :
33837 15 : switch_to_section (debug_macinfo_section);
33838 15 : ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
33839 15 : output_macinfo (debug_line_section_label, true);
33840 15 : dw2_asm_output_data (1, 0, "End compilation unit");
33841 :
33842 15 : if (flag_fat_lto_objects)
33843 : {
33844 3 : vec_free (macinfo_table);
33845 3 : macinfo_table = saved_macinfo_table;
33846 : }
33847 : }
33848 :
33849 : /* Emit a skeleton debug_line section. */
33850 1311 : switch_to_section (debug_line_section);
33851 1311 : ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
33852 1311 : output_line_info (true);
33853 :
33854 : /* If we emitted any indirect strings, output the string table too. */
33855 1311 : if (debug_str_hash || skeleton_debug_str_hash)
33856 1311 : output_indirect_strings ();
33857 1311 : if (debug_line_str_hash)
33858 : {
33859 1264 : switch_to_section (debug_line_str_section);
33860 1264 : const enum dwarf_form form = DW_FORM_line_strp;
33861 1264 : debug_line_str_hash->traverse<enum dwarf_form,
33862 1264 : output_indirect_string> (form);
33863 : }
33864 :
33865 : /* Switch back to the text section. */
33866 1311 : switch_to_section (text_section);
33867 53131 : }
33868 :
33869 : /* Reset all state within dwarf2out.cc so that we can rerun the compiler
33870 : within the same process. For use by toplev::finalize. */
33871 :
33872 : void
33873 256621 : dwarf2out_cc_finalize (void)
33874 : {
33875 256621 : last_var_location_insn = NULL;
33876 256621 : cached_next_real_insn = NULL;
33877 256621 : used_rtx_array = NULL;
33878 256621 : incomplete_types = NULL;
33879 256621 : debug_info_section = NULL;
33880 256621 : debug_skeleton_info_section = NULL;
33881 256621 : debug_abbrev_section = NULL;
33882 256621 : debug_skeleton_abbrev_section = NULL;
33883 256621 : debug_aranges_section = NULL;
33884 256621 : debug_addr_section = NULL;
33885 256621 : debug_macinfo_section = NULL;
33886 256621 : debug_line_section = NULL;
33887 256621 : debug_skeleton_line_section = NULL;
33888 256621 : debug_loc_section = NULL;
33889 256621 : debug_pubnames_section = NULL;
33890 256621 : debug_pubtypes_section = NULL;
33891 256621 : debug_str_section = NULL;
33892 256621 : debug_line_str_section = NULL;
33893 256621 : debug_str_dwo_section = NULL;
33894 256621 : debug_str_offsets_section = NULL;
33895 256621 : debug_ranges_section = NULL;
33896 256621 : debug_ranges_dwo_section = NULL;
33897 256621 : debug_frame_section = NULL;
33898 256621 : fde_vec = NULL;
33899 256621 : debug_str_hash = NULL;
33900 256621 : debug_line_str_hash = NULL;
33901 256621 : skeleton_debug_str_hash = NULL;
33902 256621 : dw2_string_counter = 0;
33903 256621 : have_multiple_function_sections = false;
33904 256621 : in_text_section_p = false;
33905 256621 : cold_text_section = NULL;
33906 256621 : last_text_label = NULL;
33907 256621 : last_cold_label = NULL;
33908 256621 : switch_text_ranges = NULL;
33909 256621 : switch_cold_ranges = NULL;
33910 256621 : current_unit_personality = NULL;
33911 256621 : btf_tag_htab = NULL;
33912 :
33913 256621 : early_dwarf = false;
33914 256621 : early_dwarf_finished = false;
33915 :
33916 256621 : next_die_offset = 0;
33917 256621 : single_comp_unit_die = NULL;
33918 256621 : comdat_type_list = NULL;
33919 256621 : limbo_die_list = NULL;
33920 256621 : file_table = NULL;
33921 256621 : decl_die_table = NULL;
33922 256621 : common_block_die_table = NULL;
33923 256621 : decl_loc_table = NULL;
33924 256621 : call_arg_locations = NULL;
33925 256621 : call_arg_loc_last = NULL;
33926 256621 : call_site_count = -1;
33927 256621 : tail_call_site_count = -1;
33928 256621 : cached_dw_loc_list_table = NULL;
33929 256621 : abbrev_die_table = NULL;
33930 309899 : delete dwarf_proc_stack_usage_map;
33931 256621 : dwarf_proc_stack_usage_map = NULL;
33932 256621 : line_info_label_num = 0;
33933 256621 : cur_line_info_table = NULL;
33934 256621 : text_section_line_info = NULL;
33935 256621 : cold_text_section_line_info = NULL;
33936 256621 : separate_line_info = NULL;
33937 256621 : info_section_emitted = false;
33938 256621 : pubname_table = NULL;
33939 256621 : pubtype_table = NULL;
33940 256621 : macinfo_table = NULL;
33941 256621 : ranges_table = NULL;
33942 256621 : ranges_by_label = NULL;
33943 256621 : rnglist_idx = 0;
33944 256621 : have_location_lists = false;
33945 256621 : loclabel_num = 0;
33946 256621 : poc_label_num = 0;
33947 256621 : last_emitted_file = NULL;
33948 256621 : label_num = 0;
33949 256621 : tmpl_value_parm_die_table = NULL;
33950 256621 : generic_type_instances = NULL;
33951 256621 : frame_pointer_fb_offset = 0;
33952 256621 : frame_pointer_fb_offset_valid = false;
33953 256621 : base_types.release ();
33954 256621 : XDELETEVEC (producer_string);
33955 256621 : producer_string = NULL;
33956 256621 : output_line_info_generation = 0;
33957 256621 : init_sections_and_labels_generation = 0;
33958 256621 : }
33959 :
33960 : #include "gt-dwarf2out.h"
|