#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 **);
{
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;
+}
#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
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;
return 1;
break;
+ case DW_AT_export_symbols:
+ if (ANON_AGGR_TYPE_P (type))
+ return 1;
+ break;
+
default:
break;
}
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);
}
--- /dev/null
+/* 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 } } */