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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
...
> Anyway, r16-3821 says that "(block vars or type fields) are already handled
> explicitly elsewhere" which is clearly not the case,
>           /* Push all TYPE_FIELDS - there can be interleaving interesting
>              and non-interesting things.  */
>           tem = TYPE_FIELDS (t);
>           while (tem)
>             {
>               if (TREE_CODE (tem) == FIELD_DECL)
>                 fld_worklist_push (tem, fld);
>               tem = TREE_CHAIN (tem);
>             }
> only handles FIELD_DECLs from TYPE_FIELDS, not also FUNCTION_DECLs or other
> entities.

I'll note that this basically assumes thin LTO operation where we do not
stream those other fields and it assumes early-debug did do all frontend
related processing.

#22 0x0000000001869350 in dwarf2out_finish (filename=0x5491920 "t.ii")
    at /space/rguenther/src/gcc-clean/gcc/dwarf2out.cc:32858
32858     gen_remaining_tmpl_value_param_die_attribute ();
(gdb) l
32853
32854     /* We shouldn't have any symbols with delayed asm names for
32855        DIEs generated after early finish.  */
32856     gcc_assert (deferred_asm_name == NULL);
32857
32858     gen_remaining_tmpl_value_param_die_attribute ();

we should have processed most of these early (all of them, but ...).
For fat LTO we could generate the location early but only append it
late.  But it's definitely broken to some extent to leave around
CV qualified main variants.  All referenced types should have been
mangled (if only via early-debug), processing the location early
would solve the symptom as well.

Fat LTO + free-lang-data is as much a problematical combination as
enabling free-lang-data without LTO would be ...

The following resolves the DWARF side of the issue, at the expense of
creating the LOC descriptor twice.  I don't know (I hope not) if we
do any sorts of caching in there, the machinery is a bit complicated...

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 8c6bab4bdb5..9432fcd606d 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -28461,10 +28461,9 @@ gen_remaining_tmpl_value_param_die_attribute (void)
              && !tree_add_const_value_attribute (e->die, e->arg))
            {
              dw_loc_descr_ref loc = NULL;
-             if (! early_dwarf
-                 && (dwarf_version >= 5 || !dwarf_strict))
+             if (dwarf_version >= 5 || !dwarf_strict)
                loc = loc_descriptor_from_tree (e->arg, 2, NULL);
-             if (loc)
+             if (! early_dwarf && loc)
                add_AT_loc (e->die, DW_AT_location, loc);
              else
                (*tmpl_value_parm_die_table)[j++] = *e;

as for FLD, the "expensive" part would be to make a distinct copy of the
main variant, to be used for the unused variants.  Like with

diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc
index edc4f1aed81..0b0ba1d7c76 100644
--- a/gcc/ipa-free-lang-data.cc
+++ b/gcc/ipa-free-lang-data.cc
@@ -421,14 +421,18 @@ free_lang_data_in_type (tree type, class free_lang_data_d
*fld)

   /* Purge non-marked variants from the variants chain, so that they
      don't reappear in the IL after free_lang_data.  */
+  tree mv_copy = NULL_TREE;
   while (TYPE_NEXT_VARIANT (type)
         && !fld->pset.contains (TYPE_NEXT_VARIANT (type)))
     {
       tree t = TYPE_NEXT_VARIANT (type);
       TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
-      /* Turn the removed types into distinct types.  */
-      TYPE_MAIN_VARIANT (t) = t;
-      TYPE_NEXT_VARIANT (t) = NULL_TREE;
+      /* Turn the removed variant types into variants of a distinct type.  */
+      if (!mv_copy)
+       mv_copy = build_distinct_type_copy (TYPE_MAIN_VARIANT (t));
+      TYPE_MAIN_VARIANT (t) = mv_copy;
+      TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv_copy);
+      TYPE_NEXT_VARIANT (mv_copy) = t;
     }

   if (TREE_CODE (type) == FUNCTION_TYPE)

but IMO the problem is really that the late DWARF ventures into the FE
because those side-effects are not applied early.  So I think the patch
to dwarf2out is better (short of inventing a clean-run variant of
loc_descriptor_from_tree or searching for symbol refs in there and
applying the name mangling only?)

Reply via email to