aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-09-03 09:46:32 +0200
committerJakub Jelinek <jakub@redhat.com>2021-09-03 09:46:32 +0200
commite902136b310ee17d4b49eb42d9d5e487d5dcf4a1 (patch)
tree65ed287d91cb135d037fcf227a333d099a589bce /gcc/tree.h
parentde6795bbf58c7085933a1f86a88d8193ea72e26b (diff)
downloadgcc-e902136b310ee17d4b49eb42d9d5e487d5dcf4a1.zip
gcc-e902136b310ee17d4b49eb42d9d5e487d5dcf4a1.tar.gz
gcc-e902136b310ee17d4b49eb42d9d5e487d5dcf4a1.tar.bz2
c++, abi: Set DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD on C++ zero width bitfields [PR102024]
The removal of remove_zero_width_bitfields function and its call from C++ FE layout_class_type (which I've done in the P0466R5 layout-compatible helper intrinsics patch, so that the FE can actually determine what is and isn't layout-compatible according to the spec) unfortunately changed the ABI on various platforms. The C FE has been keeping zero-width bitfields in the types, while the C++ FE has been removing them after structure layout, so in various cases when passing such structures in registers we had different ABI between C and C++. While both the C and C++ FE had some code to remove zero width bitfields after structure layout, in both FEs it was buggy and didn't really remove any. In the C FE that code has been removed later on, while in the C++ FE for GCC 4.5 in PR42217 it has been actually fixed, so the C++ FE started to remove those bitfields. The following patch doesn't change anything ABI-wise, but allows the targets to decide what to do, emit -Wpsabi warnings etc. Non-C zero width bitfields will be seen by the backends as normal zero width bitfields, C++ zero width bitfields that used to be previously removed will have DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD flag set. I've reused the DECL_FIELD_ABI_IGNORED flag which is only used on non-bitfield FIELD_DECLs right now, but the macros now check DECL_BIT_FIELD flag. Each backend can then decide what it wants, whether it wants to keep different ABI between C and C++ as in GCC 11 and older (i.e. incompatible with G++ <= 4.4, compatible with G++ 4.5 .. 11), for that it would ignore for the aggregate passing/returning decisions all DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD FIELD_DECLs), whether it wants to never ignore zero width bitfields (no changes needed for that case, except perhaps -Wpsabi warning should be added and for that DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD can be tested), or whether it wants to always ignore zero width bitfields (I think e.g. riscv in GCC 10+ does that). All this patch does is set the flag which the backends can then use. 2021-09-03 Jakub Jelinek <jakub@redhat.com> PR target/102024 gcc/ * tree.h (DECL_FIELD_ABI_IGNORED): Changed into rvalue only macro that is false if DECL_BIT_FIELD. (SET_DECL_FIELD_ABI_IGNORED, DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD, SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD): Define. * tree-streamer-out.c (pack_ts_decl_common_value_fields): For DECL_BIT_FIELD stream DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD instead of DECL_FIELD_ABI_IGNORED. * tree-streamer-in.c (unpack_ts_decl_common_value_fields): Use SET_DECL_FIELD_ABI_IGNORED instead of writing to DECL_FIELD_ABI_IGNORED and for DECL_BIT_FIELD use SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD instead. * lto-streamer-out.c (hash_tree): For DECL_BIT_FIELD hash DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD instead of DECL_FIELD_ABI_IGNORED. gcc/cp/ * class.c (build_base_field): Use SET_DECL_FIELD_ABI_IGNORED instead of writing to DECL_FIELD_ABI_IGNORED. (layout_class_type): Likewise. In the place where zero-width bitfields used to be removed, use SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD on those fields instead. gcc/lto/ * lto-common.c (compare_tree_sccs_1): Also compare DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD values.
Diffstat (limited to 'gcc/tree.h')
-rw-r--r--gcc/tree.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/gcc/tree.h b/gcc/tree.h
index 2c8973f..1559fe0 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2852,16 +2852,34 @@ extern void decl_value_expr_insert (tree, tree);
/* 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