https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86321

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
We're generating types late via

  if ((origin == NULL && !specialization_p)
      || (origin != NULL
          && !DECL_ABSTRACT_P (decl_or_origin)
          && variably_modified_type_p (TREE_TYPE (decl_or_origin),
                                       decl_function_context
                                                        (decl_or_origin))))
    {
      tree type = TREE_TYPE (decl_or_origin);

      if (decl_by_reference_p (decl_or_origin))
        add_type_attribute (var_die, TREE_TYPE (type), TYPE_UNQUALIFIED, false,
                            context_die);
      else
        add_type_attribute (var_die, type, decl_quals (decl_or_origin), false,
                            context_die);
    }

but then somehow end up doing this twice and get confused with gen_member_die
having an old DIE in an existing correct place but we just generated the
parent again.

      /* 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
         do put them in the right order.  */

      if (dw_die_ref child = lookup_decl_die (member))
        {
...
          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;
            }
          else
            splice_child_die (context_die, child);

we run into splice_child_die with child already having a (non-comp_unit_die)
parent.

The solution is of course to not generate the type twice.  Not sure how
easy that is to wire in.

Or to avoid generating anything but "stub" types for late LTO when
origin == NULL.

Reply via email to