@@ -595,12 +595,8 @@ fn bitfields_to_allocation_units<E, I>(
595
595
596
596
// Now we're working on a fresh bitfield allocation unit, so reset
597
597
// the current unit size and alignment.
598
- #[ allow( unused_assignments) ]
599
- {
600
- unit_size_in_bits = 0 ;
601
- offset = 0 ;
602
- unit_align = 0 ;
603
- }
598
+ offset = 0 ;
599
+ unit_align = 0 ;
604
600
}
605
601
} else {
606
602
if offset != 0 &&
@@ -612,20 +608,28 @@ fn bitfields_to_allocation_units<E, I>(
612
608
}
613
609
}
614
610
611
+ // According to the x86[-64] ABI spec: "Unnamed bit-fields’ types do not
612
+ // affect the alignment of a structure or union". This makes sense: such
613
+ // bit-fields are only used for padding, and we can't perform an
614
+ // un-aligned read of something we can't read because we can't even name
615
+ // it.
616
+ if bitfield. name ( ) . is_some ( ) {
617
+ max_align = cmp:: max ( max_align, bitfield_align) ;
618
+
619
+ // NB: The `bitfield_width` here is completely, absolutely
620
+ // intentional. Alignment of the allocation unit is based on the
621
+ // maximum bitfield width, not (directly) on the bitfields' types'
622
+ // alignment.
623
+ unit_align = cmp:: max ( unit_align, bitfield_width) ;
624
+ }
625
+
615
626
// Always keep all bitfields around. While unnamed bitifields are used
616
627
// for padding (and usually not needed hereafter), large unnamed
617
628
// bitfields over their types size cause weird allocation size behavior from clang.
618
629
// Therefore, all bitfields needed to be kept around in order to check for this
619
630
// and make the struct opaque in this case
620
631
bitfields_in_unit. push ( Bitfield :: new ( offset, bitfield) ) ;
621
632
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
633
unit_size_in_bits = offset + bitfield_width;
630
634
631
635
// Compute what the physical unit's final size would be given what we
0 commit comments