https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93951
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jason at gcc dot gnu.org --- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> --- The issue is that we have DIE 0: DW_TAG_compile_unit (0x7ffff6837000) abbrev id: 0 offset: 0 mark: 1 DW_AT_producer: "GNU C++17 10.0.1 20200302 (experimental) -g -flto -femit-struct-debug-baseonly -std=c++17 -fno-eliminate-unused-debug-symbols" DW_AT_language: 4 DW_AT_name: "t.ii" DW_AT_comp_dir: "/abuild/rguenther/obj-work2-g/gcc" DW_AT_stmt_list: label: *.Ldebug_line0 DIE 0: DW_TAG_namespace (0x7ffff6837140) abbrev id: 0 offset: 0 mark: 1 DW_AT_name: "std" DW_AT_decl_file: "<built-in>" (0) DW_AT_decl_line: 0 DW_AT_sibling: die -> 0 (0x7ffff6837230) DIE 0: DW_TAG_structure_type (0x7ffff68371e0) abbrev id: 0 offset: 0 mark: 1 DW_AT_name: "A<V::m_fn2()::<lambda()> >" DW_AT_declaration: 1 DIE 0: DW_TAG_template_type_param (0x7ffff6837410) abbrev id: 0 offset: 0 mark: 1 DW_AT_name: "_Tp" DW_AT_type: die -> 0 (0x7ffff68373c0) but something pruned that last referenced DIE so it doens't get marked and thus appears external. We're eventually coming from 0x0000000000fa2679 in generic_parameter_die ( parm=<type_decl 0x7ffff683cbe0 _Visitor>, arg=<record_type 0x7ffff6968d20 ._anon_0>, emit_name_p=true, parent_die=<dw_die_ref 0x7ffff6837190 DW_TAG_structure_type <parent=0x7ffff6837140 DW_TAG_namespace>>) at /space/rguenther/src/gcc-work2/gcc/dwarf2out.c:13665 (gdb) l 13660 TMPL_DIE should have a child DW_AT_type attribute that is set 13661 to the type of the argument to PARM, which is ARG. 13662 If PARM is a type generic parameter, TMPL_DIE should have a 13663 child DW_AT_type that is set to ARG. */ 13664 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg); 13665 add_type_attribute (tmpl_die, tmpl_type, 13666 (TREE_THIS_VOLATILE (tmpl_type) 13667 ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED), 13668 false, parent_die); (gdb) bt #0 0x0000000000fa2679 in generic_parameter_die ( parm=<type_decl 0x7ffff683cbe0 _Visitor>, arg=<record_type 0x7ffff6968d20 ._anon_0>, emit_name_p=true, parent_die=<dw_die_ref 0x7ffff6837190 DW_TAG_structure_type <parent=0x7ffff6837140 DW_TAG_namespace>>) at /space/rguenther/src/gcc-work2/gcc/dwarf2out.c:13665 #1 0x0000000000fa23c5 in gen_generic_params_dies ( t=<record_type 0x7ffff6979150 __gen_vtable>) at /space/rguenther/src/gcc-work2/gcc/dwarf2out.c:13585 #2 0x0000000000fc9fc6 in gen_scheduled_generic_parms_dies () at /space/rguenther/src/gcc-work2/gcc/dwarf2out.c:27138 #3 0x0000000000fd51d7 in dwarf2out_early_finish ( filename=0x7fffffffe1c6 "t.ii") at /space/rguenther/src/gcc-work2/gcc/dwarf2out.c:32065 and that isn't expected to generate limbo dies. The gen_scheduled_generic_parms_dies function says /* Generate generic parameters DIEs for instances of generic types that have been previously scheduled by schedule_generic_params_dies_gen. This function must be called after all the types of the CU have been laid out. */ but not all types of the CU have been laid out as obviously seen. I'm really not sure that the implementation of -femit-struct-debug- via should_emit_struct_debug () is sane. Preventing initial DIE generation is really fragile and instead later pruning everything we don't want is much easier to get correct. Now, a fix for the testcase at hand would be to flush limbos one step later, but that may simply paper over the underlying issue. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index bb45279ea56..54075b011bf 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -32058,11 +32058,12 @@ dwarf2out_early_finish (const char *filename) emit full debugging info for them. */ retry_incomplete_types (); + gen_scheduled_generic_parms_dies (); + /* 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. */ Note for non-LTO it "works" because we flush limbos again in dwarf2out_finish before marking DIEs which doesn't happen before we output the early debug. That said, I wouldn't expect gen_scheduled_generic_parms_dies to generate type DIEs in limbo. Limbo flushing may generate new DIEs as well and IIRC ones with generic param DIEs, this was the reason of flushing before. I'd hate to "iterate" here. Jason?