Branch data Line data Source code
1 : : /* Output Dwarf2 format symbol table information from GCC.
2 : : Copyright (C) 1992-2025 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 : 1849 : get_full_len (const dw_wide_int &op)
402 : : {
403 : 1849 : return CEIL (op.get_precision (), HOST_BITS_PER_WIDE_INT);
404 : : }
405 : :
406 : : static bool
407 : 99260652 : should_emit_struct_debug (tree type, enum debug_info_usage usage)
408 : : {
409 : 99260652 : if (debug_info_level <= DINFO_LEVEL_TERSE)
410 : : return false;
411 : :
412 : 99260649 : enum debug_struct_file criterion;
413 : 99260649 : tree type_decl;
414 : 99260649 : bool generic = lang_hooks.types.generic_p (type);
415 : :
416 : 99260649 : if (generic)
417 : 77672178 : criterion = debug_struct_generic[usage];
418 : : else
419 : 21588471 : criterion = debug_struct_ordinary[usage];
420 : :
421 : 99260649 : if (criterion == DINFO_STRUCT_FILE_NONE)
422 : : return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
423 : 99260438 : 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 : 39623203 : dw_cfi_oprnd1_desc (dwarf_call_frame_info cfi)
520 : : {
521 : 39623203 : 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 : 13091551 : case DW_CFA_offset:
536 : 13091551 : case DW_CFA_offset_extended:
537 : 13091551 : case DW_CFA_def_cfa:
538 : 13091551 : case DW_CFA_offset_extended_sf:
539 : 13091551 : case DW_CFA_def_cfa_sf:
540 : 13091551 : case DW_CFA_restore:
541 : 13091551 : case DW_CFA_restore_extended:
542 : 13091551 : case DW_CFA_undefined:
543 : 13091551 : case DW_CFA_same_value:
544 : 13091551 : case DW_CFA_def_cfa_register:
545 : 13091551 : case DW_CFA_register:
546 : 13091551 : case DW_CFA_expression:
547 : 13091551 : case DW_CFA_val_expression:
548 : 13091551 : return dw_cfi_oprnd_reg_num;
549 : :
550 : 24493521 : case DW_CFA_def_cfa_offset:
551 : 24493521 : case DW_CFA_GNU_args_size:
552 : 24493521 : case DW_CFA_def_cfa_offset_sf:
553 : 24493521 : return dw_cfi_oprnd_offset;
554 : :
555 : 13553 : case DW_CFA_def_cfa_expression:
556 : 13553 : 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 : 39623203 : dw_cfi_oprnd2_desc (dwarf_call_frame_info cfi)
573 : : {
574 : 39623203 : 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 : 203033 : case DW_CFA_expression:
587 : 203033 : case DW_CFA_val_expression:
588 : 203033 : return dw_cfi_oprnd_loc;
589 : :
590 : 13553 : case DW_CFA_def_cfa_expression:
591 : 13553 : return dw_cfi_oprnd_cfa_loc;
592 : :
593 : 32769722 : default:
594 : 32769722 : 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 : 258911 : output_call_frame_info (int for_eh)
758 : : {
759 : 258911 : unsigned int i;
760 : 258911 : dw_fde_ref fde;
761 : 258911 : dw_cfi_ref cfi;
762 : 258911 : char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
763 : 258911 : char section_start_label[MAX_ARTIFICIAL_LABEL_BYTES];
764 : 258911 : bool any_lsda_needed = false;
765 : 258911 : char augmentation[6];
766 : 258911 : int augmentation_size;
767 : 258911 : int fde_encoding = DW_EH_PE_absptr;
768 : 258911 : int per_encoding = DW_EH_PE_absptr;
769 : 258911 : int lsda_encoding = DW_EH_PE_absptr;
770 : 258911 : int return_reg;
771 : 258911 : rtx personality = NULL;
772 : 258911 : int dw_cie_version;
773 : :
774 : : /* Don't emit a CIE if there won't be any FDEs. */
775 : 258911 : if (!fde_vec)
776 : 258892 : return;
777 : :
778 : : /* Nothing to do if the assembler's doing it all. */
779 : 254115 : 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 : 1517069 : dwarf2out_do_cfi_startproc (bool second)
981 : : {
982 : 1517069 : int enc;
983 : 1517069 : rtx ref;
984 : :
985 : 1517069 : fprintf (asm_out_file, "\t.cfi_startproc\n");
986 : :
987 : 1517069 : 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 : 1517069 : if (targetm_common.except_unwind_info (&global_options) != UI_DWARF2)
992 : : return;
993 : :
994 : 1517069 : rtx personality = get_personality_function (current_function_decl);
995 : :
996 : 1517069 : if (personality)
997 : : {
998 : 78909 : enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
999 : 78909 : 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 : 78909 : if (enc & DW_EH_PE_indirect)
1006 : : {
1007 : 5977 : if (targetm.asm_out.make_eh_symbol_indirect != NULL)
1008 : 0 : ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
1009 : : else
1010 : 5977 : ref = dw2_force_const_mem (ref, true);
1011 : : }
1012 : :
1013 : 78909 : fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
1014 : 78909 : output_addr_const (asm_out_file, ref);
1015 : 78909 : fputc ('\n', asm_out_file);
1016 : : }
1017 : :
1018 : 1517069 : if (crtl->uses_eh_lsda)
1019 : : {
1020 : 78846 : char lab[MAX_ARTIFICIAL_LABEL_BYTES];
1021 : :
1022 : 78846 : enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1023 : 143807 : ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
1024 : : current_function_funcdef_no);
1025 : 84687 : ref = gen_rtx_SYMBOL_REF (Pmode, lab);
1026 : 78846 : SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
1027 : :
1028 : 78846 : 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 : 78846 : fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
1037 : 78846 : output_addr_const (asm_out_file, ref);
1038 : 78846 : 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 : 1455149 : dwarf2out_alloc_current_fde (void)
1047 : : {
1048 : 1455149 : dw_fde_ref fde;
1049 : :
1050 : 1455149 : fde = ggc_cleared_alloc<dw_fde_node> ();
1051 : 1455149 : fde->decl = current_function_decl;
1052 : 1455149 : fde->funcdef_number = current_function_funcdef_no;
1053 : 1455149 : fde->fde_index = vec_safe_length (fde_vec);
1054 : 1455149 : fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
1055 : 1455149 : fde->uses_eh_lsda = crtl->uses_eh_lsda;
1056 : 1455149 : fde->nothrow = crtl->nothrow;
1057 : 1455149 : fde->drap_reg = INVALID_REGNUM;
1058 : 1455149 : fde->vdrap_reg = INVALID_REGNUM;
1059 : :
1060 : : /* Record the FDE associated with this function. */
1061 : 1455149 : cfun->fde = fde;
1062 : 1455149 : vec_safe_push (fde_vec, fde);
1063 : :
1064 : 1455149 : 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 : 1455204 : dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
1072 : : unsigned int column ATTRIBUTE_UNUSED,
1073 : : const char *file ATTRIBUTE_UNUSED)
1074 : : {
1075 : 1455204 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1076 : 1455204 : char * dup_label;
1077 : 1455204 : dw_fde_ref fde;
1078 : 1455204 : section *fnsec;
1079 : 1455204 : bool do_frame;
1080 : :
1081 : 1455204 : current_function_func_begin_label = NULL;
1082 : :
1083 : 1455204 : 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 : 1455204 : if (!do_frame
1088 : 1455204 : && (!flag_exceptions
1089 : 0 : || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
1090 : 55 : return;
1091 : :
1092 : 1455149 : fnsec = function_section (current_function_decl);
1093 : 1455149 : switch_to_section (fnsec);
1094 : 1455149 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1095 : : current_function_funcdef_no);
1096 : 1455149 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1097 : : current_function_funcdef_no);
1098 : 1455149 : dup_label = xstrdup (label);
1099 : 1455149 : current_function_func_begin_label = dup_label;
1100 : :
1101 : : /* We can elide FDE allocation if we're not emitting frame unwind info. */
1102 : 1455149 : 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 : 1455149 : 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 : 1455149 : fde = cfun->fde;
1114 : 1455149 : if (fde == NULL)
1115 : 5346 : fde = dwarf2out_alloc_current_fde ();
1116 : :
1117 : : /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1118 : 1455149 : fde->dw_fde_begin = dup_label;
1119 : 1455149 : fde->dw_fde_current_label = dup_label;
1120 : 2910298 : fde->in_std_section = (fnsec == text_section
1121 : 1455149 : || (cold_text_section && fnsec == cold_text_section));
1122 : 1455149 : fde->ignored_debug = DECL_IGNORED_P (current_function_decl);
1123 : 1455149 : 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 : 1455149 : if (file)
1129 : 461659 : dwarf2out_source_line (line, column, file, 0, true);
1130 : : #endif
1131 : :
1132 : 1455149 : if (dwarf2out_do_cfi_asm ())
1133 : 1455126 : 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 : 1517098 : mark_ignored_debug_section (dw_fde_ref fde, bool second)
1195 : : {
1196 : 1517098 : bool std_section;
1197 : 1517098 : const char *begin_label, *end_label;
1198 : 1517098 : const char **last_end_label;
1199 : 1517098 : vec<const char *, va_gc> **switch_ranges;
1200 : :
1201 : 1517098 : if (second)
1202 : : {
1203 : 61949 : std_section = fde->second_in_std_section;
1204 : 61949 : begin_label = fde->dw_fde_second_begin;
1205 : 61949 : end_label = fde->dw_fde_second_end;
1206 : : }
1207 : : else
1208 : : {
1209 : 1455149 : std_section = fde->in_std_section;
1210 : 1455149 : begin_label = fde->dw_fde_begin;
1211 : 1455149 : end_label = fde->dw_fde_end;
1212 : : }
1213 : :
1214 : 1517098 : if (!std_section)
1215 : 367234 : return;
1216 : :
1217 : 1149864 : if (in_text_section_p)
1218 : : {
1219 : : last_end_label = &last_text_label;
1220 : : switch_ranges = &switch_text_ranges;
1221 : : }
1222 : : else
1223 : : {
1224 : 11331 : last_end_label = &last_cold_label;
1225 : 11331 : switch_ranges = &switch_cold_ranges;
1226 : : }
1227 : :
1228 : 1149864 : if (fde->ignored_debug)
1229 : : {
1230 : 14229 : if (*switch_ranges && !(vec_safe_length (*switch_ranges) & 1))
1231 : 6350 : vec_safe_push (*switch_ranges, *last_end_label);
1232 : : }
1233 : : else
1234 : : {
1235 : 1135635 : *last_end_label = end_label;
1236 : :
1237 : 1135635 : if (!*switch_ranges)
1238 : 182148 : vec_alloc (*switch_ranges, 16);
1239 : 953487 : else if (vec_safe_length (*switch_ranges) & 1)
1240 : 3947 : 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 : 1455149 : dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1250 : : const char *file ATTRIBUTE_UNUSED)
1251 : : {
1252 : 1455149 : dw_fde_ref fde;
1253 : 1455149 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1254 : :
1255 : 1455149 : last_var_location_insn = NULL;
1256 : 1455149 : cached_next_real_insn = NULL;
1257 : :
1258 : 1455149 : if (dwarf2out_do_cfi_asm ())
1259 : 1455126 : 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 : 1455149 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
1269 : : current_function_funcdef_no);
1270 : 1455149 : ASM_OUTPUT_LABEL (asm_out_file, label);
1271 : 1455149 : fde = cfun->fde;
1272 : 1455149 : gcc_assert (fde != NULL);
1273 : 1455149 : if (fde->dw_fde_second_begin == NULL)
1274 : 1393200 : fde->dw_fde_end = xstrdup (label);
1275 : :
1276 : 1455149 : mark_ignored_debug_section (fde, fde->dw_fde_second_begin != NULL);
1277 : 1455149 : }
1278 : :
1279 : : void
1280 : 228345 : dwarf2out_frame_finish (void)
1281 : : {
1282 : : /* Output call frame information. */
1283 : 228345 : if (targetm.debug_unwind_info () == UI_DWARF2)
1284 : 51974 : output_call_frame_info (0);
1285 : :
1286 : : /* Output another copy for the unwinder. */
1287 : 228345 : if (do_eh_frame)
1288 : 206937 : output_call_frame_info (1);
1289 : 228345 : }
1290 : :
1291 : : static void var_location_switch_text_section (void);
1292 : : static void set_cur_line_info_table (section *);
1293 : :
1294 : : void
1295 : 61949 : dwarf2out_switch_text_section (void)
1296 : : {
1297 : 61949 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
1298 : 61949 : section *sect;
1299 : 61949 : dw_fde_ref fde = cfun->fde;
1300 : :
1301 : 61949 : gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
1302 : :
1303 : 61949 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_SECOND_SECT_LABEL,
1304 : : current_function_funcdef_no);
1305 : :
1306 : 61949 : fde->dw_fde_second_begin = ggc_strdup (label);
1307 : 61949 : 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 : 61949 : fde->dw_fde_end = crtl->subsections.hot_section_end_label;
1315 : 61949 : fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
1316 : : }
1317 : 61949 : 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 : 61949 : if (dwarf2out_do_cfi_asm ())
1325 : 61943 : fprintf (asm_out_file, "\t.cfi_endproc\n");
1326 : :
1327 : 61949 : mark_ignored_debug_section (fde, false);
1328 : :
1329 : : /* Now do the real section switch. */
1330 : 61949 : sect = current_function_section ();
1331 : 61949 : switch_to_section (sect);
1332 : :
1333 : 61949 : fde->second_in_std_section
1334 : 123898 : = (sect == text_section
1335 : 61949 : || (cold_text_section && sect == cold_text_section));
1336 : 61949 : in_text_section_p = sect == text_section;
1337 : :
1338 : 61949 : if (dwarf2out_do_cfi_asm ())
1339 : 61943 : dwarf2out_do_cfi_startproc (true);
1340 : :
1341 : 61949 : var_location_switch_text_section ();
1342 : :
1343 : 61949 : if (cold_text_section != NULL)
1344 : 20262 : set_cur_line_info_table (sect);
1345 : 61949 : }
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 : 60489252 : dwarf_stack_op_name (unsigned int op)
1377 : : {
1378 : 0 : const char *name = get_DW_OP_name (op);
1379 : :
1380 : 60489252 : if (name != NULL)
1381 : 60489252 : 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 : 56669383 : dwarf2out_locviews_in_attribute ()
1392 : : {
1393 : 56669383 : 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 : 23598209 : dwarf2out_locviews_in_loclist ()
1401 : : {
1402 : : #ifndef DW_LLE_view_pair
1403 : : return false;
1404 : : #else
1405 : 23598209 : 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 : 63469729 : new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
1415 : : unsigned HOST_WIDE_INT oprnd2)
1416 : : {
1417 : 63469729 : dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
1418 : :
1419 : 63469729 : descr->dw_loc_opc = op;
1420 : 63469729 : descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
1421 : 63469729 : descr->dw_loc_oprnd1.val_entry = NULL;
1422 : 63469729 : descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
1423 : 63469729 : descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
1424 : 63469729 : descr->dw_loc_oprnd2.val_entry = NULL;
1425 : 63469729 : descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
1426 : :
1427 : 63469729 : return descr;
1428 : : }
1429 : :
1430 : : /* Add a location description term to a location description expression. */
1431 : :
1432 : : static inline void
1433 : 20585770 : add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
1434 : : {
1435 : 20585770 : dw_loc_descr_ref *d;
1436 : :
1437 : : /* Find the end of the chain. */
1438 : 112666433 : for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
1439 : : ;
1440 : :
1441 : 20822670 : *d = descr;
1442 : 15512168 : }
1443 : :
1444 : : /* Compare two location operands for exact equality. */
1445 : :
1446 : : static bool
1447 : 20324204 : dw_val_equal_p (dw_val_node *a, dw_val_node *b)
1448 : : {
1449 : 20324204 : if (a->val_class != b->val_class)
1450 : : return false;
1451 : 20324204 : 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 : 13818102 : case dw_val_class_offset:
1459 : 13818102 : case dw_val_class_unsigned_const:
1460 : 13818102 : case dw_val_class_const:
1461 : 13818102 : case dw_val_class_unsigned_const_implicit:
1462 : 13818102 : case dw_val_class_const_implicit:
1463 : 13818102 : case dw_val_class_range_list:
1464 : : /* These are all HOST_WIDE_INT, signed or unsigned. */
1465 : 13818102 : 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 : 6506102 : case dw_val_class_file:
1490 : 6506102 : case dw_val_class_file_implicit:
1491 : 6506102 : 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 : 819532 : loc_descr_plus_const (dw_loc_descr_ref *list_head, poly_int64 poly_offset)
1570 : : {
1571 : 819532 : dw_loc_descr_ref loc;
1572 : 819532 : HOST_WIDE_INT *p;
1573 : :
1574 : 819532 : gcc_assert (*list_head != NULL);
1575 : :
1576 : 819532 : if (known_eq (poly_offset, 0))
1577 : 819532 : return;
1578 : :
1579 : : /* Find the end of the chain. */
1580 : 3168979 : for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
1581 : : ;
1582 : :
1583 : 812616 : HOST_WIDE_INT offset;
1584 : 812616 : 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 : 812616 : p = NULL;
1592 : 812616 : if (loc->dw_loc_opc == DW_OP_fbreg
1593 : 812616 : || (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 : 812616 : 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 : 812616 : else if (offset > 0)
1606 : 654112 : loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
1607 : :
1608 : : else
1609 : : {
1610 : 158504 : loc->dw_loc_next
1611 : 158504 : = uint_loc_descriptor (-(unsigned HOST_WIDE_INT) offset);
1612 : 317008 : 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 : 4853132 : new_reg_loc_descr (unsigned int reg, poly_int64 offset)
1621 : : {
1622 : 4853132 : HOST_WIDE_INT const_offset;
1623 : 4853132 : if (offset.is_constant (&const_offset))
1624 : : {
1625 : 4853132 : if (reg <= 31)
1626 : 4853132 : return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
1627 : 4853132 : 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 : 73446 : loc_list_plus_const (dw_loc_list_ref list_head, poly_int64 offset)
1643 : : {
1644 : 73446 : dw_loc_list_ref d;
1645 : 146892 : for (d = list_head; d != NULL; d = d->dw_loc_next)
1646 : 73446 : 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 : 3640684 : dwarf_OP (enum dwarf_location_atom op)
1662 : : {
1663 : 1710704 : switch (op)
1664 : : {
1665 : 1916991 : case DW_OP_implicit_pointer:
1666 : 0 : if (dwarf_version < 5)
1667 : 466 : return DW_OP_GNU_implicit_pointer;
1668 : : break;
1669 : :
1670 : 1336931 : case DW_OP_entry_value:
1671 : 1336931 : if (dwarf_version < 5)
1672 : 806 : return DW_OP_GNU_entry_value;
1673 : : break;
1674 : :
1675 : 47700 : case DW_OP_const_type:
1676 : 47700 : if (dwarf_version < 5)
1677 : 9 : return DW_OP_GNU_const_type;
1678 : : break;
1679 : :
1680 : 105129 : case DW_OP_regval_type:
1681 : 105129 : if (dwarf_version < 5)
1682 : 111 : return DW_OP_GNU_regval_type;
1683 : : break;
1684 : :
1685 : 60801 : case DW_OP_deref_type:
1686 : 60801 : if (dwarf_version < 5)
1687 : 0 : return DW_OP_GNU_deref_type;
1688 : : break;
1689 : :
1690 : 171543 : case DW_OP_convert:
1691 : 158557 : if (dwarf_version < 5)
1692 : 0 : return DW_OP_GNU_convert;
1693 : : break;
1694 : :
1695 : 1586 : case DW_OP_reinterpret:
1696 : 1586 : 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 : 9371306 : dwarf_AT (enum dwarf_attribute at)
1719 : : {
1720 : 9371306 : switch (at)
1721 : : {
1722 : 2884647 : case DW_AT_call_return_pc:
1723 : 2884647 : if (dwarf_version < 5)
1724 : 1853 : return DW_AT_low_pc;
1725 : : break;
1726 : :
1727 : 55823 : case DW_AT_call_tail_call:
1728 : 55823 : if (dwarf_version < 5)
1729 : 90 : return DW_AT_GNU_tail_call;
1730 : : break;
1731 : :
1732 : 2808040 : case DW_AT_call_origin:
1733 : 2808040 : if (dwarf_version < 5)
1734 : 1831 : return DW_AT_abstract_origin;
1735 : : break;
1736 : :
1737 : 4869 : case DW_AT_call_target:
1738 : 4869 : 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 : 30722 : case DW_AT_call_parameter:
1748 : 30722 : if (dwarf_version < 5)
1749 : 6 : return DW_AT_abstract_origin;
1750 : : break;
1751 : :
1752 : 3023696 : case DW_AT_call_value:
1753 : 3023696 : if (dwarf_version < 5)
1754 : 1485 : return DW_AT_GNU_call_site_value;
1755 : : break;
1756 : :
1757 : 8147 : case DW_AT_call_data_value:
1758 : 8147 : if (dwarf_version < 5)
1759 : 0 : return DW_AT_GNU_call_site_data_value;
1760 : : break;
1761 : :
1762 : 254996 : case DW_AT_call_all_calls:
1763 : 254996 : if (dwarf_version < 5)
1764 : 2350 : return DW_AT_GNU_all_call_sites;
1765 : : break;
1766 : :
1767 : 299873 : case DW_AT_call_all_tail_calls:
1768 : 299873 : if (dwarf_version < 5)
1769 : 999 : 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 : 5908343 : dwarf_TAG (enum dwarf_tag tag)
1791 : : {
1792 : 5908343 : switch (tag)
1793 : : {
1794 : 2884647 : case DW_TAG_call_site:
1795 : 2884647 : if (dwarf_version < 5)
1796 : 1853 : return DW_TAG_GNU_call_site;
1797 : : break;
1798 : :
1799 : 3023696 : case DW_TAG_call_site_parameter:
1800 : 3023696 : if (dwarf_version < 5)
1801 : 1485 : 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 : 25527087 : dwarf_FORM (enum dwarf_form form)
1813 : : {
1814 : 25527087 : 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 : 25526581 : case DW_FORM_strx:
1822 : 25526581 : if (dwarf_version < 5)
1823 : 270011 : 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 : 179871597 : size_of_loc_descr (dw_loc_descr_ref loc)
1838 : : {
1839 : 179871597 : unsigned long size = 1;
1840 : :
1841 : 179871597 : switch (loc->dw_loc_opc)
1842 : : {
1843 : 3221983 : case DW_OP_addr:
1844 : 3221983 : size += DWARF2_ADDR_SIZE;
1845 : 3221983 : 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 : 3819451 : size += 1;
1856 : : break;
1857 : : case DW_OP_const2u:
1858 : : case DW_OP_const2s:
1859 : 1029477 : size += 2;
1860 : : break;
1861 : : case DW_OP_const4u:
1862 : : case DW_OP_const4s:
1863 : 956150 : size += 4;
1864 : : break;
1865 : 7341 : case DW_OP_const8u:
1866 : 7341 : case DW_OP_const8s:
1867 : 7341 : size += 8;
1868 : 7341 : break;
1869 : 311525 : case DW_OP_constu:
1870 : 311525 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1871 : 311525 : break;
1872 : 102990 : case DW_OP_consts:
1873 : 102990 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1874 : 102990 : break;
1875 : : case DW_OP_pick:
1876 : 3819451 : size += 1;
1877 : : break;
1878 : 3555940 : case DW_OP_plus_uconst:
1879 : 3555940 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1880 : 3555940 : break;
1881 : : case DW_OP_skip:
1882 : : case DW_OP_bra:
1883 : 1029477 : size += 2;
1884 : : break;
1885 : 13791187 : case DW_OP_breg0:
1886 : 13791187 : case DW_OP_breg1:
1887 : 13791187 : case DW_OP_breg2:
1888 : 13791187 : case DW_OP_breg3:
1889 : 13791187 : case DW_OP_breg4:
1890 : 13791187 : case DW_OP_breg5:
1891 : 13791187 : case DW_OP_breg6:
1892 : 13791187 : case DW_OP_breg7:
1893 : 13791187 : case DW_OP_breg8:
1894 : 13791187 : case DW_OP_breg9:
1895 : 13791187 : case DW_OP_breg10:
1896 : 13791187 : case DW_OP_breg11:
1897 : 13791187 : case DW_OP_breg12:
1898 : 13791187 : case DW_OP_breg13:
1899 : 13791187 : case DW_OP_breg14:
1900 : 13791187 : case DW_OP_breg15:
1901 : 13791187 : case DW_OP_breg16:
1902 : 13791187 : case DW_OP_breg17:
1903 : 13791187 : case DW_OP_breg18:
1904 : 13791187 : case DW_OP_breg19:
1905 : 13791187 : case DW_OP_breg20:
1906 : 13791187 : case DW_OP_breg21:
1907 : 13791187 : case DW_OP_breg22:
1908 : 13791187 : case DW_OP_breg23:
1909 : 13791187 : case DW_OP_breg24:
1910 : 13791187 : case DW_OP_breg25:
1911 : 13791187 : case DW_OP_breg26:
1912 : 13791187 : case DW_OP_breg27:
1913 : 13791187 : case DW_OP_breg28:
1914 : 13791187 : case DW_OP_breg29:
1915 : 13791187 : case DW_OP_breg30:
1916 : 13791187 : case DW_OP_breg31:
1917 : 13791187 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1918 : 13791187 : break;
1919 : 52345 : case DW_OP_regx:
1920 : 52345 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1921 : 52345 : break;
1922 : 22250826 : case DW_OP_fbreg:
1923 : 22250826 : size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
1924 : 22250826 : 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 : 15530334 : case DW_OP_piece:
1930 : 15530334 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1931 : 15530334 : break;
1932 : 820452 : case DW_OP_bit_piece:
1933 : 820452 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
1934 : 820452 : size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
1935 : 820452 : break;
1936 : : case DW_OP_deref_size:
1937 : : case DW_OP_xderef_size:
1938 : 3819451 : size += 1;
1939 : : break;
1940 : : case DW_OP_call2:
1941 : 1029477 : size += 2;
1942 : : break;
1943 : : case DW_OP_call4:
1944 : 956150 : 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 : 332263 : case DW_OP_implicit_value:
1951 : 332263 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1952 : 332263 : + loc->dw_loc_oprnd1.v.val_unsigned;
1953 : 332263 : break;
1954 : 3649577 : case DW_OP_implicit_pointer:
1955 : 3649577 : case DW_OP_GNU_implicit_pointer:
1956 : 3649577 : size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
1957 : 3649577 : break;
1958 : 3786163 : case DW_OP_entry_value:
1959 : 3786163 : case DW_OP_GNU_entry_value:
1960 : 3786163 : {
1961 : 3786163 : unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
1962 : 3786163 : size += size_of_uleb128 (op_size) + op_size;
1963 : 3786163 : break;
1964 : : }
1965 : 115196 : case DW_OP_const_type:
1966 : 115196 : case DW_OP_GNU_const_type:
1967 : 115196 : {
1968 : 115196 : unsigned long o
1969 : 115196 : = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
1970 : 115196 : size += size_of_uleb128 (o) + 1;
1971 : 115196 : switch (loc->dw_loc_oprnd2.val_class)
1972 : : {
1973 : 88668 : case dw_val_class_vec:
1974 : 88668 : size += loc->dw_loc_oprnd2.v.val_vec.length
1975 : 88668 : * loc->dw_loc_oprnd2.v.val_vec.elt_size;
1976 : 88668 : break;
1977 : 26132 : case dw_val_class_const:
1978 : 26132 : size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
1979 : 26132 : break;
1980 : 62 : case dw_val_class_const_double:
1981 : 62 : size += HOST_BITS_PER_DOUBLE_INT / BITS_PER_UNIT;
1982 : 62 : break;
1983 : 334 : case dw_val_class_wide_int:
1984 : 334 : size += (get_full_len (*loc->dw_loc_oprnd2.v.val_wide)
1985 : 334 : * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
1986 : 334 : break;
1987 : 0 : default:
1988 : 0 : gcc_unreachable ();
1989 : : }
1990 : : break;
1991 : : }
1992 : 350334 : case DW_OP_regval_type:
1993 : 350334 : case DW_OP_GNU_regval_type:
1994 : 350334 : {
1995 : 350334 : unsigned long o
1996 : 350334 : = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
1997 : 350334 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
1998 : 350334 : + size_of_uleb128 (o);
1999 : : }
2000 : 350334 : break;
2001 : 168474 : case DW_OP_deref_type:
2002 : 168474 : case DW_OP_GNU_deref_type:
2003 : 168474 : {
2004 : 168474 : unsigned long o
2005 : 168474 : = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
2006 : 168474 : size += 1 + size_of_uleb128 (o);
2007 : : }
2008 : 168474 : break;
2009 : 505717 : case DW_OP_convert:
2010 : 505717 : case DW_OP_reinterpret:
2011 : 505717 : case DW_OP_GNU_convert:
2012 : 505717 : case DW_OP_GNU_reinterpret:
2013 : 505717 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2014 : 78870 : size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2015 : : else
2016 : : {
2017 : 426847 : unsigned long o
2018 : 426847 : = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
2019 : 426847 : size += size_of_uleb128 (o);
2020 : : }
2021 : : break;
2022 : : case DW_OP_GNU_parameter_ref:
2023 : 956150 : size += 4;
2024 : : break;
2025 : : default:
2026 : : break;
2027 : : }
2028 : :
2029 : 179871597 : return size;
2030 : : }
2031 : :
2032 : : /* Return the size of a series of location descriptors. */
2033 : :
2034 : : unsigned long
2035 : 91196802 : size_of_locs (dw_loc_descr_ref loc)
2036 : : {
2037 : 91196802 : dw_loc_descr_ref l;
2038 : 91196802 : 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 : 263267828 : for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2043 : : {
2044 : 172354044 : if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
2045 : : break;
2046 : 172071026 : size += size_of_loc_descr (l);
2047 : : }
2048 : 91196802 : if (! l)
2049 : : return size;
2050 : :
2051 : 7234058 : for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
2052 : : {
2053 : 6951040 : l->dw_loc_addr = size;
2054 : 6951040 : 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 : 60489222 : output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
2106 : : {
2107 : 60489222 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
2108 : 60489222 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
2109 : :
2110 : 60489222 : switch (loc->dw_loc_opc)
2111 : : {
2112 : : #ifdef DWARF2_DEBUGGING_INFO
2113 : 180395 : case DW_OP_const2u:
2114 : 180395 : case DW_OP_const2s:
2115 : 180395 : dw2_asm_output_data (2, val1->v.val_int, NULL);
2116 : 180395 : break;
2117 : 276050 : case DW_OP_const4u:
2118 : 276050 : if (loc->dw_loc_dtprel)
2119 : : {
2120 : 163 : gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2121 : 163 : targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
2122 : : val1->v.val_addr);
2123 : 163 : fputc ('\n', asm_out_file);
2124 : 163 : break;
2125 : : }
2126 : : /* FALLTHRU */
2127 : 275887 : case DW_OP_const4s:
2128 : 275887 : dw2_asm_output_data (4, val1->v.val_int, NULL);
2129 : 275887 : break;
2130 : 2542 : case DW_OP_const8u:
2131 : 2542 : if (loc->dw_loc_dtprel)
2132 : : {
2133 : 535 : gcc_assert (targetm.asm_out.output_dwarf_dtprel);
2134 : 535 : targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
2135 : : val1->v.val_addr);
2136 : 535 : fputc ('\n', asm_out_file);
2137 : 535 : break;
2138 : : }
2139 : : /* FALLTHRU */
2140 : 2007 : case DW_OP_const8s:
2141 : 2007 : gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
2142 : 2007 : dw2_asm_output_data (8, val1->v.val_int, NULL);
2143 : 2007 : break;
2144 : 129621 : case DW_OP_skip:
2145 : 129621 : case DW_OP_bra:
2146 : 129621 : {
2147 : 129621 : int offset;
2148 : :
2149 : 129621 : gcc_assert (val1->val_class == dw_val_class_loc);
2150 : 129621 : offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2151 : :
2152 : 129621 : dw2_asm_output_data (2, offset, NULL);
2153 : : }
2154 : 129621 : break;
2155 : 111929 : case DW_OP_implicit_value:
2156 : 111929 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2157 : 111929 : switch (val2->val_class)
2158 : : {
2159 : 44379 : case dw_val_class_const:
2160 : 44379 : dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
2161 : 44379 : break;
2162 : 67053 : case dw_val_class_vec:
2163 : 67053 : {
2164 : 67053 : unsigned int elt_size = val2->v.val_vec.elt_size;
2165 : 67053 : unsigned int len = val2->v.val_vec.length;
2166 : 67053 : unsigned int i;
2167 : 67053 : unsigned char *p;
2168 : :
2169 : 67053 : if (elt_size > sizeof (HOST_WIDE_INT))
2170 : : {
2171 : 0 : elt_size /= 2;
2172 : 0 : len *= 2;
2173 : : }
2174 : 67053 : for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
2175 : 311111 : i < len;
2176 : 244058 : i++, p += elt_size)
2177 : 488116 : 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 : 497 : case dw_val_class_wide_int:
2202 : 497 : {
2203 : 497 : int i;
2204 : 497 : int len = get_full_len (*val2->v.val_wide);
2205 : 497 : 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 : 1491 : for (i = 0; i < len; ++i)
2211 : 994 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
2212 : 994 : 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 : 1068536 : case DW_OP_const1u:
2240 : 1068536 : case DW_OP_const1s:
2241 : 1068536 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2242 : 1068536 : break;
2243 : 122306 : case DW_OP_constu:
2244 : 122306 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2245 : 122306 : break;
2246 : 23648 : case DW_OP_consts:
2247 : 23648 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2248 : 23648 : break;
2249 : 177 : case DW_OP_pick:
2250 : 177 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2251 : 177 : break;
2252 : 761006 : case DW_OP_plus_uconst:
2253 : 761006 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2254 : 761006 : break;
2255 : 4688688 : case DW_OP_breg0:
2256 : 4688688 : case DW_OP_breg1:
2257 : 4688688 : case DW_OP_breg2:
2258 : 4688688 : case DW_OP_breg3:
2259 : 4688688 : case DW_OP_breg4:
2260 : 4688688 : case DW_OP_breg5:
2261 : 4688688 : case DW_OP_breg6:
2262 : 4688688 : case DW_OP_breg7:
2263 : 4688688 : case DW_OP_breg8:
2264 : 4688688 : case DW_OP_breg9:
2265 : 4688688 : case DW_OP_breg10:
2266 : 4688688 : case DW_OP_breg11:
2267 : 4688688 : case DW_OP_breg12:
2268 : 4688688 : case DW_OP_breg13:
2269 : 4688688 : case DW_OP_breg14:
2270 : 4688688 : case DW_OP_breg15:
2271 : 4688688 : case DW_OP_breg16:
2272 : 4688688 : case DW_OP_breg17:
2273 : 4688688 : case DW_OP_breg18:
2274 : 4688688 : case DW_OP_breg19:
2275 : 4688688 : case DW_OP_breg20:
2276 : 4688688 : case DW_OP_breg21:
2277 : 4688688 : case DW_OP_breg22:
2278 : 4688688 : case DW_OP_breg23:
2279 : 4688688 : case DW_OP_breg24:
2280 : 4688688 : case DW_OP_breg25:
2281 : 4688688 : case DW_OP_breg26:
2282 : 4688688 : case DW_OP_breg27:
2283 : 4688688 : case DW_OP_breg28:
2284 : 4688688 : case DW_OP_breg29:
2285 : 4688688 : case DW_OP_breg30:
2286 : 4688688 : case DW_OP_breg31:
2287 : 4688688 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2288 : 4688688 : break;
2289 : 17443 : case DW_OP_regx:
2290 : 17443 : {
2291 : 17443 : unsigned r = val1->v.val_unsigned;
2292 : 17443 : if (for_eh_or_skip >= 0)
2293 : 17443 : r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
2294 : 17443 : gcc_assert (size_of_uleb128 (r)
2295 : : == size_of_uleb128 (val1->v.val_unsigned));
2296 : 17443 : dw2_asm_output_data_uleb128 (r, NULL);
2297 : : }
2298 : 17443 : break;
2299 : 7840352 : case DW_OP_fbreg:
2300 : 7840352 : dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2301 : 7840352 : 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 : 5173318 : case DW_OP_piece:
2314 : 5173318 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2315 : 5173318 : break;
2316 : 273484 : case DW_OP_bit_piece:
2317 : 273484 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2318 : 273484 : dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
2319 : 273484 : break;
2320 : 170712 : case DW_OP_deref_size:
2321 : 170712 : case DW_OP_xderef_size:
2322 : 170712 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2323 : 170712 : break;
2324 : :
2325 : 1355737 : case DW_OP_addr:
2326 : 1355737 : 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 : 1435148 : 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 : 1215986 : case DW_OP_implicit_pointer:
2385 : 1215986 : case DW_OP_GNU_implicit_pointer:
2386 : 1215986 : {
2387 : 1215986 : char label[MAX_ARTIFICIAL_LABEL_BYTES
2388 : : + HOST_BITS_PER_WIDE_INT / 2 + 2];
2389 : 1215986 : gcc_assert (val1->val_class == dw_val_class_die_ref);
2390 : 1215986 : get_ref_die_offset_label (label, val1->v.val_die_ref.die);
2391 : 1215986 : dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
2392 : 1215986 : dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2393 : : }
2394 : 1215986 : break;
2395 : :
2396 : 1331304 : case DW_OP_entry_value:
2397 : 1331304 : case DW_OP_GNU_entry_value:
2398 : 1331304 : dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
2399 : 1331304 : output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
2400 : 1331304 : break;
2401 : :
2402 : 41412 : case DW_OP_const_type:
2403 : 41412 : case DW_OP_GNU_const_type:
2404 : 41412 : {
2405 : 41412 : unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
2406 : 41412 : gcc_assert (o);
2407 : 41412 : dw2_asm_output_data_uleb128 (o, NULL);
2408 : 41412 : switch (val2->val_class)
2409 : : {
2410 : 8654 : case dw_val_class_const:
2411 : 8654 : l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2412 : 8654 : dw2_asm_output_data (1, l, NULL);
2413 : 8654 : dw2_asm_output_data (l, val2->v.val_int, NULL);
2414 : 8654 : break;
2415 : 32616 : case dw_val_class_vec:
2416 : 32616 : {
2417 : 32616 : unsigned int elt_size = val2->v.val_vec.elt_size;
2418 : 32616 : unsigned int len = val2->v.val_vec.length;
2419 : 32616 : unsigned int i;
2420 : 32616 : unsigned char *p;
2421 : :
2422 : 32616 : l = len * elt_size;
2423 : 32616 : dw2_asm_output_data (1, l, NULL);
2424 : 32616 : if (elt_size > sizeof (HOST_WIDE_INT))
2425 : : {
2426 : 0 : elt_size /= 2;
2427 : 0 : len *= 2;
2428 : : }
2429 : 32616 : for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
2430 : 102639 : i < len;
2431 : 70023 : i++, p += elt_size)
2432 : 140046 : dw2_asm_output_data (elt_size, extract_int (p, elt_size),
2433 : : "fp or vector constant word %u", i);
2434 : : }
2435 : : break;
2436 : 21 : case dw_val_class_const_double:
2437 : 21 : {
2438 : 21 : unsigned HOST_WIDE_INT first, second;
2439 : 21 : l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2440 : :
2441 : 21 : dw2_asm_output_data (1, 2 * l, NULL);
2442 : 21 : if (WORDS_BIG_ENDIAN)
2443 : : {
2444 : : first = val2->v.val_double.high;
2445 : : second = val2->v.val_double.low;
2446 : : }
2447 : : else
2448 : : {
2449 : 21 : first = val2->v.val_double.low;
2450 : 21 : second = val2->v.val_double.high;
2451 : : }
2452 : 21 : dw2_asm_output_data (l, first, NULL);
2453 : 21 : dw2_asm_output_data (l, second, NULL);
2454 : : }
2455 : 21 : break;
2456 : 121 : case dw_val_class_wide_int:
2457 : 121 : {
2458 : 121 : int i;
2459 : 121 : int len = get_full_len (*val2->v.val_wide);
2460 : 121 : l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
2461 : :
2462 : 121 : dw2_asm_output_data (1, len * l, NULL);
2463 : 121 : 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 : 484 : for (i = 0; i < len; ++i)
2468 : 242 : 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 : 102683 : case DW_OP_regval_type:
2477 : 102683 : case DW_OP_GNU_regval_type:
2478 : 102683 : {
2479 : 102683 : unsigned r = val1->v.val_unsigned;
2480 : 102683 : unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2481 : 102683 : gcc_assert (o);
2482 : 102683 : 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 : 102683 : dw2_asm_output_data_uleb128 (r, NULL);
2489 : 102683 : dw2_asm_output_data_uleb128 (o, NULL);
2490 : : }
2491 : 102683 : break;
2492 : 59202 : case DW_OP_deref_type:
2493 : 59202 : case DW_OP_GNU_deref_type:
2494 : 59202 : {
2495 : 59202 : unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
2496 : 59202 : gcc_assert (o);
2497 : 59202 : dw2_asm_output_data (1, val1->v.val_int, NULL);
2498 : 59202 : dw2_asm_output_data_uleb128 (o, NULL);
2499 : : }
2500 : 59202 : break;
2501 : 165985 : case DW_OP_convert:
2502 : 165985 : case DW_OP_reinterpret:
2503 : 165985 : case DW_OP_GNU_convert:
2504 : 165985 : case DW_OP_GNU_reinterpret:
2505 : 165985 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
2506 : 25597 : dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2507 : : else
2508 : : {
2509 : 140388 : unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
2510 : 140388 : gcc_assert (o);
2511 : 140388 : dw2_asm_output_data_uleb128 (o, NULL);
2512 : : }
2513 : : break;
2514 : :
2515 : 31346 : case DW_OP_GNU_parameter_ref:
2516 : 31346 : {
2517 : 31346 : unsigned long o;
2518 : 31346 : gcc_assert (val1->val_class == dw_val_class_die_ref);
2519 : 31346 : o = get_ref_die_offset (val1->v.val_die_ref.die);
2520 : 31346 : dw2_asm_output_data (4, o, NULL);
2521 : : }
2522 : 31346 : break;
2523 : :
2524 : : default:
2525 : : /* Other codes have no operands. */
2526 : : break;
2527 : : }
2528 : 60489222 : }
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 : 32663145 : output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
2539 : : {
2540 : 93152367 : for (; loc != NULL; loc = loc->dw_loc_next)
2541 : : {
2542 : 60489222 : enum dwarf_location_atom opc = loc->dw_loc_opc;
2543 : : /* Output the opcode. */
2544 : 60489222 : 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 : 60489222 : 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 : 120978444 : dw2_asm_output_data (1, opc,
2562 : : "%s", dwarf_stack_op_name (opc));
2563 : :
2564 : : /* Output the operand(s) (if any). */
2565 : 60489222 : output_loc_operands (loc, for_eh_or_skip);
2566 : : }
2567 : 32663145 : }
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 : 63300 : output_loc_operands_raw (dw_loc_descr_ref loc)
2574 : : {
2575 : 63300 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
2576 : 63300 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
2577 : :
2578 : 63300 : 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 : 54635 : case DW_OP_consts:
2654 : 54635 : case DW_OP_breg0:
2655 : 54635 : case DW_OP_breg1:
2656 : 54635 : case DW_OP_breg2:
2657 : 54635 : case DW_OP_breg3:
2658 : 54635 : case DW_OP_breg4:
2659 : 54635 : case DW_OP_breg5:
2660 : 54635 : case DW_OP_breg6:
2661 : 54635 : case DW_OP_breg7:
2662 : 54635 : case DW_OP_breg8:
2663 : 54635 : case DW_OP_breg9:
2664 : 54635 : case DW_OP_breg10:
2665 : 54635 : case DW_OP_breg11:
2666 : 54635 : case DW_OP_breg12:
2667 : 54635 : case DW_OP_breg13:
2668 : 54635 : case DW_OP_breg14:
2669 : 54635 : case DW_OP_breg15:
2670 : 54635 : case DW_OP_breg16:
2671 : 54635 : case DW_OP_breg17:
2672 : 54635 : case DW_OP_breg18:
2673 : 54635 : case DW_OP_breg19:
2674 : 54635 : case DW_OP_breg20:
2675 : 54635 : case DW_OP_breg21:
2676 : 54635 : case DW_OP_breg22:
2677 : 54635 : case DW_OP_breg23:
2678 : 54635 : case DW_OP_breg24:
2679 : 54635 : case DW_OP_breg25:
2680 : 54635 : case DW_OP_breg26:
2681 : 54635 : case DW_OP_breg27:
2682 : 54635 : case DW_OP_breg28:
2683 : 54635 : case DW_OP_breg29:
2684 : 54635 : case DW_OP_breg30:
2685 : 54635 : case DW_OP_breg31:
2686 : 54635 : case DW_OP_fbreg:
2687 : 54635 : fputc (',', asm_out_file);
2688 : 54635 : dw2_asm_output_data_sleb128_raw (val1->v.val_int);
2689 : 54635 : 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 : 63300 : }
2726 : :
2727 : : void
2728 : 54635 : output_loc_sequence_raw (dw_loc_descr_ref loc)
2729 : : {
2730 : 71965 : while (1)
2731 : : {
2732 : 63300 : enum dwarf_location_atom opc = loc->dw_loc_opc;
2733 : : /* Output the opcode. */
2734 : 63300 : 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 : 63300 : 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 : 63300 : fprintf (asm_out_file, "%#x", opc);
2750 : 63300 : output_loc_operands_raw (loc);
2751 : :
2752 : 63300 : if (!loc->dw_loc_next)
2753 : : break;
2754 : 8665 : loc = loc->dw_loc_next;
2755 : :
2756 : 8665 : fputc (',', asm_out_file);
2757 : 8665 : }
2758 : 54635 : }
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 : 16315 : build_cfa_loc (dw_cfa_location *cfa, poly_int64 offset)
2803 : : {
2804 : 16315 : struct dw_loc_descr_node *head, *tmp;
2805 : :
2806 : 16315 : offset += cfa->offset;
2807 : :
2808 : 16315 : 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 : 16315 : else if (cfa->indirect)
2816 : : {
2817 : 6916 : head = new_reg_loc_descr (cfa->reg.reg, cfa->base_offset);
2818 : 6916 : head->dw_loc_oprnd1.val_class = dw_val_class_const;
2819 : 6916 : head->dw_loc_oprnd1.val_entry = NULL;
2820 : 6916 : tmp = new_loc_descr (DW_OP_deref, 0, 0);
2821 : 6916 : add_loc_descr (&head, tmp);
2822 : 6916 : loc_descr_plus_const (&head, offset);
2823 : : }
2824 : : else
2825 : 9399 : head = new_reg_loc_descr (cfa->reg.reg, offset);
2826 : :
2827 : 16315 : 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 : 17749 : build_cfa_aligned_loc (dw_cfa_location *cfa,
2836 : : poly_int64 offset, HOST_WIDE_INT alignment)
2837 : : {
2838 : 17749 : struct dw_loc_descr_node *head;
2839 : 17749 : unsigned int dwarf_fp
2840 : 17749 : = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
2841 : :
2842 : : /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2843 : 17749 : 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 : 17749 : head = new_reg_loc_descr (dwarf_fp, offset);
2852 : 17749 : 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 : 42270670 : maybe_reset_location_view (rtx_insn *insn, dw_line_info_table *table)
3116 : : {
3117 : 42270670 : 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 : 73802614 : set_early_dwarf () : saved(early_dwarf)
3184 : : {
3185 : 73802614 : gcc_assert (! early_dwarf_finished);
3186 : 73802614 : early_dwarf = true;
3187 : 73802614 : }
3188 : 73802614 : ~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 : 284971 : dwarf2out_default_as_loc_support (void)
3348 : : {
3349 : 284971 : 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 : 284977 : dwarf2out_default_as_locview_support (void)
3361 : : {
3362 : 284977 : 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 : 45126251 : output_asm_line_debug_info (void)
3420 : : {
3421 : 45126251 : return (dwarf2out_as_loc_support
3422 : 45126251 : && (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 : : invokation 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 : : /* Flags to represent a set of attribute classes for attributes that represent
3700 : : a scalar value (bounds, pointers, ...). */
3701 : : enum dw_scalar_form
3702 : : {
3703 : : dw_scalar_form_constant = 0x01,
3704 : : dw_scalar_form_exprloc = 0x02,
3705 : : dw_scalar_form_reference = 0x04
3706 : : };
3707 : :
3708 : : /* Forward declarations for functions defined in this file. */
3709 : :
3710 : : static bool is_pseudo_reg (const_rtx);
3711 : : static tree type_main_variant (tree);
3712 : : static bool is_tagged_type (const_tree);
3713 : : static const char *dwarf_tag_name (unsigned);
3714 : : static const char *dwarf_attr_name (unsigned);
3715 : : static const char *dwarf_form_name (unsigned);
3716 : : static tree decl_ultimate_origin (const_tree);
3717 : : static tree decl_class_context (tree);
3718 : : static void add_dwarf_attr (dw_die_ref, dw_attr_node *);
3719 : : static inline unsigned int AT_index (dw_attr_node *);
3720 : : static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3721 : : static inline unsigned AT_flag (dw_attr_node *);
3722 : : static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3723 : : static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3724 : : static void add_AT_double (dw_die_ref, enum dwarf_attribute,
3725 : : HOST_WIDE_INT, unsigned HOST_WIDE_INT);
3726 : : static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3727 : : unsigned int, unsigned char *);
3728 : : static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
3729 : : static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3730 : : static inline const char *AT_string (dw_attr_node *);
3731 : : static enum dwarf_form AT_string_form (dw_attr_node *);
3732 : : static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3733 : : static void add_AT_specification (dw_die_ref, dw_die_ref);
3734 : : static inline dw_die_ref AT_ref (dw_attr_node *);
3735 : : static inline int AT_ref_external (dw_attr_node *);
3736 : : static inline void set_AT_ref_external (dw_attr_node *, int);
3737 : : static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3738 : : static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3739 : : dw_loc_list_ref);
3740 : : static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
3741 : : static void add_AT_view_list (dw_die_ref, enum dwarf_attribute);
3742 : : static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
3743 : : static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
3744 : : static void remove_addr_table_entry (addr_table_entry *);
3745 : : static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
3746 : : static inline rtx AT_addr (dw_attr_node *);
3747 : : static void add_AT_symview (dw_die_ref, enum dwarf_attribute, const char *);
3748 : : static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *,
3749 : : int = 0);
3750 : : static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
3751 : : static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
3752 : : static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3753 : : unsigned long, bool);
3754 : : static inline const char *AT_lbl (dw_attr_node *);
3755 : : static const char *get_AT_low_pc (dw_die_ref);
3756 : : static bool is_c (void);
3757 : : static bool is_cxx (void);
3758 : : static bool is_cxx (const_tree);
3759 : : static bool is_fortran (void);
3760 : : static bool is_ada (void);
3761 : : static bool remove_AT (dw_die_ref, enum dwarf_attribute);
3762 : : static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3763 : : static void add_child_die (dw_die_ref, dw_die_ref);
3764 : : static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3765 : : static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
3766 : : static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
3767 : : static void equate_type_number_to_die (tree, dw_die_ref);
3768 : : static var_loc_list *lookup_decl_loc (const_tree);
3769 : : static void equate_decl_number_to_die (tree, dw_die_ref);
3770 : : static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *, var_loc_view);
3771 : : static void print_spaces (FILE *);
3772 : : static void print_die (dw_die_ref, FILE *);
3773 : : static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3774 : : static void attr_checksum (dw_attr_node *, struct md5_ctx *, int *);
3775 : : static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3776 : : static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
3777 : : static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
3778 : : static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
3779 : : static void attr_checksum_ordered (enum dwarf_tag, dw_attr_node *,
3780 : : struct md5_ctx *, int *);
3781 : : struct checksum_attributes;
3782 : : static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
3783 : : static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
3784 : : static void checksum_die_context (dw_die_ref, struct md5_ctx *);
3785 : : static void generate_type_signature (dw_die_ref, comdat_type_node *);
3786 : : static bool same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3787 : : static bool same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
3788 : : static bool same_attr_p (dw_attr_node *, dw_attr_node *, int *);
3789 : : static bool same_die_p (dw_die_ref, dw_die_ref, int *);
3790 : : static bool is_type_die (dw_die_ref);
3791 : : static inline bool is_template_instantiation (dw_die_ref);
3792 : : static bool is_declaration_die (dw_die_ref);
3793 : : static bool should_move_die_to_comdat (dw_die_ref);
3794 : : static dw_die_ref clone_as_declaration (dw_die_ref);
3795 : : static dw_die_ref clone_die (dw_die_ref);
3796 : : static dw_die_ref clone_tree (dw_die_ref);
3797 : : static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
3798 : : static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
3799 : : static void generate_skeleton_bottom_up (skeleton_chain_node *);
3800 : : static dw_die_ref generate_skeleton (dw_die_ref);
3801 : : static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
3802 : : dw_die_ref,
3803 : : dw_die_ref);
3804 : : static void break_out_comdat_types (dw_die_ref);
3805 : : static void copy_decls_for_unworthy_types (dw_die_ref);
3806 : :
3807 : : static void add_sibling_attributes (dw_die_ref);
3808 : : static void output_location_lists (dw_die_ref);
3809 : : static int constant_size (unsigned HOST_WIDE_INT);
3810 : : static unsigned long size_of_die (dw_die_ref);
3811 : : static void calc_die_sizes (dw_die_ref);
3812 : : static void calc_base_type_die_sizes (void);
3813 : : static void mark_dies (dw_die_ref);
3814 : : static void unmark_dies (dw_die_ref);
3815 : : static void unmark_all_dies (dw_die_ref);
3816 : : static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
3817 : : static unsigned long size_of_aranges (void);
3818 : : static enum dwarf_form value_format (dw_attr_node *);
3819 : : static void output_value_format (dw_attr_node *);
3820 : : static void output_abbrev_section (void);
3821 : : static void output_die_abbrevs (unsigned long, dw_die_ref);
3822 : : static void output_die (dw_die_ref);
3823 : : static void output_compilation_unit_header (enum dwarf_unit_type);
3824 : : static void output_comp_unit (dw_die_ref, int, const unsigned char *);
3825 : : static void output_comdat_type_unit (comdat_type_node *, bool);
3826 : : static const char *dwarf2_name (tree, int);
3827 : : static void add_pubname (tree, dw_die_ref);
3828 : : static void add_enumerator_pubname (const char *, dw_die_ref);
3829 : : static void add_pubname_string (const char *, dw_die_ref);
3830 : : static void add_pubtype (tree, dw_die_ref);
3831 : : static void output_pubnames (vec<pubname_entry, va_gc> *);
3832 : : static void output_aranges (void);
3833 : : static unsigned int add_ranges (const_tree, bool = false);
3834 : : static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
3835 : : bool *, bool);
3836 : : static void output_ranges (void);
3837 : : static dw_line_info_table *new_line_info_table (void);
3838 : : static void output_line_info (bool);
3839 : : static void output_file_names (void);
3840 : : static bool is_base_type (tree);
3841 : : static dw_die_ref subrange_type_die (tree, tree, tree, tree, dw_die_ref);
3842 : : static int decl_quals (const_tree);
3843 : : static dw_die_ref modified_type_die (tree, int, bool, dw_die_ref);
3844 : : static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
3845 : : static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
3846 : : static unsigned int debugger_reg_number (const_rtx);
3847 : : static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3848 : : static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
3849 : : static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
3850 : : enum var_init_status);
3851 : : static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
3852 : : enum var_init_status);
3853 : : static dw_loc_descr_ref based_loc_descr (rtx, poly_int64,
3854 : : enum var_init_status);
3855 : : static bool is_based_loc (const_rtx);
3856 : : static bool resolve_one_addr (rtx *);
3857 : : static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
3858 : : enum var_init_status);
3859 : : static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
3860 : : enum var_init_status);
3861 : : struct loc_descr_context;
3862 : : static void add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref);
3863 : : static void add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list);
3864 : : static dw_loc_list_ref loc_list_from_tree (tree, int,
3865 : : struct loc_descr_context *);
3866 : : static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
3867 : : struct loc_descr_context *);
3868 : : static tree field_type (const_tree);
3869 : : static unsigned int simple_type_align_in_bits (const_tree);
3870 : : static unsigned int simple_decl_align_in_bits (const_tree);
3871 : : static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
3872 : : struct vlr_context;
3873 : : static dw_loc_descr_ref field_byte_offset (const_tree, struct vlr_context *,
3874 : : HOST_WIDE_INT *);
3875 : : static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3876 : : dw_loc_list_ref);
3877 : : static void add_data_member_location_attribute (dw_die_ref, tree,
3878 : : struct vlr_context *);
3879 : : static bool add_const_value_attribute (dw_die_ref, machine_mode, rtx);
3880 : : static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
3881 : : static void insert_wide_int (const wide_int_ref &, unsigned char *, int);
3882 : : static unsigned insert_float (const_rtx, unsigned char *);
3883 : : static rtx rtl_for_decl_location (tree);
3884 : : static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
3885 : : static bool tree_add_const_value_attribute (dw_die_ref, tree);
3886 : : static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
3887 : : static void add_desc_attribute (dw_die_ref, tree);
3888 : : static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
3889 : : static void add_comp_dir_attribute (dw_die_ref);
3890 : : static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
3891 : : struct loc_descr_context *);
3892 : : static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
3893 : : struct loc_descr_context *);
3894 : : static void add_subscript_info (dw_die_ref, tree, bool);
3895 : : static void add_byte_size_attribute (dw_die_ref, tree);
3896 : : static void add_alignment_attribute (dw_die_ref, tree);
3897 : : static void add_bit_offset_attribute (dw_die_ref, tree);
3898 : : static void add_bit_size_attribute (dw_die_ref, tree);
3899 : : static void add_prototyped_attribute (dw_die_ref, tree);
3900 : : static void add_abstract_origin_attribute (dw_die_ref, tree);
3901 : : static void add_pure_or_virtual_attribute (dw_die_ref, tree);
3902 : : static void add_src_coords_attributes (dw_die_ref, tree);
3903 : : static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool = false);
3904 : : static void add_discr_value (dw_die_ref, dw_discr_value *);
3905 : : static void add_discr_list (dw_die_ref, dw_discr_list_ref);
3906 : : static inline dw_discr_list_ref AT_discr_list (dw_attr_node *);
3907 : : static dw_die_ref scope_die_for (tree, dw_die_ref);
3908 : : static inline bool local_scope_p (dw_die_ref);
3909 : : static inline bool class_scope_p (dw_die_ref);
3910 : : static inline bool class_or_namespace_scope_p (dw_die_ref);
3911 : : static void add_type_attribute (dw_die_ref, tree, int, bool, dw_die_ref);
3912 : : static void add_calling_convention_attribute (dw_die_ref, tree);
3913 : : static const char *type_tag (const_tree);
3914 : : static tree member_declared_type (const_tree);
3915 : : #if 0
3916 : : static const char *decl_start_label (tree);
3917 : : #endif
3918 : : static void gen_array_type_die (tree, dw_die_ref);
3919 : : static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
3920 : : #if 0
3921 : : static void gen_entry_point_die (tree, dw_die_ref);
3922 : : #endif
3923 : : static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref, bool);
3924 : : static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
3925 : : static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
3926 : : static void gen_unspecified_parameters_die (tree, dw_die_ref);
3927 : : static void gen_formal_types_die (tree, dw_die_ref);
3928 : : static void gen_subprogram_die (tree, dw_die_ref);
3929 : : static void gen_variable_die (tree, tree, dw_die_ref);
3930 : : static void gen_const_die (tree, dw_die_ref);
3931 : : static void gen_label_die (tree, dw_die_ref);
3932 : : static void gen_lexical_block_die (tree, dw_die_ref);
3933 : : static void gen_inlined_subroutine_die (tree, dw_die_ref);
3934 : : static void gen_field_die (tree, struct vlr_context *, dw_die_ref);
3935 : : static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
3936 : : static dw_die_ref gen_compile_unit_die (const char *);
3937 : : static void gen_inheritance_die (tree, tree, tree, dw_die_ref);
3938 : : static void gen_member_die (tree, dw_die_ref);
3939 : : static void gen_struct_or_union_type_die (tree, dw_die_ref,
3940 : : enum debug_info_usage);
3941 : : static void gen_subroutine_type_die (tree, dw_die_ref);
3942 : : static void gen_typedef_die (tree, dw_die_ref);
3943 : : static void gen_type_die (tree, dw_die_ref, bool = false);
3944 : : static void gen_block_die (tree, dw_die_ref);
3945 : : static void decls_for_scope (tree, dw_die_ref, bool = true);
3946 : : static bool is_naming_typedef_decl (const_tree);
3947 : : static inline dw_die_ref get_context_die (tree);
3948 : : static void gen_namespace_die (tree, dw_die_ref);
3949 : : static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
3950 : : static dw_die_ref gen_decl_die (tree, tree, struct vlr_context *, dw_die_ref);
3951 : : static dw_die_ref force_decl_die (tree);
3952 : : static dw_die_ref force_type_die (tree);
3953 : : static dw_die_ref setup_namespace_context (tree, dw_die_ref);
3954 : : static dw_die_ref declare_in_namespace (tree, dw_die_ref);
3955 : : static struct dwarf_file_data * lookup_filename (const char *);
3956 : : static void retry_incomplete_types (void);
3957 : : static void gen_type_die_for_member (tree, tree, dw_die_ref);
3958 : : static void gen_generic_params_dies (tree);
3959 : : static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage,
3960 : : bool = false);
3961 : : static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage,
3962 : : bool = false);
3963 : : static void splice_child_die (dw_die_ref, dw_die_ref);
3964 : : static int file_info_cmp (const void *, const void *);
3965 : : static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *, var_loc_view,
3966 : : const char *, var_loc_view, const char *);
3967 : : static void output_loc_list (dw_loc_list_ref);
3968 : : static char *gen_internal_sym (const char *);
3969 : : static bool want_pubnames (void);
3970 : :
3971 : : static void prune_unmark_dies (dw_die_ref);
3972 : : static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
3973 : : static void prune_unused_types_mark (dw_die_ref, int);
3974 : : static void prune_unused_types_walk (dw_die_ref);
3975 : : static void prune_unused_types_walk_attribs (dw_die_ref);
3976 : : static void prune_unused_types_prune (dw_die_ref);
3977 : : static void prune_unused_types (void);
3978 : : static int maybe_emit_file (struct dwarf_file_data *fd);
3979 : : static inline const char *AT_vms_delta1 (dw_attr_node *);
3980 : : static inline const char *AT_vms_delta2 (dw_attr_node *);
3981 : : #if VMS_DEBUGGING_INFO
3982 : : static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
3983 : : const char *, const char *);
3984 : : #endif
3985 : : static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
3986 : : static void gen_remaining_tmpl_value_param_die_attribute (void);
3987 : : static bool generic_type_p (tree);
3988 : : static void schedule_generic_params_dies_gen (tree t);
3989 : : static void gen_scheduled_generic_parms_dies (void);
3990 : : static void resolve_variable_values (void);
3991 : :
3992 : : static const char *comp_dir_string (void);
3993 : :
3994 : : static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
3995 : :
3996 : : /* enum for tracking thread-local variables whose address is really an offset
3997 : : relative to the TLS pointer, which will need link-time relocation, but will
3998 : : not need relocation by the DWARF consumer. */
3999 : :
4000 : : enum dtprel_bool
4001 : : {
4002 : : dtprel_false = 0,
4003 : : dtprel_true = 1
4004 : : };
4005 : :
4006 : : /* Return the operator to use for an address of a variable. For dtprel_true, we
4007 : : use DW_OP_const*. For regular variables, which need both link-time
4008 : : relocation and consumer-level relocation (e.g., to account for shared objects
4009 : : loaded at a random address), we use DW_OP_addr*. */
4010 : :
4011 : : static inline enum dwarf_location_atom
4012 : 1514128 : dw_addr_op (enum dtprel_bool dtprel)
4013 : : {
4014 : 1514128 : if (dtprel == dtprel_true)
4015 : 4912 : return (dwarf_split_debug_info ? dwarf_OP (DW_OP_constx)
4016 : 4912 : : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
4017 : : else
4018 : 1509216 : return dwarf_split_debug_info ? dwarf_OP (DW_OP_addrx) : DW_OP_addr;
4019 : : }
4020 : :
4021 : : /* Return a pointer to a newly allocated address location description. If
4022 : : dwarf_split_debug_info is true, then record the address with the appropriate
4023 : : relocation. */
4024 : : static inline dw_loc_descr_ref
4025 : 1514128 : new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
4026 : : {
4027 : 1514128 : dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
4028 : :
4029 : 1514128 : ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
4030 : 1514128 : ref->dw_loc_oprnd1.v.val_addr = addr;
4031 : 1514128 : ref->dw_loc_dtprel = dtprel;
4032 : 1514128 : if (dwarf_split_debug_info)
4033 : 3 : ref->dw_loc_oprnd1.val_entry
4034 : 6 : = add_addr_table_entry (addr,
4035 : : dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
4036 : : else
4037 : 1514125 : ref->dw_loc_oprnd1.val_entry = NULL;
4038 : :
4039 : 1514128 : return ref;
4040 : : }
4041 : :
4042 : : /* Section names used to hold DWARF debugging information. */
4043 : :
4044 : : #ifndef DEBUG_INFO_SECTION
4045 : : #define DEBUG_INFO_SECTION ".debug_info"
4046 : : #endif
4047 : : #ifndef DEBUG_DWO_INFO_SECTION
4048 : : #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
4049 : : #endif
4050 : : #ifndef DEBUG_LTO_INFO_SECTION
4051 : : #define DEBUG_LTO_INFO_SECTION ".gnu.debuglto_.debug_info"
4052 : : #endif
4053 : : #ifndef DEBUG_LTO_DWO_INFO_SECTION
4054 : : #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
4055 : : #endif
4056 : : #ifndef DEBUG_ABBREV_SECTION
4057 : : #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4058 : : #endif
4059 : : #ifndef DEBUG_LTO_ABBREV_SECTION
4060 : : #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
4061 : : #endif
4062 : : #ifndef DEBUG_DWO_ABBREV_SECTION
4063 : : #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
4064 : : #endif
4065 : : #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
4066 : : #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
4067 : : #endif
4068 : : #ifndef DEBUG_ARANGES_SECTION
4069 : : #define DEBUG_ARANGES_SECTION ".debug_aranges"
4070 : : #endif
4071 : : #ifndef DEBUG_ADDR_SECTION
4072 : : #define DEBUG_ADDR_SECTION ".debug_addr"
4073 : : #endif
4074 : : #ifndef DEBUG_MACINFO_SECTION
4075 : : #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4076 : : #endif
4077 : : #ifndef DEBUG_LTO_MACINFO_SECTION
4078 : : #define DEBUG_LTO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo"
4079 : : #endif
4080 : : #ifndef DEBUG_DWO_MACINFO_SECTION
4081 : : #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
4082 : : #endif
4083 : : #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
4084 : : #define DEBUG_LTO_DWO_MACINFO_SECTION ".gnu.debuglto_.debug_macinfo.dwo"
4085 : : #endif
4086 : : #ifndef DEBUG_MACRO_SECTION
4087 : : #define DEBUG_MACRO_SECTION ".debug_macro"
4088 : : #endif
4089 : : #ifndef DEBUG_LTO_MACRO_SECTION
4090 : : #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
4091 : : #endif
4092 : : #ifndef DEBUG_DWO_MACRO_SECTION
4093 : : #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
4094 : : #endif
4095 : : #ifndef DEBUG_LTO_DWO_MACRO_SECTION
4096 : : #define DEBUG_LTO_DWO_MACRO_SECTION ".gnu.debuglto_.debug_macro.dwo"
4097 : : #endif
4098 : : #ifndef DEBUG_LINE_SECTION
4099 : : #define DEBUG_LINE_SECTION ".debug_line"
4100 : : #endif
4101 : : #ifndef DEBUG_LTO_LINE_SECTION
4102 : : #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
4103 : : #endif
4104 : : #ifndef DEBUG_DWO_LINE_SECTION
4105 : : #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
4106 : : #endif
4107 : : #ifndef DEBUG_LTO_DWO_LINE_SECTION
4108 : : #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
4109 : : #endif
4110 : : #ifndef DEBUG_LOC_SECTION
4111 : : #define DEBUG_LOC_SECTION ".debug_loc"
4112 : : #endif
4113 : : #ifndef DEBUG_DWO_LOC_SECTION
4114 : : #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
4115 : : #endif
4116 : : #ifndef DEBUG_LOCLISTS_SECTION
4117 : : #define DEBUG_LOCLISTS_SECTION ".debug_loclists"
4118 : : #endif
4119 : : #ifndef DEBUG_DWO_LOCLISTS_SECTION
4120 : : #define DEBUG_DWO_LOCLISTS_SECTION ".debug_loclists.dwo"
4121 : : #endif
4122 : : #ifndef DEBUG_PUBNAMES_SECTION
4123 : : #define DEBUG_PUBNAMES_SECTION \
4124 : : ((debug_generate_pub_sections == 2) \
4125 : : ? ".debug_gnu_pubnames" : ".debug_pubnames")
4126 : : #endif
4127 : : #ifndef DEBUG_PUBTYPES_SECTION
4128 : : #define DEBUG_PUBTYPES_SECTION \
4129 : : ((debug_generate_pub_sections == 2) \
4130 : : ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
4131 : : #endif
4132 : : #ifndef DEBUG_STR_OFFSETS_SECTION
4133 : : #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
4134 : : #endif
4135 : : #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
4136 : : #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
4137 : : #endif
4138 : : #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
4139 : : #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
4140 : : #endif
4141 : : #ifndef DEBUG_STR_SECTION
4142 : : #define DEBUG_STR_SECTION ".debug_str"
4143 : : #endif
4144 : : #ifndef DEBUG_LTO_STR_SECTION
4145 : : #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
4146 : : #endif
4147 : : #ifndef DEBUG_STR_DWO_SECTION
4148 : : #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
4149 : : #endif
4150 : : #ifndef DEBUG_LTO_STR_DWO_SECTION
4151 : : #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
4152 : : #endif
4153 : : #ifndef DEBUG_RANGES_SECTION
4154 : : #define DEBUG_RANGES_SECTION ".debug_ranges"
4155 : : #endif
4156 : : #ifndef DEBUG_RNGLISTS_SECTION
4157 : : #define DEBUG_RNGLISTS_SECTION ".debug_rnglists"
4158 : : #endif
4159 : : #ifndef DEBUG_DWO_RNGLISTS_SECTION
4160 : : #define DEBUG_DWO_RNGLISTS_SECTION ".debug_rnglists.dwo"
4161 : : #endif
4162 : : #ifndef DEBUG_LINE_STR_SECTION
4163 : : #define DEBUG_LINE_STR_SECTION ".debug_line_str"
4164 : : #endif
4165 : : #ifndef DEBUG_LTO_LINE_STR_SECTION
4166 : : #define DEBUG_LTO_LINE_STR_SECTION ".gnu.debuglto_.debug_line_str"
4167 : : #endif
4168 : :
4169 : : /* Section flags for .debug_str section. */
4170 : : #define DEBUG_STR_SECTION_FLAGS \
4171 : : (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4172 : : ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4173 : : : SECTION_DEBUG)
4174 : :
4175 : : /* Section flags for .debug_str.dwo section. */
4176 : : #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
4177 : :
4178 : : /* Attribute used to refer to the macro section. */
4179 : : #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
4180 : : : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
4181 : :
4182 : : /* Labels we insert at beginning sections we can reference instead of
4183 : : the section names themselves. */
4184 : :
4185 : : #ifndef TEXT_SECTION_LABEL
4186 : : #define TEXT_SECTION_LABEL "Ltext"
4187 : : #endif
4188 : : #ifndef COLD_TEXT_SECTION_LABEL
4189 : : #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4190 : : #endif
4191 : : #ifndef DEBUG_LINE_SECTION_LABEL
4192 : : #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4193 : : #endif
4194 : : #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
4195 : : #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
4196 : : #endif
4197 : : #ifndef DEBUG_INFO_SECTION_LABEL
4198 : : #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4199 : : #endif
4200 : : #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
4201 : : #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
4202 : : #endif
4203 : : #ifndef DEBUG_ABBREV_SECTION_LABEL
4204 : : #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4205 : : #endif
4206 : : #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
4207 : : #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
4208 : : #endif
4209 : : #ifndef DEBUG_ADDR_SECTION_LABEL
4210 : : #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
4211 : : #endif
4212 : : #ifndef DEBUG_LOC_SECTION_LABEL
4213 : : #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4214 : : #endif
4215 : : #ifndef DEBUG_RANGES_SECTION_LABEL
4216 : : #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4217 : : #endif
4218 : : #ifndef DEBUG_MACINFO_SECTION_LABEL
4219 : : #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4220 : : #endif
4221 : : #ifndef DEBUG_MACRO_SECTION_LABEL
4222 : : #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
4223 : : #endif
4224 : : #define SKELETON_COMP_DIE_ABBREV 1
4225 : : #define SKELETON_TYPE_DIE_ABBREV 2
4226 : :
4227 : : /* Definitions of defaults for formats and names of various special
4228 : : (artificial) labels which may be generated within this file (when the -g
4229 : : options is used and DWARF2_DEBUGGING_INFO is in effect.
4230 : : If necessary, these may be overridden from within the tm.h file, but
4231 : : typically, overriding these defaults is unnecessary. */
4232 : :
4233 : : static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4234 : : static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4235 : : static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4236 : : static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4237 : : static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4238 : : static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4239 : : static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4240 : : static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4241 : : static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4242 : : static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4243 : : static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4244 : : static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4245 : : static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4246 : : static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4247 : : static char ranges_base_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4248 : :
4249 : : #ifndef TEXT_END_LABEL
4250 : : #define TEXT_END_LABEL "Letext"
4251 : : #endif
4252 : : #ifndef COLD_END_LABEL
4253 : : #define COLD_END_LABEL "Letext_cold"
4254 : : #endif
4255 : : #ifndef BLOCK_BEGIN_LABEL
4256 : : #define BLOCK_BEGIN_LABEL "LBB"
4257 : : #endif
4258 : : #ifndef BLOCK_INLINE_ENTRY_LABEL
4259 : : #define BLOCK_INLINE_ENTRY_LABEL "LBI"
4260 : : #endif
4261 : : #ifndef BLOCK_END_LABEL
4262 : : #define BLOCK_END_LABEL "LBE"
4263 : : #endif
4264 : : #ifndef LINE_CODE_LABEL
4265 : : #define LINE_CODE_LABEL "LM"
4266 : : #endif
4267 : :
4268 : :
4269 : : /* Return the root of the DIE's built for the current compilation unit. */
4270 : : static dw_die_ref
4271 : 428294242 : comp_unit_die (void)
4272 : : {
4273 : 428294242 : if (!single_comp_unit_die)
4274 : 56806 : single_comp_unit_die = gen_compile_unit_die (NULL);
4275 : 428294242 : return single_comp_unit_die;
4276 : : }
4277 : :
4278 : : /* We allow a language front-end to designate a function that is to be
4279 : : called to "demangle" any name before it is put into a DIE. */
4280 : :
4281 : : static const char *(*demangle_name_func) (const char *);
4282 : :
4283 : : void
4284 : 0 : dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4285 : : {
4286 : 0 : demangle_name_func = func;
4287 : 0 : }
4288 : :
4289 : : /* Test if rtl node points to a pseudo register. */
4290 : :
4291 : : static inline bool
4292 : 1341316 : is_pseudo_reg (const_rtx rtl)
4293 : : {
4294 : 924717 : return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4295 : 1488287 : || (GET_CODE (rtl) == SUBREG
4296 : 323 : && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4297 : : }
4298 : :
4299 : : /* Return a reference to a type, with its const and volatile qualifiers
4300 : : removed. */
4301 : :
4302 : : static inline tree
4303 : 634074978 : type_main_variant (tree type)
4304 : : {
4305 : 634074978 : type = TYPE_MAIN_VARIANT (type);
4306 : :
4307 : : /* ??? There really should be only one main variant among any group of
4308 : : variants of a given type (and all of the MAIN_VARIANT values for all
4309 : : members of the group should point to that one type) but sometimes the C
4310 : : front-end messes this up for array types, so we work around that bug
4311 : : here. */
4312 : 634074978 : if (TREE_CODE (type) == ARRAY_TYPE)
4313 : 0 : while (type != TYPE_MAIN_VARIANT (type))
4314 : 0 : type = TYPE_MAIN_VARIANT (type);
4315 : :
4316 : 634074978 : return type;
4317 : : }
4318 : :
4319 : : /* Return true if the given type node represents a tagged type. */
4320 : :
4321 : : static inline bool
4322 : 708138589 : is_tagged_type (const_tree type)
4323 : : {
4324 : 708138589 : enum tree_code code = TREE_CODE (type);
4325 : :
4326 : 708138589 : return (code == RECORD_TYPE || code == UNION_TYPE
4327 : 708138589 : || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4328 : : }
4329 : :
4330 : : /* Set label to debug_info_section_label + die_offset of a DIE reference. */
4331 : :
4332 : : static void
4333 : 1216111 : get_ref_die_offset_label (char *label, dw_die_ref ref)
4334 : : {
4335 : 1216111 : sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
4336 : 0 : }
4337 : :
4338 : : /* Return die_offset of a DIE reference to a base type. */
4339 : :
4340 : : static unsigned long int
4341 : 1404536 : get_base_type_offset (dw_die_ref ref)
4342 : : {
4343 : 1404536 : if (ref->die_offset)
4344 : 1073356 : return ref->die_offset;
4345 : 331180 : if (comp_unit_die ()->die_abbrev)
4346 : : {
4347 : 9 : calc_base_type_die_sizes ();
4348 : 9 : gcc_assert (ref->die_offset);
4349 : : }
4350 : 331180 : return ref->die_offset;
4351 : : }
4352 : :
4353 : : /* Return die_offset of a DIE reference other than base type. */
4354 : :
4355 : : static unsigned long int
4356 : 31349 : get_ref_die_offset (dw_die_ref ref)
4357 : : {
4358 : 31349 : gcc_assert (ref->die_offset);
4359 : 31349 : return ref->die_offset;
4360 : : }
4361 : :
4362 : : /* Convert a DIE tag into its string name. */
4363 : :
4364 : : static const char *
4365 : 83590812 : dwarf_tag_name (unsigned int tag)
4366 : : {
4367 : 0 : const char *name = get_DW_TAG_name (tag);
4368 : :
4369 : 83590812 : if (name != NULL)
4370 : 83590812 : return name;
4371 : :
4372 : : return "DW_TAG_<unknown>";
4373 : : }
4374 : :
4375 : : /* Convert a DWARF attribute code into its string name. */
4376 : :
4377 : : static const char *
4378 : 374470467 : dwarf_attr_name (unsigned int attr)
4379 : : {
4380 : 374470467 : const char *name;
4381 : :
4382 : 374470467 : switch (attr)
4383 : : {
4384 : : #if VMS_DEBUGGING_INFO
4385 : : case DW_AT_HP_prologue:
4386 : : return "DW_AT_HP_prologue";
4387 : : #else
4388 : : case DW_AT_MIPS_loop_unroll_factor:
4389 : : return "DW_AT_MIPS_loop_unroll_factor";
4390 : : #endif
4391 : :
4392 : : #if VMS_DEBUGGING_INFO
4393 : : case DW_AT_HP_epilogue:
4394 : : return "DW_AT_HP_epilogue";
4395 : : #else
4396 : 0 : case DW_AT_MIPS_stride:
4397 : 0 : return "DW_AT_MIPS_stride";
4398 : : #endif
4399 : : }
4400 : :
4401 : 374470467 : name = get_DW_AT_name (attr);
4402 : :
4403 : 374470467 : if (name != NULL)
4404 : 374470467 : return name;
4405 : :
4406 : : return "DW_AT_<unknown>";
4407 : : }
4408 : :
4409 : : /* Convert a DWARF value form code into its string name. */
4410 : :
4411 : : static const char *
4412 : 15439200 : dwarf_form_name (unsigned int form)
4413 : : {
4414 : 0 : const char *name = get_DW_FORM_name (form);
4415 : :
4416 : 15439200 : if (name != NULL)
4417 : 15439200 : return name;
4418 : :
4419 : : return "DW_FORM_<unknown>";
4420 : : }
4421 : :
4422 : : /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4423 : : instance of an inlined instance of a decl which is local to an inline
4424 : : function, so we have to trace all of the way back through the origin chain
4425 : : to find out what sort of node actually served as the original seed for the
4426 : : given block. */
4427 : :
4428 : : static tree
4429 : 288284801 : decl_ultimate_origin (const_tree decl)
4430 : : {
4431 : 288284801 : if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4432 : : return NULL_TREE;
4433 : :
4434 : : /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
4435 : : we're trying to output the abstract instance of this function. */
4436 : 288284801 : if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4437 : : return NULL_TREE;
4438 : :
4439 : : /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4440 : : most distant ancestor, this should never happen. */
4441 : 330812024 : gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4442 : :
4443 : 288281531 : return DECL_ABSTRACT_ORIGIN (decl);
4444 : : }
4445 : :
4446 : : /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4447 : : of a virtual function may refer to a base class, so we check the 'this'
4448 : : parameter. */
4449 : :
4450 : : static tree
4451 : 108847838 : decl_class_context (tree decl)
4452 : : {
4453 : 108847838 : tree context = NULL_TREE;
4454 : :
4455 : 108847838 : if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4456 : 107951098 : context = DECL_CONTEXT (decl);
4457 : : else
4458 : 896740 : context = TYPE_MAIN_VARIANT
4459 : : (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4460 : :
4461 : 108847838 : if (context && !TYPE_P (context))
4462 : 15785493 : context = NULL_TREE;
4463 : :
4464 : 108847838 : return context;
4465 : : }
4466 : :
4467 : : /* Add an attribute/value pair to a DIE. */
4468 : :
4469 : : static inline void
4470 : 1985529851 : add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
4471 : : {
4472 : : /* Maybe this should be an assert? */
4473 : 1985529851 : if (die == NULL)
4474 : : return;
4475 : :
4476 : 1985411762 : if (flag_checking)
4477 : : {
4478 : : /* Check we do not add duplicate attrs. Can't use get_AT here
4479 : : because that recurses to the specification/abstract origin DIE. */
4480 : : dw_attr_node *a;
4481 : : unsigned ix;
4482 : 7356803302 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
4483 : 5371391787 : gcc_assert (a->dw_attr != attr->dw_attr);
4484 : : }
4485 : :
4486 : 1985411762 : vec_safe_reserve (die->die_attr, 1);
4487 : 1985411762 : vec_safe_push (die->die_attr, *attr);
4488 : : }
4489 : :
4490 : : enum dw_val_class
4491 : 6316333916 : AT_class (dw_attr_node *a)
4492 : : {
4493 : 6316333916 : return a->dw_attr_val.val_class;
4494 : : }
4495 : :
4496 : : /* Return the index for any attribute that will be referenced with a
4497 : : DW_FORM_addrx/GNU_addr_index or DW_FORM_strx/GNU_str_index. String
4498 : : indices are stored in dw_attr_val.v.val_str for reference counting
4499 : : pruning. */
4500 : :
4501 : : static inline unsigned int
4502 : 43877251 : AT_index (dw_attr_node *a)
4503 : : {
4504 : 43877251 : if (AT_class (a) == dw_val_class_str)
4505 : 1870 : return a->dw_attr_val.v.val_str->index;
4506 : 43875381 : else if (a->dw_attr_val.val_entry != NULL)
4507 : 1771 : return a->dw_attr_val.val_entry->index;
4508 : : return NOT_INDEXED;
4509 : : }
4510 : :
4511 : : /* Add a flag value attribute to a DIE. */
4512 : :
4513 : : static inline void
4514 : 310221623 : add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4515 : : {
4516 : 310221623 : dw_attr_node attr;
4517 : :
4518 : 310221623 : attr.dw_attr = attr_kind;
4519 : 310221623 : attr.dw_attr_val.val_class = dw_val_class_flag;
4520 : 310221623 : attr.dw_attr_val.val_entry = NULL;
4521 : 310221623 : attr.dw_attr_val.v.val_flag = flag;
4522 : 310221623 : add_dwarf_attr (die, &attr);
4523 : 130049881 : }
4524 : :
4525 : : static inline unsigned
4526 : 58375247 : AT_flag (dw_attr_node *a)
4527 : : {
4528 : 58375247 : gcc_assert (a && AT_class (a) == dw_val_class_flag);
4529 : 58375247 : return a->dw_attr_val.v.val_flag;
4530 : : }
4531 : :
4532 : : /* Add a signed integer attribute value to a DIE. */
4533 : :
4534 : : static inline void
4535 : 382235 : add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4536 : : {
4537 : 382235 : dw_attr_node attr;
4538 : :
4539 : 382235 : attr.dw_attr = attr_kind;
4540 : 382235 : attr.dw_attr_val.val_class = dw_val_class_const;
4541 : 382235 : attr.dw_attr_val.val_entry = NULL;
4542 : 382235 : attr.dw_attr_val.v.val_int = int_val;
4543 : 382235 : add_dwarf_attr (die, &attr);
4544 : 189332 : }
4545 : :
4546 : : HOST_WIDE_INT
4547 : 28026 : AT_int (dw_attr_node *a)
4548 : : {
4549 : 28026 : gcc_assert (a && (AT_class (a) == dw_val_class_const
4550 : : || AT_class (a) == dw_val_class_const_implicit));
4551 : 28026 : return a->dw_attr_val.v.val_int;
4552 : : }
4553 : :
4554 : : /* Add an unsigned integer attribute value to a DIE. */
4555 : :
4556 : : static inline void
4557 : 596428493 : add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4558 : : unsigned HOST_WIDE_INT unsigned_val)
4559 : : {
4560 : 596428493 : dw_attr_node attr;
4561 : :
4562 : 596428493 : attr.dw_attr = attr_kind;
4563 : 596428493 : attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
4564 : 596428493 : attr.dw_attr_val.val_entry = NULL;
4565 : 596428493 : attr.dw_attr_val.v.val_unsigned = unsigned_val;
4566 : 1622486 : add_dwarf_attr (die, &attr);
4567 : 355523508 : }
4568 : :
4569 : : unsigned HOST_WIDE_INT
4570 : 751603210 : AT_unsigned (dw_attr_node *a)
4571 : : {
4572 : 751603210 : gcc_assert (a && (AT_class (a) == dw_val_class_unsigned_const
4573 : : || AT_class (a) == dw_val_class_unsigned_const_implicit));
4574 : 751603210 : return a->dw_attr_val.v.val_unsigned;
4575 : : }
4576 : :
4577 : : dw_wide_int *
4578 : 803 : alloc_dw_wide_int (const wide_int_ref &w)
4579 : : {
4580 : 803 : dw_wide_int *p
4581 : 803 : = (dw_wide_int *) ggc_internal_alloc (sizeof (dw_wide_int)
4582 : 803 : + ((w.get_len () - 1)
4583 : : * sizeof (HOST_WIDE_INT)));
4584 : 803 : p->precision = w.get_precision ();
4585 : 803 : p->len = w.get_len ();
4586 : 803 : memcpy (p->val, w.get_val (), p->len * sizeof (HOST_WIDE_INT));
4587 : 803 : return p;
4588 : : }
4589 : :
4590 : : /* Add an unsigned wide integer attribute value to a DIE. */
4591 : :
4592 : : static inline void
4593 : 41 : add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
4594 : : const wide_int_ref &w)
4595 : : {
4596 : 41 : dw_attr_node attr;
4597 : :
4598 : 41 : attr.dw_attr = attr_kind;
4599 : 41 : attr.dw_attr_val.val_class = dw_val_class_wide_int;
4600 : 41 : attr.dw_attr_val.val_entry = NULL;
4601 : 41 : attr.dw_attr_val.v.val_wide = alloc_dw_wide_int (w);
4602 : 41 : add_dwarf_attr (die, &attr);
4603 : 41 : }
4604 : :
4605 : : /* Add an unsigned double integer attribute value to a DIE. */
4606 : :
4607 : : static inline void
4608 : : add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
4609 : : HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
4610 : : {
4611 : : dw_attr_node attr;
4612 : :
4613 : : attr.dw_attr = attr_kind;
4614 : : attr.dw_attr_val.val_class = dw_val_class_const_double;
4615 : : attr.dw_attr_val.val_entry = NULL;
4616 : : attr.dw_attr_val.v.val_double.high = high;
4617 : : attr.dw_attr_val.v.val_double.low = low;
4618 : : add_dwarf_attr (die, &attr);
4619 : : }
4620 : :
4621 : : /* Add a floating point attribute value to a DIE and return it. */
4622 : :
4623 : : static inline void
4624 : 769194 : add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4625 : : unsigned int length, unsigned int elt_size, unsigned char *array)
4626 : : {
4627 : 769194 : dw_attr_node attr;
4628 : :
4629 : 769194 : attr.dw_attr = attr_kind;
4630 : 769194 : attr.dw_attr_val.val_class = dw_val_class_vec;
4631 : 769194 : attr.dw_attr_val.val_entry = NULL;
4632 : 769194 : attr.dw_attr_val.v.val_vec.length = length;
4633 : 769194 : attr.dw_attr_val.v.val_vec.elt_size = elt_size;
4634 : 769194 : attr.dw_attr_val.v.val_vec.array = array;
4635 : 769194 : add_dwarf_attr (die, &attr);
4636 : : }
4637 : :
4638 : : /* Add an 8-byte data attribute value to a DIE. */
4639 : :
4640 : : static inline void
4641 : 71 : add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
4642 : : unsigned char data8[8])
4643 : : {
4644 : 71 : dw_attr_node attr;
4645 : :
4646 : 71 : attr.dw_attr = attr_kind;
4647 : 71 : attr.dw_attr_val.val_class = dw_val_class_data8;
4648 : 71 : attr.dw_attr_val.val_entry = NULL;
4649 : 71 : memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
4650 : 71 : add_dwarf_attr (die, &attr);
4651 : 71 : }
4652 : :
4653 : : /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4654 : : dwarf_split_debug_info, address attributes in dies destined for the
4655 : : final executable have force_direct set to avoid using indexed
4656 : : references. */
4657 : :
4658 : : static inline void
4659 : 4935450 : add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
4660 : : bool force_direct)
4661 : : {
4662 : 4935450 : dw_attr_node attr;
4663 : 4935450 : char * lbl_id;
4664 : :
4665 : 4935450 : lbl_id = xstrdup (lbl_low);
4666 : 4935450 : attr.dw_attr = DW_AT_low_pc;
4667 : 4935450 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4668 : 4935450 : attr.dw_attr_val.v.val_lbl_id = lbl_id;
4669 : 4935450 : if (dwarf_split_debug_info && !force_direct)
4670 : 242 : attr.dw_attr_val.val_entry
4671 : 242 : = add_addr_table_entry (lbl_id, ate_kind_label);
4672 : : else
4673 : 4935208 : attr.dw_attr_val.val_entry = NULL;
4674 : 4935450 : add_dwarf_attr (die, &attr);
4675 : :
4676 : 4935450 : attr.dw_attr = DW_AT_high_pc;
4677 : 4935450 : if (dwarf_version < 4)
4678 : : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
4679 : : else
4680 : 4929778 : attr.dw_attr_val.val_class = dw_val_class_high_pc;
4681 : 4935450 : lbl_id = xstrdup (lbl_high);
4682 : 4935450 : attr.dw_attr_val.v.val_lbl_id = lbl_id;
4683 : 4935450 : if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
4684 : 5672 : && dwarf_split_debug_info && !force_direct)
4685 : 0 : attr.dw_attr_val.val_entry
4686 : 0 : = add_addr_table_entry (lbl_id, ate_kind_label);
4687 : : else
4688 : 4935450 : attr.dw_attr_val.val_entry = NULL;
4689 : 4935450 : add_dwarf_attr (die, &attr);
4690 : 4935450 : }
4691 : :
4692 : : /* Hash and equality functions for debug_str_hash. */
4693 : :
4694 : : hashval_t
4695 : 2051736155 : indirect_string_hasher::hash (indirect_string_node *x)
4696 : : {
4697 : 2051736155 : return htab_hash_string (x->str);
4698 : : }
4699 : :
4700 : : bool
4701 : 2299932827 : indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
4702 : : {
4703 : 2299932827 : return strcmp (x1->str, x2) == 0;
4704 : : }
4705 : :
4706 : : /* Add STR to the given string hash table. */
4707 : :
4708 : : static struct indirect_string_node *
4709 : 323662304 : find_AT_string_in_table (const char *str,
4710 : : hash_table<indirect_string_hasher> *table,
4711 : : enum insert_option insert = INSERT)
4712 : : {
4713 : 323662304 : struct indirect_string_node *node;
4714 : :
4715 : 323662304 : indirect_string_node **slot
4716 : 323662304 : = table->find_slot_with_hash (str, htab_hash_string (str), insert);
4717 : 323662304 : if (*slot == NULL)
4718 : : {
4719 : 169926015 : node = ggc_cleared_alloc<indirect_string_node> ();
4720 : 169926015 : node->str = ggc_strdup (str);
4721 : 169926015 : *slot = node;
4722 : : }
4723 : : else
4724 : : node = *slot;
4725 : :
4726 : 323662304 : node->refcount++;
4727 : 323662304 : return node;
4728 : : }
4729 : :
4730 : : /* Add STR to the indirect string hash table. */
4731 : :
4732 : : static struct indirect_string_node *
4733 : 323550388 : find_AT_string (const char *str, enum insert_option insert = INSERT)
4734 : : {
4735 : 323550388 : if (! debug_str_hash)
4736 : 56806 : debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
4737 : :
4738 : 323550388 : return find_AT_string_in_table (str, debug_str_hash, insert);
4739 : : }
4740 : :
4741 : : /* Add a string attribute value to a DIE. */
4742 : :
4743 : : static inline void
4744 : 323027448 : add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4745 : : {
4746 : 323027448 : dw_attr_node attr;
4747 : 323027448 : struct indirect_string_node *node;
4748 : :
4749 : 323027448 : node = find_AT_string (str);
4750 : :
4751 : 323027448 : attr.dw_attr = attr_kind;
4752 : 323027448 : attr.dw_attr_val.val_class = dw_val_class_str;
4753 : 323027448 : attr.dw_attr_val.val_entry = NULL;
4754 : 323027448 : attr.dw_attr_val.v.val_str = node;
4755 : 323027448 : add_dwarf_attr (die, &attr);
4756 : 323027448 : }
4757 : :
4758 : : static inline const char *
4759 : 33571664 : AT_string (dw_attr_node *a)
4760 : : {
4761 : 33571664 : gcc_assert (a && AT_class (a) == dw_val_class_str);
4762 : 33571664 : return a->dw_attr_val.v.val_str->str;
4763 : : }
4764 : :
4765 : : /* Call this function directly to bypass AT_string_form's logic to put
4766 : : the string inline in the die. */
4767 : :
4768 : : static void
4769 : 19363662 : set_indirect_string (struct indirect_string_node *node)
4770 : : {
4771 : 19363662 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
4772 : : /* Already indirect is a no op. */
4773 : 19363662 : if (node->form == DW_FORM_strp
4774 : 19362935 : || node->form == DW_FORM_line_strp
4775 : 38963253 : || node->form == dwarf_FORM (DW_FORM_strx))
4776 : : {
4777 : 3587 : gcc_assert (node->label);
4778 : 3587 : return;
4779 : : }
4780 : 19360075 : ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4781 : 19360075 : ++dw2_string_counter;
4782 : 19360075 : node->label = xstrdup (label);
4783 : :
4784 : 19360075 : if (!dwarf_split_debug_info)
4785 : : {
4786 : 19356967 : node->form = DW_FORM_strp;
4787 : 19356967 : node->index = NOT_INDEXED;
4788 : : }
4789 : : else
4790 : : {
4791 : 3108 : node->form = dwarf_FORM (DW_FORM_strx);
4792 : 3108 : node->index = NO_INDEX_ASSIGNED;
4793 : : }
4794 : : }
4795 : :
4796 : : /* A helper function for dwarf2out_finish, called to reset indirect
4797 : : string decisions done for early LTO dwarf output before fat object
4798 : : dwarf output. */
4799 : :
4800 : : int
4801 : 17985 : reset_indirect_string (indirect_string_node **h, void *)
4802 : : {
4803 : 17985 : struct indirect_string_node *node = *h;
4804 : 17985 : if (node->form == DW_FORM_strp
4805 : 5991 : || node->form == DW_FORM_line_strp
4806 : 21053 : || node->form == dwarf_FORM (DW_FORM_strx))
4807 : : {
4808 : 14947 : free (node->label);
4809 : 14947 : node->label = NULL;
4810 : 14947 : node->form = (dwarf_form) 0;
4811 : 14947 : node->index = 0;
4812 : : }
4813 : 17985 : return 1;
4814 : : }
4815 : :
4816 : : /* Add a string representing a file or filepath attribute value to a DIE. */
4817 : :
4818 : : static inline void
4819 : 106446 : add_filepath_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
4820 : : const char *str)
4821 : : {
4822 : 106446 : if (! asm_outputs_debug_line_str ())
4823 : 4584 : add_AT_string (die, attr_kind, str);
4824 : : else
4825 : : {
4826 : 101862 : dw_attr_node attr;
4827 : 101862 : struct indirect_string_node *node;
4828 : :
4829 : 101862 : if (!debug_line_str_hash)
4830 : 50931 : debug_line_str_hash
4831 : 50931 : = hash_table<indirect_string_hasher>::create_ggc (10);
4832 : :
4833 : 101862 : node = find_AT_string_in_table (str, debug_line_str_hash);
4834 : 101862 : set_indirect_string (node);
4835 : 101862 : node->form = DW_FORM_line_strp;
4836 : :
4837 : 101862 : attr.dw_attr = attr_kind;
4838 : 101862 : attr.dw_attr_val.val_class = dw_val_class_str;
4839 : 101862 : attr.dw_attr_val.val_entry = NULL;
4840 : 101862 : attr.dw_attr_val.v.val_str = node;
4841 : 101862 : add_dwarf_attr (die, &attr);
4842 : : }
4843 : 106446 : }
4844 : :
4845 : : /* Find out whether a string should be output inline in DIE
4846 : : or out-of-line in .debug_str section. */
4847 : :
4848 : : static enum dwarf_form
4849 : 218125493 : find_string_form (struct indirect_string_node *node)
4850 : : {
4851 : 218125493 : unsigned int len;
4852 : :
4853 : 218125493 : if (node->form)
4854 : : return node->form;
4855 : :
4856 : 19667107 : len = strlen (node->str) + 1;
4857 : :
4858 : : /* If the string is shorter or equal to the size of the reference, it is
4859 : : always better to put it inline. */
4860 : 19667107 : if (len <= (unsigned) dwarf_offset_size || node->refcount == 0)
4861 : 649199 : return node->form = DW_FORM_string;
4862 : :
4863 : : /* If we cannot expect the linker to merge strings in .debug_str
4864 : : section, only put it into .debug_str if it is worth even in this
4865 : : single module. */
4866 : 19017908 : if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4867 : 19017908 : || ((debug_str_section->common.flags & SECTION_MERGE) == 0
4868 : 759 : && (len - dwarf_offset_size) * node->refcount <= len))
4869 : 734 : return node->form = DW_FORM_string;
4870 : :
4871 : 19017174 : set_indirect_string (node);
4872 : :
4873 : 19017174 : return node->form;
4874 : : }
4875 : :
4876 : : /* Find out whether the string referenced from the attribute should be
4877 : : output inline in DIE or out-of-line in .debug_str section. */
4878 : :
4879 : : static enum dwarf_form
4880 : 198113950 : AT_string_form (dw_attr_node *a)
4881 : : {
4882 : 198113950 : gcc_assert (a && AT_class (a) == dw_val_class_str);
4883 : 198113950 : return find_string_form (a->dw_attr_val.v.val_str);
4884 : : }
4885 : :
4886 : : /* Add a DIE reference attribute value to a DIE. */
4887 : :
4888 : : static inline void
4889 : 495369356 : add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4890 : : {
4891 : 495369356 : dw_attr_node attr;
4892 : 495369356 : gcc_checking_assert (targ_die != NULL);
4893 : 495369356 : gcc_assert (targ_die != die
4894 : : || (attr_kind != DW_AT_abstract_origin
4895 : : && attr_kind != DW_AT_specification));
4896 : :
4897 : : /* With LTO we can end up trying to reference something we didn't create
4898 : : a DIE for. Avoid crashing later on a NULL referenced DIE. */
4899 : 495369356 : if (targ_die == NULL)
4900 : : return;
4901 : :
4902 : 495369356 : attr.dw_attr = attr_kind;
4903 : 495369356 : attr.dw_attr_val.val_class = dw_val_class_die_ref;
4904 : 495369356 : attr.dw_attr_val.val_entry = NULL;
4905 : 495369356 : attr.dw_attr_val.v.val_die_ref.die = targ_die;
4906 : 495369356 : attr.dw_attr_val.v.val_die_ref.external = 0;
4907 : 495369356 : add_dwarf_attr (die, &attr);
4908 : : }
4909 : :
4910 : : /* Change DIE reference REF to point to NEW_DIE instead. */
4911 : :
4912 : : static inline void
4913 : 139 : change_AT_die_ref (dw_attr_node *ref, dw_die_ref new_die)
4914 : : {
4915 : 139 : gcc_assert (ref->dw_attr_val.val_class == dw_val_class_die_ref);
4916 : 139 : ref->dw_attr_val.v.val_die_ref.die = new_die;
4917 : 139 : ref->dw_attr_val.v.val_die_ref.external = 0;
4918 : 139 : }
4919 : :
4920 : : /* Add an AT_specification attribute to a DIE, and also make the back
4921 : : pointer from the specification to the definition. */
4922 : :
4923 : : static inline void
4924 : 14720351 : add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4925 : : {
4926 : 14720351 : add_AT_die_ref (die, DW_AT_specification, targ_die);
4927 : 14720351 : gcc_assert (!targ_die->die_definition);
4928 : 14720351 : targ_die->die_definition = die;
4929 : 14720351 : }
4930 : :
4931 : : static inline dw_die_ref
4932 : 575042050 : AT_ref (dw_attr_node *a)
4933 : : {
4934 : 575042050 : gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4935 : 575042050 : return a->dw_attr_val.v.val_die_ref.die;
4936 : : }
4937 : :
4938 : : static inline int
4939 : 394055224 : AT_ref_external (dw_attr_node *a)
4940 : : {
4941 : 394055224 : if (a && AT_class (a) == dw_val_class_die_ref)
4942 : 394055224 : return a->dw_attr_val.v.val_die_ref.external;
4943 : :
4944 : : return 0;
4945 : : }
4946 : :
4947 : : static inline void
4948 : 28913 : set_AT_ref_external (dw_attr_node *a, int i)
4949 : : {
4950 : 28913 : gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4951 : 28913 : a->dw_attr_val.v.val_die_ref.external = i;
4952 : 28913 : }
4953 : :
4954 : : /* Add a location description attribute value to a DIE. */
4955 : :
4956 : : static inline void
4957 : 8285664 : add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4958 : : {
4959 : 8285664 : dw_attr_node attr;
4960 : :
4961 : 8285664 : attr.dw_attr = attr_kind;
4962 : 8285664 : attr.dw_attr_val.val_class = dw_val_class_loc;
4963 : 8285664 : attr.dw_attr_val.val_entry = NULL;
4964 : 8285664 : attr.dw_attr_val.v.val_loc = loc;
4965 : 8285664 : add_dwarf_attr (die, &attr);
4966 : 4180922 : }
4967 : :
4968 : : dw_loc_descr_ref
4969 : 31153900 : AT_loc (dw_attr_node *a)
4970 : : {
4971 : 31153900 : gcc_assert (a && AT_class (a) == dw_val_class_loc);
4972 : 31153900 : return a->dw_attr_val.v.val_loc;
4973 : : }
4974 : :
4975 : : static inline void
4976 : 11790371 : add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
4977 : : {
4978 : 11790371 : dw_attr_node attr;
4979 : :
4980 : 11790371 : if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
4981 : : return;
4982 : :
4983 : 11790371 : attr.dw_attr = attr_kind;
4984 : 11790371 : attr.dw_attr_val.val_class = dw_val_class_loc_list;
4985 : 11790371 : attr.dw_attr_val.val_entry = NULL;
4986 : 11790371 : attr.dw_attr_val.v.val_loc_list = loc_list;
4987 : 11790371 : add_dwarf_attr (die, &attr);
4988 : 11790371 : have_location_lists = true;
4989 : : }
4990 : :
4991 : : static inline dw_loc_list_ref
4992 : 33618644 : AT_loc_list (dw_attr_node *a)
4993 : : {
4994 : 33618644 : gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
4995 : 33618644 : return a->dw_attr_val.v.val_loc_list;
4996 : : }
4997 : :
4998 : : /* Add a view list attribute to DIE. It must have a DW_AT_location
4999 : : attribute, because the view list complements the location list. */
5000 : :
5001 : : static inline void
5002 : 11615471 : add_AT_view_list (dw_die_ref die, enum dwarf_attribute attr_kind)
5003 : : {
5004 : 11615471 : dw_attr_node attr;
5005 : :
5006 : 11615471 : if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
5007 : : return;
5008 : :
5009 : 11615471 : attr.dw_attr = attr_kind;
5010 : 11615471 : attr.dw_attr_val.val_class = dw_val_class_view_list;
5011 : 11615471 : attr.dw_attr_val.val_entry = NULL;
5012 : 11615471 : attr.dw_attr_val.v.val_view_list = die;
5013 : 11615471 : add_dwarf_attr (die, &attr);
5014 : 11615471 : gcc_checking_assert (get_AT (die, DW_AT_location));
5015 : 11615471 : gcc_assert (have_location_lists);
5016 : : }
5017 : :
5018 : : /* Return a pointer to the location list referenced by the attribute.
5019 : : If the named attribute is a view list, look up the corresponding
5020 : : DW_AT_location attribute and return its location list. */
5021 : :
5022 : : static inline dw_loc_list_ref *
5023 : 22821682 : AT_loc_list_ptr (dw_attr_node *a)
5024 : : {
5025 : 33852978 : gcc_assert (a);
5026 : 33852978 : switch (AT_class (a))
5027 : : {
5028 : 22821682 : case dw_val_class_loc_list:
5029 : 22821682 : return &a->dw_attr_val.v.val_loc_list;
5030 : 11031296 : case dw_val_class_view_list:
5031 : 11031296 : {
5032 : 11031296 : dw_attr_node *l;
5033 : 11031296 : l = get_AT (a->dw_attr_val.v.val_view_list, DW_AT_location);
5034 : 11031296 : if (!l)
5035 : : return NULL;
5036 : 11031296 : gcc_checking_assert (l + 1 == a);
5037 : : return AT_loc_list_ptr (l);
5038 : : }
5039 : 0 : default:
5040 : 0 : gcc_unreachable ();
5041 : : }
5042 : : }
5043 : :
5044 : : /* Return the location attribute value associated with a view list
5045 : : attribute value. */
5046 : :
5047 : : static inline dw_val_node *
5048 : 11615505 : view_list_to_loc_list_val_node (dw_val_node *val)
5049 : : {
5050 : 11615505 : gcc_assert (val->val_class == dw_val_class_view_list);
5051 : 11615505 : dw_attr_node *loc = get_AT (val->v.val_view_list, DW_AT_location);
5052 : 11615505 : if (!loc)
5053 : : return NULL;
5054 : 11031330 : gcc_checking_assert (&(loc + 1)->dw_attr_val == val);
5055 : 11031330 : gcc_assert (AT_class (loc) == dw_val_class_loc_list);
5056 : 11031330 : return &loc->dw_attr_val;
5057 : : }
5058 : :
5059 : : struct addr_hasher : ggc_ptr_hash<addr_table_entry>
5060 : : {
5061 : : static hashval_t hash (addr_table_entry *);
5062 : : static bool equal (addr_table_entry *, addr_table_entry *);
5063 : : };
5064 : :
5065 : : /* Table of entries into the .debug_addr section. */
5066 : :
5067 : : static GTY (()) hash_table<addr_hasher> *addr_index_table;
5068 : :
5069 : : /* Hash an address_table_entry. */
5070 : :
5071 : : hashval_t
5072 : 342 : addr_hasher::hash (addr_table_entry *a)
5073 : : {
5074 : 342 : inchash::hash hstate;
5075 : 342 : switch (a->kind)
5076 : : {
5077 : 21 : case ate_kind_rtx:
5078 : 21 : hstate.add_int (0);
5079 : 21 : break;
5080 : 0 : case ate_kind_rtx_dtprel:
5081 : 0 : hstate.add_int (1);
5082 : 0 : break;
5083 : 321 : case ate_kind_label:
5084 : 321 : return htab_hash_string (a->addr.label);
5085 : 0 : default:
5086 : 0 : gcc_unreachable ();
5087 : : }
5088 : 21 : inchash::add_rtx (a->addr.rtl, hstate);
5089 : 21 : return hstate.end ();
5090 : : }
5091 : :
5092 : : /* Determine equality for two address_table_entries. */
5093 : :
5094 : : bool
5095 : 77 : addr_hasher::equal (addr_table_entry *a1, addr_table_entry *a2)
5096 : : {
5097 : 77 : if (a1->kind != a2->kind)
5098 : : return false;
5099 : 47 : switch (a1->kind)
5100 : : {
5101 : 3 : case ate_kind_rtx:
5102 : 3 : case ate_kind_rtx_dtprel:
5103 : 3 : return rtx_equal_p (a1->addr.rtl, a2->addr.rtl);
5104 : 44 : case ate_kind_label:
5105 : 44 : return strcmp (a1->addr.label, a2->addr.label) == 0;
5106 : 0 : default:
5107 : 0 : gcc_unreachable ();
5108 : : }
5109 : : }
5110 : :
5111 : : /* Initialize an addr_table_entry. */
5112 : :
5113 : : void
5114 : 535 : init_addr_table_entry (addr_table_entry *e, enum ate_kind kind, void *addr)
5115 : : {
5116 : 535 : e->kind = kind;
5117 : 535 : switch (kind)
5118 : : {
5119 : 9 : case ate_kind_rtx:
5120 : 9 : case ate_kind_rtx_dtprel:
5121 : 9 : e->addr.rtl = (rtx) addr;
5122 : 9 : break;
5123 : 526 : case ate_kind_label:
5124 : 526 : e->addr.label = (char *) addr;
5125 : 526 : break;
5126 : : }
5127 : 535 : e->refcount = 0;
5128 : 535 : e->index = NO_INDEX_ASSIGNED;
5129 : 535 : }
5130 : :
5131 : : /* Add attr to the address table entry to the table. Defer setting an
5132 : : index until output time. */
5133 : :
5134 : : static addr_table_entry *
5135 : 271 : add_addr_table_entry (void *addr, enum ate_kind kind)
5136 : : {
5137 : 271 : addr_table_entry *node;
5138 : 271 : addr_table_entry finder;
5139 : :
5140 : 271 : gcc_assert (dwarf_split_debug_info);
5141 : 271 : if (! addr_index_table)
5142 : 244 : addr_index_table = hash_table<addr_hasher>::create_ggc (10);
5143 : 271 : init_addr_table_entry (&finder, kind, addr);
5144 : 271 : addr_table_entry **slot = addr_index_table->find_slot (&finder, INSERT);
5145 : :
5146 : 271 : if (*slot == HTAB_EMPTY_ENTRY)
5147 : : {
5148 : 264 : node = ggc_cleared_alloc<addr_table_entry> ();
5149 : 264 : init_addr_table_entry (node, kind, addr);
5150 : 264 : *slot = node;
5151 : : }
5152 : : else
5153 : : node = *slot;
5154 : :
5155 : 271 : node->refcount++;
5156 : 271 : return node;
5157 : : }
5158 : :
5159 : : /* Remove an entry from the addr table by decrementing its refcount.
5160 : : Strictly, decrementing the refcount would be enough, but the
5161 : : assertion that the entry is actually in the table has found
5162 : : bugs. */
5163 : :
5164 : : static void
5165 : 3 : remove_addr_table_entry (addr_table_entry *entry)
5166 : : {
5167 : 3 : gcc_assert (dwarf_split_debug_info && addr_index_table);
5168 : : /* After an index is assigned, the table is frozen. */
5169 : 3 : gcc_assert (entry->refcount > 0 && entry->index == NO_INDEX_ASSIGNED);
5170 : 3 : entry->refcount--;
5171 : 3 : }
5172 : :
5173 : : /* Given a location list, remove all addresses it refers to from the
5174 : : address_table. */
5175 : :
5176 : : static void
5177 : 424 : remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
5178 : : {
5179 : 3384 : for (; descr; descr = descr->dw_loc_next)
5180 : 2960 : if (descr->dw_loc_oprnd1.val_entry != NULL)
5181 : : {
5182 : 0 : gcc_assert (descr->dw_loc_oprnd1.val_entry->index == NO_INDEX_ASSIGNED);
5183 : 0 : remove_addr_table_entry (descr->dw_loc_oprnd1.val_entry);
5184 : : }
5185 : 424 : }
5186 : :
5187 : : /* A helper function for dwarf2out_finish called through
5188 : : htab_traverse. Assign an addr_table_entry its index. All entries
5189 : : must be collected into the table when this function is called,
5190 : : because the indexing code relies on htab_traverse to traverse nodes
5191 : : in the same order for each run. */
5192 : :
5193 : : int
5194 : 264 : index_addr_table_entry (addr_table_entry **h, unsigned int *index)
5195 : : {
5196 : 264 : addr_table_entry *node = *h;
5197 : :
5198 : : /* Don't index unreferenced nodes. */
5199 : 264 : if (node->refcount == 0)
5200 : : return 1;
5201 : :
5202 : 264 : gcc_assert (node->index == NO_INDEX_ASSIGNED);
5203 : 264 : node->index = *index;
5204 : 264 : *index += 1;
5205 : :
5206 : 264 : return 1;
5207 : : }
5208 : :
5209 : : /* Return the tag of a given DIE. */
5210 : :
5211 : : enum dwarf_tag
5212 : 6973 : dw_get_die_tag (dw_die_ref die)
5213 : : {
5214 : 6973 : return die->die_tag;
5215 : : }
5216 : :
5217 : : /* Return a reference to the children list of a given DIE. */
5218 : :
5219 : : dw_die_ref
5220 : 2030 : dw_get_die_child (dw_die_ref die)
5221 : : {
5222 : 2030 : return die->die_child;
5223 : : }
5224 : :
5225 : : /* Return a reference to the sibling of a given DIE. */
5226 : :
5227 : : dw_die_ref
5228 : 1046 : dw_get_die_sib (dw_die_ref die)
5229 : : {
5230 : 1046 : return die->die_sib;
5231 : : }
5232 : :
5233 : : /* Add an address constant attribute value to a DIE. When using
5234 : : dwarf_split_debug_info, address attributes in dies destined for the
5235 : : final executable should be direct references--setting the parameter
5236 : : force_direct ensures this behavior. */
5237 : :
5238 : : static inline void
5239 : 1484635 : add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
5240 : : bool force_direct)
5241 : : {
5242 : 1484635 : dw_attr_node attr;
5243 : :
5244 : 1484635 : attr.dw_attr = attr_kind;
5245 : 1484635 : attr.dw_attr_val.val_class = dw_val_class_addr;
5246 : 1484635 : attr.dw_attr_val.v.val_addr = addr;
5247 : 1484635 : if (dwarf_split_debug_info && !force_direct)
5248 : 0 : attr.dw_attr_val.val_entry = add_addr_table_entry (addr, ate_kind_rtx);
5249 : : else
5250 : 1484635 : attr.dw_attr_val.val_entry = NULL;
5251 : 1484635 : add_dwarf_attr (die, &attr);
5252 : 1484635 : }
5253 : :
5254 : : /* Get the RTX from to an address DIE attribute. */
5255 : :
5256 : : static inline rtx
5257 : 28356 : AT_addr (dw_attr_node *a)
5258 : : {
5259 : 28356 : gcc_assert (a && AT_class (a) == dw_val_class_addr);
5260 : 28356 : return a->dw_attr_val.v.val_addr;
5261 : : }
5262 : :
5263 : : /* Add a file attribute value to a DIE. */
5264 : :
5265 : : static inline void
5266 : 196673517 : add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
5267 : : struct dwarf_file_data *fd)
5268 : : {
5269 : 196673517 : dw_attr_node attr;
5270 : :
5271 : 196673517 : attr.dw_attr = attr_kind;
5272 : 196673517 : attr.dw_attr_val.val_class = dw_val_class_file;
5273 : 196673517 : attr.dw_attr_val.val_entry = NULL;
5274 : 196673517 : attr.dw_attr_val.v.val_file = fd;
5275 : 196673517 : add_dwarf_attr (die, &attr);
5276 : 43544 : }
5277 : :
5278 : : /* Get the dwarf_file_data from a file DIE attribute. */
5279 : :
5280 : : static inline struct dwarf_file_data *
5281 : 15318699 : AT_file (dw_attr_node *a)
5282 : : {
5283 : 15318699 : gcc_assert (a && (AT_class (a) == dw_val_class_file
5284 : : || AT_class (a) == dw_val_class_file_implicit));
5285 : 15318699 : return a->dw_attr_val.v.val_file;
5286 : : }
5287 : :
5288 : : #if VMS_DEBUGGING_INFO
5289 : : /* Add a vms delta attribute value to a DIE. */
5290 : :
5291 : : static inline void
5292 : : add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
5293 : : const char *lbl1, const char *lbl2)
5294 : : {
5295 : : dw_attr_node attr;
5296 : :
5297 : : attr.dw_attr = attr_kind;
5298 : : attr.dw_attr_val.val_class = dw_val_class_vms_delta;
5299 : : attr.dw_attr_val.val_entry = NULL;
5300 : : attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
5301 : : attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
5302 : : add_dwarf_attr (die, &attr);
5303 : : }
5304 : : #endif
5305 : :
5306 : : /* Add a symbolic view identifier attribute value to a DIE. */
5307 : :
5308 : : static inline void
5309 : 6673950 : add_AT_symview (dw_die_ref die, enum dwarf_attribute attr_kind,
5310 : : const char *view_label)
5311 : : {
5312 : 6673950 : dw_attr_node attr;
5313 : :
5314 : 6673950 : attr.dw_attr = attr_kind;
5315 : 6673950 : attr.dw_attr_val.val_class = dw_val_class_symview;
5316 : 6673950 : attr.dw_attr_val.val_entry = NULL;
5317 : 6673950 : attr.dw_attr_val.v.val_symbolic_view = xstrdup (view_label);
5318 : 6673950 : add_dwarf_attr (die, &attr);
5319 : 6673950 : }
5320 : :
5321 : : /* Add a label identifier attribute value to a DIE. */
5322 : :
5323 : : static inline void
5324 : 9599206 : add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
5325 : : const char *lbl_id, int offset)
5326 : : {
5327 : 9599206 : dw_attr_node attr;
5328 : :
5329 : 9599206 : attr.dw_attr = attr_kind;
5330 : 9599206 : attr.dw_attr_val.val_class = dw_val_class_lbl_id;
5331 : 9599206 : attr.dw_attr_val.val_entry = NULL;
5332 : 9599206 : if (!offset)
5333 : 9599206 : attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5334 : : else
5335 : 0 : attr.dw_attr_val.v.val_lbl_id = xasprintf ("%s%+i", lbl_id, offset);
5336 : 9599206 : if (dwarf_split_debug_info)
5337 : 11 : attr.dw_attr_val.val_entry
5338 : 11 : = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id,
5339 : : ate_kind_label);
5340 : 9599206 : add_dwarf_attr (die, &attr);
5341 : 9599206 : }
5342 : :
5343 : : /* Add a section offset attribute value to a DIE, an offset into the
5344 : : debug_line section. */
5345 : :
5346 : : static inline void
5347 : 53621 : add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5348 : : const char *label)
5349 : : {
5350 : 53621 : dw_attr_node attr;
5351 : :
5352 : 53621 : attr.dw_attr = attr_kind;
5353 : 53621 : attr.dw_attr_val.val_class = dw_val_class_lineptr;
5354 : 53621 : attr.dw_attr_val.val_entry = NULL;
5355 : 53621 : attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5356 : 53621 : add_dwarf_attr (die, &attr);
5357 : 53621 : }
5358 : :
5359 : : /* Add a section offset attribute value to a DIE, an offset into the
5360 : : debug_macinfo section. */
5361 : :
5362 : : static inline void
5363 : 525 : add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
5364 : : const char *label)
5365 : : {
5366 : 525 : dw_attr_node attr;
5367 : :
5368 : 525 : attr.dw_attr = attr_kind;
5369 : 525 : attr.dw_attr_val.val_class = dw_val_class_macptr;
5370 : 525 : attr.dw_attr_val.val_entry = NULL;
5371 : 525 : attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
5372 : 525 : add_dwarf_attr (die, &attr);
5373 : 525 : }
5374 : :
5375 : : /* Add a range_list attribute value to a DIE. When using
5376 : : dwarf_split_debug_info, address attributes in dies destined for the
5377 : : final executable should be direct references--setting the parameter
5378 : : force_direct ensures this behavior. */
5379 : :
5380 : : #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
5381 : : #define RELOCATED_OFFSET (NULL)
5382 : :
5383 : : static void
5384 : 3179967 : add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5385 : : long unsigned int offset, bool force_direct)
5386 : : {
5387 : 3179967 : dw_attr_node attr;
5388 : :
5389 : 3179967 : attr.dw_attr = attr_kind;
5390 : 3179967 : attr.dw_attr_val.val_class = dw_val_class_range_list;
5391 : : /* For the range_list attribute, use val_entry to store whether the
5392 : : offset should follow split-debug-info or normal semantics. This
5393 : : value is read in output_range_list_offset. */
5394 : 3179967 : if (dwarf_split_debug_info && !force_direct)
5395 : 3 : attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
5396 : : else
5397 : 3179964 : attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
5398 : 3179967 : attr.dw_attr_val.v.val_offset = offset;
5399 : 3179967 : add_dwarf_attr (die, &attr);
5400 : 3179967 : }
5401 : :
5402 : : /* Return the start label of a delta attribute. */
5403 : :
5404 : : static inline const char *
5405 : 0 : AT_vms_delta1 (dw_attr_node *a)
5406 : : {
5407 : 0 : gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5408 : 0 : return a->dw_attr_val.v.val_vms_delta.lbl1;
5409 : : }
5410 : :
5411 : : /* Return the end label of a delta attribute. */
5412 : :
5413 : : static inline const char *
5414 : 0 : AT_vms_delta2 (dw_attr_node *a)
5415 : : {
5416 : 0 : gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
5417 : 0 : return a->dw_attr_val.v.val_vms_delta.lbl2;
5418 : : }
5419 : :
5420 : : static inline const char *
5421 : 24451431 : AT_lbl (dw_attr_node *a)
5422 : : {
5423 : 24451431 : gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5424 : : || AT_class (a) == dw_val_class_lineptr
5425 : : || AT_class (a) == dw_val_class_macptr
5426 : : || AT_class (a) == dw_val_class_loclistsptr
5427 : : || AT_class (a) == dw_val_class_high_pc));
5428 : 24451431 : return a->dw_attr_val.v.val_lbl_id;
5429 : : }
5430 : :
5431 : : /* Get the attribute of type attr_kind. */
5432 : :
5433 : : dw_attr_node *
5434 : 719443318 : get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5435 : : {
5436 : 804260334 : dw_attr_node *a;
5437 : 804260334 : unsigned ix;
5438 : 804260334 : dw_die_ref spec = NULL;
5439 : :
5440 : 804260334 : if (! die)
5441 : : return NULL;
5442 : :
5443 : 2805766239 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5444 : 2589990507 : if (a->dw_attr == attr_kind)
5445 : : return a;
5446 : 2001505905 : else if (a->dw_attr == DW_AT_specification
5447 : 1942608745 : || a->dw_attr == DW_AT_abstract_origin)
5448 : 124108750 : spec = AT_ref (a);
5449 : :
5450 : 215775732 : if (spec)
5451 : : return get_AT (spec, attr_kind);
5452 : :
5453 : : return NULL;
5454 : : }
5455 : :
5456 : : /* Returns the parent of the declaration of DIE. */
5457 : :
5458 : : dw_die_ref
5459 : 80 : dw_get_die_parent (dw_die_ref die)
5460 : : {
5461 : 80 : dw_die_ref t;
5462 : :
5463 : 80 : if (!die)
5464 : : return NULL;
5465 : :
5466 : 80 : if ((t = get_AT_ref (die, DW_AT_abstract_origin))
5467 : 80 : || (t = get_AT_ref (die, DW_AT_specification)))
5468 : : die = t;
5469 : :
5470 : 80 : return die->die_parent;
5471 : : }
5472 : :
5473 : : /* Return the "low pc" attribute value, typically associated with a subprogram
5474 : : DIE. Return null if the "low pc" attribute is either not present, or if it
5475 : : cannot be represented as an assembler label identifier. */
5476 : :
5477 : : static inline const char *
5478 : 4929347 : get_AT_low_pc (dw_die_ref die)
5479 : : {
5480 : 4929347 : dw_attr_node *a = get_AT (die, DW_AT_low_pc);
5481 : :
5482 : 4929347 : return a ? AT_lbl (a) : NULL;
5483 : : }
5484 : :
5485 : : /* Return the value of the string attribute designated by ATTR_KIND, or
5486 : : NULL if it is not present. */
5487 : :
5488 : : const char *
5489 : 57410 : get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5490 : : {
5491 : 57410 : dw_attr_node *a = get_AT (die, attr_kind);
5492 : :
5493 : 57410 : return a ? AT_string (a) : NULL;
5494 : : }
5495 : :
5496 : : /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5497 : : if it is not present. */
5498 : :
5499 : : int
5500 : 46773311 : get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5501 : : {
5502 : 46773311 : dw_attr_node *a = get_AT (die, attr_kind);
5503 : :
5504 : 46773311 : return a ? AT_flag (a) : 0;
5505 : : }
5506 : :
5507 : : /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5508 : : if it is not present. */
5509 : :
5510 : : unsigned
5511 : 316405389 : get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5512 : : {
5513 : 316405389 : dw_attr_node *a = get_AT (die, attr_kind);
5514 : :
5515 : 316405389 : return a ? AT_unsigned (a) : 0;
5516 : : }
5517 : :
5518 : : dw_die_ref
5519 : 31655545 : get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5520 : : {
5521 : 31655545 : dw_attr_node *a = get_AT (die, attr_kind);
5522 : :
5523 : 31655545 : return a ? AT_ref (a) : NULL;
5524 : : }
5525 : :
5526 : : struct dwarf_file_data *
5527 : 15186611 : get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
5528 : : {
5529 : 15186611 : dw_attr_node *a = get_AT (die, attr_kind);
5530 : :
5531 : 15186611 : return a ? AT_file (a) : NULL;
5532 : : }
5533 : :
5534 : : /* Return TRUE if the language is C. */
5535 : :
5536 : : static inline bool
5537 : 6380 : is_c (void)
5538 : : {
5539 : 6380 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5540 : :
5541 : 6380 : return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_C99
5542 : 6380 : || lang == DW_LANG_C11 || lang == DW_LANG_ObjC);
5543 : :
5544 : :
5545 : : }
5546 : :
5547 : : /* Return TRUE if the language is C++. */
5548 : :
5549 : : static inline bool
5550 : 18651014 : is_cxx (void)
5551 : : {
5552 : 18651014 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5553 : :
5554 : 18651014 : return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
5555 : 18651014 : || lang == DW_LANG_C_plus_plus_11 || lang == DW_LANG_C_plus_plus_14);
5556 : : }
5557 : :
5558 : : /* Return TRUE if DECL was created by the C++ frontend. */
5559 : :
5560 : : static bool
5561 : 17244201 : is_cxx (const_tree decl)
5562 : : {
5563 : 17244201 : if (in_lto_p)
5564 : : {
5565 : 16 : const_tree context = get_ultimate_context (decl);
5566 : 32 : if (context && TRANSLATION_UNIT_LANGUAGE (context))
5567 : 16 : return startswith (TRANSLATION_UNIT_LANGUAGE (context), "GNU C++");
5568 : : }
5569 : 17244185 : return is_cxx ();
5570 : : }
5571 : :
5572 : : /* Return TRUE if the language is Fortran. */
5573 : :
5574 : : static inline bool
5575 : 132784067 : is_fortran (void)
5576 : : {
5577 : 132784067 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5578 : :
5579 : 132784067 : return (lang == DW_LANG_Fortran77
5580 : 132784067 : || lang == DW_LANG_Fortran90
5581 : 132784067 : || lang == DW_LANG_Fortran95
5582 : : || lang == DW_LANG_Fortran03
5583 : 132784067 : || lang == DW_LANG_Fortran08);
5584 : : }
5585 : :
5586 : : static inline bool
5587 : 112 : is_fortran (const_tree decl)
5588 : : {
5589 : 112 : if (in_lto_p)
5590 : : {
5591 : 112 : const_tree context = get_ultimate_context (decl);
5592 : 224 : if (context && TRANSLATION_UNIT_LANGUAGE (context))
5593 : 112 : return (strncmp (TRANSLATION_UNIT_LANGUAGE (context),
5594 : : "GNU Fortran", 11) == 0
5595 : 112 : || strcmp (TRANSLATION_UNIT_LANGUAGE (context),
5596 : : "GNU F77") == 0);
5597 : : }
5598 : 0 : return is_fortran ();
5599 : : }
5600 : :
5601 : : /* Return TRUE if the language is Rust.
5602 : : Note, returns FALSE for dwarf_version < 5 && dwarf_strict. */
5603 : :
5604 : : static inline bool
5605 : 78979 : is_rust (void)
5606 : : {
5607 : 78979 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5608 : :
5609 : 78979 : return lang == DW_LANG_Rust;
5610 : : }
5611 : :
5612 : : /* Return TRUE if the language is Ada. */
5613 : :
5614 : : static inline bool
5615 : 2520126 : is_ada (void)
5616 : : {
5617 : 2520126 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5618 : :
5619 : 2520126 : return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5620 : : }
5621 : :
5622 : : /* Return TRUE if the language is D. */
5623 : :
5624 : : static inline bool
5625 : 52006698 : is_dlang (void)
5626 : : {
5627 : 52006698 : unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
5628 : :
5629 : 52006698 : return lang == DW_LANG_D;
5630 : : }
5631 : :
5632 : : /* Remove the specified attribute if present. Return TRUE if removal
5633 : : was successful. */
5634 : :
5635 : : static bool
5636 : 34951050 : remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5637 : : {
5638 : 34951050 : dw_attr_node *a;
5639 : 34951050 : unsigned ix;
5640 : :
5641 : 34951050 : if (! die)
5642 : : return false;
5643 : :
5644 : 74429714 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
5645 : 73929787 : if (a->dw_attr == attr_kind)
5646 : : {
5647 : 34451123 : if (AT_class (a) == dw_val_class_str)
5648 : 249 : if (a->dw_attr_val.v.val_str->refcount)
5649 : 249 : a->dw_attr_val.v.val_str->refcount--;
5650 : :
5651 : : /* vec::ordered_remove should help reduce the number of abbrevs
5652 : : that are needed. */
5653 : 34451123 : die->die_attr->ordered_remove (ix);
5654 : 34451123 : return true;
5655 : : }
5656 : : return false;
5657 : : }
5658 : :
5659 : : /* Remove CHILD from its parent. PREV must have the property that
5660 : : PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5661 : :
5662 : : static void
5663 : 6307836 : remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
5664 : : {
5665 : 6307836 : gcc_assert (child->die_parent == prev->die_parent);
5666 : 6307836 : gcc_assert (prev->die_sib == child);
5667 : 6307836 : if (prev == child)
5668 : : {
5669 : 18862 : gcc_assert (child->die_parent->die_child == child);
5670 : : prev = NULL;
5671 : : }
5672 : : else
5673 : 6288974 : prev->die_sib = child->die_sib;
5674 : 6307836 : if (child->die_parent->die_child == child)
5675 : 97274 : child->die_parent->die_child = prev;
5676 : 6307836 : child->die_sib = NULL;
5677 : 6307836 : }
5678 : :
5679 : : /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
5680 : : PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
5681 : :
5682 : : static void
5683 : 138 : replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
5684 : : {
5685 : 138 : dw_die_ref parent = old_child->die_parent;
5686 : :
5687 : 138 : gcc_assert (parent == prev->die_parent);
5688 : 138 : gcc_assert (prev->die_sib == old_child);
5689 : :
5690 : 138 : new_child->die_parent = parent;
5691 : 138 : if (prev == old_child)
5692 : : {
5693 : 19 : gcc_assert (parent->die_child == old_child);
5694 : 19 : new_child->die_sib = new_child;
5695 : : }
5696 : : else
5697 : : {
5698 : 119 : prev->die_sib = new_child;
5699 : 119 : new_child->die_sib = old_child->die_sib;
5700 : : }
5701 : 138 : if (old_child->die_parent->die_child == old_child)
5702 : 25 : old_child->die_parent->die_child = new_child;
5703 : 138 : old_child->die_sib = NULL;
5704 : 138 : }
5705 : :
5706 : : /* Move all children from OLD_PARENT to NEW_PARENT. */
5707 : :
5708 : : static void
5709 : 76 : move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
5710 : : {
5711 : 76 : dw_die_ref c;
5712 : 76 : new_parent->die_child = old_parent->die_child;
5713 : 76 : old_parent->die_child = NULL;
5714 : 85 : FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
5715 : 0 : }
5716 : :
5717 : : /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5718 : : matches TAG. */
5719 : :
5720 : : static void
5721 : 45262 : remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5722 : : {
5723 : 45262 : dw_die_ref c;
5724 : :
5725 : 45262 : c = die->die_child;
5726 : 45262 : if (c) do {
5727 : 70997 : dw_die_ref prev = c;
5728 : 70997 : c = c->die_sib;
5729 : 131972 : while (c->die_tag == tag)
5730 : : {
5731 : 79836 : remove_child_with_prev (c, prev);
5732 : 79836 : c->die_parent = NULL;
5733 : : /* Might have removed every child. */
5734 : 79836 : if (die->die_child == NULL)
5735 : : return;
5736 : 60975 : c = prev->die_sib;
5737 : : }
5738 : 52136 : } while (c != die->die_child);
5739 : : }
5740 : :
5741 : : /* Add a CHILD_DIE as the last child of DIE. */
5742 : :
5743 : : static void
5744 : 493398237 : add_child_die (dw_die_ref die, dw_die_ref child_die)
5745 : : {
5746 : : /* FIXME this should probably be an assert. */
5747 : 493398237 : if (! die || ! child_die)
5748 : : return;
5749 : 493272415 : gcc_assert (die != child_die);
5750 : :
5751 : 493272415 : child_die->die_parent = die;
5752 : 493272415 : if (die->die_child)
5753 : : {
5754 : 369116500 : child_die->die_sib = die->die_child->die_sib;
5755 : 369116500 : die->die_child->die_sib = child_die;
5756 : : }
5757 : : else
5758 : 124155915 : child_die->die_sib = child_die;
5759 : 493272415 : die->die_child = child_die;
5760 : : }
5761 : :
5762 : : /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
5763 : :
5764 : : static void
5765 : 9705782 : add_child_die_after (dw_die_ref die, dw_die_ref child_die,
5766 : : dw_die_ref after_die)
5767 : : {
5768 : 9705782 : gcc_assert (die
5769 : : && child_die
5770 : : && after_die
5771 : : && die->die_child
5772 : : && die != child_die);
5773 : :
5774 : 9705782 : child_die->die_parent = die;
5775 : 9705782 : child_die->die_sib = after_die->die_sib;
5776 : 9705782 : after_die->die_sib = child_die;
5777 : 9705782 : if (die->die_child == after_die)
5778 : 6194934 : die->die_child = child_die;
5779 : 9705782 : }
5780 : :
5781 : : /* Unassociate CHILD from its parent, and make its parent be
5782 : : NEW_PARENT. */
5783 : :
5784 : : static void
5785 : 6221258 : reparent_child (dw_die_ref child, dw_die_ref new_parent)
5786 : : {
5787 : 6221258 : for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
5788 : 9137154783 : if (p->die_sib == child)
5789 : : {
5790 : 6221258 : remove_child_with_prev (child, p);
5791 : 6221258 : break;
5792 : : }
5793 : 6221258 : add_child_die (new_parent, child);
5794 : 6221258 : }
5795 : :
5796 : : /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5797 : : is the specification, to the end of PARENT's list of children.
5798 : : This is done by removing and re-adding it. */
5799 : :
5800 : : static void
5801 : 4840 : splice_child_die (dw_die_ref parent, dw_die_ref child)
5802 : : {
5803 : : /* We want the declaration DIE from inside the class, not the
5804 : : specification DIE at toplevel. */
5805 : 4840 : if (child->die_parent != parent)
5806 : : {
5807 : 453 : dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5808 : :
5809 : 453 : if (tmp)
5810 : 4840 : child = tmp;
5811 : : }
5812 : :
5813 : 4840 : gcc_assert (child->die_parent == parent
5814 : : || (child->die_parent
5815 : : == get_AT_ref (parent, DW_AT_specification)));
5816 : :
5817 : 4840 : reparent_child (child, parent);
5818 : 4840 : }
5819 : :
5820 : : /* Create and return a new die with TAG_VALUE as tag. */
5821 : :
5822 : : dw_die_ref
5823 : 496844422 : new_die_raw (enum dwarf_tag tag_value)
5824 : : {
5825 : 496844422 : dw_die_ref die = ggc_cleared_alloc<die_node> ();
5826 : 496844422 : die->die_tag = tag_value;
5827 : 496844422 : return die;
5828 : : }
5829 : :
5830 : : /* Create and return a new die with a parent of PARENT_DIE. If
5831 : : PARENT_DIE is NULL, the new DIE is placed in limbo and an
5832 : : associated tree T must be supplied to determine parenthood
5833 : : later. */
5834 : :
5835 : : static inline dw_die_ref
5836 : 486534646 : new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5837 : : {
5838 : 486534646 : dw_die_ref die = new_die_raw (tag_value);
5839 : :
5840 : 486534646 : if (parent_die != NULL)
5841 : 486335587 : add_child_die (parent_die, die);
5842 : : else
5843 : : {
5844 : 199059 : limbo_die_node *limbo_node;
5845 : :
5846 : : /* No DIEs created after early dwarf should end up in limbo,
5847 : : because the limbo list should not persist past LTO
5848 : : streaming. */
5849 : 199059 : if (tag_value != DW_TAG_compile_unit
5850 : : /* These are allowed because they're generated while
5851 : : breaking out COMDAT units late. */
5852 : 199059 : && tag_value != DW_TAG_type_unit
5853 : 141924 : && tag_value != DW_TAG_skeleton_unit
5854 : 141924 : && !early_dwarf
5855 : : /* Allow nested functions to live in limbo because they will
5856 : : only temporarily live there, as decls_for_scope will fix
5857 : : them up. */
5858 : 2906 : && (TREE_CODE (t) != FUNCTION_DECL
5859 : 0 : || !decl_function_context (t))
5860 : : /* Same as nested functions above but for types. Types that
5861 : : are local to a function will be fixed in
5862 : : decls_for_scope. */
5863 : 2906 : && (!RECORD_OR_UNION_TYPE_P (t)
5864 : 2 : || !TYPE_CONTEXT (t)
5865 : 2 : || TREE_CODE (TYPE_CONTEXT (t)) != FUNCTION_DECL)
5866 : : /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5867 : : especially in the ltrans stage, but once we implement LTO
5868 : : dwarf streaming, we should remove this exception. */
5869 : 201963 : && !in_lto_p)
5870 : : {
5871 : 0 : fprintf (stderr, "symbol ended up in limbo too late:");
5872 : 0 : debug_generic_stmt (t);
5873 : 0 : gcc_unreachable ();
5874 : : }
5875 : :
5876 : 199059 : limbo_node = ggc_cleared_alloc<limbo_die_node> ();
5877 : 199059 : limbo_node->die = die;
5878 : 199059 : limbo_node->created_for = t;
5879 : 199059 : limbo_node->next = limbo_die_list;
5880 : 199059 : limbo_die_list = limbo_node;
5881 : : }
5882 : :
5883 : 486534646 : return die;
5884 : : }
5885 : :
5886 : : /* Return the DIE associated with the given type specifier. */
5887 : :
5888 : : dw_die_ref
5889 : 1221826647 : lookup_type_die (tree type)
5890 : : {
5891 : 1221826647 : dw_die_ref die = TYPE_SYMTAB_DIE (type);
5892 : 1221826647 : if (die && die->removed)
5893 : : {
5894 : 1449 : TYPE_SYMTAB_DIE (type) = NULL;
5895 : 1449 : TREE_ASM_WRITTEN (type) = 0;
5896 : 1449 : return NULL;
5897 : : }
5898 : : return die;
5899 : : }
5900 : :
5901 : : /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5902 : : anonymous type named by the typedef TYPE_DIE, return the DIE of the
5903 : : anonymous type instead the one of the naming typedef. */
5904 : :
5905 : : static inline dw_die_ref
5906 : 17995051 : strip_naming_typedef (tree type, dw_die_ref type_die)
5907 : : {
5908 : 17995051 : if (type
5909 : 17995051 : && TREE_CODE (type) == RECORD_TYPE
5910 : 17857758 : && type_die
5911 : 17857758 : && type_die->die_tag == DW_TAG_typedef
5912 : 17995063 : && is_naming_typedef_decl (TYPE_NAME (type)))
5913 : 12 : type_die = get_AT_ref (type_die, DW_AT_type);
5914 : 17995051 : return type_die;
5915 : : }
5916 : :
5917 : : /* Like lookup_type_die, but if type is an anonymous type named by a
5918 : : typedef[1], return the DIE of the anonymous type instead the one of
5919 : : the naming typedef. This is because in gen_typedef_die, we did
5920 : : equate the anonymous struct named by the typedef with the DIE of
5921 : : the naming typedef. So by default, lookup_type_die on an anonymous
5922 : : struct yields the DIE of the naming typedef.
5923 : :
5924 : : [1]: Read the comment of is_naming_typedef_decl to learn about what
5925 : : a naming typedef is. */
5926 : :
5927 : : static inline dw_die_ref
5928 : 126372 : lookup_type_die_strip_naming_typedef (tree type)
5929 : : {
5930 : 126372 : dw_die_ref die = lookup_type_die (type);
5931 : 126372 : return strip_naming_typedef (type, die);
5932 : : }
5933 : :
5934 : : /* Equate a DIE to a given type specifier. */
5935 : :
5936 : : static inline void
5937 : 113229485 : equate_type_number_to_die (tree type, dw_die_ref type_die)
5938 : : {
5939 : 113229485 : TYPE_SYMTAB_DIE (type) = type_die;
5940 : 113229485 : }
5941 : :
5942 : : static dw_die_ref maybe_create_die_with_external_ref (tree);
5943 : : struct GTY(()) sym_off_pair
5944 : : {
5945 : : const char * GTY((skip)) sym;
5946 : : unsigned HOST_WIDE_INT off;
5947 : : };
5948 : : static GTY(()) hash_map<tree, sym_off_pair> *external_die_map;
5949 : :
5950 : : /* Returns a hash value for X (which really is a die_struct). */
5951 : :
5952 : : inline hashval_t
5953 : 7277695520 : decl_die_hasher::hash (die_node *x)
5954 : : {
5955 : 7277695520 : return (hashval_t) x->decl_id;
5956 : : }
5957 : :
5958 : : /* Return true if decl_id of die_struct X is the same as UID of decl *Y. */
5959 : :
5960 : : inline bool
5961 : 8199302581 : decl_die_hasher::equal (die_node *x, tree y)
5962 : : {
5963 : 8199302581 : return (x->decl_id == DECL_UID (y));
5964 : : }
5965 : :
5966 : : /* Return the DIE associated with a given declaration. */
5967 : :
5968 : : dw_die_ref
5969 : 795647016 : lookup_decl_die (tree decl)
5970 : : {
5971 : 795647016 : dw_die_ref *die = decl_die_table->find_slot_with_hash (decl, DECL_UID (decl),
5972 : : NO_INSERT);
5973 : 795647016 : if (!die)
5974 : : {
5975 : 392997450 : if (in_lto_p)
5976 : 37665 : return maybe_create_die_with_external_ref (decl);
5977 : : return NULL;
5978 : : }
5979 : 402649566 : if ((*die)->removed)
5980 : : {
5981 : 132 : decl_die_table->clear_slot (die);
5982 : 132 : return NULL;
5983 : : }
5984 : : return *die;
5985 : : }
5986 : :
5987 : :
5988 : : /* Return the DIE associated with BLOCK. */
5989 : :
5990 : : static inline dw_die_ref
5991 : 19181603 : lookup_block_die (tree block)
5992 : : {
5993 : 19181603 : dw_die_ref die = BLOCK_DIE (block);
5994 : 19181603 : if (!die && in_lto_p)
5995 : 9596 : return maybe_create_die_with_external_ref (block);
5996 : : return die;
5997 : : }
5998 : :
5999 : : /* Associate DIE with BLOCK. */
6000 : :
6001 : : static inline void
6002 : 7688206 : equate_block_to_die (tree block, dw_die_ref die)
6003 : : {
6004 : 7688206 : BLOCK_DIE (block) = die;
6005 : 7688206 : }
6006 : : #undef BLOCK_DIE
6007 : :
6008 : :
6009 : : /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
6010 : : style reference. Return true if we found one refering to a DIE for
6011 : : DECL, otherwise return false. */
6012 : :
6013 : : static bool
6014 : 136911 : dwarf2out_die_ref_for_decl (tree decl, const char **sym,
6015 : : unsigned HOST_WIDE_INT *off)
6016 : : {
6017 : 136911 : dw_die_ref die;
6018 : :
6019 : 136911 : if (in_lto_p)
6020 : : {
6021 : : /* During WPA stage and incremental linking we use a hash-map
6022 : : to store the decl <-> label + offset map. */
6023 : 27668 : if (!external_die_map)
6024 : : return false;
6025 : 26275 : sym_off_pair *desc = external_die_map->get (decl);
6026 : 26275 : if (!desc)
6027 : : return false;
6028 : 11237 : *sym = desc->sym;
6029 : 11237 : *off = desc->off;
6030 : 11237 : return true;
6031 : : }
6032 : :
6033 : 109243 : if (TREE_CODE (decl) == BLOCK)
6034 : 26656 : die = lookup_block_die (decl);
6035 : : else
6036 : 82587 : die = lookup_decl_die (decl);
6037 : 109243 : if (!die)
6038 : : return false;
6039 : :
6040 : : /* Similar to get_ref_die_offset_label, but using the "correct"
6041 : : label. */
6042 : 36786 : *off = die->die_offset;
6043 : 96538 : while (die->die_parent)
6044 : : die = die->die_parent;
6045 : : /* For the containing CU DIE we compute a die_symbol in
6046 : : compute_comp_unit_symbol. */
6047 : 36786 : if (die->die_tag == DW_TAG_compile_unit)
6048 : : {
6049 : 36783 : gcc_assert (die->die_id.die_symbol != NULL);
6050 : 36783 : *sym = die->die_id.die_symbol;
6051 : 36783 : return true;
6052 : : }
6053 : : /* While we can gracefully handle running into say a type unit
6054 : : we don't really want and consider this a bug. */
6055 : 3 : if (flag_checking)
6056 : 0 : gcc_unreachable ();
6057 : : return false;
6058 : : }
6059 : :
6060 : : /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE. */
6061 : :
6062 : : static void
6063 : 28568 : add_AT_external_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind,
6064 : : const char *symbol, HOST_WIDE_INT offset)
6065 : : {
6066 : : /* Create a fake DIE that contains the reference. Don't use
6067 : : new_die because we don't want to end up in the limbo list. */
6068 : : /* ??? We probably want to share these, thus put a ref to the DIE
6069 : : we create here to the external_die_map entry. */
6070 : 28568 : dw_die_ref ref = new_die_raw (die->die_tag);
6071 : 28568 : ref->die_id.die_symbol = symbol;
6072 : 28568 : ref->die_offset = offset;
6073 : 28568 : ref->with_offset = 1;
6074 : 28568 : add_AT_die_ref (die, attr_kind, ref);
6075 : 28568 : }
6076 : :
6077 : : /* Create a DIE for DECL if required and add a reference to a DIE
6078 : : at SYMBOL + OFFSET which contains attributes dumped early. */
6079 : :
6080 : : static void
6081 : 43519 : dwarf2out_register_external_die (tree decl, const char *sym,
6082 : : unsigned HOST_WIDE_INT off)
6083 : : {
6084 : 43519 : if (debug_info_level == DINFO_LEVEL_NONE)
6085 : 0 : return;
6086 : :
6087 : 43519 : if (!external_die_map)
6088 : 1348 : external_die_map = hash_map<tree, sym_off_pair>::create_ggc (1000);
6089 : 43519 : gcc_checking_assert (!external_die_map->get (decl));
6090 : 43519 : sym_off_pair p = { IDENTIFIER_POINTER (get_identifier (sym)), off };
6091 : 43519 : external_die_map->put (decl, p);
6092 : : }
6093 : :
6094 : : /* If we have a registered external DIE for DECL return a new DIE for
6095 : : the concrete instance with an appropriate abstract origin. */
6096 : :
6097 : : static dw_die_ref
6098 : 47261 : maybe_create_die_with_external_ref (tree decl)
6099 : : {
6100 : 47261 : if (!external_die_map)
6101 : : return NULL;
6102 : 47109 : sym_off_pair *desc = external_die_map->get (decl);
6103 : 47109 : if (!desc)
6104 : : return NULL;
6105 : :
6106 : 20078 : const char *sym = desc->sym;
6107 : 20078 : unsigned HOST_WIDE_INT off = desc->off;
6108 : 20078 : external_die_map->remove (decl);
6109 : :
6110 : 20078 : in_lto_p = false;
6111 : 20078 : dw_die_ref die = (TREE_CODE (decl) == BLOCK
6112 : 20078 : ? lookup_block_die (decl) : lookup_decl_die (decl));
6113 : 20078 : gcc_assert (!die);
6114 : 20078 : in_lto_p = true;
6115 : :
6116 : 20078 : tree ctx;
6117 : 20078 : dw_die_ref parent = NULL;
6118 : : /* Need to lookup a DIE for the decls context - the containing
6119 : : function or translation unit. */
6120 : 20078 : if (TREE_CODE (decl) == BLOCK)
6121 : : {
6122 : 408 : ctx = BLOCK_SUPERCONTEXT (decl);
6123 : : /* ??? We do not output DIEs for all scopes thus skip as
6124 : : many DIEs as needed. */
6125 : 408 : while (TREE_CODE (ctx) == BLOCK
6126 : 1062 : && !lookup_block_die (ctx))
6127 : 654 : ctx = BLOCK_SUPERCONTEXT (ctx);
6128 : : }
6129 : : else
6130 : 19670 : ctx = DECL_CONTEXT (decl);
6131 : : /* Peel types in the context stack. */
6132 : 20666 : while (ctx && TYPE_P (ctx))
6133 : 588 : ctx = TYPE_CONTEXT (ctx);
6134 : : /* Likewise namespaces in case we do not want to emit DIEs for them. */
6135 : 20078 : if (debug_info_level <= DINFO_LEVEL_TERSE)
6136 : 998 : while (ctx && TREE_CODE (ctx) == NAMESPACE_DECL)
6137 : 5 : ctx = DECL_CONTEXT (ctx);
6138 : 20078 : if (ctx)
6139 : : {
6140 : 19944 : if (TREE_CODE (ctx) == BLOCK)
6141 : 52 : parent = lookup_block_die (ctx);
6142 : 19892 : else if (TREE_CODE (ctx) == TRANSLATION_UNIT_DECL
6143 : : /* Keep the 1:1 association during WPA. */
6144 : 3717 : && !flag_wpa
6145 : 3717 : && flag_incremental_link != INCREMENTAL_LINK_LTO)
6146 : : /* Otherwise all late annotations go to the main CU which
6147 : : imports the original CUs. */
6148 : 3717 : parent = comp_unit_die ();
6149 : 16175 : else if (TREE_CODE (ctx) == FUNCTION_DECL
6150 : 11920 : && TREE_CODE (decl) != FUNCTION_DECL
6151 : : && TREE_CODE (decl) != PARM_DECL
6152 : : && TREE_CODE (decl) != RESULT_DECL
6153 : : && TREE_CODE (decl) != BLOCK)
6154 : : /* Leave function local entities parent determination to when
6155 : : we process scope vars. */
6156 : : ;
6157 : : else
6158 : 13271 : parent = lookup_decl_die (ctx);
6159 : : }
6160 : : else
6161 : : /* In some cases the FEs fail to set DECL_CONTEXT properly.
6162 : : Handle this case gracefully by globalizing stuff. */
6163 : 134 : parent = comp_unit_die ();
6164 : : /* Create a DIE "stub". */
6165 : 20078 : switch (TREE_CODE (decl))
6166 : : {
6167 : 134 : case TRANSLATION_UNIT_DECL:
6168 : 134 : {
6169 : 134 : die = comp_unit_die ();
6170 : : /* We re-target all CU decls to the LTRANS CU DIE, so no need
6171 : : to create a DIE for the original CUs. */
6172 : 134 : return die;
6173 : : }
6174 : 112 : case NAMESPACE_DECL:
6175 : 112 : if (is_fortran (decl))
6176 : 6 : die = new_die (DW_TAG_module, parent, decl);
6177 : : else
6178 : 106 : die = new_die (DW_TAG_namespace, parent, decl);
6179 : : break;
6180 : 7248 : case FUNCTION_DECL:
6181 : 7248 : die = new_die (DW_TAG_subprogram, parent, decl);
6182 : 7248 : break;
6183 : 3549 : case VAR_DECL:
6184 : 3549 : die = new_die (DW_TAG_variable, parent, decl);
6185 : 3549 : break;
6186 : 0 : case RESULT_DECL:
6187 : 0 : die = new_die (DW_TAG_variable, parent, decl);
6188 : 0 : break;
6189 : 8619 : case PARM_DECL:
6190 : 8619 : die = new_die (DW_TAG_formal_parameter, parent, decl);
6191 : 8619 : break;
6192 : 0 : case CONST_DECL:
6193 : 0 : die = new_die (DW_TAG_constant, parent, decl);
6194 : 0 : break;
6195 : 8 : case LABEL_DECL:
6196 : 8 : die = new_die (DW_TAG_label, parent, decl);
6197 : 8 : break;
6198 : 408 : case BLOCK:
6199 : 408 : die = new_die (DW_TAG_lexical_block, parent, decl);
6200 : 408 : break;
6201 : 0 : default:
6202 : 0 : gcc_unreachable ();
6203 : : }
6204 : 19944 : if (TREE_CODE (decl) == BLOCK)
6205 : 408 : equate_block_to_die (decl, die);
6206 : : else
6207 : 19536 : equate_decl_number_to_die (decl, die);
6208 : :
6209 : 19944 : add_desc_attribute (die, decl);
6210 : :
6211 : : /* Add a reference to the DIE providing early debug at $sym + off. */
6212 : 19944 : add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
6213 : :
6214 : 19944 : return die;
6215 : : }
6216 : :
6217 : : /* Returns a hash value for X (which really is a var_loc_list). */
6218 : :
6219 : : inline hashval_t
6220 : 367400643 : decl_loc_hasher::hash (var_loc_list *x)
6221 : : {
6222 : 367400643 : return (hashval_t) x->decl_id;
6223 : : }
6224 : :
6225 : : /* Return true if decl_id of var_loc_list X is the same as
6226 : : UID of decl *Y. */
6227 : :
6228 : : inline bool
6229 : 445276151 : decl_loc_hasher::equal (var_loc_list *x, const_tree y)
6230 : : {
6231 : 445276151 : return (x->decl_id == DECL_UID (y));
6232 : : }
6233 : :
6234 : : /* Return the var_loc list associated with a given declaration. */
6235 : :
6236 : : static inline var_loc_list *
6237 : 32086456 : lookup_decl_loc (const_tree decl)
6238 : : {
6239 : 32086456 : if (!decl_loc_table)
6240 : : return NULL;
6241 : 32086456 : return decl_loc_table->find_with_hash (decl, DECL_UID (decl));
6242 : : }
6243 : :
6244 : : /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
6245 : :
6246 : : inline hashval_t
6247 : 0 : dw_loc_list_hasher::hash (cached_dw_loc_list *x)
6248 : : {
6249 : 0 : return (hashval_t) x->decl_id;
6250 : : }
6251 : :
6252 : : /* Return true if decl_id of cached_dw_loc_list X is the same as
6253 : : UID of decl *Y. */
6254 : :
6255 : : inline bool
6256 : 0 : dw_loc_list_hasher::equal (cached_dw_loc_list *x, const_tree y)
6257 : : {
6258 : 0 : return (x->decl_id == DECL_UID (y));
6259 : : }
6260 : :
6261 : : /* Equate a DIE to a particular declaration. */
6262 : :
6263 : : static void
6264 : 156617146 : equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
6265 : : {
6266 : 156617146 : unsigned int decl_id = DECL_UID (decl);
6267 : :
6268 : 156617146 : *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
6269 : 156617146 : decl_die->decl_id = decl_id;
6270 : 156617146 : }
6271 : :
6272 : : /* Return how many bits covers PIECE EXPR_LIST. */
6273 : :
6274 : : static HOST_WIDE_INT
6275 : 33851739 : decl_piece_bitsize (rtx piece)
6276 : : {
6277 : 33851739 : int ret = (int) GET_MODE (piece);
6278 : 33851739 : if (ret)
6279 : 33835219 : return ret;
6280 : 16520 : gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
6281 : : && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
6282 : 16520 : return INTVAL (XEXP (XEXP (piece, 0), 0));
6283 : : }
6284 : :
6285 : : /* Return pointer to the location of location note in PIECE EXPR_LIST. */
6286 : :
6287 : : static rtx *
6288 : 17619098 : decl_piece_varloc_ptr (rtx piece)
6289 : : {
6290 : 0 : if ((int) GET_MODE (piece))
6291 : 17610146 : return &XEXP (piece, 0);
6292 : : else
6293 : 8952 : return &XEXP (XEXP (piece, 0), 1);
6294 : : }
6295 : :
6296 : : /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
6297 : : Next is the chain of following piece nodes. */
6298 : :
6299 : : static rtx_expr_list *
6300 : 8156855 : decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
6301 : : {
6302 : 8156855 : if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
6303 : 8151237 : return alloc_EXPR_LIST (bitsize, loc_note, next);
6304 : : else
6305 : 5618 : return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
6306 : : GEN_INT (bitsize),
6307 : 5618 : loc_note), next);
6308 : : }
6309 : :
6310 : : /* Return rtx that should be stored into loc field for
6311 : : LOC_NOTE and BITPOS/BITSIZE. */
6312 : :
6313 : : static rtx
6314 : 45155370 : construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
6315 : : HOST_WIDE_INT bitsize)
6316 : : {
6317 : 45155370 : if (bitsize != -1)
6318 : : {
6319 : 617455 : loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
6320 : 617455 : if (bitpos != 0)
6321 : 93490 : loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
6322 : : }
6323 : 45155370 : return loc_note;
6324 : : }
6325 : :
6326 : : /* This function either modifies location piece list *DEST in
6327 : : place (if SRC and INNER is NULL), or copies location piece list
6328 : : *SRC to *DEST while modifying it. Location BITPOS is modified
6329 : : to contain LOC_NOTE, any pieces overlapping it are removed resp.
6330 : : not copied and if needed some padding around it is added.
6331 : : When modifying in place, DEST should point to EXPR_LIST where
6332 : : earlier pieces cover PIECE_BITPOS bits, when copying SRC points
6333 : : to the start of the whole list and INNER points to the EXPR_LIST
6334 : : where earlier pieces cover PIECE_BITPOS bits. */
6335 : :
6336 : : static void
6337 : 6302396 : adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
6338 : : HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
6339 : : HOST_WIDE_INT bitsize, rtx loc_note)
6340 : : {
6341 : 6302396 : HOST_WIDE_INT diff;
6342 : 6302396 : bool copy = inner != NULL;
6343 : :
6344 : 6302396 : if (copy)
6345 : : {
6346 : : /* First copy all nodes preceding the current bitpos. */
6347 : 4584491 : while (src != inner)
6348 : : {
6349 : 2772046 : *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
6350 : : decl_piece_bitsize (*src), NULL_RTX);
6351 : 1386023 : dest = &XEXP (*dest, 1);
6352 : 1386023 : src = &XEXP (*src, 1);
6353 : : }
6354 : : }
6355 : : /* Add padding if needed. */
6356 : 6302396 : if (bitpos != piece_bitpos)
6357 : : {
6358 : 16319 : *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
6359 : : copy ? NULL_RTX : *dest);
6360 : 16319 : dest = &XEXP (*dest, 1);
6361 : : }
6362 : 6286077 : else if (*dest && decl_piece_bitsize (*dest) == bitsize)
6363 : : {
6364 : 2748998 : gcc_assert (!copy);
6365 : : /* A piece with correct bitpos and bitsize already exist,
6366 : : just update the location for it and return. */
6367 : 2748998 : *decl_piece_varloc_ptr (*dest) = loc_note;
6368 : 2748998 : return;
6369 : : }
6370 : : /* Add the piece that changed. */
6371 : 3553398 : *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
6372 : 3553398 : dest = &XEXP (*dest, 1);
6373 : : /* Skip over pieces that overlap it. */
6374 : 3553398 : diff = bitpos - piece_bitpos + bitsize;
6375 : 3553398 : if (!copy)
6376 : 354930 : src = dest;
6377 : 6732506 : while (diff > 0 && *src)
6378 : : {
6379 : 3179108 : rtx piece = *src;
6380 : 3179108 : diff -= decl_piece_bitsize (piece);
6381 : 3179108 : if (copy)
6382 : 3168594 : src = &XEXP (piece, 1);
6383 : : else
6384 : : {
6385 : 10514 : *src = XEXP (piece, 1);
6386 : 10514 : free_EXPR_LIST_node (piece);
6387 : : }
6388 : : }
6389 : : /* Add padding if needed. */
6390 : 3553398 : if (diff < 0 && *src)
6391 : : {
6392 : 7377 : if (!copy)
6393 : 6516 : dest = src;
6394 : 7377 : *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
6395 : 7377 : dest = &XEXP (*dest, 1);
6396 : : }
6397 : 3553398 : if (!copy)
6398 : : return;
6399 : : /* Finally copy all nodes following it. */
6400 : 5681261 : while (*src)
6401 : : {
6402 : 4965586 : *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
6403 : : decl_piece_bitsize (*src), NULL_RTX);
6404 : 2482793 : dest = &XEXP (*dest, 1);
6405 : 2482793 : src = &XEXP (*src, 1);
6406 : : }
6407 : : }
6408 : :
6409 : : /* Add a variable location node to the linked list for DECL. */
6410 : :
6411 : : static struct var_loc_node *
6412 : 56517706 : add_var_loc_to_decl (tree decl, rtx loc_note, const char *label, var_loc_view view)
6413 : : {
6414 : 56517706 : unsigned int decl_id;
6415 : 56517706 : var_loc_list *temp;
6416 : 56517706 : struct var_loc_node *loc = NULL;
6417 : 56517706 : HOST_WIDE_INT bitsize = -1, bitpos = -1;
6418 : :
6419 : 56517706 : if (VAR_P (decl) && DECL_HAS_DEBUG_EXPR_P (decl))
6420 : : {
6421 : 7838146 : tree realdecl = DECL_DEBUG_EXPR (decl);
6422 : 7838146 : if (handled_component_p (realdecl)
6423 : 816156 : || (TREE_CODE (realdecl) == MEM_REF
6424 : 816156 : && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
6425 : : {
6426 : 7838146 : bool reverse;
6427 : 7838146 : tree innerdecl = get_ref_base_and_extent_hwi (realdecl, &bitpos,
6428 : : &bitsize, &reverse);
6429 : 7838146 : if (!innerdecl
6430 : 7838146 : || !DECL_P (innerdecl)
6431 : 7838146 : || DECL_IGNORED_P (innerdecl)
6432 : 7838146 : || TREE_STATIC (innerdecl)
6433 : 7838146 : || bitsize == 0
6434 : 15676292 : || bitpos + bitsize > 256)
6435 : 0 : return NULL;
6436 : 7838146 : decl = innerdecl;
6437 : : }
6438 : : }
6439 : :
6440 : 56517706 : decl_id = DECL_UID (decl);
6441 : 56517706 : var_loc_list **slot
6442 : 56517706 : = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
6443 : 56517706 : if (*slot == NULL)
6444 : : {
6445 : 13226034 : temp = ggc_cleared_alloc<var_loc_list> ();
6446 : 13226034 : temp->decl_id = decl_id;
6447 : 13226034 : *slot = temp;
6448 : : }
6449 : : else
6450 : : temp = *slot;
6451 : :
6452 : : /* For PARM_DECLs try to keep around the original incoming value,
6453 : : even if that means we'll emit a zero-range .debug_loc entry. */
6454 : 56517706 : if (temp->last
6455 : 43291672 : && temp->first == temp->last
6456 : 20453000 : && TREE_CODE (decl) == PARM_DECL
6457 : 1035576 : && NOTE_P (temp->first->loc)
6458 : 997855 : && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
6459 : 997855 : && DECL_INCOMING_RTL (decl)
6460 : 997855 : && NOTE_VAR_LOCATION_LOC (temp->first->loc)
6461 : 997018 : && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
6462 : 997018 : == GET_CODE (DECL_INCOMING_RTL (decl))
6463 : 996964 : && prev_real_insn (as_a<rtx_insn *> (temp->first->loc)) == NULL_RTX
6464 : 57514662 : && (bitsize != -1
6465 : 996822 : || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
6466 : 996822 : NOTE_VAR_LOCATION_LOC (loc_note))
6467 : 411650 : || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
6468 : 411650 : != NOTE_VAR_LOCATION_STATUS (loc_note))))
6469 : : {
6470 : 585937 : loc = ggc_cleared_alloc<var_loc_node> ();
6471 : 585937 : temp->first->next = loc;
6472 : 585937 : temp->last = loc;
6473 : 585937 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6474 : : }
6475 : 55931769 : else if (temp->last)
6476 : : {
6477 : 42705735 : struct var_loc_node *last = temp->last, *unused = NULL;
6478 : 42705735 : rtx *piece_loc = NULL, last_loc_note;
6479 : 42705735 : HOST_WIDE_INT piece_bitpos = 0;
6480 : 42705735 : if (last->next)
6481 : : {
6482 : 27663149 : last = last->next;
6483 : 27663149 : gcc_assert (last->next == NULL);
6484 : : }
6485 : 42705735 : if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
6486 : : {
6487 : 7220691 : piece_loc = &last->loc;
6488 : 13046288 : do
6489 : : {
6490 : 13046288 : HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
6491 : 13046288 : if (piece_bitpos + cur_bitsize > bitpos)
6492 : : break;
6493 : 6200021 : piece_bitpos += cur_bitsize;
6494 : 6200021 : piece_loc = &XEXP (*piece_loc, 1);
6495 : : }
6496 : 6200021 : while (*piece_loc);
6497 : : }
6498 : : /* TEMP->LAST here is either pointer to the last but one or
6499 : : last element in the chained list, LAST is pointer to the
6500 : : last element. */
6501 : 42705735 : if (label && strcmp (last->label, label) == 0 && last->view == view)
6502 : : {
6503 : : /* For SRA optimized variables if there weren't any real
6504 : : insns since last note, just modify the last node. */
6505 : 4270542 : if (piece_loc != NULL)
6506 : : {
6507 : 3103928 : adjust_piece_list (piece_loc, NULL, NULL,
6508 : : bitpos, piece_bitpos, bitsize, loc_note);
6509 : 3103928 : return NULL;
6510 : : }
6511 : : /* If the last note doesn't cover any instructions, remove it. */
6512 : 1166614 : if (temp->last != last)
6513 : : {
6514 : 1057541 : temp->last->next = NULL;
6515 : 1057541 : unused = last;
6516 : 1057541 : last = temp->last;
6517 : 1057541 : gcc_assert (strcmp (last->label, label) != 0 || last->view != view);
6518 : : }
6519 : : else
6520 : : {
6521 : 109073 : gcc_assert (temp->first == temp->last
6522 : : || (temp->first->next == temp->last
6523 : : && TREE_CODE (decl) == PARM_DECL));
6524 : 109073 : memset (temp->last, '\0', sizeof (*temp->last));
6525 : 109073 : temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
6526 : 109073 : return temp->last;
6527 : : }
6528 : : }
6529 : 39492734 : if (bitsize == -1 && NOTE_P (last->loc))
6530 : : last_loc_note = last->loc;
6531 : 4362659 : else if (piece_loc != NULL
6532 : 4116763 : && *piece_loc != NULL_RTX
6533 : 4086801 : && piece_bitpos == bitpos
6534 : 8449120 : && decl_piece_bitsize (*piece_loc) == bitsize)
6535 : 4085551 : last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
6536 : : else
6537 : : last_loc_note = NULL_RTX;
6538 : : /* If the current location is the same as the end of the list,
6539 : : and either both or neither of the locations is uninitialized,
6540 : : we have nothing to do. */
6541 : 39215626 : if (last_loc_note == NULL_RTX
6542 : 39204837 : || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
6543 : 39204837 : NOTE_VAR_LOCATION_LOC (loc_note)))
6544 : 48077278 : || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6545 : 8861652 : != NOTE_VAR_LOCATION_STATUS (loc_note))
6546 : 3801760 : && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
6547 : : == VAR_INIT_STATUS_UNINITIALIZED)
6548 : 3006079 : || (NOTE_VAR_LOCATION_STATUS (loc_note)
6549 : : == VAR_INIT_STATUS_UNINITIALIZED))))
6550 : : {
6551 : : /* Add LOC to the end of list and update LAST. If the last
6552 : : element of the list has been removed above, reuse its
6553 : : memory for the new node, otherwise allocate a new one. */
6554 : 34432794 : if (unused)
6555 : : {
6556 : 714545 : loc = unused;
6557 : 714545 : memset (loc, '\0', sizeof (*loc));
6558 : : }
6559 : : else
6560 : 33718249 : loc = ggc_cleared_alloc<var_loc_node> ();
6561 : 34432794 : if (bitsize == -1 || piece_loc == NULL)
6562 : 31234326 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6563 : : else
6564 : 3198468 : adjust_piece_list (&loc->loc, &last->loc, piece_loc,
6565 : : bitpos, piece_bitpos, bitsize, loc_note);
6566 : 34432794 : last->next = loc;
6567 : : /* Ensure TEMP->LAST will point either to the new last but one
6568 : : element of the chain, or to the last element in it. */
6569 : 34432794 : if (last != temp->last)
6570 : 20878004 : temp->last = last;
6571 : : }
6572 : 5059940 : else if (unused)
6573 : 342996 : ggc_free (unused);
6574 : : }
6575 : : else
6576 : : {
6577 : 13226034 : loc = ggc_cleared_alloc<var_loc_node> ();
6578 : 13226034 : temp->first = loc;
6579 : 13226034 : temp->last = loc;
6580 : 13226034 : loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
6581 : : }
6582 : : return loc;
6583 : : }
6584 : :
6585 : : /* Keep track of the number of spaces used to indent the
6586 : : output of the debugging routines that print the structure of
6587 : : the DIE internal representation. */
6588 : : static int print_indent;
6589 : :
6590 : : /* Indent the line the number of spaces given by print_indent. */
6591 : :
6592 : : static inline void
6593 : 1812 : print_spaces (FILE *outfile)
6594 : : {
6595 : 1812 : fprintf (outfile, "%*s", print_indent, "");
6596 : 1812 : }
6597 : :
6598 : : /* Print a type signature in hex. */
6599 : :
6600 : : static inline void
6601 : 0 : print_signature (FILE *outfile, char *sig)
6602 : : {
6603 : 0 : int i;
6604 : :
6605 : 0 : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
6606 : 0 : fprintf (outfile, "%02x", sig[i] & 0xff);
6607 : 0 : }
6608 : :
6609 : : static inline void
6610 : 0 : print_discr_value (FILE *outfile, dw_discr_value *discr_value)
6611 : : {
6612 : 0 : if (discr_value->pos)
6613 : 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, discr_value->v.sval);
6614 : : else
6615 : 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, discr_value->v.uval);
6616 : 0 : }
6617 : :
6618 : : static void print_loc_descr (dw_loc_descr_ref, FILE *);
6619 : :
6620 : : /* Print the value associated to the VAL DWARF value node to OUTFILE. If
6621 : : RECURSE, output location descriptor operations. */
6622 : :
6623 : : static void
6624 : 1274 : print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
6625 : : {
6626 : 1274 : switch (val->val_class)
6627 : : {
6628 : 12 : case dw_val_class_addr:
6629 : 12 : fprintf (outfile, "address");
6630 : 12 : break;
6631 : 0 : case dw_val_class_offset:
6632 : 0 : fprintf (outfile, "offset");
6633 : 0 : break;
6634 : 30 : case dw_val_class_loc:
6635 : 30 : fprintf (outfile, "location descriptor");
6636 : 30 : if (val->v.val_loc == NULL)
6637 : 0 : fprintf (outfile, " -> <null>");
6638 : 30 : else if (recurse)
6639 : : {
6640 : 30 : fprintf (outfile, ":\n");
6641 : 30 : print_indent += 4;
6642 : 30 : print_loc_descr (val->v.val_loc, outfile);
6643 : 30 : print_indent -= 4;
6644 : : }
6645 : : else
6646 : : {
6647 : 0 : if (flag_dump_noaddr || flag_dump_unnumbered)
6648 : 0 : fprintf (outfile, " #");
6649 : : else
6650 : 0 : fprintf (outfile, " (%p)", (void *) val->v.val_loc);
6651 : : }
6652 : : break;
6653 : 34 : case dw_val_class_loc_list:
6654 : 34 : fprintf (outfile, "location list -> label:%s",
6655 : 34 : val->v.val_loc_list->ll_symbol);
6656 : 34 : break;
6657 : 34 : case dw_val_class_view_list:
6658 : 34 : val = view_list_to_loc_list_val_node (val);
6659 : 34 : fprintf (outfile, "location list with views -> labels:%s and %s",
6660 : : val->v.val_loc_list->ll_symbol,
6661 : 34 : val->v.val_loc_list->vl_symbol);
6662 : 34 : break;
6663 : 0 : case dw_val_class_range_list:
6664 : 0 : fprintf (outfile, "range list");
6665 : 0 : break;
6666 : 0 : case dw_val_class_const:
6667 : 0 : case dw_val_class_const_implicit:
6668 : 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
6669 : 0 : break;
6670 : 488 : case dw_val_class_unsigned_const:
6671 : 488 : case dw_val_class_unsigned_const_implicit:
6672 : 488 : fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
6673 : 488 : break;
6674 : 0 : case dw_val_class_const_double:
6675 : 0 : fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_DEC","\
6676 : : HOST_WIDE_INT_PRINT_UNSIGNED")",
6677 : : val->v.val_double.high,
6678 : : val->v.val_double.low);
6679 : 0 : break;
6680 : 0 : case dw_val_class_wide_int:
6681 : 0 : {
6682 : 0 : int i = val->v.val_wide->get_len ();
6683 : 0 : fprintf (outfile, "constant (");
6684 : 0 : gcc_assert (i > 0);
6685 : 0 : if (val->v.val_wide->elt (i - 1) == 0)
6686 : 0 : fprintf (outfile, "0x");
6687 : 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
6688 : 0 : val->v.val_wide->elt (--i));
6689 : 0 : while (--i >= 0)
6690 : 0 : fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
6691 : 0 : val->v.val_wide->elt (i));
6692 : 0 : fprintf (outfile, ")");
6693 : 0 : break;
6694 : : }
6695 : 0 : case dw_val_class_vec:
6696 : 0 : fprintf (outfile, "floating-point or vector constant");
6697 : 0 : break;
6698 : 88 : case dw_val_class_flag:
6699 : 88 : fprintf (outfile, "%u", val->v.val_flag);
6700 : 88 : break;
6701 : 224 : case dw_val_class_die_ref:
6702 : 224 : if (val->v.val_die_ref.die != NULL)
6703 : : {
6704 : 224 : dw_die_ref die = val->v.val_die_ref.die;
6705 : :
6706 : 224 : if (die->comdat_type_p)
6707 : : {
6708 : 0 : fprintf (outfile, "die -> signature: ");
6709 : 0 : print_signature (outfile,
6710 : 0 : die->die_id.die_type_node->signature);
6711 : : }
6712 : 224 : else if (die->die_id.die_symbol)
6713 : : {
6714 : 0 : fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
6715 : 0 : if (die->with_offset)
6716 : 0 : fprintf (outfile, " + %ld", die->die_offset);
6717 : : }
6718 : : else
6719 : 224 : fprintf (outfile, "die -> %ld", die->die_offset);
6720 : 224 : if (flag_dump_noaddr || flag_dump_unnumbered)
6721 : 224 : fprintf (outfile, " #");
6722 : : else
6723 : 0 : fprintf (outfile, " (%p)", (void *) die);
6724 : : }
6725 : : else
6726 : 0 : fprintf (outfile, "die -> <null>");
6727 : : break;
6728 : 0 : case dw_val_class_vms_delta:
6729 : 0 : fprintf (outfile, "delta: @slotcount(%s-%s)",
6730 : : val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
6731 : 0 : break;
6732 : 0 : case dw_val_class_symview:
6733 : 0 : fprintf (outfile, "view: %s", val->v.val_symbolic_view);
6734 : 0 : break;
6735 : 20 : case dw_val_class_lbl_id:
6736 : 20 : case dw_val_class_lineptr:
6737 : 20 : case dw_val_class_macptr:
6738 : 20 : case dw_val_class_loclistsptr:
6739 : 20 : case dw_val_class_high_pc:
6740 : 20 : fprintf (outfile, "label: %s", val->v.val_lbl_id);
6741 : 20 : break;
6742 : 192 : case dw_val_class_str:
6743 : 192 : if (val->v.val_str->str != NULL)
6744 : 192 : fprintf (outfile, "\"%s\"", val->v.val_str->str);
6745 : : else
6746 : 0 : fprintf (outfile, "<null>");
6747 : : break;
6748 : 152 : case dw_val_class_file:
6749 : 152 : case dw_val_class_file_implicit:
6750 : 152 : fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
6751 : 152 : val->v.val_file->emitted_number);
6752 : 152 : break;
6753 : : case dw_val_class_data8:
6754 : : {
6755 : : int i;
6756 : :
6757 : 0 : for (i = 0; i < 8; i++)
6758 : 0 : fprintf (outfile, "%02x", val->v.val_data8[i]);
6759 : : break;
6760 : : }
6761 : 0 : case dw_val_class_discr_value:
6762 : 0 : print_discr_value (outfile, &val->v.val_discr_value);
6763 : 0 : break;
6764 : 0 : case dw_val_class_discr_list:
6765 : 0 : for (dw_discr_list_ref node = val->v.val_discr_list;
6766 : 0 : node != NULL;
6767 : 0 : node = node->dw_discr_next)
6768 : : {
6769 : 0 : if (node->dw_discr_range)
6770 : : {
6771 : 0 : fprintf (outfile, " .. ");
6772 : 0 : print_discr_value (outfile, &node->dw_discr_lower_bound);
6773 : 0 : print_discr_value (outfile, &node->dw_discr_upper_bound);
6774 : : }
6775 : : else
6776 : 0 : print_discr_value (outfile, &node->dw_discr_lower_bound);
6777 : :
6778 : 0 : if (node->dw_discr_next != NULL)
6779 : 0 : fprintf (outfile, " | ");
6780 : : }
6781 : : default:
6782 : : break;
6783 : : }
6784 : 1274 : }
6785 : :
6786 : : /* Likewise, for a DIE attribute. */
6787 : :
6788 : : static void
6789 : 1214 : print_attribute (dw_attr_node *a, bool recurse, FILE *outfile)
6790 : : {
6791 : 0 : print_dw_val (&a->dw_attr_val, recurse, outfile);
6792 : 0 : }
6793 : :
6794 : :
6795 : : /* Print the list of operands in the LOC location description to OUTFILE. This
6796 : : routine is a debugging aid only. */
6797 : :
6798 : : static void
6799 : 30 : print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
6800 : : {
6801 : 30 : dw_loc_descr_ref l = loc;
6802 : :
6803 : 30 : if (loc == NULL)
6804 : : {
6805 : 0 : print_spaces (outfile);
6806 : 0 : fprintf (outfile, "<null>\n");
6807 : 0 : return;
6808 : : }
6809 : :
6810 : 60 : for (l = loc; l != NULL; l = l->dw_loc_next)
6811 : : {
6812 : 30 : print_spaces (outfile);
6813 : 30 : if (flag_dump_noaddr || flag_dump_unnumbered)
6814 : 30 : fprintf (outfile, "#");
6815 : : else
6816 : 0 : fprintf (outfile, "(%p)", (void *) l);
6817 : 30 : fprintf (outfile, " %s",
6818 : 30 : dwarf_stack_op_name (l->dw_loc_opc));
6819 : 30 : if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
6820 : : {
6821 : 30 : fprintf (outfile, " ");
6822 : 30 : print_dw_val (&l->dw_loc_oprnd1, false, outfile);
6823 : : }
6824 : 30 : if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
6825 : : {
6826 : 30 : fprintf (outfile, ", ");
6827 : 30 : print_dw_val (&l->dw_loc_oprnd2, false, outfile);
6828 : : }
6829 : 30 : fprintf (outfile, "\n");
6830 : : }
6831 : : }
6832 : :
6833 : : /* Print the information associated with a given DIE, and its children.
6834 : : This routine is a debugging aid only. */
6835 : :
6836 : : static void
6837 : 284 : print_die (dw_die_ref die, FILE *outfile)
6838 : : {
6839 : 284 : dw_attr_node *a;
6840 : 284 : dw_die_ref c;
6841 : 284 : unsigned ix;
6842 : :
6843 : 284 : print_spaces (outfile);
6844 : 284 : fprintf (outfile, "DIE %4ld: %s ",
6845 : 284 : die->die_offset, dwarf_tag_name (die->die_tag));
6846 : 284 : if (flag_dump_noaddr || flag_dump_unnumbered)
6847 : 284 : fprintf (outfile, "#\n");
6848 : : else
6849 : 0 : fprintf (outfile, "(%p)\n", (void*) die);
6850 : 284 : print_spaces (outfile);
6851 : 284 : fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
6852 : 284 : fprintf (outfile, " offset: %ld", die->die_offset);
6853 : 284 : fprintf (outfile, " mark: %d\n", die->die_mark);
6854 : :
6855 : 284 : if (die->comdat_type_p)
6856 : : {
6857 : 0 : print_spaces (outfile);
6858 : 0 : fprintf (outfile, " signature: ");
6859 : 0 : print_signature (outfile, die->die_id.die_type_node->signature);
6860 : 0 : fprintf (outfile, "\n");
6861 : : }
6862 : :
6863 : 1498 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6864 : : {
6865 : 1214 : print_spaces (outfile);
6866 : 1214 : fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
6867 : :
6868 : 1214 : print_attribute (a, true, outfile);
6869 : 1214 : fprintf (outfile, "\n");
6870 : : }
6871 : :
6872 : 284 : if (die->die_child != NULL)
6873 : : {
6874 : 52 : print_indent += 4;
6875 : 276 : FOR_EACH_CHILD (die, c, print_die (c, outfile));
6876 : 52 : print_indent -= 4;
6877 : : }
6878 : 284 : if (print_indent == 0)
6879 : 8 : fprintf (outfile, "\n");
6880 : 284 : }
6881 : :
6882 : : /* Print the list of operations in the LOC location description. */
6883 : :
6884 : : DEBUG_FUNCTION void
6885 : 0 : debug_dwarf_loc_descr (dw_loc_descr_ref loc)
6886 : : {
6887 : 0 : print_loc_descr (loc, stderr);
6888 : 0 : }
6889 : :
6890 : : /* Print the information collected for a given DIE. */
6891 : :
6892 : : DEBUG_FUNCTION void
6893 : 0 : debug_dwarf_die (dw_die_ref die)
6894 : : {
6895 : 0 : print_die (die, stderr);
6896 : 0 : }
6897 : :
6898 : : DEBUG_FUNCTION void
6899 : 0 : debug (die_struct &ref)
6900 : : {
6901 : 0 : print_die (&ref, stderr);
6902 : 0 : }
6903 : :
6904 : : DEBUG_FUNCTION void
6905 : 0 : debug (die_struct *ptr)
6906 : : {
6907 : 0 : if (ptr)
6908 : 0 : debug (*ptr);
6909 : : else
6910 : 0 : fprintf (stderr, "<nil>\n");
6911 : 0 : }
6912 : :
6913 : :
6914 : : /* Print all DWARF information collected for the compilation unit.
6915 : : This routine is a debugging aid only. */
6916 : :
6917 : : DEBUG_FUNCTION void
6918 : 0 : debug_dwarf (void)
6919 : : {
6920 : 0 : print_indent = 0;
6921 : 0 : print_die (comp_unit_die (), stderr);
6922 : 0 : }
6923 : :
6924 : : /* Verify the DIE tree structure. */
6925 : :
6926 : : DEBUG_FUNCTION void
6927 : 51973 : verify_die (dw_die_ref die)
6928 : : {
6929 : 51973 : gcc_assert (!die->die_mark);
6930 : 51973 : if (die->die_parent == NULL
6931 : 51973 : && die->die_sib == NULL)
6932 : : return;
6933 : : /* Verify the die_sib list is cyclic. */
6934 : : dw_die_ref x = die;
6935 : 0 : do
6936 : : {
6937 : 0 : x->die_mark = 1;
6938 : 0 : x = x->die_sib;
6939 : : }
6940 : 0 : while (x && !x->die_mark);
6941 : 0 : gcc_assert (x == die);
6942 : : x = die;
6943 : 0 : do
6944 : : {
6945 : : /* Verify all dies have the same parent. */
6946 : 0 : gcc_assert (x->die_parent == die->die_parent);
6947 : 0 : if (x->die_child)
6948 : : {
6949 : : /* Verify the child has the proper parent and recurse. */
6950 : 0 : gcc_assert (x->die_child->die_parent == x);
6951 : 0 : verify_die (x->die_child);
6952 : : }
6953 : 0 : x->die_mark = 0;
6954 : 0 : x = x->die_sib;
6955 : : }
6956 : 0 : while (x && x->die_mark);
6957 : : }
6958 : :
6959 : : /* Sanity checks on DIEs. */
6960 : :
6961 : : static void
6962 : 552269282 : check_die (dw_die_ref die)
6963 : : {
6964 : 552269282 : unsigned ix;
6965 : 552269282 : dw_attr_node *a;
6966 : 552269282 : bool inline_found = false;
6967 : 552269282 : int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0;
6968 : 552269282 : int n_decl_line = 0, n_decl_column = 0, n_decl_file = 0;
6969 : 2714682125 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
6970 : : {
6971 : 2162412843 : switch (a->dw_attr)
6972 : : {
6973 : 6331945 : case DW_AT_inline:
6974 : 6331945 : if (a->dw_attr_val.v.val_unsigned)
6975 : 2162412843 : inline_found = true;
6976 : : break;
6977 : 178 : case DW_AT_location:
6978 : 178 : ++n_location;
6979 : 178 : break;
6980 : 492259 : case DW_AT_low_pc:
6981 : 492259 : ++n_low_pc;
6982 : 492259 : break;
6983 : 492259 : case DW_AT_high_pc:
6984 : 492259 : ++n_high_pc;
6985 : 492259 : break;
6986 : 119452 : case DW_AT_artificial:
6987 : 119452 : ++n_artificial;
6988 : 119452 : break;
6989 : 316486539 : case DW_AT_decl_column:
6990 : 316486539 : ++n_decl_column;
6991 : 316486539 : break;
6992 : 317032762 : case DW_AT_decl_line:
6993 : 317032762 : ++n_decl_line;
6994 : 317032762 : break;
6995 : 316995916 : case DW_AT_decl_file:
6996 : 316995916 : ++n_decl_file;
6997 : 316995916 : break;
6998 : : default:
6999 : : break;
7000 : : }
7001 : : }
7002 : 552269282 : if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1
7003 : 552269282 : || n_decl_column > 1 || n_decl_line > 1 || n_decl_file > 1)
7004 : : {
7005 : 0 : fprintf (stderr, "Duplicate attributes in DIE:\n");
7006 : 0 : debug_dwarf_die (die);
7007 : 0 : gcc_unreachable ();
7008 : : }
7009 : 552269282 : if (inline_found)
7010 : : {
7011 : : /* A debugging information entry that is a member of an abstract
7012 : : instance tree [that has DW_AT_inline] should not contain any
7013 : : attributes which describe aspects of the subroutine which vary
7014 : : between distinct inlined expansions or distinct out-of-line
7015 : : expansions. */
7016 : 69499531 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7017 : 63170729 : gcc_assert (a->dw_attr != DW_AT_low_pc
7018 : : && a->dw_attr != DW_AT_high_pc
7019 : : && a->dw_attr != DW_AT_location
7020 : : && a->dw_attr != DW_AT_frame_base
7021 : : && a->dw_attr != DW_AT_call_all_calls
7022 : : && a->dw_attr != DW_AT_GNU_all_call_sites);
7023 : : }
7024 : 552269282 : }
7025 : :
7026 : : #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7027 : : #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7028 : : #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
7029 : :
7030 : : /* Calculate the checksum of a location expression. */
7031 : :
7032 : : static inline void
7033 : 607 : loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7034 : : {
7035 : 607 : int tem;
7036 : 607 : inchash::hash hstate;
7037 : 607 : hashval_t hash;
7038 : :
7039 : 607 : tem = (loc->dw_loc_dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
7040 : 607 : CHECKSUM (tem);
7041 : 607 : hash_loc_operands (loc, hstate);
7042 : 607 : hash = hstate.end();
7043 : 607 : CHECKSUM (hash);
7044 : 607 : }
7045 : :
7046 : : /* Calculate the checksum of an attribute. */
7047 : :
7048 : : static void
7049 : 891628 : attr_checksum (dw_attr_node *at, struct md5_ctx *ctx, int *mark)
7050 : : {
7051 : 891628 : dw_loc_descr_ref loc;
7052 : 891628 : rtx r;
7053 : :
7054 : 891628 : CHECKSUM (at->dw_attr);
7055 : :
7056 : : /* We don't care that this was compiled with a different compiler
7057 : : snapshot; if the output is the same, that's what matters. */
7058 : 891628 : if (at->dw_attr == DW_AT_producer)
7059 : : return;
7060 : :
7061 : 890056 : switch (AT_class (at))
7062 : : {
7063 : 17 : case dw_val_class_const:
7064 : 17 : case dw_val_class_const_implicit:
7065 : 17 : CHECKSUM (at->dw_attr_val.v.val_int);
7066 : 17 : break;
7067 : 248466 : case dw_val_class_unsigned_const:
7068 : 248466 : case dw_val_class_unsigned_const_implicit:
7069 : 248466 : CHECKSUM (at->dw_attr_val.v.val_unsigned);
7070 : 248466 : break;
7071 : 0 : case dw_val_class_const_double:
7072 : 0 : CHECKSUM (at->dw_attr_val.v.val_double);
7073 : 0 : break;
7074 : 0 : case dw_val_class_wide_int:
7075 : 0 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
7076 : : get_full_len (*at->dw_attr_val.v.val_wide)
7077 : : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
7078 : 0 : break;
7079 : 7 : case dw_val_class_vec:
7080 : 7 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
7081 : : (at->dw_attr_val.v.val_vec.length
7082 : : * at->dw_attr_val.v.val_vec.elt_size));
7083 : 7 : break;
7084 : 125100 : case dw_val_class_flag:
7085 : 125100 : CHECKSUM (at->dw_attr_val.v.val_flag);
7086 : 125100 : break;
7087 : 142771 : case dw_val_class_str:
7088 : 142771 : CHECKSUM_STRING (AT_string (at));
7089 : 142771 : break;
7090 : :
7091 : 0 : case dw_val_class_addr:
7092 : 0 : r = AT_addr (at);
7093 : 0 : gcc_assert (GET_CODE (r) == SYMBOL_REF);
7094 : 0 : CHECKSUM_STRING (XSTR (r, 0));
7095 : 0 : break;
7096 : :
7097 : 0 : case dw_val_class_offset:
7098 : 0 : CHECKSUM (at->dw_attr_val.v.val_offset);
7099 : 0 : break;
7100 : :
7101 : 487 : case dw_val_class_loc:
7102 : 1094 : for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7103 : 607 : loc_checksum (loc, ctx);
7104 : : break;
7105 : :
7106 : 284554 : case dw_val_class_die_ref:
7107 : 284554 : die_checksum (AT_ref (at), ctx, mark);
7108 : 284554 : break;
7109 : :
7110 : : case dw_val_class_fde_ref:
7111 : : case dw_val_class_vms_delta:
7112 : : case dw_val_class_symview:
7113 : : case dw_val_class_lbl_id:
7114 : : case dw_val_class_lineptr:
7115 : : case dw_val_class_macptr:
7116 : : case dw_val_class_loclistsptr:
7117 : : case dw_val_class_high_pc:
7118 : : break;
7119 : :
7120 : 86810 : case dw_val_class_file:
7121 : 86810 : case dw_val_class_file_implicit:
7122 : 86810 : CHECKSUM_STRING (AT_file (at)->filename);
7123 : 86810 : break;
7124 : :
7125 : 0 : case dw_val_class_data8:
7126 : 0 : CHECKSUM (at->dw_attr_val.v.val_data8);
7127 : 0 : break;
7128 : :
7129 : : default:
7130 : : break;
7131 : : }
7132 : : }
7133 : :
7134 : : /* Calculate the checksum of a DIE. */
7135 : :
7136 : : static void
7137 : 511471 : die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7138 : : {
7139 : 511471 : dw_die_ref c;
7140 : 511471 : dw_attr_node *a;
7141 : 511471 : unsigned ix;
7142 : :
7143 : : /* To avoid infinite recursion. */
7144 : 511471 : if (die->die_mark)
7145 : : {
7146 : 284544 : CHECKSUM (die->die_mark);
7147 : 284544 : return;
7148 : : }
7149 : 226927 : die->die_mark = ++(*mark);
7150 : :
7151 : 226927 : CHECKSUM (die->die_tag);
7152 : :
7153 : 1345482 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7154 : 891628 : attr_checksum (a, ctx, mark);
7155 : :
7156 : 393995 : FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
7157 : : }
7158 : :
7159 : : #undef CHECKSUM
7160 : : #undef CHECKSUM_BLOCK
7161 : : #undef CHECKSUM_STRING
7162 : :
7163 : : /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
7164 : : #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
7165 : : #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
7166 : : #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
7167 : : #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
7168 : : #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
7169 : : #define CHECKSUM_ATTR(FOO) \
7170 : : if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
7171 : :
7172 : : /* Calculate the checksum of a number in signed LEB128 format. */
7173 : :
7174 : : static void
7175 : 304 : checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
7176 : : {
7177 : 312 : unsigned char byte;
7178 : 312 : bool more;
7179 : :
7180 : 312 : while (1)
7181 : : {
7182 : 312 : byte = (value & 0x7f);
7183 : 312 : value >>= 7;
7184 : 312 : more = !((value == 0 && (byte & 0x40) == 0)
7185 : 0 : || (value == -1 && (byte & 0x40) != 0));
7186 : : if (more)
7187 : 8 : byte |= 0x80;
7188 : 312 : CHECKSUM (byte);
7189 : 312 : if (!more)
7190 : : break;
7191 : : }
7192 : 304 : }
7193 : :
7194 : : /* Calculate the checksum of a number in unsigned LEB128 format. */
7195 : :
7196 : : static void
7197 : 236055 : checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
7198 : : {
7199 : 244503 : while (1)
7200 : : {
7201 : 240279 : unsigned char byte = (value & 0x7f);
7202 : 240279 : value >>= 7;
7203 : 240279 : if (value != 0)
7204 : : /* More bytes to follow. */
7205 : 4224 : byte |= 0x80;
7206 : 240279 : CHECKSUM (byte);
7207 : 240279 : if (value == 0)
7208 : : break;
7209 : 4224 : }
7210 : 236055 : }
7211 : :
7212 : : /* Checksum the context of the DIE. This adds the names of any
7213 : : surrounding namespaces or structures to the checksum. */
7214 : :
7215 : : static void
7216 : 326 : checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
7217 : : {
7218 : 326 : const char *name;
7219 : 326 : dw_die_ref spec;
7220 : 326 : int tag = die->die_tag;
7221 : :
7222 : 326 : if (tag != DW_TAG_namespace
7223 : 326 : && tag != DW_TAG_structure_type
7224 : 245 : && tag != DW_TAG_class_type)
7225 : : return;
7226 : :
7227 : 87 : name = get_AT_string (die, DW_AT_name);
7228 : :
7229 : 87 : spec = get_AT_ref (die, DW_AT_specification);
7230 : 87 : if (spec != NULL)
7231 : 0 : die = spec;
7232 : :
7233 : 87 : if (die->die_parent != NULL)
7234 : 87 : checksum_die_context (die->die_parent, ctx);
7235 : :
7236 : 87 : CHECKSUM_ULEB128 ('C');
7237 : 87 : CHECKSUM_ULEB128 (tag);
7238 : 87 : if (name != NULL)
7239 : 72 : CHECKSUM_STRING (name);
7240 : : }
7241 : :
7242 : : /* Calculate the checksum of a location expression. */
7243 : :
7244 : : static inline void
7245 : 0 : loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
7246 : : {
7247 : : /* Special case for lone DW_OP_plus_uconst: checksum as if the location
7248 : : were emitted as a DW_FORM_sdata instead of a location expression. */
7249 : 0 : if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
7250 : : {
7251 : 0 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7252 : 0 : CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
7253 : 0 : return;
7254 : : }
7255 : :
7256 : : /* Otherwise, just checksum the raw location expression. */
7257 : 0 : while (loc != NULL)
7258 : : {
7259 : 0 : inchash::hash hstate;
7260 : 0 : hashval_t hash;
7261 : :
7262 : 0 : CHECKSUM_ULEB128 (loc->dw_loc_dtprel);
7263 : 0 : CHECKSUM_ULEB128 (loc->dw_loc_opc);
7264 : 0 : hash_loc_operands (loc, hstate);
7265 : 0 : hash = hstate.end ();
7266 : 0 : CHECKSUM (hash);
7267 : 0 : loc = loc->dw_loc_next;
7268 : : }
7269 : : }
7270 : :
7271 : : /* Calculate the checksum of an attribute. */
7272 : :
7273 : : static void
7274 : 637 : attr_checksum_ordered (enum dwarf_tag tag, dw_attr_node *at,
7275 : : struct md5_ctx *ctx, int *mark)
7276 : : {
7277 : 637 : dw_loc_descr_ref loc;
7278 : 637 : rtx r;
7279 : :
7280 : 637 : if (AT_class (at) == dw_val_class_die_ref)
7281 : : {
7282 : 109 : dw_die_ref target_die = AT_ref (at);
7283 : :
7284 : : /* For pointer and reference types, we checksum only the (qualified)
7285 : : name of the target type (if there is a name). For friend entries,
7286 : : we checksum only the (qualified) name of the target type or function.
7287 : : This allows the checksum to remain the same whether the target type
7288 : : is complete or not. */
7289 : 109 : if ((at->dw_attr == DW_AT_type
7290 : : && (tag == DW_TAG_pointer_type
7291 : 103 : || tag == DW_TAG_reference_type
7292 : 103 : || tag == DW_TAG_rvalue_reference_type
7293 : : || tag == DW_TAG_ptr_to_member_type))
7294 : 99 : || (at->dw_attr == DW_AT_friend
7295 : 0 : && tag == DW_TAG_friend))
7296 : : {
7297 : 10 : dw_attr_node *name_attr = get_AT (target_die, DW_AT_name);
7298 : :
7299 : 10 : if (name_attr != NULL)
7300 : : {
7301 : 0 : dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
7302 : :
7303 : 0 : if (decl == NULL)
7304 : 0 : decl = target_die;
7305 : 0 : CHECKSUM_ULEB128 ('N');
7306 : 0 : CHECKSUM_ULEB128 (at->dw_attr);
7307 : 0 : if (decl->die_parent != NULL)
7308 : 0 : checksum_die_context (decl->die_parent, ctx);
7309 : 0 : CHECKSUM_ULEB128 ('E');
7310 : 0 : CHECKSUM_STRING (AT_string (name_attr));
7311 : 0 : return;
7312 : : }
7313 : : }
7314 : :
7315 : : /* For all other references to another DIE, we check to see if the
7316 : : target DIE has already been visited. If it has, we emit a
7317 : : backward reference; if not, we descend recursively. */
7318 : 109 : if (target_die->die_mark > 0)
7319 : : {
7320 : 19 : CHECKSUM_ULEB128 ('R');
7321 : 19 : CHECKSUM_ULEB128 (at->dw_attr);
7322 : 19 : CHECKSUM_ULEB128 (target_die->die_mark);
7323 : : }
7324 : : else
7325 : : {
7326 : 90 : dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
7327 : :
7328 : 90 : if (decl == NULL)
7329 : 87 : decl = target_die;
7330 : 90 : target_die->die_mark = ++(*mark);
7331 : 90 : CHECKSUM_ULEB128 ('T');
7332 : 90 : CHECKSUM_ULEB128 (at->dw_attr);
7333 : 90 : if (decl->die_parent != NULL)
7334 : 90 : checksum_die_context (decl->die_parent, ctx);
7335 : 90 : die_checksum_ordered (target_die, ctx, mark);
7336 : : }
7337 : 109 : return;
7338 : : }
7339 : :
7340 : 528 : CHECKSUM_ULEB128 ('A');
7341 : 528 : CHECKSUM_ULEB128 (at->dw_attr);
7342 : :
7343 : 528 : switch (AT_class (at))
7344 : : {
7345 : 0 : case dw_val_class_const:
7346 : 0 : case dw_val_class_const_implicit:
7347 : 0 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7348 : 0 : CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
7349 : 0 : break;
7350 : :
7351 : 304 : case dw_val_class_unsigned_const:
7352 : 304 : case dw_val_class_unsigned_const_implicit:
7353 : 304 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7354 : 304 : CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
7355 : 304 : break;
7356 : :
7357 : 0 : case dw_val_class_const_double:
7358 : 0 : CHECKSUM_ULEB128 (DW_FORM_block);
7359 : 0 : CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
7360 : 0 : CHECKSUM (at->dw_attr_val.v.val_double);
7361 : 0 : break;
7362 : :
7363 : 0 : case dw_val_class_wide_int:
7364 : 0 : CHECKSUM_ULEB128 (DW_FORM_block);
7365 : 0 : CHECKSUM_ULEB128 (get_full_len (*at->dw_attr_val.v.val_wide)
7366 : : * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
7367 : 0 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
7368 : : get_full_len (*at->dw_attr_val.v.val_wide)
7369 : : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
7370 : 0 : break;
7371 : :
7372 : 0 : case dw_val_class_vec:
7373 : 0 : CHECKSUM_ULEB128 (DW_FORM_block);
7374 : 0 : CHECKSUM_ULEB128 (at->dw_attr_val.v.val_vec.length
7375 : : * at->dw_attr_val.v.val_vec.elt_size);
7376 : 0 : CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
7377 : : (at->dw_attr_val.v.val_vec.length
7378 : : * at->dw_attr_val.v.val_vec.elt_size));
7379 : 0 : break;
7380 : :
7381 : 3 : case dw_val_class_flag:
7382 : 3 : CHECKSUM_ULEB128 (DW_FORM_flag);
7383 : 3 : CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
7384 : 3 : break;
7385 : :
7386 : 221 : case dw_val_class_str:
7387 : 221 : CHECKSUM_ULEB128 (DW_FORM_string);
7388 : 221 : CHECKSUM_STRING (AT_string (at));
7389 : 221 : break;
7390 : :
7391 : 0 : case dw_val_class_addr:
7392 : 0 : r = AT_addr (at);
7393 : 0 : gcc_assert (GET_CODE (r) == SYMBOL_REF);
7394 : 0 : CHECKSUM_ULEB128 (DW_FORM_string);
7395 : 0 : CHECKSUM_STRING (XSTR (r, 0));
7396 : 0 : break;
7397 : :
7398 : 0 : case dw_val_class_offset:
7399 : 0 : CHECKSUM_ULEB128 (DW_FORM_sdata);
7400 : 0 : CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
7401 : 0 : break;
7402 : :
7403 : 0 : case dw_val_class_loc:
7404 : 0 : for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
7405 : 0 : loc_checksum_ordered (loc, ctx);
7406 : : break;
7407 : :
7408 : : case dw_val_class_fde_ref:
7409 : : case dw_val_class_symview:
7410 : : case dw_val_class_lbl_id:
7411 : : case dw_val_class_lineptr:
7412 : : case dw_val_class_macptr:
7413 : : case dw_val_class_loclistsptr:
7414 : : case dw_val_class_high_pc:
7415 : : break;
7416 : :
7417 : 0 : case dw_val_class_file:
7418 : 0 : case dw_val_class_file_implicit:
7419 : 0 : CHECKSUM_ULEB128 (DW_FORM_string);
7420 : 0 : CHECKSUM_STRING (AT_file (at)->filename);
7421 : 0 : break;
7422 : :
7423 : 0 : case dw_val_class_data8:
7424 : 0 : CHECKSUM (at->dw_attr_val.v.val_data8);
7425 : 0 : break;
7426 : :
7427 : : default:
7428 : : break;
7429 : : }
7430 : : }
7431 : :
7432 : : struct checksum_attributes
7433 : : {
7434 : : dw_attr_node *at_name;
7435 : : dw_attr_node *at_type;
7436 : : dw_attr_node *at_friend;
7437 : : dw_attr_node *at_accessibility;
7438 : : dw_attr_node *at_address_class;
7439 : : dw_attr_node *at_alignment;
7440 : : dw_attr_node *at_allocated;
7441 : : dw_attr_node *at_artificial;
7442 : : dw_attr_node *at_associated;
7443 : : dw_attr_node *at_binary_scale;
7444 : : dw_attr_node *at_bit_offset;
7445 : : dw_attr_node *at_bit_size;
7446 : : dw_attr_node *at_bit_stride;
7447 : : dw_attr_node *at_byte_size;
7448 : : dw_attr_node *at_byte_stride;
7449 : : dw_attr_node *at_const_value;
7450 : : dw_attr_node *at_containing_type;
7451 : : dw_attr_node *at_count;
7452 : : dw_attr_node *at_data_location;
7453 : : dw_attr_node *at_data_member_location;
7454 : : dw_attr_node *at_decimal_scale;
7455 : : dw_attr_node *at_decimal_sign;
7456 : : dw_attr_node *at_default_value;
7457 : : dw_attr_node *at_digit_count;
7458 : : dw_attr_node *at_discr;
7459 : : dw_attr_node *at_discr_list;
7460 : : dw_attr_node *at_discr_value;
7461 : : dw_attr_node *at_encoding;
7462 : : dw_attr_node *at_endianity;
7463 : : dw_attr_node *at_explicit;
7464 : : dw_attr_node *at_is_optional;
7465 : : dw_attr_node *at_location;
7466 : : dw_attr_node *at_lower_bound;
7467 : : dw_attr_node *at_mutable;
7468 : : dw_attr_node *at_ordering;
7469 : : dw_attr_node *at_picture_string;
7470 : : dw_attr_node *at_prototyped;
7471 : : dw_attr_node *at_small;
7472 : : dw_attr_node *at_segment;
7473 : : dw_attr_node *at_string_length;
7474 : : dw_attr_node *at_string_length_bit_size;
7475 : : dw_attr_node *at_string_length_byte_size;
7476 : : dw_attr_node *at_threads_scaled;
7477 : : dw_attr_node *at_upper_bound;
7478 : : dw_attr_node *at_use_location;
7479 : : dw_attr_node *at_use_UTF8;
7480 : : dw_attr_node *at_variable_parameter;
7481 : : dw_attr_node *at_virtuality;
7482 : : dw_attr_node *at_visibility;
7483 : : dw_attr_node *at_vtable_elem_location;
7484 : : };
7485 : :
7486 : : /* Collect the attributes that we will want to use for the checksum. */
7487 : :
7488 : : static void
7489 : 276 : collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
7490 : : {
7491 : 276 : dw_attr_node *a;
7492 : 276 : unsigned ix;
7493 : :
7494 : 1312 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
7495 : : {
7496 : 1036 : switch (a->dw_attr)
7497 : : {
7498 : 221 : case DW_AT_name:
7499 : 221 : attrs->at_name = a;
7500 : 221 : break;
7501 : 103 : case DW_AT_type:
7502 : 103 : attrs->at_type = a;
7503 : 103 : break;
7504 : 0 : case DW_AT_friend:
7505 : 0 : attrs->at_friend = a;
7506 : 0 : break;
7507 : 15 : case DW_AT_accessibility:
7508 : 15 : attrs->at_accessibility = a;
7509 : 15 : break;
7510 : 0 : case DW_AT_address_class:
7511 : 0 : attrs->at_address_class = a;
7512 : 0 : break;
7513 : 0 : case DW_AT_alignment:
7514 : 0 : attrs->at_alignment = a;
7515 : 0 : break;
7516 : 0 : case DW_AT_allocated:
7517 : 0 : attrs->at_allocated = a;
7518 : 0 : break;
7519 : 3 : case DW_AT_artificial:
7520 : 3 : attrs->at_artificial = a;
7521 : 3 : break;
7522 : 0 : case DW_AT_associated:
7523 : 0 : attrs->at_associated = a;
7524 : 0 : break;
7525 : 0 : case DW_AT_binary_scale:
7526 : 0 : attrs->at_binary_scale = a;
7527 : 0 : break;
7528 : 0 : case DW_AT_bit_offset:
7529 : 0 : attrs->at_bit_offset = a;
7530 : 0 : break;
7531 : 0 : case DW_AT_bit_size:
7532 : 0 : attrs->at_bit_size = a;
7533 : 0 : break;
7534 : 0 : case DW_AT_bit_stride:
7535 : 0 : attrs->at_bit_stride = a;
7536 : 0 : break;
7537 : 149 : case DW_AT_byte_size:
7538 : 149 : attrs->at_byte_size = a;
7539 : 149 : break;
7540 : 0 : case DW_AT_byte_stride:
7541 : 0 : attrs->at_byte_stride = a;
7542 : 0 : break;
7543 : 37 : case DW_AT_const_value:
7544 : 37 : attrs->at_const_value = a;
7545 : 37 : break;
7546 : 6 : case DW_AT_containing_type:
7547 : 6 : attrs->at_containing_type = a;
7548 : 6 : break;
7549 : 0 : case DW_AT_count:
7550 : 0 : attrs->at_count = a;
7551 : 0 : break;
7552 : 0 : case DW_AT_data_location:
7553 : 0 : attrs->at_data_location = a;
7554 : 0 : break;
7555 : 29 : case DW_AT_data_member_location:
7556 : 29 : attrs->at_data_member_location = a;
7557 : 29 : break;
7558 : 0 : case DW_AT_decimal_scale:
7559 : 0 : attrs->at_decimal_scale = a;
7560 : 0 : break;
7561 : 0 : case DW_AT_decimal_sign:
7562 : 0 : attrs->at_decimal_sign = a;
7563 : 0 : break;
7564 : 0 : case DW_AT_default_value:
7565 : 0 : attrs->at_default_value = a;
7566 : 0 : break;
7567 : 0 : case DW_AT_digit_count:
7568 : 0 : attrs->at_digit_count = a;
7569 : 0 : break;
7570 : 0 : case DW_AT_discr:
7571 : 0 : attrs->at_discr = a;
7572 : 0 : break;
7573 : 0 : case DW_AT_discr_list:
7574 : 0 : attrs->at_discr_list = a;
7575 : 0 : break;
7576 : 0 : case DW_AT_discr_value:
7577 : 0 : attrs->at_discr_value = a;
7578 : 0 : break;
7579 : 67 : case DW_AT_encoding:
7580 : 67 : attrs->at_encoding = a;
7581 : 67 : break;
7582 : 2 : case DW_AT_endianity:
7583 : 2 : attrs->at_endianity = a;
7584 : 2 : break;
7585 : 0 : case DW_AT_explicit:
7586 : 0 : attrs->at_explicit = a;
7587 : 0 : break;
7588 : 0 : case DW_AT_is_optional:
7589 : 0 : attrs->at_is_optional = a;
7590 : 0 : break;
7591 : 0 : case DW_AT_location:
7592 : 0 : attrs->at_location = a;
7593 : 0 : break;
7594 : 0 : case DW_AT_lower_bound:
7595 : 0 : attrs->at_lower_bound = a;
7596 : 0 : break;
7597 : 0 : case DW_AT_mutable:
7598 : 0 : attrs->at_mutable = a;
7599 : 0 : break;
7600 : 0 : case DW_AT_ordering:
7601 : 0 : attrs->at_ordering = a;
7602 : 0 : break;
7603 : 0 : case DW_AT_picture_string:
7604 : 0 : attrs->at_picture_string = a;
7605 : 0 : break;
7606 : 0 : case DW_AT_prototyped:
7607 : 0 : attrs->at_prototyped = a;
7608 : 0 : break;
7609 : 0 : case DW_AT_small:
7610 : 0 : attrs->at_small = a;
7611 : 0 : break;
7612 : 0 : case DW_AT_segment:
7613 : 0 : attrs->at_segment = a;
7614 : 0 : break;
7615 : 0 : case DW_AT_string_length:
7616 : 0 : attrs->at_string_length = a;
7617 : 0 : break;
7618 : 0 : case DW_AT_string_length_bit_size:
7619 : 0 : attrs->at_string_length_bit_size = a;
7620 : 0 : break;
7621 : 0 : case DW_AT_string_length_byte_size:
7622 : 0 : attrs->at_string_length_byte_size = a;
7623 : 0 : break;
7624 : 0 : case DW_AT_threads_scaled:
7625 : 0 : attrs->at_threads_scaled = a;
7626 : 0 : break;
7627 : 5 : case DW_AT_upper_bound:
7628 : 5 : attrs->at_upper_bound = a;
7629 : 5 : break;
7630 : 0 : case DW_AT_use_location:
7631 : 0 : attrs->at_use_location = a;
7632 : 0 : break;
7633 : 0 : case DW_AT_use_UTF8:
7634 : 0 : attrs->at_use_UTF8 = a;
7635 : 0 : break;
7636 : 0 : case DW_AT_variable_parameter:
7637 : 0 : attrs->at_variable_parameter = a;
7638 : 0 : break;
7639 : 0 : case DW_AT_virtuality:
7640 : 0 : attrs->at_virtuality = a;
7641 : 0 : break;
7642 : 0 : case DW_AT_visibility:
7643 : 0 : attrs->at_visibility = a;
7644 : 0 : break;
7645 : 0 : case DW_AT_vtable_elem_location:
7646 : 0 : attrs->at_vtable_elem_location = a;
7647 : 0 : break;
7648 : : default:
7649 : : break;
7650 : : }
7651 : : }
7652 : 276 : }
7653 : :
7654 : : /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
7655 : :
7656 : : static void
7657 : 273 : die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
7658 : : {
7659 : 273 : dw_die_ref c;
7660 : 273 : dw_die_ref decl;
7661 : 273 : struct checksum_attributes attrs;
7662 : :
7663 : 273 : CHECKSUM_ULEB128 ('D');
7664 : 273 : CHECKSUM_ULEB128 (die->die_tag);
7665 : :
7666 : 273 : memset (&attrs, 0, sizeof (attrs));
7667 : :
7668 : 273 : decl = get_AT_ref (die, DW_AT_specification);
7669 : 273 : if (decl != NULL)
7670 : 3 : collect_checksum_attributes (&attrs, decl);
7671 : 273 : collect_checksum_attributes (&attrs, die);
7672 : :
7673 : 273 : CHECKSUM_ATTR (attrs.at_name);
7674 : 273 : CHECKSUM_ATTR (attrs.at_accessibility);
7675 : 273 : CHECKSUM_ATTR (attrs.at_address_class);
7676 : 273 : CHECKSUM_ATTR (attrs.at_allocated);
7677 : 273 : CHECKSUM_ATTR (attrs.at_artificial);
7678 : 273 : CHECKSUM_ATTR (attrs.at_associated);
7679 : 273 : CHECKSUM_ATTR (attrs.at_binary_scale);
7680 : 273 : CHECKSUM_ATTR (attrs.at_bit_offset);
7681 : 273 : CHECKSUM_ATTR (attrs.at_bit_size);
7682 : 273 : CHECKSUM_ATTR (attrs.at_bit_stride);
7683 : 273 : CHECKSUM_ATTR (attrs.at_byte_size);
7684 : 273 : CHECKSUM_ATTR (attrs.at_byte_stride);
7685 : 273 : CHECKSUM_ATTR (attrs.at_const_value);
7686 : 273 : CHECKSUM_ATTR (attrs.at_containing_type);
7687 : 273 : CHECKSUM_ATTR (attrs.at_count);
7688 : 273 : CHECKSUM_ATTR (attrs.at_data_location);
7689 : 273 : CHECKSUM_ATTR (attrs.at_data_member_location);
7690 : 273 : CHECKSUM_ATTR (attrs.at_decimal_scale);
7691 : 273 : CHECKSUM_ATTR (attrs.at_decimal_sign);
7692 : 273 : CHECKSUM_ATTR (attrs.at_default_value);
7693 : 273 : CHECKSUM_ATTR (attrs.at_digit_count);
7694 : 273 : CHECKSUM_ATTR (attrs.at_discr);
7695 : 273 : CHECKSUM_ATTR (attrs.at_discr_list);
7696 : 273 : CHECKSUM_ATTR (attrs.at_discr_value);
7697 : 273 : CHECKSUM_ATTR (attrs.at_encoding);
7698 : 273 : CHECKSUM_ATTR (attrs.at_endianity);
7699 : 273 : CHECKSUM_ATTR (attrs.at_explicit);
7700 : 273 : CHECKSUM_ATTR (attrs.at_is_optional);
7701 : 273 : CHECKSUM_ATTR (attrs.at_location);
7702 : 273 : CHECKSUM_ATTR (attrs.at_lower_bound);
7703 : 273 : CHECKSUM_ATTR (attrs.at_mutable);
7704 : 273 : CHECKSUM_ATTR (attrs.at_ordering);
7705 : 273 : CHECKSUM_ATTR (attrs.at_picture_string);
7706 : 273 : CHECKSUM_ATTR (attrs.at_prototyped);
7707 : 273 : CHECKSUM_ATTR (attrs.at_small);
7708 : 273 : CHECKSUM_ATTR (attrs.at_segment);
7709 : 273 : CHECKSUM_ATTR (attrs.at_string_length);
7710 : 273 : CHECKSUM_ATTR (attrs.at_string_length_bit_size);
7711 : 273 : CHECKSUM_ATTR (attrs.at_string_length_byte_size);
7712 : 273 : CHECKSUM_ATTR (attrs.at_threads_scaled);
7713 : 273 : CHECKSUM_ATTR (attrs.at_upper_bound);
7714 : 273 : CHECKSUM_ATTR (attrs.at_use_location);
7715 : 273 : CHECKSUM_ATTR (attrs.at_use_UTF8);
7716 : 273 : CHECKSUM_ATTR (attrs.at_variable_parameter);
7717 : 273 : CHECKSUM_ATTR (attrs.at_virtuality);
7718 : 273 : CHECKSUM_ATTR (attrs.at_visibility);
7719 : 273 : CHECKSUM_ATTR (attrs.at_vtable_elem_location);
7720 : 273 : CHECKSUM_ATTR (attrs.at_type);
7721 : 273 : CHECKSUM_ATTR (attrs.at_friend);
7722 : 273 : CHECKSUM_ATTR (attrs.at_alignment);
7723 : :
7724 : : /* Checksum the child DIEs. */
7725 : 273 : c = die->die_child;
7726 : 273 : if (c) do {
7727 : 214 : dw_attr_node *name_attr;
7728 : :
7729 : 214 : c = c->die_sib;
7730 : 214 : name_attr = get_AT (c, DW_AT_name);
7731 : 214 : if (is_template_instantiation (c))
7732 : : {
7733 : : /* Ignore instantiations of member type and function templates. */
7734 : : }
7735 : 210 : else if (name_attr != NULL
7736 : 210 : && (is_type_die (c) || c->die_tag == DW_TAG_subprogram))
7737 : : {
7738 : : /* Use a shallow checksum for named nested types and member
7739 : : functions. */
7740 : 107 : CHECKSUM_ULEB128 ('S');
7741 : 107 : CHECKSUM_ULEB128 (c->die_tag);
7742 : 107 : CHECKSUM_STRING (AT_string (name_attr));
7743 : : }
7744 : : else
7745 : : {
7746 : : /* Use a deep checksum for other children. */
7747 : : /* Mark this DIE so it gets processed when unmarking. */
7748 : 103 : if (c->die_mark == 0)
7749 : 103 : c->die_mark = -1;
7750 : 103 : die_checksum_ordered (c, ctx, mark);
7751 : : }
7752 : 214 : } while (c != die->die_child);
7753 : :
7754 : 273 : CHECKSUM_ULEB128 (0);
7755 : 273 : }
7756 : :
7757 : : /* Add a type name and tag to a hash. */
7758 : : static void
7759 : 69 : die_odr_checksum (int tag, const char *name, md5_ctx *ctx)
7760 : : {
7761 : 69 : CHECKSUM_ULEB128 (tag);
7762 : 69 : CHECKSUM_STRING (name);
7763 : 69 : }
7764 : :
7765 : : #undef CHECKSUM
7766 : : #undef CHECKSUM_STRING
7767 : : #undef CHECKSUM_ATTR
7768 : : #undef CHECKSUM_LEB128
7769 : : #undef CHECKSUM_ULEB128
7770 : :
7771 : : /* Generate the type signature for DIE. This is computed by generating an
7772 : : MD5 checksum over the DIE's tag, its relevant attributes, and its
7773 : : children. Attributes that are references to other DIEs are processed
7774 : : by recursion, using the MARK field to prevent infinite recursion.
7775 : : If the DIE is nested inside a namespace or another type, we also
7776 : : need to include that context in the signature. The lower 64 bits
7777 : : of the resulting MD5 checksum comprise the signature. */
7778 : :
7779 : : static void
7780 : 80 : generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
7781 : : {
7782 : 80 : int mark;
7783 : 80 : const char *name;
7784 : 80 : unsigned char checksum[16];
7785 : 80 : struct md5_ctx ctx;
7786 : 80 : dw_die_ref decl;
7787 : 80 : dw_die_ref parent;
7788 : :
7789 : 80 : name = get_AT_string (die, DW_AT_name);
7790 : 80 : decl = get_AT_ref (die, DW_AT_specification);
7791 : 80 : parent = dw_get_die_parent (die);
7792 : :
7793 : : /* First, compute a signature for just the type name (and its surrounding
7794 : : context, if any. This is stored in the type unit DIE for link-time
7795 : : ODR (one-definition rule) checking. */
7796 : :
7797 : 80 : if (is_cxx () && name != NULL)
7798 : : {
7799 : 69 : md5_init_ctx (&ctx);
7800 : :
7801 : : /* Checksum the names of surrounding namespaces and structures. */
7802 : 69 : if (parent != NULL)
7803 : 69 : checksum_die_context (parent, &ctx);
7804 : :
7805 : : /* Checksum the current DIE. */
7806 : 69 : die_odr_checksum (die->die_tag, name, &ctx);
7807 : 69 : md5_finish_ctx (&ctx, checksum);
7808 : :
7809 : 69 : add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
7810 : : }
7811 : :
7812 : : /* Next, compute the complete type signature. */
7813 : :
7814 : 80 : md5_init_ctx (&ctx);
7815 : 80 : mark = 1;
7816 : 80 : die->die_mark = mark;
7817 : :
7818 : : /* Checksum the names of surrounding namespaces and structures. */
7819 : 80 : if (parent != NULL)
7820 : 80 : checksum_die_context (parent, &ctx);
7821 : :
7822 : : /* Checksum the DIE and its children. */
7823 : 80 : die_checksum_ordered (die, &ctx, &mark);
7824 : 80 : unmark_all_dies (die);
7825 : 80 : md5_finish_ctx (&ctx, checksum);
7826 : :
7827 : : /* Store the signature in the type node and link the type DIE and the
7828 : : type node together. */
7829 : 80 : memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
7830 : : DWARF_TYPE_SIGNATURE_SIZE);
7831 : 80 : die->comdat_type_p = true;
7832 : 80 : die->die_id.die_type_node = type_node;
7833 : 80 : type_node->type_die = die;
7834 : :
7835 : : /* If the DIE is a specification, link its declaration to the type node
7836 : : as well. */
7837 : 80 : if (decl != NULL)
7838 : : {
7839 : 0 : decl->comdat_type_p = true;
7840 : 0 : decl->die_id.die_type_node = type_node;
7841 : : }
7842 : 80 : }
7843 : :
7844 : : /* Do the location expressions look same? */
7845 : : static inline bool
7846 : 0 : same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
7847 : : {
7848 : 0 : return loc1->dw_loc_opc == loc2->dw_loc_opc
7849 : 0 : && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
7850 : 0 : && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
7851 : : }
7852 : :
7853 : : /* Do the values look the same? */
7854 : : static bool
7855 : 0 : same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
7856 : : {
7857 : 0 : dw_loc_descr_ref loc1, loc2;
7858 : 0 : rtx r1, r2;
7859 : :
7860 : 0 : if (v1->val_class != v2->val_class)
7861 : : return false;
7862 : :
7863 : 0 : switch (v1->val_class)
7864 : : {
7865 : 0 : case dw_val_class_const:
7866 : 0 : case dw_val_class_const_implicit:
7867 : 0 : return v1->v.val_int == v2->v.val_int;
7868 : 0 : case dw_val_class_unsigned_const:
7869 : 0 : case dw_val_class_unsigned_const_implicit:
7870 : 0 : return v1->v.val_unsigned == v2->v.val_unsigned;
7871 : 0 : case dw_val_class_const_double:
7872 : 0 : return v1->v.val_double.high == v2->v.val_double.high
7873 : 0 : && v1->v.val_double.low == v2->v.val_double.low;
7874 : 0 : case dw_val_class_wide_int:
7875 : 0 : return *v1->v.val_wide == *v2->v.val_wide;
7876 : 0 : case dw_val_class_vec:
7877 : 0 : if (v1->v.val_vec.length != v2->v.val_vec.length
7878 : 0 : || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
7879 : : return false;
7880 : 0 : if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
7881 : 0 : v1->v.val_vec.length * v1->v.val_vec.elt_size))
7882 : : return false;
7883 : : return true;
7884 : 0 : case dw_val_class_flag:
7885 : 0 : return v1->v.val_flag == v2->v.val_flag;
7886 : 0 : case dw_val_class_str:
7887 : 0 : return !strcmp (v1->v.val_str->str, v2->v.val_str->str);
7888 : :
7889 : 0 : case dw_val_class_addr:
7890 : 0 : r1 = v1->v.val_addr;
7891 : 0 : r2 = v2->v.val_addr;
7892 : 0 : if (GET_CODE (r1) != GET_CODE (r2))
7893 : : return false;
7894 : 0 : return !rtx_equal_p (r1, r2);
7895 : :
7896 : 0 : case dw_val_class_offset:
7897 : 0 : return v1->v.val_offset == v2->v.val_offset;
7898 : :
7899 : 0 : case dw_val_class_loc:
7900 : 0 : for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
7901 : 0 : loc1 && loc2;
7902 : 0 : loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
7903 : 0 : if (!same_loc_p (loc1, loc2, mark))
7904 : : return false;
7905 : 0 : return !loc1 && !loc2;
7906 : :
7907 : 0 : case dw_val_class_die_ref:
7908 : 0 : return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
7909 : :
7910 : 0 : case dw_val_class_symview:
7911 : 0 : return strcmp (v1->v.val_symbolic_view, v2->v.val_symbolic_view) == 0;
7912 : :
7913 : : case dw_val_class_fde_ref:
7914 : : case dw_val_class_vms_delta:
7915 : : case dw_val_class_lbl_id:
7916 : : case dw_val_class_lineptr:
7917 : : case dw_val_class_macptr:
7918 : : case dw_val_class_loclistsptr:
7919 : : case dw_val_class_high_pc:
7920 : : return true;
7921 : :
7922 : 0 : case dw_val_class_file:
7923 : 0 : case dw_val_class_file_implicit:
7924 : 0 : return v1->v.val_file == v2->v.val_file;
7925 : :
7926 : 0 : case dw_val_class_data8:
7927 : 0 : return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
7928 : :
7929 : : default:
7930 : : return true;
7931 : : }
7932 : : }
7933 : :
7934 : : /* Do the attributes look the same? */
7935 : :
7936 : : static bool
7937 : 0 : same_attr_p (dw_attr_node *at1, dw_attr_node *at2, int *mark)
7938 : : {
7939 : 0 : if (at1->dw_attr != at2->dw_attr)
7940 : : return false;
7941 : :
7942 : : /* We don't care that this was compiled with a different compiler
7943 : : snapshot; if the output is the same, that's what matters. */
7944 : 0 : if (at1->dw_attr == DW_AT_producer)
7945 : : return true;
7946 : :
7947 : 0 : return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
7948 : : }
7949 : :
7950 : : /* Do the dies look the same? */
7951 : :
7952 : : static bool
7953 : 0 : same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
7954 : : {
7955 : 0 : dw_die_ref c1, c2;
7956 : 0 : dw_attr_node *a1;
7957 : 0 : unsigned ix;
7958 : :
7959 : : /* To avoid infinite recursion. */
7960 : 0 : if (die1->die_mark)
7961 : 0 : return die1->die_mark == die2->die_mark;
7962 : 0 : die1->die_mark = die2->die_mark = ++(*mark);
7963 : :
7964 : 0 : if (die1->die_tag != die2->die_tag)
7965 : : return false;
7966 : :
7967 : 0 : if (vec_safe_length (die1->die_attr) != vec_safe_length (die2->die_attr))
7968 : : return false;
7969 : :
7970 : 0 : FOR_EACH_VEC_SAFE_ELT (die1->die_attr, ix, a1)
7971 : 0 : if (!same_attr_p (a1, &(*die2->die_attr)[ix], mark))
7972 : : return false;
7973 : :
7974 : 0 : c1 = die1->die_child;
7975 : 0 : c2 = die2->die_child;
7976 : 0 : if (! c1)
7977 : : {
7978 : 0 : if (c2)
7979 : : return false;
7980 : : }
7981 : : else
7982 : 0 : for (;;)
7983 : : {
7984 : 0 : if (!same_die_p (c1, c2, mark))
7985 : : return false;
7986 : 0 : c1 = c1->die_sib;
7987 : 0 : c2 = c2->die_sib;
7988 : 0 : if (c1 == die1->die_child)
7989 : : {
7990 : 0 : if (c2 == die2->die_child)
7991 : : break;
7992 : : else
7993 : : return false;
7994 : : }
7995 : : }
7996 : :
7997 : : return true;
7998 : : }
7999 : :
8000 : : /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
8001 : : children, and set die_symbol. */
8002 : :
8003 : : static void
8004 : 1323 : compute_comp_unit_symbol (dw_die_ref unit_die)
8005 : : {
8006 : 1323 : const char *die_name = get_AT_string (unit_die, DW_AT_name);
8007 : 1323 : const char *base = die_name ? lbasename (die_name) : "anonymous";
8008 : 1323 : char *name = XALLOCAVEC (char, strlen (base) + 64);
8009 : 1323 : char *p;
8010 : 1323 : int i, mark;
8011 : 1323 : unsigned char checksum[16];
8012 : 1323 : struct md5_ctx ctx;
8013 : :
8014 : : /* Compute the checksum of the DIE, then append part of it as hex digits to
8015 : : the name filename of the unit. */
8016 : :
8017 : 1323 : md5_init_ctx (&ctx);
8018 : 1323 : mark = 0;
8019 : 1323 : die_checksum (unit_die, &ctx, &mark);
8020 : 1323 : unmark_all_dies (unit_die);
8021 : 1323 : md5_finish_ctx (&ctx, checksum);
8022 : :
8023 : : /* When we this for comp_unit_die () we have a DW_AT_name that might
8024 : : not start with a letter but with anything valid for filenames and
8025 : : clean_symbol_name doesn't fix that up. Prepend 'g' if the first
8026 : : character is not a letter. */
8027 : 1323 : sprintf (name, "%s%s.", ISALPHA (*base) ? "" : "g", base);
8028 : 1323 : clean_symbol_name (name);
8029 : :
8030 : 1323 : p = name + strlen (name);
8031 : 6615 : for (i = 0; i < 4; i++)
8032 : : {
8033 : 5292 : sprintf (p, "%.2x", checksum[i]);
8034 : 5292 : p += 2;
8035 : : }
8036 : :
8037 : 1323 : unit_die->die_id.die_symbol = xstrdup (name);
8038 : 1323 : }
8039 : :
8040 : : /* Returns true if DIE represents a type, in the sense of TYPE_P. */
8041 : :
8042 : : static bool
8043 : 80889195 : is_type_die (dw_die_ref die)
8044 : : {
8045 : 80889195 : switch (die->die_tag)
8046 : : {
8047 : : case DW_TAG_array_type:
8048 : : case DW_TAG_class_type:
8049 : : case DW_TAG_interface_type:
8050 : : case DW_TAG_enumeration_type:
8051 : : case DW_TAG_pointer_type:
8052 : : case DW_TAG_reference_type:
8053 : : case DW_TAG_rvalue_reference_type:
8054 : : case DW_TAG_string_type:
8055 : : case DW_TAG_structure_type:
8056 : : case DW_TAG_subroutine_type:
8057 : : case DW_TAG_union_type:
8058 : : case DW_TAG_ptr_to_member_type:
8059 : : case DW_TAG_set_type:
8060 : : case DW_TAG_subrange_type:
8061 : : case DW_TAG_base_type:
8062 : : case DW_TAG_const_type:
8063 : : case DW_TAG_file_type:
8064 : : case DW_TAG_packed_type:
8065 : : case DW_TAG_volatile_type:
8066 : : case DW_TAG_typedef:
8067 : : return true;
8068 : 72686961 : default:
8069 : 72686961 : return false;
8070 : : }
8071 : : }
8072 : :
8073 : : /* Returns true iff C is a compile-unit DIE. */
8074 : :
8075 : : static inline bool
8076 : 32650754 : is_cu_die (dw_die_ref c)
8077 : : {
8078 : 32477498 : return c && (c->die_tag == DW_TAG_compile_unit
8079 : 32597468 : || c->die_tag == DW_TAG_skeleton_unit);
8080 : : }
8081 : :
8082 : : /* Returns true iff C is a unit DIE of some sort. */
8083 : :
8084 : : static inline bool
8085 : 1864440 : is_unit_die (dw_die_ref c)
8086 : : {
8087 : 1864440 : return c && (c->die_tag == DW_TAG_compile_unit
8088 : : || c->die_tag == DW_TAG_partial_unit
8089 : : || c->die_tag == DW_TAG_type_unit
8090 : 1864440 : || c->die_tag == DW_TAG_skeleton_unit);
8091 : : }
8092 : :
8093 : : /* Returns true iff C is a namespace DIE. */
8094 : :
8095 : : static inline bool
8096 : 165 : is_namespace_die (dw_die_ref c)
8097 : : {
8098 : 165 : return c && c->die_tag == DW_TAG_namespace;
8099 : : }
8100 : :
8101 : : /* Return true if this DIE is a template parameter. */
8102 : :
8103 : : static inline bool
8104 : 18853662 : is_template_parameter (dw_die_ref die)
8105 : : {
8106 : 18853662 : switch (die->die_tag)
8107 : : {
8108 : : case DW_TAG_template_type_param:
8109 : : case DW_TAG_template_value_param:
8110 : : case DW_TAG_GNU_template_template_param:
8111 : : case DW_TAG_GNU_template_parameter_pack:
8112 : : return true;
8113 : 216 : default:
8114 : 216 : return false;
8115 : : }
8116 : : }
8117 : :
8118 : : /* Return true if this DIE represents a template instantiation. */
8119 : :
8120 : : static inline bool
8121 : 318 : is_template_instantiation (dw_die_ref die)
8122 : : {
8123 : 318 : dw_die_ref c;
8124 : :
8125 : 318 : if (!is_type_die (die) && die->die_tag != DW_TAG_subprogram)
8126 : : return false;
8127 : 263 : FOR_EACH_CHILD (die, c, if (is_template_parameter (c)) return true);
8128 : : return false;
8129 : : }
8130 : :
8131 : : static char *
8132 : 26113120 : gen_internal_sym (const char *prefix)
8133 : : {
8134 : 26113120 : char buf[MAX_ARTIFICIAL_LABEL_BYTES];
8135 : :
8136 : 26113120 : ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
8137 : 26113120 : return xstrdup (buf);
8138 : : }
8139 : :
8140 : : /* Return true if this DIE is a declaration. */
8141 : :
8142 : : static bool
8143 : 16319318 : is_declaration_die (dw_die_ref die)
8144 : : {
8145 : 16319318 : dw_attr_node *a;
8146 : 16319318 : unsigned ix;
8147 : :
8148 : 114250463 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8149 : 113529304 : if (a->dw_attr == DW_AT_declaration)
8150 : : return true;
8151 : :
8152 : : return false;
8153 : : }
8154 : :
8155 : : /* Return true if this DIE is nested inside a subprogram. */
8156 : :
8157 : : static bool
8158 : 81 : is_nested_in_subprogram (dw_die_ref die)
8159 : : {
8160 : 81 : dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
8161 : :
8162 : 81 : if (decl == NULL)
8163 : 81 : decl = die;
8164 : 81 : return local_scope_p (decl);
8165 : : }
8166 : :
8167 : : /* Return true if this DIE contains a defining declaration of a
8168 : : subprogram. */
8169 : :
8170 : : static bool
8171 : 389 : contains_subprogram_definition (dw_die_ref die)
8172 : : {
8173 : 389 : dw_die_ref c;
8174 : :
8175 : 389 : if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
8176 : : return true;
8177 : 532 : FOR_EACH_CHILD (die, c, if (contains_subprogram_definition (c)) return 1);
8178 : : return false;
8179 : : }
8180 : :
8181 : : /* Return true if this is a type DIE that should be moved to a
8182 : : COMDAT .debug_types section or .debug_info section with DW_UT_*type
8183 : : unit type. */
8184 : :
8185 : : static bool
8186 : 755 : should_move_die_to_comdat (dw_die_ref die)
8187 : : {
8188 : 755 : switch (die->die_tag)
8189 : : {
8190 : 86 : case DW_TAG_class_type:
8191 : 86 : case DW_TAG_structure_type:
8192 : 86 : case DW_TAG_enumeration_type:
8193 : 86 : case DW_TAG_union_type:
8194 : : /* Don't move declarations, inlined instances, types nested in a
8195 : : subprogram, or types that contain subprogram definitions. */
8196 : 86 : if (is_declaration_die (die)
8197 : 81 : || get_AT (die, DW_AT_abstract_origin)
8198 : 81 : || is_nested_in_subprogram (die)
8199 : 167 : || contains_subprogram_definition (die))
8200 : 5 : return false;
8201 : 81 : if (die->die_tag != DW_TAG_enumeration_type)
8202 : : {
8203 : : /* Don't move non-constant size aggregates. */
8204 : 67 : dw_attr_node *sz = get_AT (die, DW_AT_byte_size);
8205 : 67 : if (sz == NULL
8206 : 67 : || (AT_class (sz) != dw_val_class_unsigned_const
8207 : 0 : && AT_class (sz) != dw_val_class_unsigned_const_implicit))
8208 : 1 : return false;
8209 : : }
8210 : : return true;
8211 : : case DW_TAG_array_type:
8212 : : case DW_TAG_interface_type:
8213 : : case DW_TAG_pointer_type:
8214 : : case DW_TAG_reference_type:
8215 : : case DW_TAG_rvalue_reference_type:
8216 : : case DW_TAG_string_type:
8217 : : case DW_TAG_subroutine_type:
8218 : : case DW_TAG_ptr_to_member_type:
8219 : : case DW_TAG_set_type:
8220 : : case DW_TAG_subrange_type:
8221 : : case DW_TAG_base_type:
8222 : : case DW_TAG_const_type:
8223 : : case DW_TAG_file_type:
8224 : : case DW_TAG_packed_type:
8225 : : case DW_TAG_volatile_type:
8226 : : case DW_TAG_typedef:
8227 : : default:
8228 : : return false;
8229 : : }
8230 : : }
8231 : :
8232 : : /* Make a clone of DIE. */
8233 : :
8234 : : static dw_die_ref
8235 : 270 : clone_die (dw_die_ref die)
8236 : : {
8237 : 270 : dw_die_ref clone = new_die_raw (die->die_tag);
8238 : 270 : dw_attr_node *a;
8239 : 270 : unsigned ix;
8240 : :
8241 : 1632 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8242 : 1092 : add_dwarf_attr (clone, a);
8243 : :
8244 : 270 : return clone;
8245 : : }
8246 : :
8247 : : /* Make a clone of the tree rooted at DIE. */
8248 : :
8249 : : static dw_die_ref
8250 : 0 : clone_tree (dw_die_ref die)
8251 : : {
8252 : 0 : dw_die_ref c;
8253 : 0 : dw_die_ref clone = clone_die (die);
8254 : :
8255 : 0 : FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree (c)));
8256 : :
8257 : 0 : return clone;
8258 : : }
8259 : :
8260 : : /* Make a clone of DIE as a declaration. */
8261 : :
8262 : : static dw_die_ref
8263 : 147 : clone_as_declaration (dw_die_ref die)
8264 : : {
8265 : 147 : dw_die_ref clone;
8266 : 147 : dw_die_ref decl;
8267 : 147 : dw_attr_node *a;
8268 : 147 : unsigned ix;
8269 : :
8270 : : /* If the DIE is already a declaration, just clone it. */
8271 : 147 : if (is_declaration_die (die))
8272 : 0 : return clone_die (die);
8273 : :
8274 : : /* If the DIE is a specification, just clone its declaration DIE. */
8275 : 147 : decl = get_AT_ref (die, DW_AT_specification);
8276 : 147 : if (decl != NULL)
8277 : : {
8278 : 30 : clone = clone_die (decl);
8279 : 30 : if (die->comdat_type_p)
8280 : 30 : add_AT_die_ref (clone, DW_AT_signature, die);
8281 : 30 : return clone;
8282 : : }
8283 : :
8284 : 117 : clone = new_die_raw (die->die_tag);
8285 : :
8286 : 759 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8287 : : {
8288 : : /* We don't want to copy over all attributes.
8289 : : For example we don't want DW_AT_byte_size because otherwise we will no
8290 : : longer have a declaration and GDB will treat it as a definition. */
8291 : :
8292 : 525 : switch (a->dw_attr)
8293 : : {
8294 : 111 : case DW_AT_abstract_origin:
8295 : 111 : case DW_AT_artificial:
8296 : 111 : case DW_AT_containing_type:
8297 : 111 : case DW_AT_external:
8298 : 111 : case DW_AT_name:
8299 : 111 : case DW_AT_type:
8300 : 111 : case DW_AT_virtuality:
8301 : 111 : case DW_AT_linkage_name:
8302 : 111 : case DW_AT_MIPS_linkage_name:
8303 : 111 : add_dwarf_attr (clone, a);
8304 : 111 : break;
8305 : : case DW_AT_byte_size:
8306 : : case DW_AT_alignment:
8307 : : default:
8308 : : break;
8309 : : }
8310 : : }
8311 : :
8312 : 117 : if (die->comdat_type_p)
8313 : 66 : add_AT_die_ref (clone, DW_AT_signature, die);
8314 : :
8315 : 117 : add_AT_flag (clone, DW_AT_declaration, 1);
8316 : 117 : return clone;
8317 : : }
8318 : :
8319 : :
8320 : : /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
8321 : :
8322 : : struct decl_table_entry
8323 : : {
8324 : : dw_die_ref orig;
8325 : : dw_die_ref copy;
8326 : : };
8327 : :
8328 : : /* Helpers to manipulate hash table of copied declarations. */
8329 : :
8330 : : /* Hashtable helpers. */
8331 : :
8332 : : struct decl_table_entry_hasher : free_ptr_hash <decl_table_entry>
8333 : : {
8334 : : typedef die_struct *compare_type;
8335 : : static inline hashval_t hash (const decl_table_entry *);
8336 : : static inline bool equal (const decl_table_entry *, const die_struct *);
8337 : : };
8338 : :
8339 : : inline hashval_t
8340 : 445 : decl_table_entry_hasher::hash (const decl_table_entry *entry)
8341 : : {
8342 : 445 : return htab_hash_pointer (entry->orig);
8343 : : }
8344 : :
8345 : : inline bool
8346 : 481 : decl_table_entry_hasher::equal (const decl_table_entry *entry1,
8347 : : const die_struct *entry2)
8348 : : {
8349 : 481 : return entry1->orig == entry2;
8350 : : }
8351 : :
8352 : : typedef hash_table<decl_table_entry_hasher> decl_hash_type;
8353 : :
8354 : : /* Copy DIE and its ancestors, up to, but not including, the compile unit
8355 : : or type unit entry, to a new tree. Adds the new tree to UNIT and returns
8356 : : a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
8357 : : to check if the ancestor has already been copied into UNIT. */
8358 : :
8359 : : static dw_die_ref
8360 : 101 : copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
8361 : : decl_hash_type *decl_table)
8362 : : {
8363 : 101 : dw_die_ref parent = die->die_parent;
8364 : 101 : dw_die_ref new_parent = unit;
8365 : 101 : dw_die_ref copy;
8366 : 101 : decl_table_entry **slot = NULL;
8367 : 101 : struct decl_table_entry *entry = NULL;
8368 : :
8369 : : /* If DIE refers to a stub unfold that so we get the appropriate
8370 : : DIE registered as orig in decl_table. */
8371 : 101 : if (dw_die_ref c = get_AT_ref (die, DW_AT_signature))
8372 : 0 : die = c;
8373 : :
8374 : 101 : if (decl_table)
8375 : : {
8376 : : /* Check if the entry has already been copied to UNIT. */
8377 : 11 : slot = decl_table->find_slot_with_hash (die, htab_hash_pointer (die),
8378 : : INSERT);
8379 : 11 : if (*slot != HTAB_EMPTY_ENTRY)
8380 : : {
8381 : 4 : entry = *slot;
8382 : 4 : return entry->copy;
8383 : : }
8384 : :
8385 : : /* Record in DECL_TABLE that DIE has been copied to UNIT. */
8386 : 7 : entry = XCNEW (struct decl_table_entry);
8387 : 7 : entry->orig = die;
8388 : 7 : entry->copy = NULL;
8389 : 7 : *slot = entry;
8390 : : }
8391 : :
8392 : 97 : if (parent != NULL)
8393 : : {
8394 : 97 : dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
8395 : 97 : if (spec != NULL)
8396 : 0 : parent = spec;
8397 : 97 : if (!is_unit_die (parent))
8398 : 48 : new_parent = copy_ancestor_tree (unit, parent, decl_table);
8399 : : }
8400 : :
8401 : 97 : copy = clone_as_declaration (die);
8402 : 97 : add_child_die (new_parent, copy);
8403 : :
8404 : 97 : if (decl_table)
8405 : : {
8406 : : /* Record the pointer to the copy. */
8407 : 7 : entry->copy = copy;
8408 : : }
8409 : :
8410 : : return copy;
8411 : : }
8412 : : /* Copy the declaration context to the new type unit DIE. This includes
8413 : : any surrounding namespace or type declarations. If the DIE has an
8414 : : AT_specification attribute, it also includes attributes and children
8415 : : attached to the specification, and returns a pointer to the original
8416 : : parent of the declaration DIE. Returns NULL otherwise. */
8417 : :
8418 : : static dw_die_ref
8419 : 80 : copy_declaration_context (dw_die_ref unit, dw_die_ref die)
8420 : : {
8421 : 80 : dw_die_ref decl;
8422 : 80 : dw_die_ref new_decl;
8423 : 80 : dw_die_ref orig_parent = NULL;
8424 : :
8425 : 80 : decl = get_AT_ref (die, DW_AT_specification);
8426 : 80 : if (decl == NULL)
8427 : : decl = die;
8428 : : else
8429 : : {
8430 : 0 : unsigned ix;
8431 : 0 : dw_die_ref c;
8432 : 0 : dw_attr_node *a;
8433 : :
8434 : : /* The original DIE will be changed to a declaration, and must
8435 : : be moved to be a child of the original declaration DIE. */
8436 : 0 : orig_parent = decl->die_parent;
8437 : :
8438 : : /* Copy the type node pointer from the new DIE to the original
8439 : : declaration DIE so we can forward references later. */
8440 : 0 : decl->comdat_type_p = true;
8441 : 0 : decl->die_id.die_type_node = die->die_id.die_type_node;
8442 : :
8443 : 0 : remove_AT (die, DW_AT_specification);
8444 : :
8445 : 0 : FOR_EACH_VEC_SAFE_ELT (decl->die_attr, ix, a)
8446 : : {
8447 : 0 : if (a->dw_attr != DW_AT_name
8448 : : && a->dw_attr != DW_AT_declaration
8449 : : && a->dw_attr != DW_AT_external)
8450 : 0 : add_dwarf_attr (die, a);
8451 : : }
8452 : :
8453 : 0 : FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree (c)));
8454 : : }
8455 : :
8456 : 80 : if (decl->die_parent != NULL
8457 : 80 : && !is_unit_die (decl->die_parent))
8458 : : {
8459 : 42 : new_decl = copy_ancestor_tree (unit, decl, NULL);
8460 : 42 : if (new_decl != NULL)
8461 : : {
8462 : 42 : remove_AT (new_decl, DW_AT_signature);
8463 : 42 : add_AT_specification (die, new_decl);
8464 : : }
8465 : : }
8466 : :
8467 : 80 : return orig_parent;
8468 : : }
8469 : :
8470 : : /* Generate the skeleton ancestor tree for the given NODE, then clone
8471 : : the DIE and add the clone into the tree. */
8472 : :
8473 : : static void
8474 : 88 : generate_skeleton_ancestor_tree (skeleton_chain_node *node)
8475 : : {
8476 : 88 : if (node->new_die != NULL)
8477 : : return;
8478 : :
8479 : 38 : node->new_die = clone_as_declaration (node->old_die);
8480 : :
8481 : 38 : if (node->parent != NULL)
8482 : : {
8483 : 0 : generate_skeleton_ancestor_tree (node->parent);
8484 : 0 : add_child_die (node->parent->new_die, node->new_die);
8485 : : }
8486 : : }
8487 : :
8488 : : /* Generate a skeleton tree of DIEs containing any declarations that are
8489 : : found in the original tree. We traverse the tree looking for declaration
8490 : : DIEs, and construct the skeleton from the bottom up whenever we find one. */
8491 : :
8492 : : static void
8493 : 345 : generate_skeleton_bottom_up (skeleton_chain_node *parent)
8494 : : {
8495 : 345 : skeleton_chain_node node;
8496 : 345 : dw_die_ref c;
8497 : 345 : dw_die_ref first;
8498 : 345 : dw_die_ref prev = NULL;
8499 : 345 : dw_die_ref next = NULL;
8500 : :
8501 : 345 : node.parent = parent;
8502 : :
8503 : 345 : first = c = parent->old_die->die_child;
8504 : 345 : if (c)
8505 : 146 : next = c->die_sib;
8506 : 146 : if (c) do {
8507 : 277 : if (prev == NULL || prev->die_sib == c)
8508 : 277 : prev = c;
8509 : 277 : c = next;
8510 : 277 : next = (c == first ? NULL : c->die_sib);
8511 : 277 : node.old_die = c;
8512 : 277 : node.new_die = NULL;
8513 : 277 : if (is_declaration_die (c))
8514 : : {
8515 : 92 : if (is_template_instantiation (c))
8516 : : {
8517 : : /* Instantiated templates do not need to be cloned into the
8518 : : type unit. Just move the DIE and its children back to
8519 : : the skeleton tree (in the main CU). */
8520 : 4 : remove_child_with_prev (c, prev);
8521 : 4 : add_child_die (parent->new_die, c);
8522 : 4 : c = prev;
8523 : : }
8524 : 88 : else if (c->comdat_type_p)
8525 : : {
8526 : : /* This is the skeleton of earlier break_out_comdat_types
8527 : : type. Clone the existing DIE, but keep the children
8528 : : under the original (which is in the main CU). */
8529 : 12 : dw_die_ref clone = clone_die (c);
8530 : :
8531 : 12 : replace_child (c, clone, prev);
8532 : 12 : generate_skeleton_ancestor_tree (parent);
8533 : 12 : add_child_die (parent->new_die, c);
8534 : 12 : c = clone;
8535 : 12 : continue;
8536 : 12 : }
8537 : : else
8538 : : {
8539 : : /* Clone the existing DIE, move the original to the skeleton
8540 : : tree (which is in the main CU), and put the clone, with
8541 : : all the original's children, where the original came from
8542 : : (which is about to be moved to the type unit). */
8543 : 76 : dw_die_ref clone = clone_die (c);
8544 : 76 : move_all_children (c, clone);
8545 : :
8546 : : /* If the original has a DW_AT_object_pointer attribute,
8547 : : it would now point to a child DIE just moved to the
8548 : : cloned tree, so we need to remove that attribute from
8549 : : the original. */
8550 : 76 : remove_AT (c, DW_AT_object_pointer);
8551 : :
8552 : 76 : replace_child (c, clone, prev);
8553 : 76 : generate_skeleton_ancestor_tree (parent);
8554 : 76 : add_child_die (parent->new_die, c);
8555 : 76 : node.old_die = clone;
8556 : 76 : node.new_die = c;
8557 : 76 : c = clone;
8558 : : }
8559 : : }
8560 : 265 : generate_skeleton_bottom_up (&node);
8561 : 277 : } while (next != NULL);
8562 : 345 : }
8563 : :
8564 : : /* Wrapper function for generate_skeleton_bottom_up. */
8565 : :
8566 : : static dw_die_ref
8567 : 80 : generate_skeleton (dw_die_ref die)
8568 : : {
8569 : 80 : skeleton_chain_node node;
8570 : :
8571 : 80 : node.old_die = die;
8572 : 80 : node.new_die = NULL;
8573 : 80 : node.parent = NULL;
8574 : :
8575 : : /* If this type definition is nested inside another type,
8576 : : and is not an instantiation of a template, always leave
8577 : : at least a declaration in its place. */
8578 : 80 : if (die->die_parent != NULL
8579 : 80 : && is_type_die (die->die_parent)
8580 : 92 : && !is_template_instantiation (die))
8581 : 12 : node.new_die = clone_as_declaration (die);
8582 : :
8583 : 80 : generate_skeleton_bottom_up (&node);
8584 : 80 : return node.new_die;
8585 : : }
8586 : :
8587 : : /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
8588 : : declaration. The original DIE is moved to a new compile unit so that
8589 : : existing references to it follow it to the new location. If any of the
8590 : : original DIE's descendants is a declaration, we need to replace the
8591 : : original DIE with a skeleton tree and move the declarations back into the
8592 : : skeleton tree. */
8593 : :
8594 : : static dw_die_ref
8595 : 80 : remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
8596 : : dw_die_ref prev)
8597 : : {
8598 : 80 : dw_die_ref skeleton, orig_parent;
8599 : :
8600 : : /* Copy the declaration context to the type unit DIE. If the returned
8601 : : ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
8602 : : that DIE. */
8603 : 80 : orig_parent = copy_declaration_context (unit, child);
8604 : :
8605 : 80 : skeleton = generate_skeleton (child);
8606 : 80 : if (skeleton == NULL)
8607 : 30 : remove_child_with_prev (child, prev);
8608 : : else
8609 : : {
8610 : 50 : skeleton->comdat_type_p = true;
8611 : 50 : skeleton->die_id.die_type_node = child->die_id.die_type_node;
8612 : :
8613 : : /* If the original DIE was a specification, we need to put
8614 : : the skeleton under the parent DIE of the declaration.
8615 : : This leaves the original declaration in the tree, but
8616 : : it will be pruned later since there are no longer any
8617 : : references to it. */
8618 : 50 : if (orig_parent != NULL)
8619 : : {
8620 : 0 : remove_child_with_prev (child, prev);
8621 : 0 : add_child_die (orig_parent, skeleton);
8622 : : }
8623 : : else
8624 : 50 : replace_child (child, skeleton, prev);
8625 : : }
8626 : :
8627 : 80 : return skeleton;
8628 : : }
8629 : :
8630 : : static void
8631 : : copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
8632 : : comdat_type_node *type_node,
8633 : : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs);
8634 : :
8635 : : /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
8636 : : procedure, put it under TYPE_NODE and return the copy. Continue looking for
8637 : : DWARF procedure references in the DW_AT_location attribute. */
8638 : :
8639 : : static dw_die_ref
8640 : 0 : copy_dwarf_procedure (dw_die_ref die,
8641 : : comdat_type_node *type_node,
8642 : : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
8643 : : {
8644 : 0 : gcc_assert (die->die_tag == DW_TAG_dwarf_procedure);
8645 : :
8646 : : /* DWARF procedures are not supposed to have children... */
8647 : 0 : gcc_assert (die->die_child == NULL);
8648 : :
8649 : : /* ... and they are supposed to have only one attribute: DW_AT_location. */
8650 : 0 : gcc_assert (vec_safe_length (die->die_attr) == 1
8651 : : && ((*die->die_attr)[0].dw_attr == DW_AT_location));
8652 : :
8653 : : /* Do not copy more than once DWARF procedures. */
8654 : 0 : bool existed;
8655 : 0 : dw_die_ref &die_copy = copied_dwarf_procs.get_or_insert (die, &existed);
8656 : 0 : if (existed)
8657 : 0 : return die_copy;
8658 : :
8659 : 0 : die_copy = clone_die (die);
8660 : 0 : add_child_die (type_node->root_die, die_copy);
8661 : 0 : copy_dwarf_procs_ref_in_attrs (die_copy, type_node, copied_dwarf_procs);
8662 : 0 : return die_copy;
8663 : : }
8664 : :
8665 : : /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
8666 : : procedures in DIE's attributes. */
8667 : :
8668 : : static void
8669 : 341 : copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
8670 : : comdat_type_node *type_node,
8671 : : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
8672 : : {
8673 : 341 : dw_attr_node *a;
8674 : 341 : unsigned i;
8675 : :
8676 : 1939 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, i, a)
8677 : : {
8678 : 1598 : dw_loc_descr_ref loc;
8679 : :
8680 : 1598 : if (a->dw_attr_val.val_class != dw_val_class_loc)
8681 : 1598 : continue;
8682 : :
8683 : 0 : for (loc = a->dw_attr_val.v.val_loc; loc != NULL; loc = loc->dw_loc_next)
8684 : : {
8685 : 0 : switch (loc->dw_loc_opc)
8686 : : {
8687 : 0 : case DW_OP_call2:
8688 : 0 : case DW_OP_call4:
8689 : 0 : case DW_OP_call_ref:
8690 : 0 : gcc_assert (loc->dw_loc_oprnd1.val_class
8691 : : == dw_val_class_die_ref);
8692 : 0 : loc->dw_loc_oprnd1.v.val_die_ref.die
8693 : 0 : = copy_dwarf_procedure (loc->dw_loc_oprnd1.v.val_die_ref.die,
8694 : : type_node,
8695 : : copied_dwarf_procs);
8696 : :
8697 : 0 : default:
8698 : 0 : break;
8699 : : }
8700 : : }
8701 : : }
8702 : 341 : }
8703 : :
8704 : : /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
8705 : : rewrite references to point to the copies.
8706 : :
8707 : : References are looked for in DIE's attributes and recursively in all its
8708 : : children attributes that are location descriptions. COPIED_DWARF_PROCS is a
8709 : : mapping from old DWARF procedures to their copy. It is used not to copy
8710 : : twice the same DWARF procedure under TYPE_NODE. */
8711 : :
8712 : : static void
8713 : 341 : copy_dwarf_procs_ref_in_dies (dw_die_ref die,
8714 : : comdat_type_node *type_node,
8715 : : hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
8716 : : {
8717 : 341 : dw_die_ref c;
8718 : :
8719 : 341 : copy_dwarf_procs_ref_in_attrs (die, type_node, copied_dwarf_procs);
8720 : 602 : FOR_EACH_CHILD (die, c, copy_dwarf_procs_ref_in_dies (c,
8721 : : type_node,
8722 : : copied_dwarf_procs));
8723 : 341 : }
8724 : :
8725 : : /* Traverse the DIE and set up additional .debug_types or .debug_info
8726 : : DW_UT_*type sections for each type worthy of being placed in a COMDAT
8727 : : section. */
8728 : :
8729 : : static void
8730 : 148 : break_out_comdat_types (dw_die_ref die)
8731 : : {
8732 : 148 : dw_die_ref c;
8733 : 148 : dw_die_ref first;
8734 : 148 : dw_die_ref prev = NULL;
8735 : 148 : dw_die_ref next = NULL;
8736 : 148 : dw_die_ref unit = NULL;
8737 : :
8738 : 148 : first = c = die->die_child;
8739 : 148 : if (c)
8740 : 142 : next = c->die_sib;
8741 : 142 : if (c) do {
8742 : 755 : if (prev == NULL || prev->die_sib == c)
8743 : 725 : prev = c;
8744 : 755 : c = next;
8745 : 755 : next = (c == first ? NULL : c->die_sib);
8746 : 755 : if (should_move_die_to_comdat (c))
8747 : : {
8748 : 80 : dw_die_ref replacement;
8749 : 80 : comdat_type_node *type_node;
8750 : :
8751 : : /* Break out nested types into their own type units. */
8752 : 80 : break_out_comdat_types (c);
8753 : :
8754 : : /* Create a new type unit DIE as the root for the new tree. */
8755 : 80 : unit = new_die (DW_TAG_type_unit, NULL, NULL);
8756 : 80 : add_AT_unsigned (unit, DW_AT_language,
8757 : 80 : get_AT_unsigned (comp_unit_die (), DW_AT_language));
8758 : 80 : if (unsigned lname = get_AT_unsigned (comp_unit_die (),
8759 : : DW_AT_language_name))
8760 : : {
8761 : 15 : add_AT_unsigned (unit, DW_AT_language_name, lname);
8762 : 15 : add_AT_unsigned (unit, DW_AT_language_version,
8763 : 15 : get_AT_unsigned (comp_unit_die (),
8764 : : DW_AT_language_version));
8765 : : }
8766 : :
8767 : : /* Add the new unit's type DIE into the comdat type list. */
8768 : 80 : type_node = ggc_cleared_alloc<comdat_type_node> ();
8769 : 80 : type_node->root_die = unit;
8770 : 80 : type_node->next = comdat_type_list;
8771 : 80 : comdat_type_list = type_node;
8772 : :
8773 : : /* Generate the type signature. */
8774 : 80 : generate_type_signature (c, type_node);
8775 : :
8776 : : /* Copy the declaration context, attributes, and children of the
8777 : : declaration into the new type unit DIE, then remove this DIE
8778 : : from the main CU (or replace it with a skeleton if necessary). */
8779 : 80 : replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
8780 : 80 : type_node->skeleton_die = replacement;
8781 : :
8782 : : /* Add the DIE to the new compunit. */
8783 : 80 : add_child_die (unit, c);
8784 : :
8785 : : /* Types can reference DWARF procedures for type size or data location
8786 : : expressions. Calls in DWARF expressions cannot target procedures
8787 : : that are not in the same section. So we must copy DWARF procedures
8788 : : along with this type and then rewrite references to them. */
8789 : 80 : hash_map<dw_die_ref, dw_die_ref> copied_dwarf_procs;
8790 : 80 : copy_dwarf_procs_ref_in_dies (c, type_node, copied_dwarf_procs);
8791 : :
8792 : 80 : if (replacement != NULL)
8793 : 50 : c = replacement;
8794 : 80 : }
8795 : 675 : else if (c->die_tag == DW_TAG_namespace
8796 : : || c->die_tag == DW_TAG_class_type
8797 : : || c->die_tag == DW_TAG_structure_type
8798 : : || c->die_tag == DW_TAG_union_type)
8799 : : {
8800 : : /* Look for nested types that can be broken out. */
8801 : 33 : break_out_comdat_types (c);
8802 : : }
8803 : 755 : } while (next != NULL);
8804 : 148 : }
8805 : :
8806 : : /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
8807 : : Enter all the cloned children into the hash table decl_table. */
8808 : :
8809 : : static dw_die_ref
8810 : 8 : clone_tree_partial (dw_die_ref die, decl_hash_type *decl_table)
8811 : : {
8812 : 8 : dw_die_ref c;
8813 : 8 : dw_die_ref clone;
8814 : 8 : struct decl_table_entry *entry;
8815 : 8 : decl_table_entry **slot;
8816 : :
8817 : 8 : if (die->die_tag == DW_TAG_subprogram)
8818 : 0 : clone = clone_as_declaration (die);
8819 : : else
8820 : 8 : clone = clone_die (die);
8821 : :
8822 : 8 : slot = decl_table->find_slot_with_hash (die,
8823 : : htab_hash_pointer (die), INSERT);
8824 : :
8825 : : /* Assert that DIE isn't in the hash table yet. If it would be there
8826 : : before, the ancestors would be necessarily there as well, therefore
8827 : : clone_tree_partial wouldn't be called. */
8828 : 8 : gcc_assert (*slot == HTAB_EMPTY_ENTRY);
8829 : :
8830 : 8 : entry = XCNEW (struct decl_table_entry);
8831 : 8 : entry->orig = die;
8832 : 8 : entry->copy = clone;
8833 : 8 : *slot = entry;
8834 : :
8835 : 8 : if (die->die_tag != DW_TAG_subprogram)
8836 : 8 : FOR_EACH_CHILD (die, c,
8837 : : add_child_die (clone, clone_tree_partial (c, decl_table)));
8838 : :
8839 : 8 : return clone;
8840 : : }
8841 : :
8842 : : /* Walk the DIE and its children, looking for references to incomplete
8843 : : or trivial types that are unmarked (i.e., that are not in the current
8844 : : type_unit). */
8845 : :
8846 : : static void
8847 : 1697 : copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
8848 : : {
8849 : 1697 : dw_die_ref c;
8850 : 1697 : dw_attr_node *a;
8851 : 1697 : unsigned ix;
8852 : :
8853 : 7507 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
8854 : : {
8855 : 5810 : if (AT_class (a) == dw_val_class_die_ref)
8856 : : {
8857 : 1348 : dw_die_ref targ = AT_ref (a);
8858 : 1348 : decl_table_entry **slot;
8859 : 1348 : struct decl_table_entry *entry;
8860 : :
8861 : 1348 : if (targ->die_mark != 0 || targ->comdat_type_p)
8862 : 1116 : continue;
8863 : :
8864 : 232 : slot = decl_table->find_slot_with_hash (targ,
8865 : : htab_hash_pointer (targ),
8866 : : INSERT);
8867 : :
8868 : 232 : if (*slot != HTAB_EMPTY_ENTRY)
8869 : : {
8870 : : /* TARG has already been copied, so we just need to
8871 : : modify the reference to point to the copy. */
8872 : 88 : entry = *slot;
8873 : 88 : a->dw_attr_val.v.val_die_ref.die = entry->copy;
8874 : : }
8875 : : else
8876 : : {
8877 : 144 : dw_die_ref parent = unit;
8878 : 144 : dw_die_ref copy = clone_die (targ);
8879 : :
8880 : : /* Record in DECL_TABLE that TARG has been copied.
8881 : : Need to do this now, before the recursive call,
8882 : : because DECL_TABLE may be expanded and SLOT
8883 : : would no longer be a valid pointer. */
8884 : 144 : entry = XCNEW (struct decl_table_entry);
8885 : 144 : entry->orig = targ;
8886 : 144 : entry->copy = copy;
8887 : 144 : *slot = entry;
8888 : :
8889 : : /* If TARG is not a declaration DIE, we need to copy its
8890 : : children. */
8891 : 144 : if (!is_declaration_die (targ))
8892 : : {
8893 : 140 : FOR_EACH_CHILD (
8894 : : targ, c,
8895 : : add_child_die (copy,
8896 : : clone_tree_partial (c, decl_table)));
8897 : : }
8898 : :
8899 : : /* Make sure the cloned tree is marked as part of the
8900 : : type unit. */
8901 : 144 : mark_dies (copy);
8902 : :
8903 : : /* If TARG has surrounding context, copy its ancestor tree
8904 : : into the new type unit. */
8905 : 144 : if (targ->die_parent != NULL
8906 : 144 : && !is_unit_die (targ->die_parent))
8907 : 11 : parent = copy_ancestor_tree (unit, targ->die_parent,
8908 : : decl_table);
8909 : :
8910 : 144 : add_child_die (parent, copy);
8911 : 144 : a->dw_attr_val.v.val_die_ref.die = copy;
8912 : :
8913 : : /* Make sure the newly-copied DIE is walked. If it was
8914 : : installed in a previously-added context, it won't
8915 : : get visited otherwise. */
8916 : 144 : if (parent != unit)
8917 : : {
8918 : : /* Find the highest point of the newly-added tree,
8919 : : mark each node along the way, and walk from there. */
8920 : 11 : parent->die_mark = 1;
8921 : 11 : while (parent->die_parent
8922 : 11 : && parent->die_parent->die_mark == 0)
8923 : : {
8924 : 0 : parent = parent->die_parent;
8925 : 0 : parent->die_mark = 1;
8926 : : }
8927 : 11 : copy_decls_walk (unit, parent, decl_table);
8928 : : }
8929 : : }
8930 : : }
8931 : : }
8932 : :
8933 : 2648 : FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
8934 : 1697 : }
8935 : :
8936 : : /* Collect skeleton dies in DIE created by break_out_comdat_types already
8937 : : and record them in DECL_TABLE. */
8938 : :
8939 : : static void
8940 : 1515 : collect_skeleton_dies (dw_die_ref die, decl_hash_type *decl_table)
8941 : : {
8942 : 1515 : dw_die_ref c;
8943 : :
8944 : 1515 : if (dw_attr_node *a = get_AT (die, DW_AT_signature))
8945 : : {
8946 : 62 : dw_die_ref targ = AT_ref (a);
8947 : 62 : gcc_assert (targ->die_mark == 0 && targ->comdat_type_p);
8948 : 62 : decl_table_entry **slot
8949 : 62 : = decl_table->find_slot_with_hash (targ,
8950 : : htab_hash_pointer (targ),
8951 : : INSERT);
8952 : 62 : gcc_assert (*slot == HTAB_EMPTY_ENTRY);
8953 : : /* Record in DECL_TABLE that TARG has been already copied
8954 : : by remove_child_or_replace_with_skeleton. */
8955 : 62 : decl_table_entry *entry = XCNEW (struct decl_table_entry);
8956 : 62 : entry->orig = targ;
8957 : 62 : entry->copy = die;
8958 : 62 : *slot = entry;
8959 : : }
8960 : 2915 : FOR_EACH_CHILD (die, c, collect_skeleton_dies (c, decl_table));
8961 : 1515 : }
8962 : :
8963 : : /* Copy declarations for "unworthy" types into the new comdat section.
8964 : : Incomplete types, modified types, and certain other types aren't broken
8965 : : out into comdat sections of their own, so they don't have a signature,
8966 : : and we need to copy the declaration into the same section so that we
8967 : : don't have an external reference. */
8968 : :
8969 : : static void
8970 : 115 : copy_decls_for_unworthy_types (dw_die_ref unit)
8971 : : {
8972 : 115 : mark_dies (unit);
8973 : 115 : decl_hash_type decl_table (10);
8974 : 115 : collect_skeleton_dies (unit, &decl_table);
8975 : 115 : copy_decls_walk (unit, unit, &decl_table);
8976 : 115 : unmark_dies (unit);
8977 : 115 : }
8978 : :
8979 : : /* Traverse the DIE and add a sibling attribute if it may have the
8980 : : effect of speeding up access to siblings. To save some space,
8981 : : avoid generating sibling attributes for DIE's without children. */
8982 : :
8983 : : static void
8984 : 80830097 : add_sibling_attributes (dw_die_ref die)
8985 : : {
8986 : 80830097 : dw_die_ref c;
8987 : :
8988 : 80830097 : if (! die->die_child)
8989 : : return;
8990 : :
8991 : 21777156 : if (die->die_parent && die != die->die_parent->die_child)
8992 : 16644409 : add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
8993 : :
8994 : 80776718 : FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
8995 : : }
8996 : :
8997 : : /* Output all location lists for the DIE and its children. */
8998 : :
8999 : : static void
9000 : 72857347 : output_location_lists (dw_die_ref die)
9001 : : {
9002 : 72857347 : dw_die_ref c;
9003 : 72857347 : dw_attr_node *a;
9004 : 72857347 : unsigned ix;
9005 : :
9006 : 359397398 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9007 : 286540051 : if (AT_class (a) == dw_val_class_loc_list)
9008 : 11206203 : output_loc_list (AT_loc_list (a));
9009 : :
9010 : 145682339 : FOR_EACH_CHILD (die, c, output_location_lists (c));
9011 : 72857347 : }
9012 : :
9013 : : /* During assign_location_list_indexes and output_loclists_offset the
9014 : : current index, after it the number of assigned indexes (i.e. how
9015 : : large the .debug_loclists* offset table should be). */
9016 : : static unsigned int loc_list_idx;
9017 : :
9018 : : /* Output all location list offsets for the DIE and its children. */
9019 : :
9020 : : static void
9021 : 26 : output_loclists_offsets (dw_die_ref die)
9022 : : {
9023 : 26 : dw_die_ref c;
9024 : 26 : dw_attr_node *a;
9025 : 26 : unsigned ix;
9026 : :
9027 : 155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9028 : 129 : if (AT_class (a) == dw_val_class_loc_list)
9029 : : {
9030 : 2 : dw_loc_list_ref l = AT_loc_list (a);
9031 : 2 : if (l->offset_emitted)
9032 : 0 : continue;
9033 : 2 : dw2_asm_output_delta (dwarf_offset_size, l->ll_symbol,
9034 : : loc_section_label, NULL);
9035 : 2 : gcc_assert (l->hash == loc_list_idx);
9036 : 2 : loc_list_idx++;
9037 : 2 : l->offset_emitted = true;
9038 : : }
9039 : :
9040 : 50 : FOR_EACH_CHILD (die, c, output_loclists_offsets (c));
9041 : 26 : }
9042 : :
9043 : : /* Recursively set indexes of location lists. */
9044 : :
9045 : : static void
9046 : 26 : assign_location_list_indexes (dw_die_ref die)
9047 : : {
9048 : 26 : dw_die_ref c;
9049 : 26 : dw_attr_node *a;
9050 : 26 : unsigned ix;
9051 : :
9052 : 155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9053 : 129 : if (AT_class (a) == dw_val_class_loc_list)
9054 : : {
9055 : 2 : dw_loc_list_ref list = AT_loc_list (a);
9056 : 2 : if (!list->num_assigned)
9057 : : {
9058 : 2 : list->num_assigned = true;
9059 : 2 : list->hash = loc_list_idx++;
9060 : : }
9061 : : }
9062 : :
9063 : 50 : FOR_EACH_CHILD (die, c, assign_location_list_indexes (c));
9064 : 26 : }
9065 : :
9066 : : /* We want to limit the number of external references, because they are
9067 : : larger than local references: a relocation takes multiple words, and
9068 : : even a sig8 reference is always eight bytes, whereas a local reference
9069 : : can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
9070 : : So if we encounter multiple external references to the same type DIE, we
9071 : : make a local typedef stub for it and redirect all references there.
9072 : :
9073 : : This is the element of the hash table for keeping track of these
9074 : : references. */
9075 : :
9076 : : struct external_ref
9077 : : {
9078 : : dw_die_ref type;
9079 : : dw_die_ref stub;
9080 : : unsigned n_refs;
9081 : : };
9082 : :
9083 : : /* Hashtable helpers. */
9084 : :
9085 : : struct external_ref_hasher : free_ptr_hash <external_ref>
9086 : : {
9087 : : static inline hashval_t hash (const external_ref *);
9088 : : static inline bool equal (const external_ref *, const external_ref *);
9089 : : };
9090 : :
9091 : : inline hashval_t
9092 : 1370 : external_ref_hasher::hash (const external_ref *r)
9093 : : {
9094 : 1370 : dw_die_ref die = r->type;
9095 : 1370 : hashval_t h = 0;
9096 : :
9097 : : /* We can't use the address of the DIE for hashing, because
9098 : : that will make the order of the stub DIEs non-deterministic. */
9099 : 1370 : if (! die->comdat_type_p)
9100 : : /* We have a symbol; use it to compute a hash. */
9101 : 0 : h = htab_hash_string (die->die_id.die_symbol);
9102 : : else
9103 : : {
9104 : : /* We have a type signature; use a subset of the bits as the hash.
9105 : : The 8-byte signature is at least as large as hashval_t. */
9106 : 1370 : comdat_type_node *type_node = die->die_id.die_type_node;
9107 : 1370 : memcpy (&h, type_node->signature, sizeof (h));
9108 : : }
9109 : 1370 : return h;
9110 : : }
9111 : :
9112 : : inline bool
9113 : 1030 : external_ref_hasher::equal (const external_ref *r1, const external_ref *r2)
9114 : : {
9115 : 1030 : return r1->type == r2->type;
9116 : : }
9117 : :
9118 : : typedef hash_table<external_ref_hasher> external_ref_hash_type;
9119 : :
9120 : : /* Return a pointer to the external_ref for references to DIE. */
9121 : :
9122 : : static struct external_ref *
9123 : 491 : lookup_external_ref (external_ref_hash_type *map, dw_die_ref die)
9124 : : {
9125 : 491 : struct external_ref ref, *ref_p;
9126 : 491 : external_ref **slot;
9127 : :
9128 : 491 : ref.type = die;
9129 : 491 : slot = map->find_slot (&ref, INSERT);
9130 : 491 : if (*slot != HTAB_EMPTY_ENTRY)
9131 : : return *slot;
9132 : :
9133 : 87 : ref_p = XCNEW (struct external_ref);
9134 : 87 : ref_p->type = die;
9135 : 87 : *slot = ref_p;
9136 : 87 : return ref_p;
9137 : : }
9138 : :
9139 : : /* Subroutine of optimize_external_refs, below.
9140 : :
9141 : : If we see a type skeleton, record it as our stub. If we see external
9142 : : references, remember how many we've seen. */
9143 : :
9144 : : static void
9145 : 80829030 : optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
9146 : : {
9147 : 80829030 : dw_die_ref c;
9148 : 80829030 : dw_attr_node *a;
9149 : 80829030 : unsigned ix;
9150 : 80829030 : struct external_ref *ref_p;
9151 : :
9152 : 80829030 : if (is_type_die (die)
9153 : 80829030 : && (c = get_AT_ref (die, DW_AT_signature)))
9154 : : {
9155 : : /* This is a local skeleton; use it for local references. */
9156 : 51 : ref_p = lookup_external_ref (map, c);
9157 : 51 : ref_p->stub = die;
9158 : : }
9159 : :
9160 : : /* Scan the DIE references, and remember any that refer to DIEs from
9161 : : other CUs (i.e. those which are not marked). */
9162 : 399871628 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9163 : 319042598 : if (AT_class (a) == dw_val_class_die_ref
9164 : 94848522 : && (c = AT_ref (a))->die_mark == 0
9165 : 319071638 : && is_type_die (c))
9166 : : {
9167 : 214 : ref_p = lookup_external_ref (map, c);
9168 : 214 : ref_p->n_refs++;
9169 : : }
9170 : :
9171 : 139828582 : FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
9172 : 80829030 : }
9173 : :
9174 : : /* htab_traverse callback function for optimize_external_refs, below. SLOT
9175 : : points to an external_ref, DATA is the CU we're processing. If we don't
9176 : : already have a local stub, and we have multiple refs, build a stub. */
9177 : :
9178 : : int
9179 : 87 : dwarf2_build_local_stub (external_ref **slot, dw_die_ref data)
9180 : : {
9181 : 87 : struct external_ref *ref_p = *slot;
9182 : :
9183 : 87 : if (ref_p->stub == NULL && ref_p->n_refs > 1 && !dwarf_strict)
9184 : : {
9185 : : /* We have multiple references to this type, so build a small stub.
9186 : : Both of these forms are a bit dodgy from the perspective of the
9187 : : DWARF standard, since technically they should have names. */
9188 : 12 : dw_die_ref cu = data;
9189 : 12 : dw_die_ref type = ref_p->type;
9190 : 12 : dw_die_ref stub = NULL;
9191 : :
9192 : 12 : if (type->comdat_type_p)
9193 : : {
9194 : : /* If we refer to this type via sig8, use AT_signature. */
9195 : 12 : stub = new_die (type->die_tag, cu, NULL_TREE);
9196 : 12 : add_AT_die_ref (stub, DW_AT_signature, type);
9197 : : }
9198 : : else
9199 : : {
9200 : : /* Otherwise, use a typedef with no name. */
9201 : 0 : stub = new_die (DW_TAG_typedef, cu, NULL_TREE);
9202 : 0 : add_AT_die_ref (stub, DW_AT_type, type);
9203 : : }
9204 : :
9205 : 12 : stub->die_mark++;
9206 : 12 : ref_p->stub = stub;
9207 : : }
9208 : 87 : return 1;
9209 : : }
9210 : :
9211 : : /* DIE is a unit; look through all the DIE references to see if there are
9212 : : any external references to types, and if so, create local stubs for
9213 : : them which will be applied in build_abbrev_table. This is useful because
9214 : : references to local DIEs are smaller. */
9215 : :
9216 : : static external_ref_hash_type *
9217 : 52328 : optimize_external_refs (dw_die_ref die)
9218 : : {
9219 : 52328 : external_ref_hash_type *map = new external_ref_hash_type (10);
9220 : 52328 : optimize_external_refs_1 (die, map);
9221 : 52415 : map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
9222 : 52328 : return map;
9223 : : }
9224 : :
9225 : : /* The following 3 variables are temporaries that are computed only during the
9226 : : build_abbrev_table call and used and released during the following
9227 : : optimize_abbrev_table call. */
9228 : :
9229 : : /* First abbrev_id that can be optimized based on usage. */
9230 : : static unsigned int abbrev_opt_start;
9231 : :
9232 : : /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
9233 : : abbrev_id smaller than this, because they must be already sized
9234 : : during build_abbrev_table). */
9235 : : static unsigned int abbrev_opt_base_type_end;
9236 : :
9237 : : /* Vector of usage counts during build_abbrev_table. Indexed by
9238 : : abbrev_id - abbrev_opt_start. */
9239 : : static vec<unsigned int> abbrev_usage_count;
9240 : :
9241 : : /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start. */
9242 : : static vec<dw_die_ref> sorted_abbrev_dies;
9243 : :
9244 : : /* The format of each DIE (and its attribute value pairs) is encoded in an
9245 : : abbreviation table. This routine builds the abbreviation table and assigns
9246 : : a unique abbreviation id for each abbreviation entry. The children of each
9247 : : die are visited recursively. */
9248 : :
9249 : : static void
9250 : 80829042 : build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
9251 : : {
9252 : 80829042 : unsigned int abbrev_id = 0;
9253 : 80829042 : dw_die_ref c;
9254 : 80829042 : dw_attr_node *a;
9255 : 80829042 : unsigned ix;
9256 : 80829042 : dw_die_ref abbrev;
9257 : :
9258 : : /* Scan the DIE references, and replace any that refer to
9259 : : DIEs from other CUs (i.e. those which are not marked) with
9260 : : the local stubs we built in optimize_external_refs. */
9261 : 399871652 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9262 : 319042610 : if (AT_class (a) == dw_val_class_die_ref
9263 : 319042610 : && (c = AT_ref (a))->die_mark == 0)
9264 : : {
9265 : 29052 : struct external_ref *ref_p;
9266 : 29052 : gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
9267 : :
9268 : 29052 : if (is_type_die (c)
9269 : 226 : && (ref_p = lookup_external_ref (extern_map, c))
9270 : 29278 : && ref_p->stub && ref_p->stub != die)
9271 : : {
9272 : 139 : gcc_assert (a->dw_attr != DW_AT_signature);
9273 : 139 : change_AT_die_ref (a, ref_p->stub);
9274 : : }
9275 : : else
9276 : : /* We aren't changing this reference, so mark it external. */
9277 : 28913 : set_AT_ref_external (a, 1);
9278 : : }
9279 : :
9280 : 8771760271 : FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
9281 : : {
9282 : 8769006485 : dw_attr_node *die_a, *abbrev_a;
9283 : 8769006485 : unsigned ix;
9284 : 8769006485 : bool ok = true;
9285 : :
9286 : 8769006485 : if (abbrev_id == 0)
9287 : 80829042 : continue;
9288 : 8688177443 : if (abbrev->die_tag != die->die_tag)
9289 : 8061840002 : continue;
9290 : 626337441 : if ((abbrev->die_child != NULL) != (die->die_child != NULL))
9291 : 41482233 : continue;
9292 : :
9293 : 1753517005 : if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
9294 : 440827139 : continue;
9295 : :
9296 : 598104592 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
9297 : : {
9298 : 520029336 : abbrev_a = &(*abbrev->die_attr)[ix];
9299 : 520029336 : if ((abbrev_a->dw_attr != die_a->dw_attr)
9300 : 520029336 : || (value_format (abbrev_a) != value_format (die_a)))
9301 : : {
9302 : : ok = false;
9303 : : break;
9304 : : }
9305 : : }
9306 : 144028069 : if (ok)
9307 : : break;
9308 : : }
9309 : :
9310 : 80829042 : if (abbrev_id >= vec_safe_length (abbrev_die_table))
9311 : : {
9312 : 2753786 : vec_safe_push (abbrev_die_table, die);
9313 : 2753786 : if (abbrev_opt_start)
9314 : 2753423 : abbrev_usage_count.safe_push (0);
9315 : : }
9316 : 80829042 : if (abbrev_opt_start && abbrev_id >= abbrev_opt_start)
9317 : : {
9318 : 80801776 : abbrev_usage_count[abbrev_id - abbrev_opt_start]++;
9319 : 80801776 : sorted_abbrev_dies.safe_push (die);
9320 : : }
9321 : :
9322 : 80829042 : die->die_abbrev = abbrev_id;
9323 : 139828606 : FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
9324 : 80829042 : }
9325 : :
9326 : : /* Callback function for sorted_abbrev_dies vector sorting. We sort
9327 : : by die_abbrev's usage count, from the most commonly used
9328 : : abbreviation to the least. */
9329 : :
9330 : : static int
9331 : 5060891939 : die_abbrev_cmp (const void *p1, const void *p2)
9332 : : {
9333 : 5060891939 : dw_die_ref die1 = *(const dw_die_ref *) p1;
9334 : 5060891939 : dw_die_ref die2 = *(const dw_die_ref *) p2;
9335 : :
9336 : 5060891939 : gcc_checking_assert (die1->die_abbrev >= abbrev_opt_start);
9337 : 5060891939 : gcc_checking_assert (die2->die_abbrev >= abbrev_opt_start);
9338 : :
9339 : 5060891939 : if (die1->die_abbrev >= abbrev_opt_base_type_end
9340 : 5060891939 : && die2->die_abbrev >= abbrev_opt_base_type_end)
9341 : : {
9342 : 5060891939 : if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
9343 : 5060891939 : > abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
9344 : : return -1;
9345 : 2831707981 : if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
9346 : 2831707981 : < abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
9347 : : return 1;
9348 : : }
9349 : :
9350 : : /* Stabilize the sort. */
9351 : 982849092 : if (die1->die_abbrev < die2->die_abbrev)
9352 : : return -1;
9353 : 842175694 : if (die1->die_abbrev > die2->die_abbrev)
9354 : 143808599 : return 1;
9355 : :
9356 : : return 0;
9357 : : }
9358 : :
9359 : : /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
9360 : : of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
9361 : : into dw_val_class_const_implicit or
9362 : : dw_val_class_unsigned_const_implicit. */
9363 : :
9364 : : static void
9365 : 2730706 : optimize_implicit_const (unsigned int first_id, unsigned int end,
9366 : : vec<bool> &implicit_consts)
9367 : : {
9368 : : /* It never makes sense if there is just one DIE using the abbreviation. */
9369 : 2730706 : if (end < first_id + 2)
9370 : 2730706 : return;
9371 : :
9372 : 1631928 : dw_attr_node *a;
9373 : 1631928 : unsigned ix, i;
9374 : 1631928 : dw_die_ref die = sorted_abbrev_dies[first_id];
9375 : 10455136 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9376 : 8823208 : if (implicit_consts[ix])
9377 : : {
9378 : 1118228 : enum dw_val_class new_class = dw_val_class_none;
9379 : 1118228 : switch (AT_class (a))
9380 : : {
9381 : 721656 : case dw_val_class_unsigned_const:
9382 : 721656 : if ((HOST_WIDE_INT) AT_unsigned (a) < 0)
9383 : 1688 : continue;
9384 : :
9385 : : /* The .debug_abbrev section will grow by
9386 : : size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
9387 : : in all the DIEs using that abbreviation. */
9388 : 719968 : if (constant_size (AT_unsigned (a)) * (end - first_id)
9389 : 719968 : <= (unsigned) size_of_sleb128 (AT_unsigned (a)))
9390 : 13023 : continue;
9391 : :
9392 : : new_class = dw_val_class_unsigned_const_implicit;
9393 : : break;
9394 : :
9395 : : case dw_val_class_const:
9396 : : new_class = dw_val_class_const_implicit;
9397 : : break;
9398 : :
9399 : 394630 : case dw_val_class_file:
9400 : 394630 : new_class = dw_val_class_file_implicit;
9401 : 394630 : break;
9402 : :
9403 : 0 : default:
9404 : 0 : continue;
9405 : : }
9406 : 13797644 : for (i = first_id; i < end; i++)
9407 : 12694127 : (*sorted_abbrev_dies[i]->die_attr)[ix].dw_attr_val.val_class
9408 : 25388254 : = new_class;
9409 : : }
9410 : : }
9411 : :
9412 : : /* Attempt to optimize abbreviation table from abbrev_opt_start
9413 : : abbreviation above. */
9414 : :
9415 : : static void
9416 : 52248 : optimize_abbrev_table (void)
9417 : : {
9418 : 52248 : if (abbrev_opt_start
9419 : 52248 : && vec_safe_length (abbrev_die_table) > abbrev_opt_start
9420 : 104426 : && (dwarf_version >= 5 || vec_safe_length (abbrev_die_table) > 127))
9421 : : {
9422 : 50208 : auto_vec<bool, 32> implicit_consts;
9423 : 50208 : sorted_abbrev_dies.qsort (die_abbrev_cmp);
9424 : :
9425 : 50208 : unsigned int abbrev_id = abbrev_opt_start - 1;
9426 : 50208 : unsigned int first_id = ~0U;
9427 : 50208 : unsigned int last_abbrev_id = 0;
9428 : 50208 : unsigned int i;
9429 : 50208 : dw_die_ref die;
9430 : 50208 : if (abbrev_opt_base_type_end > abbrev_opt_start)
9431 : 0 : abbrev_id = abbrev_opt_base_type_end - 1;
9432 : : /* Reassign abbreviation ids from abbrev_opt_start above, so that
9433 : : most commonly used abbreviations come first. */
9434 : 80800320 : FOR_EACH_VEC_ELT (sorted_abbrev_dies, i, die)
9435 : : {
9436 : 80750112 : dw_attr_node *a;
9437 : 80750112 : unsigned ix;
9438 : :
9439 : : /* If calc_base_type_die_sizes has been called, the CU and
9440 : : base types after it can't be optimized, because we've already
9441 : : calculated their DIE offsets. We've sorted them first. */
9442 : 80750112 : if (die->die_abbrev < abbrev_opt_base_type_end)
9443 : 0 : continue;
9444 : 80750112 : if (die->die_abbrev != last_abbrev_id)
9445 : : {
9446 : 2730706 : last_abbrev_id = die->die_abbrev;
9447 : 2730706 : if (dwarf_version >= 5 && first_id != ~0U)
9448 : 2680498 : optimize_implicit_const (first_id, i, implicit_consts);
9449 : 2730706 : abbrev_id++;
9450 : 2730706 : (*abbrev_die_table)[abbrev_id] = die;
9451 : 2730706 : if (dwarf_version >= 5)
9452 : : {
9453 : 2730706 : first_id = i;
9454 : 2730706 : implicit_consts.truncate (0);
9455 : :
9456 : 20742870 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9457 : 15281458 : switch (AT_class (a))
9458 : : {
9459 : 6451862 : case dw_val_class_const:
9460 : 6451862 : case dw_val_class_unsigned_const:
9461 : 6451862 : case dw_val_class_file:
9462 : 6451862 : implicit_consts.safe_push (true);
9463 : 6451862 : break;
9464 : 8829596 : default:
9465 : 8829596 : implicit_consts.safe_push (false);
9466 : 8829596 : break;
9467 : : }
9468 : : }
9469 : : }
9470 : 78019406 : else if (dwarf_version >= 5)
9471 : : {
9472 : 381442129 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9473 : 303422723 : if (!implicit_consts[ix])
9474 : 283098591 : continue;
9475 : : else
9476 : : {
9477 : 20324132 : dw_attr_node *other_a
9478 : 20324132 : = &(*(*abbrev_die_table)[abbrev_id]->die_attr)[ix];
9479 : 20324132 : if (!dw_val_equal_p (&a->dw_attr_val,
9480 : : &other_a->dw_attr_val))
9481 : 2579570 : implicit_consts[ix] = false;
9482 : : }
9483 : : }
9484 : 80750112 : die->die_abbrev = abbrev_id;
9485 : : }
9486 : 100416 : gcc_assert (abbrev_id == vec_safe_length (abbrev_die_table) - 1);
9487 : 50208 : if (dwarf_version >= 5 && first_id != ~0U)
9488 : 50208 : optimize_implicit_const (first_id, i, implicit_consts);
9489 : 50208 : }
9490 : :
9491 : 52248 : abbrev_opt_start = 0;
9492 : 52248 : abbrev_opt_base_type_end = 0;
9493 : 52248 : abbrev_usage_count.release ();
9494 : 52248 : sorted_abbrev_dies.release ();
9495 : 52248 : }
9496 : :
9497 : : /* Return the power-of-two number of bytes necessary to represent VALUE. */
9498 : :
9499 : : static int
9500 : 549392609 : constant_size (unsigned HOST_WIDE_INT value)
9501 : : {
9502 : 549392609 : int log;
9503 : :
9504 : 549392609 : if (value == 0)
9505 : : log = 0;
9506 : : else
9507 : 541732744 : log = floor_log2 (value);
9508 : :
9509 : 1091125353 : log = log / 8;
9510 : 541732744 : log = 1 << (floor_log2 (log) + 1);
9511 : :
9512 : 549392609 : return log;
9513 : : }
9514 : :
9515 : : /* Return the size of a DIE as it is represented in the
9516 : : .debug_info section. */
9517 : :
9518 : : static unsigned long
9519 : 80829309 : size_of_die (dw_die_ref die)
9520 : : {
9521 : 80829309 : unsigned long size = 0;
9522 : 80829309 : dw_attr_node *a;
9523 : 80829309 : unsigned ix;
9524 : 80829309 : enum dwarf_form form;
9525 : :
9526 : 80829309 : size += size_of_uleb128 (die->die_abbrev);
9527 : 399873750 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9528 : : {
9529 : 319044441 : switch (AT_class (a))
9530 : : {
9531 : 28374 : case dw_val_class_addr:
9532 : 28374 : if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
9533 : : {
9534 : 0 : gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
9535 : 0 : size += size_of_uleb128 (AT_index (a));
9536 : : }
9537 : : else
9538 : 31363 : size += DWARF2_ADDR_SIZE;
9539 : : break;
9540 : 0 : case dw_val_class_offset:
9541 : 0 : size += dwarf_offset_size;
9542 : 0 : break;
9543 : 7720099 : case dw_val_class_loc:
9544 : 7720099 : {
9545 : 7720099 : unsigned long lsize = size_of_locs (AT_loc (a));
9546 : :
9547 : : /* Block length. */
9548 : 7720099 : if (dwarf_version >= 4)
9549 : 7709195 : size += size_of_uleb128 (lsize);
9550 : : else
9551 : 10904 : size += constant_size (lsize);
9552 : 7720099 : size += lsize;
9553 : : }
9554 : 7720099 : break;
9555 : 11206203 : case dw_val_class_loc_list:
9556 : 11206203 : if (dwarf_split_debug_info && dwarf_version >= 5)
9557 : : {
9558 : 2 : gcc_assert (AT_loc_list (a)->num_assigned);
9559 : 2 : size += size_of_uleb128 (AT_loc_list (a)->hash);
9560 : : }
9561 : : else
9562 : 11206201 : size += dwarf_offset_size;
9563 : : break;
9564 : 11031296 : case dw_val_class_view_list:
9565 : 11031296 : size += dwarf_offset_size;
9566 : 11031296 : break;
9567 : 3179975 : case dw_val_class_range_list:
9568 : 3179975 : if (value_format (a) == DW_FORM_rnglistx)
9569 : : {
9570 : 3 : gcc_assert (rnglist_idx);
9571 : 3 : dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
9572 : 3 : size += size_of_uleb128 (r->idx);
9573 : : }
9574 : : else
9575 : 3179972 : size += dwarf_offset_size;
9576 : : break;
9577 : 14012 : case dw_val_class_const:
9578 : 14012 : size += size_of_sleb128 (AT_int (a));
9579 : 14012 : break;
9580 : 65186567 : case dw_val_class_unsigned_const:
9581 : 65186567 : {
9582 : 65186567 : int csize = constant_size (AT_unsigned (a));
9583 : 65186567 : if (dwarf_version == 3
9584 : 690 : && a->dw_attr == DW_AT_data_member_location
9585 : 15 : && csize >= 4)
9586 : 1 : size += size_of_uleb128 (AT_unsigned (a));
9587 : : else
9588 : 65186566 : size += csize;
9589 : : }
9590 : : break;
9591 : 6673950 : case dw_val_class_symview:
9592 : 6673950 : if (symview_upper_bound <= 0xff)
9593 : 359963 : size += 1;
9594 : 6313987 : else if (symview_upper_bound <= 0xffff)
9595 : 6313987 : size += 2;
9596 : 0 : else if (symview_upper_bound <= 0xffffffff)
9597 : 0 : size += 4;
9598 : : else
9599 : : size += 8;
9600 : : break;
9601 : : case dw_val_class_const_implicit:
9602 : : case dw_val_class_unsigned_const_implicit:
9603 : : case dw_val_class_file_implicit:
9604 : : /* These occupy no size in the DIE, just an extra sleb128 in
9605 : : .debug_abbrev. */
9606 : : break;
9607 : 0 : case dw_val_class_const_double:
9608 : 0 : size += HOST_BITS_PER_DOUBLE_INT / HOST_BITS_PER_CHAR;
9609 : 0 : if (HOST_BITS_PER_WIDE_INT >= DWARF_LARGEST_DATA_FORM_BITS)
9610 : 0 : size++; /* block */
9611 : : break;
9612 : 39 : case dw_val_class_wide_int:
9613 : 39 : size += (get_full_len (*a->dw_attr_val.v.val_wide)
9614 : 39 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
9615 : 39 : if (get_full_len (*a->dw_attr_val.v.val_wide)
9616 : 39 : * HOST_BITS_PER_WIDE_INT > DWARF_LARGEST_DATA_FORM_BITS)
9617 : 0 : size++; /* block */
9618 : : break;
9619 : 14933 : case dw_val_class_vec:
9620 : 14933 : size += constant_size (a->dw_attr_val.v.val_vec.length
9621 : 14933 : * a->dw_attr_val.v.val_vec.elt_size)
9622 : 14933 : + a->dw_attr_val.v.val_vec.length
9623 : : * a->dw_attr_val.v.val_vec.elt_size; /* block */
9624 : 14933 : break;
9625 : 27394148 : case dw_val_class_flag:
9626 : 27394148 : if (dwarf_version >= 4)
9627 : : /* Currently all add_AT_flag calls pass in 1 as last argument,
9628 : : so DW_FORM_flag_present can be used. If that ever changes,
9629 : : we'll need to use DW_FORM_flag and have some optimization
9630 : : in build_abbrev_table that will change those to
9631 : : DW_FORM_flag_present if it is set to 1 in all DIEs using
9632 : : the same abbrev entry. */
9633 : 27373008 : gcc_assert (a->dw_attr_val.v.val_flag == 1);
9634 : : else
9635 : 21140 : size += 1;
9636 : : break;
9637 : 94848534 : case dw_val_class_die_ref:
9638 : 94848534 : if (AT_ref_external (a))
9639 : : {
9640 : : /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
9641 : : we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
9642 : : is sized by target address length, whereas in DWARF3
9643 : : it's always sized as an offset. */
9644 : 28913 : if (AT_ref (a)->comdat_type_p)
9645 : 87 : size += DWARF_TYPE_SIGNATURE_SIZE;
9646 : 28826 : else if (dwarf_version == 2)
9647 : 30 : size += DWARF2_ADDR_SIZE;
9648 : : else
9649 : 28796 : size += dwarf_offset_size;
9650 : : }
9651 : : else
9652 : 94819621 : size += dwarf_offset_size;
9653 : : break;
9654 : 0 : case dw_val_class_fde_ref:
9655 : 0 : size += dwarf_offset_size;
9656 : 0 : break;
9657 : 14539893 : case dw_val_class_lbl_id:
9658 : 14539893 : if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
9659 : : {
9660 : 253 : gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
9661 : 253 : size += size_of_uleb128 (AT_index (a));
9662 : : }
9663 : : else
9664 : 15663303 : size += DWARF2_ADDR_SIZE;
9665 : : break;
9666 : 53109 : case dw_val_class_lineptr:
9667 : 53109 : case dw_val_class_macptr:
9668 : 53109 : case dw_val_class_loclistsptr:
9669 : 53109 : size += dwarf_offset_size;
9670 : 53109 : break;
9671 : 33228186 : case dw_val_class_str:
9672 : 33228186 : form = AT_string_form (a);
9673 : 33228186 : if (form == DW_FORM_strp || form == DW_FORM_line_strp)
9674 : 30154738 : size += dwarf_offset_size;
9675 : 3087648 : else if (form == dwarf_FORM (DW_FORM_strx))
9676 : 935 : size += size_of_uleb128 (AT_index (a));
9677 : : else
9678 : 3072513 : size += strlen (a->dw_attr_val.v.val_str->str) + 1;
9679 : : break;
9680 : 26293445 : case dw_val_class_file:
9681 : 26293445 : size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
9682 : 26293445 : break;
9683 : 71 : case dw_val_class_data8:
9684 : 71 : size += 8;
9685 : 71 : break;
9686 : 0 : case dw_val_class_vms_delta:
9687 : 0 : size += dwarf_offset_size;
9688 : 0 : break;
9689 : 4929347 : case dw_val_class_high_pc:
9690 : 4929347 : size += DWARF2_ADDR_SIZE;
9691 : 4929347 : break;
9692 : 0 : case dw_val_class_discr_value:
9693 : 0 : size += size_of_discr_value (&a->dw_attr_val.v.val_discr_value);
9694 : 0 : break;
9695 : 0 : case dw_val_class_discr_list:
9696 : 0 : {
9697 : 0 : unsigned block_size = size_of_discr_list (AT_discr_list (a));
9698 : :
9699 : : /* This is a block, so we have the block length and then its
9700 : : data. */
9701 : 0 : size += constant_size (block_size) + block_size;
9702 : : }
9703 : 0 : break;
9704 : 0 : default:
9705 : 0 : gcc_unreachable ();
9706 : : }
9707 : : }
9708 : :
9709 : 80829309 : return size;
9710 : : }
9711 : :
9712 : : /* Size the debugging information associated with a given DIE. Visits the
9713 : : DIE's children recursively. Updates the global variable next_die_offset, on
9714 : : each time through. Uses the current value of next_die_offset to update the
9715 : : die_offset field in each DIE. */
9716 : :
9717 : : static void
9718 : 80829042 : calc_die_sizes (dw_die_ref die)
9719 : : {
9720 : 80829042 : dw_die_ref c;
9721 : :
9722 : 80829042 : gcc_assert (die->die_offset == 0
9723 : : || (unsigned long int) die->die_offset == next_die_offset);
9724 : 80829042 : die->die_offset = next_die_offset;
9725 : 80829042 : next_die_offset += size_of_die (die);
9726 : :
9727 : 161605756 : FOR_EACH_CHILD (die, c, calc_die_sizes (c));
9728 : :
9729 : 80829042 : if (die->die_child != NULL)
9730 : : /* Count the null byte used to terminate sibling lists. */
9731 : 21777150 : next_die_offset += 1;
9732 : 80829042 : }
9733 : :
9734 : : /* Size just the base type children at the start of the CU.
9735 : : This is needed because build_abbrev needs to size locs
9736 : : and sizing of type based stack ops needs to know die_offset
9737 : : values for the base types. */
9738 : :
9739 : : static void
9740 : 9 : calc_base_type_die_sizes (void)
9741 : : {
9742 : 18 : unsigned long die_offset = (dwarf_split_debug_info
9743 : 9 : ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
9744 : 18 : : DWARF_COMPILE_UNIT_HEADER_SIZE);
9745 : 9 : unsigned int i;
9746 : 9 : dw_die_ref base_type;
9747 : : #if ENABLE_ASSERT_CHECKING
9748 : 9 : dw_die_ref prev = comp_unit_die ()->die_child;
9749 : : #endif
9750 : :
9751 : 9 : die_offset += size_of_die (comp_unit_die ());
9752 : 18 : for (i = 0; base_types.iterate (i, &base_type); i++)
9753 : : {
9754 : : #if ENABLE_ASSERT_CHECKING
9755 : 9 : gcc_assert (base_type->die_offset == 0
9756 : : && prev->die_sib == base_type
9757 : : && base_type->die_child == NULL
9758 : : && base_type->die_abbrev);
9759 : 9 : prev = base_type;
9760 : : #endif
9761 : 9 : if (abbrev_opt_start
9762 : 9 : && base_type->die_abbrev >= abbrev_opt_base_type_end)
9763 : 9 : abbrev_opt_base_type_end = base_type->die_abbrev + 1;
9764 : 9 : base_type->die_offset = die_offset;
9765 : 9 : die_offset += size_of_die (base_type);
9766 : : }
9767 : 9 : }
9768 : :
9769 : : /* Set the marks for a die and its children. We do this so
9770 : : that we know whether or not a reference needs to use FORM_ref_addr; only
9771 : : DIEs in the same CU will be marked. We used to clear out the offset
9772 : : and use that as the flag, but ran into ordering problems. */
9773 : :
9774 : : static void
9775 : 80830697 : mark_dies (dw_die_ref die)
9776 : : {
9777 : 80830697 : dw_die_ref c;
9778 : :
9779 : 80830697 : gcc_assert (!die->die_mark);
9780 : :
9781 : 80830697 : die->die_mark = 1;
9782 : 161608807 : FOR_EACH_CHILD (die, c, mark_dies (c));
9783 : 80830697 : }
9784 : :
9785 : : /* Clear the marks for a die and its children. */
9786 : :
9787 : : static void
9788 : 228467 : unmark_dies (dw_die_ref die)
9789 : : {
9790 : 228467 : dw_die_ref c;
9791 : :
9792 : 228467 : if (! use_debug_types)
9793 : 226093 : gcc_assert (die->die_mark);
9794 : :
9795 : 228467 : die->die_mark = 0;
9796 : 455416 : FOR_EACH_CHILD (die, c, unmark_dies (c));
9797 : 228467 : }
9798 : :
9799 : : /* Clear the marks for a die, its children and referred dies. */
9800 : :
9801 : : static void
9802 : 511883 : unmark_all_dies (dw_die_ref die)
9803 : : {
9804 : 511883 : dw_die_ref c;
9805 : 511883 : dw_attr_node *a;
9806 : 511883 : unsigned ix;
9807 : :
9808 : 511883 : if (!die->die_mark)
9809 : 511883 : return;
9810 : 227200 : die->die_mark = 0;
9811 : :
9812 : 394384 : FOR_EACH_CHILD (die, c, unmark_all_dies (c));
9813 : :
9814 : 1119861 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
9815 : 892661 : if (AT_class (a) == dw_val_class_die_ref)
9816 : 284672 : unmark_all_dies (AT_ref (a));
9817 : : }
9818 : :
9819 : : /* Calculate if the entry should appear in the final output file. It may be
9820 : : from a pruned a type. */
9821 : :
9822 : : static bool
9823 : 1724 : include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
9824 : : {
9825 : : /* By limiting gnu pubnames to definitions only, gold can generate a
9826 : : gdb index without entries for declarations, which don't include
9827 : : enough information to be useful. */
9828 : 1724 : if (debug_generate_pub_sections == 2 && is_declaration_die (p->die))
9829 : : return false;
9830 : :
9831 : 1594 : if (table == pubname_table)
9832 : : {
9833 : : /* Enumerator names are part of the pubname table, but the
9834 : : parent DW_TAG_enumeration_type die may have been pruned.
9835 : : Don't output them if that is the case. */
9836 : 1014 : if (p->die->die_tag == DW_TAG_enumerator &&
9837 : 72 : (p->die->die_parent == NULL
9838 : 72 : || !p->die->die_parent->die_perennial_p))
9839 : : return false;
9840 : :
9841 : : /* Everything else in the pubname table is included. */
9842 : : return true;
9843 : : }
9844 : :
9845 : : /* The pubtypes table shouldn't include types that have been
9846 : : pruned. */
9847 : 580 : return (p->die->die_offset != 0
9848 : 580 : || !flag_eliminate_unused_debug_types);
9849 : : }
9850 : :
9851 : : /* Return the size of the .debug_pubnames or .debug_pubtypes table
9852 : : generated for the compilation unit. */
9853 : :
9854 : : static unsigned long
9855 : 512 : size_of_pubnames (vec<pubname_entry, va_gc> *names)
9856 : : {
9857 : 512 : unsigned long size;
9858 : 512 : unsigned i;
9859 : 512 : pubname_entry *p;
9860 : 512 : int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0;
9861 : :
9862 : 512 : size = DWARF_PUBNAMES_HEADER_SIZE;
9863 : 1374 : FOR_EACH_VEC_ELT (*names, i, p)
9864 : 862 : if (include_pubname_in_output (names, p))
9865 : 791 : size += strlen (p->name) + dwarf_offset_size + 1 + space_for_flags;
9866 : :
9867 : 512 : size += dwarf_offset_size;
9868 : 512 : return size;
9869 : : }
9870 : :
9871 : : /* Return the size of the information in the .debug_aranges section. */
9872 : :
9873 : : static unsigned long
9874 : 50925 : size_of_aranges (void)
9875 : : {
9876 : 50925 : unsigned long size;
9877 : :
9878 : 63487 : size = DWARF_ARANGES_HEADER_SIZE;
9879 : :
9880 : : /* Count the address/length pair for this compilation unit. */
9881 : 50925 : if (switch_text_ranges)
9882 : 32102 : size += 2 * DWARF2_ADDR_SIZE
9883 : 29083 : * (vec_safe_length (switch_text_ranges) / 2 + 1);
9884 : 50925 : if (switch_cold_ranges)
9885 : 8927 : size += 2 * DWARF2_ADDR_SIZE
9886 : 8633 : * (vec_safe_length (switch_cold_ranges) / 2 + 1);
9887 : 50925 : if (have_multiple_function_sections)
9888 : : {
9889 : : unsigned fde_idx;
9890 : : dw_fde_ref fde;
9891 : :
9892 : 290201 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
9893 : : {
9894 : 262273 : if (fde->ignored_debug)
9895 : 2882 : continue;
9896 : 259391 : if (!fde->in_std_section)
9897 : 200230 : size += 2 * DWARF2_ADDR_SIZE;
9898 : 259391 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
9899 : 9640 : size += 2 * DWARF2_ADDR_SIZE;
9900 : : }
9901 : : }
9902 : :
9903 : : /* Count the two zero words used to terminated the address range table. */
9904 : 50925 : size += 2 * DWARF2_ADDR_SIZE;
9905 : 50925 : return size;
9906 : : }
9907 : :
9908 : : /* Select the encoding of an attribute value. */
9909 : :
9910 : : static enum dwarf_form
9911 : 1009995459 : value_format (dw_attr_node *a)
9912 : : {
9913 : 1009995459 : switch (AT_class (a))
9914 : : {
9915 : 57388 : case dw_val_class_addr:
9916 : : /* Only very few attributes allow DW_FORM_addr. */
9917 : 57388 : switch (a->dw_attr)
9918 : : {
9919 : 57388 : case DW_AT_low_pc:
9920 : 57388 : case DW_AT_high_pc:
9921 : 57388 : case DW_AT_entry_pc:
9922 : 57388 : case DW_AT_trampoline:
9923 : 57388 : return (AT_index (a) == NOT_INDEXED
9924 : 57388 : ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
9925 : 0 : default:
9926 : 0 : break;
9927 : : }
9928 : 0 : switch (DWARF2_ADDR_SIZE)
9929 : : {
9930 : : case 1:
9931 : : return DW_FORM_data1;
9932 : : case 2:
9933 : : return DW_FORM_data2;
9934 : : case 4:
9935 : : return DW_FORM_data4;
9936 : : case 8:
9937 : : return DW_FORM_data8;
9938 : : default:
9939 : : gcc_unreachable ();
9940 : : }
9941 : 22417057 : case dw_val_class_loc_list:
9942 : 22417057 : if (dwarf_split_debug_info
9943 : 4 : && dwarf_version >= 5
9944 : 22417061 : && AT_loc_list (a)->num_assigned)
9945 : : return DW_FORM_loclistx;
9946 : : /* FALLTHRU */
9947 : 55598978 : case dw_val_class_view_list:
9948 : 55598978 : case dw_val_class_range_list:
9949 : : /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
9950 : : but in .debug_info use DW_FORM_sec_offset, which is shorter if we
9951 : : care about sizes of .debug* sections in shared libraries and
9952 : : executables and don't take into account relocations that affect just
9953 : : relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
9954 : : table in the .debug_rnglists section. */
9955 : 55598978 : if (dwarf_split_debug_info
9956 : 19 : && dwarf_version >= 5
9957 : 19 : && AT_class (a) == dw_val_class_range_list
9958 : 15 : && rnglist_idx
9959 : 55598993 : && a->dw_attr_val.val_entry != RELOCATED_OFFSET)
9960 : : return DW_FORM_rnglistx;
9961 : 55598969 : if (dwarf_version >= 4)
9962 : : return DW_FORM_sec_offset;
9963 : : /* FALLTHRU */
9964 : 18013 : case dw_val_class_vms_delta:
9965 : 18013 : case dw_val_class_offset:
9966 : 18013 : switch (dwarf_offset_size)
9967 : : {
9968 : : case 4:
9969 : : return DW_FORM_data4;
9970 : : case 8:
9971 : : return DW_FORM_data8;
9972 : 0 : default:
9973 : 0 : gcc_unreachable ();
9974 : : }
9975 : 15487320 : case dw_val_class_loc:
9976 : 15487320 : if (dwarf_version >= 4)
9977 : : return DW_FORM_exprloc;
9978 : 21981 : switch (constant_size (size_of_locs (AT_loc (a))))
9979 : : {
9980 : : case 1:
9981 : : return DW_FORM_block1;
9982 : : case 2:
9983 : : return DW_FORM_block2;
9984 : : case 4:
9985 : : return DW_FORM_block4;
9986 : 0 : default:
9987 : 0 : gcc_unreachable ();
9988 : : }
9989 : : case dw_val_class_const:
9990 : : return DW_FORM_sdata;
9991 : 237546792 : case dw_val_class_unsigned_const:
9992 : 237546792 : switch (constant_size (AT_unsigned (a)))
9993 : : {
9994 : : case 1:
9995 : : return DW_FORM_data1;
9996 : : case 2:
9997 : : return DW_FORM_data2;
9998 : 227008 : case 4:
9999 : : /* In DWARF3 DW_AT_data_member_location with
10000 : : DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
10001 : : constant, so we need to use DW_FORM_udata if we need
10002 : : a large constant. */
10003 : 227008 : if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
10004 : : return DW_FORM_udata;
10005 : : return DW_FORM_data4;
10006 : 65156 : case 8:
10007 : 65156 : if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
10008 : : return DW_FORM_udata;
10009 : : return DW_FORM_data8;
10010 : 0 : default:
10011 : 0 : gcc_unreachable ();
10012 : : }
10013 : : case dw_val_class_const_implicit:
10014 : : case dw_val_class_unsigned_const_implicit:
10015 : : case dw_val_class_file_implicit:
10016 : : return DW_FORM_implicit_const;
10017 : 0 : case dw_val_class_const_double:
10018 : 0 : switch (HOST_BITS_PER_WIDE_INT)
10019 : : {
10020 : : case 8:
10021 : : return DW_FORM_data2;
10022 : : case 16:
10023 : : return DW_FORM_data4;
10024 : : case 32:
10025 : : return DW_FORM_data8;
10026 : 0 : case 64:
10027 : 0 : if (dwarf_version >= 5)
10028 : : return DW_FORM_data16;
10029 : : /* FALLTHRU */
10030 : : default:
10031 : : return DW_FORM_block1;
10032 : : }
10033 : 86 : case dw_val_class_wide_int:
10034 : 86 : switch (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT)
10035 : : {
10036 : : case 8:
10037 : : return DW_FORM_data1;
10038 : : case 16:
10039 : : return DW_FORM_data2;
10040 : : case 32:
10041 : : return DW_FORM_data4;
10042 : : case 64:
10043 : : return DW_FORM_data8;
10044 : 86 : case 128:
10045 : 86 : if (dwarf_version >= 5)
10046 : : return DW_FORM_data16;
10047 : : /* FALLTHRU */
10048 : : default:
10049 : : return DW_FORM_block1;
10050 : : }
10051 : 24367640 : case dw_val_class_symview:
10052 : : /* ??? We might use uleb128, but then we'd have to compute
10053 : : .debug_info offsets in the assembler. */
10054 : 24367640 : if (symview_upper_bound <= 0xff)
10055 : : return DW_FORM_data1;
10056 : 23115498 : else if (symview_upper_bound <= 0xffff)
10057 : : return DW_FORM_data2;
10058 : : else if (symview_upper_bound <= 0xffffffff)
10059 : : return DW_FORM_data4;
10060 : : else
10061 : : return DW_FORM_data8;
10062 : 46102 : case dw_val_class_vec:
10063 : 46102 : switch (constant_size (a->dw_attr_val.v.val_vec.length
10064 : 46102 : * a->dw_attr_val.v.val_vec.elt_size))
10065 : : {
10066 : : case 1:
10067 : : return DW_FORM_block1;
10068 : : case 2:
10069 : : return DW_FORM_block2;
10070 : : case 4:
10071 : : return DW_FORM_block4;
10072 : 0 : default:
10073 : 0 : gcc_unreachable ();
10074 : : }
10075 : 120275008 : case dw_val_class_flag:
10076 : 120275008 : if (dwarf_version >= 4)
10077 : : {
10078 : : /* Currently all add_AT_flag calls pass in 1 as last argument,
10079 : : so DW_FORM_flag_present can be used. If that ever changes,
10080 : : we'll need to use DW_FORM_flag and have some optimization
10081 : : in build_abbrev_table that will change those to
10082 : : DW_FORM_flag_present if it is set to 1 in all DIEs using
10083 : : the same abbrev entry. */
10084 : 120228626 : gcc_assert (a->dw_attr_val.v.val_flag == 1);
10085 : : return DW_FORM_flag_present;
10086 : : }
10087 : : return DW_FORM_flag;
10088 : 204358156 : case dw_val_class_die_ref:
10089 : 204358156 : if (AT_ref_external (a))
10090 : : {
10091 : 67381 : if (AT_ref (a)->comdat_type_p)
10092 : : return DW_FORM_ref_sig8;
10093 : : else
10094 : 67202 : return DW_FORM_ref_addr;
10095 : : }
10096 : : else
10097 : 408581550 : return DW_FORM_ref;
10098 : 0 : case dw_val_class_fde_ref:
10099 : 0 : return DW_FORM_data;
10100 : 43750652 : case dw_val_class_lbl_id:
10101 : 43750652 : return (AT_index (a) == NOT_INDEXED
10102 : 43750652 : ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
10103 : 107266 : case dw_val_class_lineptr:
10104 : 107266 : case dw_val_class_macptr:
10105 : 107266 : case dw_val_class_loclistsptr:
10106 : 107266 : return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
10107 : 164885764 : case dw_val_class_str:
10108 : 164885764 : return AT_string_form (a);
10109 : 128046095 : case dw_val_class_file:
10110 : 128046095 : switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
10111 : : {
10112 : : case 1:
10113 : : return DW_FORM_data1;
10114 : : case 2:
10115 : : return DW_FORM_data2;
10116 : : case 4:
10117 : : return DW_FORM_data4;
10118 : 0 : default:
10119 : 0 : gcc_unreachable ();
10120 : : }
10121 : :
10122 : : case dw_val_class_data8:
10123 : : return DW_FORM_data8;
10124 : :
10125 : 13152656 : case dw_val_class_high_pc:
10126 : 13152656 : switch (DWARF2_ADDR_SIZE)
10127 : : {
10128 : : case 1:
10129 : : return DW_FORM_data1;
10130 : : case 2:
10131 : : return DW_FORM_data2;
10132 : : case 4:
10133 : : return DW_FORM_data4;
10134 : : case 8:
10135 : : return DW_FORM_data8;
10136 : : default:
10137 : : gcc_unreachable ();
10138 : : }
10139 : :
10140 : 0 : case dw_val_class_discr_value:
10141 : 0 : return (a->dw_attr_val.v.val_discr_value.pos
10142 : 0 : ? DW_FORM_udata
10143 : : : DW_FORM_sdata);
10144 : 0 : case dw_val_class_discr_list:
10145 : 0 : switch (constant_size (size_of_discr_list (AT_discr_list (a))))
10146 : : {
10147 : : case 1:
10148 : : return DW_FORM_block1;
10149 : : case 2:
10150 : : return DW_FORM_block2;
10151 : : case 4:
10152 : : return DW_FORM_block4;
10153 : 0 : default:
10154 : 0 : gcc_unreachable ();
10155 : : }
10156 : :
10157 : 0 : default:
10158 : 0 : gcc_unreachable ();
10159 : : }
10160 : : }
10161 : :
10162 : : /* Output the encoding of an attribute value. */
10163 : :
10164 : : static void
10165 : 15439200 : output_value_format (dw_attr_node *a)
10166 : : {
10167 : 15439200 : enum dwarf_form form = value_format (a);
10168 : :
10169 : 30878400 : dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
10170 : 15439200 : }
10171 : :
10172 : : /* Given a die and id, produce the appropriate abbreviations. */
10173 : :
10174 : : static void
10175 : 2761237 : output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
10176 : : {
10177 : 2761237 : unsigned ix;
10178 : 2761237 : dw_attr_node *a_attr;
10179 : :
10180 : 2761237 : dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
10181 : 2761237 : dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
10182 : 2761237 : dwarf_tag_name (abbrev->die_tag));
10183 : :
10184 : 2761237 : if (abbrev->die_child != NULL)
10185 : 1312851 : dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
10186 : : else
10187 : 1448386 : dw2_asm_output_data (1, DW_children_no, "DW_children_no");
10188 : :
10189 : 18200437 : for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
10190 : : {
10191 : 15439200 : dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
10192 : 15439200 : dwarf_attr_name (a_attr->dw_attr));
10193 : 15439200 : output_value_format (a_attr);
10194 : 15439200 : if (value_format (a_attr) == DW_FORM_implicit_const)
10195 : : {
10196 : 1105885 : if (AT_class (a_attr) == dw_val_class_file_implicit)
10197 : : {
10198 : 395962 : int f = maybe_emit_file (a_attr->dw_attr_val.v.val_file);
10199 : 395962 : const char *filename = a_attr->dw_attr_val.v.val_file->filename;
10200 : 395962 : dw2_asm_output_data_sleb128 (f, "(%s)", filename);
10201 : : }
10202 : : else
10203 : 709923 : dw2_asm_output_data_sleb128 (a_attr->dw_attr_val.v.val_int, NULL);
10204 : : }
10205 : : }
10206 : :
10207 : 2761237 : dw2_asm_output_data (1, 0, NULL);
10208 : 2761237 : dw2_asm_output_data (1, 0, NULL);
10209 : 2761237 : }
10210 : :
10211 : :
10212 : : /* Output the .debug_abbrev section which defines the DIE abbreviation
10213 : : table. */
10214 : :
10215 : : static void
10216 : 52250 : output_abbrev_section (void)
10217 : : {
10218 : 52250 : unsigned int abbrev_id;
10219 : 52250 : dw_die_ref abbrev;
10220 : :
10221 : 2865488 : FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
10222 : 2813238 : if (abbrev_id != 0)
10223 : 2760988 : output_die_abbrevs (abbrev_id, abbrev);
10224 : :
10225 : : /* Terminate the table. */
10226 : 52250 : dw2_asm_output_data (1, 0, NULL);
10227 : 52250 : }
10228 : :
10229 : : /* Return a new location list, given the begin and end range, and the
10230 : : expression. */
10231 : :
10232 : : static inline dw_loc_list_ref
10233 : 25689802 : new_loc_list (dw_loc_descr_ref expr, const char *begin, var_loc_view vbegin,
10234 : : const char *end, var_loc_view vend,
10235 : : const char *section)
10236 : : {
10237 : 51379604 : dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
10238 : :
10239 : 25689802 : retlist->begin = begin;
10240 : 25689802 : retlist->begin_entry = NULL;
10241 : 25689802 : retlist->end = end;
10242 : 25689802 : retlist->end_entry = NULL;
10243 : 25689802 : retlist->expr = expr;
10244 : 25689802 : retlist->section = section;
10245 : 25689802 : retlist->vbegin = vbegin;
10246 : 25689802 : retlist->vend = vend;
10247 : :
10248 : 25689802 : return retlist;
10249 : : }
10250 : :
10251 : : /* Return true iff there's any nonzero view number in the loc list.
10252 : :
10253 : : ??? When views are not enabled, we'll often extend a single range
10254 : : to the entire function, so that we emit a single location
10255 : : expression rather than a location list. With views, even with a
10256 : : single range, we'll output a list if start or end have a nonzero
10257 : : view. If we change this, we may want to stop splitting a single
10258 : : range in dw_loc_list just because of a nonzero view, even if it
10259 : : straddles across hot/cold partitions. */
10260 : :
10261 : : static bool
10262 : 23259710 : loc_list_has_views (dw_loc_list_ref list)
10263 : : {
10264 : 23259710 : if (!debug_variable_location_views)
10265 : : return false;
10266 : :
10267 : 1403102 : for (dw_loc_list_ref loc = list;
10268 : 24658716 : loc != NULL; loc = loc->dw_loc_next)
10269 : 23971868 : if (!ZERO_VIEW_P (loc->vbegin) || !ZERO_VIEW_P (loc->vend))
10270 : 22568766 : return true;
10271 : :
10272 : : return false;
10273 : : }
10274 : :
10275 : : /* Generate a new internal symbol for this location list node, if it
10276 : : hasn't got one yet. */
10277 : :
10278 : : static inline void
10279 : 11790763 : gen_llsym (dw_loc_list_ref list)
10280 : : {
10281 : 11790763 : gcc_assert (!list->ll_symbol);
10282 : 11790763 : list->ll_symbol = gen_internal_sym ("LLST");
10283 : :
10284 : 11790763 : if (!loc_list_has_views (list))
10285 : : return;
10286 : :
10287 : 11616701 : if (dwarf2out_locviews_in_attribute ())
10288 : : {
10289 : : /* Use the same label_num for the view list. */
10290 : 11616701 : label_num--;
10291 : 11616701 : list->vl_symbol = gen_internal_sym ("LVUS");
10292 : : }
10293 : : else
10294 : 0 : list->vl_symbol = list->ll_symbol;
10295 : : }
10296 : :
10297 : : /* Generate a symbol for the list, but only if we really want to emit
10298 : : it as a list. */
10299 : :
10300 : : static inline void
10301 : 1242267 : maybe_gen_llsym (dw_loc_list_ref list)
10302 : : {
10303 : 1242267 : if (!list || (!list->dw_loc_next && !loc_list_has_views (list)))
10304 : 1195319 : return;
10305 : :
10306 : 46948 : gen_llsym (list);
10307 : : }
10308 : :
10309 : : /* Determine whether or not to skip loc_list entry CURR. If SIZEP is
10310 : : NULL, don't consider size of the location expression. If we're not
10311 : : to skip it, and SIZEP is non-null, store the size of CURR->expr's
10312 : : representation in *SIZEP. */
10313 : :
10314 : : static bool
10315 : 46689573 : skip_loc_list_entry (dw_loc_list_ref curr, unsigned long *sizep = NULL)
10316 : : {
10317 : : /* Don't output an entry that starts and ends at the same address. */
10318 : 46689573 : if (strcmp (curr->begin, curr->end) == 0
10319 : 6684299 : && curr->vbegin == curr->vend && !curr->force)
10320 : : return true;
10321 : :
10322 : 46689552 : if (!sizep)
10323 : : return false;
10324 : :
10325 : 46689548 : unsigned long size = size_of_locs (curr->expr);
10326 : :
10327 : : /* If the expression is too large, drop it on the floor. We could
10328 : : perhaps put it into DW_TAG_dwarf_procedure and refer to that
10329 : : in the expression, but >= 64KB expressions for a single value
10330 : : in a single range are unlikely very useful. */
10331 : 46689548 : if (dwarf_version < 5 && size > 0xffff)
10332 : : return true;
10333 : :
10334 : 46689548 : *sizep = size;
10335 : :
10336 : 46689548 : return false;
10337 : : }
10338 : :
10339 : : /* Output a view pair loclist entry for CURR, if it requires one. */
10340 : :
10341 : : static void
10342 : 23598209 : dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr)
10343 : : {
10344 : 23598209 : if (!dwarf2out_locviews_in_loclist ())
10345 : : return;
10346 : :
10347 : 0 : if (ZERO_VIEW_P (curr->vbegin) && ZERO_VIEW_P (curr->vend))
10348 : 0 : return;
10349 : :
10350 : : #ifdef DW_LLE_view_pair
10351 : 0 : dw2_asm_output_data (1, DW_LLE_view_pair, "DW_LLE_view_pair");
10352 : :
10353 : 0 : if (dwarf2out_as_locview_support)
10354 : : {
10355 : 0 : if (ZERO_VIEW_P (curr->vbegin))
10356 : 0 : dw2_asm_output_data_uleb128 (0, "Location view begin");
10357 : : else
10358 : : {
10359 : 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
10360 : 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vbegin);
10361 : 0 : dw2_asm_output_symname_uleb128 (label, "Location view begin");
10362 : : }
10363 : :
10364 : 0 : if (ZERO_VIEW_P (curr->vend))
10365 : 0 : dw2_asm_output_data_uleb128 (0, "Location view end");
10366 : : else
10367 : : {
10368 : 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
10369 : 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vend);
10370 : 0 : dw2_asm_output_symname_uleb128 (label, "Location view end");
10371 : : }
10372 : : }
10373 : : else
10374 : : {
10375 : 0 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
10376 : 0 : ? 0 : curr->vbegin, "Location view begin");
10377 : 0 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
10378 : 0 : ? 0 : curr->vend, "Location view end");
10379 : : }
10380 : : #endif /* DW_LLE_view_pair */
10381 : :
10382 : : return;
10383 : : }
10384 : :
10385 : : /* Output the location list given to us. */
10386 : :
10387 : : static void
10388 : 11206203 : output_loc_list (dw_loc_list_ref list_head)
10389 : : {
10390 : 11206203 : int vcount = 0, lcount = 0;
10391 : :
10392 : 11206203 : if (list_head->emitted)
10393 : : return;
10394 : 11084912 : list_head->emitted = true;
10395 : :
10396 : 11084912 : if (list_head->vl_symbol && dwarf2out_locviews_in_attribute ())
10397 : : {
10398 : 10910870 : ASM_OUTPUT_LABEL (asm_out_file, list_head->vl_symbol);
10399 : :
10400 : 33988676 : for (dw_loc_list_ref curr = list_head; curr != NULL;
10401 : 23077806 : curr = curr->dw_loc_next)
10402 : : {
10403 : 23077806 : unsigned long size;
10404 : :
10405 : 23077806 : if (skip_loc_list_entry (curr, &size))
10406 : 0 : continue;
10407 : :
10408 : 23077806 : vcount++;
10409 : :
10410 : : /* ?? dwarf_split_debug_info? */
10411 : 23077806 : if (dwarf2out_as_locview_support)
10412 : : {
10413 : 23076716 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
10414 : :
10415 : 23076716 : if (!ZERO_VIEW_P (curr->vbegin))
10416 : : {
10417 : 22503032 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vbegin);
10418 : 22503032 : dw2_asm_output_symname_uleb128 (label,
10419 : : "View list begin (%s)",
10420 : : list_head->vl_symbol);
10421 : : }
10422 : : else
10423 : 573684 : dw2_asm_output_data_uleb128 (0,
10424 : : "View list begin (%s)",
10425 : : list_head->vl_symbol);
10426 : :
10427 : 23076716 : if (!ZERO_VIEW_P (curr->vend))
10428 : : {
10429 : 22080859 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vend);
10430 : 22080859 : dw2_asm_output_symname_uleb128 (label,
10431 : : "View list end (%s)",
10432 : : list_head->vl_symbol);
10433 : : }
10434 : : else
10435 : 995857 : dw2_asm_output_data_uleb128 (0,
10436 : : "View list end (%s)",
10437 : : list_head->vl_symbol);
10438 : : }
10439 : : else
10440 : : {
10441 : 2180 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
10442 : 1051 : ? 0 : curr->vbegin,
10443 : : "View list begin (%s)",
10444 : : list_head->vl_symbol);
10445 : 2180 : dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
10446 : 1043 : ? 0 : curr->vend,
10447 : : "View list end (%s)",
10448 : : list_head->vl_symbol);
10449 : : }
10450 : : }
10451 : : }
10452 : :
10453 : 11084912 : ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
10454 : :
10455 : 11084912 : const char *last_section = NULL;
10456 : 11084912 : const char *base_label = NULL;
10457 : :
10458 : : /* Walk the location list, and output each range + expression. */
10459 : 34696675 : for (dw_loc_list_ref curr = list_head; curr != NULL;
10460 : 23611763 : curr = curr->dw_loc_next)
10461 : : {
10462 : 23611763 : unsigned long size;
10463 : :
10464 : : /* Skip this entry? If we skip it here, we must skip it in the
10465 : : view list above as well. */
10466 : 23611763 : if (skip_loc_list_entry (curr, &size))
10467 : 21 : continue;
10468 : :
10469 : 23611742 : lcount++;
10470 : :
10471 : 23611742 : if (dwarf_version >= 5)
10472 : : {
10473 : 23598209 : if (dwarf_split_debug_info && HAVE_AS_LEB128)
10474 : : {
10475 : 4 : dwarf2out_maybe_output_loclist_view_pair (curr);
10476 : : /* For -gsplit-dwarf, emit DW_LLE_startx_length, which has
10477 : : uleb128 index into .debug_addr and uleb128 length. */
10478 : 4 : dw2_asm_output_data (1, DW_LLE_startx_length,
10479 : : "DW_LLE_startx_length (%s)",
10480 : : list_head->ll_symbol);
10481 : 4 : dw2_asm_output_data_uleb128 (curr->begin_entry->index,
10482 : : "Location list range start index "
10483 : : "(%s)", curr->begin);
10484 : 4 : dw2_asm_output_delta_uleb128 (curr->end, curr->begin,
10485 : : "Location list length (%s)",
10486 : : list_head->ll_symbol);
10487 : : }
10488 : 23598205 : else if (dwarf_split_debug_info)
10489 : : {
10490 : : dwarf2out_maybe_output_loclist_view_pair (curr);
10491 : : /* For -gsplit-dwarf without usable .uleb128 support, emit
10492 : : DW_LLE_startx_endx, which has two uleb128 indexes into
10493 : : .debug_addr. */
10494 : : dw2_asm_output_data (1, DW_LLE_startx_endx,
10495 : : "DW_LLE_startx_endx (%s)",
10496 : : list_head->ll_symbol);
10497 : : dw2_asm_output_data_uleb128 (curr->begin_entry->index,
10498 : : "Location list range start index "
10499 : : "(%s)", curr->begin);
10500 : : dw2_asm_output_data_uleb128 (curr->end_entry->index,
10501 : : "Location list range end index "
10502 : : "(%s)", curr->end);
10503 : : }
10504 : 23598205 : else if (!have_multiple_function_sections && HAVE_AS_LEB128)
10505 : : {
10506 : 3782264 : dwarf2out_maybe_output_loclist_view_pair (curr);
10507 : : /* If all code is in .text section, the base address is
10508 : : already provided by the CU attributes. Use
10509 : : DW_LLE_offset_pair where both addresses are uleb128 encoded
10510 : : offsets against that base. */
10511 : 3782264 : dw2_asm_output_data (1, DW_LLE_offset_pair,
10512 : : "DW_LLE_offset_pair (%s)",
10513 : : list_head->ll_symbol);
10514 : 3782264 : dw2_asm_output_delta_uleb128 (curr->begin, curr->section,
10515 : : "Location list begin address (%s)",
10516 : : list_head->ll_symbol);
10517 : 3782264 : dw2_asm_output_delta_uleb128 (curr->end, curr->section,
10518 : : "Location list end address (%s)",
10519 : : list_head->ll_symbol);
10520 : : }
10521 : 19815941 : else if (HAVE_AS_LEB128)
10522 : : {
10523 : : /* Otherwise, find out how many consecutive entries could share
10524 : : the same base entry. If just one, emit DW_LLE_start_length,
10525 : : otherwise emit DW_LLE_base_address for the base address
10526 : : followed by a series of DW_LLE_offset_pair. */
10527 : 19815941 : if (last_section == NULL || curr->section != last_section)
10528 : : {
10529 : 10505111 : dw_loc_list_ref curr2;
10530 : 10849251 : for (curr2 = curr->dw_loc_next; curr2 != NULL;
10531 : 344140 : curr2 = curr2->dw_loc_next)
10532 : : {
10533 : 3774809 : if (strcmp (curr2->begin, curr2->end) == 0
10534 : 344140 : && !curr2->force)
10535 : 344140 : continue;
10536 : : break;
10537 : : }
10538 : 10505111 : if (curr2 == NULL || curr->section != curr2->section)
10539 : : last_section = NULL;
10540 : : else
10541 : : {
10542 : 3408504 : last_section = curr->section;
10543 : 3408504 : base_label = curr->begin;
10544 : 3408504 : dw2_asm_output_data (1, DW_LLE_base_address,
10545 : : "DW_LLE_base_address (%s)",
10546 : : list_head->ll_symbol);
10547 : 3602617 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, base_label,
10548 : : "Base address (%s)",
10549 : : list_head->ll_symbol);
10550 : : }
10551 : : }
10552 : : /* Only one entry with the same base address. Use
10553 : : DW_LLE_start_length with absolute address and uleb128
10554 : : length. */
10555 : 12719334 : if (last_section == NULL)
10556 : : {
10557 : 7096607 : dwarf2out_maybe_output_loclist_view_pair (curr);
10558 : 7096607 : dw2_asm_output_data (1, DW_LLE_start_length,
10559 : : "DW_LLE_start_length (%s)",
10560 : : list_head->ll_symbol);
10561 : 7312120 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10562 : : "Location list begin address (%s)",
10563 : : list_head->ll_symbol);
10564 : 7096607 : dw2_asm_output_delta_uleb128 (curr->end, curr->begin,
10565 : : "Location list length "
10566 : : "(%s)", list_head->ll_symbol);
10567 : : }
10568 : : /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
10569 : : DW_LLE_base_address. */
10570 : : else
10571 : : {
10572 : 12719334 : dwarf2out_maybe_output_loclist_view_pair (curr);
10573 : 12719334 : dw2_asm_output_data (1, DW_LLE_offset_pair,
10574 : : "DW_LLE_offset_pair (%s)",
10575 : : list_head->ll_symbol);
10576 : 12719334 : dw2_asm_output_delta_uleb128 (curr->begin, base_label,
10577 : : "Location list begin address "
10578 : : "(%s)", list_head->ll_symbol);
10579 : 12719334 : dw2_asm_output_delta_uleb128 (curr->end, base_label,
10580 : : "Location list end address "
10581 : : "(%s)", list_head->ll_symbol);
10582 : : }
10583 : : }
10584 : : /* The assembler does not support .uleb128 directive. Emit
10585 : : DW_LLE_start_end with a pair of absolute addresses. */
10586 : : else
10587 : : {
10588 : : dwarf2out_maybe_output_loclist_view_pair (curr);
10589 : : dw2_asm_output_data (1, DW_LLE_start_end,
10590 : : "DW_LLE_start_end (%s)",
10591 : : list_head->ll_symbol);
10592 : : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10593 : : "Location list begin address (%s)",
10594 : : list_head->ll_symbol);
10595 : : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
10596 : : "Location list end address (%s)",
10597 : : list_head->ll_symbol);
10598 : : }
10599 : : }
10600 : 13533 : else if (dwarf_split_debug_info)
10601 : : {
10602 : : /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
10603 : : and 4 byte length. */
10604 : 0 : dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry,
10605 : : "Location list start/length entry (%s)",
10606 : : list_head->ll_symbol);
10607 : 0 : dw2_asm_output_data_uleb128 (curr->begin_entry->index,
10608 : : "Location list range start index (%s)",
10609 : : curr->begin);
10610 : : /* The length field is 4 bytes. If we ever need to support
10611 : : an 8-byte length, we can add a new DW_LLE code or fall back
10612 : : to DW_LLE_GNU_start_end_entry. */
10613 : 0 : dw2_asm_output_delta (4, curr->end, curr->begin,
10614 : : "Location list range length (%s)",
10615 : : list_head->ll_symbol);
10616 : : }
10617 : 13533 : else if (!have_multiple_function_sections)
10618 : : {
10619 : : /* Pair of relative addresses against start of text section. */
10620 : 6740 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
10621 : : "Location list begin address (%s)",
10622 : : list_head->ll_symbol);
10623 : 6740 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
10624 : : "Location list end address (%s)",
10625 : : list_head->ll_symbol);
10626 : : }
10627 : : else
10628 : : {
10629 : : /* Pair of absolute addresses. */
10630 : 6793 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
10631 : : "Location list begin address (%s)",
10632 : : list_head->ll_symbol);
10633 : 6793 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
10634 : : "Location list end address (%s)",
10635 : : list_head->ll_symbol);
10636 : : }
10637 : :
10638 : : /* Output the block length for this list of location operations. */
10639 : 23611742 : if (dwarf_version >= 5)
10640 : 23598209 : dw2_asm_output_data_uleb128 (size, "Location expression size");
10641 : : else
10642 : : {
10643 : 13533 : gcc_assert (size <= 0xffff);
10644 : 13533 : dw2_asm_output_data (2, size, "Location expression size");
10645 : : }
10646 : :
10647 : 23611742 : output_loc_sequence (curr->expr, -1);
10648 : : }
10649 : :
10650 : : /* And finally list termination. */
10651 : 11084912 : if (dwarf_version >= 5)
10652 : 11080562 : dw2_asm_output_data (1, DW_LLE_end_of_list,
10653 : : "DW_LLE_end_of_list (%s)", list_head->ll_symbol);
10654 : 4350 : else if (dwarf_split_debug_info)
10655 : 0 : dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry,
10656 : : "Location list terminator (%s)",
10657 : : list_head->ll_symbol);
10658 : : else
10659 : : {
10660 : 4350 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10661 : : "Location list terminator begin (%s)",
10662 : : list_head->ll_symbol);
10663 : 4350 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
10664 : : "Location list terminator end (%s)",
10665 : : list_head->ll_symbol);
10666 : : }
10667 : :
10668 : 11084912 : gcc_assert (!list_head->vl_symbol
10669 : : || vcount == lcount * (dwarf2out_locviews_in_attribute () ? 1 : 0));
10670 : : }
10671 : :
10672 : : /* Output a range_list offset into the .debug_ranges or .debug_rnglists
10673 : : section. Emit a relocated reference if val_entry is NULL, otherwise,
10674 : : emit an indirect reference. */
10675 : :
10676 : : static void
10677 : 3179966 : output_range_list_offset (dw_attr_node *a)
10678 : : {
10679 : 3179966 : const char *name = dwarf_attr_name (a->dw_attr);
10680 : :
10681 : 3179966 : if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
10682 : : {
10683 : 3179963 : if (dwarf_version >= 5)
10684 : : {
10685 : 3178630 : dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
10686 : 3178630 : dw2_asm_output_offset (dwarf_offset_size, r->label,
10687 : : debug_ranges_section, "%s", name);
10688 : : }
10689 : : else
10690 : : {
10691 : 1333 : char *p = strchr (ranges_section_label, '\0');
10692 : 2666 : sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
10693 : 1333 : a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE);
10694 : 1333 : dw2_asm_output_offset (dwarf_offset_size, ranges_section_label,
10695 : : debug_ranges_section, "%s", name);
10696 : 1333 : *p = '\0';
10697 : : }
10698 : : }
10699 : 3 : else if (dwarf_version >= 5)
10700 : : {
10701 : 3 : dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
10702 : 3 : gcc_assert (rnglist_idx);
10703 : 3 : dw2_asm_output_data_uleb128 (r->idx, "%s", name);
10704 : : }
10705 : : else
10706 : 0 : dw2_asm_output_data (dwarf_offset_size,
10707 : 0 : a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE,
10708 : : "%s (offset from %s)", name, ranges_section_label);
10709 : 3179966 : }
10710 : :
10711 : : /* Output the offset into the debug_loc section. */
10712 : :
10713 : : static void
10714 : 11206203 : output_loc_list_offset (dw_attr_node *a)
10715 : : {
10716 : 11206203 : char *sym = AT_loc_list (a)->ll_symbol;
10717 : :
10718 : 11206203 : gcc_assert (sym);
10719 : 11206203 : if (!dwarf_split_debug_info)
10720 : 11206201 : dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
10721 : 11206201 : "%s", dwarf_attr_name (a->dw_attr));
10722 : 2 : else if (dwarf_version >= 5)
10723 : : {
10724 : 2 : gcc_assert (AT_loc_list (a)->num_assigned);
10725 : 2 : dw2_asm_output_data_uleb128 (AT_loc_list (a)->hash, "%s (%s)",
10726 : 2 : dwarf_attr_name (a->dw_attr),
10727 : : sym);
10728 : : }
10729 : : else
10730 : 0 : dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
10731 : 0 : "%s", dwarf_attr_name (a->dw_attr));
10732 : 11206203 : }
10733 : :
10734 : : /* Output the offset into the debug_loc section. */
10735 : :
10736 : : static void
10737 : 11031296 : output_view_list_offset (dw_attr_node *a)
10738 : : {
10739 : 11031296 : char *sym = (*AT_loc_list_ptr (a))->vl_symbol;
10740 : :
10741 : 11031296 : gcc_assert (sym);
10742 : 11031296 : if (dwarf_split_debug_info)
10743 : 2 : dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
10744 : 2 : "%s", dwarf_attr_name (a->dw_attr));
10745 : : else
10746 : 11031294 : dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
10747 : 11031294 : "%s", dwarf_attr_name (a->dw_attr));
10748 : 11031296 : }
10749 : :
10750 : : /* Output an attribute's index or value appropriately. */
10751 : :
10752 : : static void
10753 : 14568249 : output_attr_index_or_value (dw_attr_node *a)
10754 : : {
10755 : 14568249 : const char *name = dwarf_attr_name (a->dw_attr);
10756 : :
10757 : 14568249 : if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
10758 : : {
10759 : 253 : dw2_asm_output_data_uleb128 (AT_index (a), "%s", name);
10760 : 253 : return;
10761 : : }
10762 : 14567996 : switch (AT_class (a))
10763 : : {
10764 : 28356 : case dw_val_class_addr:
10765 : 28356 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
10766 : 28356 : break;
10767 : 14539640 : case dw_val_class_high_pc:
10768 : 14539640 : case dw_val_class_lbl_id:
10769 : 14539640 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
10770 : 14539640 : break;
10771 : 0 : default:
10772 : 0 : gcc_unreachable ();
10773 : : }
10774 : : }
10775 : :
10776 : : /* Output a type signature. */
10777 : :
10778 : : static inline void
10779 : 167 : output_signature (const char *sig, const char *name)
10780 : : {
10781 : 167 : int i;
10782 : :
10783 : 1503 : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
10784 : 2505 : dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
10785 : 167 : }
10786 : :
10787 : : /* Output a discriminant value. */
10788 : :
10789 : : static inline void
10790 : 0 : output_discr_value (dw_discr_value *discr_value, const char *name)
10791 : : {
10792 : 0 : if (discr_value->pos)
10793 : 0 : dw2_asm_output_data_uleb128 (discr_value->v.uval, "%s", name);
10794 : : else
10795 : 0 : dw2_asm_output_data_sleb128 (discr_value->v.sval, "%s", name);
10796 : 0 : }
10797 : :
10798 : : /* Output the DIE and its attributes. Called recursively to generate
10799 : : the definitions of each child DIE. */
10800 : :
10801 : : static void
10802 : 80829291 : output_die (dw_die_ref die)
10803 : : {
10804 : 80829291 : dw_attr_node *a;
10805 : 80829291 : dw_die_ref c;
10806 : 80829291 : unsigned long size;
10807 : 80829291 : unsigned ix;
10808 : :
10809 : 161658582 : dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
10810 : 80829291 : (unsigned long)die->die_offset,
10811 : 80829291 : dwarf_tag_name (die->die_tag));
10812 : :
10813 : 399873630 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
10814 : : {
10815 : 319044339 : const char *name = dwarf_attr_name (a->dw_attr);
10816 : :
10817 : 319044339 : switch (AT_class (a))
10818 : : {
10819 : 28356 : case dw_val_class_addr:
10820 : 28356 : output_attr_index_or_value (a);
10821 : 28356 : break;
10822 : :
10823 : 0 : case dw_val_class_offset:
10824 : 0 : dw2_asm_output_data (dwarf_offset_size, a->dw_attr_val.v.val_offset,
10825 : : "%s", name);
10826 : 0 : break;
10827 : :
10828 : 3179966 : case dw_val_class_range_list:
10829 : 3179966 : output_range_list_offset (a);
10830 : 3179966 : break;
10831 : :
10832 : 7720099 : case dw_val_class_loc:
10833 : 7720099 : size = size_of_locs (AT_loc (a));
10834 : :
10835 : : /* Output the block length for this list of location operations. */
10836 : 7720099 : if (dwarf_version >= 4)
10837 : 7709195 : dw2_asm_output_data_uleb128 (size, "%s", name);
10838 : : else
10839 : 10904 : dw2_asm_output_data (constant_size (size), size, "%s", name);
10840 : :
10841 : 7720099 : output_loc_sequence (AT_loc (a), -1);
10842 : 7720099 : break;
10843 : :
10844 : 14012 : case dw_val_class_const:
10845 : : /* ??? It would be slightly more efficient to use a scheme like is
10846 : : used for unsigned constants below, but gdb 4.x does not sign
10847 : : extend. Gdb 5.x does sign extend. */
10848 : 14012 : dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
10849 : 14012 : break;
10850 : :
10851 : 65186540 : case dw_val_class_unsigned_const:
10852 : 65186540 : {
10853 : 65186540 : int csize = constant_size (AT_unsigned (a));
10854 : 65186540 : if (dwarf_version == 3
10855 : 690 : && a->dw_attr == DW_AT_data_member_location
10856 : 15 : && csize >= 4)
10857 : 1 : dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
10858 : : else
10859 : 65186539 : dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
10860 : : }
10861 : : break;
10862 : :
10863 : 6673950 : case dw_val_class_symview:
10864 : 6673950 : {
10865 : 6673950 : int vsize;
10866 : 6673950 : if (symview_upper_bound <= 0xff)
10867 : : vsize = 1;
10868 : 6313987 : else if (symview_upper_bound <= 0xffff)
10869 : : vsize = 2;
10870 : 0 : else if (symview_upper_bound <= 0xffffffff)
10871 : 0 : vsize = 4;
10872 : : else
10873 : : vsize = 8;
10874 : 6673950 : dw2_asm_output_addr (vsize, a->dw_attr_val.v.val_symbolic_view,
10875 : : "%s", name);
10876 : : }
10877 : 6673950 : break;
10878 : :
10879 : 5097 : case dw_val_class_const_implicit:
10880 : 5097 : if (flag_debug_asm)
10881 : 0 : fprintf (asm_out_file, "\t\t\t%s %s ("
10882 : : HOST_WIDE_INT_PRINT_DEC ")\n",
10883 : : ASM_COMMENT_START, name, AT_int (a));
10884 : : break;
10885 : :
10886 : 9077709 : case dw_val_class_unsigned_const_implicit:
10887 : 9077709 : if (flag_debug_asm)
10888 : 349 : fprintf (asm_out_file, "\t\t\t%s %s ("
10889 : : HOST_WIDE_INT_PRINT_HEX ")\n",
10890 : : ASM_COMMENT_START, name, AT_unsigned (a));
10891 : : break;
10892 : :
10893 : 0 : case dw_val_class_const_double:
10894 : 0 : {
10895 : 0 : unsigned HOST_WIDE_INT first, second;
10896 : :
10897 : 0 : if (HOST_BITS_PER_WIDE_INT >= DWARF_LARGEST_DATA_FORM_BITS)
10898 : 0 : dw2_asm_output_data (1,
10899 : : HOST_BITS_PER_DOUBLE_INT
10900 : : / HOST_BITS_PER_CHAR,
10901 : : NULL);
10902 : :
10903 : 0 : if (WORDS_BIG_ENDIAN)
10904 : : {
10905 : : first = a->dw_attr_val.v.val_double.high;
10906 : : second = a->dw_attr_val.v.val_double.low;
10907 : : }
10908 : : else
10909 : : {
10910 : 0 : first = a->dw_attr_val.v.val_double.low;
10911 : 0 : second = a->dw_attr_val.v.val_double.high;
10912 : : }
10913 : :
10914 : 0 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10915 : : first, "%s", name);
10916 : 0 : dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
10917 : : second, NULL);
10918 : : }
10919 : 0 : break;
10920 : :
10921 : 39 : case dw_val_class_wide_int:
10922 : 39 : {
10923 : 39 : int i;
10924 : 39 : int len = get_full_len (*a->dw_attr_val.v.val_wide);
10925 : 39 : int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10926 : 39 : if (len * HOST_BITS_PER_WIDE_INT > DWARF_LARGEST_DATA_FORM_BITS)
10927 : 0 : dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide)
10928 : 0 : * l, NULL);
10929 : :
10930 : : if (WORDS_BIG_ENDIAN)
10931 : : for (i = len - 1; i >= 0; --i)
10932 : : {
10933 : : dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
10934 : : "%s", name);
10935 : : name = "";
10936 : : }
10937 : : else
10938 : 117 : for (i = 0; i < len; ++i)
10939 : : {
10940 : 78 : dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
10941 : : "%s", name);
10942 : 78 : name = "";
10943 : : }
10944 : : }
10945 : : break;
10946 : :
10947 : 14933 : case dw_val_class_vec:
10948 : 14933 : {
10949 : 14933 : unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
10950 : 14933 : unsigned int len = a->dw_attr_val.v.val_vec.length;
10951 : 14933 : unsigned int i;
10952 : 14933 : unsigned char *p;
10953 : :
10954 : 14933 : dw2_asm_output_data (constant_size (len * elt_size),
10955 : 14933 : len * elt_size, "%s", name);
10956 : 14933 : if (elt_size > sizeof (HOST_WIDE_INT))
10957 : : {
10958 : 0 : elt_size /= 2;
10959 : 0 : len *= 2;
10960 : : }
10961 : 14933 : for (i = 0, p = (unsigned char *) a->dw_attr_val.v.val_vec.array;
10962 : 4208519 : i < len;
10963 : 4193586 : i++, p += elt_size)
10964 : 8387172 : dw2_asm_output_data (elt_size, extract_int (p, elt_size),
10965 : : "fp or vector constant word %u", i);
10966 : : break;
10967 : : }
10968 : :
10969 : 27394148 : case dw_val_class_flag:
10970 : 27394148 : if (dwarf_version >= 4)
10971 : : {
10972 : : /* Currently all add_AT_flag calls pass in 1 as last argument,
10973 : : so DW_FORM_flag_present can be used. If that ever changes,
10974 : : we'll need to use DW_FORM_flag and have some optimization
10975 : : in build_abbrev_table that will change those to
10976 : : DW_FORM_flag_present if it is set to 1 in all DIEs using
10977 : : the same abbrev entry. */
10978 : 27373008 : gcc_assert (AT_flag (a) == 1);
10979 : 27373008 : if (flag_debug_asm)
10980 : 2131 : fprintf (asm_out_file, "\t\t\t%s %s\n",
10981 : : ASM_COMMENT_START, name);
10982 : : break;
10983 : : }
10984 : 21140 : dw2_asm_output_data (1, AT_flag (a), "%s", name);
10985 : 21140 : break;
10986 : :
10987 : 11206203 : case dw_val_class_loc_list:
10988 : 11206203 : output_loc_list_offset (a);
10989 : 11206203 : break;
10990 : :
10991 : 11031296 : case dw_val_class_view_list:
10992 : 11031296 : output_view_list_offset (a);
10993 : 11031296 : break;
10994 : :
10995 : 94848534 : case dw_val_class_die_ref:
10996 : 94848534 : if (AT_ref_external (a))
10997 : : {
10998 : 28913 : if (AT_ref (a)->comdat_type_p)
10999 : : {
11000 : 87 : comdat_type_node *type_node
11001 : 87 : = AT_ref (a)->die_id.die_type_node;
11002 : :
11003 : 87 : gcc_assert (type_node);
11004 : 87 : output_signature (type_node->signature, name);
11005 : : }
11006 : : else
11007 : : {
11008 : 28826 : const char *sym = AT_ref (a)->die_id.die_symbol;
11009 : 28826 : int size;
11010 : :
11011 : 28826 : gcc_assert (sym);
11012 : : /* In DWARF2, DW_FORM_ref_addr is sized by target address
11013 : : length, whereas in DWARF3 it's always sized as an
11014 : : offset. */
11015 : 28826 : if (dwarf_version == 2)
11016 : 30 : size = DWARF2_ADDR_SIZE;
11017 : : else
11018 : 28796 : size = dwarf_offset_size;
11019 : : /* ??? We cannot unconditionally output die_offset if
11020 : : non-zero - others might create references to those
11021 : : DIEs via symbols.
11022 : : And we do not clear its DIE offset after outputting it
11023 : : (and the label refers to the actual DIEs, not the
11024 : : DWARF CU unit header which is when using label + offset
11025 : : would be the correct thing to do).
11026 : : ??? This is the reason for the with_offset flag. */
11027 : 28826 : if (AT_ref (a)->with_offset)
11028 : 28826 : dw2_asm_output_offset (size, sym, AT_ref (a)->die_offset,
11029 : : debug_info_section, "%s", name);
11030 : : else
11031 : 0 : dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11032 : : name);
11033 : : }
11034 : : }
11035 : : else
11036 : : {
11037 : 94819621 : gcc_assert (AT_ref (a)->die_offset);
11038 : 94819621 : dw2_asm_output_data (dwarf_offset_size, AT_ref (a)->die_offset,
11039 : : "%s", name);
11040 : : }
11041 : : break;
11042 : :
11043 : 0 : case dw_val_class_fde_ref:
11044 : 0 : {
11045 : 0 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
11046 : :
11047 : 0 : ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11048 : : a->dw_attr_val.v.val_fde_index * 2);
11049 : 0 : dw2_asm_output_offset (dwarf_offset_size, l1, debug_frame_section,
11050 : : "%s", name);
11051 : : }
11052 : 0 : break;
11053 : :
11054 : 0 : case dw_val_class_vms_delta:
11055 : : #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
11056 : : dw2_asm_output_vms_delta (dwarf_offset_size,
11057 : : AT_vms_delta2 (a), AT_vms_delta1 (a),
11058 : : "%s", name);
11059 : : #else
11060 : 0 : dw2_asm_output_delta (dwarf_offset_size,
11061 : : AT_vms_delta2 (a), AT_vms_delta1 (a),
11062 : : "%s", name);
11063 : : #endif
11064 : 0 : break;
11065 : :
11066 : 14539893 : case dw_val_class_lbl_id:
11067 : 14539893 : output_attr_index_or_value (a);
11068 : 14539893 : break;
11069 : :
11070 : 52572 : case dw_val_class_lineptr:
11071 : 52572 : dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
11072 : : debug_line_section, "%s", name);
11073 : 52572 : break;
11074 : :
11075 : 525 : case dw_val_class_macptr:
11076 : 525 : dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
11077 : : debug_macinfo_section, "%s", name);
11078 : 525 : break;
11079 : :
11080 : 0 : case dw_val_class_loclistsptr:
11081 : 0 : dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
11082 : : debug_loc_section, "%s", name);
11083 : 0 : break;
11084 : :
11085 : 33228150 : case dw_val_class_str:
11086 : 33228150 : if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
11087 : 30054660 : dw2_asm_output_offset (dwarf_offset_size,
11088 : 30054660 : a->dw_attr_val.v.val_str->label,
11089 : : debug_str_section,
11090 : : "%s: \"%s\"", name, AT_string (a));
11091 : 3173490 : else if (a->dw_attr_val.v.val_str->form == DW_FORM_line_strp)
11092 : 100042 : dw2_asm_output_offset (dwarf_offset_size,
11093 : 100042 : a->dw_attr_val.v.val_str->label,
11094 : : debug_line_str_section,
11095 : : "%s: \"%s\"", name, AT_string (a));
11096 : 3087648 : else if (a->dw_attr_val.v.val_str->form == dwarf_FORM (DW_FORM_strx))
11097 : 935 : dw2_asm_output_data_uleb128 (AT_index (a),
11098 : : "%s: \"%s\"", name, AT_string (a));
11099 : : else
11100 : 3072513 : dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11101 : : break;
11102 : :
11103 : 26293445 : case dw_val_class_file:
11104 : 26293445 : {
11105 : 26293445 : int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11106 : :
11107 : 26293445 : dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11108 : 26293445 : a->dw_attr_val.v.val_file->filename);
11109 : 26293445 : break;
11110 : : }
11111 : :
11112 : 3619454 : case dw_val_class_file_implicit:
11113 : 3619454 : if (flag_debug_asm)
11114 : 491 : fprintf (asm_out_file, "\t\t\t%s %s (%d, %s)\n",
11115 : : ASM_COMMENT_START, name,
11116 : : maybe_emit_file (a->dw_attr_val.v.val_file),
11117 : 491 : a->dw_attr_val.v.val_file->filename);
11118 : : break;
11119 : :
11120 : : case dw_val_class_data8:
11121 : : {
11122 : : int i;
11123 : :
11124 : 639 : for (i = 0; i < 8; i++)
11125 : 1065 : dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11126 : : i == 0 ? "%s" : NULL, name);
11127 : : break;
11128 : : }
11129 : :
11130 : 4929347 : case dw_val_class_high_pc:
11131 : 4929347 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
11132 : : get_AT_low_pc (die), "DW_AT_high_pc");
11133 : 4929347 : break;
11134 : :
11135 : 0 : case dw_val_class_discr_value:
11136 : 0 : output_discr_value (&a->dw_attr_val.v.val_discr_value, name);
11137 : 0 : break;
11138 : :
11139 : 0 : case dw_val_class_discr_list:
11140 : 0 : {
11141 : 0 : dw_discr_list_ref list = AT_discr_list (a);
11142 : 0 : const int size = size_of_discr_list (list);
11143 : :
11144 : : /* This is a block, so output its length first. */
11145 : 0 : dw2_asm_output_data (constant_size (size), size,
11146 : : "%s: block size", name);
11147 : :
11148 : 0 : for (; list != NULL; list = list->dw_discr_next)
11149 : : {
11150 : : /* One byte for the discriminant value descriptor, and then as
11151 : : many LEB128 numbers as required. */
11152 : 0 : if (list->dw_discr_range)
11153 : 0 : dw2_asm_output_data (1, DW_DSC_range,
11154 : : "%s: DW_DSC_range", name);
11155 : : else
11156 : 0 : dw2_asm_output_data (1, DW_DSC_label,
11157 : : "%s: DW_DSC_label", name);
11158 : :
11159 : 0 : output_discr_value (&list->dw_discr_lower_bound, name);
11160 : 0 : if (list->dw_discr_range)
11161 : 0 : output_discr_value (&list->dw_discr_upper_bound, name);
11162 : : }
11163 : : break;
11164 : : }
11165 : :
11166 : 0 : default:
11167 : 0 : gcc_unreachable ();
11168 : : }
11169 : : }
11170 : :
11171 : 139828855 : FOR_EACH_CHILD (die, c, output_die (c));
11172 : :
11173 : : /* Add null byte to terminate sibling list. */
11174 : 80829291 : if (die->die_child != NULL)
11175 : 21777150 : dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11176 : 21777150 : (unsigned long) die->die_offset);
11177 : 80829291 : }
11178 : :
11179 : : /* Output the dwarf version number. */
11180 : :
11181 : : static void
11182 : 117462 : output_dwarf_version ()
11183 : : {
11184 : : /* ??? For now, if -gdwarf-6 is specified, we output version 5 with
11185 : : views in loclist. That will change eventually. */
11186 : 117462 : if (dwarf_version == 6)
11187 : : {
11188 : 0 : static bool once;
11189 : 0 : if (!once)
11190 : : {
11191 : 0 : warning (0, "%<-gdwarf-6%> is output as version 5 with "
11192 : : "incompatibilities");
11193 : 0 : once = true;
11194 : : }
11195 : 0 : dw2_asm_output_data (2, 5, "DWARF version number");
11196 : : }
11197 : : else
11198 : 117462 : dw2_asm_output_data (2, dwarf_version, "DWARF version number");
11199 : 117462 : }
11200 : :
11201 : : /* Output the compilation unit that appears at the beginning of the
11202 : : .debug_info section, and precedes the DIE descriptions. */
11203 : :
11204 : : static void
11205 : 52328 : output_compilation_unit_header (enum dwarf_unit_type ut)
11206 : : {
11207 : 52328 : if (!XCOFF_DEBUGGING_INFO)
11208 : : {
11209 : 52328 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11210 : 0 : dw2_asm_output_data (4, 0xffffffff,
11211 : : "Initial length escape value indicating 64-bit DWARF extension");
11212 : 52328 : dw2_asm_output_data (dwarf_offset_size,
11213 : 52328 : next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11214 : : "Length of Compilation Unit Info");
11215 : : }
11216 : :
11217 : 52328 : output_dwarf_version ();
11218 : 52328 : if (dwarf_version >= 5)
11219 : : {
11220 : 50289 : const char *name;
11221 : 50289 : switch (ut)
11222 : : {
11223 : : case DW_UT_compile: name = "DW_UT_compile"; break;
11224 : 20 : case DW_UT_type: name = "DW_UT_type"; break;
11225 : 248 : case DW_UT_split_compile: name = "DW_UT_split_compile"; break;
11226 : 0 : case DW_UT_split_type: name = "DW_UT_split_type"; break;
11227 : 0 : default: gcc_unreachable ();
11228 : : }
11229 : 50289 : dw2_asm_output_data (1, ut, "%s", name);
11230 : 56570 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11231 : : }
11232 : 52328 : dw2_asm_output_offset (dwarf_offset_size, abbrev_section_label,
11233 : : debug_abbrev_section,
11234 : : "Offset Into Abbrev. Section");
11235 : 52328 : if (dwarf_version < 5)
11236 : 2039 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11237 : 52328 : }
11238 : :
11239 : : /* Output the compilation unit DIE and its children. */
11240 : :
11241 : : static void
11242 : 53546 : output_comp_unit (dw_die_ref die, int output_if_empty,
11243 : : const unsigned char *dwo_id)
11244 : : {
11245 : 53546 : const char *secname, *oldsym;
11246 : 53546 : char *tmp;
11247 : :
11248 : : /* Unless we are outputting main CU, we may throw away empty ones. */
11249 : 53546 : if (!output_if_empty && die->die_child == NULL)
11250 : : return;
11251 : :
11252 : : /* Even if there are no children of this DIE, we must output the information
11253 : : about the compilation unit. Otherwise, on an empty translation unit, we
11254 : : will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11255 : : will then complain when examining the file. First mark all the DIEs in
11256 : : this CU so we know which get local refs. */
11257 : 52248 : mark_dies (die);
11258 : :
11259 : 52248 : external_ref_hash_type *extern_map = optimize_external_refs (die);
11260 : :
11261 : : /* For now, optimize only the main CU, in order to optimize the rest
11262 : : we'd need to see all of them earlier. Leave the rest for post-linking
11263 : : tools like DWZ. */
11264 : 52248 : if (die == comp_unit_die ())
11265 : 104496 : abbrev_opt_start = vec_safe_length (abbrev_die_table);
11266 : :
11267 : 52248 : build_abbrev_table (die, extern_map);
11268 : :
11269 : 52248 : optimize_abbrev_table ();
11270 : :
11271 : 52248 : delete extern_map;
11272 : :
11273 : : /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11274 : 104496 : next_die_offset = (dwo_id
11275 : 52250 : ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11276 : 53977 : : DWARF_COMPILE_UNIT_HEADER_SIZE);
11277 : 52248 : calc_die_sizes (die);
11278 : :
11279 : 52248 : oldsym = die->die_id.die_symbol;
11280 : 52248 : if (oldsym && die->comdat_type_p)
11281 : : {
11282 : 0 : tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11283 : :
11284 : 0 : sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11285 : 0 : secname = tmp;
11286 : 0 : die->die_id.die_symbol = NULL;
11287 : 0 : switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11288 : : }
11289 : : else
11290 : : {
11291 : 52248 : switch_to_section (debug_info_section);
11292 : 52248 : ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11293 : 52248 : info_section_emitted = true;
11294 : : }
11295 : :
11296 : : /* For LTO cross unit DIE refs we want a symbol on the start of the
11297 : : debuginfo section, not on the CU DIE. */
11298 : 52248 : if ((flag_generate_lto || flag_generate_offload) && oldsym)
11299 : : {
11300 : : /* ??? No way to get visibility assembled without a decl. */
11301 : 1323 : tree decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
11302 : : get_identifier (oldsym), char_type_node);
11303 : 1323 : TREE_PUBLIC (decl) = true;
11304 : 1323 : TREE_STATIC (decl) = true;
11305 : 1323 : DECL_ARTIFICIAL (decl) = true;
11306 : 1323 : DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
11307 : 1323 : DECL_VISIBILITY_SPECIFIED (decl) = true;
11308 : 1323 : targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN);
11309 : : #ifdef ASM_WEAKEN_LABEL
11310 : : /* We prefer a .weak because that handles duplicates from duplicate
11311 : : archive members in a graceful way. */
11312 : 1323 : ASM_WEAKEN_LABEL (asm_out_file, oldsym);
11313 : : #else
11314 : : targetm.asm_out.globalize_label (asm_out_file, oldsym);
11315 : : #endif
11316 : 1323 : ASM_OUTPUT_LABEL (asm_out_file, oldsym);
11317 : : }
11318 : :
11319 : : /* Output debugging information. */
11320 : 104247 : output_compilation_unit_header (dwo_id
11321 : : ? DW_UT_split_compile : DW_UT_compile);
11322 : 52248 : if (dwarf_version >= 5)
11323 : : {
11324 : 50269 : if (dwo_id != NULL)
11325 : 2232 : for (int i = 0; i < 8; i++)
11326 : 3720 : dw2_asm_output_data (1, dwo_id[i], i == 0 ? "DWO id" : NULL);
11327 : : }
11328 : 52248 : output_die (die);
11329 : :
11330 : : /* Leave the marks on the main CU, so we can check them in
11331 : : output_pubnames. */
11332 : 52248 : if (oldsym)
11333 : : {
11334 : 1323 : unmark_dies (die);
11335 : 1323 : die->die_id.die_symbol = oldsym;
11336 : : }
11337 : : }
11338 : :
11339 : : /* Whether to generate the DWARF accelerator tables in .debug_pubnames
11340 : : and .debug_pubtypes. This is configured per-target, but can be
11341 : : overridden by the -gpubnames or -gno-pubnames options. */
11342 : :
11343 : : static inline bool
11344 : 204833522 : want_pubnames (void)
11345 : : {
11346 : 204833522 : if (debug_info_level <= DINFO_LEVEL_TERSE
11347 : : /* Names and types go to the early debug part only. */
11348 : 204816367 : || in_lto_p)
11349 : : return false;
11350 : 204815436 : if (debug_generate_pub_sections != -1)
11351 : 1449 : return debug_generate_pub_sections;
11352 : 204813987 : return targetm.want_debug_pub_sections;
11353 : : }
11354 : :
11355 : : /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
11356 : :
11357 : : static void
11358 : 52411 : add_AT_pubnames (dw_die_ref die)
11359 : : {
11360 : 52411 : if (want_pubnames ())
11361 : 256 : add_AT_flag (die, DW_AT_GNU_pubnames, 1);
11362 : 52411 : }
11363 : :
11364 : : /* Add a string attribute value to a skeleton DIE. */
11365 : :
11366 : : static inline void
11367 : 498 : add_skeleton_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
11368 : : const char *str)
11369 : : {
11370 : 498 : dw_attr_node attr;
11371 : 498 : struct indirect_string_node *node;
11372 : :
11373 : 498 : if (! skeleton_debug_str_hash)
11374 : 249 : skeleton_debug_str_hash
11375 : 249 : = hash_table<indirect_string_hasher>::create_ggc (10);
11376 : :
11377 : 498 : node = find_AT_string_in_table (str, skeleton_debug_str_hash);
11378 : 498 : find_string_form (node);
11379 : 500 : if (node->form == dwarf_FORM (DW_FORM_strx))
11380 : 498 : node->form = DW_FORM_strp;
11381 : :
11382 : 498 : attr.dw_attr = attr_kind;
11383 : 498 : attr.dw_attr_val.val_class = dw_val_class_str;
11384 : 498 : attr.dw_attr_val.val_entry = NULL;
11385 : 498 : attr.dw_attr_val.v.val_str = node;
11386 : 498 : add_dwarf_attr (die, &attr);
11387 : 498 : }
11388 : :
11389 : : /* Helper function to generate top-level dies for skeleton debug_info and
11390 : : debug_types. */
11391 : :
11392 : : static void
11393 : 249 : add_top_level_skeleton_die_attrs (dw_die_ref die)
11394 : : {
11395 : 249 : const char *dwo_file_name = concat (aux_base_name, ".dwo", NULL);
11396 : 249 : const char *comp_dir = comp_dir_string ();
11397 : :
11398 : 250 : add_skeleton_AT_string (die, dwarf_AT (DW_AT_dwo_name), dwo_file_name);
11399 : 249 : if (comp_dir != NULL)
11400 : 249 : add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
11401 : 249 : add_AT_pubnames (die);
11402 : 249 : if (addr_index_table != NULL && addr_index_table->size () > 0)
11403 : 244 : add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label);
11404 : 249 : }
11405 : :
11406 : : /* Output skeleton debug sections that point to the dwo file. */
11407 : :
11408 : : static void
11409 : 249 : output_skeleton_debug_sections (dw_die_ref comp_unit,
11410 : : const unsigned char *dwo_id)
11411 : : {
11412 : : /* These attributes will be found in the full debug_info section. */
11413 : 249 : remove_AT (comp_unit, DW_AT_producer);
11414 : 249 : remove_AT (comp_unit, DW_AT_language);
11415 : 249 : remove_AT (comp_unit, DW_AT_language_name);
11416 : 249 : remove_AT (comp_unit, DW_AT_language_version);
11417 : :
11418 : 249 : switch_to_section (debug_skeleton_info_section);
11419 : 249 : ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
11420 : :
11421 : : /* Produce the skeleton compilation-unit header. This one differs enough from
11422 : : a normal CU header that it's better not to call output_compilation_unit
11423 : : header. */
11424 : 249 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11425 : 0 : dw2_asm_output_data (4, 0xffffffff,
11426 : : "Initial length escape value indicating 64-bit "
11427 : : "DWARF extension");
11428 : :
11429 : 249 : dw2_asm_output_data (dwarf_offset_size,
11430 : 250 : DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
11431 : 249 : - DWARF_INITIAL_LENGTH_SIZE
11432 : 249 : + size_of_die (comp_unit),
11433 : : "Length of Compilation Unit Info");
11434 : 249 : output_dwarf_version ();
11435 : 249 : if (dwarf_version >= 5)
11436 : : {
11437 : 248 : dw2_asm_output_data (1, DW_UT_skeleton, "DW_UT_skeleton");
11438 : 248 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11439 : : }
11440 : 249 : dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_abbrev_section_label,
11441 : : debug_skeleton_abbrev_section,
11442 : : "Offset Into Abbrev. Section");
11443 : 249 : if (dwarf_version < 5)
11444 : 1 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11445 : : else
11446 : 2232 : for (int i = 0; i < 8; i++)
11447 : 3720 : dw2_asm_output_data (1, dwo_id[i], i == 0 ? "DWO id" : NULL);
11448 : :
11449 : 249 : comp_unit->die_abbrev = SKELETON_COMP_DIE_ABBREV;
11450 : 249 : output_die (comp_unit);
11451 : :
11452 : : /* Build the skeleton debug_abbrev section. */
11453 : 249 : switch_to_section (debug_skeleton_abbrev_section);
11454 : 249 : ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
11455 : :
11456 : 249 : output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
11457 : :
11458 : 249 : dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
11459 : 249 : }
11460 : :
11461 : : /* Output a comdat type unit DIE and its children. */
11462 : :
11463 : : static void
11464 : 80 : output_comdat_type_unit (comdat_type_node *node,
11465 : : bool early_lto_debug ATTRIBUTE_UNUSED)
11466 : : {
11467 : 80 : const char *secname;
11468 : 80 : char *tmp;
11469 : 80 : int i;
11470 : : #if defined (OBJECT_FORMAT_ELF)
11471 : 80 : tree comdat_key;
11472 : : #endif
11473 : :
11474 : : /* First mark all the DIEs in this CU so we know which get local refs. */
11475 : 80 : mark_dies (node->root_die);
11476 : :
11477 : 80 : external_ref_hash_type *extern_map = optimize_external_refs (node->root_die);
11478 : :
11479 : 80 : build_abbrev_table (node->root_die, extern_map);
11480 : :
11481 : 80 : delete extern_map;
11482 : 80 : extern_map = NULL;
11483 : :
11484 : : /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11485 : 80 : next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11486 : 80 : calc_die_sizes (node->root_die);
11487 : :
11488 : : #if defined (OBJECT_FORMAT_ELF)
11489 : 80 : if (dwarf_version >= 5)
11490 : : {
11491 : 20 : if (!dwarf_split_debug_info)
11492 : 20 : secname = early_lto_debug ? DEBUG_LTO_INFO_SECTION : DEBUG_INFO_SECTION;
11493 : : else
11494 : 0 : secname = (early_lto_debug
11495 : 0 : ? DEBUG_LTO_DWO_INFO_SECTION : DEBUG_DWO_INFO_SECTION);
11496 : : }
11497 : 60 : else if (!dwarf_split_debug_info)
11498 : 60 : secname = early_lto_debug ? ".gnu.debuglto_.debug_types" : ".debug_types";
11499 : : else
11500 : 0 : secname = (early_lto_debug
11501 : 0 : ? ".gnu.debuglto_.debug_types.dwo" : ".debug_types.dwo");
11502 : :
11503 : 80 : tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11504 : 80 : sprintf (tmp, dwarf_version >= 5 ? "wi." : "wt.");
11505 : 720 : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11506 : 640 : sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11507 : 80 : comdat_key = get_identifier (tmp);
11508 : 80 : targetm.asm_out.named_section (secname,
11509 : : SECTION_DEBUG | SECTION_LINKONCE,
11510 : : comdat_key);
11511 : : #else
11512 : : tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11513 : : sprintf (tmp, (dwarf_version >= 5
11514 : : ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
11515 : : for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11516 : : sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11517 : : secname = tmp;
11518 : : switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11519 : : #endif
11520 : :
11521 : : /* Output debugging information. */
11522 : 160 : output_compilation_unit_header (dwarf_split_debug_info
11523 : : ? DW_UT_split_type : DW_UT_type);
11524 : 80 : output_signature (node->signature, "Type Signature");
11525 : 80 : dw2_asm_output_data (dwarf_offset_size, node->type_die->die_offset,
11526 : : "Offset to Type DIE");
11527 : 80 : output_die (node->root_die);
11528 : :
11529 : 80 : unmark_dies (node->root_die);
11530 : 80 : }
11531 : :
11532 : : /* Return the DWARF2/3 pubname associated with a decl. */
11533 : :
11534 : : static const char *
11535 : 155512640 : dwarf2_name (tree decl, int scope)
11536 : : {
11537 : 155512640 : if (DECL_NAMELESS (decl))
11538 : : return NULL;
11539 : 310946770 : return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11540 : : }
11541 : :
11542 : : /* Add a new entry to .debug_pubnames if appropriate. */
11543 : :
11544 : : static void
11545 : 536 : add_pubname_string (const char *str, dw_die_ref die)
11546 : : {
11547 : 536 : pubname_entry e;
11548 : :
11549 : 536 : e.die = die;
11550 : 536 : e.name = xstrdup (str);
11551 : 536 : vec_safe_push (pubname_table, e);
11552 : 536 : }
11553 : :
11554 : : static void
11555 : 95596547 : add_pubname (tree decl, dw_die_ref die)
11556 : : {
11557 : 95596547 : if (!want_pubnames ())
11558 : : return;
11559 : :
11560 : : /* Don't add items to the table when we expect that the consumer will have
11561 : : just read the enclosing die. For example, if the consumer is looking at a
11562 : : class_member, it will either be inside the class already, or will have just
11563 : : looked up the class to find the member. Either way, searching the class is
11564 : : faster than searching the index. */
11565 : 527 : if ((TREE_PUBLIC (decl) && !class_scope_p (die->die_parent))
11566 : 749 : || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
11567 : : {
11568 : 503 : const char *name = dwarf2_name (decl, 1);
11569 : :
11570 : 503 : if (name)
11571 : 503 : add_pubname_string (name, die);
11572 : : }
11573 : : }
11574 : :
11575 : : /* Add an enumerator to the pubnames section. */
11576 : :
11577 : : static void
11578 : 36 : add_enumerator_pubname (const char *scope_name, dw_die_ref die)
11579 : : {
11580 : 36 : pubname_entry e;
11581 : :
11582 : 36 : gcc_assert (scope_name);
11583 : 36 : e.name = concat (scope_name, get_AT_string (die, DW_AT_name), NULL);
11584 : 36 : e.die = die;
11585 : 36 : vec_safe_push (pubname_table, e);
11586 : 36 : }
11587 : :
11588 : : /* Add a new entry to .debug_pubtypes if appropriate. */
11589 : :
11590 : : static void
11591 : 108773013 : add_pubtype (tree decl, dw_die_ref die)
11592 : : {
11593 : 108773013 : pubname_entry e;
11594 : :
11595 : 108773013 : if (!want_pubnames ())
11596 : 108772699 : return;
11597 : :
11598 : 314 : if ((TREE_PUBLIC (decl)
11599 : 494 : || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
11600 : 404 : && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11601 : : {
11602 : 290 : tree scope = NULL;
11603 : 290 : const char *scope_name = "";
11604 : 290 : const char *sep = is_cxx () ? "::" : ".";
11605 : 290 : const char *name;
11606 : :
11607 : 290 : scope = TYPE_P (decl) ? TYPE_CONTEXT (decl) : NULL;
11608 : 290 : if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
11609 : : {
11610 : 60 : scope_name = lang_hooks.dwarf_name (scope, 1);
11611 : 60 : if (scope_name != NULL && scope_name[0] != '\0')
11612 : 60 : scope_name = concat (scope_name, sep, NULL);
11613 : : else
11614 : : scope_name = "";
11615 : : }
11616 : :
11617 : 290 : if (TYPE_P (decl))
11618 : 290 : name = type_tag (decl);
11619 : : else
11620 : 0 : name = lang_hooks.dwarf_name (decl, 1);
11621 : :
11622 : : /* If we don't have a name for the type, there's no point in adding
11623 : : it to the table. */
11624 : 290 : if (name != NULL && name[0] != '\0')
11625 : : {
11626 : 290 : e.die = die;
11627 : 290 : e.name = concat (scope_name, name, NULL);
11628 : 290 : vec_safe_push (pubtype_table, e);
11629 : : }
11630 : :
11631 : : /* Although it might be more consistent to add the pubinfo for the
11632 : : enumerators as their dies are created, they should only be added if the
11633 : : enum type meets the criteria above. So rather than re-check the parent
11634 : : enum type whenever an enumerator die is created, just output them all
11635 : : here. This isn't protected by the name conditional because anonymous
11636 : : enums don't have names. */
11637 : 290 : if (die->die_tag == DW_TAG_enumeration_type)
11638 : : {
11639 : 12 : dw_die_ref c;
11640 : :
11641 : 36 : FOR_EACH_CHILD (die, c, add_enumerator_pubname (scope_name, c));
11642 : : }
11643 : : }
11644 : : }
11645 : :
11646 : : /* Output a single entry in the pubnames table. */
11647 : :
11648 : : static void
11649 : 791 : output_pubname (dw_offset die_offset, pubname_entry *entry)
11650 : : {
11651 : 791 : dw_die_ref die = entry->die;
11652 : 791 : int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
11653 : :
11654 : 791 : dw2_asm_output_data (dwarf_offset_size, die_offset, "DIE offset");
11655 : :
11656 : 791 : if (debug_generate_pub_sections == 2)
11657 : : {
11658 : : /* This logic follows gdb's method for determining the value of the flag
11659 : : byte. */
11660 : 445 : uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE;
11661 : 445 : switch (die->die_tag)
11662 : : {
11663 : : case DW_TAG_typedef:
11664 : : case DW_TAG_base_type:
11665 : : case DW_TAG_subrange_type:
11666 : : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
11667 : 192 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
11668 : : break;
11669 : 0 : case DW_TAG_enumerator:
11670 : 0 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11671 : : GDB_INDEX_SYMBOL_KIND_VARIABLE);
11672 : 0 : if (!is_cxx ())
11673 : 0 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
11674 : : break;
11675 : 244 : case DW_TAG_subprogram:
11676 : 244 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11677 : : GDB_INDEX_SYMBOL_KIND_FUNCTION);
11678 : 244 : if (!is_ada ())
11679 : 244 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
11680 : : break;
11681 : 0 : case DW_TAG_constant:
11682 : 0 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11683 : : GDB_INDEX_SYMBOL_KIND_VARIABLE);
11684 : 0 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
11685 : 0 : break;
11686 : 6 : case DW_TAG_variable:
11687 : 6 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
11688 : : GDB_INDEX_SYMBOL_KIND_VARIABLE);
11689 : 6 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
11690 : 6 : break;
11691 : : case DW_TAG_namespace:
11692 : : case DW_TAG_imported_declaration:
11693 : 3 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
11694 : : break;
11695 : 0 : case DW_TAG_class_type:
11696 : 0 : case DW_TAG_interface_type:
11697 : 0 : case DW_TAG_structure_type:
11698 : 0 : case DW_TAG_union_type:
11699 : 0 : case DW_TAG_enumeration_type:
11700 : 0 : GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
11701 : 0 : if (!is_cxx ())
11702 : 192 : GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
11703 : : break;
11704 : : default:
11705 : : /* An unusual tag. Leave the flag-byte empty. */
11706 : : break;
11707 : : }
11708 : 445 : dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE,
11709 : : "GDB-index flags");
11710 : : }
11711 : :
11712 : 791 : dw2_asm_output_nstring (entry->name, -1, "external name");
11713 : 791 : }
11714 : :
11715 : :
11716 : : /* Output the public names table used to speed up access to externally
11717 : : visible names; or the public types table used to find type definitions. */
11718 : :
11719 : : static void
11720 : 512 : output_pubnames (vec<pubname_entry, va_gc> *names)
11721 : : {
11722 : 512 : unsigned i;
11723 : 512 : unsigned long pubnames_length = size_of_pubnames (names);
11724 : 512 : pubname_entry *pub;
11725 : :
11726 : 512 : if (!XCOFF_DEBUGGING_INFO)
11727 : : {
11728 : 512 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11729 : 0 : dw2_asm_output_data (4, 0xffffffff,
11730 : : "Initial length escape value indicating 64-bit DWARF extension");
11731 : 512 : dw2_asm_output_data (dwarf_offset_size, pubnames_length,
11732 : : "Pub Info Length");
11733 : : }
11734 : :
11735 : : /* Version number for pubnames/pubtypes is independent of dwarf version. */
11736 : 512 : dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
11737 : :
11738 : 512 : if (dwarf_split_debug_info)
11739 : 498 : dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
11740 : : debug_skeleton_info_section,
11741 : : "Offset of Compilation Unit Info");
11742 : : else
11743 : 14 : dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
11744 : : debug_info_section,
11745 : : "Offset of Compilation Unit Info");
11746 : 512 : dw2_asm_output_data (dwarf_offset_size, next_die_offset,
11747 : : "Compilation Unit Length");
11748 : :
11749 : 1374 : FOR_EACH_VEC_ELT (*names, i, pub)
11750 : : {
11751 : 862 : if (include_pubname_in_output (names, pub))
11752 : : {
11753 : 791 : dw_offset die_offset = pub->die->die_offset;
11754 : :
11755 : : /* We shouldn't see pubnames for DIEs outside of the main CU. */
11756 : 791 : if (names == pubname_table && pub->die->die_tag != DW_TAG_enumerator)
11757 : 471 : gcc_assert (pub->die->die_mark);
11758 : :
11759 : : /* If we're putting types in their own .debug_types sections,
11760 : : the .debug_pubtypes table will still point to the compile
11761 : : unit (not the type unit), so we want to use the offset of
11762 : : the skeleton DIE (if there is one). */
11763 : 791 : if (pub->die->comdat_type_p && names == pubtype_table)
11764 : : {
11765 : 33 : comdat_type_node *type_node = pub->die->die_id.die_type_node;
11766 : :
11767 : 33 : if (type_node != NULL)
11768 : 33 : die_offset = (type_node->skeleton_die != NULL
11769 : 33 : ? type_node->skeleton_die->die_offset
11770 : 6 : : comp_unit_die ()->die_offset);
11771 : : }
11772 : :
11773 : 791 : output_pubname (die_offset, pub);
11774 : : }
11775 : : }
11776 : :
11777 : 512 : dw2_asm_output_data (dwarf_offset_size, 0, NULL);
11778 : 512 : }
11779 : :
11780 : : /* Output public names and types tables if necessary. */
11781 : :
11782 : : static void
11783 : 51974 : output_pubtables (void)
11784 : : {
11785 : 51974 : if (!want_pubnames () || !info_section_emitted)
11786 : : return;
11787 : :
11788 : 256 : switch_to_section (debug_pubnames_section);
11789 : 256 : output_pubnames (pubname_table);
11790 : : /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
11791 : : It shouldn't hurt to emit it always, since pure DWARF2 consumers
11792 : : simply won't look for the section. */
11793 : 256 : switch_to_section (debug_pubtypes_section);
11794 : 256 : output_pubnames (pubtype_table);
11795 : : }
11796 : :
11797 : :
11798 : : /* Output the information that goes into the .debug_aranges table.
11799 : : Namely, define the beginning and ending address range of the
11800 : : text section generated for this compilation unit. */
11801 : :
11802 : : static void
11803 : 50925 : output_aranges (void)
11804 : : {
11805 : 50925 : unsigned i;
11806 : 50925 : unsigned long aranges_length = size_of_aranges ();
11807 : :
11808 : 50925 : if (!XCOFF_DEBUGGING_INFO)
11809 : : {
11810 : 50925 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
11811 : 0 : dw2_asm_output_data (4, 0xffffffff,
11812 : : "Initial length escape value indicating 64-bit DWARF extension");
11813 : 50925 : dw2_asm_output_data (dwarf_offset_size, aranges_length,
11814 : : "Length of Address Ranges Info");
11815 : : }
11816 : :
11817 : : /* Version number for aranges is still 2, even up to DWARF5. */
11818 : 50925 : dw2_asm_output_data (2, 2, "DWARF aranges version");
11819 : 50925 : if (dwarf_split_debug_info)
11820 : 249 : dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
11821 : : debug_skeleton_info_section,
11822 : : "Offset of Compilation Unit Info");
11823 : : else
11824 : 50676 : dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
11825 : : debug_info_section,
11826 : : "Offset of Compilation Unit Info");
11827 : 57206 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11828 : 50925 : dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11829 : :
11830 : : /* We need to align to twice the pointer size here. */
11831 : 69768 : if (DWARF_ARANGES_PAD_SIZE)
11832 : : {
11833 : : /* Pad using a 2 byte words so that padding is correct for any
11834 : : pointer size. */
11835 : 50925 : dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11836 : 50923 : 2 * DWARF2_ADDR_SIZE);
11837 : 190461 : for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11838 : 50925 : dw2_asm_output_data (2, 0, NULL);
11839 : : }
11840 : :
11841 : : /* It is necessary not to output these entries if the sections were
11842 : : not used; if the sections were not used, the length will be 0 and
11843 : : the address may end up as 0 if the section is discarded by ld
11844 : : --gc-sections, leaving an invalid (0, 0) entry that can be
11845 : : confused with the terminator. */
11846 : 50925 : if (switch_text_ranges)
11847 : : {
11848 : : const char *prev_loc = text_section_label;
11849 : : const char *loc;
11850 : : unsigned idx;
11851 : :
11852 : 30108 : FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
11853 : 1025 : if (prev_loc)
11854 : : {
11855 : 826 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11856 : 626 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, loc, prev_loc, "Length");
11857 : 626 : prev_loc = NULL;
11858 : : }
11859 : : else
11860 : : prev_loc = loc;
11861 : :
11862 : 29083 : if (prev_loc)
11863 : : {
11864 : 31853 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11865 : 31853 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11866 : : prev_loc, "Length");
11867 : : }
11868 : : }
11869 : :
11870 : 50925 : if (switch_cold_ranges)
11871 : : {
11872 : : const char *prev_loc = cold_text_section_label;
11873 : : const char *loc;
11874 : : unsigned idx;
11875 : :
11876 : 8633 : FOR_EACH_VEC_ELT (*switch_cold_ranges, idx, loc)
11877 : 0 : if (prev_loc)
11878 : : {
11879 : 0 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11880 : 0 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, loc, prev_loc, "Length");
11881 : 0 : prev_loc = NULL;
11882 : : }
11883 : : else
11884 : : prev_loc = loc;
11885 : :
11886 : 8633 : if (prev_loc)
11887 : : {
11888 : 8927 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
11889 : 8927 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11890 : : prev_loc, "Length");
11891 : : }
11892 : : }
11893 : :
11894 : 50925 : if (have_multiple_function_sections)
11895 : : {
11896 : : unsigned fde_idx;
11897 : : dw_fde_ref fde;
11898 : :
11899 : 290201 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
11900 : : {
11901 : 262273 : if (fde->ignored_debug)
11902 : 2882 : continue;
11903 : 259391 : if (!fde->in_std_section)
11904 : : {
11905 : 200230 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
11906 : : "Address");
11907 : 200230 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
11908 : : fde->dw_fde_begin, "Length");
11909 : : }
11910 : 259391 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11911 : : {
11912 : 9640 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
11913 : : "Address");
11914 : 9640 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
11915 : : fde->dw_fde_second_begin, "Length");
11916 : : }
11917 : : }
11918 : : }
11919 : :
11920 : : /* Output the terminator words. */
11921 : 57206 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11922 : 57206 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11923 : 50925 : }
11924 : :
11925 : : /* Add a new entry to .debug_ranges. Return its index into
11926 : : ranges_table vector. */
11927 : :
11928 : : static unsigned int
11929 : 10635311 : add_ranges_num (int num, bool maybe_new_sec)
11930 : : {
11931 : 10635311 : dw_ranges r = { NULL, num, 0, maybe_new_sec, NULL, NULL };
11932 : 10635311 : vec_safe_push (ranges_table, r);
11933 : 10635311 : return vec_safe_length (ranges_table) - 1;
11934 : : }
11935 : :
11936 : : /* Add a new entry to .debug_ranges corresponding to a block, or a
11937 : : range terminator if BLOCK is NULL. MAYBE_NEW_SEC is true if
11938 : : this entry might be in a different section from previous range. */
11939 : :
11940 : : static unsigned int
11941 : 10377660 : add_ranges (const_tree block, bool maybe_new_sec)
11942 : : {
11943 : 15349338 : return add_ranges_num (block ? BLOCK_NUMBER (block) : 0, maybe_new_sec);
11944 : : }
11945 : :
11946 : : /* Note that (*rnglist_table)[offset] is either a head of a rnglist
11947 : : chain, or middle entry of a chain that will be directly referred to. */
11948 : :
11949 : : static void
11950 : 3179967 : note_rnglist_head (unsigned int offset)
11951 : : {
11952 : 3179967 : if (dwarf_version < 5 || (*ranges_table)[offset].label)
11953 : : return;
11954 : 2705656 : (*ranges_table)[offset].label = gen_internal_sym ("LLRL");
11955 : : }
11956 : :
11957 : : /* Add a new entry to .debug_ranges corresponding to a pair of labels.
11958 : : When using dwarf_split_debug_info, address attributes in dies destined
11959 : : for the final executable should be direct references--setting the
11960 : : parameter force_direct ensures this behavior. */
11961 : :
11962 : : static void
11963 : 257651 : add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11964 : : bool *added, bool force_direct)
11965 : : {
11966 : 257651 : unsigned int in_use = vec_safe_length (ranges_by_label);
11967 : 257651 : unsigned int offset;
11968 : 257651 : dw_ranges_by_label rbl = { begin, end };
11969 : 257651 : vec_safe_push (ranges_by_label, rbl);
11970 : 257651 : offset = add_ranges_num (-(int)in_use - 1, true);
11971 : 257651 : if (!*added)
11972 : : {
11973 : 48145 : add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
11974 : 48145 : *added = true;
11975 : 48145 : note_rnglist_head (offset);
11976 : 48145 : if (dwarf_split_debug_info && force_direct)
11977 : 2 : (*ranges_table)[offset].idx = DW_RANGES_IDX_SKELETON;
11978 : : }
11979 : 257651 : }
11980 : :
11981 : : /* Emit .debug_ranges section. */
11982 : :
11983 : : static void
11984 : 528 : output_ranges (void)
11985 : : {
11986 : 528 : unsigned i;
11987 : 528 : static const char *const start_fmt = "Offset %#x";
11988 : 528 : const char *fmt = start_fmt;
11989 : 528 : dw_ranges *r;
11990 : :
11991 : 528 : switch_to_section (debug_ranges_section);
11992 : 528 : ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
11993 : 4613 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
11994 : : {
11995 : 4085 : int block_num = r->num;
11996 : :
11997 : 4085 : if (block_num > 0)
11998 : : {
11999 : 1728 : char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12000 : 1728 : char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12001 : :
12002 : 1728 : ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12003 : 1728 : ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12004 : :
12005 : : /* If all code is in the text section, then the compilation
12006 : : unit base address defaults to DW_AT_low_pc, which is the
12007 : : base of the text section. */
12008 : 1728 : if (!have_multiple_function_sections)
12009 : : {
12010 : 418 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
12011 : : text_section_label,
12012 : 418 : fmt, i * 2 * DWARF2_ADDR_SIZE);
12013 : 418 : dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
12014 : : text_section_label, NULL);
12015 : : }
12016 : :
12017 : : /* Otherwise, the compilation unit base address is zero,
12018 : : which allows us to use absolute addresses, and not worry
12019 : : about whether the target supports cross-section
12020 : : arithmetic. */
12021 : : else
12022 : : {
12023 : 1310 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12024 : 1310 : fmt, i * 2 * DWARF2_ADDR_SIZE);
12025 : 1310 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
12026 : : }
12027 : :
12028 : 1728 : fmt = NULL;
12029 : : }
12030 : :
12031 : : /* Negative block_num stands for an index into ranges_by_label. */
12032 : 2357 : else if (block_num < 0)
12033 : : {
12034 : 1265 : int lab_idx = - block_num - 1;
12035 : :
12036 : 1265 : if (!have_multiple_function_sections)
12037 : : {
12038 : 0 : gcc_unreachable ();
12039 : : #if 0
12040 : : /* If we ever use add_ranges_by_labels () for a single
12041 : : function section, all we have to do is to take out
12042 : : the #if 0 above. */
12043 : : dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12044 : : (*ranges_by_label)[lab_idx].begin,
12045 : : text_section_label,
12046 : : fmt, i * 2 * DWARF2_ADDR_SIZE);
12047 : : dw2_asm_output_delta (DWARF2_ADDR_SIZE,
12048 : : (*ranges_by_label)[lab_idx].end,
12049 : : text_section_label, NULL);
12050 : : #endif
12051 : : }
12052 : : else
12053 : : {
12054 : 1265 : dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12055 : 1265 : (*ranges_by_label)[lab_idx].begin,
12056 : 1265 : fmt, i * 2 * DWARF2_ADDR_SIZE);
12057 : 1265 : dw2_asm_output_addr (DWARF2_ADDR_SIZE,
12058 : 1265 : (*ranges_by_label)[lab_idx].end,
12059 : : NULL);
12060 : : }
12061 : : }
12062 : : else
12063 : : {
12064 : 1092 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12065 : 1092 : dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
12066 : 1092 : fmt = start_fmt;
12067 : : }
12068 : : }
12069 : 528 : }
12070 : :
12071 : : /* Non-zero if .debug_line_str should be used for .debug_line section
12072 : : strings or strings that are likely shareable with those. */
12073 : : #define DWARF5_USE_DEBUG_LINE_STR \
12074 : : (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET \
12075 : : && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0 \
12076 : : /* FIXME: there is no .debug_line_str.dwo section, \
12077 : : for -gsplit-dwarf we should use DW_FORM_strx instead. */ \
12078 : : && !dwarf_split_debug_info)
12079 : :
12080 : :
12081 : : /* Returns TRUE if we are outputting DWARF5 and the assembler supports
12082 : : DWARF5 .debug_line tables using .debug_line_str or we generate
12083 : : it ourselves, except for split-dwarf which doesn't have a
12084 : : .debug_line_str. */
12085 : : static bool
12086 : 158936 : asm_outputs_debug_line_str (void)
12087 : : {
12088 : 158936 : if (dwarf_version >= 5
12089 : 152844 : && ! output_asm_line_debug_info ()
12090 : 158942 : && DWARF5_USE_DEBUG_LINE_STR)
12091 : : return true;
12092 : : else
12093 : : {
12094 : : #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
12095 : 165766 : return !dwarf_split_debug_info && dwarf_version >= 5;
12096 : : #else
12097 : : return false;
12098 : : #endif
12099 : : }
12100 : : }
12101 : :
12102 : : /* Return true if it is beneficial to use DW_RLE_base_address{,x}.
12103 : : I is index of the following range. */
12104 : :
12105 : : static bool
12106 : 2523426 : use_distinct_base_address_for_range (unsigned int i)
12107 : : {
12108 : 2661769 : if (i >= vec_safe_length (ranges_table))
12109 : : return false;
12110 : :
12111 : 2523426 : dw_ranges *r2 = &(*ranges_table)[i];
12112 : : /* Use DW_RLE_base_address{,x} if there is a next range in the
12113 : : range list and is guaranteed to be in the same section. */
12114 : 2523426 : return r2->num != 0 && r2->label == NULL && !r2->maybe_new_sec;
12115 : : }
12116 : :
12117 : : /* Assign .debug_rnglists indexes and unique indexes into the debug_addr
12118 : : section when needed. */
12119 : :
12120 : : static void
12121 : 3 : index_rnglists (void)
12122 : : {
12123 : 3 : unsigned i;
12124 : 3 : dw_ranges *r;
12125 : 3 : bool base = false;
12126 : :
12127 : 19 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12128 : : {
12129 : 16 : if (r->label && r->idx != DW_RANGES_IDX_SKELETON)
12130 : 3 : r->idx = rnglist_idx++;
12131 : :
12132 : 16 : int block_num = r->num;
12133 : 20 : if ((HAVE_AS_LEB128 || block_num < 0)
12134 : 16 : && !have_multiple_function_sections)
12135 : 4 : continue;
12136 : 12 : if (HAVE_AS_LEB128 && (r->label || r->maybe_new_sec))
12137 : 8 : base = false;
12138 : 12 : if (block_num > 0)
12139 : : {
12140 : 0 : char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12141 : 0 : char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12142 : :
12143 : 0 : ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12144 : 0 : ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12145 : :
12146 : 0 : if (HAVE_AS_LEB128)
12147 : : {
12148 : 0 : if (!base && use_distinct_base_address_for_range (i + 1))
12149 : : {
12150 : 0 : r->begin_entry = add_addr_table_entry (xstrdup (blabel),
12151 : : ate_kind_label);
12152 : 0 : base = true;
12153 : : }
12154 : 0 : if (base)
12155 : : /* If we have a base, no need for further
12156 : : begin_entry/end_entry, as DW_RLE_offset_pair will be
12157 : : used. */
12158 : 0 : continue;
12159 : 0 : r->begin_entry
12160 : 0 : = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
12161 : : /* No need for end_entry, DW_RLE_start{,x}_length will use
12162 : : length as opposed to a pair of addresses. */
12163 : : }
12164 : : else
12165 : : {
12166 : : r->begin_entry
12167 : : = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
12168 : : r->end_entry
12169 : : = add_addr_table_entry (xstrdup (elabel), ate_kind_label);
12170 : : }
12171 : : }
12172 : :
12173 : : /* Negative block_num stands for an index into ranges_by_label. */
12174 : 12 : else if (block_num < 0)
12175 : : {
12176 : 8 : int lab_idx = - block_num - 1;
12177 : 8 : const char *blabel = (*ranges_by_label)[lab_idx].begin;
12178 : 8 : const char *elabel = (*ranges_by_label)[lab_idx].end;
12179 : :
12180 : 8 : r->begin_entry
12181 : 8 : = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
12182 : 8 : if (!HAVE_AS_LEB128)
12183 : : r->end_entry
12184 : : = add_addr_table_entry (xstrdup (elabel), ate_kind_label);
12185 : : }
12186 : : }
12187 : 3 : }
12188 : :
12189 : : /* Emit .debug_rnglists or (when DWO is true) .debug_rnglists.dwo section. */
12190 : :
12191 : : static bool
12192 : 32025 : output_rnglists (unsigned generation, bool dwo)
12193 : : {
12194 : 32025 : unsigned i;
12195 : 32025 : dw_ranges *r;
12196 : 32025 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
12197 : 32025 : char l2[MAX_ARTIFICIAL_LABEL_BYTES];
12198 : 32025 : char basebuf[MAX_ARTIFICIAL_LABEL_BYTES];
12199 : :
12200 : 32025 : if (dwo)
12201 : 3 : switch_to_section (debug_ranges_dwo_section);
12202 : : else
12203 : : {
12204 : 32022 : switch_to_section (debug_ranges_section);
12205 : 32022 : ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12206 : : }
12207 : : /* There are up to 4 unique ranges labels per generation.
12208 : : See also init_sections_and_labels. */
12209 : 32025 : ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_RANGES_SECTION_LABEL,
12210 : : 2 + 2 * dwo + generation * 6);
12211 : 32025 : ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_RANGES_SECTION_LABEL,
12212 : : 3 + 2 * dwo + generation * 6);
12213 : 32025 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
12214 : 0 : dw2_asm_output_data (4, 0xffffffff,
12215 : : "Initial length escape value indicating "
12216 : : "64-bit DWARF extension");
12217 : 32025 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
12218 : : "Length of Range Lists");
12219 : 32025 : ASM_OUTPUT_LABEL (asm_out_file, l1);
12220 : 32025 : output_dwarf_version ();
12221 : 36475 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
12222 : 32025 : dw2_asm_output_data (1, 0, "Segment Size");
12223 : : /* Emit the offset table only for -gsplit-dwarf. If we don't care
12224 : : about relocation sizes and primarily care about the size of .debug*
12225 : : sections in linked shared libraries and executables, then
12226 : : the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
12227 : : into it are usually larger than just DW_FORM_sec_offset offsets
12228 : : into the .debug_rnglists section. */
12229 : 32025 : dw2_asm_output_data (4, dwo ? rnglist_idx : 0,
12230 : : "Offset Entry Count");
12231 : 32025 : if (dwo)
12232 : : {
12233 : 3 : ASM_OUTPUT_LABEL (asm_out_file, ranges_base_label);
12234 : 22 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12235 : 16 : if (r->label && r->idx != DW_RANGES_IDX_SKELETON)
12236 : 3 : dw2_asm_output_delta (dwarf_offset_size, r->label,
12237 : : ranges_base_label, NULL);
12238 : : }
12239 : :
12240 : : const char *lab = "";
12241 : : const char *base = NULL;
12242 : : bool skipping = false;
12243 : : bool ret = false;
12244 : 10663260 : FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
12245 : : {
12246 : 10631235 : int block_num = r->num;
12247 : :
12248 : 10631235 : if (r->label)
12249 : : {
12250 : 2705659 : if (dwarf_split_debug_info
12251 : 9 : && (r->idx == DW_RANGES_IDX_SKELETON) == dwo)
12252 : : {
12253 : 4 : ret = true;
12254 : 4 : skipping = true;
12255 : 4 : continue;
12256 : : }
12257 : 2705655 : ASM_OUTPUT_LABEL (asm_out_file, r->label);
12258 : 2705655 : lab = r->label;
12259 : : }
12260 : 10631231 : if (skipping)
12261 : : {
12262 : 8 : if (block_num == 0)
12263 : 4 : skipping = false;
12264 : 8 : continue;
12265 : : }
12266 : 10631223 : if (HAVE_AS_LEB128 && (r->label || r->maybe_new_sec))
12267 : 3025381 : base = NULL;
12268 : 10631223 : if (block_num > 0)
12269 : : {
12270 : 7672939 : char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
12271 : 7672939 : char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
12272 : :
12273 : 7672939 : ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
12274 : 7672939 : ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
12275 : :
12276 : 7672939 : if (HAVE_AS_LEB128)
12277 : : {
12278 : : /* If all code is in the text section, then the compilation
12279 : : unit base address defaults to DW_AT_low_pc, which is the
12280 : : base of the text section. */
12281 : 7672939 : if (!have_multiple_function_sections)
12282 : : {
12283 : 826284 : dw2_asm_output_data (1, DW_RLE_offset_pair,
12284 : : "DW_RLE_offset_pair (%s)", lab);
12285 : 826284 : dw2_asm_output_delta_uleb128 (blabel, text_section_label,
12286 : : "Range begin address (%s)", lab);
12287 : 826284 : dw2_asm_output_delta_uleb128 (elabel, text_section_label,
12288 : : "Range end address (%s)", lab);
12289 : 7534596 : continue;
12290 : : }
12291 : 6846655 : if (base == NULL && use_distinct_base_address_for_range (i + 1))
12292 : : {
12293 : 2385083 : if (dwarf_split_debug_info)
12294 : : {
12295 : 0 : dw2_asm_output_data (1, DW_RLE_base_addressx,
12296 : : "DW_RLE_base_addressx (%s)", lab);
12297 : 0 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12298 : : "Base address index (%s)",
12299 : : blabel);
12300 : : }
12301 : : else
12302 : : {
12303 : 2385083 : dw2_asm_output_data (1, DW_RLE_base_address,
12304 : : "DW_RLE_base_address (%s)", lab);
12305 : 2483098 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12306 : : "Base address (%s)", lab);
12307 : : }
12308 : 2385083 : strcpy (basebuf, blabel);
12309 : 2385083 : base = basebuf;
12310 : : }
12311 : 6846655 : if (base)
12312 : : {
12313 : 6708312 : dw2_asm_output_data (1, DW_RLE_offset_pair,
12314 : : "DW_RLE_offset_pair (%s)", lab);
12315 : 6708312 : dw2_asm_output_delta_uleb128 (blabel, base,
12316 : : "Range begin address (%s)", lab);
12317 : 6708312 : dw2_asm_output_delta_uleb128 (elabel, base,
12318 : : "Range end address (%s)", lab);
12319 : 6708312 : continue;
12320 : : }
12321 : 138343 : if (dwarf_split_debug_info)
12322 : : {
12323 : 0 : dw2_asm_output_data (1, DW_RLE_startx_length,
12324 : : "DW_RLE_startx_length (%s)", lab);
12325 : 0 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12326 : : "Range begin address index "
12327 : : "(%s)", blabel);
12328 : : }
12329 : : else
12330 : : {
12331 : 138343 : dw2_asm_output_data (1, DW_RLE_start_length,
12332 : : "DW_RLE_start_length (%s)", lab);
12333 : 141938 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12334 : : "Range begin address (%s)", lab);
12335 : : }
12336 : 138343 : dw2_asm_output_delta_uleb128 (elabel, blabel,
12337 : : "Range length (%s)", lab);
12338 : : }
12339 : : else if (dwarf_split_debug_info)
12340 : : {
12341 : : dw2_asm_output_data (1, DW_RLE_startx_endx,
12342 : : "DW_RLE_startx_endx (%s)", lab);
12343 : : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12344 : : "Range begin address index "
12345 : : "(%s)", blabel);
12346 : : dw2_asm_output_data_uleb128 (r->end_entry->index,
12347 : : "Range end address index "
12348 : : "(%s)", elabel);
12349 : : }
12350 : : else
12351 : : {
12352 : : dw2_asm_output_data (1, DW_RLE_start_end,
12353 : : "DW_RLE_start_end (%s)", lab);
12354 : : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12355 : : "Range begin address (%s)", lab);
12356 : : dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel,
12357 : : "Range end address (%s)", lab);
12358 : : }
12359 : : }
12360 : :
12361 : : /* Negative block_num stands for an index into ranges_by_label. */
12362 : 2958284 : else if (block_num < 0)
12363 : : {
12364 : 256386 : int lab_idx = - block_num - 1;
12365 : 256386 : const char *blabel = (*ranges_by_label)[lab_idx].begin;
12366 : 256386 : const char *elabel = (*ranges_by_label)[lab_idx].end;
12367 : :
12368 : 256386 : if (!have_multiple_function_sections)
12369 : 0 : gcc_unreachable ();
12370 : 256386 : if (HAVE_AS_LEB128)
12371 : : {
12372 : 256386 : if (dwarf_split_debug_info)
12373 : : {
12374 : 8 : dw2_asm_output_data (1, DW_RLE_startx_length,
12375 : : "DW_RLE_startx_length (%s)", lab);
12376 : 8 : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12377 : : "Range begin address index "
12378 : : "(%s)", blabel);
12379 : : }
12380 : : else
12381 : : {
12382 : 256378 : dw2_asm_output_data (1, DW_RLE_start_length,
12383 : : "DW_RLE_start_length (%s)", lab);
12384 : 271348 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12385 : : "Range begin address (%s)", lab);
12386 : : }
12387 : 256386 : dw2_asm_output_delta_uleb128 (elabel, blabel,
12388 : : "Range length (%s)", lab);
12389 : : }
12390 : : else if (dwarf_split_debug_info)
12391 : : {
12392 : : dw2_asm_output_data (1, DW_RLE_startx_endx,
12393 : : "DW_RLE_startx_endx (%s)", lab);
12394 : : dw2_asm_output_data_uleb128 (r->begin_entry->index,
12395 : : "Range begin address index "
12396 : : "(%s)", blabel);
12397 : : dw2_asm_output_data_uleb128 (r->end_entry->index,
12398 : : "Range end address index "
12399 : : "(%s)", elabel);
12400 : : }
12401 : : else
12402 : : {
12403 : : dw2_asm_output_data (1, DW_RLE_start_end,
12404 : : "DW_RLE_start_end (%s)", lab);
12405 : : dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
12406 : : "Range begin address (%s)", lab);
12407 : : dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel,
12408 : : "Range end address (%s)", lab);
12409 : : }
12410 : : }
12411 : : else
12412 : 2701898 : dw2_asm_output_data (1, DW_RLE_end_of_list,
12413 : : "DW_RLE_end_of_list (%s)", lab);
12414 : : }
12415 : 32025 : ASM_OUTPUT_LABEL (asm_out_file, l2);
12416 : 32025 : return ret;
12417 : : }
12418 : :
12419 : : /* Data structure containing information about input files. */
12420 : : struct file_info
12421 : : {
12422 : : const char *path; /* Complete file name. */
12423 : : const char *fname; /* File name part. */
12424 : : int length; /* Length of entire string. */
12425 : : struct dwarf_file_data * file_idx; /* Index in input file table. */
12426 : : int dir_idx; /* Index in directory table. */
12427 : : };
12428 : :
12429 : : /* Data structure containing information about directories with source
12430 : : files. */
12431 : : struct dir_info
12432 : : {
12433 : : const char *path; /* Path including directory name. */
12434 : : int length; /* Path length. */
12435 : : int prefix; /* Index of directory entry which is a prefix. */
12436 : : int count; /* Number of files in this directory. */
12437 : : int dir_idx; /* Index of directory used as base. */
12438 : : };
12439 : :
12440 : : /* Callback function for file_info comparison. We sort by looking at
12441 : : the directories in the path. */
12442 : :
12443 : : static int
12444 : 90206 : file_info_cmp (const void *p1, const void *p2)
12445 : : {
12446 : 90206 : const struct file_info *const s1 = (const struct file_info *) p1;
12447 : 90206 : const struct file_info *const s2 = (const struct file_info *) p2;
12448 : 90206 : const unsigned char *cp1;
12449 : 90206 : const unsigned char *cp2;
12450 : :
12451 : : /* Take care of file names without directories. We need to make sure that
12452 : : we return consistent values to qsort since some will get confused if
12453 : : we return the same value when identical operands are passed in opposite
12454 : : orders. So if neither has a directory, return 0 and otherwise return
12455 : : 1 or -1 depending on which one has the directory. We want the one with
12456 : : the directory to sort after the one without, so all no directory files
12457 : : are at the start (normally only the compilation unit file). */
12458 : 90206 : if ((s1->path == s1->fname || s2->path == s2->fname))
12459 : 1660 : return (s2->path == s2->fname) - (s1->path == s1->fname);
12460 : :
12461 : : cp1 = (const unsigned char *) s1->path;
12462 : : cp2 = (const unsigned char *) s2->path;
12463 : :
12464 : 3828826 : while (1)
12465 : : {
12466 : 3828826 : ++cp1;
12467 : 3828826 : ++cp2;
12468 : : /* Reached the end of the first path? If so, handle like above,
12469 : : but now we want longer directory prefixes before shorter ones. */
12470 : 3828826 : if ((cp1 == (const unsigned char *) s1->fname)
12471 : 3795574 : || (cp2 == (const unsigned char *) s2->fname))
12472 : 48241 : return ((cp1 == (const unsigned char *) s1->fname)
12473 : 48241 : - (cp2 == (const unsigned char *) s2->fname));
12474 : :
12475 : : /* Character of current path component the same? */
12476 : 3780585 : else if (*cp1 != *cp2)
12477 : 40305 : return *cp1 - *cp2;
12478 : : }
12479 : : }
12480 : :
12481 : : struct file_name_acquire_data
12482 : : {
12483 : : struct file_info *files;
12484 : : int used_files;
12485 : : int max_files;
12486 : : };
12487 : :
12488 : : /* Traversal function for the hash table. */
12489 : :
12490 : : int
12491 : 8830 : file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
12492 : : {
12493 : 8830 : struct dwarf_file_data *d = *slot;
12494 : 8830 : struct file_info *fi;
12495 : 8830 : const char *f;
12496 : :
12497 : 8830 : gcc_assert (fnad->max_files >= d->emitted_number);
12498 : :
12499 : 8830 : if (! d->emitted_number)
12500 : : return 1;
12501 : :
12502 : 4399 : gcc_assert (fnad->max_files != fnad->used_files);
12503 : :
12504 : 4399 : fi = fnad->files + fnad->used_files++;
12505 : :
12506 : 4399 : f = d->filename;
12507 : :
12508 : : /* Skip all leading "./". */
12509 : 4399 : while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12510 : 0 : f += 2;
12511 : :
12512 : : /* Create a new array entry. */
12513 : 4399 : fi->path = f;
12514 : 4399 : fi->length = strlen (f);
12515 : 4399 : fi->file_idx = d;
12516 : :
12517 : : /* Search for the file name part. */
12518 : 4399 : f = strrchr (f, DIR_SEPARATOR);
12519 : : #if defined (DIR_SEPARATOR_2)
12520 : : {
12521 : : const char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12522 : :
12523 : : if (g != NULL)
12524 : : {
12525 : : if (f == NULL || f < g)
12526 : : f = g;
12527 : : }
12528 : : }
12529 : : #endif
12530 : :
12531 : 4399 : fi->fname = f == NULL ? fi->path : f + 1;
12532 : 4399 : return 1;
12533 : : }
12534 : :
12535 : : /* Helper function for output_file_names. Emit a FORM encoded
12536 : : string STR, with assembly comment start ENTRY_KIND and
12537 : : index IDX */
12538 : :
12539 : : static void
12540 : 9075 : output_line_string (enum dwarf_form form, const char *str,
12541 : : const char *entry_kind, unsigned int idx)
12542 : : {
12543 : 9075 : switch (form)
12544 : : {
12545 : 563 : case DW_FORM_string:
12546 : 563 : dw2_asm_output_nstring (str, -1, "%s: %#x", entry_kind, idx);
12547 : 563 : break;
12548 : 8512 : case DW_FORM_line_strp:
12549 : 8512 : if (!debug_line_str_hash)
12550 : 0 : debug_line_str_hash
12551 : 0 : = hash_table<indirect_string_hasher>::create_ggc (10);
12552 : :
12553 : 8512 : struct indirect_string_node *node;
12554 : 8512 : node = find_AT_string_in_table (str, debug_line_str_hash);
12555 : 8512 : set_indirect_string (node);
12556 : 8512 : node->form = form;
12557 : 8512 : dw2_asm_output_offset (dwarf_offset_size, node->label,
12558 : : debug_line_str_section, "%s: %#x: \"%s\"",
12559 : : entry_kind, 0, node->str);
12560 : 8512 : break;
12561 : 0 : default:
12562 : 0 : gcc_unreachable ();
12563 : : }
12564 : 9075 : }
12565 : :
12566 : : /* Output the directory table and the file name table. We try to minimize
12567 : : the total amount of memory needed. A heuristic is used to avoid large
12568 : : slowdowns with many input files. */
12569 : :
12570 : : static void
12571 : 1578 : output_file_names (void)
12572 : : {
12573 : 1578 : struct file_name_acquire_data fnad;
12574 : 1578 : int numfiles;
12575 : 1578 : struct file_info *files;
12576 : 1578 : struct dir_info *dirs;
12577 : 1578 : int *saved;
12578 : 1578 : int *savehere;
12579 : 1578 : int *backmap;
12580 : 1578 : int ndirs;
12581 : 1578 : int idx_offset;
12582 : 1578 : int i;
12583 : :
12584 : 1578 : if (!last_emitted_file)
12585 : : {
12586 : 17 : if (dwarf_version >= 5)
12587 : : {
12588 : 17 : const char *comp_dir = comp_dir_string ();
12589 : 17 : if (comp_dir == NULL)
12590 : 0 : comp_dir = "";
12591 : 17 : dw2_asm_output_data (1, 1, "Directory entry format count");
12592 : 17 : enum dwarf_form str_form = DW_FORM_string;
12593 : 17 : if (DWARF5_USE_DEBUG_LINE_STR)
12594 : 17 : str_form = DW_FORM_line_strp;
12595 : 17 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12596 : 17 : dw2_asm_output_data_uleb128 (str_form, "%s",
12597 : : get_DW_FORM_name (str_form));
12598 : 17 : dw2_asm_output_data_uleb128 (1, "Directories count");
12599 : 17 : if (str_form == DW_FORM_string)
12600 : 3 : dw2_asm_output_nstring (comp_dir, -1, "Directory Entry: %#x", 0);
12601 : : else
12602 : 14 : output_line_string (str_form, comp_dir, "Directory Entry", 0);
12603 : 17 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
12604 : 17 : if (filename0 == NULL)
12605 : 0 : filename0 = "";
12606 : : #ifdef VMS_DEBUGGING_INFO
12607 : : dw2_asm_output_data (1, 4, "File name entry format count");
12608 : : #else
12609 : 17 : dw2_asm_output_data (1, 2, "File name entry format count");
12610 : : #endif
12611 : 17 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12612 : 17 : dw2_asm_output_data_uleb128 (str_form, "%s",
12613 : : get_DW_FORM_name (str_form));
12614 : 17 : dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
12615 : : "DW_LNCT_directory_index");
12616 : 17 : dw2_asm_output_data_uleb128 (DW_FORM_data1, "%s",
12617 : : get_DW_FORM_name (DW_FORM_data1));
12618 : : #ifdef VMS_DEBUGGING_INFO
12619 : : dw2_asm_output_data_uleb128 (DW_LNCT_timestamp, "DW_LNCT_timestamp");
12620 : : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12621 : : dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
12622 : : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12623 : : #endif
12624 : 17 : dw2_asm_output_data_uleb128 (1, "File names count");
12625 : :
12626 : 17 : output_line_string (str_form, filename0, "File Entry", 0);
12627 : 17 : dw2_asm_output_data (1, 0, NULL);
12628 : : #ifdef VMS_DEBUGGING_INFO
12629 : : dw2_asm_output_data_uleb128 (0, NULL);
12630 : : dw2_asm_output_data_uleb128 (0, NULL);
12631 : : #endif
12632 : : }
12633 : : else
12634 : : {
12635 : 0 : dw2_asm_output_data (1, 0, "End directory table");
12636 : 0 : dw2_asm_output_data (1, 0, "End file name table");
12637 : : }
12638 : 17 : return;
12639 : : }
12640 : :
12641 : 1561 : numfiles = last_emitted_file->emitted_number;
12642 : :
12643 : : /* Allocate the various arrays we need. */
12644 : 1561 : files = XALLOCAVEC (struct file_info, numfiles);
12645 : 1561 : dirs = XALLOCAVEC (struct dir_info, numfiles);
12646 : :
12647 : 1561 : fnad.files = files;
12648 : 1561 : fnad.used_files = 0;
12649 : 1561 : fnad.max_files = numfiles;
12650 : 10391 : file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
12651 : 1561 : gcc_assert (fnad.used_files == fnad.max_files);
12652 : :
12653 : 1561 : qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12654 : :
12655 : : /* Find all the different directories used. */
12656 : 1561 : dirs[0].path = files[0].path;
12657 : 1561 : dirs[0].length = files[0].fname - files[0].path;
12658 : 1561 : dirs[0].prefix = -1;
12659 : 1561 : dirs[0].count = 1;
12660 : 1561 : dirs[0].dir_idx = 0;
12661 : 1561 : files[0].dir_idx = 0;
12662 : 1561 : ndirs = 1;
12663 : :
12664 : 4399 : for (i = 1; i < numfiles; i++)
12665 : 2838 : if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12666 : 1936 : && memcmp (dirs[ndirs - 1].path, files[i].path,
12667 : : dirs[ndirs - 1].length) == 0)
12668 : : {
12669 : : /* Same directory as last entry. */
12670 : 1933 : files[i].dir_idx = ndirs - 1;
12671 : 1933 : ++dirs[ndirs - 1].count;
12672 : : }
12673 : : else
12674 : : {
12675 : 905 : int j;
12676 : :
12677 : : /* This is a new directory. */
12678 : 905 : dirs[ndirs].path = files[i].path;
12679 : 905 : dirs[ndirs].length = files[i].fname - files[i].path;
12680 : 905 : dirs[ndirs].count = 1;
12681 : 905 : dirs[ndirs].dir_idx = ndirs;
12682 : 905 : files[i].dir_idx = ndirs;
12683 : :
12684 : : /* Search for a prefix. */
12685 : 905 : dirs[ndirs].prefix = -1;
12686 : 4625 : for (j = 0; j < ndirs; j++)
12687 : 3720 : if (dirs[j].length < dirs[ndirs].length
12688 : 1304 : && dirs[j].length > 1
12689 : 886 : && (dirs[ndirs].prefix == -1
12690 : 0 : || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12691 : 886 : && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12692 : 0 : dirs[ndirs].prefix = j;
12693 : :
12694 : 905 : ++ndirs;
12695 : : }
12696 : :
12697 : : /* Now to the actual work. We have to find a subset of the directories which
12698 : : allow expressing the file name using references to the directory table
12699 : : with the least amount of characters. We do not do an exhaustive search
12700 : : where we would have to check out every combination of every single
12701 : : possible prefix. Instead we use a heuristic which provides nearly optimal
12702 : : results in most cases and never is much off. */
12703 : 1561 : saved = XALLOCAVEC (int, ndirs);
12704 : 1561 : savehere = XALLOCAVEC (int, ndirs);
12705 : :
12706 : 1561 : memset (saved, '\0', ndirs * sizeof (saved[0]));
12707 : 4027 : for (i = 0; i < ndirs; i++)
12708 : : {
12709 : 2466 : int j;
12710 : 2466 : int total;
12711 : :
12712 : : /* We can always save some space for the current directory. But this
12713 : : does not mean it will be enough to justify adding the directory. */
12714 : 2466 : savehere[i] = dirs[i].length;
12715 : 2466 : total = (savehere[i] - saved[i]) * dirs[i].count;
12716 : :
12717 : 6186 : for (j = i + 1; j < ndirs; j++)
12718 : : {
12719 : 3720 : savehere[j] = 0;
12720 : 3720 : if (saved[j] < dirs[i].length)
12721 : : {
12722 : : /* Determine whether the dirs[i] path is a prefix of the
12723 : : dirs[j] path. */
12724 : 3302 : int k;
12725 : :
12726 : 3302 : k = dirs[j].prefix;
12727 : 3302 : while (k != -1 && k != (int) i)
12728 : 0 : k = dirs[k].prefix;
12729 : :
12730 : 3302 : if (k == (int) i)
12731 : : {
12732 : : /* Yes it is. We can possibly save some memory by
12733 : : writing the filenames in dirs[j] relative to
12734 : : dirs[i]. */
12735 : 0 : savehere[j] = dirs[i].length;
12736 : 0 : total += (savehere[j] - saved[j]) * dirs[j].count;
12737 : : }
12738 : : }
12739 : : }
12740 : :
12741 : : /* Check whether we can save enough to justify adding the dirs[i]
12742 : : directory. */
12743 : 2466 : if (total > dirs[i].length + 1)
12744 : : {
12745 : : /* It's worthwhile adding. */
12746 : 2146 : for (j = i; j < ndirs; j++)
12747 : 1730 : if (savehere[j] > 0)
12748 : : {
12749 : : /* Remember how much we saved for this directory so far. */
12750 : 416 : saved[j] = savehere[j];
12751 : :
12752 : : /* Remember the prefix directory. */
12753 : 416 : dirs[j].dir_idx = i;
12754 : : }
12755 : : }
12756 : : }
12757 : :
12758 : : /* Emit the directory name table. */
12759 : 1561 : idx_offset = dirs[0].length > 0 ? 1 : 0;
12760 : 1561 : enum dwarf_form str_form = DW_FORM_string;
12761 : 1561 : enum dwarf_form idx_form = DW_FORM_udata;
12762 : 1561 : if (dwarf_version >= 5)
12763 : : {
12764 : 1510 : const char *comp_dir = comp_dir_string ();
12765 : 1510 : if (comp_dir == NULL)
12766 : 0 : comp_dir = "";
12767 : 1510 : dw2_asm_output_data (1, 1, "Directory entry format count");
12768 : 1510 : if (DWARF5_USE_DEBUG_LINE_STR)
12769 : 1510 : str_form = DW_FORM_line_strp;
12770 : 1510 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12771 : 1510 : dw2_asm_output_data_uleb128 (str_form, "%s",
12772 : : get_DW_FORM_name (str_form));
12773 : 1510 : dw2_asm_output_data_uleb128 (ndirs + idx_offset, "Directories count");
12774 : 1510 : if (str_form == DW_FORM_string)
12775 : : {
12776 : 245 : dw2_asm_output_nstring (comp_dir, -1, "Directory Entry: %#x", 0);
12777 : 492 : for (i = 1 - idx_offset; i < ndirs; i++)
12778 : 247 : dw2_asm_output_nstring (dirs[i].path,
12779 : 247 : dirs[i].length
12780 : 247 : - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12781 : : "Directory Entry: %#x", i + idx_offset);
12782 : : }
12783 : : else
12784 : : {
12785 : 1265 : output_line_string (str_form, comp_dir, "Directory Entry", 0);
12786 : 3135 : for (i = 1 - idx_offset; i < ndirs; i++)
12787 : : {
12788 : 1870 : const char *str
12789 : 3740 : = ggc_alloc_string (dirs[i].path,
12790 : 1870 : dirs[i].length
12791 : : - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR);
12792 : 1870 : output_line_string (str_form, str, "Directory Entry",
12793 : 1870 : (unsigned) i + idx_offset);
12794 : : }
12795 : : }
12796 : : }
12797 : : else
12798 : : {
12799 : 118 : for (i = 1 - idx_offset; i < ndirs; i++)
12800 : 67 : dw2_asm_output_nstring (dirs[i].path,
12801 : 67 : dirs[i].length
12802 : 67 : - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12803 : : "Directory Entry: %#x", i + idx_offset);
12804 : :
12805 : 51 : dw2_asm_output_data (1, 0, "End directory table");
12806 : : }
12807 : :
12808 : : /* We have to emit them in the order of emitted_number since that's
12809 : : used in the debug info generation. To do this efficiently we
12810 : : generate a back-mapping of the indices first. */
12811 : 1561 : backmap = XALLOCAVEC (int, numfiles);
12812 : 5960 : for (i = 0; i < numfiles; i++)
12813 : 4399 : backmap[files[i].file_idx->emitted_number - 1] = i;
12814 : :
12815 : 1561 : if (dwarf_version >= 5)
12816 : : {
12817 : 1510 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
12818 : 1510 : if (filename0 == NULL)
12819 : 0 : filename0 = "";
12820 : : /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
12821 : : DW_FORM_data2. Choose one based on the number of directories
12822 : : and how much space would they occupy in each encoding.
12823 : : If we have at most 256 directories, all indexes fit into
12824 : : a single byte, so DW_FORM_data1 is most compact (if there
12825 : : are at most 128 directories, DW_FORM_udata would be as
12826 : : compact as that, but not shorter and slower to decode). */
12827 : 1510 : if (ndirs + idx_offset <= 256)
12828 : : idx_form = DW_FORM_data1;
12829 : : /* If there are more than 65536 directories, we have to use
12830 : : DW_FORM_udata, DW_FORM_data2 can't refer to them.
12831 : : Otherwise, compute what space would occupy if all the indexes
12832 : : used DW_FORM_udata - sum - and compare that to how large would
12833 : : be DW_FORM_data2 encoding, and pick the more efficient one. */
12834 : 0 : else if (ndirs + idx_offset <= 65536)
12835 : : {
12836 : : unsigned HOST_WIDE_INT sum = 1;
12837 : 0 : for (i = 0; i < numfiles; i++)
12838 : : {
12839 : 0 : int file_idx = backmap[i];
12840 : 0 : int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12841 : 0 : sum += size_of_uleb128 (dir_idx);
12842 : : }
12843 : 0 : if (sum >= HOST_WIDE_INT_UC (2) * (numfiles + 1))
12844 : 1510 : idx_form = DW_FORM_data2;
12845 : : }
12846 : : #ifdef VMS_DEBUGGING_INFO
12847 : : dw2_asm_output_data (1, 4, "File name entry format count");
12848 : : #else
12849 : 1510 : dw2_asm_output_data (1, 2, "File name entry format count");
12850 : : #endif
12851 : 1510 : dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
12852 : 1510 : dw2_asm_output_data_uleb128 (str_form, "%s",
12853 : : get_DW_FORM_name (str_form));
12854 : 1510 : dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
12855 : : "DW_LNCT_directory_index");
12856 : 1510 : dw2_asm_output_data_uleb128 (idx_form, "%s",
12857 : : get_DW_FORM_name (idx_form));
12858 : : #ifdef VMS_DEBUGGING_INFO
12859 : : dw2_asm_output_data_uleb128 (DW_LNCT_timestamp, "DW_LNCT_timestamp");
12860 : : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12861 : : dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
12862 : : dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
12863 : : #endif
12864 : 1510 : dw2_asm_output_data_uleb128 (numfiles + 1, "File names count");
12865 : :
12866 : 1510 : output_line_string (str_form, filename0, "File Entry", 0);
12867 : :
12868 : : /* Include directory index. */
12869 : 1510 : if (idx_form != DW_FORM_udata)
12870 : 1510 : dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
12871 : : 0, NULL);
12872 : : else
12873 : 0 : dw2_asm_output_data_uleb128 (0, NULL);
12874 : :
12875 : : #ifdef VMS_DEBUGGING_INFO
12876 : : dw2_asm_output_data_uleb128 (0, NULL);
12877 : : dw2_asm_output_data_uleb128 (0, NULL);
12878 : : #endif
12879 : : }
12880 : :
12881 : : /* Now write all the file names. */
12882 : 5960 : for (i = 0; i < numfiles; i++)
12883 : : {
12884 : 4399 : int file_idx = backmap[i];
12885 : 4399 : int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12886 : :
12887 : : #ifdef VMS_DEBUGGING_INFO
12888 : : #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12889 : :
12890 : : /* Setting these fields can lead to debugger miscomparisons,
12891 : : but VMS Debug requires them to be set correctly. */
12892 : :
12893 : : int ver;
12894 : : long long cdt;
12895 : : long siz;
12896 : : int maxfilelen = (strlen (files[file_idx].path)
12897 : : + dirs[dir_idx].length
12898 : : + MAX_VMS_VERSION_LEN + 1);
12899 : : char *filebuf = XALLOCAVEC (char, maxfilelen);
12900 : :
12901 : : vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12902 : : snprintf (filebuf, maxfilelen, "%s;%d",
12903 : : files[file_idx].path + dirs[dir_idx].length, ver);
12904 : :
12905 : : output_line_string (str_form, filebuf, "File Entry", (unsigned) i + 1);
12906 : :
12907 : : /* Include directory index. */
12908 : : if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
12909 : : dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
12910 : : dir_idx + idx_offset, NULL);
12911 : : else
12912 : : dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12913 : :
12914 : : /* Modification time. */
12915 : : dw2_asm_output_data_uleb128 ((vms_file_stats_name (files[file_idx].path,
12916 : : &cdt, 0, 0, 0) == 0)
12917 : : ? cdt : 0, NULL);
12918 : :
12919 : : /* File length in bytes. */
12920 : : dw2_asm_output_data_uleb128 ((vms_file_stats_name (files[file_idx].path,
12921 : : 0, &siz, 0, 0) == 0)
12922 : : ? siz : 0, NULL);
12923 : : #else
12924 : 4399 : output_line_string (str_form,
12925 : 4399 : files[file_idx].path + dirs[dir_idx].length,
12926 : 4399 : "File Entry", (unsigned) i + 1);
12927 : :
12928 : : /* Include directory index. */
12929 : 4399 : if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
12930 : 4332 : dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
12931 : 4332 : dir_idx + idx_offset, NULL);
12932 : : else
12933 : 67 : dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12934 : :
12935 : 4399 : if (dwarf_version >= 5)
12936 : 4332 : continue;
12937 : :
12938 : : /* Modification time. */
12939 : 67 : dw2_asm_output_data_uleb128 (0, NULL);
12940 : :
12941 : : /* File length in bytes. */
12942 : 67 : dw2_asm_output_data_uleb128 (0, NULL);
12943 : : #endif /* VMS_DEBUGGING_INFO */
12944 : : }
12945 : :
12946 : 1561 : if (dwarf_version < 5)
12947 : 51 : dw2_asm_output_data (1, 0, "End file name table");
12948 : : }
12949 : :
12950 : :
12951 : : /* Output one line number table into the .debug_line section. */
12952 : :
12953 : : static void
12954 : 43 : output_one_line_info_table (dw_line_info_table *table)
12955 : : {
12956 : 43 : char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12957 : 43 : unsigned int current_line = 1;
12958 : 43 : bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12959 : 43 : dw_line_info_entry *ent, *prev_addr = NULL;
12960 : 43 : size_t i;
12961 : 43 : unsigned int view;
12962 : :
12963 : 43 : view = 0;
12964 : :
12965 : 5797 : FOR_EACH_VEC_SAFE_ELT (table->entries, i, ent)
12966 : : {
12967 : 5754 : switch (ent->opcode)
12968 : : {
12969 : 88 : case LI_set_address:
12970 : : /* ??? Unfortunately, we have little choice here currently, and
12971 : : must always use the most general form. GCC does not know the
12972 : : address delta itself, so we can't use DW_LNS_advance_pc. Many
12973 : : ports do have length attributes which will give an upper bound
12974 : : on the address range. We could perhaps use length attributes
12975 : : to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12976 : 88 : ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12977 : :
12978 : 88 : view = 0;
12979 : :
12980 : : /* This can handle any delta. This takes
12981 : : 4+DWARF2_ADDR_SIZE bytes. */
12982 : 88 : dw2_asm_output_data (1, 0, "set address %s%s", line_label,
12983 : 88 : debug_variable_location_views
12984 : : ? ", reset view to 0" : "");
12985 : 103 : dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12986 : 88 : dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12987 : 88 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12988 : :
12989 : 88 : prev_addr = ent;
12990 : 88 : break;
12991 : :
12992 : 1454 : case LI_adv_address:
12993 : 1454 : {
12994 : 1454 : ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12995 : 1454 : char prev_label[MAX_ARTIFICIAL_LABEL_BYTES];
12996 : 1454 : ASM_GENERATE_INTERNAL_LABEL (prev_label, LINE_CODE_LABEL, prev_addr->val);
12997 : :
12998 : 1454 : view++;
12999 : :
13000 : 1454 : dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, "fixed advance PC, increment view to %i", view);
13001 : 1454 : dw2_asm_output_delta (2, line_label, prev_label,
13002 : : "from %s to %s", prev_label, line_label);
13003 : :
13004 : 1454 : prev_addr = ent;
13005 : 1454 : break;
13006 : : }
13007 : :
13008 : 1542 : case LI_set_line:
13009 : 1542 : if (ent->val == current_line)
13010 : : {
13011 : : /* We still need to start a new row, so output a copy insn. */
13012 : 656 : dw2_asm_output_data (1, DW_LNS_copy,
13013 : : "copy line %u", current_line);
13014 : : }
13015 : : else
13016 : : {
13017 : 886 : int line_offset = ent->val - current_line;
13018 : 886 : int line_delta = line_offset - DWARF_LINE_BASE;
13019 : :
13020 : 886 : current_line = ent->val;
13021 : 886 : if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
13022 : : {
13023 : : /* This can handle deltas from -10 to 234, using the current
13024 : : definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
13025 : : This takes 1 byte. */
13026 : 470 : dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
13027 : : "line %u", current_line);
13028 : : }
13029 : : else
13030 : : {
13031 : : /* This can handle any delta. This takes at least 4 bytes,
13032 : : depending on the value being encoded. */
13033 : 416 : dw2_asm_output_data (1, DW_LNS_advance_line,
13034 : : "advance to line %u", current_line);
13035 : 416 : dw2_asm_output_data_sleb128 (line_offset, NULL);
13036 : 416 : dw2_asm_output_data (1, DW_LNS_copy, NULL);
13037 : : }
13038 : : }
13039 : : break;
13040 : :
13041 : 290 : case LI_set_file:
13042 : 290 : dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
13043 : 290 : dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
13044 : 290 : break;
13045 : :
13046 : 1542 : case LI_set_column:
13047 : 1542 : dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
13048 : 1542 : dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
13049 : 1542 : break;
13050 : :
13051 : 573 : case LI_negate_stmt:
13052 : 573 : current_is_stmt = !current_is_stmt;
13053 : 573 : dw2_asm_output_data (1, DW_LNS_negate_stmt,
13054 : : "is_stmt %d", current_is_stmt);
13055 : 573 : break;
13056 : :
13057 : 0 : case LI_set_prologue_end:
13058 : 0 : dw2_asm_output_data (1, DW_LNS_set_prologue_end,
13059 : : "set prologue end");
13060 : 0 : break;
13061 : :
13062 : 0 : case LI_set_epilogue_begin:
13063 : 0 : dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
13064 : : "set epilogue begin");
13065 : 0 : break;
13066 : :
13067 : 265 : case LI_set_discriminator:
13068 : 265 : dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
13069 : 265 : dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
13070 : 265 : dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
13071 : 265 : dw2_asm_output_data_uleb128 (ent->val, NULL);
13072 : 265 : break;
13073 : : }
13074 : : }
13075 : :
13076 : : /* Emit debug info for the address of the end of the table. */
13077 : 43 : dw2_asm_output_data (1, 0, "set address %s", table->end_label);
13078 : 58 : dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
13079 : 43 : dw2_asm_output_data (1, DW_LNE_set_address, NULL);
13080 : 58 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
13081 : :
13082 : 43 : dw2_asm_output_data (1, 0, "end sequence");
13083 : 43 : dw2_asm_output_data_uleb128 (1, NULL);
13084 : 43 : dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
13085 : 43 : }
13086 : :
13087 : : static unsigned int output_line_info_generation;
13088 : :
13089 : : /* Output the source line number correspondence information. This
13090 : : information goes into the .debug_line section. */
13091 : :
13092 : : static void
13093 : 1578 : output_line_info (bool prologue_only)
13094 : : {
13095 : 1578 : char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
13096 : 1578 : char p1[MAX_ARTIFICIAL_LABEL_BYTES], p2[MAX_ARTIFICIAL_LABEL_BYTES];
13097 : 1578 : bool saw_one = false;
13098 : 1578 : int opc;
13099 : :
13100 : 1578 : ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL,
13101 : : output_line_info_generation);
13102 : 1578 : ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL,
13103 : : output_line_info_generation);
13104 : 1578 : ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL,
13105 : : output_line_info_generation);
13106 : 1578 : ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL,
13107 : : output_line_info_generation++);
13108 : :
13109 : 1578 : if (!XCOFF_DEBUGGING_INFO)
13110 : : {
13111 : 1578 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
13112 : 0 : dw2_asm_output_data (4, 0xffffffff,
13113 : : "Initial length escape value indicating 64-bit DWARF extension");
13114 : 1578 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
13115 : : "Length of Source Line Info");
13116 : : }
13117 : :
13118 : 1578 : ASM_OUTPUT_LABEL (asm_out_file, l1);
13119 : :
13120 : 1578 : output_dwarf_version ();
13121 : 1578 : if (dwarf_version >= 5)
13122 : : {
13123 : 1528 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
13124 : 1527 : dw2_asm_output_data (1, 0, "Segment Size");
13125 : : }
13126 : 1578 : dw2_asm_output_delta (dwarf_offset_size, p2, p1, "Prolog Length");
13127 : 1578 : ASM_OUTPUT_LABEL (asm_out_file, p1);
13128 : :
13129 : : /* Define the architecture-dependent minimum instruction length (in bytes).
13130 : : In this implementation of DWARF, this field is used for information
13131 : : purposes only. Since GCC generates assembly language, we have no
13132 : : a priori knowledge of how many instruction bytes are generated for each
13133 : : source line, and therefore can use only the DW_LNE_set_address and
13134 : : DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
13135 : : this as '1', which is "correct enough" for all architectures,
13136 : : and don't let the target override. */
13137 : 1578 : dw2_asm_output_data (1, 1, "Minimum Instruction Length");
13138 : :
13139 : 1578 : if (dwarf_version >= 4)
13140 : 1528 : dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
13141 : : "Maximum Operations Per Instruction");
13142 : 1578 : dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
13143 : : "Default is_stmt_start flag");
13144 : 1578 : dw2_asm_output_data (1, DWARF_LINE_BASE,
13145 : : "Line Base Value (Special Opcodes)");
13146 : 1578 : dw2_asm_output_data (1, DWARF_LINE_RANGE,
13147 : : "Line Range Value (Special Opcodes)");
13148 : 1578 : dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
13149 : : "Special Opcode Base");
13150 : :
13151 : 20514 : for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
13152 : : {
13153 : 18936 : int n_op_args;
13154 : 18936 : switch (opc)
13155 : : {
13156 : : case DW_LNS_advance_pc:
13157 : : case DW_LNS_advance_line:
13158 : : case DW_LNS_set_file:
13159 : : case DW_LNS_set_column:
13160 : : case DW_LNS_fixed_advance_pc:
13161 : : case DW_LNS_set_isa:
13162 : : n_op_args = 1;
13163 : : break;
13164 : 9468 : default:
13165 : 9468 : n_op_args = 0;
13166 : 9468 : break;
13167 : : }
13168 : :
13169 : 18936 : dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
13170 : : opc, n_op_args);
13171 : : }
13172 : :
13173 : : /* Write out the information about the files we use. */
13174 : 1578 : output_file_names ();
13175 : 1578 : ASM_OUTPUT_LABEL (asm_out_file, p2);
13176 : 1578 : if (prologue_only)
13177 : : {
13178 : : /* Output the marker for the end of the line number info. */
13179 : 1572 : ASM_OUTPUT_LABEL (asm_out_file, l2);
13180 : 1572 : return;
13181 : : }
13182 : :
13183 : 6 : if (separate_line_info)
13184 : : {
13185 : : dw_line_info_table *table;
13186 : : size_t i;
13187 : :
13188 : 42 : FOR_EACH_VEC_ELT (*separate_line_info, i, table)
13189 : 37 : if (table->in_use)
13190 : : {
13191 : 37 : output_one_line_info_table (table);
13192 : 37 : saw_one = true;
13193 : : }
13194 : : }
13195 : 6 : if (cold_text_section_line_info && cold_text_section_line_info->in_use)
13196 : : {
13197 : 2 : output_one_line_info_table (cold_text_section_line_info);
13198 : 2 : saw_one = true;
13199 : : }
13200 : :
13201 : : /* ??? Some Darwin linkers crash on a .debug_line section with no
13202 : : sequences. Further, merely a DW_LNE_end_sequence entry is not
13203 : : sufficient -- the address column must also be initialized.
13204 : : Make sure to output at least one set_address/end_sequence pair,
13205 : : choosing .text since that section is always present. */
13206 : 6 : if (text_section_line_info->in_use || !saw_one)
13207 : 4 : output_one_line_info_table (text_section_line_info);
13208 : :
13209 : : /* Output the marker for the end of the line number info. */
13210 : 6 : ASM_OUTPUT_LABEL (asm_out_file, l2);
13211 : : }
13212 : :
13213 : : /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
13214 : :
13215 : : static inline bool
13216 : 380943687 : need_endianity_attribute_p (bool reverse)
13217 : : {
13218 : 269 : return reverse && (dwarf_version >= 3 || !dwarf_strict);
13219 : : }
13220 : :
13221 : : /* Given a pointer to a tree node for some base type, return a pointer to
13222 : : a DIE that describes the given type. REVERSE is true if the type is
13223 : : to be interpreted in the reverse storage order wrt the target order.
13224 : :
13225 : : This routine must only be called for GCC type nodes that correspond to
13226 : : Dwarf base (fundamental) types. */
13227 : :
13228 : : dw_die_ref
13229 : 574282 : base_type_die (tree type, bool reverse)
13230 : : {
13231 : 574282 : dw_die_ref base_type_result;
13232 : 574282 : enum dwarf_type encoding;
13233 : 574282 : bool fpt_used = false;
13234 : 574282 : struct fixed_point_type_info fpt_info;
13235 : 574282 : tree type_bias = NULL_TREE;
13236 : :
13237 : : /* If this is a subtype that should not be emitted as a subrange type,
13238 : : use the base type. See subrange_type_for_debug_p. */
13239 : 574282 : if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
13240 : 0 : type = TREE_TYPE (type);
13241 : :
13242 : 574282 : switch (TREE_CODE (type))
13243 : : {
13244 : 374476 : case INTEGER_TYPE:
13245 : 3428 : if ((dwarf_version >= 4 || !dwarf_strict)
13246 : 374476 : && TYPE_NAME (type)
13247 : 373540 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13248 : 364870 : && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type))
13249 : 739346 : && DECL_NAME (TYPE_NAME (type)))
13250 : : {
13251 : 364870 : const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
13252 : 364870 : if (strcmp (name, "char16_t") == 0
13253 : 353141 : || strcmp (name, "char8_t") == 0
13254 : 350516 : || strcmp (name, "char32_t") == 0)
13255 : : {
13256 : : encoding = DW_ATE_UTF;
13257 : : break;
13258 : : }
13259 : : }
13260 : 348393 : if ((dwarf_version >= 3 || !dwarf_strict)
13261 : 348393 : && lang_hooks.types.get_fixed_point_type_info)
13262 : : {
13263 : 0 : memset (&fpt_info, 0, sizeof (fpt_info));
13264 : 0 : if (lang_hooks.types.get_fixed_point_type_info (type, &fpt_info))
13265 : : {
13266 : 0 : fpt_used = true;
13267 : 0 : encoding = ((TYPE_UNSIGNED (type))
13268 : 0 : ? DW_ATE_unsigned_fixed
13269 : : : DW_ATE_signed_fixed);
13270 : : break;
13271 : : }
13272 : : }
13273 : 348393 : if (TYPE_STRING_FLAG (type))
13274 : : {
13275 : 592 : if ((dwarf_version >= 4 || !dwarf_strict)
13276 : 78979 : && is_rust ()
13277 : 79088 : && int_size_in_bytes (type) == 4)
13278 : : encoding = DW_ATE_UTF;
13279 : 78968 : else if (TYPE_UNSIGNED (type))
13280 : : encoding = DW_ATE_unsigned_char;
13281 : : else
13282 : 49040 : encoding = DW_ATE_signed_char;
13283 : : }
13284 : 269414 : else if (TYPE_UNSIGNED (type))
13285 : : encoding = DW_ATE_unsigned;
13286 : : else
13287 : 148531 : encoding = DW_ATE_signed;
13288 : :
13289 : 348393 : if (!dwarf_strict
13290 : 348389 : && lang_hooks.types.get_type_bias)
13291 : 0 : type_bias = lang_hooks.types.get_type_bias (type);
13292 : : break;
13293 : :
13294 : 130285 : case REAL_TYPE:
13295 : 130285 : if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
13296 : : {
13297 : 862 : if (dwarf_version >= 3 || !dwarf_strict)
13298 : : encoding = DW_ATE_decimal_float;
13299 : : else
13300 : 60 : encoding = DW_ATE_lo_user;
13301 : : }
13302 : : else
13303 : : encoding = DW_ATE_float;
13304 : : break;
13305 : :
13306 : 0 : case FIXED_POINT_TYPE:
13307 : 0 : if (!(dwarf_version >= 3 || !dwarf_strict))
13308 : : encoding = DW_ATE_lo_user;
13309 : 0 : else if (TYPE_UNSIGNED (type))
13310 : : encoding = DW_ATE_unsigned_fixed;
13311 : : else
13312 : 0 : encoding = DW_ATE_signed_fixed;
13313 : : break;
13314 : :
13315 : : /* Dwarf2 doesn't know anything about complex ints, so use
13316 : : a user defined type for it. */
13317 : 50251 : case COMPLEX_TYPE:
13318 : 50251 : if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type)))
13319 : : encoding = DW_ATE_complex_float;
13320 : : else
13321 : 60 : encoding = DW_ATE_lo_user;
13322 : : break;
13323 : :
13324 : : case BOOLEAN_TYPE:
13325 : : /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
13326 : : encoding = DW_ATE_boolean;
13327 : : break;
13328 : :
13329 : 37 : case BITINT_TYPE:
13330 : : /* C23 _BitInt(N). */
13331 : 37 : if (TYPE_UNSIGNED (type))
13332 : : encoding = DW_ATE_unsigned;
13333 : : else
13334 : 23 : encoding = DW_ATE_signed;
13335 : : break;
13336 : :
13337 : 0 : default:
13338 : : /* No other TREE_CODEs are Dwarf fundamental types. */
13339 : 0 : gcc_unreachable ();
13340 : : }
13341 : :
13342 : 574282 : base_type_result = new_die_raw (DW_TAG_base_type);
13343 : :
13344 : 574282 : add_AT_unsigned (base_type_result, DW_AT_byte_size,
13345 : 574282 : int_size_in_bytes (type));
13346 : 574282 : add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
13347 : 574282 : if (TREE_CODE (type) == BITINT_TYPE)
13348 : 37 : add_AT_unsigned (base_type_result, DW_AT_bit_size, TYPE_PRECISION (type));
13349 : :
13350 : 574282 : if (need_endianity_attribute_p (reverse))
13351 : 57 : add_AT_unsigned (base_type_result, DW_AT_endianity,
13352 : : BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
13353 : :
13354 : 574282 : add_alignment_attribute (base_type_result, type);
13355 : :
13356 : 574282 : if (fpt_used)
13357 : : {
13358 : 0 : switch (fpt_info.scale_factor_kind)
13359 : : {
13360 : 0 : case fixed_point_scale_factor_binary:
13361 : 0 : add_AT_int (base_type_result, DW_AT_binary_scale,
13362 : 0 : fpt_info.scale_factor.binary);
13363 : 0 : break;
13364 : :
13365 : 0 : case fixed_point_scale_factor_decimal:
13366 : 0 : add_AT_int (base_type_result, DW_AT_decimal_scale,
13367 : 0 : fpt_info.scale_factor.decimal);
13368 : 0 : break;
13369 : :
13370 : 0 : case fixed_point_scale_factor_arbitrary:
13371 : : /* Arbitrary scale factors cannot be described in standard DWARF. */
13372 : 0 : if (!dwarf_strict)
13373 : : {
13374 : : /* Describe the scale factor as a rational constant. */
13375 : 0 : const dw_die_ref scale_factor
13376 : 0 : = new_die (DW_TAG_constant, comp_unit_die (), type);
13377 : :
13378 : 0 : add_scalar_info (scale_factor, DW_AT_GNU_numerator,
13379 : : fpt_info.scale_factor.arbitrary.numerator,
13380 : : dw_scalar_form_constant, NULL);
13381 : 0 : add_scalar_info (scale_factor, DW_AT_GNU_denominator,
13382 : : fpt_info.scale_factor.arbitrary.denominator,
13383 : : dw_scalar_form_constant, NULL);
13384 : :
13385 : 0 : add_AT_die_ref (base_type_result, DW_AT_small, scale_factor);
13386 : : }
13387 : : break;
13388 : :
13389 : 0 : default:
13390 : 0 : gcc_unreachable ();
13391 : : }
13392 : : }
13393 : :
13394 : 574282 : if (type_bias)
13395 : 0 : add_scalar_info (base_type_result, DW_AT_GNU_bias, type_bias,
13396 : : dw_scalar_form_constant
13397 : : | dw_scalar_form_exprloc
13398 : : | dw_scalar_form_reference,
13399 : : NULL);
13400 : :
13401 : 574282 : return base_type_result;
13402 : : }
13403 : :
13404 : : /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
13405 : : named 'auto' in its type: return true for it, false otherwise. */
13406 : :
13407 : : static inline bool
13408 : 49199 : is_cxx_auto (tree type)
13409 : : {
13410 : 49199 : if (is_cxx ())
13411 : : {
13412 : 49199 : tree name = TYPE_IDENTIFIER (type);
13413 : 49199 : if (name == get_identifier ("auto")
13414 : 49199 : || name == get_identifier ("decltype(auto)"))
13415 : 49199 : return true;
13416 : : }
13417 : : return false;
13418 : : }
13419 : :
13420 : : /* Given a pointer to an arbitrary ..._TYPE tree node, return true if the
13421 : : given input type is a Dwarf "fundamental" type. Otherwise return null. */
13422 : :
13423 : : static inline bool
13424 : 4740522 : is_base_type (tree type)
13425 : : {
13426 : 4740522 : switch (TREE_CODE (type))
13427 : : {
13428 : : case INTEGER_TYPE:
13429 : : case REAL_TYPE:
13430 : : case FIXED_POINT_TYPE:
13431 : : case COMPLEX_TYPE:
13432 : : case BOOLEAN_TYPE:
13433 : : case BITINT_TYPE:
13434 : : return true;
13435 : :
13436 : : case VOID_TYPE:
13437 : : case OPAQUE_TYPE:
13438 : : case ARRAY_TYPE:
13439 : : case RECORD_TYPE:
13440 : : case UNION_TYPE:
13441 : : case QUAL_UNION_TYPE:
13442 : : case ENUMERAL_TYPE:
13443 : : case FUNCTION_TYPE:
13444 : : case METHOD_TYPE:
13445 : : case POINTER_TYPE:
13446 : : case REFERENCE_TYPE:
13447 : : case NULLPTR_TYPE:
13448 : : case OFFSET_TYPE:
13449 : : case LANG_TYPE:
13450 : : case VECTOR_TYPE:
13451 : : return false;
13452 : :
13453 : 3 : default:
13454 : 3 : if (is_cxx_auto (type))
13455 : : return false;
13456 : 0 : gcc_unreachable ();
13457 : : }
13458 : : }
13459 : :
13460 : : /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
13461 : : node, return the size in bits for the type if it is a constant, or else
13462 : : return the alignment for the type if the type's size is not constant, or
13463 : : else return BITS_PER_WORD if the type actually turns out to be an
13464 : : ERROR_MARK node. */
13465 : :
13466 : : static inline unsigned HOST_WIDE_INT
13467 : 38779470 : simple_type_size_in_bits (const_tree type)
13468 : : {
13469 : 38779470 : if (TREE_CODE (type) == ERROR_MARK)
13470 : 0 : return BITS_PER_WORD;
13471 : 38779470 : else if (TYPE_SIZE (type) == NULL_TREE)
13472 : : return 0;
13473 : 38779470 : else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
13474 : 38779470 : return tree_to_uhwi (TYPE_SIZE (type));
13475 : : else
13476 : 0 : return TYPE_ALIGN (type);
13477 : : }
13478 : :
13479 : : /* Similarly, but return an offset_int instead of UHWI. */
13480 : :
13481 : : static inline offset_int
13482 : 540238 : offset_int_type_size_in_bits (const_tree type)
13483 : : {
13484 : 540238 : if (TREE_CODE (type) == ERROR_MARK)
13485 : 0 : return BITS_PER_WORD;
13486 : 540238 : else if (TYPE_SIZE (type) == NULL_TREE)
13487 : 0 : return 0;
13488 : 540238 : else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
13489 : 540238 : return wi::to_offset (TYPE_SIZE (type));
13490 : : else
13491 : 0 : return TYPE_ALIGN (type);
13492 : : }
13493 : :
13494 : : /* Given a pointer to a tree node for a subrange type, return a pointer
13495 : : to a DIE that describes the given type. */
13496 : :
13497 : : static dw_die_ref
13498 : 18 : subrange_type_die (tree type, tree low, tree high, tree bias,
13499 : : dw_die_ref context_die)
13500 : : {
13501 : 18 : dw_die_ref subrange_die;
13502 : 18 : const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
13503 : :
13504 : 18 : if (context_die == NULL)
13505 : 0 : context_die = comp_unit_die ();
13506 : :
13507 : 18 : subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
13508 : :
13509 : 18 : if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
13510 : : {
13511 : : /* The size of the subrange type and its base type do not match,
13512 : : so we need to generate a size attribute for the subrange type. */
13513 : 0 : add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
13514 : : }
13515 : :
13516 : 18 : add_alignment_attribute (subrange_die, type);
13517 : :
13518 : 18 : if (low)
13519 : 18 : add_bound_info (subrange_die, DW_AT_lower_bound, low, NULL);
13520 : 18 : if (high)
13521 : 18 : add_bound_info (subrange_die, DW_AT_upper_bound, high, NULL);
13522 : 18 : if (bias && !dwarf_strict)
13523 : 0 : add_scalar_info (subrange_die, DW_AT_GNU_bias, bias,
13524 : : dw_scalar_form_constant
13525 : : | dw_scalar_form_exprloc
13526 : : | dw_scalar_form_reference,
13527 : : NULL);
13528 : :
13529 : 18 : return subrange_die;
13530 : : }
13531 : :
13532 : : /* Returns the (const and/or volatile) cv_qualifiers associated with
13533 : : the decl node. This will normally be augmented with the
13534 : : cv_qualifiers of the underlying type in add_type_attribute. */
13535 : :
13536 : : static int
13537 : 86402999 : decl_quals (const_tree decl)
13538 : : {
13539 : 86402999 : return ((TREE_READONLY (decl)
13540 : : /* The C++ front-end correctly marks reference-typed
13541 : : variables as readonly, but from a language (and debug
13542 : : info) standpoint they are not const-qualified. */
13543 : 30080411 : && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
13544 : 86402999 : ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
13545 : 86402999 : | (TREE_THIS_VOLATILE (decl)
13546 : 86402999 : ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
13547 : : }
13548 : :
13549 : : /* Determine the TYPE whose qualifiers match the largest strict subset
13550 : : of the given TYPE_QUALS, and return its qualifiers. Ignore all
13551 : : qualifiers outside QUAL_MASK. */
13552 : :
13553 : : static int
13554 : 9913450 : get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
13555 : : {
13556 : 9913450 : tree t;
13557 : 9913450 : int best_rank = 0, best_qual = 0, max_rank;
13558 : :
13559 : 9913450 : type_quals &= qual_mask;
13560 : 9913450 : max_rank = popcount_hwi (type_quals) - 1;
13561 : :
13562 : 10461955 : for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
13563 : 548505 : t = TYPE_NEXT_VARIANT (t))
13564 : : {
13565 : 548505 : int q = TYPE_QUALS (t) & qual_mask;
13566 : :
13567 : 548468 : if ((q & type_quals) == q && q != type_quals
13568 : 1037253 : && check_base_type (t, type))
13569 : : {
13570 : 433859 : int rank = popcount_hwi (q);
13571 : :
13572 : 433859 : if (rank > best_rank)
13573 : : {
13574 : 548505 : best_rank = rank;
13575 : 548505 : best_qual = q;
13576 : : }
13577 : : }
13578 : : }
13579 : :
13580 : 9913450 : return best_qual;
13581 : : }
13582 : :
13583 : : struct dwarf_qual_info_t { int q; enum dwarf_tag t; };
13584 : : static const dwarf_qual_info_t dwarf_qual_info[] =
13585 : : {
13586 : : { TYPE_QUAL_CONST, DW_TAG_const_type },
13587 : : { TYPE_QUAL_VOLATILE, DW_TAG_volatile_type },
13588 : : { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
13589 : : { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
13590 : : };
13591 : : static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
13592 : :
13593 : : /* If DIE is a qualified DIE of some base DIE with the same parent,
13594 : : return the base DIE, otherwise return NULL. Set MASK to the
13595 : : qualifiers added compared to the returned DIE. */
13596 : :
13597 : : static dw_die_ref
13598 : 16927032 : qualified_die_p (dw_die_ref die, int *mask, unsigned int depth)
13599 : : {
13600 : 16927032 : unsigned int i;
13601 : 77607598 : for (i = 0; i < dwarf_qual_info_size; i++)
13602 : 62630047 : if (die->die_tag == dwarf_qual_info[i].t)
13603 : : break;
13604 : 16927032 : if (i == dwarf_qual_info_size)
13605 : : return NULL;
13606 : 16928419 : if (vec_safe_length (die->die_attr) != 1)
13607 : : return NULL;
13608 : 1938359 : dw_die_ref type = get_AT_ref (die, DW_AT_type);
13609 : 1938359 : if (type == NULL || type->die_parent != die->die_parent)
13610 : : return NULL;
13611 : 1936972 : *mask |= dwarf_qual_info[i].q;
13612 : 1936972 : if (depth)
13613 : : {
13614 : 1936972 : dw_die_ref ret = qualified_die_p (type, mask, depth - 1);
13615 : 1936972 : if (ret)
13616 : : return ret;
13617 : : }
13618 : : return type;
13619 : : }
13620 : :
13621 : : /* If TYPE is long double or complex long double that
13622 : : should be emitted as artificial typedef to _Float128 or
13623 : : complex _Float128, return the type it should be emitted as.
13624 : : This is done in case the target already supports 16-byte
13625 : : composite floating point type (ibm_extended_format). */
13626 : :
13627 : : static tree
13628 : 573875 : long_double_as_float128 (tree type)
13629 : : {
13630 : 573875 : if (type != long_double_type_node
13631 : 554518 : && type != complex_long_double_type_node)
13632 : : return NULL_TREE;
13633 : :
13634 : 32322 : machine_mode mode, fmode;
13635 : 32322 : if (TREE_CODE (type) == COMPLEX_TYPE)
13636 : 12965 : mode = TYPE_MODE (TREE_TYPE (type));
13637 : : else
13638 : 19357 : mode = TYPE_MODE (type);
13639 : 229650 : if (known_eq (GET_MODE_SIZE (mode), 16) && !MODE_COMPOSITE_P (mode))
13640 : 192507 : FOR_EACH_MODE_IN_CLASS (fmode, MODE_FLOAT)
13641 : 165006 : if (known_eq (GET_MODE_SIZE (fmode), 16)
13642 : 495018 : && MODE_COMPOSITE_P (fmode))
13643 : : {
13644 : 0 : if (type == long_double_type_node)
13645 : : {
13646 : 0 : if (float128_type_node
13647 : 0 : && (TYPE_MODE (float128_type_node)
13648 : 0 : == TYPE_MODE (type)))
13649 : 0 : return float128_type_node;
13650 : 0 : return NULL_TREE;
13651 : : }
13652 : 0 : for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
13653 : 0 : if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
13654 : 0 : && (TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i))
13655 : 0 : == TYPE_MODE (type)))
13656 : 0 : return COMPLEX_FLOATN_NX_TYPE_NODE (i);
13657 : : }
13658 : :
13659 : : return NULL_TREE;
13660 : : }
13661 : :
13662 : : /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
13663 : : entry that chains the modifiers specified by CV_QUALS in front of the
13664 : : given type. REVERSE is true if the type is to be interpreted in the
13665 : : reverse storage order wrt the target order. */
13666 : :
13667 : : static dw_die_ref
13668 : 380369405 : modified_type_die (tree type, int cv_quals, bool reverse,
13669 : : dw_die_ref context_die)
13670 : : {
13671 : 380369405 : enum tree_code code = TREE_CODE (type);
13672 : 380369405 : dw_die_ref mod_type_die;
13673 : 380369405 : dw_die_ref sub_die = NULL;
13674 : 380369405 : tree item_type = NULL;
13675 : 380369405 : tree qualified_type;
13676 : 380369405 : tree name, low, high;
13677 : 380369405 : dw_die_ref mod_scope;
13678 : 380369405 : struct array_descr_info info;
13679 : : /* Only these cv-qualifiers are currently handled. */
13680 : 380369405 : const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE
13681 : : | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC);
13682 : : /* DW_AT_endianity is specified only for base types in the standard. */
13683 : 380369405 : const bool reverse_type
13684 : 380369617 : = need_endianity_attribute_p (reverse)
13685 : 212 : && (is_base_type (type)
13686 : 45 : || (TREE_CODE (type) == ENUMERAL_TYPE && !dwarf_strict));
13687 : :
13688 : 380369405 : if (code == ERROR_MARK)
13689 : : return NULL;
13690 : :
13691 : 380369405 : if (lang_hooks.types.get_debug_type)
13692 : : {
13693 : 371716953 : tree debug_type = lang_hooks.types.get_debug_type (type);
13694 : :
13695 : 371716953 : if (debug_type != NULL_TREE && debug_type != type)
13696 : 241383 : return modified_type_die (debug_type, cv_quals, reverse, context_die);
13697 : : }
13698 : :
13699 : 380128022 : cv_quals &= cv_qual_mask;
13700 : :
13701 : : /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
13702 : : tag modifier (and not an attribute) old consumers won't be able
13703 : : to handle it. */
13704 : 380128022 : if (dwarf_version < 3)
13705 : 55381 : cv_quals &= ~TYPE_QUAL_RESTRICT;
13706 : :
13707 : : /* Likewise for DW_TAG_atomic_type for DWARFv5. */
13708 : 380128022 : if (dwarf_version < 5)
13709 : 57214 : cv_quals &= ~TYPE_QUAL_ATOMIC;
13710 : :
13711 : : /* See if we already have the appropriately qualified variant of
13712 : : this type. */
13713 : 380128022 : qualified_type = get_qualified_type (type, cv_quals);
13714 : :
13715 : 380128022 : if (qualified_type == sizetype)
13716 : : {
13717 : : /* Try not to expose the internal sizetype type's name. */
13718 : 849636 : if (TYPE_NAME (qualified_type)
13719 : 849636 : && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
13720 : : {
13721 : 0 : tree t = TREE_TYPE (TYPE_NAME (qualified_type));
13722 : :
13723 : 0 : gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
13724 : : && (TYPE_PRECISION (t)
13725 : : == TYPE_PRECISION (qualified_type))
13726 : : && (TYPE_UNSIGNED (t)
13727 : : == TYPE_UNSIGNED (qualified_type)));
13728 : : qualified_type = t;
13729 : : }
13730 : 849636 : else if (qualified_type == sizetype
13731 : 849636 : && TREE_CODE (sizetype) == TREE_CODE (size_type_node)
13732 : 849636 : && TYPE_PRECISION (sizetype) == TYPE_PRECISION (size_type_node)
13733 : 849636 : && TYPE_UNSIGNED (sizetype) == TYPE_UNSIGNED (size_type_node))
13734 : : qualified_type = size_type_node;
13735 : 849636 : if (type == sizetype)
13736 : 849636 : type = qualified_type;
13737 : : }
13738 : :
13739 : : /* If we do, then we can just use its DIE, if it exists. */
13740 : 380128022 : if (qualified_type)
13741 : : {
13742 : 380001779 : mod_type_die = lookup_type_die (qualified_type);
13743 : :
13744 : : /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
13745 : : dealt with specially: the DIE with the attribute, if it exists, is
13746 : : placed immediately after the regular DIE for the same type. */
13747 : 380001779 : if (mod_type_die
13748 : 380001779 : && (!reverse_type
13749 : 160 : || ((mod_type_die = mod_type_die->die_sib) != NULL
13750 : 160 : && get_AT_unsigned (mod_type_die, DW_AT_endianity))))
13751 : 335461513 : return mod_type_die;
13752 : : }
13753 : :
13754 : 44540266 : name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
13755 : :
13756 : : /* Handle C typedef types. */
13757 : 44540266 : if (name
13758 : 18987687 : && TREE_CODE (name) == TYPE_DECL
13759 : 18937514 : && DECL_ORIGINAL_TYPE (name)
13760 : 52360064 : && !DECL_ARTIFICIAL (name))
13761 : : {
13762 : 7809467 : tree dtype = TREE_TYPE (name);
13763 : :
13764 : : /* Skip the typedef for base types with DW_AT_endianity, no big deal. */
13765 : 7809467 : if (qualified_type == dtype && !reverse_type)
13766 : : {
13767 : 5402817 : tree origin = decl_ultimate_origin (name);
13768 : :
13769 : : /* Typedef variants that have an abstract origin don't get their own
13770 : : type DIE (see gen_typedef_die), so fall back on the ultimate
13771 : : abstract origin instead. */
13772 : 5402817 : if (origin != NULL && origin != name)
13773 : 0 : return modified_type_die (TREE_TYPE (origin), cv_quals, reverse,
13774 : 0 : context_die);
13775 : :
13776 : : /* For a named type, use the typedef. */
13777 : 5402817 : gen_type_die (qualified_type, context_die);
13778 : 5402817 : return lookup_type_die (qualified_type);
13779 : : }
13780 : : else
13781 : : {
13782 : 2406650 : int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
13783 : 2406650 : dquals &= cv_qual_mask;
13784 : 2406650 : if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
13785 : 2406650 : || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
13786 : : /* cv-unqualified version of named type. Just use
13787 : : the unnamed type to which it refers. */
13788 : 12830 : return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals,
13789 : 12830 : reverse, context_die);
13790 : : /* Else cv-qualified version of named type; fall through. */
13791 : : }
13792 : : }
13793 : :
13794 : 39250862 : mod_scope = scope_die_for (type, context_die);
13795 : :
13796 : 39250862 : if (cv_quals)
13797 : : {
13798 : 9913450 : int sub_quals = 0, first_quals = 0;
13799 : 9913450 : unsigned i;
13800 : 9913450 : dw_die_ref first = NULL, last = NULL;
13801 : :
13802 : : /* Determine a lesser qualified type that most closely matches
13803 : : this one. Then generate DW_TAG_* entries for the remaining
13804 : : qualifiers. */
13805 : 9913450 : sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
13806 : : cv_qual_mask);
13807 : 9913450 : if (sub_quals && use_debug_types)
13808 : : {
13809 : : bool needed = false;
13810 : : /* If emitting type units, make sure the order of qualifiers
13811 : : is canonical. Thus, start from unqualified type if
13812 : : an earlier qualifier is missing in sub_quals, but some later
13813 : : one is present there. */
13814 : 0 : for (i = 0; i < dwarf_qual_info_size; i++)
13815 : 0 : if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
13816 : : needed = true;
13817 : 0 : else if (needed && (dwarf_qual_info[i].q & cv_quals))
13818 : : {
13819 : : sub_quals = 0;
13820 : : break;
13821 : : }
13822 : : }
13823 : 9913450 : mod_type_die = modified_type_die (type, sub_quals, reverse, context_die);
13824 : 9913450 : if (mod_scope && mod_type_die && mod_type_die->die_parent == mod_scope)
13825 : : {
13826 : : /* As not all intermediate qualified DIEs have corresponding
13827 : : tree types, ensure that qualified DIEs in the same scope
13828 : : as their DW_AT_type are emitted after their DW_AT_type,
13829 : : only with other qualified DIEs for the same type possibly
13830 : : in between them. Determine the range of such qualified
13831 : : DIEs now (first being the base type, last being corresponding
13832 : : last qualified DIE for it). */
13833 : 9742814 : unsigned int count = 0;
13834 : 9742814 : first = qualified_die_p (mod_type_die, &first_quals,
13835 : : dwarf_qual_info_size);
13836 : 9742814 : if (first == NULL)
13837 : 9544284 : first = mod_type_die;
13838 : 9742814 : gcc_assert ((first_quals & ~sub_quals) == 0);
13839 : : for (count = 0, last = first;
13840 : 10585341 : count < (1U << dwarf_qual_info_size);
13841 : 842527 : count++, last = last->die_sib)
13842 : : {
13843 : 10585341 : int quals = 0;
13844 : 10585341 : if (last == mod_scope->die_child)
13845 : : break;
13846 : 4390319 : if (qualified_die_p (last->die_sib, &quals, dwarf_qual_info_size)
13847 : : != first)
13848 : : break;
13849 : : }
13850 : : }
13851 : :
13852 : 49567250 : for (i = 0; i < dwarf_qual_info_size; i++)
13853 : 39653800 : if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
13854 : : {
13855 : 9928042 : dw_die_ref d;
13856 : 9928042 : if (first && first != last)
13857 : : {
13858 : 648944 : for (d = first->die_sib; ; d = d->die_sib)
13859 : : {
13860 : 856927 : int quals = 0;
13861 : 856927 : qualified_die_p (d, &quals, dwarf_qual_info_size);
13862 : 856927 : if (quals == (first_quals | dwarf_qual_info[i].q))
13863 : : break;
13864 : 805244 : if (d == last)
13865 : : {
13866 : : d = NULL;
13867 : : break;
13868 : : }
13869 : 207983 : }
13870 : 648944 : if (d)
13871 : : {
13872 : 51683 : mod_type_die = d;
13873 : 51683 : continue;
13874 : : }
13875 : : }
13876 : 9876359 : if (first)
13877 : : {
13878 : 9705723 : d = new_die_raw (dwarf_qual_info[i].t);
13879 : 9705723 : add_child_die_after (mod_scope, d, last);
13880 : 9705723 : last = d;
13881 : : }
13882 : : else
13883 : 170636 : d = new_die (dwarf_qual_info[i].t, mod_scope, type);
13884 : 9876359 : if (mod_type_die)
13885 : 9849858 : add_AT_die_ref (d, DW_AT_type, mod_type_die);
13886 : 9876359 : mod_type_die = d;
13887 : 9876359 : first_quals |= dwarf_qual_info[i].q;
13888 : : }
13889 : : }
13890 : 29337412 : else if (code == POINTER_TYPE || code == REFERENCE_TYPE)
13891 : : {
13892 : 24508351 : dwarf_tag tag = DW_TAG_pointer_type;
13893 : 24508351 : if (code == REFERENCE_TYPE)
13894 : : {
13895 : 12935432 : if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
13896 : : tag = DW_TAG_rvalue_reference_type;
13897 : : else
13898 : : tag = DW_TAG_reference_type;
13899 : : }
13900 : 24508351 : mod_type_die = new_die (tag, mod_scope, type);
13901 : :
13902 : 24508351 : add_AT_unsigned (mod_type_die, DW_AT_byte_size,
13903 : 24508351 : simple_type_size_in_bits (type) / BITS_PER_UNIT);
13904 : 24508351 : add_alignment_attribute (mod_type_die, type);
13905 : 24508351 : item_type = TREE_TYPE (type);
13906 : :
13907 : 24508351 : addr_space_t as = TYPE_ADDR_SPACE (item_type);
13908 : 24508351 : if (!ADDR_SPACE_GENERIC_P (as))
13909 : : {
13910 : 3 : int action = targetm.addr_space.debug (as);
13911 : 3 : if (action >= 0)
13912 : : {
13913 : : /* Positive values indicate an address_class. */
13914 : 3 : add_AT_unsigned (mod_type_die, DW_AT_address_class, action);
13915 : : }
13916 : : else
13917 : : {
13918 : : /* Negative values indicate an (inverted) segment base reg. */
13919 : 0 : dw_loc_descr_ref d
13920 : 0 : = one_reg_loc_descriptor (~action, VAR_INIT_STATUS_INITIALIZED);
13921 : 0 : add_AT_loc (mod_type_die, DW_AT_segment, d);
13922 : : }
13923 : : }
13924 : : }
13925 : 4829061 : else if (code == ARRAY_TYPE
13926 : 4829061 : || (lang_hooks.types.get_array_descr_info
13927 : 21297 : && lang_hooks.types.get_array_descr_info (type, &info)))
13928 : : {
13929 : 88733 : gen_type_die (type, mod_scope);
13930 : 88733 : return lookup_type_die (type);
13931 : : }
13932 : 4740328 : else if (code == INTEGER_TYPE
13933 : 374087 : && TREE_TYPE (type) != NULL_TREE
13934 : 4740346 : && subrange_type_for_debug_p (type, &low, &high))
13935 : : {
13936 : 18 : tree bias = NULL_TREE;
13937 : 18 : if (lang_hooks.types.get_type_bias)
13938 : 0 : bias = lang_hooks.types.get_type_bias (type);
13939 : 18 : mod_type_die = subrange_type_die (type, low, high, bias, mod_scope);
13940 : 18 : item_type = TREE_TYPE (type);
13941 : : }
13942 : 4740310 : else if (is_base_type (type))
13943 : : {
13944 : : /* If a target supports long double as different floating point
13945 : : modes with the same 16-byte size, use normal DW_TAG_base_type
13946 : : only for the composite (ibm_extended_real_format) type and
13947 : : for the other for the time being emit instead a "_Float128"
13948 : : or "complex _Float128" DW_TAG_base_type and a "long double"
13949 : : or "complex long double" typedef to it. */
13950 : 573875 : if (tree other_type = long_double_as_float128 (type))
13951 : : {
13952 : 0 : dw_die_ref other_die;
13953 : 0 : if (TYPE_NAME (other_type))
13954 : 0 : other_die
13955 : 0 : = modified_type_die (other_type, TYPE_UNQUALIFIED, reverse,
13956 : : context_die);
13957 : : else
13958 : : {
13959 : 0 : other_die = base_type_die (type, reverse);
13960 : 0 : add_child_die (comp_unit_die (), other_die);
13961 : 0 : add_name_attribute (other_die,
13962 : 0 : TREE_CODE (type) == COMPLEX_TYPE
13963 : : ? "complex _Float128" : "_Float128");
13964 : : }
13965 : 0 : mod_type_die = new_die_raw (DW_TAG_typedef);
13966 : 0 : add_AT_die_ref (mod_type_die, DW_AT_type, other_die);
13967 : : }
13968 : : else
13969 : 573875 : mod_type_die = base_type_die (type, reverse);
13970 : :
13971 : : /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
13972 : 573875 : if (reverse_type)
13973 : : {
13974 : 57 : dw_die_ref after_die
13975 : 57 : = modified_type_die (type, cv_quals, false, context_die);
13976 : 57 : add_child_die_after (mod_scope, mod_type_die, after_die);
13977 : : }
13978 : : else
13979 : 573818 : add_child_die (mod_scope, mod_type_die);
13980 : :
13981 : 573875 : add_pubtype (type, mod_type_die);
13982 : : }
13983 : : else
13984 : : {
13985 : : /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
13986 : 4166435 : if (reverse_type)
13987 : : {
13988 : 2 : dw_die_ref after_die
13989 : 2 : = modified_type_die (type, cv_quals, false, context_die);
13990 : 2 : gen_type_die (type, context_die, true);
13991 : 2 : gcc_assert (after_die->die_sib
13992 : : && get_AT_unsigned (after_die->die_sib, DW_AT_endianity));
13993 : 2 : return after_die->die_sib;
13994 : : }
13995 : :
13996 : 4166433 : gen_type_die (type, context_die);
13997 : :
13998 : : /* We have to get the type_main_variant here (and pass that to the
13999 : : `lookup_type_die' routine) because the ..._TYPE node we have
14000 : : might simply be a *copy* of some original type node (where the
14001 : : copy was created to help us keep track of typedef names) and
14002 : : that copy might have a different TYPE_UID from the original
14003 : : ..._TYPE node. */
14004 : 4166433 : if (code == FUNCTION_TYPE || code == METHOD_TYPE)
14005 : : {
14006 : : /* For function/method types, can't just use type_main_variant here,
14007 : : because that can have different ref-qualifiers for C++,
14008 : : but try to canonicalize. */
14009 : 247595 : tree main = TYPE_MAIN_VARIANT (type);
14010 : 259023 : for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
14011 : 259011 : if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
14012 : 258850 : && check_base_type (t, main)
14013 : 514268 : && check_lang_type (t, type))
14014 : 247583 : return lookup_type_die (t);
14015 : 12 : return lookup_type_die (type);
14016 : : }
14017 : : /* Vectors have the debugging information in the type,
14018 : : not the main variant. */
14019 : 3918838 : else if (code == VECTOR_TYPE)
14020 : 19525 : return lookup_type_die (type);
14021 : : else
14022 : 3899313 : return lookup_type_die (type_main_variant (type));
14023 : : }
14024 : :
14025 : : /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
14026 : : don't output a DW_TAG_typedef, since there isn't one in the
14027 : : user's program; just attach a DW_AT_name to the type.
14028 : : Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
14029 : : if the base type already has the same name. */
14030 : 34995694 : if (name
14031 : 34995694 : && ((TREE_CODE (name) != TYPE_DECL
14032 : 17298 : && (qualified_type == TYPE_MAIN_VARIANT (type)
14033 : 4431 : || (cv_quals == TYPE_UNQUALIFIED)))
14034 : 9810423 : || (TREE_CODE (name) == TYPE_DECL
14035 : 9805992 : && DECL_NAME (name)
14036 : 9805957 : && !DECL_NAMELESS (name)
14037 : 9805094 : && (TREE_TYPE (name) == qualified_type
14038 : 9236559 : || (lang_hooks.types.get_debug_type
14039 : 9179065 : && (lang_hooks.types.get_debug_type (TREE_TYPE (name))
14040 : : == qualified_type))))))
14041 : : {
14042 : 581402 : if (TREE_CODE (name) == TYPE_DECL)
14043 : : /* Could just call add_name_and_src_coords_attributes here,
14044 : : but since this is a builtin type it doesn't have any
14045 : : useful source coordinates anyway. */
14046 : 568535 : name = DECL_NAME (name);
14047 : 581402 : add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
14048 : : }
14049 : 34414292 : else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
14050 : : {
14051 : 8801 : if (TREE_CODE (type) == BITINT_TYPE)
14052 : : {
14053 : 37 : char name_buf[sizeof ("unsigned _BitInt(2147483647)")];
14054 : 148 : snprintf (name_buf, sizeof (name_buf),
14055 : 37 : "%s_BitInt(%d)", TYPE_UNSIGNED (type) ? "unsigned " : "",
14056 : 37 : TYPE_PRECISION (type));
14057 : 37 : add_name_attribute (mod_type_die, name_buf);
14058 : : }
14059 : : else
14060 : : {
14061 : : /* This probably indicates a bug. */
14062 : 8764 : name = TYPE_IDENTIFIER (type);
14063 : 9768 : add_name_attribute (mod_type_die,
14064 : : name
14065 : 1004 : ? IDENTIFIER_POINTER (name) : "__unknown__");
14066 : : }
14067 : : }
14068 : :
14069 : 34995694 : if (qualified_type && !reverse_type)
14070 : 34869426 : equate_type_number_to_die (qualified_type, mod_type_die);
14071 : :
14072 : 34995694 : if (item_type)
14073 : : /* We must do this after the equate_type_number_to_die call, in case
14074 : : this is a recursive type. This ensures that the modified_type_die
14075 : : recursion will terminate even if the type is recursive. Recursive
14076 : : types are possible in Ada. */
14077 : 49016738 : sub_die = modified_type_die (item_type,
14078 : 24508369 : TYPE_QUALS_NO_ADDR_SPACE (item_type),
14079 : : reverse,
14080 : : context_die);
14081 : :
14082 : 24508369 : if (sub_die != NULL)
14083 : 24474805 : add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
14084 : :
14085 : 34995694 : add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
14086 : 34995694 : if (TYPE_ARTIFICIAL (type))
14087 : 863 : add_AT_flag (mod_type_die, DW_AT_artificial, 1);
14088 : :
14089 : : return mod_type_die;
14090 : : }
14091 : :
14092 : : /* Generate DIEs for the generic parameters of T.
14093 : : T must be either a generic type or a generic function.
14094 : : See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
14095 : :
14096 : : static void
14097 : 107272189 : gen_generic_params_dies (tree t)
14098 : : {
14099 : 107272189 : tree parms, args;
14100 : 107272189 : int parms_num, i;
14101 : 107272189 : dw_die_ref die = NULL;
14102 : 107272189 : int non_default;
14103 : :
14104 : 107272189 : if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
14105 : : return;
14106 : :
14107 : 107272189 : if (TYPE_P (t))
14108 : 27529450 : die = lookup_type_die (t);
14109 : 79742739 : else if (DECL_P (t))
14110 : 79742739 : die = lookup_decl_die (t);
14111 : :
14112 : 107272189 : gcc_assert (die);
14113 : :
14114 : 107272189 : parms = lang_hooks.get_innermost_generic_parms (t);
14115 : 107272189 : if (!parms)
14116 : : /* T has no generic parameter. It means T is neither a generic type
14117 : : or function. End of story. */
14118 : : return;
14119 : :
14120 : 28506052 : parms_num = TREE_VEC_LENGTH (parms);
14121 : 28506052 : args = lang_hooks.get_innermost_generic_args (t);
14122 : 28506052 : if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
14123 : 28505824 : non_default = int_cst_value (TREE_CHAIN (args));
14124 : : else
14125 : 228 : non_default = TREE_VEC_LENGTH (args);
14126 : 70772965 : for (i = 0; i < parms_num; i++)
14127 : : {
14128 : 42266913 : tree parm, arg, arg_pack_elems;
14129 : 42266913 : dw_die_ref parm_die;
14130 : :
14131 : 42266913 : parm = TREE_VEC_ELT (parms, i);
14132 : 42266913 : arg = TREE_VEC_ELT (args, i);
14133 : 42266913 : arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
14134 : 84533826 : gcc_assert (parm && TREE_VALUE (parm) && arg);
14135 : :
14136 : 42266913 : if (parm && TREE_VALUE (parm) && arg)
14137 : : {
14138 : : /* If PARM represents a template parameter pack,
14139 : : emit a DW_TAG_GNU_template_parameter_pack DIE, followed
14140 : : by DW_TAG_template_*_parameter DIEs for the argument
14141 : : pack elements of ARG. Note that ARG would then be
14142 : : an argument pack. */
14143 : 42266913 : if (arg_pack_elems)
14144 : 4150350 : parm_die = template_parameter_pack_die (TREE_VALUE (parm),
14145 : : arg_pack_elems,
14146 : : die);
14147 : : else
14148 : 38116563 : parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
14149 : : true /* emit name */, die);
14150 : 42266913 : if (i >= non_default)
14151 : 773259 : add_AT_flag (parm_die, DW_AT_default_value, 1);
14152 : : }
14153 : : }
14154 : : }
14155 : :
14156 : : /* Create and return a DIE for PARM which should be
14157 : : the representation of a generic type parameter.
14158 : : For instance, in the C++ front end, PARM would be a template parameter.
14159 : : ARG is the argument to PARM.
14160 : : EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
14161 : : name of the PARM.
14162 : : PARENT_DIE is the parent DIE which the new created DIE should be added to,
14163 : : as a child node. */
14164 : :
14165 : : static dw_die_ref
14166 : 48201582 : generic_parameter_die (tree parm, tree arg,
14167 : : bool emit_name_p,
14168 : : dw_die_ref parent_die)
14169 : : {
14170 : 48201582 : dw_die_ref tmpl_die = NULL;
14171 : 48201582 : const char *name = NULL;
14172 : :
14173 : : /* C++20 accepts class literals as template parameters, and var
14174 : : decls with initializers represent them. The VAR_DECLs would be
14175 : : rejected, but we can take the DECL_INITIAL constructor and
14176 : : attempt to expand it. */
14177 : 48201582 : if (arg && VAR_P (arg))
14178 : 778 : arg = DECL_INITIAL (arg);
14179 : :
14180 : 48201582 : if (!parm || !DECL_NAME (parm) || !arg)
14181 : : return NULL;
14182 : :
14183 : : /* We support non-type generic parameters and arguments,
14184 : : type generic parameters and arguments, as well as
14185 : : generic generic parameters (a.k.a. template template parameters in C++)
14186 : : and arguments. */
14187 : 39360431 : if (TREE_CODE (parm) == PARM_DECL)
14188 : : /* PARM is a nontype generic parameter */
14189 : 5097327 : tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
14190 : 34263104 : else if (TREE_CODE (parm) == TYPE_DECL)
14191 : : /* PARM is a type generic parameter. */
14192 : 34197543 : tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
14193 : 65561 : else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
14194 : : /* PARM is a generic generic parameter.
14195 : : Its DIE is a GNU extension. It shall have a
14196 : : DW_AT_name attribute to represent the name of the template template
14197 : : parameter, and a DW_AT_GNU_template_name attribute to represent the
14198 : : name of the template template argument. */
14199 : 65561 : tmpl_die = new_die (DW_TAG_GNU_template_template_param,
14200 : : parent_die, parm);
14201 : : else
14202 : 0 : gcc_unreachable ();
14203 : :
14204 : 39360431 : if (tmpl_die)
14205 : : {
14206 : 39360431 : tree tmpl_type;
14207 : :
14208 : : /* If PARM is a generic parameter pack, it means we are
14209 : : emitting debug info for a template argument pack element.
14210 : : In other terms, ARG is a template argument pack element.
14211 : : In that case, we don't emit any DW_AT_name attribute for
14212 : : the die. */
14213 : 39360431 : if (emit_name_p)
14214 : : {
14215 : 29622299 : name = IDENTIFIER_POINTER (DECL_NAME (parm));
14216 : 29622299 : gcc_assert (name);
14217 : 29622299 : add_AT_string (tmpl_die, DW_AT_name, name);
14218 : : }
14219 : :
14220 : 39360431 : if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
14221 : : {
14222 : : /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
14223 : : TMPL_DIE should have a child DW_AT_type attribute that is set
14224 : : to the type of the argument to PARM, which is ARG.
14225 : : If PARM is a type generic parameter, TMPL_DIE should have a
14226 : : child DW_AT_type that is set to ARG. */
14227 : 39294870 : tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
14228 : 39294870 : add_type_attribute (tmpl_die, tmpl_type,
14229 : 39294870 : (TREE_THIS_VOLATILE (tmpl_type)
14230 : 39294870 : ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED),
14231 : : false, parent_die);
14232 : : }
14233 : : else
14234 : : {
14235 : : /* So TMPL_DIE is a DIE representing a
14236 : : a generic generic template parameter, a.k.a template template
14237 : : parameter in C++ and arg is a template. */
14238 : :
14239 : : /* The DW_AT_GNU_template_name attribute of the DIE must be set
14240 : : to the name of the argument. */
14241 : 65561 : name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
14242 : 65561 : if (name)
14243 : 65561 : add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
14244 : : }
14245 : :
14246 : 39360431 : if (TREE_CODE (parm) == PARM_DECL)
14247 : : /* So PARM is a non-type generic parameter.
14248 : : DWARF3 5.6.8 says we must set a DW_AT_const_value child
14249 : : attribute of TMPL_DIE which value represents the value
14250 : : of ARG.
14251 : : We must be careful here:
14252 : : The value of ARG might reference some function decls.
14253 : : We might currently be emitting debug info for a generic
14254 : : type and types are emitted before function decls, we don't
14255 : : know if the function decls referenced by ARG will actually be
14256 : : emitted after cgraph computations.
14257 : : So must defer the generation of the DW_AT_const_value to
14258 : : after cgraph is ready. */
14259 : 5097327 : append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
14260 : : }
14261 : :
14262 : : return tmpl_die;
14263 : : }
14264 : :
14265 : : /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
14266 : : PARM_PACK must be a template parameter pack. The returned DIE
14267 : : will be child DIE of PARENT_DIE. */
14268 : :
14269 : : static dw_die_ref
14270 : 4150350 : template_parameter_pack_die (tree parm_pack,
14271 : : tree parm_pack_args,
14272 : : dw_die_ref parent_die)
14273 : : {
14274 : 4150350 : dw_die_ref die;
14275 : 4150350 : int j;
14276 : :
14277 : 4150350 : gcc_assert (parent_die && parm_pack);
14278 : :
14279 : 4150350 : die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
14280 : 4150350 : add_name_and_src_coords_attributes (die, parm_pack);
14281 : 18385719 : for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
14282 : 10085019 : generic_parameter_die (parm_pack,
14283 : 10085019 : TREE_VEC_ELT (parm_pack_args, j),
14284 : : false /* Don't emit DW_AT_name */,
14285 : : die);
14286 : 4150350 : return die;
14287 : : }
14288 : :
14289 : : /* Return the debugger register number described by a given RTL node. */
14290 : :
14291 : : static unsigned int
14292 : 15454861 : debugger_reg_number (const_rtx rtl)
14293 : : {
14294 : 15454861 : unsigned regno = REGNO (rtl);
14295 : :
14296 : 15454861 : gcc_assert (regno < FIRST_PSEUDO_REGISTER);
14297 : :
14298 : : #ifdef LEAF_REG_REMAP
14299 : : if (crtl->uses_only_leaf_regs)
14300 : : {
14301 : : int leaf_reg = LEAF_REG_REMAP (regno);
14302 : : if (leaf_reg != -1)
14303 : : regno = (unsigned) leaf_reg;
14304 : : }
14305 : : #endif
14306 : :
14307 : 15454861 : regno = DEBUGGER_REGNO (regno);
14308 : 15454861 : gcc_assert (regno != INVALID_REGNUM);
14309 : 15454861 : return regno;
14310 : : }
14311 : :
14312 : : /* Optionally add a DW_OP_piece term to a location description expression.
14313 : : DW_OP_piece is only added if the location description expression already
14314 : : doesn't end with DW_OP_piece. */
14315 : :
14316 : : static void
14317 : 601968 : add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
14318 : : {
14319 : 601968 : dw_loc_descr_ref loc;
14320 : :
14321 : 601968 : if (*list_head != NULL)
14322 : : {
14323 : : /* Find the end of the chain. */
14324 : 1382032 : for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
14325 : : ;
14326 : :
14327 : 601968 : if (loc->dw_loc_opc != DW_OP_piece)
14328 : 601950 : loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
14329 : : }
14330 : 601968 : }
14331 : :
14332 : : /* Return a location descriptor that designates a machine register or
14333 : : zero if there is none. */
14334 : :
14335 : : static dw_loc_descr_ref
14336 : 14113034 : reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
14337 : : {
14338 : 14113034 : rtx regs;
14339 : :
14340 : 14113034 : if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
14341 : : return 0;
14342 : :
14343 : : /* We only use "frame base" when we're sure we're talking about the
14344 : : post-prologue local stack frame. We do this by *not* running
14345 : : register elimination until this point, and recognizing the special
14346 : : argument pointer and soft frame pointer rtx's.
14347 : : Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
14348 : 14052916 : if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
14349 : 14055788 : && (ira_use_lra_p
14350 : 1436 : ? lra_eliminate_regs (rtl, VOIDmode, NULL_RTX)
14351 : 0 : : eliminate_regs (rtl, VOIDmode, NULL_RTX)) != rtl)
14352 : : {
14353 : 1436 : dw_loc_descr_ref result = NULL;
14354 : :
14355 : 1436 : if (dwarf_version >= 4 || !dwarf_strict)
14356 : : {
14357 : 1436 : result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
14358 : : initialized);
14359 : 1436 : if (result)
14360 : 2872 : add_loc_descr (&result,
14361 : : new_loc_descr (DW_OP_stack_value, 0, 0));
14362 : : }
14363 : 1436 : return result;
14364 : : }
14365 : :
14366 : 14052916 : regs = targetm.dwarf_register_span (rtl);
14367 : :
14368 : 14052916 : if (REG_NREGS (rtl) > 1 || regs)
14369 : 95611 : return multiple_reg_loc_descriptor (rtl, regs, initialized);
14370 : : else
14371 : : {
14372 : 13957305 : unsigned int debugger_regnum = debugger_reg_number (rtl);
14373 : 13957305 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
14374 : : return 0;
14375 : 13957305 : return one_reg_loc_descriptor (debugger_regnum, initialized);
14376 : : }
14377 : : }
14378 : :
14379 : : /* Return a location descriptor that designates a machine register for
14380 : : a given hard register number. */
14381 : :
14382 : : static dw_loc_descr_ref
14383 : 15445343 : one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
14384 : : {
14385 : 15445343 : dw_loc_descr_ref reg_loc_descr;
14386 : :
14387 : 15445343 : if (regno <= 31)
14388 : 15427858 : reg_loc_descr
14389 : 15427858 : = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
14390 : : else
14391 : 17485 : reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
14392 : :
14393 : 15445343 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14394 : 232576 : add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14395 : :
14396 : 15445343 : return reg_loc_descr;
14397 : : }
14398 : :
14399 : : /* Given an RTL of a register, return a location descriptor that
14400 : : designates a value that spans more than one register. */
14401 : :
14402 : : static dw_loc_descr_ref
14403 : 95611 : multiple_reg_loc_descriptor (rtx rtl, rtx regs,
14404 : : enum var_init_status initialized)
14405 : : {
14406 : 95611 : int size, i;
14407 : 95611 : dw_loc_descr_ref loc_result = NULL;
14408 : :
14409 : : /* Simple, contiguous registers. */
14410 : 95611 : if (regs == NULL_RTX)
14411 : : {
14412 : 95611 : unsigned reg = REGNO (rtl);
14413 : 95611 : int nregs;
14414 : :
14415 : : #ifdef LEAF_REG_REMAP
14416 : : if (crtl->uses_only_leaf_regs)
14417 : : {
14418 : : int leaf_reg = LEAF_REG_REMAP (reg);
14419 : : if (leaf_reg != -1)
14420 : : reg = (unsigned) leaf_reg;
14421 : : }
14422 : : #endif
14423 : :
14424 : 95611 : gcc_assert ((unsigned) DEBUGGER_REGNO (reg) == debugger_reg_number (rtl));
14425 : 95611 : nregs = REG_NREGS (rtl);
14426 : :
14427 : : /* At present we only track constant-sized pieces. */
14428 : 191222 : if (!GET_MODE_SIZE (GET_MODE (rtl)).is_constant (&size))
14429 : : return NULL;
14430 : 95611 : size /= nregs;
14431 : :
14432 : 95611 : loc_result = NULL;
14433 : 286833 : while (nregs--)
14434 : : {
14435 : 191222 : dw_loc_descr_ref t;
14436 : :
14437 : 191222 : t = one_reg_loc_descriptor (DEBUGGER_REGNO (reg),
14438 : : VAR_INIT_STATUS_INITIALIZED);
14439 : 191222 : add_loc_descr (&loc_result, t);
14440 : 191222 : add_loc_descr_op_piece (&loc_result, size);
14441 : 191222 : ++reg;
14442 : : }
14443 : 95611 : return loc_result;
14444 : : }
14445 : :
14446 : : /* Now onto stupid register sets in non contiguous locations. */
14447 : :
14448 : 0 : gcc_assert (GET_CODE (regs) == PARALLEL);
14449 : :
14450 : : /* At present we only track constant-sized pieces. */
14451 : 0 : if (!GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))).is_constant (&size))
14452 : : return NULL;
14453 : 0 : loc_result = NULL;
14454 : :
14455 : 0 : for (i = 0; i < XVECLEN (regs, 0); ++i)
14456 : : {
14457 : 0 : dw_loc_descr_ref t;
14458 : :
14459 : 0 : t = one_reg_loc_descriptor (debugger_reg_number (XVECEXP (regs, 0, i)),
14460 : : VAR_INIT_STATUS_INITIALIZED);
14461 : 0 : add_loc_descr (&loc_result, t);
14462 : 0 : add_loc_descr_op_piece (&loc_result, size);
14463 : : }
14464 : :
14465 : 0 : if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14466 : 0 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14467 : 0 : return loc_result;
14468 : : }
14469 : :
14470 : : static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
14471 : :
14472 : : /* Return a location descriptor that designates a constant i,
14473 : : as a compound operation from constant (i >> shift), constant shift
14474 : : and DW_OP_shl. */
14475 : :
14476 : : static dw_loc_descr_ref
14477 : 51539 : int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
14478 : : {
14479 : 51539 : dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
14480 : 51539 : add_loc_descr (&ret, int_loc_descriptor (shift));
14481 : 51539 : add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
14482 : 51539 : return ret;
14483 : : }
14484 : :
14485 : : /* Return a location descriptor that designates constant POLY_I. */
14486 : :
14487 : : static dw_loc_descr_ref
14488 : 5837519 : int_loc_descriptor (poly_int64 poly_i)
14489 : : {
14490 : 5837519 : enum dwarf_location_atom op;
14491 : :
14492 : 5837519 : HOST_WIDE_INT i;
14493 : 5837519 : if (!poly_i.is_constant (&i))
14494 : : {
14495 : : /* Create location descriptions for the non-constant part and
14496 : : add any constant offset at the end. */
14497 : : dw_loc_descr_ref ret = NULL;
14498 : : HOST_WIDE_INT constant = poly_i.coeffs[0];
14499 : : for (unsigned int j = 1; j < NUM_POLY_INT_COEFFS; ++j)
14500 : : {
14501 : : HOST_WIDE_INT coeff = poly_i.coeffs[j];
14502 : : if (coeff != 0)
14503 : : {
14504 : : dw_loc_descr_ref start = ret;
14505 : : unsigned int factor;
14506 : : int bias;
14507 : : unsigned int regno = targetm.dwarf_poly_indeterminate_value
14508 : : (j, &factor, &bias);
14509 : :
14510 : : /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
14511 : : add COEFF * (REGNO / FACTOR) now and subtract
14512 : : COEFF * BIAS from the final constant part. */
14513 : : constant -= coeff * bias;
14514 : : add_loc_descr (&ret, new_reg_loc_descr (regno, 0));
14515 : : if (coeff % factor == 0)
14516 : : coeff /= factor;
14517 : : else
14518 : : {
14519 : : int amount = exact_log2 (factor);
14520 : : gcc_assert (amount >= 0);
14521 : : add_loc_descr (&ret, int_loc_descriptor (amount));
14522 : : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
14523 : : }
14524 : : if (coeff != 1)
14525 : : {
14526 : : add_loc_descr (&ret, int_loc_descriptor (coeff));
14527 : : add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
14528 : : }
14529 : : if (start)
14530 : : add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
14531 : : }
14532 : : }
14533 : : loc_descr_plus_const (&ret, constant);
14534 : : return ret;
14535 : : }
14536 : :
14537 : : /* Pick the smallest representation of a constant, rather than just
14538 : : defaulting to the LEB encoding. */
14539 : 5837519 : if (i >= 0)
14540 : : {
14541 : 5562995 : int clz = clz_hwi (i);
14542 : 3683322 : int ctz = ctz_hwi (i);
14543 : 5562995 : if (i <= 31)
14544 : 3928369 : op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
14545 : 1634626 : else if (i <= 0xff)
14546 : : op = DW_OP_const1u;
14547 : 618782 : else if (i <= 0xffff)
14548 : : op = DW_OP_const2u;
14549 : 419133 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
14550 : : && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
14551 : : /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
14552 : : DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
14553 : : while DW_OP_const4u is 5 bytes. */
14554 : 45914 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
14555 : 373219 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
14556 : 2867 : && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
14557 : : /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
14558 : : while DW_OP_const4u is 5 bytes. */
14559 : 2448 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
14560 : :
14561 : 370771 : else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
14562 : 3741 : && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
14563 : : <= 4)
14564 : : {
14565 : : /* As i >= 2**31, the double cast above will yield a negative number.
14566 : : Since wrapping is defined in DWARF expressions we can output big
14567 : : positive integers as small negative ones, regardless of the size
14568 : : of host wide ints.
14569 : :
14570 : : Here, since the evaluator will handle 32-bit values and since i >=
14571 : : 2**31, we know it's going to be interpreted as a negative literal:
14572 : : store it this way if we can do better than 5 bytes this way. */
14573 : 0 : return int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
14574 : : }
14575 : 370771 : else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
14576 : : op = DW_OP_const4u;
14577 : :
14578 : : /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
14579 : : least 6 bytes: see if we can do better before falling back to it. */
14580 : 45874 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
14581 : : && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
14582 : : /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes. */
14583 : 419 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
14584 : 45455 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
14585 : 45455 : && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
14586 : : >= HOST_BITS_PER_WIDE_INT)
14587 : : /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
14588 : : DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes. */
14589 : 733 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
14590 : 44722 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
14591 : : && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
14592 : 44722 : && size_of_uleb128 (i) > 6)
14593 : : /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
14594 : 2025 : return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
14595 : : else
14596 : : op = DW_OP_constu;
14597 : : }
14598 : : else
14599 : : {
14600 : 274524 : if (i >= -0x80)
14601 : : op = DW_OP_const1s;
14602 : 40044 : else if (i >= -0x8000)
14603 : : op = DW_OP_const2s;
14604 : 35304 : else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
14605 : : {
14606 : : if (size_of_int_loc_descriptor (i) < 5)
14607 : : {
14608 : : dw_loc_descr_ref ret = int_loc_descriptor (-i);
14609 : : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14610 : : return ret;
14611 : : }
14612 : : op = DW_OP_const4s;
14613 : : }
14614 : : else
14615 : : {
14616 : 35304 : if (size_of_int_loc_descriptor (i)
14617 : 35304 : < (unsigned long) 1 + size_of_sleb128 (i))
14618 : : {
14619 : 4239 : dw_loc_descr_ref ret = int_loc_descriptor (-i);
14620 : 4239 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
14621 : 4239 : return ret;
14622 : : }
14623 : : op = DW_OP_consts;
14624 : : }
14625 : : }
14626 : :
14627 : 5781741 : return new_loc_descr (op, i, 0);
14628 : : }
14629 : :
14630 : : /* Likewise, for unsigned constants. */
14631 : :
14632 : : static dw_loc_descr_ref
14633 : 158508 : uint_loc_descriptor (unsigned HOST_WIDE_INT i)
14634 : : {
14635 : 158508 : const unsigned HOST_WIDE_INT max_int = INTTYPE_MAXIMUM (HOST_WIDE_INT);
14636 : 158508 : const unsigned HOST_WIDE_INT max_uint
14637 : : = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT);
14638 : :
14639 : : /* If possible, use the clever signed constants handling. */
14640 : 158508 : if (i <= max_int)
14641 : 158500 : return int_loc_descriptor ((HOST_WIDE_INT) i);
14642 : :
14643 : : /* Here, we are left with positive numbers that cannot be represented as
14644 : : HOST_WIDE_INT, i.e.:
14645 : : max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
14646 : :
14647 : : Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
14648 : : whereas may be better to output a negative integer: thanks to integer
14649 : : wrapping, we know that:
14650 : : x = x - 2 ** DWARF2_ADDR_SIZE
14651 : : = x - 2 * (max (HOST_WIDE_INT) + 1)
14652 : : So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
14653 : : small negative integers. Let's try that in cases it will clearly improve
14654 : : the encoding: there is no gain turning DW_OP_const4u into
14655 : : DW_OP_const4s. */
14656 : 8 : if (DWARF2_ADDR_SIZE * 8 == HOST_BITS_PER_WIDE_INT
14657 : : && ((DWARF2_ADDR_SIZE == 4 && i > max_uint - 0x8000)
14658 : 8 : || (DWARF2_ADDR_SIZE == 8 && i > max_uint - 0x80000000)))
14659 : : {
14660 : 4 : const unsigned HOST_WIDE_INT first_shift = i - max_int - 1;
14661 : :
14662 : : /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
14663 : : i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
14664 : 4 : const HOST_WIDE_INT second_shift
14665 : : = (HOST_WIDE_INT) first_shift - (HOST_WIDE_INT) max_int - 1;
14666 : :
14667 : : /* So we finally have:
14668 : : -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
14669 : : i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
14670 : 4 : return int_loc_descriptor (second_shift);
14671 : : }
14672 : :
14673 : : /* Last chance: fallback to a simple constant operation. */
14674 : 4 : return new_loc_descr
14675 : 4 : ((HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
14676 : : ? DW_OP_const4u
14677 : : : DW_OP_const8u,
14678 : 4 : i, 0);
14679 : : }
14680 : :
14681 : : /* Generate and return a location description that computes the unsigned
14682 : : comparison of the two stack top entries (a OP b where b is the top-most
14683 : : entry and a is the second one). The KIND of comparison can be LT_EXPR,
14684 : : LE_EXPR, GT_EXPR or GE_EXPR. */
14685 : :
14686 : : static dw_loc_descr_ref
14687 : 0 : uint_comparison_loc_list (enum tree_code kind)
14688 : : {
14689 : 0 : enum dwarf_location_atom op, flip_op;
14690 : 0 : dw_loc_descr_ref ret, bra_node, jmp_node, tmp;
14691 : :
14692 : 0 : switch (kind)
14693 : : {
14694 : : case LT_EXPR:
14695 : : op = DW_OP_lt;
14696 : : break;
14697 : : case LE_EXPR:
14698 : : op = DW_OP_le;
14699 : : break;
14700 : : case GT_EXPR:
14701 : : op = DW_OP_gt;
14702 : : break;
14703 : : case GE_EXPR:
14704 : : op = DW_OP_ge;
14705 : : break;
14706 : 0 : default:
14707 : 0 : gcc_unreachable ();
14708 : : }
14709 : :
14710 : 0 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14711 : 0 : jmp_node = new_loc_descr (DW_OP_skip, 0, 0);
14712 : :
14713 : : /* Until DWARFv4, operations all work on signed integers. It is nevertheless
14714 : : possible to perform unsigned comparisons: we just have to distinguish
14715 : : three cases:
14716 : :
14717 : : 1. when a and b have the same sign (as signed integers); then we should
14718 : : return: a OP(signed) b;
14719 : :
14720 : : 2. when a is a negative signed integer while b is a positive one, then a
14721 : : is a greater unsigned integer than b; likewise when a and b's roles
14722 : : are flipped.
14723 : :
14724 : : So first, compare the sign of the two operands. */
14725 : 0 : ret = new_loc_descr (DW_OP_over, 0, 0);
14726 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
14727 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_xor, 0, 0));
14728 : : /* If they have different signs (i.e. they have different sign bits), then
14729 : : the stack top value has now the sign bit set and thus it's smaller than
14730 : : zero. */
14731 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_lit0, 0, 0));
14732 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_lt, 0, 0));
14733 : 0 : add_loc_descr (&ret, bra_node);
14734 : :
14735 : : /* We are in case 1. At this point, we know both operands have the same
14736 : : sign, to it's safe to use the built-in signed comparison. */
14737 : 0 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
14738 : 0 : add_loc_descr (&ret, jmp_node);
14739 : :
14740 : : /* We are in case 2. Here, we know both operands do not have the same sign,
14741 : : so we have to flip the signed comparison. */
14742 : 0 : flip_op = (kind == LT_EXPR || kind == LE_EXPR) ? DW_OP_gt : DW_OP_lt;
14743 : 0 : tmp = new_loc_descr (flip_op, 0, 0);
14744 : 0 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14745 : 0 : bra_node->dw_loc_oprnd1.v.val_loc = tmp;
14746 : 0 : add_loc_descr (&ret, tmp);
14747 : :
14748 : : /* This dummy operation is necessary to make the two branches join. */
14749 : 0 : tmp = new_loc_descr (DW_OP_nop, 0, 0);
14750 : 0 : jmp_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14751 : 0 : jmp_node->dw_loc_oprnd1.v.val_loc = tmp;
14752 : 0 : add_loc_descr (&ret, tmp);
14753 : :
14754 : 0 : return ret;
14755 : : }
14756 : :
14757 : : /* Likewise, but takes the location description lists (might be destructive on
14758 : : them). Return NULL if either is NULL or if concatenation fails. */
14759 : :
14760 : : static dw_loc_list_ref
14761 : 0 : loc_list_from_uint_comparison (dw_loc_list_ref left, dw_loc_list_ref right,
14762 : : enum tree_code kind)
14763 : : {
14764 : 0 : if (left == NULL || right == NULL)
14765 : : return NULL;
14766 : :
14767 : 0 : add_loc_list (&left, right);
14768 : 0 : if (left == NULL)
14769 : : return NULL;
14770 : :
14771 : 0 : add_loc_descr_to_each (left, uint_comparison_loc_list (kind));
14772 : 0 : return left;
14773 : : }
14774 : :
14775 : : /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
14776 : : without actually allocating it. */
14777 : :
14778 : : static unsigned long
14779 : 45993 : size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
14780 : : {
14781 : 45993 : return size_of_int_loc_descriptor (i >> shift)
14782 : 45993 : + size_of_int_loc_descriptor (shift)
14783 : 45993 : + 1;
14784 : : }
14785 : :
14786 : : /* Return size_of_locs (int_loc_descriptor (i)) without
14787 : : actually allocating it. */
14788 : :
14789 : : static unsigned long
14790 : 4014069 : size_of_int_loc_descriptor (HOST_WIDE_INT i)
14791 : : {
14792 : 4015590 : unsigned long s;
14793 : :
14794 : 4015590 : if (i >= 0)
14795 : : {
14796 : 3730396 : int clz, ctz;
14797 : 3730396 : if (i <= 31)
14798 : : return 1;
14799 : 635366 : else if (i <= 0xff)
14800 : : return 2;
14801 : 228718 : else if (i <= 0xffff)
14802 : : return 3;
14803 : 155893 : clz = clz_hwi (i);
14804 : 155893 : ctz = ctz_hwi (i);
14805 : 155893 : if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
14806 : : && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
14807 : 38083 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
14808 : 38083 : - clz - 5);
14809 : 117810 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
14810 : 7317 : && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
14811 : 2468 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
14812 : 2468 : - clz - 8);
14813 : 115342 : else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
14814 : 2873 : && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
14815 : : <= 4)
14816 : : return size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
14817 : 113821 : else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
14818 : : return 5;
14819 : 29930 : s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
14820 : 29930 : if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
14821 : : && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
14822 : 4846 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
14823 : 4846 : - clz - 8);
14824 : 25084 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
14825 : 385 : && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
14826 : 385 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
14827 : 385 : - clz - 16);
14828 : 24699 : else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
14829 : : && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
14830 : 355 : && s > 6)
14831 : 211 : return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
14832 : 211 : - clz - 32);
14833 : : else
14834 : 24488 : return 1 + s;
14835 : : }
14836 : : else
14837 : : {
14838 : 285194 : if (i >= -0x80)
14839 : : return 2;
14840 : 188158 : else if (i >= -0x8000)
14841 : : return 3;
14842 : 185145 : else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
14843 : : {
14844 : : if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
14845 : : {
14846 : : s = size_of_int_loc_descriptor (-i) + 1;
14847 : : if (s < 5)
14848 : : return s;
14849 : : }
14850 : : return 5;
14851 : : }
14852 : : else
14853 : : {
14854 : 185145 : unsigned long r = 1 + size_of_sleb128 (i);
14855 : 185145 : if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
14856 : : {
14857 : 49387 : s = size_of_int_loc_descriptor (-i) + 1;
14858 : 49387 : if (s < r)
14859 : : return s;
14860 : : }
14861 : 177980 : return r;
14862 : : }
14863 : : }
14864 : : }
14865 : :
14866 : : /* Return loc description representing "address" of integer value.
14867 : : This can appear only as toplevel expression. */
14868 : :
14869 : : static dw_loc_descr_ref
14870 : 2885629 : address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
14871 : : {
14872 : 2885629 : int litsize;
14873 : 2885629 : dw_loc_descr_ref loc_result = NULL;
14874 : :
14875 : 2885629 : if (!(dwarf_version >= 4 || !dwarf_strict))
14876 : : return NULL;
14877 : :
14878 : 2885629 : litsize = size_of_int_loc_descriptor (i);
14879 : : /* Determine if DW_OP_stack_value or DW_OP_implicit_value
14880 : : is more compact. For DW_OP_stack_value we need:
14881 : : litsize + 1 (DW_OP_stack_value)
14882 : : and for DW_OP_implicit_value:
14883 : : 1 (DW_OP_implicit_value) + 1 (length) + size. */
14884 : 3439357 : if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
14885 : : {
14886 : 2836146 : loc_result = int_loc_descriptor (i);
14887 : 2836146 : add_loc_descr (&loc_result,
14888 : : new_loc_descr (DW_OP_stack_value, 0, 0));
14889 : 2836146 : return loc_result;
14890 : : }
14891 : :
14892 : 49483 : loc_result = new_loc_descr (DW_OP_implicit_value,
14893 : : size, 0);
14894 : 49483 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
14895 : 49483 : loc_result->dw_loc_oprnd2.v.val_int = i;
14896 : 49483 : return loc_result;
14897 : : }
14898 : :
14899 : : /* Return a location descriptor that designates a base+offset location. */
14900 : :
14901 : : static dw_loc_descr_ref
14902 : 12734864 : based_loc_descr (rtx reg, poly_int64 offset,
14903 : : enum var_init_status initialized)
14904 : : {
14905 : 12734864 : unsigned int regno;
14906 : 12734864 : dw_loc_descr_ref result;
14907 : 12734864 : dw_fde_ref fde = cfun->fde;
14908 : :
14909 : : /* We only use "frame base" when we're sure we're talking about the
14910 : : post-prologue local stack frame. We do this by *not* running
14911 : : register elimination until this point, and recognizing the special
14912 : : argument pointer and soft frame pointer rtx's. */
14913 : 12734864 : if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
14914 : : {
14915 : 7917766 : rtx elim = (ira_use_lra_p
14916 : 7917766 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
14917 : 7917766 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
14918 : :
14919 : 7917766 : if (elim != reg)
14920 : : {
14921 : : /* Allow hard frame pointer here even if frame pointer
14922 : : isn't used since hard frame pointer is encoded with
14923 : : DW_OP_fbreg which uses the DW_AT_frame_base attribute,
14924 : : not hard frame pointer directly. */
14925 : 7917766 : elim = strip_offset_and_add (elim, &offset);
14926 : 7917766 : gcc_assert (elim == hard_frame_pointer_rtx
14927 : : || elim == stack_pointer_rtx);
14928 : :
14929 : : /* If drap register is used to align stack, use frame
14930 : : pointer + offset to access stack variables. If stack
14931 : : is aligned without drap, use stack pointer + offset to
14932 : : access stack variables. */
14933 : 7917766 : if (crtl->stack_realign_tried
14934 : 11753 : && reg == frame_pointer_rtx)
14935 : : {
14936 : 5052 : int base_reg
14937 : 5052 : = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
14938 : : ? HARD_FRAME_POINTER_REGNUM
14939 : : : REGNO (elim));
14940 : 5052 : return new_reg_loc_descr (base_reg, offset);
14941 : : }
14942 : :
14943 : 7912714 : gcc_assert (frame_pointer_fb_offset_valid);
14944 : 7912714 : offset += frame_pointer_fb_offset;
14945 : 7912714 : HOST_WIDE_INT const_offset;
14946 : 7912714 : if (offset.is_constant (&const_offset))
14947 : 7912714 : return new_loc_descr (DW_OP_fbreg, const_offset, 0);
14948 : : else
14949 : : {
14950 : : dw_loc_descr_ref ret = new_loc_descr (DW_OP_fbreg, 0, 0);
14951 : : loc_descr_plus_const (&ret, offset);
14952 : : return ret;
14953 : : }
14954 : : }
14955 : : }
14956 : :
14957 : 4817098 : regno = REGNO (reg);
14958 : : #ifdef LEAF_REG_REMAP
14959 : : if (crtl->uses_only_leaf_regs)
14960 : : {
14961 : : int leaf_reg = LEAF_REG_REMAP (regno);
14962 : : if (leaf_reg != -1)
14963 : : regno = (unsigned) leaf_reg;
14964 : : }
14965 : : #endif
14966 : 4817098 : regno = DWARF_FRAME_REGNUM (regno);
14967 : :
14968 : 4817098 : HOST_WIDE_INT const_offset;
14969 : 16210 : if (!optimize && fde
14970 : 16210 : && (fde->drap_reg == regno || fde->vdrap_reg == regno)
14971 : 4817098 : && offset.is_constant (&const_offset))
14972 : : {
14973 : : /* Use cfa+offset to represent the location of arguments passed
14974 : : on the stack when drap is used to align stack.
14975 : : Only do this when not optimizing, for optimized code var-tracking
14976 : : is supposed to track where the arguments live and the register
14977 : : used as vdrap or drap in some spot might be used for something
14978 : : else in other part of the routine. */
14979 : 3082 : return new_loc_descr (DW_OP_fbreg, const_offset, 0);
14980 : : }
14981 : :
14982 : 4814016 : result = new_reg_loc_descr (regno, offset);
14983 : :
14984 : 4814016 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14985 : 0 : add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14986 : :
14987 : 4814016 : return result;
14988 : : }
14989 : :
14990 : : /* Return true if this RTL expression describes a base+offset calculation. */
14991 : :
14992 : : static inline bool
14993 : 11110196 : is_based_loc (const_rtx rtl)
14994 : : {
14995 : 11110196 : return (GET_CODE (rtl) == PLUS
14996 : 11110196 : && ((REG_P (XEXP (rtl, 0))
14997 : 9883332 : && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
14998 : 9881747 : && CONST_INT_P (XEXP (rtl, 1)))));
14999 : : }
15000 : :
15001 : : /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
15002 : : failed. */
15003 : :
15004 : : static dw_loc_descr_ref
15005 : 21684 : tls_mem_loc_descriptor (rtx mem)
15006 : : {
15007 : 21684 : tree base;
15008 : 21684 : dw_loc_descr_ref loc_result;
15009 : :
15010 : 21684 : if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
15011 : : return NULL;
15012 : :
15013 : 19275 : base = get_base_address (MEM_EXPR (mem));
15014 : 19275 : if (base == NULL
15015 : 19275 : || !VAR_P (base)
15016 : 34899 : || !DECL_THREAD_LOCAL_P (base))
15017 : 19275 : return NULL;
15018 : :
15019 : 0 : loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1, NULL);
15020 : 0 : if (loc_result == NULL)
15021 : : return NULL;
15022 : :
15023 : 0 : if (maybe_ne (MEM_OFFSET (mem), 0))
15024 : 0 : loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
15025 : :
15026 : : return loc_result;
15027 : : }
15028 : :
15029 : : /* Output debug info about reason why we failed to expand expression as dwarf
15030 : : expression. */
15031 : :
15032 : : static void
15033 : 2701470 : expansion_failed (tree expr, rtx rtl, char const *reason)
15034 : : {
15035 : 2701470 : if (dump_file && (dump_flags & TDF_DETAILS))
15036 : : {
15037 : 0 : fprintf (dump_file, "Failed to expand as dwarf: ");
15038 : 0 : if (expr)
15039 : 0 : print_generic_expr (dump_file, expr, dump_flags);
15040 : 0 : if (rtl)
15041 : : {
15042 : 0 : fprintf (dump_file, "\n");
15043 : 0 : print_rtl (dump_file, rtl);
15044 : : }
15045 : 0 : fprintf (dump_file, "\nReason: %s\n", reason);
15046 : : }
15047 : 2701470 : }
15048 : :
15049 : : /* Helper function for const_ok_for_output. */
15050 : :
15051 : : static bool
15052 : 1782081 : const_ok_for_output_1 (rtx rtl)
15053 : : {
15054 : 1782081 : if (targetm.const_not_ok_for_debug_p (rtl))
15055 : : {
15056 : 22 : if (GET_CODE (rtl) != UNSPEC)
15057 : : {
15058 : 0 : expansion_failed (NULL_TREE, rtl,
15059 : : "Expression rejected for debug by the backend.\n");
15060 : 0 : return false;
15061 : : }
15062 : :
15063 : : /* If delegitimize_address couldn't do anything with the UNSPEC, and
15064 : : the target hook doesn't explicitly allow it in debug info, assume
15065 : : we can't express it in the debug info. */
15066 : : /* Don't complain about TLS UNSPECs, those are just too hard to
15067 : : delegitimize. Note this could be a non-decl SYMBOL_REF such as
15068 : : one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
15069 : : rather than DECL_THREAD_LOCAL_P is not just an optimization. */
15070 : 22 : if (flag_checking
15071 : 22 : && (XVECLEN (rtl, 0) == 0
15072 : 22 : || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
15073 : 16 : || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl, 0, 0)) == TLS_MODEL_NONE))
15074 : 12 : inform (current_function_decl
15075 : 6 : ? DECL_SOURCE_LOCATION (current_function_decl)
15076 : : : UNKNOWN_LOCATION,
15077 : : #if NUM_UNSPEC_VALUES > 0
15078 : : "non-delegitimized UNSPEC %s (%d) found in variable location",
15079 : 6 : ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
15080 : : ? unspec_strings[XINT (rtl, 1)] : "unknown"),
15081 : : #else
15082 : : "non-delegitimized UNSPEC %d found in variable location",
15083 : : #endif
15084 : : XINT (rtl, 1));
15085 : 22 : expansion_failed (NULL_TREE, rtl,
15086 : : "UNSPEC hasn't been delegitimized.\n");
15087 : 22 : return false;
15088 : : }
15089 : :
15090 : 1782059 : if (CONST_POLY_INT_P (rtl))
15091 : : return false;
15092 : :
15093 : : /* FIXME: Refer to PR60655. It is possible for simplification
15094 : : of rtl expressions in var tracking to produce such expressions.
15095 : : We should really identify / validate expressions
15096 : : enclosed in CONST that can be handled by assemblers on various
15097 : : targets and only handle legitimate cases here. */
15098 : 1782059 : switch (GET_CODE (rtl))
15099 : : {
15100 : 1505881 : case SYMBOL_REF:
15101 : 1505881 : break;
15102 : : case NOT:
15103 : : case NEG:
15104 : : return false;
15105 : 149289 : case PLUS:
15106 : 149289 : {
15107 : : /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
15108 : : operands. */
15109 : 149289 : subrtx_var_iterator::array_type array;
15110 : 149289 : bool first = false;
15111 : 149289 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
15112 : 149289 : if (SYMBOL_REF_P (*iter)
15113 : : || LABEL_P (*iter)
15114 : : || GET_CODE (*iter) == UNSPEC)
15115 : : {
15116 : : first = true;
15117 : : break;
15118 : : }
15119 : 149289 : if (!first)
15120 : : return true;
15121 : 298578 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
15122 : 149289 : if (SYMBOL_REF_P (*iter)
15123 : : || LABEL_P (*iter)
15124 : : || GET_CODE (*iter) == UNSPEC)
15125 : 0 : return false;
15126 : 149289 : return true;
15127 : 149289 : }
15128 : 0 : case MINUS:
15129 : 0 : {
15130 : : /* Disallow negation of SYMBOL_REFs or UNSPECs when they
15131 : : appear in the second operand of MINUS. */
15132 : 0 : subrtx_var_iterator::array_type array;
15133 : 0 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
15134 : 0 : if (SYMBOL_REF_P (*iter)
15135 : : || LABEL_P (*iter)
15136 : : || GET_CODE (*iter) == UNSPEC)
15137 : 0 : return false;
15138 : 0 : return true;
15139 : 0 : }
15140 : : default:
15141 : : return true;
15142 : : }
15143 : :
15144 : 1505881 : if (CONSTANT_POOL_ADDRESS_P (rtl))
15145 : : {
15146 : 0 : bool marked;
15147 : 0 : get_pool_constant_mark (rtl, &marked);
15148 : : /* If all references to this pool constant were optimized away,
15149 : : it was not output and thus we can't represent it. */
15150 : 0 : if (!marked)
15151 : : {
15152 : 0 : expansion_failed (NULL_TREE, rtl,
15153 : : "Constant was removed from constant pool.\n");
15154 : 0 : return false;
15155 : : }
15156 : : }
15157 : :
15158 : 1505881 : if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
15159 : : return false;
15160 : :
15161 : : /* Avoid references to external symbols in debug info, on several targets
15162 : : the linker might even refuse to link when linking a shared library,
15163 : : and in many other cases the relocations for .debug_info/.debug_loc are
15164 : : dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
15165 : : to be defined within the same shared library or executable are fine. */
15166 : 1498384 : if (SYMBOL_REF_EXTERNAL_P (rtl))
15167 : : {
15168 : 121666 : tree decl = SYMBOL_REF_DECL (rtl);
15169 : :
15170 : 121666 : if (decl == NULL || !targetm.binds_local_p (decl))
15171 : : {
15172 : 115567 : expansion_failed (NULL_TREE, rtl,
15173 : : "Symbol not defined in current TU.\n");
15174 : 115567 : return false;
15175 : : }
15176 : : }
15177 : :
15178 : : return true;
15179 : : }
15180 : :
15181 : : /* Return true if constant RTL can be emitted in DW_OP_addr or
15182 : : DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
15183 : : non-marked constant pool SYMBOL_REFs can't be referenced in it. */
15184 : :
15185 : : static bool
15186 : 1510705 : const_ok_for_output (rtx rtl)
15187 : : {
15188 : 1510705 : if (GET_CODE (rtl) == SYMBOL_REF)
15189 : 1355987 : return const_ok_for_output_1 (rtl);
15190 : :
15191 : 154718 : if (GET_CODE (rtl) == CONST)
15192 : : {
15193 : 149902 : subrtx_var_iterator::array_type array;
15194 : 551962 : FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
15195 : 426080 : if (!const_ok_for_output_1 (*iter))
15196 : 24020 : return false;
15197 : 125882 : return true;
15198 : 149902 : }
15199 : :
15200 : : return true;
15201 : : }
15202 : :
15203 : : /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
15204 : : if possible, NULL otherwise. */
15205 : :
15206 : : static dw_die_ref
15207 : 362625 : base_type_for_mode (machine_mode mode, bool unsignedp)
15208 : : {
15209 : 362625 : dw_die_ref type_die;
15210 : 362625 : tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
15211 : :
15212 : 362625 : if (type == NULL)
15213 : : return NULL;
15214 : 361312 : switch (TREE_CODE (type))
15215 : : {
15216 : 356935 : case INTEGER_TYPE:
15217 : 356935 : case REAL_TYPE:
15218 : 356935 : break;
15219 : : default:
15220 : : return NULL;
15221 : : }
15222 : 356935 : type_die = lookup_type_die (type);
15223 : 356935 : if (!type_die)
15224 : 360 : type_die = modified_type_die (type, TYPE_UNQUALIFIED, false,
15225 : : comp_unit_die ());
15226 : 356935 : if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
15227 : 0 : return NULL;
15228 : : return type_die;
15229 : : }
15230 : :
15231 : : /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
15232 : : type matching MODE, or, if MODE is narrower than or as wide as
15233 : : DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
15234 : : possible. */
15235 : :
15236 : : static dw_loc_descr_ref
15237 : 4680 : convert_descriptor_to_mode (scalar_int_mode mode, dw_loc_descr_ref op)
15238 : : {
15239 : 4680 : machine_mode outer_mode = mode;
15240 : 4680 : dw_die_ref type_die;
15241 : 4680 : dw_loc_descr_ref cvt;
15242 : :
15243 : 10767 : if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
15244 : : {
15245 : 4408 : add_loc_descr (&op, new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0));
15246 : 4408 : return op;
15247 : : }
15248 : 272 : type_die = base_type_for_mode (outer_mode, 1);
15249 : 272 : if (type_die == NULL)
15250 : : return NULL;
15251 : 272 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15252 : 272 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15253 : 272 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15254 : 272 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15255 : 272 : add_loc_descr (&op, cvt);
15256 : 272 : return op;
15257 : : }
15258 : :
15259 : : /* Return location descriptor for comparison OP with operands OP0 and OP1. */
15260 : :
15261 : : static dw_loc_descr_ref
15262 : 136260 : compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
15263 : : dw_loc_descr_ref op1)
15264 : : {
15265 : 136260 : dw_loc_descr_ref ret = op0;
15266 : 136260 : add_loc_descr (&ret, op1);
15267 : 136260 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
15268 : 136260 : if (STORE_FLAG_VALUE != 1)
15269 : : {
15270 : : add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
15271 : : add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
15272 : : }
15273 : 136260 : return ret;
15274 : : }
15275 : :
15276 : : /* Subroutine of scompare_loc_descriptor for the case in which we're
15277 : : comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15278 : : and in which OP_MODE is bigger than DWARF2_ADDR_SIZE. */
15279 : :
15280 : : static dw_loc_descr_ref
15281 : 935 : scompare_loc_descriptor_wide (enum dwarf_location_atom op,
15282 : : scalar_int_mode op_mode,
15283 : : dw_loc_descr_ref op0, dw_loc_descr_ref op1)
15284 : : {
15285 : 935 : dw_die_ref type_die = base_type_for_mode (op_mode, 0);
15286 : 935 : dw_loc_descr_ref cvt;
15287 : :
15288 : 935 : if (type_die == NULL)
15289 : : return NULL;
15290 : 935 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15291 : 935 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15292 : 935 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15293 : 935 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15294 : 935 : add_loc_descr (&op0, cvt);
15295 : 935 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15296 : 935 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15297 : 935 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15298 : 935 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15299 : 935 : add_loc_descr (&op1, cvt);
15300 : 935 : return compare_loc_descriptor (op, op0, op1);
15301 : : }
15302 : :
15303 : : /* Subroutine of scompare_loc_descriptor for the case in which we're
15304 : : comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
15305 : : and in which OP_MODE is smaller than DWARF2_ADDR_SIZE. */
15306 : :
15307 : : static dw_loc_descr_ref
15308 : 52347 : scompare_loc_descriptor_narrow (enum dwarf_location_atom op, rtx rtl,
15309 : : scalar_int_mode op_mode,
15310 : : dw_loc_descr_ref op0, dw_loc_descr_ref op1)
15311 : : {
15312 : 52347 : int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
15313 : : /* For eq/ne, if the operands are known to be zero-extended,
15314 : : there is no need to do the fancy shifting up. */
15315 : 52347 : if (op == DW_OP_eq || op == DW_OP_ne)
15316 : : {
15317 : 45311 : dw_loc_descr_ref last0, last1;
15318 : 123492 : for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
15319 : : ;
15320 : 55687 : for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
15321 : : ;
15322 : : /* deref_size zero extends, and for constants we can check
15323 : : whether they are zero extended or not. */
15324 : 45311 : if (((last0->dw_loc_opc == DW_OP_deref_size
15325 : 14514 : && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
15326 : 38054 : || (CONST_INT_P (XEXP (rtl, 0))
15327 : 296 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
15328 : 296 : == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
15329 : 52795 : && ((last1->dw_loc_opc == DW_OP_deref_size
15330 : 1022 : && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
15331 : 6973 : || (CONST_INT_P (XEXP (rtl, 1))
15332 : 6665 : && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
15333 : 6665 : == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
15334 : 7150 : return compare_loc_descriptor (op, op0, op1);
15335 : :
15336 : : /* EQ/NE comparison against constant in narrower type than
15337 : : DWARF2_ADDR_SIZE can be performed either as
15338 : : DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
15339 : : DW_OP_{eq,ne}
15340 : : or
15341 : : DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
15342 : : DW_OP_{eq,ne}. Pick whatever is shorter. */
15343 : 38161 : if (CONST_INT_P (XEXP (rtl, 1))
15344 : 36119 : && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
15345 : 74280 : && (size_of_int_loc_descriptor (shift) + 1
15346 : 36119 : + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift)
15347 : 36119 : >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
15348 : 36119 : + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
15349 : 36119 : & GET_MODE_MASK (op_mode))))
15350 : : {
15351 : 18764 : add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
15352 : 18764 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15353 : 37528 : op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
15354 : 18764 : & GET_MODE_MASK (op_mode));
15355 : 18764 : return compare_loc_descriptor (op, op0, op1);
15356 : : }
15357 : : }
15358 : 26433 : add_loc_descr (&op0, int_loc_descriptor (shift));
15359 : 26433 : add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
15360 : 26433 : if (CONST_INT_P (XEXP (rtl, 1)))
15361 : 23667 : op1 = int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift);
15362 : : else
15363 : : {
15364 : 2766 : add_loc_descr (&op1, int_loc_descriptor (shift));
15365 : 5532 : add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
15366 : : }
15367 : 26433 : return compare_loc_descriptor (op, op0, op1);
15368 : : }
15369 : :
15370 : : /* Return location descriptor for signed comparison OP RTL. */
15371 : :
15372 : : static dw_loc_descr_ref
15373 : 125595 : scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
15374 : : machine_mode mem_mode)
15375 : : {
15376 : 125595 : machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
15377 : 125595 : dw_loc_descr_ref op0, op1;
15378 : :
15379 : 125595 : if (op_mode == VOIDmode)
15380 : 331 : op_mode = GET_MODE (XEXP (rtl, 1));
15381 : 125595 : if (op_mode == VOIDmode)
15382 : : return NULL;
15383 : :
15384 : 125595 : scalar_int_mode int_op_mode;
15385 : 125595 : if (dwarf_strict
15386 : 0 : && dwarf_version < 5
15387 : 148869 : && (!is_a <scalar_int_mode> (op_mode, &int_op_mode)
15388 : 0 : || GET_MODE_SIZE (int_op_mode) > DWARF2_ADDR_SIZE))
15389 : : return NULL;
15390 : :
15391 : 125595 : op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
15392 : : VAR_INIT_STATUS_INITIALIZED);
15393 : 125595 : op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
15394 : : VAR_INIT_STATUS_INITIALIZED);
15395 : :
15396 : 125595 : if (op0 == NULL || op1 == NULL)
15397 : : return NULL;
15398 : :
15399 : 102321 : if (is_a <scalar_int_mode> (op_mode, &int_op_mode))
15400 : : {
15401 : 215286 : if (GET_MODE_SIZE (int_op_mode) < DWARF2_ADDR_SIZE)
15402 : 52347 : return scompare_loc_descriptor_narrow (op, rtl, int_op_mode, op0, op1);
15403 : :
15404 : 107756 : if (GET_MODE_SIZE (int_op_mode) > DWARF2_ADDR_SIZE)
15405 : 935 : return scompare_loc_descriptor_wide (op, int_op_mode, op0, op1);
15406 : : }
15407 : 49039 : return compare_loc_descriptor (op, op0, op1);
15408 : : }
15409 : :
15410 : : /* Return location descriptor for unsigned comparison OP RTL. */
15411 : :
15412 : : static dw_loc_descr_ref
15413 : 36119 : ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
15414 : : machine_mode mem_mode)
15415 : : {
15416 : 36119 : dw_loc_descr_ref op0, op1;
15417 : :
15418 : 36119 : machine_mode test_op_mode = GET_MODE (XEXP (rtl, 0));
15419 : 36119 : if (test_op_mode == VOIDmode)
15420 : 64 : test_op_mode = GET_MODE (XEXP (rtl, 1));
15421 : :
15422 : 36119 : scalar_int_mode op_mode;
15423 : 36622 : if (!is_a <scalar_int_mode> (test_op_mode, &op_mode))
15424 : : return NULL;
15425 : :
15426 : 34442 : if (dwarf_strict
15427 : 0 : && dwarf_version < 5
15428 : 34442 : && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
15429 : : return NULL;
15430 : :
15431 : 34442 : op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
15432 : : VAR_INIT_STATUS_INITIALIZED);
15433 : 34442 : op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
15434 : : VAR_INIT_STATUS_INITIALIZED);
15435 : :
15436 : 34442 : if (op0 == NULL || op1 == NULL)
15437 : : return NULL;
15438 : :
15439 : 72836 : if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
15440 : : {
15441 : 15960 : HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
15442 : 15960 : dw_loc_descr_ref last0, last1;
15443 : 63145 : for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
15444 : : ;
15445 : 16595 : for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
15446 : : ;
15447 : 15960 : if (CONST_INT_P (XEXP (rtl, 0)))
15448 : 0 : op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
15449 : : /* deref_size zero extends, so no need to mask it again. */
15450 : 15960 : else if (last0->dw_loc_opc != DW_OP_deref_size
15451 : 19149 : || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
15452 : : {
15453 : 12771 : add_loc_descr (&op0, int_loc_descriptor (mask));
15454 : 25542 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15455 : : }
15456 : 15960 : if (CONST_INT_P (XEXP (rtl, 1)))
15457 : 15759 : op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
15458 : : /* deref_size zero extends, so no need to mask it again. */
15459 : 201 : else if (last1->dw_loc_opc != DW_OP_deref_size
15460 : 252 : || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
15461 : : {
15462 : 150 : add_loc_descr (&op1, int_loc_descriptor (mask));
15463 : 300 : add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
15464 : : }
15465 : : }
15466 : 40735 : else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
15467 : : {
15468 : 17652 : HOST_WIDE_INT bias = 1;
15469 : 17652 : bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
15470 : 17652 : add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15471 : 17652 : if (CONST_INT_P (XEXP (rtl, 1)))
15472 : 6227 : op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
15473 : 6227 : + INTVAL (XEXP (rtl, 1)));
15474 : : else
15475 : 22850 : add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
15476 : : bias, 0));
15477 : : }
15478 : 33939 : return compare_loc_descriptor (op, op0, op1);
15479 : : }
15480 : :
15481 : : /* Return location descriptor for {U,S}{MIN,MAX}. */
15482 : :
15483 : : static dw_loc_descr_ref
15484 : 74884 : minmax_loc_descriptor (rtx rtl, machine_mode mode,
15485 : : machine_mode mem_mode)
15486 : : {
15487 : 74884 : enum dwarf_location_atom op;
15488 : 74884 : dw_loc_descr_ref op0, op1, ret;
15489 : 74884 : dw_loc_descr_ref bra_node, drop_node;
15490 : :
15491 : 74884 : scalar_int_mode int_mode;
15492 : 74884 : if (dwarf_strict
15493 : 0 : && dwarf_version < 5
15494 : 74986 : && (!is_a <scalar_int_mode> (mode, &int_mode)
15495 : 0 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE))
15496 : : return NULL;
15497 : :
15498 : 74884 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15499 : : VAR_INIT_STATUS_INITIALIZED);
15500 : 74884 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15501 : : VAR_INIT_STATUS_INITIALIZED);
15502 : :
15503 : 74884 : if (op0 == NULL || op1 == NULL)
15504 : : return NULL;
15505 : :
15506 : 74782 : add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
15507 : 74782 : add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
15508 : 74782 : add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
15509 : 74782 : if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
15510 : : {
15511 : : /* Checked by the caller. */
15512 : 56507 : int_mode = as_a <scalar_int_mode> (mode);
15513 : 114214 : if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
15514 : : {
15515 : 362 : HOST_WIDE_INT mask = GET_MODE_MASK (int_mode);
15516 : 362 : add_loc_descr (&op0, int_loc_descriptor (mask));
15517 : 362 : add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
15518 : 362 : add_loc_descr (&op1, int_loc_descriptor (mask));
15519 : 724 : add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
15520 : : }
15521 : 113430 : else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
15522 : : {
15523 : 56140 : HOST_WIDE_INT bias = 1;
15524 : 56140 : bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
15525 : 56140 : add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15526 : 112280 : add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
15527 : : }
15528 : : }
15529 : 18275 : else if (is_a <scalar_int_mode> (mode, &int_mode)
15530 : 25832 : && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
15531 : : {
15532 : 1384 : int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (int_mode)) * BITS_PER_UNIT;
15533 : 1384 : add_loc_descr (&op0, int_loc_descriptor (shift));
15534 : 1384 : add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
15535 : 1384 : add_loc_descr (&op1, int_loc_descriptor (shift));
15536 : 2768 : add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
15537 : : }
15538 : 16891 : else if (is_a <scalar_int_mode> (mode, &int_mode)
15539 : 24448 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
15540 : : {
15541 : 46 : dw_die_ref type_die = base_type_for_mode (int_mode, 0);
15542 : 46 : dw_loc_descr_ref cvt;
15543 : 46 : if (type_die == NULL)
15544 : : return NULL;
15545 : 46 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15546 : 46 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15547 : 46 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15548 : 46 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15549 : 46 : add_loc_descr (&op0, cvt);
15550 : 46 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15551 : 46 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15552 : 46 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15553 : 46 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15554 : 92 : add_loc_descr (&op1, cvt);
15555 : : }
15556 : :
15557 : 74782 : if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
15558 : : op = DW_OP_lt;
15559 : : else
15560 : 74782 : op = DW_OP_gt;
15561 : 74782 : ret = op0;
15562 : 74782 : add_loc_descr (&ret, op1);
15563 : 74782 : add_loc_descr (&ret, new_loc_descr (op, 0, 0));
15564 : 74782 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15565 : 74782 : add_loc_descr (&ret, bra_node);
15566 : 74782 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15567 : 74782 : drop_node = new_loc_descr (DW_OP_drop, 0, 0);
15568 : 74782 : add_loc_descr (&ret, drop_node);
15569 : 74782 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15570 : 74782 : bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
15571 : 74782 : if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
15572 : 18275 : && is_a <scalar_int_mode> (mode, &int_mode)
15573 : 100614 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
15574 : 46 : ret = convert_descriptor_to_mode (int_mode, ret);
15575 : 74782 : return ret;
15576 : : }
15577 : :
15578 : : /* Helper function for mem_loc_descriptor. Perform OP binary op,
15579 : : but after converting arguments to type_die, afterwards
15580 : : convert back to unsigned. */
15581 : :
15582 : : static dw_loc_descr_ref
15583 : 3232 : typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
15584 : : scalar_int_mode mode, machine_mode mem_mode)
15585 : : {
15586 : 3232 : dw_loc_descr_ref cvt, op0, op1;
15587 : :
15588 : 3232 : if (type_die == NULL)
15589 : : return NULL;
15590 : 3232 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15591 : : VAR_INIT_STATUS_INITIALIZED);
15592 : 3232 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
15593 : : VAR_INIT_STATUS_INITIALIZED);
15594 : 3232 : if (op0 == NULL || op1 == NULL)
15595 : : return NULL;
15596 : 3172 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15597 : 3172 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15598 : 3172 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15599 : 3172 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15600 : 3172 : add_loc_descr (&op0, cvt);
15601 : 3172 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
15602 : 3172 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15603 : 3172 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
15604 : 3172 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
15605 : 3172 : add_loc_descr (&op1, cvt);
15606 : 3172 : add_loc_descr (&op0, op1);
15607 : 3172 : add_loc_descr (&op0, new_loc_descr (op, 0, 0));
15608 : 3172 : return convert_descriptor_to_mode (mode, op0);
15609 : : }
15610 : :
15611 : : /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
15612 : : const0 is DW_OP_lit0 or corresponding typed constant,
15613 : : const1 is DW_OP_lit1 or corresponding typed constant
15614 : : and constMSB is constant with just the MSB bit set
15615 : : for the mode):
15616 : : DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15617 : : L1: const0 DW_OP_swap
15618 : : L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
15619 : : DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15620 : : L3: DW_OP_drop
15621 : : L4: DW_OP_nop
15622 : :
15623 : : CTZ is similar:
15624 : : DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
15625 : : L1: const0 DW_OP_swap
15626 : : L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15627 : : DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15628 : : L3: DW_OP_drop
15629 : : L4: DW_OP_nop
15630 : :
15631 : : FFS is similar:
15632 : : DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
15633 : : L1: const1 DW_OP_swap
15634 : : L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
15635 : : DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
15636 : : L3: DW_OP_drop
15637 : : L4: DW_OP_nop */
15638 : :
15639 : : static dw_loc_descr_ref
15640 : 7233 : clz_loc_descriptor (rtx rtl, scalar_int_mode mode,
15641 : : machine_mode mem_mode)
15642 : : {
15643 : 7233 : dw_loc_descr_ref op0, ret, tmp;
15644 : 7233 : HOST_WIDE_INT valv;
15645 : 7233 : dw_loc_descr_ref l1jump, l1label;
15646 : 7233 : dw_loc_descr_ref l2jump, l2label;
15647 : 7233 : dw_loc_descr_ref l3jump, l3label;
15648 : 7233 : dw_loc_descr_ref l4jump, l4label;
15649 : 7233 : rtx msb;
15650 : :
15651 : 7233 : if (GET_MODE (XEXP (rtl, 0)) != mode)
15652 : : return NULL;
15653 : :
15654 : 7233 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15655 : : VAR_INIT_STATUS_INITIALIZED);
15656 : 7233 : if (op0 == NULL)
15657 : : return NULL;
15658 : 7233 : ret = op0;
15659 : 7233 : if (GET_CODE (rtl) == CLZ)
15660 : : {
15661 : 13924 : if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
15662 : 13924 : valv = GET_MODE_BITSIZE (mode);
15663 : : }
15664 : 271 : else if (GET_CODE (rtl) == FFS)
15665 : : valv = 0;
15666 : 542 : else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
15667 : 542 : valv = GET_MODE_BITSIZE (mode);
15668 : 7233 : add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
15669 : 7233 : l1jump = new_loc_descr (DW_OP_bra, 0, 0);
15670 : 7233 : add_loc_descr (&ret, l1jump);
15671 : 7233 : add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
15672 : 7233 : tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
15673 : : VAR_INIT_STATUS_INITIALIZED);
15674 : 7233 : if (tmp == NULL)
15675 : : return NULL;
15676 : 7233 : add_loc_descr (&ret, tmp);
15677 : 7233 : l4jump = new_loc_descr (DW_OP_skip, 0, 0);
15678 : 7233 : add_loc_descr (&ret, l4jump);
15679 : 7233 : l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
15680 : : ? const1_rtx : const0_rtx,
15681 : : mode, mem_mode,
15682 : : VAR_INIT_STATUS_INITIALIZED);
15683 : 7233 : if (l1label == NULL)
15684 : : return NULL;
15685 : 7233 : add_loc_descr (&ret, l1label);
15686 : 7233 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15687 : 7233 : l2label = new_loc_descr (DW_OP_dup, 0, 0);
15688 : 7233 : add_loc_descr (&ret, l2label);
15689 : 7233 : if (GET_CODE (rtl) != CLZ)
15690 : 271 : msb = const1_rtx;
15691 : 13924 : else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
15692 : 13924 : msb = GEN_INT (HOST_WIDE_INT_1U
15693 : : << (GET_MODE_BITSIZE (mode) - 1));
15694 : : else
15695 : 0 : msb = immed_wide_int_const
15696 : 0 : (wi::set_bit_in_zero (GET_MODE_PRECISION (mode) - 1,
15697 : 0 : GET_MODE_PRECISION (mode)), mode);
15698 : 7233 : if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
15699 : 2003 : tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
15700 : : ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
15701 : : ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
15702 : : else
15703 : 5230 : tmp = mem_loc_descriptor (msb, mode, mem_mode,
15704 : : VAR_INIT_STATUS_INITIALIZED);
15705 : 7233 : if (tmp == NULL)
15706 : : return NULL;
15707 : 7233 : add_loc_descr (&ret, tmp);
15708 : 7233 : add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
15709 : 7233 : l3jump = new_loc_descr (DW_OP_bra, 0, 0);
15710 : 7233 : add_loc_descr (&ret, l3jump);
15711 : 7233 : tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
15712 : : VAR_INIT_STATUS_INITIALIZED);
15713 : 7233 : if (tmp == NULL)
15714 : : return NULL;
15715 : 7233 : add_loc_descr (&ret, tmp);
15716 : 7504 : add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
15717 : : ? DW_OP_shl : DW_OP_shr, 0, 0));
15718 : 7233 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15719 : 7233 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
15720 : 7233 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15721 : 7233 : l2jump = new_loc_descr (DW_OP_skip, 0, 0);
15722 : 7233 : add_loc_descr (&ret, l2jump);
15723 : 7233 : l3label = new_loc_descr (DW_OP_drop, 0, 0);
15724 : 7233 : add_loc_descr (&ret, l3label);
15725 : 7233 : l4label = new_loc_descr (DW_OP_nop, 0, 0);
15726 : 7233 : add_loc_descr (&ret, l4label);
15727 : 7233 : l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15728 : 7233 : l1jump->dw_loc_oprnd1.v.val_loc = l1label;
15729 : 7233 : l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15730 : 7233 : l2jump->dw_loc_oprnd1.v.val_loc = l2label;
15731 : 7233 : l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15732 : 7233 : l3jump->dw_loc_oprnd1.v.val_loc = l3label;
15733 : 7233 : l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15734 : 7233 : l4jump->dw_loc_oprnd1.v.val_loc = l4label;
15735 : 7233 : return ret;
15736 : : }
15737 : :
15738 : : /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
15739 : : const1 is DW_OP_lit1 or corresponding typed constant):
15740 : : const0 DW_OP_swap
15741 : : L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15742 : : DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15743 : : L2: DW_OP_drop
15744 : :
15745 : : PARITY is similar:
15746 : : L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
15747 : : DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
15748 : : L2: DW_OP_drop */
15749 : :
15750 : : static dw_loc_descr_ref
15751 : 0 : popcount_loc_descriptor (rtx rtl, scalar_int_mode mode,
15752 : : machine_mode mem_mode)
15753 : : {
15754 : 0 : dw_loc_descr_ref op0, ret, tmp;
15755 : 0 : dw_loc_descr_ref l1jump, l1label;
15756 : 0 : dw_loc_descr_ref l2jump, l2label;
15757 : :
15758 : 0 : if (GET_MODE (XEXP (rtl, 0)) != mode)
15759 : : return NULL;
15760 : :
15761 : 0 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15762 : : VAR_INIT_STATUS_INITIALIZED);
15763 : 0 : if (op0 == NULL)
15764 : : return NULL;
15765 : 0 : ret = op0;
15766 : 0 : tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
15767 : : VAR_INIT_STATUS_INITIALIZED);
15768 : 0 : if (tmp == NULL)
15769 : : return NULL;
15770 : 0 : add_loc_descr (&ret, tmp);
15771 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15772 : 0 : l1label = new_loc_descr (DW_OP_dup, 0, 0);
15773 : 0 : add_loc_descr (&ret, l1label);
15774 : 0 : l2jump = new_loc_descr (DW_OP_bra, 0, 0);
15775 : 0 : add_loc_descr (&ret, l2jump);
15776 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
15777 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
15778 : 0 : tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
15779 : : VAR_INIT_STATUS_INITIALIZED);
15780 : 0 : if (tmp == NULL)
15781 : : return NULL;
15782 : 0 : add_loc_descr (&ret, tmp);
15783 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
15784 : 0 : add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
15785 : : ? DW_OP_plus : DW_OP_xor, 0, 0));
15786 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15787 : 0 : tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
15788 : : VAR_INIT_STATUS_INITIALIZED);
15789 : 0 : add_loc_descr (&ret, tmp);
15790 : 0 : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
15791 : 0 : l1jump = new_loc_descr (DW_OP_skip, 0, 0);
15792 : 0 : add_loc_descr (&ret, l1jump);
15793 : 0 : l2label = new_loc_descr (DW_OP_drop, 0, 0);
15794 : 0 : add_loc_descr (&ret, l2label);
15795 : 0 : l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15796 : 0 : l1jump->dw_loc_oprnd1.v.val_loc = l1label;
15797 : 0 : l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15798 : 0 : l2jump->dw_loc_oprnd1.v.val_loc = l2label;
15799 : 0 : return ret;
15800 : : }
15801 : :
15802 : : /* BSWAP (constS is initial shift count, either 56 or 24):
15803 : : constS const0
15804 : : L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
15805 : : const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
15806 : : DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
15807 : : DW_OP_minus DW_OP_swap DW_OP_skip <L1>
15808 : : L2: DW_OP_drop DW_OP_swap DW_OP_drop */
15809 : :
15810 : : static dw_loc_descr_ref
15811 : 90 : bswap_loc_descriptor (rtx rtl, scalar_int_mode mode,
15812 : : machine_mode mem_mode)
15813 : : {
15814 : 90 : dw_loc_descr_ref op0, ret, tmp;
15815 : 90 : dw_loc_descr_ref l1jump, l1label;
15816 : 90 : dw_loc_descr_ref l2jump, l2label;
15817 : :
15818 : 90 : if (BITS_PER_UNIT != 8
15819 : 59 : || (GET_MODE_BITSIZE (mode) != 32
15820 : 149 : && GET_MODE_BITSIZE (mode) != 64))
15821 : : return NULL;
15822 : :
15823 : 72 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15824 : : VAR_INIT_STATUS_INITIALIZED);
15825 : 72 : if (op0 == NULL)
15826 : : return NULL;
15827 : :
15828 : 72 : ret = op0;
15829 : 144 : tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
15830 : : mode, mem_mode,
15831 : : VAR_INIT_STATUS_INITIALIZED);
15832 : 72 : if (tmp == NULL)
15833 : : return NULL;
15834 : 72 : add_loc_descr (&ret, tmp);
15835 : 72 : tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
15836 : : VAR_INIT_STATUS_INITIALIZED);
15837 : 72 : if (tmp == NULL)
15838 : : return NULL;
15839 : 72 : add_loc_descr (&ret, tmp);
15840 : 72 : l1label = new_loc_descr (DW_OP_pick, 2, 0);
15841 : 72 : add_loc_descr (&ret, l1label);
15842 : 144 : tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
15843 : : mode, mem_mode,
15844 : : VAR_INIT_STATUS_INITIALIZED);
15845 : 72 : add_loc_descr (&ret, tmp);
15846 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
15847 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
15848 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
15849 : 72 : tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
15850 : : VAR_INIT_STATUS_INITIALIZED);
15851 : 72 : if (tmp == NULL)
15852 : : return NULL;
15853 : 72 : add_loc_descr (&ret, tmp);
15854 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
15855 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
15856 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
15857 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
15858 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15859 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
15860 : 72 : tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
15861 : : VAR_INIT_STATUS_INITIALIZED);
15862 : 72 : add_loc_descr (&ret, tmp);
15863 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
15864 : 72 : l2jump = new_loc_descr (DW_OP_bra, 0, 0);
15865 : 72 : add_loc_descr (&ret, l2jump);
15866 : 72 : tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
15867 : : VAR_INIT_STATUS_INITIALIZED);
15868 : 72 : add_loc_descr (&ret, tmp);
15869 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
15870 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15871 : 72 : l1jump = new_loc_descr (DW_OP_skip, 0, 0);
15872 : 72 : add_loc_descr (&ret, l1jump);
15873 : 72 : l2label = new_loc_descr (DW_OP_drop, 0, 0);
15874 : 72 : add_loc_descr (&ret, l2label);
15875 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15876 : 72 : add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
15877 : 72 : l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15878 : 72 : l1jump->dw_loc_oprnd1.v.val_loc = l1label;
15879 : 72 : l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
15880 : 72 : l2jump->dw_loc_oprnd1.v.val_loc = l2label;
15881 : 72 : return ret;
15882 : : }
15883 : :
15884 : : /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
15885 : : DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15886 : : [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
15887 : : DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
15888 : :
15889 : : ROTATERT is similar:
15890 : : DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
15891 : : DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
15892 : : [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
15893 : :
15894 : : static dw_loc_descr_ref
15895 : 2150 : rotate_loc_descriptor (rtx rtl, scalar_int_mode mode,
15896 : : machine_mode mem_mode)
15897 : : {
15898 : 2150 : rtx rtlop1 = XEXP (rtl, 1);
15899 : 2150 : dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
15900 : 2150 : int i;
15901 : :
15902 : 2150 : if (is_narrower_int_mode (GET_MODE (rtlop1), mode))
15903 : 52 : rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
15904 : 2150 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
15905 : : VAR_INIT_STATUS_INITIALIZED);
15906 : 2150 : op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
15907 : : VAR_INIT_STATUS_INITIALIZED);
15908 : 2150 : if (op0 == NULL || op1 == NULL)
15909 : : return NULL;
15910 : 4601 : if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
15911 : 726 : for (i = 0; i < 2; i++)
15912 : : {
15913 : 968 : if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
15914 : 484 : mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
15915 : : mode, mem_mode,
15916 : : VAR_INIT_STATUS_INITIALIZED);
15917 : 0 : else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
15918 : 0 : mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
15919 : : ? DW_OP_const4u
15920 : : : HOST_BITS_PER_WIDE_INT == 64
15921 : : ? DW_OP_const8u : DW_OP_constu,
15922 : 0 : GET_MODE_MASK (mode), 0);
15923 : : else
15924 : 0 : mask[i] = NULL;
15925 : 484 : if (mask[i] == NULL)
15926 : : return NULL;
15927 : 968 : add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
15928 : : }
15929 : 2147 : ret = op0;
15930 : 2147 : add_loc_descr (&ret, op1);
15931 : 2147 : add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
15932 : 2147 : add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
15933 : 2147 : if (GET_CODE (rtl) == ROTATERT)
15934 : : {
15935 : 193 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
15936 : 579 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
15937 : 193 : GET_MODE_BITSIZE (mode), 0));
15938 : : }
15939 : 2147 : add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
15940 : 2147 : if (mask[0] != NULL)
15941 : 484 : add_loc_descr (&ret, mask[0]);
15942 : 2147 : add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
15943 : 2147 : if (mask[1] != NULL)
15944 : : {
15945 : 242 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15946 : 242 : add_loc_descr (&ret, mask[1]);
15947 : 484 : add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
15948 : : }
15949 : 2147 : if (GET_CODE (rtl) == ROTATE)
15950 : : {
15951 : 1954 : add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
15952 : 5862 : add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
15953 : 1954 : GET_MODE_BITSIZE (mode), 0));
15954 : : }
15955 : 2147 : add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
15956 : 2147 : add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
15957 : 2147 : return ret;
15958 : : }
15959 : :
15960 : : /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
15961 : : for DEBUG_PARAMETER_REF RTL. */
15962 : :
15963 : : static dw_loc_descr_ref
15964 : 31463 : parameter_ref_descriptor (rtx rtl)
15965 : : {
15966 : 31463 : dw_loc_descr_ref ret;
15967 : 31463 : dw_die_ref ref;
15968 : :
15969 : 31463 : if (dwarf_strict)
15970 : : return NULL;
15971 : 31463 : gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
15972 : : /* With LTO during LTRANS we get the late DIE that refers to the early
15973 : : DIE, thus we add another indirection here. This seems to confuse
15974 : : gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO. */
15975 : 31463 : ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
15976 : 31463 : ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
15977 : 31463 : if (ref)
15978 : : {
15979 : 31463 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
15980 : 31463 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
15981 : 31463 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
15982 : : }
15983 : : else
15984 : : {
15985 : 0 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
15986 : 0 : ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
15987 : : }
15988 : : return ret;
15989 : : }
15990 : :
15991 : : /* The following routine converts the RTL for a variable or parameter
15992 : : (resident in memory) into an equivalent Dwarf representation of a
15993 : : mechanism for getting the address of that same variable onto the top of a
15994 : : hypothetical "address evaluation" stack.
15995 : :
15996 : : When creating memory location descriptors, we are effectively transforming
15997 : : the RTL for a memory-resident object into its Dwarf postfix expression
15998 : : equivalent. This routine recursively descends an RTL tree, turning
15999 : : it into Dwarf postfix code as it goes.
16000 : :
16001 : : MODE is the mode that should be assumed for the rtl if it is VOIDmode.
16002 : :
16003 : : MEM_MODE is the mode of the memory reference, needed to handle some
16004 : : autoincrement addressing modes.
16005 : :
16006 : : Return 0 if we can't represent the location. */
16007 : :
16008 : : dw_loc_descr_ref
16009 : 24136479 : mem_loc_descriptor (rtx rtl, machine_mode mode,
16010 : : machine_mode mem_mode,
16011 : : enum var_init_status initialized)
16012 : : {
16013 : 24136479 : dw_loc_descr_ref mem_loc_result = NULL;
16014 : 24136479 : enum dwarf_location_atom op;
16015 : 24136479 : dw_loc_descr_ref op0, op1;
16016 : 24136479 : rtx inner = NULL_RTX;
16017 : :
16018 : 24136479 : if (mode == VOIDmode)
16019 : 895 : mode = GET_MODE (rtl);
16020 : :
16021 : : /* Note that for a dynamically sized array, the location we will generate a
16022 : : description of here will be the lowest numbered location which is
16023 : : actually within the array. That's *not* necessarily the same as the
16024 : : zeroth element of the array. */
16025 : :
16026 : 24136479 : rtl = targetm.delegitimize_address (rtl);
16027 : :
16028 : 24136479 : if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
16029 : : return NULL;
16030 : :
16031 : 24136479 : scalar_int_mode int_mode = BImode, inner_mode, op1_mode;
16032 : 24136479 : switch (GET_CODE (rtl))
16033 : : {
16034 : 0 : case POST_INC:
16035 : 0 : case POST_DEC:
16036 : 0 : case POST_MODIFY:
16037 : 0 : return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
16038 : :
16039 : 298598 : case SUBREG:
16040 : : /* The case of a subreg may arise when we have a local (register)
16041 : : variable or a formal (register) parameter which doesn't quite fill
16042 : : up an entire register. For now, just assume that it is
16043 : : legitimate to make the Dwarf info refer to the whole register which
16044 : : contains the given subreg. */
16045 : 298598 : if (!subreg_lowpart_p (rtl))
16046 : : break;
16047 : 285251 : inner = SUBREG_REG (rtl);
16048 : : /* FALLTHRU */
16049 : 285251 : case TRUNCATE:
16050 : 285251 : if (inner == NULL_RTX)
16051 : 6919 : inner = XEXP (rtl, 0);
16052 : 292170 : if (is_a <scalar_int_mode> (mode, &int_mode)
16053 : 291613 : && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
16054 : 312501 : && (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16055 : : #ifdef POINTERS_EXTEND_UNSIGNED
16056 : 100 : || (int_mode == Pmode && mem_mode != VOIDmode)
16057 : : #endif
16058 : : )
16059 : 604571 : && GET_MODE_SIZE (inner_mode) <= DWARF2_ADDR_SIZE)
16060 : : {
16061 : 259720 : mem_loc_result = mem_loc_descriptor (inner,
16062 : : inner_mode,
16063 : : mem_mode, initialized);
16064 : 259720 : break;
16065 : : }
16066 : 32450 : if (dwarf_strict && dwarf_version < 5)
16067 : : break;
16068 : 32450 : if (is_a <scalar_int_mode> (mode, &int_mode)
16069 : 31893 : && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
16070 : 93810 : ? GET_MODE_SIZE (int_mode) <= GET_MODE_SIZE (inner_mode)
16071 : 35990 : : known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
16072 : : {
16073 : 32274 : dw_die_ref type_die;
16074 : 32274 : dw_loc_descr_ref cvt;
16075 : :
16076 : 64548 : mem_loc_result = mem_loc_descriptor (inner,
16077 : 32274 : GET_MODE (inner),
16078 : : mem_mode, initialized);
16079 : 32274 : if (mem_loc_result == NULL)
16080 : : break;
16081 : 22159 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16082 : 22159 : if (type_die == NULL)
16083 : : {
16084 : 0 : mem_loc_result = NULL;
16085 : 0 : break;
16086 : : }
16087 : 66477 : if (maybe_ne (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
16088 : 20573 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16089 : : else
16090 : 1586 : cvt = new_loc_descr (dwarf_OP (DW_OP_reinterpret), 0, 0);
16091 : 22159 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16092 : 22159 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16093 : 22159 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16094 : 22159 : add_loc_descr (&mem_loc_result, cvt);
16095 : 22159 : if (is_a <scalar_int_mode> (mode, &int_mode)
16096 : 64411 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
16097 : : {
16098 : : /* Convert it to untyped afterwards. */
16099 : 21323 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16100 : 21323 : add_loc_descr (&mem_loc_result, cvt);
16101 : : }
16102 : : }
16103 : : break;
16104 : :
16105 : 3144154 : case REG:
16106 : 3144154 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16107 : 6604750 : || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
16108 : 43525 : && rtl != arg_pointer_rtx
16109 : 43523 : && rtl != frame_pointer_rtx
16110 : : #ifdef POINTERS_EXTEND_UNSIGNED
16111 : 84665 : && (int_mode != Pmode || mem_mode == VOIDmode)
16112 : : #endif
16113 : : ))
16114 : : {
16115 : 109635 : dw_die_ref type_die;
16116 : 109635 : unsigned int debugger_regnum;
16117 : :
16118 : 109635 : if (dwarf_strict && dwarf_version < 5)
16119 : : break;
16120 : 109635 : if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
16121 : : break;
16122 : 109627 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16123 : 109627 : if (type_die == NULL)
16124 : : break;
16125 : :
16126 : 105129 : debugger_regnum = debugger_reg_number (rtl);
16127 : 105129 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
16128 : : break;
16129 : 105129 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_regval_type),
16130 : : debugger_regnum, 0);
16131 : 105129 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
16132 : 105129 : mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
16133 : 105129 : mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
16134 : 105129 : break;
16135 : : }
16136 : : /* Whenever a register number forms a part of the description of the
16137 : : method for calculating the (dynamic) address of a memory resident
16138 : : object, DWARF rules require the register number be referred to as
16139 : : a "base register". This distinction is not based in any way upon
16140 : : what category of register the hardware believes the given register
16141 : : belongs to. This is strictly DWARF terminology we're dealing with
16142 : : here. Note that in cases where the location of a memory-resident
16143 : : data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
16144 : : OP_CONST (0)) the actual DWARF location descriptor that we generate
16145 : : may just be OP_BASEREG (basereg). This may look deceptively like
16146 : : the object in question was allocated to a register (rather than in
16147 : : memory) so DWARF consumers need to be aware of the subtle
16148 : : distinction between OP_REG and OP_BASEREG. */
16149 : 3034519 : if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
16150 : 3032908 : mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
16151 : 98 : else if (stack_realign_drap
16152 : 0 : && crtl->drap_reg
16153 : 0 : && crtl->args.internal_arg_pointer == rtl
16154 : 1611 : && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
16155 : : {
16156 : : /* If RTL is internal_arg_pointer, which has been optimized
16157 : : out, use DRAP instead. */
16158 : 0 : mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
16159 : : VAR_INIT_STATUS_INITIALIZED);
16160 : : }
16161 : : break;
16162 : :
16163 : 302489 : case SIGN_EXTEND:
16164 : 302489 : case ZERO_EXTEND:
16165 : 302489 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16166 : 302489 : || !is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &inner_mode))
16167 : : break;
16168 : 302489 : op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
16169 : : mem_mode, VAR_INIT_STATUS_INITIALIZED);
16170 : 302489 : if (op0 == 0)
16171 : : break;
16172 : 275401 : else if (GET_CODE (rtl) == ZERO_EXTEND
16173 : 262853 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16174 : 194995 : && GET_MODE_BITSIZE (inner_mode) < HOST_BITS_PER_WIDE_INT
16175 : : /* If DW_OP_const{1,2,4}u won't be used, it is shorter
16176 : : to expand zero extend as two shifts instead of
16177 : : masking. */
16178 : 497536 : && GET_MODE_SIZE (inner_mode) <= 4)
16179 : : {
16180 : 194995 : mem_loc_result = op0;
16181 : 194995 : add_loc_descr (&mem_loc_result,
16182 : 194995 : int_loc_descriptor (GET_MODE_MASK (inner_mode)));
16183 : 194995 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
16184 : : }
16185 : 192379 : else if (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
16186 : : {
16187 : 49171 : int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (inner_mode);
16188 : 49171 : shift *= BITS_PER_UNIT;
16189 : 49171 : if (GET_CODE (rtl) == SIGN_EXTEND)
16190 : : op = DW_OP_shra;
16191 : : else
16192 : 0 : op = DW_OP_shr;
16193 : 49171 : mem_loc_result = op0;
16194 : 49171 : add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
16195 : 49171 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
16196 : 49171 : add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
16197 : 49171 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16198 : : }
16199 : 31235 : else if (!dwarf_strict || dwarf_version >= 5)
16200 : : {
16201 : 31235 : dw_die_ref type_die1, type_die2;
16202 : 31235 : dw_loc_descr_ref cvt;
16203 : :
16204 : 31235 : type_die1 = base_type_for_mode (inner_mode,
16205 : : GET_CODE (rtl) == ZERO_EXTEND);
16206 : 31235 : if (type_die1 == NULL)
16207 : : break;
16208 : 31235 : type_die2 = base_type_for_mode (int_mode, 1);
16209 : 31235 : if (type_die2 == NULL)
16210 : : break;
16211 : 31235 : mem_loc_result = op0;
16212 : 31235 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16213 : 31235 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16214 : 31235 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
16215 : 31235 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16216 : 31235 : add_loc_descr (&mem_loc_result, cvt);
16217 : 31235 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16218 : 31235 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16219 : 31235 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
16220 : 31235 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16221 : 31235 : add_loc_descr (&mem_loc_result, cvt);
16222 : : }
16223 : : break;
16224 : :
16225 : 1646564 : case MEM:
16226 : 1646564 : {
16227 : 1646564 : rtx new_rtl = avoid_constant_pool_reference (rtl);
16228 : 1646564 : if (new_rtl != rtl)
16229 : : {
16230 : 0 : mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
16231 : : initialized);
16232 : 0 : if (mem_loc_result != NULL)
16233 : : return mem_loc_result;
16234 : : }
16235 : : }
16236 : 1646564 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
16237 : 1646564 : get_address_mode (rtl), mode,
16238 : : VAR_INIT_STATUS_INITIALIZED);
16239 : 1646564 : if (mem_loc_result == NULL)
16240 : 8515 : mem_loc_result = tls_mem_loc_descriptor (rtl);
16241 : 1646564 : if (mem_loc_result != NULL)
16242 : : {
16243 : 1638049 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16244 : 3517238 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16245 : : {
16246 : 61993 : dw_die_ref type_die;
16247 : 61993 : dw_loc_descr_ref deref;
16248 : 61993 : HOST_WIDE_INT size;
16249 : :
16250 : 61993 : if (dwarf_strict && dwarf_version < 5)
16251 : 1192 : return NULL;
16252 : 123986 : if (!GET_MODE_SIZE (mode).is_constant (&size))
16253 : : return NULL;
16254 : 61993 : type_die
16255 : 61993 : = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16256 : 61993 : if (type_die == NULL)
16257 : : return NULL;
16258 : 60801 : deref = new_loc_descr (dwarf_OP (DW_OP_deref_type), size, 0);
16259 : 60801 : deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
16260 : 60801 : deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
16261 : 60801 : deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
16262 : 60801 : add_loc_descr (&mem_loc_result, deref);
16263 : : }
16264 : 3401858 : else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
16265 : 1401107 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
16266 : : else
16267 : 349898 : add_loc_descr (&mem_loc_result,
16268 : : new_loc_descr (DW_OP_deref_size,
16269 : 174949 : GET_MODE_SIZE (int_mode), 0));
16270 : : }
16271 : : break;
16272 : :
16273 : 0 : case LO_SUM:
16274 : 0 : return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
16275 : :
16276 : 1048060 : case LABEL_REF:
16277 : : /* Some ports can transform a symbol ref into a label ref, because
16278 : : the symbol ref is too far away and has to be dumped into a constant
16279 : : pool. */
16280 : 1048060 : case CONST:
16281 : 1048060 : case SYMBOL_REF:
16282 : 1048060 : case UNSPEC:
16283 : 1048060 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16284 : 2152045 : || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
16285 : : #ifdef POINTERS_EXTEND_UNSIGNED
16286 : 0 : && (int_mode != Pmode || mem_mode == VOIDmode)
16287 : : #endif
16288 : : ))
16289 : : break;
16290 : :
16291 : 1047897 : if (GET_CODE (rtl) == UNSPEC)
16292 : : {
16293 : : /* If delegitimize_address couldn't do anything with the UNSPEC, we
16294 : : can't express it in the debug info. This can happen e.g. with some
16295 : : TLS UNSPECs. Allow UNSPECs formerly from CONST that the backend
16296 : : approves. */
16297 : 46 : bool not_ok = false;
16298 : 46 : subrtx_var_iterator::array_type array;
16299 : 106 : FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
16300 : 92 : if (*iter != rtl && !CONSTANT_P (*iter))
16301 : : {
16302 : : not_ok = true;
16303 : : break;
16304 : : }
16305 : :
16306 : 46 : if (not_ok)
16307 : : break;
16308 : :
16309 : 14 : FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
16310 : 14 : if (!const_ok_for_output_1 (*iter))
16311 : : {
16312 : : not_ok = true;
16313 : : break;
16314 : : }
16315 : :
16316 : 14 : if (not_ok)
16317 : : break;
16318 : :
16319 : 0 : rtl = gen_rtx_CONST (GET_MODE (rtl), rtl);
16320 : 0 : goto symref;
16321 : 46 : }
16322 : :
16323 : 1047851 : if (GET_CODE (rtl) == SYMBOL_REF
16324 : 1047851 : && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
16325 : : {
16326 : 4448 : dw_loc_descr_ref temp;
16327 : :
16328 : : /* If this is not defined, we have no way to emit the data. */
16329 : 4448 : if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
16330 : : break;
16331 : :
16332 : 4448 : temp = new_addr_loc_descr (rtl, dtprel_true);
16333 : :
16334 : : /* We check for DWARF 5 here because gdb did not implement
16335 : : DW_OP_form_tls_address until after 7.12. */
16336 : 4452 : mem_loc_result = new_loc_descr ((dwarf_version >= 5
16337 : : ? DW_OP_form_tls_address
16338 : : : DW_OP_GNU_push_tls_address),
16339 : : 0, 0);
16340 : 4448 : add_loc_descr (&mem_loc_result, temp);
16341 : :
16342 : 4448 : break;
16343 : : }
16344 : :
16345 : 1043403 : if (!const_ok_for_output (rtl))
16346 : : {
16347 : 84890 : if (GET_CODE (rtl) == CONST)
16348 : 8483 : switch (GET_CODE (XEXP (rtl, 0)))
16349 : : {
16350 : 0 : case NOT:
16351 : 0 : op = DW_OP_not;
16352 : 0 : goto try_const_unop;
16353 : 0 : case NEG:
16354 : 0 : op = DW_OP_neg;
16355 : 0 : goto try_const_unop;
16356 : 0 : try_const_unop:
16357 : 0 : rtx arg;
16358 : 0 : arg = XEXP (XEXP (rtl, 0), 0);
16359 : 0 : if (!CONSTANT_P (arg))
16360 : 0 : arg = gen_rtx_CONST (int_mode, arg);
16361 : 0 : op0 = mem_loc_descriptor (arg, int_mode, mem_mode,
16362 : : initialized);
16363 : 0 : if (op0)
16364 : : {
16365 : 0 : mem_loc_result = op0;
16366 : 0 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16367 : : }
16368 : : break;
16369 : 8483 : default:
16370 : 8483 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), int_mode,
16371 : : mem_mode, initialized);
16372 : 8483 : break;
16373 : : }
16374 : : break;
16375 : : }
16376 : :
16377 : 958513 : symref:
16378 : 1079491 : mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
16379 : 1079491 : vec_safe_push (used_rtx_array, rtl);
16380 : 1079491 : break;
16381 : :
16382 : 207362 : case CONCAT:
16383 : 207362 : case CONCATN:
16384 : 207362 : case VAR_LOCATION:
16385 : 207362 : case DEBUG_IMPLICIT_PTR:
16386 : 207362 : expansion_failed (NULL_TREE, rtl,
16387 : : "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
16388 : 207362 : return 0;
16389 : :
16390 : 1338027 : case ENTRY_VALUE:
16391 : 1338027 : if (dwarf_strict && dwarf_version < 5)
16392 : : return NULL;
16393 : 1338027 : if (REG_P (ENTRY_VALUE_EXP (rtl)))
16394 : : {
16395 : 1336752 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16396 : 2672530 : || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16397 : 39936 : op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
16398 : : VOIDmode, VAR_INIT_STATUS_INITIALIZED);
16399 : : else
16400 : : {
16401 : 1296816 : unsigned int debugger_regnum = debugger_reg_number (ENTRY_VALUE_EXP (rtl));
16402 : 1296816 : if (debugger_regnum == IGNORED_DWARF_REGNUM)
16403 : : return NULL;
16404 : 1296816 : op0 = one_reg_loc_descriptor (debugger_regnum,
16405 : : VAR_INIT_STATUS_INITIALIZED);
16406 : : }
16407 : : }
16408 : 1275 : else if (MEM_P (ENTRY_VALUE_EXP (rtl))
16409 : 1275 : && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
16410 : : {
16411 : 1275 : op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
16412 : : VOIDmode, VAR_INIT_STATUS_INITIALIZED);
16413 : 1275 : if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
16414 : : return NULL;
16415 : : }
16416 : : else
16417 : 0 : gcc_unreachable ();
16418 : 1338005 : if (op0 == NULL)
16419 : : return NULL;
16420 : 1336931 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_entry_value), 0, 0);
16421 : 1336931 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
16422 : 1336931 : mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
16423 : 1336931 : break;
16424 : :
16425 : 31463 : case DEBUG_PARAMETER_REF:
16426 : 31463 : mem_loc_result = parameter_ref_descriptor (rtl);
16427 : 31463 : break;
16428 : :
16429 : 0 : case PRE_MODIFY:
16430 : : /* Extract the PLUS expression nested inside and fall into
16431 : : PLUS code below. */
16432 : 0 : rtl = XEXP (rtl, 1);
16433 : 0 : goto plus;
16434 : :
16435 : 0 : case PRE_INC:
16436 : 0 : case PRE_DEC:
16437 : : /* Turn these into a PLUS expression and fall into the PLUS code
16438 : : below. */
16439 : 0 : rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
16440 : : gen_int_mode (GET_CODE (rtl) == PRE_INC
16441 : : ? GET_MODE_UNIT_SIZE (mem_mode)
16442 : : : -GET_MODE_UNIT_SIZE (mem_mode),
16443 : : mode));
16444 : :
16445 : : /* fall through */
16446 : :
16447 : 11110196 : case PLUS:
16448 : 11110196 : plus:
16449 : 11110196 : if (is_based_loc (rtl)
16450 : 9702628 : && is_a <scalar_int_mode> (mode, &int_mode)
16451 : 22158668 : && (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16452 : 673 : || XEXP (rtl, 0) == arg_pointer_rtx
16453 : 673 : || XEXP (rtl, 0) == frame_pointer_rtx))
16454 : 9701956 : mem_loc_result = based_loc_descr (XEXP (rtl, 0),
16455 : 9701956 : INTVAL (XEXP (rtl, 1)),
16456 : : VAR_INIT_STATUS_INITIALIZED);
16457 : : else
16458 : : {
16459 : 1408240 : mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16460 : : VAR_INIT_STATUS_INITIALIZED);
16461 : 1408240 : if (mem_loc_result == 0)
16462 : : break;
16463 : :
16464 : 1353083 : if (CONST_INT_P (XEXP (rtl, 1))
16465 : 2094038 : && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
16466 : 740955 : <= DWARF2_ADDR_SIZE))
16467 : 739170 : loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
16468 : : else
16469 : : {
16470 : 613913 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16471 : : VAR_INIT_STATUS_INITIALIZED);
16472 : 613913 : if (op1 == 0)
16473 : : return NULL;
16474 : 601227 : add_loc_descr (&mem_loc_result, op1);
16475 : 601227 : add_loc_descr (&mem_loc_result,
16476 : : new_loc_descr (DW_OP_plus, 0, 0));
16477 : : }
16478 : : }
16479 : : break;
16480 : :
16481 : : /* If a pseudo-reg is optimized away, it is possible for it to
16482 : : be replaced with a MEM containing a multiply or shift. */
16483 : 487866 : case MINUS:
16484 : 487866 : op = DW_OP_minus;
16485 : 487866 : goto do_binop;
16486 : :
16487 : 262607 : case MULT:
16488 : 262607 : op = DW_OP_mul;
16489 : 262607 : goto do_binop;
16490 : :
16491 : 216173 : case DIV:
16492 : 0 : if ((!dwarf_strict || dwarf_version >= 5)
16493 : 216173 : && is_a <scalar_int_mode> (mode, &int_mode)
16494 : 428129 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16495 : : {
16496 : 67 : mem_loc_result = typed_binop (DW_OP_div, rtl,
16497 : : base_type_for_mode (mode, 0),
16498 : : int_mode, mem_mode);
16499 : 67 : break;
16500 : : }
16501 : 216106 : op = DW_OP_div;
16502 : 216106 : goto do_binop;
16503 : :
16504 : 27451 : case UMOD:
16505 : 27451 : op = DW_OP_mod;
16506 : 27451 : goto do_binop;
16507 : :
16508 : 352604 : case ASHIFT:
16509 : 352604 : op = DW_OP_shl;
16510 : 352604 : goto do_shift;
16511 : :
16512 : 152938 : case ASHIFTRT:
16513 : 152938 : op = DW_OP_shra;
16514 : 152938 : goto do_shift;
16515 : :
16516 : 277308 : case LSHIFTRT:
16517 : 277308 : op = DW_OP_shr;
16518 : 277308 : goto do_shift;
16519 : :
16520 : 782850 : do_shift:
16521 : 782850 : if (!is_a <scalar_int_mode> (mode, &int_mode))
16522 : : break;
16523 : 782824 : op0 = mem_loc_descriptor (XEXP (rtl, 0), int_mode, mem_mode,
16524 : : VAR_INIT_STATUS_INITIALIZED);
16525 : 782824 : {
16526 : 782824 : rtx rtlop1 = XEXP (rtl, 1);
16527 : 782824 : if (is_a <scalar_int_mode> (GET_MODE (rtlop1), &op1_mode)
16528 : 801624 : && GET_MODE_BITSIZE (op1_mode) < GET_MODE_BITSIZE (int_mode))
16529 : 7047 : rtlop1 = gen_rtx_ZERO_EXTEND (int_mode, rtlop1);
16530 : 782824 : op1 = mem_loc_descriptor (rtlop1, int_mode, mem_mode,
16531 : : VAR_INIT_STATUS_INITIALIZED);
16532 : : }
16533 : :
16534 : 782824 : if (op0 == 0 || op1 == 0)
16535 : : break;
16536 : :
16537 : 698655 : mem_loc_result = op0;
16538 : 698655 : add_loc_descr (&mem_loc_result, op1);
16539 : 698655 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16540 : 698655 : break;
16541 : :
16542 : 220530 : case AND:
16543 : 220530 : op = DW_OP_and;
16544 : 220530 : goto do_binop;
16545 : :
16546 : 85019 : case IOR:
16547 : 85019 : op = DW_OP_or;
16548 : 85019 : goto do_binop;
16549 : :
16550 : 15376 : case XOR:
16551 : 15376 : op = DW_OP_xor;
16552 : 15376 : goto do_binop;
16553 : :
16554 : 1361482 : do_binop:
16555 : 1361482 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16556 : : VAR_INIT_STATUS_INITIALIZED);
16557 : 1361482 : if (XEXP (rtl, 0) == XEXP (rtl, 1))
16558 : : {
16559 : 8719 : if (op0 == 0)
16560 : : break;
16561 : 8715 : mem_loc_result = op0;
16562 : 8715 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_dup, 0, 0));
16563 : 8715 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16564 : 8715 : break;
16565 : : }
16566 : 1352763 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16567 : : VAR_INIT_STATUS_INITIALIZED);
16568 : :
16569 : 1352763 : if (op0 == 0 || op1 == 0)
16570 : : break;
16571 : :
16572 : 1211112 : mem_loc_result = op0;
16573 : 1211112 : add_loc_descr (&mem_loc_result, op1);
16574 : 1211112 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16575 : 1211112 : break;
16576 : :
16577 : 5121 : case MOD:
16578 : 0 : if ((!dwarf_strict || dwarf_version >= 5)
16579 : 5121 : && is_a <scalar_int_mode> (mode, &int_mode)
16580 : 10460 : && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
16581 : : {
16582 : 15 : mem_loc_result = typed_binop (DW_OP_mod, rtl,
16583 : : base_type_for_mode (mode, 0),
16584 : : int_mode, mem_mode);
16585 : 15 : break;
16586 : : }
16587 : :
16588 : 5106 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16589 : : VAR_INIT_STATUS_INITIALIZED);
16590 : 5106 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16591 : : VAR_INIT_STATUS_INITIALIZED);
16592 : :
16593 : 5106 : if (op0 == 0 || op1 == 0)
16594 : : break;
16595 : :
16596 : 4901 : mem_loc_result = op0;
16597 : 4901 : add_loc_descr (&mem_loc_result, op1);
16598 : 4901 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
16599 : 4901 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
16600 : 4901 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
16601 : 4901 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
16602 : 4901 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
16603 : 4901 : break;
16604 : :
16605 : 49677 : case UDIV:
16606 : 0 : if ((!dwarf_strict || dwarf_version >= 5)
16607 : 49677 : && is_a <scalar_int_mode> (mode, &int_mode))
16608 : : {
16609 : : /* We can use a signed divide if the sign bit is not set. */
16610 : 100542 : if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
16611 : : {
16612 : 46527 : op = DW_OP_div;
16613 : 46527 : goto do_binop;
16614 : : }
16615 : :
16616 : 3150 : mem_loc_result = typed_binop (DW_OP_div, rtl,
16617 : : base_type_for_mode (int_mode, 1),
16618 : : int_mode, mem_mode);
16619 : : }
16620 : : break;
16621 : :
16622 : 40952 : case NOT:
16623 : 40952 : op = DW_OP_not;
16624 : 40952 : goto do_unop;
16625 : :
16626 : 4440 : case ABS:
16627 : 4440 : op = DW_OP_abs;
16628 : 4440 : goto do_unop;
16629 : :
16630 : 84758 : case NEG:
16631 : 84758 : op = DW_OP_neg;
16632 : 84758 : goto do_unop;
16633 : :
16634 : 130150 : do_unop:
16635 : 130150 : op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
16636 : : VAR_INIT_STATUS_INITIALIZED);
16637 : :
16638 : 130150 : if (op0 == 0)
16639 : : break;
16640 : :
16641 : 129313 : mem_loc_result = op0;
16642 : 129313 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16643 : 129313 : break;
16644 : :
16645 : 2215300 : case CONST_INT:
16646 : 2215300 : if (!is_a <scalar_int_mode> (mode, &int_mode)
16647 : 2401312 : || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16648 : : #ifdef POINTERS_EXTEND_UNSIGNED
16649 : 2291519 : || (int_mode == Pmode
16650 : 0 : && mem_mode != VOIDmode
16651 : 0 : && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
16652 : : #endif
16653 : : )
16654 : : {
16655 : 2175880 : mem_loc_result = int_loc_descriptor (INTVAL (rtl));
16656 : 2175880 : break;
16657 : : }
16658 : 0 : if ((!dwarf_strict || dwarf_version >= 5)
16659 : 78840 : && (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT
16660 : 2621 : || GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_DOUBLE_INT))
16661 : : {
16662 : 39420 : dw_die_ref type_die = base_type_for_mode (int_mode, 1);
16663 : 39420 : scalar_int_mode amode;
16664 : 39420 : if (type_die == NULL)
16665 : 24604 : return NULL;
16666 : 39420 : if (INTVAL (rtl) >= 0
16667 : 110413 : && (int_mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT, 0)
16668 : 37671 : .exists (&amode))
16669 : 37671 : && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
16670 : : /* const DW_OP_convert <XXX> vs.
16671 : : DW_OP_const_type <XXX, 1, const>. */
16672 : 64024 : && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
16673 : 24604 : < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode))
16674 : : {
16675 : 24604 : mem_loc_result = int_loc_descriptor (INTVAL (rtl));
16676 : 24604 : op0 = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16677 : 24604 : op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16678 : 24604 : op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16679 : 24604 : op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
16680 : 24604 : add_loc_descr (&mem_loc_result, op0);
16681 : 24604 : return mem_loc_result;
16682 : : }
16683 : 29632 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0,
16684 : 14816 : INTVAL (rtl));
16685 : 14816 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16686 : 14816 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16687 : 14816 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
16688 : 29632 : if (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT)
16689 : 14795 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
16690 : : else
16691 : : {
16692 : 21 : mem_loc_result->dw_loc_oprnd2.val_class
16693 : 21 : = dw_val_class_const_double;
16694 : 21 : mem_loc_result->dw_loc_oprnd2.v.val_double
16695 : 21 : = double_int::from_shwi (INTVAL (rtl));
16696 : : }
16697 : : }
16698 : : break;
16699 : :
16700 : 32763 : case CONST_DOUBLE:
16701 : 32763 : if (!dwarf_strict || dwarf_version >= 5)
16702 : : {
16703 : 32763 : dw_die_ref type_die;
16704 : :
16705 : : /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
16706 : : CONST_DOUBLE rtx could represent either a large integer
16707 : : or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
16708 : : the value is always a floating point constant.
16709 : :
16710 : : When it is an integer, a CONST_DOUBLE is used whenever
16711 : : the constant requires 2 HWIs to be adequately represented.
16712 : : We output CONST_DOUBLEs as blocks. */
16713 : 32763 : if (mode == VOIDmode
16714 : 32763 : || (GET_MODE (rtl) == VOIDmode
16715 : 0 : && maybe_ne (GET_MODE_BITSIZE (mode),
16716 : 0 : HOST_BITS_PER_DOUBLE_INT)))
16717 : : break;
16718 : 32763 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16719 : 32763 : if (type_die == NULL)
16720 : : return NULL;
16721 : 32763 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0, 0);
16722 : 32763 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16723 : 32763 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16724 : 32763 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
16725 : : #if TARGET_SUPPORTS_WIDE_INT == 0
16726 : : if (!SCALAR_FLOAT_MODE_P (mode))
16727 : : {
16728 : : mem_loc_result->dw_loc_oprnd2.val_class
16729 : : = dw_val_class_const_double;
16730 : : mem_loc_result->dw_loc_oprnd2.v.val_double
16731 : : = rtx_to_double_int (rtl);
16732 : : }
16733 : : else
16734 : : #endif
16735 : 32763 : {
16736 : 32763 : scalar_float_mode float_mode = as_a <scalar_float_mode> (mode);
16737 : 32763 : unsigned int length = GET_MODE_SIZE (float_mode);
16738 : 32763 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
16739 : 32763 : unsigned int elt_size = insert_float (rtl, array);
16740 : :
16741 : 32763 : mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
16742 : 32763 : mem_loc_result->dw_loc_oprnd2.v.val_vec.length
16743 : 32763 : = length / elt_size;
16744 : 32763 : mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
16745 : 32763 : mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
16746 : : }
16747 : : }
16748 : : break;
16749 : :
16750 : 121 : case CONST_WIDE_INT:
16751 : 121 : if (!dwarf_strict || dwarf_version >= 5)
16752 : : {
16753 : 121 : dw_die_ref type_die;
16754 : :
16755 : 121 : type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
16756 : 121 : if (type_die == NULL)
16757 : : return NULL;
16758 : 121 : mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0, 0);
16759 : 121 : mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16760 : 121 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16761 : 121 : mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
16762 : 121 : mem_loc_result->dw_loc_oprnd2.val_class
16763 : 121 : = dw_val_class_wide_int;
16764 : 121 : mem_loc_result->dw_loc_oprnd2.v.val_wide
16765 : 121 : = alloc_dw_wide_int (rtx_mode_t (rtl, mode));
16766 : : }
16767 : : break;
16768 : :
16769 : 0 : case CONST_POLY_INT:
16770 : 0 : mem_loc_result = int_loc_descriptor (rtx_to_poly_int64 (rtl));
16771 : 0 : break;
16772 : :
16773 : 34767 : case EQ:
16774 : 34767 : mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
16775 : 34767 : break;
16776 : :
16777 : 5094 : case GE:
16778 : 5094 : mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
16779 : 5094 : break;
16780 : :
16781 : 4298 : case GT:
16782 : 4298 : mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
16783 : 4298 : break;
16784 : :
16785 : 2563 : case LE:
16786 : 2563 : mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
16787 : 2563 : break;
16788 : :
16789 : 30003 : case LT:
16790 : 30003 : mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
16791 : 30003 : break;
16792 : :
16793 : 48870 : case NE:
16794 : 48870 : mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
16795 : 48870 : break;
16796 : :
16797 : 5168 : case GEU:
16798 : 5168 : mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
16799 : 5168 : break;
16800 : :
16801 : 12361 : case GTU:
16802 : 12361 : mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
16803 : 12361 : break;
16804 : :
16805 : 15448 : case LEU:
16806 : 15448 : mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
16807 : 15448 : break;
16808 : :
16809 : 3142 : case LTU:
16810 : 3142 : mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
16811 : 3142 : break;
16812 : :
16813 : 56519 : case UMIN:
16814 : 56519 : case UMAX:
16815 : 56519 : if (!SCALAR_INT_MODE_P (mode))
16816 : : break;
16817 : : /* FALLTHRU */
16818 : 74884 : case SMIN:
16819 : 74884 : case SMAX:
16820 : 74884 : mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
16821 : 74884 : break;
16822 : :
16823 : 4884 : case ZERO_EXTRACT:
16824 : 4884 : case SIGN_EXTRACT:
16825 : 4884 : if (CONST_INT_P (XEXP (rtl, 1))
16826 : 4884 : && CONST_INT_P (XEXP (rtl, 2))
16827 : 4883 : && is_a <scalar_int_mode> (mode, &int_mode)
16828 : 4875 : && is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &inner_mode)
16829 : 3984 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
16830 : 3984 : && GET_MODE_SIZE (inner_mode) <= DWARF2_ADDR_SIZE
16831 : 4884 : && ((unsigned) INTVAL (XEXP (rtl, 1))
16832 : 3674 : + (unsigned) INTVAL (XEXP (rtl, 2))
16833 : 3674 : <= GET_MODE_BITSIZE (int_mode)))
16834 : : {
16835 : 3419 : int shift, size;
16836 : 3419 : op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
16837 : : mem_mode, VAR_INIT_STATUS_INITIALIZED);
16838 : 3419 : if (op0 == 0)
16839 : : break;
16840 : 3419 : if (GET_CODE (rtl) == SIGN_EXTRACT)
16841 : : op = DW_OP_shra;
16842 : : else
16843 : 438 : op = DW_OP_shr;
16844 : 3419 : mem_loc_result = op0;
16845 : 3419 : size = INTVAL (XEXP (rtl, 1));
16846 : 3419 : shift = INTVAL (XEXP (rtl, 2));
16847 : 3419 : if (BITS_BIG_ENDIAN)
16848 : : shift = GET_MODE_BITSIZE (inner_mode) - shift - size;
16849 : 3586 : if (shift + size != (int) DWARF2_ADDR_SIZE)
16850 : : {
16851 : 3365 : add_loc_descr (&mem_loc_result,
16852 : 3365 : int_loc_descriptor (DWARF2_ADDR_SIZE
16853 : 3365 : - shift - size));
16854 : 3365 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
16855 : : }
16856 : 3586 : if (size != (int) DWARF2_ADDR_SIZE)
16857 : : {
16858 : 3160 : add_loc_descr (&mem_loc_result,
16859 : 3324 : int_loc_descriptor (DWARF2_ADDR_SIZE - size));
16860 : 3160 : add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
16861 : : }
16862 : : }
16863 : : break;
16864 : :
16865 : 28074 : case IF_THEN_ELSE:
16866 : 28074 : {
16867 : 28074 : dw_loc_descr_ref op2, bra_node, drop_node;
16868 : 28074 : op0 = mem_loc_descriptor (XEXP (rtl, 0),
16869 : 28074 : GET_MODE (XEXP (rtl, 0)) == VOIDmode
16870 : 26726 : ? word_mode : GET_MODE (XEXP (rtl, 0)),
16871 : : mem_mode, VAR_INIT_STATUS_INITIALIZED);
16872 : 28074 : op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
16873 : : VAR_INIT_STATUS_INITIALIZED);
16874 : 28074 : op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
16875 : : VAR_INIT_STATUS_INITIALIZED);
16876 : 28074 : if (op0 == NULL || op1 == NULL || op2 == NULL)
16877 : : break;
16878 : :
16879 : 26365 : mem_loc_result = op1;
16880 : 26365 : add_loc_descr (&mem_loc_result, op2);
16881 : 26365 : add_loc_descr (&mem_loc_result, op0);
16882 : 26365 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
16883 : 26365 : add_loc_descr (&mem_loc_result, bra_node);
16884 : 26365 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
16885 : 26365 : drop_node = new_loc_descr (DW_OP_drop, 0, 0);
16886 : 26365 : add_loc_descr (&mem_loc_result, drop_node);
16887 : 26365 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
16888 : 26365 : bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
16889 : : }
16890 : 26365 : break;
16891 : :
16892 : 24377 : case FLOAT_EXTEND:
16893 : 24377 : case FLOAT_TRUNCATE:
16894 : 24377 : case FLOAT:
16895 : 24377 : case UNSIGNED_FLOAT:
16896 : 24377 : case FIX:
16897 : 24377 : case UNSIGNED_FIX:
16898 : 24377 : if (!dwarf_strict || dwarf_version >= 5)
16899 : : {
16900 : 24377 : dw_die_ref type_die;
16901 : 24377 : dw_loc_descr_ref cvt;
16902 : :
16903 : 24377 : op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
16904 : : mem_mode, VAR_INIT_STATUS_INITIALIZED);
16905 : 24377 : if (op0 == NULL)
16906 : : break;
16907 : 24201 : if (is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &int_mode)
16908 : 24201 : && (GET_CODE (rtl) == FLOAT
16909 : 1706 : || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE))
16910 : : {
16911 : 5386 : type_die = base_type_for_mode (int_mode,
16912 : : GET_CODE (rtl) == UNSIGNED_FLOAT);
16913 : 5386 : if (type_die == NULL)
16914 : : break;
16915 : 5386 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16916 : 5386 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16917 : 5386 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16918 : 5386 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16919 : 5386 : add_loc_descr (&op0, cvt);
16920 : : }
16921 : 24201 : type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
16922 : 24201 : if (type_die == NULL)
16923 : : break;
16924 : 24201 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
16925 : 24201 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
16926 : 24201 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
16927 : 24201 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
16928 : 24201 : add_loc_descr (&op0, cvt);
16929 : 24201 : if (is_a <scalar_int_mode> (mode, &int_mode)
16930 : 24201 : && (GET_CODE (rtl) == FIX
16931 : 57 : || GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE))
16932 : : {
16933 : 1462 : op0 = convert_descriptor_to_mode (int_mode, op0);
16934 : 1462 : if (op0 == NULL)
16935 : : break;
16936 : : }
16937 : 24201 : mem_loc_result = op0;
16938 : : }
16939 : : break;
16940 : :
16941 : 7233 : case CLZ:
16942 : 7233 : case CTZ:
16943 : 7233 : case FFS:
16944 : 7233 : if (is_a <scalar_int_mode> (mode, &int_mode))
16945 : 7233 : mem_loc_result = clz_loc_descriptor (rtl, int_mode, mem_mode);
16946 : : break;
16947 : :
16948 : 0 : case POPCOUNT:
16949 : 0 : case PARITY:
16950 : 0 : if (is_a <scalar_int_mode> (mode, &int_mode))
16951 : 0 : mem_loc_result = popcount_loc_descriptor (rtl, int_mode, mem_mode);
16952 : : break;
16953 : :
16954 : 90 : case BSWAP:
16955 : 90 : if (is_a <scalar_int_mode> (mode, &int_mode))
16956 : 90 : mem_loc_result = bswap_loc_descriptor (rtl, int_mode, mem_mode);
16957 : : break;
16958 : :
16959 : 2150 : case ROTATE:
16960 : 2150 : case ROTATERT:
16961 : 2150 : if (is_a <scalar_int_mode> (mode, &int_mode))
16962 : 2150 : mem_loc_result = rotate_loc_descriptor (rtl, int_mode, mem_mode);
16963 : : break;
16964 : :
16965 : : case COMPARE:
16966 : : /* In theory, we could implement the above. */
16967 : : /* DWARF cannot represent the unsigned compare operations
16968 : : natively. */
16969 : : case SS_MULT:
16970 : : case US_MULT:
16971 : : case SS_DIV:
16972 : : case US_DIV:
16973 : : case SS_PLUS:
16974 : : case US_PLUS:
16975 : : case SS_MINUS:
16976 : : case US_MINUS:
16977 : : case SS_NEG:
16978 : : case US_NEG:
16979 : : case SS_ABS:
16980 : : case SS_ASHIFT:
16981 : : case US_ASHIFT:
16982 : : case SS_TRUNCATE:
16983 : : case US_TRUNCATE:
16984 : : case UNORDERED:
16985 : : case ORDERED:
16986 : : case UNEQ:
16987 : : case UNGE:
16988 : : case UNGT:
16989 : : case UNLE:
16990 : : case UNLT:
16991 : : case LTGT:
16992 : : case FRACT_CONVERT:
16993 : : case UNSIGNED_FRACT_CONVERT:
16994 : : case SAT_FRACT:
16995 : : case UNSIGNED_SAT_FRACT:
16996 : : case SQRT:
16997 : : case ASM_OPERANDS:
16998 : : case VEC_MERGE:
16999 : : case VEC_SELECT:
17000 : : case VEC_CONCAT:
17001 : : case VEC_DUPLICATE:
17002 : : case VEC_SERIES:
17003 : : case HIGH:
17004 : : case FMA:
17005 : : case STRICT_LOW_PART:
17006 : : case CONST_VECTOR:
17007 : : case CONST_FIXED:
17008 : : case CLRSB:
17009 : : case CLOBBER:
17010 : : case SMUL_HIGHPART:
17011 : : case UMUL_HIGHPART:
17012 : : case BITREVERSE:
17013 : : case COPYSIGN:
17014 : : break;
17015 : :
17016 : 120978 : case CONST_STRING:
17017 : 120978 : resolve_one_addr (&rtl);
17018 : 120978 : goto symref;
17019 : :
17020 : : /* RTL sequences inside PARALLEL record a series of DWARF operations for
17021 : : the expression. An UNSPEC rtx represents a raw DWARF operation,
17022 : : new_loc_descr is called for it to build the operation directly.
17023 : : Otherwise mem_loc_descriptor is called recursively. */
17024 : : case PARALLEL:
17025 : : {
17026 : : int index = 0;
17027 : 0 : dw_loc_descr_ref exp_result = NULL;
17028 : :
17029 : 0 : for (; index < XVECLEN (rtl, 0); index++)
17030 : : {
17031 : 0 : rtx elem = XVECEXP (rtl, 0, index);
17032 : 0 : if (GET_CODE (elem) == UNSPEC)
17033 : : {
17034 : : /* Each DWARF operation UNSPEC contain two operands, if
17035 : : one operand is not used for the operation, const0_rtx is
17036 : : passed. */
17037 : 0 : gcc_assert (XVECLEN (elem, 0) == 2);
17038 : :
17039 : 0 : HOST_WIDE_INT dw_op = XINT (elem, 1);
17040 : 0 : HOST_WIDE_INT oprnd1 = INTVAL (XVECEXP (elem, 0, 0));
17041 : 0 : HOST_WIDE_INT oprnd2 = INTVAL (XVECEXP (elem, 0, 1));
17042 : 0 : exp_result
17043 : 0 : = new_loc_descr ((enum dwarf_location_atom) dw_op, oprnd1,
17044 : : oprnd2);
17045 : : }
17046 : : else
17047 : 0 : exp_result
17048 : 0 : = mem_loc_descriptor (elem, mode, mem_mode,
17049 : : VAR_INIT_STATUS_INITIALIZED);
17050 : :
17051 : 0 : if (!mem_loc_result)
17052 : 0 : mem_loc_result = exp_result;
17053 : : else
17054 : 0 : add_loc_descr (&mem_loc_result, exp_result);
17055 : : }
17056 : :
17057 : : break;
17058 : : }
17059 : :
17060 : 0 : default:
17061 : 0 : if (flag_checking)
17062 : : {
17063 : 0 : print_rtl (stderr, rtl);
17064 : 0 : gcc_unreachable ();
17065 : : }
17066 : : break;
17067 : : }
17068 : :
17069 : 23889539 : if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
17070 : 11252 : add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
17071 : :
17072 : 23889539 : return mem_loc_result;
17073 : : }
17074 : :
17075 : : /* Return a descriptor that describes the concatenation of two locations.
17076 : : This is typically a complex variable. */
17077 : :
17078 : : static dw_loc_descr_ref
17079 : 23533 : concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
17080 : : {
17081 : : /* At present we only track constant-sized pieces. */
17082 : 23533 : unsigned int size0, size1;
17083 : 47066 : if (!GET_MODE_SIZE (GET_MODE (x0)).is_constant (&size0)
17084 : 47066 : || !GET_MODE_SIZE (GET_MODE (x1)).is_constant (&size1))
17085 : : return 0;
17086 : :
17087 : 23533 : dw_loc_descr_ref cc_loc_result = NULL;
17088 : 23533 : dw_loc_descr_ref x0_ref
17089 : 23533 : = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
17090 : 23533 : dw_loc_descr_ref x1_ref
17091 : 23533 : = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
17092 : :
17093 : 23533 : if (x0_ref == 0 || x1_ref == 0)
17094 : : return 0;
17095 : :
17096 : 22536 : cc_loc_result = x0_ref;
17097 : 22536 : add_loc_descr_op_piece (&cc_loc_result, size0);
17098 : :
17099 : 22536 : add_loc_descr (&cc_loc_result, x1_ref);
17100 : 22536 : add_loc_descr_op_piece (&cc_loc_result, size1);
17101 : :
17102 : 22536 : if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
17103 : 0 : add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
17104 : :
17105 : 22536 : return cc_loc_result;
17106 : : }
17107 : :
17108 : : /* Return a descriptor that describes the concatenation of N
17109 : : locations. */
17110 : :
17111 : : static dw_loc_descr_ref
17112 : 40486 : concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
17113 : : {
17114 : 40486 : unsigned int i;
17115 : 40486 : dw_loc_descr_ref cc_loc_result = NULL;
17116 : 40486 : unsigned int n = XVECLEN (concatn, 0);
17117 : 40486 : unsigned int size;
17118 : :
17119 : 89642 : for (i = 0; i < n; ++i)
17120 : : {
17121 : 68643 : dw_loc_descr_ref ref;
17122 : 68643 : rtx x = XVECEXP (concatn, 0, i);
17123 : :
17124 : : /* At present we only track constant-sized pieces. */
17125 : 137286 : if (!GET_MODE_SIZE (GET_MODE (x)).is_constant (&size))
17126 : : return NULL;
17127 : :
17128 : 68643 : ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
17129 : 68643 : if (ref == NULL)
17130 : : return NULL;
17131 : :
17132 : 49156 : add_loc_descr (&cc_loc_result, ref);
17133 : 49156 : add_loc_descr_op_piece (&cc_loc_result, size);
17134 : : }
17135 : :
17136 : 20999 : if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
17137 : 0 : add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
17138 : :
17139 : 20999 : return cc_loc_result;
17140 : : }
17141 : :
17142 : : /* Helper function for loc_descriptor. Return DW_OP_implicit_pointer
17143 : : for DEBUG_IMPLICIT_PTR RTL. */
17144 : :
17145 : : static dw_loc_descr_ref
17146 : 1822430 : implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
17147 : : {
17148 : 1822430 : dw_loc_descr_ref ret;
17149 : 1822430 : dw_die_ref ref;
17150 : :
17151 : 1822430 : if (dwarf_strict && dwarf_version < 5)
17152 : : return NULL;
17153 : 1822430 : gcc_assert (VAR_P (DEBUG_IMPLICIT_PTR_DECL (rtl))
17154 : : || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
17155 : : || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
17156 : 1822430 : ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
17157 : 1822833 : ret = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
17158 : 1822430 : ret->dw_loc_oprnd2.val_class = dw_val_class_const;
17159 : 1822430 : if (ref)
17160 : : {
17161 : 1123946 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
17162 : 1123946 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
17163 : 1123946 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
17164 : : }
17165 : : else
17166 : : {
17167 : 698484 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
17168 : 698484 : ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
17169 : : }
17170 : : return ret;
17171 : : }
17172 : :
17173 : : /* Output a proper Dwarf location descriptor for a variable or parameter
17174 : : which is either allocated in a register or in a memory location. For a
17175 : : register, we just generate an OP_REG and the register number. For a
17176 : : memory location we provide a Dwarf postfix expression describing how to
17177 : : generate the (dynamic) address of the object onto the address stack.
17178 : :
17179 : : MODE is mode of the decl if this loc_descriptor is going to be used in
17180 : : .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
17181 : : allowed, VOIDmode otherwise.
17182 : :
17183 : : If we don't know how to describe it, return 0. */
17184 : :
17185 : : static dw_loc_descr_ref
17186 : 54253446 : loc_descriptor (rtx rtl, machine_mode mode,
17187 : : enum var_init_status initialized)
17188 : : {
17189 : 54253446 : dw_loc_descr_ref loc_result = NULL;
17190 : 54253446 : scalar_int_mode int_mode;
17191 : :
17192 : 54253446 : switch (GET_CODE (rtl))
17193 : : {
17194 : 161762 : case SUBREG:
17195 : : /* The case of a subreg may arise when we have a local (register)
17196 : : variable or a formal (register) parameter which doesn't quite fill
17197 : : up an entire register. For now, just assume that it is
17198 : : legitimate to make the Dwarf info refer to the whole register which
17199 : : contains the given subreg. */
17200 : 161762 : if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
17201 : 70 : loc_result = loc_descriptor (SUBREG_REG (rtl),
17202 : 35 : GET_MODE (SUBREG_REG (rtl)), initialized);
17203 : : else
17204 : 161727 : goto do_default;
17205 : 35 : break;
17206 : :
17207 : 11061922 : case REG:
17208 : 11061922 : loc_result = reg_loc_descriptor (rtl, initialized);
17209 : 11061922 : break;
17210 : :
17211 : 3825429 : case MEM:
17212 : 3825429 : loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
17213 : 3825429 : GET_MODE (rtl), initialized);
17214 : 3825429 : if (loc_result == NULL)
17215 : 13169 : loc_result = tls_mem_loc_descriptor (rtl);
17216 : 3825429 : if (loc_result == NULL)
17217 : : {
17218 : 13169 : rtx new_rtl = avoid_constant_pool_reference (rtl);
17219 : 13169 : if (new_rtl != rtl)
17220 : 0 : loc_result = loc_descriptor (new_rtl, mode, initialized);
17221 : : }
17222 : : break;
17223 : :
17224 : 23533 : case CONCAT:
17225 : 23533 : loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
17226 : : initialized);
17227 : 23533 : break;
17228 : :
17229 : 40486 : case CONCATN:
17230 : 40486 : loc_result = concatn_loc_descriptor (rtl, initialized);
17231 : 40486 : break;
17232 : :
17233 : 26638478 : case VAR_LOCATION:
17234 : : /* Single part. */
17235 : 26638478 : if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
17236 : : {
17237 : 26480532 : rtx loc = PAT_VAR_LOCATION_LOC (rtl);
17238 : 26480532 : if (GET_CODE (loc) == EXPR_LIST)
17239 : 0 : loc = XEXP (loc, 0);
17240 : 26480532 : loc_result = loc_descriptor (loc, mode, initialized);
17241 : 26480532 : break;
17242 : : }
17243 : :
17244 : 157946 : rtl = XEXP (rtl, 1);
17245 : : /* FALLTHRU */
17246 : :
17247 : 158260 : case PARALLEL:
17248 : 158260 : {
17249 : 158260 : rtvec par_elems = XVEC (rtl, 0);
17250 : 158260 : int num_elem = GET_NUM_ELEM (par_elems);
17251 : 158260 : machine_mode mode;
17252 : 158260 : int i, size;
17253 : :
17254 : : /* Create the first one, so we have something to add to. */
17255 : 158260 : loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
17256 : : VOIDmode, initialized);
17257 : 158260 : if (loc_result == NULL)
17258 : 54253446 : return NULL;
17259 : 158260 : mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
17260 : : /* At present we only track constant-sized pieces. */
17261 : 316520 : if (!GET_MODE_SIZE (mode).is_constant (&size))
17262 : : return NULL;
17263 : 158260 : add_loc_descr_op_piece (&loc_result, size);
17264 : 316518 : for (i = 1; i < num_elem; i++)
17265 : : {
17266 : 158258 : dw_loc_descr_ref temp;
17267 : :
17268 : 158258 : temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
17269 : : VOIDmode, initialized);
17270 : 158258 : if (temp == NULL)
17271 : : return NULL;
17272 : 158258 : add_loc_descr (&loc_result, temp);
17273 : 158258 : mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
17274 : : /* At present we only track constant-sized pieces. */
17275 : 316516 : if (!GET_MODE_SIZE (mode).is_constant (&size))
17276 : : return NULL;
17277 : 158258 : add_loc_descr_op_piece (&loc_result, size);
17278 : : }
17279 : : }
17280 : : break;
17281 : :
17282 : 2892723 : case CONST_INT:
17283 : 2892723 : if (mode != VOIDmode && mode != BLKmode)
17284 : : {
17285 : 2885607 : int_mode = as_a <scalar_int_mode> (mode);
17286 : 5771214 : loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode),
17287 : : INTVAL (rtl));
17288 : : }
17289 : : break;
17290 : :
17291 : 58354 : case CONST_DOUBLE:
17292 : 58354 : if (mode == VOIDmode)
17293 : 16416 : mode = GET_MODE (rtl);
17294 : :
17295 : 58354 : if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
17296 : : {
17297 : 58354 : gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
17298 : :
17299 : : /* Note that a CONST_DOUBLE rtx could represent either an integer
17300 : : or a floating-point constant. A CONST_DOUBLE is used whenever
17301 : : the constant requires more than one word in order to be
17302 : : adequately represented. We output CONST_DOUBLEs as blocks. */
17303 : 58354 : scalar_mode smode = as_a <scalar_mode> (mode);
17304 : 58354 : loc_result = new_loc_descr (DW_OP_implicit_value,
17305 : 58354 : GET_MODE_SIZE (smode), 0);
17306 : : #if TARGET_SUPPORTS_WIDE_INT == 0
17307 : : if (!SCALAR_FLOAT_MODE_P (smode))
17308 : : {
17309 : : loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
17310 : : loc_result->dw_loc_oprnd2.v.val_double
17311 : : = rtx_to_double_int (rtl);
17312 : : }
17313 : : else
17314 : : #endif
17315 : 58354 : {
17316 : 58354 : unsigned int length = GET_MODE_SIZE (smode);
17317 : 58354 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
17318 : 58354 : unsigned int elt_size = insert_float (rtl, array);
17319 : :
17320 : 58354 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17321 : 58354 : loc_result->dw_loc_oprnd2.v.val_vec.length = length / elt_size;
17322 : 58354 : loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17323 : 58354 : loc_result->dw_loc_oprnd2.v.val_vec.array = array;
17324 : : }
17325 : : }
17326 : : break;
17327 : :
17328 : 645 : case CONST_WIDE_INT:
17329 : 645 : if (mode == VOIDmode)
17330 : 4 : mode = GET_MODE (rtl);
17331 : :
17332 : 645 : if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
17333 : : {
17334 : 641 : int_mode = as_a <scalar_int_mode> (mode);
17335 : 641 : loc_result = new_loc_descr (DW_OP_implicit_value,
17336 : 641 : GET_MODE_SIZE (int_mode), 0);
17337 : 641 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
17338 : 641 : loc_result->dw_loc_oprnd2.v.val_wide
17339 : 641 : = alloc_dw_wide_int (rtx_mode_t (rtl, int_mode));
17340 : : }
17341 : : break;
17342 : :
17343 : 4 : case CONST_VECTOR:
17344 : 4 : if (mode == VOIDmode)
17345 : 0 : mode = GET_MODE (rtl);
17346 : :
17347 : 0 : if (mode != VOIDmode
17348 : : /* The combination of a length and byte elt_size doesn't extend
17349 : : naturally to boolean vectors, where several elements are packed
17350 : : into the same byte. */
17351 : 4 : && GET_MODE_CLASS (mode) != MODE_VECTOR_BOOL
17352 : 4 : && (dwarf_version >= 4 || !dwarf_strict))
17353 : : {
17354 : 4 : unsigned int length;
17355 : 8 : if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
17356 : : return NULL;
17357 : :
17358 : 4 : unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
17359 : 4 : unsigned char *array
17360 : 4 : = ggc_vec_alloc<unsigned char> (length * elt_size);
17361 : 4 : unsigned int i;
17362 : 4 : unsigned char *p;
17363 : 4 : machine_mode imode = GET_MODE_INNER (mode);
17364 : :
17365 : 4 : gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
17366 : 4 : switch (GET_MODE_CLASS (mode))
17367 : : {
17368 : : case MODE_VECTOR_INT:
17369 : 10 : for (i = 0, p = array; i < length; i++, p += elt_size)
17370 : : {
17371 : 8 : rtx elt = CONST_VECTOR_ELT (rtl, i);
17372 : 8 : insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
17373 : : }
17374 : : break;
17375 : :
17376 : : case MODE_VECTOR_FLOAT:
17377 : 10 : for (i = 0, p = array; i < length; i++, p += elt_size)
17378 : : {
17379 : 8 : rtx elt = CONST_VECTOR_ELT (rtl, i);
17380 : 8 : insert_float (elt, p);
17381 : : }
17382 : : break;
17383 : :
17384 : 0 : default:
17385 : 0 : gcc_unreachable ();
17386 : : }
17387 : :
17388 : 4 : loc_result = new_loc_descr (DW_OP_implicit_value,
17389 : : length * elt_size, 0);
17390 : 4 : loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
17391 : 4 : loc_result->dw_loc_oprnd2.v.val_vec.length = length;
17392 : 4 : loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
17393 : 4 : loc_result->dw_loc_oprnd2.v.val_vec.array = array;
17394 : : }
17395 : : break;
17396 : :
17397 : 102574 : case CONST:
17398 : 102574 : if (mode == VOIDmode
17399 : 102574 : || CONST_SCALAR_INT_P (XEXP (rtl, 0))
17400 : 102574 : || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
17401 : 102574 : || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
17402 : : {
17403 : 0 : loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
17404 : 0 : break;
17405 : : }
17406 : : /* FALLTHROUGH */
17407 : 458425 : case SYMBOL_REF:
17408 : 458425 : if (!const_ok_for_output (rtl))
17409 : : break;
17410 : : /* FALLTHROUGH */
17411 : 422007 : case LABEL_REF:
17412 : 422007 : if (is_a <scalar_int_mode> (mode, &int_mode)
17413 : 455284 : && GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE
17414 : 422005 : && (dwarf_version >= 4 || !dwarf_strict))
17415 : : {
17416 : 422005 : loc_result = new_addr_loc_descr (rtl, dtprel_false);
17417 : 422005 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
17418 : 422005 : vec_safe_push (used_rtx_array, rtl);
17419 : : }
17420 : : break;
17421 : :
17422 : 1709629 : case DEBUG_IMPLICIT_PTR:
17423 : 1709629 : loc_result = implicit_ptr_descriptor (rtl, 0);
17424 : 1709629 : break;
17425 : :
17426 : 5474131 : case PLUS:
17427 : 5474131 : if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
17428 : 112801 : && CONST_INT_P (XEXP (rtl, 1)))
17429 : : {
17430 : 112801 : loc_result
17431 : 112801 : = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
17432 : 112801 : break;
17433 : : }
17434 : : /* FALLTHRU */
17435 : 5361330 : do_default:
17436 : 7430660 : default:
17437 : 7430660 : if ((is_a <scalar_int_mode> (mode, &int_mode)
17438 : 7380865 : && GET_MODE (rtl) == int_mode
17439 : 7731545 : && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
17440 : 7333072 : && dwarf_version >= 4)
17441 : 100081 : || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
17442 : : {
17443 : : /* Value expression. */
17444 : 7427543 : loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
17445 : 7427543 : if (loc_result)
17446 : 14712542 : add_loc_descr (&loc_result,
17447 : : new_loc_descr (DW_OP_stack_value, 0, 0));
17448 : : }
17449 : : break;
17450 : : }
17451 : :
17452 : 54253446 : return loc_result;
17453 : : }
17454 : :
17455 : : /* We need to figure out what section we should use as the base for the
17456 : : address ranges where a given location is valid.
17457 : : 1. If this particular DECL has a section associated with it, use that.
17458 : : 2. If this function has a section associated with it, use that.
17459 : : 3. Otherwise, use the text section.
17460 : : XXX: If you split a variable across multiple sections, we won't notice. */
17461 : :
17462 : : static const char *
17463 : 15867476 : secname_for_decl (const_tree decl)
17464 : : {
17465 : 15867476 : const char *secname;
17466 : :
17467 : 952655 : if (VAR_OR_FUNCTION_DECL_P (decl)
17468 : 14918388 : && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
17469 : 15871043 : && DECL_SECTION_NAME (decl))
17470 : 496 : secname = DECL_SECTION_NAME (decl);
17471 : 15866980 : else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
17472 : : {
17473 : 13752013 : if (in_cold_section_p)
17474 : : {
17475 : 3096183 : section *sec = current_function_section ();
17476 : 3096183 : if (sec->common.flags & SECTION_NAMED)
17477 : 3096183 : return sec->named.name;
17478 : : }
17479 : 10655830 : secname = DECL_SECTION_NAME (current_function_decl);
17480 : : }
17481 : 2114967 : else if (cfun && in_cold_section_p)
17482 : 61044 : secname = crtl->subsections.cold_section_label;
17483 : : else
17484 : : secname = text_section_label;
17485 : :
17486 : : return secname;
17487 : : }
17488 : :
17489 : : /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
17490 : :
17491 : : static bool
17492 : 81802527 : decl_by_reference_p (tree decl)
17493 : : {
17494 : 81802527 : return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
17495 : : || VAR_P (decl))
17496 : 81802527 : && DECL_BY_REFERENCE (decl));
17497 : : }
17498 : :
17499 : : /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17500 : : for VARLOC. */
17501 : :
17502 : : static dw_loc_descr_ref
17503 : 26986665 : dw_loc_list_1 (tree loc, rtx varloc, int want_address,
17504 : : enum var_init_status initialized)
17505 : : {
17506 : 26986665 : int have_address = 0;
17507 : 26986665 : dw_loc_descr_ref descr;
17508 : 26986665 : machine_mode mode;
17509 : :
17510 : 26986665 : if (want_address != 2)
17511 : : {
17512 : 348187 : gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
17513 : : /* Single part. */
17514 : 348187 : if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
17515 : : {
17516 : 348187 : varloc = PAT_VAR_LOCATION_LOC (varloc);
17517 : 348187 : if (GET_CODE (varloc) == EXPR_LIST)
17518 : 0 : varloc = XEXP (varloc, 0);
17519 : 348187 : mode = GET_MODE (varloc);
17520 : 348187 : if (MEM_P (varloc))
17521 : : {
17522 : 9696 : rtx addr = XEXP (varloc, 0);
17523 : 9696 : descr = mem_loc_descriptor (addr, get_address_mode (varloc),
17524 : : mode, initialized);
17525 : 9696 : if (descr)
17526 : : have_address = 1;
17527 : : else
17528 : : {
17529 : 0 : rtx x = avoid_constant_pool_reference (varloc);
17530 : 0 : if (x != varloc)
17531 : 0 : descr = mem_loc_descriptor (x, mode, VOIDmode,
17532 : : initialized);
17533 : : }
17534 : : }
17535 : : else
17536 : 338491 : descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
17537 : : }
17538 : : else
17539 : : return 0;
17540 : : }
17541 : : else
17542 : : {
17543 : 26638478 : if (GET_CODE (varloc) == VAR_LOCATION)
17544 : 26638478 : mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
17545 : : else
17546 : 0 : mode = DECL_MODE (loc);
17547 : 26638478 : descr = loc_descriptor (varloc, mode, initialized);
17548 : 26638478 : have_address = 1;
17549 : : }
17550 : :
17551 : 26986665 : if (!descr)
17552 : : return 0;
17553 : :
17554 : 26694278 : if (want_address == 2 && !have_address
17555 : 0 : && (dwarf_version >= 4 || !dwarf_strict))
17556 : : {
17557 : 0 : if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
17558 : : {
17559 : 0 : expansion_failed (loc, NULL_RTX,
17560 : : "DWARF address size mismatch");
17561 : 0 : return 0;
17562 : : }
17563 : 0 : add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
17564 : 0 : have_address = 1;
17565 : : }
17566 : : /* Show if we can't fill the request for an address. */
17567 : 26694278 : if (want_address && !have_address)
17568 : : {
17569 : 0 : expansion_failed (loc, NULL_RTX,
17570 : : "Want address and only have value");
17571 : 0 : return 0;
17572 : : }
17573 : :
17574 : : /* If we've got an address and don't want one, dereference. */
17575 : 26694278 : if (!want_address && have_address)
17576 : : {
17577 : 9696 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
17578 : 9696 : enum dwarf_location_atom op;
17579 : :
17580 : 11642 : if (size > DWARF2_ADDR_SIZE || size == -1)
17581 : : {
17582 : 0 : expansion_failed (loc, NULL_RTX,
17583 : : "DWARF address size mismatch");
17584 : 0 : return 0;
17585 : : }
17586 : 11642 : else if (size == DWARF2_ADDR_SIZE)
17587 : : op = DW_OP_deref;
17588 : : else
17589 : 0 : op = DW_OP_deref_size;
17590 : :
17591 : 19392 : add_loc_descr (&descr, new_loc_descr (op, size, 0));
17592 : : }
17593 : :
17594 : 26694278 : return descr;
17595 : : }
17596 : :
17597 : : /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
17598 : : if it is not possible. */
17599 : :
17600 : : static dw_loc_descr_ref
17601 : 4871826 : new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
17602 : : {
17603 : 4871826 : if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
17604 : 4598342 : return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
17605 : 273484 : else if (dwarf_version >= 3 || !dwarf_strict)
17606 : 273484 : return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
17607 : : else
17608 : : return NULL;
17609 : : }
17610 : :
17611 : : /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
17612 : : for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
17613 : :
17614 : : static dw_loc_descr_ref
17615 : 3048919 : dw_sra_loc_expr (tree decl, rtx loc)
17616 : : {
17617 : 3048919 : rtx p;
17618 : 3048919 : unsigned HOST_WIDE_INT padsize = 0;
17619 : 3048919 : dw_loc_descr_ref descr, *descr_tail;
17620 : 3048919 : unsigned HOST_WIDE_INT decl_size;
17621 : 3048919 : rtx varloc;
17622 : 3048919 : enum var_init_status initialized;
17623 : :
17624 : 3048919 : if (DECL_SIZE (decl) == NULL
17625 : 3048919 : || !tree_fits_uhwi_p (DECL_SIZE (decl)))
17626 : : return NULL;
17627 : :
17628 : 3048919 : decl_size = tree_to_uhwi (DECL_SIZE (decl));
17629 : 3048919 : descr = NULL;
17630 : 3048919 : descr_tail = &descr;
17631 : :
17632 : 9964228 : for (p = loc; p; p = XEXP (p, 1))
17633 : : {
17634 : 6915733 : unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
17635 : 6915733 : rtx loc_note = *decl_piece_varloc_ptr (p);
17636 : 6915733 : dw_loc_descr_ref cur_descr;
17637 : 6915733 : dw_loc_descr_ref *tail, last = NULL;
17638 : 6915733 : unsigned HOST_WIDE_INT opsize = 0;
17639 : :
17640 : 6915733 : if (loc_note == NULL_RTX
17641 : 6443199 : || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
17642 : : {
17643 : 3137884 : padsize += bitsize;
17644 : 3152406 : continue;
17645 : : }
17646 : 3777849 : initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
17647 : 3777849 : varloc = NOTE_VAR_LOCATION (loc_note);
17648 : 3777849 : cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
17649 : 3777849 : if (cur_descr == NULL)
17650 : : {
17651 : 14522 : padsize += bitsize;
17652 : 14522 : continue;
17653 : : }
17654 : :
17655 : : /* Check that cur_descr either doesn't use
17656 : : DW_OP_*piece operations, or their sum is equal
17657 : : to bitsize. Otherwise we can't embed it. */
17658 : 9074826 : for (tail = &cur_descr; *tail != NULL;
17659 : 5311499 : tail = &(*tail)->dw_loc_next)
17660 : 5311499 : if ((*tail)->dw_loc_opc == DW_OP_piece)
17661 : : {
17662 : 12738 : opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
17663 : 12738 : * BITS_PER_UNIT;
17664 : 12738 : last = *tail;
17665 : : }
17666 : 5298761 : else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
17667 : : {
17668 : 0 : opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
17669 : 0 : last = *tail;
17670 : : }
17671 : :
17672 : 3763327 : if (last != NULL && opsize != bitsize)
17673 : : {
17674 : 0 : padsize += bitsize;
17675 : : /* Discard the current piece of the descriptor and release any
17676 : : addr_table entries it uses. */
17677 : 0 : remove_loc_list_addr_table_entries (cur_descr);
17678 : 0 : continue;
17679 : : }
17680 : :
17681 : : /* If there is a hole, add DW_OP_*piece after empty DWARF
17682 : : expression, which means that those bits are optimized out. */
17683 : 3763327 : if (padsize)
17684 : : {
17685 : 523626 : if (padsize > decl_size)
17686 : : {
17687 : 0 : remove_loc_list_addr_table_entries (cur_descr);
17688 : 424 : goto discard_descr;
17689 : : }
17690 : 523626 : decl_size -= padsize;
17691 : 523626 : *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
17692 : 523626 : if (*descr_tail == NULL)
17693 : : {
17694 : 0 : remove_loc_list_addr_table_entries (cur_descr);
17695 : 0 : goto discard_descr;
17696 : : }
17697 : 523626 : descr_tail = &(*descr_tail)->dw_loc_next;
17698 : 523626 : padsize = 0;
17699 : : }
17700 : 3763327 : *descr_tail = cur_descr;
17701 : 3763327 : descr_tail = tail;
17702 : 3763327 : if (bitsize > decl_size)
17703 : 0 : goto discard_descr;
17704 : 3763327 : decl_size -= bitsize;
17705 : 3763327 : if (last == NULL)
17706 : : {
17707 : 3756958 : HOST_WIDE_INT offset = 0;
17708 : 3756958 : if (GET_CODE (varloc) == VAR_LOCATION
17709 : 3756958 : && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
17710 : : {
17711 : 3756958 : varloc = PAT_VAR_LOCATION_LOC (varloc);
17712 : 3756958 : if (GET_CODE (varloc) == EXPR_LIST)
17713 : 0 : varloc = XEXP (varloc, 0);
17714 : : }
17715 : 3762044 : do
17716 : : {
17717 : 3762044 : if (GET_CODE (varloc) == CONST
17718 : 3760263 : || GET_CODE (varloc) == SIGN_EXTEND
17719 : 3759920 : || GET_CODE (varloc) == ZERO_EXTEND)
17720 : 3364 : varloc = XEXP (varloc, 0);
17721 : 3758680 : else if (GET_CODE (varloc) == SUBREG)
17722 : 1722 : varloc = SUBREG_REG (varloc);
17723 : : else
17724 : : break;
17725 : : }
17726 : : while (1);
17727 : : /* DW_OP_bit_size offset should be zero for register
17728 : : or implicit location descriptions and empty location
17729 : : descriptions, but for memory addresses needs big endian
17730 : : adjustment. */
17731 : 3756958 : if (MEM_P (varloc))
17732 : : {
17733 : 1008637 : unsigned HOST_WIDE_INT memsize;
17734 : 1008640 : if (!poly_uint64 (MEM_SIZE (varloc)).is_constant (&memsize))
17735 : 424 : goto discard_descr;
17736 : 1008637 : memsize *= BITS_PER_UNIT;
17737 : 1008637 : if (memsize != bitsize)
17738 : : {
17739 : 6392 : if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
17740 : : && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
17741 : : goto discard_descr;
17742 : 6392 : if (memsize < bitsize)
17743 : 424 : goto discard_descr;
17744 : : if (BITS_BIG_ENDIAN)
17745 : : offset = memsize - bitsize;
17746 : : }
17747 : : }
17748 : :
17749 : 3756534 : *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
17750 : 3756534 : if (*descr_tail == NULL)
17751 : 0 : goto discard_descr;
17752 : 3756534 : descr_tail = &(*descr_tail)->dw_loc_next;
17753 : : }
17754 : : }
17755 : :
17756 : : /* If there were any non-empty expressions, add padding till the end of
17757 : : the decl. */
17758 : 3048495 : if (descr != NULL && decl_size != 0)
17759 : : {
17760 : 591666 : *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
17761 : 591666 : if (*descr_tail == NULL)
17762 : 0 : goto discard_descr;
17763 : : }
17764 : 3048495 : return descr;
17765 : :
17766 : 424 : discard_descr:
17767 : : /* Discard the descriptor and release any addr_table entries it uses. */
17768 : 424 : remove_loc_list_addr_table_entries (descr);
17769 : 424 : return NULL;
17770 : : }
17771 : :
17772 : : /* Return the dwarf representation of the location list LOC_LIST of
17773 : : DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
17774 : : function. */
17775 : :
17776 : : static dw_loc_list_ref
17777 : 12982508 : dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
17778 : : {
17779 : 12982508 : const char *endname, *secname;
17780 : 12982508 : var_loc_view endview;
17781 : 12982508 : rtx varloc;
17782 : 12982508 : enum var_init_status initialized;
17783 : 12982508 : struct var_loc_node *node;
17784 : 12982508 : dw_loc_descr_ref descr;
17785 : 12982508 : char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
17786 : 12982508 : dw_loc_list_ref list = NULL;
17787 : 12982508 : dw_loc_list_ref *listp = &list;
17788 : :
17789 : : /* Now that we know what section we are using for a base,
17790 : : actually construct the list of locations.
17791 : : The first location information is what is passed to the
17792 : : function that creates the location list, and the remaining
17793 : : locations just get added on to that list.
17794 : : Note that we only know the start address for a location
17795 : : (IE location changes), so to build the range, we use
17796 : : the range [current location start, next location start].
17797 : : This means we have to special case the last node, and generate
17798 : : a range of [last location start, end of function label]. */
17799 : :
17800 : 12982508 : if (cfun && crtl->has_bb_partition)
17801 : : {
17802 : 3157170 : bool save_in_cold_section_p = in_cold_section_p;
17803 : 3157170 : in_cold_section_p = first_function_block_is_cold;
17804 : 3157170 : if (loc_list->last_before_switch == NULL)
17805 : 275769 : in_cold_section_p = !in_cold_section_p;
17806 : 3157170 : secname = secname_for_decl (decl);
17807 : 3157170 : in_cold_section_p = save_in_cold_section_p;
17808 : 3157170 : }
17809 : : else
17810 : 9825338 : secname = secname_for_decl (decl);
17811 : :
17812 : 59217866 : for (node = loc_list->first; node; node = node->next)
17813 : : {
17814 : 46235358 : bool range_across_switch = false;
17815 : 46235358 : if (GET_CODE (node->loc) == EXPR_LIST
17816 : 43191182 : || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
17817 : : {
17818 : 26156999 : if (GET_CODE (node->loc) == EXPR_LIST)
17819 : : {
17820 : 3044176 : descr = NULL;
17821 : : /* This requires DW_OP_{,bit_}piece, which is not usable
17822 : : inside DWARF expressions. */
17823 : 3044176 : if (want_address == 2)
17824 : 3044176 : descr = dw_sra_loc_expr (decl, node->loc);
17825 : : }
17826 : : else
17827 : : {
17828 : 23112823 : initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
17829 : 23112823 : varloc = NOTE_VAR_LOCATION (node->loc);
17830 : 23112823 : descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
17831 : : }
17832 : 26156999 : if (descr)
17833 : : {
17834 : : /* If section switch happens in between node->label
17835 : : and node->next->label (or end of function) and
17836 : : we can't emit it as a single entry list,
17837 : : emit two ranges, first one ending at the end
17838 : : of first partition and second one starting at the
17839 : : beginning of second partition. */
17840 : 24782497 : if (node == loc_list->last_before_switch
17841 : 103289 : && (node != loc_list->first || loc_list->first->next
17842 : : /* If we are to emit a view number, we will emit
17843 : : a loclist rather than a single location
17844 : : expression for the entire function (see
17845 : : loc_list_has_views), so we have to split the
17846 : : range that straddles across partitions. */
17847 : 6422 : || !ZERO_VIEW_P (node->view))
17848 : 24883233 : && current_function_decl)
17849 : : {
17850 : 100736 : endname = cfun->fde->dw_fde_end;
17851 : 100736 : endview = 0;
17852 : 100736 : range_across_switch = true;
17853 : : }
17854 : : /* The variable has a location between NODE->LABEL and
17855 : : NODE->NEXT->LABEL. */
17856 : 24681761 : else if (node->next)
17857 : 23354810 : endname = node->next->label, endview = node->next->view;
17858 : : /* If the variable has a location at the last label
17859 : : it keeps its location until the end of function. */
17860 : 1326951 : else if (!current_function_decl)
17861 : : endname = text_end_label, endview = 0;
17862 : : else
17863 : : {
17864 : 1326951 : ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
17865 : : current_function_funcdef_no);
17866 : 1326951 : endname = ggc_strdup (label_id);
17867 : 1326951 : endview = 0;
17868 : : }
17869 : :
17870 : 24782497 : *listp = new_loc_list (descr, node->label, node->view,
17871 : : endname, endview, secname);
17872 : 24782497 : if (TREE_CODE (decl) == PARM_DECL
17873 : 3247539 : && node == loc_list->first
17874 : 918358 : && NOTE_P (node->loc)
17875 : 909808 : && strcmp (node->label, endname) == 0)
17876 : 396 : (*listp)->force = true;
17877 : 24782497 : listp = &(*listp)->dw_loc_next;
17878 : : }
17879 : : }
17880 : :
17881 : 46235358 : if (cfun
17882 : 46235358 : && crtl->has_bb_partition
17883 : 10660358 : && node == loc_list->last_before_switch)
17884 : : {
17885 : 2881401 : bool save_in_cold_section_p = in_cold_section_p;
17886 : 2881401 : in_cold_section_p = !first_function_block_is_cold;
17887 : 2881401 : secname = secname_for_decl (decl);
17888 : 2881401 : in_cold_section_p = save_in_cold_section_p;
17889 : : }
17890 : :
17891 : 46235358 : if (range_across_switch)
17892 : : {
17893 : 100736 : if (GET_CODE (node->loc) == EXPR_LIST)
17894 : 4743 : descr = dw_sra_loc_expr (decl, node->loc);
17895 : : else
17896 : : {
17897 : 95993 : initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
17898 : 95993 : varloc = NOTE_VAR_LOCATION (node->loc);
17899 : 95993 : descr = dw_loc_list_1 (decl, varloc, want_address,
17900 : : initialized);
17901 : : }
17902 : 100736 : gcc_assert (descr);
17903 : : /* The variable has a location between NODE->LABEL and
17904 : : NODE->NEXT->LABEL. */
17905 : 100736 : if (node->next)
17906 : 68125 : endname = node->next->label, endview = node->next->view;
17907 : : else
17908 : 32611 : endname = cfun->fde->dw_fde_second_end, endview = 0;
17909 : 100736 : *listp = new_loc_list (descr, cfun->fde->dw_fde_second_begin, 0,
17910 : : endname, endview, secname);
17911 : 100736 : listp = &(*listp)->dw_loc_next;
17912 : : }
17913 : : }
17914 : :
17915 : : /* Try to avoid the overhead of a location list emitting a location
17916 : : expression instead, but only if we didn't have more than one
17917 : : location entry in the first place. If some entries were not
17918 : : representable, we don't want to pretend a single entry that was
17919 : : applies to the entire scope in which the variable is
17920 : : available. */
17921 : 12982508 : if (list && loc_list->first->next)
17922 : 11743808 : gen_llsym (list);
17923 : : else
17924 : 1238700 : maybe_gen_llsym (list);
17925 : :
17926 : 12982508 : return list;
17927 : : }
17928 : :
17929 : : /* Return true if the loc_list has only single element and thus
17930 : : can be represented as location description. */
17931 : :
17932 : : static bool
17933 : 12880300 : single_element_loc_list_p (dw_loc_list_ref list)
17934 : : {
17935 : 12880300 : gcc_assert (!list->dw_loc_next || list->ll_symbol);
17936 : 12880300 : return !list->ll_symbol;
17937 : : }
17938 : :
17939 : : /* Duplicate a single element of location list. */
17940 : :
17941 : : static inline dw_loc_descr_ref
17942 : 35167 : copy_loc_descr (dw_loc_descr_ref ref)
17943 : : {
17944 : 35167 : dw_loc_descr_ref copy = ggc_alloc<dw_loc_descr_node> ();
17945 : 35167 : memcpy (copy, ref, sizeof (dw_loc_descr_node));
17946 : 35167 : return copy;
17947 : : }
17948 : :
17949 : : /* To each location in list LIST append loc descr REF. */
17950 : :
17951 : : static void
17952 : 243912 : add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
17953 : : {
17954 : 243912 : dw_loc_descr_ref copy;
17955 : 243912 : add_loc_descr (&list->expr, ref);
17956 : 243912 : list = list->dw_loc_next;
17957 : 279079 : while (list)
17958 : : {
17959 : 35167 : copy = copy_loc_descr (ref);
17960 : 35167 : add_loc_descr (&list->expr, copy);
17961 : 35167 : while (copy->dw_loc_next)
17962 : 0 : copy = copy->dw_loc_next = copy_loc_descr (copy->dw_loc_next);
17963 : 35167 : list = list->dw_loc_next;
17964 : : }
17965 : 243912 : }
17966 : :
17967 : : /* To each location in list LIST prepend loc descr REF. */
17968 : :
17969 : : static void
17970 : 0 : prepend_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
17971 : : {
17972 : 0 : dw_loc_descr_ref copy;
17973 : 0 : dw_loc_descr_ref ref_end = list->expr;
17974 : 0 : add_loc_descr (&ref, list->expr);
17975 : 0 : list->expr = ref;
17976 : 0 : list = list->dw_loc_next;
17977 : 0 : while (list)
17978 : : {
17979 : 0 : dw_loc_descr_ref end = list->expr;
17980 : 0 : list->expr = copy = copy_loc_descr (ref);
17981 : 0 : while (copy->dw_loc_next != ref_end)
17982 : 0 : copy = copy->dw_loc_next = copy_loc_descr (copy->dw_loc_next);
17983 : 0 : copy->dw_loc_next = end;
17984 : 0 : list = list->dw_loc_next;
17985 : : }
17986 : 0 : }
17987 : :
17988 : : /* Given two lists RET and LIST
17989 : : produce location list that is result of adding expression in LIST
17990 : : to expression in RET on each position in program.
17991 : : Might be destructive on both RET and LIST.
17992 : :
17993 : : TODO: We handle only simple cases of RET or LIST having at most one
17994 : : element. General case would involve sorting the lists in program order
17995 : : and merging them that will need some additional work.
17996 : : Adding that will improve quality of debug info especially for SRA-ed
17997 : : structures. */
17998 : :
17999 : : static void
18000 : 46714 : add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
18001 : : {
18002 : 46714 : if (!list)
18003 : : return;
18004 : 46714 : if (!*ret)
18005 : : {
18006 : 0 : *ret = list;
18007 : 0 : return;
18008 : : }
18009 : 46714 : if (!list->dw_loc_next)
18010 : : {
18011 : 46714 : add_loc_descr_to_each (*ret, list->expr);
18012 : 46714 : return;
18013 : : }
18014 : 0 : if (!(*ret)->dw_loc_next)
18015 : : {
18016 : 0 : prepend_loc_descr_to_each (list, (*ret)->expr);
18017 : 0 : *ret = list;
18018 : 0 : return;
18019 : : }
18020 : 0 : expansion_failed (NULL_TREE, NULL_RTX,
18021 : : "Don't know how to merge two non-trivial"
18022 : : " location lists.\n");
18023 : 0 : *ret = NULL;
18024 : 0 : return;
18025 : : }
18026 : :
18027 : : /* LOC is constant expression. Try a luck, look it up in constant
18028 : : pool and return its loc_descr of its address. */
18029 : :
18030 : : static dw_loc_descr_ref
18031 : 11815 : cst_pool_loc_descr (tree loc)
18032 : : {
18033 : : /* Get an RTL for this, if something has been emitted. */
18034 : 11815 : rtx rtl = lookup_constant_def (loc);
18035 : :
18036 : 11815 : if (!rtl || !MEM_P (rtl))
18037 : : {
18038 : 0 : gcc_assert (!rtl);
18039 : : return 0;
18040 : : }
18041 : 10839 : gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
18042 : :
18043 : : /* TODO: We might get more coverage if we was actually delaying expansion
18044 : : of all expressions till end of compilation when constant pools are fully
18045 : : populated. */
18046 : 10839 : if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
18047 : : {
18048 : 0 : expansion_failed (loc, NULL_RTX,
18049 : : "CST value in contant pool but not marked.");
18050 : 0 : return 0;
18051 : : }
18052 : 10839 : return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
18053 : 10839 : GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
18054 : : }
18055 : :
18056 : : /* Return dw_loc_list representing address of addr_expr LOC
18057 : : by looking for inner INDIRECT_REF expression and turning
18058 : : it into simple arithmetics.
18059 : :
18060 : : See loc_list_from_tree for the meaning of CONTEXT. */
18061 : :
18062 : : static dw_loc_list_ref
18063 : 84 : loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
18064 : : loc_descr_context *context)
18065 : : {
18066 : 84 : tree obj, offset;
18067 : 84 : poly_int64 bitsize, bitpos, bytepos;
18068 : 84 : machine_mode mode;
18069 : 84 : int unsignedp, reversep, volatilep = 0;
18070 : 84 : dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
18071 : :
18072 : 84 : obj = get_inner_reference (TREE_OPERAND (loc, 0),
18073 : : &bitsize, &bitpos, &offset, &mode,
18074 : : &unsignedp, &reversep, &volatilep);
18075 : 84 : STRIP_NOPS (obj);
18076 : 168 : if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
18077 : : {
18078 : 0 : expansion_failed (loc, NULL_RTX, "bitfield access");
18079 : 0 : return 0;
18080 : : }
18081 : 84 : if (!INDIRECT_REF_P (obj))
18082 : : {
18083 : 84 : expansion_failed (obj,
18084 : : NULL_RTX, "no indirect ref in inner refrence");
18085 : 84 : return 0;
18086 : : }
18087 : 0 : if (!offset && known_eq (bitpos, 0))
18088 : 0 : list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1,
18089 : : context);
18090 : 0 : else if (toplev
18091 : 0 : && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
18092 : 0 : && (dwarf_version >= 4 || !dwarf_strict))
18093 : : {
18094 : 0 : list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0, context);
18095 : 0 : if (!list_ret)
18096 : 84 : return 0;
18097 : 0 : if (offset)
18098 : : {
18099 : : /* Variable offset. */
18100 : 0 : list_ret1 = loc_list_from_tree (offset, 0, context);
18101 : 0 : if (list_ret1 == 0)
18102 : : return 0;
18103 : 0 : add_loc_list (&list_ret, list_ret1);
18104 : 0 : if (!list_ret)
18105 : : return 0;
18106 : 0 : add_loc_descr_to_each (list_ret,
18107 : : new_loc_descr (DW_OP_plus, 0, 0));
18108 : : }
18109 : 0 : HOST_WIDE_INT value;
18110 : 0 : if (bytepos.is_constant (&value) && value > 0)
18111 : 0 : add_loc_descr_to_each (list_ret,
18112 : : new_loc_descr (DW_OP_plus_uconst, value, 0));
18113 : 0 : else if (maybe_ne (bytepos, 0))
18114 : 0 : loc_list_plus_const (list_ret, bytepos);
18115 : 0 : add_loc_descr_to_each (list_ret,
18116 : : new_loc_descr (DW_OP_stack_value, 0, 0));
18117 : : }
18118 : 0 : return list_ret;
18119 : : }
18120 : :
18121 : : /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
18122 : : all operations from LOC are nops, move to the last one. Insert in NOPS all
18123 : : operations that are skipped. */
18124 : :
18125 : : static void
18126 : 55022547 : loc_descr_to_next_no_nop (dw_loc_descr_ref &loc,
18127 : : hash_set<dw_loc_descr_ref> &nops)
18128 : : {
18129 : 55035091 : while (loc->dw_loc_next != NULL && loc->dw_loc_opc == DW_OP_nop)
18130 : : {
18131 : 12544 : nops.add (loc);
18132 : 12544 : loc = loc->dw_loc_next;
18133 : : }
18134 : 55022547 : }
18135 : :
18136 : : /* Helper for loc_descr_without_nops: free the location description operation
18137 : : P. */
18138 : :
18139 : : bool
18140 : 6272 : free_loc_descr (const dw_loc_descr_ref &loc, void *data ATTRIBUTE_UNUSED)
18141 : : {
18142 : 6272 : ggc_free (loc);
18143 : 6272 : return true;
18144 : : }
18145 : :
18146 : : /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
18147 : : finishes LOC. */
18148 : :
18149 : : static void
18150 : 25633328 : loc_descr_without_nops (dw_loc_descr_ref &loc)
18151 : : {
18152 : 25633328 : if (loc->dw_loc_opc == DW_OP_nop && loc->dw_loc_next == NULL)
18153 : 0 : return;
18154 : :
18155 : : /* Set of all DW_OP_nop operations we remove. */
18156 : 25633328 : hash_set<dw_loc_descr_ref> nops;
18157 : :
18158 : : /* First, strip all prefix NOP operations in order to keep the head of the
18159 : : operations list. */
18160 : 25633328 : loc_descr_to_next_no_nop (loc, nops);
18161 : :
18162 : 79271011 : for (dw_loc_descr_ref cur = loc; cur != NULL;)
18163 : : {
18164 : : /* For control flow operations: strip "prefix" nops in destination
18165 : : labels. */
18166 : 53637683 : if (cur->dw_loc_oprnd1.val_class == dw_val_class_loc)
18167 : 1384864 : loc_descr_to_next_no_nop (cur->dw_loc_oprnd1.v.val_loc, nops);
18168 : 53637683 : if (cur->dw_loc_oprnd2.val_class == dw_val_class_loc)
18169 : 0 : loc_descr_to_next_no_nop (cur->dw_loc_oprnd2.v.val_loc, nops);
18170 : :
18171 : : /* Do the same for the operations that follow, then move to the next
18172 : : iteration. */
18173 : 53637683 : if (cur->dw_loc_next != NULL)
18174 : 28004355 : loc_descr_to_next_no_nop (cur->dw_loc_next, nops);
18175 : 53637683 : cur = cur->dw_loc_next;
18176 : : }
18177 : :
18178 : 25639600 : nops.traverse<void *, free_loc_descr> (NULL);
18179 : 25633328 : }
18180 : :
18181 : :
18182 : : struct dwarf_procedure_info;
18183 : :
18184 : : /* Helper structure for location descriptions generation. */
18185 : : struct loc_descr_context
18186 : : {
18187 : : /* The type that is implicitly referenced by DW_OP_push_object_address, or
18188 : : NULL_TREE if DW_OP_push_object_address in invalid for this location
18189 : : description. This is used when processing PLACEHOLDER_EXPR nodes. */
18190 : : tree context_type;
18191 : : /* The ..._DECL node that should be translated as a
18192 : : DW_OP_push_object_address operation. */
18193 : : tree base_decl;
18194 : : /* Information about the DWARF procedure we are currently generating. NULL if
18195 : : we are not generating a DWARF procedure. */
18196 : : struct dwarf_procedure_info *dpi;
18197 : : /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
18198 : : by consumer. Used for DW_TAG_generic_subrange attributes. */
18199 : : bool placeholder_arg;
18200 : : /* True if PLACEHOLDER_EXPR has been seen. */
18201 : : bool placeholder_seen;
18202 : : /* True if strict preservation of signedness has been requested. */
18203 : : bool strict_signedness;
18204 : : };
18205 : :
18206 : : /* DWARF procedures generation
18207 : :
18208 : : DWARF expressions (aka. location descriptions) are used to encode variable
18209 : : things such as sizes or offsets. Such computations can have redundant parts
18210 : : that can be factorized in order to reduce the size of the output debug
18211 : : information. This is the whole point of DWARF procedures.
18212 : :
18213 : : Thanks to stor-layout.cc, size and offset expressions in GENERIC trees are
18214 : : already factorized into functions ("size functions") in order to handle very
18215 : : big and complex types. Such functions are quite simple: they have integral
18216 : : arguments, they return an integral result and their body contains only a
18217 : : return statement with arithmetic expressions. This is the only kind of
18218 : : function we are interested in translating into DWARF procedures, here.
18219 : :
18220 : : DWARF expressions and DWARF procedure are executed using a stack, so we have
18221 : : to define some calling convention for them to interact. Let's say that:
18222 : :
18223 : : - Before calling a DWARF procedure, DWARF expressions must push on the stack
18224 : : all arguments in reverse order (right-to-left) so that when the DWARF
18225 : : procedure execution starts, the first argument is the top of the stack.
18226 : :
18227 : : - Then, when returning, the DWARF procedure must have consumed all arguments
18228 : : on the stack, must have pushed the result and touched nothing else.
18229 : :
18230 : : - Each integral argument and the result are integral types can be hold in a
18231 : : single stack slot.
18232 : :
18233 : : - We call "frame offset" the number of stack slots that are "under DWARF
18234 : : procedure control": it includes the arguments slots, the temporaries and
18235 : : the result slot. Thus, it is equal to the number of arguments when the
18236 : : procedure execution starts and must be equal to one (the result) when it
18237 : : returns. */
18238 : :
18239 : : /* Helper structure used when generating operations for a DWARF procedure. */
18240 : : struct dwarf_procedure_info
18241 : : {
18242 : : /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
18243 : : currently translated. */
18244 : : tree fndecl;
18245 : : /* The number of arguments FNDECL takes. */
18246 : : unsigned args_count;
18247 : : };
18248 : :
18249 : : /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
18250 : : LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
18251 : : equate it to this DIE. */
18252 : :
18253 : : static dw_die_ref
18254 : 0 : new_dwarf_proc_die (dw_loc_descr_ref location, tree fndecl,
18255 : : dw_die_ref parent_die)
18256 : : {
18257 : 0 : dw_die_ref dwarf_proc_die;
18258 : :
18259 : 0 : if ((dwarf_version < 3 && dwarf_strict)
18260 : 0 : || location == NULL)
18261 : : return NULL;
18262 : :
18263 : 0 : dwarf_proc_die = new_die (DW_TAG_dwarf_procedure, parent_die, fndecl);
18264 : 0 : if (fndecl)
18265 : 0 : equate_decl_number_to_die (fndecl, dwarf_proc_die);
18266 : 0 : add_AT_loc (dwarf_proc_die, DW_AT_location, location);
18267 : 0 : return dwarf_proc_die;
18268 : : }
18269 : :
18270 : : /* Return whether TYPE is a supported type as a DWARF procedure argument
18271 : : type or return type (we handle only scalar types and pointer types that
18272 : : aren't wider than the DWARF expression evaluation stack). */
18273 : :
18274 : : static bool
18275 : 36 : is_handled_procedure_type (tree type)
18276 : : {
18277 : 36 : return ((INTEGRAL_TYPE_P (type)
18278 : 36 : || TREE_CODE (type) == OFFSET_TYPE
18279 : 0 : || TREE_CODE (type) == POINTER_TYPE)
18280 : 36 : && int_size_in_bytes (type) <= DWARF2_ADDR_SIZE);
18281 : : }
18282 : :
18283 : : /* Helper for resolve_args_picking: do the same but stop when coming across
18284 : : visited nodes. For each node we visit, register in FRAME_OFFSETS the frame
18285 : : offset *before* evaluating the corresponding operation. */
18286 : :
18287 : : static bool
18288 : 2880 : resolve_args_picking_1 (dw_loc_descr_ref loc, unsigned initial_frame_offset,
18289 : : struct dwarf_procedure_info *dpi,
18290 : : hash_map<dw_loc_descr_ref, unsigned> &frame_offsets)
18291 : : {
18292 : : /* The "frame_offset" identifier is already used to name a macro... */
18293 : 2880 : unsigned frame_offset_ = initial_frame_offset;
18294 : 2880 : dw_loc_descr_ref l;
18295 : :
18296 : 27988 : for (l = loc; l != NULL;)
18297 : : {
18298 : 25108 : bool existed;
18299 : 25108 : unsigned &l_frame_offset = frame_offsets.get_or_insert (l, &existed);
18300 : :
18301 : : /* If we already met this node, there is nothing to compute anymore. */
18302 : 25108 : if (existed)
18303 : : {
18304 : : /* Make sure that the stack size is consistent wherever the execution
18305 : : flow comes from. */
18306 : 0 : gcc_assert ((unsigned) l_frame_offset == frame_offset_);
18307 : 0 : break;
18308 : : }
18309 : 25108 : l_frame_offset = frame_offset_;
18310 : :
18311 : : /* If needed, relocate the picking offset with respect to the frame
18312 : : offset. */
18313 : 25108 : if (l->dw_loc_frame_offset_rel)
18314 : : {
18315 : 2880 : unsigned HOST_WIDE_INT off;
18316 : 2880 : switch (l->dw_loc_opc)
18317 : : {
18318 : 2880 : case DW_OP_pick:
18319 : 2880 : off = l->dw_loc_oprnd1.v.val_unsigned;
18320 : 2880 : break;
18321 : : case DW_OP_dup:
18322 : : off = 0;
18323 : : break;
18324 : 0 : case DW_OP_over:
18325 : 0 : off = 1;
18326 : 0 : break;
18327 : 0 : default:
18328 : 0 : gcc_unreachable ();
18329 : : }
18330 : : /* frame_offset_ is the size of the current stack frame, including
18331 : : incoming arguments. Besides, the arguments are pushed
18332 : : right-to-left. Thus, in order to access the Nth argument from
18333 : : this operation node, the picking has to skip temporaries *plus*
18334 : : one stack slot per argument (0 for the first one, 1 for the second
18335 : : one, etc.).
18336 : :
18337 : : The targetted argument number (N) is already set as the operand,
18338 : : and the number of temporaries can be computed with:
18339 : : frame_offsets_ - dpi->args_count */
18340 : 2880 : off += frame_offset_ - dpi->args_count;
18341 : :
18342 : : /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
18343 : 2880 : if (off > 255)
18344 : 0 : return false;
18345 : :
18346 : 2880 : if (off == 0)
18347 : : {
18348 : 0 : l->dw_loc_opc = DW_OP_dup;
18349 : 0 : l->dw_loc_oprnd1.v.val_unsigned = 0;
18350 : : }
18351 : 2880 : else if (off == 1)
18352 : : {
18353 : 2880 : l->dw_loc_opc = DW_OP_over;
18354 : 2880 : l->dw_loc_oprnd1.v.val_unsigned = 0;
18355 : : }
18356 : : else
18357 : : {
18358 : 0 : l->dw_loc_opc = DW_OP_pick;
18359 : 0 : l->dw_loc_oprnd1.v.val_unsigned = off;
18360 : : }
18361 : : }
18362 : :
18363 : : /* Update frame_offset according to the effect the current operation has
18364 : : on the stack. */
18365 : 25108 : switch (l->dw_loc_opc)
18366 : : {
18367 : : case DW_OP_deref:
18368 : : case DW_OP_swap:
18369 : : case DW_OP_rot:
18370 : : case DW_OP_abs:
18371 : : case DW_OP_neg:
18372 : : case DW_OP_not:
18373 : : case DW_OP_plus_uconst:
18374 : : case DW_OP_skip:
18375 : : case DW_OP_reg0:
18376 : : case DW_OP_reg1:
18377 : : case DW_OP_reg2:
18378 : : case DW_OP_reg3:
18379 : : case DW_OP_reg4:
18380 : : case DW_OP_reg5:
18381 : : case DW_OP_reg6:
18382 : : case DW_OP_reg7:
18383 : : case DW_OP_reg8:
18384 : : case DW_OP_reg9:
18385 : : case DW_OP_reg10:
18386 : : case DW_OP_reg11:
18387 : : case DW_OP_reg12:
18388 : : case DW_OP_reg13:
18389 : : case DW_OP_reg14:
18390 : : case DW_OP_reg15:
18391 : : case DW_OP_reg16:
18392 : : case DW_OP_reg17:
18393 : : case DW_OP_reg18:
18394 : : case DW_OP_reg19:
18395 : : case DW_OP_reg20:
18396 : : case DW_OP_reg21:
18397 : : case DW_OP_reg22:
18398 : : case DW_OP_reg23:
18399 : : case DW_OP_reg24:
18400 : : case DW_OP_reg25:
18401 : : case DW_OP_reg26:
18402 : : case DW_OP_reg27:
18403 : : case DW_OP_reg28:
18404 : : case DW_OP_reg29:
18405 : : case DW_OP_reg30:
18406 : : case DW_OP_reg31:
18407 : : case DW_OP_bregx:
18408 : : case DW_OP_piece:
18409 : : case DW_OP_deref_size:
18410 : : case DW_OP_nop:
18411 : : case DW_OP_bit_piece:
18412 : : case DW_OP_implicit_value:
18413 : : case DW_OP_stack_value:
18414 : : case DW_OP_deref_type:
18415 : : case DW_OP_convert:
18416 : : case DW_OP_reinterpret:
18417 : : case DW_OP_GNU_deref_type:
18418 : : case DW_OP_GNU_convert:
18419 : : case DW_OP_GNU_reinterpret:
18420 : : break;
18421 : :
18422 : 9600 : case DW_OP_addr:
18423 : 9600 : case DW_OP_const1u:
18424 : 9600 : case DW_OP_const1s:
18425 : 9600 : case DW_OP_const2u:
18426 : 9600 : case DW_OP_const2s:
18427 : 9600 : case DW_OP_const4u:
18428 : 9600 : case DW_OP_const4s:
18429 : 9600 : case DW_OP_const8u:
18430 : 9600 : case DW_OP_const8s:
18431 : 9600 : case DW_OP_constu:
18432 : 9600 : case DW_OP_consts:
18433 : 9600 : case DW_OP_dup:
18434 : 9600 : case DW_OP_over:
18435 : 9600 : case DW_OP_pick:
18436 : 9600 : case DW_OP_lit0:
18437 : 9600 : case DW_OP_lit1:
18438 : 9600 : case DW_OP_lit2:
18439 : 9600 : case DW_OP_lit3:
18440 : 9600 : case DW_OP_lit4:
18441 : 9600 : case DW_OP_lit5:
18442 : 9600 : case DW_OP_lit6:
18443 : 9600 : case DW_OP_lit7:
18444 : 9600 : case DW_OP_lit8:
18445 : 9600 : case DW_OP_lit9:
18446 : 9600 : case DW_OP_lit10:
18447 : 9600 : case DW_OP_lit11:
18448 : 9600 : case DW_OP_lit12:
18449 : 9600 : case DW_OP_lit13:
18450 : 9600 : case DW_OP_lit14:
18451 : 9600 : case DW_OP_lit15:
18452 : 9600 : case DW_OP_lit16:
18453 : 9600 : case DW_OP_lit17:
18454 : 9600 : case DW_OP_lit18:
18455 : 9600 : case DW_OP_lit19:
18456 : 9600 : case DW_OP_lit20:
18457 : 9600 : case DW_OP_lit21:
18458 : 9600 : case DW_OP_lit22:
18459 : 9600 : case DW_OP_lit23:
18460 : 9600 : case DW_OP_lit24:
18461 : 9600 : case DW_OP_lit25:
18462 : 9600 : case DW_OP_lit26:
18463 : 9600 : case DW_OP_lit27:
18464 : 9600 : case DW_OP_lit28:
18465 : 9600 : case DW_OP_lit29:
18466 : 9600 : case DW_OP_lit30:
18467 : 9600 : case DW_OP_lit31:
18468 : 9600 : case DW_OP_breg0:
18469 : 9600 : case DW_OP_breg1:
18470 : 9600 : case DW_OP_breg2:
18471 : 9600 : case DW_OP_breg3:
18472 : 9600 : case DW_OP_breg4:
18473 : 9600 : case DW_OP_breg5:
18474 : 9600 : case DW_OP_breg6:
18475 : 9600 : case DW_OP_breg7:
18476 : 9600 : case DW_OP_breg8:
18477 : 9600 : case DW_OP_breg9:
18478 : 9600 : case DW_OP_breg10:
18479 : 9600 : case DW_OP_breg11:
18480 : 9600 : case DW_OP_breg12:
18481 : 9600 : case DW_OP_breg13:
18482 : 9600 : case DW_OP_breg14:
18483 : 9600 : case DW_OP_breg15:
18484 : 9600 : case DW_OP_breg16:
18485 : 9600 : case DW_OP_breg17:
18486 : 9600 : case DW_OP_breg18:
18487 : 9600 : case DW_OP_breg19:
18488 : 9600 : case DW_OP_breg20:
18489 : 9600 : case DW_OP_breg21:
18490 : 9600 : case DW_OP_breg22:
18491 : 9600 : case DW_OP_breg23:
18492 : 9600 : case DW_OP_breg24:
18493 : 9600 : case DW_OP_breg25:
18494 : 9600 : case DW_OP_breg26:
18495 : 9600 : case DW_OP_breg27:
18496 : 9600 : case DW_OP_breg28:
18497 : 9600 : case DW_OP_breg29:
18498 : 9600 : case DW_OP_breg30:
18499 : 9600 : case DW_OP_breg31:
18500 : 9600 : case DW_OP_fbreg:
18501 : 9600 : case DW_OP_push_object_address:
18502 : 9600 : case DW_OP_call_frame_cfa:
18503 : 9600 : case DW_OP_GNU_variable_value:
18504 : 9600 : case DW_OP_GNU_addr_index:
18505 : 9600 : case DW_OP_GNU_const_index:
18506 : 9600 : ++frame_offset_;
18507 : 9600 : break;
18508 : :
18509 : 6720 : case DW_OP_drop:
18510 : 6720 : case DW_OP_xderef:
18511 : 6720 : case DW_OP_and:
18512 : 6720 : case DW_OP_div:
18513 : 6720 : case DW_OP_minus:
18514 : 6720 : case DW_OP_mod:
18515 : 6720 : case DW_OP_mul:
18516 : 6720 : case DW_OP_or:
18517 : 6720 : case DW_OP_plus:
18518 : 6720 : case DW_OP_shl:
18519 : 6720 : case DW_OP_shr:
18520 : 6720 : case DW_OP_shra:
18521 : 6720 : case DW_OP_xor:
18522 : 6720 : case DW_OP_bra:
18523 : 6720 : case DW_OP_eq:
18524 : 6720 : case DW_OP_ge:
18525 : 6720 : case DW_OP_gt:
18526 : 6720 : case DW_OP_le:
18527 : 6720 : case DW_OP_lt:
18528 : 6720 : case DW_OP_ne:
18529 : 6720 : case DW_OP_regx:
18530 : 6720 : case DW_OP_xderef_size:
18531 : 6720 : --frame_offset_;
18532 : 6720 : break;
18533 : :
18534 : 0 : case DW_OP_call2:
18535 : 0 : case DW_OP_call4:
18536 : 0 : case DW_OP_call_ref:
18537 : 0 : {
18538 : 0 : dw_die_ref dwarf_proc = l->dw_loc_oprnd1.v.val_die_ref.die;
18539 : 0 : int *stack_usage = dwarf_proc_stack_usage_map->get (dwarf_proc);
18540 : :
18541 : 0 : if (stack_usage == NULL)
18542 : 0 : return false;
18543 : 0 : frame_offset_ += *stack_usage;
18544 : 0 : break;
18545 : : }
18546 : :
18547 : 0 : case DW_OP_implicit_pointer:
18548 : 0 : case DW_OP_entry_value:
18549 : 0 : case DW_OP_const_type:
18550 : 0 : case DW_OP_regval_type:
18551 : 0 : case DW_OP_form_tls_address:
18552 : 0 : case DW_OP_GNU_push_tls_address:
18553 : 0 : case DW_OP_GNU_uninit:
18554 : 0 : case DW_OP_GNU_encoded_addr:
18555 : 0 : case DW_OP_GNU_implicit_pointer:
18556 : 0 : case DW_OP_GNU_entry_value:
18557 : 0 : case DW_OP_GNU_const_type:
18558 : 0 : case DW_OP_GNU_regval_type:
18559 : 0 : case DW_OP_GNU_parameter_ref:
18560 : : /* loc_list_from_tree will probably not output these operations for
18561 : : size functions, so assume they will not appear here. */
18562 : : /* Fall through... */
18563 : :
18564 : 0 : default:
18565 : 0 : gcc_unreachable ();
18566 : : }
18567 : :
18568 : : /* Now, follow the control flow (except subroutine calls). */
18569 : 25108 : switch (l->dw_loc_opc)
18570 : : {
18571 : 0 : case DW_OP_bra:
18572 : 0 : if (!resolve_args_picking_1 (l->dw_loc_next, frame_offset_, dpi,
18573 : : frame_offsets))
18574 : : return false;
18575 : : /* Fall through. */
18576 : :
18577 : 0 : case DW_OP_skip:
18578 : 0 : l = l->dw_loc_oprnd1.v.val_loc;
18579 : 0 : break;
18580 : :
18581 : : case DW_OP_stack_value:
18582 : : return true;
18583 : :
18584 : 25108 : default:
18585 : 25108 : l = l->dw_loc_next;
18586 : 25108 : break;
18587 : : }
18588 : : }
18589 : :
18590 : : return true;
18591 : : }
18592 : :
18593 : : /* Make a DFS over operations reachable through LOC (i.e. follow branch
18594 : : operations) in order to resolve the operand of DW_OP_pick operations that
18595 : : target DWARF procedure arguments (DPI). INITIAL_FRAME_OFFSET is the frame
18596 : : offset *before* LOC is executed. Return if all relocations were
18597 : : successful. */
18598 : :
18599 : : static bool
18600 : 2880 : resolve_args_picking (dw_loc_descr_ref loc, unsigned initial_frame_offset,
18601 : : struct dwarf_procedure_info *dpi)
18602 : : {
18603 : : /* Associate to all visited operations the frame offset *before* evaluating
18604 : : this operation. */
18605 : 2880 : hash_map<dw_loc_descr_ref, unsigned> frame_offsets;
18606 : :
18607 : 2880 : return
18608 : 2880 : resolve_args_picking_1 (loc, initial_frame_offset, dpi, frame_offsets);
18609 : 2880 : }
18610 : :
18611 : : /* Try to generate a DWARF procedure that computes the same result as FNDECL.
18612 : : Return NULL if it is not possible. */
18613 : :
18614 : : static dw_die_ref
18615 : 36 : function_to_dwarf_procedure (tree fndecl)
18616 : : {
18617 : 36 : struct dwarf_procedure_info dpi;
18618 : 36 : struct loc_descr_context ctx = {
18619 : : NULL_TREE, /* context_type */
18620 : : NULL_TREE, /* base_decl */
18621 : : &dpi, /* dpi */
18622 : : false, /* placeholder_arg */
18623 : : false, /* placeholder_seen */
18624 : : true /* strict_signedness */
18625 : 36 : };
18626 : 36 : dw_die_ref dwarf_proc_die;
18627 : 36 : tree tree_body = DECL_SAVED_TREE (fndecl);
18628 : 36 : dw_loc_descr_ref loc_body, epilogue;
18629 : :
18630 : 36 : tree cursor;
18631 : 36 : unsigned i;
18632 : :
18633 : : /* Do not generate multiple DWARF procedures for the same function
18634 : : declaration. */
18635 : 36 : dwarf_proc_die = lookup_decl_die (fndecl);
18636 : 36 : if (dwarf_proc_die != NULL)
18637 : : return dwarf_proc_die;
18638 : :
18639 : : /* DWARF procedures are available starting with the DWARFv3 standard. */
18640 : 32 : if (dwarf_version < 3 && dwarf_strict)
18641 : : return NULL;
18642 : :
18643 : : /* We handle only functions for which we still have a body, that return a
18644 : : supported type and that takes arguments with supported types. Note that
18645 : : there is no point translating functions that return nothing. */
18646 : 32 : if (tree_body == NULL_TREE
18647 : 0 : || DECL_RESULT (fndecl) == NULL_TREE
18648 : 32 : || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl))))
18649 : 32 : return NULL;
18650 : :
18651 : 0 : for (cursor = DECL_ARGUMENTS (fndecl);
18652 : 0 : cursor != NULL_TREE;
18653 : 0 : cursor = TREE_CHAIN (cursor))
18654 : 0 : if (!is_handled_procedure_type (TREE_TYPE (cursor)))
18655 : : return NULL;
18656 : :
18657 : : /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
18658 : 0 : if (TREE_CODE (tree_body) != RETURN_EXPR)
18659 : : return NULL;
18660 : 0 : tree_body = TREE_OPERAND (tree_body, 0);
18661 : 0 : if (TREE_CODE (tree_body) != MODIFY_EXPR
18662 : 0 : || TREE_OPERAND (tree_body, 0) != DECL_RESULT (fndecl))
18663 : : return NULL;
18664 : 0 : tree_body = TREE_OPERAND (tree_body, 1);
18665 : :
18666 : : /* Try to translate the body expression itself. Note that this will probably
18667 : : cause an infinite recursion if its call graph has a cycle. This is very
18668 : : unlikely for size functions, however, so don't bother with such things at
18669 : : the moment. */
18670 : 0 : dpi.fndecl = fndecl;
18671 : 0 : dpi.args_count = list_length (DECL_ARGUMENTS (fndecl));
18672 : 0 : loc_body = loc_descriptor_from_tree (tree_body, 0, &ctx);
18673 : 0 : if (!loc_body)
18674 : : return NULL;
18675 : :
18676 : : /* After evaluating all operands in "loc_body", we should still have on the
18677 : : stack all arguments plus the desired function result (top of the stack).
18678 : : Generate code in order to keep only the result in our stack frame. */
18679 : : epilogue = NULL;
18680 : 0 : for (i = 0; i < dpi.args_count; ++i)
18681 : : {
18682 : 0 : dw_loc_descr_ref op_couple = new_loc_descr (DW_OP_swap, 0, 0);
18683 : 0 : op_couple->dw_loc_next = new_loc_descr (DW_OP_drop, 0, 0);
18684 : 0 : op_couple->dw_loc_next->dw_loc_next = epilogue;
18685 : 0 : epilogue = op_couple;
18686 : : }
18687 : 0 : add_loc_descr (&loc_body, epilogue);
18688 : 0 : if (!resolve_args_picking (loc_body, dpi.args_count, &dpi))
18689 : : return NULL;
18690 : :
18691 : : /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
18692 : : because they are considered useful. Now there is an epilogue, they are
18693 : : not anymore, so give it another try. */
18694 : 0 : loc_descr_without_nops (loc_body);
18695 : :
18696 : : /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
18697 : : a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
18698 : : though, given that size functions do not come from source, so they should
18699 : : not have a dedicated DW_TAG_subprogram DIE. */
18700 : 0 : dwarf_proc_die
18701 : 0 : = new_dwarf_proc_die (loc_body, fndecl,
18702 : 0 : get_context_die (DECL_CONTEXT (fndecl)));
18703 : :
18704 : : /* The called DWARF procedure consumes one stack slot per argument and
18705 : : returns one stack slot. */
18706 : 0 : dwarf_proc_stack_usage_map->put (dwarf_proc_die, 1 - dpi.args_count);
18707 : :
18708 : 0 : return dwarf_proc_die;
18709 : : }
18710 : :
18711 : : /* Helper function for loc_list_from_tree. Perform OP binary op,
18712 : : but after converting arguments to type_die, afterwards convert
18713 : : back to unsigned. */
18714 : :
18715 : : static dw_loc_list_ref
18716 : 0 : typed_binop_from_tree (enum dwarf_location_atom op, tree loc,
18717 : : dw_die_ref type_die, scalar_int_mode mode,
18718 : : struct loc_descr_context *context)
18719 : : {
18720 : 0 : dw_loc_list_ref op0, op1;
18721 : 0 : dw_loc_descr_ref cvt, binop;
18722 : :
18723 : 0 : if (type_die == NULL)
18724 : : return NULL;
18725 : :
18726 : 0 : op0 = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
18727 : 0 : op1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
18728 : 0 : if (op0 == NULL || op1 == NULL)
18729 : : return NULL;
18730 : :
18731 : 0 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
18732 : 0 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
18733 : 0 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
18734 : 0 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
18735 : 0 : add_loc_descr_to_each (op0, cvt);
18736 : :
18737 : 0 : cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
18738 : 0 : cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
18739 : 0 : cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
18740 : 0 : cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
18741 : 0 : add_loc_descr_to_each (op1, cvt);
18742 : :
18743 : 0 : add_loc_list (&op0, op1);
18744 : 0 : if (op0 == NULL)
18745 : : return NULL;
18746 : :
18747 : 0 : binop = new_loc_descr (op, 0, 0);
18748 : 0 : convert_descriptor_to_mode (mode, binop);
18749 : 0 : add_loc_descr_to_each (op0, binop);
18750 : :
18751 : 0 : return op0;
18752 : : }
18753 : :
18754 : : /* Generate Dwarf location list representing LOC.
18755 : : If WANT_ADDRESS is false, expression computing LOC will be computed
18756 : : If WANT_ADDRESS is 1, expression computing address of LOC will be returned
18757 : : if WANT_ADDRESS is 2, expression computing address useable in location
18758 : : will be returned (i.e. DW_OP_reg can be used
18759 : : to refer to register values).
18760 : :
18761 : : CONTEXT provides information to customize the location descriptions
18762 : : generation. Its context_type field specifies what type is implicitly
18763 : : referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
18764 : : will not be generated.
18765 : :
18766 : : Its DPI field determines whether we are generating a DWARF expression for a
18767 : : DWARF procedure, so PARM_DECL references are processed specifically.
18768 : :
18769 : : If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
18770 : : and dpi fields were null. */
18771 : :
18772 : : static dw_loc_list_ref
18773 : 16629676 : loc_list_from_tree_1 (tree loc, int want_address,
18774 : : struct loc_descr_context *context)
18775 : : {
18776 : 16813195 : dw_loc_descr_ref ret = NULL, ret1 = NULL;
18777 : 16813195 : dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
18778 : 16813195 : int have_address = 0;
18779 : 16813195 : enum dwarf_location_atom op;
18780 : :
18781 : : /* ??? Most of the time we do not take proper care for sign/zero
18782 : : extending the values properly. Hopefully this won't be a real
18783 : : problem... */
18784 : :
18785 : 16813195 : if (context != NULL
18786 : 376204 : && context->base_decl == loc
18787 : 94220 : && want_address == 0)
18788 : : {
18789 : 94220 : if (dwarf_version >= 3 || !dwarf_strict)
18790 : 94220 : return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
18791 : 94220 : NULL, 0, NULL, 0, NULL);
18792 : : else
18793 : : return NULL;
18794 : : }
18795 : :
18796 : 16718975 : switch (TREE_CODE (loc))
18797 : : {
18798 : 0 : case ERROR_MARK:
18799 : 0 : expansion_failed (loc, NULL_RTX, "ERROR_MARK");
18800 : 0 : return 0;
18801 : :
18802 : 5760 : case PLACEHOLDER_EXPR:
18803 : : /* This case involves extracting fields from an object to determine the
18804 : : position of other fields. It is supposed to appear only as the first
18805 : : operand of COMPONENT_REF nodes and to reference precisely the type
18806 : : that the context allows or its enclosing type. */
18807 : 5760 : if (context != NULL
18808 : 5760 : && (TREE_TYPE (loc) == context->context_type
18809 : 5760 : || TREE_TYPE (loc) == TYPE_CONTEXT (context->context_type))
18810 : 5760 : && want_address >= 1)
18811 : : {
18812 : 0 : if (dwarf_version >= 3 || !dwarf_strict)
18813 : : {
18814 : 0 : ret = new_loc_descr (DW_OP_push_object_address, 0, 0);
18815 : 0 : have_address = 1;
18816 : 0 : break;
18817 : : }
18818 : : else
18819 : : return NULL;
18820 : : }
18821 : : /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
18822 : : the single argument passed by consumer. */
18823 : 5760 : else if (context != NULL
18824 : 5760 : && context->placeholder_arg
18825 : 5760 : && INTEGRAL_TYPE_P (TREE_TYPE (loc))
18826 : 11520 : && want_address == 0)
18827 : : {
18828 : 5760 : ret = new_loc_descr (DW_OP_pick, 0, 0);
18829 : 5760 : ret->dw_loc_frame_offset_rel = 1;
18830 : 5760 : context->placeholder_seen = true;
18831 : 5760 : break;
18832 : : }
18833 : : else
18834 : 0 : expansion_failed (loc, NULL_RTX,
18835 : : "PLACEHOLDER_EXPR for an unexpected type");
18836 : 0 : break;
18837 : :
18838 : 36 : case CALL_EXPR:
18839 : 36 : {
18840 : 36 : tree callee = get_callee_fndecl (loc);
18841 : 36 : dw_die_ref dwarf_proc;
18842 : :
18843 : 36 : if (callee
18844 : 36 : && is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee)))
18845 : 72 : && (dwarf_proc = function_to_dwarf_procedure (callee)))
18846 : : {
18847 : : /* DWARF procedures are used for size functions, which are built
18848 : : when size expressions contain conditional constructs, so we
18849 : : request strict preservation of signedness for comparisons. */
18850 : 4 : bool old_strict_signedness;
18851 : 4 : if (context)
18852 : : {
18853 : 0 : old_strict_signedness = context->strict_signedness;
18854 : 0 : context->strict_signedness = true;
18855 : : }
18856 : :
18857 : : /* Evaluate arguments right-to-left so that the first argument
18858 : : will be the top-most one on the stack. */
18859 : 4 : for (int i = call_expr_nargs (loc) - 1; i >= 0; --i)
18860 : : {
18861 : 0 : tree arg = CALL_EXPR_ARG (loc, i);
18862 : 0 : ret1 = loc_descriptor_from_tree (arg, 0, context);
18863 : 0 : if (!ret1)
18864 : : {
18865 : 0 : expansion_failed (arg, NULL_RTX, "CALL_EXPR argument");
18866 : 0 : return NULL;
18867 : : }
18868 : 0 : add_loc_descr (&ret, ret1);
18869 : : }
18870 : :
18871 : 4 : ret1 = new_loc_descr (DW_OP_call4, 0, 0);
18872 : 4 : ret1->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
18873 : 4 : ret1->dw_loc_oprnd1.v.val_die_ref.die = dwarf_proc;
18874 : 4 : ret1->dw_loc_oprnd1.v.val_die_ref.external = 0;
18875 : 4 : add_loc_descr (&ret, ret1);
18876 : 4 : if (context)
18877 : 0 : context->strict_signedness = old_strict_signedness;
18878 : : }
18879 : : else
18880 : 32 : expansion_failed (loc, NULL_RTX, "CALL_EXPR target");
18881 : : break;
18882 : : }
18883 : :
18884 : 0 : case PREINCREMENT_EXPR:
18885 : 0 : case PREDECREMENT_EXPR:
18886 : 0 : case POSTINCREMENT_EXPR:
18887 : 0 : case POSTDECREMENT_EXPR:
18888 : 0 : expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
18889 : : /* There are no opcodes for these operations. */
18890 : 0 : return 0;
18891 : :
18892 : 85 : case ADDR_EXPR:
18893 : : /* If we already want an address, see if there is INDIRECT_REF inside
18894 : : e.g. for &this->field. */
18895 : 85 : if (want_address)
18896 : : {
18897 : 168 : list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
18898 : 84 : (loc, want_address == 2, context);
18899 : 84 : if (list_ret)
18900 : : have_address = 1;
18901 : 84 : else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
18902 : 84 : && (ret = cst_pool_loc_descr (loc)))
18903 : : have_address = 1;
18904 : : }
18905 : : /* Otherwise, process the argument and look for the address. */
18906 : 85 : if (!list_ret && !ret)
18907 : 85 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 1, context);
18908 : : else
18909 : : {
18910 : 0 : if (want_address)
18911 : 0 : expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
18912 : 0 : return NULL;
18913 : : }
18914 : 85 : break;
18915 : :
18916 : 15123675 : case VAR_DECL:
18917 : 15123675 : if (DECL_THREAD_LOCAL_P (loc))
18918 : : {
18919 : 464 : rtx rtl;
18920 : 464 : enum dwarf_location_atom tls_op;
18921 : 464 : enum dtprel_bool dtprel = dtprel_false;
18922 : :
18923 : 464 : if (targetm.have_tls)
18924 : : {
18925 : : /* If this is not defined, we have no way to emit the
18926 : : data. */
18927 : 464 : if (!targetm.asm_out.output_dwarf_dtprel)
18928 : : return 0;
18929 : :
18930 : : /* The way DW_OP_GNU_push_tls_address is specified, we
18931 : : can only look up addresses of objects in the current
18932 : : module. We used DW_OP_addr as first op, but that's
18933 : : wrong, because DW_OP_addr is relocated by the debug
18934 : : info consumer, while DW_OP_GNU_push_tls_address
18935 : : operand shouldn't be. */
18936 : 464 : if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
18937 : : return 0;
18938 : 464 : dtprel = dtprel_true;
18939 : : /* We check for DWARF 5 here because gdb did not implement
18940 : : DW_OP_form_tls_address until after 7.12. */
18941 : 464 : tls_op = (dwarf_version >= 5 ? DW_OP_form_tls_address
18942 : : : DW_OP_GNU_push_tls_address);
18943 : : }
18944 : : else
18945 : : {
18946 : 0 : if (!targetm.emutls.debug_form_tls_address
18947 : 0 : || !(dwarf_version >= 3 || !dwarf_strict))
18948 : : return 0;
18949 : : /* We stuffed the control variable into the DECL_VALUE_EXPR
18950 : : to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
18951 : : no longer appear in gimple code. We used the control
18952 : : variable in specific so that we could pick it up here. */
18953 : 0 : loc = DECL_VALUE_EXPR (loc);
18954 : 0 : tls_op = DW_OP_form_tls_address;
18955 : : }
18956 : :
18957 : 464 : rtl = rtl_for_decl_location (loc);
18958 : 464 : if (rtl == NULL_RTX)
18959 : : return 0;
18960 : :
18961 : 464 : if (!MEM_P (rtl))
18962 : : return 0;
18963 : 464 : rtl = XEXP (rtl, 0);
18964 : 464 : if (! CONSTANT_P (rtl))
18965 : : return 0;
18966 : :
18967 : 464 : ret = new_addr_loc_descr (rtl, dtprel);
18968 : 464 : ret1 = new_loc_descr (tls_op, 0, 0);
18969 : 464 : add_loc_descr (&ret, ret1);
18970 : :
18971 : 464 : have_address = 1;
18972 : 464 : break;
18973 : : }
18974 : : /* FALLTHRU */
18975 : :
18976 : 16161200 : case PARM_DECL:
18977 : 268 : if (context != NULL && context->dpi != NULL
18978 : 16161200 : && DECL_CONTEXT (loc) == context->dpi->fndecl)
18979 : : {
18980 : : /* We are generating code for a DWARF procedure and we want to access
18981 : : one of its arguments: find the appropriate argument offset and let
18982 : : the resolve_args_picking pass compute the offset that complies
18983 : : with the stack frame size. */
18984 : 0 : unsigned i = 0;
18985 : 0 : tree cursor;
18986 : :
18987 : 0 : for (cursor = DECL_ARGUMENTS (context->dpi->fndecl);
18988 : 0 : cursor != NULL_TREE && cursor != loc;
18989 : 0 : cursor = TREE_CHAIN (cursor), ++i)
18990 : : ;
18991 : : /* If we are translating a DWARF procedure, all referenced parameters
18992 : : must belong to the current function. */
18993 : 0 : gcc_assert (cursor != NULL_TREE);
18994 : :
18995 : 0 : ret = new_loc_descr (DW_OP_pick, i, 0);
18996 : 0 : ret->dw_loc_frame_offset_rel = 1;
18997 : 0 : break;
18998 : : }
18999 : : /* FALLTHRU */
19000 : :
19001 : 16163467 : case RESULT_DECL:
19002 : 16163467 : if (DECL_HAS_VALUE_EXPR_P (loc))
19003 : : {
19004 : 135923 : tree value_expr = DECL_VALUE_EXPR (loc);
19005 : :
19006 : : /* Non-local frame structures are DECL_IGNORED_P variables so we need
19007 : : to wait until they get an RTX in order to reference them. */
19008 : 135923 : if (early_dwarf
19009 : 21 : && TREE_CODE (value_expr) == COMPONENT_REF
19010 : 21 : && VAR_P (TREE_OPERAND (value_expr, 0))
19011 : 135942 : && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr, 0)))
19012 : : ;
19013 : : else
19014 : : return loc_list_from_tree_1 (value_expr, want_address, context);
19015 : : }
19016 : :
19017 : : /* FALLTHRU */
19018 : :
19019 : 16027647 : case FUNCTION_DECL:
19020 : 16027647 : {
19021 : 16027647 : rtx rtl;
19022 : 16027647 : var_loc_list *loc_list = lookup_decl_loc (loc);
19023 : :
19024 : 16027647 : if (loc_list && loc_list->first)
19025 : : {
19026 : 12982508 : list_ret = dw_loc_list (loc_list, loc, want_address);
19027 : 12982508 : have_address = want_address != 0;
19028 : 12982508 : break;
19029 : : }
19030 : 3045139 : rtl = rtl_for_decl_location (loc);
19031 : 3045139 : if (rtl == NULL_RTX)
19032 : : {
19033 : 2326404 : if (TREE_CODE (loc) != FUNCTION_DECL
19034 : 2326403 : && early_dwarf
19035 : 9217 : && want_address != 1
19036 : 9217 : && ! DECL_IGNORED_P (loc)
19037 : 8928 : && (INTEGRAL_TYPE_P (TREE_TYPE (loc))
19038 : 62 : || POINTER_TYPE_P (TREE_TYPE (loc)))
19039 : 8928 : && TYPE_MODE (TREE_TYPE (loc)) != BLKmode
19040 : 2344252 : && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc)))
19041 : 8924 : <= DWARF2_ADDR_SIZE))
19042 : : {
19043 : 8924 : dw_die_ref ref = lookup_decl_die (loc);
19044 : 8924 : if (ref)
19045 : : {
19046 : 5241 : ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
19047 : 5241 : ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
19048 : 5241 : ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
19049 : 5241 : ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
19050 : : }
19051 : 3683 : else if (current_function_decl
19052 : 3683 : && DECL_CONTEXT (loc) == current_function_decl)
19053 : : {
19054 : 3520 : ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
19055 : 3520 : ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
19056 : 3520 : ret->dw_loc_oprnd1.v.val_decl_ref = loc;
19057 : : }
19058 : : break;
19059 : : }
19060 : 2317480 : expansion_failed (loc, NULL_RTX, "DECL has no RTL");
19061 : 2317480 : return 0;
19062 : : }
19063 : 718735 : else if (CONST_INT_P (rtl))
19064 : : {
19065 : 0 : HOST_WIDE_INT val = INTVAL (rtl);
19066 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
19067 : 0 : val &= GET_MODE_MASK (DECL_MODE (loc));
19068 : 0 : ret = int_loc_descriptor (val);
19069 : : }
19070 : 718735 : else if (GET_CODE (rtl) == CONST_STRING)
19071 : : {
19072 : 0 : expansion_failed (loc, NULL_RTX, "CONST_STRING");
19073 : 0 : return 0;
19074 : : }
19075 : 718735 : else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
19076 : 0 : ret = new_addr_loc_descr (rtl, dtprel_false);
19077 : : else
19078 : : {
19079 : 718735 : machine_mode mode, mem_mode;
19080 : :
19081 : : /* Certain constructs can only be represented at top-level. */
19082 : 718735 : if (want_address == 2)
19083 : : {
19084 : 702174 : ret = loc_descriptor (rtl, VOIDmode,
19085 : : VAR_INIT_STATUS_INITIALIZED);
19086 : 702174 : have_address = 1;
19087 : : }
19088 : : else
19089 : : {
19090 : 16561 : mode = GET_MODE (rtl);
19091 : 16561 : mem_mode = VOIDmode;
19092 : 16561 : if (MEM_P (rtl))
19093 : : {
19094 : 2027 : mem_mode = mode;
19095 : 2027 : mode = get_address_mode (rtl);
19096 : 2027 : rtl = XEXP (rtl, 0);
19097 : 2027 : have_address = 1;
19098 : : }
19099 : 16561 : ret = mem_loc_descriptor (rtl, mode, mem_mode,
19100 : : VAR_INIT_STATUS_INITIALIZED);
19101 : : }
19102 : 718735 : if (!ret)
19103 : 59926 : expansion_failed (loc, rtl,
19104 : : "failed to produce loc descriptor for rtl");
19105 : : }
19106 : : }
19107 : : break;
19108 : :
19109 : 5210 : case MEM_REF:
19110 : 5210 : if (!integer_zerop (TREE_OPERAND (loc, 1)))
19111 : : {
19112 : 0 : have_address = 1;
19113 : 0 : goto do_plus;
19114 : : }
19115 : : /* Fallthru. */
19116 : 239084 : case INDIRECT_REF:
19117 : 239084 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19118 : 239084 : have_address = 1;
19119 : 239084 : break;
19120 : :
19121 : : case TARGET_MEM_REF:
19122 : : case SSA_NAME:
19123 : : case DEBUG_EXPR_DECL:
19124 : : return NULL;
19125 : :
19126 : 0 : case COMPOUND_EXPR:
19127 : 0 : return loc_list_from_tree_1 (TREE_OPERAND (loc, 1), want_address,
19128 : 0 : context);
19129 : :
19130 : 47615 : CASE_CONVERT:
19131 : 47615 : case VIEW_CONVERT_EXPR:
19132 : 47615 : case SAVE_EXPR:
19133 : 47615 : case MODIFY_EXPR:
19134 : 47615 : case NON_LVALUE_EXPR:
19135 : 47615 : return loc_list_from_tree_1 (TREE_OPERAND (loc, 0), want_address,
19136 : 47615 : context);
19137 : :
19138 : 112078 : case COMPONENT_REF:
19139 : 112078 : case BIT_FIELD_REF:
19140 : 112078 : case ARRAY_REF:
19141 : 112078 : case ARRAY_RANGE_REF:
19142 : 112078 : case REALPART_EXPR:
19143 : 112078 : case IMAGPART_EXPR:
19144 : 112078 : {
19145 : 112078 : tree obj, offset;
19146 : 112078 : poly_int64 bitsize, bitpos, bytepos;
19147 : 112078 : machine_mode mode;
19148 : 112078 : int unsignedp, reversep, volatilep = 0;
19149 : :
19150 : 112078 : obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
19151 : : &unsignedp, &reversep, &volatilep);
19152 : :
19153 : 112078 : gcc_assert (obj != loc);
19154 : :
19155 : 224156 : list_ret = loc_list_from_tree_1 (obj,
19156 : : want_address == 2
19157 : 95332 : && known_eq (bitpos, 0)
19158 : 44246 : && !offset ? 2 : 1,
19159 : : context);
19160 : : /* TODO: We can extract value of the small expression via shifting even
19161 : : for nonzero bitpos. */
19162 : 112078 : if (list_ret == 0)
19163 : 79320 : return 0;
19164 : 32834 : if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
19165 : : {
19166 : 0 : expansion_failed (loc, NULL_RTX, "bitfield access");
19167 : 0 : return 0;
19168 : : }
19169 : :
19170 : 32834 : if (offset != NULL_TREE)
19171 : : {
19172 : : /* Variable offset. */
19173 : 76 : list_ret1 = loc_list_from_tree_1 (offset, 0, context);
19174 : 76 : if (list_ret1 == 0)
19175 : : return 0;
19176 : 0 : add_loc_list (&list_ret, list_ret1);
19177 : 0 : if (!list_ret)
19178 : : return 0;
19179 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
19180 : : }
19181 : :
19182 : 32758 : HOST_WIDE_INT value;
19183 : 32758 : if (bytepos.is_constant (&value) && value > 0)
19184 : 24227 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst,
19185 : : value, 0));
19186 : 8531 : else if (maybe_ne (bytepos, 0))
19187 : 0 : loc_list_plus_const (list_ret, bytepos);
19188 : :
19189 : 32758 : have_address = 1;
19190 : 32758 : break;
19191 : : }
19192 : :
19193 : 18240 : case INTEGER_CST:
19194 : 18218 : if ((want_address || !tree_fits_shwi_p (loc))
19195 : 18244 : && (ret = cst_pool_loc_descr (loc)))
19196 : : have_address = 1;
19197 : 18240 : else if (want_address == 2
19198 : 22 : && tree_fits_shwi_p (loc)
19199 : 18262 : && (ret = address_of_int_loc_descriptor
19200 : 22 : (int_size_in_bytes (TREE_TYPE (loc)),
19201 : : tree_to_shwi (loc))))
19202 : : have_address = 1;
19203 : 18218 : else if (tree_fits_shwi_p (loc))
19204 : 18214 : ret = int_loc_descriptor (tree_to_shwi (loc));
19205 : 4 : else if (tree_fits_uhwi_p (loc))
19206 : 4 : ret = uint_loc_descriptor (tree_to_uhwi (loc));
19207 : : else
19208 : : {
19209 : 0 : expansion_failed (loc, NULL_RTX,
19210 : : "Integer operand is not host integer");
19211 : 0 : return 0;
19212 : : }
19213 : : break;
19214 : :
19215 : 0 : case POLY_INT_CST:
19216 : 0 : {
19217 : 0 : if (want_address)
19218 : : {
19219 : 0 : expansion_failed (loc, NULL_RTX,
19220 : : "constant address with a runtime component");
19221 : 0 : return 0;
19222 : : }
19223 : 0 : poly_int64 value;
19224 : 0 : if (!poly_int_tree_p (loc, &value))
19225 : : {
19226 : 0 : expansion_failed (loc, NULL_RTX, "constant too big");
19227 : 0 : return 0;
19228 : : }
19229 : 0 : ret = int_loc_descriptor (value);
19230 : : }
19231 : 0 : break;
19232 : :
19233 : 11706 : case CONSTRUCTOR:
19234 : 11706 : case REAL_CST:
19235 : 11706 : case STRING_CST:
19236 : 11706 : case COMPLEX_CST:
19237 : 11706 : if ((ret = cst_pool_loc_descr (loc)))
19238 : : have_address = 1;
19239 : 867 : else if (TREE_CODE (loc) == CONSTRUCTOR)
19240 : : {
19241 : 25 : tree type = TREE_TYPE (loc);
19242 : 25 : unsigned HOST_WIDE_INT size = int_size_in_bytes (type);
19243 : 25 : unsigned HOST_WIDE_INT offset = 0;
19244 : 25 : unsigned HOST_WIDE_INT cnt;
19245 : 25 : constructor_elt *ce;
19246 : :
19247 : 25 : if (TREE_CODE (type) == RECORD_TYPE)
19248 : : {
19249 : : /* This is very limited, but it's enough to output
19250 : : pointers to member functions, as long as the
19251 : : referenced function is defined in the current
19252 : : translation unit. */
19253 : 69 : FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc), cnt, ce)
19254 : : {
19255 : 47 : tree val = ce->value;
19256 : :
19257 : 47 : tree field = ce->index;
19258 : :
19259 : 47 : if (val)
19260 : 47 : STRIP_NOPS (val);
19261 : :
19262 : 94 : if (!field || DECL_BIT_FIELD (field))
19263 : : {
19264 : 0 : expansion_failed (loc, NULL_RTX,
19265 : : "bitfield in record type constructor");
19266 : 0 : size = offset = (unsigned HOST_WIDE_INT)-1;
19267 : 0 : ret = NULL;
19268 : 0 : break;
19269 : : }
19270 : :
19271 : 47 : HOST_WIDE_INT fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
19272 : 47 : unsigned HOST_WIDE_INT pos = int_byte_position (field);
19273 : 47 : gcc_assert (pos + fieldsize <= size);
19274 : 47 : if (pos < offset)
19275 : : {
19276 : 0 : expansion_failed (loc, NULL_RTX,
19277 : : "out-of-order fields in record constructor");
19278 : 0 : size = offset = (unsigned HOST_WIDE_INT)-1;
19279 : 0 : ret = NULL;
19280 : 0 : break;
19281 : : }
19282 : 47 : if (pos > offset)
19283 : : {
19284 : 0 : ret1 = new_loc_descr (DW_OP_piece, pos - offset, 0);
19285 : 0 : add_loc_descr (&ret, ret1);
19286 : 0 : offset = pos;
19287 : : }
19288 : 47 : if (val && fieldsize != 0)
19289 : : {
19290 : 47 : ret1 = loc_descriptor_from_tree (val, want_address, context);
19291 : 47 : if (!ret1)
19292 : : {
19293 : 3 : expansion_failed (loc, NULL_RTX,
19294 : : "unsupported expression in field");
19295 : 3 : size = offset = (unsigned HOST_WIDE_INT)-1;
19296 : 3 : ret = NULL;
19297 : 3 : break;
19298 : : }
19299 : 44 : add_loc_descr (&ret, ret1);
19300 : : }
19301 : 44 : if (fieldsize)
19302 : : {
19303 : 44 : ret1 = new_loc_descr (DW_OP_piece, fieldsize, 0);
19304 : 44 : add_loc_descr (&ret, ret1);
19305 : 44 : offset = pos + fieldsize;
19306 : : }
19307 : : }
19308 : :
19309 : 25 : if (offset != size)
19310 : : {
19311 : 0 : ret1 = new_loc_descr (DW_OP_piece, size - offset, 0);
19312 : 0 : add_loc_descr (&ret, ret1);
19313 : 0 : offset = size;
19314 : : }
19315 : :
19316 : 25 : have_address = !!want_address;
19317 : : }
19318 : : else
19319 : 0 : expansion_failed (loc, NULL_RTX,
19320 : : "constructor of non-record type");
19321 : : }
19322 : : else
19323 : : /* We can construct small constants here using int_loc_descriptor. */
19324 : 842 : expansion_failed (loc, NULL_RTX,
19325 : : "constructor or constant not in constant pool");
19326 : : break;
19327 : :
19328 : 4 : case TRUTH_AND_EXPR:
19329 : 4 : case TRUTH_ANDIF_EXPR:
19330 : 4 : case BIT_AND_EXPR:
19331 : 4 : op = DW_OP_and;
19332 : 4 : goto do_binop;
19333 : :
19334 : 0 : case TRUTH_XOR_EXPR:
19335 : 0 : case BIT_XOR_EXPR:
19336 : 0 : op = DW_OP_xor;
19337 : 0 : goto do_binop;
19338 : :
19339 : 0 : case TRUTH_OR_EXPR:
19340 : 0 : case TRUTH_ORIF_EXPR:
19341 : 0 : case BIT_IOR_EXPR:
19342 : 0 : op = DW_OP_or;
19343 : 0 : goto do_binop;
19344 : :
19345 : 0 : case EXACT_DIV_EXPR:
19346 : 0 : case FLOOR_DIV_EXPR:
19347 : 0 : case TRUNC_DIV_EXPR:
19348 : : /* Turn a divide by a power of 2 into a shift when possible. */
19349 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc))
19350 : 0 : && tree_fits_uhwi_p (TREE_OPERAND (loc, 1)))
19351 : : {
19352 : 0 : const int log2 = exact_log2 (tree_to_uhwi (TREE_OPERAND (loc, 1)));
19353 : 0 : if (log2 > 0)
19354 : : {
19355 : 0 : list_ret
19356 : 0 : = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19357 : 0 : if (list_ret == 0)
19358 : : return 0;
19359 : :
19360 : 0 : add_loc_descr_to_each (list_ret, uint_loc_descriptor (log2));
19361 : 0 : add_loc_descr_to_each (list_ret,
19362 : : new_loc_descr (DW_OP_shr, 0, 0));
19363 : 0 : break;
19364 : : }
19365 : : }
19366 : :
19367 : : /* fall through */
19368 : :
19369 : 0 : case CEIL_DIV_EXPR:
19370 : 0 : case ROUND_DIV_EXPR:
19371 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
19372 : : {
19373 : 0 : const enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19374 : 0 : scalar_int_mode int_mode;
19375 : :
19376 : 0 : if ((dwarf_strict && dwarf_version < 5)
19377 : 0 : || !is_a <scalar_int_mode> (mode, &int_mode))
19378 : 3397480 : return 0;
19379 : :
19380 : : /* We can use a signed divide if the sign bit is not set. */
19381 : 0 : if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
19382 : : {
19383 : 0 : op = DW_OP_div;
19384 : 0 : goto do_binop;
19385 : : }
19386 : :
19387 : 0 : list_ret = typed_binop_from_tree (DW_OP_div, loc,
19388 : : base_type_for_mode (int_mode, 1),
19389 : : int_mode, context);
19390 : 0 : break;
19391 : : }
19392 : 0 : op = DW_OP_div;
19393 : 0 : goto do_binop;
19394 : :
19395 : 4966 : case MINUS_EXPR:
19396 : 4966 : op = DW_OP_minus;
19397 : 4966 : goto do_binop;
19398 : :
19399 : 0 : case FLOOR_MOD_EXPR:
19400 : 0 : case CEIL_MOD_EXPR:
19401 : 0 : case ROUND_MOD_EXPR:
19402 : 0 : case TRUNC_MOD_EXPR:
19403 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
19404 : : {
19405 : 0 : op = DW_OP_mod;
19406 : 0 : goto do_binop;
19407 : : }
19408 : 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19409 : 0 : list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
19410 : 0 : if (list_ret == 0 || list_ret1 == 0)
19411 : : return 0;
19412 : :
19413 : 0 : add_loc_list (&list_ret, list_ret1);
19414 : 0 : if (list_ret == 0)
19415 : : return 0;
19416 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
19417 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
19418 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
19419 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
19420 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
19421 : 0 : break;
19422 : :
19423 : 23722 : case MULT_EXPR:
19424 : 23722 : op = DW_OP_mul;
19425 : 23722 : goto do_binop;
19426 : :
19427 : 0 : case LSHIFT_EXPR:
19428 : 0 : op = DW_OP_shl;
19429 : 0 : goto do_binop;
19430 : :
19431 : 0 : case RSHIFT_EXPR:
19432 : 0 : op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
19433 : 0 : goto do_binop;
19434 : :
19435 : 84260 : case POINTER_PLUS_EXPR:
19436 : 84260 : case PLUS_EXPR:
19437 : 84260 : do_plus:
19438 : 84260 : if (tree_fits_shwi_p (TREE_OPERAND (loc, 1)))
19439 : : {
19440 : : /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
19441 : : smarter to encode their opposite. The DW_OP_plus_uconst operation
19442 : : takes 1 + X bytes, X being the size of the ULEB128 addend. On the
19443 : : other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
19444 : : bytes, Y being the size of the operation that pushes the opposite
19445 : : of the addend. So let's choose the smallest representation. */
19446 : 73512 : const tree tree_addend = TREE_OPERAND (loc, 1);
19447 : 73512 : offset_int wi_addend;
19448 : 73512 : HOST_WIDE_INT shwi_addend;
19449 : 73512 : dw_loc_descr_ref loc_naddend;
19450 : :
19451 : 73512 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19452 : 73512 : if (list_ret == 0)
19453 : 50 : return 0;
19454 : :
19455 : : /* Try to get the literal to push. It is the opposite of the addend,
19456 : : so as we rely on wrapping during DWARF evaluation, first decode
19457 : : the literal as a "DWARF-sized" signed number. */
19458 : 73462 : wi_addend = wi::to_offset (tree_addend);
19459 : 74198 : wi_addend = wi::sext (wi_addend, DWARF2_ADDR_SIZE * 8);
19460 : 73462 : shwi_addend = wi_addend.to_shwi ();
19461 : 73462 : loc_naddend = (shwi_addend != INTTYPE_MINIMUM (HOST_WIDE_INT))
19462 : 73462 : ? int_loc_descriptor (-shwi_addend)
19463 : : : NULL;
19464 : :
19465 : 0 : if (loc_naddend != NULL
19466 : 146924 : && ((unsigned) size_of_uleb128 (shwi_addend)
19467 : 73462 : > size_of_loc_descr (loc_naddend)))
19468 : : {
19469 : 16 : add_loc_descr_to_each (list_ret, loc_naddend);
19470 : 16 : add_loc_descr_to_each (list_ret,
19471 : : new_loc_descr (DW_OP_minus, 0, 0));
19472 : : }
19473 : : else
19474 : : {
19475 : 146892 : for (dw_loc_descr_ref loc_cur = loc_naddend; loc_cur != NULL; )
19476 : : {
19477 : 73446 : loc_naddend = loc_cur;
19478 : 73446 : loc_cur = loc_cur->dw_loc_next;
19479 : 73446 : ggc_free (loc_naddend);
19480 : : }
19481 : 146892 : loc_list_plus_const (list_ret, wi_addend.to_shwi ());
19482 : : }
19483 : 73462 : break;
19484 : : }
19485 : :
19486 : 10748 : op = DW_OP_plus;
19487 : 10748 : goto do_binop;
19488 : :
19489 : 0 : case LE_EXPR:
19490 : 0 : op = DW_OP_le;
19491 : 0 : goto do_comp_binop;
19492 : :
19493 : 0 : case GE_EXPR:
19494 : 0 : op = DW_OP_ge;
19495 : 0 : goto do_comp_binop;
19496 : :
19497 : 0 : case LT_EXPR:
19498 : 0 : op = DW_OP_lt;
19499 : 0 : goto do_comp_binop;
19500 : :
19501 : 0 : case GT_EXPR:
19502 : 0 : op = DW_OP_gt;
19503 : 0 : goto do_comp_binop;
19504 : :
19505 : 0 : do_comp_binop:
19506 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
19507 : : {
19508 : 0 : const enum machine_mode mode
19509 : 0 : = TYPE_MODE (TREE_TYPE (TREE_OPERAND (loc, 0)));
19510 : 0 : scalar_int_mode int_mode;
19511 : :
19512 : : /* We can use a signed comparison if the sign bit is not set. */
19513 : 0 : if (is_a <scalar_int_mode> (mode, &int_mode)
19514 : 0 : && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
19515 : 0 : goto do_binop;
19516 : :
19517 : 0 : list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
19518 : 0 : list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
19519 : 0 : list_ret = loc_list_from_uint_comparison (list_ret, list_ret1,
19520 : 0 : TREE_CODE (loc));
19521 : 0 : break;
19522 : : }
19523 : : else
19524 : 0 : goto do_binop;
19525 : :
19526 : 0 : case EQ_EXPR:
19527 : 0 : op = DW_OP_eq;
19528 : 0 : goto do_binop;
19529 : :
19530 : 7404 : case NE_EXPR:
19531 : 7404 : op = DW_OP_ne;
19532 : 7404 : goto do_binop;
19533 : :
19534 : 46844 : do_binop:
19535 : 46844 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19536 : 46844 : list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
19537 : 46844 : if (list_ret == 0 || list_ret1 == 0)
19538 : : return 0;
19539 : :
19540 : 46714 : add_loc_list (&list_ret, list_ret1);
19541 : 46714 : if (list_ret == 0)
19542 : : return 0;
19543 : :
19544 : 46714 : add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
19545 : 46714 : break;
19546 : :
19547 : 0 : case TRUTH_NOT_EXPR:
19548 : 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19549 : 0 : if (list_ret == 0)
19550 : : return 0;
19551 : :
19552 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_lit0, 0, 0));
19553 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_eq, 0, 0));
19554 : 0 : break;
19555 : :
19556 : 0 : case BIT_NOT_EXPR:
19557 : 0 : op = DW_OP_not;
19558 : 0 : goto do_unop;
19559 : :
19560 : 0 : case ABS_EXPR:
19561 : 0 : op = DW_OP_abs;
19562 : 0 : goto do_unop;
19563 : :
19564 : 0 : case NEGATE_EXPR:
19565 : 0 : op = DW_OP_neg;
19566 : 0 : goto do_unop;
19567 : :
19568 : 0 : do_unop:
19569 : 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19570 : 0 : if (list_ret == 0)
19571 : : return 0;
19572 : :
19573 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
19574 : 0 : break;
19575 : :
19576 : 0 : case MIN_EXPR:
19577 : 0 : case MAX_EXPR:
19578 : 0 : {
19579 : 0 : const enum tree_code code =
19580 : 0 : TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
19581 : :
19582 : 0 : loc = build3 (COND_EXPR, TREE_TYPE (loc),
19583 : : build2 (code, integer_type_node,
19584 : 0 : TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
19585 : 0 : TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
19586 : : }
19587 : :
19588 : : /* fall through */
19589 : :
19590 : 0 : case COND_EXPR:
19591 : 0 : {
19592 : 0 : dw_loc_descr_ref lhs
19593 : 0 : = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0, context);
19594 : 0 : dw_loc_list_ref rhs
19595 : 0 : = loc_list_from_tree_1 (TREE_OPERAND (loc, 2), 0, context);
19596 : 0 : dw_loc_descr_ref bra_node, jump_node, tmp;
19597 : :
19598 : : /* DW_OP_bra is branch-on-nonzero so avoid doing useless work. */
19599 : 0 : if (TREE_CODE (TREE_OPERAND (loc, 0)) == NE_EXPR
19600 : 0 : && integer_zerop (TREE_OPERAND (TREE_OPERAND (loc, 0), 1)))
19601 : 0 : list_ret
19602 : 0 : = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0),
19603 : : 0, context);
19604 : : /* Likewise, swap the operands for a logically negated condition. */
19605 : 0 : else if (TREE_CODE (TREE_OPERAND (loc, 0)) == TRUTH_NOT_EXPR)
19606 : : {
19607 : 0 : lhs = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0, context);
19608 : 0 : rhs = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
19609 : 0 : list_ret
19610 : 0 : = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0),
19611 : : 0, context);
19612 : : }
19613 : : else
19614 : 0 : list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
19615 : 0 : if (list_ret == 0 || lhs == 0 || rhs == 0)
19616 : : return 0;
19617 : :
19618 : 0 : bra_node = new_loc_descr (DW_OP_bra, 0, 0);
19619 : 0 : add_loc_descr_to_each (list_ret, bra_node);
19620 : :
19621 : 0 : add_loc_list (&list_ret, rhs);
19622 : 0 : jump_node = new_loc_descr (DW_OP_skip, 0, 0);
19623 : 0 : add_loc_descr_to_each (list_ret, jump_node);
19624 : :
19625 : 0 : add_loc_descr_to_each (list_ret, lhs);
19626 : 0 : bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
19627 : 0 : bra_node->dw_loc_oprnd1.v.val_loc = lhs;
19628 : :
19629 : : /* ??? Need a node to point the skip at. Use a nop. */
19630 : 0 : tmp = new_loc_descr (DW_OP_nop, 0, 0);
19631 : 0 : add_loc_descr_to_each (list_ret, tmp);
19632 : 0 : jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
19633 : 0 : jump_node->dw_loc_oprnd1.v.val_loc = tmp;
19634 : : }
19635 : 0 : break;
19636 : :
19637 : : case FIX_TRUNC_EXPR:
19638 : : return 0;
19639 : :
19640 : 0 : case COMPOUND_LITERAL_EXPR:
19641 : 0 : return loc_list_from_tree_1 (COMPOUND_LITERAL_EXPR_DECL (loc),
19642 : 0 : 0, context);
19643 : :
19644 : 0 : default:
19645 : : /* Leave front-end specific codes as simply unknown. This comes
19646 : : up, for instance, with the C STMT_EXPR. */
19647 : 0 : if ((unsigned int) TREE_CODE (loc)
19648 : : >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
19649 : : {
19650 : 0 : expansion_failed (loc, NULL_RTX,
19651 : : "language specific tree node");
19652 : 0 : return 0;
19653 : : }
19654 : :
19655 : : /* Otherwise this is a generic code; we should just lists all of
19656 : : these explicitly. We forgot one. */
19657 : 0 : if (flag_checking)
19658 : 0 : gcc_unreachable ();
19659 : :
19660 : : /* In a release build, we want to degrade gracefully: better to
19661 : : generate incomplete debugging information than to crash. */
19662 : : return NULL;
19663 : : }
19664 : :
19665 : 14138476 : if (!ret && !list_ret)
19666 : : return 0;
19667 : :
19668 : : /* Implement wrap-around arithmetics for small integer types. */
19669 : 13138128 : if ((TREE_CODE (loc) == PLUS_EXPR
19670 : : || TREE_CODE (loc) == MINUS_EXPR
19671 : 13138128 : || TREE_CODE (loc) == MULT_EXPR
19672 : : || TREE_CODE (loc) == NEGATE_EXPR
19673 : : || TREE_CODE (loc) == LSHIFT_EXPR)
19674 : 39340 : && INTEGRAL_TYPE_P (TREE_TYPE (loc))
19675 : 39340 : && TYPE_OVERFLOW_WRAPS (TREE_TYPE (loc)))
19676 : : {
19677 : 11552 : const enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19678 : 11552 : scalar_int_mode int_mode;
19679 : :
19680 : 11552 : if (is_a <scalar_int_mode> (mode, &int_mode)
19681 : 12416 : && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
19682 : : {
19683 : 0 : const unsigned HOST_WIDE_INT mask
19684 : 0 : = (HOST_WIDE_INT_1U << GET_MODE_BITSIZE (int_mode)) - 1;
19685 : 0 : add_loc_descr_to_each (list_ret, uint_loc_descriptor (mask));
19686 : 0 : add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_and, 0, 0));
19687 : : }
19688 : : }
19689 : :
19690 : 13138128 : if (want_address == 2 && !have_address
19691 : 20101 : && (dwarf_version >= 4 || !dwarf_strict))
19692 : : {
19693 : 20256 : if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
19694 : : {
19695 : 0 : expansion_failed (loc, NULL_RTX,
19696 : : "DWARF address size mismatch");
19697 : 0 : return 0;
19698 : : }
19699 : 20101 : if (ret)
19700 : 9774 : add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
19701 : : else
19702 : 15214 : add_loc_descr_to_each (list_ret,
19703 : : new_loc_descr (DW_OP_stack_value, 0, 0));
19704 : : have_address = 1;
19705 : : }
19706 : : /* Show if we can't fill the request for an address. */
19707 : 13138128 : if (want_address && !have_address)
19708 : : {
19709 : 18 : expansion_failed (loc, NULL_RTX,
19710 : : "Want address and only have value");
19711 : 18 : return 0;
19712 : : }
19713 : :
19714 : 13138110 : gcc_assert (!ret || !list_ret);
19715 : :
19716 : : /* If we've got an address and don't want one, dereference. */
19717 : 13138110 : if (!want_address && have_address)
19718 : : {
19719 : 112384 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
19720 : 112384 : enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
19721 : 112384 : scalar_int_mode int_mode;
19722 : 112384 : dw_die_ref type_die;
19723 : 112384 : dw_loc_descr_ref deref;
19724 : :
19725 : : /* Bail out if the size is variable or greater than DWARF2_ADDR_SIZE. */
19726 : 119325 : if (size < 0 || size > DWARF2_ADDR_SIZE)
19727 : : {
19728 : 134 : expansion_failed (loc, NULL_RTX, "DWARF address size mismatch");
19729 : 134 : return 0;
19730 : : }
19731 : :
19732 : : /* If it is equal to DWARF2_ADDR_SIZE, extension does not matter. */
19733 : 119134 : else if (size == DWARF2_ADDR_SIZE)
19734 : 111262 : deref = new_loc_descr (DW_OP_deref, size, 0);
19735 : :
19736 : : /* If it is lower than DWARF2_ADDR_SIZE, DW_OP_deref_size will zero-
19737 : : extend the value, which is really OK for unsigned types only. */
19738 : 960 : else if (!(context && context->strict_signedness)
19739 : 0 : || TYPE_UNSIGNED (TREE_TYPE (loc))
19740 : 0 : || (dwarf_strict && dwarf_version < 5)
19741 : 988 : || !is_a <scalar_int_mode> (mode, &int_mode)
19742 : 988 : || !(type_die = base_type_for_mode (mode, false)))
19743 : 988 : deref = new_loc_descr (DW_OP_deref_size, size, 0);
19744 : :
19745 : : /* Use DW_OP_deref_type for signed integral types if possible, but
19746 : : convert back to the generic type to avoid type mismatches later. */
19747 : : else
19748 : : {
19749 : 0 : deref = new_loc_descr (dwarf_OP (DW_OP_deref_type), size, 0);
19750 : 0 : deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
19751 : 0 : deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
19752 : 0 : deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
19753 : 0 : add_loc_descr (&deref,
19754 : : new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0));
19755 : : }
19756 : :
19757 : : /* Deal with bit-fields whose size is not a multiple of a byte. */
19758 : 112250 : if (TREE_CODE (loc) == COMPONENT_REF
19759 : 112250 : && DECL_BIT_FIELD (TREE_OPERAND (loc, 1)))
19760 : : {
19761 : 0 : const unsigned HOST_WIDE_INT bitsize
19762 : 0 : = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (loc, 1)));
19763 : 0 : if (bitsize < (unsigned HOST_WIDE_INT)size * BITS_PER_UNIT)
19764 : : {
19765 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (loc)))
19766 : : {
19767 : 0 : if (BYTES_BIG_ENDIAN)
19768 : : {
19769 : : const unsigned HOST_WIDE_INT shift
19770 : : = size * BITS_PER_UNIT - bitsize;
19771 : : add_loc_descr (&deref, uint_loc_descriptor (shift));
19772 : : add_loc_descr (&deref, new_loc_descr (DW_OP_shr, 0, 0));
19773 : : }
19774 : : else
19775 : : {
19776 : 0 : const unsigned HOST_WIDE_INT mask
19777 : 0 : = (HOST_WIDE_INT_1U << bitsize) - 1;
19778 : 0 : add_loc_descr (&deref, uint_loc_descriptor (mask));
19779 : 0 : add_loc_descr (&deref, new_loc_descr (DW_OP_and, 0, 0));
19780 : : }
19781 : : }
19782 : : else
19783 : : {
19784 : 0 : const unsigned HOST_WIDE_INT shiftr
19785 : 0 : = DWARF2_ADDR_SIZE * BITS_PER_UNIT - bitsize;
19786 : 0 : const unsigned HOST_WIDE_INT shiftl
19787 : : = BYTES_BIG_ENDIAN
19788 : : ? (DWARF2_ADDR_SIZE - size) * BITS_PER_UNIT
19789 : : : shiftr;
19790 : 0 : if (shiftl > 0)
19791 : : {
19792 : 0 : add_loc_descr (&deref, uint_loc_descriptor (shiftl));
19793 : 0 : add_loc_descr (&deref, new_loc_descr (DW_OP_shl, 0, 0));
19794 : : }
19795 : 0 : add_loc_descr (&deref, uint_loc_descriptor (shiftr));
19796 : 0 : add_loc_descr (&deref, new_loc_descr (DW_OP_shra, 0, 0));
19797 : : }
19798 : : }
19799 : : }
19800 : :
19801 : 112250 : if (ret)
19802 : 2484 : add_loc_descr (&ret, deref);
19803 : : else
19804 : 111008 : add_loc_descr_to_each (list_ret, deref);
19805 : : }
19806 : :
19807 : 13137976 : if (ret)
19808 : 702881 : list_ret = new_loc_list (ret, NULL, 0, NULL, 0, NULL);
19809 : :
19810 : 13137976 : return list_ret;
19811 : : }
19812 : :
19813 : : /* Likewise, but strip useless DW_OP_nop operations in the resulting
19814 : : expressions. */
19815 : :
19816 : : static dw_loc_list_ref
19817 : 16111153 : loc_list_from_tree (tree loc, int want_address,
19818 : : struct loc_descr_context *context)
19819 : : {
19820 : 16111153 : dw_loc_list_ref result = loc_list_from_tree_1 (loc, want_address, context);
19821 : :
19822 : 16111153 : for (dw_loc_list_ref loc_cur = result;
19823 : 41744481 : loc_cur != NULL; loc_cur = loc_cur->dw_loc_next)
19824 : 25633328 : loc_descr_without_nops (loc_cur->expr);
19825 : 16111153 : return result;
19826 : : }
19827 : :
19828 : : /* Same as above but return only single location expression. */
19829 : : static dw_loc_descr_ref
19830 : 131 : loc_descriptor_from_tree (tree loc, int want_address,
19831 : : struct loc_descr_context *context)
19832 : : {
19833 : 131 : dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
19834 : 131 : if (!ret)
19835 : : return NULL;
19836 : 123 : if (ret->dw_loc_next)
19837 : : {
19838 : 0 : expansion_failed (loc, NULL_RTX,
19839 : : "Location list where only loc descriptor needed");
19840 : 0 : return NULL;
19841 : : }
19842 : 123 : return ret->expr;
19843 : : }
19844 : :
19845 : : /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
19846 : : pointer to the declared type for the relevant field variable, or return
19847 : : `integer_type_node' if the given node turns out to be an
19848 : : ERROR_MARK node. */
19849 : :
19850 : : static inline tree
19851 : 810379 : field_type (const_tree decl)
19852 : : {
19853 : 810379 : tree type;
19854 : :
19855 : 810379 : if (TREE_CODE (decl) == ERROR_MARK)
19856 : 0 : return integer_type_node;
19857 : :
19858 : 810379 : type = DECL_BIT_FIELD_TYPE (decl);
19859 : 810379 : if (type == NULL_TREE)
19860 : 0 : type = TREE_TYPE (decl);
19861 : :
19862 : : return type;
19863 : : }
19864 : :
19865 : : /* Given a pointer to a tree node, return the alignment in bits for
19866 : : it, or else return BITS_PER_WORD if the node actually turns out to
19867 : : be an ERROR_MARK node. */
19868 : :
19869 : : static inline unsigned
19870 : 540238 : simple_type_align_in_bits (const_tree type)
19871 : : {
19872 : 540238 : return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
19873 : : }
19874 : :
19875 : : static inline unsigned
19876 : 540238 : simple_decl_align_in_bits (const_tree decl)
19877 : : {
19878 : 540238 : return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
19879 : : }
19880 : :
19881 : : /* Return the result of rounding T up to ALIGN. */
19882 : :
19883 : : static inline offset_int
19884 : 540306 : round_up_to_align (const offset_int &t, unsigned int align)
19885 : : {
19886 : 540306 : return wi::udiv_trunc (t + align - 1, align) * align;
19887 : : }
19888 : :
19889 : : /* Helper structure for RECORD_TYPE processing. */
19890 : : struct vlr_context
19891 : : {
19892 : : /* Root RECORD_TYPE. It is needed to generate data member location
19893 : : descriptions in variable-length records (VLR), but also to cope with
19894 : : variants, which are composed of nested structures multiplexed with
19895 : : QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
19896 : : function processing a FIELD_DECL, it is required to be non null. */
19897 : : tree struct_type;
19898 : :
19899 : : /* When generating a variant part in a RECORD_TYPE (i.e. a nested
19900 : : QUAL_UNION_TYPE), this holds an expression that computes the offset for
19901 : : this variant part as part of the root record (in storage units). For
19902 : : regular records, it must be NULL_TREE. */
19903 : : tree variant_part_offset;
19904 : : };
19905 : :
19906 : : /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
19907 : : addressed byte of the "containing object" for the given FIELD_DECL. If
19908 : : possible, return a native constant through CST_OFFSET (in which case NULL is
19909 : : returned); otherwise return a DWARF expression that computes the offset.
19910 : :
19911 : : Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
19912 : : that offset is, either because the argument turns out to be a pointer to an
19913 : : ERROR_MARK node, or because the offset expression is too complex for us.
19914 : :
19915 : : CTX is required: see the comment for VLR_CONTEXT. */
19916 : :
19917 : : static dw_loc_descr_ref
19918 : 12989793 : field_byte_offset (const_tree decl, struct vlr_context *ctx,
19919 : : HOST_WIDE_INT *cst_offset)
19920 : : {
19921 : 12989793 : tree tree_result;
19922 : 12989793 : dw_loc_list_ref loc_result;
19923 : :
19924 : 12989793 : *cst_offset = 0;
19925 : :
19926 : 12989793 : if (TREE_CODE (decl) == ERROR_MARK)
19927 : : return NULL;
19928 : : else
19929 : 12989793 : gcc_assert (TREE_CODE (decl) == FIELD_DECL);
19930 : :
19931 : : /* We cannot handle variable bit offsets at the moment, so abort if it's the
19932 : : case. */
19933 : 12989793 : if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl)) != INTEGER_CST)
19934 : : return NULL;
19935 : :
19936 : : /* We used to handle only constant offsets in all cases. Now, we handle
19937 : : properly dynamic byte offsets only when PCC bitfield type doesn't
19938 : : matter. */
19939 : 12989793 : if (PCC_BITFIELD_TYPE_MATTERS
19940 : 12989793 : && DECL_BIT_FIELD_TYPE (decl)
19941 : 12989793 : && TREE_CODE (DECL_FIELD_OFFSET (decl)) == INTEGER_CST)
19942 : : {
19943 : 540238 : offset_int object_offset_in_bits;
19944 : 540238 : offset_int object_offset_in_bytes;
19945 : 540238 : offset_int bitpos_int;
19946 : 540238 : tree type;
19947 : 540238 : tree field_size_tree;
19948 : 540238 : offset_int deepest_bitpos;
19949 : 540238 : offset_int field_size_in_bits;
19950 : 540238 : unsigned int type_align_in_bits;
19951 : 540238 : unsigned int decl_align_in_bits;
19952 : 540238 : offset_int type_size_in_bits;
19953 : :
19954 : 540238 : bitpos_int = wi::to_offset (bit_position (decl));
19955 : 540238 : type = field_type (decl);
19956 : 540238 : type_size_in_bits = offset_int_type_size_in_bits (type);
19957 : 540238 : type_align_in_bits = simple_type_align_in_bits (type);
19958 : :
19959 : 540238 : field_size_tree = DECL_SIZE (decl);
19960 : :
19961 : : /* The size could be unspecified if there was an error, or for
19962 : : a flexible array member. */
19963 : 540238 : if (!field_size_tree)
19964 : 0 : field_size_tree = bitsize_zero_node;
19965 : :
19966 : : /* If the size of the field is not constant, use the type size. */
19967 : 540238 : if (TREE_CODE (field_size_tree) == INTEGER_CST)
19968 : 540238 : field_size_in_bits = wi::to_offset (field_size_tree);
19969 : : else
19970 : 0 : field_size_in_bits = type_size_in_bits;
19971 : :
19972 : 540238 : decl_align_in_bits = simple_decl_align_in_bits (decl);
19973 : :
19974 : : /* The GCC front-end doesn't make any attempt to keep track of the
19975 : : starting bit offset (relative to the start of the containing
19976 : : structure type) of the hypothetical "containing object" for a
19977 : : bit-field. Thus, when computing the byte offset value for the
19978 : : start of the "containing object" of a bit-field, we must deduce
19979 : : this information on our own. This can be rather tricky to do in
19980 : : some cases. For example, handling the following structure type
19981 : : definition when compiling for an i386/i486 target (which only
19982 : : aligns long long's to 32-bit boundaries) can be very tricky:
19983 : :
19984 : : struct S { int field1; long long field2:31; };
19985 : :
19986 : : Fortunately, there is a simple rule-of-thumb which can be used
19987 : : in such cases. When compiling for an i386/i486, GCC will
19988 : : allocate 8 bytes for the structure shown above. It decides to
19989 : : do this based upon one simple rule for bit-field allocation.
19990 : : GCC allocates each "containing object" for each bit-field at
19991 : : the first (i.e. lowest addressed) legitimate alignment boundary
19992 : : (based upon the required minimum alignment for the declared
19993 : : type of the field) which it can possibly use, subject to the
19994 : : condition that there is still enough available space remaining
19995 : : in the containing object (when allocated at the selected point)
19996 : : to fully accommodate all of the bits of the bit-field itself.
19997 : :
19998 : : This simple rule makes it obvious why GCC allocates 8 bytes for
19999 : : each object of the structure type shown above. When looking
20000 : : for a place to allocate the "containing object" for `field2',
20001 : : the compiler simply tries to allocate a 64-bit "containing
20002 : : object" at each successive 32-bit boundary (starting at zero)
20003 : : until it finds a place to allocate that 64- bit field such that
20004 : : at least 31 contiguous (and previously unallocated) bits remain
20005 : : within that selected 64 bit field. (As it turns out, for the
20006 : : example above, the compiler finds it is OK to allocate the
20007 : : "containing object" 64-bit field at bit-offset zero within the
20008 : : structure type.)
20009 : :
20010 : : Here we attempt to work backwards from the limited set of facts
20011 : : we're given, and we try to deduce from those facts, where GCC
20012 : : must have believed that the containing object started (within
20013 : : the structure type). The value we deduce is then used (by the
20014 : : callers of this routine) to generate DW_AT_location and
20015 : : DW_AT_bit_offset attributes for fields (both bit-fields and, in
20016 : : the case of DW_AT_location, regular fields as well). */
20017 : :
20018 : : /* Figure out the bit-distance from the start of the structure to
20019 : : the "deepest" bit of the bit-field. */
20020 : 540238 : deepest_bitpos = bitpos_int + field_size_in_bits;
20021 : :
20022 : : /* This is the tricky part. Use some fancy footwork to deduce
20023 : : where the lowest addressed bit of the containing object must
20024 : : be. */
20025 : 540238 : object_offset_in_bits = deepest_bitpos - type_size_in_bits;
20026 : :
20027 : : /* Round up to type_align by default. This works best for
20028 : : bitfields. */
20029 : 540238 : object_offset_in_bits
20030 : 540238 : = round_up_to_align (object_offset_in_bits, type_align_in_bits);
20031 : :
20032 : 540238 : if (wi::gtu_p (object_offset_in_bits, bitpos_int))
20033 : : {
20034 : 68 : object_offset_in_bits = deepest_bitpos - type_size_in_bits;
20035 : :
20036 : : /* Round up to decl_align instead. */
20037 : 68 : object_offset_in_bits
20038 : 68 : = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
20039 : : }
20040 : :
20041 : 540238 : object_offset_in_bytes
20042 : 540238 : = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
20043 : 540238 : if (ctx->variant_part_offset == NULL_TREE)
20044 : : {
20045 : 540238 : *cst_offset = object_offset_in_bytes.to_shwi ();
20046 : 540238 : return NULL;
20047 : : }
20048 : 0 : tree_result = wide_int_to_tree (sizetype, object_offset_in_bytes);
20049 : : }
20050 : : else
20051 : 12449555 : tree_result = byte_position (decl);
20052 : :
20053 : 12449555 : if (ctx->variant_part_offset != NULL_TREE)
20054 : 0 : tree_result = fold_build2 (PLUS_EXPR, TREE_TYPE (tree_result),
20055 : : ctx->variant_part_offset, tree_result);
20056 : :
20057 : : /* If the byte offset is a constant, it's simplier to handle a native
20058 : : constant rather than a DWARF expression. */
20059 : 12449555 : if (TREE_CODE (tree_result) == INTEGER_CST)
20060 : : {
20061 : 12449515 : *cst_offset = wi::to_offset (tree_result).to_shwi ();
20062 : 12449515 : return NULL;
20063 : : }
20064 : :
20065 : 40 : struct loc_descr_context loc_ctx = {
20066 : 40 : ctx->struct_type, /* context_type */
20067 : : NULL_TREE, /* base_decl */
20068 : : NULL, /* dpi */
20069 : : false, /* placeholder_arg */
20070 : : false, /* placeholder_seen */
20071 : : false /* strict_signedness */
20072 : 40 : };
20073 : 40 : loc_result = loc_list_from_tree (tree_result, 0, &loc_ctx);
20074 : :
20075 : : /* We want a DWARF expression: abort if we only have a location list with
20076 : : multiple elements. */
20077 : 40 : if (!loc_result || !single_element_loc_list_p (loc_result))
20078 : : return NULL;
20079 : : else
20080 : 40 : return loc_result->expr;
20081 : : }
20082 : :
20083 : : /* The following routines define various Dwarf attributes and any data
20084 : : associated with them. */
20085 : :
20086 : : /* Add a location description attribute value to a DIE.
20087 : :
20088 : : This emits location attributes suitable for whole variables and
20089 : : whole parameters. Note that the location attributes for struct fields are
20090 : : generated by the routine `data_member_location_attribute' below. */
20091 : :
20092 : : static inline void
20093 : 12800423 : add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
20094 : : dw_loc_list_ref descr)
20095 : : {
20096 : 12800423 : bool check_no_locviews = true;
20097 : 12800423 : if (descr == 0)
20098 : : return;
20099 : 12800289 : if (single_element_loc_list_p (descr))
20100 : 1011802 : add_AT_loc (die, attr_kind, descr->expr);
20101 : : else
20102 : : {
20103 : 11788487 : add_AT_loc_list (die, attr_kind, descr);
20104 : 11788487 : gcc_assert (descr->ll_symbol);
20105 : 11787649 : if (attr_kind == DW_AT_location && descr->vl_symbol
20106 : 23403958 : && dwarf2out_locviews_in_attribute ())
20107 : : {
20108 : 11615471 : add_AT_view_list (die, DW_AT_GNU_locviews);
20109 : 11615471 : check_no_locviews = false;
20110 : : }
20111 : : }
20112 : :
20113 : 12627273 : if (check_no_locviews)
20114 : 1184818 : gcc_assert (!get_AT (die, DW_AT_GNU_locviews));
20115 : : }
20116 : :
20117 : : /* Add DW_AT_accessibility attribute to DIE if needed. */
20118 : :
20119 : : static void
20120 : 182585593 : add_accessibility_attribute (dw_die_ref die, tree decl)
20121 : : {
20122 : : /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20123 : : children, otherwise the default is DW_ACCESS_public. In DWARF2
20124 : : the default has always been DW_ACCESS_public. */
20125 : 182585593 : if (TREE_PROTECTED (decl))
20126 : 4143026 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20127 : 178442567 : else if (TREE_PRIVATE (decl))
20128 : : {
20129 : 13358837 : if (dwarf_version == 2
20130 : 13358690 : || die->die_parent == NULL
20131 : 13358690 : || die->die_parent->die_tag != DW_TAG_class_type)
20132 : 1716649 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20133 : : }
20134 : 165083730 : else if (dwarf_version > 2
20135 : 165040591 : && die->die_parent
20136 : 164914794 : && die->die_parent->die_tag == DW_TAG_class_type)
20137 : 51146268 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20138 : 182585593 : }
20139 : :
20140 : : /* Attach the specialized form of location attribute used for data members of
20141 : : struct and union types. In the special case of a FIELD_DECL node which
20142 : : represents a bit-field, the "offset" part of this special location
20143 : : descriptor must indicate the distance in bytes from the lowest-addressed
20144 : : byte of the containing struct or union type to the lowest-addressed byte of
20145 : : the "containing object" for the bit-field. (See the `field_byte_offset'
20146 : : function above).
20147 : :
20148 : : For any given bit-field, the "containing object" is a hypothetical object
20149 : : (of some integral or enum type) within which the given bit-field lives. The
20150 : : type of this hypothetical "containing object" is always the same as the
20151 : : declared type of the individual bit-field itself (for GCC anyway... the
20152 : : DWARF spec doesn't actually mandate this). Note that it is the size (in
20153 : : bytes) of the hypothetical "containing object" which will be given in the
20154 : : DW_AT_byte_size attribute for this bit-field. (See the
20155 : : `byte_size_attribute' function below.) It is also used when calculating the
20156 : : value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
20157 : : function below.)
20158 : :
20159 : : CTX is required: see the comment for VLR_CONTEXT. */
20160 : :
20161 : : static void
20162 : 29889397 : add_data_member_location_attribute (dw_die_ref die,
20163 : : tree decl,
20164 : : struct vlr_context *ctx)
20165 : : {
20166 : 29889397 : HOST_WIDE_INT offset;
20167 : 29889397 : dw_loc_descr_ref loc_descr = 0;
20168 : :
20169 : 29889397 : if (TREE_CODE (decl) == TREE_BINFO)
20170 : : {
20171 : : /* We're working on the TAG_inheritance for a base class. */
20172 : 17169745 : if (BINFO_VIRTUAL_P (decl) && is_cxx ())
20173 : : {
20174 : : /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
20175 : : aren't at a fixed offset from all (sub)objects of the same
20176 : : type. We need to extract the appropriate offset from our
20177 : : vtable. The following dwarf expression means
20178 : :
20179 : : BaseAddr = ObAddr + *((*ObAddr) - Offset)
20180 : :
20181 : : This is specific to the V3 ABI, of course. */
20182 : :
20183 : 294 : dw_loc_descr_ref tmp;
20184 : :
20185 : : /* Make a copy of the object address. */
20186 : 294 : tmp = new_loc_descr (DW_OP_dup, 0, 0);
20187 : 294 : add_loc_descr (&loc_descr, tmp);
20188 : :
20189 : : /* Extract the vtable address. */
20190 : 294 : tmp = new_loc_descr (DW_OP_deref, 0, 0);
20191 : 294 : add_loc_descr (&loc_descr, tmp);
20192 : :
20193 : : /* Calculate the address of the offset. */
20194 : 294 : offset = tree_to_shwi (BINFO_VPTR_FIELD (decl));
20195 : 294 : gcc_assert (offset < 0);
20196 : :
20197 : 294 : tmp = int_loc_descriptor (-offset);
20198 : 294 : add_loc_descr (&loc_descr, tmp);
20199 : 294 : tmp = new_loc_descr (DW_OP_minus, 0, 0);
20200 : 294 : add_loc_descr (&loc_descr, tmp);
20201 : :
20202 : : /* Extract the offset. */
20203 : 294 : tmp = new_loc_descr (DW_OP_deref, 0, 0);
20204 : 294 : add_loc_descr (&loc_descr, tmp);
20205 : :
20206 : : /* Add it to the object address. */
20207 : 294 : tmp = new_loc_descr (DW_OP_plus, 0, 0);
20208 : 588 : add_loc_descr (&loc_descr, tmp);
20209 : : }
20210 : : else
20211 : 17169451 : offset = tree_to_shwi (BINFO_OFFSET (decl));
20212 : : }
20213 : : else
20214 : : {
20215 : 12719652 : loc_descr = field_byte_offset (decl, ctx, &offset);
20216 : :
20217 : 12719652 : if (!loc_descr)
20218 : : ;
20219 : :
20220 : : /* If loc_descr is available, then we know the offset is dynamic. */
20221 : 24 : else if (gnat_encodings == DWARF_GNAT_ENCODINGS_ALL)
20222 : : {
20223 : 0 : loc_descr = NULL;
20224 : 0 : offset = 0;
20225 : : }
20226 : :
20227 : : /* Data member location evaluation starts with the base address on the
20228 : : stack. Compute the field offset and add it to this base address. */
20229 : : else
20230 : 48 : add_loc_descr (&loc_descr, new_loc_descr (DW_OP_plus, 0, 0));
20231 : : }
20232 : :
20233 : 29889397 : if (!loc_descr)
20234 : : {
20235 : : /* While DW_AT_data_bit_offset has been added already in DWARF4,
20236 : : e.g. GDB only added support to it in November 2016. For DWARF5
20237 : : we need newer debug info consumers anyway. We might change this
20238 : : to dwarf_version >= 4 once most consumers catched up. */
20239 : 29889079 : if (dwarf_version >= 5
20240 : 29877346 : && TREE_CODE (decl) == FIELD_DECL
20241 : 12708347 : && DECL_BIT_FIELD_TYPE (decl)
20242 : 30159124 : && (ctx->variant_part_offset == NULL_TREE
20243 : 0 : || TREE_CODE (ctx->variant_part_offset) == INTEGER_CST))
20244 : : {
20245 : 270045 : tree off = bit_position (decl);
20246 : 270045 : if (ctx->variant_part_offset)
20247 : 0 : off = bit_from_pos (ctx->variant_part_offset, off);
20248 : 270045 : if (tree_fits_uhwi_p (off) && get_AT (die, DW_AT_bit_size))
20249 : : {
20250 : 270045 : remove_AT (die, DW_AT_byte_size);
20251 : 270045 : remove_AT (die, DW_AT_bit_offset);
20252 : 270045 : add_AT_unsigned (die, DW_AT_data_bit_offset, tree_to_uhwi (off));
20253 : 29877468 : return;
20254 : : }
20255 : : }
20256 : 29619034 : if (dwarf_version > 2)
20257 : : {
20258 : : /* Don't need to output a location expression, just the constant. */
20259 : 29607423 : if (offset < 0)
20260 : 0 : add_AT_int (die, DW_AT_data_member_location, offset);
20261 : : else
20262 : 29607423 : add_AT_unsigned (die, DW_AT_data_member_location, offset);
20263 : 29607423 : return;
20264 : : }
20265 : : else
20266 : : {
20267 : 11611 : enum dwarf_location_atom op;
20268 : :
20269 : : /* The DWARF2 standard says that we should assume that the structure
20270 : : address is already on the stack, so we can specify a structure
20271 : : field address by using DW_OP_plus_uconst. */
20272 : 11611 : op = DW_OP_plus_uconst;
20273 : 11611 : loc_descr = new_loc_descr (op, offset, 0);
20274 : : }
20275 : : }
20276 : :
20277 : 11929 : add_AT_loc (die, DW_AT_data_member_location, loc_descr);
20278 : : }
20279 : :
20280 : : /* Writes integer values to dw_vec_const array. */
20281 : :
20282 : : static void
20283 : 215443 : insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
20284 : : {
20285 : 1075315 : while (size != 0)
20286 : : {
20287 : 859872 : *dest++ = val & 0xff;
20288 : 859872 : val >>= 8;
20289 : 859872 : --size;
20290 : : }
20291 : 0 : }
20292 : :
20293 : : /* Reads integers from dw_vec_const array. Inverse of insert_int. */
20294 : :
20295 : : static HOST_WIDE_INT
20296 : 4507667 : extract_int (const unsigned char *src, unsigned int size)
20297 : : {
20298 : 4507667 : HOST_WIDE_INT val = 0;
20299 : :
20300 : 4507667 : src += size;
20301 : 9650528 : while (size != 0)
20302 : : {
20303 : 5142861 : val <<= 8;
20304 : 5142861 : val |= *--src & 0xff;
20305 : 5142861 : --size;
20306 : : }
20307 : 4507667 : return val;
20308 : : }
20309 : :
20310 : : /* Writes wide_int values to dw_vec_const array. */
20311 : :
20312 : : static void
20313 : 48 : insert_wide_int (const wide_int_ref &val, unsigned char *dest, int elt_size)
20314 : : {
20315 : 48 : int i;
20316 : :
20317 : 48 : if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
20318 : : {
20319 : 48 : insert_int ((HOST_WIDE_INT) val.elt (0), elt_size, dest);
20320 : : return;
20321 : : }
20322 : :
20323 : : /* We'd have to extend this code to support odd sizes. */
20324 : 0 : gcc_assert (elt_size % (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) == 0);
20325 : :
20326 : 0 : int n = elt_size / (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
20327 : :
20328 : 0 : if (WORDS_BIG_ENDIAN)
20329 : : for (i = n - 1; i >= 0; i--)
20330 : : {
20331 : : insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
20332 : : dest += sizeof (HOST_WIDE_INT);
20333 : : }
20334 : : else
20335 : 0 : for (i = 0; i < n; i++)
20336 : : {
20337 : 0 : insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
20338 : 0 : dest += sizeof (HOST_WIDE_INT);
20339 : : }
20340 : : }
20341 : :
20342 : : /* Writes floating point values to dw_vec_const array. */
20343 : :
20344 : : static unsigned
20345 : 97545 : insert_float (const_rtx rtl, unsigned char *array)
20346 : : {
20347 : 97545 : long val[4];
20348 : 97545 : int i;
20349 : 97545 : scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
20350 : :
20351 : 97545 : real_to_target (val, CONST_DOUBLE_REAL_VALUE (rtl), mode);
20352 : :
20353 : : /* real_to_target puts 32-bit pieces in each long. Pack them. */
20354 : 195090 : if (GET_MODE_SIZE (mode) < 4)
20355 : : {
20356 : 1820 : gcc_assert (GET_MODE_SIZE (mode) == 2);
20357 : 910 : insert_int (val[0], 2, array);
20358 : : return 2;
20359 : : }
20360 : :
20361 : 622240 : for (i = 0; i < GET_MODE_SIZE (mode) / 4; i++)
20362 : : {
20363 : 214485 : insert_int (val[i], 4, array);
20364 : 214485 : array += 4;
20365 : : }
20366 : : return 4;
20367 : : }
20368 : :
20369 : : /* Attach a DW_AT_const_value attribute for a variable or a parameter which
20370 : : does not have a "location" either in memory or in a register. These
20371 : : things can arise in GNU C when a constant is passed as an actual parameter
20372 : : to an inlined function. They can also arise in C++ where declared
20373 : : constants do not necessarily get memory "homes". */
20374 : :
20375 : : static bool
20376 : 51251 : add_const_value_attribute (dw_die_ref die, machine_mode mode, rtx rtl)
20377 : : {
20378 : 51251 : scalar_mode int_mode;
20379 : :
20380 : 51251 : switch (GET_CODE (rtl))
20381 : : {
20382 : 35297 : case CONST_INT:
20383 : 35297 : {
20384 : 35297 : HOST_WIDE_INT val = INTVAL (rtl);
20385 : :
20386 : 35297 : if (val < 0)
20387 : 1851 : add_AT_int (die, DW_AT_const_value, val);
20388 : : else
20389 : 33446 : add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
20390 : : }
20391 : : return true;
20392 : :
20393 : 39 : case CONST_WIDE_INT:
20394 : 39 : if (is_int_mode (mode, &int_mode)
20395 : 39 : && (GET_MODE_PRECISION (int_mode)
20396 : : & (HOST_BITS_PER_WIDE_INT - 1)) == 0)
20397 : : {
20398 : 39 : add_AT_wide (die, DW_AT_const_value, rtx_mode_t (rtl, int_mode));
20399 : 39 : return true;
20400 : : }
20401 : : return false;
20402 : :
20403 : 6356 : case CONST_DOUBLE:
20404 : : /* Note that a CONST_DOUBLE rtx could represent either an integer or a
20405 : : floating-point constant. A CONST_DOUBLE is used whenever the
20406 : : constant requires more than one word in order to be adequately
20407 : : represented. */
20408 : 6356 : if (TARGET_SUPPORTS_WIDE_INT == 0
20409 : : && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl)))
20410 : : add_AT_double (die, DW_AT_const_value,
20411 : : CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
20412 : : else
20413 : : {
20414 : 6356 : scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
20415 : 6356 : unsigned int length = GET_MODE_SIZE (mode);
20416 : 6356 : unsigned char *array = ggc_vec_alloc<unsigned char> (length);
20417 : 6356 : unsigned int elt_size = insert_float (rtl, array);
20418 : :
20419 : 6356 : add_AT_vec (die, DW_AT_const_value, length / elt_size, elt_size,
20420 : : array);
20421 : : }
20422 : 6356 : return true;
20423 : :
20424 : 23 : case CONST_VECTOR:
20425 : 23 : {
20426 : 23 : unsigned int length;
20427 : 46 : if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
20428 : 1760 : return false;
20429 : :
20430 : 23 : machine_mode mode = GET_MODE (rtl);
20431 : : /* The combination of a length and byte elt_size doesn't extend
20432 : : naturally to boolean vectors, where several elements are packed
20433 : : into the same byte. */
20434 : 23 : if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL)
20435 : : return false;
20436 : :
20437 : 23 : unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
20438 : 23 : unsigned char *array
20439 : 23 : = ggc_vec_alloc<unsigned char> (length * elt_size);
20440 : 23 : unsigned int i;
20441 : 23 : unsigned char *p;
20442 : 23 : machine_mode imode = GET_MODE_INNER (mode);
20443 : :
20444 : 23 : switch (GET_MODE_CLASS (mode))
20445 : : {
20446 : : case MODE_VECTOR_INT:
20447 : 46 : for (i = 0, p = array; i < length; i++, p += elt_size)
20448 : : {
20449 : 40 : rtx elt = CONST_VECTOR_ELT (rtl, i);
20450 : 40 : insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
20451 : : }
20452 : : break;
20453 : :
20454 : : case MODE_VECTOR_FLOAT:
20455 : 81 : for (i = 0, p = array; i < length; i++, p += elt_size)
20456 : : {
20457 : 64 : rtx elt = CONST_VECTOR_ELT (rtl, i);
20458 : 64 : insert_float (elt, p);
20459 : : }
20460 : : break;
20461 : :
20462 : 0 : default:
20463 : 0 : gcc_unreachable ();
20464 : : }
20465 : :
20466 : 23 : add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
20467 : : }
20468 : 23 : return true;
20469 : :
20470 : 599 : case CONST_STRING:
20471 : 599 : if (dwarf_version >= 4 || !dwarf_strict)
20472 : : {
20473 : 599 : dw_loc_descr_ref loc_result;
20474 : 599 : resolve_one_addr (&rtl);
20475 : 7720 : rtl_addr:
20476 : 7720 : loc_result = new_addr_loc_descr (rtl, dtprel_false);
20477 : 7720 : add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
20478 : 7720 : add_AT_loc (die, DW_AT_location, loc_result);
20479 : 7720 : vec_safe_push (used_rtx_array, rtl);
20480 : 7720 : return true;
20481 : : }
20482 : : return false;
20483 : :
20484 : 476 : case CONST:
20485 : 476 : if (CONSTANT_P (XEXP (rtl, 0)))
20486 : 0 : return add_const_value_attribute (die, mode, XEXP (rtl, 0));
20487 : : /* FALLTHROUGH */
20488 : 8877 : case SYMBOL_REF:
20489 : 8877 : if (!const_ok_for_output (rtl))
20490 : : return false;
20491 : : /* FALLTHROUGH */
20492 : 7121 : case LABEL_REF:
20493 : 7121 : if (dwarf_version >= 4 || !dwarf_strict)
20494 : 7121 : goto rtl_addr;
20495 : : return false;
20496 : :
20497 : : case PLUS:
20498 : : /* In cases where an inlined instance of an inline function is passed
20499 : : the address of an `auto' variable (which is local to the caller) we
20500 : : can get a situation where the DECL_RTL of the artificial local
20501 : : variable (for the inlining) which acts as a stand-in for the
20502 : : corresponding formal parameter (of the inline function) will look
20503 : : like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
20504 : : exactly a compile-time constant expression, but it isn't the address
20505 : : of the (artificial) local variable either. Rather, it represents the
20506 : : *value* which the artificial local variable always has during its
20507 : : lifetime. We currently have no way to represent such quasi-constant
20508 : : values in Dwarf, so for now we just punt and generate nothing. */
20509 : : return false;
20510 : :
20511 : : case HIGH:
20512 : : case CONST_FIXED:
20513 : : case MINUS:
20514 : : case SIGN_EXTEND:
20515 : : case ZERO_EXTEND:
20516 : : case CONST_POLY_INT:
20517 : : return false;
20518 : :
20519 : 56 : case MEM:
20520 : 56 : if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
20521 : 56 : && MEM_READONLY_P (rtl)
20522 : 112 : && GET_MODE (rtl) == BLKmode)
20523 : : {
20524 : 56 : add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
20525 : 56 : return true;
20526 : : }
20527 : : return false;
20528 : :
20529 : 0 : default:
20530 : : /* No other kinds of rtx should be possible here. */
20531 : 0 : gcc_unreachable ();
20532 : : }
20533 : : }
20534 : :
20535 : : /* Determine whether the evaluation of EXPR references any variables
20536 : : or functions which aren't otherwise used (and therefore may not be
20537 : : output). */
20538 : : static tree
20539 : 5863 : reference_to_unused (tree * tp, int * walk_subtrees,
20540 : : void * data ATTRIBUTE_UNUSED)
20541 : : {
20542 : 5863 : if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
20543 : 179 : *walk_subtrees = 0;
20544 : :
20545 : 5863 : if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
20546 : 17 : && ! TREE_ASM_WRITTEN (*tp))
20547 : : return *tp;
20548 : : /* ??? The C++ FE emits debug information for using decls, so
20549 : : putting gcc_unreachable here falls over. See PR31899. For now
20550 : : be conservative. */
20551 : 5846 : else if (!symtab->global_info_ready && VAR_P (*tp))
20552 : : return *tp;
20553 : 5791 : else if (VAR_P (*tp))
20554 : : {
20555 : 5 : varpool_node *node = varpool_node::get (*tp);
20556 : 5 : if (!node || !node->definition)
20557 : 0 : return *tp;
20558 : : }
20559 : 5786 : else if (TREE_CODE (*tp) == FUNCTION_DECL
20560 : 5786 : && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
20561 : : {
20562 : : /* The call graph machinery must have finished analyzing,
20563 : : optimizing and gimplifying the CU by now.
20564 : : So if *TP has no call graph node associated
20565 : : to it, it means *TP will not be emitted. */
20566 : 91 : if (!symtab->global_info_ready || !cgraph_node::get (*tp))
20567 : 59 : return *tp;
20568 : : }
20569 : 5695 : else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
20570 : 495 : return *tp;
20571 : :
20572 : : return NULL_TREE;
20573 : : }
20574 : :
20575 : : /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
20576 : : for use in a later add_const_value_attribute call. */
20577 : :
20578 : : static rtx
20579 : 41036 : rtl_for_decl_init (tree init, tree type)
20580 : : {
20581 : 41036 : rtx rtl = NULL_RTX;
20582 : :
20583 : 41036 : STRIP_NOPS (init);
20584 : :
20585 : : /* If a variable is initialized with a string constant without embedded
20586 : : zeros, build CONST_STRING. */
20587 : 41036 : if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
20588 : : {
20589 : 461 : tree enttype = TREE_TYPE (type);
20590 : 461 : tree domain = TYPE_DOMAIN (type);
20591 : 461 : scalar_int_mode mode;
20592 : :
20593 : 922 : if (is_int_mode (TYPE_MODE (enttype), &mode)
20594 : 461 : && GET_MODE_SIZE (mode) == 1
20595 : 450 : && domain
20596 : 450 : && TYPE_MAX_VALUE (domain)
20597 : 414 : && TREE_CODE (TYPE_MAX_VALUE (domain)) == INTEGER_CST
20598 : 414 : && integer_zerop (TYPE_MIN_VALUE (domain))
20599 : 405 : && compare_tree_int (TYPE_MAX_VALUE (domain),
20600 : 405 : TREE_STRING_LENGTH (init) - 1) == 0
20601 : 254 : && ((size_t) TREE_STRING_LENGTH (init)
20602 : 254 : == strlen (TREE_STRING_POINTER (init)) + 1))
20603 : : {
20604 : 204 : rtl = gen_rtx_CONST_STRING (VOIDmode,
20605 : : ggc_strdup (TREE_STRING_POINTER (init)));
20606 : 204 : rtl = gen_rtx_MEM (BLKmode, rtl);
20607 : 204 : MEM_READONLY_P (rtl) = 1;
20608 : : }
20609 : : }
20610 : : /* Other aggregates, and complex values, could be represented using
20611 : : CONCAT: FIXME!
20612 : : If this changes, please adjust tree_add_const_value_attribute
20613 : : so that for early_dwarf it will for such initializers mangle referenced
20614 : : decls. */
20615 : 40575 : else if (AGGREGATE_TYPE_P (type)
20616 : 4359 : || (TREE_CODE (init) == VIEW_CONVERT_EXPR
20617 : 0 : && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
20618 : 44934 : || TREE_CODE (type) == COMPLEX_TYPE)
20619 : : ;
20620 : : /* Vectors only work if their mode is supported by the target.
20621 : : FIXME: generic vectors ought to work too. */
20622 : 4342 : else if (TREE_CODE (type) == VECTOR_TYPE
20623 : 4342 : && !VECTOR_MODE_P (TYPE_MODE (type)))
20624 : : ;
20625 : : /* If the initializer is something that we know will expand into an
20626 : : immediate RTL constant, expand it now. We must be careful not to
20627 : : reference variables which won't be output. */
20628 : 4338 : else if (initializer_constant_valid_p (init, type)
20629 : 4338 : && ! walk_tree (&init, reference_to_unused, NULL, NULL))
20630 : : {
20631 : : /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
20632 : : possible. */
20633 : 3711 : if (TREE_CODE (type) == VECTOR_TYPE)
20634 : 21 : switch (TREE_CODE (init))
20635 : : {
20636 : : case VECTOR_CST:
20637 : : break;
20638 : 0 : case CONSTRUCTOR:
20639 : 0 : if (TREE_CONSTANT (init))
20640 : : {
20641 : 0 : vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (init);
20642 : 0 : bool constant_p = true;
20643 : 0 : tree value;
20644 : 0 : unsigned HOST_WIDE_INT ix;
20645 : :
20646 : : /* Even when ctor is constant, it might contain non-*_CST
20647 : : elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
20648 : : belong into VECTOR_CST nodes. */
20649 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
20650 : 0 : if (!CONSTANT_CLASS_P (value))
20651 : : {
20652 : : constant_p = false;
20653 : : break;
20654 : : }
20655 : :
20656 : 0 : if (constant_p)
20657 : : {
20658 : 0 : init = build_vector_from_ctor (type, elts);
20659 : 0 : break;
20660 : : }
20661 : : }
20662 : : /* FALLTHRU */
20663 : :
20664 : 0 : default:
20665 : 0 : return NULL;
20666 : : }
20667 : :
20668 : : /* Large _BitInt BLKmode INTEGER_CSTs would yield a MEM. */
20669 : 3711 : if (TREE_CODE (init) == INTEGER_CST
20670 : 350 : && TREE_CODE (TREE_TYPE (init)) == BITINT_TYPE
20671 : 3711 : && TYPE_MODE (TREE_TYPE (init)) == BLKmode)
20672 : : {
20673 : 0 : if (tree_fits_shwi_p (init))
20674 : 0 : return GEN_INT (tree_to_shwi (init));
20675 : : else
20676 : : return NULL;
20677 : : }
20678 : :
20679 : 3711 : rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
20680 : :
20681 : : /* If expand_expr returns a MEM, it wasn't immediate. */
20682 : 3711 : gcc_assert (!rtl || !MEM_P (rtl));
20683 : : }
20684 : :
20685 : : return rtl;
20686 : : }
20687 : :
20688 : : /* Generate RTL for the variable DECL to represent its location. */
20689 : :
20690 : : static rtx
20691 : 19104869 : rtl_for_decl_location (tree decl)
20692 : : {
20693 : 19104869 : rtx rtl;
20694 : :
20695 : : /* Here we have to decide where we are going to say the parameter "lives"
20696 : : (as far as the debugger is concerned). We only have a couple of
20697 : : choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
20698 : :
20699 : : DECL_RTL normally indicates where the parameter lives during most of the
20700 : : activation of the function. If optimization is enabled however, this
20701 : : could be either NULL or else a pseudo-reg. Both of those cases indicate
20702 : : that the parameter doesn't really live anywhere (as far as the code
20703 : : generation parts of GCC are concerned) during most of the function's
20704 : : activation. That will happen (for example) if the parameter is never
20705 : : referenced within the function.
20706 : :
20707 : : We could just generate a location descriptor here for all non-NULL
20708 : : non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
20709 : : a little nicer than that if we also consider DECL_INCOMING_RTL in cases
20710 : : where DECL_RTL is NULL or is a pseudo-reg.
20711 : :
20712 : : Note however that we can only get away with using DECL_INCOMING_RTL as
20713 : : a backup substitute for DECL_RTL in certain limited cases. In cases
20714 : : where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
20715 : : we can be sure that the parameter was passed using the same type as it is
20716 : : declared to have within the function, and that its DECL_INCOMING_RTL
20717 : : points us to a place where a value of that type is passed.
20718 : :
20719 : : In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
20720 : : we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
20721 : : because in these cases DECL_INCOMING_RTL points us to a value of some
20722 : : type which is *different* from the type of the parameter itself. Thus,
20723 : : if we tried to use DECL_INCOMING_RTL to generate a location attribute in
20724 : : such cases, the debugger would end up (for example) trying to fetch a
20725 : : `float' from a place which actually contains the first part of a
20726 : : `double'. That would lead to really incorrect and confusing
20727 : : output at debug-time.
20728 : :
20729 : : So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
20730 : : in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
20731 : : are a couple of exceptions however. On little-endian machines we can
20732 : : get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
20733 : : not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
20734 : : an integral type that is smaller than TREE_TYPE (decl). These cases arise
20735 : : when (on a little-endian machine) a non-prototyped function has a
20736 : : parameter declared to be of type `short' or `char'. In such cases,
20737 : : TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
20738 : : be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
20739 : : passed `int' value. If the debugger then uses that address to fetch
20740 : : a `short' or a `char' (on a little-endian machine) the result will be
20741 : : the correct data, so we allow for such exceptional cases below.
20742 : :
20743 : : Note that our goal here is to describe the place where the given formal
20744 : : parameter lives during most of the function's activation (i.e. between the
20745 : : end of the prologue and the start of the epilogue). We'll do that as best
20746 : : as we can. Note however that if the given formal parameter is modified
20747 : : sometime during the execution of the function, then a stack backtrace (at
20748 : : debug-time) will show the function as having been called with the *new*
20749 : : value rather than the value which was originally passed in. This happens
20750 : : rarely enough that it is not a major problem, but it *is* a problem, and
20751 : : I'd like to fix it.
20752 : :
20753 : : A future version of dwarf2out.cc may generate two additional attributes for
20754 : : any given DW_TAG_formal_parameter DIE which will describe the "passed
20755 : : type" and the "passed location" for the given formal parameter in addition
20756 : : to the attributes we now generate to indicate the "declared type" and the
20757 : : "active location" for each parameter. This additional set of attributes
20758 : : could be used by debuggers for stack backtraces. Separately, note that
20759 : : sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
20760 : : This happens (for example) for inlined-instances of inline function formal
20761 : : parameters which are never referenced. This really shouldn't be
20762 : : happening. All PARM_DECL nodes should get valid non-NULL
20763 : : DECL_INCOMING_RTL values. FIXME. */
20764 : :
20765 : : /* Use DECL_RTL as the "location" unless we find something better. */
20766 : 19104869 : rtl = DECL_RTL_IF_SET (decl);
20767 : :
20768 : : /* When generating abstract instances, ignore everything except
20769 : : constants, symbols living in memory, and symbols living in
20770 : : fixed registers. */
20771 : 19104869 : if (! reload_completed)
20772 : : {
20773 : 458601 : if (rtl
20774 : 449359 : && (CONSTANT_P (rtl)
20775 : 449359 : || (MEM_P (rtl)
20776 : 449359 : && CONSTANT_P (XEXP (rtl, 0)))
20777 : 0 : || (REG_P (rtl)
20778 : 0 : && VAR_P (decl)
20779 : 0 : && TREE_STATIC (decl))))
20780 : : {
20781 : 449359 : rtl = targetm.delegitimize_address (rtl);
20782 : 449359 : return rtl;
20783 : : }
20784 : : rtl = NULL_RTX;
20785 : : }
20786 : 18646268 : else if (TREE_CODE (decl) == PARM_DECL)
20787 : : {
20788 : 1131389 : if (rtl == NULL_RTX
20789 : 1131385 : || is_pseudo_reg (rtl)
20790 : 1485706 : || (MEM_P (rtl)
20791 : 209144 : && is_pseudo_reg (XEXP (rtl, 0))
20792 : 22 : && DECL_INCOMING_RTL (decl)
20793 : 22 : && MEM_P (DECL_INCOMING_RTL (decl))
20794 : 22 : && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
20795 : : {
20796 : 777094 : tree declared_type = TREE_TYPE (decl);
20797 : 777094 : tree passed_type = DECL_ARG_TYPE (decl);
20798 : 777094 : machine_mode dmode = TYPE_MODE (declared_type);
20799 : 777094 : machine_mode pmode = TYPE_MODE (passed_type);
20800 : :
20801 : : /* This decl represents a formal parameter which was optimized out.
20802 : : Note that DECL_INCOMING_RTL may be NULL in here, but we handle
20803 : : all cases where (rtl == NULL_RTX) just below. */
20804 : 777094 : if (dmode == pmode)
20805 : 776307 : rtl = DECL_INCOMING_RTL (decl);
20806 : 787 : else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
20807 : 787 : && SCALAR_INT_MODE_P (dmode)
20808 : 1402 : && known_le (GET_MODE_SIZE (dmode), GET_MODE_SIZE (pmode))
20809 : 1488 : && DECL_INCOMING_RTL (decl))
20810 : : {
20811 : 701 : rtx inc = DECL_INCOMING_RTL (decl);
20812 : 701 : if (REG_P (inc))
20813 : : rtl = inc;
20814 : 0 : else if (MEM_P (inc))
20815 : : {
20816 : : if (BYTES_BIG_ENDIAN)
20817 : : rtl = adjust_address_nv (inc, dmode,
20818 : : GET_MODE_SIZE (pmode)
20819 : : - GET_MODE_SIZE (dmode));
20820 : : else
20821 : : rtl = inc;
20822 : : }
20823 : : }
20824 : : }
20825 : :
20826 : : /* If the parm was passed in registers, but lives on the stack, then
20827 : : make a big endian correction if the mode of the type of the
20828 : : parameter is not the same as the mode of the rtl. */
20829 : : /* ??? This is the same series of checks that are made in dbxout.cc before
20830 : : we reach the big endian correction code there. It isn't clear if all
20831 : : of these checks are necessary here, but keeping them all is the safe
20832 : : thing to do. */
20833 : : else if (MEM_P (rtl)
20834 : : && XEXP (rtl, 0) != const0_rtx
20835 : : && ! CONSTANT_P (XEXP (rtl, 0))
20836 : : /* Not passed in memory. */
20837 : : && !MEM_P (DECL_INCOMING_RTL (decl))
20838 : : /* Not passed by invisible reference. */
20839 : : && (!REG_P (XEXP (rtl, 0))
20840 : : || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
20841 : : || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
20842 : : #if !HARD_FRAME_POINTER_IS_ARG_POINTER
20843 : : || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
20844 : : #endif
20845 : : )
20846 : : /* Big endian correction check. */
20847 : : && BYTES_BIG_ENDIAN
20848 : : && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
20849 : : && known_lt (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))),
20850 : : UNITS_PER_WORD))
20851 : : {
20852 : : machine_mode addr_mode = get_address_mode (rtl);
20853 : : poly_int64 offset = (UNITS_PER_WORD
20854 : : - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
20855 : :
20856 : : rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
20857 : : plus_constant (addr_mode, XEXP (rtl, 0), offset));
20858 : : }
20859 : : }
20860 : 17514879 : else if (VAR_P (decl)
20861 : 17514879 : && rtl
20862 : 1389843 : && MEM_P (rtl)
20863 : 18098995 : && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)))
20864 : : {
20865 : 4 : machine_mode addr_mode = get_address_mode (rtl);
20866 : 4 : poly_int64 offset = byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl)),
20867 : 4 : GET_MODE (rtl));
20868 : :
20869 : : /* If a variable is declared "register" yet is smaller than
20870 : : a register, then if we store the variable to memory, it
20871 : : looks like we're storing a register-sized value, when in
20872 : : fact we are not. We need to adjust the offset of the
20873 : : storage location to reflect the actual value's bytes,
20874 : : else gdb will not be able to display it. */
20875 : 4 : if (maybe_ne (offset, 0))
20876 : 0 : rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
20877 : : plus_constant (addr_mode, XEXP (rtl, 0), offset));
20878 : : }
20879 : :
20880 : : /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
20881 : : and will have been substituted directly into all expressions that use it.
20882 : : C does not have such a concept, but C++ and other languages do. */
20883 : 18654809 : if (!rtl && VAR_P (decl) && DECL_INITIAL (decl))
20884 : 1580 : rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
20885 : :
20886 : 18655510 : if (rtl)
20887 : 2521833 : rtl = targetm.delegitimize_address (rtl);
20888 : :
20889 : : /* If we don't look past the constant pool, we risk emitting a
20890 : : reference to a constant pool entry that isn't referenced from
20891 : : code, and thus is not emitted. */
20892 : 2521833 : if (rtl)
20893 : 2521833 : rtl = avoid_constant_pool_reference (rtl);
20894 : :
20895 : : /* Try harder to get a rtl. If this symbol ends up not being emitted
20896 : : in the current CU, resolve_addr will remove the expression referencing
20897 : : it. */
20898 : 2521833 : if (rtl == NULL_RTX
20899 : 16133677 : && !(early_dwarf && (flag_generate_lto || flag_generate_offload))
20900 : 16133523 : && VAR_P (decl)
20901 : 16132533 : && !DECL_EXTERNAL (decl)
20902 : 16132533 : && TREE_STATIC (decl)
20903 : 13169 : && DECL_NAME (decl)
20904 : 13169 : && !DECL_HARD_REGISTER (decl)
20905 : 2535002 : && DECL_MODE (decl) != VOIDmode)
20906 : : {
20907 : 13169 : rtl = make_decl_rtl_for_debug (decl);
20908 : 13169 : if (!MEM_P (rtl)
20909 : 13169 : || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
20910 : 26338 : || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
20911 : : rtl = NULL_RTX;
20912 : : }
20913 : :
20914 : : return rtl;
20915 : : }
20916 : :
20917 : : /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
20918 : : returned. If so, the decl for the COMMON block is returned, and the
20919 : : value is the offset into the common block for the symbol. */
20920 : :
20921 : : static tree
20922 : 34351538 : fortran_common (tree decl, HOST_WIDE_INT *value)
20923 : : {
20924 : 34351538 : tree val_expr, cvar;
20925 : 34351538 : machine_mode mode;
20926 : 34351538 : poly_int64 bitsize, bitpos;
20927 : 34351538 : tree offset;
20928 : 34351538 : HOST_WIDE_INT cbitpos;
20929 : 34351538 : int unsignedp, reversep, volatilep = 0;
20930 : :
20931 : : /* If the decl isn't a VAR_DECL, or if it isn't static, or if
20932 : : it does not have a value (the offset into the common area), or if it
20933 : : is thread local (as opposed to global) then it isn't common, and shouldn't
20934 : : be handled as such. */
20935 : 34351538 : if (!VAR_P (decl)
20936 : 34351538 : || !TREE_STATIC (decl)
20937 : 28968140 : || !DECL_HAS_VALUE_EXPR_P (decl)
20938 : 34384532 : || !is_fortran ())
20939 : 34350416 : return NULL_TREE;
20940 : :
20941 : 1122 : val_expr = DECL_VALUE_EXPR (decl);
20942 : 1122 : if (TREE_CODE (val_expr) != COMPONENT_REF)
20943 : : return NULL_TREE;
20944 : :
20945 : 1122 : cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset, &mode,
20946 : : &unsignedp, &reversep, &volatilep);
20947 : :
20948 : 1122 : if (cvar == NULL_TREE
20949 : 1122 : || !VAR_P (cvar)
20950 : 1122 : || DECL_ARTIFICIAL (cvar)
20951 : 1061 : || !TREE_PUBLIC (cvar)
20952 : : /* We don't expect to have to cope with variable offsets,
20953 : : since at present all static data must have a constant size. */
20954 : 1122 : || !bitpos.is_constant (&cbitpos))
20955 : : return NULL_TREE;
20956 : :
20957 : 1061 : *value = 0;
20958 : 1061 : if (offset != NULL)
20959 : : {
20960 : 0 : if (!tree_fits_shwi_p (offset))
20961 : : return NULL_TREE;
20962 : 0 : *value = tree_to_shwi (offset);
20963 : : }
20964 : 1061 : if (cbitpos != 0)
20965 : 719 : *value += cbitpos / BITS_PER_UNIT;
20966 : :
20967 : : return cvar;
20968 : : }
20969 : :
20970 : : /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
20971 : : data attribute for a variable or a parameter. We generate the
20972 : : DW_AT_const_value attribute only in those cases where the given variable
20973 : : or parameter does not have a true "location" either in memory or in a
20974 : : register. This can happen (for example) when a constant is passed as an
20975 : : actual argument in a call to an inline function. (It's possible that
20976 : : these things can crop up in other ways also.) Note that one type of
20977 : : constant value which can be passed into an inlined function is a constant
20978 : : pointer. This can happen for example if an actual argument in an inlined
20979 : : function call evaluates to a compile-time constant address.
20980 : :
20981 : : CACHE_P is true if it is worth caching the location list for DECL,
20982 : : so that future calls can reuse it rather than regenerate it from scratch.
20983 : : This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
20984 : : since we will need to refer to them each time the function is inlined. */
20985 : :
20986 : : static bool
20987 : 20188521 : add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p)
20988 : : {
20989 : 20188521 : rtx rtl;
20990 : 20188521 : dw_loc_list_ref list;
20991 : 20188521 : var_loc_list *loc_list;
20992 : 20188521 : cached_dw_loc_list *cache;
20993 : :
20994 : 20188521 : if (early_dwarf)
20995 : : return false;
20996 : :
20997 : 16075811 : if (TREE_CODE (decl) == ERROR_MARK)
20998 : : return false;
20999 : :
21000 : 16075811 : if (get_AT (die, DW_AT_location)
21001 : 16075811 : || get_AT (die, DW_AT_const_value))
21002 : 16545 : return true;
21003 : :
21004 : 16059266 : gcc_assert (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL
21005 : : || TREE_CODE (decl) == RESULT_DECL);
21006 : :
21007 : : /* Try to get some constant RTL for this decl, and use that as the value of
21008 : : the location. */
21009 : :
21010 : 16059266 : rtl = rtl_for_decl_location (decl);
21011 : 2265162 : if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
21012 : 16059723 : && add_const_value_attribute (die, DECL_MODE (decl), rtl))
21013 : : return true;
21014 : :
21015 : : /* See if we have single element location list that is equivalent to
21016 : : a constant value. That way we are better to use add_const_value_attribute
21017 : : rather than expanding constant value equivalent. */
21018 : 16058809 : loc_list = lookup_decl_loc (decl);
21019 : 16058809 : if (loc_list
21020 : 12944098 : && loc_list->first
21021 : 12944098 : && loc_list->first->next == NULL
21022 : 487557 : && NOTE_P (loc_list->first->loc)
21023 : 482631 : && NOTE_VAR_LOCATION (loc_list->first->loc)
21024 : 482631 : && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
21025 : : {
21026 : 428176 : struct var_loc_node *node;
21027 : :
21028 : 428176 : node = loc_list->first;
21029 : 428176 : rtl = NOTE_VAR_LOCATION_LOC (node->loc);
21030 : 428176 : if (GET_CODE (rtl) == EXPR_LIST)
21031 : 0 : rtl = XEXP (rtl, 0);
21032 : 381291 : if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
21033 : 428775 : && add_const_value_attribute (die, DECL_MODE (decl), rtl))
21034 : : return true;
21035 : : }
21036 : : /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
21037 : : list several times. See if we've already cached the contents. */
21038 : 12898367 : list = NULL;
21039 : 12898367 : if (loc_list == NULL || cached_dw_loc_list_table == NULL)
21040 : : cache_p = false;
21041 : 12898367 : if (cache_p)
21042 : : {
21043 : 0 : cache = cached_dw_loc_list_table->find_with_hash (decl, DECL_UID (decl));
21044 : 0 : if (cache)
21045 : 0 : list = cache->loc_list;
21046 : : }
21047 : 0 : if (list == NULL)
21048 : : {
21049 : 31951622 : list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2,
21050 : : NULL);
21051 : : /* It is usually worth caching this result if the decl is from
21052 : : BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
21053 : 16013078 : if (cache_p && list && list->dw_loc_next)
21054 : : {
21055 : 0 : cached_dw_loc_list **slot
21056 : 0 : = cached_dw_loc_list_table->find_slot_with_hash (decl,
21057 : 0 : DECL_UID (decl),
21058 : : INSERT);
21059 : 0 : cache = ggc_cleared_alloc<cached_dw_loc_list> ();
21060 : 0 : cache->decl_id = DECL_UID (decl);
21061 : 0 : cache->loc_list = list;
21062 : 0 : *slot = cache;
21063 : : }
21064 : : }
21065 : 16013078 : if (list)
21066 : : {
21067 : 12783023 : add_AT_location_description (die, DW_AT_location, list);
21068 : 12783023 : return true;
21069 : : }
21070 : : /* None of that worked, so it must not really have a location;
21071 : : try adding a constant value attribute from the DECL_INITIAL. */
21072 : 3230055 : return tree_add_const_value_attribute_for_decl (die, decl);
21073 : : }
21074 : :
21075 : : /* Mangle referenced decls. */
21076 : : static tree
21077 : 183792 : mangle_referenced_decls (tree *tp, int *walk_subtrees, void *)
21078 : : {
21079 : 183792 : if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
21080 : 192 : *walk_subtrees = 0;
21081 : :
21082 : 183792 : if (VAR_OR_FUNCTION_DECL_P (*tp))
21083 : 192 : assign_assembler_name_if_needed (*tp);
21084 : :
21085 : 183792 : return NULL_TREE;
21086 : : }
21087 : :
21088 : : /* Attach a DW_AT_const_value attribute to DIE. The value of the
21089 : : attribute is the const value T. */
21090 : :
21091 : : static bool
21092 : 18356311 : tree_add_const_value_attribute (dw_die_ref die, tree t)
21093 : : {
21094 : 18356311 : tree init;
21095 : 18356311 : tree type = TREE_TYPE (t);
21096 : :
21097 : 18356311 : if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
21098 : : return false;
21099 : :
21100 : 18356311 : init = t;
21101 : 18356311 : gcc_assert (!DECL_P (init));
21102 : :
21103 : 18356311 : if (TREE_CODE (init) == INTEGER_CST)
21104 : : {
21105 : 17583376 : if (tree_fits_uhwi_p (init))
21106 : : {
21107 : 17390456 : add_AT_unsigned (die, DW_AT_const_value, tree_to_uhwi (init));
21108 : 17390456 : return true;
21109 : : }
21110 : 192920 : if (tree_fits_shwi_p (init))
21111 : : {
21112 : 192903 : add_AT_int (die, DW_AT_const_value, tree_to_shwi (init));
21113 : 192903 : return true;
21114 : : }
21115 : : }
21116 : 772952 : if (!early_dwarf)
21117 : : {
21118 : 39456 : rtx rtl = rtl_for_decl_init (init, type);
21119 : 39456 : if (rtl)
21120 : 3310 : return add_const_value_attribute (die, TYPE_MODE (type), rtl);
21121 : : }
21122 : : else
21123 : : {
21124 : : /* For early_dwarf force mangling of all referenced symbols. */
21125 : 733496 : tree initializer = init;
21126 : 733496 : STRIP_NOPS (initializer);
21127 : : /* rtl_for_decl_init punts on other aggregates, and complex values. */
21128 : 733496 : if (AGGREGATE_TYPE_P (type)
21129 : 183609 : || (TREE_CODE (initializer) == VIEW_CONVERT_EXPR
21130 : 0 : && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (initializer, 0))))
21131 : 917105 : || TREE_CODE (type) == COMPLEX_TYPE)
21132 : : ;
21133 : 183571 : else if (initializer_constant_valid_p (initializer, type))
21134 : 183570 : walk_tree (&initializer, mangle_referenced_decls, NULL, NULL);
21135 : : }
21136 : : /* If the host and target are sane, try harder. */
21137 : 769642 : if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
21138 : 769642 : && initializer_constant_valid_p (init, type))
21139 : : {
21140 : 769640 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
21141 : 769640 : if (size > 0 && (int) size == size)
21142 : : {
21143 : 769590 : unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
21144 : :
21145 : 769590 : if (native_encode_initializer (init, array, size) == size)
21146 : : {
21147 : 762815 : add_AT_vec (die, DW_AT_const_value, size, 1, array);
21148 : 762815 : return true;
21149 : : }
21150 : 6775 : ggc_free (array);
21151 : : }
21152 : : }
21153 : : return false;
21154 : : }
21155 : :
21156 : : /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
21157 : : attribute is the const value of T, where T is an integral constant
21158 : : variable with static storage duration
21159 : : (so it can't be a PARM_DECL or a RESULT_DECL). */
21160 : :
21161 : : static bool
21162 : 32923929 : tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
21163 : : {
21164 : :
21165 : 32923929 : if (!decl
21166 : 32923929 : || (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
21167 : 32923394 : || (VAR_P (decl) && !TREE_STATIC (decl)))
21168 : : return false;
21169 : :
21170 : 29072915 : if (TREE_READONLY (decl)
21171 : 28815655 : && ! TREE_THIS_VOLATILE (decl)
21172 : 57888399 : && DECL_INITIAL (decl))
21173 : : /* OK */;
21174 : : else
21175 : : return false;
21176 : :
21177 : : /* Don't add DW_AT_const_value if abstract origin already has one. */
21178 : 25814210 : if (get_AT (var_die, DW_AT_const_value))
21179 : : return false;
21180 : :
21181 : 13258454 : return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
21182 : : }
21183 : :
21184 : : /* Convert the CFI instructions for the current function into a
21185 : : location list. This is used for DW_AT_frame_base when we targeting
21186 : : a dwarf2 consumer that does not support the dwarf3
21187 : : DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
21188 : : expressions. */
21189 : :
21190 : : static dw_loc_list_ref
21191 : 3567 : convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
21192 : : {
21193 : 3567 : int ix;
21194 : 3567 : dw_fde_ref fde;
21195 : 3567 : dw_loc_list_ref list, *list_tail;
21196 : 3567 : dw_cfi_ref cfi;
21197 : 3567 : dw_cfa_location last_cfa, next_cfa;
21198 : 3567 : const char *start_label, *last_label, *section;
21199 : 3567 : dw_cfa_location remember;
21200 : :
21201 : 3567 : fde = cfun->fde;
21202 : 3567 : gcc_assert (fde != NULL);
21203 : :
21204 : 3567 : section = secname_for_decl (current_function_decl);
21205 : 3567 : list_tail = &list;
21206 : 3567 : list = NULL;
21207 : :
21208 : 3567 : memset (&next_cfa, 0, sizeof (next_cfa));
21209 : :
21210 : : #ifdef CODEVIEW_DEBUGGING_INFO
21211 : : /* We can write simplified frame base information for CodeView, as we're
21212 : : not using it for rewinding. */
21213 : : if (codeview_debuginfo_p ())
21214 : : {
21215 : : int dwreg = DEBUGGER_REGNO (cfun->machine->fs.cfa_reg->u.reg.regno);
21216 : :
21217 : : next_cfa.reg.set_by_dwreg (dwreg);
21218 : : next_cfa.offset = cfun->machine->fs.fp_valid
21219 : : ? cfun->machine->fs.fp_offset : cfun->machine->fs.sp_offset;
21220 : :
21221 : : *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
21222 : : fde->dw_fde_begin, 0,
21223 : : fde->dw_fde_second_begin
21224 : : ? fde->dw_fde_second_end : fde->dw_fde_end, 0,
21225 : : section);
21226 : : maybe_gen_llsym (list);
21227 : :
21228 : : return list;
21229 : : }
21230 : : #endif
21231 : :
21232 : 3567 : next_cfa.reg.set_by_dwreg (INVALID_REGNUM);
21233 : 3567 : remember = next_cfa;
21234 : :
21235 : 3567 : start_label = fde->dw_fde_begin;
21236 : :
21237 : : /* ??? Bald assumption that the CIE opcode list does not contain
21238 : : advance opcodes. */
21239 : 10701 : FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
21240 : 7134 : lookup_cfa_1 (cfi, &next_cfa, &remember);
21241 : :
21242 : 3567 : last_cfa = next_cfa;
21243 : 3567 : last_label = start_label;
21244 : :
21245 : 3567 : if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
21246 : : {
21247 : : /* If the first partition contained no CFI adjustments, the
21248 : : CIE opcodes apply to the whole first partition. */
21249 : 0 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21250 : : fde->dw_fde_begin, 0, fde->dw_fde_end, 0, section);
21251 : 0 : list_tail =&(*list_tail)->dw_loc_next;
21252 : 0 : start_label = last_label = fde->dw_fde_second_begin;
21253 : : }
21254 : :
21255 : 20350 : FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
21256 : : {
21257 : 16783 : switch (cfi->dw_cfi_opc)
21258 : : {
21259 : 5812 : case DW_CFA_set_loc:
21260 : 5812 : case DW_CFA_advance_loc1:
21261 : 5812 : case DW_CFA_advance_loc2:
21262 : 5812 : case DW_CFA_advance_loc4:
21263 : 5812 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21264 : : {
21265 : 3898 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21266 : : start_label, 0, last_label, 0, section);
21267 : :
21268 : 3898 : list_tail = &(*list_tail)->dw_loc_next;
21269 : 3898 : last_cfa = next_cfa;
21270 : 3898 : start_label = last_label;
21271 : : }
21272 : 5812 : last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
21273 : 5812 : break;
21274 : :
21275 : 0 : case DW_CFA_advance_loc:
21276 : : /* The encoding is complex enough that we should never emit this. */
21277 : 0 : gcc_unreachable ();
21278 : :
21279 : 10971 : default:
21280 : 10971 : lookup_cfa_1 (cfi, &next_cfa, &remember);
21281 : 10971 : break;
21282 : : }
21283 : 16783 : if (ix + 1 == fde->dw_fde_switch_cfi_index)
21284 : : {
21285 : 57 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21286 : : {
21287 : 47 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21288 : : start_label, 0, last_label, 0, section);
21289 : :
21290 : 47 : list_tail = &(*list_tail)->dw_loc_next;
21291 : 47 : last_cfa = next_cfa;
21292 : 47 : start_label = last_label;
21293 : : }
21294 : 57 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21295 : : start_label, 0, fde->dw_fde_end, 0, section);
21296 : 57 : list_tail = &(*list_tail)->dw_loc_next;
21297 : 57 : start_label = last_label = fde->dw_fde_second_begin;
21298 : : }
21299 : : }
21300 : :
21301 : 3567 : if (!cfa_equal_p (&last_cfa, &next_cfa))
21302 : : {
21303 : 1830 : *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
21304 : : start_label, 0, last_label, 0, section);
21305 : 1830 : list_tail = &(*list_tail)->dw_loc_next;
21306 : 1830 : start_label = last_label;
21307 : : }
21308 : :
21309 : 3567 : *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
21310 : : start_label, 0,
21311 : 3567 : fde->dw_fde_second_begin
21312 : : ? fde->dw_fde_second_end : fde->dw_fde_end, 0,
21313 : : section);
21314 : :
21315 : 3567 : maybe_gen_llsym (list);
21316 : :
21317 : 3567 : return list;
21318 : : }
21319 : :
21320 : : /* Compute a displacement from the "steady-state frame pointer" to the
21321 : : frame base (often the same as the CFA), and store it in
21322 : : frame_pointer_fb_offset. OFFSET is added to the displacement
21323 : : before the latter is negated. */
21324 : :
21325 : : static void
21326 : 557714 : compute_frame_pointer_to_fb_displacement (poly_int64 offset)
21327 : : {
21328 : 557714 : rtx reg, elim;
21329 : :
21330 : : #ifdef FRAME_POINTER_CFA_OFFSET
21331 : : reg = frame_pointer_rtx;
21332 : : offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
21333 : : #else
21334 : 557714 : reg = arg_pointer_rtx;
21335 : 557714 : offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
21336 : : #endif
21337 : :
21338 : 557714 : elim = (ira_use_lra_p
21339 : 557714 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
21340 : 0 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
21341 : 557714 : elim = strip_offset_and_add (elim, &offset);
21342 : :
21343 : 557714 : frame_pointer_fb_offset = -offset;
21344 : :
21345 : : /* ??? AVR doesn't set up valid eliminations when there is no stack frame
21346 : : in which to eliminate. This is because it's stack pointer isn't
21347 : : directly accessible as a register within the ISA. To work around
21348 : : this, assume that while we cannot provide a proper value for
21349 : : frame_pointer_fb_offset, we won't need one either. We can use
21350 : : hard frame pointer in debug info even if frame pointer isn't used
21351 : : since hard frame pointer in debug info is encoded with DW_OP_fbreg
21352 : : which uses the DW_AT_frame_base attribute, not hard frame pointer
21353 : : directly. */
21354 : 557714 : frame_pointer_fb_offset_valid
21355 : 557714 : = (elim == hard_frame_pointer_rtx || elim == stack_pointer_rtx);
21356 : 557714 : }
21357 : :
21358 : : /* Generate a DW_AT_name attribute given some string value to be included as
21359 : : the value of the attribute. */
21360 : :
21361 : : void
21362 : 208488017 : add_name_attribute (dw_die_ref die, const char *name_string)
21363 : : {
21364 : 208488017 : if (name_string != NULL && *name_string != 0)
21365 : : {
21366 : 205262707 : if (demangle_name_func)
21367 : 0 : name_string = (*demangle_name_func) (name_string);
21368 : :
21369 : 205262707 : add_AT_string (die, DW_AT_name, name_string);
21370 : : }
21371 : 208488017 : }
21372 : :
21373 : : /* Generate a DW_AT_name attribute given some string value representing a
21374 : : file or filepath to be included as value of the attribute. */
21375 : : static void
21376 : 53223 : add_filename_attribute (dw_die_ref die, const char *name_string)
21377 : : {
21378 : 53223 : if (name_string != NULL && *name_string != 0)
21379 : 53223 : add_filepath_AT_string (die, DW_AT_name, name_string);
21380 : 53223 : }
21381 : :
21382 : : /* Generate a DW_AT_description attribute given some string value to be included
21383 : : as the value of the attribute. */
21384 : :
21385 : : static void
21386 : 0 : add_desc_attribute (dw_die_ref die, const char *name_string)
21387 : : {
21388 : 0 : if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
21389 : : return;
21390 : :
21391 : 0 : if (name_string == NULL || *name_string == 0)
21392 : : return;
21393 : :
21394 : 0 : if (demangle_name_func)
21395 : 0 : name_string = (*demangle_name_func) (name_string);
21396 : :
21397 : 0 : add_AT_string (die, DW_AT_description, name_string);
21398 : : }
21399 : :
21400 : : /* Generate a DW_AT_description attribute given some decl to be included
21401 : : as the value of the attribute. */
21402 : :
21403 : : static void
21404 : 3500008 : add_desc_attribute (dw_die_ref die, tree decl)
21405 : : {
21406 : 3500008 : tree decl_name;
21407 : :
21408 : 3500008 : if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
21409 : : return;
21410 : :
21411 : 0 : if (decl == NULL_TREE || !DECL_P (decl))
21412 : : return;
21413 : 0 : decl_name = DECL_NAME (decl);
21414 : :
21415 : 0 : if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
21416 : : {
21417 : 0 : const char *name = dwarf2_name (decl, 0);
21418 : 0 : add_desc_attribute (die, name ? name : IDENTIFIER_POINTER (decl_name));
21419 : : }
21420 : : else
21421 : : {
21422 : 0 : char *desc = print_generic_expr_to_str (decl);
21423 : 0 : add_desc_attribute (die, desc);
21424 : 0 : free (desc);
21425 : : }
21426 : : }
21427 : :
21428 : : /* Retrieve the descriptive type of TYPE, if any, make sure it has a
21429 : : DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
21430 : : of TYPE accordingly.
21431 : :
21432 : : ??? This is a temporary measure until after we're able to generate
21433 : : regular DWARF for the complex Ada type system. */
21434 : :
21435 : : static void
21436 : 71141961 : add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
21437 : : dw_die_ref context_die)
21438 : : {
21439 : 71141961 : tree dtype;
21440 : 71141961 : dw_die_ref dtype_die;
21441 : :
21442 : 71141961 : if (!lang_hooks.types.descriptive_type)
21443 : : return;
21444 : :
21445 : 0 : dtype = lang_hooks.types.descriptive_type (type);
21446 : 0 : if (!dtype)
21447 : : return;
21448 : :
21449 : 0 : dtype_die = lookup_type_die (dtype);
21450 : 0 : if (!dtype_die)
21451 : : {
21452 : 0 : gen_type_die (dtype, context_die);
21453 : 0 : dtype_die = lookup_type_die (dtype);
21454 : 0 : gcc_assert (dtype_die);
21455 : : }
21456 : :
21457 : 0 : add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
21458 : : }
21459 : :
21460 : : /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
21461 : :
21462 : : static const char *
21463 : 105405 : comp_dir_string (void)
21464 : : {
21465 : 105405 : const char *wd;
21466 : 105405 : char *wd_plus_sep = NULL;
21467 : 105405 : static const char *cached_wd = NULL;
21468 : :
21469 : 105405 : if (cached_wd != NULL)
21470 : : return cached_wd;
21471 : :
21472 : 52557 : wd = get_src_pwd ();
21473 : 52557 : if (wd == NULL)
21474 : : return NULL;
21475 : :
21476 : 52557 : if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
21477 : : {
21478 : : size_t wdlen = strlen (wd);
21479 : : wd_plus_sep = XNEWVEC (char, wdlen + 2);
21480 : : strcpy (wd_plus_sep, wd);
21481 : : wd_plus_sep [wdlen] = DIR_SEPARATOR;
21482 : : wd_plus_sep [wdlen + 1] = 0;
21483 : : wd = wd_plus_sep;
21484 : : }
21485 : :
21486 : 52557 : cached_wd = remap_debug_filename (wd);
21487 : :
21488 : : /* remap_debug_filename can just pass through wd or return a new gc string.
21489 : : These two types can't be both stored in a GTY(())-tagged string, but since
21490 : : the cached value lives forever just copy it if needed. */
21491 : 52557 : if (cached_wd != wd)
21492 : : {
21493 : 184 : cached_wd = xstrdup (cached_wd);
21494 : 184 : if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR && wd_plus_sep != NULL)
21495 : : free (wd_plus_sep);
21496 : : }
21497 : :
21498 : 52557 : return cached_wd;
21499 : : }
21500 : :
21501 : : /* Generate a DW_AT_comp_dir attribute for DIE. */
21502 : :
21503 : : static void
21504 : 53223 : add_comp_dir_attribute (dw_die_ref die)
21505 : : {
21506 : 53223 : const char * wd = comp_dir_string ();
21507 : 53223 : if (wd != NULL)
21508 : 53223 : add_filepath_AT_string (die, DW_AT_comp_dir, wd);
21509 : 53223 : }
21510 : :
21511 : : /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
21512 : : pointer computation, ...), output a representation for that bound according
21513 : : to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
21514 : : loc_list_from_tree for the meaning of CONTEXT. */
21515 : :
21516 : : static void
21517 : 929213 : add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
21518 : : int forms, struct loc_descr_context *context)
21519 : : {
21520 : 929213 : dw_die_ref context_die, decl_die = NULL;
21521 : 929213 : dw_loc_list_ref list;
21522 : 929213 : bool strip_conversions = true;
21523 : 929213 : bool placeholder_seen = false;
21524 : :
21525 : 929213 : while (strip_conversions)
21526 : 929213 : switch (TREE_CODE (value))
21527 : : {
21528 : : case ERROR_MARK:
21529 : : case SAVE_EXPR:
21530 : : return;
21531 : :
21532 : 0 : CASE_CONVERT:
21533 : 0 : case VIEW_CONVERT_EXPR:
21534 : 0 : value = TREE_OPERAND (value, 0);
21535 : 0 : break;
21536 : :
21537 : : default:
21538 : : strip_conversions = false;
21539 : : break;
21540 : : }
21541 : :
21542 : : /* If possible and permitted, output the attribute as a constant. */
21543 : 929213 : if ((forms & dw_scalar_form_constant) != 0
21544 : 922521 : && TREE_CODE (value) == INTEGER_CST)
21545 : : {
21546 : 888797 : unsigned int prec = simple_type_size_in_bits (TREE_TYPE (value));
21547 : :
21548 : : /* If HOST_WIDE_INT is big enough then represent the bound as
21549 : : a constant value. We need to choose a form based on
21550 : : whether the type is signed or unsigned. We cannot just
21551 : : call add_AT_unsigned if the value itself is positive
21552 : : (add_AT_unsigned might add the unsigned value encoded as
21553 : : DW_FORM_data[1248]). Some DWARF consumers will lookup the
21554 : : bounds type and then sign extend any unsigned values found
21555 : : for signed types. This is needed only for
21556 : : DW_AT_{lower,upper}_bound, since for most other attributes,
21557 : : consumers will treat DW_FORM_data[1248] as unsigned values,
21558 : : regardless of the underlying type. */
21559 : 888797 : if (prec <= HOST_BITS_PER_WIDE_INT
21560 : 0 : || tree_fits_uhwi_p (value))
21561 : : {
21562 : 888797 : if (TYPE_UNSIGNED (TREE_TYPE (value)))
21563 : 872964 : add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
21564 : : else
21565 : 15833 : add_AT_int (die, attr, TREE_INT_CST_LOW (value));
21566 : : }
21567 : 0 : else if (dwarf_version >= 5
21568 : 0 : && TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (value))) == 128)
21569 : : /* Otherwise represent the bound as an unsigned value with
21570 : : the precision of its type. The precision and signedness
21571 : : of the type will be necessary to re-interpret it
21572 : : unambiguously. */
21573 : 0 : add_AT_wide (die, attr, wi::to_wide (value));
21574 : : else
21575 : : {
21576 : 0 : rtx v = immed_wide_int_const (wi::to_wide (value),
21577 : 0 : TYPE_MODE (TREE_TYPE (value)));
21578 : 0 : dw_loc_descr_ref loc
21579 : 0 : = loc_descriptor (v, TYPE_MODE (TREE_TYPE (value)),
21580 : : VAR_INIT_STATUS_INITIALIZED);
21581 : 0 : if (loc)
21582 : 0 : add_AT_loc (die, attr, loc);
21583 : : }
21584 : 888797 : return;
21585 : : }
21586 : :
21587 : : /* Otherwise, if it's possible and permitted too, output a reference to
21588 : : another DIE. */
21589 : 40416 : if ((forms & dw_scalar_form_reference) != 0)
21590 : : {
21591 : 32764 : tree decl = NULL_TREE;
21592 : :
21593 : : /* Some type attributes reference an outer type. For instance, the upper
21594 : : bound of an array may reference an embedding record (this happens in
21595 : : Ada). */
21596 : 32764 : if (TREE_CODE (value) == COMPONENT_REF
21597 : 0 : && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
21598 : 32764 : && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
21599 : 0 : decl = TREE_OPERAND (value, 1);
21600 : :
21601 : 32764 : else if (VAR_P (value)
21602 : : || TREE_CODE (value) == PARM_DECL
21603 : : || TREE_CODE (value) == RESULT_DECL)
21604 : : decl = value;
21605 : :
21606 : 0 : if (decl != NULL_TREE)
21607 : : {
21608 : 4654 : decl_die = lookup_decl_die (decl);
21609 : :
21610 : : /* ??? Can this happen, or should the variable have been bound
21611 : : first? Probably it can, since I imagine that we try to create
21612 : : the types of parameters in the order in which they exist in
21613 : : the list, and won't have created a forward reference to a
21614 : : later parameter. */
21615 : 4654 : if (decl_die != NULL)
21616 : : {
21617 : 2996 : if (get_AT (decl_die, DW_AT_location)
21618 : 2960 : || get_AT (decl_die, DW_AT_data_member_location)
21619 : 2960 : || get_AT (decl_die, DW_AT_data_bit_offset)
21620 : 5956 : || get_AT (decl_die, DW_AT_const_value))
21621 : : {
21622 : 56 : add_AT_die_ref (die, attr, decl_die);
21623 : 56 : return;
21624 : : }
21625 : : }
21626 : : }
21627 : : }
21628 : :
21629 : : /* Last chance: try to create a stack operation procedure to evaluate the
21630 : : value. Do nothing if even that is not possible or permitted. */
21631 : 40360 : if ((forms & dw_scalar_form_exprloc) == 0)
21632 : : return;
21633 : :
21634 : 40360 : list = loc_list_from_tree (value, 2, context);
21635 : 40360 : if (context && context->placeholder_arg)
21636 : : {
21637 : 2880 : placeholder_seen = context->placeholder_seen;
21638 : 2880 : context->placeholder_seen = false;
21639 : : }
21640 : 40360 : if (list == NULL || single_element_loc_list_p (list))
21641 : : {
21642 : : /* If this attribute is not a reference nor constant, it is
21643 : : a DWARF expression rather than location description. For that
21644 : : loc_list_from_tree (value, 0, &context) is needed. */
21645 : 39865 : dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
21646 : 39865 : if (list2 && single_element_loc_list_p (list2))
21647 : : {
21648 : 39598 : if (placeholder_seen)
21649 : : {
21650 : 2880 : struct dwarf_procedure_info dpi;
21651 : 2880 : dpi.fndecl = NULL_TREE;
21652 : 2880 : dpi.args_count = 1;
21653 : 2880 : if (!resolve_args_picking (list2->expr, 1, &dpi))
21654 : 0 : return;
21655 : : }
21656 : 39598 : add_AT_loc (die, attr, list2->expr);
21657 : 39598 : return;
21658 : : }
21659 : : }
21660 : :
21661 : : /* If that failed to give a single element location list, fall back to
21662 : : outputting this as a reference... still if permitted. */
21663 : 762 : if (list == NULL
21664 : 495 : || (forms & dw_scalar_form_reference) == 0
21665 : 495 : || placeholder_seen)
21666 : : return;
21667 : :
21668 : 495 : if (!decl_die)
21669 : : {
21670 : 148 : if (current_function_decl == 0)
21671 : 0 : context_die = comp_unit_die ();
21672 : : else
21673 : 148 : context_die = lookup_decl_die (current_function_decl);
21674 : :
21675 : 148 : decl_die = new_die (DW_TAG_variable, context_die, value);
21676 : 148 : add_AT_flag (decl_die, DW_AT_artificial, 1);
21677 : 148 : add_type_attribute (decl_die, TREE_TYPE (value), TYPE_QUAL_CONST, false,
21678 : : context_die);
21679 : : }
21680 : :
21681 : 495 : add_AT_location_description (decl_die, DW_AT_location, list);
21682 : 495 : add_AT_die_ref (die, attr, decl_die);
21683 : : }
21684 : :
21685 : : /* Return the default for DW_AT_lower_bound, or -1 if there is not any
21686 : : default. */
21687 : :
21688 : : static int
21689 : 909605 : lower_bound_default (void)
21690 : : {
21691 : 909605 : switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
21692 : : {
21693 : : case DW_LANG_C:
21694 : : case DW_LANG_C89:
21695 : : case DW_LANG_C99:
21696 : : case DW_LANG_C11:
21697 : : case DW_LANG_C_plus_plus:
21698 : : case DW_LANG_C_plus_plus_11:
21699 : : case DW_LANG_C_plus_plus_14:
21700 : : case DW_LANG_ObjC:
21701 : : case DW_LANG_ObjC_plus_plus:
21702 : : return 0;
21703 : : case DW_LANG_Fortran77:
21704 : : case DW_LANG_Fortran90:
21705 : : case DW_LANG_Fortran95:
21706 : : case DW_LANG_Fortran03:
21707 : : case DW_LANG_Fortran08:
21708 : : return 1;
21709 : 0 : case DW_LANG_UPC:
21710 : 0 : case DW_LANG_D:
21711 : 0 : case DW_LANG_Python:
21712 : 0 : return dwarf_version >= 4 ? 0 : -1;
21713 : 1966 : case DW_LANG_Ada95:
21714 : 1966 : case DW_LANG_Ada83:
21715 : 1966 : case DW_LANG_Cobol74:
21716 : 1966 : case DW_LANG_Cobol85:
21717 : 1966 : case DW_LANG_Modula2:
21718 : 1966 : case DW_LANG_PLI:
21719 : 1966 : return dwarf_version >= 4 ? 1 : -1;
21720 : : default:
21721 : : return -1;
21722 : : }
21723 : : }
21724 : :
21725 : : /* Given a tree node describing an array bound (either lower or upper) output
21726 : : a representation for that bound. */
21727 : :
21728 : : static void
21729 : 1783279 : add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
21730 : : tree bound, struct loc_descr_context *context)
21731 : : {
21732 : 1783319 : int dflt;
21733 : :
21734 : 1783359 : while (1)
21735 : 1783319 : switch (TREE_CODE (bound))
21736 : : {
21737 : : /* Strip all conversions. */
21738 : 40 : CASE_CONVERT:
21739 : 40 : case VIEW_CONVERT_EXPR:
21740 : 40 : bound = TREE_OPERAND (bound, 0);
21741 : 40 : break;
21742 : :
21743 : : /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
21744 : : are even omitted when they are the default. */
21745 : 1763247 : case INTEGER_CST:
21746 : : /* If the value for this bound is the default one, we can even omit the
21747 : : attribute. */
21748 : 1763247 : if (bound_attr == DW_AT_lower_bound
21749 : 889835 : && tree_fits_shwi_p (bound)
21750 : 889835 : && (dflt = lower_bound_default ()) != -1
21751 : 2643339 : && tree_to_shwi (bound) == dflt)
21752 : : return;
21753 : :
21754 : : /* FALLTHRU */
21755 : :
21756 : 908829 : default:
21757 : : /* Let GNAT encodings do the magic for self-referential bounds. */
21758 : 908829 : if (is_ada ()
21759 : 0 : && gnat_encodings == DWARF_GNAT_ENCODINGS_ALL
21760 : 908829 : && contains_placeholder_p (bound))
21761 : : return;
21762 : :
21763 : 908829 : add_scalar_info (subrange_die, bound_attr, bound,
21764 : : dw_scalar_form_constant
21765 : : | dw_scalar_form_exprloc
21766 : : | dw_scalar_form_reference,
21767 : : context);
21768 : 908829 : return;
21769 : : }
21770 : : }
21771 : :
21772 : : /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
21773 : : possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
21774 : :
21775 : : This function reuses previously set type and bound information if
21776 : : available. */
21777 : :
21778 : : static void
21779 : 898573 : add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
21780 : : {
21781 : 898573 : dw_die_ref child = type_die->die_child;
21782 : 898573 : struct array_descr_info info;
21783 : 898573 : int dimension_number;
21784 : :
21785 : 898573 : if (lang_hooks.types.get_array_descr_info)
21786 : : {
21787 : 13413 : memset (&info, 0, sizeof (info));
21788 : 13413 : if (lang_hooks.types.get_array_descr_info (type, &info))
21789 : : /* Fortran sometimes emits array types with no dimension. */
21790 : 0 : gcc_assert (info.ndimensions >= 0
21791 : : && info.ndimensions
21792 : : <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN);
21793 : : }
21794 : : else
21795 : 885160 : info.ndimensions = 0;
21796 : :
21797 : : for (dimension_number = 0;
21798 : 1802146 : TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
21799 : 903573 : type = TREE_TYPE (type), dimension_number++)
21800 : : {
21801 : 904685 : tree domain = TYPE_DOMAIN (type);
21802 : :
21803 : 904685 : if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
21804 : : break;
21805 : :
21806 : : /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
21807 : : and (in GNU C only) variable bounds. Handle all three forms
21808 : : here. */
21809 : :
21810 : : /* Find and reuse a previously generated DW_TAG_subrange_type if
21811 : : available.
21812 : :
21813 : : For multi-dimensional arrays, as we iterate through the
21814 : : various dimensions in the enclosing for loop above, we also
21815 : : iterate through the DIE children and pick at each
21816 : : DW_TAG_subrange_type previously generated (if available).
21817 : : Each child DW_TAG_subrange_type DIE describes the range of
21818 : : the current dimension. At this point we should have as many
21819 : : DW_TAG_subrange_type's as we have dimensions in the
21820 : : array. */
21821 : 903573 : dw_die_ref subrange_die = NULL;
21822 : 903573 : if (child)
21823 : 4801 : while (1)
21824 : : {
21825 : 4801 : child = child->die_sib;
21826 : 4801 : if (child->die_tag == DW_TAG_subrange_type)
21827 : 4801 : subrange_die = child;
21828 : 4801 : if (child == type_die->die_child)
21829 : : {
21830 : : /* If we wrapped around, stop looking next time. */
21831 : : child = NULL;
21832 : : break;
21833 : : }
21834 : 818 : if (child->die_tag == DW_TAG_subrange_type)
21835 : : break;
21836 : : }
21837 : 4801 : if (!subrange_die)
21838 : 898772 : subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
21839 : :
21840 : 903573 : if (domain)
21841 : : {
21842 : : /* We have an array type with specified bounds. */
21843 : 868230 : tree lower = TYPE_MIN_VALUE (domain);
21844 : 868230 : tree upper = TYPE_MAX_VALUE (domain);
21845 : 868230 : tree index_type = TREE_TYPE (domain);
21846 : :
21847 : 868230 : if (dimension_number <= info.ndimensions - 1)
21848 : : {
21849 : 0 : lower = info.dimen[dimension_number].lower_bound;
21850 : 0 : upper = info.dimen[dimension_number].upper_bound;
21851 : 0 : index_type = info.dimen[dimension_number].bounds_type;
21852 : : }
21853 : :
21854 : : /* Define the index type. */
21855 : 868230 : if (index_type && !get_AT (subrange_die, DW_AT_type))
21856 : 863430 : add_type_attribute (subrange_die, index_type, TYPE_UNQUALIFIED,
21857 : : false, type_die);
21858 : :
21859 : : /* ??? If upper is NULL, the array has unspecified length,
21860 : : but it does have a lower bound. This happens with Fortran
21861 : : dimension arr(N:*)
21862 : : Since the debugger is definitely going to need to know N
21863 : : to produce useful results, go ahead and output the lower
21864 : : bound solo, and hope the debugger can cope. */
21865 : :
21866 : 868230 : if (lower && !get_AT (subrange_die, DW_AT_lower_bound))
21867 : 867649 : add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
21868 : :
21869 : 868230 : if (!get_AT (subrange_die, DW_AT_upper_bound)
21870 : 868230 : && !get_AT (subrange_die, DW_AT_count))
21871 : : {
21872 : 863502 : if (upper)
21873 : 857122 : add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
21874 : 6380 : else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type))
21875 : : /* Zero-length array. */
21876 : 1054 : add_bound_info (subrange_die, DW_AT_count,
21877 : 1054 : build_int_cst (TREE_TYPE (lower), 0), NULL);
21878 : : }
21879 : : }
21880 : :
21881 : : /* Otherwise we have an array type with an unspecified length. The
21882 : : DWARF-2 spec does not say how to handle this; let's just leave out the
21883 : : bounds. */
21884 : : }
21885 : 898573 : }
21886 : :
21887 : : /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
21888 : :
21889 : : static void
21890 : 35495824 : add_byte_size_attribute (dw_die_ref die, tree tree_node)
21891 : : {
21892 : 35495824 : dw_die_ref decl_die;
21893 : 35495824 : HOST_WIDE_INT size;
21894 : :
21895 : 35495824 : switch (TREE_CODE (tree_node))
21896 : : {
21897 : : case ERROR_MARK:
21898 : : size = 0;
21899 : : break;
21900 : 35225683 : case ENUMERAL_TYPE:
21901 : 35225683 : case RECORD_TYPE:
21902 : 35225683 : case UNION_TYPE:
21903 : 35225683 : case QUAL_UNION_TYPE:
21904 : 35225683 : if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
21905 : 35225683 : && (decl_die = lookup_decl_die (TYPE_SIZE_UNIT (tree_node))))
21906 : : {
21907 : 0 : add_AT_die_ref (die, DW_AT_byte_size, decl_die);
21908 : 0 : return;
21909 : : }
21910 : 35225683 : size = int_size_in_bytes (tree_node);
21911 : 35225683 : break;
21912 : 270141 : case FIELD_DECL:
21913 : : /* For a data member of a struct or union, the DW_AT_byte_size is
21914 : : generally given as the number of bytes normally allocated for an
21915 : : object of the *declared* type of the member itself. This is true
21916 : : even for bit-fields. */
21917 : 270141 : size = int_size_in_bytes (field_type (tree_node));
21918 : 270141 : break;
21919 : 0 : default:
21920 : 0 : gcc_unreachable ();
21921 : : }
21922 : :
21923 : : /* Note that `size' might be -1 when we get to this point. If it is, that
21924 : : indicates that the byte size of the entity in question is variable. */
21925 : 35495824 : if (size >= 0)
21926 : 35495733 : add_AT_unsigned (die, DW_AT_byte_size, size);
21927 : :
21928 : : /* Support for dynamically-sized objects was introduced in DWARF3. */
21929 : 91 : else if (TYPE_P (tree_node)
21930 : 91 : && (dwarf_version >= 3 || !dwarf_strict)
21931 : 91 : && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL)
21932 : : {
21933 : 91 : struct loc_descr_context ctx = {
21934 : : const_cast<tree> (tree_node), /* context_type */
21935 : : NULL_TREE, /* base_decl */
21936 : : NULL, /* dpi */
21937 : : false, /* placeholder_arg */
21938 : : false, /* placeholder_seen */
21939 : : false /* strict_signedness */
21940 : 91 : };
21941 : :
21942 : 91 : tree tree_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (tree_node));
21943 : 91 : add_scalar_info (die, DW_AT_byte_size, tree_size,
21944 : : dw_scalar_form_constant
21945 : : | dw_scalar_form_exprloc
21946 : : | dw_scalar_form_reference,
21947 : : &ctx);
21948 : : }
21949 : : }
21950 : :
21951 : : /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
21952 : : alignment. */
21953 : :
21954 : : static void
21955 : 209242163 : add_alignment_attribute (dw_die_ref die, tree tree_node)
21956 : : {
21957 : 209242163 : if (dwarf_version < 5 && dwarf_strict)
21958 : : return;
21959 : :
21960 : 209242104 : unsigned align;
21961 : :
21962 : 209242104 : if (DECL_P (tree_node))
21963 : : {
21964 : 109041111 : if (!DECL_USER_ALIGN (tree_node))
21965 : : return;
21966 : :
21967 : 352228 : align = DECL_ALIGN_UNIT (tree_node);
21968 : : }
21969 : 100200993 : else if (TYPE_P (tree_node))
21970 : : {
21971 : 100200993 : if (!TYPE_USER_ALIGN (tree_node))
21972 : : return;
21973 : :
21974 : 977988 : align = TYPE_ALIGN_UNIT (tree_node);
21975 : : }
21976 : : else
21977 : 0 : gcc_unreachable ();
21978 : :
21979 : 1330216 : add_AT_unsigned (die, DW_AT_alignment, align);
21980 : : }
21981 : :
21982 : : /* For a FIELD_DECL node which represents a bit-field, output an attribute
21983 : : which specifies the distance in bits from the highest order bit of the
21984 : : "containing object" for the bit-field to the highest order bit of the
21985 : : bit-field itself.
21986 : :
21987 : : For any given bit-field, the "containing object" is a hypothetical object
21988 : : (of some integral or enum type) within which the given bit-field lives. The
21989 : : type of this hypothetical "containing object" is always the same as the
21990 : : declared type of the individual bit-field itself. The determination of the
21991 : : exact location of the "containing object" for a bit-field is rather
21992 : : complicated. It's handled by the `field_byte_offset' function (above).
21993 : :
21994 : : Note that it is the size (in bytes) of the hypothetical "containing object"
21995 : : which will be given in the DW_AT_byte_size attribute for this bit-field.
21996 : : (See `byte_size_attribute' above). */
21997 : :
21998 : : static inline void
21999 : 270141 : add_bit_offset_attribute (dw_die_ref die, tree decl)
22000 : : {
22001 : 270141 : HOST_WIDE_INT object_offset_in_bytes;
22002 : 270141 : tree original_type = DECL_BIT_FIELD_TYPE (decl);
22003 : 270141 : HOST_WIDE_INT bitpos_int;
22004 : 270141 : HOST_WIDE_INT highest_order_object_bit_offset;
22005 : 270141 : HOST_WIDE_INT highest_order_field_bit_offset;
22006 : 270141 : HOST_WIDE_INT bit_offset;
22007 : :
22008 : : /* The containing object is within the DECL_CONTEXT. */
22009 : 270141 : struct vlr_context ctx = { DECL_CONTEXT (decl), NULL_TREE };
22010 : :
22011 : 270141 : field_byte_offset (decl, &ctx, &object_offset_in_bytes);
22012 : :
22013 : : /* Must be a field and a bit field. */
22014 : 270141 : gcc_assert (original_type && TREE_CODE (decl) == FIELD_DECL);
22015 : :
22016 : : /* We can't yet handle bit-fields whose offsets are variable, so if we
22017 : : encounter such things, just return without generating any attribute
22018 : : whatsoever. Likewise for variable or too large size. */
22019 : 270141 : if (! tree_fits_shwi_p (bit_position (decl))
22020 : 270141 : || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
22021 : 16 : return;
22022 : :
22023 : 270125 : bitpos_int = int_bit_position (decl);
22024 : :
22025 : : /* Note that the bit offset is always the distance (in bits) from the
22026 : : highest-order bit of the "containing object" to the highest-order bit of
22027 : : the bit-field itself. Since the "high-order end" of any object or field
22028 : : is different on big-endian and little-endian machines, the computation
22029 : : below must take account of these differences. */
22030 : 270125 : highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
22031 : 270125 : highest_order_field_bit_offset = bitpos_int;
22032 : :
22033 : 270125 : if (! BYTES_BIG_ENDIAN)
22034 : : {
22035 : 270125 : highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
22036 : 540250 : highest_order_object_bit_offset +=
22037 : 270125 : simple_type_size_in_bits (original_type);
22038 : : }
22039 : :
22040 : 270125 : bit_offset
22041 : 270125 : = (! BYTES_BIG_ENDIAN
22042 : : ? highest_order_object_bit_offset - highest_order_field_bit_offset
22043 : : : highest_order_field_bit_offset - highest_order_object_bit_offset);
22044 : :
22045 : 270125 : if (bit_offset < 0)
22046 : 32 : add_AT_int (die, DW_AT_bit_offset, bit_offset);
22047 : : else
22048 : 270093 : add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
22049 : : }
22050 : :
22051 : : /* For a FIELD_DECL node which represents a bit field, output an attribute
22052 : : which specifies the length in bits of the given field. */
22053 : :
22054 : : static inline void
22055 : 270141 : add_bit_size_attribute (dw_die_ref die, tree decl)
22056 : : {
22057 : : /* Must be a field and a bit field. */
22058 : 270141 : gcc_assert (TREE_CODE (decl) == FIELD_DECL
22059 : : && DECL_BIT_FIELD_TYPE (decl));
22060 : :
22061 : 270141 : if (tree_fits_uhwi_p (DECL_SIZE (decl)))
22062 : 270141 : add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
22063 : 270141 : }
22064 : :
22065 : : /* If the compiled language is ANSI C, then add a 'prototyped'
22066 : : attribute, if arg types are given for the parameters of a function. */
22067 : :
22068 : : static inline void
22069 : 78398516 : add_prototyped_attribute (dw_die_ref die, tree func_type)
22070 : : {
22071 : 78398516 : switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
22072 : : {
22073 : 269470 : case DW_LANG_C:
22074 : 269470 : case DW_LANG_C89:
22075 : 269470 : case DW_LANG_C99:
22076 : 269470 : case DW_LANG_C11:
22077 : 269470 : case DW_LANG_ObjC:
22078 : 269470 : if (prototype_p (func_type))
22079 : 266095 : add_AT_flag (die, DW_AT_prototyped, 1);
22080 : : break;
22081 : : default:
22082 : : break;
22083 : : }
22084 : 78398516 : }
22085 : :
22086 : : /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
22087 : : by looking in the type declaration, the object declaration equate table or
22088 : : the block mapping. */
22089 : :
22090 : : static inline void
22091 : 22038622 : add_abstract_origin_attribute (dw_die_ref die, tree origin)
22092 : : {
22093 : 22038622 : dw_die_ref origin_die = NULL;
22094 : :
22095 : : /* For late LTO debug output we want to refer directly to the abstract
22096 : : DIE in the early debug rather to the possibly existing concrete
22097 : : instance and avoid creating that just for this purpose. */
22098 : 22038622 : sym_off_pair *desc;
22099 : 22038622 : if (in_lto_p
22100 : 8893 : && external_die_map
22101 : 22047514 : && (desc = external_die_map->get (origin)))
22102 : : {
22103 : 8624 : add_AT_external_die_ref (die, DW_AT_abstract_origin,
22104 : 8624 : desc->sym, desc->off);
22105 : 8624 : return;
22106 : : }
22107 : :
22108 : 22029998 : if (DECL_P (origin))
22109 : 21669569 : origin_die = lookup_decl_die (origin);
22110 : 360429 : else if (TYPE_P (origin))
22111 : 0 : origin_die = lookup_type_die (origin);
22112 : 360429 : else if (TREE_CODE (origin) == BLOCK)
22113 : 360429 : origin_die = lookup_block_die (origin);
22114 : :
22115 : : /* XXX: Functions that are never lowered don't always have correct block
22116 : : trees (in the case of java, they simply have no block tree, in some other
22117 : : languages). For these functions, there is nothing we can really do to
22118 : : output correct debug info for inlined functions in all cases. Rather
22119 : : than die, we'll just produce deficient debug info now, in that we will
22120 : : have variables without a proper abstract origin. In the future, when all
22121 : : functions are lowered, we should re-add a gcc_assert (origin_die)
22122 : : here. */
22123 : :
22124 : 22029998 : if (origin_die)
22125 : : {
22126 : 22023379 : dw_attr_node *a;
22127 : : /* Like above, if we already created a concrete instance DIE
22128 : : do not use that for the abstract origin but the early DIE
22129 : : if present. */
22130 : 22023379 : if (in_lto_p
22131 : 22023379 : && (a = get_AT (origin_die, DW_AT_abstract_origin)))
22132 : 258 : origin_die = AT_ref (a);
22133 : 22023379 : add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
22134 : : }
22135 : : }
22136 : :
22137 : : /* We do not currently support the pure_virtual attribute. */
22138 : :
22139 : : static inline void
22140 : 77996066 : add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
22141 : : {
22142 : 77996066 : if (DECL_VINDEX (func_decl))
22143 : : {
22144 : 865564 : add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
22145 : :
22146 : 865564 : if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
22147 : 618517 : add_AT_loc (die, DW_AT_vtable_elem_location,
22148 : : new_loc_descr (DW_OP_constu,
22149 : 618517 : tree_to_shwi (DECL_VINDEX (func_decl)),
22150 : : 0));
22151 : :
22152 : : /* GNU extension: Record what type this method came from originally. */
22153 : 865564 : if (debug_info_level > DINFO_LEVEL_TERSE
22154 : 865564 : && DECL_CONTEXT (func_decl))
22155 : 865526 : add_AT_die_ref (die, DW_AT_containing_type,
22156 : 865526 : lookup_type_die (DECL_CONTEXT (func_decl)));
22157 : : }
22158 : 77996066 : }
22159 : :
22160 : : /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
22161 : : given decl. This used to be a vendor extension until after DWARF 4
22162 : : standardized it. */
22163 : :
22164 : : static void
22165 : 88014919 : add_linkage_attr (dw_die_ref die, tree decl)
22166 : : {
22167 : 88014919 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
22168 : :
22169 : : /* Mimic what assemble_name_raw does with a leading '*'. */
22170 : 88014919 : if (name[0] == '*')
22171 : 441714 : name = &name[1];
22172 : :
22173 : 88014919 : if (dwarf_version >= 4)
22174 : 88010183 : add_AT_string (die, DW_AT_linkage_name, name);
22175 : : else
22176 : 4736 : add_AT_string (die, DW_AT_MIPS_linkage_name, name);
22177 : 88014919 : }
22178 : :
22179 : : /* Add source coordinate attributes for the given decl. */
22180 : :
22181 : : static void
22182 : 184385727 : add_src_coords_attributes (dw_die_ref die, tree decl)
22183 : : {
22184 : 184385727 : expanded_location s;
22185 : :
22186 : 184385727 : if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
22187 : 98084 : return;
22188 : 184287643 : s = expand_location (DECL_SOURCE_LOCATION (decl));
22189 : 184287643 : add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
22190 : 184287643 : add_AT_unsigned (die, DW_AT_decl_line, s.line);
22191 : 184287643 : if (debug_column_info && s.column)
22192 : 183487191 : add_AT_unsigned (die, DW_AT_decl_column, s.column);
22193 : : }
22194 : :
22195 : : /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
22196 : :
22197 : : static void
22198 : 93742117 : add_linkage_name_raw (dw_die_ref die, tree decl)
22199 : : {
22200 : : /* Defer until we have an assembler name set. */
22201 : 93742117 : if (!DECL_ASSEMBLER_NAME_SET_P (decl))
22202 : : {
22203 : 91709553 : limbo_die_node *asm_name;
22204 : :
22205 : 91709553 : asm_name = ggc_cleared_alloc<limbo_die_node> ();
22206 : 91709553 : asm_name->die = die;
22207 : 91709553 : asm_name->created_for = decl;
22208 : 91709553 : asm_name->next = deferred_asm_name;
22209 : 91709553 : deferred_asm_name = asm_name;
22210 : : }
22211 : 2032564 : else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
22212 : 1618890 : add_linkage_attr (die, decl);
22213 : 93742117 : }
22214 : :
22215 : : /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
22216 : :
22217 : : static void
22218 : 155614256 : add_linkage_name (dw_die_ref die, tree decl)
22219 : : {
22220 : 155614256 : if (debug_info_level > DINFO_LEVEL_NONE
22221 : 155614247 : && VAR_OR_FUNCTION_DECL_P (decl)
22222 : 95637130 : && TREE_PUBLIC (decl)
22223 : 93421827 : && !(VAR_P (decl) && DECL_REGISTER (decl))
22224 : 249036077 : && die->die_tag != DW_TAG_member)
22225 : 93421713 : add_linkage_name_raw (die, decl);
22226 : 155614256 : }
22227 : :
22228 : : /* Add a DW_AT_name attribute and source coordinate attribute for the
22229 : : given decl, but only if it actually has a name. */
22230 : :
22231 : : static void
22232 : 155896533 : add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
22233 : : bool no_linkage_name)
22234 : : {
22235 : 155896533 : tree decl_name;
22236 : :
22237 : 155896533 : decl_name = DECL_NAME (decl);
22238 : 311342930 : if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
22239 : : {
22240 : 155446397 : const char *name = dwarf2_name (decl, 0);
22241 : 155446397 : if (name)
22242 : 155440165 : add_name_attribute (die, name);
22243 : : else
22244 : 6232 : add_desc_attribute (die, decl);
22245 : :
22246 : 155446397 : if (! DECL_ARTIFICIAL (decl))
22247 : 149364585 : add_src_coords_attributes (die, decl);
22248 : :
22249 : 155446397 : if (!no_linkage_name)
22250 : 155186756 : add_linkage_name (die, decl);
22251 : : }
22252 : : else
22253 : 450136 : add_desc_attribute (die, decl);
22254 : :
22255 : : #ifdef VMS_DEBUGGING_INFO
22256 : : /* Get the function's name, as described by its RTL. This may be different
22257 : : from the DECL_NAME name used in the source file. */
22258 : : if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
22259 : : {
22260 : : add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
22261 : : XEXP (DECL_RTL (decl), 0), false);
22262 : : vec_safe_push (used_rtx_array, XEXP (DECL_RTL (decl), 0));
22263 : : }
22264 : : #endif /* VMS_DEBUGGING_INFO */
22265 : 155896533 : }
22266 : :
22267 : : /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
22268 : :
22269 : : static void
22270 : 0 : add_discr_value (dw_die_ref die, dw_discr_value *value)
22271 : : {
22272 : 0 : dw_attr_node attr;
22273 : :
22274 : 0 : attr.dw_attr = DW_AT_discr_value;
22275 : 0 : attr.dw_attr_val.val_class = dw_val_class_discr_value;
22276 : 0 : attr.dw_attr_val.val_entry = NULL;
22277 : 0 : attr.dw_attr_val.v.val_discr_value.pos = value->pos;
22278 : 0 : if (value->pos)
22279 : 0 : attr.dw_attr_val.v.val_discr_value.v.uval = value->v.uval;
22280 : : else
22281 : 0 : attr.dw_attr_val.v.val_discr_value.v.sval = value->v.sval;
22282 : 0 : add_dwarf_attr (die, &attr);
22283 : 0 : }
22284 : :
22285 : : /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
22286 : :
22287 : : static void
22288 : 0 : add_discr_list (dw_die_ref die, dw_discr_list_ref discr_list)
22289 : : {
22290 : 0 : dw_attr_node attr;
22291 : :
22292 : 0 : attr.dw_attr = DW_AT_discr_list;
22293 : 0 : attr.dw_attr_val.val_class = dw_val_class_discr_list;
22294 : 0 : attr.dw_attr_val.val_entry = NULL;
22295 : 0 : attr.dw_attr_val.v.val_discr_list = discr_list;
22296 : 0 : add_dwarf_attr (die, &attr);
22297 : 0 : }
22298 : :
22299 : : static inline dw_discr_list_ref
22300 : 0 : AT_discr_list (dw_attr_node *attr)
22301 : : {
22302 : 0 : return attr->dw_attr_val.v.val_discr_list;
22303 : : }
22304 : :
22305 : : #ifdef VMS_DEBUGGING_INFO
22306 : : /* Output the debug main pointer die for VMS */
22307 : :
22308 : : void
22309 : : dwarf2out_vms_debug_main_pointer (void)
22310 : : {
22311 : : char label[MAX_ARTIFICIAL_LABEL_BYTES];
22312 : : dw_die_ref die;
22313 : :
22314 : : /* Allocate the VMS debug main subprogram die. */
22315 : : die = new_die_raw (DW_TAG_subprogram);
22316 : : add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
22317 : : ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
22318 : : current_function_funcdef_no);
22319 : : add_AT_lbl_id (die, DW_AT_entry_pc, label);
22320 : :
22321 : : /* Make it the first child of comp_unit_die (). */
22322 : : die->die_parent = comp_unit_die ();
22323 : : if (comp_unit_die ()->die_child)
22324 : : {
22325 : : die->die_sib = comp_unit_die ()->die_child->die_sib;
22326 : : comp_unit_die ()->die_child->die_sib = die;
22327 : : }
22328 : : else
22329 : : {
22330 : : die->die_sib = die;
22331 : : comp_unit_die ()->die_child = die;
22332 : : }
22333 : : }
22334 : : #endif /* VMS_DEBUGGING_INFO */
22335 : :
22336 : : /* walk_tree helper function for uses_local_type, below. */
22337 : :
22338 : : static tree
22339 : 2200352 : uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
22340 : : {
22341 : 2200352 : if (!TYPE_P (*tp))
22342 : 0 : *walk_subtrees = 0;
22343 : : else
22344 : : {
22345 : 2200352 : tree name = TYPE_NAME (*tp);
22346 : 2200352 : if (name && DECL_P (name) && decl_function_context (name))
22347 : 80253 : return *tp;
22348 : : }
22349 : : return NULL_TREE;
22350 : : }
22351 : :
22352 : : /* If TYPE involves a function-local type (including a local typedef to a
22353 : : non-local type), returns that type; otherwise returns NULL_TREE. */
22354 : :
22355 : : static tree
22356 : 1122272 : uses_local_type (tree type)
22357 : : {
22358 : 1122272 : tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
22359 : 1122272 : return used;
22360 : : }
22361 : :
22362 : : /* Return the DIE for the scope that immediately contains this type.
22363 : : Non-named types that do not involve a function-local type get global
22364 : : scope. Named types nested in namespaces or other types get their
22365 : : containing scope. All other types (i.e. function-local named types) get
22366 : : the current active scope. */
22367 : :
22368 : : static dw_die_ref
22369 : 122718124 : scope_die_for (tree t, dw_die_ref context_die)
22370 : : {
22371 : 122718124 : dw_die_ref scope_die = NULL;
22372 : 122718124 : tree containing_scope;
22373 : :
22374 : : /* Non-types always go in the current scope. */
22375 : 122718124 : gcc_assert (TYPE_P (t));
22376 : :
22377 : : /* Use the scope of the typedef, rather than the scope of the type
22378 : : it refers to. */
22379 : 122718124 : if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
22380 : 94802083 : containing_scope = DECL_CONTEXT (TYPE_NAME (t));
22381 : : else
22382 : 27916041 : containing_scope = TYPE_CONTEXT (t);
22383 : :
22384 : : /* Use the containing namespace if there is one. */
22385 : 122718124 : if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
22386 : : {
22387 : 76282336 : if (context_die == lookup_decl_die (containing_scope))
22388 : : /* OK */;
22389 : 39963833 : else if (debug_info_level > DINFO_LEVEL_TERSE)
22390 : 39963833 : context_die = get_context_die (containing_scope);
22391 : : else
22392 : : containing_scope = NULL_TREE;
22393 : : }
22394 : :
22395 : : /* Ignore function type "scopes" from the C frontend. They mean that
22396 : : a tagged type is local to a parmlist of a function declarator, but
22397 : : that isn't useful to DWARF. */
22398 : 93705219 : if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
22399 : : containing_scope = NULL_TREE;
22400 : :
22401 : 93705188 : if (SCOPE_FILE_SCOPE_P (containing_scope))
22402 : : {
22403 : : /* If T uses a local type keep it local as well, to avoid references
22404 : : to function-local DIEs from outside the function. */
22405 : 31839823 : if (current_function_decl && uses_local_type (t))
22406 : : scope_die = context_die;
22407 : : else
22408 : 30637298 : scope_die = comp_unit_die ();
22409 : : }
22410 : 92000573 : else if (TYPE_P (containing_scope))
22411 : : {
22412 : : /* For types, we can just look up the appropriate DIE. */
22413 : 15210523 : if (debug_info_level > DINFO_LEVEL_TERSE)
22414 : 15210523 : scope_die = get_context_die (containing_scope);
22415 : : else
22416 : : {
22417 : 0 : scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
22418 : 0 : if (scope_die == NULL)
22419 : 0 : scope_die = comp_unit_die ();
22420 : : }
22421 : : }
22422 : : else
22423 : : scope_die = context_die;
22424 : :
22425 : 122718124 : return scope_die;
22426 : : }
22427 : :
22428 : : /* Returns true if CONTEXT_DIE is internal to a function. */
22429 : :
22430 : : static inline bool
22431 : : local_scope_p (dw_die_ref context_die)
22432 : : {
22433 : 336118497 : for (; context_die; context_die = context_die->die_parent)
22434 : 257148559 : if (context_die->die_tag == DW_TAG_inlined_subroutine
22435 : 257148558 : || context_die->die_tag == DW_TAG_subprogram)
22436 : : return true;
22437 : :
22438 : : return false;
22439 : : }
22440 : :
22441 : : /* Returns true if CONTEXT_DIE is a class. */
22442 : :
22443 : : static inline bool
22444 : 147384331 : class_scope_p (dw_die_ref context_die)
22445 : : {
22446 : 147384331 : return (context_die
22447 : 147384331 : && (context_die->die_tag == DW_TAG_structure_type
22448 : : || context_die->die_tag == DW_TAG_class_type
22449 : : || context_die->die_tag == DW_TAG_interface_type
22450 : 147384331 : || context_die->die_tag == DW_TAG_union_type));
22451 : : }
22452 : :
22453 : : /* Returns true if CONTEXT_DIE is a class or namespace, for deciding
22454 : : whether or not to treat a DIE in this context as a declaration. */
22455 : :
22456 : : static inline bool
22457 : 93754940 : class_or_namespace_scope_p (dw_die_ref context_die)
22458 : : {
22459 : 93754940 : return (class_scope_p (context_die)
22460 : 93754940 : || (context_die && context_die->die_tag == DW_TAG_namespace));
22461 : : }
22462 : :
22463 : : /* Many forms of DIEs require a "type description" attribute. This
22464 : : routine locates the proper "type descriptor" die for the type given
22465 : : by 'type' plus any additional qualifiers given by 'cv_quals', and
22466 : : adds a DW_AT_type attribute below the given die. */
22467 : :
22468 : : static void
22469 : 358635974 : add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
22470 : : bool reverse, dw_die_ref context_die)
22471 : : {
22472 : 358635974 : enum tree_code code = TREE_CODE (type);
22473 : 358635974 : dw_die_ref type_die = NULL;
22474 : :
22475 : 358635974 : if (debug_info_level <= DINFO_LEVEL_TERSE)
22476 : : return;
22477 : :
22478 : : /* ??? If this type is an unnamed subrange type of an integral, floating-point
22479 : : or fixed-point type, use the inner type. This is because we have no
22480 : : support for unnamed types in base_type_die. This can happen if this is
22481 : : an Ada subrange type. Correct solution is emit a subrange type die. */
22482 : 358634874 : if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
22483 : 83952994 : && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
22484 : 625 : type = TREE_TYPE (type), code = TREE_CODE (type);
22485 : :
22486 : 358634874 : if (code == ERROR_MARK
22487 : : /* Handle a special case. For functions whose return type is void, we
22488 : : generate *no* type attribute. (Note that no object may have type
22489 : : `void', so this only applies to function return types). */
22490 : 358634874 : || code == VOID_TYPE)
22491 : : return;
22492 : :
22493 : 995844225 : type_die = modified_type_die (type,
22494 : 331948075 : cv_quals | TYPE_QUALS (type),
22495 : : reverse,
22496 : : context_die);
22497 : :
22498 : 331948075 : if (type_die != NULL)
22499 : 331947965 : add_AT_die_ref (object_die, DW_AT_type, type_die);
22500 : : }
22501 : :
22502 : : /* Given an object die, add the calling convention attribute for the
22503 : : function call type. */
22504 : : static void
22505 : 79779992 : add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
22506 : : {
22507 : 79779992 : enum dwarf_calling_convention value = DW_CC_normal;
22508 : :
22509 : 159559984 : value = ((enum dwarf_calling_convention)
22510 : 79779992 : targetm.dwarf_calling_convention (TREE_TYPE (decl)));
22511 : :
22512 : 79779992 : if (is_fortran ()
22513 : 79779992 : && id_equal (DECL_ASSEMBLER_NAME (decl), "MAIN__"))
22514 : : {
22515 : : /* DWARF 2 doesn't provide a way to identify a program's source-level
22516 : : entry point. DW_AT_calling_convention attributes are only meant
22517 : : to describe functions' calling conventions. However, lacking a
22518 : : better way to signal the Fortran main program, we used this for
22519 : : a long time, following existing custom. Now, DWARF 4 has
22520 : : DW_AT_main_subprogram, which we add below, but some tools still
22521 : : rely on the old way, which we thus keep. */
22522 : 4192 : value = DW_CC_program;
22523 : :
22524 : 4192 : if (dwarf_version >= 4 || !dwarf_strict)
22525 : 4192 : add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
22526 : : }
22527 : :
22528 : : /* Only add the attribute if the backend requests it, and
22529 : : is not DW_CC_normal. */
22530 : 79779992 : if (value && (value != DW_CC_normal))
22531 : 4192 : add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
22532 : 79779992 : }
22533 : :
22534 : : /* Given a tree pointer to a struct, class, union, or enum type node, return
22535 : : a pointer to the (string) tag name for the given type, or zero if the type
22536 : : was declared without a tag. */
22537 : :
22538 : : static const char *
22539 : 39324685 : type_tag (const_tree type)
22540 : : {
22541 : 39324685 : const char *name = 0;
22542 : :
22543 : 39324685 : if (TYPE_NAME (type) != 0)
22544 : : {
22545 : 37877804 : tree t = 0;
22546 : :
22547 : : /* Find the IDENTIFIER_NODE for the type name. */
22548 : 37877804 : if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
22549 : 37877804 : && !TYPE_NAMELESS (type))
22550 : 269028 : t = TYPE_NAME (type);
22551 : :
22552 : : /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
22553 : : a TYPE_DECL node, regardless of whether or not a `typedef' was
22554 : : involved. */
22555 : 37608776 : else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
22556 : 37608776 : && ! DECL_IGNORED_P (TYPE_NAME (type)))
22557 : : {
22558 : : /* We want to be extra verbose. Don't call dwarf_name if
22559 : : DECL_NAME isn't set. The default hook for decl_printable_name
22560 : : doesn't like that, and in this context it's correct to return
22561 : : 0, instead of "<anonymous>" or the like. */
22562 : 37595385 : if (DECL_NAME (TYPE_NAME (type))
22563 : 37595385 : && !DECL_NAMELESS (TYPE_NAME (type)))
22564 : 37593865 : name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
22565 : : }
22566 : :
22567 : : /* Now get the name as a string, or invent one. */
22568 : 37877804 : if (!name && t != 0)
22569 : 269028 : name = IDENTIFIER_POINTER (t);
22570 : : }
22571 : :
22572 : 37877804 : return (name == 0 || *name == '\0') ? 0 : name;
22573 : : }
22574 : :
22575 : : /* Return the type associated with a data member, make a special check
22576 : : for bit field types. */
22577 : :
22578 : : static inline tree
22579 : 27784779 : member_declared_type (const_tree member)
22580 : : {
22581 : 27784779 : return (DECL_BIT_FIELD_TYPE (member)
22582 : 27784779 : ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
22583 : : }
22584 : :
22585 : : /* Get the decl's label, as described by its RTL. This may be different
22586 : : from the DECL_NAME name used in the source file. */
22587 : :
22588 : : #if 0
22589 : : static const char *
22590 : : decl_start_label (tree decl)
22591 : : {
22592 : : rtx x;
22593 : : const char *fnname;
22594 : :
22595 : : x = DECL_RTL (decl);
22596 : : gcc_assert (MEM_P (x));
22597 : :
22598 : : x = XEXP (x, 0);
22599 : : gcc_assert (GET_CODE (x) == SYMBOL_REF);
22600 : :
22601 : : fnname = XSTR (x, 0);
22602 : : return fnname;
22603 : : }
22604 : : #endif
22605 : :
22606 : : /* For variable-length arrays that have been previously generated, but
22607 : : may be incomplete due to missing subscript info, fill the subscript
22608 : : info. Return TRUE if this is one of those cases. */
22609 : :
22610 : : static bool
22611 : 9426455 : fill_variable_array_bounds (tree type)
22612 : : {
22613 : 9426455 : if (TREE_ASM_WRITTEN (type)
22614 : 3271828 : && TREE_CODE (type) == ARRAY_TYPE
22615 : 9430938 : && variably_modified_type_p (type, NULL))
22616 : : {
22617 : 4453 : dw_die_ref array_die = lookup_type_die (type);
22618 : 4453 : if (!array_die)
22619 : : return false;
22620 : 4453 : add_subscript_info (array_die, type, !is_ada ());
22621 : 4453 : return true;
22622 : : }
22623 : : return false;
22624 : : }
22625 : :
22626 : : /* These routines generate the internal representation of the DIE's for
22627 : : the compilation unit. Debugging information is collected by walking
22628 : : the declaration trees passed in from dwarf2out_decl(). */
22629 : :
22630 : : static void
22631 : 922255 : gen_array_type_die (tree type, dw_die_ref context_die)
22632 : : {
22633 : 922255 : dw_die_ref array_die;
22634 : :
22635 : : /* GNU compilers represent multidimensional array types as sequences of one
22636 : : dimensional array types whose element types are themselves array types.
22637 : : We sometimes squish that down to a single array_type DIE with multiple
22638 : : subscripts in the Dwarf debugging info. The draft Dwarf specification
22639 : : say that we are allowed to do this kind of compression in C, because
22640 : : there is no difference between an array of arrays and a multidimensional
22641 : : array. We don't do this for Ada to remain as close as possible to the
22642 : : actual representation, which is especially important against the language
22643 : : flexibilty wrt arrays of variable size. */
22644 : :
22645 : 922255 : bool collapse_nested_arrays = !is_ada ();
22646 : :
22647 : 922255 : if (fill_variable_array_bounds (type))
22648 : : return;
22649 : :
22650 : 917886 : dw_die_ref scope_die = scope_die_for (type, context_die);
22651 : 917886 : tree element_type;
22652 : :
22653 : : /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
22654 : : DW_TAG_string_type doesn't have DW_AT_type attribute). */
22655 : 917886 : if (TREE_CODE (type) == ARRAY_TYPE
22656 : 898116 : && TYPE_STRING_FLAG (type)
22657 : 4391 : && is_fortran ()
22658 : 922277 : && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
22659 : : {
22660 : 3996 : HOST_WIDE_INT size;
22661 : :
22662 : 3996 : array_die = new_die (DW_TAG_string_type, scope_die, type);
22663 : 3996 : add_name_attribute (array_die, type_tag (type));
22664 : 3996 : equate_type_number_to_die (type, array_die);
22665 : 3996 : size = int_size_in_bytes (type);
22666 : 3996 : if (size >= 0)
22667 : 1578 : add_AT_unsigned (array_die, DW_AT_byte_size, size);
22668 : : /* ??? We can't annotate types late, but for LTO we may not
22669 : : generate a location early either (gfortran.dg/save_6.f90). */
22670 : 1480 : else if (! (early_dwarf && (flag_generate_lto || flag_generate_offload))
22671 : 2418 : && TYPE_DOMAIN (type) != NULL_TREE
22672 : 4836 : && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE)
22673 : : {
22674 : 2211 : tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
22675 : 2211 : tree rszdecl = szdecl;
22676 : :
22677 : 2211 : size = int_size_in_bytes (TREE_TYPE (szdecl));
22678 : 2211 : if (!DECL_P (szdecl))
22679 : : {
22680 : 78 : if (INDIRECT_REF_P (szdecl)
22681 : 78 : && DECL_P (TREE_OPERAND (szdecl, 0)))
22682 : : {
22683 : 73 : rszdecl = TREE_OPERAND (szdecl, 0);
22684 : 146 : if (int_size_in_bytes (TREE_TYPE (rszdecl))
22685 : 73 : != DWARF2_ADDR_SIZE)
22686 : : size = 0;
22687 : : }
22688 : : else
22689 : : size = 0;
22690 : : }
22691 : 2206 : if (size > 0)
22692 : : {
22693 : 2206 : dw_loc_list_ref loc
22694 : 2279 : = loc_list_from_tree (rszdecl, szdecl == rszdecl ? 2 : 0,
22695 : : NULL);
22696 : 2206 : if (loc)
22697 : : {
22698 : 2028 : add_AT_location_description (array_die, DW_AT_string_length,
22699 : : loc);
22700 : 2040 : if (size != DWARF2_ADDR_SIZE)
22701 : 0 : add_AT_unsigned (array_die, dwarf_version >= 5
22702 : : ? DW_AT_string_length_byte_size
22703 : : : DW_AT_byte_size, size);
22704 : : }
22705 : : }
22706 : : }
22707 : 3996 : return;
22708 : : }
22709 : :
22710 : 913890 : array_die = new_die (DW_TAG_array_type, scope_die, type);
22711 : 913890 : add_name_attribute (array_die, type_tag (type));
22712 : 913890 : equate_type_number_to_die (type, array_die);
22713 : :
22714 : 913890 : if (VECTOR_TYPE_P (type))
22715 : 19770 : add_AT_flag (array_die, DW_AT_GNU_vector, 1);
22716 : :
22717 : : /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
22718 : 913890 : if (is_fortran ()
22719 : 9567 : && TREE_CODE (type) == ARRAY_TYPE
22720 : 9567 : && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
22721 : 916147 : && !TYPE_STRING_FLAG (TREE_TYPE (type)))
22722 : 1657 : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
22723 : :
22724 : : #if 0
22725 : : /* We default the array ordering. Debuggers will probably do the right
22726 : : things even if DW_AT_ordering is not present. It's not even an issue
22727 : : until we start to get into multidimensional arrays anyway. If a debugger
22728 : : is ever caught doing the Wrong Thing for multi-dimensional arrays,
22729 : : then we'll have to put the DW_AT_ordering attribute back in. (But if
22730 : : and when we find out that we need to put these in, we will only do so
22731 : : for multidimensional arrays. */
22732 : : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
22733 : : #endif
22734 : :
22735 : 913890 : if (VECTOR_TYPE_P (type))
22736 : : {
22737 : : /* For VECTOR_TYPEs we use an array DIE with appropriate bounds. */
22738 : 19770 : dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
22739 : 19770 : int lb = lower_bound_default ();
22740 : 19770 : if (lb == -1)
22741 : : lb = 0;
22742 : 19770 : add_bound_info (subrange_die, DW_AT_lower_bound, size_int (lb), NULL);
22743 : 19770 : add_bound_info (subrange_die, DW_AT_upper_bound,
22744 : 39540 : size_int (lb + TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
22745 : : }
22746 : : else
22747 : 894120 : add_subscript_info (array_die, type, collapse_nested_arrays);
22748 : :
22749 : : /* Add representation of the type of the elements of this array type and
22750 : : emit the corresponding DIE if we haven't done it already. */
22751 : 913890 : element_type = TREE_TYPE (type);
22752 : 913890 : if (collapse_nested_arrays)
22753 : 918072 : while (TREE_CODE (element_type) == ARRAY_TYPE)
22754 : : {
22755 : 4940 : if (TYPE_STRING_FLAG (element_type) && is_fortran ())
22756 : : break;
22757 : 4182 : element_type = TREE_TYPE (element_type);
22758 : : }
22759 : :
22760 : 913890 : add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED,
22761 : 913890 : TREE_CODE (type) == ARRAY_TYPE
22762 : 913890 : && TYPE_REVERSE_STORAGE_ORDER (type),
22763 : : context_die);
22764 : :
22765 : 913890 : add_gnat_descriptive_type_attribute (array_die, type, context_die);
22766 : 913890 : if (TYPE_ARTIFICIAL (type))
22767 : 0 : add_AT_flag (array_die, DW_AT_artificial, 1);
22768 : :
22769 : 913890 : if (get_AT (array_die, DW_AT_name))
22770 : 60 : add_pubtype (type, array_die);
22771 : :
22772 : 913890 : add_alignment_attribute (array_die, type);
22773 : : }
22774 : :
22775 : : /* This routine generates DIE for array with hidden descriptor, details
22776 : : are filled into *info by a langhook. */
22777 : :
22778 : : static void
22779 : 6692 : gen_descr_array_type_die (tree type, struct array_descr_info *info,
22780 : : dw_die_ref context_die)
22781 : : {
22782 : 6692 : const dw_die_ref scope_die = scope_die_for (type, context_die);
22783 : 6692 : const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
22784 : 6692 : struct loc_descr_context context = {
22785 : : type, /* context_type */
22786 : 6692 : info->base_decl, /* base_decl */
22787 : : NULL, /* dpi */
22788 : : false, /* placeholder_arg */
22789 : : false, /* placeholder_seen */
22790 : : false /* strict_signedness */
22791 : 6692 : };
22792 : 6692 : enum dwarf_tag subrange_tag = DW_TAG_subrange_type;
22793 : 6692 : int dim;
22794 : :
22795 : 6692 : add_name_attribute (array_die, type_tag (type));
22796 : 6692 : equate_type_number_to_die (type, array_die);
22797 : :
22798 : 6692 : if (info->ndimensions > 1)
22799 : 1632 : switch (info->ordering)
22800 : : {
22801 : 0 : case array_descr_ordering_row_major:
22802 : 0 : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
22803 : 0 : break;
22804 : 1632 : case array_descr_ordering_column_major:
22805 : 1632 : add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
22806 : 1632 : break;
22807 : : default:
22808 : : break;
22809 : : }
22810 : :
22811 : 6692 : if (dwarf_version >= 3 || !dwarf_strict)
22812 : : {
22813 : 6692 : if (info->data_location)
22814 : 6692 : add_scalar_info (array_die, DW_AT_data_location, info->data_location,
22815 : : dw_scalar_form_exprloc, &context);
22816 : 6692 : if (info->associated)
22817 : 1286 : add_scalar_info (array_die, DW_AT_associated, info->associated,
22818 : : dw_scalar_form_constant
22819 : : | dw_scalar_form_exprloc
22820 : : | dw_scalar_form_reference, &context);
22821 : 6692 : if (info->allocated)
22822 : 2416 : add_scalar_info (array_die, DW_AT_allocated, info->allocated,
22823 : : dw_scalar_form_constant
22824 : : | dw_scalar_form_exprloc
22825 : : | dw_scalar_form_reference, &context);
22826 : 6692 : if (info->stride)
22827 : : {
22828 : 0 : const enum dwarf_attribute attr
22829 : 0 : = (info->stride_in_bits) ? DW_AT_bit_stride : DW_AT_byte_stride;
22830 : 0 : const int forms
22831 : : = (info->stride_in_bits)
22832 : 0 : ? dw_scalar_form_constant
22833 : : : (dw_scalar_form_constant
22834 : : | dw_scalar_form_exprloc
22835 : : | dw_scalar_form_reference);
22836 : :
22837 : 0 : add_scalar_info (array_die, attr, info->stride, forms, &context);
22838 : : }
22839 : : }
22840 : 6692 : if (dwarf_version >= 5)
22841 : : {
22842 : 6692 : if (info->rank)
22843 : : {
22844 : 960 : add_scalar_info (array_die, DW_AT_rank, info->rank,
22845 : : dw_scalar_form_constant
22846 : : | dw_scalar_form_exprloc, &context);
22847 : 960 : subrange_tag = DW_TAG_generic_subrange;
22848 : 960 : context.placeholder_arg = true;
22849 : : }
22850 : : }
22851 : :
22852 : 6692 : add_gnat_descriptive_type_attribute (array_die, type, context_die);
22853 : :
22854 : 15631 : for (dim = 0; dim < info->ndimensions; dim++)
22855 : : {
22856 : 8939 : dw_die_ref subrange_die = new_die (subrange_tag, array_die, NULL);
22857 : :
22858 : 8939 : if (info->dimen[dim].bounds_type)
22859 : 0 : add_type_attribute (subrange_die,
22860 : : info->dimen[dim].bounds_type, TYPE_UNQUALIFIED,
22861 : : false, context_die);
22862 : 8939 : if (info->dimen[dim].lower_bound)
22863 : 8939 : add_bound_info (subrange_die, DW_AT_lower_bound,
22864 : : info->dimen[dim].lower_bound, &context);
22865 : 8939 : if (info->dimen[dim].upper_bound)
22866 : 8939 : add_bound_info (subrange_die, DW_AT_upper_bound,
22867 : : info->dimen[dim].upper_bound, &context);
22868 : 8939 : if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
22869 : 8939 : add_scalar_info (subrange_die, DW_AT_byte_stride,
22870 : : info->dimen[dim].stride,
22871 : : dw_scalar_form_constant
22872 : : | dw_scalar_form_exprloc
22873 : : | dw_scalar_form_reference,
22874 : : &context);
22875 : : }
22876 : :
22877 : 6692 : gen_type_die (info->element_type, context_die);
22878 : 6692 : add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
22879 : 6692 : TREE_CODE (type) == ARRAY_TYPE
22880 : 6692 : && TYPE_REVERSE_STORAGE_ORDER (type),
22881 : : context_die);
22882 : :
22883 : 6692 : if (get_AT (array_die, DW_AT_name))
22884 : 0 : add_pubtype (type, array_die);
22885 : :
22886 : 6692 : add_alignment_attribute (array_die, type);
22887 : 6692 : }
22888 : :
22889 : : #if 0
22890 : : static void
22891 : : gen_entry_point_die (tree decl, dw_die_ref context_die)
22892 : : {
22893 : : tree origin = decl_ultimate_origin (decl);
22894 : : dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
22895 : :
22896 : : if (origin != NULL)
22897 : : add_abstract_origin_attribute (decl_die, origin);
22898 : : else
22899 : : {
22900 : : add_name_and_src_coords_attributes (decl_die, decl);
22901 : : add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
22902 : : TYPE_UNQUALIFIED, false, context_die);
22903 : : }
22904 : :
22905 : : if (DECL_ABSTRACT_P (decl))
22906 : : equate_decl_number_to_die (decl, decl_die);
22907 : : else
22908 : : add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
22909 : : }
22910 : : #endif
22911 : :
22912 : : /* Walk through the list of incomplete types again, trying once more to
22913 : : emit full debugging info for them. */
22914 : :
22915 : : static void
22916 : 52411 : retry_incomplete_types (void)
22917 : : {
22918 : 52411 : set_early_dwarf s;
22919 : 52411 : int i;
22920 : :
22921 : 33460699 : for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
22922 : 33355877 : if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
22923 : 33355580 : gen_type_die ((*incomplete_types)[i], comp_unit_die ());
22924 : 52411 : vec_safe_truncate (incomplete_types, 0);
22925 : 52411 : }
22926 : :
22927 : : /* Determine what tag to use for a record type. */
22928 : :
22929 : : static enum dwarf_tag
22930 : 36354254 : record_type_tag (tree type)
22931 : : {
22932 : 36354254 : if (! lang_hooks.types.classify_record)
22933 : : return DW_TAG_structure_type;
22934 : :
22935 : 35724203 : switch (lang_hooks.types.classify_record (type))
22936 : : {
22937 : : case RECORD_IS_STRUCT:
22938 : : return DW_TAG_structure_type;
22939 : :
22940 : : case RECORD_IS_CLASS:
22941 : : return DW_TAG_class_type;
22942 : :
22943 : 0 : case RECORD_IS_INTERFACE:
22944 : 0 : if (dwarf_version >= 3 || !dwarf_strict)
22945 : : return DW_TAG_interface_type;
22946 : : return DW_TAG_structure_type;
22947 : :
22948 : 0 : default:
22949 : 0 : gcc_unreachable ();
22950 : : }
22951 : : }
22952 : :
22953 : : /* Generate a DIE to represent an enumeration type. Note that these DIEs
22954 : : include all of the information about the enumeration values also. Each
22955 : : enumerated type name/value is listed as a child of the enumerated type
22956 : : DIE. REVERSE is true if the type is to be interpreted in the reverse
22957 : : storage order wrt the target order. */
22958 : :
22959 : : static dw_die_ref
22960 : 1622906 : gen_enumeration_type_die (tree type, dw_die_ref context_die, bool reverse)
22961 : : {
22962 : 1622906 : dw_die_ref type_die = lookup_type_die (type);
22963 : 1622906 : dw_die_ref orig_type_die = type_die;
22964 : :
22965 : 1622906 : if (type_die == NULL || reverse)
22966 : : {
22967 : 1622486 : dw_die_ref scope_die = scope_die_for (type, context_die);
22968 : :
22969 : : /* The DIE with DW_AT_endianity is placed right after the naked DIE. */
22970 : 1622486 : if (reverse)
22971 : : {
22972 : 2 : gcc_assert (type_die);
22973 : 2 : dw_die_ref after_die = type_die;
22974 : 2 : type_die = new_die_raw (DW_TAG_enumeration_type);
22975 : 2 : add_child_die_after (scope_die, type_die, after_die);
22976 : : }
22977 : : else
22978 : : {
22979 : 1622484 : type_die = new_die (DW_TAG_enumeration_type, scope_die, type);
22980 : 1622484 : equate_type_number_to_die (type, type_die);
22981 : : }
22982 : 1622486 : add_name_attribute (type_die, type_tag (type));
22983 : 816 : if ((dwarf_version >= 4 || !dwarf_strict)
22984 : 3244972 : && ENUM_IS_SCOPED (type))
22985 : 232366 : add_AT_flag (type_die, DW_AT_enum_class, 1);
22986 : 1622486 : if (ENUM_IS_OPAQUE (type) && TYPE_SIZE (type))
22987 : 360 : add_AT_flag (type_die, DW_AT_declaration, 1);
22988 : 1622486 : if (!dwarf_strict)
22989 : 1622486 : add_AT_unsigned (type_die, DW_AT_encoding,
22990 : 1622486 : TYPE_UNSIGNED (type)
22991 : : ? DW_ATE_unsigned
22992 : : : DW_ATE_signed);
22993 : 1622486 : if (reverse)
22994 : 2 : add_AT_unsigned (type_die, DW_AT_endianity,
22995 : : BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
22996 : : }
22997 : 839 : else if (! TYPE_SIZE (type) || ENUM_IS_OPAQUE (type))
22998 : : return type_die;
22999 : : else
23000 : 7 : remove_AT (type_die, DW_AT_declaration);
23001 : :
23002 : : /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
23003 : : given enum type is incomplete, do not generate the DW_AT_byte_size
23004 : : attribute or the DW_AT_element_list attribute. */
23005 : 1622493 : if (TYPE_SIZE (type))
23006 : : {
23007 : 1622485 : tree link;
23008 : :
23009 : 1622485 : if (!ENUM_IS_OPAQUE (type))
23010 : 1622125 : TREE_ASM_WRITTEN (type) = 1;
23011 : 1622485 : if (!orig_type_die || !get_AT (type_die, DW_AT_byte_size))
23012 : 1622483 : add_byte_size_attribute (type_die, type);
23013 : 1622485 : if (!orig_type_die || !get_AT (type_die, DW_AT_alignment))
23014 : 1622485 : add_alignment_attribute (type_die, type);
23015 : 816 : if ((dwarf_version >= 3 || !dwarf_strict)
23016 : 1623301 : && (!orig_type_die || !get_AT (type_die, DW_AT_type)))
23017 : : {
23018 : 1622483 : tree underlying = lang_hooks.types.enum_underlying_base_type (type);
23019 : 1622483 : add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED, false,
23020 : : context_die);
23021 : : }
23022 : 1622485 : if (TYPE_STUB_DECL (type) != NULL_TREE)
23023 : : {
23024 : 1622459 : if (!orig_type_die || !get_AT (type_die, DW_AT_decl_file))
23025 : 1622457 : add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
23026 : 1622459 : if (!orig_type_die || !get_AT (type_die, DW_AT_accessibility))
23027 : 1622459 : add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
23028 : : }
23029 : :
23030 : : /* If the first reference to this type was as the return type of an
23031 : : inline function, then it may not have a parent. Fix this now. */
23032 : 1622485 : if (type_die->die_parent == NULL)
23033 : 7 : add_child_die (scope_die_for (type, context_die), type_die);
23034 : :
23035 : 1622485 : for (link = TYPE_VALUES (type);
23036 : 14734682 : link != NULL; link = TREE_CHAIN (link))
23037 : : {
23038 : 13112197 : dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
23039 : 13112197 : tree value = TREE_VALUE (link);
23040 : :
23041 : 13112197 : if (DECL_P (value))
23042 : 13103757 : equate_decl_number_to_die (value, enum_die);
23043 : :
23044 : 13112197 : gcc_assert (!ENUM_IS_OPAQUE (type));
23045 : 13112197 : add_name_attribute (enum_die,
23046 : 13112197 : IDENTIFIER_POINTER (TREE_PURPOSE (link)));
23047 : :
23048 : 13112197 : if (TREE_CODE (value) == CONST_DECL)
23049 : 13103757 : value = DECL_INITIAL (value);
23050 : :
23051 : 13112197 : if (simple_type_size_in_bits (TREE_TYPE (value))
23052 : 13112197 : <= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
23053 : : {
23054 : : /* For constant forms created by add_AT_unsigned DWARF
23055 : : consumers (GDB, elfutils, etc.) always zero extend
23056 : : the value. Only when the actual value is negative
23057 : : do we need to use add_AT_int to generate a constant
23058 : : form that can represent negative values. */
23059 : 13112195 : HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
23060 : 13112195 : if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
23061 : 12940579 : add_AT_unsigned (enum_die, DW_AT_const_value,
23062 : : (unsigned HOST_WIDE_INT) val);
23063 : : else
23064 : 171616 : add_AT_int (enum_die, DW_AT_const_value, val);
23065 : : }
23066 : : else
23067 : : /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
23068 : : that here. TODO: This should be re-worked to use correct
23069 : : signed/unsigned double tags for all cases. */
23070 : 2 : add_AT_wide (enum_die, DW_AT_const_value, wi::to_wide (value));
23071 : : }
23072 : :
23073 : 1622485 : add_gnat_descriptive_type_attribute (type_die, type, context_die);
23074 : 1622485 : if (TYPE_ARTIFICIAL (type)
23075 : 1622485 : && (!orig_type_die || !get_AT (type_die, DW_AT_artificial)))
23076 : 0 : add_AT_flag (type_die, DW_AT_artificial, 1);
23077 : : }
23078 : : else
23079 : 8 : add_AT_flag (type_die, DW_AT_declaration, 1);
23080 : :
23081 : 1622493 : add_pubtype (type, type_die);
23082 : :
23083 : 1622493 : return type_die;
23084 : : }
23085 : :
23086 : : /* Generate a DIE to represent either a real live formal parameter decl or to
23087 : : represent just the type of some formal parameter position in some function
23088 : : type.
23089 : :
23090 : : Note that this routine is a bit unusual because its argument may be a
23091 : : ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
23092 : : represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
23093 : : node. If it's the former then this function is being called to output a
23094 : : DIE to represent a formal parameter object (or some inlining thereof). If
23095 : : it's the latter, then this function is only being called to output a
23096 : : DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
23097 : : argument type of some subprogram type.
23098 : : If EMIT_NAME_P is true, name and source coordinate attributes
23099 : : are emitted. */
23100 : :
23101 : : static dw_die_ref
23102 : 164074559 : gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
23103 : : dw_die_ref context_die)
23104 : : {
23105 : 164074559 : tree node_or_origin = node ? node : origin;
23106 : 164074559 : tree ultimate_origin;
23107 : 164074559 : dw_die_ref parm_die = NULL;
23108 : :
23109 : 164074559 : if (DECL_P (node_or_origin))
23110 : : {
23111 : 17288875 : parm_die = lookup_decl_die (node);
23112 : :
23113 : : /* If the contexts differ, we may not be talking about the same
23114 : : thing.
23115 : : ??? When in LTO the DIE parent is the "abstract" copy and the
23116 : : context_die is the specification "copy". */
23117 : 17288875 : if (parm_die
23118 : 975383 : && parm_die->die_parent != context_die
23119 : 81866 : && (parm_die->die_parent->die_tag != DW_TAG_GNU_formal_parameter_pack
23120 : 2952 : || parm_die->die_parent->die_parent != context_die)
23121 : 79139 : && !in_lto_p)
23122 : : {
23123 : 79139 : gcc_assert (!DECL_ABSTRACT_P (node));
23124 : : /* This can happen when creating a concrete instance, in
23125 : : which case we need to create a new DIE that will get
23126 : : annotated with DW_AT_abstract_origin. */
23127 : : parm_die = NULL;
23128 : : }
23129 : :
23130 : 896244 : if (parm_die && parm_die->die_parent == NULL)
23131 : : {
23132 : : /* Check that parm_die already has the right attributes that
23133 : : we would have added below. If any attributes are
23134 : : missing, fall through to add them. */
23135 : 0 : if (! DECL_ABSTRACT_P (node_or_origin)
23136 : 0 : && !get_AT (parm_die, DW_AT_location)
23137 : 0 : && !get_AT (parm_die, DW_AT_const_value))
23138 : : /* We are missing location info, and are about to add it. */
23139 : : ;
23140 : : else
23141 : : {
23142 : 0 : add_child_die (context_die, parm_die);
23143 : 0 : return parm_die;
23144 : : }
23145 : : }
23146 : : }
23147 : :
23148 : : /* If we have a previously generated DIE, use it, unless this is an
23149 : : concrete instance (origin != NULL), in which case we need a new
23150 : : DIE with a corresponding DW_AT_abstract_origin. */
23151 : 164074559 : bool reusing_die;
23152 : 164074559 : if (parm_die && origin == NULL)
23153 : : reusing_die = true;
23154 : : else
23155 : : {
23156 : 163178315 : parm_die = new_die (DW_TAG_formal_parameter, context_die, node);
23157 : 163178315 : reusing_die = false;
23158 : : }
23159 : :
23160 : 164074559 : switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
23161 : : {
23162 : 17288875 : case tcc_declaration:
23163 : 17288875 : ultimate_origin = decl_ultimate_origin (node_or_origin);
23164 : 17288875 : if (node || ultimate_origin)
23165 : 17288875 : origin = ultimate_origin;
23166 : :
23167 : 17288875 : if (reusing_die)
23168 : 896244 : goto add_location;
23169 : :
23170 : 16392631 : if (origin != NULL)
23171 : 12883982 : add_abstract_origin_attribute (parm_die, origin);
23172 : 3508649 : else if (emit_name_p)
23173 : 3425209 : add_name_and_src_coords_attributes (parm_die, node);
23174 : 16392631 : if (origin == NULL
23175 : 16392631 : || (! DECL_ABSTRACT_P (node_or_origin)
23176 : 12883982 : && variably_modified_type_p (TREE_TYPE (node_or_origin),
23177 : : decl_function_context
23178 : : (node_or_origin))))
23179 : : {
23180 : 3510346 : tree type = TREE_TYPE (node_or_origin);
23181 : 3510346 : if (decl_by_reference_p (node_or_origin))
23182 : 41767 : add_type_attribute (parm_die, TREE_TYPE (type),
23183 : : TYPE_UNQUALIFIED,
23184 : : false, context_die);
23185 : : else
23186 : 3468579 : add_type_attribute (parm_die, type,
23187 : : decl_quals (node_or_origin),
23188 : : false, context_die);
23189 : : }
23190 : 16392631 : if (origin == NULL && DECL_ARTIFICIAL (node))
23191 : 1021950 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23192 : 17288875 : add_location:
23193 : 17288875 : if (node && node != origin)
23194 : 17209684 : equate_decl_number_to_die (node, parm_die);
23195 : 17288875 : if (! DECL_ABSTRACT_P (node_or_origin))
23196 : 17288875 : add_location_or_const_value_attribute (parm_die, node_or_origin,
23197 : : node == NULL);
23198 : :
23199 : : break;
23200 : :
23201 : 146785684 : case tcc_type:
23202 : : /* We were called with some kind of a ..._TYPE node. */
23203 : 146785684 : add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED, false,
23204 : : context_die);
23205 : 146785684 : break;
23206 : :
23207 : 0 : default:
23208 : 0 : gcc_unreachable ();
23209 : : }
23210 : :
23211 : : return parm_die;
23212 : : }
23213 : :
23214 : : /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
23215 : : children DW_TAG_formal_parameter DIEs representing the arguments of the
23216 : : parameter pack.
23217 : :
23218 : : PARM_PACK must be a function parameter pack.
23219 : : PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
23220 : : must point to the subsequent arguments of the function PACK_ARG belongs to.
23221 : : SUBR_DIE is the DIE of the function PACK_ARG belongs to.
23222 : : If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
23223 : : following the last one for which a DIE was generated. */
23224 : :
23225 : : static dw_die_ref
23226 : 77026 : gen_formal_parameter_pack_die (tree parm_pack,
23227 : : tree pack_arg,
23228 : : dw_die_ref subr_die,
23229 : : tree *next_arg)
23230 : : {
23231 : 77026 : tree arg;
23232 : 77026 : dw_die_ref parm_pack_die;
23233 : :
23234 : 77026 : gcc_assert (parm_pack
23235 : : && lang_hooks.function_parameter_pack_p (parm_pack)
23236 : : && subr_die);
23237 : :
23238 : 77026 : parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
23239 : 77026 : add_name_and_src_coords_attributes (parm_pack_die, parm_pack);
23240 : :
23241 : 252151 : for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
23242 : : {
23243 : 98099 : if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
23244 : : parm_pack))
23245 : : break;
23246 : 98099 : gen_formal_parameter_die (arg, NULL,
23247 : : false /* Don't emit name attribute. */,
23248 : : parm_pack_die);
23249 : : }
23250 : 77026 : if (next_arg)
23251 : 77026 : *next_arg = arg;
23252 : 77026 : return parm_pack_die;
23253 : : }
23254 : :
23255 : : /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
23256 : : at the end of an (ANSI prototyped) formal parameters list. */
23257 : :
23258 : : static void
23259 : 99792 : gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
23260 : : {
23261 : 0 : new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
23262 : 99792 : }
23263 : :
23264 : : /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
23265 : : DW_TAG_unspecified_parameters DIE) to represent the types of the formal
23266 : : parameters as specified in some function type specification (except for
23267 : : those which appear as part of a function *definition*). */
23268 : :
23269 : : static void
23270 : 77957862 : gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
23271 : : {
23272 : 77957862 : tree link;
23273 : 77957862 : tree formal_type = NULL;
23274 : 77957862 : tree first_parm_type;
23275 : 77957862 : tree arg;
23276 : :
23277 : 77957862 : if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
23278 : : {
23279 : 77541709 : arg = DECL_ARGUMENTS (function_or_method_type);
23280 : 77541709 : function_or_method_type = TREE_TYPE (function_or_method_type);
23281 : : }
23282 : : else
23283 : : arg = NULL_TREE;
23284 : :
23285 : 77957862 : first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
23286 : :
23287 : : /* Make our first pass over the list of formal parameter types and output a
23288 : : DW_TAG_formal_parameter DIE for each one. */
23289 : 224743546 : for (link = first_parm_type; link; )
23290 : : {
23291 : 224648208 : dw_die_ref parm_die;
23292 : :
23293 : 224648208 : formal_type = TREE_VALUE (link);
23294 : 224648208 : if (formal_type == void_type_node)
23295 : : break;
23296 : :
23297 : : /* Output a (nameless) DIE to represent the formal parameter itself. */
23298 : 146785684 : parm_die = gen_formal_parameter_die (formal_type, NULL,
23299 : : true /* Emit name attribute. */,
23300 : : context_die);
23301 : 146785684 : if (TREE_CODE (function_or_method_type) == METHOD_TYPE
23302 : 133479664 : && link == first_parm_type)
23303 : : {
23304 : 66350868 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23305 : 66350868 : if (dwarf_version >= 3 || !dwarf_strict)
23306 : 66350868 : add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
23307 : : }
23308 : 80434816 : else if (arg && DECL_ARTIFICIAL (arg))
23309 : 23256 : add_AT_flag (parm_die, DW_AT_artificial, 1);
23310 : :
23311 : 146785684 : link = TREE_CHAIN (link);
23312 : 146785684 : if (arg)
23313 : 146029635 : arg = DECL_CHAIN (arg);
23314 : : }
23315 : :
23316 : : /* If this function type has an ellipsis, add a
23317 : : DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
23318 : 77957862 : if (formal_type != void_type_node)
23319 : 95338 : gen_unspecified_parameters_die (function_or_method_type, context_die);
23320 : :
23321 : : /* Make our second (and final) pass over the list of formal parameter types
23322 : : and output DIEs to represent those types (as necessary). */
23323 : 77957862 : for (link = TYPE_ARG_TYPES (function_or_method_type);
23324 : 527254278 : link && TREE_VALUE (link);
23325 : 224648208 : link = TREE_CHAIN (link))
23326 : 224648208 : gen_type_die (TREE_VALUE (link), context_die);
23327 : 77957862 : }
23328 : :
23329 : : /* We want to generate the DIE for TYPE so that we can generate the
23330 : : die for MEMBER, which has been defined; we will need to refer back
23331 : : to the member declaration nested within TYPE. If we're trying to
23332 : : generate minimal debug info for TYPE, processing TYPE won't do the
23333 : : trick; we need to attach the member declaration by hand. */
23334 : :
23335 : : static void
23336 : 93062351 : gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
23337 : : {
23338 : 93062351 : gen_type_die (type, context_die);
23339 : :
23340 : : /* If we're trying to avoid duplicate debug info, we may not have
23341 : : emitted the member decl for this function. Emit it now. */
23342 : 93062351 : if (TYPE_STUB_DECL (type)
23343 : 93062351 : && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
23344 : 93275657 : && ! lookup_decl_die (member))
23345 : : {
23346 : 126372 : dw_die_ref type_die;
23347 : 126372 : gcc_assert (!decl_ultimate_origin (member));
23348 : :
23349 : 126372 : type_die = lookup_type_die_strip_naming_typedef (type);
23350 : 126372 : if (TREE_CODE (member) == FUNCTION_DECL)
23351 : 125717 : gen_subprogram_die (member, type_die);
23352 : 655 : else if (TREE_CODE (member) == FIELD_DECL)
23353 : : {
23354 : : /* Ignore the nameless fields that are used to skip bits but handle
23355 : : C++ anonymous unions and structs. */
23356 : 6 : if (DECL_NAME (member) != NULL_TREE
23357 : 0 : || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
23358 : 6 : || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
23359 : : {
23360 : 6 : struct vlr_context vlr_ctx = {
23361 : 6 : DECL_CONTEXT (member), /* struct_type */
23362 : : NULL_TREE /* variant_part_offset */
23363 : 6 : };
23364 : 6 : gen_type_die (member_declared_type (member), type_die);
23365 : 6 : gen_field_die (member, &vlr_ctx, type_die);
23366 : : }
23367 : : }
23368 : : else
23369 : 649 : gen_variable_die (member, NULL_TREE, type_die);
23370 : : }
23371 : 93062351 : }
23372 : :
23373 : : /* Forward declare these functions, because they are mutually recursive
23374 : : with their set_block_* pairing functions. */
23375 : : static void set_decl_origin_self (tree);
23376 : :
23377 : : /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
23378 : : given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
23379 : : that it points to the node itself, thus indicating that the node is its
23380 : : own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
23381 : : the given node is NULL, recursively descend the decl/block tree which
23382 : : it is the root of, and for each other ..._DECL or BLOCK node contained
23383 : : therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
23384 : : still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
23385 : : values to point to themselves. */
23386 : :
23387 : : static void
23388 : 2823342 : set_block_origin_self (tree stmt)
23389 : : {
23390 : 2823342 : if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
23391 : : {
23392 : 1735492 : BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
23393 : :
23394 : 1735492 : {
23395 : 1735492 : tree local_decl;
23396 : :
23397 : 1735492 : for (local_decl = BLOCK_VARS (stmt);
23398 : 2495579 : local_decl != NULL_TREE;
23399 : 760087 : local_decl = DECL_CHAIN (local_decl))
23400 : : /* Do not recurse on nested functions since the inlining status
23401 : : of parent and child can be different as per the DWARF spec. */
23402 : 760087 : if (TREE_CODE (local_decl) != FUNCTION_DECL
23403 : 760087 : && !DECL_EXTERNAL (local_decl))
23404 : 756777 : set_decl_origin_self (local_decl);
23405 : : }
23406 : :
23407 : 1735492 : {
23408 : 1735492 : tree subblock;
23409 : :
23410 : 3198073 : for (subblock = BLOCK_SUBBLOCKS (stmt);
23411 : 3198073 : subblock != NULL_TREE;
23412 : 1462581 : subblock = BLOCK_CHAIN (subblock))
23413 : 1462581 : set_block_origin_self (subblock); /* Recurse. */
23414 : : }
23415 : : }
23416 : 2823342 : }
23417 : :
23418 : : /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
23419 : : the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
23420 : : node to so that it points to the node itself, thus indicating that the
23421 : : node represents its own (abstract) origin. Additionally, if the
23422 : : DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
23423 : : the decl/block tree of which the given node is the root of, and for
23424 : : each other ..._DECL or BLOCK node contained therein whose
23425 : : DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
23426 : : set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
23427 : : point to themselves. */
23428 : :
23429 : : static void
23430 : 2133478 : set_decl_origin_self (tree decl)
23431 : : {
23432 : 2133478 : if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
23433 : : {
23434 : 2133478 : DECL_ABSTRACT_ORIGIN (decl) = decl;
23435 : 2133478 : if (TREE_CODE (decl) == FUNCTION_DECL)
23436 : : {
23437 : 1376701 : tree arg;
23438 : :
23439 : 3968163 : for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
23440 : 2591462 : DECL_ABSTRACT_ORIGIN (arg) = arg;
23441 : 1376701 : if (DECL_INITIAL (decl) != NULL_TREE
23442 : 1376701 : && DECL_INITIAL (decl) != error_mark_node)
23443 : 1360761 : set_block_origin_self (DECL_INITIAL (decl));
23444 : : }
23445 : : }
23446 : 2133478 : }
23447 : :
23448 : : /* Mark the early DIE for DECL as the abstract instance. */
23449 : :
23450 : : static void
23451 : 4402480 : dwarf2out_abstract_function (tree decl)
23452 : : {
23453 : 4402480 : dw_die_ref old_die;
23454 : :
23455 : : /* Make sure we have the actual abstract inline, not a clone. */
23456 : 4402480 : decl = DECL_ORIGIN (decl);
23457 : :
23458 : 4402480 : if (DECL_IGNORED_P (decl))
23459 : : return;
23460 : :
23461 : : #ifdef CODEVIEW_DEBUGGING_INFO
23462 : : if (codeview_debuginfo_p ())
23463 : : codeview_abstract_function (decl);
23464 : : #endif
23465 : :
23466 : : /* In LTO we're all set. We already created abstract instances
23467 : : early and we want to avoid creating a concrete instance of that
23468 : : if we don't output it. */
23469 : 4402439 : if (in_lto_p)
23470 : : return;
23471 : :
23472 : 4402027 : old_die = lookup_decl_die (decl);
23473 : 4402027 : gcc_assert (old_die != NULL);
23474 : 4402027 : if (get_AT (old_die, DW_AT_inline))
23475 : : /* We've already generated the abstract instance. */
23476 : : return;
23477 : :
23478 : : /* Go ahead and put DW_AT_inline on the DIE. */
23479 : 1376701 : if (DECL_DECLARED_INLINE_P (decl))
23480 : : {
23481 : 1253309 : if (cgraph_function_possibly_inlined_p (decl))
23482 : 932823 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_inlined);
23483 : : else
23484 : 320486 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_not_inlined);
23485 : : }
23486 : : else
23487 : : {
23488 : 123392 : if (cgraph_function_possibly_inlined_p (decl))
23489 : 102858 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_inlined);
23490 : : else
23491 : 20534 : add_AT_unsigned (old_die, DW_AT_inline, DW_INL_not_inlined);
23492 : : }
23493 : :
23494 : 1376701 : if (DECL_DECLARED_INLINE_P (decl)
23495 : 1376701 : && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
23496 : 1290 : add_AT_flag (old_die, DW_AT_artificial, 1);
23497 : :
23498 : 1376701 : set_decl_origin_self (decl);
23499 : : }
23500 : :
23501 : : /* Helper function of premark_used_types() which gets called through
23502 : : htab_traverse.
23503 : :
23504 : : Marks the DIE of a given type in *SLOT as perennial, so it never gets
23505 : : marked as unused by prune_unused_types. */
23506 : :
23507 : : bool
23508 : 1230853 : premark_used_types_helper (tree const &type, void *)
23509 : : {
23510 : 1230853 : dw_die_ref die;
23511 : :
23512 : 1230853 : die = lookup_type_die (type);
23513 : 1230853 : if (die != NULL)
23514 : 1109694 : die->die_perennial_p = 1;
23515 : 1230853 : return true;
23516 : : }
23517 : :
23518 : : /* Helper function of premark_types_used_by_global_vars which gets called
23519 : : through htab_traverse.
23520 : :
23521 : : Marks the DIE of a given type in *SLOT as perennial, so it never gets
23522 : : marked as unused by prune_unused_types. The DIE of the type is marked
23523 : : only if the global variable using the type will actually be emitted. */
23524 : :
23525 : : int
23526 : 4583542 : premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
23527 : : void *)
23528 : : {
23529 : 4583542 : struct types_used_by_vars_entry *entry;
23530 : 4583542 : dw_die_ref die;
23531 : :
23532 : 4583542 : entry = (struct types_used_by_vars_entry *) *slot;
23533 : 4583542 : gcc_assert (entry->type != NULL
23534 : : && entry->var_decl != NULL);
23535 : 4583542 : die = lookup_type_die (entry->type);
23536 : 4583542 : if (die)
23537 : : {
23538 : : /* Ask cgraph if the global variable really is to be emitted.
23539 : : If yes, then we'll keep the DIE of ENTRY->TYPE. */
23540 : 4351587 : varpool_node *node = varpool_node::get (entry->var_decl);
23541 : 4351587 : if (node && node->definition)
23542 : : {
23543 : 12486 : die->die_perennial_p = 1;
23544 : : /* Keep the parent DIEs as well. */
23545 : 21522 : while ((die = die->die_parent) && die->die_perennial_p == 0)
23546 : 9036 : die->die_perennial_p = 1;
23547 : : }
23548 : : }
23549 : 4583542 : return 1;
23550 : : }
23551 : :
23552 : : /* Mark all members of used_types_hash as perennial. */
23553 : :
23554 : : static void
23555 : 80314320 : premark_used_types (struct function *fun)
23556 : : {
23557 : 80314320 : if (fun && fun->used_types_hash)
23558 : 2043342 : fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
23559 : 80314320 : }
23560 : :
23561 : : /* Mark all members of types_used_by_vars_entry as perennial. */
23562 : :
23563 : : static void
23564 : 52443 : premark_types_used_by_global_vars (void)
23565 : : {
23566 : 52443 : if (types_used_by_vars_hash)
23567 : 14163 : types_used_by_vars_hash
23568 : 4597705 : ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
23569 : 52443 : }
23570 : :
23571 : : /* Mark all variables used by the symtab as perennial. */
23572 : :
23573 : : static void
23574 : 52411 : premark_used_variables (void)
23575 : : {
23576 : : /* Mark DIEs in the symtab as used. */
23577 : 52411 : varpool_node *var;
23578 : 4019116 : FOR_EACH_VARIABLE (var)
23579 : : {
23580 : 1957147 : dw_die_ref die = lookup_decl_die (var->decl);
23581 : 1957147 : if (die)
23582 : 269748 : die->die_perennial_p = 1;
23583 : : }
23584 : 52411 : }
23585 : :
23586 : : /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
23587 : : for CA_LOC call arg loc node. */
23588 : :
23589 : : static dw_die_ref
23590 : 2884647 : gen_call_site_die (tree decl, dw_die_ref subr_die,
23591 : : struct call_arg_loc_node *ca_loc)
23592 : : {
23593 : 2884647 : dw_die_ref stmt_die = NULL, die;
23594 : 2884647 : tree block = ca_loc->block;
23595 : :
23596 : 2884647 : while (block
23597 : 5489297 : && block != DECL_INITIAL (decl)
23598 : 10055093 : && TREE_CODE (block) == BLOCK)
23599 : : {
23600 : 4499583 : stmt_die = lookup_block_die (block);
23601 : 4499583 : if (stmt_die)
23602 : : break;
23603 : 2670863 : block = BLOCK_SUPERCONTEXT (block);
23604 : : }
23605 : 2884647 : if (stmt_die == NULL)
23606 : 1055927 : stmt_die = subr_die;
23607 : 2886500 : die = new_die (dwarf_TAG (DW_TAG_call_site), stmt_die, NULL_TREE);
23608 : 2886500 : add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc),
23609 : : ca_loc->label,
23610 : 2884647 : targetm.calls.call_offset_return_label (ca_loc->call_insn));
23611 : 2884647 : if (ca_loc->tail_call_p)
23612 : 55913 : add_AT_flag (die, dwarf_AT (DW_AT_call_tail_call), 1);
23613 : 2884647 : if (ca_loc->symbol_ref)
23614 : : {
23615 : 2808040 : dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
23616 : 2808040 : if (tdie)
23617 : 1353040 : add_AT_die_ref (die, dwarf_AT (DW_AT_call_origin), tdie);
23618 : : else
23619 : 1456831 : add_AT_addr (die, dwarf_AT (DW_AT_call_origin), ca_loc->symbol_ref,
23620 : : false);
23621 : : }
23622 : 2884647 : return die;
23623 : : }
23624 : :
23625 : : /* Generate a DIE to represent a declared function (either file-scope or
23626 : : block-local). */
23627 : :
23628 : : static void
23629 : 80446146 : gen_subprogram_die (tree decl, dw_die_ref context_die)
23630 : : {
23631 : 80446146 : tree origin = decl_ultimate_origin (decl);
23632 : 80446146 : dw_die_ref subr_die;
23633 : 80446146 : dw_die_ref old_die = lookup_decl_die (decl);
23634 : 80446146 : bool old_die_had_no_children = false;
23635 : :
23636 : : /* This function gets called multiple times for different stages of
23637 : : the debug process. For example, for func() in this code:
23638 : :
23639 : : namespace S
23640 : : {
23641 : : void func() { ... }
23642 : : }
23643 : :
23644 : : ...we get called 4 times. Twice in early debug and twice in
23645 : : late debug:
23646 : :
23647 : : Early debug
23648 : : -----------
23649 : :
23650 : : 1. Once while generating func() within the namespace. This is
23651 : : the declaration. The declaration bit below is set, as the
23652 : : context is the namespace.
23653 : :
23654 : : A new DIE will be generated with DW_AT_declaration set.
23655 : :
23656 : : 2. Once for func() itself. This is the specification. The
23657 : : declaration bit below is clear as the context is the CU.
23658 : :
23659 : : We will use the cached DIE from (1) to create a new DIE with
23660 : : DW_AT_specification pointing to the declaration in (1).
23661 : :
23662 : : Late debug via rest_of_handle_final()
23663 : : -------------------------------------
23664 : :
23665 : : 3. Once generating func() within the namespace. This is also the
23666 : : declaration, as in (1), but this time we will early exit below
23667 : : as we have a cached DIE and a declaration needs no additional
23668 : : annotations (no locations), as the source declaration line
23669 : : info is enough.
23670 : :
23671 : : 4. Once for func() itself. As in (2), this is the specification,
23672 : : but this time we will re-use the cached DIE, and just annotate
23673 : : it with the location information that should now be available.
23674 : :
23675 : : For something without namespaces, but with abstract instances, we
23676 : : are also called a multiple times:
23677 : :
23678 : : class Base
23679 : : {
23680 : : public:
23681 : : Base (); // constructor declaration (1)
23682 : : };
23683 : :
23684 : : Base::Base () { } // constructor specification (2)
23685 : :
23686 : : Early debug
23687 : : -----------
23688 : :
23689 : : 1. Once for the Base() constructor by virtue of it being a
23690 : : member of the Base class. This is done via
23691 : : rest_of_type_compilation.
23692 : :
23693 : : This is a declaration, so a new DIE will be created with
23694 : : DW_AT_declaration.
23695 : :
23696 : : 2. Once for the Base() constructor definition, but this time
23697 : : while generating the abstract instance of the base
23698 : : constructor (__base_ctor) which is being generated via early
23699 : : debug of reachable functions.
23700 : :
23701 : : Even though we have a cached version of the declaration (1),
23702 : : we will create a DW_AT_specification of the declaration DIE
23703 : : in (1).
23704 : :
23705 : : 3. Once for the __base_ctor itself, but this time, we generate
23706 : : an DW_AT_abstract_origin version of the DW_AT_specification in
23707 : : (2).
23708 : :
23709 : : Late debug via rest_of_handle_final
23710 : : -----------------------------------
23711 : :
23712 : : 4. One final time for the __base_ctor (which will have a cached
23713 : : DIE with DW_AT_abstract_origin created in (3). This time,
23714 : : we will just annotate the location information now
23715 : : available.
23716 : : */
23717 : 80446146 : int declaration = (current_function_decl != decl
23718 : 3483232 : || (!DECL_INITIAL (decl) && !origin)
23719 : 83544176 : || class_or_namespace_scope_p (context_die));
23720 : :
23721 : : /* A declaration that has been previously dumped needs no
23722 : : additional information. */
23723 : 80446146 : if (old_die && declaration)
23724 : : return;
23725 : :
23726 : 80314320 : if (in_lto_p && old_die && old_die->die_child == NULL)
23727 : 80314320 : old_die_had_no_children = true;
23728 : :
23729 : : /* Now that the C++ front end lazily declares artificial member fns, we
23730 : : might need to retrofit the declaration into its class. */
23731 : 2318298 : if (!declaration && !origin && !old_die
23732 : 709839 : && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
23733 : 255859 : && !class_or_namespace_scope_p (context_die)
23734 : 80570179 : && debug_info_level > DINFO_LEVEL_TERSE)
23735 : 255660 : old_die = force_decl_die (decl);
23736 : :
23737 : : /* A concrete instance, tag a new DIE with DW_AT_abstract_origin. */
23738 : 80314320 : if (origin != NULL)
23739 : : {
23740 : 454135 : gcc_assert (!declaration || local_scope_p (context_die));
23741 : :
23742 : : /* Fixup die_parent for the abstract instance of a nested
23743 : : inline function. */
23744 : 454135 : if (old_die && old_die->die_parent == NULL)
23745 : 0 : add_child_die (context_die, old_die);
23746 : :
23747 : 72933 : if (old_die && get_AT_ref (old_die, DW_AT_abstract_origin))
23748 : : {
23749 : : /* If we have a DW_AT_abstract_origin we have a working
23750 : : cached version. */
23751 : : subr_die = old_die;
23752 : : }
23753 : : else
23754 : : {
23755 : 427430 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
23756 : 427430 : add_abstract_origin_attribute (subr_die, origin);
23757 : : /* This is where the actual code for a cloned function is.
23758 : : Let's emit linkage name attribute for it. This helps
23759 : : debuggers to e.g, set breakpoints into
23760 : : constructors/destructors when the user asks "break
23761 : : K::K". */
23762 : 427430 : add_linkage_name (subr_die, decl);
23763 : : }
23764 : : }
23765 : : /* A cached copy, possibly from early dwarf generation. Reuse as
23766 : : much as possible. */
23767 : 79860185 : else if (old_die)
23768 : : {
23769 : 1864119 : if (!get_AT_flag (old_die, DW_AT_declaration)
23770 : : /* We can have a normal definition following an inline one in the
23771 : : case of redefinition of GNU C extern inlines.
23772 : : It seems reasonable to use AT_specification in this case. */
23773 : 1864119 : && !get_AT (old_die, DW_AT_inline))
23774 : : {
23775 : : /* Detect and ignore this case, where we are trying to output
23776 : : something we have already output. */
23777 : 381455 : if (get_AT (old_die, DW_AT_low_pc)
23778 : 381455 : || get_AT (old_die, DW_AT_ranges))
23779 : 0 : return;
23780 : :
23781 : : /* If we have no location information, this must be a
23782 : : partially generated DIE from early dwarf generation.
23783 : : Fall through and generate it. */
23784 : : }
23785 : :
23786 : : /* If the definition comes from the same place as the declaration,
23787 : : maybe use the old DIE. We always want the DIE for this function
23788 : : that has the *_pc attributes to be under comp_unit_die so the
23789 : : debugger can find it. We also need to do this for abstract
23790 : : instances of inlines, since the spec requires the out-of-line copy
23791 : : to have the same parent. For local class methods, this doesn't
23792 : : apply; we just use the old DIE. */
23793 : 1864119 : expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
23794 : 1864119 : struct dwarf_file_data * file_index = lookup_filename (s.file);
23795 : 1864119 : if (((is_unit_die (old_die->die_parent)
23796 : : /* This condition fixes the inconsistency/ICE with the
23797 : : following Fortran test (or some derivative thereof) while
23798 : : building libgfortran:
23799 : :
23800 : : module some_m
23801 : : contains
23802 : : logical function funky (FLAG)
23803 : : funky = .true.
23804 : : end function
23805 : : end module
23806 : : */
23807 : 1410073 : || (old_die->die_parent
23808 : 1410073 : && old_die->die_parent->die_tag == DW_TAG_module)
23809 : 1407388 : || local_scope_p (old_die->die_parent)
23810 : 1359891 : || context_die == NULL)
23811 : 504258 : && (DECL_ARTIFICIAL (decl)
23812 : 466305 : || (get_AT_file (old_die, DW_AT_decl_file) == file_index
23813 : 463770 : && (get_AT_unsigned (old_die, DW_AT_decl_line)
23814 : 463770 : == (unsigned) s.line)
23815 : 463770 : && (!debug_column_info
23816 : 463766 : || s.column == 0
23817 : 370533 : || (get_AT_unsigned (old_die, DW_AT_decl_column)
23818 : 370533 : == (unsigned) s.column)))))
23819 : : /* With LTO if there's an abstract instance for
23820 : : the old DIE, this is a concrete instance and
23821 : : thus re-use the DIE. */
23822 : 3226515 : || get_AT (old_die, DW_AT_abstract_origin))
23823 : : {
23824 : 507623 : subr_die = old_die;
23825 : :
23826 : : /* Clear out the declaration attribute, but leave the
23827 : : parameters so they can be augmented with location
23828 : : information later. Unless this was a declaration, in
23829 : : which case, wipe out the nameless parameters and recreate
23830 : : them further down. */
23831 : 507623 : if (remove_AT (subr_die, DW_AT_declaration))
23832 : : {
23833 : :
23834 : 45262 : remove_AT (subr_die, DW_AT_object_pointer);
23835 : 45262 : remove_child_TAG (subr_die, DW_TAG_formal_parameter);
23836 : : }
23837 : : }
23838 : : /* Make a specification pointing to the previously built
23839 : : declaration. */
23840 : : else
23841 : : {
23842 : 1356496 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
23843 : 1356496 : add_AT_specification (subr_die, old_die);
23844 : 1356496 : add_pubname (decl, subr_die);
23845 : 1356496 : if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
23846 : 39373 : add_AT_file (subr_die, DW_AT_decl_file, file_index);
23847 : 1356496 : if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
23848 : 44023 : add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
23849 : 1356496 : if (debug_column_info
23850 : 1356484 : && s.column
23851 : 2712980 : && (get_AT_unsigned (old_die, DW_AT_decl_column)
23852 : 1356484 : != (unsigned) s.column))
23853 : 44021 : add_AT_unsigned (subr_die, DW_AT_decl_column, s.column);
23854 : :
23855 : : /* If the prototype had an 'auto' or 'decltype(auto)' in
23856 : : the return type, emit the real type on the definition die. */
23857 : 1356496 : if (is_cxx () && debug_info_level > DINFO_LEVEL_TERSE)
23858 : : {
23859 : 1356496 : dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
23860 : 1356496 : while (die
23861 : 1675373 : && (die->die_tag == DW_TAG_reference_type
23862 : : || die->die_tag == DW_TAG_rvalue_reference_type
23863 : : || die->die_tag == DW_TAG_pointer_type
23864 : : || die->die_tag == DW_TAG_const_type
23865 : : || die->die_tag == DW_TAG_volatile_type
23866 : : || die->die_tag == DW_TAG_restrict_type
23867 : : || die->die_tag == DW_TAG_array_type
23868 : : || die->die_tag == DW_TAG_ptr_to_member_type
23869 : : || die->die_tag == DW_TAG_subroutine_type))
23870 : 318877 : die = get_AT_ref (die, DW_AT_type);
23871 : 1356496 : if (die == auto_die || die == decltype_auto_die)
23872 : 447627 : add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
23873 : : TYPE_UNQUALIFIED, false, context_die);
23874 : : }
23875 : :
23876 : : /* When we process the method declaration, we haven't seen
23877 : : the out-of-class defaulted definition yet, so we have to
23878 : : recheck now. */
23879 : 1294 : if ((dwarf_version >= 5 || ! dwarf_strict)
23880 : 1357778 : && !get_AT (subr_die, DW_AT_defaulted))
23881 : : {
23882 : 1335234 : int defaulted
23883 : 1335234 : = lang_hooks.decls.decl_dwarf_attribute (decl,
23884 : : DW_AT_defaulted);
23885 : 1335234 : if (defaulted != -1)
23886 : : {
23887 : : /* Other values must have been handled before. */
23888 : 318 : gcc_assert (defaulted == DW_DEFAULTED_out_of_class);
23889 : 318 : add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
23890 : : }
23891 : : }
23892 : : }
23893 : : }
23894 : : /* Create a fresh DIE for anything else. */
23895 : : else
23896 : : {
23897 : 77996066 : subr_die = new_die (DW_TAG_subprogram, context_die, decl);
23898 : :
23899 : 77996066 : if (TREE_PUBLIC (decl))
23900 : 77781520 : add_AT_flag (subr_die, DW_AT_external, 1);
23901 : :
23902 : 77996066 : add_name_and_src_coords_attributes (subr_die, decl);
23903 : 77996066 : add_pubname (decl, subr_die);
23904 : 77996066 : if (debug_info_level > DINFO_LEVEL_TERSE)
23905 : : {
23906 : 77982363 : add_prototyped_attribute (subr_die, TREE_TYPE (decl));
23907 : 77982363 : add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
23908 : : TYPE_UNQUALIFIED, false, context_die);
23909 : : }
23910 : :
23911 : 77996066 : add_pure_or_virtual_attribute (subr_die, decl);
23912 : 77996066 : if (DECL_ARTIFICIAL (decl))
23913 : 1068621 : add_AT_flag (subr_die, DW_AT_artificial, 1);
23914 : :
23915 : 77996066 : if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
23916 : 67921 : add_AT_flag (subr_die, DW_AT_noreturn, 1);
23917 : :
23918 : 77996066 : add_alignment_attribute (subr_die, decl);
23919 : :
23920 : 77996066 : add_accessibility_attribute (subr_die, decl);
23921 : : }
23922 : :
23923 : : /* Unless we have an existing non-declaration DIE, equate the new
23924 : : DIE. */
23925 : 80314320 : if (!old_die || is_declaration_die (old_die))
23926 : 79733752 : equate_decl_number_to_die (decl, subr_die);
23927 : :
23928 : 80314320 : if (declaration)
23929 : : {
23930 : 77541887 : if (!old_die || !get_AT (old_die, DW_AT_inline))
23931 : : {
23932 : 77541887 : add_AT_flag (subr_die, DW_AT_declaration, 1);
23933 : :
23934 : : /* If this is an explicit function declaration then generate
23935 : : a DW_AT_explicit attribute. */
23936 : 2976 : if ((dwarf_version >= 3 || !dwarf_strict)
23937 : 77544863 : && lang_hooks.decls.decl_dwarf_attribute (decl,
23938 : : DW_AT_explicit) == 1)
23939 : 2056688 : add_AT_flag (subr_die, DW_AT_explicit, 1);
23940 : :
23941 : : /* If this is a C++11 deleted special function member then generate
23942 : : a DW_AT_deleted attribute. */
23943 : 3198 : if ((dwarf_version >= 5 || !dwarf_strict)
23944 : 77545067 : && lang_hooks.decls.decl_dwarf_attribute (decl,
23945 : : DW_AT_deleted) == 1)
23946 : 2402874 : add_AT_flag (subr_die, DW_AT_deleted, 1);
23947 : :
23948 : : /* If this is a C++11 defaulted special function member then
23949 : : generate a DW_AT_defaulted attribute. */
23950 : 77541887 : if (dwarf_version >= 5 || !dwarf_strict)
23951 : : {
23952 : 77541869 : int defaulted
23953 : 77541869 : = lang_hooks.decls.decl_dwarf_attribute (decl,
23954 : : DW_AT_defaulted);
23955 : 77541869 : if (defaulted != -1)
23956 : 4795974 : add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
23957 : : }
23958 : :
23959 : : /* If this is a C++11 non-static member function with & ref-qualifier
23960 : : then generate a DW_AT_reference attribute. */
23961 : 3198 : if ((dwarf_version >= 5 || !dwarf_strict)
23962 : 77545067 : && lang_hooks.decls.decl_dwarf_attribute (decl,
23963 : : DW_AT_reference) == 1)
23964 : 27199 : add_AT_flag (subr_die, DW_AT_reference, 1);
23965 : :
23966 : : /* If this is a C++11 non-static member function with &&
23967 : : ref-qualifier then generate a DW_AT_reference attribute. */
23968 : 3198 : if ((dwarf_version >= 5 || !dwarf_strict)
23969 : 77545067 : && lang_hooks.decls.decl_dwarf_attribute (decl,
23970 : : DW_AT_rvalue_reference)
23971 : : == 1)
23972 : 33320 : add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
23973 : : }
23974 : : }
23975 : : /* For non DECL_EXTERNALs, if range information is available, fill
23976 : : the DIE with it. */
23977 : 2772433 : else if (!DECL_EXTERNAL (decl) && !early_dwarf)
23978 : : {
23979 : 557714 : HOST_WIDE_INT cfa_fb_offset;
23980 : :
23981 : 557714 : struct function *fun = DECL_STRUCT_FUNCTION (decl);
23982 : :
23983 : 557714 : if (!crtl->has_bb_partition)
23984 : : {
23985 : 537497 : dw_fde_ref fde = fun->fde;
23986 : 537497 : if (fde->dw_fde_begin)
23987 : : {
23988 : : /* We have already generated the labels. */
23989 : 537497 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
23990 : : fde->dw_fde_end, false);
23991 : : }
23992 : : else
23993 : : {
23994 : : /* Create start/end labels and add the range. */
23995 : 0 : char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
23996 : 0 : char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
23997 : 0 : ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
23998 : : current_function_funcdef_no);
23999 : 0 : ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
24000 : : current_function_funcdef_no);
24001 : 0 : add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
24002 : : false);
24003 : : }
24004 : :
24005 : : #if VMS_DEBUGGING_INFO
24006 : : /* HP OpenVMS Industry Standard 64: DWARF Extensions
24007 : : Section 2.3 Prologue and Epilogue Attributes:
24008 : : When a breakpoint is set on entry to a function, it is generally
24009 : : desirable for execution to be suspended, not on the very first
24010 : : instruction of the function, but rather at a point after the
24011 : : function's frame has been set up, after any language defined local
24012 : : declaration processing has been completed, and before execution of
24013 : : the first statement of the function begins. Debuggers generally
24014 : : cannot properly determine where this point is. Similarly for a
24015 : : breakpoint set on exit from a function. The prologue and epilogue
24016 : : attributes allow a compiler to communicate the location(s) to use. */
24017 : :
24018 : : {
24019 : : if (fde->dw_fde_vms_end_prologue)
24020 : : add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
24021 : : fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
24022 : :
24023 : : if (fde->dw_fde_vms_begin_epilogue)
24024 : : add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
24025 : : fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
24026 : : }
24027 : : #endif
24028 : :
24029 : : }
24030 : : else
24031 : : {
24032 : : /* Generate pubnames entries for the split function code ranges. */
24033 : 20217 : dw_fde_ref fde = fun->fde;
24034 : :
24035 : 20217 : if (fde->dw_fde_second_begin)
24036 : : {
24037 : 20217 : if (dwarf_version >= 3 || !dwarf_strict)
24038 : : {
24039 : : /* We should use ranges for non-contiguous code section
24040 : : addresses. Use the actual code range for the initial
24041 : : section, since the HOT/COLD labels might precede an
24042 : : alignment offset. */
24043 : 20217 : bool range_list_added = false;
24044 : 20217 : add_ranges_by_labels (subr_die, fde->dw_fde_begin,
24045 : : fde->dw_fde_end, &range_list_added,
24046 : : false);
24047 : 20217 : add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
24048 : : fde->dw_fde_second_end,
24049 : : &range_list_added, false);
24050 : 20217 : if (range_list_added)
24051 : 20217 : add_ranges (NULL);
24052 : 20217 : }
24053 : : else
24054 : : {
24055 : : /* There is no real support in DW2 for this .. so we make
24056 : : a work-around. First, emit the pub name for the segment
24057 : : containing the function label. Then make and emit a
24058 : : simplified subprogram DIE for the second segment with the
24059 : : name pre-fixed by __hot/cold_sect_of_. We use the same
24060 : : linkage name for the second die so that gdb will find both
24061 : : sections when given "b foo". */
24062 : 0 : const char *name = NULL;
24063 : 0 : tree decl_name = DECL_NAME (decl);
24064 : 0 : dw_die_ref seg_die;
24065 : :
24066 : : /* Do the 'primary' section. */
24067 : 0 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
24068 : : fde->dw_fde_end, false);
24069 : :
24070 : : /* Build a minimal DIE for the secondary section. */
24071 : 0 : seg_die = new_die (DW_TAG_subprogram,
24072 : : subr_die->die_parent, decl);
24073 : :
24074 : 0 : if (TREE_PUBLIC (decl))
24075 : 0 : add_AT_flag (seg_die, DW_AT_external, 1);
24076 : :
24077 : 0 : if (decl_name != NULL
24078 : 0 : && IDENTIFIER_POINTER (decl_name) != NULL)
24079 : : {
24080 : 0 : name = dwarf2_name (decl, 1);
24081 : 0 : if (! DECL_ARTIFICIAL (decl))
24082 : 0 : add_src_coords_attributes (seg_die, decl);
24083 : :
24084 : 0 : add_linkage_name (seg_die, decl);
24085 : : }
24086 : 0 : gcc_assert (name != NULL);
24087 : 0 : add_pure_or_virtual_attribute (seg_die, decl);
24088 : 0 : if (DECL_ARTIFICIAL (decl))
24089 : 0 : add_AT_flag (seg_die, DW_AT_artificial, 1);
24090 : :
24091 : 0 : name = concat ("__second_sect_of_", name, NULL);
24092 : 0 : add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
24093 : : fde->dw_fde_second_end, false);
24094 : 0 : add_name_attribute (seg_die, name);
24095 : 0 : if (want_pubnames ())
24096 : 0 : add_pubname_string (name, seg_die);
24097 : : }
24098 : : }
24099 : : else
24100 : 0 : add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
24101 : : false);
24102 : : }
24103 : :
24104 : 557714 : cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
24105 : :
24106 : : /* We define the "frame base" as the function's CFA. This is more
24107 : : convenient for several reasons: (1) It's stable across the prologue
24108 : : and epilogue, which makes it better than just a frame pointer,
24109 : : (2) With dwarf3, there exists a one-byte encoding that allows us
24110 : : to reference the .debug_frame data by proxy, but failing that,
24111 : : (3) We can at least reuse the code inspection and interpretation
24112 : : code that determines the CFA position at various points in the
24113 : : function. */
24114 : 557714 : if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
24115 : : {
24116 : 554147 : dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
24117 : 554147 : add_AT_loc (subr_die, DW_AT_frame_base, op);
24118 : : }
24119 : : else
24120 : : {
24121 : 3567 : dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
24122 : 3567 : if (list->dw_loc_next)
24123 : 1884 : add_AT_loc_list (subr_die, DW_AT_frame_base, list);
24124 : : else
24125 : 1683 : add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
24126 : : }
24127 : :
24128 : : /* Compute a displacement from the "steady-state frame pointer" to
24129 : : the CFA. The former is what all stack slots and argument slots
24130 : : will reference in the rtl; the latter is what we've told the
24131 : : debugger about. We'll need to adjust all frame_base references
24132 : : by this displacement. */
24133 : 557714 : compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
24134 : :
24135 : 557714 : if (fun->static_chain_decl)
24136 : : {
24137 : : /* DWARF requires here a location expression that computes the
24138 : : address of the enclosing subprogram's frame base. The machinery
24139 : : in tree-nested.cc is supposed to store this specific address in the
24140 : : last field of the FRAME record. */
24141 : 14528 : const tree frame_type
24142 : 14528 : = TREE_TYPE (TREE_TYPE (fun->static_chain_decl));
24143 : 14528 : const tree fb_decl = tree_last (TYPE_FIELDS (frame_type));
24144 : :
24145 : 14528 : tree fb_expr
24146 : 14528 : = build1 (INDIRECT_REF, frame_type, fun->static_chain_decl);
24147 : 14528 : fb_expr = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
24148 : : fb_expr, fb_decl, NULL_TREE);
24149 : :
24150 : 14528 : add_AT_location_description (subr_die, DW_AT_static_link,
24151 : : loc_list_from_tree (fb_expr, 0, NULL));
24152 : : }
24153 : :
24154 : 557714 : resolve_variable_values ();
24155 : : }
24156 : :
24157 : : /* Generate child dies for template parameters. */
24158 : 80314320 : if (early_dwarf && debug_info_level > DINFO_LEVEL_TERSE)
24159 : 79742739 : gen_generic_params_dies (decl);
24160 : :
24161 : : /* Now output descriptions of the arguments for this function. This gets
24162 : : (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
24163 : : for a FUNCTION_DECL doesn't indicate cases where there was a trailing
24164 : : `...' at the end of the formal parameter list. In order to find out if
24165 : : there was a trailing ellipsis or not, we must instead look at the type
24166 : : associated with the FUNCTION_DECL. This will be a node of type
24167 : : FUNCTION_TYPE. If the chain of type nodes hanging off of this
24168 : : FUNCTION_TYPE node ends with a void_type_node then there should *not* be
24169 : : an ellipsis at the end. */
24170 : :
24171 : : /* In the case where we are describing a mere function declaration, all we
24172 : : need to do here (and all we *can* do here) is to describe the *types* of
24173 : : its formal parameters. */
24174 : 80314320 : if (debug_info_level <= DINFO_LEVEL_TERSE)
24175 : : ;
24176 : 80287336 : else if (declaration)
24177 : 77541709 : gen_formal_types_die (decl, subr_die);
24178 : : else
24179 : : {
24180 : : /* Generate DIEs to represent all known formal parameters. */
24181 : 2745627 : tree parm = DECL_ARGUMENTS (decl);
24182 : 2745627 : tree generic_decl = early_dwarf
24183 : 2745627 : ? lang_hooks.decls.get_generic_function_decl (decl) : NULL;
24184 : 2201047 : tree generic_decl_parm = generic_decl
24185 : 2201047 : ? DECL_ARGUMENTS (generic_decl)
24186 : 519769 : : NULL;
24187 : :
24188 : : /* Now we want to walk the list of parameters of the function and
24189 : : emit their relevant DIEs.
24190 : :
24191 : : We consider the case of DECL being an instance of a generic function
24192 : : as well as it being a normal function.
24193 : :
24194 : : If DECL is an instance of a generic function we walk the
24195 : : parameters of the generic function declaration _and_ the parameters of
24196 : : DECL itself. This is useful because we want to emit specific DIEs for
24197 : : function parameter packs and those are declared as part of the
24198 : : generic function declaration. In that particular case,
24199 : : the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
24200 : : That DIE has children DIEs representing the set of arguments
24201 : : of the pack. Note that the set of pack arguments can be empty.
24202 : : In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
24203 : : children DIE.
24204 : :
24205 : : Otherwise, we just consider the parameters of DECL. */
24206 : 7860779 : while (generic_decl_parm || parm)
24207 : : {
24208 : : if (generic_decl_parm
24209 : 1245600 : && lang_hooks.function_parameter_pack_p (generic_decl_parm))
24210 : 77026 : gen_formal_parameter_pack_die (generic_decl_parm,
24211 : : parm, subr_die,
24212 : : &parm);
24213 : 5038126 : else if (parm)
24214 : : {
24215 : 5038126 : dw_die_ref parm_die = gen_decl_die (parm, NULL, NULL, subr_die);
24216 : :
24217 : 5038126 : if (early_dwarf
24218 : 4014611 : && parm == DECL_ARGUMENTS (decl)
24219 : 2088037 : && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
24220 : 1338257 : && parm_die
24221 : 6376383 : && (dwarf_version >= 3 || !dwarf_strict))
24222 : 1338257 : add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
24223 : :
24224 : 5038126 : parm = DECL_CHAIN (parm);
24225 : : }
24226 : :
24227 : 5115152 : if (generic_decl_parm)
24228 : 1245600 : generic_decl_parm = DECL_CHAIN (generic_decl_parm);
24229 : : }
24230 : :
24231 : : /* Decide whether we need an unspecified_parameters DIE at the end.
24232 : : There are 2 more cases to do this for: 1) the ansi ... declaration -
24233 : : this is detectable when the end of the arg list is not a
24234 : : void_type_node 2) an unprototyped function declaration (not a
24235 : : definition). This just means that we have no info about the
24236 : : parameters at all. */
24237 : 2745627 : if (early_dwarf)
24238 : : {
24239 : 2201047 : if (prototype_p (TREE_TYPE (decl)))
24240 : : {
24241 : : /* This is the prototyped case, check for.... */
24242 : 2198805 : if (stdarg_p (TREE_TYPE (decl)))
24243 : 4283 : gen_unspecified_parameters_die (decl, subr_die);
24244 : : }
24245 : 2242 : else if (DECL_INITIAL (decl) == NULL_TREE)
24246 : 0 : gen_unspecified_parameters_die (decl, subr_die);
24247 : : }
24248 : 544580 : else if ((subr_die != old_die || old_die_had_no_children)
24249 : 74284 : && prototype_p (TREE_TYPE (decl))
24250 : 618557 : && stdarg_p (TREE_TYPE (decl)))
24251 : 171 : gen_unspecified_parameters_die (decl, subr_die);
24252 : : }
24253 : :
24254 : 80314320 : if (subr_die != old_die)
24255 : : /* Add the calling convention attribute if requested. */
24256 : 79779992 : add_calling_convention_attribute (subr_die, decl);
24257 : :
24258 : : /* Output Dwarf info for all of the stuff within the body of the function
24259 : : (if it has one - it may be just a declaration).
24260 : :
24261 : : OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
24262 : : a function. This BLOCK actually represents the outermost binding contour
24263 : : for the function, i.e. the contour in which the function's formal
24264 : : parameters and labels get declared. Curiously, it appears that the front
24265 : : end doesn't actually put the PARM_DECL nodes for the current function onto
24266 : : the BLOCK_VARS list for this outer scope, but are strung off of the
24267 : : DECL_ARGUMENTS list for the function instead.
24268 : :
24269 : : The BLOCK_VARS list for the `outer_scope' does provide us with a list of
24270 : : the LABEL_DECL nodes for the function however, and we output DWARF info
24271 : : for those in decls_for_scope. Just within the `outer_scope' there will be
24272 : : a BLOCK node representing the function's outermost pair of curly braces,
24273 : : and any blocks used for the base and member initializers of a C++
24274 : : constructor function. */
24275 : 80314320 : tree outer_scope = DECL_INITIAL (decl);
24276 : 80314320 : if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
24277 : : {
24278 : 2753223 : int call_site_note_count = 0;
24279 : 2753223 : int tail_call_site_note_count = 0;
24280 : :
24281 : : /* Emit a DW_TAG_variable DIE for a named return value. */
24282 : 2753223 : if (DECL_NAME (DECL_RESULT (decl)))
24283 : 8482 : gen_decl_die (DECL_RESULT (decl), NULL, NULL, subr_die);
24284 : :
24285 : : /* The first time through decls_for_scope we will generate the
24286 : : DIEs for the locals. The second time, we fill in the
24287 : : location info. */
24288 : 2753223 : decls_for_scope (outer_scope, subr_die);
24289 : :
24290 : 2753223 : if (call_arg_locations && (!dwarf_strict || dwarf_version >= 5))
24291 : : {
24292 : : struct call_arg_loc_node *ca_loc;
24293 : 3654365 : for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
24294 : : {
24295 : 3210394 : dw_die_ref die = NULL;
24296 : 3210394 : rtx tloc = NULL_RTX, tlocc = NULL_RTX;
24297 : 3210394 : rtx call_arg_loc_note
24298 : 3210394 : = find_reg_note (ca_loc->call_insn,
24299 : : REG_CALL_ARG_LOCATION, NULL_RTX);
24300 : 3210394 : rtx arg, next_arg;
24301 : 3210394 : tree arg_decl = NULL_TREE;
24302 : :
24303 : 3174639 : for (arg = (call_arg_loc_note != NULL_RTX
24304 : 3210394 : ? XEXP (call_arg_loc_note, 0)
24305 : : : NULL_RTX);
24306 : 6320190 : arg; arg = next_arg)
24307 : : {
24308 : 3109796 : dw_loc_descr_ref reg, val;
24309 : 3109796 : machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
24310 : 3109796 : dw_die_ref cdie, tdie = NULL;
24311 : :
24312 : 3109796 : next_arg = XEXP (arg, 1);
24313 : 3109796 : if (REG_P (XEXP (XEXP (arg, 0), 0))
24314 : 3051106 : && next_arg
24315 : 1368799 : && MEM_P (XEXP (XEXP (next_arg, 0), 0))
24316 : 8691 : && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
24317 : 3118431 : && REGNO (XEXP (XEXP (arg, 0), 0))
24318 : 8635 : == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
24319 : 8147 : next_arg = XEXP (next_arg, 1);
24320 : 3109796 : if (mode == VOIDmode)
24321 : : {
24322 : 553811 : mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
24323 : 553811 : if (mode == VOIDmode)
24324 : 943 : mode = GET_MODE (XEXP (arg, 0));
24325 : : }
24326 : 3109796 : if (mode == VOIDmode || mode == BLKmode)
24327 : 0 : continue;
24328 : : /* Get dynamic information about call target only if we
24329 : : have no static information: we cannot generate both
24330 : : DW_AT_call_origin and DW_AT_call_target
24331 : : attributes. */
24332 : 3109796 : if (ca_loc->symbol_ref == NULL_RTX)
24333 : : {
24334 : 130065 : if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
24335 : : {
24336 : 4873 : tloc = XEXP (XEXP (arg, 0), 1);
24337 : 4873 : continue;
24338 : : }
24339 : 125192 : else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
24340 : 0 : && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
24341 : : {
24342 : 0 : tlocc = XEXP (XEXP (arg, 0), 1);
24343 : 0 : continue;
24344 : : }
24345 : : }
24346 : 3104923 : reg = NULL;
24347 : 3104923 : if (REG_P (XEXP (XEXP (arg, 0), 0)))
24348 : 3051106 : reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
24349 : : VAR_INIT_STATUS_INITIALIZED);
24350 : 53817 : else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
24351 : : {
24352 : 1937 : rtx mem = XEXP (XEXP (arg, 0), 0);
24353 : 1937 : reg = mem_loc_descriptor (XEXP (mem, 0),
24354 : 1937 : get_address_mode (mem),
24355 : 1937 : GET_MODE (mem),
24356 : : VAR_INIT_STATUS_INITIALIZED);
24357 : : }
24358 : 51880 : else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
24359 : : == DEBUG_PARAMETER_REF)
24360 : : {
24361 : 51880 : tree tdecl
24362 : : = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
24363 : 51880 : tdie = lookup_decl_die (tdecl);
24364 : 51880 : if (tdie == NULL)
24365 : 0 : continue;
24366 : : arg_decl = tdecl;
24367 : : }
24368 : : else
24369 : 0 : continue;
24370 : 3053043 : if (reg == NULL
24371 : 51880 : && GET_CODE (XEXP (XEXP (arg, 0), 0))
24372 : : != DEBUG_PARAMETER_REF)
24373 : 0 : continue;
24374 : 3104923 : val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
24375 : : VOIDmode,
24376 : : VAR_INIT_STATUS_INITIALIZED);
24377 : 3104923 : if (val == NULL)
24378 : 81227 : continue;
24379 : 3023696 : if (die == NULL)
24380 : 1701203 : die = gen_call_site_die (decl, subr_die, ca_loc);
24381 : 3025181 : cdie = new_die (dwarf_TAG (DW_TAG_call_site_parameter), die,
24382 : : NULL_TREE);
24383 : 3023696 : add_desc_attribute (cdie, arg_decl);
24384 : 3023696 : if (reg != NULL)
24385 : 2992974 : add_AT_loc (cdie, DW_AT_location, reg);
24386 : 30722 : else if (tdie != NULL)
24387 : 30728 : add_AT_die_ref (cdie, dwarf_AT (DW_AT_call_parameter),
24388 : : tdie);
24389 : 3025181 : add_AT_loc (cdie, dwarf_AT (DW_AT_call_value), val);
24390 : 3023696 : if (next_arg != XEXP (arg, 1))
24391 : : {
24392 : 8147 : mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
24393 : 8147 : if (mode == VOIDmode)
24394 : 6866 : mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
24395 : 8147 : val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
24396 : : 0), 1),
24397 : : mode, VOIDmode,
24398 : : VAR_INIT_STATUS_INITIALIZED);
24399 : 8147 : if (val != NULL)
24400 : 8147 : add_AT_loc (cdie, dwarf_AT (DW_AT_call_data_value),
24401 : : val);
24402 : : }
24403 : : }
24404 : 3210394 : if (die == NULL
24405 : 1509191 : && (ca_loc->symbol_ref || tloc))
24406 : 1183444 : die = gen_call_site_die (decl, subr_die, ca_loc);
24407 : 3210394 : if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
24408 : : {
24409 : 4873 : dw_loc_descr_ref tval = NULL;
24410 : :
24411 : 4873 : if (tloc != NULL_RTX)
24412 : 4873 : tval = mem_loc_descriptor (tloc,
24413 : 4873 : GET_MODE (tloc) == VOIDmode
24414 : 943 : ? Pmode : GET_MODE (tloc),
24415 : : VOIDmode,
24416 : : VAR_INIT_STATUS_INITIALIZED);
24417 : 4873 : if (tval)
24418 : 4881 : add_AT_loc (die, dwarf_AT (DW_AT_call_target), tval);
24419 : 4 : else if (tlocc != NULL_RTX)
24420 : : {
24421 : 0 : tval = mem_loc_descriptor (tlocc,
24422 : 0 : GET_MODE (tlocc) == VOIDmode
24423 : 0 : ? Pmode : GET_MODE (tlocc),
24424 : : VOIDmode,
24425 : : VAR_INIT_STATUS_INITIALIZED);
24426 : 0 : if (tval)
24427 : 0 : add_AT_loc (die,
24428 : : dwarf_AT (DW_AT_call_target_clobbered),
24429 : : tval);
24430 : : }
24431 : : }
24432 : 2884647 : if (die != NULL)
24433 : : {
24434 : 2884647 : call_site_note_count++;
24435 : 2884647 : if (ca_loc->tail_call_p)
24436 : 55823 : tail_call_site_note_count++;
24437 : : }
24438 : : }
24439 : : }
24440 : 2753223 : call_arg_locations = NULL;
24441 : 2753223 : call_arg_loc_last = NULL;
24442 : 2753223 : if (tail_call_site_count >= 0
24443 : 557714 : && tail_call_site_count == tail_call_site_note_count
24444 : 554885 : && (!dwarf_strict || dwarf_version >= 5))
24445 : : {
24446 : 554869 : if (call_site_count >= 0
24447 : 554869 : && call_site_count == call_site_note_count)
24448 : 257346 : add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_calls), 1);
24449 : : else
24450 : 300872 : add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_tail_calls), 1);
24451 : : }
24452 : 2753223 : call_site_count = -1;
24453 : 2753223 : tail_call_site_count = -1;
24454 : : }
24455 : :
24456 : : /* Mark used types after we have created DIEs for the functions scopes. */
24457 : 80314320 : premark_used_types (DECL_STRUCT_FUNCTION (decl));
24458 : : }
24459 : :
24460 : : /* Returns a hash value for X (which really is a die_struct). */
24461 : :
24462 : : hashval_t
24463 : 2923 : block_die_hasher::hash (die_struct *d)
24464 : : {
24465 : 2923 : return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
24466 : : }
24467 : :
24468 : : /* Return true if decl_id and die_parent of die_struct X is the same
24469 : : as decl_id and die_parent of die_struct Y. */
24470 : :
24471 : : bool
24472 : 2167 : block_die_hasher::equal (die_struct *x, die_struct *y)
24473 : : {
24474 : 2167 : return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
24475 : : }
24476 : :
24477 : : /* Hold information about markers for inlined entry points. */
24478 : : struct GTY ((for_user)) inline_entry_data
24479 : : {
24480 : : /* The block that's the inlined_function_outer_scope for an inlined
24481 : : function. */
24482 : : tree block;
24483 : :
24484 : : /* The label at the inlined entry point. */
24485 : : const char *label_pfx;
24486 : : unsigned int label_num;
24487 : :
24488 : : /* The view number to be used as the inlined entry point. */
24489 : : var_loc_view view;
24490 : : };
24491 : :
24492 : : struct inline_entry_data_hasher : ggc_ptr_hash <inline_entry_data>
24493 : : {
24494 : : typedef tree compare_type;
24495 : : static inline hashval_t hash (const inline_entry_data *);
24496 : : static inline bool equal (const inline_entry_data *, const_tree);
24497 : : };
24498 : :
24499 : : /* Hash table routines for inline_entry_data. */
24500 : :
24501 : : inline hashval_t
24502 : 39514203 : inline_entry_data_hasher::hash (const inline_entry_data *data)
24503 : : {
24504 : 39514203 : return htab_hash_pointer (data->block);
24505 : : }
24506 : :
24507 : : inline bool
24508 : 47827669 : inline_entry_data_hasher::equal (const inline_entry_data *data,
24509 : : const_tree block)
24510 : : {
24511 : 47827669 : return data->block == block;
24512 : : }
24513 : :
24514 : : /* Inlined entry points pending DIE creation in this compilation unit. */
24515 : :
24516 : : static GTY(()) hash_table<inline_entry_data_hasher> *inline_entry_data_table;
24517 : :
24518 : :
24519 : : /* Return TRUE if DECL, which may have been previously generated as
24520 : : OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
24521 : : true if decl (or its origin) is either an extern declaration or a
24522 : : class/namespace scoped declaration.
24523 : :
24524 : : The declare_in_namespace support causes us to get two DIEs for one
24525 : : variable, both of which are declarations. We want to avoid
24526 : : considering one to be a specification, so we must test for
24527 : : DECLARATION and DW_AT_declaration. */
24528 : : static inline bool
24529 : 46012880 : decl_will_get_specification_p (dw_die_ref old_die, tree decl, bool declaration)
24530 : : {
24531 : 28795755 : return (old_die && TREE_STATIC (decl) && !declaration
24532 : 73550267 : && get_AT_flag (old_die, DW_AT_declaration) == 1);
24533 : : }
24534 : :
24535 : : /* Return true if DECL is a local static. */
24536 : :
24537 : : static inline bool
24538 : 16572962 : local_function_static (tree decl)
24539 : : {
24540 : 16572962 : gcc_assert (VAR_P (decl));
24541 : 16572962 : return TREE_STATIC (decl)
24542 : 15959192 : && DECL_CONTEXT (decl)
24543 : 32332182 : && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
24544 : : }
24545 : :
24546 : : /* Return true iff DECL overrides (presumably completes) the type of
24547 : : OLD_DIE within CONTEXT_DIE. */
24548 : :
24549 : : static bool
24550 : 13363813 : override_type_for_decl_p (tree decl, dw_die_ref old_die,
24551 : : dw_die_ref context_die)
24552 : : {
24553 : 13363813 : tree type = TREE_TYPE (decl);
24554 : 13363813 : int cv_quals;
24555 : :
24556 : 13363813 : if (decl_by_reference_p (decl))
24557 : : {
24558 : 0 : type = TREE_TYPE (type);
24559 : 0 : cv_quals = TYPE_UNQUALIFIED;
24560 : : }
24561 : : else
24562 : 13363813 : cv_quals = decl_quals (decl);
24563 : :
24564 : 40091439 : dw_die_ref type_die = modified_type_die (type,
24565 : 13363813 : cv_quals | TYPE_QUALS (type),
24566 : : false,
24567 : : context_die);
24568 : :
24569 : 13363813 : dw_die_ref old_type_die = get_AT_ref (old_die, DW_AT_type);
24570 : :
24571 : 13363813 : return type_die != old_type_die;
24572 : : }
24573 : :
24574 : : /* Generate a DIE to represent a declared data object.
24575 : : Either DECL or ORIGIN must be non-null. */
24576 : :
24577 : : static void
24578 : 34351538 : gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
24579 : : {
24580 : 34351538 : HOST_WIDE_INT off = 0;
24581 : 34351538 : tree com_decl;
24582 : 34351538 : tree decl_or_origin = decl ? decl : origin;
24583 : 34351523 : tree ultimate_origin;
24584 : 34351523 : dw_die_ref var_die;
24585 : 34351523 : dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
24586 : 34351538 : bool declaration = (DECL_EXTERNAL (decl_or_origin)
24587 : 34351538 : || class_or_namespace_scope_p (context_die));
24588 : 34351538 : bool specialization_p = false;
24589 : 34351538 : bool no_linkage_name = false;
24590 : :
24591 : : /* While C++ inline static data members have definitions inside of the
24592 : : class, force the first DIE to be a declaration, then let gen_member_die
24593 : : reparent it to the class context and call gen_variable_die again
24594 : : to create the outside of the class DIE for the definition. */
24595 : 34351538 : if (!declaration
24596 : 34351538 : && old_die == NULL
24597 : 9754347 : && decl
24598 : 9754347 : && DECL_CONTEXT (decl)
24599 : 9557089 : && TYPE_P (DECL_CONTEXT (decl))
24600 : 40633914 : && lang_hooks.decls.decl_dwarf_attribute (decl, DW_AT_inline) != -1)
24601 : : {
24602 : 6282373 : declaration = true;
24603 : 6282373 : if (dwarf_version < 5)
24604 : 14 : no_linkage_name = true;
24605 : : }
24606 : :
24607 : 34351538 : ultimate_origin = decl_ultimate_origin (decl_or_origin);
24608 : 34351538 : if (decl || ultimate_origin)
24609 : 34351523 : origin = ultimate_origin;
24610 : 34351538 : com_decl = fortran_common (decl_or_origin, &off);
24611 : :
24612 : : /* Symbol in common gets emitted as a child of the common block, in the form
24613 : : of a data member. */
24614 : 34351538 : if (com_decl)
24615 : : {
24616 : 1061 : dw_die_ref com_die;
24617 : 1061 : dw_loc_list_ref loc = NULL;
24618 : 1061 : die_node com_die_arg;
24619 : :
24620 : 1061 : var_die = lookup_decl_die (decl_or_origin);
24621 : 1061 : if (var_die)
24622 : : {
24623 : 357 : if (! early_dwarf && get_AT (var_die, DW_AT_location) == NULL)
24624 : : {
24625 : 418 : loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
24626 : 349 : if (loc)
24627 : : {
24628 : 349 : if (off)
24629 : : {
24630 : : /* Optimize the common case. */
24631 : 280 : if (single_element_loc_list_p (loc)
24632 : 280 : && loc->expr->dw_loc_opc == DW_OP_addr
24633 : 280 : && loc->expr->dw_loc_next == NULL
24634 : 560 : && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
24635 : : == SYMBOL_REF)
24636 : : {
24637 : 280 : rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
24638 : 280 : loc->expr->dw_loc_oprnd1.v.val_addr
24639 : 280 : = plus_constant (GET_MODE (x), x , off);
24640 : : }
24641 : : else
24642 : 0 : loc_list_plus_const (loc, off);
24643 : : }
24644 : 349 : add_AT_location_description (var_die, DW_AT_location, loc);
24645 : 349 : remove_AT (var_die, DW_AT_declaration);
24646 : : }
24647 : : }
24648 : 357 : return;
24649 : : }
24650 : :
24651 : 704 : if (common_block_die_table == NULL)
24652 : 99 : common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
24653 : :
24654 : 704 : com_die_arg.decl_id = DECL_UID (com_decl);
24655 : 704 : com_die_arg.die_parent = context_die;
24656 : 704 : com_die = common_block_die_table->find (&com_die_arg);
24657 : 704 : if (! early_dwarf)
24658 : 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24659 : 704 : if (com_die == NULL)
24660 : : {
24661 : 247 : const char *cnam
24662 : 247 : = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
24663 : 247 : die_node **slot;
24664 : :
24665 : 247 : com_die = new_die (DW_TAG_common_block, context_die, decl);
24666 : 247 : add_name_and_src_coords_attributes (com_die, com_decl);
24667 : 247 : if (loc)
24668 : : {
24669 : 0 : add_AT_location_description (com_die, DW_AT_location, loc);
24670 : : /* Avoid sharing the same loc descriptor between
24671 : : DW_TAG_common_block and DW_TAG_variable. */
24672 : 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24673 : : }
24674 : 247 : else if (DECL_EXTERNAL (decl_or_origin))
24675 : 7 : add_AT_flag (com_die, DW_AT_declaration, 1);
24676 : 247 : if (want_pubnames ())
24677 : 0 : add_pubname_string (cnam, com_die); /* ??? needed? */
24678 : 247 : com_die->decl_id = DECL_UID (com_decl);
24679 : 247 : slot = common_block_die_table->find_slot (com_die, INSERT);
24680 : 247 : *slot = com_die;
24681 : : }
24682 : 457 : else if (get_AT (com_die, DW_AT_location) == NULL && loc)
24683 : : {
24684 : 0 : add_AT_location_description (com_die, DW_AT_location, loc);
24685 : 0 : loc = loc_list_from_tree (com_decl, 2, NULL);
24686 : 0 : remove_AT (com_die, DW_AT_declaration);
24687 : : }
24688 : 704 : var_die = new_die (DW_TAG_variable, com_die, decl);
24689 : 704 : add_name_and_src_coords_attributes (var_die, decl_or_origin);
24690 : 704 : add_type_attribute (var_die, TREE_TYPE (decl_or_origin),
24691 : : decl_quals (decl_or_origin), false,
24692 : : context_die);
24693 : 704 : add_alignment_attribute (var_die, decl);
24694 : 704 : add_AT_flag (var_die, DW_AT_external, 1);
24695 : 704 : if (loc)
24696 : : {
24697 : 0 : if (off)
24698 : : {
24699 : : /* Optimize the common case. */
24700 : 0 : if (single_element_loc_list_p (loc)
24701 : 0 : && loc->expr->dw_loc_opc == DW_OP_addr
24702 : 0 : && loc->expr->dw_loc_next == NULL
24703 : 0 : && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
24704 : : {
24705 : 0 : rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
24706 : 0 : loc->expr->dw_loc_oprnd1.v.val_addr
24707 : 0 : = plus_constant (GET_MODE (x), x, off);
24708 : : }
24709 : : else
24710 : 0 : loc_list_plus_const (loc, off);
24711 : : }
24712 : 0 : add_AT_location_description (var_die, DW_AT_location, loc);
24713 : : }
24714 : 704 : else if (DECL_EXTERNAL (decl_or_origin))
24715 : 8 : add_AT_flag (var_die, DW_AT_declaration, 1);
24716 : 704 : if (decl)
24717 : 704 : equate_decl_number_to_die (decl, var_die);
24718 : 704 : return;
24719 : : }
24720 : :
24721 : 34350477 : if (old_die)
24722 : : {
24723 : 15744968 : if (declaration)
24724 : : {
24725 : : /* A declaration that has been previously dumped, needs no
24726 : : further annotations, since it doesn't need location on
24727 : : the second pass. */
24728 : : return;
24729 : : }
24730 : 15431942 : else if (decl_will_get_specification_p (old_die, decl, declaration)
24731 : 15431942 : && !get_AT (old_die, DW_AT_specification))
24732 : : {
24733 : : /* Fall-thru so we can make a new variable die along with a
24734 : : DW_AT_specification. */
24735 : : }
24736 : 2068129 : else if (origin && old_die->die_parent != context_die)
24737 : : {
24738 : : /* If we will be creating an inlined instance, we need a
24739 : : new DIE that will get annotated with
24740 : : DW_AT_abstract_origin. */
24741 : 56872 : gcc_assert (!DECL_ABSTRACT_P (decl));
24742 : : }
24743 : : else
24744 : : {
24745 : : /* If a DIE was dumped early, it still needs location info.
24746 : : Skip to where we fill the location bits. */
24747 : 2011257 : var_die = old_die;
24748 : :
24749 : : /* ??? In LTRANS we cannot annotate early created variably
24750 : : modified type DIEs without copying them and adjusting all
24751 : : references to them. Thus we dumped them again. Also add a
24752 : : reference to them but beware of -g0 compile and -g link
24753 : : in which case the reference will be already present. */
24754 : 2011257 : tree type = TREE_TYPE (decl_or_origin);
24755 : 2011257 : if (in_lto_p
24756 : 2777 : && ! get_AT (var_die, DW_AT_type)
24757 : 2014034 : && variably_modified_type_p
24758 : 2777 : (type, decl_function_context (decl_or_origin)))
24759 : : {
24760 : 45 : if (decl_by_reference_p (decl_or_origin))
24761 : 4 : add_type_attribute (var_die, TREE_TYPE (type),
24762 : : TYPE_UNQUALIFIED, false, context_die);
24763 : : else
24764 : 41 : add_type_attribute (var_die, type, decl_quals (decl_or_origin),
24765 : : false, context_die);
24766 : : }
24767 : :
24768 : 2011257 : goto gen_variable_die_location;
24769 : : }
24770 : : }
24771 : :
24772 : : /* For static data members, the declaration in the class is supposed
24773 : : to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
24774 : : also in DWARF2; the specification should still be DW_TAG_variable
24775 : : referencing the DW_TAG_member DIE. */
24776 : 32026194 : if (declaration && class_scope_p (context_die) && dwarf_version < 5)
24777 : 120 : var_die = new_die (DW_TAG_member, context_die, decl);
24778 : : else
24779 : 32026074 : var_die = new_die (DW_TAG_variable, context_die, decl);
24780 : :
24781 : 32026194 : if (origin != NULL)
24782 : 1445256 : add_abstract_origin_attribute (var_die, origin);
24783 : :
24784 : : /* Loop unrolling can create multiple blocks that refer to the same
24785 : : static variable, so we must test for the DW_AT_declaration flag.
24786 : :
24787 : : ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
24788 : : copy decls and set the DECL_ABSTRACT_P flag on them instead of
24789 : : sharing them.
24790 : :
24791 : : ??? Duplicated blocks have been rewritten to use .debug_ranges. */
24792 : 30580938 : else if (decl_will_get_specification_p (old_die, decl, declaration))
24793 : : {
24794 : : /* This is a definition of a C++ class level static. */
24795 : 13363813 : add_AT_specification (var_die, old_die);
24796 : 13363813 : specialization_p = true;
24797 : 13363813 : if (DECL_NAME (decl))
24798 : : {
24799 : 13363810 : expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
24800 : 13363810 : struct dwarf_file_data * file_index = lookup_filename (s.file);
24801 : :
24802 : 13363810 : if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
24803 : 4171 : add_AT_file (var_die, DW_AT_decl_file, file_index);
24804 : :
24805 : 13363810 : if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
24806 : 35501 : add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
24807 : :
24808 : 13363810 : if (debug_column_info
24809 : 13363810 : && s.column
24810 : 26727620 : && (get_AT_unsigned (old_die, DW_AT_decl_column)
24811 : 13363810 : != (unsigned) s.column))
24812 : 35447 : add_AT_unsigned (var_die, DW_AT_decl_column, s.column);
24813 : :
24814 : 13363810 : if (old_die->die_tag == DW_TAG_member)
24815 : 70 : add_linkage_name (var_die, decl);
24816 : : }
24817 : : }
24818 : : else
24819 : 17217125 : add_name_and_src_coords_attributes (var_die, decl, no_linkage_name);
24820 : :
24821 : 32026194 : if ((origin == NULL && !specialization_p)
24822 : 14809069 : || (origin != NULL
24823 : 1445256 : && !DECL_ABSTRACT_P (decl_or_origin)
24824 : 1445256 : && variably_modified_type_p (TREE_TYPE (decl_or_origin),
24825 : : decl_function_context
24826 : : (decl_or_origin)))
24827 : 46832760 : || (old_die && specialization_p
24828 : 13363813 : && override_type_for_decl_p (decl_or_origin, old_die, context_die)))
24829 : : {
24830 : 17219873 : tree type = TREE_TYPE (decl_or_origin);
24831 : :
24832 : 17219873 : if (decl_by_reference_p (decl_or_origin))
24833 : 1269 : add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
24834 : : context_die);
24835 : : else
24836 : 17218604 : add_type_attribute (var_die, type, decl_quals (decl_or_origin), false,
24837 : : context_die);
24838 : : }
24839 : :
24840 : 32026194 : if (origin == NULL && !specialization_p)
24841 : : {
24842 : 17217125 : if (TREE_PUBLIC (decl))
24843 : 15247435 : add_AT_flag (var_die, DW_AT_external, 1);
24844 : :
24845 : 17217125 : if (DECL_ARTIFICIAL (decl))
24846 : 138871 : add_AT_flag (var_die, DW_AT_artificial, 1);
24847 : :
24848 : 17217125 : add_alignment_attribute (var_die, decl);
24849 : :
24850 : 17217125 : add_accessibility_attribute (var_die, decl);
24851 : : }
24852 : :
24853 : 32026194 : if (declaration)
24854 : 15134231 : add_AT_flag (var_die, DW_AT_declaration, 1);
24855 : :
24856 : 32026194 : if (decl && (DECL_ABSTRACT_P (decl)
24857 : 32026179 : || !old_die || is_declaration_die (old_die)))
24858 : 31969307 : equate_decl_number_to_die (decl, var_die);
24859 : :
24860 : 34037451 : gen_variable_die_location:
24861 : 34037451 : if (! declaration
24862 : 34037451 : && (! DECL_ABSTRACT_P (decl_or_origin)
24863 : : /* Local static vars are shared between all clones/inlines,
24864 : : so emit DW_AT_location on the abstract DIE if DECL_RTL is
24865 : : already set. */
24866 : 0 : || (VAR_P (decl_or_origin)
24867 : 0 : && TREE_STATIC (decl_or_origin)
24868 : 0 : && DECL_RTL_SET_P (decl_or_origin))))
24869 : : {
24870 : 18903220 : if (early_dwarf)
24871 : : {
24872 : 16243985 : add_pubname (decl_or_origin, var_die);
24873 : : /* For global register variables, emit DW_AT_location if possible
24874 : : already during early_dwarf, as late_global_decl won't be usually
24875 : : called. */
24876 : 16243985 : if (DECL_HARD_REGISTER (decl_or_origin)
24877 : 76 : && TREE_STATIC (decl_or_origin)
24878 : 12 : && !decl_by_reference_p (decl_or_origin)
24879 : 12 : && !get_AT (var_die, DW_AT_location)
24880 : 6 : && !get_AT (var_die, DW_AT_const_value)
24881 : 6 : && DECL_RTL_SET_P (decl_or_origin)
24882 : 16243991 : && REG_P (DECL_RTL (decl_or_origin)))
24883 : : {
24884 : 6 : dw_loc_descr_ref descr
24885 : 6 : = reg_loc_descriptor (DECL_RTL (decl_or_origin),
24886 : : VAR_INIT_STATUS_INITIALIZED);
24887 : 6 : if (descr)
24888 : 6 : add_AT_loc (var_die, DW_AT_location, descr);
24889 : : }
24890 : : }
24891 : : else
24892 : 2659235 : add_location_or_const_value_attribute (var_die, decl_or_origin,
24893 : : decl == NULL);
24894 : : }
24895 : : else
24896 : 15134231 : tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
24897 : :
24898 : 9101 : if ((dwarf_version >= 4 || !dwarf_strict)
24899 : 34037451 : && lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
24900 : : DW_AT_const_expr) == 1
24901 : 26391885 : && !get_AT (var_die, DW_AT_const_expr)
24902 : 46945878 : && !specialization_p)
24903 : 12880366 : add_AT_flag (var_die, DW_AT_const_expr, 1);
24904 : :
24905 : 34037451 : if (!dwarf_strict)
24906 : : {
24907 : 34037449 : int inl = lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
24908 : : DW_AT_inline);
24909 : 34037449 : if (inl != -1
24910 : 26138113 : && !get_AT (var_die, DW_AT_inline)
24911 : 46822600 : && !specialization_p)
24912 : 12754711 : add_AT_unsigned (var_die, DW_AT_inline, inl);
24913 : : }
24914 : : }
24915 : :
24916 : : /* Generate a DIE to represent a named constant. */
24917 : :
24918 : : static void
24919 : 25615 : gen_const_die (tree decl, dw_die_ref context_die)
24920 : : {
24921 : 25615 : dw_die_ref const_die;
24922 : 25615 : tree type = TREE_TYPE (decl);
24923 : :
24924 : 25615 : const_die = lookup_decl_die (decl);
24925 : 25615 : if (const_die)
24926 : : return;
24927 : :
24928 : 18724 : const_die = new_die (DW_TAG_constant, context_die, decl);
24929 : 18724 : equate_decl_number_to_die (decl, const_die);
24930 : 18724 : add_name_and_src_coords_attributes (const_die, decl);
24931 : 18724 : add_type_attribute (const_die, type, TYPE_QUAL_CONST, false, context_die);
24932 : 18724 : if (TREE_PUBLIC (decl))
24933 : 356 : add_AT_flag (const_die, DW_AT_external, 1);
24934 : 18724 : if (DECL_ARTIFICIAL (decl))
24935 : 0 : add_AT_flag (const_die, DW_AT_artificial, 1);
24936 : 18724 : tree_add_const_value_attribute_for_decl (const_die, decl);
24937 : : }
24938 : :
24939 : : /* Generate a DIE to represent a label identifier. */
24940 : :
24941 : : static void
24942 : 90928 : gen_label_die (tree decl, dw_die_ref context_die)
24943 : : {
24944 : 90928 : tree origin = decl_ultimate_origin (decl);
24945 : 90928 : dw_die_ref lbl_die = lookup_decl_die (decl);
24946 : 90928 : rtx insn;
24947 : 90928 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
24948 : :
24949 : 90928 : if (!lbl_die)
24950 : : {
24951 : 54588 : lbl_die = new_die (DW_TAG_label, context_die, decl);
24952 : 54588 : equate_decl_number_to_die (decl, lbl_die);
24953 : :
24954 : 54588 : if (origin != NULL)
24955 : 13542 : add_abstract_origin_attribute (lbl_die, origin);
24956 : : else
24957 : 41046 : add_name_and_src_coords_attributes (lbl_die, decl);
24958 : : }
24959 : :
24960 : 90928 : if (DECL_ABSTRACT_P (decl))
24961 : 0 : equate_decl_number_to_die (decl, lbl_die);
24962 : 90928 : else if (! early_dwarf)
24963 : : {
24964 : 49882 : insn = DECL_RTL_IF_SET (decl);
24965 : :
24966 : : /* Deleted labels are programmer specified labels which have been
24967 : : eliminated because of various optimizations. We still emit them
24968 : : here so that it is possible to put breakpoints on them. */
24969 : 39753 : if (insn
24970 : 39753 : && (LABEL_P (insn)
24971 : 23307 : || ((NOTE_P (insn)
24972 : 23307 : && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
24973 : : {
24974 : : /* When optimization is enabled (via -O) some parts of the compiler
24975 : : (e.g. jump.cc and cse.cc) may try to delete CODE_LABEL insns which
24976 : : represent source-level labels which were explicitly declared by
24977 : : the user. This really shouldn't be happening though, so catch
24978 : : it if it ever does happen. */
24979 : 33848 : gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
24980 : :
24981 : 33848 : ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
24982 : 33848 : add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
24983 : 33848 : }
24984 : : else if (insn
24985 : 5905 : && NOTE_P (insn)
24986 : 5905 : && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
24987 : 5905 : && CODE_LABEL_NUMBER (insn) != -1)
24988 : : {
24989 : 5905 : ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
24990 : 5905 : add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
24991 : : }
24992 : : }
24993 : 90928 : }
24994 : :
24995 : : /* A helper function for gen_inlined_subroutine_die. Add source coordinate
24996 : : attributes to the DIE for a block STMT, to describe where the inlined
24997 : : function was called from. This is similar to add_src_coords_attributes. */
24998 : :
24999 : : static inline void
25000 : 6907883 : add_call_src_coords_attributes (tree stmt, dw_die_ref die)
25001 : : {
25002 : : /* We can end up with BUILTINS_LOCATION here. */
25003 : 6907883 : if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt)))
25004 : 59 : return;
25005 : :
25006 : 6907824 : location_t locus = BLOCK_SOURCE_LOCATION (stmt);
25007 : 6907824 : expanded_location s = expand_location (locus);
25008 : :
25009 : 6907824 : if (dwarf_version >= 3 || !dwarf_strict)
25010 : : {
25011 : 6907824 : add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
25012 : 6907824 : add_AT_unsigned (die, DW_AT_call_line, s.line);
25013 : 6907824 : if (debug_column_info && s.column)
25014 : 6899769 : add_AT_unsigned (die, DW_AT_call_column, s.column);
25015 : 6907824 : unsigned discr = get_discriminator_from_loc (locus);
25016 : 6907824 : if (discr != 0)
25017 : 0 : add_AT_unsigned (die, DW_AT_GNU_discriminator, discr);
25018 : : }
25019 : : }
25020 : :
25021 : :
25022 : : /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
25023 : : Add low_pc and high_pc attributes to the DIE for a block STMT. */
25024 : :
25025 : : static inline void
25026 : 7510564 : add_high_low_attributes (tree stmt, dw_die_ref die)
25027 : : {
25028 : 7510564 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
25029 : :
25030 : 7107198 : if (inline_entry_data **iedp
25031 : 7510564 : = !inline_entry_data_table ? NULL
25032 : 7107198 : : inline_entry_data_table->find_slot_with_hash (stmt,
25033 : : htab_hash_pointer (stmt),
25034 : : NO_INSERT))
25035 : : {
25036 : 6674669 : inline_entry_data *ied = *iedp;
25037 : 6674669 : gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS);
25038 : 6674669 : gcc_assert (debug_inline_points);
25039 : 6674669 : gcc_assert (inlined_function_outer_scope_p (stmt));
25040 : :
25041 : 6674669 : ASM_GENERATE_INTERNAL_LABEL (label, ied->label_pfx, ied->label_num);
25042 : 6674669 : add_AT_lbl_id (die, DW_AT_entry_pc, label);
25043 : :
25044 : 6674669 : if (debug_variable_location_views && !ZERO_VIEW_P (ied->view)
25045 : 13349053 : && !dwarf_strict)
25046 : : {
25047 : 6674384 : if (!output_asm_line_debug_info ())
25048 : 434 : add_AT_unsigned (die, DW_AT_GNU_entry_view, ied->view);
25049 : : else
25050 : : {
25051 : 6673950 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", ied->view);
25052 : : /* FIXME: this will resolve to a small number. Could we
25053 : : possibly emit smaller data? Ideally we'd emit a
25054 : : uleb128, but that would make the size of DIEs
25055 : : impossible for the compiler to compute, since it's
25056 : : the assembler that computes the value of the view
25057 : : label in this case. Ideally, we'd have a single form
25058 : : encompassing both the address and the view, and
25059 : : indirecting them through a table might make things
25060 : : easier, but even that would be more wasteful,
25061 : : space-wise, than what we have now. */
25062 : 6673950 : add_AT_symview (die, DW_AT_GNU_entry_view, label);
25063 : : }
25064 : : }
25065 : :
25066 : 6674669 : inline_entry_data_table->clear_slot (iedp);
25067 : : }
25068 : :
25069 : 7510564 : if (BLOCK_FRAGMENT_CHAIN (stmt)
25070 : 7510564 : && (dwarf_version >= 3 || !dwarf_strict))
25071 : : {
25072 : 3131822 : tree chain, superblock = NULL_TREE;
25073 : 3131822 : dw_die_ref pdie;
25074 : 3131822 : dw_attr_node *attr = NULL;
25075 : :
25076 : 3131822 : if (!debug_inline_points && inlined_function_outer_scope_p (stmt))
25077 : : {
25078 : 137 : ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
25079 : : BLOCK_NUMBER (stmt));
25080 : 137 : add_AT_lbl_id (die, DW_AT_entry_pc, label);
25081 : : }
25082 : :
25083 : : /* Optimize duplicate .debug_ranges lists or even tails of
25084 : : lists. If this BLOCK has same ranges as its supercontext,
25085 : : lookup DW_AT_ranges attribute in the supercontext (and
25086 : : recursively so), verify that the ranges_table contains the
25087 : : right values and use it instead of adding a new .debug_range. */
25088 : 1592879 : for (chain = stmt, pdie = die;
25089 : 4724701 : BLOCK_SAME_RANGE (chain);
25090 : 1592879 : chain = BLOCK_SUPERCONTEXT (chain))
25091 : : {
25092 : 1680405 : dw_attr_node *new_attr;
25093 : :
25094 : 1680405 : pdie = pdie->die_parent;
25095 : 1680405 : if (pdie == NULL)
25096 : : break;
25097 : 1680405 : if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
25098 : : break;
25099 : 1680405 : new_attr = get_AT (pdie, DW_AT_ranges);
25100 : 1680405 : if (new_attr == NULL
25101 : 1592879 : || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
25102 : : break;
25103 : 1592879 : attr = new_attr;
25104 : 1592879 : superblock = BLOCK_SUPERCONTEXT (chain);
25105 : : }
25106 : 3131822 : if (attr != NULL
25107 : 789646 : && ((*ranges_table)[attr->dw_attr_val.v.val_offset].num
25108 : 789646 : == (int)BLOCK_NUMBER (superblock))
25109 : 3608798 : && BLOCK_FRAGMENT_CHAIN (superblock))
25110 : : {
25111 : : unsigned long off = attr->dw_attr_val.v.val_offset;
25112 : 1339118 : unsigned long supercnt = 0, thiscnt = 0;
25113 : 862142 : for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
25114 : 1339118 : chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
25115 : : {
25116 : 862142 : ++supercnt;
25117 : 862142 : gcc_checking_assert ((*ranges_table)[off + supercnt].num
25118 : : == (int)BLOCK_NUMBER (chain));
25119 : : }
25120 : 476976 : gcc_checking_assert ((*ranges_table)[off + supercnt + 1].num == 0);
25121 : 476976 : for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
25122 : 1328499 : chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
25123 : 851523 : ++thiscnt;
25124 : 476976 : gcc_assert (supercnt >= thiscnt);
25125 : 476976 : add_AT_range_list (die, DW_AT_ranges, off + supercnt - thiscnt,
25126 : : false);
25127 : 476976 : note_rnglist_head (off + supercnt - thiscnt);
25128 : 476976 : return;
25129 : : }
25130 : :
25131 : 2654846 : unsigned int offset = add_ranges (stmt, true);
25132 : 2654846 : add_AT_range_list (die, DW_AT_ranges, offset, false);
25133 : 2654846 : note_rnglist_head (offset);
25134 : :
25135 : 2654846 : bool prev_in_cold = BLOCK_IN_COLD_SECTION_P (stmt);
25136 : 2654846 : chain = BLOCK_FRAGMENT_CHAIN (stmt);
25137 : 5019823 : do
25138 : : {
25139 : 5019823 : add_ranges (chain, prev_in_cold != BLOCK_IN_COLD_SECTION_P (chain));
25140 : 5019823 : prev_in_cold = BLOCK_IN_COLD_SECTION_P (chain);
25141 : 5019823 : chain = BLOCK_FRAGMENT_CHAIN (chain);
25142 : : }
25143 : 5019823 : while (chain);
25144 : 2654846 : add_ranges (NULL);
25145 : : }
25146 : : else
25147 : : {
25148 : 4378742 : char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
25149 : 4378742 : ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
25150 : : BLOCK_NUMBER (stmt));
25151 : 4378742 : ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
25152 : : BLOCK_NUMBER (stmt));
25153 : 4378742 : add_AT_low_high_pc (die, label, label_high, false);
25154 : : }
25155 : : }
25156 : :
25157 : : /* Generate a DIE for a lexical block. */
25158 : :
25159 : : static void
25160 : 1057864 : gen_lexical_block_die (tree stmt, dw_die_ref context_die)
25161 : : {
25162 : 1057864 : dw_die_ref old_die = lookup_block_die (stmt);
25163 : 1057864 : dw_die_ref stmt_die = NULL;
25164 : 1057864 : if (!old_die)
25165 : : {
25166 : 788226 : stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
25167 : 788226 : equate_block_to_die (stmt, stmt_die);
25168 : : }
25169 : :
25170 : 1057864 : if (BLOCK_ABSTRACT_ORIGIN (stmt))
25171 : : {
25172 : : /* If this is an inlined or conrecte instance, create a new lexical
25173 : : die for anything below to attach DW_AT_abstract_origin to. */
25174 : 361246 : if (old_die)
25175 : 10424 : stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
25176 : :
25177 : 361246 : tree origin = block_ultimate_origin (stmt);
25178 : 361246 : if (origin != NULL_TREE && (origin != stmt || old_die))
25179 : 360529 : add_abstract_origin_attribute (stmt_die, origin);
25180 : :
25181 : : old_die = NULL;
25182 : : }
25183 : :
25184 : 696618 : if (old_die)
25185 : 259214 : stmt_die = old_die;
25186 : :
25187 : : /* A non abstract block whose blocks have already been reordered
25188 : : should have the instruction range for this block. If so, set the
25189 : : high/low attributes. */
25190 : 1057864 : if (!early_dwarf && TREE_ASM_WRITTEN (stmt))
25191 : : {
25192 : 602681 : gcc_assert (stmt_die);
25193 : 602681 : add_high_low_attributes (stmt, stmt_die);
25194 : : }
25195 : :
25196 : 1057864 : decls_for_scope (stmt, stmt_die);
25197 : 1057864 : }
25198 : :
25199 : : /* Generate a DIE for an inlined subprogram. */
25200 : :
25201 : : static void
25202 : 6907883 : gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
25203 : : {
25204 : 6907883 : tree decl = block_ultimate_origin (stmt);
25205 : :
25206 : : /* Make sure any inlined functions are known to be inlineable. */
25207 : 6907883 : gcc_checking_assert (DECL_ABSTRACT_P (decl)
25208 : : || cgraph_function_possibly_inlined_p (decl));
25209 : :
25210 : 6907883 : dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
25211 : :
25212 : 6907883 : if (call_arg_locations || debug_inline_points)
25213 : 6899572 : equate_block_to_die (stmt, subr_die);
25214 : 6907883 : add_abstract_origin_attribute (subr_die, decl);
25215 : 6907883 : if (TREE_ASM_WRITTEN (stmt))
25216 : 6907883 : add_high_low_attributes (stmt, subr_die);
25217 : 6907883 : add_call_src_coords_attributes (stmt, subr_die);
25218 : :
25219 : : /* The inliner creates an extra BLOCK for the parameter setup,
25220 : : we want to merge that with the actual outermost BLOCK of the
25221 : : inlined function to avoid duplicate locals in consumers.
25222 : : Do that by doing the recursion to subblocks on the single subblock
25223 : : of STMT. */
25224 : 6907883 : bool unwrap_one = false;
25225 : 6907883 : tree sub = BLOCK_SUBBLOCKS (stmt);
25226 : 6907883 : if (sub)
25227 : : {
25228 : 5356582 : tree origin = block_ultimate_origin (sub);
25229 : 5356582 : if (origin
25230 : 5356582 : && TREE_CODE (origin) == BLOCK
25231 : 8755536 : && BLOCK_SUPERCONTEXT (origin) == decl)
25232 : : unwrap_one = true;
25233 : 8500114 : for (tree next = BLOCK_CHAIN (sub); unwrap_one && next;
25234 : 3143532 : next = BLOCK_CHAIN (next))
25235 : 3143532 : if (BLOCK_FRAGMENT_ORIGIN (next) != sub)
25236 : 4544 : unwrap_one = false;
25237 : : }
25238 : 6907883 : decls_for_scope (stmt, subr_die, !unwrap_one);
25239 : 6907883 : if (unwrap_one)
25240 : : {
25241 : 3286290 : decls_for_scope (sub, subr_die);
25242 : 6422568 : for (sub = BLOCK_CHAIN (sub); sub; sub = BLOCK_CHAIN (sub))
25243 : 3136278 : gen_block_die (sub, subr_die);
25244 : : }
25245 : 6907883 : }
25246 : :
25247 : : /* Generate a DIE for a field in a record, or structure. CTX is required: see
25248 : : the comment for VLR_CONTEXT. */
25249 : :
25250 : : static void
25251 : 13827242 : gen_field_die (tree decl, struct vlr_context *ctx, dw_die_ref context_die)
25252 : : {
25253 : 13827242 : dw_die_ref decl_die;
25254 : :
25255 : 13827242 : if (TREE_TYPE (decl) == error_mark_node)
25256 : : return;
25257 : :
25258 : 13827242 : decl_die = new_die (DW_TAG_member, context_die, decl);
25259 : 13827242 : add_name_and_src_coords_attributes (decl_die, decl);
25260 : 27654484 : add_type_attribute (decl_die, member_declared_type (decl), decl_quals (decl),
25261 : 13827242 : TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl)),
25262 : : context_die);
25263 : :
25264 : 13827242 : if (DECL_BIT_FIELD_TYPE (decl))
25265 : : {
25266 : 270141 : add_byte_size_attribute (decl_die, decl);
25267 : 270141 : add_bit_size_attribute (decl_die, decl);
25268 : 270141 : add_bit_offset_attribute (decl_die, decl);
25269 : : }
25270 : :
25271 : 13827242 : add_alignment_attribute (decl_die, decl);
25272 : :
25273 : 13827242 : if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
25274 : 12719652 : add_data_member_location_attribute (decl_die, decl, ctx);
25275 : :
25276 : 13827242 : if (DECL_ARTIFICIAL (decl))
25277 : 47127 : add_AT_flag (decl_die, DW_AT_artificial, 1);
25278 : :
25279 : 13827242 : add_accessibility_attribute (decl_die, decl);
25280 : :
25281 : : /* Add DW_AT_export_symbols to anonymous unions or structs. */
25282 : 13827242 : if ((dwarf_version >= 5 || !dwarf_strict) && DECL_NAME (decl) == NULL_TREE)
25283 : 130295 : if (tree type = member_declared_type (decl))
25284 : 130295 : if (lang_hooks.types.type_dwarf_attribute (TYPE_MAIN_VARIANT (type),
25285 : : DW_AT_export_symbols) != -1)
25286 : : {
25287 : 130215 : dw_die_ref type_die = lookup_type_die (TYPE_MAIN_VARIANT (type));
25288 : 130215 : if (type_die && get_AT (type_die, DW_AT_export_symbols) == NULL)
25289 : 130215 : add_AT_flag (type_die, DW_AT_export_symbols, 1);
25290 : : }
25291 : :
25292 : : /* Equate decl number to die, so that we can look up this decl later on. */
25293 : 13827242 : equate_decl_number_to_die (decl, decl_die);
25294 : : }
25295 : :
25296 : : /* Generate a DIE for a pointer to a member type. TYPE can be an
25297 : : OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
25298 : : pointer to member function. */
25299 : :
25300 : : static void
25301 : 31939 : gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
25302 : : {
25303 : 31939 : if (lookup_type_die (type))
25304 : : return;
25305 : :
25306 : 31939 : dw_die_ref ptr_die = new_die (DW_TAG_ptr_to_member_type,
25307 : : scope_die_for (type, context_die), type);
25308 : :
25309 : 31939 : equate_type_number_to_die (type, ptr_die);
25310 : 63878 : add_AT_die_ref (ptr_die, DW_AT_containing_type,
25311 : 31939 : lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
25312 : 31939 : add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
25313 : : context_die);
25314 : 31939 : add_alignment_attribute (ptr_die, type);
25315 : :
25316 : 31939 : if (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
25317 : 31939 : && TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)
25318 : : {
25319 : 500 : dw_loc_descr_ref op = new_loc_descr (DW_OP_plus, 0, 0);
25320 : 500 : add_AT_loc (ptr_die, DW_AT_use_location, op);
25321 : : }
25322 : : }
25323 : :
25324 : : static char *producer_string;
25325 : :
25326 : : /* Given a C and/or C++ language/version string return the "highest".
25327 : : C++ is assumed to be "higher" than C in this case. Used for merging
25328 : : LTO translation unit languages. */
25329 : : static const char *
25330 : 1 : highest_c_language (const char *lang1, const char *lang2)
25331 : : {
25332 : 1 : if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
25333 : : return "GNU C++26";
25334 : 1 : if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
25335 : : return "GNU C++23";
25336 : 1 : if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
25337 : : return "GNU C++20";
25338 : 1 : if (strcmp ("GNU C++17", lang1) == 0 || strcmp ("GNU C++17", lang2) == 0)
25339 : : return "GNU C++17";
25340 : 0 : if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
25341 : : return "GNU C++14";
25342 : 0 : if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
25343 : : return "GNU C++11";
25344 : 0 : if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
25345 : : return "GNU C++98";
25346 : :
25347 : 0 : if (strcmp ("GNU C2Y", lang1) == 0 || strcmp ("GNU C2Y", lang2) == 0)
25348 : : return "GNU C2Y";
25349 : 0 : if (strcmp ("GNU C23", lang1) == 0 || strcmp ("GNU C23", lang2) == 0)
25350 : : return "GNU C23";
25351 : 0 : if (strcmp ("GNU C17", lang1) == 0 || strcmp ("GNU C17", lang2) == 0)
25352 : : return "GNU C17";
25353 : 0 : if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
25354 : : return "GNU C11";
25355 : 0 : if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
25356 : : return "GNU C99";
25357 : 0 : if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
25358 : : return "GNU C89";
25359 : :
25360 : 0 : gcc_unreachable ();
25361 : : }
25362 : :
25363 : :
25364 : : /* Generate the DIE for the compilation unit. */
25365 : :
25366 : : static dw_die_ref
25367 : 57055 : gen_compile_unit_die (const char *filename)
25368 : : {
25369 : 57055 : dw_die_ref die;
25370 : 57055 : const char *language_string = lang_hooks.name;
25371 : 57055 : int language, lname, lversion;
25372 : :
25373 : 57055 : die = new_die (DW_TAG_compile_unit, NULL, NULL);
25374 : :
25375 : 57055 : if (filename)
25376 : : {
25377 : 0 : add_filename_attribute (die, filename);
25378 : : /* Don't add cwd for <built-in>. */
25379 : 0 : if (filename[0] != '<')
25380 : 0 : add_comp_dir_attribute (die);
25381 : : }
25382 : :
25383 : 57304 : add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
25384 : :
25385 : : /* If our producer is LTO try to figure out a common language to use
25386 : : from the global list of translation units. */
25387 : 57055 : if (strcmp (language_string, "GNU GIMPLE") == 0)
25388 : : {
25389 : : unsigned i;
25390 : : tree t;
25391 : : const char *common_lang = NULL;
25392 : :
25393 : 1646 : FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
25394 : : {
25395 : 834 : if (!TRANSLATION_UNIT_LANGUAGE (t))
25396 : 0 : continue;
25397 : 834 : if (!common_lang)
25398 : : common_lang = TRANSLATION_UNIT_LANGUAGE (t);
25399 : 22 : else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
25400 : : ;
25401 : 1 : else if (startswith (common_lang, "GNU C")
25402 : 1 : && startswith (TRANSLATION_UNIT_LANGUAGE (t), "GNU C"))
25403 : : /* Mixing C and C++ is ok, use C++ in that case. */
25404 : 1 : common_lang = highest_c_language (common_lang,
25405 : 1 : TRANSLATION_UNIT_LANGUAGE (t));
25406 : : else
25407 : : {
25408 : : /* Fall back to C. */
25409 : : common_lang = NULL;
25410 : : break;
25411 : : }
25412 : : }
25413 : :
25414 : 812 : if (common_lang)
25415 : 57055 : language_string = common_lang;
25416 : : }
25417 : :
25418 : 57055 : language = DW_LANG_C;
25419 : 57055 : lname = 0;
25420 : 57055 : lversion = 0;
25421 : 57055 : if (startswith (language_string, "GNU C")
25422 : 57055 : && ISDIGIT (language_string[5]))
25423 : : {
25424 : 24246 : language = DW_LANG_C89;
25425 : 24246 : if (dwarf_version >= 3 || !dwarf_strict)
25426 : : {
25427 : 24246 : if (strcmp (language_string, "GNU C89") != 0)
25428 : 23030 : language = DW_LANG_C99;
25429 : :
25430 : 24246 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25431 : : {
25432 : 23315 : if (strcmp (language_string, "GNU C11") == 0)
25433 : : language = DW_LANG_C11;
25434 : 19641 : else if (strcmp (language_string, "GNU C17") == 0)
25435 : : {
25436 : : language = DW_LANG_C11;
25437 : : lname = DW_LNAME_C;
25438 : : lversion = 201710;
25439 : : }
25440 : 19531 : else if (strcmp (language_string, "GNU C23") == 0)
25441 : : {
25442 : : language = DW_LANG_C11;
25443 : : lname = DW_LNAME_C;
25444 : : lversion = 202311;
25445 : : }
25446 : 1296 : else if (strcmp (language_string, "GNU C2Y") == 0)
25447 : : {
25448 : 57055 : language = DW_LANG_C11;
25449 : 57055 : lname = DW_LNAME_C;
25450 : 57055 : lversion = 202500;
25451 : : }
25452 : : }
25453 : : }
25454 : : }
25455 : 32809 : else if (startswith (language_string, "GNU C++"))
25456 : : {
25457 : 18531 : language = DW_LANG_C_plus_plus;
25458 : 18531 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25459 : : {
25460 : 17346 : if (strcmp (language_string, "GNU C++11") == 0)
25461 : : language = DW_LANG_C_plus_plus_11;
25462 : 16920 : else if (strcmp (language_string, "GNU C++14") == 0)
25463 : : language = DW_LANG_C_plus_plus_14;
25464 : 16902 : else if (strcmp (language_string, "GNU C++17") == 0)
25465 : : {
25466 : : language = DW_LANG_C_plus_plus_14;
25467 : : lname = DW_LNAME_C_plus_plus;
25468 : : lversion = 201703;
25469 : : }
25470 : 3349 : else if (strcmp (language_string, "GNU C++20") == 0)
25471 : : {
25472 : : language = DW_LANG_C_plus_plus_14;
25473 : : lname = DW_LNAME_C_plus_plus;
25474 : : lversion = 202002;
25475 : : }
25476 : 2262 : else if (strcmp (language_string, "GNU C++23") == 0)
25477 : : {
25478 : : language = DW_LANG_C_plus_plus_14;
25479 : : lname = DW_LNAME_C_plus_plus;
25480 : : lversion = 202302;
25481 : : }
25482 : 1984 : else if (strcmp (language_string, "GNU C++26") == 0)
25483 : : {
25484 : 57055 : language = DW_LANG_C_plus_plus_14;
25485 : 57055 : lname = DW_LNAME_C_plus_plus;
25486 : 57055 : lversion = 202400;
25487 : : }
25488 : : }
25489 : : }
25490 : 14278 : else if (strcmp (language_string, "GNU F77") == 0)
25491 : : language = DW_LANG_Fortran77;
25492 : 14278 : else if (strcmp (language_string, "GCC COBOL") == 0)
25493 : : language = DW_LANG_Cobol85;
25494 : 14278 : else if (strcmp (language_string, "GNU Modula-2") == 0)
25495 : : language = DW_LANG_Modula2;
25496 : 10538 : else if (dwarf_version >= 3 || !dwarf_strict)
25497 : : {
25498 : 10538 : if (strcmp (language_string, "GNU Ada") == 0)
25499 : : language = DW_LANG_Ada95;
25500 : 10538 : else if (startswith (language_string, "GNU Fortran"))
25501 : : {
25502 : 5045 : language = DW_LANG_Fortran95;
25503 : 5045 : if (dwarf_version >= 5 /* || !dwarf_strict */)
25504 : : {
25505 : 5021 : if (strcmp (language_string, "GNU Fortran2003") == 0)
25506 : : language = DW_LANG_Fortran03;
25507 : 4998 : else if (strcmp (language_string, "GNU Fortran2008") == 0)
25508 : 57055 : language = DW_LANG_Fortran08;
25509 : : }
25510 : : }
25511 : 5493 : else if (strcmp (language_string, "GNU Objective-C") == 0)
25512 : : language = DW_LANG_ObjC;
25513 : 5493 : else if (strcmp (language_string, "GNU Objective-C++") == 0)
25514 : : language = DW_LANG_ObjC_plus_plus;
25515 : 5493 : else if (strcmp (language_string, "GNU D") == 0)
25516 : : language = DW_LANG_D;
25517 : 5493 : else if (dwarf_version >= 5 || !dwarf_strict)
25518 : : {
25519 : 5492 : if (strcmp (language_string, "GNU Go") == 0)
25520 : : language = DW_LANG_Go;
25521 : 1230 : else if (strcmp (language_string, "GNU Rust") == 0)
25522 : 57055 : language = DW_LANG_Rust;
25523 : : }
25524 : : }
25525 : : /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
25526 : 0 : else if (startswith (language_string, "GNU Fortran"))
25527 : : language = DW_LANG_Fortran90;
25528 : : /* Likewise for Ada. */
25529 : 0 : else if (strcmp (language_string, "GNU Ada") == 0)
25530 : 57055 : language = DW_LANG_Ada83;
25531 : :
25532 : 57055 : add_AT_unsigned (die, DW_AT_language, language);
25533 : 57055 : if (lname && dwarf_version >= 5 && !dwarf_strict)
25534 : : {
25535 : 34882 : add_AT_unsigned (die, DW_AT_language_name, lname);
25536 : 34882 : add_AT_unsigned (die, DW_AT_language_version, lversion);
25537 : : }
25538 : :
25539 : 57055 : switch (language)
25540 : : {
25541 : 5045 : case DW_LANG_Fortran77:
25542 : 5045 : case DW_LANG_Fortran90:
25543 : 5045 : case DW_LANG_Fortran95:
25544 : 5045 : case DW_LANG_Fortran03:
25545 : 5045 : case DW_LANG_Fortran08:
25546 : : /* Fortran has case insensitive identifiers and the front-end
25547 : : lowercases everything. */
25548 : 5045 : add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
25549 : 5045 : break;
25550 : 0 : case DW_LANG_Cobol85:
25551 : 0 : add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_case_insensitive);
25552 : 0 : break;
25553 : : default:
25554 : : /* The default DW_ID_case_sensitive doesn't need to be specified. */
25555 : : break;
25556 : : }
25557 : 57055 : return die;
25558 : : }
25559 : :
25560 : : /* Generate the DIE for a base class. */
25561 : :
25562 : : static void
25563 : 17169745 : gen_inheritance_die (tree binfo, tree access, tree type,
25564 : : dw_die_ref context_die)
25565 : : {
25566 : 17169745 : dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
25567 : 17169745 : struct vlr_context ctx = { type, NULL };
25568 : :
25569 : 17169745 : add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, false,
25570 : : context_die);
25571 : 17169745 : add_data_member_location_attribute (die, binfo, &ctx);
25572 : :
25573 : 17169745 : if (BINFO_VIRTUAL_P (binfo))
25574 : 294 : add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
25575 : :
25576 : : /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
25577 : : children, otherwise the default is DW_ACCESS_public. In DWARF2
25578 : : the default has always been DW_ACCESS_private. */
25579 : 17169745 : if (access == access_public_node)
25580 : : {
25581 : 16695456 : if (dwarf_version == 2
25582 : 16695042 : || context_die->die_tag == DW_TAG_class_type)
25583 : 860574 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
25584 : : }
25585 : 474289 : else if (access == access_protected_node)
25586 : 68201 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
25587 : 406088 : else if (dwarf_version > 2
25588 : 406082 : && context_die->die_tag != DW_TAG_class_type)
25589 : 187719 : add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
25590 : 17169745 : }
25591 : :
25592 : : /* Return whether DECL is a FIELD_DECL that represents the variant part of a
25593 : : structure. */
25594 : :
25595 : : static bool
25596 : 200729518 : is_variant_part (tree decl)
25597 : : {
25598 : 200729518 : return (TREE_CODE (decl) == FIELD_DECL
25599 : 200729518 : && TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
25600 : : }
25601 : :
25602 : : /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
25603 : : return the FIELD_DECL. Return NULL_TREE otherwise. */
25604 : :
25605 : : static tree
25606 : 0 : analyze_discr_in_predicate (tree operand, tree struct_type)
25607 : : {
25608 : 0 : while (CONVERT_EXPR_P (operand))
25609 : 0 : operand = TREE_OPERAND (operand, 0);
25610 : :
25611 : : /* Match field access to members of struct_type only. */
25612 : 0 : if (TREE_CODE (operand) == COMPONENT_REF
25613 : 0 : && TREE_CODE (TREE_OPERAND (operand, 0)) == PLACEHOLDER_EXPR
25614 : 0 : && TREE_TYPE (TREE_OPERAND (operand, 0)) == struct_type
25615 : 0 : && TREE_CODE (TREE_OPERAND (operand, 1)) == FIELD_DECL)
25616 : 0 : return TREE_OPERAND (operand, 1);
25617 : : else
25618 : : return NULL_TREE;
25619 : : }
25620 : :
25621 : : /* Check that SRC is a constant integer that can be represented as a native
25622 : : integer constant (either signed or unsigned). If so, store it into DEST and
25623 : : return true. Return false otherwise. */
25624 : :
25625 : : static bool
25626 : 0 : get_discr_value (tree src, dw_discr_value *dest)
25627 : : {
25628 : 0 : tree discr_type = TREE_TYPE (src);
25629 : :
25630 : 0 : if (lang_hooks.types.get_debug_type)
25631 : : {
25632 : 0 : tree debug_type = lang_hooks.types.get_debug_type (discr_type);
25633 : 0 : if (debug_type != NULL)
25634 : 0 : discr_type = debug_type;
25635 : : }
25636 : :
25637 : 0 : if (TREE_CODE (src) != INTEGER_CST || !INTEGRAL_TYPE_P (discr_type))
25638 : : return false;
25639 : :
25640 : : /* Signedness can vary between the original type and the debug type. This
25641 : : can happen for character types in Ada for instance: the character type
25642 : : used for code generation can be signed, to be compatible with the C one,
25643 : : but from a debugger point of view, it must be unsigned. */
25644 : 0 : bool is_orig_unsigned = TYPE_UNSIGNED (TREE_TYPE (src));
25645 : 0 : bool is_debug_unsigned = TYPE_UNSIGNED (discr_type);
25646 : :
25647 : 0 : if (is_orig_unsigned != is_debug_unsigned)
25648 : 0 : src = fold_convert (discr_type, src);
25649 : :
25650 : 0 : if (!(is_debug_unsigned ? tree_fits_uhwi_p (src) : tree_fits_shwi_p (src)))
25651 : : return false;
25652 : :
25653 : 0 : dest->pos = is_debug_unsigned;
25654 : 0 : if (is_debug_unsigned)
25655 : 0 : dest->v.uval = tree_to_uhwi (src);
25656 : : else
25657 : 0 : dest->v.sval = tree_to_shwi (src);
25658 : :
25659 : : return true;
25660 : : }
25661 : :
25662 : : /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
25663 : : FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
25664 : : store NULL_TREE in DISCR_DECL. Otherwise:
25665 : :
25666 : : - store the discriminant field in STRUCT_TYPE that controls the variant
25667 : : part to *DISCR_DECL
25668 : :
25669 : : - put in *DISCR_LISTS_P an array where for each variant, the item
25670 : : represents the corresponding matching list of discriminant values.
25671 : :
25672 : : - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
25673 : : the above array.
25674 : :
25675 : : Note that when the array is allocated (i.e. when the analysis is
25676 : : successful), it is up to the caller to free the array. */
25677 : :
25678 : : static void
25679 : 0 : analyze_variants_discr (tree variant_part_decl,
25680 : : tree struct_type,
25681 : : tree *discr_decl,
25682 : : dw_discr_list_ref **discr_lists_p,
25683 : : unsigned *discr_lists_length)
25684 : : {
25685 : 0 : tree variant_part_type = TREE_TYPE (variant_part_decl);
25686 : 0 : tree variant;
25687 : 0 : dw_discr_list_ref *discr_lists;
25688 : 0 : unsigned i;
25689 : :
25690 : : /* Compute how many variants there are in this variant part. */
25691 : 0 : *discr_lists_length = 0;
25692 : 0 : for (variant = TYPE_FIELDS (variant_part_type);
25693 : 0 : variant != NULL_TREE;
25694 : 0 : variant = DECL_CHAIN (variant))
25695 : 0 : ++*discr_lists_length;
25696 : :
25697 : 0 : *discr_decl = NULL_TREE;
25698 : 0 : *discr_lists_p
25699 : 0 : = (dw_discr_list_ref *) xcalloc (*discr_lists_length,
25700 : : sizeof (**discr_lists_p));
25701 : 0 : discr_lists = *discr_lists_p;
25702 : :
25703 : : /* And then analyze all variants to extract discriminant information for all
25704 : : of them. This analysis is conservative: as soon as we detect something we
25705 : : do not support, abort everything and pretend we found nothing. */
25706 : 0 : for (variant = TYPE_FIELDS (variant_part_type), i = 0;
25707 : 0 : variant != NULL_TREE;
25708 : 0 : variant = DECL_CHAIN (variant), ++i)
25709 : : {
25710 : 0 : tree match_expr = DECL_QUALIFIER (variant);
25711 : :
25712 : : /* Now, try to analyze the predicate and deduce a discriminant for
25713 : : it. */
25714 : 0 : if (match_expr == boolean_true_node)
25715 : : /* Typically happens for the default variant: it matches all cases that
25716 : : previous variants rejected. Don't output any matching value for
25717 : : this one. */
25718 : 0 : continue;
25719 : :
25720 : : /* The following loop tries to iterate over each discriminant
25721 : : possibility: single values or ranges. */
25722 : 0 : while (match_expr != NULL_TREE)
25723 : : {
25724 : 0 : tree next_round_match_expr;
25725 : 0 : tree candidate_discr = NULL_TREE;
25726 : 0 : dw_discr_list_ref new_node = NULL;
25727 : :
25728 : : /* Possibilities are matched one after the other by nested
25729 : : TRUTH_ORIF_EXPR expressions. Process the current possibility and
25730 : : continue with the rest at next iteration. */
25731 : 0 : if (TREE_CODE (match_expr) == TRUTH_ORIF_EXPR)
25732 : : {
25733 : 0 : next_round_match_expr = TREE_OPERAND (match_expr, 0);
25734 : 0 : match_expr = TREE_OPERAND (match_expr, 1);
25735 : : }
25736 : : else
25737 : : next_round_match_expr = NULL_TREE;
25738 : :
25739 : 0 : if (match_expr == boolean_false_node)
25740 : : /* This sub-expression matches nothing: just wait for the next
25741 : : one. */
25742 : : ;
25743 : :
25744 : 0 : else if (TREE_CODE (match_expr) == EQ_EXPR)
25745 : : {
25746 : : /* We are matching: <discr_field> == <integer_cst>
25747 : : This sub-expression matches a single value. */
25748 : 0 : tree integer_cst = TREE_OPERAND (match_expr, 1);
25749 : :
25750 : 0 : candidate_discr
25751 : 0 : = analyze_discr_in_predicate (TREE_OPERAND (match_expr, 0),
25752 : : struct_type);
25753 : :
25754 : 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
25755 : 0 : if (!get_discr_value (integer_cst,
25756 : : &new_node->dw_discr_lower_bound))
25757 : 0 : goto abort;
25758 : 0 : new_node->dw_discr_range = false;
25759 : : }
25760 : :
25761 : 0 : else if (TREE_CODE (match_expr) == TRUTH_ANDIF_EXPR)
25762 : : {
25763 : : /* We are matching:
25764 : : <discr_field> > <integer_cst>
25765 : : && <discr_field> < <integer_cst>.
25766 : : This sub-expression matches the range of values between the
25767 : : two matched integer constants. Note that comparisons can be
25768 : : inclusive or exclusive. */
25769 : 0 : tree candidate_discr_1, candidate_discr_2;
25770 : 0 : tree lower_cst, upper_cst;
25771 : 0 : bool lower_cst_included, upper_cst_included;
25772 : 0 : tree lower_op = TREE_OPERAND (match_expr, 0);
25773 : 0 : tree upper_op = TREE_OPERAND (match_expr, 1);
25774 : :
25775 : : /* When the comparison is exclusive, the integer constant is not
25776 : : the discriminant range bound we are looking for: we will have
25777 : : to increment or decrement it. */
25778 : 0 : if (TREE_CODE (lower_op) == GE_EXPR)
25779 : : lower_cst_included = true;
25780 : 0 : else if (TREE_CODE (lower_op) == GT_EXPR)
25781 : : lower_cst_included = false;
25782 : : else
25783 : 0 : goto abort;
25784 : :
25785 : 0 : if (TREE_CODE (upper_op) == LE_EXPR)
25786 : : upper_cst_included = true;
25787 : 0 : else if (TREE_CODE (upper_op) == LT_EXPR)
25788 : : upper_cst_included = false;
25789 : : else
25790 : 0 : goto abort;
25791 : :
25792 : : /* Extract the discriminant from the first operand and check it
25793 : : is consistant with the same analysis in the second
25794 : : operand. */
25795 : 0 : candidate_discr_1
25796 : 0 : = analyze_discr_in_predicate (TREE_OPERAND (lower_op, 0),
25797 : : struct_type);
25798 : 0 : candidate_discr_2
25799 : 0 : = analyze_discr_in_predicate (TREE_OPERAND (upper_op, 0),
25800 : : struct_type);
25801 : 0 : if (candidate_discr_1 == candidate_discr_2)
25802 : 0 : candidate_discr = candidate_discr_1;
25803 : : else
25804 : 0 : goto abort;
25805 : :
25806 : : /* Extract bounds from both. */
25807 : 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
25808 : 0 : lower_cst = TREE_OPERAND (lower_op, 1);
25809 : 0 : upper_cst = TREE_OPERAND (upper_op, 1);
25810 : :
25811 : 0 : if (!lower_cst_included)
25812 : 0 : lower_cst
25813 : 0 : = fold_build2 (PLUS_EXPR, TREE_TYPE (lower_cst), lower_cst,
25814 : : build_int_cst (TREE_TYPE (lower_cst), 1));
25815 : 0 : if (!upper_cst_included)
25816 : 0 : upper_cst
25817 : 0 : = fold_build2 (MINUS_EXPR, TREE_TYPE (upper_cst), upper_cst,
25818 : : build_int_cst (TREE_TYPE (upper_cst), 1));
25819 : :
25820 : 0 : if (!get_discr_value (lower_cst,
25821 : : &new_node->dw_discr_lower_bound)
25822 : 0 : || !get_discr_value (upper_cst,
25823 : : &new_node->dw_discr_upper_bound))
25824 : 0 : goto abort;
25825 : :
25826 : 0 : new_node->dw_discr_range = true;
25827 : : }
25828 : :
25829 : 0 : else if ((candidate_discr
25830 : 0 : = analyze_discr_in_predicate (match_expr, struct_type))
25831 : 0 : && (TREE_TYPE (candidate_discr) == boolean_type_node
25832 : 0 : || TREE_TYPE (TREE_TYPE (candidate_discr))
25833 : : == boolean_type_node))
25834 : : {
25835 : : /* We are matching: <discr_field> for a boolean discriminant.
25836 : : This sub-expression matches boolean_true_node. */
25837 : 0 : new_node = ggc_cleared_alloc<dw_discr_list_node> ();
25838 : 0 : if (!get_discr_value (boolean_true_node,
25839 : : &new_node->dw_discr_lower_bound))
25840 : 0 : goto abort;
25841 : 0 : new_node->dw_discr_range = false;
25842 : : }
25843 : :
25844 : : else
25845 : : /* Unsupported sub-expression: we cannot determine the set of
25846 : : matching discriminant values. Abort everything. */
25847 : 0 : goto abort;
25848 : :
25849 : : /* If the discriminant info is not consistant with what we saw so
25850 : : far, consider the analysis failed and abort everything. */
25851 : 0 : if (candidate_discr == NULL_TREE
25852 : 0 : || (*discr_decl != NULL_TREE && candidate_discr != *discr_decl))
25853 : 0 : goto abort;
25854 : : else
25855 : 0 : *discr_decl = candidate_discr;
25856 : :
25857 : 0 : if (new_node != NULL)
25858 : : {
25859 : 0 : new_node->dw_discr_next = discr_lists[i];
25860 : 0 : discr_lists[i] = new_node;
25861 : : }
25862 : 0 : match_expr = next_round_match_expr;
25863 : : }
25864 : : }
25865 : :
25866 : : /* If we reach this point, we could match everything we were interested
25867 : : in. */
25868 : : return;
25869 : :
25870 : 0 : abort:
25871 : : /* Clean all data structure and return no result. */
25872 : 0 : free (*discr_lists_p);
25873 : 0 : *discr_lists_p = NULL;
25874 : 0 : *discr_decl = NULL_TREE;
25875 : : }
25876 : :
25877 : : /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
25878 : : of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
25879 : : under CONTEXT_DIE.
25880 : :
25881 : : Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
25882 : : QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
25883 : : this type, which are record types, represent the available variants and each
25884 : : has a DECL_QUALIFIER attribute. The discriminant and the discriminant
25885 : : values are inferred from these attributes.
25886 : :
25887 : : In trees, the offsets for the fields inside these sub-records are relative
25888 : : to the variant part itself, whereas the corresponding DIEs should have
25889 : : offset attributes that are relative to the embedding record base address.
25890 : : This is why the caller must provide a VARIANT_PART_OFFSET expression: it
25891 : : must be an expression that computes the offset of the variant part to
25892 : : describe in DWARF. */
25893 : :
25894 : : static void
25895 : 0 : gen_variant_part (tree variant_part_decl, struct vlr_context *vlr_ctx,
25896 : : dw_die_ref context_die)
25897 : : {
25898 : 0 : const tree variant_part_type = TREE_TYPE (variant_part_decl);
25899 : 0 : tree variant_part_offset = vlr_ctx->variant_part_offset;
25900 : :
25901 : : /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
25902 : : NULL_TREE if there is no such field. */
25903 : 0 : tree discr_decl = NULL_TREE;
25904 : 0 : dw_discr_list_ref *discr_lists;
25905 : 0 : unsigned discr_lists_length = 0;
25906 : 0 : unsigned i;
25907 : :
25908 : 0 : dw_die_ref dwarf_proc_die = NULL;
25909 : 0 : dw_die_ref variant_part_die
25910 : 0 : = new_die (DW_TAG_variant_part, context_die, variant_part_type);
25911 : :
25912 : 0 : equate_decl_number_to_die (variant_part_decl, variant_part_die);
25913 : :
25914 : 0 : analyze_variants_discr (variant_part_decl, vlr_ctx->struct_type,
25915 : : &discr_decl, &discr_lists, &discr_lists_length);
25916 : :
25917 : 0 : if (discr_decl != NULL_TREE)
25918 : : {
25919 : 0 : dw_die_ref discr_die = lookup_decl_die (discr_decl);
25920 : :
25921 : 0 : if (discr_die)
25922 : 0 : add_AT_die_ref (variant_part_die, DW_AT_discr, discr_die);
25923 : : else
25924 : : /* We have no DIE for the discriminant, so just discard all
25925 : : discrimimant information in the output. */
25926 : 0 : discr_decl = NULL_TREE;
25927 : : }
25928 : :
25929 : : /* If the offset for this variant part is more complex than a constant,
25930 : : create a DWARF procedure for it so that we will not have to generate
25931 : : DWARF expressions for it for each member. */
25932 : 0 : if (TREE_CODE (variant_part_offset) != INTEGER_CST
25933 : 0 : && (dwarf_version >= 3 || !dwarf_strict))
25934 : : {
25935 : 0 : struct loc_descr_context ctx = {
25936 : 0 : vlr_ctx->struct_type, /* context_type */
25937 : : NULL_TREE, /* base_decl */
25938 : : NULL, /* dpi */
25939 : : false, /* placeholder_arg */
25940 : : false, /* placeholder_seen */
25941 : : false /* strict_signedness */
25942 : 0 : };
25943 : 0 : const tree dwarf_proc_fndecl
25944 : 0 : = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
25945 : 0 : build_function_type (TREE_TYPE (variant_part_offset),
25946 : : NULL_TREE));
25947 : 0 : const tree dwarf_proc_call = build_call_expr (dwarf_proc_fndecl, 0);
25948 : 0 : const dw_loc_descr_ref dwarf_proc_body
25949 : 0 : = loc_descriptor_from_tree (variant_part_offset, 0, &ctx);
25950 : :
25951 : 0 : dwarf_proc_die = new_dwarf_proc_die (dwarf_proc_body,
25952 : : dwarf_proc_fndecl, context_die);
25953 : 0 : if (dwarf_proc_die != NULL)
25954 : 0 : variant_part_offset = dwarf_proc_call;
25955 : : }
25956 : :
25957 : : /* Output DIEs for all variants. */
25958 : 0 : i = 0;
25959 : 0 : for (tree variant = TYPE_FIELDS (variant_part_type);
25960 : 0 : variant != NULL_TREE;
25961 : 0 : variant = DECL_CHAIN (variant), ++i)
25962 : : {
25963 : 0 : tree variant_type = TREE_TYPE (variant);
25964 : 0 : dw_die_ref variant_die;
25965 : :
25966 : : /* All variants (i.e. members of a variant part) are supposed to be
25967 : : encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
25968 : : under these records. */
25969 : 0 : gcc_assert (TREE_CODE (variant_type) == RECORD_TYPE);
25970 : :
25971 : 0 : variant_die = new_die (DW_TAG_variant, variant_part_die, variant_type);
25972 : 0 : equate_decl_number_to_die (variant, variant_die);
25973 : :
25974 : : /* Output discriminant values this variant matches, if any. */
25975 : 0 : if (discr_decl == NULL || discr_lists[i] == NULL)
25976 : : /* In the case we have discriminant information at all, this is
25977 : : probably the default variant: as the standard says, don't
25978 : : output any discriminant value/list attribute. */
25979 : : ;
25980 : 0 : else if (discr_lists[i]->dw_discr_next == NULL
25981 : 0 : && !discr_lists[i]->dw_discr_range)
25982 : : /* If there is only one accepted value, don't bother outputting a
25983 : : list. */
25984 : 0 : add_discr_value (variant_die, &discr_lists[i]->dw_discr_lower_bound);
25985 : : else
25986 : 0 : add_discr_list (variant_die, discr_lists[i]);
25987 : :
25988 : 0 : for (tree member = TYPE_FIELDS (variant_type);
25989 : 0 : member != NULL_TREE;
25990 : 0 : member = DECL_CHAIN (member))
25991 : : {
25992 : 0 : struct vlr_context vlr_sub_ctx = {
25993 : 0 : vlr_ctx->struct_type, /* struct_type */
25994 : : NULL /* variant_part_offset */
25995 : 0 : };
25996 : 0 : if (is_variant_part (member))
25997 : : {
25998 : : /* All offsets for fields inside variant parts are relative to
25999 : : the top-level embedding RECORD_TYPE's base address. On the
26000 : : other hand, offsets in GCC's types are relative to the
26001 : : nested-most variant part. So we have to sum offsets each time
26002 : : we recurse. */
26003 : :
26004 : 0 : vlr_sub_ctx.variant_part_offset
26005 : 0 : = fold_build2 (PLUS_EXPR, TREE_TYPE (variant_part_offset),
26006 : : variant_part_offset, byte_position (member));
26007 : 0 : gen_variant_part (member, &vlr_sub_ctx, variant_die);
26008 : : }
26009 : : else
26010 : : {
26011 : 0 : vlr_sub_ctx.variant_part_offset = variant_part_offset;
26012 : 0 : gen_decl_die (member, NULL, &vlr_sub_ctx, variant_die);
26013 : : }
26014 : : }
26015 : : }
26016 : :
26017 : 0 : free (discr_lists);
26018 : 0 : }
26019 : :
26020 : : /* Generate a DIE for a class member. */
26021 : :
26022 : : static void
26023 : 33603200 : gen_member_die (tree type, dw_die_ref context_die)
26024 : : {
26025 : 33603200 : tree member;
26026 : 33603200 : tree binfo = TYPE_BINFO (type);
26027 : :
26028 : 33603200 : gcc_assert (TYPE_MAIN_VARIANT (type) == type);
26029 : :
26030 : : /* If this is not an incomplete type, output descriptions of each of its
26031 : : members. Note that as we output the DIEs necessary to represent the
26032 : : members of this record or union type, we will also be trying to output
26033 : : DIEs to represent the *types* of those members. However the `type'
26034 : : function (above) will specifically avoid generating type DIEs for member
26035 : : types *within* the list of member DIEs for this (containing) type except
26036 : : for those types (of members) which are explicitly marked as also being
26037 : : members of this (containing) type themselves. The g++ front- end can
26038 : : force any given type to be treated as a member of some other (containing)
26039 : : type by setting the TYPE_CONTEXT of the given (member) type to point to
26040 : : the TREE node representing the appropriate (containing) type. */
26041 : :
26042 : : /* First output info about the base classes. */
26043 : 33603200 : if (binfo && early_dwarf)
26044 : : {
26045 : 32910504 : vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
26046 : 32910504 : int i;
26047 : 32910504 : tree base;
26048 : :
26049 : 50080249 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
26050 : 34339490 : gen_inheritance_die (base,
26051 : 17169745 : (accesses ? (*accesses)[i] : access_public_node),
26052 : : type,
26053 : : context_die);
26054 : : }
26055 : :
26056 : : /* Now output info about the members. */
26057 : 287919958 : for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
26058 : : {
26059 : : /* Ignore clones. */
26060 : 254316758 : if (DECL_ABSTRACT_ORIGIN (member))
26061 : 46222823 : continue;
26062 : :
26063 : 208093935 : struct vlr_context vlr_ctx = { type, NULL_TREE };
26064 : 208093935 : bool static_inline_p
26065 : 208093935 : = (VAR_P (member)
26066 : 8745330 : && TREE_STATIC (member)
26067 : 216839265 : && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
26068 : 208093935 : != -1));
26069 : :
26070 : : /* If we thought we were generating minimal debug info for TYPE
26071 : : and then changed our minds, some of the member declarations
26072 : : may have already been defined. Don't define them again, but
26073 : : do put them in the right order. */
26074 : :
26075 : 208093935 : if (dw_die_ref child = lookup_decl_die (member))
26076 : : {
26077 : : /* Handle inline static data members, which only have in-class
26078 : : declarations. */
26079 : 7364417 : bool splice = true;
26080 : :
26081 : 7364417 : dw_die_ref ref = NULL;
26082 : 7364417 : if (child->die_tag == DW_TAG_variable
26083 : 7364417 : && child->die_parent == comp_unit_die ())
26084 : : {
26085 : 6216871 : ref = get_AT_ref (child, DW_AT_specification);
26086 : :
26087 : : /* For C++17 inline static data members followed by redundant
26088 : : out of class redeclaration, we might get here with
26089 : : child being the DIE created for the out of class
26090 : : redeclaration and with its DW_AT_specification being
26091 : : the DIE created for in-class definition. We want to
26092 : : reparent the latter, and don't want to create another
26093 : : DIE with DW_AT_specification in that case, because
26094 : : we already have one. */
26095 : 6216871 : if (ref
26096 : 6216871 : && static_inline_p
26097 : 6 : && ref->die_tag == DW_TAG_variable
26098 : 6 : && ref->die_parent == comp_unit_die ()
26099 : 6216877 : && get_AT (ref, DW_AT_specification) == NULL)
26100 : : {
26101 : : child = ref;
26102 : : ref = NULL;
26103 : : static_inline_p = false;
26104 : : }
26105 : :
26106 : 6216865 : if (!ref)
26107 : : {
26108 : 6216418 : reparent_child (child, context_die);
26109 : 6216418 : if (dwarf_version < 5)
26110 : 14 : child->die_tag = DW_TAG_member;
26111 : : splice = false;
26112 : : }
26113 : : }
26114 : 1147546 : else if (child->die_tag == DW_TAG_enumerator)
26115 : : /* Enumerators remain under their enumeration even if
26116 : : their names are introduced in the enclosing scope. */
26117 : : splice = false;
26118 : :
26119 : : if (splice)
26120 : 4840 : splice_child_die (context_die, child);
26121 : : }
26122 : :
26123 : : /* Do not generate DWARF for variant parts if we are generating the
26124 : : corresponding GNAT encodings: DIEs generated for the two schemes
26125 : : would conflict in our mappings. */
26126 : 200729518 : else if (is_variant_part (member)
26127 : 200729518 : && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL)
26128 : : {
26129 : 0 : vlr_ctx.variant_part_offset = byte_position (member);
26130 : 0 : gen_variant_part (member, &vlr_ctx, context_die);
26131 : : }
26132 : : else
26133 : : {
26134 : 200729518 : vlr_ctx.variant_part_offset = NULL_TREE;
26135 : 200729518 : gen_decl_die (member, NULL, &vlr_ctx, context_die);
26136 : : }
26137 : :
26138 : : /* For C++ inline static data members emit immediately a DW_TAG_variable
26139 : : DIE that will refer to that DW_TAG_member/DW_TAG_variable through
26140 : : DW_AT_specification. */
26141 : 208093935 : if (static_inline_p)
26142 : : {
26143 : 7335308 : int old_extern = DECL_EXTERNAL (member);
26144 : 7335308 : DECL_EXTERNAL (member) = 0;
26145 : 7335308 : gen_decl_die (member, NULL, NULL, comp_unit_die ());
26146 : 7335308 : DECL_EXTERNAL (member) = old_extern;
26147 : : }
26148 : : }
26149 : 33603200 : }
26150 : :
26151 : : /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
26152 : : is set, we pretend that the type was never defined, so we only get the
26153 : : member DIEs needed by later specification DIEs. */
26154 : :
26155 : : static void
26156 : 95391159 : gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
26157 : : enum debug_info_usage usage)
26158 : : {
26159 : 95391159 : if (TREE_ASM_WRITTEN (type))
26160 : : {
26161 : : /* Fill in the bound of variable-length fields in late dwarf if
26162 : : still incomplete. */
26163 : 180 : if (!early_dwarf && variably_modified_type_p (type, NULL))
26164 : 86 : for (tree member = TYPE_FIELDS (type);
26165 : 209 : member;
26166 : 123 : member = DECL_CHAIN (member))
26167 : 123 : fill_variable_array_bounds (TREE_TYPE (member));
26168 : 180 : return;
26169 : : }
26170 : :
26171 : 95390979 : dw_die_ref type_die = lookup_type_die (type);
26172 : 95390979 : dw_die_ref scope_die = 0;
26173 : 95390979 : bool nested = false;
26174 : 95390979 : bool complete = (TYPE_SIZE (type)
26175 : 95390979 : && (! TYPE_STUB_DECL (type)
26176 : 65732848 : || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
26177 : 95390979 : bool ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
26178 : 95390979 : complete = complete && should_emit_struct_debug (type, usage);
26179 : :
26180 : 95390979 : if (type_die && ! complete)
26181 : : return;
26182 : :
26183 : 69357768 : if (TYPE_CONTEXT (type) != NULL_TREE
26184 : 69357768 : && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
26185 : 66011602 : || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
26186 : : nested = true;
26187 : :
26188 : 69357768 : scope_die = scope_die_for (type, context_die);
26189 : :
26190 : : /* Generate child dies for template parameters. */
26191 : 69357768 : if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
26192 : 36777328 : schedule_generic_params_dies_gen (type);
26193 : :
26194 : 32580437 : if (! type_die || (nested && is_cu_die (scope_die)))
26195 : : /* First occurrence of type or toplevel definition of nested class. */
26196 : : {
26197 : 36777331 : dw_die_ref old_die = type_die;
26198 : :
26199 : 73131585 : type_die = new_die (TREE_CODE (type) == RECORD_TYPE
26200 : 36354254 : ? record_type_tag (type) : DW_TAG_union_type,
26201 : : scope_die, type);
26202 : 36777331 : equate_type_number_to_die (type, type_die);
26203 : 36777331 : if (old_die)
26204 : 0 : add_AT_specification (type_die, old_die);
26205 : : else
26206 : 36777331 : add_name_attribute (type_die, type_tag (type));
26207 : : }
26208 : : else
26209 : 32580437 : remove_AT (type_die, DW_AT_declaration);
26210 : :
26211 : : /* If this type has been completed, then give it a byte_size attribute and
26212 : : then give a list of members. */
26213 : 69357768 : if (complete && !ns_decl)
26214 : : {
26215 : : /* Prevent infinite recursion in cases where the type of some member of
26216 : : this type is expressed in terms of this type itself. */
26217 : 33603200 : TREE_ASM_WRITTEN (type) = 1;
26218 : 33603200 : add_byte_size_attribute (type_die, type);
26219 : 33603200 : add_alignment_attribute (type_die, type);
26220 : 33603200 : if (TYPE_STUB_DECL (type) != NULL_TREE)
26221 : : {
26222 : 33398685 : add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
26223 : 33398685 : add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
26224 : : }
26225 : :
26226 : : /* If the first reference to this type was as the return type of an
26227 : : inline function, then it may not have a parent. Fix this now. */
26228 : 33603200 : if (type_die->die_parent == NULL)
26229 : 125814 : add_child_die (scope_die, type_die);
26230 : :
26231 : 33603200 : gen_member_die (type, type_die);
26232 : :
26233 : 33603200 : add_gnat_descriptive_type_attribute (type_die, type, context_die);
26234 : 33603200 : if (TYPE_ARTIFICIAL (type))
26235 : 1436 : add_AT_flag (type_die, DW_AT_artificial, 1);
26236 : :
26237 : : /* GNU extension: Record what type our vtable lives in. */
26238 : 33603200 : if (TYPE_VFIELD (type))
26239 : : {
26240 : 270894 : tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
26241 : :
26242 : 270894 : gen_type_die (vtype, context_die);
26243 : 270894 : add_AT_die_ref (type_die, DW_AT_containing_type,
26244 : : lookup_type_die (vtype));
26245 : : }
26246 : : }
26247 : : else
26248 : : {
26249 : 35754568 : add_AT_flag (type_die, DW_AT_declaration, 1);
26250 : :
26251 : : /* We don't need to do this for function-local types. */
26252 : 35754568 : if (TYPE_STUB_DECL (type)
26253 : 35754568 : && ! decl_function_context (TYPE_STUB_DECL (type)))
26254 : 35753840 : vec_safe_push (incomplete_types, type);
26255 : : }
26256 : :
26257 : 69357768 : if (get_AT (type_die, DW_AT_name))
26258 : 68052578 : add_pubtype (type, type_die);
26259 : : }
26260 : :
26261 : : /* Generate a DIE for a subroutine _type_. */
26262 : :
26263 : : static void
26264 : 416153 : gen_subroutine_type_die (tree type, dw_die_ref context_die)
26265 : : {
26266 : 416153 : tree return_type = TREE_TYPE (type);
26267 : 416153 : dw_die_ref subr_die
26268 : 416153 : = new_die (DW_TAG_subroutine_type,
26269 : : scope_die_for (type, context_die), type);
26270 : :
26271 : 416153 : equate_type_number_to_die (type, subr_die);
26272 : 416153 : add_prototyped_attribute (subr_die, type);
26273 : 416153 : add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, false,
26274 : : context_die);
26275 : 416153 : add_alignment_attribute (subr_die, type);
26276 : 416153 : gen_formal_types_die (type, subr_die);
26277 : :
26278 : 416153 : if (get_AT (subr_die, DW_AT_name))
26279 : 0 : add_pubtype (type, subr_die);
26280 : 775 : if ((dwarf_version >= 5 || !dwarf_strict)
26281 : 416922 : && lang_hooks.types.type_dwarf_attribute (type, DW_AT_reference) != -1)
26282 : 91 : add_AT_flag (subr_die, DW_AT_reference, 1);
26283 : 775 : if ((dwarf_version >= 5 || !dwarf_strict)
26284 : 416922 : && lang_hooks.types.type_dwarf_attribute (type,
26285 : : DW_AT_rvalue_reference) != -1)
26286 : 40 : add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
26287 : 416153 : }
26288 : :
26289 : : /* Generate a DIE for a type definition. */
26290 : :
26291 : : static void
26292 : 47170006 : gen_typedef_die (tree decl, dw_die_ref context_die)
26293 : : {
26294 : 47170006 : dw_die_ref type_die;
26295 : 47170006 : tree type;
26296 : :
26297 : 47170006 : if (TREE_ASM_WRITTEN (decl))
26298 : : {
26299 : 8645990 : if (DECL_ORIGINAL_TYPE (decl))
26300 : 8504077 : fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl));
26301 : 8645990 : return;
26302 : : }
26303 : :
26304 : : /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
26305 : : checks in process_scope_var and modified_type_die), this should be called
26306 : : only for original types. */
26307 : 38524016 : gcc_assert (decl_ultimate_origin (decl) == NULL
26308 : : || decl_ultimate_origin (decl) == decl);
26309 : :
26310 : 38524016 : TREE_ASM_WRITTEN (decl) = 1;
26311 : 38524016 : type_die = new_die (DW_TAG_typedef, context_die, decl);
26312 : :
26313 : 38524016 : add_name_and_src_coords_attributes (type_die, decl);
26314 : 38524016 : if (DECL_ORIGINAL_TYPE (decl))
26315 : : {
26316 : 38203155 : type = DECL_ORIGINAL_TYPE (decl);
26317 : 38203155 : if (type == error_mark_node)
26318 : : return;
26319 : :
26320 : 38203155 : gcc_assert (type != TREE_TYPE (decl));
26321 : 38203155 : equate_type_number_to_die (TREE_TYPE (decl), type_die);
26322 : : }
26323 : : else
26324 : : {
26325 : 320861 : type = TREE_TYPE (decl);
26326 : 320861 : if (type == error_mark_node)
26327 : : return;
26328 : :
26329 : 320861 : if (is_naming_typedef_decl (TYPE_NAME (type)))
26330 : : {
26331 : : /* Here, we are in the case of decl being a typedef naming
26332 : : an anonymous type, e.g:
26333 : : typedef struct {...} foo;
26334 : : In that case TREE_TYPE (decl) is not a typedef variant
26335 : : type and TYPE_NAME of the anonymous type is set to the
26336 : : TYPE_DECL of the typedef. This construct is emitted by
26337 : : the C++ FE.
26338 : :
26339 : : TYPE is the anonymous struct named by the typedef
26340 : : DECL. As we need the DW_AT_type attribute of the
26341 : : DW_TAG_typedef to point to the DIE of TYPE, let's
26342 : : generate that DIE right away. add_type_attribute
26343 : : called below will then pick (via lookup_type_die) that
26344 : : anonymous struct DIE. */
26345 : 320404 : if (!TREE_ASM_WRITTEN (type))
26346 : 40 : gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
26347 : :
26348 : : /* This is a GNU Extension. We are adding a
26349 : : DW_AT_linkage_name attribute to the DIE of the
26350 : : anonymous struct TYPE. The value of that attribute
26351 : : is the name of the typedef decl naming the anonymous
26352 : : struct. This greatly eases the work of consumers of
26353 : : this debug info. */
26354 : 320404 : add_linkage_name_raw (lookup_type_die (type), decl);
26355 : : }
26356 : : }
26357 : :
26358 : 38524016 : add_type_attribute (type_die, type, decl_quals (decl), false,
26359 : : context_die);
26360 : :
26361 : 38524016 : if (is_naming_typedef_decl (decl))
26362 : : /* We want that all subsequent calls to lookup_type_die with
26363 : : TYPE in argument yield the DW_TAG_typedef we have just
26364 : : created. */
26365 : 320404 : equate_type_number_to_die (type, type_die);
26366 : :
26367 : 38524016 : add_alignment_attribute (type_die, TREE_TYPE (decl));
26368 : :
26369 : 38524016 : add_accessibility_attribute (type_die, decl);
26370 : :
26371 : 38524016 : if (DECL_ABSTRACT_P (decl))
26372 : 6432 : equate_decl_number_to_die (decl, type_die);
26373 : :
26374 : 38524016 : if (get_AT (type_die, DW_AT_name))
26375 : 38524007 : add_pubtype (decl, type_die);
26376 : : }
26377 : :
26378 : : /* Generate a DIE for a struct, class, enum or union type. */
26379 : :
26380 : : static void
26381 : 97407160 : gen_tagged_type_die (tree type,
26382 : : dw_die_ref context_die,
26383 : : enum debug_info_usage usage,
26384 : : bool reverse)
26385 : : {
26386 : 97407160 : if (type == NULL_TREE
26387 : 97407160 : || !is_tagged_type (type))
26388 : : return;
26389 : :
26390 : 97407160 : if (TREE_ASM_WRITTEN (type))
26391 : : ;
26392 : : /* If this is a nested type whose containing class hasn't been written
26393 : : out yet, writing it out will cover this one, too. This does not apply
26394 : : to instantiations of member class templates; they need to be added to
26395 : : the containing class as they are generated. FIXME: This hurts the
26396 : : idea of combining type decls from multiple TUs, since we can't predict
26397 : : what set of template instantiations we'll get. */
26398 : 97406978 : else if (TYPE_CONTEXT (type)
26399 : 96532539 : && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
26400 : 101890665 : && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
26401 : : {
26402 : 1882866 : gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
26403 : :
26404 : 1882866 : if (TREE_ASM_WRITTEN (type))
26405 : : return;
26406 : :
26407 : : /* If that failed, attach ourselves to the stub. */
26408 : 1882866 : context_die = lookup_type_die (TYPE_CONTEXT (type));
26409 : : }
26410 : 95524112 : else if (TYPE_CONTEXT (type) != NULL_TREE
26411 : 95524112 : && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
26412 : : {
26413 : : /* If this type is local to a function that hasn't been written
26414 : : out yet, use a NULL context for now; it will be fixed up in
26415 : : decls_for_scope. */
26416 : 148476 : context_die = lookup_decl_die (TYPE_CONTEXT (type));
26417 : : /* A declaration DIE doesn't count; nested types need to go in the
26418 : : specification. */
26419 : 148476 : if (context_die && is_declaration_die (context_die))
26420 : : context_die = NULL;
26421 : : }
26422 : : else
26423 : 95375636 : context_die = declare_in_namespace (type, context_die);
26424 : :
26425 : 97407160 : if (TREE_CODE (type) == ENUMERAL_TYPE)
26426 : : {
26427 : : /* This might have been written out by the call to
26428 : : declare_in_namespace. */
26429 : 2016001 : if (!TREE_ASM_WRITTEN (type) || reverse)
26430 : 1622906 : gen_enumeration_type_die (type, context_die, reverse);
26431 : : }
26432 : : else
26433 : 95391159 : gen_struct_or_union_type_die (type, context_die, usage);
26434 : :
26435 : : /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
26436 : : it up if it is ever completed. gen_*_type_die will set it for us
26437 : : when appropriate. */
26438 : : }
26439 : :
26440 : : /* Generate a type description DIE. */
26441 : :
26442 : : static void
26443 : 704275534 : gen_type_die_with_usage (tree type, dw_die_ref context_die,
26444 : : enum debug_info_usage usage, bool reverse)
26445 : : {
26446 : 704275534 : struct array_descr_info info;
26447 : :
26448 : 704275534 : if (type == NULL_TREE || type == error_mark_node)
26449 : 679552386 : return;
26450 : :
26451 : 704275534 : if (flag_checking && type)
26452 : 704275511 : verify_type (type);
26453 : :
26454 : 704275534 : if (TYPE_NAME (type) != NULL_TREE
26455 : 578485197 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
26456 : 577873991 : && is_redundant_typedef (TYPE_NAME (type))
26457 : 1061752198 : && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
26458 : : /* The DECL of this type is a typedef we don't want to emit debug
26459 : : info for but we want debug info for its underlying typedef.
26460 : : This can happen for e.g, the injected-class-name of a C++
26461 : : type. */
26462 : 32944295 : type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
26463 : :
26464 : : /* If TYPE is a typedef type variant, let's generate debug info
26465 : : for the parent typedef which TYPE is a type of. */
26466 : 704275534 : if (typedef_variant_p (type))
26467 : : {
26468 : 72011212 : tree name = TYPE_NAME (type);
26469 : 72011212 : if (TREE_ASM_WRITTEN (name))
26470 : : return;
26471 : :
26472 : 10854817 : tree origin = decl_ultimate_origin (name);
26473 : 10854817 : if (origin != NULL && origin != name)
26474 : : {
26475 : 0 : gen_decl_die (origin, NULL, NULL, context_die);
26476 : 0 : return;
26477 : : }
26478 : :
26479 : : /* Prevent broken recursion; we can't hand off to the same type. */
26480 : 10854817 : gcc_assert (DECL_ORIGINAL_TYPE (name) != type);
26481 : :
26482 : : /* Give typedefs the right scope. */
26483 : 10854817 : context_die = scope_die_for (type, context_die);
26484 : :
26485 : 10854817 : gen_decl_die (name, NULL, NULL, context_die);
26486 : 10854817 : return;
26487 : : }
26488 : :
26489 : : /* If type is an anonymous tagged type named by a typedef, let's
26490 : : generate debug info for the typedef. */
26491 : 632264322 : if (is_naming_typedef_decl (TYPE_NAME (type)))
26492 : : {
26493 : : /* Give typedefs the right scope. */
26494 : 142260 : context_die = scope_die_for (type, context_die);
26495 : :
26496 : 142260 : gen_decl_die (TYPE_NAME (type), NULL, NULL, context_die);
26497 : 142260 : return;
26498 : : }
26499 : :
26500 : 632122062 : if (lang_hooks.types.get_debug_type)
26501 : : {
26502 : 626040630 : tree debug_type = lang_hooks.types.get_debug_type (type);
26503 : :
26504 : 626040630 : if (debug_type != NULL_TREE && debug_type != type)
26505 : : {
26506 : 14200 : gen_type_die_with_usage (debug_type, context_die, usage, reverse);
26507 : 14200 : return;
26508 : : }
26509 : : }
26510 : :
26511 : : /* We are going to output a DIE to represent the unqualified version
26512 : : of this type (i.e. without any const or volatile qualifiers) so
26513 : : get the main variant (i.e. the unqualified version) of this type
26514 : : now. (Vectors and arrays are special because the debugging info is in the
26515 : : cloned type itself. Similarly function/method types can contain extra
26516 : : ref-qualification). */
26517 : 632107862 : if (FUNC_OR_METHOD_TYPE_P (type))
26518 : : {
26519 : : /* For function/method types, can't use type_main_variant here,
26520 : : because that can have different ref-qualifiers for C++,
26521 : : but try to canonicalize. */
26522 : 472128 : tree main = TYPE_MAIN_VARIANT (type);
26523 : 483970 : for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
26524 : 483958 : if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
26525 : 483793 : && check_base_type (t, main)
26526 : 964100 : && check_lang_type (t, type))
26527 : : {
26528 : : type = t;
26529 : : break;
26530 : : }
26531 : : }
26532 : 631635734 : else if (TREE_CODE (type) != VECTOR_TYPE
26533 : 631635734 : && TREE_CODE (type) != ARRAY_TYPE)
26534 : 630175665 : type = type_main_variant (type);
26535 : :
26536 : : /* If this is an array type with hidden descriptor, handle it first. */
26537 : 632107862 : if (!TREE_ASM_WRITTEN (type)
26538 : 122132409 : && lang_hooks.types.get_array_descr_info)
26539 : : {
26540 : 85979 : memset (&info, 0, sizeof (info));
26541 : 85979 : if (lang_hooks.types.get_array_descr_info (type, &info))
26542 : : {
26543 : : /* Fortran sometimes emits array types with no dimension. */
26544 : 6692 : gcc_assert (info.ndimensions >= 0
26545 : : && (info.ndimensions
26546 : : <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN));
26547 : 6692 : gen_descr_array_type_die (type, &info, context_die);
26548 : 6692 : TREE_ASM_WRITTEN (type) = 1;
26549 : 6692 : return;
26550 : : }
26551 : : }
26552 : :
26553 : 632101170 : if (TREE_ASM_WRITTEN (type) && !reverse)
26554 : : {
26555 : : /* Variable-length types may be incomplete even if
26556 : : TREE_ASM_WRITTEN. For such types, fall through to
26557 : : gen_array_type_die() and possibly fill in
26558 : : DW_AT_{upper,lower}_bound attributes. */
26559 : 509975451 : if ((TREE_CODE (type) != ARRAY_TYPE
26560 : : && TREE_CODE (type) != RECORD_TYPE
26561 : : && TREE_CODE (type) != UNION_TYPE
26562 : 509975451 : && TREE_CODE (type) != QUAL_UNION_TYPE)
26563 : 509975451 : || !variably_modified_type_p (type, NULL))
26564 : 509970902 : return;
26565 : : }
26566 : :
26567 : 122130268 : switch (TREE_CODE (type))
26568 : : {
26569 : : case ERROR_MARK:
26570 : : break;
26571 : :
26572 : 22776064 : case POINTER_TYPE:
26573 : 22776064 : case REFERENCE_TYPE:
26574 : : /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
26575 : : ensures that the gen_type_die recursion will terminate even if the
26576 : : type is recursive. Recursive types are possible in Ada. */
26577 : : /* ??? We could perhaps do this for all types before the switch
26578 : : statement. */
26579 : 22776064 : TREE_ASM_WRITTEN (type) = 1;
26580 : :
26581 : : /* For these types, all that is required is that we output a DIE (or a
26582 : : set of DIEs) to represent the "basis" type. */
26583 : 22776064 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26584 : : DINFO_USAGE_IND_USE);
26585 : 22776064 : break;
26586 : :
26587 : 31939 : case OFFSET_TYPE:
26588 : : /* This code is used for C++ pointer-to-data-member types.
26589 : : Output a description of the relevant class type. */
26590 : 31939 : gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
26591 : : DINFO_USAGE_IND_USE);
26592 : :
26593 : : /* Output a description of the type of the object pointed to. */
26594 : 31939 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26595 : : DINFO_USAGE_IND_USE);
26596 : :
26597 : : /* Now output a DIE to represent this pointer-to-data-member type
26598 : : itself. */
26599 : 31939 : gen_ptr_to_mbr_type_die (type, context_die);
26600 : 31939 : break;
26601 : :
26602 : 384720 : case FUNCTION_TYPE:
26603 : : /* Force out return type (in case it wasn't forced out already). */
26604 : 384720 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26605 : : DINFO_USAGE_DIR_USE);
26606 : 384720 : gen_subroutine_type_die (type, context_die);
26607 : 384720 : break;
26608 : :
26609 : 31433 : case METHOD_TYPE:
26610 : : /* Force out return type (in case it wasn't forced out already). */
26611 : 31433 : gen_type_die_with_usage (TREE_TYPE (type), context_die,
26612 : : DINFO_USAGE_DIR_USE);
26613 : 31433 : gen_subroutine_type_die (type, context_die);
26614 : 31433 : break;
26615 : :
26616 : 922255 : case ARRAY_TYPE:
26617 : 922255 : case VECTOR_TYPE:
26618 : 922255 : gen_array_type_die (type, context_die);
26619 : 922255 : break;
26620 : :
26621 : 97407120 : case ENUMERAL_TYPE:
26622 : 97407120 : case RECORD_TYPE:
26623 : 97407120 : case UNION_TYPE:
26624 : 97407120 : case QUAL_UNION_TYPE:
26625 : 97407120 : gen_tagged_type_die (type, context_die, usage, reverse);
26626 : 97407120 : return;
26627 : :
26628 : : case VOID_TYPE:
26629 : : case OPAQUE_TYPE:
26630 : : case INTEGER_TYPE:
26631 : : case REAL_TYPE:
26632 : : case FIXED_POINT_TYPE:
26633 : : case COMPLEX_TYPE:
26634 : : case BOOLEAN_TYPE:
26635 : : case BITINT_TYPE:
26636 : : /* No DIEs needed for fundamental types. */
26637 : : break;
26638 : :
26639 : 14819 : case NULLPTR_TYPE:
26640 : 14819 : case LANG_TYPE:
26641 : : /* Just use DW_TAG_unspecified_type. */
26642 : 14819 : {
26643 : 14819 : dw_die_ref type_die = lookup_type_die (type);
26644 : 14819 : if (type_die == NULL)
26645 : : {
26646 : 14819 : tree name = TYPE_IDENTIFIER (type);
26647 : 14819 : type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
26648 : : type);
26649 : 14819 : add_name_attribute (type_die, IDENTIFIER_POINTER (name));
26650 : 14819 : equate_type_number_to_die (type, type_die);
26651 : : }
26652 : : }
26653 : : break;
26654 : :
26655 : 49196 : default:
26656 : 49196 : if (is_cxx_auto (type))
26657 : : {
26658 : 49196 : tree name = TYPE_IDENTIFIER (type);
26659 : 49196 : dw_die_ref *die = (name == get_identifier ("auto")
26660 : 49196 : ? &auto_die : &decltype_auto_die);
26661 : 49196 : if (!*die)
26662 : : {
26663 : 4838 : *die = new_die (DW_TAG_unspecified_type,
26664 : : comp_unit_die (), NULL_TREE);
26665 : 4838 : add_name_attribute (*die, IDENTIFIER_POINTER (name));
26666 : : }
26667 : 49196 : equate_type_number_to_die (type, *die);
26668 : 49196 : break;
26669 : : }
26670 : 0 : gcc_unreachable ();
26671 : : }
26672 : :
26673 : 24723148 : TREE_ASM_WRITTEN (type) = 1;
26674 : : }
26675 : :
26676 : : static void
26677 : 679122373 : gen_type_die (tree type, dw_die_ref context_die, bool reverse)
26678 : : {
26679 : 679122373 : if (type != error_mark_node)
26680 : : {
26681 : 679122373 : gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE, reverse);
26682 : 679122373 : if (flag_checking)
26683 : : {
26684 : 679122350 : dw_die_ref die = lookup_type_die (type);
26685 : 679122350 : if (die)
26686 : 534909200 : check_die (die);
26687 : : }
26688 : : }
26689 : 679122373 : }
26690 : :
26691 : : /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
26692 : : things which are local to the given block. */
26693 : :
26694 : : static void
26695 : 23863436 : gen_block_die (tree stmt, dw_die_ref context_die)
26696 : : {
26697 : 23863436 : int must_output_die = 0;
26698 : 23863436 : bool inlined_func;
26699 : :
26700 : : /* Ignore blocks that are NULL. */
26701 : 23863436 : if (stmt == NULL_TREE)
26702 : : return;
26703 : :
26704 : 23863436 : inlined_func = inlined_function_outer_scope_p (stmt);
26705 : :
26706 : : /* If the block is one fragment of a non-contiguous block, do not
26707 : : process the variables, since they will have been done by the
26708 : : origin block. Do process subblocks. */
26709 : 23863436 : if (BLOCK_FRAGMENT_ORIGIN (stmt))
26710 : : {
26711 : 10893729 : tree sub;
26712 : :
26713 : 10893729 : for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
26714 : 0 : gen_block_die (sub, context_die);
26715 : :
26716 : : return;
26717 : : }
26718 : :
26719 : : /* Determine if we need to output any Dwarf DIEs at all to represent this
26720 : : block. */
26721 : 12969707 : if (inlined_func)
26722 : : /* The outer scopes for inlinings *must* always be represented. We
26723 : : generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
26724 : : must_output_die = 1;
26725 : 6061824 : else if (lookup_block_die (stmt))
26726 : : /* If we already have a DIE then it was filled early. Meanwhile
26727 : : we might have pruned all BLOCK_VARS as optimized out but we
26728 : : still want to generate high/low PC attributes so output it. */
26729 : : must_output_die = 1;
26730 : 5792186 : else if (TREE_USED (stmt)
26731 : 8587 : || TREE_ASM_WRITTEN (stmt))
26732 : : {
26733 : : /* Determine if this block directly contains any "significant"
26734 : : local declarations which we will need to output DIEs for. */
26735 : 5790329 : if (debug_info_level > DINFO_LEVEL_TERSE)
26736 : : {
26737 : : /* We are not in terse mode so any local declaration that
26738 : : is not ignored for debug purposes counts as being a
26739 : : "significant" one. */
26740 : 5705081 : if (BLOCK_NUM_NONLOCALIZED_VARS (stmt))
26741 : : must_output_die = 1;
26742 : : else
26743 : 5935630 : for (tree var = BLOCK_VARS (stmt); var; var = DECL_CHAIN (var))
26744 : 1018722 : if (!DECL_IGNORED_P (var))
26745 : : {
26746 : : must_output_die = 1;
26747 : : break;
26748 : : }
26749 : : }
26750 : 85248 : else if (!dwarf2out_ignore_block (stmt))
26751 : : must_output_die = 1;
26752 : : }
26753 : :
26754 : : /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
26755 : : DIE for any block which contains no significant local declarations at
26756 : : all. Rather, in such cases we just call `decls_for_scope' so that any
26757 : : needed Dwarf info for any sub-blocks will get properly generated. Note
26758 : : that in terse mode, our definition of what constitutes a "significant"
26759 : : local declaration gets restricted to include only inlined function
26760 : : instances and local (nested) function definitions. */
26761 : 5699321 : if (must_output_die)
26762 : : {
26763 : 7965747 : if (inlined_func)
26764 : 6907883 : gen_inlined_subroutine_die (stmt, context_die);
26765 : : else
26766 : 1057864 : gen_lexical_block_die (stmt, context_die);
26767 : : }
26768 : : else
26769 : 5003960 : decls_for_scope (stmt, context_die);
26770 : : }
26771 : :
26772 : : /* Process variable DECL (or variable with origin ORIGIN) within
26773 : : block STMT and add it to CONTEXT_DIE. */
26774 : : static void
26775 : 18401456 : process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
26776 : : {
26777 : 18401456 : dw_die_ref die;
26778 : 18401456 : tree decl_or_origin = decl ? decl : origin;
26779 : :
26780 : 18401456 : if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
26781 : 16230 : die = lookup_decl_die (decl_or_origin);
26782 : 18385226 : else if (TREE_CODE (decl_or_origin) == TYPE_DECL)
26783 : : {
26784 : 958675 : if (TYPE_DECL_IS_STUB (decl_or_origin))
26785 : 120699 : die = lookup_type_die (TREE_TYPE (decl_or_origin));
26786 : : else
26787 : 837976 : die = lookup_decl_die (decl_or_origin);
26788 : : /* Avoid re-creating the DIE late if it was optimized as unused early. */
26789 : 958675 : if (! die && ! early_dwarf)
26790 : : return;
26791 : : }
26792 : : else
26793 : : die = NULL;
26794 : :
26795 : : /* Avoid creating DIEs for local typedefs and concrete static variables that
26796 : : will only be pruned later. */
26797 : 17672503 : if ((origin || decl_ultimate_origin (decl))
26798 : 31424766 : && (TREE_CODE (decl_or_origin) == TYPE_DECL
26799 : 13703792 : || (VAR_P (decl_or_origin) && TREE_STATIC (decl_or_origin))))
26800 : : {
26801 : 108579 : origin = decl_ultimate_origin (decl_or_origin);
26802 : 108579 : if (decl && VAR_P (decl) && die != NULL)
26803 : : {
26804 : 0 : die = lookup_decl_die (origin);
26805 : 0 : if (die != NULL)
26806 : 0 : equate_decl_number_to_die (decl, die);
26807 : : }
26808 : 108579 : return;
26809 : : }
26810 : :
26811 : 17621954 : if (die != NULL && die->die_parent == NULL)
26812 : 7991 : add_child_die (context_die, die);
26813 : :
26814 : 17621954 : if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
26815 : : {
26816 : 26185 : if (early_dwarf)
26817 : 12618 : dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
26818 : : stmt, context_die);
26819 : : }
26820 : : else
26821 : : {
26822 : 17595769 : if (decl && DECL_P (decl))
26823 : : {
26824 : 17595754 : die = lookup_decl_die (decl);
26825 : :
26826 : : /* Early created DIEs do not have a parent as the decls refer
26827 : : to the function as DECL_CONTEXT rather than the BLOCK. */
26828 : 17595754 : if (die && die->die_parent == NULL)
26829 : : {
26830 : 2785 : gcc_assert (in_lto_p);
26831 : 2785 : add_child_die (context_die, die);
26832 : : }
26833 : : }
26834 : :
26835 : 17595769 : gen_decl_die (decl, origin, NULL, context_die);
26836 : : }
26837 : : }
26838 : :
26839 : : /* Generate all of the decls declared within a given scope and (recursively)
26840 : : all of its sub-blocks. */
26841 : :
26842 : : static void
26843 : 19009220 : decls_for_scope (tree stmt, dw_die_ref context_die, bool recurse)
26844 : : {
26845 : 19009220 : tree decl;
26846 : 19009220 : unsigned int i;
26847 : 19009220 : tree subblocks;
26848 : :
26849 : : /* Ignore NULL blocks. */
26850 : 19009220 : if (stmt == NULL_TREE)
26851 : : return;
26852 : :
26853 : : /* Output the DIEs to represent all of the data objects and typedefs
26854 : : declared directly within this block but not within any nested
26855 : : sub-blocks. Also, nested function and tag DIEs have been
26856 : : generated with a parent of NULL; fix that up now. We don't
26857 : : have to do this if we're at -g1. */
26858 : 19009220 : if (debug_info_level > DINFO_LEVEL_TERSE)
26859 : : {
26860 : 37236708 : for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
26861 : 18339874 : process_scope_var (stmt, decl, NULL_TREE, context_die);
26862 : : /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
26863 : : origin - avoid doing this twice as we have no good way to see
26864 : : if we've done it once already. */
26865 : 18896834 : if (! early_dwarf)
26866 : 13394689 : for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
26867 : : {
26868 : 61586 : decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
26869 : 61586 : if (decl == current_function_decl)
26870 : : /* Ignore declarations of the current function, while they
26871 : : are declarations, gen_subprogram_die would treat them
26872 : : as definitions again, because they are equal to
26873 : : current_function_decl and endlessly recurse. */;
26874 : 61582 : else if (TREE_CODE (decl) == FUNCTION_DECL)
26875 : 3552 : process_scope_var (stmt, decl, NULL_TREE, context_die);
26876 : : else
26877 : 58030 : process_scope_var (stmt, NULL_TREE, decl, context_die);
26878 : : }
26879 : : }
26880 : :
26881 : : /* Even if we're at -g1, we need to process the subblocks in order to get
26882 : : inlined call information. */
26883 : :
26884 : : /* Output the DIEs to represent all sub-blocks (and the items declared
26885 : : therein) of this block. */
26886 : 19009220 : if (recurse)
26887 : 36450088 : for (subblocks = BLOCK_SUBBLOCKS (stmt);
26888 : 36450088 : subblocks != NULL;
26889 : 20727158 : subblocks = BLOCK_CHAIN (subblocks))
26890 : 20727158 : gen_block_die (subblocks, context_die);
26891 : : }
26892 : :
26893 : : /* Is this a typedef we can avoid emitting? */
26894 : :
26895 : : static bool
26896 : 1068921718 : is_redundant_typedef (const_tree decl)
26897 : : {
26898 : 1068921718 : if (TYPE_DECL_IS_STUB (decl))
26899 : : return true;
26900 : :
26901 : 350652575 : if (DECL_ARTIFICIAL (decl)
26902 : 211555308 : && DECL_CONTEXT (decl)
26903 : 66039200 : && is_tagged_type (DECL_CONTEXT (decl))
26904 : 65841059 : && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
26905 : 416493634 : && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
26906 : : /* Also ignore the artificial member typedef for the class name. */
26907 : 65841041 : return true;
26908 : :
26909 : : return false;
26910 : : }
26911 : :
26912 : : /* Return TRUE if TYPE is a typedef that names a type for linkage
26913 : : purposes. This kind of typedefs is produced by the C++ FE for
26914 : : constructs like:
26915 : :
26916 : : typedef struct {...} foo;
26917 : :
26918 : : In that case, there is no typedef variant type produced for foo.
26919 : : Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
26920 : : struct type. */
26921 : :
26922 : : static bool
26923 : 671109211 : is_naming_typedef_decl (const_tree decl)
26924 : : {
26925 : 671109211 : if (decl == NULL_TREE
26926 : 545304964 : || TREE_CODE (decl) != TYPE_DECL
26927 : 544693678 : || DECL_NAMELESS (decl)
26928 : 544692229 : || !is_tagged_type (TREE_TYPE (decl))
26929 : 374391033 : || DECL_IS_UNDECLARED_BUILTIN (decl)
26930 : 374338526 : || is_redundant_typedef (decl)
26931 : : /* It looks like Ada produces TYPE_DECLs that are very similar
26932 : : to C++ naming typedefs but that have different
26933 : : semantics. Let's be specific to c++ for now. */
26934 : 688353412 : || !is_cxx (decl))
26935 : 654324007 : return false;
26936 : :
26937 : 16785204 : return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
26938 : 783086 : && TYPE_NAME (TREE_TYPE (decl)) == decl
26939 : 17568284 : && (TYPE_STUB_DECL (TREE_TYPE (decl))
26940 : 783080 : != TYPE_NAME (TREE_TYPE (decl))));
26941 : : }
26942 : :
26943 : : /* Looks up the DIE for a context. */
26944 : :
26945 : : static inline dw_die_ref
26946 : 293971 : lookup_context_die (tree context)
26947 : : {
26948 : 293971 : if (context)
26949 : : {
26950 : : /* Find die that represents this context. */
26951 : 69810 : if (TYPE_P (context))
26952 : : {
26953 : 13 : context = TYPE_MAIN_VARIANT (context);
26954 : 13 : dw_die_ref ctx = lookup_type_die (context);
26955 : 13 : if (!ctx)
26956 : : return NULL;
26957 : 12 : return strip_naming_typedef (context, ctx);
26958 : : }
26959 : : else
26960 : 69797 : return lookup_decl_die (context);
26961 : : }
26962 : 224161 : return comp_unit_die ();
26963 : : }
26964 : :
26965 : : /* Returns the DIE for a context. */
26966 : :
26967 : : static inline dw_die_ref
26968 : 63559629 : get_context_die (tree context)
26969 : : {
26970 : 63559629 : if (context)
26971 : : {
26972 : : /* Find die that represents this context. */
26973 : 63355174 : if (TYPE_P (context))
26974 : : {
26975 : 17868667 : context = TYPE_MAIN_VARIANT (context);
26976 : 17868667 : return strip_naming_typedef (context, force_type_die (context));
26977 : : }
26978 : : else
26979 : 45486507 : return force_decl_die (context);
26980 : : }
26981 : 204455 : return comp_unit_die ();
26982 : : }
26983 : :
26984 : : /* Returns the DIE for decl. A DIE will always be returned. */
26985 : :
26986 : : static dw_die_ref
26987 : 151039553 : force_decl_die (tree decl)
26988 : : {
26989 : 151039553 : dw_die_ref decl_die;
26990 : 151039553 : unsigned saved_external_flag;
26991 : 151039553 : tree save_fn = NULL_TREE;
26992 : 151039553 : decl_die = lookup_decl_die (decl);
26993 : 151039553 : if (!decl_die)
26994 : : {
26995 : 2579521 : dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
26996 : :
26997 : 2579521 : decl_die = lookup_decl_die (decl);
26998 : 2579521 : if (decl_die)
26999 : : return decl_die;
27000 : :
27001 : 2579521 : switch (TREE_CODE (decl))
27002 : : {
27003 : 2224170 : case FUNCTION_DECL:
27004 : : /* Clear current_function_decl, so that gen_subprogram_die thinks
27005 : : that this is a declaration. At this point, we just want to force
27006 : : declaration die. */
27007 : 2224170 : save_fn = current_function_decl;
27008 : 2224170 : current_function_decl = NULL_TREE;
27009 : 2224170 : gen_subprogram_die (decl, context_die);
27010 : 2224170 : current_function_decl = save_fn;
27011 : 2224170 : break;
27012 : :
27013 : 263 : case VAR_DECL:
27014 : : /* Set external flag to force declaration die. Restore it after
27015 : : gen_decl_die() call. */
27016 : 263 : saved_external_flag = DECL_EXTERNAL (decl);
27017 : 263 : DECL_EXTERNAL (decl) = 1;
27018 : 263 : gen_decl_die (decl, NULL, NULL, context_die);
27019 : 263 : DECL_EXTERNAL (decl) = saved_external_flag;
27020 : 263 : break;
27021 : :
27022 : 355082 : case NAMESPACE_DECL:
27023 : 355082 : if (dwarf_version >= 3 || !dwarf_strict)
27024 : 355082 : dwarf2out_decl (decl);
27025 : : else
27026 : : /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
27027 : 0 : decl_die = comp_unit_die ();
27028 : : break;
27029 : :
27030 : 0 : case CONST_DECL:
27031 : : /* Enumerators shouldn't need force_decl_die. */
27032 : 0 : gcc_assert (DECL_CONTEXT (decl) == NULL_TREE
27033 : : || TREE_CODE (DECL_CONTEXT (decl)) != ENUMERAL_TYPE);
27034 : 0 : gen_decl_die (decl, NULL, NULL, context_die);
27035 : 0 : break;
27036 : :
27037 : 6 : case TRANSLATION_UNIT_DECL:
27038 : 6 : decl_die = comp_unit_die ();
27039 : 6 : break;
27040 : :
27041 : 0 : default:
27042 : 0 : gcc_unreachable ();
27043 : : }
27044 : :
27045 : : /* We should be able to find the DIE now. */
27046 : 2579521 : if (!decl_die)
27047 : 2579515 : decl_die = lookup_decl_die (decl);
27048 : 2579515 : gcc_assert (decl_die);
27049 : : }
27050 : :
27051 : : return decl_die;
27052 : : }
27053 : :
27054 : : /* Returns the DIE for TYPE, that must not be a base type. A DIE is
27055 : : always returned. */
27056 : :
27057 : : static dw_die_ref
27058 : 18529731 : force_type_die (tree type)
27059 : : {
27060 : 18529731 : dw_die_ref type_die;
27061 : :
27062 : 18529731 : type_die = lookup_type_die (type);
27063 : 18529731 : if (!type_die)
27064 : : {
27065 : 381066 : dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
27066 : :
27067 : 381066 : type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
27068 : : false, context_die);
27069 : 381066 : gcc_assert (type_die);
27070 : : }
27071 : 18529731 : return type_die;
27072 : : }
27073 : :
27074 : : /* Force out any required namespaces to be able to output DECL,
27075 : : and return the new context_die for it, if it's changed. */
27076 : :
27077 : : static dw_die_ref
27078 : 204546721 : setup_namespace_context (tree thing, dw_die_ref context_die)
27079 : : {
27080 : 204546721 : tree context = (DECL_P (thing)
27081 : 204546721 : ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
27082 : 204546721 : if (context && TREE_CODE (context) == NAMESPACE_DECL)
27083 : : /* Force out the namespace. */
27084 : 103303976 : context_die = force_decl_die (context);
27085 : :
27086 : 204546721 : return context_die;
27087 : : }
27088 : :
27089 : : /* Emit a declaration DIE for THING (which is either a DECL or a tagged
27090 : : type) within its namespace, if appropriate.
27091 : :
27092 : : For compatibility with older debuggers, namespace DIEs only contain
27093 : : declarations; all definitions are emitted at CU scope, with
27094 : : DW_AT_specification pointing to the declaration (like with class
27095 : : members). */
27096 : :
27097 : : static dw_die_ref
27098 : 204249089 : declare_in_namespace (tree thing, dw_die_ref context_die)
27099 : : {
27100 : 204249089 : dw_die_ref ns_context;
27101 : :
27102 : 204249089 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27103 : : return context_die;
27104 : :
27105 : : /* External declarations in the local scope only need to be emitted
27106 : : once, not once in the namespace and once in the scope.
27107 : :
27108 : : This avoids declaring the `extern' below in the
27109 : : namespace DIE as well as in the innermost scope:
27110 : :
27111 : : namespace S
27112 : : {
27113 : : int i=5;
27114 : : int foo()
27115 : : {
27116 : : int i=8;
27117 : : extern int i;
27118 : : return i;
27119 : : }
27120 : : }
27121 : : */
27122 : 281900474 : if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
27123 : : return context_die;
27124 : :
27125 : : /* If this decl is from an inlined function, then don't try to emit it in its
27126 : : namespace, as we will get confused. It would have already been emitted
27127 : : when the abstract instance of the inline function was emitted anyways. */
27128 : 204207664 : if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
27129 : : return context_die;
27130 : :
27131 : 204187432 : ns_context = setup_namespace_context (thing, context_die);
27132 : :
27133 : 204187432 : if (ns_context != context_die)
27134 : : {
27135 : 51335374 : if (is_fortran () || is_dlang ())
27136 : 13021 : return ns_context;
27137 : 51322353 : if (DECL_P (thing))
27138 : 6306974 : gen_decl_die (thing, NULL, NULL, ns_context);
27139 : : else
27140 : 45015379 : gen_type_die (thing, ns_context);
27141 : : }
27142 : : return context_die;
27143 : : }
27144 : :
27145 : : /* Generate a DIE for a namespace or namespace alias. */
27146 : :
27147 : : static void
27148 : 359330 : gen_namespace_die (tree decl, dw_die_ref context_die)
27149 : : {
27150 : 359330 : dw_die_ref namespace_die;
27151 : :
27152 : : /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
27153 : : they are an alias of. */
27154 : 359330 : if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
27155 : : {
27156 : : /* Output a real namespace or module. */
27157 : 355082 : context_die = setup_namespace_context (decl, comp_unit_die ());
27158 : 356595 : namespace_die = new_die (is_fortran () || is_dlang () || is_ada ()
27159 : : ? DW_TAG_module : DW_TAG_namespace,
27160 : : context_die, decl);
27161 : : /* For Fortran modules defined in different CU don't add src coords. */
27162 : 355082 : if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
27163 : : {
27164 : 179 : const char *name = dwarf2_name (decl, 0);
27165 : 179 : if (name)
27166 : 179 : add_name_attribute (namespace_die, name);
27167 : : }
27168 : : else
27169 : 354903 : add_name_and_src_coords_attributes (namespace_die, decl);
27170 : 355082 : if (DECL_EXTERNAL (decl))
27171 : 179 : add_AT_flag (namespace_die, DW_AT_declaration, 1);
27172 : 355082 : equate_decl_number_to_die (decl, namespace_die);
27173 : : }
27174 : : else
27175 : : {
27176 : : /* Output a namespace alias. */
27177 : :
27178 : : /* Force out the namespace we are an alias of, if necessary. */
27179 : 4248 : dw_die_ref origin_die
27180 : 4248 : = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
27181 : :
27182 : 8496 : if (DECL_FILE_SCOPE_P (decl)
27183 : 6617 : || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
27184 : 4207 : context_die = setup_namespace_context (decl, comp_unit_die ());
27185 : : /* Now create the namespace alias DIE. */
27186 : 4248 : namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
27187 : 4248 : add_name_and_src_coords_attributes (namespace_die, decl);
27188 : 4248 : add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
27189 : 4248 : equate_decl_number_to_die (decl, namespace_die);
27190 : : }
27191 : 313 : if ((dwarf_version >= 5 || !dwarf_strict)
27192 : 359643 : && lang_hooks.decls.decl_dwarf_attribute (decl,
27193 : : DW_AT_export_symbols) == 1)
27194 : 81211 : add_AT_flag (namespace_die, DW_AT_export_symbols, 1);
27195 : :
27196 : : /* Bypass dwarf2_name's check for DECL_NAMELESS. */
27197 : 359330 : if (want_pubnames ())
27198 : 33 : add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
27199 : 359330 : }
27200 : :
27201 : : /* Generate Dwarf debug information for a decl described by DECL.
27202 : : The return value is currently only meaningful for PARM_DECLs,
27203 : : for all other decls it returns NULL.
27204 : :
27205 : : If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
27206 : : It can be NULL otherwise. */
27207 : :
27208 : : static dw_die_ref
27209 : 307452179 : gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
27210 : : dw_die_ref context_die)
27211 : : {
27212 : 307452179 : tree decl_or_origin = decl ? decl : origin;
27213 : 307452179 : tree class_origin = NULL, ultimate_origin;
27214 : :
27215 : 307452179 : if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
27216 : : return NULL;
27217 : :
27218 : 261301031 : switch (TREE_CODE (decl_or_origin))
27219 : : {
27220 : : case ERROR_MARK:
27221 : : break;
27222 : :
27223 : 356391 : case CONST_DECL:
27224 : 356391 : if (!is_fortran () && !is_ada () && !is_dlang ())
27225 : : {
27226 : : /* The individual enumerators of an enum type get output when we output
27227 : : the Dwarf representation of the relevant enum type itself. */
27228 : : break;
27229 : : }
27230 : :
27231 : : /* Emit its type. */
27232 : 25615 : gen_type_die (TREE_TYPE (decl), context_die);
27233 : :
27234 : : /* And its containing namespace. */
27235 : 25615 : context_die = declare_in_namespace (decl, context_die);
27236 : :
27237 : 25615 : gen_const_die (decl, context_die);
27238 : 25615 : break;
27239 : :
27240 : 78096259 : case FUNCTION_DECL:
27241 : : #if 0
27242 : : /* FIXME */
27243 : : /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
27244 : : on local redeclarations of global functions. That seems broken. */
27245 : : if (current_function_decl != decl)
27246 : : /* This is only a declaration. */;
27247 : : #endif
27248 : :
27249 : : /* We should have abstract copies already and should not generate
27250 : : stray type DIEs in late LTO dumping. */
27251 : 78096259 : if (! early_dwarf)
27252 : : ;
27253 : :
27254 : : /* If we're emitting a clone, emit info for the abstract instance. */
27255 : 77892328 : else if (origin || DECL_ORIGIN (decl) != decl)
27256 : 717676 : dwarf2out_abstract_function (origin
27257 : 0 : ? DECL_ORIGIN (origin)
27258 : 358838 : : DECL_ABSTRACT_ORIGIN (decl));
27259 : :
27260 : : /* If we're emitting a possibly inlined function emit it as
27261 : : abstract instance. */
27262 : 77171382 : else if (cgraph_function_possibly_inlined_p (decl)
27263 : 74576999 : && ! DECL_ABSTRACT_P (decl)
27264 : 59119166 : && ! class_or_namespace_scope_p (context_die)
27265 : : /* dwarf2out_abstract_function won't emit a die if this is just
27266 : : a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
27267 : : that case, because that works only if we have a die. */
27268 : 77171382 : && DECL_INITIAL (decl) != NULL_TREE)
27269 : 0 : dwarf2out_abstract_function (decl);
27270 : :
27271 : : /* Otherwise we're emitting the primary DIE for this decl. */
27272 : 77171382 : else if (debug_info_level > DINFO_LEVEL_TERSE)
27273 : : {
27274 : : /* Before we describe the FUNCTION_DECL itself, make sure that we
27275 : : have its containing type. */
27276 : 77157679 : if (!origin)
27277 : 77157679 : origin = decl_class_context (decl);
27278 : 77157679 : if (origin != NULL_TREE)
27279 : 75947838 : gen_type_die (origin, context_die);
27280 : :
27281 : : /* And its return type. */
27282 : 77157679 : gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
27283 : :
27284 : : /* And its virtual context. */
27285 : 77157679 : if (DECL_VINDEX (decl) != NULL_TREE)
27286 : 896740 : gen_type_die (DECL_CONTEXT (decl), context_die);
27287 : :
27288 : : /* Make sure we have a member DIE for decl. */
27289 : 77157679 : if (origin != NULL_TREE)
27290 : 75947838 : gen_type_die_for_member (origin, decl, context_die);
27291 : :
27292 : : /* And its containing namespace. */
27293 : 77157679 : context_die = declare_in_namespace (decl, context_die);
27294 : : }
27295 : :
27296 : : /* Now output a DIE to represent the function itself. */
27297 : 78096259 : if (decl)
27298 : 78096259 : gen_subprogram_die (decl, context_die);
27299 : : break;
27300 : :
27301 : 116709201 : case TYPE_DECL:
27302 : : /* If we are in terse mode, don't generate any DIEs to represent any
27303 : : actual typedefs. */
27304 : 116709201 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27305 : : break;
27306 : :
27307 : : /* In the special case of a TYPE_DECL node representing the declaration
27308 : : of some type tag, if the given TYPE_DECL is marked as having been
27309 : : instantiated from some other (original) TYPE_DECL node (e.g. one which
27310 : : was generated within the original definition of an inline function) we
27311 : : used to generate a special (abbreviated) DW_TAG_structure_type,
27312 : : DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
27313 : : should be actually referencing those DIEs, as variable DIEs with that
27314 : : type would be emitted already in the abstract origin, so it was always
27315 : : removed during unused type prunning. Don't add anything in this
27316 : : case. */
27317 : 116709201 : if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
27318 : : break;
27319 : :
27320 : 116709201 : if (is_redundant_typedef (decl))
27321 : 69539195 : gen_type_die (TREE_TYPE (decl), context_die);
27322 : : else
27323 : : /* Output a DIE to represent the typedef itself. */
27324 : 47170006 : gen_typedef_die (decl, context_die);
27325 : : break;
27326 : :
27327 : 90928 : case LABEL_DECL:
27328 : 90928 : if (debug_info_level >= DINFO_LEVEL_NORMAL)
27329 : 90928 : gen_label_die (decl, context_die);
27330 : : break;
27331 : :
27332 : 46513542 : case VAR_DECL:
27333 : 46513542 : case RESULT_DECL:
27334 : : /* If we are in terse mode, don't generate any DIEs to represent any
27335 : : variable declarations or definitions unless it is external. */
27336 : 46513542 : if (debug_info_level < DINFO_LEVEL_TERSE
27337 : 46513542 : || (debug_info_level == DINFO_LEVEL_TERSE
27338 : 1200 : && !TREE_PUBLIC (decl_or_origin)))
27339 : : break;
27340 : :
27341 : 46513542 : if (debug_info_level > DINFO_LEVEL_TERSE)
27342 : : {
27343 : : /* Avoid generating stray type DIEs during late dwarf dumping.
27344 : : All types have been dumped early. */
27345 : 46512342 : if (early_dwarf
27346 : : /* ??? But in LTRANS we cannot annotate early created variably
27347 : : modified type DIEs without copying them and adjusting all
27348 : : references to them. Dump them again as happens for inlining
27349 : : which copies both the decl and the types. */
27350 : : /* ??? And even non-LTO needs to re-visit type DIEs to fill
27351 : : in VLA bound information for example. */
27352 : 46512342 : || (decl && variably_modified_type_p (TREE_TYPE (decl),
27353 : : current_function_decl)))
27354 : : {
27355 : : /* Output any DIEs that are needed to specify the type of this data
27356 : : object. */
27357 : 31695360 : if (decl_by_reference_p (decl_or_origin))
27358 : 2900 : gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
27359 : : else
27360 : 31692460 : gen_type_die (TREE_TYPE (decl_or_origin), context_die);
27361 : : }
27362 : :
27363 : 46512342 : if (early_dwarf)
27364 : : {
27365 : : /* And its containing type. */
27366 : 31690159 : class_origin = decl_class_context (decl_or_origin);
27367 : 31690159 : if (class_origin != NULL_TREE)
27368 : 17114507 : gen_type_die_for_member (class_origin, decl_or_origin, context_die);
27369 : :
27370 : : /* And its containing namespace. */
27371 : 31690159 : context_die = declare_in_namespace (decl_or_origin, context_die);
27372 : : }
27373 : : }
27374 : :
27375 : : /* Now output the DIE to represent the data object itself. This gets
27376 : : complicated because of the possibility that the VAR_DECL really
27377 : : represents an inlined instance of a formal parameter for an inline
27378 : : function. */
27379 : 46513542 : ultimate_origin = decl_ultimate_origin (decl_or_origin);
27380 : 46513542 : if (ultimate_origin != NULL_TREE
27381 : 13607958 : && TREE_CODE (ultimate_origin) == PARM_DECL)
27382 : 12162653 : gen_formal_parameter_die (decl, origin,
27383 : : true /* Emit name attribute. */,
27384 : : context_die);
27385 : : else
27386 : 34350889 : gen_variable_die (decl, origin, context_die);
27387 : : break;
27388 : :
27389 : 13963620 : case FIELD_DECL:
27390 : 13963620 : gcc_assert (ctx != NULL && ctx->struct_type != NULL);
27391 : : /* Ignore the nameless fields that are used to skip bits but handle C++
27392 : : anonymous unions and structs. */
27393 : 13963620 : if (DECL_NAME (decl) != NULL_TREE
27394 : 266679 : || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
27395 : 14120255 : || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
27396 : : {
27397 : 13827236 : gen_type_die (member_declared_type (decl), context_die);
27398 : 13827236 : gen_field_die (decl, ctx, context_die);
27399 : : }
27400 : : break;
27401 : :
27402 : 5028123 : case PARM_DECL:
27403 : : /* Avoid generating stray type DIEs during late dwarf dumping.
27404 : : All types have been dumped early. */
27405 : 5028123 : if (early_dwarf
27406 : : /* ??? But in LTRANS we cannot annotate early created variably
27407 : : modified type DIEs without copying them and adjusting all
27408 : : references to them. Dump them again as happens for inlining
27409 : : which copies both the decl and the types. */
27410 : : /* ??? And even non-LTO needs to re-visit type DIEs to fill
27411 : : in VLA bound information for example. */
27412 : 5028123 : || (decl && variably_modified_type_p (TREE_TYPE (decl),
27413 : : current_function_decl)))
27414 : : {
27415 : 4015615 : if (DECL_BY_REFERENCE (decl_or_origin))
27416 : 43722 : gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
27417 : : else
27418 : 3971893 : gen_type_die (TREE_TYPE (decl_or_origin), context_die);
27419 : : }
27420 : 5028123 : return gen_formal_parameter_die (decl, origin,
27421 : : true /* Emit name attribute. */,
27422 : 5028123 : context_die);
27423 : :
27424 : 359330 : case NAMESPACE_DECL:
27425 : 359330 : if (dwarf_version >= 3 || !dwarf_strict)
27426 : 359330 : gen_namespace_die (decl, context_die);
27427 : : break;
27428 : :
27429 : 0 : case IMPORTED_DECL:
27430 : 0 : dwarf2out_imported_module_or_decl_1 (decl, DECL_NAME (decl),
27431 : 0 : DECL_CONTEXT (decl), context_die);
27432 : 0 : break;
27433 : :
27434 : 235 : case NAMELIST_DECL:
27435 : 235 : gen_namelist_decl (DECL_NAME (decl), context_die,
27436 : 235 : NAMELIST_DECL_ASSOCIATED_DECL (decl));
27437 : 235 : break;
27438 : :
27439 : 183402 : default:
27440 : : /* Probably some frontend-internal decl. Assume we don't care. */
27441 : 183402 : gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
27442 : : break;
27443 : : }
27444 : :
27445 : : return NULL;
27446 : : }
27447 : :
27448 : : /* Output initial debug information for global DECL. Called at the
27449 : : end of the parsing process.
27450 : :
27451 : : This is the initial debug generation process. As such, the DIEs
27452 : : generated may be incomplete. A later debug generation pass
27453 : : (dwarf2out_late_global_decl) will augment the information generated
27454 : : in this pass (e.g., with complete location info). */
27455 : :
27456 : : static void
27457 : 25519337 : dwarf2out_early_global_decl (tree decl)
27458 : : {
27459 : 25519337 : set_early_dwarf s;
27460 : :
27461 : : /* gen_decl_die() will set DECL_ABSTRACT because
27462 : : cgraph_function_possibly_inlined_p() returns true. This is in
27463 : : turn will cause DW_AT_inline attributes to be set.
27464 : :
27465 : : This happens because at early dwarf generation, there is no
27466 : : cgraph information, causing cgraph_function_possibly_inlined_p()
27467 : : to return true. Trick cgraph_function_possibly_inlined_p()
27468 : : while we generate dwarf early. */
27469 : 25519337 : bool save = symtab->global_info_ready;
27470 : 25519337 : symtab->global_info_ready = true;
27471 : :
27472 : : /* We don't handle TYPE_DECLs. If required, they'll be reached via
27473 : : other DECLs and they can point to template types or other things
27474 : : that dwarf2out can't handle when done via dwarf2out_decl. */
27475 : 25519337 : if (TREE_CODE (decl) != TYPE_DECL
27476 : 25519337 : && TREE_CODE (decl) != PARM_DECL)
27477 : : {
27478 : 18750263 : if (TREE_CODE (decl) == FUNCTION_DECL)
27479 : : {
27480 : 2173204 : tree save_fndecl = current_function_decl;
27481 : :
27482 : : /* For nested functions, make sure we have DIEs for the parents first
27483 : : so that all nested DIEs are generated at the proper scope in the
27484 : : first shot. */
27485 : 2173204 : tree context = decl_function_context (decl);
27486 : 2173204 : if (context != NULL)
27487 : : {
27488 : 44003 : dw_die_ref context_die = lookup_decl_die (context);
27489 : 44003 : current_function_decl = context;
27490 : :
27491 : : /* Avoid emitting DIEs multiple times, but still process CONTEXT
27492 : : enough so that it lands in its own context. This avoids type
27493 : : pruning issues later on. */
27494 : 44003 : if (context_die == NULL || is_declaration_die (context_die))
27495 : 2996 : dwarf2out_early_global_decl (context);
27496 : : }
27497 : :
27498 : : /* Emit an abstract origin of a function first. This happens
27499 : : with C++ constructor clones for example and makes
27500 : : dwarf2out_abstract_function happy which requires the early
27501 : : DIE of the abstract instance to be present. */
27502 : 2173204 : tree origin = DECL_ABSTRACT_ORIGIN (decl);
27503 : 2173204 : dw_die_ref origin_die;
27504 : 2173204 : if (origin != NULL
27505 : : /* Do not emit the DIE multiple times but make sure to
27506 : : process it fully here in case we just saw a declaration. */
27507 : 2173204 : && ((origin_die = lookup_decl_die (origin)) == NULL
27508 : 251234 : || is_declaration_die (origin_die)))
27509 : : {
27510 : 344213 : current_function_decl = origin;
27511 : 344213 : dwarf2out_decl (origin);
27512 : : }
27513 : :
27514 : : /* Emit the DIE for decl but avoid doing that multiple times. */
27515 : 2173204 : dw_die_ref old_die;
27516 : 2173204 : if ((old_die = lookup_decl_die (decl)) == NULL
27517 : 2173204 : || is_declaration_die (old_die))
27518 : : {
27519 : 2170018 : current_function_decl = decl;
27520 : 2170018 : dwarf2out_decl (decl);
27521 : : }
27522 : :
27523 : 2173204 : current_function_decl = save_fndecl;
27524 : : }
27525 : : else
27526 : 16577059 : dwarf2out_decl (decl);
27527 : : }
27528 : 25519337 : symtab->global_info_ready = save;
27529 : 25519337 : }
27530 : :
27531 : : /* Return whether EXPR is an expression with the following pattern:
27532 : : INDIRECT_REF (NOP_EXPR (INTEGER_CST)). */
27533 : :
27534 : : static bool
27535 : 52 : is_trivial_indirect_ref (tree expr)
27536 : : {
27537 : 52 : if (expr == NULL_TREE || TREE_CODE (expr) != INDIRECT_REF)
27538 : : return false;
27539 : :
27540 : 0 : tree nop = TREE_OPERAND (expr, 0);
27541 : 0 : if (nop == NULL_TREE || TREE_CODE (nop) != NOP_EXPR)
27542 : : return false;
27543 : :
27544 : 0 : tree int_cst = TREE_OPERAND (nop, 0);
27545 : 0 : return int_cst != NULL_TREE && TREE_CODE (int_cst) == INTEGER_CST;
27546 : : }
27547 : :
27548 : : /* Output debug information for global decl DECL. Called from
27549 : : toplev.cc after compilation proper has finished. */
27550 : :
27551 : : static void
27552 : 19230218 : dwarf2out_late_global_decl (tree decl)
27553 : : {
27554 : : /* Fill-in any location information we were unable to determine
27555 : : on the first pass. */
27556 : 19230218 : if (VAR_P (decl))
27557 : : {
27558 : 19230218 : dw_die_ref die = lookup_decl_die (decl);
27559 : :
27560 : : /* We may have to generate full debug late for LTO in case debug
27561 : : was not enabled at compile-time or the target doesn't support
27562 : : the LTO early debug scheme. */
27563 : 4448888 : if (! die && in_lto_p
27564 : : /* Function scope variables are emitted when emitting the
27565 : : DIE for the function. */
27566 : 19231887 : && ! local_function_static (decl))
27567 : 1644 : dwarf2out_decl (decl);
27568 : 19228574 : else if (die)
27569 : : {
27570 : : /* We get called via the symtab code invoking late_global_decl
27571 : : for symbols that are optimized out.
27572 : :
27573 : : Do not add locations for those, except if they have a
27574 : : DECL_VALUE_EXPR, in which case they are relevant for debuggers.
27575 : : Still don't add a location if the DECL_VALUE_EXPR is not a trivial
27576 : : INDIRECT_REF expression, as this could generate relocations to
27577 : : text symbols in LTO object files, which is invalid. */
27578 : 14781330 : varpool_node *node = varpool_node::get (decl);
27579 : 14781330 : if ((! node || ! node->definition)
27580 : 29322301 : && ! (DECL_HAS_VALUE_EXPR_P (decl)
27581 : 52 : && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl))))
27582 : 14540919 : tree_add_const_value_attribute_for_decl (die, decl);
27583 : : else
27584 : 240411 : add_location_or_const_value_attribute (die, decl, false);
27585 : : }
27586 : : }
27587 : 19230218 : }
27588 : :
27589 : : /* Output debug information for type decl DECL. Called from toplev.cc
27590 : : and from language front ends (to record built-in types). */
27591 : : static void
27592 : 48454972 : dwarf2out_type_decl (tree decl, int local)
27593 : : {
27594 : 48454972 : if (!local)
27595 : : {
27596 : 42755755 : set_early_dwarf s;
27597 : 42755755 : dwarf2out_decl (decl);
27598 : 42755755 : }
27599 : 48454972 : }
27600 : :
27601 : : /* Output debug information for imported module or decl DECL.
27602 : : NAME is non-NULL name in the lexical block if the decl has been renamed.
27603 : : LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
27604 : : that DECL belongs to.
27605 : : LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
27606 : : static void
27607 : 5434506 : dwarf2out_imported_module_or_decl_1 (tree decl,
27608 : : tree name,
27609 : : tree lexical_block,
27610 : : dw_die_ref lexical_block_die)
27611 : : {
27612 : 5434506 : expanded_location xloc;
27613 : 5434506 : dw_die_ref imported_die = NULL;
27614 : 5434506 : dw_die_ref at_import_die;
27615 : :
27616 : 5434506 : if (TREE_CODE (decl) == IMPORTED_DECL)
27617 : : {
27618 : 12618 : xloc = expand_location (DECL_SOURCE_LOCATION (decl));
27619 : 12618 : decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
27620 : 12618 : gcc_assert (decl);
27621 : : }
27622 : : else
27623 : 5421888 : xloc = expand_location (input_location);
27624 : :
27625 : 5434506 : if (TREE_CODE (decl) == TYPE_DECL)
27626 : : {
27627 : 661064 : at_import_die = force_type_die (TREE_TYPE (decl));
27628 : : /* For namespace N { typedef void T; } using N::T; base_type_die
27629 : : returns NULL, but DW_TAG_imported_declaration requires
27630 : : the DW_AT_import tag. Force creation of DW_TAG_typedef. */
27631 : 661064 : if (!at_import_die)
27632 : : {
27633 : 0 : gcc_assert (TREE_CODE (decl) == TYPE_DECL);
27634 : 0 : gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
27635 : 0 : at_import_die = lookup_type_die (TREE_TYPE (decl));
27636 : 0 : gcc_assert (at_import_die);
27637 : : }
27638 : : }
27639 : : else
27640 : : {
27641 : 4773442 : at_import_die = lookup_decl_die (decl);
27642 : 4773442 : if (!at_import_die)
27643 : : {
27644 : : /* If we're trying to avoid duplicate debug info, we may not have
27645 : : emitted the member decl for this field. Emit it now. */
27646 : 1988912 : if (TREE_CODE (decl) == FIELD_DECL)
27647 : : {
27648 : 6 : tree type = DECL_CONTEXT (decl);
27649 : :
27650 : 6 : if (TYPE_CONTEXT (type)
27651 : 6 : && TYPE_P (TYPE_CONTEXT (type))
27652 : 6 : && !should_emit_struct_debug (TYPE_CONTEXT (type),
27653 : : DINFO_USAGE_DIR_USE))
27654 : 0 : return;
27655 : 6 : gen_type_die_for_member (type, decl,
27656 : 6 : get_context_die (TYPE_CONTEXT (type)));
27657 : : }
27658 : 1988912 : if (TREE_CODE (decl) == CONST_DECL)
27659 : : {
27660 : : /* Individual enumerators of an enum type do not get output here
27661 : : (see gen_decl_die), so we cannot call force_decl_die. */
27662 : 0 : if (!is_fortran () && !is_ada () && !is_dlang ())
27663 : : return;
27664 : : }
27665 : 1988912 : if (TREE_CODE (decl) == NAMELIST_DECL)
27666 : 4 : at_import_die = gen_namelist_decl (DECL_NAME (decl),
27667 : 4 : get_context_die (DECL_CONTEXT (decl)),
27668 : : NULL_TREE);
27669 : : else
27670 : 1988908 : at_import_die = force_decl_die (decl);
27671 : : }
27672 : : }
27673 : :
27674 : 5434506 : if (TREE_CODE (decl) == NAMESPACE_DECL)
27675 : : {
27676 : 41609 : if (dwarf_version >= 3 || !dwarf_strict)
27677 : 41609 : imported_die = new_die (DW_TAG_imported_module,
27678 : : lexical_block_die,
27679 : : lexical_block);
27680 : : else
27681 : : return;
27682 : : }
27683 : : else
27684 : 5392897 : imported_die = new_die (DW_TAG_imported_declaration,
27685 : : lexical_block_die,
27686 : : lexical_block);
27687 : :
27688 : 5434506 : add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
27689 : 5434506 : add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
27690 : 5434506 : if (debug_column_info && xloc.column)
27691 : 5434506 : add_AT_unsigned (imported_die, DW_AT_decl_column, xloc.column);
27692 : 5434506 : if (name)
27693 : 28 : add_AT_string (imported_die, DW_AT_name,
27694 : 28 : IDENTIFIER_POINTER (name));
27695 : 5434506 : add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
27696 : : }
27697 : :
27698 : : /* Output debug information for imported module or decl DECL.
27699 : : NAME is non-NULL name in context if the decl has been renamed.
27700 : : CHILD is true if decl is one of the renamed decls as part of
27701 : : importing whole module.
27702 : : IMPLICIT is set if this hook is called for an implicit import
27703 : : such as inline namespace. */
27704 : :
27705 : : static void
27706 : 5549127 : dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
27707 : : bool child, bool implicit)
27708 : : {
27709 : : /* dw_die_ref at_import_die; */
27710 : 5549127 : dw_die_ref scope_die;
27711 : :
27712 : 5549127 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27713 : 127239 : return;
27714 : :
27715 : 5549052 : gcc_assert (decl);
27716 : :
27717 : : /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
27718 : : should be enough, for DWARF4 and older even if we emit as extension
27719 : : DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
27720 : : for the benefit of consumers unaware of DW_AT_export_symbols. */
27721 : 5549052 : if (implicit
27722 : 127239 : && dwarf_version >= 5
27723 : 5676216 : && lang_hooks.decls.decl_dwarf_attribute (decl,
27724 : : DW_AT_export_symbols) == 1)
27725 : : return;
27726 : :
27727 : 5421888 : set_early_dwarf s;
27728 : :
27729 : : /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
27730 : : We need decl DIE for reference and scope die. First, get DIE for the decl
27731 : : itself. */
27732 : :
27733 : : /* Get the scope die for decl context. Use comp_unit_die for global module
27734 : : or decl. If die is not found for non globals, force new die. */
27735 : 5421888 : if (context
27736 : 5219173 : && TYPE_P (context)
27737 : 7816664 : && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
27738 : : return;
27739 : :
27740 : 5421888 : scope_die = get_context_die (context);
27741 : :
27742 : 5421888 : if (child)
27743 : : {
27744 : : /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
27745 : : there is nothing we can do, here. */
27746 : 13 : if (dwarf_version < 3 && dwarf_strict)
27747 : : return;
27748 : :
27749 : 13 : gcc_assert (scope_die->die_child);
27750 : 13 : gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
27751 : 13 : gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
27752 : : scope_die = scope_die->die_child;
27753 : : }
27754 : :
27755 : : /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
27756 : 5421888 : dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
27757 : 5421888 : }
27758 : :
27759 : : /* Output debug information for namelists. */
27760 : :
27761 : : static dw_die_ref
27762 : 239 : gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
27763 : : {
27764 : 239 : dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
27765 : 239 : tree value;
27766 : 239 : unsigned i;
27767 : :
27768 : 239 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27769 : : return NULL;
27770 : :
27771 : 239 : gcc_assert (scope_die != NULL);
27772 : 239 : nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
27773 : 239 : add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
27774 : :
27775 : : /* If there are no item_decls, we have a nondefining namelist, e.g.
27776 : : with USE association; hence, set DW_AT_declaration. */
27777 : 239 : if (item_decls == NULL_TREE)
27778 : : {
27779 : 4 : add_AT_flag (nml_die, DW_AT_declaration, 1);
27780 : 4 : return nml_die;
27781 : : }
27782 : :
27783 : 876 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
27784 : : {
27785 : 641 : nml_item_ref_die = lookup_decl_die (value);
27786 : 641 : if (!nml_item_ref_die)
27787 : 254 : nml_item_ref_die = force_decl_die (value);
27788 : :
27789 : 641 : nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
27790 : 641 : add_AT_die_ref (nml_item_die, DW_AT_namelist_item, nml_item_ref_die);
27791 : : }
27792 : : return nml_die;
27793 : : }
27794 : :
27795 : :
27796 : : /* Write the debugging output for DECL and return the DIE. */
27797 : :
27798 : : static void
27799 : 62761485 : dwarf2out_decl (tree decl)
27800 : : {
27801 : 62761485 : dw_die_ref context_die = comp_unit_die ();
27802 : :
27803 : 62761485 : switch (TREE_CODE (decl))
27804 : : {
27805 : : case ERROR_MARK:
27806 : : return;
27807 : :
27808 : 3071945 : case FUNCTION_DECL:
27809 : : /* If we're a nested function, initially use a parent of NULL; if we're
27810 : : a plain function, this will be fixed up in decls_for_scope. If
27811 : : we're a method, it will be ignored, since we already have a DIE.
27812 : : Avoid doing this late though since clones of class methods may
27813 : : otherwise end up in limbo and create type DIEs late. */
27814 : 3071945 : if (early_dwarf
27815 : 2514231 : && decl_function_context (decl)
27816 : : /* But if we're in terse mode, we don't care about scope. */
27817 : 3125983 : && debug_info_level > DINFO_LEVEL_TERSE)
27818 : : context_die = NULL;
27819 : : break;
27820 : :
27821 : 16571293 : case VAR_DECL:
27822 : : /* For local statics lookup proper context die. */
27823 : 16571293 : if (local_function_static (decl))
27824 : 33 : context_die = lookup_decl_die (DECL_CONTEXT (decl));
27825 : :
27826 : : /* If we are in terse mode, don't generate any DIEs to represent any
27827 : : variable declarations or definitions unless it is external. */
27828 : 16571293 : if (debug_info_level < DINFO_LEVEL_TERSE
27829 : 16571288 : || (debug_info_level == DINFO_LEVEL_TERSE
27830 : 2385 : && !TREE_PUBLIC (decl)))
27831 : : return;
27832 : : break;
27833 : :
27834 : 3184 : case CONST_DECL:
27835 : 3184 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27836 : : return;
27837 : 3184 : if (!is_fortran () && !is_ada () && !is_dlang ())
27838 : : return;
27839 : 3184 : if (TREE_STATIC (decl) && decl_function_context (decl))
27840 : 2828 : context_die = lookup_decl_die (DECL_CONTEXT (decl));
27841 : : break;
27842 : :
27843 : 359292 : case NAMESPACE_DECL:
27844 : 359292 : case IMPORTED_DECL:
27845 : 359292 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27846 : : return;
27847 : 359289 : if (lookup_decl_die (decl) != NULL)
27848 : : return;
27849 : : break;
27850 : :
27851 : 42755755 : case TYPE_DECL:
27852 : : /* Don't emit stubs for types unless they are needed by other DIEs. */
27853 : 42755755 : if (TYPE_DECL_SUPPRESS_DEBUG (decl))
27854 : : return;
27855 : :
27856 : : /* Don't bother trying to generate any DIEs to represent any of the
27857 : : normal built-in types for the language we are compiling. */
27858 : 41164042 : if (DECL_IS_UNDECLARED_BUILTIN (decl))
27859 : : return;
27860 : :
27861 : : /* If we are in terse mode, don't generate any DIEs for types. */
27862 : 39436057 : if (debug_info_level <= DINFO_LEVEL_TERSE)
27863 : : return;
27864 : :
27865 : : /* If we're a function-scope tag, initially use a parent of NULL;
27866 : : this will be fixed up in decls_for_scope. */
27867 : 39435643 : if (decl_function_context (decl))
27868 : 54125 : context_die = NULL;
27869 : :
27870 : : break;
27871 : :
27872 : : case NAMELIST_DECL:
27873 : : break;
27874 : :
27875 : : default:
27876 : : return;
27877 : : }
27878 : :
27879 : 59440352 : gen_decl_die (decl, NULL, NULL, context_die);
27880 : :
27881 : 59440352 : if (flag_checking)
27882 : : {
27883 : 59440330 : dw_die_ref die = lookup_decl_die (decl);
27884 : 59440330 : if (die)
27885 : 17360082 : check_die (die);
27886 : : }
27887 : : }
27888 : :
27889 : : /* Write the debugging output for DECL. */
27890 : :
27891 : : static void
27892 : 557714 : dwarf2out_function_decl (tree decl)
27893 : : {
27894 : 557714 : dwarf2out_decl (decl);
27895 : 557714 : call_arg_locations = NULL;
27896 : 557714 : call_arg_loc_last = NULL;
27897 : 557714 : call_site_count = -1;
27898 : 557714 : tail_call_site_count = -1;
27899 : 557714 : decl_loc_table->empty ();
27900 : 557714 : cached_dw_loc_list_table->empty ();
27901 : 557714 : }
27902 : :
27903 : : /* Output a marker (i.e. a label) for the beginning of the generated code for
27904 : : a lexical block. */
27905 : :
27906 : : static void
27907 : 23708387 : dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
27908 : : unsigned int blocknum,
27909 : : tree block ATTRIBUTE_UNUSED)
27910 : : {
27911 : : #ifdef CODEVIEW_DEBUGGING_INFO
27912 : : if (codeview_debuginfo_p ())
27913 : : codeview_begin_block (line, blocknum, block);
27914 : : #endif
27915 : :
27916 : 23708387 : switch_to_section (current_function_section ());
27917 : 23708387 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
27918 : 23708387 : }
27919 : :
27920 : : /* Output a marker (i.e. a label) for the end of the generated code for a
27921 : : lexical block. */
27922 : :
27923 : : static void
27924 : 23708387 : dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
27925 : : {
27926 : : #ifdef CODEVIEW_DEBUGGING_INFO
27927 : : if (codeview_debuginfo_p ())
27928 : : codeview_end_block (line, blocknum);
27929 : : #endif
27930 : :
27931 : 23708387 : switch_to_section (current_function_section ());
27932 : 23708387 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
27933 : 23708387 : }
27934 : :
27935 : : /* Returns true if it is appropriate not to emit any debugging
27936 : : information for BLOCK, because it doesn't contain any instructions.
27937 : :
27938 : : Don't allow this for blocks with nested functions or local classes
27939 : : as we would end up with orphans, and in the presence of scheduling
27940 : : we may end up calling them anyway. */
27941 : :
27942 : : static bool
27943 : 109175271 : dwarf2out_ignore_block (const_tree block)
27944 : : {
27945 : 109175271 : tree decl;
27946 : 109175271 : unsigned int i;
27947 : :
27948 : 220915540 : for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
27949 : 112152695 : if (TREE_CODE (decl) == FUNCTION_DECL
27950 : 112152695 : || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
27951 : : return false;
27952 : 109059013 : for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
27953 : : {
27954 : 313439 : decl = BLOCK_NONLOCALIZED_VAR (block, i);
27955 : 313439 : if (TREE_CODE (decl) == FUNCTION_DECL
27956 : 313439 : || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
27957 : : return false;
27958 : : }
27959 : :
27960 : : return true;
27961 : : }
27962 : :
27963 : : /* Hash table routines for file_hash. */
27964 : :
27965 : : bool
27966 : 1537816738 : dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
27967 : : {
27968 : 1537816738 : return filename_cmp (p1->key, p2) == 0;
27969 : : }
27970 : :
27971 : : hashval_t
27972 : 1115780404 : dwarf_file_hasher::hash (dwarf_file_data *p)
27973 : : {
27974 : 1115780404 : return htab_hash_string (p->key);
27975 : : }
27976 : :
27977 : : /* Lookup FILE_NAME (in the list of filenames that we know about here in
27978 : : dwarf2out.cc) and return its "index". The index of each (known) filename is
27979 : : just a unique number which is associated with only that one filename. We
27980 : : need such numbers for the sake of generating labels (in the .debug_sfnames
27981 : : section) and references to those files numbers (in the .debug_srcinfo
27982 : : and .debug_macinfo sections). If the filename given as an argument is not
27983 : : found in our current list, add it to the list and assign it the next
27984 : : available unique index number. */
27985 : :
27986 : : static struct dwarf_file_data *
27987 : 247733464 : lookup_filename (const char *file_name)
27988 : : {
27989 : 247733464 : struct dwarf_file_data * created;
27990 : :
27991 : 247733464 : if (!file_name)
27992 : : return NULL;
27993 : :
27994 : 247724173 : if (!file_name[0])
27995 : 246 : file_name = "<stdin>";
27996 : :
27997 : 247724173 : dwarf_file_data **slot
27998 : 247724173 : = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
27999 : : INSERT);
28000 : 247724173 : if (*slot)
28001 : : return *slot;
28002 : :
28003 : 2900594 : created = ggc_alloc<dwarf_file_data> ();
28004 : 2900594 : created->key = file_name;
28005 : 2900594 : created->filename = remap_debug_filename (file_name);
28006 : 2900594 : created->emitted_number = 0;
28007 : 2900594 : *slot = created;
28008 : 2900594 : return created;
28009 : : }
28010 : :
28011 : : /* If the assembler will construct the file table, then translate the compiler
28012 : : internal file table number into the assembler file table number, and emit
28013 : : a .file directive if we haven't already emitted one yet. The file table
28014 : : numbers are different because we prune debug info for unused variables and
28015 : : types, which may include filenames. */
28016 : :
28017 : : static int
28018 : 216905000 : maybe_emit_file (struct dwarf_file_data * fd)
28019 : : {
28020 : 216905000 : if (! fd->emitted_number)
28021 : : {
28022 : 1121546 : if (last_emitted_file)
28023 : 1071672 : fd->emitted_number = last_emitted_file->emitted_number + 1;
28024 : : else
28025 : 49874 : fd->emitted_number = 1;
28026 : 1121546 : last_emitted_file = fd;
28027 : :
28028 : 1121546 : if (output_asm_line_debug_info ())
28029 : : {
28030 : 1121432 : fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
28031 : 1121432 : output_quoted_string (asm_out_file, fd->filename);
28032 : 1121432 : fputc ('\n', asm_out_file);
28033 : : }
28034 : : }
28035 : :
28036 : 216905000 : return fd->emitted_number;
28037 : : }
28038 : :
28039 : : /* Schedule generation of a DW_AT_const_value attribute to DIE.
28040 : : That generation should happen after function debug info has been
28041 : : generated. The value of the attribute is the constant value of ARG. */
28042 : :
28043 : : static void
28044 : 5097327 : append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
28045 : : {
28046 : 5097327 : die_arg_entry entry;
28047 : :
28048 : 5097327 : if (!die || !arg)
28049 : 0 : return;
28050 : :
28051 : 5097327 : gcc_assert (early_dwarf);
28052 : :
28053 : 5097327 : if (!tmpl_value_parm_die_table)
28054 : 12000 : vec_alloc (tmpl_value_parm_die_table, 32);
28055 : :
28056 : 5097327 : entry.die = die;
28057 : 5097327 : entry.arg = arg;
28058 : 5097327 : vec_safe_push (tmpl_value_parm_die_table, entry);
28059 : : }
28060 : :
28061 : : /* Return TRUE if T is an instance of generic type, FALSE
28062 : : otherwise. */
28063 : :
28064 : : static bool
28065 : 36777328 : generic_type_p (tree t)
28066 : : {
28067 : 36777328 : if (t == NULL_TREE || !TYPE_P (t))
28068 : : return false;
28069 : 36777328 : return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
28070 : : }
28071 : :
28072 : : /* Schedule the generation of the generic parameter dies for the
28073 : : instance of generic type T. The proper generation itself is later
28074 : : done by gen_scheduled_generic_parms_dies. */
28075 : :
28076 : : static void
28077 : 36777328 : schedule_generic_params_dies_gen (tree t)
28078 : : {
28079 : 36777328 : if (!generic_type_p (t))
28080 : : return;
28081 : :
28082 : 30954504 : gcc_assert (early_dwarf);
28083 : :
28084 : 30954504 : if (!generic_type_instances)
28085 : 12994 : vec_alloc (generic_type_instances, 256);
28086 : :
28087 : 30954504 : vec_safe_push (generic_type_instances, t);
28088 : : }
28089 : :
28090 : : /* Add a DW_AT_const_value attribute to DIEs that were scheduled
28091 : : by append_entry_to_tmpl_value_parm_die_table. This function must
28092 : : be called after function DIEs have been generated. */
28093 : :
28094 : : static void
28095 : 104385 : gen_remaining_tmpl_value_param_die_attribute (void)
28096 : : {
28097 : 104385 : if (tmpl_value_parm_die_table)
28098 : : {
28099 : : unsigned i, j;
28100 : : die_arg_entry *e;
28101 : :
28102 : : /* We do this in two phases - first get the cases we can
28103 : : handle during early-finish, preserving those we cannot
28104 : : (containing symbolic constants where we don't yet know
28105 : : whether we are going to output the referenced symbols).
28106 : : For those we try again at late-finish. */
28107 : : j = 0;
28108 : 5121416 : FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
28109 : : {
28110 : 5097450 : if (!e->die->removed
28111 : 5097450 : && !tree_add_const_value_attribute (e->die, e->arg))
28112 : : {
28113 : 210 : dw_loc_descr_ref loc = NULL;
28114 : 210 : if (! early_dwarf
28115 : 87 : && (dwarf_version >= 5 || !dwarf_strict))
28116 : 84 : loc = loc_descriptor_from_tree (e->arg, 2, NULL);
28117 : 84 : if (loc)
28118 : 79 : add_AT_loc (e->die, DW_AT_location, loc);
28119 : : else
28120 : 131 : (*tmpl_value_parm_die_table)[j++] = *e;
28121 : : }
28122 : : }
28123 : 23966 : tmpl_value_parm_die_table->truncate (j);
28124 : : }
28125 : 104385 : }
28126 : :
28127 : : /* Generate generic parameters DIEs for instances of generic types
28128 : : that have been previously scheduled by
28129 : : schedule_generic_params_dies_gen. This function must be called
28130 : : after all the types of the CU have been laid out. */
28131 : :
28132 : : static void
28133 : 52411 : gen_scheduled_generic_parms_dies (void)
28134 : : {
28135 : 52411 : unsigned i;
28136 : 52411 : tree t;
28137 : :
28138 : 52411 : if (!generic_type_instances)
28139 : 52411 : return;
28140 : :
28141 : 29861160 : FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
28142 : 29848671 : if (COMPLETE_TYPE_P (t))
28143 : 27529450 : gen_generic_params_dies (t);
28144 : :
28145 : 12489 : generic_type_instances = NULL;
28146 : : }
28147 : :
28148 : :
28149 : : /* Replace DW_AT_name for the decl with name. */
28150 : :
28151 : : static void
28152 : 0 : dwarf2out_set_name (tree decl, tree name)
28153 : : {
28154 : 0 : dw_die_ref die;
28155 : 0 : dw_attr_node *attr;
28156 : 0 : const char *dname;
28157 : :
28158 : 0 : die = TYPE_SYMTAB_DIE (decl);
28159 : 0 : if (!die)
28160 : : return;
28161 : :
28162 : 0 : dname = dwarf2_name (name, 0);
28163 : 0 : if (!dname)
28164 : : return;
28165 : :
28166 : 0 : attr = get_AT (die, DW_AT_name);
28167 : 0 : if (attr)
28168 : : {
28169 : 0 : struct indirect_string_node *node;
28170 : :
28171 : 0 : node = find_AT_string (dname);
28172 : : /* replace the string. */
28173 : 0 : attr->dw_attr_val.v.val_str = node;
28174 : : }
28175 : :
28176 : : else
28177 : 0 : add_name_attribute (die, dname);
28178 : : }
28179 : :
28180 : : /* True if before or during processing of the first function being emitted. */
28181 : : static bool in_first_function_p = true;
28182 : : /* True if loc_note during dwarf2out_var_location call might still be
28183 : : before first real instruction at address equal to .Ltext0. */
28184 : : static bool maybe_at_text_label_p = true;
28185 : : /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
28186 : : static unsigned int first_loclabel_num_not_at_text_label;
28187 : :
28188 : : /* Look ahead for a real insn. */
28189 : :
28190 : : static rtx_insn *
28191 : 13990077 : dwarf2out_next_real_insn (rtx_insn *loc_note)
28192 : : {
28193 : 13990077 : rtx_insn *next_real = NEXT_INSN (loc_note);
28194 : :
28195 : 149712080 : while (next_real)
28196 : 135467358 : if (INSN_P (next_real))
28197 : : break;
28198 : : else
28199 : 121731926 : next_real = NEXT_INSN (next_real);
28200 : :
28201 : 13990077 : return next_real;
28202 : : }
28203 : :
28204 : : /* Called by the final INSN scan whenever we see a var location. We
28205 : : use it to drop labels in the right places, and throw the location in
28206 : : our lookup table. */
28207 : :
28208 : : static void
28209 : 98788920 : dwarf2out_var_location (rtx_insn *loc_note)
28210 : : {
28211 : 98788920 : char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
28212 : 98788920 : struct var_loc_node *newloc;
28213 : 98788920 : rtx_insn *next_real;
28214 : 98788920 : rtx_insn *call_insn = NULL;
28215 : 98788920 : static const char *last_label;
28216 : 98788920 : static const char *last_postcall_label;
28217 : 98788920 : static bool last_in_cold_section_p;
28218 : 98788920 : static rtx_insn *expected_next_loc_note;
28219 : 98788920 : tree decl;
28220 : 98788920 : bool var_loc_p;
28221 : 98788920 : var_loc_view view = 0;
28222 : :
28223 : 98788920 : if (!NOTE_P (loc_note))
28224 : : {
28225 : 42270670 : if (CALL_P (loc_note))
28226 : : {
28227 : 3537837 : maybe_reset_location_view (loc_note, cur_line_info_table);
28228 : 3537837 : call_site_count++;
28229 : 3537837 : if (SIBLING_CALL_P (loc_note))
28230 : 58799 : tail_call_site_count++;
28231 : 3537837 : if (find_reg_note (loc_note, REG_CALL_ARG_LOCATION, NULL_RTX))
28232 : : {
28233 : 3174639 : call_insn = loc_note;
28234 : 3174639 : loc_note = NULL;
28235 : 3174639 : var_loc_p = false;
28236 : :
28237 : 3174639 : next_real = dwarf2out_next_real_insn (call_insn);
28238 : 3174639 : cached_next_real_insn = NULL;
28239 : 3174639 : goto create_label;
28240 : : }
28241 : 363198 : if (optimize == 0 && !flag_var_tracking)
28242 : : {
28243 : : /* When the var-tracking pass is not running, there is no note
28244 : : for indirect calls whose target is compile-time known. In this
28245 : : case, process such calls specifically so that we generate call
28246 : : sites for them anyway. */
28247 : 338268 : rtx x = PATTERN (loc_note);
28248 : 338268 : if (GET_CODE (x) == PARALLEL)
28249 : 1 : x = XVECEXP (x, 0, 0);
28250 : 338268 : if (GET_CODE (x) == SET)
28251 : 101678 : x = SET_SRC (x);
28252 : 338268 : if (GET_CODE (x) == CALL)
28253 : 338268 : x = XEXP (x, 0);
28254 : 338268 : if (!MEM_P (x)
28255 : 338268 : || GET_CODE (XEXP (x, 0)) != SYMBOL_REF
28256 : 317807 : || !SYMBOL_REF_DECL (XEXP (x, 0))
28257 : 640781 : || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0)))
28258 : : != FUNCTION_DECL))
28259 : : {
28260 : 35755 : call_insn = loc_note;
28261 : 35755 : loc_note = NULL;
28262 : 35755 : var_loc_p = false;
28263 : :
28264 : 35755 : next_real = dwarf2out_next_real_insn (call_insn);
28265 : 35755 : cached_next_real_insn = NULL;
28266 : 35755 : goto create_label;
28267 : : }
28268 : : }
28269 : : }
28270 : 38732833 : else if (!debug_variable_location_views)
28271 : 0 : gcc_unreachable ();
28272 : : else
28273 : 38732833 : maybe_reset_location_view (loc_note, cur_line_info_table);
28274 : :
28275 : 47224688 : return;
28276 : : }
28277 : :
28278 : 56518250 : var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
28279 : 56518250 : if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
28280 : : return;
28281 : :
28282 : : /* Optimize processing a large consecutive sequence of location
28283 : : notes so we don't spend too much time in next_real_insn. If the
28284 : : next insn is another location note, remember the next_real_insn
28285 : : calculation for next time. */
28286 : 56518250 : next_real = cached_next_real_insn;
28287 : 56518250 : if (next_real)
28288 : : {
28289 : 45738567 : if (expected_next_loc_note != loc_note)
28290 : : next_real = NULL;
28291 : : }
28292 : :
28293 : : if (! next_real)
28294 : 10779683 : next_real = dwarf2out_next_real_insn (loc_note);
28295 : :
28296 : 10779683 : if (next_real)
28297 : : {
28298 : 56400865 : rtx_insn *next_note = NEXT_INSN (loc_note);
28299 : 166665596 : while (next_note != next_real)
28300 : : {
28301 : 99602433 : if (! next_note->deleted ()
28302 : 99602433 : && NOTE_P (next_note)
28303 : 196163814 : && NOTE_KIND (next_note) == NOTE_INSN_VAR_LOCATION)
28304 : : break;
28305 : 53863866 : next_note = NEXT_INSN (next_note);
28306 : : }
28307 : :
28308 : 56400865 : if (next_note == next_real)
28309 : 10662298 : cached_next_real_insn = NULL;
28310 : : else
28311 : : {
28312 : 45738567 : expected_next_loc_note = next_note;
28313 : 45738567 : cached_next_real_insn = next_real;
28314 : : }
28315 : : }
28316 : : else
28317 : 117385 : cached_next_real_insn = NULL;
28318 : :
28319 : : /* If there are no instructions which would be affected by this note,
28320 : : don't do anything. */
28321 : 56518250 : if (var_loc_p
28322 : 56518250 : && next_real == NULL_RTX
28323 : 56518250 : && !NOTE_DURING_CALL_P (loc_note))
28324 : : return;
28325 : :
28326 : 59728100 : create_label:
28327 : :
28328 : 59728100 : if (next_real == NULL_RTX)
28329 : 254101 : next_real = get_last_insn ();
28330 : :
28331 : : /* If there were any real insns between note we processed last time
28332 : : and this note (or if it is the first note), clear
28333 : : last_{,postcall_}label so that they are not reused this time. */
28334 : 59728100 : if (last_var_location_insn == NULL_RTX
28335 : 59227174 : || last_var_location_insn != next_real
28336 : 45889512 : || last_in_cold_section_p != in_cold_section_p)
28337 : : {
28338 : 13842008 : last_label = NULL;
28339 : 13842008 : last_postcall_label = NULL;
28340 : : }
28341 : :
28342 : 59728100 : if (var_loc_p)
28343 : : {
28344 : 56517706 : const char *label
28345 : 56517706 : = NOTE_DURING_CALL_P (loc_note) ? last_postcall_label : last_label;
28346 : 56517706 : view = cur_line_info_table->view;
28347 : 56517706 : decl = NOTE_VAR_LOCATION_DECL (loc_note);
28348 : 56517706 : newloc = add_var_loc_to_decl (decl, loc_note, label, view);
28349 : 56517706 : if (newloc == NULL)
28350 : : return;
28351 : : }
28352 : : else
28353 : : {
28354 : : decl = NULL_TREE;
28355 : : newloc = NULL;
28356 : : }
28357 : :
28358 : : /* If there were no real insns between note we processed last time
28359 : : and this note, use the label we emitted last time. Otherwise
28360 : : create a new label and emit it. */
28361 : 51564232 : if (last_label == NULL)
28362 : : {
28363 : 11744028 : ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
28364 : 11744028 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
28365 : 11744028 : loclabel_num++;
28366 : 11744028 : last_label = ggc_strdup (loclabel);
28367 : : /* See if loclabel might be equal to .Ltext0. If yes,
28368 : : bump first_loclabel_num_not_at_text_label. */
28369 : 11744028 : if (!have_multiple_function_sections
28370 : 4695300 : && in_first_function_p
28371 : 259089 : && maybe_at_text_label_p)
28372 : : {
28373 : : static rtx_insn *last_start;
28374 : : rtx_insn *insn;
28375 : 126410 : for (insn = loc_note; insn; insn = previous_insn (insn))
28376 : 82044 : if (insn == last_start)
28377 : : break;
28378 : 81864 : else if (!NONDEBUG_INSN_P (insn))
28379 : 69658 : continue;
28380 : : else
28381 : : {
28382 : 12206 : rtx body = PATTERN (insn);
28383 : 12206 : if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
28384 : 3 : continue;
28385 : : /* Inline asm could occupy zero bytes. */
28386 : 12447 : else if (GET_CODE (body) == ASM_INPUT
28387 : 12203 : || asm_noperands (body) >= 0)
28388 : 244 : continue;
28389 : : #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h. */
28390 : : else if (HAVE_ATTR_length && get_attr_min_length (insn) == 0)
28391 : : continue;
28392 : : #endif
28393 : : else
28394 : : {
28395 : : /* Assume insn has non-zero length. */
28396 : 11959 : maybe_at_text_label_p = false;
28397 : 11959 : break;
28398 : : }
28399 : : }
28400 : 56505 : if (maybe_at_text_label_p)
28401 : : {
28402 : 44546 : last_start = loc_note;
28403 : 44546 : first_loclabel_num_not_at_text_label = loclabel_num;
28404 : : }
28405 : : }
28406 : : }
28407 : :
28408 : 51564232 : gcc_assert ((loc_note == NULL_RTX && call_insn != NULL_RTX)
28409 : : || (loc_note != NULL_RTX && call_insn == NULL_RTX));
28410 : :
28411 : 51564232 : if (!var_loc_p)
28412 : : {
28413 : 3210394 : struct call_arg_loc_node *ca_loc
28414 : 3210394 : = ggc_cleared_alloc<call_arg_loc_node> ();
28415 : 3210394 : rtx_insn *prev = call_insn;
28416 : :
28417 : 3210394 : ca_loc->call_insn = call_insn;
28418 : 3210394 : ca_loc->next = NULL;
28419 : 3210394 : ca_loc->label = last_label;
28420 : 3210394 : gcc_assert (prev
28421 : : && (CALL_P (prev)
28422 : : || (NONJUMP_INSN_P (prev)
28423 : : && GET_CODE (PATTERN (prev)) == SEQUENCE
28424 : : && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
28425 : 3210394 : if (!CALL_P (prev))
28426 : 0 : prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
28427 : 3210394 : ca_loc->tail_call_p = SIBLING_CALL_P (prev);
28428 : :
28429 : : /* Look for a SYMBOL_REF in the "prev" instruction. */
28430 : 3210394 : rtx x = get_call_rtx_from (prev);
28431 : 3210394 : if (x)
28432 : : {
28433 : : /* Try to get the call symbol, if any. */
28434 : 3210394 : if (MEM_P (XEXP (x, 0)))
28435 : 3210394 : x = XEXP (x, 0);
28436 : : /* First, look for a memory access to a symbol_ref. */
28437 : 3210394 : if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
28438 : 3058341 : && SYMBOL_REF_DECL (XEXP (x, 0))
28439 : 6018437 : && TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0))) == FUNCTION_DECL)
28440 : 2808040 : ca_loc->symbol_ref = XEXP (x, 0);
28441 : : /* Otherwise, look at a compile-time known user-level function
28442 : : declaration. */
28443 : 402354 : else if (MEM_P (x)
28444 : 402354 : && MEM_EXPR (x)
28445 : 548635 : && TREE_CODE (MEM_EXPR (x)) == FUNCTION_DECL)
28446 : 0 : ca_loc->symbol_ref = XEXP (DECL_RTL (MEM_EXPR (x)), 0);
28447 : : }
28448 : :
28449 : 3210394 : ca_loc->block = insn_scope (prev);
28450 : 3210394 : if (call_arg_locations)
28451 : 2766423 : call_arg_loc_last->next = ca_loc;
28452 : : else
28453 : 443971 : call_arg_locations = ca_loc;
28454 : 3210394 : call_arg_loc_last = ca_loc;
28455 : : }
28456 : 48353838 : else if (loc_note != NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
28457 : : {
28458 : 45671624 : newloc->label = last_label;
28459 : 45671624 : newloc->view = view;
28460 : : }
28461 : : else
28462 : : {
28463 : 2682214 : if (!last_postcall_label)
28464 : : {
28465 : 1077898 : sprintf (loclabel, "%s-1", last_label);
28466 : 1077898 : last_postcall_label = ggc_strdup (loclabel);
28467 : : }
28468 : 2682214 : newloc->label = last_postcall_label;
28469 : : /* ??? This view is at last_label, not last_label-1, but we
28470 : : could only assume view at last_label-1 is zero if we could
28471 : : assume calls always have length greater than one. This is
28472 : : probably true in general, though there might be a rare
28473 : : exception to this rule, e.g. if a call insn is optimized out
28474 : : by target magic. Then, even the -1 in the label will be
28475 : : wrong, which might invalidate the range. Anyway, using view,
28476 : : though technically possibly incorrect, will work as far as
28477 : : ranges go: since L-1 is in the middle of the call insn,
28478 : : (L-1).0 and (L-1).V shouldn't make any difference, and having
28479 : : the loclist entry refer to the .loc entry might be useful, so
28480 : : leave it like this. */
28481 : 2682214 : newloc->view = view;
28482 : : }
28483 : :
28484 : 51564232 : if (var_loc_p && flag_debug_asm)
28485 : : {
28486 : 396 : const char *name, *sep, *patstr;
28487 : 396 : if (decl && DECL_NAME (decl))
28488 : 385 : name = IDENTIFIER_POINTER (DECL_NAME (decl));
28489 : : else
28490 : : name = "";
28491 : 396 : if (NOTE_VAR_LOCATION_LOC (loc_note))
28492 : : {
28493 : 296 : sep = " => ";
28494 : 296 : patstr = str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note));
28495 : : }
28496 : : else
28497 : : {
28498 : : sep = " ";
28499 : : patstr = "RESET";
28500 : : }
28501 : 396 : fprintf (asm_out_file, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START,
28502 : : name, sep, patstr);
28503 : : }
28504 : :
28505 : 51564232 : last_var_location_insn = next_real;
28506 : 51564232 : last_in_cold_section_p = in_cold_section_p;
28507 : : }
28508 : :
28509 : : /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
28510 : : OUTER itself. If BOTHWAYS, check not only that BLOCK can reach
28511 : : OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
28512 : : path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
28513 : : BLOCK_FRAGMENT_ORIGIN links. */
28514 : : static bool
28515 : 7174081 : block_within_block_p (tree block, tree outer, bool bothways)
28516 : : {
28517 : 7174081 : if (block == outer)
28518 : : return true;
28519 : :
28520 : : /* Quickly check that OUTER is up BLOCK's supercontext chain. */
28521 : 7174081 : for (tree context = BLOCK_SUPERCONTEXT (block);
28522 : 50709834 : context != outer;
28523 : 43535753 : context = BLOCK_SUPERCONTEXT (context))
28524 : 43535753 : if (!context || TREE_CODE (context) != BLOCK)
28525 : : return false;
28526 : :
28527 : 7174081 : if (!bothways)
28528 : : return true;
28529 : :
28530 : : /* Now check that each block is actually referenced by its
28531 : : parent. */
28532 : 43535753 : for (tree context = BLOCK_SUPERCONTEXT (block); ;
28533 : 43535753 : context = BLOCK_SUPERCONTEXT (context))
28534 : : {
28535 : 50709834 : if (BLOCK_FRAGMENT_ORIGIN (context))
28536 : : {
28537 : 2325925 : gcc_assert (!BLOCK_SUBBLOCKS (context));
28538 : : context = BLOCK_FRAGMENT_ORIGIN (context);
28539 : : }
28540 : 237167666 : for (tree sub = BLOCK_SUBBLOCKS (context);
28541 : 237167666 : sub != block;
28542 : 186457832 : sub = BLOCK_CHAIN (sub))
28543 : 186457832 : if (!sub)
28544 : : return false;
28545 : 50709834 : if (context == outer)
28546 : : return true;
28547 : : else
28548 : 43535753 : block = context;
28549 : 43535753 : }
28550 : : }
28551 : :
28552 : : /* Called during final while assembling the marker of the entry point
28553 : : for an inlined function. */
28554 : :
28555 : : static void
28556 : 7174081 : dwarf2out_inline_entry (tree block)
28557 : : {
28558 : 7174081 : gcc_assert (debug_inline_points);
28559 : :
28560 : : /* If we can't represent it, don't bother. */
28561 : 7174081 : if (!(dwarf_version >= 3 || !dwarf_strict))
28562 : : return;
28563 : :
28564 : 7174081 : gcc_assert (DECL_P (block_ultimate_origin (block)));
28565 : :
28566 : : /* Sanity check the block tree. This would catch a case in which
28567 : : BLOCK got removed from the tree reachable from the outermost
28568 : : lexical block, but got retained in markers. It would still link
28569 : : back to its parents, but some ancestor would be missing a link
28570 : : down the path to the sub BLOCK. If the block got removed, its
28571 : : BLOCK_NUMBER will not be a usable value. */
28572 : 7174081 : if (flag_checking)
28573 : 7174081 : gcc_assert (block_within_block_p (block,
28574 : : DECL_INITIAL (current_function_decl),
28575 : : true));
28576 : :
28577 : 7174081 : gcc_assert (inlined_function_outer_scope_p (block));
28578 : 7174081 : gcc_assert (!lookup_block_die (block));
28579 : :
28580 : 7174081 : if (BLOCK_FRAGMENT_ORIGIN (block))
28581 : 0 : block = BLOCK_FRAGMENT_ORIGIN (block);
28582 : : /* Can the entry point ever not be at the beginning of an
28583 : : unfragmented lexical block? */
28584 : 7174081 : else if (!(BLOCK_FRAGMENT_CHAIN (block)
28585 : 4057076 : || (cur_line_info_table
28586 : 4057076 : && !ZERO_VIEW_P (cur_line_info_table->view))))
28587 : 933 : return;
28588 : :
28589 : 7173148 : if (!inline_entry_data_table)
28590 : 12704 : inline_entry_data_table
28591 : 12704 : = hash_table<inline_entry_data_hasher>::create_ggc (10);
28592 : :
28593 : :
28594 : 7173148 : inline_entry_data **iedp
28595 : 7173148 : = inline_entry_data_table->find_slot_with_hash (block,
28596 : : htab_hash_pointer (block),
28597 : : INSERT);
28598 : 7173148 : if (*iedp)
28599 : : /* ??? Ideally, we'd record all entry points for the same inlined
28600 : : function (some may have been duplicated by e.g. unrolling), but
28601 : : we have no way to represent that ATM. */
28602 : : return;
28603 : :
28604 : 6674669 : inline_entry_data *ied = *iedp = ggc_cleared_alloc<inline_entry_data> ();
28605 : 6674669 : ied->block = block;
28606 : 6674669 : ied->label_pfx = BLOCK_INLINE_ENTRY_LABEL;
28607 : 6674669 : ied->label_num = BLOCK_NUMBER (block);
28608 : 6674669 : if (cur_line_info_table)
28609 : 6674669 : ied->view = cur_line_info_table->view;
28610 : :
28611 : 6674669 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_INLINE_ENTRY_LABEL,
28612 : : BLOCK_NUMBER (block));
28613 : : }
28614 : :
28615 : : /* Called from finalize_size_functions for size functions so that their body
28616 : : can be encoded in the debug info to describe the layout of variable-length
28617 : : structures. */
28618 : :
28619 : : static void
28620 : 0 : dwarf2out_size_function (tree decl)
28621 : : {
28622 : 0 : set_early_dwarf s;
28623 : 0 : function_to_dwarf_procedure (decl);
28624 : 0 : }
28625 : :
28626 : : /* Note in one location list that text section has changed. */
28627 : :
28628 : : int
28629 : 2912968 : var_location_switch_text_section_1 (var_loc_list **slot, void *)
28630 : : {
28631 : 2912968 : var_loc_list *list = *slot;
28632 : 2912968 : if (list->first)
28633 : 2912968 : list->last_before_switch
28634 : 2954091 : = list->last->next ? list->last->next : list->last;
28635 : 2912968 : return 1;
28636 : : }
28637 : :
28638 : : /* Note in all location lists that text section has changed. */
28639 : :
28640 : : static void
28641 : 61949 : var_location_switch_text_section (void)
28642 : : {
28643 : 61949 : if (decl_loc_table == NULL)
28644 : : return;
28645 : :
28646 : 2933230 : decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
28647 : : }
28648 : :
28649 : : /* Create a new line number table. */
28650 : :
28651 : : static dw_line_info_table *
28652 : 260002 : new_line_info_table (void)
28653 : : {
28654 : 260002 : dw_line_info_table *table;
28655 : :
28656 : 260002 : table = ggc_cleared_alloc<dw_line_info_table> ();
28657 : 260002 : table->file_num = 1;
28658 : 260002 : table->line_num = 1;
28659 : 260002 : table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
28660 : 260002 : FORCE_RESET_NEXT_VIEW (table->view);
28661 : 260002 : table->symviews_since_reset = 0;
28662 : :
28663 : 260002 : return table;
28664 : : }
28665 : :
28666 : : /* Lookup the "current" table into which we emit line info, so
28667 : : that we don't have to do it for every source line. */
28668 : :
28669 : : static void
28670 : 586029 : set_cur_line_info_table (section *sec)
28671 : : {
28672 : 586029 : dw_line_info_table *table;
28673 : :
28674 : 586029 : if (sec == text_section)
28675 : 375713 : table = text_section_line_info;
28676 : 210316 : else if (sec == cold_text_section)
28677 : : {
28678 : 11363 : table = cold_text_section_line_info;
28679 : 11363 : if (!table)
28680 : : {
28681 : 8633 : cold_text_section_line_info = table = new_line_info_table ();
28682 : 8633 : table->end_label = cold_end_label;
28683 : : }
28684 : : }
28685 : : else
28686 : : {
28687 : 198953 : const char *end_label;
28688 : :
28689 : 198953 : if (crtl->has_bb_partition)
28690 : : {
28691 : 25191 : if (in_cold_section_p)
28692 : 8995 : end_label = crtl->subsections.cold_section_end_label;
28693 : : else
28694 : 16196 : end_label = crtl->subsections.hot_section_end_label;
28695 : : }
28696 : : else
28697 : : {
28698 : 173762 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
28699 : 173762 : ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
28700 : : current_function_funcdef_no);
28701 : 173762 : end_label = ggc_strdup (label);
28702 : : }
28703 : :
28704 : 198953 : table = new_line_info_table ();
28705 : 198953 : table->end_label = end_label;
28706 : :
28707 : 198953 : vec_safe_push (separate_line_info, table);
28708 : : }
28709 : :
28710 : 586029 : if (output_asm_line_debug_info ())
28711 : 1171966 : table->is_stmt = (cur_line_info_table
28712 : 585983 : ? cur_line_info_table->is_stmt
28713 : : : DWARF_LINE_DEFAULT_IS_STMT_START);
28714 : 586029 : cur_line_info_table = table;
28715 : 586029 : }
28716 : :
28717 : :
28718 : : /* We need to reset the locations at the beginning of each
28719 : : function. We can't do this in the end_function hook, because the
28720 : : declarations that use the locations won't have been output when
28721 : : that hook is called. Also compute have_multiple_function_sections here. */
28722 : :
28723 : : static void
28724 : 557758 : dwarf2out_begin_function (tree fun)
28725 : : {
28726 : 557758 : section *sec = function_section (fun);
28727 : :
28728 : 557758 : if (sec != text_section)
28729 : 186651 : have_multiple_function_sections = true;
28730 : :
28731 : 557758 : if (crtl->has_bb_partition && !cold_text_section)
28732 : : {
28733 : 8633 : gcc_assert (current_function_decl == fun);
28734 : 8633 : cold_text_section = unlikely_text_section ();
28735 : 8633 : switch_to_section (cold_text_section);
28736 : 8633 : ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
28737 : 8633 : switch_to_section (sec);
28738 : : }
28739 : :
28740 : 557758 : call_site_count = 0;
28741 : 557758 : tail_call_site_count = 0;
28742 : :
28743 : 557758 : set_cur_line_info_table (sec);
28744 : 557758 : FORCE_RESET_NEXT_VIEW (cur_line_info_table->view);
28745 : 557758 : }
28746 : :
28747 : : /* Helper function of dwarf2out_end_function, called only after emitting
28748 : : the very first function into assembly. Check if some .debug_loc range
28749 : : might end with a .LVL* label that could be equal to .Ltext0.
28750 : : In that case we must force using absolute addresses in .debug_loc ranges,
28751 : : because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
28752 : : .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
28753 : : list terminator.
28754 : : Set have_multiple_function_sections to true in that case and
28755 : : terminate htab traversal. */
28756 : :
28757 : : int
28758 : 181858 : find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
28759 : : {
28760 : 181858 : var_loc_list *entry = *slot;
28761 : 181858 : struct var_loc_node *node;
28762 : :
28763 : 181858 : node = entry->first;
28764 : 181858 : if (node && node->next && node->next->label)
28765 : : {
28766 : : unsigned int i;
28767 : : const char *label = node->next->label;
28768 : : char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
28769 : :
28770 : 130510 : for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
28771 : : {
28772 : 75551 : ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
28773 : 75551 : if (strcmp (label, loclabel) == 0)
28774 : : {
28775 : 667 : have_multiple_function_sections = true;
28776 : 667 : return 0;
28777 : : }
28778 : : }
28779 : : }
28780 : : return 1;
28781 : : }
28782 : :
28783 : : /* Hook called after emitting a function into assembly.
28784 : : This does something only for the very first function emitted. */
28785 : :
28786 : : static void
28787 : 557758 : dwarf2out_end_function (unsigned int)
28788 : : {
28789 : 557758 : if (in_first_function_p
28790 : 46904 : && !have_multiple_function_sections
28791 : 27076 : && first_loclabel_num_not_at_text_label
28792 : 18959 : && decl_loc_table)
28793 : 200817 : decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
28794 : 557758 : in_first_function_p = false;
28795 : 557758 : maybe_at_text_label_p = false;
28796 : 557758 : }
28797 : :
28798 : : /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
28799 : : front-ends register a translation unit even before dwarf2out_init is
28800 : : called. */
28801 : : static tree main_translation_unit = NULL_TREE;
28802 : :
28803 : : /* Hook called by front-ends after they built their main translation unit.
28804 : : Associate comp_unit_die to UNIT. */
28805 : :
28806 : : static void
28807 : 45038 : dwarf2out_register_main_translation_unit (tree unit)
28808 : : {
28809 : 45038 : gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
28810 : : && main_translation_unit == NULL_TREE);
28811 : 45038 : main_translation_unit = unit;
28812 : : /* If dwarf2out_init has not been called yet, it will perform the association
28813 : : itself looking at main_translation_unit. */
28814 : 45038 : if (decl_die_table != NULL)
28815 : 26806 : equate_decl_number_to_die (unit, comp_unit_die ());
28816 : 45038 : }
28817 : :
28818 : : /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
28819 : :
28820 : : static void
28821 : 5754 : push_dw_line_info_entry (dw_line_info_table *table,
28822 : : enum dw_line_info_opcode opcode, unsigned int val)
28823 : : {
28824 : 5754 : dw_line_info_entry e;
28825 : 5754 : e.opcode = opcode;
28826 : 5754 : e.val = val;
28827 : 0 : vec_safe_push (table->entries, e);
28828 : 4212 : }
28829 : :
28830 : : /* Output a label to mark the beginning of a source code line entry
28831 : : and record information relating to this source line, in
28832 : : 'line_info_table' for later output of the .debug_line section. */
28833 : : /* ??? The discriminator parameter ought to be unsigned. */
28834 : :
28835 : : static void
28836 : 36475283 : dwarf2out_source_line (unsigned int line, unsigned int column,
28837 : : const char *filename,
28838 : : int discriminator, bool is_stmt)
28839 : : {
28840 : 36475283 : unsigned int file_num;
28841 : 36475283 : dw_line_info_table *table;
28842 : 36475283 : static var_loc_view lvugid;
28843 : :
28844 : : #ifdef CODEVIEW_DEBUGGING_INFO
28845 : : if (codeview_debuginfo_p ())
28846 : : codeview_source_line (line, filename);
28847 : : #endif
28848 : :
28849 : : /* 'line_info_table' information gathering is not needed when the debug
28850 : : info level is set to the lowest value. Also, the current DWARF-based
28851 : : debug formats do not use this info. */
28852 : 36475283 : if (debug_info_level < DINFO_LEVEL_TERSE || !dwarf_debuginfo_p ())
28853 : 1639 : return;
28854 : :
28855 : 36473644 : table = cur_line_info_table;
28856 : :
28857 : 36473644 : if (line == 0)
28858 : : {
28859 : 601877 : if (debug_variable_location_views
28860 : 563566 : && output_asm_line_debug_info ()
28861 : 1165443 : && table && !RESETTING_VIEW_P (table->view))
28862 : : {
28863 : : /* If we're using the assembler to compute view numbers, we
28864 : : can't issue a .loc directive for line zero, so we can't
28865 : : get a view number at this point. We might attempt to
28866 : : compute it from the previous view, or equate it to a
28867 : : subsequent view (though it might not be there!), but
28868 : : since we're omitting the line number entry, we might as
28869 : : well omit the view number as well. That means pretending
28870 : : it's a view number zero, which might very well turn out
28871 : : to be correct. ??? Extend the assembler so that the
28872 : : compiler could emit e.g. ".locview .LVU#", to output a
28873 : : view without changing line number information. We'd then
28874 : : have to count it in symviews_since_reset; when it's omitted,
28875 : : it doesn't count. */
28876 : 3832 : if (!zero_view_p)
28877 : 0 : zero_view_p = BITMAP_GGC_ALLOC ();
28878 : 3832 : bitmap_set_bit (zero_view_p, table->view);
28879 : 3832 : if (flag_debug_asm)
28880 : : {
28881 : 0 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
28882 : 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
28883 : 0 : fprintf (asm_out_file, "\t%s line 0, omitted view ",
28884 : : ASM_COMMENT_START);
28885 : 0 : assemble_name (asm_out_file, label);
28886 : 0 : putc ('\n', asm_out_file);
28887 : : }
28888 : 3832 : table->view = ++lvugid;
28889 : : }
28890 : 601877 : return;
28891 : : }
28892 : :
28893 : : /* The discriminator column was added in dwarf4. Simplify the below
28894 : : by simply removing it if we're not supposed to output it. */
28895 : 35871767 : if (dwarf_version < 4 && dwarf_strict)
28896 : 35871767 : discriminator = 0;
28897 : :
28898 : 35871767 : if (!debug_column_info)
28899 : 66 : column = 0;
28900 : :
28901 : 35871767 : file_num = maybe_emit_file (lookup_filename (filename));
28902 : :
28903 : : /* ??? TODO: Elide duplicate line number entries. Traditionally,
28904 : : the debugger has used the second (possibly duplicate) line number
28905 : : at the beginning of the function to mark the end of the prologue.
28906 : : We could eliminate any other duplicates within the function. For
28907 : : Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
28908 : : that second line number entry. */
28909 : : /* Recall that this end-of-prologue indication is *not* the same thing
28910 : : as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
28911 : : to which the hook corresponds, follows the last insn that was
28912 : : emitted by gen_prologue. What we need is to precede the first insn
28913 : : that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
28914 : : insn that corresponds to something the user wrote. These may be
28915 : : very different locations once scheduling is enabled. */
28916 : :
28917 : 35871767 : if (0 && file_num == table->file_num
28918 : : && line == table->line_num
28919 : : && column == table->column_num
28920 : : && discriminator == table->discrim_num
28921 : : && is_stmt == table->is_stmt)
28922 : : return;
28923 : :
28924 : 35871767 : switch_to_section (current_function_section ());
28925 : :
28926 : : /* If requested, emit something human-readable. */
28927 : 35871767 : if (flag_debug_asm)
28928 : : {
28929 : 6517 : if (debug_column_info)
28930 : 6475 : fprintf (asm_out_file, "\t%s %s:%d:%d\n", ASM_COMMENT_START,
28931 : : filename, line, column);
28932 : : else
28933 : 42 : fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
28934 : : filename, line);
28935 : : }
28936 : :
28937 : 35871767 : if (output_asm_line_debug_info ())
28938 : : {
28939 : : /* Emit the .loc directive understood by GNU as. */
28940 : : /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
28941 : : file_num, line, is_stmt, discriminator */
28942 : 35870225 : fputs ("\t.loc ", asm_out_file);
28943 : 35870225 : fprint_ul (asm_out_file, file_num);
28944 : 35870225 : putc (' ', asm_out_file);
28945 : 35870225 : fprint_ul (asm_out_file, line);
28946 : 35870225 : putc (' ', asm_out_file);
28947 : 35870225 : fprint_ul (asm_out_file, column);
28948 : :
28949 : 35870225 : if (is_stmt != table->is_stmt)
28950 : : {
28951 : : #if HAVE_GAS_LOC_STMT
28952 : 13710855 : fputs (" is_stmt ", asm_out_file);
28953 : 20581296 : putc (is_stmt ? '1' : '0', asm_out_file);
28954 : : #endif
28955 : : }
28956 : 35870225 : if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
28957 : : {
28958 : 8403163 : gcc_assert (discriminator > 0);
28959 : 8403163 : fputs (" discriminator ", asm_out_file);
28960 : 8403163 : fprint_ul (asm_out_file, (unsigned long) discriminator);
28961 : : }
28962 : 35870225 : if (debug_variable_location_views)
28963 : : {
28964 : 35059792 : if (!RESETTING_VIEW_P (table->view))
28965 : : {
28966 : 34626022 : table->symviews_since_reset++;
28967 : 34626022 : if (table->symviews_since_reset > symview_upper_bound)
28968 : 6874407 : symview_upper_bound = table->symviews_since_reset;
28969 : : /* When we're using the assembler to compute view
28970 : : numbers, we output symbolic labels after "view" in
28971 : : .loc directives, and the assembler will set them for
28972 : : us, so that we can refer to the view numbers in
28973 : : location lists. The only exceptions are when we know
28974 : : a view will be zero: "-0" is a forced reset, used
28975 : : e.g. in the beginning of functions, whereas "0" tells
28976 : : the assembler to check that there was a PC change
28977 : : since the previous view, in a way that implicitly
28978 : : resets the next view. */
28979 : 34626022 : fputs (" view ", asm_out_file);
28980 : 34626022 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
28981 : 34626022 : ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
28982 : 34626022 : assemble_name (asm_out_file, label);
28983 : 34626022 : table->view = ++lvugid;
28984 : : }
28985 : : else
28986 : : {
28987 : 433770 : table->symviews_since_reset = 0;
28988 : 433770 : if (FORCE_RESETTING_VIEW_P (table->view))
28989 : 433770 : fputs (" view -0", asm_out_file);
28990 : : else
28991 : 0 : fputs (" view 0", asm_out_file);
28992 : : /* Mark the present view as a zero view. Earlier debug
28993 : : binds may have already added its id to loclists to be
28994 : : emitted later, so we can't reuse the id for something
28995 : : else. However, it's good to know whether a view is
28996 : : known to be zero, because then we may be able to
28997 : : optimize out locviews that are all zeros, so take
28998 : : note of it in zero_view_p. */
28999 : 433770 : if (!zero_view_p)
29000 : 40587 : zero_view_p = BITMAP_GGC_ALLOC ();
29001 : 433770 : bitmap_set_bit (zero_view_p, lvugid);
29002 : 433770 : table->view = ++lvugid;
29003 : : }
29004 : : }
29005 : 35870225 : putc ('\n', asm_out_file);
29006 : : }
29007 : : else
29008 : : {
29009 : 1542 : unsigned int label_num = ++line_info_label_num;
29010 : :
29011 : 1542 : targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
29012 : :
29013 : 1542 : if (debug_variable_location_views && !RESETTING_VIEW_P (table->view))
29014 : 1454 : push_dw_line_info_entry (table, LI_adv_address, label_num);
29015 : : else
29016 : 88 : push_dw_line_info_entry (table, LI_set_address, label_num);
29017 : 1542 : if (debug_variable_location_views)
29018 : : {
29019 : 1488 : bool resetting = FORCE_RESETTING_VIEW_P (table->view);
29020 : 1488 : if (resetting)
29021 : 34 : table->view = 0;
29022 : :
29023 : 1488 : if (flag_debug_asm)
29024 : 88 : fprintf (asm_out_file, "\t%s view %s%d\n",
29025 : : ASM_COMMENT_START,
29026 : : resetting ? "-" : "",
29027 : : table->view);
29028 : :
29029 : 1488 : table->view++;
29030 : : }
29031 : 1542 : if (file_num != table->file_num)
29032 : 290 : push_dw_line_info_entry (table, LI_set_file, file_num);
29033 : 1542 : if (discriminator != table->discrim_num)
29034 : 265 : push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
29035 : 1542 : if (is_stmt != table->is_stmt)
29036 : 573 : push_dw_line_info_entry (table, LI_negate_stmt, 0);
29037 : 1542 : push_dw_line_info_entry (table, LI_set_line, line);
29038 : 1542 : if (debug_column_info)
29039 : 1542 : push_dw_line_info_entry (table, LI_set_column, column);
29040 : : }
29041 : :
29042 : 35871767 : table->file_num = file_num;
29043 : 35871767 : table->line_num = line;
29044 : 35871767 : table->column_num = column;
29045 : 35871767 : table->discrim_num = discriminator;
29046 : 35871767 : table->is_stmt = is_stmt;
29047 : 35871767 : table->in_use = true;
29048 : : }
29049 : :
29050 : : /* Record a source file location for a DECL_IGNORED_P function. */
29051 : :
29052 : : static void
29053 : 8009 : dwarf2out_set_ignored_loc (unsigned int line, unsigned int column,
29054 : : const char *filename)
29055 : : {
29056 : 8009 : dw_fde_ref fde = cfun->fde;
29057 : :
29058 : 8009 : fde->ignored_debug = false;
29059 : 8009 : set_cur_line_info_table (current_function_section ());
29060 : :
29061 : 8009 : dwarf2out_source_line (line, column, filename, 0, true);
29062 : 8009 : }
29063 : :
29064 : : /* Record the beginning of a new source file. */
29065 : :
29066 : : static void
29067 : 7064309 : dwarf2out_start_source_file (unsigned int lineno, const char *filename)
29068 : : {
29069 : : #ifdef CODEVIEW_DEBUGGING_INFO
29070 : : if (codeview_debuginfo_p ())
29071 : : codeview_start_source_file (filename);
29072 : : #endif
29073 : :
29074 : 7064309 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29075 : : {
29076 : 1801 : macinfo_entry e;
29077 : 1801 : e.code = DW_MACINFO_start_file;
29078 : 1801 : e.lineno = lineno;
29079 : 1801 : e.info = ggc_strdup (filename);
29080 : 1801 : vec_safe_push (macinfo_table, e);
29081 : : }
29082 : 7064309 : }
29083 : :
29084 : : /* Record the end of a source file. */
29085 : :
29086 : : static void
29087 : 7064197 : dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
29088 : : {
29089 : 7064197 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29090 : : {
29091 : 1801 : macinfo_entry e;
29092 : 1801 : e.code = DW_MACINFO_end_file;
29093 : 1801 : e.lineno = lineno;
29094 : 1801 : e.info = NULL;
29095 : 1801 : vec_safe_push (macinfo_table, e);
29096 : : }
29097 : 7064197 : }
29098 : :
29099 : : /* Called from debug_define in toplev.cc. The `buffer' parameter contains
29100 : : the tail part of the directive line, i.e. the part which is past the
29101 : : initial whitespace, #, whitespace, directive-name, whitespace part. */
29102 : :
29103 : : static void
29104 : 236030 : dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
29105 : : const char *buffer ATTRIBUTE_UNUSED)
29106 : : {
29107 : 236030 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29108 : : {
29109 : 236030 : macinfo_entry e;
29110 : : /* Insert a dummy first entry to be able to optimize the whole
29111 : : predefined macro block using DW_MACRO_import. */
29112 : 236030 : if (macinfo_table->is_empty () && lineno <= 1)
29113 : : {
29114 : 519 : e.code = 0;
29115 : 519 : e.lineno = 0;
29116 : 519 : e.info = NULL;
29117 : 519 : vec_safe_push (macinfo_table, e);
29118 : : }
29119 : 236030 : e.code = DW_MACINFO_define;
29120 : 236030 : e.lineno = lineno;
29121 : 236030 : e.info = ggc_strdup (buffer);
29122 : 236030 : vec_safe_push (macinfo_table, e);
29123 : : }
29124 : 236030 : }
29125 : :
29126 : : /* Called from debug_undef in toplev.cc. The `buffer' parameter contains
29127 : : the tail part of the directive line, i.e. the part which is past the
29128 : : initial whitespace, #, whitespace, directive-name, whitespace part. */
29129 : :
29130 : : static void
29131 : 627 : dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
29132 : : const char *buffer ATTRIBUTE_UNUSED)
29133 : : {
29134 : 627 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29135 : : {
29136 : 627 : macinfo_entry e;
29137 : : /* Insert a dummy first entry to be able to optimize the whole
29138 : : predefined macro block using DW_MACRO_import. */
29139 : 627 : if (macinfo_table->is_empty () && lineno <= 1)
29140 : : {
29141 : 0 : e.code = 0;
29142 : 0 : e.lineno = 0;
29143 : 0 : e.info = NULL;
29144 : 0 : vec_safe_push (macinfo_table, e);
29145 : : }
29146 : 627 : e.code = DW_MACINFO_undef;
29147 : 627 : e.lineno = lineno;
29148 : 627 : e.info = ggc_strdup (buffer);
29149 : 627 : vec_safe_push (macinfo_table, e);
29150 : : }
29151 : 627 : }
29152 : :
29153 : : /* Helpers to manipulate hash table of CUs. */
29154 : :
29155 : : struct macinfo_entry_hasher : nofree_ptr_hash <macinfo_entry>
29156 : : {
29157 : : static inline hashval_t hash (const macinfo_entry *);
29158 : : static inline bool equal (const macinfo_entry *, const macinfo_entry *);
29159 : : };
29160 : :
29161 : : inline hashval_t
29162 : 6534 : macinfo_entry_hasher::hash (const macinfo_entry *entry)
29163 : : {
29164 : 6534 : return htab_hash_string (entry->info);
29165 : : }
29166 : :
29167 : : inline bool
29168 : 5089 : macinfo_entry_hasher::equal (const macinfo_entry *entry1,
29169 : : const macinfo_entry *entry2)
29170 : : {
29171 : 5089 : return !strcmp (entry1->info, entry2->info);
29172 : : }
29173 : :
29174 : : typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
29175 : :
29176 : : /* Output a single .debug_macinfo entry. */
29177 : :
29178 : : static void
29179 : 239831 : output_macinfo_op (macinfo_entry *ref)
29180 : : {
29181 : 474478 : int file_num;
29182 : 474478 : size_t len;
29183 : 474478 : struct indirect_string_node *node;
29184 : 474478 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29185 : 474478 : struct dwarf_file_data *fd;
29186 : :
29187 : 474478 : switch (ref->code)
29188 : : {
29189 : 1795 : case DW_MACINFO_start_file:
29190 : 1795 : fd = lookup_filename (ref->info);
29191 : 1795 : file_num = maybe_emit_file (fd);
29192 : 1795 : dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
29193 : 1795 : dw2_asm_output_data_uleb128 (ref->lineno,
29194 : : "Included from line number "
29195 : : HOST_WIDE_INT_PRINT_UNSIGNED,
29196 : : ref->lineno);
29197 : 1795 : dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
29198 : 1795 : break;
29199 : 1795 : case DW_MACINFO_end_file:
29200 : 1795 : dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
29201 : 1795 : break;
29202 : 234657 : case DW_MACINFO_define:
29203 : 234657 : case DW_MACINFO_undef:
29204 : 234657 : len = strlen (ref->info) + 1;
29205 : 234657 : if ((!dwarf_strict || dwarf_version >= 5)
29206 : 234657 : && len > (size_t) dwarf_offset_size
29207 : : && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29208 : 234647 : && (debug_str_section->common.flags & SECTION_MERGE) != 0)
29209 : : {
29210 : 234647 : if (dwarf_split_debug_info)
29211 : 1671 : ref->code = ref->code == DW_MACINFO_define
29212 : : ? DW_MACRO_define_strx : DW_MACRO_undef_strx;
29213 : : else
29214 : 233432 : ref->code = ref->code == DW_MACINFO_define
29215 : : ? DW_MACRO_define_strp : DW_MACRO_undef_strp;
29216 : 234647 : output_macinfo_op (ref);
29217 : : return;
29218 : : }
29219 : 18 : dw2_asm_output_data (1, ref->code,
29220 : : ref->code == DW_MACINFO_define
29221 : : ? "Define macro" : "Undefine macro");
29222 : 10 : dw2_asm_output_data_uleb128 (ref->lineno,
29223 : : "At line number "
29224 : : HOST_WIDE_INT_PRINT_UNSIGNED,
29225 : : ref->lineno);
29226 : 10 : dw2_asm_output_nstring (ref->info, -1, "The macro");
29227 : 10 : break;
29228 : 232520 : case DW_MACRO_define_strp:
29229 : 232520 : dw2_asm_output_data (1, ref->code, "Define macro strp");
29230 : 232520 : goto do_DW_MACRO_define_strpx;
29231 : 456 : case DW_MACRO_undef_strp:
29232 : 456 : dw2_asm_output_data (1, ref->code, "Undefine macro strp");
29233 : 456 : goto do_DW_MACRO_define_strpx;
29234 : 1671 : case DW_MACRO_define_strx:
29235 : 1671 : dw2_asm_output_data (1, ref->code, "Define macro strx");
29236 : 1671 : goto do_DW_MACRO_define_strpx;
29237 : 0 : case DW_MACRO_undef_strx:
29238 : 0 : dw2_asm_output_data (1, ref->code, "Undefine macro strx");
29239 : : /* FALLTHRU */
29240 : 234647 : do_DW_MACRO_define_strpx:
29241 : : /* NB: dwarf2out_finish performs:
29242 : : 1. save_macinfo_strings
29243 : : 2. hash table traverse of index_string
29244 : : 3. output_macinfo -> output_macinfo_op
29245 : : 4. output_indirect_strings
29246 : : -> hash table traverse of output_index_string
29247 : :
29248 : : When output_macinfo_op is called, all index strings have been
29249 : : added to hash table by save_macinfo_strings and we can't pass
29250 : : INSERT to find_slot_with_hash which may expand hash table, even
29251 : : if no insertion is needed, and change hash table traverse order
29252 : : between index_string and output_index_string. */
29253 : 234647 : node = find_AT_string (ref->info, NO_INSERT);
29254 : 235056 : gcc_assert (node
29255 : : && (node->form == DW_FORM_strp
29256 : : || node->form == dwarf_FORM (DW_FORM_strx)));
29257 : 234647 : dw2_asm_output_data_uleb128 (ref->lineno,
29258 : : "At line number "
29259 : : HOST_WIDE_INT_PRINT_UNSIGNED,
29260 : : ref->lineno);
29261 : 234647 : if (node->form == DW_FORM_strp)
29262 : : {
29263 : 232976 : gcc_assert (ref->code == DW_MACRO_define_strp
29264 : : || ref->code == DW_MACRO_undef_strp);
29265 : 232976 : dw2_asm_output_offset (dwarf_offset_size, node->label,
29266 : : debug_str_section, "The macro: \"%s\"",
29267 : : ref->info);
29268 : : }
29269 : : else
29270 : : {
29271 : 1671 : gcc_assert (ref->code == DW_MACRO_define_strx
29272 : : || ref->code == DW_MACRO_undef_strx);
29273 : 1671 : dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
29274 : : ref->info);
29275 : : }
29276 : : break;
29277 : 1584 : case DW_MACRO_import:
29278 : 1584 : dw2_asm_output_data (1, ref->code, "Import");
29279 : 1584 : ASM_GENERATE_INTERNAL_LABEL (label,
29280 : : DEBUG_MACRO_SECTION_LABEL,
29281 : : ref->lineno + macinfo_label_base);
29282 : 1584 : dw2_asm_output_offset (dwarf_offset_size, label, NULL, NULL);
29283 : 1584 : break;
29284 : 0 : default:
29285 : 0 : fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
29286 : : ASM_COMMENT_START, (unsigned long) ref->code);
29287 : 0 : break;
29288 : : }
29289 : : }
29290 : :
29291 : : /* Attempt to make a sequence of define/undef macinfo ops shareable with
29292 : : other compilation unit .debug_macinfo sections. IDX is the first
29293 : : index of a define/undef, return the number of ops that should be
29294 : : emitted in a comdat .debug_macinfo section and emit
29295 : : a DW_MACRO_import entry referencing it.
29296 : : If the define/undef entry should be emitted normally, return 0. */
29297 : :
29298 : : static unsigned
29299 : 1950 : optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
29300 : : macinfo_hash_type **macinfo_htab)
29301 : : {
29302 : 1950 : macinfo_entry *first, *second, *cur, *inc;
29303 : 1950 : char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
29304 : 1950 : unsigned char checksum[16];
29305 : 1950 : struct md5_ctx ctx;
29306 : 1950 : char *grp_name, *tail;
29307 : 1950 : const char *base;
29308 : 1950 : unsigned int i, count, encoded_filename_len, linebuf_len;
29309 : 1950 : macinfo_entry **slot;
29310 : :
29311 : 1950 : first = &(*macinfo_table)[idx];
29312 : 1950 : second = &(*macinfo_table)[idx + 1];
29313 : :
29314 : : /* Optimize only if there are at least two consecutive define/undef ops,
29315 : : and either all of them are before first DW_MACINFO_start_file
29316 : : with lineno {0,1} (i.e. predefined macro block), or all of them are
29317 : : in some included header file. */
29318 : 1950 : if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
29319 : : return 0;
29320 : 1584 : if (vec_safe_is_empty (files))
29321 : : {
29322 : 512 : if (first->lineno > 1 || second->lineno > 1)
29323 : : return 0;
29324 : : }
29325 : 1072 : else if (first->lineno == 0)
29326 : : return 0;
29327 : :
29328 : : /* Find the last define/undef entry that can be grouped together
29329 : : with first and at the same time compute md5 checksum of their
29330 : : codes, linenumbers and strings. */
29331 : 1584 : md5_init_ctx (&ctx);
29332 : 234539 : for (i = idx; macinfo_table->iterate (i, &cur); i++)
29333 : 234539 : if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
29334 : : break;
29335 : 232955 : else if (vec_safe_is_empty (files) && cur->lineno > 1)
29336 : : break;
29337 : : else
29338 : : {
29339 : 232955 : unsigned char code = cur->code;
29340 : 232955 : md5_process_bytes (&code, 1, &ctx);
29341 : 232955 : checksum_uleb128 (cur->lineno, &ctx);
29342 : 232955 : md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
29343 : : }
29344 : 1584 : md5_finish_ctx (&ctx, checksum);
29345 : 1584 : count = i - idx;
29346 : :
29347 : : /* From the containing include filename (if any) pick up just
29348 : : usable characters from its basename. */
29349 : 1584 : if (vec_safe_is_empty (files))
29350 : : base = "";
29351 : : else
29352 : 1072 : base = lbasename (files->last ().info);
29353 : 13852 : for (encoded_filename_len = 0, i = 0; base[i]; i++)
29354 : 12268 : if (ISIDNUM (base[i]) || base[i] == '.')
29355 : 11660 : encoded_filename_len++;
29356 : : /* Count . at the end. */
29357 : 1584 : if (encoded_filename_len)
29358 : 1072 : encoded_filename_len++;
29359 : :
29360 : 1584 : sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
29361 : 1584 : linebuf_len = strlen (linebuf);
29362 : :
29363 : : /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
29364 : 1584 : grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
29365 : : + 16 * 2 + 1);
29366 : 1584 : memcpy (grp_name, dwarf_offset_size == 4 ? "wm4." : "wm8.", 4);
29367 : 1584 : tail = grp_name + 4;
29368 : 1584 : if (encoded_filename_len)
29369 : : {
29370 : 13340 : for (i = 0; base[i]; i++)
29371 : 12268 : if (ISIDNUM (base[i]) || base[i] == '.')
29372 : 11660 : *tail++ = base[i];
29373 : 1072 : *tail++ = '.';
29374 : : }
29375 : 1584 : memcpy (tail, linebuf, linebuf_len);
29376 : 1584 : tail += linebuf_len;
29377 : 1584 : *tail++ = '.';
29378 : 26928 : for (i = 0; i < 16; i++)
29379 : 25344 : sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
29380 : :
29381 : : /* Construct a macinfo_entry for DW_MACRO_import
29382 : : in the empty vector entry before the first define/undef. */
29383 : 1584 : inc = &(*macinfo_table)[idx - 1];
29384 : 1584 : inc->code = DW_MACRO_import;
29385 : 1584 : inc->lineno = 0;
29386 : 1584 : inc->info = ggc_strdup (grp_name);
29387 : 1584 : if (!*macinfo_htab)
29388 : 513 : *macinfo_htab = new macinfo_hash_type (10);
29389 : : /* Avoid emitting duplicates. */
29390 : 1584 : slot = (*macinfo_htab)->find_slot (inc, INSERT);
29391 : 1584 : if (*slot != NULL)
29392 : : {
29393 : 97 : inc->code = 0;
29394 : 97 : inc->info = NULL;
29395 : : /* If such an entry has been used before, just emit
29396 : : a DW_MACRO_import op. */
29397 : 97 : inc = *slot;
29398 : 97 : output_macinfo_op (inc);
29399 : : /* And clear all macinfo_entry in the range to avoid emitting them
29400 : : in the second pass. */
29401 : 610 : for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
29402 : : {
29403 : 416 : cur->code = 0;
29404 : 416 : cur->info = NULL;
29405 : : }
29406 : : }
29407 : : else
29408 : : {
29409 : 1487 : *slot = inc;
29410 : 1487 : inc->lineno = (*macinfo_htab)->elements ();
29411 : 1487 : output_macinfo_op (inc);
29412 : : }
29413 : : return count;
29414 : : }
29415 : :
29416 : : /* Save any strings needed by the macinfo table in the debug str
29417 : : table. All strings must be collected into the table by the time
29418 : : index_string is called. */
29419 : :
29420 : : static void
29421 : 53297 : save_macinfo_strings (void)
29422 : : {
29423 : 53297 : unsigned len;
29424 : 53297 : unsigned i;
29425 : 53297 : macinfo_entry *ref;
29426 : :
29427 : 292476 : for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
29428 : : {
29429 : 239179 : switch (ref->code)
29430 : : {
29431 : : /* Match the logic in output_macinfo_op to decide on
29432 : : indirect strings. */
29433 : 235073 : case DW_MACINFO_define:
29434 : 235073 : case DW_MACINFO_undef:
29435 : 235073 : len = strlen (ref->info) + 1;
29436 : 235073 : if ((!dwarf_strict || dwarf_version >= 5)
29437 : 235073 : && len > (unsigned) dwarf_offset_size
29438 : : && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
29439 : 235062 : && (debug_str_section->common.flags & SECTION_MERGE) != 0)
29440 : 235062 : set_indirect_string (find_AT_string (ref->info));
29441 : : break;
29442 : 1795 : case DW_MACINFO_start_file:
29443 : : /* -gsplit-dwarf -g3 will also output filename as indirect
29444 : : string. */
29445 : 1795 : if (!dwarf_split_debug_info)
29446 : : break;
29447 : : /* Fall through. */
29448 : 8 : case DW_MACRO_define_strp:
29449 : 8 : case DW_MACRO_undef_strp:
29450 : 8 : case DW_MACRO_define_strx:
29451 : 8 : case DW_MACRO_undef_strx:
29452 : 8 : set_indirect_string (find_AT_string (ref->info));
29453 : 8 : break;
29454 : : default:
29455 : : break;
29456 : : }
29457 : : }
29458 : 53297 : }
29459 : :
29460 : : /* Output macinfo section(s). */
29461 : :
29462 : : static void
29463 : 525 : output_macinfo (const char *debug_line_label, bool early_lto_debug)
29464 : : {
29465 : 525 : unsigned i;
29466 : 525 : unsigned long length = vec_safe_length (macinfo_table);
29467 : 525 : macinfo_entry *ref;
29468 : 525 : vec<macinfo_entry, va_gc> *files = NULL;
29469 : 525 : macinfo_hash_type *macinfo_htab = NULL;
29470 : 525 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
29471 : :
29472 : 525 : if (! length)
29473 : 12 : return;
29474 : :
29475 : : /* output_macinfo* uses these interchangeably. */
29476 : 525 : gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_define
29477 : : && (int) DW_MACINFO_undef == (int) DW_MACRO_undef
29478 : : && (int) DW_MACINFO_start_file == (int) DW_MACRO_start_file
29479 : : && (int) DW_MACINFO_end_file == (int) DW_MACRO_end_file);
29480 : :
29481 : : /* AIX Assembler inserts the length, so adjust the reference to match the
29482 : : offset expected by debuggers. */
29483 : 525 : strcpy (dl_section_ref, debug_line_label);
29484 : 525 : if (XCOFF_DEBUGGING_INFO)
29485 : : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
29486 : :
29487 : : /* For .debug_macro emit the section header. */
29488 : 525 : if (!dwarf_strict || dwarf_version >= 5)
29489 : : {
29490 : 1030 : dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
29491 : : "DWARF macro version number");
29492 : 525 : if (dwarf_offset_size == 8)
29493 : 0 : dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
29494 : : else
29495 : 525 : dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
29496 : 525 : dw2_asm_output_offset (dwarf_offset_size, debug_line_label,
29497 : : debug_line_section, NULL);
29498 : : }
29499 : :
29500 : : /* In the first loop, it emits the primary .debug_macinfo section
29501 : : and after each emitted op the macinfo_entry is cleared.
29502 : : If a longer range of define/undef ops can be optimized using
29503 : : DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
29504 : : the vector before the first define/undef in the range and the
29505 : : whole range of define/undef ops is not emitted and kept. */
29506 : 8333 : for (i = 0; macinfo_table->iterate (i, &ref); i++)
29507 : : {
29508 : 7808 : switch (ref->code)
29509 : : {
29510 : 1795 : case DW_MACINFO_start_file:
29511 : 1795 : vec_safe_push (files, *ref);
29512 : 1795 : break;
29513 : 1795 : case DW_MACINFO_end_file:
29514 : 1795 : if (!vec_safe_is_empty (files))
29515 : 1795 : files->pop ();
29516 : : break;
29517 : 3702 : case DW_MACINFO_define:
29518 : 3702 : case DW_MACINFO_undef:
29519 : 0 : if ((!dwarf_strict || dwarf_version >= 5)
29520 : 3702 : && !dwarf_split_debug_info
29521 : : && HAVE_COMDAT_GROUP
29522 : 2031 : && vec_safe_length (files) != 1
29523 : 1950 : && i > 0
29524 : 1950 : && i + 1 < length
29525 : 5652 : && (*macinfo_table)[i - 1].code == 0)
29526 : : {
29527 : 1950 : unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
29528 : 1950 : if (count)
29529 : : {
29530 : 1584 : i += count - 1;
29531 : 1584 : continue;
29532 : : }
29533 : : }
29534 : : break;
29535 : 516 : case 0:
29536 : : /* A dummy entry may be inserted at the beginning to be able
29537 : : to optimize the whole block of predefined macros. */
29538 : 516 : if (i == 0)
29539 : 516 : continue;
29540 : : default:
29541 : : break;
29542 : : }
29543 : 5708 : output_macinfo_op (ref);
29544 : 5708 : ref->info = NULL;
29545 : 5708 : ref->code = 0;
29546 : : }
29547 : :
29548 : 525 : if (!macinfo_htab)
29549 : : return;
29550 : :
29551 : : /* Save the number of transparent includes so we can adjust the
29552 : : label number for the fat LTO object DWARF. */
29553 : 513 : unsigned macinfo_label_base_adj = macinfo_htab->elements ();
29554 : :
29555 : 513 : delete macinfo_htab;
29556 : 513 : macinfo_htab = NULL;
29557 : :
29558 : : /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
29559 : : terminate the current chain and switch to a new comdat .debug_macinfo
29560 : : section and emit the define/undef entries within it. */
29561 : 237953 : for (i = 0; macinfo_table->iterate (i, &ref); i++)
29562 : 237440 : switch (ref->code)
29563 : : {
29564 : 3414 : case 0:
29565 : 3414 : continue;
29566 : 1487 : case DW_MACRO_import:
29567 : 1487 : {
29568 : 1487 : char label[MAX_ARTIFICIAL_LABEL_BYTES];
29569 : 1487 : tree comdat_key = get_identifier (ref->info);
29570 : : /* Terminate the previous .debug_macinfo section. */
29571 : 1487 : dw2_asm_output_data (1, 0, "End compilation unit");
29572 : 2944 : targetm.asm_out.named_section (debug_macinfo_section_name,
29573 : : SECTION_DEBUG
29574 : : | SECTION_LINKONCE
29575 : : | (early_lto_debug
29576 : : ? SECTION_EXCLUDE : 0),
29577 : : comdat_key);
29578 : 1487 : ASM_GENERATE_INTERNAL_LABEL (label,
29579 : : DEBUG_MACRO_SECTION_LABEL,
29580 : : ref->lineno + macinfo_label_base);
29581 : 1487 : ASM_OUTPUT_LABEL (asm_out_file, label);
29582 : 1487 : ref->code = 0;
29583 : 1487 : ref->info = NULL;
29584 : 2485 : dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
29585 : : "DWARF macro version number");
29586 : 1487 : if (dwarf_offset_size == 8)
29587 : 0 : dw2_asm_output_data (1, 1, "Flags: 64-bit");
29588 : : else
29589 : 1487 : dw2_asm_output_data (1, 0, "Flags: 32-bit");
29590 : : }
29591 : 1487 : break;
29592 : 232539 : case DW_MACINFO_define:
29593 : 232539 : case DW_MACINFO_undef:
29594 : 232539 : output_macinfo_op (ref);
29595 : 232539 : ref->code = 0;
29596 : 232539 : ref->info = NULL;
29597 : 232539 : break;
29598 : 0 : default:
29599 : 0 : gcc_unreachable ();
29600 : 3414 : }
29601 : :
29602 : 513 : macinfo_label_base += macinfo_label_base_adj;
29603 : : }
29604 : :
29605 : : /* As init_sections_and_labels may get called multiple times, have a
29606 : : generation count for labels. */
29607 : : static unsigned init_sections_and_labels_generation;
29608 : :
29609 : : /* Initialize the various sections and labels for dwarf output and prefix
29610 : : them with PREFIX if non-NULL. Returns the generation (zero based
29611 : : number of times function was called). */
29612 : :
29613 : : static unsigned
29614 : 53297 : init_sections_and_labels (bool early_lto_debug)
29615 : : {
29616 : 53297 : if (early_lto_debug)
29617 : : {
29618 : 1323 : if (!dwarf_split_debug_info)
29619 : : {
29620 : 1323 : debug_info_section = get_section (DEBUG_LTO_INFO_SECTION,
29621 : : SECTION_DEBUG | SECTION_EXCLUDE,
29622 : : NULL);
29623 : 1323 : debug_abbrev_section = get_section (DEBUG_LTO_ABBREV_SECTION,
29624 : : SECTION_DEBUG | SECTION_EXCLUDE,
29625 : : NULL);
29626 : 1323 : debug_macinfo_section_name
29627 : 0 : = ((dwarf_strict && dwarf_version < 5)
29628 : 1323 : ? DEBUG_LTO_MACINFO_SECTION : DEBUG_LTO_MACRO_SECTION);
29629 : 1323 : debug_macinfo_section = get_section (debug_macinfo_section_name,
29630 : : SECTION_DEBUG
29631 : : | SECTION_EXCLUDE, NULL);
29632 : : }
29633 : : else
29634 : : {
29635 : : /* ??? Which of the following do we need early? */
29636 : 0 : debug_info_section = get_section (DEBUG_LTO_DWO_INFO_SECTION,
29637 : : SECTION_DEBUG | SECTION_EXCLUDE,
29638 : : NULL);
29639 : 0 : debug_abbrev_section = get_section (DEBUG_LTO_DWO_ABBREV_SECTION,
29640 : : SECTION_DEBUG | SECTION_EXCLUDE,
29641 : : NULL);
29642 : 0 : debug_skeleton_info_section = get_section (DEBUG_LTO_INFO_SECTION,
29643 : : SECTION_DEBUG
29644 : : | SECTION_EXCLUDE, NULL);
29645 : 0 : debug_skeleton_abbrev_section
29646 : 0 : = get_section (DEBUG_LTO_ABBREV_SECTION,
29647 : : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29648 : 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
29649 : : DEBUG_SKELETON_ABBREV_SECTION_LABEL,
29650 : : init_sections_and_labels_generation);
29651 : :
29652 : : /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29653 : : stay in the main .o, but the skeleton_line goes into the split
29654 : : off dwo. */
29655 : 0 : debug_skeleton_line_section
29656 : 0 : = get_section (DEBUG_LTO_LINE_SECTION,
29657 : : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29658 : 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
29659 : : DEBUG_SKELETON_LINE_SECTION_LABEL,
29660 : : init_sections_and_labels_generation);
29661 : 0 : debug_str_offsets_section
29662 : 0 : = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION,
29663 : : SECTION_DEBUG | SECTION_EXCLUDE,
29664 : : NULL);
29665 : 0 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
29666 : : DEBUG_SKELETON_INFO_SECTION_LABEL,
29667 : : init_sections_and_labels_generation);
29668 : 0 : debug_str_dwo_section = get_section (DEBUG_LTO_STR_DWO_SECTION,
29669 : : DEBUG_STR_DWO_SECTION_FLAGS,
29670 : : NULL);
29671 : 0 : debug_macinfo_section_name
29672 : 0 : = ((dwarf_strict && dwarf_version < 5)
29673 : 0 : ? DEBUG_LTO_DWO_MACINFO_SECTION : DEBUG_LTO_DWO_MACRO_SECTION);
29674 : 0 : debug_macinfo_section = get_section (debug_macinfo_section_name,
29675 : : SECTION_DEBUG | SECTION_EXCLUDE,
29676 : : NULL);
29677 : : }
29678 : : /* For macro info and the file table we have to refer to a
29679 : : debug_line section. */
29680 : 1323 : debug_line_section = get_section (DEBUG_LTO_LINE_SECTION,
29681 : : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29682 : 1323 : ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
29683 : : DEBUG_LINE_SECTION_LABEL,
29684 : : init_sections_and_labels_generation);
29685 : :
29686 : 1323 : debug_str_section = get_section (DEBUG_LTO_STR_SECTION,
29687 : 1323 : DEBUG_STR_SECTION_FLAGS
29688 : : | SECTION_EXCLUDE, NULL);
29689 : 1323 : if (!dwarf_split_debug_info)
29690 : 1323 : debug_line_str_section
29691 : 1323 : = get_section (DEBUG_LTO_LINE_STR_SECTION,
29692 : 1323 : DEBUG_STR_SECTION_FLAGS | SECTION_EXCLUDE, NULL);
29693 : : }
29694 : : else
29695 : : {
29696 : 51974 : if (!dwarf_split_debug_info)
29697 : : {
29698 : 51725 : debug_info_section = get_section (DEBUG_INFO_SECTION,
29699 : : SECTION_DEBUG, NULL);
29700 : 51725 : debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
29701 : : SECTION_DEBUG, NULL);
29702 : 53731 : debug_loc_section = get_section (dwarf_version >= 5
29703 : : ? DEBUG_LOCLISTS_SECTION
29704 : : : DEBUG_LOC_SECTION,
29705 : : SECTION_DEBUG, NULL);
29706 : 51725 : debug_macinfo_section_name
29707 : 5 : = ((dwarf_strict && dwarf_version < 5)
29708 : 51725 : ? DEBUG_MACINFO_SECTION : DEBUG_MACRO_SECTION);
29709 : 51725 : debug_macinfo_section = get_section (debug_macinfo_section_name,
29710 : : SECTION_DEBUG, NULL);
29711 : : }
29712 : : else
29713 : : {
29714 : 249 : debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
29715 : : SECTION_DEBUG | SECTION_EXCLUDE,
29716 : : NULL);
29717 : 249 : debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
29718 : : SECTION_DEBUG | SECTION_EXCLUDE,
29719 : : NULL);
29720 : 249 : debug_addr_section = get_section (DEBUG_ADDR_SECTION,
29721 : : SECTION_DEBUG, NULL);
29722 : 249 : debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
29723 : : SECTION_DEBUG, NULL);
29724 : 249 : debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
29725 : : SECTION_DEBUG, NULL);
29726 : 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
29727 : : DEBUG_SKELETON_ABBREV_SECTION_LABEL,
29728 : : init_sections_and_labels_generation);
29729 : :
29730 : : /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
29731 : : stay in the main .o, but the skeleton_line goes into the
29732 : : split off dwo. */
29733 : 249 : debug_skeleton_line_section
29734 : 249 : = get_section (DEBUG_DWO_LINE_SECTION,
29735 : : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29736 : 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
29737 : : DEBUG_SKELETON_LINE_SECTION_LABEL,
29738 : : init_sections_and_labels_generation);
29739 : 249 : debug_str_offsets_section
29740 : 249 : = get_section (DEBUG_DWO_STR_OFFSETS_SECTION,
29741 : : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29742 : 249 : ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
29743 : : DEBUG_SKELETON_INFO_SECTION_LABEL,
29744 : : init_sections_and_labels_generation);
29745 : 250 : debug_loc_section = get_section (dwarf_version >= 5
29746 : : ? DEBUG_DWO_LOCLISTS_SECTION
29747 : : : DEBUG_DWO_LOC_SECTION,
29748 : : SECTION_DEBUG | SECTION_EXCLUDE,
29749 : : NULL);
29750 : 249 : debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
29751 : : DEBUG_STR_DWO_SECTION_FLAGS,
29752 : : NULL);
29753 : 249 : debug_macinfo_section_name
29754 : 0 : = ((dwarf_strict && dwarf_version < 5)
29755 : 249 : ? DEBUG_DWO_MACINFO_SECTION : DEBUG_DWO_MACRO_SECTION);
29756 : 249 : debug_macinfo_section = get_section (debug_macinfo_section_name,
29757 : : SECTION_DEBUG | SECTION_EXCLUDE,
29758 : : NULL);
29759 : 249 : if (dwarf_version >= 5)
29760 : 248 : debug_ranges_dwo_section
29761 : 248 : = get_section (DEBUG_DWO_RNGLISTS_SECTION,
29762 : : SECTION_DEBUG | SECTION_EXCLUDE, NULL);
29763 : : }
29764 : 51974 : debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
29765 : : SECTION_DEBUG, NULL);
29766 : 51974 : debug_line_section = get_section (DEBUG_LINE_SECTION,
29767 : : SECTION_DEBUG, NULL);
29768 : 103699 : debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
29769 : : SECTION_DEBUG, NULL);
29770 : 103699 : debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
29771 : : SECTION_DEBUG, NULL);
29772 : 51974 : debug_str_section = get_section (DEBUG_STR_SECTION,
29773 : 51974 : DEBUG_STR_SECTION_FLAGS, NULL);
29774 : 51725 : if ((!dwarf_split_debug_info && !output_asm_line_debug_info ())
29775 : 103693 : || asm_outputs_debug_line_str ())
29776 : 49722 : debug_line_str_section = get_section (DEBUG_LINE_STR_SECTION,
29777 : 49722 : DEBUG_STR_SECTION_FLAGS, NULL);
29778 : :
29779 : 53981 : debug_ranges_section = get_section (dwarf_version >= 5
29780 : : ? DEBUG_RNGLISTS_SECTION
29781 : : : DEBUG_RANGES_SECTION,
29782 : : SECTION_DEBUG, NULL);
29783 : 51974 : debug_frame_section = get_section (DEBUG_FRAME_SECTION,
29784 : : SECTION_DEBUG, NULL);
29785 : : }
29786 : :
29787 : 53297 : ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
29788 : : DEBUG_ABBREV_SECTION_LABEL,
29789 : : init_sections_and_labels_generation);
29790 : 53297 : ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
29791 : : DEBUG_INFO_SECTION_LABEL,
29792 : : init_sections_and_labels_generation);
29793 : 53297 : info_section_emitted = false;
29794 : 53297 : ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
29795 : : DEBUG_LINE_SECTION_LABEL,
29796 : : init_sections_and_labels_generation);
29797 : : /* There are up to 6 unique ranges labels per generation.
29798 : : See also output_rnglists. */
29799 : 53297 : ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
29800 : : DEBUG_RANGES_SECTION_LABEL,
29801 : : init_sections_and_labels_generation * 6);
29802 : 53297 : if (dwarf_version >= 5 && dwarf_split_debug_info)
29803 : 248 : ASM_GENERATE_INTERNAL_LABEL (ranges_base_label,
29804 : : DEBUG_RANGES_SECTION_LABEL,
29805 : : 1 + init_sections_and_labels_generation * 6);
29806 : 53297 : ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
29807 : : DEBUG_ADDR_SECTION_LABEL,
29808 : : init_sections_and_labels_generation);
29809 : 106589 : ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
29810 : : (dwarf_strict && dwarf_version < 5)
29811 : : ? DEBUG_MACINFO_SECTION_LABEL
29812 : : : DEBUG_MACRO_SECTION_LABEL,
29813 : : init_sections_and_labels_generation);
29814 : 53297 : ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL,
29815 : : init_sections_and_labels_generation);
29816 : :
29817 : 53297 : ++init_sections_and_labels_generation;
29818 : 53297 : return init_sections_and_labels_generation - 1;
29819 : : }
29820 : :
29821 : : /* Set up for Dwarf output at the start of compilation. */
29822 : :
29823 : : static void
29824 : 55510 : dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
29825 : : {
29826 : : /* Allocate the file_table. */
29827 : 55510 : file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
29828 : :
29829 : : #ifndef DWARF2_LINENO_DEBUGGING_INFO
29830 : : /* Allocate the decl_die_table. */
29831 : 55510 : decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
29832 : :
29833 : : /* Allocate the decl_loc_table. */
29834 : 55510 : decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
29835 : :
29836 : : /* Allocate the cached_dw_loc_list_table. */
29837 : 55510 : cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
29838 : :
29839 : : /* Allocate the initial hunk of the abbrev_die_table. */
29840 : 55510 : vec_alloc (abbrev_die_table, 256);
29841 : : /* Zero-th entry is allocated, but unused. */
29842 : 55510 : abbrev_die_table->quick_push (NULL);
29843 : :
29844 : : /* Allocate the dwarf_proc_stack_usage_map. */
29845 : 55510 : dwarf_proc_stack_usage_map = new hash_map<dw_die_ref, int>;
29846 : :
29847 : : /* Allocate the pubtypes and pubnames vectors. */
29848 : 55510 : vec_alloc (pubname_table, 32);
29849 : 55510 : vec_alloc (pubtype_table, 32);
29850 : :
29851 : 55510 : vec_alloc (incomplete_types, 64);
29852 : :
29853 : 55510 : vec_alloc (used_rtx_array, 32);
29854 : :
29855 : 55510 : if (debug_info_level >= DINFO_LEVEL_VERBOSE)
29856 : 531 : vec_alloc (macinfo_table, 64);
29857 : : #endif
29858 : :
29859 : : /* If front-ends already registered a main translation unit but we were not
29860 : : ready to perform the association, do this now. */
29861 : 55510 : if (main_translation_unit != NULL_TREE)
29862 : 17660 : equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
29863 : 55510 : }
29864 : :
29865 : : /* Called before compile () starts outputtting functions, variables
29866 : : and toplevel asms into assembly. */
29867 : :
29868 : : static void
29869 : 52417 : dwarf2out_assembly_start (void)
29870 : : {
29871 : 52417 : if (text_section_line_info)
29872 : : return;
29873 : :
29874 : : #ifndef DWARF2_LINENO_DEBUGGING_INFO
29875 : 52416 : ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
29876 : 52416 : ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
29877 : 52416 : ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
29878 : : COLD_TEXT_SECTION_LABEL, 0);
29879 : 52416 : ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
29880 : :
29881 : 52416 : switch_to_section (text_section);
29882 : 52416 : ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
29883 : : #endif
29884 : :
29885 : : /* Make sure the line number table for .text always exists. */
29886 : 52416 : text_section_line_info = new_line_info_table ();
29887 : 52416 : text_section_line_info->end_label = text_end_label;
29888 : :
29889 : : #ifdef DWARF2_LINENO_DEBUGGING_INFO
29890 : : cur_line_info_table = text_section_line_info;
29891 : : #endif
29892 : :
29893 : 52416 : if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
29894 : 52416 : && dwarf2out_do_cfi_asm ()
29895 : 52416 : && !dwarf2out_do_eh_frame ())
29896 : 5 : fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
29897 : :
29898 : : #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
29899 : 52416 : if (output_asm_line_debug_info () && dwarf_version >= 5)
29900 : : {
29901 : : /* When gas outputs DWARF5 .debug_line[_str] then we have to
29902 : : tell it the comp_dir and main file name for the zero entry
29903 : : line table. */
29904 : 50406 : const char *comp_dir, *filename0;
29905 : :
29906 : 50406 : comp_dir = comp_dir_string ();
29907 : 50406 : if (comp_dir == NULL)
29908 : 0 : comp_dir = "";
29909 : :
29910 : 50406 : filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
29911 : 50406 : if (filename0 == NULL)
29912 : 1 : filename0 = "";
29913 : :
29914 : 50406 : fprintf (asm_out_file, "\t.file 0 ");
29915 : 50406 : output_quoted_string (asm_out_file, remap_debug_filename (comp_dir));
29916 : 50406 : fputc (' ', asm_out_file);
29917 : 50406 : output_quoted_string (asm_out_file, remap_debug_filename (filename0));
29918 : 50406 : fputc ('\n', asm_out_file);
29919 : : }
29920 : : else
29921 : : #endif
29922 : : /* Work around for PR101575: output a dummy .file directive. */
29923 : 2000 : if (!last_emitted_file && dwarf_debuginfo_p ()
29924 : 4010 : && debug_info_level >= DINFO_LEVEL_TERSE)
29925 : : {
29926 : 2000 : const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
29927 : :
29928 : 2000 : if (filename0 == NULL)
29929 : 0 : filename0 = "<dummy>";
29930 : 2000 : maybe_emit_file (lookup_filename (filename0));
29931 : : }
29932 : : }
29933 : :
29934 : : /* A helper function for dwarf2out_finish called through
29935 : : htab_traverse. Assign a string its index. All strings must be
29936 : : collected into the table by the time index_string is called,
29937 : : because the indexing code relies on htab_traverse to traverse nodes
29938 : : in the same order for each run. */
29939 : :
29940 : : int
29941 : 2927 : index_string (indirect_string_node **h, unsigned int *index)
29942 : : {
29943 : 2927 : indirect_string_node *node = *h;
29944 : :
29945 : 2927 : find_string_form (node);
29946 : 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
29947 : : {
29948 : 2610 : gcc_assert (node->index == NO_INDEX_ASSIGNED);
29949 : 2610 : node->index = *index;
29950 : 2610 : *index += 1;
29951 : : }
29952 : 2927 : return 1;
29953 : : }
29954 : :
29955 : : /* A helper function for output_indirect_strings called through
29956 : : htab_traverse. Output the offset to a string and update the
29957 : : current offset. */
29958 : :
29959 : : int
29960 : 2927 : output_index_string_offset (indirect_string_node **h, unsigned int *offset)
29961 : : {
29962 : 2927 : indirect_string_node *node = *h;
29963 : :
29964 : 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
29965 : : {
29966 : : /* Assert that this node has been assigned an index. */
29967 : 2610 : gcc_assert (node->index != NO_INDEX_ASSIGNED
29968 : : && node->index != NOT_INDEXED);
29969 : 2610 : dw2_asm_output_data (dwarf_offset_size, *offset,
29970 : : "indexed string 0x%x: %s", node->index, node->str);
29971 : 2610 : *offset += strlen (node->str) + 1;
29972 : : }
29973 : 2927 : return 1;
29974 : : }
29975 : :
29976 : : /* A helper function for dwarf2out_finish called through
29977 : : htab_traverse. Output the indexed string. */
29978 : :
29979 : : int
29980 : 2927 : output_index_string (indirect_string_node **h, unsigned int *cur_idx)
29981 : : {
29982 : 2927 : struct indirect_string_node *node = *h;
29983 : :
29984 : 3340 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
29985 : : {
29986 : : /* Assert that the strings are output in the same order as their
29987 : : indexes were assigned. */
29988 : 2610 : gcc_assert (*cur_idx == node->index);
29989 : 2610 : assemble_string (node->str, strlen (node->str) + 1);
29990 : 2610 : *cur_idx += 1;
29991 : : }
29992 : 2927 : return 1;
29993 : : }
29994 : :
29995 : : /* A helper function for output_indirect_strings. Counts the number
29996 : : of index strings offsets. Must match the logic of the functions
29997 : : output_index_string[_offsets] above. */
29998 : : int
29999 : 2514 : count_index_strings (indirect_string_node **h, unsigned int *last_idx)
30000 : : {
30001 : 2514 : struct indirect_string_node *node = *h;
30002 : :
30003 : 2514 : if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
30004 : 2197 : *last_idx += 1;
30005 : 2514 : return 1;
30006 : : }
30007 : :
30008 : : /* A helper function for dwarf2out_finish called through
30009 : : htab_traverse. Emit one queued .debug_str string. */
30010 : :
30011 : : int
30012 : 20008118 : output_indirect_string (indirect_string_node **h, enum dwarf_form form)
30013 : : {
30014 : 20008118 : struct indirect_string_node *node = *h;
30015 : :
30016 : 20008118 : node->form = find_string_form (node);
30017 : 20008118 : if (node->form == form && node->refcount > 0)
30018 : : {
30019 : 19356549 : ASM_OUTPUT_LABEL (asm_out_file, node->label);
30020 : 19356549 : assemble_string (node->str, strlen (node->str) + 1);
30021 : : }
30022 : :
30023 : 20008118 : return 1;
30024 : : }
30025 : :
30026 : : /* Output the indexed string table. */
30027 : :
30028 : : static void
30029 : 53297 : output_indirect_strings (void)
30030 : : {
30031 : 53297 : switch_to_section (debug_str_section);
30032 : 53297 : if (!dwarf_split_debug_info)
30033 : 53048 : debug_str_hash->traverse<enum dwarf_form,
30034 : 20061166 : output_indirect_string> (DW_FORM_strp);
30035 : : else
30036 : : {
30037 : 249 : unsigned int offset = 0;
30038 : 249 : unsigned int cur_idx = 0;
30039 : :
30040 : 249 : if (skeleton_debug_str_hash)
30041 : 249 : skeleton_debug_str_hash->traverse<enum dwarf_form,
30042 : 249 : output_indirect_string> (DW_FORM_strp);
30043 : :
30044 : 249 : switch_to_section (debug_str_offsets_section);
30045 : : /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
30046 : : header. Note that we don't need to generate a label to the
30047 : : actual index table following the header here, because this is
30048 : : for the split dwarf case only. In an .dwo file there is only
30049 : : one string offsets table (and one debug info section). But
30050 : : if we would start using string offset tables for the main (or
30051 : : skeleton) unit, then we have to add a DW_AT_str_offsets_base
30052 : : pointing to the actual index after the header. Split dwarf
30053 : : units will never have a string offsets base attribute. When
30054 : : a split unit is moved into a .dwp file the string offsets can
30055 : : be found through the .debug_cu_index section table. */
30056 : 249 : if (dwarf_version >= 5)
30057 : : {
30058 : 248 : unsigned int last_idx = 0;
30059 : 248 : unsigned long str_offsets_length;
30060 : :
30061 : 248 : debug_str_hash->traverse_noresize
30062 : 2762 : <unsigned int *, count_index_strings> (&last_idx);
30063 : 248 : str_offsets_length = last_idx * dwarf_offset_size + 4;
30064 : 248 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
30065 : 0 : dw2_asm_output_data (4, 0xffffffff,
30066 : : "Escape value for 64-bit DWARF extension");
30067 : 248 : dw2_asm_output_data (dwarf_offset_size, str_offsets_length,
30068 : : "Length of string offsets unit");
30069 : 248 : dw2_asm_output_data (2, 5, "DWARF string offsets version");
30070 : 248 : dw2_asm_output_data (2, 0, "Header zero padding");
30071 : : }
30072 : 249 : debug_str_hash->traverse_noresize
30073 : 3176 : <unsigned int *, output_index_string_offset> (&offset);
30074 : 249 : switch_to_section (debug_str_dwo_section);
30075 : 249 : debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
30076 : 3176 : (&cur_idx);
30077 : : }
30078 : 53297 : }
30079 : :
30080 : : /* Callback for htab_traverse to assign an index to an entry in the
30081 : : table, and to write that entry to the .debug_addr section. */
30082 : :
30083 : : int
30084 : 264 : output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
30085 : : {
30086 : 264 : addr_table_entry *entry = *slot;
30087 : :
30088 : 264 : if (entry->refcount == 0)
30089 : : {
30090 : 0 : gcc_assert (entry->index == NO_INDEX_ASSIGNED
30091 : : || entry->index == NOT_INDEXED);
30092 : : return 1;
30093 : : }
30094 : :
30095 : 264 : gcc_assert (entry->index == *cur_index);
30096 : 264 : (*cur_index)++;
30097 : :
30098 : 264 : switch (entry->kind)
30099 : : {
30100 : 3 : case ate_kind_rtx:
30101 : 3 : dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
30102 : : "0x%x", entry->index);
30103 : 3 : break;
30104 : 0 : case ate_kind_rtx_dtprel:
30105 : 0 : gcc_assert (targetm.asm_out.output_dwarf_dtprel);
30106 : 0 : targetm.asm_out.output_dwarf_dtprel (asm_out_file,
30107 : 0 : DWARF2_ADDR_SIZE,
30108 : : entry->addr.rtl);
30109 : 0 : fputc ('\n', asm_out_file);
30110 : 0 : break;
30111 : 261 : case ate_kind_label:
30112 : 261 : dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
30113 : : "0x%x", entry->index);
30114 : 261 : break;
30115 : 0 : default:
30116 : 0 : gcc_unreachable ();
30117 : : }
30118 : : return 1;
30119 : : }
30120 : :
30121 : : /* A helper function for dwarf2out_finish. Counts the number
30122 : : of indexed addresses. Must match the logic of the functions
30123 : : output_addr_table_entry above. */
30124 : : int
30125 : 264 : count_index_addrs (addr_table_entry **slot, unsigned int *last_idx)
30126 : : {
30127 : 264 : addr_table_entry *entry = *slot;
30128 : :
30129 : 264 : if (entry->refcount > 0)
30130 : 264 : *last_idx += 1;
30131 : 264 : return 1;
30132 : : }
30133 : :
30134 : : /* Produce the .debug_addr section. */
30135 : :
30136 : : static void
30137 : 249 : output_addr_table (void)
30138 : : {
30139 : 249 : unsigned int index = 0;
30140 : 249 : if (addr_index_table == NULL || addr_index_table->size () == 0)
30141 : 5 : return;
30142 : :
30143 : 244 : switch_to_section (debug_addr_section);
30144 : : /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
30145 : : which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
30146 : : before DWARF5, didn't have a header for .debug_addr units.
30147 : : DWARF5 specifies a small header when address tables are used. */
30148 : 244 : if (dwarf_version >= 5)
30149 : : {
30150 : 244 : unsigned int last_idx = 0;
30151 : 244 : unsigned long addrs_length;
30152 : :
30153 : 244 : addr_index_table->traverse_noresize
30154 : 508 : <unsigned int *, count_index_addrs> (&last_idx);
30155 : 244 : addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
30156 : :
30157 : 244 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
30158 : 0 : dw2_asm_output_data (4, 0xffffffff,
30159 : : "Escape value for 64-bit DWARF extension");
30160 : 244 : dw2_asm_output_data (dwarf_offset_size, addrs_length,
30161 : : "Length of Address Unit");
30162 : 244 : dw2_asm_output_data (2, 5, "DWARF addr version");
30163 : 244 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
30164 : 244 : dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
30165 : : }
30166 : 244 : ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
30167 : :
30168 : 244 : addr_index_table
30169 : 508 : ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
30170 : : }
30171 : :
30172 : : #if ENABLE_ASSERT_CHECKING
30173 : : /* Verify that all marks are clear. */
30174 : :
30175 : : static void
30176 : 452241131 : verify_marks_clear (dw_die_ref die)
30177 : : {
30178 : 452241131 : dw_die_ref c;
30179 : :
30180 : 452241131 : gcc_assert (! die->die_mark);
30181 : 793828272 : FOR_EACH_CHILD (die, c, verify_marks_clear (c));
30182 : 452241131 : }
30183 : : #endif /* ENABLE_ASSERT_CHECKING */
30184 : :
30185 : : /* Clear the marks for a die and its children.
30186 : : Be cool if the mark isn't set. */
30187 : :
30188 : : static void
30189 : 53554511 : prune_unmark_dies (dw_die_ref die)
30190 : : {
30191 : 53554511 : dw_die_ref c;
30192 : :
30193 : 53554511 : if (die->die_mark)
30194 : 53554511 : die->die_mark = 0;
30195 : 107056499 : FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
30196 : 53554511 : }
30197 : :
30198 : : /* Given LOC that is referenced by a DIE we're marking as used, find all
30199 : : referenced DWARF procedures it references and mark them as used. */
30200 : :
30201 : : static void
30202 : 118691 : prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc)
30203 : : {
30204 : 348528 : for (; loc != NULL; loc = loc->dw_loc_next)
30205 : 229837 : switch (loc->dw_loc_opc)
30206 : : {
30207 : 0 : case DW_OP_implicit_pointer:
30208 : 0 : case DW_OP_convert:
30209 : 0 : case DW_OP_reinterpret:
30210 : 0 : case DW_OP_GNU_implicit_pointer:
30211 : 0 : case DW_OP_GNU_convert:
30212 : 0 : case DW_OP_GNU_reinterpret:
30213 : 0 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref)
30214 : 0 : prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
30215 : : break;
30216 : 4962 : case DW_OP_GNU_variable_value:
30217 : 4962 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
30218 : : {
30219 : 2186 : dw_die_ref ref
30220 : 2186 : = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
30221 : 2186 : if (ref == NULL)
30222 : : break;
30223 : 1435 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
30224 : 1435 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
30225 : 1435 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
30226 : : }
30227 : : /* FALLTHRU */
30228 : 4213 : case DW_OP_call2:
30229 : 4213 : case DW_OP_call4:
30230 : 4213 : case DW_OP_call_ref:
30231 : 4213 : case DW_OP_const_type:
30232 : 4213 : case DW_OP_GNU_const_type:
30233 : 4213 : case DW_OP_GNU_parameter_ref:
30234 : 4213 : gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref);
30235 : 4213 : prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
30236 : 4213 : break;
30237 : 0 : case DW_OP_regval_type:
30238 : 0 : case DW_OP_deref_type:
30239 : 0 : case DW_OP_GNU_regval_type:
30240 : 0 : case DW_OP_GNU_deref_type:
30241 : 0 : gcc_assert (loc->dw_loc_oprnd2.val_class == dw_val_class_die_ref);
30242 : 0 : prune_unused_types_mark (loc->dw_loc_oprnd2.v.val_die_ref.die, 1);
30243 : 0 : break;
30244 : 0 : case DW_OP_entry_value:
30245 : 0 : case DW_OP_GNU_entry_value:
30246 : 0 : gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_loc);
30247 : 0 : prune_unused_types_walk_loc_descr (loc->dw_loc_oprnd1.v.val_loc);
30248 : 0 : break;
30249 : : default:
30250 : : break;
30251 : : }
30252 : 118691 : }
30253 : :
30254 : : /* Given DIE that we're marking as used, find any other dies
30255 : : it references as attributes and mark them as used. */
30256 : :
30257 : : static void
30258 : 53554511 : prune_unused_types_walk_attribs (dw_die_ref die)
30259 : : {
30260 : 53554511 : dw_attr_node *a;
30261 : 53554511 : unsigned ix;
30262 : :
30263 : 248892480 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
30264 : : {
30265 : 195337969 : switch (AT_class (a))
30266 : : {
30267 : : /* Make sure DWARF procedures referenced by location descriptions will
30268 : : get emitted. */
30269 : 118691 : case dw_val_class_loc:
30270 : 118691 : prune_unused_types_walk_loc_descr (AT_loc (a));
30271 : 118691 : break;
30272 : 0 : case dw_val_class_loc_list:
30273 : 0 : for (dw_loc_list_ref list = AT_loc_list (a);
30274 : 0 : list != NULL;
30275 : 0 : list = list->dw_loc_next)
30276 : 0 : prune_unused_types_walk_loc_descr (list->expr);
30277 : : break;
30278 : :
30279 : : case dw_val_class_view_list:
30280 : : /* This points to a loc_list in another attribute, so it's
30281 : : already covered. */
30282 : : break;
30283 : :
30284 : 54335945 : case dw_val_class_die_ref:
30285 : : /* A reference to another DIE.
30286 : : Make sure that it will get emitted.
30287 : : If it was broken out into a comdat group, don't follow it. */
30288 : 54335945 : if (! AT_ref (a)->comdat_type_p
30289 : 54335945 : || a->dw_attr == DW_AT_specification)
30290 : 54335689 : prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
30291 : : break;
30292 : :
30293 : 32665123 : case dw_val_class_str:
30294 : : /* Set the string's refcount to 0 so that prune_unused_types_mark
30295 : : accounts properly for it. */
30296 : 32665123 : a->dw_attr_val.v.val_str->refcount = 0;
30297 : 32665123 : break;
30298 : :
30299 : : default:
30300 : : break;
30301 : : }
30302 : : }
30303 : 53554511 : }
30304 : :
30305 : : /* Mark the generic parameters and arguments children DIEs of DIE. */
30306 : :
30307 : : static void
30308 : 17314798 : prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
30309 : : {
30310 : 17314798 : dw_die_ref c;
30311 : :
30312 : 17314798 : if (die == NULL || die->die_child == NULL)
30313 : : return;
30314 : : c = die->die_child;
30315 : 18853438 : do
30316 : : {
30317 : 18853438 : if (is_template_parameter (c))
30318 : 804834 : prune_unused_types_mark (c, 1);
30319 : 18853438 : c = c->die_sib;
30320 : 18853438 : } while (c && c != die->die_child);
30321 : : }
30322 : :
30323 : : /* Mark DIE as being used. If DOKIDS is true, then walk down
30324 : : to DIE's children. */
30325 : :
30326 : : static void
30327 : 72745462 : prune_unused_types_mark (dw_die_ref die, int dokids)
30328 : : {
30329 : 72745462 : dw_die_ref c;
30330 : :
30331 : 72745462 : if (die->die_mark == 0)
30332 : : {
30333 : : /* We haven't done this node yet. Mark it as used. */
30334 : 17314798 : die->die_mark = 1;
30335 : : /* If this is the DIE of a generic type instantiation,
30336 : : mark the children DIEs that describe its generic parms and
30337 : : args. */
30338 : 17314798 : prune_unused_types_mark_generic_parms_dies (die);
30339 : :
30340 : : /* We also have to mark its parents as used.
30341 : : (But we don't want to mark our parent's kids due to this,
30342 : : unless it is a class.) */
30343 : 17314798 : if (die->die_parent)
30344 : 17314798 : prune_unused_types_mark (die->die_parent,
30345 : 17314798 : class_scope_p (die->die_parent));
30346 : :
30347 : : /* Mark any referenced nodes. */
30348 : 17314798 : prune_unused_types_walk_attribs (die);
30349 : :
30350 : : /* If this node is a specification,
30351 : : also mark the definition, if it exists. */
30352 : 17314798 : if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
30353 : 101021 : prune_unused_types_mark (die->die_definition, 1);
30354 : : }
30355 : :
30356 : 72745462 : if (dokids && die->die_mark != 2)
30357 : : {
30358 : : /* We need to walk the children, but haven't done so yet.
30359 : : Remember that we've walked the kids. */
30360 : 16809780 : die->die_mark = 2;
30361 : :
30362 : : /* If this is an array type, we need to make sure our
30363 : : kids get marked, even if they're types. If we're
30364 : : breaking out types into comdat sections, do this
30365 : : for all type definitions. */
30366 : 16809780 : if (die->die_tag == DW_TAG_array_type
30367 : 16809780 : || (use_debug_types
30368 : 1479 : && is_type_die (die) && ! is_declaration_die (die)))
30369 : 169019 : FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
30370 : : else
30371 : 30223167 : FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
30372 : : }
30373 : 72745462 : }
30374 : :
30375 : : /* For local classes, look if any static member functions were emitted
30376 : : and if so, mark them. */
30377 : :
30378 : : static void
30379 : 117714 : prune_unused_types_walk_local_classes (dw_die_ref die)
30380 : : {
30381 : 117714 : dw_die_ref c;
30382 : :
30383 : 117714 : if (die->die_mark == 2)
30384 : : return;
30385 : :
30386 : 89043 : switch (die->die_tag)
30387 : : {
30388 : 16996 : case DW_TAG_structure_type:
30389 : 16996 : case DW_TAG_union_type:
30390 : 16996 : case DW_TAG_class_type:
30391 : 16996 : case DW_TAG_interface_type:
30392 : 16996 : break;
30393 : :
30394 : 55241 : case DW_TAG_subprogram:
30395 : 55241 : if (!get_AT_flag (die, DW_AT_declaration)
30396 : 55241 : || die->die_definition != NULL)
30397 : 15439 : prune_unused_types_mark (die, 1);
30398 : : return;
30399 : :
30400 : : default:
30401 : : return;
30402 : : }
30403 : :
30404 : : /* Mark children. */
30405 : 100755 : FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
30406 : : }
30407 : :
30408 : : /* Walk the tree DIE and mark types that we actually use. */
30409 : :
30410 : : static void
30411 : 139536652 : prune_unused_types_walk (dw_die_ref die)
30412 : : {
30413 : 139536652 : dw_die_ref c;
30414 : :
30415 : : /* Don't do anything if this node is already marked and
30416 : : children have been marked as well. */
30417 : 139536652 : if (die->die_mark == 2)
30418 : : return;
30419 : :
30420 : 126646933 : switch (die->die_tag)
30421 : : {
30422 : 32862314 : case DW_TAG_structure_type:
30423 : 32862314 : case DW_TAG_union_type:
30424 : 32862314 : case DW_TAG_class_type:
30425 : 32862314 : case DW_TAG_interface_type:
30426 : 32862314 : if (die->die_perennial_p)
30427 : : break;
30428 : :
30429 : 100362994 : for (c = die->die_parent; c; c = c->die_parent)
30430 : 67555787 : if (c->die_tag == DW_TAG_subprogram)
30431 : : break;
30432 : :
30433 : : /* Finding used static member functions inside of classes
30434 : : is needed just for local classes, because for other classes
30435 : : static member function DIEs with DW_AT_specification
30436 : : are emitted outside of the DW_TAG_*_type. If we ever change
30437 : : it, we'd need to call this even for non-local classes. */
30438 : 32824198 : if (c)
30439 : 16991 : prune_unused_types_walk_local_classes (die);
30440 : :
30441 : : /* It's a type node --- don't mark it. */
30442 : : return;
30443 : :
30444 : 38003342 : case DW_TAG_const_type:
30445 : 38003342 : case DW_TAG_packed_type:
30446 : 38003342 : case DW_TAG_pointer_type:
30447 : 38003342 : case DW_TAG_reference_type:
30448 : 38003342 : case DW_TAG_rvalue_reference_type:
30449 : 38003342 : case DW_TAG_volatile_type:
30450 : 38003342 : case DW_TAG_restrict_type:
30451 : 38003342 : case DW_TAG_shared_type:
30452 : 38003342 : case DW_TAG_atomic_type:
30453 : 38003342 : case DW_TAG_immutable_type:
30454 : 38003342 : case DW_TAG_typedef:
30455 : 38003342 : case DW_TAG_array_type:
30456 : 38003342 : case DW_TAG_coarray_type:
30457 : 38003342 : case DW_TAG_friend:
30458 : 38003342 : case DW_TAG_enumeration_type:
30459 : 38003342 : case DW_TAG_subroutine_type:
30460 : 38003342 : case DW_TAG_string_type:
30461 : 38003342 : case DW_TAG_set_type:
30462 : 38003342 : case DW_TAG_subrange_type:
30463 : 38003342 : case DW_TAG_ptr_to_member_type:
30464 : 38003342 : case DW_TAG_file_type:
30465 : 38003342 : case DW_TAG_unspecified_type:
30466 : 38003342 : case DW_TAG_dynamic_type:
30467 : : /* Type nodes are useful only when other DIEs reference them --- don't
30468 : : mark them. */
30469 : : /* FALLTHROUGH */
30470 : :
30471 : 38003342 : case DW_TAG_dwarf_procedure:
30472 : : /* Likewise for DWARF procedures. */
30473 : :
30474 : 38003342 : if (die->die_perennial_p)
30475 : : break;
30476 : :
30477 : : return;
30478 : :
30479 : 21452573 : case DW_TAG_variable:
30480 : 21452573 : if (flag_debug_only_used_symbols)
30481 : : {
30482 : 21452332 : if (die->die_perennial_p)
30483 : : break;
30484 : :
30485 : : /* For static data members, the declaration in the class is supposed
30486 : : to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
30487 : : DWARF5. DW_TAG_member will be marked, so mark even such
30488 : : DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
30489 : : attribute. */
30490 : 21182931 : if (dwarf_version >= 5
30491 : 21179835 : && class_scope_p (die->die_parent)
30492 : 21363342 : && get_AT (die, DW_AT_const_value))
30493 : : break;
30494 : :
30495 : : /* premark_used_variables marks external variables --- don't mark
30496 : : them here. But function-local externals are always considered
30497 : : used. */
30498 : 21080489 : if (get_AT (die, DW_AT_external))
30499 : : {
30500 : 46646201 : for (c = die->die_parent; c; c = c->die_parent)
30501 : 27537725 : if (c->die_tag == DW_TAG_subprogram)
30502 : : break;
30503 : 19110186 : if (!c)
30504 : : return;
30505 : : }
30506 : : }
30507 : : /* FALLTHROUGH */
30508 : :
30509 : : default:
30510 : : /* Mark everything else. */
30511 : : break;
30512 : : }
30513 : :
30514 : 36809602 : if (die->die_mark == 0)
30515 : : {
30516 : 36239713 : die->die_mark = 1;
30517 : :
30518 : : /* Now, mark any dies referenced from here. */
30519 : 36239713 : prune_unused_types_walk_attribs (die);
30520 : : }
30521 : :
30522 : 36809602 : die->die_mark = 2;
30523 : :
30524 : : /* Mark children. */
30525 : 149913913 : FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
30526 : : }
30527 : :
30528 : : /* Increment the string counts on strings referred to from DIE's
30529 : : attributes. */
30530 : :
30531 : : static void
30532 : 53554511 : prune_unused_types_update_strings (dw_die_ref die)
30533 : : {
30534 : 53554511 : dw_attr_node *a;
30535 : 53554511 : unsigned ix;
30536 : :
30537 : 248892480 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
30538 : 195337969 : if (AT_class (a) == dw_val_class_str)
30539 : : {
30540 : 32665123 : struct indirect_string_node *s = a->dw_attr_val.v.val_str;
30541 : 32665123 : s->refcount++;
30542 : : /* Avoid unnecessarily putting strings that are used less than
30543 : : twice in the hash table. */
30544 : 32665123 : if (s->form != DW_FORM_line_strp
30545 : 32564835 : && (s->refcount
30546 : 32564835 : == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2)))
30547 : : {
30548 : 19356074 : indirect_string_node **slot
30549 : 19356074 : = debug_str_hash->find_slot_with_hash (s->str,
30550 : 19356074 : htab_hash_string (s->str),
30551 : : INSERT);
30552 : 19356074 : gcc_assert (*slot == NULL);
30553 : 19356074 : *slot = s;
30554 : : }
30555 : : }
30556 : 53554511 : }
30557 : :
30558 : : /* Mark DIE and its children as removed. */
30559 : :
30560 : : static void
30561 : 398686620 : mark_removed (dw_die_ref die)
30562 : : {
30563 : 398686620 : dw_die_ref c;
30564 : 398686620 : die->removed = true;
30565 : 711254476 : FOR_EACH_CHILD (die, c, mark_removed (c));
30566 : 398686620 : }
30567 : :
30568 : : /* Remove from the tree DIE any dies that aren't marked. */
30569 : :
30570 : : static void
30571 : 53554511 : prune_unused_types_prune (dw_die_ref die)
30572 : : {
30573 : 53554511 : dw_die_ref c;
30574 : :
30575 : 53554511 : gcc_assert (die->die_mark);
30576 : 53554511 : prune_unused_types_update_strings (die);
30577 : :
30578 : 53554511 : if (! die->die_child)
30579 : : return;
30580 : :
30581 : : c = die->die_child;
30582 : 53826179 : do {
30583 : 53826179 : dw_die_ref prev = c, next;
30584 : 139620752 : for (c = c->die_sib; ! c->die_mark; c = next)
30585 : 86118764 : if (c == die->die_child)
30586 : : {
30587 : : /* No marked children between 'prev' and the end of the list. */
30588 : 324191 : if (prev == c)
30589 : : /* No marked children at all. */
30590 : 176153 : die->die_child = NULL;
30591 : : else
30592 : : {
30593 : 148038 : prev->die_sib = c->die_sib;
30594 : 148038 : die->die_child = prev;
30595 : : }
30596 : 324191 : c->die_sib = NULL;
30597 : 324191 : mark_removed (c);
30598 : 324191 : return;
30599 : : }
30600 : : else
30601 : : {
30602 : 85794573 : next = c->die_sib;
30603 : 85794573 : c->die_sib = NULL;
30604 : 85794573 : mark_removed (c);
30605 : : }
30606 : :
30607 : 53501988 : if (c != prev->die_sib)
30608 : 2193941 : prev->die_sib = c;
30609 : 53501988 : prune_unused_types_prune (c);
30610 : 53501988 : } while (c != die->die_child);
30611 : : }
30612 : :
30613 : : /* Remove dies representing declarations that we never use. */
30614 : :
30615 : : static void
30616 : 52443 : prune_unused_types (void)
30617 : : {
30618 : 52443 : unsigned int i;
30619 : 52443 : limbo_die_node *node;
30620 : 52443 : comdat_type_node *ctnode;
30621 : 52443 : pubname_entry *pub;
30622 : 52443 : dw_die_ref base_type;
30623 : :
30624 : : #if ENABLE_ASSERT_CHECKING
30625 : : /* All the marks should already be clear. */
30626 : 52443 : verify_marks_clear (comp_unit_die ());
30627 : 52443 : for (node = limbo_die_list; node; node = node->next)
30628 : 0 : verify_marks_clear (node->die);
30629 : 52523 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30630 : 80 : verify_marks_clear (ctnode->root_die);
30631 : : #endif /* ENABLE_ASSERT_CHECKING */
30632 : :
30633 : : /* Mark types that are used in global variables. */
30634 : 52443 : premark_types_used_by_global_vars ();
30635 : :
30636 : : /* Mark variables used in the symtab. */
30637 : 52443 : if (flag_debug_only_used_symbols)
30638 : 52411 : premark_used_variables ();
30639 : :
30640 : : /* Set the mark on nodes that are actually used. */
30641 : 52443 : prune_unused_types_walk (comp_unit_die ());
30642 : 52443 : for (node = limbo_die_list; node; node = node->next)
30643 : 0 : prune_unused_types_walk (node->die);
30644 : 52523 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30645 : : {
30646 : 80 : prune_unused_types_walk (ctnode->root_die);
30647 : 80 : prune_unused_types_mark (ctnode->type_die, 1);
30648 : : }
30649 : :
30650 : : /* Also set the mark on nodes referenced from the pubname_table. Enumerators
30651 : : are unusual in that they are pubnames that are the children of pubtypes.
30652 : : They should only be marked via their parent DW_TAG_enumeration_type die,
30653 : : not as roots in themselves. */
30654 : 53141 : FOR_EACH_VEC_ELT (*pubname_table, i, pub)
30655 : 698 : if (pub->die->die_tag != DW_TAG_enumerator)
30656 : 644 : prune_unused_types_mark (pub->die, 1);
30657 : 52443 : for (i = 0; base_types.iterate (i, &base_type); i++)
30658 : 0 : prune_unused_types_mark (base_type, 1);
30659 : :
30660 : : /* Also set the mark on nodes that could be referenced by
30661 : : DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
30662 : : by DW_TAG_inlined_subroutine origins. */
30663 : 52443 : cgraph_node *cnode;
30664 : 5782578 : FOR_EACH_FUNCTION (cnode)
30665 : 2838846 : if (cnode->referred_to_p (false))
30666 : : {
30667 : 2645762 : dw_die_ref die = lookup_decl_die (cnode->decl);
30668 : 2645762 : if (die == NULL || die->die_mark)
30669 : 2645588 : continue;
30670 : 174 : for (cgraph_edge *e = cnode->callers; e; e = e->next_caller)
30671 : 152 : if (e->caller != cnode)
30672 : : {
30673 : 152 : prune_unused_types_mark (die, 1);
30674 : 152 : break;
30675 : : }
30676 : : }
30677 : :
30678 : 52443 : if (debug_str_hash)
30679 : 52443 : debug_str_hash->empty ();
30680 : 52443 : if (skeleton_debug_str_hash)
30681 : 0 : skeleton_debug_str_hash->empty ();
30682 : 52443 : prune_unused_types_prune (comp_unit_die ());
30683 : 52443 : for (limbo_die_node **pnode = &limbo_die_list; *pnode; )
30684 : : {
30685 : 0 : node = *pnode;
30686 : 0 : if (!node->die->die_mark)
30687 : 0 : *pnode = node->next;
30688 : : else
30689 : : {
30690 : 0 : prune_unused_types_prune (node->die);
30691 : 0 : pnode = &node->next;
30692 : : }
30693 : : }
30694 : 52523 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30695 : 80 : prune_unused_types_prune (ctnode->root_die);
30696 : :
30697 : : /* Leave the marks clear. */
30698 : 52443 : prune_unmark_dies (comp_unit_die ());
30699 : 52443 : for (node = limbo_die_list; node; node = node->next)
30700 : 0 : prune_unmark_dies (node->die);
30701 : 52523 : for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
30702 : 80 : prune_unmark_dies (ctnode->root_die);
30703 : 52443 : }
30704 : :
30705 : : /* Helpers to manipulate hash table of comdat type units. */
30706 : :
30707 : : struct comdat_type_hasher : nofree_ptr_hash <comdat_type_node>
30708 : : {
30709 : : static inline hashval_t hash (const comdat_type_node *);
30710 : : static inline bool equal (const comdat_type_node *, const comdat_type_node *);
30711 : : };
30712 : :
30713 : : inline hashval_t
30714 : 85 : comdat_type_hasher::hash (const comdat_type_node *type_node)
30715 : : {
30716 : 85 : hashval_t h;
30717 : 85 : memcpy (&h, type_node->signature, sizeof (h));
30718 : 85 : return h;
30719 : : }
30720 : :
30721 : : inline bool
30722 : 5 : comdat_type_hasher::equal (const comdat_type_node *type_node_1,
30723 : : const comdat_type_node *type_node_2)
30724 : : {
30725 : 5 : return (! memcmp (type_node_1->signature, type_node_2->signature,
30726 : : DWARF_TYPE_SIGNATURE_SIZE));
30727 : : }
30728 : :
30729 : : /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
30730 : : to the location it would have been added, should we know its
30731 : : DECL_ASSEMBLER_NAME when we added other attributes. This will
30732 : : probably improve compactness of debug info, removing equivalent
30733 : : abbrevs, and hide any differences caused by deferring the
30734 : : computation of the assembler name, triggered by e.g. PCH. */
30735 : :
30736 : : static inline void
30737 : 86136402 : move_linkage_attr (dw_die_ref die)
30738 : : {
30739 : 86136402 : unsigned ix = vec_safe_length (die->die_attr);
30740 : 86136402 : dw_attr_node linkage = (*die->die_attr)[ix - 1];
30741 : :
30742 : 86136402 : gcc_assert (linkage.dw_attr == DW_AT_linkage_name
30743 : : || linkage.dw_attr == DW_AT_MIPS_linkage_name);
30744 : :
30745 : 402074263 : while (--ix > 0)
30746 : : {
30747 : 402074215 : dw_attr_node *prev = &(*die->die_attr)[ix - 1];
30748 : :
30749 : 402074215 : if (prev->dw_attr == DW_AT_decl_line
30750 : : || prev->dw_attr == DW_AT_decl_column
30751 : : || prev->dw_attr == DW_AT_name)
30752 : : break;
30753 : : }
30754 : :
30755 : 86136402 : if (ix != vec_safe_length (die->die_attr) - 1)
30756 : : {
30757 : 85829254 : die->die_attr->pop ();
30758 : 85829254 : die->die_attr->quick_insert (ix, linkage);
30759 : : }
30760 : 86136402 : }
30761 : :
30762 : : /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
30763 : : referenced from typed stack ops and count how often they are used. */
30764 : :
30765 : : static void
30766 : 32860774 : mark_base_types (dw_loc_descr_ref loc)
30767 : : {
30768 : 32860774 : dw_die_ref base_type = NULL;
30769 : :
30770 : 93905187 : for (; loc; loc = loc->dw_loc_next)
30771 : : {
30772 : 61044413 : switch (loc->dw_loc_opc)
30773 : : {
30774 : 163727 : case DW_OP_regval_type:
30775 : 163727 : case DW_OP_deref_type:
30776 : 163727 : case DW_OP_GNU_regval_type:
30777 : 163727 : case DW_OP_GNU_deref_type:
30778 : 163727 : base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
30779 : 163727 : break;
30780 : 167204 : case DW_OP_convert:
30781 : 167204 : case DW_OP_reinterpret:
30782 : 167204 : case DW_OP_GNU_convert:
30783 : 167204 : case DW_OP_GNU_reinterpret:
30784 : 167204 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
30785 : 25603 : continue;
30786 : : /* FALLTHRU */
30787 : 183206 : case DW_OP_const_type:
30788 : 183206 : case DW_OP_GNU_const_type:
30789 : 183206 : base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
30790 : 183206 : break;
30791 : 1331304 : case DW_OP_entry_value:
30792 : 1331304 : case DW_OP_GNU_entry_value:
30793 : 1331304 : mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
30794 : 1331304 : continue;
30795 : 59340573 : default:
30796 : 59340573 : continue;
30797 : : }
30798 : 346933 : gcc_assert (base_type->die_parent == comp_unit_die ());
30799 : 346933 : if (base_type->die_mark)
30800 : 340225 : base_type->die_mark++;
30801 : : else
30802 : : {
30803 : 6708 : base_types.safe_push (base_type);
30804 : 6708 : base_type->die_mark = 1;
30805 : : }
30806 : : }
30807 : 32860774 : }
30808 : :
30809 : : /* Stripped-down variant of resolve_addr, mark DW_TAG_base_type nodes
30810 : : referenced from typed stack ops and count how often they are used. */
30811 : :
30812 : : static void
30813 : 226167 : mark_base_types (dw_die_ref die)
30814 : : {
30815 : 226167 : dw_die_ref c;
30816 : 226167 : dw_attr_node *a;
30817 : 226167 : dw_loc_list_ref *curr;
30818 : 226167 : unsigned ix;
30819 : :
30820 : 1056857 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
30821 : 830690 : switch (AT_class (a))
30822 : : {
30823 : 0 : case dw_val_class_loc_list:
30824 : 0 : curr = AT_loc_list_ptr (a);
30825 : 0 : while (*curr)
30826 : : {
30827 : 0 : mark_base_types ((*curr)->expr);
30828 : 0 : curr = &(*curr)->dw_loc_next;
30829 : : }
30830 : : break;
30831 : :
30832 : 237 : case dw_val_class_loc:
30833 : 237 : mark_base_types (AT_loc (a));
30834 : 237 : break;
30835 : :
30836 : : default:
30837 : : break;
30838 : : }
30839 : :
30840 : 451005 : FOR_EACH_CHILD (die, c, mark_base_types (c));
30841 : 226167 : }
30842 : :
30843 : : /* Comparison function for sorting marked base types. */
30844 : :
30845 : : static int
30846 : 18812 : base_type_cmp (const void *x, const void *y)
30847 : : {
30848 : 18812 : dw_die_ref dx = *(const dw_die_ref *) x;
30849 : 18812 : dw_die_ref dy = *(const dw_die_ref *) y;
30850 : 18812 : unsigned int byte_size1, byte_size2;
30851 : 18812 : unsigned int encoding1, encoding2;
30852 : 18812 : unsigned int align1, align2;
30853 : 18812 : if (dx->die_mark > dy->die_mark)
30854 : : return -1;
30855 : 10830 : if (dx->die_mark < dy->die_mark)
30856 : : return 1;
30857 : 4086 : byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
30858 : 4086 : byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
30859 : 4086 : if (byte_size1 < byte_size2)
30860 : : return 1;
30861 : 2598 : if (byte_size1 > byte_size2)
30862 : : return -1;
30863 : 665 : encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
30864 : 665 : encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
30865 : 665 : if (encoding1 < encoding2)
30866 : : return 1;
30867 : 391 : if (encoding1 > encoding2)
30868 : : return -1;
30869 : 6 : align1 = get_AT_unsigned (dx, DW_AT_alignment);
30870 : 6 : align2 = get_AT_unsigned (dy, DW_AT_alignment);
30871 : 6 : if (align1 < align2)
30872 : : return 1;
30873 : 6 : if (align1 > align2)
30874 : : return -1;
30875 : : return 0;
30876 : : }
30877 : :
30878 : : /* Move base types marked by mark_base_types as early as possible
30879 : : in the CU, sorted by decreasing usage count both to make the
30880 : : uleb128 references as small as possible and to make sure they
30881 : : will have die_offset already computed by calc_die_sizes when
30882 : : sizes of typed stack loc ops is computed. */
30883 : :
30884 : : static void
30885 : 53297 : move_marked_base_types (void)
30886 : : {
30887 : 53297 : unsigned int i;
30888 : 53297 : dw_die_ref base_type, die, c;
30889 : :
30890 : 53297 : if (base_types.is_empty ())
30891 : 53297 : return;
30892 : :
30893 : : /* Sort by decreasing usage count, they will be added again in that
30894 : : order later on. */
30895 : 3617 : base_types.qsort (base_type_cmp);
30896 : 3617 : die = comp_unit_die ();
30897 : 3617 : c = die->die_child;
30898 : 1519001 : do
30899 : : {
30900 : 1519001 : dw_die_ref prev = c;
30901 : 1519001 : c = c->die_sib;
30902 : 1525709 : while (c->die_mark)
30903 : : {
30904 : 6708 : remove_child_with_prev (c, prev);
30905 : : /* As base types got marked, there must be at least
30906 : : one node other than DW_TAG_base_type. */
30907 : 6708 : gcc_assert (die->die_child != NULL);
30908 : 6708 : c = prev->die_sib;
30909 : : }
30910 : : }
30911 : 1519001 : while (c != die->die_child);
30912 : 3617 : gcc_assert (die->die_child);
30913 : : c = die->die_child;
30914 : 10325 : for (i = 0; base_types.iterate (i, &base_type); i++)
30915 : : {
30916 : 6708 : base_type->die_mark = 0;
30917 : 6708 : base_type->die_sib = c->die_sib;
30918 : 6708 : c->die_sib = base_type;
30919 : 6708 : c = base_type;
30920 : : }
30921 : : }
30922 : :
30923 : : /* Helper function for resolve_addr, attempt to resolve
30924 : : one CONST_STRING, return true if successful. Similarly verify that
30925 : : SYMBOL_REFs refer to variables emitted in the current CU. */
30926 : :
30927 : : static bool
30928 : 2009967 : resolve_one_addr (rtx *addr)
30929 : : {
30930 : 2009967 : rtx rtl = *addr;
30931 : :
30932 : 2009967 : if (GET_CODE (rtl) == CONST_STRING)
30933 : : {
30934 : 243146 : size_t len = strlen (XSTR (rtl, 0)) + 1;
30935 : 243146 : tree t = build_string (len, XSTR (rtl, 0));
30936 : 243146 : tree tlen = size_int (len - 1);
30937 : 243146 : TREE_TYPE (t)
30938 : 243146 : = build_array_type (char_type_node, build_index_type (tlen));
30939 : 243146 : rtl = lookup_constant_def (t);
30940 : 243146 : if (!rtl || !MEM_P (rtl))
30941 : : return false;
30942 : 111461 : rtl = XEXP (rtl, 0);
30943 : 111461 : if (GET_CODE (rtl) == SYMBOL_REF
30944 : 111461 : && SYMBOL_REF_DECL (rtl)
30945 : 222922 : && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
30946 : : return false;
30947 : 5639 : vec_safe_push (used_rtx_array, rtl);
30948 : 5639 : *addr = rtl;
30949 : 5639 : return true;
30950 : : }
30951 : :
30952 : 1766821 : if (GET_CODE (rtl) == SYMBOL_REF
30953 : 1766821 : && SYMBOL_REF_DECL (rtl))
30954 : : {
30955 : 1386636 : if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
30956 : : {
30957 : 540492 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
30958 : : return false;
30959 : : }
30960 : 846144 : else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
30961 : : return false;
30962 : : }
30963 : :
30964 : 1735348 : if (GET_CODE (rtl) == CONST)
30965 : : {
30966 : 125775 : subrtx_ptr_iterator::array_type array;
30967 : 499110 : FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
30968 : 375361 : if (!resolve_one_addr (*iter))
30969 : 2026 : return false;
30970 : 125775 : }
30971 : :
30972 : : return true;
30973 : : }
30974 : :
30975 : : /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
30976 : : if possible, and create DW_TAG_dwarf_procedure that can be referenced
30977 : : from DW_OP_implicit_pointer if the string hasn't been seen yet. */
30978 : :
30979 : : static rtx
30980 : 81145 : string_cst_pool_decl (tree t)
30981 : : {
30982 : 81145 : rtx rtl = output_constant_def (t, 1);
30983 : 81145 : unsigned char *array;
30984 : 81145 : dw_loc_descr_ref l;
30985 : 81145 : tree decl;
30986 : 81145 : size_t len;
30987 : 81145 : dw_die_ref ref;
30988 : :
30989 : 81145 : if (!rtl || !MEM_P (rtl))
30990 : : return NULL_RTX;
30991 : 81145 : rtl = XEXP (rtl, 0);
30992 : 81145 : if (GET_CODE (rtl) != SYMBOL_REF
30993 : 81145 : || SYMBOL_REF_DECL (rtl) == NULL_TREE)
30994 : : return NULL_RTX;
30995 : :
30996 : 81145 : decl = SYMBOL_REF_DECL (rtl);
30997 : 81145 : if (!lookup_decl_die (decl))
30998 : : {
30999 : 9997 : len = TREE_STRING_LENGTH (t);
31000 : 9997 : vec_safe_push (used_rtx_array, rtl);
31001 : 9997 : ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
31002 : 9997 : array = ggc_vec_alloc<unsigned char> (len);
31003 : 9997 : memcpy (array, TREE_STRING_POINTER (t), len);
31004 : 9997 : l = new_loc_descr (DW_OP_implicit_value, len, 0);
31005 : 9997 : l->dw_loc_oprnd2.val_class = dw_val_class_vec;
31006 : 9997 : l->dw_loc_oprnd2.v.val_vec.length = len;
31007 : 9997 : l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
31008 : 9997 : l->dw_loc_oprnd2.v.val_vec.array = array;
31009 : 9997 : add_AT_loc (ref, DW_AT_location, l);
31010 : 9997 : equate_decl_number_to_die (decl, ref);
31011 : : }
31012 : : return rtl;
31013 : : }
31014 : :
31015 : : /* Helper function of resolve_addr_in_expr. LOC is
31016 : : a DW_OP_addr followed by DW_OP_stack_value, either at the start
31017 : : of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
31018 : : resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
31019 : : with DW_OP_implicit_pointer if possible
31020 : : and return true, if unsuccessful, return false. */
31021 : :
31022 : : static bool
31023 : 101511 : optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
31024 : : {
31025 : 101511 : rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
31026 : 101511 : HOST_WIDE_INT offset = 0;
31027 : 101511 : dw_die_ref ref = NULL;
31028 : 101511 : tree decl;
31029 : :
31030 : 101511 : if (GET_CODE (rtl) == CONST
31031 : 1980 : && GET_CODE (XEXP (rtl, 0)) == PLUS
31032 : 1980 : && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
31033 : : {
31034 : 1980 : offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
31035 : 1980 : rtl = XEXP (XEXP (rtl, 0), 0);
31036 : : }
31037 : 101511 : if (GET_CODE (rtl) == CONST_STRING)
31038 : : {
31039 : 81145 : size_t len = strlen (XSTR (rtl, 0)) + 1;
31040 : 81145 : tree t = build_string (len, XSTR (rtl, 0));
31041 : 81145 : tree tlen = size_int (len - 1);
31042 : :
31043 : 81145 : TREE_TYPE (t)
31044 : 81145 : = build_array_type (char_type_node, build_index_type (tlen));
31045 : 81145 : rtl = string_cst_pool_decl (t);
31046 : 81145 : if (!rtl)
31047 : : return false;
31048 : : }
31049 : 101511 : if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
31050 : : {
31051 : 101511 : decl = SYMBOL_REF_DECL (rtl);
31052 : 101511 : if (VAR_P (decl) && !DECL_EXTERNAL (decl))
31053 : : {
31054 : 101147 : ref = lookup_decl_die (decl);
31055 : 101147 : if (ref && (get_AT (ref, DW_AT_location)
31056 : 14180 : || get_AT (ref, DW_AT_const_value)))
31057 : : {
31058 : 94561 : loc->dw_loc_opc = dwarf_OP (DW_OP_implicit_pointer);
31059 : 94561 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31060 : 94561 : loc->dw_loc_oprnd1.val_entry = NULL;
31061 : 94561 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
31062 : 94561 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
31063 : 94561 : loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
31064 : 94561 : loc->dw_loc_oprnd2.v.val_int = offset;
31065 : 94561 : return true;
31066 : : }
31067 : : }
31068 : : }
31069 : : return false;
31070 : : }
31071 : :
31072 : : /* Helper function for resolve_addr, handle one location
31073 : : expression, return false if at least one CONST_STRING or SYMBOL_REF in
31074 : : the location list couldn't be resolved. */
31075 : :
31076 : : static bool
31077 : 32278604 : resolve_addr_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
31078 : : {
31079 : 32278604 : dw_loc_descr_ref keep = NULL;
31080 : 91996965 : for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
31081 : 60472997 : switch (loc->dw_loc_opc)
31082 : : {
31083 : 1508408 : case DW_OP_addr:
31084 : 1508408 : if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
31085 : : {
31086 : 143483 : if ((prev == NULL
31087 : 194 : || prev->dw_loc_opc == DW_OP_piece
31088 : 30 : || prev->dw_loc_opc == DW_OP_bit_piece)
31089 : 143453 : && loc->dw_loc_next
31090 : 136268 : && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
31091 : 101511 : && (!dwarf_strict || dwarf_version >= 5)
31092 : 244994 : && optimize_one_addr_into_implicit_ptr (loc))
31093 : : break;
31094 : 48922 : return false;
31095 : : }
31096 : : break;
31097 : 3 : case DW_OP_GNU_addr_index:
31098 : 3 : case DW_OP_addrx:
31099 : 3 : case DW_OP_GNU_const_index:
31100 : 3 : case DW_OP_constx:
31101 : 3 : if ((loc->dw_loc_opc == DW_OP_GNU_addr_index
31102 : 3 : || loc->dw_loc_opc == DW_OP_addrx)
31103 : : || ((loc->dw_loc_opc == DW_OP_GNU_const_index
31104 : : || loc->dw_loc_opc == DW_OP_constx)
31105 : 0 : && loc->dw_loc_dtprel))
31106 : : {
31107 : 3 : rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
31108 : 3 : if (!resolve_one_addr (&rtl))
31109 : 0 : return false;
31110 : 3 : remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
31111 : 3 : loc->dw_loc_oprnd1.val_entry
31112 : 3 : = add_addr_table_entry (rtl, loc->dw_loc_dtprel
31113 : : ? ate_kind_rtx_dtprel : ate_kind_rtx);
31114 : : }
31115 : : break;
31116 : 288474 : case DW_OP_const4u:
31117 : 288474 : case DW_OP_const8u:
31118 : 288474 : if (loc->dw_loc_dtprel
31119 : 288474 : && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
31120 : : return false;
31121 : : break;
31122 : 776069 : case DW_OP_plus_uconst:
31123 : 776069 : if (size_of_loc_descr (loc)
31124 : 776069 : > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
31125 : 776069 : + 1
31126 : 776069 : && loc->dw_loc_oprnd1.v.val_unsigned > 0)
31127 : : {
31128 : 14443 : dw_loc_descr_ref repl
31129 : 14443 : = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
31130 : 14443 : add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
31131 : 14443 : add_loc_descr (&repl, loc->dw_loc_next);
31132 : 14443 : *loc = *repl;
31133 : : }
31134 : : break;
31135 : 118466 : case DW_OP_implicit_value:
31136 : 118466 : if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
31137 : 118466 : && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
31138 : : return false;
31139 : : break;
31140 : 1858563 : case DW_OP_implicit_pointer:
31141 : 1858563 : case DW_OP_GNU_implicit_pointer:
31142 : 1858563 : case DW_OP_GNU_parameter_ref:
31143 : 1858563 : case DW_OP_GNU_variable_value:
31144 : 1858563 : if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
31145 : : {
31146 : 698690 : dw_die_ref ref
31147 : 698690 : = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
31148 : 698690 : if (ref == NULL)
31149 : : return false;
31150 : 179 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31151 : 179 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
31152 : 179 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
31153 : : }
31154 : 1160052 : if (loc->dw_loc_opc == DW_OP_GNU_variable_value)
31155 : : {
31156 : 4471 : if (prev == NULL
31157 : 4471 : && loc->dw_loc_next == NULL
31158 : 7788 : && AT_class (a) == dw_val_class_loc)
31159 : 3317 : switch (a->dw_attr)
31160 : : {
31161 : : /* Following attributes allow both exprloc and reference,
31162 : : so if the whole expression is DW_OP_GNU_variable_value
31163 : : alone we could transform it into reference. */
31164 : 3283 : case DW_AT_byte_size:
31165 : 3283 : case DW_AT_bit_size:
31166 : 3283 : case DW_AT_lower_bound:
31167 : 3283 : case DW_AT_upper_bound:
31168 : 3283 : case DW_AT_bit_stride:
31169 : 3283 : case DW_AT_count:
31170 : 3283 : case DW_AT_allocated:
31171 : 3283 : case DW_AT_associated:
31172 : 3283 : case DW_AT_byte_stride:
31173 : 3283 : a->dw_attr_val.val_class = dw_val_class_die_ref;
31174 : 3283 : a->dw_attr_val.val_entry = NULL;
31175 : 3283 : a->dw_attr_val.v.val_die_ref.die
31176 : 3283 : = loc->dw_loc_oprnd1.v.val_die_ref.die;
31177 : 3283 : a->dw_attr_val.v.val_die_ref.external = 0;
31178 : 3283 : return true;
31179 : : default:
31180 : : break;
31181 : : }
31182 : 1188 : if (dwarf_strict)
31183 : : return false;
31184 : : }
31185 : : break;
31186 : : case DW_OP_const_type:
31187 : : case DW_OP_regval_type:
31188 : : case DW_OP_deref_type:
31189 : : case DW_OP_convert:
31190 : : case DW_OP_reinterpret:
31191 : : case DW_OP_GNU_const_type:
31192 : : case DW_OP_GNU_regval_type:
31193 : : case DW_OP_GNU_deref_type:
31194 : : case DW_OP_GNU_convert:
31195 : : case DW_OP_GNU_reinterpret:
31196 : 335596 : while (loc->dw_loc_next
31197 : 335596 : && (loc->dw_loc_next->dw_loc_opc == DW_OP_convert
31198 : 244308 : || loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert))
31199 : : {
31200 : 71593 : dw_die_ref base1, base2;
31201 : 71593 : unsigned enc1, enc2, size1, size2;
31202 : 71593 : if (loc->dw_loc_opc == DW_OP_regval_type
31203 : 71593 : || loc->dw_loc_opc == DW_OP_deref_type
31204 : 64954 : || loc->dw_loc_opc == DW_OP_GNU_regval_type
31205 : 64954 : || loc->dw_loc_opc == DW_OP_GNU_deref_type)
31206 : 6639 : base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
31207 : 64954 : else if (loc->dw_loc_oprnd1.val_class
31208 : : == dw_val_class_unsigned_const)
31209 : : break;
31210 : : else
31211 : 64179 : base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
31212 : 70818 : if (loc->dw_loc_next->dw_loc_oprnd1.val_class
31213 : : == dw_val_class_unsigned_const)
31214 : : break;
31215 : 48078 : base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
31216 : 48078 : gcc_assert (base1->die_tag == DW_TAG_base_type
31217 : : && base2->die_tag == DW_TAG_base_type);
31218 : 48078 : enc1 = get_AT_unsigned (base1, DW_AT_encoding);
31219 : 48078 : enc2 = get_AT_unsigned (base2, DW_AT_encoding);
31220 : 48078 : size1 = get_AT_unsigned (base1, DW_AT_byte_size);
31221 : 48078 : size2 = get_AT_unsigned (base2, DW_AT_byte_size);
31222 : 48078 : if (size1 == size2
31223 : 4815 : && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
31224 : 4706 : && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
31225 : 1910 : && loc != keep)
31226 : 2922 : || enc1 == enc2))
31227 : : {
31228 : : /* Optimize away next DW_OP_convert after
31229 : : adjusting LOC's base type die reference. */
31230 : 1893 : if (loc->dw_loc_opc == DW_OP_regval_type
31231 : 1893 : || loc->dw_loc_opc == DW_OP_deref_type
31232 : 1115 : || loc->dw_loc_opc == DW_OP_GNU_regval_type
31233 : 1115 : || loc->dw_loc_opc == DW_OP_GNU_deref_type)
31234 : 778 : loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
31235 : : else
31236 : 1115 : loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
31237 : 1893 : loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
31238 : 1893 : continue;
31239 : : }
31240 : : /* Don't change integer DW_OP_convert after e.g. floating
31241 : : point typed stack entry. */
31242 : 46185 : else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
31243 : 18024 : keep = loc->dw_loc_next;
31244 : : break;
31245 : : }
31246 : : break;
31247 : : default:
31248 : : break;
31249 : : }
31250 : : return true;
31251 : : }
31252 : :
31253 : : /* Helper function of resolve_addr. DIE had DW_AT_location of
31254 : : DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
31255 : : and DW_OP_addr couldn't be resolved. resolve_addr has already
31256 : : removed the DW_AT_location attribute. This function attempts to
31257 : : add a new DW_AT_location attribute with DW_OP_implicit_pointer
31258 : : to it or DW_AT_const_value attribute, if possible. */
31259 : :
31260 : : static void
31261 : 571 : optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
31262 : : {
31263 : 571 : if (!VAR_P (decl)
31264 : 571 : || lookup_decl_die (decl) != die
31265 : 571 : || DECL_EXTERNAL (decl)
31266 : 571 : || !TREE_STATIC (decl)
31267 : 571 : || DECL_INITIAL (decl) == NULL_TREE
31268 : 408 : || DECL_P (DECL_INITIAL (decl))
31269 : 979 : || get_AT (die, DW_AT_const_value))
31270 : 163 : return;
31271 : :
31272 : 408 : tree init = DECL_INITIAL (decl);
31273 : 408 : HOST_WIDE_INT offset = 0;
31274 : : /* For variables that have been optimized away and thus
31275 : : don't have a memory location, see if we can emit
31276 : : DW_AT_const_value instead. */
31277 : 408 : if (tree_add_const_value_attribute (die, init))
31278 : : return;
31279 : 245 : if (dwarf_strict && dwarf_version < 5)
31280 : : return;
31281 : : /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
31282 : : and ADDR_EXPR refers to a decl that has DW_AT_location or
31283 : : DW_AT_const_value (but isn't addressable, otherwise
31284 : : resolving the original DW_OP_addr wouldn't fail), see if
31285 : : we can add DW_OP_implicit_pointer. */
31286 : 245 : STRIP_NOPS (init);
31287 : 245 : if (TREE_CODE (init) == POINTER_PLUS_EXPR
31288 : 245 : && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
31289 : : {
31290 : 0 : offset = tree_to_shwi (TREE_OPERAND (init, 1));
31291 : 0 : init = TREE_OPERAND (init, 0);
31292 : 0 : STRIP_NOPS (init);
31293 : : }
31294 : 245 : if (TREE_CODE (init) != ADDR_EXPR)
31295 : : return;
31296 : 1 : if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
31297 : 0 : && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
31298 : 1 : || (VAR_P (TREE_OPERAND (init, 0))
31299 : 0 : && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
31300 : 0 : && TREE_OPERAND (init, 0) != decl))
31301 : : {
31302 : 0 : dw_die_ref ref;
31303 : 0 : dw_loc_descr_ref l;
31304 : :
31305 : 0 : if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
31306 : : {
31307 : 0 : rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
31308 : 0 : if (!rtl)
31309 : : return;
31310 : 0 : decl = SYMBOL_REF_DECL (rtl);
31311 : : }
31312 : : else
31313 : 0 : decl = TREE_OPERAND (init, 0);
31314 : 0 : ref = lookup_decl_die (decl);
31315 : 0 : if (ref == NULL
31316 : 0 : || (!get_AT (ref, DW_AT_location)
31317 : 0 : && !get_AT (ref, DW_AT_const_value)))
31318 : 0 : return;
31319 : 0 : l = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
31320 : 0 : l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31321 : 0 : l->dw_loc_oprnd1.v.val_die_ref.die = ref;
31322 : 0 : l->dw_loc_oprnd1.v.val_die_ref.external = 0;
31323 : 0 : add_AT_loc (die, DW_AT_location, l);
31324 : : }
31325 : : }
31326 : :
31327 : : /* Return NULL if l is a DWARF expression, or first op that is not
31328 : : valid DWARF expression. */
31329 : :
31330 : : static dw_loc_descr_ref
31331 : 139 : non_dwarf_expression (dw_loc_descr_ref l)
31332 : : {
31333 : 182 : while (l)
31334 : : {
31335 : 181 : if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
31336 : : return l;
31337 : 85 : switch (l->dw_loc_opc)
31338 : : {
31339 : : case DW_OP_regx:
31340 : : case DW_OP_implicit_value:
31341 : : case DW_OP_stack_value:
31342 : : case DW_OP_implicit_pointer:
31343 : : case DW_OP_GNU_implicit_pointer:
31344 : : case DW_OP_GNU_parameter_ref:
31345 : : case DW_OP_piece:
31346 : : case DW_OP_bit_piece:
31347 : : return l;
31348 : 43 : default:
31349 : 43 : break;
31350 : : }
31351 : 43 : l = l->dw_loc_next;
31352 : : }
31353 : : return NULL;
31354 : : }
31355 : :
31356 : : /* Return adjusted copy of EXPR:
31357 : : If it is empty DWARF expression, return it.
31358 : : If it is valid non-empty DWARF expression,
31359 : : return copy of EXPR with DW_OP_deref appended to it.
31360 : : If it is DWARF expression followed by DW_OP_reg{N,x}, return
31361 : : copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
31362 : : If it is DWARF expression followed by DW_OP_stack_value, return
31363 : : copy of the DWARF expression without anything appended.
31364 : : Otherwise, return NULL. */
31365 : :
31366 : : static dw_loc_descr_ref
31367 : 69 : copy_deref_exprloc (dw_loc_descr_ref expr)
31368 : : {
31369 : 69 : dw_loc_descr_ref tail = NULL;
31370 : :
31371 : 69 : if (expr == NULL)
31372 : : return NULL;
31373 : :
31374 : 69 : dw_loc_descr_ref l = non_dwarf_expression (expr);
31375 : 69 : if (l && l->dw_loc_next)
31376 : : return NULL;
31377 : :
31378 : 69 : if (l)
31379 : : {
31380 : 69 : if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
31381 : 48 : tail = new_loc_descr ((enum dwarf_location_atom)
31382 : 48 : (DW_OP_breg0 + (l->dw_loc_opc - DW_OP_reg0)),
31383 : : 0, 0);
31384 : : else
31385 : 21 : switch (l->dw_loc_opc)
31386 : : {
31387 : 0 : case DW_OP_regx:
31388 : 0 : tail = new_loc_descr (DW_OP_bregx,
31389 : : l->dw_loc_oprnd1.v.val_unsigned, 0);
31390 : 0 : break;
31391 : : case DW_OP_stack_value:
31392 : : break;
31393 : : default:
31394 : : return NULL;
31395 : : }
31396 : : }
31397 : : else
31398 : 0 : tail = new_loc_descr (DW_OP_deref, 0, 0);
31399 : :
31400 : 69 : dw_loc_descr_ref ret = NULL, *p = &ret;
31401 : 90 : while (expr != l)
31402 : : {
31403 : 21 : *p = new_loc_descr (expr->dw_loc_opc, 0, 0);
31404 : 21 : (*p)->dw_loc_oprnd1.val_class = expr->dw_loc_oprnd1.val_class;
31405 : 21 : (*p)->dw_loc_oprnd1.val_entry = expr->dw_loc_oprnd1.val_entry;
31406 : 21 : (*p)->dw_loc_oprnd1.v = expr->dw_loc_oprnd1.v;
31407 : 21 : (*p)->dw_loc_oprnd2.val_class = expr->dw_loc_oprnd2.val_class;
31408 : 21 : (*p)->dw_loc_oprnd2.val_entry = expr->dw_loc_oprnd2.val_entry;
31409 : 21 : (*p)->dw_loc_oprnd2.v = expr->dw_loc_oprnd2.v;
31410 : 21 : p = &(*p)->dw_loc_next;
31411 : 21 : expr = expr->dw_loc_next;
31412 : : }
31413 : 69 : *p = tail;
31414 : 69 : return ret;
31415 : : }
31416 : :
31417 : : /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
31418 : : reference to a variable or argument, adjust it if needed and return:
31419 : : -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
31420 : : attribute if present should be removed
31421 : : 0 keep the attribute perhaps with minor modifications, no need to rescan
31422 : : 1 if the attribute has been successfully adjusted. */
31423 : :
31424 : : static int
31425 : 1177 : optimize_string_length (dw_attr_node *a)
31426 : : {
31427 : 1177 : dw_loc_descr_ref l = AT_loc (a), lv;
31428 : 1177 : dw_die_ref die;
31429 : 1177 : if (l->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
31430 : : {
31431 : 0 : tree decl = l->dw_loc_oprnd1.v.val_decl_ref;
31432 : 0 : die = lookup_decl_die (decl);
31433 : 0 : if (die)
31434 : : {
31435 : 0 : l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
31436 : 0 : l->dw_loc_oprnd1.v.val_die_ref.die = die;
31437 : 0 : l->dw_loc_oprnd1.v.val_die_ref.external = 0;
31438 : : }
31439 : : else
31440 : : return -1;
31441 : : }
31442 : : else
31443 : 1177 : die = l->dw_loc_oprnd1.v.val_die_ref.die;
31444 : :
31445 : : /* DWARF5 allows reference class, so we can then reference the DIE.
31446 : : Only do this for DW_OP_GNU_variable_value DW_OP_stack_value. */
31447 : 1177 : if (l->dw_loc_next != NULL && dwarf_version >= 5)
31448 : : {
31449 : 1135 : a->dw_attr_val.val_class = dw_val_class_die_ref;
31450 : 1135 : a->dw_attr_val.val_entry = NULL;
31451 : 1135 : a->dw_attr_val.v.val_die_ref.die = die;
31452 : 1135 : a->dw_attr_val.v.val_die_ref.external = 0;
31453 : 1135 : return 0;
31454 : : }
31455 : :
31456 : 42 : dw_attr_node *av = get_AT (die, DW_AT_location);
31457 : 42 : dw_loc_list_ref d;
31458 : 42 : bool non_dwarf_expr = false;
31459 : :
31460 : 42 : if (av == NULL)
31461 : 68 : return dwarf_strict ? -1 : 0;
31462 : 8 : switch (AT_class (av))
31463 : : {
31464 : 7 : case dw_val_class_loc_list:
31465 : 76 : for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
31466 : 69 : if (d->expr && non_dwarf_expression (d->expr))
31467 : : non_dwarf_expr = true;
31468 : : break;
31469 : 0 : case dw_val_class_view_list:
31470 : 0 : gcc_unreachable ();
31471 : 1 : case dw_val_class_loc:
31472 : 1 : lv = AT_loc (av);
31473 : 1 : if (lv == NULL)
31474 : 0 : return dwarf_strict ? -1 : 0;
31475 : 1 : if (non_dwarf_expression (lv))
31476 : : non_dwarf_expr = true;
31477 : : break;
31478 : 0 : default:
31479 : 0 : return dwarf_strict ? -1 : 0;
31480 : : }
31481 : :
31482 : : /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
31483 : : into DW_OP_call4 or DW_OP_GNU_variable_value into
31484 : : DW_OP_call4 DW_OP_deref, do so. */
31485 : 7 : if (!non_dwarf_expr
31486 : 8 : && (l->dw_loc_next != NULL || AT_class (av) == dw_val_class_loc))
31487 : : {
31488 : 1 : l->dw_loc_opc = DW_OP_call4;
31489 : 1 : if (l->dw_loc_next)
31490 : 0 : l->dw_loc_next = NULL;
31491 : : else
31492 : 1 : l->dw_loc_next = new_loc_descr (DW_OP_deref, 0, 0);
31493 : 1 : return 0;
31494 : : }
31495 : :
31496 : : /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
31497 : : copy over the DW_AT_location attribute from die to a. */
31498 : 7 : if (l->dw_loc_next != NULL)
31499 : : {
31500 : 0 : a->dw_attr_val.val_class = av->dw_attr_val.val_class;
31501 : 0 : a->dw_attr_val.val_entry = av->dw_attr_val.val_entry;
31502 : 0 : a->dw_attr_val.v = av->dw_attr_val.v;
31503 : 0 : return 1;
31504 : : }
31505 : :
31506 : 7 : dw_loc_list_ref list, *p;
31507 : 7 : switch (AT_class (av))
31508 : : {
31509 : 7 : case dw_val_class_loc_list:
31510 : 7 : p = &list;
31511 : 7 : list = NULL;
31512 : 76 : for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
31513 : : {
31514 : 69 : lv = copy_deref_exprloc (d->expr);
31515 : 69 : if (lv)
31516 : : {
31517 : 69 : *p = new_loc_list (lv, d->begin, d->vbegin, d->end, d->vend, d->section);
31518 : 69 : p = &(*p)->dw_loc_next;
31519 : : }
31520 : 0 : else if (!dwarf_strict && d->expr)
31521 : : return 0;
31522 : : }
31523 : 7 : if (list == NULL)
31524 : 0 : return dwarf_strict ? -1 : 0;
31525 : 7 : a->dw_attr_val.val_class = dw_val_class_loc_list;
31526 : 7 : gen_llsym (list);
31527 : 7 : *AT_loc_list_ptr (a) = list;
31528 : 7 : return 1;
31529 : 0 : case dw_val_class_loc:
31530 : 0 : lv = copy_deref_exprloc (AT_loc (av));
31531 : 0 : if (lv == NULL)
31532 : 0 : return dwarf_strict ? -1 : 0;
31533 : 0 : a->dw_attr_val.v.val_loc = lv;
31534 : 0 : return 1;
31535 : 0 : default:
31536 : 0 : gcc_unreachable ();
31537 : : }
31538 : : }
31539 : :
31540 : : /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
31541 : : an address in .rodata section if the string literal is emitted there,
31542 : : or remove the containing location list or replace DW_AT_const_value
31543 : : with DW_AT_location and empty location expression, if it isn't found
31544 : : in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
31545 : : to something that has been emitted in the current CU. */
31546 : :
31547 : : static void
31548 : 80603811 : resolve_addr (dw_die_ref die)
31549 : : {
31550 : 80603811 : dw_die_ref c;
31551 : 80603811 : dw_attr_node *a;
31552 : 80603811 : dw_loc_list_ref *curr, *start, loc;
31553 : 80603811 : unsigned ix;
31554 : 80603811 : bool remove_AT_byte_size = false;
31555 : :
31556 : 383270914 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
31557 : 302667103 : switch (AT_class (a))
31558 : : {
31559 : 11790379 : case dw_val_class_loc_list:
31560 : 11790379 : start = curr = AT_loc_list_ptr (a);
31561 : 11790379 : loc = *curr;
31562 : 11790379 : gcc_assert (loc);
31563 : : /* The same list can be referenced more than once. See if we have
31564 : : already recorded the result from a previous pass. */
31565 : 11790379 : if (loc->replaced)
31566 : 0 : *curr = loc->dw_loc_next;
31567 : 11790379 : else if (!loc->resolved_addr)
31568 : : {
31569 : : /* As things stand, we do not expect or allow one die to
31570 : : reference a suffix of another die's location list chain.
31571 : : References must be identical or completely separate.
31572 : : There is therefore no need to cache the result of this
31573 : : pass on any list other than the first; doing so
31574 : : would lead to unnecessary writes. */
31575 : 36339236 : while (*curr)
31576 : : {
31577 : 24548857 : gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
31578 : 24548857 : if (!resolve_addr_in_expr (a, (*curr)->expr))
31579 : : {
31580 : 743904 : dw_loc_list_ref next = (*curr)->dw_loc_next;
31581 : 743904 : dw_loc_descr_ref l = (*curr)->expr;
31582 : :
31583 : 743904 : if (next && (*curr)->ll_symbol)
31584 : : {
31585 : 153045 : gcc_assert (!next->ll_symbol);
31586 : 153045 : next->ll_symbol = (*curr)->ll_symbol;
31587 : 153045 : next->vl_symbol = (*curr)->vl_symbol;
31588 : : }
31589 : 743904 : if (dwarf_split_debug_info)
31590 : 0 : remove_loc_list_addr_table_entries (l);
31591 : 743904 : *curr = next;
31592 : : }
31593 : : else
31594 : : {
31595 : 23804953 : mark_base_types ((*curr)->expr);
31596 : 23804953 : curr = &(*curr)->dw_loc_next;
31597 : : }
31598 : : }
31599 : 11790379 : if (loc == *start)
31600 : 11206013 : loc->resolved_addr = 1;
31601 : : else
31602 : : {
31603 : 584366 : loc->replaced = 1;
31604 : 584366 : loc->dw_loc_next = *start;
31605 : : }
31606 : : }
31607 : 11790379 : if (!*start)
31608 : : {
31609 : 584176 : remove_AT (die, a->dw_attr);
31610 : 584176 : ix--;
31611 : : }
31612 : : break;
31613 : 11615471 : case dw_val_class_view_list:
31614 : 11615471 : {
31615 : 11615471 : gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
31616 : 11615471 : gcc_checking_assert (dwarf2out_locviews_in_attribute ());
31617 : 11615471 : dw_val_node *llnode
31618 : 11615471 : = view_list_to_loc_list_val_node (&a->dw_attr_val);
31619 : : /* If we no longer have a loclist, or it no longer needs
31620 : : views, drop this attribute. */
31621 : 11615471 : if (!llnode || !llnode->v.val_loc_list->vl_symbol)
31622 : : {
31623 : 584175 : remove_AT (die, a->dw_attr);
31624 : 584175 : ix--;
31625 : : }
31626 : : break;
31627 : : }
31628 : 7731736 : case dw_val_class_loc:
31629 : 7731736 : {
31630 : 7731736 : dw_loc_descr_ref l = AT_loc (a);
31631 : : /* DW_OP_GNU_variable_value DW_OP_stack_value or
31632 : : DW_OP_GNU_variable_value in DW_AT_string_length can be converted
31633 : : into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
31634 : : DWARF4 unlike DW_OP_GNU_variable_value. Or for DWARF5
31635 : : DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
31636 : : with DW_FORM_ref referencing the same DIE as
31637 : : DW_OP_GNU_variable_value used to reference. */
31638 : 7731736 : if (a->dw_attr == DW_AT_string_length
31639 : 1190 : && l
31640 : 1190 : && l->dw_loc_opc == DW_OP_GNU_variable_value
31641 : 1177 : && (l->dw_loc_next == NULL
31642 : 1135 : || (l->dw_loc_next->dw_loc_next == NULL
31643 : 1135 : && l->dw_loc_next->dw_loc_opc == DW_OP_stack_value)))
31644 : : {
31645 : 1177 : switch (optimize_string_length (a))
31646 : : {
31647 : 0 : case -1:
31648 : 0 : remove_AT (die, a->dw_attr);
31649 : 0 : ix--;
31650 : : /* If we drop DW_AT_string_length, we need to drop also
31651 : : DW_AT_{string_length_,}byte_size. */
31652 : 0 : remove_AT_byte_size = true;
31653 : 0 : continue;
31654 : : default:
31655 : : break;
31656 : 7 : case 1:
31657 : : /* Even if we keep the optimized DW_AT_string_length,
31658 : : it might have changed AT_class, so process it again. */
31659 : 7 : ix--;
31660 : 7 : continue;
31661 : : }
31662 : : }
31663 : : /* For -gdwarf-2 don't attempt to optimize
31664 : : DW_AT_data_member_location containing
31665 : : DW_OP_plus_uconst - older consumers might
31666 : : rely on it being that op instead of a more complex,
31667 : : but shorter, location description. */
31668 : 7731729 : if ((dwarf_version > 2
31669 : 10715 : || a->dw_attr != DW_AT_data_member_location
31670 : 1988 : || l == NULL
31671 : 1988 : || l->dw_loc_opc != DW_OP_plus_uconst
31672 : 1982 : || l->dw_loc_next != NULL)
31673 : 7740462 : && !resolve_addr_in_expr (a, l))
31674 : : {
31675 : 7449 : if (dwarf_split_debug_info)
31676 : 0 : remove_loc_list_addr_table_entries (l);
31677 : 7449 : if (l != NULL
31678 : 7449 : && l->dw_loc_next == NULL
31679 : 7250 : && l->dw_loc_opc == DW_OP_addr
31680 : 7043 : && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
31681 : 6938 : && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
31682 : 14387 : && a->dw_attr == DW_AT_location)
31683 : : {
31684 : 571 : tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
31685 : 571 : remove_AT (die, a->dw_attr);
31686 : 571 : ix--;
31687 : 571 : optimize_location_into_implicit_ptr (die, decl);
31688 : 571 : break;
31689 : : }
31690 : 6878 : if (a->dw_attr == DW_AT_string_length)
31691 : : /* If we drop DW_AT_string_length, we need to drop also
31692 : : DW_AT_{string_length_,}byte_size. */
31693 : 0 : remove_AT_byte_size = true;
31694 : 6878 : remove_AT (die, a->dw_attr);
31695 : 6878 : ix--;
31696 : : }
31697 : : else
31698 : 7724280 : mark_base_types (l);
31699 : : }
31700 : : break;
31701 : 1456279 : case dw_val_class_addr:
31702 : 1456279 : if (a->dw_attr == DW_AT_const_value
31703 : 1456279 : && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
31704 : : {
31705 : 0 : if (AT_index (a) != NOT_INDEXED)
31706 : 0 : remove_addr_table_entry (a->dw_attr_val.val_entry);
31707 : 0 : remove_AT (die, a->dw_attr);
31708 : 0 : ix--;
31709 : : }
31710 : 1456279 : if ((die->die_tag == DW_TAG_call_site
31711 : 1455727 : && a->dw_attr == DW_AT_call_origin)
31712 : 552 : || (die->die_tag == DW_TAG_GNU_call_site
31713 : 552 : && a->dw_attr == DW_AT_abstract_origin))
31714 : : {
31715 : 1456279 : tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
31716 : 1456279 : dw_die_ref tdie = lookup_decl_die (tdecl);
31717 : 1456279 : dw_die_ref cdie;
31718 : 1456279 : if (tdie == NULL
31719 : 325215 : && DECL_EXTERNAL (tdecl)
31720 : 294787 : && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
31721 : 1750250 : && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
31722 : : {
31723 : : dw_die_ref pdie = cdie;
31724 : : /* Make sure we don't add these DIEs into type units.
31725 : : We could emit skeleton DIEs for context (namespaces,
31726 : : outer structs/classes) and a skeleton DIE for the
31727 : : innermost context with DW_AT_signature pointing to the
31728 : : type unit. See PR78835. */
31729 : 519409 : while (pdie && pdie->die_tag != DW_TAG_type_unit)
31730 : 259782 : pdie = pdie->die_parent;
31731 : 259627 : if (pdie == NULL)
31732 : : {
31733 : : /* Creating a full DIE for tdecl is overly expensive and
31734 : : at this point even wrong when in the LTO phase
31735 : : as it can end up generating new type DIEs we didn't
31736 : : output and thus optimize_external_refs will crash. */
31737 : 259627 : tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
31738 : 259627 : add_AT_flag (tdie, DW_AT_external, 1);
31739 : 259627 : add_AT_flag (tdie, DW_AT_declaration, 1);
31740 : 259627 : add_linkage_attr (tdie, tdecl);
31741 : 259627 : add_name_and_src_coords_attributes (tdie, tdecl, true);
31742 : 259627 : equate_decl_number_to_die (tdecl, tdie);
31743 : : }
31744 : : }
31745 : 1456279 : if (tdie)
31746 : : {
31747 : 1390691 : a->dw_attr_val.val_class = dw_val_class_die_ref;
31748 : 1390691 : a->dw_attr_val.v.val_die_ref.die = tdie;
31749 : 1390691 : a->dw_attr_val.v.val_die_ref.external = 0;
31750 : : }
31751 : : else
31752 : : {
31753 : 65588 : if (AT_index (a) != NOT_INDEXED)
31754 : 0 : remove_addr_table_entry (a->dw_attr_val.val_entry);
31755 : 65588 : remove_AT (die, a->dw_attr);
31756 : 65588 : ix--;
31757 : : }
31758 : : }
31759 : : break;
31760 : : default:
31761 : : break;
31762 : : }
31763 : :
31764 : 80603811 : if (remove_AT_byte_size)
31765 : 0 : remove_AT (die, dwarf_version >= 5
31766 : : ? DW_AT_string_length_byte_size
31767 : : : DW_AT_byte_size);
31768 : :
31769 : 139436443 : FOR_EACH_CHILD (die, c, resolve_addr (c));
31770 : 80603811 : }
31771 : :
31772 : : /* Helper routines for optimize_location_lists.
31773 : : This pass tries to share identical local lists in .debug_loc
31774 : : section. */
31775 : :
31776 : : /* Iteratively hash operands of LOC opcode into HSTATE. */
31777 : :
31778 : : static void
31779 : 51324944 : hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
31780 : : {
31781 : 51324944 : dw_val_ref val1 = &loc->dw_loc_oprnd1;
31782 : 51324944 : dw_val_ref val2 = &loc->dw_loc_oprnd2;
31783 : :
31784 : 51324944 : switch (loc->dw_loc_opc)
31785 : : {
31786 : 277658 : case DW_OP_const4u:
31787 : 277658 : case DW_OP_const8u:
31788 : 277658 : if (loc->dw_loc_dtprel)
31789 : 235 : goto hash_addr;
31790 : : /* FALLTHRU */
31791 : 17648795 : case DW_OP_const1u:
31792 : 17648795 : case DW_OP_const1s:
31793 : 17648795 : case DW_OP_const2u:
31794 : 17648795 : case DW_OP_const2s:
31795 : 17648795 : case DW_OP_const4s:
31796 : 17648795 : case DW_OP_const8s:
31797 : 17648795 : case DW_OP_constu:
31798 : 17648795 : case DW_OP_consts:
31799 : 17648795 : case DW_OP_pick:
31800 : 17648795 : case DW_OP_plus_uconst:
31801 : 17648795 : case DW_OP_breg0:
31802 : 17648795 : case DW_OP_breg1:
31803 : 17648795 : case DW_OP_breg2:
31804 : 17648795 : case DW_OP_breg3:
31805 : 17648795 : case DW_OP_breg4:
31806 : 17648795 : case DW_OP_breg5:
31807 : 17648795 : case DW_OP_breg6:
31808 : 17648795 : case DW_OP_breg7:
31809 : 17648795 : case DW_OP_breg8:
31810 : 17648795 : case DW_OP_breg9:
31811 : 17648795 : case DW_OP_breg10:
31812 : 17648795 : case DW_OP_breg11:
31813 : 17648795 : case DW_OP_breg12:
31814 : 17648795 : case DW_OP_breg13:
31815 : 17648795 : case DW_OP_breg14:
31816 : 17648795 : case DW_OP_breg15:
31817 : 17648795 : case DW_OP_breg16:
31818 : 17648795 : case DW_OP_breg17:
31819 : 17648795 : case DW_OP_breg18:
31820 : 17648795 : case DW_OP_breg19:
31821 : 17648795 : case DW_OP_breg20:
31822 : 17648795 : case DW_OP_breg21:
31823 : 17648795 : case DW_OP_breg22:
31824 : 17648795 : case DW_OP_breg23:
31825 : 17648795 : case DW_OP_breg24:
31826 : 17648795 : case DW_OP_breg25:
31827 : 17648795 : case DW_OP_breg26:
31828 : 17648795 : case DW_OP_breg27:
31829 : 17648795 : case DW_OP_breg28:
31830 : 17648795 : case DW_OP_breg29:
31831 : 17648795 : case DW_OP_breg30:
31832 : 17648795 : case DW_OP_breg31:
31833 : 17648795 : case DW_OP_regx:
31834 : 17648795 : case DW_OP_fbreg:
31835 : 17648795 : case DW_OP_piece:
31836 : 17648795 : case DW_OP_deref_size:
31837 : 17648795 : case DW_OP_xderef_size:
31838 : 17648795 : hstate.add_object (val1->v.val_int);
31839 : 17648795 : break;
31840 : 119631 : case DW_OP_skip:
31841 : 119631 : case DW_OP_bra:
31842 : 119631 : {
31843 : 119631 : int offset;
31844 : :
31845 : 119631 : gcc_assert (val1->val_class == dw_val_class_loc);
31846 : 119631 : offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
31847 : 119631 : hstate.add_object (offset);
31848 : : }
31849 : 119631 : break;
31850 : 108469 : case DW_OP_implicit_value:
31851 : 108469 : hstate.add_object (val1->v.val_unsigned);
31852 : 108469 : switch (val2->val_class)
31853 : : {
31854 : 49482 : case dw_val_class_const:
31855 : 49482 : hstate.add_object (val2->v.val_int);
31856 : 49482 : break;
31857 : 58346 : case dw_val_class_vec:
31858 : 58346 : {
31859 : 58346 : unsigned int elt_size = val2->v.val_vec.elt_size;
31860 : 58346 : unsigned int len = val2->v.val_vec.length;
31861 : :
31862 : 58346 : hstate.add_int (elt_size);
31863 : 58346 : hstate.add_int (len);
31864 : 58346 : hstate.add (val2->v.val_vec.array, len * elt_size);
31865 : : }
31866 : 58346 : break;
31867 : 0 : case dw_val_class_const_double:
31868 : 0 : hstate.add_object (val2->v.val_double.low);
31869 : 0 : hstate.add_object (val2->v.val_double.high);
31870 : 0 : break;
31871 : 641 : case dw_val_class_wide_int:
31872 : 1282 : hstate.add (val2->v.val_wide->get_val (),
31873 : 641 : get_full_len (*val2->v.val_wide)
31874 : 641 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
31875 : 641 : break;
31876 : 0 : case dw_val_class_addr:
31877 : 0 : inchash::add_rtx (val2->v.val_addr, hstate);
31878 : 0 : break;
31879 : 0 : default:
31880 : 0 : gcc_unreachable ();
31881 : : }
31882 : : break;
31883 : 273484 : case DW_OP_bregx:
31884 : 273484 : case DW_OP_bit_piece:
31885 : 273484 : hstate.add_object (val1->v.val_int);
31886 : 273484 : hstate.add_object (val2->v.val_int);
31887 : 273484 : break;
31888 : 492129 : case DW_OP_addr:
31889 : 492129 : hash_addr:
31890 : 492129 : if (loc->dw_loc_dtprel)
31891 : : {
31892 : 235 : unsigned char dtprel = 0xd1;
31893 : 235 : hstate.add_object (dtprel);
31894 : : }
31895 : 492129 : inchash::add_rtx (val1->v.val_addr, hstate);
31896 : 492129 : break;
31897 : 3 : case DW_OP_GNU_addr_index:
31898 : 3 : case DW_OP_addrx:
31899 : 3 : case DW_OP_GNU_const_index:
31900 : 3 : case DW_OP_constx:
31901 : 3 : {
31902 : 3 : if (loc->dw_loc_dtprel)
31903 : : {
31904 : 0 : unsigned char dtprel = 0xd1;
31905 : 0 : hstate.add_object (dtprel);
31906 : : }
31907 : 3 : inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
31908 : : }
31909 : 3 : break;
31910 : 1217605 : case DW_OP_implicit_pointer:
31911 : 1217605 : case DW_OP_GNU_implicit_pointer:
31912 : 1217605 : hstate.add_int (val2->v.val_int);
31913 : 1217605 : break;
31914 : 1264998 : case DW_OP_entry_value:
31915 : 1264998 : case DW_OP_GNU_entry_value:
31916 : 1264998 : hstate.add_object (val1->v.val_loc);
31917 : 1264998 : break;
31918 : 113702 : case DW_OP_regval_type:
31919 : 113702 : case DW_OP_deref_type:
31920 : 113702 : case DW_OP_GNU_regval_type:
31921 : 113702 : case DW_OP_GNU_deref_type:
31922 : 113702 : {
31923 : 113702 : unsigned int byte_size
31924 : 113702 : = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
31925 : 113702 : unsigned int encoding
31926 : 113702 : = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
31927 : 113702 : hstate.add_object (val1->v.val_int);
31928 : 113702 : hstate.add_object (byte_size);
31929 : 113702 : hstate.add_object (encoding);
31930 : : }
31931 : 113702 : break;
31932 : 166573 : case DW_OP_convert:
31933 : 166573 : case DW_OP_reinterpret:
31934 : 166573 : case DW_OP_GNU_convert:
31935 : 166573 : case DW_OP_GNU_reinterpret:
31936 : 166573 : if (val1->val_class == dw_val_class_unsigned_const)
31937 : : {
31938 : 25317 : hstate.add_object (val1->v.val_unsigned);
31939 : 25317 : break;
31940 : : }
31941 : : /* FALLTHRU */
31942 : 172318 : case DW_OP_const_type:
31943 : 172318 : case DW_OP_GNU_const_type:
31944 : 172318 : {
31945 : 172318 : unsigned int byte_size
31946 : 172318 : = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
31947 : 172318 : unsigned int encoding
31948 : 172318 : = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
31949 : 172318 : hstate.add_object (byte_size);
31950 : 172318 : hstate.add_object (encoding);
31951 : 172318 : if (loc->dw_loc_opc != DW_OP_const_type
31952 : 141256 : && loc->dw_loc_opc != DW_OP_GNU_const_type)
31953 : : break;
31954 : 31062 : hstate.add_object (val2->val_class);
31955 : 31062 : switch (val2->val_class)
31956 : : {
31957 : 8787 : case dw_val_class_const:
31958 : 8787 : hstate.add_object (val2->v.val_int);
31959 : 8787 : break;
31960 : 22163 : case dw_val_class_vec:
31961 : 22163 : {
31962 : 22163 : unsigned int elt_size = val2->v.val_vec.elt_size;
31963 : 22163 : unsigned int len = val2->v.val_vec.length;
31964 : :
31965 : 22163 : hstate.add_object (elt_size);
31966 : 22163 : hstate.add_object (len);
31967 : 22163 : hstate.add (val2->v.val_vec.array, len * elt_size);
31968 : : }
31969 : 22163 : break;
31970 : 20 : case dw_val_class_const_double:
31971 : 20 : hstate.add_object (val2->v.val_double.low);
31972 : 20 : hstate.add_object (val2->v.val_double.high);
31973 : 20 : break;
31974 : 92 : case dw_val_class_wide_int:
31975 : 184 : hstate.add (val2->v.val_wide->get_val (),
31976 : 92 : get_full_len (*val2->v.val_wide)
31977 : 92 : * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
31978 : 92 : break;
31979 : 0 : default:
31980 : 0 : gcc_unreachable ();
31981 : : }
31982 : : }
31983 : 31062 : break;
31984 : :
31985 : : default:
31986 : : /* Other codes have no operands. */
31987 : : break;
31988 : : }
31989 : 51324944 : }
31990 : :
31991 : : /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
31992 : :
31993 : : static inline void
31994 : 23804953 : hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
31995 : : {
31996 : 23804953 : dw_loc_descr_ref l;
31997 : 23804953 : bool sizes_computed = false;
31998 : : /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
31999 : 23804953 : size_of_locs (loc);
32000 : :
32001 : 75129290 : for (l = loc; l != NULL; l = l->dw_loc_next)
32002 : : {
32003 : 51324337 : enum dwarf_location_atom opc = l->dw_loc_opc;
32004 : 51324337 : hstate.add_object (opc);
32005 : 51324337 : if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
32006 : : {
32007 : 68020 : size_of_locs (loc);
32008 : 68020 : sizes_computed = true;
32009 : : }
32010 : 51324337 : hash_loc_operands (l, hstate);
32011 : : }
32012 : 23804953 : }
32013 : :
32014 : : /* Compute hash of the whole location list LIST_HEAD. */
32015 : :
32016 : : static inline void
32017 : 11206203 : hash_loc_list (dw_loc_list_ref list_head)
32018 : : {
32019 : 11206203 : dw_loc_list_ref curr = list_head;
32020 : 11206203 : inchash::hash hstate;
32021 : :
32022 : 35011156 : for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
32023 : : {
32024 : 23804953 : hstate.add (curr->begin, strlen (curr->begin) + 1);
32025 : 23804953 : hstate.add (curr->end, strlen (curr->end) + 1);
32026 : 23804953 : hstate.add_object (curr->vbegin);
32027 : 23804953 : hstate.add_object (curr->vend);
32028 : 23804953 : if (curr->section)
32029 : 23804953 : hstate.add (curr->section, strlen (curr->section) + 1);
32030 : 23804953 : hash_locs (curr->expr, hstate);
32031 : : }
32032 : 11206203 : list_head->hash = hstate.end ();
32033 : 11206203 : }
32034 : :
32035 : : /* Return true if X and Y opcodes have the same operands. */
32036 : :
32037 : : static inline bool
32038 : 611690 : compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
32039 : : {
32040 : 611690 : dw_val_ref valx1 = &x->dw_loc_oprnd1;
32041 : 611690 : dw_val_ref valx2 = &x->dw_loc_oprnd2;
32042 : 611690 : dw_val_ref valy1 = &y->dw_loc_oprnd1;
32043 : 611690 : dw_val_ref valy2 = &y->dw_loc_oprnd2;
32044 : :
32045 : 611690 : switch (x->dw_loc_opc)
32046 : : {
32047 : 5957 : case DW_OP_const4u:
32048 : 5957 : case DW_OP_const8u:
32049 : 5957 : if (x->dw_loc_dtprel)
32050 : 0 : goto hash_addr;
32051 : : /* FALLTHRU */
32052 : 151084 : case DW_OP_const1u:
32053 : 151084 : case DW_OP_const1s:
32054 : 151084 : case DW_OP_const2u:
32055 : 151084 : case DW_OP_const2s:
32056 : 151084 : case DW_OP_const4s:
32057 : 151084 : case DW_OP_const8s:
32058 : 151084 : case DW_OP_constu:
32059 : 151084 : case DW_OP_consts:
32060 : 151084 : case DW_OP_pick:
32061 : 151084 : case DW_OP_plus_uconst:
32062 : 151084 : case DW_OP_breg0:
32063 : 151084 : case DW_OP_breg1:
32064 : 151084 : case DW_OP_breg2:
32065 : 151084 : case DW_OP_breg3:
32066 : 151084 : case DW_OP_breg4:
32067 : 151084 : case DW_OP_breg5:
32068 : 151084 : case DW_OP_breg6:
32069 : 151084 : case DW_OP_breg7:
32070 : 151084 : case DW_OP_breg8:
32071 : 151084 : case DW_OP_breg9:
32072 : 151084 : case DW_OP_breg10:
32073 : 151084 : case DW_OP_breg11:
32074 : 151084 : case DW_OP_breg12:
32075 : 151084 : case DW_OP_breg13:
32076 : 151084 : case DW_OP_breg14:
32077 : 151084 : case DW_OP_breg15:
32078 : 151084 : case DW_OP_breg16:
32079 : 151084 : case DW_OP_breg17:
32080 : 151084 : case DW_OP_breg18:
32081 : 151084 : case DW_OP_breg19:
32082 : 151084 : case DW_OP_breg20:
32083 : 151084 : case DW_OP_breg21:
32084 : 151084 : case DW_OP_breg22:
32085 : 151084 : case DW_OP_breg23:
32086 : 151084 : case DW_OP_breg24:
32087 : 151084 : case DW_OP_breg25:
32088 : 151084 : case DW_OP_breg26:
32089 : 151084 : case DW_OP_breg27:
32090 : 151084 : case DW_OP_breg28:
32091 : 151084 : case DW_OP_breg29:
32092 : 151084 : case DW_OP_breg30:
32093 : 151084 : case DW_OP_breg31:
32094 : 151084 : case DW_OP_regx:
32095 : 151084 : case DW_OP_fbreg:
32096 : 151084 : case DW_OP_piece:
32097 : 151084 : case DW_OP_deref_size:
32098 : 151084 : case DW_OP_xderef_size:
32099 : 151084 : return valx1->v.val_int == valy1->v.val_int;
32100 : 269 : case DW_OP_skip:
32101 : 269 : case DW_OP_bra:
32102 : : /* If splitting debug info, the use of DW_OP_GNU_addr_index
32103 : : can cause irrelevant differences in dw_loc_addr. */
32104 : 269 : gcc_assert (valx1->val_class == dw_val_class_loc
32105 : : && valy1->val_class == dw_val_class_loc
32106 : : && (dwarf_split_debug_info
32107 : : || x->dw_loc_addr == y->dw_loc_addr));
32108 : 269 : return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
32109 : 6537 : case DW_OP_implicit_value:
32110 : 6537 : if (valx1->v.val_unsigned != valy1->v.val_unsigned
32111 : 6537 : || valx2->val_class != valy2->val_class)
32112 : : return false;
32113 : 6537 : switch (valx2->val_class)
32114 : : {
32115 : 5103 : case dw_val_class_const:
32116 : 5103 : return valx2->v.val_int == valy2->v.val_int;
32117 : 1290 : case dw_val_class_vec:
32118 : 1290 : return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
32119 : 1290 : && valx2->v.val_vec.length == valy2->v.val_vec.length
32120 : 1290 : && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
32121 : : valx2->v.val_vec.elt_size
32122 : 1290 : * valx2->v.val_vec.length) == 0;
32123 : 0 : case dw_val_class_const_double:
32124 : 0 : return valx2->v.val_double.low == valy2->v.val_double.low
32125 : 0 : && valx2->v.val_double.high == valy2->v.val_double.high;
32126 : 144 : case dw_val_class_wide_int:
32127 : 144 : return *valx2->v.val_wide == *valy2->v.val_wide;
32128 : 0 : case dw_val_class_addr:
32129 : 0 : return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
32130 : 0 : default:
32131 : 0 : gcc_unreachable ();
32132 : : }
32133 : 0 : case DW_OP_bregx:
32134 : 0 : case DW_OP_bit_piece:
32135 : 0 : return valx1->v.val_int == valy1->v.val_int
32136 : 0 : && valx2->v.val_int == valy2->v.val_int;
32137 : 9148 : case DW_OP_addr:
32138 : 9148 : hash_addr:
32139 : 9148 : return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
32140 : 0 : case DW_OP_GNU_addr_index:
32141 : 0 : case DW_OP_addrx:
32142 : 0 : case DW_OP_GNU_const_index:
32143 : 0 : case DW_OP_constx:
32144 : 0 : {
32145 : 0 : rtx ax1 = valx1->val_entry->addr.rtl;
32146 : 0 : rtx ay1 = valy1->val_entry->addr.rtl;
32147 : 0 : return rtx_equal_p (ax1, ay1);
32148 : : }
32149 : 60157 : case DW_OP_implicit_pointer:
32150 : 60157 : case DW_OP_GNU_implicit_pointer:
32151 : 60157 : return valx1->val_class == dw_val_class_die_ref
32152 : 60157 : && valx1->val_class == valy1->val_class
32153 : 60157 : && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
32154 : 62831 : && valx2->v.val_int == valy2->v.val_int;
32155 : 0 : case DW_OP_entry_value:
32156 : 0 : case DW_OP_GNU_entry_value:
32157 : 0 : return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
32158 : 193 : case DW_OP_const_type:
32159 : 193 : case DW_OP_GNU_const_type:
32160 : 193 : if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
32161 : 193 : || valx2->val_class != valy2->val_class)
32162 : : return false;
32163 : 193 : switch (valx2->val_class)
32164 : : {
32165 : 133 : case dw_val_class_const:
32166 : 133 : return valx2->v.val_int == valy2->v.val_int;
32167 : 60 : case dw_val_class_vec:
32168 : 60 : return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
32169 : 60 : && valx2->v.val_vec.length == valy2->v.val_vec.length
32170 : 60 : && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
32171 : : valx2->v.val_vec.elt_size
32172 : 60 : * valx2->v.val_vec.length) == 0;
32173 : 0 : case dw_val_class_const_double:
32174 : 0 : return valx2->v.val_double.low == valy2->v.val_double.low
32175 : 0 : && valx2->v.val_double.high == valy2->v.val_double.high;
32176 : 0 : case dw_val_class_wide_int:
32177 : 0 : return *valx2->v.val_wide == *valy2->v.val_wide;
32178 : 0 : default:
32179 : 0 : gcc_unreachable ();
32180 : : }
32181 : 1842 : case DW_OP_regval_type:
32182 : 1842 : case DW_OP_deref_type:
32183 : 1842 : case DW_OP_GNU_regval_type:
32184 : 1842 : case DW_OP_GNU_deref_type:
32185 : 1842 : return valx1->v.val_int == valy1->v.val_int
32186 : 1842 : && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
32187 : 1219 : case DW_OP_convert:
32188 : 1219 : case DW_OP_reinterpret:
32189 : 1219 : case DW_OP_GNU_convert:
32190 : 1219 : case DW_OP_GNU_reinterpret:
32191 : 1219 : if (valx1->val_class != valy1->val_class)
32192 : : return false;
32193 : 1219 : if (valx1->val_class == dw_val_class_unsigned_const)
32194 : 6 : return valx1->v.val_unsigned == valy1->v.val_unsigned;
32195 : 1213 : return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
32196 : 4707 : case DW_OP_GNU_parameter_ref:
32197 : 4707 : return valx1->val_class == dw_val_class_die_ref
32198 : 4707 : && valx1->val_class == valy1->val_class
32199 : 9414 : && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
32200 : : default:
32201 : : /* Other codes have no operands. */
32202 : : return true;
32203 : : }
32204 : : }
32205 : :
32206 : : /* Return true if DWARF location expressions X and Y are the same. */
32207 : :
32208 : : static inline bool
32209 : 255263 : compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
32210 : : {
32211 : 804880 : for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
32212 : 611690 : if (x->dw_loc_opc != y->dw_loc_opc
32213 : 611690 : || x->dw_loc_dtprel != y->dw_loc_dtprel
32214 : 1223380 : || !compare_loc_operands (x, y))
32215 : : break;
32216 : 255263 : return x == NULL && y == NULL;
32217 : : }
32218 : :
32219 : : /* Hashtable helpers. */
32220 : :
32221 : : struct loc_list_hasher : nofree_ptr_hash <dw_loc_list_struct>
32222 : : {
32223 : : static inline hashval_t hash (const dw_loc_list_struct *);
32224 : : static inline bool equal (const dw_loc_list_struct *,
32225 : : const dw_loc_list_struct *);
32226 : : };
32227 : :
32228 : : /* Return precomputed hash of location list X. */
32229 : :
32230 : : inline hashval_t
32231 : 66417734 : loc_list_hasher::hash (const dw_loc_list_struct *x)
32232 : : {
32233 : 66417734 : return x->hash;
32234 : : }
32235 : :
32236 : : /* Return true if location lists A and B are the same. */
32237 : :
32238 : : inline bool
32239 : 66093127 : loc_list_hasher::equal (const dw_loc_list_struct *a,
32240 : : const dw_loc_list_struct *b)
32241 : : {
32242 : 66093127 : if (a == b)
32243 : : return true;
32244 : 66093127 : if (a->hash != b->hash)
32245 : : return false;
32246 : 376586 : for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
32247 : 255295 : if (strcmp (a->begin, b->begin) != 0
32248 : 255263 : || strcmp (a->end, b->end) != 0
32249 : 255263 : || (a->section == NULL) != (b->section == NULL)
32250 : 255263 : || (a->section && strcmp (a->section, b->section) != 0)
32251 : 255263 : || a->vbegin != b->vbegin || a->vend != b->vend
32252 : 510558 : || !compare_locs (a->expr, b->expr))
32253 : : break;
32254 : 183396 : return a == NULL && b == NULL;
32255 : : }
32256 : :
32257 : : typedef hash_table<loc_list_hasher> loc_list_hash_type;
32258 : :
32259 : :
32260 : : /* Recursively optimize location lists referenced from DIE
32261 : : children and share them whenever possible. */
32262 : :
32263 : : static void
32264 : 72857347 : optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
32265 : : {
32266 : 72857347 : dw_die_ref c;
32267 : 72857347 : dw_attr_node *a;
32268 : 72857347 : unsigned ix;
32269 : 72857347 : dw_loc_list_struct **slot;
32270 : 72857347 : bool drop_locviews = false;
32271 : 72857347 : bool has_locviews = false;
32272 : :
32273 : 359397398 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
32274 : 286540051 : if (AT_class (a) == dw_val_class_loc_list)
32275 : : {
32276 : 11206203 : dw_loc_list_ref list = AT_loc_list (a);
32277 : : /* TODO: perform some optimizations here, before hashing
32278 : : it and storing into the hash table. */
32279 : 11206203 : hash_loc_list (list);
32280 : 11206203 : slot = htab->find_slot_with_hash (list, list->hash, INSERT);
32281 : 11206203 : if (*slot == NULL)
32282 : : {
32283 : 11084912 : *slot = list;
32284 : 11084912 : if (loc_list_has_views (list))
32285 : 10910870 : gcc_assert (list->vl_symbol);
32286 : 174042 : else if (list->vl_symbol)
32287 : : {
32288 : 0 : drop_locviews = true;
32289 : 0 : list->vl_symbol = NULL;
32290 : : }
32291 : : }
32292 : : else
32293 : : {
32294 : 121291 : if (list->vl_symbol && !(*slot)->vl_symbol)
32295 : 121291 : drop_locviews = true;
32296 : 121291 : a->dw_attr_val.v.val_loc_list = *slot;
32297 : : }
32298 : : }
32299 : 275333848 : else if (AT_class (a) == dw_val_class_view_list)
32300 : : {
32301 : 11031296 : gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
32302 : : has_locviews = true;
32303 : : }
32304 : :
32305 : :
32306 : 72857347 : if (drop_locviews && has_locviews)
32307 : 0 : remove_AT (die, DW_AT_GNU_locviews);
32308 : :
32309 : 145682339 : FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
32310 : 72857347 : }
32311 : :
32312 : :
32313 : : /* Recursively assign each location list a unique index into the debug_addr
32314 : : section. */
32315 : :
32316 : : static void
32317 : 26 : index_location_lists (dw_die_ref die)
32318 : : {
32319 : 26 : dw_die_ref c;
32320 : 26 : dw_attr_node *a;
32321 : 26 : unsigned ix;
32322 : :
32323 : 155 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
32324 : 129 : if (AT_class (a) == dw_val_class_loc_list)
32325 : : {
32326 : 2 : dw_loc_list_ref list = AT_loc_list (a);
32327 : 2 : dw_loc_list_ref curr;
32328 : 8 : for (curr = list; curr != NULL; curr = curr->dw_loc_next)
32329 : : {
32330 : : /* Don't index an entry that has already been indexed
32331 : : or won't be output. Make sure skip_loc_list_entry doesn't
32332 : : call size_of_locs, because that might cause circular dependency,
32333 : : index_location_lists requiring address table indexes to be
32334 : : computed, but adding new indexes through add_addr_table_entry
32335 : : and address table index computation requiring no new additions
32336 : : to the hash table. In the rare case of DWARF[234] >= 64KB
32337 : : location expression, we'll just waste unused address table entry
32338 : : for it. */
32339 : 4 : if (curr->begin_entry != NULL || skip_loc_list_entry (curr))
32340 : 0 : continue;
32341 : :
32342 : 4 : curr->begin_entry
32343 : 4 : = add_addr_table_entry (xstrdup (curr->begin), ate_kind_label);
32344 : 4 : if (dwarf_version >= 5 && !HAVE_AS_LEB128)
32345 : : curr->end_entry
32346 : : = add_addr_table_entry (xstrdup (curr->end), ate_kind_label);
32347 : : }
32348 : : }
32349 : :
32350 : 50 : FOR_EACH_CHILD (die, c, index_location_lists (c));
32351 : 26 : }
32352 : :
32353 : : /* Optimize location lists referenced from DIE
32354 : : children and share them whenever possible. */
32355 : :
32356 : : static void
32357 : 32355 : optimize_location_lists (dw_die_ref die)
32358 : : {
32359 : 32355 : loc_list_hash_type htab (500);
32360 : 32355 : optimize_location_lists_1 (die, &htab);
32361 : 32355 : }
32362 : :
32363 : : /* Traverse the limbo die list, and add parent/child links. The only
32364 : : dies without parents that should be here are concrete instances of
32365 : : inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
32366 : : For concrete instances, we can get the parent die from the abstract
32367 : : instance. */
32368 : :
32369 : : static void
32370 : 104385 : flush_limbo_die_list (void)
32371 : : {
32372 : 104385 : limbo_die_node *node;
32373 : :
32374 : : /* get_context_die calls force_decl_die, which can put new DIEs on the
32375 : : limbo list in LTO mode when nested functions are put in a different
32376 : : partition than that of their parent function. */
32377 : 104385 : while ((node = limbo_die_list))
32378 : : {
32379 : 194546 : dw_die_ref die = node->die;
32380 : 194546 : limbo_die_list = node->next;
32381 : :
32382 : 194546 : if (die->die_parent == NULL)
32383 : : {
32384 : 183770 : dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
32385 : :
32386 : 183770 : if (origin && origin->die_parent)
32387 : 10514 : add_child_die (origin->die_parent, die);
32388 : 472187 : else if (is_cu_die (die))
32389 : : ;
32390 : 120042 : else if (seen_error ())
32391 : : /* It's OK to be confused by errors in the input. */
32392 : 0 : add_child_die (comp_unit_die (), die);
32393 : : else
32394 : : {
32395 : : /* In certain situations, the lexical block containing a
32396 : : nested function can be optimized away, which results
32397 : : in the nested function die being orphaned. Likewise
32398 : : with the return type of that nested function. Force
32399 : : this to be a child of the containing function.
32400 : :
32401 : : It may happen that even the containing function got fully
32402 : : inlined and optimized out. In that case we are lost and
32403 : : assign the empty child. This should not be big issue as
32404 : : the function is likely unreachable too. */
32405 : 120042 : gcc_assert (node->created_for);
32406 : :
32407 : 120042 : if (DECL_P (node->created_for))
32408 : 2788 : origin = get_context_die (DECL_CONTEXT (node->created_for));
32409 : 117254 : else if (TYPE_P (node->created_for))
32410 : 117254 : origin = scope_die_for (node->created_for, comp_unit_die ());
32411 : : else
32412 : 0 : origin = comp_unit_die ();
32413 : :
32414 : 120042 : add_child_die (origin, die);
32415 : : }
32416 : : }
32417 : : }
32418 : 104385 : }
32419 : :
32420 : : /* Reset DIEs so we can output them again. */
32421 : :
32422 : : static void
32423 : 34243 : reset_dies (dw_die_ref die)
32424 : : {
32425 : 34243 : dw_die_ref c;
32426 : :
32427 : : /* Remove stuff we re-generate. */
32428 : 34243 : die->die_mark = 0;
32429 : 34243 : die->die_offset = 0;
32430 : 34243 : die->die_abbrev = 0;
32431 : 34243 : remove_AT (die, DW_AT_sibling);
32432 : :
32433 : 67952 : FOR_EACH_CHILD (die, c, reset_dies (c));
32434 : 34243 : }
32435 : :
32436 : : /* reset_indirect_string removed the references coming from DW_AT_name
32437 : : and DW_AT_comp_dir attributes on compilation unit DIEs. Readd them as
32438 : : .debug_line_str strings again. */
32439 : :
32440 : : static void
32441 : 522 : adjust_name_comp_dir (dw_die_ref die)
32442 : : {
32443 : 1566 : for (int i = 0; i < 2; i++)
32444 : : {
32445 : 1044 : dwarf_attribute attr_kind = i ? DW_AT_comp_dir : DW_AT_name;
32446 : 1044 : dw_attr_node *a = get_AT (die, attr_kind);
32447 : 1044 : if (a == NULL || a->dw_attr_val.val_class != dw_val_class_str)
32448 : 0 : continue;
32449 : :
32450 : 1044 : if (!debug_line_str_hash)
32451 : 522 : debug_line_str_hash
32452 : 522 : = hash_table<indirect_string_hasher>::create_ggc (10);
32453 : :
32454 : 1044 : struct indirect_string_node *node
32455 : 1044 : = find_AT_string_in_table (a->dw_attr_val.v.val_str->str,
32456 : : debug_line_str_hash);
32457 : 1044 : set_indirect_string (node);
32458 : 1044 : node->form = DW_FORM_line_strp;
32459 : 1044 : a->dw_attr_val.v.val_str = node;
32460 : : }
32461 : 522 : }
32462 : :
32463 : : /* Output stuff that dwarf requires at the end of every file,
32464 : : and generate the DWARF-2 debugging info. */
32465 : :
32466 : : static void
32467 : 52409 : dwarf2out_finish (const char *filename)
32468 : : {
32469 : 52409 : comdat_type_node *ctnode;
32470 : 52409 : dw_die_ref main_comp_unit_die;
32471 : 52409 : unsigned char checksum[16];
32472 : 52409 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
32473 : :
32474 : : /* Generate CTF/BTF debug info. */
32475 : 52409 : if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
32476 : 52409 : || btf_debuginfo_p ()) && lang_GNU_C ())
32477 : 405 : ctf_debug_finish ();
32478 : :
32479 : : #ifdef CODEVIEW_DEBUGGING_INFO
32480 : : if (codeview_debuginfo_p ())
32481 : : codeview_debug_finish ();
32482 : : #endif
32483 : :
32484 : : /* Skip emitting DWARF if not required. */
32485 : 52409 : if (!dwarf_debuginfo_p ())
32486 : 435 : return;
32487 : :
32488 : : /* Flush out any latecomers to the limbo party. */
32489 : 51974 : flush_limbo_die_list ();
32490 : :
32491 : 51974 : if (inline_entry_data_table)
32492 : 12704 : gcc_assert (inline_entry_data_table->is_empty ());
32493 : :
32494 : 51974 : if (flag_checking)
32495 : : {
32496 : 51973 : verify_die (comp_unit_die ());
32497 : 51973 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32498 : 0 : verify_die (node->die);
32499 : : }
32500 : :
32501 : : /* We shouldn't have any symbols with delayed asm names for
32502 : : DIEs generated after early finish. */
32503 : 51974 : gcc_assert (deferred_asm_name == NULL);
32504 : :
32505 : 51974 : gen_remaining_tmpl_value_param_die_attribute ();
32506 : :
32507 : 51974 : if (flag_generate_lto || flag_generate_offload)
32508 : : {
32509 : 532 : gcc_assert (flag_fat_lto_objects || flag_generate_offload);
32510 : :
32511 : : /* Prune stuff so that dwarf2out_finish runs successfully
32512 : : for the fat part of the object. */
32513 : 532 : reset_dies (comp_unit_die ());
32514 : 532 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32515 : 0 : reset_dies (node->die);
32516 : 534 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32517 : : {
32518 : : /* Remove the pointer to the line table. */
32519 : 2 : remove_AT (ctnode->root_die, DW_AT_stmt_list);
32520 : 2 : if (debug_info_level >= DINFO_LEVEL_TERSE)
32521 : 2 : reset_dies (ctnode->root_die);
32522 : : }
32523 : :
32524 : : /* Reset die CU symbol so we don't output it twice. */
32525 : 532 : comp_unit_die ()->die_id.die_symbol = NULL;
32526 : :
32527 : : /* Remove DW_AT_macro and DW_AT_stmt_list from the early output. */
32528 : 532 : remove_AT (comp_unit_die (), DW_AT_stmt_list);
32529 : 532 : if (have_macinfo)
32530 : 6 : remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE);
32531 : :
32532 : : /* Remove indirect string decisions. */
32533 : 18517 : debug_str_hash->traverse<void *, reset_indirect_string> (NULL);
32534 : 532 : if (debug_line_str_hash)
32535 : : {
32536 : 522 : debug_line_str_hash->traverse<void *, reset_indirect_string> (NULL);
32537 : 522 : debug_line_str_hash = NULL;
32538 : 522 : if (asm_outputs_debug_line_str ())
32539 : : {
32540 : 522 : adjust_name_comp_dir (comp_unit_die ());
32541 : 522 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
32542 : 0 : adjust_name_comp_dir (node->die);
32543 : : }
32544 : : }
32545 : : }
32546 : :
32547 : : #if ENABLE_ASSERT_CHECKING
32548 : 51974 : {
32549 : 51974 : dw_die_ref die = comp_unit_die (), c;
32550 : 9931935 : FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
32551 : : }
32552 : : #endif
32553 : 51974 : base_types.truncate (0);
32554 : 52050 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32555 : 76 : resolve_addr (ctnode->root_die);
32556 : 51974 : resolve_addr (comp_unit_die ());
32557 : 51974 : move_marked_base_types ();
32558 : :
32559 : 51974 : if (dump_file)
32560 : : {
32561 : 4 : fprintf (dump_file, "DWARF for %s\n", filename);
32562 : 4 : print_die (comp_unit_die (), dump_file);
32563 : : }
32564 : :
32565 : : /* Initialize sections and labels used for actual assembler output. */
32566 : 51974 : unsigned generation = init_sections_and_labels (false);
32567 : :
32568 : : /* Traverse the DIE's and add sibling attributes to those DIE's that
32569 : : have children. */
32570 : 51974 : add_sibling_attributes (comp_unit_die ());
32571 : 51974 : limbo_die_node *node;
32572 : 51974 : for (node = cu_die_list; node; node = node->next)
32573 : 0 : add_sibling_attributes (node->die);
32574 : 52050 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32575 : 76 : add_sibling_attributes (ctnode->root_die);
32576 : :
32577 : : /* When splitting DWARF info, we put some attributes in the
32578 : : skeleton compile_unit DIE that remains in the .o, while
32579 : : most attributes go in the DWO compile_unit_die. */
32580 : 51974 : if (dwarf_split_debug_info)
32581 : : {
32582 : 249 : limbo_die_node *cu;
32583 : 249 : main_comp_unit_die = gen_compile_unit_die (NULL);
32584 : 249 : if (dwarf_version >= 5)
32585 : 248 : main_comp_unit_die->die_tag = DW_TAG_skeleton_unit;
32586 : 249 : cu = limbo_die_list;
32587 : 249 : gcc_assert (cu->die == main_comp_unit_die);
32588 : 249 : limbo_die_list = limbo_die_list->next;
32589 : 249 : cu->next = cu_die_list;
32590 : 249 : cu_die_list = cu;
32591 : : }
32592 : : else
32593 : 51725 : main_comp_unit_die = comp_unit_die ();
32594 : :
32595 : : /* Output a terminator label for the .text section. */
32596 : 51974 : switch_to_section (text_section);
32597 : 51974 : targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
32598 : 51974 : if (cold_text_section)
32599 : : {
32600 : 8633 : switch_to_section (cold_text_section);
32601 : 8633 : targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
32602 : : }
32603 : :
32604 : : /* We can only use the low/high_pc attributes if all of the code was
32605 : : in .text. */
32606 : 51974 : if ((!have_multiple_function_sections
32607 : 24065 : && vec_safe_length (switch_text_ranges) < 2)
32608 : 51993 : || (dwarf_version < 3 && dwarf_strict))
32609 : : {
32610 : 24046 : const char *end_label = text_end_label;
32611 : 24046 : if (vec_safe_length (switch_text_ranges) == 1)
32612 : 187 : end_label = (*switch_text_ranges)[0];
32613 : : /* Don't add if the CU has no associated code. */
32614 : 24046 : if (switch_text_ranges)
32615 : 19211 : add_AT_low_high_pc (main_comp_unit_die, text_section_label,
32616 : : end_label, true);
32617 : : }
32618 : : else
32619 : : {
32620 : 27928 : unsigned fde_idx;
32621 : 27928 : dw_fde_ref fde;
32622 : 27928 : bool range_list_added = false;
32623 : 27928 : if (switch_text_ranges)
32624 : : {
32625 : : const char *prev_loc = text_section_label;
32626 : : const char *loc;
32627 : : unsigned idx;
32628 : :
32629 : 10714 : FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
32630 : 838 : if (prev_loc)
32631 : : {
32632 : 439 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32633 : : loc, &range_list_added, true);
32634 : 439 : prev_loc = NULL;
32635 : : }
32636 : : else
32637 : : prev_loc = loc;
32638 : :
32639 : 9876 : if (prev_loc)
32640 : 9836 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32641 : : text_end_label, &range_list_added, true);
32642 : : }
32643 : :
32644 : 27928 : if (switch_cold_ranges)
32645 : : {
32646 : : const char *prev_loc = cold_text_section_label;
32647 : : const char *loc;
32648 : : unsigned idx;
32649 : :
32650 : 8633 : FOR_EACH_VEC_ELT (*switch_cold_ranges, idx, loc)
32651 : 0 : if (prev_loc)
32652 : : {
32653 : 0 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32654 : : loc, &range_list_added, true);
32655 : 0 : prev_loc = NULL;
32656 : : }
32657 : : else
32658 : : prev_loc = loc;
32659 : :
32660 : 8633 : if (prev_loc)
32661 : 8633 : add_ranges_by_labels (main_comp_unit_die, prev_loc,
32662 : : cold_end_label, &range_list_added, true);
32663 : : }
32664 : :
32665 : 290201 : FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
32666 : : {
32667 : 262273 : if (fde->ignored_debug)
32668 : 2882 : continue;
32669 : 259391 : if (!fde->in_std_section)
32670 : 189327 : add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
32671 : : fde->dw_fde_end, &range_list_added,
32672 : : true);
32673 : 259391 : if (fde->dw_fde_second_begin && !fde->second_in_std_section)
32674 : 8982 : add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
32675 : : fde->dw_fde_second_end, &range_list_added,
32676 : : true);
32677 : : }
32678 : :
32679 : 27928 : if (range_list_added)
32680 : : {
32681 : : /* We need to give .debug_loc and .debug_ranges an appropriate
32682 : : "base address". Use zero so that these addresses become
32683 : : absolute. Historically, we've emitted the unexpected
32684 : : DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
32685 : : Emit both to give time for other tools to adapt. */
32686 : 27928 : add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
32687 : 27928 : if (! dwarf_strict && dwarf_version < 4)
32688 : 428 : add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
32689 : :
32690 : 27928 : add_ranges (NULL);
32691 : 27928 : have_multiple_function_sections = true;
32692 : : }
32693 : : }
32694 : :
32695 : : /* AIX Assembler inserts the length, so adjust the reference to match the
32696 : : offset expected by debuggers. */
32697 : 51974 : strcpy (dl_section_ref, debug_line_section_label);
32698 : 51974 : if (XCOFF_DEBUGGING_INFO)
32699 : : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
32700 : :
32701 : 51974 : if (debug_info_level >= DINFO_LEVEL_TERSE)
32702 : 51974 : add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
32703 : : dl_section_ref);
32704 : :
32705 : 51974 : if (have_macinfo)
32706 : 1000 : add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
32707 : : macinfo_section_label);
32708 : :
32709 : 51974 : if (dwarf_split_debug_info)
32710 : : {
32711 : 249 : if (have_location_lists)
32712 : : {
32713 : : /* Since we generate the loclists in the split DWARF .dwo
32714 : : file itself, we don't need to generate a loclists_base
32715 : : attribute for the split compile unit DIE. That attribute
32716 : : (and using relocatable sec_offset FORMs) isn't allowed
32717 : : for a split compile unit. Only if the .debug_loclists
32718 : : section was in the main file, would we need to generate a
32719 : : loclists_base attribute here (for the full or skeleton
32720 : : unit DIE). */
32721 : :
32722 : : /* optimize_location_lists calculates the size of the lists,
32723 : : so index them first, and assign indices to the entries.
32724 : : Although optimize_location_lists will remove entries from
32725 : : the table, it only does so for duplicates, and therefore
32726 : : only reduces ref_counts to 1. */
32727 : 2 : index_location_lists (comp_unit_die ());
32728 : : }
32729 : :
32730 : 249 : if (dwarf_version >= 5 && !vec_safe_is_empty (ranges_table))
32731 : 3 : index_rnglists ();
32732 : :
32733 : 249 : if (addr_index_table != NULL)
32734 : : {
32735 : 244 : unsigned int index = 0;
32736 : 244 : addr_index_table
32737 : : ->traverse_noresize<unsigned int *, index_addr_table_entry>
32738 : 508 : (&index);
32739 : : }
32740 : : }
32741 : :
32742 : 51974 : loc_list_idx = 0;
32743 : 51974 : if (have_location_lists)
32744 : : {
32745 : 32355 : optimize_location_lists (comp_unit_die ());
32746 : : /* And finally assign indexes to the entries for -gsplit-dwarf. */
32747 : 32355 : if (dwarf_version >= 5 && dwarf_split_debug_info)
32748 : 2 : assign_location_list_indexes (comp_unit_die ());
32749 : : }
32750 : :
32751 : 51974 : save_macinfo_strings ();
32752 : :
32753 : 51974 : if (dwarf_split_debug_info)
32754 : : {
32755 : 249 : unsigned int index = 0;
32756 : :
32757 : : /* Add attributes common to skeleton compile_units and
32758 : : type_units. Because these attributes include strings, it
32759 : : must be done before freezing the string table. Top-level
32760 : : skeleton die attrs are added when the skeleton type unit is
32761 : : created, so ensure it is created by this point. */
32762 : 249 : add_top_level_skeleton_die_attrs (main_comp_unit_die);
32763 : 3176 : debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
32764 : : }
32765 : :
32766 : : /* Output all of the compilation units. We put the main one last so that
32767 : : the offsets are available to output_pubnames. */
32768 : 52223 : for (node = cu_die_list; node; node = node->next)
32769 : 249 : output_comp_unit (node->die, 0, NULL);
32770 : :
32771 : 51974 : hash_table<comdat_type_hasher> comdat_type_table (100);
32772 : 52050 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
32773 : : {
32774 : 76 : comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
32775 : :
32776 : : /* Don't output duplicate types. */
32777 : 76 : if (*slot != HTAB_EMPTY_ENTRY)
32778 : 1 : continue;
32779 : :
32780 : : /* Add a pointer to the line table for the main compilation unit
32781 : : so that the debugger can make sense of DW_AT_decl_file
32782 : : attributes. */
32783 : 75 : if (debug_info_level >= DINFO_LEVEL_TERSE)
32784 : 75 : add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
32785 : 75 : (!dwarf_split_debug_info
32786 : : ? dl_section_ref
32787 : : : debug_skeleton_line_section_label));
32788 : :
32789 : 75 : output_comdat_type_unit (ctnode, false);
32790 : 75 : *slot = ctnode;
32791 : : }
32792 : :
32793 : 51974 : if (dwarf_split_debug_info)
32794 : : {
32795 : 249 : int mark;
32796 : 249 : struct md5_ctx ctx;
32797 : :
32798 : : /* Compute a checksum of the comp_unit to use as the dwo_id. */
32799 : 249 : md5_init_ctx (&ctx);
32800 : 249 : mark = 0;
32801 : 249 : die_checksum (comp_unit_die (), &ctx, &mark);
32802 : 249 : unmark_all_dies (comp_unit_die ());
32803 : 249 : md5_finish_ctx (&ctx, checksum);
32804 : :
32805 : 249 : if (dwarf_version < 5)
32806 : : {
32807 : : /* Use the first 8 bytes of the checksum as the dwo_id,
32808 : : and add it to both comp-unit DIEs. */
32809 : 1 : add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
32810 : 1 : add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
32811 : : }
32812 : :
32813 : : /* Add the base offset of the ranges table to the skeleton
32814 : : comp-unit DIE. */
32815 : 249 : if (!vec_safe_is_empty (ranges_table))
32816 : : {
32817 : 3 : if (dwarf_version < 5)
32818 : 0 : add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
32819 : : ranges_section_label);
32820 : : }
32821 : :
32822 : 249 : output_addr_table ();
32823 : : }
32824 : :
32825 : : /* Output the main compilation unit if non-empty or if .debug_macinfo
32826 : : or .debug_macro will be emitted. */
32827 : 103438 : output_comp_unit (comp_unit_die (), have_macinfo,
32828 : 51974 : dwarf_split_debug_info ? checksum : NULL);
32829 : :
32830 : 51974 : if (dwarf_split_debug_info && info_section_emitted)
32831 : 249 : output_skeleton_debug_sections (main_comp_unit_die, checksum);
32832 : :
32833 : : /* Output the abbreviation table. */
32834 : 51974 : if (vec_safe_length (abbrev_die_table) != 1)
32835 : : {
32836 : 50927 : switch_to_section (debug_abbrev_section);
32837 : 50927 : ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
32838 : 50927 : output_abbrev_section ();
32839 : : }
32840 : :
32841 : : /* Output location list section if necessary. */
32842 : 51974 : if (have_location_lists)
32843 : : {
32844 : 32355 : char l1[MAX_ARTIFICIAL_LABEL_BYTES];
32845 : 32355 : char l2[MAX_ARTIFICIAL_LABEL_BYTES];
32846 : : /* Output the location lists info. */
32847 : 32355 : switch_to_section (debug_loc_section);
32848 : 32355 : if (dwarf_version >= 5)
32849 : : {
32850 : 31282 : ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_LOC_SECTION_LABEL, 2);
32851 : 31282 : ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_LOC_SECTION_LABEL, 3);
32852 : 31282 : if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
32853 : 0 : dw2_asm_output_data (4, 0xffffffff,
32854 : : "Initial length escape value indicating "
32855 : : "64-bit DWARF extension");
32856 : 31282 : dw2_asm_output_delta (dwarf_offset_size, l2, l1,
32857 : : "Length of Location Lists");
32858 : 31282 : ASM_OUTPUT_LABEL (asm_out_file, l1);
32859 : 31282 : output_dwarf_version ();
32860 : 35188 : dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
32861 : 31282 : dw2_asm_output_data (1, 0, "Segment Size");
32862 : 31282 : dw2_asm_output_data (4, dwarf_split_debug_info ? loc_list_idx : 0,
32863 : : "Offset Entry Count");
32864 : : }
32865 : 32355 : ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
32866 : 32355 : if (dwarf_version >= 5 && dwarf_split_debug_info)
32867 : : {
32868 : 2 : unsigned int save_loc_list_idx = loc_list_idx;
32869 : 2 : loc_list_idx = 0;
32870 : 2 : output_loclists_offsets (comp_unit_die ());
32871 : 2 : gcc_assert (save_loc_list_idx == loc_list_idx);
32872 : : }
32873 : 32355 : output_location_lists (comp_unit_die ());
32874 : 32355 : if (dwarf_version >= 5)
32875 : 31282 : ASM_OUTPUT_LABEL (asm_out_file, l2);
32876 : : }
32877 : :
32878 : 51974 : output_pubtables ();
32879 : :
32880 : : /* Output the address range information if a CU (.debug_info section)
32881 : : was emitted. We output an empty table even if we had no functions
32882 : : to put in it. This because the consumer has no way to tell the
32883 : : difference between an empty table that we omitted and failure to
32884 : : generate a table that would have contained data. */
32885 : 51974 : if (info_section_emitted)
32886 : : {
32887 : 50925 : switch_to_section (debug_aranges_section);
32888 : 50925 : output_aranges ();
32889 : : }
32890 : :
32891 : : /* Output ranges section if necessary. */
32892 : 51974 : if (!vec_safe_is_empty (ranges_table))
32893 : : {
32894 : 32551 : if (dwarf_version >= 5)
32895 : : {
32896 : 32023 : if (dwarf_split_debug_info)
32897 : : {
32898 : : /* We don't know right now whether there are any
32899 : : ranges for .debug_rnglists and any for .debug_rnglists.dwo.
32900 : : Depending on into which of those two belongs the first
32901 : : ranges_table entry, emit that section first and that
32902 : : output_rnglists call will return true if the other kind of
32903 : : ranges needs to be emitted as well. */
32904 : 3 : bool dwo = (*ranges_table)[0].idx != DW_RANGES_IDX_SKELETON;
32905 : 3 : if (output_rnglists (generation, dwo))
32906 : 2 : output_rnglists (generation, !dwo);
32907 : : }
32908 : : else
32909 : 32020 : output_rnglists (generation, false);
32910 : : }
32911 : : else
32912 : 528 : output_ranges ();
32913 : : }
32914 : :
32915 : : /* Have to end the macro section. */
32916 : 51974 : if (have_macinfo)
32917 : : {
32918 : 510 : switch_to_section (debug_macinfo_section);
32919 : 510 : ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
32920 : 514 : output_macinfo (!dwarf_split_debug_info ? debug_line_section_label
32921 : : : debug_skeleton_line_section_label, false);
32922 : 510 : dw2_asm_output_data (1, 0, "End compilation unit");
32923 : : }
32924 : :
32925 : : /* Output the source line correspondence table. We must do this
32926 : : even if there is no line information. Otherwise, on an empty
32927 : : translation unit, we will generate a present, but empty,
32928 : : .debug_info section. IRIX 6.5 `nm' will then complain when
32929 : : examining the file. This is done late so that any filenames
32930 : : used by the debug_info section are marked as 'used'. */
32931 : 51974 : switch_to_section (debug_line_section);
32932 : 51974 : ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
32933 : 51974 : if (! output_asm_line_debug_info ())
32934 : 6 : output_line_info (false);
32935 : :
32936 : 51974 : if (dwarf_split_debug_info && info_section_emitted)
32937 : : {
32938 : 249 : switch_to_section (debug_skeleton_line_section);
32939 : 249 : ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
32940 : 249 : output_line_info (true);
32941 : : }
32942 : :
32943 : : /* If we emitted any indirect strings, output the string table too. */
32944 : 51974 : if (debug_str_hash || skeleton_debug_str_hash)
32945 : 51974 : output_indirect_strings ();
32946 : 51974 : if (debug_line_str_hash)
32947 : : {
32948 : 49719 : switch_to_section (debug_line_str_section);
32949 : 49719 : const enum dwarf_form form = DW_FORM_line_strp;
32950 : 49719 : debug_line_str_hash->traverse<enum dwarf_form,
32951 : 49719 : output_indirect_string> (form);
32952 : : }
32953 : :
32954 : : /* ??? Move lvugid out of dwarf2out_source_line and reset it too? */
32955 : 51974 : symview_upper_bound = 0;
32956 : 51974 : if (zero_view_p)
32957 : 40585 : bitmap_clear (zero_view_p);
32958 : 51974 : }
32959 : :
32960 : : /* Returns a hash value for X (which really is a variable_value_struct). */
32961 : :
32962 : : inline hashval_t
32963 : 5211 : variable_value_hasher::hash (variable_value_struct *x)
32964 : : {
32965 : 5211 : return (hashval_t) x->decl_id;
32966 : : }
32967 : :
32968 : : /* Return true if decl_id of variable_value_struct X is the same as
32969 : : UID of decl Y. */
32970 : :
32971 : : inline bool
32972 : 5815 : variable_value_hasher::equal (variable_value_struct *x, tree y)
32973 : : {
32974 : 5815 : return x->decl_id == DECL_UID (y);
32975 : : }
32976 : :
32977 : : /* Helper function for resolve_variable_value, handle
32978 : : DW_OP_GNU_variable_value in one location expression.
32979 : : Return true if exprloc has been changed into loclist. */
32980 : :
32981 : : static bool
32982 : 606 : resolve_variable_value_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
32983 : : {
32984 : 606 : dw_loc_descr_ref next;
32985 : 2091 : for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = next)
32986 : : {
32987 : 1488 : next = loc->dw_loc_next;
32988 : 1488 : if (loc->dw_loc_opc != DW_OP_GNU_variable_value
32989 : 596 : || loc->dw_loc_oprnd1.val_class != dw_val_class_decl_ref)
32990 : 892 : continue;
32991 : :
32992 : 596 : tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
32993 : 596 : if (DECL_CONTEXT (decl) != current_function_decl)
32994 : 0 : continue;
32995 : :
32996 : 596 : dw_die_ref ref = lookup_decl_die (decl);
32997 : 596 : if (ref)
32998 : : {
32999 : 0 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33000 : 0 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33001 : 0 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33002 : 0 : continue;
33003 : : }
33004 : 596 : dw_loc_list_ref l = loc_list_from_tree (decl, 0, NULL);
33005 : 596 : if (l == NULL)
33006 : 120 : continue;
33007 : 476 : if (l->dw_loc_next)
33008 : : {
33009 : 246 : if (AT_class (a) != dw_val_class_loc)
33010 : 0 : continue;
33011 : 246 : switch (a->dw_attr)
33012 : : {
33013 : : /* Following attributes allow both exprloc and loclist
33014 : : classes, so we can change them into a loclist. */
33015 : 3 : case DW_AT_location:
33016 : 3 : case DW_AT_string_length:
33017 : 3 : case DW_AT_return_addr:
33018 : 3 : case DW_AT_data_member_location:
33019 : 3 : case DW_AT_frame_base:
33020 : 3 : case DW_AT_segment:
33021 : 3 : case DW_AT_static_link:
33022 : 3 : case DW_AT_use_location:
33023 : 3 : case DW_AT_vtable_elem_location:
33024 : 3 : if (prev)
33025 : : {
33026 : 0 : prev->dw_loc_next = NULL;
33027 : 0 : prepend_loc_descr_to_each (l, AT_loc (a));
33028 : : }
33029 : 3 : if (next)
33030 : 3 : add_loc_descr_to_each (l, next);
33031 : 3 : a->dw_attr_val.val_class = dw_val_class_loc_list;
33032 : 3 : a->dw_attr_val.val_entry = NULL;
33033 : 3 : a->dw_attr_val.v.val_loc_list = l;
33034 : 3 : have_location_lists = true;
33035 : 3 : return true;
33036 : : /* Following attributes allow both exprloc and reference,
33037 : : so if the whole expression is DW_OP_GNU_variable_value alone
33038 : : we could transform it into reference. */
33039 : 243 : case DW_AT_byte_size:
33040 : 243 : case DW_AT_bit_size:
33041 : 243 : case DW_AT_lower_bound:
33042 : 243 : case DW_AT_upper_bound:
33043 : 243 : case DW_AT_bit_stride:
33044 : 243 : case DW_AT_count:
33045 : 243 : case DW_AT_allocated:
33046 : 243 : case DW_AT_associated:
33047 : 243 : case DW_AT_byte_stride:
33048 : 243 : if (prev == NULL && next == NULL)
33049 : : break;
33050 : : /* FALLTHRU */
33051 : 0 : default:
33052 : 0 : if (dwarf_strict)
33053 : 0 : continue;
33054 : : break;
33055 : : }
33056 : : /* Create DW_TAG_variable that we can refer to. */
33057 : 243 : gen_decl_die (decl, NULL_TREE, NULL,
33058 : : lookup_decl_die (current_function_decl));
33059 : 243 : ref = lookup_decl_die (decl);
33060 : 243 : if (ref)
33061 : : {
33062 : 243 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33063 : 243 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33064 : 243 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33065 : : }
33066 : 243 : continue;
33067 : : }
33068 : 230 : if (prev)
33069 : : {
33070 : 0 : prev->dw_loc_next = l->expr;
33071 : 0 : add_loc_descr (&prev->dw_loc_next, next);
33072 : 0 : free_loc_descr (loc, NULL);
33073 : 0 : next = prev->dw_loc_next;
33074 : : }
33075 : : else
33076 : : {
33077 : 230 : memcpy (loc, l->expr, sizeof (dw_loc_descr_node));
33078 : 230 : add_loc_descr (&loc, next);
33079 : 230 : next = loc;
33080 : : }
33081 : 230 : loc = prev;
33082 : : }
33083 : : return false;
33084 : : }
33085 : :
33086 : : /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree. */
33087 : :
33088 : : static void
33089 : 596 : resolve_variable_value (dw_die_ref die)
33090 : : {
33091 : 596 : dw_attr_node *a;
33092 : 596 : dw_loc_list_ref loc;
33093 : 596 : unsigned ix;
33094 : :
33095 : 1884 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
33096 : 1288 : switch (AT_class (a))
33097 : : {
33098 : 596 : case dw_val_class_loc:
33099 : 596 : if (!resolve_variable_value_in_expr (a, AT_loc (a)))
33100 : : break;
33101 : : /* FALLTHRU */
33102 : 3 : case dw_val_class_loc_list:
33103 : 3 : loc = AT_loc_list (a);
33104 : 3 : gcc_assert (loc);
33105 : 13 : for (; loc; loc = loc->dw_loc_next)
33106 : 10 : resolve_variable_value_in_expr (a, loc->expr);
33107 : : break;
33108 : : default:
33109 : : break;
33110 : : }
33111 : 596 : }
33112 : :
33113 : : /* Attempt to optimize DW_OP_GNU_variable_value refering to
33114 : : temporaries in the current function. */
33115 : :
33116 : : static void
33117 : 557714 : resolve_variable_values (void)
33118 : : {
33119 : 557714 : if (!variable_value_hash || !current_function_decl)
33120 : : return;
33121 : :
33122 : 2351 : struct variable_value_struct *node
33123 : 2351 : = variable_value_hash->find_with_hash (current_function_decl,
33124 : 2351 : DECL_UID (current_function_decl));
33125 : :
33126 : 2351 : if (node == NULL)
33127 : : return;
33128 : :
33129 : : unsigned int i;
33130 : : dw_die_ref die;
33131 : 1048 : FOR_EACH_VEC_SAFE_ELT (node->dies, i, die)
33132 : 596 : resolve_variable_value (die);
33133 : : }
33134 : :
33135 : : /* Helper function for note_variable_value, handle one location
33136 : : expression. */
33137 : :
33138 : : static void
33139 : 118695 : note_variable_value_in_expr (dw_die_ref die, dw_loc_descr_ref loc)
33140 : : {
33141 : 348536 : for (; loc; loc = loc->dw_loc_next)
33142 : 229841 : if (loc->dw_loc_opc == DW_OP_GNU_variable_value
33143 : 4961 : && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
33144 : : {
33145 : 750 : tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
33146 : 750 : dw_die_ref ref = lookup_decl_die (decl);
33147 : 750 : if (! ref && (flag_generate_lto || flag_generate_offload))
33148 : : {
33149 : : /* ??? This is somewhat a hack because we do not create DIEs
33150 : : for variables not in BLOCK trees early but when generating
33151 : : early LTO output we need the dw_val_class_decl_ref to be
33152 : : fully resolved. For fat LTO objects we'd also like to
33153 : : undo this after LTO dwarf output. */
33154 : 67 : gcc_assert (DECL_CONTEXT (decl));
33155 : 67 : dw_die_ref ctx = lookup_decl_die (DECL_CONTEXT (decl));
33156 : 67 : gcc_assert (ctx != NULL);
33157 : 67 : gen_decl_die (decl, NULL_TREE, NULL, ctx);
33158 : 67 : ref = lookup_decl_die (decl);
33159 : 67 : gcc_assert (ref != NULL);
33160 : : }
33161 : 750 : if (ref)
33162 : : {
33163 : 67 : loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
33164 : 67 : loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
33165 : 67 : loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
33166 : 67 : continue;
33167 : : }
33168 : 683 : if (VAR_P (decl)
33169 : 683 : && DECL_CONTEXT (decl)
33170 : 683 : && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
33171 : 1366 : && lookup_decl_die (DECL_CONTEXT (decl)))
33172 : : {
33173 : 683 : if (!variable_value_hash)
33174 : 396 : variable_value_hash
33175 : 396 : = hash_table<variable_value_hasher>::create_ggc (10);
33176 : :
33177 : 683 : tree fndecl = DECL_CONTEXT (decl);
33178 : 683 : struct variable_value_struct *node;
33179 : 683 : struct variable_value_struct **slot
33180 : 2049 : = variable_value_hash->find_slot_with_hash (fndecl,
33181 : 683 : DECL_UID (fndecl),
33182 : : INSERT);
33183 : 683 : if (*slot == NULL)
33184 : : {
33185 : 534 : node = ggc_cleared_alloc<variable_value_struct> ();
33186 : 534 : node->decl_id = DECL_UID (fndecl);
33187 : 534 : *slot = node;
33188 : : }
33189 : : else
33190 : : node = *slot;
33191 : :
33192 : 683 : vec_safe_push (node->dies, die);
33193 : : }
33194 : : }
33195 : 118695 : }
33196 : :
33197 : : /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
33198 : : with dw_val_class_decl_ref operand. */
33199 : :
33200 : : static void
33201 : 53553322 : note_variable_value (dw_die_ref die)
33202 : : {
33203 : 53553322 : dw_die_ref c;
33204 : 53553322 : dw_attr_node *a;
33205 : 53553322 : dw_loc_list_ref loc;
33206 : 53553322 : unsigned ix;
33207 : :
33208 : 248887154 : FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
33209 : 195333832 : switch (AT_class (a))
33210 : : {
33211 : 0 : case dw_val_class_loc_list:
33212 : 0 : loc = AT_loc_list (a);
33213 : 0 : gcc_assert (loc);
33214 : 0 : if (!loc->noted_variable_value)
33215 : : {
33216 : 0 : loc->noted_variable_value = 1;
33217 : 0 : for (; loc; loc = loc->dw_loc_next)
33218 : 0 : note_variable_value_in_expr (die, loc->expr);
33219 : : }
33220 : : break;
33221 : 118695 : case dw_val_class_loc:
33222 : 118695 : note_variable_value_in_expr (die, AT_loc (a));
33223 : 118695 : break;
33224 : : default:
33225 : : break;
33226 : : }
33227 : :
33228 : : /* Mark children. */
33229 : 107054153 : FOR_EACH_CHILD (die, c, note_variable_value (c));
33230 : 53553322 : }
33231 : :
33232 : : /* Process DWARF dies for CTF generation. */
33233 : :
33234 : : static void
33235 : 407 : ctf_debug_do_cu (dw_die_ref die)
33236 : : {
33237 : 407 : dw_die_ref c;
33238 : :
33239 : 407 : if (!ctf_do_die (die))
33240 : : return;
33241 : :
33242 : 1724 : FOR_EACH_CHILD (die, c, ctf_do_die (c));
33243 : : }
33244 : :
33245 : : /* Perform any cleanups needed after the early debug generation pass
33246 : : has run. */
33247 : :
33248 : : static void
33249 : 53223 : dwarf2out_early_finish (const char *filename)
33250 : : {
33251 : 53223 : comdat_type_node *ctnode;
33252 : 53223 : set_early_dwarf s;
33253 : 53223 : char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
33254 : :
33255 : : /* PCH might result in DW_AT_producer string being restored from the
33256 : : header compilation, so always fill it with empty string initially
33257 : : and overwrite only here. */
33258 : 53223 : dw_attr_node *producer = get_AT (comp_unit_die (), DW_AT_producer);
33259 : :
33260 : 53223 : if (dwarf_record_gcc_switches)
33261 : 52690 : producer_string = gen_producer_string (lang_hooks.name,
33262 : : save_decoded_options,
33263 : : save_decoded_options_count);
33264 : : else
33265 : 533 : producer_string = concat (lang_hooks.name, " ", version_string, NULL);
33266 : :
33267 : 53223 : producer->dw_attr_val.v.val_str->refcount--;
33268 : 53223 : producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
33269 : :
33270 : : /* Add the name for the main input file now. We delayed this from
33271 : : dwarf2out_init to avoid complications with PCH. */
33272 : 53223 : add_filename_attribute (comp_unit_die (), remap_debug_filename (filename));
33273 : 53223 : add_comp_dir_attribute (comp_unit_die ());
33274 : :
33275 : : /* With LTO early dwarf was really finished at compile-time, so make
33276 : : sure to adjust the phase after annotating the LTRANS CU DIE. */
33277 : 53223 : if (in_lto_p)
33278 : : {
33279 : 812 : early_dwarf_finished = true;
33280 : 812 : if (dump_file)
33281 : : {
33282 : 0 : fprintf (dump_file, "LTO EARLY DWARF for %s\n", filename);
33283 : 0 : print_die (comp_unit_die (), dump_file);
33284 : : }
33285 : 812 : return;
33286 : : }
33287 : :
33288 : : /* Walk through the list of incomplete types again, trying once more to
33289 : : emit full debugging info for them. */
33290 : 52411 : retry_incomplete_types ();
33291 : :
33292 : 52411 : gen_scheduled_generic_parms_dies ();
33293 : 52411 : gen_remaining_tmpl_value_param_die_attribute ();
33294 : :
33295 : : /* The point here is to flush out the limbo list so that it is empty
33296 : : and we don't need to stream it for LTO. */
33297 : 52411 : flush_limbo_die_list ();
33298 : :
33299 : : /* Add DW_AT_linkage_name for all deferred DIEs. */
33300 : 87835461 : for (limbo_die_node *node = deferred_asm_name; node; node = node->next)
33301 : : {
33302 : 87783050 : tree decl = node->created_for;
33303 : 87783050 : if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
33304 : : /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
33305 : : ended up in deferred_asm_name before we knew it was
33306 : : constant and never written to disk. */
33307 : 87783050 : && DECL_ASSEMBLER_NAME (decl))
33308 : : {
33309 : 86136402 : add_linkage_attr (node->die, decl);
33310 : 86136402 : move_linkage_attr (node->die);
33311 : : }
33312 : : }
33313 : 52411 : deferred_asm_name = NULL;
33314 : :
33315 : 52411 : if (flag_eliminate_unused_debug_types)
33316 : 52408 : prune_unused_types ();
33317 : :
33318 : : /* Generate separate COMDAT sections for type DIEs. */
33319 : 52411 : if (use_debug_types)
33320 : : {
33321 : 35 : break_out_comdat_types (comp_unit_die ());
33322 : :
33323 : : /* Each new type_unit DIE was added to the limbo die list when created.
33324 : : Since these have all been added to comdat_type_list, clear the
33325 : : limbo die list. */
33326 : 35 : limbo_die_list = NULL;
33327 : :
33328 : : /* For each new comdat type unit, copy declarations for incomplete
33329 : : types to make the new unit self-contained (i.e., no direct
33330 : : references to the main compile unit). */
33331 : 115 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33332 : 80 : copy_decls_for_unworthy_types (ctnode->root_die);
33333 : 35 : copy_decls_for_unworthy_types (comp_unit_die ());
33334 : :
33335 : : /* In the process of copying declarations from one unit to another,
33336 : : we may have left some declarations behind that are no longer
33337 : : referenced. Prune them. */
33338 : 35 : prune_unused_types ();
33339 : : }
33340 : :
33341 : : /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
33342 : : with dw_val_class_decl_ref operand. */
33343 : 52411 : note_variable_value (comp_unit_die ());
33344 : 52411 : for (limbo_die_node *node = cu_die_list; node; node = node->next)
33345 : 0 : note_variable_value (node->die);
33346 : 52491 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33347 : 80 : note_variable_value (ctnode->root_die);
33348 : 52411 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33349 : 0 : note_variable_value (node->die);
33350 : :
33351 : : /* The AT_pubnames attribute needs to go in all skeleton dies, including
33352 : : both the main_cu and all skeleton TUs. Making this call unconditional
33353 : : would end up either adding a second copy of the AT_pubnames attribute, or
33354 : : requiring a special case in add_top_level_skeleton_die_attrs. */
33355 : 52411 : if (!dwarf_split_debug_info)
33356 : 52162 : add_AT_pubnames (comp_unit_die ());
33357 : :
33358 : : /* The early debug phase is now finished. */
33359 : 52411 : early_dwarf_finished = true;
33360 : 52411 : if (dump_file)
33361 : : {
33362 : 4 : fprintf (dump_file, "EARLY DWARF for %s\n", filename);
33363 : 4 : print_die (comp_unit_die (), dump_file);
33364 : : }
33365 : :
33366 : : /* Generate CTF/BTF debug info. */
33367 : 52411 : if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
33368 : 52411 : || btf_debuginfo_p ()) && lang_GNU_C ())
33369 : : {
33370 : 407 : ctf_debug_init ();
33371 : 407 : ctf_debug_do_cu (comp_unit_die ());
33372 : 407 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33373 : 0 : ctf_debug_do_cu (node->die);
33374 : :
33375 : 407 : ctf_debug_early_finish (filename);
33376 : : }
33377 : :
33378 : : #ifdef CODEVIEW_DEBUGGING_INFO
33379 : : if (codeview_debuginfo_p ())
33380 : : codeview_debug_early_finish (comp_unit_die ());
33381 : : #endif
33382 : :
33383 : : /* Do not generate DWARF assembler now when not producing LTO bytecode. */
33384 : 52411 : if ((!flag_generate_lto && !flag_generate_offload)
33385 : : /* FIXME: Disable debug info generation for (PE-)COFF targets since the
33386 : : copy_lto_debug_sections operation of the simple object support in
33387 : : libiberty is not implemented for them yet. */
33388 : : || TARGET_PECOFF || TARGET_COFF)
33389 : : return;
33390 : :
33391 : : /* Now as we are going to output for LTO initialize sections and labels
33392 : : to the LTO variants. We don't need a random-seed postfix as other
33393 : : LTO sections as linking the LTO debug sections into one in a partial
33394 : : link is fine. */
33395 : 1323 : init_sections_and_labels (true);
33396 : :
33397 : : /* The output below is modeled after dwarf2out_finish with all
33398 : : location related output removed and some LTO specific changes.
33399 : : Some refactoring might make both smaller and easier to match up. */
33400 : :
33401 : 1323 : base_types.truncate (0);
33402 : 1329 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33403 : 6 : mark_base_types (ctnode->root_die);
33404 : 1323 : mark_base_types (comp_unit_die ());
33405 : 1323 : move_marked_base_types ();
33406 : :
33407 : : /* Traverse the DIE's and add sibling attributes to those DIE's
33408 : : that have children. */
33409 : 1323 : add_sibling_attributes (comp_unit_die ());
33410 : 1323 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33411 : 0 : add_sibling_attributes (node->die);
33412 : 1329 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33413 : 6 : add_sibling_attributes (ctnode->root_die);
33414 : :
33415 : : /* AIX Assembler inserts the length, so adjust the reference to match the
33416 : : offset expected by debuggers. */
33417 : 1323 : strcpy (dl_section_ref, debug_line_section_label);
33418 : 1323 : if (XCOFF_DEBUGGING_INFO)
33419 : : strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
33420 : :
33421 : 1323 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33422 : 1323 : add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list, dl_section_ref);
33423 : :
33424 : 1323 : if (have_macinfo)
33425 : 30 : add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
33426 : : macinfo_section_label);
33427 : :
33428 : 1323 : save_macinfo_strings ();
33429 : :
33430 : 1323 : if (dwarf_split_debug_info)
33431 : : {
33432 : 0 : unsigned int index = 0;
33433 : 0 : debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
33434 : : }
33435 : :
33436 : : /* Output all of the compilation units. We put the main one last so that
33437 : : the offsets are available to output_pubnames. */
33438 : 1323 : for (limbo_die_node *node = limbo_die_list; node; node = node->next)
33439 : 0 : output_comp_unit (node->die, 0, NULL);
33440 : :
33441 : 1323 : hash_table<comdat_type_hasher> comdat_type_table (100);
33442 : 1329 : for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
33443 : : {
33444 : 6 : comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
33445 : :
33446 : : /* Don't output duplicate types. */
33447 : 6 : if (*slot != HTAB_EMPTY_ENTRY)
33448 : 1 : continue;
33449 : :
33450 : : /* Add a pointer to the line table for the main compilation unit
33451 : : so that the debugger can make sense of DW_AT_decl_file
33452 : : attributes. */
33453 : 5 : if (debug_info_level >= DINFO_LEVEL_TERSE)
33454 : 5 : add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
33455 : 5 : (!dwarf_split_debug_info
33456 : : ? debug_line_section_label
33457 : : : debug_skeleton_line_section_label));
33458 : :
33459 : 5 : output_comdat_type_unit (ctnode, true);
33460 : 5 : *slot = ctnode;
33461 : : }
33462 : :
33463 : : /* Stick a unique symbol to the main debuginfo section. */
33464 : 1323 : compute_comp_unit_symbol (comp_unit_die ());
33465 : :
33466 : : /* Output the main compilation unit. We always need it if only for
33467 : : the CU symbol. */
33468 : 1323 : output_comp_unit (comp_unit_die (), true, NULL);
33469 : :
33470 : : /* Output the abbreviation table. */
33471 : 1323 : if (vec_safe_length (abbrev_die_table) != 1)
33472 : : {
33473 : 1323 : switch_to_section (debug_abbrev_section);
33474 : 1323 : ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
33475 : 1323 : output_abbrev_section ();
33476 : : }
33477 : :
33478 : : /* Have to end the macro section. */
33479 : 1323 : if (have_macinfo)
33480 : : {
33481 : : /* We have to save macinfo state if we need to output it again
33482 : : for the FAT part of the object. */
33483 : 15 : vec<macinfo_entry, va_gc> *saved_macinfo_table = macinfo_table;
33484 : 15 : if (flag_fat_lto_objects)
33485 : 3 : macinfo_table = macinfo_table->copy ();
33486 : :
33487 : 15 : switch_to_section (debug_macinfo_section);
33488 : 15 : ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
33489 : 15 : output_macinfo (debug_line_section_label, true);
33490 : 15 : dw2_asm_output_data (1, 0, "End compilation unit");
33491 : :
33492 : 15 : if (flag_fat_lto_objects)
33493 : : {
33494 : 3 : vec_free (macinfo_table);
33495 : 3 : macinfo_table = saved_macinfo_table;
33496 : : }
33497 : : }
33498 : :
33499 : : /* Emit a skeleton debug_line section. */
33500 : 1323 : switch_to_section (debug_line_section);
33501 : 1323 : ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
33502 : 1323 : output_line_info (true);
33503 : :
33504 : : /* If we emitted any indirect strings, output the string table too. */
33505 : 1323 : if (debug_str_hash || skeleton_debug_str_hash)
33506 : 1323 : output_indirect_strings ();
33507 : 1323 : if (debug_line_str_hash)
33508 : : {
33509 : 1276 : switch_to_section (debug_line_str_section);
33510 : 1276 : const enum dwarf_form form = DW_FORM_line_strp;
33511 : 1276 : debug_line_str_hash->traverse<enum dwarf_form,
33512 : 1276 : output_indirect_string> (form);
33513 : : }
33514 : :
33515 : : /* Switch back to the text section. */
33516 : 1323 : switch_to_section (text_section);
33517 : 53223 : }
33518 : :
33519 : : /* Reset all state within dwarf2out.cc so that we can rerun the compiler
33520 : : within the same process. For use by toplev::finalize. */
33521 : :
33522 : : void
33523 : 256374 : dwarf2out_cc_finalize (void)
33524 : : {
33525 : 256374 : last_var_location_insn = NULL;
33526 : 256374 : cached_next_real_insn = NULL;
33527 : 256374 : used_rtx_array = NULL;
33528 : 256374 : incomplete_types = NULL;
33529 : 256374 : debug_info_section = NULL;
33530 : 256374 : debug_skeleton_info_section = NULL;
33531 : 256374 : debug_abbrev_section = NULL;
33532 : 256374 : debug_skeleton_abbrev_section = NULL;
33533 : 256374 : debug_aranges_section = NULL;
33534 : 256374 : debug_addr_section = NULL;
33535 : 256374 : debug_macinfo_section = NULL;
33536 : 256374 : debug_line_section = NULL;
33537 : 256374 : debug_skeleton_line_section = NULL;
33538 : 256374 : debug_loc_section = NULL;
33539 : 256374 : debug_pubnames_section = NULL;
33540 : 256374 : debug_pubtypes_section = NULL;
33541 : 256374 : debug_str_section = NULL;
33542 : 256374 : debug_line_str_section = NULL;
33543 : 256374 : debug_str_dwo_section = NULL;
33544 : 256374 : debug_str_offsets_section = NULL;
33545 : 256374 : debug_ranges_section = NULL;
33546 : 256374 : debug_ranges_dwo_section = NULL;
33547 : 256374 : debug_frame_section = NULL;
33548 : 256374 : fde_vec = NULL;
33549 : 256374 : debug_str_hash = NULL;
33550 : 256374 : debug_line_str_hash = NULL;
33551 : 256374 : skeleton_debug_str_hash = NULL;
33552 : 256374 : dw2_string_counter = 0;
33553 : 256374 : have_multiple_function_sections = false;
33554 : 256374 : in_text_section_p = false;
33555 : 256374 : cold_text_section = NULL;
33556 : 256374 : last_text_label = NULL;
33557 : 256374 : last_cold_label = NULL;
33558 : 256374 : switch_text_ranges = NULL;
33559 : 256374 : switch_cold_ranges = NULL;
33560 : 256374 : current_unit_personality = NULL;
33561 : :
33562 : 256374 : early_dwarf = false;
33563 : 256374 : early_dwarf_finished = false;
33564 : :
33565 : 256374 : next_die_offset = 0;
33566 : 256374 : single_comp_unit_die = NULL;
33567 : 256374 : comdat_type_list = NULL;
33568 : 256374 : limbo_die_list = NULL;
33569 : 256374 : file_table = NULL;
33570 : 256374 : decl_die_table = NULL;
33571 : 256374 : common_block_die_table = NULL;
33572 : 256374 : decl_loc_table = NULL;
33573 : 256374 : call_arg_locations = NULL;
33574 : 256374 : call_arg_loc_last = NULL;
33575 : 256374 : call_site_count = -1;
33576 : 256374 : tail_call_site_count = -1;
33577 : 256374 : cached_dw_loc_list_table = NULL;
33578 : 256374 : abbrev_die_table = NULL;
33579 : 309781 : delete dwarf_proc_stack_usage_map;
33580 : 256374 : dwarf_proc_stack_usage_map = NULL;
33581 : 256374 : line_info_label_num = 0;
33582 : 256374 : cur_line_info_table = NULL;
33583 : 256374 : text_section_line_info = NULL;
33584 : 256374 : cold_text_section_line_info = NULL;
33585 : 256374 : separate_line_info = NULL;
33586 : 256374 : info_section_emitted = false;
33587 : 256374 : pubname_table = NULL;
33588 : 256374 : pubtype_table = NULL;
33589 : 256374 : macinfo_table = NULL;
33590 : 256374 : ranges_table = NULL;
33591 : 256374 : ranges_by_label = NULL;
33592 : 256374 : rnglist_idx = 0;
33593 : 256374 : have_location_lists = false;
33594 : 256374 : loclabel_num = 0;
33595 : 256374 : poc_label_num = 0;
33596 : 256374 : last_emitted_file = NULL;
33597 : 256374 : label_num = 0;
33598 : 256374 : tmpl_value_parm_die_table = NULL;
33599 : 256374 : generic_type_instances = NULL;
33600 : 256374 : frame_pointer_fb_offset = 0;
33601 : 256374 : frame_pointer_fb_offset_valid = false;
33602 : 256374 : base_types.release ();
33603 : 256374 : XDELETEVEC (producer_string);
33604 : 256374 : producer_string = NULL;
33605 : 256374 : output_line_info_generation = 0;
33606 : 256374 : init_sections_and_labels_generation = 0;
33607 : 256374 : }
33608 : :
33609 : : #include "gt-dwarf2out.h"
|