@@ -574,7 +574,13 @@ fn bitfields_to_allocation_units<E, I>(
574
574
. layout ( ctx)
575
575
. expect ( "Bitfield without layout? Gah!" ) ;
576
576
let bitfield_size = bitfield_layout. size ;
577
- let bitfield_align = bitfield_layout. align ;
577
+ let bitfield_align = if bitfield. name ( ) . is_none ( ) {
578
+ // Anonymous bitfields can never be read, so unaligned reads are not
579
+ // a worry, and they don't contribute to alignement.
580
+ 1
581
+ } else {
582
+ bitfield_layout. align
583
+ } ;
578
584
579
585
let mut offset = unit_size_in_bits;
580
586
if is_ms_struct {
@@ -612,20 +618,22 @@ fn bitfields_to_allocation_units<E, I>(
612
618
}
613
619
}
614
620
621
+ max_align = cmp:: max ( max_align, bitfield_align) ;
622
+
623
+ // NB: The `bitfield_width` here is completely, absolutely intentional.
624
+ // Alignment of the allocation unit is based on the maximum bitfield
625
+ // width, not (directly) on the bitfields' types' alignment.
626
+ if bitfield. name ( ) . is_some ( ) {
627
+ unit_align = cmp:: max ( unit_align, bitfield_width) ;
628
+ }
629
+
615
630
// Always keep all bitfields around. While unnamed bitifields are used
616
631
// for padding (and usually not needed hereafter), large unnamed
617
632
// bitfields over their types size cause weird allocation size behavior from clang.
618
633
// Therefore, all bitfields needed to be kept around in order to check for this
619
634
// and make the struct opaque in this case
620
635
bitfields_in_unit. push ( Bitfield :: new ( offset, bitfield) ) ;
621
636
622
- max_align = cmp:: max ( max_align, bitfield_align) ;
623
-
624
- // NB: The `bitfield_width` here is completely, absolutely intentional.
625
- // Alignment of the allocation unit is based on the maximum bitfield
626
- // width, not (directly) on the bitfields' types' alignment.
627
- unit_align = cmp:: max ( unit_align, bitfield_width) ;
628
-
629
637
unit_size_in_bits = offset + bitfield_width;
630
638
631
639
// Compute what the physical unit's final size would be given what we
0 commit comments