aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-03-08 09:14:32 +0100
committerJakub Jelinek <jakub@redhat.com>2024-03-08 09:29:30 +0100
commit05109b1bd5ef4ee9d78fe17d4563889694a26d05 (patch)
tree8ce23436b07d004c0cb2eff2161e1f7aca20d97e /gcc/c
parent3ecc5071797c4ceb6da67a6c2b2527a046091de2 (diff)
downloadgcc-05109b1bd5ef4ee9d78fe17d4563889694a26d05.zip
gcc-05109b1bd5ef4ee9d78fe17d4563889694a26d05.tar.gz
gcc-05109b1bd5ef4ee9d78fe17d4563889694a26d05.tar.bz2
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 <jakub@redhat.com> 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.
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/c-objc-common.cc23
-rw-r--r--gcc/c/c-objc-common.h3
-rw-r--r--gcc/c/c-tree.h1
3 files changed, 27 insertions, 0 deletions
diff --git a/gcc/c/c-objc-common.cc b/gcc/c/c-objc-common.cc
index 116b73a..b7c72d2 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 35a5998..20af5a5 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 1fba9c8..22b0009 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;