From 05109b1bd5ef4ee9d78fe17d4563889694a26d05 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 8 Mar 2024 09:14:32 +0100 Subject: dwarf2out: Emit DW_AT_export_symbols on anon unions/structs [PR113918] DWARF5 added DW_AT_export_symbols both for use on inline namespaces (where we emit it), but also on anonymous unions/structs (and we didn't emit that attribute there). The following patch fixes it. 2024-03-08 Jakub Jelinek PR debug/113918 gcc/ * dwarf2out.cc (gen_field_die): Emit DW_AT_export_symbols on anonymous unions or structs for -gdwarf-5 or -gno-strict-dwarf. gcc/c/ * c-tree.h (c_type_dwarf_attribute): Declare. * c-objc-common.h (LANG_HOOKS_TYPE_DWARF_ATTRIBUTE): Redefine. * c-objc-common.cc: Include dwarf2.h. (c_type_dwarf_attribute): New function. gcc/cp/ * cp-objcp-common.cc (cp_type_dwarf_attribute): Return 1 for DW_AT_export_symbols on anonymous structs or unions. gcc/testsuite/ * c-c++-common/dwarf2/pr113918.c: New test. --- gcc/dwarf2out.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gcc/dwarf2out.cc') diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 03d73f9..87e4240 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -25162,6 +25162,17 @@ gen_field_die (tree decl, struct vlr_context *ctx, dw_die_ref context_die) add_accessibility_attribute (decl_die, decl); + /* Add DW_AT_export_symbols to anonymous unions or structs. */ + if ((dwarf_version >= 5 || !dwarf_strict) && DECL_NAME (decl) == NULL_TREE) + if (tree type = member_declared_type (decl)) + if (lang_hooks.types.type_dwarf_attribute (TYPE_MAIN_VARIANT (type), + DW_AT_export_symbols) != -1) + { + dw_die_ref type_die = lookup_type_die (TYPE_MAIN_VARIANT (type)); + if (type_die && get_AT (type_die, DW_AT_export_symbols) == NULL) + add_AT_flag (type_die, DW_AT_export_symbols, 1); + } + /* Equate decl number to die, so that we can look up this decl later on. */ equate_decl_number_to_die (decl, decl_die); } -- cgit v1.1