diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/class.c | 21 | ||||
-rw-r--r-- | gcc/lto-streamer-out.c | 5 | ||||
-rw-r--r-- | gcc/lto/lto-common.c | 1 | ||||
-rw-r--r-- | gcc/tree-streamer-in.c | 6 | ||||
-rw-r--r-- | gcc/tree-streamer-out.c | 5 | ||||
-rw-r--r-- | gcc/tree.h | 26 |
6 files changed, 55 insertions, 9 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 17876c7..fe225c6 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -4634,7 +4634,7 @@ build_base_field (record_layout_info rli, tree binfo, tree access, 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 @@ -6658,7 +6658,7 @@ layout_class_type (tree t, tree *virtuals_p) } 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 @@ -6746,6 +6746,23 @@ layout_class_type (tree t, tree *virtuals_p) 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 diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c index a26d488..643d927 100644 --- a/gcc/lto-streamer-out.c +++ b/gcc/lto-streamer-out.c @@ -1271,7 +1271,10 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, 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) diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c index bfe52a2..3eba431 100644 --- a/gcc/lto/lto-common.c +++ b/gcc/lto/lto-common.c @@ -1187,6 +1187,7 @@ compare_tree_sccs_1 (tree t1, tree t2, tree **map) 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) diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c index e0522bf..848981a 100644 --- a/gcc/tree-streamer-in.c +++ b/gcc/tree-streamer-in.c @@ -256,7 +256,11 @@ unpack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr) 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); } diff --git a/gcc/tree-streamer-out.c b/gcc/tree-streamer-out.c index 855d1cd..1f9ce52 100644 --- a/gcc/tree-streamer-out.c +++ b/gcc/tree-streamer-out.c @@ -219,7 +219,10 @@ pack_ts_decl_common_value_fields (struct bitpack_d *bp, tree expr) 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); } @@ -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 |