summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-11-01 01:06:21 -0500
committerGitHub <noreply@github.com>2017-11-01 01:06:21 -0500
commitddb680b27db6581070b7b4fb03ea1119167a0bd3 (patch)
treee5c385a8060cddda62009b9d4f979757c93bf1fb /src
parent55cf63c08c539df2a8c5437c062dda5fb57a8b18 (diff)
parente17bd8df3fbd686fa0857b2e09d6e38c9fb6262c (diff)
Auto merge of #1130 - fitzgen:issue-1076, r=pepyakin
Unnamed bit-fields and alignment r? @pepyakin or @emilio
Diffstat (limited to 'src')
-rw-r--r--src/ir/comp.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index 56e41d52..7265660c 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -595,12 +595,8 @@ fn bitfields_to_allocation_units<E, I>(
// Now we're working on a fresh bitfield allocation unit, so reset
// the current unit size and alignment.
- #[allow(unused_assignments)]
- {
- unit_size_in_bits = 0;
- offset = 0;
- unit_align = 0;
- }
+ offset = 0;
+ unit_align = 0;
}
} else {
if offset != 0 &&
@@ -612,6 +608,21 @@ fn bitfields_to_allocation_units<E, I>(
}
}
+ // According to the x86[-64] ABI spec: "Unnamed bit-fields’ types do not
+ // affect the alignment of a structure or union". This makes sense: such
+ // bit-fields are only used for padding, and we can't perform an
+ // un-aligned read of something we can't read because we can't even name
+ // it.
+ if bitfield.name().is_some() {
+ max_align = cmp::max(max_align, bitfield_align);
+
+ // NB: The `bitfield_width` here is completely, absolutely
+ // intentional. Alignment of the allocation unit is based on the
+ // maximum bitfield width, not (directly) on the bitfields' types'
+ // alignment.
+ unit_align = cmp::max(unit_align, bitfield_width);
+ }
+
// Always keep all bitfields around. While unnamed bitifields are used
// for padding (and usually not needed hereafter), large unnamed
// bitfields over their types size cause weird allocation size behavior from clang.
@@ -619,13 +630,6 @@ fn bitfields_to_allocation_units<E, I>(
// and make the struct opaque in this case
bitfields_in_unit.push(Bitfield::new(offset, bitfield));
- max_align = cmp::max(max_align, bitfield_align);
-
- // NB: The `bitfield_width` here is completely, absolutely intentional.
- // Alignment of the allocation unit is based on the maximum bitfield
- // width, not (directly) on the bitfields' types' alignment.
- unit_align = cmp::max(unit_align, bitfield_width);
-
unit_size_in_bits = offset + bitfield_width;
// Compute what the physical unit's final size would be given what we