Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions tests/expectations/tests/bitfield-large.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
9 changes: 9 additions & 0 deletions tests/headers/bitfield-large.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct HasBigBitfield {
__int128 x : 128;
};


struct HasTwoBigBitfields {
__int128 x : 80;
__int128 y : 48;
};