https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86523
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> --- So there was no early debug info generated for the decl <var_decl 0x7ffff7fefb40 e type <record_type 0x7ffff6a86690 B readonly SI ... context <record_type 0x7ffff6a865e8 k> in fact there's no early debug for anything besides the globals c,d,f and g and artifical infrastructure. Which is likely because everything is optimized away. But we _do_ end up assembling the instantiated k<int>::e. Somehow dwarf2out_early_global_decl doesn't see it but only the guard variable for its initialization. This is because when the C++ FE calls rest_of_decl_compilation we have current_function_decl set to __static_initialization_and_destruction_0 which looks spurious. The following fixes that and properly generates debug info early (also for non-LTO though that's currently harmless becuase we do not perform free-lang-data): diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index f8fc20e4093..d67ced097da 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -4754,14 +4754,14 @@ c_parse_final_cleanups (void) inline, with resulting performance improvements. */ tree ssdf_body; + /* Make sure the back end knows about all the variables. */ + write_out_vars (vars); + /* Set the line and file, so that it is obviously not from the source file. */ input_location = locus_at_end_of_parsing; ssdf_body = start_static_storage_duration_function (ssdf_count); - /* Make sure the back end knows about all the variables. */ - write_out_vars (vars); - /* First generate code to do all the initializations. */ if (vars) do_static_initialization_or_destruction (vars, /*initp=*/true);