summaryrefslogtreecommitdiff
path: root/src/codegen/helpers.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2020-12-20 17:07:40 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2020-12-20 21:29:47 +0100
commit669dc1b628b16da33cc382142c53f6377120a3b8 (patch)
treef08354425b49284f14abf02db51e817fc52b2d06 /src/codegen/helpers.rs
parent98841b32ed51e4474377712aa636251d9a4f7215 (diff)
comp: Fix bitfields to allow underaligned fields after them to take padding space.
Fixes #1947. There are two separate issues here: First, the change in comp.rs ensures that we don't round up the amount of storage to the alignment of the bitfield. That generates the "expected" output in #1947 (`__BindgenBitfieldUnit<[u8; 3], u16>`). But that's still not enough to fix that test-case because __BindgenBitfieldUnit would be aligned and have padding, and Rust won't put the extra field in the padding. In order to ensure the bitfield starts at the right alignment, but that Rust can put stuff in the extra field, we need to make a breaking change and split the generated fields in two: One preceding that guarantees alignment, and the actual storage, bit-aligned. This keeps the existing behavior while fixing that test-case.
Diffstat (limited to 'src/codegen/helpers.rs')
-rw-r--r--src/codegen/helpers.rs9
1 files changed, 1 insertions, 8 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index b6825f5e..205995bc 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -120,16 +120,9 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> TokenStream {
tokens.append_all(quote! { root:: });
}
- let align = match layout.align {
- n if n >= 8 => quote! { u64 },
- 4 => quote! { u32 },
- 2 => quote! { u16 },
- _ => quote! { u8 },
- };
-
let size = layout.size;
tokens.append_all(quote! {
- __BindgenBitfieldUnit<[u8; #size], #align>
+ __BindgenBitfieldUnit<[u8; #size]>
});
tokens