From ed6e1bbec439e8b260e6e701379fc70d295f35fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 4 Mar 2019 03:00:53 +0100 Subject: [PATCH 1/3] Update default rust target to 1.33. Closes #1529. --- CHANGELOG.md | 14 ++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/features.rs | 2 +- tests/expectations/tests/16-byte-alignment.rs | 19 ++++- tests/expectations/tests/annotation_hide.rs | 1 + .../tests/anon_struct_in_union.rs | 10 ++- tests/expectations/tests/anon_union.rs | 1 + .../expectations/tests/bitfield-enum-basic.rs | 8 +- tests/expectations/tests/bitfield-large.rs | 73 +++++++++++++++++++ tests/expectations/tests/bitfield_align.rs | 10 +-- tests/expectations/tests/bitfield_align_2.rs | 2 +- .../tests/bitfield_large_overflow.rs | 10 ++- .../tests/bitfield_method_mangling.rs | 2 +- tests/expectations/tests/class.rs | 1 + .../tests/class_with_inner_struct.rs | 10 ++- tests/expectations/tests/convert-floats.rs | 2 +- .../tests/derive-debug-mangle-name.rs | 14 ++-- .../expectations/tests/derive-debug-opaque.rs | 10 ++- .../tests/derive-partialeq-anonfield.rs | 16 +++- .../tests/derive-partialeq-pointer.rs | 10 ++- .../tests/derive-partialeq-union.rs | 1 + tests/expectations/tests/doggo-or-null.rs | 1 + .../tests/enum-default-bitfield.rs | 9 ++- tests/expectations/tests/enum-doc-bitfield.rs | 2 +- .../issue-1198-alias-rust-bitfield-enum.rs | 11 ++- tests/expectations/tests/issue-1285.rs | 8 +- tests/expectations/tests/issue-493.rs | 8 +- tests/expectations/tests/issue-537.rs | 39 +++++++++- .../issue-648-derive-debug-with-padding.rs | 12 +++ .../tests/issue-739-pointer-wide-bitfield.rs | 2 +- .../tests/issue-801-opaque-sloppiness.rs | 8 +- ...07-opaque-types-methods-being-generated.rs | 10 ++- tests/expectations/tests/issue-816.rs | 2 +- .../expectations/tests/jsval_layout_opaque.rs | 4 +- tests/expectations/tests/layout.rs | 9 ++- tests/expectations/tests/layout_align.rs | 4 +- tests/expectations/tests/layout_array.rs | 18 +++++ .../tests/layout_array_too_long.rs | 6 ++ tests/expectations/tests/layout_eth_conf.rs | 1 + tests/expectations/tests/layout_kni_mbuf.rs | 6 ++ .../tests/layout_large_align_field.rs | 18 +++++ tests/expectations/tests/layout_mbuf.rs | 16 +++- ...0600-cannot-apply-unary-negation-to-u32.rs | 1 + ...0600-cannot-apply-unary-negation-to-u32.rs | 1 + ...0600-cannot-apply-unary-negation-to-u32.rs | 1 + .../tests/libclang-5/call-conv-field.rs | 12 ++- ...0600-cannot-apply-unary-negation-to-u32.rs | 1 + tests/expectations/tests/no-hash-opaque.rs | 10 ++- .../expectations/tests/no-partialeq-opaque.rs | 10 ++- tests/expectations/tests/no_copy_opaque.rs | 10 ++- tests/expectations/tests/opaque-tracing.rs | 10 ++- tests/expectations/tests/opaque_in_struct.rs | 1 + tests/expectations/tests/opaque_pointer.rs | 1 + .../tests/struct_with_anon_union.rs | 10 ++- .../tests/struct_with_anon_unnamed_union.rs | 10 ++- .../expectations/tests/struct_with_nesting.rs | 10 ++- tests/expectations/tests/typeref.rs | 10 ++- tests/expectations/tests/union-in-ns.rs | 10 ++- tests/expectations/tests/union_bitfield.rs | 2 + tests/expectations/tests/union_dtor.rs | 10 ++- tests/expectations/tests/union_fields.rs | 10 ++- tests/expectations/tests/union_template.rs | 12 ++- .../tests/union_with_anon_struct.rs | 10 ++- .../tests/union_with_anon_struct_bitfield.rs | 3 +- .../tests/union_with_anon_union.rs | 11 ++- .../tests/union_with_anon_unnamed_struct.rs | 10 ++- .../tests/union_with_anon_unnamed_union.rs | 11 ++- .../tests/union_with_big_member.rs | 12 ++- .../expectations/tests/union_with_nesting.rs | 12 ++- tests/expectations/tests/unknown_attr.rs | 15 +++- tests/expectations/tests/use-core.rs | 9 ++- ...E0600-cannot-apply-unary-negation-to-u32.h | 2 + tests/headers/layout.h | 6 +- 74 files changed, 528 insertions(+), 129 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c2d328069..031efe676c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,20 @@ 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][] + +[#1529]: https://github.com/rust-lang-nursery/rust-bindgen/issues/1529 + -------------------------------------------------------------------------------- # 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/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..9f19d212d0 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)] @@ -12,6 +15,7 @@ pub struct rte_ipv4_tuple { pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_ipv4_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, @@ -145,6 +149,7 @@ pub struct rte_ipv6_tuple { pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_ipv6_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, @@ -271,11 +276,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 +290,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..40c56b9ad2 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)] @@ -10,6 +13,7 @@ pub struct s { pub u: s__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union s__bindgen_ty_1 { pub field: s__bindgen_ty_1_inner, diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index a9b6029234..c086e73813 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -33,6 +33,7 @@ pub struct TErrorResult_DOMExceptionInfo { _unused: [u8; 0], } #[repr(C)] +#[repr(align(8))] pub union TErrorResult__bindgen_ty_1 { pub mMessage: *mut TErrorResult_Message, pub mDOMExceptionInfo: *mut TErrorResult_DOMExceptionInfo, 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.rs b/tests/expectations/tests/class.rs index f52f0f8580..3fda629b7b 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -335,6 +335,7 @@ impl Default for IncompleteArrayNonCopiable { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union Union { pub d: f32, diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 265d7c5bfc..d055cfbc20 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)] @@ -49,6 +54,7 @@ fn bindgen_test_layout_A_Segment() { ); } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union A__bindgen_ty_1 { pub f: ::std::os::raw::c_int, @@ -83,6 +89,7 @@ impl Default for A__bindgen_ty_1 { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union A__bindgen_ty_2 { pub d: ::std::os::raw::c_int, @@ -226,6 +233,7 @@ pub struct C { pub __bindgen_anon_1: C__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union C__bindgen_ty_1 { pub mFunc: C__bindgen_ty_1__bindgen_ty_1, 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..ca9e7e213f 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)] @@ -12,6 +15,7 @@ pub struct perf_event_attr { pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union perf_event_attr__bindgen_ty_1 { pub b: ::std::os::raw::c_int, @@ -104,9 +108,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..1d38b0b627 100644 --- a/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -1,15 +1,20 @@ /* 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, } #[repr(C)] +#[repr(align(1))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { _bindgen_union_align: [u8; 0usize], @@ -39,6 +44,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..ea1b88a287 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)] @@ -38,6 +41,7 @@ pub struct c { pub __bindgen_anon_1: c__bindgen_ty_1, } #[repr(C)] +#[repr(align(1))] #[derive(Copy, Clone)] pub union c__bindgen_ty_1 { _bindgen_union_align: u8, diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index a271f41032..5adbca1f97 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -9,6 +9,7 @@ /// Deriving PartialEq for rust unions is not supported. #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union ShouldNotDerivePartialEq { pub a: ::std::os::raw::c_char, 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..666f6175e2 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -1,12 +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 +)] #[repr(C)] pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index c13101d0a9..02ed7ed73d 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); @@ -78,6 +83,7 @@ pub struct basic_string___short { pub __data_: *mut basic_string_value_type, } #[repr(C)] +#[repr(align(1))] pub union basic_string___short__bindgen_ty_1 { pub __size_: ::std::os::raw::c_uchar, pub __lx: basic_string_value_type, 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..9ea5e5c015 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -176,6 +176,7 @@ pub enum JSWhyMagic { JS_WHY_MAGIC_COUNT = 18, } #[repr(C)] +#[repr(align(8))] #[derive(Copy, Clone)] pub union jsval_layout { pub asBits: u64, @@ -188,10 +189,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() { @@ -258,6 +259,7 @@ pub struct jsval_layout__bindgen_ty_2 { pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub i32: i32, 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_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 5582c7ded3..734839fc20 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -1830,6 +1830,7 @@ impl Default for rte_eth_conf__bindgen_ty_1 { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_eth_conf__bindgen_ty_2 { pub vmdq_dcb_tx_conf: rte_eth_vmdq_dcb_tx_conf, 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..8bfda72d0c 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. @@ -179,6 +180,7 @@ pub struct rte_mbuf { /// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC /// config option. #[repr(C)] +#[repr(align(2))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { ///< Atomically accessed refcnt @@ -228,6 +230,7 @@ impl Default for rte_mbuf__bindgen_ty_1 { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_2 { ///< L2/L3/L4 and tunnel information. @@ -236,10 +239,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() { @@ -412,6 +415,7 @@ impl Default for rte_mbuf__bindgen_ty_2 { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3 { ///< RSS hash result if RSS enabled @@ -431,6 +435,7 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { pub hi: u32, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, @@ -667,6 +672,7 @@ impl Default for rte_mbuf__bindgen_ty_3 { } } #[repr(C)] +#[repr(align(8))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_4 { ///< Can be used for external metadata @@ -714,6 +720,7 @@ impl Default for rte_mbuf__bindgen_ty_4 { } } #[repr(C)] +#[repr(align(8))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_5 { ///< combined for easy fetch @@ -722,10 +729,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 +895,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..2279853f42 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)] @@ -10,6 +13,7 @@ pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 378900198d..90ee13e49e 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)] @@ -10,6 +13,7 @@ pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index f56c44a5f8..ddbbe77822 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)] @@ -11,6 +14,7 @@ pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index d533b9fb00..b0f1290d9f 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)] @@ -57,6 +60,7 @@ pub struct mozilla_StyleShapeSource { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, } #[repr(C)] +#[repr(align(8))] pub union mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: *mut mozilla_Position, pub mFragmentOrURL: *mut mozilla_FragmentOrURL, diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index ee4ac07c45..c3b541a2de 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.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 +)] #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] + #[repr(align(4))] #[derive(Copy, Clone)] pub union bar { pub baz: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index d6f52ef5d0..d3a94b1090 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -90,6 +90,7 @@ where } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union U4 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, @@ -137,6 +138,7 @@ impl U4 { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union B { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 69359e64f7..ee6e4e22e1 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.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))] pub union UnionWithDtor { pub mFoo: ::std::os::raw::c_int, pub mBar: *mut ::std::os::raw::c_void, diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 38657d05a2..40e374cfa7 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.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(Copy, Clone)] pub union nsStyleUnion { pub mInt: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index 515d568867..eea3b0e525 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 { @@ -11,6 +14,7 @@ pub struct NastyStruct { pub __bindgen_anon_1: NastyStruct__bindgen_ty_2, } #[repr(C)] +#[repr(align(8))] pub union NastyStruct__bindgen_ty_1 { pub mFoo: *mut ::std::os::raw::c_void, pub mDummy: ::std::os::raw::c_ulong, @@ -22,6 +26,7 @@ impl Default for NastyStruct__bindgen_ty_1 { } } #[repr(C)] +#[repr(align(8))] pub union NastyStruct__bindgen_ty_2 { pub wat: ::std::os::raw::c_short, pub wut: *mut ::std::os::raw::c_int, @@ -38,6 +43,7 @@ impl Default for NastyStruct { } } #[repr(C)] +#[repr(align(8))] pub union Whatever { pub mTPtr: *mut ::std::os::raw::c_void, pub mInt: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index dbffb17c81..ede6acf041 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.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(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index e41fc9735b..d08a7ff8e6 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -90,6 +90,7 @@ where } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_int, @@ -97,10 +98,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..df1b34f870 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -1,16 +1,21 @@ /* 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(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, _bindgen_union_align: u32, } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 738aade3b3..79f6624b7a 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.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(Copy, Clone)] pub union pixel { pub rgba: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 35c9028570..c81afa1fd0 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.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(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_uint, @@ -12,6 +16,7 @@ pub union foo { _bindgen_union_align: u32, } #[repr(C)] +#[repr(align(2))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_ushort, diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 64ce4d0feb..40eed80b71 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.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(Copy, Clone)] pub union WithBigArray { pub a: ::std::os::raw::c_int, @@ -50,6 +54,7 @@ impl Default for WithBigArray { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union WithBigArray2 { pub a: ::std::os::raw::c_int, @@ -95,6 +100,7 @@ impl Default for WithBigArray2 { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union WithBigMember { pub a: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 631005f81e..e11aff2eee 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.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(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_uint, @@ -18,6 +22,7 @@ pub struct foo__bindgen_ty_1 { pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, } #[repr(C)] +#[repr(align(2))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1__bindgen_ty_1 { pub b1: ::std::os::raw::c_ushort, @@ -67,6 +72,7 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_1 { } } #[repr(C)] +#[repr(align(2))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1__bindgen_ty_2 { pub c1: ::std::os::raw::c_ushort, 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..133065e04c 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; @@ -46,6 +50,7 @@ impl Default for foo { } } #[repr(C)] +#[repr(align(8))] #[derive(Copy, Clone)] pub union _bindgen_ty_1 { pub bar: ::std::os::raw::c_int, 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/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)); From 9134679a98703879ddd081fe14b64cfae074de4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 4 Mar 2019 03:21:11 +0100 Subject: [PATCH 2/3] codegen: Properly track alignment of unions. This makes us not unnecessarily add repr(align) to unions. Closes #1498. --- CHANGELOG.md | 46 +++--- src/codegen/mod.rs | 3 +- src/codegen/struct_layout.rs | 6 +- tests/expectations/tests/16-byte-alignment.rs | 2 - .../tests/anon_struct_in_union.rs | 1 - tests/expectations/tests/anon_union.rs | 1 - tests/expectations/tests/class.rs | 1 - .../tests/class_with_inner_struct.rs | 3 - .../tests/derive-debug-mangle-name.rs | 1 - .../tests/derive-partialeq-anonfield.rs | 1 - .../tests/derive-partialeq-pointer.rs | 1 - .../tests/derive-partialeq-union.rs | 1 - tests/expectations/tests/issue-1285.rs | 1 - tests/expectations/tests/issue-1498.rs | 153 ++++++++++++++++++ tests/expectations/tests/issue-493.rs | 1 - .../expectations/tests/jsval_layout_opaque.rs | 2 - tests/expectations/tests/layout_eth_conf.rs | 1 - tests/expectations/tests/layout_mbuf.rs | 6 - .../tests/struct_with_anon_union.rs | 1 - .../tests/struct_with_anon_unnamed_union.rs | 1 - .../expectations/tests/struct_with_nesting.rs | 1 - tests/expectations/tests/typeref.rs | 1 - tests/expectations/tests/union-in-ns.rs | 1 - tests/expectations/tests/union_bitfield.rs | 2 - tests/expectations/tests/union_dtor.rs | 1 - tests/expectations/tests/union_fields.rs | 1 - tests/expectations/tests/union_template.rs | 3 - .../tests/union_with_anon_struct.rs | 1 - .../tests/union_with_anon_struct_bitfield.rs | 1 - .../tests/union_with_anon_union.rs | 2 - .../tests/union_with_anon_unnamed_struct.rs | 1 - .../tests/union_with_anon_unnamed_union.rs | 2 - .../tests/union_with_big_member.rs | 3 - .../expectations/tests/union_with_nesting.rs | 3 - tests/expectations/tests/use-core.rs | 1 - tests/headers/issue-1498.h | 17 ++ 36 files changed, 201 insertions(+), 73 deletions(-) create mode 100644 tests/expectations/tests/issue-1498.rs create mode 100644 tests/headers/issue-1498.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 031efe676c..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) @@ -101,7 +104,12 @@ Released 2019/03/04 * 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 -------------------------------------------------------------------------------- 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/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 9f19d212d0..3a9e89984a 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -15,7 +15,6 @@ pub struct rte_ipv4_tuple { pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_ipv4_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, @@ -149,7 +148,6 @@ pub struct rte_ipv6_tuple { pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_ipv6_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 40c56b9ad2..5b5ed43c9e 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -13,7 +13,6 @@ pub struct s { pub u: s__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union s__bindgen_ty_1 { pub field: s__bindgen_ty_1_inner, diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index c086e73813..a9b6029234 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -33,7 +33,6 @@ pub struct TErrorResult_DOMExceptionInfo { _unused: [u8; 0], } #[repr(C)] -#[repr(align(8))] pub union TErrorResult__bindgen_ty_1 { pub mMessage: *mut TErrorResult_Message, pub mDOMExceptionInfo: *mut TErrorResult_DOMExceptionInfo, diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 3fda629b7b..f52f0f8580 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -335,7 +335,6 @@ impl Default for IncompleteArrayNonCopiable { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union Union { pub d: f32, diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index d055cfbc20..577dec6f55 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -54,7 +54,6 @@ fn bindgen_test_layout_A_Segment() { ); } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union A__bindgen_ty_1 { pub f: ::std::os::raw::c_int, @@ -89,7 +88,6 @@ impl Default for A__bindgen_ty_1 { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union A__bindgen_ty_2 { pub d: ::std::os::raw::c_int, @@ -233,7 +231,6 @@ pub struct C { pub __bindgen_anon_1: C__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union C__bindgen_ty_1 { pub mFunc: C__bindgen_ty_1__bindgen_ty_1, diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index ca9e7e213f..9c72fbbd1e 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -15,7 +15,6 @@ pub struct perf_event_attr { pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union perf_event_attr__bindgen_ty_1 { pub b: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/tests/expectations/tests/derive-partialeq-anonfield.rs index 1d38b0b627..b5cb15937d 100644 --- a/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -14,7 +14,6 @@ pub struct rte_mbuf { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, } #[repr(C)] -#[repr(align(1))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { _bindgen_union_align: [u8; 0usize], diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index ea1b88a287..2ac23c8120 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -41,7 +41,6 @@ pub struct c { pub __bindgen_anon_1: c__bindgen_ty_1, } #[repr(C)] -#[repr(align(1))] #[derive(Copy, Clone)] pub union c__bindgen_ty_1 { _bindgen_union_align: u8, diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index 5adbca1f97..a271f41032 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -9,7 +9,6 @@ /// Deriving PartialEq for rust unions is not supported. #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union ShouldNotDerivePartialEq { pub a: ::std::os::raw::c_char, diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index 666f6175e2..77df620b02 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -12,7 +12,6 @@ pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, 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 02ed7ed73d..e7e5c5579c 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -83,7 +83,6 @@ pub struct basic_string___short { pub __data_: *mut basic_string_value_type, } #[repr(C)] -#[repr(align(1))] pub union basic_string___short__bindgen_ty_1 { pub __size_: ::std::os::raw::c_uchar, pub __lx: basic_string_value_type, diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 9ea5e5c015..aa0420aa0b 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -176,7 +176,6 @@ pub enum JSWhyMagic { JS_WHY_MAGIC_COUNT = 18, } #[repr(C)] -#[repr(align(8))] #[derive(Copy, Clone)] pub union jsval_layout { pub asBits: u64, @@ -259,7 +258,6 @@ pub struct jsval_layout__bindgen_ty_2 { pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub i32: i32, diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 734839fc20..5582c7ded3 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -1830,7 +1830,6 @@ impl Default for rte_eth_conf__bindgen_ty_1 { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_eth_conf__bindgen_ty_2 { pub vmdq_dcb_tx_conf: rte_eth_vmdq_dcb_tx_conf, diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 8bfda72d0c..6ed1d13083 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -180,7 +180,6 @@ pub struct rte_mbuf { /// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC /// config option. #[repr(C)] -#[repr(align(2))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { ///< Atomically accessed refcnt @@ -230,7 +229,6 @@ impl Default for rte_mbuf__bindgen_ty_1 { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_2 { ///< L2/L3/L4 and tunnel information. @@ -415,7 +413,6 @@ impl Default for rte_mbuf__bindgen_ty_2 { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3 { ///< RSS hash result if RSS enabled @@ -435,7 +432,6 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { pub hi: u32, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, @@ -672,7 +668,6 @@ impl Default for rte_mbuf__bindgen_ty_3 { } } #[repr(C)] -#[repr(align(8))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_4 { ///< Can be used for external metadata @@ -720,7 +715,6 @@ impl Default for rte_mbuf__bindgen_ty_4 { } } #[repr(C)] -#[repr(align(8))] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_5 { ///< combined for easy fetch diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 2279853f42..d0328d340e 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -13,7 +13,6 @@ pub struct foo { pub bar: foo__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 90ee13e49e..abb0bd3f85 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -13,7 +13,6 @@ pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index ddbbe77822..73787d8611 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -14,7 +14,6 @@ pub struct foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index b0f1290d9f..3a76d51425 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -60,7 +60,6 @@ pub struct mozilla_StyleShapeSource { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, } #[repr(C)] -#[repr(align(8))] pub union mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: *mut mozilla_Position, pub mFragmentOrURL: *mut mozilla_FragmentOrURL, diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index c3b541a2de..b0d3ac9cab 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -12,7 +12,6 @@ pub mod root { #[allow(unused_imports)] use self::super::root; #[repr(C)] - #[repr(align(4))] #[derive(Copy, Clone)] pub union bar { pub baz: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index d3a94b1090..d6f52ef5d0 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -90,7 +90,6 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union U4 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, @@ -138,7 +137,6 @@ impl U4 { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union B { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index ee6e4e22e1..1a3ad7161a 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -8,7 +8,6 @@ )] #[repr(C)] -#[repr(align(8))] pub union UnionWithDtor { pub mFoo: ::std::os::raw::c_int, pub mBar: *mut ::std::os::raw::c_void, diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 40e374cfa7..e6f4e22965 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -8,7 +8,6 @@ )] #[repr(C)] -#[repr(align(8))] #[derive(Copy, Clone)] pub union nsStyleUnion { pub mInt: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index eea3b0e525..a8af8b9c15 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -14,7 +14,6 @@ pub struct NastyStruct { pub __bindgen_anon_1: NastyStruct__bindgen_ty_2, } #[repr(C)] -#[repr(align(8))] pub union NastyStruct__bindgen_ty_1 { pub mFoo: *mut ::std::os::raw::c_void, pub mDummy: ::std::os::raw::c_ulong, @@ -26,7 +25,6 @@ impl Default for NastyStruct__bindgen_ty_1 { } } #[repr(C)] -#[repr(align(8))] pub union NastyStruct__bindgen_ty_2 { pub wat: ::std::os::raw::c_short, pub wut: *mut ::std::os::raw::c_int, @@ -43,7 +41,6 @@ impl Default for NastyStruct { } } #[repr(C)] -#[repr(align(8))] pub union Whatever { pub mTPtr: *mut ::std::os::raw::c_void, pub mInt: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index ede6acf041..a145133277 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -8,7 +8,6 @@ )] #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index d08a7ff8e6..f97f122cf0 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -90,7 +90,6 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index df1b34f870..aa2abc864d 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -8,14 +8,12 @@ )] #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, _bindgen_union_align: u32, } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 79f6624b7a..a1267b3952 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -8,7 +8,6 @@ )] #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union pixel { pub rgba: ::std::os::raw::c_uint, diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index c81afa1fd0..c6272c1332 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -8,7 +8,6 @@ )] #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_uint, @@ -16,7 +15,6 @@ pub union foo { _bindgen_union_align: u32, } #[repr(C)] -#[repr(align(2))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_ushort, diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 40eed80b71..c31a69f94f 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -8,7 +8,6 @@ )] #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union WithBigArray { pub a: ::std::os::raw::c_int, @@ -54,7 +53,6 @@ impl Default for WithBigArray { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union WithBigArray2 { pub a: ::std::os::raw::c_int, @@ -100,7 +98,6 @@ impl Default for WithBigArray2 { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union WithBigMember { pub a: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index e11aff2eee..0a4fd91cbe 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -8,7 +8,6 @@ )] #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union foo { pub a: ::std::os::raw::c_uint, @@ -22,7 +21,6 @@ pub struct foo__bindgen_ty_1 { pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, } #[repr(C)] -#[repr(align(2))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1__bindgen_ty_1 { pub b1: ::std::os::raw::c_ushort, @@ -72,7 +70,6 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_1 { } } #[repr(C)] -#[repr(align(2))] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1__bindgen_ty_2 { pub c1: ::std::os::raw::c_ushort, diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 133065e04c..563258a0b1 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -50,7 +50,6 @@ impl Default for foo { } } #[repr(C)] -#[repr(align(8))] #[derive(Copy, Clone)] pub union _bindgen_ty_1 { pub bar: ::std::os::raw::c_int, 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__)); From a43cc2afcd69cbaa2f699ee3d4b9c804576ffad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 4 Mar 2019 03:27:08 +0100 Subject: [PATCH 3/3] integration: Fix integration tests with rust 1.33. Alignment arrays are not needed anymore, since we have repr(align). --- bindgen-integration/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) 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)