]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/dwarf2out.c
dwarf2out: Emit DW_AT_location for global register vars during early dwarf [PR101905]
[gcc.git] / gcc / dwarf2out.c
index 77317ed2575ad32205631f1438c2ad74b703068b..ecf01120381394f3c848077442702ee7b18f51d0 100644 (file)
@@ -1,5 +1,5 @@
 /* Output Dwarf2 format symbol table information from GCC.
-   Copyright (C) 1992-2018 Free Software Foundation, Inc.
+   Copyright (C) 1992-2020 Free Software Foundation, Inc.
    Contributed by Gary Funck (gary@intrepid.com).
    Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
    Extensively modified by Jason Merrill (jason@cygnus.com).
@@ -399,6 +399,9 @@ get_full_len (const wide_int &op)
 static bool
 should_emit_struct_debug (tree type, enum debug_info_usage usage)
 {
+  if (debug_info_level <= DINFO_LEVEL_TERSE)
+    return false;
+
   enum debug_struct_file criterion;
   tree type_decl;
   bool generic = lang_hooks.types.generic_p (type);
@@ -969,6 +972,8 @@ dwarf2out_do_cfi_startproc (bool second)
 
   fprintf (asm_out_file, "\t.cfi_startproc\n");
 
+  targetm.asm_out.post_cfi_startproc (asm_out_file, current_function_decl);
+
   /* .cfi_personality and .cfi_lsda are only relevant to DWARF2
      eh unwinders.  */
   if (targetm_common.except_unwind_info (&global_options) != UI_DWARF2)
@@ -1113,7 +1118,7 @@ dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
         function anymore.  */
       if (personality && current_unit_personality != personality)
        sorry ("multiple EH personalities are supported only with assemblers "
-              "supporting .cfi_personality directive");
+              "supporting %<.cfi_personality%> directive");
     }
 }
 
@@ -1474,7 +1479,7 @@ dw_val_equal_p (dw_val_node *a, dw_val_node *b)
 
     case dw_val_class_vms_delta:
       return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)
-              && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1));
+             && !strcmp (a->v.val_vms_delta.lbl2, b->v.val_vms_delta.lbl2));
 
     case dw_val_class_discr_value:
       return (a->v.val_discr_value.pos == b->v.val_discr_value.pos
@@ -2912,9 +2917,13 @@ const struct gcc_debug_hooks dwarf2_lineno_debug_hooks =
    separate comdat sections since the linker will then be able to
    remove duplicates.  But not all tools support .debug_types sections
    yet.  For Dwarf V5 or higher .debug_types doesn't exist any more,
-   it is DW_UT_type unit type in .debug_info section.  */
+   it is DW_UT_type unit type in .debug_info section.  For late LTO
+   debug there should be almost no types emitted so avoid enabling
+   -fdebug-types-section there.  */
 
-#define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
+#define use_debug_types (dwarf_version >= 4 \
+                        && flag_debug_types_section \
+                        && !in_lto_p)
 
 /* Various DIE's use offsets relative to the beginning of the
    .debug_info section to refer to each other.  */
@@ -3098,7 +3107,8 @@ die_node;
 /* Set to TRUE while dwarf2out_early_global_decl is running.  */
 static bool early_dwarf;
 static bool early_dwarf_finished;
-struct set_early_dwarf {
+class set_early_dwarf {
+public:
   bool saved;
   set_early_dwarf () : saved(early_dwarf)
     {
@@ -3649,7 +3659,6 @@ static void add_AT_specification (dw_die_ref, dw_die_ref);
 static inline dw_die_ref AT_ref (dw_attr_node *);
 static inline int AT_ref_external (dw_attr_node *);
 static inline void set_AT_ref_external (dw_attr_node *, int);
-static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
 static inline dw_loc_descr_ref AT_loc (dw_attr_node *);
 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
@@ -3665,20 +3674,16 @@ static void add_AT_symview (dw_die_ref, enum dwarf_attribute, const char *);
 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
-static void add_AT_loclistsptr (dw_die_ref, enum dwarf_attribute,
-                               const char *);
-static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
-                          unsigned HOST_WIDE_INT);
 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
                                unsigned long, bool);
 static inline const char *AT_lbl (dw_attr_node *);
 static dw_attr_node *get_AT (dw_die_ref, enum dwarf_attribute);
 static const char *get_AT_low_pc (dw_die_ref);
-static const char *get_AT_hi_pc (dw_die_ref);
 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
+static bool is_c (void);
 static bool is_cxx (void);
 static bool is_cxx (const_tree);
 static bool is_fortran (void);
@@ -3715,7 +3720,6 @@ static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
 static int same_attr_p (dw_attr_node *, dw_attr_node *, int *);
 static int same_die_p (dw_die_ref, dw_die_ref, int *);
 static int is_type_die (dw_die_ref);
-static int is_comdat_die (dw_die_ref);
 static inline bool is_template_instantiation (dw_die_ref);
 static int is_declaration_die (dw_die_ref);
 static int should_move_die_to_comdat (dw_die_ref);
@@ -3750,7 +3754,7 @@ static void output_die_abbrevs (unsigned long, dw_die_ref);
 static void output_die (dw_die_ref);
 static void output_compilation_unit_header (enum dwarf_unit_type);
 static void output_comp_unit (dw_die_ref, int, const unsigned char *);
-static void output_comdat_type_unit (comdat_type_node *);
+static void output_comdat_type_unit (comdat_type_node *, bool);
 static const char *dwarf2_name (tree, int);
 static void add_pubname (tree, dw_die_ref);
 static void add_enumerator_pubname (const char *, dw_die_ref);
@@ -3772,7 +3776,6 @@ static int decl_quals (const_tree);
 static dw_die_ref modified_type_die (tree, int, bool, dw_die_ref);
 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
-static int type_is_enum (const_tree);
 static unsigned int dbx_reg_number (const_rtx);
 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
@@ -3795,7 +3798,6 @@ static dw_loc_list_ref loc_list_from_tree (tree, int,
                                           struct loc_descr_context *);
 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
                                                  struct loc_descr_context *);
-static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
 static tree field_type (const_tree);
 static unsigned int simple_type_align_in_bits (const_tree);
 static unsigned int simple_decl_align_in_bits (const_tree);
@@ -3810,12 +3812,13 @@ static void add_data_member_location_attribute (dw_die_ref, tree,
 static bool add_const_value_attribute (dw_die_ref, rtx);
 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
 static void insert_wide_int (const wide_int &, unsigned char *, int);
-static void insert_float (const_rtx, unsigned char *);
+static unsigned insert_float (const_rtx, unsigned char *);
 static rtx rtl_for_decl_location (tree);
 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
 static bool tree_add_const_value_attribute (dw_die_ref, tree);
 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
 static void add_name_attribute (dw_die_ref, const char *);
+static void add_desc_attribute (dw_die_ref, tree);
 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
 static void add_comp_dir_attribute (dw_die_ref);
 static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
@@ -3829,7 +3832,7 @@ static inline void add_bit_offset_attribute (dw_die_ref, tree,
                                             struct vlr_context *);
 static void add_bit_size_attribute (dw_die_ref, tree);
 static void add_prototyped_attribute (dw_die_ref, tree);
-static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
+static void add_abstract_origin_attribute (dw_die_ref, tree);
 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
 static void add_src_coords_attributes (dw_die_ref, tree);
 static void add_name_and_src_coords_attributes (dw_die_ref, tree, bool = false);
@@ -3874,7 +3877,7 @@ static void gen_subroutine_type_die (tree, dw_die_ref);
 static void gen_typedef_die (tree, dw_die_ref);
 static void gen_type_die (tree, dw_die_ref);
 static void gen_block_die (tree, dw_die_ref);
-static void decls_for_scope (tree, dw_die_ref);
+static void decls_for_scope (tree, dw_die_ref, bool = true);
 static bool is_naming_typedef_decl (const_tree);
 static inline dw_die_ref get_context_die (tree);
 static void gen_namespace_die (tree, dw_die_ref);
@@ -4625,12 +4628,13 @@ indirect_string_hasher::equal (indirect_string_node *x1, const char *x2)
 
 static struct indirect_string_node *
 find_AT_string_in_table (const char *str,
-                        hash_table<indirect_string_hasher> *table)
+                        hash_table<indirect_string_hasher> *table,
+                        enum insert_option insert = INSERT)
 {
   struct indirect_string_node *node;
 
   indirect_string_node **slot
-    = table->find_slot_with_hash (str, htab_hash_string (str), INSERT);
+    = table->find_slot_with_hash (str, htab_hash_string (str), insert);
   if (*slot == NULL)
     {
       node = ggc_cleared_alloc<indirect_string_node> ();
@@ -4647,12 +4651,12 @@ find_AT_string_in_table (const char *str,
 /* Add STR to the indirect string hash table.  */
 
 static struct indirect_string_node *
-find_AT_string (const char *str)
+find_AT_string (const char *str, enum insert_option insert = INSERT)
 {
   if (! debug_str_hash)
     debug_str_hash = hash_table<indirect_string_hasher>::create_ggc (10);
 
-  return find_AT_string_in_table (str, debug_str_hash);
+  return find_AT_string_in_table (str, debug_str_hash, insert);
 }
 
 /* Add a string attribute value to a DIE.  */
@@ -4834,20 +4838,6 @@ set_AT_ref_external (dw_attr_node *a, int i)
   a->dw_attr_val.v.val_die_ref.external = i;
 }
 
-/* Add an FDE reference attribute value to a DIE.  */
-
-static inline void
-add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
-{
-  dw_attr_node attr;
-
-  attr.dw_attr = attr_kind;
-  attr.dw_attr_val.val_class = dw_val_class_fde_ref;
-  attr.dw_attr_val.val_entry = NULL;
-  attr.dw_attr_val.v.val_fde_index = targ_fde;
-  add_dwarf_attr (die, &attr);
-}
-
 /* Add a location description attribute value to a DIE.  */
 
 static inline void
@@ -5224,22 +5214,6 @@ add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
   add_dwarf_attr (die, &attr);
 }
 
-/* Add a section offset attribute value to a DIE, an offset into the
-   debug_loclists section.  */
-
-static inline void
-add_AT_loclistsptr (dw_die_ref die, enum dwarf_attribute attr_kind,
-                   const char *label)
-{
-  dw_attr_node attr;
-
-  attr.dw_attr = attr_kind;
-  attr.dw_attr_val.val_class = dw_val_class_loclistsptr;
-  attr.dw_attr_val.val_entry = NULL;
-  attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
-  add_dwarf_attr (die, &attr);
-}
-
 /* Add a section offset attribute value to a DIE, an offset into the
    debug_macinfo section.  */
 
@@ -5256,21 +5230,6 @@ add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
   add_dwarf_attr (die, &attr);
 }
 
-/* Add an offset attribute value to a DIE.  */
-
-static inline void
-add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
-              unsigned HOST_WIDE_INT offset)
-{
-  dw_attr_node attr;
-
-  attr.dw_attr = attr_kind;
-  attr.dw_attr_val.val_class = dw_val_class_offset;
-  attr.dw_attr_val.val_entry = NULL;
-  attr.dw_attr_val.v.val_offset = offset;
-  add_dwarf_attr (die, &attr);
-}
-
 /* Add a range_list attribute value to a DIE.  When using
    dwarf_split_debug_info, address attributes in dies destined for the
    final executable should be direct references--setting the parameter
@@ -5381,18 +5340,6 @@ get_AT_low_pc (dw_die_ref die)
   return a ? AT_lbl (a) : NULL;
 }
 
-/* Return the "high pc" attribute value, typically associated with a subprogram
-   DIE.  Return null if the "high pc" attribute is either not present, or if it
-   cannot be represented as an assembler label identifier.  */
-
-static inline const char *
-get_AT_hi_pc (dw_die_ref die)
-{
-  dw_attr_node *a = get_AT (die, DW_AT_high_pc);
-
-  return a ? AT_lbl (a) : NULL;
-}
-
 /* Return the value of the string attribute designated by ATTR_KIND, or
    NULL if it is not present.  */
 
@@ -5442,6 +5389,19 @@ get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
   return a ? AT_file (a) : NULL;
 }
 
+/* Return TRUE if the language is C.  */
+
+static inline bool
+is_c (void)
+{
+  unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
+
+  return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_C99
+         || lang == DW_LANG_C11 || lang == DW_LANG_ObjC);
+
+
+}
+
 /* Return TRUE if the language is C++.  */
 
 static inline bool
@@ -5506,6 +5466,16 @@ is_ada (void)
   return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
 }
 
+/* Return TRUE if the language is D.  */
+
+static inline bool
+is_dlang (void)
+{
+  unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
+
+  return lang == DW_LANG_D;
+}
+
 /* Remove the specified attribute if present.  Return TRUE if removal
    was successful.  */
 
@@ -5815,6 +5785,14 @@ equate_type_number_to_die (tree type, dw_die_ref type_die)
   TYPE_SYMTAB_DIE (type) = type_die;
 }
 
+static dw_die_ref maybe_create_die_with_external_ref (tree);
+struct GTY(()) sym_off_pair 
+{
+  const char * GTY((skip)) sym;
+  unsigned HOST_WIDE_INT off;
+};
+static GTY(()) hash_map<tree, sym_off_pair> *external_die_map;
+
 /* Returns a hash value for X (which really is a die_struct).  */
 
 inline hashval_t
@@ -5839,7 +5817,11 @@ lookup_decl_die (tree decl)
   dw_die_ref *die = decl_die_table->find_slot_with_hash (decl, DECL_UID (decl),
                                                         NO_INSERT);
   if (!die)
-    return NULL;
+    {
+      if (in_lto_p)
+       return maybe_create_die_with_external_ref (decl);
+      return NULL;
+    }
   if ((*die)->removed)
     {
       decl_die_table->clear_slot (die);
@@ -5849,6 +5831,27 @@ lookup_decl_die (tree decl)
 }
 
 
+/* Return the DIE associated with BLOCK.  */
+
+static inline dw_die_ref
+lookup_block_die (tree block)
+{
+  dw_die_ref die = BLOCK_DIE (block);
+  if (!die && in_lto_p)
+    return maybe_create_die_with_external_ref (block);
+  return die;
+}
+
+/* Associate DIE with BLOCK.  */
+
+static inline void
+equate_block_to_die (tree block, dw_die_ref die)
+{
+  BLOCK_DIE (block) = die;
+}
+#undef BLOCK_DIE
+
+
 /* For DECL which might have early dwarf output query a SYMBOL + OFFSET
    style reference.  Return true if we found one refering to a DIE for
    DECL, otherwise return false.  */
@@ -5859,32 +5862,27 @@ dwarf2out_die_ref_for_decl (tree decl, const char **sym,
 {
   dw_die_ref die;
 
-  if (in_lto_p && !decl_die_table)
-    return false;
+  if (in_lto_p)
+    {
+      /* During WPA stage and incremental linking we use a hash-map
+        to store the decl <-> label + offset map.  */
+      if (!external_die_map)
+       return false;
+      sym_off_pair *desc = external_die_map->get (decl);
+      if (!desc)
+       return false;
+      *sym = desc->sym;
+      *off = desc->off;
+      return true;
+    }
 
   if (TREE_CODE (decl) == BLOCK)
-    die = BLOCK_DIE (decl);
+    die = lookup_block_die (decl);
   else
     die = lookup_decl_die (decl);
   if (!die)
     return false;
 
-  /* During WPA stage and incremental linking we currently use DIEs
-     to store the decl <-> label + offset map.  That's quite inefficient
-     but it works for now.  */
-  if (in_lto_p)
-    {
-      dw_die_ref ref = get_AT_ref (die, DW_AT_abstract_origin);
-      if (!ref)
-       {
-         gcc_assert (die == comp_unit_die ());
-         return false;
-       }
-      *off = ref->die_offset;
-      *sym = ref->die_id.die_symbol;
-      return true;
-    }
-
   /* Similar to get_ref_die_offset_label, but using the "correct"
      label.  */
   *off = die->die_offset;
@@ -5906,8 +5904,10 @@ add_AT_external_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind,
 {
   /* Create a fake DIE that contains the reference.  Don't use
      new_die because we don't want to end up in the limbo list.  */
+  /* ???  We probably want to share these, thus put a ref to the DIE
+     we create here to the external_die_map entry.  */
   dw_die_ref ref = new_die_raw (die->die_tag);
-  ref->die_id.die_symbol = IDENTIFIER_POINTER (get_identifier (symbol));
+  ref->die_id.die_symbol = symbol;
   ref->die_offset = offset;
   ref->with_offset = 1;
   add_AT_die_ref (die, attr_kind, ref);
@@ -5923,13 +5923,33 @@ dwarf2out_register_external_die (tree decl, const char *sym,
   if (debug_info_level == DINFO_LEVEL_NONE)
     return;
 
-  if ((flag_wpa
-       || flag_incremental_link == INCREMENTAL_LINK_LTO) && !decl_die_table)
-    decl_die_table = hash_table<decl_die_hasher>::create_ggc (1000);
+  if (!external_die_map)
+    external_die_map = hash_map<tree, sym_off_pair>::create_ggc (1000);
+  gcc_checking_assert (!external_die_map->get (decl));
+  sym_off_pair p = { IDENTIFIER_POINTER (get_identifier (sym)), off };
+  external_die_map->put (decl, p);
+}
+
+/* If we have a registered external DIE for DECL return a new DIE for
+   the concrete instance with an appropriate abstract origin.  */
+
+static dw_die_ref
+maybe_create_die_with_external_ref (tree decl)
+{
+  if (!external_die_map)
+    return NULL;
+  sym_off_pair *desc = external_die_map->get (decl);
+  if (!desc)
+    return NULL;
+
+  const char *sym = desc->sym;
+  unsigned HOST_WIDE_INT off = desc->off;
 
-  dw_die_ref die
-    = TREE_CODE (decl) == BLOCK ? BLOCK_DIE (decl) : lookup_decl_die (decl);
+  in_lto_p = false;
+  dw_die_ref die = (TREE_CODE (decl) == BLOCK
+                   ? lookup_block_die (decl) : lookup_decl_die (decl));
   gcc_assert (!die);
+  in_lto_p = true;
 
   tree ctx;
   dw_die_ref parent = NULL;
@@ -5941,7 +5961,7 @@ dwarf2out_register_external_die (tree decl, const char *sym,
       /* ???  We do not output DIEs for all scopes thus skip as
         many DIEs as needed.  */
       while (TREE_CODE (ctx) == BLOCK
-            && !BLOCK_DIE (ctx))
+            && !lookup_block_die (ctx))
        ctx = BLOCK_SUPERCONTEXT (ctx);
     }
   else
@@ -5956,7 +5976,7 @@ dwarf2out_register_external_die (tree decl, const char *sym,
   if (ctx)
     {
       if (TREE_CODE (ctx) == BLOCK)
-       parent = BLOCK_DIE (ctx);
+       parent = lookup_block_die (ctx);
       else if (TREE_CODE (ctx) == TRANSLATION_UNIT_DECL
               /* Keep the 1:1 association during WPA.  */
               && !flag_wpa
@@ -5983,18 +6003,12 @@ dwarf2out_register_external_die (tree decl, const char *sym,
   switch (TREE_CODE (decl))
     {
     case TRANSLATION_UNIT_DECL:
-      if (! flag_wpa && flag_incremental_link != INCREMENTAL_LINK_LTO)
-       {
-         die = comp_unit_die ();
-         dw_die_ref import = new_die (DW_TAG_imported_unit, die, NULL_TREE);
-         add_AT_external_die_ref (import, DW_AT_import, sym, off);
-         /* We re-target all CU decls to the LTRANS CU DIE, so no need
-            to create a DIE for the original CUs.  */
-         return;
-       }
-      /* Keep the 1:1 association during WPA.  */
-      die = new_die (DW_TAG_compile_unit, NULL, decl);
-      break;
+      {
+       die = comp_unit_die ();
+       /* We re-target all CU decls to the LTRANS CU DIE, so no need
+          to create a DIE for the original CUs.  */
+       return die;
+      }
     case NAMESPACE_DECL:
       if (is_fortran (decl))
        die = new_die (DW_TAG_module, parent, decl);
@@ -6026,12 +6040,16 @@ dwarf2out_register_external_die (tree decl, const char *sym,
       gcc_unreachable ();
     }
   if (TREE_CODE (decl) == BLOCK)
-    BLOCK_DIE (decl) = die;
+    equate_block_to_die (decl, die);
   else
     equate_decl_number_to_die (decl, die);
 
+  add_desc_attribute (die, decl);
+
   /* Add a reference to the DIE providing early debug at $sym + off.  */
   add_AT_external_die_ref (die, DW_AT_abstract_origin, sym, off);
+
+  return die;
 }
 
 /* Returns a hash value for X (which really is a var_loc_list).  */
@@ -7890,36 +7908,6 @@ is_type_die (dw_die_ref die)
     }
 }
 
-/* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
-   Basically, we want to choose the bits that are likely to be shared between
-   compilations (types) and leave out the bits that are specific to individual
-   compilations (functions).  */
-
-static int
-is_comdat_die (dw_die_ref c)
-{
-  /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
-     we do for stabs.  The advantage is a greater likelihood of sharing between
-     objects that don't include headers in the same order (and therefore would
-     put the base types in a different comdat).  jason 8/28/00 */
-
-  if (c->die_tag == DW_TAG_base_type)
-    return 0;
-
-  if (c->die_tag == DW_TAG_pointer_type
-      || c->die_tag == DW_TAG_reference_type
-      || c->die_tag == DW_TAG_rvalue_reference_type
-      || c->die_tag == DW_TAG_const_type
-      || c->die_tag == DW_TAG_volatile_type)
-    {
-      dw_die_ref t = get_AT_ref (c, DW_AT_type);
-
-      return t ? is_comdat_die (t) : 0;
-    }
-
-  return is_type_die (c);
-}
-
 /* Returns true iff C is a compile-unit DIE.  */
 
 static inline bool
@@ -7948,15 +7936,6 @@ is_namespace_die (dw_die_ref c)
   return c && c->die_tag == DW_TAG_namespace;
 }
 
-/* Returns true iff C is a class or structure DIE.  */
-
-static inline bool
-is_class_die (dw_die_ref c)
-{
-  return c && (c->die_tag == DW_TAG_class_type
-               || c->die_tag == DW_TAG_structure_type);
-}
-
 /* Return non-zero if this DIE is a template parameter.  */
 
 static inline bool
@@ -8216,6 +8195,11 @@ copy_ancestor_tree (dw_die_ref unit, dw_die_ref die,
   decl_table_entry **slot = NULL;
   struct decl_table_entry *entry = NULL;
 
+  /* If DIE refers to a stub unfold that so we get the appropriate
+     DIE registered as orig in decl_table.  */
+  if (dw_die_ref c = get_AT_ref (die, DW_AT_signature))
+    die = c;
+
   if (decl_table)
     {
       /* Check if the entry has already been copied to UNIT.  */
@@ -8596,11 +8580,12 @@ break_out_comdat_types (dw_die_ref die)
         /* Break out nested types into their own type units.  */
         break_out_comdat_types (c);
 
-        /* Create a new type unit DIE as the root for the new tree, and
-           add it to the list of comdat types.  */
+        /* Create a new type unit DIE as the root for the new tree.  */
         unit = new_die (DW_TAG_type_unit, NULL, NULL);
         add_AT_unsigned (unit, DW_AT_language,
                          get_AT_unsigned (comp_unit_die (), DW_AT_language));
+
+       /* Add the new unit's type DIE into the comdat type list.  */
         type_node = ggc_cleared_alloc<comdat_type_node> ();
         type_node->root_die = unit;
         type_node->next = comdat_type_list;
@@ -8769,6 +8754,33 @@ copy_decls_walk (dw_die_ref unit, dw_die_ref die, decl_hash_type *decl_table)
   FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
 }
 
+/* Collect skeleton dies in DIE created by break_out_comdat_types already
+   and record them in DECL_TABLE.  */
+
+static void
+collect_skeleton_dies (dw_die_ref die, decl_hash_type *decl_table)
+{
+  dw_die_ref c;
+
+  if (dw_attr_node *a = get_AT (die, DW_AT_signature))
+    {
+      dw_die_ref targ = AT_ref (a);
+      gcc_assert (targ->die_mark == 0 && targ->comdat_type_p);
+      decl_table_entry **slot
+        = decl_table->find_slot_with_hash (targ,
+                                          htab_hash_pointer (targ),
+                                          INSERT);
+      gcc_assert (*slot == HTAB_EMPTY_ENTRY);
+      /* Record in DECL_TABLE that TARG has been already copied
+        by remove_child_or_replace_with_skeleton.  */
+      decl_table_entry *entry = XCNEW (struct decl_table_entry);
+      entry->orig = targ;
+      entry->copy = die;
+      *slot = entry;
+    }
+  FOR_EACH_CHILD (die, c, collect_skeleton_dies (c, decl_table));
+}
+
 /* Copy declarations for "unworthy" types into the new comdat section.
    Incomplete types, modified types, and certain other types aren't broken
    out into comdat sections of their own, so they don't have a signature,
@@ -8780,6 +8792,7 @@ copy_decls_for_unworthy_types (dw_die_ref unit)
 {
   mark_dies (unit);
   decl_hash_type decl_table (10);
+  collect_skeleton_dies (unit, &decl_table);
   copy_decls_walk (unit, unit, &decl_table);
   unmark_dies (unit);
 }
@@ -9073,9 +9086,13 @@ build_abbrev_table (dw_die_ref die, external_ref_hash_type *extern_map)
        struct external_ref *ref_p;
        gcc_assert (AT_ref (a)->comdat_type_p || AT_ref (a)->die_id.die_symbol);
 
-       ref_p = lookup_external_ref (extern_map, c);
-       if (ref_p->stub && ref_p->stub != die)
-         change_AT_die_ref (a, ref_p->stub);
+       if (is_type_die (c)
+           && (ref_p = lookup_external_ref (extern_map, c))
+           && ref_p->stub && ref_p->stub != die)
+         {
+           gcc_assert (a->dw_attr != DW_AT_signature);
+           change_AT_die_ref (a, ref_p->stub);
+         }
        else
          /* We aren't changing this reference, so mark it external.  */
          set_AT_ref_external (a, 1);
@@ -9357,7 +9374,6 @@ size_of_die (dw_die_ref die)
          }
          break;
        case dw_val_class_loc_list:
-       case dw_val_class_view_list:
          if (dwarf_split_debug_info && dwarf_version >= 5)
            {
              gcc_assert (AT_loc_list (a)->num_assigned);
@@ -9366,6 +9382,9 @@ size_of_die (dw_die_ref die)
           else
             size += DWARF_OFFSET_SIZE;
          break;
+       case dw_val_class_view_list:
+         size += DWARF_OFFSET_SIZE;
+         break;
        case dw_val_class_range_list:
          if (value_format (a) == DW_FORM_rnglistx)
            {
@@ -9443,7 +9462,7 @@ size_of_die (dw_die_ref die)
                 we use DW_FORM_ref_addr.  In DWARF2, DW_FORM_ref_addr
                 is sized by target address length, whereas in DWARF3
                 it's always sized as an offset.  */
-             if (use_debug_types)
+             if (AT_ref (a)->comdat_type_p)
                size += DWARF_TYPE_SIGNATURE_SIZE;
              else if (dwarf_version == 2)
                size += DWARF2_ADDR_SIZE;
@@ -9739,12 +9758,12 @@ value_format (dw_attr_node *a)
          gcc_unreachable ();
        }
     case dw_val_class_loc_list:
-    case dw_val_class_view_list:
       if (dwarf_split_debug_info
          && dwarf_version >= 5
          && AT_loc_list (a)->num_assigned)
        return DW_FORM_loclistx;
       /* FALLTHRU */
+    case dw_val_class_view_list:
     case dw_val_class_range_list:
       /* For range lists in DWARF 5, use DW_FORM_rnglistx from .debug_info.dwo
         but in .debug_info use DW_FORM_sec_offset, which is shorter if we
@@ -9887,7 +9906,12 @@ value_format (dw_attr_node *a)
       return DW_FORM_flag;
     case dw_val_class_die_ref:
       if (AT_ref_external (a))
-       return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
+       {
+         if (AT_ref (a)->comdat_type_p)
+           return DW_FORM_ref_sig8;
+         else
+           return DW_FORM_ref_addr;
+       }
       else
        return DW_FORM_ref;
     case dw_val_class_fde_ref:
@@ -10965,8 +10989,8 @@ output_dwarf_version ()
       static bool once;
       if (!once)
        {
-         warning (0,
-                  "-gdwarf-6 is output as version 5 with incompatibilities");
+         warning (0, "%<-gdwarf-6%> is output as version 5 with "
+                  "incompatibilities");
          once = true;
        }
       dw2_asm_output_data (2, 5, "DWARF version number");
@@ -11120,7 +11144,9 @@ output_comp_unit (dw_die_ref die, int output_if_empty,
 static inline bool
 want_pubnames (void)
 {
-  if (debug_info_level <= DINFO_LEVEL_TERSE)
+  if (debug_info_level <= DINFO_LEVEL_TERSE
+      /* Names and types go to the early debug part only.  */
+      || in_lto_p)
     return false;
   if (debug_generate_pub_sections != -1)
     return debug_generate_pub_sections;
@@ -11174,7 +11200,8 @@ add_top_level_skeleton_die_attrs (dw_die_ref die)
   if (comp_dir != NULL)
     add_skeleton_AT_string (die, DW_AT_comp_dir, comp_dir);
   add_AT_pubnames (die);
-  add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label);
+  if (addr_index_table != NULL && addr_index_table->size () > 0)
+    add_AT_lineptr (die, dwarf_AT (DW_AT_addr_base), debug_addr_section_label);
 }
 
 /* Output skeleton debug sections that point to the dwo file.  */
@@ -11233,7 +11260,8 @@ output_skeleton_debug_sections (dw_die_ref comp_unit,
 /* Output a comdat type unit DIE and its children.  */
 
 static void
-output_comdat_type_unit (comdat_type_node *node)
+output_comdat_type_unit (comdat_type_node *node,
+                        bool early_lto_debug ATTRIBUTE_UNUSED)
 {
   const char *secname;
   char *tmp;
@@ -11260,14 +11288,16 @@ output_comdat_type_unit (comdat_type_node *node)
   if (dwarf_version >= 5)
     {
       if (!dwarf_split_debug_info)
-       secname = ".debug_info";
+       secname = early_lto_debug ? DEBUG_LTO_INFO_SECTION : DEBUG_INFO_SECTION;
       else
-       secname = ".debug_info.dwo";
+       secname = (early_lto_debug
+                  ? DEBUG_LTO_DWO_INFO_SECTION : DEBUG_DWO_INFO_SECTION);
     }
   else if (!dwarf_split_debug_info)
-    secname = ".debug_types";
+    secname = early_lto_debug ? ".gnu.debuglto_.debug_types" : ".debug_types";
   else
-    secname = ".debug_types.dwo";
+    secname = (early_lto_debug
+              ? ".gnu.debuglto_.debug_types.dwo" : ".debug_types.dwo");
 
   tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
   sprintf (tmp, dwarf_version >= 5 ? "wi." : "wt.");
@@ -12074,8 +12104,9 @@ file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
 
   fi = fnad->files + fnad->used_files++;
 
+  f = remap_debug_filename (d->filename);
+
   /* Skip all leading "./".  */
-  f = d->filename;
   while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
     f += 2;
 
@@ -13198,6 +13229,8 @@ modified_type_die (tree type, int cv_quals, bool reverse,
               && TYPE_PRECISION (sizetype) == TYPE_PRECISION (size_type_node)
               && TYPE_UNSIGNED (sizetype) == TYPE_UNSIGNED (size_type_node))
        qualified_type = size_type_node;
+      if (type == sizetype)
+       type = qualified_type;
     }
 
   /* If we do, then we can just use its DIE, if it exists.  */
@@ -13577,6 +13610,13 @@ generic_parameter_die (tree parm, tree arg,
   dw_die_ref tmpl_die = NULL;
   const char *name = NULL;
 
+  /* C++2a accepts class literals as template parameters, and var
+     decls with initializers represent them.  The VAR_DECLs would be
+     rejected, but we can take the DECL_INITIAL constructor and
+     attempt to expand it.  */
+  if (arg && VAR_P (arg))
+    arg = DECL_INITIAL (arg);
+
   if (!parm || !DECL_NAME (parm) || !arg)
     return NULL;
 
@@ -13686,15 +13726,6 @@ template_parameter_pack_die (tree parm_pack,
   return die;
 }
 
-/* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
-   an enumerated type.  */
-
-static inline int
-type_is_enum (const_tree type)
-{
-  return TREE_CODE (type) == ENUMERAL_TYPE;
-}
-
 /* Return the DBX register number described by a given RTL node.  */
 
 static unsigned int
@@ -14325,13 +14356,13 @@ based_loc_descr (rtx reg, poly_int64 offset,
 
       if (elim != reg)
        {
+         /* Allow hard frame pointer here even if frame pointer
+           isn't used since hard frame pointer is encoded with
+           DW_OP_fbreg which uses the DW_AT_frame_base attribute,
+           not hard frame pointer directly.  */
          elim = strip_offset_and_add (elim, &offset);
-         gcc_assert ((SUPPORTS_STACK_ALIGNMENT
-                      && (elim == hard_frame_pointer_rtx
-                          || elim == stack_pointer_rtx))
-                     || elim == (frame_pointer_needed
-                                 ? hard_frame_pointer_rtx
-                                 : stack_pointer_rtx));
+         gcc_assert (elim == hard_frame_pointer_rtx
+                     || elim == stack_pointer_rtx);
 
          /* If drap register is used to align stack, use frame
             pointer + offset to access stack variables.  If stack
@@ -14485,11 +14516,10 @@ const_ok_for_output_1 (rtx rtl)
                "non-delegitimized UNSPEC %s (%d) found in variable location",
                ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
                 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
-               XINT (rtl, 1));
 #else
                "non-delegitimized UNSPEC %d found in variable location",
-               XINT (rtl, 1));
 #endif
+               XINT (rtl, 1));
       expansion_failed (NULL_TREE, rtl,
                        "UNSPEC hasn't been delegitimized.\n");
       return false;
@@ -14498,13 +14528,6 @@ const_ok_for_output_1 (rtx rtl)
   if (CONST_POLY_INT_P (rtl))
     return false;
 
-  if (targetm.const_not_ok_for_debug_p (rtl))
-    {
-      expansion_failed (NULL_TREE, rtl,
-                       "Expression rejected for debug by the backend.\n");
-      return false;
-    }
-
   /* FIXME: Refer to PR60655. It is possible for simplification
      of rtl expressions in var tracking to produce such expressions.
      We should really identify / validate expressions
@@ -14517,6 +14540,41 @@ const_ok_for_output_1 (rtx rtl)
     case NOT:
     case NEG:
       return false;
+    case PLUS:
+      {
+       /* Make sure SYMBOL_REFs/UNSPECs are at most in one of the
+          operands.  */
+       subrtx_var_iterator::array_type array;
+       bool first = false;
+       FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 0), ALL)
+         if (SYMBOL_REF_P (*iter)
+             || LABEL_P (*iter)
+             || GET_CODE (*iter) == UNSPEC)
+           {
+             first = true;
+             break;
+           }
+       if (!first)
+         return true;
+       FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
+         if (SYMBOL_REF_P (*iter)
+             || LABEL_P (*iter)
+             || GET_CODE (*iter) == UNSPEC)
+           return false;
+       return true;
+      }
+    case MINUS:
+      {
+       /* Disallow negation of SYMBOL_REFs or UNSPECs when they
+          appear in the second operand of MINUS.  */
+       subrtx_var_iterator::array_type array;
+       FOR_EACH_SUBRTX_VAR (iter, array, XEXP (rtl, 1), ALL)
+         if (SYMBOL_REF_P (*iter)
+             || LABEL_P (*iter)
+             || GET_CODE (*iter) == UNSPEC)
+           return false;
+       return true;
+      }
     default:
       return true;
     }
@@ -15409,7 +15467,7 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
   if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
     return NULL;
 
-  scalar_int_mode int_mode, inner_mode, op1_mode;
+  scalar_int_mode int_mode = BImode, inner_mode, op1_mode;
   switch (GET_CODE (rtl))
     {
     case POST_INC:
@@ -15660,6 +15718,7 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
         pool.  */
     case CONST:
     case SYMBOL_REF:
+    case UNSPEC:
       if (!is_a <scalar_int_mode> (mode, &int_mode)
          || (GET_MODE_SIZE (int_mode) > DWARF2_ADDR_SIZE
 #ifdef POINTERS_EXTEND_UNSIGNED
@@ -15667,6 +15726,39 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
 #endif
              ))
        break;
+
+      if (GET_CODE (rtl) == UNSPEC)
+       {
+         /* If delegitimize_address couldn't do anything with the UNSPEC, we
+            can't express it in the debug info.  This can happen e.g. with some
+            TLS UNSPECs.  Allow UNSPECs formerly from CONST that the backend
+            approves.  */
+         bool not_ok = false;
+         subrtx_var_iterator::array_type array;
+         FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
+           if (*iter != rtl && !CONSTANT_P (*iter))
+             {
+               not_ok = true;
+               break;
+             }
+
+         if (not_ok)
+           break;
+
+         FOR_EACH_SUBRTX_VAR (iter, array, rtl, ALL)
+           if (!const_ok_for_output_1 (*iter))
+             {
+               not_ok = true;
+               break;
+             }
+
+         if (not_ok)
+           break;
+
+         rtl = gen_rtx_CONST (GET_MODE (rtl), rtl);
+         goto symref;
+       }
+
       if (GET_CODE (rtl) == SYMBOL_REF
          && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
        {
@@ -16072,11 +16164,12 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
              scalar_float_mode float_mode = as_a <scalar_float_mode> (mode);
              unsigned int length = GET_MODE_SIZE (float_mode);
              unsigned char *array = ggc_vec_alloc<unsigned char> (length);
+             unsigned int elt_size = insert_float (rtl, array);
 
-             insert_float (rtl, array);
              mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
-             mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
-             mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
+             mem_loc_result->dw_loc_oprnd2.v.val_vec.length
+               = length / elt_size;
+             mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
              mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
            }
        }
@@ -16335,7 +16428,6 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
     case VEC_CONCAT:
     case VEC_DUPLICATE:
     case VEC_SERIES:
-    case UNSPEC:
     case HIGH:
     case FMA:
     case STRICT_LOW_PART:
@@ -16343,10 +16435,6 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
     case CONST_FIXED:
     case CLRSB:
     case CLOBBER:
-    case CLOBBER_HIGH:
-      /* If delegitimize_address couldn't do anything with the UNSPEC, we
-        can't express it in the debug info.  This can happen e.g. with some
-        TLS UNSPECs.  */
       break;
 
     case CONST_STRING:
@@ -16651,11 +16739,11 @@ loc_descriptor (rtx rtl, machine_mode mode,
            {
              unsigned int length = GET_MODE_SIZE (smode);
              unsigned char *array = ggc_vec_alloc<unsigned char> (length);
+             unsigned int elt_size = insert_float (rtl, array);
 
-             insert_float (rtl, array);
              loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
-             loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
-             loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
+             loc_result->dw_loc_oprnd2.v.val_vec.length = length / elt_size;
+             loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
              loc_result->dw_loc_oprnd2.v.val_vec.array = array;
            }
        }
@@ -16680,7 +16768,12 @@ loc_descriptor (rtx rtl, machine_mode mode,
       if (mode == VOIDmode)
        mode = GET_MODE (rtl);
 
-      if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
+      if (mode != VOIDmode
+         /* The combination of a length and byte elt_size doesn't extend
+            naturally to boolean vectors, where several elements are packed
+            into the same byte.  */
+         && GET_MODE_CLASS (mode) != MODE_VECTOR_BOOL
+         && (dwarf_version >= 4 || !dwarf_strict))
        {
          unsigned int length;
          if (!CONST_VECTOR_NUNITS (rtl).is_constant (&length))
@@ -16800,7 +16893,15 @@ secname_for_decl (const_tree decl)
       && DECL_SECTION_NAME (decl))
     secname = DECL_SECTION_NAME (decl);
   else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
-    secname = DECL_SECTION_NAME (current_function_decl);
+    {
+      if (in_cold_section_p)
+       {
+         section *sec = current_function_section ();
+         if (sec->common.flags & SECTION_NAMED)
+           return sec->named.name;
+       }
+      secname = DECL_SECTION_NAME (current_function_decl);
+    }
   else if (cfun && in_cold_section_p)
     secname = crtl->subsections.cold_section_label;
   else
@@ -17816,6 +17917,8 @@ resolve_args_picking_1 (dw_loc_descr_ref loc, unsigned initial_frame_offset,
        case DW_OP_push_object_address:
        case DW_OP_call_frame_cfa:
        case DW_OP_GNU_variable_value:
+       case DW_OP_GNU_addr_index:
+       case DW_OP_GNU_const_index:
          ++frame_offset_;
          break;
 
@@ -18474,6 +18577,24 @@ loc_list_from_tree_1 (tree loc, int want_address,
        }
       break;
 
+    case POLY_INT_CST:
+      {
+       if (want_address)
+         {
+           expansion_failed (loc, NULL_RTX,
+                             "constant address with a runtime component");
+           return 0;
+         }
+       poly_int64 value;
+       if (!poly_int_tree_p (loc, &value))
+         {
+           expansion_failed (loc, NULL_RTX, "constant too big");
+           return 0;
+         }
+       ret = int_loc_descriptor (value);
+      }
+      break;
+
     case CONSTRUCTOR:
     case REAL_CST:
     case STRING_CST:
@@ -18807,6 +18928,10 @@ loc_list_from_tree_1 (tree loc, int want_address,
     case FIX_TRUNC_EXPR:
       return 0;
 
+    case COMPOUND_LITERAL_EXPR:
+      return loc_list_from_tree_1 (COMPOUND_LITERAL_EXPR_DECL (loc),
+                                  0, context);
+
     default:
       /* Leave front-end specific codes as simply unknown.  This comes
         up, for instance, with the C STMT_EXPR.  */
@@ -18916,15 +19041,6 @@ loc_descriptor_from_tree (tree loc, int want_address,
   return ret->expr;
 }
 
-/* Given a value, round it up to the lowest multiple of `boundary'
-   which is not less than the value itself.  */
-
-static inline HOST_WIDE_INT
-ceiling (HOST_WIDE_INT value, unsigned int boundary)
-{
-  return (((value + boundary - 1) / boundary) * boundary);
-}
-
 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
    pointer to the declared type for the relevant field variable, or return
    `integer_type_node' if the given node turns out to be an
@@ -19044,7 +19160,6 @@ field_byte_offset (const_tree decl, struct vlr_context *ctx,
   if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl)) != INTEGER_CST)
     return NULL;
 
-#ifdef PCC_BITFIELD_TYPE_MATTERS
   /* We used to handle only constant offsets in all cases.  Now, we handle
      properly dynamic byte offsets only when PCC bitfield type doesn't
      matter.  */
@@ -19159,7 +19274,6 @@ field_byte_offset (const_tree decl, struct vlr_context *ctx,
       tree_result = wide_int_to_tree (sizetype, object_offset_in_bytes);
     }
   else
-#endif /* PCC_BITFIELD_TYPE_MATTERS */
     tree_result = byte_position (decl);
 
   if (ctx->variant_part_offset != NULL_TREE)
@@ -19446,7 +19560,7 @@ insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size)
 
 /* Writes floating point values to dw_vec_const array.  */
 
-static void
+static unsigned
 insert_float (const_rtx rtl, unsigned char *array)
 {
   long val[4];
@@ -19456,11 +19570,19 @@ insert_float (const_rtx rtl, unsigned char *array)
   real_to_target (val, CONST_DOUBLE_REAL_VALUE (rtl), mode);
 
   /* real_to_target puts 32-bit pieces in each long.  Pack them.  */
+  if (GET_MODE_SIZE (mode) < 4)
+    {
+      gcc_assert (GET_MODE_SIZE (mode) == 2);
+      insert_int (val[0], 2, array);
+      return 2;
+    }
+
   for (i = 0; i < GET_MODE_SIZE (mode) / 4; i++)
     {
       insert_int (val[i], 4, array);
       array += 4;
     }
+  return 4;
 }
 
 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
@@ -19509,9 +19631,10 @@ add_const_value_attribute (dw_die_ref die, rtx rtl)
          scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
          unsigned int length = GET_MODE_SIZE (mode);
          unsigned char *array = ggc_vec_alloc<unsigned char> (length);
+         unsigned int elt_size = insert_float (rtl, array);
 
-         insert_float (rtl, array);
-         add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
+         add_AT_vec (die, DW_AT_const_value, length / elt_size, elt_size,
+                     array);
        }
       return true;
 
@@ -19522,6 +19645,12 @@ add_const_value_attribute (dw_die_ref die, rtx rtl)
          return false;
 
        machine_mode mode = GET_MODE (rtl);
+       /* The combination of a length and byte elt_size doesn't extend
+          naturally to boolean vectors, where several elements are packed
+          into the same byte.  */
+       if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL)
+         return false;
+
        unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
        unsigned char *array
          = ggc_vec_alloc<unsigned char> (length * elt_size);
@@ -19598,6 +19727,10 @@ add_const_value_attribute (dw_die_ref die, rtx rtl)
 
     case HIGH:
     case CONST_FIXED:
+    case MINUS:
+    case SIGN_EXTEND:
+    case ZERO_EXTEND:
+    case CONST_POLY_INT:
       return false;
 
     case MEM:
@@ -19633,7 +19766,7 @@ reference_to_unused (tree * tp, int * walk_subtrees,
   /* ???  The C++ FE emits debug information for using decls, so
      putting gcc_unreachable here falls over.  See PR31899.  For now
      be conservative.  */
-  else if (!symtab->global_info_ready && VAR_OR_FUNCTION_DECL_P (*tp))
+  else if (!symtab->global_info_ready && VAR_P (*tp))
     return *tp;
   else if (VAR_P (*tp))
     {
@@ -19648,7 +19781,7 @@ reference_to_unused (tree * tp, int * walk_subtrees,
          optimizing and gimplifying the CU by now.
         So if *TP has no call graph node associated
         to it, it means *TP will not be emitted.  */
-      if (!cgraph_node::get (*tp))
+      if (!symtab->global_info_ready || !cgraph_node::get (*tp))
        return *tp;
     }
   else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
@@ -20143,169 +20276,25 @@ add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p)
   return tree_add_const_value_attribute_for_decl (die, decl);
 }
 
-/* Helper function for tree_add_const_value_attribute.  Natively encode
-   initializer INIT into an array.  Return true if successful.  */
+/* Attach a DW_AT_const_value attribute to DIE. The value of the
+   attribute is the const value T.  */
 
 static bool
-native_encode_initializer (tree init, unsigned char *array, int size)
+tree_add_const_value_attribute (dw_die_ref die, tree t)
 {
-  tree type;
+  tree init;
+  tree type = TREE_TYPE (t);
+  rtx rtl;
 
-  if (init == NULL_TREE)
+  if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
     return false;
 
-  STRIP_NOPS (init);
-  switch (TREE_CODE (init))
+  init = t;
+  gcc_assert (!DECL_P (init));
+
+  if (TREE_CODE (init) == INTEGER_CST)
     {
-    case STRING_CST:
-      type = TREE_TYPE (init);
-      if (TREE_CODE (type) == ARRAY_TYPE)
-       {
-         tree enttype = TREE_TYPE (type);
-         scalar_int_mode mode;
-
-         if (!is_int_mode (TYPE_MODE (enttype), &mode)
-             || GET_MODE_SIZE (mode) != 1)
-           return false;
-         if (int_size_in_bytes (type) != size)
-           return false;
-         if (size > TREE_STRING_LENGTH (init))
-           {
-             memcpy (array, TREE_STRING_POINTER (init),
-                     TREE_STRING_LENGTH (init));
-             memset (array + TREE_STRING_LENGTH (init),
-                     '\0', size - TREE_STRING_LENGTH (init));
-           }
-         else
-           memcpy (array, TREE_STRING_POINTER (init), size);
-         return true;
-       }
-      return false;
-    case CONSTRUCTOR:
-      type = TREE_TYPE (init);
-      if (int_size_in_bytes (type) != size)
-       return false;
-      if (TREE_CODE (type) == ARRAY_TYPE)
-       {
-         HOST_WIDE_INT min_index;
-         unsigned HOST_WIDE_INT cnt;
-         int curpos = 0, fieldsize;
-         constructor_elt *ce;
-
-         if (TYPE_DOMAIN (type) == NULL_TREE
-             || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type))))
-           return false;
-
-         fieldsize = int_size_in_bytes (TREE_TYPE (type));
-         if (fieldsize <= 0)
-           return false;
-
-         min_index = tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type)));
-         memset (array, '\0', size);
-         FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
-           {
-             tree val = ce->value;
-             tree index = ce->index;
-             int pos = curpos;
-             if (index && TREE_CODE (index) == RANGE_EXPR)
-               pos = (tree_to_shwi (TREE_OPERAND (index, 0)) - min_index)
-                     * fieldsize;
-             else if (index)
-               pos = (tree_to_shwi (index) - min_index) * fieldsize;
-
-             if (val)
-               {
-                 STRIP_NOPS (val);
-                 if (!native_encode_initializer (val, array + pos, fieldsize))
-                   return false;
-               }
-             curpos = pos + fieldsize;
-             if (index && TREE_CODE (index) == RANGE_EXPR)
-               {
-                 int count = tree_to_shwi (TREE_OPERAND (index, 1))
-                             - tree_to_shwi (TREE_OPERAND (index, 0));
-                 while (count-- > 0)
-                   {
-                     if (val)
-                       memcpy (array + curpos, array + pos, fieldsize);
-                     curpos += fieldsize;
-                   }
-               }
-             gcc_assert (curpos <= size);
-           }
-         return true;
-       }
-      else if (TREE_CODE (type) == RECORD_TYPE
-              || TREE_CODE (type) == UNION_TYPE)
-       {
-         tree field = NULL_TREE;
-         unsigned HOST_WIDE_INT cnt;
-         constructor_elt *ce;
-
-         if (int_size_in_bytes (type) != size)
-           return false;
-
-         if (TREE_CODE (type) == RECORD_TYPE)
-           field = TYPE_FIELDS (type);
-
-         FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init), cnt, ce)
-           {
-             tree val = ce->value;
-             int pos, fieldsize;
-
-             if (ce->index != 0)
-               field = ce->index;
-
-             if (val)
-               STRIP_NOPS (val);
-
-             if (field == NULL_TREE || DECL_BIT_FIELD (field))
-               return false;
-
-             if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
-                 && TYPE_DOMAIN (TREE_TYPE (field))
-                 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
-               return false;
-             else if (DECL_SIZE_UNIT (field) == NULL_TREE
-                      || !tree_fits_shwi_p (DECL_SIZE_UNIT (field)))
-               return false;
-             fieldsize = tree_to_shwi (DECL_SIZE_UNIT (field));
-             pos = int_byte_position (field);
-             gcc_assert (pos + fieldsize <= size);
-             if (val && fieldsize != 0
-                 && !native_encode_initializer (val, array + pos, fieldsize))
-               return false;
-           }
-         return true;
-       }
-      return false;
-    case VIEW_CONVERT_EXPR:
-    case NON_LVALUE_EXPR:
-      return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
-    default:
-      return native_encode_expr (init, array, size) == size;
-    }
-}
-
-/* Attach a DW_AT_const_value attribute to DIE. The value of the
-   attribute is the const value T.  */
-
-static bool
-tree_add_const_value_attribute (dw_die_ref die, tree t)
-{
-  tree init;
-  tree type = TREE_TYPE (t);
-  rtx rtl;
-
-  if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
-    return false;
-
-  init = t;
-  gcc_assert (!DECL_P (init));
-
-  if (TREE_CODE (init) == INTEGER_CST)
-    {
-      if (tree_fits_uhwi_p (init))
+      if (tree_fits_uhwi_p (init))
        {
          add_AT_unsigned (die, DW_AT_const_value, tree_to_uhwi (init));
          return true;
@@ -20316,12 +20305,11 @@ tree_add_const_value_attribute (dw_die_ref die, tree t)
          return true;
        }
     }
-  if (! early_dwarf)
-    {
-      rtl = rtl_for_decl_init (init, type);
-      if (rtl)
-       return add_const_value_attribute (die, rtl);
-    }
+  /* Generate the RTL even if early_dwarf to force mangling of all refered to
+     symbols.  */
+  rtl = rtl_for_decl_init (init, type);
+  if (rtl && !early_dwarf)
+    return add_const_value_attribute (die, rtl);
   /* If the host and target are sane, try harder.  */
   if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
       && initializer_constant_valid_p (init, type))
@@ -20331,7 +20319,7 @@ tree_add_const_value_attribute (dw_die_ref die, tree t)
        {
          unsigned char *array = ggc_cleared_vec_alloc<unsigned char> (size);
 
-         if (native_encode_initializer (init, array, size))
+         if (native_encode_initializer (init, array, size) == size)
            {
              add_AT_vec (die, DW_AT_const_value, size, 1, array);
              return true;
@@ -20512,14 +20500,13 @@ compute_frame_pointer_to_fb_displacement (poly_int64 offset)
      in which to eliminate.  This is because it's stack pointer isn't 
      directly accessible as a register within the ISA.  To work around
      this, assume that while we cannot provide a proper value for
-     frame_pointer_fb_offset, we won't need one either.  */
+     frame_pointer_fb_offset, we won't need one either.  We can use
+     hard frame pointer in debug info even if frame pointer isn't used
+     since hard frame pointer in debug info is encoded with DW_OP_fbreg
+     which uses the DW_AT_frame_base attribute, not hard frame pointer
+     directly.  */
   frame_pointer_fb_offset_valid
-    = ((SUPPORTS_STACK_ALIGNMENT
-       && (elim == hard_frame_pointer_rtx
-           || elim == stack_pointer_rtx))
-       || elim == (frame_pointer_needed
-                  ? hard_frame_pointer_rtx
-                  : stack_pointer_rtx));
+    = (elim == hard_frame_pointer_rtx || elim == stack_pointer_rtx);
 }
 
 /* Generate a DW_AT_name attribute given some string value to be included as
@@ -20537,6 +20524,52 @@ add_name_attribute (dw_die_ref die, const char *name_string)
     }
 }
 
+/* Generate a DW_AT_description attribute given some string value to be included
+   as the value of the attribute.  */
+
+static void
+add_desc_attribute (dw_die_ref die, const char *name_string)
+{
+  if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
+    return;
+
+  if (name_string == NULL || *name_string == 0)
+    return;
+
+  if (demangle_name_func)
+    name_string = (*demangle_name_func) (name_string);
+
+  add_AT_string (die, DW_AT_description, name_string);
+}
+
+/* Generate a DW_AT_description attribute given some decl to be included
+   as the value of the attribute.  */
+
+static void
+add_desc_attribute (dw_die_ref die, tree decl)
+{
+  tree decl_name;
+
+  if (!flag_describe_dies || (dwarf_version < 3 && dwarf_strict))
+    return;
+
+  if (decl == NULL_TREE || !DECL_P (decl))
+    return;
+  decl_name = DECL_NAME (decl);
+
+  if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
+    {
+      const char *name = dwarf2_name (decl, 0);
+      add_desc_attribute (die, name ? name : IDENTIFIER_POINTER (decl_name));
+    }
+  else
+    {
+      char *desc = print_generic_expr_to_str (decl);
+      add_desc_attribute (die, desc);
+      free (desc);
+    }
+}
+
 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
    DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
    of TYPE accordingly.
@@ -20575,7 +20608,7 @@ static const char *
 comp_dir_string (void)
 {
   const char *wd;
-  char *wd1;
+  char *wd_plus_sep = NULL;
   static const char *cached_wd = NULL;
 
   if (cached_wd != NULL)
@@ -20587,17 +20620,26 @@ comp_dir_string (void)
 
   if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
     {
-      int wdlen;
-
-      wdlen = strlen (wd);
-      wd1 = ggc_vec_alloc<char> (wdlen + 2);
-      strcpy (wd1, wd);
-      wd1 [wdlen] = DIR_SEPARATOR;
-      wd1 [wdlen + 1] = 0;
-      wd = wd1;
+      size_t wdlen = strlen (wd);
+      wd_plus_sep = XNEWVEC (char, wdlen + 2);
+      strcpy (wd_plus_sep, wd);
+      wd_plus_sep [wdlen] = DIR_SEPARATOR;
+      wd_plus_sep [wdlen + 1] = 0;
+      wd = wd_plus_sep;
     }
 
   cached_wd = remap_debug_filename (wd);
+
+  /* remap_debug_filename can just pass through wd or return a new gc string.
+     These two types can't be both stored in a GTY(())-tagged string, but since
+     the cached value lives forever just copy it if needed.  */
+  if (cached_wd != wd)
+    {
+      cached_wd = xstrdup (cached_wd);
+      if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR && wd_plus_sep != NULL)
+        free (wd_plus_sep);
+    }
+
   return cached_wd;
 }
 
@@ -20667,12 +20709,23 @@ add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
          else
            add_AT_int (die, attr, TREE_INT_CST_LOW (value));
        }
-      else
+      else if (dwarf_version >= 5
+              && TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (value))) == 128)
        /* Otherwise represent the bound as an unsigned value with
           the precision of its type.  The precision and signedness
           of the type will be necessary to re-interpret it
           unambiguously.  */
        add_AT_wide (die, attr, wi::to_wide (value));
+      else
+       {
+         rtx v = immed_wide_int_const (wi::to_wide (value),
+                                       TYPE_MODE (TREE_TYPE (value)));
+         dw_loc_descr_ref loc
+           = loc_descriptor (v, TYPE_MODE (TREE_TYPE (value)),
+                             VAR_INIT_STATUS_INITIALIZED);
+         if (loc)
+           add_AT_loc (die, attr, loc);
+       }
       return;
     }
 
@@ -20707,6 +20760,7 @@ add_scalar_info (dw_die_ref die, enum dwarf_attribute attr, tree value,
          if (decl_die != NULL)
            {
              if (get_AT (decl_die, DW_AT_location)
+                 || get_AT (decl_die, DW_AT_data_member_location)
                  || get_AT (decl_die, DW_AT_const_value))
                {
                  add_AT_die_ref (die, attr, decl_die);
@@ -20952,8 +21006,16 @@ add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
 
          if (!get_AT (subrange_die, DW_AT_lower_bound))
            add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
-         if (upper && !get_AT (subrange_die, DW_AT_upper_bound))
-           add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
+         if (!get_AT (subrange_die, DW_AT_upper_bound)
+             && !get_AT (subrange_die, DW_AT_count))
+           {
+             if (upper)
+               add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
+             else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type))
+               /* Zero-length array.  */
+               add_bound_info (subrange_die, DW_AT_count,
+                               build_int_cst (TREE_TYPE (lower), 0), NULL);
+           }
        }
 
       /* Otherwise we have an array type with an unspecified length.  The
@@ -21152,28 +21214,30 @@ add_prototyped_attribute (dw_die_ref die, tree func_type)
    by looking in the type declaration, the object declaration equate table or
    the block mapping.  */
 
-static inline dw_die_ref
+static inline void
 add_abstract_origin_attribute (dw_die_ref die, tree origin)
 {
   dw_die_ref origin_die = NULL;
 
-  if (DECL_P (origin))
+  /* For late LTO debug output we want to refer directly to the abstract
+     DIE in the early debug rather to the possibly existing concrete
+     instance and avoid creating that just for this purpose.  */
+  sym_off_pair *desc;
+  if (in_lto_p
+      && external_die_map
+      && (desc = external_die_map->get (origin)))
     {
-      dw_die_ref c;
-      origin_die = lookup_decl_die (origin);
-      /* "Unwrap" the decls DIE which we put in the imported unit context.
-         We are looking for the abstract copy here.  */
-      if (in_lto_p
-         && origin_die
-         && (c = get_AT_ref (origin_die, DW_AT_abstract_origin))
-         /* ???  Identify this better.  */
-         && c->with_offset)
-       origin_die = c;
+      add_AT_external_die_ref (die, DW_AT_abstract_origin,
+                              desc->sym, desc->off);
+      return;
     }
+
+  if (DECL_P (origin))
+    origin_die = lookup_decl_die (origin);
   else if (TYPE_P (origin))
     origin_die = lookup_type_die (origin);
   else if (TREE_CODE (origin) == BLOCK)
-    origin_die = BLOCK_DIE (origin);
+    origin_die = lookup_block_die (origin);
 
   /* XXX: Functions that are never lowered don't always have correct block
      trees (in the case of java, they simply have no block tree, in some other
@@ -21186,7 +21250,6 @@ add_abstract_origin_attribute (dw_die_ref die, tree origin)
 
   if (origin_die)
     add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
-  return origin_die;
 }
 
 /* We do not currently support the pure_virtual attribute.  */
@@ -21295,12 +21358,17 @@ add_name_and_src_coords_attributes (dw_die_ref die, tree decl,
       const char *name = dwarf2_name (decl, 0);
       if (name)
        add_name_attribute (die, name);
+      else
+       add_desc_attribute (die, decl);
+
       if (! DECL_ARTIFICIAL (decl))
        add_src_coords_attributes (die, decl);
 
       if (!no_linkage_name)
        add_linkage_name (die, decl);
     }
+  else
+    add_desc_attribute (die, decl);
 
 #ifdef VMS_DEBUGGING_INFO
   /* Get the function's name, as described by its RTL.  This may be different
@@ -21522,6 +21590,9 @@ add_type_attribute (dw_die_ref object_die, tree type, int cv_quals,
   enum tree_code code  = TREE_CODE (type);
   dw_die_ref type_die  = NULL;
 
+  if (debug_info_level <= DINFO_LEVEL_TERSE)
+    return;
+
   /* ??? If this type is an unnamed subrange type of an integral, floating-point
      or fixed-point type, use the inner type.  This is because we have no
      support for unnamed types in base_type_die.  This can happen if this is
@@ -21698,8 +21769,8 @@ gen_array_type_die (tree type, dw_die_ref context_die)
 
   /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
      DW_TAG_string_type doesn't have DW_AT_type attribute).  */
-  if (TYPE_STRING_FLAG (type)
-      && TREE_CODE (type) == ARRAY_TYPE
+  if (TREE_CODE (type) == ARRAY_TYPE
+      && TYPE_STRING_FLAG (type)
       && is_fortran ()
       && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
     {
@@ -22131,19 +22202,18 @@ gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
       /* If the contexts differ, we may not be talking about the same
         thing.
         ???  When in LTO the DIE parent is the "abstract" copy and the
-        context_die is the specification "copy".  But this whole block
-        should eventually be no longer needed.  */
-      if (parm_die && parm_die->die_parent != context_die && !in_lto_p)
+        context_die is the specification "copy".  */
+      if (parm_die
+         && parm_die->die_parent != context_die
+         && (parm_die->die_parent->die_tag != DW_TAG_GNU_formal_parameter_pack
+             || parm_die->die_parent->die_parent != context_die)
+         && !in_lto_p)
        {
-         if (!DECL_ABSTRACT_P (node))
-           {
-             /* This can happen when creating an inlined instance, in
-                which case we need to create a new DIE that will get
-                annotated with DW_AT_abstract_origin.  */
-             parm_die = NULL;
-           }
-         else
-           gcc_unreachable ();
+         gcc_assert (!DECL_ABSTRACT_P (node));
+         /* This can happen when creating a concrete instance, in
+            which case we need to create a new DIE that will get
+            annotated with DW_AT_abstract_origin.  */
+         parm_die = NULL;
        }
 
       if (parm_die && parm_die->die_parent == NULL)
@@ -22477,14 +22547,15 @@ dwarf2out_abstract_function (tree decl)
   if (DECL_IGNORED_P (decl))
     return;
 
-  old_die = lookup_decl_die (decl);
-  /* With early debug we always have an old DIE unless we are in LTO
-     and the user did not compile but only link with debug.  */
-  if (in_lto_p && ! old_die)
+  /* In LTO we're all set.  We already created abstract instances
+     early and we want to avoid creating a concrete instance of that
+     if we don't output it.  */
+  if (in_lto_p)
     return;
+
+  old_die = lookup_decl_die (decl);
   gcc_assert (old_die != NULL);
-  if (get_AT (old_die, DW_AT_inline)
-      || get_AT (old_die, DW_AT_abstract_origin))
+  if (get_AT (old_die, DW_AT_inline))
     /* We've already generated the abstract instance.  */
     return;
 
@@ -22581,6 +22652,21 @@ premark_types_used_by_global_vars (void)
       ->traverse<void *, premark_types_used_by_global_vars_helper> (NULL);
 }
 
+/* Mark all variables used by the symtab as perennial.  */
+
+static void
+premark_used_variables (void)
+{
+  /* Mark DIEs in the symtab as used.  */
+  varpool_node *var;
+  FOR_EACH_VARIABLE (var)
+    {
+      dw_die_ref die = lookup_decl_die (var->decl);
+      if (die)
+       die->die_perennial_p = 1;
+    }
+}
+
 /* Generate a DW_TAG_call_site DIE in function DECL under SUBR_DIE
    for CA_LOC call arg loc node.  */
 
@@ -22595,7 +22681,7 @@ gen_call_site_die (tree decl, dw_die_ref subr_die,
         && block != DECL_INITIAL (decl)
         && TREE_CODE (block) == BLOCK)
     {
-      stmt_die = BLOCK_DIE (block);
+      stmt_die = lookup_block_die (block);
       if (stmt_die)
        break;
       block = BLOCK_SUPERCONTEXT (block);
@@ -22627,6 +22713,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
   tree origin = decl_ultimate_origin (decl);
   dw_die_ref subr_die;
   dw_die_ref old_die = lookup_decl_die (decl);
+  bool old_die_had_no_children = false;
 
   /* This function gets called multiple times for different stages of
      the debug process.  For example, for func() in this code:
@@ -22710,6 +22797,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
           available.
   */
   int declaration = (current_function_decl != decl
+                    || (!DECL_INITIAL (decl) && !origin)
                     || class_or_namespace_scope_p (context_die));
 
   /* A declaration that has been previously dumped needs no
@@ -22717,6 +22805,9 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
   if (old_die && declaration)
     return;
 
+  if (in_lto_p && old_die && old_die->die_child == NULL)
+    old_die_had_no_children = true;
+
   /* Now that the C++ front end lazily declares artificial member fns, we
      might need to retrofit the declaration into its class.  */
   if (!declaration && !origin && !old_die
@@ -22843,11 +22934,22 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
                  != (unsigned) s.column))
            add_AT_unsigned (subr_die, DW_AT_decl_column, s.column);
 
-         /* If the prototype had an 'auto' or 'decltype(auto)' return type,
-            emit the real type on the definition die.  */
+         /* If the prototype had an 'auto' or 'decltype(auto)' in
+            the return type, emit the real type on the definition die.  */
          if (is_cxx () && debug_info_level > DINFO_LEVEL_TERSE)
            {
              dw_die_ref die = get_AT_ref (old_die, DW_AT_type);
+             while (die
+                    && (die->die_tag == DW_TAG_reference_type
+                        || die->die_tag == DW_TAG_rvalue_reference_type
+                        || die->die_tag == DW_TAG_pointer_type
+                        || die->die_tag == DW_TAG_const_type
+                        || die->die_tag == DW_TAG_volatile_type
+                        || die->die_tag == DW_TAG_restrict_type
+                        || die->die_tag == DW_TAG_array_type
+                        || die->die_tag == DW_TAG_ptr_to_member_type
+                        || die->die_tag == DW_TAG_subroutine_type))
+               die = get_AT_ref (die, DW_AT_type);
              if (die == auto_die || die == decltype_auto_die)
                add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
                                    TYPE_UNQUALIFIED, false, context_die);
@@ -23203,8 +23305,6 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
 
              parm = DECL_CHAIN (parm);
            }
-         else if (parm)
-           parm = DECL_CHAIN (parm);
 
          if (generic_decl_parm)
            generic_decl_parm = DECL_CHAIN (generic_decl_parm);
@@ -23227,6 +23327,10 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
          else if (DECL_INITIAL (decl) == NULL_TREE)
            gen_unspecified_parameters_die (decl, subr_die);
        }
+      else if ((subr_die != old_die || old_die_had_no_children)
+              && prototype_p (TREE_TYPE (decl))
+              && stdarg_p (TREE_TYPE (decl)))
+       gen_unspecified_parameters_die (decl, subr_die);
     }
 
   if (subr_die != old_die)
@@ -23273,6 +23377,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
              dw_die_ref die = NULL;
              rtx tloc = NULL_RTX, tlocc = NULL_RTX;
              rtx arg, next_arg;
+             tree arg_decl = NULL_TREE;
 
              for (arg = (ca_loc->call_arg_loc_note != NULL_RTX
                          ? XEXP (ca_loc->call_arg_loc_note, 0)
@@ -23337,6 +23442,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
                      tdie = lookup_decl_die (tdecl);
                      if (tdie == NULL)
                        continue;
+                     arg_decl = tdecl;
                    }
                  else
                    continue;
@@ -23353,6 +23459,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
                    die = gen_call_site_die (decl, subr_die, ca_loc);
                  cdie = new_die (dwarf_TAG (DW_TAG_call_site_parameter), die,
                                  NULL_TREE);
+                 add_desc_attribute (cdie, arg_decl);
                  if (reg != NULL)
                    add_AT_loc (cdie, DW_AT_location, reg);
                  else if (tdie != NULL)
@@ -23515,6 +23622,34 @@ local_function_static (tree decl)
     && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
 }
 
+/* Return true iff DECL overrides (presumably completes) the type of
+   OLD_DIE within CONTEXT_DIE.  */
+
+static bool
+override_type_for_decl_p (tree decl, dw_die_ref old_die,
+                         dw_die_ref context_die)
+{
+  tree type = TREE_TYPE (decl);
+  int cv_quals;
+
+  if (decl_by_reference_p (decl))
+    {
+      type = TREE_TYPE (type);
+      cv_quals = TYPE_UNQUALIFIED;
+    }
+  else
+    cv_quals = decl_quals (decl);
+
+  dw_die_ref type_die = modified_type_die (type,
+                                          cv_quals | TYPE_QUALS (type),
+                                          false,
+                                          context_die);
+
+  dw_die_ref old_type_die = get_AT_ref (old_die, DW_AT_type);
+
+  return type_die != old_type_die;
+}
+
 /* Generate a DIE to represent a declared data object.
    Either DECL or ORIGIN must be non-null.  */
 
@@ -23767,7 +23902,9 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
          && !DECL_ABSTRACT_P (decl_or_origin)
          && variably_modified_type_p (TREE_TYPE (decl_or_origin),
                                       decl_function_context
-                                                       (decl_or_origin))))
+                                      (decl_or_origin)))
+      || (old_die && specialization_p
+         && override_type_for_decl_p (decl_or_origin, old_die, context_die)))
     {
       tree type = TREE_TYPE (decl_or_origin);
 
@@ -23810,7 +23947,26 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
              && DECL_RTL_SET_P (decl_or_origin))))
     {
       if (early_dwarf)
-       add_pubname (decl_or_origin, var_die);
+       {
+         add_pubname (decl_or_origin, var_die);
+         /* For global register variables, emit DW_AT_location if possible
+            already during early_dwarf, as late_global_decl won't be usually
+            called.  */
+         if (DECL_HARD_REGISTER (decl_or_origin)
+             && TREE_STATIC (decl_or_origin)
+             && !decl_by_reference_p (decl_or_origin)
+             && !get_AT (var_die, DW_AT_location)
+             && !get_AT (var_die, DW_AT_const_value)
+             && DECL_RTL_SET_P (decl_or_origin)
+             && REG_P (DECL_RTL (decl_or_origin)))
+           {
+             dw_loc_descr_ref descr
+               = reg_loc_descriptor (DECL_RTL (decl_or_origin),
+                                     VAR_INIT_STATUS_INITIALIZED);
+             if (descr)
+               add_AT_loc (var_die, DW_AT_location, descr);
+           }
+       }
       else
        add_location_or_const_value_attribute (var_die, decl_or_origin,
                                               decl == NULL);
@@ -23922,6 +24078,10 @@ gen_label_die (tree decl, dw_die_ref context_die)
 static inline void
 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
 {
+  /* We can end up with BUILTINS_LOCATION here.  */
+  if (RESERVED_LOCATION_P (BLOCK_SOURCE_LOCATION (stmt)))
+    return;
+
   expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
 
   if (dwarf_version >= 3 || !dwarf_strict)
@@ -24020,7 +24180,7 @@ add_high_low_attributes (tree stmt, dw_die_ref die)
        }
       if (attr != NULL
          && ((*ranges_table)[attr->dw_attr_val.v.val_offset].num
-             == BLOCK_NUMBER (superblock))
+             == (int)BLOCK_NUMBER (superblock))
          && BLOCK_FRAGMENT_CHAIN (superblock))
        {
          unsigned long off = attr->dw_attr_val.v.val_offset;
@@ -24030,7 +24190,7 @@ add_high_low_attributes (tree stmt, dw_die_ref die)
            {
              ++supercnt;
              gcc_checking_assert ((*ranges_table)[off + supercnt].num
-                                  == BLOCK_NUMBER (chain));
+                                  == (int)BLOCK_NUMBER (chain));
            }
          gcc_checking_assert ((*ranges_table)[off + supercnt + 1].num == 0);
          for (chain = BLOCK_FRAGMENT_CHAIN (stmt);
@@ -24074,46 +24234,26 @@ add_high_low_attributes (tree stmt, dw_die_ref die)
 static void
 gen_lexical_block_die (tree stmt, dw_die_ref context_die)
 {
-  dw_die_ref old_die = BLOCK_DIE (stmt);
+  dw_die_ref old_die = lookup_block_die (stmt);
   dw_die_ref stmt_die = NULL;
   if (!old_die)
     {
       stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
-      BLOCK_DIE (stmt) = stmt_die;
+      equate_block_to_die (stmt, stmt_die);
     }
 
-  if (BLOCK_ABSTRACT (stmt))
-    {
-      if (old_die)
-       {
-         /* This must have been generated early and it won't even
-            need location information since it's a DW_AT_inline
-            function.  */
-         if (flag_checking)
-           for (dw_die_ref c = context_die; c; c = c->die_parent)
-             if (c->die_tag == DW_TAG_inlined_subroutine
-                 || c->die_tag == DW_TAG_subprogram)
-               {
-                 gcc_assert (get_AT (c, DW_AT_inline));
-                 break;
-               }
-         return;
-       }
-    }
-  else if (BLOCK_ABSTRACT_ORIGIN (stmt))
+  if (BLOCK_ABSTRACT_ORIGIN (stmt))
     {
-      /* If this is an inlined instance, create a new lexical die for
-        anything below to attach DW_AT_abstract_origin to.  */
+      /* If this is an inlined or conrecte instance, create a new lexical
+        die for anything below to attach DW_AT_abstract_origin to.  */
       if (old_die)
-       {
-         stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
-         BLOCK_DIE (stmt) = stmt_die;
-         old_die = NULL;
-       }
+       stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
 
       tree origin = block_ultimate_origin (stmt);
-      if (origin != NULL_TREE && origin != stmt)
+      if (origin != NULL_TREE && (origin != stmt || old_die))
        add_abstract_origin_attribute (stmt_die, origin);
+
+      old_die = NULL;
     }
 
   if (old_die)
@@ -24122,7 +24262,7 @@ gen_lexical_block_die (tree stmt, dw_die_ref context_die)
   /* A non abstract block whose blocks have already been reordered
      should have the instruction range for this block.  If so, set the
      high/low attributes.  */
-  if (!early_dwarf && !BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
+  if (!early_dwarf && TREE_ASM_WRITTEN (stmt))
     {
       gcc_assert (stmt_die);
       add_high_low_attributes (stmt, stmt_die);
@@ -24136,32 +24276,38 @@ gen_lexical_block_die (tree stmt, dw_die_ref context_die)
 static void
 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die)
 {
-  tree decl;
-
-  /* The instance of function that is effectively being inlined shall not
-     be abstract.  */
-  gcc_assert (! BLOCK_ABSTRACT (stmt));
-
-  decl = block_ultimate_origin (stmt);
+  tree decl = block_ultimate_origin (stmt);
 
   /* Make sure any inlined functions are known to be inlineable.  */
   gcc_checking_assert (DECL_ABSTRACT_P (decl)
                       || cgraph_function_possibly_inlined_p (decl));
 
-  if (! BLOCK_ABSTRACT (stmt))
-    {
-      dw_die_ref subr_die
-       = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
+  dw_die_ref subr_die = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
 
-      if (call_arg_locations || debug_inline_points)
-       BLOCK_DIE (stmt) = subr_die;
-      add_abstract_origin_attribute (subr_die, decl);
-      if (TREE_ASM_WRITTEN (stmt))
-        add_high_low_attributes (stmt, subr_die);
-      add_call_src_coords_attributes (stmt, subr_die);
+  if (call_arg_locations || debug_inline_points)
+    equate_block_to_die (stmt, subr_die);
+  add_abstract_origin_attribute (subr_die, decl);
+  if (TREE_ASM_WRITTEN (stmt))
+    add_high_low_attributes (stmt, subr_die);
+  add_call_src_coords_attributes (stmt, subr_die);
 
-      decls_for_scope (stmt, subr_die);
+  /* The inliner creates an extra BLOCK for the parameter setup,
+     we want to merge that with the actual outermost BLOCK of the
+     inlined function to avoid duplicate locals in consumers.
+     Do that by doing the recursion to subblocks on the single subblock
+     of STMT.  */
+  bool unwrap_one = false;
+  if (BLOCK_SUBBLOCKS (stmt) && !BLOCK_CHAIN (BLOCK_SUBBLOCKS (stmt)))
+    {
+      tree origin = block_ultimate_origin (BLOCK_SUBBLOCKS (stmt));
+      if (origin
+         && TREE_CODE (origin) == BLOCK
+         && BLOCK_SUPERCONTEXT (origin) == decl)
+       unwrap_one = true;
     }
+  decls_for_scope (stmt, subr_die, !unwrap_one);
+  if (unwrap_one)
+    decls_for_scope (BLOCK_SUBBLOCKS (stmt), subr_die);
 }
 
 /* Generate a DIE for a field in a record, or structure.  CTX is required: see
@@ -24270,7 +24416,7 @@ gen_producer_string (void)
       case OPT_U:
       case OPT_SPECIAL_unknown:
       case OPT_SPECIAL_ignore:
-      case OPT_SPECIAL_deprecated:
+      case OPT_SPECIAL_warn_removed:
       case OPT_SPECIAL_program_name:
       case OPT_SPECIAL_input_file:
       case OPT_grecord_gcc_switches:
@@ -24281,6 +24427,7 @@ gen_producer_string (void)
       case OPT_fdiagnostics_show_labels:
       case OPT_fdiagnostics_show_line_numbers:
       case OPT_fdiagnostics_color_:
+      case OPT_fdiagnostics_format_:
       case OPT_fverbose_asm:
       case OPT____:
       case OPT__sysroot_:
@@ -24297,6 +24444,13 @@ gen_producer_string (void)
       case OPT_fchecking_:
        /* Ignore these.  */
        continue;
+      case OPT_flto_:
+       {
+         const char *lto_canonical = "-flto";
+         switches.safe_push (lto_canonical);
+         len += strlen (lto_canonical) + 1;
+         break;
+       }
       default:
         if (cl_options[save_decoded_options[j].opt_index].flags
            & CL_NO_DWARF_RECORD)
@@ -24354,6 +24508,8 @@ highest_c_language (const char *lang1, const char *lang2)
   if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) == 0)
     return "GNU C++98";
 
+  if (strcmp ("GNU C2X", lang1) == 0 || strcmp ("GNU C2X", lang2) == 0)
+    return "GNU C2X";
   if (strcmp ("GNU C17", lang1) == 0 || strcmp ("GNU C17", lang2) == 0)
     return "GNU C17";
   if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
@@ -24433,7 +24589,8 @@ gen_compile_unit_die (const char *filename)
 
          if (dwarf_version >= 5 /* || !dwarf_strict */)
            if (strcmp (language_string, "GNU C11") == 0
-               || strcmp (language_string, "GNU C17") == 0)
+               || strcmp (language_string, "GNU C17") == 0
+               || strcmp (language_string, "GNU C2X"))
              language = DW_LANG_C11;
        }
     }
@@ -24472,6 +24629,8 @@ gen_compile_unit_die (const char *filename)
        language = DW_LANG_ObjC;
       else if (strcmp (language_string, "GNU Objective-C++") == 0)
        language = DW_LANG_ObjC_plus_plus;
+      else if (strcmp (language_string, "GNU D") == 0)
+       language = DW_LANG_D;
       else if (dwarf_version >= 5 || !dwarf_strict)
        {
          if (strcmp (language_string, "GNU Go") == 0)
@@ -24539,6 +24698,7 @@ gen_inheritance_die (tree binfo, tree access, tree type,
 
 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
    structure.  */
+
 static bool
 is_variant_part (tree decl)
 {
@@ -24552,17 +24712,8 @@ is_variant_part (tree decl)
 static tree
 analyze_discr_in_predicate (tree operand, tree struct_type)
 {
-  bool continue_stripping = true;
-  while (continue_stripping)
-    switch (TREE_CODE (operand))
-      {
-      CASE_CONVERT:
-       operand = TREE_OPERAND (operand, 0);
-       break;
-      default:
-       continue_stripping = false;
-       break;
-      }
+  while (CONVERT_EXPR_P (operand))
+    operand = TREE_OPERAND (operand, 0);
 
   /* Match field access to members of struct_type only.  */
   if (TREE_CODE (operand) == COMPONENT_REF
@@ -24782,6 +24933,19 @@ analyze_variants_discr (tree variant_part_decl,
              new_node->dw_discr_range = true;
            }
 
+         else if ((candidate_discr
+                     = analyze_discr_in_predicate (match_expr, struct_type))
+                  && TREE_TYPE (candidate_discr) == boolean_type_node)
+           {
+             /* We are matching:  <discr_field> for a boolean discriminant.
+                This sub-expression matches boolean_true_node.  */
+             new_node = ggc_cleared_alloc<dw_discr_list_node> ();
+             if (!get_discr_value (boolean_true_node,
+                                   &new_node->dw_discr_lower_bound))
+               goto abort;
+             new_node->dw_discr_range = false;
+           }
+
          else
            /* Unsupported sub-expression: we cannot determine the set of
               matching discriminant values.  Abort everything.  */
@@ -24980,7 +25144,7 @@ gen_member_die (tree type, dw_die_ref context_die)
      the TREE node representing the appropriate (containing) type.  */
 
   /* First output info about the base classes.  */
-  if (binfo)
+  if (binfo && early_dwarf)
     {
       vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
       int i;
@@ -24993,19 +25157,20 @@ gen_member_die (tree type, dw_die_ref context_die)
                             context_die);
     }
 
-  /* Now output info about the data members and type members.  */
+  /* Now output info about the members. */
   for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
     {
+      /* Ignore clones.  */
+      if (DECL_ABSTRACT_ORIGIN (member))
+       continue;
+
       struct vlr_context vlr_ctx = { type, NULL_TREE };
       bool static_inline_p
-       = (TREE_STATIC (member)
+       = (VAR_P (member)
+          && TREE_STATIC (member)
           && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
               != -1));
 
-      /* Ignore clones.  */
-      if (DECL_ABSTRACT_ORIGIN (member))
-       continue;
-
       /* If we thought we were generating minimal debug info for TYPE
         and then changed our minds, some of the member declarations
         may have already been defined.  Don't define them again, but
@@ -25015,11 +25180,14 @@ gen_member_die (tree type, dw_die_ref context_die)
        {
          /* Handle inline static data members, which only have in-class
             declarations.  */
-         dw_die_ref ref = NULL; 
+         bool splice = true;
+
+         dw_die_ref ref = NULL;
          if (child->die_tag == DW_TAG_variable
              && child->die_parent == comp_unit_die ())
            {
              ref = get_AT_ref (child, DW_AT_specification);
+
              /* For C++17 inline static data members followed by redundant
                 out of class redeclaration, we might get here with
                 child being the DIE created for the out of class
@@ -25038,17 +25206,17 @@ gen_member_die (tree type, dw_die_ref context_die)
                  ref = NULL;
                  static_inline_p = false;
                }
-           }
 
-         if (child->die_tag == DW_TAG_variable
-             && child->die_parent == comp_unit_die ()
-             && ref == NULL)
-           {
-             reparent_child (child, context_die);
-             if (dwarf_version < 5)
-               child->die_tag = DW_TAG_member;
+             if (!ref)
+               {
+                 reparent_child (child, context_die);
+                 if (dwarf_version < 5)
+                   child->die_tag = DW_TAG_member;
+                 splice = false;
+               }
            }
-         else
+
+         if (splice)
            splice_child_die (context_die, child);
        }
 
@@ -25654,14 +25822,13 @@ gen_block_die (tree stmt, dw_die_ref context_die)
     /* The outer scopes for inlinings *must* always be represented.  We
        generate DW_TAG_inlined_subroutine DIEs for them.  (See below.) */
     must_output_die = 1;
-  else if (BLOCK_DIE (stmt))
+  else if (lookup_block_die (stmt))
     /* If we already have a DIE then it was filled early.  Meanwhile
        we might have pruned all BLOCK_VARS as optimized out but we
        still want to generate high/low PC attributes so output it.  */
     must_output_die = 1;
   else if (TREE_USED (stmt)
-          || TREE_ASM_WRITTEN (stmt)
-          || BLOCK_ABSTRACT (stmt))
+          || TREE_ASM_WRITTEN (stmt))
     {
       /* Determine if this block directly contains any "significant"
         local declarations which we will need to output DIEs for.  */
@@ -25694,23 +25861,7 @@ gen_block_die (tree stmt, dw_die_ref context_die)
   if (must_output_die)
     {
       if (inlined_func)
-       {
-         /* If STMT block is abstract, that means we have been called
-            indirectly from dwarf2out_abstract_function.
-            That function rightfully marks the descendent blocks (of
-            the abstract function it is dealing with) as being abstract,
-            precisely to prevent us from emitting any
-            DW_TAG_inlined_subroutine DIE as a descendent
-            of an abstract function instance. So in that case, we should
-            not call gen_inlined_subroutine_die.
-
-            Later though, when cgraph asks dwarf2out to emit info
-            for the concrete instance of the function decl into which
-            the concrete instance of STMT got inlined, the later will lead
-            to the generation of a DW_TAG_inlined_subroutine DIE.  */
-         if (! BLOCK_ABSTRACT (stmt))
-           gen_inlined_subroutine_die (stmt, context_die);
-       }
+       gen_inlined_subroutine_die (stmt, context_die);
       else
        gen_lexical_block_die (stmt, context_die);
     }
@@ -25788,7 +25939,7 @@ process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
    all of its sub-blocks.  */
 
 static void
-decls_for_scope (tree stmt, dw_die_ref context_die)
+decls_for_scope (tree stmt, dw_die_ref context_die, bool recurse)
 {
   tree decl;
   unsigned int i;
@@ -25831,10 +25982,11 @@ decls_for_scope (tree stmt, dw_die_ref context_die)
 
   /* Output the DIEs to represent all sub-blocks (and the items declared
      therein) of this block.  */
-  for (subblocks = BLOCK_SUBBLOCKS (stmt);
-       subblocks != NULL;
-       subblocks = BLOCK_CHAIN (subblocks))
-    gen_block_die (subblocks, context_die);
+  if (recurse)
+    for (subblocks = BLOCK_SUBBLOCKS (stmt);
+        subblocks != NULL;
+        subblocks = BLOCK_CHAIN (subblocks))
+      gen_block_die (subblocks, context_die);
 }
 
 /* Is this a typedef we can avoid emitting?  */
@@ -26072,7 +26224,7 @@ declare_in_namespace (tree thing, dw_die_ref context_die)
 
   if (ns_context != context_die)
     {
-      if (is_fortran ())
+      if (is_fortran () || is_dlang ())
        return ns_context;
       if (DECL_P (thing))
        gen_decl_die (thing, NULL, NULL, ns_context);
@@ -26095,7 +26247,7 @@ gen_namespace_die (tree decl, dw_die_ref context_die)
     {
       /* Output a real namespace or module.  */
       context_die = setup_namespace_context (decl, comp_unit_die ());
-      namespace_die = new_die (is_fortran ()
+      namespace_die = new_die (is_fortran () || is_dlang ()
                               ? DW_TAG_module : DW_TAG_namespace,
                               context_die, decl);
       /* For Fortran modules defined in different CU don't add src coords.  */
@@ -26161,7 +26313,7 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
       break;
 
     case CONST_DECL:
-      if (!is_fortran () && !is_ada ())
+      if (!is_fortran () && !is_ada () && !is_dlang ())
        {
          /* The individual enumerators of an enum type get output when we output
             the Dwarf representation of the relevant enum type itself.  */
@@ -26272,39 +26424,44 @@ gen_decl_die (tree decl, tree origin, struct vlr_context *ctx,
     case VAR_DECL:
     case RESULT_DECL:
       /* If we are in terse mode, don't generate any DIEs to represent any
-        variable declarations or definitions.  */
-      if (debug_info_level <= DINFO_LEVEL_TERSE)
+        variable declarations or definitions unless it is external.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+         || (debug_info_level == DINFO_LEVEL_TERSE
+             && !TREE_PUBLIC (decl_or_origin)))
        break;
 
-      /* Avoid generating stray type DIEs during late dwarf dumping.
-         All types have been dumped early.  */
-      if (early_dwarf
-         /* ???  But in LTRANS we cannot annotate early created variably
-            modified type DIEs without copying them and adjusting all
-            references to them.  Dump them again as happens for inlining
-            which copies both the decl and the types.  */
-         /* ???  And even non-LTO needs to re-visit type DIEs to fill
-            in VLA bound information for example.  */
-         || (decl && variably_modified_type_p (TREE_TYPE (decl),
-                                               current_function_decl)))
+      if (debug_info_level > DINFO_LEVEL_TERSE)
        {
-         /* Output any DIEs that are needed to specify the type of this data
-            object.  */
-         if (decl_by_reference_p (decl_or_origin))
-           gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
-         else
-           gen_type_die (TREE_TYPE (decl_or_origin), context_die);
-       }
+         /* Avoid generating stray type DIEs during late dwarf dumping.
+            All types have been dumped early.  */
+         if (early_dwarf
+             /* ???  But in LTRANS we cannot annotate early created variably
+                modified type DIEs without copying them and adjusting all
+                references to them.  Dump them again as happens for inlining
+                which copies both the decl and the types.  */
+             /* ???  And even non-LTO needs to re-visit type DIEs to fill
+                in VLA bound information for example.  */
+             || (decl && variably_modified_type_p (TREE_TYPE (decl),
+                                                   current_function_decl)))
+           {
+             /* Output any DIEs that are needed to specify the type of this data
+                object.  */
+             if (decl_by_reference_p (decl_or_origin))
+               gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
+             else
+               gen_type_die (TREE_TYPE (decl_or_origin), context_die);
+           }
 
-      if (early_dwarf)
-       {
-         /* And its containing type.  */
-         class_origin = decl_class_context (decl_or_origin);
-         if (class_origin != NULL_TREE)
-           gen_type_die_for_member (class_origin, decl_or_origin, context_die);
+         if (early_dwarf)
+           {
+             /* And its containing type.  */
+             class_origin = decl_class_context (decl_or_origin);
+             if (class_origin != NULL_TREE)
+               gen_type_die_for_member (class_origin, decl_or_origin, context_die);
 
-         /* And its containing namespace.  */
-         context_die = declare_in_namespace (decl_or_origin, context_die);
+             /* And its containing namespace.  */
+             context_die = declare_in_namespace (decl_or_origin, context_die);
+           }
        }
 
       /* Now output the DIE to represent the data object itself.  This gets
@@ -26427,7 +26584,7 @@ dwarf2out_early_global_decl (tree decl)
                 enough so that it lands in its own context.  This avoids type
                 pruning issues later on.  */
              if (context_die == NULL || is_declaration_die (context_die))
-               dwarf2out_decl (context);
+               dwarf2out_early_global_decl (context);
            }
 
          /* Emit an abstract origin of a function first.  This happens
@@ -26492,16 +26649,12 @@ dwarf2out_late_global_decl (tree decl)
     {
       dw_die_ref die = lookup_decl_die (decl);
 
-      /* We may have to generate early debug late for LTO in case debug
+      /* We may have to generate full debug late for LTO in case debug
          was not enabled at compile-time or the target doesn't support
         the LTO early debug scheme.  */
       if (! die && in_lto_p)
-       {
-         dwarf2out_decl (decl);
-         die = lookup_decl_die (decl);
-       }
-
-      if (die)
+       dwarf2out_decl (decl);
+      else if (die)
        {
          /* We get called via the symtab code invoking late_global_decl
             for symbols that are optimized out.
@@ -26753,15 +26906,17 @@ dwarf2out_decl (tree decl)
        context_die = lookup_decl_die (DECL_CONTEXT (decl));
 
       /* If we are in terse mode, don't generate any DIEs to represent any
-        variable declarations or definitions.  */
-      if (debug_info_level <= DINFO_LEVEL_TERSE)
+        variable declarations or definitions unless it is external.  */
+      if (debug_info_level < DINFO_LEVEL_TERSE
+         || (debug_info_level == DINFO_LEVEL_TERSE
+             && !TREE_PUBLIC (decl)))
        return;
       break;
 
     case CONST_DECL:
       if (debug_info_level <= DINFO_LEVEL_TERSE)
        return;
-      if (!is_fortran () && !is_ada ())
+      if (!is_fortran () && !is_ada () && !is_dlang ())
        return;
       if (TREE_STATIC (decl) && decl_function_context (decl))
        context_die = lookup_decl_die (DECL_CONTEXT (decl));
@@ -26907,6 +27062,9 @@ lookup_filename (const char *file_name)
   if (!file_name)
     return NULL;
 
+  if (!file_name[0])
+    file_name = "<stdin>";
+
   dwarf_file_data **slot
     = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
                                       INSERT);
@@ -27098,7 +27256,7 @@ static bool maybe_at_text_label_p = true;
 /* One above highest N where .LVLN label might be equal to .Ltext0 label.  */
 static unsigned int first_loclabel_num_not_at_text_label;
 
-/* Look ahead for a real insn, or for a begin stmt marker.  */
+/* Look ahead for a real insn.  */
 
 static rtx_insn *
 dwarf2out_next_real_insn (rtx_insn *loc_note)
@@ -27123,7 +27281,7 @@ dwarf2out_var_location (rtx_insn *loc_note)
 {
   char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
   struct var_loc_node *newloc;
-  rtx_insn *next_real, *next_note;
+  rtx_insn *next_real;
   rtx_insn *call_insn = NULL;
   static const char *last_label;
   static const char *last_postcall_label;
@@ -27148,7 +27306,6 @@ dwarf2out_var_location (rtx_insn *loc_note)
              var_loc_p = false;
 
              next_real = dwarf2out_next_real_insn (call_insn);
-             next_note = NULL;
              cached_next_real_insn = NULL;
              goto create_label;
            }
@@ -27176,7 +27333,6 @@ dwarf2out_var_location (rtx_insn *loc_note)
                  var_loc_p = false;
 
                  next_real = dwarf2out_next_real_insn (call_insn);
-                 next_note = NULL;
                  cached_next_real_insn = NULL;
                  goto create_label;
                }
@@ -27205,22 +27361,28 @@ dwarf2out_var_location (rtx_insn *loc_note)
        next_real = NULL;
     }
 
-  next_note = NEXT_INSN (loc_note);
-  if (! next_note
-      || next_note->deleted ()
-      || ! NOTE_P (next_note)
-      || (NOTE_KIND (next_note) != NOTE_INSN_VAR_LOCATION
-         && NOTE_KIND (next_note) != NOTE_INSN_BEGIN_STMT
-         && NOTE_KIND (next_note) != NOTE_INSN_INLINE_ENTRY))
-    next_note = NULL;
-
   if (! next_real)
     next_real = dwarf2out_next_real_insn (loc_note);
 
-  if (next_note)
+  if (next_real)
     {
-      expected_next_loc_note = next_note;
-      cached_next_real_insn = next_real;
+      rtx_insn *next_note = NEXT_INSN (loc_note);
+      while (next_note != next_real)
+       {
+         if (! next_note->deleted ()
+             && NOTE_P (next_note)
+             && NOTE_KIND (next_note) == NOTE_INSN_VAR_LOCATION)
+           break;
+         next_note = NEXT_INSN (next_note);
+       }
+
+      if (next_note == next_real)
+       cached_next_real_insn = NULL;
+      else
+       {
+         expected_next_loc_note = next_note;
+         cached_next_real_insn = next_real;
+       }
     }
   else
     cached_next_real_insn = NULL;
@@ -27337,7 +27499,7 @@ create_label:
       ca_loc->tail_call_p = SIBLING_CALL_P (prev);
 
       /* Look for a SYMBOL_REF in the "prev" instruction.  */
-      rtx x = get_call_rtx_from (PATTERN (prev));
+      rtx x = get_call_rtx_from (prev);
       if (x)
        {
          /* Try to get the call symbol, if any.  */
@@ -27485,7 +27647,7 @@ dwarf2out_inline_entry (tree block)
                                      true));
 
   gcc_assert (inlined_function_outer_scope_p (block));
-  gcc_assert (!BLOCK_DIE (block));
+  gcc_assert (!lookup_block_die (block));
 
   if (BLOCK_FRAGMENT_ORIGIN (block))
     block = BLOCK_FRAGMENT_ORIGIN (block);
@@ -27518,11 +27680,8 @@ dwarf2out_inline_entry (tree block)
   if (cur_line_info_table)
     ied->view = cur_line_info_table->view;
 
-  char label[MAX_ARTIFICIAL_LABEL_BYTES];
-
-  ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_INLINE_ENTRY_LABEL,
-                              BLOCK_NUMBER (block));
-  ASM_OUTPUT_LABEL (asm_out_file, label);
+  ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_INLINE_ENTRY_LABEL,
+                         BLOCK_NUMBER (block));
 }
 
 /* Called from finalize_size_functions for size functions so that their body
@@ -27532,6 +27691,7 @@ dwarf2out_inline_entry (tree block)
 static void
 dwarf2out_size_function (tree decl)
 {
+  set_early_dwarf s;
   function_to_dwarf_procedure (decl);
 }
 
@@ -27853,8 +28013,10 @@ dwarf2out_source_line (unsigned int line, unsigned int column,
 
       if (is_stmt != table->is_stmt)
        {
+#if HAVE_GAS_LOC_STMT
          fputs (" is_stmt ", asm_out_file);
          putc (is_stmt ? '1' : '0', asm_out_file);
+#endif
        }
       if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
        {
@@ -28104,7 +28266,19 @@ output_macinfo_op (macinfo_entry *ref)
       break;
     case DW_MACRO_define_strp:
     case DW_MACRO_undef_strp:
-      node = find_AT_string (ref->info);
+      /* NB: dwarf2out_finish performs:
+          1. save_macinfo_strings
+          2. hash table traverse of index_string
+          3. output_macinfo -> output_macinfo_op
+          4. output_indirect_strings
+               -> hash table traverse of output_index_string
+
+        When output_macinfo_op is called, all index strings have been
+        added to hash table by save_macinfo_strings and we can't pass
+        INSERT to find_slot_with_hash which may expand hash table, even
+        if no insertion is needed, and change hash table traverse order
+        between index_string and output_index_string.  */
+      node = find_AT_string (ref->info, NO_INSERT);
       gcc_assert (node
                  && (node->form == DW_FORM_strp
                      || node->form == dwarf_FORM (DW_FORM_strx)));
@@ -28939,6 +29113,30 @@ output_addr_table (void)
     return;
 
   switch_to_section (debug_addr_section);
+  /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
+     which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
+     before DWARF5, didn't have a header for .debug_addr units.
+     DWARF5 specifies a small header when address tables are used.  */
+  if (dwarf_version >= 5)
+    {
+      unsigned int last_idx = 0;
+      unsigned long addrs_length;
+
+      addr_index_table->traverse_noresize
+       <unsigned int *, count_index_addrs> (&last_idx);
+      addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
+
+      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+       dw2_asm_output_data (4, 0xffffffff,
+                            "Escape value for 64-bit DWARF extension");
+      dw2_asm_output_data (DWARF_OFFSET_SIZE, addrs_length,
+                          "Length of Address Unit");
+      dw2_asm_output_data (2, 5, "DWARF addr version");
+      dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
+      dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
+    }
+  ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
+
   addr_index_table
     ->traverse_noresize<unsigned int *, output_addr_table_entry> (&index);
 }
@@ -29162,6 +29360,7 @@ prune_unused_types_walk_local_classes (dw_die_ref die)
     case DW_TAG_structure_type:
     case DW_TAG_union_type:
     case DW_TAG_class_type:
+    case DW_TAG_interface_type:
       break;
 
     case DW_TAG_subprogram:
@@ -29195,6 +29394,7 @@ prune_unused_types_walk (dw_die_ref die)
     case DW_TAG_structure_type:
     case DW_TAG_union_type:
     case DW_TAG_class_type:
+    case DW_TAG_interface_type:
       if (die->die_perennial_p)
        break;
 
@@ -29221,7 +29421,6 @@ prune_unused_types_walk (dw_die_ref die)
     case DW_TAG_volatile_type:
     case DW_TAG_typedef:
     case DW_TAG_array_type:
-    case DW_TAG_interface_type:
     case DW_TAG_friend:
     case DW_TAG_enumeration_type:
     case DW_TAG_subroutine_type:
@@ -29242,6 +29441,26 @@ prune_unused_types_walk (dw_die_ref die)
 
       return;
 
+    case DW_TAG_variable:
+      if (flag_debug_only_used_symbols)
+       {
+         if (die->die_perennial_p)
+           break;
+
+         /* premark_used_variables marks external variables --- don't mark
+            them here.  But function-local externals are always considered
+            used.  */
+         if (get_AT (die, DW_AT_external))
+           {
+             for (c = die->die_parent; c; c = c->die_parent)
+               if (c->die_tag == DW_TAG_subprogram)
+                 break;
+             if (!c)
+               return;
+           }
+       }
+      /* FALLTHROUGH */
+
     default:
       /* Mark everything else.  */
       break;
@@ -29368,6 +29587,10 @@ prune_unused_types (void)
   /* Mark types that are used in global variables.  */
   premark_types_used_by_global_vars ();
 
+  /* Mark variables used in the symtab.  */
+  if (flag_debug_only_used_symbols)
+    premark_used_variables ();
+
   /* Set the mark on nodes that are actually used.  */
   prune_unused_types_walk (comp_unit_die ());
   for (node = limbo_die_list; node; node = node->next)
@@ -29388,9 +29611,9 @@ prune_unused_types (void)
   for (i = 0; base_types.iterate (i, &base_type); i++)
     prune_unused_types_mark (base_type, 1);
 
-  /* For -fvar-tracking-assignments, also set the mark on nodes that could be
-     referenced by DW_TAG_call_site DW_AT_call_origin (i.e. direct call
-     callees).  */
+  /* Also set the mark on nodes that could be referenced by
+     DW_TAG_call_site DW_AT_call_origin (i.e. direct call callees) or
+     by DW_TAG_inlined_subroutine origins.  */
   cgraph_node *cnode;
   FOR_EACH_FUNCTION (cnode)
     if (cnode->referred_to_p (false))
@@ -29399,8 +29622,7 @@ prune_unused_types (void)
        if (die == NULL || die->die_mark)
          continue;
        for (cgraph_edge *e = cnode->callers; e; e = e->next_caller)
-         if (e->caller != cnode
-             && opt_for_fn (e->caller->decl, flag_var_tracking_assignments))
+         if (e->caller != cnode)
            {
              prune_unused_types_mark (die, 1);
              break;
@@ -31137,7 +31359,7 @@ dwarf2out_finish (const char *filename)
   flush_limbo_die_list ();
 
   if (inline_entry_data_table)
-    gcc_assert (inline_entry_data_table->elements () == 0);
+    gcc_assert (inline_entry_data_table->is_empty ());
 
   if (flag_checking)
     {
@@ -31204,6 +31426,8 @@ dwarf2out_finish (const char *filename)
     FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
   }
 #endif
+  for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
+    resolve_addr (ctnode->root_die);
   resolve_addr (comp_unit_die ());
   move_marked_base_types ();
 
@@ -31395,7 +31619,7 @@ dwarf2out_finish (const char *filename)
                          ? dl_section_ref
                          : debug_skeleton_line_section_label));
 
-      output_comdat_type_unit (ctnode);
+      output_comdat_type_unit (ctnode, false);
       *slot = ctnode;
     }
 
@@ -31434,30 +31658,6 @@ dwarf2out_finish (const char *filename)
                            ranges_section_label);
        }
 
-      switch_to_section (debug_addr_section);
-      /* GNU DebugFission https://gcc.gnu.org/wiki/DebugFission
-        which GCC uses to implement -gsplit-dwarf as DWARF GNU extension
-        before DWARF5, didn't have a header for .debug_addr units.
-        DWARF5 specifies a small header when address tables are used.  */
-      if (dwarf_version >= 5)
-       {
-         unsigned int last_idx = 0;
-         unsigned long addrs_length;
-
-         addr_index_table->traverse_noresize
-           <unsigned int *, count_index_addrs> (&last_idx);
-         addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
-
-         if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
-           dw2_asm_output_data (4, 0xffffffff,
-                                "Escape value for 64-bit DWARF extension");
-         dw2_asm_output_data (DWARF_OFFSET_SIZE, addrs_length,
-                              "Length of Address Unit");
-         dw2_asm_output_data (2, 5, "DWARF addr version");
-         dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
-         dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
-       }
-      ASM_OUTPUT_LABEL (asm_out_file, debug_addr_section_label);
       output_addr_table ();
     }
 
@@ -31920,13 +32120,13 @@ dwarf2out_early_finish (const char *filename)
      emit full debugging info for them.  */
   retry_incomplete_types ();
 
+  gen_scheduled_generic_parms_dies ();
+  gen_remaining_tmpl_value_param_die_attribute ();
+
   /* The point here is to flush out the limbo list so that it is empty
      and we don't need to stream it for LTO.  */
   flush_limbo_die_list ();
 
-  gen_scheduled_generic_parms_dies ();
-  gen_remaining_tmpl_value_param_die_attribute ();
-
   /* Add DW_AT_linkage_name for all deferred DIEs.  */
   for (limbo_die_node *node = deferred_asm_name; node; node = node->next)
     {
@@ -32014,7 +32214,7 @@ dwarf2out_early_finish (const char *filename)
      location related output removed and some LTO specific changes.
      Some refactoring might make both smaller and easier to match up.  */
 
-  /* Traverse the DIE's and add add sibling attributes to those DIE's
+  /* Traverse the DIE's and add sibling attributes to those DIE's
      that have children.  */
   add_sibling_attributes (comp_unit_die ());
   for (limbo_die_node *node = limbo_die_list; node; node = node->next)
@@ -32068,7 +32268,7 @@ dwarf2out_early_finish (const char *filename)
                          ? debug_line_section_label
                          : debug_skeleton_line_section_label));
 
-      output_comdat_type_unit (ctnode);
+      output_comdat_type_unit (ctnode, true);
       *slot = ctnode;
     }
 
This page took 0.141755 seconds and 5 git commands to generate.