diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ee4a9d4e78..c203795a62 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -913,20 +913,20 @@ fn flush_bitfields<'a, I>(ctx: &BindgenContext, .pub_() .build_ty(field_ty.clone()); + let field_int_ty = match field_layout.size { + 8 => quote_ty!(ctx.ext_cx(), u64), + 4 => quote_ty!(ctx.ext_cx(), u32), + 2 => quote_ty!(ctx.ext_cx(), u16), + 1 => quote_ty!(ctx.ext_cx(), u8), + _ => return field + }; + for (name, offset, width, bitfield_ty, bitfield_layout) in bitfields { let prefix = ctx.trait_prefix(); let getter_name = bitfield_getter_name(ctx, parent, name); let setter_name = bitfield_setter_name(ctx, parent, name); let field_ident = ctx.ext_cx().ident_of(field_name); - let field_int_ty = match field_layout.size { - 8 => quote_ty!(ctx.ext_cx(), u64), - 4 => quote_ty!(ctx.ext_cx(), u32), - 2 => quote_ty!(ctx.ext_cx(), u16), - 1 => quote_ty!(ctx.ext_cx(), u8), - _ => panic!("physical field containing bitfields should be sized \ - 8, 4, 2, or 1 bytes") - }; let bitfield_int_ty = BlobTyBuilder::new(bitfield_layout).build(); let mask: usize = ((1usize << width) - 1usize) << offset; diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs new file mode 100644 index 0000000000..d4fe96948a --- /dev/null +++ b/tests/expectations/tests/bitfield-large.rs @@ -0,0 +1,32 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct HasBigBitfield { + pub _bitfield_1: [u8; 16usize], +} +#[test] +fn bindgen_test_layout_HasBigBitfield() { + assert_eq!(::std::mem::size_of::() , 16usize , concat ! ( + "Size of: " , stringify ! ( HasBigBitfield ) )); +} +impl Clone for HasBigBitfield { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct HasTwoBigBitfields { + pub _bitfield_1: [u8; 16usize], +} +#[test] +fn bindgen_test_layout_HasTwoBigBitfields() { + assert_eq!(::std::mem::size_of::() , 16usize , concat + ! ( "Size of: " , stringify ! ( HasTwoBigBitfields ) )); +} +impl Clone for HasTwoBigBitfields { + fn clone(&self) -> Self { *self } +} diff --git a/tests/headers/bitfield-large.hpp b/tests/headers/bitfield-large.hpp new file mode 100644 index 0000000000..2e34927929 --- /dev/null +++ b/tests/headers/bitfield-large.hpp @@ -0,0 +1,9 @@ +struct HasBigBitfield { + __int128 x : 128; +}; + + +struct HasTwoBigBitfields { + __int128 x : 80; + __int128 y : 48; +};