bitsize = (bitsize + BITS_PER_UNIT - 1) & ~(BITS_PER_UNIT - 1);
/* Now nothing tells us how to pad out bitsize ... */
- nextf = DECL_CHAIN (field);
- while (nextf && TREE_CODE (nextf) != FIELD_DECL)
- nextf = DECL_CHAIN (nextf);
+ if (TREE_CODE (DECL_CONTEXT (field)) == RECORD_TYPE)
+ {
+ nextf = DECL_CHAIN (field);
+ while (nextf && TREE_CODE (nextf) != FIELD_DECL)
+ nextf = DECL_CHAIN (nextf);
+ }
+ else
+ nextf = NULL_TREE;
if (nextf)
{
tree maxsize;
tree field, prev;
tree repr = NULL_TREE;
- /* Unions would be special, for the ease of type-punning optimizations
- we could use the underlying type as hint for the representative
- if the bitfield would fit and the representative would not exceed
- the union in size. */
- if (TREE_CODE (t) != RECORD_TYPE)
- return;
-
for (prev = NULL_TREE, field = TYPE_FIELDS (t);
field; field = DECL_CHAIN (field))
{
if (repr)
DECL_BIT_FIELD_REPRESENTATIVE (field) = repr;
- prev = field;
+ if (TREE_CODE (t) == RECORD_TYPE)
+ prev = field;
+ else if (repr)
+ {
+ finish_bitfield_representative (repr, field);
+ repr = NULL_TREE;
+ }
}
if (repr)
--- /dev/null
+/* PR middle-end/101062 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-toplevel-reorder -frename-registers" } */
+
+union U { signed b : 5; };
+int c;
+volatile union U d[7] = { { 8 } };
+short e = 1;
+
+__attribute__((noipa)) void
+foo ()
+{
+ d[6].b = 0;
+ d[6].b = 0;
+ d[6].b = 0;
+ d[6].b = 0;
+ d[6].b = 0;
+ e = 0;
+ c = 0;
+}
+
+int
+main ()
+{
+ foo ();
+ if (e != 0)
+ __builtin_abort ();
+ return 0;
+}