From 41a0e588f4814a2e9deeffe7dccc80086a93b593 Mon Sep 17 00:00:00 2001 From: Robert Sammelson Date: Wed, 15 Nov 2023 12:17:02 -0500 Subject: [PATCH] Fix const array issue --- .../tests/constified-enum-module-overflow.rs | 15 ++++++++++++- .../tests/issue-544-stylo-creduce-2.rs | 2 +- .../libclang-9/ptr32-has-different-size.rs | 6 +++--- .../expectations/tests/struct_typedef_ns.rs | 21 ++++++++----------- bindgen/codegen/mod.rs | 3 ++- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index 49498deaa5..61e666d2a0 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -13,7 +13,7 @@ pub type C_U = B; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { - pub u: u8, + pub u: B, } #[test] fn bindgen_test_layout_A() { @@ -44,3 +44,16 @@ fn __bindgen_test_layout_C_open0_A_close0_instantiation() { concat!("Alignment of template specialization: ", stringify!(C)), ); } +#[test] +fn __bindgen_test_layout_B_open0_A_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(B)), + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(B)), + ); +} diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 835f029cb2..574384d92a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -4,7 +4,7 @@ pub struct Foo { pub member: Foo_SecondAlias, } pub type Foo_FirstAlias = [u8; 0usize]; -pub type Foo_SecondAlias = [u8; 0usize]; +pub type Foo_SecondAlias = Foo; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs index 0d677052ea..bdcc170af7 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs @@ -2,7 +2,7 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct TEST_STRUCT { - pub ptr_32bit: *mut ::std::os::raw::c_void, + pub ptr_32bit: u32, } #[test] fn bindgen_test_layout_TEST_STRUCT() { @@ -10,12 +10,12 @@ fn bindgen_test_layout_TEST_STRUCT() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 8usize, + 4usize, concat!("Size of: ", stringify!(TEST_STRUCT)), ); assert_eq!( ::std::mem::align_of::(), - 8usize, + 4usize, concat!("Alignment of ", stringify!(TEST_STRUCT)), ); assert_eq!( diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index 44afa4822a..aabe23b18e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -47,41 +47,38 @@ pub mod root { use self::super::super::root; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] - pub struct _bindgen_ty_1 { + pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } #[test] - fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + fn bindgen_test_layout_typedef_struct() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), + ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), + concat!("Size of: ", stringify!(typedef_struct)), ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), + ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), + concat!("Alignment of ", stringify!(typedef_struct)), ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(_bindgen_ty_1), + stringify!(typedef_struct), "::", stringify!(foo), ), ); } - pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; - pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] - pub enum _bindgen_ty_2 { + pub enum typedef_enum { BAR = 1, } - pub use self::super::super::root::_bindgen_mod_id_12::_bindgen_ty_2 as typedef_enum; } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 8e13606345..93c6c88020 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5260,7 +5260,8 @@ pub(crate) mod utils { } else { t.to_rust_ty_or_opaque(ctx, &()) }; - stream.to_ptr(ctx.resolve_type(t).is_const()) + stream + .to_ptr(ctx.resolve_type(t).is_const() || arg_ty.is_const()) } TypeKind::Pointer(inner) => { let inner = ctx.resolve_item(inner);