The following fixes PR86452 by using scope_die_for which correctly deals with -g1 in not creating (new) DIEs for namespaces. With a larger LTO testcase we run into this with a namespace DIE not readily available but I'm not sure the issue isn't latent with non-LTO.
The original code was added with the fix for PR44188 which had a lengthy discussion and various patch variants but this very piece of change didn't have an explanation and why it didn't use scope_die_for. The single testcase added still passes after the patch. Bootstraped on x86_64-unknown-linux-gnu, testing in progress. OK for trunk? Thanks, Richard. 2018-07-11 Richard Biener <rguent...@suse.de> PR debug/86452 * dwarf2out.c (gen_type_die_with_usage): Use scope_die_for instead of get_context_die. Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 262551) +++ gcc/dwarf2out.c (working copy) @@ -25378,11 +25378,8 @@ gen_type_die_with_usage (tree type, dw_d generate debug info for the typedef. */ if (is_naming_typedef_decl (TYPE_NAME (type))) { - /* Use the DIE of the containing namespace as the parent DIE of - the type description DIE we want to generate. */ - if (DECL_CONTEXT (TYPE_NAME (type)) - && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL) - context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type))); + /* Give typedefs the right scope. */ + context_die = scope_die_for (type, context_die); gen_decl_die (TYPE_NAME (type), NULL, NULL, context_die); return;