https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
--- gcc/expr.c.jj 2021-06-14 12:27:02.000000000 +0200
+++ gcc/expr.c 2021-06-14 22:18:56.852524237 +0200
@@ -5120,15 +5120,18 @@ get_bit_range (poly_uint64_pod *bitstart
poly_int64_pod *bitpos, tree *offset)
{
poly_int64 bitoffset;
- tree field, repr;
gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
- field = TREE_OPERAND (exp, 1);
- repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
- /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
- need to limit the range we can access. */
- if (!repr)
+ tree field = TREE_OPERAND (exp, 1);
+ tree repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
+ tree type = TREE_TYPE (TREE_OPERAND (exp, 0));
+ /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE (except for bitfields
+ in unions) there is no need to limit the range we can access. */
+ if (!repr
+ && (TREE_CODE (type) != UNION_TYPE
+ || !TYPE_SIZE (type)
+ || !tree_fits_poly_uint64_p (TYPE_SIZE (type))))
{
*bitstart = *bitend = 0;
return;
@@ -5153,6 +5156,14 @@ get_bit_range (poly_uint64_pod *bitstart
}
}
+ /* For bitfields in unions, return bitsize of the whole union. */
+ if (!repr)
+ {
+ *bitstart = *bitpos;
+ *bitend = *bitstart + tree_to_poly_uint64 (TYPE_SIZE (type)) - 1;
+ return;
+ }
+
/* Compute the adjustment to bitpos from the offset of the field
relative to the representative. DECL_FIELD_OFFSET of field and
repr are the same by construction if they are not constants,
fixes it for me.