From 669dc1b628b16da33cc382142c53f6377120a3b8 Mon Sep 17 00:00:00 2001 From: Emilio Cobos Álvarez Date: Sun, 20 Dec 2020 17:07:40 +0100 Subject: 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. --- src/codegen/helpers.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src/codegen/helpers.rs') 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 -- cgit v1.2.3