LCOV - code coverage report
Current view: top level - gcc - dwarf2out.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 83.2 % 14980 12464
Test Date: 2026-09-19 16:22:48 Functions: 93.3 % 601 561
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Output Dwarf2 format symbol table information from GCC.
       2              :    Copyright (C) 1992-2026 Free Software Foundation, Inc.
       3              :    Contributed by Gary Funck (gary@intrepid.com).
       4              :    Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
       5              :    Extensively modified by Jason Merrill (jason@cygnus.com).
       6              : 
       7              : This file is part of GCC.
       8              : 
       9              : GCC is free software; you can redistribute it and/or modify it under
      10              : the terms of the GNU General Public License as published by the Free
      11              : Software Foundation; either version 3, or (at your option) any later
      12              : version.
      13              : 
      14              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      15              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      16              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      17              : for more details.
      18              : 
      19              : You should have received a copy of the GNU General Public License
      20              : along with GCC; see the file COPYING3.  If not see
      21              : <http://www.gnu.org/licenses/>.  */
      22              : 
      23              : /* TODO: Emit .debug_line header even when there are no functions, since
      24              :            the file numbers are used by .debug_info.  Alternately, leave
      25              :            out locations for types and decls.
      26              :          Avoid talking about ctors and op= for PODs.
      27              :          Factor out common prologue sequences into multiple CIEs.  */
      28              : 
      29              : /* The first part of this file deals with the DWARF 2 frame unwind
      30              :    information, which is also used by the GCC efficient exception handling
      31              :    mechanism.  The second part, controlled only by an #ifdef
      32              :    DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
      33              :    information.  */
      34              : 
      35              : /* DWARF2 Abbreviation Glossary:
      36              : 
      37              :    CFA = Canonical Frame Address
      38              :            a fixed address on the stack which identifies a call frame.
      39              :            We define it to be the value of SP just before the call insn.
      40              :            The CFA register and offset, which may change during the course
      41              :            of the function, are used to calculate its value at runtime.
      42              : 
      43              :    CFI = Call Frame Instruction
      44              :            an instruction for the DWARF2 abstract machine
      45              : 
      46              :    CIE = Common Information Entry
      47              :            information describing information common to one or more FDEs
      48              : 
      49              :    DIE = Debugging Information Entry
      50              : 
      51              :    FDE = Frame Description Entry
      52              :            information describing the stack call frame, in particular,
      53              :            how to restore registers
      54              : 
      55              :    DW_CFA_... = DWARF2 CFA call frame instruction
      56              :    DW_TAG_... = DWARF2 DIE tag */
      57              : 
      58              : #include "config.h"
      59              : #include "system.h"
      60              : #include "coretypes.h"
      61              : #include "target.h"
      62              : #include "function.h"
      63              : #include "rtl.h"
      64              : #include "tree.h"
      65              : #include "memmodel.h"
      66              : #include "tm_p.h"
      67              : #include "stringpool.h"
      68              : #include "insn-config.h"
      69              : #include "ira.h"
      70              : #include "cgraph.h"
      71              : #include "diagnostic.h"
      72              : #include "fold-const.h"
      73              : #include "stor-layout.h"
      74              : #include "varasm.h"
      75              : #include "version.h"
      76              : #include "flags.h"
      77              : #include "rtlhash.h"
      78              : #include "reload.h"
      79              : #include "output.h"
      80              : #include "expr.h"
      81              : #include "dwarf2out.h"
      82              : #include "dwarf2ctf.h"
      83              : #include "dwarf2codeview.h"
      84              : #include "dwarf2asm.h"
      85              : #include "toplev.h"
      86              : #include "md5.h"
      87              : #include "tree-pretty-print.h"
      88              : #include "print-rtl.h"
      89              : #include "debug.h"
      90              : #include "common/common-target.h"
      91              : #include "langhooks.h"
      92              : #include "lra.h"
      93              : #include "dumpfile.h"
      94              : #include "opts.h"
      95              : #include "tree-dfa.h"
      96              : #include "gdb/gdb-index.h"
      97              : #include "rtl-iter.h"
      98              : #include "attribs.h"
      99              : #include "file-prefix-map.h" /* remap_debug_filename()  */
     100              : 
     101              : static void dwarf2out_source_line (unsigned int, unsigned int, const char *,
     102              :                                    int, bool);
     103              : static rtx_insn *last_var_location_insn;
     104              : static rtx_insn *cached_next_real_insn;
     105              : static void dwarf2out_decl (tree);
     106              : static bool is_redundant_typedef (const_tree);
     107              : 
     108              : #ifndef XCOFF_DEBUGGING_INFO
     109              : #define XCOFF_DEBUGGING_INFO 0
     110              : #endif
     111              : 
     112              : #ifndef HAVE_XCOFF_DWARF_EXTRAS
     113              : #define HAVE_XCOFF_DWARF_EXTRAS 0
     114              : #endif
     115              : 
     116              : #ifdef VMS_DEBUGGING_INFO
     117              : int vms_file_stats_name (const char *, long long *, long *, char *, int *);
     118              : 
     119              : /* Define this macro to be a nonzero value if the directory specifications
     120              :     which are output in the debug info should end with a separator.  */
     121              : #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
     122              : /* Define this macro to evaluate to a nonzero value if GCC should refrain
     123              :    from generating indirect strings in DWARF2 debug information, for instance
     124              :    if your target is stuck with an old version of GDB that is unable to
     125              :    process them properly or uses VMS Debug.  */
     126              : #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
     127              : #else
     128              : #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
     129              : #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
     130              : #endif
     131              : 
     132              : /* ??? Poison these here until it can be done generically.  They've been
     133              :    totally replaced in this file; make sure it stays that way.  */
     134              : #undef DWARF2_UNWIND_INFO
     135              : #undef DWARF2_FRAME_INFO
     136              : #if (GCC_VERSION >= 3000)
     137              :  #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
     138              : #endif
     139              : 
     140              : /* The size of the target's pointer type.  */
     141              : #ifndef PTR_SIZE
     142              : #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
     143              : #endif
     144              : 
     145              : /* Array of RTXes referenced by the debugging information, which therefore
     146              :    must be kept around forever.  */
     147              : static GTY(()) vec<rtx, va_gc> *used_rtx_array;
     148              : 
     149              : /* A pointer to the base of a list of incomplete types which might be
     150              :    completed at some later time.  incomplete_types_list needs to be a
     151              :    vec<tree, va_gc> *because we want to tell the garbage collector about
     152              :    it.  */
     153              : static GTY(()) vec<tree, va_gc> *incomplete_types;
     154              : 
     155              : /* Pointers to various DWARF2 sections.  */
     156              : static GTY(()) section *debug_info_section;
     157              : static GTY(()) section *debug_skeleton_info_section;
     158              : static GTY(()) section *debug_abbrev_section;
     159              : static GTY(()) section *debug_skeleton_abbrev_section;
     160              : static GTY(()) section *debug_aranges_section;
     161              : static GTY(()) section *debug_addr_section;
     162              : static GTY(()) section *debug_macinfo_section;
     163              : static const char *debug_macinfo_section_name;
     164              : static unsigned macinfo_label_base = 1;
     165              : static GTY(()) section *debug_line_section;
     166              : static GTY(()) section *debug_skeleton_line_section;
     167              : static GTY(()) section *debug_loc_section;
     168              : static GTY(()) section *debug_pubnames_section;
     169              : static GTY(()) section *debug_pubtypes_section;
     170              : static GTY(()) section *debug_str_section;
     171              : static GTY(()) section *debug_line_str_section;
     172              : static GTY(()) section *debug_str_dwo_section;
     173              : static GTY(()) section *debug_str_offsets_section;
     174              : static GTY(()) section *debug_ranges_section;
     175              : static GTY(()) section *debug_ranges_dwo_section;
     176              : static GTY(()) section *debug_frame_section;
     177              : 
     178              : /* Maximum size (in bytes) of an artificially generated label.  */
     179              : #define MAX_ARTIFICIAL_LABEL_BYTES      40
     180              : 
     181              : /* According to the (draft) DWARF 3 specification, the initial length
     182              :    should either be 4 or 12 bytes.  When it's 12 bytes, the first 4
     183              :    bytes are 0xffffffff, followed by the length stored in the next 8
     184              :    bytes.
     185              : 
     186              :    However, the SGI/MIPS ABI uses an initial length which is equal to
     187              :    dwarf_offset_size.  It is defined (elsewhere) accordingly.  */
     188              : 
     189              : #ifndef DWARF_INITIAL_LENGTH_SIZE
     190              : #define DWARF_INITIAL_LENGTH_SIZE (dwarf_offset_size == 4 ? 4 : 12)
     191              : #endif
     192              : 
     193              : #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
     194              : #define DWARF_INITIAL_LENGTH_SIZE_STR (dwarf_offset_size == 4 ? "-4" : "-12")
     195              : #endif
     196              : 
     197              : /* Round SIZE up to the nearest BOUNDARY.  */
     198              : #define DWARF_ROUND(SIZE,BOUNDARY) \
     199              :   ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
     200              : 
     201              : /* CIE identifier.  */
     202              : #if HOST_BITS_PER_WIDE_INT >= 64
     203              : #define DWARF_CIE_ID \
     204              :   (unsigned HOST_WIDE_INT) (dwarf_offset_size == 4 ? DW_CIE_ID : DW64_CIE_ID)
     205              : #else
     206              : #define DWARF_CIE_ID DW_CIE_ID
     207              : #endif
     208              : 
     209              : 
     210              : /* A vector for a table that contains frame description
     211              :    information for each routine.  */
     212              : #define NOT_INDEXED (-1U)
     213              : #define NO_INDEX_ASSIGNED (-2U)
     214              : 
     215              : static GTY(()) vec<dw_fde_ref, va_gc> *fde_vec;
     216              : 
     217              : struct GTY((for_user)) indirect_string_node {
     218              :   const char *str;
     219              :   unsigned int refcount;
     220              :   enum dwarf_form form;
     221              :   char *label;
     222              :   unsigned int index;
     223              : };
     224              : 
     225              : struct indirect_string_hasher : ggc_ptr_hash<indirect_string_node>
     226              : {
     227              :   typedef const char *compare_type;
     228              : 
     229              :   static hashval_t hash (indirect_string_node *);
     230              :   static bool equal (indirect_string_node *, const char *);
     231              : };
     232              : 
     233              : static GTY (()) hash_table<indirect_string_hasher> *debug_str_hash;
     234              : 
     235              : static GTY (()) hash_table<indirect_string_hasher> *debug_line_str_hash;
     236              : 
     237              : /* With split_debug_info, both the comp_dir and dwo_name go in the
     238              :    main object file, rather than the dwo, similar to the force_direct
     239              :    parameter elsewhere but with additional complications:
     240              : 
     241              :    1) The string is needed in both the main object file and the dwo.
     242              :    That is, the comp_dir and dwo_name will appear in both places.
     243              : 
     244              :    2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
     245              :    DW_FORM_line_strp or DW_FORM_strx/GNU_str_index.
     246              : 
     247              :    3) GCC chooses the form to use late, depending on the size and
     248              :    reference count.
     249              : 
     250              :    Rather than forcing the all debug string handling functions and
     251              :    callers to deal with these complications, simply use a separate,
     252              :    special-cased string table for any attribute that should go in the
     253              :    main object file.  This limits the complexity to just the places
     254              :    that need it.  */
     255              : 
     256              : static GTY (()) hash_table<indirect_string_hasher> *skeleton_debug_str_hash;
     257              : 
     258              : static GTY(()) int dw2_string_counter;
     259              : 
     260              : /* True if the compilation unit places functions in more than one section.  */
     261              : static GTY(()) bool have_multiple_function_sections = false;
     262              : 
     263              : /* The default cold text section.  */
     264              : static GTY(()) section *cold_text_section;
     265              : 
     266              : /* True if currently in text section.  */
     267              : static GTY(()) bool in_text_section_p = false;
     268              : 
     269              : /* Last debug-on location in corresponding section.  */
     270              : static GTY(()) const char *last_text_label;
     271              : static GTY(()) const char *last_cold_label;
     272              : 
     273              : /* Mark debug-on/off locations per section.
     274              :    NULL means the section is not used at all.  */
     275              : static GTY(()) vec<const char *, va_gc> *switch_text_ranges;
     276              : static GTY(()) vec<const char *, va_gc> *switch_cold_ranges;
     277              : 
     278              : /* The DIE for C++14 'auto' in a function return type.  */
     279              : static GTY(()) dw_die_ref auto_die;
     280              : 
     281              : /* The DIE for C++14 'decltype(auto)' in a function return type.  */
     282              : static GTY(()) dw_die_ref decltype_auto_die;
     283              : 
     284              : /* Forward declarations for functions defined in this file.  */
     285              : 
     286              : static void output_call_frame_info (int);
     287              : 
     288              : /* Personality decl of current unit.  Used only when assembler does not support
     289              :    personality CFI.  */
     290              : static GTY(()) rtx current_unit_personality;
     291              : 
     292              : /* Whether an eh_frame section is required.  */
     293              : static GTY(()) bool do_eh_frame = false;
     294              : 
     295              : /* .debug_rnglists next index.  */
     296              : static unsigned int rnglist_idx;
     297              : 
     298              : /* Data and reference forms for relocatable data.  */
     299              : #define DW_FORM_data (dwarf_offset_size == 8 ? DW_FORM_data8 : DW_FORM_data4)
     300              : #define DW_FORM_ref (dwarf_offset_size == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
     301              : 
     302              : #ifndef DEBUG_FRAME_SECTION
     303              : #define DEBUG_FRAME_SECTION     ".debug_frame"
     304              : #endif
     305              : 
     306              : #ifndef FUNC_BEGIN_LABEL
     307              : #define FUNC_BEGIN_LABEL        "LFB"
     308              : #endif
     309              : 
     310              : #ifndef FUNC_SECOND_SECT_LABEL
     311              : #define FUNC_SECOND_SECT_LABEL  "LFSB"
     312              : #endif
     313              : 
     314              : #ifndef FUNC_END_LABEL
     315              : #define FUNC_END_LABEL          "LFE"
     316              : #endif
     317              : 
     318              : #ifndef PROLOGUE_END_LABEL
     319              : #define PROLOGUE_END_LABEL      "LPE"
     320              : #endif
     321              : 
     322              : #ifndef EPILOGUE_BEGIN_LABEL
     323              : #define EPILOGUE_BEGIN_LABEL    "LEB"
     324              : #endif
     325              : 
     326              : #ifndef FRAME_BEGIN_LABEL
     327              : #define FRAME_BEGIN_LABEL       "Lframe"
     328              : #endif
     329              : #define CIE_AFTER_SIZE_LABEL    "LSCIE"
     330              : #define CIE_END_LABEL           "LECIE"
     331              : #define FDE_LABEL               "LSFDE"
     332              : #define FDE_AFTER_SIZE_LABEL    "LASFDE"
     333              : #define FDE_END_LABEL           "LEFDE"
     334              : #define LINE_NUMBER_BEGIN_LABEL "LSLT"
     335              : #define LINE_NUMBER_END_LABEL   "LELT"
     336              : #define LN_PROLOG_AS_LABEL      "LASLTP"
     337              : #define LN_PROLOG_END_LABEL     "LELTP"
     338              : #define DIE_LABEL_PREFIX        "DW"
     339              : 
     340              : /* Match the base name of a file to the base name of a compilation unit. */
     341              : 
     342              : static bool
     343          620 : matches_main_base (const char *path)
     344              : {
     345              :   /* Cache the last query. */
     346          620 :   static const char *last_path = NULL;
     347          620 :   static bool last_match = false;
     348          620 :   if (path != last_path)
     349              :     {
     350          113 :       const char *base;
     351          113 :       int length = base_of_path (path, &base);
     352          113 :       last_path = path;
     353          113 :       last_match = (length == main_input_baselength
     354          113 :                     && memcmp (base, main_input_basename, length) == 0);
     355              :     }
     356          620 :   return last_match;
     357              : }
     358              : 
     359              : #ifdef DEBUG_DEBUG_STRUCT
     360              : 
     361              : static bool
     362              : dump_struct_debug (tree type, enum debug_info_usage usage,
     363              :                    enum debug_struct_file criterion, int generic,
     364              :                    bool matches, bool result)
     365              : {
     366              :   /* Find the type name. */
     367              :   tree type_decl = TYPE_STUB_DECL (type);
     368              :   tree t = type_decl;
     369              :   const char *name = 0;
     370              :   if (TREE_CODE (t) == TYPE_DECL)
     371              :     t = DECL_NAME (t);
     372              :   if (t)
     373              :     name = IDENTIFIER_POINTER (t);
     374              : 
     375              :   fprintf (stderr, "       struct %d %s %s %s %s %d %p %s\n",
     376              :            criterion,
     377              :            DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
     378              :            matches ? "bas" : "hdr",
     379              :            generic ? "gen" : "ord",
     380              :            usage == DINFO_USAGE_DFN ? ";" :
     381              :              usage == DINFO_USAGE_DIR_USE ? "." : "*",
     382              :            result,
     383              :            (void*) type_decl, name);
     384              :   return result;
     385              : }
     386              : #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
     387              :   dump_struct_debug (type, usage, criterion, generic, matches, result)
     388              : 
     389              : #else
     390              : 
     391              : #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
     392              :   (result)
     393              : 
     394              : #endif
     395              : 
     396              : /* Get the number of HOST_WIDE_INTs needed to represent the precision
     397              :    of the number.  */
     398              : 
     399              : static unsigned int
     400         1673 : get_full_len (const dw_wide_int &op)
     401              : {
     402         1673 :   return CEIL (op.get_precision (), HOST_BITS_PER_WIDE_INT);
     403              : }
     404              : 
     405              : static bool
     406    141623423 : should_emit_struct_debug (tree type, enum debug_info_usage usage)
     407              : {
     408    141623423 :   if (debug_info_level <= DINFO_LEVEL_TERSE)
     409              :     return false;
     410              : 
     411    141623420 :   enum debug_struct_file criterion;
     412    141623420 :   tree type_decl;
     413    141623420 :   bool generic = lang_hooks.types.generic_p (type);
     414              : 
     415    141623420 :   if (generic)
     416    113395420 :     criterion = debug_struct_generic[usage];
     417              :   else
     418     28228000 :     criterion = debug_struct_ordinary[usage];
     419              : 
     420    141623420 :   if (criterion == DINFO_STRUCT_FILE_NONE)
     421              :     return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
     422    141623209 :   if (criterion == DINFO_STRUCT_FILE_ANY)
     423              :     return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
     424              : 
     425          640 :   type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
     426              : 
     427          640 :   if (type_decl != NULL)
     428              :     {
     429          636 :      if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
     430              :         return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
     431              : 
     432          620 :       if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
     433              :         return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
     434              :     }
     435              : 
     436              :   return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
     437              : }
     438              : 
     439              : /* Switch [BACK] to eh_frame_section.  If we don't have an eh_frame_section,
     440              :    switch to the data section instead, and write out a synthetic start label
     441              :    for collect2 the first time around.  */
     442              : 
     443              : static void
     444           10 : switch_to_eh_frame_section (bool back ATTRIBUTE_UNUSED)
     445              : {
     446           10 :   if (eh_frame_section == 0)
     447              :     {
     448           10 :       int flags;
     449              : 
     450           10 :       if (EH_TABLES_CAN_BE_READ_ONLY)
     451              :         {
     452           10 :           int fde_encoding;
     453           10 :           int per_encoding;
     454           10 :           int lsda_encoding;
     455              : 
     456           10 :           fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
     457              :                                                        /*global=*/0);
     458           10 :           per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
     459              :                                                        /*global=*/1);
     460           10 :           lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
     461              :                                                         /*global=*/0);
     462           20 :           flags = ((! flag_pic
     463            0 :                     || ((fde_encoding & 0x70) != DW_EH_PE_absptr
     464            0 :                         && (fde_encoding & 0x70) != DW_EH_PE_aligned
     465            0 :                         && (per_encoding & 0x70) != DW_EH_PE_absptr
     466            0 :                         && (per_encoding & 0x70) != DW_EH_PE_aligned
     467            0 :                         && (lsda_encoding & 0x70) != DW_EH_PE_absptr
     468            0 :                         && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
     469           10 :                    ? 0 : SECTION_WRITE);
     470              :         }
     471              :       else
     472              :         flags = SECTION_WRITE;
     473              : 
     474              : #ifdef EH_FRAME_SECTION_NAME
     475           10 :       eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
     476              : #else
     477              :       eh_frame_section = ((flags == SECTION_WRITE)
     478              :                           ? data_section : readonly_data_section);
     479              : #endif /* EH_FRAME_SECTION_NAME */
     480              :     }
     481              : 
     482           10 :   switch_to_section (eh_frame_section);
     483              : 
     484              : #ifdef EH_FRAME_THROUGH_COLLECT2
     485              :   /* We have no special eh_frame section.  Emit special labels to guide
     486              :      collect2.  */
     487              :   if (!back)
     488              :     {
     489              :       tree label = get_file_function_name ("F");
     490              :       ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
     491              :       targetm.asm_out.globalize_label (asm_out_file,
     492              :                                         IDENTIFIER_POINTER (label));
     493              :       ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
     494              :     }
     495              : #endif
     496           10 : }
     497              : 
     498              : /* Switch [BACK] to the eh or debug frame table section, depending on
     499              :    FOR_EH.  */
     500              : 
     501              : static void
     502           19 : switch_to_frame_table_section (int for_eh, bool back)
     503              : {
     504           19 :   if (for_eh)
     505           10 :     switch_to_eh_frame_section (back);
     506              :   else
     507              :     {
     508            9 :       if (!debug_frame_section)
     509            9 :         debug_frame_section = get_section (DEBUG_FRAME_SECTION,
     510              :                                            SECTION_DEBUG, NULL);
     511            9 :       switch_to_section (debug_frame_section);
     512              :     }
     513           19 : }
     514              : 
     515              : /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used.  */
     516              : 
     517              : enum dw_cfi_oprnd_type
     518     47505704 : dw_cfi_oprnd1_desc (dwarf_call_frame_info cfi)
     519              : {
     520     47505704 :   switch (cfi)
     521              :     {
     522              :     case DW_CFA_nop:
     523              :     case DW_CFA_remember_state:
     524              :     case DW_CFA_restore_state:
     525              :       return dw_cfi_oprnd_unused;
     526              : 
     527           76 :     case DW_CFA_set_loc:
     528           76 :     case DW_CFA_advance_loc1:
     529           76 :     case DW_CFA_advance_loc2:
     530           76 :     case DW_CFA_advance_loc4:
     531           76 :     case DW_CFA_MIPS_advance_loc8:
     532           76 :       return dw_cfi_oprnd_addr;
     533              : 
     534     15363593 :     case DW_CFA_offset:
     535     15363593 :     case DW_CFA_offset_extended:
     536     15363593 :     case DW_CFA_def_cfa:
     537     15363593 :     case DW_CFA_offset_extended_sf:
     538     15363593 :     case DW_CFA_def_cfa_sf:
     539     15363593 :     case DW_CFA_restore:
     540     15363593 :     case DW_CFA_restore_extended:
     541     15363593 :     case DW_CFA_undefined:
     542     15363593 :     case DW_CFA_same_value:
     543     15363593 :     case DW_CFA_def_cfa_register:
     544     15363593 :     case DW_CFA_register:
     545     15363593 :     case DW_CFA_expression:
     546     15363593 :     case DW_CFA_val_expression:
     547     15363593 :       return dw_cfi_oprnd_reg_num;
     548              : 
     549     28890962 :     case DW_CFA_def_cfa_offset:
     550     28890962 :     case DW_CFA_GNU_args_size:
     551     28890962 :     case DW_CFA_def_cfa_offset_sf:
     552     28890962 :       return dw_cfi_oprnd_offset;
     553              : 
     554        13481 :     case DW_CFA_def_cfa_expression:
     555        13481 :       return dw_cfi_oprnd_loc;
     556              : 
     557            0 :     default:
     558            0 :       {
     559            0 :         dw_cfi_oprnd_type oprnd_type;
     560            0 :         if (targetm.dw_cfi_oprnd1_desc (cfi, oprnd_type))
     561            0 :           return oprnd_type;
     562              :         else
     563            0 :           gcc_unreachable ();
     564              :       }
     565              :     }
     566              : }
     567              : 
     568              : /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used.  */
     569              : 
     570              : enum dw_cfi_oprnd_type
     571     47505704 : dw_cfi_oprnd2_desc (dwarf_call_frame_info cfi)
     572              : {
     573     47505704 :   switch (cfi)
     574              :     {
     575              :     case DW_CFA_def_cfa:
     576              :     case DW_CFA_def_cfa_sf:
     577              :     case DW_CFA_offset:
     578              :     case DW_CFA_offset_extended_sf:
     579              :     case DW_CFA_offset_extended:
     580              :       return dw_cfi_oprnd_offset;
     581              : 
     582            0 :     case DW_CFA_register:
     583            0 :       return dw_cfi_oprnd_reg_num;
     584              : 
     585       199338 :     case DW_CFA_expression:
     586       199338 :     case DW_CFA_val_expression:
     587       199338 :       return dw_cfi_oprnd_loc;
     588              : 
     589        13481 :     case DW_CFA_def_cfa_expression:
     590        13481 :       return dw_cfi_oprnd_cfa_loc;
     591              : 
     592     39497533 :     default:
     593     39497533 :       return dw_cfi_oprnd_unused;
     594              :     }
     595              : }
     596              : 
     597              : /* Output one FDE.  */
     598              : 
     599              : static void
     600           52 : output_fde (dw_fde_ref fde, bool for_eh, bool second,
     601              :             char *section_start_label, int fde_encoding, char *augmentation,
     602              :             bool any_lsda_needed, int lsda_encoding)
     603              : {
     604           52 :   const char *begin, *end;
     605           52 :   static unsigned int j;
     606           52 :   char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
     607              : 
     608           52 :   targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
     609              :                                      /* empty */ 0);
     610           52 :   targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
     611           52 :                                   for_eh + j);
     612           52 :   ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
     613           52 :   ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
     614           52 :   if (!XCOFF_DEBUGGING_INFO || for_eh)
     615              :     {
     616           52 :       if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
     617            0 :         dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
     618              :                              " indicating 64-bit DWARF extension");
     619           52 :       dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
     620              :                             "FDE Length");
     621              :     }
     622           52 :   ASM_OUTPUT_LABEL (asm_out_file, l1);
     623              : 
     624           52 :   if (for_eh)
     625           28 :     dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
     626              :   else
     627           24 :     dw2_asm_output_offset (dwarf_offset_size, section_start_label,
     628              :                            debug_frame_section, "FDE CIE offset");
     629              : 
     630           52 :   begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
     631           52 :   end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
     632              : 
     633           52 :   if (for_eh)
     634              :     {
     635           28 :       rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
     636           28 :       SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
     637           28 :       dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
     638              :                                        "FDE initial location");
     639           28 :       dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
     640              :                             end, begin, "FDE address range");
     641              :     }
     642              :   else
     643              :     {
     644           24 :       dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
     645           24 :       dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
     646              :     }
     647              : 
     648           52 :   if (augmentation[0])
     649              :     {
     650           28 :       if (any_lsda_needed)
     651              :         {
     652           28 :           int size = size_of_encoded_value (lsda_encoding);
     653              : 
     654           28 :           if (lsda_encoding == DW_EH_PE_aligned)
     655              :             {
     656            0 :               int offset = (  4         /* Length */
     657              :                             + 4         /* CIE offset */
     658            0 :                             + 2 * size_of_encoded_value (fde_encoding)
     659            0 :                             + 1         /* Augmentation size */ );
     660            0 :               int pad = -offset & (PTR_SIZE - 1);
     661              : 
     662            0 :               size += pad;
     663            0 :               gcc_assert (size_of_uleb128 (size) == 1);
     664              :             }
     665              : 
     666           28 :           dw2_asm_output_data_uleb128 (size, "Augmentation size");
     667              : 
     668           28 :           if (fde->uses_eh_lsda)
     669              :             {
     670           28 :               ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
     671              :                                            fde->funcdef_number);
     672           17 :               dw2_asm_output_encoded_addr_rtx (lsda_encoding,
     673           17 :                                                gen_rtx_SYMBOL_REF (Pmode, l1),
     674              :                                                false,
     675              :                                                "Language Specific Data Area");
     676              :             }
     677              :           else
     678              :             {
     679           11 :               if (lsda_encoding == DW_EH_PE_aligned)
     680            0 :                 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
     681           11 :               dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
     682              :                                    "Language Specific Data Area (none)");
     683              :             }
     684              :         }
     685              :       else
     686            0 :         dw2_asm_output_data_uleb128 (0, "Augmentation size");
     687              :     }
     688              : 
     689              :   /* Loop through the Call Frame Instructions associated with this FDE.  */
     690           52 :   fde->dw_fde_current_label = begin;
     691           52 :   {
     692           52 :     size_t from, until, i;
     693              : 
     694           52 :     from = 0;
     695           52 :     until = vec_safe_length (fde->dw_fde_cfi);
     696              : 
     697           52 :     if (fde->dw_fde_second_begin == NULL)
     698              :       ;
     699           24 :     else if (!second)
     700           12 :       until = fde->dw_fde_switch_cfi_index;
     701              :     else
     702           12 :       from = fde->dw_fde_switch_cfi_index;
     703              : 
     704          280 :     for (i = from; i < until; i++)
     705          228 :       output_cfi ((*fde->dw_fde_cfi)[i], fde, for_eh);
     706              :   }
     707              : 
     708              :   /* If we are to emit a ref/link from function bodies to their frame tables,
     709              :      do it now.  This is typically performed to make sure that tables
     710              :      associated with functions are dragged with them and not discarded in
     711              :      garbage collecting links. We need to do this on a per function basis to
     712              :      cope with -ffunction-sections.  */
     713              : 
     714              : #ifdef ASM_OUTPUT_DWARF_TABLE_REF
     715              :   /* Switch to the function section, emit the ref to the tables, and
     716              :      switch *back* into the table section.  */
     717              :   switch_to_section (function_section (fde->decl));
     718              :   ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
     719              :   switch_to_frame_table_section (for_eh, true);
     720              : #endif
     721              : 
     722              :   /* Pad the FDE out to an address sized boundary.  */
     723           52 :   ASM_OUTPUT_ALIGN (asm_out_file,
     724              :                     floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
     725           52 :   ASM_OUTPUT_LABEL (asm_out_file, l2);
     726              : 
     727           52 :   j += 2;
     728           52 : }
     729              : 
     730              : /* Return true if frame description entry FDE is needed for EH.  */
     731              : 
     732              : static bool
     733           35 : fde_needed_for_eh_p (dw_fde_ref fde)
     734              : {
     735           35 :   if (flag_asynchronous_unwind_tables)
     736              :     return true;
     737              : 
     738            8 :   if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
     739              :     return true;
     740              : 
     741            8 :   if (fde->uses_eh_lsda)
     742              :     return true;
     743              : 
     744              :   /* If exceptions are enabled, we have collected nothrow info.  */
     745            6 :   if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
     746            2 :     return false;
     747              : 
     748              :   return true;
     749              : }
     750              : 
     751              : /* Output the call frame information used to record information
     752              :    that relates to calculating the frame pointer, and records the
     753              :    location of saved registers.  */
     754              : 
     755              : static void
     756       268712 : output_call_frame_info (int for_eh)
     757              : {
     758       268712 :   unsigned int i;
     759       268712 :   dw_fde_ref fde;
     760       268712 :   dw_cfi_ref cfi;
     761       268712 :   char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
     762       268712 :   char section_start_label[MAX_ARTIFICIAL_LABEL_BYTES];
     763       268712 :   bool any_lsda_needed = false;
     764       268712 :   char augmentation[6];
     765       268712 :   int augmentation_size;
     766       268712 :   int fde_encoding = DW_EH_PE_absptr;
     767       268712 :   int per_encoding = DW_EH_PE_absptr;
     768       268712 :   int lsda_encoding = DW_EH_PE_absptr;
     769       268712 :   int return_reg;
     770       268712 :   rtx personality = NULL;
     771       268712 :   int dw_cie_version;
     772              : 
     773              :   /* Don't emit a CIE if there won't be any FDEs.  */
     774       268712 :   if (!fde_vec)
     775       268693 :     return;
     776              : 
     777              :   /* Nothing to do if the assembler's doing it all.  */
     778       264130 :   if (dwarf2out_do_cfi_asm ())
     779              :     return;
     780              : 
     781              :   /* If we don't have any functions we'll want to unwind out of, don't emit
     782              :      any EH unwind information.  If we make FDEs linkonce, we may have to
     783              :      emit an empty label for an FDE that wouldn't otherwise be emitted.  We
     784              :      want to avoid having an FDE kept around when the function it refers to
     785              :      is discarded.  Example where this matters: a primary function template
     786              :      in C++ requires EH information, an explicit specialization doesn't.  */
     787           19 :   if (for_eh)
     788              :     {
     789              :       bool any_eh_needed = false;
     790              : 
     791           33 :       FOR_EACH_VEC_ELT (*fde_vec, i, fde)
     792              :         {
     793           23 :           if (fde->uses_eh_lsda)
     794              :             any_eh_needed = any_lsda_needed = true;
     795           12 :           else if (fde_needed_for_eh_p (fde))
     796           11 :             any_eh_needed = true;
     797              :           else if (TARGET_USES_WEAK_UNWIND_INFO)
     798              :             targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, 1, 1);
     799              :         }
     800              : 
     801           10 :       if (!any_eh_needed)
     802              :         return;
     803              :     }
     804              : 
     805              :   /* We're going to be generating comments, so turn on app.  */
     806           19 :   if (flag_debug_asm)
     807            0 :     app_enable ();
     808              : 
     809              :   /* Switch to the proper frame section, first time.  */
     810           19 :   switch_to_frame_table_section (for_eh, false);
     811              : 
     812           19 :   ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
     813           19 :   ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
     814              : 
     815              :   /* Output the CIE.  */
     816           19 :   ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
     817           19 :   ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
     818           19 :   if (!XCOFF_DEBUGGING_INFO || for_eh)
     819              :     {
     820           19 :       if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
     821            0 :         dw2_asm_output_data (4, 0xffffffff,
     822              :           "Initial length escape value indicating 64-bit DWARF extension");
     823           19 :       dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
     824              :                             "Length of Common Information Entry");
     825              :     }
     826           19 :   ASM_OUTPUT_LABEL (asm_out_file, l1);
     827              : 
     828              :   /* Now that the CIE pointer is PC-relative for EH,
     829              :      use 0 to identify the CIE.  */
     830           28 :   dw2_asm_output_data ((for_eh ? 4 : dwarf_offset_size),
     831            9 :                        (for_eh ? 0 : DWARF_CIE_ID),
     832              :                        "CIE Identifier Tag");
     833              : 
     834              :   /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
     835              :      use CIE version 1, unless that would produce incorrect results
     836              :      due to overflowing the return register column.  */
     837           19 :   return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
     838           19 :   dw_cie_version = 1;
     839           19 :   if (return_reg >= 256 || dwarf_version > 2)
     840            1 :     dw_cie_version = 3;
     841           19 :   dw2_asm_output_data (1, dw_cie_version, "CIE Version");
     842              : 
     843           19 :   augmentation[0] = 0;
     844           19 :   augmentation_size = 0;
     845              : 
     846           19 :   personality = current_unit_personality;
     847           19 :   if (for_eh)
     848              :     {
     849           10 :       char *p;
     850              : 
     851              :       /* Augmentation:
     852              :          z      Indicates that a uleb128 is present to size the
     853              :                 augmentation section.
     854              :          L      Indicates the encoding (and thus presence) of
     855              :                 an LSDA pointer in the FDE augmentation.
     856              :          R      Indicates a non-default pointer encoding for
     857              :                 FDE code pointers.
     858              :          P      Indicates the presence of an encoding + language
     859              :                 personality routine in the CIE augmentation.  */
     860              : 
     861           10 :       fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
     862           10 :       per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
     863           10 :       lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
     864              : 
     865           10 :       p = augmentation + 1;
     866           10 :       if (personality)
     867              :         {
     868           10 :           *p++ = 'P';
     869           10 :           augmentation_size += 1 + size_of_encoded_value (per_encoding);
     870           10 :           assemble_external_libcall (personality);
     871              :         }
     872           10 :       if (any_lsda_needed)
     873              :         {
     874           10 :           *p++ = 'L';
     875           10 :           augmentation_size += 1;
     876              :         }
     877           10 :       if (fde_encoding != DW_EH_PE_absptr)
     878              :         {
     879           10 :           *p++ = 'R';
     880           10 :           augmentation_size += 1;
     881              :         }
     882           10 :       if (p > augmentation + 1)
     883              :         {
     884           10 :           augmentation[0] = 'z';
     885           10 :           *p = '\0';
     886              :         }
     887              : 
     888              :       /* Ug.  Some platforms can't do unaligned dynamic relocations at all.  */
     889           10 :       if (personality && per_encoding == DW_EH_PE_aligned)
     890              :         {
     891            0 :           int offset = (  4             /* Length */
     892              :                         + 4             /* CIE Id */
     893              :                         + 1             /* CIE version */
     894            0 :                         + strlen (augmentation) + 1     /* Augmentation */
     895            0 :                         + size_of_uleb128 (1)           /* Code alignment */
     896            0 :                         + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
     897              :                         + 1             /* RA column */
     898              :                         + 1             /* Augmentation size */
     899            0 :                         + 1             /* Personality encoding */ );
     900            0 :           int pad = -offset & (PTR_SIZE - 1);
     901              : 
     902            0 :           augmentation_size += pad;
     903              : 
     904              :           /* Augmentations should be small, so there's scarce need to
     905              :              iterate for a solution.  Die if we exceed one uleb128 byte.  */
     906            0 :           gcc_assert (size_of_uleb128 (augmentation_size) == 1);
     907              :         }
     908              :     }
     909              : 
     910           19 :   dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
     911           19 :   if (dw_cie_version >= 4)
     912              :     {
     913              :       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
     914              :       dw2_asm_output_data (1, 0, "CIE Segment Size");
     915              :     }
     916           19 :   dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
     917           19 :   dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
     918              :                                "CIE Data Alignment Factor");
     919              : 
     920           19 :   if (dw_cie_version == 1)
     921           18 :     dw2_asm_output_data (1, return_reg, "CIE RA Column");
     922              :   else
     923            1 :     dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
     924              : 
     925           19 :   if (augmentation[0])
     926              :     {
     927           10 :       dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
     928           10 :       if (personality)
     929              :         {
     930           10 :           dw2_asm_output_data (1, per_encoding, "Personality (%s)",
     931              :                                eh_data_format_name (per_encoding));
     932           10 :           dw2_asm_output_encoded_addr_rtx (per_encoding,
     933              :                                            personality,
     934              :                                            true, NULL);
     935              :         }
     936              : 
     937           10 :       if (any_lsda_needed)
     938           10 :         dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
     939              :                              eh_data_format_name (lsda_encoding));
     940              : 
     941           10 :       if (fde_encoding != DW_EH_PE_absptr)
     942           10 :         dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
     943              :                              eh_data_format_name (fde_encoding));
     944              :     }
     945              : 
     946           57 :   FOR_EACH_VEC_ELT (*cie_cfi_vec, i, cfi)
     947           38 :     output_cfi (cfi, NULL, for_eh);
     948              : 
     949              :   /* Pad the CIE out to an address sized boundary.  */
     950           19 :   ASM_OUTPUT_ALIGN (asm_out_file,
     951              :                     floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
     952           19 :   ASM_OUTPUT_LABEL (asm_out_file, l2);
     953              : 
     954              :   /* Loop through all of the FDE's.  */
     955           79 :   FOR_EACH_VEC_ELT (*fde_vec, i, fde)
     956              :     {
     957           41 :       unsigned int k;
     958              : 
     959              :       /* Don't emit EH unwind info for leaf functions that don't need it.  */
     960           41 :       if (for_eh && !fde_needed_for_eh_p (fde))
     961            1 :         continue;
     962              : 
     963          148 :       for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
     964           52 :         output_fde (fde, for_eh, k, section_start_label, fde_encoding,
     965              :                     augmentation, any_lsda_needed, lsda_encoding);
     966              :     }
     967              : 
     968           19 :   if (for_eh && targetm.terminate_dw2_eh_frame_info)
     969            0 :     dw2_asm_output_data (4, 0, "End of Table");
     970              : 
     971              :   /* Turn off app to make assembly quicker.  */
     972           19 :   if (flag_debug_asm)
     973            0 :     app_disable ();
     974              : }
     975              : 
     976              : /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed.  */
     977              : 
     978              : static void
     979      1582788 : dwarf2out_do_cfi_startproc (bool second)
     980              : {
     981      1582788 :   int enc;
     982      1582788 :   rtx ref;
     983              : 
     984      1582788 :   fprintf (asm_out_file, "\t.cfi_startproc\n");
     985              : 
     986      1582788 :   targetm.asm_out.post_cfi_startproc (asm_out_file, current_function_decl);
     987              : 
     988              :   /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
     989              :      eh unwinders.  */
     990      1582788 :   if (targetm_common.except_unwind_info (&global_options) != UI_DWARF2)
     991              :     return;
     992              : 
     993      1582788 :   rtx personality = get_personality_function (current_function_decl);
     994              : 
     995      1582788 :   if (personality)
     996              :     {
     997        79221 :       enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
     998        79221 :       ref = personality;
     999              : 
    1000              :       /* ??? The GAS support isn't entirely consistent.  We have to
    1001              :          handle indirect support ourselves, but PC-relative is done
    1002              :          in the assembler.  Further, the assembler can't handle any
    1003              :          of the weirder relocation types.  */
    1004        79221 :       if (enc & DW_EH_PE_indirect)
    1005              :         {
    1006         9419 :           if (targetm.asm_out.make_eh_symbol_indirect != NULL)
    1007            0 :             ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
    1008              :           else
    1009         9419 :             ref = dw2_force_const_mem (ref, true);
    1010              :         }
    1011              : 
    1012        79221 :       fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
    1013        79221 :       output_addr_const (asm_out_file, ref);
    1014        79221 :       fputc ('\n', asm_out_file);
    1015              :     }
    1016              : 
    1017      1582788 :   if (crtl->uses_eh_lsda)
    1018              :     {
    1019        79145 :       char lab[MAX_ARTIFICIAL_LABEL_BYTES];
    1020              : 
    1021        79145 :       enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
    1022       143766 :       ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
    1023              :                                    current_function_funcdef_no);
    1024        84960 :       ref = gen_rtx_SYMBOL_REF (Pmode, lab);
    1025        79145 :       SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
    1026              : 
    1027        79145 :       if (enc & DW_EH_PE_indirect)
    1028              :         {
    1029            0 :           if (targetm.asm_out.make_eh_symbol_indirect != NULL)
    1030            0 :             ref = targetm.asm_out.make_eh_symbol_indirect (ref, true);
    1031              :           else
    1032            0 :             ref = dw2_force_const_mem (ref, true);
    1033              :         }
    1034              : 
    1035        79145 :       fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
    1036        79145 :       output_addr_const (asm_out_file, ref);
    1037        79145 :       fputc ('\n', asm_out_file);
    1038              :     }
    1039              : }
    1040              : 
    1041              : /* Allocate CURRENT_FDE.  Immediately initialize all we can, noting that
    1042              :    this allocation may be done before pass_final.  */
    1043              : 
    1044              : dw_fde_ref
    1045      1516888 : dwarf2out_alloc_current_fde (void)
    1046              : {
    1047      1516888 :   dw_fde_ref fde;
    1048              : 
    1049      1516888 :   fde = ggc_cleared_alloc<dw_fde_node> ();
    1050      1516888 :   fde->decl = current_function_decl;
    1051      1516888 :   fde->funcdef_number = current_function_funcdef_no;
    1052      1516888 :   fde->fde_index = vec_safe_length (fde_vec);
    1053      1516888 :   fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
    1054      1516888 :   fde->uses_eh_lsda = crtl->uses_eh_lsda;
    1055      1516888 :   fde->nothrow = crtl->nothrow;
    1056      1516888 :   fde->drap_reg = INVALID_REGNUM;
    1057      1516888 :   fde->vdrap_reg = INVALID_REGNUM;
    1058              : 
    1059              :   /* Record the FDE associated with this function.  */
    1060      1516888 :   cfun->fde = fde;
    1061      1516888 :   vec_safe_push (fde_vec, fde);
    1062              : 
    1063      1516888 :   return fde;
    1064              : }
    1065              : 
    1066              : /* Output a marker (i.e. a label) for the beginning of a function, before
    1067              :    the prologue.  */
    1068              : 
    1069              : void
    1070      1516946 : dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
    1071              :                           unsigned int column ATTRIBUTE_UNUSED,
    1072              :                           const char *file ATTRIBUTE_UNUSED)
    1073              : {
    1074      1516946 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
    1075      1516946 :   char * dup_label;
    1076      1516946 :   dw_fde_ref fde;
    1077      1516946 :   section *fnsec;
    1078      1516946 :   bool do_frame;
    1079              : 
    1080      1516946 :   current_function_func_begin_label = NULL;
    1081              : 
    1082      1516946 :   do_frame = dwarf2out_do_frame ();
    1083              : 
    1084              :   /* ??? current_function_func_begin_label is also used by except.cc for
    1085              :      call-site information.  We must emit this label if it might be used.  */
    1086      1516946 :   if (!do_frame
    1087      1516946 :       && (!flag_exceptions
    1088            0 :           || targetm_common.except_unwind_info (&global_options) == UI_SJLJ))
    1089           58 :     return;
    1090              : 
    1091      1516888 :   fnsec = function_section (current_function_decl);
    1092      1516888 :   switch_to_section (fnsec);
    1093      1516888 :   ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
    1094              :                                current_function_funcdef_no);
    1095      1516888 :   ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
    1096              :                           current_function_funcdef_no);
    1097      1516888 :   dup_label = xstrdup (label);
    1098      1516888 :   current_function_func_begin_label = dup_label;
    1099              : 
    1100              :   /* We can elide FDE allocation if we're not emitting frame unwind info.  */
    1101      1516888 :   if (!do_frame)
    1102              :     return;
    1103              : 
    1104              :   /* Unlike the debug version, the EH version of frame unwind info is a per-
    1105              :      function setting so we need to record whether we need it for the unit.  */
    1106      1516888 :   do_eh_frame |= dwarf2out_do_eh_frame ();
    1107              : 
    1108              :   /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
    1109              :      emit insns as rtx but bypass the bulk of rest_of_compilation, which
    1110              :      would include pass_dwarf2_frame.  If we've not created the FDE yet,
    1111              :      do so now.  */
    1112      1516888 :   fde = cfun->fde;
    1113      1516888 :   if (fde == NULL)
    1114         5559 :     fde = dwarf2out_alloc_current_fde ();
    1115              : 
    1116              :   /* Initialize the bits of CURRENT_FDE that were not available earlier.  */
    1117      1516888 :   fde->dw_fde_begin = dup_label;
    1118      1516888 :   fde->dw_fde_current_label = dup_label;
    1119      3033776 :   fde->in_std_section = (fnsec == text_section
    1120      1516888 :                          || (cold_text_section && fnsec == cold_text_section));
    1121      1516888 :   fde->ignored_debug = DECL_IGNORED_P (current_function_decl);
    1122      1516888 :   in_text_section_p = fnsec == text_section;
    1123              : 
    1124              :   /* We only want to output line number information for the genuine dwarf2
    1125              :      prologue case, not the eh frame case.  */
    1126              : #ifdef DWARF2_DEBUGGING_INFO
    1127      1516888 :   if (file)
    1128       478118 :     dwarf2out_source_line (line, column, file, 0, true);
    1129              : #endif
    1130              : 
    1131      1516888 :   if (dwarf2out_do_cfi_asm ())
    1132      1516865 :     dwarf2out_do_cfi_startproc (false);
    1133              :   else
    1134              :     {
    1135           23 :       rtx personality = get_personality_function (current_function_decl);
    1136           23 :       if (!current_unit_personality)
    1137           13 :         current_unit_personality = personality;
    1138              : 
    1139              :       /* We cannot keep a current personality per function as without CFI
    1140              :          asm, at the point where we emit the CFI data, there is no current
    1141              :          function anymore.  */
    1142           23 :       if (personality && current_unit_personality != personality)
    1143            0 :         sorry ("multiple EH personalities are supported only with assemblers "
    1144              :                "supporting %<.cfi_personality%> directive");
    1145              :     }
    1146              : }
    1147              : 
    1148              : /* Output a marker (i.e. a label) for the end of the generated code
    1149              :    for a function prologue.  This gets called *after* the prologue code has
    1150              :    been generated.  */
    1151              : 
    1152              : void
    1153            0 : dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
    1154              :                             const char *file ATTRIBUTE_UNUSED)
    1155              : {
    1156            0 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
    1157              : 
    1158              :   /* Output a label to mark the endpoint of the code generated for this
    1159              :      function.  */
    1160            0 :   ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
    1161              :                                current_function_funcdef_no);
    1162            0 :   ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
    1163              :                           current_function_funcdef_no);
    1164            0 :   cfun->fde->dw_fde_vms_end_prologue = xstrdup (label);
    1165            0 : }
    1166              : 
    1167              : /* Output a marker (i.e. a label) for the beginning of the generated code
    1168              :    for a function epilogue.  This gets called *before* the prologue code has
    1169              :    been generated.  */
    1170              : 
    1171              : void
    1172            0 : dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
    1173              :                           const char *file ATTRIBUTE_UNUSED)
    1174              : {
    1175            0 :   dw_fde_ref fde = cfun->fde;
    1176            0 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
    1177              : 
    1178            0 :   if (fde->dw_fde_vms_begin_epilogue)
    1179              :     return;
    1180              : 
    1181              :   /* Output a label to mark the endpoint of the code generated for this
    1182              :      function.  */
    1183            0 :   ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
    1184              :                                current_function_funcdef_no);
    1185            0 :   ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
    1186              :                           current_function_funcdef_no);
    1187            0 :   fde->dw_fde_vms_begin_epilogue = xstrdup (label);
    1188              : }
    1189              : 
    1190              : /* Mark the ranges of non-debug subsections in the std text sections.  */
    1191              : 
    1192              : static void
    1193      1582817 : mark_ignored_debug_section (dw_fde_ref fde, bool second)
    1194              : {
    1195      1582817 :   bool std_section;
    1196      1582817 :   const char *begin_label, *end_label;
    1197      1582817 :   const char **last_end_label;
    1198      1582817 :   vec<const char *, va_gc> **switch_ranges;
    1199              : 
    1200      1582817 :   if (second)
    1201              :     {
    1202        65929 :       std_section = fde->second_in_std_section;
    1203        65929 :       begin_label = fde->dw_fde_second_begin;
    1204        65929 :       end_label   = fde->dw_fde_second_end;
    1205              :     }
    1206              :   else
    1207              :     {
    1208      1516888 :       std_section = fde->in_std_section;
    1209      1516888 :       begin_label = fde->dw_fde_begin;
    1210      1516888 :       end_label   = fde->dw_fde_end;
    1211              :     }
    1212              : 
    1213      1582817 :   if (!std_section)
    1214       389624 :     return;
    1215              : 
    1216      1193193 :   if (in_text_section_p)
    1217              :     {
    1218              :       last_end_label = &last_text_label;
    1219      1181028 :       switch_ranges  = &switch_text_ranges;
    1220              :     }
    1221              :   else
    1222              :     {
    1223        12165 :       last_end_label = &last_cold_label;
    1224        12165 :       switch_ranges  = &switch_cold_ranges;
    1225              :     }
    1226              : 
    1227      1193193 :   if (fde->ignored_debug)
    1228              :     {
    1229          884 :       if (*switch_ranges && !(vec_safe_length (*switch_ranges) & 1))
    1230          524 :         vec_safe_push (*switch_ranges, *last_end_label);
    1231              :     }
    1232              :   else
    1233              :     {
    1234      1192309 :       *last_end_label = end_label;
    1235              : 
    1236      1192309 :       if (!*switch_ranges)
    1237       189573 :         vec_alloc (*switch_ranges, 16);
    1238      1002736 :       else if (vec_safe_length (*switch_ranges) & 1)
    1239           74 :         vec_safe_push (*switch_ranges, begin_label);
    1240              :     }
    1241              : }
    1242              : 
    1243              : /* Output a marker (i.e. a label) for the absolute end of the generated code
    1244              :    for a function definition.  This gets called *after* the epilogue code has
    1245              :    been generated.  */
    1246              : 
    1247              : void
    1248      1516888 : dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
    1249              :                         const char *file ATTRIBUTE_UNUSED)
    1250              : {
    1251      1516888 :   dw_fde_ref fde;
    1252      1516888 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
    1253              : 
    1254      1516888 :   last_var_location_insn = NULL;
    1255      1516888 :   cached_next_real_insn = NULL;
    1256              : 
    1257      1516888 :   if (dwarf2out_do_cfi_asm ())
    1258      1516865 :     fprintf (asm_out_file, "\t.cfi_endproc\n");
    1259              : 
    1260              : #ifdef CODEVIEW_DEBUGGING_INFO
    1261              :   if (codeview_debuginfo_p ())
    1262              :     codeview_end_epilogue ();
    1263              : #endif
    1264              : 
    1265              :   /* Output a label to mark the endpoint of the code generated for this
    1266              :      function.  */
    1267      1516888 :   ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
    1268              :                                current_function_funcdef_no);
    1269      1516888 :   ASM_OUTPUT_LABEL (asm_out_file, label);
    1270      1516888 :   fde = cfun->fde;
    1271      1516888 :   gcc_assert (fde != NULL);
    1272      1516888 :   if (fde->dw_fde_second_begin == NULL)
    1273      1450959 :     fde->dw_fde_end = xstrdup (label);
    1274              : 
    1275      1516888 :   mark_ignored_debug_section (fde, fde->dw_fde_second_begin != NULL);
    1276      1516888 : }
    1277              : 
    1278              : void
    1279       237364 : dwarf2out_frame_finish (void)
    1280              : {
    1281              :   /* Output call frame information.  */
    1282       237364 :   if (targetm.debug_unwind_info () == UI_DWARF2)
    1283        53235 :     output_call_frame_info (0);
    1284              : 
    1285              :   /* Output another copy for the unwinder.  */
    1286       237364 :   if (do_eh_frame)
    1287       215477 :     output_call_frame_info (1);
    1288       237364 : }
    1289              : 
    1290              : static void var_location_switch_text_section (void);
    1291              : static void set_cur_line_info_table (section *);
    1292              : 
    1293              : void
    1294        65929 : dwarf2out_switch_text_section (void)
    1295              : {
    1296        65929 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
    1297        65929 :   section *sect;
    1298        65929 :   dw_fde_ref fde = cfun->fde;
    1299              : 
    1300        65929 :   gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
    1301              : 
    1302        65929 :   ASM_GENERATE_INTERNAL_LABEL (label, FUNC_SECOND_SECT_LABEL,
    1303              :                                current_function_funcdef_no);
    1304              : 
    1305        65929 :   fde->dw_fde_second_begin = ggc_strdup (label);
    1306        65929 :   if (!in_cold_section_p)
    1307              :     {
    1308            0 :       fde->dw_fde_end = crtl->subsections.cold_section_end_label;
    1309            0 :       fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
    1310              :     }
    1311              :   else
    1312              :     {
    1313        65929 :       fde->dw_fde_end = crtl->subsections.hot_section_end_label;
    1314        65929 :       fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
    1315              :     }
    1316        65929 :   have_multiple_function_sections = true;
    1317              : 
    1318              : #ifdef CODEVIEW_DEBUGGING_INFO
    1319              :   if (codeview_debuginfo_p ())
    1320              :     codeview_switch_text_section ();
    1321              : #endif
    1322              : 
    1323        65929 :   if (dwarf2out_do_cfi_asm ())
    1324        65923 :     fprintf (asm_out_file, "\t.cfi_endproc\n");
    1325              : 
    1326        65929 :   mark_ignored_debug_section (fde, false);
    1327              : 
    1328              :   /* Now do the real section switch.  */
    1329        65929 :   sect = current_function_section ();
    1330        65929 :   switch_to_section (sect);
    1331              : 
    1332        65929 :   fde->second_in_std_section
    1333       131858 :     = (sect == text_section
    1334        65929 :        || (cold_text_section && sect == cold_text_section));
    1335        65929 :   in_text_section_p = sect == text_section;
    1336              : 
    1337        65929 :   if (dwarf2out_do_cfi_asm ())
    1338        65923 :     dwarf2out_do_cfi_startproc (true);
    1339              : 
    1340        65929 :   var_location_switch_text_section ();
    1341              : 
    1342        65929 :   if (cold_text_section != NULL)
    1343        22654 :     set_cur_line_info_table (sect);
    1344        65929 : }
    1345              : 
    1346              : /* And now, the subset of the debugging information support code necessary
    1347              :    for emitting location expressions.  */
    1348              : 
    1349              : /* Describe an entry into the .debug_addr section.  */
    1350              : 
    1351              : enum ate_kind {
    1352              :   ate_kind_rtx,
    1353              :   ate_kind_rtx_dtprel,
    1354              :   ate_kind_label
    1355              : };
    1356              : 
    1357              : struct GTY((for_user)) addr_table_entry {
    1358              :   enum ate_kind kind;
    1359              :   unsigned int refcount;
    1360              :   unsigned int index;
    1361              :   union addr_table_entry_struct_union
    1362              :     {
    1363              :       rtx GTY ((tag ("0"))) rtl;
    1364              :       char * GTY ((tag ("1"))) label;
    1365              :     }
    1366              :   GTY ((desc ("%1.kind"))) addr;
    1367              : };
    1368              : 
    1369              : static dw_loc_descr_ref int_loc_descriptor (poly_int64);
    1370              : static dw_loc_descr_ref uint_loc_descriptor (unsigned HOST_WIDE_INT);
    1371              : 
    1372              : /* Convert a DWARF stack opcode into its string name.  */
    1373              : 
    1374              : static const char *
    1375     64892609 : dwarf_stack_op_name (unsigned int op)
    1376              : {
    1377            0 :   const char *name = get_DW_OP_name (op);
    1378              : 
    1379     64892609 :   if (name != NULL)
    1380     64892609 :     return name;
    1381              : 
    1382              :   return "OP_<unknown>";
    1383              : }
    1384              : 
    1385              : /* Return TRUE iff we're to output location view lists as a separate
    1386              :    attribute next to the location lists, as an extension compatible
    1387              :    with DWARF 2 and above.  */
    1388              : 
    1389              : static inline bool
    1390     61755800 : dwarf2out_locviews_in_attribute ()
    1391              : {
    1392     61755800 :   return debug_variable_location_views == 1;
    1393              : }
    1394              : 
    1395              : /* Return TRUE iff we're to output location view lists as part of the
    1396              :    location lists, as proposed for standardization after DWARF 5.  */
    1397              : 
    1398              : static inline bool
    1399     26060243 : dwarf2out_locviews_in_loclist ()
    1400              : {
    1401              : #ifndef DW_LLE_view_pair
    1402              :   return false;
    1403              : #else
    1404     26060243 :   return debug_variable_location_views == -1;
    1405              : #endif
    1406              : }
    1407              : 
    1408              : /* Return a pointer to a newly allocated location description.  Location
    1409              :    descriptions are simple expression terms that can be strung
    1410              :    together to form more complicated location (address) descriptions.  */
    1411              : 
    1412              : static inline dw_loc_descr_ref
    1413     69461557 : new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
    1414              :                unsigned HOST_WIDE_INT oprnd2)
    1415              : {
    1416     69461557 :   dw_loc_descr_ref descr = ggc_cleared_alloc<dw_loc_descr_node> ();
    1417              : 
    1418     69461557 :   descr->dw_loc_opc = op;
    1419     69461557 :   descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
    1420     69461557 :   descr->dw_loc_oprnd1.val_entry = NULL;
    1421     69461557 :   descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
    1422     69461557 :   descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
    1423     69461557 :   descr->dw_loc_oprnd2.val_entry = NULL;
    1424     69461557 :   descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
    1425              : 
    1426     69461557 :   return descr;
    1427              : }
    1428              : 
    1429              : /* Add a location description term to a location description expression.  */
    1430              : 
    1431              : static inline void
    1432     23456347 : add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
    1433              : {
    1434     23456347 :   dw_loc_descr_ref *d;
    1435              : 
    1436              :   /* Find the end of the chain.  */
    1437    109902418 :   for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
    1438              :     ;
    1439              : 
    1440     23664828 :   *d = descr;
    1441      9475340 : }
    1442              : 
    1443              : /* Compare two location operands for exact equality.  */
    1444              : 
    1445              : static bool
    1446     21153402 : dw_val_equal_p (dw_val_node *a, dw_val_node *b)
    1447              : {
    1448     21153402 :   if (a->val_class != b->val_class)
    1449              :     return false;
    1450     21153402 :   switch (a->val_class)
    1451              :     {
    1452              :     case dw_val_class_none:
    1453              :       return true;
    1454            0 :     case dw_val_class_addr:
    1455            0 :       return rtx_equal_p (a->v.val_addr, b->v.val_addr);
    1456              : 
    1457     14423318 :     case dw_val_class_offset:
    1458     14423318 :     case dw_val_class_unsigned_const:
    1459     14423318 :     case dw_val_class_const:
    1460     14423318 :     case dw_val_class_unsigned_const_implicit:
    1461     14423318 :     case dw_val_class_const_implicit:
    1462     14423318 :     case dw_val_class_range_list:
    1463              :       /* These are all HOST_WIDE_INT, signed or unsigned.  */
    1464     14423318 :       return a->v.val_unsigned == b->v.val_unsigned;
    1465              : 
    1466            0 :     case dw_val_class_loc:
    1467            0 :       return a->v.val_loc == b->v.val_loc;
    1468            0 :     case dw_val_class_loc_list:
    1469            0 :       return a->v.val_loc_list == b->v.val_loc_list;
    1470            0 :     case dw_val_class_view_list:
    1471            0 :       return a->v.val_view_list == b->v.val_view_list;
    1472            0 :     case dw_val_class_die_ref:
    1473            0 :       return a->v.val_die_ref.die == b->v.val_die_ref.die;
    1474            0 :     case dw_val_class_fde_ref:
    1475            0 :       return a->v.val_fde_index == b->v.val_fde_index;
    1476            0 :     case dw_val_class_symview:
    1477            0 :       return strcmp (a->v.val_symbolic_view, b->v.val_symbolic_view) == 0;
    1478            0 :     case dw_val_class_lbl_id:
    1479            0 :     case dw_val_class_lineptr:
    1480            0 :     case dw_val_class_macptr:
    1481            0 :     case dw_val_class_loclistsptr:
    1482            0 :     case dw_val_class_high_pc:
    1483            0 :       return strcmp (a->v.val_lbl_id, b->v.val_lbl_id) == 0;
    1484            0 :     case dw_val_class_str:
    1485            0 :       return a->v.val_str == b->v.val_str;
    1486            0 :     case dw_val_class_flag:
    1487            0 :       return a->v.val_flag == b->v.val_flag;
    1488      6730084 :     case dw_val_class_file:
    1489      6730084 :     case dw_val_class_file_implicit:
    1490      6730084 :       return a->v.val_file == b->v.val_file;
    1491            0 :     case dw_val_class_decl_ref:
    1492            0 :       return a->v.val_decl_ref == b->v.val_decl_ref;
    1493              : 
    1494            0 :     case dw_val_class_const_double:
    1495            0 :       return (a->v.val_double.high == b->v.val_double.high
    1496            0 :               && a->v.val_double.low == b->v.val_double.low);
    1497              : 
    1498            0 :     case dw_val_class_wide_int:
    1499            0 :       return *a->v.val_wide == *b->v.val_wide;
    1500              : 
    1501            0 :     case dw_val_class_vec:
    1502            0 :       {
    1503            0 :         size_t a_len = a->v.val_vec.elt_size * a->v.val_vec.length;
    1504            0 :         size_t b_len = b->v.val_vec.elt_size * b->v.val_vec.length;
    1505              : 
    1506            0 :         return (a_len == b_len
    1507            0 :                 && !memcmp (a->v.val_vec.array, b->v.val_vec.array, a_len));
    1508              :       }
    1509              : 
    1510            0 :     case dw_val_class_data8:
    1511            0 :       return memcmp (a->v.val_data8, b->v.val_data8, 8) == 0;
    1512              : 
    1513            0 :     case dw_val_class_vms_delta:
    1514            0 :       return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
    1515            0 :               && !strcmp (a->v.val_vms_delta.lbl2, b->v.val_vms_delta.lbl2));
    1516              : 
    1517            0 :     case dw_val_class_discr_value:
    1518            0 :       return (a->v.val_discr_value.pos == b->v.val_discr_value.pos
    1519            0 :               && a->v.val_discr_value.v.uval == b->v.val_discr_value.v.uval);
    1520              :     case dw_val_class_discr_list:
    1521              :       /* It makes no sense comparing two discriminant value lists.  */
    1522              :       return false;
    1523              :     }
    1524            0 :   gcc_unreachable ();
    1525              : }
    1526              : 
    1527              : /* Compare two location atoms for exact equality.  */
    1528              : 
    1529              : static bool
    1530           36 : loc_descr_equal_p_1 (dw_loc_descr_ref a, dw_loc_descr_ref b)
    1531              : {
    1532           36 :   if (a->dw_loc_opc != b->dw_loc_opc)
    1533              :     return false;
    1534              : 
    1535              :   /* ??? This is only ever set for DW_OP_constNu, for N equal to the
    1536              :      address size, but since we always allocate cleared storage it
    1537              :      should be zero for other types of locations.  */
    1538           36 :   if (a->dw_loc_dtprel != b->dw_loc_dtprel)
    1539              :     return false;
    1540              : 
    1541           36 :   return (dw_val_equal_p (&a->dw_loc_oprnd1, &b->dw_loc_oprnd1)
    1542           36 :           && dw_val_equal_p (&a->dw_loc_oprnd2, &b->dw_loc_oprnd2));
    1543              : }
    1544              : 
    1545              : /* Compare two complete location expressions for exact equality.  */
    1546              : 
    1547              : bool
    1548           24 : loc_descr_equal_p (dw_loc_descr_ref a, dw_loc_descr_ref b)
    1549              : {
    1550           96 :   while (1)
    1551              :     {
    1552           60 :       if (a == b)
    1553              :         return true;
    1554           36 :       if (a == NULL || b == NULL)
    1555              :         return false;
    1556           36 :       if (!loc_descr_equal_p_1 (a, b))
    1557              :         return false;
    1558              : 
    1559           36 :       a = a->dw_loc_next;
    1560           36 :       b = b->dw_loc_next;
    1561              :     }
    1562              : }
    1563              : 
    1564              : 
    1565              : /* Add a constant POLY_OFFSET to a location expression.  */
    1566              : 
    1567              : static void
    1568       916278 : loc_descr_plus_const (dw_loc_descr_ref *list_head, poly_int64 poly_offset)
    1569              : {
    1570       916278 :   dw_loc_descr_ref loc;
    1571       916278 :   HOST_WIDE_INT *p;
    1572              : 
    1573       916278 :   gcc_assert (*list_head != NULL);
    1574              : 
    1575       916278 :   if (known_eq (poly_offset, 0))
    1576       916278 :     return;
    1577              : 
    1578              :   /* Find the end of the chain.  */
    1579      3280433 :   for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
    1580              :     ;
    1581              : 
    1582       909267 :   HOST_WIDE_INT offset;
    1583       909267 :   if (!poly_offset.is_constant (&offset))
    1584              :     {
    1585              :       loc->dw_loc_next = int_loc_descriptor (poly_offset);
    1586              :       add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_plus, 0, 0));
    1587              :       return;
    1588              :     }
    1589              : 
    1590       909267 :   p = NULL;
    1591       909267 :   if (loc->dw_loc_opc == DW_OP_fbreg
    1592       909267 :       || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
    1593            0 :     p = &loc->dw_loc_oprnd1.v.val_int;
    1594       909267 :   else if (loc->dw_loc_opc == DW_OP_bregx)
    1595            0 :     p = &loc->dw_loc_oprnd2.v.val_int;
    1596              : 
    1597              :   /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
    1598              :      offset.  Don't optimize if an signed integer overflow would happen.  */
    1599            0 :   if (p != NULL
    1600            0 :       && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
    1601            0 :           || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
    1602            0 :     *p += offset;
    1603              : 
    1604       909267 :   else if (offset > 0)
    1605       763380 :     loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
    1606              : 
    1607              :   else
    1608              :     {
    1609       145887 :       loc->dw_loc_next
    1610       145887 :         = uint_loc_descriptor (-(unsigned HOST_WIDE_INT) offset);
    1611       291774 :       add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
    1612              :     }
    1613              : }
    1614              : 
    1615              : /* Return a pointer to a newly allocated location description for
    1616              :    REG and OFFSET.  */
    1617              : 
    1618              : static inline dw_loc_descr_ref
    1619      5412903 : new_reg_loc_descr (unsigned int reg, poly_int64 offset)
    1620              : {
    1621      5412903 :   HOST_WIDE_INT const_offset;
    1622      5412903 :   if (offset.is_constant (&const_offset))
    1623              :     {
    1624      5412903 :       if (reg <= 31)
    1625      5412903 :         return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
    1626      5412903 :                               const_offset, 0);
    1627              :       else
    1628            0 :         return new_loc_descr (DW_OP_bregx, reg, const_offset);
    1629              :     }
    1630              :   else
    1631              :     {
    1632              :       dw_loc_descr_ref ret = new_reg_loc_descr (reg, 0);
    1633              :       loc_descr_plus_const (&ret, offset);
    1634              :       return ret;
    1635              :     }
    1636              : }
    1637              : 
    1638              : /* Add a constant OFFSET to a location list.  */
    1639              : 
    1640              : static void
    1641        79314 : loc_list_plus_const (dw_loc_list_ref list_head, poly_int64 offset)
    1642              : {
    1643        79314 :   dw_loc_list_ref d;
    1644       158628 :   for (d = list_head; d != NULL; d = d->dw_loc_next)
    1645        79314 :     loc_descr_plus_const (&d->expr, offset);
    1646            0 : }
    1647              : 
    1648              : #define DWARF_REF_SIZE  \
    1649              :   (dwarf_version == 2 ? DWARF2_ADDR_SIZE : dwarf_offset_size)
    1650              : 
    1651              : /* The number of bits that can be encoded by largest DW_FORM_dataN.
    1652              :    In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
    1653              :    DW_FORM_data16 with 128 bits.  */
    1654              : #define DWARF_LARGEST_DATA_FORM_BITS \
    1655              :   (dwarf_version >= 5 ? 128 : 64)
    1656              : 
    1657              : /* Utility inline function for construction of ops that were GNU extension
    1658              :    before DWARF 5.  */
    1659              : static inline enum dwarf_location_atom
    1660      4402411 : dwarf_OP (enum dwarf_location_atom op)
    1661              : {
    1662      2235808 :   switch (op)
    1663              :     {
    1664      2149999 :     case DW_OP_implicit_pointer:
    1665            0 :       if (dwarf_version < 5)
    1666          466 :         return DW_OP_GNU_implicit_pointer;
    1667              :       break;
    1668              : 
    1669      1351785 :     case DW_OP_entry_value:
    1670      1351785 :       if (dwarf_version < 5)
    1671          836 :         return DW_OP_GNU_entry_value;
    1672              :       break;
    1673              : 
    1674       252349 :     case DW_OP_const_type:
    1675       252349 :       if (dwarf_version < 5)
    1676            9 :         return DW_OP_GNU_const_type;
    1677              :       break;
    1678              : 
    1679       108919 :     case DW_OP_regval_type:
    1680       108919 :       if (dwarf_version < 5)
    1681          111 :         return DW_OP_GNU_regval_type;
    1682              :       break;
    1683              : 
    1684        75674 :     case DW_OP_deref_type:
    1685        75674 :       if (dwarf_version < 5)
    1686            0 :         return DW_OP_GNU_deref_type;
    1687              :       break;
    1688              : 
    1689       462026 :     case DW_OP_convert:
    1690       445425 :       if (dwarf_version < 5)
    1691            0 :         return DW_OP_GNU_convert;
    1692              :       break;
    1693              : 
    1694         1656 :     case DW_OP_reinterpret:
    1695         1656 :       if (dwarf_version < 5)
    1696            0 :         return DW_OP_GNU_reinterpret;
    1697              :       break;
    1698              : 
    1699            3 :     case DW_OP_addrx:
    1700            3 :       if (dwarf_version < 5)
    1701            0 :         return DW_OP_GNU_addr_index;
    1702              :       break;
    1703              : 
    1704            0 :     case DW_OP_constx:
    1705            0 :       if (dwarf_version < 5)
    1706            0 :         return DW_OP_GNU_const_index;
    1707              :       break;
    1708              : 
    1709              :     default:
    1710              :       break;
    1711              :     }
    1712              :   return op;
    1713              : }
    1714              : 
    1715              : /* Similarly for attributes.  */
    1716              : static inline enum dwarf_attribute
    1717      9705298 : dwarf_AT (enum dwarf_attribute at)
    1718              : {
    1719      9705298 :   switch (at)
    1720              :     {
    1721      2981329 :     case DW_AT_call_return_pc:
    1722      2981329 :       if (dwarf_version < 5)
    1723         1855 :         return DW_AT_low_pc;
    1724              :       break;
    1725              : 
    1726        57575 :     case DW_AT_call_tail_call:
    1727        57575 :       if (dwarf_version < 5)
    1728           90 :         return DW_AT_GNU_tail_call;
    1729              :       break;
    1730              : 
    1731      2911399 :     case DW_AT_call_origin:
    1732      2911399 :       if (dwarf_version < 5)
    1733         1833 :         return DW_AT_abstract_origin;
    1734              :       break;
    1735              : 
    1736         5447 :     case DW_AT_call_target:
    1737         5447 :       if (dwarf_version < 5)
    1738           12 :         return DW_AT_GNU_call_site_target;
    1739              :       break;
    1740              : 
    1741            0 :     case DW_AT_call_target_clobbered:
    1742            0 :       if (dwarf_version < 5)
    1743            0 :         return DW_AT_GNU_call_site_target_clobbered;
    1744              :       break;
    1745              : 
    1746        35789 :     case DW_AT_call_parameter:
    1747        35789 :       if (dwarf_version < 5)
    1748            0 :         return DW_AT_abstract_origin;
    1749              :       break;
    1750              : 
    1751      3133582 :     case DW_AT_call_value:
    1752      3133582 :       if (dwarf_version < 5)
    1753         1497 :         return DW_AT_GNU_call_site_value;
    1754              :       break;
    1755              : 
    1756         7110 :     case DW_AT_call_data_value:
    1757         7110 :       if (dwarf_version < 5)
    1758            0 :         return DW_AT_GNU_call_site_data_value;
    1759              :       break;
    1760              : 
    1761       272404 :     case DW_AT_call_all_calls:
    1762       272404 :       if (dwarf_version < 5)
    1763         2388 :         return DW_AT_GNU_all_call_sites;
    1764              :       break;
    1765              : 
    1766       300170 :     case DW_AT_call_all_tail_calls:
    1767       300170 :       if (dwarf_version < 5)
    1768         1034 :         return DW_AT_GNU_all_tail_call_sites;
    1769              :       break;
    1770              : 
    1771          249 :     case DW_AT_dwo_name:
    1772          249 :       if (dwarf_version < 5)
    1773            1 :         return DW_AT_GNU_dwo_name;
    1774              :       break;
    1775              : 
    1776          244 :     case DW_AT_addr_base:
    1777          244 :       if (dwarf_version < 5)
    1778            0 :         return DW_AT_GNU_addr_base;
    1779              :       break;
    1780              : 
    1781              :     default:
    1782              :       break;
    1783              :     }
    1784              :   return at;
    1785              : }
    1786              : 
    1787              : /* And similarly for tags.  */
    1788              : static inline enum dwarf_tag
    1789      6114911 : dwarf_TAG (enum dwarf_tag tag)
    1790              : {
    1791      6114911 :   switch (tag)
    1792              :     {
    1793      2981329 :     case DW_TAG_call_site:
    1794      2981329 :       if (dwarf_version < 5)
    1795         1855 :         return DW_TAG_GNU_call_site;
    1796              :       break;
    1797              : 
    1798      3133582 :     case DW_TAG_call_site_parameter:
    1799      3133582 :       if (dwarf_version < 5)
    1800         1497 :         return DW_TAG_GNU_call_site_parameter;
    1801              :       break;
    1802              : 
    1803              :     default:
    1804              :       break;
    1805              :     }
    1806              :   return tag;
    1807              : }
    1808              : 
    1809              : /* And similarly for forms.  */
    1810              : static inline enum dwarf_form
    1811     27491066 : dwarf_FORM (enum dwarf_form form)
    1812              : {
    1813     27491066 :   switch (form)
    1814              :     {
    1815          506 :     case DW_FORM_addrx:
    1816          506 :       if (dwarf_version < 5)
    1817              :         return DW_FORM_GNU_addr_index;
    1818              :       break;
    1819              : 
    1820     27490560 :     case DW_FORM_strx:
    1821     27490560 :       if (dwarf_version < 5)
    1822       273796 :         return DW_FORM_GNU_str_index;
    1823              :       break;
    1824              : 
    1825              :     default:
    1826              :       break;
    1827              :     }
    1828              :   return form;
    1829              : }
    1830              : 
    1831              : static unsigned long int get_base_type_offset (dw_die_ref);
    1832              : 
    1833              : /* Return the size of a location descriptor.  */
    1834              : 
    1835              : static unsigned long
    1836    194483324 : size_of_loc_descr (dw_loc_descr_ref loc)
    1837              : {
    1838    194483324 :   unsigned long size = 1;
    1839              : 
    1840    194483324 :   switch (loc->dw_loc_opc)
    1841              :     {
    1842      3530378 :     case DW_OP_addr:
    1843      3530378 :       size += DWARF2_ADDR_SIZE;
    1844      3530378 :       break;
    1845            6 :     case DW_OP_GNU_addr_index:
    1846            6 :     case DW_OP_addrx:
    1847            6 :     case DW_OP_GNU_const_index:
    1848            6 :     case DW_OP_constx:
    1849            6 :       gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
    1850            6 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.val_entry->index);
    1851            6 :       break;
    1852              :     case DW_OP_const1u:
    1853              :     case DW_OP_const1s:
    1854      4063877 :       size += 1;
    1855              :       break;
    1856              :     case DW_OP_const2u:
    1857              :     case DW_OP_const2s:
    1858       957743 :       size += 2;
    1859              :       break;
    1860              :     case DW_OP_const4u:
    1861              :     case DW_OP_const4s:
    1862      1298962 :       size += 4;
    1863              :       break;
    1864         7873 :     case DW_OP_const8u:
    1865         7873 :     case DW_OP_const8s:
    1866         7873 :       size += 8;
    1867         7873 :       break;
    1868       331157 :     case DW_OP_constu:
    1869       331157 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
    1870       331157 :       break;
    1871       100859 :     case DW_OP_consts:
    1872       100859 :       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
    1873       100859 :       break;
    1874              :     case DW_OP_pick:
    1875      4063877 :       size += 1;
    1876              :       break;
    1877      3977000 :     case DW_OP_plus_uconst:
    1878      3977000 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
    1879      3977000 :       break;
    1880              :     case DW_OP_skip:
    1881              :     case DW_OP_bra:
    1882       957743 :       size += 2;
    1883              :       break;
    1884     15419253 :     case DW_OP_breg0:
    1885     15419253 :     case DW_OP_breg1:
    1886     15419253 :     case DW_OP_breg2:
    1887     15419253 :     case DW_OP_breg3:
    1888     15419253 :     case DW_OP_breg4:
    1889     15419253 :     case DW_OP_breg5:
    1890     15419253 :     case DW_OP_breg6:
    1891     15419253 :     case DW_OP_breg7:
    1892     15419253 :     case DW_OP_breg8:
    1893     15419253 :     case DW_OP_breg9:
    1894     15419253 :     case DW_OP_breg10:
    1895     15419253 :     case DW_OP_breg11:
    1896     15419253 :     case DW_OP_breg12:
    1897     15419253 :     case DW_OP_breg13:
    1898     15419253 :     case DW_OP_breg14:
    1899     15419253 :     case DW_OP_breg15:
    1900     15419253 :     case DW_OP_breg16:
    1901     15419253 :     case DW_OP_breg17:
    1902     15419253 :     case DW_OP_breg18:
    1903     15419253 :     case DW_OP_breg19:
    1904     15419253 :     case DW_OP_breg20:
    1905     15419253 :     case DW_OP_breg21:
    1906     15419253 :     case DW_OP_breg22:
    1907     15419253 :     case DW_OP_breg23:
    1908     15419253 :     case DW_OP_breg24:
    1909     15419253 :     case DW_OP_breg25:
    1910     15419253 :     case DW_OP_breg26:
    1911     15419253 :     case DW_OP_breg27:
    1912     15419253 :     case DW_OP_breg28:
    1913     15419253 :     case DW_OP_breg29:
    1914     15419253 :     case DW_OP_breg30:
    1915     15419253 :     case DW_OP_breg31:
    1916     15419253 :       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
    1917     15419253 :       break;
    1918        55234 :     case DW_OP_regx:
    1919        55234 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
    1920        55234 :       break;
    1921     24765255 :     case DW_OP_fbreg:
    1922     24765255 :       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
    1923     24765255 :       break;
    1924            0 :     case DW_OP_bregx:
    1925            0 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
    1926            0 :       size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
    1927            0 :       break;
    1928     15431555 :     case DW_OP_piece:
    1929     15431555 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
    1930     15431555 :       break;
    1931       347760 :     case DW_OP_bit_piece:
    1932       347760 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
    1933       347760 :       size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
    1934       347760 :       break;
    1935              :     case DW_OP_deref_size:
    1936              :     case DW_OP_xderef_size:
    1937      4063877 :       size += 1;
    1938              :       break;
    1939              :     case DW_OP_call2:
    1940       957743 :       size += 2;
    1941              :       break;
    1942              :     case DW_OP_call4:
    1943      1298962 :       size += 4;
    1944              :       break;
    1945          262 :     case DW_OP_call_ref:
    1946          262 :     case DW_OP_GNU_variable_value:
    1947          262 :       size += DWARF_REF_SIZE;
    1948          262 :       break;
    1949       355833 :     case DW_OP_implicit_value:
    1950       355833 :       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
    1951       355833 :               + loc->dw_loc_oprnd1.v.val_unsigned;
    1952       355833 :       break;
    1953      3887134 :     case DW_OP_implicit_pointer:
    1954      3887134 :     case DW_OP_GNU_implicit_pointer:
    1955      3887134 :       size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
    1956      3887134 :       break;
    1957      3845660 :     case DW_OP_entry_value:
    1958      3845660 :     case DW_OP_GNU_entry_value:
    1959      3845660 :       {
    1960      3845660 :         unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
    1961      3845660 :         size += size_of_uleb128 (op_size) + op_size;
    1962      3845660 :         break;
    1963              :       }
    1964       168089 :     case DW_OP_const_type:
    1965       168089 :     case DW_OP_GNU_const_type:
    1966       168089 :       {
    1967       168089 :         unsigned long o
    1968       168089 :           = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
    1969       168089 :         size += size_of_uleb128 (o) + 1;
    1970       168089 :         switch (loc->dw_loc_oprnd2.val_class)
    1971              :           {
    1972        90998 :           case dw_val_class_vec:
    1973        90998 :             size += loc->dw_loc_oprnd2.v.val_vec.length
    1974        90998 :                     * loc->dw_loc_oprnd2.v.val_vec.elt_size;
    1975        90998 :             break;
    1976        76609 :           case dw_val_class_const:
    1977        76609 :             size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
    1978        76609 :             break;
    1979          266 :           case dw_val_class_const_double:
    1980          266 :             size += HOST_BITS_PER_DOUBLE_INT / BITS_PER_UNIT;
    1981          266 :             break;
    1982          216 :           case dw_val_class_wide_int:
    1983          216 :             size += (get_full_len (*loc->dw_loc_oprnd2.v.val_wide)
    1984          216 :                      * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
    1985          216 :             break;
    1986            0 :           default:
    1987            0 :             gcc_unreachable ();
    1988              :           }
    1989              :         break;
    1990              :       }
    1991       361462 :     case DW_OP_regval_type:
    1992       361462 :     case DW_OP_GNU_regval_type:
    1993       361462 :       {
    1994       361462 :         unsigned long o
    1995       361462 :           = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
    1996       361462 :         size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
    1997       361462 :                 + size_of_uleb128 (o);
    1998              :       }
    1999       361462 :       break;
    2000       179696 :     case DW_OP_deref_type:
    2001       179696 :     case DW_OP_GNU_deref_type:
    2002       179696 :       {
    2003       179696 :         unsigned long o
    2004       179696 :           = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
    2005       179696 :         size += 1 + size_of_uleb128 (o);
    2006              :       }
    2007       179696 :       break;
    2008       800643 :     case DW_OP_convert:
    2009       800643 :     case DW_OP_reinterpret:
    2010       800643 :     case DW_OP_GNU_convert:
    2011       800643 :     case DW_OP_GNU_reinterpret:
    2012       800643 :       if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
    2013        84703 :         size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
    2014              :       else
    2015              :         {
    2016       715940 :           unsigned long o
    2017       715940 :             = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
    2018       715940 :           size += size_of_uleb128 (o);
    2019              :         }
    2020              :       break;
    2021              :     case DW_OP_GNU_parameter_ref:
    2022      1298962 :       size += 4;
    2023              :       break;
    2024              :     default:
    2025              :       break;
    2026              :     }
    2027              : 
    2028    194483324 :   return size;
    2029              : }
    2030              : 
    2031              : /* Return the size of a series of location descriptors.  */
    2032              : 
    2033              : unsigned long
    2034     99243666 : size_of_locs (dw_loc_descr_ref loc)
    2035              : {
    2036     99243666 :   dw_loc_descr_ref l;
    2037     99243666 :   unsigned long size;
    2038              : 
    2039              :   /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
    2040              :      field, to avoid writing to a PCH file.  */
    2041    285503908 :   for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
    2042              :     {
    2043    186557868 :       if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
    2044              :         break;
    2045    186260242 :       size += size_of_loc_descr (l);
    2046              :     }
    2047     99243666 :   if (! l)
    2048              :     return size;
    2049              : 
    2050      7560562 :   for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
    2051              :     {
    2052      7262936 :       l->dw_loc_addr = size;
    2053      7262936 :       size += size_of_loc_descr (l);
    2054              :     }
    2055              : 
    2056              :   return size;
    2057              : }
    2058              : 
    2059              : /* Return the size of the value in a DW_AT_discr_value attribute.  */
    2060              : 
    2061              : static int
    2062            0 : size_of_discr_value (dw_discr_value *discr_value)
    2063              : {
    2064            0 :   if (discr_value->pos)
    2065            0 :     return size_of_uleb128 (discr_value->v.uval);
    2066              :   else
    2067            0 :     return size_of_sleb128 (discr_value->v.sval);
    2068              : }
    2069              : 
    2070              : /* Return the size of the value in a DW_AT_discr_list attribute.  */
    2071              : 
    2072              : static int
    2073            0 : size_of_discr_list (dw_discr_list_ref discr_list)
    2074              : {
    2075            0 :   int size = 0;
    2076              : 
    2077            0 :   for (dw_discr_list_ref list = discr_list;
    2078            0 :        list != NULL;
    2079            0 :        list = list->dw_discr_next)
    2080              :     {
    2081              :       /* One byte for the discriminant value descriptor, and then one or two
    2082              :          LEB128 numbers, depending on whether it's a single case label or a
    2083              :          range label.  */
    2084            0 :       size += 1;
    2085            0 :       size += size_of_discr_value (&list->dw_discr_lower_bound);
    2086            0 :       if (list->dw_discr_range != 0)
    2087            0 :         size += size_of_discr_value (&list->dw_discr_upper_bound);
    2088              :     }
    2089            0 :   return size;
    2090              : }
    2091              : 
    2092              : static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
    2093              : static void get_ref_die_offset_label (char *, dw_die_ref);
    2094              : static unsigned long int get_ref_die_offset (dw_die_ref);
    2095              : 
    2096              : /* Output location description stack opcode's operands (if any).
    2097              :    The for_eh_or_skip parameter controls whether register numbers are
    2098              :    converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
    2099              :    hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
    2100              :    info).  This should be suppressed for the cases that have not been converted
    2101              :    (i.e. symbolic debug info), by setting the parameter < 0.  See PR47324.  */
    2102              : 
    2103              : static void
    2104     64892581 : output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
    2105              : {
    2106     64892581 :   dw_val_ref val1 = &loc->dw_loc_oprnd1;
    2107     64892581 :   dw_val_ref val2 = &loc->dw_loc_oprnd2;
    2108              : 
    2109     64892581 :   switch (loc->dw_loc_opc)
    2110              :     {
    2111              : #ifdef DWARF2_DEBUGGING_INFO
    2112       160204 :     case DW_OP_const2u:
    2113       160204 :     case DW_OP_const2s:
    2114       160204 :       dw2_asm_output_data (2, val1->v.val_int, NULL);
    2115       160204 :       break;
    2116       362906 :     case DW_OP_const4u:
    2117       362906 :       if (loc->dw_loc_dtprel)
    2118              :         {
    2119          131 :           gcc_assert (targetm.asm_out.output_dwarf_dtprel);
    2120          131 :           targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
    2121              :                                                val1->v.val_addr);
    2122          131 :           fputc ('\n', asm_out_file);
    2123          131 :           break;
    2124              :         }
    2125              :       /* FALLTHRU */
    2126       362775 :     case DW_OP_const4s:
    2127       362775 :       dw2_asm_output_data (4, val1->v.val_int, NULL);
    2128       362775 :       break;
    2129         2385 :     case DW_OP_const8u:
    2130         2385 :       if (loc->dw_loc_dtprel)
    2131              :         {
    2132          556 :           gcc_assert (targetm.asm_out.output_dwarf_dtprel);
    2133          556 :           targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
    2134              :                                                val1->v.val_addr);
    2135          556 :           fputc ('\n', asm_out_file);
    2136          556 :           break;
    2137              :         }
    2138              :       /* FALLTHRU */
    2139         1829 :     case DW_OP_const8s:
    2140         1829 :       gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
    2141         1829 :       dw2_asm_output_data (8, val1->v.val_int, NULL);
    2142         1829 :       break;
    2143       132508 :     case DW_OP_skip:
    2144       132508 :     case DW_OP_bra:
    2145       132508 :       {
    2146       132508 :         int offset;
    2147              : 
    2148       132508 :         gcc_assert (val1->val_class == dw_val_class_loc);
    2149       132508 :         offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
    2150              : 
    2151       132508 :         dw2_asm_output_data (2, offset, NULL);
    2152              :       }
    2153       132508 :       break;
    2154       115696 :     case DW_OP_implicit_value:
    2155       115696 :       dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
    2156       115696 :       switch (val2->val_class)
    2157              :         {
    2158        52905 :         case dw_val_class_const:
    2159        52905 :           dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
    2160        52905 :           break;
    2161        62301 :         case dw_val_class_vec:
    2162        62301 :           {
    2163        62301 :             unsigned int elt_size = val2->v.val_vec.elt_size;
    2164        62301 :             unsigned int len = val2->v.val_vec.length;
    2165        62301 :             unsigned int i;
    2166        62301 :             unsigned char *p;
    2167              : 
    2168        62301 :             if (elt_size > sizeof (HOST_WIDE_INT))
    2169              :               {
    2170            0 :                 elt_size /= 2;
    2171            0 :                 len *= 2;
    2172              :               }
    2173        62301 :             for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
    2174       288987 :                  i < len;
    2175       226686 :                  i++, p += elt_size)
    2176       453372 :               dw2_asm_output_data (elt_size, extract_int (p, elt_size),
    2177              :                                    "fp or vector constant word %u", i);
    2178              :           }
    2179              :           break;
    2180            0 :         case dw_val_class_const_double:
    2181            0 :           {
    2182            0 :             unsigned HOST_WIDE_INT first, second;
    2183              : 
    2184            0 :             if (WORDS_BIG_ENDIAN)
    2185              :               {
    2186              :                 first = val2->v.val_double.high;
    2187              :                 second = val2->v.val_double.low;
    2188              :               }
    2189              :             else
    2190              :               {
    2191            0 :                 first = val2->v.val_double.low;
    2192            0 :                 second = val2->v.val_double.high;
    2193              :               }
    2194            0 :             dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
    2195              :                                  first, NULL);
    2196            0 :             dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
    2197              :                                  second, NULL);
    2198              :           }
    2199            0 :           break;
    2200          490 :         case dw_val_class_wide_int:
    2201          490 :           {
    2202          490 :             int i;
    2203          490 :             int len = get_full_len (*val2->v.val_wide);
    2204          490 :             if (WORDS_BIG_ENDIAN)
    2205              :               for (i = len - 1; i >= 0; --i)
    2206              :                 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
    2207              :                                      val2->v.val_wide->elt (i), NULL);
    2208              :             else
    2209         1470 :               for (i = 0; i < len; ++i)
    2210          980 :                 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
    2211          980 :                                      val2->v.val_wide->elt (i), NULL);
    2212              :           }
    2213              :           break;
    2214            0 :         case dw_val_class_addr:
    2215            0 :           gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
    2216            0 :           dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
    2217            0 :           break;
    2218            0 :         default:
    2219            0 :           gcc_unreachable ();
    2220              :         }
    2221              :       break;
    2222              : #else
    2223              :     case DW_OP_const2u:
    2224              :     case DW_OP_const2s:
    2225              :     case DW_OP_const4u:
    2226              :     case DW_OP_const4s:
    2227              :     case DW_OP_const8u:
    2228              :     case DW_OP_const8s:
    2229              :     case DW_OP_skip:
    2230              :     case DW_OP_bra:
    2231              :     case DW_OP_implicit_value:
    2232              :       /* We currently don't make any attempt to make sure these are
    2233              :          aligned properly like we do for the main unwind info, so
    2234              :          don't support emitting things larger than a byte if we're
    2235              :          only doing unwinding.  */
    2236              :       gcc_unreachable ();
    2237              : #endif
    2238      1113888 :     case DW_OP_const1u:
    2239      1113888 :     case DW_OP_const1s:
    2240      1113888 :       dw2_asm_output_data (1, val1->v.val_int, NULL);
    2241      1113888 :       break;
    2242       131593 :     case DW_OP_constu:
    2243       131593 :       dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
    2244       131593 :       break;
    2245        23448 :     case DW_OP_consts:
    2246        23448 :       dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
    2247        23448 :       break;
    2248          177 :     case DW_OP_pick:
    2249          177 :       dw2_asm_output_data (1, val1->v.val_int, NULL);
    2250          177 :       break;
    2251       865690 :     case DW_OP_plus_uconst:
    2252       865690 :       dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
    2253       865690 :       break;
    2254      5207678 :     case DW_OP_breg0:
    2255      5207678 :     case DW_OP_breg1:
    2256      5207678 :     case DW_OP_breg2:
    2257      5207678 :     case DW_OP_breg3:
    2258      5207678 :     case DW_OP_breg4:
    2259      5207678 :     case DW_OP_breg5:
    2260      5207678 :     case DW_OP_breg6:
    2261      5207678 :     case DW_OP_breg7:
    2262      5207678 :     case DW_OP_breg8:
    2263      5207678 :     case DW_OP_breg9:
    2264      5207678 :     case DW_OP_breg10:
    2265      5207678 :     case DW_OP_breg11:
    2266      5207678 :     case DW_OP_breg12:
    2267      5207678 :     case DW_OP_breg13:
    2268      5207678 :     case DW_OP_breg14:
    2269      5207678 :     case DW_OP_breg15:
    2270      5207678 :     case DW_OP_breg16:
    2271      5207678 :     case DW_OP_breg17:
    2272      5207678 :     case DW_OP_breg18:
    2273      5207678 :     case DW_OP_breg19:
    2274      5207678 :     case DW_OP_breg20:
    2275      5207678 :     case DW_OP_breg21:
    2276      5207678 :     case DW_OP_breg22:
    2277      5207678 :     case DW_OP_breg23:
    2278      5207678 :     case DW_OP_breg24:
    2279      5207678 :     case DW_OP_breg25:
    2280      5207678 :     case DW_OP_breg26:
    2281      5207678 :     case DW_OP_breg27:
    2282      5207678 :     case DW_OP_breg28:
    2283      5207678 :     case DW_OP_breg29:
    2284      5207678 :     case DW_OP_breg30:
    2285      5207678 :     case DW_OP_breg31:
    2286      5207678 :       dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
    2287      5207678 :       break;
    2288        18407 :     case DW_OP_regx:
    2289        18407 :       {
    2290        18407 :         unsigned r = val1->v.val_unsigned;
    2291        18407 :         if (for_eh_or_skip >= 0)
    2292        18407 :           r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
    2293        18407 :         gcc_assert (size_of_uleb128 (r)
    2294              :                     == size_of_uleb128 (val1->v.val_unsigned));
    2295        18407 :         dw2_asm_output_data_uleb128 (r, NULL);
    2296              :       }
    2297        18407 :       break;
    2298      8601662 :     case DW_OP_fbreg:
    2299      8601662 :       dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
    2300      8601662 :       break;
    2301            0 :     case DW_OP_bregx:
    2302            0 :       {
    2303            0 :         unsigned r = val1->v.val_unsigned;
    2304            0 :         if (for_eh_or_skip >= 0)
    2305            0 :           r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
    2306            0 :         gcc_assert (size_of_uleb128 (r)
    2307              :                     == size_of_uleb128 (val1->v.val_unsigned));
    2308            0 :         dw2_asm_output_data_uleb128 (r, NULL);
    2309            0 :         dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
    2310              :       }
    2311            0 :       break;
    2312      5140148 :     case DW_OP_piece:
    2313      5140148 :       dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
    2314      5140148 :       break;
    2315       115920 :     case DW_OP_bit_piece:
    2316       115920 :       dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
    2317       115920 :       dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
    2318       115920 :       break;
    2319       178626 :     case DW_OP_deref_size:
    2320       178626 :     case DW_OP_xderef_size:
    2321       178626 :       dw2_asm_output_data (1, val1->v.val_int, NULL);
    2322       178626 :       break;
    2323              : 
    2324      1475059 :     case DW_OP_addr:
    2325      1475059 :       if (loc->dw_loc_dtprel)
    2326              :         {
    2327            0 :           if (targetm.asm_out.output_dwarf_dtprel)
    2328              :             {
    2329            0 :               targetm.asm_out.output_dwarf_dtprel (asm_out_file,
    2330            0 :                                                    DWARF2_ADDR_SIZE,
    2331              :                                                    val1->v.val_addr);
    2332            0 :               fputc ('\n', asm_out_file);
    2333              :             }
    2334              :           else
    2335            0 :             gcc_unreachable ();
    2336              :         }
    2337              :       else
    2338              :         {
    2339              : #ifdef DWARF2_DEBUGGING_INFO
    2340      1555980 :           dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
    2341              : #else
    2342              :           gcc_unreachable ();
    2343              : #endif
    2344              :         }
    2345              :       break;
    2346              : 
    2347            3 :     case DW_OP_GNU_addr_index:
    2348            3 :     case DW_OP_addrx:
    2349            3 :     case DW_OP_GNU_const_index:
    2350            3 :     case DW_OP_constx:
    2351            3 :       gcc_assert (loc->dw_loc_oprnd1.val_entry->index != NO_INDEX_ASSIGNED);
    2352            3 :       dw2_asm_output_data_uleb128 (loc->dw_loc_oprnd1.val_entry->index,
    2353              :                                    "(index into .debug_addr)");
    2354            3 :       break;
    2355              : 
    2356            3 :     case DW_OP_call2:
    2357            3 :     case DW_OP_call4:
    2358            3 :       {
    2359            3 :         unsigned long die_offset
    2360            3 :           = get_ref_die_offset (val1->v.val_die_ref.die);
    2361              :         /* Make sure the offset has been computed and that we can encode it as
    2362              :            an operand.  */
    2363            6 :         gcc_assert (die_offset > 0
    2364              :                     && die_offset <= (loc->dw_loc_opc == DW_OP_call2
    2365              :                                      ? 0xffff
    2366              :                                      : 0xffffffff));
    2367            3 :         dw2_asm_output_data ((loc->dw_loc_opc == DW_OP_call2) ? 2 : 4,
    2368              :                              die_offset, NULL);
    2369              :       }
    2370            3 :       break;
    2371              : 
    2372          125 :     case DW_OP_call_ref:
    2373          125 :     case DW_OP_GNU_variable_value:
    2374          125 :       {
    2375          125 :         char label[MAX_ARTIFICIAL_LABEL_BYTES
    2376              :                    + HOST_BITS_PER_WIDE_INT / 2 + 2];
    2377          125 :         gcc_assert (val1->val_class == dw_val_class_die_ref);
    2378          125 :         get_ref_die_offset_label (label, val1->v.val_die_ref.die);
    2379          125 :         dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
    2380              :       }
    2381          125 :       break;
    2382              : 
    2383      1294626 :     case DW_OP_implicit_pointer:
    2384      1294626 :     case DW_OP_GNU_implicit_pointer:
    2385      1294626 :       {
    2386      1294626 :         char label[MAX_ARTIFICIAL_LABEL_BYTES
    2387              :                    + HOST_BITS_PER_WIDE_INT / 2 + 2];
    2388      1294626 :         gcc_assert (val1->val_class == dw_val_class_die_ref);
    2389      1294626 :         get_ref_die_offset_label (label, val1->v.val_die_ref.die);
    2390      1294626 :         dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
    2391      1294626 :         dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
    2392              :       }
    2393      1294626 :       break;
    2394              : 
    2395      1351416 :     case DW_OP_entry_value:
    2396      1351416 :     case DW_OP_GNU_entry_value:
    2397      1351416 :       dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
    2398      1351416 :       output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
    2399      1351416 :       break;
    2400              : 
    2401        51608 :     case DW_OP_const_type:
    2402        51608 :     case DW_OP_GNU_const_type:
    2403        51608 :       {
    2404        51608 :         unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
    2405        51608 :         gcc_assert (o);
    2406        51608 :         dw2_asm_output_data_uleb128 (o, NULL);
    2407        51608 :         switch (val2->val_class)
    2408              :           {
    2409        18316 :           case dw_val_class_const:
    2410        18316 :             l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
    2411        18316 :             dw2_asm_output_data (1, l, NULL);
    2412        18316 :             dw2_asm_output_data (l, val2->v.val_int, NULL);
    2413        18316 :             break;
    2414        33131 :           case dw_val_class_vec:
    2415        33131 :             {
    2416        33131 :               unsigned int elt_size = val2->v.val_vec.elt_size;
    2417        33131 :               unsigned int len = val2->v.val_vec.length;
    2418        33131 :               unsigned int i;
    2419        33131 :               unsigned char *p;
    2420              : 
    2421        33131 :               l = len * elt_size;
    2422        33131 :               dw2_asm_output_data (1, l, NULL);
    2423        33131 :               if (elt_size > sizeof (HOST_WIDE_INT))
    2424              :                 {
    2425            0 :                   elt_size /= 2;
    2426            0 :                   len *= 2;
    2427              :                 }
    2428        33131 :               for (i = 0, p = (unsigned char *) val2->v.val_vec.array;
    2429       103664 :                    i < len;
    2430        70533 :                    i++, p += elt_size)
    2431       141066 :                 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
    2432              :                                      "fp or vector constant word %u", i);
    2433              :             }
    2434              :             break;
    2435           89 :           case dw_val_class_const_double:
    2436           89 :             {
    2437           89 :               unsigned HOST_WIDE_INT first, second;
    2438           89 :               l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
    2439              : 
    2440           89 :               dw2_asm_output_data (1, 2 * l, NULL);
    2441           89 :               if (WORDS_BIG_ENDIAN)
    2442              :                 {
    2443              :                   first = val2->v.val_double.high;
    2444              :                   second = val2->v.val_double.low;
    2445              :                 }
    2446              :               else
    2447              :                 {
    2448           89 :                   first = val2->v.val_double.low;
    2449           89 :                   second = val2->v.val_double.high;
    2450              :                 }
    2451           89 :               dw2_asm_output_data (l, first, NULL);
    2452           89 :               dw2_asm_output_data (l, second, NULL);
    2453              :             }
    2454           89 :             break;
    2455           72 :           case dw_val_class_wide_int:
    2456           72 :             {
    2457           72 :               int i;
    2458           72 :               int len = get_full_len (*val2->v.val_wide);
    2459           72 :               l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
    2460              : 
    2461           72 :               dw2_asm_output_data (1, len * l, NULL);
    2462           72 :               if (WORDS_BIG_ENDIAN)
    2463              :                 for (i = len - 1; i >= 0; --i)
    2464              :                   dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
    2465              :               else
    2466          288 :                 for (i = 0; i < len; ++i)
    2467          144 :                   dw2_asm_output_data (l, val2->v.val_wide->elt (i), NULL);
    2468              :             }
    2469              :             break;
    2470            0 :           default:
    2471            0 :             gcc_unreachable ();
    2472              :           }
    2473              :       }
    2474              :       break;
    2475       105057 :     case DW_OP_regval_type:
    2476       105057 :     case DW_OP_GNU_regval_type:
    2477       105057 :       {
    2478       105057 :         unsigned r = val1->v.val_unsigned;
    2479       105057 :         unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
    2480       105057 :         gcc_assert (o);
    2481       105057 :         if (for_eh_or_skip >= 0)
    2482              :           {
    2483            0 :             r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
    2484            0 :             gcc_assert (size_of_uleb128 (r)
    2485              :                         == size_of_uleb128 (val1->v.val_unsigned));
    2486              :           }
    2487       105057 :         dw2_asm_output_data_uleb128 (r, NULL);
    2488       105057 :         dw2_asm_output_data_uleb128 (o, NULL);
    2489              :       }
    2490       105057 :       break;
    2491        57010 :     case DW_OP_deref_type:
    2492        57010 :     case DW_OP_GNU_deref_type:
    2493        57010 :       {
    2494        57010 :         unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
    2495        57010 :         gcc_assert (o);
    2496        57010 :         dw2_asm_output_data (1, val1->v.val_int, NULL);
    2497        57010 :         dw2_asm_output_data_uleb128 (o, NULL);
    2498              :       }
    2499        57010 :       break;
    2500       237914 :     case DW_OP_convert:
    2501       237914 :     case DW_OP_reinterpret:
    2502       237914 :     case DW_OP_GNU_convert:
    2503       237914 :     case DW_OP_GNU_reinterpret:
    2504       237914 :       if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
    2505        27510 :         dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
    2506              :       else
    2507              :         {
    2508       210404 :           unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
    2509       210404 :           gcc_assert (o);
    2510       210404 :           dw2_asm_output_data_uleb128 (o, NULL);
    2511              :         }
    2512              :       break;
    2513              : 
    2514        32522 :     case DW_OP_GNU_parameter_ref:
    2515        32522 :       {
    2516        32522 :         unsigned long o;
    2517        32522 :         gcc_assert (val1->val_class == dw_val_class_die_ref);
    2518        32522 :         o = get_ref_die_offset (val1->v.val_die_ref.die);
    2519        32522 :         dw2_asm_output_data (4, o, NULL);
    2520              :       }
    2521        32522 :       break;
    2522              : 
    2523              :     default:
    2524              :       /* Other codes have no operands.  */
    2525              :       break;
    2526              :     }
    2527     64892581 : }
    2528              : 
    2529              : /* Output a sequence of location operations.
    2530              :    The for_eh_or_skip parameter controls whether register numbers are
    2531              :    converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
    2532              :    hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
    2533              :    info).  This should be suppressed for the cases that have not been converted
    2534              :    (i.e. symbolic debug info), by setting the parameter < 0.  See PR47324.  */
    2535              : 
    2536              : void
    2537     35379498 : output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
    2538              : {
    2539    100272079 :   for (; loc != NULL; loc = loc->dw_loc_next)
    2540              :     {
    2541     64892581 :       enum dwarf_location_atom opc = loc->dw_loc_opc;
    2542              :       /* Output the opcode.  */
    2543     64892581 :       if (for_eh_or_skip >= 0
    2544              :           && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
    2545              :         {
    2546              :           unsigned r = (opc - DW_OP_breg0);
    2547              :           r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
    2548              :           gcc_assert (r <= 31);
    2549              :           opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
    2550              :         }
    2551     64892581 :       else if (for_eh_or_skip >= 0
    2552              :                && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
    2553              :         {
    2554              :           unsigned r = (opc - DW_OP_reg0);
    2555              :           r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
    2556              :           gcc_assert (r <= 31);
    2557              :           opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
    2558              :         }
    2559              : 
    2560    129785162 :       dw2_asm_output_data (1, opc,
    2561              :                              "%s", dwarf_stack_op_name (opc));
    2562              : 
    2563              :       /* Output the operand(s) (if any).  */
    2564     64892581 :       output_loc_operands (loc, for_eh_or_skip);
    2565              :     }
    2566     35379498 : }
    2567              : 
    2568              : /* Output location description stack opcode's operands (if any).
    2569              :    The output is single bytes on a line, suitable for .cfi_escape.  */
    2570              : 
    2571              : static void
    2572        63783 : output_loc_operands_raw (dw_loc_descr_ref loc)
    2573              : {
    2574        63783 :   dw_val_ref val1 = &loc->dw_loc_oprnd1;
    2575        63783 :   dw_val_ref val2 = &loc->dw_loc_oprnd2;
    2576              : 
    2577        63783 :   switch (loc->dw_loc_opc)
    2578              :     {
    2579            0 :     case DW_OP_addr:
    2580            0 :     case DW_OP_GNU_addr_index:
    2581            0 :     case DW_OP_addrx:
    2582            0 :     case DW_OP_GNU_const_index:
    2583            0 :     case DW_OP_constx:
    2584            0 :     case DW_OP_implicit_value:
    2585              :       /* We cannot output addresses in .cfi_escape, only bytes.  */
    2586            0 :       gcc_unreachable ();
    2587              : 
    2588            0 :     case DW_OP_const1u:
    2589            0 :     case DW_OP_const1s:
    2590            0 :     case DW_OP_pick:
    2591            0 :     case DW_OP_deref_size:
    2592            0 :     case DW_OP_xderef_size:
    2593            0 :       fputc (',', asm_out_file);
    2594            0 :       dw2_asm_output_data_raw (1, val1->v.val_int);
    2595            0 :       break;
    2596              : 
    2597            0 :     case DW_OP_const2u:
    2598            0 :     case DW_OP_const2s:
    2599            0 :       fputc (',', asm_out_file);
    2600            0 :       dw2_asm_output_data_raw (2, val1->v.val_int);
    2601            0 :       break;
    2602              : 
    2603            0 :     case DW_OP_const4u:
    2604            0 :     case DW_OP_const4s:
    2605            0 :       fputc (',', asm_out_file);
    2606            0 :       dw2_asm_output_data_raw (4, val1->v.val_int);
    2607            0 :       break;
    2608              : 
    2609            0 :     case DW_OP_const8u:
    2610            0 :     case DW_OP_const8s:
    2611            0 :       gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
    2612            0 :       fputc (',', asm_out_file);
    2613            0 :       dw2_asm_output_data_raw (8, val1->v.val_int);
    2614            0 :       break;
    2615              : 
    2616            0 :     case DW_OP_skip:
    2617            0 :     case DW_OP_bra:
    2618            0 :       {
    2619            0 :         int offset;
    2620              : 
    2621            0 :         gcc_assert (val1->val_class == dw_val_class_loc);
    2622            0 :         offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
    2623              : 
    2624            0 :         fputc (',', asm_out_file);
    2625            0 :         dw2_asm_output_data_raw (2, offset);
    2626              :       }
    2627            0 :       break;
    2628              : 
    2629            0 :     case DW_OP_regx:
    2630            0 :       {
    2631            0 :         unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
    2632            0 :         gcc_assert (size_of_uleb128 (r)
    2633              :                     == size_of_uleb128 (val1->v.val_unsigned));
    2634            0 :         fputc (',', asm_out_file);
    2635            0 :         dw2_asm_output_data_uleb128_raw (r);
    2636              :       }
    2637            0 :       break;
    2638              : 
    2639            0 :     case DW_OP_constu:
    2640            0 :     case DW_OP_plus_uconst:
    2641            0 :     case DW_OP_piece:
    2642            0 :       fputc (',', asm_out_file);
    2643            0 :       dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
    2644            0 :       break;
    2645              : 
    2646            0 :     case DW_OP_bit_piece:
    2647            0 :       fputc (',', asm_out_file);
    2648            0 :       dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
    2649            0 :       dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
    2650            0 :       break;
    2651              : 
    2652        54942 :     case DW_OP_consts:
    2653        54942 :     case DW_OP_breg0:
    2654        54942 :     case DW_OP_breg1:
    2655        54942 :     case DW_OP_breg2:
    2656        54942 :     case DW_OP_breg3:
    2657        54942 :     case DW_OP_breg4:
    2658        54942 :     case DW_OP_breg5:
    2659        54942 :     case DW_OP_breg6:
    2660        54942 :     case DW_OP_breg7:
    2661        54942 :     case DW_OP_breg8:
    2662        54942 :     case DW_OP_breg9:
    2663        54942 :     case DW_OP_breg10:
    2664        54942 :     case DW_OP_breg11:
    2665        54942 :     case DW_OP_breg12:
    2666        54942 :     case DW_OP_breg13:
    2667        54942 :     case DW_OP_breg14:
    2668        54942 :     case DW_OP_breg15:
    2669        54942 :     case DW_OP_breg16:
    2670        54942 :     case DW_OP_breg17:
    2671        54942 :     case DW_OP_breg18:
    2672        54942 :     case DW_OP_breg19:
    2673        54942 :     case DW_OP_breg20:
    2674        54942 :     case DW_OP_breg21:
    2675        54942 :     case DW_OP_breg22:
    2676        54942 :     case DW_OP_breg23:
    2677        54942 :     case DW_OP_breg24:
    2678        54942 :     case DW_OP_breg25:
    2679        54942 :     case DW_OP_breg26:
    2680        54942 :     case DW_OP_breg27:
    2681        54942 :     case DW_OP_breg28:
    2682        54942 :     case DW_OP_breg29:
    2683        54942 :     case DW_OP_breg30:
    2684        54942 :     case DW_OP_breg31:
    2685        54942 :     case DW_OP_fbreg:
    2686        54942 :       fputc (',', asm_out_file);
    2687        54942 :       dw2_asm_output_data_sleb128_raw (val1->v.val_int);
    2688        54942 :       break;
    2689              : 
    2690            0 :     case DW_OP_bregx:
    2691            0 :       {
    2692            0 :         unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
    2693            0 :         gcc_assert (size_of_uleb128 (r)
    2694              :                     == size_of_uleb128 (val1->v.val_unsigned));
    2695            0 :         fputc (',', asm_out_file);
    2696            0 :         dw2_asm_output_data_uleb128_raw (r);
    2697            0 :         fputc (',', asm_out_file);
    2698            0 :         dw2_asm_output_data_sleb128_raw (val2->v.val_int);
    2699              :       }
    2700            0 :       break;
    2701              : 
    2702            0 :     case DW_OP_implicit_pointer:
    2703            0 :     case DW_OP_entry_value:
    2704            0 :     case DW_OP_const_type:
    2705            0 :     case DW_OP_regval_type:
    2706            0 :     case DW_OP_deref_type:
    2707            0 :     case DW_OP_convert:
    2708            0 :     case DW_OP_reinterpret:
    2709            0 :     case DW_OP_GNU_implicit_pointer:
    2710            0 :     case DW_OP_GNU_entry_value:
    2711            0 :     case DW_OP_GNU_const_type:
    2712            0 :     case DW_OP_GNU_regval_type:
    2713            0 :     case DW_OP_GNU_deref_type:
    2714            0 :     case DW_OP_GNU_convert:
    2715            0 :     case DW_OP_GNU_reinterpret:
    2716            0 :     case DW_OP_GNU_parameter_ref:
    2717            0 :       gcc_unreachable ();
    2718              :       break;
    2719              : 
    2720              :     default:
    2721              :       /* Other codes have no operands.  */
    2722              :       break;
    2723              :     }
    2724        63783 : }
    2725              : 
    2726              : void
    2727        54942 : output_loc_sequence_raw (dw_loc_descr_ref loc)
    2728              : {
    2729        72624 :   while (1)
    2730              :     {
    2731        63783 :       enum dwarf_location_atom opc = loc->dw_loc_opc;
    2732              :       /* Output the opcode.  */
    2733        63783 :       if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
    2734              :         {
    2735              :           unsigned r = (opc - DW_OP_breg0);
    2736              :           r = DWARF2_FRAME_REG_OUT (r, 1);
    2737              :           gcc_assert (r <= 31);
    2738              :           opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
    2739              :         }
    2740        63783 :       else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
    2741              :         {
    2742              :           unsigned r = (opc - DW_OP_reg0);
    2743              :           r = DWARF2_FRAME_REG_OUT (r, 1);
    2744              :           gcc_assert (r <= 31);
    2745              :           opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
    2746              :         }
    2747              :       /* Output the opcode.  */
    2748        63783 :       fprintf (asm_out_file, "%#x", opc);
    2749        63783 :       output_loc_operands_raw (loc);
    2750              : 
    2751        63783 :       if (!loc->dw_loc_next)
    2752              :         break;
    2753         8841 :       loc = loc->dw_loc_next;
    2754              : 
    2755         8841 :       fputc (',', asm_out_file);
    2756         8841 :     }
    2757        54942 : }
    2758              : 
    2759              : static void
    2760            0 : build_breg_loc (struct dw_loc_descr_node **head, unsigned int regno)
    2761              : {
    2762            0 :   if (regno <= 31)
    2763            0 :     add_loc_descr (head, new_loc_descr ((enum dwarf_location_atom)
    2764            0 :                                         (DW_OP_breg0 + regno),  0, 0));
    2765              :   else
    2766            0 :     add_loc_descr (head, new_loc_descr (DW_OP_bregx, regno, 0));
    2767            0 : }
    2768              : 
    2769              : /* Build a dwarf location for a cfa_reg spanning multiple
    2770              :    consecutive registers.  */
    2771              : 
    2772              : struct dw_loc_descr_node *
    2773            0 : build_span_loc (struct cfa_reg reg)
    2774              : {
    2775            0 :   struct dw_loc_descr_node *head = NULL;
    2776              : 
    2777            0 :   gcc_assert (reg.span_width > 0);
    2778            0 :   gcc_assert (reg.span > 1);
    2779              : 
    2780              :   /* Start from the highest number register as it goes in the upper bits.  */
    2781            0 :   unsigned int regno = reg.reg + reg.span - 1;
    2782            0 :   build_breg_loc (&head, regno);
    2783              : 
    2784              :   /* Deal with the remaining registers in the span.  */
    2785            0 :   for (int i = reg.span - 2; i >= 0; i--)
    2786              :     {
    2787            0 :       add_loc_descr (&head, int_loc_descriptor (reg.span_width * 8));
    2788            0 :       add_loc_descr (&head, new_loc_descr (DW_OP_shl, 0, 0));
    2789            0 :       regno--;
    2790            0 :       build_breg_loc (&head, regno);
    2791            0 :       add_loc_descr (&head, new_loc_descr (DW_OP_plus, 0, 0));
    2792              :     }
    2793            0 :   return head;
    2794              : }
    2795              : 
    2796              : /* This function builds a dwarf location descriptor sequence from a
    2797              :    dw_cfa_location, adding the given OFFSET to the result of the
    2798              :    expression.  */
    2799              : 
    2800              : struct dw_loc_descr_node *
    2801        16246 : build_cfa_loc (dw_cfa_location *cfa, poly_int64 offset)
    2802              : {
    2803        16246 :   struct dw_loc_descr_node *head, *tmp;
    2804              : 
    2805        16246 :   offset += cfa->offset;
    2806              : 
    2807        16246 :   if (cfa->reg.span > 1)
    2808              :     {
    2809            0 :       head = build_span_loc (cfa->reg);
    2810              : 
    2811            0 :       if (maybe_ne (offset, 0))
    2812            0 :           loc_descr_plus_const (&head, offset);
    2813              :     }
    2814        16246 :   else if (cfa->indirect)
    2815              :     {
    2816         7011 :       head = new_reg_loc_descr (cfa->reg.reg, cfa->base_offset);
    2817         7011 :       head->dw_loc_oprnd1.val_class = dw_val_class_const;
    2818         7011 :       head->dw_loc_oprnd1.val_entry = NULL;
    2819         7011 :       tmp = new_loc_descr (DW_OP_deref, 0, 0);
    2820         7011 :       add_loc_descr (&head, tmp);
    2821         7011 :       loc_descr_plus_const (&head, offset);
    2822              :     }
    2823              :   else
    2824         9235 :     head = new_reg_loc_descr (cfa->reg.reg, offset);
    2825              : 
    2826        16246 :   return head;
    2827              : }
    2828              : 
    2829              : /* This function builds a dwarf location descriptor sequence for
    2830              :    the address at OFFSET from the CFA when stack is aligned to
    2831              :    ALIGNMENT byte.  */
    2832              : 
    2833              : struct dw_loc_descr_node *
    2834        17793 : build_cfa_aligned_loc (dw_cfa_location *cfa,
    2835              :                        poly_int64 offset, HOST_WIDE_INT alignment)
    2836              : {
    2837        17793 :   struct dw_loc_descr_node *head;
    2838        17793 :   unsigned int dwarf_fp
    2839        17793 :     = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
    2840              : 
    2841              :   /* When CFA is defined as FP+OFFSET, emulate stack alignment.  */
    2842        17793 :   if (cfa->reg.reg == HARD_FRAME_POINTER_REGNUM && cfa->indirect == 0)
    2843              :     {
    2844            0 :       head = new_reg_loc_descr (dwarf_fp, 0);
    2845            0 :       add_loc_descr (&head, int_loc_descriptor (alignment));
    2846            0 :       add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
    2847            0 :       loc_descr_plus_const (&head, offset);
    2848              :     }
    2849              :   else
    2850        17793 :     head = new_reg_loc_descr (dwarf_fp, offset);
    2851        17793 :   return head;
    2852              : }
    2853              : 
    2854              : /* And now, the support for symbolic debugging information.  */
    2855              : 
    2856              : /* .debug_str support.  */
    2857              : 
    2858              : static void dwarf2out_init (const char *);
    2859              : static void dwarf2out_finish (const char *);
    2860              : static void dwarf2out_early_finish (const char *);
    2861              : static void dwarf2out_assembly_start (void);
    2862              : static void dwarf2out_define (unsigned int, const char *);
    2863              : static void dwarf2out_undef (unsigned int, const char *);
    2864              : static void dwarf2out_start_source_file (unsigned, const char *);
    2865              : static void dwarf2out_end_source_file (unsigned);
    2866              : static void dwarf2out_function_decl (tree);
    2867              : static void dwarf2out_begin_block (unsigned, unsigned, tree);
    2868              : static void dwarf2out_end_block (unsigned, unsigned);
    2869              : static bool dwarf2out_ignore_block (const_tree);
    2870              : static void dwarf2out_set_ignored_loc (unsigned, unsigned, const char *);
    2871              : static void dwarf2out_early_global_decl (tree);
    2872              : static void dwarf2out_late_global_decl (tree);
    2873              : static void dwarf2out_type_decl (tree, int);
    2874              : static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool, bool);
    2875              : static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
    2876              :                                                  dw_die_ref);
    2877              : static void dwarf2out_abstract_function (tree);
    2878              : static void dwarf2out_var_location (rtx_insn *);
    2879              : static void dwarf2out_inline_entry (tree);
    2880              : static void dwarf2out_size_function (tree);
    2881              : static void dwarf2out_begin_function (tree);
    2882              : static void dwarf2out_end_function (unsigned int);
    2883              : static void dwarf2out_register_main_translation_unit (tree unit);
    2884              : static void dwarf2out_set_name (tree, tree);
    2885              : static void dwarf2out_register_external_die (tree decl, const char *sym,
    2886              :                                              unsigned HOST_WIDE_INT off);
    2887              : static bool dwarf2out_die_ref_for_decl (tree decl, const char **sym,
    2888              :                                         unsigned HOST_WIDE_INT *off);
    2889              : 
    2890              : /* The debug hooks structure.  */
    2891              : 
    2892              : const struct gcc_debug_hooks dwarf2_debug_hooks =
    2893              : {
    2894              :   dwarf2out_init,
    2895              :   dwarf2out_finish,
    2896              :   dwarf2out_early_finish,
    2897              :   dwarf2out_assembly_start,
    2898              :   dwarf2out_define,
    2899              :   dwarf2out_undef,
    2900              :   dwarf2out_start_source_file,
    2901              :   dwarf2out_end_source_file,
    2902              :   dwarf2out_begin_block,
    2903              :   dwarf2out_end_block,
    2904              :   dwarf2out_ignore_block,
    2905              :   dwarf2out_source_line,
    2906              :   dwarf2out_set_ignored_loc,
    2907              :   dwarf2out_begin_prologue,
    2908              : #if VMS_DEBUGGING_INFO
    2909              :   dwarf2out_vms_end_prologue,
    2910              :   dwarf2out_vms_begin_epilogue,
    2911              : #else
    2912              :   debug_nothing_int_charstar,
    2913              :   debug_nothing_int_charstar,
    2914              : #endif
    2915              :   dwarf2out_end_epilogue,
    2916              :   dwarf2out_begin_function,
    2917              :   dwarf2out_end_function,       /* end_function */
    2918              :   dwarf2out_register_main_translation_unit,
    2919              :   dwarf2out_function_decl,      /* function_decl */
    2920              :   dwarf2out_early_global_decl,
    2921              :   dwarf2out_late_global_decl,
    2922              :   dwarf2out_type_decl,          /* type_decl */
    2923              :   dwarf2out_imported_module_or_decl,
    2924              :   dwarf2out_die_ref_for_decl,
    2925              :   dwarf2out_register_external_die,
    2926              :   debug_nothing_tree,           /* deferred_inline_function */
    2927              :   /* The DWARF 2 backend tries to reduce debugging bloat by not
    2928              :      emitting the abstract description of inline functions until
    2929              :      something tries to reference them.  */
    2930              :   dwarf2out_abstract_function,  /* outlining_inline_function */
    2931              :   debug_nothing_rtx_code_label, /* label */
    2932              :   debug_nothing_int,            /* handle_pch */
    2933              :   dwarf2out_var_location,
    2934              :   dwarf2out_inline_entry,       /* inline_entry */
    2935              :   dwarf2out_size_function,      /* size_function */
    2936              :   dwarf2out_switch_text_section,
    2937              :   dwarf2out_set_name,
    2938              :   1,                            /* start_end_main_source_file */
    2939              :   TYPE_SYMTAB_IS_DIE            /* tree_type_symtab_field */
    2940              : };
    2941              : 
    2942              : const struct gcc_debug_hooks dwarf2_lineno_debug_hooks =
    2943              : {
    2944              :   dwarf2out_init,
    2945              :   debug_nothing_charstar,
    2946              :   debug_nothing_charstar,
    2947              :   dwarf2out_assembly_start,
    2948              :   debug_nothing_int_charstar,
    2949              :   debug_nothing_int_charstar,
    2950              :   debug_nothing_int_charstar,
    2951              :   debug_nothing_int,
    2952              :   debug_nothing_int_int_tree,            /* begin_block */
    2953              :   debug_nothing_int_int,                 /* end_block */
    2954              :   debug_true_const_tree,                 /* ignore_block */
    2955              :   dwarf2out_source_line,                 /* source_line */
    2956              :   debug_nothing_int_int_charstar,        /* set_ignored_loc */
    2957              :   debug_nothing_int_int_charstar,        /* begin_prologue */
    2958              :   debug_nothing_int_charstar,            /* end_prologue */
    2959              :   debug_nothing_int_charstar,            /* begin_epilogue */
    2960              :   debug_nothing_int_charstar,            /* end_epilogue */
    2961              :   debug_nothing_tree,                    /* begin_function */
    2962              :   debug_nothing_int,                     /* end_function */
    2963              :   debug_nothing_tree,                    /* register_main_translation_unit */
    2964              :   debug_nothing_tree,                    /* function_decl */
    2965              :   debug_nothing_tree,                    /* early_global_decl */
    2966              :   debug_nothing_tree,                    /* late_global_decl */
    2967              :   debug_nothing_tree_int,                /* type_decl */
    2968              :   debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
    2969              :   debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */
    2970              :   debug_nothing_tree_charstar_uhwi,      /* register_external_die */
    2971              :   debug_nothing_tree,                    /* deferred_inline_function */
    2972              :   debug_nothing_tree,                    /* outlining_inline_function */
    2973              :   debug_nothing_rtx_code_label,          /* label */
    2974              :   debug_nothing_int,                     /* handle_pch */
    2975              :   debug_nothing_rtx_insn,                /* var_location */
    2976              :   debug_nothing_tree,                    /* inline_entry */
    2977              :   debug_nothing_tree,                    /* size_function */
    2978              :   debug_nothing_void,                    /* switch_text_section */
    2979              :   debug_nothing_tree_tree,               /* set_name */
    2980              :   0,                                     /* start_end_main_source_file */
    2981              :   TYPE_SYMTAB_IS_ADDRESS                 /* tree_type_symtab_field */
    2982              : };
    2983              : 
    2984              : /* NOTE: In the comments in this file, many references are made to
    2985              :    "Debugging Information Entries".  This term is abbreviated as `DIE'
    2986              :    throughout the remainder of this file.  */
    2987              : 
    2988              : /* An internal representation of the DWARF output is built, and then
    2989              :    walked to generate the DWARF debugging info.  The walk of the internal
    2990              :    representation is done after the entire program has been compiled.
    2991              :    The types below are used to describe the internal representation.  */
    2992              : 
    2993              : /* Whether to put type DIEs into their own section .debug_types instead
    2994              :    of making them part of the .debug_info section.  Only supported for
    2995              :    Dwarf V4 or higher and the user didn't disable them through
    2996              :    -fno-debug-types-section.  It is more efficient to put them in a
    2997              :    separate comdat sections since the linker will then be able to
    2998              :    remove duplicates.  But not all tools support .debug_types sections
    2999              :    yet.  For Dwarf V5 or higher .debug_types doesn't exist any more,
    3000              :    it is DW_UT_type unit type in .debug_info section.  For late LTO
    3001              :    debug there should be almost no types emitted so avoid enabling
    3002              :    -fdebug-types-section there.  */
    3003              : 
    3004              : #define use_debug_types (dwarf_version >= 4 \
    3005              :                          && flag_debug_types_section \
    3006              :                          && !in_lto_p)
    3007              : 
    3008              : /* Various DIE's use offsets relative to the beginning of the
    3009              :    .debug_info section to refer to each other.  */
    3010              : 
    3011              : typedef long int dw_offset;
    3012              : 
    3013              : struct comdat_type_node;
    3014              : 
    3015              : /* The entries in the line_info table more-or-less mirror the opcodes
    3016              :    that are used in the real dwarf line table.  Arrays of these entries
    3017              :    are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
    3018              :    supported.  */
    3019              : 
    3020              : enum dw_line_info_opcode {
    3021              :   /* Emit DW_LNE_set_address; the operand is the label index.  */
    3022              :   LI_set_address,
    3023              : 
    3024              :   /* Emit a row to the matrix with the given line.  This may be done
    3025              :      via any combination of DW_LNS_copy, DW_LNS_advance_line, and
    3026              :      special opcodes.  */
    3027              :   LI_set_line,
    3028              : 
    3029              :   /* Emit a DW_LNS_set_file.  */
    3030              :   LI_set_file,
    3031              : 
    3032              :   /* Emit a DW_LNS_set_column.  */
    3033              :   LI_set_column,
    3034              : 
    3035              :   /* Emit a DW_LNS_negate_stmt; the operand is ignored.  */
    3036              :   LI_negate_stmt,
    3037              : 
    3038              :   /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored.  */
    3039              :   LI_set_prologue_end,
    3040              :   LI_set_epilogue_begin,
    3041              : 
    3042              :   /* Emit a DW_LNE_set_discriminator.  */
    3043              :   LI_set_discriminator,
    3044              : 
    3045              :   /* Output a Fixed Advance PC; the target PC is the label index; the
    3046              :      base PC is the previous LI_adv_address or LI_set_address entry.
    3047              :      We only use this when emitting debug views without assembler
    3048              :      support, at explicit user request.  Ideally, we should only use
    3049              :      it when the offset might be zero but we can't tell: it's the only
    3050              :      way to maybe change the PC without resetting the view number.  */
    3051              :   LI_adv_address
    3052              : };
    3053              : 
    3054              : typedef struct GTY(()) dw_line_info_struct {
    3055              :   enum dw_line_info_opcode opcode;
    3056              :   unsigned int val;
    3057              : } dw_line_info_entry;
    3058              : 
    3059              : 
    3060              : struct GTY(()) dw_line_info_table {
    3061              :   /* The label that marks the end of this section.  */
    3062              :   const char *end_label;
    3063              : 
    3064              :   /* The values for the last row of the matrix, as collected in the table.
    3065              :      These are used to minimize the changes to the next row.  */
    3066              :   unsigned int file_num;
    3067              :   unsigned int line_num;
    3068              :   unsigned int column_num;
    3069              :   int discrim_num;
    3070              :   bool is_stmt;
    3071              :   bool in_use;
    3072              : 
    3073              :   /* This denotes the NEXT view number.
    3074              : 
    3075              :      If it is 0, it is known that the NEXT view will be the first view
    3076              :      at the given PC.
    3077              : 
    3078              :      If it is -1, we're forcing the view number to be reset, e.g. at a
    3079              :      function entry.
    3080              : 
    3081              :      The meaning of other nonzero values depends on whether we're
    3082              :      computing views internally or leaving it for the assembler to do
    3083              :      so.  If we're emitting them internally, view denotes the view
    3084              :      number since the last known advance of PC.  If we're leaving it
    3085              :      for the assembler, it denotes the LVU label number that we're
    3086              :      going to ask the assembler to assign.  */
    3087              :   var_loc_view view;
    3088              : 
    3089              :   /* This counts the number of symbolic views emitted in this table
    3090              :      since the latest view reset.  Its max value, over all tables,
    3091              :      sets symview_upper_bound.  */
    3092              :   var_loc_view symviews_since_reset;
    3093              : 
    3094              : #define FORCE_RESET_NEXT_VIEW(x) ((x) = (var_loc_view)-1)
    3095              : #define RESET_NEXT_VIEW(x) ((x) = (var_loc_view)0)
    3096              : #define FORCE_RESETTING_VIEW_P(x) ((x) == (var_loc_view)-1)
    3097              : #define RESETTING_VIEW_P(x) ((x) == (var_loc_view)0 || FORCE_RESETTING_VIEW_P (x))
    3098              : 
    3099              :   vec<dw_line_info_entry, va_gc> *entries;
    3100              : };
    3101              : 
    3102              : /* This is an upper bound for view numbers that the assembler may
    3103              :    assign to symbolic views output in this translation.  It is used to
    3104              :    decide how big a field to use to represent view numbers in
    3105              :    symview-classed attributes.  */
    3106              : 
    3107              : static var_loc_view symview_upper_bound;
    3108              : 
    3109              : /* If we're keep track of location views and their reset points, and
    3110              :    INSN is a reset point (i.e., it necessarily advances the PC), mark
    3111              :    the next view in TABLE as reset.  */
    3112              : 
    3113              : static void
    3114     43098381 : maybe_reset_location_view (rtx_insn *insn, dw_line_info_table *table)
    3115              : {
    3116     43098381 :   if (!debug_internal_reset_location_views)
    3117              :     return;
    3118              : 
    3119              :   /* Maybe turn (part of?) this test into a default target hook.  */
    3120            0 :   int reset = 0;
    3121              : 
    3122            0 :   if (targetm.reset_location_view)
    3123            0 :     reset = targetm.reset_location_view (insn);
    3124              : 
    3125            0 :   if (reset)
    3126              :     ;
    3127            0 :   else if (JUMP_TABLE_DATA_P (insn))
    3128              :     reset = 1;
    3129            0 :   else if (GET_CODE (insn) == USE
    3130            0 :            || GET_CODE (insn) == CLOBBER
    3131            0 :            || GET_CODE (insn) == ASM_INPUT
    3132            0 :            || asm_noperands (insn) >= 0)
    3133              :     ;
    3134            0 :   else if (get_attr_min_length (insn) > 0)
    3135              :     reset = 1;
    3136              : 
    3137            0 :   if (reset > 0 && !RESETTING_VIEW_P (table->view))
    3138            0 :     RESET_NEXT_VIEW (table->view);
    3139              : }
    3140              : 
    3141              : /* The Debugging Information Entry (DIE) structure.  DIEs form a tree.
    3142              :    The children of each node form a circular list linked by
    3143              :    die_sib.  die_child points to the node *before* the "first" child node.  */
    3144              : 
    3145              : typedef struct GTY((chain_circular ("%h.die_sib"), for_user)) die_struct {
    3146              :   union die_symbol_or_type_node
    3147              :     {
    3148              :       const char * GTY ((tag ("0"))) die_symbol;
    3149              :       comdat_type_node *GTY ((tag ("1"))) die_type_node;
    3150              :     }
    3151              :   GTY ((desc ("%0.comdat_type_p"))) die_id;
    3152              :   vec<dw_attr_node, va_gc> *die_attr;
    3153              :   dw_die_ref die_parent;
    3154              :   dw_die_ref die_child;
    3155              :   dw_die_ref die_sib;
    3156              :   dw_die_ref die_definition; /* ref from a specification to its definition */
    3157              :   dw_offset die_offset;
    3158              :   unsigned long die_abbrev;
    3159              :   int die_mark;
    3160              :   unsigned int decl_id;
    3161              :   enum dwarf_tag die_tag;
    3162              :   /* Die is used and must not be pruned as unused.  */
    3163              :   bool die_perennial_p : 1;
    3164              :   bool comdat_type_p : 1; /* DIE has a type signature */
    3165              :   /* For an external ref to die_symbol if die_offset contains an extra
    3166              :      offset to that symbol.  */
    3167              :   bool with_offset : 1;
    3168              :   /* Whether this DIE was removed from the DIE tree, for example via
    3169              :      prune_unused_types.  We don't consider those present from the
    3170              :      DIE lookup routines.  */
    3171              :   bool removed : 1;
    3172              :   /* Lots of spare bits.  */
    3173              : }
    3174              : die_node;
    3175              : 
    3176              : /* Set to TRUE while dwarf2out_early_global_decl is running.  */
    3177              : static bool early_dwarf;
    3178              : static bool early_dwarf_finished;
    3179              : class set_early_dwarf {
    3180              : public:
    3181              :   bool saved;
    3182    102839612 :   set_early_dwarf () : saved(early_dwarf)
    3183              :     {
    3184    102839612 :       gcc_assert (! early_dwarf_finished);
    3185    102839612 :       early_dwarf = true;
    3186    102839612 :     }
    3187    102839612 :   ~set_early_dwarf () { early_dwarf = saved; }
    3188              : };
    3189              : 
    3190              : /* Evaluate 'expr' while 'c' is set to each child of DIE in order.  */
    3191              : #define FOR_EACH_CHILD(die, c, expr) do {       \
    3192              :   c = die->die_child;                                \
    3193              :   if (c) do {                                   \
    3194              :     c = c->die_sib;                          \
    3195              :     expr;                                       \
    3196              :   } while (c != die->die_child);             \
    3197              : } while (0)
    3198              : 
    3199              : /* The pubname structure */
    3200              : 
    3201              : typedef struct GTY(()) pubname_struct {
    3202              :   dw_die_ref die;
    3203              :   const char *name;
    3204              : }
    3205              : pubname_entry;
    3206              : 
    3207              : 
    3208              : struct GTY(()) dw_ranges {
    3209              :   const char *label;
    3210              :   /* If this is positive, it's a block number, otherwise it's a
    3211              :      bitwise-negated index into dw_ranges_by_label.  */
    3212              :   int num;
    3213              :   /* If idx is equal to DW_RANGES_IDX_SKELETON, it should be emitted
    3214              :      into .debug_rnglists section rather than .debug_rnglists.dwo
    3215              :      for -gsplit-dwarf and DWARF >= 5.  */
    3216              : #define DW_RANGES_IDX_SKELETON ((1U << 31) - 1)
    3217              :   /* Index for the range list for DW_FORM_rnglistx.  */
    3218              :   unsigned int idx : 31;
    3219              :   /* True if this range might be possibly in a different section
    3220              :      from previous entry.  */
    3221              :   unsigned int maybe_new_sec : 1;
    3222              :   addr_table_entry *begin_entry;
    3223              :   addr_table_entry *end_entry;
    3224              : };
    3225              : 
    3226              : /* A structure to hold a macinfo entry.  */
    3227              : 
    3228              : typedef struct GTY(()) macinfo_struct {
    3229              :   unsigned char code;
    3230              :   unsigned HOST_WIDE_INT lineno;
    3231              :   const char *info;
    3232              : }
    3233              : macinfo_entry;
    3234              : 
    3235              : 
    3236              : struct GTY(()) dw_ranges_by_label {
    3237              :   const char *begin;
    3238              :   const char *end;
    3239              : };
    3240              : 
    3241              : /* The comdat type node structure.  */
    3242              : struct GTY(()) comdat_type_node
    3243              : {
    3244              :   dw_die_ref root_die;
    3245              :   dw_die_ref type_die;
    3246              :   dw_die_ref skeleton_die;
    3247              :   char signature[DWARF_TYPE_SIGNATURE_SIZE];
    3248              :   comdat_type_node *next;
    3249              : };
    3250              : 
    3251              : /* A list of DIEs for which we can't determine ancestry (parent_die
    3252              :    field) just yet.  Later in dwarf2out_finish we will fill in the
    3253              :    missing bits.  */
    3254              : typedef struct GTY(()) limbo_die_struct {
    3255              :   dw_die_ref die;
    3256              :   /* The tree for which this DIE was created.  We use this to
    3257              :      determine ancestry later.  */
    3258              :   tree created_for;
    3259              :   struct limbo_die_struct *next;
    3260              : }
    3261              : limbo_die_node;
    3262              : 
    3263              : typedef struct skeleton_chain_struct
    3264              : {
    3265              :   dw_die_ref old_die;
    3266              :   dw_die_ref new_die;
    3267              :   struct skeleton_chain_struct *parent;
    3268              : }
    3269              : skeleton_chain_node;
    3270              : 
    3271              : /* Define a macro which returns nonzero for a TYPE_DECL which was
    3272              :    implicitly generated for a type.
    3273              : 
    3274              :    Note that, unlike the C front-end (which generates a NULL named
    3275              :    TYPE_DECL node for each complete tagged type, each array type,
    3276              :    and each function type node created) the C++ front-end generates
    3277              :    a _named_ TYPE_DECL node for each tagged type node created.
    3278              :    These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
    3279              :    generate a DW_TAG_typedef DIE for them.  Likewise with the Ada
    3280              :    front-end, but for each type, tagged or not.  */
    3281              : 
    3282              : #define TYPE_DECL_IS_STUB(decl)                         \
    3283              :   (DECL_NAME (decl) == NULL_TREE                        \
    3284              :    || (DECL_ARTIFICIAL (decl)                           \
    3285              :        && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl)))  \
    3286              :            /* This is necessary for stub decls that     \
    3287              :               appear in nested inline functions.  */    \
    3288              :            || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
    3289              :                && (decl_ultimate_origin (decl)          \
    3290              :                    == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
    3291              : 
    3292              : /* Information concerning the compilation unit's programming
    3293              :    language, and compiler version.  */
    3294              : 
    3295              : /* Fixed size portion of the DWARF compilation unit header.  */
    3296              : #define DWARF_COMPILE_UNIT_HEADER_SIZE \
    3297              :   (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size                        \
    3298              :    + (dwarf_version >= 5 ? 4 : 3))
    3299              : 
    3300              : /* Fixed size portion of the DWARF comdat type unit header.  */
    3301              : #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
    3302              :   (DWARF_COMPILE_UNIT_HEADER_SIZE                                       \
    3303              :    + DWARF_TYPE_SIGNATURE_SIZE + dwarf_offset_size)
    3304              : 
    3305              : /* Fixed size portion of the DWARF skeleton compilation unit header.  */
    3306              : #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
    3307              :   (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
    3308              : 
    3309              : /* Fixed size portion of public names info.  */
    3310              : #define DWARF_PUBNAMES_HEADER_SIZE (2 * dwarf_offset_size + 2)
    3311              : 
    3312              : /* Fixed size portion of the address range info.  */
    3313              : #define DWARF_ARANGES_HEADER_SIZE                                       \
    3314              :   (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4,      \
    3315              :                 DWARF2_ADDR_SIZE * 2)                                   \
    3316              :    - DWARF_INITIAL_LENGTH_SIZE)
    3317              : 
    3318              : /* Size of padding portion in the address range info.  It must be
    3319              :    aligned to twice the pointer size.  */
    3320              : #define DWARF_ARANGES_PAD_SIZE \
    3321              :   (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
    3322              :                 DWARF2_ADDR_SIZE * 2)                              \
    3323              :    - (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4))
    3324              : 
    3325              : /* Use assembler line directives if available.  */
    3326              : #ifndef DWARF2_ASM_LINE_DEBUG_INFO
    3327              : #ifdef HAVE_AS_DWARF2_DEBUG_LINE
    3328              : #define DWARF2_ASM_LINE_DEBUG_INFO 1
    3329              : #else
    3330              : #define DWARF2_ASM_LINE_DEBUG_INFO 0
    3331              : #endif
    3332              : #endif
    3333              : 
    3334              : /* Use assembler views in line directives if available.  */
    3335              : #ifndef DWARF2_ASM_VIEW_DEBUG_INFO
    3336              : #ifdef HAVE_AS_DWARF2_DEBUG_VIEW
    3337              : #define DWARF2_ASM_VIEW_DEBUG_INFO 1
    3338              : #else
    3339              : #define DWARF2_ASM_VIEW_DEBUG_INFO 0
    3340              : #endif
    3341              : #endif
    3342              : 
    3343              : /* Return true if GCC configure detected assembler support for .loc.  */
    3344              : 
    3345              : bool
    3346       294503 : dwarf2out_default_as_loc_support (void)
    3347              : {
    3348       294503 :   return DWARF2_ASM_LINE_DEBUG_INFO;
    3349              : #if (GCC_VERSION >= 3000)
    3350              : # undef DWARF2_ASM_LINE_DEBUG_INFO
    3351              : # pragma GCC poison DWARF2_ASM_LINE_DEBUG_INFO
    3352              : #endif
    3353              : }
    3354              : 
    3355              : /* Return true if GCC configure detected assembler support for views
    3356              :    in .loc directives.  */
    3357              : 
    3358              : bool
    3359       294509 : dwarf2out_default_as_locview_support (void)
    3360              : {
    3361       294509 :   return DWARF2_ASM_VIEW_DEBUG_INFO;
    3362              : #if (GCC_VERSION >= 3000)
    3363              : # undef DWARF2_ASM_VIEW_DEBUG_INFO
    3364              : # pragma GCC poison DWARF2_ASM_VIEW_DEBUG_INFO
    3365              : #endif
    3366              : }
    3367              : 
    3368              : /* A bit is set in ZERO_VIEW_P if we are using the assembler-supported
    3369              :    view computation, and it refers to a view identifier for which we
    3370              :    will not emit a label because it is known to map to a view number
    3371              :    zero.  We won't allocate the bitmap if we're not using assembler
    3372              :    support for location views, but we have to make the variable
    3373              :    visible for GGC and for code that will be optimized out for lack of
    3374              :    support but that's still parsed and compiled.  We could abstract it
    3375              :    out with macros, but it's not worth it.  */
    3376              : static GTY(()) bitmap zero_view_p;
    3377              : 
    3378              : /* Evaluate to TRUE iff N is known to identify the first location view
    3379              :    at its PC.  When not using assembler location view computation,
    3380              :    that must be view number zero.  Otherwise, ZERO_VIEW_P is allocated
    3381              :    and views label numbers recorded in it are the ones known to be
    3382              :    zero.  */
    3383              : #define ZERO_VIEW_P(N) ((N) == (var_loc_view)0                          \
    3384              :                         || (N) == (var_loc_view)-1                      \
    3385              :                         || (zero_view_p                                 \
    3386              :                             && bitmap_bit_p (zero_view_p, (N))))
    3387              : 
    3388              : /* Return true iff we're to emit .loc directives for the assembler to
    3389              :    generate line number sections.
    3390              : 
    3391              :    When we're not emitting views, all we need from the assembler is
    3392              :    support for .loc directives.
    3393              : 
    3394              :    If we are emitting views, we can only use the assembler's .loc
    3395              :    support if it also supports views.
    3396              : 
    3397              :    When the compiler is emitting the line number programs and
    3398              :    computing view numbers itself, it resets view numbers at known PC
    3399              :    changes and counts from that, and then it emits view numbers as
    3400              :    literal constants in locviewlists.  There are cases in which the
    3401              :    compiler is not sure about PC changes, e.g. when extra alignment is
    3402              :    requested for a label.  In these cases, the compiler may not reset
    3403              :    the view counter, and the potential PC advance in the line number
    3404              :    program will use an opcode that does not reset the view counter
    3405              :    even if the PC actually changes, so that compiler and debug info
    3406              :    consumer can keep view numbers in sync.
    3407              : 
    3408              :    When the compiler defers view computation to the assembler, it
    3409              :    emits symbolic view numbers in locviewlists, with the exception of
    3410              :    views known to be zero (forced resets, or reset after
    3411              :    compiler-visible PC changes): instead of emitting symbols for
    3412              :    these, we emit literal zero and assert the assembler agrees with
    3413              :    the compiler's assessment.  We could use symbolic views everywhere,
    3414              :    instead of special-casing zero views, but then we'd be unable to
    3415              :    optimize out locviewlists that contain only zeros.  */
    3416              : 
    3417              : static bool
    3418     46293203 : output_asm_line_debug_info (void)
    3419              : {
    3420     46293203 :   return (dwarf2out_as_loc_support
    3421     46293203 :           && (dwarf2out_as_locview_support
    3422            0 :               || !debug_variable_location_views));
    3423              : }
    3424              : 
    3425              : static bool asm_outputs_debug_line_str (void);
    3426              : 
    3427              : /* Minimum line offset in a special line info. opcode.
    3428              :    This value was chosen to give a reasonable range of values.  */
    3429              : #define DWARF_LINE_BASE  -10
    3430              : 
    3431              : /* First special line opcode - leave room for the standard opcodes.  */
    3432              : #define DWARF_LINE_OPCODE_BASE  ((int)DW_LNS_set_isa + 1)
    3433              : 
    3434              : /* Range of line offsets in a special line info. opcode.  */
    3435              : #define DWARF_LINE_RANGE  (254-DWARF_LINE_OPCODE_BASE+1)
    3436              : 
    3437              : /* Flag that indicates the initial value of the is_stmt_start flag.
    3438              :    In the present implementation, we do not mark any lines as
    3439              :    the beginning of a source statement, because that information
    3440              :    is not made available by the GCC front-end.  */
    3441              : #define DWARF_LINE_DEFAULT_IS_STMT_START 1
    3442              : 
    3443              : /* Maximum number of operations per instruction bundle.  */
    3444              : #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
    3445              : #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
    3446              : #endif
    3447              : 
    3448              : /* This location is used by calc_die_sizes() to keep track
    3449              :    the offset of each DIE within the .debug_info section.  */
    3450              : static unsigned long next_die_offset;
    3451              : 
    3452              : /* Record the root of the DIE's built for the current compilation unit.  */
    3453              : static GTY(()) dw_die_ref single_comp_unit_die;
    3454              : 
    3455              : /* A list of type DIEs that have been separated into comdat sections.  */
    3456              : static GTY(()) comdat_type_node *comdat_type_list;
    3457              : 
    3458              : /* A list of CU DIEs that have been separated.  */
    3459              : static GTY(()) limbo_die_node *cu_die_list;
    3460              : 
    3461              : /* A list of DIEs with a NULL parent waiting to be relocated.  */
    3462              : static GTY(()) limbo_die_node *limbo_die_list;
    3463              : 
    3464              : /* A list of DIEs for which we may have to generate
    3465              :    DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set.  */
    3466              : static GTY(()) limbo_die_node *deferred_asm_name;
    3467              : 
    3468              : struct dwarf_file_hasher : ggc_ptr_hash<dwarf_file_data>
    3469              : {
    3470              :   typedef const char *compare_type;
    3471              : 
    3472              :   static hashval_t hash (dwarf_file_data *);
    3473              :   static bool equal (dwarf_file_data *, const char *);
    3474              : };
    3475              : 
    3476              : /* Filenames referenced by this compilation unit.  */
    3477              : static GTY(()) hash_table<dwarf_file_hasher> *file_table;
    3478              : 
    3479              : struct decl_die_hasher : ggc_ptr_hash<die_node>
    3480              : {
    3481              :   typedef tree compare_type;
    3482              : 
    3483              :   static hashval_t hash (die_node *);
    3484              :   static bool equal (die_node *, tree);
    3485              : };
    3486              : /* A hash table of references to DIE's that describe declarations.
    3487              :    The key is a DECL_UID() which is a unique number identifying each decl.  */
    3488              : static GTY (()) hash_table<decl_die_hasher> *decl_die_table;
    3489              : 
    3490              : struct GTY ((for_user)) variable_value_struct {
    3491              :   unsigned int decl_id;
    3492              :   vec<dw_die_ref, va_gc> *dies;
    3493              : };
    3494              : 
    3495              : struct variable_value_hasher : ggc_ptr_hash<variable_value_struct>
    3496              : {
    3497              :   typedef tree compare_type;
    3498              : 
    3499              :   static hashval_t hash (variable_value_struct *);
    3500              :   static bool equal (variable_value_struct *, tree);
    3501              : };
    3502              : /* A hash table of DIEs that contain DW_OP_GNU_variable_value with
    3503              :    dw_val_class_decl_ref class, indexed by FUNCTION_DECLs which is
    3504              :    DECL_CONTEXT of the referenced VAR_DECLs.  */
    3505              : static GTY (()) hash_table<variable_value_hasher> *variable_value_hash;
    3506              : 
    3507              : struct block_die_hasher : ggc_ptr_hash<die_struct>
    3508              : {
    3509              :   static hashval_t hash (die_struct *);
    3510              :   static bool equal (die_struct *, die_struct *);
    3511              : };
    3512              : 
    3513              : /* A hash table of references to DIE's that describe COMMON blocks.
    3514              :    The key is DECL_UID() ^ die_parent.  */
    3515              : static GTY (()) hash_table<block_die_hasher> *common_block_die_table;
    3516              : 
    3517              : typedef struct GTY(()) die_arg_entry_struct {
    3518              :     dw_die_ref die;
    3519              :     tree arg;
    3520              : } die_arg_entry;
    3521              : 
    3522              : 
    3523              : /* Node of the variable location list.  */
    3524              : struct GTY ((chain_next ("%h.next"))) var_loc_node {
    3525              :   /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
    3526              :      EXPR_LIST chain.  For small bitsizes, bitsize is encoded
    3527              :      in mode of the EXPR_LIST node and first EXPR_LIST operand
    3528              :      is either NOTE_INSN_VAR_LOCATION for a piece with a known
    3529              :      location or NULL for padding.  For larger bitsizes,
    3530              :      mode is 0 and first operand is a CONCAT with bitsize
    3531              :      as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
    3532              :      NULL as second operand.  */
    3533              :   rtx GTY (()) loc;
    3534              :   const char * GTY (()) label;
    3535              :   struct var_loc_node * GTY (()) next;
    3536              :   var_loc_view view;
    3537              : };
    3538              : 
    3539              : /* Variable location list.  */
    3540              : struct GTY ((for_user)) var_loc_list_def {
    3541              :   struct var_loc_node * GTY (()) first;
    3542              : 
    3543              :   /* Pointer to the last but one or last element of the
    3544              :      chained list.  If the list is empty, both first and
    3545              :      last are NULL, if the list contains just one node
    3546              :      or the last node certainly is not redundant, it points
    3547              :      to the last node, otherwise points to the last but one.
    3548              :      Do not mark it for GC because it is marked through the chain.  */
    3549              :   struct var_loc_node * GTY ((skip ("%h"))) last;
    3550              : 
    3551              :   /* Pointer to the last element before section switch,
    3552              :      if NULL, either sections weren't switched or first
    3553              :      is after section switch.  */
    3554              :   struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
    3555              : 
    3556              :   /* DECL_UID of the variable decl.  */
    3557              :   unsigned int decl_id;
    3558              : };
    3559              : typedef struct var_loc_list_def var_loc_list;
    3560              : 
    3561              : /* Call argument location list.  */
    3562              : struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
    3563              :   rtx_insn * GTY (()) call_insn;
    3564              :   const char * GTY (()) label;
    3565              :   tree GTY (()) block;
    3566              :   bool tail_call_p;
    3567              :   rtx GTY (()) symbol_ref;
    3568              :   struct call_arg_loc_node * GTY (()) next;
    3569              : };
    3570              : 
    3571              : 
    3572              : struct decl_loc_hasher : ggc_ptr_hash<var_loc_list>
    3573              : {
    3574              :   typedef const_tree compare_type;
    3575              : 
    3576              :   static hashval_t hash (var_loc_list *);
    3577              :   static bool equal (var_loc_list *, const_tree);
    3578              : };
    3579              : 
    3580              : /* Table of decl location linked lists.  */
    3581              : static GTY (()) hash_table<decl_loc_hasher> *decl_loc_table;
    3582              : 
    3583              : /* Head and tail of call_arg_loc chain.  */
    3584              : static GTY (()) struct call_arg_loc_node *call_arg_locations;
    3585              : static struct call_arg_loc_node *call_arg_loc_last;
    3586              : 
    3587              : /* Number of call sites in the current function.  */
    3588              : static int call_site_count = -1;
    3589              : /* Number of tail call sites in the current function.  */
    3590              : static int tail_call_site_count = -1;
    3591              : 
    3592              : /* A cached location list.  */
    3593              : struct GTY ((for_user)) cached_dw_loc_list_def {
    3594              :   /* The DECL_UID of the decl that this entry describes.  */
    3595              :   unsigned int decl_id;
    3596              : 
    3597              :   /* The cached location list.  */
    3598              :   dw_loc_list_ref loc_list;
    3599              : };
    3600              : typedef struct cached_dw_loc_list_def cached_dw_loc_list;
    3601              : 
    3602              : struct dw_loc_list_hasher : ggc_ptr_hash<cached_dw_loc_list>
    3603              : {
    3604              : 
    3605              :   typedef const_tree compare_type;
    3606              : 
    3607              :   static hashval_t hash (cached_dw_loc_list *);
    3608              :   static bool equal (cached_dw_loc_list *, const_tree);
    3609              : };
    3610              : 
    3611              : /* Table of cached location lists.  */
    3612              : static GTY (()) hash_table<dw_loc_list_hasher> *cached_dw_loc_list_table;
    3613              : 
    3614              : /* A vector of references to DIE's that are uniquely identified by their tag,
    3615              :    presence/absence of children DIE's, and list of attribute/value pairs.  */
    3616              : static GTY(()) vec<dw_die_ref, va_gc> *abbrev_die_table;
    3617              : 
    3618              : /* A hash map to remember the stack usage for DWARF procedures.  The value
    3619              :    stored is the stack size difference between before the DWARF procedure
    3620              :    invocation and after it returned.  In other words, for a DWARF procedure
    3621              :    that consumes N stack slots and that pushes M ones, this stores M - N.  */
    3622              : static hash_map<dw_die_ref, int> *dwarf_proc_stack_usage_map;
    3623              : 
    3624              : /* A global counter for generating labels for line number data.  */
    3625              : static unsigned int line_info_label_num;
    3626              : 
    3627              : /* The current table to which we should emit line number information
    3628              :    for the current function.  This will be set up at the beginning of
    3629              :    assembly for the function.  */
    3630              : static GTY(()) dw_line_info_table *cur_line_info_table;
    3631              : 
    3632              : /* The two default tables of line number info.  */
    3633              : static GTY(()) dw_line_info_table *text_section_line_info;
    3634              : static GTY(()) dw_line_info_table *cold_text_section_line_info;
    3635              : 
    3636              : /* The set of all non-default tables of line number info.  */
    3637              : static GTY(()) vec<dw_line_info_table *, va_gc> *separate_line_info;
    3638              : 
    3639              : /* A flag to tell pubnames/types export if there is an info section to
    3640              :    refer to.  */
    3641              : static bool info_section_emitted;
    3642              : 
    3643              : /* A pointer to the base of a table that contains a list of publicly
    3644              :    accessible names.  */
    3645              : static GTY (()) vec<pubname_entry, va_gc> *pubname_table;
    3646              : 
    3647              : /* A pointer to the base of a table that contains a list of publicly
    3648              :    accessible types.  */
    3649              : static GTY (()) vec<pubname_entry, va_gc> *pubtype_table;
    3650              : 
    3651              : /* A pointer to the base of a table that contains a list of macro
    3652              :    defines/undefines (and file start/end markers).  */
    3653              : static GTY (()) vec<macinfo_entry, va_gc> *macinfo_table;
    3654              : 
    3655              : /* True if .debug_macinfo or .debug_macros section is going to be
    3656              :    emitted.  */
    3657              : #define have_macinfo \
    3658              :   ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
    3659              :    && debug_info_level >= DINFO_LEVEL_VERBOSE \
    3660              :    && !macinfo_table->is_empty ())
    3661              : 
    3662              : /* Vector of dies for which we should generate .debug_ranges info.  */
    3663              : static GTY (()) vec<dw_ranges, va_gc> *ranges_table;
    3664              : 
    3665              : /* Vector of pairs of labels referenced in ranges_table.  */
    3666              : static GTY (()) vec<dw_ranges_by_label, va_gc> *ranges_by_label;
    3667              : 
    3668              : /* Whether we have location lists that need outputting */
    3669              : static GTY(()) bool have_location_lists;
    3670              : 
    3671              : /* Unique label counter.  */
    3672              : static GTY(()) unsigned int loclabel_num;
    3673              : 
    3674              : /* Unique label counter for point-of-call tables.  */
    3675              : static GTY(()) unsigned int poc_label_num;
    3676              : 
    3677              : /* The last file entry emitted by maybe_emit_file().  */
    3678              : static GTY(()) struct dwarf_file_data * last_emitted_file;
    3679              : 
    3680              : /* Number of internal labels generated by gen_internal_sym().  */
    3681              : static GTY(()) int label_num;
    3682              : 
    3683              : static GTY(()) vec<die_arg_entry, va_gc> *tmpl_value_parm_die_table;
    3684              : 
    3685              : /* Instances of generic types for which we need to generate debug
    3686              :    info that describe their generic parameters and arguments. That
    3687              :    generation needs to happen once all types are properly laid out so
    3688              :    we do it at the end of compilation.  */
    3689              : static GTY(()) vec<tree, va_gc> *generic_type_instances;
    3690              : 
    3691              : /* Offset from the "steady-state frame pointer" to the frame base,
    3692              :    within the current function.  */
    3693              : static poly_int64 frame_pointer_fb_offset;
    3694              : static bool frame_pointer_fb_offset_valid;
    3695              : 
    3696              : static vec<dw_die_ref> base_types;
    3697              : 
    3698              : /* A cached btf_type_tag or btf_decl_tag user annotation.  */
    3699              : struct GTY ((for_user)) annotation_node
    3700              : {
    3701              :   const char *name;
    3702              :   const char *value;
    3703              :   hashval_t hash;
    3704              :   dw_die_ref die;
    3705              :   struct annotation_node *next;
    3706              : };
    3707              : 
    3708              : /* Hasher for btf_type_tag and btf_decl_tag annotation nodes.  */
    3709              : struct annotation_node_hasher : ggc_ptr_hash<annotation_node>
    3710              : {
    3711              :   typedef const struct annotation_node *compare_type;
    3712              : 
    3713              :   static hashval_t hash (struct annotation_node *);
    3714              :   static bool equal (const struct annotation_node *,
    3715              :                      const struct annotation_node *);
    3716              : };
    3717              : 
    3718              : /* A hash table of tag annotation nodes for btf_type_tag and btf_decl_tag C
    3719              :    attributes.  DIEs for these user annotations may be reused if they are
    3720              :    structurally equivalent; this hash table is used to ensure the DIEs are
    3721              :    reused wherever possible.  */
    3722              : static GTY (()) hash_table<annotation_node_hasher> *btf_tag_htab;
    3723              : 
    3724              : 
    3725              : /* Flags to represent a set of attribute classes for attributes that represent
    3726              :    a scalar value (bounds, pointers, ...).  */
    3727              : enum dw_scalar_form
    3728              : {
    3729              :   dw_scalar_form_constant = 0x01,
    3730              :   dw_scalar_form_exprloc = 0x02,
    3731              :   dw_scalar_form_reference = 0x04
    3732              : };
    3733              : 
    3734              : /* Forward declarations for functions defined in this file.  */
    3735              : 
    3736              : static bool is_pseudo_reg (const_rtx);
    3737              : static tree type_main_variant (tree);
    3738              : static bool is_tagged_type (const_tree);
    3739              : static const char *dwarf_tag_name (unsigned);
    3740              : static const char *dwarf_attr_name (unsigned);
    3741              : static const char *dwarf_form_name (unsigned);
    3742              : static tree decl_ultimate_origin (const_tree);
    3743              : static tree decl_class_context (tree);
    3744              : static void add_dwarf_attr (dw_die_ref, dw_attr_node *);
    3745              : static inline unsigned int AT_index (dw_attr_node *);
    3746              : static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
    3747              : static inline unsigned AT_flag (dw_attr_node *);
    3748              : static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
    3749              : static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
    3750              : static void add_AT_double (dw_die_ref, enum dwarf_attribute,
    3751              :                            HOST_WIDE_INT, unsigned HOST_WIDE_INT);
    3752              : static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
    3753              :                                unsigned int, unsigned char *);
    3754              : static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
    3755              : static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
    3756              : static inline const char *AT_string (dw_attr_node *);
    3757              : static enum dwarf_form AT_string_form (dw_attr_node *);
    3758              : static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
    3759              : static void add_AT_specification (dw_die_ref, dw_die_ref);
    3760              : static inline dw_die_ref AT_ref (dw_attr_node *);
    3761              : static inline int AT_ref_external (dw_attr_node *);
    3762              : static inline void set_AT_ref_external (dw_attr_node *, int);
    3763              : static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
    3764              : static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
    3765              :                              dw_loc_list_ref);
    3766              : static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
    3767              : static void add_AT_view_list (dw_die_ref, enum dwarf_attribute);
    3768              : static inline dw_loc_list_ref AT_loc_list (dw_attr_node *);
    3769              : static addr_table_entry *add_addr_table_entry (void *, enum ate_kind);
    3770              : static void remove_addr_table_entry (addr_table_entry *);
    3771              : static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx, bool);
    3772              : static inline rtx AT_addr (dw_attr_node *);
    3773              : static void add_AT_symview (dw_die_ref, enum dwarf_attribute, const char *);
    3774              : static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *,
    3775              :                            int = 0);
    3776              : static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
    3777              : static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
    3778              : static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
    3779              :                                unsigned long, bool);
    3780              : static inline const char *AT_lbl (dw_attr_node *);
    3781              : static const char *get_AT_low_pc (dw_die_ref);
    3782              : static bool is_c (void);
    3783              : static bool is_cxx (void);
    3784              : static bool is_cxx (const_tree);
    3785              : static bool is_fortran (void);
    3786              : static bool is_ada (void);
    3787              : static bool remove_AT (dw_die_ref, enum dwarf_attribute);
    3788              : static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
    3789              : static void add_child_die (dw_die_ref, dw_die_ref);
    3790              : static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
    3791              : static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
    3792              : static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
    3793              : static void equate_type_number_to_die (tree, dw_die_ref);
    3794              : static var_loc_list *lookup_decl_loc (const_tree);
    3795              : static void equate_decl_number_to_die (tree, dw_die_ref);
    3796              : static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *, var_loc_view);
    3797              : static void print_spaces (FILE *);
    3798              : static void print_die (dw_die_ref, FILE *);
    3799              : static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
    3800              : static void attr_checksum (dw_attr_node *, struct md5_ctx *, int *);
    3801              : static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
    3802              : static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
    3803              : static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
    3804              : static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
    3805              : static void attr_checksum_ordered (enum dwarf_tag, dw_attr_node *,
    3806              :                                    struct md5_ctx *, int *);
    3807              : struct checksum_attributes;
    3808              : static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
    3809              : static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
    3810              : static void checksum_die_context (dw_die_ref, struct md5_ctx *);
    3811              : static void generate_type_signature (dw_die_ref, comdat_type_node *);
    3812              : static bool same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
    3813              : static bool same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
    3814              : static bool same_attr_p (dw_attr_node *, dw_attr_node *, int *);
    3815              : static bool same_die_p (dw_die_ref, dw_die_ref, int *);
    3816              : static bool is_type_die (dw_die_ref);
    3817              : static inline bool is_template_instantiation (dw_die_ref);
    3818              : static bool is_declaration_die (dw_die_ref);
    3819              : static bool should_move_die_to_comdat (dw_die_ref);
    3820              : static dw_die_ref clone_as_declaration (dw_die_ref);
    3821              : static dw_die_ref clone_die (dw_die_ref);
    3822              : static dw_die_ref clone_tree (dw_die_ref);
    3823              : static dw_die_ref copy_declaration_context (dw_die_ref, dw_die_ref);
    3824              : static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
    3825              : static void generate_skeleton_bottom_up (skeleton_chain_node *);
    3826              : static dw_die_ref generate_skeleton (dw_die_ref);
    3827              : static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
    3828              :                                                          dw_die_ref,
    3829              :                                                          dw_die_ref);
    3830              : static void break_out_comdat_types (dw_die_ref);
    3831              : static void copy_decls_for_unworthy_types (dw_die_ref);
    3832              : 
    3833              : static void add_sibling_attributes (dw_die_ref);
    3834              : static void output_location_lists (dw_die_ref);
    3835              : static int constant_size (unsigned HOST_WIDE_INT);
    3836              : static unsigned long size_of_die (dw_die_ref);
    3837              : static void calc_die_sizes (dw_die_ref);
    3838              : static void calc_base_type_die_sizes (void);
    3839              : static void mark_dies (dw_die_ref);
    3840              : static void unmark_dies (dw_die_ref);
    3841              : static void unmark_all_dies (dw_die_ref);
    3842              : static unsigned long size_of_pubnames (vec<pubname_entry, va_gc> *);
    3843              : static unsigned long size_of_aranges (void);
    3844              : static enum dwarf_form value_format (dw_attr_node *);
    3845              : static void output_value_format (dw_attr_node *);
    3846              : static void output_abbrev_section (void);
    3847              : static void output_die_abbrevs (unsigned long, dw_die_ref);
    3848              : static void output_die (dw_die_ref);
    3849              : static void output_compilation_unit_header (enum dwarf_unit_type);
    3850              : static void output_comp_unit (dw_die_ref, int, const unsigned char *);
    3851              : static void output_comdat_type_unit (comdat_type_node *, bool);
    3852              : static const char *dwarf2_name (tree, int);
    3853              : static void add_pubname (tree, dw_die_ref);
    3854              : static void add_enumerator_pubname (const char *, dw_die_ref);
    3855              : static void add_pubname_string (const char *, dw_die_ref);
    3856              : static void add_pubtype (tree, dw_die_ref);
    3857              : static void output_pubnames (vec<pubname_entry, va_gc> *);
    3858              : static void output_aranges (void);
    3859              : static unsigned int add_ranges (const_tree, bool = false);
    3860              : static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
    3861              :                                   bool *, bool);
    3862              : static void output_ranges (void);
    3863              : static dw_line_info_table *new_line_info_table (void);
    3864              : static void output_line_info (bool);
    3865              : static void output_file_names (void);
    3866              : static bool is_base_type (tree);
    3867              : static dw_die_ref subrange_type_die (tree, tree, tree, tree, dw_die_ref);
    3868              : static int decl_quals (const_tree);
    3869              : static dw_die_ref modified_type_die (tree, int, tree, bool, dw_die_ref);
    3870              : static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
    3871              : static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
    3872              : static unsigned int debugger_reg_number (const_rtx);
    3873              : static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
    3874              : static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
    3875              : static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
    3876              :                                                 enum var_init_status);
    3877              : static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
    3878              :                                                      enum var_init_status);
    3879              : static dw_loc_descr_ref based_loc_descr (rtx, poly_int64,
    3880              :                                          enum var_init_status);
    3881              : static bool is_based_loc (const_rtx);
    3882              : static bool resolve_one_addr (rtx *);
    3883              : static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
    3884              :                                                enum var_init_status);
    3885              : static dw_loc_descr_ref loc_descriptor (rtx, machine_mode mode,
    3886              :                                         enum var_init_status);
    3887              : struct loc_descr_context;
    3888              : static void add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref);
    3889              : static void add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list);
    3890              : static dw_loc_list_ref loc_list_from_tree (tree, int,
    3891              :                                            struct loc_descr_context *);
    3892              : static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
    3893              :                                                   struct loc_descr_context *);
    3894              : static tree field_type (const_tree);
    3895              : static unsigned int simple_type_align_in_bits (const_tree);
    3896              : static unsigned int simple_decl_align_in_bits (const_tree);
    3897              : static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
    3898              : struct vlr_context;
    3899              : static dw_loc_descr_ref field_byte_offset (const_tree, struct vlr_context *,
    3900              :                                            HOST_WIDE_INT *);
    3901              : static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
    3902              :                                          dw_loc_list_ref);
    3903              : static void add_data_member_location_attribute (dw_die_ref, tree,
    3904              :                                                 struct vlr_context *);
    3905              : static bool add_const_value_attribute (dw_die_ref, machine_mode, rtx);
    3906              : static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
    3907              : static void insert_wide_int (const wide_int_ref &, unsigned char *, int);
    3908              : static unsigned insert_float (const_rtx, unsigned char *);
    3909              : static rtx rtl_for_decl_location (tree);
    3910              : static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
    3911              : static bool tree_add_const_value_attribute (dw_die_ref, tree);
    3912              : static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
    3913              : static void add_desc_attribute (dw_die_ref, tree);
    3914              : static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
    3915              : static void add_comp_dir_attribute (dw_die_ref);
    3916              : static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
    3917              :                              struct loc_descr_context *);
    3918              : static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
    3919              :                             struct loc_descr_context *);
    3920              : static void add_subscript_info (dw_die_ref, tree, bool);
    3921              : static void add_byte_size_attribute (dw_die_ref, tree);
    3922              : static void add_alignment_attribute (dw_die_ref, tree);
    3923              : static void add_bit_offset_attribute (dw_die_ref, tree);
    3924              : static void add_bit_size_attribute (dw_die_ref, tree);
    3925              : static void add_prototyped_attribute (dw_die_ref, tree);
    3926              : static void add_abstract_origin_attribute (dw_die_ref, tree);
    3927              : static void add_pure_or_virtual_attribute (dw_die_ref, tree);
    3928              : static void add_src_coords_attributes (dw_die_ref, tree);
    3929              : static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool = false);
    3930              : static void add_discr_value (dw_die_ref, dw_discr_value *);
    3931              : static void add_discr_list (dw_die_ref, dw_discr_list_ref);
    3932              : static inline dw_discr_list_ref AT_discr_list (dw_attr_node *);
    3933              : static dw_die_ref scope_die_for (tree, dw_die_ref);
    3934              : static inline bool local_scope_p (dw_die_ref);
    3935              : static inline bool class_scope_p (dw_die_ref);
    3936              : static inline bool class_or_namespace_scope_p (dw_die_ref);
    3937              : static void add_type_attribute (dw_die_ref, tree, int, bool, dw_die_ref);
    3938              : static void add_calling_convention_attribute (dw_die_ref, tree);
    3939              : static const char *type_tag (const_tree);
    3940              : static tree member_declared_type (const_tree);
    3941              : #if 0
    3942              : static const char *decl_start_label (tree);
    3943              : #endif
    3944              : static void gen_array_type_die (tree, dw_die_ref);
    3945              : static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
    3946              : #if 0
    3947              : static void gen_entry_point_die (tree, dw_die_ref);
    3948              : #endif
    3949              : static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref, bool);
    3950              : static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
    3951              : static dw_die_ref gen_formal_parameter_pack_die  (tree, tree, dw_die_ref, tree*);
    3952              : static void gen_unspecified_parameters_die (tree, dw_die_ref);
    3953              : static void gen_formal_types_die (tree, dw_die_ref);
    3954              : static void gen_subprogram_die (tree, dw_die_ref);
    3955              : static void gen_variable_die (tree, tree, dw_die_ref);
    3956              : static void gen_const_die (tree, dw_die_ref);
    3957              : static void gen_label_die (tree, dw_die_ref);
    3958              : static void gen_lexical_block_die (tree, dw_die_ref);
    3959              : static void gen_inlined_subroutine_die (tree, dw_die_ref);
    3960              : static void gen_field_die (tree, struct vlr_context *, dw_die_ref);
    3961              : static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
    3962              : static dw_die_ref gen_compile_unit_die (const char *);
    3963              : static void gen_inheritance_die (tree, tree, tree, dw_die_ref);
    3964              : static void gen_member_die (tree, dw_die_ref);
    3965              : static void gen_struct_or_union_type_die (tree, dw_die_ref,
    3966              :                                                 enum debug_info_usage);
    3967              : static void gen_subroutine_type_die (tree, dw_die_ref);
    3968              : static void gen_typedef_die (tree, dw_die_ref);
    3969              : static void gen_type_die (tree, dw_die_ref, bool = false);
    3970              : static void gen_block_die (tree, dw_die_ref);
    3971              : static void decls_for_scope (tree, dw_die_ref, bool = true);
    3972              : static bool is_naming_typedef_decl (const_tree);
    3973              : static inline dw_die_ref get_context_die (tree);
    3974              : static void gen_namespace_die (tree, dw_die_ref);
    3975              : static dw_die_ref gen_namelist_decl (tree, dw_die_ref, tree);
    3976              : static dw_die_ref gen_decl_die (tree, tree, struct vlr_context *, dw_die_ref);
    3977              : static dw_die_ref force_decl_die (tree);
    3978              : static dw_die_ref force_type_die (tree);
    3979              : static dw_die_ref setup_namespace_context (tree, dw_die_ref);
    3980              : static dw_die_ref declare_in_namespace (tree, dw_die_ref);
    3981              : static struct dwarf_file_data * lookup_filename (const char *);
    3982              : static void retry_incomplete_types (void);
    3983              : static void gen_type_die_for_member (tree, tree, dw_die_ref);
    3984              : static void gen_generic_params_dies (tree);
    3985              : static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage,
    3986              :                                  bool = false);
    3987              : static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage,
    3988              :                                      bool = false);
    3989              : static void splice_child_die (dw_die_ref, dw_die_ref);
    3990              : static int file_info_cmp (const void *, const void *);
    3991              : static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *, var_loc_view,
    3992              :                                      const char *, var_loc_view, const char *);
    3993              : static void output_loc_list (dw_loc_list_ref);
    3994              : static char *gen_internal_sym (const char *);
    3995              : static bool want_pubnames (void);
    3996              : 
    3997              : static void prune_unmark_dies (dw_die_ref);
    3998              : static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
    3999              : static void prune_unused_types_mark (dw_die_ref, int);
    4000              : static void prune_unused_types_walk (dw_die_ref);
    4001              : static void prune_unused_types_walk_attribs (dw_die_ref);
    4002              : static void prune_unused_types_prune (dw_die_ref);
    4003              : static void prune_unused_types (void);
    4004              : static int maybe_emit_file (struct dwarf_file_data *fd);
    4005              : static inline const char *AT_vms_delta1 (dw_attr_node *);
    4006              : static inline const char *AT_vms_delta2 (dw_attr_node *);
    4007              : #if VMS_DEBUGGING_INFO
    4008              : static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
    4009              :                                      const char *, const char *);
    4010              : #endif
    4011              : static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
    4012              : static void gen_remaining_tmpl_value_param_die_attribute (void);
    4013              : static bool generic_type_p (tree);
    4014              : static void schedule_generic_params_dies_gen (tree t);
    4015              : static void gen_scheduled_generic_parms_dies (void);
    4016              : static void resolve_variable_values (void);
    4017              : 
    4018              : static const char *comp_dir_string (void);
    4019              : 
    4020              : static void hash_loc_operands (dw_loc_descr_ref, inchash::hash &);
    4021              : 
    4022              : /* enum for tracking thread-local variables whose address is really an offset
    4023              :    relative to the TLS pointer, which will need link-time relocation, but will
    4024              :    not need relocation by the DWARF consumer.  */
    4025              : 
    4026              : enum dtprel_bool
    4027              : {
    4028              :   dtprel_false = 0,
    4029              :   dtprel_true = 1
    4030              : };
    4031              : 
    4032              : /* Return the operator to use for an address of a variable.  For dtprel_true, we
    4033              :    use DW_OP_const*.  For regular variables, which need both link-time
    4034              :    relocation and consumer-level relocation (e.g., to account for shared objects
    4035              :    loaded at a random address), we use DW_OP_addr*.  */
    4036              : 
    4037              : static inline enum dwarf_location_atom
    4038      1650605 : dw_addr_op (enum dtprel_bool dtprel)
    4039              : {
    4040      1650605 :   if (dtprel == dtprel_true)
    4041         5353 :     return (dwarf_split_debug_info ? dwarf_OP (DW_OP_constx)
    4042         5353 :             : (DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u));
    4043              :   else
    4044      1645252 :     return dwarf_split_debug_info ? dwarf_OP (DW_OP_addrx) : DW_OP_addr;
    4045              : }
    4046              : 
    4047              : /* Return a pointer to a newly allocated address location description.  If
    4048              :    dwarf_split_debug_info is true, then record the address with the appropriate
    4049              :    relocation.  */
    4050              : static inline dw_loc_descr_ref
    4051      1650605 : new_addr_loc_descr (rtx addr, enum dtprel_bool dtprel)
    4052              : {
    4053      1650605 :   dw_loc_descr_ref ref = new_loc_descr (dw_addr_op (dtprel), 0, 0);
    4054              : 
    4055      1650605 :   ref->dw_loc_oprnd1.val_class = dw_val_class_addr;
    4056      1650605 :   ref->dw_loc_oprnd1.v.val_addr = addr;
    4057      1650605 :   ref->dw_loc_dtprel = dtprel;
    4058      1650605 :   if (dwarf_split_debug_info)
    4059            3 :     ref->dw_loc_oprnd1.val_entry
    4060            6 :       = add_addr_table_entry (addr,
    4061              :                               dtprel ? ate_kind_rtx_dtprel : ate_kind_rtx);
    4062              :   else
    4063      1650602 :     ref->dw_loc_oprnd1.val_entry = NULL;
    4064              : 
    4065      1650605 :   return ref;
    4066              : }
    4067              : 
    4068              : /* Section names used to hold DWARF debugging information.  */
    4069              : 
    4070              : #ifndef DEBUG_INFO_SECTION
    4071              : #define DEBUG_INFO_SECTION      ".debug_info"
    4072              : #endif
    4073              : #ifndef DEBUG_DWO_INFO_SECTION
    4074              : #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
    4075              : #endif
    4076              : #ifndef DEBUG_LTO_INFO_SECTION
    4077              : #define DEBUG_LTO_INFO_SECTION  ".gnu.debuglto_.debug_info"
    4078              : #endif
    4079              : #ifndef DEBUG_LTO_DWO_INFO_SECTION
    4080              : #define DEBUG_LTO_DWO_INFO_SECTION ".gnu.debuglto_.debug_info.dwo"
    4081              : #endif
    4082              : #ifndef DEBUG_ABBREV_SECTION
    4083              : #define DEBUG_ABBREV_SECTION    ".debug_abbrev"
    4084              : #endif
    4085              : #ifndef DEBUG_LTO_ABBREV_SECTION
    4086              : #define DEBUG_LTO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev"
    4087              : #endif
    4088              : #ifndef DEBUG_DWO_ABBREV_SECTION
    4089              : #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
    4090              : #endif
    4091              : #ifndef DEBUG_LTO_DWO_ABBREV_SECTION
    4092              : #define DEBUG_LTO_DWO_ABBREV_SECTION ".gnu.debuglto_.debug_abbrev.dwo"
    4093              : #endif
    4094              : #ifndef DEBUG_ARANGES_SECTION
    4095              : #define DEBUG_ARANGES_SECTION   ".debug_aranges"
    4096              : #endif
    4097              : #ifndef DEBUG_ADDR_SECTION
    4098              : #define DEBUG_ADDR_SECTION     ".debug_addr"
    4099              : #endif
    4100              : #ifndef DEBUG_MACINFO_SECTION
    4101              : #define DEBUG_MACINFO_SECTION     ".debug_macinfo"
    4102              : #endif
    4103              : #ifndef DEBUG_LTO_MACINFO_SECTION
    4104              : #define DEBUG_LTO_MACINFO_SECTION      ".gnu.debuglto_.debug_macinfo"
    4105              : #endif
    4106              : #ifndef DEBUG_DWO_MACINFO_SECTION
    4107              : #define DEBUG_DWO_MACINFO_SECTION      ".debug_macinfo.dwo"
    4108              : #endif
    4109              : #ifndef DEBUG_LTO_DWO_MACINFO_SECTION
    4110              : #define DEBUG_LTO_DWO_MACINFO_SECTION  ".gnu.debuglto_.debug_macinfo.dwo"
    4111              : #endif
    4112              : #ifndef DEBUG_MACRO_SECTION
    4113              : #define DEBUG_MACRO_SECTION     ".debug_macro"
    4114              : #endif
    4115              : #ifndef DEBUG_LTO_MACRO_SECTION
    4116              : #define DEBUG_LTO_MACRO_SECTION ".gnu.debuglto_.debug_macro"
    4117              : #endif
    4118              : #ifndef DEBUG_DWO_MACRO_SECTION
    4119              : #define DEBUG_DWO_MACRO_SECTION        ".debug_macro.dwo"
    4120              : #endif
    4121              : #ifndef DEBUG_LTO_DWO_MACRO_SECTION
    4122              : #define DEBUG_LTO_DWO_MACRO_SECTION    ".gnu.debuglto_.debug_macro.dwo"
    4123              : #endif
    4124              : #ifndef DEBUG_LINE_SECTION
    4125              : #define DEBUG_LINE_SECTION      ".debug_line"
    4126              : #endif
    4127              : #ifndef DEBUG_LTO_LINE_SECTION
    4128              : #define DEBUG_LTO_LINE_SECTION ".gnu.debuglto_.debug_line"
    4129              : #endif
    4130              : #ifndef DEBUG_DWO_LINE_SECTION
    4131              : #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
    4132              : #endif
    4133              : #ifndef DEBUG_LTO_DWO_LINE_SECTION
    4134              : #define DEBUG_LTO_DWO_LINE_SECTION ".gnu.debuglto_.debug_line.dwo"
    4135              : #endif
    4136              : #ifndef DEBUG_LOC_SECTION
    4137              : #define DEBUG_LOC_SECTION       ".debug_loc"
    4138              : #endif
    4139              : #ifndef DEBUG_DWO_LOC_SECTION
    4140              : #define DEBUG_DWO_LOC_SECTION  ".debug_loc.dwo"
    4141              : #endif
    4142              : #ifndef DEBUG_LOCLISTS_SECTION
    4143              : #define DEBUG_LOCLISTS_SECTION  ".debug_loclists"
    4144              : #endif
    4145              : #ifndef DEBUG_DWO_LOCLISTS_SECTION
    4146              : #define DEBUG_DWO_LOCLISTS_SECTION  ".debug_loclists.dwo"
    4147              : #endif
    4148              : #ifndef DEBUG_PUBNAMES_SECTION
    4149              : #define DEBUG_PUBNAMES_SECTION  \
    4150              :   ((debug_generate_pub_sections == 2) \
    4151              :    ? ".debug_gnu_pubnames" : ".debug_pubnames")
    4152              : #endif
    4153              : #ifndef DEBUG_PUBTYPES_SECTION
    4154              : #define DEBUG_PUBTYPES_SECTION  \
    4155              :   ((debug_generate_pub_sections == 2) \
    4156              :    ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
    4157              : #endif
    4158              : #ifndef DEBUG_STR_OFFSETS_SECTION
    4159              : #define DEBUG_STR_OFFSETS_SECTION ".debug_str_offsets"
    4160              : #endif
    4161              : #ifndef DEBUG_DWO_STR_OFFSETS_SECTION
    4162              : #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
    4163              : #endif
    4164              : #ifndef DEBUG_LTO_DWO_STR_OFFSETS_SECTION
    4165              : #define DEBUG_LTO_DWO_STR_OFFSETS_SECTION ".gnu.debuglto_.debug_str_offsets.dwo"
    4166              : #endif
    4167              : #ifndef DEBUG_STR_SECTION
    4168              : #define DEBUG_STR_SECTION  ".debug_str"
    4169              : #endif
    4170              : #ifndef DEBUG_LTO_STR_SECTION
    4171              : #define DEBUG_LTO_STR_SECTION ".gnu.debuglto_.debug_str"
    4172              : #endif
    4173              : #ifndef DEBUG_STR_DWO_SECTION
    4174              : #define DEBUG_STR_DWO_SECTION   ".debug_str.dwo"
    4175              : #endif
    4176              : #ifndef DEBUG_LTO_STR_DWO_SECTION
    4177              : #define DEBUG_LTO_STR_DWO_SECTION ".gnu.debuglto_.debug_str.dwo"
    4178              : #endif
    4179              : #ifndef DEBUG_RANGES_SECTION
    4180              : #define DEBUG_RANGES_SECTION    ".debug_ranges"
    4181              : #endif
    4182              : #ifndef DEBUG_RNGLISTS_SECTION
    4183              : #define DEBUG_RNGLISTS_SECTION  ".debug_rnglists"
    4184              : #endif
    4185              : #ifndef DEBUG_DWO_RNGLISTS_SECTION
    4186              : #define DEBUG_DWO_RNGLISTS_SECTION      ".debug_rnglists.dwo"
    4187              : #endif
    4188              : #ifndef DEBUG_LINE_STR_SECTION
    4189              : #define DEBUG_LINE_STR_SECTION  ".debug_line_str"
    4190              : #endif
    4191              : #ifndef DEBUG_LTO_LINE_STR_SECTION
    4192              : #define DEBUG_LTO_LINE_STR_SECTION  ".gnu.debuglto_.debug_line_str"
    4193              : #endif
    4194              : 
    4195              : /* Section flags for .debug_str section.  */
    4196              : #define DEBUG_STR_SECTION_FLAGS                                 \
    4197              :   (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings               \
    4198              :    ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1        \
    4199              :    : SECTION_DEBUG)
    4200              : 
    4201              : /* Section flags for .debug_str.dwo section.  */
    4202              : #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
    4203              : 
    4204              : /* Attribute used to refer to the macro section.  */
    4205              : #define DEBUG_MACRO_ATTRIBUTE (dwarf_version >= 5 ? DW_AT_macros \
    4206              :                    : dwarf_strict ? DW_AT_macro_info : DW_AT_GNU_macros)
    4207              : 
    4208              : /* Labels we insert at beginning sections we can reference instead of
    4209              :    the section names themselves.  */
    4210              : 
    4211              : #ifndef TEXT_SECTION_LABEL
    4212              : #define TEXT_SECTION_LABEL                 "Ltext"
    4213              : #endif
    4214              : #ifndef COLD_TEXT_SECTION_LABEL
    4215              : #define COLD_TEXT_SECTION_LABEL             "Ltext_cold"
    4216              : #endif
    4217              : #ifndef DEBUG_LINE_SECTION_LABEL
    4218              : #define DEBUG_LINE_SECTION_LABEL           "Ldebug_line"
    4219              : #endif
    4220              : #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
    4221              : #define DEBUG_SKELETON_LINE_SECTION_LABEL   "Lskeleton_debug_line"
    4222              : #endif
    4223              : #ifndef DEBUG_INFO_SECTION_LABEL
    4224              : #define DEBUG_INFO_SECTION_LABEL           "Ldebug_info"
    4225              : #endif
    4226              : #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
    4227              : #define DEBUG_SKELETON_INFO_SECTION_LABEL   "Lskeleton_debug_info"
    4228              : #endif
    4229              : #ifndef DEBUG_ABBREV_SECTION_LABEL
    4230              : #define DEBUG_ABBREV_SECTION_LABEL         "Ldebug_abbrev"
    4231              : #endif
    4232              : #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
    4233              : #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
    4234              : #endif
    4235              : #ifndef DEBUG_ADDR_SECTION_LABEL
    4236              : #define DEBUG_ADDR_SECTION_LABEL           "Ldebug_addr"
    4237              : #endif
    4238              : #ifndef DEBUG_LOC_SECTION_LABEL
    4239              : #define DEBUG_LOC_SECTION_LABEL                    "Ldebug_loc"
    4240              : #endif
    4241              : #ifndef DEBUG_RANGES_SECTION_LABEL
    4242              : #define DEBUG_RANGES_SECTION_LABEL         "Ldebug_ranges"
    4243              : #endif
    4244              : #ifndef DEBUG_MACINFO_SECTION_LABEL
    4245              : #define DEBUG_MACINFO_SECTION_LABEL         "Ldebug_macinfo"
    4246              : #endif
    4247              : #ifndef DEBUG_MACRO_SECTION_LABEL
    4248              : #define DEBUG_MACRO_SECTION_LABEL          "Ldebug_macro"
    4249              : #endif
    4250              : #define SKELETON_COMP_DIE_ABBREV 1
    4251              : #define SKELETON_TYPE_DIE_ABBREV 2
    4252              : 
    4253              : /* Definitions of defaults for formats and names of various special
    4254              :    (artificial) labels which may be generated within this file (when the -g
    4255              :    options is used and DWARF2_DEBUGGING_INFO is in effect.
    4256              :    If necessary, these may be overridden from within the tm.h file, but
    4257              :    typically, overriding these defaults is unnecessary.  */
    4258              : 
    4259              : static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4260              : static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4261              : static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4262              : static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4263              : static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4264              : static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4265              : static char debug_skeleton_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4266              : static char debug_skeleton_abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4267              : static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4268              : static char debug_addr_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4269              : static char debug_skeleton_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4270              : static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4271              : static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
    4272              : static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
    4273              : static char ranges_base_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
    4274              : 
    4275              : #ifndef TEXT_END_LABEL
    4276              : #define TEXT_END_LABEL          "Letext"
    4277              : #endif
    4278              : #ifndef COLD_END_LABEL
    4279              : #define COLD_END_LABEL          "Letext_cold"
    4280              : #endif
    4281              : #ifndef BLOCK_BEGIN_LABEL
    4282              : #define BLOCK_BEGIN_LABEL       "LBB"
    4283              : #endif
    4284              : #ifndef BLOCK_INLINE_ENTRY_LABEL
    4285              : #define BLOCK_INLINE_ENTRY_LABEL "LBI"
    4286              : #endif
    4287              : #ifndef BLOCK_END_LABEL
    4288              : #define BLOCK_END_LABEL         "LBE"
    4289              : #endif
    4290              : #ifndef LINE_CODE_LABEL
    4291              : #define LINE_CODE_LABEL         "LM"
    4292              : #endif
    4293              : 
    4294              : 
    4295              : /* Return the root of the DIE's built for the current compilation unit.  */
    4296              : static dw_die_ref
    4297    580071803 : comp_unit_die (void)
    4298              : {
    4299    580071803 :   if (!single_comp_unit_die)
    4300        58205 :     single_comp_unit_die = gen_compile_unit_die (NULL);
    4301    580071803 :   return single_comp_unit_die;
    4302              : }
    4303              : 
    4304              : /* We allow a language front-end to designate a function that is to be
    4305              :    called to "demangle" any name before it is put into a DIE.  */
    4306              : 
    4307              : static const char *(*demangle_name_func) (const char *);
    4308              : 
    4309              : void
    4310            0 : dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
    4311              : {
    4312            0 :   demangle_name_func = func;
    4313            0 : }
    4314              : 
    4315              : /* Test if rtl node points to a pseudo register.  */
    4316              : 
    4317              : static inline bool
    4318      1366647 : is_pseudo_reg (const_rtx rtl)
    4319              : {
    4320       939436 :   return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
    4321      1512975 :           || (GET_CODE (rtl) == SUBREG
    4322          618 :               && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
    4323              : }
    4324              : 
    4325              : /* Return a reference to a type, with its const and volatile qualifiers
    4326              :    removed.  */
    4327              : 
    4328              : static inline tree
    4329    832616768 : type_main_variant (tree type)
    4330              : {
    4331    832616768 :   type = TYPE_MAIN_VARIANT (type);
    4332              : 
    4333              :   /* ??? There really should be only one main variant among any group of
    4334              :      variants of a given type (and all of the MAIN_VARIANT values for all
    4335              :      members of the group should point to that one type) but sometimes the C
    4336              :      front-end messes this up for array types, so we work around that bug
    4337              :      here.  */
    4338    832616768 :   if (TREE_CODE (type) == ARRAY_TYPE)
    4339            0 :     while (type != TYPE_MAIN_VARIANT (type))
    4340            0 :       type = TYPE_MAIN_VARIANT (type);
    4341              : 
    4342    832616768 :   return type;
    4343              : }
    4344              : 
    4345              : /* Return true if the given type node represents a tagged type.  */
    4346              : 
    4347              : static inline bool
    4348    953126323 : is_tagged_type (const_tree type)
    4349              : {
    4350    953126323 :   enum tree_code code = TREE_CODE (type);
    4351              : 
    4352    953126323 :   return (code == RECORD_TYPE || code == UNION_TYPE
    4353    953126323 :           || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
    4354              : }
    4355              : 
    4356              : /* Set label to debug_info_section_label + die_offset of a DIE reference.  */
    4357              : 
    4358              : static void
    4359      1294751 : get_ref_die_offset_label (char *label, dw_die_ref ref)
    4360              : {
    4361      1294751 :   sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
    4362            0 : }
    4363              : 
    4364              : /* Return die_offset of a DIE reference to a base type.  */
    4365              : 
    4366              : static unsigned long int
    4367      1849266 : get_base_type_offset (dw_die_ref ref)
    4368              : {
    4369      1849266 :   if (ref->die_offset)
    4370      1316644 :     return ref->die_offset;
    4371       532622 :   if (comp_unit_die ()->die_abbrev)
    4372              :     {
    4373            9 :       calc_base_type_die_sizes ();
    4374            9 :       gcc_assert (ref->die_offset);
    4375              :     }
    4376       532622 :   return ref->die_offset;
    4377              : }
    4378              : 
    4379              : /* Return die_offset of a DIE reference other than base type.  */
    4380              : 
    4381              : static unsigned long int
    4382        32525 : get_ref_die_offset (dw_die_ref ref)
    4383              : {
    4384        32525 :   gcc_assert (ref->die_offset);
    4385        32525 :   return ref->die_offset;
    4386              : }
    4387              : 
    4388              : /* Convert a DIE tag into its string name.  */
    4389              : 
    4390              : static const char *
    4391     88853607 : dwarf_tag_name (unsigned int tag)
    4392              : {
    4393            0 :   const char *name = get_DW_TAG_name (tag);
    4394              : 
    4395     88853607 :   if (name != NULL)
    4396     88853607 :     return name;
    4397              : 
    4398              :   return "DW_TAG_<unknown>";
    4399              : }
    4400              : 
    4401              : /* Convert a DWARF attribute code into its string name.  */
    4402              : 
    4403              : static const char *
    4404    396467806 : dwarf_attr_name (unsigned int attr)
    4405              : {
    4406    396467806 :   const char *name;
    4407              : 
    4408    396467806 :   switch (attr)
    4409              :     {
    4410              : #if VMS_DEBUGGING_INFO
    4411              :     case DW_AT_HP_prologue:
    4412              :       return "DW_AT_HP_prologue";
    4413              : #else
    4414              :     case DW_AT_MIPS_loop_unroll_factor:
    4415              :       return "DW_AT_MIPS_loop_unroll_factor";
    4416              : #endif
    4417              : 
    4418              : #if VMS_DEBUGGING_INFO
    4419              :     case DW_AT_HP_epilogue:
    4420              :       return "DW_AT_HP_epilogue";
    4421              : #else
    4422            0 :     case DW_AT_MIPS_stride:
    4423            0 :       return "DW_AT_MIPS_stride";
    4424              : #endif
    4425              :     }
    4426              : 
    4427    396467806 :   name = get_DW_AT_name (attr);
    4428              : 
    4429    396467806 :   if (name != NULL)
    4430    396467806 :     return name;
    4431              : 
    4432              :   return "DW_AT_<unknown>";
    4433              : }
    4434              : 
    4435              : /* Convert a DWARF value form code into its string name.  */
    4436              : 
    4437              : static const char *
    4438     16596860 : dwarf_form_name (unsigned int form)
    4439              : {
    4440            0 :   const char *name = get_DW_FORM_name (form);
    4441              : 
    4442     16596860 :   if (name != NULL)
    4443     16596860 :     return name;
    4444              : 
    4445              :   return "DW_FORM_<unknown>";
    4446              : }
    4447              : 
    4448              : /* Determine the "ultimate origin" of a decl.  The decl may be an inlined
    4449              :    instance of an inlined instance of a decl which is local to an inline
    4450              :    function, so we have to trace all of the way back through the origin chain
    4451              :    to find out what sort of node actually served as the original seed for the
    4452              :    given block.  */
    4453              : 
    4454              : static tree
    4455    397121092 : decl_ultimate_origin (const_tree decl)
    4456              : {
    4457    397121092 :   if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
    4458              :     return NULL_TREE;
    4459              : 
    4460              :   /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
    4461              :      we're trying to output the abstract instance of this function.  */
    4462    397121092 :   if (DECL_ABSTRACT_P (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
    4463              :     return NULL_TREE;
    4464              : 
    4465              :   /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
    4466              :      most distant ancestor, this should never happen.  */
    4467    443916691 :   gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
    4468              : 
    4469    397117582 :   return DECL_ABSTRACT_ORIGIN (decl);
    4470              : }
    4471              : 
    4472              : /* Get the class to which DECL belongs, if any.  In g++, the DECL_CONTEXT
    4473              :    of a virtual function may refer to a base class, so we check the 'this'
    4474              :    parameter.  */
    4475              : 
    4476              : static tree
    4477    154514976 : decl_class_context (tree decl)
    4478              : {
    4479    154514976 :   tree context = NULL_TREE;
    4480              : 
    4481    154514976 :   if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
    4482    153412552 :     context = DECL_CONTEXT (decl);
    4483              :   else
    4484      1102424 :     context = TYPE_MAIN_VARIANT
    4485              :       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
    4486              : 
    4487    154514976 :   if (context && !TYPE_P (context))
    4488     35308071 :     context = NULL_TREE;
    4489              : 
    4490    154514976 :   return context;
    4491              : }
    4492              : 
    4493              : /* Add an attribute/value pair to a DIE.  */
    4494              : 
    4495              : static inline void
    4496   2620518409 : add_dwarf_attr (dw_die_ref die, dw_attr_node *attr)
    4497              : {
    4498              :   /* Maybe this should be an assert?  */
    4499   2620518409 :   if (die == NULL)
    4500              :     return;
    4501              : 
    4502   2620287688 :   if (flag_checking)
    4503              :     {
    4504              :       /* Check we do not add duplicate attrs.  Can't use get_AT here
    4505              :          because that recurses to the specification/abstract origin DIE.  */
    4506              :       dw_attr_node *a;
    4507              :       unsigned ix;
    4508   9851991906 :       FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    4509   7231704469 :         gcc_assert (a->dw_attr != attr->dw_attr);
    4510              :     }
    4511              : 
    4512   2620287688 :   vec_safe_reserve (die->die_attr, 1);
    4513   2620287688 :   vec_safe_push (die->die_attr, *attr);
    4514              : }
    4515              : 
    4516              : enum dw_val_class
    4517   6941136437 : AT_class (dw_attr_node *a)
    4518              : {
    4519   6941136437 :   return a->dw_attr_val.val_class;
    4520              : }
    4521              : 
    4522              : /* Return the index for any attribute that will be referenced with a
    4523              :    DW_FORM_addrx/GNU_addr_index or DW_FORM_strx/GNU_str_index.  String
    4524              :    indices are stored in dw_attr_val.v.val_str for reference counting
    4525              :    pruning.  */
    4526              : 
    4527              : static inline unsigned int
    4528     55916411 : AT_index (dw_attr_node *a)
    4529              : {
    4530     55916411 :   if (AT_class (a) == dw_val_class_str)
    4531         1870 :     return a->dw_attr_val.v.val_str->index;
    4532     55914541 :   else if (a->dw_attr_val.val_entry != NULL)
    4533         1771 :     return a->dw_attr_val.val_entry->index;
    4534              :   return NOT_INDEXED;
    4535              : }
    4536              : 
    4537              : /* Add a flag value attribute to a DIE.  */
    4538              : 
    4539              : static inline void
    4540    420253166 : add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
    4541              : {
    4542    420253166 :   dw_attr_node attr;
    4543              : 
    4544    420253166 :   attr.dw_attr = attr_kind;
    4545    420253166 :   attr.dw_attr_val.val_class = dw_val_class_flag;
    4546    420253166 :   attr.dw_attr_val.val_entry = NULL;
    4547    420253166 :   attr.dw_attr_val.v.val_flag = flag;
    4548    420253166 :   add_dwarf_attr (die, &attr);
    4549              : }
    4550              : 
    4551              : static inline unsigned
    4552     85934329 : AT_flag (dw_attr_node *a)
    4553              : {
    4554     85934329 :   gcc_assert (a && AT_class (a) == dw_val_class_flag);
    4555     85934329 :   return a->dw_attr_val.v.val_flag;
    4556              : }
    4557              : 
    4558              : /* Add a signed integer attribute value to a DIE.  */
    4559              : 
    4560              : static inline void
    4561       421902 : add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
    4562              : {
    4563       421902 :   dw_attr_node attr;
    4564              : 
    4565       421902 :   attr.dw_attr = attr_kind;
    4566       421902 :   attr.dw_attr_val.val_class = dw_val_class_const;
    4567       421902 :   attr.dw_attr_val.val_entry = NULL;
    4568       421902 :   attr.dw_attr_val.v.val_int = int_val;
    4569       421902 :   add_dwarf_attr (die, &attr);
    4570              : }
    4571              : 
    4572              : HOST_WIDE_INT
    4573        30436 : AT_int (dw_attr_node *a)
    4574              : {
    4575        30436 :   gcc_assert (a && (AT_class (a) == dw_val_class_const
    4576              :                     || AT_class (a) == dw_val_class_const_implicit));
    4577        30436 :   return a->dw_attr_val.v.val_int;
    4578              : }
    4579              : 
    4580              : /* Add an unsigned integer attribute value to a DIE.  */
    4581              : 
    4582              : static inline void
    4583    797869199 : add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
    4584              :                  unsigned HOST_WIDE_INT unsigned_val)
    4585              : {
    4586    797869199 :   dw_attr_node attr;
    4587              : 
    4588    797869199 :   attr.dw_attr = attr_kind;
    4589    797869199 :   attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
    4590    797869199 :   attr.dw_attr_val.val_entry = NULL;
    4591    797869199 :   attr.dw_attr_val.v.val_unsigned = unsigned_val;
    4592      1872813 :   add_dwarf_attr (die, &attr);
    4593              : }
    4594              : 
    4595              : unsigned HOST_WIDE_INT
    4596    914956505 : AT_unsigned (dw_attr_node *a)
    4597              : {
    4598    914956505 :   gcc_assert (a && (AT_class (a) == dw_val_class_unsigned_const
    4599              :                     || AT_class (a) == dw_val_class_unsigned_const_implicit));
    4600    914956505 :   return a->dw_attr_val.v.val_unsigned;
    4601              : }
    4602              : 
    4603              : dw_wide_int *
    4604         1051 : alloc_dw_wide_int (const wide_int_ref &w)
    4605              : {
    4606         1051 :   dw_wide_int *p
    4607         1051 :     = (dw_wide_int *) ggc_internal_alloc (sizeof (dw_wide_int)
    4608         1051 :                                           + ((w.get_len () - 1)
    4609              :                                              * sizeof (HOST_WIDE_INT)));
    4610         1051 :   p->precision = w.get_precision ();
    4611         1051 :   p->len = w.get_len ();
    4612         1051 :   memcpy (p->val, w.get_val (), p->len * sizeof (HOST_WIDE_INT));
    4613         1051 :   return p;
    4614              : }
    4615              : 
    4616              : /* Add an unsigned wide integer attribute value to a DIE.  */
    4617              : 
    4618              : static inline void
    4619           51 : add_AT_wide (dw_die_ref die, enum dwarf_attribute attr_kind,
    4620              :              const wide_int_ref &w)
    4621              : {
    4622           51 :   dw_attr_node attr;
    4623              : 
    4624           51 :   attr.dw_attr = attr_kind;
    4625           51 :   attr.dw_attr_val.val_class = dw_val_class_wide_int;
    4626           51 :   attr.dw_attr_val.val_entry = NULL;
    4627           51 :   attr.dw_attr_val.v.val_wide = alloc_dw_wide_int (w);
    4628           51 :   add_dwarf_attr (die, &attr);
    4629           51 : }
    4630              : 
    4631              : /* Add an unsigned double integer attribute value to a DIE.  */
    4632              : 
    4633              : static inline void
    4634              : add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
    4635              :                HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
    4636              : {
    4637              :   dw_attr_node attr;
    4638              : 
    4639              :   attr.dw_attr = attr_kind;
    4640              :   attr.dw_attr_val.val_class = dw_val_class_const_double;
    4641              :   attr.dw_attr_val.val_entry = NULL;
    4642              :   attr.dw_attr_val.v.val_double.high = high;
    4643              :   attr.dw_attr_val.v.val_double.low = low;
    4644              :   add_dwarf_attr (die, &attr);
    4645              : }
    4646              : 
    4647              : /* Add a floating point attribute value to a DIE and return it.  */
    4648              : 
    4649              : static inline void
    4650      2442365 : add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
    4651              :             unsigned int length, unsigned int elt_size, unsigned char *array)
    4652              : {
    4653      2442365 :   dw_attr_node attr;
    4654              : 
    4655      2442365 :   attr.dw_attr = attr_kind;
    4656      2442365 :   attr.dw_attr_val.val_class = dw_val_class_vec;
    4657      2442365 :   attr.dw_attr_val.val_entry = NULL;
    4658      2442365 :   attr.dw_attr_val.v.val_vec.length = length;
    4659      2442365 :   attr.dw_attr_val.v.val_vec.elt_size = elt_size;
    4660      2442365 :   attr.dw_attr_val.v.val_vec.array = array;
    4661      2442365 :   add_dwarf_attr (die, &attr);
    4662              : }
    4663              : 
    4664              : /* Add an 8-byte data attribute value to a DIE.  */
    4665              : 
    4666              : static inline void
    4667           71 : add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
    4668              :               unsigned char data8[8])
    4669              : {
    4670           71 :   dw_attr_node attr;
    4671              : 
    4672           71 :   attr.dw_attr = attr_kind;
    4673           71 :   attr.dw_attr_val.val_class = dw_val_class_data8;
    4674           71 :   attr.dw_attr_val.val_entry = NULL;
    4675           71 :   memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
    4676           71 :   add_dwarf_attr (die, &attr);
    4677           71 : }
    4678              : 
    4679              : /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE.  When using
    4680              :    dwarf_split_debug_info, address attributes in dies destined for the
    4681              :    final executable have force_direct set to avoid using indexed
    4682              :    references.  */
    4683              : 
    4684              : static inline void
    4685      4893580 : add_AT_low_high_pc (dw_die_ref die, const char *lbl_low, const char *lbl_high,
    4686              :                     bool force_direct)
    4687              : {
    4688      4893580 :   dw_attr_node attr;
    4689      4893580 :   char * lbl_id;
    4690              : 
    4691      4893580 :   lbl_id = xstrdup (lbl_low);
    4692      4893580 :   attr.dw_attr = DW_AT_low_pc;
    4693      4893580 :   attr.dw_attr_val.val_class = dw_val_class_lbl_id;
    4694      4893580 :   attr.dw_attr_val.v.val_lbl_id = lbl_id;
    4695      4893580 :   if (dwarf_split_debug_info && !force_direct)
    4696          242 :     attr.dw_attr_val.val_entry
    4697          242 :       = add_addr_table_entry (lbl_id, ate_kind_label);
    4698              :   else
    4699      4893338 :     attr.dw_attr_val.val_entry = NULL;
    4700      4893580 :   add_dwarf_attr (die, &attr);
    4701              : 
    4702      4893580 :   attr.dw_attr = DW_AT_high_pc;
    4703      4893580 :   if (dwarf_version < 4)
    4704              :     attr.dw_attr_val.val_class = dw_val_class_lbl_id;
    4705              :   else
    4706      4887835 :     attr.dw_attr_val.val_class = dw_val_class_high_pc;
    4707      4893580 :   lbl_id = xstrdup (lbl_high);
    4708      4893580 :   attr.dw_attr_val.v.val_lbl_id = lbl_id;
    4709      4893580 :   if (attr.dw_attr_val.val_class == dw_val_class_lbl_id
    4710         5745 :       && dwarf_split_debug_info && !force_direct)
    4711            0 :     attr.dw_attr_val.val_entry
    4712            0 :       = add_addr_table_entry (lbl_id, ate_kind_label);
    4713              :   else
    4714      4893580 :     attr.dw_attr_val.val_entry = NULL;
    4715      4893580 :   add_dwarf_attr (die, &attr);
    4716      4893580 : }
    4717              : 
    4718              : /* Hash and equality functions for debug_str_hash.  */
    4719              : 
    4720              : hashval_t
    4721   2980165944 : indirect_string_hasher::hash (indirect_string_node *x)
    4722              : {
    4723   2980165944 :   return htab_hash_string (x->str);
    4724              : }
    4725              : 
    4726              : bool
    4727   3338137771 : indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
    4728              : {
    4729   3338137771 :   return strcmp (x1->str, x2) == 0;
    4730              : }
    4731              : 
    4732              : /* Add STR to the given string hash table.  */
    4733              : 
    4734              : static struct indirect_string_node *
    4735    437295951 : find_AT_string_in_table (const char *str,
    4736              :                          hash_table<indirect_string_hasher> *table,
    4737              :                          enum insert_option insert = INSERT)
    4738              : {
    4739    437295951 :   struct indirect_string_node *node;
    4740              : 
    4741    437295951 :   indirect_string_node **slot
    4742    437295951 :     = table->find_slot_with_hash (str, htab_hash_string (str), insert);
    4743    437295951 :   if (*slot == NULL)
    4744              :     {
    4745    222118554 :       node = ggc_cleared_alloc<indirect_string_node> ();
    4746    222118554 :       node->str = ggc_strdup (str);
    4747    222118554 :       *slot = node;
    4748              :     }
    4749              :   else
    4750              :     node = *slot;
    4751              : 
    4752    437295951 :   node->refcount++;
    4753    437295951 :   return node;
    4754              : }
    4755              : 
    4756              : /* Add STR to the indirect string hash table.  */
    4757              : 
    4758              : static struct indirect_string_node *
    4759    437181221 : find_AT_string (const char *str, enum insert_option insert = INSERT)
    4760              : {
    4761    437181221 :   if (! debug_str_hash)
    4762        58205 :     debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
    4763              : 
    4764    437181221 :   return find_AT_string_in_table (str, debug_str_hash, insert);
    4765              : }
    4766              : 
    4767              : /* Add a string attribute value to a DIE.  */
    4768              : 
    4769              : static inline void
    4770    436642374 : add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
    4771              : {
    4772    436642374 :   dw_attr_node attr;
    4773    436642374 :   struct indirect_string_node *node;
    4774              : 
    4775    436642374 :   node = find_AT_string (str);
    4776              : 
    4777    436642374 :   attr.dw_attr = attr_kind;
    4778    436642374 :   attr.dw_attr_val.val_class = dw_val_class_str;
    4779    436642374 :   attr.dw_attr_val.val_entry = NULL;
    4780    436642374 :   attr.dw_attr_val.v.val_str = node;
    4781    436642374 :   add_dwarf_attr (die, &attr);
    4782    436642374 : }
    4783              : 
    4784              : static inline const char *
    4785     35577991 : AT_string (dw_attr_node *a)
    4786              : {
    4787     35577991 :   gcc_assert (a && AT_class (a) == dw_val_class_str);
    4788     35577991 :   return a->dw_attr_val.v.val_str->str;
    4789              : }
    4790              : 
    4791              : /* Call this function directly to bypass AT_string_form's logic to put
    4792              :    the string inline in the die. */
    4793              : 
    4794              : static void
    4795     20957079 : set_indirect_string (struct indirect_string_node *node)
    4796              : {
    4797     20957079 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
    4798              :   /* Already indirect is a no op.  */
    4799     20957079 :   if (node->form == DW_FORM_strp
    4800     20956253 :       || node->form == DW_FORM_line_strp
    4801     42153851 :       || node->form == dwarf_FORM (DW_FORM_strx))
    4802              :     {
    4803         3682 :       gcc_assert (node->label);
    4804         3682 :       return;
    4805              :     }
    4806     20953397 :   ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
    4807     20953397 :   ++dw2_string_counter;
    4808     20953397 :   node->label = xstrdup (label);
    4809              : 
    4810     20953397 :   if (!dwarf_split_debug_info)
    4811              :     {
    4812     20950289 :       node->form = DW_FORM_strp;
    4813     20950289 :       node->index = NOT_INDEXED;
    4814              :     }
    4815              :   else
    4816              :     {
    4817         3108 :       node->form = dwarf_FORM (DW_FORM_strx);
    4818         3108 :       node->index = NO_INDEX_ASSIGNED;
    4819              :     }
    4820              : }
    4821              : 
    4822              : /* A helper function for dwarf2out_finish, called to reset indirect
    4823              :    string decisions done for early LTO dwarf output before fat object
    4824              :    dwarf output.  */
    4825              : 
    4826              : int
    4827        18986 : reset_indirect_string (indirect_string_node **h, void *)
    4828              : {
    4829        18986 :   struct indirect_string_node *node = *h;
    4830        18986 :   if (node->form == DW_FORM_strp
    4831         6402 :       || node->form == DW_FORM_line_strp
    4832        22305 :       || node->form == dwarf_FORM (DW_FORM_strx))
    4833              :     {
    4834        15697 :       free (node->label);
    4835        15697 :       node->label = NULL;
    4836        15697 :       node->form = (dwarf_form) 0;
    4837        15697 :       node->index = 0;
    4838              :     }
    4839        18986 :   return 1;
    4840              : }
    4841              : 
    4842              : /* Add a string representing a file or filepath attribute value to a DIE.  */
    4843              : 
    4844              : static inline void
    4845       108716 : add_filepath_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
    4846              :                         const char *str)
    4847              : {
    4848       108716 :   if (! asm_outputs_debug_line_str ())
    4849         4524 :     add_AT_string (die, attr_kind, str);
    4850              :   else
    4851              :     {
    4852       104192 :       dw_attr_node attr;
    4853       104192 :       struct indirect_string_node *node;
    4854              : 
    4855       104192 :       if (!debug_line_str_hash)
    4856        52096 :         debug_line_str_hash
    4857        52096 :           = hash_table<indirect_string_hasher>::create_ggc (10);
    4858              : 
    4859       104192 :       node = find_AT_string_in_table (str, debug_line_str_hash);
    4860       104192 :       set_indirect_string (node);
    4861       104192 :       node->form = DW_FORM_line_strp;
    4862              : 
    4863       104192 :       attr.dw_attr = attr_kind;
    4864       104192 :       attr.dw_attr_val.val_class = dw_val_class_str;
    4865       104192 :       attr.dw_attr_val.val_entry = NULL;
    4866       104192 :       attr.dw_attr_val.v.val_str = node;
    4867       104192 :       add_dwarf_attr (die, &attr);
    4868              :     }
    4869       108716 : }
    4870              : 
    4871              : /* Find out whether a string should be output inline in DIE
    4872              :    or out-of-line in .debug_str section.  */
    4873              : 
    4874              : static enum dwarf_form
    4875    224924416 : find_string_form (struct indirect_string_node *node)
    4876              : {
    4877    224924416 :   unsigned int len;
    4878              : 
    4879    224924416 :   if (node->form)
    4880              :     return node->form;
    4881              : 
    4882     21289289 :   len = strlen (node->str) + 1;
    4883              : 
    4884              :   /* If the string is shorter or equal to the size of the reference, it is
    4885              :      always better to put it inline.  */
    4886     21289289 :   if (len <= (unsigned) dwarf_offset_size || node->refcount == 0)
    4887       688182 :     return node->form = DW_FORM_string;
    4888              : 
    4889              :   /* If we cannot expect the linker to merge strings in .debug_str
    4890              :      section, only put it into .debug_str if it is worth even in this
    4891              :      single module.  */
    4892     20601107 :   if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
    4893     20601107 :       || ((debug_str_section->common.flags & SECTION_MERGE) == 0
    4894          759 :           && (len - dwarf_offset_size) * node->refcount <= len))
    4895          734 :     return node->form = DW_FORM_string;
    4896              : 
    4897     20600373 :   set_indirect_string (node);
    4898              : 
    4899     20600373 :   return node->form;
    4900              : }
    4901              : 
    4902              : /* Find out whether the string referenced from the attribute should be
    4903              :    output inline in DIE or out-of-line in .debug_str section.  */
    4904              : 
    4905              : static enum dwarf_form
    4906    203280086 : AT_string_form (dw_attr_node *a)
    4907              : {
    4908    203280086 :   gcc_assert (a && AT_class (a) == dw_val_class_str);
    4909    203280086 :   return find_string_form (a->dw_attr_val.v.val_str);
    4910              : }
    4911              : 
    4912              : /* Add a DIE reference attribute value to a DIE.  */
    4913              : 
    4914              : static inline void
    4915    637450408 : add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
    4916              : {
    4917    637450408 :   dw_attr_node attr;
    4918    637450408 :   gcc_checking_assert (targ_die != NULL);
    4919    637450408 :   gcc_assert (targ_die != die
    4920              :               || (attr_kind != DW_AT_abstract_origin
    4921              :                   && attr_kind != DW_AT_specification));
    4922              : 
    4923              :   /* With LTO we can end up trying to reference something we didn't create
    4924              :      a DIE for.  Avoid crashing later on a NULL referenced DIE.  */
    4925    637450408 :   if (targ_die == NULL)
    4926              :     return;
    4927              : 
    4928    637450408 :   attr.dw_attr = attr_kind;
    4929    637450408 :   attr.dw_attr_val.val_class = dw_val_class_die_ref;
    4930    637450408 :   attr.dw_attr_val.val_entry = NULL;
    4931    637450408 :   attr.dw_attr_val.v.val_die_ref.die = targ_die;
    4932    637450408 :   attr.dw_attr_val.v.val_die_ref.external = 0;
    4933    637450408 :   add_dwarf_attr (die, &attr);
    4934              : }
    4935              : 
    4936              : /* Change DIE reference REF to point to NEW_DIE instead.  */
    4937              : 
    4938              : static inline void
    4939          139 : change_AT_die_ref (dw_attr_node *ref, dw_die_ref new_die)
    4940              : {
    4941          139 :   gcc_assert (ref->dw_attr_val.val_class == dw_val_class_die_ref);
    4942          139 :   ref->dw_attr_val.v.val_die_ref.die = new_die;
    4943          139 :   ref->dw_attr_val.v.val_die_ref.external = 0;
    4944          139 : }
    4945              : 
    4946              : /* Add an AT_specification attribute to a DIE, and also make the back
    4947              :    pointer from the specification to the definition.  */
    4948              : 
    4949              : static inline void
    4950     27594405 : add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
    4951              : {
    4952     27594405 :   add_AT_die_ref (die, DW_AT_specification, targ_die);
    4953     27594405 :   gcc_assert (!targ_die->die_definition);
    4954     27594405 :   targ_die->die_definition = die;
    4955     27594405 : }
    4956              : 
    4957              : static inline dw_die_ref
    4958    666709081 : AT_ref (dw_attr_node *a)
    4959              : {
    4960    666709081 :   gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
    4961    666709081 :   return a->dw_attr_val.v.val_die_ref.die;
    4962              : }
    4963              : 
    4964              : static inline int
    4965    419729895 : AT_ref_external (dw_attr_node *a)
    4966              : {
    4967    419729895 :   if (a && AT_class (a) == dw_val_class_die_ref)
    4968    419729895 :     return a->dw_attr_val.v.val_die_ref.external;
    4969              : 
    4970              :   return 0;
    4971              : }
    4972              : 
    4973              : static inline void
    4974        29849 : set_AT_ref_external (dw_attr_node *a, int i)
    4975              : {
    4976        29849 :   gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
    4977        29849 :   a->dw_attr_val.v.val_die_ref.external = i;
    4978        29849 : }
    4979              : 
    4980              : /* Add a location description attribute value to a DIE.  */
    4981              : 
    4982              : static inline void
    4983      8705749 : add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
    4984              : {
    4985      8705749 :   dw_attr_node attr;
    4986              : 
    4987      8705749 :   attr.dw_attr = attr_kind;
    4988      8705749 :   attr.dw_attr_val.val_class = dw_val_class_loc;
    4989      8705749 :   attr.dw_attr_val.val_entry = NULL;
    4990      8705749 :   attr.dw_attr_val.v.val_loc = loc;
    4991      8705749 :   add_dwarf_attr (die, &attr);
    4992              : }
    4993              : 
    4994              : dw_loc_descr_ref
    4995     32120337 : AT_loc (dw_attr_node *a)
    4996              : {
    4997     32120337 :   gcc_assert (a && AT_class (a) == dw_val_class_loc);
    4998     32120337 :   return a->dw_attr_val.v.val_loc;
    4999              : }
    5000              : 
    5001              : static inline void
    5002     12816391 : add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
    5003              : {
    5004     12816391 :   dw_attr_node attr;
    5005              : 
    5006     12816391 :   if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
    5007              :     return;
    5008              : 
    5009     12816391 :   attr.dw_attr = attr_kind;
    5010     12816391 :   attr.dw_attr_val.val_class = dw_val_class_loc_list;
    5011     12816391 :   attr.dw_attr_val.val_entry = NULL;
    5012     12816391 :   attr.dw_attr_val.v.val_loc_list = loc_list;
    5013     12816391 :   add_dwarf_attr (die, &attr);
    5014     12816391 :   have_location_lists = true;
    5015              : }
    5016              : 
    5017              : static inline dw_loc_list_ref
    5018     36707087 : AT_loc_list (dw_attr_node *a)
    5019              : {
    5020     36707087 :   gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
    5021     36707087 :   return a->dw_attr_val.v.val_loc_list;
    5022              : }
    5023              : 
    5024              : /* Add a view list attribute to DIE.  It must have a DW_AT_location
    5025              :    attribute, because the view list complements the location list.  */
    5026              : 
    5027              : static inline void
    5028     12639444 : add_AT_view_list (dw_die_ref die, enum dwarf_attribute attr_kind)
    5029              : {
    5030     12639444 :   dw_attr_node attr;
    5031              : 
    5032     12639444 :   if (XCOFF_DEBUGGING_INFO && !HAVE_XCOFF_DWARF_EXTRAS)
    5033              :     return;
    5034              : 
    5035     12639444 :   attr.dw_attr = attr_kind;
    5036     12639444 :   attr.dw_attr_val.val_class = dw_val_class_view_list;
    5037     12639444 :   attr.dw_attr_val.val_entry = NULL;
    5038     12639444 :   attr.dw_attr_val.v.val_view_list = die;
    5039     12639444 :   add_dwarf_attr (die, &attr);
    5040     12639444 :   gcc_checking_assert (get_AT (die, DW_AT_location));
    5041     12639444 :   gcc_assert (have_location_lists);
    5042              : }
    5043              : 
    5044              : /* Return a pointer to the location list referenced by the attribute.
    5045              :    If the named attribute is a view list, look up the corresponding
    5046              :    DW_AT_location attribute and return its location list.  */
    5047              : 
    5048              : static inline dw_loc_list_ref *
    5049     24875136 : AT_loc_list_ptr (dw_attr_node *a)
    5050              : {
    5051     36933866 :   gcc_assert (a);
    5052     36933866 :   switch (AT_class (a))
    5053              :     {
    5054     24875136 :     case dw_val_class_loc_list:
    5055     24875136 :       return &a->dw_attr_val.v.val_loc_list;
    5056     12058730 :     case dw_val_class_view_list:
    5057     12058730 :       {
    5058     12058730 :         dw_attr_node *l;
    5059     12058730 :         l = get_AT (a->dw_attr_val.v.val_view_list, DW_AT_location);
    5060     12058730 :         if (!l)
    5061              :           return NULL;
    5062     12058730 :         gcc_checking_assert (l + 1 == a);
    5063              :         return AT_loc_list_ptr (l);
    5064              :       }
    5065            0 :     default:
    5066            0 :       gcc_unreachable ();
    5067              :     }
    5068              : }
    5069              : 
    5070              : /* Return the location attribute value associated with a view list
    5071              :    attribute value.  */
    5072              : 
    5073              : static inline dw_val_node *
    5074     12639480 : view_list_to_loc_list_val_node (dw_val_node *val)
    5075              : {
    5076     12639480 :   gcc_assert (val->val_class == dw_val_class_view_list);
    5077     12639480 :   dw_attr_node *loc = get_AT (val->v.val_view_list, DW_AT_location);
    5078     12639480 :   if (!loc)
    5079              :     return NULL;
    5080     12058766 :   gcc_checking_assert (&(loc + 1)->dw_attr_val == val);
    5081     12058766 :   gcc_assert (AT_class (loc) == dw_val_class_loc_list);
    5082     12058766 :   return &loc->dw_attr_val;
    5083              : }
    5084              : 
    5085              : struct addr_hasher : ggc_ptr_hash<addr_table_entry>
    5086              : {
    5087              :   static hashval_t hash (addr_table_entry *);
    5088              :   static bool equal (addr_table_entry *, addr_table_entry *);
    5089              : };
    5090              : 
    5091              : /* Table of entries into the .debug_addr section.  */
    5092              : 
    5093              : static GTY (()) hash_table<addr_hasher> *addr_index_table;
    5094              : 
    5095              : /* Hash an address_table_entry.  */
    5096              : 
    5097              : hashval_t
    5098          342 : addr_hasher::hash (addr_table_entry *a)
    5099              : {
    5100          342 :   inchash::hash hstate;
    5101          342 :   switch (a->kind)
    5102              :     {
    5103           21 :       case ate_kind_rtx:
    5104           21 :         hstate.add_int (0);
    5105           21 :         break;
    5106            0 :       case ate_kind_rtx_dtprel:
    5107            0 :         hstate.add_int (1);
    5108            0 :         break;
    5109          321 :       case ate_kind_label:
    5110          321 :         return htab_hash_string (a->addr.label);
    5111            0 :       default:
    5112            0 :         gcc_unreachable ();
    5113              :     }
    5114           21 :   inchash::add_rtx (a->addr.rtl, hstate);
    5115           21 :   return hstate.end ();
    5116              : }
    5117              : 
    5118              : /* Determine equality for two address_table_entries.  */
    5119              : 
    5120              : bool
    5121           77 : addr_hasher::equal (addr_table_entry *a1, addr_table_entry *a2)
    5122              : {
    5123           77 :   if (a1->kind != a2->kind)
    5124              :     return false;
    5125           47 :   switch (a1->kind)
    5126              :     {
    5127            3 :       case ate_kind_rtx:
    5128            3 :       case ate_kind_rtx_dtprel:
    5129            3 :         return rtx_equal_p (a1->addr.rtl, a2->addr.rtl);
    5130           44 :       case ate_kind_label:
    5131           44 :         return strcmp (a1->addr.label, a2->addr.label) == 0;
    5132            0 :       default:
    5133            0 :         gcc_unreachable ();
    5134              :     }
    5135              : }
    5136              : 
    5137              : /* Initialize an addr_table_entry.  */
    5138              : 
    5139              : void
    5140          535 : init_addr_table_entry (addr_table_entry *e, enum ate_kind kind, void *addr)
    5141              : {
    5142          535 :   e->kind = kind;
    5143          535 :   switch (kind)
    5144              :     {
    5145            9 :       case ate_kind_rtx:
    5146            9 :       case ate_kind_rtx_dtprel:
    5147            9 :         e->addr.rtl = (rtx) addr;
    5148            9 :         break;
    5149          526 :       case ate_kind_label:
    5150          526 :         e->addr.label = (char *) addr;
    5151          526 :         break;
    5152              :     }
    5153          535 :   e->refcount = 0;
    5154          535 :   e->index = NO_INDEX_ASSIGNED;
    5155          535 : }
    5156              : 
    5157              : /* Add attr to the address table entry to the table.  Defer setting an
    5158              :    index until output time.  */
    5159              : 
    5160              : static addr_table_entry *
    5161          271 : add_addr_table_entry (void *addr, enum ate_kind kind)
    5162              : {
    5163          271 :   addr_table_entry *node;
    5164          271 :   addr_table_entry finder;
    5165              : 
    5166          271 :   gcc_assert (dwarf_split_debug_info);
    5167          271 :   if (! addr_index_table)
    5168          244 :     addr_index_table = hash_table<addr_hasher>::create_ggc (10);
    5169          271 :   init_addr_table_entry (&finder, kind, addr);
    5170          271 :   addr_table_entry **slot = addr_index_table->find_slot (&finder, INSERT);
    5171              : 
    5172          271 :   if (*slot == HTAB_EMPTY_ENTRY)
    5173              :     {
    5174          264 :       node = ggc_cleared_alloc<addr_table_entry> ();
    5175          264 :       init_addr_table_entry (node, kind, addr);
    5176          264 :       *slot = node;
    5177              :     }
    5178              :   else
    5179              :     node = *slot;
    5180              : 
    5181          271 :   node->refcount++;
    5182          271 :   return node;
    5183              : }
    5184              : 
    5185              : /* Remove an entry from the addr table by decrementing its refcount.
    5186              :    Strictly, decrementing the refcount would be enough, but the
    5187              :    assertion that the entry is actually in the table has found
    5188              :    bugs.  */
    5189              : 
    5190              : static void
    5191            3 : remove_addr_table_entry (addr_table_entry *entry)
    5192              : {
    5193            3 :   gcc_assert (dwarf_split_debug_info && addr_index_table);
    5194              :   /* After an index is assigned, the table is frozen.  */
    5195            3 :   gcc_assert (entry->refcount > 0 && entry->index == NO_INDEX_ASSIGNED);
    5196            3 :   entry->refcount--;
    5197            3 : }
    5198              : 
    5199              : /* Given a location list, remove all addresses it refers to from the
    5200              :    address_table.  */
    5201              : 
    5202              : static void
    5203          550 : remove_loc_list_addr_table_entries (dw_loc_descr_ref descr)
    5204              : {
    5205         4217 :   for (; descr; descr = descr->dw_loc_next)
    5206         3667 :     if (descr->dw_loc_oprnd1.val_entry != NULL)
    5207              :       {
    5208            0 :         gcc_assert (descr->dw_loc_oprnd1.val_entry->index == NO_INDEX_ASSIGNED);
    5209            0 :         remove_addr_table_entry (descr->dw_loc_oprnd1.val_entry);
    5210              :       }
    5211          550 : }
    5212              : 
    5213              : /* A helper function for dwarf2out_finish called through
    5214              :    htab_traverse.  Assign an addr_table_entry its index.  All entries
    5215              :    must be collected into the table when this function is called,
    5216              :    because the indexing code relies on htab_traverse to traverse nodes
    5217              :    in the same order for each run. */
    5218              : 
    5219              : int
    5220          264 : index_addr_table_entry (addr_table_entry **h, unsigned int *index)
    5221              : {
    5222          264 :   addr_table_entry *node = *h;
    5223              : 
    5224              :   /* Don't index unreferenced nodes.  */
    5225          264 :   if (node->refcount == 0)
    5226              :     return 1;
    5227              : 
    5228          264 :   gcc_assert (node->index == NO_INDEX_ASSIGNED);
    5229          264 :   node->index = *index;
    5230          264 :   *index += 1;
    5231              : 
    5232          264 :   return 1;
    5233              : }
    5234              : 
    5235              : /* Return the tag of a given DIE.  */
    5236              : 
    5237              : enum dwarf_tag
    5238         6407 : dw_get_die_tag (dw_die_ref die)
    5239              : {
    5240         6407 :   return die->die_tag;
    5241              : }
    5242              : 
    5243              : /* Return a reference to the children list of a given DIE.  */
    5244              : 
    5245              : dw_die_ref
    5246         1861 : dw_get_die_child (dw_die_ref die)
    5247              : {
    5248         1861 :   return die->die_child;
    5249              : }
    5250              : 
    5251              : /* Return a reference to the sibling of a given DIE.  */
    5252              : 
    5253              : dw_die_ref
    5254         1112 : dw_get_die_sib (dw_die_ref die)
    5255              : {
    5256         1112 :   return die->die_sib;
    5257              : }
    5258              : 
    5259              : /* Add an address constant attribute value to a DIE.  When using
    5260              :    dwarf_split_debug_info, address attributes in dies destined for the
    5261              :    final executable should be direct references--setting the parameter
    5262              :    force_direct ensures this behavior.  */
    5263              : 
    5264              : static inline void
    5265      1554392 : add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr,
    5266              :              bool force_direct)
    5267              : {
    5268      1554392 :   dw_attr_node attr;
    5269              : 
    5270      1554392 :   attr.dw_attr = attr_kind;
    5271      1554392 :   attr.dw_attr_val.val_class = dw_val_class_addr;
    5272      1554392 :   attr.dw_attr_val.v.val_addr = addr;
    5273      1554392 :   if (dwarf_split_debug_info && !force_direct)
    5274            0 :     attr.dw_attr_val.val_entry = add_addr_table_entry (addr, ate_kind_rtx);
    5275              :   else
    5276      1554392 :     attr.dw_attr_val.val_entry = NULL;
    5277      1554392 :   add_dwarf_attr (die, &attr);
    5278      1554392 : }
    5279              : 
    5280              : /* Get the RTX from to an address DIE attribute.  */
    5281              : 
    5282              : static inline rtx
    5283        29808 : AT_addr (dw_attr_node *a)
    5284              : {
    5285        29808 :   gcc_assert (a && AT_class (a) == dw_val_class_addr);
    5286        29808 :   return a->dw_attr_val.v.val_addr;
    5287              : }
    5288              : 
    5289              : /* Add a file attribute value to a DIE.  */
    5290              : 
    5291              : static inline void
    5292    259424804 : add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
    5293              :              struct dwarf_file_data *fd)
    5294              : {
    5295    259424804 :   dw_attr_node attr;
    5296              : 
    5297    259424804 :   attr.dw_attr = attr_kind;
    5298    259424804 :   attr.dw_attr_val.val_class = dw_val_class_file;
    5299    259424804 :   attr.dw_attr_val.val_entry = NULL;
    5300    259424804 :   attr.dw_attr_val.v.val_file = fd;
    5301    259424804 :   add_dwarf_attr (die, &attr);
    5302              : }
    5303              : 
    5304              : /* Get the dwarf_file_data from a file DIE attribute.  */
    5305              : 
    5306              : static inline struct dwarf_file_data *
    5307     28204439 : AT_file (dw_attr_node *a)
    5308              : {
    5309     28204439 :   gcc_assert (a && (AT_class (a) == dw_val_class_file
    5310              :                     || AT_class (a) == dw_val_class_file_implicit));
    5311     28204439 :   return a->dw_attr_val.v.val_file;
    5312              : }
    5313              : 
    5314              : #if VMS_DEBUGGING_INFO
    5315              : /* Add a vms delta attribute value to a DIE.  */
    5316              : 
    5317              : static inline void
    5318              : add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
    5319              :                   const char *lbl1, const char *lbl2)
    5320              : {
    5321              :   dw_attr_node attr;
    5322              : 
    5323              :   attr.dw_attr = attr_kind;
    5324              :   attr.dw_attr_val.val_class = dw_val_class_vms_delta;
    5325              :   attr.dw_attr_val.val_entry = NULL;
    5326              :   attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
    5327              :   attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
    5328              :   add_dwarf_attr (die, &attr);
    5329              : }
    5330              : #endif
    5331              : 
    5332              : /* Add a symbolic view identifier attribute value to a DIE.  */
    5333              : 
    5334              : static inline void
    5335      6910345 : add_AT_symview (dw_die_ref die, enum dwarf_attribute attr_kind,
    5336              :                const char *view_label)
    5337              : {
    5338      6910345 :   dw_attr_node attr;
    5339              : 
    5340      6910345 :   attr.dw_attr = attr_kind;
    5341      6910345 :   attr.dw_attr_val.val_class = dw_val_class_symview;
    5342      6910345 :   attr.dw_attr_val.val_entry = NULL;
    5343      6910345 :   attr.dw_attr_val.v.val_symbolic_view = xstrdup (view_label);
    5344      6910345 :   add_dwarf_attr (die, &attr);
    5345      6910345 : }
    5346              : 
    5347              : /* Add a label identifier attribute value to a DIE.  */
    5348              : 
    5349              : static inline void
    5350      9941059 : add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind,
    5351              :                const char *lbl_id, int offset)
    5352              : {
    5353      9941059 :   dw_attr_node attr;
    5354              : 
    5355      9941059 :   attr.dw_attr = attr_kind;
    5356      9941059 :   attr.dw_attr_val.val_class = dw_val_class_lbl_id;
    5357      9941059 :   attr.dw_attr_val.val_entry = NULL;
    5358      9941059 :   if (!offset)
    5359      9941059 :     attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
    5360              :   else
    5361            0 :     attr.dw_attr_val.v.val_lbl_id = xasprintf ("%s%+i", lbl_id, offset);
    5362      9941059 :   if (dwarf_split_debug_info)
    5363           11 :     attr.dw_attr_val.val_entry
    5364           11 :         = add_addr_table_entry (attr.dw_attr_val.v.val_lbl_id,
    5365              :                                 ate_kind_label);
    5366      9941059 :   add_dwarf_attr (die, &attr);
    5367      9941059 : }
    5368              : 
    5369              : /* Add a section offset attribute value to a DIE, an offset into the
    5370              :    debug_line section.  */
    5371              : 
    5372              : static inline void
    5373        54898 : add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
    5374              :                 const char *label)
    5375              : {
    5376        54898 :   dw_attr_node attr;
    5377              : 
    5378        54898 :   attr.dw_attr = attr_kind;
    5379        54898 :   attr.dw_attr_val.val_class = dw_val_class_lineptr;
    5380        54898 :   attr.dw_attr_val.val_entry = NULL;
    5381        54898 :   attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
    5382        54898 :   add_dwarf_attr (die, &attr);
    5383        54898 : }
    5384              : 
    5385              : /* Add a section offset attribute value to a DIE, an offset into the
    5386              :    debug_macinfo section.  */
    5387              : 
    5388              : static inline void
    5389          528 : add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
    5390              :                const char *label)
    5391              : {
    5392          528 :   dw_attr_node attr;
    5393              : 
    5394          528 :   attr.dw_attr = attr_kind;
    5395          528 :   attr.dw_attr_val.val_class = dw_val_class_macptr;
    5396          528 :   attr.dw_attr_val.val_entry = NULL;
    5397          528 :   attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
    5398          528 :   add_dwarf_attr (die, &attr);
    5399          528 : }
    5400              : 
    5401              : /* Add a range_list attribute value to a DIE.  When using
    5402              :    dwarf_split_debug_info, address attributes in dies destined for the
    5403              :    final executable should be direct references--setting the parameter
    5404              :    force_direct ensures this behavior.  */
    5405              : 
    5406              : #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
    5407              : #define RELOCATED_OFFSET (NULL)
    5408              : 
    5409              : static void
    5410      3498191 : add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
    5411              :                    long unsigned int offset, bool force_direct)
    5412              : {
    5413      3498191 :   dw_attr_node attr;
    5414              : 
    5415      3498191 :   attr.dw_attr = attr_kind;
    5416      3498191 :   attr.dw_attr_val.val_class = dw_val_class_range_list;
    5417              :   /* For the range_list attribute, use val_entry to store whether the
    5418              :      offset should follow split-debug-info or normal semantics.  This
    5419              :      value is read in output_range_list_offset.  */
    5420      3498191 :   if (dwarf_split_debug_info && !force_direct)
    5421            3 :     attr.dw_attr_val.val_entry = UNRELOCATED_OFFSET;
    5422              :   else
    5423      3498188 :     attr.dw_attr_val.val_entry = RELOCATED_OFFSET;
    5424      3498191 :   attr.dw_attr_val.v.val_offset = offset;
    5425      3498191 :   add_dwarf_attr (die, &attr);
    5426      3498191 : }
    5427              : 
    5428              : /* Return the start label of a delta attribute.  */
    5429              : 
    5430              : static inline const char *
    5431            0 : AT_vms_delta1 (dw_attr_node *a)
    5432              : {
    5433            0 :   gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
    5434            0 :   return a->dw_attr_val.v.val_vms_delta.lbl1;
    5435              : }
    5436              : 
    5437              : /* Return the end label of a delta attribute.  */
    5438              : 
    5439              : static inline const char *
    5440            0 : AT_vms_delta2 (dw_attr_node *a)
    5441              : {
    5442            0 :   gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
    5443            0 :   return a->dw_attr_val.v.val_vms_delta.lbl2;
    5444              : }
    5445              : 
    5446              : static inline const char *
    5447     24669262 : AT_lbl (dw_attr_node *a)
    5448              : {
    5449     24669262 :   gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
    5450              :                     || AT_class (a) == dw_val_class_lineptr
    5451              :                     || AT_class (a) == dw_val_class_macptr
    5452              :                     || AT_class (a) == dw_val_class_loclistsptr
    5453              :                     || AT_class (a) == dw_val_class_high_pc));
    5454     24669262 :   return a->dw_attr_val.v.val_lbl_id;
    5455              : }
    5456              : 
    5457              : /* Get the attribute of type attr_kind.  */
    5458              : 
    5459              : dw_attr_node *
    5460   1060700315 : get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
    5461              : {
    5462   1201089217 :   dw_attr_node *a;
    5463   1201089217 :   unsigned ix;
    5464   1201089217 :   dw_die_ref spec = NULL;
    5465              : 
    5466   1201089217 :   if (! die)
    5467              :     return NULL;
    5468              : 
    5469   4564493176 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    5470   4236407491 :     if (a->dw_attr == attr_kind)
    5471              :       return a;
    5472   3363403959 :     else if (a->dw_attr == DW_AT_specification
    5473   3251301907 :              || a->dw_attr == DW_AT_abstract_origin)
    5474    183679894 :       spec = AT_ref (a);
    5475              : 
    5476    328085685 :   if (spec)
    5477              :     return get_AT (spec, attr_kind);
    5478              : 
    5479              :   return NULL;
    5480              : }
    5481              : 
    5482              : /* Returns the parent of the declaration of DIE.  */
    5483              : 
    5484              : dw_die_ref
    5485           81 : dw_get_die_parent (dw_die_ref die)
    5486              : {
    5487           81 :   dw_die_ref t;
    5488              : 
    5489           81 :   if (!die)
    5490              :     return NULL;
    5491              : 
    5492           81 :   if ((t = get_AT_ref (die, DW_AT_abstract_origin))
    5493           81 :       || (t = get_AT_ref (die, DW_AT_specification)))
    5494              :     die = t;
    5495              : 
    5496           81 :   return die->die_parent;
    5497              : }
    5498              : 
    5499              : /* Return the "low pc" attribute value, typically associated with a subprogram
    5500              :    DIE.  Return null if the "low pc" attribute is either not present, or if it
    5501              :    cannot be represented as an assembler label identifier.  */
    5502              : 
    5503              : static inline const char *
    5504      4887532 : get_AT_low_pc (dw_die_ref die)
    5505              : {
    5506      4887532 :   dw_attr_node *a = get_AT (die, DW_AT_low_pc);
    5507              : 
    5508      4887532 :   return a ? AT_lbl (a) : NULL;
    5509              : }
    5510              : 
    5511              : /* Return the value of the string attribute designated by ATTR_KIND, or
    5512              :    NULL if it is not present.  */
    5513              : 
    5514              : const char *
    5515        58504 : get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
    5516              : {
    5517        58504 :   dw_attr_node *a = get_AT (die, attr_kind);
    5518              : 
    5519        58504 :   return a ? AT_string (a) : NULL;
    5520              : }
    5521              : 
    5522              : /* Return the value of the flag attribute designated by ATTR_KIND, or -1
    5523              :    if it is not present.  */
    5524              : 
    5525              : int
    5526     74153123 : get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
    5527              : {
    5528     74153123 :   dw_attr_node *a = get_AT (die, attr_kind);
    5529              : 
    5530     74153123 :   return a ? AT_flag (a) : 0;
    5531              : }
    5532              : 
    5533              : /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
    5534              :    if it is not present.  */
    5535              : 
    5536              : unsigned
    5537    440595566 : get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
    5538              : {
    5539    440595566 :   dw_attr_node *a = get_AT (die, attr_kind);
    5540              : 
    5541    440595566 :   return a ? AT_unsigned (a) : 0;
    5542              : }
    5543              : 
    5544              : dw_die_ref
    5545     46988642 : get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
    5546              : {
    5547     46988642 :   dw_attr_node *a = get_AT (die, attr_kind);
    5548              : 
    5549     46988642 :   return a ? AT_ref (a) : NULL;
    5550              : }
    5551              : 
    5552              : struct dwarf_file_data *
    5553     28068885 : get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
    5554              : {
    5555     28068885 :   dw_attr_node *a = get_AT (die, attr_kind);
    5556              : 
    5557     28068885 :   return a ? AT_file (a) : NULL;
    5558              : }
    5559              : 
    5560              : /* Return TRUE if the language is C.  */
    5561              : 
    5562              : static inline bool
    5563         6686 : is_c (void)
    5564              : {
    5565         6686 :   unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
    5566              : 
    5567         6686 :   return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_C99
    5568         6686 :           || lang == DW_LANG_C11 || lang == DW_LANG_ObjC);
    5569              : 
    5570              : 
    5571              : }
    5572              : 
    5573              : /* Return TRUE if the language is C++.  */
    5574              : 
    5575              : static inline bool
    5576     24509676 : is_cxx (void)
    5577              : {
    5578     24509676 :   unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
    5579              : 
    5580     24509676 :   return (lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus
    5581     24509676 :           || lang == DW_LANG_C_plus_plus_11 || lang == DW_LANG_C_plus_plus_14);
    5582              : }
    5583              : 
    5584              : /* Return TRUE if DECL was created by the C++ frontend.  */
    5585              : 
    5586              : static bool
    5587     22992677 : is_cxx (const_tree decl)
    5588              : {
    5589     22992677 :   if (in_lto_p)
    5590              :     {
    5591           16 :       const_tree context = get_ultimate_context (decl);
    5592           32 :       if (context && TRANSLATION_UNIT_LANGUAGE (context))
    5593           16 :         return startswith (TRANSLATION_UNIT_LANGUAGE (context), "GNU C++");
    5594              :     }
    5595     22992661 :   return is_cxx ();
    5596              : }
    5597              : 
    5598              : /* Return TRUE if the language is Fortran.  */
    5599              : 
    5600              : static inline bool
    5601    178602793 : is_fortran (void)
    5602              : {
    5603    178602793 :   unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
    5604              : 
    5605    178602793 :   return (lang == DW_LANG_Fortran77
    5606    178602793 :           || lang == DW_LANG_Fortran90
    5607    178602793 :           || lang == DW_LANG_Fortran95
    5608              :           || lang == DW_LANG_Fortran03
    5609    178602793 :           || lang == DW_LANG_Fortran08);
    5610              : }
    5611              : 
    5612              : static inline bool
    5613          109 : is_fortran (const_tree decl)
    5614              : {
    5615          109 :   if (in_lto_p)
    5616              :     {
    5617          109 :       const_tree context = get_ultimate_context (decl);
    5618          218 :       if (context && TRANSLATION_UNIT_LANGUAGE (context))
    5619          109 :         return (strncmp (TRANSLATION_UNIT_LANGUAGE (context),
    5620              :                          "GNU Fortran", 11) == 0
    5621          109 :                 || strcmp (TRANSLATION_UNIT_LANGUAGE (context),
    5622              :                            "GNU F77") == 0);
    5623              :     }
    5624            0 :   return is_fortran ();
    5625              : }
    5626              : 
    5627              : /* Return TRUE if the language is Rust.
    5628              :    Note, returns FALSE for dwarf_version < 5 && dwarf_strict. */
    5629              : 
    5630              : static inline bool
    5631        79863 : is_rust (void)
    5632              : {
    5633        79863 :   unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
    5634              : 
    5635        79863 :   return lang == DW_LANG_Rust;
    5636              : }
    5637              : 
    5638              : /* Return TRUE if the language is Ada.  */
    5639              : 
    5640              : static inline bool
    5641      2924183 : is_ada (void)
    5642              : {
    5643      2924183 :   unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
    5644              : 
    5645      2924183 :   return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
    5646              : }
    5647              : 
    5648              : /* Return TRUE if the language is D.  */
    5649              : 
    5650              : static inline bool
    5651     78715413 : is_dlang (void)
    5652              : {
    5653     78715413 :   unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
    5654              : 
    5655     78715413 :   return lang == DW_LANG_D;
    5656              : }
    5657              : 
    5658              : /* Remove the specified attribute if present.  Return TRUE if removal
    5659              :    was successful.  */
    5660              : 
    5661              : static bool
    5662     50180347 : remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
    5663              : {
    5664     50180347 :   dw_attr_node *a;
    5665     50180347 :   unsigned ix;
    5666              : 
    5667     50180347 :   if (! die)
    5668              :     return false;
    5669              : 
    5670    107181315 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    5671    106667201 :     if (a->dw_attr == attr_kind)
    5672              :       {
    5673     49666233 :         if (AT_class (a) == dw_val_class_str)
    5674          249 :           if (a->dw_attr_val.v.val_str->refcount)
    5675          249 :             a->dw_attr_val.v.val_str->refcount--;
    5676              : 
    5677              :         /* vec::ordered_remove should help reduce the number of abbrevs
    5678              :            that are needed.  */
    5679     49666233 :         die->die_attr->ordered_remove (ix);
    5680     49666233 :         return true;
    5681              :       }
    5682              :   return false;
    5683              : }
    5684              : 
    5685              : /* Remove CHILD from its parent.  PREV must have the property that
    5686              :    PREV->DIE_SIB == CHILD.  Does not alter CHILD.  */
    5687              : 
    5688              : static void
    5689      8166436 : remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
    5690              : {
    5691      8166436 :   gcc_assert (child->die_parent == prev->die_parent);
    5692      8166436 :   gcc_assert (prev->die_sib == child);
    5693      8166436 :   if (prev == child)
    5694              :     {
    5695        18569 :       gcc_assert (child->die_parent->die_child == child);
    5696              :       prev = NULL;
    5697              :     }
    5698              :   else
    5699      8147867 :     prev->die_sib = child->die_sib;
    5700      8166436 :   if (child->die_parent->die_child == child)
    5701       388884 :     child->die_parent->die_child = prev;
    5702      8166436 :   child->die_sib = NULL;
    5703      8166436 : }
    5704              : 
    5705              : /* Replace OLD_CHILD with NEW_CHILD.  PREV must have the property that
    5706              :    PREV->DIE_SIB == OLD_CHILD.  Does not alter OLD_CHILD.  */
    5707              : 
    5708              : static void
    5709          139 : replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
    5710              : {
    5711          139 :   dw_die_ref parent = old_child->die_parent;
    5712              : 
    5713          139 :   gcc_assert (parent == prev->die_parent);
    5714          139 :   gcc_assert (prev->die_sib == old_child);
    5715              : 
    5716          139 :   new_child->die_parent = parent;
    5717          139 :   if (prev == old_child)
    5718              :     {
    5719           19 :       gcc_assert (parent->die_child == old_child);
    5720           19 :       new_child->die_sib = new_child;
    5721              :     }
    5722              :   else
    5723              :     {
    5724          120 :       prev->die_sib = new_child;
    5725          120 :       new_child->die_sib = old_child->die_sib;
    5726              :     }
    5727          139 :   if (old_child->die_parent->die_child == old_child)
    5728           25 :     old_child->die_parent->die_child = new_child;
    5729          139 :   old_child->die_sib = NULL;
    5730          139 : }
    5731              : 
    5732              : /* Move all children from OLD_PARENT to NEW_PARENT.  */
    5733              : 
    5734              : static void
    5735           76 : move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
    5736              : {
    5737           76 :   dw_die_ref c;
    5738           76 :   new_parent->die_child = old_parent->die_child;
    5739           76 :   old_parent->die_child = NULL;
    5740           85 :   FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
    5741            0 : }
    5742              : 
    5743              : /* Remove child DIE whose die_tag is TAG.  Do nothing if no child
    5744              :    matches TAG.  */
    5745              : 
    5746              : static void
    5747        50787 : remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
    5748              : {
    5749        50787 :   dw_die_ref c;
    5750              : 
    5751        50787 :   c = die->die_child;
    5752        50787 :   if (c) do {
    5753        87756 :     dw_die_ref prev = c;
    5754        87756 :     c = c->die_sib;
    5755       160273 :     while (c->die_tag == tag)
    5756              :       {
    5757        91085 :         remove_child_with_prev (c, prev);
    5758        91085 :         c->die_parent = NULL;
    5759              :         /* Might have removed every child.  */
    5760        91085 :         if (die->die_child == NULL)
    5761              :           return;
    5762        72517 :         c = prev->die_sib;
    5763              :       }
    5764        69188 :   } while (c != die->die_child);
    5765              : }
    5766              : 
    5767              : /* Add a CHILD_DIE as the last child of DIE.  */
    5768              : 
    5769              : static void
    5770    640605967 : add_child_die (dw_die_ref die, dw_die_ref child_die)
    5771              : {
    5772              :   /* FIXME this should probably be an assert.  */
    5773    640605967 :   if (! die || ! child_die)
    5774              :     return;
    5775    640463782 :   gcc_assert (die != child_die);
    5776              : 
    5777    640463782 :   child_die->die_parent = die;
    5778    640463782 :   if (die->die_child)
    5779              :     {
    5780    483673024 :       child_die->die_sib = die->die_child->die_sib;
    5781    483673024 :       die->die_child->die_sib = child_die;
    5782              :     }
    5783              :   else
    5784    156790758 :     child_die->die_sib = child_die;
    5785    640463782 :   die->die_child = child_die;
    5786              : }
    5787              : 
    5788              : /* Like add_child_die, but put CHILD_DIE after AFTER_DIE.  */
    5789              : 
    5790              : static void
    5791     13111409 : add_child_die_after (dw_die_ref die, dw_die_ref child_die,
    5792              :                      dw_die_ref after_die)
    5793              : {
    5794     13111409 :   gcc_assert (die
    5795              :               && child_die
    5796              :               && after_die
    5797              :               && die->die_child
    5798              :               && die != child_die);
    5799              : 
    5800     13111409 :   child_die->die_parent = die;
    5801     13111409 :   child_die->die_sib = after_die->die_sib;
    5802     13111409 :   after_die->die_sib = child_die;
    5803     13111409 :   if (die->die_child == after_die)
    5804      7819733 :     die->die_child = child_die;
    5805     13111409 : }
    5806              : 
    5807              : /* Unassociate CHILD from its parent, and make its parent be
    5808              :    NEW_PARENT.  */
    5809              : 
    5810              : static void
    5811      8068529 : reparent_child (dw_die_ref child, dw_die_ref new_parent)
    5812              : {
    5813      8068529 :   for (dw_die_ref p = child->die_parent->die_child; ; p = p->die_sib)
    5814   6975268538 :     if (p->die_sib == child)
    5815              :       {
    5816      8068529 :         remove_child_with_prev (child, p);
    5817      8068529 :         break;
    5818              :       }
    5819      8068529 :   add_child_die (new_parent, child);
    5820      8068529 : }
    5821              : 
    5822              : /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
    5823              :    is the specification, to the end of PARENT's list of children.
    5824              :    This is done by removing and re-adding it.  */
    5825              : 
    5826              : static void
    5827        18748 : splice_child_die (dw_die_ref parent, dw_die_ref child)
    5828              : {
    5829              :   /* We want the declaration DIE from inside the class, not the
    5830              :      specification DIE at toplevel.  */
    5831        18748 :   if (child->die_parent != parent)
    5832              :     {
    5833          701 :       dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
    5834              : 
    5835          701 :       if (tmp)
    5836        18748 :         child = tmp;
    5837              :     }
    5838              : 
    5839        18748 :   gcc_assert (child->die_parent == parent
    5840              :               || (child->die_parent
    5841              :                   == get_AT_ref (parent, DW_AT_specification)));
    5842              : 
    5843        18748 :   reparent_child (child, parent);
    5844        18748 : }
    5845              : 
    5846              : /* Create and return a new die with TAG_VALUE as tag.  */
    5847              : 
    5848              : dw_die_ref
    5849    645596220 : new_die_raw (enum dwarf_tag tag_value)
    5850              : {
    5851    645596220 :   dw_die_ref die = ggc_cleared_alloc<die_node> ();
    5852    645596220 :   die->die_tag = tag_value;
    5853    645596220 :   return die;
    5854              : }
    5855              : 
    5856              : /* Create and return a new die with a parent of PARENT_DIE.  If
    5857              :    PARENT_DIE is NULL, the new DIE is placed in limbo and an
    5858              :    associated tree T must be supplied to determine parenthood
    5859              :    later.  */
    5860              : 
    5861              : static inline dw_die_ref
    5862    631840045 : new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
    5863              : {
    5864    631840045 :   dw_die_ref die = new_die_raw (tag_value);
    5865              : 
    5866    631840045 :   if (parent_die != NULL)
    5867    631622965 :     add_child_die (parent_die, die);
    5868              :   else
    5869              :     {
    5870       217080 :       limbo_die_node *limbo_node;
    5871              : 
    5872              :       /* No DIEs created after early dwarf should end up in limbo,
    5873              :          because the limbo list should not persist past LTO
    5874              :          streaming.  */
    5875       217080 :       if (tag_value != DW_TAG_compile_unit
    5876              :           /* These are allowed because they're generated while
    5877              :              breaking out COMDAT units late.  */
    5878       217080 :           && tag_value != DW_TAG_type_unit
    5879       158545 :           && tag_value != DW_TAG_skeleton_unit
    5880       158545 :           && !early_dwarf
    5881              :           /* Allow nested functions to live in limbo because they will
    5882              :              only temporarily live there, as decls_for_scope will fix
    5883              :              them up.  */
    5884         3125 :           && (TREE_CODE (t) != FUNCTION_DECL
    5885            0 :               || !decl_function_context (t))
    5886              :           /* Same as nested functions above but for types.  Types that
    5887              :              are local to a function will be fixed in
    5888              :              decls_for_scope.  */
    5889         3125 :           && (!RECORD_OR_UNION_TYPE_P (t)
    5890            2 :               || !TYPE_CONTEXT (t)
    5891            2 :               || TREE_CODE (TYPE_CONTEXT (t)) != FUNCTION_DECL)
    5892              :           /* FIXME debug-early: Allow late limbo DIE creation for LTO,
    5893              :              especially in the ltrans stage, but once we implement LTO
    5894              :              dwarf streaming, we should remove this exception.  */
    5895       220203 :           && !in_lto_p)
    5896              :         {
    5897            0 :           fprintf (stderr, "symbol ended up in limbo too late:");
    5898            0 :           debug_generic_stmt (t);
    5899            0 :           gcc_unreachable ();
    5900              :         }
    5901              : 
    5902       217080 :       limbo_node = ggc_cleared_alloc<limbo_die_node> ();
    5903       217080 :       limbo_node->die = die;
    5904       217080 :       limbo_node->created_for = t;
    5905       217080 :       limbo_node->next = limbo_die_list;
    5906       217080 :       limbo_die_list = limbo_node;
    5907              :     }
    5908              : 
    5909    631840045 :   return die;
    5910              : }
    5911              : 
    5912              : /* Return the DIE associated with the given type specifier.  */
    5913              : 
    5914              : dw_die_ref
    5915   1744471244 : lookup_type_die (tree type)
    5916              : {
    5917   1744471244 :   dw_die_ref die = TYPE_SYMTAB_DIE (type);
    5918   1744471244 :   if (die && die->removed)
    5919              :     {
    5920         2688 :       TYPE_SYMTAB_DIE (type) = NULL;
    5921         2688 :       TREE_ASM_WRITTEN (type) = 0;
    5922         2688 :       return NULL;
    5923              :     }
    5924              :   return die;
    5925              : }
    5926              : 
    5927              : /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
    5928              :    anonymous type named by the typedef TYPE_DIE, return the DIE of the
    5929              :    anonymous type instead the one of the naming typedef.  */
    5930              : 
    5931              : static inline dw_die_ref
    5932     21345647 : strip_naming_typedef (tree type, dw_die_ref type_die)
    5933              : {
    5934     21345647 :   if (type
    5935     21345647 :       && TREE_CODE (type) == RECORD_TYPE
    5936     21191048 :       && type_die
    5937     21191048 :       && type_die->die_tag == DW_TAG_typedef
    5938     21345669 :       && is_naming_typedef_decl (TYPE_NAME (type)))
    5939           22 :     type_die = get_AT_ref (type_die, DW_AT_type);
    5940     21345647 :   return type_die;
    5941              : }
    5942              : 
    5943              : /* Like lookup_type_die, but if type is an anonymous type named by a
    5944              :    typedef[1], return the DIE of the anonymous type instead the one of
    5945              :    the naming typedef.  This is because in gen_typedef_die, we did
    5946              :    equate the anonymous struct named by the typedef with the DIE of
    5947              :    the naming typedef. So by default, lookup_type_die on an anonymous
    5948              :    struct yields the DIE of the naming typedef.
    5949              : 
    5950              :    [1]: Read the comment of is_naming_typedef_decl to learn about what
    5951              :    a naming typedef is.  */
    5952              : 
    5953              : static inline dw_die_ref
    5954       131879 : lookup_type_die_strip_naming_typedef (tree type)
    5955              : {
    5956       131879 :   dw_die_ref die = lookup_type_die (type);
    5957       131879 :   return strip_naming_typedef (type, die);
    5958              : }
    5959              : 
    5960              : /* Equate a DIE to a given type specifier.  */
    5961              : 
    5962              : static inline void
    5963    149291149 : equate_type_number_to_die (tree type, dw_die_ref type_die)
    5964              : {
    5965    149291149 :   TYPE_SYMTAB_DIE (type) = type_die;
    5966    149291149 : }
    5967              : 
    5968              : static dw_die_ref maybe_create_die_with_external_ref (tree);
    5969              : struct GTY(()) sym_off_pair
    5970              : {
    5971              :   const char *sym;
    5972              :   unsigned HOST_WIDE_INT off;
    5973              : };
    5974              : static GTY(()) hash_map<tree, sym_off_pair> *external_die_map;
    5975              : 
    5976              : /* Returns a hash value for X (which really is a die_struct).  */
    5977              : 
    5978              : inline hashval_t
    5979  12735769731 : decl_die_hasher::hash (die_node *x)
    5980              : {
    5981  12735769731 :   return (hashval_t) x->decl_id;
    5982              : }
    5983              : 
    5984              : /* Return true if decl_id of die_struct X is the same as UID of decl *Y.  */
    5985              : 
    5986              : inline bool
    5987  14594455649 : decl_die_hasher::equal (die_node *x, tree y)
    5988              : {
    5989  14594455649 :   return (x->decl_id == DECL_UID (y));
    5990              : }
    5991              : 
    5992              : /* Return the DIE associated with a given declaration.  */
    5993              : 
    5994              : dw_die_ref
    5995   1423581995 : lookup_decl_die (tree decl)
    5996              : {
    5997   1423581995 :   dw_die_ref *die = decl_die_table->find_slot_with_hash (decl, DECL_UID (decl),
    5998              :                                                          NO_INSERT);
    5999   1423581995 :   if (!die)
    6000              :     {
    6001    664083015 :       if (in_lto_p)
    6002        39293 :         return maybe_create_die_with_external_ref (decl);
    6003              :       return NULL;
    6004              :     }
    6005    759498980 :   if ((*die)->removed)
    6006              :     {
    6007         1013 :       decl_die_table->clear_slot (die);
    6008         1013 :       return NULL;
    6009              :     }
    6010              :   return *die;
    6011              : }
    6012              : 
    6013              : 
    6014              : /* Return the DIE associated with BLOCK.  */
    6015              : 
    6016              : static inline dw_die_ref
    6017     19440683 : lookup_block_die (tree block)
    6018              : {
    6019     19440683 :   dw_die_ref die = BLOCK_DIE (block);
    6020     19440683 :   if (!die && in_lto_p)
    6021         9476 :     return maybe_create_die_with_external_ref (block);
    6022              :   return die;
    6023              : }
    6024              : 
    6025              : /* Associate DIE with BLOCK.  */
    6026              : 
    6027              : static inline void
    6028      7943245 : equate_block_to_die (tree block, dw_die_ref die)
    6029              : {
    6030      7943245 :   BLOCK_DIE (block) = die;
    6031      7943245 : }
    6032              : #undef BLOCK_DIE
    6033              : 
    6034              : 
    6035              : /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
    6036              :    style reference.  Return true if we found one referring to a DIE for
    6037              :    DECL, otherwise return false.  */
    6038              : 
    6039              : static bool
    6040       140346 : dwarf2out_die_ref_for_decl (tree decl, const char **sym,
    6041              :                             unsigned HOST_WIDE_INT *off)
    6042              : {
    6043       140346 :   dw_die_ref die;
    6044              : 
    6045       140346 :   if (in_lto_p)
    6046              :     {
    6047              :       /* During WPA stage and incremental linking we use a hash-map
    6048              :          to store the decl <-> label + offset map.  */
    6049        27644 :       if (!external_die_map)
    6050              :         return false;
    6051        26359 :       sym_off_pair *desc = external_die_map->get (decl);
    6052        26359 :       if (!desc)
    6053              :         return false;
    6054        11226 :       *sym = desc->sym;
    6055        11226 :       *off = desc->off;
    6056        11226 :       return true;
    6057              :     }
    6058              : 
    6059       112702 :   if (TREE_CODE (decl) == BLOCK)
    6060        27415 :     die = lookup_block_die (decl);
    6061              :   else
    6062        85287 :     die = lookup_decl_die (decl);
    6063       112702 :   if (!die)
    6064              :     return false;
    6065              : 
    6066              :   /* Similar to get_ref_die_offset_label, but using the "correct"
    6067              :      label.  */
    6068        38346 :   *off = die->die_offset;
    6069       101121 :   while (die->die_parent)
    6070              :     die = die->die_parent;
    6071              :   /* For the containing CU DIE we compute a die_symbol in
    6072              :      compute_comp_unit_symbol.  */
    6073        38346 :   if (die->die_tag == DW_TAG_compile_unit)
    6074              :     {
    6075        38343 :       gcc_assert (die->die_id.die_symbol != NULL);
    6076        38343 :       *sym = die->die_id.die_symbol;
    6077        38343 :       return true;
    6078              :     }
    6079              :   /* While we can gracefully handle running into say a type unit
    6080              :      we don't really want and consider this a bug.  */
    6081            3 :   if (flag_checking)
    6082            0 :     gcc_unreachable ();
    6083              :   return false;
    6084              : }
    6085              : 
    6086              : /* Add a reference of kind ATTR_KIND to a DIE at SYMBOL + OFFSET to DIE.  */
    6087              : 
    6088              : static void
    6089        29493 : add_AT_external_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind,
    6090              :                          const char *symbol, HOST_WIDE_INT offset)
    6091              : {
    6092              :   /* Create a fake DIE that contains the reference.  Don't use
    6093              :      new_die because we don't want to end up in the limbo list.  */
    6094              :   /* ???  We probably want to share these, thus put a ref to the DIE
    6095              :      we create here to the external_die_map entry.  */
    6096        29493 :   dw_die_ref ref = new_die_raw (die->die_tag);
    6097        29493 :   ref->die_id.die_symbol = symbol;
    6098        29493 :   ref->die_offset = offset;
    6099        29493 :   ref->with_offset = 1;
    6100        29493 :   add_AT_die_ref (die, attr_kind, ref);
    6101        29493 : }
    6102              : 
    6103              : /* Create a DIE for DECL if required and add a reference to a DIE
    6104              :    at SYMBOL + OFFSET which contains attributes dumped early.  */
    6105              : 
    6106              : static void
    6107        44421 : dwarf2out_register_external_die (tree decl, const char *sym,
    6108              :                                  unsigned HOST_WIDE_INT off)
    6109              : {
    6110        44421 :   if (debug_info_level == DINFO_LEVEL_NONE)
    6111            0 :     return;
    6112              : 
    6113        44421 :   if (!external_die_map)
    6114         1240 :     external_die_map = hash_map<tree, sym_off_pair>::create_ggc (1000);
    6115        44421 :   gcc_checking_assert (!external_die_map->get (decl));
    6116        44421 :   sym_off_pair p = { IDENTIFIER_POINTER (get_identifier (sym)), off };
    6117        44421 :   external_die_map->put (decl, p);
    6118              : }
    6119              : 
    6120              : /* If we have a registered external DIE for DECL return a new DIE for
    6121              :    the concrete instance with an appropriate abstract origin.  */
    6122              : 
    6123              : static dw_die_ref
    6124        48769 : maybe_create_die_with_external_ref (tree decl)
    6125              : {
    6126        48769 :   if (!external_die_map)
    6127              :     return NULL;
    6128        48611 :   sym_off_pair *desc = external_die_map->get (decl);
    6129        48611 :   if (!desc)
    6130              :     return NULL;
    6131              : 
    6132        20499 :   const char *sym = desc->sym;
    6133        20499 :   unsigned HOST_WIDE_INT off = desc->off;
    6134        20499 :   external_die_map->remove (decl);
    6135              : 
    6136        20499 :   in_lto_p = false;
    6137        20499 :   dw_die_ref die = (TREE_CODE (decl) == BLOCK
    6138        20499 :                     ? lookup_block_die (decl) : lookup_decl_die (decl));
    6139        20499 :   gcc_assert (!die);
    6140        20499 :   in_lto_p = true;
    6141              : 
    6142        20499 :   tree ctx;
    6143        20499 :   dw_die_ref parent = NULL;
    6144              :   /* Need to lookup a DIE for the decls context - the containing
    6145              :      function or translation unit.  */
    6146        20499 :   if (TREE_CODE (decl) == BLOCK)
    6147              :     {
    6148          436 :       ctx = BLOCK_SUPERCONTEXT (decl);
    6149              :       /* ???  We do not output DIEs for all scopes thus skip as
    6150              :          many DIEs as needed.  */
    6151          436 :       while (TREE_CODE (ctx) == BLOCK
    6152         1111 :              && !lookup_block_die (ctx))
    6153          675 :         ctx = BLOCK_SUPERCONTEXT (ctx);
    6154              :     }
    6155              :   else
    6156        20063 :     ctx = DECL_CONTEXT (decl);
    6157              :   /* Peel types in the context stack.  */
    6158        21027 :   while (ctx && TYPE_P (ctx))
    6159          528 :     ctx = TYPE_CONTEXT (ctx);
    6160              :   /* Likewise namespaces in case we do not want to emit DIEs for them.  */
    6161        20499 :   if (debug_info_level <= DINFO_LEVEL_TERSE)
    6162          998 :     while (ctx && TREE_CODE (ctx) == NAMESPACE_DECL)
    6163            5 :       ctx = DECL_CONTEXT (ctx);
    6164        20499 :   if (ctx)
    6165              :     {
    6166        20354 :       if (TREE_CODE (ctx) == BLOCK)
    6167           64 :         parent = lookup_block_die (ctx);
    6168        20290 :       else if (TREE_CODE (ctx) == TRANSLATION_UNIT_DECL
    6169              :                /* Keep the 1:1 association during WPA.  */
    6170         3758 :                && !flag_wpa
    6171         3758 :                && flag_incremental_link != INCREMENTAL_LINK_LTO)
    6172              :         /* Otherwise all late annotations go to the main CU which
    6173              :            imports the original CUs.  */
    6174         3758 :         parent = comp_unit_die ();
    6175        16532 :       else if (TREE_CODE (ctx) == FUNCTION_DECL
    6176        12284 :                && TREE_CODE (decl) != FUNCTION_DECL
    6177              :                && TREE_CODE (decl) != PARM_DECL
    6178              :                && TREE_CODE (decl) != RESULT_DECL
    6179              :                && TREE_CODE (decl) != BLOCK)
    6180              :         /* Leave function local entities parent determination to when
    6181              :            we process scope vars.  */
    6182              :         ;
    6183              :       else
    6184        13409 :         parent = lookup_decl_die (ctx);
    6185              :     }
    6186              :   else
    6187              :     /* In some cases the FEs fail to set DECL_CONTEXT properly.
    6188              :        Handle this case gracefully by globalizing stuff.  */
    6189          145 :     parent = comp_unit_die ();
    6190              :   /* Create a DIE "stub".  */
    6191        20499 :   switch (TREE_CODE (decl))
    6192              :     {
    6193          145 :     case TRANSLATION_UNIT_DECL:
    6194          145 :       {
    6195          145 :         die = comp_unit_die ();
    6196              :         /* We re-target all CU decls to the LTRANS CU DIE, so no need
    6197              :            to create a DIE for the original CUs.  */
    6198          145 :         return die;
    6199              :       }
    6200          109 :     case NAMESPACE_DECL:
    6201          109 :       if (is_fortran (decl))
    6202            6 :         die = new_die (DW_TAG_module, parent, decl);
    6203              :       else
    6204          103 :         die = new_die (DW_TAG_namespace, parent, decl);
    6205              :       break;
    6206         7223 :     case FUNCTION_DECL:
    6207         7223 :       die = new_die (DW_TAG_subprogram, parent, decl);
    6208         7223 :       break;
    6209         3803 :     case VAR_DECL:
    6210         3803 :       die = new_die (DW_TAG_variable, parent, decl);
    6211         3803 :       break;
    6212            0 :     case RESULT_DECL:
    6213            0 :       die = new_die (DW_TAG_variable, parent, decl);
    6214            0 :       break;
    6215         8748 :     case PARM_DECL:
    6216         8748 :       die = new_die (DW_TAG_formal_parameter, parent, decl);
    6217         8748 :       break;
    6218            0 :     case CONST_DECL:
    6219            0 :       die = new_die (DW_TAG_constant, parent, decl);
    6220            0 :       break;
    6221           35 :     case LABEL_DECL:
    6222           35 :       die = new_die (DW_TAG_label, parent, decl);
    6223           35 :       break;
    6224          436 :     case BLOCK:
    6225          436 :       die = new_die (DW_TAG_lexical_block, parent, decl);
    6226          436 :       break;
    6227            0 :     default:
    6228            0 :       gcc_unreachable ();
    6229              :     }
    6230        20354 :   if (TREE_CODE (decl) == BLOCK)
    6231          436 :     equate_block_to_die (decl, die);
    6232              :   else
    6233        19918 :     equate_decl_number_to_die (decl, die);
    6234              : 
    6235        20354 :   add_desc_attribute (die, decl);
    6236              : 
    6237              :   /* Add a reference to the DIE providing early debug at $sym + off.  */
    6238        20354 :   add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
    6239              : 
    6240        20354 :   return die;
    6241              : }
    6242              : 
    6243              : /* Returns a hash value for X (which really is a var_loc_list).  */
    6244              : 
    6245              : inline hashval_t
    6246    436362552 : decl_loc_hasher::hash (var_loc_list *x)
    6247              : {
    6248    436362552 :   return (hashval_t) x->decl_id;
    6249              : }
    6250              : 
    6251              : /* Return true if decl_id of var_loc_list X is the same as
    6252              :    UID of decl *Y.  */
    6253              : 
    6254              : inline bool
    6255    529343707 : decl_loc_hasher::equal (var_loc_list *x, const_tree y)
    6256              : {
    6257    529343707 :   return (x->decl_id == DECL_UID (y));
    6258              : }
    6259              : 
    6260              : /* Return the var_loc list associated with a given declaration.  */
    6261              : 
    6262              : static inline var_loc_list *
    6263     34529408 : lookup_decl_loc (const_tree decl)
    6264              : {
    6265     34529408 :   if (!decl_loc_table)
    6266              :     return NULL;
    6267     34529408 :   return decl_loc_table->find_with_hash (decl, DECL_UID (decl));
    6268              : }
    6269              : 
    6270              : /* Returns a hash value for X (which really is a cached_dw_loc_list_list).  */
    6271              : 
    6272              : inline hashval_t
    6273            0 : dw_loc_list_hasher::hash (cached_dw_loc_list *x)
    6274              : {
    6275            0 :   return (hashval_t) x->decl_id;
    6276              : }
    6277              : 
    6278              : /* Return true if decl_id of cached_dw_loc_list X is the same as
    6279              :    UID of decl *Y.  */
    6280              : 
    6281              : inline bool
    6282            0 : dw_loc_list_hasher::equal (cached_dw_loc_list *x, const_tree y)
    6283              : {
    6284            0 :   return (x->decl_id == DECL_UID (y));
    6285              : }
    6286              : 
    6287              : /* Equate a DIE to a particular declaration.  */
    6288              : 
    6289              : static void
    6290    207226458 : equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
    6291              : {
    6292    207226458 :   unsigned int decl_id = DECL_UID (decl);
    6293              : 
    6294    207226458 :   *decl_die_table->find_slot_with_hash (decl, decl_id, INSERT) = decl_die;
    6295    207226458 :   decl_die->decl_id = decl_id;
    6296    207226458 : }
    6297              : 
    6298              : /* Return how many bits covers PIECE EXPR_LIST.  */
    6299              : 
    6300              : static HOST_WIDE_INT
    6301     32317652 : decl_piece_bitsize (rtx piece)
    6302              : {
    6303     32317652 :   int ret = (int) GET_MODE (piece);
    6304     32317652 :   if (ret)
    6305     32038570 :     return ret;
    6306       279082 :   gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
    6307              :               && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
    6308       279082 :   return INTVAL (XEXP (XEXP (piece, 0), 0));
    6309              : }
    6310              : 
    6311              : /* Return pointer to the location of location note in PIECE EXPR_LIST.  */
    6312              : 
    6313              : static rtx *
    6314     16730844 : decl_piece_varloc_ptr (rtx piece)
    6315              : {
    6316            0 :   if ((int) GET_MODE (piece))
    6317     16607818 :     return &XEXP (piece, 0);
    6318              :   else
    6319       123026 :     return &XEXP (XEXP (piece, 0), 1);
    6320              : }
    6321              : 
    6322              : /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
    6323              :    Next is the chain of following piece nodes.  */
    6324              : 
    6325              : static rtx_expr_list *
    6326      7529236 : decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
    6327              : {
    6328      7529236 :   if (bitsize > 0 && bitsize <= (int) MAX_MACHINE_MODE)
    6329      7450408 :     return alloc_EXPR_LIST (bitsize, loc_note, next);
    6330              :   else
    6331        78828 :     return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
    6332              :                                                GEN_INT (bitsize),
    6333        78828 :                                                loc_note), next);
    6334              : }
    6335              : 
    6336              : /* Return rtx that should be stored into loc field for
    6337              :    LOC_NOTE and BITPOS/BITSIZE.  */
    6338              : 
    6339              : static rtx
    6340     50137640 : construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
    6341              :                       HOST_WIDE_INT bitsize)
    6342              : {
    6343     50137640 :   if (bitsize != -1)
    6344              :     {
    6345       614482 :       loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
    6346       614482 :       if (bitpos != 0)
    6347        88693 :         loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
    6348              :     }
    6349     50137640 :   return loc_note;
    6350              : }
    6351              : 
    6352              : /* This function either modifies location piece list *DEST in
    6353              :    place (if SRC and INNER is NULL), or copies location piece list
    6354              :    *SRC to *DEST while modifying it.  Location BITPOS is modified
    6355              :    to contain LOC_NOTE, any pieces overlapping it are removed resp.
    6356              :    not copied and if needed some padding around it is added.
    6357              :    When modifying in place, DEST should point to EXPR_LIST where
    6358              :    earlier pieces cover PIECE_BITPOS bits, when copying SRC points
    6359              :    to the start of the whole list and INNER points to the EXPR_LIST
    6360              :    where earlier pieces cover PIECE_BITPOS bits.  */
    6361              : 
    6362              : static void
    6363      5754109 : adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
    6364              :                    HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
    6365              :                    HOST_WIDE_INT bitsize, rtx loc_note)
    6366              : {
    6367      5754109 :   HOST_WIDE_INT diff;
    6368      5754109 :   bool copy = inner != NULL;
    6369              : 
    6370      5754109 :   if (copy)
    6371              :     {
    6372              :       /* First copy all nodes preceding the current bitpos.  */
    6373      4246036 :       while (src != inner)
    6374              :         {
    6375      2639638 :           *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
    6376              :                                    decl_piece_bitsize (*src), NULL_RTX);
    6377      1319819 :           dest = &XEXP (*dest, 1);
    6378      1319819 :           src = &XEXP (*src, 1);
    6379              :         }
    6380              :     }
    6381              :   /* Add padding if needed.  */
    6382      5754109 :   if (bitpos != piece_bitpos)
    6383              :     {
    6384        18472 :       *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
    6385              :                                copy ? NULL_RTX : *dest);
    6386        18472 :       dest = &XEXP (*dest, 1);
    6387              :     }
    6388      5735637 :   else if (*dest && decl_piece_bitsize (*dest) == bitsize)
    6389              :     {
    6390      2478495 :       gcc_assert (!copy);
    6391              :       /* A piece with correct bitpos and bitsize already exist,
    6392              :          just update the location for it and return.  */
    6393      2478495 :       *decl_piece_varloc_ptr (*dest) = loc_note;
    6394      2478495 :       return;
    6395              :     }
    6396              :   /* Add the piece that changed.  */
    6397      3275614 :   *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
    6398      3275614 :   dest = &XEXP (*dest, 1);
    6399              :   /* Skip over pieces that overlap it.  */
    6400      3275614 :   diff = bitpos - piece_bitpos + bitsize;
    6401      3275614 :   if (!copy)
    6402       349397 :     src = dest;
    6403      6183206 :   while (diff > 0 && *src)
    6404              :     {
    6405      2907592 :       rtx piece = *src;
    6406      2907592 :       diff -= decl_piece_bitsize (piece);
    6407      2907592 :       if (copy)
    6408      2896408 :         src = &XEXP (piece, 1);
    6409              :       else
    6410              :         {
    6411        11184 :           *src = XEXP (piece, 1);
    6412        11184 :           free_EXPR_LIST_node (piece);
    6413              :         }
    6414              :     }
    6415              :   /* Add padding if needed.  */
    6416      3275614 :   if (diff < 0 && *src)
    6417              :     {
    6418         8392 :       if (!copy)
    6419         7072 :         dest = src;
    6420         8392 :       *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
    6421         8392 :       dest = &XEXP (*dest, 1);
    6422              :     }
    6423      3275614 :   if (!copy)
    6424              :     return;
    6425              :   /* Finally copy all nodes following it.  */
    6426      5129981 :   while (*src)
    6427              :     {
    6428      4407528 :       *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
    6429              :                                decl_piece_bitsize (*src), NULL_RTX);
    6430      2203764 :       dest = &XEXP (*dest, 1);
    6431      2203764 :       src = &XEXP (*src, 1);
    6432              :     }
    6433              : }
    6434              : 
    6435              : /* Add a variable location node to the linked list for DECL.  */
    6436              : 
    6437              : static struct var_loc_node *
    6438     67242269 : add_var_loc_to_decl (tree decl, rtx loc_note, const char *label, var_loc_view view)
    6439              : {
    6440     67242269 :   unsigned int decl_id;
    6441     67242269 :   var_loc_list *temp;
    6442     67242269 :   struct var_loc_node *loc = NULL;
    6443     67242269 :   HOST_WIDE_INT bitsize = -1, bitpos = -1;
    6444              : 
    6445     67242269 :   if (VAR_P (decl) && DECL_HAS_DEBUG_EXPR_P (decl))
    6446              :     {
    6447      7846206 :       tree realdecl = DECL_DEBUG_EXPR (decl);
    6448      7846206 :       if (handled_component_p (realdecl)
    6449       952663 :           || (TREE_CODE (realdecl) == MEM_REF
    6450       952663 :               && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
    6451              :         {
    6452      7846206 :           bool reverse;
    6453      7846206 :           tree innerdecl = get_ref_base_and_extent_hwi (realdecl, &bitpos,
    6454              :                                                         &bitsize, &reverse);
    6455      7846206 :           if (!innerdecl
    6456      7846206 :               || !DECL_P (innerdecl)
    6457      7846206 :               || DECL_IGNORED_P (innerdecl)
    6458      7846206 :               || TREE_STATIC (innerdecl)
    6459      7846206 :               || bitsize == 0
    6460     15692412 :               || bitpos + bitsize > 256)
    6461            0 :             return NULL;
    6462      7846206 :           decl = innerdecl;
    6463              :         }
    6464              :     }
    6465              : 
    6466     67242269 :   decl_id = DECL_UID (decl);
    6467     67242269 :   var_loc_list **slot
    6468     67242269 :     = decl_loc_table->find_slot_with_hash (decl, decl_id, INSERT);
    6469     67242269 :   if (*slot == NULL)
    6470              :     {
    6471     14766836 :       temp = ggc_cleared_alloc<var_loc_list> ();
    6472     14766836 :       temp->decl_id = decl_id;
    6473     14766836 :       *slot = temp;
    6474              :     }
    6475              :   else
    6476              :     temp = *slot;
    6477              : 
    6478              :   /* For PARM_DECLs try to keep around the original incoming value,
    6479              :      even if that means we'll emit a zero-range .debug_loc entry.  */
    6480     67242269 :   if (temp->last
    6481     52475433 :       && temp->first == temp->last
    6482     24288674 :       && TREE_CODE (decl) == PARM_DECL
    6483      1033421 :       && NOTE_P (temp->first->loc)
    6484       994673 :       && NOTE_VAR_LOCATION_DECL (temp->first->loc) == decl
    6485       994673 :       && DECL_INCOMING_RTL (decl)
    6486       994673 :       && NOTE_VAR_LOCATION_LOC (temp->first->loc)
    6487       993962 :       && GET_CODE (NOTE_VAR_LOCATION_LOC (temp->first->loc))
    6488       993962 :          == GET_CODE (DECL_INCOMING_RTL (decl))
    6489       993903 :       && prev_real_insn (as_a<rtx_insn *> (temp->first->loc)) == NULL_RTX
    6490     68236164 :       && (bitsize != -1
    6491       993771 :           || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->first->loc),
    6492       993771 :                            NOTE_VAR_LOCATION_LOC (loc_note))
    6493       408342 :           || (NOTE_VAR_LOCATION_STATUS (temp->first->loc)
    6494       408342 :               != NOTE_VAR_LOCATION_STATUS (loc_note))))
    6495              :     {
    6496       585553 :       loc = ggc_cleared_alloc<var_loc_node> ();
    6497       585553 :       temp->first->next = loc;
    6498       585553 :       temp->last = loc;
    6499       585553 :       loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
    6500              :     }
    6501     66656716 :   else if (temp->last)
    6502              :     {
    6503     51889880 :       struct var_loc_node *last = temp->last, *unused = NULL;
    6504     51889880 :       rtx *piece_loc = NULL, last_loc_note;
    6505     51889880 :       HOST_WIDE_INT piece_bitpos = 0;
    6506     51889880 :       if (last->next)
    6507              :         {
    6508     34315279 :           last = last->next;
    6509     34315279 :           gcc_assert (last->next == NULL);
    6510              :         }
    6511     51889880 :       if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
    6512              :         {
    6513      7231724 :           piece_loc = &last->loc;
    6514     12670722 :           do
    6515              :             {
    6516     12670722 :               HOST_WIDE_INT cur_bitsize = decl_piece_bitsize (*piece_loc);
    6517     12670722 :               if (piece_bitpos + cur_bitsize > bitpos)
    6518              :                 break;
    6519      5807446 :               piece_bitpos += cur_bitsize;
    6520      5807446 :               piece_loc = &XEXP (*piece_loc, 1);
    6521              :             }
    6522      5807446 :           while (*piece_loc);
    6523              :         }
    6524              :       /* TEMP->LAST here is either pointer to the last but one or
    6525              :          last element in the chained list, LAST is pointer to the
    6526              :          last element.  */
    6527     51889880 :       if (label && strcmp (last->label, label) == 0 && last->view == view)
    6528              :         {
    6529              :           /* For SRA optimized variables if there weren't any real
    6530              :              insns since last note, just modify the last node.  */
    6531      5577183 :           if (piece_loc != NULL)
    6532              :             {
    6533      2827892 :               adjust_piece_list (piece_loc, NULL, NULL,
    6534              :                                  bitpos, piece_bitpos, bitsize, loc_note);
    6535      2827892 :               return NULL;
    6536              :             }
    6537              :           /* If the last note doesn't cover any instructions, remove it.  */
    6538      2749291 :           if (temp->last != last)
    6539              :             {
    6540      2583550 :               temp->last->next = NULL;
    6541      2583550 :               unused = last;
    6542      2583550 :               last = temp->last;
    6543      2583550 :               gcc_assert (strcmp (last->label, label) != 0 || last->view != view);
    6544              :             }
    6545              :           else
    6546              :             {
    6547       165741 :               gcc_assert (temp->first == temp->last
    6548              :                           || (temp->first->next == temp->last
    6549              :                               && TREE_CODE (decl) == PARM_DECL));
    6550       165741 :               memset (temp->last, '\0', sizeof (*temp->last));
    6551       165741 :               temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
    6552       165741 :               return temp->last;
    6553              :             }
    6554              :         }
    6555     48896247 :       if (bitsize == -1 && NOTE_P (last->loc))
    6556              :         last_loc_note = last->loc;
    6557      4647957 :       else if (piece_loc != NULL
    6558      4403832 :                && *piece_loc != NULL_RTX
    6559      4373715 :                && piece_bitpos == bitpos
    6560      9021079 :                && decl_piece_bitsize (*piece_loc) == bitsize)
    6561      4371557 :         last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
    6562              :       else
    6563              :         last_loc_note = NULL_RTX;
    6564              :       /* If the current location is the same as the end of the list,
    6565              :          and either both or neither of the locations is uninitialized,
    6566              :          we have nothing to do.  */
    6567     48619847 :       if (last_loc_note == NULL_RTX
    6568     48608839 :           || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
    6569     48608839 :                             NOTE_VAR_LOCATION_LOC (loc_note)))
    6570     59970367 :           || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
    6571     11350520 :                != NOTE_VAR_LOCATION_STATUS (loc_note))
    6572            0 :               && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
    6573              :                    == VAR_INIT_STATUS_UNINITIALIZED)
    6574            0 :                   || (NOTE_VAR_LOCATION_STATUS (loc_note)
    6575              :                       == VAR_INIT_STATUS_UNINITIALIZED))))
    6576              :         {
    6577              :           /* Add LOC to the end of list and update LAST.  If the last
    6578              :              element of the list has been removed above, reuse its
    6579              :              memory for the new node, otherwise allocate a new one.  */
    6580     37545727 :           if (unused)
    6581              :             {
    6582      2207093 :               loc = unused;
    6583      2207093 :               memset (loc, '\0', sizeof (*loc));
    6584              :             }
    6585              :           else
    6586     35338634 :             loc = ggc_cleared_alloc<var_loc_node> ();
    6587     37545727 :           if (bitsize == -1 || piece_loc == NULL)
    6588     34619510 :             loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
    6589              :           else
    6590      2926217 :             adjust_piece_list (&loc->loc, &last->loc, piece_loc,
    6591              :                                bitpos, piece_bitpos, bitsize, loc_note);
    6592     37545727 :           last->next = loc;
    6593              :           /* Ensure TEMP->LAST will point either to the new last but one
    6594              :              element of the chain, or to the last element in it.  */
    6595     37545727 :           if (last != temp->last)
    6596     21861194 :             temp->last = last;
    6597              :         }
    6598     11350520 :       else if (unused)
    6599       376457 :         ggc_free (unused);
    6600              :     }
    6601              :   else
    6602              :     {
    6603     14766836 :       loc = ggc_cleared_alloc<var_loc_node> ();
    6604     14766836 :       temp->first = loc;
    6605     14766836 :       temp->last = loc;
    6606     14766836 :       loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
    6607              :     }
    6608              :   return loc;
    6609              : }
    6610              : 
    6611              : /* Keep track of the number of spaces used to indent the
    6612              :    output of the debugging routines that print the structure of
    6613              :    the DIE internal representation.  */
    6614              : static int print_indent;
    6615              : 
    6616              : /* Indent the line the number of spaces given by print_indent.  */
    6617              : 
    6618              : static inline void
    6619         1812 : print_spaces (FILE *outfile)
    6620              : {
    6621         1812 :   fprintf (outfile, "%*s", print_indent, "");
    6622         1812 : }
    6623              : 
    6624              : /* Print a type signature in hex.  */
    6625              : 
    6626              : static inline void
    6627            0 : print_signature (FILE *outfile, char *sig)
    6628              : {
    6629            0 :   int i;
    6630              : 
    6631            0 :   for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
    6632            0 :     fprintf (outfile, "%02x", sig[i] & 0xff);
    6633            0 : }
    6634              : 
    6635              : static inline void
    6636            0 : print_discr_value (FILE *outfile, dw_discr_value *discr_value)
    6637              : {
    6638            0 :   if (discr_value->pos)
    6639            0 :     fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, discr_value->v.sval);
    6640              :   else
    6641            0 :     fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, discr_value->v.uval);
    6642            0 : }
    6643              : 
    6644              : static void print_loc_descr (dw_loc_descr_ref, FILE *);
    6645              : 
    6646              : /* Print the value associated to the VAL DWARF value node to OUTFILE.  If
    6647              :    RECURSE, output location descriptor operations.  */
    6648              : 
    6649              : static void
    6650         1272 : print_dw_val (dw_val_node *val, bool recurse, FILE *outfile)
    6651              : {
    6652         1272 :   switch (val->val_class)
    6653              :     {
    6654           12 :     case dw_val_class_addr:
    6655           12 :       fprintf (outfile, "address");
    6656           12 :       break;
    6657            0 :     case dw_val_class_offset:
    6658            0 :       fprintf (outfile, "offset");
    6659            0 :       break;
    6660           28 :     case dw_val_class_loc:
    6661           28 :       fprintf (outfile, "location descriptor");
    6662           28 :       if (val->v.val_loc == NULL)
    6663            0 :         fprintf (outfile, " -> <null>");
    6664           28 :       else if (recurse)
    6665              :         {
    6666           28 :           fprintf (outfile, ":\n");
    6667           28 :           print_indent += 4;
    6668           28 :           print_loc_descr (val->v.val_loc, outfile);
    6669           28 :           print_indent -= 4;
    6670              :         }
    6671              :       else
    6672              :         {
    6673            0 :           if (flag_dump_noaddr || flag_dump_unnumbered)
    6674            0 :             fprintf (outfile, " #");
    6675              :           else
    6676            0 :             fprintf (outfile, " (%p)", (void *) val->v.val_loc);
    6677              :         }
    6678              :       break;
    6679           36 :     case dw_val_class_loc_list:
    6680           36 :       fprintf (outfile, "location list -> label:%s",
    6681           36 :                val->v.val_loc_list->ll_symbol);
    6682           36 :       break;
    6683           36 :     case dw_val_class_view_list:
    6684           36 :       val = view_list_to_loc_list_val_node (val);
    6685           36 :       fprintf (outfile, "location list with views -> labels:%s and %s",
    6686              :                val->v.val_loc_list->ll_symbol,
    6687           36 :                val->v.val_loc_list->vl_symbol);
    6688           36 :       break;
    6689            0 :     case dw_val_class_range_list:
    6690            0 :       fprintf (outfile, "range list");
    6691            0 :       break;
    6692            0 :     case dw_val_class_const:
    6693            0 :     case dw_val_class_const_implicit:
    6694            0 :       fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, val->v.val_int);
    6695            0 :       break;
    6696          484 :     case dw_val_class_unsigned_const:
    6697          484 :     case dw_val_class_unsigned_const_implicit:
    6698          484 :       fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, val->v.val_unsigned);
    6699          484 :       break;
    6700            0 :     case dw_val_class_const_double:
    6701            0 :       fprintf (outfile, "constant (" HOST_WIDE_INT_PRINT_DEC","\
    6702              :                         HOST_WIDE_INT_PRINT_UNSIGNED")",
    6703              :                val->v.val_double.high,
    6704              :                val->v.val_double.low);
    6705            0 :       break;
    6706            0 :     case dw_val_class_wide_int:
    6707            0 :       {
    6708            0 :         int i = val->v.val_wide->get_len ();
    6709            0 :         fprintf (outfile, "constant (");
    6710            0 :         gcc_assert (i > 0);
    6711            0 :         if (val->v.val_wide->elt (i - 1) == 0)
    6712            0 :           fprintf (outfile, "0x");
    6713            0 :         fprintf (outfile, HOST_WIDE_INT_PRINT_HEX,
    6714            0 :                  val->v.val_wide->elt (--i));
    6715            0 :         while (--i >= 0)
    6716            0 :           fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX,
    6717            0 :                    val->v.val_wide->elt (i));
    6718            0 :         fprintf (outfile, ")");
    6719            0 :         break;
    6720              :       }
    6721            0 :     case dw_val_class_vec:
    6722            0 :       fprintf (outfile, "floating-point or vector constant");
    6723            0 :       break;
    6724           88 :     case dw_val_class_flag:
    6725           88 :       fprintf (outfile, "%u", val->v.val_flag);
    6726           88 :       break;
    6727          224 :     case dw_val_class_die_ref:
    6728          224 :       if (val->v.val_die_ref.die != NULL)
    6729              :         {
    6730          224 :           dw_die_ref die = val->v.val_die_ref.die;
    6731              : 
    6732          224 :           if (die->comdat_type_p)
    6733              :             {
    6734            0 :               fprintf (outfile, "die -> signature: ");
    6735            0 :               print_signature (outfile,
    6736            0 :                                die->die_id.die_type_node->signature);
    6737              :             }
    6738          224 :           else if (die->die_id.die_symbol)
    6739              :             {
    6740            0 :               fprintf (outfile, "die -> label: %s", die->die_id.die_symbol);
    6741            0 :               if (die->with_offset)
    6742            0 :                 fprintf (outfile, " + %ld", die->die_offset);
    6743              :             }
    6744              :           else
    6745          224 :             fprintf (outfile, "die -> %ld", die->die_offset);
    6746          224 :           if (flag_dump_noaddr || flag_dump_unnumbered)
    6747          224 :             fprintf (outfile, " #");
    6748              :           else
    6749            0 :             fprintf (outfile, " (%p)", (void *) die);
    6750              :         }
    6751              :       else
    6752            0 :         fprintf (outfile, "die -> <null>");
    6753              :       break;
    6754            0 :     case dw_val_class_vms_delta:
    6755            0 :       fprintf (outfile, "delta: @slotcount(%s-%s)",
    6756              :                val->v.val_vms_delta.lbl2, val->v.val_vms_delta.lbl1);
    6757            0 :       break;
    6758            0 :     case dw_val_class_symview:
    6759            0 :       fprintf (outfile, "view: %s", val->v.val_symbolic_view);
    6760            0 :       break;
    6761           20 :     case dw_val_class_lbl_id:
    6762           20 :     case dw_val_class_lineptr:
    6763           20 :     case dw_val_class_macptr:
    6764           20 :     case dw_val_class_loclistsptr:
    6765           20 :     case dw_val_class_high_pc:
    6766           20 :       fprintf (outfile, "label: %s", val->v.val_lbl_id);
    6767           20 :       break;
    6768          192 :     case dw_val_class_str:
    6769          192 :       if (val->v.val_str->str != NULL)
    6770          192 :         fprintf (outfile, "\"%s\"", val->v.val_str->str);
    6771              :       else
    6772            0 :         fprintf (outfile, "<null>");
    6773              :       break;
    6774          152 :     case dw_val_class_file:
    6775          152 :     case dw_val_class_file_implicit:
    6776          152 :       fprintf (outfile, "\"%s\" (%d)", val->v.val_file->filename,
    6777          152 :                val->v.val_file->emitted_number);
    6778          152 :       break;
    6779              :     case dw_val_class_data8:
    6780              :       {
    6781              :         int i;
    6782              : 
    6783            0 :         for (i = 0; i < 8; i++)
    6784            0 :           fprintf (outfile, "%02x", val->v.val_data8[i]);
    6785              :         break;
    6786              :       }
    6787            0 :     case dw_val_class_discr_value:
    6788            0 :       print_discr_value (outfile, &val->v.val_discr_value);
    6789            0 :       break;
    6790            0 :     case dw_val_class_discr_list:
    6791            0 :       for (dw_discr_list_ref node = val->v.val_discr_list;
    6792            0 :            node != NULL;
    6793            0 :            node = node->dw_discr_next)
    6794              :         {
    6795            0 :           if (node->dw_discr_range)
    6796              :             {
    6797            0 :               fprintf (outfile, " .. ");
    6798            0 :               print_discr_value (outfile, &node->dw_discr_lower_bound);
    6799            0 :               print_discr_value (outfile, &node->dw_discr_upper_bound);
    6800              :             }
    6801              :           else
    6802            0 :             print_discr_value (outfile, &node->dw_discr_lower_bound);
    6803              : 
    6804            0 :           if (node->dw_discr_next != NULL)
    6805            0 :             fprintf (outfile, " | ");
    6806              :         }
    6807              :     default:
    6808              :       break;
    6809              :     }
    6810         1272 : }
    6811              : 
    6812              : /* Likewise, for a DIE attribute.  */
    6813              : 
    6814              : static void
    6815         1216 : print_attribute (dw_attr_node *a, bool recurse, FILE *outfile)
    6816              : {
    6817            0 :   print_dw_val (&a->dw_attr_val, recurse, outfile);
    6818            0 : }
    6819              : 
    6820              : 
    6821              : /* Print the list of operands in the LOC location description to OUTFILE.  This
    6822              :    routine is a debugging aid only.  */
    6823              : 
    6824              : static void
    6825           28 : print_loc_descr (dw_loc_descr_ref loc, FILE *outfile)
    6826              : {
    6827           28 :   dw_loc_descr_ref l = loc;
    6828              : 
    6829           28 :   if (loc == NULL)
    6830              :     {
    6831            0 :       print_spaces (outfile);
    6832            0 :       fprintf (outfile, "<null>\n");
    6833            0 :       return;
    6834              :     }
    6835              : 
    6836           56 :   for (l = loc; l != NULL; l = l->dw_loc_next)
    6837              :     {
    6838           28 :       print_spaces (outfile);
    6839           28 :       if (flag_dump_noaddr || flag_dump_unnumbered)
    6840           28 :         fprintf (outfile, "#");
    6841              :       else
    6842            0 :         fprintf (outfile, "(%p)", (void *) l);
    6843           28 :       fprintf (outfile, " %s",
    6844           28 :                dwarf_stack_op_name (l->dw_loc_opc));
    6845           28 :       if (l->dw_loc_oprnd1.val_class != dw_val_class_none)
    6846              :         {
    6847           28 :           fprintf (outfile, " ");
    6848           28 :           print_dw_val (&l->dw_loc_oprnd1, false, outfile);
    6849              :         }
    6850           28 :       if (l->dw_loc_oprnd2.val_class != dw_val_class_none)
    6851              :         {
    6852           28 :           fprintf (outfile, ", ");
    6853           28 :           print_dw_val (&l->dw_loc_oprnd2, false, outfile);
    6854              :         }
    6855           28 :       fprintf (outfile, "\n");
    6856              :     }
    6857              : }
    6858              : 
    6859              : /* Print the information associated with a given DIE, and its children.
    6860              :    This routine is a debugging aid only.  */
    6861              : 
    6862              : static void
    6863          284 : print_die (dw_die_ref die, FILE *outfile)
    6864              : {
    6865          284 :   dw_attr_node *a;
    6866          284 :   dw_die_ref c;
    6867          284 :   unsigned ix;
    6868              : 
    6869          284 :   print_spaces (outfile);
    6870          284 :   fprintf (outfile, "DIE %4ld: %s ",
    6871          284 :            die->die_offset, dwarf_tag_name (die->die_tag));
    6872          284 :   if (flag_dump_noaddr || flag_dump_unnumbered)
    6873          284 :     fprintf (outfile, "#\n");
    6874              :   else
    6875            0 :     fprintf (outfile, "(%p)\n", (void*) die);
    6876          284 :   print_spaces (outfile);
    6877          284 :   fprintf (outfile, "  abbrev id: %lu", die->die_abbrev);
    6878          284 :   fprintf (outfile, " offset: %ld", die->die_offset);
    6879          284 :   fprintf (outfile, " mark: %d\n", die->die_mark);
    6880              : 
    6881          284 :   if (die->comdat_type_p)
    6882              :     {
    6883            0 :       print_spaces (outfile);
    6884            0 :       fprintf (outfile, "  signature: ");
    6885            0 :       print_signature (outfile, die->die_id.die_type_node->signature);
    6886            0 :       fprintf (outfile, "\n");
    6887              :     }
    6888              : 
    6889         1500 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    6890              :     {
    6891         1216 :       print_spaces (outfile);
    6892         1216 :       fprintf (outfile, "  %s: ", dwarf_attr_name (a->dw_attr));
    6893              : 
    6894         1216 :       print_attribute (a, true, outfile);
    6895         1216 :       fprintf (outfile, "\n");
    6896              :     }
    6897              : 
    6898          284 :   if (die->die_child != NULL)
    6899              :     {
    6900           52 :       print_indent += 4;
    6901          276 :       FOR_EACH_CHILD (die, c, print_die (c, outfile));
    6902           52 :       print_indent -= 4;
    6903              :     }
    6904          284 :   if (print_indent == 0)
    6905            8 :     fprintf (outfile, "\n");
    6906          284 : }
    6907              : 
    6908              : /* Print the list of operations in the LOC location description.  */
    6909              : 
    6910              : DEBUG_FUNCTION void
    6911            0 : debug_dwarf_loc_descr (dw_loc_descr_ref loc)
    6912              : {
    6913            0 :   print_loc_descr (loc, stderr);
    6914            0 : }
    6915              : 
    6916              : /* Print the information collected for a given DIE.  */
    6917              : 
    6918              : DEBUG_FUNCTION void
    6919            0 : debug_dwarf_die (dw_die_ref die)
    6920              : {
    6921            0 :   print_die (die, stderr);
    6922            0 : }
    6923              : 
    6924              : DEBUG_FUNCTION void
    6925            0 : debug (die_struct &ref)
    6926              : {
    6927            0 :   print_die (&ref, stderr);
    6928            0 : }
    6929              : 
    6930              : DEBUG_FUNCTION void
    6931            0 : debug (die_struct *ptr)
    6932              : {
    6933            0 :   if (ptr)
    6934            0 :     debug (*ptr);
    6935              :   else
    6936            0 :     fprintf (stderr, "<nil>\n");
    6937            0 : }
    6938              : 
    6939              : 
    6940              : /* Print all DWARF information collected for the compilation unit.
    6941              :    This routine is a debugging aid only.  */
    6942              : 
    6943              : DEBUG_FUNCTION void
    6944            0 : debug_dwarf (void)
    6945              : {
    6946            0 :   print_indent = 0;
    6947            0 :   print_die (comp_unit_die (), stderr);
    6948            0 : }
    6949              : 
    6950              : /* Verify the DIE tree structure.  */
    6951              : 
    6952              : DEBUG_FUNCTION void
    6953        53234 : verify_die (dw_die_ref die)
    6954              : {
    6955        53234 :   gcc_assert (!die->die_mark);
    6956        53234 :   if (die->die_parent == NULL
    6957        53234 :       && die->die_sib == NULL)
    6958              :     return;
    6959              :   /* Verify the die_sib list is cyclic.  */
    6960              :   dw_die_ref x = die;
    6961            0 :   do
    6962              :     {
    6963            0 :       x->die_mark = 1;
    6964            0 :       x = x->die_sib;
    6965              :     }
    6966            0 :   while (x && !x->die_mark);
    6967            0 :   gcc_assert (x == die);
    6968              :   x = die;
    6969            0 :   do
    6970              :     {
    6971              :       /* Verify all dies have the same parent.  */
    6972            0 :       gcc_assert (x->die_parent == die->die_parent);
    6973            0 :       if (x->die_child)
    6974              :         {
    6975              :           /* Verify the child has the proper parent and recurse.  */
    6976            0 :           gcc_assert (x->die_child->die_parent == x);
    6977            0 :           verify_die (x->die_child);
    6978              :         }
    6979            0 :       x->die_mark = 0;
    6980            0 :       x = x->die_sib;
    6981              :     }
    6982            0 :   while (x && x->die_mark);
    6983              : }
    6984              : 
    6985              : /* Sanity checks on DIEs.  */
    6986              : 
    6987              : static void
    6988    733243561 : check_die (dw_die_ref die)
    6989              : {
    6990    733243561 :   unsigned ix;
    6991    733243561 :   dw_attr_node *a;
    6992    733243561 :   bool inline_found = false;
    6993    733243561 :   int n_location = 0, n_low_pc = 0, n_high_pc = 0, n_artificial = 0;
    6994    733243561 :   int n_decl_line = 0, n_decl_column = 0, n_decl_file = 0;
    6995   3535637430 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    6996              :     {
    6997   2802393869 :       switch (a->dw_attr)
    6998              :         {
    6999      8208376 :         case DW_AT_inline:
    7000      8208376 :           if (a->dw_attr_val.v.val_unsigned)
    7001   2802393869 :             inline_found = true;
    7002              :           break;
    7003          178 :         case DW_AT_location:
    7004          178 :           ++n_location;
    7005          178 :           break;
    7006       505095 :         case DW_AT_low_pc:
    7007       505095 :           ++n_low_pc;
    7008       505095 :           break;
    7009       505095 :         case DW_AT_high_pc:
    7010       505095 :           ++n_high_pc;
    7011       505095 :           break;
    7012       130973 :         case DW_AT_artificial:
    7013       130973 :           ++n_artificial;
    7014       130973 :           break;
    7015    409383338 :         case DW_AT_decl_column:
    7016    409383338 :           ++n_decl_column;
    7017    409383338 :           break;
    7018    409930672 :         case DW_AT_decl_line:
    7019    409930672 :           ++n_decl_line;
    7020    409930672 :           break;
    7021    409788024 :         case DW_AT_decl_file:
    7022    409788024 :           ++n_decl_file;
    7023    409788024 :           break;
    7024              :         default:
    7025              :           break;
    7026              :         }
    7027              :     }
    7028    733243561 :   if (n_location > 1 || n_low_pc > 1 || n_high_pc > 1 || n_artificial > 1
    7029    733243561 :       || n_decl_column > 1 || n_decl_line > 1 || n_decl_file > 1)
    7030              :     {
    7031            0 :       fprintf (stderr, "Duplicate attributes in DIE:\n");
    7032            0 :       debug_dwarf_die (die);
    7033            0 :       gcc_unreachable ();
    7034              :     }
    7035    733243561 :   if (inline_found)
    7036              :     {
    7037              :       /* A debugging information entry that is a member of an abstract
    7038              :          instance tree [that has DW_AT_inline] should not contain any
    7039              :          attributes which describe aspects of the subroutine which vary
    7040              :          between distinct inlined expansions or distinct out-of-line
    7041              :          expansions.  */
    7042     90171043 :       FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    7043     81966050 :         gcc_assert (a->dw_attr != DW_AT_low_pc
    7044              :                     && a->dw_attr != DW_AT_high_pc
    7045              :                     && a->dw_attr != DW_AT_location
    7046              :                     && a->dw_attr != DW_AT_frame_base
    7047              :                     && a->dw_attr != DW_AT_call_all_calls
    7048              :                     && a->dw_attr != DW_AT_GNU_all_call_sites);
    7049              :     }
    7050    733243561 : }
    7051              : 
    7052              : #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
    7053              : #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
    7054              : #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
    7055              : 
    7056              : /* Calculate the checksum of a location expression.  */
    7057              : 
    7058              : static inline void
    7059          610 : loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
    7060              : {
    7061          610 :   int tem;
    7062          610 :   inchash::hash hstate;
    7063          610 :   hashval_t hash;
    7064              : 
    7065          610 :   tem = (loc->dw_loc_dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
    7066          610 :   CHECKSUM (tem);
    7067          610 :   hash_loc_operands (loc, hstate);
    7068          610 :   hash = hstate.end();
    7069          610 :   CHECKSUM (hash);
    7070          610 : }
    7071              : 
    7072              : /* Calculate the checksum of an attribute.  */
    7073              : 
    7074              : static void
    7075       930943 : attr_checksum (dw_attr_node *at, struct md5_ctx *ctx, int *mark)
    7076              : {
    7077       930943 :   dw_loc_descr_ref loc;
    7078       930943 :   rtx r;
    7079              : 
    7080       930943 :   CHECKSUM (at->dw_attr);
    7081              : 
    7082              :   /* We don't care that this was compiled with a different compiler
    7083              :      snapshot; if the output is the same, that's what matters.  */
    7084       930943 :   if (at->dw_attr == DW_AT_producer)
    7085              :     return;
    7086              : 
    7087       929356 :   switch (AT_class (at))
    7088              :     {
    7089           20 :     case dw_val_class_const:
    7090           20 :     case dw_val_class_const_implicit:
    7091           20 :       CHECKSUM (at->dw_attr_val.v.val_int);
    7092           20 :       break;
    7093       258980 :     case dw_val_class_unsigned_const:
    7094       258980 :     case dw_val_class_unsigned_const_implicit:
    7095       258980 :       CHECKSUM (at->dw_attr_val.v.val_unsigned);
    7096       258980 :       break;
    7097            0 :     case dw_val_class_const_double:
    7098            0 :       CHECKSUM (at->dw_attr_val.v.val_double);
    7099            0 :       break;
    7100            0 :     case dw_val_class_wide_int:
    7101            0 :       CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
    7102              :                       get_full_len (*at->dw_attr_val.v.val_wide)
    7103              :                       * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
    7104            0 :       break;
    7105            7 :     case dw_val_class_vec:
    7106            7 :       CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
    7107              :                       (at->dw_attr_val.v.val_vec.length
    7108              :                        * at->dw_attr_val.v.val_vec.elt_size));
    7109            7 :       break;
    7110       131456 :     case dw_val_class_flag:
    7111       131456 :       CHECKSUM (at->dw_attr_val.v.val_flag);
    7112       131456 :       break;
    7113       149161 :     case dw_val_class_str:
    7114       149161 :       CHECKSUM_STRING (AT_string (at));
    7115       149161 :       break;
    7116              : 
    7117            0 :     case dw_val_class_addr:
    7118            0 :       r = AT_addr (at);
    7119            0 :       gcc_assert (GET_CODE (r) == SYMBOL_REF);
    7120            0 :       CHECKSUM_STRING (XSTR (r, 0));
    7121            0 :       break;
    7122              : 
    7123            0 :     case dw_val_class_offset:
    7124            0 :       CHECKSUM (at->dw_attr_val.v.val_offset);
    7125            0 :       break;
    7126              : 
    7127          490 :     case dw_val_class_loc:
    7128         1100 :       for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
    7129          610 :         loc_checksum (loc, ctx);
    7130              :       break;
    7131              : 
    7132       296273 :     case dw_val_class_die_ref:
    7133       296273 :       die_checksum (AT_ref (at), ctx, mark);
    7134       296273 :       break;
    7135              : 
    7136              :     case dw_val_class_fde_ref:
    7137              :     case dw_val_class_vms_delta:
    7138              :     case dw_val_class_symview:
    7139              :     case dw_val_class_lbl_id:
    7140              :     case dw_val_class_lineptr:
    7141              :     case dw_val_class_macptr:
    7142              :     case dw_val_class_loclistsptr:
    7143              :     case dw_val_class_high_pc:
    7144              :       break;
    7145              : 
    7146        91110 :     case dw_val_class_file:
    7147        91110 :     case dw_val_class_file_implicit:
    7148        91110 :       CHECKSUM_STRING (AT_file (at)->filename);
    7149        91110 :       break;
    7150              : 
    7151            0 :     case dw_val_class_data8:
    7152            0 :       CHECKSUM (at->dw_attr_val.v.val_data8);
    7153            0 :       break;
    7154              : 
    7155              :     default:
    7156              :       break;
    7157              :     }
    7158              : }
    7159              : 
    7160              : /* Calculate the checksum of a DIE.  */
    7161              : 
    7162              : static void
    7163       533154 : die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
    7164              : {
    7165       533154 :   dw_die_ref c;
    7166       533154 :   dw_attr_node *a;
    7167       533154 :   unsigned ix;
    7168              : 
    7169              :   /* To avoid infinite recursion.  */
    7170       533154 :   if (die->die_mark)
    7171              :     {
    7172       296263 :       CHECKSUM (die->die_mark);
    7173       296263 :       return;
    7174              :     }
    7175       236891 :   die->die_mark = ++(*mark);
    7176              : 
    7177       236891 :   CHECKSUM (die->die_tag);
    7178              : 
    7179      1404725 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    7180       930943 :     attr_checksum (a, ctx, mark);
    7181              : 
    7182       411546 :   FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
    7183              : }
    7184              : 
    7185              : #undef CHECKSUM
    7186              : #undef CHECKSUM_BLOCK
    7187              : #undef CHECKSUM_STRING
    7188              : 
    7189              : /* For DWARF-4 types, include the trailing NULL when checksumming strings.  */
    7190              : #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
    7191              : #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
    7192              : #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
    7193              : #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
    7194              : #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
    7195              : #define CHECKSUM_ATTR(FOO) \
    7196              :   if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
    7197              : 
    7198              : /* Calculate the checksum of a number in signed LEB128 format.  */
    7199              : 
    7200              : static void
    7201          310 : checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
    7202              : {
    7203          318 :   unsigned char byte;
    7204          318 :   bool more;
    7205              : 
    7206          318 :   while (1)
    7207              :     {
    7208          318 :       byte = (value & 0x7f);
    7209          318 :       value >>= 7;
    7210          318 :       more = !((value == 0 && (byte & 0x40) == 0)
    7211            0 :                 || (value == -1 && (byte & 0x40) != 0));
    7212              :       if (more)
    7213            8 :         byte |= 0x80;
    7214          318 :       CHECKSUM (byte);
    7215          318 :       if (!more)
    7216              :         break;
    7217              :     }
    7218          310 : }
    7219              : 
    7220              : /* Calculate the checksum of a number in unsigned LEB128 format.  */
    7221              : 
    7222              : static void
    7223       243502 : checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
    7224              : {
    7225       255460 :   while (1)
    7226              :     {
    7227       249481 :       unsigned char byte = (value & 0x7f);
    7228       249481 :       value >>= 7;
    7229       249481 :       if (value != 0)
    7230              :         /* More bytes to follow.  */
    7231         5979 :         byte |= 0x80;
    7232       249481 :       CHECKSUM (byte);
    7233       249481 :       if (value == 0)
    7234              :         break;
    7235         5979 :     }
    7236       243502 : }
    7237              : 
    7238              : /* Checksum the context of the DIE.  This adds the names of any
    7239              :    surrounding namespaces or structures to the checksum.  */
    7240              : 
    7241              : static void
    7242          330 : checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
    7243              : {
    7244          330 :   const char *name;
    7245          330 :   dw_die_ref spec;
    7246          330 :   int tag = die->die_tag;
    7247              : 
    7248          330 :   if (tag != DW_TAG_namespace
    7249          330 :       && tag != DW_TAG_structure_type
    7250          249 :       && tag != DW_TAG_class_type)
    7251              :     return;
    7252              : 
    7253           87 :   name = get_AT_string (die, DW_AT_name);
    7254              : 
    7255           87 :   spec = get_AT_ref (die, DW_AT_specification);
    7256           87 :   if (spec != NULL)
    7257            0 :     die = spec;
    7258              : 
    7259           87 :   if (die->die_parent != NULL)
    7260           87 :     checksum_die_context (die->die_parent, ctx);
    7261              : 
    7262           87 :   CHECKSUM_ULEB128 ('C');
    7263           87 :   CHECKSUM_ULEB128 (tag);
    7264           87 :   if (name != NULL)
    7265           72 :     CHECKSUM_STRING (name);
    7266              : }
    7267              : 
    7268              : /* Calculate the checksum of a location expression.  */
    7269              : 
    7270              : static inline void
    7271            0 : loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
    7272              : {
    7273              :   /* Special case for lone DW_OP_plus_uconst: checksum as if the location
    7274              :      were emitted as a DW_FORM_sdata instead of a location expression.  */
    7275            0 :   if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
    7276              :     {
    7277            0 :       CHECKSUM_ULEB128 (DW_FORM_sdata);
    7278            0 :       CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
    7279            0 :       return;
    7280              :     }
    7281              : 
    7282              :   /* Otherwise, just checksum the raw location expression.  */
    7283            0 :   while (loc != NULL)
    7284              :     {
    7285            0 :       inchash::hash hstate;
    7286            0 :       hashval_t hash;
    7287              : 
    7288            0 :       CHECKSUM_ULEB128 (loc->dw_loc_dtprel);
    7289            0 :       CHECKSUM_ULEB128 (loc->dw_loc_opc);
    7290            0 :       hash_loc_operands (loc, hstate);
    7291            0 :       hash = hstate.end ();
    7292            0 :       CHECKSUM (hash);
    7293            0 :       loc = loc->dw_loc_next;
    7294              :     }
    7295              : }
    7296              : 
    7297              : /* Calculate the checksum of an attribute.  */
    7298              : 
    7299              : static void
    7300          650 : attr_checksum_ordered (enum dwarf_tag tag, dw_attr_node *at,
    7301              :                        struct md5_ctx *ctx, int *mark)
    7302              : {
    7303          650 :   dw_loc_descr_ref loc;
    7304          650 :   rtx r;
    7305              : 
    7306          650 :   if (AT_class (at) == dw_val_class_die_ref)
    7307              :     {
    7308          112 :       dw_die_ref target_die = AT_ref (at);
    7309              : 
    7310              :       /* For pointer and reference types, we checksum only the (qualified)
    7311              :          name of the target type (if there is a name).  For friend entries,
    7312              :          we checksum only the (qualified) name of the target type or function.
    7313              :          This allows the checksum to remain the same whether the target type
    7314              :          is complete or not.  */
    7315          112 :       if ((at->dw_attr == DW_AT_type
    7316              :            && (tag == DW_TAG_pointer_type
    7317          106 :                || tag == DW_TAG_reference_type
    7318          106 :                || tag == DW_TAG_rvalue_reference_type
    7319              :                || tag == DW_TAG_ptr_to_member_type))
    7320          101 :           || (at->dw_attr == DW_AT_friend
    7321            0 :               && tag == DW_TAG_friend))
    7322              :         {
    7323           11 :           dw_attr_node *name_attr = get_AT (target_die, DW_AT_name);
    7324              : 
    7325           11 :           if (name_attr != NULL)
    7326              :             {
    7327            1 :               dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
    7328              : 
    7329            1 :               if (decl == NULL)
    7330            1 :                 decl = target_die;
    7331            1 :               CHECKSUM_ULEB128 ('N');
    7332            1 :               CHECKSUM_ULEB128 (at->dw_attr);
    7333            1 :               if (decl->die_parent != NULL)
    7334            1 :                 checksum_die_context (decl->die_parent, ctx);
    7335            1 :               CHECKSUM_ULEB128 ('E');
    7336            1 :               CHECKSUM_STRING (AT_string (name_attr));
    7337            1 :               return;
    7338              :             }
    7339              :         }
    7340              : 
    7341              :       /* For all other references to another DIE, we check to see if the
    7342              :          target DIE has already been visited.  If it has, we emit a
    7343              :          backward reference; if not, we descend recursively.  */
    7344          111 :       if (target_die->die_mark > 0)
    7345              :         {
    7346           19 :           CHECKSUM_ULEB128 ('R');
    7347           19 :           CHECKSUM_ULEB128 (at->dw_attr);
    7348           19 :           CHECKSUM_ULEB128 (target_die->die_mark);
    7349              :         }
    7350              :       else
    7351              :         {
    7352           92 :           dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
    7353              : 
    7354           92 :           if (decl == NULL)
    7355           89 :             decl = target_die;
    7356           92 :           target_die->die_mark = ++(*mark);
    7357           92 :           CHECKSUM_ULEB128 ('T');
    7358           92 :           CHECKSUM_ULEB128 (at->dw_attr);
    7359           92 :           if (decl->die_parent != NULL)
    7360           92 :             checksum_die_context (decl->die_parent, ctx);
    7361           92 :           die_checksum_ordered (target_die, ctx, mark);
    7362              :         }
    7363              :       return;
    7364              :     }
    7365              : 
    7366          538 :   CHECKSUM_ULEB128 ('A');
    7367          538 :   CHECKSUM_ULEB128 (at->dw_attr);
    7368              : 
    7369          538 :   switch (AT_class (at))
    7370              :     {
    7371            0 :     case dw_val_class_const:
    7372            0 :     case dw_val_class_const_implicit:
    7373            0 :       CHECKSUM_ULEB128 (DW_FORM_sdata);
    7374            0 :       CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
    7375            0 :       break;
    7376              : 
    7377          310 :     case dw_val_class_unsigned_const:
    7378          310 :     case dw_val_class_unsigned_const_implicit:
    7379          310 :       CHECKSUM_ULEB128 (DW_FORM_sdata);
    7380          310 :       CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
    7381          310 :       break;
    7382              : 
    7383            0 :     case dw_val_class_const_double:
    7384            0 :       CHECKSUM_ULEB128 (DW_FORM_block);
    7385            0 :       CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
    7386            0 :       CHECKSUM (at->dw_attr_val.v.val_double);
    7387            0 :       break;
    7388              : 
    7389            0 :     case dw_val_class_wide_int:
    7390            0 :       CHECKSUM_ULEB128 (DW_FORM_block);
    7391            0 :       CHECKSUM_ULEB128 (get_full_len (*at->dw_attr_val.v.val_wide)
    7392              :                         * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
    7393            0 :       CHECKSUM_BLOCK (at->dw_attr_val.v.val_wide->get_val (),
    7394              :                       get_full_len (*at->dw_attr_val.v.val_wide)
    7395              :                       * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
    7396            0 :       break;
    7397              : 
    7398            0 :     case dw_val_class_vec:
    7399            0 :       CHECKSUM_ULEB128 (DW_FORM_block);
    7400            0 :       CHECKSUM_ULEB128 (at->dw_attr_val.v.val_vec.length
    7401              :                         * at->dw_attr_val.v.val_vec.elt_size);
    7402            0 :       CHECKSUM_BLOCK (at->dw_attr_val.v.val_vec.array,
    7403              :                       (at->dw_attr_val.v.val_vec.length
    7404              :                        * at->dw_attr_val.v.val_vec.elt_size));
    7405            0 :       break;
    7406              : 
    7407            3 :     case dw_val_class_flag:
    7408            3 :       CHECKSUM_ULEB128 (DW_FORM_flag);
    7409            3 :       CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
    7410            3 :       break;
    7411              : 
    7412          225 :     case dw_val_class_str:
    7413          225 :       CHECKSUM_ULEB128 (DW_FORM_string);
    7414          225 :       CHECKSUM_STRING (AT_string (at));
    7415          225 :       break;
    7416              : 
    7417            0 :     case dw_val_class_addr:
    7418            0 :       r = AT_addr (at);
    7419            0 :       gcc_assert (GET_CODE (r) == SYMBOL_REF);
    7420            0 :       CHECKSUM_ULEB128 (DW_FORM_string);
    7421            0 :       CHECKSUM_STRING (XSTR (r, 0));
    7422            0 :       break;
    7423              : 
    7424            0 :     case dw_val_class_offset:
    7425            0 :       CHECKSUM_ULEB128 (DW_FORM_sdata);
    7426            0 :       CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
    7427            0 :       break;
    7428              : 
    7429            0 :     case dw_val_class_loc:
    7430            0 :       for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
    7431            0 :         loc_checksum_ordered (loc, ctx);
    7432              :       break;
    7433              : 
    7434              :     case dw_val_class_fde_ref:
    7435              :     case dw_val_class_symview:
    7436              :     case dw_val_class_lbl_id:
    7437              :     case dw_val_class_lineptr:
    7438              :     case dw_val_class_macptr:
    7439              :     case dw_val_class_loclistsptr:
    7440              :     case dw_val_class_high_pc:
    7441              :       break;
    7442              : 
    7443            0 :     case dw_val_class_file:
    7444            0 :     case dw_val_class_file_implicit:
    7445            0 :       CHECKSUM_ULEB128 (DW_FORM_string);
    7446            0 :       CHECKSUM_STRING (AT_file (at)->filename);
    7447            0 :       break;
    7448              : 
    7449            0 :     case dw_val_class_data8:
    7450            0 :       CHECKSUM (at->dw_attr_val.v.val_data8);
    7451            0 :       break;
    7452              : 
    7453              :     default:
    7454              :       break;
    7455              :     }
    7456              : }
    7457              : 
    7458              : struct checksum_attributes
    7459              : {
    7460              :   dw_attr_node *at_name;
    7461              :   dw_attr_node *at_type;
    7462              :   dw_attr_node *at_friend;
    7463              :   dw_attr_node *at_accessibility;
    7464              :   dw_attr_node *at_address_class;
    7465              :   dw_attr_node *at_alignment;
    7466              :   dw_attr_node *at_allocated;
    7467              :   dw_attr_node *at_artificial;
    7468              :   dw_attr_node *at_associated;
    7469              :   dw_attr_node *at_binary_scale;
    7470              :   dw_attr_node *at_bit_offset;
    7471              :   dw_attr_node *at_bit_size;
    7472              :   dw_attr_node *at_bit_stride;
    7473              :   dw_attr_node *at_byte_size;
    7474              :   dw_attr_node *at_byte_stride;
    7475              :   dw_attr_node *at_const_value;
    7476              :   dw_attr_node *at_containing_type;
    7477              :   dw_attr_node *at_count;
    7478              :   dw_attr_node *at_data_location;
    7479              :   dw_attr_node *at_data_member_location;
    7480              :   dw_attr_node *at_decimal_scale;
    7481              :   dw_attr_node *at_decimal_sign;
    7482              :   dw_attr_node *at_default_value;
    7483              :   dw_attr_node *at_digit_count;
    7484              :   dw_attr_node *at_discr;
    7485              :   dw_attr_node *at_discr_list;
    7486              :   dw_attr_node *at_discr_value;
    7487              :   dw_attr_node *at_encoding;
    7488              :   dw_attr_node *at_endianity;
    7489              :   dw_attr_node *at_explicit;
    7490              :   dw_attr_node *at_is_optional;
    7491              :   dw_attr_node *at_location;
    7492              :   dw_attr_node *at_lower_bound;
    7493              :   dw_attr_node *at_mutable;
    7494              :   dw_attr_node *at_ordering;
    7495              :   dw_attr_node *at_picture_string;
    7496              :   dw_attr_node *at_prototyped;
    7497              :   dw_attr_node *at_small;
    7498              :   dw_attr_node *at_segment;
    7499              :   dw_attr_node *at_string_length;
    7500              :   dw_attr_node *at_string_length_bit_size;
    7501              :   dw_attr_node *at_string_length_byte_size;
    7502              :   dw_attr_node *at_threads_scaled;
    7503              :   dw_attr_node *at_upper_bound;
    7504              :   dw_attr_node *at_use_location;
    7505              :   dw_attr_node *at_use_UTF8;
    7506              :   dw_attr_node *at_variable_parameter;
    7507              :   dw_attr_node *at_virtuality;
    7508              :   dw_attr_node *at_visibility;
    7509              :   dw_attr_node *at_vtable_elem_location;
    7510              : };
    7511              : 
    7512              : /* Collect the attributes that we will want to use for the checksum.  */
    7513              : 
    7514              : static void
    7515          281 : collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
    7516              : {
    7517          281 :   dw_attr_node *a;
    7518          281 :   unsigned ix;
    7519              : 
    7520         1341 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    7521              :     {
    7522         1060 :       switch (a->dw_attr)
    7523              :         {
    7524          225 :         case DW_AT_name:
    7525          225 :           attrs->at_name = a;
    7526          225 :           break;
    7527          106 :         case DW_AT_type:
    7528          106 :           attrs->at_type = a;
    7529          106 :           break;
    7530            0 :         case DW_AT_friend:
    7531            0 :           attrs->at_friend = a;
    7532            0 :           break;
    7533           15 :         case DW_AT_accessibility:
    7534           15 :           attrs->at_accessibility = a;
    7535           15 :           break;
    7536            0 :         case DW_AT_address_class:
    7537            0 :           attrs->at_address_class = a;
    7538            0 :           break;
    7539            0 :         case DW_AT_alignment:
    7540            0 :           attrs->at_alignment = a;
    7541            0 :           break;
    7542            0 :         case DW_AT_allocated:
    7543            0 :           attrs->at_allocated = a;
    7544            0 :           break;
    7545            3 :         case DW_AT_artificial:
    7546            3 :           attrs->at_artificial = a;
    7547            3 :           break;
    7548            0 :         case DW_AT_associated:
    7549            0 :           attrs->at_associated = a;
    7550            0 :           break;
    7551            0 :         case DW_AT_binary_scale:
    7552            0 :           attrs->at_binary_scale = a;
    7553            0 :           break;
    7554            0 :         case DW_AT_bit_offset:
    7555            0 :           attrs->at_bit_offset = a;
    7556            0 :           break;
    7557            0 :         case DW_AT_bit_size:
    7558            0 :           attrs->at_bit_size = a;
    7559            0 :           break;
    7560            0 :         case DW_AT_bit_stride:
    7561            0 :           attrs->at_bit_stride = a;
    7562            0 :           break;
    7563          152 :         case DW_AT_byte_size:
    7564          152 :           attrs->at_byte_size = a;
    7565          152 :           break;
    7566            0 :         case DW_AT_byte_stride:
    7567            0 :           attrs->at_byte_stride = a;
    7568            0 :           break;
    7569           37 :         case DW_AT_const_value:
    7570           37 :           attrs->at_const_value = a;
    7571           37 :           break;
    7572            6 :         case DW_AT_containing_type:
    7573            6 :           attrs->at_containing_type = a;
    7574            6 :           break;
    7575            0 :         case DW_AT_count:
    7576            0 :           attrs->at_count = a;
    7577            0 :           break;
    7578            0 :         case DW_AT_data_location:
    7579            0 :           attrs->at_data_location = a;
    7580            0 :           break;
    7581           31 :         case DW_AT_data_member_location:
    7582           31 :           attrs->at_data_member_location = a;
    7583           31 :           break;
    7584            0 :         case DW_AT_decimal_scale:
    7585            0 :           attrs->at_decimal_scale = a;
    7586            0 :           break;
    7587            0 :         case DW_AT_decimal_sign:
    7588            0 :           attrs->at_decimal_sign = a;
    7589            0 :           break;
    7590            0 :         case DW_AT_default_value:
    7591            0 :           attrs->at_default_value = a;
    7592            0 :           break;
    7593            0 :         case DW_AT_digit_count:
    7594            0 :           attrs->at_digit_count = a;
    7595            0 :           break;
    7596            0 :         case DW_AT_discr:
    7597            0 :           attrs->at_discr = a;
    7598            0 :           break;
    7599            0 :         case DW_AT_discr_list:
    7600            0 :           attrs->at_discr_list = a;
    7601            0 :           break;
    7602            0 :         case DW_AT_discr_value:
    7603            0 :           attrs->at_discr_value = a;
    7604            0 :           break;
    7605           68 :         case DW_AT_encoding:
    7606           68 :           attrs->at_encoding = a;
    7607           68 :           break;
    7608            2 :         case DW_AT_endianity:
    7609            2 :           attrs->at_endianity = a;
    7610            2 :           break;
    7611            0 :         case DW_AT_explicit:
    7612            0 :           attrs->at_explicit = a;
    7613            0 :           break;
    7614            0 :         case DW_AT_is_optional:
    7615            0 :           attrs->at_is_optional = a;
    7616            0 :           break;
    7617            0 :         case DW_AT_location:
    7618            0 :           attrs->at_location = a;
    7619            0 :           break;
    7620            0 :         case DW_AT_lower_bound:
    7621            0 :           attrs->at_lower_bound = a;
    7622            0 :           break;
    7623            0 :         case DW_AT_mutable:
    7624            0 :           attrs->at_mutable = a;
    7625            0 :           break;
    7626            0 :         case DW_AT_ordering:
    7627            0 :           attrs->at_ordering = a;
    7628            0 :           break;
    7629            0 :         case DW_AT_picture_string:
    7630            0 :           attrs->at_picture_string = a;
    7631            0 :           break;
    7632            0 :         case DW_AT_prototyped:
    7633            0 :           attrs->at_prototyped = a;
    7634            0 :           break;
    7635            0 :         case DW_AT_small:
    7636            0 :           attrs->at_small = a;
    7637            0 :           break;
    7638            0 :         case DW_AT_segment:
    7639            0 :           attrs->at_segment = a;
    7640            0 :           break;
    7641            0 :         case DW_AT_string_length:
    7642            0 :           attrs->at_string_length = a;
    7643            0 :           break;
    7644            0 :         case DW_AT_string_length_bit_size:
    7645            0 :           attrs->at_string_length_bit_size = a;
    7646            0 :           break;
    7647            0 :         case DW_AT_string_length_byte_size:
    7648            0 :           attrs->at_string_length_byte_size = a;
    7649            0 :           break;
    7650            0 :         case DW_AT_threads_scaled:
    7651            0 :           attrs->at_threads_scaled = a;
    7652            0 :           break;
    7653            5 :         case DW_AT_upper_bound:
    7654            5 :           attrs->at_upper_bound = a;
    7655            5 :           break;
    7656            0 :         case DW_AT_use_location:
    7657            0 :           attrs->at_use_location = a;
    7658            0 :           break;
    7659            0 :         case DW_AT_use_UTF8:
    7660            0 :           attrs->at_use_UTF8 = a;
    7661            0 :           break;
    7662            0 :         case DW_AT_variable_parameter:
    7663            0 :           attrs->at_variable_parameter = a;
    7664            0 :           break;
    7665            0 :         case DW_AT_virtuality:
    7666            0 :           attrs->at_virtuality = a;
    7667            0 :           break;
    7668            0 :         case DW_AT_visibility:
    7669            0 :           attrs->at_visibility = a;
    7670            0 :           break;
    7671            0 :         case DW_AT_vtable_elem_location:
    7672            0 :           attrs->at_vtable_elem_location = a;
    7673            0 :           break;
    7674              :         default:
    7675              :           break;
    7676              :         }
    7677              :     }
    7678          281 : }
    7679              : 
    7680              : /* Calculate the checksum of a DIE, using an ordered subset of attributes.  */
    7681              : 
    7682              : static void
    7683          278 : die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
    7684              : {
    7685          278 :   dw_die_ref c;
    7686          278 :   dw_die_ref decl;
    7687          278 :   struct checksum_attributes attrs;
    7688              : 
    7689          278 :   CHECKSUM_ULEB128 ('D');
    7690          278 :   CHECKSUM_ULEB128 (die->die_tag);
    7691              : 
    7692          278 :   memset (&attrs, 0, sizeof (attrs));
    7693              : 
    7694          278 :   decl = get_AT_ref (die, DW_AT_specification);
    7695          278 :   if (decl != NULL)
    7696            3 :     collect_checksum_attributes (&attrs, decl);
    7697          278 :   collect_checksum_attributes (&attrs, die);
    7698              : 
    7699          278 :   CHECKSUM_ATTR (attrs.at_name);
    7700          278 :   CHECKSUM_ATTR (attrs.at_accessibility);
    7701          278 :   CHECKSUM_ATTR (attrs.at_address_class);
    7702          278 :   CHECKSUM_ATTR (attrs.at_allocated);
    7703          278 :   CHECKSUM_ATTR (attrs.at_artificial);
    7704          278 :   CHECKSUM_ATTR (attrs.at_associated);
    7705          278 :   CHECKSUM_ATTR (attrs.at_binary_scale);
    7706          278 :   CHECKSUM_ATTR (attrs.at_bit_offset);
    7707          278 :   CHECKSUM_ATTR (attrs.at_bit_size);
    7708          278 :   CHECKSUM_ATTR (attrs.at_bit_stride);
    7709          278 :   CHECKSUM_ATTR (attrs.at_byte_size);
    7710          278 :   CHECKSUM_ATTR (attrs.at_byte_stride);
    7711          278 :   CHECKSUM_ATTR (attrs.at_const_value);
    7712          278 :   CHECKSUM_ATTR (attrs.at_containing_type);
    7713          278 :   CHECKSUM_ATTR (attrs.at_count);
    7714          278 :   CHECKSUM_ATTR (attrs.at_data_location);
    7715          278 :   CHECKSUM_ATTR (attrs.at_data_member_location);
    7716          278 :   CHECKSUM_ATTR (attrs.at_decimal_scale);
    7717          278 :   CHECKSUM_ATTR (attrs.at_decimal_sign);
    7718          278 :   CHECKSUM_ATTR (attrs.at_default_value);
    7719          278 :   CHECKSUM_ATTR (attrs.at_digit_count);
    7720          278 :   CHECKSUM_ATTR (attrs.at_discr);
    7721          278 :   CHECKSUM_ATTR (attrs.at_discr_list);
    7722          278 :   CHECKSUM_ATTR (attrs.at_discr_value);
    7723          278 :   CHECKSUM_ATTR (attrs.at_encoding);
    7724          278 :   CHECKSUM_ATTR (attrs.at_endianity);
    7725          278 :   CHECKSUM_ATTR (attrs.at_explicit);
    7726          278 :   CHECKSUM_ATTR (attrs.at_is_optional);
    7727          278 :   CHECKSUM_ATTR (attrs.at_location);
    7728          278 :   CHECKSUM_ATTR (attrs.at_lower_bound);
    7729          278 :   CHECKSUM_ATTR (attrs.at_mutable);
    7730          278 :   CHECKSUM_ATTR (attrs.at_ordering);
    7731          278 :   CHECKSUM_ATTR (attrs.at_picture_string);
    7732          278 :   CHECKSUM_ATTR (attrs.at_prototyped);
    7733          278 :   CHECKSUM_ATTR (attrs.at_small);
    7734          278 :   CHECKSUM_ATTR (attrs.at_segment);
    7735          278 :   CHECKSUM_ATTR (attrs.at_string_length);
    7736          278 :   CHECKSUM_ATTR (attrs.at_string_length_bit_size);
    7737          278 :   CHECKSUM_ATTR (attrs.at_string_length_byte_size);
    7738          278 :   CHECKSUM_ATTR (attrs.at_threads_scaled);
    7739          278 :   CHECKSUM_ATTR (attrs.at_upper_bound);
    7740          278 :   CHECKSUM_ATTR (attrs.at_use_location);
    7741          278 :   CHECKSUM_ATTR (attrs.at_use_UTF8);
    7742          278 :   CHECKSUM_ATTR (attrs.at_variable_parameter);
    7743          278 :   CHECKSUM_ATTR (attrs.at_virtuality);
    7744          278 :   CHECKSUM_ATTR (attrs.at_visibility);
    7745          278 :   CHECKSUM_ATTR (attrs.at_vtable_elem_location);
    7746          278 :   CHECKSUM_ATTR (attrs.at_type);
    7747          278 :   CHECKSUM_ATTR (attrs.at_friend);
    7748          278 :   CHECKSUM_ATTR (attrs.at_alignment);
    7749              : 
    7750              :   /* Checksum the child DIEs.  */
    7751          278 :   c = die->die_child;
    7752          278 :   if (c) do {
    7753          216 :     dw_attr_node *name_attr;
    7754              : 
    7755          216 :     c = c->die_sib;
    7756          216 :     name_attr = get_AT (c, DW_AT_name);
    7757          216 :     if (is_template_instantiation (c))
    7758              :       {
    7759              :         /* Ignore instantiations of member type and function templates.  */
    7760              :       }
    7761          212 :     else if (name_attr != NULL
    7762          212 :              && (is_type_die (c) || c->die_tag == DW_TAG_subprogram))
    7763              :       {
    7764              :         /* Use a shallow checksum for named nested types and member
    7765              :            functions.  */
    7766          107 :         CHECKSUM_ULEB128 ('S');
    7767          107 :         CHECKSUM_ULEB128 (c->die_tag);
    7768          107 :         CHECKSUM_STRING (AT_string (name_attr));
    7769              :       }
    7770              :     else
    7771              :       {
    7772              :         /* Use a deep checksum for other children.  */
    7773              :         /* Mark this DIE so it gets processed when unmarking.  */
    7774          105 :         if (c->die_mark == 0)
    7775          105 :           c->die_mark = -1;
    7776          105 :         die_checksum_ordered (c, ctx, mark);
    7777              :       }
    7778          216 :   } while (c != die->die_child);
    7779              : 
    7780          278 :   CHECKSUM_ULEB128 (0);
    7781          278 : }
    7782              : 
    7783              : /* Add a type name and tag to a hash.  */
    7784              : static void
    7785           69 : die_odr_checksum (int tag, const char *name, md5_ctx *ctx)
    7786              : {
    7787           69 :   CHECKSUM_ULEB128 (tag);
    7788           69 :   CHECKSUM_STRING (name);
    7789           69 : }
    7790              : 
    7791              : #undef CHECKSUM
    7792              : #undef CHECKSUM_STRING
    7793              : #undef CHECKSUM_ATTR
    7794              : #undef CHECKSUM_LEB128
    7795              : #undef CHECKSUM_ULEB128
    7796              : 
    7797              : /* Generate the type signature for DIE.  This is computed by generating an
    7798              :    MD5 checksum over the DIE's tag, its relevant attributes, and its
    7799              :    children.  Attributes that are references to other DIEs are processed
    7800              :    by recursion, using the MARK field to prevent infinite recursion.
    7801              :    If the DIE is nested inside a namespace or another type, we also
    7802              :    need to include that context in the signature.  The lower 64 bits
    7803              :    of the resulting MD5 checksum comprise the signature.  */
    7804              : 
    7805              : static void
    7806           81 : generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
    7807              : {
    7808           81 :   int mark;
    7809           81 :   const char *name;
    7810           81 :   unsigned char checksum[16];
    7811           81 :   struct md5_ctx ctx;
    7812           81 :   dw_die_ref decl;
    7813           81 :   dw_die_ref parent;
    7814              : 
    7815           81 :   name = get_AT_string (die, DW_AT_name);
    7816           81 :   decl = get_AT_ref (die, DW_AT_specification);
    7817           81 :   parent = dw_get_die_parent (die);
    7818              : 
    7819              :   /* First, compute a signature for just the type name (and its surrounding
    7820              :      context, if any.  This is stored in the type unit DIE for link-time
    7821              :      ODR (one-definition rule) checking.  */
    7822              : 
    7823           81 :   if (is_cxx () && name != NULL)
    7824              :     {
    7825           69 :       md5_init_ctx (&ctx);
    7826              : 
    7827              :       /* Checksum the names of surrounding namespaces and structures.  */
    7828           69 :       if (parent != NULL)
    7829           69 :         checksum_die_context (parent, &ctx);
    7830              : 
    7831              :       /* Checksum the current DIE. */
    7832           69 :       die_odr_checksum (die->die_tag, name, &ctx);
    7833           69 :       md5_finish_ctx (&ctx, checksum);
    7834              : 
    7835           69 :       add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
    7836              :     }
    7837              : 
    7838              :   /* Next, compute the complete type signature.  */
    7839              : 
    7840           81 :   md5_init_ctx (&ctx);
    7841           81 :   mark = 1;
    7842           81 :   die->die_mark = mark;
    7843              : 
    7844              :   /* Checksum the names of surrounding namespaces and structures.  */
    7845           81 :   if (parent != NULL)
    7846           81 :     checksum_die_context (parent, &ctx);
    7847              : 
    7848              :   /* Checksum the DIE and its children.  */
    7849           81 :   die_checksum_ordered (die, &ctx, &mark);
    7850           81 :   unmark_all_dies (die);
    7851           81 :   md5_finish_ctx (&ctx, checksum);
    7852              : 
    7853              :   /* Store the signature in the type node and link the type DIE and the
    7854              :      type node together.  */
    7855           81 :   memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
    7856              :           DWARF_TYPE_SIGNATURE_SIZE);
    7857           81 :   die->comdat_type_p = true;
    7858           81 :   die->die_id.die_type_node = type_node;
    7859           81 :   type_node->type_die = die;
    7860              : 
    7861              :   /* If the DIE is a specification, link its declaration to the type node
    7862              :      as well.  */
    7863           81 :   if (decl != NULL)
    7864              :     {
    7865            0 :       decl->comdat_type_p = true;
    7866            0 :       decl->die_id.die_type_node = type_node;
    7867              :     }
    7868           81 : }
    7869              : 
    7870              : /* Do the location expressions look same?  */
    7871              : static inline bool
    7872            0 : same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
    7873              : {
    7874            0 :   return loc1->dw_loc_opc == loc2->dw_loc_opc
    7875            0 :          && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
    7876            0 :          && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
    7877              : }
    7878              : 
    7879              : /* Do the values look the same?  */
    7880              : static bool
    7881            0 : same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
    7882              : {
    7883            0 :   dw_loc_descr_ref loc1, loc2;
    7884            0 :   rtx r1, r2;
    7885              : 
    7886            0 :   if (v1->val_class != v2->val_class)
    7887              :     return false;
    7888              : 
    7889            0 :   switch (v1->val_class)
    7890              :     {
    7891            0 :     case dw_val_class_const:
    7892            0 :     case dw_val_class_const_implicit:
    7893            0 :       return v1->v.val_int == v2->v.val_int;
    7894            0 :     case dw_val_class_unsigned_const:
    7895            0 :     case dw_val_class_unsigned_const_implicit:
    7896            0 :       return v1->v.val_unsigned == v2->v.val_unsigned;
    7897            0 :     case dw_val_class_const_double:
    7898            0 :       return v1->v.val_double.high == v2->v.val_double.high
    7899            0 :              && v1->v.val_double.low == v2->v.val_double.low;
    7900            0 :     case dw_val_class_wide_int:
    7901            0 :       return *v1->v.val_wide == *v2->v.val_wide;
    7902            0 :     case dw_val_class_vec:
    7903            0 :       if (v1->v.val_vec.length != v2->v.val_vec.length
    7904            0 :           || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
    7905              :         return false;
    7906            0 :       if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
    7907            0 :                   v1->v.val_vec.length * v1->v.val_vec.elt_size))
    7908              :         return false;
    7909              :       return true;
    7910            0 :     case dw_val_class_flag:
    7911            0 :       return v1->v.val_flag == v2->v.val_flag;
    7912            0 :     case dw_val_class_str:
    7913            0 :       return !strcmp (v1->v.val_str->str, v2->v.val_str->str);
    7914              : 
    7915            0 :     case dw_val_class_addr:
    7916            0 :       r1 = v1->v.val_addr;
    7917            0 :       r2 = v2->v.val_addr;
    7918            0 :       if (GET_CODE (r1) != GET_CODE (r2))
    7919              :         return false;
    7920            0 :       return !rtx_equal_p (r1, r2);
    7921              : 
    7922            0 :     case dw_val_class_offset:
    7923            0 :       return v1->v.val_offset == v2->v.val_offset;
    7924              : 
    7925            0 :     case dw_val_class_loc:
    7926            0 :       for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
    7927            0 :            loc1 && loc2;
    7928            0 :            loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
    7929            0 :         if (!same_loc_p (loc1, loc2, mark))
    7930              :           return false;
    7931            0 :       return !loc1 && !loc2;
    7932              : 
    7933            0 :     case dw_val_class_die_ref:
    7934            0 :       return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
    7935              : 
    7936            0 :     case dw_val_class_symview:
    7937            0 :       return strcmp (v1->v.val_symbolic_view, v2->v.val_symbolic_view) == 0;
    7938              : 
    7939              :     case dw_val_class_fde_ref:
    7940              :     case dw_val_class_vms_delta:
    7941              :     case dw_val_class_lbl_id:
    7942              :     case dw_val_class_lineptr:
    7943              :     case dw_val_class_macptr:
    7944              :     case dw_val_class_loclistsptr:
    7945              :     case dw_val_class_high_pc:
    7946              :       return true;
    7947              : 
    7948            0 :     case dw_val_class_file:
    7949            0 :     case dw_val_class_file_implicit:
    7950            0 :       return v1->v.val_file == v2->v.val_file;
    7951              : 
    7952            0 :     case dw_val_class_data8:
    7953            0 :       return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
    7954              : 
    7955              :     default:
    7956              :       return true;
    7957              :     }
    7958              : }
    7959              : 
    7960              : /* Do the attributes look the same?  */
    7961              : 
    7962              : static bool
    7963            0 : same_attr_p (dw_attr_node *at1, dw_attr_node *at2, int *mark)
    7964              : {
    7965            0 :   if (at1->dw_attr != at2->dw_attr)
    7966              :     return false;
    7967              : 
    7968              :   /* We don't care that this was compiled with a different compiler
    7969              :      snapshot; if the output is the same, that's what matters. */
    7970            0 :   if (at1->dw_attr == DW_AT_producer)
    7971              :     return true;
    7972              : 
    7973            0 :   return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
    7974              : }
    7975              : 
    7976              : /* Do the dies look the same?  */
    7977              : 
    7978              : static bool
    7979            0 : same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
    7980              : {
    7981            0 :   dw_die_ref c1, c2;
    7982            0 :   dw_attr_node *a1;
    7983            0 :   unsigned ix;
    7984              : 
    7985              :   /* To avoid infinite recursion.  */
    7986            0 :   if (die1->die_mark)
    7987            0 :     return die1->die_mark == die2->die_mark;
    7988            0 :   die1->die_mark = die2->die_mark = ++(*mark);
    7989              : 
    7990            0 :   if (die1->die_tag != die2->die_tag)
    7991              :     return false;
    7992              : 
    7993            0 :   if (vec_safe_length (die1->die_attr) != vec_safe_length (die2->die_attr))
    7994              :     return false;
    7995              : 
    7996            0 :   FOR_EACH_VEC_SAFE_ELT (die1->die_attr, ix, a1)
    7997            0 :     if (!same_attr_p (a1, &(*die2->die_attr)[ix], mark))
    7998              :       return false;
    7999              : 
    8000            0 :   c1 = die1->die_child;
    8001            0 :   c2 = die2->die_child;
    8002            0 :   if (! c1)
    8003              :     {
    8004            0 :       if (c2)
    8005            0 :         return false;
    8006              :     }
    8007              :   else
    8008            0 :     for (;;)
    8009              :       {
    8010            0 :         if (!same_die_p (c1, c2, mark))
    8011              :           return false;
    8012            0 :         c1 = c1->die_sib;
    8013            0 :         c2 = c2->die_sib;
    8014            0 :         if (c1 == die1->die_child)
    8015              :           {
    8016            0 :             if (c2 == die2->die_child)
    8017              :               break;
    8018              :             else
    8019            0 :               return false;
    8020              :           }
    8021              :     }
    8022              : 
    8023              :   return true;
    8024              : }
    8025              : 
    8026              : /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
    8027              :    children, and set die_symbol.  */
    8028              : 
    8029              : static void
    8030         1338 : compute_comp_unit_symbol (dw_die_ref unit_die)
    8031              : {
    8032         1338 :   const char *die_name = get_AT_string (unit_die, DW_AT_name);
    8033         1338 :   const char *base = die_name ? lbasename (die_name) : "anonymous";
    8034         1338 :   char *name = XALLOCAVEC (char, strlen (base) + 64);
    8035         1338 :   char *p;
    8036         1338 :   int i, mark;
    8037         1338 :   unsigned char checksum[16];
    8038         1338 :   struct md5_ctx ctx;
    8039              : 
    8040              :   /* Compute the checksum of the DIE, then append part of it as hex digits to
    8041              :      the name filename of the unit.  */
    8042              : 
    8043         1338 :   md5_init_ctx (&ctx);
    8044         1338 :   mark = 0;
    8045         1338 :   die_checksum (unit_die, &ctx, &mark);
    8046         1338 :   unmark_all_dies (unit_die);
    8047         1338 :   md5_finish_ctx (&ctx, checksum);
    8048              : 
    8049              :   /* When we this for comp_unit_die () we have a DW_AT_name that might
    8050              :      not start with a letter but with anything valid for filenames and
    8051              :      clean_symbol_name doesn't fix that up.  Prepend 'g' if the first
    8052              :      character is not a letter.  */
    8053         1338 :   sprintf (name, "%s%s.", ISALPHA (*base) ? "" : "g", base);
    8054         1338 :   clean_symbol_name (name);
    8055              : 
    8056         1338 :   p = name + strlen (name);
    8057         6690 :   for (i = 0; i < 4; i++)
    8058              :     {
    8059         5352 :       sprintf (p, "%.2x", checksum[i]);
    8060         5352 :       p += 2;
    8061              :     }
    8062              : 
    8063         1338 :   unit_die->die_id.die_symbol = xstrdup (name);
    8064         1338 : }
    8065              : 
    8066              : /* Returns true if DIE represents a type, in the sense of TYPE_P.  */
    8067              : 
    8068              : static bool
    8069     85970882 : is_type_die (dw_die_ref die)
    8070              : {
    8071     85970882 :   switch (die->die_tag)
    8072              :     {
    8073              :     case DW_TAG_array_type:
    8074              :     case DW_TAG_class_type:
    8075              :     case DW_TAG_interface_type:
    8076              :     case DW_TAG_enumeration_type:
    8077              :     case DW_TAG_pointer_type:
    8078              :     case DW_TAG_reference_type:
    8079              :     case DW_TAG_rvalue_reference_type:
    8080              :     case DW_TAG_string_type:
    8081              :     case DW_TAG_structure_type:
    8082              :     case DW_TAG_subroutine_type:
    8083              :     case DW_TAG_union_type:
    8084              :     case DW_TAG_ptr_to_member_type:
    8085              :     case DW_TAG_set_type:
    8086              :     case DW_TAG_subrange_type:
    8087              :     case DW_TAG_base_type:
    8088              :     case DW_TAG_const_type:
    8089              :     case DW_TAG_file_type:
    8090              :     case DW_TAG_packed_type:
    8091              :     case DW_TAG_volatile_type:
    8092              :     case DW_TAG_typedef:
    8093              :       return true;
    8094     77613655 :     default:
    8095     77613655 :       return false;
    8096              :     }
    8097              : }
    8098              : 
    8099              : /* Returns true iff C is a compile-unit DIE.  */
    8100              : 
    8101              : static inline bool
    8102     47349917 : is_cu_die (dw_die_ref c)
    8103              : {
    8104     47160672 :   return c && (c->die_tag == DW_TAG_compile_unit
    8105     47295496 :                || c->die_tag == DW_TAG_skeleton_unit);
    8106              : }
    8107              : 
    8108              : /* Returns true iff C is a unit DIE of some sort.  */
    8109              : 
    8110              : static inline bool
    8111      1922760 : is_unit_die (dw_die_ref c)
    8112              : {
    8113      1922760 :   return c && (c->die_tag == DW_TAG_compile_unit
    8114              :                || c->die_tag == DW_TAG_partial_unit
    8115              :                || c->die_tag == DW_TAG_type_unit
    8116      1922760 :                || c->die_tag == DW_TAG_skeleton_unit);
    8117              : }
    8118              : 
    8119              : /* Returns true iff C is a namespace DIE.  */
    8120              : 
    8121              : static inline bool
    8122          165 : is_namespace_die (dw_die_ref c)
    8123              : {
    8124          165 :   return c && c->die_tag == DW_TAG_namespace;
    8125              : }
    8126              : 
    8127              : /* Return true if this DIE is a template parameter.  */
    8128              : 
    8129              : static inline bool
    8130     20860985 : is_template_parameter (dw_die_ref die)
    8131              : {
    8132     20860985 :   switch (die->die_tag)
    8133              :     {
    8134              :     case DW_TAG_template_type_param:
    8135              :     case DW_TAG_template_value_param:
    8136              :     case DW_TAG_GNU_template_template_param:
    8137              :     case DW_TAG_GNU_template_parameter_pack:
    8138              :       return true;
    8139          216 :     default:
    8140          216 :       return false;
    8141              :     }
    8142              : }
    8143              : 
    8144              : /* Return true if this DIE represents a template instantiation.  */
    8145              : 
    8146              : static inline bool
    8147          320 : is_template_instantiation (dw_die_ref die)
    8148              : {
    8149          320 :   dw_die_ref c;
    8150              : 
    8151          320 :   if (!is_type_die (die) && die->die_tag != DW_TAG_subprogram)
    8152              :     return false;
    8153          263 :   FOR_EACH_CHILD (die, c, if (is_template_parameter (c)) return true);
    8154              :   return false;
    8155              : }
    8156              : 
    8157              : static char *
    8158     28365512 : gen_internal_sym (const char *prefix)
    8159              : {
    8160     28365512 :   char buf[MAX_ARTIFICIAL_LABEL_BYTES];
    8161              : 
    8162     28365512 :   ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
    8163     28365512 :   return xstrdup (buf);
    8164              : }
    8165              : 
    8166              : /* Return true if this DIE is a declaration.  */
    8167              : 
    8168              : static bool
    8169     29297374 : is_declaration_die (dw_die_ref die)
    8170              : {
    8171     29297374 :   dw_attr_node *a;
    8172     29297374 :   unsigned ix;
    8173              : 
    8174    205436928 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    8175    204671751 :     if (a->dw_attr == DW_AT_declaration)
    8176              :       return true;
    8177              : 
    8178              :   return false;
    8179              : }
    8180              : 
    8181              : /* Return true if this DIE is nested inside a subprogram.  */
    8182              : 
    8183              : static bool
    8184           82 : is_nested_in_subprogram (dw_die_ref die)
    8185              : {
    8186           82 :   dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
    8187              : 
    8188           82 :   if (decl == NULL)
    8189           82 :     decl = die;
    8190          164 :   return local_scope_p (decl);
    8191              : }
    8192              : 
    8193              : /* Return true if this DIE contains a defining declaration of a
    8194              :    subprogram.  */
    8195              : 
    8196              : static bool
    8197          392 : contains_subprogram_definition (dw_die_ref die)
    8198              : {
    8199          392 :   dw_die_ref c;
    8200              : 
    8201          392 :   if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
    8202              :     return true;
    8203          536 :   FOR_EACH_CHILD (die, c, if (contains_subprogram_definition (c)) return 1);
    8204              :   return false;
    8205              : }
    8206              : 
    8207              : /* Return true if this is a type DIE that should be moved to a
    8208              :    COMDAT .debug_types section or .debug_info section with DW_UT_*type
    8209              :    unit type.  */
    8210              : 
    8211              : static bool
    8212          766 : should_move_die_to_comdat (dw_die_ref die)
    8213              : {
    8214          766 :   switch (die->die_tag)
    8215              :     {
    8216           87 :     case DW_TAG_class_type:
    8217           87 :     case DW_TAG_structure_type:
    8218           87 :     case DW_TAG_enumeration_type:
    8219           87 :     case DW_TAG_union_type:
    8220              :       /* Don't move declarations, inlined instances, types nested in a
    8221              :          subprogram, or types that contain subprogram definitions.  */
    8222           87 :       if (is_declaration_die (die)
    8223           82 :           || get_AT (die, DW_AT_abstract_origin)
    8224           82 :           || is_nested_in_subprogram (die)
    8225          169 :           || contains_subprogram_definition (die))
    8226              :         return false;
    8227           82 :       if (die->die_tag != DW_TAG_enumeration_type)
    8228              :         {
    8229              :           /* Don't move non-constant size aggregates.  */
    8230           68 :           dw_attr_node *sz = get_AT (die, DW_AT_byte_size);
    8231           68 :           if (sz == NULL
    8232           68 :               || (AT_class (sz) != dw_val_class_unsigned_const
    8233            0 :                   && AT_class (sz) != dw_val_class_unsigned_const_implicit))
    8234            1 :             return false;
    8235              :         }
    8236              :       return true;
    8237              :     case DW_TAG_array_type:
    8238              :     case DW_TAG_interface_type:
    8239              :     case DW_TAG_pointer_type:
    8240              :     case DW_TAG_reference_type:
    8241              :     case DW_TAG_rvalue_reference_type:
    8242              :     case DW_TAG_string_type:
    8243              :     case DW_TAG_subroutine_type:
    8244              :     case DW_TAG_ptr_to_member_type:
    8245              :     case DW_TAG_set_type:
    8246              :     case DW_TAG_subrange_type:
    8247              :     case DW_TAG_base_type:
    8248              :     case DW_TAG_const_type:
    8249              :     case DW_TAG_file_type:
    8250              :     case DW_TAG_packed_type:
    8251              :     case DW_TAG_volatile_type:
    8252              :     case DW_TAG_typedef:
    8253              :     default:
    8254              :       return false;
    8255              :     }
    8256              : }
    8257              : 
    8258              : /* Make a clone of DIE.  */
    8259              : 
    8260              : static dw_die_ref
    8261          276 : clone_die (dw_die_ref die)
    8262              : {
    8263          276 :   dw_die_ref clone = new_die_raw (die->die_tag);
    8264          276 :   dw_attr_node *a;
    8265          276 :   unsigned ix;
    8266              : 
    8267         1663 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    8268         1111 :     add_dwarf_attr (clone, a);
    8269              : 
    8270          276 :   return clone;
    8271              : }
    8272              : 
    8273              : /* Make a clone of the tree rooted at DIE.  */
    8274              : 
    8275              : static dw_die_ref
    8276            0 : clone_tree (dw_die_ref die)
    8277              : {
    8278            0 :   dw_die_ref c;
    8279            0 :   dw_die_ref clone = clone_die (die);
    8280              : 
    8281            0 :   FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree (c)));
    8282              : 
    8283            0 :   return clone;
    8284              : }
    8285              : 
    8286              : /* Make a clone of DIE as a declaration.  */
    8287              : 
    8288              : static dw_die_ref
    8289          147 : clone_as_declaration (dw_die_ref die)
    8290              : {
    8291          147 :   dw_die_ref clone;
    8292          147 :   dw_die_ref decl;
    8293          147 :   dw_attr_node *a;
    8294          147 :   unsigned ix;
    8295              : 
    8296              :   /* If the DIE is already a declaration, just clone it.  */
    8297          147 :   if (is_declaration_die (die))
    8298            0 :     return clone_die (die);
    8299              : 
    8300              :   /* If the DIE is a specification, just clone its declaration DIE.  */
    8301          147 :   decl = get_AT_ref (die, DW_AT_specification);
    8302          147 :   if (decl != NULL)
    8303              :     {
    8304           30 :       clone = clone_die (decl);
    8305           30 :       if (die->comdat_type_p)
    8306           30 :         add_AT_die_ref (clone, DW_AT_signature, die);
    8307              :       return clone;
    8308              :     }
    8309              : 
    8310          117 :   clone = new_die_raw (die->die_tag);
    8311              : 
    8312          759 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    8313              :     {
    8314              :       /* We don't want to copy over all attributes.
    8315              :          For example we don't want DW_AT_byte_size because otherwise we will no
    8316              :          longer have a declaration and GDB will treat it as a definition.  */
    8317              : 
    8318          525 :       switch (a->dw_attr)
    8319              :         {
    8320          111 :         case DW_AT_abstract_origin:
    8321          111 :         case DW_AT_artificial:
    8322          111 :         case DW_AT_containing_type:
    8323          111 :         case DW_AT_external:
    8324          111 :         case DW_AT_name:
    8325          111 :         case DW_AT_type:
    8326          111 :         case DW_AT_virtuality:
    8327          111 :         case DW_AT_linkage_name:
    8328          111 :         case DW_AT_MIPS_linkage_name:
    8329          111 :           add_dwarf_attr (clone, a);
    8330          111 :           break;
    8331              :         case DW_AT_byte_size:
    8332              :         case DW_AT_alignment:
    8333              :         default:
    8334              :           break;
    8335              :         }
    8336              :     }
    8337              : 
    8338          117 :   if (die->comdat_type_p)
    8339           66 :     add_AT_die_ref (clone, DW_AT_signature, die);
    8340              : 
    8341          117 :   add_AT_flag (clone, DW_AT_declaration, 1);
    8342          117 :   return clone;
    8343              : }
    8344              : 
    8345              : 
    8346              : /* Structure to map a DIE in one CU to its copy in a comdat type unit.  */
    8347              : 
    8348              : struct decl_table_entry
    8349              : {
    8350              :   dw_die_ref orig;
    8351              :   dw_die_ref copy;
    8352              : };
    8353              : 
    8354              : /* Helpers to manipulate hash table of copied declarations.  */
    8355              : 
    8356              : /* Hashtable helpers.  */
    8357              : 
    8358              : struct decl_table_entry_hasher : free_ptr_hash <decl_table_entry>
    8359              : {
    8360              :   typedef die_struct *compare_type;
    8361              :   static inline hashval_t hash (const decl_table_entry *);
    8362              :   static inline bool equal (const decl_table_entry *, const die_struct *);
    8363              : };
    8364              : 
    8365              : inline hashval_t
    8366          436 : decl_table_entry_hasher::hash (const decl_table_entry *entry)
    8367              : {
    8368          436 :   return htab_hash_pointer (entry->orig);
    8369              : }
    8370              : 
    8371              : inline bool
    8372          495 : decl_table_entry_hasher::equal (const decl_table_entry *entry1,
    8373              :                                 const die_struct *entry2)
    8374              : {
    8375          495 :   return entry1->orig == entry2;
    8376              : }
    8377              : 
    8378              : typedef hash_table<decl_table_entry_hasher> decl_hash_type;
    8379              : 
    8380              : /* Copy DIE and its ancestors, up to, but not including, the compile unit
    8381              :    or type unit entry, to a new tree.  Adds the new tree to UNIT and returns
    8382              :    a pointer to the copy of DIE.  If DECL_TABLE is provided, it is used
    8383              :    to check if the ancestor has already been copied into UNIT.  */
    8384              : 
    8385              : static dw_die_ref
    8386           99 : copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
    8387              :                     decl_hash_type *decl_table)
    8388              : {
    8389           99 :   dw_die_ref parent = die->die_parent;
    8390           99 :   dw_die_ref new_parent = unit;
    8391           99 :   dw_die_ref copy;
    8392           99 :   decl_table_entry **slot = NULL;
    8393           99 :   struct decl_table_entry *entry = NULL;
    8394              : 
    8395              :   /* If DIE refers to a stub unfold that so we get the appropriate
    8396              :      DIE registered as orig in decl_table.  */
    8397           99 :   if (dw_die_ref c = get_AT_ref (die, DW_AT_signature))
    8398            0 :     die = c;
    8399              : 
    8400           99 :   if (decl_table)
    8401              :     {
    8402              :       /* Check if the entry has already been copied to UNIT.  */
    8403            9 :       slot = decl_table->find_slot_with_hash (die, htab_hash_pointer (die),
    8404              :                                               INSERT);
    8405            9 :       if (*slot != HTAB_EMPTY_ENTRY)
    8406              :         {
    8407            3 :           entry = *slot;
    8408            3 :           return entry->copy;
    8409              :         }
    8410              : 
    8411              :       /* Record in DECL_TABLE that DIE has been copied to UNIT.  */
    8412            6 :       entry = XCNEW (struct decl_table_entry);
    8413            6 :       entry->orig = die;
    8414            6 :       entry->copy = NULL;
    8415            6 :       *slot = entry;
    8416              :     }
    8417              : 
    8418           96 :   if (parent != NULL)
    8419              :     {
    8420           96 :       dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
    8421           96 :       if (spec != NULL)
    8422            0 :         parent = spec;
    8423           96 :       if (!is_unit_die (parent))
    8424           48 :         new_parent = copy_ancestor_tree (unit, parent, decl_table);
    8425              :     }
    8426              : 
    8427           96 :   copy = clone_as_declaration (die);
    8428           96 :   add_child_die (new_parent, copy);
    8429              : 
    8430           96 :   if (decl_table)
    8431              :     {
    8432              :       /* Record the pointer to the copy.  */
    8433            6 :       entry->copy = copy;
    8434              :     }
    8435              : 
    8436              :   return copy;
    8437              : }
    8438              : /* Copy the declaration context to the new type unit DIE.  This includes
    8439              :    any surrounding namespace or type declarations.  If the DIE has an
    8440              :    AT_specification attribute, it also includes attributes and children
    8441              :    attached to the specification, and returns a pointer to the original
    8442              :    parent of the declaration DIE.  Returns NULL otherwise.  */
    8443              : 
    8444              : static dw_die_ref
    8445           81 : copy_declaration_context (dw_die_ref unit, dw_die_ref die)
    8446              : {
    8447           81 :   dw_die_ref decl;
    8448           81 :   dw_die_ref new_decl;
    8449           81 :   dw_die_ref orig_parent = NULL;
    8450              : 
    8451           81 :   decl = get_AT_ref (die, DW_AT_specification);
    8452           81 :   if (decl == NULL)
    8453              :     decl = die;
    8454              :   else
    8455              :     {
    8456            0 :       unsigned ix;
    8457            0 :       dw_die_ref c;
    8458            0 :       dw_attr_node *a;
    8459              : 
    8460              :       /* The original DIE will be changed to a declaration, and must
    8461              :          be moved to be a child of the original declaration DIE.  */
    8462            0 :       orig_parent = decl->die_parent;
    8463              : 
    8464              :       /* Copy the type node pointer from the new DIE to the original
    8465              :          declaration DIE so we can forward references later.  */
    8466            0 :       decl->comdat_type_p = true;
    8467            0 :       decl->die_id.die_type_node = die->die_id.die_type_node;
    8468              : 
    8469            0 :       remove_AT (die, DW_AT_specification);
    8470              : 
    8471            0 :       FOR_EACH_VEC_SAFE_ELT (decl->die_attr, ix, a)
    8472              :         {
    8473            0 :           if (a->dw_attr != DW_AT_name
    8474              :               && a->dw_attr != DW_AT_declaration
    8475              :               && a->dw_attr != DW_AT_external)
    8476            0 :             add_dwarf_attr (die, a);
    8477              :         }
    8478              : 
    8479            0 :       FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree (c)));
    8480              :     }
    8481              : 
    8482           81 :   if (decl->die_parent != NULL
    8483           81 :       && !is_unit_die (decl->die_parent))
    8484              :     {
    8485           42 :       new_decl = copy_ancestor_tree (unit, decl, NULL);
    8486           42 :       if (new_decl != NULL)
    8487              :         {
    8488           42 :           remove_AT (new_decl, DW_AT_signature);
    8489           42 :           add_AT_specification (die, new_decl);
    8490              :         }
    8491              :     }
    8492              : 
    8493           81 :   return orig_parent;
    8494              : }
    8495              : 
    8496              : /* Generate the skeleton ancestor tree for the given NODE, then clone
    8497              :    the DIE and add the clone into the tree.  */
    8498              : 
    8499              : static void
    8500           92 : generate_skeleton_ancestor_tree (skeleton_chain_node *node)
    8501              : {
    8502           92 :   if (node->new_die != NULL)
    8503              :     return;
    8504              : 
    8505           39 :   node->new_die = clone_as_declaration (node->old_die);
    8506              : 
    8507           39 :   if (node->parent != NULL)
    8508              :     {
    8509            0 :       generate_skeleton_ancestor_tree (node->parent);
    8510            0 :       add_child_die (node->parent->new_die, node->new_die);
    8511              :     }
    8512              : }
    8513              : 
    8514              : /* Generate a skeleton tree of DIEs containing any declarations that are
    8515              :    found in the original tree.  We traverse the tree looking for declaration
    8516              :    DIEs, and construct the skeleton from the bottom up whenever we find one.  */
    8517              : 
    8518              : static void
    8519          348 : generate_skeleton_bottom_up (skeleton_chain_node *parent)
    8520              : {
    8521          348 :   skeleton_chain_node node;
    8522          348 :   dw_die_ref c;
    8523          348 :   dw_die_ref first;
    8524          348 :   dw_die_ref prev = NULL;
    8525          348 :   dw_die_ref next = NULL;
    8526              : 
    8527          348 :   node.parent = parent;
    8528              : 
    8529          348 :   first = c = parent->old_die->die_child;
    8530          348 :   if (c)
    8531          147 :     next = c->die_sib;
    8532          147 :   if (c) do {
    8533          279 :     if (prev == NULL || prev->die_sib == c)
    8534          279 :       prev = c;
    8535          279 :     c = next;
    8536          279 :     next = (c == first ? NULL : c->die_sib);
    8537          279 :     node.old_die = c;
    8538          279 :     node.new_die = NULL;
    8539          279 :     if (is_declaration_die (c))
    8540              :       {
    8541           92 :         if (is_template_instantiation (c))
    8542              :           {
    8543              :             /* Instantiated templates do not need to be cloned into the
    8544              :                type unit.  Just move the DIE and its children back to
    8545              :                the skeleton tree (in the main CU).  */
    8546            4 :             remove_child_with_prev (c, prev);
    8547            4 :             generate_skeleton_ancestor_tree (parent);
    8548            4 :             add_child_die (parent->new_die, c);
    8549            4 :             c = prev;
    8550              :           }
    8551           88 :         else if (c->comdat_type_p)
    8552              :           {
    8553              :             /* This is the skeleton of earlier break_out_comdat_types
    8554              :                type.  Clone the existing DIE, but keep the children
    8555              :                under the original (which is in the main CU).  */
    8556           12 :             dw_die_ref clone = clone_die (c);
    8557              : 
    8558           12 :             replace_child (c, clone, prev);
    8559           12 :             generate_skeleton_ancestor_tree (parent);
    8560           12 :             add_child_die (parent->new_die, c);
    8561           12 :             c = clone;
    8562           12 :             continue;
    8563           12 :           }
    8564              :         else
    8565              :           {
    8566              :             /* Clone the existing DIE, move the original to the skeleton
    8567              :                tree (which is in the main CU), and put the clone, with
    8568              :                all the original's children, where the original came from
    8569              :                (which is about to be moved to the type unit).  */
    8570           76 :             dw_die_ref clone = clone_die (c);
    8571           76 :             move_all_children (c, clone);
    8572              : 
    8573              :             /* If the original has a DW_AT_object_pointer attribute,
    8574              :                it would now point to a child DIE just moved to the
    8575              :                cloned tree, so we need to remove that attribute from
    8576              :                the original.  */
    8577           76 :             remove_AT (c, DW_AT_object_pointer);
    8578              : 
    8579           76 :             replace_child (c, clone, prev);
    8580           76 :             generate_skeleton_ancestor_tree (parent);
    8581           76 :             add_child_die (parent->new_die, c);
    8582           76 :             node.old_die = clone;
    8583           76 :             node.new_die = c;
    8584           76 :             c = clone;
    8585              :           }
    8586              :       }
    8587          267 :     generate_skeleton_bottom_up (&node);
    8588          279 :   } while (next != NULL);
    8589          348 : }
    8590              : 
    8591              : /* Wrapper function for generate_skeleton_bottom_up.  */
    8592              : 
    8593              : static dw_die_ref
    8594           81 : generate_skeleton (dw_die_ref die)
    8595              : {
    8596           81 :   skeleton_chain_node node;
    8597              : 
    8598           81 :   node.old_die = die;
    8599           81 :   node.new_die = NULL;
    8600           81 :   node.parent = NULL;
    8601              : 
    8602              :   /* If this type definition is nested inside another type,
    8603              :      and is not an instantiation of a template, always leave
    8604              :      at least a declaration in its place.  */
    8605           81 :   if (die->die_parent != NULL
    8606           81 :       && is_type_die (die->die_parent)
    8607           93 :       && !is_template_instantiation (die))
    8608           12 :     node.new_die = clone_as_declaration (die);
    8609              : 
    8610           81 :   generate_skeleton_bottom_up (&node);
    8611           81 :   return node.new_die;
    8612              : }
    8613              : 
    8614              : /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
    8615              :    declaration.  The original DIE is moved to a new compile unit so that
    8616              :    existing references to it follow it to the new location.  If any of the
    8617              :    original DIE's descendants is a declaration, we need to replace the
    8618              :    original DIE with a skeleton tree and move the declarations back into the
    8619              :    skeleton tree.  */
    8620              : 
    8621              : static dw_die_ref
    8622           81 : remove_child_or_replace_with_skeleton (dw_die_ref unit, dw_die_ref child,
    8623              :                                        dw_die_ref prev)
    8624              : {
    8625           81 :   dw_die_ref skeleton, orig_parent;
    8626              : 
    8627              :   /* Copy the declaration context to the type unit DIE.  If the returned
    8628              :      ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
    8629              :      that DIE.  */
    8630           81 :   orig_parent = copy_declaration_context (unit, child);
    8631              : 
    8632           81 :   skeleton = generate_skeleton (child);
    8633           81 :   if (skeleton == NULL)
    8634           30 :     remove_child_with_prev (child, prev);
    8635              :   else
    8636              :     {
    8637           51 :       skeleton->comdat_type_p = true;
    8638           51 :       skeleton->die_id.die_type_node = child->die_id.die_type_node;
    8639              : 
    8640              :       /* If the original DIE was a specification, we need to put
    8641              :          the skeleton under the parent DIE of the declaration.
    8642              :          This leaves the original declaration in the tree, but
    8643              :          it will be pruned later since there are no longer any
    8644              :          references to it.  */
    8645           51 :       if (orig_parent != NULL)
    8646              :         {
    8647            0 :           remove_child_with_prev (child, prev);
    8648            0 :           add_child_die (orig_parent, skeleton);
    8649              :         }
    8650              :       else
    8651           51 :         replace_child (child, skeleton, prev);
    8652              :     }
    8653              : 
    8654           81 :   return skeleton;
    8655              : }
    8656              : 
    8657              : static void
    8658              : copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
    8659              :                                comdat_type_node *type_node,
    8660              :                                hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs);
    8661              : 
    8662              : /* Helper for copy_dwarf_procs_ref_in_dies.  Make a copy of the DIE DWARF
    8663              :    procedure, put it under TYPE_NODE and return the copy.  Continue looking for
    8664              :    DWARF procedure references in the DW_AT_location attribute.  */
    8665              : 
    8666              : static dw_die_ref
    8667            0 : copy_dwarf_procedure (dw_die_ref die,
    8668              :                       comdat_type_node *type_node,
    8669              :                       hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
    8670              : {
    8671            0 :   gcc_assert (die->die_tag == DW_TAG_dwarf_procedure);
    8672              : 
    8673              :   /* DWARF procedures are not supposed to have children...  */
    8674            0 :   gcc_assert (die->die_child == NULL);
    8675              : 
    8676              :   /* ... and they are supposed to have only one attribute: DW_AT_location.  */
    8677            0 :   gcc_assert (vec_safe_length (die->die_attr) == 1
    8678              :               && ((*die->die_attr)[0].dw_attr == DW_AT_location));
    8679              : 
    8680              :   /* Do not copy more than once DWARF procedures.  */
    8681            0 :   bool existed;
    8682            0 :   dw_die_ref &die_copy = copied_dwarf_procs.get_or_insert (die, &existed);
    8683            0 :   if (existed)
    8684            0 :     return die_copy;
    8685              : 
    8686            0 :   die_copy = clone_die (die);
    8687            0 :   add_child_die (type_node->root_die, die_copy);
    8688            0 :   copy_dwarf_procs_ref_in_attrs (die_copy, type_node, copied_dwarf_procs);
    8689            0 :   return die_copy;
    8690              : }
    8691              : 
    8692              : /* Helper for copy_dwarf_procs_ref_in_dies.  Look for references to DWARF
    8693              :    procedures in DIE's attributes.  */
    8694              : 
    8695              : static void
    8696          344 : copy_dwarf_procs_ref_in_attrs (dw_die_ref die,
    8697              :                                comdat_type_node *type_node,
    8698              :                                hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
    8699              : {
    8700          344 :   dw_attr_node *a;
    8701          344 :   unsigned i;
    8702              : 
    8703         1960 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, i, a)
    8704              :     {
    8705         1616 :       dw_loc_descr_ref loc;
    8706              : 
    8707         1616 :       if (a->dw_attr_val.val_class != dw_val_class_loc)
    8708         1616 :         continue;
    8709              : 
    8710            0 :       for (loc = a->dw_attr_val.v.val_loc; loc != NULL; loc = loc->dw_loc_next)
    8711              :         {
    8712            0 :           switch (loc->dw_loc_opc)
    8713              :             {
    8714            0 :             case DW_OP_call2:
    8715            0 :             case DW_OP_call4:
    8716            0 :             case DW_OP_call_ref:
    8717            0 :               gcc_assert (loc->dw_loc_oprnd1.val_class
    8718              :                           == dw_val_class_die_ref);
    8719            0 :               loc->dw_loc_oprnd1.v.val_die_ref.die
    8720            0 :                 = copy_dwarf_procedure (loc->dw_loc_oprnd1.v.val_die_ref.die,
    8721              :                                         type_node,
    8722              :                                         copied_dwarf_procs);
    8723              : 
    8724            0 :             default:
    8725            0 :               break;
    8726              :             }
    8727              :         }
    8728              :     }
    8729          344 : }
    8730              : 
    8731              : /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
    8732              :    rewrite references to point to the copies.
    8733              : 
    8734              :    References are looked for in DIE's attributes and recursively in all its
    8735              :    children attributes that are location descriptions. COPIED_DWARF_PROCS is a
    8736              :    mapping from old DWARF procedures to their copy. It is used not to copy
    8737              :    twice the same DWARF procedure under TYPE_NODE.  */
    8738              : 
    8739              : static void
    8740          344 : copy_dwarf_procs_ref_in_dies (dw_die_ref die,
    8741              :                               comdat_type_node *type_node,
    8742              :                               hash_map<dw_die_ref, dw_die_ref> &copied_dwarf_procs)
    8743              : {
    8744          344 :   dw_die_ref c;
    8745              : 
    8746          344 :   copy_dwarf_procs_ref_in_attrs (die, type_node, copied_dwarf_procs);
    8747          607 :   FOR_EACH_CHILD (die, c, copy_dwarf_procs_ref_in_dies (c,
    8748              :                                                         type_node,
    8749              :                                                         copied_dwarf_procs));
    8750          344 : }
    8751              : 
    8752              : /* Traverse the DIE and set up additional .debug_types or .debug_info
    8753              :    DW_UT_*type sections for each type worthy of being placed in a COMDAT
    8754              :    section.  */
    8755              : 
    8756              : static void
    8757          150 : break_out_comdat_types (dw_die_ref die)
    8758              : {
    8759          150 :   dw_die_ref c;
    8760          150 :   dw_die_ref first;
    8761          150 :   dw_die_ref prev = NULL;
    8762          150 :   dw_die_ref next = NULL;
    8763          150 :   dw_die_ref unit = NULL;
    8764              : 
    8765          150 :   first = c = die->die_child;
    8766          150 :   if (c)
    8767          144 :     next = c->die_sib;
    8768          144 :   if (c) do {
    8769          766 :     if (prev == NULL || prev->die_sib == c)
    8770          736 :       prev = c;
    8771          766 :     c = next;
    8772          766 :     next = (c == first ? NULL : c->die_sib);
    8773          766 :     if (should_move_die_to_comdat (c))
    8774              :       {
    8775           81 :         dw_die_ref replacement;
    8776           81 :         comdat_type_node *type_node;
    8777              : 
    8778              :         /* Break out nested types into their own type units.  */
    8779           81 :         break_out_comdat_types (c);
    8780              : 
    8781              :         /* Create a new type unit DIE as the root for the new tree.  */
    8782           81 :         unit = new_die (DW_TAG_type_unit, NULL, NULL);
    8783           81 :         add_AT_unsigned (unit, DW_AT_language,
    8784           81 :                          get_AT_unsigned (comp_unit_die (), DW_AT_language));
    8785           81 :         if (unsigned lname = get_AT_unsigned (comp_unit_die (),
    8786              :                                               DW_AT_language_name))
    8787              :           {
    8788           16 :             add_AT_unsigned (unit, DW_AT_language_name, lname);
    8789           16 :             add_AT_unsigned (unit, DW_AT_language_version,
    8790           16 :                              get_AT_unsigned (comp_unit_die (),
    8791              :                                               DW_AT_language_version));
    8792              :           }
    8793              : 
    8794              :         /* Add the new unit's type DIE into the comdat type list.  */
    8795           81 :         type_node = ggc_cleared_alloc<comdat_type_node> ();
    8796           81 :         type_node->root_die = unit;
    8797           81 :         type_node->next = comdat_type_list;
    8798           81 :         comdat_type_list = type_node;
    8799              : 
    8800              :         /* Generate the type signature.  */
    8801           81 :         generate_type_signature (c, type_node);
    8802              : 
    8803              :         /* Copy the declaration context, attributes, and children of the
    8804              :            declaration into the new type unit DIE, then remove this DIE
    8805              :            from the main CU (or replace it with a skeleton if necessary).  */
    8806           81 :         replacement = remove_child_or_replace_with_skeleton (unit, c, prev);
    8807           81 :         type_node->skeleton_die = replacement;
    8808              : 
    8809              :         /* Add the DIE to the new compunit.  */
    8810           81 :         add_child_die (unit, c);
    8811              : 
    8812              :         /* Types can reference DWARF procedures for type size or data location
    8813              :            expressions.  Calls in DWARF expressions cannot target procedures
    8814              :            that are not in the same section.  So we must copy DWARF procedures
    8815              :            along with this type and then rewrite references to them.  */
    8816           81 :         hash_map<dw_die_ref, dw_die_ref> copied_dwarf_procs;
    8817           81 :         copy_dwarf_procs_ref_in_dies (c, type_node, copied_dwarf_procs);
    8818              : 
    8819           81 :         if (replacement != NULL)
    8820           51 :           c = replacement;
    8821           81 :       }
    8822          685 :     else if (c->die_tag == DW_TAG_namespace
    8823              :              || c->die_tag == DW_TAG_class_type
    8824              :              || c->die_tag == DW_TAG_structure_type
    8825              :              || c->die_tag == DW_TAG_union_type)
    8826              :       {
    8827              :         /* Look for nested types that can be broken out.  */
    8828           33 :         break_out_comdat_types (c);
    8829              :       }
    8830          766 :   } while (next != NULL);
    8831          150 : }
    8832              : 
    8833              : /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
    8834              :    Enter all the cloned children into the hash table decl_table.  */
    8835              : 
    8836              : static dw_die_ref
    8837            8 : clone_tree_partial (dw_die_ref die, decl_hash_type *decl_table)
    8838              : {
    8839            8 :   dw_die_ref c;
    8840            8 :   dw_die_ref clone;
    8841            8 :   struct decl_table_entry *entry;
    8842            8 :   decl_table_entry **slot;
    8843              : 
    8844            8 :   if (die->die_tag == DW_TAG_subprogram)
    8845            0 :     clone = clone_as_declaration (die);
    8846              :   else
    8847            8 :     clone = clone_die (die);
    8848              : 
    8849            8 :   slot = decl_table->find_slot_with_hash (die,
    8850              :                                           htab_hash_pointer (die), INSERT);
    8851              : 
    8852              :   /* Assert that DIE isn't in the hash table yet.  If it would be there
    8853              :      before, the ancestors would be necessarily there as well, therefore
    8854              :      clone_tree_partial wouldn't be called.  */
    8855            8 :   gcc_assert (*slot == HTAB_EMPTY_ENTRY);
    8856              : 
    8857            8 :   entry = XCNEW (struct decl_table_entry);
    8858            8 :   entry->orig = die;
    8859            8 :   entry->copy = clone;
    8860            8 :   *slot = entry;
    8861              : 
    8862            8 :   if (die->die_tag != DW_TAG_subprogram)
    8863            8 :     FOR_EACH_CHILD (die, c,
    8864              :                     add_child_die (clone, clone_tree_partial (c, decl_table)));
    8865              : 
    8866            8 :   return clone;
    8867              : }
    8868              : 
    8869              : /* Walk the DIE and its children, looking for references to incomplete
    8870              :    or trivial types that are unmarked (i.e., that are not in the current
    8871              :    type_unit).  */
    8872              : 
    8873              : static void
    8874         1712 : copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
    8875              : {
    8876         1712 :   dw_die_ref c;
    8877         1712 :   dw_attr_node *a;
    8878         1712 :   unsigned ix;
    8879              : 
    8880         7573 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    8881              :     {
    8882         5861 :       if (AT_class (a) == dw_val_class_die_ref)
    8883              :         {
    8884         1353 :           dw_die_ref targ = AT_ref (a);
    8885         1353 :           decl_table_entry **slot;
    8886         1353 :           struct decl_table_entry *entry;
    8887              : 
    8888         1353 :           if (targ->die_mark != 0 || targ->comdat_type_p)
    8889         1118 :             continue;
    8890              : 
    8891          235 :           slot = decl_table->find_slot_with_hash (targ,
    8892              :                                                   htab_hash_pointer (targ),
    8893              :                                                   INSERT);
    8894              : 
    8895          235 :           if (*slot != HTAB_EMPTY_ENTRY)
    8896              :             {
    8897              :               /* TARG has already been copied, so we just need to
    8898              :                  modify the reference to point to the copy.  */
    8899           88 :               entry = *slot;
    8900           88 :               a->dw_attr_val.v.val_die_ref.die = entry->copy;
    8901              :             }
    8902              :           else
    8903              :             {
    8904          147 :               dw_die_ref parent = unit;
    8905          147 :               dw_die_ref copy = clone_die (targ);
    8906              : 
    8907              :               /* Record in DECL_TABLE that TARG has been copied.
    8908              :                  Need to do this now, before the recursive call,
    8909              :                  because DECL_TABLE may be expanded and SLOT
    8910              :                  would no longer be a valid pointer.  */
    8911          147 :               entry = XCNEW (struct decl_table_entry);
    8912          147 :               entry->orig = targ;
    8913          147 :               entry->copy = copy;
    8914          147 :               *slot = entry;
    8915              : 
    8916              :               /* If TARG is not a declaration DIE, we need to copy its
    8917              :                  children.  */
    8918          147 :               if (!is_declaration_die (targ))
    8919              :                 {
    8920          144 :                   FOR_EACH_CHILD (
    8921              :                       targ, c,
    8922              :                       add_child_die (copy,
    8923              :                                      clone_tree_partial (c, decl_table)));
    8924              :                 }
    8925              : 
    8926              :               /* Make sure the cloned tree is marked as part of the
    8927              :                  type unit.  */
    8928          147 :               mark_dies (copy);
    8929              : 
    8930              :               /* If TARG has surrounding context, copy its ancestor tree
    8931              :                  into the new type unit.  */
    8932          147 :               if (targ->die_parent != NULL
    8933          147 :                   && !is_unit_die (targ->die_parent))
    8934            9 :                 parent = copy_ancestor_tree (unit, targ->die_parent,
    8935              :                                              decl_table);
    8936              : 
    8937          147 :               add_child_die (parent, copy);
    8938          147 :               a->dw_attr_val.v.val_die_ref.die = copy;
    8939              : 
    8940              :               /* Make sure the newly-copied DIE is walked.  If it was
    8941              :                  installed in a previously-added context, it won't
    8942              :                  get visited otherwise.  */
    8943          147 :               if (parent != unit)
    8944              :                 {
    8945              :                   /* Find the highest point of the newly-added tree,
    8946              :                      mark each node along the way, and walk from there.  */
    8947            9 :                   parent->die_mark = 1;
    8948            9 :                   while (parent->die_parent
    8949            9 :                          && parent->die_parent->die_mark == 0)
    8950              :                     {
    8951            0 :                       parent = parent->die_parent;
    8952            0 :                       parent->die_mark = 1;
    8953              :                     }
    8954            9 :                   copy_decls_walk (unit, parent, decl_table);
    8955              :                 }
    8956              :             }
    8957              :         }
    8958              :     }
    8959              : 
    8960         2678 :   FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
    8961         1712 : }
    8962              : 
    8963              : /* Collect skeleton dies in DIE created by break_out_comdat_types already
    8964              :    and record them in DECL_TABLE.  */
    8965              : 
    8966              : static void
    8967         1533 : collect_skeleton_dies (dw_die_ref die, decl_hash_type *decl_table)
    8968              : {
    8969         1533 :   dw_die_ref c;
    8970              : 
    8971         1533 :   if (dw_attr_node *a = get_AT (die, DW_AT_signature))
    8972              :     {
    8973           63 :       dw_die_ref targ = AT_ref (a);
    8974           63 :       gcc_assert (targ->die_mark == 0 && targ->comdat_type_p);
    8975           63 :       decl_table_entry **slot
    8976           63 :         = decl_table->find_slot_with_hash (targ,
    8977              :                                            htab_hash_pointer (targ),
    8978              :                                            INSERT);
    8979           63 :       gcc_assert (*slot == HTAB_EMPTY_ENTRY);
    8980              :       /* Record in DECL_TABLE that TARG has been already copied
    8981              :          by remove_child_or_replace_with_skeleton.  */
    8982           63 :       decl_table_entry *entry = XCNEW (struct decl_table_entry);
    8983           63 :       entry->orig = targ;
    8984           63 :       entry->copy = die;
    8985           63 :       *slot = entry;
    8986              :     }
    8987         2949 :   FOR_EACH_CHILD (die, c, collect_skeleton_dies (c, decl_table));
    8988         1533 : }
    8989              : 
    8990              : /* Copy declarations for "unworthy" types into the new comdat section.
    8991              :    Incomplete types, modified types, and certain other types aren't broken
    8992              :    out into comdat sections of their own, so they don't have a signature,
    8993              :    and we need to copy the declaration into the same section so that we
    8994              :    don't have an external reference.  */
    8995              : 
    8996              : static void
    8997          117 : copy_decls_for_unworthy_types (dw_die_ref unit)
    8998              : {
    8999          117 :   mark_dies (unit);
    9000          117 :   decl_hash_type decl_table (10);
    9001          117 :   collect_skeleton_dies (unit, &decl_table);
    9002          117 :   copy_decls_walk (unit, unit, &decl_table);
    9003          117 :   unmark_dies (unit);
    9004          117 : }
    9005              : 
    9006              : /* Traverse the DIE and add a sibling attribute if it may have the
    9007              :    effect of speeding up access to siblings.  To save some space,
    9008              :    avoid generating sibling attributes for DIE's without children.  */
    9009              : 
    9010              : static void
    9011     85909897 : add_sibling_attributes (dw_die_ref die)
    9012              : {
    9013     85909897 :   dw_die_ref c;
    9014              : 
    9015     85909897 :   if (! die->die_child)
    9016              :     return;
    9017              : 
    9018     22602688 :   if (die->die_parent && die != die->die_parent->die_child)
    9019     17175486 :     add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
    9020              : 
    9021     85855241 :   FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
    9022              : }
    9023              : 
    9024              : /* Output all location lists for the DIE and its children.  */
    9025              : 
    9026              : static void
    9027     78507922 : output_location_lists (dw_die_ref die)
    9028              : {
    9029     78507922 :   dw_die_ref c;
    9030     78507922 :   dw_attr_node *a;
    9031     78507922 :   unsigned ix;
    9032              : 
    9033    386084558 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9034    307576636 :     if (AT_class (a) == dw_val_class_loc_list)
    9035     12235684 :       output_loc_list (AT_loc_list (a));
    9036              : 
    9037    156982189 :   FOR_EACH_CHILD (die, c, output_location_lists (c));
    9038     78507922 : }
    9039              : 
    9040              : /* During assign_location_list_indexes and output_loclists_offset the
    9041              :    current index, after it the number of assigned indexes (i.e. how
    9042              :    large the .debug_loclists* offset table should be).  */
    9043              : static unsigned int loc_list_idx;
    9044              : 
    9045              : /* Output all location list offsets for the DIE and its children.  */
    9046              : 
    9047              : static void
    9048           26 : output_loclists_offsets (dw_die_ref die)
    9049              : {
    9050           26 :   dw_die_ref c;
    9051           26 :   dw_attr_node *a;
    9052           26 :   unsigned ix;
    9053              : 
    9054          155 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9055          129 :     if (AT_class (a) == dw_val_class_loc_list)
    9056              :       {
    9057            2 :         dw_loc_list_ref l = AT_loc_list (a);
    9058            2 :         if (l->offset_emitted)
    9059            0 :           continue;
    9060            2 :         dw2_asm_output_delta (dwarf_offset_size, l->ll_symbol,
    9061              :                               loc_section_label, NULL);
    9062            2 :         gcc_assert (l->hash == loc_list_idx);
    9063            2 :         loc_list_idx++;
    9064            2 :         l->offset_emitted = true;
    9065              :       }
    9066              : 
    9067           50 :   FOR_EACH_CHILD (die, c, output_loclists_offsets (c));
    9068           26 : }
    9069              : 
    9070              : /* Recursively set indexes of location lists.  */
    9071              : 
    9072              : static void
    9073           26 : assign_location_list_indexes (dw_die_ref die)
    9074              : {
    9075           26 :   dw_die_ref c;
    9076           26 :   dw_attr_node *a;
    9077           26 :   unsigned ix;
    9078              : 
    9079          155 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9080          129 :     if (AT_class (a) == dw_val_class_loc_list)
    9081              :       {
    9082            2 :         dw_loc_list_ref list = AT_loc_list (a);
    9083            2 :         if (!list->num_assigned)
    9084              :           {
    9085            2 :             list->num_assigned = true;
    9086            2 :             list->hash = loc_list_idx++;
    9087              :           }
    9088              :       }
    9089              : 
    9090           50 :   FOR_EACH_CHILD (die, c, assign_location_list_indexes (c));
    9091           26 : }
    9092              : 
    9093              : /* We want to limit the number of external references, because they are
    9094              :    larger than local references: a relocation takes multiple words, and
    9095              :    even a sig8 reference is always eight bytes, whereas a local reference
    9096              :    can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
    9097              :    So if we encounter multiple external references to the same type DIE, we
    9098              :    make a local typedef stub for it and redirect all references there.
    9099              : 
    9100              :    This is the element of the hash table for keeping track of these
    9101              :    references.  */
    9102              : 
    9103              : struct external_ref
    9104              : {
    9105              :   dw_die_ref type;
    9106              :   dw_die_ref stub;
    9107              :   unsigned n_refs;
    9108              : };
    9109              : 
    9110              : /* Hashtable helpers.  */
    9111              : 
    9112              : struct external_ref_hasher : free_ptr_hash <external_ref>
    9113              : {
    9114              :   static inline hashval_t hash (const external_ref *);
    9115              :   static inline bool equal (const external_ref *, const external_ref *);
    9116              : };
    9117              : 
    9118              : inline hashval_t
    9119         1373 : external_ref_hasher::hash (const external_ref *r)
    9120              : {
    9121         1373 :   dw_die_ref die = r->type;
    9122         1373 :   hashval_t h = 0;
    9123              : 
    9124              :   /* We can't use the address of the DIE for hashing, because
    9125              :      that will make the order of the stub DIEs non-deterministic.  */
    9126         1373 :   if (! die->comdat_type_p)
    9127              :     /* We have a symbol; use it to compute a hash.  */
    9128            0 :     h = htab_hash_string (die->die_id.die_symbol);
    9129              :   else
    9130              :     {
    9131              :       /* We have a type signature; use a subset of the bits as the hash.
    9132              :          The 8-byte signature is at least as large as hashval_t.  */
    9133         1373 :       comdat_type_node *type_node = die->die_id.die_type_node;
    9134         1373 :       memcpy (&h, type_node->signature, sizeof (h));
    9135              :     }
    9136         1373 :   return h;
    9137              : }
    9138              : 
    9139              : inline bool
    9140         1031 : external_ref_hasher::equal (const external_ref *r1, const external_ref *r2)
    9141              : {
    9142         1031 :   return r1->type == r2->type;
    9143              : }
    9144              : 
    9145              : typedef hash_table<external_ref_hasher> external_ref_hash_type;
    9146              : 
    9147              : /* Return a pointer to the external_ref for references to DIE.  */
    9148              : 
    9149              : static struct external_ref *
    9150          493 : lookup_external_ref (external_ref_hash_type *map, dw_die_ref die)
    9151              : {
    9152          493 :   struct external_ref ref, *ref_p;
    9153          493 :   external_ref **slot;
    9154              : 
    9155          493 :   ref.type = die;
    9156          493 :   slot = map->find_slot (&ref, INSERT);
    9157          493 :   if (*slot != HTAB_EMPTY_ENTRY)
    9158              :     return *slot;
    9159              : 
    9160           88 :   ref_p = XCNEW (struct external_ref);
    9161           88 :   ref_p->type = die;
    9162           88 :   *slot = ref_p;
    9163           88 :   return ref_p;
    9164              : }
    9165              : 
    9166              : /* Subroutine of optimize_external_refs, below.
    9167              : 
    9168              :    If we see a type skeleton, record it as our stub.  If we see external
    9169              :    references, remember how many we've seen.  */
    9170              : 
    9171              : static void
    9172     85908827 : optimize_external_refs_1 (dw_die_ref die, external_ref_hash_type *map)
    9173              : {
    9174     85908827 :   dw_die_ref c;
    9175     85908827 :   dw_attr_node *a;
    9176     85908827 :   unsigned ix;
    9177     85908827 :   struct external_ref *ref_p;
    9178              : 
    9179     85908827 :   if (is_type_die (die)
    9180     85908827 :       && (c = get_AT_ref (die, DW_AT_signature)))
    9181              :     {
    9182              :       /* This is a local skeleton; use it for local references.  */
    9183           51 :       ref_p = lookup_external_ref (map, c);
    9184           51 :       ref_p->stub = die;
    9185              :     }
    9186              : 
    9187              :   /* Scan the DIE references, and remember any that refer to DIEs from
    9188              :      other CUs (i.e. those which are not marked).  */
    9189    423114327 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9190    337205500 :     if (AT_class (a) == dw_val_class_die_ref
    9191     99030701 :         && (c = AT_ref (a))->die_mark == 0
    9192    337235476 :         && is_type_die (c))
    9193              :       {
    9194          215 :         ref_p = lookup_external_ref (map, c);
    9195          215 :         ref_p->n_refs++;
    9196              :       }
    9197              : 
    9198    149161370 :   FOR_EACH_CHILD (die, c, optimize_external_refs_1 (c, map));
    9199     85908827 : }
    9200              : 
    9201              : /* htab_traverse callback function for optimize_external_refs, below.  SLOT
    9202              :    points to an external_ref, DATA is the CU we're processing.  If we don't
    9203              :    already have a local stub, and we have multiple refs, build a stub.  */
    9204              : 
    9205              : int
    9206           88 : dwarf2_build_local_stub (external_ref **slot, dw_die_ref data)
    9207              : {
    9208           88 :   struct external_ref *ref_p = *slot;
    9209              : 
    9210           88 :   if (ref_p->stub == NULL && ref_p->n_refs > 1 && !dwarf_strict)
    9211              :     {
    9212              :       /* We have multiple references to this type, so build a small stub.
    9213              :          Both of these forms are a bit dodgy from the perspective of the
    9214              :          DWARF standard, since technically they should have names.  */
    9215           12 :       dw_die_ref cu = data;
    9216           12 :       dw_die_ref type = ref_p->type;
    9217           12 :       dw_die_ref stub = NULL;
    9218              : 
    9219           12 :       if (type->comdat_type_p)
    9220              :         {
    9221              :           /* If we refer to this type via sig8, use AT_signature.  */
    9222           12 :           stub = new_die (type->die_tag, cu, NULL_TREE);
    9223           12 :           add_AT_die_ref (stub, DW_AT_signature, type);
    9224              :         }
    9225              :       else
    9226              :         {
    9227              :           /* Otherwise, use a typedef with no name.  */
    9228            0 :           stub = new_die (DW_TAG_typedef, cu, NULL_TREE);
    9229            0 :           add_AT_die_ref (stub, DW_AT_type, type);
    9230              :         }
    9231              : 
    9232           12 :       stub->die_mark++;
    9233           12 :       ref_p->stub = stub;
    9234              :     }
    9235           88 :   return 1;
    9236              : }
    9237              : 
    9238              : /* DIE is a unit; look through all the DIE references to see if there are
    9239              :    any external references to types, and if so, create local stubs for
    9240              :    them which will be applied in build_abbrev_table.  This is useful because
    9241              :    references to local DIEs are smaller.  */
    9242              : 
    9243              : static external_ref_hash_type *
    9244        53602 : optimize_external_refs (dw_die_ref die)
    9245              : {
    9246        53602 :   external_ref_hash_type *map = new external_ref_hash_type (10);
    9247        53602 :   optimize_external_refs_1 (die, map);
    9248        53690 :   map->traverse <dw_die_ref, dwarf2_build_local_stub> (die);
    9249        53602 :   return map;
    9250              : }
    9251              : 
    9252              : /* The following 3 variables are temporaries that are computed only during the
    9253              :    build_abbrev_table call and used and released during the following
    9254              :    optimize_abbrev_table call.  */
    9255              : 
    9256              : /* First abbrev_id that can be optimized based on usage.  */
    9257              : static unsigned int abbrev_opt_start;
    9258              : 
    9259              : /* Maximum abbrev_id of a base type plus one (we can't optimize DIEs with
    9260              :    abbrev_id smaller than this, because they must be already sized
    9261              :    during build_abbrev_table).  */
    9262              : static unsigned int abbrev_opt_base_type_end;
    9263              : 
    9264              : /* Vector of usage counts during build_abbrev_table.  Indexed by
    9265              :    abbrev_id - abbrev_opt_start.  */
    9266              : static vec<unsigned int> abbrev_usage_count;
    9267              : 
    9268              : /* Vector of all DIEs added with die_abbrev >= abbrev_opt_start.  */
    9269              : static vec<dw_die_ref> sorted_abbrev_dies;
    9270              : 
    9271              : /* The format of each DIE (and its attribute value pairs) is encoded in an
    9272              :    abbreviation table.  This routine builds the abbreviation table and assigns
    9273              :    a unique abbreviation id for each abbreviation entry.  The children of each
    9274              :    die are visited recursively.  */
    9275              : 
    9276              : static void
    9277     85908839 : build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
    9278              : {
    9279     85908839 :   unsigned int abbrev_id = 0;
    9280     85908839 :   dw_die_ref c;
    9281     85908839 :   dw_attr_node *a;
    9282     85908839 :   unsigned ix;
    9283     85908839 :   dw_die_ref abbrev;
    9284              : 
    9285              :   /* Scan the DIE references, and replace any that refer to
    9286              :      DIEs from other CUs (i.e. those which are not marked) with
    9287              :      the local stubs we built in optimize_external_refs.  */
    9288    423114351 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9289    337205512 :     if (AT_class (a) == dw_val_class_die_ref
    9290    337205512 :         && (c = AT_ref (a))->die_mark == 0)
    9291              :       {
    9292        29988 :         struct external_ref *ref_p;
    9293        29988 :         gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
    9294              : 
    9295        29988 :         if (is_type_die (c)
    9296          227 :             && (ref_p = lookup_external_ref (extern_map, c))
    9297        30215 :             && ref_p->stub && ref_p->stub != die)
    9298              :           {
    9299          139 :             gcc_assert (a->dw_attr != DW_AT_signature);
    9300          139 :             change_AT_die_ref (a, ref_p->stub);
    9301              :           }
    9302              :         else
    9303              :           /* We aren't changing this reference, so mark it external.  */
    9304        29849 :           set_AT_ref_external (a, 1);
    9305              :       }
    9306              : 
    9307   9244452292 :   FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
    9308              :     {
    9309   9241515885 :       dw_attr_node *die_a, *abbrev_a;
    9310   9241515885 :       unsigned ix;
    9311   9241515885 :       bool ok = true;
    9312              : 
    9313   9241515885 :       if (abbrev_id == 0)
    9314     85908839 :         continue;
    9315   9155607046 :       if (abbrev->die_tag != die->die_tag)
    9316   8479264659 :         continue;
    9317    676342387 :       if ((abbrev->die_child != NULL) != (die->die_child != NULL))
    9318     47014774 :         continue;
    9319              : 
    9320   1886917299 :       if (vec_safe_length (abbrev->die_attr) != vec_safe_length (die->die_attr))
    9321    474370807 :         continue;
    9322              : 
    9323    645357475 :       FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, die_a)
    9324              :         {
    9325    562385043 :           abbrev_a = &(*abbrev->die_attr)[ix];
    9326    562385043 :           if ((abbrev_a->dw_attr != die_a->dw_attr)
    9327    562385043 :               || (value_format (abbrev_a) != value_format (die_a)))
    9328              :             {
    9329              :               ok = false;
    9330              :               break;
    9331              :             }
    9332              :         }
    9333    154956806 :       if (ok)
    9334              :         break;
    9335              :     }
    9336              : 
    9337     85908839 :   if (abbrev_id >= vec_safe_length (abbrev_die_table))
    9338              :     {
    9339      2936407 :       vec_safe_push (abbrev_die_table, die);
    9340      2936407 :       if (abbrev_opt_start)
    9341      2936037 :         abbrev_usage_count.safe_push (0);
    9342              :     }
    9343     85908839 :   if (abbrev_opt_start && abbrev_id >= abbrev_opt_start)
    9344              :     {
    9345     85880255 :       abbrev_usage_count[abbrev_id - abbrev_opt_start]++;
    9346     85880255 :       sorted_abbrev_dies.safe_push (die);
    9347              :     }
    9348              : 
    9349     85908839 :   die->die_abbrev = abbrev_id;
    9350    149161394 :   FOR_EACH_CHILD (die, c, build_abbrev_table (c, extern_map));
    9351     85908839 : }
    9352              : 
    9353              : /* Callback function for sorted_abbrev_dies vector sorting.  We sort
    9354              :    by die_abbrev's usage count, from the most commonly used
    9355              :    abbreviation to the least.  */
    9356              : 
    9357              : static int
    9358   5376308563 : die_abbrev_cmp (const void *p1, const void *p2)
    9359              : {
    9360   5376308563 :   dw_die_ref die1 = *(const dw_die_ref *) p1;
    9361   5376308563 :   dw_die_ref die2 = *(const dw_die_ref *) p2;
    9362              : 
    9363   5376308563 :   gcc_checking_assert (die1->die_abbrev >= abbrev_opt_start);
    9364   5376308563 :   gcc_checking_assert (die2->die_abbrev >= abbrev_opt_start);
    9365              : 
    9366   5376308563 :   if (die1->die_abbrev >= abbrev_opt_base_type_end
    9367   5376308563 :       && die2->die_abbrev >= abbrev_opt_base_type_end)
    9368              :     {
    9369   5376308563 :       if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
    9370   5376308563 :           > abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
    9371              :         return -1;
    9372   3016425987 :       if (abbrev_usage_count[die1->die_abbrev - abbrev_opt_start]
    9373   3016425987 :           < abbrev_usage_count[die2->die_abbrev - abbrev_opt_start])
    9374              :         return 1;
    9375              :     }
    9376              : 
    9377              :   /* Stabilize the sort.  */
    9378   1056560739 :   if (die1->die_abbrev < die2->die_abbrev)
    9379              :     return -1;
    9380    900071605 :   if (die1->die_abbrev > die2->die_abbrev)
    9381    159658995 :     return 1;
    9382              : 
    9383              :   return 0;
    9384              : }
    9385              : 
    9386              : /* Convert dw_val_class_const and dw_val_class_unsigned_const class attributes
    9387              :    of DIEs in between sorted_abbrev_dies[first_id] and abbrev_dies[end_id - 1]
    9388              :    into dw_val_class_const_implicit or
    9389              :    dw_val_class_unsigned_const_implicit.  */
    9390              : 
    9391              : static void
    9392      2913324 : optimize_implicit_const (unsigned int first_id, unsigned int end,
    9393              :                          vec<bool> &implicit_consts)
    9394              : {
    9395              :   /* It never makes sense if there is just one DIE using the abbreviation.  */
    9396      2913324 :   if (end < first_id + 2)
    9397      2913324 :     return;
    9398              : 
    9399      1746752 :   dw_attr_node *a;
    9400      1746752 :   unsigned ix, i;
    9401      1746752 :   dw_die_ref die = sorted_abbrev_dies[first_id];
    9402     11357795 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9403      9611043 :     if (implicit_consts[ix])
    9404              :       {
    9405      1168945 :         enum dw_val_class new_class = dw_val_class_none;
    9406      1168945 :         switch (AT_class (a))
    9407              :           {
    9408       751451 :           case dw_val_class_unsigned_const:
    9409       751451 :             if ((HOST_WIDE_INT) AT_unsigned (a) < 0)
    9410         1308 :               continue;
    9411              : 
    9412              :             /* The .debug_abbrev section will grow by
    9413              :                size_of_sleb128 (AT_unsigned (a)) and we avoid the constants
    9414              :                in all the DIEs using that abbreviation.  */
    9415       750143 :             if (constant_size (AT_unsigned (a)) * (end - first_id)
    9416       750143 :                 <= (unsigned) size_of_sleb128 (AT_unsigned (a)))
    9417        15132 :               continue;
    9418              : 
    9419              :             new_class = dw_val_class_unsigned_const_implicit;
    9420              :             break;
    9421              : 
    9422              :           case dw_val_class_const:
    9423              :             new_class = dw_val_class_const_implicit;
    9424              :             break;
    9425              : 
    9426       415443 :           case dw_val_class_file:
    9427       415443 :             new_class = dw_val_class_file_implicit;
    9428       415443 :             break;
    9429              : 
    9430            0 :           default:
    9431            0 :             continue;
    9432              :           }
    9433     14207655 :         for (i = first_id; i < end; i++)
    9434     13055150 :           (*sorted_abbrev_dies[i]->die_attr)[ix].dw_attr_val.val_class
    9435     26110300 :             = new_class;
    9436              :       }
    9437              : }
    9438              : 
    9439              : /* Attempt to optimize abbreviation table from abbrev_opt_start
    9440              :    abbreviation above.  */
    9441              : 
    9442              : static void
    9443        53521 : optimize_abbrev_table (void)
    9444              : {
    9445        53521 :   if (abbrev_opt_start
    9446        53521 :       && vec_safe_length (abbrev_die_table) > abbrev_opt_start
    9447       106969 :       && (dwarf_version >= 5 || vec_safe_length (abbrev_die_table) > 127))
    9448              :     {
    9449        51508 :       auto_vec<bool, 32> implicit_consts;
    9450        51508 :       sorted_abbrev_dies.qsort (die_abbrev_cmp);
    9451              : 
    9452        51508 :       unsigned int abbrev_id = abbrev_opt_start - 1;
    9453        51508 :       unsigned int first_id = ~0U;
    9454        51508 :       unsigned int last_abbrev_id = 0;
    9455        51508 :       unsigned int i;
    9456        51508 :       dw_die_ref die;
    9457        51508 :       if (abbrev_opt_base_type_end > abbrev_opt_start)
    9458            0 :         abbrev_id = abbrev_opt_base_type_end - 1;
    9459              :       /* Reassign abbreviation ids from abbrev_opt_start above, so that
    9460              :          most commonly used abbreviations come first.  */
    9461     85880134 :       FOR_EACH_VEC_ELT (sorted_abbrev_dies, i, die)
    9462              :         {
    9463     85828626 :           dw_attr_node *a;
    9464     85828626 :           unsigned ix;
    9465              : 
    9466              :           /* If calc_base_type_die_sizes has been called, the CU and
    9467              :              base types after it can't be optimized, because we've already
    9468              :              calculated their DIE offsets.  We've sorted them first.  */
    9469     85828626 :           if (die->die_abbrev < abbrev_opt_base_type_end)
    9470            0 :             continue;
    9471     85828626 :           if (die->die_abbrev != last_abbrev_id)
    9472              :             {
    9473      2913324 :               last_abbrev_id = die->die_abbrev;
    9474      2913324 :               if (dwarf_version >= 5 && first_id != ~0U)
    9475      2861816 :                 optimize_implicit_const (first_id, i, implicit_consts);
    9476      2913324 :               abbrev_id++;
    9477      2913324 :               (*abbrev_die_table)[abbrev_id] = die;
    9478      2913324 :               if (dwarf_version >= 5)
    9479              :                 {
    9480      2913324 :                   first_id = i;
    9481      2913324 :                   implicit_consts.truncate (0);
    9482              : 
    9483     22263244 :                   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9484     16436596 :                     switch (AT_class (a))
    9485              :                       {
    9486      6967202 :                       case dw_val_class_const:
    9487      6967202 :                       case dw_val_class_unsigned_const:
    9488      6967202 :                       case dw_val_class_file:
    9489      6967202 :                         implicit_consts.safe_push (true);
    9490      6967202 :                         break;
    9491      9469394 :                       default:
    9492      9469394 :                         implicit_consts.safe_push (false);
    9493      9469394 :                         break;
    9494              :                       }
    9495              :                 }
    9496              :             }
    9497     82915302 :           else if (dwarf_version >= 5)
    9498              :             {
    9499    403338674 :               FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9500    320423372 :                 if (!implicit_consts[ix])
    9501    299270042 :                   continue;
    9502              :                 else
    9503              :                   {
    9504     21153330 :                     dw_attr_node *other_a
    9505     21153330 :                       = &(*(*abbrev_die_table)[abbrev_id]->die_attr)[ix];
    9506     21153330 :                     if (!dw_val_equal_p (&a->dw_attr_val,
    9507              :                                          &other_a->dw_attr_val))
    9508      2866033 :                       implicit_consts[ix] = false;
    9509              :                   }
    9510              :             }
    9511     85828626 :           die->die_abbrev = abbrev_id;
    9512              :         }
    9513       103016 :       gcc_assert (abbrev_id == vec_safe_length (abbrev_die_table) - 1);
    9514        51508 :       if (dwarf_version >= 5 && first_id != ~0U)
    9515        51508 :         optimize_implicit_const (first_id, i, implicit_consts);
    9516        51508 :     }
    9517              : 
    9518        53521 :   abbrev_opt_start = 0;
    9519        53521 :   abbrev_opt_base_type_end = 0;
    9520        53521 :   abbrev_usage_count.release ();
    9521        53521 :   sorted_abbrev_dies.release ();
    9522        53521 : }
    9523              : 
    9524              : /* Return the power-of-two number of bytes necessary to represent VALUE.  */
    9525              : 
    9526              : static int
    9527    591239170 : constant_size (unsigned HOST_WIDE_INT value)
    9528              : {
    9529    591239170 :   int log;
    9530              : 
    9531    591239170 :   if (value == 0)
    9532              :     log = 0;
    9533              :   else
    9534    583157774 :     log = floor_log2 (value);
    9535              : 
    9536   1174396944 :   log = log / 8;
    9537    583157774 :   log = 1 << (floor_log2 (log) + 1);
    9538              : 
    9539    591239170 :   return log;
    9540              : }
    9541              : 
    9542              : /* Return the size of a DIE as it is represented in the
    9543              :    .debug_info section.  */
    9544              : 
    9545              : static unsigned long
    9546     85909106 : size_of_die (dw_die_ref die)
    9547              : {
    9548     85909106 :   unsigned long size = 0;
    9549     85909106 :   dw_attr_node *a;
    9550     85909106 :   unsigned ix;
    9551     85909106 :   enum dwarf_form form;
    9552              : 
    9553     85909106 :   size += size_of_uleb128 (die->die_abbrev);
    9554    423116449 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9555              :     {
    9556    337207343 :       switch (AT_class (a))
    9557              :         {
    9558        29826 :         case dw_val_class_addr:
    9559        29826 :           if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
    9560              :             {
    9561            0 :               gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
    9562            0 :               size += size_of_uleb128 (AT_index (a));
    9563              :             }
    9564              :           else
    9565        32866 :             size += DWARF2_ADDR_SIZE;
    9566              :           break;
    9567            0 :         case dw_val_class_offset:
    9568            0 :           size += dwarf_offset_size;
    9569            0 :           break;
    9570      7954305 :         case dw_val_class_loc:
    9571      7954305 :           {
    9572      7954305 :             unsigned long lsize = size_of_locs (AT_loc (a));
    9573              : 
    9574              :             /* Block length.  */
    9575      7954305 :             if (dwarf_version >= 4)
    9576      7943264 :               size += size_of_uleb128 (lsize);
    9577              :             else
    9578        11041 :               size += constant_size (lsize);
    9579      7954305 :             size += lsize;
    9580              :           }
    9581      7954305 :           break;
    9582     12235684 :         case dw_val_class_loc_list:
    9583     12235684 :           if (dwarf_split_debug_info && dwarf_version >= 5)
    9584              :             {
    9585            2 :               gcc_assert (AT_loc_list (a)->num_assigned);
    9586            2 :               size += size_of_uleb128 (AT_loc_list (a)->hash);
    9587              :             }
    9588              :           else
    9589     12235682 :             size += dwarf_offset_size;
    9590              :           break;
    9591     12058730 :         case dw_val_class_view_list:
    9592     12058730 :           size += dwarf_offset_size;
    9593     12058730 :           break;
    9594      3498199 :         case dw_val_class_range_list:
    9595      3498199 :           if (value_format (a) == DW_FORM_rnglistx)
    9596              :             {
    9597            3 :               gcc_assert (rnglist_idx);
    9598            3 :               dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
    9599            3 :               size += size_of_uleb128 (r->idx);
    9600              :             }
    9601              :           else
    9602      3498196 :             size += dwarf_offset_size;
    9603              :           break;
    9604        15217 :         case dw_val_class_const:
    9605        15217 :           size += size_of_sleb128 (AT_int (a));
    9606        15217 :           break;
    9607     71709575 :         case dw_val_class_unsigned_const:
    9608     71709575 :           {
    9609     71709575 :             int csize = constant_size (AT_unsigned (a));
    9610     71709575 :             if (dwarf_version == 3
    9611          690 :                 && a->dw_attr == DW_AT_data_member_location
    9612           15 :                 && csize >= 4)
    9613            1 :               size += size_of_uleb128 (AT_unsigned (a));
    9614              :             else
    9615     71709574 :               size += csize;
    9616              :           }
    9617              :           break;
    9618      6910345 :         case dw_val_class_symview:
    9619      6910345 :           if (symview_upper_bound <= 0xff)
    9620       358083 :             size += 1;
    9621      6552262 :           else if (symview_upper_bound <= 0xffff)
    9622      6552262 :             size += 2;
    9623            0 :           else if (symview_upper_bound <= 0xffffffff)
    9624            0 :             size += 4;
    9625              :           else
    9626              :             size += 8;
    9627              :           break;
    9628              :         case dw_val_class_const_implicit:
    9629              :         case dw_val_class_unsigned_const_implicit:
    9630              :         case dw_val_class_file_implicit:
    9631              :           /* These occupy no size in the DIE, just an extra sleb128 in
    9632              :              .debug_abbrev.  */
    9633              :           break;
    9634            0 :         case dw_val_class_const_double:
    9635            0 :           size += HOST_BITS_PER_DOUBLE_INT / HOST_BITS_PER_CHAR;
    9636            0 :           if (HOST_BITS_PER_WIDE_INT >= DWARF_LARGEST_DATA_FORM_BITS)
    9637            0 :             size++; /* block */
    9638              :           break;
    9639           43 :         case dw_val_class_wide_int:
    9640           43 :           size += (get_full_len (*a->dw_attr_val.v.val_wide)
    9641           43 :                    * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
    9642           43 :           if (get_full_len (*a->dw_attr_val.v.val_wide)
    9643           43 :               * HOST_BITS_PER_WIDE_INT > DWARF_LARGEST_DATA_FORM_BITS)
    9644            0 :             size++; /* block */
    9645              :           break;
    9646        20620 :         case dw_val_class_vec:
    9647        20620 :           size += constant_size (a->dw_attr_val.v.val_vec.length
    9648        20620 :                                  * a->dw_attr_val.v.val_vec.elt_size)
    9649        20620 :                   + a->dw_attr_val.v.val_vec.length
    9650              :                     * a->dw_attr_val.v.val_vec.elt_size; /* block */
    9651        20620 :           break;
    9652     28111170 :         case dw_val_class_flag:
    9653     28111170 :           if (dwarf_version >= 4)
    9654              :             /* Currently all add_AT_flag calls pass in 1 as last argument,
    9655              :                so DW_FORM_flag_present can be used.  If that ever changes,
    9656              :                we'll need to use DW_FORM_flag and have some optimization
    9657              :                in build_abbrev_table that will change those to
    9658              :                DW_FORM_flag_present if it is set to 1 in all DIEs using
    9659              :                the same abbrev entry.  */
    9660     28089926 :             gcc_assert (a->dw_attr_val.v.val_flag == 1);
    9661              :           else
    9662        21244 :             size += 1;
    9663              :           break;
    9664     99030713 :         case dw_val_class_die_ref:
    9665     99030713 :           if (AT_ref_external (a))
    9666              :             {
    9667              :               /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
    9668              :                  we use DW_FORM_ref_addr.  In DWARF2, DW_FORM_ref_addr
    9669              :                  is sized by target address length, whereas in DWARF3
    9670              :                  it's always sized as an offset.  */
    9671        29849 :               if (AT_ref (a)->comdat_type_p)
    9672           88 :                 size += DWARF_TYPE_SIGNATURE_SIZE;
    9673        29761 :               else if (dwarf_version == 2)
    9674           30 :                 size += DWARF2_ADDR_SIZE;
    9675              :               else
    9676        29731 :                 size += dwarf_offset_size;
    9677              :             }
    9678              :           else
    9679     99000864 :             size += dwarf_offset_size;
    9680              :           break;
    9681            0 :         case dw_val_class_fde_ref:
    9682            0 :           size += dwarf_offset_size;
    9683            0 :           break;
    9684     14840077 :         case dw_val_class_lbl_id:
    9685     14840077 :           if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
    9686              :             {
    9687          253 :               gcc_assert (AT_index (a) != NO_INDEX_ASSIGNED);
    9688          253 :               size += size_of_uleb128 (AT_index (a));
    9689              :             }
    9690              :           else
    9691     16000036 :             size += DWARF2_ADDR_SIZE;
    9692              :           break;
    9693        54386 :         case dw_val_class_lineptr:
    9694        54386 :         case dw_val_class_macptr:
    9695        54386 :         case dw_val_class_loclistsptr:
    9696        54386 :           size += dwarf_offset_size;
    9697        54386 :           break;
    9698     35220632 :         case dw_val_class_str:
    9699     35220632 :           form = AT_string_form (a);
    9700     35220632 :           if (form == DW_FORM_strp || form == DW_FORM_line_strp)
    9701     31961981 :             size += dwarf_offset_size;
    9702      3272814 :           else if (form == dwarf_FORM (DW_FORM_strx))
    9703          935 :             size += size_of_uleb128 (AT_index (a));
    9704              :           else
    9705      3257716 :             size += strlen (a->dw_attr_val.v.val_str->str) + 1;
    9706              :           break;
    9707     27566597 :         case dw_val_class_file:
    9708     27566597 :           size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
    9709     27566597 :           break;
    9710           71 :         case dw_val_class_data8:
    9711           71 :           size += 8;
    9712           71 :           break;
    9713            0 :         case dw_val_class_vms_delta:
    9714            0 :           size += dwarf_offset_size;
    9715            0 :           break;
    9716      4887532 :         case dw_val_class_high_pc:
    9717      4887532 :           size += DWARF2_ADDR_SIZE;
    9718      4887532 :           break;
    9719            0 :         case dw_val_class_discr_value:
    9720            0 :           size += size_of_discr_value (&a->dw_attr_val.v.val_discr_value);
    9721            0 :           break;
    9722            0 :         case dw_val_class_discr_list:
    9723            0 :             {
    9724            0 :               unsigned block_size = size_of_discr_list (AT_discr_list (a));
    9725              : 
    9726              :               /* This is a block, so we have the block length and then its
    9727              :                  data.  */
    9728            0 :               size += constant_size (block_size) + block_size;
    9729              :             }
    9730            0 :           break;
    9731            0 :         default:
    9732            0 :           gcc_unreachable ();
    9733              :         }
    9734              :     }
    9735              : 
    9736     85909106 :   return size;
    9737              : }
    9738              : 
    9739              : /* Size the debugging information associated with a given DIE.  Visits the
    9740              :    DIE's children recursively.  Updates the global variable next_die_offset, on
    9741              :    each time through.  Uses the current value of next_die_offset to update the
    9742              :    die_offset field in each DIE.  */
    9743              : 
    9744              : static void
    9745     85908839 : calc_die_sizes (dw_die_ref die)
    9746              : {
    9747     85908839 :   dw_die_ref c;
    9748              : 
    9749     85908839 :   gcc_assert (die->die_offset == 0
    9750              :               || (unsigned long int) die->die_offset == next_die_offset);
    9751     85908839 :   die->die_offset = next_die_offset;
    9752     85908839 :   next_die_offset += size_of_die (die);
    9753              : 
    9754    171764076 :   FOR_EACH_CHILD (die, c, calc_die_sizes (c));
    9755              : 
    9756     85908839 :   if (die->die_child != NULL)
    9757              :     /* Count the null byte used to terminate sibling lists.  */
    9758     22602682 :     next_die_offset += 1;
    9759     85908839 : }
    9760              : 
    9761              : /* Size just the base type children at the start of the CU.
    9762              :    This is needed because build_abbrev needs to size locs
    9763              :    and sizing of type based stack ops needs to know die_offset
    9764              :    values for the base types.  */
    9765              : 
    9766              : static void
    9767            9 : calc_base_type_die_sizes (void)
    9768              : {
    9769           18 :   unsigned long die_offset = (dwarf_split_debug_info
    9770            9 :                               ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
    9771           18 :                               : DWARF_COMPILE_UNIT_HEADER_SIZE);
    9772            9 :   unsigned int i;
    9773            9 :   dw_die_ref base_type;
    9774              : #if ENABLE_ASSERT_CHECKING
    9775            9 :   dw_die_ref prev = comp_unit_die ()->die_child;
    9776              : #endif
    9777              : 
    9778            9 :   die_offset += size_of_die (comp_unit_die ());
    9779           18 :   for (i = 0; base_types.iterate (i, &base_type); i++)
    9780              :     {
    9781              : #if ENABLE_ASSERT_CHECKING
    9782            9 :       gcc_assert (base_type->die_offset == 0
    9783              :                   && prev->die_sib == base_type
    9784              :                   && base_type->die_child == NULL
    9785              :                   && base_type->die_abbrev);
    9786            9 :       prev = base_type;
    9787              : #endif
    9788            9 :       if (abbrev_opt_start
    9789            9 :           && base_type->die_abbrev >= abbrev_opt_base_type_end)
    9790            9 :         abbrev_opt_base_type_end = base_type->die_abbrev + 1;
    9791            9 :       base_type->die_offset = die_offset;
    9792            9 :       die_offset += size_of_die (base_type);
    9793              :     }
    9794            9 : }
    9795              : 
    9796              : /* Set the marks for a die and its children.  We do this so
    9797              :    that we know whether or not a reference needs to use FORM_ref_addr; only
    9798              :    DIEs in the same CU will be marked.  We used to clear out the offset
    9799              :    and use that as the flag, but ran into ordering problems.  */
    9800              : 
    9801              : static void
    9802     85910515 : mark_dies (dw_die_ref die)
    9803              : {
    9804     85910515 :   dw_die_ref c;
    9805              : 
    9806     85910515 :   gcc_assert (!die->die_mark);
    9807              : 
    9808     85910515 :   die->die_mark = 1;
    9809    171767164 :   FOR_EACH_CHILD (die, c, mark_dies (c));
    9810     85910515 : }
    9811              : 
    9812              : /* Clear the marks for a die and its children.  */
    9813              : 
    9814              : static void
    9815       238460 : unmark_dies (dw_die_ref die)
    9816              : {
    9817       238460 :   dw_die_ref c;
    9818              : 
    9819       238460 :   if (! use_debug_types)
    9820       236057 :     gcc_assert (die->die_mark);
    9821              : 
    9822       238460 :   die->die_mark = 0;
    9823       475384 :   FOR_EACH_CHILD (die, c, unmark_dies (c));
    9824       238460 : }
    9825              : 
    9826              : /* Clear the marks for a die, its children and referred dies.  */
    9827              : 
    9828              : static void
    9829       533574 : unmark_all_dies (dw_die_ref die)
    9830              : {
    9831       533574 :   dw_die_ref c;
    9832       533574 :   dw_attr_node *a;
    9833       533574 :   unsigned ix;
    9834              : 
    9835       533574 :   if (!die->die_mark)
    9836       533574 :     return;
    9837       237169 :   die->die_mark = 0;
    9838              : 
    9839       411941 :   FOR_EACH_CHILD (die, c, unmark_all_dies (c));
    9840              : 
    9841      1169169 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
    9842       932000 :     if (AT_class (a) == dw_val_class_die_ref)
    9843       296396 :       unmark_all_dies (AT_ref (a));
    9844              : }
    9845              : 
    9846              : /* Calculate if the entry should appear in the final output file.  It may be
    9847              :    from a pruned a type.  */
    9848              : 
    9849              : static bool
    9850         1724 : include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
    9851              : {
    9852              :   /* By limiting gnu pubnames to definitions only, gold can generate a
    9853              :      gdb index without entries for declarations, which don't include
    9854              :      enough information to be useful.  */
    9855         1724 :   if (debug_generate_pub_sections == 2 && is_declaration_die (p->die))
    9856              :     return false;
    9857              : 
    9858         1594 :   if (table == pubname_table)
    9859              :     {
    9860              :       /* Enumerator names are part of the pubname table, but the
    9861              :          parent DW_TAG_enumeration_type die may have been pruned.
    9862              :          Don't output them if that is the case.  */
    9863         1014 :       if (p->die->die_tag == DW_TAG_enumerator &&
    9864           72 :           (p->die->die_parent == NULL
    9865           72 :            || !p->die->die_parent->die_perennial_p))
    9866              :         return false;
    9867              : 
    9868              :       /* Everything else in the pubname table is included.  */
    9869              :       return true;
    9870              :     }
    9871              : 
    9872              :   /* The pubtypes table shouldn't include types that have been
    9873              :      pruned.  */
    9874          580 :   return (p->die->die_offset != 0
    9875          580 :           || !flag_eliminate_unused_debug_types);
    9876              : }
    9877              : 
    9878              : /* Return the size of the .debug_pubnames or .debug_pubtypes table
    9879              :    generated for the compilation unit.  */
    9880              : 
    9881              : static unsigned long
    9882          512 : size_of_pubnames (vec<pubname_entry, va_gc> *names)
    9883              : {
    9884          512 :   unsigned long size;
    9885          512 :   unsigned i;
    9886          512 :   pubname_entry *p;
    9887          512 :   int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0;
    9888              : 
    9889          512 :   size = DWARF_PUBNAMES_HEADER_SIZE;
    9890         1374 :   FOR_EACH_VEC_ELT (*names, i, p)
    9891          862 :     if (include_pubname_in_output (names, p))
    9892          791 :       size += strlen (p->name) + dwarf_offset_size + 1 + space_for_flags;
    9893              : 
    9894          512 :   size += dwarf_offset_size;
    9895          512 :   return size;
    9896              : }
    9897              : 
    9898              : /* Return the size of the information in the .debug_aranges section.  */
    9899              : 
    9900              : static unsigned long
    9901        52183 : size_of_aranges (void)
    9902              : {
    9903        52183 :   unsigned long size;
    9904              : 
    9905        64861 :   size = DWARF_ARANGES_HEADER_SIZE;
    9906              : 
    9907              :   /* Count the address/length pair for this compilation unit.  */
    9908        52183 :   if (switch_text_ranges)
    9909        32686 :     size += 2 * DWARF2_ADDR_SIZE
    9910        29610 :             * (vec_safe_length (switch_text_ranges) / 2 + 1);
    9911        52183 :   if (switch_cold_ranges)
    9912         9642 :     size += 2 * DWARF2_ADDR_SIZE
    9913         9320 :             * (vec_safe_length (switch_cold_ranges) / 2 + 1);
    9914        52183 :   if (have_multiple_function_sections)
    9915              :     {
    9916              :       unsigned fde_idx;
    9917              :       dw_fde_ref fde;
    9918              : 
    9919       300656 :       FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
    9920              :         {
    9921       271276 :           if (fde->ignored_debug)
    9922         2546 :             continue;
    9923       268730 :           if (!fde->in_std_section)
    9924       206800 :             size += 2 * DWARF2_ADDR_SIZE;
    9925       268730 :           if (fde->dw_fde_second_begin && !fde->second_in_std_section)
    9926        11221 :             size += 2 * DWARF2_ADDR_SIZE;
    9927              :         }
    9928              :     }
    9929              : 
    9930              :   /* Count the two zero words used to terminated the address range table.  */
    9931        52183 :   size += 2 * DWARF2_ADDR_SIZE;
    9932        52183 :   return size;
    9933              : }
    9934              : 
    9935              : /* Select the encoding of an attribute value.  */
    9936              : 
    9937              : static enum dwarf_form
    9938   1087480297 : value_format (dw_attr_node *a)
    9939              : {
    9940   1087480297 :   switch (AT_class (a))
    9941              :     {
    9942        60314 :     case dw_val_class_addr:
    9943              :       /* Only very few attributes allow DW_FORM_addr.  */
    9944        60314 :       switch (a->dw_attr)
    9945              :         {
    9946        60314 :         case DW_AT_low_pc:
    9947        60314 :         case DW_AT_high_pc:
    9948        60314 :         case DW_AT_entry_pc:
    9949        60314 :         case DW_AT_trampoline:
    9950        60314 :           return (AT_index (a) == NOT_INDEXED
    9951        60314 :                   ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
    9952            0 :         default:
    9953            0 :           break;
    9954              :         }
    9955            0 :       switch (DWARF2_ADDR_SIZE)
    9956              :         {
    9957              :         case 1:
    9958              :           return DW_FORM_data1;
    9959              :         case 2:
    9960              :           return DW_FORM_data2;
    9961              :         case 4:
    9962              :           return DW_FORM_data4;
    9963              :         case 8:
    9964              :           return DW_FORM_data8;
    9965              :         default:
    9966              :           gcc_unreachable ();
    9967              :         }
    9968     24477319 :     case dw_val_class_loc_list:
    9969     24477319 :       if (dwarf_split_debug_info
    9970            4 :           && dwarf_version >= 5
    9971     24477323 :           && AT_loc_list (a)->num_assigned)
    9972              :         return DW_FORM_loclistx;
    9973              :       /* FALLTHRU */
    9974     62333174 :     case dw_val_class_view_list:
    9975     62333174 :     case dw_val_class_range_list:
    9976              :       /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
    9977              :          but in .debug_info use DW_FORM_sec_offset, which is shorter if we
    9978              :          care about sizes of .debug* sections in shared libraries and
    9979              :          executables and don't take into account relocations that affect just
    9980              :          relocatable objects - for DW_FORM_rnglistx we'd have to emit offset
    9981              :          table in the .debug_rnglists section.  */
    9982     62333174 :       if (dwarf_split_debug_info
    9983           19 :           && dwarf_version >= 5
    9984           19 :           && AT_class (a) == dw_val_class_range_list
    9985           15 :           && rnglist_idx
    9986     62333189 :           && a->dw_attr_val.val_entry != RELOCATED_OFFSET)
    9987              :         return DW_FORM_rnglistx;
    9988     62333165 :       if (dwarf_version >= 4)
    9989              :         return DW_FORM_sec_offset;
    9990              :       /* FALLTHRU */
    9991        18101 :     case dw_val_class_vms_delta:
    9992        18101 :     case dw_val_class_offset:
    9993        18101 :       switch (dwarf_offset_size)
    9994              :         {
    9995              :         case 4:
    9996              :           return DW_FORM_data4;
    9997              :         case 8:
    9998              :           return DW_FORM_data8;
    9999            0 :         default:
   10000            0 :           gcc_unreachable ();
   10001              :         }
   10002     15952723 :     case dw_val_class_loc:
   10003     15952723 :       if (dwarf_version >= 4)
   10004              :         return DW_FORM_exprloc;
   10005        22263 :       switch (constant_size (size_of_locs (AT_loc (a))))
   10006              :         {
   10007              :         case 1:
   10008              :           return DW_FORM_block1;
   10009              :         case 2:
   10010              :           return DW_FORM_block2;
   10011              :         case 4:
   10012              :           return DW_FORM_block4;
   10013            0 :         default:
   10014            0 :           gcc_unreachable ();
   10015              :         }
   10016              :     case dw_val_class_const:
   10017              :       return DW_FORM_sdata;
   10018    257060882 :     case dw_val_class_unsigned_const:
   10019    257060882 :       switch (constant_size (AT_unsigned (a)))
   10020              :         {
   10021              :         case 1:
   10022              :           return DW_FORM_data1;
   10023              :         case 2:
   10024              :           return DW_FORM_data2;
   10025       226178 :         case 4:
   10026              :           /* In DWARF3 DW_AT_data_member_location with
   10027              :              DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
   10028              :              constant, so we need to use DW_FORM_udata if we need
   10029              :              a large constant.  */
   10030       226178 :           if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
   10031              :             return DW_FORM_udata;
   10032              :           return DW_FORM_data4;
   10033        79432 :         case 8:
   10034        79432 :           if (dwarf_version == 3 && a->dw_attr == DW_AT_data_member_location)
   10035              :             return DW_FORM_udata;
   10036              :           return DW_FORM_data8;
   10037              :         default:
   10038              :           gcc_unreachable ();
   10039              :         }
   10040              :     case dw_val_class_const_implicit:
   10041              :     case dw_val_class_unsigned_const_implicit:
   10042              :     case dw_val_class_file_implicit:
   10043              :       return DW_FORM_implicit_const;
   10044            0 :     case dw_val_class_const_double:
   10045            0 :       switch (HOST_BITS_PER_WIDE_INT)
   10046              :         {
   10047              :         case 8:
   10048              :           return DW_FORM_data2;
   10049              :         case 16:
   10050              :           return DW_FORM_data4;
   10051              :         case 32:
   10052              :           return DW_FORM_data8;
   10053            0 :         case 64:
   10054            0 :           if (dwarf_version >= 5)
   10055              :             return DW_FORM_data16;
   10056              :           /* FALLTHRU */
   10057              :         default:
   10058              :           return DW_FORM_block1;
   10059              :         }
   10060          103 :     case dw_val_class_wide_int:
   10061          103 :       switch (get_full_len (*a->dw_attr_val.v.val_wide) * HOST_BITS_PER_WIDE_INT)
   10062              :         {
   10063              :         case 8:
   10064              :           return DW_FORM_data1;
   10065              :         case 16:
   10066              :           return DW_FORM_data2;
   10067              :         case 32:
   10068              :           return DW_FORM_data4;
   10069              :         case 64:
   10070              :           return DW_FORM_data8;
   10071          103 :         case 128:
   10072          103 :           if (dwarf_version >= 5)
   10073              :             return DW_FORM_data16;
   10074              :           /* FALLTHRU */
   10075              :         default:
   10076              :           return DW_FORM_block1;
   10077              :         }
   10078     33352078 :     case dw_val_class_symview:
   10079              :       /* ??? We might use uleb128, but then we'd have to compute
   10080              :          .debug_info offsets in the assembler.  */
   10081     33352078 :       if (symview_upper_bound <= 0xff)
   10082              :         return DW_FORM_data1;
   10083     31871790 :       else if (symview_upper_bound <= 0xffff)
   10084              :         return DW_FORM_data2;
   10085              :       else if (symview_upper_bound <= 0xffffffff)
   10086              :         return DW_FORM_data4;
   10087              :       else
   10088              :         return DW_FORM_data8;
   10089        59352 :     case dw_val_class_vec:
   10090        59352 :       switch (constant_size (a->dw_attr_val.v.val_vec.length
   10091        59352 :                              * a->dw_attr_val.v.val_vec.elt_size))
   10092              :         {
   10093              :         case 1:
   10094              :           return DW_FORM_block1;
   10095              :         case 2:
   10096              :           return DW_FORM_block2;
   10097              :         case 4:
   10098              :           return DW_FORM_block4;
   10099            0 :         default:
   10100            0 :           gcc_unreachable ();
   10101              :         }
   10102    120234322 :     case dw_val_class_flag:
   10103    120234322 :       if (dwarf_version >= 4)
   10104              :         {
   10105              :           /* Currently all add_AT_flag calls pass in 1 as last argument,
   10106              :              so DW_FORM_flag_present can be used.  If that ever changes,
   10107              :              we'll need to use DW_FORM_flag and have some optimization
   10108              :              in build_abbrev_table that will change those to
   10109              :              DW_FORM_flag_present if it is set to 1 in all DIEs using
   10110              :              the same abbrev entry.  */
   10111    120187660 :           gcc_assert (a->dw_attr_val.v.val_flag == 1);
   10112              :           return DW_FORM_flag_present;
   10113              :         }
   10114              :       return DW_FORM_flag;
   10115    221668469 :     case dw_val_class_die_ref:
   10116    221668469 :       if (AT_ref_external (a))
   10117              :         {
   10118        71345 :           if (AT_ref (a)->comdat_type_p)
   10119              :             return DW_FORM_ref_sig8;
   10120              :           else
   10121        71164 :             return DW_FORM_ref_addr;
   10122              :         }
   10123              :       else
   10124    221597124 :         return DW_FORM_ref;
   10125            0 :     case dw_val_class_fde_ref:
   10126            0 :       return DW_FORM_data;
   10127     55762878 :     case dw_val_class_lbl_id:
   10128     55762878 :       return (AT_index (a) == NOT_INDEXED
   10129     55762878 :               ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
   10130       109872 :     case dw_val_class_lineptr:
   10131       109872 :     case dw_val_class_macptr:
   10132       109872 :     case dw_val_class_loclistsptr:
   10133       109872 :       return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
   10134    168059454 :     case dw_val_class_str:
   10135    168059454 :       return AT_string_form (a);
   10136    134730891 :     case dw_val_class_file:
   10137    134730891 :       switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
   10138              :         {
   10139              :         case 1:
   10140              :           return DW_FORM_data1;
   10141              :         case 2:
   10142              :           return DW_FORM_data2;
   10143              :         case 4:
   10144              :           return DW_FORM_data4;
   10145            0 :         default:
   10146            0 :           gcc_unreachable ();
   10147              :         }
   10148              : 
   10149              :     case dw_val_class_data8:
   10150              :       return DW_FORM_data8;
   10151              : 
   10152     15681266 :     case dw_val_class_high_pc:
   10153     15681266 :       switch (DWARF2_ADDR_SIZE)
   10154              :         {
   10155              :         case 1:
   10156              :           return DW_FORM_data1;
   10157              :         case 2:
   10158              :           return DW_FORM_data2;
   10159              :         case 4:
   10160              :           return DW_FORM_data4;
   10161              :         case 8:
   10162              :           return DW_FORM_data8;
   10163              :         default:
   10164              :           gcc_unreachable ();
   10165              :         }
   10166              : 
   10167            0 :     case dw_val_class_discr_value:
   10168            0 :       return (a->dw_attr_val.v.val_discr_value.pos
   10169            0 :               ? DW_FORM_udata
   10170              :               : DW_FORM_sdata);
   10171            0 :     case dw_val_class_discr_list:
   10172            0 :       switch (constant_size (size_of_discr_list (AT_discr_list (a))))
   10173              :         {
   10174              :         case 1:
   10175              :           return DW_FORM_block1;
   10176              :         case 2:
   10177              :           return DW_FORM_block2;
   10178              :         case 4:
   10179              :           return DW_FORM_block4;
   10180            0 :         default:
   10181            0 :           gcc_unreachable ();
   10182              :         }
   10183              : 
   10184            0 :     default:
   10185            0 :       gcc_unreachable ();
   10186              :     }
   10187              : }
   10188              : 
   10189              : /* Output the encoding of an attribute value.  */
   10190              : 
   10191              : static void
   10192     16596860 : output_value_format (dw_attr_node *a)
   10193              : {
   10194     16596860 :   enum dwarf_form form = value_format (a);
   10195              : 
   10196     33193720 :   dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
   10197     16596860 : }
   10198              : 
   10199              : /* Given a die and id, produce the appropriate abbreviations.  */
   10200              : 
   10201              : static void
   10202      2944235 : output_die_abbrevs (unsigned long abbrev_id, dw_die_ref abbrev)
   10203              : {
   10204      2944235 :   unsigned ix;
   10205      2944235 :   dw_attr_node *a_attr;
   10206              : 
   10207      2944235 :   dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
   10208      2944235 :   dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
   10209      2944235 :                                dwarf_tag_name (abbrev->die_tag));
   10210              : 
   10211      2944235 :   if (abbrev->die_child != NULL)
   10212      1427428 :     dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
   10213              :   else
   10214      1516807 :     dw2_asm_output_data (1, DW_children_no, "DW_children_no");
   10215              : 
   10216     19541095 :   for (ix = 0; vec_safe_iterate (abbrev->die_attr, ix, &a_attr); ix++)
   10217              :     {
   10218     16596860 :       dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
   10219     16596860 :                                    dwarf_attr_name (a_attr->dw_attr));
   10220     16596860 :       output_value_format (a_attr);
   10221     16596860 :       if (value_format (a_attr) == DW_FORM_implicit_const)
   10222              :         {
   10223      1154974 :           if (AT_class (a_attr) == dw_val_class_file_implicit)
   10224              :             {
   10225       416863 :               int f = maybe_emit_file (a_attr->dw_attr_val.v.val_file);
   10226       416863 :               const char *filename = a_attr->dw_attr_val.v.val_file->filename;
   10227       416863 :               dw2_asm_output_data_sleb128 (f, "(%s)", filename);
   10228              :             }
   10229              :           else
   10230       738111 :             dw2_asm_output_data_sleb128 (a_attr->dw_attr_val.v.val_int, NULL);
   10231              :         }
   10232              :     }
   10233              : 
   10234      2944235 :   dw2_asm_output_data (1, 0, NULL);
   10235      2944235 :   dw2_asm_output_data (1, 0, NULL);
   10236      2944235 : }
   10237              : 
   10238              : 
   10239              : /* Output the .debug_abbrev section which defines the DIE abbreviation
   10240              :    table.  */
   10241              : 
   10242              : static void
   10243        53523 : output_abbrev_section (void)
   10244              : {
   10245        53523 :   unsigned int abbrev_id;
   10246        53523 :   dw_die_ref abbrev;
   10247              : 
   10248      3051032 :   FOR_EACH_VEC_SAFE_ELT (abbrev_die_table, abbrev_id, abbrev)
   10249      2997509 :     if (abbrev_id != 0)
   10250      2943986 :       output_die_abbrevs (abbrev_id, abbrev);
   10251              : 
   10252              :   /* Terminate the table.  */
   10253        53523 :   dw2_asm_output_data (1, 0, NULL);
   10254        53523 : }
   10255              : 
   10256              : /* Return a new location list, given the begin and end range, and the
   10257              :    expression.  */
   10258              : 
   10259              : static inline dw_loc_list_ref
   10260     28440691 : new_loc_list (dw_loc_descr_ref expr, const char *begin, var_loc_view vbegin,
   10261              :               const char *end, var_loc_view vend,
   10262              :               const char *section)
   10263              : {
   10264     56881382 :   dw_loc_list_ref retlist = ggc_cleared_alloc<dw_loc_list_node> ();
   10265              : 
   10266     28440691 :   retlist->begin = begin;
   10267     28440691 :   retlist->begin_entry = NULL;
   10268     28440691 :   retlist->end = end;
   10269     28440691 :   retlist->end_entry = NULL;
   10270     28440691 :   retlist->expr = expr;
   10271     28440691 :   retlist->section = section;
   10272     28440691 :   retlist->vbegin = vbegin;
   10273     28440691 :   retlist->vend = vend;
   10274              : 
   10275     28440691 :   return retlist;
   10276              : }
   10277              : 
   10278              : /* Return true iff there's any nonzero view number in the loc list.
   10279              : 
   10280              :    ??? When views are not enabled, we'll often extend a single range
   10281              :    to the entire function, so that we emit a single location
   10282              :    expression rather than a location list.  With views, even with a
   10283              :    single range, we'll output a list if start or end have a nonzero
   10284              :    view.  If we change this, we may want to stop splitting a single
   10285              :    range in dw_loc_list just because of a nonzero view, even if it
   10286              :    straddles across hot/cold partitions.  */
   10287              : 
   10288              : static bool
   10289     25314501 : loc_list_has_views (dw_loc_list_ref list)
   10290              : {
   10291     25314501 :   if (!debug_variable_location_views)
   10292              :     return false;
   10293              : 
   10294      1430822 :   for (dw_loc_list_ref loc = list;
   10295     26741401 :        loc != NULL; loc = loc->dw_loc_next)
   10296     26036467 :     if (!ZERO_VIEW_P (loc->vbegin) || !ZERO_VIEW_P (loc->vend))
   10297              :       return true;
   10298              : 
   10299              :   return false;
   10300              : }
   10301              : 
   10302              : /* Generate a new internal symbol for this location list node, if it
   10303              :    hasn't got one yet.  */
   10304              : 
   10305              : static inline void
   10306     12816782 : gen_llsym (dw_loc_list_ref list)
   10307              : {
   10308     12816782 :   gcc_assert (!list->ll_symbol);
   10309     12816782 :   list->ll_symbol = gen_internal_sym ("LLST");
   10310              : 
   10311     12816782 :   if (!loc_list_has_views (list))
   10312              :     return;
   10313              : 
   10314     12640732 :   if (dwarf2out_locviews_in_attribute ())
   10315              :     {
   10316              :       /* Use the same label_num for the view list.  */
   10317     12640732 :       label_num--;
   10318     12640732 :       list->vl_symbol = gen_internal_sym ("LVUS");
   10319              :     }
   10320              :   else
   10321            0 :     list->vl_symbol = list->ll_symbol;
   10322              : }
   10323              : 
   10324              : /* Generate a symbol for the list, but only if we really want to emit
   10325              :    it as a list.  */
   10326              : 
   10327              : static inline void
   10328      1444556 : maybe_gen_llsym (dw_loc_list_ref list)
   10329              : {
   10330      1444556 :   if (!list || (!list->dw_loc_next && !loc_list_has_views (list)))
   10331              :     return;
   10332              : 
   10333        53716 :   gen_llsym (list);
   10334              : }
   10335              : 
   10336              : /* Determine whether or not to skip loc_list entry CURR.  If SIZEP is
   10337              :    NULL, don't consider size of the location expression.  If we're not
   10338              :    to skip it, and SIZEP is non-null, store the size of CURR->expr's
   10339              :    representation in *SIZEP.  */
   10340              : 
   10341              : static bool
   10342     51606827 : skip_loc_list_entry (dw_loc_list_ref curr, unsigned long *sizep = NULL)
   10343              : {
   10344              :   /* Don't output an entry that starts and ends at the same address.  */
   10345     51606827 :   if (strcmp (curr->begin, curr->end) == 0
   10346      7098225 :       && curr->vbegin == curr->vend && !curr->force)
   10347              :     return true;
   10348              : 
   10349     51606806 :   if (!sizep)
   10350              :     return false;
   10351              : 
   10352     51606802 :   unsigned long size = size_of_locs (curr->expr);
   10353              : 
   10354              :   /* If the expression is too large, drop it on the floor.  We could
   10355              :      perhaps put it into DW_TAG_dwarf_procedure and refer to that
   10356              :      in the expression, but >= 64KB expressions for a single value
   10357              :      in a single range are unlikely very useful.  */
   10358     51606802 :   if (dwarf_version < 5 && size > 0xffff)
   10359              :     return true;
   10360              : 
   10361     51606802 :   *sizep = size;
   10362              : 
   10363     51606802 :   return false;
   10364              : }
   10365              : 
   10366              : /* Output a view pair loclist entry for CURR, if it requires one.  */
   10367              : 
   10368              : static void
   10369     26060243 : dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr)
   10370              : {
   10371     26060243 :   if (!dwarf2out_locviews_in_loclist ())
   10372              :     return;
   10373              : 
   10374            0 :   if (ZERO_VIEW_P (curr->vbegin) && ZERO_VIEW_P (curr->vend))
   10375              :     return;
   10376              : 
   10377              : #ifdef DW_LLE_view_pair
   10378            0 :   dw2_asm_output_data (1, DW_LLE_view_pair, "DW_LLE_view_pair");
   10379              : 
   10380            0 :   if (dwarf2out_as_locview_support)
   10381              :     {
   10382            0 :       if (ZERO_VIEW_P (curr->vbegin))
   10383            0 :         dw2_asm_output_data_uleb128 (0, "Location view begin");
   10384              :       else
   10385              :         {
   10386            0 :           char label[MAX_ARTIFICIAL_LABEL_BYTES];
   10387            0 :           ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vbegin);
   10388            0 :           dw2_asm_output_symname_uleb128 (label, "Location view begin");
   10389              :         }
   10390              : 
   10391            0 :       if (ZERO_VIEW_P (curr->vend))
   10392            0 :         dw2_asm_output_data_uleb128 (0, "Location view end");
   10393              :       else
   10394              :         {
   10395            0 :           char label[MAX_ARTIFICIAL_LABEL_BYTES];
   10396            0 :           ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vend);
   10397            0 :           dw2_asm_output_symname_uleb128 (label, "Location view end");
   10398              :         }
   10399              :     }
   10400              :   else
   10401              :     {
   10402            0 :       dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
   10403            0 :                                    ? 0 : curr->vbegin, "Location view begin");
   10404            0 :       dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
   10405            0 :                                    ? 0 : curr->vend, "Location view end");
   10406              :     }
   10407              : #endif /* DW_LLE_view_pair */
   10408              : 
   10409              :   return;
   10410              : }
   10411              : 
   10412              : /* Output the location list given to us.  */
   10413              : 
   10414              : static void
   10415     12235684 : output_loc_list (dw_loc_list_ref list_head)
   10416              : {
   10417     12235684 :   int vcount = 0, lcount = 0;
   10418              : 
   10419     12235684 :   if (list_head->emitted)
   10420              :     return;
   10421     12094115 :   list_head->emitted = true;
   10422              : 
   10423     12094115 :   if (list_head->vl_symbol && dwarf2out_locviews_in_attribute ())
   10424              :     {
   10425     11918090 :       ASM_OUTPUT_LABEL (asm_out_file, list_head->vl_symbol);
   10426              : 
   10427     49369205 :       for (dw_loc_list_ref curr = list_head; curr != NULL;
   10428     25533025 :            curr = curr->dw_loc_next)
   10429              :         {
   10430     25533025 :           unsigned long size;
   10431              : 
   10432     25533025 :           if (skip_loc_list_entry (curr, &size))
   10433            0 :             continue;
   10434              : 
   10435     25533025 :           vcount++;
   10436              : 
   10437              :           /* ?? dwarf_split_debug_info?  */
   10438     25533025 :           if (dwarf2out_as_locview_support)
   10439              :             {
   10440     25531645 :               char label[MAX_ARTIFICIAL_LABEL_BYTES];
   10441              : 
   10442     25531645 :               if (!ZERO_VIEW_P (curr->vbegin))
   10443              :                 {
   10444     24922707 :                   ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vbegin);
   10445     24922707 :                   dw2_asm_output_symname_uleb128 (label,
   10446              :                                                   "View list begin (%s)",
   10447              :                                                   list_head->vl_symbol);
   10448              :                 }
   10449              :               else
   10450       608938 :                 dw2_asm_output_data_uleb128 (0,
   10451              :                                              "View list begin (%s)",
   10452              :                                              list_head->vl_symbol);
   10453              : 
   10454     25531645 :               if (!ZERO_VIEW_P (curr->vend))
   10455              :                 {
   10456     24428010 :                   ASM_GENERATE_INTERNAL_LABEL (label, "LVU", curr->vend);
   10457     24428010 :                   dw2_asm_output_symname_uleb128 (label,
   10458              :                                                   "View list end (%s)",
   10459              :                                                   list_head->vl_symbol);
   10460              :                 }
   10461              :               else
   10462      1103635 :                 dw2_asm_output_data_uleb128 (0,
   10463              :                                              "View list end (%s)",
   10464              :                                              list_head->vl_symbol);
   10465              :             }
   10466              :           else
   10467              :             {
   10468         2721 :               dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
   10469         1341 :                                            ? 0 : curr->vbegin,
   10470              :                                            "View list begin (%s)",
   10471              :                                            list_head->vl_symbol);
   10472         2713 :               dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
   10473         1333 :                                            ? 0 : curr->vend,
   10474              :                                            "View list end (%s)",
   10475              :                                            list_head->vl_symbol);
   10476              :             }
   10477              :         }
   10478              :     }
   10479              : 
   10480     12094115 :   ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
   10481              : 
   10482     12094115 :   const char *last_section = NULL;
   10483     12094115 :   const char *base_label = NULL;
   10484              : 
   10485              :   /* Walk the location list, and output each range + expression.  */
   10486     50262028 :   for (dw_loc_list_ref curr = list_head; curr != NULL;
   10487     26073798 :        curr = curr->dw_loc_next)
   10488              :     {
   10489     26073798 :       unsigned long size;
   10490              : 
   10491              :       /* Skip this entry?  If we skip it here, we must skip it in the
   10492              :          view list above as well. */
   10493     26073798 :       if (skip_loc_list_entry (curr, &size))
   10494           21 :         continue;
   10495              : 
   10496     26073777 :       lcount++;
   10497              : 
   10498     26073777 :       if (dwarf_version >= 5)
   10499              :         {
   10500     26060243 :           if (dwarf_split_debug_info && HAVE_AS_LEB128)
   10501              :             {
   10502            4 :               dwarf2out_maybe_output_loclist_view_pair (curr);
   10503              :               /* For -gsplit-dwarf, emit DW_LLE_startx_length, which has
   10504              :                  uleb128 index into .debug_addr and uleb128 length.  */
   10505            4 :               dw2_asm_output_data (1, DW_LLE_startx_length,
   10506              :                                    "DW_LLE_startx_length (%s)",
   10507              :                                    list_head->ll_symbol);
   10508            4 :               dw2_asm_output_data_uleb128 (curr->begin_entry->index,
   10509              :                                            "Location list range start index "
   10510              :                                            "(%s)", curr->begin);
   10511            4 :               dw2_asm_output_delta_uleb128 (curr->end, curr->begin,
   10512              :                                             "Location list length (%s)",
   10513              :                                             list_head->ll_symbol);
   10514              :             }
   10515     26060239 :           else if (dwarf_split_debug_info)
   10516              :             {
   10517              :               dwarf2out_maybe_output_loclist_view_pair (curr);
   10518              :               /* For -gsplit-dwarf without usable .uleb128 support, emit
   10519              :                  DW_LLE_startx_endx, which has two uleb128 indexes into
   10520              :                  .debug_addr.  */
   10521              :               dw2_asm_output_data (1, DW_LLE_startx_endx,
   10522              :                                    "DW_LLE_startx_endx (%s)",
   10523              :                                    list_head->ll_symbol);
   10524              :               dw2_asm_output_data_uleb128 (curr->begin_entry->index,
   10525              :                                            "Location list range start index "
   10526              :                                            "(%s)", curr->begin);
   10527              :               dw2_asm_output_data_uleb128 (curr->end_entry->index,
   10528              :                                            "Location list range end index "
   10529              :                                            "(%s)", curr->end);
   10530              :             }
   10531     26060239 :           else if (!have_multiple_function_sections && HAVE_AS_LEB128)
   10532              :             {
   10533      3932727 :               dwarf2out_maybe_output_loclist_view_pair (curr);
   10534              :               /* If all code is in .text section, the base address is
   10535              :                  already provided by the CU attributes.  Use
   10536              :                  DW_LLE_offset_pair where both addresses are uleb128 encoded
   10537              :                  offsets against that base.  */
   10538      3932727 :               dw2_asm_output_data (1, DW_LLE_offset_pair,
   10539              :                                    "DW_LLE_offset_pair (%s)",
   10540              :                                    list_head->ll_symbol);
   10541      3932727 :               dw2_asm_output_delta_uleb128 (curr->begin, curr->section,
   10542              :                                             "Location list begin address (%s)",
   10543              :                                             list_head->ll_symbol);
   10544      3932727 :               dw2_asm_output_delta_uleb128 (curr->end, curr->section,
   10545              :                                             "Location list end address (%s)",
   10546              :                                             list_head->ll_symbol);
   10547              :             }
   10548     22127512 :           else if (HAVE_AS_LEB128)
   10549              :             {
   10550              :               /* Otherwise, find out how many consecutive entries could share
   10551              :                  the same base entry.  If just one, emit DW_LLE_start_length,
   10552              :                  otherwise emit DW_LLE_base_address for the base address
   10553              :                  followed by a series of DW_LLE_offset_pair.  */
   10554     22127512 :               if (last_section == NULL || curr->section != last_section)
   10555              :                 {
   10556     11665439 :                   dw_loc_list_ref curr2;
   10557     12162730 :                   for (curr2 = curr->dw_loc_next; curr2 != NULL;
   10558       497291 :                        curr2 = curr2->dw_loc_next)
   10559              :                     {
   10560      4406880 :                       if (strcmp (curr2->begin, curr2->end) == 0
   10561       497291 :                           && !curr2->force)
   10562       497291 :                         continue;
   10563              :                       break;
   10564              :                     }
   10565     11665439 :                   if (curr2 == NULL || curr->section != curr2->section)
   10566              :                     last_section = NULL;
   10567              :                   else
   10568              :                     {
   10569      3879636 :                       last_section = curr->section;
   10570      3879636 :                       base_label = curr->begin;
   10571      3879636 :                       dw2_asm_output_data (1, DW_LLE_base_address,
   10572              :                                            "DW_LLE_base_address (%s)",
   10573              :                                            list_head->ll_symbol);
   10574      4089333 :                       dw2_asm_output_addr (DWARF2_ADDR_SIZE, base_label,
   10575              :                                            "Base address (%s)",
   10576              :                                            list_head->ll_symbol);
   10577              :                     }
   10578              :                 }
   10579              :               /* Only one entry with the same base address.  Use
   10580              :                  DW_LLE_start_length with absolute address and uleb128
   10581              :                  length.  */
   10582     14341709 :               if (last_section == NULL)
   10583              :                 {
   10584      7785803 :                   dwarf2out_maybe_output_loclist_view_pair (curr);
   10585      7785803 :                   dw2_asm_output_data (1, DW_LLE_start_length,
   10586              :                                        "DW_LLE_start_length (%s)",
   10587              :                                        list_head->ll_symbol);
   10588      8021043 :                   dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
   10589              :                                        "Location list begin address (%s)",
   10590              :                                        list_head->ll_symbol);
   10591      7785803 :                   dw2_asm_output_delta_uleb128 (curr->end, curr->begin,
   10592              :                                                 "Location list length "
   10593              :                                                 "(%s)", list_head->ll_symbol);
   10594              :                 }
   10595              :               /* Otherwise emit DW_LLE_offset_pair, relative to above emitted
   10596              :                  DW_LLE_base_address.  */
   10597              :               else
   10598              :                 {
   10599     14341709 :                   dwarf2out_maybe_output_loclist_view_pair (curr);
   10600     14341709 :                   dw2_asm_output_data (1, DW_LLE_offset_pair,
   10601              :                                        "DW_LLE_offset_pair (%s)",
   10602              :                                        list_head->ll_symbol);
   10603     14341709 :                   dw2_asm_output_delta_uleb128 (curr->begin, base_label,
   10604              :                                                 "Location list begin address "
   10605              :                                                 "(%s)", list_head->ll_symbol);
   10606     14341709 :                   dw2_asm_output_delta_uleb128 (curr->end, base_label,
   10607              :                                                 "Location list end address "
   10608              :                                                 "(%s)", list_head->ll_symbol);
   10609              :                 }
   10610              :             }
   10611              :           /* The assembler does not support .uleb128 directive.  Emit
   10612              :              DW_LLE_start_end with a pair of absolute addresses.  */
   10613              :           else
   10614              :             {
   10615              :               dwarf2out_maybe_output_loclist_view_pair (curr);
   10616              :               dw2_asm_output_data (1, DW_LLE_start_end,
   10617              :                                    "DW_LLE_start_end (%s)",
   10618              :                                    list_head->ll_symbol);
   10619              :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
   10620              :                                    "Location list begin address (%s)",
   10621              :                                    list_head->ll_symbol);
   10622              :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
   10623              :                                    "Location list end address (%s)",
   10624              :                                    list_head->ll_symbol);
   10625              :             }
   10626              :         }
   10627        13534 :       else if (dwarf_split_debug_info)
   10628              :         {
   10629              :           /* For -gsplit-dwarf -gdwarf-{2,3,4} emit index into .debug_addr
   10630              :              and 4 byte length.  */
   10631            0 :           dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry,
   10632              :                                "Location list start/length entry (%s)",
   10633              :                                list_head->ll_symbol);
   10634            0 :           dw2_asm_output_data_uleb128 (curr->begin_entry->index,
   10635              :                                        "Location list range start index (%s)",
   10636              :                                        curr->begin);
   10637              :           /* The length field is 4 bytes.  If we ever need to support
   10638              :              an 8-byte length, we can add a new DW_LLE code or fall back
   10639              :              to DW_LLE_GNU_start_end_entry.  */
   10640            0 :           dw2_asm_output_delta (4, curr->end, curr->begin,
   10641              :                                 "Location list range length (%s)",
   10642              :                                 list_head->ll_symbol);
   10643              :         }
   10644        13534 :       else if (!have_multiple_function_sections)
   10645              :         {
   10646              :           /* Pair of relative addresses against start of text section.  */
   10647         6735 :           dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
   10648              :                                 "Location list begin address (%s)",
   10649              :                                 list_head->ll_symbol);
   10650         6735 :           dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
   10651              :                                 "Location list end address (%s)",
   10652              :                                 list_head->ll_symbol);
   10653              :         }
   10654              :       else
   10655              :         {
   10656              :           /* Pair of absolute addresses.  */
   10657         6799 :           dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
   10658              :                                "Location list begin address (%s)",
   10659              :                                list_head->ll_symbol);
   10660         6799 :           dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
   10661              :                                "Location list end address (%s)",
   10662              :                                list_head->ll_symbol);
   10663              :         }
   10664              : 
   10665              :       /* Output the block length for this list of location operations.  */
   10666     26073777 :       if (dwarf_version >= 5)
   10667     26060243 :         dw2_asm_output_data_uleb128 (size, "Location expression size");
   10668              :       else
   10669              :         {
   10670        13534 :           gcc_assert (size <= 0xffff);
   10671        13534 :           dw2_asm_output_data (2, size, "Location expression size");
   10672              :         }
   10673              : 
   10674     26073777 :       output_loc_sequence (curr->expr, -1);
   10675              :     }
   10676              : 
   10677              :   /* And finally list termination.  */
   10678     12094115 :   if (dwarf_version >= 5)
   10679     12089789 :     dw2_asm_output_data (1, DW_LLE_end_of_list,
   10680              :                          "DW_LLE_end_of_list (%s)", list_head->ll_symbol);
   10681         4326 :   else if (dwarf_split_debug_info)
   10682            0 :     dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry,
   10683              :                          "Location list terminator (%s)",
   10684              :                          list_head->ll_symbol);
   10685              :   else
   10686              :     {
   10687         4326 :       dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
   10688              :                            "Location list terminator begin (%s)",
   10689              :                            list_head->ll_symbol);
   10690         4326 :       dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
   10691              :                            "Location list terminator end (%s)",
   10692              :                            list_head->ll_symbol);
   10693              :     }
   10694              : 
   10695     12094115 :   gcc_assert (!list_head->vl_symbol
   10696              :               || vcount == lcount * (dwarf2out_locviews_in_attribute () ? 1 : 0));
   10697              : }
   10698              : 
   10699              : /* Output a range_list offset into the .debug_ranges or .debug_rnglists
   10700              :    section.  Emit a relocated reference if val_entry is NULL, otherwise,
   10701              :    emit an indirect reference.  */
   10702              : 
   10703              : static void
   10704      3498190 : output_range_list_offset (dw_attr_node *a)
   10705              : {
   10706      3498190 :   const char *name = dwarf_attr_name (a->dw_attr);
   10707              : 
   10708      3498190 :   if (a->dw_attr_val.val_entry == RELOCATED_OFFSET)
   10709              :     {
   10710      3498187 :       if (dwarf_version >= 5)
   10711              :         {
   10712      3496856 :           dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
   10713      3496856 :           dw2_asm_output_offset (dwarf_offset_size, r->label,
   10714              :                                  debug_ranges_section, "%s", name);
   10715              :         }
   10716              :       else
   10717              :         {
   10718         1331 :           char *p = strchr (ranges_section_label, '\0');
   10719         2662 :           sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
   10720         1331 :                    a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE);
   10721         1331 :           dw2_asm_output_offset (dwarf_offset_size, ranges_section_label,
   10722              :                                  debug_ranges_section, "%s", name);
   10723         1331 :           *p = '\0';
   10724              :         }
   10725              :     }
   10726            3 :   else if (dwarf_version >= 5)
   10727              :     {
   10728            3 :       dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
   10729            3 :       gcc_assert (rnglist_idx);
   10730            3 :       dw2_asm_output_data_uleb128 (r->idx, "%s", name);
   10731              :     }
   10732              :   else
   10733            0 :     dw2_asm_output_data (dwarf_offset_size,
   10734            0 :                          a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE,
   10735              :                          "%s (offset from %s)", name, ranges_section_label);
   10736      3498190 : }
   10737              : 
   10738              : /* Output the offset into the debug_loc section.  */
   10739              : 
   10740              : static void
   10741     12235684 : output_loc_list_offset (dw_attr_node *a)
   10742              : {
   10743     12235684 :   char *sym = AT_loc_list (a)->ll_symbol;
   10744              : 
   10745     12235684 :   gcc_assert (sym);
   10746     12235684 :   if (!dwarf_split_debug_info)
   10747     12235682 :     dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
   10748     12235682 :                            "%s", dwarf_attr_name (a->dw_attr));
   10749            2 :   else if (dwarf_version >= 5)
   10750              :     {
   10751            2 :       gcc_assert (AT_loc_list (a)->num_assigned);
   10752            2 :       dw2_asm_output_data_uleb128 (AT_loc_list (a)->hash, "%s (%s)",
   10753            2 :                                    dwarf_attr_name (a->dw_attr),
   10754              :                                    sym);
   10755              :     }
   10756              :   else
   10757            0 :     dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
   10758            0 :                           "%s", dwarf_attr_name (a->dw_attr));
   10759     12235684 : }
   10760              : 
   10761              : /* Output the offset into the debug_loc section.  */
   10762              : 
   10763              : static void
   10764     12058730 : output_view_list_offset (dw_attr_node *a)
   10765              : {
   10766     12058730 :   char *sym = (*AT_loc_list_ptr (a))->vl_symbol;
   10767              : 
   10768     12058730 :   gcc_assert (sym);
   10769     12058730 :   if (dwarf_split_debug_info)
   10770            2 :     dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
   10771            2 :                           "%s", dwarf_attr_name (a->dw_attr));
   10772              :   else
   10773     12058728 :     dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
   10774     12058728 :                            "%s", dwarf_attr_name (a->dw_attr));
   10775     12058730 : }
   10776              : 
   10777              : /* Output an attribute's index or value appropriately.  */
   10778              : 
   10779              : static void
   10780     14869885 : output_attr_index_or_value (dw_attr_node *a)
   10781              : {
   10782     14869885 :   const char *name = dwarf_attr_name (a->dw_attr);
   10783              : 
   10784     14869885 :   if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
   10785              :     {
   10786          253 :       dw2_asm_output_data_uleb128 (AT_index (a), "%s", name);
   10787          253 :       return;
   10788              :     }
   10789     14869632 :   switch (AT_class (a))
   10790              :     {
   10791        29808 :     case dw_val_class_addr:
   10792        29808 :       dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
   10793        29808 :       break;
   10794     14839824 :     case dw_val_class_high_pc:
   10795     14839824 :     case dw_val_class_lbl_id:
   10796     14839824 :       dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
   10797     14839824 :       break;
   10798            0 :     default:
   10799            0 :       gcc_unreachable ();
   10800              :     }
   10801              : }
   10802              : 
   10803              : /* Output a type signature.  */
   10804              : 
   10805              : static inline void
   10806          169 : output_signature (const char *sig, const char *name)
   10807              : {
   10808          169 :   int i;
   10809              : 
   10810         1521 :   for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
   10811         2535 :     dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
   10812          169 : }
   10813              : 
   10814              : /* Output a discriminant value.  */
   10815              : 
   10816              : static inline void
   10817            0 : output_discr_value (dw_discr_value *discr_value, const char *name)
   10818              : {
   10819            0 :   if (discr_value->pos)
   10820            0 :     dw2_asm_output_data_uleb128 (discr_value->v.uval, "%s", name);
   10821              :   else
   10822            0 :     dw2_asm_output_data_sleb128 (discr_value->v.sval, "%s", name);
   10823            0 : }
   10824              : 
   10825              : /* Output the DIE and its attributes.  Called recursively to generate
   10826              :    the definitions of each child DIE.  */
   10827              : 
   10828              : static void
   10829     85909088 : output_die (dw_die_ref die)
   10830              : {
   10831     85909088 :   dw_attr_node *a;
   10832     85909088 :   dw_die_ref c;
   10833     85909088 :   unsigned long size;
   10834     85909088 :   unsigned ix;
   10835              : 
   10836    171818176 :   dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
   10837     85909088 :                                (unsigned long)die->die_offset,
   10838     85909088 :                                dwarf_tag_name (die->die_tag));
   10839              : 
   10840    509025417 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   10841              :     {
   10842    337207241 :       const char *name = dwarf_attr_name (a->dw_attr);
   10843              : 
   10844    337207241 :       switch (AT_class (a))
   10845              :         {
   10846        29808 :         case dw_val_class_addr:
   10847        29808 :           output_attr_index_or_value (a);
   10848        29808 :           break;
   10849              : 
   10850            0 :         case dw_val_class_offset:
   10851            0 :           dw2_asm_output_data (dwarf_offset_size, a->dw_attr_val.v.val_offset,
   10852              :                                "%s", name);
   10853            0 :           break;
   10854              : 
   10855      3498190 :         case dw_val_class_range_list:
   10856      3498190 :           output_range_list_offset (a);
   10857      3498190 :           break;
   10858              : 
   10859      7954305 :         case dw_val_class_loc:
   10860      7954305 :           size = size_of_locs (AT_loc (a));
   10861              : 
   10862              :           /* Output the block length for this list of location operations.  */
   10863      7954305 :           if (dwarf_version >= 4)
   10864      7943264 :             dw2_asm_output_data_uleb128 (size, "%s", name);
   10865              :           else
   10866        11041 :             dw2_asm_output_data (constant_size (size), size, "%s", name);
   10867              : 
   10868      7954305 :           output_loc_sequence (AT_loc (a), -1);
   10869      7954305 :           break;
   10870              : 
   10871        15217 :         case dw_val_class_const:
   10872              :           /* ??? It would be slightly more efficient to use a scheme like is
   10873              :              used for unsigned constants below, but gdb 4.x does not sign
   10874              :              extend.  Gdb 5.x does sign extend.  */
   10875        15217 :           dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
   10876        15217 :           break;
   10877              : 
   10878     71709548 :         case dw_val_class_unsigned_const:
   10879     71709548 :           {
   10880     71709548 :             int csize = constant_size (AT_unsigned (a));
   10881     71709548 :             if (dwarf_version == 3
   10882          690 :                 && a->dw_attr == DW_AT_data_member_location
   10883           15 :                 && csize >= 4)
   10884            1 :               dw2_asm_output_data_uleb128 (AT_unsigned (a), "%s", name);
   10885              :             else
   10886     71709547 :               dw2_asm_output_data (csize, AT_unsigned (a), "%s", name);
   10887              :           }
   10888              :           break;
   10889              : 
   10890      6910345 :         case dw_val_class_symview:
   10891      6910345 :           {
   10892      6910345 :             int vsize;
   10893      6910345 :             if (symview_upper_bound <= 0xff)
   10894              :               vsize = 1;
   10895      6552262 :             else if (symview_upper_bound <= 0xffff)
   10896              :               vsize = 2;
   10897            0 :             else if (symview_upper_bound <= 0xffffffff)
   10898            0 :               vsize = 4;
   10899              :             else
   10900              :               vsize = 8;
   10901      6910345 :             dw2_asm_output_addr (vsize, a->dw_attr_val.v.val_symbolic_view,
   10902              :                                  "%s", name);
   10903              :           }
   10904      6910345 :           break;
   10905              : 
   10906         5291 :         case dw_val_class_const_implicit:
   10907         5291 :           if (flag_debug_asm)
   10908            0 :             fprintf (asm_out_file, "\t\t\t%s %s ("
   10909              :                                    HOST_WIDE_INT_PRINT_DEC ")\n",
   10910              :                      ASM_COMMENT_START, name, AT_int (a));
   10911              :           break;
   10912              : 
   10913      9254484 :         case dw_val_class_unsigned_const_implicit:
   10914      9254484 :           if (flag_debug_asm)
   10915          375 :             fprintf (asm_out_file, "\t\t\t%s %s ("
   10916              :                                    HOST_WIDE_INT_PRINT_HEX ")\n",
   10917              :                      ASM_COMMENT_START, name, AT_unsigned (a));
   10918              :           break;
   10919              : 
   10920            0 :         case dw_val_class_const_double:
   10921            0 :           {
   10922            0 :             unsigned HOST_WIDE_INT first, second;
   10923              : 
   10924            0 :             if (HOST_BITS_PER_WIDE_INT >= DWARF_LARGEST_DATA_FORM_BITS)
   10925            0 :               dw2_asm_output_data (1,
   10926              :                                    HOST_BITS_PER_DOUBLE_INT
   10927              :                                    / HOST_BITS_PER_CHAR,
   10928              :                                    NULL);
   10929              : 
   10930            0 :             if (WORDS_BIG_ENDIAN)
   10931              :               {
   10932              :                 first = a->dw_attr_val.v.val_double.high;
   10933              :                 second = a->dw_attr_val.v.val_double.low;
   10934              :               }
   10935              :             else
   10936              :               {
   10937            0 :                 first = a->dw_attr_val.v.val_double.low;
   10938            0 :                 second = a->dw_attr_val.v.val_double.high;
   10939              :               }
   10940              : 
   10941            0 :             dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
   10942              :                                  first, "%s", name);
   10943            0 :             dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
   10944              :                                  second, NULL);
   10945              :           }
   10946            0 :           break;
   10947              : 
   10948           43 :         case dw_val_class_wide_int:
   10949           43 :           {
   10950           43 :             int i;
   10951           43 :             int len = get_full_len (*a->dw_attr_val.v.val_wide);
   10952           43 :             int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
   10953           43 :             if (len * HOST_BITS_PER_WIDE_INT > DWARF_LARGEST_DATA_FORM_BITS)
   10954            0 :               dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide)
   10955            0 :                                       * l, NULL);
   10956              : 
   10957           43 :             if (WORDS_BIG_ENDIAN)
   10958              :               for (i = len - 1; i >= 0; --i)
   10959              :                 {
   10960              :                   dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
   10961              :                                        "%s", name);
   10962              :                   name = "";
   10963              :                 }
   10964              :             else
   10965          129 :               for (i = 0; i < len; ++i)
   10966              :                 {
   10967           86 :                   dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
   10968              :                                        "%s", name);
   10969           86 :                   name = "";
   10970              :                 }
   10971              :           }
   10972              :           break;
   10973              : 
   10974        20620 :         case dw_val_class_vec:
   10975        20620 :           {
   10976        20620 :             unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
   10977        20620 :             unsigned int len = a->dw_attr_val.v.val_vec.length;
   10978        20620 :             unsigned int i;
   10979        20620 :             unsigned char *p;
   10980              : 
   10981        20620 :             dw2_asm_output_data (constant_size (len * elt_size),
   10982        20620 :                                  len * elt_size, "%s", name);
   10983        20620 :             if (elt_size > sizeof (HOST_WIDE_INT))
   10984              :               {
   10985            0 :                 elt_size /= 2;
   10986            0 :                 len *= 2;
   10987              :               }
   10988        20620 :             for (i = 0, p = (unsigned char *) a->dw_attr_val.v.val_vec.array;
   10989      3310499 :                  i < len;
   10990      3289879 :                  i++, p += elt_size)
   10991      6579758 :               dw2_asm_output_data (elt_size, extract_int (p, elt_size),
   10992              :                                    "fp or vector constant word %u", i);
   10993              :             break;
   10994              :           }
   10995              : 
   10996     28111170 :         case dw_val_class_flag:
   10997     28111170 :           if (dwarf_version >= 4)
   10998              :             {
   10999              :               /* Currently all add_AT_flag calls pass in 1 as last argument,
   11000              :                  so DW_FORM_flag_present can be used.  If that ever changes,
   11001              :                  we'll need to use DW_FORM_flag and have some optimization
   11002              :                  in build_abbrev_table that will change those to
   11003              :                  DW_FORM_flag_present if it is set to 1 in all DIEs using
   11004              :                  the same abbrev entry.  */
   11005     28089926 :               gcc_assert (AT_flag (a) == 1);
   11006     28089926 :               if (flag_debug_asm)
   11007         2192 :                 fprintf (asm_out_file, "\t\t\t%s %s\n",
   11008              :                          ASM_COMMENT_START, name);
   11009              :               break;
   11010              :             }
   11011        21244 :           dw2_asm_output_data (1, AT_flag (a), "%s", name);
   11012        21244 :           break;
   11013              : 
   11014     12235684 :         case dw_val_class_loc_list:
   11015     12235684 :           output_loc_list_offset (a);
   11016     12235684 :           break;
   11017              : 
   11018     12058730 :         case dw_val_class_view_list:
   11019     12058730 :           output_view_list_offset (a);
   11020     12058730 :           break;
   11021              : 
   11022     99030713 :         case dw_val_class_die_ref:
   11023     99030713 :           if (AT_ref_external (a))
   11024              :             {
   11025        29849 :               if (AT_ref (a)->comdat_type_p)
   11026              :                 {
   11027           88 :                   comdat_type_node *type_node
   11028           88 :                     = AT_ref (a)->die_id.die_type_node;
   11029              : 
   11030           88 :                   gcc_assert (type_node);
   11031           88 :                   output_signature (type_node->signature, name);
   11032              :                 }
   11033              :               else
   11034              :                 {
   11035        29761 :                   const char *sym = AT_ref (a)->die_id.die_symbol;
   11036        29761 :                   int size;
   11037              : 
   11038        29761 :                   gcc_assert (sym);
   11039              :                   /* In DWARF2, DW_FORM_ref_addr is sized by target address
   11040              :                      length, whereas in DWARF3 it's always sized as an
   11041              :                      offset.  */
   11042        29761 :                   if (dwarf_version == 2)
   11043           30 :                     size = DWARF2_ADDR_SIZE;
   11044              :                   else
   11045        29731 :                     size = dwarf_offset_size;
   11046              :                   /* ???  We cannot unconditionally output die_offset if
   11047              :                      non-zero - others might create references to those
   11048              :                      DIEs via symbols.
   11049              :                      And we do not clear its DIE offset after outputting it
   11050              :                      (and the label refers to the actual DIEs, not the
   11051              :                      DWARF CU unit header which is when using label + offset
   11052              :                      would be the correct thing to do).
   11053              :                      ???  This is the reason for the with_offset flag.  */
   11054        29761 :                   if (AT_ref (a)->with_offset)
   11055        29761 :                     dw2_asm_output_offset (size, sym, AT_ref (a)->die_offset,
   11056              :                                            debug_info_section, "%s", name);
   11057              :                   else
   11058            0 :                     dw2_asm_output_offset (size, sym, debug_info_section, "%s",
   11059              :                                            name);
   11060              :                 }
   11061              :             }
   11062              :           else
   11063              :             {
   11064     99000864 :               gcc_assert (AT_ref (a)->die_offset);
   11065     99000864 :               dw2_asm_output_data (dwarf_offset_size, AT_ref (a)->die_offset,
   11066              :                                    "%s", name);
   11067              :             }
   11068              :           break;
   11069              : 
   11070            0 :         case dw_val_class_fde_ref:
   11071            0 :           {
   11072            0 :             char l1[MAX_ARTIFICIAL_LABEL_BYTES];
   11073              : 
   11074            0 :             ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
   11075              :                                          a->dw_attr_val.v.val_fde_index * 2);
   11076            0 :             dw2_asm_output_offset (dwarf_offset_size, l1, debug_frame_section,
   11077              :                                    "%s", name);
   11078              :           }
   11079            0 :           break;
   11080              : 
   11081            0 :         case dw_val_class_vms_delta:
   11082              : #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
   11083              :           dw2_asm_output_vms_delta (dwarf_offset_size,
   11084              :                                     AT_vms_delta2 (a), AT_vms_delta1 (a),
   11085              :                                     "%s", name);
   11086              : #else
   11087            0 :           dw2_asm_output_delta (dwarf_offset_size,
   11088              :                                 AT_vms_delta2 (a), AT_vms_delta1 (a),
   11089              :                                 "%s", name);
   11090              : #endif
   11091            0 :           break;
   11092              : 
   11093     14840077 :         case dw_val_class_lbl_id:
   11094     14840077 :           output_attr_index_or_value (a);
   11095     14840077 :           break;
   11096              : 
   11097        53846 :         case dw_val_class_lineptr:
   11098        53846 :           dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
   11099              :                                  debug_line_section, "%s", name);
   11100        53846 :           break;
   11101              : 
   11102          528 :         case dw_val_class_macptr:
   11103          528 :           dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
   11104              :                                  debug_macinfo_section, "%s", name);
   11105          528 :           break;
   11106              : 
   11107            0 :         case dw_val_class_loclistsptr:
   11108            0 :           dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
   11109              :                                  debug_loc_section, "%s", name);
   11110            0 :           break;
   11111              : 
   11112     35220596 :         case dw_val_class_str:
   11113     35220596 :           if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
   11114     31859297 :             dw2_asm_output_offset (dwarf_offset_size,
   11115     31859297 :                                    a->dw_attr_val.v.val_str->label,
   11116              :                                    debug_str_section,
   11117              :                                    "%s: \"%s\"", name, AT_string (a));
   11118      3361299 :           else if (a->dw_attr_val.v.val_str->form == DW_FORM_line_strp)
   11119       102648 :             dw2_asm_output_offset (dwarf_offset_size,
   11120       102648 :                                    a->dw_attr_val.v.val_str->label,
   11121              :                                    debug_line_str_section,
   11122              :                                    "%s: \"%s\"", name, AT_string (a));
   11123      3272814 :           else if (a->dw_attr_val.v.val_str->form == dwarf_FORM (DW_FORM_strx))
   11124          935 :             dw2_asm_output_data_uleb128 (AT_index (a),
   11125              :                                          "%s: \"%s\"", name, AT_string (a));
   11126              :           else
   11127      3257716 :             dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
   11128              :           break;
   11129              : 
   11130     27566597 :         case dw_val_class_file:
   11131     27566597 :           {
   11132     27566597 :             int f = maybe_emit_file (a->dw_attr_val.v.val_file);
   11133              : 
   11134     27566597 :             dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
   11135     27566597 :                                  a->dw_attr_val.v.val_file->filename);
   11136     27566597 :             break;
   11137              :           }
   11138              : 
   11139      3803846 :         case dw_val_class_file_implicit:
   11140      3803846 :           if (flag_debug_asm)
   11141          541 :             fprintf (asm_out_file, "\t\t\t%s %s (%d, %s)\n",
   11142              :                      ASM_COMMENT_START, name,
   11143              :                      maybe_emit_file (a->dw_attr_val.v.val_file),
   11144          541 :                      a->dw_attr_val.v.val_file->filename);
   11145              :           break;
   11146              : 
   11147              :         case dw_val_class_data8:
   11148              :           {
   11149              :             int i;
   11150              : 
   11151          639 :             for (i = 0; i < 8; i++)
   11152         1065 :               dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
   11153              :                                    i == 0 ? "%s" : NULL, name);
   11154              :             break;
   11155              :           }
   11156              : 
   11157      4887532 :         case dw_val_class_high_pc:
   11158      4887532 :           dw2_asm_output_delta (DWARF2_ADDR_SIZE, AT_lbl (a),
   11159              :                                 get_AT_low_pc (die), "DW_AT_high_pc");
   11160      4887532 :           break;
   11161              : 
   11162            0 :         case dw_val_class_discr_value:
   11163            0 :           output_discr_value (&a->dw_attr_val.v.val_discr_value, name);
   11164            0 :           break;
   11165              : 
   11166            0 :         case dw_val_class_discr_list:
   11167            0 :           {
   11168            0 :             dw_discr_list_ref list = AT_discr_list (a);
   11169            0 :             const int size = size_of_discr_list (list);
   11170              : 
   11171              :             /* This is a block, so output its length first.  */
   11172            0 :             dw2_asm_output_data (constant_size (size), size,
   11173              :                                  "%s: block size", name);
   11174              : 
   11175            0 :             for (; list != NULL; list = list->dw_discr_next)
   11176              :               {
   11177              :                 /* One byte for the discriminant value descriptor, and then as
   11178              :                    many LEB128 numbers as required.  */
   11179            0 :                 if (list->dw_discr_range)
   11180            0 :                   dw2_asm_output_data (1, DW_DSC_range,
   11181              :                                        "%s: DW_DSC_range", name);
   11182              :                 else
   11183            0 :                   dw2_asm_output_data (1, DW_DSC_label,
   11184              :                                        "%s: DW_DSC_label", name);
   11185              : 
   11186            0 :                 output_discr_value (&list->dw_discr_lower_bound, name);
   11187            0 :                 if (list->dw_discr_range)
   11188            0 :                   output_discr_value (&list->dw_discr_upper_bound, name);
   11189              :               }
   11190              :             break;
   11191              :           }
   11192              : 
   11193            0 :         default:
   11194            0 :           gcc_unreachable ();
   11195              :         }
   11196              :     }
   11197              : 
   11198    149161643 :   FOR_EACH_CHILD (die, c, output_die (c));
   11199              : 
   11200              :   /* Add null byte to terminate sibling list.  */
   11201     85909088 :   if (die->die_child != NULL)
   11202     22602682 :     dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
   11203     22602682 :                          (unsigned long) die->die_offset);
   11204     85909088 : }
   11205              : 
   11206              : /* Output the dwarf version number.  */
   11207              : 
   11208              : static void
   11209       121715 : output_dwarf_version ()
   11210              : {
   11211              :   /* ??? For now, if -gdwarf-6 is specified, we output version 5 with
   11212              :      views in loclist.  That will change eventually.  */
   11213       121715 :   if (dwarf_version == 6)
   11214              :     {
   11215            0 :       static bool once;
   11216            0 :       if (!once)
   11217              :         {
   11218            0 :           warning (0, "%<-gdwarf-6%> is output as version 5 with "
   11219              :                    "incompatibilities");
   11220            0 :           once = true;
   11221              :         }
   11222            0 :       dw2_asm_output_data (2, 5, "DWARF version number");
   11223              :     }
   11224              :   else
   11225       121715 :     dw2_asm_output_data (2, dwarf_version, "DWARF version number");
   11226       121715 : }
   11227              : 
   11228              : /* Output the compilation unit that appears at the beginning of the
   11229              :    .debug_info section, and precedes the DIE descriptions.  */
   11230              : 
   11231              : static void
   11232        53602 : output_compilation_unit_header (enum dwarf_unit_type ut)
   11233              : {
   11234        53602 :   if (!XCOFF_DEBUGGING_INFO)
   11235              :     {
   11236        53602 :       if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   11237            0 :         dw2_asm_output_data (4, 0xffffffff,
   11238              :           "Initial length escape value indicating 64-bit DWARF extension");
   11239        53602 :       dw2_asm_output_data (dwarf_offset_size,
   11240        53602 :                            next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
   11241              :                            "Length of Compilation Unit Info");
   11242              :     }
   11243              : 
   11244        53602 :   output_dwarf_version ();
   11245        53602 :   if (dwarf_version >= 5)
   11246              :     {
   11247        51593 :       const char *name;
   11248        51593 :       switch (ut)
   11249              :         {
   11250              :         case DW_UT_compile: name = "DW_UT_compile"; break;
   11251           21 :         case DW_UT_type: name = "DW_UT_type"; break;
   11252          248 :         case DW_UT_split_compile: name = "DW_UT_split_compile"; break;
   11253            0 :         case DW_UT_split_type: name = "DW_UT_split_type"; break;
   11254            0 :         default: gcc_unreachable ();
   11255              :         }
   11256        51593 :       dw2_asm_output_data (1, ut, "%s", name);
   11257        57932 :       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
   11258              :     }
   11259        53602 :   dw2_asm_output_offset (dwarf_offset_size, abbrev_section_label,
   11260              :                          debug_abbrev_section,
   11261              :                          "Offset Into Abbrev. Section");
   11262        53602 :   if (dwarf_version < 5)
   11263         2009 :     dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
   11264        53602 : }
   11265              : 
   11266              : /* Output the compilation unit DIE and its children.  */
   11267              : 
   11268              : static void
   11269        54822 : output_comp_unit (dw_die_ref die, int output_if_empty,
   11270              :                   const unsigned char *dwo_id)
   11271              : {
   11272        54822 :   const char *secname, *oldsym;
   11273        54822 :   char *tmp;
   11274              : 
   11275              :   /* Unless we are outputting main CU, we may throw away empty ones.  */
   11276        54822 :   if (!output_if_empty && die->die_child == NULL)
   11277              :     return;
   11278              : 
   11279              :   /* Even if there are no children of this DIE, we must output the information
   11280              :      about the compilation unit.  Otherwise, on an empty translation unit, we
   11281              :      will generate a present, but empty, .debug_info section.  IRIX 6.5 `nm'
   11282              :      will then complain when examining the file.  First mark all the DIEs in
   11283              :      this CU so we know which get local refs.  */
   11284        53521 :   mark_dies (die);
   11285              : 
   11286        53521 :   external_ref_hash_type *extern_map = optimize_external_refs (die);
   11287              : 
   11288              :   /* For now, optimize only the main CU, in order to optimize the rest
   11289              :      we'd need to see all of them earlier.  Leave the rest for post-linking
   11290              :      tools like DWZ.  */
   11291        53521 :   if (die == comp_unit_die ())
   11292       107042 :     abbrev_opt_start = vec_safe_length (abbrev_die_table);
   11293              : 
   11294        53521 :   build_abbrev_table (die, extern_map);
   11295              : 
   11296        53521 :   optimize_abbrev_table ();
   11297              : 
   11298        53521 :   delete extern_map;
   11299              : 
   11300              :   /* Initialize the beginning DIE offset - and calculate sizes/offsets.  */
   11301       107042 :   next_die_offset = (dwo_id
   11302        53523 :                      ? DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
   11303        55220 :                      : DWARF_COMPILE_UNIT_HEADER_SIZE);
   11304        53521 :   calc_die_sizes (die);
   11305              : 
   11306        53521 :   oldsym = die->die_id.die_symbol;
   11307        53521 :   if (oldsym && die->comdat_type_p)
   11308              :     {
   11309            0 :       tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
   11310              : 
   11311            0 :       sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
   11312            0 :       secname = tmp;
   11313            0 :       die->die_id.die_symbol = NULL;
   11314            0 :       switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
   11315              :     }
   11316              :   else
   11317              :     {
   11318        53521 :       switch_to_section (debug_info_section);
   11319        53521 :       ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
   11320        53521 :       info_section_emitted = true;
   11321              :     }
   11322              : 
   11323              :   /* For LTO cross unit DIE refs we want a symbol on the start of the
   11324              :      debuginfo section, not on the CU DIE.  */
   11325        53521 :   if ((flag_generate_lto || flag_generate_offload) && oldsym)
   11326              :     {
   11327              :       /* ???  No way to get visibility assembled without a decl.  */
   11328         1338 :       tree decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
   11329              :                               get_identifier (oldsym), char_type_node);
   11330         1338 :       TREE_PUBLIC (decl) = true;
   11331         1338 :       TREE_STATIC (decl) = true;
   11332         1338 :       DECL_ARTIFICIAL (decl) = true;
   11333         1338 :       DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
   11334         1338 :       DECL_VISIBILITY_SPECIFIED (decl) = true;
   11335         1338 :       targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN);
   11336              : #ifdef ASM_WEAKEN_LABEL
   11337              :       /* We prefer a .weak because that handles duplicates from duplicate
   11338              :          archive members in a graceful way.  */
   11339         1338 :       ASM_WEAKEN_LABEL (asm_out_file, oldsym);
   11340              : #else
   11341              :       targetm.asm_out.globalize_label (asm_out_file, oldsym);
   11342              : #endif
   11343         1338 :       ASM_OUTPUT_LABEL (asm_out_file, oldsym);
   11344              :     }
   11345              : 
   11346              :   /* Output debugging information.  */
   11347       106793 :   output_compilation_unit_header (dwo_id
   11348              :                                   ? DW_UT_split_compile : DW_UT_compile);
   11349        53521 :   if (dwarf_version >= 5)
   11350              :     {
   11351        51572 :       if (dwo_id != NULL)
   11352         2232 :         for (int i = 0; i < 8; i++)
   11353         3720 :           dw2_asm_output_data (1, dwo_id[i], i == 0 ? "DWO id" : NULL);
   11354              :     }
   11355        53521 :   output_die (die);
   11356              : 
   11357              :   /* Leave the marks on the main CU, so we can check them in
   11358              :      output_pubnames.  */
   11359        53521 :   if (oldsym)
   11360              :     {
   11361         1338 :       unmark_dies (die);
   11362         1338 :       die->die_id.die_symbol = oldsym;
   11363              :     }
   11364              : }
   11365              : 
   11366              : /* Whether to generate the DWARF accelerator tables in .debug_pubnames
   11367              :    and .debug_pubtypes.  This is configured per-target, but can be
   11368              :    overridden by the -gpubnames or -gno-pubnames options.  */
   11369              : 
   11370              : static inline bool
   11371    279102136 : want_pubnames (void)
   11372              : {
   11373    279102136 :   if (debug_info_level <= DINFO_LEVEL_TERSE
   11374              :       /* Names and types go to the early debug part only.  */
   11375    279084894 :       || in_lto_p)
   11376              :     return false;
   11377    279084016 :   if (debug_generate_pub_sections != -1)
   11378         1449 :     return debug_generate_pub_sections;
   11379    279082567 :   return targetm.want_debug_pub_sections;
   11380              : }
   11381              : 
   11382              : /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes.  */
   11383              : 
   11384              : static void
   11385        53595 : add_AT_pubnames (dw_die_ref die)
   11386              : {
   11387        53595 :   if (want_pubnames ())
   11388          256 :     add_AT_flag (die, DW_AT_GNU_pubnames, 1);
   11389        53595 : }
   11390              : 
   11391              : /* Add a string attribute value to a skeleton DIE.  */
   11392              : 
   11393              : static inline void
   11394          498 : add_skeleton_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind,
   11395              :                         const char *str)
   11396              : {
   11397          498 :   dw_attr_node attr;
   11398          498 :   struct indirect_string_node *node;
   11399              : 
   11400          498 :   if (! skeleton_debug_str_hash)
   11401          249 :     skeleton_debug_str_hash
   11402          249 :       = hash_table<indirect_string_hasher>::create_ggc (10);
   11403              : 
   11404          498 :   node = find_AT_string_in_table (str, skeleton_debug_str_hash);
   11405          498 :   find_string_form (node);
   11406          500 :   if (node->form == dwarf_FORM (DW_FORM_strx))
   11407          498 :     node->form = DW_FORM_strp;
   11408              : 
   11409          498 :   attr.dw_attr = attr_kind;
   11410          498 :   attr.dw_attr_val.val_class = dw_val_class_str;
   11411          498 :   attr.dw_attr_val.val_entry = NULL;
   11412          498 :   attr.dw_attr_val.v.val_str = node;
   11413          498 :   add_dwarf_attr (die, &attr);
   11414          498 : }
   11415              : 
   11416              : /* Helper function to generate top-level dies for skeleton debug_info and
   11417              :    debug_types.  */
   11418              : 
   11419              : static void
   11420          249 : add_top_level_skeleton_die_attrs (dw_die_ref die)
   11421              : {
   11422          249 :   const char *dwo_file_name = concat (aux_base_name, ".dwo", NULL);
   11423          249 :   const char *comp_dir = comp_dir_string ();
   11424              : 
   11425          250 :   add_skeleton_AT_string (die, dwarf_AT (DW_AT_dwo_name), dwo_file_name);
   11426          249 :   if (comp_dir != NULL)
   11427          249 :     add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
   11428          249 :   add_AT_pubnames (die);
   11429          249 :   if (addr_index_table != NULL && addr_index_table->size () > 0)
   11430          244 :     add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label);
   11431          249 : }
   11432              : 
   11433              : /* Output skeleton debug sections that point to the dwo file.  */
   11434              : 
   11435              : static void
   11436          249 : output_skeleton_debug_sections (dw_die_ref comp_unit,
   11437              :                                 const unsigned char *dwo_id)
   11438              : {
   11439              :   /* These attributes will be found in the full debug_info section.  */
   11440          249 :   remove_AT (comp_unit, DW_AT_producer);
   11441          249 :   remove_AT (comp_unit, DW_AT_language);
   11442          249 :   remove_AT (comp_unit, DW_AT_language_name);
   11443          249 :   remove_AT (comp_unit, DW_AT_language_version);
   11444              : 
   11445          249 :   switch_to_section (debug_skeleton_info_section);
   11446          249 :   ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_info_section_label);
   11447              : 
   11448              :   /* Produce the skeleton compilation-unit header.  This one differs enough from
   11449              :      a normal CU header that it's better not to call output_compilation_unit
   11450              :      header.  */
   11451          249 :   if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   11452            0 :     dw2_asm_output_data (4, 0xffffffff,
   11453              :                          "Initial length escape value indicating 64-bit "
   11454              :                          "DWARF extension");
   11455              : 
   11456          249 :   dw2_asm_output_data (dwarf_offset_size,
   11457          250 :                        DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
   11458          249 :                        - DWARF_INITIAL_LENGTH_SIZE
   11459          249 :                        + size_of_die (comp_unit),
   11460              :                       "Length of Compilation Unit Info");
   11461          249 :   output_dwarf_version ();
   11462          249 :   if (dwarf_version >= 5)
   11463              :     {
   11464          248 :       dw2_asm_output_data (1, DW_UT_skeleton, "DW_UT_skeleton");
   11465          248 :       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
   11466              :     }
   11467          249 :   dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_abbrev_section_label,
   11468              :                          debug_skeleton_abbrev_section,
   11469              :                          "Offset Into Abbrev. Section");
   11470          249 :   if (dwarf_version < 5)
   11471            1 :     dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
   11472              :   else
   11473         2232 :     for (int i = 0; i < 8; i++)
   11474         3720 :       dw2_asm_output_data (1, dwo_id[i], i == 0 ? "DWO id" : NULL);
   11475              : 
   11476          249 :   comp_unit->die_abbrev = SKELETON_COMP_DIE_ABBREV;
   11477          249 :   output_die (comp_unit);
   11478              : 
   11479              :   /* Build the skeleton debug_abbrev section.  */
   11480          249 :   switch_to_section (debug_skeleton_abbrev_section);
   11481          249 :   ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_abbrev_section_label);
   11482              : 
   11483          249 :   output_die_abbrevs (SKELETON_COMP_DIE_ABBREV, comp_unit);
   11484              : 
   11485          249 :   dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
   11486          249 : }
   11487              : 
   11488              : /* Output a comdat type unit DIE and its children.  */
   11489              : 
   11490              : static void
   11491           81 : output_comdat_type_unit (comdat_type_node *node,
   11492              :                          bool early_lto_debug ATTRIBUTE_UNUSED)
   11493              : {
   11494           81 :   const char *secname;
   11495           81 :   char *tmp;
   11496           81 :   int i;
   11497              : #if defined (OBJECT_FORMAT_ELF)
   11498           81 :   tree comdat_key;
   11499              : #endif
   11500              : 
   11501              :   /* First mark all the DIEs in this CU so we know which get local refs.  */
   11502           81 :   mark_dies (node->root_die);
   11503              : 
   11504           81 :   external_ref_hash_type *extern_map = optimize_external_refs (node->root_die);
   11505              : 
   11506           81 :   build_abbrev_table (node->root_die, extern_map);
   11507              : 
   11508           81 :   delete extern_map;
   11509           81 :   extern_map = NULL;
   11510              : 
   11511              :   /* Initialize the beginning DIE offset - and calculate sizes/offsets.  */
   11512           81 :   next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
   11513           81 :   calc_die_sizes (node->root_die);
   11514              : 
   11515              : #if defined (OBJECT_FORMAT_ELF)
   11516           81 :   if (dwarf_version >= 5)
   11517              :     {
   11518           21 :       if (!dwarf_split_debug_info)
   11519           21 :         secname = early_lto_debug ? DEBUG_LTO_INFO_SECTION : DEBUG_INFO_SECTION;
   11520              :       else
   11521            0 :         secname = (early_lto_debug
   11522            0 :                    ? DEBUG_LTO_DWO_INFO_SECTION : DEBUG_DWO_INFO_SECTION);
   11523              :     }
   11524           60 :   else if (!dwarf_split_debug_info)
   11525           60 :     secname = early_lto_debug ? ".gnu.debuglto_.debug_types" : ".debug_types";
   11526              :   else
   11527            0 :     secname = (early_lto_debug
   11528            0 :                ? ".gnu.debuglto_.debug_types.dwo" : ".debug_types.dwo");
   11529              : 
   11530           81 :   tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
   11531           81 :   sprintf (tmp, dwarf_version >= 5 ? "wi." : "wt.");
   11532          729 :   for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
   11533          648 :     sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
   11534           81 :   comdat_key = get_identifier (tmp);
   11535           81 :   targetm.asm_out.named_section (secname,
   11536              :                                  SECTION_DEBUG | SECTION_LINKONCE,
   11537              :                                  comdat_key);
   11538              : #else
   11539              :   tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
   11540              :   sprintf (tmp, (dwarf_version >= 5
   11541              :                  ? ".gnu.linkonce.wi." : ".gnu.linkonce.wt."));
   11542              :   for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
   11543              :     sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
   11544              :   secname = tmp;
   11545              :   switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
   11546              : #endif
   11547              : 
   11548              :   /* Output debugging information.  */
   11549          162 :   output_compilation_unit_header (dwarf_split_debug_info
   11550              :                                   ? DW_UT_split_type : DW_UT_type);
   11551           81 :   output_signature (node->signature, "Type Signature");
   11552           81 :   dw2_asm_output_data (dwarf_offset_size, node->type_die->die_offset,
   11553              :                        "Offset to Type DIE");
   11554           81 :   output_die (node->root_die);
   11555              : 
   11556           81 :   unmark_dies (node->root_die);
   11557           81 : }
   11558              : 
   11559              : /* Return the DWARF2/3 pubname associated with a decl.  */
   11560              : 
   11561              : static const char *
   11562    203952147 : dwarf2_name (tree decl, int scope)
   11563              : {
   11564    203952147 :   if (DECL_NAMELESS (decl))
   11565              :     return NULL;
   11566    407753277 :   return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
   11567              : }
   11568              : 
   11569              : /* Add a new entry to .debug_pubnames if appropriate.  */
   11570              : 
   11571              : static void
   11572          536 : add_pubname_string (const char *str, dw_die_ref die)
   11573              : {
   11574          536 :   pubname_entry e;
   11575              : 
   11576          536 :   e.die = die;
   11577          536 :   e.name = xstrdup (str);
   11578          536 :   vec_safe_push (pubname_table, e);
   11579          536 : }
   11580              : 
   11581              : static void
   11582    128371636 : add_pubname (tree decl, dw_die_ref die)
   11583              : {
   11584    128371636 :   if (!want_pubnames ())
   11585              :     return;
   11586              : 
   11587              :   /* Don't add items to the table when we expect that the consumer will have
   11588              :      just read the enclosing die.  For example, if the consumer is looking at a
   11589              :      class_member, it will either be inside the class already, or will have just
   11590              :      looked up the class to find the member.  Either way, searching the class is
   11591              :      faster than searching the index.  */
   11592          527 :   if ((TREE_PUBLIC (decl) && !class_scope_p (die->die_parent))
   11593          749 :       || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
   11594              :     {
   11595          503 :       const char *name = dwarf2_name (decl, 1);
   11596              : 
   11597          503 :       if (name)
   11598          503 :         add_pubname_string (name, die);
   11599              :     }
   11600              : }
   11601              : 
   11602              : /* Add an enumerator to the pubnames section.  */
   11603              : 
   11604              : static void
   11605           36 : add_enumerator_pubname (const char *scope_name, dw_die_ref die)
   11606              : {
   11607           36 :   pubname_entry e;
   11608              : 
   11609           36 :   gcc_assert (scope_name);
   11610           36 :   e.name = concat (scope_name, get_AT_string (die, DW_AT_name), NULL);
   11611           36 :   e.die = die;
   11612           36 :   vec_safe_push (pubname_table, e);
   11613           36 : }
   11614              : 
   11615              : /* Add a new entry to .debug_pubtypes if appropriate.  */
   11616              : 
   11617              : static void
   11618    150101949 : add_pubtype (tree decl, dw_die_ref die)
   11619              : {
   11620    150101949 :   pubname_entry e;
   11621              : 
   11622    150101949 :   if (!want_pubnames ())
   11623    150101635 :     return;
   11624              : 
   11625          314 :   if ((TREE_PUBLIC (decl)
   11626          494 :        || is_cu_die (die->die_parent) || is_namespace_die (die->die_parent))
   11627          404 :       && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
   11628              :     {
   11629          290 :       tree scope = NULL;
   11630          290 :       const char *scope_name = "";
   11631          290 :       const char *sep = is_cxx () ? "::" : ".";
   11632          290 :       const char *name;
   11633              : 
   11634          290 :       scope = TYPE_P (decl) ? TYPE_CONTEXT (decl) : NULL;
   11635          290 :       if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
   11636              :         {
   11637           60 :           scope_name = lang_hooks.dwarf_name (scope, 1);
   11638           60 :           if (scope_name != NULL && scope_name[0] != '\0')
   11639           60 :             scope_name = concat (scope_name, sep, NULL);
   11640              :           else
   11641              :             scope_name = "";
   11642              :         }
   11643              : 
   11644          290 :       if (TYPE_P (decl))
   11645          290 :         name = type_tag (decl);
   11646              :       else
   11647            0 :         name = lang_hooks.dwarf_name (decl, 1);
   11648              : 
   11649              :       /* If we don't have a name for the type, there's no point in adding
   11650              :          it to the table.  */
   11651          290 :       if (name != NULL && name[0] != '\0')
   11652              :         {
   11653          290 :           e.die = die;
   11654          290 :           e.name = concat (scope_name, name, NULL);
   11655          290 :           vec_safe_push (pubtype_table, e);
   11656              :         }
   11657              : 
   11658              :       /* Although it might be more consistent to add the pubinfo for the
   11659              :          enumerators as their dies are created, they should only be added if the
   11660              :          enum type meets the criteria above.  So rather than re-check the parent
   11661              :          enum type whenever an enumerator die is created, just output them all
   11662              :          here.  This isn't protected by the name conditional because anonymous
   11663              :          enums don't have names.  */
   11664          290 :       if (die->die_tag == DW_TAG_enumeration_type)
   11665              :         {
   11666           12 :           dw_die_ref c;
   11667              : 
   11668           36 :           FOR_EACH_CHILD (die, c, add_enumerator_pubname (scope_name, c));
   11669              :         }
   11670              :     }
   11671              : }
   11672              : 
   11673              : /* Output a single entry in the pubnames table.  */
   11674              : 
   11675              : static void
   11676          791 : output_pubname (dw_offset die_offset, pubname_entry *entry)
   11677              : {
   11678          791 :   dw_die_ref die = entry->die;
   11679          791 :   int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
   11680              : 
   11681          791 :   dw2_asm_output_data (dwarf_offset_size, die_offset, "DIE offset");
   11682              : 
   11683          791 :   if (debug_generate_pub_sections == 2)
   11684              :     {
   11685              :       /* This logic follows gdb's method for determining the value of the flag
   11686              :          byte.  */
   11687          445 :       uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE;
   11688          445 :       switch (die->die_tag)
   11689              :       {
   11690              :         case DW_TAG_typedef:
   11691              :         case DW_TAG_base_type:
   11692              :         case DW_TAG_subrange_type:
   11693              :           GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
   11694          192 :           GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
   11695              :           break;
   11696            0 :         case DW_TAG_enumerator:
   11697            0 :           GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
   11698              :                                           GDB_INDEX_SYMBOL_KIND_VARIABLE);
   11699            0 :           if (!is_cxx ())
   11700            0 :             GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
   11701              :           break;
   11702          244 :         case DW_TAG_subprogram:
   11703          244 :           GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
   11704              :                                           GDB_INDEX_SYMBOL_KIND_FUNCTION);
   11705          244 :           if (!is_ada ())
   11706          244 :             GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
   11707              :           break;
   11708            0 :         case DW_TAG_constant:
   11709            0 :           GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
   11710              :                                           GDB_INDEX_SYMBOL_KIND_VARIABLE);
   11711            0 :           GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
   11712            0 :           break;
   11713            6 :         case DW_TAG_variable:
   11714            6 :           GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags,
   11715              :                                           GDB_INDEX_SYMBOL_KIND_VARIABLE);
   11716            6 :           GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static);
   11717            6 :           break;
   11718              :         case DW_TAG_namespace:
   11719              :         case DW_TAG_imported_declaration:
   11720            3 :           GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
   11721              :           break;
   11722            0 :         case DW_TAG_class_type:
   11723            0 :         case DW_TAG_interface_type:
   11724            0 :         case DW_TAG_structure_type:
   11725            0 :         case DW_TAG_union_type:
   11726            0 :         case DW_TAG_enumeration_type:
   11727            0 :           GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE);
   11728            0 :           if (!is_cxx ())
   11729          192 :             GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1);
   11730              :           break;
   11731              :         default:
   11732              :           /* An unusual tag.  Leave the flag-byte empty.  */
   11733              :           break;
   11734              :       }
   11735          445 :       dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE,
   11736              :                            "GDB-index flags");
   11737              :     }
   11738              : 
   11739          791 :   dw2_asm_output_nstring (entry->name, -1, "external name");
   11740          791 : }
   11741              : 
   11742              : 
   11743              : /* Output the public names table used to speed up access to externally
   11744              :    visible names; or the public types table used to find type definitions.  */
   11745              : 
   11746              : static void
   11747          512 : output_pubnames (vec<pubname_entry, va_gc> *names)
   11748              : {
   11749          512 :   unsigned i;
   11750          512 :   unsigned long pubnames_length = size_of_pubnames (names);
   11751          512 :   pubname_entry *pub;
   11752              : 
   11753          512 :   if (!XCOFF_DEBUGGING_INFO)
   11754              :     {
   11755          512 :       if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   11756            0 :         dw2_asm_output_data (4, 0xffffffff,
   11757              :           "Initial length escape value indicating 64-bit DWARF extension");
   11758          512 :       dw2_asm_output_data (dwarf_offset_size, pubnames_length,
   11759              :                            "Pub Info Length");
   11760              :     }
   11761              : 
   11762              :   /* Version number for pubnames/pubtypes is independent of dwarf version.  */
   11763          512 :   dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
   11764              : 
   11765          512 :   if (dwarf_split_debug_info)
   11766          498 :     dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
   11767              :                            debug_skeleton_info_section,
   11768              :                            "Offset of Compilation Unit Info");
   11769              :   else
   11770           14 :     dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
   11771              :                            debug_info_section,
   11772              :                            "Offset of Compilation Unit Info");
   11773          512 :   dw2_asm_output_data (dwarf_offset_size, next_die_offset,
   11774              :                        "Compilation Unit Length");
   11775              : 
   11776         1886 :   FOR_EACH_VEC_ELT (*names, i, pub)
   11777              :     {
   11778          862 :       if (include_pubname_in_output (names, pub))
   11779              :         {
   11780          791 :           dw_offset die_offset = pub->die->die_offset;
   11781              : 
   11782              :           /* We shouldn't see pubnames for DIEs outside of the main CU.  */
   11783          791 :           if (names == pubname_table && pub->die->die_tag != DW_TAG_enumerator)
   11784          471 :             gcc_assert (pub->die->die_mark);
   11785              : 
   11786              :           /* If we're putting types in their own .debug_types sections,
   11787              :              the .debug_pubtypes table will still point to the compile
   11788              :              unit (not the type unit), so we want to use the offset of
   11789              :              the skeleton DIE (if there is one).  */
   11790          791 :           if (pub->die->comdat_type_p && names == pubtype_table)
   11791              :             {
   11792           33 :               comdat_type_node *type_node = pub->die->die_id.die_type_node;
   11793              : 
   11794           33 :               if (type_node != NULL)
   11795           33 :                 die_offset = (type_node->skeleton_die != NULL
   11796           33 :                               ? type_node->skeleton_die->die_offset
   11797            6 :                               : comp_unit_die ()->die_offset);
   11798              :             }
   11799              : 
   11800          791 :           output_pubname (die_offset, pub);
   11801              :         }
   11802              :     }
   11803              : 
   11804          512 :   dw2_asm_output_data (dwarf_offset_size, 0, NULL);
   11805          512 : }
   11806              : 
   11807              : /* Output public names and types tables if necessary.  */
   11808              : 
   11809              : static void
   11810        53235 : output_pubtables (void)
   11811              : {
   11812        53235 :   if (!want_pubnames () || !info_section_emitted)
   11813              :     return;
   11814              : 
   11815          256 :   switch_to_section (debug_pubnames_section);
   11816          256 :   output_pubnames (pubname_table);
   11817              :   /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
   11818              :      It shouldn't hurt to emit it always, since pure DWARF2 consumers
   11819              :      simply won't look for the section.  */
   11820          256 :   switch_to_section (debug_pubtypes_section);
   11821          256 :   output_pubnames (pubtype_table);
   11822              : }
   11823              : 
   11824              : 
   11825              : /* Output the information that goes into the .debug_aranges table.
   11826              :    Namely, define the beginning and ending address range of the
   11827              :    text section generated for this compilation unit.  */
   11828              : 
   11829              : static void
   11830        52183 : output_aranges (void)
   11831              : {
   11832        52183 :   unsigned i;
   11833        52183 :   unsigned long aranges_length = size_of_aranges ();
   11834              : 
   11835        52183 :   if (!XCOFF_DEBUGGING_INFO)
   11836              :     {
   11837        52183 :       if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   11838            0 :         dw2_asm_output_data (4, 0xffffffff,
   11839              :           "Initial length escape value indicating 64-bit DWARF extension");
   11840        52183 :       dw2_asm_output_data (dwarf_offset_size, aranges_length,
   11841              :                            "Length of Address Ranges Info");
   11842              :     }
   11843              : 
   11844              :   /* Version number for aranges is still 2, even up to DWARF5.  */
   11845        52183 :   dw2_asm_output_data (2, 2, "DWARF aranges version");
   11846        52183 :   if (dwarf_split_debug_info)
   11847          249 :     dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
   11848              :                            debug_skeleton_info_section,
   11849              :                            "Offset of Compilation Unit Info");
   11850              :   else
   11851        51934 :     dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
   11852              :                            debug_info_section,
   11853              :                            "Offset of Compilation Unit Info");
   11854        58522 :   dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
   11855        52183 :   dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
   11856              : 
   11857              :   /* We need to align to twice the pointer size here.  */
   11858        71200 :   if (DWARF_ARANGES_PAD_SIZE)
   11859              :     {
   11860              :       /* Pad using a 2 byte words so that padding is correct for any
   11861              :          pointer size.  */
   11862        52183 :       dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
   11863        52181 :                            2 * DWARF2_ADDR_SIZE);
   11864       194583 :       for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
   11865        52183 :         dw2_asm_output_data (2, 0, NULL);
   11866              :     }
   11867              : 
   11868              :   /* It is necessary not to output these entries if the sections were
   11869              :      not used; if the sections were not used, the length will be 0 and
   11870              :      the address may end up as 0 if the section is discarded by ld
   11871              :      --gc-sections, leaving an invalid (0, 0) entry that can be
   11872              :      confused with the terminator.  */
   11873        52183 :   if (switch_text_ranges)
   11874              :     {
   11875              :       const char *prev_loc = text_section_label;
   11876              :       const char *loc;
   11877              :       unsigned idx;
   11878              : 
   11879        29712 :       FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
   11880          102 :         if (prev_loc)
   11881              :           {
   11882          102 :             dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
   11883          102 :             dw2_asm_output_delta (DWARF2_ADDR_SIZE, loc, prev_loc, "Length");
   11884          102 :             prev_loc = NULL;
   11885              :           }
   11886              :         else
   11887              :           prev_loc = loc;
   11888              : 
   11889        29610 :       if (prev_loc)
   11890              :         {
   11891        32584 :           dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
   11892        32584 :           dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
   11893              :                                 prev_loc, "Length");
   11894              :         }
   11895              :     }
   11896              : 
   11897        52183 :   if (switch_cold_ranges)
   11898              :     {
   11899              :       const char *prev_loc = cold_text_section_label;
   11900              :       const char *loc;
   11901              :       unsigned idx;
   11902              : 
   11903         9320 :       FOR_EACH_VEC_ELT (*switch_cold_ranges, idx, loc)
   11904            0 :         if (prev_loc)
   11905              :           {
   11906            0 :             dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
   11907            0 :             dw2_asm_output_delta (DWARF2_ADDR_SIZE, loc, prev_loc, "Length");
   11908            0 :             prev_loc = NULL;
   11909              :           }
   11910              :         else
   11911              :           prev_loc = loc;
   11912              : 
   11913         9320 :       if (prev_loc)
   11914              :         {
   11915         9642 :           dw2_asm_output_addr (DWARF2_ADDR_SIZE, prev_loc, "Address");
   11916         9642 :           dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
   11917              :                                 prev_loc, "Length");
   11918              :         }
   11919              :     }
   11920              : 
   11921        52183 :   if (have_multiple_function_sections)
   11922              :     {
   11923              :       unsigned fde_idx;
   11924              :       dw_fde_ref fde;
   11925              : 
   11926       300656 :       FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
   11927              :         {
   11928       271276 :           if (fde->ignored_debug)
   11929         2546 :             continue;
   11930       268730 :           if (!fde->in_std_section)
   11931              :             {
   11932       206800 :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
   11933              :                                    "Address");
   11934       206800 :               dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
   11935              :                                     fde->dw_fde_begin, "Length");
   11936              :             }
   11937       268730 :           if (fde->dw_fde_second_begin && !fde->second_in_std_section)
   11938              :             {
   11939        11221 :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
   11940              :                                    "Address");
   11941        11221 :               dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
   11942              :                                     fde->dw_fde_second_begin, "Length");
   11943              :             }
   11944              :         }
   11945              :     }
   11946              : 
   11947              :   /* Output the terminator words.  */
   11948        58522 :   dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
   11949        58522 :   dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
   11950        52183 : }
   11951              : 
   11952              : /* Add a new entry to .debug_ranges.  Return its index into
   11953              :    ranges_table vector.  */
   11954              : 
   11955              : static unsigned int
   11956     11775674 : add_ranges_num (int num, bool maybe_new_sec)
   11957              : {
   11958     11775674 :   dw_ranges r = { NULL, num, 0, maybe_new_sec, NULL, NULL };
   11959     11775674 :   vec_safe_push (ranges_table, r);
   11960     11775674 :   return vec_safe_length (ranges_table) - 1;
   11961              : }
   11962              : 
   11963              : /* Add a new entry to .debug_ranges corresponding to a block, or a
   11964              :    range terminator if BLOCK is NULL.  MAYBE_NEW_SEC is true if
   11965              :    this entry might be in a different section from previous range.  */
   11966              : 
   11967              : static unsigned int
   11968     11504537 : add_ranges (const_tree block, bool maybe_new_sec)
   11969              : {
   11970     17202110 :   return add_ranges_num (block ? BLOCK_NUMBER (block) : 0, maybe_new_sec);
   11971              : }
   11972              : 
   11973              : /* Note that (*rnglist_table)[offset] is either a head of a rnglist
   11974              :    chain, or middle entry of a chain that will be directly referred to.  */
   11975              : 
   11976              : static void
   11977      3498191 : note_rnglist_head (unsigned int offset)
   11978              : {
   11979      3498191 :   if (dwarf_version < 5 || (*ranges_table)[offset].label)
   11980              :     return;
   11981      2907998 :   (*ranges_table)[offset].label = gen_internal_sym ("LLRL");
   11982              : }
   11983              : 
   11984              : /* Add a new entry to .debug_ranges corresponding to a pair of labels.
   11985              :    When using dwarf_split_debug_info, address attributes in dies destined
   11986              :    for the final executable should be direct references--setting the
   11987              :    parameter force_direct ensures this behavior.  */
   11988              : 
   11989              : static void
   11990       271137 : add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
   11991              :                       bool *added, bool force_direct)
   11992              : {
   11993       271137 :   unsigned int in_use = vec_safe_length (ranges_by_label);
   11994       271137 :   unsigned int offset;
   11995       271137 :   dw_ranges_by_label rbl = { begin, end };
   11996       271137 :   vec_safe_push (ranges_by_label, rbl);
   11997       271137 :   offset = add_ranges_num (-(int)in_use - 1, true);
   11998       271137 :   if (!*added)
   11999              :     {
   12000        52020 :       add_AT_range_list (die, DW_AT_ranges, offset, force_direct);
   12001        52020 :       *added = true;
   12002        52020 :       note_rnglist_head (offset);
   12003        52020 :       if (dwarf_split_debug_info && force_direct)
   12004            2 :         (*ranges_table)[offset].idx = DW_RANGES_IDX_SKELETON;
   12005              :     }
   12006       271137 : }
   12007              : 
   12008              : /* Emit .debug_ranges section.  */
   12009              : 
   12010              : static void
   12011          522 : output_ranges (void)
   12012              : {
   12013          522 :   unsigned i;
   12014          522 :   static const char *const start_fmt = "Offset %#x";
   12015          522 :   const char *fmt = start_fmt;
   12016          522 :   dw_ranges *r;
   12017              : 
   12018          522 :   switch_to_section (debug_ranges_section);
   12019          522 :   ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
   12020         5181 :   FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
   12021              :     {
   12022         4137 :       int block_num = r->num;
   12023              : 
   12024         4137 :       if (block_num > 0)
   12025              :         {
   12026         1774 :           char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
   12027         1774 :           char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
   12028              : 
   12029         1774 :           ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
   12030         1774 :           ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
   12031              : 
   12032              :           /* If all code is in the text section, then the compilation
   12033              :              unit base address defaults to DW_AT_low_pc, which is the
   12034              :              base of the text section.  */
   12035         1774 :           if (!have_multiple_function_sections)
   12036              :             {
   12037          482 :               dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
   12038              :                                     text_section_label,
   12039          482 :                                     fmt, i * 2 * DWARF2_ADDR_SIZE);
   12040          482 :               dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
   12041              :                                     text_section_label, NULL);
   12042              :             }
   12043              : 
   12044              :           /* Otherwise, the compilation unit base address is zero,
   12045              :              which allows us to use absolute addresses, and not worry
   12046              :              about whether the target supports cross-section
   12047              :              arithmetic.  */
   12048              :           else
   12049              :             {
   12050         1292 :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
   12051         1292 :                                    fmt, i * 2 * DWARF2_ADDR_SIZE);
   12052         1292 :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
   12053              :             }
   12054              : 
   12055         1774 :           fmt = NULL;
   12056              :         }
   12057              : 
   12058              :       /* Negative block_num stands for an index into ranges_by_label.  */
   12059         2363 :       else if (block_num < 0)
   12060              :         {
   12061         1265 :           int lab_idx = - block_num - 1;
   12062              : 
   12063         1265 :           if (!have_multiple_function_sections)
   12064              :             {
   12065            0 :               gcc_unreachable ();
   12066              : #if 0
   12067              :               /* If we ever use add_ranges_by_labels () for a single
   12068              :                  function section, all we have to do is to take out
   12069              :                  the #if 0 above.  */
   12070              :               dw2_asm_output_delta (DWARF2_ADDR_SIZE,
   12071              :                                     (*ranges_by_label)[lab_idx].begin,
   12072              :                                     text_section_label,
   12073              :                                     fmt, i * 2 * DWARF2_ADDR_SIZE);
   12074              :               dw2_asm_output_delta (DWARF2_ADDR_SIZE,
   12075              :                                     (*ranges_by_label)[lab_idx].end,
   12076              :                                     text_section_label, NULL);
   12077              : #endif
   12078              :             }
   12079              :           else
   12080              :             {
   12081         1265 :               dw2_asm_output_addr (DWARF2_ADDR_SIZE,
   12082         1265 :                                    (*ranges_by_label)[lab_idx].begin,
   12083         1265 :                                    fmt, i * 2 * DWARF2_ADDR_SIZE);
   12084         1265 :               dw2_asm_output_addr (DWARF2_ADDR_SIZE,
   12085         1265 :                                    (*ranges_by_label)[lab_idx].end,
   12086              :                                    NULL);
   12087              :             }
   12088              :         }
   12089              :       else
   12090              :         {
   12091         1098 :           dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
   12092         1098 :           dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
   12093         1098 :           fmt = start_fmt;
   12094              :         }
   12095              :     }
   12096          522 : }
   12097              : 
   12098              : /* Non-zero if .debug_line_str should be used for .debug_line section
   12099              :    strings or strings that are likely shareable with those.  */
   12100              : #define DWARF5_USE_DEBUG_LINE_STR \
   12101              :   (!DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET            \
   12102              :    && (DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) != 0                \
   12103              :    /* FIXME: there is no .debug_line_str.dwo section,           \
   12104              :       for -gsplit-dwarf we should use DW_FORM_strx instead.  */ \
   12105              :    && !dwarf_split_debug_info)
   12106              : 
   12107              : 
   12108              : /* Returns TRUE if we are outputting DWARF5 and the assembler supports
   12109              :    DWARF5 .debug_line tables using .debug_line_str or we generate
   12110              :    it ourselves, except for split-dwarf which doesn't have a
   12111              :    .debug_line_str.  */
   12112              : static bool
   12113       162493 : asm_outputs_debug_line_str (void)
   12114              : {
   12115       162493 :   if (dwarf_version >= 5
   12116       156491 :       && ! output_asm_line_debug_info ()
   12117       162499 :       && DWARF5_USE_DEBUG_LINE_STR)
   12118              :     return true;
   12119              :   else
   12120              :     {
   12121              : #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
   12122       162487 :       return !dwarf_split_debug_info && dwarf_version >= 5;
   12123              : #else
   12124              :       return false;
   12125              : #endif
   12126              :     }
   12127              : }
   12128              : 
   12129              : /* Return true if it is beneficial to use DW_RLE_base_address{,x}.
   12130              :    I is index of the following range.  */
   12131              : 
   12132              : static bool
   12133      2759709 : use_distinct_base_address_for_range (unsigned int i)
   12134              : {
   12135      2941183 :   if (i >= vec_safe_length (ranges_table))
   12136              :     return false;
   12137              : 
   12138      2759709 :   dw_ranges *r2 = &(*ranges_table)[i];
   12139              :   /* Use DW_RLE_base_address{,x} if there is a next range in the
   12140              :      range list and is guaranteed to be in the same section.  */
   12141      2759709 :   return r2->num != 0 && r2->label == NULL && !r2->maybe_new_sec;
   12142              : }
   12143              : 
   12144              : /* Assign .debug_rnglists indexes and unique indexes into the debug_addr
   12145              :    section when needed.  */
   12146              : 
   12147              : static void
   12148            3 : index_rnglists (void)
   12149              : {
   12150            3 :   unsigned i;
   12151            3 :   dw_ranges *r;
   12152            3 :   bool base = false;
   12153              : 
   12154           19 :   FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
   12155              :     {
   12156           16 :       if (r->label && r->idx != DW_RANGES_IDX_SKELETON)
   12157            3 :         r->idx = rnglist_idx++;
   12158              : 
   12159           16 :       int block_num = r->num;
   12160           20 :       if ((HAVE_AS_LEB128 || block_num < 0)
   12161           16 :           && !have_multiple_function_sections)
   12162            4 :         continue;
   12163           12 :       if (HAVE_AS_LEB128 && (r->label || r->maybe_new_sec))
   12164            8 :         base = false;
   12165           12 :       if (block_num > 0)
   12166              :         {
   12167            0 :           char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
   12168            0 :           char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
   12169              : 
   12170            0 :           ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
   12171            0 :           ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
   12172              : 
   12173            0 :           if (HAVE_AS_LEB128)
   12174              :             {
   12175            0 :               if (!base && use_distinct_base_address_for_range (i + 1))
   12176              :                 {
   12177            0 :                   r->begin_entry = add_addr_table_entry (xstrdup (blabel),
   12178              :                                                          ate_kind_label);
   12179            0 :                   base = true;
   12180              :                 }
   12181            0 :               if (base)
   12182              :                 /* If we have a base, no need for further
   12183              :                    begin_entry/end_entry, as DW_RLE_offset_pair will be
   12184              :                    used.  */
   12185            0 :                 continue;
   12186            0 :               r->begin_entry
   12187            0 :                 = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
   12188              :               /* No need for end_entry, DW_RLE_start{,x}_length will use
   12189              :                  length as opposed to a pair of addresses.  */
   12190              :             }
   12191              :           else
   12192              :             {
   12193              :               r->begin_entry
   12194              :                 = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
   12195              :               r->end_entry
   12196              :                 = add_addr_table_entry (xstrdup (elabel), ate_kind_label);
   12197              :             }
   12198              :         }
   12199              : 
   12200              :       /* Negative block_num stands for an index into ranges_by_label.  */
   12201           12 :       else if (block_num < 0)
   12202              :         {
   12203            8 :           int lab_idx = - block_num - 1;
   12204            8 :           const char *blabel = (*ranges_by_label)[lab_idx].begin;
   12205            8 :           const char *elabel = (*ranges_by_label)[lab_idx].end;
   12206              : 
   12207            8 :           r->begin_entry
   12208            8 :             = add_addr_table_entry (xstrdup (blabel), ate_kind_label);
   12209            8 :           if (!HAVE_AS_LEB128)
   12210              :             r->end_entry
   12211              :               = add_addr_table_entry (xstrdup (elabel), ate_kind_label);
   12212              :         }
   12213              :     }
   12214            3 : }
   12215              : 
   12216              : /* Emit .debug_rnglists or (when DWO is true) .debug_rnglists.dwo section.  */
   12217              : 
   12218              : static bool
   12219        33650 : output_rnglists (unsigned generation, bool dwo)
   12220              : {
   12221        33650 :   unsigned i;
   12222        33650 :   dw_ranges *r;
   12223        33650 :   char l1[MAX_ARTIFICIAL_LABEL_BYTES];
   12224        33650 :   char l2[MAX_ARTIFICIAL_LABEL_BYTES];
   12225        33650 :   char basebuf[MAX_ARTIFICIAL_LABEL_BYTES];
   12226              : 
   12227        33650 :   if (dwo)
   12228            3 :     switch_to_section (debug_ranges_dwo_section);
   12229              :   else
   12230              :     {
   12231        33647 :       switch_to_section (debug_ranges_section);
   12232        33647 :       ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
   12233              :     }
   12234              :   /* There are up to 4 unique ranges labels per generation.
   12235              :      See also init_sections_and_labels.  */
   12236        33650 :   ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_RANGES_SECTION_LABEL,
   12237              :                                2 + 2 * dwo + generation * 6);
   12238        33650 :   ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_RANGES_SECTION_LABEL,
   12239              :                                3 + 2 * dwo + generation * 6);
   12240        33650 :   if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   12241            0 :     dw2_asm_output_data (4, 0xffffffff,
   12242              :                          "Initial length escape value indicating "
   12243              :                          "64-bit DWARF extension");
   12244        33650 :   dw2_asm_output_delta (dwarf_offset_size, l2, l1,
   12245              :                         "Length of Range Lists");
   12246        33650 :   ASM_OUTPUT_LABEL (asm_out_file, l1);
   12247        33650 :   output_dwarf_version ();
   12248        38159 :   dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
   12249        33650 :   dw2_asm_output_data (1, 0, "Segment Size");
   12250              :   /* Emit the offset table only for -gsplit-dwarf.  If we don't care
   12251              :      about relocation sizes and primarily care about the size of .debug*
   12252              :      sections in linked shared libraries and executables, then
   12253              :      the offset table plus corresponding DW_FORM_rnglistx uleb128 indexes
   12254              :      into it are usually larger than just DW_FORM_sec_offset offsets
   12255              :      into the .debug_rnglists section.  */
   12256        33650 :   dw2_asm_output_data (4, dwo ? rnglist_idx : 0,
   12257              :                        "Offset Entry Count");
   12258        33650 :   if (dwo)
   12259              :     {
   12260            3 :       ASM_OUTPUT_LABEL (asm_out_file, ranges_base_label);
   12261           22 :       FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
   12262           16 :         if (r->label && r->idx != DW_RANGES_IDX_SKELETON)
   12263            3 :           dw2_asm_output_delta (dwarf_offset_size, r->label,
   12264              :                                 ranges_base_label, NULL);
   12265              :     }
   12266              : 
   12267        33650 :   const char *lab = "";
   12268        33650 :   const char *base = NULL;
   12269        33650 :   bool skipping = false;
   12270        33650 :   bool ret = false;
   12271     11805196 :   FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
   12272              :     {
   12273     11771546 :       int block_num = r->num;
   12274              : 
   12275     11771546 :       if (r->label)
   12276              :         {
   12277      2908001 :           if (dwarf_split_debug_info
   12278            9 :               && (r->idx == DW_RANGES_IDX_SKELETON) == dwo)
   12279              :             {
   12280            4 :               ret = true;
   12281            4 :               skipping = true;
   12282            4 :               continue;
   12283              :             }
   12284      2907997 :           ASM_OUTPUT_LABEL (asm_out_file, r->label);
   12285      2907997 :           lab = r->label;
   12286              :         }
   12287     11771542 :       if (skipping)
   12288              :         {
   12289            8 :           if (block_num == 0)
   12290            4 :             skipping = false;
   12291            8 :           continue;
   12292              :         }
   12293     11771534 :       if (HAVE_AS_LEB128 && (r->label || r->maybe_new_sec))
   12294      3277138 :         base = NULL;
   12295     11771534 :       if (block_num > 0)
   12296              :         {
   12297      8599279 :           char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
   12298      8599279 :           char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
   12299              : 
   12300      8599279 :           ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
   12301      8599279 :           ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
   12302              : 
   12303      8599279 :           if (HAVE_AS_LEB128)
   12304              :             {
   12305              :               /* If all code is in the text section, then the compilation
   12306              :                  unit base address defaults to DW_AT_low_pc, which is the
   12307              :                  base of the text section.  */
   12308      8599279 :               if (!have_multiple_function_sections)
   12309              :                 {
   12310       849428 :                   dw2_asm_output_data (1, DW_RLE_offset_pair,
   12311              :                                        "DW_RLE_offset_pair (%s)", lab);
   12312       849428 :                   dw2_asm_output_delta_uleb128 (blabel, text_section_label,
   12313              :                                                 "Range begin address (%s)", lab);
   12314       849428 :                   dw2_asm_output_delta_uleb128 (elabel, text_section_label,
   12315              :                                                 "Range end address (%s)", lab);
   12316      8417805 :                   continue;
   12317              :                 }
   12318      7749851 :               if (base == NULL && use_distinct_base_address_for_range (i + 1))
   12319              :                 {
   12320      2578235 :                   if (dwarf_split_debug_info)
   12321              :                     {
   12322            0 :                       dw2_asm_output_data (1, DW_RLE_base_addressx,
   12323              :                                            "DW_RLE_base_addressx (%s)", lab);
   12324            0 :                       dw2_asm_output_data_uleb128 (r->begin_entry->index,
   12325              :                                                    "Base address index (%s)",
   12326              :                                                    blabel);
   12327              :                     }
   12328              :                   else
   12329              :                     {
   12330      2578235 :                       dw2_asm_output_data (1, DW_RLE_base_address,
   12331              :                                            "DW_RLE_base_address (%s)", lab);
   12332      2682896 :                       dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
   12333              :                                            "Base address (%s)", lab);
   12334              :                     }
   12335      2578235 :                   strcpy (basebuf, blabel);
   12336      2578235 :                   base = basebuf;
   12337              :                 }
   12338      7749851 :               if (base)
   12339              :                 {
   12340      7568377 :                   dw2_asm_output_data (1, DW_RLE_offset_pair,
   12341              :                                        "DW_RLE_offset_pair (%s)", lab);
   12342      7568377 :                   dw2_asm_output_delta_uleb128 (blabel, base,
   12343              :                                                 "Range begin address (%s)", lab);
   12344      7568377 :                   dw2_asm_output_delta_uleb128 (elabel, base,
   12345              :                                                 "Range end address (%s)", lab);
   12346      7568377 :                   continue;
   12347              :                 }
   12348       181474 :               if (dwarf_split_debug_info)
   12349              :                 {
   12350            0 :                   dw2_asm_output_data (1, DW_RLE_startx_length,
   12351              :                                        "DW_RLE_startx_length (%s)", lab);
   12352            0 :                   dw2_asm_output_data_uleb128 (r->begin_entry->index,
   12353              :                                                "Range begin address index "
   12354              :                                                "(%s)", blabel);
   12355              :                 }
   12356              :               else
   12357              :                 {
   12358       181474 :                   dw2_asm_output_data (1, DW_RLE_start_length,
   12359              :                                        "DW_RLE_start_length (%s)", lab);
   12360       185468 :                   dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
   12361              :                                        "Range begin address (%s)", lab);
   12362              :                 }
   12363       181474 :               dw2_asm_output_delta_uleb128 (elabel, blabel,
   12364              :                                             "Range length (%s)", lab);
   12365              :             }
   12366              :           else if (dwarf_split_debug_info)
   12367              :             {
   12368              :               dw2_asm_output_data (1, DW_RLE_startx_endx,
   12369              :                                    "DW_RLE_startx_endx (%s)", lab);
   12370              :               dw2_asm_output_data_uleb128 (r->begin_entry->index,
   12371              :                                            "Range begin address index "
   12372              :                                            "(%s)", blabel);
   12373              :               dw2_asm_output_data_uleb128 (r->end_entry->index,
   12374              :                                            "Range end address index "
   12375              :                                            "(%s)", elabel);
   12376              :             }
   12377              :           else
   12378              :             {
   12379              :               dw2_asm_output_data (1, DW_RLE_start_end,
   12380              :                                    "DW_RLE_start_end (%s)", lab);
   12381              :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
   12382              :                                    "Range begin address (%s)", lab);
   12383              :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel,
   12384              :                                    "Range end address (%s)", lab);
   12385              :             }
   12386              :         }
   12387              : 
   12388              :       /* Negative block_num stands for an index into ranges_by_label.  */
   12389      3172255 :       else if (block_num < 0)
   12390              :         {
   12391       269872 :           int lab_idx = - block_num - 1;
   12392       269872 :           const char *blabel = (*ranges_by_label)[lab_idx].begin;
   12393       269872 :           const char *elabel = (*ranges_by_label)[lab_idx].end;
   12394              : 
   12395       269872 :           if (!have_multiple_function_sections)
   12396            0 :             gcc_unreachable ();
   12397       269872 :           if (HAVE_AS_LEB128)
   12398              :             {
   12399       269872 :               if (dwarf_split_debug_info)
   12400              :                 {
   12401            8 :                   dw2_asm_output_data (1, DW_RLE_startx_length,
   12402              :                                        "DW_RLE_startx_length (%s)", lab);
   12403            8 :                   dw2_asm_output_data_uleb128 (r->begin_entry->index,
   12404              :                                                "Range begin address index "
   12405              :                                                "(%s)", blabel);
   12406              :                 }
   12407              :               else
   12408              :                 {
   12409       269864 :                   dw2_asm_output_data (1, DW_RLE_start_length,
   12410              :                                        "DW_RLE_start_length (%s)", lab);
   12411       285192 :                   dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
   12412              :                                        "Range begin address (%s)", lab);
   12413              :                 }
   12414       269872 :               dw2_asm_output_delta_uleb128 (elabel, blabel,
   12415              :                                             "Range length (%s)", lab);
   12416              :             }
   12417              :           else if (dwarf_split_debug_info)
   12418              :             {
   12419              :               dw2_asm_output_data (1, DW_RLE_startx_endx,
   12420              :                                    "DW_RLE_startx_endx (%s)", lab);
   12421              :               dw2_asm_output_data_uleb128 (r->begin_entry->index,
   12422              :                                            "Range begin address index "
   12423              :                                            "(%s)", blabel);
   12424              :               dw2_asm_output_data_uleb128 (r->end_entry->index,
   12425              :                                            "Range end address index "
   12426              :                                            "(%s)", elabel);
   12427              :             }
   12428              :           else
   12429              :             {
   12430              :               dw2_asm_output_data (1, DW_RLE_start_end,
   12431              :                                    "DW_RLE_start_end (%s)", lab);
   12432              :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
   12433              :                                    "Range begin address (%s)", lab);
   12434              :               dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel,
   12435              :                                    "Range end address (%s)", lab);
   12436              :             }
   12437              :         }
   12438              :       else
   12439      2902383 :         dw2_asm_output_data (1, DW_RLE_end_of_list,
   12440              :                              "DW_RLE_end_of_list (%s)", lab);
   12441              :     }
   12442        33650 :   ASM_OUTPUT_LABEL (asm_out_file, l2);
   12443        33650 :   return ret;
   12444              : }
   12445              : 
   12446              : /* Data structure containing information about input files.  */
   12447              : struct file_info
   12448              : {
   12449              :   const char *path;     /* Complete file name.  */
   12450              :   const char *fname;    /* File name part.  */
   12451              :   int length;           /* Length of entire string.  */
   12452              :   struct dwarf_file_data * file_idx;    /* Index in input file table.  */
   12453              :   int dir_idx;          /* Index in directory table.  */
   12454              : };
   12455              : 
   12456              : /* Data structure containing information about directories with source
   12457              :    files.  */
   12458              : struct dir_info
   12459              : {
   12460              :   const char *path;     /* Path including directory name.  */
   12461              :   int length;           /* Path length.  */
   12462              :   int prefix;           /* Index of directory entry which is a prefix.  */
   12463              :   int count;            /* Number of files in this directory.  */
   12464              :   int dir_idx;          /* Index of directory used as base.  */
   12465              : };
   12466              : 
   12467              : /* Callback function for file_info comparison.  We sort by looking at
   12468              :    the directories in the path.  */
   12469              : 
   12470              : static int
   12471       103498 : file_info_cmp (const void *p1, const void *p2)
   12472              : {
   12473       103498 :   const struct file_info *const s1 = (const struct file_info *) p1;
   12474       103498 :   const struct file_info *const s2 = (const struct file_info *) p2;
   12475       103498 :   const unsigned char *cp1;
   12476       103498 :   const unsigned char *cp2;
   12477              : 
   12478              :   /* Take care of file names without directories.  We need to make sure that
   12479              :      we return consistent values to qsort since some will get confused if
   12480              :      we return the same value when identical operands are passed in opposite
   12481              :      orders.  So if neither has a directory, return 0 and otherwise return
   12482              :      1 or -1 depending on which one has the directory.  We want the one with
   12483              :      the directory to sort after the one without, so all no directory files
   12484              :      are at the start (normally only the compilation unit file).  */
   12485       103498 :   if ((s1->path == s1->fname || s2->path == s2->fname))
   12486         1855 :     return (s2->path == s2->fname) - (s1->path == s1->fname);
   12487              : 
   12488              :   cp1 = (const unsigned char *) s1->path;
   12489              :   cp2 = (const unsigned char *) s2->path;
   12490              : 
   12491      4479286 :   while (1)
   12492              :     {
   12493      4479286 :       ++cp1;
   12494      4479286 :       ++cp2;
   12495              :       /* Reached the end of the first path?  If so, handle like above,
   12496              :          but now we want longer directory prefixes before shorter ones.  */
   12497      4479286 :       if ((cp1 == (const unsigned char *) s1->fname)
   12498      4440510 :           || (cp2 == (const unsigned char *) s2->fname))
   12499        56269 :         return ((cp1 == (const unsigned char *) s1->fname)
   12500        56269 :                 - (cp2 == (const unsigned char *) s2->fname));
   12501              : 
   12502              :       /* Character of current path component the same?  */
   12503      4423017 :       else if (*cp1 != *cp2)
   12504        45374 :         return *cp1 - *cp2;
   12505              :     }
   12506              : }
   12507              : 
   12508              : struct file_name_acquire_data
   12509              : {
   12510              :   struct file_info *files;
   12511              :   int used_files;
   12512              :   int max_files;
   12513              : };
   12514              : 
   12515              : /* Traversal function for the hash table.  */
   12516              : 
   12517              : int
   12518         9543 : file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
   12519              : {
   12520         9543 :   struct dwarf_file_data *d = *slot;
   12521         9543 :   struct file_info *fi;
   12522         9543 :   const char *f;
   12523              : 
   12524         9543 :   gcc_assert (fnad->max_files >= d->emitted_number);
   12525              : 
   12526         9543 :   if (! d->emitted_number)
   12527              :     return 1;
   12528              : 
   12529         4713 :   gcc_assert (fnad->max_files != fnad->used_files);
   12530              : 
   12531         4713 :   fi = fnad->files + fnad->used_files++;
   12532              : 
   12533         4713 :   f = d->filename;
   12534              : 
   12535              :   /* Skip all leading "./".  */
   12536         4713 :   while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
   12537            0 :     f += 2;
   12538              : 
   12539              :   /* Create a new array entry.  */
   12540         4713 :   fi->path = f;
   12541         4713 :   fi->length = strlen (f);
   12542         4713 :   fi->file_idx = d;
   12543              : 
   12544              :   /* Search for the file name part.  */
   12545         4713 :   f = strrchr (f, DIR_SEPARATOR);
   12546              : #if defined (DIR_SEPARATOR_2)
   12547              :   {
   12548              :     const char *g = strrchr (fi->path, DIR_SEPARATOR_2);
   12549              : 
   12550              :     if (g != NULL)
   12551              :       {
   12552              :         if (f == NULL || f < g)
   12553              :           f = g;
   12554              :       }
   12555              :   }
   12556              : #endif
   12557              : 
   12558         4713 :   fi->fname = f == NULL ? fi->path : f + 1;
   12559         4713 :   return 1;
   12560              : }
   12561              : 
   12562              : /* Helper function for output_file_names.  Emit a FORM encoded
   12563              :    string STR, with assembly comment start ENTRY_KIND and
   12564              :    index IDX */
   12565              : 
   12566              : static void
   12567         9507 : output_line_string (enum dwarf_form form, const char *str,
   12568              :                     const char *entry_kind, unsigned int idx)
   12569              : {
   12570         9507 :   switch (form)
   12571              :     {
   12572          563 :     case DW_FORM_string:
   12573          563 :       dw2_asm_output_nstring (str, -1, "%s: %#x", entry_kind, idx);
   12574          563 :       break;
   12575         8944 :     case DW_FORM_line_strp:
   12576         8944 :       if (!debug_line_str_hash)
   12577            0 :         debug_line_str_hash
   12578            0 :           = hash_table<indirect_string_hasher>::create_ggc (10);
   12579              : 
   12580         8944 :       struct indirect_string_node *node;
   12581         8944 :       node = find_AT_string_in_table (str, debug_line_str_hash);
   12582         8944 :       set_indirect_string (node);
   12583         8944 :       node->form = form;
   12584         8944 :       dw2_asm_output_offset (dwarf_offset_size, node->label,
   12585              :                              debug_line_str_section, "%s: %#x: \"%s\"",
   12586              :                              entry_kind, 0, node->str);
   12587         8944 :       break;
   12588            0 :     default:
   12589            0 :       gcc_unreachable ();
   12590              :     }
   12591         9507 : }
   12592              : 
   12593              : /* Output the directory table and the file name table.  We try to minimize
   12594              :    the total amount of memory needed.  A heuristic is used to avoid large
   12595              :    slowdowns with many input files.  */
   12596              : 
   12597              : static void
   12598         1593 : output_file_names (void)
   12599              : {
   12600         1593 :   struct file_name_acquire_data fnad;
   12601         1593 :   int numfiles;
   12602         1593 :   struct file_info *files;
   12603         1593 :   struct dir_info *dirs;
   12604         1593 :   int *saved;
   12605         1593 :   int *savehere;
   12606         1593 :   int *backmap;
   12607         1593 :   int ndirs;
   12608         1593 :   int idx_offset;
   12609         1593 :   int i;
   12610              : 
   12611         1593 :   if (!last_emitted_file)
   12612              :     {
   12613           17 :       if (dwarf_version >= 5)
   12614              :         {
   12615           17 :           const char *comp_dir = comp_dir_string ();
   12616           17 :           if (comp_dir == NULL)
   12617            0 :             comp_dir = "";
   12618           17 :           dw2_asm_output_data (1, 1, "Directory entry format count");
   12619           17 :           enum dwarf_form str_form = DW_FORM_string;
   12620           17 :           if (DWARF5_USE_DEBUG_LINE_STR)
   12621           17 :             str_form = DW_FORM_line_strp;
   12622           17 :           dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
   12623           17 :           dw2_asm_output_data_uleb128 (str_form, "%s",
   12624              :                                        get_DW_FORM_name (str_form));
   12625           17 :           dw2_asm_output_data_uleb128 (1, "Directories count");
   12626           17 :           if (str_form == DW_FORM_string)
   12627            3 :             dw2_asm_output_nstring (comp_dir, -1, "Directory Entry: %#x", 0);
   12628              :           else
   12629           14 :             output_line_string (str_form, comp_dir, "Directory Entry", 0);
   12630           17 :           const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
   12631           17 :           if (filename0 == NULL)
   12632            0 :             filename0 = "";
   12633              : #ifdef VMS_DEBUGGING_INFO
   12634              :           dw2_asm_output_data (1, 4, "File name entry format count");
   12635              : #else
   12636           17 :           dw2_asm_output_data (1, 2, "File name entry format count");
   12637              : #endif
   12638           17 :           dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
   12639           17 :           dw2_asm_output_data_uleb128 (str_form, "%s",
   12640              :                                        get_DW_FORM_name (str_form));
   12641           17 :           dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
   12642              :                                        "DW_LNCT_directory_index");
   12643           17 :           dw2_asm_output_data_uleb128 (DW_FORM_data1, "%s",
   12644              :                                        get_DW_FORM_name (DW_FORM_data1));
   12645              : #ifdef VMS_DEBUGGING_INFO
   12646              :           dw2_asm_output_data_uleb128 (DW_LNCT_timestamp, "DW_LNCT_timestamp");
   12647              :           dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
   12648              :           dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
   12649              :           dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
   12650              : #endif
   12651           17 :           dw2_asm_output_data_uleb128 (1, "File names count");
   12652              : 
   12653           17 :           output_line_string (str_form, filename0, "File Entry", 0);
   12654           17 :           dw2_asm_output_data (1, 0, NULL);
   12655              : #ifdef VMS_DEBUGGING_INFO
   12656              :           dw2_asm_output_data_uleb128 (0, NULL);
   12657              :           dw2_asm_output_data_uleb128 (0, NULL);
   12658              : #endif
   12659              :         }
   12660              :       else
   12661              :         {
   12662            0 :           dw2_asm_output_data (1, 0, "End directory table");
   12663            0 :           dw2_asm_output_data (1, 0, "End file name table");
   12664              :         }
   12665           17 :       return;
   12666              :     }
   12667              : 
   12668         1576 :   numfiles = last_emitted_file->emitted_number;
   12669              : 
   12670              :   /* Allocate the various arrays we need.  */
   12671         1576 :   files = XALLOCAVEC (struct file_info, numfiles);
   12672         1576 :   dirs = XALLOCAVEC (struct dir_info, numfiles);
   12673              : 
   12674         1576 :   fnad.files = files;
   12675         1576 :   fnad.used_files = 0;
   12676         1576 :   fnad.max_files = numfiles;
   12677        11119 :   file_table->traverse<file_name_acquire_data *, file_name_acquire> (&fnad);
   12678         1576 :   gcc_assert (fnad.used_files == fnad.max_files);
   12679              : 
   12680         1576 :   qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
   12681              : 
   12682              :   /* Find all the different directories used.  */
   12683         1576 :   dirs[0].path = files[0].path;
   12684         1576 :   dirs[0].length = files[0].fname - files[0].path;
   12685         1576 :   dirs[0].prefix = -1;
   12686         1576 :   dirs[0].count = 1;
   12687         1576 :   dirs[0].dir_idx = 0;
   12688         1576 :   files[0].dir_idx = 0;
   12689         1576 :   ndirs = 1;
   12690              : 
   12691         4713 :   for (i = 1; i < numfiles; i++)
   12692         3137 :     if (files[i].fname - files[i].path == dirs[ndirs - 1].length
   12693         2200 :         && memcmp (dirs[ndirs - 1].path, files[i].path,
   12694              :                    dirs[ndirs - 1].length) == 0)
   12695              :       {
   12696              :         /* Same directory as last entry.  */
   12697         2197 :         files[i].dir_idx = ndirs - 1;
   12698         2197 :         ++dirs[ndirs - 1].count;
   12699              :       }
   12700              :     else
   12701              :       {
   12702          940 :         int j;
   12703              : 
   12704              :         /* This is a new directory.  */
   12705          940 :         dirs[ndirs].path = files[i].path;
   12706          940 :         dirs[ndirs].length = files[i].fname - files[i].path;
   12707          940 :         dirs[ndirs].count = 1;
   12708          940 :         dirs[ndirs].dir_idx = ndirs;
   12709          940 :         files[i].dir_idx = ndirs;
   12710              : 
   12711              :         /* Search for a prefix.  */
   12712          940 :         dirs[ndirs].prefix = -1;
   12713         4870 :         for (j = 0; j < ndirs; j++)
   12714         3930 :           if (dirs[j].length < dirs[ndirs].length
   12715         1404 :               && dirs[j].length > 1
   12716          957 :               && (dirs[ndirs].prefix == -1
   12717            0 :                   || dirs[j].length > dirs[dirs[ndirs].prefix].length)
   12718          957 :               && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
   12719            0 :             dirs[ndirs].prefix = j;
   12720              : 
   12721          940 :         ++ndirs;
   12722              :       }
   12723              : 
   12724              :   /* Now to the actual work.  We have to find a subset of the directories which
   12725              :      allow expressing the file name using references to the directory table
   12726              :      with the least amount of characters.  We do not do an exhaustive search
   12727              :      where we would have to check out every combination of every single
   12728              :      possible prefix.  Instead we use a heuristic which provides nearly optimal
   12729              :      results in most cases and never is much off.  */
   12730         1576 :   saved = XALLOCAVEC (int, ndirs);
   12731         1576 :   savehere = XALLOCAVEC (int, ndirs);
   12732              : 
   12733         1576 :   memset (saved, '\0', ndirs * sizeof (saved[0]));
   12734         4092 :   for (i = 0; i < ndirs; i++)
   12735              :     {
   12736         2516 :       int j;
   12737         2516 :       int total;
   12738              : 
   12739              :       /* We can always save some space for the current directory.  But this
   12740              :          does not mean it will be enough to justify adding the directory.  */
   12741         2516 :       savehere[i] = dirs[i].length;
   12742         2516 :       total = (savehere[i] - saved[i]) * dirs[i].count;
   12743              : 
   12744         6446 :       for (j = i + 1; j < ndirs; j++)
   12745              :         {
   12746         3930 :           savehere[j] = 0;
   12747         3930 :           if (saved[j] < dirs[i].length)
   12748              :             {
   12749              :               /* Determine whether the dirs[i] path is a prefix of the
   12750              :                  dirs[j] path.  */
   12751         3483 :               int k;
   12752              : 
   12753         3483 :               k = dirs[j].prefix;
   12754         3483 :               while (k != -1 && k != (int) i)
   12755            0 :                 k = dirs[k].prefix;
   12756              : 
   12757         3483 :               if (k == (int) i)
   12758              :                 {
   12759              :                   /* Yes it is.  We can possibly save some memory by
   12760              :                      writing the filenames in dirs[j] relative to
   12761              :                      dirs[i].  */
   12762            0 :                   savehere[j] = dirs[i].length;
   12763            0 :                   total += (savehere[j] - saved[j]) * dirs[j].count;
   12764              :                 }
   12765              :             }
   12766              :         }
   12767              : 
   12768              :       /* Check whether we can save enough to justify adding the dirs[i]
   12769              :          directory.  */
   12770         2516 :       if (total > dirs[i].length + 1)
   12771              :         {
   12772              :           /* It's worthwhile adding.  */
   12773         2270 :           for (j = i; j < ndirs; j++)
   12774         1834 :             if (savehere[j] > 0)
   12775              :               {
   12776              :                 /* Remember how much we saved for this directory so far.  */
   12777          436 :                 saved[j] = savehere[j];
   12778              : 
   12779              :                 /* Remember the prefix directory.  */
   12780          436 :                 dirs[j].dir_idx = i;
   12781              :               }
   12782              :         }
   12783              :     }
   12784              : 
   12785              :   /* Emit the directory name table.  */
   12786         1576 :   idx_offset = dirs[0].length > 0 ? 1 : 0;
   12787         1576 :   enum dwarf_form str_form = DW_FORM_string;
   12788         1576 :   enum dwarf_form idx_form = DW_FORM_udata;
   12789         1576 :   if (dwarf_version >= 5)
   12790              :     {
   12791         1525 :       const char *comp_dir = comp_dir_string ();
   12792         1525 :       if (comp_dir == NULL)
   12793            0 :         comp_dir = "";
   12794         1525 :       dw2_asm_output_data (1, 1, "Directory entry format count");
   12795         1525 :       if (DWARF5_USE_DEBUG_LINE_STR)
   12796         1525 :         str_form = DW_FORM_line_strp;
   12797         1525 :       dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
   12798         1525 :       dw2_asm_output_data_uleb128 (str_form, "%s",
   12799              :                                    get_DW_FORM_name (str_form));
   12800         1525 :       dw2_asm_output_data_uleb128 (ndirs + idx_offset, "Directories count");
   12801         1525 :       if (str_form == DW_FORM_string)
   12802              :         {
   12803          245 :           dw2_asm_output_nstring (comp_dir, -1, "Directory Entry: %#x", 0);
   12804          492 :           for (i = 1 - idx_offset; i < ndirs; i++)
   12805          247 :             dw2_asm_output_nstring (dirs[i].path,
   12806          247 :                                     dirs[i].length
   12807          247 :                                     - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
   12808              :                                     "Directory Entry: %#x", i + idx_offset);
   12809              :         }
   12810              :       else
   12811              :         {
   12812         1280 :           output_line_string (str_form, comp_dir, "Directory Entry", 0);
   12813         3238 :           for (i = 1 - idx_offset; i < ndirs; i++)
   12814              :             {
   12815         1958 :               const char *str
   12816         3916 :                 = ggc_alloc_string (dirs[i].path,
   12817         1958 :                                     dirs[i].length
   12818              :                                     - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR);
   12819         1958 :               output_line_string (str_form, str, "Directory Entry",
   12820         1958 :                                   (unsigned) i + idx_offset);
   12821              :             }
   12822              :         }
   12823              :     }
   12824              :   else
   12825              :     {
   12826          118 :       for (i = 1 - idx_offset; i < ndirs; i++)
   12827           67 :         dw2_asm_output_nstring (dirs[i].path,
   12828           67 :                                 dirs[i].length
   12829           67 :                                 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
   12830              :                                 "Directory Entry: %#x", i + idx_offset);
   12831              : 
   12832           51 :       dw2_asm_output_data (1, 0, "End directory table");
   12833              :     }
   12834              : 
   12835              :   /* We have to emit them in the order of emitted_number since that's
   12836              :      used in the debug info generation.  To do this efficiently we
   12837              :      generate a back-mapping of the indices first.  */
   12838         1576 :   backmap = XALLOCAVEC (int, numfiles);
   12839         6289 :   for (i = 0; i < numfiles; i++)
   12840         4713 :     backmap[files[i].file_idx->emitted_number - 1] = i;
   12841              : 
   12842         1576 :   if (dwarf_version >= 5)
   12843              :     {
   12844         1525 :       const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
   12845         1525 :       if (filename0 == NULL)
   12846            0 :         filename0 = "";
   12847              :       /* DW_LNCT_directory_index can use DW_FORM_udata, DW_FORM_data1 and
   12848              :          DW_FORM_data2.  Choose one based on the number of directories
   12849              :          and how much space would they occupy in each encoding.
   12850              :          If we have at most 256 directories, all indexes fit into
   12851              :          a single byte, so DW_FORM_data1 is most compact (if there
   12852              :          are at most 128 directories, DW_FORM_udata would be as
   12853              :          compact as that, but not shorter and slower to decode).  */
   12854         1525 :       if (ndirs + idx_offset <= 256)
   12855              :         idx_form = DW_FORM_data1;
   12856              :       /* If there are more than 65536 directories, we have to use
   12857              :          DW_FORM_udata, DW_FORM_data2 can't refer to them.
   12858              :          Otherwise, compute what space would occupy if all the indexes
   12859              :          used DW_FORM_udata - sum - and compare that to how large would
   12860              :          be DW_FORM_data2 encoding, and pick the more efficient one.  */
   12861            0 :       else if (ndirs + idx_offset <= 65536)
   12862              :         {
   12863              :           unsigned HOST_WIDE_INT sum = 1;
   12864            0 :           for (i = 0; i < numfiles; i++)
   12865              :             {
   12866            0 :               int file_idx = backmap[i];
   12867            0 :               int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
   12868            0 :               sum += size_of_uleb128 (dir_idx);
   12869              :             }
   12870            0 :           if (sum >= HOST_WIDE_INT_UC (2) * (numfiles + 1))
   12871         1525 :             idx_form = DW_FORM_data2;
   12872              :         }
   12873              : #ifdef VMS_DEBUGGING_INFO
   12874              :       dw2_asm_output_data (1, 4, "File name entry format count");
   12875              : #else
   12876         1525 :       dw2_asm_output_data (1, 2, "File name entry format count");
   12877              : #endif
   12878         1525 :       dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
   12879         1525 :       dw2_asm_output_data_uleb128 (str_form, "%s",
   12880              :                                    get_DW_FORM_name (str_form));
   12881         1525 :       dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
   12882              :                                    "DW_LNCT_directory_index");
   12883         1525 :       dw2_asm_output_data_uleb128 (idx_form, "%s",
   12884              :                                    get_DW_FORM_name (idx_form));
   12885              : #ifdef VMS_DEBUGGING_INFO
   12886              :       dw2_asm_output_data_uleb128 (DW_LNCT_timestamp, "DW_LNCT_timestamp");
   12887              :       dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
   12888              :       dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
   12889              :       dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
   12890              : #endif
   12891         1525 :       dw2_asm_output_data_uleb128 (numfiles + 1, "File names count");
   12892              : 
   12893         1525 :       output_line_string (str_form, filename0, "File Entry", 0);
   12894              : 
   12895              :       /* Include directory index.  */
   12896         1525 :       if (idx_form != DW_FORM_udata)
   12897         1525 :         dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
   12898              :                              0, NULL);
   12899              :       else
   12900            0 :         dw2_asm_output_data_uleb128 (0, NULL);
   12901              : 
   12902              : #ifdef VMS_DEBUGGING_INFO
   12903              :       dw2_asm_output_data_uleb128 (0, NULL);
   12904              :       dw2_asm_output_data_uleb128 (0, NULL);
   12905              : #endif
   12906              :     }
   12907              : 
   12908              :   /* Now write all the file names.  */
   12909         6289 :   for (i = 0; i < numfiles; i++)
   12910              :     {
   12911         4713 :       int file_idx = backmap[i];
   12912         4713 :       int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
   12913              : 
   12914              : #ifdef VMS_DEBUGGING_INFO
   12915              : #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
   12916              : 
   12917              :       /* Setting these fields can lead to debugger miscomparisons,
   12918              :          but VMS Debug requires them to be set correctly.  */
   12919              : 
   12920              :       int ver;
   12921              :       long long cdt;
   12922              :       long siz;
   12923              :       int maxfilelen = (strlen (files[file_idx].path)
   12924              :                         + dirs[dir_idx].length
   12925              :                         + MAX_VMS_VERSION_LEN + 1);
   12926              :       char *filebuf = XALLOCAVEC (char, maxfilelen);
   12927              : 
   12928              :       vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
   12929              :       snprintf (filebuf, maxfilelen, "%s;%d",
   12930              :                 files[file_idx].path + dirs[dir_idx].length, ver);
   12931              : 
   12932              :       output_line_string (str_form, filebuf, "File Entry", (unsigned) i + 1);
   12933              : 
   12934              :       /* Include directory index.  */
   12935              :       if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
   12936              :         dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
   12937              :                              dir_idx + idx_offset, NULL);
   12938              :       else
   12939              :         dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
   12940              : 
   12941              :       /* Modification time.  */
   12942              :       dw2_asm_output_data_uleb128 ((vms_file_stats_name (files[file_idx].path,
   12943              :                                                          &cdt, 0, 0, 0) == 0)
   12944              :                                    ? cdt : 0, NULL);
   12945              : 
   12946              :       /* File length in bytes.  */
   12947              :       dw2_asm_output_data_uleb128 ((vms_file_stats_name (files[file_idx].path,
   12948              :                                                          0, &siz, 0, 0) == 0)
   12949              :                                    ? siz : 0, NULL);
   12950              : #else
   12951         4713 :       output_line_string (str_form,
   12952         4713 :                           files[file_idx].path + dirs[dir_idx].length,
   12953         4713 :                           "File Entry", (unsigned) i + 1);
   12954              : 
   12955              :       /* Include directory index.  */
   12956         4713 :       if (dwarf_version >= 5 && idx_form != DW_FORM_udata)
   12957         4646 :         dw2_asm_output_data (idx_form == DW_FORM_data1 ? 1 : 2,
   12958         4646 :                              dir_idx + idx_offset, NULL);
   12959              :       else
   12960           67 :         dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
   12961              : 
   12962         4713 :       if (dwarf_version >= 5)
   12963         4646 :         continue;
   12964              : 
   12965              :       /* Modification time.  */
   12966           67 :       dw2_asm_output_data_uleb128 (0, NULL);
   12967              : 
   12968              :       /* File length in bytes.  */
   12969           67 :       dw2_asm_output_data_uleb128 (0, NULL);
   12970              : #endif /* VMS_DEBUGGING_INFO */
   12971              :     }
   12972              : 
   12973         1576 :   if (dwarf_version < 5)
   12974           51 :     dw2_asm_output_data (1, 0, "End file name table");
   12975              : }
   12976              : 
   12977              : 
   12978              : /* Output one line number table into the .debug_line section.  */
   12979              : 
   12980              : static void
   12981           43 : output_one_line_info_table (dw_line_info_table *table)
   12982              : {
   12983           43 :   char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
   12984           43 :   unsigned int current_line = 1;
   12985           43 :   bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
   12986           43 :   dw_line_info_entry *ent, *prev_addr = NULL;
   12987           43 :   size_t i;
   12988           43 :   unsigned int view;
   12989              : 
   12990           43 :   view = 0;
   12991              : 
   12992         5995 :   FOR_EACH_VEC_SAFE_ELT (table->entries, i, ent)
   12993              :     {
   12994         5952 :       switch (ent->opcode)
   12995              :         {
   12996           90 :         case LI_set_address:
   12997              :           /* ??? Unfortunately, we have little choice here currently, and
   12998              :              must always use the most general form.  GCC does not know the
   12999              :              address delta itself, so we can't use DW_LNS_advance_pc.  Many
   13000              :              ports do have length attributes which will give an upper bound
   13001              :              on the address range.  We could perhaps use length attributes
   13002              :              to determine when it is safe to use DW_LNS_fixed_advance_pc.  */
   13003           90 :           ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
   13004              : 
   13005           90 :           view = 0;
   13006              : 
   13007              :           /* This can handle any delta.  This takes
   13008              :              4+DWARF2_ADDR_SIZE bytes.  */
   13009           90 :           dw2_asm_output_data (1, 0, "set address %s%s", line_label,
   13010           90 :                                debug_variable_location_views
   13011              :                                ? ", reset view to 0" : "");
   13012          105 :           dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
   13013           90 :           dw2_asm_output_data (1, DW_LNE_set_address, NULL);
   13014           90 :           dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
   13015              : 
   13016           90 :           prev_addr = ent;
   13017           90 :           break;
   13018              : 
   13019         1516 :         case LI_adv_address:
   13020         1516 :           {
   13021         1516 :             ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
   13022         1516 :             char prev_label[MAX_ARTIFICIAL_LABEL_BYTES];
   13023         1516 :             ASM_GENERATE_INTERNAL_LABEL (prev_label, LINE_CODE_LABEL, prev_addr->val);
   13024              : 
   13025         1516 :             view++;
   13026              : 
   13027         1516 :             if (HAVE_AS_LEB128)
   13028              :               {
   13029              :                 /* Using DW_LNS_advance_pc with label delta is only valid if
   13030              :                    Minimum Instruction Length in the header is 1, but that is
   13031              :                    what we use on all targets.  */
   13032         1516 :                 dw2_asm_output_data (1, DW_LNS_advance_pc,
   13033              :                                      "advance PC, increment view to %i", view);
   13034         1516 :                 dw2_asm_output_delta_uleb128 (line_label, prev_label,
   13035              :                                               "from %s to %s", prev_label,
   13036              :                                               line_label);
   13037              :               }
   13038              :             else
   13039              :               {
   13040              :                 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
   13041              :                                      "fixed advance PC, increment view to %i",
   13042              :                                      view);
   13043              :                 dw2_asm_output_delta (2, line_label, prev_label,
   13044              :                                       "from %s to %s", prev_label, line_label);
   13045              :               }
   13046              : 
   13047         1516 :             prev_addr = ent;
   13048         1516 :             break;
   13049              :           }
   13050              : 
   13051         1606 :         case LI_set_line:
   13052         1606 :           if (ent->val == current_line)
   13053              :             {
   13054              :               /* We still need to start a new row, so output a copy insn.  */
   13055          743 :               dw2_asm_output_data (1, DW_LNS_copy,
   13056              :                                    "copy line %u", current_line);
   13057              :             }
   13058              :           else
   13059              :             {
   13060          863 :               int line_offset = ent->val - current_line;
   13061          863 :               int line_delta = line_offset - DWARF_LINE_BASE;
   13062              : 
   13063          863 :               current_line = ent->val;
   13064          863 :               if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
   13065              :                 {
   13066              :                   /* This can handle deltas from -10 to 234, using the current
   13067              :                      definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
   13068              :                      This takes 1 byte.  */
   13069          425 :                   dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
   13070              :                                        "line %u", current_line);
   13071              :                 }
   13072              :               else
   13073              :                 {
   13074              :                   /* This can handle any delta.  This takes at least 4 bytes,
   13075              :                      depending on the value being encoded.  */
   13076          438 :                   dw2_asm_output_data (1, DW_LNS_advance_line,
   13077              :                                        "advance to line %u", current_line);
   13078          438 :                   dw2_asm_output_data_sleb128 (line_offset, NULL);
   13079          438 :                   dw2_asm_output_data (1, DW_LNS_copy, NULL);
   13080              :                 }
   13081              :             }
   13082              :           break;
   13083              : 
   13084          280 :         case LI_set_file:
   13085          280 :           dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
   13086          280 :           dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
   13087          280 :           break;
   13088              : 
   13089         1606 :         case LI_set_column:
   13090         1606 :           dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
   13091         1606 :           dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
   13092         1606 :           break;
   13093              : 
   13094          573 :         case LI_negate_stmt:
   13095          573 :           current_is_stmt = !current_is_stmt;
   13096          573 :           dw2_asm_output_data (1, DW_LNS_negate_stmt,
   13097              :                                "is_stmt %d", current_is_stmt);
   13098          573 :           break;
   13099              : 
   13100            0 :         case LI_set_prologue_end:
   13101            0 :           dw2_asm_output_data (1, DW_LNS_set_prologue_end,
   13102              :                                "set prologue end");
   13103            0 :           break;
   13104              : 
   13105            0 :         case LI_set_epilogue_begin:
   13106            0 :           dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
   13107              :                                "set epilogue begin");
   13108            0 :           break;
   13109              : 
   13110          281 :         case LI_set_discriminator:
   13111          281 :           dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
   13112          281 :           dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
   13113          281 :           dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
   13114          281 :           dw2_asm_output_data_uleb128 (ent->val, NULL);
   13115          281 :           break;
   13116              :         }
   13117              :     }
   13118              : 
   13119              :   /* Emit debug info for the address of the end of the table.  */
   13120           43 :   dw2_asm_output_data (1, 0, "set address %s", table->end_label);
   13121           58 :   dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
   13122           43 :   dw2_asm_output_data (1, DW_LNE_set_address, NULL);
   13123           58 :   dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
   13124              : 
   13125           43 :   dw2_asm_output_data (1, 0, "end sequence");
   13126           43 :   dw2_asm_output_data_uleb128 (1, NULL);
   13127           43 :   dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
   13128           43 : }
   13129              : 
   13130              : static unsigned int output_line_info_generation;
   13131              : 
   13132              : /* Output the source line number correspondence information.  This
   13133              :    information goes into the .debug_line section.  */
   13134              : 
   13135              : static void
   13136         1593 : output_line_info (bool prologue_only)
   13137              : {
   13138         1593 :   char l1[MAX_ARTIFICIAL_LABEL_BYTES], l2[MAX_ARTIFICIAL_LABEL_BYTES];
   13139         1593 :   char p1[MAX_ARTIFICIAL_LABEL_BYTES], p2[MAX_ARTIFICIAL_LABEL_BYTES];
   13140         1593 :   bool saw_one = false;
   13141         1593 :   int opc;
   13142              : 
   13143         1593 :   ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL,
   13144              :                                output_line_info_generation);
   13145         1593 :   ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL,
   13146              :                                output_line_info_generation);
   13147         1593 :   ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL,
   13148              :                                output_line_info_generation);
   13149         1593 :   ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL,
   13150              :                                output_line_info_generation++);
   13151              : 
   13152         1593 :   if (!XCOFF_DEBUGGING_INFO)
   13153              :     {
   13154         1593 :       if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   13155            0 :         dw2_asm_output_data (4, 0xffffffff,
   13156              :           "Initial length escape value indicating 64-bit DWARF extension");
   13157         1593 :       dw2_asm_output_delta (dwarf_offset_size, l2, l1,
   13158              :                             "Length of Source Line Info");
   13159              :     }
   13160              : 
   13161         1593 :   ASM_OUTPUT_LABEL (asm_out_file, l1);
   13162              : 
   13163         1593 :   output_dwarf_version ();
   13164         1593 :   if (dwarf_version >= 5)
   13165              :     {
   13166         1543 :       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
   13167         1542 :       dw2_asm_output_data (1, 0, "Segment Size");
   13168              :     }
   13169         1593 :   dw2_asm_output_delta (dwarf_offset_size, p2, p1, "Prolog Length");
   13170         1593 :   ASM_OUTPUT_LABEL (asm_out_file, p1);
   13171              : 
   13172              :   /* Define the architecture-dependent minimum instruction length (in bytes).
   13173              :      In this implementation of DWARF, this field is used for information
   13174              :      purposes only.  Since GCC generates assembly language, we have no
   13175              :      a priori knowledge of how many instruction bytes are generated for each
   13176              :      source line, and therefore can use only the DW_LNE_set_address and
   13177              :      DW_LNS_fixed_advance_pc line information commands.  Accordingly, we fix
   13178              :      this as '1', which is "correct enough" for all architectures,
   13179              :      and don't let the target override.  */
   13180         1593 :   dw2_asm_output_data (1, 1, "Minimum Instruction Length");
   13181              : 
   13182         1593 :   if (dwarf_version >= 4)
   13183         1543 :     dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
   13184              :                          "Maximum Operations Per Instruction");
   13185         1593 :   dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
   13186              :                        "Default is_stmt_start flag");
   13187         1593 :   dw2_asm_output_data (1, DWARF_LINE_BASE,
   13188              :                        "Line Base Value (Special Opcodes)");
   13189         1593 :   dw2_asm_output_data (1, DWARF_LINE_RANGE,
   13190              :                        "Line Range Value (Special Opcodes)");
   13191         1593 :   dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
   13192              :                        "Special Opcode Base");
   13193              : 
   13194        22302 :   for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
   13195              :     {
   13196        19116 :       int n_op_args;
   13197        19116 :       switch (opc)
   13198              :         {
   13199              :         case DW_LNS_advance_pc:
   13200              :         case DW_LNS_advance_line:
   13201              :         case DW_LNS_set_file:
   13202              :         case DW_LNS_set_column:
   13203              :         case DW_LNS_fixed_advance_pc:
   13204              :         case DW_LNS_set_isa:
   13205              :           n_op_args = 1;
   13206              :           break;
   13207         9558 :         default:
   13208         9558 :           n_op_args = 0;
   13209         9558 :           break;
   13210              :         }
   13211              : 
   13212        19116 :       dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
   13213              :                            opc, n_op_args);
   13214              :     }
   13215              : 
   13216              :   /* Write out the information about the files we use.  */
   13217         1593 :   output_file_names ();
   13218         1593 :   ASM_OUTPUT_LABEL (asm_out_file, p2);
   13219         1593 :   if (prologue_only)
   13220              :     {
   13221              :       /* Output the marker for the end of the line number info.  */
   13222         1587 :       ASM_OUTPUT_LABEL (asm_out_file, l2);
   13223         1587 :       return;
   13224              :     }
   13225              : 
   13226            6 :   if (separate_line_info)
   13227              :     {
   13228              :       dw_line_info_table *table;
   13229              :       size_t i;
   13230              : 
   13231           42 :       FOR_EACH_VEC_ELT (*separate_line_info, i, table)
   13232           37 :         if (table->in_use)
   13233              :           {
   13234           37 :             output_one_line_info_table (table);
   13235           37 :             saw_one = true;
   13236              :           }
   13237              :     }
   13238            6 :   if (cold_text_section_line_info && cold_text_section_line_info->in_use)
   13239              :     {
   13240            2 :       output_one_line_info_table (cold_text_section_line_info);
   13241            2 :       saw_one = true;
   13242              :     }
   13243              : 
   13244              :   /* ??? Some Darwin linkers crash on a .debug_line section with no
   13245              :      sequences.  Further, merely a DW_LNE_end_sequence entry is not
   13246              :      sufficient -- the address column must also be initialized.
   13247              :      Make sure to output at least one set_address/end_sequence pair,
   13248              :      choosing .text since that section is always present.  */
   13249            6 :   if (text_section_line_info->in_use || !saw_one)
   13250            4 :     output_one_line_info_table (text_section_line_info);
   13251              : 
   13252              :   /* Output the marker for the end of the line number info.  */
   13253            6 :   ASM_OUTPUT_LABEL (asm_out_file, l2);
   13254              : }
   13255              : 
   13256              : /* Return true if DW_AT_endianity should be emitted according to REVERSE.  */
   13257              : 
   13258              : static inline bool
   13259    503848885 : need_endianity_attribute_p (bool reverse)
   13260              : {
   13261          287 :   return reverse && (dwarf_version >= 3 || !dwarf_strict);
   13262              : }
   13263              : 
   13264              : /* Given a pointer to a tree node for some base type, return a pointer to
   13265              :    a DIE that describes the given type.  REVERSE is true if the type is
   13266              :    to be interpreted in the reverse storage order wrt the target order.
   13267              : 
   13268              :    This routine must only be called for GCC type nodes that correspond to
   13269              :    Dwarf base (fundamental) types.  */
   13270              : 
   13271              : dw_die_ref
   13272       614356 : base_type_die (tree type, bool reverse)
   13273              : {
   13274       614356 :   dw_die_ref base_type_result;
   13275       614356 :   enum dwarf_type encoding;
   13276       614356 :   bool fpt_used = false;
   13277       614356 :   struct fixed_point_type_info fpt_info;
   13278       614356 :   tree type_bias = NULL_TREE;
   13279              : 
   13280              :   /* If this is a subtype that should not be emitted as a subrange type,
   13281              :      use the base type.  See subrange_type_for_debug_p.  */
   13282       614356 :   if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
   13283            0 :     type = TREE_TYPE (type);
   13284              : 
   13285       614356 :   switch (TREE_CODE (type))
   13286              :     {
   13287       390852 :     case INTEGER_TYPE:
   13288         3372 :       if ((dwarf_version >= 4 || !dwarf_strict)
   13289       390852 :           && TYPE_NAME (type)
   13290       389524 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   13291       380529 :           && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type))
   13292       771381 :           && DECL_NAME (TYPE_NAME (type)))
   13293              :         {
   13294       380529 :           const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
   13295       380529 :           if (strcmp (name, "char16_t") == 0
   13296       368450 :               || strcmp (name, "char8_t") == 0
   13297       356784 :               || strcmp (name, "char32_t") == 0)
   13298              :             {
   13299              :               encoding = DW_ATE_UTF;
   13300              :               break;
   13301              :             }
   13302              :         }
   13303       355028 :       if ((dwarf_version >= 3 || !dwarf_strict)
   13304       355028 :           && lang_hooks.types.get_fixed_point_type_info)
   13305              :         {
   13306            0 :           memset (&fpt_info, 0, sizeof (fpt_info));
   13307            0 :           if (lang_hooks.types.get_fixed_point_type_info (type, &fpt_info))
   13308              :             {
   13309            0 :               fpt_used = true;
   13310            0 :               encoding = ((TYPE_UNSIGNED (type))
   13311            0 :                           ? DW_ATE_unsigned_fixed
   13312              :                           : DW_ATE_signed_fixed);
   13313              :               break;
   13314              :             }
   13315              :         }
   13316       355028 :       if (TYPE_STRING_FLAG (type))
   13317              :         {
   13318          583 :           if ((dwarf_version >= 4 || !dwarf_strict)
   13319        79863 :               && is_rust ()
   13320        79990 :               && int_size_in_bytes (type) == 4)
   13321              :             encoding = DW_ATE_UTF;
   13322        79852 :           else if (TYPE_UNSIGNED (type))
   13323              :             encoding = DW_ATE_unsigned_char;
   13324              :           else
   13325        49378 :             encoding = DW_ATE_signed_char;
   13326              :         }
   13327       275165 :       else if (TYPE_UNSIGNED (type))
   13328              :         encoding = DW_ATE_unsigned;
   13329              :       else
   13330       151553 :         encoding = DW_ATE_signed;
   13331              : 
   13332       355028 :       if (!dwarf_strict
   13333       355024 :           && lang_hooks.types.get_type_bias)
   13334            0 :         type_bias = lang_hooks.types.get_type_bias (type);
   13335              :       break;
   13336              : 
   13337       154960 :     case REAL_TYPE:
   13338       154960 :       if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
   13339              :         {
   13340          863 :           if (dwarf_version >= 3 || !dwarf_strict)
   13341              :             encoding = DW_ATE_decimal_float;
   13342              :           else
   13343           73 :             encoding = DW_ATE_lo_user;
   13344              :         }
   13345              :       else
   13346              :         encoding = DW_ATE_float;
   13347              :       break;
   13348              : 
   13349            0 :     case FIXED_POINT_TYPE:
   13350            0 :       if (!(dwarf_version >= 3 || !dwarf_strict))
   13351              :         encoding = DW_ATE_lo_user;
   13352            0 :       else if (TYPE_UNSIGNED (type))
   13353              :         encoding = DW_ATE_unsigned_fixed;
   13354              :       else
   13355            0 :         encoding = DW_ATE_signed_fixed;
   13356              :       break;
   13357              : 
   13358              :       /* Dwarf2 doesn't know anything about complex ints, so use
   13359              :          a user defined type for it.  */
   13360        47901 :     case COMPLEX_TYPE:
   13361        47901 :       if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type)))
   13362              :         encoding = DW_ATE_complex_float;
   13363              :       else
   13364           73 :         encoding = DW_ATE_lo_user;
   13365              :       break;
   13366              : 
   13367              :     case BOOLEAN_TYPE:
   13368              :       /* GNU FORTRAN/Ada/C++ BOOLEAN type.  */
   13369              :       encoding = DW_ATE_boolean;
   13370              :       break;
   13371              : 
   13372           94 :     case BITINT_TYPE:
   13373              :       /* C23 _BitInt(N).  */
   13374           94 :       if (TYPE_UNSIGNED (type))
   13375              :         encoding = DW_ATE_unsigned;
   13376              :       else
   13377           62 :         encoding = DW_ATE_signed;
   13378              :       break;
   13379              : 
   13380            0 :     default:
   13381              :       /* No other TREE_CODEs are Dwarf fundamental types.  */
   13382            0 :       gcc_unreachable ();
   13383              :     }
   13384              : 
   13385       614356 :   base_type_result = new_die_raw (DW_TAG_base_type);
   13386              : 
   13387       614356 :   add_AT_unsigned (base_type_result, DW_AT_byte_size,
   13388       614356 :                    int_size_in_bytes (type));
   13389       614356 :   add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
   13390       614356 :   if (TREE_CODE (type) == BITINT_TYPE)
   13391           94 :     add_AT_unsigned (base_type_result, DW_AT_bit_size, TYPE_PRECISION (type));
   13392              : 
   13393       614356 :   if (need_endianity_attribute_p (reverse))
   13394           62 :     add_AT_unsigned (base_type_result, DW_AT_endianity,
   13395              :                      BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
   13396              : 
   13397       614356 :   add_alignment_attribute (base_type_result, type);
   13398              : 
   13399       614356 :   if (fpt_used)
   13400              :     {
   13401            0 :       switch (fpt_info.scale_factor_kind)
   13402              :         {
   13403            0 :         case fixed_point_scale_factor_binary:
   13404            0 :           add_AT_int (base_type_result, DW_AT_binary_scale,
   13405            0 :                       fpt_info.scale_factor.binary);
   13406            0 :           break;
   13407              : 
   13408            0 :         case fixed_point_scale_factor_decimal:
   13409            0 :           add_AT_int (base_type_result, DW_AT_decimal_scale,
   13410            0 :                       fpt_info.scale_factor.decimal);
   13411            0 :           break;
   13412              : 
   13413            0 :         case fixed_point_scale_factor_arbitrary:
   13414              :           /* Arbitrary scale factors cannot be described in standard DWARF.  */
   13415            0 :           if (!dwarf_strict)
   13416              :             {
   13417              :               /* Describe the scale factor as a rational constant.  */
   13418            0 :               const dw_die_ref scale_factor
   13419            0 :                 = new_die (DW_TAG_constant, comp_unit_die (), type);
   13420              : 
   13421            0 :               add_scalar_info (scale_factor, DW_AT_GNU_numerator,
   13422              :                                fpt_info.scale_factor.arbitrary.numerator,
   13423              :                                dw_scalar_form_constant, NULL);
   13424            0 :               add_scalar_info (scale_factor, DW_AT_GNU_denominator,
   13425              :                                fpt_info.scale_factor.arbitrary.denominator,
   13426              :                                dw_scalar_form_constant, NULL);
   13427              : 
   13428            0 :               add_AT_die_ref (base_type_result, DW_AT_small, scale_factor);
   13429              :             }
   13430              :           break;
   13431              : 
   13432            0 :         default:
   13433            0 :           gcc_unreachable ();
   13434              :         }
   13435              :     }
   13436              : 
   13437       614356 :   if (type_bias)
   13438            0 :     add_scalar_info (base_type_result, DW_AT_GNU_bias, type_bias,
   13439              :                      dw_scalar_form_constant
   13440              :                      | dw_scalar_form_exprloc
   13441              :                      | dw_scalar_form_reference,
   13442              :                      NULL);
   13443              : 
   13444       614356 :   return base_type_result;
   13445              : }
   13446              : 
   13447              : /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
   13448              :    named 'auto' in its type: return true for it, false otherwise.  */
   13449              : 
   13450              : static inline bool
   13451       116252 : is_cxx_auto (tree type)
   13452              : {
   13453       116252 :   if (is_cxx ())
   13454              :     {
   13455       116252 :       tree name = TYPE_IDENTIFIER (type);
   13456       116252 :       if (name == get_identifier ("auto")
   13457       116252 :           || name == get_identifier ("decltype(auto)"))
   13458       116252 :         return true;
   13459              :     }
   13460              :   return false;
   13461              : }
   13462              : 
   13463              : /* Given a pointer to an arbitrary ..._TYPE tree node, return true if the
   13464              :    given input type is a Dwarf "fundamental" type.  Otherwise return null.  */
   13465              : 
   13466              : static inline bool
   13467      5462718 : is_base_type (tree type)
   13468              : {
   13469      5462718 :   switch (TREE_CODE (type))
   13470              :     {
   13471              :     case INTEGER_TYPE:
   13472              :     case REAL_TYPE:
   13473              :     case FIXED_POINT_TYPE:
   13474              :     case COMPLEX_TYPE:
   13475              :     case BOOLEAN_TYPE:
   13476              :     case BITINT_TYPE:
   13477              :       return true;
   13478              : 
   13479              :     case VOID_TYPE:
   13480              :     case OPAQUE_TYPE:
   13481              :     case ARRAY_TYPE:
   13482              :     case RECORD_TYPE:
   13483              :     case UNION_TYPE:
   13484              :     case QUAL_UNION_TYPE:
   13485              :     case ENUMERAL_TYPE:
   13486              :     case FUNCTION_TYPE:
   13487              :     case METHOD_TYPE:
   13488              :     case POINTER_TYPE:
   13489              :     case REFERENCE_TYPE:
   13490              :     case NULLPTR_TYPE:
   13491              :     case OFFSET_TYPE:
   13492              :     case LANG_TYPE:
   13493              :     case VECTOR_TYPE:
   13494              :       return false;
   13495              : 
   13496            3 :     default:
   13497            3 :       if (is_cxx ()
   13498            3 :           && TREE_CODE (type) >= LAST_AND_UNUSED_TREE_CODE
   13499            3 :           && TYPE_P (type)
   13500            6 :           && TYPE_IDENTIFIER (type))
   13501              :         return false;
   13502            0 :       gcc_unreachable ();
   13503              :     }
   13504              : }
   13505              : 
   13506              : /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
   13507              :    node, return the size in bits for the type if it is a constant, or else
   13508              :    return the alignment for the type if the type's size is not constant, or
   13509              :    else return BITS_PER_WORD if the type actually turns out to be an
   13510              :    ERROR_MARK node.  */
   13511              : 
   13512              : static inline unsigned HOST_WIDE_INT
   13513     46168975 : simple_type_size_in_bits (const_tree type)
   13514              : {
   13515     46168975 :   if (TREE_CODE (type) == ERROR_MARK)
   13516            0 :     return BITS_PER_WORD;
   13517     46168975 :   else if (TYPE_SIZE (type) == NULL_TREE)
   13518              :     return 0;
   13519     46168975 :   else if (tree_fits_uhwi_p (TYPE_SIZE (type)))
   13520     46168975 :     return tree_to_uhwi (TYPE_SIZE (type));
   13521              :   else
   13522            0 :     return TYPE_ALIGN (type);
   13523              : }
   13524              : 
   13525              : /* Similarly, but return an offset_int instead of UHWI.  */
   13526              : 
   13527              : static inline offset_int
   13528      1027398 : offset_int_type_size_in_bits (const_tree type)
   13529              : {
   13530      1027398 :   if (TREE_CODE (type) == ERROR_MARK)
   13531            0 :     return BITS_PER_WORD;
   13532      1027398 :   else if (TYPE_SIZE (type) == NULL_TREE)
   13533            0 :     return 0;
   13534      1027398 :   else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
   13535      1027398 :     return wi::to_offset (TYPE_SIZE (type));
   13536              :   else
   13537            0 :     return TYPE_ALIGN (type);
   13538              : }
   13539              : 
   13540              : /*  Given a pointer to a tree node for a subrange type, return a pointer
   13541              :     to a DIE that describes the given type.  */
   13542              : 
   13543              : static dw_die_ref
   13544           18 : subrange_type_die (tree type, tree low, tree high, tree bias,
   13545              :                    dw_die_ref context_die)
   13546              : {
   13547           18 :   dw_die_ref subrange_die;
   13548           18 :   const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
   13549              : 
   13550           18 :   if (context_die == NULL)
   13551            0 :     context_die = comp_unit_die ();
   13552              : 
   13553           18 :   subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
   13554              : 
   13555           18 :   if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
   13556              :     {
   13557              :       /* The size of the subrange type and its base type do not match,
   13558              :          so we need to generate a size attribute for the subrange type.  */
   13559            0 :       add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
   13560              :     }
   13561              : 
   13562           18 :   add_alignment_attribute (subrange_die, type);
   13563              : 
   13564           18 :   if (low)
   13565           18 :     add_bound_info (subrange_die, DW_AT_lower_bound, low, NULL);
   13566           18 :   if (high)
   13567           18 :     add_bound_info (subrange_die, DW_AT_upper_bound, high, NULL);
   13568           18 :   if (bias && !dwarf_strict)
   13569            0 :     add_scalar_info (subrange_die, DW_AT_GNU_bias, bias,
   13570              :                      dw_scalar_form_constant
   13571              :                      | dw_scalar_form_exprloc
   13572              :                      | dw_scalar_form_reference,
   13573              :                      NULL);
   13574              : 
   13575           18 :   return subrange_die;
   13576              : }
   13577              : 
   13578              : /* Returns the (const and/or volatile) cv_qualifiers associated with
   13579              :    the decl node.  This will normally be augmented with the
   13580              :    cv_qualifiers of the underlying type in add_type_attribute.  */
   13581              : 
   13582              : static int
   13583    127483494 : decl_quals (const_tree decl)
   13584              : {
   13585    127483494 :   return ((TREE_READONLY (decl)
   13586              :            /* The C++ front-end correctly marks reference-typed
   13587              :               variables as readonly, but from a language (and debug
   13588              :               info) standpoint they are not const-qualified.  */
   13589     56031646 :            && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
   13590    127483494 :            ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
   13591    127483494 :           | (TREE_THIS_VOLATILE (decl)
   13592    127483494 :              ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
   13593              : }
   13594              : 
   13595              : /* Determine the TYPE whose qualifiers match the largest strict subset
   13596              :    of the given TYPE_QUALS, and return its qualifiers.  Ignore all
   13597              :    qualifiers outside QUAL_MASK.  */
   13598              : 
   13599              : static int
   13600     13389361 : get_nearest_type_subqualifiers (tree type, int type_quals, int qual_mask)
   13601              : {
   13602     13389361 :   tree t;
   13603     13389361 :   int best_rank = 0, best_qual = 0, max_rank;
   13604              : 
   13605     13389361 :   type_quals &= qual_mask;
   13606     13389361 :   max_rank = popcount_hwi (type_quals) - 1;
   13607              : 
   13608     14185091 :   for (t = TYPE_MAIN_VARIANT (type); t && best_rank < max_rank;
   13609       795730 :        t = TYPE_NEXT_VARIANT (t))
   13610              :     {
   13611       795730 :       int q = TYPE_QUALS (t) & qual_mask;
   13612              : 
   13613       795693 :       if ((q & type_quals) == q && q != type_quals
   13614      1531089 :           && check_base_type (t, type))
   13615              :         {
   13616       511174 :           int rank = popcount_hwi (q);
   13617              : 
   13618       511174 :           if (rank > best_rank)
   13619              :             {
   13620       795730 :               best_rank = rank;
   13621       795730 :               best_qual = q;
   13622              :             }
   13623              :         }
   13624              :     }
   13625              : 
   13626     13389361 :   return best_qual;
   13627              : }
   13628              : 
   13629              : struct dwarf_qual_info_t { int q; enum dwarf_tag t; };
   13630              : static const dwarf_qual_info_t dwarf_qual_info[] =
   13631              : {
   13632              :   { TYPE_QUAL_CONST, DW_TAG_const_type },
   13633              :   { TYPE_QUAL_VOLATILE, DW_TAG_volatile_type },
   13634              :   { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
   13635              :   { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
   13636              : };
   13637              : static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
   13638              : 
   13639              : /* If DIE is a qualified DIE of some base DIE with the same parent,
   13640              :    return the base DIE, otherwise return NULL.  Set MASK to the
   13641              :    qualifiers added compared to the returned DIE.  */
   13642              : 
   13643              : static dw_die_ref
   13644     22986855 : qualified_die_p (dw_die_ref die, int *mask, unsigned int depth)
   13645              : {
   13646     22986855 :   unsigned int i;
   13647    106430343 :   for (i = 0; i < dwarf_qual_info_size; i++)
   13648     85800245 :     if (die->die_tag == dwarf_qual_info[i].t)
   13649              :       break;
   13650     22986855 :   if (i == dwarf_qual_info_size)
   13651              :     return NULL;
   13652      2356757 :   if (vec_safe_length (die->die_attr) != 1)
   13653              :     return NULL;
   13654      2345139 :   dw_die_ref type = get_AT_ref (die, DW_AT_type);
   13655      2345139 :   if (type == NULL || type->die_parent != die->die_parent)
   13656              :     return NULL;
   13657      2340546 :   *mask |= dwarf_qual_info[i].q;
   13658      2340546 :   if (depth)
   13659              :     {
   13660      2340546 :       dw_die_ref ret = qualified_die_p (type, mask, depth - 1);
   13661      2340546 :       if (ret)
   13662        37930 :         return ret;
   13663              :     }
   13664              :   return type;
   13665              : }
   13666              : 
   13667              : /* If TYPE is long double or complex long double that
   13668              :    should be emitted as artificial typedef to _Float128 or
   13669              :    complex _Float128, return the type it should be emitted as.
   13670              :    This is done in case the target already supports 16-byte
   13671              :    composite floating point type (ibm_extended_format).  */
   13672              : 
   13673              : static tree
   13674       614063 : long_double_as_float128 (tree type)
   13675              : {
   13676       614063 :   if (type != long_double_type_node
   13677       594029 :       && type != complex_long_double_type_node)
   13678              :     return NULL_TREE;
   13679              : 
   13680        32879 :   machine_mode mode, fmode;
   13681        32879 :   if (TREE_CODE (type) == COMPLEX_TYPE)
   13682        12845 :     mode = TYPE_MODE (TREE_TYPE (type));
   13683              :   else
   13684        20034 :     mode = TYPE_MODE (type);
   13685       233704 :   if (known_eq (GET_MODE_SIZE (mode), 16) && !MODE_COMPOSITE_P (mode))
   13686       195937 :     FOR_EACH_MODE_IN_CLASS (fmode, MODE_FLOAT)
   13687       167946 :       if (known_eq (GET_MODE_SIZE (fmode), 16)
   13688       503838 :           && MODE_COMPOSITE_P (fmode))
   13689              :         {
   13690            0 :           if (type == long_double_type_node)
   13691              :             {
   13692            0 :               if (float128_type_node
   13693            0 :                   && (TYPE_MODE (float128_type_node)
   13694            0 :                       == TYPE_MODE (type)))
   13695            0 :                 return float128_type_node;
   13696              :               return NULL_TREE;
   13697              :             }
   13698            0 :           for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
   13699            0 :             if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
   13700            0 :                 && (TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i))
   13701            0 :                     == TYPE_MODE (type)))
   13702            0 :               return COMPLEX_FLOATN_NX_TYPE_NODE (i);
   13703              :         }
   13704              : 
   13705              :   return NULL_TREE;
   13706              : }
   13707              : 
   13708              : /* Hash function for struct annotation_node.  The hash value is computed when
   13709              :    the annotation node is created based on the name, value and chain of any
   13710              :    further annotations on the same entity.  */
   13711              : 
   13712              : hashval_t
   13713          487 : annotation_node_hasher::hash (struct annotation_node *node)
   13714              : {
   13715          487 :   return node->hash;
   13716              : }
   13717              : 
   13718              : /* Return whether two annotation nodes represent the same annotation and
   13719              :    can therefore share a DIE.  Beware of hash value collisions.  */
   13720              : 
   13721              : bool
   13722          348 : annotation_node_hasher::equal (const struct annotation_node *node1,
   13723              :                                const struct annotation_node *node2)
   13724              : {
   13725          348 :   return (node1->hash == node2->hash
   13726           97 :           && (node1->name == node2->name
   13727            0 :               || !strcmp (node1->name, node2->name))
   13728           97 :           && (node1->value == node2->value
   13729           41 :               || !strcmp (node1->value, node2->value))
   13730          445 :           && node1->next == node2->next);
   13731              : }
   13732              : 
   13733              : /* Return an appropriate entry in the btf tag hash table for a given btf tag.
   13734              :    If a structurally equivalent tag (one with the same name, value, and
   13735              :    subsequent chain of further tags) has already been processed, then the
   13736              :    existing entry for that tag is returned and should be reused.
   13737              :    Otherwise, a new entry is added to the hash table and returned.  */
   13738              : 
   13739              : static struct annotation_node *
   13740          299 : hash_btf_tag (tree attr)
   13741              : {
   13742          299 :   if (attr == NULL_TREE || TREE_CODE (attr) != TREE_LIST)
   13743              :     return NULL;
   13744              : 
   13745          168 :   if (!btf_tag_htab)
   13746           27 :     btf_tag_htab = hash_table<annotation_node_hasher>::create_ggc (10);
   13747              : 
   13748          168 :   const char * name = IDENTIFIER_POINTER (get_attribute_name (attr));
   13749          168 :   const char * value = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
   13750          168 :   tree chain = lookup_attribute (name, TREE_CHAIN (attr));
   13751              : 
   13752              :   /* Hash for one tag depends on hash of next tag in the chain, because
   13753              :      the chain is part of structural equivalence.  */
   13754          168 :   struct annotation_node *chain_node = hash_btf_tag (chain);
   13755          168 :   gcc_checking_assert (chain == NULL_TREE || chain_node != NULL);
   13756              : 
   13757              :   /* Skip any non-btf-tag attributes that might be in the chain.  */
   13758          168 :   if (strcmp (name, "btf_type_tag") != 0 && strcmp (name, "btf_decl_tag") != 0)
   13759              :     return chain_node;
   13760              : 
   13761              :   /* Hash for a given tag is determined by the name, value, and chain of
   13762              :      further tags.  */
   13763          168 :   inchash::hash h;
   13764          168 :   h.merge_hash (htab_hash_string (name));
   13765          168 :   h.merge_hash (htab_hash_string (value));
   13766          168 :   h.merge_hash (chain_node ? chain_node->hash : 0);
   13767              : 
   13768          168 :   struct annotation_node node;
   13769          168 :   node.name = name;
   13770          168 :   node.value = value;
   13771          168 :   node.hash = h.end ();
   13772          168 :   node.next = chain_node;
   13773              : 
   13774          168 :   struct annotation_node **slot = btf_tag_htab->find_slot (&node, INSERT);
   13775          168 :   if (*slot == NULL)
   13776              :     {
   13777              :       /* Create new htab entry for this annotation.  */
   13778           71 :       struct annotation_node *new_slot
   13779           71 :         = ggc_cleared_alloc<struct annotation_node> ();
   13780           71 :       new_slot->name = name;
   13781           71 :       new_slot->value = value;
   13782           71 :       new_slot->hash = node.hash;
   13783           71 :       new_slot->next = chain_node;
   13784              : 
   13785           71 :       *slot = new_slot;
   13786           71 :       return new_slot;
   13787              :     }
   13788              :   else
   13789              :     {
   13790              :       /* This node is already in the hash table.  */
   13791              :       return *slot;
   13792              :     }
   13793              : }
   13794              : 
   13795              : /* Generate (or reuse) DW_TAG_GNU_annotation DIEs representing the btf_type_tag
   13796              :    or btf_decl_tag user annotations in ATTR, and update DIE to refer to them
   13797              :    via DW_AT_GNU_annotation.  If there are multiple type_tag or decl_tag
   13798              :    annotations in ATTR, they are all processed recursively by this function to
   13799              :    build a chain of annotation DIEs.
   13800              :    A single chain of annotation DIEs can be shared among all occurrences of
   13801              :    equivalent sets of attributes appearing on different types or declarations.
   13802              :    Return the first annotation DIE in the created (or reused) chain.  */
   13803              : 
   13804              : static dw_die_ref
   13805          131 : gen_btf_tag_dies (tree attr, dw_die_ref die)
   13806              : {
   13807          131 :   if (attr == NULL_TREE)
   13808              :     return die;
   13809              : 
   13810          131 :   const char * name = IDENTIFIER_POINTER (get_attribute_name (attr));
   13811          131 :   const char * value = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
   13812              : 
   13813          131 :   dw_die_ref tag_die, prev = NULL;
   13814              : 
   13815              :   /* Multiple annotations on the same item form a singly-linked list of
   13816              :      annotation DIEs; generate recursively backward from the end so we can
   13817              :      chain each created DIE to the next, which has already been created.  */
   13818          131 :   tree rest = lookup_attribute (name, TREE_CHAIN (attr));
   13819          131 :   if (rest)
   13820           33 :     prev = gen_btf_tag_dies (rest, NULL);
   13821              : 
   13822              :   /* Calculate a hash value for the tag based on its structure, find the
   13823              :      existing entry for it (if any) in the hash table, or create a new entry
   13824              :      which can be reused by structurally-equivalent tags.  */
   13825          131 :   struct annotation_node *entry = hash_btf_tag (attr);
   13826          131 :   if (!entry)
   13827              :     return die;
   13828              : 
   13829              :   /* If the node already has an associated DIE, reuse it.
   13830              :      Otherwise, create the new annotation DIE, and associate it with
   13831              :      the hash table entry for future reuse.  Any structurally-equivalent
   13832              :      tag we process later will find and share the same DIE.  */
   13833          131 :   if (entry->die)
   13834              :     tag_die = entry->die;
   13835              :   else
   13836              :     {
   13837           71 :       tag_die = new_die (DW_TAG_GNU_annotation, comp_unit_die (), NULL);
   13838           71 :       add_name_attribute (tag_die, name);
   13839           71 :       add_AT_string (tag_die, DW_AT_const_value, value);
   13840           71 :       if (prev)
   13841           21 :         add_AT_die_ref (tag_die, DW_AT_GNU_annotation, prev);
   13842              : 
   13843           71 :       entry->die = tag_die;
   13844              :     }
   13845              : 
   13846          131 :   if (die)
   13847              :     {
   13848              :       /* Add (or replace) AT_GNU_annotation referring to the annotation DIE.
   13849              :          Replacement may happen for example when 'die' is a global variable
   13850              :          which has been re-declared multiple times.  In any case, the set of
   13851              :          input attributes is the one that ought to be reflected.  For global
   13852              :          variable re-declarations which add additional decl tags, they will
   13853              :          have been accumulated in the variable's DECL_ATTRIBUTES for us.  */
   13854           98 :       remove_AT (die, DW_AT_GNU_annotation);
   13855           98 :       add_AT_die_ref (die, DW_AT_GNU_annotation, tag_die);
   13856              :     }
   13857              : 
   13858              :   return tag_die;
   13859              : }
   13860              : 
   13861              : /* Generate (or reuse) annotation DIEs representing the type_tags on T, if
   13862              :    any, and update DIE to refer to them as appropriate.  */
   13863              : 
   13864              : static void
   13865    133573788 : maybe_gen_btf_type_tag_dies (tree t, dw_die_ref target)
   13866              : {
   13867    133573788 :   if (t == NULL_TREE || !TYPE_P (t) || !target)
   13868              :     return;
   13869              : 
   13870    133573788 :   tree attr = lookup_attribute ("btf_type_tag", TYPE_ATTRIBUTES (t));
   13871    133573788 :   if (attr == NULL_TREE)
   13872              :     return;
   13873              : 
   13874            5 :   gen_btf_tag_dies (attr, target);
   13875              : }
   13876              : 
   13877              : /* Generate (or reuse) annotation DIEs representing any decl_tags in ATTR that
   13878              :    apply to TARGET.  */
   13879              : 
   13880              : static void
   13881    549286739 : maybe_gen_btf_decl_tag_dies (tree t, dw_die_ref target)
   13882              : {
   13883    549286739 :   if (t == NULL_TREE || !DECL_P (t) || !target)
   13884              :     return;
   13885              : 
   13886    207108804 :   tree attr = lookup_attribute ("btf_decl_tag", DECL_ATTRIBUTES (t));
   13887    207108804 :   if (attr == NULL_TREE)
   13888              :     return;
   13889              : 
   13890           61 :   gen_btf_tag_dies (attr, target);
   13891              : }
   13892              : 
   13893              : /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
   13894              :    entry that chains the modifiers specified by CV_QUALS in front of the
   13895              :    given type.  Also handle any type attributes in TYPE_ATTRS which have
   13896              :    a representation in DWARF.  REVERSE is true if the type is to be interpreted
   13897              :    in the reverse storage order wrt the target order.  */
   13898              : 
   13899              : static dw_die_ref
   13900    502997454 : modified_type_die (tree type, int cv_quals, tree type_attrs, bool reverse,
   13901              :                    dw_die_ref context_die)
   13902              : {
   13903    503234529 :   enum tree_code code = TREE_CODE (type);
   13904    503234529 :   dw_die_ref mod_type_die;
   13905    503234529 :   dw_die_ref sub_die = NULL;
   13906    503234529 :   tree item_type = NULL;
   13907    503234529 :   tree qualified_type;
   13908    503234529 :   tree name, low, high;
   13909    503234529 :   tree btf_tags;
   13910    503234529 :   dw_die_ref mod_scope;
   13911    503234529 :   struct array_descr_info info;
   13912              :   /* Only these cv-qualifiers are currently handled.  */
   13913    503234529 :   const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE
   13914              :                             | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC);
   13915              :   /* DW_AT_endianity is specified only for base types in the standard.  */
   13916    503234529 :   const bool reverse_type
   13917    503234754 :     = need_endianity_attribute_p (reverse)
   13918          225 :       && (is_base_type (type)
   13919           50 :           || (TREE_CODE (type) == ENUMERAL_TYPE && !dwarf_strict));
   13920              : 
   13921    503234529 :   if (code == ERROR_MARK)
   13922              :     return NULL;
   13923              : 
   13924    503234529 :   if (lang_hooks.types.get_debug_type)
   13925              :     {
   13926    494457848 :       tree debug_type = lang_hooks.types.get_debug_type (type);
   13927              : 
   13928    494457848 :       if (debug_type != NULL_TREE && debug_type != type)
   13929              :         return modified_type_die (debug_type, cv_quals, type_attrs, reverse,
   13930              :                                   context_die);
   13931              :     }
   13932              : 
   13933    502997540 :   cv_quals &= cv_qual_mask;
   13934              : 
   13935              :   /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
   13936              :      tag modifier (and not an attribute) old consumers won't be able
   13937              :      to handle it.  */
   13938    502997540 :   if (dwarf_version < 3)
   13939        55035 :     cv_quals &= ~TYPE_QUAL_RESTRICT;
   13940              : 
   13941              :   /* Likewise for DW_TAG_atomic_type for DWARFv5.  */
   13942    502997540 :   if (dwarf_version < 5)
   13943        56868 :     cv_quals &= ~TYPE_QUAL_ATOMIC;
   13944              : 
   13945              :   /* See if we already have the appropriately qualified variant of
   13946              :      this type.  */
   13947    502997540 :   qualified_type = get_qualified_type (type, cv_quals);
   13948              : 
   13949    502997540 :   if (qualified_type == sizetype)
   13950              :     {
   13951              :       /* Try not to expose the internal sizetype type's name.  */
   13952       932389 :       if (TYPE_NAME (qualified_type)
   13953       932389 :           && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
   13954              :         {
   13955            0 :           tree t = TREE_TYPE (TYPE_NAME (qualified_type));
   13956              : 
   13957            0 :           gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
   13958              :                                && (TYPE_PRECISION (t)
   13959              :                                    == TYPE_PRECISION (qualified_type))
   13960              :                                && (TYPE_UNSIGNED (t)
   13961              :                                    == TYPE_UNSIGNED (qualified_type)));
   13962              :           qualified_type = t;
   13963              :         }
   13964       932389 :       else if (qualified_type == sizetype
   13965       932389 :                && TREE_CODE (sizetype) == TREE_CODE (size_type_node)
   13966       932389 :                && TYPE_PRECISION (sizetype) == TYPE_PRECISION (size_type_node)
   13967       932389 :                && TYPE_UNSIGNED (sizetype) == TYPE_UNSIGNED (size_type_node))
   13968              :         qualified_type = size_type_node;
   13969       932389 :       if (type == sizetype)
   13970       932389 :         type = qualified_type;
   13971              :     }
   13972              : 
   13973              :   /* If we do, then we can just use its DIE, if it exists.  */
   13974    502997540 :   if (qualified_type)
   13975              :     {
   13976    502769371 :       mod_type_die = lookup_type_die (qualified_type);
   13977              : 
   13978              :       /* DW_AT_endianity doesn't come from a qualifier on the type, so it is
   13979              :          dealt with specially: the DIE with the attribute, if it exists, is
   13980              :          placed immediately after the regular DIE for the same type.  */
   13981    502769371 :       if (mod_type_die
   13982    502769371 :           && (!reverse_type
   13983          164 :               || ((mod_type_die = mod_type_die->die_sib) != NULL
   13984          164 :                   && get_AT_unsigned (mod_type_die, DW_AT_endianity))))
   13985              :         return mod_type_die;
   13986              :     }
   13987              : 
   13988     56119186 :   name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
   13989              : 
   13990              :   /* Handle C typedef types.  */
   13991     56119186 :   if (name
   13992     24688749 :       && TREE_CODE (name) == TYPE_DECL
   13993     24636648 :       && DECL_ORIGINAL_TYPE (name)
   13994     66232073 :       && !DECL_ARTIFICIAL (name))
   13995              :     {
   13996     10099308 :       tree dtype = TREE_TYPE (name);
   13997              : 
   13998              :       /* Skip the typedef for base types with DW_AT_endianity, no big deal.  */
   13999     10099308 :       if (!reverse_type
   14000     10099308 :           && (qualified_type == dtype
   14001              :               /* Pointer identity check above might fail when qualified_type
   14002              :                  is a different variant node of the same typedef yet requires
   14003              :                  the same handling as if they matched (see PR/125421).
   14004              :                  Skip this when btf_type_tag attributes are present, as those
   14005              :                  need to be handled in the else branch below.  */
   14006      2975836 :               || (TYPE_NAME (qualified_type) == name
   14007      2975836 :                   && TYPE_QUALS (qualified_type) == TYPE_QUALS (dtype)
   14008        13801 :                   && !lookup_attribute ("btf_type_tag", type_attrs))))
   14009              :         {
   14010      7137266 :           tree origin = decl_ultimate_origin (name);
   14011              : 
   14012              :           /* Typedef variants that have an abstract origin don't get their own
   14013              :              type DIE (see gen_typedef_die), so fall back on the ultimate
   14014              :              abstract origin instead.  */
   14015      7137266 :           if (origin != NULL && origin != name)
   14016            1 :             return modified_type_die (TREE_TYPE (origin), cv_quals, type_attrs,
   14017            1 :                                       reverse, context_die);
   14018              : 
   14019              :           /* For a named type, use the typedef.  */
   14020      7137265 :           gen_type_die (dtype, context_die);
   14021      7137265 :           return lookup_type_die (dtype);
   14022              :         }
   14023              :       else
   14024              :         {
   14025      2962042 :           int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
   14026      2962042 :           dquals &= cv_qual_mask;
   14027      2962042 :           if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
   14028      2962049 :               || (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
   14029              :             {
   14030           88 :               tree tags = lookup_attribute ("btf_type_tag", type_attrs);
   14031           88 :               tree dtags = lookup_attribute ("btf_type_tag",
   14032           88 :                                              TYPE_ATTRIBUTES (dtype));
   14033           88 :               if (tags && !attribute_list_equal (tags, dtags))
   14034              :                 {
   14035              :                   /* Use of a typedef with additional btf_type_tags.
   14036              :                      Create a new typedef DIE to which we can attach the
   14037              :                      additional type_tag DIEs without disturbing other users of
   14038              :                      the underlying typedef.  */
   14039            3 :                   dw_die_ref mod_die
   14040            3 :                     = modified_type_die (dtype, cv_quals, NULL_TREE, reverse,
   14041              :                                          context_die);
   14042              : 
   14043            3 :                   mod_die = clone_die (mod_die);
   14044            3 :                   add_child_die (comp_unit_die (), mod_die);
   14045            3 :                   if (!lookup_type_die (type))
   14046            3 :                     equate_type_number_to_die (type, mod_die);
   14047              : 
   14048              :                   /* Now generate the type_tag DIEs only for the new
   14049              :                      type_tags appearing in the use of the typedef, and
   14050              :                      attach them to the cloned typedef DIE.  */
   14051            3 :                   gen_btf_tag_dies (tags, mod_die);
   14052            3 :                   return mod_die;
   14053              :                 }
   14054              :               /* cv-unqualified version of named type.  Just use
   14055              :                  the unnamed type to which it refers.  */
   14056           85 :               return modified_type_die (DECL_ORIGINAL_TYPE (name), cv_quals,
   14057           85 :                                         type_attrs, reverse, context_die);
   14058              :             }
   14059              :           /* Else cv-qualified version of named type; fall through.  */
   14060              :         }
   14061              :     }
   14062              : 
   14063     49210001 :   mod_scope = scope_die_for (type, context_die);
   14064              : 
   14065     49210001 :   if (cv_quals)
   14066              :     {
   14067     13389361 :       int sub_quals = 0, first_quals = 0;
   14068     13389361 :       unsigned i;
   14069     13389361 :       dw_die_ref first = NULL, last = NULL;
   14070              : 
   14071              :       /* Determine a lesser qualified type that most closely matches
   14072              :          this one.  Then generate DW_TAG_* entries for the remaining
   14073              :          qualifiers.  */
   14074     13389361 :       sub_quals = get_nearest_type_subqualifiers (type, cv_quals,
   14075              :                                                   cv_qual_mask);
   14076     13389361 :       if (sub_quals && use_debug_types)
   14077              :         {
   14078              :           bool needed = false;
   14079              :           /* If emitting type units, make sure the order of qualifiers
   14080              :              is canonical.  Thus, start from unqualified type if
   14081              :              an earlier qualifier is missing in sub_quals, but some later
   14082              :              one is present there.  */
   14083            0 :           for (i = 0; i < dwarf_qual_info_size; i++)
   14084            0 :             if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
   14085              :               needed = true;
   14086            0 :             else if (needed && (dwarf_qual_info[i].q & cv_quals))
   14087              :               {
   14088              :                 sub_quals = 0;
   14089              :                 break;
   14090              :               }
   14091              :         }
   14092     13389361 :       mod_type_die = modified_type_die (type, sub_quals, type_attrs,
   14093              :                                         reverse, context_die);
   14094     13389361 :       if (mod_scope && mod_type_die && mod_type_die->die_parent == mod_scope)
   14095              :         {
   14096              :           /* As not all intermediate qualified DIEs have corresponding
   14097              :              tree types, ensure that qualified DIEs in the same scope
   14098              :              as their DW_AT_type are emitted after their DW_AT_type,
   14099              :              only with other qualified DIEs for the same type possibly
   14100              :              in between them.  Determine the range of such qualified
   14101              :              DIEs now (first being the base type, last being corresponding
   14102              :              last qualified DIE for it).  */
   14103     13200163 :           unsigned int count = 0;
   14104     13200163 :           first = qualified_die_p (mod_type_die, &first_quals,
   14105              :                                    dwarf_qual_info_size);
   14106     13200163 :           if (first == NULL)
   14107     12963407 :             first = mod_type_die;
   14108     13200163 :           gcc_assert ((first_quals & ~sub_quals) == 0);
   14109              :           for (count = 0, last = first;
   14110     14225959 :                count < (1U << dwarf_qual_info_size);
   14111      1025796 :                count++, last = last->die_sib)
   14112              :             {
   14113     14225959 :               int quals = 0;
   14114     14225959 :               if (last == mod_scope->die_child)
   14115              :                 break;
   14116      6406082 :               if (qualified_die_p (last->die_sib, &quals, dwarf_qual_info_size)
   14117              :                   != first)
   14118              :                 break;
   14119              :             }
   14120              :         }
   14121              : 
   14122     66946805 :       for (i = 0; i < dwarf_qual_info_size; i++)
   14123     53557444 :         if (dwarf_qual_info[i].q & cv_quals & ~sub_quals)
   14124              :           {
   14125     13403764 :             dw_die_ref d;
   14126     13403764 :             if (first && first != last)
   14127              :               {
   14128       794130 :                 for (d = first->die_sib; ; d = d->die_sib)
   14129              :                   {
   14130      1040064 :                     int quals = 0;
   14131      1040064 :                     qualified_die_p (d, &quals, dwarf_qual_info_size);
   14132      1040064 :                     if (quals == (first_quals | dwarf_qual_info[i].q))
   14133              :                       break;
   14134       936843 :                     if (d == last)
   14135              :                       {
   14136              :                         d = NULL;
   14137              :                         break;
   14138              :                       }
   14139       245934 :                   }
   14140       794130 :                 if (d)
   14141              :                   {
   14142       103221 :                     mod_type_die = d;
   14143       103221 :                     continue;
   14144              :                   }
   14145              :               }
   14146     13300543 :             if (first)
   14147              :               {
   14148     13111345 :                 d = new_die_raw (dwarf_qual_info[i].t);
   14149     13111345 :                 add_child_die_after (mod_scope, d, last);
   14150     13111345 :                 last = d;
   14151              :               }
   14152              :             else
   14153       189198 :               d = new_die (dwarf_qual_info[i].t, mod_scope, type);
   14154     13300543 :             if (mod_type_die)
   14155     13270889 :               add_AT_die_ref (d, DW_AT_type, mod_type_die);
   14156     13300543 :             mod_type_die = d;
   14157     13300543 :             first_quals |= dwarf_qual_info[i].q;
   14158              :           }
   14159              :     }
   14160     35820640 :   else if (type_attrs
   14161     35820640 :            && (btf_tags = lookup_attribute ("btf_type_tag", type_attrs)))
   14162              :     {
   14163              :       /* First create a DIE for the type without any type_tag attribute.
   14164              :          Then generate TAG_GNU_annotation DIEs for the type_tags.  */
   14165           29 :       dw_die_ref mod_die = modified_type_die (type, cv_quals, NULL_TREE,
   14166              :                                               reverse, context_die);
   14167           29 :       gen_btf_tag_dies (btf_tags, mod_die);
   14168           29 :       return mod_die;
   14169              :     }
   14170     35820611 :   else if (code == POINTER_TYPE || code == REFERENCE_TYPE)
   14171              :     {
   14172     30225085 :       dwarf_tag tag = DW_TAG_pointer_type;
   14173     30225085 :       if (code == REFERENCE_TYPE)
   14174              :         {
   14175     15972604 :           if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
   14176              :             tag = DW_TAG_rvalue_reference_type;
   14177              :           else
   14178     13459319 :             tag = DW_TAG_reference_type;
   14179              :         }
   14180     30225085 :       mod_type_die = new_die (tag, mod_scope, type);
   14181              : 
   14182     30225085 :       add_AT_unsigned (mod_type_die, DW_AT_byte_size,
   14183     30225085 :                        simple_type_size_in_bits (type) / BITS_PER_UNIT);
   14184     30225085 :       add_alignment_attribute (mod_type_die, type);
   14185     30225085 :       item_type = TREE_TYPE (type);
   14186              : 
   14187     30225085 :       addr_space_t as = TYPE_ADDR_SPACE (item_type);
   14188     30225085 :       if (!ADDR_SPACE_GENERIC_P (as))
   14189              :         {
   14190            3 :           int action = targetm.addr_space.debug (as);
   14191            3 :           if (action >= 0)
   14192              :             {
   14193              :               /* Positive values indicate an address_class.  */
   14194            3 :               add_AT_unsigned (mod_type_die, DW_AT_address_class, action);
   14195              :             }
   14196              :           else
   14197              :             {
   14198              :               /* Negative values indicate an (inverted) segment base reg.  */
   14199            0 :               dw_loc_descr_ref d
   14200            0 :                 = one_reg_loc_descriptor (~action, VAR_INIT_STATUS_INITIALIZED);
   14201            0 :               add_AT_loc (mod_type_die, DW_AT_segment, d);
   14202              :             }
   14203              :         }
   14204              :     }
   14205      5595526 :   else if (code == ARRAY_TYPE
   14206      5595526 :            || (lang_hooks.types.get_array_descr_info
   14207        22716 :                && lang_hooks.types.get_array_descr_info (type, &info)))
   14208              :     {
   14209       133015 :       gen_type_die (type, mod_scope);
   14210       133015 :       return lookup_type_die (type);
   14211              :     }
   14212      5462511 :   else if (code == INTEGER_TYPE
   14213       390577 :            && TREE_TYPE (type) != NULL_TREE
   14214      5462529 :            && subrange_type_for_debug_p (type, &low, &high))
   14215              :     {
   14216           18 :       tree bias = NULL_TREE;
   14217           18 :       if (lang_hooks.types.get_type_bias)
   14218            0 :         bias = lang_hooks.types.get_type_bias (type);
   14219           18 :       mod_type_die = subrange_type_die (type, low, high, bias, mod_scope);
   14220           18 :       item_type = TREE_TYPE (type);
   14221              :     }
   14222      5462493 :   else if (is_base_type (type))
   14223              :     {
   14224              :       /* If a target supports long double as different floating point
   14225              :          modes with the same 16-byte size, use normal DW_TAG_base_type
   14226              :          only for the composite (ibm_extended_real_format) type and
   14227              :          for the other for the time being emit instead a "_Float128"
   14228              :          or "complex _Float128" DW_TAG_base_type and a "long double"
   14229              :          or "complex long double" typedef to it.  */
   14230       614063 :       if (tree other_type = long_double_as_float128 (type))
   14231              :         {
   14232            0 :           dw_die_ref other_die;
   14233            0 :           if (TYPE_NAME (other_type))
   14234              :             {
   14235            0 :               other_die
   14236            0 :                 = modified_type_die (other_type, TYPE_UNQUALIFIED,
   14237            0 :                                      TYPE_ATTRIBUTES (other_type),
   14238              :                                      reverse, context_die);
   14239              :             }
   14240              :           else
   14241              :             {
   14242            0 :               other_die = base_type_die (type, reverse);
   14243            0 :               add_child_die (comp_unit_die (), other_die);
   14244            0 :               add_name_attribute (other_die,
   14245            0 :                                   TREE_CODE (type) == COMPLEX_TYPE
   14246              :                                   ? "complex _Float128" : "_Float128");
   14247              :             }
   14248            0 :           mod_type_die = new_die_raw (DW_TAG_typedef);
   14249            0 :           add_AT_die_ref (mod_type_die, DW_AT_type, other_die);
   14250              :         }
   14251              :       else
   14252       614063 :         mod_type_die = base_type_die (type, reverse);
   14253              : 
   14254              :       /* The DIE with DW_AT_endianity is placed right after the naked DIE.  */
   14255       614063 :       if (reverse_type)
   14256              :         {
   14257           62 :           dw_die_ref after_die = modified_type_die (type, cv_quals, type_attrs,
   14258              :                                                     false, context_die);
   14259           62 :           add_child_die_after (mod_scope, mod_type_die, after_die);
   14260              :         }
   14261              :       else
   14262       614001 :         add_child_die (mod_scope, mod_type_die);
   14263              : 
   14264       614063 :       add_pubtype (type, mod_type_die);
   14265              :     }
   14266              :   else
   14267              :     {
   14268              :       /* The DIE with DW_AT_endianity is placed right after the naked DIE.  */
   14269      4848430 :       if (reverse_type)
   14270              :         {
   14271            2 :           dw_die_ref after_die = modified_type_die (type, cv_quals, type_attrs,
   14272              :                                                     false, context_die);
   14273            2 :           gen_type_die (type, context_die, true);
   14274            2 :           gcc_assert (after_die->die_sib
   14275              :                       && get_AT_unsigned (after_die->die_sib, DW_AT_endianity));
   14276            2 :           return after_die->die_sib;
   14277              :         }
   14278              : 
   14279      4848428 :       gen_type_die (type, context_die);
   14280              : 
   14281              :       /* We have to get the type_main_variant here (and pass that to the
   14282              :          `lookup_type_die' routine) because the ..._TYPE node we have
   14283              :          might simply be a *copy* of some original type node (where the
   14284              :          copy was created to help us keep track of typedef names) and
   14285              :          that copy might have a different TYPE_UID from the original
   14286              :          ..._TYPE node.  */
   14287      4848428 :       if (code == FUNCTION_TYPE || code == METHOD_TYPE)
   14288              :         {
   14289              :           /* For function/method types, can't just use type_main_variant here,
   14290              :              because that can have different ref-qualifiers for C++,
   14291              :              but try to canonicalize.  */
   14292       274631 :           tree main = TYPE_MAIN_VARIANT (type);
   14293       300438 :           for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
   14294       300426 :             if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
   14295       300160 :                 && check_base_type (t, main)
   14296       590100 :                 && check_lang_type (t, type))
   14297       274619 :               return lookup_type_die (t);
   14298           12 :           return lookup_type_die (type);
   14299              :         }
   14300              :       /* Vectors have the debugging information in the type,
   14301              :          not the main variant.  */
   14302      4573797 :       else if (code == VECTOR_TYPE)
   14303        20308 :         return lookup_type_die (type);
   14304              :       else
   14305      4553489 :         return lookup_type_die (type_main_variant (type));
   14306              :     }
   14307              : 
   14308              :   /* Builtin types don't have a DECL_ORIGINAL_TYPE.  For those,
   14309              :      don't output a DW_TAG_typedef, since there isn't one in the
   14310              :      user's program; just attach a DW_AT_name to the type.
   14311              :      Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
   14312              :      if the base type already has the same name.  */
   14313     44228527 :   if (name
   14314     44228527 :       && ((TREE_CODE (name) != TYPE_DECL
   14315        17791 :            && (qualified_type == TYPE_MAIN_VARIANT (type)
   14316         4486 :                || (cv_quals == TYPE_UNQUALIFIED)))
   14317     13134996 :           || (TREE_CODE (name) == TYPE_DECL
   14318     13130510 :               && DECL_NAME (name)
   14319     13130475 :               && !DECL_NAMELESS (name)
   14320     13129566 :               && (TREE_TYPE (name) == qualified_type
   14321     12519844 :                   || (lang_hooks.types.get_debug_type
   14322     12460898 :                       && (lang_hooks.types.get_debug_type (TREE_TYPE (name))
   14323              :                           == qualified_type))))))
   14324              :     {
   14325       623027 :       if (TREE_CODE (name) == TYPE_DECL)
   14326              :         /* Could just call add_name_and_src_coords_attributes here,
   14327              :            but since this is a builtin type it doesn't have any
   14328              :            useful source coordinates anyway.  */
   14329       609722 :         name = DECL_NAME (name);
   14330       623027 :       add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
   14331              :     }
   14332     43605500 :   else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
   14333              :     {
   14334         7326 :       if (TREE_CODE (type) == BITINT_TYPE)
   14335              :         {
   14336           94 :           char name_buf[sizeof ("unsigned _BitInt(2147483647)")];
   14337          376 :           snprintf (name_buf, sizeof (name_buf),
   14338           94 :                     "%s_BitInt(%d)", TYPE_UNSIGNED (type) ? "unsigned " : "",
   14339           94 :                     TYPE_PRECISION (type));
   14340           94 :           add_name_attribute (mod_type_die, name_buf);
   14341              :         }
   14342              :       else
   14343              :         {
   14344              :           /* This probably indicates a bug.  */
   14345         7232 :           name = TYPE_IDENTIFIER (type);
   14346         8290 :           add_name_attribute (mod_type_die,
   14347              :                               name
   14348         1058 :                               ? IDENTIFIER_POINTER (name) : "__unknown__");
   14349              :         }
   14350              :     }
   14351              : 
   14352     44228527 :   if (qualified_type && !reverse_type)
   14353     44000346 :     equate_type_number_to_die (qualified_type, mod_type_die);
   14354              : 
   14355     44228527 :   if (item_type)
   14356              :     /* We must do this after the equate_type_number_to_die call, in case
   14357              :        this is a recursive type.  This ensures that the modified_type_die
   14358              :        recursion will terminate even if the type is recursive.  Recursive
   14359              :        types are possible in Ada.  */
   14360     90675309 :     sub_die = modified_type_die (item_type,
   14361     30225103 :                                  TYPE_QUALS_NO_ADDR_SPACE (item_type),
   14362     30225103 :                                  TYPE_ATTRIBUTES (item_type),
   14363              :                                  reverse, context_die);
   14364              : 
   14365     30225103 :   if (sub_die != NULL)
   14366     30191157 :     add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
   14367              : 
   14368     44228527 :   add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
   14369     44228527 :   if (TYPE_ARTIFICIAL (type))
   14370          922 :     add_AT_flag (mod_type_die, DW_AT_artificial, 1);
   14371              : 
   14372              :   return mod_type_die;
   14373              : }
   14374              : 
   14375              : /* Generate DIEs for the generic parameters of T.
   14376              :    T must be either a generic type or a generic function.
   14377              :    See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more.  */
   14378              : 
   14379              : static void
   14380    137962085 : gen_generic_params_dies (tree t)
   14381              : {
   14382    137962085 :   tree parms, args;
   14383    137962085 :   int parms_num, i;
   14384    137962085 :   dw_die_ref die = NULL;
   14385    137962085 :   int non_default;
   14386              : 
   14387    137962085 :   if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
   14388              :     return;
   14389              : 
   14390    137962085 :   if (TYPE_P (t))
   14391     39220113 :     die = lookup_type_die (t);
   14392     98741972 :   else if (DECL_P (t))
   14393     98741972 :     die = lookup_decl_die (t);
   14394              : 
   14395    137962085 :   gcc_assert (die);
   14396              : 
   14397    137962085 :   parms = lang_hooks.get_innermost_generic_parms (t);
   14398    137962085 :   if (!parms)
   14399              :     /* T has no generic parameter. It means T is neither a generic type
   14400              :        or function. End of story.  */
   14401              :     return;
   14402              : 
   14403     40198257 :   parms_num = TREE_VEC_LENGTH (parms);
   14404     40198257 :   args = lang_hooks.get_innermost_generic_args (t);
   14405     40198257 :   if (TREE_CHAIN (args) && TREE_CODE (TREE_CHAIN (args)) == INTEGER_CST)
   14406     40197909 :     non_default = int_cst_value (TREE_CHAIN (args));
   14407              :   else
   14408          348 :     non_default = TREE_VEC_LENGTH (args);
   14409    102664300 :   for (i = 0; i < parms_num; i++)
   14410              :     {
   14411     62466043 :       tree parm, arg, arg_pack_elems;
   14412     62466043 :       dw_die_ref parm_die;
   14413              : 
   14414     62466043 :       parm = TREE_VEC_ELT (parms, i);
   14415     62466043 :       arg = TREE_VEC_ELT (args, i);
   14416     62466043 :       arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
   14417    124932086 :       gcc_assert (parm && TREE_VALUE (parm) && arg);
   14418              : 
   14419     62466043 :       if (parm && TREE_VALUE (parm) && arg)
   14420              :         {
   14421              :           /* If PARM represents a template parameter pack,
   14422              :              emit a DW_TAG_GNU_template_parameter_pack DIE, followed
   14423              :              by DW_TAG_template_*_parameter DIEs for the argument
   14424              :              pack elements of ARG. Note that ARG would then be
   14425              :              an argument pack.  */
   14426     62466043 :           if (arg_pack_elems)
   14427      5236554 :             parm_die = template_parameter_pack_die (TREE_VALUE (parm),
   14428              :                                                     arg_pack_elems,
   14429              :                                                     die);
   14430              :           else
   14431     57229489 :             parm_die = generic_parameter_die (TREE_VALUE (parm), arg,
   14432              :                                               true /* emit name */, die);
   14433     62466043 :           if (i >= non_default)
   14434       992365 :             add_AT_flag (parm_die, DW_AT_default_value, 1);
   14435              :         }
   14436              :     }
   14437              : }
   14438              : 
   14439              : /* Create and return a DIE for PARM which should be
   14440              :    the representation of a generic type parameter.
   14441              :    For instance, in the C++ front end, PARM would be a template parameter.
   14442              :    ARG is the argument to PARM.
   14443              :    EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
   14444              :    name of the PARM.
   14445              :    PARENT_DIE is the parent DIE which the new created DIE should be added to,
   14446              :    as a child node.  */
   14447              : 
   14448              : static dw_die_ref
   14449     67757039 : generic_parameter_die (tree parm, tree arg,
   14450              :                        bool emit_name_p,
   14451              :                        dw_die_ref parent_die)
   14452              : {
   14453     67757039 :   dw_die_ref tmpl_die = NULL;
   14454     67757039 :   const char *name = NULL;
   14455              : 
   14456              :   /* C++20 accepts class literals as template parameters, and var
   14457              :      decls with initializers represent them.  The VAR_DECLs would be
   14458              :      rejected, but we can take the DECL_INITIAL constructor and
   14459              :      attempt to expand it.  */
   14460     67757039 :   if (arg && VAR_P (arg))
   14461         7379 :     arg = DECL_INITIAL (arg);
   14462              : 
   14463     67757039 :   if (!parm || !DECL_NAME (parm) || !arg)
   14464              :     return NULL;
   14465              : 
   14466              :   /* We support non-type generic parameters and arguments,
   14467              :      type generic parameters and arguments, as well as
   14468              :      generic generic parameters (a.k.a. template template parameters in C++)
   14469              :      and arguments.  */
   14470     58329432 :   if (TREE_CODE (parm) == PARM_DECL)
   14471              :     /* PARM is a nontype generic parameter  */
   14472     10543735 :     tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
   14473     47785697 :   else if (TREE_CODE (parm) == TYPE_DECL)
   14474              :     /* PARM is a type generic parameter.  */
   14475     47648801 :     tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
   14476       136896 :   else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
   14477              :     /* PARM is a generic generic parameter.
   14478              :        Its DIE is a GNU extension. It shall have a
   14479              :        DW_AT_name attribute to represent the name of the template template
   14480              :        parameter, and a DW_AT_GNU_template_name attribute to represent the
   14481              :        name of the template template argument.  */
   14482       136896 :     tmpl_die = new_die (DW_TAG_GNU_template_template_param,
   14483              :                         parent_die, parm);
   14484              :   else
   14485            0 :     gcc_unreachable ();
   14486              : 
   14487     58329432 :   if (tmpl_die)
   14488              :     {
   14489     58329432 :       tree tmpl_type;
   14490              : 
   14491              :       /* If PARM is a generic parameter pack, it means we are
   14492              :          emitting debug info for a template argument pack element.
   14493              :          In other terms, ARG is a template argument pack element.
   14494              :          In that case, we don't emit any DW_AT_name attribute for
   14495              :          the die.  */
   14496     58329432 :       if (emit_name_p)
   14497              :         {
   14498     48157967 :           name = IDENTIFIER_POINTER (DECL_NAME (parm));
   14499     48157967 :           gcc_assert (name);
   14500     48157967 :           add_AT_string (tmpl_die, DW_AT_name, name);
   14501              :         }
   14502              : 
   14503     58329432 :       if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
   14504              :         {
   14505              :           /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
   14506              :              TMPL_DIE should have a child DW_AT_type attribute that is set
   14507              :              to the type of the argument to PARM, which is ARG.
   14508              :              If PARM is a type generic parameter, TMPL_DIE should have a
   14509              :              child DW_AT_type that is set to ARG.  */
   14510     58192536 :           tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
   14511     58192536 :           add_type_attribute (tmpl_die, tmpl_type,
   14512     58192536 :                               (TREE_THIS_VOLATILE (tmpl_type)
   14513     58192536 :                                ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED),
   14514              :                               false, parent_die);
   14515              :         }
   14516              :       else
   14517              :         {
   14518              :           /* So TMPL_DIE is a DIE representing a
   14519              :              a generic generic template parameter, a.k.a template template
   14520              :              parameter in C++ and arg is a template.  */
   14521              : 
   14522              :           /* The DW_AT_GNU_template_name attribute of the DIE must be set
   14523              :              to the name of the argument.  */
   14524       136896 :           name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
   14525       136896 :           if (name)
   14526       136896 :             add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
   14527              :         }
   14528              : 
   14529     58329432 :       if (TREE_CODE (parm) == PARM_DECL)
   14530              :         /* So PARM is a non-type generic parameter.
   14531              :            DWARF3 5.6.8 says we must set a DW_AT_const_value child
   14532              :            attribute of TMPL_DIE which value represents the value
   14533              :            of ARG.
   14534              :            We must be careful here:
   14535              :            The value of ARG might reference some function decls.
   14536              :            We might currently be emitting debug info for a generic
   14537              :            type and types are emitted before function decls, we don't
   14538              :            know if the function decls referenced by ARG will actually be
   14539              :            emitted after cgraph computations.
   14540              :            So must defer the generation of the DW_AT_const_value to
   14541              :            after cgraph is ready.  */
   14542     10543735 :         append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
   14543              :     }
   14544              : 
   14545              :   return tmpl_die;
   14546              : }
   14547              : 
   14548              : /* Generate and return a  DW_TAG_GNU_template_parameter_pack DIE representing.
   14549              :    PARM_PACK must be a template parameter pack. The returned DIE
   14550              :    will be child DIE of PARENT_DIE.  */
   14551              : 
   14552              : static dw_die_ref
   14553      5236554 : template_parameter_pack_die (tree parm_pack,
   14554              :                              tree parm_pack_args,
   14555              :                              dw_die_ref parent_die)
   14556              : {
   14557      5236554 :   dw_die_ref die;
   14558      5236554 :   int j;
   14559              : 
   14560      5236554 :   gcc_assert (parent_die && parm_pack);
   14561              : 
   14562      5236554 :   die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
   14563      5236554 :   add_name_and_src_coords_attributes (die, parm_pack);
   14564     21000658 :   for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
   14565     10527550 :     generic_parameter_die (parm_pack,
   14566     10527550 :                            TREE_VEC_ELT (parm_pack_args, j),
   14567              :                            false /* Don't emit DW_AT_name */,
   14568              :                            die);
   14569      5236554 :   return die;
   14570              : }
   14571              : 
   14572              : /* Return the debugger register number described by a given RTL node.  */
   14573              : 
   14574              : static unsigned int
   14575     16435227 : debugger_reg_number (const_rtx rtl)
   14576              : {
   14577     16435227 :   unsigned regno = REGNO (rtl);
   14578              : 
   14579     16435227 :   gcc_assert (regno < FIRST_PSEUDO_REGISTER);
   14580              : 
   14581              : #ifdef LEAF_REG_REMAP
   14582              :   if (crtl->uses_only_leaf_regs)
   14583              :     {
   14584              :       int leaf_reg = LEAF_REG_REMAP (regno);
   14585              :       if (leaf_reg != -1)
   14586              :         regno = (unsigned) leaf_reg;
   14587              :     }
   14588              : #endif
   14589              : 
   14590     16435227 :   regno = DEBUGGER_REGNO (regno);
   14591     16435227 :   gcc_assert (regno != INVALID_REGNUM);
   14592     16435227 :   return regno;
   14593              : }
   14594              : 
   14595              : /* Optionally add a DW_OP_piece term to a location description expression.
   14596              :    DW_OP_piece is only added if the location description expression already
   14597              :    doesn't end with DW_OP_piece.  */
   14598              : 
   14599              : static void
   14600       561227 : add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
   14601              : {
   14602       561227 :   dw_loc_descr_ref loc;
   14603              : 
   14604       561227 :   if (*list_head != NULL)
   14605              :     {
   14606              :       /* Find the end of the chain.  */
   14607      1137464 :       for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
   14608              :         ;
   14609              : 
   14610       561227 :       if (loc->dw_loc_opc != DW_OP_piece)
   14611       561213 :         loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
   14612              :     }
   14613       561227 : }
   14614              : 
   14615              : /* Return a location descriptor that designates a machine register or
   14616              :    zero if there is none.  */
   14617              : 
   14618              : static dw_loc_descr_ref
   14619     15067782 : reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
   14620              : {
   14621     15067782 :   rtx regs;
   14622              : 
   14623     15067782 :   if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
   14624              :     return 0;
   14625              : 
   14626              :   /* We only use "frame base" when we're sure we're talking about the
   14627              :      post-prologue local stack frame.  We do this by *not* running
   14628              :      register elimination until this point, and recognizing the special
   14629              :      argument pointer and soft frame pointer rtx's.
   14630              :      Use DW_OP_fbreg offset DW_OP_stack_value in this case.  */
   14631     15015718 :   if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
   14632     15024662 :       && (ira_use_lra_p
   14633         4472 :           ? lra_eliminate_regs (rtl, VOIDmode, NULL_RTX)
   14634            0 :           : eliminate_regs (rtl, VOIDmode, NULL_RTX)) != rtl)
   14635              :     {
   14636         4472 :       dw_loc_descr_ref result = NULL;
   14637              : 
   14638         4472 :       if (dwarf_version >= 4 || !dwarf_strict)
   14639              :         {
   14640         4472 :           result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
   14641              :                                        initialized);
   14642         4472 :           if (result)
   14643         8944 :             add_loc_descr (&result,
   14644              :                            new_loc_descr (DW_OP_stack_value, 0, 0));
   14645              :         }
   14646         4472 :       return result;
   14647              :     }
   14648              : 
   14649     15015718 :   regs = targetm.dwarf_register_span (rtl);
   14650              : 
   14651     15015718 :   if (REG_NREGS (rtl) > 1 || regs)
   14652        90268 :     return multiple_reg_loc_descriptor (rtl, regs, initialized);
   14653              :   else
   14654              :     {
   14655     14925450 :       unsigned int debugger_regnum = debugger_reg_number (rtl);
   14656     14925450 :       if (debugger_regnum == IGNORED_DWARF_REGNUM)
   14657              :         return 0;
   14658     14925450 :       return one_reg_loc_descriptor (debugger_regnum, initialized);
   14659              :     }
   14660              : }
   14661              : 
   14662              : /* Return a location descriptor that designates a machine register for
   14663              :    a given hard register number.  */
   14664              : 
   14665              : static dw_loc_descr_ref
   14666     16416576 : one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
   14667              : {
   14668     16416576 :   dw_loc_descr_ref reg_loc_descr;
   14669              : 
   14670     16416576 :   if (regno <= 31)
   14671     16398127 :     reg_loc_descr
   14672     16398127 :       = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
   14673              :   else
   14674        18449 :     reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
   14675              : 
   14676     16416576 :   if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
   14677            0 :     add_loc_descr (&reg_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
   14678              : 
   14679     16416576 :   return reg_loc_descr;
   14680              : }
   14681              : 
   14682              : /* Given an RTL of a register, return a location descriptor that
   14683              :    designates a value that spans more than one register.  */
   14684              : 
   14685              : static dw_loc_descr_ref
   14686        90268 : multiple_reg_loc_descriptor (rtx rtl, rtx regs,
   14687              :                              enum var_init_status initialized)
   14688              : {
   14689        90268 :   int size, i;
   14690        90268 :   dw_loc_descr_ref loc_result = NULL;
   14691              : 
   14692              :   /* Simple, contiguous registers.  */
   14693        90268 :   if (regs == NULL_RTX)
   14694              :     {
   14695        90268 :       unsigned reg = REGNO (rtl);
   14696        90268 :       int nregs;
   14697              : 
   14698              : #ifdef LEAF_REG_REMAP
   14699              :       if (crtl->uses_only_leaf_regs)
   14700              :         {
   14701              :           int leaf_reg = LEAF_REG_REMAP (reg);
   14702              :           if (leaf_reg != -1)
   14703              :             reg = (unsigned) leaf_reg;
   14704              :         }
   14705              : #endif
   14706              : 
   14707        90268 :       gcc_assert ((unsigned) DEBUGGER_REGNO (reg) == debugger_reg_number (rtl));
   14708        90268 :       nregs = REG_NREGS (rtl);
   14709              : 
   14710              :       /* At present we only track constant-sized pieces.  */
   14711       180536 :       if (!GET_MODE_SIZE (GET_MODE (rtl)).is_constant (&size))
   14712              :         return NULL;
   14713        90268 :       size /= nregs;
   14714              : 
   14715        90268 :       loc_result = NULL;
   14716       270804 :       while (nregs--)
   14717              :         {
   14718       180536 :           dw_loc_descr_ref t;
   14719              : 
   14720       180536 :           t = one_reg_loc_descriptor (DEBUGGER_REGNO (reg),
   14721              :                                       VAR_INIT_STATUS_INITIALIZED);
   14722       180536 :           add_loc_descr (&loc_result, t);
   14723       180536 :           add_loc_descr_op_piece (&loc_result, size);
   14724       180536 :           ++reg;
   14725              :         }
   14726        90268 :       return loc_result;
   14727              :     }
   14728              : 
   14729              :   /* Now onto stupid register sets in non contiguous locations.  */
   14730              : 
   14731            0 :   gcc_assert (GET_CODE (regs) == PARALLEL);
   14732              : 
   14733              :   /* At present we only track constant-sized pieces.  */
   14734            0 :   if (!GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))).is_constant (&size))
   14735              :     return NULL;
   14736            0 :   loc_result = NULL;
   14737              : 
   14738            0 :   for (i = 0; i < XVECLEN (regs, 0); ++i)
   14739              :     {
   14740            0 :       dw_loc_descr_ref t;
   14741              : 
   14742            0 :       t = one_reg_loc_descriptor (debugger_reg_number (XVECEXP (regs, 0, i)),
   14743              :                                   VAR_INIT_STATUS_INITIALIZED);
   14744            0 :       add_loc_descr (&loc_result, t);
   14745            0 :       add_loc_descr_op_piece (&loc_result, size);
   14746              :     }
   14747              : 
   14748            0 :   if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
   14749            0 :     add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
   14750            0 :   return loc_result;
   14751              : }
   14752              : 
   14753              : static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT);
   14754              : 
   14755              : /* Return a location descriptor that designates a constant i,
   14756              :    as a compound operation from constant (i >> shift), constant shift
   14757              :    and DW_OP_shl.  */
   14758              : 
   14759              : static dw_loc_descr_ref
   14760        35526 : int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
   14761              : {
   14762        35526 :   dw_loc_descr_ref ret = int_loc_descriptor (i >> shift);
   14763        35526 :   add_loc_descr (&ret, int_loc_descriptor (shift));
   14764        35526 :   add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
   14765        35526 :   return ret;
   14766              : }
   14767              : 
   14768              : /* Return a location descriptor that designates constant POLY_I.  */
   14769              : 
   14770              : static dw_loc_descr_ref
   14771      6443839 : int_loc_descriptor (poly_int64 poly_i)
   14772              : {
   14773      6443856 :   enum dwarf_location_atom op;
   14774              : 
   14775      6443856 :   HOST_WIDE_INT i;
   14776      6443856 :   if (!poly_i.is_constant (&i))
   14777              :     {
   14778              :       /* Create location descriptions for the non-constant part and
   14779              :          add any constant offset at the end.  */
   14780              :       dw_loc_descr_ref ret = NULL;
   14781              :       HOST_WIDE_INT constant = poly_i.coeffs[0];
   14782              :       for (unsigned int j = 1; j < NUM_POLY_INT_COEFFS; ++j)
   14783              :         {
   14784              :           HOST_WIDE_INT coeff = poly_i.coeffs[j];
   14785              :           if (coeff != 0)
   14786              :             {
   14787              :               dw_loc_descr_ref start = ret;
   14788              :               unsigned int factor;
   14789              :               int bias;
   14790              :               unsigned int regno = targetm.dwarf_poly_indeterminate_value
   14791              :                 (j, &factor, &bias);
   14792              : 
   14793              :               /* Add COEFF * ((REGNO / FACTOR) - BIAS) to the value:
   14794              :                  add COEFF * (REGNO / FACTOR) now and subtract
   14795              :                  COEFF * BIAS from the final constant part.  */
   14796              :               constant -= coeff * bias;
   14797              :               add_loc_descr (&ret, new_reg_loc_descr (regno, 0));
   14798              :               if (coeff % factor == 0)
   14799              :                 coeff /= factor;
   14800              :               else
   14801              :                 {
   14802              :                   int amount = exact_log2 (factor);
   14803              :                   gcc_assert (amount >= 0);
   14804              :                   add_loc_descr (&ret, int_loc_descriptor (amount));
   14805              :                   add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
   14806              :                 }
   14807              :               if (coeff != 1)
   14808              :                 {
   14809              :                   add_loc_descr (&ret, int_loc_descriptor (coeff));
   14810              :                   add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
   14811              :                 }
   14812              :               if (start)
   14813              :                 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
   14814              :             }
   14815              :         }
   14816              :       loc_descr_plus_const (&ret, constant);
   14817              :       return ret;
   14818              :     }
   14819              : 
   14820              :   /* Pick the smallest representation of a constant, rather than just
   14821              :      defaulting to the LEB encoding.  */
   14822      6443856 :   if (i >= 0)
   14823              :     {
   14824      6143146 :       int clz = clz_hwi (i);
   14825      4240523 :       int ctz = ctz_hwi (i);
   14826      6143146 :       if (i <= 31)
   14827      4195224 :         op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
   14828      1947922 :       else if (i <= 0xff)
   14829              :         op = DW_OP_const1u;
   14830       731707 :       else if (i <= 0xffff)
   14831              :         op = DW_OP_const2u;
   14832       552440 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
   14833              :                && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
   14834              :         /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
   14835              :            DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
   14836              :            while DW_OP_const4u is 5 bytes.  */
   14837        33456 :         return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 5);
   14838       518984 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
   14839         1341 :                && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
   14840              :         /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
   14841              :            while DW_OP_const4u is 5 bytes.  */
   14842          926 :         return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
   14843              : 
   14844       518058 :       else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
   14845         3835 :                && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
   14846              :                   <= 4)
   14847              :         {
   14848              :           /* As i >= 2**31, the double cast above will yield a negative number.
   14849              :              Since wrapping is defined in DWARF expressions we can output big
   14850              :              positive integers as small negative ones, regardless of the size
   14851              :              of host wide ints.
   14852              : 
   14853              :              Here, since the evaluator will handle 32-bit values and since i >=
   14854              :              2**31, we know it's going to be interpreted as a negative literal:
   14855              :              store it this way if we can do better than 5 bytes this way.  */
   14856           17 :           return int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
   14857              :         }
   14858       518041 :       else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
   14859              :         op = DW_OP_const4u;
   14860              : 
   14861              :       /* Past this point, i >= 0x100000000 and thus DW_OP_constu will take at
   14862              :          least 6 bytes: see if we can do better before falling back to it.  */
   14863        54313 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
   14864              :                && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
   14865              :         /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes.  */
   14866          415 :         return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 8);
   14867        53898 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
   14868        53898 :                && clz + 16 + (size_of_uleb128 (i) > 5 ? 255 : 31)
   14869              :                   >= HOST_BITS_PER_WIDE_INT)
   14870              :         /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
   14871              :            DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes.  */
   14872          568 :         return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 16);
   14873        53330 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
   14874              :                && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
   14875        53330 :                && size_of_uleb128 (i) > 6)
   14876              :         /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes.  */
   14877          161 :         return int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT - clz - 32);
   14878              :       else
   14879              :         op = DW_OP_constu;
   14880              :     }
   14881              :   else
   14882              :     {
   14883       300710 :       if (i >= -0x80)
   14884              :         op = DW_OP_const1s;
   14885        34363 :       else if (i >= -0x8000)
   14886              :         op = DW_OP_const2s;
   14887        29788 :       else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
   14888              :         {
   14889              :           if (size_of_int_loc_descriptor (i) < 5)
   14890              :             {
   14891              :               dw_loc_descr_ref ret = int_loc_descriptor (-i);
   14892              :               add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
   14893              :               return ret;
   14894              :             }
   14895              :           op = DW_OP_const4s;
   14896              :         }
   14897              :       else
   14898              :         {
   14899        29788 :           if (size_of_int_loc_descriptor (i)
   14900        29788 :               < (unsigned long) 1 + size_of_sleb128 (i))
   14901              :             {
   14902         4122 :               dw_loc_descr_ref ret = int_loc_descriptor (-i);
   14903         4122 :               add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
   14904         4122 :               return ret;
   14905              :             }
   14906              :           op = DW_OP_consts;
   14907              :         }
   14908              :     }
   14909              : 
   14910      6404191 :   return new_loc_descr (op, i, 0);
   14911              : }
   14912              : 
   14913              : /* Likewise, for unsigned constants.  */
   14914              : 
   14915              : static dw_loc_descr_ref
   14916       145891 : uint_loc_descriptor (unsigned HOST_WIDE_INT i)
   14917              : {
   14918       145891 :   const unsigned HOST_WIDE_INT max_int = INTTYPE_MAXIMUM (HOST_WIDE_INT);
   14919       145891 :   const unsigned HOST_WIDE_INT max_uint
   14920              :     = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT);
   14921              : 
   14922              :   /* If possible, use the clever signed constants handling.  */
   14923       145891 :   if (i <= max_int)
   14924       145883 :     return int_loc_descriptor ((HOST_WIDE_INT) i);
   14925              : 
   14926              :   /* Here, we are left with positive numbers that cannot be represented as
   14927              :      HOST_WIDE_INT, i.e.:
   14928              :          max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
   14929              : 
   14930              :      Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
   14931              :      whereas may be better to output a negative integer: thanks to integer
   14932              :      wrapping, we know that:
   14933              :          x = x - 2 ** DWARF2_ADDR_SIZE
   14934              :            = x - 2 * (max (HOST_WIDE_INT) + 1)
   14935              :      So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
   14936              :      small negative integers.  Let's try that in cases it will clearly improve
   14937              :      the encoding: there is no gain turning DW_OP_const4u into
   14938              :      DW_OP_const4s.  */
   14939            8 :   if (DWARF2_ADDR_SIZE * 8 == HOST_BITS_PER_WIDE_INT
   14940              :       && ((DWARF2_ADDR_SIZE == 4 && i > max_uint - 0x8000)
   14941            8 :           || (DWARF2_ADDR_SIZE == 8 && i > max_uint - 0x80000000)))
   14942              :     {
   14943            4 :       const unsigned HOST_WIDE_INT first_shift = i - max_int - 1;
   14944              : 
   14945              :       /* Now, -1 <  first_shift <= max (HOST_WIDE_INT)
   14946              :          i.e.  0 <= first_shift <= max (HOST_WIDE_INT).  */
   14947            4 :       const HOST_WIDE_INT second_shift
   14948              :         = (HOST_WIDE_INT) first_shift - (HOST_WIDE_INT) max_int - 1;
   14949              : 
   14950              :       /* So we finally have:
   14951              :               -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
   14952              :          i.e.  min (HOST_WIDE_INT)     <= second_shift <  0.  */
   14953            4 :       return int_loc_descriptor (second_shift);
   14954              :     }
   14955              : 
   14956              :   /* Last chance: fallback to a simple constant operation.  */
   14957            4 :   return new_loc_descr
   14958            4 :      ((HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
   14959              :       ? DW_OP_const4u
   14960              :       : DW_OP_const8u,
   14961            4 :       i, 0);
   14962              : }
   14963              : 
   14964              : /* Generate and return a location description that computes the unsigned
   14965              :    comparison of the two stack top entries (a OP b where b is the top-most
   14966              :    entry and a is the second one).  The KIND of comparison can be LT_EXPR,
   14967              :    LE_EXPR, GT_EXPR or GE_EXPR.  */
   14968              : 
   14969              : static dw_loc_descr_ref
   14970            0 : uint_comparison_loc_list (enum tree_code kind)
   14971              : {
   14972            0 :   enum dwarf_location_atom op, flip_op;
   14973            0 :   dw_loc_descr_ref ret, bra_node, jmp_node, tmp;
   14974              : 
   14975            0 :   switch (kind)
   14976              :     {
   14977              :     case LT_EXPR:
   14978              :       op = DW_OP_lt;
   14979              :       break;
   14980              :     case LE_EXPR:
   14981              :       op = DW_OP_le;
   14982              :       break;
   14983              :     case GT_EXPR:
   14984              :       op = DW_OP_gt;
   14985              :       break;
   14986              :     case GE_EXPR:
   14987              :       op = DW_OP_ge;
   14988              :       break;
   14989            0 :     default:
   14990            0 :       gcc_unreachable ();
   14991              :     }
   14992              : 
   14993            0 :   bra_node = new_loc_descr (DW_OP_bra, 0, 0);
   14994            0 :   jmp_node = new_loc_descr (DW_OP_skip, 0, 0);
   14995              : 
   14996              :   /* Until DWARFv4, operations all work on signed integers.  It is nevertheless
   14997              :      possible to perform unsigned comparisons: we just have to distinguish
   14998              :      three cases:
   14999              : 
   15000              :        1. when a and b have the same sign (as signed integers); then we should
   15001              :           return: a OP(signed) b;
   15002              : 
   15003              :        2. when a is a negative signed integer while b is a positive one, then a
   15004              :           is a greater unsigned integer than b; likewise when a and b's roles
   15005              :           are flipped.
   15006              : 
   15007              :      So first, compare the sign of the two operands.  */
   15008            0 :   ret = new_loc_descr (DW_OP_over, 0, 0);
   15009            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
   15010            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_xor, 0, 0));
   15011              :   /* If they have different signs (i.e. they have different sign bits), then
   15012              :      the stack top value has now the sign bit set and thus it's smaller than
   15013              :      zero.  */
   15014            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_lit0, 0, 0));
   15015            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_lt, 0, 0));
   15016            0 :   add_loc_descr (&ret, bra_node);
   15017              : 
   15018              :   /* We are in case 1.  At this point, we know both operands have the same
   15019              :      sign, to it's safe to use the built-in signed comparison.  */
   15020            0 :   add_loc_descr (&ret, new_loc_descr (op, 0, 0));
   15021            0 :   add_loc_descr (&ret, jmp_node);
   15022              : 
   15023              :   /* We are in case 2.  Here, we know both operands do not have the same sign,
   15024              :      so we have to flip the signed comparison.  */
   15025            0 :   flip_op = (kind == LT_EXPR || kind == LE_EXPR) ? DW_OP_gt : DW_OP_lt;
   15026            0 :   tmp = new_loc_descr (flip_op, 0, 0);
   15027            0 :   bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
   15028            0 :   bra_node->dw_loc_oprnd1.v.val_loc = tmp;
   15029            0 :   add_loc_descr (&ret, tmp);
   15030              : 
   15031              :   /* This dummy operation is necessary to make the two branches join.  */
   15032            0 :   tmp = new_loc_descr (DW_OP_nop, 0, 0);
   15033            0 :   jmp_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
   15034            0 :   jmp_node->dw_loc_oprnd1.v.val_loc = tmp;
   15035            0 :   add_loc_descr (&ret, tmp);
   15036              : 
   15037            0 :   return ret;
   15038              : }
   15039              : 
   15040              : /* Likewise, but takes the location description lists (might be destructive on
   15041              :    them).  Return NULL if either is NULL or if concatenation fails.  */
   15042              : 
   15043              : static dw_loc_list_ref
   15044            0 : loc_list_from_uint_comparison (dw_loc_list_ref left, dw_loc_list_ref right,
   15045              :                                enum tree_code kind)
   15046              : {
   15047            0 :   if (left == NULL || right == NULL)
   15048              :     return NULL;
   15049              : 
   15050            0 :   add_loc_list (&left, right);
   15051            0 :   if (left == NULL)
   15052              :     return NULL;
   15053              : 
   15054            0 :   add_loc_descr_to_each (left, uint_comparison_loc_list (kind));
   15055            0 :   return left;
   15056              : }
   15057              : 
   15058              : /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
   15059              :    without actually allocating it.  */
   15060              : 
   15061              : static unsigned long
   15062        31562 : size_of_int_shift_loc_descriptor (HOST_WIDE_INT i, int shift)
   15063              : {
   15064        31562 :   return size_of_int_loc_descriptor (i >> shift)
   15065        31562 :          + size_of_int_loc_descriptor (shift)
   15066        31562 :          + 1;
   15067              : }
   15068              : 
   15069              : /* Return size_of_locs (int_loc_descriptor (i)) without
   15070              :    actually allocating it.  */
   15071              : 
   15072              : static unsigned long
   15073      4507176 : size_of_int_loc_descriptor (HOST_WIDE_INT i)
   15074              : {
   15075      4519117 :   unsigned long s;
   15076              : 
   15077      4519117 :   if (i >= 0)
   15078              :     {
   15079      4233146 :       int clz, ctz;
   15080      4233146 :       if (i <= 31)
   15081              :         return 1;
   15082       795302 :       else if (i <= 0xff)
   15083              :         return 2;
   15084       217382 :       else if (i <= 0xffff)
   15085              :         return 3;
   15086       133104 :       clz = clz_hwi (i);
   15087       133104 :       ctz = ctz_hwi (i);
   15088       133104 :       if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 5
   15089              :           && clz + 5 + 255 >= HOST_BITS_PER_WIDE_INT)
   15090        28900 :         return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
   15091        28900 :                                                     - clz - 5);
   15092       104204 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
   15093         2093 :                && clz + 8 + 31 >= HOST_BITS_PER_WIDE_INT)
   15094          958 :         return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
   15095          958 :                                                     - clz - 8);
   15096       103246 :       else if (DWARF2_ADDR_SIZE == 4 && i > 0x7fffffff
   15097        13267 :                && size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i)
   15098              :                   <= 4)
   15099              :         return size_of_int_loc_descriptor ((HOST_WIDE_INT) (int32_t) i);
   15100        91305 :       else if (HOST_BITS_PER_WIDE_INT == 32 || i <= 0xffffffff)
   15101              :         return 5;
   15102        30202 :       s = size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
   15103        30202 :       if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 8
   15104              :           && clz + 8 + 255 >= HOST_BITS_PER_WIDE_INT)
   15105         1132 :         return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
   15106         1132 :                                                     - clz - 8);
   15107        29070 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 16
   15108          411 :                && clz + 16 + (s > 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT)
   15109          411 :         return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
   15110          411 :                                                     - clz - 16);
   15111        28659 :       else if (clz + ctz >= HOST_BITS_PER_WIDE_INT - 32
   15112              :                && clz + 32 + 31 >= HOST_BITS_PER_WIDE_INT
   15113          334 :                && s > 6)
   15114          161 :         return size_of_int_shift_loc_descriptor (i, HOST_BITS_PER_WIDE_INT
   15115          161 :                                                     - clz - 32);
   15116              :       else
   15117        28498 :         return 1 + s;
   15118              :     }
   15119              :   else
   15120              :     {
   15121       285971 :       if (i >= -0x80)
   15122              :         return 2;
   15123       161441 :       else if (i >= -0x8000)
   15124              :         return 3;
   15125       159121 :       else if (HOST_BITS_PER_WIDE_INT == 32 || i >= -0x80000000)
   15126              :         {
   15127              :           if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
   15128              :             {
   15129              :               s = size_of_int_loc_descriptor (-i) + 1;
   15130              :               if (s < 5)
   15131              :                 return s;
   15132              :             }
   15133              :           return 5;
   15134              :         }
   15135              :       else
   15136              :         {
   15137       159121 :           unsigned long r = 1 + size_of_sleb128 (i);
   15138       159121 :           if (-(unsigned HOST_WIDE_INT) i != (unsigned HOST_WIDE_INT) i)
   15139              :             {
   15140        38576 :               s = size_of_int_loc_descriptor (-i) + 1;
   15141        38576 :               if (s < r)
   15142              :                 return s;
   15143              :             }
   15144       152145 :           return r;
   15145              :         }
   15146              :     }
   15147              : }
   15148              : 
   15149              : /* Return loc description representing "address" of integer value.
   15150              :    This can appear only as toplevel expression.  */
   15151              : 
   15152              : static dw_loc_descr_ref
   15153      3142271 : address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
   15154              : {
   15155      3142271 :   int litsize;
   15156      3142271 :   dw_loc_descr_ref loc_result = NULL;
   15157              : 
   15158      3142271 :   if (!(dwarf_version >= 4 || !dwarf_strict))
   15159              :     return NULL;
   15160              : 
   15161      3142271 :   litsize = size_of_int_loc_descriptor (i);
   15162              :   /* Determine if DW_OP_stack_value or DW_OP_implicit_value
   15163              :      is more compact.  For DW_OP_stack_value we need:
   15164              :      litsize + 1 (DW_OP_stack_value)
   15165              :      and for DW_OP_implicit_value:
   15166              :      1 (DW_OP_implicit_value) + 1 (length) + size.  */
   15167      3721862 :   if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
   15168              :     {
   15169      3073166 :       loc_result = int_loc_descriptor (i);
   15170      3073166 :       add_loc_descr (&loc_result,
   15171              :                      new_loc_descr (DW_OP_stack_value, 0, 0));
   15172      3073166 :       return loc_result;
   15173              :     }
   15174              : 
   15175        69105 :   loc_result = new_loc_descr (DW_OP_implicit_value,
   15176              :                               size, 0);
   15177        69105 :   loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
   15178        69105 :   loc_result->dw_loc_oprnd2.v.val_int = i;
   15179        69105 :   return loc_result;
   15180              : }
   15181              : 
   15182              : /* Return a location descriptor that designates a base+offset location.  */
   15183              : 
   15184              : static dw_loc_descr_ref
   15185     14150343 : based_loc_descr (rtx reg, poly_int64 offset,
   15186              :                  enum var_init_status initialized)
   15187              : {
   15188     14150343 :   unsigned int regno;
   15189     14150343 :   dw_loc_descr_ref result;
   15190     14150343 :   dw_fde_ref fde = cfun->fde;
   15191              : 
   15192              :   /* We only use "frame base" when we're sure we're talking about the
   15193              :      post-prologue local stack frame.  We do this by *not* running
   15194              :      register elimination until this point, and recognizing the special
   15195              :      argument pointer and soft frame pointer rtx's.  */
   15196     14150343 :   if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
   15197              :     {
   15198      8773229 :       rtx elim = (ira_use_lra_p
   15199      8773229 :                   ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
   15200      8773229 :                   : eliminate_regs (reg, VOIDmode, NULL_RTX));
   15201              : 
   15202      8773229 :       if (elim != reg)
   15203              :         {
   15204              :           /* Allow hard frame pointer here even if frame pointer
   15205              :             isn't used since hard frame pointer is encoded with
   15206              :             DW_OP_fbreg which uses the DW_AT_frame_base attribute,
   15207              :             not hard frame pointer directly.  */
   15208      8773229 :           elim = strip_offset_and_add (elim, &offset);
   15209      8773229 :           gcc_assert (elim == hard_frame_pointer_rtx
   15210              :                       || elim == stack_pointer_rtx);
   15211              : 
   15212              :           /* If drap register is used to align stack, use frame
   15213              :              pointer + offset to access stack variables.  If stack
   15214              :              is aligned without drap, use stack pointer + offset to
   15215              :              access stack variables.  */
   15216      8773229 :           if (crtl->stack_realign_tried
   15217        11633 :               && reg == frame_pointer_rtx)
   15218              :             {
   15219         4832 :               int base_reg
   15220         4832 :                 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
   15221              :                                       ? HARD_FRAME_POINTER_REGNUM
   15222              :                                       : REGNO (elim));
   15223         4832 :               return new_reg_loc_descr (base_reg, offset);
   15224              :             }
   15225              : 
   15226      8768397 :           gcc_assert (frame_pointer_fb_offset_valid);
   15227      8768397 :           offset += frame_pointer_fb_offset;
   15228      8768397 :           HOST_WIDE_INT const_offset;
   15229      8768397 :           if (offset.is_constant (&const_offset))
   15230      8768397 :             return new_loc_descr (DW_OP_fbreg, const_offset, 0);
   15231              :           else
   15232              :             {
   15233              :               dw_loc_descr_ref ret = new_loc_descr (DW_OP_fbreg, 0, 0);
   15234              :               loc_descr_plus_const (&ret, offset);
   15235              :               return ret;
   15236              :             }
   15237              :         }
   15238              :     }
   15239              : 
   15240      5377114 :   regno = REGNO (reg);
   15241              : #ifdef LEAF_REG_REMAP
   15242              :   if (crtl->uses_only_leaf_regs)
   15243              :     {
   15244              :       int leaf_reg = LEAF_REG_REMAP (regno);
   15245              :       if (leaf_reg != -1)
   15246              :         regno = (unsigned) leaf_reg;
   15247              :     }
   15248              : #endif
   15249      5377114 :   regno = DWARF_FRAME_REGNUM (regno);
   15250              : 
   15251      5377114 :   HOST_WIDE_INT const_offset;
   15252        16268 :   if (!optimize && fde
   15253        16268 :       && (fde->drap_reg == regno || fde->vdrap_reg == regno)
   15254      5377114 :       && offset.is_constant (&const_offset))
   15255              :     {
   15256              :       /* Use cfa+offset to represent the location of arguments passed
   15257              :          on the stack when drap is used to align stack.
   15258              :          Only do this when not optimizing, for optimized code var-tracking
   15259              :          is supposed to track where the arguments live and the register
   15260              :          used as vdrap or drap in some spot might be used for something
   15261              :          else in other part of the routine.  */
   15262         3082 :       return new_loc_descr (DW_OP_fbreg, const_offset, 0);
   15263              :     }
   15264              : 
   15265      5374032 :   result = new_reg_loc_descr (regno, offset);
   15266              : 
   15267      5374032 :   if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
   15268            0 :     add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
   15269              : 
   15270      5374032 :   return result;
   15271              : }
   15272              : 
   15273              : /* Return true if this RTL expression describes a base+offset calculation.  */
   15274              : 
   15275              : static inline bool
   15276     12560685 : is_based_loc (const_rtx rtl)
   15277              : {
   15278     12560685 :   return (GET_CODE (rtl) == PLUS
   15279     12560685 :           && ((REG_P (XEXP (rtl, 0))
   15280     11020213 :                && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
   15281     11018242 :                && CONST_INT_P (XEXP (rtl, 1)))));
   15282              : }
   15283              : 
   15284              : /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
   15285              :    failed.  */
   15286              : 
   15287              : static dw_loc_descr_ref
   15288        19131 : tls_mem_loc_descriptor (rtx mem)
   15289              : {
   15290        19131 :   tree base;
   15291        19131 :   dw_loc_descr_ref loc_result;
   15292              : 
   15293        19131 :   if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
   15294              :     return NULL;
   15295              : 
   15296        17699 :   base = get_base_address (MEM_EXPR (mem));
   15297        17699 :   if (base == NULL
   15298        17699 :       || !VAR_P (base)
   15299        32797 :       || !DECL_THREAD_LOCAL_P (base))
   15300              :     return NULL;
   15301              : 
   15302            0 :   loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1, NULL);
   15303            0 :   if (loc_result == NULL)
   15304              :     return NULL;
   15305              : 
   15306            0 :   if (maybe_ne (MEM_OFFSET (mem), 0))
   15307            0 :     loc_descr_plus_const (&loc_result, MEM_OFFSET (mem));
   15308              : 
   15309              :   return loc_result;
   15310              : }
   15311              : 
   15312              : /* Output debug info about reason why we failed to expand expression as dwarf
   15313              :    expression.  */
   15314              : 
   15315              : static void
   15316      2975864 : expansion_failed (tree expr, rtx rtl, char const *reason)
   15317              : {
   15318      2975864 :   if (dump_file && (dump_flags & TDF_DETAILS))
   15319              :     {
   15320            0 :       fprintf (dump_file, "Failed to expand as dwarf: ");
   15321            0 :       if (expr)
   15322            0 :         print_generic_expr (dump_file, expr, dump_flags);
   15323            0 :       if (rtl)
   15324              :         {
   15325            0 :           fprintf (dump_file, "\n");
   15326            0 :           print_rtl (dump_file, rtl);
   15327              :         }
   15328            0 :       fprintf (dump_file, "\nReason: %s\n", reason);
   15329              :     }
   15330      2975864 : }
   15331              : 
   15332              : /* Helper function for const_ok_for_output.  */
   15333              : 
   15334              : static bool
   15335      1895454 : const_ok_for_output_1 (rtx rtl)
   15336              : {
   15337      1895454 :   if (targetm.const_not_ok_for_debug_p (rtl))
   15338              :     {
   15339           20 :       if (GET_CODE (rtl) != UNSPEC)
   15340              :         {
   15341            0 :           expansion_failed (NULL_TREE, rtl,
   15342              :                             "Expression rejected for debug by the backend.\n");
   15343            0 :           return false;
   15344              :         }
   15345              : 
   15346              :       /* If delegitimize_address couldn't do anything with the UNSPEC, and
   15347              :          the target hook doesn't explicitly allow it in debug info, assume
   15348              :          we can't express it in the debug info.  */
   15349              :       /* Don't complain about TLS UNSPECs, those are just too hard to
   15350              :          delegitimize.  Note this could be a non-decl SYMBOL_REF such as
   15351              :          one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
   15352              :          rather than DECL_THREAD_LOCAL_P is not just an optimization.  */
   15353           20 :       if (flag_checking
   15354           20 :           && (XVECLEN (rtl, 0) == 0
   15355           20 :               || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
   15356           20 :               || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl, 0, 0)) == TLS_MODEL_NONE))
   15357            0 :         inform (current_function_decl
   15358            0 :                 ? DECL_SOURCE_LOCATION (current_function_decl)
   15359              :                 : UNKNOWN_LOCATION,
   15360              : #if NUM_UNSPEC_VALUES > 0
   15361              :                 "non-delegitimized UNSPEC %s (%d) found in variable location",
   15362            0 :                 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
   15363              :                  ? unspec_strings[XINT (rtl, 1)] : "unknown"),
   15364              : #else
   15365              :                 "non-delegitimized UNSPEC %d found in variable location",
   15366              : #endif
   15367              :                 XINT (rtl, 1));
   15368           20 :       expansion_failed (NULL_TREE, rtl,
   15369              :                         "UNSPEC hasn't been delegitimized.\n");
   15370           20 :       return false;
   15371              :     }
   15372              : 
   15373      1895434 :   if (CONST_POLY_INT_P (rtl))
   15374              :     return false;
   15375              : 
   15376              :   /* FIXME: Refer to PR60655. It is possible for simplification
   15377              :      of rtl expressions in var tracking to produce such expressions.
   15378              :      We should really identify / validate expressions
   15379              :      enclosed in CONST that can be handled by assemblers on various
   15380              :      targets and only handle legitimate cases here.  */
   15381      1895434 :   switch (GET_CODE (rtl))
   15382              :     {
   15383      1689672 :     case SYMBOL_REF:
   15384      1689672 :       break;
   15385              :     case NOT:
   15386              :     case NEG:
   15387              :       return false;
   15388       113408 :     case PLUS:
   15389       113408 :       {
   15390              :         /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
   15391              :            operands.  */
   15392       113408 :         subrtx_var_iterator::array_type array;
   15393       113408 :         bool first = false;
   15394       113408 :         FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
   15395       113408 :           if (SYMBOL_REF_P (*iter)
   15396              :               || LABEL_P (*iter)
   15397              :               || GET_CODE (*iter) == UNSPEC)
   15398              :             {
   15399              :               first = true;
   15400              :               break;
   15401              :             }
   15402       113408 :         if (!first)
   15403              :           return true;
   15404       226816 :         FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
   15405       113408 :           if (SYMBOL_REF_P (*iter)
   15406              :               || LABEL_P (*iter)
   15407              :               || GET_CODE (*iter) == UNSPEC)
   15408            0 :             return false;
   15409       113408 :         return true;
   15410       113408 :       }
   15411            0 :     case MINUS:
   15412            0 :       {
   15413              :         /* Disallow negation of SYMBOL_REFs or UNSPECs when they
   15414              :            appear in the second operand of MINUS.  */
   15415            0 :         subrtx_var_iterator::array_type array;
   15416            0 :         FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
   15417            0 :           if (SYMBOL_REF_P (*iter)
   15418              :               || LABEL_P (*iter)
   15419              :               || GET_CODE (*iter) == UNSPEC)
   15420            0 :             return false;
   15421            0 :         return true;
   15422            0 :       }
   15423              :     default:
   15424              :       return true;
   15425              :     }
   15426              : 
   15427      1689672 :   if (CONSTANT_POOL_ADDRESS_P (rtl))
   15428              :     {
   15429            0 :       bool marked;
   15430            0 :       get_pool_constant_mark (rtl, &marked);
   15431              :       /* If all references to this pool constant were optimized away,
   15432              :          it was not output and thus we can't represent it.  */
   15433            0 :       if (!marked)
   15434              :         {
   15435            0 :           expansion_failed (NULL_TREE, rtl,
   15436              :                             "Constant was removed from constant pool.\n");
   15437            0 :           return false;
   15438              :         }
   15439              :     }
   15440              : 
   15441      1689672 :   if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
   15442              :     return false;
   15443              : 
   15444              :   /* Avoid references to external symbols in debug info, on several targets
   15445              :      the linker might even refuse to link when linking a shared library,
   15446              :      and in many other cases the relocations for .debug_info/.debug_loc are
   15447              :      dropped, so the address becomes zero anyway.  Hidden symbols, guaranteed
   15448              :      to be defined within the same shared library or executable are fine.  */
   15449      1681791 :   if (SYMBOL_REF_EXTERNAL_P (rtl))
   15450              :     {
   15451       160588 :       tree decl = SYMBOL_REF_DECL (rtl);
   15452              : 
   15453       160588 :       if (decl == NULL || !targetm.binds_local_p (decl))
   15454              :         {
   15455       153828 :           expansion_failed (NULL_TREE, rtl,
   15456              :                             "Symbol not defined in current TU.\n");
   15457       153828 :           return false;
   15458              :         }
   15459              :     }
   15460              : 
   15461              :   return true;
   15462              : }
   15463              : 
   15464              : /* Return true if constant RTL can be emitted in DW_OP_addr or
   15465              :    DW_AT_const_value.  TLS SYMBOL_REFs, external SYMBOL_REFs or
   15466              :    non-marked constant pool SYMBOL_REFs can't be referenced in it.  */
   15467              : 
   15468              : static bool
   15469      1694498 : const_ok_for_output (rtx rtl)
   15470              : {
   15471      1694498 :   if (GET_CODE (rtl) == SYMBOL_REF)
   15472      1575894 :     return const_ok_for_output_1 (rtl);
   15473              : 
   15474       118604 :   if (GET_CODE (rtl) == CONST)
   15475              :     {
   15476       113788 :       subrtx_var_iterator::array_type array;
   15477       411539 :       FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
   15478       319550 :         if (!const_ok_for_output_1 (*iter))
   15479        21799 :           return false;
   15480        91989 :       return true;
   15481       113788 :     }
   15482              : 
   15483              :   return true;
   15484              : }
   15485              : 
   15486              : /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
   15487              :    if possible, NULL otherwise.  */
   15488              : 
   15489              : static dw_die_ref
   15490       884947 : base_type_for_mode (machine_mode mode, bool unsignedp)
   15491              : {
   15492       884947 :   dw_die_ref type_die;
   15493       884947 :   tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
   15494              : 
   15495       884947 :   if (type == NULL)
   15496              :     return NULL;
   15497       883587 :   switch (TREE_CODE (type))
   15498              :     {
   15499       867709 :     case INTEGER_TYPE:
   15500       867709 :     case REAL_TYPE:
   15501       867709 :       break;
   15502              :     default:
   15503              :       return NULL;
   15504              :     }
   15505       867709 :   type_die = lookup_type_die (type);
   15506       867709 :   if (!type_die)
   15507          428 :     type_die = modified_type_die (type, TYPE_UNQUALIFIED, NULL_TREE,
   15508              :                                   false, comp_unit_die ());
   15509       867709 :   if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
   15510            0 :     return NULL;
   15511              :   return type_die;
   15512              : }
   15513              : 
   15514              : /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
   15515              :    type matching MODE, or, if MODE is narrower than or as wide as
   15516              :    DWARF2_ADDR_SIZE, untyped.  Return NULL if the conversion is not
   15517              :    possible.  */
   15518              : 
   15519              : static dw_loc_descr_ref
   15520         5945 : convert_descriptor_to_mode (scalar_int_mode mode, dw_loc_descr_ref op)
   15521              : {
   15522         5945 :   machine_mode outer_mode = mode;
   15523         5945 :   dw_die_ref type_die;
   15524         5945 :   dw_loc_descr_ref cvt;
   15525              : 
   15526        13236 :   if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
   15527              :     {
   15528         5653 :       add_loc_descr (&op, new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0));
   15529         5653 :       return op;
   15530              :     }
   15531          292 :   type_die = base_type_for_mode (outer_mode, 1);
   15532          292 :   if (type_die == NULL)
   15533              :     return NULL;
   15534          292 :   cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   15535          292 :   cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   15536          292 :   cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   15537          292 :   cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   15538          292 :   add_loc_descr (&op, cvt);
   15539          292 :   return op;
   15540              : }
   15541              : 
   15542              : /* Return location descriptor for comparison OP with operands OP0 and OP1.  */
   15543              : 
   15544              : static dw_loc_descr_ref
   15545       165704 : compare_loc_descriptor (enum dwarf_location_atom op, dw_loc_descr_ref op0,
   15546              :                         dw_loc_descr_ref op1)
   15547              : {
   15548       165704 :   dw_loc_descr_ref ret = op0;
   15549       165704 :   add_loc_descr (&ret, op1);
   15550       165704 :   add_loc_descr (&ret, new_loc_descr (op, 0, 0));
   15551       165704 :   if (STORE_FLAG_VALUE != 1)
   15552              :     {
   15553              :       add_loc_descr (&ret, int_loc_descriptor (STORE_FLAG_VALUE));
   15554              :       add_loc_descr (&ret, new_loc_descr (DW_OP_mul, 0, 0));
   15555              :     }
   15556       165704 :   return ret;
   15557              : }
   15558              : 
   15559              : /* Subroutine of scompare_loc_descriptor for the case in which we're
   15560              :    comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
   15561              :    and in which OP_MODE is bigger than DWARF2_ADDR_SIZE.  */
   15562              : 
   15563              : static dw_loc_descr_ref
   15564         1015 : scompare_loc_descriptor_wide (enum dwarf_location_atom op,
   15565              :                               scalar_int_mode op_mode,
   15566              :                               dw_loc_descr_ref op0, dw_loc_descr_ref op1)
   15567              : {
   15568         1015 :   dw_die_ref type_die = base_type_for_mode (op_mode, 0);
   15569         1015 :   dw_loc_descr_ref cvt;
   15570              : 
   15571         1015 :   if (type_die == NULL)
   15572              :     return NULL;
   15573         1015 :   cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   15574         1015 :   cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   15575         1015 :   cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   15576         1015 :   cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   15577         1015 :   add_loc_descr (&op0, cvt);
   15578         1015 :   cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   15579         1015 :   cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   15580         1015 :   cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   15581         1015 :   cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   15582         1015 :   add_loc_descr (&op1, cvt);
   15583         1015 :   return compare_loc_descriptor (op, op0, op1);
   15584              : }
   15585              : 
   15586              : /* Subroutine of scompare_loc_descriptor for the case in which we're
   15587              :    comparing two scalar integer operands OP0 and OP1 that have mode OP_MODE,
   15588              :    and in which OP_MODE is smaller than DWARF2_ADDR_SIZE.  */
   15589              : 
   15590              : static dw_loc_descr_ref
   15591        40333 : scompare_loc_descriptor_narrow (enum dwarf_location_atom op, rtx rtl,
   15592              :                                 scalar_int_mode op_mode,
   15593              :                                 dw_loc_descr_ref op0, dw_loc_descr_ref op1)
   15594              : {
   15595        40333 :   int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode)) * BITS_PER_UNIT;
   15596              :   /* For eq/ne, if the operands are known to be zero-extended,
   15597              :      there is no need to do the fancy shifting up.  */
   15598        40333 :   if (op == DW_OP_eq || op == DW_OP_ne)
   15599              :     {
   15600        37330 :       dw_loc_descr_ref last0, last1;
   15601       102078 :       for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
   15602              :         ;
   15603        46784 :       for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
   15604              :         ;
   15605              :       /* deref_size zero extends, and for constants we can check
   15606              :          whether they are zero extended or not.  */
   15607        37330 :       if (((last0->dw_loc_opc == DW_OP_deref_size
   15608        13304 :             && last0->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
   15609        30678 :            || (CONST_INT_P (XEXP (rtl, 0))
   15610          201 :                && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
   15611          201 :                   == (INTVAL (XEXP (rtl, 0)) & GET_MODE_MASK (op_mode))))
   15612        44055 :           && ((last1->dw_loc_opc == DW_OP_deref_size
   15613         1676 :                && last1->dw_loc_oprnd1.v.val_int <= GET_MODE_SIZE (op_mode))
   15614         5887 :               || (CONST_INT_P (XEXP (rtl, 1))
   15615         5082 :                   && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 1))
   15616         5082 :                      == (INTVAL (XEXP (rtl, 1)) & GET_MODE_MASK (op_mode)))))
   15617         5793 :         return compare_loc_descriptor (op, op0, op1);
   15618              : 
   15619              :       /* EQ/NE comparison against constant in narrower type than
   15620              :          DWARF2_ADDR_SIZE can be performed either as
   15621              :          DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
   15622              :          DW_OP_{eq,ne}
   15623              :          or
   15624              :          DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
   15625              :          DW_OP_{eq,ne}.  Pick whatever is shorter.  */
   15626        31537 :       if (CONST_INT_P (XEXP (rtl, 1))
   15627        27244 :           && GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT
   15628        58781 :           && (size_of_int_loc_descriptor (shift) + 1
   15629        27244 :               + size_of_int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift)
   15630        27244 :               >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode)) + 1
   15631        27244 :                  + size_of_int_loc_descriptor (INTVAL (XEXP (rtl, 1))
   15632        27244 :                                                & GET_MODE_MASK (op_mode))))
   15633              :         {
   15634        10572 :           add_loc_descr (&op0, int_loc_descriptor (GET_MODE_MASK (op_mode)));
   15635        10572 :           add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
   15636        21144 :           op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1))
   15637        10572 :                                     & GET_MODE_MASK (op_mode));
   15638        10572 :           return compare_loc_descriptor (op, op0, op1);
   15639              :         }
   15640              :     }
   15641        23968 :   add_loc_descr (&op0, int_loc_descriptor (shift));
   15642        23968 :   add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
   15643        23968 :   if (CONST_INT_P (XEXP (rtl, 1)))
   15644        18915 :     op1 = int_loc_descriptor (UINTVAL (XEXP (rtl, 1)) << shift);
   15645              :   else
   15646              :     {
   15647         5053 :       add_loc_descr (&op1, int_loc_descriptor (shift));
   15648        10106 :       add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
   15649              :     }
   15650        23968 :   return compare_loc_descriptor (op, op0, op1);
   15651              : }
   15652              : 
   15653              : /* Return location descriptor for signed comparison OP RTL.  */
   15654              : 
   15655              : static dw_loc_descr_ref
   15656       131638 : scompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
   15657              :                          machine_mode mem_mode)
   15658              : {
   15659       131638 :   machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
   15660       131638 :   dw_loc_descr_ref op0, op1;
   15661              : 
   15662       131638 :   if (op_mode == VOIDmode)
   15663          361 :     op_mode = GET_MODE (XEXP (rtl, 1));
   15664       131638 :   if (op_mode == VOIDmode)
   15665              :     return NULL;
   15666              : 
   15667       131638 :   scalar_int_mode int_op_mode;
   15668       131638 :   if (dwarf_strict
   15669            0 :       && dwarf_version < 5
   15670       131638 :       && (!is_a <scalar_int_mode> (op_mode, &int_op_mode)
   15671            0 :           || GET_MODE_SIZE (int_op_mode) > DWARF2_ADDR_SIZE))
   15672              :     return NULL;
   15673              : 
   15674       131638 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
   15675              :                             VAR_INIT_STATUS_INITIALIZED);
   15676       131638 :   op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
   15677              :                             VAR_INIT_STATUS_INITIALIZED);
   15678              : 
   15679       131638 :   if (op0 == NULL || op1 == NULL)
   15680              :     return NULL;
   15681              : 
   15682       119952 :   if (is_a <scalar_int_mode> (op_mode, &int_op_mode))
   15683              :     {
   15684       250713 :       if (GET_MODE_SIZE (int_op_mode) < DWARF2_ADDR_SIZE)
   15685        40333 :         return scompare_loc_descriptor_narrow (op, rtl, int_op_mode, op0, op1);
   15686              : 
   15687       167027 :       if (GET_MODE_SIZE (int_op_mode) > DWARF2_ADDR_SIZE)
   15688         1015 :         return scompare_loc_descriptor_wide (op, int_op_mode, op0, op1);
   15689              :     }
   15690        78604 :   return compare_loc_descriptor (op, op0, op1);
   15691              : }
   15692              : 
   15693              : /* Return location descriptor for unsigned comparison OP RTL.  */
   15694              : 
   15695              : static dw_loc_descr_ref
   15696        47901 : ucompare_loc_descriptor (enum dwarf_location_atom op, rtx rtl,
   15697              :                          machine_mode mem_mode)
   15698              : {
   15699        47901 :   dw_loc_descr_ref op0, op1;
   15700              : 
   15701        47901 :   machine_mode test_op_mode = GET_MODE (XEXP (rtl, 0));
   15702        47901 :   if (test_op_mode == VOIDmode)
   15703           98 :     test_op_mode = GET_MODE (XEXP (rtl, 1));
   15704              : 
   15705        47901 :   scalar_int_mode op_mode;
   15706        47901 :   if (!is_a <scalar_int_mode> (test_op_mode, &op_mode))
   15707              :     return NULL;
   15708              : 
   15709        46206 :   if (dwarf_strict
   15710            0 :       && dwarf_version < 5
   15711        46206 :       && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
   15712              :     return NULL;
   15713              : 
   15714        46206 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
   15715              :                             VAR_INIT_STATUS_INITIALIZED);
   15716        46206 :   op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
   15717              :                             VAR_INIT_STATUS_INITIALIZED);
   15718              : 
   15719        46206 :   if (op0 == NULL || op1 == NULL)
   15720              :     return NULL;
   15721              : 
   15722        97461 :   if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
   15723              :     {
   15724        10322 :       HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
   15725        10322 :       dw_loc_descr_ref last0, last1;
   15726        22935 :       for (last0 = op0; last0->dw_loc_next != NULL; last0 = last0->dw_loc_next)
   15727              :         ;
   15728        10609 :       for (last1 = op1; last1->dw_loc_next != NULL; last1 = last1->dw_loc_next)
   15729              :         ;
   15730        10322 :       if (CONST_INT_P (XEXP (rtl, 0)))
   15731            0 :         op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
   15732              :       /* deref_size zero extends, so no need to mask it again.  */
   15733        10322 :       else if (last0->dw_loc_opc != DW_OP_deref_size
   15734        13657 :                || last0->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
   15735              :         {
   15736         6987 :           add_loc_descr (&op0, int_loc_descriptor (mask));
   15737        13974 :           add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
   15738              :         }
   15739        10322 :       if (CONST_INT_P (XEXP (rtl, 1)))
   15740        10144 :         op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
   15741              :       /* deref_size zero extends, so no need to mask it again.  */
   15742          178 :       else if (last1->dw_loc_opc != DW_OP_deref_size
   15743          230 :                || last1->dw_loc_oprnd1.v.val_int > GET_MODE_SIZE (op_mode))
   15744              :         {
   15745          126 :           add_loc_descr (&op1, int_loc_descriptor (mask));
   15746          252 :           add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
   15747              :         }
   15748              :     }
   15749        76649 :   else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
   15750              :     {
   15751        34014 :       HOST_WIDE_INT bias = 1;
   15752        34014 :       bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
   15753        34014 :       add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
   15754        34014 :       if (CONST_INT_P (XEXP (rtl, 1)))
   15755        14157 :         op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
   15756        14157 :                                   + INTVAL (XEXP (rtl, 1)));
   15757              :       else
   15758        39714 :         add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
   15759              :                                             bias, 0));
   15760              :     }
   15761        45752 :   return compare_loc_descriptor (op, op0, op1);
   15762              : }
   15763              : 
   15764              : /* Return location descriptor for {U,S}{MIN,MAX}.  */
   15765              : 
   15766              : static dw_loc_descr_ref
   15767        56590 : minmax_loc_descriptor (rtx rtl, machine_mode mode,
   15768              :                        machine_mode mem_mode)
   15769              : {
   15770        56590 :   enum dwarf_location_atom op;
   15771        56590 :   dw_loc_descr_ref op0, op1, ret;
   15772        56590 :   dw_loc_descr_ref bra_node, drop_node;
   15773              : 
   15774        56590 :   scalar_int_mode int_mode;
   15775        56590 :   if (dwarf_strict
   15776            0 :       && dwarf_version < 5
   15777        56590 :       && (!is_a <scalar_int_mode> (mode, &int_mode)
   15778            0 :           || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE))
   15779              :     return NULL;
   15780              : 
   15781        56590 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   15782              :                             VAR_INIT_STATUS_INITIALIZED);
   15783        56590 :   op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
   15784              :                             VAR_INIT_STATUS_INITIALIZED);
   15785              : 
   15786        56590 :   if (op0 == NULL || op1 == NULL)
   15787              :     return NULL;
   15788              : 
   15789        56410 :   add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
   15790        56410 :   add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
   15791        56410 :   add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
   15792        56410 :   if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
   15793              :     {
   15794              :       /* Checked by the caller.  */
   15795        36600 :       int_mode = as_a <scalar_int_mode> (mode);
   15796        74248 :       if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
   15797              :         {
   15798          442 :           HOST_WIDE_INT mask = GET_MODE_MASK (int_mode);
   15799          442 :           add_loc_descr (&op0, int_loc_descriptor (mask));
   15800          442 :           add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
   15801          442 :           add_loc_descr (&op1, int_loc_descriptor (mask));
   15802          884 :           add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
   15803              :         }
   15804        73302 :       else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
   15805              :         {
   15806        36153 :           HOST_WIDE_INT bias = 1;
   15807        36153 :           bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
   15808        36153 :           add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
   15809        72306 :           add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
   15810              :         }
   15811              :     }
   15812        19810 :   else if (is_a <scalar_int_mode> (mode, &int_mode)
   15813        30632 :            && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
   15814              :     {
   15815         1193 :       int shift = (DWARF2_ADDR_SIZE - GET_MODE_SIZE (int_mode)) * BITS_PER_UNIT;
   15816         1193 :       add_loc_descr (&op0, int_loc_descriptor (shift));
   15817         1193 :       add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
   15818         1193 :       add_loc_descr (&op1, int_loc_descriptor (shift));
   15819         2386 :       add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
   15820              :     }
   15821        18617 :   else if (is_a <scalar_int_mode> (mode, &int_mode)
   15822        29439 :            && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
   15823              :     {
   15824           53 :       dw_die_ref type_die = base_type_for_mode (int_mode, 0);
   15825           53 :       dw_loc_descr_ref cvt;
   15826           53 :       if (type_die == NULL)
   15827              :         return NULL;
   15828           53 :       cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   15829           53 :       cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   15830           53 :       cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   15831           53 :       cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   15832           53 :       add_loc_descr (&op0, cvt);
   15833           53 :       cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   15834           53 :       cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   15835           53 :       cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   15836           53 :       cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   15837          106 :       add_loc_descr (&op1, cvt);
   15838              :     }
   15839              : 
   15840        56410 :   if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
   15841              :     op = DW_OP_lt;
   15842              :   else
   15843        56410 :     op = DW_OP_gt;
   15844        56410 :   ret = op0;
   15845        56410 :   add_loc_descr (&ret, op1);
   15846        56410 :   add_loc_descr (&ret, new_loc_descr (op, 0, 0));
   15847        56410 :   bra_node = new_loc_descr (DW_OP_bra, 0, 0);
   15848        56410 :   add_loc_descr (&ret, bra_node);
   15849        56410 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   15850        56410 :   drop_node = new_loc_descr (DW_OP_drop, 0, 0);
   15851        56410 :   add_loc_descr (&ret, drop_node);
   15852        56410 :   bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
   15853        56410 :   bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
   15854        56410 :   if ((GET_CODE (rtl) == SMIN || GET_CODE (rtl) == SMAX)
   15855        19810 :       && is_a <scalar_int_mode> (mode, &int_mode)
   15856        87042 :       && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
   15857           53 :     ret = convert_descriptor_to_mode (int_mode, ret);
   15858        56410 :   return ret;
   15859              : }
   15860              : 
   15861              : /* Helper function for mem_loc_descriptor.  Perform OP binary op,
   15862              :    but after converting arguments to type_die, afterwards
   15863              :    convert back to unsigned.  */
   15864              : 
   15865              : static dw_loc_descr_ref
   15866         4318 : typed_binop (enum dwarf_location_atom op, rtx rtl, dw_die_ref type_die,
   15867              :              scalar_int_mode mode, machine_mode mem_mode)
   15868              : {
   15869         4318 :   dw_loc_descr_ref cvt, op0, op1;
   15870              : 
   15871         4318 :   if (type_die == NULL)
   15872              :     return NULL;
   15873         4318 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   15874              :                             VAR_INIT_STATUS_INITIALIZED);
   15875         4318 :   op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
   15876              :                             VAR_INIT_STATUS_INITIALIZED);
   15877         4318 :   if (op0 == NULL || op1 == NULL)
   15878              :     return NULL;
   15879         4260 :   cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   15880         4260 :   cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   15881         4260 :   cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   15882         4260 :   cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   15883         4260 :   add_loc_descr (&op0, cvt);
   15884         4260 :   cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   15885         4260 :   cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   15886         4260 :   cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   15887         4260 :   cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   15888         4260 :   add_loc_descr (&op1, cvt);
   15889         4260 :   add_loc_descr (&op0, op1);
   15890         4260 :   add_loc_descr (&op0, new_loc_descr (op, 0, 0));
   15891         4260 :   return convert_descriptor_to_mode (mode, op0);
   15892              : }
   15893              : 
   15894              : /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
   15895              :    const0 is DW_OP_lit0 or corresponding typed constant,
   15896              :    const1 is DW_OP_lit1 or corresponding typed constant
   15897              :    and constMSB is constant with just the MSB bit set
   15898              :    for the mode):
   15899              :        DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
   15900              :    L1: const0 DW_OP_swap
   15901              :    L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
   15902              :        DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
   15903              :    L3: DW_OP_drop
   15904              :    L4: DW_OP_nop
   15905              : 
   15906              :    CTZ is similar:
   15907              :        DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
   15908              :    L1: const0 DW_OP_swap
   15909              :    L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
   15910              :        DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
   15911              :    L3: DW_OP_drop
   15912              :    L4: DW_OP_nop
   15913              : 
   15914              :    FFS is similar:
   15915              :        DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
   15916              :    L1: const1 DW_OP_swap
   15917              :    L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
   15918              :        DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
   15919              :    L3: DW_OP_drop
   15920              :    L4: DW_OP_nop  */
   15921              : 
   15922              : static dw_loc_descr_ref
   15923         4153 : clz_loc_descriptor (rtx rtl, scalar_int_mode mode,
   15924              :                     machine_mode mem_mode)
   15925              : {
   15926         4153 :   dw_loc_descr_ref op0, ret, tmp;
   15927         4153 :   HOST_WIDE_INT valv;
   15928         4153 :   dw_loc_descr_ref l1jump, l1label;
   15929         4153 :   dw_loc_descr_ref l2jump, l2label;
   15930         4153 :   dw_loc_descr_ref l3jump, l3label;
   15931         4153 :   dw_loc_descr_ref l4jump, l4label;
   15932         4153 :   rtx msb;
   15933              : 
   15934         4153 :   if (GET_MODE (XEXP (rtl, 0)) != mode)
   15935              :     return NULL;
   15936              : 
   15937         4153 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   15938              :                             VAR_INIT_STATUS_INITIALIZED);
   15939         4153 :   if (op0 == NULL)
   15940              :     return NULL;
   15941         4133 :   ret = op0;
   15942         4133 :   if (GET_CODE (rtl) == CLZ)
   15943              :     {
   15944         6980 :       if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, valv))
   15945         6980 :         valv = GET_MODE_BITSIZE (mode);
   15946              :     }
   15947          643 :   else if (GET_CODE (rtl) == FFS)
   15948              :     valv = 0;
   15949         1286 :   else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, valv))
   15950         1286 :     valv = GET_MODE_BITSIZE (mode);
   15951         4133 :   add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
   15952         4133 :   l1jump = new_loc_descr (DW_OP_bra, 0, 0);
   15953         4133 :   add_loc_descr (&ret, l1jump);
   15954         4133 :   add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
   15955         4133 :   tmp = mem_loc_descriptor (GEN_INT (valv), mode, mem_mode,
   15956              :                             VAR_INIT_STATUS_INITIALIZED);
   15957         4133 :   if (tmp == NULL)
   15958              :     return NULL;
   15959         4133 :   add_loc_descr (&ret, tmp);
   15960         4133 :   l4jump = new_loc_descr (DW_OP_skip, 0, 0);
   15961         4133 :   add_loc_descr (&ret, l4jump);
   15962         4133 :   l1label = mem_loc_descriptor (GET_CODE (rtl) == FFS
   15963              :                                 ? const1_rtx : const0_rtx,
   15964              :                                 mode, mem_mode,
   15965              :                                 VAR_INIT_STATUS_INITIALIZED);
   15966         4133 :   if (l1label == NULL)
   15967              :     return NULL;
   15968         4133 :   add_loc_descr (&ret, l1label);
   15969         4133 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   15970         4133 :   l2label = new_loc_descr (DW_OP_dup, 0, 0);
   15971         4133 :   add_loc_descr (&ret, l2label);
   15972         4133 :   if (GET_CODE (rtl) != CLZ)
   15973          643 :     msb = const1_rtx;
   15974         6980 :   else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
   15975         6980 :     msb = GEN_INT (HOST_WIDE_INT_1U
   15976              :                    << (GET_MODE_BITSIZE (mode) - 1));
   15977              :   else
   15978            0 :     msb = immed_wide_int_const
   15979            0 :       (wi::set_bit_in_zero (GET_MODE_PRECISION (mode) - 1,
   15980            0 :                             GET_MODE_PRECISION (mode)), mode);
   15981         4133 :   if (GET_CODE (msb) == CONST_INT && INTVAL (msb) < 0)
   15982         1825 :     tmp = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
   15983              :                          ? DW_OP_const4u : HOST_BITS_PER_WIDE_INT == 64
   15984              :                          ? DW_OP_const8u : DW_OP_constu, INTVAL (msb), 0);
   15985              :   else
   15986         2308 :     tmp = mem_loc_descriptor (msb, mode, mem_mode,
   15987              :                               VAR_INIT_STATUS_INITIALIZED);
   15988         4133 :   if (tmp == NULL)
   15989              :     return NULL;
   15990         4133 :   add_loc_descr (&ret, tmp);
   15991         4133 :   add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
   15992         4133 :   l3jump = new_loc_descr (DW_OP_bra, 0, 0);
   15993         4133 :   add_loc_descr (&ret, l3jump);
   15994         4133 :   tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
   15995              :                             VAR_INIT_STATUS_INITIALIZED);
   15996         4133 :   if (tmp == NULL)
   15997              :     return NULL;
   15998         4133 :   add_loc_descr (&ret, tmp);
   15999         4776 :   add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == CLZ
   16000              :                                       ? DW_OP_shl : DW_OP_shr, 0, 0));
   16001         4133 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16002         4133 :   add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, 1, 0));
   16003         4133 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16004         4133 :   l2jump = new_loc_descr (DW_OP_skip, 0, 0);
   16005         4133 :   add_loc_descr (&ret, l2jump);
   16006         4133 :   l3label = new_loc_descr (DW_OP_drop, 0, 0);
   16007         4133 :   add_loc_descr (&ret, l3label);
   16008         4133 :   l4label = new_loc_descr (DW_OP_nop, 0, 0);
   16009         4133 :   add_loc_descr (&ret, l4label);
   16010         4133 :   l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16011         4133 :   l1jump->dw_loc_oprnd1.v.val_loc = l1label;
   16012         4133 :   l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16013         4133 :   l2jump->dw_loc_oprnd1.v.val_loc = l2label;
   16014         4133 :   l3jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16015         4133 :   l3jump->dw_loc_oprnd1.v.val_loc = l3label;
   16016         4133 :   l4jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16017         4133 :   l4jump->dw_loc_oprnd1.v.val_loc = l4label;
   16018         4133 :   return ret;
   16019              : }
   16020              : 
   16021              : /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
   16022              :    const1 is DW_OP_lit1 or corresponding typed constant):
   16023              :        const0 DW_OP_swap
   16024              :    L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
   16025              :        DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
   16026              :    L2: DW_OP_drop
   16027              : 
   16028              :    PARITY is similar:
   16029              :    L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
   16030              :        DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
   16031              :    L2: DW_OP_drop  */
   16032              : 
   16033              : static dw_loc_descr_ref
   16034            0 : popcount_loc_descriptor (rtx rtl, scalar_int_mode mode,
   16035              :                          machine_mode mem_mode)
   16036              : {
   16037            0 :   dw_loc_descr_ref op0, ret, tmp;
   16038            0 :   dw_loc_descr_ref l1jump, l1label;
   16039            0 :   dw_loc_descr_ref l2jump, l2label;
   16040              : 
   16041            0 :   if (GET_MODE (XEXP (rtl, 0)) != mode)
   16042              :     return NULL;
   16043              : 
   16044            0 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   16045              :                             VAR_INIT_STATUS_INITIALIZED);
   16046            0 :   if (op0 == NULL)
   16047              :     return NULL;
   16048            0 :   ret = op0;
   16049            0 :   tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
   16050              :                             VAR_INIT_STATUS_INITIALIZED);
   16051            0 :   if (tmp == NULL)
   16052              :     return NULL;
   16053            0 :   add_loc_descr (&ret, tmp);
   16054            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16055            0 :   l1label = new_loc_descr (DW_OP_dup, 0, 0);
   16056            0 :   add_loc_descr (&ret, l1label);
   16057            0 :   l2jump = new_loc_descr (DW_OP_bra, 0, 0);
   16058            0 :   add_loc_descr (&ret, l2jump);
   16059            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
   16060            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
   16061            0 :   tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
   16062              :                             VAR_INIT_STATUS_INITIALIZED);
   16063            0 :   if (tmp == NULL)
   16064              :     return NULL;
   16065            0 :   add_loc_descr (&ret, tmp);
   16066            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
   16067            0 :   add_loc_descr (&ret, new_loc_descr (GET_CODE (rtl) == POPCOUNT
   16068              :                                       ? DW_OP_plus : DW_OP_xor, 0, 0));
   16069            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16070            0 :   tmp = mem_loc_descriptor (const1_rtx, mode, mem_mode,
   16071              :                             VAR_INIT_STATUS_INITIALIZED);
   16072            0 :   add_loc_descr (&ret, tmp);
   16073            0 :   add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
   16074            0 :   l1jump = new_loc_descr (DW_OP_skip, 0, 0);
   16075            0 :   add_loc_descr (&ret, l1jump);
   16076            0 :   l2label = new_loc_descr (DW_OP_drop, 0, 0);
   16077            0 :   add_loc_descr (&ret, l2label);
   16078            0 :   l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16079            0 :   l1jump->dw_loc_oprnd1.v.val_loc = l1label;
   16080            0 :   l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16081            0 :   l2jump->dw_loc_oprnd1.v.val_loc = l2label;
   16082            0 :   return ret;
   16083              : }
   16084              : 
   16085              : /* BSWAP (constS is initial shift count, either 56 or 24):
   16086              :        constS const0
   16087              :    L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
   16088              :        const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
   16089              :        DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
   16090              :        DW_OP_minus DW_OP_swap DW_OP_skip <L1>
   16091              :    L2: DW_OP_drop DW_OP_swap DW_OP_drop  */
   16092              : 
   16093              : static dw_loc_descr_ref
   16094          248 : bswap_loc_descriptor (rtx rtl, scalar_int_mode mode,
   16095              :                       machine_mode mem_mode)
   16096              : {
   16097          248 :   dw_loc_descr_ref op0, ret, tmp;
   16098          248 :   dw_loc_descr_ref l1jump, l1label;
   16099          248 :   dw_loc_descr_ref l2jump, l2label;
   16100              : 
   16101          248 :   if (BITS_PER_UNIT != 8
   16102          217 :       || (GET_MODE_BITSIZE (mode) != 32
   16103          465 :           && GET_MODE_BITSIZE (mode) != 64))
   16104              :     return NULL;
   16105              : 
   16106           72 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   16107              :                             VAR_INIT_STATUS_INITIALIZED);
   16108           72 :   if (op0 == NULL)
   16109              :     return NULL;
   16110              : 
   16111           72 :   ret = op0;
   16112          144 :   tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
   16113              :                             mode, mem_mode,
   16114              :                             VAR_INIT_STATUS_INITIALIZED);
   16115           72 :   if (tmp == NULL)
   16116              :     return NULL;
   16117           72 :   add_loc_descr (&ret, tmp);
   16118           72 :   tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
   16119              :                             VAR_INIT_STATUS_INITIALIZED);
   16120           72 :   if (tmp == NULL)
   16121              :     return NULL;
   16122           72 :   add_loc_descr (&ret, tmp);
   16123           72 :   l1label = new_loc_descr (DW_OP_pick, 2, 0);
   16124           72 :   add_loc_descr (&ret, l1label);
   16125          144 :   tmp = mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode) - 8),
   16126              :                             mode, mem_mode,
   16127              :                             VAR_INIT_STATUS_INITIALIZED);
   16128           72 :   add_loc_descr (&ret, tmp);
   16129           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 3, 0));
   16130           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
   16131           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
   16132           72 :   tmp = mem_loc_descriptor (GEN_INT (255), mode, mem_mode,
   16133              :                             VAR_INIT_STATUS_INITIALIZED);
   16134           72 :   if (tmp == NULL)
   16135              :     return NULL;
   16136           72 :   add_loc_descr (&ret, tmp);
   16137           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_and, 0, 0));
   16138           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_pick, 2, 0));
   16139           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
   16140           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
   16141           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16142           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_dup, 0, 0));
   16143           72 :   tmp = mem_loc_descriptor (const0_rtx, mode, mem_mode,
   16144              :                             VAR_INIT_STATUS_INITIALIZED);
   16145           72 :   add_loc_descr (&ret, tmp);
   16146           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_eq, 0, 0));
   16147           72 :   l2jump = new_loc_descr (DW_OP_bra, 0, 0);
   16148           72 :   add_loc_descr (&ret, l2jump);
   16149           72 :   tmp = mem_loc_descriptor (GEN_INT (8), mode, mem_mode,
   16150              :                             VAR_INIT_STATUS_INITIALIZED);
   16151           72 :   add_loc_descr (&ret, tmp);
   16152           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_minus, 0, 0));
   16153           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16154           72 :   l1jump = new_loc_descr (DW_OP_skip, 0, 0);
   16155           72 :   add_loc_descr (&ret, l1jump);
   16156           72 :   l2label = new_loc_descr (DW_OP_drop, 0, 0);
   16157           72 :   add_loc_descr (&ret, l2label);
   16158           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16159           72 :   add_loc_descr (&ret, new_loc_descr (DW_OP_drop, 0, 0));
   16160           72 :   l1jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16161           72 :   l1jump->dw_loc_oprnd1.v.val_loc = l1label;
   16162           72 :   l2jump->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16163           72 :   l2jump->dw_loc_oprnd1.v.val_loc = l2label;
   16164           72 :   return ret;
   16165              : }
   16166              : 
   16167              : /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
   16168              :    DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
   16169              :    [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
   16170              :    DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
   16171              : 
   16172              :    ROTATERT is similar:
   16173              :    DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
   16174              :    DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
   16175              :    [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or  */
   16176              : 
   16177              : static dw_loc_descr_ref
   16178         2291 : rotate_loc_descriptor (rtx rtl, scalar_int_mode mode,
   16179              :                        machine_mode mem_mode)
   16180              : {
   16181         2291 :   rtx rtlop1 = XEXP (rtl, 1);
   16182         2291 :   dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL };
   16183         2291 :   int i;
   16184              : 
   16185         2291 :   if (is_narrower_int_mode (GET_MODE (rtlop1), mode))
   16186           51 :     rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1);
   16187         2291 :   op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   16188              :                             VAR_INIT_STATUS_INITIALIZED);
   16189         2291 :   op1 = mem_loc_descriptor (rtlop1, mode, mem_mode,
   16190              :                             VAR_INIT_STATUS_INITIALIZED);
   16191         2291 :   if (op0 == NULL || op1 == NULL)
   16192              :     return NULL;
   16193         5581 :   if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
   16194         3306 :     for (i = 0; i < 2; i++)
   16195              :       {
   16196         4408 :         if (GET_MODE_BITSIZE (mode) < HOST_BITS_PER_WIDE_INT)
   16197         2204 :           mask[i] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode)),
   16198              :                                         mode, mem_mode,
   16199              :                                         VAR_INIT_STATUS_INITIALIZED);
   16200            0 :         else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
   16201            0 :           mask[i] = new_loc_descr (HOST_BITS_PER_WIDE_INT == 32
   16202              :                                    ? DW_OP_const4u
   16203              :                                    : HOST_BITS_PER_WIDE_INT == 64
   16204              :                                    ? DW_OP_const8u : DW_OP_constu,
   16205            0 :                                    GET_MODE_MASK (mode), 0);
   16206              :         else
   16207            0 :           mask[i] = NULL;
   16208         2204 :         if (mask[i] == NULL)
   16209              :           return NULL;
   16210         4408 :         add_loc_descr (&mask[i], new_loc_descr (DW_OP_and, 0, 0));
   16211              :       }
   16212         2288 :   ret = op0;
   16213         2288 :   add_loc_descr (&ret, op1);
   16214         2288 :   add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
   16215         2288 :   add_loc_descr (&ret, new_loc_descr (DW_OP_over, 0, 0));
   16216         2288 :   if (GET_CODE (rtl) == ROTATERT)
   16217              :     {
   16218          191 :       add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
   16219          573 :       add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
   16220          191 :                                           GET_MODE_BITSIZE (mode), 0));
   16221              :     }
   16222         2288 :   add_loc_descr (&ret, new_loc_descr (DW_OP_shl, 0, 0));
   16223         2288 :   if (mask[0] != NULL)
   16224         2204 :     add_loc_descr (&ret, mask[0]);
   16225         2288 :   add_loc_descr (&ret, new_loc_descr (DW_OP_rot, 0, 0));
   16226         2288 :   if (mask[1] != NULL)
   16227              :     {
   16228         1102 :       add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16229         1102 :       add_loc_descr (&ret, mask[1]);
   16230         2204 :       add_loc_descr (&ret, new_loc_descr (DW_OP_swap, 0, 0));
   16231              :     }
   16232         2288 :   if (GET_CODE (rtl) == ROTATE)
   16233              :     {
   16234         2097 :       add_loc_descr (&ret, new_loc_descr (DW_OP_neg, 0, 0));
   16235         6291 :       add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst,
   16236         2097 :                                           GET_MODE_BITSIZE (mode), 0));
   16237              :     }
   16238         2288 :   add_loc_descr (&ret, new_loc_descr (DW_OP_shr, 0, 0));
   16239         2288 :   add_loc_descr (&ret, new_loc_descr (DW_OP_or, 0, 0));
   16240         2288 :   return ret;
   16241              : }
   16242              : 
   16243              : /* Helper function for mem_loc_descriptor.  Return DW_OP_GNU_parameter_ref
   16244              :    for DEBUG_PARAMETER_REF RTL.  */
   16245              : 
   16246              : static dw_loc_descr_ref
   16247        32588 : parameter_ref_descriptor (rtx rtl)
   16248              : {
   16249        32588 :   dw_loc_descr_ref ret;
   16250        32588 :   dw_die_ref ref;
   16251              : 
   16252        32588 :   if (dwarf_strict)
   16253              :     return NULL;
   16254        32588 :   gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl)) == PARM_DECL);
   16255              :   /* With LTO during LTRANS we get the late DIE that refers to the early
   16256              :      DIE, thus we add another indirection here.  This seems to confuse
   16257              :      gdb enough to make gcc.dg/guality/pr68860-1.c FAIL with LTO.  */
   16258        32588 :   ref = lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl));
   16259        32588 :   ret = new_loc_descr (DW_OP_GNU_parameter_ref, 0, 0);
   16260        32588 :   if (ref)
   16261              :     {
   16262        32588 :       ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   16263        32588 :       ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
   16264        32588 :       ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
   16265              :     }
   16266              :   else
   16267              :     {
   16268            0 :       ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
   16269            0 :       ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_PARAMETER_REF_DECL (rtl);
   16270              :     }
   16271              :   return ret;
   16272              : }
   16273              : 
   16274              : /* The following routine converts the RTL for a variable or parameter
   16275              :    (resident in memory) into an equivalent Dwarf representation of a
   16276              :    mechanism for getting the address of that same variable onto the top of a
   16277              :    hypothetical "address evaluation" stack.
   16278              : 
   16279              :    When creating memory location descriptors, we are effectively transforming
   16280              :    the RTL for a memory-resident object into its Dwarf postfix expression
   16281              :    equivalent.  This routine recursively descends an RTL tree, turning
   16282              :    it into Dwarf postfix code as it goes.
   16283              : 
   16284              :    MODE is the mode that should be assumed for the rtl if it is VOIDmode.
   16285              : 
   16286              :    MEM_MODE is the mode of the memory reference, needed to handle some
   16287              :    autoincrement addressing modes.
   16288              : 
   16289              :    Return 0 if we can't represent the location.  */
   16290              : 
   16291              : dw_loc_descr_ref
   16292     27680738 : mem_loc_descriptor (rtx rtl, machine_mode mode,
   16293              :                     machine_mode mem_mode,
   16294              :                     enum var_init_status initialized)
   16295              : {
   16296     27680738 :   dw_loc_descr_ref mem_loc_result = NULL;
   16297     27680738 :   enum dwarf_location_atom op;
   16298     27680738 :   dw_loc_descr_ref op0, op1;
   16299     27680738 :   rtx inner = NULL_RTX;
   16300              : 
   16301     27680738 :   if (mode == VOIDmode)
   16302          379 :     mode = GET_MODE (rtl);
   16303              : 
   16304              :   /* Note that for a dynamically sized array, the location we will generate a
   16305              :      description of here will be the lowest numbered location which is
   16306              :      actually within the array.  That's *not* necessarily the same as the
   16307              :      zeroth element of the array.  */
   16308              : 
   16309     27680738 :   rtl = targetm.delegitimize_address (rtl);
   16310              : 
   16311     27680738 :   if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
   16312              :     return NULL;
   16313              : 
   16314     27680738 :   scalar_int_mode int_mode = BImode, inner_mode, op1_mode;
   16315     27680738 :   switch (GET_CODE (rtl))
   16316              :     {
   16317            0 :     case POST_INC:
   16318            0 :     case POST_DEC:
   16319            0 :     case POST_MODIFY:
   16320            0 :       return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
   16321              : 
   16322       204131 :     case SUBREG:
   16323              :       /* The case of a subreg may arise when we have a local (register)
   16324              :          variable or a formal (register) parameter which doesn't quite fill
   16325              :          up an entire register.  For now, just assume that it is
   16326              :          legitimate to make the Dwarf info refer to the whole register which
   16327              :          contains the given subreg.  */
   16328       204131 :       if (!subreg_lowpart_p (rtl))
   16329              :         break;
   16330       192038 :       inner = SUBREG_REG (rtl);
   16331              :       /* FALLTHRU */
   16332       192038 :     case TRUNCATE:
   16333       192038 :       if (inner == NULL_RTX)
   16334          322 :         inner = XEXP (rtl, 0);
   16335       192360 :       if (is_a <scalar_int_mode> (mode, &int_mode)
   16336       191570 :           && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
   16337       213288 :           && (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
   16338              : #ifdef POINTERS_EXTEND_UNSIGNED
   16339           86 :               || (int_mode == Pmode && mem_mode != VOIDmode)
   16340              : #endif
   16341              :              )
   16342       405562 :           && GET_MODE_SIZE (inner_mode) <= DWARF2_ADDR_SIZE)
   16343              :         {
   16344       161484 :           mem_loc_result = mem_loc_descriptor (inner,
   16345              :                                                inner_mode,
   16346              :                                                mem_mode, initialized);
   16347       161484 :           break;
   16348              :         }
   16349        30876 :       if (dwarf_strict && dwarf_version < 5)
   16350              :         break;
   16351        30876 :       if (is_a <scalar_int_mode> (mode, &int_mode)
   16352        30086 :           && is_a <scalar_int_mode> (GET_MODE (inner), &inner_mode)
   16353        88458 :           ? GET_MODE_SIZE (int_mode) <= GET_MODE_SIZE (inner_mode)
   16354        35046 :           : known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
   16355              :         {
   16356        30643 :           dw_die_ref type_die;
   16357        30643 :           dw_loc_descr_ref cvt;
   16358              : 
   16359        61286 :           mem_loc_result = mem_loc_descriptor (inner,
   16360        30643 :                                                GET_MODE (inner),
   16361              :                                                mem_mode, initialized);
   16362        30643 :           if (mem_loc_result == NULL)
   16363              :             break;
   16364        22850 :           type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
   16365        22850 :           if (type_die == NULL)
   16366              :             {
   16367            4 :               mem_loc_result = NULL;
   16368            4 :               break;
   16369              :             }
   16370        68538 :           if (maybe_ne (GET_MODE_SIZE (mode), GET_MODE_SIZE (GET_MODE (inner))))
   16371        21190 :             cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   16372              :           else
   16373         1656 :             cvt = new_loc_descr (dwarf_OP (DW_OP_reinterpret), 0, 0);
   16374        22846 :           cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   16375        22846 :           cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   16376        22846 :           cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   16377        22846 :           add_loc_descr (&mem_loc_result, cvt);
   16378        22846 :           if (is_a <scalar_int_mode> (mode, &int_mode)
   16379        66805 :               && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
   16380              :             {
   16381              :               /* Convert it to untyped afterwards.  */
   16382        21992 :               cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   16383        21992 :               add_loc_descr (&mem_loc_result, cvt);
   16384              :             }
   16385              :         }
   16386              :       break;
   16387              : 
   16388      3475993 :     case REG:
   16389      3475993 :       if (!is_a <scalar_int_mode> (mode, &int_mode)
   16390      7275462 :           || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
   16391        45447 :               && rtl != arg_pointer_rtx
   16392        45445 :               && rtl != frame_pointer_rtx
   16393              : #ifdef POINTERS_EXTEND_UNSIGNED
   16394        88749 :               && (int_mode != Pmode || mem_mode == VOIDmode)
   16395              : #endif
   16396              :               ))
   16397              :         {
   16398       121395 :           dw_die_ref type_die;
   16399       121395 :           unsigned int debugger_regnum;
   16400              : 
   16401       121395 :           if (dwarf_strict && dwarf_version < 5)
   16402              :             break;
   16403       121395 :           if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
   16404              :             break;
   16405       121395 :           type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
   16406       121395 :           if (type_die == NULL)
   16407              :             break;
   16408              : 
   16409       108919 :           debugger_regnum = debugger_reg_number (rtl);
   16410       108919 :           if (debugger_regnum == IGNORED_DWARF_REGNUM)
   16411              :             break;
   16412       108919 :           mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_regval_type),
   16413              :                                           debugger_regnum, 0);
   16414       108919 :           mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
   16415       108919 :           mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
   16416       108919 :           mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
   16417       108919 :           break;
   16418              :         }
   16419              :       /* Whenever a register number forms a part of the description of the
   16420              :          method for calculating the (dynamic) address of a memory resident
   16421              :          object, DWARF rules require the register number be referred to as
   16422              :          a "base register".  This distinction is not based in any way upon
   16423              :          what category of register the hardware believes the given register
   16424              :          belongs to.  This is strictly DWARF terminology we're dealing with
   16425              :          here. Note that in cases where the location of a memory-resident
   16426              :          data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
   16427              :          OP_CONST (0)) the actual DWARF location descriptor that we generate
   16428              :          may just be OP_BASEREG (basereg).  This may look deceptively like
   16429              :          the object in question was allocated to a register (rather than in
   16430              :          memory) so DWARF consumers need to be aware of the subtle
   16431              :          distinction between OP_REG and OP_BASEREG.  */
   16432      3354598 :       if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
   16433      3352599 :         mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
   16434          103 :       else if (stack_realign_drap
   16435            0 :                && crtl->drap_reg
   16436            0 :                && crtl->args.internal_arg_pointer == rtl
   16437         1999 :                && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
   16438              :         {
   16439              :           /* If RTL is internal_arg_pointer, which has been optimized
   16440              :              out, use DRAP instead.  */
   16441            0 :           mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
   16442              :                                             VAR_INIT_STATUS_INITIALIZED);
   16443              :         }
   16444              :       break;
   16445              : 
   16446       285679 :     case SIGN_EXTEND:
   16447       285679 :     case ZERO_EXTEND:
   16448       285679 :       if (!is_a <scalar_int_mode> (mode, &int_mode)
   16449       285679 :           || !is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &inner_mode))
   16450              :         break;
   16451       285601 :       op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
   16452              :                                 mem_mode, VAR_INIT_STATUS_INITIALIZED);
   16453       285601 :       if (op0 == 0)
   16454              :         break;
   16455       281011 :       else if (GET_CODE (rtl) == ZERO_EXTEND
   16456       309903 :                && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
   16457       281011 :                && GET_MODE_BITSIZE (inner_mode) < HOST_BITS_PER_WIDE_INT
   16458              :                /* If DW_OP_const{1,2,4}u won't be used, it is shorter
   16459              :                   to expand zero extend as two shifts instead of
   16460              :                   masking.  */
   16461       441380 :                && GET_MODE_SIZE (inner_mode) <= 4)
   16462              :         {
   16463       160369 :           mem_loc_result = op0;
   16464       160369 :           add_loc_descr (&mem_loc_result,
   16465       160369 :                          int_loc_descriptor (GET_MODE_MASK (inner_mode)));
   16466       160369 :           add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_and, 0, 0));
   16467              :         }
   16468       314433 :       else if (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE)
   16469              :         {
   16470        47818 :           int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (inner_mode);
   16471        47818 :           shift *= BITS_PER_UNIT;
   16472        47818 :           if (GET_CODE (rtl) == SIGN_EXTEND)
   16473              :             op = DW_OP_shra;
   16474              :           else
   16475            0 :             op = DW_OP_shr;
   16476        47818 :           mem_loc_result = op0;
   16477        47818 :           add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
   16478        47818 :           add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
   16479        47818 :           add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
   16480        47818 :           add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
   16481              :         }
   16482        72824 :       else if (!dwarf_strict || dwarf_version >= 5)
   16483              :         {
   16484        72824 :           dw_die_ref type_die1, type_die2;
   16485        72824 :           dw_loc_descr_ref cvt;
   16486              : 
   16487        72824 :           type_die1 = base_type_for_mode (inner_mode,
   16488              :                                           GET_CODE (rtl) == ZERO_EXTEND);
   16489        72824 :           if (type_die1 == NULL)
   16490              :             break;
   16491        72824 :           type_die2 = base_type_for_mode (int_mode, 1);
   16492        72824 :           if (type_die2 == NULL)
   16493              :             break;
   16494        72824 :           mem_loc_result = op0;
   16495        72824 :           cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   16496        72824 :           cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   16497        72824 :           cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
   16498        72824 :           cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   16499        72824 :           add_loc_descr (&mem_loc_result, cvt);
   16500        72824 :           cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   16501        72824 :           cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   16502        72824 :           cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
   16503        72824 :           cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   16504        72824 :           add_loc_descr (&mem_loc_result, cvt);
   16505              :         }
   16506              :       break;
   16507              : 
   16508      1854052 :     case MEM:
   16509      1854052 :       {
   16510      1854052 :         rtx new_rtl = avoid_constant_pool_reference (rtl);
   16511      1854052 :         if (new_rtl != rtl)
   16512              :           {
   16513            0 :             mem_loc_result = mem_loc_descriptor (new_rtl, mode, mem_mode,
   16514              :                                                  initialized);
   16515            0 :             if (mem_loc_result != NULL)
   16516              :               return mem_loc_result;
   16517              :           }
   16518              :       }
   16519      1854052 :       mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
   16520      1854052 :                                            get_address_mode (rtl), mode,
   16521              :                                            VAR_INIT_STATUS_INITIALIZED);
   16522      1854052 :       if (mem_loc_result == NULL)
   16523         7667 :         mem_loc_result = tls_mem_loc_descriptor (rtl);
   16524      1854052 :       if (mem_loc_result != NULL)
   16525              :         {
   16526      1846385 :           if (!is_a <scalar_int_mode> (mode, &int_mode)
   16527      4059112 :               || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
   16528              :             {
   16529        80432 :               dw_die_ref type_die;
   16530        80432 :               dw_loc_descr_ref deref;
   16531        80432 :               HOST_WIDE_INT size;
   16532              : 
   16533        80432 :               if (dwarf_strict && dwarf_version < 5)
   16534         4758 :                 return NULL;
   16535       160864 :               if (!GET_MODE_SIZE (mode).is_constant (&size))
   16536              :                 return NULL;
   16537        80432 :               type_die
   16538        80432 :                 = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
   16539        80432 :               if (type_die == NULL)
   16540              :                 return NULL;
   16541        75674 :               deref = new_loc_descr (dwarf_OP (DW_OP_deref_type), size, 0);
   16542        75674 :               deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
   16543        75674 :               deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
   16544        75674 :               deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
   16545        75674 :               add_loc_descr (&mem_loc_result, deref);
   16546              :             }
   16547      3888474 :           else if (GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE)
   16548      1555694 :             add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
   16549              :           else
   16550       420518 :             add_loc_descr (&mem_loc_result,
   16551              :                            new_loc_descr (DW_OP_deref_size,
   16552       210259 :                                           GET_MODE_SIZE (int_mode), 0));
   16553              :         }
   16554              :       break;
   16555              : 
   16556            0 :     case LO_SUM:
   16557            0 :       return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
   16558              : 
   16559      1136453 :     case LABEL_REF:
   16560              :       /* Some ports can transform a symbol ref into a label ref, because
   16561              :          the symbol ref is too far away and has to be dumped into a constant
   16562              :          pool.  */
   16563      1136453 :     case CONST:
   16564      1136453 :     case SYMBOL_REF:
   16565      1136453 :     case UNSPEC:
   16566      1136453 :       if (!is_a <scalar_int_mode> (mode, &int_mode)
   16567      2328404 :           || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
   16568              : #ifdef POINTERS_EXTEND_UNSIGNED
   16569            0 :               && (int_mode != Pmode || mem_mode == VOIDmode)
   16570              : #endif
   16571              :               ))
   16572              :         break;
   16573              : 
   16574      1136315 :       if (GET_CODE (rtl) == UNSPEC)
   16575              :         {
   16576              :           /* If delegitimize_address couldn't do anything with the UNSPEC, we
   16577              :              can't express it in the debug info.  This can happen e.g. with some
   16578              :              TLS UNSPECs.  Allow UNSPECs formerly from CONST that the backend
   16579              :              approves.  */
   16580          788 :           bool not_ok = false;
   16581          788 :           subrtx_var_iterator::array_type array;
   16582         1586 :           FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
   16583         1576 :             if (*iter != rtl && !CONSTANT_P (*iter))
   16584              :               {
   16585              :                 not_ok = true;
   16586              :                 break;
   16587              :               }
   16588              : 
   16589          788 :           if (not_ok)
   16590              :             break;
   16591              : 
   16592           10 :           FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
   16593           10 :             if (!const_ok_for_output_1 (*iter))
   16594              :               {
   16595              :                 not_ok = true;
   16596              :                 break;
   16597              :               }
   16598              : 
   16599           10 :           if (not_ok)
   16600              :             break;
   16601              : 
   16602            0 :           rtl = gen_rtx_CONST (GET_MODE (rtl), rtl);
   16603            0 :           goto symref;
   16604          788 :         }
   16605              : 
   16606      1135527 :       if (GET_CODE (rtl) == SYMBOL_REF
   16607      1135527 :           && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
   16608              :         {
   16609         4874 :           dw_loc_descr_ref temp;
   16610              : 
   16611              :           /* If this is not defined, we have no way to emit the data.  */
   16612         4874 :           if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
   16613              :             break;
   16614              : 
   16615         4874 :           temp = new_addr_loc_descr (rtl, dtprel_true);
   16616              : 
   16617              :           /* We check for DWARF 5 here because gdb did not implement
   16618              :              DW_OP_form_tls_address until after 7.12.  */
   16619         4878 :           mem_loc_result = new_loc_descr ((dwarf_version >= 5
   16620              :                                            ? DW_OP_form_tls_address
   16621              :                                            : DW_OP_GNU_push_tls_address),
   16622              :                                           0, 0);
   16623         4874 :           add_loc_descr (&mem_loc_result, temp);
   16624              : 
   16625         4874 :           break;
   16626              :         }
   16627              : 
   16628      1130653 :       if (!const_ok_for_output (rtl))
   16629              :         {
   16630       105018 :           if (GET_CODE (rtl) == CONST)
   16631         8968 :             switch (GET_CODE (XEXP (rtl, 0)))
   16632              :               {
   16633            0 :               case NOT:
   16634            0 :                 op = DW_OP_not;
   16635            0 :                 goto try_const_unop;
   16636            0 :               case NEG:
   16637            0 :                 op = DW_OP_neg;
   16638            0 :                 goto try_const_unop;
   16639            0 :               try_const_unop:
   16640            0 :                 rtx arg;
   16641            0 :                 arg = XEXP (XEXP (rtl, 0), 0);
   16642            0 :                 if (!CONSTANT_P (arg))
   16643            0 :                   arg = gen_rtx_CONST (int_mode, arg);
   16644            0 :                 op0 = mem_loc_descriptor (arg, int_mode, mem_mode,
   16645              :                                           initialized);
   16646            0 :                 if (op0)
   16647              :                   {
   16648            0 :                     mem_loc_result = op0;
   16649            0 :                     add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
   16650              :                   }
   16651              :                 break;
   16652         8968 :               default:
   16653         8968 :                 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), int_mode,
   16654              :                                                      mem_mode, initialized);
   16655         8968 :                 break;
   16656              :               }
   16657              :           break;
   16658              :         }
   16659              : 
   16660      1025635 :     symref:
   16661      1137842 :       mem_loc_result = new_addr_loc_descr (rtl, dtprel_false);
   16662      1137842 :       vec_safe_push (used_rtx_array, rtl);
   16663      1137842 :       break;
   16664              : 
   16665       444320 :     case CONCAT:
   16666       444320 :     case CONCATN:
   16667       444320 :     case VAR_LOCATION:
   16668       444320 :     case DEBUG_IMPLICIT_PTR:
   16669       444320 :       expansion_failed (NULL_TREE, rtl,
   16670              :                         "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
   16671       444320 :       return 0;
   16672              : 
   16673      1353237 :     case ENTRY_VALUE:
   16674      1353237 :       if (dwarf_strict && dwarf_version < 5)
   16675              :         return NULL;
   16676      1353237 :       if (REG_P (ENTRY_VALUE_EXP (rtl)))
   16677              :         {
   16678      1352023 :           if (!is_a <scalar_int_mode> (mode, &int_mode)
   16679      2703025 :               || GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
   16680        41433 :             op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
   16681              :                                       VOIDmode, VAR_INIT_STATUS_INITIALIZED);
   16682              :           else
   16683              :             {
   16684      1310590 :               unsigned int debugger_regnum = debugger_reg_number (ENTRY_VALUE_EXP (rtl));
   16685      1310590 :               if (debugger_regnum == IGNORED_DWARF_REGNUM)
   16686              :                 return NULL;
   16687      1310590 :               op0 = one_reg_loc_descriptor (debugger_regnum,
   16688              :                                             VAR_INIT_STATUS_INITIALIZED);
   16689              :             }
   16690              :         }
   16691         1214 :       else if (MEM_P (ENTRY_VALUE_EXP (rtl))
   16692         1214 :                && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
   16693              :         {
   16694         1214 :           op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
   16695              :                                     VOIDmode, VAR_INIT_STATUS_INITIALIZED);
   16696         1214 :           if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
   16697              :             return NULL;
   16698              :         }
   16699              :       else
   16700            0 :         gcc_unreachable ();
   16701      1353216 :       if (op0 == NULL)
   16702              :         return NULL;
   16703      1351785 :       mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_entry_value), 0, 0);
   16704      1351785 :       mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
   16705      1351785 :       mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
   16706      1351785 :       break;
   16707              : 
   16708        32588 :     case DEBUG_PARAMETER_REF:
   16709        32588 :       mem_loc_result = parameter_ref_descriptor (rtl);
   16710        32588 :       break;
   16711              : 
   16712            0 :     case PRE_MODIFY:
   16713              :       /* Extract the PLUS expression nested inside and fall into
   16714              :          PLUS code below.  */
   16715            0 :       rtl = XEXP (rtl, 1);
   16716            0 :       goto plus;
   16717              : 
   16718            0 :     case PRE_INC:
   16719            0 :     case PRE_DEC:
   16720              :       /* Turn these into a PLUS expression and fall into the PLUS code
   16721              :          below.  */
   16722            0 :       rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
   16723              :                           gen_int_mode (GET_CODE (rtl) == PRE_INC
   16724              :                                         ? GET_MODE_UNIT_SIZE (mem_mode)
   16725              :                                         : -GET_MODE_UNIT_SIZE (mem_mode),
   16726              :                                         mode));
   16727              : 
   16728              :       /* fall through */
   16729              : 
   16730     12560685 :     case PLUS:
   16731     12560685 :     plus:
   16732     12560685 :       if (is_based_loc (rtl)
   16733     10798890 :           && is_a <scalar_int_mode> (mode, &int_mode)
   16734     24839711 :           && (GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
   16735         1147 :               || XEXP (rtl, 0) == arg_pointer_rtx
   16736         1147 :               || XEXP (rtl, 0) == frame_pointer_rtx))
   16737     10797744 :         mem_loc_result = based_loc_descr (XEXP (rtl, 0),
   16738     10797744 :                                           INTVAL (XEXP (rtl, 1)),
   16739              :                                           VAR_INIT_STATUS_INITIALIZED);
   16740              :       else
   16741              :         {
   16742      1762941 :           mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   16743              :                                                VAR_INIT_STATUS_INITIALIZED);
   16744      1762941 :           if (mem_loc_result == 0)
   16745              :             break;
   16746              : 
   16747      1627465 :           if (CONST_INT_P (XEXP (rtl, 1))
   16748      2459955 :               && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
   16749       832490 :                   <= DWARF2_ADDR_SIZE))
   16750       829953 :             loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
   16751              :           else
   16752              :             {
   16753       797512 :               op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
   16754              :                                         VAR_INIT_STATUS_INITIALIZED);
   16755       797512 :               if (op1 == 0)
   16756              :                 return NULL;
   16757       777469 :               add_loc_descr (&mem_loc_result, op1);
   16758       777469 :               add_loc_descr (&mem_loc_result,
   16759              :                              new_loc_descr (DW_OP_plus, 0, 0));
   16760              :             }
   16761              :         }
   16762              :       break;
   16763              : 
   16764              :     /* If a pseudo-reg is optimized away, it is possible for it to
   16765              :        be replaced with a MEM containing a multiply or shift.  */
   16766       330531 :     case MINUS:
   16767       330531 :       op = DW_OP_minus;
   16768       330531 :       goto do_binop;
   16769              : 
   16770       474364 :     case MULT:
   16771       474364 :       op = DW_OP_mul;
   16772       474364 :       goto do_binop;
   16773              : 
   16774       256563 :     case DIV:
   16775            0 :       if ((!dwarf_strict || dwarf_version >= 5)
   16776       256563 :           && is_a <scalar_int_mode> (mode, &int_mode)
   16777       508355 :           && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
   16778              :         {
   16779           83 :           mem_loc_result = typed_binop (DW_OP_div, rtl,
   16780              :                                         base_type_for_mode (mode, 0),
   16781              :                                         int_mode, mem_mode);
   16782           83 :           break;
   16783              :         }
   16784       256480 :       op = DW_OP_div;
   16785       256480 :       goto do_binop;
   16786              : 
   16787         4275 :     case UMOD:
   16788         4275 :       op = DW_OP_mod;
   16789         4275 :       goto do_binop;
   16790              : 
   16791       394521 :     case ASHIFT:
   16792       394521 :       op = DW_OP_shl;
   16793       394521 :       goto do_shift;
   16794              : 
   16795        88058 :     case ASHIFTRT:
   16796        88058 :       op = DW_OP_shra;
   16797        88058 :       goto do_shift;
   16798              : 
   16799       507421 :     case LSHIFTRT:
   16800       507421 :       op = DW_OP_shr;
   16801       507421 :       goto do_shift;
   16802              : 
   16803       990000 :     do_shift:
   16804       990000 :       if (!is_a <scalar_int_mode> (mode, &int_mode))
   16805              :         break;
   16806       989935 :       op0 = mem_loc_descriptor (XEXP (rtl, 0), int_mode, mem_mode,
   16807              :                                 VAR_INIT_STATUS_INITIALIZED);
   16808       989935 :       {
   16809       989935 :         rtx rtlop1 = XEXP (rtl, 1);
   16810       989935 :         if (is_a <scalar_int_mode> (GET_MODE (rtlop1), &op1_mode)
   16811      1008459 :             && GET_MODE_BITSIZE (op1_mode) < GET_MODE_BITSIZE (int_mode))
   16812         6976 :           rtlop1 = gen_rtx_ZERO_EXTEND (int_mode, rtlop1);
   16813       989935 :         op1 = mem_loc_descriptor (rtlop1, int_mode, mem_mode,
   16814              :                                   VAR_INIT_STATUS_INITIALIZED);
   16815              :       }
   16816              : 
   16817       989935 :       if (op0 == 0 || op1 == 0)
   16818              :         break;
   16819              : 
   16820       840316 :       mem_loc_result = op0;
   16821       840316 :       add_loc_descr (&mem_loc_result, op1);
   16822       840316 :       add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
   16823       840316 :       break;
   16824              : 
   16825       663295 :     case AND:
   16826       663295 :       op = DW_OP_and;
   16827       663295 :       goto do_binop;
   16828              : 
   16829        72445 :     case IOR:
   16830        72445 :       op = DW_OP_or;
   16831        72445 :       goto do_binop;
   16832              : 
   16833        21884 :     case XOR:
   16834        21884 :       op = DW_OP_xor;
   16835        21884 :       goto do_binop;
   16836              : 
   16837      1826640 :     do_binop:
   16838      1826640 :       op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   16839              :                                 VAR_INIT_STATUS_INITIALIZED);
   16840      1826640 :       if (XEXP (rtl, 0) == XEXP (rtl, 1))
   16841              :         {
   16842         9162 :           if (op0 == 0)
   16843              :             break;
   16844         8170 :           mem_loc_result = op0;
   16845         8170 :           add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_dup, 0, 0));
   16846         8170 :           add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
   16847         8170 :           break;
   16848              :         }
   16849      1817478 :       op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
   16850              :                                 VAR_INIT_STATUS_INITIALIZED);
   16851              : 
   16852      1817478 :       if (op0 == 0 || op1 == 0)
   16853              :         break;
   16854              : 
   16855      1501091 :       mem_loc_result = op0;
   16856      1501091 :       add_loc_descr (&mem_loc_result, op1);
   16857      1501091 :       add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
   16858      1501091 :       break;
   16859              : 
   16860         2213 :     case MOD:
   16861            0 :       if ((!dwarf_strict || dwarf_version >= 5)
   16862         2213 :           && is_a <scalar_int_mode> (mode, &int_mode)
   16863         4636 :           && GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE)
   16864              :         {
   16865            8 :           mem_loc_result = typed_binop (DW_OP_mod, rtl,
   16866              :                                         base_type_for_mode (mode, 0),
   16867              :                                         int_mode, mem_mode);
   16868            8 :           break;
   16869              :         }
   16870              : 
   16871         2205 :       op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   16872              :                                 VAR_INIT_STATUS_INITIALIZED);
   16873         2205 :       op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
   16874              :                                 VAR_INIT_STATUS_INITIALIZED);
   16875              : 
   16876         2205 :       if (op0 == 0 || op1 == 0)
   16877              :         break;
   16878              : 
   16879         2202 :       mem_loc_result = op0;
   16880         2202 :       add_loc_descr (&mem_loc_result, op1);
   16881         2202 :       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
   16882         2202 :       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
   16883         2202 :       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
   16884         2202 :       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
   16885         2202 :       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
   16886         2202 :       break;
   16887              : 
   16888         7593 :     case UDIV:
   16889            0 :       if ((!dwarf_strict || dwarf_version >= 5)
   16890         7593 :           && is_a <scalar_int_mode> (mode, &int_mode))
   16891              :         {
   16892              :           /* We can use a signed divide if the sign bit is not set.  */
   16893        16294 :           if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
   16894              :             {
   16895         3366 :               op = DW_OP_div;
   16896         3366 :               goto do_binop;
   16897              :             }
   16898              : 
   16899         4227 :           mem_loc_result = typed_binop (DW_OP_div, rtl,
   16900              :                                         base_type_for_mode (int_mode, 1),
   16901              :                                         int_mode, mem_mode);
   16902              :         }
   16903              :       break;
   16904              : 
   16905        46425 :     case NOT:
   16906        46425 :       op = DW_OP_not;
   16907        46425 :       goto do_unop;
   16908              : 
   16909         3426 :     case ABS:
   16910         3426 :       op = DW_OP_abs;
   16911         3426 :       goto do_unop;
   16912              : 
   16913        53954 :     case NEG:
   16914        53954 :       op = DW_OP_neg;
   16915        53954 :       goto do_unop;
   16916              : 
   16917       103805 :     do_unop:
   16918       103805 :       op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
   16919              :                                 VAR_INIT_STATUS_INITIALIZED);
   16920              : 
   16921       103805 :       if (op0 == 0)
   16922              :         break;
   16923              : 
   16924        93594 :       mem_loc_result = op0;
   16925        93594 :       add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
   16926        93594 :       break;
   16927              : 
   16928      2890565 :     case CONST_INT:
   16929      2890565 :       if (!is_a <scalar_int_mode> (mode, &int_mode)
   16930      3511539 :           || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
   16931              : #ifdef POINTERS_EXTEND_UNSIGNED
   16932      3779284 :           || (int_mode == Pmode
   16933            0 :               && mem_mode != VOIDmode
   16934            0 :               && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
   16935              : #endif
   16936              :           )
   16937              :         {
   16938      2445329 :           mem_loc_result = int_loc_descriptor (INTVAL (rtl));
   16939      2445329 :           break;
   16940              :         }
   16941            0 :       if ((!dwarf_strict || dwarf_version >= 5)
   16942       890472 :           && (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT
   16943         1753 :               || GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_DOUBLE_INT))
   16944              :         {
   16945       445236 :           dw_die_ref type_die = base_type_for_mode (int_mode, 1);
   16946       445236 :           scalar_int_mode amode;
   16947       445236 :           if (type_die == NULL)
   16948       226523 :             return NULL;
   16949       445236 :           if (INTVAL (rtl) >= 0
   16950      1326757 :               && (int_mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT, 0)
   16951       442807 :                   .exists (&amode))
   16952       442807 :               && trunc_int_for_mode (INTVAL (rtl), amode) == INTVAL (rtl)
   16953              :               /* const DW_OP_convert <XXX> vs.
   16954              :                  DW_OP_const_type <XXX, 1, const>.  */
   16955       671759 :               && size_of_int_loc_descriptor (INTVAL (rtl)) + 1 + 1
   16956       226523 :                  < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (int_mode))
   16957              :             {
   16958       226523 :               mem_loc_result = int_loc_descriptor (INTVAL (rtl));
   16959       226523 :               op0 = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   16960       226523 :               op0->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   16961       226523 :               op0->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   16962       226523 :               op0->dw_loc_oprnd1.v.val_die_ref.external = 0;
   16963       226523 :               add_loc_descr (&mem_loc_result, op0);
   16964       226523 :               return mem_loc_result;
   16965              :             }
   16966       437426 :           mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0,
   16967       218713 :                                           INTVAL (rtl));
   16968       218713 :           mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   16969       218713 :           mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   16970       218713 :           mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
   16971       437426 :           if (GET_MODE_BITSIZE (int_mode) == HOST_BITS_PER_WIDE_INT)
   16972       218624 :             mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
   16973              :           else
   16974              :             {
   16975           89 :               mem_loc_result->dw_loc_oprnd2.val_class
   16976           89 :                 = dw_val_class_const_double;
   16977           89 :               mem_loc_result->dw_loc_oprnd2.v.val_double
   16978           89 :                 = double_int::from_shwi (INTVAL (rtl));
   16979              :             }
   16980              :         }
   16981              :       break;
   16982              : 
   16983        33270 :     case CONST_DOUBLE:
   16984        33270 :       if (!dwarf_strict || dwarf_version >= 5)
   16985              :         {
   16986        33270 :           dw_die_ref type_die;
   16987              : 
   16988              :           /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
   16989              :              CONST_DOUBLE rtx could represent either a large integer
   16990              :              or a floating-point constant.  If TARGET_SUPPORTS_WIDE_INT != 0,
   16991              :              the value is always a floating point constant.
   16992              : 
   16993              :              When it is an integer, a CONST_DOUBLE is used whenever
   16994              :              the constant requires 2 HWIs to be adequately represented.
   16995              :              We output CONST_DOUBLEs as blocks.  */
   16996        33270 :           if (mode == VOIDmode
   16997        33270 :               || (GET_MODE (rtl) == VOIDmode
   16998            0 :                   && maybe_ne (GET_MODE_BITSIZE (mode),
   16999            0 :                                HOST_BITS_PER_DOUBLE_INT)))
   17000              :             break;
   17001        33270 :           type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
   17002        33270 :           if (type_die == NULL)
   17003              :             return NULL;
   17004        33270 :           mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0, 0);
   17005        33270 :           mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   17006        33270 :           mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   17007        33270 :           mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
   17008              : #if TARGET_SUPPORTS_WIDE_INT == 0
   17009              :           if (!SCALAR_FLOAT_MODE_P (mode))
   17010              :             {
   17011              :               mem_loc_result->dw_loc_oprnd2.val_class
   17012              :                 = dw_val_class_const_double;
   17013              :               mem_loc_result->dw_loc_oprnd2.v.val_double
   17014              :                 = rtx_to_double_int (rtl);
   17015              :             }
   17016              :           else
   17017              : #endif
   17018        33270 :             {
   17019        33270 :               scalar_float_mode float_mode = as_a <scalar_float_mode> (mode);
   17020        33270 :               unsigned int length = GET_MODE_SIZE (float_mode);
   17021        33270 :               unsigned char *array = ggc_vec_alloc<unsigned char> (length);
   17022        33270 :               unsigned int elt_size = insert_float (rtl, array);
   17023              : 
   17024        33270 :               mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
   17025        33270 :               mem_loc_result->dw_loc_oprnd2.v.val_vec.length
   17026        33270 :                 = length / elt_size;
   17027        33270 :               mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
   17028        33270 :               mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
   17029              :             }
   17030              :         }
   17031              :       break;
   17032              : 
   17033          366 :     case CONST_WIDE_INT:
   17034          366 :       if (!dwarf_strict || dwarf_version >= 5)
   17035              :         {
   17036          366 :           dw_die_ref type_die;
   17037              : 
   17038          366 :           type_die = base_type_for_mode (mode, SCALAR_INT_MODE_P (mode));
   17039          366 :           if (type_die == NULL)
   17040              :             return NULL;
   17041          366 :           mem_loc_result = new_loc_descr (dwarf_OP (DW_OP_const_type), 0, 0);
   17042          366 :           mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   17043          366 :           mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   17044          366 :           mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
   17045          366 :           mem_loc_result->dw_loc_oprnd2.val_class
   17046          366 :             = dw_val_class_wide_int;
   17047          366 :           mem_loc_result->dw_loc_oprnd2.v.val_wide
   17048          366 :             = alloc_dw_wide_int (rtx_mode_t (rtl, mode));
   17049              :         }
   17050              :       break;
   17051              : 
   17052            0 :     case CONST_POLY_INT:
   17053            0 :       mem_loc_result = int_loc_descriptor (rtx_to_poly_int64 (rtl));
   17054            0 :       break;
   17055              : 
   17056        42105 :     case EQ:
   17057        42105 :       mem_loc_result = scompare_loc_descriptor (DW_OP_eq, rtl, mem_mode);
   17058        42105 :       break;
   17059              : 
   17060         5874 :     case GE:
   17061         5874 :       mem_loc_result = scompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
   17062         5874 :       break;
   17063              : 
   17064         4304 :     case GT:
   17065         4304 :       mem_loc_result = scompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
   17066         4304 :       break;
   17067              : 
   17068         3821 :     case LE:
   17069         3821 :       mem_loc_result = scompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
   17070         3821 :       break;
   17071              : 
   17072         5298 :     case LT:
   17073         5298 :       mem_loc_result = scompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
   17074         5298 :       break;
   17075              : 
   17076        70236 :     case NE:
   17077        70236 :       mem_loc_result = scompare_loc_descriptor (DW_OP_ne, rtl, mem_mode);
   17078        70236 :       break;
   17079              : 
   17080        13323 :     case GEU:
   17081        13323 :       mem_loc_result = ucompare_loc_descriptor (DW_OP_ge, rtl, mem_mode);
   17082        13323 :       break;
   17083              : 
   17084         7834 :     case GTU:
   17085         7834 :       mem_loc_result = ucompare_loc_descriptor (DW_OP_gt, rtl, mem_mode);
   17086         7834 :       break;
   17087              : 
   17088        21447 :     case LEU:
   17089        21447 :       mem_loc_result = ucompare_loc_descriptor (DW_OP_le, rtl, mem_mode);
   17090        21447 :       break;
   17091              : 
   17092         5297 :     case LTU:
   17093         5297 :       mem_loc_result = ucompare_loc_descriptor (DW_OP_lt, rtl, mem_mode);
   17094         5297 :       break;
   17095              : 
   17096        36630 :     case UMIN:
   17097        36630 :     case UMAX:
   17098        36630 :       if (!SCALAR_INT_MODE_P (mode))
   17099              :         break;
   17100              :       /* FALLTHRU */
   17101        56590 :     case SMIN:
   17102        56590 :     case SMAX:
   17103        56590 :       mem_loc_result = minmax_loc_descriptor (rtl, mode, mem_mode);
   17104        56590 :       break;
   17105              : 
   17106         3709 :     case ZERO_EXTRACT:
   17107         3709 :     case SIGN_EXTRACT:
   17108         3709 :       if (CONST_INT_P (XEXP (rtl, 1))
   17109         3709 :           && CONST_INT_P (XEXP (rtl, 2))
   17110         3695 :           && is_a <scalar_int_mode> (mode, &int_mode)
   17111         3651 :           && is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &inner_mode)
   17112         2462 :           && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
   17113         2420 :           && GET_MODE_SIZE (inner_mode) <= DWARF2_ADDR_SIZE
   17114         3709 :           && ((unsigned) INTVAL (XEXP (rtl, 1))
   17115         2148 :               + (unsigned) INTVAL (XEXP (rtl, 2))
   17116         2148 :               <= GET_MODE_BITSIZE (int_mode)))
   17117              :         {
   17118         2051 :           int shift, size;
   17119         2051 :           op0 = mem_loc_descriptor (XEXP (rtl, 0), inner_mode,
   17120              :                                     mem_mode, VAR_INIT_STATUS_INITIALIZED);
   17121         2051 :           if (op0 == 0)
   17122              :             break;
   17123         2050 :           if (GET_CODE (rtl) == SIGN_EXTRACT)
   17124              :             op = DW_OP_shra;
   17125              :           else
   17126          305 :             op = DW_OP_shr;
   17127         2050 :           mem_loc_result = op0;
   17128         2050 :           size = INTVAL (XEXP (rtl, 1));
   17129         2050 :           shift = INTVAL (XEXP (rtl, 2));
   17130         2050 :           if (BITS_BIG_ENDIAN)
   17131              :             shift = GET_MODE_BITSIZE (inner_mode) - shift - size;
   17132         2175 :           if (shift + size != (int) DWARF2_ADDR_SIZE)
   17133              :             {
   17134         1978 :               add_loc_descr (&mem_loc_result,
   17135         1978 :                              int_loc_descriptor (DWARF2_ADDR_SIZE
   17136         1978 :                                                  - shift - size));
   17137         1978 :               add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
   17138              :             }
   17139         2175 :           if (size != (int) DWARF2_ADDR_SIZE)
   17140              :             {
   17141         1852 :               add_loc_descr (&mem_loc_result,
   17142         1973 :                              int_loc_descriptor (DWARF2_ADDR_SIZE - size));
   17143         1852 :               add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
   17144              :             }
   17145              :         }
   17146              :       break;
   17147              : 
   17148        60793 :     case IF_THEN_ELSE:
   17149        60793 :       {
   17150        60793 :         dw_loc_descr_ref op2, bra_node, drop_node;
   17151        60793 :         op0 = mem_loc_descriptor (XEXP (rtl, 0),
   17152        60793 :                                   GET_MODE (XEXP (rtl, 0)) == VOIDmode
   17153        58621 :                                   ? word_mode : GET_MODE (XEXP (rtl, 0)),
   17154              :                                   mem_mode, VAR_INIT_STATUS_INITIALIZED);
   17155        60793 :         op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
   17156              :                                   VAR_INIT_STATUS_INITIALIZED);
   17157        60793 :         op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
   17158              :                                   VAR_INIT_STATUS_INITIALIZED);
   17159        60793 :         if (op0 == NULL || op1 == NULL || op2 == NULL)
   17160              :           break;
   17161              : 
   17162        60238 :         mem_loc_result = op1;
   17163        60238 :         add_loc_descr (&mem_loc_result, op2);
   17164        60238 :         add_loc_descr (&mem_loc_result, op0);
   17165        60238 :         bra_node = new_loc_descr (DW_OP_bra, 0, 0);
   17166        60238 :         add_loc_descr (&mem_loc_result, bra_node);
   17167        60238 :         add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
   17168        60238 :         drop_node = new_loc_descr (DW_OP_drop, 0, 0);
   17169        60238 :         add_loc_descr (&mem_loc_result, drop_node);
   17170        60238 :         bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
   17171        60238 :         bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
   17172              :       }
   17173        60238 :       break;
   17174              : 
   17175        24744 :     case FLOAT_EXTEND:
   17176        24744 :     case FLOAT_TRUNCATE:
   17177        24744 :     case FLOAT:
   17178        24744 :     case UNSIGNED_FLOAT:
   17179        24744 :     case FIX:
   17180        24744 :     case UNSIGNED_FIX:
   17181        24744 :       if (!dwarf_strict || dwarf_version >= 5)
   17182              :         {
   17183        24744 :           dw_die_ref type_die;
   17184        24744 :           dw_loc_descr_ref cvt;
   17185              : 
   17186        24744 :           op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
   17187              :                                     mem_mode, VAR_INIT_STATUS_INITIALIZED);
   17188        24744 :           if (op0 == NULL)
   17189              :             break;
   17190        24524 :           if (is_a <scalar_int_mode> (GET_MODE (XEXP (rtl, 0)), &int_mode)
   17191        24524 :               && (GET_CODE (rtl) == FLOAT
   17192         1712 :                   || GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE))
   17193              :             {
   17194         5548 :               type_die = base_type_for_mode (int_mode,
   17195              :                                              GET_CODE (rtl) == UNSIGNED_FLOAT);
   17196         5548 :               if (type_die == NULL)
   17197              :                 break;
   17198         5548 :               cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   17199         5548 :               cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   17200         5548 :               cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   17201         5548 :               cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   17202         5548 :               add_loc_descr (&op0, cvt);
   17203              :             }
   17204        24524 :           type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
   17205        24524 :           if (type_die == NULL)
   17206              :             break;
   17207        24524 :           cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   17208        24524 :           cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   17209        24524 :           cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   17210        24524 :           cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   17211        24524 :           add_loc_descr (&op0, cvt);
   17212        24524 :           if (is_a <scalar_int_mode> (mode, &int_mode)
   17213        24524 :               && (GET_CODE (rtl) == FIX
   17214           63 :                   || GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE))
   17215              :             {
   17216         1632 :               op0 = convert_descriptor_to_mode (int_mode, op0);
   17217         1632 :               if (op0 == NULL)
   17218              :                 break;
   17219              :             }
   17220        24524 :           mem_loc_result = op0;
   17221              :         }
   17222              :       break;
   17223              : 
   17224         4153 :     case CLZ:
   17225         4153 :     case CTZ:
   17226         4153 :     case FFS:
   17227         4153 :       if (is_a <scalar_int_mode> (mode, &int_mode))
   17228         4153 :         mem_loc_result = clz_loc_descriptor (rtl, int_mode, mem_mode);
   17229              :       break;
   17230              : 
   17231            0 :     case POPCOUNT:
   17232            0 :     case PARITY:
   17233            0 :       if (is_a <scalar_int_mode> (mode, &int_mode))
   17234            0 :         mem_loc_result = popcount_loc_descriptor (rtl, int_mode, mem_mode);
   17235              :       break;
   17236              : 
   17237          248 :     case BSWAP:
   17238          248 :       if (is_a <scalar_int_mode> (mode, &int_mode))
   17239          248 :         mem_loc_result = bswap_loc_descriptor (rtl, int_mode, mem_mode);
   17240              :       break;
   17241              : 
   17242         2291 :     case ROTATE:
   17243         2291 :     case ROTATERT:
   17244         2291 :       if (is_a <scalar_int_mode> (mode, &int_mode))
   17245         2291 :         mem_loc_result = rotate_loc_descriptor (rtl, int_mode, mem_mode);
   17246              :       break;
   17247              : 
   17248              :     case COMPARE:
   17249              :       /* In theory, we could implement the above.  */
   17250              :       /* DWARF cannot represent the unsigned compare operations
   17251              :          natively.  */
   17252              :     case SS_MULT:
   17253              :     case US_MULT:
   17254              :     case SS_DIV:
   17255              :     case US_DIV:
   17256              :     case SS_PLUS:
   17257              :     case US_PLUS:
   17258              :     case SS_MINUS:
   17259              :     case US_MINUS:
   17260              :     case SS_NEG:
   17261              :     case US_NEG:
   17262              :     case SS_ABS:
   17263              :     case SS_ASHIFT:
   17264              :     case US_ASHIFT:
   17265              :     case SS_TRUNCATE:
   17266              :     case US_TRUNCATE:
   17267              :     case UNORDERED:
   17268              :     case ORDERED:
   17269              :     case UNEQ:
   17270              :     case UNGE:
   17271              :     case UNGT:
   17272              :     case UNLE:
   17273              :     case UNLT:
   17274              :     case LTGT:
   17275              :     case FRACT_CONVERT:
   17276              :     case UNSIGNED_FRACT_CONVERT:
   17277              :     case SAT_FRACT:
   17278              :     case UNSIGNED_SAT_FRACT:
   17279              :     case SQRT:
   17280              :     case ASM_OPERANDS:
   17281              :     case VEC_MERGE:
   17282              :     case VEC_SELECT:
   17283              :     case VEC_CONCAT:
   17284              :     case VEC_DUPLICATE:
   17285              :     case VEC_SERIES:
   17286              :     case HIGH:
   17287              :     case FMA:
   17288              :     case STRICT_LOW_PART:
   17289              :     case CONST_VECTOR:
   17290              :     case CONST_FIXED:
   17291              :     case CLRSB:
   17292              :     case CLOBBER:
   17293              :     case SMUL_HIGHPART:
   17294              :     case UMUL_HIGHPART:
   17295              :     case BITREVERSE:
   17296              :     case COPYSIGN:
   17297              :       break;
   17298              : 
   17299       112207 :     case CONST_STRING:
   17300       112207 :       resolve_one_addr (&rtl);
   17301       112207 :       goto symref;
   17302              : 
   17303              :     /* RTL sequences inside PARALLEL record a series of DWARF operations for
   17304              :        the expression.  An UNSPEC rtx represents a raw DWARF operation,
   17305              :        new_loc_descr is called for it to build the operation directly.
   17306              :        Otherwise mem_loc_descriptor is called recursively.  */
   17307              :     case PARALLEL:
   17308              :       {
   17309              :         int index = 0;
   17310            0 :         dw_loc_descr_ref exp_result = NULL;
   17311              : 
   17312            0 :         for (; index < XVECLEN (rtl, 0); index++)
   17313              :           {
   17314            0 :             rtx elem = XVECEXP (rtl, 0, index);
   17315            0 :             if (GET_CODE (elem) == UNSPEC)
   17316              :               {
   17317              :                 /* Each DWARF operation UNSPEC contain two operands, if
   17318              :                    one operand is not used for the operation, const0_rtx is
   17319              :                    passed.  */
   17320            0 :                 gcc_assert (XVECLEN (elem, 0) == 2);
   17321              : 
   17322            0 :                 HOST_WIDE_INT dw_op = XINT (elem, 1);
   17323            0 :                 HOST_WIDE_INT oprnd1 = INTVAL (XVECEXP (elem, 0, 0));
   17324            0 :                 HOST_WIDE_INT oprnd2 = INTVAL (XVECEXP (elem, 0, 1));
   17325            0 :                 exp_result
   17326            0 :                   = new_loc_descr ((enum dwarf_location_atom) dw_op, oprnd1,
   17327              :                                    oprnd2);
   17328              :               }
   17329              :             else
   17330            0 :               exp_result
   17331            0 :                 = mem_loc_descriptor (elem, mode, mem_mode,
   17332              :                                       VAR_INIT_STATUS_INITIALIZED);
   17333              : 
   17334            0 :             if (!mem_loc_result)
   17335            0 :               mem_loc_result = exp_result;
   17336              :             else
   17337            0 :               add_loc_descr (&mem_loc_result, exp_result);
   17338              :           }
   17339              : 
   17340              :         break;
   17341              :       }
   17342              : 
   17343            0 :     default:
   17344            0 :       if (flag_checking)
   17345              :         {
   17346            0 :           print_rtl (stderr, rtl);
   17347            0 :           gcc_unreachable ();
   17348              :         }
   17349              :       break;
   17350              :     }
   17351              : 
   17352     26983642 :   if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
   17353            0 :     add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
   17354              : 
   17355     26983642 :   return mem_loc_result;
   17356              : }
   17357              : 
   17358              : /* Return a descriptor that describes the concatenation of two locations.
   17359              :    This is typically a complex variable.  */
   17360              : 
   17361              : static dw_loc_descr_ref
   17362        21110 : concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
   17363              : {
   17364              :   /* At present we only track constant-sized pieces.  */
   17365        21110 :   unsigned int size0, size1;
   17366        42220 :   if (!GET_MODE_SIZE (GET_MODE (x0)).is_constant (&size0)
   17367        42220 :       || !GET_MODE_SIZE (GET_MODE (x1)).is_constant (&size1))
   17368              :     return 0;
   17369              : 
   17370        21110 :   dw_loc_descr_ref cc_loc_result = NULL;
   17371        21110 :   dw_loc_descr_ref x0_ref
   17372        21110 :     = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
   17373        21110 :   dw_loc_descr_ref x1_ref
   17374        21110 :     = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
   17375              : 
   17376        21110 :   if (x0_ref == 0 || x1_ref == 0)
   17377              :     return 0;
   17378              : 
   17379        19996 :   cc_loc_result = x0_ref;
   17380        19996 :   add_loc_descr_op_piece (&cc_loc_result, size0);
   17381              : 
   17382        19996 :   add_loc_descr (&cc_loc_result, x1_ref);
   17383        19996 :   add_loc_descr_op_piece (&cc_loc_result, size1);
   17384              : 
   17385        19996 :   if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
   17386            0 :     add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
   17387              : 
   17388        19996 :   return cc_loc_result;
   17389              : }
   17390              : 
   17391              : /* Return a descriptor that describes the concatenation of N
   17392              :    locations.  */
   17393              : 
   17394              : static dw_loc_descr_ref
   17395        36444 : concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
   17396              : {
   17397        36444 :   unsigned int i;
   17398        36444 :   dw_loc_descr_ref cc_loc_result = NULL;
   17399        36444 :   unsigned int n = XVECLEN (concatn, 0);
   17400        36444 :   unsigned int size;
   17401              : 
   17402        78281 :   for (i = 0; i < n; ++i)
   17403              :     {
   17404        59900 :       dw_loc_descr_ref ref;
   17405        59900 :       rtx x = XVECEXP (concatn, 0, i);
   17406              : 
   17407              :       /* At present we only track constant-sized pieces.  */
   17408       119800 :       if (!GET_MODE_SIZE (GET_MODE (x)).is_constant (&size))
   17409              :         return NULL;
   17410              : 
   17411        59900 :       ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
   17412        59900 :       if (ref == NULL)
   17413              :         return NULL;
   17414              : 
   17415        41837 :       add_loc_descr (&cc_loc_result, ref);
   17416        41837 :       add_loc_descr_op_piece (&cc_loc_result, size);
   17417              :     }
   17418              : 
   17419        18381 :   if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
   17420            0 :     add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
   17421              : 
   17422        18381 :   return cc_loc_result;
   17423              : }
   17424              : 
   17425              : /* Helper function for loc_descriptor.  Return DW_OP_implicit_pointer
   17426              :    for DEBUG_IMPLICIT_PTR RTL.  */
   17427              : 
   17428              : static dw_loc_descr_ref
   17429      2055605 : implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
   17430              : {
   17431      2055605 :   dw_loc_descr_ref ret;
   17432      2055605 :   dw_die_ref ref;
   17433              : 
   17434      2055605 :   if (dwarf_strict && dwarf_version < 5)
   17435              :     return NULL;
   17436      2055605 :   gcc_assert (VAR_P (DEBUG_IMPLICIT_PTR_DECL (rtl))
   17437              :               || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
   17438              :               || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
   17439      2055605 :   ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
   17440      2056008 :   ret = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
   17441      2055605 :   ret->dw_loc_oprnd2.val_class = dw_val_class_const;
   17442      2055605 :   if (ref)
   17443              :     {
   17444      1203777 :       ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   17445      1203777 :       ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
   17446      1203777 :       ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
   17447              :     }
   17448              :   else
   17449              :     {
   17450       851828 :       ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
   17451       851828 :       ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
   17452              :     }
   17453              :   return ret;
   17454              : }
   17455              : 
   17456              : /* Output a proper Dwarf location descriptor for a variable or parameter
   17457              :    which is either allocated in a register or in a memory location.  For a
   17458              :    register, we just generate an OP_REG and the register number.  For a
   17459              :    memory location we provide a Dwarf postfix expression describing how to
   17460              :    generate the (dynamic) address of the object onto the address stack.
   17461              : 
   17462              :    MODE is mode of the decl if this loc_descriptor is going to be used in
   17463              :    .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
   17464              :    allowed, VOIDmode otherwise.
   17465              : 
   17466              :    If we don't know how to describe it, return 0.  */
   17467              : 
   17468              : static dw_loc_descr_ref
   17469     59855527 : loc_descriptor (rtx rtl, machine_mode mode,
   17470              :                 enum var_init_status initialized)
   17471              : {
   17472     59855527 :   dw_loc_descr_ref loc_result = NULL;
   17473     59855527 :   scalar_int_mode int_mode;
   17474              : 
   17475     59855527 :   switch (GET_CODE (rtl))
   17476              :     {
   17477       138334 :     case SUBREG:
   17478              :       /* The case of a subreg may arise when we have a local (register)
   17479              :          variable or a formal (register) parameter which doesn't quite fill
   17480              :          up an entire register.  For now, just assume that it is
   17481              :          legitimate to make the Dwarf info refer to the whole register which
   17482              :          contains the given subreg.  */
   17483       138334 :       if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
   17484           50 :         loc_result = loc_descriptor (SUBREG_REG (rtl),
   17485           25 :                                      GET_MODE (SUBREG_REG (rtl)), initialized);
   17486              :       else
   17487       138309 :         goto do_default;
   17488           25 :       break;
   17489              : 
   17490     11897516 :     case REG:
   17491     11897516 :       loc_result = reg_loc_descriptor (rtl, initialized);
   17492     11897516 :       break;
   17493              : 
   17494      3895526 :     case MEM:
   17495      3895526 :       loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
   17496      3895526 :                                        GET_MODE (rtl), initialized);
   17497      3895526 :       if (loc_result == NULL)
   17498        11464 :         loc_result = tls_mem_loc_descriptor (rtl);
   17499      3895526 :       if (loc_result == NULL)
   17500              :         {
   17501        11464 :           rtx new_rtl = avoid_constant_pool_reference (rtl);
   17502        11464 :           if (new_rtl != rtl)
   17503            0 :             loc_result = loc_descriptor (new_rtl, mode, initialized);
   17504              :         }
   17505              :       break;
   17506              : 
   17507        21110 :     case CONCAT:
   17508        21110 :       loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
   17509              :                                           initialized);
   17510        21110 :       break;
   17511              : 
   17512        36444 :     case CONCATN:
   17513        36444 :       loc_result = concatn_loc_descriptor (rtl, initialized);
   17514        36444 :       break;
   17515              : 
   17516     29463703 :     case VAR_LOCATION:
   17517              :       /* Single part.  */
   17518     29463703 :       if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
   17519              :         {
   17520     29314607 :           rtx loc = PAT_VAR_LOCATION_LOC (rtl);
   17521     29314607 :           if (GET_CODE (loc) == EXPR_LIST)
   17522            0 :             loc = XEXP (loc, 0);
   17523     29314607 :           loc_result = loc_descriptor (loc, mode, initialized);
   17524     29314607 :           break;
   17525              :         }
   17526              : 
   17527       149096 :       rtl = XEXP (rtl, 1);
   17528              :       /* FALLTHRU */
   17529              : 
   17530       149414 :     case PARALLEL:
   17531       149414 :       {
   17532       149414 :         rtvec par_elems = XVEC (rtl, 0);
   17533       149414 :         int num_elem = GET_NUM_ELEM (par_elems);
   17534       149414 :         machine_mode mode;
   17535       149414 :         int i, size;
   17536              : 
   17537              :         /* Create the first one, so we have something to add to.  */
   17538       149414 :         loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
   17539              :                                      VOIDmode, initialized);
   17540       149414 :         if (loc_result == NULL)
   17541     59855527 :           return NULL;
   17542       149414 :         mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
   17543              :         /* At present we only track constant-sized pieces.  */
   17544       298828 :         if (!GET_MODE_SIZE (mode).is_constant (&size))
   17545              :           return NULL;
   17546       149414 :         add_loc_descr_op_piece (&loc_result, size);
   17547       448276 :         for (i = 1; i < num_elem; i++)
   17548              :           {
   17549       149448 :             dw_loc_descr_ref temp;
   17550              : 
   17551       149448 :             temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
   17552              :                                    VOIDmode, initialized);
   17553       149448 :             if (temp == NULL)
   17554              :               return NULL;
   17555       149448 :             add_loc_descr (&loc_result, temp);
   17556       149448 :             mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
   17557              :             /* At present we only track constant-sized pieces.  */
   17558       298896 :             if (!GET_MODE_SIZE (mode).is_constant (&size))
   17559              :               return NULL;
   17560       149448 :             add_loc_descr_op_piece (&loc_result, size);
   17561              :           }
   17562              :       }
   17563              :       break;
   17564              : 
   17565      3147301 :     case CONST_INT:
   17566      3147301 :       if (mode != VOIDmode && mode != BLKmode)
   17567              :         {
   17568      3142201 :           int_mode = as_a <scalar_int_mode> (mode);
   17569      6284402 :           loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (int_mode),
   17570              :                                                       INTVAL (rtl));
   17571              :         }
   17572              :       break;
   17573              : 
   17574        54831 :     case CONST_DOUBLE:
   17575        54831 :       if (mode == VOIDmode)
   17576        12660 :         mode = GET_MODE (rtl);
   17577              : 
   17578        54831 :       if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
   17579              :         {
   17580        54831 :           gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
   17581              : 
   17582              :           /* Note that a CONST_DOUBLE rtx could represent either an integer
   17583              :              or a floating-point constant.  A CONST_DOUBLE is used whenever
   17584              :              the constant requires more than one word in order to be
   17585              :              adequately represented.  We output CONST_DOUBLEs as blocks.  */
   17586        54831 :           scalar_mode smode = as_a <scalar_mode> (mode);
   17587        54831 :           loc_result = new_loc_descr (DW_OP_implicit_value,
   17588        54831 :                                       GET_MODE_SIZE (smode), 0);
   17589              : #if TARGET_SUPPORTS_WIDE_INT == 0
   17590              :           if (!SCALAR_FLOAT_MODE_P (smode))
   17591              :             {
   17592              :               loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
   17593              :               loc_result->dw_loc_oprnd2.v.val_double
   17594              :                 = rtx_to_double_int (rtl);
   17595              :             }
   17596              :           else
   17597              : #endif
   17598        54831 :             {
   17599        54831 :               unsigned int length = GET_MODE_SIZE (smode);
   17600        54831 :               unsigned char *array = ggc_vec_alloc<unsigned char> (length);
   17601        54831 :               unsigned int elt_size = insert_float (rtl, array);
   17602              : 
   17603        54831 :               loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
   17604        54831 :               loc_result->dw_loc_oprnd2.v.val_vec.length = length / elt_size;
   17605        54831 :               loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
   17606        54831 :               loc_result->dw_loc_oprnd2.v.val_vec.array = array;
   17607              :             }
   17608              :         }
   17609              :       break;
   17610              : 
   17611          638 :     case CONST_WIDE_INT:
   17612          638 :       if (mode == VOIDmode)
   17613            4 :         mode = GET_MODE (rtl);
   17614              : 
   17615          638 :       if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
   17616              :         {
   17617          634 :           int_mode = as_a <scalar_int_mode> (mode);
   17618          634 :           loc_result = new_loc_descr (DW_OP_implicit_value,
   17619          634 :                                       GET_MODE_SIZE (int_mode), 0);
   17620          634 :           loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
   17621          634 :           loc_result->dw_loc_oprnd2.v.val_wide
   17622          634 :             = alloc_dw_wide_int (rtx_mode_t (rtl, int_mode));
   17623              :         }
   17624              :       break;
   17625              : 
   17626           10 :     case CONST_VECTOR:
   17627           10 :       if (mode == VOIDmode)
   17628            0 :         mode = GET_MODE (rtl);
   17629              : 
   17630            0 :       if (mode != VOIDmode
   17631              :           /* The combination of a length and byte elt_size doesn't extend
   17632              :              naturally to boolean vectors, where several elements are packed
   17633              :              into the same byte.  */
   17634           10 :           && GET_MODE_CLASS (mode) != MODE_VECTOR_BOOL
   17635           10 :           && (dwarf_version >= 4 || !dwarf_strict))
   17636              :         {
   17637           10 :           unsigned int length;
   17638           20 :           if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
   17639              :             return NULL;
   17640              : 
   17641           10 :           unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
   17642           10 :           unsigned char *array
   17643           10 :             = ggc_vec_alloc<unsigned char> (length * elt_size);
   17644           10 :           unsigned int i;
   17645           10 :           unsigned char *p;
   17646           10 :           machine_mode imode = GET_MODE_INNER (mode);
   17647              : 
   17648           10 :           gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
   17649           10 :           switch (GET_MODE_CLASS (mode))
   17650              :             {
   17651              :             case MODE_VECTOR_INT:
   17652           40 :               for (i = 0, p = array; i < length; i++, p += elt_size)
   17653              :                 {
   17654           32 :                   rtx elt = CONST_VECTOR_ELT (rtl, i);
   17655           32 :                   insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
   17656              :                 }
   17657              :               break;
   17658              : 
   17659              :             case MODE_VECTOR_FLOAT:
   17660           10 :               for (i = 0, p = array; i < length; i++, p += elt_size)
   17661              :                 {
   17662            8 :                   rtx elt = CONST_VECTOR_ELT (rtl, i);
   17663            8 :                   insert_float (elt, p);
   17664              :                 }
   17665              :               break;
   17666              : 
   17667            0 :             default:
   17668            0 :               gcc_unreachable ();
   17669              :             }
   17670              : 
   17671           10 :           loc_result = new_loc_descr (DW_OP_implicit_value,
   17672              :                                       length * elt_size, 0);
   17673           10 :           loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
   17674           10 :           loc_result->dw_loc_oprnd2.v.val_vec.length = length;
   17675           10 :           loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
   17676           10 :           loc_result->dw_loc_oprnd2.v.val_vec.array = array;
   17677              :         }
   17678              :       break;
   17679              : 
   17680        75949 :     case CONST:
   17681        75949 :       if (mode == VOIDmode
   17682        75949 :           || CONST_SCALAR_INT_P (XEXP (rtl, 0))
   17683        75949 :           || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl, 0))
   17684        75949 :           || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
   17685              :         {
   17686            0 :           loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
   17687            0 :           break;
   17688              :         }
   17689              :       /* FALLTHROUGH */
   17690       553420 :     case SYMBOL_REF:
   17691       553420 :       if (!const_ok_for_output (rtl))
   17692              :         break;
   17693              :       /* FALLTHROUGH */
   17694       498562 :     case LABEL_REF:
   17695       498562 :       if (is_a <scalar_int_mode> (mode, &int_mode)
   17696       533487 :           && GET_MODE_SIZE (int_mode) == DWARF2_ADDR_SIZE
   17697       498560 :           && (dwarf_version >= 4 || !dwarf_strict))
   17698              :         {
   17699       498560 :          loc_result = new_addr_loc_descr (rtl, dtprel_false);
   17700       498560 :           add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
   17701       498560 :           vec_safe_push (used_rtx_array, rtl);
   17702              :         }
   17703              :       break;
   17704              : 
   17705      1909600 :     case DEBUG_IMPLICIT_PTR:
   17706      1909600 :       loc_result = implicit_ptr_descriptor (rtl, 0);
   17707      1909600 :       break;
   17708              : 
   17709      6548926 :     case PLUS:
   17710      6548926 :       if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
   17711       146005 :           && CONST_INT_P (XEXP (rtl, 1)))
   17712              :         {
   17713       146005 :           loc_result
   17714       146005 :             = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
   17715       146005 :           break;
   17716              :         }
   17717              :       /* FALLTHRU */
   17718      6402921 :     do_default:
   17719      8729080 :     default:
   17720      8729080 :       if ((is_a <scalar_int_mode> (mode, &int_mode)
   17721      8670236 :            && GET_MODE (rtl) == int_mode
   17722      9265450 :            && GET_MODE_SIZE (int_mode) <= DWARF2_ADDR_SIZE
   17723      8431379 :            && dwarf_version >= 4)
   17724       300260 :           || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
   17725              :         {
   17726              :           /* Value expression.  */
   17727      8725579 :           loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
   17728      8725579 :           if (loc_result)
   17729     16936598 :             add_loc_descr (&loc_result,
   17730              :                            new_loc_descr (DW_OP_stack_value, 0, 0));
   17731              :         }
   17732              :       break;
   17733              :     }
   17734              : 
   17735     59855527 :   return loc_result;
   17736              : }
   17737              : 
   17738              : /* We need to figure out what section we should use as the base for the
   17739              :    address ranges where a given location is valid.
   17740              :    1. If this particular DECL has a section associated with it, use that.
   17741              :    2. If this function has a section associated with it, use that.
   17742              :    3. Otherwise, use the text section.
   17743              :    XXX: If you split a variable across multiple sections, we won't notice.  */
   17744              : 
   17745              : static const char *
   17746     18076796 : secname_for_decl (const_tree decl)
   17747              : {
   17748     18076796 :   const char *secname;
   17749              : 
   17750       973729 :   if (VAR_OR_FUNCTION_DECL_P (decl)
   17751     17106578 :       && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl) || TREE_STATIC (decl))
   17752     18080307 :       && DECL_SECTION_NAME (decl))
   17753          496 :     secname = DECL_SECTION_NAME (decl);
   17754     18076300 :   else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
   17755              :     {
   17756     15904479 :       if (in_cold_section_p)
   17757              :         {
   17758      4095737 :           section *sec = current_function_section ();
   17759      4095737 :           if (sec->common.flags & SECTION_NAMED)
   17760      4095737 :             return sec->named.name;
   17761              :         }
   17762     11808742 :       secname = DECL_SECTION_NAME (current_function_decl);
   17763              :     }
   17764      2171821 :   else if (cfun && in_cold_section_p)
   17765        64276 :     secname = crtl->subsections.cold_section_label;
   17766              :   else
   17767              :     secname = text_section_label;
   17768              : 
   17769              :   return secname;
   17770              : }
   17771              : 
   17772              : /* Return true when DECL_BY_REFERENCE is defined and set for DECL.  */
   17773              : 
   17774              : static bool
   17775    136066580 : decl_by_reference_p (tree decl)
   17776              : {
   17777    136066580 :   return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
   17778              :            || VAR_P (decl))
   17779    136066580 :           && DECL_BY_REFERENCE (decl));
   17780              : }
   17781              : 
   17782              : /* Helper function for dw_loc_list.  Compute proper Dwarf location descriptor
   17783              :    for VARLOC.  */
   17784              : 
   17785              : static dw_loc_descr_ref
   17786     29819539 : dw_loc_list_1 (tree loc, rtx varloc, int want_address,
   17787              :                enum var_init_status initialized)
   17788              : {
   17789     29819539 :   int have_address = 0;
   17790     29819539 :   dw_loc_descr_ref descr;
   17791     29819539 :   machine_mode mode;
   17792              : 
   17793     29819539 :   if (want_address != 2)
   17794              :     {
   17795       355836 :       gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
   17796              :       /* Single part.  */
   17797       355836 :       if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
   17798              :         {
   17799       355836 :           varloc = PAT_VAR_LOCATION_LOC (varloc);
   17800       355836 :           if (GET_CODE (varloc) == EXPR_LIST)
   17801            0 :             varloc = XEXP (varloc, 0);
   17802       355836 :           mode = GET_MODE (varloc);
   17803       355836 :           if (MEM_P (varloc))
   17804              :             {
   17805        14299 :               rtx addr = XEXP (varloc, 0);
   17806        14299 :               descr = mem_loc_descriptor (addr, get_address_mode (varloc),
   17807              :                                           mode, initialized);
   17808        14299 :               if (descr)
   17809              :                 have_address = 1;
   17810              :               else
   17811              :                 {
   17812            0 :                   rtx x = avoid_constant_pool_reference (varloc);
   17813            0 :                   if (x != varloc)
   17814            0 :                     descr = mem_loc_descriptor (x, mode, VOIDmode,
   17815              :                                                 initialized);
   17816              :                 }
   17817              :             }
   17818              :           else
   17819       341537 :             descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
   17820              :         }
   17821              :       else
   17822              :         return 0;
   17823              :     }
   17824              :   else
   17825              :     {
   17826     29463703 :       if (GET_CODE (varloc) == VAR_LOCATION)
   17827     29463703 :         mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
   17828              :       else
   17829            0 :         mode = DECL_MODE (loc);
   17830     29463703 :       descr = loc_descriptor (varloc, mode, initialized);
   17831     29463703 :       have_address = 1;
   17832              :     }
   17833              : 
   17834     29819539 :   if (!descr)
   17835              :     return 0;
   17836              : 
   17837     29343844 :   if (want_address == 2 && !have_address
   17838            0 :       && (dwarf_version >= 4 || !dwarf_strict))
   17839              :     {
   17840            0 :       if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
   17841              :         {
   17842            0 :           expansion_failed (loc, NULL_RTX,
   17843              :                             "DWARF address size mismatch");
   17844            0 :           return 0;
   17845              :         }
   17846            0 :       add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
   17847            0 :       have_address = 1;
   17848              :     }
   17849              :   /* Show if we can't fill the request for an address.  */
   17850     29343844 :   if (want_address && !have_address)
   17851              :     {
   17852            0 :       expansion_failed (loc, NULL_RTX,
   17853              :                         "Want address and only have value");
   17854            0 :       return 0;
   17855              :     }
   17856              : 
   17857              :   /* If we've got an address and don't want one, dereference.  */
   17858     29343844 :   if (!want_address && have_address)
   17859              :     {
   17860        14299 :       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
   17861        14299 :       enum dwarf_location_atom op;
   17862              : 
   17863        16715 :       if (size > DWARF2_ADDR_SIZE || size == -1)
   17864              :         {
   17865            0 :           expansion_failed (loc, NULL_RTX,
   17866              :                             "DWARF address size mismatch");
   17867            0 :           return 0;
   17868              :         }
   17869        16715 :       else if (size == DWARF2_ADDR_SIZE)
   17870              :         op = DW_OP_deref;
   17871              :       else
   17872            0 :         op = DW_OP_deref_size;
   17873              : 
   17874        28598 :       add_loc_descr (&descr, new_loc_descr (op, size, 0));
   17875              :     }
   17876              : 
   17877     29343844 :   return descr;
   17878              : }
   17879              : 
   17880              : /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
   17881              :    if it is not possible.  */
   17882              : 
   17883              : static dw_loc_descr_ref
   17884      4724590 : new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
   17885              : {
   17886      4724590 :   if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
   17887      4608670 :     return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
   17888       115920 :   else if (dwarf_version >= 3 || !dwarf_strict)
   17889       115920 :     return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
   17890              :   else
   17891              :     return NULL;
   17892              : }
   17893              : 
   17894              : /* Helper function for dw_loc_list.  Compute proper Dwarf location descriptor
   17895              :    for VAR_LOC_NOTE for variable DECL that has been optimized by SRA.  */
   17896              : 
   17897              : static dw_loc_descr_ref
   17898      2875151 : dw_sra_loc_expr (tree decl, rtx loc)
   17899              : {
   17900      2875151 :   rtx p;
   17901      2875151 :   unsigned HOST_WIDE_INT padsize = 0;
   17902      2875151 :   dw_loc_descr_ref descr, *descr_tail;
   17903      2875151 :   unsigned HOST_WIDE_INT decl_size;
   17904      2875151 :   rtx varloc;
   17905      2875151 :   enum var_init_status initialized;
   17906              : 
   17907      2875151 :   if (DECL_SIZE (decl) == NULL
   17908      2875151 :       || !tree_fits_uhwi_p (DECL_SIZE (decl)))
   17909              :     return NULL;
   17910              : 
   17911      2875151 :   decl_size = tree_to_uhwi (DECL_SIZE (decl));
   17912      2875151 :   descr = NULL;
   17913      2875151 :   descr_tail = &descr;
   17914              : 
   17915      9231810 :   for (p = loc; p; p = XEXP (p, 1))
   17916              :     {
   17917      6357209 :       unsigned HOST_WIDE_INT bitsize = decl_piece_bitsize (p);
   17918      6357209 :       rtx loc_note = *decl_piece_varloc_ptr (p);
   17919      6357209 :       dw_loc_descr_ref cur_descr;
   17920      6357209 :       dw_loc_descr_ref *tail, last = NULL;
   17921      6357209 :       unsigned HOST_WIDE_INT opsize = 0;
   17922              : 
   17923      6357209 :       if (loc_note == NULL_RTX
   17924      5967754 :           || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
   17925              :         {
   17926      2681958 :           padsize += bitsize;
   17927      2694840 :           continue;
   17928              :         }
   17929      3675251 :       initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
   17930      3675251 :       varloc = NOTE_VAR_LOCATION (loc_note);
   17931      3675251 :       cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
   17932      3675251 :       if (cur_descr == NULL)
   17933              :         {
   17934        12882 :           padsize += bitsize;
   17935        12882 :           continue;
   17936              :         }
   17937              : 
   17938              :       /* Check that cur_descr either doesn't use
   17939              :          DW_OP_*piece operations, or their sum is equal
   17940              :          to bitsize.  Otherwise we can't embed it.  */
   17941      8777670 :       for (tail = &cur_descr; *tail != NULL;
   17942      5115301 :            tail = &(*tail)->dw_loc_next)
   17943      5115301 :         if ((*tail)->dw_loc_opc == DW_OP_piece)
   17944              :           {
   17945        17408 :             opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
   17946        17408 :                       * BITS_PER_UNIT;
   17947        17408 :             last = *tail;
   17948              :           }
   17949      5097893 :         else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
   17950              :           {
   17951            0 :             opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
   17952            0 :             last = *tail;
   17953              :           }
   17954              : 
   17955      3662369 :       if (last != NULL && opsize != bitsize)
   17956              :         {
   17957            0 :           padsize += bitsize;
   17958              :           /* Discard the current piece of the descriptor and release any
   17959              :              addr_table entries it uses.  */
   17960            0 :           remove_loc_list_addr_table_entries (cur_descr);
   17961            0 :           continue;
   17962              :         }
   17963              : 
   17964              :       /* If there is a hole, add DW_OP_*piece after empty DWARF
   17965              :          expression, which means that those bits are optimized out.  */
   17966      3662369 :       if (padsize)
   17967              :         {
   17968       464418 :           if (padsize > decl_size)
   17969              :             {
   17970            0 :               remove_loc_list_addr_table_entries (cur_descr);
   17971          550 :               goto discard_descr;
   17972              :             }
   17973       464418 :           decl_size -= padsize;
   17974       464418 :           *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
   17975       464418 :           if (*descr_tail == NULL)
   17976              :             {
   17977            0 :               remove_loc_list_addr_table_entries (cur_descr);
   17978            0 :               goto discard_descr;
   17979              :             }
   17980       464418 :           descr_tail = &(*descr_tail)->dw_loc_next;
   17981       464418 :           padsize = 0;
   17982              :         }
   17983      3662369 :       *descr_tail = cur_descr;
   17984      3662369 :       descr_tail = tail;
   17985      3662369 :       if (bitsize > decl_size)
   17986            0 :         goto discard_descr;
   17987      3662369 :       decl_size -= bitsize;
   17988      3662369 :       if (last == NULL)
   17989              :         {
   17990      3653665 :           HOST_WIDE_INT offset = 0;
   17991      3653665 :           if (GET_CODE (varloc) == VAR_LOCATION
   17992      3653665 :               && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
   17993              :             {
   17994      3653665 :               varloc = PAT_VAR_LOCATION_LOC (varloc);
   17995      3653665 :               if (GET_CODE (varloc) == EXPR_LIST)
   17996            0 :                 varloc = XEXP (varloc, 0);
   17997              :             }
   17998      3659221 :           do
   17999              :             {
   18000      3659221 :               if (GET_CODE (varloc) == CONST
   18001      3656056 :                   || GET_CODE (varloc) == SIGN_EXTEND
   18002      3655650 :                   || GET_CODE (varloc) == ZERO_EXTEND)
   18003         4334 :                 varloc = XEXP (varloc, 0);
   18004      3654887 :               else if (GET_CODE (varloc) == SUBREG)
   18005         1222 :                 varloc = SUBREG_REG (varloc);
   18006              :               else
   18007              :                 break;
   18008              :             }
   18009              :           while (1);
   18010              :           /* DW_OP_bit_size offset should be zero for register
   18011              :              or implicit location descriptions and empty location
   18012              :              descriptions, but for memory addresses needs big endian
   18013              :              adjustment.  */
   18014      3653665 :           if (MEM_P (varloc))
   18015              :             {
   18016      1062276 :               unsigned HOST_WIDE_INT memsize;
   18017      1062279 :               if (!poly_uint64 (MEM_SIZE (varloc)).is_constant (&memsize))
   18018          550 :                 goto discard_descr;
   18019      1062276 :               memsize *= BITS_PER_UNIT;
   18020      1062276 :               if (memsize != bitsize)
   18021              :                 {
   18022         2428 :                   if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
   18023              :                       && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
   18024              :                     goto discard_descr;
   18025         2428 :                   if (memsize < bitsize)
   18026          550 :                     goto discard_descr;
   18027              :                   if (BITS_BIG_ENDIAN)
   18028              :                     offset = memsize - bitsize;
   18029              :                 }
   18030              :             }
   18031              : 
   18032      3653115 :           *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
   18033      3653115 :           if (*descr_tail == NULL)
   18034            0 :             goto discard_descr;
   18035      3653115 :           descr_tail = &(*descr_tail)->dw_loc_next;
   18036              :         }
   18037              :     }
   18038              : 
   18039              :   /* If there were any non-empty expressions, add padding till the end of
   18040              :      the decl.  */
   18041      2874601 :   if (descr != NULL && decl_size != 0)
   18042              :     {
   18043       607057 :       *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
   18044       607057 :       if (*descr_tail == NULL)
   18045            0 :         goto discard_descr;
   18046              :     }
   18047      2874601 :   return descr;
   18048              : 
   18049          550 : discard_descr:
   18050              :   /* Discard the descriptor and release any addr_table entries it uses.  */
   18051          550 :   remove_loc_list_addr_table_entries (descr);
   18052          550 :   return NULL;
   18053              : }
   18054              : 
   18055              : /* Return the dwarf representation of the location list LOC_LIST of
   18056              :    DECL.  WANT_ADDRESS has the same meaning as in loc_list_from_tree
   18057              :    function.  */
   18058              : 
   18059              : static dw_loc_list_ref
   18060     14204104 : dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
   18061              : {
   18062     14204104 :   const char *endname, *secname;
   18063     14204104 :   var_loc_view endview;
   18064     14204104 :   rtx varloc;
   18065     14204104 :   enum var_init_status initialized;
   18066     14204104 :   struct var_loc_node *node;
   18067     14204104 :   dw_loc_descr_ref descr;
   18068     14204104 :   char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
   18069     14204104 :   dw_loc_list_ref list = NULL;
   18070     14204104 :   dw_loc_list_ref *listp = &list;
   18071              : 
   18072              :   /* Now that we know what section we are using for a base,
   18073              :      actually construct the list of locations.
   18074              :      The first location information is what is passed to the
   18075              :      function that creates the location list, and the remaining
   18076              :      locations just get added on to that list.
   18077              :      Note that we only know the start address for a location
   18078              :      (IE location changes), so to build the range, we use
   18079              :      the range [current location start, next location start].
   18080              :      This means we have to special case the last node, and generate
   18081              :      a range of [last location start, end of function label].  */
   18082              : 
   18083     14204104 :   if (cfun && crtl->has_bb_partition)
   18084              :     {
   18085      4159956 :       bool save_in_cold_section_p = in_cold_section_p;
   18086      4159956 :       in_cold_section_p = first_function_block_is_cold;
   18087      4159956 :       if (loc_list->last_before_switch == NULL)
   18088       290775 :         in_cold_section_p = !in_cold_section_p;
   18089      4159956 :       secname = secname_for_decl (decl);
   18090      4159956 :       in_cold_section_p = save_in_cold_section_p;
   18091      4159956 :     }
   18092              :   else
   18093     10044148 :     secname = secname_for_decl (decl);
   18094              : 
   18095     61833700 :   for (node = loc_list->first; node; node = node->next)
   18096              :     {
   18097     47629596 :       bool range_across_switch = false;
   18098     47629596 :       if (GET_CODE (node->loc) == EXPR_LIST
   18099     44760059 :           || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
   18100              :         {
   18101     28866416 :           if (GET_CODE (node->loc) == EXPR_LIST)
   18102              :             {
   18103      2869537 :               descr = NULL;
   18104              :               /* This requires DW_OP_{,bit_}piece, which is not usable
   18105              :                  inside DWARF expressions.  */
   18106      2869537 :               if (want_address == 2)
   18107      2869537 :                 descr = dw_sra_loc_expr (decl, node->loc);
   18108              :             }
   18109              :           else
   18110              :             {
   18111     25996879 :               initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
   18112     25996879 :               varloc = NOTE_VAR_LOCATION (node->loc);
   18113     25996879 :               descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
   18114              :             }
   18115     28866416 :           if (descr)
   18116              :             {
   18117              :               /* If section switch happens in between node->label
   18118              :                  and node->next->label (or end of function) and
   18119              :                  we can't emit it as a single entry list,
   18120              :                  emit two ranges, first one ending at the end
   18121              :                  of first partition and second one starting at the
   18122              :                  beginning of second partition.  */
   18123     27470899 :               if (node == loc_list->last_before_switch
   18124       155704 :                   && (node != loc_list->first || loc_list->first->next
   18125              :                       /* If we are to emit a view number, we will emit
   18126              :                          a loclist rather than a single location
   18127              :                          expression for the entire function (see
   18128              :                          loc_list_has_views), so we have to split the
   18129              :                          range that straddles across partitions.  */
   18130         7730 :                       || !ZERO_VIEW_P (node->view))
   18131     27623922 :                   && current_function_decl)
   18132              :                 {
   18133       153023 :                   endname = cfun->fde->dw_fde_end;
   18134       153023 :                   endview = 0;
   18135       153023 :                   range_across_switch = true;
   18136              :                 }
   18137              :               /* The variable has a location between NODE->LABEL and
   18138              :                  NODE->NEXT->LABEL.  */
   18139     27317876 :               else if (node->next)
   18140     25898467 :                 endname = node->next->label, endview = node->next->view;
   18141              :               /* If the variable has a location at the last label
   18142              :                  it keeps its location until the end of function.  */
   18143      1419409 :               else if (!current_function_decl)
   18144              :                 endname = text_end_label, endview = 0;
   18145              :               else
   18146              :                 {
   18147      1419409 :                   ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
   18148              :                                                current_function_funcdef_no);
   18149      1419409 :                   endname = ggc_strdup (label_id);
   18150      1419409 :                   endview = 0;
   18151              :                 }
   18152              : 
   18153     27470899 :               *listp = new_loc_list (descr, node->label, node->view,
   18154              :                                      endname, endview, secname);
   18155     27470899 :               if (TREE_CODE (decl) == PARM_DECL
   18156      3163179 :                   && node == loc_list->first
   18157       934167 :                   && NOTE_P (node->loc)
   18158       925423 :                   && strcmp (node->label, endname) == 0)
   18159          425 :                 (*listp)->force = true;
   18160     27470899 :               listp = &(*listp)->dw_loc_next;
   18161              :             }
   18162              :         }
   18163              : 
   18164     47629596 :       if (cfun
   18165     47629596 :           && crtl->has_bb_partition
   18166     14139248 :           && node == loc_list->last_before_switch)
   18167              :         {
   18168      3869181 :           bool save_in_cold_section_p = in_cold_section_p;
   18169      3869181 :           in_cold_section_p = !first_function_block_is_cold;
   18170      3869181 :           secname = secname_for_decl (decl);
   18171      3869181 :           in_cold_section_p = save_in_cold_section_p;
   18172              :         }
   18173              : 
   18174     47629596 :       if (range_across_switch)
   18175              :         {
   18176       153023 :           if (GET_CODE (node->loc) == EXPR_LIST)
   18177         5614 :             descr = dw_sra_loc_expr (decl, node->loc);
   18178              :           else
   18179              :             {
   18180       147409 :               initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
   18181       147409 :               varloc = NOTE_VAR_LOCATION (node->loc);
   18182       147409 :               descr = dw_loc_list_1 (decl, varloc, want_address,
   18183              :                                      initialized);
   18184              :             }
   18185       153023 :           gcc_assert (descr);
   18186              :           /* The variable has a location between NODE->LABEL and
   18187              :              NODE->NEXT->LABEL.  */
   18188       153023 :           if (node->next)
   18189       111184 :             endname = node->next->label, endview = node->next->view;
   18190              :           else
   18191        41839 :             endname = cfun->fde->dw_fde_second_end, endview = 0;
   18192       153023 :           *listp = new_loc_list (descr, cfun->fde->dw_fde_second_begin, 0,
   18193              :                                  endname, endview, secname);
   18194       153023 :           listp = &(*listp)->dw_loc_next;
   18195              :         }
   18196              :     }
   18197              : 
   18198              :   /* Try to avoid the overhead of a location list emitting a location
   18199              :      expression instead, but only if we didn't have more than one
   18200              :      location entry in the first place.  If some entries were not
   18201              :      representable, we don't want to pretend a single entry that was
   18202              :      applies to the entire scope in which the variable is
   18203              :      available.  */
   18204     14204104 :   if (list && loc_list->first->next)
   18205     12763059 :     gen_llsym (list);
   18206              :   else
   18207      1441045 :     maybe_gen_llsym (list);
   18208              : 
   18209     14204104 :   return list;
   18210              : }
   18211              : 
   18212              : /* Return true if the loc_list has only single element and thus
   18213              :    can be represented as location description.   */
   18214              : 
   18215              : static bool
   18216     13923835 : single_element_loc_list_p (dw_loc_list_ref list)
   18217              : {
   18218     13923835 :   gcc_assert (!list->dw_loc_next || list->ll_symbol);
   18219     13923835 :   return !list->ll_symbol;
   18220              : }
   18221              : 
   18222              : /* Duplicate a single element of location list.  */
   18223              : 
   18224              : static inline dw_loc_descr_ref
   18225        44430 : copy_loc_descr (dw_loc_descr_ref ref)
   18226              : {
   18227        44430 :   dw_loc_descr_ref copy = ggc_alloc<dw_loc_descr_node> ();
   18228        44430 :   memcpy (copy, ref, sizeof (dw_loc_descr_node));
   18229        44430 :   return copy;
   18230              : }
   18231              : 
   18232              : /* To each location in list LIST append loc descr REF.  */
   18233              : 
   18234              : static void
   18235       277698 : add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
   18236              : {
   18237       277698 :   dw_loc_descr_ref copy;
   18238       277698 :   add_loc_descr (&list->expr, ref);
   18239       277698 :   list = list->dw_loc_next;
   18240       322128 :   while (list)
   18241              :     {
   18242        44430 :       copy = copy_loc_descr (ref);
   18243        44430 :       add_loc_descr (&list->expr, copy);
   18244        44430 :       while (copy->dw_loc_next)
   18245            0 :         copy = copy->dw_loc_next = copy_loc_descr (copy->dw_loc_next);
   18246        44430 :       list = list->dw_loc_next;
   18247              :     }
   18248       277698 : }
   18249              : 
   18250              : /* To each location in list LIST prepend loc descr REF.  */
   18251              : 
   18252              : static void
   18253            0 : prepend_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
   18254              : {
   18255            0 :   dw_loc_descr_ref copy;
   18256            0 :   dw_loc_descr_ref ref_end = list->expr;
   18257            0 :   add_loc_descr (&ref, list->expr);
   18258            0 :   list->expr = ref;
   18259            0 :   list = list->dw_loc_next;
   18260            0 :   while (list)
   18261              :     {
   18262            0 :       dw_loc_descr_ref end = list->expr;
   18263            0 :       list->expr = copy = copy_loc_descr (ref);
   18264            0 :       while (copy->dw_loc_next != ref_end)
   18265            0 :         copy = copy->dw_loc_next = copy_loc_descr (copy->dw_loc_next);
   18266            0 :       copy->dw_loc_next = end;
   18267            0 :       list = list->dw_loc_next;
   18268              :     }
   18269            0 : }
   18270              : 
   18271              : /* Given two lists RET and LIST
   18272              :    produce location list that is result of adding expression in LIST
   18273              :    to expression in RET on each position in program.
   18274              :    Might be destructive on both RET and LIST.
   18275              : 
   18276              :    TODO: We handle only simple cases of RET or LIST having at most one
   18277              :    element.  General case would involve sorting the lists in program order
   18278              :    and merging them that will need some additional work.
   18279              :    Adding that will improve quality of debug info especially for SRA-ed
   18280              :    structures.  */
   18281              : 
   18282              : static void
   18283        51380 : add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
   18284              : {
   18285        51380 :   if (!list)
   18286              :     return;
   18287        51380 :   if (!*ret)
   18288              :     {
   18289            0 :       *ret = list;
   18290            0 :       return;
   18291              :     }
   18292        51380 :   if (!list->dw_loc_next)
   18293              :     {
   18294        51380 :       add_loc_descr_to_each (*ret, list->expr);
   18295        51380 :       return;
   18296              :     }
   18297            0 :   if (!(*ret)->dw_loc_next)
   18298              :     {
   18299            0 :       prepend_loc_descr_to_each (list, (*ret)->expr);
   18300            0 :       *ret = list;
   18301            0 :       return;
   18302              :     }
   18303            0 :   expansion_failed (NULL_TREE, NULL_RTX,
   18304              :                     "Don't know how to merge two non-trivial"
   18305              :                     " location lists.\n");
   18306            0 :   *ret = NULL;
   18307            0 :   return;
   18308              : }
   18309              : 
   18310              : /* LOC is constant expression.  Try a luck, look it up in constant
   18311              :    pool and return its loc_descr of its address.  */
   18312              : 
   18313              : static dw_loc_descr_ref
   18314        14145 : cst_pool_loc_descr (tree loc)
   18315              : {
   18316              :   /* Get an RTL for this, if something has been emitted.  */
   18317        14145 :   rtx rtl = lookup_constant_def (loc);
   18318              : 
   18319        14145 :   if (!rtl || !MEM_P (rtl))
   18320              :     {
   18321            0 :       gcc_assert (!rtl);
   18322              :       return 0;
   18323              :     }
   18324        10834 :   gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
   18325              : 
   18326              :   /* TODO: We might get more coverage if we was actually delaying expansion
   18327              :      of all expressions till end of compilation when constant pools are fully
   18328              :      populated.  */
   18329        10834 :   if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
   18330              :     {
   18331            0 :       expansion_failed (loc, NULL_RTX,
   18332              :                         "CST value in constant pool but not marked.");
   18333            0 :       return 0;
   18334              :     }
   18335        10834 :   return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
   18336        10834 :                              GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
   18337              : }
   18338              : 
   18339              : /* Return dw_loc_list representing address of addr_expr LOC
   18340              :    by looking for inner INDIRECT_REF expression and turning
   18341              :    it into simple arithmetics.
   18342              : 
   18343              :    See loc_list_from_tree for the meaning of CONTEXT.  */
   18344              : 
   18345              : static dw_loc_list_ref
   18346         2211 : loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev,
   18347              :                                                    loc_descr_context *context)
   18348              : {
   18349         2211 :   tree obj, offset;
   18350         2211 :   poly_int64 bitsize, bitpos, bytepos;
   18351         2211 :   machine_mode mode;
   18352         2211 :   int unsignedp, reversep, volatilep = 0;
   18353         2211 :   dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
   18354              : 
   18355         2211 :   obj = get_inner_reference (TREE_OPERAND (loc, 0),
   18356              :                              &bitsize, &bitpos, &offset, &mode,
   18357              :                              &unsignedp, &reversep, &volatilep);
   18358         2211 :   STRIP_NOPS (obj);
   18359         4422 :   if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
   18360              :     {
   18361            0 :       expansion_failed (loc, NULL_RTX, "bitfield access");
   18362            0 :       return 0;
   18363              :     }
   18364         2211 :   if (!INDIRECT_REF_P (obj))
   18365              :     {
   18366         2211 :       expansion_failed (obj,
   18367              :                         NULL_RTX, "no indirect ref in inner reference");
   18368         2211 :       return 0;
   18369              :     }
   18370            0 :   if (!offset && known_eq (bitpos, 0))
   18371            0 :     list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1,
   18372              :                                    context);
   18373            0 :   else if (toplev
   18374            0 :            && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
   18375            0 :            && (dwarf_version >= 4 || !dwarf_strict))
   18376              :     {
   18377            0 :       list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0, context);
   18378            0 :       if (!list_ret)
   18379         2211 :         return 0;
   18380            0 :       if (offset)
   18381              :         {
   18382              :           /* Variable offset.  */
   18383            0 :           list_ret1 = loc_list_from_tree (offset, 0, context);
   18384            0 :           if (list_ret1 == 0)
   18385              :             return 0;
   18386            0 :           add_loc_list (&list_ret, list_ret1);
   18387            0 :           if (!list_ret)
   18388              :             return 0;
   18389            0 :           add_loc_descr_to_each (list_ret,
   18390              :                                  new_loc_descr (DW_OP_plus, 0, 0));
   18391              :         }
   18392            0 :       HOST_WIDE_INT value;
   18393            0 :       if (bytepos.is_constant (&value) && value > 0)
   18394            0 :         add_loc_descr_to_each (list_ret,
   18395              :                                new_loc_descr (DW_OP_plus_uconst, value, 0));
   18396            0 :       else if (maybe_ne (bytepos, 0))
   18397            0 :         loc_list_plus_const (list_ret, bytepos);
   18398            0 :       add_loc_descr_to_each (list_ret,
   18399              :                              new_loc_descr (DW_OP_stack_value, 0, 0));
   18400              :     }
   18401            0 :   return list_ret;
   18402              : }
   18403              : 
   18404              : /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
   18405              :    all operations from LOC are nops, move to the last one.  Insert in NOPS all
   18406              :    operations that are skipped.  */
   18407              : 
   18408              : static void
   18409     60314645 : loc_descr_to_next_no_nop (dw_loc_descr_ref &loc,
   18410              :                           hash_set<dw_loc_descr_ref> &nops)
   18411              : {
   18412     60322107 :   while (loc->dw_loc_next != NULL && loc->dw_loc_opc == DW_OP_nop)
   18413              :     {
   18414         7462 :       nops.add (loc);
   18415         7462 :       loc = loc->dw_loc_next;
   18416              :     }
   18417     60314645 : }
   18418              : 
   18419              : /* Helper for loc_descr_without_nops: free the location description operation
   18420              :    P.  */
   18421              : 
   18422              : bool
   18423         3731 : free_loc_descr (const dw_loc_descr_ref &loc, void *data ATTRIBUTE_UNUSED)
   18424              : {
   18425         3731 :   ggc_free (loc);
   18426         3731 :   return true;
   18427              : }
   18428              : 
   18429              : /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
   18430              :    finishes LOC.  */
   18431              : 
   18432              : static void
   18433     28379709 : loc_descr_without_nops (dw_loc_descr_ref &loc)
   18434              : {
   18435     28379709 :   if (loc->dw_loc_opc == DW_OP_nop && loc->dw_loc_next == NULL)
   18436            0 :     return;
   18437              : 
   18438              :   /* Set of all DW_OP_nop operations we remove.  */
   18439     28379709 :   hash_set<dw_loc_descr_ref> nops;
   18440              : 
   18441              :   /* First, strip all prefix NOP operations in order to keep the head of the
   18442              :      operations list.  */
   18443     28379709 :   loc_descr_to_next_no_nop (loc, nops);
   18444              : 
   18445     87288040 :   for (dw_loc_descr_ref cur = loc; cur != NULL;)
   18446              :     {
   18447              :       /* For control flow operations: strip "prefix" nops in destination
   18448              :          labels.  */
   18449     58908331 :       if (cur->dw_loc_oprnd1.val_class == dw_val_class_loc)
   18450      1406314 :         loc_descr_to_next_no_nop (cur->dw_loc_oprnd1.v.val_loc, nops);
   18451     58908331 :       if (cur->dw_loc_oprnd2.val_class == dw_val_class_loc)
   18452            0 :         loc_descr_to_next_no_nop (cur->dw_loc_oprnd2.v.val_loc, nops);
   18453              : 
   18454              :       /* Do the same for the operations that follow, then move to the next
   18455              :          iteration.  */
   18456     58908331 :       if (cur->dw_loc_next != NULL)
   18457     30528622 :         loc_descr_to_next_no_nop (cur->dw_loc_next, nops);
   18458     58908331 :       cur = cur->dw_loc_next;
   18459              :     }
   18460              : 
   18461     28383440 :   nops.traverse<void *, free_loc_descr> (NULL);
   18462     28379709 : }
   18463              : 
   18464              : 
   18465              : struct dwarf_procedure_info;
   18466              : 
   18467              : /* Helper structure for location descriptions generation.  */
   18468              : struct loc_descr_context
   18469              : {
   18470              :   /* The type that is implicitly referenced by DW_OP_push_object_address, or
   18471              :      NULL_TREE if DW_OP_push_object_address in invalid for this location
   18472              :      description.  This is used when processing PLACEHOLDER_EXPR nodes.  */
   18473              :   tree context_type;
   18474              :   /* The ..._DECL node that should be translated as a
   18475              :      DW_OP_push_object_address operation.  */
   18476              :   tree base_decl;
   18477              :   /* Information about the DWARF procedure we are currently generating. NULL if
   18478              :      we are not generating a DWARF procedure.  */
   18479              :   struct dwarf_procedure_info *dpi;
   18480              :   /* True if integral PLACEHOLDER_EXPR stands for the first argument passed
   18481              :      by consumer.  Used for DW_TAG_generic_subrange attributes.  */
   18482              :   bool placeholder_arg;
   18483              :   /* True if PLACEHOLDER_EXPR has been seen.  */
   18484              :   bool placeholder_seen;
   18485              :   /* True if strict preservation of signedness has been requested.  */
   18486              :   bool strict_signedness;
   18487              : };
   18488              : 
   18489              : /* DWARF procedures generation
   18490              : 
   18491              :    DWARF expressions (aka. location descriptions) are used to encode variable
   18492              :    things such as sizes or offsets.  Such computations can have redundant parts
   18493              :    that can be factorized in order to reduce the size of the output debug
   18494              :    information.  This is the whole point of DWARF procedures.
   18495              : 
   18496              :    Thanks to stor-layout.cc, size and offset expressions in GENERIC trees are
   18497              :    already factorized into functions ("size functions") in order to handle very
   18498              :    big and complex types.  Such functions are quite simple: they have integral
   18499              :    arguments, they return an integral result and their body contains only a
   18500              :    return statement with arithmetic expressions.  This is the only kind of
   18501              :    function we are interested in translating into DWARF procedures, here.
   18502              : 
   18503              :    DWARF expressions and DWARF procedure are executed using a stack, so we have
   18504              :    to define some calling convention for them to interact.  Let's say that:
   18505              : 
   18506              :    - Before calling a DWARF procedure, DWARF expressions must push on the stack
   18507              :      all arguments in reverse order (right-to-left) so that when the DWARF
   18508              :      procedure execution starts, the first argument is the top of the stack.
   18509              : 
   18510              :    - Then, when returning, the DWARF procedure must have consumed all arguments
   18511              :      on the stack, must have pushed the result and touched nothing else.
   18512              : 
   18513              :    - Each integral argument and the result are integral types can be hold in a
   18514              :      single stack slot.
   18515              : 
   18516              :    - We call "frame offset" the number of stack slots that are "under DWARF
   18517              :      procedure control": it includes the arguments slots, the temporaries and
   18518              :      the result slot. Thus, it is equal to the number of arguments when the
   18519              :      procedure execution starts and must be equal to one (the result) when it
   18520              :      returns.  */
   18521              : 
   18522              : /* Helper structure used when generating operations for a DWARF procedure.  */
   18523              : struct dwarf_procedure_info
   18524              : {
   18525              :   /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
   18526              :      currently translated.  */
   18527              :   tree fndecl;
   18528              :   /* The number of arguments FNDECL takes.  */
   18529              :   unsigned args_count;
   18530              : };
   18531              : 
   18532              : /* Return a pointer to a newly created DIE node for a DWARF procedure.  Add
   18533              :    LOCATION as its DW_AT_location attribute.  If FNDECL is not NULL_TREE,
   18534              :    equate it to this DIE.  */
   18535              : 
   18536              : static dw_die_ref
   18537            0 : new_dwarf_proc_die (dw_loc_descr_ref location, tree fndecl,
   18538              :                     dw_die_ref parent_die)
   18539              : {
   18540            0 :   dw_die_ref dwarf_proc_die;
   18541              : 
   18542            0 :   if ((dwarf_version < 3 && dwarf_strict)
   18543            0 :       || location == NULL)
   18544              :     return NULL;
   18545              : 
   18546            0 :   dwarf_proc_die = new_die (DW_TAG_dwarf_procedure, parent_die, fndecl);
   18547            0 :   if (fndecl)
   18548            0 :     equate_decl_number_to_die (fndecl, dwarf_proc_die);
   18549            0 :   add_AT_loc (dwarf_proc_die, DW_AT_location, location);
   18550            0 :   return dwarf_proc_die;
   18551              : }
   18552              : 
   18553              : /* Return whether TYPE is a supported type as a DWARF procedure argument
   18554              :    type or return type (we handle only scalar types and pointer types that
   18555              :    aren't wider than the DWARF expression evaluation stack).  */
   18556              : 
   18557              : static bool
   18558           36 : is_handled_procedure_type (tree type)
   18559              : {
   18560           36 :   return ((INTEGRAL_TYPE_P (type)
   18561           36 :            || TREE_CODE (type) == OFFSET_TYPE
   18562            0 :            || TREE_CODE (type) == POINTER_TYPE)
   18563           36 :           && int_size_in_bytes (type) <= DWARF2_ADDR_SIZE);
   18564              : }
   18565              : 
   18566              : /* Helper for resolve_args_picking: do the same but stop when coming across
   18567              :    visited nodes.  For each node we visit, register in FRAME_OFFSETS the frame
   18568              :    offset *before* evaluating the corresponding operation.  */
   18569              : 
   18570              : static bool
   18571         3390 : resolve_args_picking_1 (dw_loc_descr_ref loc, unsigned initial_frame_offset,
   18572              :                         struct dwarf_procedure_info *dpi,
   18573              :                         hash_map<dw_loc_descr_ref, unsigned> &frame_offsets)
   18574              : {
   18575              :   /* The "frame_offset" identifier is already used to name a macro... */
   18576         3390 :   unsigned frame_offset_ = initial_frame_offset;
   18577         3390 :   dw_loc_descr_ref l;
   18578              : 
   18579        32824 :   for (l = loc; l != NULL;)
   18580              :     {
   18581        29434 :       bool existed;
   18582        29434 :       unsigned &l_frame_offset = frame_offsets.get_or_insert (l, &existed);
   18583              : 
   18584              :       /* If we already met this node, there is nothing to compute anymore.  */
   18585        29434 :       if (existed)
   18586              :         {
   18587              :           /* Make sure that the stack size is consistent wherever the execution
   18588              :              flow comes from.  */
   18589            0 :           gcc_assert ((unsigned) l_frame_offset == frame_offset_);
   18590            0 :           break;
   18591              :         }
   18592        29434 :       l_frame_offset = frame_offset_;
   18593              : 
   18594              :       /* If needed, relocate the picking offset with respect to the frame
   18595              :          offset. */
   18596        29434 :       if (l->dw_loc_frame_offset_rel)
   18597              :         {
   18598         3390 :           unsigned HOST_WIDE_INT off;
   18599         3390 :           switch (l->dw_loc_opc)
   18600              :             {
   18601         3390 :             case DW_OP_pick:
   18602         3390 :               off = l->dw_loc_oprnd1.v.val_unsigned;
   18603         3390 :               break;
   18604              :             case DW_OP_dup:
   18605              :               off = 0;
   18606              :               break;
   18607            0 :             case DW_OP_over:
   18608            0 :               off = 1;
   18609            0 :               break;
   18610            0 :             default:
   18611            0 :               gcc_unreachable ();
   18612              :             }
   18613              :           /* frame_offset_ is the size of the current stack frame, including
   18614              :              incoming arguments. Besides, the arguments are pushed
   18615              :              right-to-left.  Thus, in order to access the Nth argument from
   18616              :              this operation node, the picking has to skip temporaries *plus*
   18617              :              one stack slot per argument (0 for the first one, 1 for the second
   18618              :              one, etc.).
   18619              : 
   18620              :              The targeted argument number (N) is already set as the operand,
   18621              :              and the number of temporaries can be computed with:
   18622              :                frame_offsets_ - dpi->args_count */
   18623         3390 :           off += frame_offset_ - dpi->args_count;
   18624              : 
   18625              :           /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)...  */
   18626         3390 :           if (off > 255)
   18627            0 :             return false;
   18628              : 
   18629         3390 :           if (off == 0)
   18630              :             {
   18631            0 :               l->dw_loc_opc = DW_OP_dup;
   18632            0 :               l->dw_loc_oprnd1.v.val_unsigned = 0;
   18633              :             }
   18634         3390 :           else if (off == 1)
   18635              :             {
   18636         3390 :               l->dw_loc_opc = DW_OP_over;
   18637         3390 :               l->dw_loc_oprnd1.v.val_unsigned = 0;
   18638              :             }
   18639              :           else
   18640              :             {
   18641            0 :               l->dw_loc_opc = DW_OP_pick;
   18642            0 :               l->dw_loc_oprnd1.v.val_unsigned = off;
   18643              :             }
   18644              :         }
   18645              : 
   18646              :       /* Update frame_offset according to the effect the current operation has
   18647              :          on the stack.  */
   18648        29434 :       switch (l->dw_loc_opc)
   18649              :         {
   18650              :         case DW_OP_deref:
   18651              :         case DW_OP_swap:
   18652              :         case DW_OP_rot:
   18653              :         case DW_OP_abs:
   18654              :         case DW_OP_neg:
   18655              :         case DW_OP_not:
   18656              :         case DW_OP_plus_uconst:
   18657              :         case DW_OP_skip:
   18658              :         case DW_OP_reg0:
   18659              :         case DW_OP_reg1:
   18660              :         case DW_OP_reg2:
   18661              :         case DW_OP_reg3:
   18662              :         case DW_OP_reg4:
   18663              :         case DW_OP_reg5:
   18664              :         case DW_OP_reg6:
   18665              :         case DW_OP_reg7:
   18666              :         case DW_OP_reg8:
   18667              :         case DW_OP_reg9:
   18668              :         case DW_OP_reg10:
   18669              :         case DW_OP_reg11:
   18670              :         case DW_OP_reg12:
   18671              :         case DW_OP_reg13:
   18672              :         case DW_OP_reg14:
   18673              :         case DW_OP_reg15:
   18674              :         case DW_OP_reg16:
   18675              :         case DW_OP_reg17:
   18676              :         case DW_OP_reg18:
   18677              :         case DW_OP_reg19:
   18678              :         case DW_OP_reg20:
   18679              :         case DW_OP_reg21:
   18680              :         case DW_OP_reg22:
   18681              :         case DW_OP_reg23:
   18682              :         case DW_OP_reg24:
   18683              :         case DW_OP_reg25:
   18684              :         case DW_OP_reg26:
   18685              :         case DW_OP_reg27:
   18686              :         case DW_OP_reg28:
   18687              :         case DW_OP_reg29:
   18688              :         case DW_OP_reg30:
   18689              :         case DW_OP_reg31:
   18690              :         case DW_OP_bregx:
   18691              :         case DW_OP_piece:
   18692              :         case DW_OP_deref_size:
   18693              :         case DW_OP_nop:
   18694              :         case DW_OP_bit_piece:
   18695              :         case DW_OP_implicit_value:
   18696              :         case DW_OP_stack_value:
   18697              :         case DW_OP_deref_type:
   18698              :         case DW_OP_convert:
   18699              :         case DW_OP_reinterpret:
   18700              :         case DW_OP_GNU_deref_type:
   18701              :         case DW_OP_GNU_convert:
   18702              :         case DW_OP_GNU_reinterpret:
   18703              :           break;
   18704              : 
   18705        11300 :         case DW_OP_addr:
   18706        11300 :         case DW_OP_const1u:
   18707        11300 :         case DW_OP_const1s:
   18708        11300 :         case DW_OP_const2u:
   18709        11300 :         case DW_OP_const2s:
   18710        11300 :         case DW_OP_const4u:
   18711        11300 :         case DW_OP_const4s:
   18712        11300 :         case DW_OP_const8u:
   18713        11300 :         case DW_OP_const8s:
   18714        11300 :         case DW_OP_constu:
   18715        11300 :         case DW_OP_consts:
   18716        11300 :         case DW_OP_dup:
   18717        11300 :         case DW_OP_over:
   18718        11300 :         case DW_OP_pick:
   18719        11300 :         case DW_OP_lit0:
   18720        11300 :         case DW_OP_lit1:
   18721        11300 :         case DW_OP_lit2:
   18722        11300 :         case DW_OP_lit3:
   18723        11300 :         case DW_OP_lit4:
   18724        11300 :         case DW_OP_lit5:
   18725        11300 :         case DW_OP_lit6:
   18726        11300 :         case DW_OP_lit7:
   18727        11300 :         case DW_OP_lit8:
   18728        11300 :         case DW_OP_lit9:
   18729        11300 :         case DW_OP_lit10:
   18730        11300 :         case DW_OP_lit11:
   18731        11300 :         case DW_OP_lit12:
   18732        11300 :         case DW_OP_lit13:
   18733        11300 :         case DW_OP_lit14:
   18734        11300 :         case DW_OP_lit15:
   18735        11300 :         case DW_OP_lit16:
   18736        11300 :         case DW_OP_lit17:
   18737        11300 :         case DW_OP_lit18:
   18738        11300 :         case DW_OP_lit19:
   18739        11300 :         case DW_OP_lit20:
   18740        11300 :         case DW_OP_lit21:
   18741        11300 :         case DW_OP_lit22:
   18742        11300 :         case DW_OP_lit23:
   18743        11300 :         case DW_OP_lit24:
   18744        11300 :         case DW_OP_lit25:
   18745        11300 :         case DW_OP_lit26:
   18746        11300 :         case DW_OP_lit27:
   18747        11300 :         case DW_OP_lit28:
   18748        11300 :         case DW_OP_lit29:
   18749        11300 :         case DW_OP_lit30:
   18750        11300 :         case DW_OP_lit31:
   18751        11300 :         case DW_OP_breg0:
   18752        11300 :         case DW_OP_breg1:
   18753        11300 :         case DW_OP_breg2:
   18754        11300 :         case DW_OP_breg3:
   18755        11300 :         case DW_OP_breg4:
   18756        11300 :         case DW_OP_breg5:
   18757        11300 :         case DW_OP_breg6:
   18758        11300 :         case DW_OP_breg7:
   18759        11300 :         case DW_OP_breg8:
   18760        11300 :         case DW_OP_breg9:
   18761        11300 :         case DW_OP_breg10:
   18762        11300 :         case DW_OP_breg11:
   18763        11300 :         case DW_OP_breg12:
   18764        11300 :         case DW_OP_breg13:
   18765        11300 :         case DW_OP_breg14:
   18766        11300 :         case DW_OP_breg15:
   18767        11300 :         case DW_OP_breg16:
   18768        11300 :         case DW_OP_breg17:
   18769        11300 :         case DW_OP_breg18:
   18770        11300 :         case DW_OP_breg19:
   18771        11300 :         case DW_OP_breg20:
   18772        11300 :         case DW_OP_breg21:
   18773        11300 :         case DW_OP_breg22:
   18774        11300 :         case DW_OP_breg23:
   18775        11300 :         case DW_OP_breg24:
   18776        11300 :         case DW_OP_breg25:
   18777        11300 :         case DW_OP_breg26:
   18778        11300 :         case DW_OP_breg27:
   18779        11300 :         case DW_OP_breg28:
   18780        11300 :         case DW_OP_breg29:
   18781        11300 :         case DW_OP_breg30:
   18782        11300 :         case DW_OP_breg31:
   18783        11300 :         case DW_OP_fbreg:
   18784        11300 :         case DW_OP_push_object_address:
   18785        11300 :         case DW_OP_call_frame_cfa:
   18786        11300 :         case DW_OP_GNU_variable_value:
   18787        11300 :         case DW_OP_GNU_addr_index:
   18788        11300 :         case DW_OP_GNU_const_index:
   18789        11300 :           ++frame_offset_;
   18790        11300 :           break;
   18791              : 
   18792         7910 :         case DW_OP_drop:
   18793         7910 :         case DW_OP_xderef:
   18794         7910 :         case DW_OP_and:
   18795         7910 :         case DW_OP_div:
   18796         7910 :         case DW_OP_minus:
   18797         7910 :         case DW_OP_mod:
   18798         7910 :         case DW_OP_mul:
   18799         7910 :         case DW_OP_or:
   18800         7910 :         case DW_OP_plus:
   18801         7910 :         case DW_OP_shl:
   18802         7910 :         case DW_OP_shr:
   18803         7910 :         case DW_OP_shra:
   18804         7910 :         case DW_OP_xor:
   18805         7910 :         case DW_OP_bra:
   18806         7910 :         case DW_OP_eq:
   18807         7910 :         case DW_OP_ge:
   18808         7910 :         case DW_OP_gt:
   18809         7910 :         case DW_OP_le:
   18810         7910 :         case DW_OP_lt:
   18811         7910 :         case DW_OP_ne:
   18812         7910 :         case DW_OP_regx:
   18813         7910 :         case DW_OP_xderef_size:
   18814         7910 :           --frame_offset_;
   18815         7910 :           break;
   18816              : 
   18817            0 :         case DW_OP_call2:
   18818            0 :         case DW_OP_call4:
   18819            0 :         case DW_OP_call_ref:
   18820            0 :           {
   18821            0 :             dw_die_ref dwarf_proc = l->dw_loc_oprnd1.v.val_die_ref.die;
   18822            0 :             int *stack_usage = dwarf_proc_stack_usage_map->get (dwarf_proc);
   18823              : 
   18824            0 :             if (stack_usage == NULL)
   18825            0 :               return false;
   18826            0 :             frame_offset_ += *stack_usage;
   18827            0 :             break;
   18828              :           }
   18829              : 
   18830            0 :         case DW_OP_implicit_pointer:
   18831            0 :         case DW_OP_entry_value:
   18832            0 :         case DW_OP_const_type:
   18833            0 :         case DW_OP_regval_type:
   18834            0 :         case DW_OP_form_tls_address:
   18835            0 :         case DW_OP_GNU_push_tls_address:
   18836            0 :         case DW_OP_GNU_uninit:
   18837            0 :         case DW_OP_GNU_encoded_addr:
   18838            0 :         case DW_OP_GNU_implicit_pointer:
   18839            0 :         case DW_OP_GNU_entry_value:
   18840            0 :         case DW_OP_GNU_const_type:
   18841            0 :         case DW_OP_GNU_regval_type:
   18842            0 :         case DW_OP_GNU_parameter_ref:
   18843              :           /* loc_list_from_tree will probably not output these operations for
   18844              :              size functions, so assume they will not appear here.  */
   18845              :           /* Fall through...  */
   18846              : 
   18847            0 :         default:
   18848            0 :           gcc_unreachable ();
   18849              :         }
   18850              : 
   18851              :       /* Now, follow the control flow (except subroutine calls).  */
   18852        29434 :       switch (l->dw_loc_opc)
   18853              :         {
   18854            0 :         case DW_OP_bra:
   18855            0 :           if (!resolve_args_picking_1 (l->dw_loc_next, frame_offset_, dpi,
   18856              :                                        frame_offsets))
   18857              :             return false;
   18858              :           /* Fall through. */
   18859              : 
   18860            0 :         case DW_OP_skip:
   18861            0 :           l = l->dw_loc_oprnd1.v.val_loc;
   18862            0 :           break;
   18863              : 
   18864              :         case DW_OP_stack_value:
   18865              :           return true;
   18866              : 
   18867        29434 :         default:
   18868        29434 :           l = l->dw_loc_next;
   18869        29434 :           break;
   18870              :         }
   18871              :     }
   18872              : 
   18873              :   return true;
   18874              : }
   18875              : 
   18876              : /* Make a DFS over operations reachable through LOC (i.e. follow branch
   18877              :    operations) in order to resolve the operand of DW_OP_pick operations that
   18878              :    target DWARF procedure arguments (DPI).  INITIAL_FRAME_OFFSET is the frame
   18879              :    offset *before* LOC is executed.  Return if all relocations were
   18880              :    successful.  */
   18881              : 
   18882              : static bool
   18883         3390 : resolve_args_picking (dw_loc_descr_ref loc, unsigned initial_frame_offset,
   18884              :                       struct dwarf_procedure_info *dpi)
   18885              : {
   18886              :   /* Associate to all visited operations the frame offset *before* evaluating
   18887              :      this operation.  */
   18888         3390 :   hash_map<dw_loc_descr_ref, unsigned> frame_offsets;
   18889              : 
   18890         3390 :   return
   18891         3390 :     resolve_args_picking_1 (loc, initial_frame_offset, dpi, frame_offsets);
   18892         3390 : }
   18893              : 
   18894              : /* Try to generate a DWARF procedure that computes the same result as FNDECL.
   18895              :    Return NULL if it is not possible.  */
   18896              : 
   18897              : static dw_die_ref
   18898           36 : function_to_dwarf_procedure (tree fndecl)
   18899              : {
   18900           36 :   struct dwarf_procedure_info dpi;
   18901           36 :   struct loc_descr_context ctx = {
   18902              :     NULL_TREE,  /* context_type */
   18903              :     NULL_TREE,  /* base_decl */
   18904              :     &dpi,   /* dpi */
   18905              :     false,      /* placeholder_arg */
   18906              :     false,      /* placeholder_seen */
   18907              :     true        /* strict_signedness */
   18908           36 :   };
   18909           36 :   dw_die_ref dwarf_proc_die;
   18910           36 :   tree tree_body = DECL_SAVED_TREE (fndecl);
   18911           36 :   dw_loc_descr_ref loc_body, epilogue;
   18912              : 
   18913           36 :   tree cursor;
   18914           36 :   unsigned i;
   18915              : 
   18916              :   /* Do not generate multiple DWARF procedures for the same function
   18917              :      declaration.  */
   18918           36 :   dwarf_proc_die = lookup_decl_die (fndecl);
   18919           36 :   if (dwarf_proc_die != NULL)
   18920              :     return dwarf_proc_die;
   18921              : 
   18922              :   /* DWARF procedures are available starting with the DWARFv3 standard.  */
   18923           32 :   if (dwarf_version < 3 && dwarf_strict)
   18924              :     return NULL;
   18925              : 
   18926              :   /* We handle only functions for which we still have a body, that return a
   18927              :      supported type and that takes arguments with supported types.  Note that
   18928              :      there is no point translating functions that return nothing.  */
   18929           32 :   if (tree_body == NULL_TREE
   18930            0 :       || DECL_RESULT (fndecl) == NULL_TREE
   18931           32 :       || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl))))
   18932              :     return NULL;
   18933              : 
   18934            0 :   for (cursor = DECL_ARGUMENTS (fndecl);
   18935            0 :        cursor != NULL_TREE;
   18936            0 :        cursor = TREE_CHAIN (cursor))
   18937            0 :     if (!is_handled_procedure_type (TREE_TYPE (cursor)))
   18938              :       return NULL;
   18939              : 
   18940              :   /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)).  */
   18941            0 :   if (TREE_CODE (tree_body) != RETURN_EXPR)
   18942              :     return NULL;
   18943            0 :   tree_body = TREE_OPERAND (tree_body, 0);
   18944            0 :   if (TREE_CODE (tree_body) != MODIFY_EXPR
   18945            0 :       || TREE_OPERAND (tree_body, 0) != DECL_RESULT (fndecl))
   18946              :     return NULL;
   18947            0 :   tree_body = TREE_OPERAND (tree_body, 1);
   18948              : 
   18949              :   /* Try to translate the body expression itself.  Note that this will probably
   18950              :      cause an infinite recursion if its call graph has a cycle.  This is very
   18951              :      unlikely for size functions, however, so don't bother with such things at
   18952              :      the moment.  */
   18953            0 :   dpi.fndecl = fndecl;
   18954            0 :   dpi.args_count = list_length (DECL_ARGUMENTS (fndecl));
   18955            0 :   loc_body = loc_descriptor_from_tree (tree_body, 0, &ctx);
   18956            0 :   if (!loc_body)
   18957              :     return NULL;
   18958              : 
   18959              :   /* After evaluating all operands in "loc_body", we should still have on the
   18960              :      stack all arguments plus the desired function result (top of the stack).
   18961              :      Generate code in order to keep only the result in our stack frame.  */
   18962              :   epilogue = NULL;
   18963            0 :   for (i = 0; i < dpi.args_count; ++i)
   18964              :     {
   18965            0 :       dw_loc_descr_ref op_couple = new_loc_descr (DW_OP_swap, 0, 0);
   18966            0 :       op_couple->dw_loc_next = new_loc_descr (DW_OP_drop, 0, 0);
   18967            0 :       op_couple->dw_loc_next->dw_loc_next = epilogue;
   18968            0 :       epilogue = op_couple;
   18969              :     }
   18970            0 :   add_loc_descr (&loc_body, epilogue);
   18971            0 :   if (!resolve_args_picking (loc_body, dpi.args_count, &dpi))
   18972              :     return NULL;
   18973              : 
   18974              :   /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
   18975              :      because they are considered useful.  Now there is an epilogue, they are
   18976              :      not anymore, so give it another try.   */
   18977            0 :   loc_descr_without_nops (loc_body);
   18978              : 
   18979              :   /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
   18980              :      a DW_TAG_dwarf_procedure, so we may have a conflict, here.  It's unlikely,
   18981              :      though, given that size functions do not come from source, so they should
   18982              :      not have a dedicated DW_TAG_subprogram DIE.  */
   18983            0 :   dwarf_proc_die
   18984            0 :     = new_dwarf_proc_die (loc_body, fndecl,
   18985            0 :                           get_context_die (DECL_CONTEXT (fndecl)));
   18986              : 
   18987              :   /* The called DWARF procedure consumes one stack slot per argument and
   18988              :      returns one stack slot.  */
   18989            0 :   dwarf_proc_stack_usage_map->put (dwarf_proc_die, 1 - dpi.args_count);
   18990              : 
   18991            0 :   return dwarf_proc_die;
   18992              : }
   18993              : 
   18994              : /* Helper function for loc_list_from_tree.  Perform OP binary op,
   18995              :    but after converting arguments to type_die, afterwards convert
   18996              :    back to unsigned.  */
   18997              : 
   18998              : static dw_loc_list_ref
   18999            0 : typed_binop_from_tree (enum dwarf_location_atom op, tree loc,
   19000              :                        dw_die_ref type_die, scalar_int_mode mode,
   19001              :                        struct loc_descr_context *context)
   19002              : {
   19003            0 :   dw_loc_list_ref op0, op1;
   19004            0 :   dw_loc_descr_ref cvt, binop;
   19005              : 
   19006            0 :   if (type_die == NULL)
   19007              :     return NULL;
   19008              : 
   19009            0 :   op0 = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
   19010            0 :   op1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
   19011            0 :   if (op0 == NULL || op1 == NULL)
   19012              :     return NULL;
   19013              : 
   19014            0 :   cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   19015            0 :   cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   19016            0 :   cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   19017            0 :   cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   19018            0 :   add_loc_descr_to_each (op0, cvt);
   19019              : 
   19020            0 :   cvt = new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0);
   19021            0 :   cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   19022            0 :   cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
   19023            0 :   cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
   19024            0 :   add_loc_descr_to_each (op1, cvt);
   19025              : 
   19026            0 :   add_loc_list (&op0, op1);
   19027            0 :   if (op0 == NULL)
   19028              :     return NULL;
   19029              : 
   19030            0 :   binop = new_loc_descr (op, 0, 0);
   19031            0 :   convert_descriptor_to_mode (mode, binop);
   19032            0 :   add_loc_descr_to_each (op0, binop);
   19033              : 
   19034            0 :   return op0;
   19035              : }
   19036              : 
   19037              : /* Generate Dwarf location list representing LOC.
   19038              :    If WANT_ADDRESS is false, expression computing LOC will be computed
   19039              :    If WANT_ADDRESS is 1, expression computing address of LOC will be returned
   19040              :    if WANT_ADDRESS is 2, expression computing address usable in location
   19041              :      will be returned (i.e. DW_OP_reg can be used
   19042              :      to refer to register values).
   19043              : 
   19044              :    CONTEXT provides information to customize the location descriptions
   19045              :    generation.  Its context_type field specifies what type is implicitly
   19046              :    referenced by DW_OP_push_object_address.  If it is NULL_TREE, this operation
   19047              :    will not be generated.
   19048              : 
   19049              :    Its DPI field determines whether we are generating a DWARF expression for a
   19050              :    DWARF procedure, so PARM_DECL references are processed specifically.
   19051              : 
   19052              :    If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
   19053              :    and dpi fields were null.  */
   19054              : 
   19055              : static dw_loc_list_ref
   19056     17954309 : loc_list_from_tree_1 (tree loc, int want_address,
   19057              :                       struct loc_descr_context *context)
   19058              : {
   19059     18215517 :   dw_loc_descr_ref ret = NULL, ret1 = NULL;
   19060     18215517 :   dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
   19061     18215517 :   int have_address = 0;
   19062     18215517 :   enum dwarf_location_atom op;
   19063              : 
   19064              :   /* ??? Most of the time we do not take proper care for sign/zero
   19065              :      extending the values properly.  Hopefully this won't be a real
   19066              :      problem...  */
   19067              : 
   19068     18215517 :   if (context != NULL
   19069       407600 :       && context->base_decl == loc
   19070       101782 :       && want_address == 0)
   19071              :     {
   19072       101782 :       if (dwarf_version >= 3 || !dwarf_strict)
   19073       101782 :         return new_loc_list (new_loc_descr (DW_OP_push_object_address, 0, 0),
   19074       101782 :                              NULL, 0, NULL, 0, NULL);
   19075              :       else
   19076              :         return NULL;
   19077              :     }
   19078              : 
   19079     18113735 :   switch (TREE_CODE (loc))
   19080              :     {
   19081            0 :     case ERROR_MARK:
   19082            0 :       expansion_failed (loc, NULL_RTX, "ERROR_MARK");
   19083            0 :       return 0;
   19084              : 
   19085         6780 :     case PLACEHOLDER_EXPR:
   19086              :       /* This case involves extracting fields from an object to determine the
   19087              :          position of other fields. It is supposed to appear only as the first
   19088              :          operand of COMPONENT_REF nodes and to reference precisely the type
   19089              :          that the context allows or its enclosing type.  */
   19090         6780 :       if (context != NULL
   19091         6780 :           && (TREE_TYPE (loc) == context->context_type
   19092         6780 :               || TREE_TYPE (loc) == TYPE_CONTEXT (context->context_type))
   19093         6780 :           && want_address >= 1)
   19094              :         {
   19095            0 :           if (dwarf_version >= 3 || !dwarf_strict)
   19096              :             {
   19097            0 :               ret = new_loc_descr (DW_OP_push_object_address, 0, 0);
   19098            0 :               have_address = 1;
   19099            0 :               break;
   19100              :             }
   19101              :           else
   19102              :             return NULL;
   19103              :         }
   19104              :       /* For DW_TAG_generic_subrange attributes, PLACEHOLDER_EXPR stands for
   19105              :          the single argument passed by consumer.  */
   19106         6780 :       else if (context != NULL
   19107         6780 :                && context->placeholder_arg
   19108         6780 :                && INTEGRAL_TYPE_P (TREE_TYPE (loc))
   19109        13560 :                && want_address == 0)
   19110              :         {
   19111         6780 :           ret = new_loc_descr (DW_OP_pick, 0, 0);
   19112         6780 :           ret->dw_loc_frame_offset_rel = 1;
   19113         6780 :           context->placeholder_seen = true;
   19114         6780 :           break;
   19115              :         }
   19116              :       else
   19117            0 :         expansion_failed (loc, NULL_RTX,
   19118              :                           "PLACEHOLDER_EXPR for an unexpected type");
   19119            0 :       break;
   19120              : 
   19121           36 :     case CALL_EXPR:
   19122           36 :         {
   19123           36 :           tree callee = get_callee_fndecl (loc);
   19124           36 :           dw_die_ref dwarf_proc;
   19125              : 
   19126           36 :           if (callee
   19127           36 :               && is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee)))
   19128           72 :               && (dwarf_proc = function_to_dwarf_procedure (callee)))
   19129              :             {
   19130              :               /* DWARF procedures are used for size functions, which are built
   19131              :                  when size expressions contain conditional constructs, so we
   19132              :                  request strict preservation of signedness for comparisons.  */
   19133            4 :               bool old_strict_signedness;
   19134            4 :               if (context)
   19135              :                 {
   19136            0 :                   old_strict_signedness = context->strict_signedness;
   19137            0 :                   context->strict_signedness = true;
   19138              :                 }
   19139              : 
   19140              :               /* Evaluate arguments right-to-left so that the first argument
   19141              :                  will be the top-most one on the stack.  */
   19142            4 :               for (int i = call_expr_nargs (loc) - 1; i >= 0; --i)
   19143              :                 {
   19144            0 :                   tree arg = CALL_EXPR_ARG (loc, i);
   19145            0 :                   ret1 = loc_descriptor_from_tree (arg, 0, context);
   19146            0 :                   if (!ret1)
   19147              :                     {
   19148            0 :                       expansion_failed (arg, NULL_RTX, "CALL_EXPR argument");
   19149            0 :                       return NULL;
   19150              :                     }
   19151            0 :                   add_loc_descr (&ret, ret1);
   19152              :                 }
   19153              : 
   19154            4 :               ret1 = new_loc_descr (DW_OP_call4, 0, 0);
   19155            4 :               ret1->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   19156            4 :               ret1->dw_loc_oprnd1.v.val_die_ref.die = dwarf_proc;
   19157            4 :               ret1->dw_loc_oprnd1.v.val_die_ref.external = 0;
   19158            4 :               add_loc_descr (&ret, ret1);
   19159            4 :               if (context)
   19160            0 :                 context->strict_signedness = old_strict_signedness;
   19161              :             }
   19162              :           else
   19163           32 :             expansion_failed (loc, NULL_RTX, "CALL_EXPR target");
   19164              :           break;
   19165              :         }
   19166              : 
   19167            0 :     case PREINCREMENT_EXPR:
   19168            0 :     case PREDECREMENT_EXPR:
   19169            0 :     case POSTINCREMENT_EXPR:
   19170            0 :     case POSTDECREMENT_EXPR:
   19171            0 :       expansion_failed (loc, NULL_RTX, "PRE/POST INCREMENT/DECREMENT");
   19172              :       /* There are no opcodes for these operations.  */
   19173            0 :       return 0;
   19174              : 
   19175         2212 :     case ADDR_EXPR:
   19176              :       /* If we already want an address, see if there is INDIRECT_REF inside
   19177              :          e.g. for &this->field.  */
   19178         2212 :       if (want_address)
   19179              :         {
   19180         4422 :           list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
   19181         2211 :                        (loc, want_address == 2, context);
   19182         2211 :           if (list_ret)
   19183              :             have_address = 1;
   19184         2211 :           else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
   19185         2211 :                    && (ret = cst_pool_loc_descr (loc)))
   19186              :             have_address = 1;
   19187              :         }
   19188              :         /* Otherwise, process the argument and look for the address.  */
   19189         2212 :       if (!list_ret && !ret)
   19190         2212 :         list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 1, context);
   19191              :       else
   19192              :         {
   19193            0 :           if (want_address)
   19194            0 :             expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
   19195              :           return NULL;
   19196              :         }
   19197         2212 :       break;
   19198              : 
   19199     16376274 :     case VAR_DECL:
   19200     16376274 :       if (DECL_THREAD_LOCAL_P (loc))
   19201              :         {
   19202          479 :           rtx rtl;
   19203          479 :          enum dwarf_location_atom tls_op;
   19204          479 :          enum dtprel_bool dtprel = dtprel_false;
   19205              : 
   19206          479 :           if (targetm.have_tls)
   19207              :             {
   19208              :               /* If this is not defined, we have no way to emit the
   19209              :                  data.  */
   19210          479 :               if (!targetm.asm_out.output_dwarf_dtprel)
   19211              :                 return 0;
   19212              : 
   19213              :                /* The way DW_OP_GNU_push_tls_address is specified, we
   19214              :                   can only look up addresses of objects in the current
   19215              :                   module.  We used DW_OP_addr as first op, but that's
   19216              :                   wrong, because DW_OP_addr is relocated by the debug
   19217              :                   info consumer, while DW_OP_GNU_push_tls_address
   19218              :                   operand shouldn't be.  */
   19219          479 :               if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
   19220              :                 return 0;
   19221          479 :               dtprel = dtprel_true;
   19222              :               /* We check for DWARF 5 here because gdb did not implement
   19223              :                  DW_OP_form_tls_address until after 7.12.  */
   19224          479 :               tls_op = (dwarf_version >= 5 ? DW_OP_form_tls_address
   19225              :                         : DW_OP_GNU_push_tls_address);
   19226              :             }
   19227              :           else
   19228              :             {
   19229            0 :               if (!targetm.emutls.debug_form_tls_address
   19230            0 :                   || !(dwarf_version >= 3 || !dwarf_strict))
   19231              :                 return 0;
   19232              :               /* We stuffed the control variable into the DECL_VALUE_EXPR
   19233              :                  to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
   19234              :                  no longer appear in gimple code.  We used the control
   19235              :                  variable in specific so that we could pick it up here.  */
   19236            0 :               loc = DECL_VALUE_EXPR (loc);
   19237            0 :               tls_op = DW_OP_form_tls_address;
   19238              :             }
   19239              : 
   19240          479 :           rtl = rtl_for_decl_location (loc);
   19241          479 :           if (rtl == NULL_RTX)
   19242              :             return 0;
   19243              : 
   19244          479 :           if (!MEM_P (rtl))
   19245              :             return 0;
   19246          479 :           rtl = XEXP (rtl, 0);
   19247          479 :           if (! CONSTANT_P (rtl))
   19248              :             return 0;
   19249              : 
   19250          479 :           ret = new_addr_loc_descr (rtl, dtprel);
   19251          479 :           ret1 = new_loc_descr (tls_op, 0, 0);
   19252          479 :           add_loc_descr (&ret, ret1);
   19253              : 
   19254          479 :           have_address = 1;
   19255          479 :           break;
   19256              :         }
   19257              :       /* FALLTHRU */
   19258              : 
   19259     17432984 :     case PARM_DECL:
   19260          268 :       if (context != NULL && context->dpi != NULL
   19261     17432984 :           && DECL_CONTEXT (loc) == context->dpi->fndecl)
   19262              :         {
   19263              :           /* We are generating code for a DWARF procedure and we want to access
   19264              :              one of its arguments: find the appropriate argument offset and let
   19265              :              the resolve_args_picking pass compute the offset that complies
   19266              :              with the stack frame size.  */
   19267            0 :           unsigned i = 0;
   19268            0 :           tree cursor;
   19269              : 
   19270            0 :           for (cursor = DECL_ARGUMENTS (context->dpi->fndecl);
   19271            0 :                cursor != NULL_TREE && cursor != loc;
   19272            0 :                cursor = TREE_CHAIN (cursor), ++i)
   19273              :             ;
   19274              :           /* If we are translating a DWARF procedure, all referenced parameters
   19275              :              must belong to the current function.  */
   19276            0 :           gcc_assert (cursor != NULL_TREE);
   19277              : 
   19278            0 :           ret = new_loc_descr (DW_OP_pick, i, 0);
   19279            0 :           ret->dw_loc_frame_offset_rel = 1;
   19280            0 :           break;
   19281              :         }
   19282              :       /* FALLTHRU */
   19283              : 
   19284     17435485 :     case RESULT_DECL:
   19285     17435485 :       if (DECL_HAS_VALUE_EXPR_P (loc))
   19286              :         {
   19287       189744 :           tree value_expr = DECL_VALUE_EXPR (loc);
   19288              : 
   19289              :           /* Non-local frame structures are DECL_IGNORED_P variables so we need
   19290              :              to wait until they get an RTX in order to reference them.  */
   19291       189744 :           if (early_dwarf
   19292           22 :               && TREE_CODE (value_expr) == COMPONENT_REF
   19293           22 :               && VAR_P (TREE_OPERAND (value_expr, 0))
   19294       189764 :               && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr, 0)))
   19295              :             ;
   19296              :           else
   19297              :             return loc_list_from_tree_1 (value_expr, want_address, context);
   19298              :         }
   19299              : 
   19300              :       /* FALLTHRU */
   19301              : 
   19302     17245954 :     case FUNCTION_DECL:
   19303     17245954 :       {
   19304     17245954 :         rtx rtl;
   19305     17245954 :         var_loc_list *loc_list = lookup_decl_loc (loc);
   19306              : 
   19307     17245954 :         if (loc_list && loc_list->first)
   19308              :           {
   19309     14204104 :             list_ret = dw_loc_list (loc_list, loc, want_address);
   19310     14204104 :             have_address = want_address != 0;
   19311     14204104 :             break;
   19312              :           }
   19313      3041850 :         rtl = rtl_for_decl_location (loc);
   19314      3041850 :         if (rtl == NULL_RTX)
   19315              :           {
   19316      2335036 :             if (TREE_CODE (loc) != FUNCTION_DECL
   19317      2335035 :                 && early_dwarf
   19318        10138 :                 && want_address != 1
   19319        10138 :                 && ! DECL_IGNORED_P (loc)
   19320         9849 :                 && (INTEGRAL_TYPE_P (TREE_TYPE (loc))
   19321           62 :                     || POINTER_TYPE_P (TREE_TYPE (loc)))
   19322         9849 :                 && TYPE_MODE (TREE_TYPE (loc)) != BLKmode
   19323      2354726 :                 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (loc)))
   19324         9845 :                     <= DWARF2_ADDR_SIZE))
   19325              :               {
   19326         9845 :                 dw_die_ref ref = lookup_decl_die (loc);
   19327         9845 :                 if (ref)
   19328              :                   {
   19329         6066 :                     ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
   19330         6066 :                     ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   19331         6066 :                     ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
   19332         6066 :                     ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
   19333              :                   }
   19334         3779 :                 else if (current_function_decl
   19335         3779 :                          && DECL_CONTEXT (loc) == current_function_decl)
   19336              :                   {
   19337         3616 :                     ret = new_loc_descr (DW_OP_GNU_variable_value, 0, 0);
   19338         3616 :                     ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
   19339         3616 :                     ret->dw_loc_oprnd1.v.val_decl_ref = loc;
   19340              :                   }
   19341              :                 break;
   19342              :               }
   19343      2325191 :             expansion_failed (loc, NULL_RTX, "DECL has no RTL");
   19344      2325191 :             return 0;
   19345              :           }
   19346       706814 :         else if (CONST_INT_P (rtl))
   19347              :           {
   19348            0 :             HOST_WIDE_INT val = INTVAL (rtl);
   19349            0 :             if (TYPE_UNSIGNED (TREE_TYPE (loc)))
   19350            0 :               val &= GET_MODE_MASK (DECL_MODE (loc));
   19351            0 :             ret = int_loc_descriptor (val);
   19352              :           }
   19353       706814 :         else if (GET_CODE (rtl) == CONST_STRING)
   19354              :           {
   19355            0 :             expansion_failed (loc, NULL_RTX, "CONST_STRING");
   19356            0 :             return 0;
   19357              :           }
   19358       706814 :         else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
   19359            0 :           ret = new_addr_loc_descr (rtl, dtprel_false);
   19360              :         else
   19361              :           {
   19362       706814 :             machine_mode mode, mem_mode;
   19363              : 
   19364              :             /* Certain constructs can only be represented at top-level.  */
   19365       706814 :             if (want_address == 2)
   19366              :               {
   19367       676210 :                 ret = loc_descriptor (rtl, VOIDmode,
   19368              :                                       VAR_INIT_STATUS_INITIALIZED);
   19369       676210 :                 have_address = 1;
   19370              :               }
   19371              :             else
   19372              :               {
   19373        30604 :                 mode = GET_MODE (rtl);
   19374        30604 :                 mem_mode = VOIDmode;
   19375        30604 :                 if (MEM_P (rtl))
   19376              :                   {
   19377        16005 :                     mem_mode = mode;
   19378        16005 :                     mode = get_address_mode (rtl);
   19379        16005 :                     rtl = XEXP (rtl, 0);
   19380        16005 :                     have_address = 1;
   19381              :                   }
   19382        30604 :                 ret = mem_loc_descriptor (rtl, mode, mem_mode,
   19383              :                                           VAR_INIT_STATUS_INITIALIZED);
   19384              :               }
   19385       706814 :             if (!ret)
   19386        49151 :               expansion_failed (loc, rtl,
   19387              :                                 "failed to produce loc descriptor for rtl");
   19388              :           }
   19389              :       }
   19390              :       break;
   19391              : 
   19392         5352 :     case MEM_REF:
   19393         5352 :       if (!integer_zerop (TREE_OPERAND (loc, 1)))
   19394              :         {
   19395            0 :           have_address = 1;
   19396            0 :           goto do_plus;
   19397              :         }
   19398              :       /* Fallthru.  */
   19399       269407 :     case INDIRECT_REF:
   19400       269407 :       list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19401       269407 :       have_address = 1;
   19402       269407 :       break;
   19403              : 
   19404              :     case TARGET_MEM_REF:
   19405              :     case SSA_NAME:
   19406              :     case DEBUG_EXPR_DECL:
   19407              :       return NULL;
   19408              : 
   19409            3 :     case COMPOUND_EXPR:
   19410            3 :       return loc_list_from_tree_1 (TREE_OPERAND (loc, 1), want_address,
   19411            3 :                                    context);
   19412              : 
   19413        71481 :     CASE_CONVERT:
   19414        71481 :     case VIEW_CONVERT_EXPR:
   19415        71481 :     case SAVE_EXPR:
   19416        71481 :     case MODIFY_EXPR:
   19417        71481 :     case NON_LVALUE_EXPR:
   19418        71481 :       return loc_list_from_tree_1 (TREE_OPERAND (loc, 0), want_address,
   19419        71481 :                                    context);
   19420              : 
   19421       164714 :     case COMPONENT_REF:
   19422       164714 :     case BIT_FIELD_REF:
   19423       164714 :     case ARRAY_REF:
   19424       164714 :     case ARRAY_RANGE_REF:
   19425       164714 :     case REALPART_EXPR:
   19426       164714 :     case IMAGPART_EXPR:
   19427       164714 :       {
   19428       164714 :         tree obj, offset;
   19429       164714 :         poly_int64 bitsize, bitpos, bytepos;
   19430       164714 :         machine_mode mode;
   19431       164714 :         int unsignedp, reversep, volatilep = 0;
   19432              : 
   19433       164714 :         obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
   19434              :                                    &unsignedp, &reversep, &volatilep);
   19435              : 
   19436       164714 :         gcc_assert (obj != loc);
   19437              : 
   19438       329428 :         list_ret = loc_list_from_tree_1 (obj,
   19439              :                                          want_address == 2
   19440       147899 :                                          && known_eq (bitpos, 0)
   19441        70192 :                                          && !offset ? 2 : 1,
   19442              :                                          context);
   19443              :         /* TODO: We can extract value of the small expression via shifting even
   19444              :            for nonzero bitpos.  */
   19445       164714 :         if (list_ret == 0)
   19446       115408 :           return 0;
   19447        49385 :         if (!multiple_p (bitpos, BITS_PER_UNIT, &bytepos))
   19448              :           {
   19449            0 :             expansion_failed (loc, NULL_RTX, "bitfield access");
   19450            0 :             return 0;
   19451              :           }
   19452              : 
   19453        49385 :         if (offset != NULL_TREE)
   19454              :           {
   19455              :             /* Variable offset.  */
   19456           79 :             list_ret1 = loc_list_from_tree_1 (offset, 0, context);
   19457           79 :             if (list_ret1 == 0)
   19458              :               return 0;
   19459            0 :             add_loc_list (&list_ret, list_ret1);
   19460            0 :             if (!list_ret)
   19461              :               return 0;
   19462            0 :             add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
   19463              :           }
   19464              : 
   19465        49306 :         HOST_WIDE_INT value;
   19466        49306 :         if (bytepos.is_constant (&value) && value > 0)
   19467        38786 :           add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst,
   19468              :                                                           value, 0));
   19469        10520 :         else if (maybe_ne (bytepos, 0))
   19470            0 :           loc_list_plus_const (list_ret, bytepos);
   19471              : 
   19472        49306 :         have_address = 1;
   19473        49306 :         break;
   19474              :       }
   19475              : 
   19476        20191 :     case INTEGER_CST:
   19477        20121 :       if ((want_address || !tree_fits_shwi_p (loc))
   19478        20195 :           && (ret = cst_pool_loc_descr (loc)))
   19479              :         have_address = 1;
   19480        20191 :       else if (want_address == 2
   19481           70 :                && tree_fits_shwi_p (loc)
   19482        20261 :                && (ret = address_of_int_loc_descriptor
   19483           70 :                            (int_size_in_bytes (TREE_TYPE (loc)),
   19484              :                             tree_to_shwi (loc))))
   19485              :         have_address = 1;
   19486        20121 :       else if (tree_fits_shwi_p (loc))
   19487        20117 :         ret = int_loc_descriptor (tree_to_shwi (loc));
   19488            4 :       else if (tree_fits_uhwi_p (loc))
   19489            4 :         ret = uint_loc_descriptor (tree_to_uhwi (loc));
   19490              :       else
   19491              :         {
   19492            0 :           expansion_failed (loc, NULL_RTX,
   19493              :                             "Integer operand is not host integer");
   19494            0 :           return 0;
   19495              :         }
   19496              :       break;
   19497              : 
   19498            0 :     case POLY_INT_CST:
   19499            0 :       {
   19500            0 :         if (want_address)
   19501              :           {
   19502            0 :             expansion_failed (loc, NULL_RTX,
   19503              :                               "constant address with a runtime component");
   19504            0 :             return 0;
   19505              :           }
   19506            0 :         poly_int64 value;
   19507            0 :         if (!poly_int_tree_p (loc, &value))
   19508              :           {
   19509            0 :             expansion_failed (loc, NULL_RTX, "constant too big");
   19510            0 :             return 0;
   19511              :           }
   19512            0 :         ret = int_loc_descriptor (value);
   19513              :       }
   19514            0 :       break;
   19515              : 
   19516        11861 :     case CONSTRUCTOR:
   19517        11861 :     case REAL_CST:
   19518        11861 :     case STRING_CST:
   19519        11861 :     case COMPLEX_CST:
   19520        11861 :       if ((ret = cst_pool_loc_descr (loc)))
   19521              :         have_address = 1;
   19522         1027 :       else if (TREE_CODE (loc) == CONSTRUCTOR)
   19523              :         {
   19524           74 :           tree type = TREE_TYPE (loc);
   19525           74 :           unsigned HOST_WIDE_INT size = int_size_in_bytes (type);
   19526           74 :           unsigned HOST_WIDE_INT offset = 0;
   19527           74 :           unsigned HOST_WIDE_INT cnt;
   19528           74 :           constructor_elt *ce;
   19529              : 
   19530           74 :           if (TREE_CODE (type) == RECORD_TYPE)
   19531              :             {
   19532              :               /* This is very limited, but it's enough to output
   19533              :                  pointers to member functions, as long as the
   19534              :                  referenced function is defined in the current
   19535              :                  translation unit.  */
   19536          214 :               FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (loc), cnt, ce)
   19537              :                 {
   19538          144 :                   tree val = ce->value;
   19539              : 
   19540          144 :                   tree field = ce->index;
   19541              : 
   19542          144 :                   if (val)
   19543          144 :                     STRIP_NOPS (val);
   19544              : 
   19545          288 :                   if (!field || DECL_BIT_FIELD (field))
   19546              :                     {
   19547            0 :                       expansion_failed (loc, NULL_RTX,
   19548              :                                         "bitfield in record type constructor");
   19549            0 :                       size = offset = (unsigned HOST_WIDE_INT)-1;
   19550            0 :                       ret = NULL;
   19551            0 :                       break;
   19552              :                     }
   19553              : 
   19554          144 :                   HOST_WIDE_INT fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
   19555          144 :                   unsigned HOST_WIDE_INT pos = int_byte_position (field);
   19556          144 :                   gcc_assert (pos + fieldsize <= size);
   19557          144 :                   if (pos < offset)
   19558              :                     {
   19559            0 :                       expansion_failed (loc, NULL_RTX,
   19560              :                                         "out-of-order fields in record constructor");
   19561            0 :                       size = offset = (unsigned HOST_WIDE_INT)-1;
   19562            0 :                       ret = NULL;
   19563            0 :                       break;
   19564              :                     }
   19565          144 :                   if (pos > offset)
   19566              :                     {
   19567            0 :                       ret1 = new_loc_descr (DW_OP_piece, pos - offset, 0);
   19568            0 :                       add_loc_descr (&ret, ret1);
   19569            0 :                       offset = pos;
   19570              :                     }
   19571          144 :                   if (val && fieldsize != 0)
   19572              :                     {
   19573          144 :                       ret1 = loc_descriptor_from_tree (val, want_address, context);
   19574          144 :                       if (!ret1)
   19575              :                         {
   19576            4 :                           expansion_failed (loc, NULL_RTX,
   19577              :                                             "unsupported expression in field");
   19578            4 :                           size = offset = (unsigned HOST_WIDE_INT)-1;
   19579            4 :                           ret = NULL;
   19580            4 :                           break;
   19581              :                         }
   19582          140 :                       add_loc_descr (&ret, ret1);
   19583              :                     }
   19584          140 :                   if (fieldsize)
   19585              :                     {
   19586          140 :                       ret1 = new_loc_descr (DW_OP_piece, fieldsize, 0);
   19587          140 :                       add_loc_descr (&ret, ret1);
   19588          140 :                       offset = pos + fieldsize;
   19589              :                     }
   19590              :                 }
   19591              : 
   19592           74 :               if (offset != size)
   19593              :                 {
   19594            0 :                   ret1 = new_loc_descr (DW_OP_piece, size - offset, 0);
   19595            0 :                   add_loc_descr (&ret, ret1);
   19596            0 :                   offset = size;
   19597              :                 }
   19598              : 
   19599           74 :               have_address = !!want_address;
   19600              :             }
   19601              :           else
   19602            0 :             expansion_failed (loc, NULL_RTX,
   19603              :                               "constructor of non-record type");
   19604              :         }
   19605              :       else
   19606              :       /* We can construct small constants here using int_loc_descriptor.  */
   19607          953 :         expansion_failed (loc, NULL_RTX,
   19608              :                           "constructor or constant not in constant pool");
   19609              :       break;
   19610              : 
   19611            4 :     case TRUTH_AND_EXPR:
   19612            4 :     case TRUTH_ANDIF_EXPR:
   19613            4 :     case BIT_AND_EXPR:
   19614            4 :       op = DW_OP_and;
   19615            4 :       goto do_binop;
   19616              : 
   19617            0 :     case TRUTH_XOR_EXPR:
   19618            0 :     case BIT_XOR_EXPR:
   19619            0 :       op = DW_OP_xor;
   19620            0 :       goto do_binop;
   19621              : 
   19622            0 :     case TRUTH_OR_EXPR:
   19623            0 :     case TRUTH_ORIF_EXPR:
   19624            0 :     case BIT_IOR_EXPR:
   19625            0 :       op = DW_OP_or;
   19626            0 :       goto do_binop;
   19627              : 
   19628            0 :     case EXACT_DIV_EXPR:
   19629            0 :     case FLOOR_DIV_EXPR:
   19630            0 :     case TRUNC_DIV_EXPR:
   19631              :       /* Turn a divide by a power of 2 into a shift when possible.  */
   19632            0 :       if (TYPE_UNSIGNED (TREE_TYPE (loc))
   19633            0 :           && tree_fits_uhwi_p (TREE_OPERAND (loc, 1)))
   19634              :         {
   19635            0 :           const int log2 = exact_log2 (tree_to_uhwi (TREE_OPERAND (loc, 1)));
   19636            0 :           if (log2 > 0)
   19637              :             {
   19638            0 :               list_ret
   19639            0 :                 = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19640            0 :               if (list_ret == 0)
   19641              :                 return 0;
   19642              : 
   19643            0 :               add_loc_descr_to_each (list_ret, uint_loc_descriptor (log2));
   19644            0 :               add_loc_descr_to_each (list_ret,
   19645              :                                      new_loc_descr (DW_OP_shr, 0, 0));
   19646            0 :               break;
   19647              :             }
   19648              :         }
   19649              : 
   19650              :       /* fall through */
   19651              : 
   19652            0 :     case CEIL_DIV_EXPR:
   19653            0 :     case ROUND_DIV_EXPR:
   19654            0 :       if (TYPE_UNSIGNED (TREE_TYPE (loc)))
   19655              :         {
   19656            0 :           const enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
   19657            0 :           scalar_int_mode int_mode;
   19658              : 
   19659            0 :           if ((dwarf_strict && dwarf_version < 5)
   19660            0 :               || !is_a <scalar_int_mode> (mode, &int_mode))
   19661     17954309 :             return 0;
   19662              : 
   19663              :           /* We can use a signed divide if the sign bit is not set.  */
   19664            0 :           if (GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
   19665              :             {
   19666            0 :               op = DW_OP_div;
   19667            0 :               goto do_binop;
   19668              :             }
   19669              : 
   19670            0 :           list_ret = typed_binop_from_tree (DW_OP_div, loc,
   19671              :                                             base_type_for_mode (int_mode, 1),
   19672              :                                             int_mode, context);
   19673            0 :           break;
   19674              :         }
   19675            0 :       op = DW_OP_div;
   19676            0 :       goto do_binop;
   19677              : 
   19678         5330 :     case MINUS_EXPR:
   19679         5330 :       op = DW_OP_minus;
   19680         5330 :       goto do_binop;
   19681              : 
   19682            0 :     case FLOOR_MOD_EXPR:
   19683            0 :     case CEIL_MOD_EXPR:
   19684            0 :     case ROUND_MOD_EXPR:
   19685            0 :     case TRUNC_MOD_EXPR:
   19686            0 :       if (TYPE_UNSIGNED (TREE_TYPE (loc)))
   19687              :         {
   19688            0 :           op = DW_OP_mod;
   19689            0 :           goto do_binop;
   19690              :         }
   19691            0 :       list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19692            0 :       list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
   19693            0 :       if (list_ret == 0 || list_ret1 == 0)
   19694              :         return 0;
   19695              : 
   19696            0 :       add_loc_list (&list_ret, list_ret1);
   19697            0 :       if (list_ret == 0)
   19698              :         return 0;
   19699            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
   19700            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
   19701            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
   19702            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
   19703            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
   19704            0 :       break;
   19705              : 
   19706        26127 :     case MULT_EXPR:
   19707        26127 :       op = DW_OP_mul;
   19708        26127 :       goto do_binop;
   19709              : 
   19710            0 :     case LSHIFT_EXPR:
   19711            0 :       op = DW_OP_shl;
   19712            0 :       goto do_binop;
   19713              : 
   19714            0 :     case RSHIFT_EXPR:
   19715            0 :       op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
   19716            0 :       goto do_binop;
   19717              : 
   19718        91512 :     case POINTER_PLUS_EXPR:
   19719        91512 :     case PLUS_EXPR:
   19720        91512 :     do_plus:
   19721        91512 :       if (tree_fits_shwi_p (TREE_OPERAND (loc, 1)))
   19722              :         {
   19723              :           /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
   19724              :              smarter to encode their opposite.  The DW_OP_plus_uconst operation
   19725              :              takes 1 + X bytes, X being the size of the ULEB128 addend.  On the
   19726              :              other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
   19727              :              bytes, Y being the size of the operation that pushes the opposite
   19728              :              of the addend.  So let's choose the smallest representation.  */
   19729        79380 :           const tree tree_addend = TREE_OPERAND (loc, 1);
   19730        79380 :           offset_int wi_addend;
   19731        79380 :           HOST_WIDE_INT shwi_addend;
   19732        79380 :           dw_loc_descr_ref loc_naddend;
   19733              : 
   19734        79380 :           list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19735        79380 :           if (list_ret == 0)
   19736           50 :             return 0;
   19737              : 
   19738              :           /* Try to get the literal to push.  It is the opposite of the addend,
   19739              :              so as we rely on wrapping during DWARF evaluation, first decode
   19740              :              the literal as a "DWARF-sized" signed number.  */
   19741        79330 :           wi_addend = wi::to_offset (tree_addend);
   19742        80066 :           wi_addend = wi::sext (wi_addend, DWARF2_ADDR_SIZE * 8);
   19743        79330 :           shwi_addend = wi_addend.to_shwi ();
   19744        79330 :           loc_naddend = (shwi_addend != INTTYPE_MINIMUM (HOST_WIDE_INT))
   19745        79330 :                         ? int_loc_descriptor (-shwi_addend)
   19746              :                         : NULL;
   19747              : 
   19748            0 :           if (loc_naddend != NULL
   19749       158660 :               && ((unsigned) size_of_uleb128 (shwi_addend)
   19750        79330 :                   > size_of_loc_descr (loc_naddend)))
   19751              :             {
   19752           16 :               add_loc_descr_to_each (list_ret, loc_naddend);
   19753           16 :               add_loc_descr_to_each (list_ret,
   19754              :                                      new_loc_descr (DW_OP_minus, 0, 0));
   19755              :             }
   19756              :           else
   19757              :             {
   19758       158628 :               for (dw_loc_descr_ref loc_cur = loc_naddend; loc_cur != NULL; )
   19759              :                 {
   19760        79314 :                   loc_naddend = loc_cur;
   19761        79314 :                   loc_cur = loc_cur->dw_loc_next;
   19762        79314 :                   ggc_free (loc_naddend);
   19763              :                 }
   19764       158628 :               loc_list_plus_const (list_ret, wi_addend.to_shwi ());
   19765              :             }
   19766        79330 :           break;
   19767              :         }
   19768              : 
   19769        12132 :       op = DW_OP_plus;
   19770        12132 :       goto do_binop;
   19771              : 
   19772            0 :     case LE_EXPR:
   19773            0 :       op = DW_OP_le;
   19774            0 :       goto do_comp_binop;
   19775              : 
   19776            0 :     case GE_EXPR:
   19777            0 :       op = DW_OP_ge;
   19778            0 :       goto do_comp_binop;
   19779              : 
   19780            0 :     case LT_EXPR:
   19781            0 :       op = DW_OP_lt;
   19782            0 :       goto do_comp_binop;
   19783              : 
   19784            0 :     case GT_EXPR:
   19785            0 :       op = DW_OP_gt;
   19786            0 :       goto do_comp_binop;
   19787              : 
   19788            0 :     do_comp_binop:
   19789            0 :       if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
   19790              :         {
   19791            0 :           const enum machine_mode mode
   19792            0 :             = TYPE_MODE (TREE_TYPE (TREE_OPERAND (loc, 0)));
   19793            0 :           scalar_int_mode int_mode;
   19794              : 
   19795              :           /* We can use a signed comparison if the sign bit is not set.  */
   19796            0 :           if (is_a <scalar_int_mode> (mode, &int_mode)
   19797            0 :               && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
   19798            0 :             goto do_binop;
   19799              : 
   19800            0 :           list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0, context);
   19801            0 :           list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0, context);
   19802            0 :           list_ret = loc_list_from_uint_comparison (list_ret, list_ret1,
   19803            0 :                                                     TREE_CODE (loc));
   19804            0 :           break;
   19805              :         }
   19806              :       else
   19807            0 :         goto do_binop;
   19808              : 
   19809            0 :     case EQ_EXPR:
   19810            0 :       op = DW_OP_eq;
   19811            0 :       goto do_binop;
   19812              : 
   19813         7920 :     case NE_EXPR:
   19814         7920 :       op = DW_OP_ne;
   19815         7920 :       goto do_binop;
   19816              : 
   19817        51513 :     do_binop:
   19818        51513 :       list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19819        51513 :       list_ret1 = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
   19820        51513 :       if (list_ret == 0 || list_ret1 == 0)
   19821              :         return 0;
   19822              : 
   19823        51380 :       add_loc_list (&list_ret, list_ret1);
   19824        51380 :       if (list_ret == 0)
   19825              :         return 0;
   19826              : 
   19827        51380 :       add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
   19828        51380 :       break;
   19829              : 
   19830            0 :     case TRUTH_NOT_EXPR:
   19831            0 :       list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19832            0 :       if (list_ret == 0)
   19833              :         return 0;
   19834              : 
   19835            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_lit0, 0, 0));
   19836            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_eq, 0, 0));
   19837            0 :       break;
   19838              : 
   19839            0 :     case BIT_NOT_EXPR:
   19840            0 :       op = DW_OP_not;
   19841            0 :       goto do_unop;
   19842              : 
   19843            0 :     case ABS_EXPR:
   19844            0 :       op = DW_OP_abs;
   19845            0 :       goto do_unop;
   19846              : 
   19847            0 :     case NEGATE_EXPR:
   19848            0 :       op = DW_OP_neg;
   19849            0 :       goto do_unop;
   19850              : 
   19851            0 :     do_unop:
   19852            0 :       list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19853            0 :       if (list_ret == 0)
   19854              :         return 0;
   19855              : 
   19856            0 :       add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
   19857            0 :       break;
   19858              : 
   19859            0 :     case MIN_EXPR:
   19860            0 :     case MAX_EXPR:
   19861            0 :       {
   19862            0 :         const enum tree_code code =
   19863            0 :           TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
   19864              : 
   19865            0 :         loc = build3 (COND_EXPR, TREE_TYPE (loc),
   19866              :                       build2 (code, integer_type_node,
   19867            0 :                               TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
   19868            0 :                       TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
   19869              :       }
   19870              : 
   19871              :       /* fall through */
   19872              : 
   19873            0 :     case COND_EXPR:
   19874            0 :       {
   19875            0 :         dw_loc_descr_ref lhs
   19876            0 :           = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0, context);
   19877            0 :         dw_loc_list_ref rhs
   19878            0 :           = loc_list_from_tree_1 (TREE_OPERAND (loc, 2), 0, context);
   19879            0 :         dw_loc_descr_ref bra_node, jump_node, tmp;
   19880              : 
   19881              :         /* DW_OP_bra is branch-on-nonzero so avoid doing useless work.  */
   19882            0 :         if (TREE_CODE (TREE_OPERAND (loc, 0)) == NE_EXPR
   19883            0 :             && integer_zerop (TREE_OPERAND (TREE_OPERAND (loc, 0), 1)))
   19884            0 :           list_ret
   19885            0 :             = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0),
   19886              :                                     0, context);
   19887              :         /* Likewise, swap the operands for a logically negated condition.  */
   19888            0 :         else if (TREE_CODE (TREE_OPERAND (loc, 0)) == TRUTH_NOT_EXPR)
   19889              :           {
   19890            0 :             lhs = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0, context);
   19891            0 :             rhs = loc_list_from_tree_1 (TREE_OPERAND (loc, 1), 0, context);
   19892            0 :             list_ret
   19893            0 :               = loc_list_from_tree_1 (TREE_OPERAND (TREE_OPERAND (loc, 0), 0),
   19894              :                                       0, context);
   19895              :           }
   19896              :         else
   19897            0 :           list_ret = loc_list_from_tree_1 (TREE_OPERAND (loc, 0), 0, context);
   19898            0 :         if (list_ret == 0 || lhs == 0 || rhs == 0)
   19899              :           return 0;
   19900              : 
   19901            0 :         bra_node = new_loc_descr (DW_OP_bra, 0, 0);
   19902            0 :         add_loc_descr_to_each (list_ret, bra_node);
   19903              : 
   19904            0 :         add_loc_list (&list_ret, rhs);
   19905            0 :         jump_node = new_loc_descr (DW_OP_skip, 0, 0);
   19906            0 :         add_loc_descr_to_each (list_ret, jump_node);
   19907              : 
   19908            0 :         add_loc_descr_to_each (list_ret, lhs);
   19909            0 :         bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
   19910            0 :         bra_node->dw_loc_oprnd1.v.val_loc = lhs;
   19911              : 
   19912              :         /* ??? Need a node to point the skip at.  Use a nop.  */
   19913            0 :         tmp = new_loc_descr (DW_OP_nop, 0, 0);
   19914            0 :         add_loc_descr_to_each (list_ret, tmp);
   19915            0 :         jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
   19916            0 :         jump_node->dw_loc_oprnd1.v.val_loc = tmp;
   19917              :       }
   19918            0 :       break;
   19919              : 
   19920              :     case FIX_TRUNC_EXPR:
   19921              :       return 0;
   19922              : 
   19923            0 :     case COMPOUND_LITERAL_EXPR:
   19924            0 :       return loc_list_from_tree_1 (COMPOUND_LITERAL_EXPR_DECL (loc),
   19925            0 :                                    0, context);
   19926              : 
   19927            0 :     default:
   19928              :       /* Leave front-end specific codes as simply unknown.  This comes
   19929              :          up, for instance, with the C STMT_EXPR.  */
   19930            0 :       if ((unsigned int) TREE_CODE (loc)
   19931              :           >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
   19932              :         {
   19933            0 :           expansion_failed (loc, NULL_RTX,
   19934              :                             "language specific tree node");
   19935            0 :           return 0;
   19936              :         }
   19937              : 
   19938              :       /* Otherwise this is a generic code; we should just lists all of
   19939              :          these explicitly.  We forgot one.  */
   19940            0 :       if (flag_checking)
   19941            0 :         gcc_unreachable ();
   19942              : 
   19943              :       /* In a release build, we want to degrade gracefully: better to
   19944              :          generate incomplete debugging information than to crash.  */
   19945              :       return NULL;
   19946              :     }
   19947              : 
   19948     15411745 :   if (!ret && !list_ret)
   19949              :     return 0;
   19950              : 
   19951              :   /* Implement wrap-around arithmetics for small integer types.  */
   19952     14221448 :   if ((TREE_CODE (loc) == PLUS_EXPR
   19953              :        || TREE_CODE (loc) == MINUS_EXPR
   19954     14221448 :        || TREE_CODE (loc) == MULT_EXPR
   19955              :        || TREE_CODE (loc) == NEGATE_EXPR
   19956              :        || TREE_CODE (loc) == LSHIFT_EXPR)
   19957        43490 :       && INTEGRAL_TYPE_P (TREE_TYPE (loc))
   19958        43490 :       && TYPE_OVERFLOW_WRAPS (TREE_TYPE (loc)))
   19959              :     {
   19960        13592 :       const enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
   19961        13592 :       scalar_int_mode int_mode;
   19962              : 
   19963        13592 :       if (is_a <scalar_int_mode> (mode, &int_mode)
   19964        14456 :           && GET_MODE_SIZE (int_mode) < DWARF2_ADDR_SIZE)
   19965              :         {
   19966            0 :            const unsigned HOST_WIDE_INT mask
   19967            0 :             = (HOST_WIDE_INT_1U << GET_MODE_BITSIZE (int_mode)) - 1;
   19968            0 :            add_loc_descr_to_each (list_ret, uint_loc_descriptor (mask));
   19969            0 :            add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_and, 0, 0));
   19970              :         }
   19971              :     }
   19972              : 
   19973     14221448 :   if (want_address == 2 && !have_address
   19974        23856 :       && (dwarf_version >= 4 || !dwarf_strict))
   19975              :     {
   19976        24011 :       if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
   19977              :         {
   19978            0 :           expansion_failed (loc, NULL_RTX,
   19979              :                             "DWARF address size mismatch");
   19980            0 :           return 0;
   19981              :         }
   19982        23856 :       if (ret)
   19983        10770 :         add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
   19984              :       else
   19985        18471 :         add_loc_descr_to_each (list_ret,
   19986              :                                new_loc_descr (DW_OP_stack_value, 0, 0));
   19987              :       have_address = 1;
   19988              :     }
   19989              :   /* Show if we can't fill the request for an address.  */
   19990     14221448 :   if (want_address && !have_address)
   19991              :     {
   19992           20 :       expansion_failed (loc, NULL_RTX,
   19993              :                         "Want address and only have value");
   19994           20 :       return 0;
   19995              :     }
   19996              : 
   19997     14221428 :   gcc_assert (!ret || !list_ret);
   19998              : 
   19999              :   /* If we've got an address and don't want one, dereference.  */
   20000     14221428 :   if (!want_address && have_address)
   20001              :     {
   20002       119149 :       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
   20003       119149 :       enum machine_mode mode = TYPE_MODE (TREE_TYPE (loc));
   20004       119149 :       scalar_int_mode int_mode;
   20005       119149 :       dw_die_ref type_die;
   20006       119149 :       dw_loc_descr_ref deref;
   20007              : 
   20008              :       /* Bail out if the size is variable or greater than DWARF2_ADDR_SIZE.  */
   20009       126090 :       if (size < 0 || size > DWARF2_ADDR_SIZE)
   20010              :         {
   20011          134 :           expansion_failed (loc, NULL_RTX, "DWARF address size mismatch");
   20012          134 :           return 0;
   20013              :         }
   20014              : 
   20015              :       /* If it is equal to DWARF2_ADDR_SIZE, extension does not matter.  */
   20016       125899 :       else if (size == DWARF2_ADDR_SIZE)
   20017       117857 :         deref = new_loc_descr (DW_OP_deref, size, 0);
   20018              : 
   20019              :       /* If it is lower than DWARF2_ADDR_SIZE, DW_OP_deref_size will zero-
   20020              :          extend the value, which is really OK for unsigned types only.  */
   20021         1130 :       else if (!(context && context->strict_signedness)
   20022            0 :                || TYPE_UNSIGNED (TREE_TYPE (loc))
   20023            0 :                || (dwarf_strict && dwarf_version < 5)
   20024         1158 :                || !is_a <scalar_int_mode> (mode, &int_mode)
   20025         1158 :                || !(type_die = base_type_for_mode (mode, false)))
   20026         1158 :         deref = new_loc_descr (DW_OP_deref_size, size, 0);
   20027              : 
   20028              :       /* Use DW_OP_deref_type for signed integral types if possible, but
   20029              :          convert back to the generic type to avoid type mismatches later.  */
   20030              :       else
   20031              :         {
   20032            0 :           deref = new_loc_descr (dwarf_OP (DW_OP_deref_type), size, 0);
   20033            0 :           deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
   20034            0 :           deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
   20035            0 :           deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
   20036            0 :           add_loc_descr (&deref,
   20037              :                          new_loc_descr (dwarf_OP (DW_OP_convert), 0, 0));
   20038              :         }
   20039              : 
   20040              :       /* Deal with bit-fields whose size is not a multiple of a byte.  */
   20041       119015 :       if (TREE_CODE (loc) == COMPONENT_REF
   20042       119015 :           && DECL_BIT_FIELD (TREE_OPERAND (loc, 1)))
   20043              :         {
   20044            0 :           const unsigned HOST_WIDE_INT bitsize
   20045            0 :             = tree_to_uhwi (DECL_SIZE (TREE_OPERAND (loc, 1)));
   20046            0 :           if (bitsize < (unsigned HOST_WIDE_INT)size * BITS_PER_UNIT)
   20047              :             {
   20048            0 :               if (TYPE_UNSIGNED (TREE_TYPE (loc)))
   20049              :                 {
   20050            0 :                   if (BYTES_BIG_ENDIAN)
   20051              :                     {
   20052              :                       const unsigned HOST_WIDE_INT shift
   20053              :                         = size * BITS_PER_UNIT - bitsize;
   20054              :                       add_loc_descr (&deref, uint_loc_descriptor (shift));
   20055              :                       add_loc_descr (&deref, new_loc_descr (DW_OP_shr, 0, 0));
   20056              :                     }
   20057              :                   else
   20058              :                     {
   20059            0 :                       const unsigned HOST_WIDE_INT mask
   20060            0 :                         = (HOST_WIDE_INT_1U << bitsize) - 1;
   20061            0 :                       add_loc_descr (&deref, uint_loc_descriptor (mask));
   20062            0 :                       add_loc_descr (&deref, new_loc_descr (DW_OP_and, 0, 0));
   20063              :                     }
   20064              :                 }
   20065              :               else
   20066              :                 {
   20067            0 :                   const unsigned HOST_WIDE_INT shiftr
   20068            0 :                     = DWARF2_ADDR_SIZE * BITS_PER_UNIT - bitsize;
   20069            0 :                   const unsigned HOST_WIDE_INT shiftl
   20070              :                     = BYTES_BIG_ENDIAN
   20071              :                       ? (DWARF2_ADDR_SIZE - size) * BITS_PER_UNIT
   20072              :                       : shiftr;
   20073            0 :                   if (shiftl > 0)
   20074              :                     {
   20075            0 :                       add_loc_descr (&deref, uint_loc_descriptor (shiftl));
   20076            0 :                       add_loc_descr (&deref, new_loc_descr (DW_OP_shl, 0, 0));
   20077              :                     }
   20078            0 :                   add_loc_descr (&deref, uint_loc_descriptor (shiftr));
   20079            0 :                   add_loc_descr (&deref, new_loc_descr (DW_OP_shra, 0, 0));
   20080              :                 }
   20081              :             }
   20082              :         }
   20083              : 
   20084       119015 :       if (ret)
   20085         2738 :         add_loc_descr (&ret, deref);
   20086              :       else
   20087       117646 :         add_loc_descr_to_each (list_ret, deref);
   20088              :     }
   20089              : 
   20090     14221294 :   if (ret)
   20091       705683 :     list_ret = new_loc_list (ret, NULL, 0, NULL, 0, NULL);
   20092              : 
   20093     14221294 :   return list_ret;
   20094              : }
   20095              : 
   20096              : /* Likewise, but strip useless DW_OP_nop operations in the resulting
   20097              :    expressions.  */
   20098              : 
   20099              : static dw_loc_list_ref
   20100     17335491 : loc_list_from_tree (tree loc, int want_address,
   20101              :                     struct loc_descr_context *context)
   20102              : {
   20103     17335491 :   dw_loc_list_ref result = loc_list_from_tree_1 (loc, want_address, context);
   20104              : 
   20105     17335491 :   for (dw_loc_list_ref loc_cur = result;
   20106     45715200 :        loc_cur != NULL; loc_cur = loc_cur->dw_loc_next)
   20107     28379709 :     loc_descr_without_nops (loc_cur->expr);
   20108     17335491 :   return result;
   20109              : }
   20110              : 
   20111              : /* Same as above but return only single location expression.  */
   20112              : static dw_loc_descr_ref
   20113         2355 : loc_descriptor_from_tree (tree loc, int want_address,
   20114              :                           struct loc_descr_context *context)
   20115              : {
   20116         2355 :   dw_loc_list_ref ret = loc_list_from_tree (loc, want_address, context);
   20117         2355 :   if (!ret)
   20118              :     return NULL;
   20119         2345 :   if (ret->dw_loc_next)
   20120              :     {
   20121            0 :       expansion_failed (loc, NULL_RTX,
   20122              :                         "Location list where only loc descriptor needed");
   20123            0 :       return NULL;
   20124              :     }
   20125         2345 :   return ret->expr;
   20126              : }
   20127              : 
   20128              : /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
   20129              :    pointer to the declared type for the relevant field variable, or return
   20130              :    `integer_type_node' if the given node turns out to be an
   20131              :    ERROR_MARK node.  */
   20132              : 
   20133              : static inline tree
   20134      1541119 : field_type (const_tree decl)
   20135              : {
   20136      1541119 :   tree type;
   20137              : 
   20138      1541119 :   if (TREE_CODE (decl) == ERROR_MARK)
   20139            0 :     return integer_type_node;
   20140              : 
   20141      1541119 :   type = DECL_BIT_FIELD_TYPE (decl);
   20142      1541119 :   if (type == NULL_TREE)
   20143            0 :     type = TREE_TYPE (decl);
   20144              : 
   20145              :   return type;
   20146              : }
   20147              : 
   20148              : /* Given a pointer to a tree node, return the alignment in bits for
   20149              :    it, or else return BITS_PER_WORD if the node actually turns out to
   20150              :    be an ERROR_MARK node.  */
   20151              : 
   20152              : static inline unsigned
   20153      1027398 : simple_type_align_in_bits (const_tree type)
   20154              : {
   20155      1027398 :   return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
   20156              : }
   20157              : 
   20158              : static inline unsigned
   20159      1027398 : simple_decl_align_in_bits (const_tree decl)
   20160              : {
   20161      1027398 :   return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
   20162              : }
   20163              : 
   20164              : /* Return the result of rounding T up to ALIGN.  */
   20165              : 
   20166              : static inline offset_int
   20167      1027468 : round_up_to_align (const offset_int &t, unsigned int align)
   20168              : {
   20169      1027468 :   return wi::udiv_trunc (t + align - 1, align) * align;
   20170              : }
   20171              : 
   20172              : /* Helper structure for RECORD_TYPE processing.  */
   20173              : struct vlr_context
   20174              : {
   20175              :   /* Root RECORD_TYPE.  It is needed to generate data member location
   20176              :      descriptions in variable-length records (VLR), but also to cope with
   20177              :      variants, which are composed of nested structures multiplexed with
   20178              :      QUAL_UNION_TYPE nodes.  Each time such a structure is passed to a
   20179              :      function processing a FIELD_DECL, it is required to be non null.  */
   20180              :   tree struct_type;
   20181              : 
   20182              :   /* When generating a variant part in a RECORD_TYPE (i.e. a nested
   20183              :      QUAL_UNION_TYPE), this holds an expression that computes the offset for
   20184              :      this variant part as part of the root record (in storage units).  For
   20185              :      regular records, it must be NULL_TREE.  */
   20186              :   tree variant_part_offset;
   20187              : };
   20188              : 
   20189              : /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
   20190              :    addressed byte of the "containing object" for the given FIELD_DECL. If
   20191              :    possible, return a native constant through CST_OFFSET (in which case NULL is
   20192              :    returned); otherwise return a DWARF expression that computes the offset.
   20193              : 
   20194              :    Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
   20195              :    that offset is, either because the argument turns out to be a pointer to an
   20196              :    ERROR_MARK node, or because the offset expression is too complex for us.
   20197              : 
   20198              :    CTX is required: see the comment for VLR_CONTEXT.  */
   20199              : 
   20200              : static dw_loc_descr_ref
   20201     15515605 : field_byte_offset (const_tree decl, struct vlr_context *ctx,
   20202              :                    HOST_WIDE_INT *cst_offset)
   20203              : {
   20204     15515605 :   tree tree_result;
   20205     15515605 :   dw_loc_list_ref loc_result;
   20206              : 
   20207     15515605 :   *cst_offset = 0;
   20208              : 
   20209     15515605 :   if (TREE_CODE (decl) == ERROR_MARK)
   20210              :     return NULL;
   20211              :   else
   20212     15515605 :     gcc_assert (TREE_CODE (decl) == FIELD_DECL);
   20213              : 
   20214              :   /* We cannot handle variable bit offsets at the moment, so abort if it's the
   20215              :      case.  */
   20216     15515605 :   if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl)) != INTEGER_CST)
   20217              :     return NULL;
   20218              : 
   20219              :   /* We used to handle only constant offsets in all cases.  Now, we handle
   20220              :      properly dynamic byte offsets only when PCC bitfield type doesn't
   20221              :      matter.  */
   20222     15515605 :   if (PCC_BITFIELD_TYPE_MATTERS
   20223     15515605 :       && DECL_BIT_FIELD_TYPE (decl)
   20224     15515605 :       && TREE_CODE (DECL_FIELD_OFFSET (decl)) == INTEGER_CST)
   20225              :     {
   20226      1027398 :       offset_int object_offset_in_bits;
   20227      1027398 :       offset_int object_offset_in_bytes;
   20228      1027398 :       offset_int bitpos_int;
   20229      1027398 :       tree type;
   20230      1027398 :       tree field_size_tree;
   20231      1027398 :       offset_int deepest_bitpos;
   20232      1027398 :       offset_int field_size_in_bits;
   20233      1027398 :       unsigned int type_align_in_bits;
   20234      1027398 :       unsigned int decl_align_in_bits;
   20235      1027398 :       offset_int type_size_in_bits;
   20236              : 
   20237      1027398 :       bitpos_int = wi::to_offset (bit_position (decl));
   20238      1027398 :       type = field_type (decl);
   20239      1027398 :       type_size_in_bits = offset_int_type_size_in_bits (type);
   20240      1027398 :       type_align_in_bits = simple_type_align_in_bits (type);
   20241              : 
   20242      1027398 :       field_size_tree = DECL_SIZE (decl);
   20243              : 
   20244              :       /* The size could be unspecified if there was an error, or for
   20245              :          a flexible array member.  */
   20246      1027398 :       if (!field_size_tree)
   20247            0 :         field_size_tree = bitsize_zero_node;
   20248              : 
   20249              :       /* If the size of the field is not constant, use the type size.  */
   20250      1027398 :       if (TREE_CODE (field_size_tree) == INTEGER_CST)
   20251      1027398 :         field_size_in_bits = wi::to_offset (field_size_tree);
   20252              :       else
   20253            0 :         field_size_in_bits = type_size_in_bits;
   20254              : 
   20255      1027398 :       decl_align_in_bits = simple_decl_align_in_bits (decl);
   20256              : 
   20257              :       /* The GCC front-end doesn't make any attempt to keep track of the
   20258              :          starting bit offset (relative to the start of the containing
   20259              :          structure type) of the hypothetical "containing object" for a
   20260              :          bit-field.  Thus, when computing the byte offset value for the
   20261              :          start of the "containing object" of a bit-field, we must deduce
   20262              :          this information on our own. This can be rather tricky to do in
   20263              :          some cases.  For example, handling the following structure type
   20264              :          definition when compiling for an i386/i486 target (which only
   20265              :          aligns long long's to 32-bit boundaries) can be very tricky:
   20266              : 
   20267              :          struct S { int field1; long long field2:31; };
   20268              : 
   20269              :          Fortunately, there is a simple rule-of-thumb which can be used
   20270              :          in such cases.  When compiling for an i386/i486, GCC will
   20271              :          allocate 8 bytes for the structure shown above.  It decides to
   20272              :          do this based upon one simple rule for bit-field allocation.
   20273              :          GCC allocates each "containing object" for each bit-field at
   20274              :          the first (i.e. lowest addressed) legitimate alignment boundary
   20275              :          (based upon the required minimum alignment for the declared
   20276              :          type of the field) which it can possibly use, subject to the
   20277              :          condition that there is still enough available space remaining
   20278              :          in the containing object (when allocated at the selected point)
   20279              :          to fully accommodate all of the bits of the bit-field itself.
   20280              : 
   20281              :          This simple rule makes it obvious why GCC allocates 8 bytes for
   20282              :          each object of the structure type shown above.  When looking
   20283              :          for a place to allocate the "containing object" for `field2',
   20284              :          the compiler simply tries to allocate a 64-bit "containing
   20285              :          object" at each successive 32-bit boundary (starting at zero)
   20286              :          until it finds a place to allocate that 64- bit field such that
   20287              :          at least 31 contiguous (and previously unallocated) bits remain
   20288              :          within that selected 64 bit field.  (As it turns out, for the
   20289              :          example above, the compiler finds it is OK to allocate the
   20290              :          "containing object" 64-bit field at bit-offset zero within the
   20291              :          structure type.)
   20292              : 
   20293              :          Here we attempt to work backwards from the limited set of facts
   20294              :          we're given, and we try to deduce from those facts, where GCC
   20295              :          must have believed that the containing object started (within
   20296              :          the structure type). The value we deduce is then used (by the
   20297              :          callers of this routine) to generate DW_AT_location and
   20298              :          DW_AT_bit_offset attributes for fields (both bit-fields and, in
   20299              :          the case of DW_AT_location, regular fields as well).  */
   20300              : 
   20301              :       /* Figure out the bit-distance from the start of the structure to
   20302              :          the "deepest" bit of the bit-field.  */
   20303      1027398 :       deepest_bitpos = bitpos_int + field_size_in_bits;
   20304              : 
   20305              :       /* This is the tricky part.  Use some fancy footwork to deduce
   20306              :          where the lowest addressed bit of the containing object must
   20307              :          be.  */
   20308      1027398 :       object_offset_in_bits = deepest_bitpos - type_size_in_bits;
   20309              : 
   20310              :       /* Round up to type_align by default.  This works best for
   20311              :          bitfields.  */
   20312      1027398 :       object_offset_in_bits
   20313      1027398 :         = round_up_to_align (object_offset_in_bits, type_align_in_bits);
   20314              : 
   20315      1027398 :       if (wi::gtu_p (object_offset_in_bits, bitpos_int))
   20316              :         {
   20317           70 :           object_offset_in_bits = deepest_bitpos - type_size_in_bits;
   20318              : 
   20319              :           /* Round up to decl_align instead.  */
   20320           70 :           object_offset_in_bits
   20321           70 :             = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
   20322              :         }
   20323              : 
   20324      1027398 :       object_offset_in_bytes
   20325      1027398 :         = wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
   20326      1027398 :       if (ctx->variant_part_offset == NULL_TREE)
   20327              :         {
   20328      1027398 :           *cst_offset = object_offset_in_bytes.to_shwi ();
   20329      1027398 :           return NULL;
   20330              :         }
   20331            0 :       tree_result = wide_int_to_tree (sizetype, object_offset_in_bytes);
   20332              :     }
   20333              :   else
   20334     14488207 :     tree_result = byte_position (decl);
   20335              : 
   20336     14488207 :   if (ctx->variant_part_offset != NULL_TREE)
   20337            0 :     tree_result = fold_build2 (PLUS_EXPR, TREE_TYPE (tree_result),
   20338              :                                ctx->variant_part_offset, tree_result);
   20339              : 
   20340              :   /* If the byte offset is a constant, it's simpler to handle a native
   20341              :      constant rather than a DWARF expression.  */
   20342     14488207 :   if (TREE_CODE (tree_result) == INTEGER_CST)
   20343              :     {
   20344     14488167 :       *cst_offset = wi::to_offset (tree_result).to_shwi ();
   20345     14488167 :       return NULL;
   20346              :     }
   20347              : 
   20348           40 :   struct loc_descr_context loc_ctx = {
   20349           40 :     ctx->struct_type, /* context_type */
   20350              :     NULL_TREE,        /* base_decl */
   20351              :     NULL,             /* dpi */
   20352              :     false,            /* placeholder_arg */
   20353              :     false,            /* placeholder_seen */
   20354              :     false             /* strict_signedness */
   20355           40 :   };
   20356           40 :   loc_result = loc_list_from_tree (tree_result, 0, &loc_ctx);
   20357              : 
   20358              :   /* We want a DWARF expression: abort if we only have a location list with
   20359              :      multiple elements.  */
   20360           40 :   if (!loc_result || !single_element_loc_list_p (loc_result))
   20361              :     return NULL;
   20362              :   else
   20363           40 :     return loc_result->expr;
   20364              : }
   20365              : 
   20366              : /* The following routines define various Dwarf attributes and any data
   20367              :    associated with them.  */
   20368              : 
   20369              : /* Add a location description attribute value to a DIE.
   20370              : 
   20371              :    This emits location attributes suitable for whole variables and
   20372              :    whole parameters.  Note that the location attributes for struct fields are
   20373              :    generated by the routine `data_member_location_attribute' below.  */
   20374              : 
   20375              : static inline void
   20376     13837228 : add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
   20377              :                              dw_loc_list_ref descr)
   20378              : {
   20379     13837228 :   bool check_no_locviews = true;
   20380     13837228 :   if (descr == 0)
   20381              :     return;
   20382     13837094 :   if (single_element_loc_list_p (descr))
   20383      1022547 :     add_AT_loc (die, attr_kind, descr->expr);
   20384              :   else
   20385              :     {
   20386     12814547 :       add_AT_loc_list (die, attr_kind, descr);
   20387     12814547 :       gcc_assert (descr->ll_symbol);
   20388     12813650 :       if (attr_kind == DW_AT_location && descr->vl_symbol
   20389     25453991 :           && dwarf2out_locviews_in_attribute ())
   20390              :         {
   20391     12639444 :           add_AT_view_list (die, DW_AT_GNU_locviews);
   20392     12639444 :           check_no_locviews = false;
   20393              :         }
   20394              :     }
   20395              : 
   20396     13661991 :   if (check_no_locviews)
   20397      1197650 :     gcc_assert (!get_AT (die, DW_AT_GNU_locviews));
   20398              : }
   20399              : 
   20400              : /* Add DW_AT_accessibility attribute to DIE if needed.  */
   20401              : 
   20402              : static void
   20403    243874280 : add_accessibility_attribute (dw_die_ref die, tree decl)
   20404              : {
   20405              :   /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
   20406              :      children, otherwise the default is DW_ACCESS_public.  In DWARF2
   20407              :      the default has always been DW_ACCESS_public.  */
   20408    243874280 :   if (TREE_PROTECTED (decl))
   20409      5138672 :     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
   20410    238735608 :   else if (TREE_PRIVATE (decl))
   20411              :     {
   20412     17633481 :       if (dwarf_version == 2
   20413     17633334 :           || die->die_parent == NULL
   20414     17633334 :           || die->die_parent->die_tag != DW_TAG_class_type)
   20415      2905542 :         add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
   20416              :     }
   20417    221102127 :   else if (dwarf_version > 2
   20418    221059088 :            && die->die_parent
   20419    220916925 :            && die->die_parent->die_tag == DW_TAG_class_type)
   20420     62399674 :     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
   20421    243874280 : }
   20422              : 
   20423              : /* Attach the specialized form of location attribute used for data members of
   20424              :    struct and union types.  In the special case of a FIELD_DECL node which
   20425              :    represents a bit-field, the "offset" part of this special location
   20426              :    descriptor must indicate the distance in bytes from the lowest-addressed
   20427              :    byte of the containing struct or union type to the lowest-addressed byte of
   20428              :    the "containing object" for the bit-field.  (See the `field_byte_offset'
   20429              :    function above).
   20430              : 
   20431              :    For any given bit-field, the "containing object" is a hypothetical object
   20432              :    (of some integral or enum type) within which the given bit-field lives.  The
   20433              :    type of this hypothetical "containing object" is always the same as the
   20434              :    declared type of the individual bit-field itself (for GCC anyway... the
   20435              :    DWARF spec doesn't actually mandate this).  Note that it is the size (in
   20436              :    bytes) of the hypothetical "containing object" which will be given in the
   20437              :    DW_AT_byte_size attribute for this bit-field.  (See the
   20438              :    `byte_size_attribute' function below.)  It is also used when calculating the
   20439              :    value of the DW_AT_bit_offset attribute.  (See the `bit_offset_attribute'
   20440              :    function below.)
   20441              : 
   20442              :    CTX is required: see the comment for VLR_CONTEXT.  */
   20443              : 
   20444              : static void
   20445     37078841 : add_data_member_location_attribute (dw_die_ref die,
   20446              :                                     tree decl,
   20447              :                                     struct vlr_context *ctx)
   20448              : {
   20449     37078841 :   HOST_WIDE_INT offset;
   20450     37078841 :   dw_loc_descr_ref loc_descr = 0;
   20451              : 
   20452     37078841 :   if (TREE_CODE (decl) == TREE_BINFO)
   20453              :     {
   20454              :       /* We're working on the TAG_inheritance for a base class.  */
   20455     22076957 :       if (BINFO_VIRTUAL_P (decl) && is_cxx ())
   20456              :         {
   20457              :           /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
   20458              :              aren't at a fixed offset from all (sub)objects of the same
   20459              :              type.  We need to extract the appropriate offset from our
   20460              :              vtable.  The following dwarf expression means
   20461              : 
   20462              :                BaseAddr = ObAddr + *((*ObAddr) - Offset)
   20463              : 
   20464              :              This is specific to the V3 ABI, of course.  */
   20465              : 
   20466          308 :           dw_loc_descr_ref tmp;
   20467              : 
   20468              :           /* Make a copy of the object address.  */
   20469          308 :           tmp = new_loc_descr (DW_OP_dup, 0, 0);
   20470          308 :           add_loc_descr (&loc_descr, tmp);
   20471              : 
   20472              :           /* Extract the vtable address.  */
   20473          308 :           tmp = new_loc_descr (DW_OP_deref, 0, 0);
   20474          308 :           add_loc_descr (&loc_descr, tmp);
   20475              : 
   20476              :           /* Calculate the address of the offset.  */
   20477          308 :           offset = tree_to_shwi (BINFO_VPTR_FIELD (decl));
   20478          308 :           gcc_assert (offset < 0);
   20479              : 
   20480          308 :           tmp = int_loc_descriptor (-offset);
   20481          308 :           add_loc_descr (&loc_descr, tmp);
   20482          308 :           tmp = new_loc_descr (DW_OP_minus, 0, 0);
   20483          308 :           add_loc_descr (&loc_descr, tmp);
   20484              : 
   20485              :           /* Extract the offset.  */
   20486          308 :           tmp = new_loc_descr (DW_OP_deref, 0, 0);
   20487          308 :           add_loc_descr (&loc_descr, tmp);
   20488              : 
   20489              :           /* Add it to the object address.  */
   20490          308 :           tmp = new_loc_descr (DW_OP_plus, 0, 0);
   20491          616 :           add_loc_descr (&loc_descr, tmp);
   20492              :         }
   20493              :       else
   20494     22076649 :         offset = tree_to_shwi (BINFO_OFFSET (decl));
   20495              :     }
   20496              :   else
   20497              :     {
   20498     15001884 :       loc_descr = field_byte_offset (decl, ctx, &offset);
   20499              : 
   20500     15001884 :       if (!loc_descr)
   20501              :         ;
   20502              : 
   20503              :       /* If loc_descr is available, then we know the offset is dynamic.  */
   20504           24 :       else if (gnat_encodings == DWARF_GNAT_ENCODINGS_ALL)
   20505              :         {
   20506            0 :           loc_descr = NULL;
   20507            0 :           offset = 0;
   20508              :         }
   20509              : 
   20510              :       /* Data member location evaluation starts with the base address on the
   20511              :          stack.  Compute the field offset and add it to this base address.  */
   20512              :       else
   20513           48 :         add_loc_descr (&loc_descr, new_loc_descr (DW_OP_plus, 0, 0));
   20514              :     }
   20515              : 
   20516     37078841 :   if (!loc_descr)
   20517              :     {
   20518              :       /* While DW_AT_data_bit_offset has been added already in DWARF4,
   20519              :          e.g. GDB only added support to it in November 2016.  For DWARF5
   20520              :          we need newer debug info consumers anyway.  We might change this
   20521              :          to dwarf_version >= 4 once most consumers caught up.  */
   20522     37078509 :       if (dwarf_version >= 5
   20523     37066691 :           && TREE_CODE (decl) == FIELD_DECL
   20524     14990494 :           && DECL_BIT_FIELD_TYPE (decl)
   20525     37592134 :           && (ctx->variant_part_offset == NULL_TREE
   20526            0 :               || TREE_CODE (ctx->variant_part_offset) == INTEGER_CST))
   20527              :         {
   20528       513625 :           tree off = bit_position (decl);
   20529       513625 :           if (ctx->variant_part_offset)
   20530            0 :             off = bit_from_pos (ctx->variant_part_offset, off);
   20531       513625 :           if (tree_fits_uhwi_p (off) && get_AT (die, DW_AT_bit_size))
   20532              :             {
   20533       513625 :               remove_AT (die, DW_AT_byte_size);
   20534       513625 :               remove_AT (die, DW_AT_bit_offset);
   20535       513625 :               add_AT_unsigned (die, DW_AT_data_bit_offset, tree_to_uhwi (off));
   20536     37066813 :               return;
   20537              :             }
   20538              :         }
   20539     36564884 :       if (dwarf_version > 2)
   20540              :         {
   20541              :           /* Don't need to output a location expression, just the constant. */
   20542     36553188 :           if (offset < 0)
   20543            0 :             add_AT_int (die, DW_AT_data_member_location, offset);
   20544              :           else
   20545     36553188 :             add_AT_unsigned (die, DW_AT_data_member_location, offset);
   20546              :           return;
   20547              :         }
   20548              :       else
   20549              :         {
   20550        11696 :           enum dwarf_location_atom op;
   20551              : 
   20552              :           /* The DWARF2 standard says that we should assume that the structure
   20553              :              address is already on the stack, so we can specify a structure
   20554              :              field address by using DW_OP_plus_uconst.  */
   20555        11696 :           op = DW_OP_plus_uconst;
   20556        11696 :           loc_descr = new_loc_descr (op, offset, 0);
   20557              :         }
   20558              :     }
   20559              : 
   20560        12028 :   add_AT_loc (die, DW_AT_data_member_location, loc_descr);
   20561              : }
   20562              : 
   20563              : /* Writes integer values to dw_vec_const array.  */
   20564              : 
   20565              : static void
   20566       204071 : insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
   20567              : {
   20568      1016845 :   while (size != 0)
   20569              :     {
   20570       812774 :       *dest++ = val & 0xff;
   20571       812774 :       val >>= 8;
   20572       812774 :       --size;
   20573              :     }
   20574            0 : }
   20575              : 
   20576              : /* Reads integers from dw_vec_const array.  Inverse of insert_int.  */
   20577              : 
   20578              : static HOST_WIDE_INT
   20579      3587098 : extract_int (const unsigned char *src, unsigned int size)
   20580              : {
   20581      3587098 :   HOST_WIDE_INT val = 0;
   20582              : 
   20583      3587098 :   src += size;
   20584      7772389 :   while (size != 0)
   20585              :     {
   20586      4185291 :       val <<= 8;
   20587      4185291 :       val |= *--src & 0xff;
   20588      4185291 :       --size;
   20589              :     }
   20590      3587098 :   return val;
   20591              : }
   20592              : 
   20593              : /* Writes wide_int values to dw_vec_const array.  */
   20594              : 
   20595              : static void
   20596          520 : insert_wide_int (const wide_int_ref &val, unsigned char *dest, int elt_size)
   20597              : {
   20598          520 :   int i;
   20599              : 
   20600          520 :   if (elt_size <= HOST_BITS_PER_WIDE_INT/BITS_PER_UNIT)
   20601              :     {
   20602          520 :       insert_int ((HOST_WIDE_INT) val.elt (0), elt_size, dest);
   20603              :       return;
   20604              :     }
   20605              : 
   20606              :   /* We'd have to extend this code to support odd sizes.  */
   20607            0 :   gcc_assert (elt_size % (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) == 0);
   20608              : 
   20609            0 :   int n = elt_size / (HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT);
   20610              : 
   20611            0 :   if (WORDS_BIG_ENDIAN)
   20612              :     for (i = n - 1; i >= 0; i--)
   20613              :       {
   20614              :         insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
   20615              :         dest += sizeof (HOST_WIDE_INT);
   20616              :       }
   20617              :   else
   20618            0 :     for (i = 0; i < n; i++)
   20619              :       {
   20620            0 :         insert_int ((HOST_WIDE_INT) val.elt (i), sizeof (HOST_WIDE_INT), dest);
   20621            0 :         dest += sizeof (HOST_WIDE_INT);
   20622              :       }
   20623              : }
   20624              : 
   20625              : /* Writes floating point values to dw_vec_const array.  */
   20626              : 
   20627              : static unsigned
   20628        95175 : insert_float (const_rtx rtl, unsigned char *array)
   20629              : {
   20630        95175 :   long val[4];
   20631        95175 :   int i;
   20632        95175 :   scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
   20633              : 
   20634        95175 :   real_to_target (val, CONST_DOUBLE_REAL_VALUE (rtl), mode);
   20635              : 
   20636              :   /* real_to_target puts 32-bit pieces in each long.  Pack them.  */
   20637       190350 :   if (GET_MODE_SIZE (mode) < 4)
   20638              :     {
   20639         2502 :       gcc_assert (GET_MODE_SIZE (mode) == 2);
   20640         1251 :       insert_int (val[0], 2, array);
   20641              :       return 2;
   20642              :     }
   20643              : 
   20644       592448 :   for (i = 0; i < GET_MODE_SIZE (mode) / 4; i++)
   20645              :     {
   20646       202300 :       insert_int (val[i], 4, array);
   20647       202300 :       array += 4;
   20648              :     }
   20649              :   return 4;
   20650              : }
   20651              : 
   20652              : /* Attach a DW_AT_const_value attribute for a variable or a parameter which
   20653              :    does not have a "location" either in memory or in a register.  These
   20654              :    things can arise in GNU C when a constant is passed as an actual parameter
   20655              :    to an inlined function.  They can also arise in C++ where declared
   20656              :    constants do not necessarily get memory "homes".  */
   20657              : 
   20658              : static bool
   20659        60925 : add_const_value_attribute (dw_die_ref die, machine_mode mode, rtx rtl)
   20660              : {
   20661        60925 :   scalar_mode int_mode;
   20662              : 
   20663        60925 :   switch (GET_CODE (rtl))
   20664              :     {
   20665        43022 :     case CONST_INT:
   20666        43022 :       {
   20667        43022 :         HOST_WIDE_INT val = INTVAL (rtl);
   20668              : 
   20669        43022 :         if (val < 0)
   20670         1453 :           add_AT_int (die, DW_AT_const_value, val);
   20671              :         else
   20672        41569 :           add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
   20673              :       }
   20674              :       return true;
   20675              : 
   20676           49 :     case CONST_WIDE_INT:
   20677           49 :       if (is_int_mode (mode, &int_mode)
   20678           49 :           && (GET_MODE_PRECISION (int_mode)
   20679              :               & (HOST_BITS_PER_WIDE_INT - 1)) == 0)
   20680              :         {
   20681           49 :           add_AT_wide (die, DW_AT_const_value, rtx_mode_t (rtl, int_mode));
   20682           49 :           return true;
   20683              :         }
   20684              :       return false;
   20685              : 
   20686         7002 :     case CONST_DOUBLE:
   20687              :       /* Note that a CONST_DOUBLE rtx could represent either an integer or a
   20688              :          floating-point constant.  A CONST_DOUBLE is used whenever the
   20689              :          constant requires more than one word in order to be adequately
   20690              :          represented.  */
   20691         7002 :       if (TARGET_SUPPORTS_WIDE_INT == 0
   20692              :           && !SCALAR_FLOAT_MODE_P (GET_MODE (rtl)))
   20693              :         add_AT_double (die, DW_AT_const_value,
   20694              :                        CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
   20695              :       else
   20696              :         {
   20697         7002 :           scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
   20698         7002 :           unsigned int length = GET_MODE_SIZE (mode);
   20699         7002 :           unsigned char *array = ggc_vec_alloc<unsigned char> (length);
   20700         7002 :           unsigned int elt_size = insert_float (rtl, array);
   20701              : 
   20702         7002 :           add_AT_vec (die, DW_AT_const_value, length / elt_size, elt_size,
   20703              :                       array);
   20704              :         }
   20705         7002 :       return true;
   20706              : 
   20707           84 :     case CONST_VECTOR:
   20708           84 :       {
   20709           84 :         unsigned int length;
   20710          168 :         if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
   20711        60925 :           return false;
   20712              : 
   20713           84 :         machine_mode mode = GET_MODE (rtl);
   20714              :         /* The combination of a length and byte elt_size doesn't extend
   20715              :            naturally to boolean vectors, where several elements are packed
   20716              :            into the same byte.  */
   20717           84 :         if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL)
   20718              :           return false;
   20719              : 
   20720           84 :         unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
   20721           84 :         unsigned char *array
   20722           84 :           = ggc_vec_alloc<unsigned char> (length * elt_size);
   20723           84 :         unsigned int i;
   20724           84 :         unsigned char *p;
   20725           84 :         machine_mode imode = GET_MODE_INNER (mode);
   20726              : 
   20727           84 :         switch (GET_MODE_CLASS (mode))
   20728              :           {
   20729              :           case MODE_VECTOR_INT:
   20730          555 :             for (i = 0, p = array; i < length; i++, p += elt_size)
   20731              :               {
   20732          488 :                 rtx elt = CONST_VECTOR_ELT (rtl, i);
   20733          488 :                 insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
   20734              :               }
   20735              :             break;
   20736              : 
   20737              :           case MODE_VECTOR_FLOAT:
   20738           81 :             for (i = 0, p = array; i < length; i++, p += elt_size)
   20739              :               {
   20740           64 :                 rtx elt = CONST_VECTOR_ELT (rtl, i);
   20741           64 :                 insert_float (elt, p);
   20742              :               }
   20743              :             break;
   20744              : 
   20745            0 :           default:
   20746            0 :             gcc_unreachable ();
   20747              :           }
   20748              : 
   20749           84 :         add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
   20750              :       }
   20751           84 :       return true;
   20752              : 
   20753          268 :     case CONST_STRING:
   20754          268 :       if (dwarf_version >= 4 || !dwarf_strict)
   20755              :         {
   20756          268 :           dw_loc_descr_ref loc_result;
   20757          268 :           resolve_one_addr (&rtl);
   20758         8850 :         rtl_addr:
   20759         8850 :           loc_result = new_addr_loc_descr (rtl, dtprel_false);
   20760         8850 :           add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
   20761         8850 :           add_AT_loc (die, DW_AT_location, loc_result);
   20762         8850 :           vec_safe_push (used_rtx_array, rtl);
   20763         8850 :           return true;
   20764              :         }
   20765              :       return false;
   20766              : 
   20767          372 :     case CONST:
   20768          372 :       if (CONSTANT_P (XEXP (rtl, 0)))
   20769            0 :         return add_const_value_attribute (die, mode, XEXP (rtl, 0));
   20770              :       /* FALLTHROUGH */
   20771        10425 :     case SYMBOL_REF:
   20772        10425 :       if (!const_ok_for_output (rtl))
   20773              :         return false;
   20774              :       /* FALLTHROUGH */
   20775         8582 :     case LABEL_REF:
   20776         8582 :       if (dwarf_version >= 4 || !dwarf_strict)
   20777         8582 :         goto rtl_addr;
   20778              :       return false;
   20779              : 
   20780              :     case PLUS:
   20781              :       /* In cases where an inlined instance of an inline function is passed
   20782              :          the address of an `auto' variable (which is local to the caller) we
   20783              :          can get a situation where the DECL_RTL of the artificial local
   20784              :          variable (for the inlining) which acts as a stand-in for the
   20785              :          corresponding formal parameter (of the inline function) will look
   20786              :          like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).  This is not
   20787              :          exactly a compile-time constant expression, but it isn't the address
   20788              :          of the (artificial) local variable either.  Rather, it represents the
   20789              :          *value* which the artificial local variable always has during its
   20790              :          lifetime.  We currently have no way to represent such quasi-constant
   20791              :          values in Dwarf, so for now we just punt and generate nothing.  */
   20792              :       return false;
   20793              : 
   20794              :     case HIGH:
   20795              :     case CONST_FIXED:
   20796              :     case MINUS:
   20797              :     case SIGN_EXTEND:
   20798              :     case ZERO_EXTEND:
   20799              :     case CONST_POLY_INT:
   20800              :       return false;
   20801              : 
   20802           71 :     case MEM:
   20803           71 :       if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
   20804           71 :           && MEM_READONLY_P (rtl)
   20805          142 :           && GET_MODE (rtl) == BLKmode)
   20806              :         {
   20807           71 :           add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
   20808           71 :           return true;
   20809              :         }
   20810              :       return false;
   20811              : 
   20812            0 :     default:
   20813              :       /* No other kinds of rtx should be possible here.  */
   20814            0 :       gcc_unreachable ();
   20815              :     }
   20816              : }
   20817              : 
   20818              : /* Determine whether the evaluation of EXPR references any variables
   20819              :    or functions which aren't otherwise used (and therefore may not be
   20820              :    output).  */
   20821              : static tree
   20822        10513 : reference_to_unused (tree * tp, int * walk_subtrees,
   20823              :                      void * data ATTRIBUTE_UNUSED)
   20824              : {
   20825        10513 :   if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
   20826         2639 :     *walk_subtrees = 0;
   20827              : 
   20828        10513 :   if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
   20829           17 :       && ! TREE_ASM_WRITTEN (*tp))
   20830              :     return *tp;
   20831              :   /* ???  The C++ FE emits debug information for using decls, so
   20832              :      putting gcc_unreachable here falls over.  See PR31899.  For now
   20833              :      be conservative.  */
   20834        10496 :   else if (!symtab->global_info_ready && VAR_P (*tp))
   20835              :     return *tp;
   20836        10117 :   else if (VAR_P (*tp))
   20837              :     {
   20838         2023 :       varpool_node *node = varpool_node::get (*tp);
   20839         2023 :       if (!node || !node->definition)
   20840         2018 :         return *tp;
   20841              :     }
   20842         8094 :   else if (TREE_CODE (*tp) == FUNCTION_DECL
   20843         8094 :            && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
   20844              :     {
   20845              :       /* The call graph machinery must have finished analyzing,
   20846              :          optimizing and gimplifying the CU by now.
   20847              :          So if *TP has no call graph node associated
   20848              :          to it, it means *TP will not be emitted.  */
   20849          193 :       if (!symtab->global_info_ready || !cgraph_node::get (*tp))
   20850          127 :         return *tp;
   20851              :     }
   20852         7901 :   else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
   20853          329 :     return *tp;
   20854              : 
   20855              :   return NULL_TREE;
   20856              : }
   20857              : 
   20858              : /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
   20859              :    for use in a later add_const_value_attribute call.  */
   20860              : 
   20861              : static rtx
   20862       170922 : rtl_for_decl_init (tree init, tree type)
   20863              : {
   20864       170922 :   rtx rtl = NULL_RTX;
   20865              : 
   20866       170922 :   STRIP_NOPS (init);
   20867              : 
   20868              :   /* If a variable is initialized with a string constant without embedded
   20869              :      zeros, build CONST_STRING.  */
   20870       170922 :   if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
   20871              :     {
   20872          451 :       tree enttype = TREE_TYPE (type);
   20873          451 :       tree domain = TYPE_DOMAIN (type);
   20874          451 :       scalar_int_mode mode;
   20875              : 
   20876          902 :       if (is_int_mode (TYPE_MODE (enttype), &mode)
   20877          451 :           && GET_MODE_SIZE (mode) == 1
   20878          440 :           && domain
   20879          440 :           && TYPE_MAX_VALUE (domain)
   20880          404 :           && TREE_CODE (TYPE_MAX_VALUE (domain)) == INTEGER_CST
   20881          404 :           && integer_zerop (TYPE_MIN_VALUE (domain))
   20882          395 :           && compare_tree_int (TYPE_MAX_VALUE (domain),
   20883          395 :                                TREE_STRING_LENGTH (init) - 1) == 0
   20884          257 :           && ((size_t) TREE_STRING_LENGTH (init)
   20885          257 :               == strlen (TREE_STRING_POINTER (init)) + 1))
   20886              :         {
   20887          219 :           rtl = gen_rtx_CONST_STRING (VOIDmode,
   20888              :                                       ggc_strdup (TREE_STRING_POINTER (init)));
   20889          219 :           rtl = gen_rtx_MEM (BLKmode, rtl);
   20890          219 :           MEM_READONLY_P (rtl) = 1;
   20891              :         }
   20892              :     }
   20893              :   /* Other aggregates, and complex values, could be represented using
   20894              :      CONCAT: FIXME!
   20895              :      If this changes, please adjust tree_add_const_value_attribute
   20896              :      so that for early_dwarf it will for such initializers mangle referenced
   20897              :      decls.  */
   20898       170471 :   else if (AGGREGATE_TYPE_P (type)
   20899         6771 :            || (TREE_CODE (init) == VIEW_CONVERT_EXPR
   20900            0 :                && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
   20901       177242 :            || TREE_CODE (type) == COMPLEX_TYPE)
   20902              :     ;
   20903              :   /* Vectors only work if their mode is supported by the target.
   20904              :      FIXME: generic vectors ought to work too.  */
   20905         6754 :   else if (TREE_CODE (type) == VECTOR_TYPE
   20906         6754 :            && !VECTOR_MODE_P (TYPE_MODE (type)))
   20907              :     ;
   20908              :   /* If the initializer is something that we know will expand into an
   20909              :      immediate RTL constant, expand it now.  We must be careful not to
   20910              :      reference variables which won't be output.  */
   20911         6750 :   else if (initializer_constant_valid_p (init, type)
   20912         6750 :            && ! walk_tree (&init, reference_to_unused, NULL, NULL))
   20913              :     {
   20914              :       /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
   20915              :          possible.  */
   20916         3879 :       if (TREE_CODE (type) == VECTOR_TYPE)
   20917           81 :         switch (TREE_CODE (init))
   20918              :           {
   20919              :           case VECTOR_CST:
   20920              :             break;
   20921            0 :           case CONSTRUCTOR:
   20922            0 :             if (TREE_CONSTANT (init))
   20923              :               {
   20924            0 :                 vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (init);
   20925            0 :                 bool constant_p = true;
   20926            0 :                 tree value;
   20927            0 :                 unsigned HOST_WIDE_INT ix;
   20928              : 
   20929              :                 /* Even when ctor is constant, it might contain non-*_CST
   20930              :                    elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
   20931              :                    belong into VECTOR_CST nodes.  */
   20932            0 :                 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
   20933            0 :                   if (!CONSTANT_CLASS_P (value))
   20934              :                     {
   20935              :                       constant_p = false;
   20936              :                       break;
   20937              :                     }
   20938              : 
   20939            0 :                 if (constant_p)
   20940              :                   {
   20941            0 :                     init = build_vector_from_ctor (type, elts);
   20942            0 :                     break;
   20943              :                   }
   20944              :               }
   20945              :             /* FALLTHRU */
   20946              : 
   20947              :           default:
   20948              :             return NULL;
   20949              :           }
   20950              : 
   20951              :       /* Large _BitInt BLKmode INTEGER_CSTs would yield a MEM.  */
   20952         3879 :       if (TREE_CODE (init) == INTEGER_CST
   20953          250 :           && TREE_CODE (TREE_TYPE (init)) == BITINT_TYPE
   20954         3879 :           && TYPE_MODE (TREE_TYPE (init)) == BLKmode)
   20955              :         {
   20956            0 :           if (tree_fits_shwi_p (init))
   20957            0 :             return GEN_INT (tree_to_shwi (init));
   20958              :           else
   20959              :             return NULL;
   20960              :         }
   20961              : 
   20962         3879 :       rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
   20963              : 
   20964              :       /* If expand_expr returns a MEM, it wasn't immediate.  */
   20965         3879 :       gcc_assert (!rtl || !MEM_P (rtl));
   20966              :     }
   20967              : 
   20968              :   return rtl;
   20969              : }
   20970              : 
   20971              : /* Generate RTL for the variable DECL to represent its location.  */
   20972              : 
   20973              : static rtx
   20974     20326130 : rtl_for_decl_location (tree decl)
   20975              : {
   20976     20326130 :   rtx rtl;
   20977              : 
   20978              :   /* Here we have to decide where we are going to say the parameter "lives"
   20979              :      (as far as the debugger is concerned).  We only have a couple of
   20980              :      choices.  GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
   20981              : 
   20982              :      DECL_RTL normally indicates where the parameter lives during most of the
   20983              :      activation of the function.  If optimization is enabled however, this
   20984              :      could be either NULL or else a pseudo-reg.  Both of those cases indicate
   20985              :      that the parameter doesn't really live anywhere (as far as the code
   20986              :      generation parts of GCC are concerned) during most of the function's
   20987              :      activation.  That will happen (for example) if the parameter is never
   20988              :      referenced within the function.
   20989              : 
   20990              :      We could just generate a location descriptor here for all non-NULL
   20991              :      non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
   20992              :      a little nicer than that if we also consider DECL_INCOMING_RTL in cases
   20993              :      where DECL_RTL is NULL or is a pseudo-reg.
   20994              : 
   20995              :      Note however that we can only get away with using DECL_INCOMING_RTL as
   20996              :      a backup substitute for DECL_RTL in certain limited cases.  In cases
   20997              :      where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
   20998              :      we can be sure that the parameter was passed using the same type as it is
   20999              :      declared to have within the function, and that its DECL_INCOMING_RTL
   21000              :      points us to a place where a value of that type is passed.
   21001              : 
   21002              :      In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
   21003              :      we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
   21004              :      because in these cases DECL_INCOMING_RTL points us to a value of some
   21005              :      type which is *different* from the type of the parameter itself.  Thus,
   21006              :      if we tried to use DECL_INCOMING_RTL to generate a location attribute in
   21007              :      such cases, the debugger would end up (for example) trying to fetch a
   21008              :      `float' from a place which actually contains the first part of a
   21009              :      `double'.  That would lead to really incorrect and confusing
   21010              :      output at debug-time.
   21011              : 
   21012              :      So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
   21013              :      in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl).  There
   21014              :      are a couple of exceptions however.  On little-endian machines we can
   21015              :      get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
   21016              :      not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
   21017              :      an integral type that is smaller than TREE_TYPE (decl). These cases arise
   21018              :      when (on a little-endian machine) a non-prototyped function has a
   21019              :      parameter declared to be of type `short' or `char'.  In such cases,
   21020              :      TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
   21021              :      be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
   21022              :      passed `int' value.  If the debugger then uses that address to fetch
   21023              :      a `short' or a `char' (on a little-endian machine) the result will be
   21024              :      the correct data, so we allow for such exceptional cases below.
   21025              : 
   21026              :      Note that our goal here is to describe the place where the given formal
   21027              :      parameter lives during most of the function's activation (i.e. between the
   21028              :      end of the prologue and the start of the epilogue).  We'll do that as best
   21029              :      as we can. Note however that if the given formal parameter is modified
   21030              :      sometime during the execution of the function, then a stack backtrace (at
   21031              :      debug-time) will show the function as having been called with the *new*
   21032              :      value rather than the value which was originally passed in.  This happens
   21033              :      rarely enough that it is not a major problem, but it *is* a problem, and
   21034              :      I'd like to fix it.
   21035              : 
   21036              :      A future version of dwarf2out.cc may generate two additional attributes for
   21037              :      any given DW_TAG_formal_parameter DIE which will describe the "passed
   21038              :      type" and the "passed location" for the given formal parameter in addition
   21039              :      to the attributes we now generate to indicate the "declared type" and the
   21040              :      "active location" for each parameter.  This additional set of attributes
   21041              :      could be used by debuggers for stack backtraces. Separately, note that
   21042              :      sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
   21043              :      This happens (for example) for inlined-instances of inline function formal
   21044              :      parameters which are never referenced.  This really shouldn't be
   21045              :      happening.  All PARM_DECL nodes should get valid non-NULL
   21046              :      DECL_INCOMING_RTL values.  FIXME.  */
   21047              : 
   21048              :   /* Use DECL_RTL as the "location" unless we find something better.  */
   21049     20326130 :   rtl = DECL_RTL_IF_SET (decl);
   21050              : 
   21051              :   /* When generating abstract instances, ignore everything except
   21052              :      constants, symbols living in memory, and symbols living in
   21053              :      fixed registers.  */
   21054     20326130 :   if (! reload_completed)
   21055              :     {
   21056       467617 :       if (rtl
   21057       457313 :           && (CONSTANT_P (rtl)
   21058       457313 :               || (MEM_P (rtl)
   21059       457313 :                   && CONSTANT_P (XEXP (rtl, 0)))
   21060            0 :               || (REG_P (rtl)
   21061            0 :                   && VAR_P (decl)
   21062            0 :                   && TREE_STATIC (decl))))
   21063              :         {
   21064       457313 :           rtl = targetm.delegitimize_address (rtl);
   21065       457313 :           return rtl;
   21066              :         }
   21067              :       rtl = NULL_RTX;
   21068              :     }
   21069     19858513 :   else if (TREE_CODE (decl) == PARM_DECL)
   21070              :     {
   21071      1151239 :       if (rtl == NULL_RTX
   21072      1151235 :           || is_pseudo_reg (rtl)
   21073      1509806 :           || (MEM_P (rtl)
   21074       214583 :               && is_pseudo_reg (XEXP (rtl, 0))
   21075           22 :               && DECL_INCOMING_RTL (decl)
   21076           22 :               && MEM_P (DECL_INCOMING_RTL (decl))
   21077           22 :               && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
   21078              :         {
   21079       792694 :           tree declared_type = TREE_TYPE (decl);
   21080       792694 :           tree passed_type = DECL_ARG_TYPE (decl);
   21081       792694 :           machine_mode dmode = TYPE_MODE (declared_type);
   21082       792694 :           machine_mode pmode = TYPE_MODE (passed_type);
   21083              : 
   21084              :           /* This decl represents a formal parameter which was optimized out.
   21085              :              Note that DECL_INCOMING_RTL may be NULL in here, but we handle
   21086              :              all cases where (rtl == NULL_RTX) just below.  */
   21087       792694 :           if (dmode == pmode)
   21088       791865 :             rtl = DECL_INCOMING_RTL (decl);
   21089          829 :           else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
   21090          829 :                    && SCALAR_INT_MODE_P (dmode)
   21091         1458 :                    && known_le (GET_MODE_SIZE (dmode), GET_MODE_SIZE (pmode))
   21092         1558 :                    && DECL_INCOMING_RTL (decl))
   21093              :             {
   21094          729 :               rtx inc = DECL_INCOMING_RTL (decl);
   21095          729 :               if (REG_P (inc))
   21096              :                 rtl = inc;
   21097            0 :               else if (MEM_P (inc))
   21098              :                 {
   21099              :                   if (BYTES_BIG_ENDIAN)
   21100              :                     rtl = adjust_address_nv (inc, dmode,
   21101              :                                              GET_MODE_SIZE (pmode)
   21102              :                                              - GET_MODE_SIZE (dmode));
   21103              :                   else
   21104              :                     rtl = inc;
   21105              :                 }
   21106              :             }
   21107              :         }
   21108              : 
   21109              :       /* If the parm was passed in registers, but lives on the stack, then
   21110              :          make a big endian correction if the mode of the type of the
   21111              :          parameter is not the same as the mode of the rtl.  */
   21112              :       /* ??? This is the same series of checks that are made in dbxout.cc before
   21113              :          we reach the big endian correction code there.  It isn't clear if all
   21114              :          of these checks are necessary here, but keeping them all is the safe
   21115              :          thing to do.  */
   21116       358545 :       else if (MEM_P (rtl)
   21117       214561 :                && XEXP (rtl, 0) != const0_rtx
   21118       214561 :                && ! CONSTANT_P (XEXP (rtl, 0))
   21119              :                /* Not passed in memory.  */
   21120       214561 :                && !MEM_P (DECL_INCOMING_RTL (decl))
   21121              :                /* Not passed by invisible reference.  */
   21122       518013 :                && (!REG_P (XEXP (rtl, 0))
   21123         8214 :                    || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
   21124              :                    || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
   21125              : #if !HARD_FRAME_POINTER_IS_ARG_POINTER
   21126              :                    || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
   21127              : #endif
   21128              :                      )
   21129              :                /* Big endian correction check.  */
   21130              :                && BYTES_BIG_ENDIAN
   21131              :                && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
   21132              :                && known_lt (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))),
   21133              :                             UNITS_PER_WORD))
   21134              :         {
   21135              :           machine_mode addr_mode = get_address_mode (rtl);
   21136              :           poly_int64 offset = (UNITS_PER_WORD
   21137              :                                - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
   21138              : 
   21139              :           rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
   21140              :                              plus_constant (addr_mode, XEXP (rtl, 0), offset));
   21141              :         }
   21142              :     }
   21143     18707274 :   else if (VAR_P (decl)
   21144     18707274 :            && rtl
   21145      1281833 :            && MEM_P (rtl)
   21146     19247338 :            && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)))
   21147              :     {
   21148            4 :       machine_mode addr_mode = get_address_mode (rtl);
   21149            4 :       poly_int64 offset = byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl)),
   21150            4 :                                                GET_MODE (rtl));
   21151              : 
   21152              :       /* If a variable is declared "register" yet is smaller than
   21153              :          a register, then if we store the variable to memory, it
   21154              :          looks like we're storing a register-sized value, when in
   21155              :          fact we are not.  We need to adjust the offset of the
   21156              :          storage location to reflect the actual value's bytes,
   21157              :          else gdb will not be able to display it.  */
   21158            4 :       if (maybe_ne (offset, 0))
   21159            0 :         rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
   21160              :                            plus_constant (addr_mode, XEXP (rtl, 0), offset));
   21161              :     }
   21162              : 
   21163              :   /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
   21164              :      and will have been substituted directly into all expressions that use it.
   21165              :      C does not have such a concept, but C++ and other languages do.  */
   21166     19710678 :   if (!rtl && VAR_P (decl) && DECL_INITIAL (decl))
   21167        15326 :     rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
   21168              : 
   21169     19868817 :   if (rtl)
   21170      2433563 :     rtl = targetm.delegitimize_address (rtl);
   21171              : 
   21172              :   /* If we don't look past the constant pool, we risk emitting a
   21173              :      reference to a constant pool entry that isn't referenced from
   21174              :      code, and thus is not emitted.  */
   21175      2433563 :   if (rtl)
   21176      2433563 :     rtl = avoid_constant_pool_reference (rtl);
   21177              : 
   21178              :   /* Try harder to get a rtl.  If this symbol ends up not being emitted
   21179              :      in the current CU, resolve_addr will remove the expression referencing
   21180              :      it.  */
   21181      2433563 :   if (rtl == NULL_RTX
   21182     17435254 :       && !(early_dwarf && (flag_generate_lto || flag_generate_offload))
   21183     17435100 :       && VAR_P (decl)
   21184     17434067 :       && !DECL_EXTERNAL (decl)
   21185     17434067 :       && TREE_STATIC (decl)
   21186        27293 :       && DECL_NAME (decl)
   21187        27293 :       && !DECL_HARD_REGISTER (decl)
   21188      2460856 :       && DECL_MODE (decl) != VOIDmode)
   21189              :     {
   21190        27293 :       rtl = make_decl_rtl_for_debug (decl);
   21191        27293 :       if (!MEM_P (rtl)
   21192        27293 :           || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
   21193        54586 :           || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
   21194              :         rtl = NULL_RTX;
   21195              :     }
   21196              : 
   21197              :   return rtl;
   21198              : }
   21199              : 
   21200              : /* Check whether decl is a Fortran COMMON symbol.  If not, NULL_TREE is
   21201              :    returned.  If so, the decl for the COMMON block is returned, and the
   21202              :    value is the offset into the common block for the symbol.  */
   21203              : 
   21204              : static tree
   21205     61481301 : fortran_common (tree decl, HOST_WIDE_INT *value)
   21206              : {
   21207     61481301 :   tree val_expr, cvar;
   21208     61481301 :   machine_mode mode;
   21209     61481301 :   poly_int64 bitsize, bitpos;
   21210     61481301 :   tree offset;
   21211     61481301 :   HOST_WIDE_INT cbitpos;
   21212     61481301 :   int unsignedp, reversep, volatilep = 0;
   21213              : 
   21214              :   /* If the decl isn't a VAR_DECL, or if it isn't static, or if
   21215              :      it does not have a value (the offset into the common area), or if it
   21216              :      is thread local (as opposed to global) then it isn't common, and shouldn't
   21217              :      be handled as such.  */
   21218     61481301 :   if (!VAR_P (decl)
   21219     61481301 :       || !TREE_STATIC (decl)
   21220     55842701 :       || !DECL_HAS_VALUE_EXPR_P (decl)
   21221     61515241 :       || !is_fortran ())
   21222              :     return NULL_TREE;
   21223              : 
   21224         1121 :   val_expr = DECL_VALUE_EXPR (decl);
   21225         1121 :   if (TREE_CODE (val_expr) != COMPONENT_REF)
   21226              :     return NULL_TREE;
   21227              : 
   21228         1121 :   cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset, &mode,
   21229              :                               &unsignedp, &reversep, &volatilep);
   21230              : 
   21231         1121 :   if (cvar == NULL_TREE
   21232         1121 :       || !VAR_P (cvar)
   21233         1121 :       || DECL_ARTIFICIAL (cvar)
   21234         1060 :       || !TREE_PUBLIC (cvar)
   21235              :       /* We don't expect to have to cope with variable offsets,
   21236              :          since at present all static data must have a constant size.  */
   21237         1121 :       || !bitpos.is_constant (&cbitpos))
   21238              :     return NULL_TREE;
   21239              : 
   21240         1060 :   *value = 0;
   21241         1060 :   if (offset != NULL)
   21242              :     {
   21243            0 :       if (!tree_fits_shwi_p (offset))
   21244              :         return NULL_TREE;
   21245            0 :       *value = tree_to_shwi (offset);
   21246              :     }
   21247         1060 :   if (cbitpos != 0)
   21248          719 :     *value += cbitpos / BITS_PER_UNIT;
   21249              : 
   21250              :   return cvar;
   21251              : }
   21252              : 
   21253              : /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
   21254              :    data attribute for a variable or a parameter.  We generate the
   21255              :    DW_AT_const_value attribute only in those cases where the given variable
   21256              :    or parameter does not have a true "location" either in memory or in a
   21257              :    register.  This can happen (for example) when a constant is passed as an
   21258              :    actual argument in a call to an inline function.  (It's possible that
   21259              :    these things can crop up in other ways also.)  Note that one type of
   21260              :    constant value which can be passed into an inlined function is a constant
   21261              :    pointer.  This can happen for example if an actual argument in an inlined
   21262              :    function call evaluates to a compile-time constant address.
   21263              : 
   21264              :    CACHE_P is true if it is worth caching the location list for DECL,
   21265              :    so that future calls can reuse it rather than regenerate it from scratch.
   21266              :    This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
   21267              :    since we will need to refer to them each time the function is inlined.  */
   21268              : 
   21269              : static bool
   21270     21556335 : add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p)
   21271              : {
   21272     21556335 :   rtx rtl;
   21273     21556335 :   dw_loc_list_ref list;
   21274     21556335 :   var_loc_list *loc_list;
   21275     21556335 :   cached_dw_loc_list *cache;
   21276              : 
   21277     21556335 :   if (early_dwarf)
   21278              :     return false;
   21279              : 
   21280     17300459 :   if (TREE_CODE (decl) == ERROR_MARK)
   21281              :     return false;
   21282              : 
   21283     17300459 :   if (get_AT (die, DW_AT_location)
   21284     17300459 :       || get_AT (die, DW_AT_const_value))
   21285              :     return true;
   21286              : 
   21287     17283801 :   gcc_assert (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL
   21288              :               || TREE_CODE (decl) == RESULT_DECL);
   21289              : 
   21290              :   /* Try to get some constant RTL for this decl, and use that as the value of
   21291              :      the location.  */
   21292              : 
   21293     17283801 :   rtl = rtl_for_decl_location (decl);
   21294      2210876 :   if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
   21295     17284148 :       && add_const_value_attribute (die, DECL_MODE (decl), rtl))
   21296              :     return true;
   21297              : 
   21298              :   /* See if we have single element location list that is equivalent to
   21299              :      a constant value.  That way we are better to use add_const_value_attribute
   21300              :      rather than expanding constant value equivalent.  */
   21301     17283454 :   loc_list = lookup_decl_loc (decl);
   21302     17283454 :   if (loc_list
   21303     14170458 :       && loc_list->first
   21304     14170458 :       && loc_list->first->next == NULL
   21305      1347442 :       && NOTE_P (loc_list->first->loc)
   21306      1334357 :       && NOTE_VAR_LOCATION (loc_list->first->loc)
   21307      1334357 :       && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
   21308              :     {
   21309       458746 :       struct var_loc_node *node;
   21310              : 
   21311       458746 :       node = loc_list->first;
   21312       458746 :       rtl = NOTE_VAR_LOCATION_LOC (node->loc);
   21313       458746 :       if (GET_CODE (rtl) == EXPR_LIST)
   21314            0 :         rtl = XEXP (rtl, 0);
   21315       402039 :       if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
   21316       459014 :           && add_const_value_attribute (die, DECL_MODE (decl), rtl))
   21317              :          return true;
   21318              :     }
   21319              :   /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
   21320              :      list several times.  See if we've already cached the contents.  */
   21321     14115307 :   list = NULL;
   21322     14115307 :   if (loc_list == NULL || cached_dw_loc_list_table == NULL)
   21323              :     cache_p = false;
   21324     14115307 :   if (cache_p)
   21325              :     {
   21326            0 :       cache = cached_dw_loc_list_table->find_with_hash (decl, DECL_UID (decl));
   21327            0 :       if (cache)
   21328            0 :         list = cache->loc_list;
   21329              :     }
   21330            0 :   if (list == NULL)
   21331              :     {
   21332     34379865 :       list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2,
   21333              :                                  NULL);
   21334              :       /* It is usually worth caching this result if the decl is from
   21335              :          BLOCK_NONLOCALIZED_VARS and if the list has at least two elements.  */
   21336     17228303 :       if (cache_p && list && list->dw_loc_next)
   21337              :         {
   21338            0 :           cached_dw_loc_list **slot
   21339            0 :             = cached_dw_loc_list_table->find_slot_with_hash (decl,
   21340            0 :                                                              DECL_UID (decl),
   21341              :                                                              INSERT);
   21342            0 :           cache = ggc_cleared_alloc<cached_dw_loc_list> ();
   21343            0 :           cache->decl_id = DECL_UID (decl);
   21344            0 :           cache->loc_list = list;
   21345            0 :           *slot = cache;
   21346              :         }
   21347              :     }
   21348     17228303 :   if (list)
   21349              :     {
   21350     13819636 :       add_AT_location_description (die, DW_AT_location, list);
   21351     13819636 :       return true;
   21352              :     }
   21353              :   /* None of that worked, so it must not really have a location;
   21354              :      try adding a constant value attribute from the DECL_INITIAL.  */
   21355      3408667 :   return tree_add_const_value_attribute_for_decl (die, decl);
   21356              : }
   21357              : 
   21358              : /* Mangle referenced decls.  */
   21359              : static tree
   21360     50222886 : mangle_referenced_decls (tree *tp, int *walk_subtrees, void *)
   21361              : {
   21362     50222886 :   if (! EXPR_P (*tp)
   21363     48834237 :       && ! CONSTANT_CLASS_P (*tp)
   21364      2508762 :       && TREE_CODE (*tp) != CONSTRUCTOR)
   21365         2843 :     *walk_subtrees = 0;
   21366              : 
   21367     50222886 :   if (VAR_OR_FUNCTION_DECL_P (*tp))
   21368         2843 :     assign_assembler_name_if_needed (*tp);
   21369              : 
   21370     50222886 :   return NULL_TREE;
   21371              : }
   21372              : 
   21373              : /* Attach a DW_AT_const_value attribute to DIE. The value of the
   21374              :    attribute is the const value T.  */
   21375              : 
   21376              : static bool
   21377     36557262 : tree_add_const_value_attribute (dw_die_ref die, tree t)
   21378              : {
   21379     36557262 :   tree init;
   21380     36557262 :   tree type = TREE_TYPE (t);
   21381              : 
   21382     36557262 :   if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
   21383              :     return false;
   21384              : 
   21385     36557261 :   init = t;
   21386     36557261 :   gcc_assert (!DECL_P (init));
   21387              : 
   21388     36557261 :   if (TREE_CODE (init) == INTEGER_CST)
   21389              :     {
   21390     34100349 :       if (tree_fits_uhwi_p (init))
   21391              :         {
   21392     33892360 :           add_AT_unsigned (die, DW_AT_const_value, tree_to_uhwi (init));
   21393     33892360 :           return true;
   21394              :         }
   21395       207989 :       if (tree_fits_shwi_p (init))
   21396              :         {
   21397       207967 :           add_AT_int (die, DW_AT_const_value, tree_to_shwi (init));
   21398       207967 :           return true;
   21399              :         }
   21400              :     }
   21401      2456934 :   if (!early_dwarf)
   21402              :     {
   21403       155596 :       rtx rtl = rtl_for_decl_init (init, type);
   21404       155596 :       if (rtl)
   21405         3603 :         return add_const_value_attribute (die, TYPE_MODE (type), rtl);
   21406              :     }
   21407              :   else
   21408              :     {
   21409              :       /* For early_dwarf force mangling of all referenced symbols.  */
   21410      2301338 :       tree initializer = init;
   21411      2301338 :       STRIP_NOPS (initializer);
   21412      2301338 :       if (initializer_constant_valid_p (initializer, type))
   21413      2301281 :         walk_tree (&initializer, mangle_referenced_decls, NULL, NULL);
   21414              :     }
   21415              :   /* If the host and target are sane, try harder.  */
   21416      2453331 :   if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
   21417      2453331 :       && initializer_constant_valid_p (init, type))
   21418              :     {
   21419      2453273 :       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
   21420      2453273 :       if (size > 0 && (int) size == size)
   21421              :         {
   21422      2453194 :           unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
   21423              : 
   21424      2453194 :           if (native_encode_initializer (init, array, size) == size)
   21425              :             {
   21426      2435279 :               add_AT_vec (die, DW_AT_const_value, size, 1, array);
   21427      2435279 :               return true;
   21428              :             }
   21429        17915 :           ggc_free (array);
   21430              :         }
   21431              :     }
   21432              :   return false;
   21433              : }
   21434              : 
   21435              : /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
   21436              :    attribute is the const value of T, where T is an integral constant
   21437              :    variable with static storage duration
   21438              :    (so it can't be a PARM_DECL or a RESULT_DECL).  */
   21439              : 
   21440              : static bool
   21441     59357446 : tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
   21442              : {
   21443              : 
   21444     59357446 :   if (!decl
   21445     59357446 :       || (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
   21446     59356768 :       || (VAR_P (decl) && !TREE_STATIC (decl)))
   21447              :     return false;
   21448              : 
   21449     55322744 :   if (TREE_READONLY (decl)
   21450     55051261 :       && ! TREE_THIS_VOLATILE (decl)
   21451    110373839 :       && DECL_INITIAL (decl))
   21452              :     /* OK */;
   21453              :   else
   21454              :     return false;
   21455              : 
   21456              :   /* Don't add DW_AT_const_value if abstract origin already has one.  */
   21457     50754187 :   if (get_AT (var_die, DW_AT_const_value))
   21458              :     return false;
   21459              : 
   21460     26010703 :   return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
   21461              : }
   21462              : 
   21463              : /* Convert the CFI instructions for the current function into a
   21464              :    location list.  This is used for DW_AT_frame_base when we targeting
   21465              :    a dwarf2 consumer that does not support the dwarf3
   21466              :    DW_OP_call_frame_cfa.  OFFSET is a constant to be added to all CFA
   21467              :    expressions.  */
   21468              : 
   21469              : static dw_loc_list_ref
   21470         3511 : convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
   21471              : {
   21472         3511 :   int ix;
   21473         3511 :   dw_fde_ref fde;
   21474         3511 :   dw_loc_list_ref list, *list_tail;
   21475         3511 :   dw_cfi_ref cfi;
   21476         3511 :   dw_cfa_location last_cfa, next_cfa;
   21477         3511 :   const char *start_label, *last_label, *section;
   21478         3511 :   dw_cfa_location remember;
   21479              : 
   21480         3511 :   fde = cfun->fde;
   21481         3511 :   gcc_assert (fde != NULL);
   21482              : 
   21483         3511 :   section = secname_for_decl (current_function_decl);
   21484         3511 :   list_tail = &list;
   21485         3511 :   list = NULL;
   21486              : 
   21487         3511 :   memset (&next_cfa, 0, sizeof (next_cfa));
   21488              : 
   21489              : #ifdef CODEVIEW_DEBUGGING_INFO
   21490              :   /* We can write simplified frame base information for CodeView, as we're
   21491              :      not using it for rewinding.  */
   21492              :   if (codeview_debuginfo_p ())
   21493              :     {
   21494              :       int dwreg = DEBUGGER_REGNO (cfun->machine->fs.cfa_reg->u.reg.regno);
   21495              : 
   21496              :       next_cfa.reg.set_by_dwreg (dwreg);
   21497              :       next_cfa.offset = cfun->machine->fs.fp_valid
   21498              :         ? cfun->machine->fs.fp_offset : cfun->machine->fs.sp_offset;
   21499              : 
   21500              :       *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
   21501              :                                  fde->dw_fde_begin, 0,
   21502              :                                  fde->dw_fde_second_begin
   21503              :                                  ? fde->dw_fde_second_end : fde->dw_fde_end, 0,
   21504              :                                  section);
   21505              :       maybe_gen_llsym (list);
   21506              : 
   21507              :       return list;
   21508              :     }
   21509              : #endif
   21510              : 
   21511         3511 :   next_cfa.reg.set_by_dwreg (INVALID_REGNUM);
   21512         3511 :   remember = next_cfa;
   21513              : 
   21514         3511 :   start_label = fde->dw_fde_begin;
   21515              : 
   21516              :   /* ??? Bald assumption that the CIE opcode list does not contain
   21517              :      advance opcodes.  */
   21518        10533 :   FOR_EACH_VEC_ELT (*cie_cfi_vec, ix, cfi)
   21519         7022 :     lookup_cfa_1 (cfi, &next_cfa, &remember);
   21520              : 
   21521         3511 :   last_cfa = next_cfa;
   21522         3511 :   last_label = start_label;
   21523              : 
   21524         3511 :   if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
   21525              :     {
   21526              :       /* If the first partition contained no CFI adjustments, the
   21527              :          CIE opcodes apply to the whole first partition.  */
   21528            0 :       *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
   21529              :                                  fde->dw_fde_begin, 0, fde->dw_fde_end, 0, section);
   21530            0 :       list_tail =&(*list_tail)->dw_loc_next;
   21531            0 :       start_label = last_label = fde->dw_fde_second_begin;
   21532              :     }
   21533              : 
   21534        19559 :   FOR_EACH_VEC_SAFE_ELT (fde->dw_fde_cfi, ix, cfi)
   21535              :     {
   21536        16048 :       switch (cfi->dw_cfi_opc)
   21537              :         {
   21538         5704 :         case DW_CFA_set_loc:
   21539         5704 :         case DW_CFA_advance_loc1:
   21540         5704 :         case DW_CFA_advance_loc2:
   21541         5704 :         case DW_CFA_advance_loc4:
   21542         5704 :           if (!cfa_equal_p (&last_cfa, &next_cfa))
   21543              :             {
   21544         3830 :               *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
   21545              :                                          start_label, 0, last_label, 0, section);
   21546              : 
   21547         3830 :               list_tail = &(*list_tail)->dw_loc_next;
   21548         3830 :               last_cfa = next_cfa;
   21549         3830 :               start_label = last_label;
   21550              :             }
   21551         5704 :           last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
   21552         5704 :           break;
   21553              : 
   21554            0 :         case DW_CFA_advance_loc:
   21555              :           /* The encoding is complex enough that we should never emit this.  */
   21556            0 :           gcc_unreachable ();
   21557              : 
   21558        10344 :         default:
   21559        10344 :           lookup_cfa_1 (cfi, &next_cfa, &remember);
   21560        10344 :           break;
   21561              :         }
   21562        16048 :       if (ix + 1 == fde->dw_fde_switch_cfi_index)
   21563              :         {
   21564           57 :           if (!cfa_equal_p (&last_cfa, &next_cfa))
   21565              :             {
   21566           47 :               *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
   21567              :                                          start_label, 0, last_label, 0, section);
   21568              : 
   21569           47 :               list_tail = &(*list_tail)->dw_loc_next;
   21570           47 :               last_cfa = next_cfa;
   21571           47 :               start_label = last_label;
   21572              :             }
   21573           57 :           *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
   21574              :                                      start_label, 0, fde->dw_fde_end, 0, section);
   21575           57 :           list_tail = &(*list_tail)->dw_loc_next;
   21576           57 :           start_label = last_label = fde->dw_fde_second_begin;
   21577              :         }
   21578              :     }
   21579              : 
   21580         3511 :   if (!cfa_equal_p (&last_cfa, &next_cfa))
   21581              :     {
   21582         1790 :       *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
   21583              :                                  start_label, 0, last_label, 0, section);
   21584         1790 :       list_tail = &(*list_tail)->dw_loc_next;
   21585         1790 :       start_label = last_label;
   21586              :     }
   21587              : 
   21588         3511 :   *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
   21589              :                              start_label, 0,
   21590         3511 :                              fde->dw_fde_second_begin
   21591              :                              ? fde->dw_fde_second_end : fde->dw_fde_end, 0,
   21592              :                              section);
   21593              : 
   21594         3511 :   maybe_gen_llsym (list);
   21595              : 
   21596         3511 :   return list;
   21597              : }
   21598              : 
   21599              : /* Compute a displacement from the "steady-state frame pointer" to the
   21600              :    frame base (often the same as the CFA), and store it in
   21601              :    frame_pointer_fb_offset.  OFFSET is added to the displacement
   21602              :    before the latter is negated.  */
   21603              : 
   21604              : static void
   21605       575999 : compute_frame_pointer_to_fb_displacement (poly_int64 offset)
   21606              : {
   21607       575999 :   rtx reg, elim;
   21608              : 
   21609              : #ifdef FRAME_POINTER_CFA_OFFSET
   21610              :   reg = frame_pointer_rtx;
   21611              :   offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
   21612              : #else
   21613       575999 :   reg = arg_pointer_rtx;
   21614       575999 :   offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
   21615              : #endif
   21616              : 
   21617       575999 :   elim = (ira_use_lra_p
   21618       575999 :           ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
   21619            0 :           : eliminate_regs (reg, VOIDmode, NULL_RTX));
   21620       575999 :   elim = strip_offset_and_add (elim, &offset);
   21621              : 
   21622       575999 :   frame_pointer_fb_offset = -offset;
   21623              : 
   21624              :   /* ??? AVR doesn't set up valid eliminations when there is no stack frame
   21625              :      in which to eliminate.  This is because it's stack pointer isn't
   21626              :      directly accessible as a register within the ISA.  To work around
   21627              :      this, assume that while we cannot provide a proper value for
   21628              :      frame_pointer_fb_offset, we won't need one either.  We can use
   21629              :      hard frame pointer in debug info even if frame pointer isn't used
   21630              :      since hard frame pointer in debug info is encoded with DW_OP_fbreg
   21631              :      which uses the DW_AT_frame_base attribute, not hard frame pointer
   21632              :      directly.  */
   21633       575999 :   frame_pointer_fb_offset_valid
   21634       575999 :     = (elim == hard_frame_pointer_rtx || elim == stack_pointer_rtx);
   21635       575999 : }
   21636              : 
   21637              : /* Generate a DW_AT_name attribute given some string value to be included as
   21638              :    the value of the attribute.  */
   21639              : 
   21640              : void
   21641    272840116 : add_name_attribute (dw_die_ref die, const char *name_string)
   21642              : {
   21643    272840116 :   if (name_string != NULL && *name_string != 0)
   21644              :     {
   21645    269314825 :       if (demangle_name_func)
   21646            0 :         name_string = (*demangle_name_func) (name_string);
   21647              : 
   21648    269314825 :       add_AT_string (die, DW_AT_name, name_string);
   21649              :     }
   21650    272840116 : }
   21651              : 
   21652              : /* Generate a DW_AT_name attribute given some string value representing a
   21653              :    file or filepath to be included as value of the attribute.  */
   21654              : static void
   21655        54358 : add_filename_attribute (dw_die_ref die, const char *name_string)
   21656              : {
   21657        54358 :   if (name_string != NULL && *name_string != 0)
   21658        54358 :     add_filepath_AT_string (die, DW_AT_name, name_string);
   21659        54358 : }
   21660              : 
   21661              : /* Generate a DW_AT_description attribute given some string value to be included
   21662              :    as the value of the attribute.  */
   21663              : 
   21664              : static void
   21665            0 : add_desc_attribute (dw_die_ref die, const char *name_string)
   21666              : {
   21667            0 :   if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
   21668              :     return;
   21669              : 
   21670            0 :   if (name_string == NULL || *name_string == 0)
   21671              :     return;
   21672              : 
   21673            0 :   if (demangle_name_func)
   21674            0 :     name_string = (*demangle_name_func) (name_string);
   21675              : 
   21676            0 :   add_AT_string (die, DW_AT_description, name_string);
   21677              : }
   21678              : 
   21679              : /* Generate a DW_AT_description attribute given some decl to be included
   21680              :    as the value of the attribute.  */
   21681              : 
   21682              : static void
   21683      3685563 : add_desc_attribute (dw_die_ref die, tree decl)
   21684              : {
   21685      3685563 :   tree decl_name;
   21686              : 
   21687      3685563 :   if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
   21688              :     return;
   21689              : 
   21690            0 :   if (decl == NULL_TREE || !DECL_P (decl))
   21691              :     return;
   21692            0 :   decl_name = DECL_NAME (decl);
   21693              : 
   21694            0 :   if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
   21695              :     {
   21696            0 :       const char *name = dwarf2_name (decl, 0);
   21697            0 :       add_desc_attribute (die, name ? name : IDENTIFIER_POINTER (decl_name));
   21698              :     }
   21699              :   else
   21700              :     {
   21701            0 :       char *desc = print_generic_expr_to_str (decl);
   21702            0 :       add_desc_attribute (die, desc);
   21703            0 :       free (desc);
   21704              :     }
   21705              : }
   21706              : 
   21707              : /* Retrieve the descriptive type of TYPE, if any, make sure it has a
   21708              :    DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
   21709              :    of TYPE accordingly.
   21710              : 
   21711              :    ??? This is a temporary measure until after we're able to generate
   21712              :    regular DWARF for the complex Ada type system.  */
   21713              : 
   21714              : static void
   21715     94702049 : add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
   21716              :                                      dw_die_ref context_die)
   21717              : {
   21718     94702049 :   tree dtype;
   21719     94702049 :   dw_die_ref dtype_die;
   21720              : 
   21721     94702049 :   if (!lang_hooks.types.descriptive_type)
   21722              :     return;
   21723              : 
   21724            0 :   dtype = lang_hooks.types.descriptive_type (type);
   21725            0 :   if (!dtype)
   21726              :     return;
   21727              : 
   21728            0 :   dtype_die = lookup_type_die (dtype);
   21729            0 :   if (!dtype_die)
   21730              :     {
   21731            0 :       gen_type_die (dtype, context_die);
   21732            0 :       dtype_die = lookup_type_die (dtype);
   21733            0 :       gcc_assert (dtype_die);
   21734              :     }
   21735              : 
   21736            0 :   add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
   21737              : }
   21738              : 
   21739              : /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir.  */
   21740              : 
   21741              : static const char *
   21742       107731 : comp_dir_string (void)
   21743              : {
   21744       107731 :   const char *wd;
   21745       107731 :   char *wd_plus_sep = NULL;
   21746       107731 :   static const char *cached_wd = NULL;
   21747              : 
   21748       107731 :   if (cached_wd != NULL)
   21749              :     return cached_wd;
   21750              : 
   21751        53630 :   wd = get_src_pwd ();
   21752        53630 :   if (wd == NULL)
   21753              :     return NULL;
   21754              : 
   21755        53630 :   if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
   21756              :     {
   21757              :       size_t wdlen = strlen (wd);
   21758              :       wd_plus_sep = XNEWVEC (char, wdlen + 2);
   21759              :       strcpy (wd_plus_sep, wd);
   21760              :       wd_plus_sep [wdlen] = DIR_SEPARATOR;
   21761              :       wd_plus_sep [wdlen + 1] = 0;
   21762              :       wd = wd_plus_sep;
   21763              :     }
   21764              : 
   21765        53630 :   cached_wd = remap_debug_filename (wd);
   21766              : 
   21767              :   /* remap_debug_filename can just pass through wd or return a new gc string.
   21768              :      These two types can't be both stored in a GTY(())-tagged string, but since
   21769              :      the cached value lives forever just copy it if needed.  */
   21770        53630 :   if (cached_wd != wd)
   21771              :     {
   21772          184 :       cached_wd = xstrdup (cached_wd);
   21773          184 :       if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR && wd_plus_sep != NULL)
   21774              :         free (wd_plus_sep);
   21775              :     }
   21776              : 
   21777        53630 :   return cached_wd;
   21778              : }
   21779              : 
   21780              : /* Generate a DW_AT_comp_dir attribute for DIE.  */
   21781              : 
   21782              : static void
   21783        54358 : add_comp_dir_attribute (dw_die_ref die)
   21784              : {
   21785        54358 :   const char * wd = comp_dir_string ();
   21786        54358 :   if (wd != NULL)
   21787        54358 :     add_filepath_AT_string (die, DW_AT_comp_dir, wd);
   21788        54358 : }
   21789              : 
   21790              : /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
   21791              :    pointer computation, ...), output a representation for that bound according
   21792              :    to the accepted FORMS (see enum dw_scalar_form) and add it to DIE.  See
   21793              :    loc_list_from_tree for the meaning of CONTEXT.  */
   21794              : 
   21795              : static void
   21796      1017600 : add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
   21797              :                  int forms, struct loc_descr_context *context)
   21798              : {
   21799      1017600 :   dw_die_ref context_die, decl_die = NULL;
   21800      1017600 :   dw_loc_list_ref list;
   21801      1017600 :   bool strip_conversions = true;
   21802      1017600 :   bool placeholder_seen = false;
   21803              : 
   21804      1017600 :   while (strip_conversions)
   21805      1017600 :     switch (TREE_CODE (value))
   21806              :       {
   21807              :       case ERROR_MARK:
   21808              :       case SAVE_EXPR:
   21809              :         return;
   21810              : 
   21811            0 :       CASE_CONVERT:
   21812            0 :       case VIEW_CONVERT_EXPR:
   21813            0 :         value = TREE_OPERAND (value, 0);
   21814            0 :         break;
   21815              : 
   21816              :       default:
   21817              :         strip_conversions = false;
   21818              :         break;
   21819              :       }
   21820              : 
   21821              :   /* If possible and permitted, output the attribute as a constant.  */
   21822      1017600 :   if ((forms & dw_scalar_form_constant) != 0
   21823      1010319 :       && TREE_CODE (value) == INTEGER_CST)
   21824              :     {
   21825       973815 :       unsigned int prec = simple_type_size_in_bits (TREE_TYPE (value));
   21826              : 
   21827              :       /* If HOST_WIDE_INT is big enough then represent the bound as
   21828              :          a constant value.  We need to choose a form based on
   21829              :          whether the type is signed or unsigned.  We cannot just
   21830              :          call add_AT_unsigned if the value itself is positive
   21831              :          (add_AT_unsigned might add the unsigned value encoded as
   21832              :          DW_FORM_data[1248]).  Some DWARF consumers will lookup the
   21833              :          bounds type and then sign extend any unsigned values found
   21834              :          for signed types.  This is needed only for
   21835              :          DW_AT_{lower,upper}_bound, since for most other attributes,
   21836              :          consumers will treat DW_FORM_data[1248] as unsigned values,
   21837              :          regardless of the underlying type.  */
   21838       973815 :       if (prec <= HOST_BITS_PER_WIDE_INT
   21839            0 :           || tree_fits_uhwi_p (value))
   21840              :         {
   21841       973815 :           if (TYPE_UNSIGNED (TREE_TYPE (value)))
   21842       956793 :             add_AT_unsigned (die, attr, TREE_INT_CST_LOW (value));
   21843              :           else
   21844        17022 :             add_AT_int (die, attr, TREE_INT_CST_LOW (value));
   21845              :         }
   21846            0 :       else if (dwarf_version >= 5
   21847            0 :                && TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (value))) == 128)
   21848              :         /* Otherwise represent the bound as an unsigned value with
   21849              :            the precision of its type.  The precision and signedness
   21850              :            of the type will be necessary to re-interpret it
   21851              :            unambiguously.  */
   21852            0 :         add_AT_wide (die, attr, wi::to_wide (value));
   21853              :       else
   21854              :         {
   21855            0 :           rtx v = immed_wide_int_const (wi::to_wide (value),
   21856            0 :                                         TYPE_MODE (TREE_TYPE (value)));
   21857            0 :           dw_loc_descr_ref loc
   21858            0 :             = loc_descriptor (v, TYPE_MODE (TREE_TYPE (value)),
   21859              :                               VAR_INIT_STATUS_INITIALIZED);
   21860            0 :           if (loc)
   21861            0 :             add_AT_loc (die, attr, loc);
   21862              :         }
   21863              :       return;
   21864              :     }
   21865              : 
   21866              :   /* Otherwise, if it's possible and permitted too, output a reference to
   21867              :      another DIE.  */
   21868        43785 :   if ((forms & dw_scalar_form_reference) != 0)
   21869              :     {
   21870        35374 :       tree decl = NULL_TREE;
   21871              : 
   21872              :       /* Some type attributes reference an outer type.  For instance, the upper
   21873              :          bound of an array may reference an embedding record (this happens in
   21874              :          Ada).  */
   21875        35374 :       if (TREE_CODE (value) == COMPONENT_REF
   21876            0 :           && TREE_CODE (TREE_OPERAND (value, 0)) == PLACEHOLDER_EXPR
   21877        35374 :           && TREE_CODE (TREE_OPERAND (value, 1)) == FIELD_DECL)
   21878            0 :         decl = TREE_OPERAND (value, 1);
   21879              : 
   21880        35374 :       else if (VAR_P (value)
   21881              :                || TREE_CODE (value) == PARM_DECL
   21882              :                || TREE_CODE (value) == RESULT_DECL)
   21883              :         decl = value;
   21884              : 
   21885            0 :       if (decl != NULL_TREE)
   21886              :         {
   21887         5116 :           decl_die = lookup_decl_die (decl);
   21888              : 
   21889              :           /* ??? Can this happen, or should the variable have been bound
   21890              :              first?  Probably it can, since I imagine that we try to create
   21891              :              the types of parameters in the order in which they exist in
   21892              :              the list, and won't have created a forward reference to a
   21893              :              later parameter.  */
   21894         5116 :           if (decl_die != NULL)
   21895              :             {
   21896         3414 :               if (get_AT (decl_die, DW_AT_location)
   21897         3388 :                   || get_AT (decl_die, DW_AT_data_member_location)
   21898         3388 :                   || get_AT (decl_die, DW_AT_data_bit_offset)
   21899         6802 :                   || get_AT (decl_die, DW_AT_const_value))
   21900              :                 {
   21901           41 :                   add_AT_die_ref (die, attr, decl_die);
   21902           41 :                   return;
   21903              :                 }
   21904              :             }
   21905              :         }
   21906              :     }
   21907              : 
   21908              :   /* Last chance: try to create a stack operation procedure to evaluate the
   21909              :      value.  Do nothing if even that is not possible or permitted.  */
   21910        43744 :   if ((forms & dw_scalar_form_exprloc) == 0)
   21911              :     return;
   21912              : 
   21913        43744 :   list = loc_list_from_tree (value, 2, context);
   21914        43744 :   if (context && context->placeholder_arg)
   21915              :     {
   21916         3390 :       placeholder_seen = context->placeholder_seen;
   21917         3390 :       context->placeholder_seen = false;
   21918              :     }
   21919        43744 :   if (list == NULL || single_element_loc_list_p (list))
   21920              :     {
   21921              :       /* If this attribute is not a reference nor constant, it is
   21922              :          a DWARF expression rather than location description.  For that
   21923              :          loc_list_from_tree (value, 0, &context) is needed.  */
   21924        43201 :       dw_loc_list_ref list2 = loc_list_from_tree (value, 0, context);
   21925        43201 :       if (list2 && single_element_loc_list_p (list2))
   21926              :         {
   21927        42939 :           if (placeholder_seen)
   21928              :             {
   21929         3390 :               struct dwarf_procedure_info dpi;
   21930         3390 :               dpi.fndecl = NULL_TREE;
   21931         3390 :               dpi.args_count = 1;
   21932         3390 :               if (!resolve_args_picking (list2->expr, 1, &dpi))
   21933            0 :                 return;
   21934              :             }
   21935        42939 :           add_AT_loc (die, attr, list2->expr);
   21936        42939 :           return;
   21937              :         }
   21938              :     }
   21939              : 
   21940              :   /* If that failed to give a single element location list, fall back to
   21941              :      outputting this as a reference... still if permitted.  */
   21942          805 :   if (list == NULL
   21943          543 :       || (forms & dw_scalar_form_reference) == 0
   21944          543 :       || placeholder_seen)
   21945              :     return;
   21946              : 
   21947          543 :   if (!decl_die)
   21948              :     {
   21949          168 :       if (current_function_decl == 0)
   21950            0 :         context_die = comp_unit_die ();
   21951              :       else
   21952          168 :         context_die = lookup_decl_die (current_function_decl);
   21953              : 
   21954          168 :       decl_die = new_die (DW_TAG_variable, context_die, value);
   21955          168 :       add_AT_flag (decl_die, DW_AT_artificial, 1);
   21956          168 :       add_type_attribute (decl_die, TREE_TYPE (value), TYPE_QUAL_CONST, false,
   21957              :                           context_die);
   21958              :     }
   21959              : 
   21960          543 :   add_AT_location_description (decl_die, DW_AT_location, list);
   21961          543 :   add_AT_die_ref (die, attr, decl_die);
   21962              : }
   21963              : 
   21964              : /* Return the default for DW_AT_lower_bound, or -1 if there is not any
   21965              :    default.  */
   21966              : 
   21967              : static int
   21968      1002681 : lower_bound_default (void)
   21969              : {
   21970      1002681 :   switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
   21971              :     {
   21972              :     case DW_LANG_C:
   21973              :     case DW_LANG_C89:
   21974              :     case DW_LANG_C99:
   21975              :     case DW_LANG_C11:
   21976              :     case DW_LANG_C_plus_plus:
   21977              :     case DW_LANG_C_plus_plus_11:
   21978              :     case DW_LANG_C_plus_plus_14:
   21979              :     case DW_LANG_ObjC:
   21980              :     case DW_LANG_ObjC_plus_plus:
   21981              :       return 0;
   21982              :     case DW_LANG_Fortran77:
   21983              :     case DW_LANG_Fortran90:
   21984              :     case DW_LANG_Fortran95:
   21985              :     case DW_LANG_Fortran03:
   21986              :     case DW_LANG_Fortran08:
   21987              :       return 1;
   21988            0 :     case DW_LANG_UPC:
   21989            0 :     case DW_LANG_D:
   21990            0 :     case DW_LANG_Python:
   21991            0 :       return dwarf_version >= 4 ? 0 : -1;
   21992         2206 :     case DW_LANG_Ada95:
   21993         2206 :     case DW_LANG_Ada83:
   21994         2206 :     case DW_LANG_Cobol74:
   21995         2206 :     case DW_LANG_Cobol85:
   21996         2206 :     case DW_LANG_Modula2:
   21997         2206 :     case DW_LANG_PLI:
   21998         2206 :       return dwarf_version >= 4 ? 1 : -1;
   21999              :     default:
   22000              :       return -1;
   22001              :     }
   22002              : }
   22003              : 
   22004              : /* Given a tree node describing an array bound (either lower or upper) output
   22005              :    a representation for that bound.  */
   22006              : 
   22007              : static void
   22008      1961162 : add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr,
   22009              :                 tree bound, struct loc_descr_context *context)
   22010              : {
   22011      1961202 :   int dflt;
   22012              : 
   22013      1961242 :   while (1)
   22014      1961202 :     switch (TREE_CODE (bound))
   22015              :       {
   22016              :       /* Strip all conversions.  */
   22017           40 :       CASE_CONVERT:
   22018           40 :       case VIEW_CONVERT_EXPR:
   22019           40 :         bound = TREE_OPERAND (bound, 0);
   22020           40 :         break;
   22021              : 
   22022              :       /* All fixed-bounds are represented by INTEGER_CST nodes.  Lower bounds
   22023              :          are even omitted when they are the default.  */
   22024      1939469 :       case INTEGER_CST:
   22025              :         /* If the value for this bound is the default one, we can even omit the
   22026              :            attribute.  */
   22027      1939469 :         if (bound_attr == DW_AT_lower_bound
   22028       981586 :             && tree_fits_shwi_p (bound)
   22029       981586 :             && (dflt = lower_bound_default ()) != -1
   22030      2911311 :             && tree_to_shwi (bound) == dflt)
   22031              :           return;
   22032              : 
   22033              :         /* FALLTHRU */
   22034              : 
   22035       995508 :       default:
   22036              :         /* Let GNAT encodings do the magic for self-referential bounds.  */
   22037       995508 :         if (is_ada ()
   22038            0 :             && gnat_encodings == DWARF_GNAT_ENCODINGS_ALL
   22039       995508 :             && contains_placeholder_p (bound))
   22040              :           return;
   22041              : 
   22042       995508 :         add_scalar_info (subrange_die, bound_attr, bound,
   22043              :                          dw_scalar_form_constant
   22044              :                          | dw_scalar_form_exprloc
   22045              :                          | dw_scalar_form_reference,
   22046              :                          context);
   22047       995508 :         return;
   22048              :       }
   22049              : }
   22050              : 
   22051              : /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
   22052              :    possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
   22053              : 
   22054              :    This function reuses previously set type and bound information if
   22055              :    available.  */
   22056              : 
   22057              : static void
   22058      1009025 : add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
   22059              : {
   22060      1009025 :   dw_die_ref child = type_die->die_child;
   22061      1009025 :   struct array_descr_info info;
   22062      1009025 :   int dimension_number;
   22063              : 
   22064      1009025 :   if (lang_hooks.types.get_array_descr_info)
   22065              :     {
   22066        20354 :       memset (&info, 0, sizeof (info));
   22067        20354 :       if (lang_hooks.types.get_array_descr_info (type, &info))
   22068              :         /* Fortran sometimes emits array types with no dimension.  */
   22069            0 :         gcc_assert (info.ndimensions >= 0
   22070              :                     && info.ndimensions
   22071              :                        <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN);
   22072              :     }
   22073              :   else
   22074       988671 :     info.ndimensions = 0;
   22075              : 
   22076      1009025 :   for (dimension_number = 0;
   22077      2024465 :        TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
   22078      1015440 :        type = TREE_TYPE (type), dimension_number++)
   22079              :     {
   22080      1017221 :       tree domain = TYPE_DOMAIN (type);
   22081              : 
   22082      1017221 :       if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
   22083              :         break;
   22084              : 
   22085              :       /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
   22086              :          and (in GNU C only) variable bounds.  Handle all three forms
   22087              :          here.  */
   22088              : 
   22089              :       /* Find and reuse a previously generated DW_TAG_subrange_type if
   22090              :          available.
   22091              : 
   22092              :          For multi-dimensional arrays, as we iterate through the
   22093              :          various dimensions in the enclosing for loop above, we also
   22094              :          iterate through the DIE children and pick at each
   22095              :          DW_TAG_subrange_type previously generated (if available).
   22096              :          Each child DW_TAG_subrange_type DIE describes the range of
   22097              :          the current dimension.  At this point we should have as many
   22098              :          DW_TAG_subrange_type's as we have dimensions in the
   22099              :          array.  */
   22100      1015440 :       dw_die_ref subrange_die = NULL;
   22101      1015440 :       if (child)
   22102        12363 :         while (1)
   22103              :           {
   22104        12363 :             child = child->die_sib;
   22105        12363 :             if (child->die_tag == DW_TAG_subrange_type)
   22106        12363 :               subrange_die = child;
   22107        12363 :             if (child == type_die->die_child)
   22108              :               {
   22109              :                 /* If we wrapped around, stop looking next time.  */
   22110              :                 child = NULL;
   22111              :                 break;
   22112              :               }
   22113         2210 :             if (child->die_tag == DW_TAG_subrange_type)
   22114              :               break;
   22115              :           }
   22116        12363 :       if (!subrange_die)
   22117      1003077 :         subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
   22118              : 
   22119      1015440 :       if (domain)
   22120              :         {
   22121              :           /* We have an array type with specified bounds.  */
   22122       959594 :           tree lower = TYPE_MIN_VALUE (domain);
   22123       959594 :           tree upper = TYPE_MAX_VALUE (domain);
   22124       959594 :           tree index_type = TREE_TYPE (domain);
   22125              : 
   22126       959594 :           if (dimension_number <= info.ndimensions - 1)
   22127              :             {
   22128            0 :               lower = info.dimen[dimension_number].lower_bound;
   22129            0 :               upper = info.dimen[dimension_number].upper_bound;
   22130            0 :               index_type = info.dimen[dimension_number].bounds_type;
   22131              :             }
   22132              : 
   22133              :           /* Define the index type.  */
   22134       959594 :           if (index_type && !get_AT (subrange_die, DW_AT_type))
   22135       947232 :             add_type_attribute (subrange_die, index_type, TYPE_UNQUALIFIED,
   22136              :                                 false, type_die);
   22137              : 
   22138              :           /* ??? If upper is NULL, the array has unspecified length,
   22139              :              but it does have a lower bound.  This happens with Fortran
   22140              :                dimension arr(N:*)
   22141              :              Since the debugger is definitely going to need to know N
   22142              :              to produce useful results, go ahead and output the lower
   22143              :              bound solo, and hope the debugger can cope.  */
   22144              : 
   22145       959594 :           if (lower && !get_AT (subrange_die, DW_AT_lower_bound))
   22146       957893 :             add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
   22147              : 
   22148       959594 :           if (!get_AT (subrange_die, DW_AT_upper_bound)
   22149       959594 :               && !get_AT (subrange_die, DW_AT_count))
   22150              :             {
   22151       947397 :               if (upper)
   22152       940711 :                 add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
   22153         6686 :               else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type))
   22154              :                 /* Zero-length array.  */
   22155         1072 :                 add_bound_info (subrange_die, DW_AT_count,
   22156         1072 :                                 build_int_cst (TREE_TYPE (lower), 0), NULL);
   22157              :             }
   22158              :         }
   22159              : 
   22160              :       /* Otherwise we have an array type with an unspecified length.  The
   22161              :          DWARF-2 spec does not say how to handle this; let's just leave out the
   22162              :          bounds.  */
   22163              :     }
   22164      1009025 : }
   22165              : 
   22166              : /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size.  */
   22167              : 
   22168              : static void
   22169     49960499 : add_byte_size_attribute (dw_die_ref die, tree tree_node)
   22170              : {
   22171     49960499 :   dw_die_ref decl_die;
   22172     49960499 :   HOST_WIDE_INT size;
   22173              : 
   22174     49960499 :   switch (TREE_CODE (tree_node))
   22175              :     {
   22176              :     case ERROR_MARK:
   22177              :       size = 0;
   22178              :       break;
   22179     49446778 :     case ENUMERAL_TYPE:
   22180     49446778 :     case RECORD_TYPE:
   22181     49446778 :     case UNION_TYPE:
   22182     49446778 :     case QUAL_UNION_TYPE:
   22183     49446778 :       if (TREE_CODE (TYPE_SIZE_UNIT (tree_node)) == VAR_DECL
   22184     49446778 :           && (decl_die = lookup_decl_die (TYPE_SIZE_UNIT (tree_node))))
   22185              :         {
   22186            0 :           add_AT_die_ref (die, DW_AT_byte_size, decl_die);
   22187            0 :           return;
   22188              :         }
   22189     49446778 :       size = int_size_in_bytes (tree_node);
   22190     49446778 :       break;
   22191       513721 :     case FIELD_DECL:
   22192              :       /* For a data member of a struct or union, the DW_AT_byte_size is
   22193              :          generally given as the number of bytes normally allocated for an
   22194              :          object of the *declared* type of the member itself.  This is true
   22195              :          even for bit-fields.  */
   22196       513721 :       size = int_size_in_bytes (field_type (tree_node));
   22197       513721 :       break;
   22198            0 :     default:
   22199            0 :       gcc_unreachable ();
   22200              :     }
   22201              : 
   22202              :   /* Note that `size' might be -1 when we get to this point.  If it is, that
   22203              :      indicates that the byte size of the entity in question is variable.  */
   22204     49960499 :   if (size >= 0)
   22205     49960408 :     add_AT_unsigned (die, DW_AT_byte_size, size);
   22206              : 
   22207              :   /* Support for dynamically-sized objects was introduced in DWARF3.  */
   22208           91 :   else if (TYPE_P (tree_node)
   22209           91 :            && (dwarf_version >= 3 || !dwarf_strict)
   22210           91 :            && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL)
   22211              :     {
   22212           91 :       struct loc_descr_context ctx = {
   22213              :         const_cast<tree> (tree_node),     /* context_type */
   22214              :         NULL_TREE,                      /* base_decl */
   22215              :         NULL,                   /* dpi */
   22216              :         false,                  /* placeholder_arg */
   22217              :         false,                  /* placeholder_seen */
   22218              :         false                   /* strict_signedness */
   22219           91 :       };
   22220              : 
   22221           91 :       tree tree_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (tree_node));
   22222           91 :       add_scalar_info (die, DW_AT_byte_size, tree_size,
   22223              :                        dw_scalar_form_constant
   22224              :                        | dw_scalar_form_exprloc
   22225              :                        | dw_scalar_form_reference,
   22226              :                        &ctx);
   22227              :     }
   22228              : }
   22229              : 
   22230              : /* Add a DW_AT_alignment attribute to DIE with TREE_NODE's non-default
   22231              :    alignment.  */
   22232              : 
   22233              : static void
   22234    276419403 : add_alignment_attribute (dw_die_ref die, tree tree_node)
   22235              : {
   22236    276419403 :   if (dwarf_version < 5 && dwarf_strict)
   22237              :     return;
   22238              : 
   22239    276419344 :   unsigned align;
   22240              : 
   22241    276419344 :   if (DECL_P (tree_node))
   22242              :     {
   22243    143857144 :       if (!DECL_USER_ALIGN (tree_node))
   22244              :         return;
   22245              : 
   22246       434347 :       align = DECL_ALIGN_UNIT (tree_node);
   22247              :     }
   22248    132562200 :   else if (TYPE_P (tree_node))
   22249              :     {
   22250    132562200 :       if (!TYPE_USER_ALIGN (tree_node))
   22251              :         return;
   22252              : 
   22253      1082655 :       align = TYPE_ALIGN_UNIT (tree_node);
   22254              :     }
   22255              :   else
   22256            0 :     gcc_unreachable ();
   22257              : 
   22258      1517002 :   add_AT_unsigned (die, DW_AT_alignment, align);
   22259              : }
   22260              : 
   22261              : /* For a FIELD_DECL node which represents a bit-field, output an attribute
   22262              :    which specifies the distance in bits from the highest order bit of the
   22263              :    "containing object" for the bit-field to the highest order bit of the
   22264              :    bit-field itself.
   22265              : 
   22266              :    For any given bit-field, the "containing object" is a hypothetical object
   22267              :    (of some integral or enum type) within which the given bit-field lives.  The
   22268              :    type of this hypothetical "containing object" is always the same as the
   22269              :    declared type of the individual bit-field itself.  The determination of the
   22270              :    exact location of the "containing object" for a bit-field is rather
   22271              :    complicated.  It's handled by the `field_byte_offset' function (above).
   22272              : 
   22273              :    Note that it is the size (in bytes) of the hypothetical "containing object"
   22274              :    which will be given in the DW_AT_byte_size attribute for this bit-field.
   22275              :    (See `byte_size_attribute' above).  */
   22276              : 
   22277              : static inline void
   22278       513721 : add_bit_offset_attribute (dw_die_ref die, tree decl)
   22279              : {
   22280       513721 :   HOST_WIDE_INT object_offset_in_bytes;
   22281       513721 :   tree original_type = DECL_BIT_FIELD_TYPE (decl);
   22282       513721 :   HOST_WIDE_INT bitpos_int;
   22283       513721 :   HOST_WIDE_INT highest_order_object_bit_offset;
   22284       513721 :   HOST_WIDE_INT highest_order_field_bit_offset;
   22285       513721 :   HOST_WIDE_INT bit_offset;
   22286              : 
   22287              :   /* The containing object is within the DECL_CONTEXT.  */
   22288       513721 :   struct vlr_context ctx = { DECL_CONTEXT (decl), NULL_TREE };
   22289              : 
   22290       513721 :   field_byte_offset (decl, &ctx, &object_offset_in_bytes);
   22291              : 
   22292              :   /* Must be a field and a bit field.  */
   22293       513721 :   gcc_assert (original_type && TREE_CODE (decl) == FIELD_DECL);
   22294              : 
   22295              :   /* We can't yet handle bit-fields whose offsets are variable, so if we
   22296              :      encounter such things, just return without generating any attribute
   22297              :      whatsoever.  Likewise for variable or too large size.  */
   22298       513721 :   if (! tree_fits_shwi_p (bit_position (decl))
   22299       513721 :       || ! tree_fits_uhwi_p (DECL_SIZE (decl)))
   22300           16 :     return;
   22301              : 
   22302       513705 :   bitpos_int = int_bit_position (decl);
   22303              : 
   22304              :   /* Note that the bit offset is always the distance (in bits) from the
   22305              :      highest-order bit of the "containing object" to the highest-order bit of
   22306              :      the bit-field itself.  Since the "high-order end" of any object or field
   22307              :      is different on big-endian and little-endian machines, the computation
   22308              :      below must take account of these differences.  */
   22309       513705 :   highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
   22310       513705 :   highest_order_field_bit_offset = bitpos_int;
   22311              : 
   22312       513705 :   if (! BYTES_BIG_ENDIAN)
   22313              :     {
   22314       513705 :       highest_order_field_bit_offset += tree_to_shwi (DECL_SIZE (decl));
   22315      1027410 :       highest_order_object_bit_offset +=
   22316       513705 :         simple_type_size_in_bits (original_type);
   22317              :     }
   22318              : 
   22319       513705 :   bit_offset
   22320       513705 :     = (! BYTES_BIG_ENDIAN
   22321              :        ? highest_order_object_bit_offset - highest_order_field_bit_offset
   22322              :        : highest_order_field_bit_offset - highest_order_object_bit_offset);
   22323              : 
   22324       513705 :   if (bit_offset < 0)
   22325           33 :     add_AT_int (die, DW_AT_bit_offset, bit_offset);
   22326              :   else
   22327       513672 :     add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
   22328              : }
   22329              : 
   22330              : /* For a FIELD_DECL node which represents a bit field, output an attribute
   22331              :    which specifies the length in bits of the given field.  */
   22332              : 
   22333              : static inline void
   22334       513721 : add_bit_size_attribute (dw_die_ref die, tree decl)
   22335              : {
   22336              :   /* Must be a field and a bit field.  */
   22337       513721 :   gcc_assert (TREE_CODE (decl) == FIELD_DECL
   22338              :               && DECL_BIT_FIELD_TYPE (decl));
   22339              : 
   22340       513721 :   if (tree_fits_uhwi_p (DECL_SIZE (decl)))
   22341       513721 :     add_AT_unsigned (die, DW_AT_bit_size, tree_to_uhwi (DECL_SIZE (decl)));
   22342       513721 : }
   22343              : 
   22344              : /* If the compiled language is ANSI C, then add a 'prototyped'
   22345              :    attribute, if arg types are given for the parameters of a function.  */
   22346              : 
   22347              : static inline void
   22348     97379628 : add_prototyped_attribute (dw_die_ref die, tree func_type)
   22349              : {
   22350     97379628 :   switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
   22351              :     {
   22352       275561 :     case DW_LANG_C:
   22353       275561 :     case DW_LANG_C89:
   22354       275561 :     case DW_LANG_C99:
   22355       275561 :     case DW_LANG_C11:
   22356       275561 :     case DW_LANG_ObjC:
   22357       275561 :       if (prototype_p (func_type))
   22358       272169 :         add_AT_flag (die, DW_AT_prototyped, 1);
   22359              :       break;
   22360              :     default:
   22361              :       break;
   22362              :     }
   22363     97379628 : }
   22364              : 
   22365              : /* Add an 'abstract_origin' attribute below a given DIE.  The DIE is found
   22366              :    by looking in the type declaration, the object declaration equate table or
   22367              :    the block mapping.  */
   22368              : 
   22369              : static inline void
   22370     23564237 : add_abstract_origin_attribute (dw_die_ref die, tree origin)
   22371              : {
   22372     23564237 :   dw_die_ref origin_die = NULL;
   22373              : 
   22374              :   /* For late LTO debug output we want to refer directly to the abstract
   22375              :      DIE in the early debug rather to the possibly existing concrete
   22376              :      instance and avoid creating that just for this purpose.  */
   22377     23564237 :   sym_off_pair *desc;
   22378     23564237 :   if (in_lto_p
   22379         9418 :       && external_die_map
   22380     23573654 :       && (desc = external_die_map->get (origin)))
   22381              :     {
   22382         9139 :       add_AT_external_die_ref (die, DW_AT_abstract_origin,
   22383         9139 :                                desc->sym, desc->off);
   22384         9139 :       return;
   22385              :     }
   22386              : 
   22387     23555098 :   if (DECL_P (origin))
   22388     23165053 :     origin_die = lookup_decl_die (origin);
   22389       390045 :   else if (TYPE_P (origin))
   22390            0 :     origin_die = lookup_type_die (origin);
   22391       390045 :   else if (TREE_CODE (origin) == BLOCK)
   22392       390045 :     origin_die = lookup_block_die (origin);
   22393              : 
   22394              :   /* XXX: Functions that are never lowered don't always have correct block
   22395              :      trees (in the case of java, they simply have no block tree, in some other
   22396              :      languages).  For these functions, there is nothing we can really do to
   22397              :      output correct debug info for inlined functions in all cases.  Rather
   22398              :      than die, we'll just produce deficient debug info now, in that we will
   22399              :      have variables without a proper abstract origin.  In the future, when all
   22400              :      functions are lowered, we should re-add a gcc_assert (origin_die)
   22401              :      here.  */
   22402              : 
   22403     23555098 :   if (origin_die)
   22404              :     {
   22405     23545487 :       dw_attr_node *a;
   22406              :       /* Like above, if we already created a concrete instance DIE
   22407              :          do not use that for the abstract origin but the early DIE
   22408              :          if present.  */
   22409     23545487 :       if (in_lto_p
   22410     23545487 :           && (a = get_AT (origin_die, DW_AT_abstract_origin)))
   22411          268 :         origin_die = AT_ref (a);
   22412     23545487 :       add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
   22413              :     }
   22414              : }
   22415              : 
   22416              : /* We do not currently support the pure_virtual attribute.  */
   22417              : 
   22418              : static inline void
   22419     96951193 : add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
   22420              : {
   22421     96951193 :   if (DECL_VINDEX (func_decl))
   22422              :     {
   22423      1072347 :       add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
   22424              : 
   22425      1072347 :       if (tree_fits_shwi_p (DECL_VINDEX (func_decl)))
   22426       789762 :         add_AT_loc (die, DW_AT_vtable_elem_location,
   22427              :                     new_loc_descr (DW_OP_constu,
   22428       789762 :                                    tree_to_shwi (DECL_VINDEX (func_decl)),
   22429              :                                    0));
   22430              : 
   22431              :       /* GNU extension: Record what type this method came from originally.  */
   22432      1072347 :       if (debug_info_level > DINFO_LEVEL_TERSE
   22433      1072347 :           && DECL_CONTEXT (func_decl))
   22434      1072309 :         add_AT_die_ref (die, DW_AT_containing_type,
   22435      1072309 :                         lookup_type_die (DECL_CONTEXT (func_decl)));
   22436              :     }
   22437     96951193 : }
   22438              : 
   22439              : /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
   22440              :    given decl.  This used to be a vendor extension until after DWARF 4
   22441              :    standardized it.  */
   22442              : 
   22443              : static void
   22444    118969282 : add_linkage_attr (dw_die_ref die, tree decl)
   22445              : {
   22446    118969282 :   const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   22447              : 
   22448              :   /* Mimic what assemble_name_raw does with a leading '*'.  */
   22449    118969282 :   if (name[0] == '*')
   22450       448777 :     name = &name[1];
   22451              : 
   22452    118969282 :   if (dwarf_version >= 4)
   22453    118964457 :     add_AT_string (die, DW_AT_linkage_name, name);
   22454              :   else
   22455         4825 :     add_AT_string (die, DW_AT_MIPS_linkage_name, name);
   22456    118969282 : }
   22457              : 
   22458              : /* Add source coordinate attributes for the given decl.  */
   22459              : 
   22460              : static void
   22461    245913114 : add_src_coords_attributes (dw_die_ref die, tree decl)
   22462              : {
   22463    245913114 :   expanded_location s;
   22464              : 
   22465    245913114 :   if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl)) == UNKNOWN_LOCATION)
   22466       115695 :     return;
   22467    245797419 :   s = expand_location (DECL_SOURCE_LOCATION (decl));
   22468    245797419 :   add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
   22469    245797419 :   add_AT_unsigned (die, DW_AT_decl_line, s.line);
   22470    245797419 :   if (debug_column_info && s.column)
   22471    244991654 :     add_AT_unsigned (die, DW_AT_decl_column, s.column);
   22472              : }
   22473              : 
   22474              : /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl.  */
   22475              : 
   22476              : static void
   22477    125867729 : add_linkage_name_raw (dw_die_ref die, tree decl)
   22478              : {
   22479              :   /* Defer until we have an assembler name set.  */
   22480    125867729 :   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
   22481              :     {
   22482    123787530 :       limbo_die_node *asm_name;
   22483              : 
   22484    123787530 :       asm_name = ggc_cleared_alloc<limbo_die_node> ();
   22485    123787530 :       asm_name->die = die;
   22486    123787530 :       asm_name->created_for = decl;
   22487    123787530 :       asm_name->next = deferred_asm_name;
   22488    123787530 :       deferred_asm_name = asm_name;
   22489              :     }
   22490      2080199 :   else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
   22491      1655606 :     add_linkage_attr (die, decl);
   22492    125867729 : }
   22493              : 
   22494              : /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired.  */
   22495              : 
   22496              : static void
   22497    203979180 : add_linkage_name (dw_die_ref die, tree decl)
   22498              : {
   22499    203979180 :   if (debug_info_level > DINFO_LEVEL_NONE
   22500    203979171 :       && VAR_OR_FUNCTION_DECL_P (decl)
   22501    127758484 :       && TREE_PUBLIC (decl)
   22502    125539270 :       && !(VAR_P (decl) && DECL_REGISTER (decl))
   22503    329518444 :       && die->die_tag != DW_TAG_member)
   22504    125539156 :     add_linkage_name_raw (die, decl);
   22505    203979180 : }
   22506              : 
   22507              : /* Add a DW_AT_name attribute and source coordinate attribute for the
   22508              :    given decl, but only if it actually has a name.  */
   22509              : 
   22510              : static void
   22511    204339319 : add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
   22512              :                                     bool no_linkage_name)
   22513              : {
   22514    204339319 :   tree decl_name;
   22515              : 
   22516    204339319 :   decl_name = DECL_NAME (decl);
   22517    408153872 :   if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
   22518              :     {
   22519    203814553 :       const char *name = dwarf2_name (decl, 0);
   22520    203814553 :       if (name)
   22521    203807692 :         add_name_attribute (die, name);
   22522              :       else
   22523         6861 :         add_desc_attribute (die, decl);
   22524              : 
   22525    203814553 :       if (! DECL_ARTIFICIAL (decl))
   22526    196671348 :         add_src_coords_attributes (die, decl);
   22527              : 
   22528    203814553 :       if (!no_linkage_name)
   22529    203549752 :         add_linkage_name (die, decl);
   22530              :     }
   22531              :   else
   22532       524766 :     add_desc_attribute (die, decl);
   22533              : 
   22534              : #ifdef VMS_DEBUGGING_INFO
   22535              :   /* Get the function's name, as described by its RTL.  This may be different
   22536              :      from the DECL_NAME name used in the source file.  */
   22537              :   if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
   22538              :     {
   22539              :       add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
   22540              :                   XEXP (DECL_RTL (decl), 0), false);
   22541              :       vec_safe_push (used_rtx_array, XEXP (DECL_RTL (decl), 0));
   22542              :     }
   22543              : #endif /* VMS_DEBUGGING_INFO */
   22544    204339319 : }
   22545              : 
   22546              : /* Add VALUE as a DW_AT_discr_value attribute to DIE.  */
   22547              : 
   22548              : static void
   22549            0 : add_discr_value (dw_die_ref die, dw_discr_value *value)
   22550              : {
   22551            0 :   dw_attr_node attr;
   22552              : 
   22553            0 :   attr.dw_attr = DW_AT_discr_value;
   22554            0 :   attr.dw_attr_val.val_class = dw_val_class_discr_value;
   22555            0 :   attr.dw_attr_val.val_entry = NULL;
   22556            0 :   attr.dw_attr_val.v.val_discr_value.pos = value->pos;
   22557            0 :   if (value->pos)
   22558            0 :     attr.dw_attr_val.v.val_discr_value.v.uval = value->v.uval;
   22559              :   else
   22560            0 :     attr.dw_attr_val.v.val_discr_value.v.sval = value->v.sval;
   22561            0 :   add_dwarf_attr (die, &attr);
   22562            0 : }
   22563              : 
   22564              : /* Add DISCR_LIST as a DW_AT_discr_list to DIE.  */
   22565              : 
   22566              : static void
   22567            0 : add_discr_list (dw_die_ref die, dw_discr_list_ref discr_list)
   22568              : {
   22569            0 :   dw_attr_node attr;
   22570              : 
   22571            0 :   attr.dw_attr = DW_AT_discr_list;
   22572            0 :   attr.dw_attr_val.val_class = dw_val_class_discr_list;
   22573            0 :   attr.dw_attr_val.val_entry = NULL;
   22574            0 :   attr.dw_attr_val.v.val_discr_list = discr_list;
   22575            0 :   add_dwarf_attr (die, &attr);
   22576            0 : }
   22577              : 
   22578              : static inline dw_discr_list_ref
   22579            0 : AT_discr_list (dw_attr_node *attr)
   22580              : {
   22581            0 :   return attr->dw_attr_val.v.val_discr_list;
   22582              : }
   22583              : 
   22584              : #ifdef VMS_DEBUGGING_INFO
   22585              : /* Output the debug main pointer die for VMS */
   22586              : 
   22587              : void
   22588              : dwarf2out_vms_debug_main_pointer (void)
   22589              : {
   22590              :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
   22591              :   dw_die_ref die;
   22592              : 
   22593              :   /* Allocate the VMS debug main subprogram die.  */
   22594              :   die = new_die_raw (DW_TAG_subprogram);
   22595              :   add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
   22596              :   ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
   22597              :                                current_function_funcdef_no);
   22598              :   add_AT_lbl_id (die, DW_AT_entry_pc, label);
   22599              : 
   22600              :   /* Make it the first child of comp_unit_die ().  */
   22601              :   die->die_parent = comp_unit_die ();
   22602              :   if (comp_unit_die ()->die_child)
   22603              :     {
   22604              :       die->die_sib = comp_unit_die ()->die_child->die_sib;
   22605              :       comp_unit_die ()->die_child->die_sib = die;
   22606              :     }
   22607              :   else
   22608              :     {
   22609              :       die->die_sib = die;
   22610              :       comp_unit_die ()->die_child = die;
   22611              :     }
   22612              : }
   22613              : #endif /* VMS_DEBUGGING_INFO */
   22614              : 
   22615              : /* walk_tree helper function for uses_local_type, below.  */
   22616              : 
   22617              : static tree
   22618      2298625 : uses_local_type_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
   22619              : {
   22620      2298625 :   if (!TYPE_P (*tp))
   22621            0 :     *walk_subtrees = 0;
   22622              :   else
   22623              :     {
   22624      2298625 :       tree name = TYPE_NAME (*tp);
   22625      2298625 :       if (name && DECL_P (name) && decl_function_context (name))
   22626       105663 :         return *tp;
   22627              :     }
   22628              :   return NULL_TREE;
   22629              : }
   22630              : 
   22631              : /* If TYPE involves a function-local type (including a local typedef to a
   22632              :    non-local type), returns that type; otherwise returns NULL_TREE.  */
   22633              : 
   22634              : static tree
   22635      1171406 : uses_local_type (tree type)
   22636              : {
   22637      1171406 :   tree used = walk_tree_without_duplicates (&type, uses_local_type_r, NULL);
   22638      1171406 :   return used;
   22639              : }
   22640              : 
   22641              : /* Return the DIE for the scope that immediately contains this type.
   22642              :    Non-named types that do not involve a function-local type get global
   22643              :    scope.  Named types nested in namespaces or other types get their
   22644              :    containing scope.  All other types (i.e. function-local named types) get
   22645              :    the current active scope.  */
   22646              : 
   22647              : static dw_die_ref
   22648    164921813 : scope_die_for (tree t, dw_die_ref context_die)
   22649              : {
   22650    164921813 :   dw_die_ref scope_die = NULL;
   22651    164921813 :   tree containing_scope;
   22652              : 
   22653              :   /* Non-types always go in the current scope.  */
   22654    164921813 :   gcc_assert (TYPE_P (t));
   22655              : 
   22656              :   /* Use the scope of the typedef, rather than the scope of the type
   22657              :      it refers to.  */
   22658    164921813 :   if (TYPE_NAME (t) && DECL_P (TYPE_NAME (t)))
   22659    130879672 :     containing_scope = DECL_CONTEXT (TYPE_NAME (t));
   22660              :   else
   22661     34042141 :     containing_scope = TYPE_CONTEXT (t);
   22662              : 
   22663              :   /* Use the containing namespace if there is one.  */
   22664    164921813 :   if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
   22665              :     {
   22666    109276286 :       if (context_die == lookup_decl_die (containing_scope))
   22667              :         /* OK */;
   22668     56857879 :       else if (debug_info_level > DINFO_LEVEL_TERSE)
   22669     56857879 :         context_die = get_context_die (containing_scope);
   22670              :       else
   22671              :         containing_scope = NULL_TREE;
   22672              :     }
   22673              : 
   22674              :   /* Ignore function type "scopes" from the C frontend.  They mean that
   22675              :      a tagged type is local to a parmlist of a function declarator, but
   22676              :      that isn't useful to DWARF.  */
   22677    129716351 :   if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
   22678              :     containing_scope = NULL_TREE;
   22679              : 
   22680    129716320 :   if (SCOPE_FILE_SCOPE_P (containing_scope))
   22681              :     {
   22682              :       /* If T uses a local type keep it local as well, to avoid references
   22683              :          to function-local DIEs from outside the function.  */
   22684     38166309 :       if (current_function_decl && uses_local_type (t))
   22685              :         scope_die = context_die;
   22686              :       else
   22687     36889240 :         scope_die = comp_unit_die ();
   22688              :     }
   22689    127926910 :   else if (TYPE_P (containing_scope))
   22690              :     {
   22691              :       /* For types, we can just look up the appropriate DIE.  */
   22692     18069792 :       if (debug_info_level > DINFO_LEVEL_TERSE)
   22693     18069792 :         scope_die = get_context_die (containing_scope);
   22694              :       else
   22695              :         {
   22696            0 :           scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
   22697            0 :           if (scope_die == NULL)
   22698            0 :             scope_die = comp_unit_die ();
   22699              :         }
   22700              :     }
   22701              :   else
   22702              :     scope_die = context_die;
   22703              : 
   22704    164921813 :   return scope_die;
   22705              : }
   22706              : 
   22707              : /* Returns true if CONTEXT_DIE is internal to a function.  */
   22708              : 
   22709              : static inline bool
   22710           82 : local_scope_p (dw_die_ref context_die)
   22711              : {
   22712    422627498 :   for (; context_die; context_die = context_die->die_parent)
   22713    324009004 :     if (context_die->die_tag == DW_TAG_inlined_subroutine
   22714    324009003 :         || context_die->die_tag == DW_TAG_subprogram)
   22715              :       return true;
   22716              : 
   22717              :   return false;
   22718              : }
   22719              : 
   22720              : /* Returns true if CONTEXT_DIE is a class.  */
   22721              : 
   22722              : static inline bool
   22723    225257225 : class_scope_p (dw_die_ref context_die)
   22724              : {
   22725    225257225 :   return (context_die
   22726    225257225 :           && (context_die->die_tag == DW_TAG_structure_type
   22727              :               || context_die->die_tag == DW_TAG_class_type
   22728              :               || context_die->die_tag == DW_TAG_interface_type
   22729    225257225 :               || context_die->die_tag == DW_TAG_union_type));
   22730              : }
   22731              : 
   22732              : /* Returns true if CONTEXT_DIE is a class or namespace, for deciding
   22733              :    whether or not to treat a DIE in this context as a declaration.  */
   22734              : 
   22735              : static inline bool
   22736    135436549 : class_or_namespace_scope_p (dw_die_ref context_die)
   22737              : {
   22738    135436549 :   return (class_scope_p (context_die)
   22739    135436549 :           || (context_die && context_die->die_tag == DW_TAG_namespace));
   22740              : }
   22741              : 
   22742              : /* Many forms of DIEs require a "type description" attribute.  This
   22743              :    routine locates the proper "type descriptor" die for the type given
   22744              :    by 'type' plus any additional qualifiers given by 'cv_quals', and
   22745              :    adds a DW_AT_type attribute below the given die.  */
   22746              : 
   22747              : static void
   22748    465342598 : add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
   22749              :                     bool reverse, dw_die_ref context_die)
   22750              : {
   22751    465342598 :   enum tree_code code  = TREE_CODE (type);
   22752    465342598 :   dw_die_ref type_die  = NULL;
   22753              : 
   22754    465342598 :   if (debug_info_level <= DINFO_LEVEL_TERSE)
   22755              :     return;
   22756              : 
   22757              :   /* ??? If this type is an unnamed subrange type of an integral, floating-point
   22758              :      or fixed-point type, use the inner type.  This is because we have no
   22759              :      support for unnamed types in base_type_die.  This can happen if this is
   22760              :      an Ada subrange type.  Correct solution is emit a subrange type die.  */
   22761    465341480 :   if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
   22762    106878071 :       && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
   22763          681 :     type = TREE_TYPE (type), code = TREE_CODE (type);
   22764              : 
   22765    465341480 :   if (code == ERROR_MARK
   22766              :       /* Handle a special case.  For functions whose return type is void, we
   22767              :          generate *no* type attribute.  (Note that no object may have type
   22768              :          `void', so this only applies to function return types).  */
   22769    465341480 :       || code == VOID_TYPE)
   22770              :     return;
   22771              : 
   22772   1730747700 :   type_die = modified_type_die (type,
   22773    432686925 :                                 cv_quals | TYPE_QUALS (type),
   22774    432686925 :                                 TYPE_ATTRIBUTES (type),
   22775              :                                 reverse,
   22776              :                                 context_die);
   22777              : 
   22778    432686925 :   if (type_die != NULL)
   22779    432686813 :     add_AT_die_ref (object_die, DW_AT_type, type_die);
   22780              : }
   22781              : 
   22782              : /* Given an object die, add the calling convention attribute for the
   22783              :    function call type.  */
   22784              : static void
   22785     98780060 : add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
   22786              : {
   22787     98780060 :   enum dwarf_calling_convention value = DW_CC_normal;
   22788              : 
   22789    197560120 :   value = ((enum dwarf_calling_convention)
   22790     98780060 :            targetm.dwarf_calling_convention (TREE_TYPE (decl)));
   22791              : 
   22792     98780060 :   if (is_fortran ()
   22793     98780060 :       && id_equal (DECL_ASSEMBLER_NAME (decl), "MAIN__"))
   22794              :     {
   22795              :       /* DWARF 2 doesn't provide a way to identify a program's source-level
   22796              :         entry point.  DW_AT_calling_convention attributes are only meant
   22797              :         to describe functions' calling conventions.  However, lacking a
   22798              :         better way to signal the Fortran main program, we used this for
   22799              :         a long time, following existing custom.  Now, DWARF 4 has
   22800              :         DW_AT_main_subprogram, which we add below, but some tools still
   22801              :         rely on the old way, which we thus keep.  */
   22802         4416 :       value = DW_CC_program;
   22803              : 
   22804         4416 :       if (dwarf_version >= 4 || !dwarf_strict)
   22805         4416 :         add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
   22806              :     }
   22807              : 
   22808              :   /* Only add the attribute if the backend requests it, and
   22809              :      is not DW_CC_normal.  */
   22810     98780060 :   if (value && (value != DW_CC_normal))
   22811         4416 :     add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
   22812     98780060 : }
   22813              : 
   22814              : /* Given a tree pointer to a struct, class, union, or enum type node, return
   22815              :    a pointer to the (string) tag name for the given type, or zero if the type
   22816              :    was declared without a tag.  */
   22817              : 
   22818              : static const char *
   22819     53910837 : type_tag (const_tree type)
   22820              : {
   22821     53910837 :   const char *name = 0;
   22822              : 
   22823     53910837 :   if (TYPE_NAME (type) != 0)
   22824              :     {
   22825     52352410 :       tree t = 0;
   22826              : 
   22827              :       /* Find the IDENTIFIER_NODE for the type name.  */
   22828     52352410 :       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
   22829     52352410 :           && !TYPE_NAMELESS (type))
   22830       275857 :         t = TYPE_NAME (type);
   22831              : 
   22832              :       /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
   22833              :          a TYPE_DECL node, regardless of whether or not a `typedef' was
   22834              :          involved.  */
   22835     52076553 :       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   22836     52076553 :                && ! DECL_IGNORED_P (TYPE_NAME (type)))
   22837              :         {
   22838              :           /* We want to be extra verbose.  Don't call dwarf_name if
   22839              :              DECL_NAME isn't set.  The default hook for decl_printable_name
   22840              :              doesn't like that, and in this context it's correct to return
   22841              :              0, instead of "<anonymous>" or the like.  */
   22842     52062057 :           if (DECL_NAME (TYPE_NAME (type))
   22843     52062057 :               && !DECL_NAMELESS (TYPE_NAME (type)))
   22844     52060447 :             name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
   22845              :         }
   22846              : 
   22847              :       /* Now get the name as a string, or invent one.  */
   22848     52352410 :       if (!name && t != 0)
   22849       275857 :         name = IDENTIFIER_POINTER (t);
   22850              :     }
   22851              : 
   22852     52352410 :   return (name == 0 || *name == '\0') ? 0 : name;
   22853              : }
   22854              : 
   22855              : /* Return the type associated with a data member, make a special check
   22856              :    for bit field types.  */
   22857              : 
   22858              : static inline tree
   22859     33242464 : member_declared_type (const_tree member)
   22860              : {
   22861     33242464 :   return (DECL_BIT_FIELD_TYPE (member)
   22862     33242464 :           ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
   22863              : }
   22864              : 
   22865              : /* Get the decl's label, as described by its RTL. This may be different
   22866              :    from the DECL_NAME name used in the source file.  */
   22867              : 
   22868              : #if 0
   22869              : static const char *
   22870              : decl_start_label (tree decl)
   22871              : {
   22872              :   rtx x;
   22873              :   const char *fnname;
   22874              : 
   22875              :   x = DECL_RTL (decl);
   22876              :   gcc_assert (MEM_P (x));
   22877              : 
   22878              :   x = XEXP (x, 0);
   22879              :   gcc_assert (GET_CODE (x) == SYMBOL_REF);
   22880              : 
   22881              :   fnname = XSTR (x, 0);
   22882              :   return fnname;
   22883              : }
   22884              : #endif
   22885              : 
   22886              : /* For variable-length arrays that have been previously generated, but
   22887              :    may be incomplete due to missing subscript info, fill the subscript
   22888              :    info.  Return TRUE if this is one of those cases.  */
   22889              : 
   22890              : static bool
   22891     11017000 : fill_variable_array_bounds (tree type)
   22892              : {
   22893     11017000 :   if (TREE_ASM_WRITTEN (type)
   22894      4051136 :       && TREE_CODE (type) == ARRAY_TYPE
   22895     11027688 :       && variably_modified_type_p (type, NULL))
   22896              :     {
   22897        10659 :       dw_die_ref array_die = lookup_type_die (type);
   22898        10659 :       if (!array_die)
   22899              :         return false;
   22900        10659 :       add_subscript_info (array_die, type, !is_ada ());
   22901        10659 :       return true;
   22902              :     }
   22903              :   return false;
   22904              : }
   22905              : 
   22906              : /* These routines generate the internal representation of the DIE's for
   22907              :    the compilation unit.  Debugging information is collected by walking
   22908              :    the declaration trees passed in from dwarf2out_decl().  */
   22909              : 
   22910              : static void
   22911      1034278 : gen_array_type_die (tree type, dw_die_ref context_die)
   22912              : {
   22913      1034278 :   dw_die_ref array_die;
   22914              : 
   22915              :   /* GNU compilers represent multidimensional array types as sequences of one
   22916              :      dimensional array types whose element types are themselves array types.
   22917              :      We sometimes squish that down to a single array_type DIE with multiple
   22918              :      subscripts in the Dwarf debugging info.  The draft Dwarf specification
   22919              :      say that we are allowed to do this kind of compression in C, because
   22920              :      there is no difference between an array of arrays and a multidimensional
   22921              :      array.  We don't do this for Ada to remain as close as possible to the
   22922              :      actual representation, which is especially important against the language
   22923              :      flexibility wrt arrays of variable size.  */
   22924              : 
   22925      1034278 :   bool collapse_nested_arrays = !is_ada ();
   22926              : 
   22927      1034278 :   if (fill_variable_array_bounds (type))
   22928              :     return;
   22929              : 
   22930      1023701 :   dw_die_ref scope_die = scope_die_for (type, context_die);
   22931      1023701 :   tree element_type;
   22932              : 
   22933              :   /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
   22934              :      DW_TAG_string_type doesn't have DW_AT_type attribute).  */
   22935      1023701 :   if (TREE_CODE (type) == ARRAY_TYPE
   22936      1002606 :       && TYPE_STRING_FLAG (type)
   22937         4627 :       && is_fortran ()
   22938      1028328 :       && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
   22939              :     {
   22940         4240 :       HOST_WIDE_INT size;
   22941              : 
   22942         4240 :       array_die = new_die (DW_TAG_string_type, scope_die, type);
   22943         4240 :       add_name_attribute (array_die, type_tag (type));
   22944         4240 :       equate_type_number_to_die (type, array_die);
   22945         4240 :       size = int_size_in_bytes (type);
   22946         4240 :       if (size >= 0)
   22947         1659 :         add_AT_unsigned (array_die, DW_AT_byte_size, size);
   22948              :       /* ???  We can't annotate types late, but for LTO we may not
   22949              :          generate a location early either (gfortran.dg/save_6.f90).  */
   22950         1563 :       else if (! (early_dwarf && (flag_generate_lto || flag_generate_offload))
   22951         2581 :                && TYPE_DOMAIN (type) != NULL_TREE
   22952         5162 :                && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE)
   22953              :         {
   22954         2366 :           tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
   22955         2366 :           tree rszdecl = szdecl;
   22956              : 
   22957         2366 :           size = int_size_in_bytes (TREE_TYPE (szdecl));
   22958         2366 :           if (!DECL_P (szdecl))
   22959              :             {
   22960           77 :               if (INDIRECT_REF_P (szdecl)
   22961           77 :                   && DECL_P (TREE_OPERAND (szdecl, 0)))
   22962              :                 {
   22963           72 :                   rszdecl = TREE_OPERAND (szdecl, 0);
   22964          144 :                   if (int_size_in_bytes (TREE_TYPE (rszdecl))
   22965           72 :                       != DWARF2_ADDR_SIZE)
   22966              :                     size = 0;
   22967              :                 }
   22968              :               else
   22969              :                 size = 0;
   22970              :             }
   22971         2361 :           if (size > 0)
   22972              :             {
   22973         2361 :               dw_loc_list_ref loc
   22974         2433 :                 = loc_list_from_tree (rszdecl, szdecl == rszdecl ? 2 : 0,
   22975              :                                       NULL);
   22976         2361 :               if (loc)
   22977              :                 {
   22978         2162 :                   add_AT_location_description (array_die, DW_AT_string_length,
   22979              :                                                loc);
   22980         2174 :                   if (size != DWARF2_ADDR_SIZE)
   22981            0 :                     add_AT_unsigned (array_die, dwarf_version >= 5
   22982              :                                                 ? DW_AT_string_length_byte_size
   22983              :                                                 : DW_AT_byte_size, size);
   22984              :                 }
   22985              :             }
   22986              :         }
   22987              :       return;
   22988              :     }
   22989              : 
   22990      1019461 :   array_die = new_die (DW_TAG_array_type, scope_die, type);
   22991      1019461 :   add_name_attribute (array_die, type_tag (type));
   22992      1019461 :   equate_type_number_to_die (type, array_die);
   22993              : 
   22994      1019461 :   if (VECTOR_TYPE_P (type))
   22995        21095 :     add_AT_flag (array_die, DW_AT_GNU_vector, 1);
   22996              : 
   22997              :   /* For Fortran multidimensional arrays use DW_ORD_col_major ordering.  */
   22998      1019461 :   if (is_fortran ()
   22999        10299 :       && TREE_CODE (type) == ARRAY_TYPE
   23000        10299 :       && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
   23001      1021818 :       && !TYPE_STRING_FLAG (TREE_TYPE (type)))
   23002         1718 :     add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
   23003              : 
   23004              : #if 0
   23005              :   /* We default the array ordering.  Debuggers will probably do the right
   23006              :      things even if DW_AT_ordering is not present.  It's not even an issue
   23007              :      until we start to get into multidimensional arrays anyway.  If a debugger
   23008              :      is ever caught doing the Wrong Thing for multi-dimensional arrays,
   23009              :      then we'll have to put the DW_AT_ordering attribute back in.  (But if
   23010              :      and when we find out that we need to put these in, we will only do so
   23011              :      for multidimensional arrays.  */
   23012              :   add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
   23013              : #endif
   23014              : 
   23015      1019461 :   if (VECTOR_TYPE_P (type))
   23016              :     {
   23017              :       /* For VECTOR_TYPEs we use an array DIE with appropriate bounds.  */
   23018        21095 :       dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
   23019        21095 :       int lb = lower_bound_default ();
   23020        21095 :       if (lb == -1)
   23021              :         lb = 0;
   23022        21095 :       add_bound_info (subrange_die, DW_AT_lower_bound, size_int (lb), NULL);
   23023        21095 :       add_bound_info (subrange_die, DW_AT_upper_bound,
   23024        42190 :                       size_int (lb + TYPE_VECTOR_SUBPARTS (type) - 1), NULL);
   23025              :     }
   23026              :   else
   23027       998366 :     add_subscript_info (array_die, type, collapse_nested_arrays);
   23028              : 
   23029              :   /* Add representation of the type of the elements of this array type and
   23030              :      emit the corresponding DIE if we haven't done it already.  */
   23031      1019461 :   element_type = TREE_TYPE (type);
   23032      1019461 :   if (collapse_nested_arrays)
   23033      1023666 :     while (TREE_CODE (element_type) == ARRAY_TYPE)
   23034              :       {
   23035         5004 :         if (TYPE_STRING_FLAG (element_type) && is_fortran ())
   23036              :           break;
   23037         4205 :         element_type = TREE_TYPE (element_type);
   23038              :       }
   23039              : 
   23040      1019461 :   add_type_attribute (array_die, element_type, TYPE_UNQUALIFIED,
   23041      1019461 :                       TREE_CODE (type) == ARRAY_TYPE
   23042       998366 :                       && TYPE_REVERSE_STORAGE_ORDER (type),
   23043              :                       context_die);
   23044              : 
   23045              :   /* Add bit stride information to boolean vectors of single bits so that
   23046              :      elements can be correctly read and displayed by a debugger.  */
   23047      1019461 :   if (VECTOR_BOOLEAN_TYPE_P (type))
   23048              :     {
   23049            0 :       enum machine_mode tmode = TYPE_MODE_RAW (type);
   23050            0 :       if (GET_MODE_CLASS (tmode) == MODE_VECTOR_BOOL)
   23051              :         {
   23052              :           /* Calculate bit-size of element based on mnode.  */
   23053            0 :           poly_uint16 bit_size = exact_div (GET_MODE_BITSIZE (tmode),
   23054            0 :                                             GET_MODE_NUNITS (tmode));
   23055              :           /* Set bit stride in the array type DIE.  */
   23056            0 :           add_AT_unsigned (array_die, DW_AT_bit_stride, bit_size.coeffs[0]);
   23057              :           /* Find DIE corresponding to the element type so that we could
   23058              :              add DW_AT_bit_size to it.  */
   23059            0 :           dw_die_ref elem_die = get_AT_ref (array_die, DW_AT_type);
   23060              :           /* Avoid adding DW_AT_bit_size twice.  */
   23061            0 :           if (get_AT (elem_die, DW_AT_bit_size) == NULL)
   23062            0 :             add_AT_unsigned (elem_die, DW_AT_bit_size,
   23063            0 :                              TYPE_PRECISION (element_type));
   23064              :         }
   23065              :     }
   23066              : 
   23067      1019461 :   add_gnat_descriptive_type_attribute (array_die, type, context_die);
   23068      1019461 :   if (TYPE_ARTIFICIAL (type))
   23069            0 :     add_AT_flag (array_die, DW_AT_artificial, 1);
   23070              : 
   23071      1019461 :   if (get_AT (array_die, DW_AT_name))
   23072           68 :     add_pubtype (type, array_die);
   23073              : 
   23074      1019461 :   add_alignment_attribute (array_die, type);
   23075      1019461 :   maybe_gen_btf_type_tag_dies (type, array_die);
   23076              : }
   23077              : 
   23078              : /* This routine generates DIE for array with hidden descriptor, details
   23079              :    are filled into *info by a langhook.  */
   23080              : 
   23081              : static void
   23082         7281 : gen_descr_array_type_die (tree type, struct array_descr_info *info,
   23083              :                           dw_die_ref context_die)
   23084              : {
   23085         7281 :   const dw_die_ref scope_die = scope_die_for (type, context_die);
   23086         7281 :   const dw_die_ref array_die = new_die (DW_TAG_array_type, scope_die, type);
   23087         7281 :   struct loc_descr_context context = {
   23088              :     type,               /* context_type */
   23089         7281 :     info->base_decl, /* base_decl */
   23090              :     NULL,               /* dpi */
   23091              :     false,              /* placeholder_arg */
   23092              :     false,              /* placeholder_seen */
   23093              :     false               /* strict_signedness */
   23094         7281 :   };
   23095         7281 :   enum dwarf_tag subrange_tag = DW_TAG_subrange_type;
   23096         7281 :   int dim;
   23097              : 
   23098         7281 :   add_name_attribute (array_die, type_tag (type));
   23099         7281 :   equate_type_number_to_die (type, array_die);
   23100              : 
   23101         7281 :   if (info->ndimensions > 1)
   23102         1727 :     switch (info->ordering)
   23103              :       {
   23104            0 :       case array_descr_ordering_row_major:
   23105            0 :         add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
   23106            0 :         break;
   23107         1727 :       case array_descr_ordering_column_major:
   23108         1727 :         add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
   23109         1727 :         break;
   23110              :       default:
   23111              :         break;
   23112              :       }
   23113              : 
   23114         7281 :   if (dwarf_version >= 3 || !dwarf_strict)
   23115              :     {
   23116         7281 :       if (info->data_location)
   23117         7281 :         add_scalar_info (array_die, DW_AT_data_location, info->data_location,
   23118              :                          dw_scalar_form_exprloc, &context);
   23119         7281 :       if (info->associated)
   23120         1334 :         add_scalar_info (array_die, DW_AT_associated, info->associated,
   23121              :                          dw_scalar_form_constant
   23122              :                          | dw_scalar_form_exprloc
   23123              :                          | dw_scalar_form_reference, &context);
   23124         7281 :       if (info->allocated)
   23125         2626 :         add_scalar_info (array_die, DW_AT_allocated, info->allocated,
   23126              :                          dw_scalar_form_constant
   23127              :                          | dw_scalar_form_exprloc
   23128              :                          | dw_scalar_form_reference, &context);
   23129         7281 :       if (info->stride)
   23130              :         {
   23131            0 :           const enum dwarf_attribute attr
   23132            0 :             = (info->stride_in_bits) ? DW_AT_bit_stride : DW_AT_byte_stride;
   23133            0 :           const int forms
   23134              :             = (info->stride_in_bits)
   23135            0 :               ? dw_scalar_form_constant
   23136              :               : (dw_scalar_form_constant
   23137              :                  | dw_scalar_form_exprloc
   23138              :                  | dw_scalar_form_reference);
   23139              : 
   23140            0 :           add_scalar_info (array_die, attr, info->stride, forms, &context);
   23141              :         }
   23142              :     }
   23143         7281 :   if (dwarf_version >= 5)
   23144              :     {
   23145         7281 :       if (info->rank)
   23146              :         {
   23147         1130 :           add_scalar_info (array_die, DW_AT_rank, info->rank,
   23148              :                            dw_scalar_form_constant
   23149              :                            | dw_scalar_form_exprloc, &context);
   23150         1130 :           subrange_tag = DW_TAG_generic_subrange;
   23151         1130 :           context.placeholder_arg = true;
   23152              :         }
   23153              :     }
   23154              : 
   23155         7281 :   add_gnat_descriptive_type_attribute (array_die, type, context_die);
   23156              : 
   23157        24192 :   for (dim = 0; dim < info->ndimensions; dim++)
   23158              :     {
   23159         9630 :       dw_die_ref subrange_die = new_die (subrange_tag, array_die, NULL);
   23160              : 
   23161         9630 :       if (info->dimen[dim].bounds_type)
   23162            0 :         add_type_attribute (subrange_die,
   23163              :                             info->dimen[dim].bounds_type, TYPE_UNQUALIFIED,
   23164              :                             false, context_die);
   23165         9630 :       if (info->dimen[dim].lower_bound)
   23166         9630 :         add_bound_info (subrange_die, DW_AT_lower_bound,
   23167              :                         info->dimen[dim].lower_bound, &context);
   23168         9630 :       if (info->dimen[dim].upper_bound)
   23169         9630 :         add_bound_info (subrange_die, DW_AT_upper_bound,
   23170              :                         info->dimen[dim].upper_bound, &context);
   23171         9630 :       if ((dwarf_version >= 3 || !dwarf_strict) && info->dimen[dim].stride)
   23172         9630 :         add_scalar_info (subrange_die, DW_AT_byte_stride,
   23173              :                          info->dimen[dim].stride,
   23174              :                          dw_scalar_form_constant
   23175              :                          | dw_scalar_form_exprloc
   23176              :                          | dw_scalar_form_reference,
   23177              :                          &context);
   23178              :     }
   23179              : 
   23180         7281 :   gen_type_die (info->element_type, context_die);
   23181         7281 :   add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
   23182         7281 :                       TREE_CODE (type) == ARRAY_TYPE
   23183            0 :                       && TYPE_REVERSE_STORAGE_ORDER (type),
   23184              :                       context_die);
   23185              : 
   23186         7281 :   if (get_AT (array_die, DW_AT_name))
   23187            0 :     add_pubtype (type, array_die);
   23188              : 
   23189         7281 :   add_alignment_attribute (array_die, type);
   23190         7281 : }
   23191              : 
   23192              : #if 0
   23193              : static void
   23194              : gen_entry_point_die (tree decl, dw_die_ref context_die)
   23195              : {
   23196              :   tree origin = decl_ultimate_origin (decl);
   23197              :   dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
   23198              : 
   23199              :   if (origin != NULL)
   23200              :     add_abstract_origin_attribute (decl_die, origin);
   23201              :   else
   23202              :     {
   23203              :       add_name_and_src_coords_attributes (decl_die, decl);
   23204              :       add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
   23205              :                           TYPE_UNQUALIFIED, false, context_die);
   23206              :     }
   23207              : 
   23208              :   if (DECL_ABSTRACT_P (decl))
   23209              :     equate_decl_number_to_die (decl, decl_die);
   23210              :   else
   23211              :     add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
   23212              : }
   23213              : #endif
   23214              : 
   23215              : /* Walk through the list of incomplete types again, trying once more to
   23216              :    emit full debugging info for them.  */
   23217              : 
   23218              : static void
   23219        53595 : retry_incomplete_types (void)
   23220              : {
   23221        53595 :   set_early_dwarf s;
   23222        53595 :   int i;
   23223              : 
   23224     48019840 :   for (i = vec_safe_length (incomplete_types) - 1; i >= 0; i--)
   23225     47912650 :     if (should_emit_struct_debug ((*incomplete_types)[i], DINFO_USAGE_DIR_USE))
   23226     47912353 :       gen_type_die ((*incomplete_types)[i], comp_unit_die ());
   23227        53595 :   vec_safe_truncate (incomplete_types, 0);
   23228        53595 : }
   23229              : 
   23230              : /* Determine what tag to use for a record type.  */
   23231              : 
   23232              : static enum dwarf_tag
   23233     50522714 : record_type_tag (tree type)
   23234              : {
   23235     50522714 :   if (! lang_hooks.types.classify_record)
   23236              :     return DW_TAG_structure_type;
   23237              : 
   23238     49883991 :   switch (lang_hooks.types.classify_record (type))
   23239              :     {
   23240              :     case RECORD_IS_STRUCT:
   23241              :       return DW_TAG_structure_type;
   23242              : 
   23243              :     case RECORD_IS_CLASS:
   23244              :       return DW_TAG_class_type;
   23245              : 
   23246            0 :     case RECORD_IS_INTERFACE:
   23247            0 :       if (dwarf_version >= 3 || !dwarf_strict)
   23248              :         return DW_TAG_interface_type;
   23249              :       return DW_TAG_structure_type;
   23250              : 
   23251            0 :     default:
   23252            0 :       gcc_unreachable ();
   23253              :     }
   23254              : }
   23255              : 
   23256              : /* Generate a DIE to represent an enumeration type.  Note that these DIEs
   23257              :    include all of the information about the enumeration values also. Each
   23258              :    enumerated type name/value is listed as a child of the enumerated type
   23259              :    DIE. REVERSE is true if the type is to be interpreted in the reverse
   23260              :    storage order wrt the target order.  */
   23261              : 
   23262              : static dw_die_ref
   23263      1873244 : gen_enumeration_type_die (tree type, dw_die_ref context_die, bool reverse)
   23264              : {
   23265      1873244 :   dw_die_ref type_die = lookup_type_die (type);
   23266      1873244 :   dw_die_ref orig_type_die = type_die;
   23267              : 
   23268      1873244 :   if (type_die == NULL || reverse)
   23269              :     {
   23270      1872813 :       dw_die_ref scope_die = scope_die_for (type, context_die);
   23271              : 
   23272              :       /* The DIE with DW_AT_endianity is placed right after the naked DIE.  */
   23273      1872813 :       if (reverse)
   23274              :         {
   23275            2 :           gcc_assert (type_die);
   23276            2 :           dw_die_ref after_die = type_die;
   23277            2 :           type_die = new_die_raw (DW_TAG_enumeration_type);
   23278            2 :           add_child_die_after (scope_die, type_die, after_die);
   23279              :         }
   23280              :       else
   23281              :         {
   23282      1872811 :           type_die = new_die (DW_TAG_enumeration_type, scope_die, type);
   23283      1872811 :           equate_type_number_to_die (type, type_die);
   23284              :         }
   23285      1872813 :       add_name_attribute (type_die, type_tag (type));
   23286          816 :       if ((dwarf_version >= 4 || !dwarf_strict)
   23287      3745626 :           && ENUM_IS_SCOPED (type))
   23288       373783 :         add_AT_flag (type_die, DW_AT_enum_class, 1);
   23289      1872813 :       if (ENUM_IS_OPAQUE (type) && TYPE_SIZE (type))
   23290          339 :         add_AT_flag (type_die, DW_AT_declaration, 1);
   23291      1872813 :       if (!dwarf_strict)
   23292      1872813 :         add_AT_unsigned (type_die, DW_AT_encoding,
   23293      1872813 :                          TYPE_UNSIGNED (type)
   23294              :                          ? DW_ATE_unsigned
   23295              :                          : DW_ATE_signed);
   23296      1872813 :       if (reverse)
   23297            2 :         add_AT_unsigned (type_die, DW_AT_endianity,
   23298              :                          BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big);
   23299              :     }
   23300          861 :   else if (! TYPE_SIZE (type) || ENUM_IS_OPAQUE (type))
   23301              :     return type_die;
   23302              :   else
   23303            7 :     remove_AT (type_die, DW_AT_declaration);
   23304              : 
   23305              :   /* Handle a GNU C/C++ extension, i.e. incomplete enum types.  If the
   23306              :      given enum type is incomplete, do not generate the DW_AT_byte_size
   23307              :      attribute or the DW_AT_element_list attribute.  */
   23308      1872820 :   if (TYPE_SIZE (type))
   23309              :     {
   23310      1872812 :       tree link;
   23311              : 
   23312      1872812 :       if (!ENUM_IS_OPAQUE (type))
   23313      1872473 :         TREE_ASM_WRITTEN (type) = 1;
   23314      1872812 :       if (!orig_type_die || !get_AT (type_die, DW_AT_byte_size))
   23315      1872810 :         add_byte_size_attribute (type_die, type);
   23316      1872812 :       if (!orig_type_die || !get_AT (type_die, DW_AT_alignment))
   23317      1872812 :         add_alignment_attribute (type_die, type);
   23318          816 :       if ((dwarf_version >= 3 || !dwarf_strict)
   23319      1873628 :           && (!orig_type_die || !get_AT (type_die, DW_AT_type)))
   23320              :         {
   23321      1872810 :           tree underlying = lang_hooks.types.enum_underlying_base_type (type);
   23322      1872810 :           add_type_attribute (type_die, underlying, TYPE_UNQUALIFIED, false,
   23323              :                               context_die);
   23324              :         }
   23325      1872812 :       if (TYPE_STUB_DECL (type) != NULL_TREE)
   23326              :         {
   23327      1872782 :           if (!orig_type_die || !get_AT (type_die, DW_AT_decl_file))
   23328      1872780 :             add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
   23329      1872782 :           if (!orig_type_die || !get_AT (type_die, DW_AT_accessibility))
   23330      1872782 :             add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
   23331              :         }
   23332              : 
   23333              :       /* If the first reference to this type was as the return type of an
   23334              :          inline function, then it may not have a parent.  Fix this now.  */
   23335      1872812 :       if (type_die->die_parent == NULL)
   23336            5 :         add_child_die (scope_die_for (type, context_die), type_die);
   23337              : 
   23338      1872812 :       for (link = TYPE_VALUES (type);
   23339     16329182 :            link != NULL; link = TREE_CHAIN (link))
   23340              :         {
   23341     14456370 :           dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
   23342     14456370 :           tree value = TREE_VALUE (link);
   23343              : 
   23344     14456370 :           if (DECL_P (value))
   23345     14447712 :             equate_decl_number_to_die (value, enum_die);
   23346              : 
   23347     14456370 :           gcc_assert (!ENUM_IS_OPAQUE (type));
   23348     14456370 :           add_name_attribute (enum_die,
   23349     14456370 :                               IDENTIFIER_POINTER (TREE_PURPOSE (link)));
   23350              : 
   23351     14456370 :           if (TREE_CODE (value) == CONST_DECL)
   23352     14447712 :             value = DECL_INITIAL (value);
   23353              : 
   23354     14456370 :           if (simple_type_size_in_bits (TREE_TYPE (value))
   23355     14456370 :               <= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
   23356              :             {
   23357              :               /* For constant forms created by add_AT_unsigned DWARF
   23358              :                  consumers (GDB, elfutils, etc.) always zero extend
   23359              :                  the value.  Only when the actual value is negative
   23360              :                  do we need to use add_AT_int to generate a constant
   23361              :                  form that can represent negative values.  */
   23362     14456368 :               HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
   23363     14456368 :               if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
   23364     14260941 :                 add_AT_unsigned (enum_die, DW_AT_const_value,
   23365              :                                  (unsigned HOST_WIDE_INT) val);
   23366              :               else
   23367       195427 :                 add_AT_int (enum_die, DW_AT_const_value, val);
   23368              :             }
   23369              :           else
   23370              :             /* Enumeration constants may be wider than HOST_WIDE_INT.  Handle
   23371              :                that here.  TODO: This should be re-worked to use correct
   23372              :                signed/unsigned double tags for all cases.  */
   23373            2 :             add_AT_wide (enum_die, DW_AT_const_value, wi::to_wide (value));
   23374              :         }
   23375              : 
   23376      1872812 :       add_gnat_descriptive_type_attribute (type_die, type, context_die);
   23377      1872812 :       if (TYPE_ARTIFICIAL (type)
   23378      1872812 :           && (!orig_type_die || !get_AT (type_die, DW_AT_artificial)))
   23379            0 :         add_AT_flag (type_die, DW_AT_artificial, 1);
   23380              :     }
   23381              :   else
   23382            8 :     add_AT_flag (type_die, DW_AT_declaration, 1);
   23383              : 
   23384      1872820 :   add_pubtype (type, type_die);
   23385              : 
   23386      1872820 :   return type_die;
   23387              : }
   23388              : 
   23389              : /* Generate a DIE to represent either a real live formal parameter decl or to
   23390              :    represent just the type of some formal parameter position in some function
   23391              :    type.
   23392              : 
   23393              :    Note that this routine is a bit unusual because its argument may be a
   23394              :    ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
   23395              :    represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
   23396              :    node.  If it's the former then this function is being called to output a
   23397              :    DIE to represent a formal parameter object (or some inlining thereof).  If
   23398              :    it's the latter, then this function is only being called to output a
   23399              :    DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
   23400              :    argument type of some subprogram type.
   23401              :    If EMIT_NAME_P is true, name and source coordinate attributes
   23402              :    are emitted.  */
   23403              : 
   23404              : static dw_die_ref
   23405    200761288 : gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
   23406              :                           dw_die_ref context_die)
   23407              : {
   23408    200761288 :   tree node_or_origin = node ? node : origin;
   23409    200761288 :   tree ultimate_origin;
   23410    200761288 :   dw_die_ref parm_die = NULL;
   23411              : 
   23412    200761288 :   if (DECL_P (node_or_origin))
   23413              :     {
   23414     18432236 :       parm_die = lookup_decl_die (node);
   23415              : 
   23416              :       /* If the contexts differ, we may not be talking about the same
   23417              :          thing.
   23418              :          ???  When in LTO the DIE parent is the "abstract" copy and the
   23419              :          context_die is the specification "copy".  */
   23420     18432236 :       if (parm_die
   23421       988795 :           && parm_die->die_parent != context_die
   23422        86298 :           && (parm_die->die_parent->die_tag != DW_TAG_GNU_formal_parameter_pack
   23423         4289 :               || parm_die->die_parent->die_parent != context_die)
   23424        82484 :           && !in_lto_p)
   23425              :         {
   23426        82484 :           gcc_assert (!DECL_ABSTRACT_P (node));
   23427              :           /* This can happen when creating a concrete instance, in
   23428              :              which case we need to create a new DIE that will get
   23429              :              annotated with DW_AT_abstract_origin.  */
   23430              :           parm_die = NULL;
   23431              :         }
   23432              : 
   23433       906311 :       if (parm_die && parm_die->die_parent == NULL)
   23434              :         {
   23435              :           /* Check that parm_die already has the right attributes that
   23436              :              we would have added below.  If any attributes are
   23437              :              missing, fall through to add them.  */
   23438            0 :           if (! DECL_ABSTRACT_P (node_or_origin)
   23439            0 :               && !get_AT (parm_die, DW_AT_location)
   23440            0 :               && !get_AT (parm_die, DW_AT_const_value))
   23441              :             /* We are missing  location info, and are about to add it.  */
   23442              :             ;
   23443              :           else
   23444              :             {
   23445            0 :               add_child_die (context_die, parm_die);
   23446            0 :               maybe_gen_btf_decl_tag_dies (node_or_origin, parm_die);
   23447            0 :               return parm_die;
   23448              :             }
   23449              :         }
   23450              :     }
   23451              : 
   23452              :   /* If we have a previously generated DIE, use it, unless this is an
   23453              :      concrete instance (origin != NULL), in which case we need a new
   23454              :      DIE with a corresponding DW_AT_abstract_origin.  */
   23455    200761288 :   bool reusing_die;
   23456    200761288 :   if (parm_die && origin == NULL)
   23457              :     reusing_die = true;
   23458              :   else
   23459              :     {
   23460    199854977 :       parm_die = new_die (DW_TAG_formal_parameter, context_die, node);
   23461    199854977 :       reusing_die = false;
   23462              :     }
   23463              : 
   23464    200761288 :   switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
   23465              :     {
   23466     18432236 :     case tcc_declaration:
   23467     18432236 :       ultimate_origin = decl_ultimate_origin (node_or_origin);
   23468     18432236 :       if (node || ultimate_origin)
   23469     18432236 :         origin = ultimate_origin;
   23470              : 
   23471     18432236 :       if (reusing_die)
   23472       906311 :         goto add_location;
   23473              : 
   23474     17525925 :       if (origin != NULL)
   23475     13878074 :         add_abstract_origin_attribute (parm_die, origin);
   23476      3647851 :       else if (emit_name_p)
   23477      3516195 :         add_name_and_src_coords_attributes (parm_die, node);
   23478     17525925 :       if (origin == NULL
   23479     17525925 :           || (! DECL_ABSTRACT_P (node_or_origin)
   23480     13878074 :               && variably_modified_type_p (TREE_TYPE (node_or_origin),
   23481              :                                            decl_function_context
   23482              :                                                             (node_or_origin))))
   23483              :         {
   23484      3649625 :           tree type = TREE_TYPE (node_or_origin);
   23485      3649625 :           if (decl_by_reference_p (node_or_origin))
   23486        44556 :             add_type_attribute (parm_die, TREE_TYPE (type),
   23487              :                                 TYPE_UNQUALIFIED,
   23488              :                                 false, context_die);
   23489              :           else
   23490      3605069 :             add_type_attribute (parm_die, type,
   23491              :                                 decl_quals (node_or_origin),
   23492              :                                 false, context_die);
   23493              :         }
   23494     17525925 :       if (origin == NULL && DECL_ARTIFICIAL (node))
   23495      1029026 :         add_AT_flag (parm_die, DW_AT_artificial, 1);
   23496     18432236 :     add_location:
   23497     18432236 :       if (node && node != origin)
   23498     18349700 :         equate_decl_number_to_die (node, parm_die);
   23499     18432236 :       if (! DECL_ABSTRACT_P (node_or_origin))
   23500     18432236 :         add_location_or_const_value_attribute (parm_die, node_or_origin,
   23501              :                                                node == NULL);
   23502              : 
   23503              :       break;
   23504              : 
   23505    182329052 :     case tcc_type:
   23506              :       /* We were called with some kind of a ..._TYPE node.  */
   23507    182329052 :       add_type_attribute (parm_die, node_or_origin, TYPE_UNQUALIFIED, false,
   23508              :                           context_die);
   23509    182329052 :       break;
   23510              : 
   23511            0 :     default:
   23512            0 :       gcc_unreachable ();
   23513              :     }
   23514              : 
   23515    200761288 :   maybe_gen_btf_decl_tag_dies (node_or_origin, parm_die);
   23516              : 
   23517    200761288 :   return parm_die;
   23518              : }
   23519              : 
   23520              : /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
   23521              :    children DW_TAG_formal_parameter DIEs representing the arguments of the
   23522              :    parameter pack.
   23523              : 
   23524              :    PARM_PACK must be a function parameter pack.
   23525              :    PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
   23526              :    must point to the subsequent arguments of the function PACK_ARG belongs to.
   23527              :    SUBR_DIE is the DIE of the function PACK_ARG belongs to.
   23528              :    If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
   23529              :    following the last one for which a DIE was generated.  */
   23530              : 
   23531              : static dw_die_ref
   23532        99119 : gen_formal_parameter_pack_die  (tree parm_pack,
   23533              :                                 tree pack_arg,
   23534              :                                 dw_die_ref subr_die,
   23535              :                                 tree *next_arg)
   23536              : {
   23537        99119 :   tree arg;
   23538        99119 :   dw_die_ref parm_pack_die;
   23539              : 
   23540        99119 :   gcc_assert (parm_pack
   23541              :               && lang_hooks.function_parameter_pack_p (parm_pack)
   23542              :               && subr_die);
   23543              : 
   23544        99119 :   parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
   23545        99119 :   add_name_and_src_coords_attributes (parm_pack_die, parm_pack);
   23546              : 
   23547       347665 :   for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
   23548              :     {
   23549       149427 :       if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
   23550              :                                                                  parm_pack))
   23551              :         break;
   23552       149427 :       gen_formal_parameter_die (arg, NULL,
   23553              :                                 false /* Don't emit name attribute.  */,
   23554              :                                 parm_pack_die);
   23555              :     }
   23556        99119 :   if (next_arg)
   23557        99119 :     *next_arg = arg;
   23558        99119 :   return parm_pack_die;
   23559              : }
   23560              : 
   23561              : /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
   23562              :    at the end of an (ANSI prototyped) formal parameters list.  */
   23563              : 
   23564              : static void
   23565        93702 : gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
   23566              : {
   23567            0 :   new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
   23568            0 : }
   23569              : 
   23570              : /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
   23571              :    DW_TAG_unspecified_parameters DIE) to represent the types of the formal
   23572              :    parameters as specified in some function type specification (except for
   23573              :    those which appear as part of a function *definition*).  */
   23574              : 
   23575              : static void
   23576     96921847 : gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
   23577              : {
   23578     96921847 :   tree link;
   23579     96921847 :   tree formal_type = NULL;
   23580     96921847 :   tree first_parm_type;
   23581     96921847 :   tree arg;
   23582              : 
   23583     96921847 :   if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
   23584              :     {
   23585     96479644 :       arg = DECL_ARGUMENTS (function_or_method_type);
   23586     96479644 :       function_or_method_type = TREE_TYPE (function_or_method_type);
   23587              :     }
   23588              :   else
   23589              :     arg = NULL_TREE;
   23590              : 
   23591     96921847 :   first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
   23592              : 
   23593              :   /* Make our first pass over the list of formal parameter types and output a
   23594              :      DW_TAG_formal_parameter DIE for each one.  */
   23595    279250899 :   for (link = first_parm_type; link; )
   23596              :     {
   23597    279161704 :       dw_die_ref parm_die;
   23598              : 
   23599    279161704 :       formal_type = TREE_VALUE (link);
   23600    279161704 :       if (formal_type == void_type_node)
   23601              :         break;
   23602              : 
   23603              :       /* Output a (nameless) DIE to represent the formal parameter itself.  */
   23604    182329052 :       parm_die = gen_formal_parameter_die (formal_type, NULL,
   23605              :                                            true /* Emit name attribute.  */,
   23606              :                                            context_die);
   23607    182329052 :       if (TREE_CODE (function_or_method_type) == METHOD_TYPE
   23608    165587012 :           && link == first_parm_type)
   23609              :         {
   23610     82317768 :           add_AT_flag (parm_die, DW_AT_artificial, 1);
   23611     82317768 :           if (dwarf_version >= 3 || !dwarf_strict)
   23612     82317768 :             add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
   23613              :         }
   23614    100011284 :       else if (arg && DECL_ARTIFICIAL (arg))
   23615        23347 :         add_AT_flag (parm_die, DW_AT_artificial, 1);
   23616              : 
   23617    182329052 :       link = TREE_CHAIN (link);
   23618    182329052 :       if (arg)
   23619    181504441 :         arg = DECL_CHAIN (arg);
   23620              :     }
   23621              : 
   23622              :   /* If this function type has an ellipsis, add a
   23623              :      DW_TAG_unspecified_parameters DIE to the end of the parameter list.  */
   23624     96921847 :   if (formal_type != void_type_node)
   23625        89195 :     gen_unspecified_parameters_die (function_or_method_type, context_die);
   23626              : 
   23627              :   /* Make our second (and final) pass over the list of formal parameter types
   23628              :      and output DIEs to represent those types (as necessary).  */
   23629     96921847 :   for (link = TYPE_ARG_TYPES (function_or_method_type);
   23630    655245255 :        link && TREE_VALUE (link);
   23631    279161704 :        link = TREE_CHAIN (link))
   23632    279161704 :     gen_type_die (TREE_VALUE (link), context_die);
   23633     96921847 : }
   23634              : 
   23635              : /* We want to generate the DIE for TYPE so that we can generate the
   23636              :    die for MEMBER, which has been defined; we will need to refer back
   23637              :    to the member declaration nested within TYPE.  If we're trying to
   23638              :    generate minimal debug info for TYPE, processing TYPE won't do the
   23639              :    trick; we need to attach the member declaration by hand.  */
   23640              : 
   23641              : static void
   23642    119206911 : gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
   23643              : {
   23644    119206911 :   gen_type_die (type, context_die);
   23645              : 
   23646              :   /* If we're trying to avoid duplicate debug info, we may not have
   23647              :      emitted the member decl for this function.  Emit it now.  */
   23648    119206911 :   if (TYPE_STUB_DECL (type)
   23649    119206911 :       && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
   23650    119457709 :       && ! lookup_decl_die (member))
   23651              :     {
   23652       131879 :       dw_die_ref type_die;
   23653       131879 :       gcc_assert (!decl_ultimate_origin (member));
   23654              : 
   23655       131879 :       type_die = lookup_type_die_strip_naming_typedef (type);
   23656       131879 :       if (TREE_CODE (member) == FUNCTION_DECL)
   23657       130980 :         gen_subprogram_die (member, type_die);
   23658          899 :       else if (TREE_CODE (member) == FIELD_DECL)
   23659              :         {
   23660              :           /* Ignore the nameless fields that are used to skip bits but handle
   23661              :              C++ anonymous unions and structs.  */
   23662            6 :           if (DECL_NAME (member) != NULL_TREE
   23663            0 :               || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
   23664            6 :               || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
   23665              :             {
   23666            6 :               struct vlr_context vlr_ctx = {
   23667            6 :                 DECL_CONTEXT (member), /* struct_type */
   23668              :                 NULL_TREE /* variant_part_offset */
   23669            6 :               };
   23670            6 :               gen_type_die (member_declared_type (member), type_die);
   23671            6 :               gen_field_die (member, &vlr_ctx, type_die);
   23672              :             }
   23673              :         }
   23674              :       else
   23675          893 :         gen_variable_die (member, NULL_TREE, type_die);
   23676              :     }
   23677    119206911 : }
   23678              : 
   23679              : /* Forward declare these functions, because they are mutually recursive
   23680              :   with their set_block_* pairing functions.  */
   23681              : static void set_decl_origin_self (tree);
   23682              : 
   23683              : /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
   23684              :    given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
   23685              :    that it points to the node itself, thus indicating that the node is its
   23686              :    own (abstract) origin.  Additionally, if the BLOCK_ABSTRACT_ORIGIN for
   23687              :    the given node is NULL, recursively descend the decl/block tree which
   23688              :    it is the root of, and for each other ..._DECL or BLOCK node contained
   23689              :    therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
   23690              :    still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
   23691              :    values to point to themselves.  */
   23692              : 
   23693              : static void
   23694      3031318 : set_block_origin_self (tree stmt)
   23695              : {
   23696      3031318 :   if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
   23697              :     {
   23698      1803636 :       BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
   23699              : 
   23700      1803636 :       {
   23701      1803636 :         tree local_decl;
   23702              : 
   23703      1803636 :         for (local_decl = BLOCK_VARS (stmt);
   23704      2667448 :              local_decl != NULL_TREE;
   23705       863812 :              local_decl = DECL_CHAIN (local_decl))
   23706              :           /* Do not recurse on nested functions since the inlining status
   23707              :              of parent and child can be different as per the DWARF spec.  */
   23708       863812 :           if (TREE_CODE (local_decl) != FUNCTION_DECL
   23709       863812 :               && !DECL_EXTERNAL (local_decl))
   23710       860404 :             set_decl_origin_self (local_decl);
   23711              :       }
   23712              : 
   23713      1803636 :       {
   23714      1803636 :         tree subblock;
   23715              : 
   23716      3413204 :         for (subblock = BLOCK_SUBBLOCKS (stmt);
   23717      3413204 :              subblock != NULL_TREE;
   23718      1609568 :              subblock = BLOCK_CHAIN (subblock))
   23719      1609568 :           set_block_origin_self (subblock);     /* Recurse.  */
   23720              :       }
   23721              :     }
   23722      3031318 : }
   23723              : 
   23724              : /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
   23725              :    the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
   23726              :    node to so that it points to the node itself, thus indicating that the
   23727              :    node represents its own (abstract) origin.  Additionally, if the
   23728              :    DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
   23729              :    the decl/block tree of which the given node is the root of, and for
   23730              :    each other ..._DECL or BLOCK node contained therein whose
   23731              :    DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
   23732              :    set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
   23733              :    point to themselves.  */
   23734              : 
   23735              : static void
   23736      2298455 : set_decl_origin_self (tree decl)
   23737              : {
   23738      2298455 :   if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
   23739              :     {
   23740      2298455 :       DECL_ABSTRACT_ORIGIN (decl) = decl;
   23741      2298455 :       if (TREE_CODE (decl) == FUNCTION_DECL)
   23742              :         {
   23743      1438051 :           tree arg;
   23744              : 
   23745      4174145 :           for (arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
   23746      2736094 :             DECL_ABSTRACT_ORIGIN (arg) = arg;
   23747      1438051 :           if (DECL_INITIAL (decl) != NULL_TREE
   23748      1438051 :               && DECL_INITIAL (decl) != error_mark_node)
   23749      1421750 :             set_block_origin_self (DECL_INITIAL (decl));
   23750              :         }
   23751              :     }
   23752      2298455 : }
   23753              : 
   23754              : /* Mark the early DIE for DECL as the abstract instance.  */
   23755              : 
   23756              : static void
   23757      4691464 : dwarf2out_abstract_function (tree decl)
   23758              : {
   23759      4691464 :   dw_die_ref old_die;
   23760              : 
   23761              :   /* Make sure we have the actual abstract inline, not a clone.  */
   23762      4691464 :   decl = DECL_ORIGIN (decl);
   23763              : 
   23764      4691464 :   if (DECL_IGNORED_P (decl))
   23765              :     return;
   23766              : 
   23767              : #ifdef CODEVIEW_DEBUGGING_INFO
   23768              :   if (codeview_debuginfo_p ())
   23769              :     codeview_abstract_function (decl);
   23770              : #endif
   23771              : 
   23772              :   /* In LTO we're all set.  We already created abstract instances
   23773              :      early and we want to avoid creating a concrete instance of that
   23774              :      if we don't output it.  */
   23775      4691443 :   if (in_lto_p)
   23776              :     return;
   23777              : 
   23778      4690970 :   old_die = lookup_decl_die (decl);
   23779      4690970 :   gcc_assert (old_die != NULL);
   23780      4690970 :   if (get_AT (old_die, DW_AT_inline))
   23781              :     /* We've already generated the abstract instance.  */
   23782              :     return;
   23783              : 
   23784              :   /* Go ahead and put DW_AT_inline on the DIE.  */
   23785      1438051 :   if (DECL_DECLARED_INLINE_P (decl))
   23786              :     {
   23787      1317391 :       if (cgraph_function_possibly_inlined_p (decl))
   23788      1003698 :         add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_inlined);
   23789              :       else
   23790       313693 :         add_AT_unsigned (old_die, DW_AT_inline, DW_INL_declared_not_inlined);
   23791              :     }
   23792              :   else
   23793              :     {
   23794       120660 :       if (cgraph_function_possibly_inlined_p (decl))
   23795        99045 :         add_AT_unsigned (old_die, DW_AT_inline, DW_INL_inlined);
   23796              :       else
   23797        21615 :         add_AT_unsigned (old_die, DW_AT_inline, DW_INL_not_inlined);
   23798              :     }
   23799              : 
   23800      1438051 :   if (DECL_DECLARED_INLINE_P (decl)
   23801      1317391 :       && !DECL_ARTIFICIAL (decl)
   23802      2689445 :       && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
   23803         1270 :     add_AT_flag (old_die, DW_AT_artificial, 1);
   23804              : 
   23805      1438051 :   set_decl_origin_self (decl);
   23806              : }
   23807              : 
   23808              : /* Helper function of premark_used_types() which gets called through
   23809              :    htab_traverse.
   23810              : 
   23811              :    Marks the DIE of a given type in *SLOT as perennial, so it never gets
   23812              :    marked as unused by prune_unused_types.  */
   23813              : 
   23814              : bool
   23815      1221314 : premark_used_types_helper (tree const &type, void *)
   23816              : {
   23817      1221314 :   dw_die_ref die;
   23818              : 
   23819      1221314 :   die = lookup_type_die (type);
   23820      1221314 :   if (die != NULL)
   23821      1053714 :     die->die_perennial_p = 1;
   23822      1221314 :   return true;
   23823              : }
   23824              : 
   23825              : /* Helper function of premark_types_used_by_global_vars which gets called
   23826              :    through htab_traverse.
   23827              : 
   23828              :    Marks the DIE of a given type in *SLOT as perennial, so it never gets
   23829              :    marked as unused by prune_unused_types. The DIE of the type is marked
   23830              :    only if the global variable using the type will actually be emitted.  */
   23831              : 
   23832              : int
   23833      7632389 : premark_types_used_by_global_vars_helper (types_used_by_vars_entry **slot,
   23834              :                                           void *)
   23835              : {
   23836      7632389 :   struct types_used_by_vars_entry *entry;
   23837      7632389 :   dw_die_ref die;
   23838              : 
   23839      7632389 :   entry = (struct types_used_by_vars_entry *) *slot;
   23840      7632389 :   gcc_assert (entry->type != NULL
   23841              :               && entry->var_decl != NULL);
   23842      7632389 :   die = lookup_type_die (entry->type);
   23843      7632389 :   if (die)
   23844              :     {
   23845              :       /* Ask cgraph if the global variable really is to be emitted.
   23846              :          If yes, then we'll keep the DIE of ENTRY->TYPE.  */
   23847      7021844 :       varpool_node *node = varpool_node::get (entry->var_decl);
   23848      7021844 :       if (node && node->definition)
   23849              :         {
   23850        10906 :           die->die_perennial_p = 1;
   23851              :           /* Keep the parent DIEs as well.  */
   23852        19869 :           while ((die = die->die_parent) && die->die_perennial_p == 0)
   23853         8963 :             die->die_perennial_p = 1;
   23854              :         }
   23855              :     }
   23856      7632389 :   return 1;
   23857              : }
   23858              : 
   23859              : /* Mark all members of used_types_hash as perennial.  */
   23860              : 
   23861              : static void
   23862     99331930 : premark_used_types (struct function *fun)
   23863              : {
   23864     99331930 :   if (fun && fun->used_types_hash)
   23865      2078860 :     fun->used_types_hash->traverse<void *, premark_used_types_helper> (NULL);
   23866     99331930 : }
   23867              : 
   23868              : /* Mark all members of types_used_by_vars_entry as perennial.  */
   23869              : 
   23870              : static void
   23871        53628 : premark_types_used_by_global_vars (void)
   23872              : {
   23873        53628 :   if (types_used_by_vars_hash)
   23874        14603 :     types_used_by_vars_hash
   23875      7646992 :       ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
   23876        53628 : }
   23877              : 
   23878              : /* Mark all variables used by the symtab as perennial.  */
   23879              : 
   23880              : static void
   23881        53596 : premark_used_variables (void)
   23882              : {
   23883              :   /* Mark DIEs in the symtab as used.  */
   23884        53596 :   varpool_node *var;
   23885      2028890 :   FOR_EACH_VARIABLE (var)
   23886              :     {
   23887      1975294 :       dw_die_ref die = lookup_decl_die (var->decl);
   23888      1975294 :       if (die)
   23889              :         {
   23890       273319 :           die->die_perennial_p = 1;
   23891       273319 :           if (tree attr = lookup_attribute ("structured bindings",
   23892       273319 :                                             DECL_ATTRIBUTES (var->decl)))
   23893          166 :             for (tree d = TREE_VALUE (attr); d; d = TREE_CHAIN (d))
   23894              :               {
   23895          128 :                 die = lookup_decl_die (TREE_VALUE (d));
   23896          128 :                 if (die)
   23897          128 :                   die->die_perennial_p = 1;
   23898              :               }
   23899              :         }
   23900              :     }
   23901        53596 : }
   23902              : 
   23903              : /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
   23904              :    for CA_LOC call arg loc node.  */
   23905              : 
   23906              : static dw_die_ref
   23907      2981329 : gen_call_site_die (tree decl, dw_die_ref subr_die,
   23908              :                    struct call_arg_loc_node *ca_loc)
   23909              : {
   23910      2981329 :   dw_die_ref stmt_die = NULL, die;
   23911      2981329 :   tree block = ca_loc->block;
   23912              : 
   23913      2981329 :   while (block
   23914      5621385 :          && block != DECL_INITIAL (decl)
   23915     10286604 :          && TREE_CODE (block) == BLOCK)
   23916              :     {
   23917      4593973 :       stmt_die = lookup_block_die (block);
   23918      4593973 :       if (stmt_die)
   23919              :         break;
   23920      2711302 :       block = BLOCK_SUPERCONTEXT (block);
   23921              :     }
   23922      2981329 :   if (stmt_die == NULL)
   23923      1098658 :     stmt_die = subr_die;
   23924      2983184 :   die = new_die (dwarf_TAG (DW_TAG_call_site), stmt_die, NULL_TREE);
   23925      2983184 :   add_AT_lbl_id (die, dwarf_AT (DW_AT_call_return_pc),
   23926              :                  ca_loc->label,
   23927      2981329 :                  targetm.calls.call_offset_return_label (ca_loc->call_insn));
   23928      2981329 :   if (ca_loc->tail_call_p)
   23929        57665 :     add_AT_flag (die, dwarf_AT (DW_AT_call_tail_call), 1);
   23930      2981329 :   if (ca_loc->symbol_ref)
   23931              :     {
   23932      2911399 :       dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
   23933      2911399 :       if (tdie)
   23934      1388094 :         add_AT_die_ref (die, dwarf_AT (DW_AT_call_origin), tdie);
   23935              :       else
   23936      1525138 :         add_AT_addr (die, dwarf_AT (DW_AT_call_origin), ca_loc->symbol_ref,
   23937              :                      false);
   23938              :     }
   23939      2981329 :   return die;
   23940              : }
   23941              : 
   23942              : /* Generate a DIE to represent a declared function (either file-scope or
   23943              :    block-local).  */
   23944              : 
   23945              : static void
   23946     99465148 : gen_subprogram_die (tree decl, dw_die_ref context_die)
   23947              : {
   23948     99465148 :   tree origin = decl_ultimate_origin (decl);
   23949     99465148 :   dw_die_ref subr_die;
   23950     99465148 :   dw_die_ref old_die = lookup_decl_die (decl);
   23951     99465148 :   bool old_die_had_no_children = false;
   23952              : 
   23953              :   /* This function gets called multiple times for different stages of
   23954              :      the debug process.  For example, for func() in this code:
   23955              : 
   23956              :         namespace S
   23957              :         {
   23958              :           void func() { ... }
   23959              :         }
   23960              : 
   23961              :      ...we get called 4 times.  Twice in early debug and twice in
   23962              :      late debug:
   23963              : 
   23964              :      Early debug
   23965              :      -----------
   23966              : 
   23967              :        1. Once while generating func() within the namespace.  This is
   23968              :           the declaration.  The declaration bit below is set, as the
   23969              :           context is the namespace.
   23970              : 
   23971              :           A new DIE will be generated with DW_AT_declaration set.
   23972              : 
   23973              :        2. Once for func() itself.  This is the specification.  The
   23974              :           declaration bit below is clear as the context is the CU.
   23975              : 
   23976              :           We will use the cached DIE from (1) to create a new DIE with
   23977              :           DW_AT_specification pointing to the declaration in (1).
   23978              : 
   23979              :      Late debug via rest_of_handle_final()
   23980              :      -------------------------------------
   23981              : 
   23982              :        3. Once generating func() within the namespace.  This is also the
   23983              :           declaration, as in (1), but this time we will early exit below
   23984              :           as we have a cached DIE and a declaration needs no additional
   23985              :           annotations (no locations), as the source declaration line
   23986              :           info is enough.
   23987              : 
   23988              :        4. Once for func() itself.  As in (2), this is the specification,
   23989              :           but this time we will re-use the cached DIE, and just annotate
   23990              :           it with the location information that should now be available.
   23991              : 
   23992              :      For something without namespaces, but with abstract instances, we
   23993              :      are also called a multiple times:
   23994              : 
   23995              :         class Base
   23996              :         {
   23997              :         public:
   23998              :           Base ();        // constructor declaration (1)
   23999              :         };
   24000              : 
   24001              :         Base::Base () { } // constructor specification (2)
   24002              : 
   24003              :     Early debug
   24004              :     -----------
   24005              : 
   24006              :        1. Once for the Base() constructor by virtue of it being a
   24007              :           member of the Base class.  This is done via
   24008              :           rest_of_type_compilation.
   24009              : 
   24010              :           This is a declaration, so a new DIE will be created with
   24011              :           DW_AT_declaration.
   24012              : 
   24013              :        2. Once for the Base() constructor definition, but this time
   24014              :           while generating the abstract instance of the base
   24015              :           constructor (__base_ctor) which is being generated via early
   24016              :           debug of reachable functions.
   24017              : 
   24018              :           Even though we have a cached version of the declaration (1),
   24019              :           we will create a DW_AT_specification of the declaration DIE
   24020              :           in (1).
   24021              : 
   24022              :        3. Once for the __base_ctor itself, but this time, we generate
   24023              :           an DW_AT_abstract_origin version of the DW_AT_specification in
   24024              :           (2).
   24025              : 
   24026              :     Late debug via rest_of_handle_final
   24027              :     -----------------------------------
   24028              : 
   24029              :        4. One final time for the __base_ctor (which will have a cached
   24030              :           DIE with DW_AT_abstract_origin created in (3).  This time,
   24031              :           we will just annotate the location information now
   24032              :           available.
   24033              :   */
   24034     99465148 :   int declaration = (current_function_decl != decl
   24035      3600599 :                      || (!DECL_INITIAL (decl) && !origin)
   24036    102666588 :                      || class_or_namespace_scope_p (context_die));
   24037              : 
   24038              :   /* A declaration that has been previously dumped needs no
   24039              :      additional information.  */
   24040     99465148 :   if (old_die && declaration)
   24041              :     return;
   24042              : 
   24043     99331930 :   if (in_lto_p && old_die && old_die->die_child == NULL)
   24044     99331930 :     old_die_had_no_children = true;
   24045              : 
   24046              :   /* Now that the C++ front end lazily declares artificial member fns, we
   24047              :      might need to retrofit the declaration into its class.  */
   24048      2393789 :   if (!declaration && !origin && !old_die
   24049       710394 :       && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
   24050       239276 :       && !class_or_namespace_scope_p (context_die)
   24051     99571206 :       && debug_info_level > DINFO_LEVEL_TERSE)
   24052       239041 :     old_die = force_decl_die (decl);
   24053              : 
   24054              :   /* A concrete instance, tag a new DIE with DW_AT_abstract_origin.  */
   24055     99331930 :   if (origin != NULL)
   24056              :     {
   24057       458301 :       gcc_assert (!declaration || local_scope_p (context_die));
   24058              : 
   24059              :       /* Fixup die_parent for the abstract instance of a nested
   24060              :          inline function.  */
   24061       458301 :       if (old_die && old_die->die_parent == NULL)
   24062            0 :         add_child_die (context_die, old_die);
   24063              : 
   24064        78406 :       if (old_die && get_AT_ref (old_die, DW_AT_abstract_origin))
   24065              :         {
   24066              :           /* If we have a DW_AT_abstract_origin we have a working
   24067              :              cached version.  */
   24068              :           subr_die = old_die;
   24069              :         }
   24070              :       else
   24071              :         {
   24072       429358 :           subr_die = new_die (DW_TAG_subprogram, context_die, decl);
   24073       429358 :           add_abstract_origin_attribute (subr_die, origin);
   24074              :           /*  This is where the actual code for a cloned function is.
   24075              :               Let's emit linkage name attribute for it.  This helps
   24076              :               debuggers to e.g, set breakpoints into
   24077              :               constructors/destructors when the user asks "break
   24078              :               K::K".  */
   24079       429358 :           add_linkage_name (subr_die, decl);
   24080              :         }
   24081              :     }
   24082              :   /* A cached copy, possibly from early dwarf generation.  Reuse as
   24083              :      much as possible.  */
   24084     98873629 :   else if (old_die)
   24085              :     {
   24086      1922436 :       if (!get_AT_flag (old_die, DW_AT_declaration)
   24087              :           /* We can have a normal definition following an inline one in the
   24088              :              case of redefinition of GNU C extern inlines.
   24089              :              It seems reasonable to use AT_specification in this case.  */
   24090      1922436 :           && !get_AT (old_die, DW_AT_inline))
   24091              :         {
   24092              :           /* Detect and ignore this case, where we are trying to output
   24093              :              something we have already output.  */
   24094       394266 :           if (get_AT (old_die, DW_AT_low_pc)
   24095       394266 :               || get_AT (old_die, DW_AT_ranges))
   24096            0 :             return;
   24097              : 
   24098              :           /* If we have no location information, this must be a
   24099              :              partially generated DIE from early dwarf generation.
   24100              :              Fall through and generate it.  */
   24101              :         }
   24102              : 
   24103              :       /* If the definition comes from the same place as the declaration,
   24104              :          maybe use the old DIE.  We always want the DIE for this function
   24105              :          that has the *_pc attributes to be under comp_unit_die so the
   24106              :          debugger can find it.  We also need to do this for abstract
   24107              :          instances of inlines, since the spec requires the out-of-line copy
   24108              :          to have the same parent.  For local class methods, this doesn't
   24109              :          apply; we just use the old DIE.  */
   24110      1922436 :       expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
   24111      1922436 :       struct dwarf_file_data * file_index = lookup_filename (s.file);
   24112      1922436 :       if (((is_unit_die (old_die->die_parent)
   24113              :             /* This condition fixes the inconsistency/ICE with the
   24114              :                following Fortran test (or some derivative thereof) while
   24115              :                building libgfortran:
   24116              : 
   24117              :                   module some_m
   24118              :                   contains
   24119              :                      logical function funky (FLAG)
   24120              :                        funky = .true.
   24121              :                     end function
   24122              :                   end module
   24123              :              */
   24124      1459904 :             || (old_die->die_parent
   24125      1459904 :                 && old_die->die_parent->die_tag == DW_TAG_module)
   24126      1456628 :             || local_scope_p (old_die->die_parent)
   24127      1402911 :             || context_die == NULL)
   24128       519555 :            && (DECL_ARTIFICIAL (decl)
   24129       474541 :                || (get_AT_file (old_die, DW_AT_decl_file) == file_index
   24130       472009 :                    && (get_AT_unsigned (old_die, DW_AT_decl_line)
   24131       472009 :                        == (unsigned) s.line)
   24132       472009 :                    && (!debug_column_info
   24133       472005 :                        || s.column == 0
   24134       377797 :                        || (get_AT_unsigned (old_die, DW_AT_decl_column)
   24135       377797 :                            == (unsigned) s.column)))))
   24136              :           /* With LTO if there's an abstract instance for
   24137              :              the old DIE, this is a concrete instance and
   24138              :              thus re-use the DIE.  */
   24139      3327849 :           || get_AT (old_die, DW_AT_abstract_origin))
   24140              :         {
   24141       522927 :           subr_die = old_die;
   24142              : 
   24143              :           /* Clear out the declaration attribute, but leave the
   24144              :              parameters so they can be augmented with location
   24145              :              information later.  Unless this was a declaration, in
   24146              :              which case, wipe out the nameless parameters and recreate
   24147              :              them further down.  */
   24148       522927 :           if (remove_AT (subr_die, DW_AT_declaration))
   24149              :             {
   24150              : 
   24151        50787 :               remove_AT (subr_die, DW_AT_object_pointer);
   24152        50787 :               remove_child_TAG (subr_die, DW_TAG_formal_parameter);
   24153              :             }
   24154              :         }
   24155              :       /* Make a specification pointing to the previously built
   24156              :          declaration.  */
   24157              :       else
   24158              :         {
   24159      1399509 :           subr_die = new_die (DW_TAG_subprogram, context_die, decl);
   24160      1399509 :           add_AT_specification (subr_die, old_die);
   24161      1399509 :           add_pubname (decl, subr_die);
   24162      1399509 :           if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
   24163        51935 :             add_AT_file (subr_die, DW_AT_decl_file, file_index);
   24164      1399509 :           if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
   24165        56579 :             add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
   24166      1399509 :           if (debug_column_info
   24167      1399497 :               && s.column
   24168      2799006 :               && (get_AT_unsigned (old_die, DW_AT_decl_column)
   24169      1399497 :                   != (unsigned) s.column))
   24170        56569 :             add_AT_unsigned (subr_die, DW_AT_decl_column, s.column);
   24171              : 
   24172              :           /* If the prototype had an 'auto' or 'decltype(auto)' in
   24173              :              the return type, emit the real type on the definition die.  */
   24174      1399509 :           if (is_cxx () && debug_info_level > DINFO_LEVEL_TERSE)
   24175              :             {
   24176      1399509 :               dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
   24177      1399509 :               while (die
   24178      1760074 :                      && (die->die_tag == DW_TAG_reference_type
   24179              :                          || die->die_tag == DW_TAG_rvalue_reference_type
   24180              :                          || die->die_tag == DW_TAG_pointer_type
   24181              :                          || die->die_tag == DW_TAG_const_type
   24182              :                          || die->die_tag == DW_TAG_volatile_type
   24183              :                          || die->die_tag == DW_TAG_restrict_type
   24184              :                          || die->die_tag == DW_TAG_array_type
   24185              :                          || die->die_tag == DW_TAG_ptr_to_member_type
   24186              :                          || die->die_tag == DW_TAG_subroutine_type))
   24187       360565 :                 die = get_AT_ref (die, DW_AT_type);
   24188      1399509 :               if (die == auto_die || die == decltype_auto_die)
   24189       131984 :                 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
   24190              :                                     TYPE_UNQUALIFIED, false, context_die);
   24191              :             }
   24192              : 
   24193              :           /* When we process the method declaration, we haven't seen
   24194              :              the out-of-class defaulted definition yet, so we have to
   24195              :              recheck now.  */
   24196         1294 :           if ((dwarf_version >= 5 || ! dwarf_strict)
   24197      1400791 :               && !get_AT (subr_die, DW_AT_defaulted))
   24198              :             {
   24199      1377051 :               int defaulted
   24200      1377051 :                 = lang_hooks.decls.decl_dwarf_attribute (decl,
   24201              :                                                          DW_AT_defaulted);
   24202      1377051 :               if (defaulted != -1)
   24203              :                 {
   24204              :                   /* Other values must have been handled before.  */
   24205          318 :                   gcc_assert (defaulted == DW_DEFAULTED_out_of_class);
   24206          318 :                   add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
   24207              :                 }
   24208              :             }
   24209              :         }
   24210              :     }
   24211              :   /* Create a fresh DIE for anything else.  */
   24212              :   else
   24213              :     {
   24214     96951193 :       subr_die = new_die (DW_TAG_subprogram, context_die, decl);
   24215              : 
   24216     96951193 :       if (TREE_PUBLIC (decl))
   24217     96755564 :         add_AT_flag (subr_die, DW_AT_external, 1);
   24218              : 
   24219     96951193 :       add_name_and_src_coords_attributes (subr_die, decl);
   24220     96951193 :       add_pubname (decl, subr_die);
   24221     96951193 :       if (debug_info_level > DINFO_LEVEL_TERSE)
   24222              :         {
   24223     96937425 :           add_prototyped_attribute (subr_die, TREE_TYPE (decl));
   24224     96937425 :           add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
   24225              :                               TYPE_UNQUALIFIED, false, context_die);
   24226              :         }
   24227              : 
   24228     96951193 :       add_pure_or_virtual_attribute (subr_die, decl);
   24229     96951193 :       if (DECL_ARTIFICIAL (decl))
   24230      1239778 :         add_AT_flag (subr_die, DW_AT_artificial, 1);
   24231              : 
   24232     96951193 :       if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
   24233        74728 :         add_AT_flag (subr_die, DW_AT_noreturn, 1);
   24234              : 
   24235     96951193 :       add_alignment_attribute (subr_die, decl);
   24236              : 
   24237     96951193 :       add_accessibility_attribute (subr_die, decl);
   24238              :     }
   24239              : 
   24240              :   /* Unless we have an existing non-declaration DIE, equate the new
   24241              :      DIE.  */
   24242     99331930 :   if (!old_die || is_declaration_die (old_die))
   24243     98730585 :     equate_decl_number_to_die (decl, subr_die);
   24244              : 
   24245     99331930 :   if (declaration)
   24246              :     {
   24247     96479840 :       if (!old_die || !get_AT (old_die, DW_AT_inline))
   24248              :         {
   24249     96479840 :           add_AT_flag (subr_die, DW_AT_declaration, 1);
   24250              : 
   24251              :           /* If this is an explicit function declaration then generate
   24252              :              a DW_AT_explicit attribute.  */
   24253         2994 :           if ((dwarf_version >= 3 || !dwarf_strict)
   24254     96482834 :               && lang_hooks.decls.decl_dwarf_attribute (decl,
   24255              :                                                         DW_AT_explicit) == 1)
   24256      2786032 :             add_AT_flag (subr_die, DW_AT_explicit, 1);
   24257              : 
   24258              :           /* If this is a C++11 deleted special function member then generate
   24259              :              a DW_AT_deleted attribute.  */
   24260         3216 :           if ((dwarf_version >= 5 || !dwarf_strict)
   24261     96483038 :               && lang_hooks.decls.decl_dwarf_attribute (decl,
   24262              :                                                         DW_AT_deleted) == 1)
   24263      3060782 :             add_AT_flag (subr_die, DW_AT_deleted, 1);
   24264              : 
   24265              :           /* If this is a C++11 defaulted special function member then
   24266              :              generate a DW_AT_defaulted attribute.  */
   24267     96479840 :           if (dwarf_version >= 5 || !dwarf_strict)
   24268              :             {
   24269     96479822 :               int defaulted
   24270     96479822 :                 = lang_hooks.decls.decl_dwarf_attribute (decl,
   24271              :                                                          DW_AT_defaulted);
   24272     96479822 :               if (defaulted != -1)
   24273      5893835 :                 add_AT_unsigned (subr_die, DW_AT_defaulted, defaulted);
   24274              :             }
   24275              : 
   24276              :           /* If this is a C++11 non-static member function with & ref-qualifier
   24277              :              then generate a DW_AT_reference attribute.  */
   24278         3216 :           if ((dwarf_version >= 5 || !dwarf_strict)
   24279     96483038 :               && lang_hooks.decls.decl_dwarf_attribute (decl,
   24280              :                                                         DW_AT_reference) == 1)
   24281        36000 :             add_AT_flag (subr_die, DW_AT_reference, 1);
   24282              : 
   24283              :           /* If this is a C++11 non-static member function with &&
   24284              :              ref-qualifier then generate a DW_AT_reference attribute.  */
   24285         3216 :           if ((dwarf_version >= 5 || !dwarf_strict)
   24286     96483038 :               && lang_hooks.decls.decl_dwarf_attribute (decl,
   24287              :                                                         DW_AT_rvalue_reference)
   24288              :                  == 1)
   24289        61956 :             add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
   24290              :         }
   24291              :     }
   24292              :   /* For non DECL_EXTERNALs, if range information is available, fill
   24293              :      the DIE with it.  */
   24294      2852090 :   else if (!DECL_EXTERNAL (decl) && !early_dwarf)
   24295              :     {
   24296       575999 :       HOST_WIDE_INT cfa_fb_offset;
   24297              : 
   24298       575999 :       struct function *fun = DECL_STRUCT_FUNCTION (decl);
   24299              : 
   24300       575999 :       if (!crtl->has_bb_partition)
   24301              :         {
   24302       553359 :           dw_fde_ref fde = fun->fde;
   24303       553359 :           if (fde->dw_fde_begin)
   24304              :             {
   24305              :               /* We have already generated the labels.  */
   24306       553359 :              add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
   24307              :                                  fde->dw_fde_end, false);
   24308              :             }
   24309              :           else
   24310              :             {
   24311              :               /* Create start/end labels and add the range.  */
   24312            0 :               char label_id_low[MAX_ARTIFICIAL_LABEL_BYTES];
   24313            0 :               char label_id_high[MAX_ARTIFICIAL_LABEL_BYTES];
   24314            0 :               ASM_GENERATE_INTERNAL_LABEL (label_id_low, FUNC_BEGIN_LABEL,
   24315              :                                            current_function_funcdef_no);
   24316            0 :               ASM_GENERATE_INTERNAL_LABEL (label_id_high, FUNC_END_LABEL,
   24317              :                                            current_function_funcdef_no);
   24318            0 :              add_AT_low_high_pc (subr_die, label_id_low, label_id_high,
   24319              :                                  false);
   24320              :             }
   24321              : 
   24322              : #if VMS_DEBUGGING_INFO
   24323              :       /* HP OpenVMS Industry Standard 64: DWARF Extensions
   24324              :          Section 2.3 Prologue and Epilogue Attributes:
   24325              :          When a breakpoint is set on entry to a function, it is generally
   24326              :          desirable for execution to be suspended, not on the very first
   24327              :          instruction of the function, but rather at a point after the
   24328              :          function's frame has been set up, after any language defined local
   24329              :          declaration processing has been completed, and before execution of
   24330              :          the first statement of the function begins. Debuggers generally
   24331              :          cannot properly determine where this point is.  Similarly for a
   24332              :          breakpoint set on exit from a function. The prologue and epilogue
   24333              :          attributes allow a compiler to communicate the location(s) to use.  */
   24334              : 
   24335              :       {
   24336              :         if (fde->dw_fde_vms_end_prologue)
   24337              :           add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
   24338              :             fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
   24339              : 
   24340              :         if (fde->dw_fde_vms_begin_epilogue)
   24341              :           add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
   24342              :             fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
   24343              :       }
   24344              : #endif
   24345              : 
   24346              :         }
   24347              :       else
   24348              :         {
   24349              :           /* Generate pubnames entries for the split function code ranges.  */
   24350        22640 :           dw_fde_ref fde = fun->fde;
   24351              : 
   24352        22640 :           if (fde->dw_fde_second_begin)
   24353              :             {
   24354        22640 :               if (dwarf_version >= 3 || !dwarf_strict)
   24355              :                 {
   24356              :                   /* We should use ranges for non-contiguous code section
   24357              :                      addresses.  Use the actual code range for the initial
   24358              :                      section, since the HOT/COLD labels might precede an
   24359              :                      alignment offset.  */
   24360        22640 :                   bool range_list_added = false;
   24361        22640 :                   add_ranges_by_labels (subr_die, fde->dw_fde_begin,
   24362              :                                         fde->dw_fde_end, &range_list_added,
   24363              :                                         false);
   24364        22640 :                   add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
   24365              :                                         fde->dw_fde_second_end,
   24366              :                                         &range_list_added, false);
   24367        22640 :                   if (range_list_added)
   24368        22640 :                     add_ranges (NULL);
   24369        22640 :                 }
   24370              :               else
   24371              :                 {
   24372              :                   /* There is no real support in DW2 for this .. so we make
   24373              :                      a work-around.  First, emit the pub name for the segment
   24374              :                      containing the function label.  Then make and emit a
   24375              :                      simplified subprogram DIE for the second segment with the
   24376              :                      name pre-fixed by __hot/cold_sect_of_.  We use the same
   24377              :                      linkage name for the second die so that gdb will find both
   24378              :                      sections when given "b foo".  */
   24379            0 :                   const char *name = NULL;
   24380            0 :                   tree decl_name = DECL_NAME (decl);
   24381            0 :                   dw_die_ref seg_die;
   24382              : 
   24383              :                   /* Do the 'primary' section.   */
   24384            0 :                   add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
   24385              :                                       fde->dw_fde_end, false);
   24386              : 
   24387              :                   /* Build a minimal DIE for the secondary section.  */
   24388            0 :                   seg_die = new_die (DW_TAG_subprogram,
   24389              :                                      subr_die->die_parent, decl);
   24390              : 
   24391            0 :                   if (TREE_PUBLIC (decl))
   24392            0 :                     add_AT_flag (seg_die, DW_AT_external, 1);
   24393              : 
   24394            0 :                   if (decl_name != NULL
   24395            0 :                       && IDENTIFIER_POINTER (decl_name) != NULL)
   24396              :                     {
   24397            0 :                       name = dwarf2_name (decl, 1);
   24398            0 :                       if (! DECL_ARTIFICIAL (decl))
   24399            0 :                         add_src_coords_attributes (seg_die, decl);
   24400              : 
   24401            0 :                       add_linkage_name (seg_die, decl);
   24402              :                     }
   24403            0 :                   gcc_assert (name != NULL);
   24404            0 :                   add_pure_or_virtual_attribute (seg_die, decl);
   24405            0 :                   if (DECL_ARTIFICIAL (decl))
   24406            0 :                     add_AT_flag (seg_die, DW_AT_artificial, 1);
   24407              : 
   24408            0 :                   name = concat ("__second_sect_of_", name, NULL);
   24409            0 :                   add_AT_low_high_pc (seg_die, fde->dw_fde_second_begin,
   24410              :                                       fde->dw_fde_second_end, false);
   24411            0 :                   add_name_attribute (seg_die, name);
   24412            0 :                   if (want_pubnames ())
   24413            0 :                     add_pubname_string (name, seg_die);
   24414              :                 }
   24415              :             }
   24416              :           else
   24417            0 :            add_AT_low_high_pc (subr_die, fde->dw_fde_begin, fde->dw_fde_end,
   24418              :                                false);
   24419              :         }
   24420              : 
   24421       575999 :       cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
   24422              : 
   24423              :       /* We define the "frame base" as the function's CFA.  This is more
   24424              :          convenient for several reasons: (1) It's stable across the prologue
   24425              :          and epilogue, which makes it better than just a frame pointer,
   24426              :          (2) With dwarf3, there exists a one-byte encoding that allows us
   24427              :          to reference the .debug_frame data by proxy, but failing that,
   24428              :          (3) We can at least reuse the code inspection and interpretation
   24429              :          code that determines the CFA position at various points in the
   24430              :          function.  */
   24431       575999 :       if (dwarf_version >= 3 && targetm.debug_unwind_info () == UI_DWARF2)
   24432              :         {
   24433       572488 :           dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
   24434       572488 :           add_AT_loc (subr_die, DW_AT_frame_base, op);
   24435              :         }
   24436              :       else
   24437              :         {
   24438         3511 :           dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
   24439         3511 :           if (list->dw_loc_next)
   24440         1844 :             add_AT_loc_list (subr_die, DW_AT_frame_base, list);
   24441              :           else
   24442         1667 :             add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
   24443              :         }
   24444              : 
   24445              :       /* Compute a displacement from the "steady-state frame pointer" to
   24446              :          the CFA.  The former is what all stack slots and argument slots
   24447              :          will reference in the rtl; the latter is what we've told the
   24448              :          debugger about.  We'll need to adjust all frame_base references
   24449              :          by this displacement.  */
   24450       575999 :       compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
   24451              : 
   24452       575999 :       if (fun->static_chain_decl)
   24453              :         {
   24454              :           /* DWARF requires here a location expression that computes the
   24455              :              address of the enclosing subprogram's frame base.  The machinery
   24456              :              in tree-nested.cc is supposed to store this specific address in the
   24457              :              last field of the FRAME record.  */
   24458        14539 :           const tree frame_type
   24459        14539 :             = TREE_TYPE (TREE_TYPE (fun->static_chain_decl));
   24460        14539 :           const tree fb_decl = tree_last (TYPE_FIELDS (frame_type));
   24461              : 
   24462        14539 :           tree fb_expr
   24463        14539 :             = build1 (INDIRECT_REF, frame_type, fun->static_chain_decl);
   24464        14539 :           fb_expr = build3 (COMPONENT_REF, TREE_TYPE (fb_decl),
   24465              :                             fb_expr, fb_decl, NULL_TREE);
   24466              : 
   24467        14539 :           add_AT_location_description (subr_die, DW_AT_static_link,
   24468              :                                        loc_list_from_tree (fb_expr, 0, NULL));
   24469              :         }
   24470              : 
   24471       575999 :       resolve_variable_values ();
   24472              :     }
   24473              : 
   24474              :   /* Generate child dies for template parameters.  */
   24475     99331930 :   if (early_dwarf && debug_info_level > DINFO_LEVEL_TERSE)
   24476     98741972 :     gen_generic_params_dies (decl);
   24477              : 
   24478              :   /* Now output descriptions of the arguments for this function. This gets
   24479              :      (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
   24480              :      for a FUNCTION_DECL doesn't indicate cases where there was a trailing
   24481              :      `...' at the end of the formal parameter list.  In order to find out if
   24482              :      there was a trailing ellipsis or not, we must instead look at the type
   24483              :      associated with the FUNCTION_DECL.  This will be a node of type
   24484              :      FUNCTION_TYPE. If the chain of type nodes hanging off of this
   24485              :      FUNCTION_TYPE node ends with a void_type_node then there should *not* be
   24486              :      an ellipsis at the end.  */
   24487              : 
   24488              :   /* In the case where we are describing a mere function declaration, all we
   24489              :      need to do here (and all we *can* do here) is to describe the *types* of
   24490              :      its formal parameters.  */
   24491     99331930 :   if (debug_info_level <= DINFO_LEVEL_TERSE)
   24492              :     ;
   24493     99304817 :   else if (declaration)
   24494     96479644 :     gen_formal_types_die (decl, subr_die);
   24495              :   else
   24496              :     {
   24497              :       /* Generate DIEs to represent all known formal parameters.  */
   24498      2825173 :       tree parm = DECL_ARGUMENTS (decl);
   24499      2825173 :       tree generic_decl = early_dwarf
   24500      2825173 :         ? lang_hooks.decls.get_generic_function_decl (decl) : NULL;
   24501      2262345 :       tree generic_decl_parm = generic_decl
   24502      2262345 :                                 ? DECL_ARGUMENTS (generic_decl)
   24503      2825173 :                                 : NULL;
   24504              : 
   24505              :       /* Now we want to walk the list of parameters of the function and
   24506              :          emit their relevant DIEs.
   24507              : 
   24508              :          We consider the case of DECL being an instance of a generic function
   24509              :          as well as it being a normal function.
   24510              : 
   24511              :          If DECL is an instance of a generic function we walk the
   24512              :          parameters of the generic function declaration _and_ the parameters of
   24513              :          DECL itself. This is useful because we want to emit specific DIEs for
   24514              :          function parameter packs and those are declared as part of the
   24515              :          generic function declaration. In that particular case,
   24516              :          the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
   24517              :          That DIE has children DIEs representing the set of arguments
   24518              :          of the pack. Note that the set of pack arguments can be empty.
   24519              :          In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
   24520              :          children DIE.
   24521              : 
   24522              :          Otherwise, we just consider the parameters of DECL.  */
   24523      8072830 :       while (generic_decl_parm || parm)
   24524              :         {
   24525              :           if (generic_decl_parm
   24526      1209762 :               && lang_hooks.function_parameter_pack_p (generic_decl_parm))
   24527        99119 :             gen_formal_parameter_pack_die (generic_decl_parm,
   24528              :                                            parm, subr_die,
   24529              :                                            &parm);
   24530      5148538 :           else if (parm)
   24531              :             {
   24532      5148538 :               dw_die_ref parm_die = gen_decl_die (parm, NULL, NULL, subr_die);
   24533              : 
   24534      5148538 :               if (early_dwarf
   24535      4106449 :                   && parm == DECL_ARGUMENTS (decl)
   24536      2144774 :                   && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
   24537      1340106 :                   && parm_die
   24538      6488644 :                   && (dwarf_version >= 3 || !dwarf_strict))
   24539      1340106 :                 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
   24540              : 
   24541      5148538 :               parm = DECL_CHAIN (parm);
   24542              :             }
   24543              : 
   24544      5247657 :           if (generic_decl_parm)
   24545      1209762 :             generic_decl_parm = DECL_CHAIN (generic_decl_parm);
   24546              :         }
   24547              : 
   24548              :       /* Decide whether we need an unspecified_parameters DIE at the end.
   24549              :          There are 2 more cases to do this for: 1) the ansi ... declaration -
   24550              :          this is detectable when the end of the arg list is not a
   24551              :          void_type_node 2) an unprototyped function declaration (not a
   24552              :          definition).  This just means that we have no info about the
   24553              :          parameters at all.  */
   24554      2825173 :       if (early_dwarf)
   24555              :         {
   24556      2262345 :           if (prototype_p (TREE_TYPE (decl)))
   24557              :             {
   24558              :               /* This is the prototyped case, check for....  */
   24559      2260094 :               if (stdarg_p (TREE_TYPE (decl)))
   24560         4349 :                 gen_unspecified_parameters_die (decl, subr_die);
   24561              :             }
   24562         2251 :           else if (DECL_INITIAL (decl) == NULL_TREE)
   24563            0 :             gen_unspecified_parameters_die (decl, subr_die);
   24564              :         }
   24565       562828 :       else if ((subr_die != old_die || old_die_had_no_children)
   24566        80527 :                && prototype_p (TREE_TYPE (decl))
   24567       643039 :                && stdarg_p (TREE_TYPE (decl)))
   24568          158 :         gen_unspecified_parameters_die (decl, subr_die);
   24569              :     }
   24570              : 
   24571     99331930 :   if (subr_die != old_die)
   24572              :     /* Add the calling convention attribute if requested.  */
   24573     98780060 :     add_calling_convention_attribute (subr_die, decl);
   24574              : 
   24575              :   /* Output Dwarf info for all of the stuff within the body of the function
   24576              :      (if it has one - it may be just a declaration).
   24577              : 
   24578              :      OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
   24579              :      a function.  This BLOCK actually represents the outermost binding contour
   24580              :      for the function, i.e. the contour in which the function's formal
   24581              :      parameters and labels get declared. Curiously, it appears that the front
   24582              :      end doesn't actually put the PARM_DECL nodes for the current function onto
   24583              :      the BLOCK_VARS list for this outer scope, but are strung off of the
   24584              :      DECL_ARGUMENTS list for the function instead.
   24585              : 
   24586              :      The BLOCK_VARS list for the `outer_scope' does provide us with a list of
   24587              :      the LABEL_DECL nodes for the function however, and we output DWARF info
   24588              :      for those in decls_for_scope.  Just within the `outer_scope' there will be
   24589              :      a BLOCK node representing the function's outermost pair of curly braces,
   24590              :      and any blocks used for the base and member initializers of a C++
   24591              :      constructor function.  */
   24592     99331930 :   tree outer_scope = DECL_INITIAL (decl);
   24593     99331930 :   if (! declaration && outer_scope && TREE_CODE (outer_scope) != ERROR_MARK)
   24594              :     {
   24595      2832279 :       int call_site_note_count = 0;
   24596      2832279 :       int tail_call_site_note_count = 0;
   24597              : 
   24598              :       /* Emit a DW_TAG_variable DIE for a named return value.  */
   24599      2832279 :       if (DECL_NAME (DECL_RESULT (decl)))
   24600        10663 :         gen_decl_die (DECL_RESULT (decl), NULL, NULL, subr_die);
   24601              : 
   24602              :       /* The first time through decls_for_scope we will generate the
   24603              :          DIEs for the locals.  The second time, we fill in the
   24604              :          location info.  */
   24605      2832279 :       decls_for_scope (outer_scope, subr_die);
   24606              : 
   24607      2832279 :       if (call_arg_locations && (!dwarf_strict || dwarf_version >= 5))
   24608              :         {
   24609              :           struct call_arg_loc_node *ca_loc;
   24610      3761308 :           for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
   24611              :             {
   24612      3308939 :               dw_die_ref die = NULL;
   24613      3308939 :               rtx tloc = NULL_RTX, tlocc = NULL_RTX;
   24614      3308939 :               rtx call_arg_loc_note
   24615      3308939 :                 = find_reg_note (ca_loc->call_insn,
   24616              :                                  REG_CALL_ARG_LOCATION, NULL_RTX);
   24617      3308939 :               rtx arg, next_arg;
   24618      3308939 :               tree arg_decl = NULL_TREE;
   24619              : 
   24620      3308939 :               for (arg = (call_arg_loc_note != NULL_RTX
   24621      3308939 :                           ? XEXP (call_arg_loc_note, 0)
   24622              :                           : NULL_RTX);
   24623      6543189 :                    arg; arg = next_arg)
   24624              :                 {
   24625      3234250 :                   dw_loc_descr_ref reg, val;
   24626      3234250 :                   machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
   24627      3234250 :                   dw_die_ref cdie, tdie = NULL;
   24628              : 
   24629      3234250 :                   next_arg = XEXP (arg, 1);
   24630      3234250 :                   if (REG_P (XEXP (XEXP (arg, 0), 0))
   24631      3170260 :                       && next_arg
   24632      1415487 :                       && MEM_P (XEXP (XEXP (next_arg, 0), 0))
   24633         7709 :                       && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
   24634      3241928 :                       && REGNO (XEXP (XEXP (arg, 0), 0))
   24635         7678 :                          == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
   24636         7110 :                     next_arg = XEXP (next_arg, 1);
   24637      3234250 :                   if (mode == VOIDmode)
   24638              :                     {
   24639       570263 :                       mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
   24640       570263 :                       if (mode == VOIDmode)
   24641         1348 :                         mode = GET_MODE (XEXP (arg, 0));
   24642              :                     }
   24643      3234250 :                   if (mode == VOIDmode || mode == BLKmode)
   24644            0 :                     continue;
   24645              :                   /* Get dynamic information about call target only if we
   24646              :                      have no static information: we cannot generate both
   24647              :                      DW_AT_call_origin and DW_AT_call_target
   24648              :                      attributes.  */
   24649      3234250 :                   if (ca_loc->symbol_ref == NULL_RTX)
   24650              :                     {
   24651       121944 :                       if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
   24652              :                         {
   24653         5451 :                           tloc = XEXP (XEXP (arg, 0), 1);
   24654         5451 :                           continue;
   24655              :                         }
   24656       116493 :                       else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
   24657            0 :                                && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
   24658              :                         {
   24659            0 :                           tlocc = XEXP (XEXP (arg, 0), 1);
   24660            0 :                           continue;
   24661              :                         }
   24662              :                     }
   24663      3228799 :                   reg = NULL;
   24664      3228799 :                   if (REG_P (XEXP (XEXP (arg, 0), 0)))
   24665      3170260 :                     reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
   24666              :                                               VAR_INIT_STATUS_INITIALIZED);
   24667        58539 :                   else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
   24668              :                     {
   24669         1967 :                       rtx mem = XEXP (XEXP (arg, 0), 0);
   24670         1967 :                       reg = mem_loc_descriptor (XEXP (mem, 0),
   24671         1967 :                                                 get_address_mode (mem),
   24672         1967 :                                                 GET_MODE (mem),
   24673              :                                                 VAR_INIT_STATUS_INITIALIZED);
   24674              :                     }
   24675        56572 :                   else if (GET_CODE (XEXP (XEXP (arg, 0), 0))
   24676              :                            == DEBUG_PARAMETER_REF)
   24677              :                     {
   24678        56572 :                       tree tdecl
   24679              :                         = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg, 0), 0));
   24680        56572 :                       tdie = lookup_decl_die (tdecl);
   24681        56572 :                       if (tdie == NULL)
   24682            0 :                         continue;
   24683              :                       arg_decl = tdecl;
   24684              :                     }
   24685              :                   else
   24686            0 :                     continue;
   24687      3172227 :                   if (reg == NULL
   24688        56572 :                       && GET_CODE (XEXP (XEXP (arg, 0), 0))
   24689              :                          != DEBUG_PARAMETER_REF)
   24690            0 :                     continue;
   24691      3228799 :                   val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
   24692              :                                             VOIDmode,
   24693              :                                             VAR_INIT_STATUS_INITIALIZED);
   24694      3228799 :                   if (val == NULL)
   24695        95217 :                     continue;
   24696      3133582 :                   if (die == NULL)
   24697      1775191 :                     die = gen_call_site_die (decl, subr_die, ca_loc);
   24698      3135079 :                   cdie = new_die (dwarf_TAG (DW_TAG_call_site_parameter), die,
   24699              :                                   NULL_TREE);
   24700      3133582 :                   add_desc_attribute (cdie, arg_decl);
   24701      3133582 :                   if (reg != NULL)
   24702      3097793 :                     add_AT_loc (cdie, DW_AT_location, reg);
   24703        35789 :                   else if (tdie != NULL)
   24704        35789 :                     add_AT_die_ref (cdie, dwarf_AT (DW_AT_call_parameter),
   24705              :                                     tdie);
   24706      3135079 :                   add_AT_loc (cdie, dwarf_AT (DW_AT_call_value), val);
   24707      3133582 :                   if (next_arg != XEXP (arg, 1))
   24708              :                     {
   24709         7110 :                       mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
   24710         7110 :                       if (mode == VOIDmode)
   24711         5890 :                         mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
   24712         7110 :                       val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
   24713              :                                                             0), 1),
   24714              :                                                 mode, VOIDmode,
   24715              :                                                 VAR_INIT_STATUS_INITIALIZED);
   24716         7110 :                       if (val != NULL)
   24717         7110 :                         add_AT_loc (cdie, dwarf_AT (DW_AT_call_data_value),
   24718              :                                     val);
   24719              :                     }
   24720              :                 }
   24721      3308939 :               if (die == NULL
   24722      1533748 :                   && (ca_loc->symbol_ref || tloc))
   24723      1206138 :                 die = gen_call_site_die (decl, subr_die, ca_loc);
   24724      3308939 :               if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
   24725              :                 {
   24726         5451 :                   dw_loc_descr_ref tval = NULL;
   24727              : 
   24728         5451 :                   if (tloc != NULL_RTX)
   24729         5451 :                     tval = mem_loc_descriptor (tloc,
   24730         5451 :                                                GET_MODE (tloc) == VOIDmode
   24731         1348 :                                                ? Pmode : GET_MODE (tloc),
   24732              :                                                VOIDmode,
   24733              :                                                VAR_INIT_STATUS_INITIALIZED);
   24734         5451 :                   if (tval)
   24735         5459 :                     add_AT_loc (die, dwarf_AT (DW_AT_call_target), tval);
   24736            4 :                   else if (tlocc != NULL_RTX)
   24737              :                     {
   24738            0 :                       tval = mem_loc_descriptor (tlocc,
   24739            0 :                                                  GET_MODE (tlocc) == VOIDmode
   24740            0 :                                                  ? Pmode : GET_MODE (tlocc),
   24741              :                                                  VOIDmode,
   24742              :                                                  VAR_INIT_STATUS_INITIALIZED);
   24743            0 :                       if (tval)
   24744            0 :                         add_AT_loc (die,
   24745              :                                     dwarf_AT (DW_AT_call_target_clobbered),
   24746              :                                     tval);
   24747              :                     }
   24748              :                 }
   24749      2981329 :               if (die != NULL)
   24750              :                 {
   24751      2981329 :                   call_site_note_count++;
   24752      2981329 :                   if (ca_loc->tail_call_p)
   24753        57575 :                     tail_call_site_note_count++;
   24754              :                 }
   24755              :             }
   24756              :         }
   24757      2832279 :       call_arg_locations = NULL;
   24758      2832279 :       call_arg_loc_last = NULL;
   24759      2832279 :       if (tail_call_site_count >= 0
   24760       575999 :           && tail_call_site_count == tail_call_site_note_count
   24761       572590 :           && (!dwarf_strict || dwarf_version >= 5))
   24762              :         {
   24763       572574 :           if (call_site_count >= 0
   24764       572574 :               && call_site_count == call_site_note_count)
   24765       274792 :             add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_calls), 1);
   24766              :           else
   24767       301204 :             add_AT_flag (subr_die, dwarf_AT (DW_AT_call_all_tail_calls), 1);
   24768              :         }
   24769      2832279 :       call_site_count = -1;
   24770      2832279 :       tail_call_site_count = -1;
   24771              :     }
   24772              : 
   24773              :   /* Mark used types after we have created DIEs for the functions scopes.  */
   24774     99331930 :   premark_used_types (DECL_STRUCT_FUNCTION (decl));
   24775              : }
   24776              : 
   24777              : /* Returns a hash value for X (which really is a die_struct).  */
   24778              : 
   24779              : hashval_t
   24780         2918 : block_die_hasher::hash (die_struct *d)
   24781              : {
   24782         2918 :   return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
   24783              : }
   24784              : 
   24785              : /* Return true if decl_id and die_parent of die_struct X is the same
   24786              :    as decl_id and die_parent of die_struct Y.  */
   24787              : 
   24788              : bool
   24789         2275 : block_die_hasher::equal (die_struct *x, die_struct *y)
   24790              : {
   24791         2275 :   return x->decl_id == y->decl_id && x->die_parent == y->die_parent;
   24792              : }
   24793              : 
   24794              : /* Hold information about markers for inlined entry points.  */
   24795              : struct GTY ((for_user)) inline_entry_data
   24796              : {
   24797              :   /* The block that's the inlined_function_outer_scope for an inlined
   24798              :      function.  */
   24799              :   tree block;
   24800              : 
   24801              :   /* The label at the inlined entry point.  */
   24802              :   const char *label_pfx;
   24803              :   unsigned int label_num;
   24804              : 
   24805              :   /* The view number to be used as the inlined entry point.  */
   24806              :   var_loc_view view;
   24807              : };
   24808              : 
   24809              : struct inline_entry_data_hasher : ggc_ptr_hash <inline_entry_data>
   24810              : {
   24811              :   typedef tree compare_type;
   24812              :   static inline hashval_t hash (const inline_entry_data *);
   24813              :   static inline bool equal (const inline_entry_data *, const_tree);
   24814              : };
   24815              : 
   24816              : /* Hash table routines for inline_entry_data.  */
   24817              : 
   24818              : inline hashval_t
   24819     40615393 : inline_entry_data_hasher::hash (const inline_entry_data *data)
   24820              : {
   24821     40615393 :   return htab_hash_pointer (data->block);
   24822              : }
   24823              : 
   24824              : inline bool
   24825     49169887 : inline_entry_data_hasher::equal (const inline_entry_data *data,
   24826              :                                  const_tree block)
   24827              : {
   24828     49169887 :   return data->block == block;
   24829              : }
   24830              : 
   24831              : /* Inlined entry points pending DIE creation in this compilation unit.  */
   24832              : 
   24833              : static GTY(()) hash_table<inline_entry_data_hasher> *inline_entry_data_table;
   24834              : 
   24835              : 
   24836              : /* Return TRUE if DECL, which may have been previously generated as
   24837              :    OLD_DIE, is a candidate for a DW_AT_specification.  DECLARATION is
   24838              :    true if decl (or its origin) is either an extern declaration or a
   24839              :    class/namespace scoped declaration.
   24840              : 
   24841              :    The declare_in_namespace support causes us to get two DIEs for one
   24842              :    variable, both of which are declarations.  We want to avoid
   24843              :    considering one to be a specification, so we must test for
   24844              :    DECLARATION and DW_AT_declaration.  */
   24845              : static inline bool
   24846     85715843 : decl_will_get_specification_p (dw_die_ref old_die, tree decl, bool declaration)
   24847              : {
   24848     55329392 :   return (old_die && TREE_STATIC (decl) && !declaration
   24849    139824583 :           && get_AT_flag (old_die, DW_AT_declaration) == 1);
   24850              : }
   24851              : 
   24852              : /* Return true if DECL is a local static.  */
   24853              : 
   24854              : static inline bool
   24855     29509367 : local_function_static (tree decl)
   24856              : {
   24857     29509367 :   gcc_assert (VAR_P (decl));
   24858     29509367 :   return TREE_STATIC (decl)
   24859     28889920 :     && DECL_CONTEXT (decl)
   24860     58198378 :     && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
   24861              : }
   24862              : 
   24863              : /* Return true iff DECL overrides (presumably completes) the type of
   24864              :    OLD_DIE within CONTEXT_DIE.  */
   24865              : 
   24866              : static bool
   24867     26194854 : override_type_for_decl_p (tree decl, dw_die_ref old_die,
   24868              :                           dw_die_ref context_die)
   24869              : {
   24870     26194854 :   tree type = TREE_TYPE (decl);
   24871     26194854 :   int cv_quals;
   24872              : 
   24873     26194854 :   if (decl_by_reference_p (decl))
   24874              :     {
   24875            0 :       type = TREE_TYPE (type);
   24876            0 :       cv_quals = TYPE_UNQUALIFIED;
   24877              :     }
   24878              :   else
   24879     26194854 :     cv_quals = decl_quals (decl);
   24880              : 
   24881     26194854 :   dw_die_ref type_die
   24882     78584562 :     = modified_type_die (type,
   24883     26194854 :                          cv_quals | TYPE_QUALS (type),
   24884     26194854 :                          TYPE_ATTRIBUTES (type),
   24885              :                          false,
   24886              :                          context_die);
   24887              : 
   24888     26194854 :   dw_die_ref old_type_die = get_AT_ref (old_die, DW_AT_type);
   24889              : 
   24890     26194854 :   return type_die != old_type_die;
   24891              : }
   24892              : 
   24893              : /* Generate a DIE to represent a declared data object.
   24894              :    Either DECL or ORIGIN must be non-null.  */
   24895              : 
   24896              : static void
   24897     61481301 : gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
   24898              : {
   24899     61481301 :   HOST_WIDE_INT off = 0;
   24900     61481301 :   tree com_decl;
   24901     61481301 :   tree decl_or_origin = decl ? decl : origin;
   24902     61481286 :   tree ultimate_origin;
   24903     61481286 :   dw_die_ref var_die;
   24904     61481286 :   dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
   24905     61481301 :   bool declaration = (DECL_EXTERNAL (decl_or_origin)
   24906     61481301 :                       || class_or_namespace_scope_p (context_die));
   24907     61481301 :   bool specialization_p = false;
   24908     61481301 :   bool no_linkage_name = false;
   24909              : 
   24910              :   /* While C++ inline static data members have definitions inside of the
   24911              :      class, force the first DIE to be a declaration, then let gen_member_die
   24912              :      reparent it to the class context and call gen_variable_die again
   24913              :      to create the outside of the class DIE for the definition.  */
   24914     61481301 :   if (!declaration
   24915     61481301 :       && old_die == NULL
   24916     11922507 :       && decl
   24917     11922507 :       && DECL_CONTEXT (decl)
   24918     11724392 :       && TYPE_P (DECL_CONTEXT (decl))
   24919     69636049 :       && lang_hooks.decls.decl_dwarf_attribute (decl, DW_AT_inline) != -1)
   24920              :     {
   24921      8154745 :       declaration = true;
   24922      8154745 :       if (dwarf_version < 5)
   24923           32 :         no_linkage_name = true;
   24924              :     }
   24925              : 
   24926     61481301 :   ultimate_origin = decl_ultimate_origin (decl_or_origin);
   24927     61481301 :   if (decl || ultimate_origin)
   24928     61481286 :     origin = ultimate_origin;
   24929     61481301 :   com_decl = fortran_common (decl_or_origin, &off);
   24930              : 
   24931              :   /* Symbol in common gets emitted as a child of the common block, in the form
   24932              :      of a data member.  */
   24933     61481301 :   if (com_decl)
   24934              :     {
   24935         1060 :       dw_die_ref com_die;
   24936         1060 :       dw_loc_list_ref loc = NULL;
   24937         1060 :       die_node com_die_arg;
   24938              : 
   24939         1060 :       var_die = lookup_decl_die (decl_or_origin);
   24940         1060 :       if (var_die)
   24941              :         {
   24942          356 :           if (! early_dwarf && get_AT (var_die, DW_AT_location) == NULL)
   24943              :             {
   24944          416 :               loc = loc_list_from_tree (com_decl, off ? 1 : 2, NULL);
   24945          348 :               if (loc)
   24946              :                 {
   24947          348 :                   if (off)
   24948              :                     {
   24949              :                       /* Optimize the common case.  */
   24950          280 :                       if (single_element_loc_list_p (loc)
   24951          280 :                           && loc->expr->dw_loc_opc == DW_OP_addr
   24952          280 :                           && loc->expr->dw_loc_next == NULL
   24953          560 :                           && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
   24954              :                              == SYMBOL_REF)
   24955              :                         {
   24956          280 :                           rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
   24957          280 :                           loc->expr->dw_loc_oprnd1.v.val_addr
   24958          280 :                             = plus_constant (GET_MODE (x), x , off);
   24959              :                         }
   24960              :                       else
   24961            0 :                         loc_list_plus_const (loc, off);
   24962              :                     }
   24963          348 :                   add_AT_location_description (var_die, DW_AT_location, loc);
   24964          348 :                   remove_AT (var_die, DW_AT_declaration);
   24965              :                 }
   24966              :             }
   24967              :           return;
   24968              :         }
   24969              : 
   24970          704 :       if (common_block_die_table == NULL)
   24971           99 :         common_block_die_table = hash_table<block_die_hasher>::create_ggc (10);
   24972              : 
   24973          704 :       com_die_arg.decl_id = DECL_UID (com_decl);
   24974          704 :       com_die_arg.die_parent = context_die;
   24975          704 :       com_die = common_block_die_table->find (&com_die_arg);
   24976          704 :       if (! early_dwarf)
   24977            0 :         loc = loc_list_from_tree (com_decl, 2, NULL);
   24978          704 :       if (com_die == NULL)
   24979              :         {
   24980          247 :           const char *cnam
   24981          247 :             = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
   24982          247 :           die_node **slot;
   24983              : 
   24984          247 :           com_die = new_die (DW_TAG_common_block, context_die, decl);
   24985          247 :           add_name_and_src_coords_attributes (com_die, com_decl);
   24986          247 :           if (loc)
   24987              :             {
   24988            0 :               add_AT_location_description (com_die, DW_AT_location, loc);
   24989              :               /* Avoid sharing the same loc descriptor between
   24990              :                  DW_TAG_common_block and DW_TAG_variable.  */
   24991            0 :               loc = loc_list_from_tree (com_decl, 2, NULL);
   24992              :             }
   24993          247 :           else if (DECL_EXTERNAL (decl_or_origin))
   24994            7 :             add_AT_flag (com_die, DW_AT_declaration, 1);
   24995          247 :           if (want_pubnames ())
   24996            0 :             add_pubname_string (cnam, com_die); /* ??? needed? */
   24997          247 :           com_die->decl_id = DECL_UID (com_decl);
   24998          247 :           slot = common_block_die_table->find_slot (com_die, INSERT);
   24999          247 :           *slot = com_die;
   25000              :         }
   25001          457 :       else if (get_AT (com_die, DW_AT_location) == NULL && loc)
   25002              :         {
   25003            0 :           add_AT_location_description (com_die, DW_AT_location, loc);
   25004            0 :           loc = loc_list_from_tree (com_decl, 2, NULL);
   25005            0 :           remove_AT (com_die, DW_AT_declaration);
   25006              :         }
   25007          704 :       var_die = new_die (DW_TAG_variable, com_die, decl);
   25008          704 :       add_name_and_src_coords_attributes (var_die, decl_or_origin);
   25009          704 :       add_type_attribute (var_die, TREE_TYPE (decl_or_origin),
   25010              :                           decl_quals (decl_or_origin), false,
   25011              :                           context_die);
   25012          704 :       add_alignment_attribute (var_die, decl);
   25013          704 :       add_AT_flag (var_die, DW_AT_external, 1);
   25014          704 :       if (loc)
   25015              :         {
   25016            0 :           if (off)
   25017              :             {
   25018              :               /* Optimize the common case.  */
   25019            0 :               if (single_element_loc_list_p (loc)
   25020            0 :                   && loc->expr->dw_loc_opc == DW_OP_addr
   25021            0 :                   && loc->expr->dw_loc_next == NULL
   25022            0 :                   && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
   25023              :                 {
   25024            0 :                   rtx x = loc->expr->dw_loc_oprnd1.v.val_addr;
   25025            0 :                   loc->expr->dw_loc_oprnd1.v.val_addr
   25026            0 :                     = plus_constant (GET_MODE (x), x, off);
   25027              :                 }
   25028              :               else
   25029            0 :                 loc_list_plus_const (loc, off);
   25030              :             }
   25031            0 :           add_AT_location_description (var_die, DW_AT_location, loc);
   25032              :         }
   25033          704 :       else if (DECL_EXTERNAL (decl_or_origin))
   25034            8 :         add_AT_flag (var_die, DW_AT_declaration, 1);
   25035          704 :       if (decl)
   25036          704 :         equate_decl_number_to_die (decl, var_die);
   25037              :       return;
   25038              :     }
   25039              : 
   25040     61480241 :   if (old_die)
   25041              :     {
   25042     29446639 :       if (declaration)
   25043              :         {
   25044              :           /* A declaration that has been previously dumped, needs no
   25045              :              further annotations, since it doesn't need location on
   25046              :              the second pass.  */
   25047              :           return;
   25048              :         }
   25049     29134538 :       else if (decl_will_get_specification_p (old_die, decl, declaration)
   25050     29134538 :                && !get_AT (old_die, DW_AT_specification))
   25051              :         {
   25052              :           /* Fall-thru so we can make a new variable die along with a
   25053              :              DW_AT_specification.  */
   25054              :         }
   25055      2939684 :       else if (origin && old_die->die_parent != context_die)
   25056              :         {
   25057              :           /* If we will be creating an inlined instance, we need a
   25058              :              new DIE that will get annotated with
   25059              :              DW_AT_abstract_origin.  */
   25060        59766 :           gcc_assert (!DECL_ABSTRACT_P (decl));
   25061              :         }
   25062              :       else
   25063              :         {
   25064              :           /* If a DIE was dumped early, it still needs location info.
   25065              :              Skip to where we fill the location bits.  */
   25066      2879918 :           var_die = old_die;
   25067              : 
   25068              :           /* ???  In LTRANS we cannot annotate early created variably
   25069              :              modified type DIEs without copying them and adjusting all
   25070              :              references to them.  Thus we dumped them again.  Also add a
   25071              :              reference to them but beware of -g0 compile and -g link
   25072              :              in which case the reference will be already present.  */
   25073      2879918 :           tree type = TREE_TYPE (decl_or_origin);
   25074      2879918 :           if (in_lto_p
   25075         2969 :               && ! get_AT (var_die, DW_AT_type)
   25076      2882887 :               && variably_modified_type_p
   25077         2969 :                    (type, decl_function_context (decl_or_origin)))
   25078              :             {
   25079           45 :               if (decl_by_reference_p (decl_or_origin))
   25080            4 :                 add_type_attribute (var_die, TREE_TYPE (type),
   25081              :                                     TYPE_UNQUALIFIED, false, context_die);
   25082              :               else
   25083           41 :                 add_type_attribute (var_die, type, decl_quals (decl_or_origin),
   25084              :                                     false, context_die);
   25085              :             }
   25086              : 
   25087      2879918 :           goto gen_variable_die_location;
   25088              :         }
   25089              :     }
   25090              : 
   25091              :   /* For static data members, the declaration in the class is supposed
   25092              :      to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
   25093              :      also in DWARF2; the specification should still be DW_TAG_variable
   25094              :      referencing the DW_TAG_member DIE.  */
   25095     58288222 :   if (declaration && class_scope_p (context_die) && dwarf_version < 5)
   25096          120 :     var_die = new_die (DW_TAG_member, context_die, decl);
   25097              :   else
   25098     58288102 :     var_die = new_die (DW_TAG_variable, context_die, decl);
   25099              : 
   25100     58288222 :   if (origin != NULL)
   25101      1706917 :     add_abstract_origin_attribute (var_die, origin);
   25102              : 
   25103              :   /* Loop unrolling can create multiple blocks that refer to the same
   25104              :      static variable, so we must test for the DW_AT_declaration flag.
   25105              : 
   25106              :      ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
   25107              :      copy decls and set the DECL_ABSTRACT_P flag on them instead of
   25108              :      sharing them.
   25109              : 
   25110              :      ??? Duplicated blocks have been rewritten to use .debug_ranges.  */
   25111     56581305 :   else if (decl_will_get_specification_p (old_die, decl, declaration))
   25112              :     {
   25113              :       /* This is a definition of a C++ class level static.  */
   25114     26194854 :       add_AT_specification (var_die, old_die);
   25115     26194854 :       specialization_p = true;
   25116     26194854 :       if (DECL_NAME (decl))
   25117              :         {
   25118     26194835 :           expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
   25119     26194835 :           struct dwarf_file_data * file_index = lookup_filename (s.file);
   25120              : 
   25121     26194835 :           if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
   25122         4854 :             add_AT_file (var_die, DW_AT_decl_file, file_index);
   25123              : 
   25124     26194835 :           if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
   25125       142012 :             add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
   25126              : 
   25127     26194835 :           if (debug_column_info
   25128     26194835 :               && s.column
   25129     52389670 :               && (get_AT_unsigned (old_die, DW_AT_decl_column)
   25130     26194835 :                   != (unsigned) s.column))
   25131       141950 :             add_AT_unsigned (var_die, DW_AT_decl_column, s.column);
   25132              : 
   25133     26194835 :           if (old_die->die_tag == DW_TAG_member)
   25134           70 :             add_linkage_name (var_die, decl);
   25135              :         }
   25136              :     }
   25137              :   else
   25138     30386451 :     add_name_and_src_coords_attributes (var_die, decl, no_linkage_name);
   25139              : 
   25140     58288222 :   if ((origin == NULL && !specialization_p)
   25141     27901771 :       || (origin != NULL
   25142      1706917 :           && !DECL_ABSTRACT_P (decl_or_origin)
   25143      1706917 :           && variably_modified_type_p (TREE_TYPE (decl_or_origin),
   25144              :                                        decl_function_context
   25145              :                                        (decl_or_origin)))
   25146     86187076 :       || (old_die && specialization_p
   25147     26194854 :           && override_type_for_decl_p (decl_or_origin, old_die, context_die)))
   25148              :     {
   25149     30389626 :       tree type = TREE_TYPE (decl_or_origin);
   25150              : 
   25151     30389626 :       if (decl_by_reference_p (decl_or_origin))
   25152         1668 :         add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
   25153              :                             context_die);
   25154              :       else
   25155     30387958 :         add_type_attribute (var_die, type, decl_quals (decl_or_origin), false,
   25156              :                             context_die);
   25157              :     }
   25158              : 
   25159     58288222 :   if (origin == NULL && !specialization_p)
   25160              :     {
   25161     30386451 :       if (TREE_PUBLIC (decl))
   25162     28390308 :         add_AT_flag (var_die, DW_AT_external, 1);
   25163              : 
   25164     30386451 :       if (DECL_ARTIFICIAL (decl))
   25165       153189 :         add_AT_flag (var_die, DW_AT_artificial, 1);
   25166              : 
   25167     30386451 :       add_alignment_attribute (var_die, decl);
   25168              : 
   25169     30386451 :       add_accessibility_attribute (var_die, decl);
   25170              :     }
   25171              : 
   25172     58288222 :   if (declaration)
   25173     28266536 :     add_AT_flag (var_die, DW_AT_declaration, 1);
   25174              : 
   25175     58288222 :   if (decl && (DECL_ABSTRACT_P (decl)
   25176     58288207 :                || !old_die || is_declaration_die (old_die)))
   25177     58228441 :     equate_decl_number_to_die (decl, var_die);
   25178              : 
   25179     61168140 :  gen_variable_die_location:
   25180     61168140 :   if (! declaration
   25181     61168140 :       && (! DECL_ABSTRACT_P (decl_or_origin)
   25182              :           /* Local static vars are shared between all clones/inlines,
   25183              :              so emit DW_AT_location on the abstract DIE if DECL_RTL is
   25184              :              already set.  */
   25185            0 :           || (VAR_P (decl_or_origin)
   25186            0 :               && TREE_STATIC (decl_or_origin)
   25187            0 :               && DECL_RTL_SET_P (decl_or_origin))))
   25188              :     {
   25189     32901604 :       if (early_dwarf)
   25190              :         {
   25191     30020934 :           add_pubname (decl_or_origin, var_die);
   25192              :           /* For global register variables, emit DW_AT_location if possible
   25193              :              already during early_dwarf, as late_global_decl won't be usually
   25194              :              called.  */
   25195     30020934 :           if (DECL_HARD_REGISTER (decl_or_origin)
   25196           76 :               && TREE_STATIC (decl_or_origin)
   25197           12 :               && !decl_by_reference_p (decl_or_origin)
   25198           12 :               && !get_AT (var_die, DW_AT_location)
   25199            6 :               && !get_AT (var_die, DW_AT_const_value)
   25200            6 :               && DECL_RTL_SET_P (decl_or_origin)
   25201     30020940 :               && REG_P (DECL_RTL (decl_or_origin)))
   25202              :             {
   25203            6 :               dw_loc_descr_ref descr
   25204            6 :                 = reg_loc_descriptor (DECL_RTL (decl_or_origin),
   25205              :                                       VAR_INIT_STATUS_INITIALIZED);
   25206            6 :               if (descr)
   25207            6 :                 add_AT_loc (var_die, DW_AT_location, descr);
   25208              :             }
   25209              :         }
   25210              :       else
   25211      2880670 :         add_location_or_const_value_attribute (var_die, decl_or_origin,
   25212              :                                                decl == NULL);
   25213              :     }
   25214              :   else
   25215     28266536 :     tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
   25216              : 
   25217         9113 :   if ((dwarf_version >= 4 || !dwarf_strict)
   25218     61168140 :       && lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
   25219              :                                                 DW_AT_const_expr) == 1
   25220     52952322 :       && !get_AT (var_die, DW_AT_const_expr)
   25221     86970069 :       && !specialization_p)
   25222     25675152 :     add_AT_flag (var_die, DW_AT_const_expr, 1);
   25223              : 
   25224     61168140 :   if (!dwarf_strict)
   25225              :     {
   25226     61168138 :       int inl = lang_hooks.decls.decl_dwarf_attribute (decl_or_origin,
   25227              :                                                        DW_AT_inline);
   25228     61168138 :       if (inl != -1
   25229     51496976 :           && !get_AT (var_die, DW_AT_inline)
   25230     86251328 :           && !specialization_p)
   25231     24946924 :         add_AT_unsigned (var_die, DW_AT_inline, inl);
   25232              :     }
   25233              : }
   25234              : 
   25235              : /* Generate a DIE to represent a named constant.  */
   25236              : 
   25237              : static void
   25238        26722 : gen_const_die (tree decl, dw_die_ref context_die)
   25239              : {
   25240        26722 :   dw_die_ref const_die;
   25241        26722 :   tree type = TREE_TYPE (decl);
   25242              : 
   25243        26722 :   const_die = lookup_decl_die (decl);
   25244        26722 :   if (const_die)
   25245              :     return;
   25246              : 
   25247        19618 :   const_die = new_die (DW_TAG_constant, context_die, decl);
   25248        19618 :   equate_decl_number_to_die (decl, const_die);
   25249        19618 :   add_name_and_src_coords_attributes (const_die, decl);
   25250        19618 :   add_type_attribute (const_die, type, TYPE_QUAL_CONST, false, context_die);
   25251        19618 :   if (TREE_PUBLIC (decl))
   25252          370 :     add_AT_flag (const_die, DW_AT_external, 1);
   25253        19618 :   if (DECL_ARTIFICIAL (decl))
   25254            0 :     add_AT_flag (const_die, DW_AT_artificial, 1);
   25255        19618 :   tree_add_const_value_attribute_for_decl (const_die, decl);
   25256              : }
   25257              : 
   25258              : /* Generate a DIE to represent a label identifier.  */
   25259              : 
   25260              : static void
   25261       106800 : gen_label_die (tree decl, dw_die_ref context_die)
   25262              : {
   25263       106800 :   tree origin = decl_ultimate_origin (decl);
   25264       106800 :   dw_die_ref lbl_die = lookup_decl_die (decl);
   25265       106800 :   rtx insn;
   25266       106800 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
   25267              : 
   25268       106800 :   if (!lbl_die)
   25269              :     {
   25270        64419 :       lbl_die = new_die (DW_TAG_label, context_die, decl);
   25271        64419 :       equate_decl_number_to_die (decl, lbl_die);
   25272              : 
   25273        64419 :       if (origin != NULL)
   25274        16097 :         add_abstract_origin_attribute (lbl_die, origin);
   25275              :       else
   25276        48322 :         add_name_and_src_coords_attributes (lbl_die, decl);
   25277              :     }
   25278              : 
   25279       106800 :   if (DECL_ABSTRACT_P (decl))
   25280            0 :     equate_decl_number_to_die (decl, lbl_die);
   25281       106800 :   else if (! early_dwarf)
   25282              :     {
   25283        58478 :       insn = DECL_RTL_IF_SET (decl);
   25284              : 
   25285              :       /* Deleted labels are programmer specified labels which have been
   25286              :          eliminated because of various optimizations.  We still emit them
   25287              :          here so that it is possible to put breakpoints on them.  */
   25288        48577 :       if (insn
   25289        48577 :           && (LABEL_P (insn)
   25290        26950 :               || ((NOTE_P (insn)
   25291        26950 :                    && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
   25292              :         {
   25293              :           /* When optimization is enabled (via -O) some parts of the compiler
   25294              :              (e.g. jump.cc and cse.cc) may try to delete CODE_LABEL insns which
   25295              :              represent source-level labels which were explicitly declared by
   25296              :              the user.  This really shouldn't be happening though, so catch
   25297              :              it if it ever does happen.  */
   25298        41734 :           gcc_assert (!as_a<rtx_insn *> (insn)->deleted ());
   25299              : 
   25300        41734 :           ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
   25301        41734 :           add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
   25302        41734 :         }
   25303              :       else if (insn
   25304         6843 :                && NOTE_P (insn)
   25305         6843 :                && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL
   25306         6843 :                && CODE_LABEL_NUMBER (insn) != -1)
   25307              :         {
   25308         6843 :           ASM_GENERATE_INTERNAL_LABEL (label, "LDL", CODE_LABEL_NUMBER (insn));
   25309         6843 :           add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
   25310              :         }
   25311              :     }
   25312       106800 : }
   25313              : 
   25314              : /* A helper function for gen_inlined_subroutine_die.  Add source coordinate
   25315              :    attributes to the DIE for a block STMT, to describe where the inlined
   25316              :    function was called from.  This is similar to add_src_coords_attributes.  */
   25317              : 
   25318              : static inline void
   25319      7143655 : add_call_src_coords_attributes (tree stmt, dw_die_ref die)
   25320              : {
   25321              :   /* We can end up with BUILTINS_LOCATION here.  */
   25322      7143655 :   if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt)))
   25323           71 :     return;
   25324              : 
   25325      7143584 :   location_t locus = BLOCK_SOURCE_LOCATION (stmt);
   25326      7143584 :   expanded_location s = expand_location (locus);
   25327              : 
   25328      7143584 :   if (dwarf_version >= 3 || !dwarf_strict)
   25329              :     {
   25330      7143584 :       add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
   25331      7143584 :       add_AT_unsigned (die, DW_AT_call_line, s.line);
   25332      7143584 :       if (debug_column_info && s.column)
   25333      7135535 :         add_AT_unsigned (die, DW_AT_call_column, s.column);
   25334      7143584 :       unsigned discr = get_discriminator_from_loc (locus);
   25335      7143584 :         if (discr != 0)
   25336      2250792 :           add_AT_unsigned (die, DW_AT_GNU_discriminator, discr);
   25337              :     }
   25338              : }
   25339              : 
   25340              : 
   25341              : /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
   25342              :    Add low_pc and high_pc attributes to the DIE for a block STMT.  */
   25343              : 
   25344              : static inline void
   25345      7767158 : add_high_low_attributes (tree stmt, dw_die_ref die)
   25346              : {
   25347      7767158 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
   25348              : 
   25349      7356068 :   if (inline_entry_data **iedp
   25350      7767158 :       = !inline_entry_data_table ? NULL
   25351      7356068 :       : inline_entry_data_table->find_slot_with_hash (stmt,
   25352              :                                                       htab_hash_pointer (stmt),
   25353              :                                                       NO_INSERT))
   25354              :     {
   25355      6911054 :       inline_entry_data *ied = *iedp;
   25356      6911054 :       gcc_assert (MAY_HAVE_DEBUG_MARKER_INSNS);
   25357      6911054 :       gcc_assert (debug_inline_points);
   25358      6911054 :       gcc_assert (inlined_function_outer_scope_p (stmt));
   25359              : 
   25360      6911054 :       ASM_GENERATE_INTERNAL_LABEL (label, ied->label_pfx, ied->label_num);
   25361      6911054 :       add_AT_lbl_id (die, DW_AT_entry_pc, label);
   25362              : 
   25363      6911054 :       if (debug_variable_location_views && !ZERO_VIEW_P (ied->view)
   25364     13821833 :           && !dwarf_strict)
   25365              :         {
   25366      6910779 :           if (!output_asm_line_debug_info ())
   25367          434 :             add_AT_unsigned (die, DW_AT_GNU_entry_view, ied->view);
   25368              :           else
   25369              :             {
   25370      6910345 :               ASM_GENERATE_INTERNAL_LABEL (label, "LVU", ied->view);
   25371              :               /* FIXME: this will resolve to a small number.  Could we
   25372              :                  possibly emit smaller data?  Ideally we'd emit a
   25373              :                  uleb128, but that would make the size of DIEs
   25374              :                  impossible for the compiler to compute, since it's
   25375              :                  the assembler that computes the value of the view
   25376              :                  label in this case.  Ideally, we'd have a single form
   25377              :                  encompassing both the address and the view, and
   25378              :                  indirecting them through a table might make things
   25379              :                  easier, but even that would be more wasteful,
   25380              :                  space-wise, than what we have now.  */
   25381      6910345 :               add_AT_symview (die, DW_AT_GNU_entry_view, label);
   25382              :             }
   25383              :         }
   25384              : 
   25385      6911054 :       inline_entry_data_table->clear_slot (iedp);
   25386              :     }
   25387              : 
   25388      7767158 :   if (BLOCK_FRAGMENT_CHAIN (stmt)
   25389      7767158 :       && (dwarf_version >= 3 || !dwarf_strict))
   25390              :     {
   25391      3446171 :       tree chain, superblock = NULL_TREE;
   25392      3446171 :       dw_die_ref pdie;
   25393      3446171 :       dw_attr_node *attr = NULL;
   25394              : 
   25395      3446171 :       if (!debug_inline_points && inlined_function_outer_scope_p (stmt))
   25396              :         {
   25397           99 :           ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
   25398              :                                        BLOCK_NUMBER (stmt));
   25399           99 :           add_AT_lbl_id (die, DW_AT_entry_pc, label);
   25400              :         }
   25401              : 
   25402              :       /* Optimize duplicate .debug_ranges lists or even tails of
   25403              :          lists.  If this BLOCK has same ranges as its supercontext,
   25404              :          lookup DW_AT_ranges attribute in the supercontext (and
   25405              :          recursively so), verify that the ranges_table contains the
   25406              :          right values and use it instead of adding a new .debug_range.  */
   25407      3446171 :       for (chain = stmt, pdie = die;
   25408      5665539 :            BLOCK_SAME_RANGE (chain);
   25409      2219368 :            chain = BLOCK_SUPERCONTEXT (chain))
   25410              :         {
   25411      2325110 :           dw_attr_node *new_attr;
   25412              : 
   25413      2325110 :           pdie = pdie->die_parent;
   25414      2325110 :           if (pdie == NULL)
   25415              :             break;
   25416      2325110 :           if (BLOCK_SUPERCONTEXT (chain) == NULL_TREE)
   25417              :             break;
   25418      2325110 :           new_attr = get_AT (pdie, DW_AT_ranges);
   25419      2325110 :           if (new_attr == NULL
   25420      2219368 :               || new_attr->dw_attr_val.val_class != dw_val_class_range_list)
   25421              :             break;
   25422      2219368 :           attr = new_attr;
   25423      2219368 :           superblock = BLOCK_SUPERCONTEXT (chain);
   25424              :         }
   25425      3446171 :       if (attr != NULL
   25426      1020422 :           && ((*ranges_table)[attr->dw_attr_val.v.val_offset].num
   25427      1020422 :               == (int)BLOCK_NUMBER (superblock))
   25428      4040880 :           && BLOCK_FRAGMENT_CHAIN (superblock))
   25429              :         {
   25430              :           unsigned long off = attr->dw_attr_val.v.val_offset;
   25431      1726747 :           unsigned long supercnt = 0, thiscnt = 0;
   25432      2858785 :           for (chain = BLOCK_FRAGMENT_CHAIN (superblock);
   25433      1726747 :                chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
   25434              :             {
   25435      1132038 :               ++supercnt;
   25436      1132038 :               gcc_checking_assert ((*ranges_table)[off + supercnt].num
   25437              :                                    == (int)BLOCK_NUMBER (chain));
   25438              :             }
   25439       594709 :           gcc_checking_assert ((*ranges_table)[off + supercnt + 1].num == 0);
   25440       594709 :           for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
   25441      1707442 :                chain; chain = BLOCK_FRAGMENT_CHAIN (chain))
   25442      1112733 :             ++thiscnt;
   25443       594709 :           gcc_assert (supercnt >= thiscnt);
   25444       594709 :           add_AT_range_list (die, DW_AT_ranges, off + supercnt - thiscnt,
   25445              :                              false);
   25446       594709 :           note_rnglist_head (off + supercnt - thiscnt);
   25447       594709 :           return;
   25448              :         }
   25449              : 
   25450      2851462 :       unsigned int offset = add_ranges (stmt, true);
   25451      2851462 :       add_AT_range_list (die, DW_AT_ranges, offset, false);
   25452      2851462 :       note_rnglist_head (offset);
   25453              : 
   25454      2851462 :       bool prev_in_cold = BLOCK_IN_COLD_SECTION_P (stmt);
   25455      2851462 :       chain = BLOCK_FRAGMENT_CHAIN (stmt);
   25456      5749593 :       do
   25457              :         {
   25458      5749593 :           add_ranges (chain, prev_in_cold != BLOCK_IN_COLD_SECTION_P (chain));
   25459      5749593 :           prev_in_cold = BLOCK_IN_COLD_SECTION_P (chain);
   25460      5749593 :           chain = BLOCK_FRAGMENT_CHAIN (chain);
   25461              :         }
   25462      5749593 :       while (chain);
   25463      2851462 :       add_ranges (NULL);
   25464              :     }
   25465              :   else
   25466              :     {
   25467      4320987 :       char label_high[MAX_ARTIFICIAL_LABEL_BYTES];
   25468      4320987 :       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
   25469              :                                    BLOCK_NUMBER (stmt));
   25470      4320987 :       ASM_GENERATE_INTERNAL_LABEL (label_high, BLOCK_END_LABEL,
   25471              :                                    BLOCK_NUMBER (stmt));
   25472      4320987 :       add_AT_low_high_pc (die, label, label_high, false);
   25473              :     }
   25474              : }
   25475              : 
   25476              : /* Generate a DIE for a lexical block.  */
   25477              : 
   25478              : static void
   25479      1070517 : gen_lexical_block_die (tree stmt, dw_die_ref context_die)
   25480              : {
   25481      1070517 :   dw_die_ref old_die = lookup_block_die (stmt);
   25482      1070517 :   dw_die_ref stmt_die = NULL;
   25483      1070517 :   if (!old_die)
   25484              :     {
   25485       807175 :       stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
   25486       807175 :       equate_block_to_die (stmt, stmt_die);
   25487              :     }
   25488              : 
   25489      1070517 :   if (BLOCK_ABSTRACT_ORIGIN (stmt))
   25490              :     {
   25491              :       /* If this is an inlined or concrete instance, create a new lexical
   25492              :          die for anything below to attach DW_AT_abstract_origin to.  */
   25493       390887 :       if (old_die)
   25494        11036 :         stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
   25495              : 
   25496       390887 :       tree origin = block_ultimate_origin (stmt);
   25497       390887 :       if (origin != NULL_TREE && (origin != stmt || old_die))
   25498       390136 :         add_abstract_origin_attribute (stmt_die, origin);
   25499              : 
   25500              :       old_die = NULL;
   25501              :     }
   25502              : 
   25503      1069766 :   if (old_die)
   25504       252306 :     stmt_die = old_die;
   25505              : 
   25506              :   /* A non abstract block whose blocks have already been reordered
   25507              :      should have the instruction range for this block.  If so, set the
   25508              :      high/low attributes.  */
   25509      1070517 :   if (!early_dwarf && TREE_ASM_WRITTEN (stmt))
   25510              :     {
   25511       623503 :       gcc_assert (stmt_die);
   25512       623503 :       add_high_low_attributes (stmt, stmt_die);
   25513              :     }
   25514              : 
   25515      1070517 :   decls_for_scope (stmt, stmt_die);
   25516      1070517 : }
   25517              : 
   25518              : /* Generate a DIE for an inlined subprogram.  */
   25519              : 
   25520              : static void
   25521      7143655 : gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
   25522              : {
   25523      7143655 :   tree decl = block_ultimate_origin (stmt);
   25524              : 
   25525              :   /* Make sure any inlined functions are known to be inlineable.  */
   25526      7143655 :   gcc_checking_assert (DECL_ABSTRACT_P (decl)
   25527              :                        || cgraph_function_possibly_inlined_p (decl));
   25528              : 
   25529      7143655 :   dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
   25530              : 
   25531      7143655 :   if (call_arg_locations || debug_inline_points)
   25532      7135634 :     equate_block_to_die (stmt, subr_die);
   25533      7143655 :   add_abstract_origin_attribute (subr_die, decl);
   25534      7143655 :   if (TREE_ASM_WRITTEN (stmt))
   25535      7143655 :     add_high_low_attributes (stmt, subr_die);
   25536      7143655 :   add_call_src_coords_attributes (stmt, subr_die);
   25537              : 
   25538              :   /* The inliner creates an extra BLOCK for the parameter setup,
   25539              :      we want to merge that with the actual outermost BLOCK of the
   25540              :      inlined function to avoid duplicate locals in consumers.
   25541              :      Do that by doing the recursion to subblocks on the single subblock
   25542              :      of STMT.  */
   25543      7143655 :   bool unwrap_one = false;
   25544      7143655 :   tree sub = BLOCK_SUBBLOCKS (stmt);
   25545      7143655 :   if (sub)
   25546              :     {
   25547      5662376 :       tree origin = block_ultimate_origin (sub);
   25548      5662376 :       if (origin
   25549      5662376 :           && TREE_CODE (origin) == BLOCK
   25550      9206407 :           && BLOCK_SUPERCONTEXT (origin) == decl)
   25551              :         unwrap_one = true;
   25552      9121386 :       for (tree next = BLOCK_CHAIN (sub); unwrap_one && next;
   25553      3459010 :            next = BLOCK_CHAIN (next))
   25554      3459010 :         if (BLOCK_FRAGMENT_ORIGIN (next) != sub)
   25555         7217 :           unwrap_one = false;
   25556              :     }
   25557      7143655 :   decls_for_scope (stmt, subr_die, !unwrap_one);
   25558      7143655 :   if (unwrap_one)
   25559              :     {
   25560      3422858 :       decls_for_scope (sub, subr_die);
   25561      6867068 :       for (sub = BLOCK_CHAIN (sub); sub; sub = BLOCK_CHAIN (sub))
   25562      3444210 :         gen_block_die (sub, subr_die);
   25563              :     }
   25564      7143655 : }
   25565              : 
   25566              : /* Generate a DIE for a field in a record, or structure.  CTX is required: see
   25567              :    the comment for VLR_CONTEXT.  */
   25568              : 
   25569              : static void
   25570     16518822 : gen_field_die (tree decl, struct vlr_context *ctx, dw_die_ref context_die)
   25571              : {
   25572     16518822 :   dw_die_ref decl_die;
   25573              : 
   25574     16518822 :   if (TREE_TYPE (decl) == error_mark_node)
   25575              :     return;
   25576              : 
   25577     16518822 :   decl_die = new_die (DW_TAG_member, context_die, decl);
   25578     16518822 :   add_name_and_src_coords_attributes (decl_die, decl);
   25579     33037644 :   add_type_attribute (decl_die, member_declared_type (decl), decl_quals (decl),
   25580     16518822 :                       TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl)),
   25581              :                       context_die);
   25582              : 
   25583     16518822 :   if (DECL_BIT_FIELD_TYPE (decl))
   25584              :     {
   25585       513721 :       add_byte_size_attribute (decl_die, decl);
   25586       513721 :       add_bit_size_attribute (decl_die, decl);
   25587       513721 :       add_bit_offset_attribute (decl_die, decl);
   25588              :     }
   25589              : 
   25590     16518822 :   add_alignment_attribute (decl_die, decl);
   25591              : 
   25592     16518822 :   if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
   25593     15001884 :     add_data_member_location_attribute (decl_die, decl, ctx);
   25594              : 
   25595     16518822 :   if (DECL_ARTIFICIAL (decl))
   25596        57715 :     add_AT_flag (decl_die, DW_AT_artificial, 1);
   25597              : 
   25598     16518822 :   add_accessibility_attribute (decl_die, decl);
   25599              : 
   25600              :   /* Add DW_AT_export_symbols to anonymous unions or structs.  */
   25601     16518822 :   if ((dwarf_version >= 5 || !dwarf_strict) && DECL_NAME (decl) == NULL_TREE)
   25602       204820 :     if (tree type = member_declared_type (decl))
   25603       204820 :       if (lang_hooks.types.type_dwarf_attribute (TYPE_MAIN_VARIANT (type),
   25604              :                                                  DW_AT_export_symbols) != -1)
   25605              :         {
   25606       204720 :           dw_die_ref type_die = lookup_type_die (TYPE_MAIN_VARIANT (type));
   25607       204720 :           if (type_die && get_AT (type_die, DW_AT_export_symbols) == NULL)
   25608       204720 :             add_AT_flag (type_die, DW_AT_export_symbols, 1);
   25609              :         }
   25610              : 
   25611              :   /* Equate decl number to die, so that we can look up this decl later on.  */
   25612     16518822 :   equate_decl_number_to_die (decl, decl_die);
   25613              : }
   25614              : 
   25615              : /* Generate a DIE for a pointer to a member type.  TYPE can be an
   25616              :    OFFSET_TYPE, for a pointer to data member, or a RECORD_TYPE, for a
   25617              :    pointer to member function.  */
   25618              : 
   25619              : static void
   25620        31003 : gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
   25621              : {
   25622        31003 :   if (lookup_type_die (type))
   25623              :     return;
   25624              : 
   25625        31003 :   dw_die_ref ptr_die = new_die (DW_TAG_ptr_to_member_type,
   25626              :                                 scope_die_for (type, context_die), type);
   25627              : 
   25628        31003 :   equate_type_number_to_die (type, ptr_die);
   25629        62006 :   add_AT_die_ref (ptr_die, DW_AT_containing_type,
   25630        31003 :                   lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
   25631        31003 :   add_type_attribute (ptr_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
   25632              :                       context_die);
   25633        31003 :   add_alignment_attribute (ptr_die, type);
   25634              : 
   25635        31003 :   if (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
   25636        31003 :       && TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)
   25637              :     {
   25638          484 :       dw_loc_descr_ref op = new_loc_descr (DW_OP_plus, 0, 0);
   25639          484 :       add_AT_loc (ptr_die, DW_AT_use_location, op);
   25640              :     }
   25641              : }
   25642              : 
   25643              : static char *producer_string;
   25644              : 
   25645              : /* Given a C and/or C++ language/version string return the "highest".
   25646              :    C++ is assumed to be "higher" than C in this case.  Used for merging
   25647              :    LTO translation unit languages.  */
   25648              : static const char *
   25649            1 : highest_c_language (const char *lang1, const char *lang2)
   25650              : {
   25651            1 :   if (strcmp ("GNU C++29", lang1) == 0 || strcmp ("GNU C++29", lang2) == 0)
   25652              :     return "GNU C++29";
   25653            1 :   if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
   25654              :     return "GNU C++26";
   25655            1 :   if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
   25656              :     return "GNU C++23";
   25657            1 :   if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
   25658              :     return "GNU C++20";
   25659            0 :   if (strcmp ("GNU C++17", lang1) == 0 || strcmp ("GNU C++17", lang2) == 0)
   25660              :     return "GNU C++17";
   25661            0 :   if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0)
   25662              :     return "GNU C++14";
   25663            0 :   if (strcmp ("GNU C++11", lang1) == 0 || strcmp ("GNU C++11", lang2) == 0)
   25664              :     return "GNU C++11";
   25665            0 :   if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
   25666              :     return "GNU C++98";
   25667              : 
   25668            0 :   if (strcmp ("GNU C2Y", lang1) == 0 || strcmp ("GNU C2Y", lang2) == 0)
   25669              :     return "GNU C2Y";
   25670            0 :   if (strcmp ("GNU C23", lang1) == 0 || strcmp ("GNU C23", lang2) == 0)
   25671              :     return "GNU C23";
   25672            0 :   if (strcmp ("GNU C17", lang1) == 0 || strcmp ("GNU C17", lang2) == 0)
   25673              :     return "GNU C17";
   25674            0 :   if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
   25675              :     return "GNU C11";
   25676            0 :   if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
   25677              :     return "GNU C99";
   25678            0 :   if (strcmp ("GNU C89", lang1) == 0 || strcmp ("GNU C89", lang2) == 0)
   25679              :     return "GNU C89";
   25680              : 
   25681            0 :   gcc_unreachable ();
   25682              : }
   25683              : 
   25684              : 
   25685              : /* Generate the DIE for the compilation unit.  */
   25686              : 
   25687              : static dw_die_ref
   25688        58454 : gen_compile_unit_die (const char *filename)
   25689              : {
   25690        58454 :   dw_die_ref die;
   25691        58454 :   const char *language_string = lang_hooks.name;
   25692        58454 :   int language, lname, lversion;
   25693              : 
   25694        58454 :   die = new_die (DW_TAG_compile_unit, NULL, NULL);
   25695              : 
   25696        58454 :   if (filename)
   25697              :     {
   25698            0 :       add_filename_attribute (die, filename);
   25699              :       /* Don't add cwd for <built-in>.  */
   25700            0 :       if (filename[0] != '<')
   25701            0 :         add_comp_dir_attribute (die);
   25702              :     }
   25703              : 
   25704        58703 :   add_AT_string (die, DW_AT_producer, producer_string ? producer_string : "");
   25705              : 
   25706              :   /* If our producer is LTO try to figure out a common language to use
   25707              :      from the global list of translation units.  */
   25708        58454 :   if (strcmp (language_string, "GNU GIMPLE") == 0)
   25709              :     {
   25710              :       unsigned i;
   25711              :       tree t;
   25712              :       const char *common_lang = NULL;
   25713              : 
   25714         1549 :       FOR_EACH_VEC_SAFE_ELT (all_translation_units, i, t)
   25715              :         {
   25716          786 :           if (!TRANSLATION_UNIT_LANGUAGE (t))
   25717            0 :             continue;
   25718          786 :           if (!common_lang)
   25719              :             common_lang = TRANSLATION_UNIT_LANGUAGE (t);
   25720           23 :           else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
   25721              :             ;
   25722            1 :           else if (startswith (common_lang, "GNU C")
   25723            1 :                     && startswith (TRANSLATION_UNIT_LANGUAGE (t), "GNU C"))
   25724              :             /* Mixing C and C++ is ok, use C++ in that case.  */
   25725            1 :             common_lang = highest_c_language (common_lang,
   25726            1 :                                               TRANSLATION_UNIT_LANGUAGE (t));
   25727              :           else
   25728              :             {
   25729              :               /* Fall back to C.  */
   25730              :               common_lang = NULL;
   25731              :               break;
   25732              :             }
   25733              :         }
   25734              : 
   25735          763 :       if (common_lang)
   25736        58454 :         language_string = common_lang;
   25737              :     }
   25738              : 
   25739        58454 :   language = DW_LANG_C;
   25740        58454 :   lname = 0;
   25741        58454 :   lversion = 0;
   25742        58454 :   if (startswith (language_string, "GNU C")
   25743        58454 :       && ISDIGIT (language_string[5]))
   25744              :     {
   25745        24328 :       language = DW_LANG_C89;
   25746        24328 :       if (dwarf_version >= 3 || !dwarf_strict)
   25747              :         {
   25748        24328 :           if (strcmp (language_string, "GNU C89") != 0)
   25749        22936 :             language = DW_LANG_C99;
   25750              : 
   25751        24328 :           if (dwarf_version >= 5 /* || !dwarf_strict */)
   25752              :             {
   25753        23429 :               if (strcmp (language_string, "GNU C11") == 0)
   25754              :                 language = DW_LANG_C11;
   25755        19729 :               else if (strcmp (language_string, "GNU C17") == 0)
   25756              :                 {
   25757              :                   language = DW_LANG_C11;
   25758              :                   lname = DW_LNAME_C;
   25759              :                   lversion = 201710;
   25760              :                 }
   25761        19624 :               else if (strcmp (language_string, "GNU C23") == 0)
   25762              :                 {
   25763              :                   language = DW_LANG_C11;
   25764              :                   lname = DW_LNAME_C;
   25765              :                   lversion = 202311;
   25766              :                 }
   25767         1474 :               else if (strcmp (language_string, "GNU C2Y") == 0)
   25768              :                 {
   25769        58454 :                   language = DW_LANG_C11;
   25770        58454 :                   lname = DW_LNAME_C;
   25771        58454 :                   lversion = 202500;
   25772              :                 }
   25773              :             }
   25774              :         }
   25775              :     }
   25776        34126 :   else if (startswith (language_string, "GNU C++"))
   25777              :     {
   25778        19397 :       language = DW_LANG_C_plus_plus;
   25779        19397 :       if (dwarf_version >= 5 /* || !dwarf_strict */)
   25780              :         {
   25781        18209 :           if (strcmp (language_string, "GNU C++11") == 0)
   25782              :             language = DW_LANG_C_plus_plus_11;
   25783        17783 :           else if (strcmp (language_string, "GNU C++14") == 0)
   25784              :             language = DW_LANG_C_plus_plus_14;
   25785        17765 :           else if (strcmp (language_string, "GNU C++17") == 0)
   25786              :             {
   25787              :               language = DW_LANG_C_plus_plus_14;
   25788              :               lname = DW_LNAME_C_plus_plus;
   25789              :               lversion = 201703;
   25790              :             }
   25791        16987 :           else if (strcmp (language_string, "GNU C++20") == 0)
   25792              :             {
   25793              :               language = DW_LANG_C_plus_plus_14;
   25794              :               lname = DW_LNAME_C_plus_plus;
   25795              :               lversion = 202002;
   25796              :             }
   25797         1899 :           else if (strcmp (language_string, "GNU C++23") == 0)
   25798              :             {
   25799              :               language = DW_LANG_C_plus_plus_14;
   25800              :               lname = DW_LNAME_C_plus_plus;
   25801              :               lversion = 202302;
   25802              :             }
   25803         1559 :           else if (strcmp (language_string, "GNU C++26") == 0)
   25804              :             {
   25805              :               language = DW_LANG_C_plus_plus_14;
   25806              :               lname = DW_LNAME_C_plus_plus;
   25807              :               lversion = 202603;
   25808              :             }
   25809         1268 :           else if (strcmp (language_string, "GNU C++29") == 0)
   25810              :             {
   25811        58454 :               language = DW_LANG_C_plus_plus_14;
   25812        58454 :               lname = DW_LNAME_C_plus_plus;
   25813        58454 :               lversion = 202700;
   25814              :             }
   25815              :         }
   25816              :     }
   25817        14729 :   else if (strcmp (language_string, "GNU F77") == 0)
   25818              :     language = DW_LANG_Fortran77;
   25819        14729 :   else if (strcmp (language_string, "GCC COBOL") == 0)
   25820              :     language = DW_LANG_Cobol85;
   25821        14729 :   else if (strcmp (language_string, "GNU Modula-2") == 0)
   25822              :     language = DW_LANG_Modula2;
   25823        10920 :   else if (dwarf_version >= 3 || !dwarf_strict)
   25824              :     {
   25825        10920 :       if (strcmp (language_string, "GNU Ada") == 0)
   25826              :         language = DW_LANG_Ada95;
   25827        10920 :       else if (startswith (language_string, "GNU Fortran"))
   25828              :         {
   25829         5277 :           language = DW_LANG_Fortran95;
   25830         5277 :           if (dwarf_version >= 5 /* || !dwarf_strict */)
   25831              :             {
   25832         5254 :               if (strcmp (language_string, "GNU Fortran2003") == 0)
   25833              :                 language = DW_LANG_Fortran03;
   25834         5231 :               else if (strcmp (language_string, "GNU Fortran2008") == 0)
   25835        58454 :                 language = DW_LANG_Fortran08;
   25836              :             }
   25837              :         }
   25838         5643 :       else if (strcmp (language_string, "GNU Objective-C") == 0)
   25839              :         language = DW_LANG_ObjC;
   25840         5643 :       else if (strcmp (language_string, "GNU Objective-C++") == 0)
   25841              :         language = DW_LANG_ObjC_plus_plus;
   25842         5643 :       else if (strcmp (language_string, "GNU D") == 0)
   25843              :         language = DW_LANG_D;
   25844         5643 :       else if (dwarf_version >= 5 || !dwarf_strict)
   25845              :         {
   25846         5642 :           if (strcmp (language_string, "GNU Go") == 0)
   25847              :             language = DW_LANG_Go;
   25848         1382 :           else if (strcmp (language_string, "GNU Rust") == 0)
   25849              :             language = DW_LANG_Rust;
   25850          837 :           else if (strcmp (language_string, "GNU Algol 68") == 0)
   25851              :             {
   25852        58454 :               language = DW_LANG_Algol68;
   25853        58454 :               lname = DW_LNAME_Algol68;
   25854        58454 :               lversion = 1978; /* Not a typo.  The revised language of the
   25855              :                                   Revised Report.  */
   25856              :             }
   25857              :         }
   25858              :     }
   25859              :   /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works.  */
   25860            0 :   else if (startswith (language_string, "GNU Fortran"))
   25861              :     language = DW_LANG_Fortran90;
   25862              :   /* Likewise for Ada.  */
   25863            0 :   else if (strcmp (language_string, "GNU Ada") == 0)
   25864        58454 :     language = DW_LANG_Ada83;
   25865              : 
   25866        58454 :   add_AT_unsigned (die, DW_AT_language, language);
   25867        58454 :   if (lname && dwarf_version >= 5 && !dwarf_strict)
   25868              :     {
   25869        35594 :       add_AT_unsigned (die, DW_AT_language_name, lname);
   25870        35594 :       add_AT_unsigned (die, DW_AT_language_version, lversion);
   25871              :     }
   25872              : 
   25873        58454 :   switch (language)
   25874              :     {
   25875         5277 :     case DW_LANG_Fortran77:
   25876         5277 :     case DW_LANG_Fortran90:
   25877         5277 :     case DW_LANG_Fortran95:
   25878         5277 :     case DW_LANG_Fortran03:
   25879         5277 :     case DW_LANG_Fortran08:
   25880              :       /* Fortran has case insensitive identifiers and the front-end
   25881              :          lowercases everything.  */
   25882         5277 :       add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
   25883         5277 :       break;
   25884            0 :     case DW_LANG_Cobol85:
   25885            0 :       add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_case_insensitive);
   25886            0 :       break;
   25887              :     default:
   25888              :       /* The default DW_ID_case_sensitive doesn't need to be specified.  */
   25889              :       break;
   25890              :     }
   25891        58454 :   return die;
   25892              : }
   25893              : 
   25894              : /* Generate the DIE for a base class.  */
   25895              : 
   25896              : static void
   25897     22076957 : gen_inheritance_die (tree binfo, tree access, tree type,
   25898              :                      dw_die_ref context_die)
   25899              : {
   25900     22076957 :   dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
   25901     22076957 :   struct vlr_context ctx = { type, NULL };
   25902              : 
   25903     22076957 :   add_type_attribute (die, BINFO_TYPE (binfo), TYPE_UNQUALIFIED, false,
   25904              :                       context_die);
   25905     22076957 :   add_data_member_location_attribute (die, binfo, &ctx);
   25906              : 
   25907     22076957 :   if (BINFO_VIRTUAL_P (binfo))
   25908          308 :     add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
   25909              : 
   25910              :   /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
   25911              :      children, otherwise the default is DW_ACCESS_public.  In DWARF2
   25912              :      the default has always been DW_ACCESS_private.  */
   25913     22076957 :   if (access == access_public_node)
   25914              :     {
   25915     21549208 :       if (dwarf_version == 2
   25916     21548794 :           || context_die->die_tag == DW_TAG_class_type)
   25917       988773 :       add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
   25918              :     }
   25919       527749 :   else if (access == access_protected_node)
   25920        88777 :     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
   25921       438972 :   else if (dwarf_version > 2
   25922       438966 :            && context_die->die_tag != DW_TAG_class_type)
   25923       230824 :     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
   25924     22076957 : }
   25925              : 
   25926              : /* Return whether DECL is a FIELD_DECL that represents the variant part of a
   25927              :    structure.  */
   25928              : 
   25929              : static bool
   25930    260196105 : is_variant_part (tree decl)
   25931              : {
   25932    260196105 :   return (TREE_CODE (decl) == FIELD_DECL
   25933    260196105 :           && TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
   25934              : }
   25935              : 
   25936              : /* Check that OPERAND is a reference to a field in STRUCT_TYPE.  If it is,
   25937              :    return the FIELD_DECL.  Return NULL_TREE otherwise.  */
   25938              : 
   25939              : static tree
   25940            0 : analyze_discr_in_predicate (tree operand, tree struct_type)
   25941              : {
   25942            0 :   while (CONVERT_EXPR_P (operand))
   25943            0 :     operand = TREE_OPERAND (operand, 0);
   25944              : 
   25945              :   /* Match field access to members of struct_type only.  */
   25946            0 :   if (TREE_CODE (operand) == COMPONENT_REF
   25947            0 :       && TREE_CODE (TREE_OPERAND (operand, 0)) == PLACEHOLDER_EXPR
   25948            0 :       && TREE_TYPE (TREE_OPERAND (operand, 0)) == struct_type
   25949            0 :       && TREE_CODE (TREE_OPERAND (operand, 1)) == FIELD_DECL)
   25950            0 :     return TREE_OPERAND (operand, 1);
   25951              :   else
   25952              :     return NULL_TREE;
   25953              : }
   25954              : 
   25955              : /* Check that SRC is a constant integer that can be represented as a native
   25956              :    integer constant (either signed or unsigned).  If so, store it into DEST and
   25957              :    return true.  Return false otherwise. */
   25958              : 
   25959              : static bool
   25960            0 : get_discr_value (tree src, dw_discr_value *dest)
   25961              : {
   25962            0 :   tree discr_type = TREE_TYPE (src);
   25963              : 
   25964            0 :   if (lang_hooks.types.get_debug_type)
   25965              :     {
   25966            0 :       tree debug_type = lang_hooks.types.get_debug_type (discr_type);
   25967            0 :       if (debug_type != NULL)
   25968            0 :         discr_type = debug_type;
   25969              :     }
   25970              : 
   25971            0 :   if (TREE_CODE (src) != INTEGER_CST || !INTEGRAL_TYPE_P (discr_type))
   25972              :     return false;
   25973              : 
   25974              :   /* Signedness can vary between the original type and the debug type. This
   25975              :      can happen for character types in Ada for instance: the character type
   25976              :      used for code generation can be signed, to be compatible with the C one,
   25977              :      but from a debugger point of view, it must be unsigned.  */
   25978            0 :   bool is_orig_unsigned = TYPE_UNSIGNED (TREE_TYPE (src));
   25979            0 :   bool is_debug_unsigned = TYPE_UNSIGNED (discr_type);
   25980              : 
   25981            0 :   if (is_orig_unsigned != is_debug_unsigned)
   25982            0 :     src = fold_convert (discr_type, src);
   25983              : 
   25984            0 :   if (!(is_debug_unsigned ? tree_fits_uhwi_p (src) : tree_fits_shwi_p (src)))
   25985              :     return false;
   25986              : 
   25987            0 :   dest->pos = is_debug_unsigned;
   25988            0 :   if (is_debug_unsigned)
   25989            0 :     dest->v.uval = tree_to_uhwi (src);
   25990              :   else
   25991            0 :     dest->v.sval = tree_to_shwi (src);
   25992              : 
   25993              :   return true;
   25994              : }
   25995              : 
   25996              : /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
   25997              :    FIELD_DECL in STRUCT_TYPE that represents a variant part.  If unsuccessful,
   25998              :    store NULL_TREE in DISCR_DECL.  Otherwise:
   25999              : 
   26000              :      - store the discriminant field in STRUCT_TYPE that controls the variant
   26001              :        part to *DISCR_DECL
   26002              : 
   26003              :      - put in *DISCR_LISTS_P an array where for each variant, the item
   26004              :        represents the corresponding matching list of discriminant values.
   26005              : 
   26006              :      - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
   26007              :        the above array.
   26008              : 
   26009              :    Note that when the array is allocated (i.e. when the analysis is
   26010              :    successful), it is up to the caller to free the array.  */
   26011              : 
   26012              : static void
   26013            0 : analyze_variants_discr (tree variant_part_decl,
   26014              :                         tree struct_type,
   26015              :                         tree *discr_decl,
   26016              :                         dw_discr_list_ref **discr_lists_p,
   26017              :                         unsigned *discr_lists_length)
   26018              : {
   26019            0 :   tree variant_part_type = TREE_TYPE (variant_part_decl);
   26020            0 :   tree variant;
   26021            0 :   dw_discr_list_ref *discr_lists;
   26022            0 :   unsigned i;
   26023              : 
   26024              :   /* Compute how many variants there are in this variant part.  */
   26025            0 :   *discr_lists_length = 0;
   26026            0 :   for (variant = TYPE_FIELDS (variant_part_type);
   26027            0 :        variant != NULL_TREE;
   26028            0 :        variant = DECL_CHAIN (variant))
   26029            0 :     ++*discr_lists_length;
   26030              : 
   26031            0 :   *discr_decl = NULL_TREE;
   26032            0 :   *discr_lists_p
   26033            0 :     = (dw_discr_list_ref *) xcalloc (*discr_lists_length,
   26034              :                                      sizeof (**discr_lists_p));
   26035            0 :   discr_lists = *discr_lists_p;
   26036              : 
   26037              :   /* And then analyze all variants to extract discriminant information for all
   26038              :      of them.  This analysis is conservative: as soon as we detect something we
   26039              :      do not support, abort everything and pretend we found nothing.  */
   26040            0 :   for (variant = TYPE_FIELDS (variant_part_type), i = 0;
   26041            0 :        variant != NULL_TREE;
   26042            0 :        variant = DECL_CHAIN (variant), ++i)
   26043              :     {
   26044            0 :       tree match_expr = DECL_QUALIFIER (variant);
   26045              : 
   26046              :       /* Now, try to analyze the predicate and deduce a discriminant for
   26047              :          it.  */
   26048            0 :       if (match_expr == boolean_true_node)
   26049              :         /* Typically happens for the default variant: it matches all cases that
   26050              :            previous variants rejected.  Don't output any matching value for
   26051              :            this one.  */
   26052            0 :         continue;
   26053              : 
   26054              :       /* The following loop tries to iterate over each discriminant
   26055              :          possibility: single values or ranges.  */
   26056            0 :       while (match_expr != NULL_TREE)
   26057              :         {
   26058            0 :           tree next_round_match_expr;
   26059            0 :           tree candidate_discr = NULL_TREE;
   26060            0 :           dw_discr_list_ref new_node = NULL;
   26061              : 
   26062              :           /* Possibilities are matched one after the other by nested
   26063              :              TRUTH_ORIF_EXPR expressions.  Process the current possibility and
   26064              :              continue with the rest at next iteration.  */
   26065            0 :           if (TREE_CODE (match_expr) == TRUTH_ORIF_EXPR)
   26066              :             {
   26067            0 :               next_round_match_expr = TREE_OPERAND (match_expr, 0);
   26068            0 :               match_expr = TREE_OPERAND (match_expr, 1);
   26069              :             }
   26070              :           else
   26071              :             next_round_match_expr = NULL_TREE;
   26072              : 
   26073            0 :           if (match_expr == boolean_false_node)
   26074              :             /* This sub-expression matches nothing: just wait for the next
   26075              :                one.  */
   26076              :             ;
   26077              : 
   26078            0 :           else if (TREE_CODE (match_expr) == EQ_EXPR)
   26079              :             {
   26080              :               /* We are matching:  <discr_field> == <integer_cst>
   26081              :                  This sub-expression matches a single value.  */
   26082            0 :               tree integer_cst = TREE_OPERAND (match_expr, 1);
   26083              : 
   26084            0 :               candidate_discr
   26085            0 :                = analyze_discr_in_predicate (TREE_OPERAND (match_expr, 0),
   26086              :                                              struct_type);
   26087              : 
   26088            0 :               new_node = ggc_cleared_alloc<dw_discr_list_node> ();
   26089            0 :               if (!get_discr_value (integer_cst,
   26090              :                                     &new_node->dw_discr_lower_bound))
   26091            0 :                 goto abort;
   26092            0 :               new_node->dw_discr_range = false;
   26093              :             }
   26094              : 
   26095            0 :           else if (TREE_CODE (match_expr) == TRUTH_ANDIF_EXPR)
   26096              :             {
   26097              :               /* We are matching:
   26098              :                    <discr_field> > <integer_cst>
   26099              :                    && <discr_field> < <integer_cst>.
   26100              :                  This sub-expression matches the range of values between the
   26101              :                  two matched integer constants.  Note that comparisons can be
   26102              :                  inclusive or exclusive.  */
   26103            0 :               tree candidate_discr_1, candidate_discr_2;
   26104            0 :               tree lower_cst, upper_cst;
   26105            0 :               bool lower_cst_included, upper_cst_included;
   26106            0 :               tree lower_op = TREE_OPERAND (match_expr, 0);
   26107            0 :               tree upper_op = TREE_OPERAND (match_expr, 1);
   26108              : 
   26109              :               /* When the comparison is exclusive, the integer constant is not
   26110              :                  the discriminant range bound we are looking for: we will have
   26111              :                  to increment or decrement it.  */
   26112            0 :               if (TREE_CODE (lower_op) == GE_EXPR)
   26113              :                 lower_cst_included = true;
   26114            0 :               else if (TREE_CODE (lower_op) == GT_EXPR)
   26115              :                 lower_cst_included = false;
   26116              :               else
   26117            0 :                 goto abort;
   26118              : 
   26119            0 :               if (TREE_CODE (upper_op) == LE_EXPR)
   26120              :                 upper_cst_included = true;
   26121            0 :               else if (TREE_CODE (upper_op) == LT_EXPR)
   26122              :                 upper_cst_included = false;
   26123              :               else
   26124            0 :                 goto abort;
   26125              : 
   26126              :               /* Extract the discriminant from the first operand and check it
   26127              :                  is consistent with the same analysis in the second
   26128              :                  operand.  */
   26129            0 :               candidate_discr_1
   26130            0 :                 = analyze_discr_in_predicate (TREE_OPERAND (lower_op, 0),
   26131              :                                               struct_type);
   26132            0 :               candidate_discr_2
   26133            0 :                 = analyze_discr_in_predicate (TREE_OPERAND (upper_op, 0),
   26134              :                                               struct_type);
   26135            0 :               if (candidate_discr_1 == candidate_discr_2)
   26136            0 :                 candidate_discr = candidate_discr_1;
   26137              :               else
   26138            0 :                 goto abort;
   26139              : 
   26140              :               /* Extract bounds from both.  */
   26141            0 :               new_node = ggc_cleared_alloc<dw_discr_list_node> ();
   26142            0 :               lower_cst = TREE_OPERAND (lower_op, 1);
   26143            0 :               upper_cst = TREE_OPERAND (upper_op, 1);
   26144              : 
   26145            0 :               if (!lower_cst_included)
   26146            0 :                 lower_cst
   26147            0 :                   = fold_build2 (PLUS_EXPR, TREE_TYPE (lower_cst), lower_cst,
   26148              :                                  build_int_cst (TREE_TYPE (lower_cst), 1));
   26149            0 :               if (!upper_cst_included)
   26150            0 :                 upper_cst
   26151            0 :                   = fold_build2 (MINUS_EXPR, TREE_TYPE (upper_cst), upper_cst,
   26152              :                                  build_int_cst (TREE_TYPE (upper_cst), 1));
   26153              : 
   26154            0 :               if (!get_discr_value (lower_cst,
   26155              :                                     &new_node->dw_discr_lower_bound)
   26156            0 :                   || !get_discr_value (upper_cst,
   26157              :                                        &new_node->dw_discr_upper_bound))
   26158            0 :                 goto abort;
   26159              : 
   26160            0 :               new_node->dw_discr_range = true;
   26161              :             }
   26162              : 
   26163            0 :           else if ((candidate_discr
   26164            0 :                       = analyze_discr_in_predicate (match_expr, struct_type))
   26165            0 :                    && (TREE_TYPE (candidate_discr) == boolean_type_node
   26166            0 :                        || TREE_TYPE (TREE_TYPE (candidate_discr))
   26167              :                           == boolean_type_node))
   26168              :             {
   26169              :               /* We are matching:  <discr_field> for a boolean discriminant.
   26170              :                  This sub-expression matches boolean_true_node.  */
   26171            0 :               new_node = ggc_cleared_alloc<dw_discr_list_node> ();
   26172            0 :               if (!get_discr_value (boolean_true_node,
   26173              :                                     &new_node->dw_discr_lower_bound))
   26174            0 :                 goto abort;
   26175            0 :               new_node->dw_discr_range = false;
   26176              :             }
   26177              : 
   26178              :           else
   26179              :             /* Unsupported sub-expression: we cannot determine the set of
   26180              :                matching discriminant values.  Abort everything.  */
   26181            0 :             goto abort;
   26182              : 
   26183              :           /* If the discriminant info is not consistent with what we saw so
   26184              :              far, consider the analysis failed and abort everything.  */
   26185            0 :           if (candidate_discr == NULL_TREE
   26186            0 :               || (*discr_decl != NULL_TREE && candidate_discr != *discr_decl))
   26187            0 :             goto abort;
   26188              :           else
   26189            0 :             *discr_decl = candidate_discr;
   26190              : 
   26191            0 :           if (new_node != NULL)
   26192              :             {
   26193            0 :               new_node->dw_discr_next = discr_lists[i];
   26194            0 :               discr_lists[i] = new_node;
   26195              :             }
   26196            0 :           match_expr = next_round_match_expr;
   26197              :         }
   26198              :     }
   26199              : 
   26200              :   /* If we reach this point, we could match everything we were interested
   26201              :      in.  */
   26202              :   return;
   26203              : 
   26204            0 : abort:
   26205              :   /* Clean all data structure and return no result.  */
   26206            0 :   free (*discr_lists_p);
   26207            0 :   *discr_lists_p = NULL;
   26208            0 :   *discr_decl = NULL_TREE;
   26209              : }
   26210              : 
   26211              : /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
   26212              :    of STRUCT_TYPE, a record type.  This new DIE is emitted as the next child
   26213              :    under CONTEXT_DIE.
   26214              : 
   26215              :    Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
   26216              :    QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter.  The members for
   26217              :    this type, which are record types, represent the available variants and each
   26218              :    has a DECL_QUALIFIER attribute.  The discriminant and the discriminant
   26219              :    values are inferred from these attributes.
   26220              : 
   26221              :    In trees, the offsets for the fields inside these sub-records are relative
   26222              :    to the variant part itself, whereas the corresponding DIEs should have
   26223              :    offset attributes that are relative to the embedding record base address.
   26224              :    This is why the caller must provide a VARIANT_PART_OFFSET expression: it
   26225              :    must be an expression that computes the offset of the variant part to
   26226              :    describe in DWARF.  */
   26227              : 
   26228              : static void
   26229            0 : gen_variant_part (tree variant_part_decl, struct vlr_context *vlr_ctx,
   26230              :                   dw_die_ref context_die)
   26231              : {
   26232            0 :   const tree variant_part_type = TREE_TYPE (variant_part_decl);
   26233            0 :   tree variant_part_offset = vlr_ctx->variant_part_offset;
   26234              : 
   26235              :   /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
   26236              :      NULL_TREE if there is no such field.  */
   26237            0 :   tree discr_decl = NULL_TREE;
   26238            0 :   dw_discr_list_ref *discr_lists;
   26239            0 :   unsigned discr_lists_length = 0;
   26240            0 :   unsigned i;
   26241              : 
   26242            0 :   dw_die_ref dwarf_proc_die = NULL;
   26243            0 :   dw_die_ref variant_part_die
   26244            0 :     = new_die (DW_TAG_variant_part, context_die, variant_part_type);
   26245              : 
   26246            0 :   equate_decl_number_to_die (variant_part_decl, variant_part_die);
   26247              : 
   26248            0 :   analyze_variants_discr (variant_part_decl, vlr_ctx->struct_type,
   26249              :                           &discr_decl, &discr_lists, &discr_lists_length);
   26250              : 
   26251            0 :   if (discr_decl != NULL_TREE)
   26252              :     {
   26253            0 :       dw_die_ref discr_die = lookup_decl_die (discr_decl);
   26254              : 
   26255            0 :       if (discr_die)
   26256            0 :         add_AT_die_ref (variant_part_die, DW_AT_discr, discr_die);
   26257              :       else
   26258              :         /* We have no DIE for the discriminant, so just discard all
   26259              :            discrimimant information in the output.  */
   26260            0 :         discr_decl = NULL_TREE;
   26261              :     }
   26262              : 
   26263              :   /* If the offset for this variant part is more complex than a constant,
   26264              :      create a DWARF procedure for it so that we will not have to generate
   26265              :      DWARF expressions for it for each member.  */
   26266            0 :   if (TREE_CODE (variant_part_offset) != INTEGER_CST
   26267            0 :       && (dwarf_version >= 3 || !dwarf_strict))
   26268              :     {
   26269            0 :       struct loc_descr_context ctx = {
   26270            0 :         vlr_ctx->struct_type,        /* context_type */
   26271              :         NULL_TREE,              /* base_decl */
   26272              :         NULL,                   /* dpi */
   26273              :         false,                  /* placeholder_arg */
   26274              :         false,                  /* placeholder_seen */
   26275              :         false                   /* strict_signedness */
   26276            0 :       };
   26277            0 :       const tree dwarf_proc_fndecl
   26278            0 :         = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
   26279            0 :                       build_function_type (TREE_TYPE (variant_part_offset),
   26280              :                                            NULL_TREE));
   26281            0 :       const tree dwarf_proc_call = build_call_expr (dwarf_proc_fndecl, 0);
   26282            0 :       const dw_loc_descr_ref dwarf_proc_body
   26283            0 :         = loc_descriptor_from_tree (variant_part_offset, 0, &ctx);
   26284              : 
   26285            0 :       dwarf_proc_die = new_dwarf_proc_die (dwarf_proc_body,
   26286              :                                            dwarf_proc_fndecl, context_die);
   26287            0 :       if (dwarf_proc_die != NULL)
   26288            0 :         variant_part_offset = dwarf_proc_call;
   26289              :     }
   26290              : 
   26291              :   /* Output DIEs for all variants.  */
   26292            0 :   i = 0;
   26293            0 :   for (tree variant = TYPE_FIELDS (variant_part_type);
   26294            0 :        variant != NULL_TREE;
   26295            0 :        variant = DECL_CHAIN (variant), ++i)
   26296              :     {
   26297            0 :       tree variant_type = TREE_TYPE (variant);
   26298            0 :       dw_die_ref variant_die;
   26299              : 
   26300              :       /* All variants (i.e. members of a variant part) are supposed to be
   26301              :          encoded as structures.  Sub-variant parts are QUAL_UNION_TYPE fields
   26302              :          under these records.  */
   26303            0 :       gcc_assert (TREE_CODE (variant_type) == RECORD_TYPE);
   26304              : 
   26305            0 :       variant_die = new_die (DW_TAG_variant, variant_part_die, variant_type);
   26306            0 :       equate_decl_number_to_die (variant, variant_die);
   26307              : 
   26308              :       /* Output discriminant values this variant matches, if any.  */
   26309            0 :       if (discr_decl == NULL || discr_lists[i] == NULL)
   26310              :         /* In the case we have discriminant information at all, this is
   26311              :            probably the default variant: as the standard says, don't
   26312              :            output any discriminant value/list attribute.  */
   26313              :         ;
   26314            0 :       else if (discr_lists[i]->dw_discr_next == NULL
   26315            0 :                && !discr_lists[i]->dw_discr_range)
   26316              :         /* If there is only one accepted value, don't bother outputting a
   26317              :            list.  */
   26318            0 :         add_discr_value (variant_die, &discr_lists[i]->dw_discr_lower_bound);
   26319              :       else
   26320            0 :         add_discr_list (variant_die, discr_lists[i]);
   26321              : 
   26322            0 :       for (tree member = TYPE_FIELDS (variant_type);
   26323            0 :            member != NULL_TREE;
   26324            0 :            member = DECL_CHAIN (member))
   26325              :         {
   26326            0 :           struct vlr_context vlr_sub_ctx = {
   26327            0 :             vlr_ctx->struct_type, /* struct_type */
   26328              :             NULL                  /* variant_part_offset */
   26329            0 :           };
   26330            0 :           if (is_variant_part (member))
   26331              :             {
   26332              :               /* All offsets for fields inside variant parts are relative to
   26333              :                  the top-level embedding RECORD_TYPE's base address.  On the
   26334              :                  other hand, offsets in GCC's types are relative to the
   26335              :                  nested-most variant part.  So we have to sum offsets each time
   26336              :                  we recurse.  */
   26337              : 
   26338            0 :               vlr_sub_ctx.variant_part_offset
   26339            0 :                 = fold_build2 (PLUS_EXPR, TREE_TYPE (variant_part_offset),
   26340              :                                variant_part_offset, byte_position (member));
   26341            0 :               gen_variant_part (member, &vlr_sub_ctx, variant_die);
   26342              :             }
   26343              :           else
   26344              :             {
   26345            0 :               vlr_sub_ctx.variant_part_offset = variant_part_offset;
   26346            0 :               gen_decl_die (member, NULL, &vlr_sub_ctx, variant_die);
   26347              :             }
   26348              :         }
   26349              :     }
   26350              : 
   26351            0 :   free (discr_lists);
   26352            0 : }
   26353              : 
   26354              : /* Generate a DIE for a class member.  */
   26355              : 
   26356              : static void
   26357     47573968 : gen_member_die (tree type, dw_die_ref context_die)
   26358              : {
   26359     47573968 :   tree member;
   26360     47573968 :   tree binfo = TYPE_BINFO (type);
   26361              : 
   26362     47573968 :   gcc_assert (TYPE_MAIN_VARIANT (type) == type);
   26363              : 
   26364              :   /* If this is not an incomplete type, output descriptions of each of its
   26365              :      members. Note that as we output the DIEs necessary to represent the
   26366              :      members of this record or union type, we will also be trying to output
   26367              :      DIEs to represent the *types* of those members. However the `type'
   26368              :      function (above) will specifically avoid generating type DIEs for member
   26369              :      types *within* the list of member DIEs for this (containing) type except
   26370              :      for those types (of members) which are explicitly marked as also being
   26371              :      members of this (containing) type themselves.  The g++ front- end can
   26372              :      force any given type to be treated as a member of some other (containing)
   26373              :      type by setting the TYPE_CONTEXT of the given (member) type to point to
   26374              :      the TREE node representing the appropriate (containing) type.  */
   26375              : 
   26376              :   /* First output info about the base classes.  */
   26377     47573968 :   if (binfo && early_dwarf)
   26378              :     {
   26379     46872611 :       vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
   26380     46872611 :       int i;
   26381     46872611 :       tree base;
   26382              : 
   26383     68949568 :       for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
   26384     44153914 :         gen_inheritance_die (base,
   26385     22076957 :                              (accesses ? (*accesses)[i] : access_public_node),
   26386              :                              type,
   26387              :                              context_die);
   26388              :     }
   26389              : 
   26390              :   /* Now output info about the members. */
   26391    372219283 :   for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
   26392              :     {
   26393              :       /* Ignore clones.  */
   26394    324645315 :       if (DECL_ABSTRACT_ORIGIN (member))
   26395     55175104 :         continue;
   26396              : 
   26397    269470211 :       struct vlr_context vlr_ctx = { type, NULL_TREE };
   26398    269470211 :       bool static_inline_p
   26399    269470211 :         = (VAR_P (member)
   26400     12128972 :            && TREE_STATIC (member)
   26401    281599183 :            && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
   26402    269470211 :                != -1));
   26403              : 
   26404              :       /* If we thought we were generating minimal debug info for TYPE
   26405              :          and then changed our minds, some of the member declarations
   26406              :          may have already been defined.  Don't define them again, but
   26407              :          do put them in the right order.  */
   26408              : 
   26409    269470211 :       if (dw_die_ref child = lookup_decl_die (member))
   26410              :         {
   26411              :           /* Handle inline static data members, which only have in-class
   26412              :              declarations.  */
   26413      9274106 :           bool splice = true;
   26414              : 
   26415      9274106 :           dw_die_ref ref = NULL;
   26416      9274106 :           if (child->die_tag == DW_TAG_variable
   26417      9274106 :               && child->die_parent == comp_unit_die ())
   26418              :             {
   26419      8050482 :               ref = get_AT_ref (child, DW_AT_specification);
   26420              : 
   26421              :               /* For C++17 inline static data members followed by redundant
   26422              :                  out of class redeclaration, we might get here with
   26423              :                  child being the DIE created for the out of class
   26424              :                  redeclaration and with its DW_AT_specification being
   26425              :                  the DIE created for in-class definition.  We want to
   26426              :                  reparent the latter, and don't want to create another
   26427              :                  DIE with DW_AT_specification in that case, because
   26428              :                  we already have one.  */
   26429      8050482 :               if (ref
   26430      8050482 :                   && static_inline_p
   26431            6 :                   && ref->die_tag == DW_TAG_variable
   26432            6 :                   && ref->die_parent == comp_unit_die ()
   26433      8050488 :                   && get_AT (ref, DW_AT_specification) == NULL)
   26434              :                 {
   26435              :                   child = ref;
   26436              :                   ref = NULL;
   26437              :                   static_inline_p = false;
   26438              :                 }
   26439              : 
   26440      8050476 :               if (!ref)
   26441              :                 {
   26442      8049781 :                   reparent_child (child, context_die);
   26443      8049781 :                   if (dwarf_version < 5)
   26444           14 :                     child->die_tag = DW_TAG_member;
   26445              :                   splice = false;
   26446              :                 }
   26447              :             }
   26448      1223624 :           else if (child->die_tag == DW_TAG_enumerator)
   26449              :             /* Enumerators remain under their enumeration even if
   26450              :                their names are introduced in the enclosing scope.  */
   26451              :             splice = false;
   26452              : 
   26453           14 :           if (splice)
   26454        18748 :             splice_child_die (context_die, child);
   26455              :         }
   26456              : 
   26457              :       /* Do not generate DWARF for variant parts if we are generating the
   26458              :          corresponding GNAT encodings: DIEs generated for the two schemes
   26459              :          would conflict in our mappings.  */
   26460    260196105 :       else if (is_variant_part (member)
   26461    260196105 :                && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL)
   26462              :         {
   26463            0 :           vlr_ctx.variant_part_offset = byte_position (member);
   26464            0 :           gen_variant_part (member, &vlr_ctx, context_die);
   26465              :         }
   26466              :       else
   26467              :         {
   26468    260196105 :           vlr_ctx.variant_part_offset = NULL_TREE;
   26469    260196105 :           gen_decl_die (member, NULL, &vlr_ctx, context_die);
   26470              :         }
   26471              : 
   26472              :       /* For C++ inline static data members emit immediately a DW_TAG_variable
   26473              :          DIE that will refer to that DW_TAG_member/DW_TAG_variable through
   26474              :          DW_AT_specification.  */
   26475    269470211 :       if (static_inline_p)
   26476              :         {
   26477     10341505 :           int old_extern = DECL_EXTERNAL (member);
   26478     10341505 :           DECL_EXTERNAL (member) = 0;
   26479     10341505 :           gen_decl_die (member, NULL, NULL, comp_unit_die ());
   26480     10341505 :           DECL_EXTERNAL (member) = old_extern;
   26481              :         }
   26482              :     }
   26483     47573968 : }
   26484              : 
   26485              : /* Generate a DIE for a structure or union type.  If TYPE_DECL_SUPPRESS_DEBUG
   26486              :    is set, we pretend that the type was never defined, so we only get the
   26487              :    member DIEs needed by later specification DIEs.  */
   26488              : 
   26489              : static void
   26490    130152528 : gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
   26491              :                                 enum debug_info_usage usage)
   26492              : {
   26493    130152528 :   if (TREE_ASM_WRITTEN (type))
   26494              :     {
   26495              :       /* Fill in the bound of variable-length fields in late dwarf if
   26496              :          still incomplete.  */
   26497          182 :       if (!early_dwarf && variably_modified_type_p (type, NULL))
   26498           86 :         for (tree member = TYPE_FIELDS (type);
   26499          209 :              member;
   26500          123 :              member = DECL_CHAIN (member))
   26501          123 :           fill_variable_array_bounds (TREE_TYPE (member));
   26502              :       return;
   26503              :     }
   26504              : 
   26505    130152346 :   dw_die_ref type_die = lookup_type_die (type);
   26506    130152346 :   dw_die_ref scope_die = 0;
   26507    130152346 :   bool nested = false;
   26508    130152346 :   bool complete = (TYPE_SIZE (type)
   26509    130152346 :                    && (! TYPE_STUB_DECL (type)
   26510     93411747 :                        || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
   26511    130152346 :   bool ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
   26512    130152346 :   complete = complete && should_emit_struct_debug (type, usage);
   26513              : 
   26514    130152346 :   if (type_die && ! complete)
   26515              :     return;
   26516              : 
   26517     98271632 :   if (TYPE_CONTEXT (type) != NULL_TREE
   26518     98271632 :       && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
   26519     94187470 :           || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
   26520              :     nested = true;
   26521              : 
   26522     98271632 :   scope_die = scope_die_for (type, context_die);
   26523              : 
   26524              :   /* Generate child dies for template parameters.  */
   26525     98271632 :   if (!type_die && debug_info_level > DINFO_LEVEL_TERSE)
   26526     51006749 :     schedule_generic_params_dies_gen (type);
   26527              : 
   26528     47264880 :   if (! type_die || (nested && is_cu_die (scope_die)))
   26529              :     /* First occurrence of type or toplevel definition of nested class.  */
   26530              :     {
   26531     51006752 :       dw_die_ref old_die = type_die;
   26532              : 
   26533    101529466 :       type_die = new_die (TREE_CODE (type) == RECORD_TYPE
   26534     50522714 :                           ? record_type_tag (type) : DW_TAG_union_type,
   26535              :                           scope_die, type);
   26536     51006752 :       equate_type_number_to_die (type, type_die);
   26537     51006752 :       if (old_die)
   26538            0 :         add_AT_specification (type_die, old_die);
   26539              :       else
   26540     51006752 :         add_name_attribute (type_die, type_tag (type));
   26541              :     }
   26542              :   else
   26543     47264880 :     remove_AT (type_die, DW_AT_declaration);
   26544              : 
   26545              :   /* If this type has been completed, then give it a byte_size attribute and
   26546              :      then give a list of members.  */
   26547     98271632 :   if (complete && !ns_decl)
   26548              :     {
   26549              :       /* Prevent infinite recursion in cases where the type of some member of
   26550              :          this type is expressed in terms of this type itself.  */
   26551     47573968 :       TREE_ASM_WRITTEN (type) = 1;
   26552     47573968 :       add_byte_size_attribute (type_die, type);
   26553     47573968 :       add_alignment_attribute (type_die, type);
   26554     47573968 :       if (TYPE_STUB_DECL (type) != NULL_TREE)
   26555              :         {
   26556     47368986 :           add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
   26557     47368986 :           add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
   26558              :         }
   26559              : 
   26560              :       /* If the first reference to this type was as the return type of an
   26561              :          inline function, then it may not have a parent.  Fix this now.  */
   26562     47573968 :       if (type_die->die_parent == NULL)
   26563       142180 :         add_child_die (scope_die, type_die);
   26564              : 
   26565     47573968 :       gen_member_die (type, type_die);
   26566              : 
   26567     47573968 :       add_gnat_descriptive_type_attribute (type_die, type, context_die);
   26568     47573968 :       if (TYPE_ARTIFICIAL (type))
   26569         1497 :         add_AT_flag (type_die, DW_AT_artificial, 1);
   26570              : 
   26571              :       /* GNU extension: Record what type our vtable lives in.  */
   26572     47573968 :       if (TYPE_VFIELD (type))
   26573              :         {
   26574       332907 :           tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
   26575              : 
   26576       332907 :           gen_type_die (vtype, context_die);
   26577       332907 :           add_AT_die_ref (type_die, DW_AT_containing_type,
   26578              :                           lookup_type_die (vtype));
   26579              :         }
   26580              :     }
   26581              :   else
   26582              :     {
   26583     50697664 :       add_AT_flag (type_die, DW_AT_declaration, 1);
   26584              : 
   26585              :       /* We don't need to do this for function-local types.  */
   26586     50697664 :       if (TYPE_STUB_DECL (type)
   26587     50697664 :           && ! decl_function_context (TYPE_STUB_DECL (type)))
   26588     50696904 :         vec_safe_push (incomplete_types, type);
   26589              :     }
   26590              : 
   26591     98271632 :   if (get_AT (type_die, DW_AT_name))
   26592     96839004 :     add_pubtype (type, type_die);
   26593              : }
   26594              : 
   26595              : /* Generate a DIE for a subroutine _type_.  */
   26596              : 
   26597              : static void
   26598       442203 : gen_subroutine_type_die (tree type, dw_die_ref context_die)
   26599              : {
   26600       442203 :   tree return_type = TREE_TYPE (type);
   26601       442203 :   dw_die_ref subr_die
   26602       442203 :     = new_die (DW_TAG_subroutine_type,
   26603              :                scope_die_for (type, context_die), type);
   26604              : 
   26605       442203 :   equate_type_number_to_die (type, subr_die);
   26606       442203 :   add_prototyped_attribute (subr_die, type);
   26607       442203 :   add_type_attribute (subr_die, return_type, TYPE_UNQUALIFIED, false,
   26608              :                       context_die);
   26609       442203 :   add_alignment_attribute (subr_die, type);
   26610       442203 :   gen_formal_types_die (type, subr_die);
   26611              : 
   26612       442203 :   if (get_AT (subr_die, DW_AT_name))
   26613            0 :     add_pubtype (type, subr_die);
   26614          775 :   if ((dwarf_version >= 5 || !dwarf_strict)
   26615       442972 :       && lang_hooks.types.type_dwarf_attribute (type, DW_AT_reference) != -1)
   26616          104 :     add_AT_flag (subr_die, DW_AT_reference, 1);
   26617          775 :   if ((dwarf_version >= 5 || !dwarf_strict)
   26618       442972 :       && lang_hooks.types.type_dwarf_attribute (type,
   26619              :                                                 DW_AT_rvalue_reference) != -1)
   26620           47 :     add_AT_flag (subr_die, DW_AT_rvalue_reference, 1);
   26621       442203 : }
   26622              : 
   26623              : /* Generate a DIE for a type definition.  */
   26624              : 
   26625              : static void
   26626     60902573 : gen_typedef_die (tree decl, dw_die_ref context_die)
   26627              : {
   26628     60902573 :   dw_die_ref type_die;
   26629     60902573 :   tree type;
   26630              : 
   26631     60902573 :   if (TREE_ASM_WRITTEN (decl))
   26632              :     {
   26633     10126527 :       if (DECL_ORIGINAL_TYPE (decl))
   26634      9982599 :         fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl));
   26635              :       return;
   26636              :     }
   26637              : 
   26638              :   /* As we avoid creating DIEs for local typedefs (see decl_ultimate_origin
   26639              :      checks in process_scope_var and modified_type_die), this should be called
   26640              :      only for original types.  */
   26641     50776046 :   gcc_assert (decl_ultimate_origin (decl) == NULL
   26642              :               || decl_ultimate_origin (decl) == decl);
   26643              : 
   26644     50776046 :   TREE_ASM_WRITTEN (decl) = 1;
   26645     50776046 :   type_die = new_die (DW_TAG_typedef, context_die, decl);
   26646              : 
   26647     50776046 :   add_name_and_src_coords_attributes (type_die, decl);
   26648     50776046 :   if (DECL_ORIGINAL_TYPE (decl))
   26649              :     {
   26650     50446974 :       type = DECL_ORIGINAL_TYPE (decl);
   26651     50446974 :       if (type == error_mark_node)
   26652              :         return;
   26653              : 
   26654     50446974 :       gcc_assert (type != TREE_TYPE (decl));
   26655     50446974 :       equate_type_number_to_die (TREE_TYPE (decl), type_die);
   26656              :     }
   26657              :   else
   26658              :     {
   26659       329072 :       type = TREE_TYPE (decl);
   26660       329072 :       if (type == error_mark_node)
   26661              :         return;
   26662              : 
   26663       329072 :       if (is_naming_typedef_decl (TYPE_NAME (type)))
   26664              :         {
   26665              :           /* Here, we are in the case of decl being a typedef naming
   26666              :              an anonymous type, e.g:
   26667              :                  typedef struct {...} foo;
   26668              :              In that case TREE_TYPE (decl) is not a typedef variant
   26669              :              type and TYPE_NAME of the anonymous type is set to the
   26670              :              TYPE_DECL of the typedef. This construct is emitted by
   26671              :              the C++ FE.
   26672              : 
   26673              :              TYPE is the anonymous struct named by the typedef
   26674              :              DECL. As we need the DW_AT_type attribute of the
   26675              :              DW_TAG_typedef to point to the DIE of TYPE, let's
   26676              :              generate that DIE right away. add_type_attribute
   26677              :              called below will then pick (via lookup_type_die) that
   26678              :              anonymous struct DIE.  */
   26679       328573 :           if (!TREE_ASM_WRITTEN (type))
   26680           83 :             gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
   26681              : 
   26682              :           /* This is a GNU Extension.  We are adding a
   26683              :              DW_AT_linkage_name attribute to the DIE of the
   26684              :              anonymous struct TYPE.  The value of that attribute
   26685              :              is the name of the typedef decl naming the anonymous
   26686              :              struct.  This greatly eases the work of consumers of
   26687              :              this debug info.  */
   26688       328573 :           add_linkage_name_raw (lookup_type_die (type), decl);
   26689              :         }
   26690              :     }
   26691              : 
   26692     50776046 :   add_type_attribute (type_die, type, decl_quals (decl), false,
   26693              :                       context_die);
   26694              : 
   26695     50776046 :   if (is_naming_typedef_decl (decl))
   26696              :     /* We want that all subsequent calls to lookup_type_die with
   26697              :        TYPE in argument yield the DW_TAG_typedef we have just
   26698              :        created.  */
   26699       328573 :     equate_type_number_to_die (type, type_die);
   26700              : 
   26701     50776046 :   add_alignment_attribute (type_die, TREE_TYPE (decl));
   26702              : 
   26703     50776046 :   add_accessibility_attribute (type_die, decl);
   26704              : 
   26705     50776046 :   if (DECL_ABSTRACT_P (decl))
   26706         5997 :     equate_decl_number_to_die (decl, type_die);
   26707              : 
   26708     50776046 :   if (get_AT (type_die, DW_AT_name))
   26709     50775994 :     add_pubtype (decl, type_die);
   26710              : }
   26711              : 
   26712              : /* Generate a DIE for a struct, class, enum or union type.  */
   26713              : 
   26714              : static void
   26715    132554327 : gen_tagged_type_die (tree type,
   26716              :                      dw_die_ref context_die,
   26717              :                      enum debug_info_usage usage,
   26718              :                      bool reverse)
   26719              : {
   26720    132554327 :   if (type == NULL_TREE
   26721    132554327 :       || !is_tagged_type (type))
   26722              :     return;
   26723              : 
   26724    132554327 :   if (TREE_ASM_WRITTEN (type))
   26725              :     ;
   26726              :   /* If this is a nested type whose containing class hasn't been written
   26727              :      out yet, writing it out will cover this one, too.  This does not apply
   26728              :      to instantiations of member class templates; they need to be added to
   26729              :      the containing class as they are generated.  FIXME: This hurts the
   26730              :      idea of combining type decls from multiple TUs, since we can't predict
   26731              :      what set of template instantiations we'll get.  */
   26732    132554143 :   else if (TYPE_CONTEXT (type)
   26733    131664252 :       && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
   26734    138314736 :       && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
   26735              :     {
   26736      2273116 :       gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
   26737              : 
   26738      2273116 :       if (TREE_ASM_WRITTEN (type))
   26739              :         return;
   26740              : 
   26741              :       /* If that failed, attach ourselves to the stub.  */
   26742      2273116 :       context_die = lookup_type_die (TYPE_CONTEXT (type));
   26743              :     }
   26744    130281027 :   else if (TYPE_CONTEXT (type) != NULL_TREE
   26745    130281027 :            && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
   26746              :     {
   26747              :       /* If this type is local to a function that hasn't been written
   26748              :          out yet, use a NULL context for now; it will be fixed up in
   26749              :          decls_for_scope.  */
   26750       172289 :       context_die = lookup_decl_die (TYPE_CONTEXT (type));
   26751              :       /* A declaration DIE doesn't count; nested types need to go in the
   26752              :          specification.  */
   26753       172289 :       if (context_die && is_declaration_die (context_die))
   26754              :         context_die = NULL;
   26755              :     }
   26756              :   else
   26757    130108738 :     context_die = declare_in_namespace (type, context_die);
   26758              : 
   26759    132554327 :   if (TREE_CODE (type) == ENUMERAL_TYPE)
   26760              :     {
   26761              :       /* This might have been written out by the call to
   26762              :          declare_in_namespace.  */
   26763      2401799 :       if (!TREE_ASM_WRITTEN (type) || reverse)
   26764      1873244 :         gen_enumeration_type_die (type, context_die, reverse);
   26765              :     }
   26766              :   else
   26767    130152528 :     gen_struct_or_union_type_die (type, context_die, usage);
   26768              : 
   26769    132554327 :   dw_die_ref die = lookup_type_die (type);
   26770    132554327 :   if (die)
   26771    132554327 :     maybe_gen_btf_type_tag_dies (type, die);
   26772              : 
   26773              :   /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
   26774              :      it up if it is ever completed.  gen_*_type_die will set it for us
   26775              :      when appropriate.  */
   26776              : }
   26777              : 
   26778              : /* Generate a type description DIE.  */
   26779              : 
   26780              : static void
   26781    920314206 : gen_type_die_with_usage (tree type, dw_die_ref context_die,
   26782              :                          enum debug_info_usage usage, bool reverse)
   26783              : {
   26784    920327923 :   struct array_descr_info info;
   26785              : 
   26786    920327923 :   if (type == NULL_TREE || type == error_mark_node)
   26787    890193976 :     return;
   26788              : 
   26789    920327923 :   if (flag_checking && type)
   26790    920327900 :      verify_type (type);
   26791              : 
   26792    920327923 :   if (TYPE_NAME (type) != NULL_TREE
   26793    765847540 :       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   26794    765213091 :       && is_redundant_typedef (TYPE_NAME (type))
   26795   1396303782 :       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
   26796              :     /* The DECL of this type is a typedef we don't want to emit debug
   26797              :        info for but we want debug info for its underlying typedef.
   26798              :        This can happen for e.g, the injected-class-name of a C++
   26799              :        type.  */
   26800     46913958 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   26801              : 
   26802              :   /* If TYPE is a typedef type variant, let's generate debug info
   26803              :      for the parent typedef which TYPE is a type of.  */
   26804    920327923 :   if (typedef_variant_p (type))
   26805              :     {
   26806     89940680 :       tree name = TYPE_NAME (type);
   26807     89940680 :       if (TREE_ASM_WRITTEN (name))
   26808              :         return;
   26809              : 
   26810     13786919 :       tree origin = decl_ultimate_origin (name);
   26811     13786919 :       if (origin != NULL && origin != name)
   26812              :         {
   26813            0 :           gen_decl_die (origin, NULL, NULL, context_die);
   26814            0 :           return;
   26815              :         }
   26816              : 
   26817              :       /* Prevent broken recursion; we can't hand off to the same type.  */
   26818     13786919 :       gcc_assert (DECL_ORIGINAL_TYPE (name) != type);
   26819              : 
   26820              :       /* Give typedefs the right scope.  */
   26821     13786919 :       context_die = scope_die_for (type, context_die);
   26822              : 
   26823     13786919 :       gen_decl_die (name, NULL, NULL, context_die);
   26824     13786919 :       return;
   26825              :     }
   26826              : 
   26827              :   /* If type is an anonymous tagged type named by a typedef, let's
   26828              :      generate debug info for the typedef.  */
   26829    830387243 :   if (is_naming_typedef_decl (TYPE_NAME (type)))
   26830              :     {
   26831              :       /* Give typedefs the right scope.  */
   26832       144318 :       context_die = scope_die_for (type, context_die);
   26833              : 
   26834       144318 :       gen_decl_die (TYPE_NAME (type), NULL, NULL, context_die);
   26835       144318 :       return;
   26836              :     }
   26837              : 
   26838    830242925 :   if (lang_hooks.types.get_debug_type)
   26839              :     {
   26840    824026557 :       tree debug_type = lang_hooks.types.get_debug_type (type);
   26841              : 
   26842    824026557 :       if (debug_type != NULL_TREE && debug_type != type)
   26843              :         {
   26844              :           gen_type_die_with_usage (debug_type, context_die, usage, reverse);
   26845              :           return;
   26846              :         }
   26847              :     }
   26848              : 
   26849              :   /* We are going to output a DIE to represent the unqualified version
   26850              :      of this type (i.e. without any const or volatile qualifiers) so
   26851              :      get the main variant (i.e. the unqualified version) of this type
   26852              :      now.  (Vectors and arrays are special because the debugging info is in the
   26853              :      cloned type itself.  Similarly function/method types can contain extra
   26854              :      ref-qualification).  */
   26855    830229208 :   if (FUNC_OR_METHOD_TYPE_P (type))
   26856              :     {
   26857              :       /* For function/method types, can't use type_main_variant here,
   26858              :          because that can have different ref-qualifiers for C++,
   26859              :          but try to canonicalize.  */
   26860       497754 :       tree main = TYPE_MAIN_VARIANT (type);
   26861       524247 :       for (tree t = main; t; t = TYPE_NEXT_VARIANT (t))
   26862       524235 :         if (TYPE_QUALS_NO_ADDR_SPACE (t) == 0
   26863       523965 :             && check_base_type (t, main)
   26864      1037606 :             && check_lang_type (t, type))
   26865              :           {
   26866              :             type = t;
   26867              :             break;
   26868              :           }
   26869              :     }
   26870    829731454 :   else if (TREE_CODE (type) != VECTOR_TYPE
   26871    829731454 :            && TREE_CODE (type) != ARRAY_TYPE)
   26872    828063279 :     type = type_main_variant (type);
   26873              : 
   26874              :   /* If this is an array type with hidden descriptor, handle it first.  */
   26875    830229208 :   if (!TREE_ASM_WRITTEN (type)
   26876    162670994 :       && lang_hooks.types.get_array_descr_info)
   26877              :     {
   26878        91322 :       memset (&info, 0, sizeof (info));
   26879        91322 :       if (lang_hooks.types.get_array_descr_info (type, &info))
   26880              :         {
   26881              :           /* Fortran sometimes emits array types with no dimension.  */
   26882         7281 :           gcc_assert (info.ndimensions >= 0
   26883              :                       && (info.ndimensions
   26884              :                           <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN));
   26885         7281 :           gen_descr_array_type_die (type, &info, context_die);
   26886         7281 :           TREE_ASM_WRITTEN (type) = 1;
   26887         7281 :           return;
   26888              :         }
   26889              :     }
   26890              : 
   26891    830221927 :   if (TREE_ASM_WRITTEN (type) && !reverse)
   26892              :     {
   26893              :       /* Variable-length types may be incomplete even if
   26894              :          TREE_ASM_WRITTEN.  For such types, fall through to
   26895              :          gen_array_type_die() and possibly fill in
   26896              :          DW_AT_{upper,lower}_bound attributes.  */
   26897    667558212 :       if ((TREE_CODE (type) != ARRAY_TYPE
   26898              :            && TREE_CODE (type) != RECORD_TYPE
   26899              :            && TREE_CODE (type) != UNION_TYPE
   26900    667558212 :            && TREE_CODE (type) != QUAL_UNION_TYPE)
   26901    667558212 :           || !variably_modified_type_p (type, NULL))
   26902              :         return;
   26903              :     }
   26904              : 
   26905    162674474 :   switch (TREE_CODE (type))
   26906              :     {
   26907              :     case ERROR_MARK:
   26908              :       break;
   26909              : 
   26910     27937076 :     case POINTER_TYPE:
   26911     27937076 :     case REFERENCE_TYPE:
   26912              :       /* We must set TREE_ASM_WRITTEN in case this is a recursive type.  This
   26913              :          ensures that the gen_type_die recursion will terminate even if the
   26914              :          type is recursive.  Recursive types are possible in Ada.  */
   26915              :       /* ??? We could perhaps do this for all types before the switch
   26916              :          statement.  */
   26917     27937076 :       TREE_ASM_WRITTEN (type) = 1;
   26918              : 
   26919              :       /* For these types, all that is required is that we output a DIE (or a
   26920              :          set of DIEs) to represent the "basis" type.  */
   26921     27937076 :       gen_type_die_with_usage (TREE_TYPE (type), context_die,
   26922              :                                DINFO_USAGE_IND_USE);
   26923     27937076 :       break;
   26924              : 
   26925        31003 :     case OFFSET_TYPE:
   26926              :       /* This code is used for C++ pointer-to-data-member types.
   26927              :          Output a description of the relevant class type.  */
   26928        31003 :       gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
   26929              :                                DINFO_USAGE_IND_USE);
   26930              : 
   26931              :       /* Output a description of the type of the object pointed to.  */
   26932        31003 :       gen_type_die_with_usage (TREE_TYPE (type), context_die,
   26933              :                                DINFO_USAGE_IND_USE);
   26934              : 
   26935              :       /* Now output a DIE to represent this pointer-to-data-member type
   26936              :          itself.  */
   26937        31003 :       gen_ptr_to_mbr_type_die (type, context_die);
   26938        31003 :       break;
   26939              : 
   26940       411685 :     case FUNCTION_TYPE:
   26941              :       /* Force out return type (in case it wasn't forced out already).  */
   26942       411685 :       gen_type_die_with_usage (TREE_TYPE (type), context_die,
   26943              :                                DINFO_USAGE_DIR_USE);
   26944       411685 :       gen_subroutine_type_die (type, context_die);
   26945       411685 :       break;
   26946              : 
   26947        30518 :     case METHOD_TYPE:
   26948              :       /* Force out return type (in case it wasn't forced out already).  */
   26949        30518 :       gen_type_die_with_usage (TREE_TYPE (type), context_die,
   26950              :                                DINFO_USAGE_DIR_USE);
   26951        30518 :       gen_subroutine_type_die (type, context_die);
   26952        30518 :       break;
   26953              : 
   26954      1034278 :     case ARRAY_TYPE:
   26955      1034278 :     case VECTOR_TYPE:
   26956      1034278 :       gen_array_type_die (type, context_die);
   26957      1034278 :       break;
   26958              : 
   26959    132554244 :     case ENUMERAL_TYPE:
   26960    132554244 :     case RECORD_TYPE:
   26961    132554244 :     case UNION_TYPE:
   26962    132554244 :     case QUAL_UNION_TYPE:
   26963    132554244 :       gen_tagged_type_die (type, context_die, usage, reverse);
   26964    132554244 :       return;
   26965              : 
   26966              :     case VOID_TYPE:
   26967              :     case OPAQUE_TYPE:
   26968              :     case INTEGER_TYPE:
   26969              :     case REAL_TYPE:
   26970              :     case FIXED_POINT_TYPE:
   26971              :     case COMPLEX_TYPE:
   26972              :     case BOOLEAN_TYPE:
   26973              :     case BITINT_TYPE:
   26974              :       /* No DIEs needed for fundamental types.  */
   26975              :       break;
   26976              : 
   26977        15250 :     case NULLPTR_TYPE:
   26978        15250 :     case LANG_TYPE:
   26979        15250 :     unspecified_type:
   26980              :       /* Just use DW_TAG_unspecified_type.  */
   26981        15250 :       {
   26982        15250 :         dw_die_ref type_die = lookup_type_die (type);
   26983        15250 :         if (type_die == NULL)
   26984              :           {
   26985        15250 :             tree name = TYPE_IDENTIFIER (type);
   26986        15250 :             type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (),
   26987              :                                 type);
   26988        15250 :             add_name_attribute (type_die, IDENTIFIER_POINTER (name));
   26989        15250 :             equate_type_number_to_die (type, type_die);
   26990              :           }
   26991              :       }
   26992              :       break;
   26993              : 
   26994       116252 :     default:
   26995       116252 :       if (is_cxx_auto (type))
   26996              :         {
   26997       116252 :           tree name = TYPE_IDENTIFIER (type);
   26998       116252 :           dw_die_ref *die = (name == get_identifier ("auto")
   26999       116252 :                              ? &auto_die : &decltype_auto_die);
   27000       116252 :           if (!*die)
   27001              :             {
   27002        18759 :               *die = new_die (DW_TAG_unspecified_type,
   27003              :                               comp_unit_die (), NULL_TREE);
   27004        18759 :               add_name_attribute (*die, IDENTIFIER_POINTER (name));
   27005              :             }
   27006       116252 :           equate_type_number_to_die (type, *die);
   27007       116252 :           break;
   27008              :         }
   27009            0 :       if (is_cxx ()
   27010            0 :           && TREE_CODE (type) >= LAST_AND_UNUSED_TREE_CODE
   27011            0 :           && TYPE_P (type)
   27012            0 :           && TYPE_IDENTIFIER (type))
   27013            0 :         goto unspecified_type;
   27014            0 :       gcc_unreachable ();
   27015              :     }
   27016              : 
   27017     30120230 :   TREE_ASM_WRITTEN (type) = 1;
   27018              : }
   27019              : 
   27020              : static void
   27021    889599833 : gen_type_die (tree type, dw_die_ref context_die, bool reverse)
   27022              : {
   27023    889599833 :   if (type != error_mark_node)
   27024              :     {
   27025    889599805 :       gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE, reverse);
   27026    889599805 :       if (flag_checking)
   27027              :         {
   27028    889599782 :           dw_die_ref die = lookup_type_die (type);
   27029    889599782 :           if (die)
   27030    703016898 :             check_die (die);
   27031              :         }
   27032              :     }
   27033    889599833 : }
   27034              : 
   27035              : /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
   27036              :    things which are local to the given block.  */
   27037              : 
   27038              : static void
   27039     24796625 : gen_block_die (tree stmt, dw_die_ref context_die)
   27040              : {
   27041     24796625 :   int must_output_die = 0;
   27042     24796625 :   bool inlined_func;
   27043              : 
   27044              :   /* Ignore blocks that are NULL.  */
   27045     24796625 :   if (stmt == NULL_TREE)
   27046              :     return;
   27047              : 
   27048     24796625 :   inlined_func = inlined_function_outer_scope_p (stmt);
   27049              : 
   27050              :   /* If the block is one fragment of a non-contiguous block, do not
   27051              :      process the variables, since they will have been done by the
   27052              :      origin block.  Do process subblocks.  */
   27053     24796625 :   if (BLOCK_FRAGMENT_ORIGIN (stmt))
   27054              :     {
   27055     11831263 :       tree sub;
   27056              : 
   27057     11831263 :       for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
   27058            0 :         gen_block_die (sub, context_die);
   27059              : 
   27060              :       return;
   27061              :     }
   27062              : 
   27063              :   /* Determine if we need to output any Dwarf DIEs at all to represent this
   27064              :      block.  */
   27065     12965362 :   if (inlined_func)
   27066              :     /* The outer scopes for inlinings *must* always be represented.  We
   27067              :        generate DW_TAG_inlined_subroutine DIEs for them.  (See below.) */
   27068              :     must_output_die = 1;
   27069      5821707 :   else if (lookup_block_die (stmt))
   27070              :     /* If we already have a DIE then it was filled early.  Meanwhile
   27071              :        we might have pruned all BLOCK_VARS as optimized out but we
   27072              :        still want to generate high/low PC attributes so output it.  */
   27073              :     must_output_die = 1;
   27074      5558365 :   else if (TREE_USED (stmt)
   27075         8396 :            || TREE_ASM_WRITTEN (stmt))
   27076              :     {
   27077              :       /* Determine if this block directly contains any "significant"
   27078              :          local declarations which we will need to output DIEs for.  */
   27079      5556398 :       if (debug_info_level > DINFO_LEVEL_TERSE)
   27080              :         {
   27081              :           /* We are not in terse mode so any local declaration that
   27082              :              is not ignored for debug purposes counts as being a
   27083              :              "significant" one.  */
   27084      5471236 :           if (BLOCK_NUM_NONLOCALIZED_VARS (stmt))
   27085              :             must_output_die = 1;
   27086              :           else
   27087      5721755 :             for (tree var = BLOCK_VARS (stmt); var; var = DECL_CHAIN (var))
   27088      1057641 :               if (!DECL_IGNORED_P (var))
   27089              :                 {
   27090              :                   must_output_die = 1;
   27091              :                   break;
   27092              :                 }
   27093              :         }
   27094        85162 :       else if (!dwarf2out_ignore_block (stmt))
   27095              :         must_output_die = 1;
   27096              :     }
   27097              : 
   27098              :   /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
   27099              :      DIE for any block which contains no significant local declarations at
   27100              :      all.  Rather, in such cases we just call `decls_for_scope' so that any
   27101              :      needed Dwarf info for any sub-blocks will get properly generated. Note
   27102              :      that in terse mode, our definition of what constitutes a "significant"
   27103              :      local declaration gets restricted to include only inlined function
   27104              :      instances and local (nested) function definitions.  */
   27105      5464016 :   if (must_output_die)
   27106              :     {
   27107      8214172 :       if (inlined_func)
   27108      7143655 :         gen_inlined_subroutine_die (stmt, context_die);
   27109              :       else
   27110      1070517 :         gen_lexical_block_die (stmt, context_die);
   27111              :     }
   27112              :   else
   27113      4751190 :     decls_for_scope (stmt, context_die);
   27114              : }
   27115              : 
   27116              : /* Process variable DECL (or variable with origin ORIGIN) within
   27117              :    block STMT and add it to CONTEXT_DIE.  */
   27118              : static void
   27119     19611983 : process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
   27120              : {
   27121     19611983 :   dw_die_ref die;
   27122     19611983 :   tree decl_or_origin = decl ? decl : origin;
   27123              : 
   27124     19611983 :   if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
   27125        16014 :     die = lookup_decl_die (decl_or_origin);
   27126     19595969 :   else if (TREE_CODE (decl_or_origin) == TYPE_DECL)
   27127              :     {
   27128       848800 :       if (TYPE_DECL_IS_STUB (decl_or_origin))
   27129       173271 :         die = lookup_type_die (TREE_TYPE (decl_or_origin));
   27130              :       else
   27131       675529 :         die = lookup_decl_die (decl_or_origin);
   27132              :       /* Avoid re-creating the DIE late if it was optimized as unused early.  */
   27133       848800 :       if (! die && ! early_dwarf)
   27134              :         return;
   27135              :     }
   27136              :   else
   27137              :     die = NULL;
   27138              : 
   27139              :   /* Avoid creating DIEs for local typedefs and concrete static variables that
   27140              :      will only be pruned later.  */
   27141     19046327 :   if ((origin || decl_ultimate_origin (decl))
   27142     34089861 :       && (TREE_CODE (decl_or_origin) == TYPE_DECL
   27143     14953307 :           || (VAR_P (decl_or_origin) && TREE_STATIC (decl_or_origin))))
   27144              :     {
   27145       152268 :       origin = decl_ultimate_origin (decl_or_origin);
   27146       152268 :       if (decl && VAR_P (decl) && die != NULL)
   27147              :         {
   27148            0 :           die = lookup_decl_die (origin);
   27149            0 :           if (die != NULL)
   27150            0 :             equate_decl_number_to_die (decl, die);
   27151              :         }
   27152              :       return;
   27153              :     }
   27154              : 
   27155     18954103 :   if (die != NULL && die->die_parent == NULL)
   27156         9576 :     add_child_die (context_die, die);
   27157              : 
   27158     18954103 :   if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
   27159              :     {
   27160        11451 :       if (early_dwarf)
   27161         5582 :         dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
   27162              :                                              stmt, context_die);
   27163              :     }
   27164              :   else
   27165              :     {
   27166     18942652 :       if (decl && DECL_P (decl))
   27167              :         {
   27168     18942637 :           die = lookup_decl_die (decl);
   27169              : 
   27170              :           /* Early created DIEs do not have a parent as the decls refer
   27171              :              to the function as DECL_CONTEXT rather than the BLOCK.  */
   27172     18942637 :           if (die && die->die_parent == NULL)
   27173              :             {
   27174         3004 :               gcc_assert (in_lto_p);
   27175         3004 :               add_child_die (context_die, die);
   27176              :             }
   27177              :         }
   27178              : 
   27179     18942652 :       gen_decl_die (decl, origin, NULL, context_die);
   27180              :     }
   27181              : }
   27182              : 
   27183              : /* Generate all of the decls declared within a given scope and (recursively)
   27184              :    all of its sub-blocks.  */
   27185              : 
   27186              : static void
   27187     19220499 : decls_for_scope (tree stmt, dw_die_ref context_die, bool recurse)
   27188              : {
   27189     19220499 :   tree decl;
   27190     19220499 :   unsigned int i;
   27191     19220499 :   tree subblocks;
   27192              : 
   27193              :   /* Ignore NULL blocks.  */
   27194     19220499 :   if (stmt == NULL_TREE)
   27195              :     return;
   27196              : 
   27197              :   /* Output the DIEs to represent all of the data objects and typedefs
   27198              :      declared directly within this block but not within any nested
   27199              :      sub-blocks.  Also, nested function and tag DIEs have been
   27200              :      generated with a parent of NULL; fix that up now.  We don't
   27201              :      have to do this if we're at -g1.  */
   27202     19220499 :   if (debug_info_level > DINFO_LEVEL_TERSE)
   27203              :     {
   27204     38656335 :       for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
   27205     19548300 :         process_scope_var (stmt, decl, NULL_TREE, context_die);
   27206              :       /* BLOCK_NONLOCALIZED_VARs simply generate DIE stubs with abstract
   27207              :          origin - avoid doing this twice as we have no good way to see
   27208              :          if we've done it once already.  */
   27209     19108035 :       if (! early_dwarf)
   27210     13572605 :         for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
   27211              :           {
   27212        63687 :             decl = BLOCK_NONLOCALIZED_VAR (stmt, i);
   27213        63687 :             if (decl == current_function_decl)
   27214              :               /* Ignore declarations of the current function, while they
   27215              :                  are declarations, gen_subprogram_die would treat them
   27216              :                  as definitions again, because they are equal to
   27217              :                  current_function_decl and endlessly recurse.  */;
   27218        63683 :             else if (TREE_CODE (decl) == FUNCTION_DECL)
   27219         3639 :               process_scope_var (stmt, decl, NULL_TREE, context_die);
   27220              :             else
   27221        60044 :               process_scope_var (stmt, NULL_TREE, decl, context_die);
   27222              :           }
   27223              :     }
   27224              : 
   27225              :   /* Even if we're at -g1, we need to process the subblocks in order to get
   27226              :      inlined call information.  */
   27227              : 
   27228              :   /* Output the DIEs to represent all sub-blocks (and the items declared
   27229              :      therein) of this block.  */
   27230     19220499 :   if (recurse)
   27231     37150056 :     for (subblocks = BLOCK_SUBBLOCKS (stmt);
   27232     37150056 :          subblocks != NULL;
   27233     21352415 :          subblocks = BLOCK_CHAIN (subblocks))
   27234     21352415 :       gen_block_die (subblocks, context_die);
   27235              : }
   27236              : 
   27237              : /* Is this a typedef we can avoid emitting?  */
   27238              : 
   27239              : static bool
   27240   1422842244 : is_redundant_typedef (const_tree decl)
   27241              : {
   27242   1422842244 :   if (TYPE_DECL_IS_STUB (decl))
   27243              :     return true;
   27244              : 
   27245    466904073 :   if (DECL_ARTIFICIAL (decl)
   27246    290335585 :       && DECL_CONTEXT (decl)
   27247     94211121 :       && is_tagged_type (DECL_CONTEXT (decl))
   27248     93771695 :       && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
   27249    560675768 :       && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
   27250              :     /* Also ignore the artificial member typedef for the class name.  */
   27251     93771591 :     return true;
   27252              : 
   27253              :   return false;
   27254              : }
   27255              : 
   27256              : /* Return TRUE if TYPE is a typedef that names a type for linkage
   27257              :    purposes. This kind of typedefs is produced by the C++ FE for
   27258              :    constructs like:
   27259              : 
   27260              :    typedef struct {...} foo;
   27261              : 
   27262              :    In that case, there is no typedef variant type produced for foo.
   27263              :    Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
   27264              :    struct type.  */
   27265              : 
   27266              : static bool
   27267    881492383 : is_naming_typedef_decl (const_tree decl)
   27268              : {
   27269    881492383 :   if (decl == NULL_TREE
   27270    726996903 :       || TREE_CODE (decl) != TYPE_DECL
   27271    726362372 :       || DECL_NAMELESS (decl)
   27272    726360875 :       || !is_tagged_type (TREE_TYPE (decl))
   27273    498629413 :       || DECL_IS_UNDECLARED_BUILTIN (decl)
   27274    498575584 :       || is_redundant_typedef (decl)
   27275              :       /* It looks like Ada produces TYPE_DECLs that are very similar
   27276              :          to C++ naming typedefs but that have different
   27277              :          semantics. Let's be specific to c++ for now.  */
   27278    904485060 :       || !is_cxx (decl))
   27279              :     return false;
   27280              : 
   27281     22521236 :   return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
   27282       801492 :           && TYPE_NAME (TREE_TYPE (decl)) == decl
   27283     23322722 :           && (TYPE_STUB_DECL (TREE_TYPE (decl))
   27284       801486 :               != TYPE_NAME (TREE_TYPE (decl))));
   27285              : }
   27286              : 
   27287              : /* Looks up the DIE for a context.  */
   27288              : 
   27289              : static inline dw_die_ref
   27290       300346 : lookup_context_die (tree context)
   27291              : {
   27292       300346 :   if (context)
   27293              :     {
   27294              :       /* Find die that represents this context.  */
   27295        74305 :       if (TYPE_P (context))
   27296              :         {
   27297           13 :           context = TYPE_MAIN_VARIANT (context);
   27298           13 :           dw_die_ref ctx = lookup_type_die (context);
   27299           13 :           if (!ctx)
   27300              :             return NULL;
   27301           12 :           return strip_naming_typedef (context, ctx);
   27302              :         }
   27303              :       else
   27304        74292 :         return lookup_decl_die (context);
   27305              :     }
   27306       226041 :   return comp_unit_die ();
   27307              : }
   27308              : 
   27309              : /* Returns the DIE for a context.  */
   27310              : 
   27311              : static inline dw_die_ref
   27312     84828257 : get_context_die (tree context)
   27313              : {
   27314     84828257 :   if (context)
   27315              :     {
   27316              :       /* Find die that represents this context.  */
   27317     84676091 :       if (TYPE_P (context))
   27318              :         {
   27319     21213756 :           context = TYPE_MAIN_VARIANT (context);
   27320     21213756 :           return strip_naming_typedef (context, force_type_die (context));
   27321              :         }
   27322              :       else
   27323     63462335 :         return force_decl_die (context);
   27324              :     }
   27325       152166 :   return comp_unit_die ();
   27326              : }
   27327              : 
   27328              : /* Returns the DIE for decl.  A DIE will always be returned.  */
   27329              : 
   27330              : static dw_die_ref
   27331    222655762 : force_decl_die (tree decl)
   27332              : {
   27333    222655762 :   dw_die_ref decl_die;
   27334    222655762 :   unsigned saved_external_flag;
   27335    222655762 :   tree save_fn = NULL_TREE;
   27336    222655762 :   decl_die = lookup_decl_die (decl);
   27337    222655762 :   if (!decl_die)
   27338              :     {
   27339      2975498 :       dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
   27340              : 
   27341      2975498 :       decl_die = lookup_decl_die (decl);
   27342      2975498 :       if (decl_die)
   27343              :         return decl_die;
   27344              : 
   27345      2975498 :       switch (TREE_CODE (decl))
   27346              :         {
   27347      2464940 :         case FUNCTION_DECL:
   27348              :           /* Clear current_function_decl, so that gen_subprogram_die thinks
   27349              :              that this is a declaration. At this point, we just want to force
   27350              :              declaration die.  */
   27351      2464940 :           save_fn = current_function_decl;
   27352      2464940 :           current_function_decl = NULL_TREE;
   27353      2464940 :           gen_subprogram_die (decl, context_die);
   27354      2464940 :           current_function_decl = save_fn;
   27355      2464940 :           break;
   27356              : 
   27357          567 :         case VAR_DECL:
   27358              :           /* Set external flag to force declaration die. Restore it after
   27359              :            gen_decl_die() call.  */
   27360          567 :           saved_external_flag = DECL_EXTERNAL (decl);
   27361          567 :           DECL_EXTERNAL (decl) = 1;
   27362          567 :           gen_decl_die (decl, NULL, NULL, context_die);
   27363          567 :           DECL_EXTERNAL (decl) = saved_external_flag;
   27364          567 :           break;
   27365              : 
   27366       509985 :         case NAMESPACE_DECL:
   27367       509985 :           if (dwarf_version >= 3 || !dwarf_strict)
   27368       509985 :             dwarf2out_decl (decl);
   27369              :           else
   27370              :             /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace.  */
   27371            0 :             decl_die = comp_unit_die ();
   27372              :           break;
   27373              : 
   27374            0 :         case CONST_DECL:
   27375              :           /* Enumerators shouldn't need force_decl_die.  */
   27376            0 :           gcc_assert (DECL_CONTEXT (decl) == NULL_TREE
   27377              :                       || TREE_CODE (DECL_CONTEXT (decl)) != ENUMERAL_TYPE);
   27378            0 :           gen_decl_die (decl, NULL, NULL, context_die);
   27379            0 :           break;
   27380              : 
   27381            6 :         case TRANSLATION_UNIT_DECL:
   27382            6 :           decl_die = comp_unit_die ();
   27383            6 :           break;
   27384              : 
   27385            0 :         default:
   27386            0 :           gcc_unreachable ();
   27387              :         }
   27388              : 
   27389              :       /* We should be able to find the DIE now.  */
   27390      2975498 :       if (!decl_die)
   27391      2975492 :         decl_die = lookup_decl_die (decl);
   27392      2975492 :       gcc_assert (decl_die);
   27393              :     }
   27394              : 
   27395              :   return decl_die;
   27396              : }
   27397              : 
   27398              : /* Returns the DIE for TYPE, that must not be a base type.  A DIE is
   27399              :    always returned.  */
   27400              : 
   27401              : static dw_die_ref
   27402     21857235 : force_type_die (tree type)
   27403              : {
   27404     21857235 :   dw_die_ref type_die;
   27405              : 
   27406     21857235 :   type_die = lookup_type_die (type);
   27407     21857235 :   if (!type_die)
   27408              :     {
   27409       500687 :       dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
   27410              : 
   27411       500687 :       type_die = modified_type_die (type, TYPE_QUALS_NO_ADDR_SPACE (type),
   27412       500687 :                                     TYPE_ATTRIBUTES (type),
   27413              :                                     false, context_die);
   27414       500687 :       gcc_assert (type_die);
   27415              :     }
   27416     21857235 :   return type_die;
   27417              : }
   27418              : 
   27419              : /* Force out any required namespaces to be able to output DECL,
   27420              :    and return the new context_die for it, if it's changed.  */
   27421              : 
   27422              : static dw_die_ref
   27423    285092247 : setup_namespace_context (tree thing, dw_die_ref context_die)
   27424              : {
   27425    285092247 :   tree context = (DECL_P (thing)
   27426    285092247 :                   ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
   27427    285092247 :   if (context && TREE_CODE (context) == NAMESPACE_DECL)
   27428              :     /* Force out the namespace.  */
   27429    156695937 :     context_die = force_decl_die (context);
   27430              : 
   27431    285092247 :   return context_die;
   27432              : }
   27433              : 
   27434              : /* Emit a declaration DIE for THING (which is either a DECL or a tagged
   27435              :    type) within its namespace, if appropriate.
   27436              : 
   27437              :    For compatibility with older debuggers, namespace DIEs only contain
   27438              :    declarations; all definitions are emitted at CU scope, with
   27439              :    DW_AT_specification pointing to the declaration (like with class
   27440              :    members).  */
   27441              : 
   27442              : static dw_die_ref
   27443    284650436 : declare_in_namespace (tree thing, dw_die_ref context_die)
   27444              : {
   27445    284650436 :   dw_die_ref ns_context;
   27446              : 
   27447    284650436 :   if (debug_info_level <= DINFO_LEVEL_TERSE)
   27448              :     return context_die;
   27449              : 
   27450              :   /* External declarations in the local scope only need to be emitted
   27451              :      once, not once in the namespace and once in the scope.
   27452              : 
   27453              :      This avoids declaring the `extern' below in the
   27454              :      namespace DIE as well as in the innermost scope:
   27455              : 
   27456              :           namespace S
   27457              :           {
   27458              :             int i=5;
   27459              :             int foo()
   27460              :             {
   27461              :               int i=8;
   27462              :               extern int i;
   27463              :               return i;
   27464              :             }
   27465              :           }
   27466              :   */
   27467    381924853 :   if (DECL_P (thing) && DECL_EXTERNAL (thing) && local_scope_p (context_die))
   27468              :     return context_die;
   27469              : 
   27470              :   /* If this decl is from an inlined function, then don't try to emit it in its
   27471              :      namespace, as we will get confused.  It would have already been emitted
   27472              :      when the abstract instance of the inline function was emitted anyways.  */
   27473    284591514 :   if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
   27474              :     return context_die;
   27475              : 
   27476    284570814 :   ns_context = setup_namespace_context (thing, context_die);
   27477              : 
   27478    284570814 :   if (ns_context != context_die)
   27479              :     {
   27480     77845916 :       if (is_fortran () || is_dlang ())
   27481              :         return ns_context;
   27482     77831919 :       if (DECL_P (thing))
   27483     16033891 :         gen_decl_die (thing, NULL, NULL, ns_context);
   27484              :       else
   27485     61798028 :         gen_type_die (thing, ns_context);
   27486              :     }
   27487              :   return context_die;
   27488              : }
   27489              : 
   27490              : /* Generate a DIE for a namespace or namespace alias.  */
   27491              : 
   27492              : static void
   27493       521474 : gen_namespace_die (tree decl, dw_die_ref context_die)
   27494              : {
   27495       521474 :   dw_die_ref namespace_die;
   27496              : 
   27497              :   /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
   27498              :      they are an alias of.  */
   27499       521474 :   if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
   27500              :     {
   27501              :       /* Output a real namespace or module.  */
   27502       509985 :       context_die = setup_namespace_context (decl, comp_unit_die ());
   27503       511667 :       namespace_die = new_die (is_fortran () || is_dlang () || is_ada ()
   27504              :                                ? DW_TAG_module : DW_TAG_namespace,
   27505              :                                context_die, decl);
   27506              :       /* For Fortran modules defined in different CU don't add src coords.  */
   27507       509985 :       if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
   27508              :         {
   27509          195 :           const char *name = dwarf2_name (decl, 0);
   27510          195 :           if (name)
   27511          195 :             add_name_attribute (namespace_die, name);
   27512              :         }
   27513              :       else
   27514       509790 :         add_name_and_src_coords_attributes (namespace_die, decl);
   27515       509985 :       if (DECL_EXTERNAL (decl))
   27516          195 :         add_AT_flag (namespace_die, DW_AT_declaration, 1);
   27517       509985 :       equate_decl_number_to_die (decl, namespace_die);
   27518              :     }
   27519              :   else
   27520              :     {
   27521              :       /* Output a namespace alias.  */
   27522              : 
   27523              :       /* Force out the namespace we are an alias of, if necessary.  */
   27524        11489 :       dw_die_ref origin_die
   27525        11489 :         = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
   27526              : 
   27527        22978 :       if (DECL_FILE_SCOPE_P (decl)
   27528        20963 :           || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
   27529        11448 :         context_die = setup_namespace_context (decl, comp_unit_die ());
   27530              :       /* Now create the namespace alias DIE.  */
   27531        11489 :       namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
   27532        11489 :       add_name_and_src_coords_attributes (namespace_die, decl);
   27533        11489 :       add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
   27534        11489 :       equate_decl_number_to_die (decl, namespace_die);
   27535              :     }
   27536          313 :   if ((dwarf_version >= 5 || !dwarf_strict)
   27537       521787 :       && lang_hooks.decls.decl_dwarf_attribute (decl,
   27538              :                                                 DW_AT_export_symbols) == 1)
   27539       113530 :     add_AT_flag (namespace_die, DW_AT_export_symbols, 1);
   27540              : 
   27541              :   /* Bypass dwarf2_name's check for DECL_NAMELESS.  */
   27542       521474 :   if (want_pubnames ())
   27543           33 :     add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
   27544       521474 : }
   27545              : 
   27546              : /* Generate Dwarf debug information for a decl described by DECL.
   27547              :    The return value is currently only meaningful for PARM_DECLs,
   27548              :    for all other decls it returns NULL.
   27549              : 
   27550              :    If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
   27551              :    It can be NULL otherwise.  */
   27552              : 
   27553              : static dw_die_ref
   27554    411550843 : gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
   27555              :               dw_die_ref context_die)
   27556              : {
   27557    411550843 :   tree decl_or_origin = decl ? decl : origin;
   27558    411550843 :   tree class_origin = NULL, ultimate_origin;
   27559              : 
   27560    411550843 :   if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
   27561              :     return NULL;
   27562              : 
   27563    353661956 :   switch (TREE_CODE (decl_or_origin))
   27564              :     {
   27565              :     case ERROR_MARK:
   27566              :       break;
   27567              : 
   27568       401911 :     case CONST_DECL:
   27569       401911 :       if (!is_fortran () && !is_ada () && !is_dlang ())
   27570              :         {
   27571              :           /* The individual enumerators of an enum type get output when we output
   27572              :              the Dwarf representation of the relevant enum type itself.  */
   27573              :           break;
   27574              :         }
   27575              : 
   27576              :       /* Emit its type.  */
   27577        26722 :       gen_type_die (TREE_TYPE (decl), context_die);
   27578              : 
   27579              :       /* And its containing namespace.  */
   27580        26722 :       context_die = declare_in_namespace (decl, context_die);
   27581              : 
   27582        26722 :       gen_const_die (decl, context_die);
   27583        26722 :       break;
   27584              : 
   27585     96869228 :     case FUNCTION_DECL:
   27586              : #if 0
   27587              :       /* FIXME */
   27588              :       /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
   27589              :          on local redeclarations of global functions.  That seems broken.  */
   27590              :       if (current_function_decl != decl)
   27591              :         /* This is only a declaration.  */;
   27592              : #endif
   27593              : 
   27594              :       /* We should have abstract copies already and should not generate
   27595              :          stray type DIEs in late LTO dumping.  */
   27596     96869228 :       if (! early_dwarf)
   27597              :         ;
   27598              : 
   27599              :       /* If we're emitting a clone, emit info for the abstract instance.  */
   27600     96643026 :       else if (origin || DECL_ORIGIN (decl) != decl)
   27601       708998 :         dwarf2out_abstract_function (origin
   27602            0 :                                      ? DECL_ORIGIN (origin)
   27603       354499 :                                      : DECL_ABSTRACT_ORIGIN (decl));
   27604              : 
   27605              :       /* If we're emitting a possibly inlined function emit it as
   27606              :          abstract instance.  */
   27607     95930518 :       else if (cgraph_function_possibly_inlined_p (decl)
   27608     93191449 :                && ! DECL_ABSTRACT_P (decl)
   27609     74592012 :                && ! class_or_namespace_scope_p (context_die)
   27610              :                /* dwarf2out_abstract_function won't emit a die if this is just
   27611              :                   a declaration.  We must avoid setting DECL_ABSTRACT_ORIGIN in
   27612              :                   that case, because that works only if we have a die.  */
   27613     95930518 :                && DECL_INITIAL (decl) != NULL_TREE)
   27614            0 :         dwarf2out_abstract_function (decl);
   27615              : 
   27616              :       /* Otherwise we're emitting the primary DIE for this decl.  */
   27617     95930518 :       else if (debug_info_level > DINFO_LEVEL_TERSE)
   27618              :         {
   27619              :           /* Before we describe the FUNCTION_DECL itself, make sure that we
   27620              :              have its containing type.  */
   27621     95916750 :           if (!origin)
   27622     95916750 :             origin = decl_class_context (decl);
   27623     95916750 :           if (origin != NULL_TREE)
   27624     94634592 :             gen_type_die (origin, context_die);
   27625              : 
   27626              :           /* And its return type.  */
   27627     95916750 :           gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
   27628              : 
   27629              :           /* And its virtual context.  */
   27630     95916750 :           if (DECL_VINDEX (decl) != NULL_TREE)
   27631      1102424 :             gen_type_die (DECL_CONTEXT (decl), context_die);
   27632              : 
   27633              :           /* Make sure we have a member DIE for decl.  */
   27634     95916750 :           if (origin != NULL_TREE)
   27635     94634592 :             gen_type_die_for_member (origin, decl, context_die);
   27636              : 
   27637              :           /* And its containing namespace.  */
   27638     95916750 :           context_die = declare_in_namespace (decl, context_die);
   27639              :         }
   27640              : 
   27641              :       /* Now output a DIE to represent the function itself.  */
   27642     96869228 :       if (decl)
   27643     96869228 :         gen_subprogram_die (decl, context_die);
   27644              :       break;
   27645              : 
   27646    159053569 :     case TYPE_DECL:
   27647              :       /* If we are in terse mode, don't generate any DIEs to represent any
   27648              :          actual typedefs.  */
   27649    159053569 :       if (debug_info_level <= DINFO_LEVEL_TERSE)
   27650              :         break;
   27651              : 
   27652              :       /* In the special case of a TYPE_DECL node representing the declaration
   27653              :          of some type tag, if the given TYPE_DECL is marked as having been
   27654              :          instantiated from some other (original) TYPE_DECL node (e.g. one which
   27655              :          was generated within the original definition of an inline function) we
   27656              :          used to generate a special (abbreviated) DW_TAG_structure_type,
   27657              :          DW_TAG_union_type, or DW_TAG_enumeration_type DIE here.  But nothing
   27658              :          should be actually referencing those DIEs, as variable DIEs with that
   27659              :          type would be emitted already in the abstract origin, so it was always
   27660              :          removed during unused type pruning.  Don't add anything in this
   27661              :          case.  */
   27662    159053569 :       if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
   27663              :         break;
   27664              : 
   27665    159053569 :       if (is_redundant_typedef (decl))
   27666     98150996 :         gen_type_die (TREE_TYPE (decl), context_die);
   27667              :       else
   27668              :         /* Output a DIE to represent the typedef itself.  */
   27669     60902573 :         gen_typedef_die (decl, context_die);
   27670              :       break;
   27671              : 
   27672       106800 :     case LABEL_DECL:
   27673       106800 :       if (debug_info_level >= DINFO_LEVEL_NORMAL)
   27674       106800 :         gen_label_die (decl, context_die);
   27675              :       break;
   27676              : 
   27677     74626712 :     case VAR_DECL:
   27678     74626712 :     case RESULT_DECL:
   27679              :       /* If we are in terse mode, don't generate any DIEs to represent any
   27680              :          variable declarations or definitions unless it is external.  */
   27681     74626712 :       if (debug_info_level < DINFO_LEVEL_TERSE
   27682     74626712 :           || (debug_info_level == DINFO_LEVEL_TERSE
   27683         1218 :               && !TREE_PUBLIC (decl_or_origin)))
   27684              :         break;
   27685              : 
   27686     74626712 :       if (debug_info_level > DINFO_LEVEL_TERSE)
   27687              :         {
   27688              :           /* Avoid generating stray type DIEs during late dwarf dumping.
   27689              :              All types have been dumped early.  */
   27690     74625494 :           if (early_dwarf
   27691              :               /* ???  But in LTRANS we cannot annotate early created variably
   27692              :                  modified type DIEs without copying them and adjusting all
   27693              :                  references to them.  Dump them again as happens for inlining
   27694              :                  which copies both the decl and the types.  */
   27695              :               /* ???  And even non-LTO needs to re-visit type DIEs to fill
   27696              :                  in VLA bound information for example.  */
   27697     74625494 :               || (decl && variably_modified_type_p (TREE_TYPE (decl),
   27698              :                                                     current_function_decl)))
   27699              :             {
   27700              :               /* Output any DIEs that are needed to specify the type of this data
   27701              :                  object.  */
   27702     58604115 :               if (decl_by_reference_p (decl_or_origin))
   27703         3508 :                 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
   27704              :               else
   27705     58600607 :                 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
   27706              :             }
   27707              : 
   27708     74625494 :           if (early_dwarf)
   27709              :             {
   27710              :               /* And its containing type.  */
   27711     58598226 :               class_origin = decl_class_context (decl_or_origin);
   27712     58598226 :               if (class_origin != NULL_TREE)
   27713     24572313 :                 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
   27714              : 
   27715              :               /* And its containing namespace.  */
   27716     58598226 :               context_die = declare_in_namespace (decl_or_origin, context_die);
   27717              :             }
   27718              :         }
   27719              : 
   27720              :       /* Now output the DIE to represent the data object itself.  This gets
   27721              :          complicated because of the possibility that the VAR_DECL really
   27722              :          represents an inlined instance of a formal parameter for an inline
   27723              :          function.  */
   27724     74626712 :       ultimate_origin = decl_ultimate_origin (decl_or_origin);
   27725     74626712 :       if (ultimate_origin != NULL_TREE
   27726     14853278 :           && TREE_CODE (ultimate_origin) == PARM_DECL)
   27727     13146304 :         gen_formal_parameter_die (decl, origin,
   27728              :                                   true /* Emit name attribute.  */,
   27729              :                                   context_die);
   27730              :       else
   27731     61480408 :         gen_variable_die (decl, origin, context_die);
   27732              :       break;
   27733              : 
   27734     16658299 :     case FIELD_DECL:
   27735     16658299 :       gcc_assert (ctx != NULL && ctx->struct_type != NULL);
   27736              :       /* Ignore the nameless fields that are used to skip bits but handle C++
   27737              :          anonymous unions and structs.  */
   27738     16658299 :       if (DECL_NAME (decl) != NULL_TREE
   27739       344303 :           || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
   27740     16836455 :           || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
   27741              :         {
   27742     16518816 :           gen_type_die (member_declared_type (decl), context_die);
   27743     16518816 :           gen_field_die (decl, ctx, context_die);
   27744              :         }
   27745              :       break;
   27746              : 
   27747      5136505 :     case PARM_DECL:
   27748              :       /* Avoid generating stray type DIEs during late dwarf dumping.
   27749              :          All types have been dumped early.  */
   27750      5136505 :       if (early_dwarf
   27751              :           /* ???  But in LTRANS we cannot annotate early created variably
   27752              :              modified type DIEs without copying them and adjusting all
   27753              :              references to them.  Dump them again as happens for inlining
   27754              :              which copies both the decl and the types.  */
   27755              :           /* ???  And even non-LTO needs to re-visit type DIEs to fill
   27756              :              in VLA bound information for example.  */
   27757      5136505 :           || (decl && variably_modified_type_p (TREE_TYPE (decl),
   27758              :                                                 current_function_decl)))
   27759              :         {
   27760      4107518 :           if (DECL_BY_REFERENCE (decl_or_origin))
   27761        46672 :             gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
   27762              :           else
   27763      4060846 :             gen_type_die (TREE_TYPE (decl_or_origin), context_die);
   27764              :         }
   27765      5136505 :       return gen_formal_parameter_die (decl, origin,
   27766              :                                        true /* Emit name attribute.  */,
   27767      5136505 :                                        context_die);
   27768              : 
   27769       521474 :     case NAMESPACE_DECL:
   27770       521474 :       if (dwarf_version >= 3 || !dwarf_strict)
   27771       521474 :         gen_namespace_die (decl, context_die);
   27772              :       break;
   27773              : 
   27774            0 :     case IMPORTED_DECL:
   27775            0 :       dwarf2out_imported_module_or_decl_1 (decl, DECL_NAME (decl),
   27776            0 :                                            DECL_CONTEXT (decl), context_die);
   27777            0 :       break;
   27778              : 
   27779          251 :     case NAMELIST_DECL:
   27780          251 :       gen_namelist_decl (DECL_NAME (decl), context_die,
   27781          251 :                          NAMELIST_DECL_ASSOCIATED_DECL (decl));
   27782          251 :       break;
   27783              : 
   27784       287207 :     default:
   27785              :       /* Probably some frontend-internal decl.  Assume we don't care.  */
   27786       287207 :       gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
   27787              :       break;
   27788              :     }
   27789              : 
   27790    348525451 :   maybe_gen_btf_decl_tag_dies (decl_or_origin,
   27791              :                                lookup_decl_die (decl_or_origin));
   27792              : 
   27793    348525451 :   return NULL;
   27794              : }
   27795              : 
   27796              : /* Output initial debug information for global DECL.  Called at the
   27797              :    end of the parsing process.
   27798              : 
   27799              :    This is the initial debug generation process.  As such, the DIEs
   27800              :    generated may be incomplete.  A later debug generation pass
   27801              :    (dwarf2out_late_global_decl) will augment the information generated
   27802              :    in this pass (e.g., with complete location info).  */
   27803              : 
   27804              : static void
   27805     39040441 : dwarf2out_early_global_decl (tree decl)
   27806              : {
   27807     39040441 :   set_early_dwarf s;
   27808              : 
   27809              :   /* gen_decl_die() will set DECL_ABSTRACT because
   27810              :      cgraph_function_possibly_inlined_p() returns true.  This is in
   27811              :      turn will cause DW_AT_inline attributes to be set.
   27812              : 
   27813              :      This happens because at early dwarf generation, there is no
   27814              :      cgraph information, causing cgraph_function_possibly_inlined_p()
   27815              :      to return true.  Trick cgraph_function_possibly_inlined_p()
   27816              :      while we generate dwarf early.  */
   27817     39040441 :   bool save = symtab->global_info_ready;
   27818     39040441 :   symtab->global_info_ready = true;
   27819              : 
   27820              :   /* We don't handle TYPE_DECLs.  If required, they'll be reached via
   27821              :      other DECLs and they can point to template types or other things
   27822              :      that dwarf2out can't handle when done via dwarf2out_decl.  */
   27823     39040441 :   if (TREE_CODE (decl) != TYPE_DECL
   27824     39040441 :       && TREE_CODE (decl) != PARM_DECL)
   27825              :     {
   27826     31772972 :       if (TREE_CODE (decl) == FUNCTION_DECL)
   27827              :         {
   27828      2252087 :           tree save_fndecl = current_function_decl;
   27829              : 
   27830              :           /* For nested functions, make sure we have DIEs for the parents first
   27831              :              so that all nested DIEs are generated at the proper scope in the
   27832              :              first shot.  */
   27833      2252087 :           tree context = decl_function_context (decl);
   27834      2252087 :           if (context != NULL)
   27835              :             {
   27836        50136 :               dw_die_ref context_die = lookup_decl_die (context);
   27837        50136 :               current_function_decl = context;
   27838              : 
   27839              :               /* Avoid emitting DIEs multiple times, but still process CONTEXT
   27840              :                  enough so that it lands in its own context.  This avoids type
   27841              :                  pruning issues later on.  */
   27842        50136 :               if (context_die == NULL || is_declaration_die (context_die))
   27843         3936 :                 dwarf2out_early_global_decl (context);
   27844              :             }
   27845              : 
   27846              :           /* Emit an abstract origin of a function first.  This happens
   27847              :              with C++ constructor clones for example and makes
   27848              :              dwarf2out_abstract_function happy which requires the early
   27849              :              DIE of the abstract instance to be present.  */
   27850      2252087 :           tree origin = DECL_ABSTRACT_ORIGIN (decl);
   27851      2252087 :           dw_die_ref origin_die;
   27852      2252087 :           if (origin != NULL
   27853              :               /* Do not emit the DIE multiple times but make sure to
   27854              :                  process it fully here in case we just saw a declaration.  */
   27855      2252087 :               && ((origin_die = lookup_decl_die (origin)) == NULL
   27856       242461 :                   || is_declaration_die (origin_die)))
   27857              :             {
   27858       338739 :               current_function_decl = origin;
   27859       338739 :               dwarf2out_decl (origin);
   27860              :             }
   27861              : 
   27862              :           /* Emit the DIE for decl but avoid doing that multiple times.  */
   27863      2252087 :           dw_die_ref old_die;
   27864      2252087 :           if ((old_die = lookup_decl_die (decl)) == NULL
   27865      2252087 :               || is_declaration_die (old_die))
   27866              :             {
   27867      2245153 :               current_function_decl = decl;
   27868      2245153 :               dwarf2out_decl (decl);
   27869              :             }
   27870              : 
   27871      2252087 :           current_function_decl = save_fndecl;
   27872              :         }
   27873              :       else
   27874     29520885 :         dwarf2out_decl (decl);
   27875              :     }
   27876     39040441 :   symtab->global_info_ready = save;
   27877     39040441 : }
   27878              : 
   27879              : /* Return whether EXPR is an expression with the following pattern:
   27880              :    INDIRECT_REF (NOP_EXPR (INTEGER_CST)).  */
   27881              : 
   27882              : static bool
   27883           52 : is_trivial_indirect_ref (tree expr)
   27884              : {
   27885           52 :   if (expr == NULL_TREE || TREE_CODE (expr) != INDIRECT_REF)
   27886              :     return false;
   27887              : 
   27888            0 :   tree nop = TREE_OPERAND (expr, 0);
   27889            0 :   if (nop == NULL_TREE || TREE_CODE (nop) != NOP_EXPR)
   27890              :     return false;
   27891              : 
   27892            0 :   tree int_cst = TREE_OPERAND (nop, 0);
   27893            0 :   return int_cst != NULL_TREE && TREE_CODE (int_cst) == INTEGER_CST;
   27894              : }
   27895              : 
   27896              : /* Output debug information for global decl DECL.  Called from
   27897              :    toplev.cc after compilation proper has finished.  */
   27898              : 
   27899              : static void
   27900     33082624 : dwarf2out_late_global_decl (tree decl)
   27901              : {
   27902              :   /* Fill-in any location information we were unable to determine
   27903              :      on the first pass.  */
   27904     33082624 :   if (VAR_P (decl))
   27905              :     {
   27906     33082624 :       dw_die_ref die = lookup_decl_die (decl);
   27907              : 
   27908              :       /* We may have to generate full debug late for LTO in case debug
   27909              :          was not enabled at compile-time or the target doesn't support
   27910              :          the LTO early debug scheme.  */
   27911      5176711 :       if (! die && in_lto_p
   27912              :           /* Function scope variables are emitted when emitting the
   27913              :              DIE for the function.  */
   27914     33084305 :           && ! local_function_static (decl))
   27915         1656 :         dwarf2out_decl (decl);
   27916     33080968 :       else if (die)
   27917              :         {
   27918              :           /* We get called via the symtab code invoking late_global_decl
   27919              :              for symbols that are optimized out.
   27920              : 
   27921              :              Do not add locations for those, except if they have a
   27922              :              DECL_VALUE_EXPR, in which case they are relevant for debuggers.
   27923              :              Still don't add a location if the DECL_VALUE_EXPR is not a trivial
   27924              :              INDIRECT_REF expression, as this could generate relocations to
   27925              :              text symbols in LTO object files, which is invalid.  */
   27926     27905913 :           varpool_node *node = varpool_node::get (decl);
   27927     27905913 :           if ((! node || ! node->definition)
   27928     55568590 :               && ! (DECL_HAS_VALUE_EXPR_P (decl)
   27929           52 :                     && is_trivial_indirect_ref (DECL_VALUE_EXPR (decl))))
   27930     27662625 :             tree_add_const_value_attribute_for_decl (die, decl);
   27931              :           else
   27932              :             {
   27933       243288 :               add_location_or_const_value_attribute (die, decl, false);
   27934              :               /* For C++ structured bindings at namespace scope when processing
   27935              :                  the underlying variable also add locations on the structured
   27936              :                  bindings which refer to it (unless they are tuple-based, then
   27937              :                  they are separate VAR_DECLs registered in varpool).  */
   27938       243288 :               if (tree attr = lookup_attribute ("structured bindings",
   27939       243288 :                                                 DECL_ATTRIBUTES (decl)))
   27940          183 :                 for (tree d = TREE_VALUE (attr); d; d = TREE_CHAIN (d))
   27941              :                   {
   27942          141 :                     die = lookup_decl_die (TREE_VALUE (d));
   27943          141 :                     if (die)
   27944          141 :                       add_location_or_const_value_attribute (die,
   27945          141 :                                                              TREE_VALUE (d),
   27946              :                                                              false);
   27947              :                   }
   27948              :             }
   27949              :         }
   27950              :     }
   27951     33082624 : }
   27952              : 
   27953              : /* Output debug information for type decl DECL.  Called from toplev.cc
   27954              :    and from language front ends (to record built-in types).  */
   27955              : static void
   27956     64387653 : dwarf2out_type_decl (tree decl, int local)
   27957              : {
   27958     64387653 :   if (!local)
   27959              :     {
   27960     57269786 :       set_early_dwarf s;
   27961     57269786 :       dwarf2out_decl (decl);
   27962     57269786 :     }
   27963     64387653 : }
   27964              : 
   27965              : /* Output debug information for imported module or decl DECL.
   27966              :    NAME is non-NULL name in the lexical block if the decl has been renamed.
   27967              :    LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
   27968              :    that DECL belongs to.
   27969              :    LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK.  */
   27970              : static void
   27971      6427014 : dwarf2out_imported_module_or_decl_1 (tree decl,
   27972              :                                      tree name,
   27973              :                                      tree lexical_block,
   27974              :                                      dw_die_ref lexical_block_die)
   27975              : {
   27976      6427014 :   expanded_location xloc;
   27977      6427014 :   dw_die_ref imported_die = NULL;
   27978      6427014 :   dw_die_ref at_import_die;
   27979              : 
   27980      6427014 :   if (TREE_CODE (decl) == IMPORTED_DECL)
   27981              :     {
   27982         5582 :       xloc = expand_location (DECL_SOURCE_LOCATION (decl));
   27983         5582 :       decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
   27984         5582 :       gcc_assert (decl);
   27985              :     }
   27986              :   else
   27987      6421432 :     xloc = expand_location (input_location);
   27988              : 
   27989      6427014 :   if (TREE_CODE (decl) == TYPE_DECL)
   27990              :     {
   27991       643479 :       at_import_die = force_type_die (TREE_TYPE (decl));
   27992              :       /* For namespace N { typedef void T; } using N::T; base_type_die
   27993              :          returns NULL, but DW_TAG_imported_declaration requires
   27994              :          the DW_AT_import tag.  Force creation of DW_TAG_typedef.  */
   27995       643479 :       if (!at_import_die)
   27996              :         {
   27997            0 :           gcc_assert (TREE_CODE (decl) == TYPE_DECL);
   27998            0 :           gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
   27999            0 :           at_import_die = lookup_type_die (TREE_TYPE (decl));
   28000            0 :           gcc_assert (at_import_die);
   28001              :         }
   28002              :     }
   28003              :   else
   28004              :     {
   28005      5783535 :       at_import_die = lookup_decl_die (decl);
   28006      5783535 :       if (!at_import_die)
   28007              :         {
   28008              :           /* If we're trying to avoid duplicate debug info, we may not have
   28009              :              emitted the member decl for this field.  Emit it now.  */
   28010      2246704 :           if (TREE_CODE (decl) == FIELD_DECL)
   28011              :             {
   28012            6 :               tree type = DECL_CONTEXT (decl);
   28013              : 
   28014            6 :               if (TYPE_CONTEXT (type)
   28015            6 :                   && TYPE_P (TYPE_CONTEXT (type))
   28016            6 :                   && !should_emit_struct_debug (TYPE_CONTEXT (type),
   28017              :                                                 DINFO_USAGE_DIR_USE))
   28018            2 :                 return;
   28019            6 :               gen_type_die_for_member (type, decl,
   28020            6 :                                        get_context_die (TYPE_CONTEXT (type)));
   28021              :             }
   28022      2246704 :           if (TREE_CODE (decl) == CONST_DECL)
   28023              :             {
   28024              :               /* Individual enumerators of an enum type do not get output here
   28025              :                  (see gen_decl_die), so we cannot call force_decl_die.  */
   28026            2 :               if (!is_fortran () && !is_ada () && !is_dlang ())
   28027              :                 return;
   28028              :             }
   28029      2246702 :           if (TREE_CODE (decl) == NAMELIST_DECL)
   28030            4 :             at_import_die = gen_namelist_decl (DECL_NAME (decl),
   28031            4 :                                          get_context_die (DECL_CONTEXT (decl)),
   28032              :                                          NULL_TREE);
   28033              :           else
   28034      2246698 :             at_import_die = force_decl_die (decl);
   28035              :         }
   28036              :     }
   28037              : 
   28038      6427012 :   if (TREE_CODE (decl) == NAMESPACE_DECL)
   28039              :     {
   28040        35143 :       if (dwarf_version >= 3 || !dwarf_strict)
   28041        35143 :         imported_die = new_die (DW_TAG_imported_module,
   28042              :                                 lexical_block_die,
   28043              :                                 lexical_block);
   28044              :       else
   28045              :         return;
   28046              :     }
   28047              :   else
   28048      6391869 :     imported_die = new_die (DW_TAG_imported_declaration,
   28049              :                             lexical_block_die,
   28050              :                             lexical_block);
   28051              : 
   28052      6427012 :   add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
   28053      6427012 :   add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
   28054      6427012 :   if (debug_column_info && xloc.column)
   28055      6427012 :     add_AT_unsigned (imported_die, DW_AT_decl_column, xloc.column);
   28056      6427012 :   if (name)
   28057           29 :     add_AT_string (imported_die, DW_AT_name,
   28058           29 :                    IDENTIFIER_POINTER (name));
   28059      6427012 :   add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
   28060              : }
   28061              : 
   28062              : /* Output debug information for imported module or decl DECL.
   28063              :    NAME is non-NULL name in context if the decl has been renamed.
   28064              :    CHILD is true if decl is one of the renamed decls as part of
   28065              :    importing whole module.
   28066              :    IMPLICIT is set if this hook is called for an implicit import
   28067              :    such as inline namespace.  */
   28068              : 
   28069              : static void
   28070      6582433 : dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
   28071              :                                    bool child, bool implicit)
   28072              : {
   28073              :   /* dw_die_ref at_import_die;  */
   28074      6582433 :   dw_die_ref scope_die;
   28075              : 
   28076      6582433 :   if (debug_info_level <= DINFO_LEVEL_TERSE)
   28077       161001 :     return;
   28078              : 
   28079      6582358 :   gcc_assert (decl);
   28080              : 
   28081              :   /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
   28082              :      should be enough, for DWARF4 and older even if we emit as extension
   28083              :      DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
   28084              :      for the benefit of consumers unaware of DW_AT_export_symbols.  */
   28085      6582358 :   if (implicit
   28086       161001 :       && dwarf_version >= 5
   28087      6743284 :       && lang_hooks.decls.decl_dwarf_attribute (decl,
   28088              :                                                 DW_AT_export_symbols) == 1)
   28089              :     return;
   28090              : 
   28091      6421432 :   set_early_dwarf s;
   28092              : 
   28093              :   /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
   28094              :      We need decl DIE for reference and scope die. First, get DIE for the decl
   28095              :      itself.  */
   28096              : 
   28097              :   /* Get the scope die for decl context. Use comp_unit_die for global module
   28098              :      or decl. If die is not found for non globals, force new die.  */
   28099      6421432 :   if (context
   28100      6271323 :       && TYPE_P (context)
   28101      9239542 :       && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
   28102              :     return;
   28103              : 
   28104      6421432 :   scope_die = get_context_die (context);
   28105              : 
   28106      6421432 :   if (child)
   28107              :     {
   28108              :       /* DW_TAG_imported_module was introduced in the DWARFv3 specification, so
   28109              :          there is nothing we can do, here.  */
   28110           13 :       if (dwarf_version < 3 && dwarf_strict)
   28111              :         return;
   28112              : 
   28113           13 :       gcc_assert (scope_die->die_child);
   28114           13 :       gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
   28115           13 :       gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
   28116              :       scope_die = scope_die->die_child;
   28117              :     }
   28118              : 
   28119              :   /* OK, now we have DIEs for decl as well as scope. Emit imported die.  */
   28120      6421432 :   dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
   28121      6421432 : }
   28122              : 
   28123              : /* Output debug information for namelists.   */
   28124              : 
   28125              : static dw_die_ref
   28126          255 : gen_namelist_decl (tree name, dw_die_ref scope_die, tree item_decls)
   28127              : {
   28128          255 :   dw_die_ref nml_die, nml_item_die, nml_item_ref_die;
   28129          255 :   tree value;
   28130          255 :   unsigned i;
   28131              : 
   28132          255 :   if (debug_info_level <= DINFO_LEVEL_TERSE)
   28133              :     return NULL;
   28134              : 
   28135          255 :   gcc_assert (scope_die != NULL);
   28136          255 :   nml_die = new_die (DW_TAG_namelist, scope_die, NULL);
   28137          255 :   add_AT_string (nml_die, DW_AT_name, IDENTIFIER_POINTER (name));
   28138              : 
   28139              :   /* If there are no item_decls, we have a nondefining namelist, e.g.
   28140              :      with USE association; hence, set DW_AT_declaration.  */
   28141          255 :   if (item_decls == NULL_TREE)
   28142              :     {
   28143            4 :       add_AT_flag (nml_die, DW_AT_declaration, 1);
   28144            4 :       return nml_die;
   28145              :     }
   28146              : 
   28147          920 :   FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls), i, value)
   28148              :     {
   28149          669 :       nml_item_ref_die = lookup_decl_die (value);
   28150          669 :       if (!nml_item_ref_die)
   28151          262 :         nml_item_ref_die = force_decl_die (value);
   28152              : 
   28153          669 :       nml_item_die = new_die (DW_TAG_namelist_item, nml_die, NULL);
   28154          669 :       add_AT_die_ref (nml_item_die, DW_AT_namelist_item, nml_item_ref_die);
   28155              :     }
   28156              :   return nml_die;
   28157              : }
   28158              : 
   28159              : 
   28160              : /* Write the debugging output for DECL and return the DIE.  */
   28161              : 
   28162              : static void
   28163     90462203 : dwarf2out_decl (tree decl)
   28164              : {
   28165     90462203 :   dw_die_ref context_die = comp_unit_die ();
   28166              : 
   28167     90462203 :   switch (TREE_CODE (decl))
   28168              :     {
   28169              :     case ERROR_MARK:
   28170              :       return;
   28171              : 
   28172      3159891 :     case FUNCTION_DECL:
   28173              :       /* If we're a nested function, initially use a parent of NULL; if we're
   28174              :          a plain function, this will be fixed up in decls_for_scope.  If
   28175              :          we're a method, it will be ignored, since we already have a DIE.
   28176              :          Avoid doing this late though since clones of class methods may
   28177              :          otherwise end up in limbo and create type DIEs late.  */
   28178      3159891 :       if (early_dwarf
   28179      2583892 :           && decl_function_context (decl)
   28180              :           /* But if we're in terse mode, we don't care about scope.  */
   28181      3219063 :           && debug_info_level > DINFO_LEVEL_TERSE)
   28182              :         context_die = NULL;
   28183              :       break;
   28184              : 
   28185     29507686 :     case VAR_DECL:
   28186              :       /* For local statics lookup proper context die.  */
   28187     29507686 :       if (local_function_static (decl))
   28188           35 :         context_die = lookup_decl_die (DECL_CONTEXT (decl));
   28189              : 
   28190              :       /* If we are in terse mode, don't generate any DIEs to represent any
   28191              :          variable declarations or definitions unless it is external.  */
   28192     29507686 :       if (debug_info_level < DINFO_LEVEL_TERSE
   28193     29507681 :           || (debug_info_level == DINFO_LEVEL_TERSE
   28194         2412 :               && !TREE_PUBLIC (decl)))
   28195              :         return;
   28196              :       break;
   28197              : 
   28198         3384 :     case CONST_DECL:
   28199         3384 :       if (debug_info_level <= DINFO_LEVEL_TERSE)
   28200              :         return;
   28201         3384 :       if (!is_fortran () && !is_ada () && !is_dlang ())
   28202              :         return;
   28203         3384 :       if (TREE_STATIC (decl) && decl_function_context (decl))
   28204         3014 :         context_die = lookup_decl_die (DECL_CONTEXT (decl));
   28205              :       break;
   28206              : 
   28207       521440 :     case NAMESPACE_DECL:
   28208       521440 :     case IMPORTED_DECL:
   28209       521440 :       if (debug_info_level <= DINFO_LEVEL_TERSE)
   28210              :         return;
   28211       521437 :       if (lookup_decl_die (decl) != NULL)
   28212              :         return;
   28213              :       break;
   28214              : 
   28215     57269786 :     case TYPE_DECL:
   28216              :       /* Don't emit stubs for types unless they are needed by other DIEs.  */
   28217     57269786 :       if (TYPE_DECL_SUPPRESS_DEBUG (decl))
   28218              :         return;
   28219              : 
   28220              :       /* Don't bother trying to generate any DIEs to represent any of the
   28221              :          normal built-in types for the language we are compiling.  */
   28222     55543627 :       if (DECL_IS_UNDECLARED_BUILTIN (decl))
   28223              :         return;
   28224              : 
   28225              :       /* If we are in terse mode, don't generate any DIEs for types.  */
   28226     53754593 :       if (debug_info_level <= DINFO_LEVEL_TERSE)
   28227              :         return;
   28228              : 
   28229              :       /* If we're a function-scope tag, initially use a parent of NULL;
   28230              :          this will be fixed up in decls_for_scope.  */
   28231     53753990 :       if (decl_function_context (decl))
   28232     86945373 :         context_die = NULL;
   28233              : 
   28234              :       break;
   28235              : 
   28236              :     case NAMELIST_DECL:
   28237              :       break;
   28238              : 
   28239              :     default:
   28240              :       return;
   28241              :     }
   28242              : 
   28243     86945373 :   gen_decl_die (decl, NULL, NULL, context_die);
   28244              : 
   28245     86945373 :   if (flag_checking)
   28246              :     {
   28247     86945351 :       dw_die_ref die = lookup_decl_die (decl);
   28248     86945351 :       if (die)
   28249     30226663 :         check_die (die);
   28250              :     }
   28251              : }
   28252              : 
   28253              : /* Write the debugging output for DECL.  */
   28254              : 
   28255              : static void
   28256       575999 : dwarf2out_function_decl (tree decl)
   28257              : {
   28258       575999 :   dwarf2out_decl (decl);
   28259       575999 :   call_arg_locations = NULL;
   28260       575999 :   call_arg_loc_last = NULL;
   28261       575999 :   call_site_count = -1;
   28262       575999 :   tail_call_site_count = -1;
   28263       575999 :   decl_loc_table->empty ();
   28264       575999 :   cached_dw_loc_list_table->empty ();
   28265       575999 : }
   28266              : 
   28267              : /* Output a marker (i.e. a label) for the beginning of the generated code for
   28268              :    a lexical block.  */
   28269              : 
   28270              : static void
   28271     24803446 : dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
   28272              :                        unsigned int blocknum,
   28273              :                        tree block ATTRIBUTE_UNUSED)
   28274              : {
   28275              : #ifdef CODEVIEW_DEBUGGING_INFO
   28276              :   if (codeview_debuginfo_p ())
   28277              :     codeview_begin_block (line, blocknum, block);
   28278              : #endif
   28279              : 
   28280     24803446 :   switch_to_section (current_function_section ());
   28281     24803446 :   ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
   28282     24803446 : }
   28283              : 
   28284              : /* Output a marker (i.e. a label) for the end of the generated code for a
   28285              :    lexical block.  */
   28286              : 
   28287              : static void
   28288     24803446 : dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
   28289              : {
   28290              : #ifdef CODEVIEW_DEBUGGING_INFO
   28291              :   if (codeview_debuginfo_p ())
   28292              :     codeview_end_block (line, blocknum);
   28293              : #endif
   28294              : 
   28295     24803446 :   switch_to_section (current_function_section ());
   28296     24803446 :   ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
   28297     24803446 : }
   28298              : 
   28299              : /* Returns true if it is appropriate not to emit any debugging
   28300              :    information for BLOCK, because it doesn't contain any instructions.
   28301              : 
   28302              :    Don't allow this for blocks with nested functions or local classes
   28303              :    as we would end up with orphans, and in the presence of scheduling
   28304              :    we may end up calling them anyway.  */
   28305              : 
   28306              : static bool
   28307    113745163 : dwarf2out_ignore_block (const_tree block)
   28308              : {
   28309    113745163 :   tree decl;
   28310    113745163 :   unsigned int i;
   28311              : 
   28312    236498600 :   for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
   28313    123551353 :     if (TREE_CODE (decl) == FUNCTION_DECL
   28314    123551353 :         || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
   28315              :       return false;
   28316    113269791 :   for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
   28317              :     {
   28318       338758 :       decl = BLOCK_NONLOCALIZED_VAR (block, i);
   28319       338758 :       if (TREE_CODE (decl) == FUNCTION_DECL
   28320       338758 :           || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
   28321              :       return false;
   28322              :     }
   28323              : 
   28324              :   return true;
   28325              : }
   28326              : 
   28327              : /* Hash table routines for file_hash.  */
   28328              : 
   28329              : bool
   28330   2020157614 : dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
   28331              : {
   28332   2020157614 :   return filename_cmp (p1->key, p2) == 0;
   28333              : }
   28334              : 
   28335              : hashval_t
   28336   1492090435 : dwarf_file_hasher::hash (dwarf_file_data *p)
   28337              : {
   28338   1492090435 :   return htab_hash_string (p->key);
   28339              : }
   28340              : 
   28341              : /* Lookup FILE_NAME (in the list of filenames that we know about here in
   28342              :    dwarf2out.cc) and return its "index".  The index of each (known) filename is
   28343              :    just a unique number which is associated with only that one filename.  We
   28344              :    need such numbers for the sake of generating labels (in the .debug_sfnames
   28345              :    section) and references to those files numbers (in the .debug_srcinfo
   28346              :    and .debug_macinfo sections).  If the filename given as an argument is not
   28347              :    found in our current list, add it to the list and assign it the next
   28348              :    available unique index number.  */
   28349              : 
   28350              : static struct dwarf_file_data *
   28351    324159992 : lookup_filename (const char *file_name)
   28352              : {
   28353    324159992 :   struct dwarf_file_data * created;
   28354              : 
   28355    324159992 :   if (!file_name)
   28356              :     return NULL;
   28357              : 
   28358    324149174 :   if (!file_name[0])
   28359          244 :     file_name = "<stdin>";
   28360              : 
   28361    324149174 :   dwarf_file_data **slot
   28362    324149174 :     = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
   28363              :                                        INSERT);
   28364    324149174 :   if (*slot)
   28365              :     return *slot;
   28366              : 
   28367      3233192 :   created = ggc_alloc<dwarf_file_data> ();
   28368      3233192 :   created->key = file_name;
   28369      3233192 :   created->filename = remap_debug_filename (file_name);
   28370      3233192 :   created->emitted_number = 0;
   28371      3233192 :   *slot = created;
   28372      3233192 :   return created;
   28373              : }
   28374              : 
   28375              : /* If the assembler will construct the file table, then translate the compiler
   28376              :    internal file table number into the assembler file table number, and emit
   28377              :    a .file directive if we haven't already emitted one yet.  The file table
   28378              :    numbers are different because we prune debug info for unused variables and
   28379              :    types, which may include filenames.  */
   28380              : 
   28381              : static int
   28382    226956195 : maybe_emit_file (struct dwarf_file_data * fd)
   28383              : {
   28384    226956195 :   if (! fd->emitted_number)
   28385              :     {
   28386      1238641 :       if (last_emitted_file)
   28387      1187563 :         fd->emitted_number = last_emitted_file->emitted_number + 1;
   28388              :       else
   28389              :         fd->emitted_number = 1;
   28390      1238641 :       last_emitted_file = fd;
   28391              : 
   28392      1238641 :       if (output_asm_line_debug_info ())
   28393              :         {
   28394      1238529 :           fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
   28395      1238529 :           output_quoted_string (asm_out_file, fd->filename);
   28396      1238529 :           fputc ('\n', asm_out_file);
   28397              :         }
   28398              :     }
   28399              : 
   28400    226956195 :   return fd->emitted_number;
   28401              : }
   28402              : 
   28403              : /* Schedule generation of a DW_AT_const_value attribute to DIE.
   28404              :    That generation should happen after function debug info has been
   28405              :    generated. The value of the attribute is the constant value of ARG.  */
   28406              : 
   28407              : static void
   28408     10543735 : append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
   28409              : {
   28410     10543735 :   die_arg_entry entry;
   28411              : 
   28412     10543735 :   if (!die || !arg)
   28413            0 :     return;
   28414              : 
   28415     10543735 :   gcc_assert (early_dwarf);
   28416              : 
   28417     10543735 :   if (!tmpl_value_parm_die_table)
   28418        12399 :     vec_alloc (tmpl_value_parm_die_table, 32);
   28419              : 
   28420     10543735 :   entry.die = die;
   28421     10543735 :   entry.arg = arg;
   28422     10543735 :   vec_safe_push (tmpl_value_parm_die_table, entry);
   28423              : }
   28424              : 
   28425              : /* Return TRUE if T is an instance of generic type, FALSE
   28426              :    otherwise.  */
   28427              : 
   28428              : static bool
   28429     51006749 : generic_type_p (tree t)
   28430              : {
   28431     51006749 :   if (t == NULL_TREE || !TYPE_P (t))
   28432              :     return false;
   28433     51006749 :   return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
   28434              : }
   28435              : 
   28436              : /* Schedule the generation of the generic parameter dies for the
   28437              :   instance of generic type T. The proper generation itself is later
   28438              :   done by gen_scheduled_generic_parms_dies. */
   28439              : 
   28440              : static void
   28441     51006749 : schedule_generic_params_dies_gen (tree t)
   28442              : {
   28443     51006749 :   if (!generic_type_p (t))
   28444              :     return;
   28445              : 
   28446     43149821 :   gcc_assert (early_dwarf);
   28447              : 
   28448     43149821 :   if (!generic_type_instances)
   28449        13414 :     vec_alloc (generic_type_instances, 256);
   28450              : 
   28451     43149821 :   vec_safe_push (generic_type_instances, t);
   28452              : }
   28453              : 
   28454              : /* Add a DW_AT_const_value attribute to DIEs that were scheduled
   28455              :    by append_entry_to_tmpl_value_parm_die_table. This function must
   28456              :    be called after function DIEs have been generated.  */
   28457              : 
   28458              : static void
   28459       106830 : gen_remaining_tmpl_value_param_die_attribute (void)
   28460              : {
   28461       106830 :   if (tmpl_value_parm_die_table)
   28462              :     {
   28463              :       unsigned i, j;
   28464              :       die_arg_entry *e;
   28465              : 
   28466              :       /* We do this in two phases - first get the cases we can
   28467              :          handle during early-finish, preserving those we cannot
   28468              :          (containing symbolic constants where we don't yet know
   28469              :          whether we are going to output the referenced symbols).
   28470              :          For those we try again at late-finish.  */
   28471              :       j = 0;
   28472     10570840 :       FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table, i, e)
   28473              :         {
   28474     10546079 :           if (!e->die->removed
   28475     10546079 :               && !tree_add_const_value_attribute (e->die, e->arg))
   28476              :             {
   28477         4558 :               dw_loc_descr_ref loc = NULL;
   28478         4558 :               if (! early_dwarf
   28479         2214 :                   && (dwarf_version >= 5 || !dwarf_strict))
   28480         2211 :                 loc = loc_descriptor_from_tree (e->arg, 2, NULL);
   28481         2211 :               if (loc)
   28482         2205 :                 add_AT_loc (e->die, DW_AT_location, loc);
   28483              :               else
   28484         2353 :                 (*tmpl_value_parm_die_table)[j++] = *e;
   28485              :             }
   28486              :         }
   28487        24761 :       tmpl_value_parm_die_table->truncate (j);
   28488              :     }
   28489       106830 : }
   28490              : 
   28491              : /* Generate generic parameters DIEs for instances of generic types
   28492              :    that have been previously scheduled by
   28493              :    schedule_generic_params_dies_gen. This function must be called
   28494              :    after all the types of the CU have been laid out.  */
   28495              : 
   28496              : static void
   28497        53595 : gen_scheduled_generic_parms_dies (void)
   28498              : {
   28499        53595 :   unsigned i;
   28500        53595 :   tree t;
   28501              : 
   28502        53595 :   if (!generic_type_instances)
   28503        53595 :     return;
   28504              : 
   28505     41615962 :   FOR_EACH_VEC_ELT (*generic_type_instances, i, t)
   28506     41603070 :     if (COMPLETE_TYPE_P (t))
   28507     39220113 :       gen_generic_params_dies (t);
   28508              : 
   28509        12892 :   generic_type_instances = NULL;
   28510              : }
   28511              : 
   28512              : 
   28513              : /* Replace DW_AT_name for the decl with name.  */
   28514              : 
   28515              : static void
   28516            0 : dwarf2out_set_name (tree decl, tree name)
   28517              : {
   28518            0 :   dw_die_ref die;
   28519            0 :   dw_attr_node *attr;
   28520            0 :   const char *dname;
   28521              : 
   28522            0 :   die = TYPE_SYMTAB_DIE (decl);
   28523            0 :   if (!die)
   28524              :     return;
   28525              : 
   28526            0 :   dname = dwarf2_name (name, 0);
   28527            0 :   if (!dname)
   28528              :     return;
   28529              : 
   28530            0 :   attr = get_AT (die, DW_AT_name);
   28531            0 :   if (attr)
   28532              :     {
   28533            0 :       struct indirect_string_node *node;
   28534              : 
   28535            0 :       node = find_AT_string (dname);
   28536              :       /* replace the string.  */
   28537            0 :       attr->dw_attr_val.v.val_str = node;
   28538              :     }
   28539              : 
   28540              :   else
   28541            0 :     add_name_attribute (die, dname);
   28542              : }
   28543              : 
   28544              : /* True if before or during processing of the first function being emitted.  */
   28545              : static bool in_first_function_p = true;
   28546              : /* True if loc_note during dwarf2out_var_location call might still be
   28547              :    before first real instruction at address equal to .Ltext0.  */
   28548              : static bool maybe_at_text_label_p = true;
   28549              : /* One above highest N where .LVLN label might be equal to .Ltext0 label.  */
   28550              : static unsigned int first_loclabel_num_not_at_text_label;
   28551              : 
   28552              : /* Look ahead for a real insn.  */
   28553              : 
   28554              : static rtx_insn *
   28555     14270021 : dwarf2out_next_real_insn (rtx_insn *loc_note)
   28556              : {
   28557     14270021 :   rtx_insn *next_real = NEXT_INSN (loc_note);
   28558              : 
   28559    164890739 :   while (next_real)
   28560    150351398 :     if (INSN_P (next_real))
   28561              :       break;
   28562              :     else
   28563    136350697 :       next_real = NEXT_INSN (next_real);
   28564              : 
   28565     14270021 :   return next_real;
   28566              : }
   28567              : 
   28568              : /* Called by the final INSN scan whenever we see a var location.  We
   28569              :    use it to drop labels in the right places, and throw the location in
   28570              :    our lookup table.  */
   28571              : 
   28572              : static void
   28573    110340811 : dwarf2out_var_location (rtx_insn *loc_note)
   28574              : {
   28575    110340811 :   char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
   28576    110340811 :   struct var_loc_node *newloc;
   28577    110340811 :   rtx_insn *next_real;
   28578    110340811 :   rtx_insn *call_insn = NULL;
   28579    110340811 :   static const char *last_label;
   28580    110340811 :   static const char *last_postcall_label;
   28581    110340811 :   static bool last_in_cold_section_p;
   28582    110340811 :   static rtx_insn *expected_next_loc_note;
   28583    110340811 :   tree decl;
   28584    110340811 :   bool var_loc_p;
   28585    110340811 :   var_loc_view view = 0;
   28586              : 
   28587    110340811 :   if (!NOTE_P (loc_note))
   28588              :     {
   28589     43098381 :       if (CALL_P (loc_note))
   28590              :         {
   28591      3645469 :           maybe_reset_location_view (loc_note, cur_line_info_table);
   28592      3645469 :           call_site_count++;
   28593      3645469 :           if (SIBLING_CALL_P (loc_note))
   28594        61601 :             tail_call_site_count++;
   28595      3645469 :           if (find_reg_note (loc_note, REG_CALL_ARG_LOCATION, NULL_RTX))
   28596              :             {
   28597      3273166 :               call_insn = loc_note;
   28598      3273166 :               loc_note = NULL;
   28599      3273166 :               var_loc_p = false;
   28600              : 
   28601      3273166 :               next_real = dwarf2out_next_real_insn (call_insn);
   28602      3273166 :               cached_next_real_insn = NULL;
   28603      3273166 :               goto create_label;
   28604              :             }
   28605       372303 :           if (optimize == 0 && !flag_var_tracking)
   28606              :             {
   28607              :               /* When the var-tracking pass is not running, there is no note
   28608              :                  for indirect calls whose target is compile-time known. In this
   28609              :                  case, process such calls specifically so that we generate call
   28610              :                  sites for them anyway.  */
   28611       347417 :               rtx x = PATTERN (loc_note);
   28612       347417 :               if (GET_CODE (x) == PARALLEL)
   28613            1 :                 x = XVECEXP (x, 0, 0);
   28614       347417 :               if (GET_CODE (x) == SET)
   28615       107121 :                 x = SET_SRC (x);
   28616       347417 :               if (GET_CODE (x) == CALL)
   28617       347417 :                 x = XEXP (x, 0);
   28618       347417 :               if (!MEM_P (x)
   28619       347417 :                   || GET_CODE (XEXP (x, 0)) != SYMBOL_REF
   28620       326939 :                   || !SYMBOL_REF_DECL (XEXP (x, 0))
   28621       659061 :                   || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0)))
   28622              :                       != FUNCTION_DECL))
   28623              :                 {
   28624        35773 :                   call_insn = loc_note;
   28625        35773 :                   loc_note = NULL;
   28626        35773 :                   var_loc_p = false;
   28627              : 
   28628        35773 :                   next_real = dwarf2out_next_real_insn (call_insn);
   28629        35773 :                   cached_next_real_insn = NULL;
   28630        35773 :                   goto create_label;
   28631              :                 }
   28632              :             }
   28633              :         }
   28634     39452912 :       else if (!debug_variable_location_views)
   28635            0 :         gcc_unreachable ();
   28636              :       else
   28637     39452912 :         maybe_reset_location_view (loc_note, cur_line_info_table);
   28638              : 
   28639     53968015 :       return;
   28640              :     }
   28641              : 
   28642     67242430 :   var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
   28643     67242430 :   if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
   28644              :     return;
   28645              : 
   28646              :   /* Optimize processing a large consecutive sequence of location
   28647              :      notes so we don't spend too much time in next_real_insn.  If the
   28648              :      next insn is another location note, remember the next_real_insn
   28649              :      calculation for next time.  */
   28650     67242430 :   next_real = cached_next_real_insn;
   28651     67242430 :   if (next_real)
   28652              :     {
   28653     56281348 :       if (expected_next_loc_note != loc_note)
   28654              :         next_real = NULL;
   28655              :     }
   28656              : 
   28657              :   if (! next_real)
   28658     10961082 :     next_real = dwarf2out_next_real_insn (loc_note);
   28659              : 
   28660     10961082 :   if (next_real)
   28661              :     {
   28662     67114320 :       rtx_insn *next_note = NEXT_INSN (loc_note);
   28663    190246573 :       while (next_note != next_real)
   28664              :         {
   28665    112299281 :           if (! next_note->deleted ()
   28666    112299281 :               && NOTE_P (next_note)
   28667    221524926 :               && NOTE_KIND (next_note) == NOTE_INSN_VAR_LOCATION)
   28668              :             break;
   28669     56017933 :           next_note = NEXT_INSN (next_note);
   28670              :         }
   28671              : 
   28672     67114320 :       if (next_note == next_real)
   28673     10832972 :         cached_next_real_insn = NULL;
   28674              :       else
   28675              :         {
   28676     56281348 :           expected_next_loc_note = next_note;
   28677     56281348 :           cached_next_real_insn = next_real;
   28678              :         }
   28679              :     }
   28680              :   else
   28681       128110 :     cached_next_real_insn = NULL;
   28682              : 
   28683              :   /* If there are no instructions which would be affected by this note,
   28684              :      don't do anything.  */
   28685     67242430 :   if (var_loc_p
   28686     67242430 :       && next_real == NULL_RTX
   28687     67242430 :       && !NOTE_DURING_CALL_P (loc_note))
   28688              :     return;
   28689              : 
   28690     70551208 : create_label:
   28691              : 
   28692     70551208 :   if (next_real == NULL_RTX)
   28693       269159 :     next_real = get_last_insn ();
   28694              : 
   28695              :   /* If there were any real insns between note we processed last time
   28696              :      and this note (or if it is the first note), clear
   28697              :      last_{,postcall_}label so that they are not reused this time.  */
   28698     70551208 :   if (last_var_location_insn == NULL_RTX
   28699     70034101 :       || last_var_location_insn != next_real
   28700     55734468 :       || last_in_cold_section_p != in_cold_section_p)
   28701              :     {
   28702     14820346 :       last_label = NULL;
   28703     14820346 :       last_postcall_label = NULL;
   28704              :     }
   28705              : 
   28706     70551208 :   if (var_loc_p)
   28707              :     {
   28708     67242269 :       const char *label
   28709     67242269 :         = NOTE_DURING_CALL_P (loc_note) ? last_postcall_label : last_label;
   28710     67242269 :       view = cur_line_info_table->view;
   28711     67242269 :       decl = NOTE_VAR_LOCATION_DECL (loc_note);
   28712     67242269 :       newloc = add_var_loc_to_decl (decl, loc_note, label, view);
   28713     67242269 :       if (newloc == NULL)
   28714              :         return;
   28715              :     }
   28716              :   else
   28717              :     {
   28718              :       decl = NULL_TREE;
   28719              :       newloc = NULL;
   28720              :     }
   28721              : 
   28722              :   /* If there were no real insns between note we processed last time
   28723              :      and this note, use the label we emitted last time.  Otherwise
   28724              :      create a new label and emit it.  */
   28725     56372796 :   if (last_label == NULL)
   28726              :     {
   28727     11857972 :       ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
   28728     11857972 :       ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
   28729     11857972 :       loclabel_num++;
   28730     11857972 :       last_label = ggc_strdup (loclabel);
   28731              :       /* See if loclabel might be equal to .Ltext0.  If yes,
   28732              :          bump first_loclabel_num_not_at_text_label.  */
   28733     11857972 :       if (!have_multiple_function_sections
   28734      4697569 :           && in_first_function_p
   28735       261636 :           && maybe_at_text_label_p)
   28736              :         {
   28737              :           static rtx_insn *last_start;
   28738              :           rtx_insn *insn;
   28739       129890 :           for (insn = loc_note; insn; insn = previous_insn (insn))
   28740        84413 :             if (insn == last_start)
   28741              :               break;
   28742        84233 :             else if (!NONDEBUG_INSN_P (insn))
   28743        71648 :               continue;
   28744              :             else
   28745              :               {
   28746        12585 :                 rtx body = PATTERN (insn);
   28747        12585 :                 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
   28748            3 :                   continue;
   28749              :                 /* Inline asm could occupy zero bytes.  */
   28750        12826 :                 else if (GET_CODE (body) == ASM_INPUT
   28751        12582 :                          || asm_noperands (body) >= 0)
   28752          244 :                   continue;
   28753              : #ifdef HAVE_ATTR_length /* ??? We don't include insn-attr.h.  */
   28754              :                 else if (HAVE_ATTR_length && get_attr_min_length (insn) == 0)
   28755              :                   continue;
   28756              : #endif
   28757              :                 else
   28758              :                   {
   28759              :                     /* Assume insn has non-zero length.  */
   28760        12338 :                     maybe_at_text_label_p = false;
   28761        12338 :                     break;
   28762              :                   }
   28763              :               }
   28764        57995 :           if (maybe_at_text_label_p)
   28765              :             {
   28766        45657 :               last_start = loc_note;
   28767        45657 :               first_loclabel_num_not_at_text_label = loclabel_num;
   28768              :             }
   28769              :         }
   28770              :     }
   28771              : 
   28772     56372796 :   gcc_assert ((loc_note == NULL_RTX && call_insn != NULL_RTX)
   28773              :               || (loc_note != NULL_RTX && call_insn == NULL_RTX));
   28774              : 
   28775     56372796 :   if (!var_loc_p)
   28776              :     {
   28777      3308939 :       struct call_arg_loc_node *ca_loc
   28778      3308939 :         = ggc_cleared_alloc<call_arg_loc_node> ();
   28779      3308939 :       rtx_insn *prev = call_insn;
   28780              : 
   28781      3308939 :       ca_loc->call_insn = call_insn;
   28782      3308939 :       ca_loc->next = NULL;
   28783      3308939 :       ca_loc->label = last_label;
   28784      3308939 :       gcc_assert (prev
   28785              :                   && (CALL_P (prev)
   28786              :                       || (NONJUMP_INSN_P (prev)
   28787              :                           && GET_CODE (PATTERN (prev)) == SEQUENCE
   28788              :                           && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
   28789      3308939 :       if (!CALL_P (prev))
   28790            0 :         prev = as_a <rtx_sequence *> (PATTERN (prev))->insn (0);
   28791      3308939 :       ca_loc->tail_call_p = SIBLING_CALL_P (prev);
   28792              : 
   28793              :       /* Look for a SYMBOL_REF in the "prev" instruction.  */
   28794      3308939 :       rtx x = get_call_rtx_from (prev);
   28795      3308939 :       if (x)
   28796              :         {
   28797              :           /* Try to get the call symbol, if any.  */
   28798      3308939 :           if (MEM_P (XEXP (x, 0)))
   28799      3308939 :             x = XEXP (x, 0);
   28800              :           /* First, look for a memory access to a symbol_ref.  */
   28801      3308939 :           if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
   28802      3161243 :               && SYMBOL_REF_DECL (XEXP (x, 0))
   28803      6220341 :               && TREE_CODE (SYMBOL_REF_DECL (XEXP (x, 0))) == FUNCTION_DECL)
   28804      2911399 :             ca_loc->symbol_ref = XEXP (x, 0);
   28805              :           /* Otherwise, look at a compile-time known user-level function
   28806              :              declaration.  */
   28807       397540 :           else if (MEM_P (x)
   28808       397540 :                    && MEM_EXPR (x)
   28809       538456 :                    && TREE_CODE (MEM_EXPR (x)) == FUNCTION_DECL)
   28810            0 :             ca_loc->symbol_ref = XEXP (DECL_RTL (MEM_EXPR (x)), 0);
   28811              :         }
   28812              : 
   28813      3308939 :       ca_loc->block = insn_scope (prev);
   28814      3308939 :       if (call_arg_locations)
   28815      2856570 :         call_arg_loc_last->next = ca_loc;
   28816              :       else
   28817       452369 :         call_arg_locations = ca_loc;
   28818      3308939 :       call_arg_loc_last = ca_loc;
   28819              :     }
   28820     53063857 :   else if (loc_note != NULL_RTX && !NOTE_DURING_CALL_P (loc_note))
   28821              :     {
   28822     49741973 :       newloc->label = last_label;
   28823     49741973 :       newloc->view = view;
   28824              :     }
   28825              :   else
   28826              :     {
   28827      3321884 :       if (!last_postcall_label)
   28828              :         {
   28829      1127764 :           sprintf (loclabel, "%s-1", last_label);
   28830      1127764 :           last_postcall_label = ggc_strdup (loclabel);
   28831              :         }
   28832      3321884 :       newloc->label = last_postcall_label;
   28833              :       /* ??? This view is at last_label, not last_label-1, but we
   28834              :          could only assume view at last_label-1 is zero if we could
   28835              :          assume calls always have length greater than one.  This is
   28836              :          probably true in general, though there might be a rare
   28837              :          exception to this rule, e.g. if a call insn is optimized out
   28838              :          by target magic.  Then, even the -1 in the label will be
   28839              :          wrong, which might invalidate the range.  Anyway, using view,
   28840              :          though technically possibly incorrect, will work as far as
   28841              :          ranges go: since L-1 is in the middle of the call insn,
   28842              :          (L-1).0 and (L-1).V shouldn't make any difference, and having
   28843              :          the loclist entry refer to the .loc entry might be useful, so
   28844              :          leave it like this.  */
   28845      3321884 :       newloc->view = view;
   28846              :     }
   28847              : 
   28848     56372796 :   if (var_loc_p && flag_debug_asm)
   28849              :     {
   28850          400 :       const char *name, *sep, *patstr;
   28851          400 :       if (decl && DECL_NAME (decl))
   28852          389 :         name = IDENTIFIER_POINTER (DECL_NAME (decl));
   28853              :       else
   28854              :         name = "";
   28855          400 :       if (NOTE_VAR_LOCATION_LOC (loc_note))
   28856              :         {
   28857          302 :           sep = " => ";
   28858          302 :           patstr = str_pattern_slim (NOTE_VAR_LOCATION_LOC (loc_note));
   28859              :         }
   28860              :       else
   28861              :         {
   28862              :           sep = " ";
   28863              :           patstr = "RESET";
   28864              :         }
   28865          400 :       fprintf (asm_out_file, "\t%s DEBUG %s%s%s\n", ASM_COMMENT_START,
   28866              :                name, sep, patstr);
   28867              :     }
   28868              : 
   28869     56372796 :   last_var_location_insn = next_real;
   28870     56372796 :   last_in_cold_section_p = in_cold_section_p;
   28871              : }
   28872              : 
   28873              : /* Check whether BLOCK, a lexical block, is nested within OUTER, or is
   28874              :    OUTER itself.  If BOTHWAYS, check not only that BLOCK can reach
   28875              :    OUTER through BLOCK_SUPERCONTEXT links, but also that there is a
   28876              :    path from OUTER to BLOCK through BLOCK_SUBBLOCKs and
   28877              :    BLOCK_FRAGMENT_ORIGIN links.  */
   28878              : static bool
   28879      7535787 : block_within_block_p (tree block, tree outer, bool bothways)
   28880              : {
   28881      7535787 :   if (block == outer)
   28882              :     return true;
   28883              : 
   28884              :   /* Quickly check that OUTER is up BLOCK's supercontext chain.  */
   28885      7535787 :   for (tree context = BLOCK_SUPERCONTEXT (block);
   28886     55301246 :        context != outer;
   28887     47765459 :        context = BLOCK_SUPERCONTEXT (context))
   28888     47765459 :     if (!context || TREE_CODE (context) != BLOCK)
   28889              :       return false;
   28890              : 
   28891      7535787 :   if (!bothways)
   28892              :     return true;
   28893              : 
   28894              :   /* Now check that each block is actually referenced by its
   28895              :      parent.  */
   28896     47765459 :   for (tree context = BLOCK_SUPERCONTEXT (block); ;
   28897     47765459 :        context = BLOCK_SUPERCONTEXT (context))
   28898              :     {
   28899     55301246 :       if (BLOCK_FRAGMENT_ORIGIN (context))
   28900              :         {
   28901      2302600 :           gcc_assert (!BLOCK_SUBBLOCKS (context));
   28902              :           context = BLOCK_FRAGMENT_ORIGIN (context);
   28903              :         }
   28904    251647778 :       for (tree sub = BLOCK_SUBBLOCKS (context);
   28905    251647778 :            sub != block;
   28906    196346532 :            sub = BLOCK_CHAIN (sub))
   28907    196346532 :         if (!sub)
   28908              :           return false;
   28909     55301246 :       if (context == outer)
   28910              :         return true;
   28911              :       else
   28912     47765459 :         block = context;
   28913     47765459 :     }
   28914              : }
   28915              : 
   28916              : /* Called during final while assembling the marker of the entry point
   28917              :    for an inlined function.  */
   28918              : 
   28919              : static void
   28920      7535787 : dwarf2out_inline_entry (tree block)
   28921              : {
   28922      7535787 :   gcc_assert (debug_inline_points);
   28923              : 
   28924              :   /* If we can't represent it, don't bother.  */
   28925      7535787 :   if (!(dwarf_version >= 3 || !dwarf_strict))
   28926              :     return;
   28927              : 
   28928      7535787 :   gcc_assert (DECL_P (block_ultimate_origin (block)));
   28929              : 
   28930              :   /* Sanity check the block tree.  This would catch a case in which
   28931              :      BLOCK got removed from the tree reachable from the outermost
   28932              :      lexical block, but got retained in markers.  It would still link
   28933              :      back to its parents, but some ancestor would be missing a link
   28934              :      down the path to the sub BLOCK.  If the block got removed, its
   28935              :      BLOCK_NUMBER will not be a usable value.  */
   28936      7535787 :   if (flag_checking)
   28937      7535787 :     gcc_assert (block_within_block_p (block,
   28938              :                                       DECL_INITIAL (current_function_decl),
   28939              :                                       true));
   28940              : 
   28941      7535787 :   gcc_assert (inlined_function_outer_scope_p (block));
   28942      7535787 :   gcc_assert (!lookup_block_die (block));
   28943              : 
   28944      7535787 :   if (BLOCK_FRAGMENT_ORIGIN (block))
   28945            0 :     block = BLOCK_FRAGMENT_ORIGIN (block);
   28946              :   /* Can the entry point ever not be at the beginning of an
   28947              :      unfragmented lexical block?  */
   28948      7535787 :   else if (!(BLOCK_FRAGMENT_CHAIN (block)
   28949      3982611 :              || (cur_line_info_table
   28950      3982611 :                  && !ZERO_VIEW_P (cur_line_info_table->view))))
   28951              :     return;
   28952              : 
   28953      7535195 :   if (!inline_entry_data_table)
   28954        13468 :     inline_entry_data_table
   28955        13468 :       = hash_table<inline_entry_data_hasher>::create_ggc (10);
   28956              : 
   28957              : 
   28958      7535195 :   inline_entry_data **iedp
   28959      7535195 :     = inline_entry_data_table->find_slot_with_hash (block,
   28960              :                                                     htab_hash_pointer (block),
   28961              :                                                     INSERT);
   28962      7535195 :   if (*iedp)
   28963              :     /* ??? Ideally, we'd record all entry points for the same inlined
   28964              :        function (some may have been duplicated by e.g. unrolling), but
   28965              :        we have no way to represent that ATM.  */
   28966              :     return;
   28967              : 
   28968      6911054 :   inline_entry_data *ied = *iedp = ggc_cleared_alloc<inline_entry_data> ();
   28969      6911054 :   ied->block = block;
   28970      6911054 :   ied->label_pfx = BLOCK_INLINE_ENTRY_LABEL;
   28971      6911054 :   ied->label_num = BLOCK_NUMBER (block);
   28972      6911054 :   if (cur_line_info_table)
   28973      6911054 :     ied->view = cur_line_info_table->view;
   28974              : 
   28975      6911054 :   ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_INLINE_ENTRY_LABEL,
   28976              :                           BLOCK_NUMBER (block));
   28977              : }
   28978              : 
   28979              : /* Called from finalize_size_functions for size functions so that their body
   28980              :    can be encoded in the debug info to describe the layout of variable-length
   28981              :    structures.  */
   28982              : 
   28983              : static void
   28984            0 : dwarf2out_size_function (tree decl)
   28985              : {
   28986            0 :   set_early_dwarf s;
   28987            0 :   function_to_dwarf_procedure (decl);
   28988            0 : }
   28989              : 
   28990              : /* Note in one location list that text section has changed.  */
   28991              : 
   28992              : int
   28993      3966487 : var_location_switch_text_section_1 (var_loc_list **slot, void *)
   28994              : {
   28995      3966487 :   var_loc_list *list = *slot;
   28996      3966487 :   if (list->first)
   28997      3966487 :     list->last_before_switch
   28998      4227971 :       = list->last->next ? list->last->next : list->last;
   28999      3966487 :   return 1;
   29000              : }
   29001              : 
   29002              : /* Note in all location lists that text section has changed.  */
   29003              : 
   29004              : static void
   29005        65929 : var_location_switch_text_section (void)
   29006              : {
   29007        65929 :   if (decl_loc_table == NULL)
   29008              :     return;
   29009              : 
   29010      3989141 :   decl_loc_table->traverse<void *, var_location_switch_text_section_1> (NULL);
   29011              : }
   29012              : 
   29013              : /* Create a new line number table.  */
   29014              : 
   29015              : static dw_line_info_table *
   29016       269730 : new_line_info_table (void)
   29017              : {
   29018       269730 :   dw_line_info_table *table;
   29019              : 
   29020       269730 :   table = ggc_cleared_alloc<dw_line_info_table> ();
   29021       269730 :   table->file_num = 1;
   29022       269730 :   table->line_num = 1;
   29023       269730 :   table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
   29024       269730 :   FORCE_RESET_NEXT_VIEW (table->view);
   29025       269730 :   table->symviews_since_reset = 0;
   29026              : 
   29027       269730 :   return table;
   29028              : }
   29029              : 
   29030              : /* Lookup the "current" table into which we emit line info, so
   29031              :    that we don't have to do it for every source line.  */
   29032              : 
   29033              : static void
   29034       602625 : set_cur_line_info_table (section *sec)
   29035              : {
   29036       602625 :   dw_line_info_table *table;
   29037              : 
   29038       602625 :   if (sec == text_section)
   29039       383610 :     table = text_section_line_info;
   29040       219015 :   else if (sec == cold_text_section)
   29041              :     {
   29042        12167 :       table = cold_text_section_line_info;
   29043        12167 :       if (!table)
   29044              :         {
   29045         9320 :           cold_text_section_line_info = table = new_line_info_table ();
   29046         9320 :           table->end_label = cold_end_label;
   29047              :         }
   29048              :     }
   29049              :   else
   29050              :     {
   29051       206848 :       const char *end_label;
   29052              : 
   29053       206848 :       if (crtl->has_bb_partition)
   29054              :         {
   29055        28877 :           if (in_cold_section_p)
   29056        10553 :             end_label = crtl->subsections.cold_section_end_label;
   29057              :           else
   29058        18324 :             end_label = crtl->subsections.hot_section_end_label;
   29059              :         }
   29060              :       else
   29061              :         {
   29062       177971 :           char label[MAX_ARTIFICIAL_LABEL_BYTES];
   29063       177971 :           ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
   29064              :                                        current_function_funcdef_no);
   29065       177971 :           end_label = ggc_strdup (label);
   29066              :         }
   29067              : 
   29068       206848 :       table = new_line_info_table ();
   29069       206848 :       table->end_label = end_label;
   29070              : 
   29071       206848 :       vec_safe_push (separate_line_info, table);
   29072              :     }
   29073              : 
   29074       602625 :   if (output_asm_line_debug_info ())
   29075      1205158 :     table->is_stmt = (cur_line_info_table
   29076       602579 :                       ? cur_line_info_table->is_stmt
   29077              :                       : DWARF_LINE_DEFAULT_IS_STMT_START);
   29078       602625 :   cur_line_info_table = table;
   29079       602625 : }
   29080              : 
   29081              : 
   29082              : /* We need to reset the locations at the beginning of each
   29083              :    function. We can't do this in the end_function hook, because the
   29084              :    declarations that use the locations won't have been output when
   29085              :    that hook is called.  Also compute have_multiple_function_sections here.  */
   29086              : 
   29087              : static void
   29088       576043 : dwarf2out_begin_function (tree fun)
   29089              : {
   29090       576043 :   section *sec = function_section (fun);
   29091              : 
   29092       576043 :   if (sec != text_section)
   29093       193716 :     have_multiple_function_sections = true;
   29094              : 
   29095       576043 :   if (crtl->has_bb_partition && !cold_text_section)
   29096              :     {
   29097         9320 :       gcc_assert (current_function_decl == fun);
   29098         9320 :       cold_text_section = unlikely_text_section ();
   29099         9320 :       switch_to_section (cold_text_section);
   29100         9320 :       ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
   29101         9320 :       switch_to_section (sec);
   29102              :     }
   29103              : 
   29104       576043 :   call_site_count = 0;
   29105       576043 :   tail_call_site_count = 0;
   29106              : 
   29107       576043 :   set_cur_line_info_table (sec);
   29108       576043 :   FORCE_RESET_NEXT_VIEW (cur_line_info_table->view);
   29109       576043 : }
   29110              : 
   29111              : /* Helper function of dwarf2out_end_function, called only after emitting
   29112              :    the very first function into assembly.  Check if some .debug_loc range
   29113              :    might end with a .LVL* label that could be equal to .Ltext0.
   29114              :    In that case we must force using absolute addresses in .debug_loc ranges,
   29115              :    because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
   29116              :    .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
   29117              :    list terminator.
   29118              :    Set have_multiple_function_sections to true in that case and
   29119              :    terminate htab traversal.  */
   29120              : 
   29121              : int
   29122       184363 : find_empty_loc_ranges_at_text_label (var_loc_list **slot, int)
   29123              : {
   29124       184363 :   var_loc_list *entry = *slot;
   29125       184363 :   struct var_loc_node *node;
   29126              : 
   29127       184363 :   node = entry->first;
   29128       184363 :   if (node && node->next && node->next->label)
   29129              :     {
   29130              :       unsigned int i;
   29131              :       const char *label = node->next->label;
   29132              :       char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
   29133              : 
   29134       133328 :       for (i = 0; i < first_loclabel_num_not_at_text_label; i++)
   29135              :         {
   29136        77316 :           ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", i);
   29137        77316 :           if (strcmp (label, loclabel) == 0)
   29138              :             {
   29139          709 :               have_multiple_function_sections = true;
   29140          709 :               return 0;
   29141              :             }
   29142              :         }
   29143              :     }
   29144              :   return 1;
   29145              : }
   29146              : 
   29147              : /* Hook called after emitting a function into assembly.
   29148              :    This does something only for the very first function emitted.  */
   29149              : 
   29150              : static void
   29151       576043 : dwarf2out_end_function (unsigned int)
   29152              : {
   29153       576043 :   if (in_first_function_p
   29154        48208 :       && !have_multiple_function_sections
   29155        27359 :       && first_loclabel_num_not_at_text_label
   29156        19498 :       && decl_loc_table)
   29157       203861 :     decl_loc_table->traverse<int, find_empty_loc_ranges_at_text_label> (0);
   29158       576043 :   in_first_function_p = false;
   29159       576043 :   maybe_at_text_label_p = false;
   29160       576043 : }
   29161              : 
   29162              : /* Temporary holder for dwarf2out_register_main_translation_unit.  Used to let
   29163              :    front-ends register a translation unit even before dwarf2out_init is
   29164              :    called.  */
   29165              : static tree main_translation_unit = NULL_TREE;
   29166              : 
   29167              : /* Hook called by front-ends after they built their main translation unit.
   29168              :    Associate comp_unit_die to UNIT.  */
   29169              : 
   29170              : static void
   29171        46128 : dwarf2out_register_main_translation_unit (tree unit)
   29172              : {
   29173        46128 :   gcc_assert (TREE_CODE (unit) == TRANSLATION_UNIT_DECL
   29174              :               && main_translation_unit == NULL_TREE);
   29175        46128 :   main_translation_unit = unit;
   29176              :   /* If dwarf2out_init has not been called yet, it will perform the association
   29177              :      itself looking at main_translation_unit.  */
   29178        46128 :   if (decl_die_table != NULL)
   29179        27038 :     equate_decl_number_to_die (unit, comp_unit_die ());
   29180        46128 : }
   29181              : 
   29182              : /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE.  */
   29183              : 
   29184              : static void
   29185         5952 : push_dw_line_info_entry (dw_line_info_table *table,
   29186              :                          enum dw_line_info_opcode opcode, unsigned int val)
   29187              : {
   29188         5952 :   dw_line_info_entry e;
   29189         5952 :   e.opcode = opcode;
   29190         5952 :   e.val = val;
   29191            0 :   vec_safe_push (table->entries, e);
   29192            0 : }
   29193              : 
   29194              : /* Output a label to mark the beginning of a source code line entry
   29195              :    and record information relating to this source line, in
   29196              :    'line_info_table' for later output of the .debug_line section.  */
   29197              : /* ??? The discriminator parameter ought to be unsigned.  */
   29198              : 
   29199              : static void
   29200     37262457 : dwarf2out_source_line (unsigned int line, unsigned int column,
   29201              :                        const char *filename,
   29202              :                        int discriminator, bool is_stmt)
   29203              : {
   29204     37262457 :   unsigned int file_num;
   29205     37262457 :   dw_line_info_table *table;
   29206     37262457 :   static var_loc_view lvugid;
   29207              : 
   29208              : #ifdef CODEVIEW_DEBUGGING_INFO
   29209              :   if (codeview_debuginfo_p ())
   29210              :     codeview_source_line (line, filename);
   29211              : #endif
   29212              : 
   29213              :   /* 'line_info_table' information gathering is not needed when the debug
   29214              :      info level is set to the lowest value.  Also, the current DWARF-based
   29215              :      debug formats do not use this info.  */
   29216     37262457 :   if (debug_info_level < DINFO_LEVEL_TERSE || !dwarf_debuginfo_p ())
   29217              :     return;
   29218              : 
   29219     37261199 :   table = cur_line_info_table;
   29220              : 
   29221     37261199 :   if (line == 0)
   29222              :     {
   29223       590324 :       if (debug_variable_location_views
   29224       554009 :           && output_asm_line_debug_info ()
   29225      1144333 :           && table && !RESETTING_VIEW_P (table->view))
   29226              :         {
   29227              :           /* If we're using the assembler to compute view numbers, we
   29228              :              can't issue a .loc directive for line zero, so we can't
   29229              :              get a view number at this point.  We might attempt to
   29230              :              compute it from the previous view, or equate it to a
   29231              :              subsequent view (though it might not be there!), but
   29232              :              since we're omitting the line number entry, we might as
   29233              :              well omit the view number as well.  That means pretending
   29234              :              it's a view number zero, which might very well turn out
   29235              :              to be correct.  ??? Extend the assembler so that the
   29236              :              compiler could emit e.g. ".locview .LVU#", to output a
   29237              :              view without changing line number information.  We'd then
   29238              :              have to count it in symviews_since_reset; when it's omitted,
   29239              :              it doesn't count.  */
   29240         4067 :           if (!zero_view_p)
   29241            0 :             zero_view_p = BITMAP_GGC_ALLOC ();
   29242         4067 :           bitmap_set_bit (zero_view_p, table->view);
   29243         4067 :           if (flag_debug_asm)
   29244              :             {
   29245            0 :               char label[MAX_ARTIFICIAL_LABEL_BYTES];
   29246            0 :               ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
   29247            0 :               fprintf (asm_out_file, "\t%s line 0, omitted view ",
   29248              :                        ASM_COMMENT_START);
   29249            0 :               assemble_name (asm_out_file, label);
   29250            0 :               putc ('\n', asm_out_file);
   29251              :             }
   29252         4067 :           table->view = ++lvugid;
   29253              :         }
   29254              :       return;
   29255              :     }
   29256              : 
   29257              :   /* The discriminator column was added in dwarf4.  Simplify the below
   29258              :      by simply removing it if we're not supposed to output it.  */
   29259     36670875 :   if (dwarf_version < 4 && dwarf_strict)
   29260     36670875 :     discriminator = 0;
   29261              : 
   29262     36670875 :   if (!debug_column_info)
   29263           82 :     column = 0;
   29264              : 
   29265     36670875 :   file_num = maybe_emit_file (lookup_filename (filename));
   29266              : 
   29267              :   /* ??? TODO: Elide duplicate line number entries.  Traditionally,
   29268              :      the debugger has used the second (possibly duplicate) line number
   29269              :      at the beginning of the function to mark the end of the prologue.
   29270              :      We could eliminate any other duplicates within the function.  For
   29271              :      Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
   29272              :      that second line number entry.  */
   29273              :   /* Recall that this end-of-prologue indication is *not* the same thing
   29274              :      as the end_prologue debug hook.  The NOTE_INSN_PROLOGUE_END note,
   29275              :      to which the hook corresponds, follows the last insn that was
   29276              :      emitted by gen_prologue.  What we need is to precede the first insn
   29277              :      that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
   29278              :      insn that corresponds to something the user wrote.  These may be
   29279              :      very different locations once scheduling is enabled.  */
   29280              : 
   29281     36670875 :   if (0 && file_num == table->file_num
   29282              :       && line == table->line_num
   29283              :       && column == table->column_num
   29284              :       && discriminator == table->discrim_num
   29285              :       && is_stmt == table->is_stmt)
   29286              :     return;
   29287              : 
   29288     36670875 :   switch_to_section (current_function_section ());
   29289              : 
   29290              :   /* If requested, emit something human-readable.  */
   29291     36670875 :   if (flag_debug_asm)
   29292              :     {
   29293         6659 :       if (debug_column_info)
   29294         6602 :         fprintf (asm_out_file, "\t%s %s:%d:%d\n", ASM_COMMENT_START,
   29295              :                  filename, line, column);
   29296              :       else
   29297           57 :         fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
   29298              :                  filename, line);
   29299              :     }
   29300              : 
   29301     36670875 :   if (output_asm_line_debug_info ())
   29302              :     {
   29303              :       /* Emit the .loc directive understood by GNU as.  */
   29304              :       /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
   29305              :          file_num, line, is_stmt, discriminator */
   29306     36669269 :       fputs ("\t.loc ", asm_out_file);
   29307     36669269 :       fprint_ul (asm_out_file, file_num);
   29308     36669269 :       putc (' ', asm_out_file);
   29309     36669269 :       fprint_ul (asm_out_file, line);
   29310     36669269 :       putc (' ', asm_out_file);
   29311     36669269 :       fprint_ul (asm_out_file, column);
   29312              : 
   29313     36669269 :       if (is_stmt != table->is_stmt)
   29314              :         {
   29315              : #if HAVE_GAS_LOC_STMT
   29316     14105269 :           fputs (" is_stmt ", asm_out_file);
   29317     21174465 :           putc (is_stmt ? '1' : '0', asm_out_file);
   29318              : #endif
   29319              :         }
   29320     36669269 :       if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
   29321              :         {
   29322      9962821 :           gcc_assert (discriminator > 0);
   29323      9962821 :           fputs (" discriminator ", asm_out_file);
   29324      9962821 :           fprint_ul (asm_out_file, (unsigned long) discriminator);
   29325              :         }
   29326     36669269 :       if (debug_variable_location_views)
   29327              :         {
   29328     35827941 :           if (!RESETTING_VIEW_P (table->view))
   29329              :             {
   29330     35376788 :               table->symviews_since_reset++;
   29331     35376788 :               if (table->symviews_since_reset > symview_upper_bound)
   29332      7505451 :                 symview_upper_bound = table->symviews_since_reset;
   29333              :               /* When we're using the assembler to compute view
   29334              :                  numbers, we output symbolic labels after "view" in
   29335              :                  .loc directives, and the assembler will set them for
   29336              :                  us, so that we can refer to the view numbers in
   29337              :                  location lists.  The only exceptions are when we know
   29338              :                  a view will be zero: "-0" is a forced reset, used
   29339              :                  e.g. in the beginning of functions, whereas "0" tells
   29340              :                  the assembler to check that there was a PC change
   29341              :                  since the previous view, in a way that implicitly
   29342              :                  resets the next view.  */
   29343     35376788 :               fputs (" view ", asm_out_file);
   29344     35376788 :               char label[MAX_ARTIFICIAL_LABEL_BYTES];
   29345     35376788 :               ASM_GENERATE_INTERNAL_LABEL (label, "LVU", table->view);
   29346     35376788 :               assemble_name (asm_out_file, label);
   29347     35376788 :               table->view = ++lvugid;
   29348              :             }
   29349              :           else
   29350              :             {
   29351       451153 :               table->symviews_since_reset = 0;
   29352       451153 :               if (FORCE_RESETTING_VIEW_P (table->view))
   29353       451153 :                 fputs (" view -0", asm_out_file);
   29354              :               else
   29355            0 :                 fputs (" view 0", asm_out_file);
   29356              :               /* Mark the present view as a zero view.  Earlier debug
   29357              :                  binds may have already added its id to loclists to be
   29358              :                  emitted later, so we can't reuse the id for something
   29359              :                  else.  However, it's good to know whether a view is
   29360              :                  known to be zero, because then we may be able to
   29361              :                  optimize out locviews that are all zeros, so take
   29362              :                  note of it in zero_view_p.  */
   29363       451153 :               if (!zero_view_p)
   29364        42241 :                 zero_view_p = BITMAP_GGC_ALLOC ();
   29365       451153 :               bitmap_set_bit (zero_view_p, lvugid);
   29366       451153 :               table->view = ++lvugid;
   29367              :             }
   29368              :         }
   29369     36669269 :       putc ('\n', asm_out_file);
   29370              :     }
   29371              :   else
   29372              :     {
   29373         1606 :       unsigned int label_num = ++line_info_label_num;
   29374              : 
   29375         1606 :       targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
   29376              : 
   29377         1606 :       if (debug_variable_location_views && !RESETTING_VIEW_P (table->view))
   29378         1516 :         push_dw_line_info_entry (table, LI_adv_address, label_num);
   29379              :       else
   29380           90 :         push_dw_line_info_entry (table, LI_set_address, label_num);
   29381         1606 :       if (debug_variable_location_views)
   29382              :         {
   29383         1550 :           bool resetting = FORCE_RESETTING_VIEW_P (table->view);
   29384         1550 :           if (resetting)
   29385           34 :             table->view = 0;
   29386              : 
   29387         1550 :           if (flag_debug_asm)
   29388           88 :             fprintf (asm_out_file, "\t%s view %s%d\n",
   29389              :                      ASM_COMMENT_START,
   29390              :                      resetting ? "-" : "",
   29391              :                      table->view);
   29392              : 
   29393         1550 :           table->view++;
   29394              :         }
   29395         1606 :       if (file_num != table->file_num)
   29396          280 :         push_dw_line_info_entry (table, LI_set_file, file_num);
   29397         1606 :       if (discriminator != table->discrim_num)
   29398          281 :         push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
   29399         1606 :       if (is_stmt != table->is_stmt)
   29400          573 :         push_dw_line_info_entry (table, LI_negate_stmt, 0);
   29401         1606 :       push_dw_line_info_entry (table, LI_set_line, line);
   29402         1606 :       if (debug_column_info)
   29403         1606 :         push_dw_line_info_entry (table, LI_set_column, column);
   29404              :     }
   29405              : 
   29406     36670875 :   table->file_num = file_num;
   29407     36670875 :   table->line_num = line;
   29408     36670875 :   table->column_num = column;
   29409     36670875 :   table->discrim_num = discriminator;
   29410     36670875 :   table->is_stmt = is_stmt;
   29411     36670875 :   table->in_use = true;
   29412              : }
   29413              : 
   29414              : /* Record a source file location for a DECL_IGNORED_P function.  */
   29415              : 
   29416              : static void
   29417         3928 : dwarf2out_set_ignored_loc (unsigned int line, unsigned int column,
   29418              :                            const char *filename)
   29419              : {
   29420         3928 :   dw_fde_ref fde = cfun->fde;
   29421              : 
   29422         3928 :   fde->ignored_debug = false;
   29423         3928 :   set_cur_line_info_table (current_function_section ());
   29424              : 
   29425         3928 :   dwarf2out_source_line (line, column, filename, 0, true);
   29426         3928 : }
   29427              : 
   29428              : /* Record the beginning of a new source file.  */
   29429              : 
   29430              : static void
   29431      7779440 : dwarf2out_start_source_file (unsigned int lineno, const char *filename)
   29432              : {
   29433              : #ifdef CODEVIEW_DEBUGGING_INFO
   29434              :   if (codeview_debuginfo_p ())
   29435              :     codeview_start_source_file (filename);
   29436              : #endif
   29437              : 
   29438      7779440 :   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
   29439              :     {
   29440         1867 :       macinfo_entry e;
   29441         1867 :       e.code = DW_MACINFO_start_file;
   29442         1867 :       e.lineno = lineno;
   29443         1867 :       e.info = ggc_strdup (filename);
   29444         1867 :       vec_safe_push (macinfo_table, e);
   29445              :     }
   29446      7779440 : }
   29447              : 
   29448              : /* Record the end of a source file.  */
   29449              : 
   29450              : static void
   29451      7779324 : dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
   29452              : {
   29453      7779324 :   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
   29454              :     {
   29455         1867 :       macinfo_entry e;
   29456         1867 :       e.code = DW_MACINFO_end_file;
   29457         1867 :       e.lineno = lineno;
   29458         1867 :       e.info = NULL;
   29459         1867 :       vec_safe_push (macinfo_table, e);
   29460              :     }
   29461      7779324 : }
   29462              : 
   29463              : /* Called from debug_define in toplev.cc.  The `buffer' parameter contains
   29464              :    the tail part of the directive line, i.e. the part which is past the
   29465              :    initial whitespace, #, whitespace, directive-name, whitespace part.  */
   29466              : 
   29467              : static void
   29468       243317 : dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
   29469              :                   const char *buffer ATTRIBUTE_UNUSED)
   29470              : {
   29471       243317 :   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
   29472              :     {
   29473       243317 :       macinfo_entry e;
   29474              :       /* Insert a dummy first entry to be able to optimize the whole
   29475              :          predefined macro block using DW_MACRO_import.  */
   29476       243317 :       if (macinfo_table->is_empty () && lineno <= 1)
   29477              :         {
   29478          522 :           e.code = 0;
   29479          522 :           e.lineno = 0;
   29480          522 :           e.info = NULL;
   29481          522 :           vec_safe_push (macinfo_table, e);
   29482              :         }
   29483       243317 :       e.code = DW_MACINFO_define;
   29484       243317 :       e.lineno = lineno;
   29485       243317 :       e.info = ggc_strdup (buffer);
   29486       243317 :       vec_safe_push (macinfo_table, e);
   29487              :     }
   29488       243317 : }
   29489              : 
   29490              : /* Called from debug_undef in toplev.cc.  The `buffer' parameter contains
   29491              :    the tail part of the directive line, i.e. the part which is past the
   29492              :    initial whitespace, #, whitespace, directive-name, whitespace part.  */
   29493              : 
   29494              : static void
   29495          849 : dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
   29496              :                  const char *buffer ATTRIBUTE_UNUSED)
   29497              : {
   29498          849 :   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
   29499              :     {
   29500          849 :       macinfo_entry e;
   29501              :       /* Insert a dummy first entry to be able to optimize the whole
   29502              :          predefined macro block using DW_MACRO_import.  */
   29503          849 :       if (macinfo_table->is_empty () && lineno <= 1)
   29504              :         {
   29505            0 :           e.code = 0;
   29506            0 :           e.lineno = 0;
   29507            0 :           e.info = NULL;
   29508            0 :           vec_safe_push (macinfo_table, e);
   29509              :         }
   29510          849 :       e.code = DW_MACINFO_undef;
   29511          849 :       e.lineno = lineno;
   29512          849 :       e.info = ggc_strdup (buffer);
   29513          849 :       vec_safe_push (macinfo_table, e);
   29514              :     }
   29515          849 : }
   29516              : 
   29517              : /* Helpers to manipulate hash table of CUs.  */
   29518              : 
   29519              : struct macinfo_entry_hasher : nofree_ptr_hash <macinfo_entry>
   29520              : {
   29521              :   static inline hashval_t hash (const macinfo_entry *);
   29522              :   static inline bool equal (const macinfo_entry *, const macinfo_entry *);
   29523              : };
   29524              : 
   29525              : inline hashval_t
   29526         6270 : macinfo_entry_hasher::hash (const macinfo_entry *entry)
   29527              : {
   29528         6270 :   return htab_hash_string (entry->info);
   29529              : }
   29530              : 
   29531              : inline bool
   29532         4633 : macinfo_entry_hasher::equal (const macinfo_entry *entry1,
   29533              :                              const macinfo_entry *entry2)
   29534              : {
   29535         4633 :   return !strcmp (entry1->info, entry2->info);
   29536              : }
   29537              : 
   29538              : typedef hash_table<macinfo_entry_hasher> macinfo_hash_type;
   29539              : 
   29540              : /* Output a single .debug_macinfo entry.  */
   29541              : 
   29542              : static void
   29543       247421 : output_macinfo_op (macinfo_entry *ref)
   29544              : {
   29545       489436 :   int file_num;
   29546       489436 :   size_t len;
   29547       489436 :   struct indirect_string_node *node;
   29548       489436 :   char label[MAX_ARTIFICIAL_LABEL_BYTES];
   29549       489436 :   struct dwarf_file_data *fd;
   29550              : 
   29551       489436 :   switch (ref->code)
   29552              :     {
   29553         1861 :     case DW_MACINFO_start_file:
   29554         1861 :       fd = lookup_filename (ref->info);
   29555         1861 :       file_num = maybe_emit_file (fd);
   29556         1861 :       dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
   29557         1861 :       dw2_asm_output_data_uleb128 (ref->lineno,
   29558              :                                    "Included from line number "
   29559              :                                    HOST_WIDE_INT_PRINT_UNSIGNED,
   29560              :                                    ref->lineno);
   29561         1861 :       dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
   29562         1861 :       break;
   29563         1861 :     case DW_MACINFO_end_file:
   29564         1861 :       dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
   29565         1861 :       break;
   29566       242034 :     case DW_MACINFO_define:
   29567       242034 :     case DW_MACINFO_undef:
   29568       242034 :       len = strlen (ref->info) + 1;
   29569       242034 :       if ((!dwarf_strict || dwarf_version >= 5)
   29570       242034 :           && len > (size_t) dwarf_offset_size
   29571              :           && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
   29572       242015 :           && (debug_str_section->common.flags & SECTION_MERGE) != 0)
   29573              :         {
   29574       242015 :           if (dwarf_split_debug_info)
   29575         1671 :             ref->code = ref->code == DW_MACINFO_define
   29576              :                         ? DW_MACRO_define_strx : DW_MACRO_undef_strx;
   29577              :           else
   29578       241013 :             ref->code = ref->code == DW_MACINFO_define
   29579              :                         ? DW_MACRO_define_strp : DW_MACRO_undef_strp;
   29580       242015 :           output_macinfo_op (ref);
   29581              :           return;
   29582              :         }
   29583           36 :       dw2_asm_output_data (1, ref->code,
   29584              :                            ref->code == DW_MACINFO_define
   29585              :                            ? "Define macro" : "Undefine macro");
   29586           19 :       dw2_asm_output_data_uleb128 (ref->lineno,
   29587              :                                    "At line number "
   29588              :                                    HOST_WIDE_INT_PRINT_UNSIGNED,
   29589              :                                    ref->lineno);
   29590           19 :       dw2_asm_output_nstring (ref->info, -1, "The macro");
   29591           19 :       break;
   29592       239675 :     case DW_MACRO_define_strp:
   29593       239675 :       dw2_asm_output_data (1, ref->code, "Define macro strp");
   29594       239675 :       goto do_DW_MACRO_define_strpx;
   29595          669 :     case DW_MACRO_undef_strp:
   29596          669 :       dw2_asm_output_data (1, ref->code, "Undefine macro strp");
   29597          669 :       goto do_DW_MACRO_define_strpx;
   29598         1671 :     case DW_MACRO_define_strx:
   29599         1671 :       dw2_asm_output_data (1, ref->code, "Define macro strx");
   29600         1671 :       goto do_DW_MACRO_define_strpx;
   29601            0 :     case DW_MACRO_undef_strx:
   29602            0 :       dw2_asm_output_data (1, ref->code, "Undefine macro strx");
   29603              :       /* FALLTHRU */
   29604       242015 :     do_DW_MACRO_define_strpx:
   29605              :       /* NB: dwarf2out_finish performs:
   29606              :            1. save_macinfo_strings
   29607              :            2. hash table traverse of index_string
   29608              :            3. output_macinfo -> output_macinfo_op
   29609              :            4. output_indirect_strings
   29610              :                 -> hash table traverse of output_index_string
   29611              : 
   29612              :          When output_macinfo_op is called, all index strings have been
   29613              :          added to hash table by save_macinfo_strings and we can't pass
   29614              :          INSERT to find_slot_with_hash which may expand hash table, even
   29615              :          if no insertion is needed, and change hash table traverse order
   29616              :          between index_string and output_index_string.  */
   29617       242015 :       node = find_AT_string (ref->info, NO_INSERT);
   29618       242424 :       gcc_assert (node
   29619              :                   && (node->form == DW_FORM_strp
   29620              :                       || node->form == dwarf_FORM (DW_FORM_strx)));
   29621       242015 :       dw2_asm_output_data_uleb128 (ref->lineno,
   29622              :                                    "At line number "
   29623              :                                    HOST_WIDE_INT_PRINT_UNSIGNED,
   29624              :                                    ref->lineno);
   29625       242015 :       if (node->form == DW_FORM_strp)
   29626              :         {
   29627       240344 :           gcc_assert (ref->code == DW_MACRO_define_strp
   29628              :                       || ref->code == DW_MACRO_undef_strp);
   29629       240344 :           dw2_asm_output_offset (dwarf_offset_size, node->label,
   29630              :                                  debug_str_section, "The macro: \"%s\"",
   29631              :                                  ref->info);
   29632              :         }
   29633              :       else
   29634              :         {
   29635         1671 :           gcc_assert (ref->code == DW_MACRO_define_strx
   29636              :                       || ref->code == DW_MACRO_undef_strx);
   29637         1671 :           dw2_asm_output_data_uleb128 (node->index, "The macro: \"%s\"",
   29638              :                                        ref->info);
   29639              :         }
   29640              :       break;
   29641         1665 :     case DW_MACRO_import:
   29642         1665 :       dw2_asm_output_data (1, ref->code, "Import");
   29643         1665 :       ASM_GENERATE_INTERNAL_LABEL (label,
   29644              :                                    DEBUG_MACRO_SECTION_LABEL,
   29645              :                                    ref->lineno + macinfo_label_base);
   29646         1665 :       dw2_asm_output_offset (dwarf_offset_size, label, NULL, NULL);
   29647         1665 :       break;
   29648            0 :     default:
   29649            0 :       fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
   29650              :                ASM_COMMENT_START, (unsigned long) ref->code);
   29651            0 :       break;
   29652              :     }
   29653              : }
   29654              : 
   29655              : /* Attempt to make a sequence of define/undef macinfo ops shareable with
   29656              :    other compilation unit .debug_macinfo sections.  IDX is the first
   29657              :    index of a define/undef, return the number of ops that should be
   29658              :    emitted in a comdat .debug_macinfo section and emit
   29659              :    a DW_MACRO_import entry referencing it.
   29660              :    If the define/undef entry should be emitted normally, return 0.  */
   29661              : 
   29662              : static unsigned
   29663         2049 : optimize_macinfo_range (unsigned int idx, vec<macinfo_entry, va_gc> *files,
   29664              :                         macinfo_hash_type **macinfo_htab)
   29665              : {
   29666         2049 :   macinfo_entry *first, *second, *cur, *inc;
   29667         2049 :   char linebuf[sizeof (HOST_WIDE_INT) * 3 + 1];
   29668         2049 :   unsigned char checksum[16];
   29669         2049 :   struct md5_ctx ctx;
   29670         2049 :   char *grp_name, *tail;
   29671         2049 :   const char *base;
   29672         2049 :   unsigned int i, count, encoded_filename_len, linebuf_len;
   29673         2049 :   macinfo_entry **slot;
   29674              : 
   29675         2049 :   first = &(*macinfo_table)[idx];
   29676         2049 :   second = &(*macinfo_table)[idx + 1];
   29677              : 
   29678              :   /* Optimize only if there are at least two consecutive define/undef ops,
   29679              :      and either all of them are before first DW_MACINFO_start_file
   29680              :      with lineno {0,1} (i.e. predefined macro block), or all of them are
   29681              :      in some included header file.  */
   29682         2049 :   if (second->code != DW_MACINFO_define && second->code != DW_MACINFO_undef)
   29683              :     return 0;
   29684         1665 :   if (vec_safe_is_empty (files))
   29685              :     {
   29686          515 :       if (first->lineno > 1 || second->lineno > 1)
   29687              :         return 0;
   29688              :     }
   29689         1150 :   else if (first->lineno == 0)
   29690              :     return 0;
   29691              : 
   29692              :   /* Find the last define/undef entry that can be grouped together
   29693              :      with first and at the same time compute md5 checksum of their
   29694              :      codes, linenumbers and strings.  */
   29695         1665 :   md5_init_ctx (&ctx);
   29696       243680 :   for (i = idx; macinfo_table->iterate (i, &cur); i++)
   29697       242015 :     if (cur->code != DW_MACINFO_define && cur->code != DW_MACINFO_undef)
   29698              :       break;
   29699       240350 :     else if (vec_safe_is_empty (files) && cur->lineno > 1)
   29700              :       break;
   29701              :     else
   29702              :       {
   29703       240350 :         unsigned char code = cur->code;
   29704       240350 :         md5_process_bytes (&code, 1, &ctx);
   29705       240350 :         checksum_uleb128 (cur->lineno, &ctx);
   29706       240350 :         md5_process_bytes (cur->info, strlen (cur->info) + 1, &ctx);
   29707              :       }
   29708         1665 :   md5_finish_ctx (&ctx, checksum);
   29709         1665 :   count = i - idx;
   29710              : 
   29711              :   /* From the containing include filename (if any) pick up just
   29712              :      usable characters from its basename.  */
   29713         1665 :   if (vec_safe_is_empty (files))
   29714              :     base = "";
   29715              :   else
   29716         1150 :     base = lbasename (files->last ().info);
   29717        14698 :   for (encoded_filename_len = 0, i = 0; base[i]; i++)
   29718        13033 :     if (ISIDNUM (base[i]) || base[i] == '.')
   29719        12401 :       encoded_filename_len++;
   29720              :   /* Count . at the end.  */
   29721         1665 :   if (encoded_filename_len)
   29722         1150 :     encoded_filename_len++;
   29723              : 
   29724         1665 :   sprintf (linebuf, HOST_WIDE_INT_PRINT_UNSIGNED, first->lineno);
   29725         1665 :   linebuf_len = strlen (linebuf);
   29726              : 
   29727              :   /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum>  */
   29728         1665 :   grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
   29729              :                          + 16 * 2 + 1);
   29730         1665 :   memcpy (grp_name, dwarf_offset_size == 4 ? "wm4." : "wm8.", 4);
   29731         1665 :   tail = grp_name + 4;
   29732         1665 :   if (encoded_filename_len)
   29733              :     {
   29734        14183 :       for (i = 0; base[i]; i++)
   29735        13033 :         if (ISIDNUM (base[i]) || base[i] == '.')
   29736        12401 :           *tail++ = base[i];
   29737         1150 :       *tail++ = '.';
   29738              :     }
   29739         1665 :   memcpy (tail, linebuf, linebuf_len);
   29740         1665 :   tail += linebuf_len;
   29741         1665 :   *tail++ = '.';
   29742        28305 :   for (i = 0; i < 16; i++)
   29743        26640 :     sprintf (tail + i * 2, "%02x", checksum[i] & 0xff);
   29744              : 
   29745              :   /* Construct a macinfo_entry for DW_MACRO_import
   29746              :      in the empty vector entry before the first define/undef.  */
   29747         1665 :   inc = &(*macinfo_table)[idx - 1];
   29748         1665 :   inc->code = DW_MACRO_import;
   29749         1665 :   inc->lineno = 0;
   29750         1665 :   inc->info = ggc_strdup (grp_name);
   29751         1665 :   if (!*macinfo_htab)
   29752          516 :     *macinfo_htab = new macinfo_hash_type (10);
   29753              :   /* Avoid emitting duplicates.  */
   29754         1665 :   slot = (*macinfo_htab)->find_slot (inc, INSERT);
   29755         1665 :   if (*slot != NULL)
   29756              :     {
   29757          109 :       inc->code = 0;
   29758          109 :       inc->info = NULL;
   29759              :       /* If such an entry has been used before, just emit
   29760              :          a DW_MACRO_import op.  */
   29761          109 :       inc = *slot;
   29762          109 :       output_macinfo_op (inc);
   29763              :       /* And clear all macinfo_entry in the range to avoid emitting them
   29764              :          in the second pass.  */
   29765          670 :       for (i = idx; macinfo_table->iterate (i, &cur) && i < idx + count; i++)
   29766              :         {
   29767          452 :           cur->code = 0;
   29768          452 :           cur->info = NULL;
   29769              :         }
   29770              :     }
   29771              :   else
   29772              :     {
   29773         1556 :       *slot = inc;
   29774         1556 :       inc->lineno = (*macinfo_htab)->elements ();
   29775         1556 :       output_macinfo_op (inc);
   29776              :     }
   29777              :   return count;
   29778              : }
   29779              : 
   29780              : /* Save any strings needed by the macinfo table in the debug str
   29781              :    table.  All strings must be collected into the table by the time
   29782              :    index_string is called.  */
   29783              : 
   29784              : static void
   29785        54573 : save_macinfo_strings (void)
   29786              : {
   29787        54573 :   unsigned len;
   29788        54573 :   unsigned i;
   29789        54573 :   macinfo_entry *ref;
   29790              : 
   29791       301300 :   for (i = 0; macinfo_table && macinfo_table->iterate (i, &ref); i++)
   29792              :     {
   29793       246727 :       switch (ref->code)
   29794              :         {
   29795              :           /* Match the logic in output_macinfo_op to decide on
   29796              :              indirect strings.  */
   29797       242486 :           case DW_MACINFO_define:
   29798       242486 :           case DW_MACINFO_undef:
   29799       242486 :             len = strlen (ref->info) + 1;
   29800       242486 :             if ((!dwarf_strict || dwarf_version >= 5)
   29801       242486 :                 && len > (unsigned) dwarf_offset_size
   29802              :                 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
   29803       242466 :                 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
   29804       242466 :               set_indirect_string (find_AT_string (ref->info));
   29805              :             break;
   29806         1861 :           case DW_MACINFO_start_file:
   29807              :             /* -gsplit-dwarf -g3 will also output filename as indirect
   29808              :                string.  */
   29809         1861 :             if (!dwarf_split_debug_info)
   29810              :               break;
   29811              :             /* Fall through. */
   29812            8 :           case DW_MACRO_define_strp:
   29813            8 :           case DW_MACRO_undef_strp:
   29814            8 :           case DW_MACRO_define_strx:
   29815            8 :           case DW_MACRO_undef_strx:
   29816            8 :             set_indirect_string (find_AT_string (ref->info));
   29817            8 :             break;
   29818              :           default:
   29819              :             break;
   29820              :         }
   29821              :     }
   29822        54573 : }
   29823              : 
   29824              : /* Output macinfo section(s).  */
   29825              : 
   29826              : static void
   29827          528 : output_macinfo (const char *debug_line_label, bool early_lto_debug)
   29828              : {
   29829          528 :   unsigned i;
   29830          528 :   unsigned long length = vec_safe_length (macinfo_table);
   29831          528 :   macinfo_entry *ref;
   29832          528 :   vec<macinfo_entry, va_gc> *files = NULL;
   29833          528 :   macinfo_hash_type *macinfo_htab = NULL;
   29834          528 :   char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
   29835              : 
   29836          528 :   if (! length)
   29837           12 :     return;
   29838              : 
   29839              :   /* output_macinfo* uses these interchangeably.  */
   29840          528 :   gcc_assert ((int) DW_MACINFO_define == (int) DW_MACRO_define
   29841              :               && (int) DW_MACINFO_undef == (int) DW_MACRO_undef
   29842              :               && (int) DW_MACINFO_start_file == (int) DW_MACRO_start_file
   29843              :               && (int) DW_MACINFO_end_file == (int) DW_MACRO_end_file);
   29844              : 
   29845              :   /* AIX Assembler inserts the length, so adjust the reference to match the
   29846              :      offset expected by debuggers.  */
   29847          528 :   strcpy (dl_section_ref, debug_line_label);
   29848          528 :   if (XCOFF_DEBUGGING_INFO)
   29849              :     strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
   29850              : 
   29851              :   /* For .debug_macro emit the section header.  */
   29852          528 :   if (!dwarf_strict || dwarf_version >= 5)
   29853              :     {
   29854         1033 :       dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
   29855              :                            "DWARF macro version number");
   29856          528 :       if (dwarf_offset_size == 8)
   29857            0 :         dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
   29858              :       else
   29859          528 :         dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
   29860          528 :       dw2_asm_output_offset (dwarf_offset_size, debug_line_label,
   29861              :                              debug_line_section, NULL);
   29862              :     }
   29863              : 
   29864              :   /* In the first loop, it emits the primary .debug_macinfo section
   29865              :      and after each emitted op the macinfo_entry is cleared.
   29866              :      If a longer range of define/undef ops can be optimized using
   29867              :      DW_MACRO_import, the DW_MACRO_import op is emitted and kept in
   29868              :      the vector before the first define/undef in the range and the
   29869              :      whole range of define/undef ops is not emitted and kept.  */
   29870         8570 :   for (i = 0; macinfo_table->iterate (i, &ref); i++)
   29871              :     {
   29872         8042 :       switch (ref->code)
   29873              :         {
   29874         1861 :         case DW_MACINFO_start_file:
   29875         1861 :           vec_safe_push (files, *ref);
   29876         1861 :           break;
   29877         1861 :         case DW_MACINFO_end_file:
   29878         1861 :           if (!vec_safe_is_empty (files))
   29879         1861 :             files->pop ();
   29880              :           break;
   29881         3801 :         case DW_MACINFO_define:
   29882         3801 :         case DW_MACINFO_undef:
   29883            0 :           if ((!dwarf_strict || dwarf_version >= 5)
   29884         3801 :               && !dwarf_split_debug_info
   29885              :               && HAVE_COMDAT_GROUP
   29886         2130 :               && vec_safe_length (files) != 1
   29887         2049 :               && i > 0
   29888         2049 :               && i + 1 < length
   29889         5850 :               && (*macinfo_table)[i - 1].code == 0)
   29890              :             {
   29891         2049 :               unsigned count = optimize_macinfo_range (i, files, &macinfo_htab);
   29892         2049 :               if (count)
   29893              :                 {
   29894         1665 :                   i += count - 1;
   29895         1665 :                   continue;
   29896              :                 }
   29897              :             }
   29898              :           break;
   29899          519 :         case 0:
   29900              :           /* A dummy entry may be inserted at the beginning to be able
   29901              :              to optimize the whole block of predefined macros.  */
   29902          519 :           if (i == 0)
   29903          519 :             continue;
   29904              :         default:
   29905              :           break;
   29906              :         }
   29907         5858 :       output_macinfo_op (ref);
   29908         5858 :       ref->info = NULL;
   29909         5858 :       ref->code = 0;
   29910              :     }
   29911              : 
   29912          528 :   if (!macinfo_htab)
   29913              :     return;
   29914              : 
   29915              :   /* Save the number of transparent includes so we can adjust the
   29916              :      label number for the fat LTO object DWARF.  */
   29917          516 :   unsigned macinfo_label_base_adj = macinfo_htab->elements ();
   29918              : 
   29919          516 :   delete macinfo_htab;
   29920          516 :   macinfo_htab = NULL;
   29921              : 
   29922              :   /* If any DW_MACRO_import were used, on those DW_MACRO_import entries
   29923              :      terminate the current chain and switch to a new comdat .debug_macinfo
   29924              :      section and emit the define/undef entries within it.  */
   29925       246020 :   for (i = 0; macinfo_table->iterate (i, &ref); i++)
   29926       244988 :     switch (ref->code)
   29927              :       {
   29928         3534 :       case 0:
   29929         3534 :         continue;
   29930         1556 :       case DW_MACRO_import:
   29931         1556 :         {
   29932         1556 :           char label[MAX_ARTIFICIAL_LABEL_BYTES];
   29933         1556 :           tree comdat_key = get_identifier (ref->info);
   29934              :           /* Terminate the previous .debug_macinfo section.  */
   29935         1556 :           dw2_asm_output_data (1, 0, "End compilation unit");
   29936         3082 :           targetm.asm_out.named_section (debug_macinfo_section_name,
   29937              :                                          SECTION_DEBUG
   29938              :                                          | SECTION_LINKONCE
   29939              :                                          | (early_lto_debug
   29940              :                                             ? SECTION_EXCLUDE : 0),
   29941              :                                          comdat_key);
   29942         1556 :           ASM_GENERATE_INTERNAL_LABEL (label,
   29943              :                                        DEBUG_MACRO_SECTION_LABEL,
   29944              :                                        ref->lineno + macinfo_label_base);
   29945         1556 :           ASM_OUTPUT_LABEL (asm_out_file, label);
   29946         1556 :           ref->code = 0;
   29947         1556 :           ref->info = NULL;
   29948         2554 :           dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
   29949              :                                "DWARF macro version number");
   29950         1556 :           if (dwarf_offset_size == 8)
   29951            0 :             dw2_asm_output_data (1, 1, "Flags: 64-bit");
   29952              :           else
   29953         1556 :             dw2_asm_output_data (1, 0, "Flags: 32-bit");
   29954              :         }
   29955         1556 :         break;
   29956       239898 :       case DW_MACINFO_define:
   29957       239898 :       case DW_MACINFO_undef:
   29958       239898 :         output_macinfo_op (ref);
   29959       239898 :         ref->code = 0;
   29960       239898 :         ref->info = NULL;
   29961       239898 :         break;
   29962            0 :       default:
   29963            0 :         gcc_unreachable ();
   29964         3534 :       }
   29965              : 
   29966          516 :   macinfo_label_base += macinfo_label_base_adj;
   29967              : }
   29968              : 
   29969              : /* As init_sections_and_labels may get called multiple times, have a
   29970              :    generation count for labels.  */
   29971              : static unsigned init_sections_and_labels_generation;
   29972              : 
   29973              : /* Initialize the various sections and labels for dwarf output and prefix
   29974              :    them with PREFIX if non-NULL.  Returns the generation (zero based
   29975              :    number of times function was called).  */
   29976              : 
   29977              : static unsigned
   29978        54573 : init_sections_and_labels (bool early_lto_debug)
   29979              : {
   29980        54573 :   if (early_lto_debug)
   29981              :     {
   29982         1338 :       if (!dwarf_split_debug_info)
   29983              :         {
   29984         1338 :           debug_info_section = get_section (DEBUG_LTO_INFO_SECTION,
   29985              :                                             SECTION_DEBUG | SECTION_EXCLUDE,
   29986              :                                             NULL);
   29987         1338 :           debug_abbrev_section = get_section (DEBUG_LTO_ABBREV_SECTION,
   29988              :                                               SECTION_DEBUG | SECTION_EXCLUDE,
   29989              :                                               NULL);
   29990         1338 :           debug_macinfo_section_name
   29991            0 :             = ((dwarf_strict && dwarf_version < 5)
   29992         1338 :                ? DEBUG_LTO_MACINFO_SECTION : DEBUG_LTO_MACRO_SECTION);
   29993         1338 :           debug_macinfo_section = get_section (debug_macinfo_section_name,
   29994              :                                                SECTION_DEBUG
   29995              :                                                | SECTION_EXCLUDE, NULL);
   29996              :         }
   29997              :       else
   29998              :         {
   29999              :           /* ???  Which of the following do we need early?  */
   30000            0 :           debug_info_section = get_section (DEBUG_LTO_DWO_INFO_SECTION,
   30001              :                                             SECTION_DEBUG | SECTION_EXCLUDE,
   30002              :                                             NULL);
   30003            0 :           debug_abbrev_section = get_section (DEBUG_LTO_DWO_ABBREV_SECTION,
   30004              :                                               SECTION_DEBUG | SECTION_EXCLUDE,
   30005              :                                               NULL);
   30006            0 :           debug_skeleton_info_section = get_section (DEBUG_LTO_INFO_SECTION,
   30007              :                                                      SECTION_DEBUG
   30008              :                                                      | SECTION_EXCLUDE, NULL);
   30009            0 :           debug_skeleton_abbrev_section
   30010            0 :             = get_section (DEBUG_LTO_ABBREV_SECTION,
   30011              :                            SECTION_DEBUG | SECTION_EXCLUDE, NULL);
   30012            0 :           ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
   30013              :                                        DEBUG_SKELETON_ABBREV_SECTION_LABEL,
   30014              :                                        init_sections_and_labels_generation);
   30015              : 
   30016              :           /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
   30017              :              stay in the main .o, but the skeleton_line goes into the split
   30018              :              off dwo.  */
   30019            0 :           debug_skeleton_line_section
   30020            0 :             = get_section (DEBUG_LTO_LINE_SECTION,
   30021              :                            SECTION_DEBUG | SECTION_EXCLUDE, NULL);
   30022            0 :           ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
   30023              :                                        DEBUG_SKELETON_LINE_SECTION_LABEL,
   30024              :                                        init_sections_and_labels_generation);
   30025            0 :           debug_str_offsets_section
   30026            0 :             = get_section (DEBUG_LTO_DWO_STR_OFFSETS_SECTION,
   30027              :                            SECTION_DEBUG | SECTION_EXCLUDE,
   30028              :                            NULL);
   30029            0 :           ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
   30030              :                                        DEBUG_SKELETON_INFO_SECTION_LABEL,
   30031              :                                        init_sections_and_labels_generation);
   30032            0 :           debug_str_dwo_section = get_section (DEBUG_LTO_STR_DWO_SECTION,
   30033              :                                                DEBUG_STR_DWO_SECTION_FLAGS,
   30034              :                                                NULL);
   30035            0 :           debug_macinfo_section_name
   30036            0 :             = ((dwarf_strict && dwarf_version < 5)
   30037            0 :                ? DEBUG_LTO_DWO_MACINFO_SECTION : DEBUG_LTO_DWO_MACRO_SECTION);
   30038            0 :           debug_macinfo_section = get_section (debug_macinfo_section_name,
   30039              :                                                SECTION_DEBUG | SECTION_EXCLUDE,
   30040              :                                                NULL);
   30041              :         }
   30042              :       /* For macro info and the file table we have to refer to a
   30043              :          debug_line section.  */
   30044         1338 :       debug_line_section = get_section (DEBUG_LTO_LINE_SECTION,
   30045              :                                         SECTION_DEBUG | SECTION_EXCLUDE, NULL);
   30046         1338 :       ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
   30047              :                                    DEBUG_LINE_SECTION_LABEL,
   30048              :                                    init_sections_and_labels_generation);
   30049              : 
   30050         1338 :       debug_str_section = get_section (DEBUG_LTO_STR_SECTION,
   30051         1338 :                                        DEBUG_STR_SECTION_FLAGS
   30052              :                                        | SECTION_EXCLUDE, NULL);
   30053         1338 :       if (!dwarf_split_debug_info)
   30054         1338 :         debug_line_str_section
   30055         1338 :           = get_section (DEBUG_LTO_LINE_STR_SECTION,
   30056         1338 :                          DEBUG_STR_SECTION_FLAGS | SECTION_EXCLUDE, NULL);
   30057              :     }
   30058              :   else
   30059              :     {
   30060        53235 :       if (!dwarf_split_debug_info)
   30061              :         {
   30062        52986 :           debug_info_section = get_section (DEBUG_INFO_SECTION,
   30063              :                                             SECTION_DEBUG, NULL);
   30064        52986 :           debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
   30065              :                                               SECTION_DEBUG, NULL);
   30066        54962 :           debug_loc_section = get_section (dwarf_version >= 5
   30067              :                                            ? DEBUG_LOCLISTS_SECTION
   30068              :                                            : DEBUG_LOC_SECTION,
   30069              :                                            SECTION_DEBUG, NULL);
   30070        52986 :           debug_macinfo_section_name
   30071            5 :             = ((dwarf_strict && dwarf_version < 5)
   30072        52986 :                ? DEBUG_MACINFO_SECTION : DEBUG_MACRO_SECTION);
   30073        52986 :           debug_macinfo_section = get_section (debug_macinfo_section_name,
   30074              :                                                SECTION_DEBUG, NULL);
   30075              :         }
   30076              :       else
   30077              :         {
   30078          249 :           debug_info_section = get_section (DEBUG_DWO_INFO_SECTION,
   30079              :                                             SECTION_DEBUG | SECTION_EXCLUDE,
   30080              :                                             NULL);
   30081          249 :           debug_abbrev_section = get_section (DEBUG_DWO_ABBREV_SECTION,
   30082              :                                               SECTION_DEBUG | SECTION_EXCLUDE,
   30083              :                                               NULL);
   30084          249 :           debug_addr_section = get_section (DEBUG_ADDR_SECTION,
   30085              :                                             SECTION_DEBUG, NULL);
   30086          249 :           debug_skeleton_info_section = get_section (DEBUG_INFO_SECTION,
   30087              :                                                      SECTION_DEBUG, NULL);
   30088          249 :           debug_skeleton_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
   30089              :                                                        SECTION_DEBUG, NULL);
   30090          249 :           ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label,
   30091              :                                        DEBUG_SKELETON_ABBREV_SECTION_LABEL,
   30092              :                                        init_sections_and_labels_generation);
   30093              : 
   30094              :           /* Somewhat confusing detail: The skeleton_[abbrev|info] sections
   30095              :              stay in the main .o, but the skeleton_line goes into the
   30096              :              split off dwo.  */
   30097          249 :           debug_skeleton_line_section
   30098          249 :               = get_section (DEBUG_DWO_LINE_SECTION,
   30099              :                              SECTION_DEBUG | SECTION_EXCLUDE, NULL);
   30100          249 :           ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label,
   30101              :                                        DEBUG_SKELETON_LINE_SECTION_LABEL,
   30102              :                                        init_sections_and_labels_generation);
   30103          249 :           debug_str_offsets_section
   30104          249 :             = get_section (DEBUG_DWO_STR_OFFSETS_SECTION,
   30105              :                            SECTION_DEBUG | SECTION_EXCLUDE, NULL);
   30106          249 :           ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label,
   30107              :                                        DEBUG_SKELETON_INFO_SECTION_LABEL,
   30108              :                                        init_sections_and_labels_generation);
   30109          250 :           debug_loc_section = get_section (dwarf_version >= 5
   30110              :                                            ? DEBUG_DWO_LOCLISTS_SECTION
   30111              :                                            : DEBUG_DWO_LOC_SECTION,
   30112              :                                            SECTION_DEBUG | SECTION_EXCLUDE,
   30113              :                                            NULL);
   30114          249 :           debug_str_dwo_section = get_section (DEBUG_STR_DWO_SECTION,
   30115              :                                                DEBUG_STR_DWO_SECTION_FLAGS,
   30116              :                                                NULL);
   30117          249 :           debug_macinfo_section_name
   30118            0 :             = ((dwarf_strict && dwarf_version < 5)
   30119          249 :                ? DEBUG_DWO_MACINFO_SECTION : DEBUG_DWO_MACRO_SECTION);
   30120          249 :           debug_macinfo_section = get_section (debug_macinfo_section_name,
   30121              :                                                SECTION_DEBUG | SECTION_EXCLUDE,
   30122              :                                                NULL);
   30123          249 :           if (dwarf_version >= 5)
   30124          248 :             debug_ranges_dwo_section
   30125          248 :               = get_section (DEBUG_DWO_RNGLISTS_SECTION,
   30126              :                              SECTION_DEBUG | SECTION_EXCLUDE, NULL);
   30127              :         }
   30128        53235 :       debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
   30129              :                                            SECTION_DEBUG, NULL);
   30130        53235 :       debug_line_section = get_section (DEBUG_LINE_SECTION,
   30131              :                                         SECTION_DEBUG, NULL);
   30132       106221 :       debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
   30133              :                                             SECTION_DEBUG, NULL);
   30134       106221 :       debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
   30135              :                                             SECTION_DEBUG, NULL);
   30136        53235 :       debug_str_section = get_section (DEBUG_STR_SECTION,
   30137        53235 :                                        DEBUG_STR_SECTION_FLAGS, NULL);
   30138        52986 :       if ((!dwarf_split_debug_info && !output_asm_line_debug_info ())
   30139       106215 :           || asm_outputs_debug_line_str ())
   30140        51013 :         debug_line_str_section = get_section (DEBUG_LINE_STR_SECTION,
   30141        51013 :                                               DEBUG_STR_SECTION_FLAGS, NULL);
   30142              : 
   30143        55212 :       debug_ranges_section = get_section (dwarf_version >= 5
   30144              :                                           ? DEBUG_RNGLISTS_SECTION
   30145              :                                           : DEBUG_RANGES_SECTION,
   30146              :                                           SECTION_DEBUG, NULL);
   30147        53235 :       debug_frame_section = get_section (DEBUG_FRAME_SECTION,
   30148              :                                          SECTION_DEBUG, NULL);
   30149              :     }
   30150              : 
   30151        54573 :   ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
   30152              :                                DEBUG_ABBREV_SECTION_LABEL,
   30153              :                                init_sections_and_labels_generation);
   30154        54573 :   ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
   30155              :                                DEBUG_INFO_SECTION_LABEL,
   30156              :                                init_sections_and_labels_generation);
   30157        54573 :   info_section_emitted = false;
   30158        54573 :   ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
   30159              :                                DEBUG_LINE_SECTION_LABEL,
   30160              :                                init_sections_and_labels_generation);
   30161              :   /* There are up to 6 unique ranges labels per generation.
   30162              :      See also output_rnglists.  */
   30163        54573 :   ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
   30164              :                                DEBUG_RANGES_SECTION_LABEL,
   30165              :                                init_sections_and_labels_generation * 6);
   30166        54573 :   if (dwarf_version >= 5 && dwarf_split_debug_info)
   30167          248 :     ASM_GENERATE_INTERNAL_LABEL (ranges_base_label,
   30168              :                                  DEBUG_RANGES_SECTION_LABEL,
   30169              :                                  1 + init_sections_and_labels_generation * 6);
   30170        54573 :   ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label,
   30171              :                                DEBUG_ADDR_SECTION_LABEL,
   30172              :                                init_sections_and_labels_generation);
   30173       109141 :   ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
   30174              :                                (dwarf_strict && dwarf_version < 5)
   30175              :                                ? DEBUG_MACINFO_SECTION_LABEL
   30176              :                                : DEBUG_MACRO_SECTION_LABEL,
   30177              :                                init_sections_and_labels_generation);
   30178        54573 :   ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL,
   30179              :                                init_sections_and_labels_generation);
   30180              : 
   30181        54573 :   ++init_sections_and_labels_generation;
   30182        54573 :   return init_sections_and_labels_generation - 1;
   30183              : }
   30184              : 
   30185              : /* Set up for Dwarf output at the start of compilation.  */
   30186              : 
   30187              : static void
   30188        56683 : dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
   30189              : {
   30190              :   /* Allocate the file_table.  */
   30191        56683 :   file_table = hash_table<dwarf_file_hasher>::create_ggc (50);
   30192              : 
   30193              : #ifndef DWARF2_LINENO_DEBUGGING_INFO
   30194              :   /* Allocate the decl_die_table.  */
   30195        56683 :   decl_die_table = hash_table<decl_die_hasher>::create_ggc (10);
   30196              : 
   30197              :   /* Allocate the decl_loc_table.  */
   30198        56683 :   decl_loc_table = hash_table<decl_loc_hasher>::create_ggc (10);
   30199              : 
   30200              :   /* Allocate the cached_dw_loc_list_table.  */
   30201        56683 :   cached_dw_loc_list_table = hash_table<dw_loc_list_hasher>::create_ggc (10);
   30202              : 
   30203              :   /* Allocate the initial hunk of the abbrev_die_table.  */
   30204        56683 :   vec_alloc (abbrev_die_table, 256);
   30205              :   /* Zero-th entry is allocated, but unused.  */
   30206        56683 :   abbrev_die_table->quick_push (NULL);
   30207              : 
   30208              :   /* Allocate the dwarf_proc_stack_usage_map.  */
   30209        56683 :   dwarf_proc_stack_usage_map = new hash_map<dw_die_ref, int>;
   30210              : 
   30211              :   /* Allocate the pubtypes and pubnames vectors.  */
   30212        56683 :   vec_alloc (pubname_table, 32);
   30213        56683 :   vec_alloc (pubtype_table, 32);
   30214              : 
   30215        56683 :   vec_alloc (incomplete_types, 64);
   30216              : 
   30217        56683 :   vec_alloc (used_rtx_array, 32);
   30218              : 
   30219        56683 :   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
   30220          534 :     vec_alloc (macinfo_table, 64);
   30221              : #endif
   30222              : 
   30223              :   /* If front-ends already registered a main translation unit but we were not
   30224              :      ready to perform the association, do this now.  */
   30225        56683 :   if (main_translation_unit != NULL_TREE)
   30226        18424 :     equate_decl_number_to_die (main_translation_unit, comp_unit_die ());
   30227        56683 : }
   30228              : 
   30229              : /* Called before compile () starts outputtting functions, variables
   30230              :    and toplevel asms into assembly.  */
   30231              : 
   30232              : static void
   30233        53563 : dwarf2out_assembly_start (void)
   30234              : {
   30235        53563 :   if (text_section_line_info)
   30236              :     return;
   30237              : 
   30238              : #ifndef DWARF2_LINENO_DEBUGGING_INFO
   30239        53562 :   ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
   30240        53562 :   ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
   30241        53562 :   ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
   30242              :                                COLD_TEXT_SECTION_LABEL, 0);
   30243        53562 :   ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
   30244              : 
   30245        53562 :   switch_to_section (text_section);
   30246        53562 :   ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
   30247              : #endif
   30248              : 
   30249              :   /* Make sure the line number table for .text always exists.  */
   30250        53562 :   text_section_line_info = new_line_info_table ();
   30251        53562 :   text_section_line_info->end_label = text_end_label;
   30252              : 
   30253              : #ifdef DWARF2_LINENO_DEBUGGING_INFO
   30254              :   cur_line_info_table = text_section_line_info;
   30255              : #endif
   30256              : 
   30257        53562 :   if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
   30258        53562 :       && dwarf2out_do_cfi_asm ()
   30259        53562 :       && !dwarf2out_do_eh_frame ())
   30260            5 :     fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
   30261              : 
   30262              : #if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG)
   30263        53562 :   if (output_asm_line_debug_info () && dwarf_version >= 5)
   30264              :     {
   30265              :       /* When gas outputs DWARF5 .debug_line[_str] then we have to
   30266              :          tell it the comp_dir and main file name for the zero entry
   30267              :          line table.  */
   30268        51582 :       const char *comp_dir, *filename0;
   30269              : 
   30270        51582 :       comp_dir = comp_dir_string ();
   30271        51582 :       if (comp_dir == NULL)
   30272            0 :         comp_dir = "";
   30273              : 
   30274        51582 :       filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
   30275        51582 :       if (filename0 == NULL)
   30276            1 :         filename0 = "";
   30277              : 
   30278        51582 :       fprintf (asm_out_file, "\t.file 0 ");
   30279        51582 :       output_quoted_string (asm_out_file, remap_debug_filename (comp_dir));
   30280        51582 :       fputc (' ', asm_out_file);
   30281        51582 :       output_quoted_string (asm_out_file, remap_debug_filename (filename0));
   30282        51582 :       fputc ('\n', asm_out_file);
   30283              :     }
   30284              :   else
   30285              : #endif
   30286              :   /* Work around for PR101575: output a dummy .file directive.  */
   30287         1970 :   if (!last_emitted_file && dwarf_debuginfo_p ()
   30288         3950 :       && debug_info_level >= DINFO_LEVEL_TERSE)
   30289              :     {
   30290         1970 :       const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
   30291              : 
   30292         1970 :       if (filename0 == NULL)
   30293            0 :         filename0 = "<dummy>";
   30294         1970 :       maybe_emit_file (lookup_filename (filename0));
   30295              :     }
   30296              : }
   30297              : 
   30298              : /* A helper function for dwarf2out_finish called through
   30299              :    htab_traverse.  Assign a string its index.  All strings must be
   30300              :    collected into the table by the time index_string is called,
   30301              :    because the indexing code relies on htab_traverse to traverse nodes
   30302              :    in the same order for each run. */
   30303              : 
   30304              : int
   30305         2927 : index_string (indirect_string_node **h, unsigned int *index)
   30306              : {
   30307         2927 :   indirect_string_node *node = *h;
   30308              : 
   30309         2927 :   find_string_form (node);
   30310         3340 :   if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
   30311              :     {
   30312         2610 :       gcc_assert (node->index == NO_INDEX_ASSIGNED);
   30313         2610 :       node->index = *index;
   30314         2610 :       *index += 1;
   30315              :     }
   30316         2927 :   return 1;
   30317              : }
   30318              : 
   30319              : /* A helper function for output_indirect_strings called through
   30320              :    htab_traverse.  Output the offset to a string and update the
   30321              :    current offset.  */
   30322              : 
   30323              : int
   30324         2927 : output_index_string_offset (indirect_string_node **h, unsigned int *offset)
   30325              : {
   30326         2927 :   indirect_string_node *node = *h;
   30327              : 
   30328         3340 :   if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
   30329              :     {
   30330              :       /* Assert that this node has been assigned an index.  */
   30331         2610 :       gcc_assert (node->index != NO_INDEX_ASSIGNED
   30332              :                   && node->index != NOT_INDEXED);
   30333         2610 :       dw2_asm_output_data (dwarf_offset_size, *offset,
   30334              :                            "indexed string 0x%x: %s", node->index, node->str);
   30335         2610 :       *offset += strlen (node->str) + 1;
   30336              :     }
   30337         2927 :   return 1;
   30338              : }
   30339              : 
   30340              : /* A helper function for dwarf2out_finish called through
   30341              :    htab_traverse.  Output the indexed string.  */
   30342              : 
   30343              : int
   30344         2927 : output_index_string (indirect_string_node **h, unsigned int *cur_idx)
   30345              : {
   30346         2927 :   struct indirect_string_node *node = *h;
   30347              : 
   30348         3340 :   if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
   30349              :     {
   30350              :       /* Assert that the strings are output in the same order as their
   30351              :          indexes were assigned.  */
   30352         2610 :       gcc_assert (*cur_idx == node->index);
   30353         2610 :       assemble_string (node->str, strlen (node->str) + 1);
   30354         2610 :       *cur_idx += 1;
   30355              :     }
   30356         2927 :   return 1;
   30357              : }
   30358              : 
   30359              : /* A helper function for output_indirect_strings.  Counts the number
   30360              :    of index strings offsets.  Must match the logic of the functions
   30361              :    output_index_string[_offsets] above.  */
   30362              : int
   30363         2514 : count_index_strings (indirect_string_node **h, unsigned int *last_idx)
   30364              : {
   30365         2514 :   struct indirect_string_node *node = *h;
   30366              : 
   30367         2514 :   if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
   30368         2197 :     *last_idx += 1;
   30369         2514 :   return 1;
   30370              : }
   30371              : 
   30372              : /* A helper function for dwarf2out_finish called through
   30373              :    htab_traverse.  Emit one queued .debug_str string.  */
   30374              : 
   30375              : int
   30376     21640905 : output_indirect_string (indirect_string_node **h, enum dwarf_form form)
   30377              : {
   30378     21640905 :   struct indirect_string_node *node = *h;
   30379              : 
   30380     21640905 :   node->form = find_string_form (node);
   30381     21640905 :   if (node->form == form && node->refcount > 0)
   30382              :     {
   30383     20950101 :       ASM_OUTPUT_LABEL (asm_out_file, node->label);
   30384     20950101 :       assemble_string (node->str, strlen (node->str) + 1);
   30385              :     }
   30386              : 
   30387     21640905 :   return 1;
   30388              : }
   30389              : 
   30390              : /* Output the indexed string table.  */
   30391              : 
   30392              : static void
   30393        54573 : output_indirect_strings (void)
   30394              : {
   30395        54573 :   switch_to_section (debug_str_section);
   30396        54573 :   if (!dwarf_split_debug_info)
   30397        54324 :     debug_str_hash->traverse<enum dwarf_form,
   30398     21695229 :                              output_indirect_string> (DW_FORM_strp);
   30399              :   else
   30400              :     {
   30401          249 :       unsigned int offset = 0;
   30402          249 :       unsigned int cur_idx = 0;
   30403              : 
   30404          249 :       if (skeleton_debug_str_hash)
   30405          249 :         skeleton_debug_str_hash->traverse<enum dwarf_form,
   30406          249 :                                           output_indirect_string> (DW_FORM_strp);
   30407              : 
   30408          249 :       switch_to_section (debug_str_offsets_section);
   30409              :       /* For DWARF5 the .debug_str_offsets[.dwo] section needs a unit
   30410              :          header.  Note that we don't need to generate a label to the
   30411              :          actual index table following the header here, because this is
   30412              :          for the split dwarf case only.  In an .dwo file there is only
   30413              :          one string offsets table (and one debug info section).  But
   30414              :          if we would start using string offset tables for the main (or
   30415              :          skeleton) unit, then we have to add a DW_AT_str_offsets_base
   30416              :          pointing to the actual index after the header.  Split dwarf
   30417              :          units will never have a string offsets base attribute.  When
   30418              :          a split unit is moved into a .dwp file the string offsets can
   30419              :          be found through the .debug_cu_index section table.  */
   30420          249 :       if (dwarf_version >= 5)
   30421              :         {
   30422          248 :           unsigned int last_idx = 0;
   30423          248 :           unsigned long str_offsets_length;
   30424              : 
   30425          248 :           debug_str_hash->traverse_noresize
   30426         2762 :             <unsigned int *, count_index_strings> (&last_idx);
   30427          248 :           str_offsets_length = last_idx * dwarf_offset_size + 4;
   30428          248 :           if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   30429            0 :             dw2_asm_output_data (4, 0xffffffff,
   30430              :                                  "Escape value for 64-bit DWARF extension");
   30431          248 :           dw2_asm_output_data (dwarf_offset_size, str_offsets_length,
   30432              :                                "Length of string offsets unit");
   30433          248 :           dw2_asm_output_data (2, 5, "DWARF string offsets version");
   30434          248 :           dw2_asm_output_data (2, 0, "Header zero padding");
   30435              :         }
   30436          249 :       debug_str_hash->traverse_noresize
   30437         3176 :         <unsigned int *, output_index_string_offset> (&offset);
   30438          249 :       switch_to_section (debug_str_dwo_section);
   30439          249 :       debug_str_hash->traverse_noresize<unsigned int *, output_index_string>
   30440         3176 :         (&cur_idx);
   30441              :     }
   30442        54573 : }
   30443              : 
   30444              : /* Callback for htab_traverse to assign an index to an entry in the
   30445              :    table, and to write that entry to the .debug_addr section.  */
   30446              : 
   30447              : int
   30448          264 : output_addr_table_entry (addr_table_entry **slot, unsigned int *cur_index)
   30449              : {
   30450          264 :   addr_table_entry *entry = *slot;
   30451              : 
   30452          264 :   if (entry->refcount == 0)
   30453              :     {
   30454            0 :       gcc_assert (entry->index == NO_INDEX_ASSIGNED
   30455              :                   || entry->index == NOT_INDEXED);
   30456              :       return 1;
   30457              :     }
   30458              : 
   30459          264 :   gcc_assert (entry->index == *cur_index);
   30460          264 :   (*cur_index)++;
   30461              : 
   30462          264 :   switch (entry->kind)
   30463              :     {
   30464            3 :       case ate_kind_rtx:
   30465            3 :         dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, entry->addr.rtl,
   30466              :                                  "0x%x", entry->index);
   30467            3 :         break;
   30468            0 :       case ate_kind_rtx_dtprel:
   30469            0 :         gcc_assert (targetm.asm_out.output_dwarf_dtprel);
   30470            0 :         targetm.asm_out.output_dwarf_dtprel (asm_out_file,
   30471            0 :                                              DWARF2_ADDR_SIZE,
   30472              :                                              entry->addr.rtl);
   30473            0 :         fputc ('\n', asm_out_file);
   30474            0 :         break;
   30475          261 :       case ate_kind_label:
   30476          261 :         dw2_asm_output_addr (DWARF2_ADDR_SIZE, entry->addr.label,
   30477              :                                  "0x%x", entry->index);
   30478          261 :         break;
   30479            0 :       default:
   30480            0 :         gcc_unreachable ();
   30481              :     }
   30482              :   return 1;
   30483              : }
   30484              : 
   30485              : /* A helper function for dwarf2out_finish.  Counts the number
   30486              :    of indexed addresses.  Must match the logic of the functions
   30487              :    output_addr_table_entry above.  */
   30488              : int
   30489          264 : count_index_addrs (addr_table_entry **slot, unsigned int *last_idx)
   30490              : {
   30491          264 :   addr_table_entry *entry = *slot;
   30492              : 
   30493          264 :   if (entry->refcount > 0)
   30494          264 :     *last_idx += 1;
   30495          264 :   return 1;
   30496              : }
   30497              : 
   30498              : /* Produce the .debug_addr section.  */
   30499              : 
   30500              : static void
   30501          249 : output_addr_table (void)
   30502              : {
   30503          249 :   unsigned int index = 0;
   30504          249 :   if (addr_index_table == NULL || addr_index_table->size () == 0)
   30505            5 :     return;
   30506              : 
   30507          244 :   switch_to_section (debug_addr_section);
   30508              :   /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
   30509              :      which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
   30510              :      before DWARF5, didn't have a header for .debug_addr units.
   30511              :      DWARF5 specifies a small header when address tables are used.  */
   30512          244 :   if (dwarf_version >= 5)
   30513              :     {
   30514          244 :       unsigned int last_idx = 0;
   30515          244 :       unsigned long addrs_length;
   30516              : 
   30517          244 :       addr_index_table->traverse_noresize
   30518          508 :         <unsigned int *, count_index_addrs> (&last_idx);
   30519          244 :       addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
   30520              : 
   30521          244 :       if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   30522            0 :         dw2_asm_output_data (4, 0xffffffff,
   30523              :                              "Escape value for 64-bit DWARF extension");
   30524          244 :       dw2_asm_output_data (dwarf_offset_size, addrs_length,
   30525              :                            "Length of Address Unit");
   30526          244 :       dw2_asm_output_data (2, 5, "DWARF addr version");
   30527          244 :       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
   30528          244 :       dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
   30529              :     }
   30530          244 :   ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
   30531              : 
   30532          244 :   addr_index_table
   30533          508 :     ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
   30534              : }
   30535              : 
   30536              : #if ENABLE_ASSERT_CHECKING
   30537              : /* Verify that all marks are clear.  */
   30538              : 
   30539              : static void
   30540    594369675 : verify_marks_clear (dw_die_ref die)
   30541              : {
   30542    594369675 :   dw_die_ref c;
   30543              : 
   30544    594369675 :   gcc_assert (! die->die_mark);
   30545   1047100994 :   FOR_EACH_CHILD (die, c, verify_marks_clear (c));
   30546    594369675 : }
   30547              : #endif /* ENABLE_ASSERT_CHECKING */
   30548              : 
   30549              : /* Clear the marks for a die and its children.
   30550              :    Be cool if the mark isn't set.  */
   30551              : 
   30552              : static void
   30553     56897133 : prune_unmark_dies (dw_die_ref die)
   30554              : {
   30555     56897133 :   dw_die_ref c;
   30556              : 
   30557     56897133 :   if (die->die_mark)
   30558     56897133 :     die->die_mark = 0;
   30559    113740557 :   FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
   30560     56897133 : }
   30561              : 
   30562              : /* Given LOC that is referenced by a DIE we're marking as used, find all
   30563              :    referenced DWARF procedures it references and mark them as used.  */
   30564              : 
   30565              : static void
   30566       124692 : prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc)
   30567              : {
   30568       370908 :   for (; loc != NULL; loc = loc->dw_loc_next)
   30569       246216 :     switch (loc->dw_loc_opc)
   30570              :       {
   30571            0 :       case DW_OP_implicit_pointer:
   30572            0 :       case DW_OP_convert:
   30573            0 :       case DW_OP_reinterpret:
   30574            0 :       case DW_OP_GNU_implicit_pointer:
   30575            0 :       case DW_OP_GNU_convert:
   30576            0 :       case DW_OP_GNU_reinterpret:
   30577            0 :         if (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref)
   30578            0 :           prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
   30579              :         break;
   30580         5460 :       case DW_OP_GNU_variable_value:
   30581         5460 :         if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
   30582              :           {
   30583         2258 :             dw_die_ref ref
   30584         2258 :               = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
   30585         2258 :             if (ref == NULL)
   30586              :               break;
   30587         1487 :             loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   30588         1487 :             loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
   30589         1487 :             loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
   30590              :           }
   30591              :         /* FALLTHRU */
   30592         4691 :       case DW_OP_call2:
   30593         4691 :       case DW_OP_call4:
   30594         4691 :       case DW_OP_call_ref:
   30595         4691 :       case DW_OP_const_type:
   30596         4691 :       case DW_OP_GNU_const_type:
   30597         4691 :       case DW_OP_GNU_parameter_ref:
   30598         4691 :         gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_die_ref);
   30599         4691 :         prune_unused_types_mark (loc->dw_loc_oprnd1.v.val_die_ref.die, 1);
   30600         4691 :         break;
   30601            0 :       case DW_OP_regval_type:
   30602            0 :       case DW_OP_deref_type:
   30603            0 :       case DW_OP_GNU_regval_type:
   30604            0 :       case DW_OP_GNU_deref_type:
   30605            0 :         gcc_assert (loc->dw_loc_oprnd2.val_class == dw_val_class_die_ref);
   30606            0 :         prune_unused_types_mark (loc->dw_loc_oprnd2.v.val_die_ref.die, 1);
   30607            0 :         break;
   30608            0 :       case DW_OP_entry_value:
   30609            0 :       case DW_OP_GNU_entry_value:
   30610            0 :         gcc_assert (loc->dw_loc_oprnd1.val_class == dw_val_class_loc);
   30611            0 :         prune_unused_types_walk_loc_descr (loc->dw_loc_oprnd1.v.val_loc);
   30612            0 :         break;
   30613              :       default:
   30614              :         break;
   30615              :       }
   30616       124692 : }
   30617              : 
   30618              : /* Given DIE that we're marking as used, find any other dies
   30619              :    it references as attributes and mark them as used.  */
   30620              : 
   30621              : static void
   30622     56897133 : prune_unused_types_walk_attribs (dw_die_ref die)
   30623              : {
   30624     56897133 :   dw_attr_node *a;
   30625     56897133 :   unsigned ix;
   30626              : 
   30627    262069241 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   30628              :     {
   30629    205172108 :       switch (AT_class (a))
   30630              :         {
   30631              :         /* Make sure DWARF procedures referenced by location descriptions will
   30632              :            get emitted.  */
   30633       124692 :         case dw_val_class_loc:
   30634       124692 :           prune_unused_types_walk_loc_descr (AT_loc (a));
   30635       124692 :           break;
   30636            0 :         case dw_val_class_loc_list:
   30637            0 :           for (dw_loc_list_ref list = AT_loc_list (a);
   30638            0 :                list != NULL;
   30639            0 :                list = list->dw_loc_next)
   30640            0 :             prune_unused_types_walk_loc_descr (list->expr);
   30641              :           break;
   30642              : 
   30643              :         case dw_val_class_view_list:
   30644              :           /* This points to a loc_list in another attribute, so it's
   30645              :              already covered.  */
   30646              :           break;
   30647              : 
   30648     56376250 :         case dw_val_class_die_ref:
   30649              :           /* A reference to another DIE.
   30650              :              Make sure that it will get emitted.
   30651              :              If it was broken out into a comdat group, don't follow it.  */
   30652     56376250 :           if (! AT_ref (a)->comdat_type_p
   30653     56376250 :               || a->dw_attr == DW_AT_specification)
   30654     56375993 :             prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
   30655              :           break;
   30656              : 
   30657     34643711 :         case dw_val_class_str:
   30658              :           /* Set the string's refcount to 0 so that prune_unused_types_mark
   30659              :              accounts properly for it.  */
   30660     34643711 :           a->dw_attr_val.v.val_str->refcount = 0;
   30661     34643711 :           break;
   30662              : 
   30663              :         default:
   30664              :           break;
   30665              :         }
   30666              :     }
   30667     56897133 : }
   30668              : 
   30669              : /* Mark the generic parameters and arguments children DIEs of DIE.  */
   30670              : 
   30671              : static void
   30672     18046668 : prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
   30673              : {
   30674     18046668 :   dw_die_ref c;
   30675              : 
   30676     18046668 :   if (die == NULL || die->die_child == NULL)
   30677              :     return;
   30678              :   c = die->die_child;
   30679     20860761 :   do
   30680              :     {
   30681     20860761 :       if (is_template_parameter (c))
   30682       853433 :         prune_unused_types_mark (c, 1);
   30683     20860761 :       c = c->die_sib;
   30684     20860761 :     } while (c && c != die->die_child);
   30685              : }
   30686              : 
   30687              : /* Mark DIE as being used.  If DOKIDS is true, then walk down
   30688              :    to DIE's children.  */
   30689              : 
   30690              : static void
   30691     75576171 : prune_unused_types_mark (dw_die_ref die, int dokids)
   30692              : {
   30693     75576171 :   dw_die_ref c;
   30694              : 
   30695     75576171 :   if (die->die_mark == 0)
   30696              :     {
   30697              :       /* We haven't done this node yet.  Mark it as used.  */
   30698     18046668 :       die->die_mark = 1;
   30699              :       /* If this is the DIE of a generic type instantiation,
   30700              :          mark the children DIEs that describe its generic parms and
   30701              :          args.  */
   30702     18046668 :       prune_unused_types_mark_generic_parms_dies (die);
   30703              : 
   30704              :       /* We also have to mark its parents as used.
   30705              :          (But we don't want to mark our parent's kids due to this,
   30706              :          unless it is a class.)  */
   30707     18046668 :       if (die->die_parent)
   30708     18046668 :         prune_unused_types_mark (die->die_parent,
   30709     18046668 :                                  class_scope_p (die->die_parent));
   30710              : 
   30711              :       /* Mark any referenced nodes.  */
   30712     18046668 :       prune_unused_types_walk_attribs (die);
   30713              : 
   30714              :       /* If this node is a specification,
   30715              :          also mark the definition, if it exists.  */
   30716     18046668 :       if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
   30717       102975 :         prune_unused_types_mark (die->die_definition, 1);
   30718              :     }
   30719              : 
   30720     75576171 :   if (dokids && die->die_mark != 2)
   30721              :     {
   30722              :       /* We need to walk the children, but haven't done so yet.
   30723              :          Remember that we've walked the kids.  */
   30724     17494955 :       die->die_mark = 2;
   30725              : 
   30726              :       /* If this is an array type, we need to make sure our
   30727              :          kids get marked, even if they're types.  If we're
   30728              :          breaking out types into comdat sections, do this
   30729              :          for all type definitions.  */
   30730     17494955 :       if (die->die_tag == DW_TAG_array_type
   30731     17494955 :           || (use_debug_types
   30732         1492 :               && is_type_die (die) && ! is_declaration_die (die)))
   30733       171492 :         FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
   30734              :       else
   30735     32155749 :         FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
   30736              :     }
   30737     75576171 : }
   30738              : 
   30739              : /* For local classes, look if any static member functions were emitted
   30740              :    and if so, mark them.  */
   30741              : 
   30742              : static void
   30743       147916 : prune_unused_types_walk_local_classes (dw_die_ref die)
   30744              : {
   30745       147916 :   dw_die_ref c;
   30746              : 
   30747       147916 :   if (die->die_mark == 2)
   30748              :     return;
   30749              : 
   30750       123388 :   switch (die->die_tag)
   30751              :     {
   30752        23730 :     case DW_TAG_structure_type:
   30753        23730 :     case DW_TAG_union_type:
   30754        23730 :     case DW_TAG_class_type:
   30755        23730 :     case DW_TAG_interface_type:
   30756        23730 :       break;
   30757              : 
   30758        73589 :     case DW_TAG_subprogram:
   30759        73589 :       if (!get_AT_flag (die, DW_AT_declaration)
   30760        73589 :           || die->die_definition != NULL)
   30761        20470 :         prune_unused_types_mark (die, 1);
   30762              :       return;
   30763              : 
   30764              :     default:
   30765              :       return;
   30766              :     }
   30767              : 
   30768              :   /* Mark children.  */
   30769       124216 :   FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
   30770              : }
   30771              : 
   30772              : /* Walk the tree DIE and mark types that we actually use.  */
   30773              : 
   30774              : static void
   30775    187913060 : prune_unused_types_walk (dw_die_ref die)
   30776              : {
   30777    187913060 :   dw_die_ref c;
   30778              : 
   30779              :   /* Don't do anything if this node is already marked and
   30780              :      children have been marked as well.  */
   30781    187913060 :   if (die->die_mark == 2)
   30782              :     return;
   30783              : 
   30784    174719879 :   switch (die->die_tag)
   30785              :     {
   30786     45956970 :     case DW_TAG_structure_type:
   30787     45956970 :     case DW_TAG_union_type:
   30788     45956970 :     case DW_TAG_class_type:
   30789     45956970 :     case DW_TAG_interface_type:
   30790     45956970 :       if (die->die_perennial_p)
   30791              :         break;
   30792              : 
   30793    142861553 :       for (c = die->die_parent; c; c = c->die_parent)
   30794     96968316 :         if (c->die_tag == DW_TAG_subprogram)
   30795              :           break;
   30796              : 
   30797              :       /* Finding used static member functions inside of classes
   30798              :          is needed just for local classes, because for other classes
   30799              :          static member function DIEs with DW_AT_specification
   30800              :          are emitted outside of the DW_TAG_*_type.  If we ever change
   30801              :          it, we'd need to call this even for non-local classes.  */
   30802     45916963 :       if (c)
   30803        23726 :         prune_unused_types_walk_local_classes (die);
   30804              : 
   30805              :       /* It's a type node --- don't mark it.  */
   30806              :       return;
   30807              : 
   30808     48039355 :     case DW_TAG_const_type:
   30809     48039355 :     case DW_TAG_packed_type:
   30810     48039355 :     case DW_TAG_pointer_type:
   30811     48039355 :     case DW_TAG_reference_type:
   30812     48039355 :     case DW_TAG_rvalue_reference_type:
   30813     48039355 :     case DW_TAG_volatile_type:
   30814     48039355 :     case DW_TAG_restrict_type:
   30815     48039355 :     case DW_TAG_shared_type:
   30816     48039355 :     case DW_TAG_atomic_type:
   30817     48039355 :     case DW_TAG_immutable_type:
   30818     48039355 :     case DW_TAG_typedef:
   30819     48039355 :     case DW_TAG_array_type:
   30820     48039355 :     case DW_TAG_coarray_type:
   30821     48039355 :     case DW_TAG_friend:
   30822     48039355 :     case DW_TAG_enumeration_type:
   30823     48039355 :     case DW_TAG_subroutine_type:
   30824     48039355 :     case DW_TAG_string_type:
   30825     48039355 :     case DW_TAG_set_type:
   30826     48039355 :     case DW_TAG_subrange_type:
   30827     48039355 :     case DW_TAG_ptr_to_member_type:
   30828     48039355 :     case DW_TAG_file_type:
   30829     48039355 :     case DW_TAG_unspecified_type:
   30830     48039355 :     case DW_TAG_dynamic_type:
   30831              :       /* Type nodes are useful only when other DIEs reference them --- don't
   30832              :          mark them.  */
   30833              :       /* FALLTHROUGH */
   30834              : 
   30835     48039355 :     case DW_TAG_dwarf_procedure:
   30836              :       /* Likewise for DWARF procedures.  */
   30837              : 
   30838     48039355 :       if (die->die_perennial_p)
   30839              :         break;
   30840              : 
   30841              :       return;
   30842              : 
   30843     43783284 :     case DW_TAG_variable:
   30844     43783284 :       if (flag_debug_only_used_symbols)
   30845              :         {
   30846     43783043 :           if (die->die_perennial_p)
   30847              :             break;
   30848              : 
   30849              :           /* For static data members, the declaration in the class is supposed
   30850              :              to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
   30851              :              DWARF5.  DW_TAG_member will be marked, so mark even such
   30852              :              DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
   30853              :              attribute.  */
   30854     43510059 :           if (dwarf_version >= 5
   30855     43506945 :               && class_scope_p (die->die_parent)
   30856     43699224 :               && get_AT (die, DW_AT_const_value))
   30857              :             break;
   30858              : 
   30859              :           /* premark_used_variables marks external variables --- don't mark
   30860              :              them here.  But function-local externals are always considered
   30861              :              used.  */
   30862     43412580 :           if (get_AT (die, DW_AT_external))
   30863              :             {
   30864    103360470 :               for (c = die->die_parent; c; c = c->die_parent)
   30865     61938002 :                 if (c->die_tag == DW_TAG_subprogram)
   30866              :                   break;
   30867     41423917 :               if (!c)
   30868              :                 return;
   30869              :             }
   30870              :         }
   30871              :       /* FALLTHROUGH */
   30872              : 
   30873              :     default:
   30874              :       /* Mark everything else.  */
   30875              :       break;
   30876              :   }
   30877              : 
   30878     39431062 :   if (die->die_mark == 0)
   30879              :     {
   30880     38850465 :       die->die_mark = 1;
   30881              : 
   30882              :       /* Now, mark any dies referenced from here.  */
   30883     38850465 :       prune_unused_types_walk_attribs (die);
   30884              :     }
   30885              : 
   30886     39431062 :   die->die_mark = 2;
   30887              : 
   30888              :   /* Mark children.  */
   30889    199098841 :   FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
   30890              : }
   30891              : 
   30892              : /* Increment the string counts on strings referred to from DIE's
   30893              :    attributes.  */
   30894              : 
   30895              : static void
   30896     56897133 : prune_unused_types_update_strings (dw_die_ref die)
   30897              : {
   30898     56897133 :   dw_attr_node *a;
   30899     56897133 :   unsigned ix;
   30900              : 
   30901    262069241 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   30902    205172108 :     if (AT_class (a) == dw_val_class_str)
   30903              :       {
   30904     34643711 :         struct indirect_string_node *s = a->dw_attr_val.v.val_str;
   30905     34643711 :         s->refcount++;
   30906              :         /* Avoid unnecessarily putting strings that are used less than
   30907              :            twice in the hash table.  */
   30908     34643711 :         if (s->form != DW_FORM_line_strp
   30909     34540993 :             && (s->refcount
   30910     34540993 :                 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2)))
   30911              :           {
   30912     20968924 :             indirect_string_node **slot
   30913     20968924 :               = debug_str_hash->find_slot_with_hash (s->str,
   30914     20968924 :                                                      htab_hash_string (s->str),
   30915              :                                                      INSERT);
   30916     20968924 :             gcc_assert (*slot == NULL);
   30917     20968924 :             *slot = s;
   30918              :           }
   30919              :       }
   30920     56897133 : }
   30921              : 
   30922              : /* Mark DIE and its children as removed.  */
   30923              : 
   30924              : static void
   30925    537472542 : mark_removed (dw_die_ref die)
   30926              : {
   30927    537472542 :   dw_die_ref c;
   30928    537472542 :   die->removed = true;
   30929    943408591 :   FOR_EACH_CHILD (die, c, mark_removed (c));
   30930    537472542 : }
   30931              : 
   30932              : /* Remove from the tree DIE any dies that aren't marked.  */
   30933              : 
   30934              : static void
   30935     56897133 : prune_unused_types_prune (dw_die_ref die)
   30936              : {
   30937     56897133 :   dw_die_ref c;
   30938              : 
   30939     56897133 :   gcc_assert (die->die_mark);
   30940     56897133 :   prune_unused_types_update_strings (die);
   30941              : 
   30942     56897133 :   if (! die->die_child)
   30943              :     return;
   30944              : 
   30945              :   c = die->die_child;
   30946     57320626 :   do {
   30947     57320626 :     dw_die_ref prev = c, next;
   30948    188379917 :     for (c = c->die_sib; ! c->die_mark; c = next)
   30949    131536493 :       if (c == die->die_child)
   30950              :         {
   30951              :           /* No marked children between 'prev' and the end of the list.  */
   30952       477202 :           if (prev == c)
   30953              :             /* No marked children at all.  */
   30954              :             die->die_child = NULL;
   30955              :           else
   30956              :             {
   30957       183503 :               prev->die_sib = c->die_sib;
   30958       183503 :               die->die_child = prev;
   30959              :             }
   30960       477202 :           c->die_sib = NULL;
   30961       477202 :           mark_removed (c);
   30962       477202 :           return;
   30963              :         }
   30964              :       else
   30965              :         {
   30966    131059291 :           next = c->die_sib;
   30967    131059291 :           c->die_sib = NULL;
   30968    131059291 :           mark_removed (c);
   30969              :         }
   30970              : 
   30971     56843424 :     if (c != prev->die_sib)
   30972      2387845 :       prev->die_sib = c;
   30973     56843424 :     prune_unused_types_prune (c);
   30974     56843424 :   } while (c != die->die_child);
   30975              : }
   30976              : 
   30977              : /* Remove dies representing declarations that we never use.  */
   30978              : 
   30979              : static void
   30980        53628 : prune_unused_types (void)
   30981              : {
   30982        53628 :   unsigned int i;
   30983        53628 :   limbo_die_node *node;
   30984        53628 :   comdat_type_node *ctnode;
   30985        53628 :   pubname_entry *pub;
   30986        53628 :   dw_die_ref base_type;
   30987              : 
   30988              : #if ENABLE_ASSERT_CHECKING
   30989              :   /* All the marks should already be clear.  */
   30990        53628 :   verify_marks_clear (comp_unit_die ());
   30991        53628 :   for (node = limbo_die_list; node; node = node->next)
   30992            0 :     verify_marks_clear (node->die);
   30993        53709 :   for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
   30994           81 :     verify_marks_clear (ctnode->root_die);
   30995              : #endif /* ENABLE_ASSERT_CHECKING */
   30996              : 
   30997              :   /* Mark types that are used in global variables.  */
   30998        53628 :   premark_types_used_by_global_vars ();
   30999              : 
   31000              :   /* Mark variables used in the symtab.  */
   31001        53628 :   if (flag_debug_only_used_symbols)
   31002        53596 :     premark_used_variables ();
   31003              : 
   31004              :   /* Set the mark on nodes that are actually used.  */
   31005        53628 :   prune_unused_types_walk (comp_unit_die ());
   31006        53628 :   for (node = limbo_die_list; node; node = node->next)
   31007            0 :     prune_unused_types_walk (node->die);
   31008        53709 :   for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
   31009              :     {
   31010           81 :       prune_unused_types_walk (ctnode->root_die);
   31011           81 :       prune_unused_types_mark (ctnode->type_die, 1);
   31012              :     }
   31013              : 
   31014              :   /* Also set the mark on nodes referenced from the pubname_table.  Enumerators
   31015              :      are unusual in that they are pubnames that are the children of pubtypes.
   31016              :      They should only be marked via their parent DW_TAG_enumeration_type die,
   31017              :      not as roots in themselves.  */
   31018        54326 :   FOR_EACH_VEC_ELT (*pubname_table, i, pub)
   31019          698 :     if (pub->die->die_tag != DW_TAG_enumerator)
   31020          644 :       prune_unused_types_mark (pub->die, 1);
   31021        53628 :   for (i = 0; base_types.iterate (i, &base_type); i++)
   31022            0 :     prune_unused_types_mark (base_type, 1);
   31023              : 
   31024              :   /* Also set the mark on nodes that could be referenced by
   31025              :      DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
   31026              :      by DW_TAG_inlined_subroutine origins.  */
   31027        53628 :   cgraph_node *cnode;
   31028      2973502 :   FOR_EACH_FUNCTION (cnode)
   31029      2919874 :     if (cnode->referred_to_p (false))
   31030              :       {
   31031      2728413 :         dw_die_ref die = lookup_decl_die (cnode->decl);
   31032      2728413 :         if (die == NULL || die->die_mark)
   31033      2728236 :           continue;
   31034          177 :         for (cgraph_edge *e = cnode->callers; e; e = e->next_caller)
   31035          155 :           if (e->caller != cnode)
   31036              :             {
   31037          155 :               prune_unused_types_mark (die, 1);
   31038          155 :               break;
   31039              :             }
   31040              :       }
   31041              : 
   31042        53628 :   if (debug_str_hash)
   31043        53628 :     debug_str_hash->empty ();
   31044        53628 :   if (skeleton_debug_str_hash)
   31045            0 :     skeleton_debug_str_hash->empty ();
   31046        53628 :   prune_unused_types_prune (comp_unit_die ());
   31047       107256 :   for (limbo_die_node **pnode = &limbo_die_list; *pnode; )
   31048              :     {
   31049            0 :       node = *pnode;
   31050            0 :       if (!node->die->die_mark)
   31051            0 :         *pnode = node->next;
   31052              :       else
   31053              :         {
   31054            0 :           prune_unused_types_prune (node->die);
   31055            0 :           pnode = &node->next;
   31056              :         }
   31057              :     }
   31058        53709 :   for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
   31059           81 :     prune_unused_types_prune (ctnode->root_die);
   31060              : 
   31061              :   /* Leave the marks clear.  */
   31062        53628 :   prune_unmark_dies (comp_unit_die ());
   31063        53628 :   for (node = limbo_die_list; node; node = node->next)
   31064            0 :     prune_unmark_dies (node->die);
   31065        53709 :   for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
   31066           81 :     prune_unmark_dies (ctnode->root_die);
   31067        53628 : }
   31068              : 
   31069              : /* Helpers to manipulate hash table of comdat type units.  */
   31070              : 
   31071              : struct comdat_type_hasher : nofree_ptr_hash <comdat_type_node>
   31072              : {
   31073              :   static inline hashval_t hash (const comdat_type_node *);
   31074              :   static inline bool equal (const comdat_type_node *, const comdat_type_node *);
   31075              : };
   31076              : 
   31077              : inline hashval_t
   31078           86 : comdat_type_hasher::hash (const comdat_type_node *type_node)
   31079              : {
   31080           86 :   hashval_t h;
   31081           86 :   memcpy (&h, type_node->signature, sizeof (h));
   31082           86 :   return h;
   31083              : }
   31084              : 
   31085              : inline bool
   31086            5 : comdat_type_hasher::equal (const comdat_type_node *type_node_1,
   31087              :                            const comdat_type_node *type_node_2)
   31088              : {
   31089            5 :   return (! memcmp (type_node_1->signature, type_node_2->signature,
   31090              :                     DWARF_TYPE_SIGNATURE_SIZE));
   31091              : }
   31092              : 
   31093              : /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
   31094              :    to the location it would have been added, should we know its
   31095              :    DECL_ASSEMBLER_NAME when we added other attributes.  This will
   31096              :    probably improve compactness of debug info, removing equivalent
   31097              :    abbrevs, and hide any differences caused by deferring the
   31098              :    computation of the assembler name, triggered by e.g. PCH.  */
   31099              : 
   31100              : static inline void
   31101    117048907 : move_linkage_attr (dw_die_ref die)
   31102              : {
   31103    117048907 :   unsigned ix = vec_safe_length (die->die_attr);
   31104    117048907 :   dw_attr_node linkage = (*die->die_attr)[ix - 1];
   31105              : 
   31106    117048907 :   gcc_assert (linkage.dw_attr == DW_AT_linkage_name
   31107              :               || linkage.dw_attr == DW_AT_MIPS_linkage_name);
   31108              : 
   31109    567610072 :   while (--ix > 0)
   31110              :     {
   31111    567610024 :       dw_attr_node *prev = &(*die->die_attr)[ix - 1];
   31112              : 
   31113    567610024 :       if (prev->dw_attr == DW_AT_decl_line
   31114              :           || prev->dw_attr == DW_AT_decl_column
   31115              :           || prev->dw_attr == DW_AT_name)
   31116              :         break;
   31117              :     }
   31118              : 
   31119    117048907 :   if (ix != vec_safe_length (die->die_attr) - 1)
   31120              :     {
   31121    116734182 :       die->die_attr->pop ();
   31122    116734182 :       die->die_attr->quick_insert (ix, linkage);
   31123              :     }
   31124    117048907 : }
   31125              : 
   31126              : /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
   31127              :    referenced from typed stack ops and count how often they are used.  */
   31128              : 
   31129              : static void
   31130     35692970 : mark_base_types (dw_loc_descr_ref loc)
   31131              : {
   31132     35692970 :   dw_die_ref base_type = NULL;
   31133              : 
   31134    102102456 :   for (; loc; loc = loc->dw_loc_next)
   31135              :     {
   31136     66409486 :       switch (loc->dw_loc_opc)
   31137              :         {
   31138       180551 :         case DW_OP_regval_type:
   31139       180551 :         case DW_OP_deref_type:
   31140       180551 :         case DW_OP_GNU_regval_type:
   31141       180551 :         case DW_OP_GNU_deref_type:
   31142       180551 :           base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
   31143       180551 :           break;
   31144       317834 :         case DW_OP_convert:
   31145       317834 :         case DW_OP_reinterpret:
   31146       317834 :         case DW_OP_GNU_convert:
   31147       317834 :         case DW_OP_GNU_reinterpret:
   31148       317834 :           if (loc->dw_loc_oprnd1.val_class == dw_val_class_unsigned_const)
   31149        27516 :             continue;
   31150              :           /* FALLTHRU */
   31151       363602 :         case DW_OP_const_type:
   31152       363602 :         case DW_OP_GNU_const_type:
   31153       363602 :           base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
   31154       363602 :           break;
   31155      1351416 :         case DW_OP_entry_value:
   31156      1351416 :         case DW_OP_GNU_entry_value:
   31157      1351416 :           mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
   31158      1351416 :           continue;
   31159     64486401 :         default:
   31160     64486401 :           continue;
   31161              :         }
   31162       544153 :       gcc_assert (base_type->die_parent == comp_unit_die ());
   31163       544153 :       if (base_type->die_mark)
   31164       537365 :         base_type->die_mark++;
   31165              :       else
   31166              :         {
   31167         6788 :           base_types.safe_push (base_type);
   31168         6788 :           base_type->die_mark = 1;
   31169              :         }
   31170              :     }
   31171     35692970 : }
   31172              : 
   31173              : /* Stripped-down variant of resolve_addr, mark DW_TAG_base_type nodes
   31174              :    referenced from typed stack ops and count how often they are used.  */
   31175              : 
   31176              : static void
   31177       236131 : mark_base_types (dw_die_ref die)
   31178              : {
   31179       236131 :   dw_die_ref c;
   31180       236131 :   dw_attr_node *a;
   31181       236131 :   dw_loc_list_ref *curr;
   31182       236131 :   unsigned ix;
   31183              : 
   31184      1103850 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   31185       867719 :     switch (AT_class (a))
   31186              :       {
   31187            0 :       case dw_val_class_loc_list:
   31188            0 :         curr = AT_loc_list_ptr (a);
   31189            0 :         while (*curr)
   31190              :           {
   31191            0 :             mark_base_types ((*curr)->expr);
   31192            0 :             curr = &(*curr)->dw_loc_next;
   31193              :           }
   31194              :         break;
   31195              : 
   31196          240 :       case dw_val_class_loc:
   31197          240 :         mark_base_types (AT_loc (a));
   31198          240 :         break;
   31199              : 
   31200              :       default:
   31201              :         break;
   31202              :       }
   31203              : 
   31204       470918 :   FOR_EACH_CHILD (die, c, mark_base_types (c));
   31205       236131 : }
   31206              : 
   31207              : /* Comparison function for sorting marked base types.  */
   31208              : 
   31209              : static int
   31210        19405 : base_type_cmp (const void *x, const void *y)
   31211              : {
   31212        19405 :   dw_die_ref dx = *(const dw_die_ref *) x;
   31213        19405 :   dw_die_ref dy = *(const dw_die_ref *) y;
   31214        19405 :   unsigned int byte_size1, byte_size2;
   31215        19405 :   unsigned int encoding1, encoding2;
   31216        19405 :   unsigned int align1, align2;
   31217        19405 :   if (dx->die_mark > dy->die_mark)
   31218              :     return -1;
   31219        11043 :   if (dx->die_mark < dy->die_mark)
   31220              :     return 1;
   31221         3859 :   byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
   31222         3859 :   byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
   31223         3859 :   if (byte_size1 < byte_size2)
   31224              :     return 1;
   31225         2550 :   if (byte_size1 > byte_size2)
   31226              :     return -1;
   31227          841 :   encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
   31228          841 :   encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
   31229          841 :   if (encoding1 < encoding2)
   31230              :     return 1;
   31231          671 :   if (encoding1 > encoding2)
   31232              :     return -1;
   31233          381 :   align1 = get_AT_unsigned (dx, DW_AT_alignment);
   31234          381 :   align2 = get_AT_unsigned (dy, DW_AT_alignment);
   31235          381 :   if (align1 < align2)
   31236              :     return 1;
   31237          381 :   if (align1 > align2)
   31238            0 :     return -1;
   31239              :   return 0;
   31240              : }
   31241              : 
   31242              : /* Move base types marked by mark_base_types as early as possible
   31243              :    in the CU, sorted by decreasing usage count both to make the
   31244              :    uleb128 references as small as possible and to make sure they
   31245              :    will have die_offset already computed by calc_die_sizes when
   31246              :    sizes of typed stack loc ops is computed.  */
   31247              : 
   31248              : static void
   31249        54573 : move_marked_base_types (void)
   31250              : {
   31251        54573 :   unsigned int i;
   31252        54573 :   dw_die_ref base_type, die, c;
   31253              : 
   31254        54573 :   if (base_types.is_empty ())
   31255        54573 :     return;
   31256              : 
   31257              :   /* Sort by decreasing usage count, they will be added again in that
   31258              :      order later on.  */
   31259         3740 :   base_types.qsort (base_type_cmp);
   31260         3740 :   die = comp_unit_die ();
   31261         3740 :   c = die->die_child;
   31262      1467870 :   do
   31263              :     {
   31264      1467870 :       dw_die_ref prev = c;
   31265      1467870 :       c = c->die_sib;
   31266      1474658 :       while (c->die_mark)
   31267              :         {
   31268         6788 :           remove_child_with_prev (c, prev);
   31269              :           /* As base types got marked, there must be at least
   31270              :              one node other than DW_TAG_base_type.  */
   31271         6788 :           gcc_assert (die->die_child != NULL);
   31272         6788 :           c = prev->die_sib;
   31273              :         }
   31274              :     }
   31275      1467870 :   while (c != die->die_child);
   31276         3740 :   gcc_assert (die->die_child);
   31277              :   c = die->die_child;
   31278        10528 :   for (i = 0; base_types.iterate (i, &base_type); i++)
   31279              :     {
   31280         6788 :       base_type->die_mark = 0;
   31281         6788 :       base_type->die_sib = c->die_sib;
   31282         6788 :       c->die_sib = base_type;
   31283         6788 :       c = base_type;
   31284              :     }
   31285              : }
   31286              : 
   31287              : /* Helper function for resolve_addr, attempt to resolve
   31288              :    one CONST_STRING, return true if successful.  Similarly verify that
   31289              :    SYMBOL_REFs refer to variables emitted in the current CU.  */
   31290              : 
   31291              : static bool
   31292      2034591 : resolve_one_addr (rtx *addr)
   31293              : {
   31294      2034591 :   rtx rtl = *addr;
   31295              : 
   31296      2034591 :   if (GET_CODE (rtl) == CONST_STRING)
   31297              :     {
   31298       224946 :       size_t len = strlen (XSTR (rtl, 0)) + 1;
   31299       224946 :       tree t = build_string (len, XSTR (rtl, 0));
   31300       224946 :       tree tlen = size_int (len - 1);
   31301       224946 :       TREE_TYPE (t)
   31302       224946 :         = build_array_type (char_type_node, build_index_type (tlen));
   31303       224946 :       rtl = lookup_constant_def (t);
   31304       224946 :       if (!rtl || !MEM_P (rtl))
   31305              :         return false;
   31306       103532 :       rtl = XEXP (rtl, 0);
   31307       103532 :       if (GET_CODE (rtl) == SYMBOL_REF
   31308       103532 :           && SYMBOL_REF_DECL (rtl)
   31309       207064 :           && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
   31310              :         return false;
   31311         4456 :       vec_safe_push (used_rtx_array, rtl);
   31312         4456 :       *addr = rtl;
   31313         4456 :       return true;
   31314              :     }
   31315              : 
   31316      1809645 :   if (GET_CODE (rtl) == SYMBOL_REF
   31317      1809645 :       && SYMBOL_REF_DECL (rtl))
   31318              :     {
   31319      1531945 :       if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
   31320              :         {
   31321       622785 :           if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
   31322              :             return false;
   31323              :         }
   31324       909160 :       else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
   31325              :         return false;
   31326              :     }
   31327              : 
   31328      1757771 :   if (GET_CODE (rtl) == CONST)
   31329              :     {
   31330        91887 :       subrtx_ptr_iterator::array_type array;
   31331       362117 :       FOR_EACH_SUBRTX_PTR (iter, array, &XEXP (rtl, 0), ALL)
   31332       272884 :         if (!resolve_one_addr (*iter))
   31333         2654 :           return false;
   31334        91887 :     }
   31335              : 
   31336              :   return true;
   31337              : }
   31338              : 
   31339              : /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
   31340              :    if possible, and create DW_TAG_dwarf_procedure that can be referenced
   31341              :    from DW_OP_implicit_pointer if the string hasn't been seen yet.  */
   31342              : 
   31343              : static rtx
   31344        80049 : string_cst_pool_decl (tree t)
   31345              : {
   31346        80049 :   rtx rtl = output_constant_def (t, 1);
   31347        80049 :   unsigned char *array;
   31348        80049 :   dw_loc_descr_ref l;
   31349        80049 :   tree decl;
   31350        80049 :   size_t len;
   31351        80049 :   dw_die_ref ref;
   31352              : 
   31353        80049 :   if (!rtl || !MEM_P (rtl))
   31354              :     return NULL_RTX;
   31355        80049 :   rtl = XEXP (rtl, 0);
   31356        80049 :   if (GET_CODE (rtl) != SYMBOL_REF
   31357        80049 :       || SYMBOL_REF_DECL (rtl) == NULL_TREE)
   31358              :     return NULL_RTX;
   31359              : 
   31360        80049 :   decl = SYMBOL_REF_DECL (rtl);
   31361        80049 :   if (!lookup_decl_die (decl))
   31362              :     {
   31363         8837 :       len = TREE_STRING_LENGTH (t);
   31364         8837 :       vec_safe_push (used_rtx_array, rtl);
   31365         8837 :       ref = new_die (DW_TAG_dwarf_procedure, comp_unit_die (), decl);
   31366         8837 :       array = ggc_vec_alloc<unsigned char> (len);
   31367         8837 :       memcpy (array, TREE_STRING_POINTER (t), len);
   31368         8837 :       l = new_loc_descr (DW_OP_implicit_value, len, 0);
   31369         8837 :       l->dw_loc_oprnd2.val_class = dw_val_class_vec;
   31370         8837 :       l->dw_loc_oprnd2.v.val_vec.length = len;
   31371         8837 :       l->dw_loc_oprnd2.v.val_vec.elt_size = 1;
   31372         8837 :       l->dw_loc_oprnd2.v.val_vec.array = array;
   31373         8837 :       add_AT_loc (ref, DW_AT_location, l);
   31374         8837 :       equate_decl_number_to_die (decl, ref);
   31375              :     }
   31376              :   return rtl;
   31377              : }
   31378              : 
   31379              : /* Helper function of resolve_addr_in_expr.  LOC is
   31380              :    a DW_OP_addr followed by DW_OP_stack_value, either at the start
   31381              :    of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
   31382              :    resolved.  Replace it (both DW_OP_addr and DW_OP_stack_value)
   31383              :    with DW_OP_implicit_pointer if possible
   31384              :    and return true, if unsuccessful, return false.  */
   31385              : 
   31386              : static bool
   31387       105700 : optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc)
   31388              : {
   31389       105700 :   rtx rtl = loc->dw_loc_oprnd1.v.val_addr;
   31390       105700 :   HOST_WIDE_INT offset = 0;
   31391       105700 :   dw_die_ref ref = NULL;
   31392       105700 :   tree decl;
   31393              : 
   31394       105700 :   if (GET_CODE (rtl) == CONST
   31395         2601 :       && GET_CODE (XEXP (rtl, 0)) == PLUS
   31396         2601 :       && CONST_INT_P (XEXP (XEXP (rtl, 0), 1)))
   31397              :     {
   31398         2601 :       offset = INTVAL (XEXP (XEXP (rtl, 0), 1));
   31399         2601 :       rtl = XEXP (XEXP (rtl, 0), 0);
   31400              :     }
   31401       105700 :   if (GET_CODE (rtl) == CONST_STRING)
   31402              :     {
   31403        80045 :       size_t len = strlen (XSTR (rtl, 0)) + 1;
   31404        80045 :       tree t = build_string (len, XSTR (rtl, 0));
   31405        80045 :       tree tlen = size_int (len - 1);
   31406              : 
   31407        80045 :       TREE_TYPE (t)
   31408        80045 :         = build_array_type (char_type_node, build_index_type (tlen));
   31409        80045 :       rtl = string_cst_pool_decl (t);
   31410        80045 :       if (!rtl)
   31411              :         return false;
   31412              :     }
   31413       105700 :   if (GET_CODE (rtl) == SYMBOL_REF && SYMBOL_REF_DECL (rtl))
   31414              :     {
   31415       105700 :       decl = SYMBOL_REF_DECL (rtl);
   31416       105700 :       if (VAR_P (decl) && !DECL_EXTERNAL (decl))
   31417              :         {
   31418       105265 :           ref = lookup_decl_die (decl);
   31419       105265 :           if (ref && (get_AT (ref, DW_AT_location)
   31420        14840 :                       || get_AT (ref, DW_AT_const_value)))
   31421              :             {
   31422        94390 :               loc->dw_loc_opc = dwarf_OP (DW_OP_implicit_pointer);
   31423        94390 :               loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   31424        94390 :               loc->dw_loc_oprnd1.val_entry = NULL;
   31425        94390 :               loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
   31426        94390 :               loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
   31427        94390 :               loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
   31428        94390 :               loc->dw_loc_oprnd2.v.val_int = offset;
   31429        94390 :               return true;
   31430              :             }
   31431              :         }
   31432              :     }
   31433              :   return false;
   31434              : }
   31435              : 
   31436              : /* Helper function for resolve_addr, handle one location
   31437              :    expression, return false if at least one CONST_STRING or SYMBOL_REF in
   31438              :    the location list couldn't be resolved.  */
   31439              : 
   31440              : static bool
   31441     35256569 : resolve_addr_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
   31442              : {
   31443     35256569 :   dw_loc_descr_ref keep = NULL;
   31444    100323615 :   for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = loc->dw_loc_next)
   31445     65987975 :     switch (loc->dw_loc_opc)
   31446              :       {
   31447      1644165 :       case DW_OP_addr:
   31448      1644165 :         if (!resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
   31449              :           {
   31450       155512 :             if ((prev == NULL
   31451          677 :                  || prev->dw_loc_opc == DW_OP_piece
   31452           26 :                  || prev->dw_loc_opc == DW_OP_bit_piece)
   31453       155486 :                 && loc->dw_loc_next
   31454       145234 :                 && loc->dw_loc_next->dw_loc_opc == DW_OP_stack_value
   31455       105700 :                 && (!dwarf_strict || dwarf_version >= 5)
   31456       261212 :                 && optimize_one_addr_into_implicit_ptr (loc))
   31457              :               break;
   31458              :             return false;
   31459              :           }
   31460              :         break;
   31461            3 :       case DW_OP_GNU_addr_index:
   31462            3 :       case DW_OP_addrx:
   31463            3 :       case DW_OP_GNU_const_index:
   31464            3 :       case DW_OP_constx:
   31465            3 :         if ((loc->dw_loc_opc == DW_OP_GNU_addr_index
   31466            3 :              || loc->dw_loc_opc == DW_OP_addrx)
   31467              :             || ((loc->dw_loc_opc == DW_OP_GNU_const_index
   31468              :                  || loc->dw_loc_opc == DW_OP_constx)
   31469            0 :                 && loc->dw_loc_dtprel))
   31470              :           {
   31471            3 :             rtx rtl = loc->dw_loc_oprnd1.val_entry->addr.rtl;
   31472            3 :             if (!resolve_one_addr (&rtl))
   31473            0 :               return false;
   31474            3 :             remove_addr_table_entry (loc->dw_loc_oprnd1.val_entry);
   31475            3 :             loc->dw_loc_oprnd1.val_entry
   31476            3 :               = add_addr_table_entry (rtl, loc->dw_loc_dtprel
   31477              :                                       ? ate_kind_rtx_dtprel : ate_kind_rtx);
   31478              :           }
   31479              :         break;
   31480       464979 :       case DW_OP_const4u:
   31481       464979 :       case DW_OP_const8u:
   31482       464979 :         if (loc->dw_loc_dtprel
   31483       464979 :             && !resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr))
   31484              :           return false;
   31485              :         break;
   31486       880816 :       case DW_OP_plus_uconst:
   31487       880816 :         if (size_of_loc_descr (loc)
   31488       880816 :             > size_of_int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned)
   31489       880816 :               + 1
   31490       880816 :             && loc->dw_loc_oprnd1.v.val_unsigned > 0)
   31491              :           {
   31492        14406 :             dw_loc_descr_ref repl
   31493        14406 :               = int_loc_descriptor (loc->dw_loc_oprnd1.v.val_unsigned);
   31494        14406 :             add_loc_descr (&repl, new_loc_descr (DW_OP_plus, 0, 0));
   31495        14406 :             add_loc_descr (&repl, loc->dw_loc_next);
   31496        14406 :             *loc = *repl;
   31497              :           }
   31498              :         break;
   31499       133397 :       case DW_OP_implicit_value:
   31500       133397 :         if (loc->dw_loc_oprnd2.val_class == dw_val_class_addr
   31501       133397 :             && !resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr))
   31502              :           return false;
   31503              :         break;
   31504      2093366 :       case DW_OP_implicit_pointer:
   31505      2093366 :       case DW_OP_GNU_implicit_pointer:
   31506      2093366 :       case DW_OP_GNU_parameter_ref:
   31507      2093366 :       case DW_OP_GNU_variable_value:
   31508      2093366 :         if (loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
   31509              :           {
   31510       852054 :             dw_die_ref ref
   31511       852054 :               = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
   31512       852054 :             if (ref == NULL)
   31513              :               return false;
   31514          312 :             loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   31515          312 :             loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
   31516          312 :             loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
   31517              :           }
   31518      1241624 :         if (loc->dw_loc_opc == DW_OP_GNU_variable_value)
   31519              :           {
   31520         4951 :             if (prev == NULL
   31521         4951 :                 && loc->dw_loc_next == NULL
   31522         8673 :                 && AT_class (a) == dw_val_class_loc)
   31523         3722 :               switch (a->dw_attr)
   31524              :                 {
   31525              :                   /* Following attributes allow both exprloc and reference,
   31526              :                      so if the whole expression is DW_OP_GNU_variable_value
   31527              :                      alone we could transform it into reference.  */
   31528         3688 :                 case DW_AT_byte_size:
   31529         3688 :                 case DW_AT_bit_size:
   31530         3688 :                 case DW_AT_lower_bound:
   31531         3688 :                 case DW_AT_upper_bound:
   31532         3688 :                 case DW_AT_bit_stride:
   31533         3688 :                 case DW_AT_count:
   31534         3688 :                 case DW_AT_allocated:
   31535         3688 :                 case DW_AT_associated:
   31536         3688 :                 case DW_AT_byte_stride:
   31537         3688 :                   a->dw_attr_val.val_class = dw_val_class_die_ref;
   31538         3688 :                   a->dw_attr_val.val_entry = NULL;
   31539         3688 :                   a->dw_attr_val.v.val_die_ref.die
   31540         3688 :                     = loc->dw_loc_oprnd1.v.val_die_ref.die;
   31541         3688 :                   a->dw_attr_val.v.val_die_ref.external = 0;
   31542         3688 :                   return true;
   31543              :                 default:
   31544              :                   break;
   31545              :                 }
   31546         1263 :             if (dwarf_strict)
   31547              :               return false;
   31548              :           }
   31549              :         break;
   31550              :       case DW_OP_const_type:
   31551              :       case DW_OP_regval_type:
   31552              :       case DW_OP_deref_type:
   31553              :       case DW_OP_convert:
   31554              :       case DW_OP_reinterpret:
   31555              :       case DW_OP_GNU_const_type:
   31556              :       case DW_OP_GNU_regval_type:
   31557              :       case DW_OP_GNU_deref_type:
   31558              :       case DW_OP_GNU_convert:
   31559              :       case DW_OP_GNU_reinterpret:
   31560       533622 :         while (loc->dw_loc_next
   31561       533622 :                && (loc->dw_loc_next->dw_loc_opc == DW_OP_convert
   31562       402677 :                    || loc->dw_loc_next->dw_loc_opc == DW_OP_GNU_convert))
   31563              :           {
   31564       113563 :             dw_die_ref base1, base2;
   31565       113563 :             unsigned enc1, enc2, size1, size2;
   31566       113563 :             if (loc->dw_loc_opc == DW_OP_regval_type
   31567       113563 :                 || loc->dw_loc_opc == DW_OP_deref_type
   31568       106913 :                 || loc->dw_loc_opc == DW_OP_GNU_regval_type
   31569       106913 :                 || loc->dw_loc_opc == DW_OP_GNU_deref_type)
   31570         6650 :               base1 = loc->dw_loc_oprnd2.v.val_die_ref.die;
   31571       106913 :             else if (loc->dw_loc_oprnd1.val_class
   31572              :                      == dw_val_class_unsigned_const)
   31573              :               break;
   31574              :             else
   31575       106061 :               base1 = loc->dw_loc_oprnd1.v.val_die_ref.die;
   31576       112711 :             if (loc->dw_loc_next->dw_loc_oprnd1.val_class
   31577              :                 == dw_val_class_unsigned_const)
   31578              :               break;
   31579        89130 :             base2 = loc->dw_loc_next->dw_loc_oprnd1.v.val_die_ref.die;
   31580        89130 :             gcc_assert (base1->die_tag == DW_TAG_base_type
   31581              :                         && base2->die_tag == DW_TAG_base_type);
   31582        89130 :             enc1 = get_AT_unsigned (base1, DW_AT_encoding);
   31583        89130 :             enc2 = get_AT_unsigned (base2, DW_AT_encoding);
   31584        89130 :             size1 = get_AT_unsigned (base1, DW_AT_byte_size);
   31585        89130 :             size2 = get_AT_unsigned (base2, DW_AT_byte_size);
   31586        89130 :             if (size1 == size2
   31587         4919 :                 && (((enc1 == DW_ATE_unsigned || enc1 == DW_ATE_signed)
   31588         4791 :                      && (enc2 == DW_ATE_unsigned || enc2 == DW_ATE_signed)
   31589         1921 :                      && loc != keep)
   31590         3020 :                     || enc1 == enc2))
   31591              :               {
   31592              :                 /* Optimize away next DW_OP_convert after
   31593              :                    adjusting LOC's base type die reference.  */
   31594         1899 :                 if (loc->dw_loc_opc == DW_OP_regval_type
   31595         1899 :                     || loc->dw_loc_opc == DW_OP_deref_type
   31596         1197 :                     || loc->dw_loc_opc == DW_OP_GNU_regval_type
   31597         1197 :                     || loc->dw_loc_opc == DW_OP_GNU_deref_type)
   31598          702 :                   loc->dw_loc_oprnd2.v.val_die_ref.die = base2;
   31599              :                 else
   31600         1197 :                   loc->dw_loc_oprnd1.v.val_die_ref.die = base2;
   31601         1899 :                 loc->dw_loc_next = loc->dw_loc_next->dw_loc_next;
   31602         1899 :                 continue;
   31603              :               }
   31604              :             /* Don't change integer DW_OP_convert after e.g. floating
   31605              :                point typed stack entry.  */
   31606        87231 :             else if (enc1 != DW_ATE_unsigned && enc1 != DW_ATE_signed)
   31607        59169 :               keep = loc->dw_loc_next;
   31608              :             break;
   31609              :           }
   31610              :         break;
   31611              :       default:
   31612              :         break;
   31613              :       }
   31614              :   return true;
   31615              : }
   31616              : 
   31617              : /* Helper function of resolve_addr.  DIE had DW_AT_location of
   31618              :    DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
   31619              :    and DW_OP_addr couldn't be resolved.  resolve_addr has already
   31620              :    removed the DW_AT_location attribute.  This function attempts to
   31621              :    add a new DW_AT_location attribute with DW_OP_implicit_pointer
   31622              :    to it or DW_AT_const_value attribute, if possible.  */
   31623              : 
   31624              : static void
   31625         2732 : optimize_location_into_implicit_ptr (dw_die_ref die, tree decl)
   31626              : {
   31627         2732 :   if (!VAR_P (decl)
   31628         2732 :       || lookup_decl_die (decl) != die
   31629          714 :       || DECL_EXTERNAL (decl)
   31630          714 :       || !TREE_STATIC (decl)
   31631          714 :       || DECL_INITIAL (decl) == NULL_TREE
   31632          541 :       || DECL_P (DECL_INITIAL (decl))
   31633         3273 :       || get_AT (die, DW_AT_const_value))
   31634              :     return;
   31635              : 
   31636          541 :   tree init = DECL_INITIAL (decl);
   31637          541 :   HOST_WIDE_INT offset = 0;
   31638              :   /* For variables that have been optimized away and thus
   31639              :      don't have a memory location, see if we can emit
   31640              :      DW_AT_const_value instead.  */
   31641          541 :   if (tree_add_const_value_attribute (die, init))
   31642              :     return;
   31643          160 :   if (dwarf_strict && dwarf_version < 5)
   31644              :     return;
   31645              :   /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
   31646              :      and ADDR_EXPR refers to a decl that has DW_AT_location or
   31647              :      DW_AT_const_value (but isn't addressable, otherwise
   31648              :      resolving the original DW_OP_addr wouldn't fail), see if
   31649              :      we can add DW_OP_implicit_pointer.  */
   31650          160 :   STRIP_NOPS (init);
   31651          160 :   if (TREE_CODE (init) == POINTER_PLUS_EXPR
   31652          160 :       && tree_fits_shwi_p (TREE_OPERAND (init, 1)))
   31653              :     {
   31654            0 :       offset = tree_to_shwi (TREE_OPERAND (init, 1));
   31655            0 :       init = TREE_OPERAND (init, 0);
   31656            0 :       STRIP_NOPS (init);
   31657              :     }
   31658          160 :   if (TREE_CODE (init) != ADDR_EXPR)
   31659              :     return;
   31660            5 :   if ((TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST
   31661            4 :        && !TREE_ASM_WRITTEN (TREE_OPERAND (init, 0)))
   31662            5 :       || (VAR_P (TREE_OPERAND (init, 0))
   31663            0 :           && !DECL_EXTERNAL (TREE_OPERAND (init, 0))
   31664            0 :           && TREE_OPERAND (init, 0) != decl))
   31665              :     {
   31666            4 :       dw_die_ref ref;
   31667            4 :       dw_loc_descr_ref l;
   31668              : 
   31669            4 :       if (TREE_CODE (TREE_OPERAND (init, 0)) == STRING_CST)
   31670              :         {
   31671            4 :           rtx rtl = string_cst_pool_decl (TREE_OPERAND (init, 0));
   31672            4 :           if (!rtl)
   31673              :             return;
   31674            4 :           decl = SYMBOL_REF_DECL (rtl);
   31675              :         }
   31676              :       else
   31677            0 :         decl = TREE_OPERAND (init, 0);
   31678            4 :       ref = lookup_decl_die (decl);
   31679            4 :       if (ref == NULL
   31680            4 :           || (!get_AT (ref, DW_AT_location)
   31681            0 :               && !get_AT (ref, DW_AT_const_value)))
   31682              :         return;
   31683            4 :       l = new_loc_descr (dwarf_OP (DW_OP_implicit_pointer), 0, offset);
   31684            4 :       l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   31685            4 :       l->dw_loc_oprnd1.v.val_die_ref.die = ref;
   31686            4 :       l->dw_loc_oprnd1.v.val_die_ref.external = 0;
   31687            4 :       add_AT_loc (die, DW_AT_location, l);
   31688              :     }
   31689              : }
   31690              : 
   31691              : /* Return NULL if l is a DWARF expression, or first op that is not
   31692              :    valid DWARF expression.  */
   31693              : 
   31694              : static dw_loc_descr_ref
   31695          139 : non_dwarf_expression (dw_loc_descr_ref l)
   31696              : {
   31697          182 :   while (l)
   31698              :     {
   31699          181 :       if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
   31700              :         return l;
   31701           85 :       switch (l->dw_loc_opc)
   31702              :         {
   31703              :         case DW_OP_regx:
   31704              :         case DW_OP_implicit_value:
   31705              :         case DW_OP_stack_value:
   31706              :         case DW_OP_implicit_pointer:
   31707              :         case DW_OP_GNU_implicit_pointer:
   31708              :         case DW_OP_GNU_parameter_ref:
   31709              :         case DW_OP_piece:
   31710              :         case DW_OP_bit_piece:
   31711              :           return l;
   31712           43 :         default:
   31713           43 :           break;
   31714              :         }
   31715           43 :       l = l->dw_loc_next;
   31716              :     }
   31717              :   return NULL;
   31718              : }
   31719              : 
   31720              : /* Return adjusted copy of EXPR:
   31721              :    If it is empty DWARF expression, return it.
   31722              :    If it is valid non-empty DWARF expression,
   31723              :    return copy of EXPR with DW_OP_deref appended to it.
   31724              :    If it is DWARF expression followed by DW_OP_reg{N,x}, return
   31725              :    copy of the DWARF expression with DW_OP_breg{N,x} <0> appended.
   31726              :    If it is DWARF expression followed by DW_OP_stack_value, return
   31727              :    copy of the DWARF expression without anything appended.
   31728              :    Otherwise, return NULL.  */
   31729              : 
   31730              : static dw_loc_descr_ref
   31731           69 : copy_deref_exprloc (dw_loc_descr_ref expr)
   31732              : {
   31733           69 :   dw_loc_descr_ref tail = NULL;
   31734              : 
   31735           69 :   if (expr == NULL)
   31736              :     return NULL;
   31737              : 
   31738           69 :   dw_loc_descr_ref l = non_dwarf_expression (expr);
   31739           69 :   if (l && l->dw_loc_next)
   31740              :     return NULL;
   31741              : 
   31742           69 :   if (l)
   31743              :     {
   31744           69 :       if (l->dw_loc_opc >= DW_OP_reg0 && l->dw_loc_opc <= DW_OP_reg31)
   31745           48 :         tail = new_loc_descr ((enum dwarf_location_atom)
   31746              :                               (DW_OP_breg0 + (l->dw_loc_opc - DW_OP_reg0)),
   31747              :                               0, 0);
   31748              :       else
   31749           21 :         switch (l->dw_loc_opc)
   31750              :           {
   31751            0 :           case DW_OP_regx:
   31752            0 :             tail = new_loc_descr (DW_OP_bregx,
   31753              :                                   l->dw_loc_oprnd1.v.val_unsigned, 0);
   31754            0 :             break;
   31755              :           case DW_OP_stack_value:
   31756              :             break;
   31757              :           default:
   31758              :             return NULL;
   31759              :           }
   31760              :     }
   31761              :   else
   31762            0 :     tail = new_loc_descr (DW_OP_deref, 0, 0);
   31763              : 
   31764           69 :   dw_loc_descr_ref ret = NULL, *p = &ret;
   31765           90 :   while (expr != l)
   31766              :     {
   31767           21 :       *p = new_loc_descr (expr->dw_loc_opc, 0, 0);
   31768           21 :       (*p)->dw_loc_oprnd1.val_class = expr->dw_loc_oprnd1.val_class;
   31769           21 :       (*p)->dw_loc_oprnd1.val_entry = expr->dw_loc_oprnd1.val_entry;
   31770           21 :       (*p)->dw_loc_oprnd1.v = expr->dw_loc_oprnd1.v;
   31771           21 :       (*p)->dw_loc_oprnd2.val_class = expr->dw_loc_oprnd2.val_class;
   31772           21 :       (*p)->dw_loc_oprnd2.val_entry = expr->dw_loc_oprnd2.val_entry;
   31773           21 :       (*p)->dw_loc_oprnd2.v = expr->dw_loc_oprnd2.v;
   31774           21 :       p = &(*p)->dw_loc_next;
   31775           21 :       expr = expr->dw_loc_next;
   31776              :     }
   31777           69 :   *p = tail;
   31778           69 :   return ret;
   31779              : }
   31780              : 
   31781              : /* For DW_AT_string_length attribute with DW_OP_GNU_variable_value
   31782              :    reference to a variable or argument, adjust it if needed and return:
   31783              :    -1 if the DW_AT_string_length attribute and DW_AT_{string_length_,}byte_size
   31784              :       attribute if present should be removed
   31785              :    0 keep the attribute perhaps with minor modifications, no need to rescan
   31786              :    1 if the attribute has been successfully adjusted.  */
   31787              : 
   31788              : static int
   31789         1252 : optimize_string_length (dw_attr_node *a)
   31790              : {
   31791         1252 :   dw_loc_descr_ref l = AT_loc (a), lv;
   31792         1252 :   dw_die_ref die;
   31793         1252 :   if (l->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
   31794              :     {
   31795            0 :       tree decl = l->dw_loc_oprnd1.v.val_decl_ref;
   31796            0 :       die = lookup_decl_die (decl);
   31797            0 :       if (die)
   31798              :         {
   31799            0 :           l->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   31800            0 :           l->dw_loc_oprnd1.v.val_die_ref.die = die;
   31801            0 :           l->dw_loc_oprnd1.v.val_die_ref.external = 0;
   31802              :         }
   31803              :       else
   31804              :         return -1;
   31805              :     }
   31806              :   else
   31807         1252 :     die = l->dw_loc_oprnd1.v.val_die_ref.die;
   31808              : 
   31809              :   /* DWARF5 allows reference class, so we can then reference the DIE.
   31810              :      Only do this for DW_OP_GNU_variable_value DW_OP_stack_value.  */
   31811         1252 :   if (l->dw_loc_next != NULL && dwarf_version >= 5)
   31812              :     {
   31813         1210 :       a->dw_attr_val.val_class = dw_val_class_die_ref;
   31814         1210 :       a->dw_attr_val.val_entry = NULL;
   31815         1210 :       a->dw_attr_val.v.val_die_ref.die = die;
   31816         1210 :       a->dw_attr_val.v.val_die_ref.external = 0;
   31817         1210 :       return 0;
   31818              :     }
   31819              : 
   31820           42 :   dw_attr_node *av = get_AT (die, DW_AT_location);
   31821           42 :   dw_loc_list_ref d;
   31822           42 :   bool non_dwarf_expr = false;
   31823              : 
   31824           42 :   if (av == NULL)
   31825           34 :     return dwarf_strict ? -1 : 0;
   31826            8 :   switch (AT_class (av))
   31827              :     {
   31828            7 :     case dw_val_class_loc_list:
   31829           76 :       for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
   31830           69 :         if (d->expr && non_dwarf_expression (d->expr))
   31831              :           non_dwarf_expr = true;
   31832              :       break;
   31833            0 :     case dw_val_class_view_list:
   31834            0 :       gcc_unreachable ();
   31835            1 :     case dw_val_class_loc:
   31836            1 :       lv = AT_loc (av);
   31837            1 :       if (lv == NULL)
   31838            0 :         return dwarf_strict ? -1 : 0;
   31839            1 :       if (non_dwarf_expression (lv))
   31840              :         non_dwarf_expr = true;
   31841              :       break;
   31842            0 :     default:
   31843            0 :       return dwarf_strict ? -1 : 0;
   31844              :     }
   31845              : 
   31846              :   /* If it is safe to transform DW_OP_GNU_variable_value DW_OP_stack_value
   31847              :      into DW_OP_call4  or DW_OP_GNU_variable_value into
   31848              :      DW_OP_call4 DW_OP_deref, do so.  */
   31849            7 :   if (!non_dwarf_expr
   31850            8 :       && (l->dw_loc_next != NULL || AT_class (av) == dw_val_class_loc))
   31851              :     {
   31852            1 :       l->dw_loc_opc = DW_OP_call4;
   31853            1 :       if (l->dw_loc_next)
   31854              :         l->dw_loc_next = NULL;
   31855              :       else
   31856            1 :         l->dw_loc_next = new_loc_descr (DW_OP_deref, 0, 0);
   31857            1 :       return 0;
   31858              :     }
   31859              : 
   31860              :   /* For DW_OP_GNU_variable_value DW_OP_stack_value, we can just
   31861              :      copy over the DW_AT_location attribute from die to a.  */
   31862            7 :   if (l->dw_loc_next != NULL)
   31863              :     {
   31864            0 :       a->dw_attr_val.val_class = av->dw_attr_val.val_class;
   31865            0 :       a->dw_attr_val.val_entry = av->dw_attr_val.val_entry;
   31866            0 :       a->dw_attr_val.v = av->dw_attr_val.v;
   31867            0 :       return 1;
   31868              :     }
   31869              : 
   31870            7 :   dw_loc_list_ref list, *p;
   31871            7 :   switch (AT_class (av))
   31872              :     {
   31873            7 :     case dw_val_class_loc_list:
   31874            7 :       p = &list;
   31875            7 :       list = NULL;
   31876           76 :       for (d = AT_loc_list (av); d != NULL; d = d->dw_loc_next)
   31877              :         {
   31878           69 :           lv = copy_deref_exprloc (d->expr);
   31879           69 :           if (lv)
   31880              :             {
   31881           69 :               *p = new_loc_list (lv, d->begin, d->vbegin, d->end, d->vend, d->section);
   31882           69 :               p = &(*p)->dw_loc_next;
   31883              :             }
   31884            0 :           else if (!dwarf_strict && d->expr)
   31885              :             return 0;
   31886              :         }
   31887            7 :       if (list == NULL)
   31888            0 :         return dwarf_strict ? -1 : 0;
   31889            7 :       a->dw_attr_val.val_class = dw_val_class_loc_list;
   31890            7 :       gen_llsym (list);
   31891            7 :       *AT_loc_list_ptr (a) = list;
   31892            7 :       return 1;
   31893            0 :     case dw_val_class_loc:
   31894            0 :       lv = copy_deref_exprloc (AT_loc (av));
   31895            0 :       if (lv == NULL)
   31896            0 :         return dwarf_strict ? -1 : 0;
   31897            0 :       a->dw_attr_val.v.val_loc = lv;
   31898            0 :       return 1;
   31899            0 :     default:
   31900            0 :       gcc_unreachable ();
   31901              :     }
   31902              : }
   31903              : 
   31904              : /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
   31905              :    an address in .rodata section if the string literal is emitted there,
   31906              :    or remove the containing location list or replace DW_AT_const_value
   31907              :    with DW_AT_location and empty location expression, if it isn't found
   31908              :    in .rodata.  Similarly for SYMBOL_REFs, keep only those that refer
   31909              :    to something that has been emitted in the current CU.  */
   31910              : 
   31911              : static void
   31912     85673586 : resolve_addr (dw_die_ref die)
   31913              : {
   31914     85673586 :   dw_die_ref c;
   31915     85673586 :   dw_attr_node *a;
   31916     85673586 :   dw_loc_list_ref *curr, *start, loc;
   31917     85673586 :   unsigned ix;
   31918     85673586 :   bool remove_AT_byte_size = false;
   31919              : 
   31920    405964849 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   31921    320291263 :     switch (AT_class (a))
   31922              :       {
   31923     12816399 :       case dw_val_class_loc_list:
   31924     12816399 :         start = curr = AT_loc_list_ptr (a);
   31925     12816399 :         loc = *curr;
   31926     12816399 :         gcc_assert (loc);
   31927              :         /* The same list can be referenced more than once.  See if we have
   31928              :            already recorded the result from a previous pass.  */
   31929     12816399 :         if (loc->replaced)
   31930            0 :           *curr = loc->dw_loc_next;
   31931     12816399 :         else if (!loc->resolved_addr)
   31932              :           {
   31933              :             /* As things stand, we do not expect or allow one die to
   31934              :                reference a suffix of another die's location list chain.
   31935              :                References must be identical or completely separate.
   31936              :                There is therefore no need to cache the result of this
   31937              :                pass on any list other than the first; doing so
   31938              :                would lead to unnecessary writes.  */
   31939     40091775 :             while (*curr)
   31940              :               {
   31941     27275376 :                 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
   31942     27275376 :                 if (!resolve_addr_in_expr (a, (*curr)->expr))
   31943              :                   {
   31944       893025 :                     dw_loc_list_ref next = (*curr)->dw_loc_next;
   31945       893025 :                     dw_loc_descr_ref l = (*curr)->expr;
   31946              : 
   31947       893025 :                     if (next && (*curr)->ll_symbol)
   31948              :                       {
   31949       306771 :                         gcc_assert (!next->ll_symbol);
   31950       306771 :                         next->ll_symbol = (*curr)->ll_symbol;
   31951       306771 :                         next->vl_symbol = (*curr)->vl_symbol;
   31952              :                       }
   31953       893025 :                     if (dwarf_split_debug_info)
   31954            0 :                       remove_loc_list_addr_table_entries (l);
   31955       893025 :                     *curr = next;
   31956              :                   }
   31957              :                 else
   31958              :                   {
   31959     26382351 :                     mark_base_types ((*curr)->expr);
   31960     26382351 :                     curr = &(*curr)->dw_loc_next;
   31961              :                   }
   31962              :               }
   31963     12816399 :             if (loc == *start)
   31964     12235486 :               loc->resolved_addr = 1;
   31965              :             else
   31966              :               {
   31967       580913 :                 loc->replaced = 1;
   31968       580913 :                 loc->dw_loc_next = *start;
   31969              :               }
   31970              :           }
   31971     12816399 :         if (!*start)
   31972              :           {
   31973       580715 :             remove_AT (die, a->dw_attr);
   31974       580715 :             ix--;
   31975              :           }
   31976              :         break;
   31977     12639444 :       case dw_val_class_view_list:
   31978     12639444 :         {
   31979     12639444 :           gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
   31980     12639444 :           gcc_checking_assert (dwarf2out_locviews_in_attribute ());
   31981     12639444 :           dw_val_node *llnode
   31982     12639444 :             = view_list_to_loc_list_val_node (&a->dw_attr_val);
   31983              :           /* If we no longer have a loclist, or it no longer needs
   31984              :              views, drop this attribute.  */
   31985     12639444 :           if (!llnode || !llnode->v.val_loc_list->vl_symbol)
   31986              :             {
   31987       580714 :               remove_AT (die, a->dw_attr);
   31988       580714 :               ix--;
   31989              :             }
   31990              :           break;
   31991              :         }
   31992      7983186 :       case dw_val_class_loc:
   31993      7983186 :         {
   31994      7983186 :           dw_loc_descr_ref l = AT_loc (a);
   31995              :           /* DW_OP_GNU_variable_value DW_OP_stack_value or
   31996              :              DW_OP_GNU_variable_value in DW_AT_string_length can be converted
   31997              :              into DW_OP_call4 or DW_OP_call4 DW_OP_deref, which is standard
   31998              :              DWARF4 unlike DW_OP_GNU_variable_value.  Or for DWARF5
   31999              :              DW_OP_GNU_variable_value DW_OP_stack_value can be replaced
   32000              :              with DW_FORM_ref referencing the same DIE as
   32001              :              DW_OP_GNU_variable_value used to reference.  */
   32002      7983186 :           if (a->dw_attr == DW_AT_string_length
   32003         1265 :               && l
   32004         1265 :               && l->dw_loc_opc == DW_OP_GNU_variable_value
   32005         1252 :               && (l->dw_loc_next == NULL
   32006         1210 :                   || (l->dw_loc_next->dw_loc_next == NULL
   32007         1210 :                       && l->dw_loc_next->dw_loc_opc == DW_OP_stack_value)))
   32008              :             {
   32009         1252 :               switch (optimize_string_length (a))
   32010              :                 {
   32011            0 :                 case -1:
   32012            0 :                   remove_AT (die, a->dw_attr);
   32013            0 :                   ix--;
   32014              :                   /* If we drop DW_AT_string_length, we need to drop also
   32015              :                      DW_AT_{string_length_,}byte_size.  */
   32016            0 :                   remove_AT_byte_size = true;
   32017            0 :                   continue;
   32018              :                 default:
   32019              :                   break;
   32020            7 :                 case 1:
   32021              :                   /* Even if we keep the optimized DW_AT_string_length,
   32022              :                      it might have changed AT_class, so process it again.  */
   32023            7 :                   ix--;
   32024            7 :                   continue;
   32025              :                 }
   32026              :             }
   32027              :           /* For -gdwarf-2 don't attempt to optimize
   32028              :              DW_AT_data_member_location containing
   32029              :              DW_OP_plus_uconst - older consumers might
   32030              :              rely on it being that op instead of a more complex,
   32031              :              but shorter, location description.  */
   32032      7983179 :           if ((dwarf_version > 2
   32033        10852 :                || a->dw_attr != DW_AT_data_member_location
   32034         1992 :                || l == NULL
   32035         1992 :                || l->dw_loc_opc != DW_OP_plus_uconst
   32036         1986 :                || l->dw_loc_next != NULL)
   32037      7992045 :               && !resolve_addr_in_expr (a, l))
   32038              :             {
   32039        24216 :               if (dwarf_split_debug_info)
   32040            0 :                 remove_loc_list_addr_table_entries (l);
   32041        24216 :               if (l != NULL
   32042        24216 :                   && l->dw_loc_next == NULL
   32043        10332 :                   && l->dw_loc_opc == DW_OP_addr
   32044        10105 :                   && GET_CODE (l->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF
   32045        10011 :                   && SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr)
   32046        34227 :                   && a->dw_attr == DW_AT_location)
   32047              :                 {
   32048         2732 :                   tree decl = SYMBOL_REF_DECL (l->dw_loc_oprnd1.v.val_addr);
   32049         2732 :                   remove_AT (die, a->dw_attr);
   32050         2732 :                   ix--;
   32051         2732 :                   optimize_location_into_implicit_ptr (die, decl);
   32052         2732 :                   break;
   32053              :                 }
   32054        21484 :               if (a->dw_attr == DW_AT_string_length)
   32055              :                 /* If we drop DW_AT_string_length, we need to drop also
   32056              :                    DW_AT_{string_length_,}byte_size.  */
   32057            0 :                 remove_AT_byte_size = true;
   32058        21484 :               remove_AT (die, a->dw_attr);
   32059        21484 :               ix--;
   32060              :             }
   32061              :           else
   32062      7958963 :             mark_base_types (l);
   32063              :         }
   32064              :         break;
   32065      1524584 :       case dw_val_class_addr:
   32066      1524584 :         if (a->dw_attr == DW_AT_const_value
   32067      1524584 :             && !resolve_one_addr (&a->dw_attr_val.v.val_addr))
   32068              :           {
   32069            0 :             if (AT_index (a) != NOT_INDEXED)
   32070            0 :               remove_addr_table_entry (a->dw_attr_val.val_entry);
   32071            0 :             remove_AT (die, a->dw_attr);
   32072            0 :             ix--;
   32073              :           }
   32074      1524584 :         if ((die->die_tag == DW_TAG_call_site
   32075      1524030 :              && a->dw_attr == DW_AT_call_origin)
   32076          554 :             || (die->die_tag == DW_TAG_GNU_call_site
   32077          554 :                 && a->dw_attr == DW_AT_abstract_origin))
   32078              :           {
   32079      1524584 :             tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
   32080      1524584 :             dw_die_ref tdie = lookup_decl_die (tdecl);
   32081      1524584 :             dw_die_ref cdie;
   32082      1524584 :             if (tdie == NULL
   32083       354365 :                 && DECL_EXTERNAL (tdecl)
   32084       301526 :                 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE
   32085      1824930 :                 && (cdie = lookup_context_die (DECL_CONTEXT (tdecl))))
   32086              :               {
   32087              :                 dw_die_ref pdie = cdie;
   32088              :                 /* Make sure we don't add these DIEs into type units.
   32089              :                    We could emit skeleton DIEs for context (namespaces,
   32090              :                    outer structs/classes) and a skeleton DIE for the
   32091              :                    innermost context with DW_AT_signature pointing to the
   32092              :                    type unit.  See PR78835.  */
   32093       529754 :                 while (pdie && pdie->die_tag != DW_TAG_type_unit)
   32094       264985 :                   pdie = pdie->die_parent;
   32095       264769 :                 if (pdie == NULL)
   32096              :                   {
   32097              :                     /* Creating a full DIE for tdecl is overly expensive and
   32098              :                        at this point even wrong when in the LTO phase
   32099              :                        as it can end up generating new type DIEs we didn't
   32100              :                        output and thus optimize_external_refs will crash.  */
   32101       264769 :                     tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE);
   32102       264769 :                     add_AT_flag (tdie, DW_AT_external, 1);
   32103       264769 :                     add_AT_flag (tdie, DW_AT_declaration, 1);
   32104       264769 :                     add_linkage_attr (tdie, tdecl);
   32105       264769 :                     add_name_and_src_coords_attributes (tdie, tdecl, true);
   32106       264769 :                     equate_decl_number_to_die (tdecl, tdie);
   32107              :                   }
   32108              :               }
   32109      1524584 :             if (tdie)
   32110              :               {
   32111      1434988 :                 a->dw_attr_val.val_class = dw_val_class_die_ref;
   32112      1434988 :                 a->dw_attr_val.v.val_die_ref.die = tdie;
   32113      1434988 :                 a->dw_attr_val.v.val_die_ref.external = 0;
   32114              :               }
   32115              :             else
   32116              :               {
   32117        89596 :                 if (AT_index (a) != NOT_INDEXED)
   32118            0 :                   remove_addr_table_entry (a->dw_attr_val.val_entry);
   32119        89596 :                 remove_AT (die, a->dw_attr);
   32120        89596 :                 ix--;
   32121              :               }
   32122              :           }
   32123              :         break;
   32124              :       default:
   32125              :         break;
   32126              :       }
   32127              : 
   32128     85673586 :   if (remove_AT_byte_size)
   32129            0 :     remove_AT (die, dwarf_version >= 5
   32130              :                     ? DW_AT_string_length_byte_size
   32131              :                     : DW_AT_byte_size);
   32132              : 
   32133    148751561 :   FOR_EACH_CHILD (die, c, resolve_addr (c));
   32134     85673586 : }
   32135              : 
   32136              : /* Helper routines for optimize_location_lists.
   32137              :    This pass tries to share identical local lists in .debug_loc
   32138              :    section.  */
   32139              : 
   32140              : /* Iteratively hash operands of LOC opcode into HSTATE.  */
   32141              : 
   32142              : static void
   32143     56393065 : hash_loc_operands (dw_loc_descr_ref loc, inchash::hash &hstate)
   32144              : {
   32145     56393065 :   dw_val_ref val1 = &loc->dw_loc_oprnd1;
   32146     56393065 :   dw_val_ref val2 = &loc->dw_loc_oprnd2;
   32147              : 
   32148     56393065 :   switch (loc->dw_loc_opc)
   32149              :     {
   32150       453350 :     case DW_OP_const4u:
   32151       453350 :     case DW_OP_const8u:
   32152       453350 :       if (loc->dw_loc_dtprel)
   32153          209 :         goto hash_addr;
   32154              :       /* FALLTHRU */
   32155     19430852 :     case DW_OP_const1u:
   32156     19430852 :     case DW_OP_const1s:
   32157     19430852 :     case DW_OP_const2u:
   32158     19430852 :     case DW_OP_const2s:
   32159     19430852 :     case DW_OP_const4s:
   32160     19430852 :     case DW_OP_const8s:
   32161     19430852 :     case DW_OP_constu:
   32162     19430852 :     case DW_OP_consts:
   32163     19430852 :     case DW_OP_pick:
   32164     19430852 :     case DW_OP_plus_uconst:
   32165     19430852 :     case DW_OP_breg0:
   32166     19430852 :     case DW_OP_breg1:
   32167     19430852 :     case DW_OP_breg2:
   32168     19430852 :     case DW_OP_breg3:
   32169     19430852 :     case DW_OP_breg4:
   32170     19430852 :     case DW_OP_breg5:
   32171     19430852 :     case DW_OP_breg6:
   32172     19430852 :     case DW_OP_breg7:
   32173     19430852 :     case DW_OP_breg8:
   32174     19430852 :     case DW_OP_breg9:
   32175     19430852 :     case DW_OP_breg10:
   32176     19430852 :     case DW_OP_breg11:
   32177     19430852 :     case DW_OP_breg12:
   32178     19430852 :     case DW_OP_breg13:
   32179     19430852 :     case DW_OP_breg14:
   32180     19430852 :     case DW_OP_breg15:
   32181     19430852 :     case DW_OP_breg16:
   32182     19430852 :     case DW_OP_breg17:
   32183     19430852 :     case DW_OP_breg18:
   32184     19430852 :     case DW_OP_breg19:
   32185     19430852 :     case DW_OP_breg20:
   32186     19430852 :     case DW_OP_breg21:
   32187     19430852 :     case DW_OP_breg22:
   32188     19430852 :     case DW_OP_breg23:
   32189     19430852 :     case DW_OP_breg24:
   32190     19430852 :     case DW_OP_breg25:
   32191     19430852 :     case DW_OP_breg26:
   32192     19430852 :     case DW_OP_breg27:
   32193     19430852 :     case DW_OP_breg28:
   32194     19430852 :     case DW_OP_breg29:
   32195     19430852 :     case DW_OP_breg30:
   32196     19430852 :     case DW_OP_breg31:
   32197     19430852 :     case DW_OP_regx:
   32198     19430852 :     case DW_OP_fbreg:
   32199     19430852 :     case DW_OP_piece:
   32200     19430852 :     case DW_OP_deref_size:
   32201     19430852 :     case DW_OP_xderef_size:
   32202     19430852 :       hstate.add_object (val1->v.val_int);
   32203     19430852 :       break;
   32204       121377 :     case DW_OP_skip:
   32205       121377 :     case DW_OP_bra:
   32206       121377 :       {
   32207       121377 :         int offset;
   32208              : 
   32209       121377 :         gcc_assert (val1->val_class == dw_val_class_loc);
   32210       121377 :         offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
   32211       121377 :         hstate.add_object (offset);
   32212              :       }
   32213       121377 :       break;
   32214       124560 :     case DW_OP_implicit_value:
   32215       124560 :       hstate.add_object (val1->v.val_unsigned);
   32216       124560 :       switch (val2->val_class)
   32217              :         {
   32218        69104 :         case dw_val_class_const:
   32219        69104 :           hstate.add_object (val2->v.val_int);
   32220        69104 :           break;
   32221        54822 :         case dw_val_class_vec:
   32222        54822 :           {
   32223        54822 :             unsigned int elt_size = val2->v.val_vec.elt_size;
   32224        54822 :             unsigned int len = val2->v.val_vec.length;
   32225              : 
   32226        54822 :             hstate.add_int (elt_size);
   32227        54822 :             hstate.add_int (len);
   32228        54822 :             hstate.add (val2->v.val_vec.array, len * elt_size);
   32229              :           }
   32230        54822 :           break;
   32231            0 :         case dw_val_class_const_double:
   32232            0 :           hstate.add_object (val2->v.val_double.low);
   32233            0 :           hstate.add_object (val2->v.val_double.high);
   32234            0 :           break;
   32235          634 :         case dw_val_class_wide_int:
   32236         1268 :           hstate.add (val2->v.val_wide->get_val (),
   32237          634 :                       get_full_len (*val2->v.val_wide)
   32238          634 :                       * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
   32239          634 :           break;
   32240            0 :         case dw_val_class_addr:
   32241            0 :           inchash::add_rtx (val2->v.val_addr, hstate);
   32242            0 :           break;
   32243            0 :         default:
   32244            0 :           gcc_unreachable ();
   32245              :         }
   32246              :       break;
   32247       115920 :     case DW_OP_bregx:
   32248       115920 :     case DW_OP_bit_piece:
   32249       115920 :       hstate.add_object (val1->v.val_int);
   32250       115920 :       hstate.add_object (val2->v.val_int);
   32251       115920 :       break;
   32252       562885 :     case DW_OP_addr:
   32253       562885 :     hash_addr:
   32254       562885 :       if (loc->dw_loc_dtprel)
   32255              :         {
   32256          209 :           unsigned char dtprel = 0xd1;
   32257          209 :           hstate.add_object (dtprel);
   32258              :         }
   32259       562885 :       inchash::add_rtx (val1->v.val_addr, hstate);
   32260       562885 :       break;
   32261            3 :     case DW_OP_GNU_addr_index:
   32262            3 :     case DW_OP_addrx:
   32263            3 :     case DW_OP_GNU_const_index:
   32264            3 :     case DW_OP_constx:
   32265            3 :       {
   32266            3 :         if (loc->dw_loc_dtprel)
   32267              :           {
   32268            0 :             unsigned char dtprel = 0xd1;
   32269            0 :             hstate.add_object (dtprel);
   32270              :           }
   32271            3 :         inchash::add_rtx (val1->val_entry->addr.rtl, hstate);
   32272              :       }
   32273            3 :       break;
   32274      1297882 :     case DW_OP_implicit_pointer:
   32275      1297882 :     case DW_OP_GNU_implicit_pointer:
   32276      1297882 :       hstate.add_int (val2->v.val_int);
   32277      1297882 :       break;
   32278      1284645 :     case DW_OP_entry_value:
   32279      1284645 :     case DW_OP_GNU_entry_value:
   32280      1284645 :       hstate.add_object (val1->v.val_loc);
   32281      1284645 :       break;
   32282       131542 :     case DW_OP_regval_type:
   32283       131542 :     case DW_OP_deref_type:
   32284       131542 :     case DW_OP_GNU_regval_type:
   32285       131542 :     case DW_OP_GNU_deref_type:
   32286       131542 :       {
   32287       131542 :         unsigned int byte_size
   32288       131542 :           = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
   32289       131542 :         unsigned int encoding
   32290       131542 :           = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
   32291       131542 :         hstate.add_object (val1->v.val_int);
   32292       131542 :         hstate.add_object (byte_size);
   32293       131542 :         hstate.add_object (encoding);
   32294              :       }
   32295       131542 :       break;
   32296       317167 :     case DW_OP_convert:
   32297       317167 :     case DW_OP_reinterpret:
   32298       317167 :     case DW_OP_GNU_convert:
   32299       317167 :     case DW_OP_GNU_reinterpret:
   32300       317167 :       if (val1->val_class == dw_val_class_unsigned_const)
   32301              :         {
   32302        27216 :           hstate.add_object (val1->v.val_unsigned);
   32303        27216 :           break;
   32304              :         }
   32305              :       /* FALLTHRU */
   32306       352773 :     case DW_OP_const_type:
   32307       352773 :     case DW_OP_GNU_const_type:
   32308       352773 :       {
   32309       352773 :         unsigned int byte_size
   32310       352773 :           = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
   32311       352773 :         unsigned int encoding
   32312       352773 :           = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
   32313       352773 :         hstate.add_object (byte_size);
   32314       352773 :         hstate.add_object (encoding);
   32315       352773 :         if (loc->dw_loc_opc != DW_OP_const_type
   32316       289951 :             && loc->dw_loc_opc != DW_OP_GNU_const_type)
   32317              :           break;
   32318        62822 :         hstate.add_object (val2->val_class);
   32319        62822 :         switch (val2->val_class)
   32320              :           {
   32321        39925 :           case dw_val_class_const:
   32322        39925 :             hstate.add_object (val2->v.val_int);
   32323        39925 :             break;
   32324        22737 :           case dw_val_class_vec:
   32325        22737 :             {
   32326        22737 :               unsigned int elt_size = val2->v.val_vec.elt_size;
   32327        22737 :               unsigned int len = val2->v.val_vec.length;
   32328              : 
   32329        22737 :               hstate.add_object (elt_size);
   32330        22737 :               hstate.add_object (len);
   32331        22737 :               hstate.add (val2->v.val_vec.array, len * elt_size);
   32332              :             }
   32333        22737 :             break;
   32334           88 :           case dw_val_class_const_double:
   32335           88 :             hstate.add_object (val2->v.val_double.low);
   32336           88 :             hstate.add_object (val2->v.val_double.high);
   32337           88 :             break;
   32338           72 :           case dw_val_class_wide_int:
   32339          144 :             hstate.add (val2->v.val_wide->get_val (),
   32340           72 :                         get_full_len (*val2->v.val_wide)
   32341           72 :                         * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR);
   32342           72 :             break;
   32343            0 :           default:
   32344            0 :             gcc_unreachable ();
   32345              :           }
   32346              :       }
   32347        62822 :       break;
   32348              : 
   32349              :     default:
   32350              :       /* Other codes have no operands.  */
   32351              :       break;
   32352              :     }
   32353     56393065 : }
   32354              : 
   32355              : /* Iteratively hash the whole DWARF location expression LOC into HSTATE.  */
   32356              : 
   32357              : static inline void
   32358     26382351 : hash_locs (dw_loc_descr_ref loc, inchash::hash &hstate)
   32359              : {
   32360     26382351 :   dw_loc_descr_ref l;
   32361     26382351 :   bool sizes_computed = false;
   32362              :   /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed.  */
   32363     26382351 :   size_of_locs (loc);
   32364              : 
   32365    109157157 :   for (l = loc; l != NULL; l = l->dw_loc_next)
   32366              :     {
   32367     56392455 :       enum dwarf_location_atom opc = l->dw_loc_opc;
   32368     56392455 :       hstate.add_object (opc);
   32369     56392455 :       if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
   32370              :         {
   32371        71622 :           size_of_locs (loc);
   32372        71622 :           sizes_computed = true;
   32373              :         }
   32374     56392455 :       hash_loc_operands (l, hstate);
   32375              :     }
   32376     26382351 : }
   32377              : 
   32378              : /* Compute hash of the whole location list LIST_HEAD.  */
   32379              : 
   32380              : static inline void
   32381     12235684 : hash_loc_list (dw_loc_list_ref list_head)
   32382              : {
   32383     12235684 :   dw_loc_list_ref curr = list_head;
   32384     12235684 :   inchash::hash hstate;
   32385              : 
   32386     38618035 :   for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
   32387              :     {
   32388     26382351 :       hstate.add (curr->begin, strlen (curr->begin) + 1);
   32389     26382351 :       hstate.add (curr->end, strlen (curr->end) + 1);
   32390     26382351 :       hstate.add_object (curr->vbegin);
   32391     26382351 :       hstate.add_object (curr->vend);
   32392     26382351 :       if (curr->section)
   32393     26382351 :         hstate.add (curr->section, strlen (curr->section) + 1);
   32394     26382351 :       hash_locs (curr->expr, hstate);
   32395              :     }
   32396     12235684 :   list_head->hash = hstate.end ();
   32397     12235684 : }
   32398              : 
   32399              : /* Return true if X and Y opcodes have the same operands.  */
   32400              : 
   32401              : static inline bool
   32402      1590645 : compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
   32403              : {
   32404      1590645 :   dw_val_ref valx1 = &x->dw_loc_oprnd1;
   32405      1590645 :   dw_val_ref valx2 = &x->dw_loc_oprnd2;
   32406      1590645 :   dw_val_ref valy1 = &y->dw_loc_oprnd1;
   32407      1590645 :   dw_val_ref valy2 = &y->dw_loc_oprnd2;
   32408              : 
   32409      1590645 :   switch (x->dw_loc_opc)
   32410              :     {
   32411        95306 :     case DW_OP_const4u:
   32412        95306 :     case DW_OP_const8u:
   32413        95306 :       if (x->dw_loc_dtprel)
   32414            0 :         goto hash_addr;
   32415              :       /* FALLTHRU */
   32416       503622 :     case DW_OP_const1u:
   32417       503622 :     case DW_OP_const1s:
   32418       503622 :     case DW_OP_const2u:
   32419       503622 :     case DW_OP_const2s:
   32420       503622 :     case DW_OP_const4s:
   32421       503622 :     case DW_OP_const8s:
   32422       503622 :     case DW_OP_constu:
   32423       503622 :     case DW_OP_consts:
   32424       503622 :     case DW_OP_pick:
   32425       503622 :     case DW_OP_plus_uconst:
   32426       503622 :     case DW_OP_breg0:
   32427       503622 :     case DW_OP_breg1:
   32428       503622 :     case DW_OP_breg2:
   32429       503622 :     case DW_OP_breg3:
   32430       503622 :     case DW_OP_breg4:
   32431       503622 :     case DW_OP_breg5:
   32432       503622 :     case DW_OP_breg6:
   32433       503622 :     case DW_OP_breg7:
   32434       503622 :     case DW_OP_breg8:
   32435       503622 :     case DW_OP_breg9:
   32436       503622 :     case DW_OP_breg10:
   32437       503622 :     case DW_OP_breg11:
   32438       503622 :     case DW_OP_breg12:
   32439       503622 :     case DW_OP_breg13:
   32440       503622 :     case DW_OP_breg14:
   32441       503622 :     case DW_OP_breg15:
   32442       503622 :     case DW_OP_breg16:
   32443       503622 :     case DW_OP_breg17:
   32444       503622 :     case DW_OP_breg18:
   32445       503622 :     case DW_OP_breg19:
   32446       503622 :     case DW_OP_breg20:
   32447       503622 :     case DW_OP_breg21:
   32448       503622 :     case DW_OP_breg22:
   32449       503622 :     case DW_OP_breg23:
   32450       503622 :     case DW_OP_breg24:
   32451       503622 :     case DW_OP_breg25:
   32452       503622 :     case DW_OP_breg26:
   32453       503622 :     case DW_OP_breg27:
   32454       503622 :     case DW_OP_breg28:
   32455       503622 :     case DW_OP_breg29:
   32456       503622 :     case DW_OP_breg30:
   32457       503622 :     case DW_OP_breg31:
   32458       503622 :     case DW_OP_regx:
   32459       503622 :     case DW_OP_fbreg:
   32460       503622 :     case DW_OP_piece:
   32461       503622 :     case DW_OP_deref_size:
   32462       503622 :     case DW_OP_xderef_size:
   32463       503622 :       return valx1->v.val_int == valy1->v.val_int;
   32464          588 :     case DW_OP_skip:
   32465          588 :     case DW_OP_bra:
   32466              :       /* If splitting debug info, the use of DW_OP_GNU_addr_index
   32467              :         can cause irrelevant differences in dw_loc_addr.  */
   32468          588 :       gcc_assert (valx1->val_class == dw_val_class_loc
   32469              :                   && valy1->val_class == dw_val_class_loc
   32470              :                   && (dwarf_split_debug_info
   32471              :                       || x->dw_loc_addr == y->dw_loc_addr));
   32472          588 :       return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
   32473        17701 :     case DW_OP_implicit_value:
   32474        17701 :       if (valx1->v.val_unsigned != valy1->v.val_unsigned
   32475        17701 :           || valx2->val_class != valy2->val_class)
   32476              :         return false;
   32477        17701 :       switch (valx2->val_class)
   32478              :         {
   32479        16199 :         case dw_val_class_const:
   32480        16199 :           return valx2->v.val_int == valy2->v.val_int;
   32481         1358 :         case dw_val_class_vec:
   32482         1358 :           return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
   32483         1358 :                  && valx2->v.val_vec.length == valy2->v.val_vec.length
   32484         1358 :                  && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
   32485              :                             valx2->v.val_vec.elt_size
   32486         1358 :                             * valx2->v.val_vec.length) == 0;
   32487            0 :         case dw_val_class_const_double:
   32488            0 :           return valx2->v.val_double.low == valy2->v.val_double.low
   32489            0 :                  && valx2->v.val_double.high == valy2->v.val_double.high;
   32490          144 :         case dw_val_class_wide_int:
   32491          144 :           return *valx2->v.val_wide == *valy2->v.val_wide;
   32492            0 :         case dw_val_class_addr:
   32493            0 :           return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
   32494            0 :         default:
   32495            0 :           gcc_unreachable ();
   32496              :         }
   32497            0 :     case DW_OP_bregx:
   32498            0 :     case DW_OP_bit_piece:
   32499            0 :       return valx1->v.val_int == valy1->v.val_int
   32500            0 :              && valx2->v.val_int == valy2->v.val_int;
   32501        13568 :     case DW_OP_addr:
   32502        13568 :     hash_addr:
   32503        13568 :       return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
   32504            0 :     case DW_OP_GNU_addr_index:
   32505            0 :     case DW_OP_addrx:
   32506            0 :     case DW_OP_GNU_const_index:
   32507            0 :     case DW_OP_constx:
   32508            0 :       {
   32509            0 :         rtx ax1 = valx1->val_entry->addr.rtl;
   32510            0 :         rtx ay1 = valy1->val_entry->addr.rtl;
   32511            0 :         return rtx_equal_p (ax1, ay1);
   32512              :       }
   32513        78773 :     case DW_OP_implicit_pointer:
   32514        78773 :     case DW_OP_GNU_implicit_pointer:
   32515        78773 :       return valx1->val_class == dw_val_class_die_ref
   32516        78773 :              && valx1->val_class == valy1->val_class
   32517        78773 :              && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
   32518        82620 :              && valx2->v.val_int == valy2->v.val_int;
   32519            0 :     case DW_OP_entry_value:
   32520            0 :     case DW_OP_GNU_entry_value:
   32521            0 :       return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
   32522        21676 :     case DW_OP_const_type:
   32523        21676 :     case DW_OP_GNU_const_type:
   32524        21676 :       if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
   32525        21676 :           || valx2->val_class != valy2->val_class)
   32526              :         return false;
   32527        21676 :       switch (valx2->val_class)
   32528              :         {
   32529        21609 :         case dw_val_class_const:
   32530        21609 :           return valx2->v.val_int == valy2->v.val_int;
   32531           67 :         case dw_val_class_vec:
   32532           67 :           return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
   32533           67 :                  && valx2->v.val_vec.length == valy2->v.val_vec.length
   32534           67 :                  && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
   32535              :                             valx2->v.val_vec.elt_size
   32536           67 :                             * valx2->v.val_vec.length) == 0;
   32537            0 :         case dw_val_class_const_double:
   32538            0 :           return valx2->v.val_double.low == valy2->v.val_double.low
   32539            0 :                  && valx2->v.val_double.high == valy2->v.val_double.high;
   32540            0 :         case dw_val_class_wide_int:
   32541            0 :           return *valx2->v.val_wide == *valy2->v.val_wide;
   32542            0 :         default:
   32543            0 :           gcc_unreachable ();
   32544              :         }
   32545        18484 :     case DW_OP_regval_type:
   32546        18484 :     case DW_OP_deref_type:
   32547        18484 :     case DW_OP_GNU_regval_type:
   32548        18484 :     case DW_OP_GNU_deref_type:
   32549        18484 :       return valx1->v.val_int == valy1->v.val_int
   32550        18484 :              && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
   32551        79920 :     case DW_OP_convert:
   32552        79920 :     case DW_OP_reinterpret:
   32553        79920 :     case DW_OP_GNU_convert:
   32554        79920 :     case DW_OP_GNU_reinterpret:
   32555        79920 :       if (valx1->val_class != valy1->val_class)
   32556              :         return false;
   32557        79920 :       if (valx1->val_class == dw_val_class_unsigned_const)
   32558            6 :         return valx1->v.val_unsigned == valy1->v.val_unsigned;
   32559        79914 :       return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
   32560         5007 :     case DW_OP_GNU_parameter_ref:
   32561         5007 :       return valx1->val_class == dw_val_class_die_ref
   32562         5007 :              && valx1->val_class == valy1->val_class
   32563        10014 :              && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
   32564              :     default:
   32565              :       /* Other codes have no operands.  */
   32566              :       return true;
   32567              :     }
   32568              : }
   32569              : 
   32570              : /* Return true if DWARF location expressions X and Y are the same.  */
   32571              : 
   32572              : static inline bool
   32573       388420 : compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
   32574              : {
   32575      1899198 :   for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
   32576      1590645 :     if (x->dw_loc_opc != y->dw_loc_opc
   32577      1590645 :         || x->dw_loc_dtprel != y->dw_loc_dtprel
   32578      3181290 :         || !compare_loc_operands (x, y))
   32579              :       break;
   32580       388420 :   return x == NULL && y == NULL;
   32581              : }
   32582              : 
   32583              : /* Hashtable helpers.  */
   32584              : 
   32585              : struct loc_list_hasher : nofree_ptr_hash <dw_loc_list_struct>
   32586              : {
   32587              :   static inline hashval_t hash (const dw_loc_list_struct *);
   32588              :   static inline bool equal (const dw_loc_list_struct *,
   32589              :                             const dw_loc_list_struct *);
   32590              : };
   32591              : 
   32592              : /* Return precomputed hash of location list X.  */
   32593              : 
   32594              : inline hashval_t
   32595     73328808 : loc_list_hasher::hash (const dw_loc_list_struct *x)
   32596              : {
   32597     73328808 :   return x->hash;
   32598              : }
   32599              : 
   32600              : /* Return true if location lists A and B are the same.  */
   32601              : 
   32602              : inline bool
   32603     73387316 : loc_list_hasher::equal (const dw_loc_list_struct *a,
   32604              :                         const dw_loc_list_struct *b)
   32605              : {
   32606     73387316 :   if (a == b)
   32607              :     return true;
   32608     73387316 :   if (a->hash != b->hash)
   32609              :     return false;
   32610       530015 :   for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
   32611       388446 :     if (strcmp (a->begin, b->begin) != 0
   32612       388420 :         || strcmp (a->end, b->end) != 0
   32613       388420 :         || (a->section == NULL) != (b->section == NULL)
   32614       388420 :         || (a->section && strcmp (a->section, b->section) != 0)
   32615       388420 :         || a->vbegin != b->vbegin || a->vend != b->vend
   32616       776866 :         || !compare_locs (a->expr, b->expr))
   32617              :       break;
   32618       221462 :   return a == NULL && b == NULL;
   32619              : }
   32620              : 
   32621              : typedef hash_table<loc_list_hasher> loc_list_hash_type;
   32622              : 
   32623              : 
   32624              : /* Recursively optimize location lists referenced from DIE
   32625              :    children and share them whenever possible.  */
   32626              : 
   32627              : static void
   32628     78507922 : optimize_location_lists_1 (dw_die_ref die, loc_list_hash_type *htab)
   32629              : {
   32630     78507922 :   dw_die_ref c;
   32631     78507922 :   dw_attr_node *a;
   32632     78507922 :   unsigned ix;
   32633     78507922 :   dw_loc_list_struct **slot;
   32634     78507922 :   bool drop_locviews = false;
   32635     78507922 :   bool has_locviews = false;
   32636              : 
   32637    386084558 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   32638    307576636 :     if (AT_class (a) == dw_val_class_loc_list)
   32639              :       {
   32640     12235684 :         dw_loc_list_ref list = AT_loc_list (a);
   32641              :         /* TODO: perform some optimizations here, before hashing
   32642              :            it and storing into the hash table.  */
   32643     12235684 :         hash_loc_list (list);
   32644     12235684 :         slot = htab->find_slot_with_hash (list, list->hash, INSERT);
   32645     12235684 :         if (*slot == NULL)
   32646              :           {
   32647     12094115 :             *slot = list;
   32648     12094115 :             if (loc_list_has_views (list))
   32649     11918090 :               gcc_assert (list->vl_symbol);
   32650       176025 :             else if (list->vl_symbol)
   32651              :               {
   32652            0 :                 drop_locviews = true;
   32653            0 :                 list->vl_symbol = NULL;
   32654              :               }
   32655              :           }
   32656              :         else
   32657              :           {
   32658       141569 :             if (list->vl_symbol && !(*slot)->vl_symbol)
   32659       141569 :               drop_locviews = true;
   32660       141569 :             a->dw_attr_val.v.val_loc_list = *slot;
   32661              :           }
   32662              :       }
   32663    295340952 :     else if (AT_class (a) == dw_val_class_view_list)
   32664              :       {
   32665     12058730 :         gcc_checking_assert (a->dw_attr == DW_AT_GNU_locviews);
   32666              :         has_locviews = true;
   32667              :       }
   32668              : 
   32669              : 
   32670     78507922 :   if (drop_locviews && has_locviews)
   32671            0 :     remove_AT (die, DW_AT_GNU_locviews);
   32672              : 
   32673    156982189 :   FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
   32674     78507922 : }
   32675              : 
   32676              : 
   32677              : /* Recursively assign each location list a unique index into the debug_addr
   32678              :    section.  */
   32679              : 
   32680              : static void
   32681           26 : index_location_lists (dw_die_ref die)
   32682              : {
   32683           26 :   dw_die_ref c;
   32684           26 :   dw_attr_node *a;
   32685           26 :   unsigned ix;
   32686              : 
   32687          155 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   32688          129 :     if (AT_class (a) == dw_val_class_loc_list)
   32689              :       {
   32690            2 :         dw_loc_list_ref list = AT_loc_list (a);
   32691            2 :         dw_loc_list_ref curr;
   32692            8 :         for (curr = list; curr != NULL; curr = curr->dw_loc_next)
   32693              :           {
   32694              :             /* Don't index an entry that has already been indexed
   32695              :                or won't be output.  Make sure skip_loc_list_entry doesn't
   32696              :                call size_of_locs, because that might cause circular dependency,
   32697              :                index_location_lists requiring address table indexes to be
   32698              :                computed, but adding new indexes through add_addr_table_entry
   32699              :                and address table index computation requiring no new additions
   32700              :                to the hash table.  In the rare case of DWARF[234] >= 64KB
   32701              :                location expression, we'll just waste unused address table entry
   32702              :                for it.  */
   32703            4 :             if (curr->begin_entry != NULL || skip_loc_list_entry (curr))
   32704            0 :               continue;
   32705              : 
   32706            4 :             curr->begin_entry
   32707            4 :               = add_addr_table_entry (xstrdup (curr->begin), ate_kind_label);
   32708            4 :             if (dwarf_version >= 5 && !HAVE_AS_LEB128)
   32709              :               curr->end_entry
   32710              :                 = add_addr_table_entry (xstrdup (curr->end), ate_kind_label);
   32711              :           }
   32712              :       }
   32713              : 
   32714           50 :   FOR_EACH_CHILD (die, c, index_location_lists (c));
   32715           26 : }
   32716              : 
   32717              : /* Optimize location lists referenced from DIE
   32718              :    children and share them whenever possible.  */
   32719              : 
   32720              : static void
   32721        33655 : optimize_location_lists (dw_die_ref die)
   32722              : {
   32723        33655 :   loc_list_hash_type htab (500);
   32724        33655 :   optimize_location_lists_1 (die, &htab);
   32725        33655 : }
   32726              : 
   32727              : /* Traverse the limbo die list, and add parent/child links.  The only
   32728              :    dies without parents that should be here are concrete instances of
   32729              :    inline functions, and the comp_unit_die.  We can ignore the comp_unit_die.
   32730              :    For concrete instances, we can get the parent die from the abstract
   32731              :    instance.  */
   32732              : 
   32733              : static void
   32734       106830 : flush_limbo_die_list (void)
   32735              : {
   32736       106830 :   limbo_die_node *node;
   32737              : 
   32738              :   /* get_context_die calls force_decl_die, which can put new DIEs on the
   32739              :      limbo list in LTO mode when nested functions are put in a different
   32740              :      partition than that of their parent function.  */
   32741       425869 :   while ((node = limbo_die_list))
   32742              :     {
   32743       212209 :       dw_die_ref die = node->die;
   32744       212209 :       limbo_die_list = node->next;
   32745              : 
   32746       212209 :       if (die->die_parent == NULL)
   32747              :         {
   32748       199629 :           dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
   32749              : 
   32750       199629 :           if (origin && origin->die_parent)
   32751        10384 :             add_child_die (origin->die_parent, die);
   32752       334525 :           else if (is_cu_die (die))
   32753              :             ;
   32754       134896 :           else if (seen_error ())
   32755              :             /* It's OK to be confused by errors in the input.  */
   32756            0 :             add_child_die (comp_unit_die (), die);
   32757              :           else
   32758              :             {
   32759              :               /* In certain situations, the lexical block containing a
   32760              :                  nested function can be optimized away, which results
   32761              :                  in the nested function die being orphaned.  Likewise
   32762              :                  with the return type of that nested function.  Force
   32763              :                  this to be a child of the containing function.
   32764              : 
   32765              :                  It may happen that even the containing function got fully
   32766              :                  inlined and optimized out.  In that case we are lost and
   32767              :                  assign the empty child.  This should not be big issue as
   32768              :                  the function is likely unreachable too.  */
   32769       134896 :               gcc_assert (node->created_for);
   32770              : 
   32771       134896 :               if (DECL_P (node->created_for))
   32772         2959 :                 origin = get_context_die (DECL_CONTEXT (node->created_for));
   32773       131937 :               else if (TYPE_P (node->created_for))
   32774       131937 :                 origin = scope_die_for (node->created_for, comp_unit_die ());
   32775              :               else
   32776            0 :                 origin = comp_unit_die ();
   32777              : 
   32778       134896 :               add_child_die (origin, die);
   32779              :             }
   32780              :         }
   32781              :     }
   32782       106830 : }
   32783              : 
   32784              : /* Reset DIEs so we can output them again.  */
   32785              : 
   32786              : static void
   32787        37132 : reset_dies (dw_die_ref die)
   32788              : {
   32789        37132 :   dw_die_ref c;
   32790              : 
   32791              :   /* Remove stuff we re-generate.  */
   32792        37132 :   die->die_mark = 0;
   32793        37132 :   die->die_offset = 0;
   32794        37132 :   die->die_abbrev = 0;
   32795        37132 :   remove_AT (die, DW_AT_sibling);
   32796              : 
   32797        73704 :   FOR_EACH_CHILD (die, c, reset_dies (c));
   32798        37132 : }
   32799              : 
   32800              : /* reset_indirect_string removed the references coming from DW_AT_name
   32801              :    and DW_AT_comp_dir attributes on compilation unit DIEs.  Readd them as
   32802              :    .debug_line_str strings again.  */
   32803              : 
   32804              : static void
   32805          548 : adjust_name_comp_dir (dw_die_ref die)
   32806              : {
   32807         1644 :   for (int i = 0; i < 2; i++)
   32808              :     {
   32809         1096 :       dwarf_attribute attr_kind = i ? DW_AT_comp_dir : DW_AT_name;
   32810         1096 :       dw_attr_node *a = get_AT (die, attr_kind);
   32811         1096 :       if (a == NULL || a->dw_attr_val.val_class != dw_val_class_str)
   32812            0 :         continue;
   32813              : 
   32814         1096 :       if (!debug_line_str_hash)
   32815          548 :         debug_line_str_hash
   32816          548 :           = hash_table<indirect_string_hasher>::create_ggc (10);
   32817              : 
   32818         1096 :       struct indirect_string_node *node
   32819         1096 :         = find_AT_string_in_table (a->dw_attr_val.v.val_str->str,
   32820              :                                    debug_line_str_hash);
   32821         1096 :       set_indirect_string (node);
   32822         1096 :       node->form = DW_FORM_line_strp;
   32823         1096 :       a->dw_attr_val.v.val_str = node;
   32824              :     }
   32825          548 : }
   32826              : 
   32827              : /* Output stuff that dwarf requires at the end of every file,
   32828              :    and generate the DWARF-2 debugging info.  */
   32829              : 
   32830              : static void
   32831        53550 : dwarf2out_finish (const char *filename)
   32832              : {
   32833        53550 :   comdat_type_node *ctnode;
   32834        53550 :   dw_die_ref main_comp_unit_die;
   32835        53550 :   unsigned char checksum[16];
   32836        53550 :   char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
   32837              : 
   32838              :   /* Generate CTF/BTF debug info.  */
   32839        53550 :   if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
   32840        53550 :        || btf_debuginfo_p ()) && lang_GNU_C ())
   32841          291 :     ctf_debug_finish ();
   32842              : 
   32843              : #ifdef CODEVIEW_DEBUGGING_INFO
   32844              :   if (codeview_debuginfo_p ())
   32845              :     codeview_debug_finish ();
   32846              : #endif
   32847              : 
   32848              :   /* Skip emitting DWARF if not required.  */
   32849        53550 :   if (!dwarf_debuginfo_p ())
   32850          315 :     return;
   32851              : 
   32852              :   /* Flush out any latecomers to the limbo party.  */
   32853        53235 :   flush_limbo_die_list ();
   32854              : 
   32855        53235 :   if (btf_tag_htab)
   32856           16 :     btf_tag_htab->empty ();
   32857              : 
   32858        53235 :   if (inline_entry_data_table)
   32859        13468 :     gcc_assert (inline_entry_data_table->is_empty ());
   32860              : 
   32861        53235 :   if (flag_checking)
   32862              :     {
   32863        53234 :       verify_die (comp_unit_die ());
   32864        53234 :       for (limbo_die_node *node = cu_die_list; node; node = node->next)
   32865            0 :         verify_die (node->die);
   32866              :     }
   32867              : 
   32868              :   /* We shouldn't have any symbols with delayed asm names for
   32869              :      DIEs generated after early finish.  */
   32870        53235 :   gcc_assert (deferred_asm_name == NULL);
   32871              : 
   32872        53235 :   gen_remaining_tmpl_value_param_die_attribute ();
   32873              : 
   32874        53235 :   if (flag_generate_lto || flag_generate_offload)
   32875              :     {
   32876          558 :       gcc_assert (flag_fat_lto_objects || flag_generate_offload);
   32877              : 
   32878              :       /* Prune stuff so that dwarf2out_finish runs successfully
   32879              :          for the fat part of the object.  */
   32880          558 :       reset_dies (comp_unit_die ());
   32881          558 :       for (limbo_die_node *node = cu_die_list; node; node = node->next)
   32882            0 :         reset_dies (node->die);
   32883          560 :       for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   32884              :         {
   32885              :           /* Remove the pointer to the line table.  */
   32886            2 :           remove_AT (ctnode->root_die, DW_AT_stmt_list);
   32887            2 :           if (debug_info_level >= DINFO_LEVEL_TERSE)
   32888            2 :             reset_dies (ctnode->root_die);
   32889              :         }
   32890              : 
   32891              :       /* Reset die CU symbol so we don't output it twice.  */
   32892          558 :       comp_unit_die ()->die_id.die_symbol = NULL;
   32893              : 
   32894              :       /* Remove DW_AT_macro and DW_AT_stmt_list from the early output.  */
   32895          558 :       remove_AT (comp_unit_die (), DW_AT_stmt_list);
   32896          558 :       if (have_macinfo)
   32897            6 :         remove_AT (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE);
   32898              : 
   32899              :       /* Remove indirect string decisions.  */
   32900        19544 :       debug_str_hash->traverse<void *, reset_indirect_string> (NULL);
   32901          558 :       if (debug_line_str_hash)
   32902              :         {
   32903          548 :           debug_line_str_hash->traverse<void *, reset_indirect_string> (NULL);
   32904          548 :           debug_line_str_hash = NULL;
   32905          548 :           if (asm_outputs_debug_line_str ())
   32906              :             {
   32907          548 :               adjust_name_comp_dir (comp_unit_die ());
   32908          548 :               for (limbo_die_node *node = cu_die_list; node; node = node->next)
   32909            0 :                 adjust_name_comp_dir (node->die);
   32910              :             }
   32911              :         }
   32912              :     }
   32913              : 
   32914              : #if ENABLE_ASSERT_CHECKING
   32915        53235 :   {
   32916        53235 :     dw_die_ref die = comp_unit_die (), c;
   32917     10060131 :     FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
   32918              :   }
   32919              : #endif
   32920        53235 :   base_types.truncate (0);
   32921        53312 :   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   32922           77 :     resolve_addr (ctnode->root_die);
   32923        53235 :   resolve_addr (comp_unit_die ());
   32924        53235 :   move_marked_base_types ();
   32925              : 
   32926        53235 :   if (dump_file)
   32927              :     {
   32928            4 :       fprintf (dump_file, "DWARF for %s\n", filename);
   32929            4 :       print_die (comp_unit_die (), dump_file);
   32930              :     }
   32931              : 
   32932              :   /* Initialize sections and labels used for actual assembler output.  */
   32933        53235 :   unsigned generation = init_sections_and_labels (false);
   32934              : 
   32935              :   /* Traverse the DIE's and add sibling attributes to those DIE's that
   32936              :      have children.  */
   32937        53235 :   add_sibling_attributes (comp_unit_die ());
   32938        53235 :   limbo_die_node *node;
   32939        53235 :   for (node = cu_die_list; node; node = node->next)
   32940            0 :     add_sibling_attributes (node->die);
   32941        53312 :   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   32942           77 :     add_sibling_attributes (ctnode->root_die);
   32943              : 
   32944              :   /* When splitting DWARF info, we put some attributes in the
   32945              :      skeleton compile_unit DIE that remains in the .o, while
   32946              :      most attributes go in the DWO compile_unit_die.  */
   32947        53235 :   if (dwarf_split_debug_info)
   32948              :     {
   32949          249 :       limbo_die_node *cu;
   32950          249 :       main_comp_unit_die = gen_compile_unit_die (NULL);
   32951          249 :       if (dwarf_version >= 5)
   32952          248 :         main_comp_unit_die->die_tag = DW_TAG_skeleton_unit;
   32953          249 :       cu = limbo_die_list;
   32954          249 :       gcc_assert (cu->die == main_comp_unit_die);
   32955          249 :       limbo_die_list = limbo_die_list->next;
   32956          249 :       cu->next = cu_die_list;
   32957          249 :       cu_die_list = cu;
   32958              :     }
   32959              :   else
   32960        52986 :     main_comp_unit_die = comp_unit_die ();
   32961              : 
   32962              :   /* Output a terminator label for the .text section.  */
   32963        53235 :   switch_to_section (text_section);
   32964        53235 :   targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
   32965        53235 :   if (cold_text_section)
   32966              :     {
   32967         9320 :       switch_to_section (cold_text_section);
   32968         9320 :       targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
   32969              :     }
   32970              : 
   32971              :   /* We can only use the low/high_pc attributes if all of the code was
   32972              :      in .text.  */
   32973        53235 :   if ((!have_multiple_function_sections
   32974        23855 :        && vec_safe_length (switch_text_ranges) < 2)
   32975        53235 :       || (dwarf_version < 3 && dwarf_strict))
   32976              :     {
   32977        23855 :       const char *end_label = text_end_label;
   32978        23855 :       if (vec_safe_length (switch_text_ranges) == 1)
   32979          102 :         end_label = (*switch_text_ranges)[0];
   32980              :       /* Don't add if the CU has no associated code.  */
   32981        23855 :       if (switch_text_ranges)
   32982        19234 :         add_AT_low_high_pc (main_comp_unit_die, text_section_label,
   32983              :                             end_label, true);
   32984              :     }
   32985              :   else
   32986              :     {
   32987        29380 :       unsigned fde_idx;
   32988        29380 :       dw_fde_ref fde;
   32989        29380 :       bool range_list_added = false;
   32990        29380 :       if (switch_text_ranges)
   32991              :         {
   32992              :           const char *prev_loc = text_section_label;
   32993              :           const char *loc;
   32994              :           unsigned idx;
   32995              : 
   32996        10380 :           FOR_EACH_VEC_ELT (*switch_text_ranges, idx, loc)
   32997            0 :             if (prev_loc)
   32998              :               {
   32999            0 :                 add_ranges_by_labels (main_comp_unit_die, prev_loc,
   33000              :                                       loc, &range_list_added, true);
   33001            0 :                 prev_loc = NULL;
   33002              :               }
   33003              :             else
   33004              :               prev_loc = loc;
   33005              : 
   33006        10380 :           if (prev_loc)
   33007        10380 :             add_ranges_by_labels (main_comp_unit_die, prev_loc,
   33008              :                                   text_end_label, &range_list_added, true);
   33009              :         }
   33010              : 
   33011        29380 :       if (switch_cold_ranges)
   33012              :         {
   33013              :           const char *prev_loc = cold_text_section_label;
   33014              :           const char *loc;
   33015              :           unsigned idx;
   33016              : 
   33017         9320 :           FOR_EACH_VEC_ELT (*switch_cold_ranges, idx, loc)
   33018            0 :             if (prev_loc)
   33019              :               {
   33020            0 :                 add_ranges_by_labels (main_comp_unit_die, prev_loc,
   33021              :                                       loc, &range_list_added, true);
   33022            0 :                 prev_loc = NULL;
   33023              :               }
   33024              :             else
   33025              :               prev_loc = loc;
   33026              : 
   33027         9320 :           if (prev_loc)
   33028         9320 :             add_ranges_by_labels (main_comp_unit_die, prev_loc,
   33029              :                                   cold_end_label, &range_list_added, true);
   33030              :         }
   33031              : 
   33032       300656 :       FOR_EACH_VEC_ELT (*fde_vec, fde_idx, fde)
   33033              :         {
   33034       271276 :           if (fde->ignored_debug)
   33035         2546 :             continue;
   33036       268730 :           if (!fde->in_std_section)
   33037       195616 :             add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_begin,
   33038              :                                   fde->dw_fde_end, &range_list_added,
   33039              :                                   true);
   33040       268730 :           if (fde->dw_fde_second_begin && !fde->second_in_std_section)
   33041        10541 :             add_ranges_by_labels (main_comp_unit_die, fde->dw_fde_second_begin,
   33042              :                                   fde->dw_fde_second_end, &range_list_added,
   33043              :                                   true);
   33044              :         }
   33045              : 
   33046        29380 :       if (range_list_added)
   33047              :         {
   33048              :           /* We need to give .debug_loc and .debug_ranges an appropriate
   33049              :              "base address".  Use zero so that these addresses become
   33050              :              absolute.  Historically, we've emitted the unexpected
   33051              :              DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
   33052              :              Emit both to give time for other tools to adapt.  */
   33053        29380 :           add_AT_addr (main_comp_unit_die, DW_AT_low_pc, const0_rtx, true);
   33054        29380 :           if (! dwarf_strict && dwarf_version < 4)
   33055          428 :             add_AT_addr (main_comp_unit_die, DW_AT_entry_pc, const0_rtx, true);
   33056              : 
   33057        29380 :           add_ranges (NULL);
   33058        29380 :           have_multiple_function_sections = true;
   33059              :         }
   33060              :     }
   33061              : 
   33062              :   /* AIX Assembler inserts the length, so adjust the reference to match the
   33063              :      offset expected by debuggers.  */
   33064        53235 :   strcpy (dl_section_ref, debug_line_section_label);
   33065        53235 :   if (XCOFF_DEBUGGING_INFO)
   33066              :     strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
   33067              : 
   33068        53235 :   if (debug_info_level >= DINFO_LEVEL_TERSE)
   33069        53235 :     add_AT_lineptr (main_comp_unit_die, DW_AT_stmt_list,
   33070              :                     dl_section_ref);
   33071              : 
   33072        53235 :   if (have_macinfo)
   33073         1003 :     add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
   33074              :                    macinfo_section_label);
   33075              : 
   33076        53235 :   if (dwarf_split_debug_info)
   33077              :     {
   33078          249 :       if (have_location_lists)
   33079              :         {
   33080              :           /* Since we generate the loclists in the split DWARF .dwo
   33081              :              file itself, we don't need to generate a loclists_base
   33082              :              attribute for the split compile unit DIE.  That attribute
   33083              :              (and using relocatable sec_offset FORMs) isn't allowed
   33084              :              for a split compile unit.  Only if the .debug_loclists
   33085              :              section was in the main file, would we need to generate a
   33086              :              loclists_base attribute here (for the full or skeleton
   33087              :              unit DIE).  */
   33088              : 
   33089              :           /* optimize_location_lists calculates the size of the lists,
   33090              :              so index them first, and assign indices to the entries.
   33091              :              Although optimize_location_lists will remove entries from
   33092              :              the table, it only does so for duplicates, and therefore
   33093              :              only reduces ref_counts to 1.  */
   33094            2 :           index_location_lists (comp_unit_die ());
   33095              :         }
   33096              : 
   33097          249 :       if (dwarf_version >= 5 && !vec_safe_is_empty (ranges_table))
   33098            3 :         index_rnglists ();
   33099              : 
   33100          249 :       if (addr_index_table != NULL)
   33101              :         {
   33102          244 :           unsigned int index = 0;
   33103          244 :           addr_index_table
   33104              :             ->traverse_noresize<unsigned int *, index_addr_table_entry>
   33105          508 :             (&index);
   33106              :         }
   33107              :     }
   33108              : 
   33109        53235 :   loc_list_idx = 0;
   33110        53235 :   if (have_location_lists)
   33111              :     {
   33112        33655 :       optimize_location_lists (comp_unit_die ());
   33113              :       /* And finally assign indexes to the entries for -gsplit-dwarf.  */
   33114        33655 :       if (dwarf_version >= 5 && dwarf_split_debug_info)
   33115            2 :         assign_location_list_indexes (comp_unit_die ());
   33116              :     }
   33117              : 
   33118        53235 :   save_macinfo_strings ();
   33119              : 
   33120        53235 :   if (dwarf_split_debug_info)
   33121              :     {
   33122          249 :       unsigned int index = 0;
   33123              : 
   33124              :       /* Add attributes common to skeleton compile_units and
   33125              :          type_units.  Because these attributes include strings, it
   33126              :          must be done before freezing the string table.  Top-level
   33127              :          skeleton die attrs are added when the skeleton type unit is
   33128              :          created, so ensure it is created by this point.  */
   33129          249 :       add_top_level_skeleton_die_attrs (main_comp_unit_die);
   33130         3176 :       debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
   33131              :     }
   33132              : 
   33133              :   /* Output all of the compilation units.  We put the main one last so that
   33134              :      the offsets are available to output_pubnames.  */
   33135        53484 :   for (node = cu_die_list; node; node = node->next)
   33136          249 :     output_comp_unit (node->die, 0, NULL);
   33137              : 
   33138        53235 :   hash_table<comdat_type_hasher> comdat_type_table (100);
   33139        53312 :   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   33140              :     {
   33141           77 :       comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
   33142              : 
   33143              :       /* Don't output duplicate types.  */
   33144           77 :       if (*slot != HTAB_EMPTY_ENTRY)
   33145            1 :         continue;
   33146              : 
   33147              :       /* Add a pointer to the line table for the main compilation unit
   33148              :          so that the debugger can make sense of DW_AT_decl_file
   33149              :          attributes.  */
   33150           76 :       if (debug_info_level >= DINFO_LEVEL_TERSE)
   33151           76 :         add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
   33152           76 :                         (!dwarf_split_debug_info
   33153              :                          ? dl_section_ref
   33154              :                          : debug_skeleton_line_section_label));
   33155              : 
   33156           76 :       output_comdat_type_unit (ctnode, false);
   33157           76 :       *slot = ctnode;
   33158              :     }
   33159              : 
   33160        53235 :   if (dwarf_split_debug_info)
   33161              :     {
   33162          249 :       int mark;
   33163          249 :       struct md5_ctx ctx;
   33164              : 
   33165              :       /* Compute a checksum of the comp_unit to use as the dwo_id.  */
   33166          249 :       md5_init_ctx (&ctx);
   33167          249 :       mark = 0;
   33168          249 :       die_checksum (comp_unit_die (), &ctx, &mark);
   33169          249 :       unmark_all_dies (comp_unit_die ());
   33170          249 :       md5_finish_ctx (&ctx, checksum);
   33171              : 
   33172          249 :       if (dwarf_version < 5)
   33173              :         {
   33174              :           /* Use the first 8 bytes of the checksum as the dwo_id,
   33175              :              and add it to both comp-unit DIEs.  */
   33176            1 :           add_AT_data8 (main_comp_unit_die, DW_AT_GNU_dwo_id, checksum);
   33177            1 :           add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id, checksum);
   33178              :         }
   33179              : 
   33180              :       /* Add the base offset of the ranges table to the skeleton
   33181              :         comp-unit DIE.  */
   33182          249 :       if (!vec_safe_is_empty (ranges_table))
   33183              :         {
   33184            3 :           if (dwarf_version < 5)
   33185            0 :             add_AT_lineptr (main_comp_unit_die, DW_AT_GNU_ranges_base,
   33186              :                             ranges_section_label);
   33187              :         }
   33188              : 
   33189          249 :       output_addr_table ();
   33190              :     }
   33191              : 
   33192              :   /* Output the main compilation unit if non-empty or if .debug_macinfo
   33193              :      or .debug_macro will be emitted.  */
   33194       105957 :   output_comp_unit (comp_unit_die (), have_macinfo,
   33195        53235 :                     dwarf_split_debug_info ? checksum : NULL);
   33196              : 
   33197        53235 :   if (dwarf_split_debug_info && info_section_emitted)
   33198          249 :     output_skeleton_debug_sections (main_comp_unit_die, checksum);
   33199              : 
   33200              :   /* Output the abbreviation table.  */
   33201        53235 :   if (vec_safe_length (abbrev_die_table) != 1)
   33202              :     {
   33203        52185 :       switch_to_section (debug_abbrev_section);
   33204        52185 :       ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
   33205        52185 :       output_abbrev_section ();
   33206              :     }
   33207              : 
   33208              :   /* Output location list section if necessary.  */
   33209        53235 :   if (have_location_lists)
   33210              :     {
   33211        33655 :       char l1[MAX_ARTIFICIAL_LABEL_BYTES];
   33212        33655 :       char l2[MAX_ARTIFICIAL_LABEL_BYTES];
   33213              :       /* Output the location lists info.  */
   33214        33655 :       switch_to_section (debug_loc_section);
   33215        33655 :       if (dwarf_version >= 5)
   33216              :         {
   33217        32621 :           ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_LOC_SECTION_LABEL, 2);
   33218        32621 :           ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_LOC_SECTION_LABEL, 3);
   33219        32621 :           if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
   33220            0 :             dw2_asm_output_data (4, 0xffffffff,
   33221              :                                  "Initial length escape value indicating "
   33222              :                                  "64-bit DWARF extension");
   33223        32621 :           dw2_asm_output_delta (dwarf_offset_size, l2, l1,
   33224              :                             "Length of Location Lists");
   33225        32621 :           ASM_OUTPUT_LABEL (asm_out_file, l1);
   33226        32621 :           output_dwarf_version ();
   33227        36578 :           dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
   33228        32621 :           dw2_asm_output_data (1, 0, "Segment Size");
   33229        32621 :           dw2_asm_output_data (4, dwarf_split_debug_info ? loc_list_idx : 0,
   33230              :                                "Offset Entry Count");
   33231              :         }
   33232        33655 :       ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
   33233        33655 :       if (dwarf_version >= 5 && dwarf_split_debug_info)
   33234              :         {
   33235            2 :           unsigned int save_loc_list_idx = loc_list_idx;
   33236            2 :           loc_list_idx = 0;
   33237            2 :           output_loclists_offsets (comp_unit_die ());
   33238            2 :           gcc_assert (save_loc_list_idx == loc_list_idx);
   33239              :         }
   33240        33655 :       output_location_lists (comp_unit_die ());
   33241        33655 :       if (dwarf_version >= 5)
   33242        32621 :         ASM_OUTPUT_LABEL (asm_out_file, l2);
   33243              :     }
   33244              : 
   33245        53235 :   output_pubtables ();
   33246              : 
   33247              :   /* Output the address range information if a CU (.debug_info section)
   33248              :      was emitted.  We output an empty table even if we had no functions
   33249              :      to put in it.  This because the consumer has no way to tell the
   33250              :      difference between an empty table that we omitted and failure to
   33251              :      generate a table that would have contained data.  */
   33252        53235 :   if (info_section_emitted)
   33253              :     {
   33254        52183 :       switch_to_section (debug_aranges_section);
   33255        52183 :       output_aranges ();
   33256              :     }
   33257              : 
   33258              :   /* Output ranges section if necessary.  */
   33259        53235 :   if (!vec_safe_is_empty (ranges_table))
   33260              :     {
   33261        34170 :       if (dwarf_version >= 5)
   33262              :         {
   33263        33648 :           if (dwarf_split_debug_info)
   33264              :             {
   33265              :               /* We don't know right now whether there are any
   33266              :                  ranges for .debug_rnglists and any for .debug_rnglists.dwo.
   33267              :                  Depending on into which of those two belongs the first
   33268              :                  ranges_table entry, emit that section first and that
   33269              :                  output_rnglists call will return true if the other kind of
   33270              :                  ranges needs to be emitted as well.  */
   33271            3 :               bool dwo = (*ranges_table)[0].idx != DW_RANGES_IDX_SKELETON;
   33272            3 :               if (output_rnglists (generation, dwo))
   33273            2 :                 output_rnglists (generation, !dwo);
   33274              :             }
   33275              :           else
   33276        33645 :             output_rnglists (generation, false);
   33277              :         }
   33278              :       else
   33279          522 :         output_ranges ();
   33280              :     }
   33281              : 
   33282              :   /* Have to end the macro section.  */
   33283        53235 :   if (have_macinfo)
   33284              :     {
   33285          513 :       switch_to_section (debug_macinfo_section);
   33286          513 :       ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
   33287          517 :       output_macinfo (!dwarf_split_debug_info ? debug_line_section_label
   33288              :                       : debug_skeleton_line_section_label, false);
   33289          513 :       dw2_asm_output_data (1, 0, "End compilation unit");
   33290              :     }
   33291              : 
   33292              :   /* Output the source line correspondence table.  We must do this
   33293              :      even if there is no line information.  Otherwise, on an empty
   33294              :      translation unit, we will generate a present, but empty,
   33295              :      .debug_info section.  IRIX 6.5 `nm' will then complain when
   33296              :      examining the file.  This is done late so that any filenames
   33297              :      used by the debug_info section are marked as 'used'.  */
   33298        53235 :   switch_to_section (debug_line_section);
   33299        53235 :   ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
   33300        53235 :   if (! output_asm_line_debug_info ())
   33301            6 :     output_line_info (false);
   33302              : 
   33303        53235 :   if (dwarf_split_debug_info && info_section_emitted)
   33304              :     {
   33305          249 :       switch_to_section (debug_skeleton_line_section);
   33306          249 :       ASM_OUTPUT_LABEL (asm_out_file, debug_skeleton_line_section_label);
   33307          249 :       output_line_info (true);
   33308              :     }
   33309              : 
   33310              :   /* If we emitted any indirect strings, output the string table too.  */
   33311        53235 :   if (debug_str_hash || skeleton_debug_str_hash)
   33312        53235 :     output_indirect_strings ();
   33313        53235 :   if (debug_line_str_hash)
   33314              :     {
   33315        51010 :       switch_to_section (debug_line_str_section);
   33316        51010 :       const enum dwarf_form form = DW_FORM_line_strp;
   33317        51010 :       debug_line_str_hash->traverse<enum dwarf_form,
   33318        51010 :                                     output_indirect_string> (form);
   33319              :     }
   33320              : 
   33321              :   /* ??? Move lvugid out of dwarf2out_source_line and reset it too?  */
   33322        53235 :   symview_upper_bound = 0;
   33323        53235 :   if (zero_view_p)
   33324        42239 :     bitmap_clear (zero_view_p);
   33325        53235 : }
   33326              : 
   33327              : /* Returns a hash value for X (which really is a variable_value_struct).  */
   33328              : 
   33329              : inline hashval_t
   33330         4700 : variable_value_hasher::hash (variable_value_struct *x)
   33331              : {
   33332         4700 :   return (hashval_t) x->decl_id;
   33333              : }
   33334              : 
   33335              : /* Return true if decl_id of variable_value_struct X is the same as
   33336              :    UID of decl Y.  */
   33337              : 
   33338              : inline bool
   33339         5250 : variable_value_hasher::equal (variable_value_struct *x, tree y)
   33340              : {
   33341         5250 :   return x->decl_id == DECL_UID (y);
   33342              : }
   33343              : 
   33344              : /* Helper function for resolve_variable_value, handle
   33345              :    DW_OP_GNU_variable_value in one location expression.
   33346              :    Return true if exprloc has been changed into loclist.  */
   33347              : 
   33348              : static bool
   33349          610 : resolve_variable_value_in_expr (dw_attr_node *a, dw_loc_descr_ref loc)
   33350              : {
   33351          610 :   dw_loc_descr_ref next;
   33352         2088 :   for (dw_loc_descr_ref prev = NULL; loc; prev = loc, loc = next)
   33353              :     {
   33354         1481 :       next = loc->dw_loc_next;
   33355         1481 :       if (loc->dw_loc_opc != DW_OP_GNU_variable_value
   33356          600 :           || loc->dw_loc_oprnd1.val_class != dw_val_class_decl_ref)
   33357          881 :         continue;
   33358              : 
   33359          600 :       tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
   33360          600 :       if (DECL_CONTEXT (decl) != current_function_decl)
   33361            0 :         continue;
   33362              : 
   33363          600 :       dw_die_ref ref = lookup_decl_die (decl);
   33364          600 :       if (ref)
   33365              :         {
   33366            0 :           loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   33367            0 :           loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
   33368            0 :           loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
   33369            0 :           continue;
   33370              :         }
   33371          600 :       dw_loc_list_ref l = loc_list_from_tree (decl, 0, NULL);
   33372          600 :       if (l == NULL)
   33373          125 :         continue;
   33374          475 :       if (l->dw_loc_next)
   33375              :         {
   33376          248 :           if (AT_class (a) != dw_val_class_loc)
   33377            0 :             continue;
   33378          248 :           switch (a->dw_attr)
   33379              :             {
   33380              :             /* Following attributes allow both exprloc and loclist
   33381              :                classes, so we can change them into a loclist.  */
   33382            3 :             case DW_AT_location:
   33383            3 :             case DW_AT_string_length:
   33384            3 :             case DW_AT_return_addr:
   33385            3 :             case DW_AT_data_member_location:
   33386            3 :             case DW_AT_frame_base:
   33387            3 :             case DW_AT_segment:
   33388            3 :             case DW_AT_static_link:
   33389            3 :             case DW_AT_use_location:
   33390            3 :             case DW_AT_vtable_elem_location:
   33391            3 :               if (prev)
   33392              :                 {
   33393            0 :                   prev->dw_loc_next = NULL;
   33394            0 :                   prepend_loc_descr_to_each (l, AT_loc (a));
   33395              :                 }
   33396            3 :               if (next)
   33397            3 :                 add_loc_descr_to_each (l, next);
   33398            3 :               a->dw_attr_val.val_class = dw_val_class_loc_list;
   33399            3 :               a->dw_attr_val.val_entry = NULL;
   33400            3 :               a->dw_attr_val.v.val_loc_list = l;
   33401            3 :               have_location_lists = true;
   33402            3 :               return true;
   33403              :             /* Following attributes allow both exprloc and reference,
   33404              :                so if the whole expression is DW_OP_GNU_variable_value alone
   33405              :                we could transform it into reference.  */
   33406          245 :             case DW_AT_byte_size:
   33407          245 :             case DW_AT_bit_size:
   33408          245 :             case DW_AT_lower_bound:
   33409          245 :             case DW_AT_upper_bound:
   33410          245 :             case DW_AT_bit_stride:
   33411          245 :             case DW_AT_count:
   33412          245 :             case DW_AT_allocated:
   33413          245 :             case DW_AT_associated:
   33414          245 :             case DW_AT_byte_stride:
   33415          245 :               if (prev == NULL && next == NULL)
   33416              :                 break;
   33417              :               /* FALLTHRU */
   33418            0 :             default:
   33419            0 :               if (dwarf_strict)
   33420            0 :                 continue;
   33421              :               break;
   33422              :             }
   33423              :           /* Create DW_TAG_variable that we can refer to.  */
   33424          245 :           gen_decl_die (decl, NULL_TREE, NULL,
   33425              :                         lookup_decl_die (current_function_decl));
   33426          245 :           ref = lookup_decl_die (decl);
   33427          245 :           if (ref)
   33428              :             {
   33429          245 :               loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   33430          245 :               loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
   33431          245 :               loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
   33432              :             }
   33433          245 :           continue;
   33434              :         }
   33435          227 :       if (prev)
   33436              :         {
   33437            0 :           prev->dw_loc_next = l->expr;
   33438            0 :           add_loc_descr (&prev->dw_loc_next, next);
   33439            0 :           free_loc_descr (loc, NULL);
   33440            0 :           next = prev->dw_loc_next;
   33441              :         }
   33442              :       else
   33443              :         {
   33444          227 :           memcpy (loc, l->expr, sizeof (dw_loc_descr_node));
   33445          227 :           add_loc_descr (&loc, next);
   33446          227 :           next = loc;
   33447              :         }
   33448          227 :       loc = prev;
   33449              :     }
   33450              :   return false;
   33451              : }
   33452              : 
   33453              : /* Attempt to resolve DW_OP_GNU_variable_value using loc_list_from_tree.  */
   33454              : 
   33455              : static void
   33456          600 : resolve_variable_value (dw_die_ref die)
   33457              : {
   33458          600 :   dw_attr_node *a;
   33459          600 :   dw_loc_list_ref loc;
   33460          600 :   unsigned ix;
   33461              : 
   33462         1896 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   33463         1296 :     switch (AT_class (a))
   33464              :       {
   33465          600 :       case dw_val_class_loc:
   33466          600 :         if (!resolve_variable_value_in_expr (a, AT_loc (a)))
   33467              :           break;
   33468              :         /* FALLTHRU */
   33469            3 :       case dw_val_class_loc_list:
   33470            3 :         loc = AT_loc_list (a);
   33471            3 :         gcc_assert (loc);
   33472           13 :         for (; loc; loc = loc->dw_loc_next)
   33473           10 :           resolve_variable_value_in_expr (a, loc->expr);
   33474              :         break;
   33475              :       default:
   33476              :         break;
   33477              :       }
   33478          600 : }
   33479              : 
   33480              : /* Attempt to optimize DW_OP_GNU_variable_value referring to
   33481              :    temporaries in the current function.  */
   33482              : 
   33483              : static void
   33484       575999 : resolve_variable_values (void)
   33485              : {
   33486       575999 :   if (!variable_value_hash || !current_function_decl)
   33487              :     return;
   33488              : 
   33489         2465 :   struct variable_value_struct *node
   33490         2465 :     = variable_value_hash->find_with_hash (current_function_decl,
   33491         2465 :                                            DECL_UID (current_function_decl));
   33492              : 
   33493         2465 :   if (node == NULL)
   33494              :     return;
   33495              : 
   33496              :   unsigned int i;
   33497              :   dw_die_ref die;
   33498         1056 :   FOR_EACH_VEC_SAFE_ELT (node->dies, i, die)
   33499          600 :     resolve_variable_value (die);
   33500              : }
   33501              : 
   33502              : /* Helper function for note_variable_value, handle one location
   33503              :    expression.  */
   33504              : 
   33505              : static void
   33506       124696 : note_variable_value_in_expr (dw_die_ref die, dw_loc_descr_ref loc)
   33507              : {
   33508       370916 :   for (; loc; loc = loc->dw_loc_next)
   33509       246220 :     if (loc->dw_loc_opc == DW_OP_GNU_variable_value
   33510         5459 :         && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
   33511              :       {
   33512          770 :         tree decl = loc->dw_loc_oprnd1.v.val_decl_ref;
   33513          770 :         dw_die_ref ref = lookup_decl_die (decl);
   33514          770 :         if (! ref && (flag_generate_lto || flag_generate_offload))
   33515              :           {
   33516              :             /* ???  This is somewhat a hack because we do not create DIEs
   33517              :                for variables not in BLOCK trees early but when generating
   33518              :                early LTO output we need the dw_val_class_decl_ref to be
   33519              :                fully resolved.  For fat LTO objects we'd also like to
   33520              :                undo this after LTO dwarf output.  */
   33521           67 :             gcc_assert (DECL_CONTEXT (decl));
   33522           67 :             dw_die_ref ctx = lookup_decl_die (DECL_CONTEXT (decl));
   33523           67 :             gcc_assert (ctx != NULL);
   33524           67 :             gen_decl_die (decl, NULL_TREE, NULL, ctx);
   33525           67 :             ref = lookup_decl_die (decl);
   33526           67 :             gcc_assert (ref != NULL);
   33527              :           }
   33528          770 :         if (ref)
   33529              :           {
   33530           67 :             loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
   33531           67 :             loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
   33532           67 :             loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
   33533           67 :             continue;
   33534              :           }
   33535          703 :         if (VAR_P (decl)
   33536          703 :             && DECL_CONTEXT (decl)
   33537          703 :             && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL
   33538         1406 :             && lookup_decl_die (DECL_CONTEXT (decl)))
   33539              :           {
   33540          703 :             if (!variable_value_hash)
   33541          400 :               variable_value_hash
   33542          400 :                 = hash_table<variable_value_hasher>::create_ggc (10);
   33543              : 
   33544          703 :             tree fndecl = DECL_CONTEXT (decl);
   33545          703 :             struct variable_value_struct *node;
   33546          703 :             struct variable_value_struct **slot
   33547         2109 :               = variable_value_hash->find_slot_with_hash (fndecl,
   33548          703 :                                                           DECL_UID (fndecl),
   33549              :                                                           INSERT);
   33550          703 :             if (*slot == NULL)
   33551              :               {
   33552          547 :                 node = ggc_cleared_alloc<variable_value_struct> ();
   33553          547 :                 node->decl_id = DECL_UID (fndecl);
   33554          547 :                 *slot = node;
   33555              :               }
   33556              :             else
   33557              :               node = *slot;
   33558              : 
   33559          703 :             vec_safe_push (node->dies, die);
   33560              :           }
   33561              :       }
   33562       124696 : }
   33563              : 
   33564              : /* Walk the tree DIE and note DIEs with DW_OP_GNU_variable_value still
   33565              :    with dw_val_class_decl_ref operand.  */
   33566              : 
   33567              : static void
   33568     56895932 : note_variable_value (dw_die_ref die)
   33569              : {
   33570     56895932 :   dw_die_ref c;
   33571     56895932 :   dw_attr_node *a;
   33572     56895932 :   dw_loc_list_ref loc;
   33573     56895932 :   unsigned ix;
   33574              : 
   33575    262063850 :   FOR_EACH_VEC_SAFE_ELT (die->die_attr, ix, a)
   33576    205167918 :     switch (AT_class (a))
   33577              :       {
   33578            0 :       case dw_val_class_loc_list:
   33579            0 :         loc = AT_loc_list (a);
   33580            0 :         gcc_assert (loc);
   33581            0 :         if (!loc->noted_variable_value)
   33582              :           {
   33583            0 :             loc->noted_variable_value = 1;
   33584            0 :             for (; loc; loc = loc->dw_loc_next)
   33585            0 :               note_variable_value_in_expr (die, loc->expr);
   33586              :           }
   33587              :         break;
   33588       124696 :       case dw_val_class_loc:
   33589       124696 :         note_variable_value_in_expr (die, AT_loc (a));
   33590       124696 :         break;
   33591              :       default:
   33592              :         break;
   33593              :       }
   33594              : 
   33595              :   /* Mark children.  */
   33596    113738188 :   FOR_EACH_CHILD (die, c, note_variable_value (c));
   33597     56895932 : }
   33598              : 
   33599              : /* Process DWARF dies for CTF generation.  */
   33600              : 
   33601              : static void
   33602          293 : ctf_debug_do_cu (dw_die_ref die)
   33603              : {
   33604          293 :   dw_die_ref c;
   33605              : 
   33606          293 :   if (!ctf_do_die (die))
   33607              :     return;
   33608              : 
   33609         1602 :   FOR_EACH_CHILD (die, c, ctf_do_die (c));
   33610              : }
   33611              : 
   33612              : /* Perform any cleanups needed after the early debug generation pass
   33613              :    has run.  */
   33614              : 
   33615              : static void
   33616        54358 : dwarf2out_early_finish (const char *filename)
   33617              : {
   33618        54358 :   comdat_type_node *ctnode;
   33619        54358 :   set_early_dwarf s;
   33620        54358 :   char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
   33621              : 
   33622              :   /* PCH might result in DW_AT_producer string being restored from the
   33623              :      header compilation, so always fill it with empty string initially
   33624              :      and overwrite only here.  */
   33625        54358 :   dw_attr_node *producer = get_AT (comp_unit_die (), DW_AT_producer);
   33626              : 
   33627        54358 :   if (dwarf_record_gcc_switches)
   33628        53827 :     producer_string = gen_producer_string (lang_hooks.name,
   33629              :                                            save_decoded_options,
   33630              :                                            save_decoded_options_count);
   33631              :   else
   33632          531 :     producer_string = concat (lang_hooks.name, " ", version_string, NULL);
   33633              : 
   33634        54358 :   producer->dw_attr_val.v.val_str->refcount--;
   33635        54358 :   producer->dw_attr_val.v.val_str = find_AT_string (producer_string);
   33636              : 
   33637              :   /* Add the name for the main input file now.  We delayed this from
   33638              :      dwarf2out_init to avoid complications with PCH.  */
   33639        54358 :   add_filename_attribute (comp_unit_die (), remap_debug_filename (filename));
   33640        54358 :   add_comp_dir_attribute (comp_unit_die ());
   33641              : 
   33642              :   /* With LTO early dwarf was really finished at compile-time, so make
   33643              :      sure to adjust the phase after annotating the LTRANS CU DIE.  */
   33644        54358 :   if (in_lto_p)
   33645              :     {
   33646          763 :       early_dwarf_finished = true;
   33647          763 :       if (dump_file)
   33648              :         {
   33649            0 :           fprintf (dump_file, "LTO EARLY DWARF for %s\n", filename);
   33650            0 :           print_die (comp_unit_die (), dump_file);
   33651              :         }
   33652              :       return;
   33653              :     }
   33654              : 
   33655              :   /* Walk through the list of incomplete types again, trying once more to
   33656              :      emit full debugging info for them.  */
   33657        53595 :   retry_incomplete_types ();
   33658              : 
   33659        53595 :   gen_scheduled_generic_parms_dies ();
   33660        53595 :   gen_remaining_tmpl_value_param_die_attribute ();
   33661              : 
   33662              :   /* The point here is to flush out the limbo list so that it is empty
   33663              :      and we don't need to stream it for LTO.  */
   33664        53595 :   flush_limbo_die_list ();
   33665              : 
   33666              :   /* Add DW_AT_linkage_name for all deferred DIEs.  */
   33667    118801857 :   for (limbo_die_node *node = deferred_asm_name; node; node = node->next)
   33668              :     {
   33669    118748262 :       tree decl = node->created_for;
   33670    118748262 :       if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
   33671              :           /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
   33672              :              ended up in deferred_asm_name before we knew it was
   33673              :              constant and never written to disk.  */
   33674    118748262 :           && DECL_ASSEMBLER_NAME (decl))
   33675              :         {
   33676    117048907 :           add_linkage_attr (node->die, decl);
   33677    117048907 :           move_linkage_attr (node->die);
   33678              :         }
   33679              :     }
   33680        53595 :   deferred_asm_name = NULL;
   33681              : 
   33682        53595 :   if (flag_eliminate_unused_debug_types)
   33683        53592 :     prune_unused_types ();
   33684              : 
   33685              :   /* Generate separate COMDAT sections for type DIEs. */
   33686        53595 :   if (use_debug_types)
   33687              :     {
   33688           36 :       break_out_comdat_types (comp_unit_die ());
   33689              : 
   33690              :       /* Each new type_unit DIE was added to the limbo die list when created.
   33691              :          Since these have all been added to comdat_type_list, clear the
   33692              :          limbo die list.  */
   33693           36 :       limbo_die_list = NULL;
   33694              : 
   33695              :       /* For each new comdat type unit, copy declarations for incomplete
   33696              :          types to make the new unit self-contained (i.e., no direct
   33697              :          references to the main compile unit).  */
   33698          117 :       for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   33699           81 :         copy_decls_for_unworthy_types (ctnode->root_die);
   33700           36 :       copy_decls_for_unworthy_types (comp_unit_die ());
   33701              : 
   33702              :       /* In the process of copying declarations from one unit to another,
   33703              :          we may have left some declarations behind that are no longer
   33704              :          referenced.  Prune them.  */
   33705           36 :       prune_unused_types ();
   33706              :     }
   33707              : 
   33708              :   /* Traverse the DIE's and note DIEs with DW_OP_GNU_variable_value still
   33709              :      with dw_val_class_decl_ref operand.  */
   33710        53595 :   note_variable_value (comp_unit_die ());
   33711        53595 :   for (limbo_die_node *node = cu_die_list; node; node = node->next)
   33712            0 :     note_variable_value (node->die);
   33713        53676 :   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   33714           81 :     note_variable_value (ctnode->root_die);
   33715        53595 :   for (limbo_die_node *node = limbo_die_list; node; node = node->next)
   33716            0 :     note_variable_value (node->die);
   33717              : 
   33718              :   /* The AT_pubnames attribute needs to go in all skeleton dies, including
   33719              :      both the main_cu and all skeleton TUs.  Making this call unconditional
   33720              :      would end up either adding a second copy of the AT_pubnames attribute, or
   33721              :      requiring a special case in add_top_level_skeleton_die_attrs.  */
   33722        53595 :   if (!dwarf_split_debug_info)
   33723        53346 :     add_AT_pubnames (comp_unit_die ());
   33724              : 
   33725              :   /* The early debug phase is now finished.  */
   33726        53595 :   early_dwarf_finished = true;
   33727        53595 :   if (dump_file)
   33728              :     {
   33729            4 :       fprintf (dump_file, "EARLY DWARF for %s\n", filename);
   33730            4 :       print_die (comp_unit_die (), dump_file);
   33731              :     }
   33732              : 
   33733              :   /* Generate CTF/BTF debug info.  */
   33734        53595 :   if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
   33735        53595 :        || btf_debuginfo_p ()) && lang_GNU_C ())
   33736              :     {
   33737          293 :       ctf_debug_init ();
   33738          293 :       ctf_debug_do_cu (comp_unit_die ());
   33739          293 :       for (limbo_die_node *node = limbo_die_list; node; node = node->next)
   33740            0 :         ctf_debug_do_cu (node->die);
   33741              : 
   33742          293 :       ctf_debug_early_finish (filename);
   33743              :     }
   33744              : 
   33745              : #ifdef CODEVIEW_DEBUGGING_INFO
   33746              :   if (codeview_debuginfo_p ())
   33747              :     codeview_debug_early_finish (comp_unit_die ());
   33748              : #endif
   33749              : 
   33750              :   /* Do not generate DWARF assembler now when not producing LTO bytecode.  */
   33751        53595 :   if ((!flag_generate_lto && !flag_generate_offload)
   33752              :       /* FIXME: Disable debug info generation for (PE-)COFF targets since the
   33753              :          copy_lto_debug_sections operation of the simple object support in
   33754              :          libiberty is not implemented for them yet.  */
   33755              :       || TARGET_PECOFF || TARGET_COFF)
   33756              :     return;
   33757              : 
   33758              :   /* Now as we are going to output for LTO initialize sections and labels
   33759              :      to the LTO variants.  We don't need a random-seed postfix as other
   33760              :      LTO sections as linking the LTO debug sections into one in a partial
   33761              :      link is fine.  */
   33762         1338 :   init_sections_and_labels (true);
   33763              : 
   33764              :   /* The output below is modeled after dwarf2out_finish with all
   33765              :      location related output removed and some LTO specific changes.
   33766              :      Some refactoring might make both smaller and easier to match up.  */
   33767              : 
   33768         1338 :   base_types.truncate (0);
   33769         1344 :   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   33770            6 :     mark_base_types (ctnode->root_die);
   33771         1338 :   mark_base_types (comp_unit_die ());
   33772         1338 :   move_marked_base_types ();
   33773              : 
   33774              :   /* Traverse the DIE's and add sibling attributes to those DIE's
   33775              :      that have children.  */
   33776         1338 :   add_sibling_attributes (comp_unit_die ());
   33777         1338 :   for (limbo_die_node *node = limbo_die_list; node; node = node->next)
   33778            0 :     add_sibling_attributes (node->die);
   33779         1344 :   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   33780            6 :     add_sibling_attributes (ctnode->root_die);
   33781              : 
   33782              :   /* AIX Assembler inserts the length, so adjust the reference to match the
   33783              :      offset expected by debuggers.  */
   33784         1338 :   strcpy (dl_section_ref, debug_line_section_label);
   33785         1338 :   if (XCOFF_DEBUGGING_INFO)
   33786              :     strcat (dl_section_ref, DWARF_INITIAL_LENGTH_SIZE_STR);
   33787              : 
   33788         1338 :   if (debug_info_level >= DINFO_LEVEL_TERSE)
   33789         1338 :     add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list, dl_section_ref);
   33790              : 
   33791         1338 :   if (have_macinfo)
   33792           30 :     add_AT_macptr (comp_unit_die (), DEBUG_MACRO_ATTRIBUTE,
   33793              :                    macinfo_section_label);
   33794              : 
   33795         1338 :   save_macinfo_strings ();
   33796              : 
   33797         1338 :   if (dwarf_split_debug_info)
   33798              :     {
   33799            0 :       unsigned int index = 0;
   33800            0 :       debug_str_hash->traverse_noresize<unsigned int *, index_string> (&index);
   33801              :     }
   33802              : 
   33803              :   /* Output all of the compilation units.  We put the main one last so that
   33804              :      the offsets are available to output_pubnames.  */
   33805         1338 :   for (limbo_die_node *node = limbo_die_list; node; node = node->next)
   33806            0 :     output_comp_unit (node->die, 0, NULL);
   33807              : 
   33808         1338 :   hash_table<comdat_type_hasher> comdat_type_table (100);
   33809         1344 :   for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
   33810              :     {
   33811            6 :       comdat_type_node **slot = comdat_type_table.find_slot (ctnode, INSERT);
   33812              : 
   33813              :       /* Don't output duplicate types.  */
   33814            6 :       if (*slot != HTAB_EMPTY_ENTRY)
   33815            1 :         continue;
   33816              : 
   33817              :       /* Add a pointer to the line table for the main compilation unit
   33818              :          so that the debugger can make sense of DW_AT_decl_file
   33819              :          attributes.  */
   33820            5 :       if (debug_info_level >= DINFO_LEVEL_TERSE)
   33821            5 :         add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
   33822            5 :                         (!dwarf_split_debug_info
   33823              :                          ? debug_line_section_label
   33824              :                          : debug_skeleton_line_section_label));
   33825              : 
   33826            5 :       output_comdat_type_unit (ctnode, true);
   33827            5 :       *slot = ctnode;
   33828              :     }
   33829              : 
   33830              :   /* Stick a unique symbol to the main debuginfo section.  */
   33831         1338 :   compute_comp_unit_symbol (comp_unit_die ());
   33832              : 
   33833              :   /* Output the main compilation unit.  We always need it if only for
   33834              :      the CU symbol.  */
   33835         1338 :   output_comp_unit (comp_unit_die (), true, NULL);
   33836              : 
   33837              :   /* Output the abbreviation table.  */
   33838         1338 :   if (vec_safe_length (abbrev_die_table) != 1)
   33839              :     {
   33840         1338 :       switch_to_section (debug_abbrev_section);
   33841         1338 :       ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
   33842         1338 :       output_abbrev_section ();
   33843              :     }
   33844              : 
   33845              :   /* Have to end the macro section.  */
   33846         1338 :   if (have_macinfo)
   33847              :     {
   33848              :       /* We have to save macinfo state if we need to output it again
   33849              :          for the FAT part of the object.  */
   33850           15 :       vec<macinfo_entry, va_gc> *saved_macinfo_table = macinfo_table;
   33851           15 :       if (flag_fat_lto_objects)
   33852            3 :         macinfo_table = macinfo_table->copy ();
   33853              : 
   33854           15 :       switch_to_section (debug_macinfo_section);
   33855           15 :       ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
   33856           15 :       output_macinfo (debug_line_section_label, true);
   33857           15 :       dw2_asm_output_data (1, 0, "End compilation unit");
   33858              : 
   33859           15 :       if (flag_fat_lto_objects)
   33860              :         {
   33861            3 :           vec_free (macinfo_table);
   33862            3 :           macinfo_table = saved_macinfo_table;
   33863              :         }
   33864              :     }
   33865              : 
   33866              :   /* Emit a skeleton debug_line section.  */
   33867         1338 :   switch_to_section (debug_line_section);
   33868         1338 :   ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
   33869         1338 :   output_line_info (true);
   33870              : 
   33871              :   /* If we emitted any indirect strings, output the string table too.  */
   33872         1338 :   if (debug_str_hash || skeleton_debug_str_hash)
   33873         1338 :     output_indirect_strings ();
   33874         1338 :   if (debug_line_str_hash)
   33875              :     {
   33876         1291 :       switch_to_section (debug_line_str_section);
   33877         1291 :       const enum dwarf_form form = DW_FORM_line_strp;
   33878         1291 :       debug_line_str_hash->traverse<enum dwarf_form,
   33879         1291 :                                     output_indirect_string> (form);
   33880              :     }
   33881              : 
   33882              :   /* Switch back to the text section.  */
   33883         1338 :   switch_to_section (text_section);
   33884        54358 : }
   33885              : 
   33886              : /* Reset all state within dwarf2out.cc so that we can rerun the compiler
   33887              :    within the same process.  For use by toplev::finalize.  */
   33888              : 
   33889              : void
   33890       264541 : dwarf2out_cc_finalize (void)
   33891              : {
   33892       264541 :   last_var_location_insn = NULL;
   33893       264541 :   cached_next_real_insn = NULL;
   33894       264541 :   used_rtx_array = NULL;
   33895       264541 :   incomplete_types = NULL;
   33896       264541 :   debug_info_section = NULL;
   33897       264541 :   debug_skeleton_info_section = NULL;
   33898       264541 :   debug_abbrev_section = NULL;
   33899       264541 :   debug_skeleton_abbrev_section = NULL;
   33900       264541 :   debug_aranges_section = NULL;
   33901       264541 :   debug_addr_section = NULL;
   33902       264541 :   debug_macinfo_section = NULL;
   33903       264541 :   debug_line_section = NULL;
   33904       264541 :   debug_skeleton_line_section = NULL;
   33905       264541 :   debug_loc_section = NULL;
   33906       264541 :   debug_pubnames_section = NULL;
   33907       264541 :   debug_pubtypes_section = NULL;
   33908       264541 :   debug_str_section = NULL;
   33909       264541 :   debug_line_str_section = NULL;
   33910       264541 :   debug_str_dwo_section = NULL;
   33911       264541 :   debug_str_offsets_section = NULL;
   33912       264541 :   debug_ranges_section = NULL;
   33913       264541 :   debug_ranges_dwo_section = NULL;
   33914       264541 :   debug_frame_section = NULL;
   33915       264541 :   fde_vec = NULL;
   33916       264541 :   debug_str_hash = NULL;
   33917       264541 :   debug_line_str_hash = NULL;
   33918       264541 :   skeleton_debug_str_hash = NULL;
   33919       264541 :   dw2_string_counter = 0;
   33920       264541 :   have_multiple_function_sections = false;
   33921       264541 :   in_text_section_p = false;
   33922       264541 :   cold_text_section = NULL;
   33923       264541 :   last_text_label = NULL;
   33924       264541 :   last_cold_label = NULL;
   33925       264541 :   switch_text_ranges = NULL;
   33926       264541 :   switch_cold_ranges = NULL;
   33927       264541 :   current_unit_personality = NULL;
   33928       264541 :   btf_tag_htab = NULL;
   33929              : 
   33930       264541 :   early_dwarf = false;
   33931       264541 :   early_dwarf_finished = false;
   33932              : 
   33933       264541 :   next_die_offset = 0;
   33934       264541 :   single_comp_unit_die = NULL;
   33935       264541 :   comdat_type_list = NULL;
   33936       264541 :   limbo_die_list = NULL;
   33937       264541 :   file_table = NULL;
   33938       264541 :   decl_die_table = NULL;
   33939       264541 :   common_block_die_table = NULL;
   33940       264541 :   decl_loc_table = NULL;
   33941       264541 :   call_arg_locations = NULL;
   33942       264541 :   call_arg_loc_last = NULL;
   33943       264541 :   call_site_count = -1;
   33944       264541 :   tail_call_site_count = -1;
   33945       264541 :   cached_dw_loc_list_table = NULL;
   33946       264541 :   abbrev_die_table = NULL;
   33947       319050 :   delete dwarf_proc_stack_usage_map;
   33948       264541 :   dwarf_proc_stack_usage_map = NULL;
   33949       264541 :   line_info_label_num = 0;
   33950       264541 :   cur_line_info_table = NULL;
   33951       264541 :   text_section_line_info = NULL;
   33952       264541 :   cold_text_section_line_info = NULL;
   33953       264541 :   separate_line_info = NULL;
   33954       264541 :   info_section_emitted = false;
   33955       264541 :   pubname_table = NULL;
   33956       264541 :   pubtype_table = NULL;
   33957       264541 :   macinfo_table = NULL;
   33958       264541 :   ranges_table = NULL;
   33959       264541 :   ranges_by_label = NULL;
   33960       264541 :   rnglist_idx = 0;
   33961       264541 :   have_location_lists = false;
   33962       264541 :   loclabel_num = 0;
   33963       264541 :   poc_label_num = 0;
   33964       264541 :   last_emitted_file = NULL;
   33965       264541 :   label_num = 0;
   33966       264541 :   tmpl_value_parm_die_table = NULL;
   33967       264541 :   generic_type_instances = NULL;
   33968       264541 :   frame_pointer_fb_offset = 0;
   33969       264541 :   frame_pointer_fb_offset_valid = false;
   33970       264541 :   base_types.release ();
   33971       264541 :   XDELETEVEC (producer_string);
   33972       264541 :   producer_string = NULL;
   33973       264541 :   output_line_info_generation = 0;
   33974       264541 :   init_sections_and_labels_generation = 0;
   33975       264541 : }
   33976              : 
   33977              : #include "gt-dwarf2out.h"
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.