This patch isn't currently necessary with how I've currently done the
follow-up patches, but is needed for avoiding any potential issues in
the future with DECL_CONTEXT'ful types getting created in the compiler
with no names on the fields.  (For instance, this change would make much
of r15-7342-gd3627c78be116e unnecessary.)

It does take up another flag though in the frontend though.  Another
possible approach would be to instead do a walk through all the fields
first to see if this is the target of a DECL_BIT_FIELD_REPRESENTATIVE;
thoughts?  Or would you prefer to skip this patch entirely?

-- >8 --

Modules streaming needs to handle these differently from other unnamed
FIELD_DECLs that are streamed for internal RECORD_DECLs, and there
doesn't seem to be a good way to detect this case otherwise.

gcc/cp/ChangeLog:

        * module.cc (trees_out::get_merge_kind): Use new flag.

gcc/ChangeLog:

        * stor-layout.cc (start_bitfield_representative): Mark with
        DECL_BIT_FIELD_UNDERLYING_REPR_P.
        * tree-core.h (struct tree_decl_common): Add comment.
        * tree.h (DECL_BIT_FIELD_UNDERLYING_REPR_P): New accessor.

Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
---
 gcc/cp/module.cc   | 4 +---
 gcc/stor-layout.cc | 1 +
 gcc/tree-core.h    | 1 +
 gcc/tree.h         | 5 +++++
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 13f8770b7bd..99cbfdbf01d 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11131,9 +11131,7 @@ trees_out::get_merge_kind (tree decl, depset *dep)
              return MK_named;
            }
 
-         if (!DECL_NAME (decl)
-             && !RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
-             && !DECL_BIT_FIELD_REPRESENTATIVE (decl))
+         if (!DECL_NAME (decl) && DECL_BIT_FIELD_UNDERLYING_REPR_P (decl))
            {
              /* The underlying storage unit for a bitfield.  We do not
                 need to dedup it, because it's only reachable through
diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc
index 12071c96ca7..1f37a130e24 100644
--- a/gcc/stor-layout.cc
+++ b/gcc/stor-layout.cc
@@ -2067,6 +2067,7 @@ static tree
 start_bitfield_representative (tree field)
 {
   tree repr = make_node (FIELD_DECL);
+  DECL_BIT_FIELD_UNDERLYING_REPR_P (repr) = 1;
   DECL_FIELD_OFFSET (repr) = DECL_FIELD_OFFSET (field);
   /* Force the representative to begin at a BITS_PER_UNIT aligned
      boundary - C++ may use tail-padding of a base object to
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index bd19c99d326..2e773d7bf83 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -1911,6 +1911,7 @@ struct GTY(()) tree_decl_common {
   unsigned decl_read_flag : 1;
   /* In a VAR_DECL or RESULT_DECL, this is DECL_NONSHAREABLE.  */
   /* In a PARM_DECL, this is DECL_HIDDEN_STRING_LENGTH.  */
+  /* In a FIELD_DECL, this is DECL_BIT_FIELD_UNDERLYING_REPR_P.  */
   unsigned decl_nonshareable_flag : 1;
 
   /* DECL_OFFSET_ALIGN, used only for FIELD_DECLs.  */
diff --git a/gcc/tree.h b/gcc/tree.h
index 99f26177628..0d876234824 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3085,6 +3085,11 @@ extern void decl_value_expr_insert (tree, tree);
 #define DECL_BIT_FIELD_REPRESENTATIVE(NODE) \
   (FIELD_DECL_CHECK (NODE)->field_decl.qualifier)
 
+/* In a FIELD_DECL of a RECORD_TYPE, this indicates whether the field
+   is used as the underlying storage unit for a bitfield.  */
+#define DECL_BIT_FIELD_UNDERLYING_REPR_P(NODE) \
+  (FIELD_DECL_CHECK (NODE)->decl_common.decl_nonshareable_flag)
+
 /* For a FIELD_DECL in a QUAL_UNION_TYPE, records the expression, which
    if nonzero, indicates that the field occupies the type.  */
 #define DECL_QUALIFIER(NODE) (FIELD_DECL_CHECK (NODE)->field_decl.qualifier)
-- 
2.47.0

Reply via email to