[Bug debug/90232] gcc drops top-level dies with -fdebug-types-section

2019-04-25 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90232

Richard Biener  changed:

   What|Removed |Added

   Keywords||wrong-debug
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-04-25
 CC||rguenth at gcc dot gnu.org
 Ever confirmed|0   |1
  Known to fail||4.8.5

--- Comment #2 from Richard Biener  ---
Confirmed also with gcc 4.8.  -fno-eliminate-unused-debug-types doesn't help
so it's an artifact of the debug-types implementation.

[Bug debug/90232] gcc drops top-level dies with -fdebug-types-section

2019-04-24 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90232

--- Comment #1 from Tom de Vries  ---
With this demonstrator patch:
...
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index b9a624e1ac7..1e818973fae 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -8400,10 +8400,11 @@ generate_skeleton (dw_die_ref die)
   /* If this type definition is nested inside another type,
  and is not an instantiation of a template, always leave
  at least a declaration in its place.  */
-  if (die->die_parent != NULL
-  && is_type_die (die->die_parent)
-  && !is_template_instantiation (die))
-node.new_die = clone_as_declaration (die);
+  if (true || (die->die_parent != NULL
+  && is_type_die (die->die_parent)
+  && !is_template_instantiation (die)))
+  node.new_die = clone_as_declaration (die);
+  node.new_die->die_perennial_p = 1;

   generate_skeleton_bottom_up ();
   return node.new_die;
...
instead we get the desired:
...
 <0>: Abbrev Number: 5 (DW_TAG_compile_unit)
   DW_AT_name: (indirect string, offset: 0x1f8): 36.c
 <1>: Abbrev Number: 6 (DW_TAG_structure_type)
   DW_AT_name: s
   DW_AT_signature   : signature: 0xfd1462823bb6f7b7
 <1><106>: Abbrev Number: 7 (DW_TAG_subprogram)
<107>   DW_AT_name: (indirect string, offset: 0x2b8): main
 <2><124>: Abbrev Number: 8 (DW_TAG_variable)
<125>   DW_AT_name: a
<12a>   DW_AT_type: <0xf4>
Contents of the .debug_types section:
   Signature: 0xfd1462823bb6f7b7
 <1><1d>: Abbrev Number: 2 (DW_TAG_structure_type)
<1e>   DW_AT_name: s
...
and:
...
 <0><13e>: Abbrev Number: 5 (DW_TAG_compile_unit)
<144>   DW_AT_name: (indirect string, offset: 0x2bd): 36b.c
 <1><160>: Abbrev Number: 6 (DW_TAG_structure_type)
<161>   DW_AT_name: s
<163>   DW_AT_signature   : signature: 0x534310fbefba324d
 <1><172>: Abbrev Number: 7 (DW_TAG_subprogram)
<173>   DW_AT_name: f
 <2><18a>: Abbrev Number: 8 (DW_TAG_variable)
<18b>   DW_AT_name: b
Contents of the .debug_types section:
   Signature: 0x534310fbefba324d
 <1><59>: Abbrev Number: 2 (DW_TAG_structure_type)
<5a>   DW_AT_name: s
...