https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86549
Bug ID: 86549 Summary: [8/9 Regression] -flto -g0 vs. -g issues Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: ice-on-valid-code, lto Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- We do have some issues when compiling with LTO and -g0 but link with -g because of the fact that the debug machinery doesn't consistently avoid creating types late and with free-lang-data scrapping useful info dwarf2out gets confused. Example from PR86523: class a { int b; }; int const c = 0, d = 1, f = 2, g = 3; struct B { typedef a h; h i; }; template <class> B j(); template <class> struct k { static B const e; }; template <class l> B const k<l>::e = j<l>(); inline B m() { switch (0) { case c: case d: return k<int>::e; case f: case g:; } } And that PRs comment#8 says That would be fixed by sth like the following but that then hides issues with consistent -g as we ran into. It might be instead interesting to make it more consistently fail by asserting early_dwarf here ... (but I expect that to blow up in our face) So I'm not going to fix this right now but will open a new bug for it. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index bd45e0b0685..3eaa032bb95 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -23732,12 +23732,13 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die) else add_name_and_src_coords_attributes (var_die, decl, no_linkage_name); - if ((origin == NULL && !specialization_p) - || (origin != NULL - && !DECL_ABSTRACT_P (decl_or_origin) - && variably_modified_type_p (TREE_TYPE (decl_or_origin), - decl_function_context - (decl_or_origin)))) + if (early_dwarf + && ((origin == NULL && !specialization_p) + || (origin != NULL + && !DECL_ABSTRACT_P (decl_or_origin) + && variably_modified_type_p (TREE_TYPE (decl_or_origin), + decl_function_context + (decl_or_origin))))) { tree type = TREE_TYPE (decl_or_origin);