diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c2d328069..fbbf29c1e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,53 +9,56 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-1) -- [0.47.2](#0472) - [Fixed](#fixed-1) -- [0.47.1](#0471) +- [0.47.3](#0473) - [Changed](#changed-2) +- [0.47.2](#0472) - [Fixed](#fixed-2) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-3) - [Fixed](#fixed-3) +- [0.47.0](#0470) + - [Changed](#changed-4) + - [Fixed](#fixed-4) - [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-1) - [Removed](#removed-1) - - [Changed](#changed-4) - - [Fixed](#fixed-4) -- [0.33.1](#0331) + - [Changed](#changed-5) - [Fixed](#fixed-5) +- [0.33.1](#0331) + - [Fixed](#fixed-6) - [0.33.0](#0330) - [Added](#added-2) - - [Changed](#changed-5) + - [Changed](#changed-6) - [Deprecated](#deprecated-1) - [Removed](#removed-2) - - [Fixed](#fixed-6) + - [Fixed](#fixed-7) - [Security](#security-1) - [0.32.2](#0322) - - [Fixed](#fixed-7) -- [0.32.1](#0321) - [Fixed](#fixed-8) +- [0.32.1](#0321) + - [Fixed](#fixed-9) - [0.32.0](#0320) - [Added](#added-3) - - [Changed](#changed-6) - - [Fixed](#fixed-9) + - [Changed](#changed-7) + - [Fixed](#fixed-10) - [0.31.0](#0310) - [Added](#added-4) - - [Changed](#changed-7) + - [Changed](#changed-8) - [Deprecated](#deprecated-2) - [Removed](#removed-3) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [0.30.0](#0300) - [Added](#added-5) - - [Changed](#changed-8) + - [Changed](#changed-9) - [Deprecated](#deprecated-3) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [0.29.0](#0290) - [Added](#added-6) - - [Changed](#changed-9) - - [Fixed](#fixed-12) + - [Changed](#changed-10) + - [Fixed](#fixed-13) @@ -89,6 +92,25 @@ Released YYYY/MM/DD * TODO (or remove section if none) + +-------------------------------------------------------------------------------- + +# 0.48.0 + +Released 2019/03/04 + +## Changed + +* Default rust target was changed to 1.33, which means that bindgen can get much + more often the layout of structs right. [#1529][] + +## Fixed + +* Bindgen will output repr(align) just when needed for unions. [#1498][] + +[#1529]: https://github.com/rust-lang-nursery/rust-bindgen/issues/1529 +[#1498]: https://github.com/rust-lang-nursery/rust-bindgen/issues/1498 + -------------------------------------------------------------------------------- # 0.47.3 diff --git a/Cargo.lock b/Cargo.lock index 4634e28e21..34e54e9b31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.47.3" +version = "0.48.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index bebbbffe35..7e0b014b4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.47.3" +version = "0.48.0" build = "build.rs" include = [ diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 04617ff31f..8374e2084a 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -179,7 +179,6 @@ fn test_bitfield_constructors() { let mut second = bindings::bitfields::Second { _bitfield_1: bindings::bitfields::Second::new_bitfield_1(1337, true), - __bindgen_align: [], }; assert!(unsafe { second.assert(1337, true) }); @@ -189,7 +188,6 @@ fn test_bitfield_constructors() { false, bindings::bitfields::ItemKind::ITEM_KIND_TRES, ), - __bindgen_align: [], }; assert!(unsafe { third.assert(42, false, bindings::bitfields::ItemKind::ITEM_KIND_TRES) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 2d71942ca2..d7f98c139a 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1589,6 +1589,7 @@ impl CodeGenerator for CompInfo { // TODO(emilio): It'd be nice to unify this with the struct path // above somehow. let layout = layout.expect("Unable to get layout information?"); + struct_layout.saw_union(layout); if struct_layout.requires_explicit_align(layout) { explicit_align = Some(layout.align); @@ -1600,8 +1601,6 @@ impl CodeGenerator for CompInfo { _bindgen_union_align: #ty , } } else { - struct_layout.saw_union(layout); - quote! { pub bindgen_union_field: #ty , } diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 921ab2159c..29d281aa4b 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -85,9 +85,9 @@ impl<'a> StructLayoutTracker<'a> { name: &'a str, ) -> Self { StructLayoutTracker { - name: name, - ctx: ctx, - comp: comp, + name, + ctx, + comp, is_packed: comp.is_packed(ctx, &ty.layout(ctx)), latest_offset: 0, padding_count: 0, diff --git a/src/features.rs b/src/features.rs index b5a6340246..50759c3189 100644 --- a/src/features.rs +++ b/src/features.rs @@ -114,7 +114,7 @@ rust_target_base!(rust_target_def); rust_target_base!(rust_target_values_def); /// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_21; +pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_33; /// Create RustFeatures struct definition, new(), and a getter for each field macro_rules! rust_feature_def { diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 84383c3575..3a9e89984a 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] @@ -271,11 +274,12 @@ impl Default for rte_ipv6_tuple { } } #[repr(C)] +#[repr(align(16))] #[derive(Copy, Clone)] pub union rte_thash_tuple { pub v4: rte_ipv4_tuple, pub v6: rte_ipv6_tuple, - _bindgen_union_align: [u8; 48usize], + _bindgen_union_align: [u128; 3usize], } #[test] fn bindgen_test_layout_rte_thash_tuple() { @@ -284,6 +288,11 @@ fn bindgen_test_layout_rte_thash_tuple() { 48usize, concat!("Size of: ", stringify!(rte_thash_tuple)) ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(rte_thash_tuple)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).v4 as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index d59ed05cf7..49a771ac6b 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -9,6 +9,7 @@ ///
#[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct D { pub _bindgen_opaque_blob: u32, diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 6916d5afe8..5b5ed43c9e 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index 2142776e65..7a3dd3562b 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -45,7 +45,7 @@ impl ::std::ops::BitAndAssign for Foo { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Foo(pub i32); impl Buz { @@ -86,7 +86,7 @@ impl ::std::ops::BitAndAssign for Buz { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Buz(pub i8); pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1); @@ -117,7 +117,7 @@ impl ::std::ops::BitAndAssign for _bindgen_ty_1 { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct _bindgen_ty_1(pub u32); #[repr(C)] @@ -153,7 +153,7 @@ impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Dummy__bindgen_ty_1(pub u32); #[test] diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs index 408c2a0ed5..1791cd32ca 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -90,6 +90,7 @@ where } } #[repr(C)] +#[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct HasBigBitfield { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u64>, @@ -101,8 +102,37 @@ fn bindgen_test_layout_HasBigBitfield() { 16usize, concat!("Size of: ", stringify!(HasBigBitfield)) ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(HasBigBitfield)) + ); +} +impl HasBigBitfield { + #[inline] + pub fn x(&self) -> i128 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 128u8) as u128) } + } + #[inline] + pub fn set_x(&mut self, val: i128) { + unsafe { + let val: u128 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 128u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize], u64> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize], u64> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 128u8, { + let x: u128 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }); + __bindgen_bitfield_unit + } } #[repr(C)] +#[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct HasTwoBigBitfields { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u64>, @@ -114,4 +144,47 @@ fn bindgen_test_layout_HasTwoBigBitfields() { 16usize, concat!("Size of: ", stringify!(HasTwoBigBitfields)) ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(HasTwoBigBitfields)) + ); +} +impl HasTwoBigBitfields { + #[inline] + pub fn x(&self) -> i128 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 80u8) as u128) } + } + #[inline] + pub fn set_x(&mut self, val: i128) { + unsafe { + let val: u128 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 80u8, val as u64) + } + } + #[inline] + pub fn y(&self) -> i128 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128) } + } + #[inline] + pub fn set_y(&mut self, val: i128) { + unsafe { + let val: u128 = ::std::mem::transmute(val); + self._bitfield_1.set(80usize, 48u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1(x: i128, y: i128) -> __BindgenBitfieldUnit<[u8; 16usize], u64> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize], u64> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 80u8, { + let x: u128 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }); + __bindgen_bitfield_unit.set(80usize, 48u8, { + let y: u128 = unsafe { ::std::mem::transmute(y) }; + y as u64 + }); + __bindgen_bitfield_unit + } } diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index c7758c5a04..35e9479bab 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -90,12 +90,12 @@ where } } #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct A { pub x: ::std::os::raw::c_uchar, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, pub y: ::std::os::raw::c_uchar, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_A() { @@ -290,10 +290,10 @@ impl A { } } #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct B { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_B() { @@ -421,11 +421,11 @@ impl C { } } #[repr(C)] +#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize], u8>, pub __bindgen_padding_0: u8, - pub __bindgen_align: [u16; 0usize], } #[test] fn bindgen_test_layout_Date1() { @@ -514,10 +514,10 @@ impl Date1 { } } #[repr(C)] +#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date2 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u8>, - pub __bindgen_align: [u16; 0usize], } #[test] fn bindgen_test_layout_Date2() { @@ -622,11 +622,11 @@ impl Date2 { } } #[repr(C)] +#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date3 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize], u8>, pub byte: ::std::os::raw::c_uchar, - pub __bindgen_align: [u16; 0usize], } #[test] fn bindgen_test_layout_Date3() { diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index 39ab0eeff8..6f93397fc6 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -98,10 +98,10 @@ pub enum MyEnum { FOUR = 3, } #[repr(C)] +#[repr(align(8))] #[derive(Debug, Copy, Clone)] pub struct TaggedPtr { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_TaggedPtr() { diff --git a/tests/expectations/tests/bitfield_large_overflow.rs b/tests/expectations/tests/bitfield_large_overflow.rs index e5b254cf76..7df5b937f8 100644 --- a/tests/expectations/tests/bitfield_large_overflow.rs +++ b/tests/expectations/tests/bitfield_large_overflow.rs @@ -1,10 +1,14 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] +#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { pub _bindgen_opaque_blob: [u64; 10usize], diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index 0089d2c7af..8ebb778d69 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -90,10 +90,10 @@ where } } #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct mach_msg_type_descriptor_t { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_mach_msg_type_descriptor_t() { diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 265d7c5bfc..577dec6f55 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index e6abee16d6..325fc267e4 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -19,7 +19,7 @@ pub struct foo { pub bar: ::std::os::raw::c_float, pub baz: ::std::os::raw::c_float, pub bazz: ::std::os::raw::c_double, - pub bazzz: *mut f64, + pub bazzz: *mut u128, pub complexFloat: __BindgenComplex<::std::os::raw::c_float>, pub complexDouble: __BindgenComplex<::std::os::raw::c_double>, } diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index fbf518bdf7..9c72fbbd1e 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] @@ -104,9 +107,7 @@ impl ::std::fmt::Debug for perf_event_attr { write!( f, "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}", - self.type_, - self.a, - self.__bindgen_anon_1 + self.type_, self.a, self.__bindgen_anon_1 ) } } diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index d7f8878b94..bc7d9fd6be 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -1,10 +1,14 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] +#[repr(align(4))] pub struct Opaque { pub _bindgen_opaque_blob: [u32; 41usize], } diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/tests/expectations/tests/derive-partialeq-anonfield.rs index 73972d70d7..b5cb15937d 100644 --- a/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -1,10 +1,14 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct rte_mbuf { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, @@ -39,6 +43,11 @@ fn bindgen_test_layout_rte_mbuf() { 0usize, concat!("Size of: ", stringify!(rte_mbuf)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mbuf)) + ); } impl Default for rte_mbuf { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 4ce1a3fe3f..2ac23c8120 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index 5a7aa86f92..216889146e 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -55,6 +55,7 @@ fn bindgen_test_layout_Null() { /// probably emit an opaque struct for opaque unions... but until then, we have /// this test to make sure that opaque unions don't derive and still compile. #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union DoggoOrNull { pub _bindgen_opaque_blob: u32, diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 19172d0b49..a5ba04efba 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] impl Foo { pub const Bar: Foo = Foo(0); @@ -34,7 +39,7 @@ impl ::std::ops::BitAndAssign for Foo { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Foo(pub u32); pub mod Neg { diff --git a/tests/expectations/tests/enum-doc-bitfield.rs b/tests/expectations/tests/enum-doc-bitfield.rs index 9ebfc10e40..5fe668be07 100644 --- a/tests/expectations/tests/enum-doc-bitfield.rs +++ b/tests/expectations/tests/enum-doc-bitfield.rs @@ -60,7 +60,7 @@ impl ::std::ops::BitAndAssign for B { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] /// Document enum #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct B(pub u32); diff --git a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs index 8c70625e37..8c58b232c7 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] impl MyDupeEnum { pub const A: MyDupeEnum = MyDupeEnum(0); @@ -37,7 +42,7 @@ impl ::std::ops::BitAndAssign for MyDupeEnum { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct MyDupeEnum(pub u32); impl MyOtherDupeEnum { @@ -75,6 +80,6 @@ impl ::std::ops::BitAndAssign for MyOtherDupeEnum { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct MyOtherDupeEnum(pub u32); diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index 7b2c0ae9d4..77df620b02 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] pub struct foo { diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs new file mode 100644 index 0000000000..0f9ef68031 --- /dev/null +++ b/tests/expectations/tests/issue-1498.rs @@ -0,0 +1,153 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C, packed)] +#[derive(Copy, Clone)] +pub struct rte_memseg { + ///< Start physical address. + pub phys_addr: u64, + pub __bindgen_anon_1: rte_memseg__bindgen_ty_1, + ///< Length of the segment. + pub len: usize, + ///< The pagesize of underlying memory + pub hugepage_sz: u64, + ///< NUMA socket ID. + pub socket_id: i32, + ///< Number of channels. + pub nchannel: u32, + ///< Number of ranks. + pub nrank: u32, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union rte_memseg__bindgen_ty_1 { + ///< Start virtual address. + pub addr: *mut ::std::os::raw::c_void, + ///< Makes sure addr is always 64 bits + pub addr_64: u64, + _bindgen_union_align: u64, +} +#[test] +fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_memseg__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).addr as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).addr_64 as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr_64) + ) + ); +} +impl Default for rte_memseg__bindgen_ty_1 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[test] +fn bindgen_test_layout_rte_memseg() { + assert_eq!( + ::std::mem::size_of::(), + 44usize, + concat!("Size of: ", stringify!(rte_memseg)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(rte_memseg)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).phys_addr as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(phys_addr) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).hugepage_sz as *const _ as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(hugepage_sz) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).socket_id as *const _ as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(socket_id) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).nchannel as *const _ as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(nchannel) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).nrank as *const _ as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(nrank) + ) + ); +} +impl Default for rte_memseg { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index c13101d0a9..e7e5c5579c 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs index 94c6dd3b3f..aaaa9f195e 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -39,10 +39,10 @@ fn bindgen_test_layout_AlignedToOne() { } /// This should be opaque because although we can see the attributes, Rust before /// 1.33 doesn't have `#[repr(packed(N))]`. -#[repr(C)] +#[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToTwo { - pub _bindgen_opaque_blob: [u16; 2usize], + pub i: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_AlignedToTwo() { @@ -56,6 +56,16 @@ fn bindgen_test_layout_AlignedToTwo() { 2usize, concat!("Alignment of ", stringify!(AlignedToTwo)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToTwo), + "::", + stringify!(i) + ) + ); } /// This should not be opaque because although `libclang` doesn't give us the /// `#pragma pack(1)`, we can detect that alignment is 1 and add @@ -102,10 +112,11 @@ fn bindgen_test_layout_PackedToOne() { /// In this case, even if we can detect the weird alignment triggered by /// `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 /// doesn't have `#[repr(packed(N))]`. Therefore, we must make it opaque. -#[repr(C)] +#[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToTwo { - pub _bindgen_opaque_blob: [u16; 4usize], + pub x: ::std::os::raw::c_int, + pub y: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_PackedToTwo() { @@ -119,4 +130,24 @@ fn bindgen_test_layout_PackedToTwo() { 2usize, concat!("Alignment of ", stringify!(PackedToTwo)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(y) + ) + ); } diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index ddd8545517..15f0209410 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -12,6 +12,7 @@ /// up with the reight alignment, we're waiting on `#[repr(align="N")]` to land /// in rustc). #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct NoDebug { pub c: ::std::os::raw::c_char, @@ -24,6 +25,11 @@ fn bindgen_test_layout_NoDebug() { 64usize, concat!("Size of: ", stringify!(NoDebug)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(NoDebug)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, 0usize, @@ -50,6 +56,7 @@ impl ::std::cmp::PartialEq for NoDebug { /// we determine Debug derive-ability before we compute padding, which happens at /// codegen. (Again, we expect to get the alignment wrong for similar reasons.) #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct ShouldDeriveDebugButDoesNot { pub c: [::std::os::raw::c_char; 32usize], @@ -63,6 +70,11 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { 64usize, concat!("Size of: ", stringify!(ShouldDeriveDebugButDoesNot)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index ce0066560d..ca56ccceb0 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -90,10 +90,10 @@ where } } #[repr(C)] +#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 32usize], u64>, - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_Foo() { diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 76deebbaa5..f6356c497d 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -8,6 +13,7 @@ pub struct A { _unused: [u8; 0], } #[repr(C)] +#[repr(align(1))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct B { pub _bindgen_opaque_blob: u8, diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index 0b1c020d82..798a9f8fab 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -59,6 +62,7 @@ fn bindgen_test_layout_SuchWow() { ); } #[repr(C)] +#[repr(align(1))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque { pub _bindgen_opaque_blob: u8, diff --git a/tests/expectations/tests/issue-816.rs b/tests/expectations/tests/issue-816.rs index d7be76ce01..b5e30fbedd 100644 --- a/tests/expectations/tests/issue-816.rs +++ b/tests/expectations/tests/issue-816.rs @@ -90,10 +90,10 @@ where } } #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct capabilities { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u8>, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_capabilities() { diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 00b4301cc2..aa0420aa0b 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -188,10 +188,10 @@ pub union jsval_layout { _bindgen_union_align: u64, } #[repr(C)] +#[repr(align(8))] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { diff --git a/tests/expectations/tests/layout.rs b/tests/expectations/tests/layout.rs index 2790446c1a..3053122d12 100644 --- a/tests/expectations/tests/layout.rs +++ b/tests/expectations/tests/layout.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] pub struct header { diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 39fb294857..e655b9dc8f 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -126,6 +126,7 @@ impl ::std::clone::Clone for __IncompleteArrayField { } } #[repr(C)] +#[repr(align(8))] #[derive(Debug)] pub struct rte_kni_fifo { ///< Next position to be written @@ -138,7 +139,6 @@ pub struct rte_kni_fifo { pub elem_size: ::std::os::raw::c_uint, ///< The buffer contains mbuf pointers pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_rte_kni_fifo() { @@ -159,13 +159,13 @@ impl Default for rte_kni_fifo { } } #[repr(C)] +#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct rte_eth_link { ///< ETH_SPEED_NUM_ pub link_speed: u32, pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, pub __bindgen_padding_0: [u8; 3usize], - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_rte_eth_link() { diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 2fd93c4ae9..0da08871e7 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -49,6 +49,7 @@ pub type rte_mempool_get_count = ::std::option::Option ::std::os::raw::c_uint>; /// Structure defining mempool operations structure #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct rte_mempool_ops { ///< Name of mempool ops struct. @@ -72,6 +73,11 @@ fn bindgen_test_layout_rte_mempool_ops() { 128usize, concat!("Size of: ", stringify!(rte_mempool_ops)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mempool_ops)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).name as *const _ as usize }, 0usize, @@ -186,6 +192,7 @@ fn bindgen_test_layout_rte_spinlock_t() { /// any function pointers stored directly in the mempool struct would not be. /// This results in us simply having "ops_index" in the mempool struct. #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct rte_mempool_ops_table { ///< Spinlock for add/delete. @@ -203,6 +210,11 @@ fn bindgen_test_layout_rte_mempool_ops_table() { 2112usize, concat!("Size of: ", stringify!(rte_mempool_ops_table)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mempool_ops_table)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).sl as *const _ as usize }, 0usize, @@ -241,6 +253,7 @@ impl Default for rte_mempool_ops_table { } /// Structure to hold malloc heap #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct malloc_heap { pub lock: rte_spinlock_t, @@ -290,6 +303,11 @@ fn bindgen_test_layout_malloc_heap() { 128usize, concat!("Size of: ", stringify!(malloc_heap)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(malloc_heap)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).lock as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index 91c74d4bfe..27dd96ff4c 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -140,6 +140,7 @@ fn bindgen_test_layout_ip_frag_key() { /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct ip_frag_pkt { ///< LRU list @@ -213,6 +214,11 @@ fn bindgen_test_layout_ip_frag_pkt() { 192usize, concat!("Size of: ", stringify!(ip_frag_pkt)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ip_frag_pkt)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).lru as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index cd45688155..fd8047aef9 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -10,6 +10,7 @@ pub const RTE_CACHE_LINE_MIN_SIZE: u32 = 64; pub const RTE_CACHE_LINE_SIZE: u32 = 64; #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct rte_kni_mbuf { pub buf_addr: *mut ::std::os::raw::c_void, @@ -41,6 +42,11 @@ fn bindgen_test_layout_rte_kni_mbuf() { 128usize, concat!("Size of: ", stringify!(rte_kni_mbuf)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_kni_mbuf)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).buf_addr as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 8b7be4ca5f..4c10223c6c 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -176,6 +176,7 @@ fn bindgen_test_layout_ip_frag_key() { /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct ip_frag_pkt { ///< LRU list @@ -249,6 +250,11 @@ fn bindgen_test_layout_ip_frag_pkt() { 192usize, concat!("Size of: ", stringify!(ip_frag_pkt)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ip_frag_pkt)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).lru as *const _ as usize }, 0usize, @@ -371,6 +377,7 @@ impl Default for ip_pkt_list { } /// fragmentation table statistics #[repr(C)] +#[repr(align(64))] #[derive(Copy, Clone)] pub struct ip_frag_tbl_stat { ///< total # of find/insert attempts. @@ -394,6 +401,11 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { 64usize, concat!("Size of: ", stringify!(ip_frag_tbl_stat)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ip_frag_tbl_stat)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).find_num as *const _ as usize }, 0usize, @@ -462,6 +474,7 @@ impl Default for ip_frag_tbl_stat { } /// fragmentation table #[repr(C)] +#[repr(align(64))] pub struct rte_ip_frag_tbl { ///< ttl for table entries. pub max_cycles: u64, @@ -494,6 +507,11 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { 128usize, concat!("Size of: ", stringify!(rte_ip_frag_tbl)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_ip_frag_tbl)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).max_cycles as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 83dfb94655..6ed1d13083 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -127,6 +127,7 @@ fn bindgen_test_layout_rte_atomic16_t() { } /// The generic rte_mbuf, containing a packet mbuf. #[repr(C)] +#[repr(align(64))] pub struct rte_mbuf { pub cacheline0: MARKER, ///< Virtual address of segment buffer. @@ -236,10 +237,10 @@ pub union rte_mbuf__bindgen_ty_2 { _bindgen_union_align: u32, } #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u8>, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { @@ -722,10 +723,10 @@ pub union rte_mbuf__bindgen_ty_5 { _bindgen_union_align: u64, } #[repr(C)] +#[repr(align(8))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u16>, - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { @@ -888,6 +889,11 @@ fn bindgen_test_layout_rte_mbuf() { 128usize, concat!("Size of: ", stringify!(rte_mbuf)) ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mbuf)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).cacheline0 as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs index 68eab7a2d3..04833a6581 100644 --- a/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -6,5 +6,6 @@ non_camel_case_types, non_upper_case_globals )] +#![allow(overflowing_literals)] pub const a: u32 = 18446744073709551611; diff --git a/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs index 68eab7a2d3..04833a6581 100644 --- a/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -6,5 +6,6 @@ non_camel_case_types, non_upper_case_globals )] +#![allow(overflowing_literals)] pub const a: u32 = 18446744073709551611; diff --git a/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs index 7ad2fc1c7d..ce5d0362d6 100644 --- a/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -6,5 +6,6 @@ non_camel_case_types, non_upper_case_globals )] +#![allow(overflowing_literals)] pub const a: u32 = 4294967291; diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index 295a23f9ac..e167e5ebd2 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -1,6 +1,11 @@ /* automatically generated by rust-bindgen */ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #![cfg(not(test))] #[repr(C)] @@ -19,6 +24,11 @@ fn bindgen_test_layout_JNINativeInterface_() { 16usize, concat!("Size of: ", stringify!(JNINativeInterface_)) ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(JNINativeInterface_)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).GetVersion as *const _ as usize }, 0usize, diff --git a/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs index 7ad2fc1c7d..ce5d0362d6 100644 --- a/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -6,5 +6,6 @@ non_camel_case_types, non_upper_case_globals )] +#![allow(overflowing_literals)] pub const a: u32 = 4294967291; diff --git a/tests/expectations/tests/no-hash-opaque.rs b/tests/expectations/tests/no-hash-opaque.rs index c4211c71b1..427a3d3424 100644 --- a/tests/expectations/tests/no-hash-opaque.rs +++ b/tests/expectations/tests/no-hash-opaque.rs @@ -1,10 +1,14 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct NoHash { pub _bindgen_opaque_blob: u32, diff --git a/tests/expectations/tests/no-partialeq-opaque.rs b/tests/expectations/tests/no-partialeq-opaque.rs index 1a7941623d..5bf2d12180 100644 --- a/tests/expectations/tests/no-partialeq-opaque.rs +++ b/tests/expectations/tests/no-partialeq-opaque.rs @@ -1,10 +1,14 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { pub _bindgen_opaque_blob: u32, diff --git a/tests/expectations/tests/no_copy_opaque.rs b/tests/expectations/tests/no_copy_opaque.rs index 8de90cd4ec..6659a95a99 100644 --- a/tests/expectations/tests/no_copy_opaque.rs +++ b/tests/expectations/tests/no_copy_opaque.rs @@ -1,10 +1,14 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default)] pub struct NoCopy { pub _bindgen_opaque_blob: u32, diff --git a/tests/expectations/tests/opaque-tracing.rs b/tests/expectations/tests/opaque-tracing.rs index 87d91f3c4e..6bba62456e 100644 --- a/tests/expectations/tests/opaque-tracing.rs +++ b/tests/expectations/tests/opaque-tracing.rs @@ -1,14 +1,18 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern "C" { #[link_name = "\u{1}_Z3fooP9Container"] pub fn foo(c: *mut Container); } #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Container { pub _bindgen_opaque_blob: [u32; 2usize], diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 590c5fdcad..9301f7ab86 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -9,6 +9,7 @@ ///
#[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct opaque { pub _bindgen_opaque_blob: u32, diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index c44a244046..3ec962144f 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -9,6 +9,7 @@ ///
#[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OtherOpaque { pub _bindgen_opaque_blob: u32, diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index f7ddb3584d..d0328d340e 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 378900198d..abb0bd3f85 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index f56c44a5f8..73787d8611 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index d533b9fb00..3a76d51425 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index ee4ac07c45..b0d3ac9cab 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 69359e64f7..1a3ad7161a 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] pub union UnionWithDtor { diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 38657d05a2..e6f4e22965 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index 515d568867..a8af8b9c15 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] pub struct NastyStruct { diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index dbffb17c81..a145133277 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index e41fc9735b..f97f122cf0 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -97,10 +97,10 @@ pub union foo { _bindgen_union_align: u32, } #[repr(C)] +#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 43581d8b91..aa2abc864d 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 738aade3b3..a1267b3952 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 35c9028570..c6272c1332 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 64ce4d0feb..c31a69f94f 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 631005f81e..0a4fd91cbe 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Copy, Clone)] diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index 5040465f88..a11f105a3a 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -1,10 +1,14 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] +#[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct max_align_t { pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, @@ -19,6 +23,11 @@ fn bindgen_test_layout_max_align_t() { 32usize, concat!("Size of: ", stringify!(max_align_t)) ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(max_align_t)) + ); assert_eq!( unsafe { &(*(::std::ptr::null::())).__clang_max_align_nonce1 as *const _ as usize diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index d4e53ef16e..563258a0b1 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -1,7 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern crate core; diff --git a/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h b/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h index c9189952bb..4c342c0ec5 100644 --- a/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h +++ b/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h @@ -1,3 +1,5 @@ +// bindgen-flags: --raw-line "#![allow(overflowing_literals)]" + typedef unsigned int uint32_t; uint32_t a = 18446744073709551611; diff --git a/tests/headers/issue-1498.h b/tests/headers/issue-1498.h new file mode 100644 index 0000000000..aceabbd2b4 --- /dev/null +++ b/tests/headers/issue-1498.h @@ -0,0 +1,17 @@ +typedef unsigned long uint64_t; +typedef uint64_t size_t; +typedef unsigned uint32_t; +typedef int int32_t; + +struct rte_memseg { + uint64_t phys_addr; /**< Start physical address. */ + union { + void *addr; /**< Start virtual address. */ + uint64_t addr_64; /**< Makes sure addr is always 64 bits */ + }; + size_t len; /**< Length of the segment. */ + uint64_t hugepage_sz; /**< The pagesize of underlying memory */ + int32_t socket_id; /**< NUMA socket ID. */ + uint32_t nchannel; /**< Number of channels. */ + uint32_t nrank; /**< Number of ranks. */ +} __attribute__((__packed__)); diff --git a/tests/headers/layout.h b/tests/headers/layout.h index d1822a04de..b290ee856b 100644 --- a/tests/headers/layout.h +++ b/tests/headers/layout.h @@ -1,6 +1,10 @@ +// bindgen-flags: --rust-target 1.21 +// +// FIXME: https://github.com/rust-lang/rust-bindgen/issues/1498 + struct header { char proto; unsigned int size __attribute__ ((packed)); unsigned char data[] __attribute__ ((aligned(8))); -} __attribute__ ((aligned, packed)); \ No newline at end of file +} __attribute__ ((aligned, packed));