diff options
-rw-r--r-- | src/codegen/mod.rs | 16 | ||||
-rw-r--r-- | tests/expectations/tests/bitfield-large.rs | 32 | ||||
-rw-r--r-- | tests/headers/bitfield-large.hpp | 9 |
3 files changed, 49 insertions, 8 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5a89e5c8..579e9de1 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 00000000..d4fe9694 --- /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::<HasBigBitfield>() , 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::<HasTwoBigBitfields>() , 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 00000000..2e349279 --- /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; +}; |