From 5f6c6cdd9846406bb2f6f448cd408903791be316 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 27 Nov 2024 14:17:23 -0500 Subject: [PATCH] Remove `layout` test. This is done because bindgen is producing bogus code where a single struct has both `packed` and `align` attributes. --- Cargo.toml | 1 + .../tests/expectations/tests/layout.rs | 69 ------------------- bindgen-tests/tests/headers/layout.h | 10 --- 3 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 bindgen-tests/tests/expectations/tests/layout.rs delete mode 100644 bindgen-tests/tests/headers/layout.h diff --git a/Cargo.toml b/Cargo.toml index e0535a1c66..bd87aacf0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,3 +54,4 @@ release = false [profile.dist] inherits = "release" lto = "thin" + diff --git a/bindgen-tests/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs deleted file mode 100644 index 073f184f11..0000000000 --- a/bindgen-tests/tests/expectations/tests/layout.rs +++ /dev/null @@ -1,69 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C, packed(16))] -#[repr(align(16))] -pub struct header { - pub proto: ::std::os::raw::c_char, - pub size: ::std::os::raw::c_uint, - pub data: __IncompleteArrayField<::std::os::raw::c_uchar>, -} -#[test] -fn bindgen_test_layout_header() { - const UNINIT: ::std::mem::MaybeUninit
= ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::
(), 16usize, "Size of header"); - assert_eq!(::std::mem::align_of::
(), 16usize, "Alignment of header"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 0usize, - "Offset of field: header::proto", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize }, - 1usize, - "Offset of field: header::size", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 8usize, - "Offset of field: header::data", - ); -} -impl Default for header { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} diff --git a/bindgen-tests/tests/headers/layout.h b/bindgen-tests/tests/headers/layout.h deleted file mode 100644 index 6a3df9b3f5..0000000000 --- a/bindgen-tests/tests/headers/layout.h +++ /dev/null @@ -1,10 +0,0 @@ -// bindgen-flags: \-\-rust-target=1.33 -// -// 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));