dwarf2out: Don't prune static data members initialized with constants with -gdwarf-5 [PR98755]

In DWARF4 and earlier, static data members were represented as DW_TAG_member and the
pruning code wouldn't prune those, but in DWARF5 they are represented as DW_TAG_variable
with the class parent and the pruning code prunes those by default unless they are
referenced from a separate definition without the class parent (out of class definition).
C++17 inline vars have the definitions in the class though and even before if the static
data member isn't ODR used, it doesn't need to be defined, so we could just never describe
those static data members in the debug info.

This change stops the pruning of DW_TAG_variable with DW_AT_const_value attribute
with a class parent for -gdwarf-5 and later.

This fixes
-FAIL: g++.dg/debug/dwarf2/constexpr-var-1.C   scan-assembler-times  DW_AT_const_expr 2
-FAIL: libstdc++-prettyprinters/80276.cc whatis p4
-FAIL: libstdc++-prettyprinters/80276.cc whatis p4
-FAIL: libstdc++-prettyprinters/libfundts.cc print as
-FAIL: libstdc++-prettyprinters/libfundts.cc print as
-FAIL: libstdc++-prettyprinters/libfundts.cc print os
-FAIL: libstdc++-prettyprinters/libfundts.cc print os

2021-02-10  Jakub Jelinek  <jakub@redhat.com>

	PR debug/98755
	* dwarf2out.c (prune_unused_types_walk): Mark DW_TAG_variable DIEs
	at class scope for DWARF5+.
This commit is contained in:
Jakub Jelinek 2021-02-10 07:54:30 +01:00
parent f7fb2f662f
commit e1782d8ad1

View File

@ -29475,6 +29475,16 @@ prune_unused_types_walk (dw_die_ref die)
if (die->die_perennial_p)
break;
/* For static data members, the declaration in the class is supposed
to have DW_TAG_member tag in DWARF{3,4} but DW_TAG_variable in
DWARF5. DW_TAG_member will be marked, so mark even such
DW_TAG_variables in DWARF5, as long as it has DW_AT_const_value
attribute. */
if (dwarf_version >= 5
&& class_scope_p (die->die_parent)
&& get_AT (die, DW_AT_const_value))
break;
/* premark_used_variables marks external variables --- don't mark
them here. But function-local externals are always considered
used. */