From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 0FE993857732; Fri, 8 Mar 2024 08:30:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FE993857732 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709886605; bh=z3U8hFOU92/6a1CsUEl6eFai/T5YrIZJmObpazg2QGg=; h=From:To:Subject:Date:From; b=D0v2UddemcYcM4pxBu58bz8PZIytKzp4b6QgObXb/j+LW3kg4YArnt/o/EWtSHC+S 7PvboOi850uui1R0dfUxsazFptY7SWlMlm39rK+r25bd+Hlbi/sCAnGXCTRvDCX5D4 dVCcRYh8sgV/UdBEf/HH7xwrofYyiLVT1Eo5BRZ0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9385] dwarf2out: Emit DW_AT_export_symbols on anon unions/structs [PR113918] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 3ecc5071797c4ceb6da67a6c2b2527a046091de2 X-Git-Newrev: 05109b1bd5ef4ee9d78fe17d4563889694a26d05 Message-Id: <20240308083005.0FE993857732@sourceware.org> Date: Fri, 8 Mar 2024 08:30:02 +0000 (GMT) List-Id: https://gcc.gnu.org/g:05109b1bd5ef4ee9d78fe17d4563889694a26d05 commit r14-9385-g05109b1bd5ef4ee9d78fe17d4563889694a26d05 Author: Jakub Jelinek Date: Fri Mar 8 09:14:32 2024 +0100 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. Diff: --- gcc/c/c-objc-common.cc | 23 +++++++++++++++++++ gcc/c/c-objc-common.h | 3 +++ gcc/c/c-tree.h | 1 + gcc/cp/cp-objcp-common.cc | 5 +++++ gcc/dwarf2out.cc | 11 ++++++++++ gcc/testsuite/c-c++-common/dwarf2/pr113918.c | 33 ++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+) diff --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc index 116b73af6db..b7c72d2609c 100644 --- a/gcc/c/c-objc-common.cc +++ b/gcc/c/c-objc-common.cc @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "gcc-rich-location.h" #include "stringpool.h" #include "attribs.h" +#include "dwarf2.h" static bool c_tree_printer (pretty_printer *, text_info *, const char *, int, bool, bool, bool, bool *, const char **); @@ -446,3 +447,25 @@ instantiation_dependent_expression_p (tree) { return false; } + +/* Return -1 if dwarf ATTR shouldn't be added for TYPE, or the attribute + value otherwise. */ +int +c_type_dwarf_attribute (const_tree type, int attr) +{ + if (type == NULL_TREE) + return -1; + + switch (attr) + { + case DW_AT_export_symbols: + if (RECORD_OR_UNION_TYPE_P (type) && TYPE_NAME (type) == NULL_TREE) + return 1; + break; + + default: + break; + } + + return -1; +} diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h index 35a59988e90..20af5a5bb94 100644 --- a/gcc/c/c-objc-common.h +++ b/gcc/c/c-objc-common.h @@ -119,6 +119,9 @@ static const scoped_attribute_specs *const c_objc_attribute_table[] = #undef LANG_HOOKS_GIMPLIFY_EXPR #define LANG_HOOKS_GIMPLIFY_EXPR c_gimplify_expr +#undef LANG_HOOKS_TYPE_DWARF_ATTRIBUTE +#define LANG_HOOKS_TYPE_DWARF_ATTRIBUTE c_type_dwarf_attribute + #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING #define LANG_HOOKS_OMP_PREDETERMINED_SHARING c_omp_predetermined_sharing diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 1fba9c8dae7..22b0009874b 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -731,6 +731,7 @@ extern bool c_warn_unused_global_decl (const_tree); extern void c_initialize_diagnostics (diagnostic_context *); extern bool c_var_mod_p (tree x, tree fn); extern alias_set_type c_get_alias_set (tree); +extern int c_type_dwarf_attribute (const_tree, int); /* in c-typeck.cc */ extern int in_alignof; diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 85dde0459fa..86e0b49d46b 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -410,6 +410,11 @@ cp_type_dwarf_attribute (const_tree type, int attr) return 1; break; + case DW_AT_export_symbols: + if (ANON_AGGR_TYPE_P (type)) + return 1; + break; + default: break; } diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 03d73f9eecd..87e4240b871 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); } diff --git a/gcc/testsuite/c-c++-common/dwarf2/pr113918.c b/gcc/testsuite/c-c++-common/dwarf2/pr113918.c new file mode 100644 index 00000000000..f72a6c4338f --- /dev/null +++ b/gcc/testsuite/c-c++-common/dwarf2/pr113918.c @@ -0,0 +1,33 @@ +/* PR debug/113918 */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf-5 -dA -fno-merge-debug-strings" } */ + +struct S { + union { + int i; + long long j; + }; + struct { + int k; + long long l; + }; + union { + int m; + long long n; + } u; + struct { + int o; + long long p; + } v; +} s; + +int +main () +{ + s.i = 1; + s.k = 2; + s.u.m = 3; + s.v.o = 4; +} + +/* { dg-final { scan-assembler-times "DW_AT_export_symbols" 4 } } */