https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78835
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I have once written: --- gcc/dwarf2out.c.jj 2016-10-21 18:40:34.000000000 +0200 +++ gcc/dwarf2out.c 2016-10-21 19:36:28.622894699 +0200 @@ -28399,16 +28399,23 @@ resolve_addr (dw_die_ref die) && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE && (cdie = lookup_context_die (DECL_CONTEXT (tdecl)))) { - /* Creating a full DIE for tdecl is overly expensive and - at this point even wrong when in the LTO phase - as it can end up generating new type DIEs we didn't - output and thus optimize_external_refs will crash. */ - tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE); - add_AT_flag (tdie, DW_AT_external, 1); - add_AT_flag (tdie, DW_AT_declaration, 1); - add_linkage_attr (tdie, tdecl); - add_name_and_src_coords_attributes (tdie, tdecl); - equate_decl_number_to_die (tdecl, tdie); + dw_die_ref pdie = cdie; + /* Make sure we don't add these DIEs into type units. */ + while (pdie && pdie->die_tag != DW_TAG_type_unit) + pdie = pdie->die_parent; + if (pdie == NULL) + { + /* Creating a full DIE for tdecl is overly expensive and + at this point even wrong when in the LTO phase + as it can end up generating new type DIEs we didn't + output and thus optimize_external_refs will crash. */ + tdie = new_die (DW_TAG_subprogram, cdie, NULL_TREE); + add_AT_flag (tdie, DW_AT_external, 1); + add_AT_flag (tdie, DW_AT_declaration, 1); + add_linkage_attr (tdie, tdecl); + add_name_and_src_coords_attributes (tdie, tdecl); + equate_decl_number_to_die (tdecl, tdie); + } } if (tdie) { for this, but am not really sure what is right. Basically, for DW_TAG_call_site we sometimes want to refer to a DIE that isn't included, creating it on the fly outside of type units works, inside of type units is harder (but I'm afraid I don't know the type units code too much to even know what should be emitted then). So the above patch just pessimizes the call site info in that case rather than ICEing.