From: Jason Merrill Date: Fri, 20 Nov 2020 20:20:45 +0000 (-0500) Subject: dwarf2: ICE with local class in unused function [PR97918] X-Git-Tag: releases/gcc-10.3.0~593 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8157b74114f2ba8a6495244f3e171a818a86436a;p=thirdparty%2Fgcc.git dwarf2: ICE with local class in unused function [PR97918] Here, since we only mention bar, we never emit debug information for it. But we do emit debug information for H::h, so we need to refer to the debug info for bar::J even though there is no bar. We deal with this sort of thing in dwarf2out with the limbo_die_list; parentless dies like J get attached to the CU at EOF. But here, we were flushing the limbo list, then generating the template argument DIE for H that refers to J, which adds J to the limbo list, too late to be flushed. So let's flush a little later. gcc/ChangeLog: PR c++/97918 * dwarf2out.c (dwarf2out_early_finish): flush_limbo_die_list after gen_scheduled_generic_parms_dies. gcc/testsuite/ChangeLog: PR c++/97918 * g++.dg/debug/localclass2.C: New test. --- diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 1fa6b846317d..cd12a76b67a8 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -32068,13 +32068,13 @@ dwarf2out_early_finish (const char *filename) emit full debugging info for them. */ retry_incomplete_types (); + gen_scheduled_generic_parms_dies (); + gen_remaining_tmpl_value_param_die_attribute (); + /* 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. */ for (limbo_die_node *node = deferred_asm_name; node; node = node->next) { diff --git a/gcc/testsuite/g++.dg/debug/localclass2.C b/gcc/testsuite/g++.dg/debug/localclass2.C new file mode 100644 index 000000000000..9897eec5d2d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/localclass2.C @@ -0,0 +1,24 @@ +// PR c++/97918 +// { dg-do compile { target c++11 } } +// { dg-require-effective-target lto } +// { dg-additional-options "-g -O -flto" } + +namespace { class A {}; } +class B {}; +template struct H { + constexpr static unsigned h = 0; +}; + +template A bar () +{ + struct J { + static void foo(); + }; + H(); + return A (); +} + +void fn () +{ + bar; // only mentions the function +}