DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
- DECL_FIELD_ABI_IGNORED (decl) = 1;
+ SET_DECL_FIELD_ABI_IGNORED (decl, 1);
}
/* An empty virtual base causes a class to be non-empty
}
else if (might_overlap && is_empty_class (type))
{
- DECL_FIELD_ABI_IGNORED (field) = 1;
+ SET_DECL_FIELD_ABI_IGNORED (field, 1);
layout_empty_base_or_field (rli, field, empty_base_offsets);
}
else
normalize_rli (rli);
}
+ /* We used to remove zero width bitfields at this point since PR42217,
+ while the C FE never did that. That caused ABI differences on various
+ targets. Set the DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD flag on them
+ instead, so that the backends can emit -Wpsabi warnings in the cases
+ where the ABI changed. */
+ for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
+ if (TREE_CODE (field) == FIELD_DECL
+ && DECL_C_BIT_FIELD (field)
+ /* We should not be confused by the fact that grokbitfield
+ temporarily sets the width of the bit field into
+ DECL_BIT_FIELD_REPRESENTATIVE (field).
+ check_bitfield_decl eventually sets DECL_SIZE (field)
+ to that width. */
+ && (DECL_SIZE (field) == NULL_TREE
+ || integer_zerop (DECL_SIZE (field))))
+ SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
+
if (CLASSTYPE_NON_LAYOUT_POD_P (t) || CLASSTYPE_EMPTY_P (t))
{
/* T needs a different layout as a base (eliding virtual bases
hstate.add_flag (DECL_PACKED (t));
hstate.add_flag (DECL_NONADDRESSABLE_P (t));
hstate.add_flag (DECL_PADDING_P (t));
- hstate.add_flag (DECL_FIELD_ABI_IGNORED (t));
+ if (DECL_BIT_FIELD (t))
+ hstate.add_flag (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (t));
+ else
+ hstate.add_flag (DECL_FIELD_ABI_IGNORED (t));
hstate.add_int (DECL_OFFSET_ALIGN (t));
}
else if (code == VAR_DECL)
compare_values (DECL_NONADDRESSABLE_P);
compare_values (DECL_PADDING_P);
compare_values (DECL_FIELD_ABI_IGNORED);
+ compare_values (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD);
compare_values (DECL_OFFSET_ALIGN);
}
else if (code == VAR_DECL)
DECL_PACKED (expr) = (unsigned) bp_unpack_value (bp, 1);
DECL_NONADDRESSABLE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
DECL_PADDING_P (expr) = (unsigned) bp_unpack_value (bp, 1);
- DECL_FIELD_ABI_IGNORED (expr) = (unsigned) bp_unpack_value (bp, 1);
+ unsigned val = (unsigned) bp_unpack_value (bp, 1);
+ if (DECL_BIT_FIELD (expr))
+ SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (expr, val);
+ else
+ SET_DECL_FIELD_ABI_IGNORED (expr, val);
expr->decl_common.off_align = bp_unpack_value (bp, 8);
}
bp_pack_value (bp, DECL_PACKED (expr), 1);
bp_pack_value (bp, DECL_NONADDRESSABLE_P (expr), 1);
bp_pack_value (bp, DECL_PADDING_P (expr), 1);
- bp_pack_value (bp, DECL_FIELD_ABI_IGNORED (expr), 1);
+ if (DECL_BIT_FIELD (expr))
+ bp_pack_value (bp, DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (expr), 1);
+ else
+ bp_pack_value (bp, DECL_FIELD_ABI_IGNORED (expr), 1);
bp_pack_value (bp, expr->decl_common.off_align, 8);
}
/* In a FIELD_DECL, indicates this field should be bit-packed. */
#define DECL_PACKED(NODE) (FIELD_DECL_CHECK (NODE)->base.u.bits.packed_flag)
+/* Nonzero in a FIELD_DECL means it is a bit field, and must be accessed
+ specially. */
+#define DECL_BIT_FIELD(NODE) (FIELD_DECL_CHECK (NODE)->decl_common.decl_flag_1)
+
/* In a FIELD_DECL, indicates this field should be ignored for ABI decisions
like passing/returning containing struct by value.
Set for C++17 empty base artificial FIELD_DECLs as well as
empty [[no_unique_address]] non-static data members. */
#define DECL_FIELD_ABI_IGNORED(NODE) \
- (FIELD_DECL_CHECK (NODE)->decl_common.decl_flag_0)
+ (!DECL_BIT_FIELD (NODE) && (NODE)->decl_common.decl_flag_0)
+#define SET_DECL_FIELD_ABI_IGNORED(NODE, VAL) \
+ do { \
+ gcc_checking_assert (!DECL_BIT_FIELD (NODE)); \
+ FIELD_DECL_CHECK (NODE)->decl_common.decl_flag_0 = (VAL); \
+ } while (0)
-/* Nonzero in a FIELD_DECL means it is a bit field, and must be accessed
- specially. */
-#define DECL_BIT_FIELD(NODE) (FIELD_DECL_CHECK (NODE)->decl_common.decl_flag_1)
+/* In a FIELD_DECL, indicates C++ zero-width bitfield that used to be
+ removed from the IL since PR42217 until PR101539 and by that changed
+ the ABI on several targets. This flag is provided so that the backends
+ can decide on the ABI with zero-width bitfields and emit -Wpsabi
+ warnings. */
+#define DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD(NODE) \
+ (DECL_BIT_FIELD (NODE) && (NODE)->decl_common.decl_flag_0)
+#define SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD(NODE, VAL) \
+ do { \
+ gcc_checking_assert (DECL_BIT_FIELD (NODE)); \
+ FIELD_DECL_CHECK (NODE)->decl_common.decl_flag_0 = (VAL); \
+ } while (0)
/* Used in a FIELD_DECL to indicate that we cannot form the address of
this component. This makes it possible for Type-Based Alias Analysis