diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6f8a451a2a..51843146d0 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2084,8 +2084,12 @@ impl CodeGenerator for CompInfo { .count() > 1; + + // The offset of #[repr(C)] union is always 0, don't need to recheck it. + let is_not_packed_union = is_union && !packed; + let should_skip_field_offset_checks = - is_opaque || too_many_base_vtables; + is_opaque || too_many_base_vtables || is_not_packed_union; let check_field_offset = if should_skip_field_offset_checks { @@ -2105,8 +2109,24 @@ impl CodeGenerator for CompInfo { Some(quote! { assert_eq!( - unsafe { - &(*(::#prefix::ptr::null::<#canonical_ident>())).#field_name as *const _ as usize + { + // Create an instance of #canonical_ident struct from zero bit pattern + let struct_instance = unsafe { + std::mem::zeroed::<#canonical_ident>() + }; + + // Get the pointers to the struct and its field + let struct_ptr = &struct_instance as *const #canonical_ident; + let field_ptr = std::ptr::addr_of!(struct_instance.#field_name); + + // Get the offset of the field + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + + //Do not call the destructor + std::mem::forget(struct_instance); + + field_address.checked_sub(struct_address).unwrap() }, #field_offset, concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 058568f24c..adc6366190 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -43,10 +43,17 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.dport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -57,10 +64,17 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.sport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -83,19 +97,6 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); } impl Default for rte_ipv4_tuple__bindgen_ty_1 { fn default() -> Self { @@ -119,9 +120,15 @@ fn bindgen_test_layout_rte_ipv4_tuple() { concat!("Alignment of ", stringify!(rte_ipv4_tuple)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv4_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.src_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -132,9 +139,15 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv4_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -192,10 +205,17 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.dport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -206,10 +226,17 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.sport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -232,19 +259,6 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); } impl Default for rte_ipv6_tuple__bindgen_ty_1 { fn default() -> Self { @@ -268,9 +282,15 @@ fn bindgen_test_layout_rte_ipv6_tuple() { concat!("Alignment of ", stringify!(rte_ipv6_tuple)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv6_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.src_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -281,9 +301,15 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv6_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -322,30 +348,6 @@ fn bindgen_test_layout_rte_thash_tuple() { 16usize, concat!("Alignment of ", stringify!(rte_thash_tuple)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).v4 as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).v6 as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) - ); } impl Default for rte_thash_tuple { fn default() -> Self { diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs index 1df6778b56..da4e3bf0fd 100644 --- a/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -88,10 +88,17 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.dport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -102,10 +109,17 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.sport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -133,19 +147,6 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { fn clone(&self) -> Self { @@ -165,9 +166,15 @@ fn bindgen_test_layout_rte_ipv4_tuple() { concat!("Alignment of ", stringify!(rte_ipv4_tuple)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv4_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.src_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -178,9 +185,15 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv4_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -236,10 +249,17 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.dport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -250,10 +270,17 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.sport); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -281,19 +308,6 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { fn clone(&self) -> Self { @@ -313,9 +327,15 @@ fn bindgen_test_layout_rte_ipv6_tuple() { concat!("Alignment of ", stringify!(rte_ipv6_tuple)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv6_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.src_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -326,9 +346,15 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ipv6_tuple; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -358,30 +384,6 @@ fn bindgen_test_layout_rte_thash_tuple() { 48usize, concat!("Size of: ", stringify!(rte_thash_tuple)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).v4 as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).v6 as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) - ); } impl Clone for rte_thash_tuple { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index 9977baa282..0f2fe3f466 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -29,9 +29,15 @@ fn bindgen_test_layout_SomeAccessors() { concat!("Alignment of ", stringify!(SomeAccessors)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mNoAccessor as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const SomeAccessors; + let field_ptr = std::ptr::addr_of!(struct_instance.mNoAccessor); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -42,9 +48,15 @@ fn bindgen_test_layout_SomeAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBothAccessors as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const SomeAccessors; + let field_ptr = std::ptr::addr_of!(struct_instance.mBothAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -55,9 +67,16 @@ fn bindgen_test_layout_SomeAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mUnsafeAccessors - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const SomeAccessors; + let field_ptr = + std::ptr::addr_of!(struct_instance.mUnsafeAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -68,9 +87,16 @@ fn bindgen_test_layout_SomeAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mImmutableAccessor - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const SomeAccessors; + let field_ptr = + std::ptr::addr_of!(struct_instance.mImmutableAccessor); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -125,9 +151,14 @@ fn bindgen_test_layout_AllAccessors() { concat!("Alignment of ", stringify!(AllAccessors)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBothAccessors as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllAccessors; + let field_ptr = std::ptr::addr_of!(struct_instance.mBothAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -138,9 +169,15 @@ fn bindgen_test_layout_AllAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mAlsoBothAccessors - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllAccessors; + let field_ptr = + std::ptr::addr_of!(struct_instance.mAlsoBothAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -189,9 +226,15 @@ fn bindgen_test_layout_AllUnsafeAccessors() { concat!("Alignment of ", stringify!(AllUnsafeAccessors)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBothAccessors - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllUnsafeAccessors; + let field_ptr = std::ptr::addr_of!(struct_instance.mBothAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -202,9 +245,16 @@ fn bindgen_test_layout_AllUnsafeAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mAlsoBothAccessors - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllUnsafeAccessors; + let field_ptr = + std::ptr::addr_of!(struct_instance.mAlsoBothAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -262,9 +312,15 @@ fn bindgen_test_layout_ContradictAccessors() { concat!("Alignment of ", stringify!(ContradictAccessors)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBothAccessors - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContradictAccessors; + let field_ptr = std::ptr::addr_of!(struct_instance.mBothAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -275,9 +331,15 @@ fn bindgen_test_layout_ContradictAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mNoAccessors - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContradictAccessors; + let field_ptr = std::ptr::addr_of!(struct_instance.mNoAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -288,9 +350,16 @@ fn bindgen_test_layout_ContradictAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mUnsafeAccessors - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContradictAccessors; + let field_ptr = + std::ptr::addr_of!(struct_instance.mUnsafeAccessors); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -301,9 +370,16 @@ fn bindgen_test_layout_ContradictAccessors() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mImmutableAccessor - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContradictAccessors; + let field_ptr = + std::ptr::addr_of!(struct_instance.mImmutableAccessor); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -357,8 +433,14 @@ fn bindgen_test_layout_Replaced() { concat!("Alignment of ", stringify!(Replaced)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mAccessor as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Replaced; + let field_ptr = std::ptr::addr_of!(struct_instance.mAccessor); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -398,8 +480,14 @@ fn bindgen_test_layout_Wrapper() { concat!("Alignment of ", stringify!(Wrapper)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mReplaced as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Wrapper; + let field_ptr = std::ptr::addr_of!(struct_instance.mReplaced); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlist-namespaces.rs b/tests/expectations/tests/allowlist-namespaces.rs index 4236f63ed9..ab6b6cdf2c 100644 --- a/tests/expectations/tests/allowlist-namespaces.rs +++ b/tests/expectations/tests/allowlist-namespaces.rs @@ -52,8 +52,14 @@ pub mod root { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).helper as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.helper); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/tests/expectations/tests/allowlisted-item-references-no-hash.rs index bc3fde1ded..2b0b9bb799 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -41,8 +41,14 @@ fn bindgen_test_layout_AllowlistMe() { concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllowlistMe; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index f26f692391..95771bfad5 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -41,8 +41,14 @@ fn bindgen_test_layout_AllowlistMe() { concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllowlistMe; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/tests/expectations/tests/allowlisted_item_references_no_copy.rs index a5cb17b238..0e8d7c41b5 100644 --- a/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -41,8 +41,14 @@ fn bindgen_test_layout_AllowlistMe() { concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllowlistMe; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index 38435d0a4c..57b3a8a1c9 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -43,8 +43,14 @@ fn bindgen_test_layout_NotAnnotated() { concat!("Alignment of ", stringify!(NotAnnotated)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).f as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NotAnnotated; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs index edd551d193..1b02cc8f4e 100644 --- a/tests/expectations/tests/anon-fields-prefix.rs +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -32,9 +32,15 @@ fn bindgen_test_layout_color__bindgen_ty_1() { concat!("Alignment of ", stringify!(color__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).r as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const color__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.r); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -45,9 +51,15 @@ fn bindgen_test_layout_color__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).g as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const color__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.g); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1usize, concat!( @@ -58,9 +70,15 @@ fn bindgen_test_layout_color__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const color__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -91,9 +109,15 @@ fn bindgen_test_layout_color__bindgen_ty_2() { concat!("Alignment of ", stringify!(color__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).y as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const color__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -104,9 +128,15 @@ fn bindgen_test_layout_color__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).u as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const color__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1usize, concat!( @@ -117,9 +147,15 @@ fn bindgen_test_layout_color__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).v as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const color__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.v); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -142,11 +178,6 @@ fn bindgen_test_layout_color() { 1usize, concat!("Alignment of ", stringify!(color)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).v3 as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) - ); } impl Default for color { fn default() -> Self { diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index 8cae632999..52cdd21b25 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -30,12 +30,28 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 1a4040151e..cc044b0ed1 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -33,9 +33,15 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const s__bindgen_ty_1_inner; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -58,19 +64,6 @@ fn bindgen_test_layout_s__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).field as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) - ); } impl Default for s__bindgen_ty_1 { fn default() -> Self { @@ -94,7 +87,15 @@ fn bindgen_test_layout_s() { concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const s; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/tests/expectations/tests/anon_struct_in_union_1_0.rs index 021f41451b..128f08110a 100644 --- a/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -77,9 +77,15 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const s__bindgen_ty_1_inner; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -107,19 +113,6 @@ fn bindgen_test_layout_s__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).field as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) - ); } impl Clone for s__bindgen_ty_1 { fn clone(&self) -> Self { @@ -139,7 +132,15 @@ fn bindgen_test_layout_s() { concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const s; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs index 0c00cea9ce..9f16ffb704 100644 --- a/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/tests/expectations/tests/array-of-zero-sized-types.rs @@ -44,9 +44,15 @@ fn bindgen_test_layout_HasArrayOfEmpty() { concat!("Alignment of ", stringify!(HasArrayOfEmpty)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).empties as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const HasArrayOfEmpty; + let field_ptr = std::ptr::addr_of!(struct_instance.empties); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/bindgen-union-inside-namespace.rs b/tests/expectations/tests/bindgen-union-inside-namespace.rs index 6083313bfb..2b8923a5b5 100644 --- a/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -77,30 +77,6 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bar) - ) - ); } impl Clone for Bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/tests/expectations/tests/bitfield-linux-32.rs index 15c35cee8d..b70dcc1876 100644 --- a/tests/expectations/tests/bitfield-linux-32.rs +++ b/tests/expectations/tests/bitfield-linux-32.rs @@ -111,7 +111,15 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 509981a887..7d87c9ee3b 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -113,12 +113,28 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 3usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) ); @@ -398,12 +414,28 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) ); @@ -695,7 +727,15 @@ fn bindgen_test_layout_Date3() { concat!("Alignment of ", stringify!(Date3)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).byte as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Date3; + let field_ptr = std::ptr::addr_of!(struct_instance.byte); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 3usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/blocklist-and-impl-debug.rs b/tests/expectations/tests/blocklist-and-impl-debug.rs index ba39fb14d5..97d0a79f66 100644 --- a/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -25,9 +25,15 @@ fn bindgen_test_layout_ShouldManuallyImplDebug() { concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ShouldManuallyImplDebug; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index 22136ddfb7..2a5b84c1da 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -48,9 +48,15 @@ fn bindgen_test_layout_contains_block_pointers() { concat!("Alignment of ", stringify!(contains_block_pointers)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).val as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const contains_block_pointers; + let field_ptr = std::ptr::addr_of!(struct_instance.val); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -61,9 +67,15 @@ fn bindgen_test_layout_contains_block_pointers() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ptr_val - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const contains_block_pointers; + let field_ptr = std::ptr::addr_of!(struct_instance.ptr_val); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index b2ae0b2901..961ec12e75 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -47,9 +47,15 @@ fn bindgen_test_layout_contains_block_pointers() { concat!("Alignment of ", stringify!(contains_block_pointers)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).val as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const contains_block_pointers; + let field_ptr = std::ptr::addr_of!(struct_instance.val); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -60,9 +66,15 @@ fn bindgen_test_layout_contains_block_pointers() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ptr_val - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const contains_block_pointers; + let field_ptr = std::ptr::addr_of!(struct_instance.ptr_val); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs index abcccf1fd2..1a550aac61 100644 --- a/tests/expectations/tests/c_naming.rs +++ b/tests/expectations/tests/c_naming.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_struct_a() { concat!("Alignment of ", stringify!(struct_a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const struct_a; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -52,26 +60,6 @@ fn bindgen_test_layout_union_b() { 4usize, concat!("Alignment of ", stringify!(union_b)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(b) - ) - ); } impl Default for union_b { fn default() -> Self { diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index 1e1a19879d..5c2352f595 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -37,52 +37,132 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ch as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.ch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cch as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cu as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cd as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cch as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cu as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cd as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccch as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 9usize, concat!( "Offset of field: ", @@ -92,12 +172,28 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccu as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccd as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index ecc5c20a7e..5ffde3d606 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -28,8 +28,14 @@ fn bindgen_test_layout_A_B() { concat!("Alignment of ", stringify!(A_B)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).member_b as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A_B; + let field_ptr = std::ptr::addr_of!(struct_instance.member_b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -68,7 +74,15 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member_a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.member_a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -96,7 +110,15 @@ fn bindgen_test_layout_A_C() { concat!("Alignment of ", stringify!(A_C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A_C; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) ); @@ -144,7 +166,15 @@ fn bindgen_test_layout_D() { concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const D; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) ); diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 6c1e4880a6..5a63a959d4 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -59,9 +59,16 @@ fn bindgen_test_layout_whatever_child_with_member() { concat!("Alignment of ", stringify!(whatever_child_with_member)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).m_member - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const whatever_child_with_member; + let field_ptr = std::ptr::addr_of!(struct_instance.m_member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index d6a71ac358..638eb14281 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -24,9 +24,14 @@ fn bindgen_test_layout_whatever() { concat!("Alignment of ", stringify!(whatever)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).replacement as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const whatever; + let field_ptr = std::ptr::addr_of!(struct_instance.replacement); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -55,7 +60,15 @@ fn bindgen_test_layout_container() { concat!("Alignment of ", stringify!(container)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const container; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 0cf2d8d236..08909c826a 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -39,9 +39,15 @@ fn bindgen_test_layout_WithoutDtor() { concat!("Alignment of ", stringify!(WithoutDtor)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).shouldBeWithDtor as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithoutDtor; + let field_ptr = + std::ptr::addr_of!(struct_instance.shouldBeWithDtor); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 35ed765914..73199e5c98 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -31,8 +31,14 @@ fn bindgen_test_layout_A_Segment() { concat!("Alignment of ", stringify!(A_Segment)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.begin); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -43,8 +49,14 @@ fn bindgen_test_layout_A_Segment() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.end); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -72,18 +84,6 @@ fn bindgen_test_layout_A__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).f as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) - ); } impl Default for A__bindgen_ty_1 { fn default() -> Self { @@ -111,18 +111,6 @@ fn bindgen_test_layout_A__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) - ); } impl Default for A__bindgen_ty_2 { fn default() -> Self { @@ -146,13 +134,27 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).named_union as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.named_union); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -196,8 +198,14 @@ fn bindgen_test_layout_B_Segment() { concat!("Alignment of ", stringify!(B_Segment)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.begin); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -208,8 +216,14 @@ fn bindgen_test_layout_B_Segment() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.end); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -233,7 +247,15 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); @@ -279,9 +301,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mX1 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mX1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -292,9 +321,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mY1 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mY1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -305,9 +341,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mX2 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mX2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -318,9 +361,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mY2 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mY2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -350,9 +400,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .mStepSyntax as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.mStepSyntax); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -363,9 +420,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mSteps - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.mSteps); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -397,19 +461,6 @@ fn bindgen_test_layout_C__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mFunc as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) - ); } impl Default for C__bindgen_ty_1 { fn default() -> Self { @@ -439,8 +490,14 @@ fn bindgen_test_layout_C_Segment() { concat!("Alignment of ", stringify!(C_Segment)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.begin); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -451,8 +508,14 @@ fn bindgen_test_layout_C_Segment() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.end); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -476,7 +539,15 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 52cd590d67..16fa86b197 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -74,8 +74,14 @@ fn bindgen_test_layout_A_Segment() { concat!("Alignment of ", stringify!(A_Segment)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.begin); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -86,8 +92,14 @@ fn bindgen_test_layout_A_Segment() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.end); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -121,18 +133,6 @@ fn bindgen_test_layout_A__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).f as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) - ); } impl Clone for A__bindgen_ty_1 { fn clone(&self) -> Self { @@ -157,18 +157,6 @@ fn bindgen_test_layout_A__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) - ); } impl Clone for A__bindgen_ty_2 { fn clone(&self) -> Self { @@ -188,13 +176,27 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).named_union as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.named_union); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -234,8 +236,14 @@ fn bindgen_test_layout_B_Segment() { concat!("Alignment of ", stringify!(B_Segment)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.begin); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -246,8 +254,14 @@ fn bindgen_test_layout_B_Segment() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.end); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -276,7 +290,15 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); @@ -328,9 +350,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mX1 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mX1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -341,9 +370,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mY1 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mY1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -354,9 +390,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mX2 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mX2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -367,9 +410,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mY2 - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.mY2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -404,9 +454,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .mStepSyntax as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.mStepSyntax); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -417,9 +474,16 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mSteps - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.mSteps); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -456,19 +520,6 @@ fn bindgen_test_layout_C__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mFunc as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) - ); } impl Clone for C__bindgen_ty_1 { fn clone(&self) -> Self { @@ -494,8 +545,14 @@ fn bindgen_test_layout_C_Segment() { concat!("Alignment of ", stringify!(C_Segment)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.begin); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -506,8 +563,14 @@ fn bindgen_test_layout_C_Segment() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_Segment; + let field_ptr = std::ptr::addr_of!(struct_instance.end); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -536,7 +599,15 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 31faa49ddb..20fdb9736d 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -30,27 +30,67 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.ptr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).arr as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.arr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 56usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).other_ptr as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.other_ptr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 64usize, concat!( "Offset of field: ", @@ -122,7 +162,15 @@ fn bindgen_test_layout_D() { concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const D; + let field_ptr = std::ptr::addr_of!(struct_instance.ptr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 72usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) ); diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index c381b7342b..5d9115069c 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -81,8 +81,14 @@ pub mod root { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).member as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Baz; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index 4dae071727..3c56af94df 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -29,8 +29,14 @@ fn bindgen_test_layout_TestDouble() { concat!("Alignment of ", stringify!(TestDouble)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mMember as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const TestDouble; + let field_ptr = std::ptr::addr_of!(struct_instance.mMember); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -59,9 +65,15 @@ fn bindgen_test_layout_TestDoublePtr() { concat!("Alignment of ", stringify!(TestDoublePtr)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mMember as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const TestDoublePtr; + let field_ptr = std::ptr::addr_of!(struct_instance.mMember); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -99,8 +111,14 @@ fn bindgen_test_layout_TestFloat() { concat!("Alignment of ", stringify!(TestFloat)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mMember as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const TestFloat; + let field_ptr = std::ptr::addr_of!(struct_instance.mMember); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -129,9 +147,14 @@ fn bindgen_test_layout_TestFloatPtr() { concat!("Alignment of ", stringify!(TestFloatPtr)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mMember as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const TestFloatPtr; + let field_ptr = std::ptr::addr_of!(struct_instance.mMember); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/tests/expectations/tests/const-const-mut-ptr.rs index bc1e76277a..09233a58e3 100644 --- a/tests/expectations/tests/const-const-mut-ptr.rs +++ b/tests/expectations/tests/const-const-mut-ptr.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index 78bb99faf5..b9e54416ef 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -27,9 +27,15 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).this_should_work as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = + std::ptr::addr_of!(struct_instance.this_should_work); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index 59e9ba12ba..ee7dcadcc8 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -31,9 +31,15 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).this_should_work as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = + std::ptr::addr_of!(struct_instance.this_should_work); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index e434291a15..108ceb5187 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -43,9 +43,17 @@ pub mod root { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).this_should_work - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!( + struct_instance.this_should_work + ); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index 60401dc093..4773841cee 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -30,7 +30,15 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 317697dd3b..9b5033457b 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -39,28 +39,66 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz1 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz2 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz3 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz4 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 12usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).baz_ptr1 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz_ptr1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -71,8 +109,14 @@ fn bindgen_test_layout_Bar() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).baz_ptr2 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz_ptr2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -83,8 +127,14 @@ fn bindgen_test_layout_Bar() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).baz_ptr3 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz_ptr3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -95,8 +145,14 @@ fn bindgen_test_layout_Bar() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).baz_ptr4 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz_ptr4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index b6644797d7..92fbb62c1b 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -29,12 +29,28 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz1 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz2 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index ec7e6c0eee..1a11f1beb0 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -64,7 +64,15 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member1 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -74,7 +82,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member2 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!( "Offset of field: ", @@ -84,7 +100,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member3 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!( "Offset of field: ", @@ -94,7 +118,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member4 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 12usize, concat!( "Offset of field: ", @@ -104,7 +136,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member5 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member5); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!( "Offset of field: ", @@ -114,7 +154,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member6 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member6); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 24usize, concat!( "Offset of field: ", @@ -124,7 +172,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member7 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member7); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 32usize, concat!( "Offset of field: ", @@ -134,7 +190,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member8 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member8); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 36usize, concat!( "Offset of field: ", @@ -144,7 +208,15 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member9 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member9); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 40usize, concat!( "Offset of field: ", @@ -154,8 +226,14 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).member10 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.member10); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 44usize, concat!( @@ -193,7 +271,15 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member1 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Baz; + let field_ptr = std::ptr::addr_of!(struct_instance.member1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -235,7 +321,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 2882fa845d..c4ef62a09c 100644 --- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -44,7 +44,15 @@ fn bindgen_test_layout_Inherits() { concat!("Alignment of ", stringify!(Inherits)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Inherits; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -75,8 +83,14 @@ fn bindgen_test_layout_Contains() { concat!("Alignment of ", stringify!(Contains)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).empty as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Contains; + let field_ptr = std::ptr::addr_of!(struct_instance.empty); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -87,7 +101,15 @@ fn bindgen_test_layout_Contains() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Contains; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 1usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/tests/expectations/tests/convert-cpp-comment-to-rust.rs index 86279caf47..50163eebac 100644 --- a/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -30,8 +30,14 @@ fn bindgen_test_layout_mbedtls_mpi() { concat!("Alignment of ", stringify!(mbedtls_mpi)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).s as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const mbedtls_mpi; + let field_ptr = std::ptr::addr_of!(struct_instance.s); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -42,8 +48,14 @@ fn bindgen_test_layout_mbedtls_mpi() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).n as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const mbedtls_mpi; + let field_ptr = std::ptr::addr_of!(struct_instance.n); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -54,8 +66,14 @@ fn bindgen_test_layout_mbedtls_mpi() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).p as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const mbedtls_mpi; + let field_ptr = std::ptr::addr_of!(struct_instance.p); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index 6623159211..b0c6055836 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -34,22 +34,54 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bazz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bazz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bazzz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bazzz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!( "Offset of field: ", @@ -59,8 +91,14 @@ fn bindgen_test_layout_foo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).complexFloat as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.complexFloat); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -71,8 +109,14 @@ fn bindgen_test_layout_foo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).complexDouble as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.complexDouble); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/tests/expectations/tests/ctypes-prefix-path.rs index 12cedac955..25ee0cc2d2 100644 --- a/tests/expectations/tests/ctypes-prefix-path.rs +++ b/tests/expectations/tests/ctypes-prefix-path.rs @@ -32,17 +32,41 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index 1dc1d6e350..36a736b8f6 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -115,7 +115,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).large as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.large); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index e589a29ea3..dfcb784b5d 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -24,9 +24,15 @@ fn bindgen_test_layout_ShouldDeriveClone() { concat!("Alignment of ", stringify!(ShouldDeriveClone)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).large as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ShouldDeriveClone; + let field_ptr = std::ptr::addr_of!(struct_instance.large); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index a437d5c314..3b7ed5d282 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -25,9 +25,15 @@ fn bindgen_test_layout_ShouldImplClone() { concat!("Alignment of ", stringify!(ShouldImplClone)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).large as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ShouldImplClone; + let field_ptr = std::ptr::addr_of!(struct_instance.large); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-custom.rs b/tests/expectations/tests/derive-custom.rs index 1cae9af0ae..3aab6d95fe 100644 --- a/tests/expectations/tests/derive-custom.rs +++ b/tests/expectations/tests/derive-custom.rs @@ -24,7 +24,15 @@ fn bindgen_test_layout_my_type() { concat!("Alignment of ", stringify!(my_type)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const my_type; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -54,7 +62,15 @@ fn bindgen_test_layout_my_type2() { concat!("Alignment of ", stringify!(my_type2)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const my_type2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -83,7 +99,15 @@ fn bindgen_test_layout_my_type3() { concat!("Alignment of ", stringify!(my_type3)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const my_type3; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 33f0f2ffbc..366923eaeb 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -113,8 +113,14 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - &(*(::core::ptr::null::())).large_array as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.large_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 00976b59df..859304bcc1 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -111,8 +111,14 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.large_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index c031897b6a..472a92ae9b 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -26,8 +26,14 @@ fn bindgen_test_layout_Nice() { concat!("Alignment of ", stringify!(Nice)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pointer as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Nice; + let field_ptr = std::ptr::addr_of!(struct_instance.pointer); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -38,8 +44,14 @@ fn bindgen_test_layout_Nice() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Nice; + let field_ptr = std::ptr::addr_of!(struct_instance.large_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index ed5416486c..bbba5f74ae 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -30,32 +30,6 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(c) - ) - ); } impl Default for perf_event_attr__bindgen_ty_1 { fn default() -> Self { @@ -84,9 +58,15 @@ fn bindgen_test_layout_perf_event_attr() { concat!("Alignment of ", stringify!(perf_event_attr)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).type_ as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const perf_event_attr; + let field_ptr = std::ptr::addr_of!(struct_instance.type_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -97,8 +77,15 @@ fn bindgen_test_layout_perf_event_attr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const perf_event_attr; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index ceb70ffe4e..45db4488da 100644 --- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -22,8 +22,14 @@ fn bindgen_test_layout_Instance() { concat!("Alignment of ", stringify!(Instance)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).val as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Instance; + let field_ptr = std::ptr::addr_of!(struct_instance.val); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index 411c7a7036..e5b22fa1b2 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -54,8 +54,14 @@ fn bindgen_test_layout_OpaqueUser() { concat!("Alignment of ", stringify!(OpaqueUser)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).opaque as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const OpaqueUser; + let field_ptr = std::ptr::addr_of!(struct_instance.opaque); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-default-and-blocklist.rs b/tests/expectations/tests/derive-default-and-blocklist.rs index 5d53ede28c..96e071e702 100644 --- a/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/tests/expectations/tests/derive-default-and-blocklist.rs @@ -26,9 +26,15 @@ fn bindgen_test_layout_ShouldNotDeriveDefault() { concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ShouldNotDeriveDefault; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index 7c9f426115..c54f355dc0 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -43,8 +43,14 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).callback as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.callback); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -89,8 +95,14 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).callback as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.callback); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-and-blocklist.rs b/tests/expectations/tests/derive-hash-and-blocklist.rs index 8e1190ea72..9f7a25b8f4 100644 --- a/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -25,9 +25,15 @@ fn bindgen_test_layout_ShouldNotDeriveHash() { concat!("Alignment of ", stringify!(ShouldNotDeriveHash)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ShouldNotDeriveHash; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-blocklisting.rs b/tests/expectations/tests/derive-hash-blocklisting.rs index 7cd29c21d2..a7ec9583c4 100644 --- a/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/tests/expectations/tests/derive-hash-blocklisting.rs @@ -31,8 +31,15 @@ fn bindgen_test_layout_AllowlistedOne() { concat!("Alignment of ", stringify!(AllowlistedOne)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllowlistedOne; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -70,8 +77,15 @@ fn bindgen_test_layout_AllowlistedTwo() { concat!("Alignment of ", stringify!(AllowlistedTwo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AllowlistedTwo; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 92846f3c96..cbf39b809c 100644 --- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -30,8 +30,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -42,8 +49,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -67,7 +81,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs index e2e1bcef22..f21a2b4455 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -24,7 +24,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index e98bbf0f32..5f78ec6662 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -24,8 +24,15 @@ fn bindgen_test_layout_ConstPtrMutObj() { concat!("Alignment of ", stringify!(ConstPtrMutObj)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ConstPtrMutObj; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -63,8 +70,14 @@ fn bindgen_test_layout_MutPtrMutObj() { concat!("Alignment of ", stringify!(MutPtrMutObj)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const MutPtrMutObj; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -102,8 +115,15 @@ fn bindgen_test_layout_MutPtrConstObj() { concat!("Alignment of ", stringify!(MutPtrConstObj)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const MutPtrConstObj; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -141,9 +161,15 @@ fn bindgen_test_layout_ConstPtrConstObj() { concat!("Alignment of ", stringify!(ConstPtrConstObj)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).bar as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ConstPtrConstObj; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index f861815234..e4ec39c63f 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -40,7 +40,15 @@ fn bindgen_test_layout_IntStr() { concat!("Alignment of ", stringify!(IntStr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const IntStr; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) ); @@ -73,7 +81,15 @@ fn bindgen_test_layout_FloatStr() { concat!("Alignment of ", stringify!(FloatStr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const FloatStr; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/tests/expectations/tests/derive-partialeq-and-blocklist.rs index d9dfb44618..99001aa273 100644 --- a/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -26,9 +26,16 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ShouldNotDerivePartialEq; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index cdf8dff8b4..75fe265f5d 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Base() { concat!("Alignment of ", stringify!(Base)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).large as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Base; + let field_ptr = std::ptr::addr_of!(struct_instance.large); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index cffffca57c..1a7c52fa4c 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -111,8 +111,14 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.large_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index 8cdfb92c6a..2079d8b2fc 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -25,8 +25,14 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - &(*(::core::ptr::null::())).large_array as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.large_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 17a5edcbbf..4c97a575dc 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) ); @@ -109,7 +117,15 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index b97c053198..7150806f71 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -24,32 +24,6 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { 4usize, concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(b) - ) - ); } impl Default for ShouldNotDerivePartialEq { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index 2098849f99..938a30ee34 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -68,32 +68,6 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { 4usize, concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(b) - ) - ); } impl Clone for ShouldDerivePartialEq { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/disable-nested-struct-naming.rs b/tests/expectations/tests/disable-nested-struct-naming.rs index a9ad26a50a..bae8d3e126 100644 --- a/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/tests/expectations/tests/disable-nested-struct-naming.rs @@ -46,7 +46,15 @@ fn bindgen_test_layout_bar4() { concat!("Alignment of ", stringify!(bar4)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x4 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar4; + let field_ptr = std::ptr::addr_of!(struct_instance.x4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) ); @@ -67,9 +75,17 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x3 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const bar1__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.x3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -80,9 +96,17 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b4 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const bar1__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -106,9 +130,15 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x2 as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.x2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -119,9 +149,15 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b3 as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -145,12 +181,28 @@ fn bindgen_test_layout_bar1() { concat!("Alignment of ", stringify!(bar1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x1 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar1; + let field_ptr = std::ptr::addr_of!(struct_instance.x1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b2 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar1; + let field_ptr = std::ptr::addr_of!(struct_instance.b2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) ); @@ -168,7 +220,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b1 as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.b1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) ); @@ -201,7 +261,15 @@ fn bindgen_test_layout_baz() { concat!("Alignment of ", stringify!(baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const baz; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) ); @@ -219,9 +287,16 @@ fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1__bindgen_ty_1>())).b - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::<_bindgen_ty_1__bindgen_ty_1>() }; + let struct_ptr = + &struct_instance as *const _bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -245,8 +320,15 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).anon2 as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::<_bindgen_ty_1>() }; + let struct_ptr = &struct_instance as *const _bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.anon2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/disable-untagged-union.rs b/tests/expectations/tests/disable-untagged-union.rs index 5300273384..c6a8c51515 100644 --- a/tests/expectations/tests/disable-untagged-union.rs +++ b/tests/expectations/tests/disable-untagged-union.rs @@ -67,14 +67,4 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) - ); } diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/tests/expectations/tests/do-not-derive-copy.rs index 4112d88a5c..d48dc97782 100644 --- a/tests/expectations/tests/do-not-derive-copy.rs +++ b/tests/expectations/tests/do-not-derive-copy.rs @@ -26,9 +26,17 @@ fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const WouldBeCopyButWeAreNotDerivingCopy; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index fa7a5e89dc..a2d241ad12 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Doggo() { concat!("Alignment of ", stringify!(Doggo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Doggo; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) ); diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 324fe2a0a7..59ef1768ac 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -31,8 +31,14 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -43,8 +49,14 @@ pub mod root { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).baz as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -77,8 +89,14 @@ pub mod root { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ptr as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.ptr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index b06a6cf809..1576f1a1cf 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_X() { concat!("Alignment of ", stringify!(X)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::()))._x as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const X; + let field_ptr = std::ptr::addr_of!(struct_instance._x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) ); diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index 8a66dc3f9a..5772d3a201 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::()))._x as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance._x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) ); diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 1520bea70d..607a304b8e 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -54,7 +54,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index 1a9513d928..795aba4880 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -26,7 +26,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index 73a0462eac..2263361ea4 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -28,7 +28,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index c47521a29c..167cf8b213 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -31,7 +31,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 67d263e94c..86889b5689 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -26,7 +26,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 9e9c6bcb2f..aa3f3d993f 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -34,7 +34,15 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index fa0018ba90..5646bc076e 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -23,8 +23,14 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).details as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const nsFoo; + let field_ptr = std::ptr::addr_of!(struct_instance.details); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index bf0b6926f1..d2ab5be72d 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -43,8 +43,14 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).m_member as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.m_member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index e185e83064..0d53ffae36 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -46,7 +46,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs index c6331c6941..52deea01d0 100644 --- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -56,7 +56,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index 2ecfc60ed6..f31bd9e7df 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); @@ -46,7 +54,15 @@ fn bindgen_test_layout_c() { concat!("Alignment of ", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const c; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 8f98763fbc..579f02479a 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -33,7 +33,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs index 67b6d70143..47576ae37c 100644 --- a/tests/expectations/tests/gen-destructors-neg.rs +++ b/tests/expectations/tests/gen-destructors-neg.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs index 7d96870df8..35adc5eb84 100644 --- a/tests/expectations/tests/gen-destructors.rs +++ b/tests/expectations/tests/gen-destructors.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/i128.rs b/tests/expectations/tests/i128.rs index 1a239694c4..fc3413d1d1 100644 --- a/tests/expectations/tests/i128.rs +++ b/tests/expectations/tests/i128.rs @@ -25,8 +25,14 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).my_signed as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.my_signed); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -37,8 +43,14 @@ fn bindgen_test_layout_foo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).my_unsigned as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.my_unsigned); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index 036d2da618..3cf1e90c0c 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -32,7 +32,15 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index 3d2ce0c419..2ef677dce0 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -37,7 +37,15 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index 912ae02422..21f69738e2 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -31,7 +31,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index 3361a1f9dd..0f93d63b22 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -38,9 +38,15 @@ fn bindgen_test_layout_InstantiateIt() { concat!("Alignment of ", stringify!(InstantiateIt)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).m_list as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const InstantiateIt; + let field_ptr = std::ptr::addr_of!(struct_instance.m_list); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/tests/expectations/tests/issue-1118-using-forward-decl.rs index 99f0341c9d..77ec9e5655 100644 --- a/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -24,8 +24,15 @@ fn bindgen_test_layout_nsTArray_base() { concat!("Alignment of ", stringify!(nsTArray_base)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const nsTArray_base; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -77,8 +84,14 @@ fn bindgen_test_layout_nsIContent() { concat!("Alignment of ", stringify!(nsIContent)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const nsIContent; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-1216-variadic-member.rs b/tests/expectations/tests/issue-1216-variadic-member.rs index 5bca80966c..08b5ee029e 100644 --- a/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/tests/expectations/tests/issue-1216-variadic-member.rs @@ -33,7 +33,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs index fe18fb1a0a..bcaa490ba1 100644 --- a/tests/expectations/tests/issue-1281.rs +++ b/tests/expectations/tests/issue-1281.rs @@ -28,7 +28,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) ); @@ -46,7 +54,15 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) ); @@ -70,7 +86,15 @@ fn bindgen_test_layout_baz() { concat!("Alignment of ", stringify!(baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const baz; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index 15b8c9e449..99b5aba9f2 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -28,30 +28,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -75,7 +51,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/issue-1291.rs b/tests/expectations/tests/issue-1291.rs index 5680c348cf..935ba129ce 100644 --- a/tests/expectations/tests/issue-1291.rs +++ b/tests/expectations/tests/issue-1291.rs @@ -38,7 +38,15 @@ fn bindgen_test_layout_RTCRay() { concat!("Alignment of ", stringify!(RTCRay)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).org as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.org); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -48,8 +56,14 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).align0 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.align0); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -60,7 +74,15 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).dir as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.dir); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!( "Offset of field: ", @@ -70,8 +92,14 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).align1 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.align1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 28usize, concat!( @@ -82,8 +110,14 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tnear as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.tnear); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -94,7 +128,15 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).tfar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.tfar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 36usize, concat!( "Offset of field: ", @@ -104,7 +146,15 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).time as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.time); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 40usize, concat!( "Offset of field: ", @@ -114,7 +164,15 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mask as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 44usize, concat!( "Offset of field: ", @@ -124,7 +182,15 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ng as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.Ng); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 48usize, concat!( "Offset of field: ", @@ -134,8 +200,14 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).align2 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.align2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 60usize, concat!( @@ -146,18 +218,40 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 64usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).v as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.v); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 68usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).geomID as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.geomID); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 72usize, concat!( @@ -168,8 +262,14 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).primID as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.primID); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 76usize, concat!( @@ -180,8 +280,14 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).instID as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RTCRay; + let field_ptr = std::ptr::addr_of!(struct_instance.instID); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 80usize, concat!( diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 6f5aec4b6f..4b25adcf42 100644 --- a/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -44,47 +44,119 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i8_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.i8_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u8_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.u8_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i16_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.i16_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u16_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.u16_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 12usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i32_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.i32_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u32_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.u32_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 20usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i64_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.i64_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 24usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u64_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.u64_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 28usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i128_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.i128_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 32usize, concat!( "Offset of field: ", @@ -94,7 +166,15 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u128_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.u128_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 36usize, concat!( "Offset of field: ", @@ -104,7 +184,15 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).isize_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.isize_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 40usize, concat!( "Offset of field: ", @@ -114,7 +202,15 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).usize_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.usize_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 44usize, concat!( "Offset of field: ", @@ -124,12 +220,28 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f32_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.f32_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 48usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f64_ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.f64_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 52usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) ); diff --git a/tests/expectations/tests/issue-1443.rs b/tests/expectations/tests/issue-1443.rs index f422f4c353..3e91e1e01e 100644 --- a/tests/expectations/tests/issue-1443.rs +++ b/tests/expectations/tests/issue-1443.rs @@ -29,12 +29,28 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.m); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) ); @@ -67,12 +83,28 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Baz; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Baz; + let field_ptr = std::ptr::addr_of!(struct_instance.m); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) ); @@ -105,12 +137,28 @@ fn bindgen_test_layout_Tar() { concat!("Alignment of ", stringify!(Tar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Tar; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Tar; + let field_ptr = std::ptr::addr_of!(struct_instance.m); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) ); @@ -143,12 +191,28 @@ fn bindgen_test_layout_Taz() { concat!("Alignment of ", stringify!(Taz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Taz; + let field_ptr = std::ptr::addr_of!(struct_instance.f); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Taz; + let field_ptr = std::ptr::addr_of!(struct_instance.m); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) ); diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs index e88e46978b..83e7371b05 100644 --- a/tests/expectations/tests/issue-1454.rs +++ b/tests/expectations/tests/issue-1454.rs @@ -27,8 +27,14 @@ fn bindgen_test_layout_local_type() { concat!("Alignment of ", stringify!(local_type)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).inner as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const local_type; + let field_ptr = std::ptr::addr_of!(struct_instance.inner); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index 4f8a89305b..11bf3da2d3 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -43,32 +43,6 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { 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 { @@ -92,9 +66,14 @@ fn bindgen_test_layout_rte_memseg() { concat!("Alignment of ", stringify!(rte_memseg)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).phys_addr as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_memseg; + let field_ptr = std::ptr::addr_of!(struct_instance.phys_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -105,8 +84,14 @@ fn bindgen_test_layout_rte_memseg() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_memseg; + let field_ptr = std::ptr::addr_of!(struct_instance.len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -117,9 +102,14 @@ fn bindgen_test_layout_rte_memseg() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hugepage_sz as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_memseg; + let field_ptr = std::ptr::addr_of!(struct_instance.hugepage_sz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -130,9 +120,14 @@ fn bindgen_test_layout_rte_memseg() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).socket_id as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_memseg; + let field_ptr = std::ptr::addr_of!(struct_instance.socket_id); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -143,8 +138,14 @@ fn bindgen_test_layout_rte_memseg() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nchannel as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_memseg; + let field_ptr = std::ptr::addr_of!(struct_instance.nchannel); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 36usize, concat!( @@ -155,8 +156,14 @@ fn bindgen_test_layout_rte_memseg() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nrank as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_memseg; + let field_ptr = std::ptr::addr_of!(struct_instance.nrank); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( diff --git a/tests/expectations/tests/issue-1947.rs b/tests/expectations/tests/issue-1947.rs index 1753ef8d02..fabe688f94 100644 --- a/tests/expectations/tests/issue-1947.rs +++ b/tests/expectations/tests/issue-1947.rs @@ -118,8 +118,14 @@ fn bindgen_test_layout_V56AMDY() { concat!("Alignment of ", stringify!(V56AMDY)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).MADK as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const V56AMDY; + let field_ptr = std::ptr::addr_of!(struct_instance.MADK); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -130,8 +136,14 @@ fn bindgen_test_layout_V56AMDY() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).MABR as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const V56AMDY; + let field_ptr = std::ptr::addr_of!(struct_instance.MABR); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 3usize, concat!( @@ -142,8 +154,14 @@ fn bindgen_test_layout_V56AMDY() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::()))._rB_ as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const V56AMDY; + let field_ptr = std::ptr::addr_of!(struct_instance._rB_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 7usize, concat!( diff --git a/tests/expectations/tests/issue-1995.rs b/tests/expectations/tests/issue-1995.rs index 58e11eb297..282343c90b 100644 --- a/tests/expectations/tests/issue-1995.rs +++ b/tests/expectations/tests/issue-1995.rs @@ -30,7 +30,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/issue-2019.rs b/tests/expectations/tests/issue-2019.rs index 383bd57e15..6030e076cf 100644 --- a/tests/expectations/tests/issue-2019.rs +++ b/tests/expectations/tests/issue-2019.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) ); @@ -56,7 +64,15 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index 0cd9f7adb3..3df94cb801 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -29,17 +29,41 @@ pub mod root { concat!("Alignment of ", stringify!(i)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).j as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const i; + let field_ptr = std::ptr::addr_of!(struct_instance.j); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).k as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const i; + let field_ptr = std::ptr::addr_of!(struct_instance.k); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).l as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const i; + let field_ptr = std::ptr::addr_of!(struct_instance.l); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) ); @@ -71,7 +95,15 @@ pub mod root { concat!("Alignment of ", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const d; + let field_ptr = std::ptr::addr_of!(struct_instance.m); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) ); @@ -118,7 +150,15 @@ pub mod root { concat!("Alignment of ", stringify!(F)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).w as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const F; + let field_ptr = std::ptr::addr_of!(struct_instance.w); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) ); diff --git a/tests/expectations/tests/issue-537-repr-packed-n.rs b/tests/expectations/tests/issue-537-repr-packed-n.rs index 13e1482d30..6e37fcd5bc 100644 --- a/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -26,8 +26,14 @@ fn bindgen_test_layout_AlignedToOne() { concat!("Alignment of ", stringify!(AlignedToOne)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AlignedToOne; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -57,8 +63,14 @@ fn bindgen_test_layout_AlignedToTwo() { concat!("Alignment of ", stringify!(AlignedToTwo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AlignedToTwo; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -91,8 +103,14 @@ fn bindgen_test_layout_PackedToOne() { concat!("Alignment of ", stringify!(PackedToOne)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToOne; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -103,8 +121,14 @@ fn bindgen_test_layout_PackedToOne() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToOne; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -135,8 +159,14 @@ fn bindgen_test_layout_PackedToTwo() { concat!("Alignment of ", stringify!(PackedToTwo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToTwo; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -147,8 +177,14 @@ fn bindgen_test_layout_PackedToTwo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToTwo; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs index e67c0e9c2e..9b0ddac41c 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -25,8 +25,14 @@ fn bindgen_test_layout_AlignedToOne() { concat!("Alignment of ", stringify!(AlignedToOne)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AlignedToOne; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -57,8 +63,14 @@ fn bindgen_test_layout_AlignedToTwo() { concat!("Alignment of ", stringify!(AlignedToTwo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AlignedToTwo; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -91,8 +103,14 @@ fn bindgen_test_layout_PackedToOne() { concat!("Alignment of ", stringify!(PackedToOne)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToOne; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -103,8 +121,14 @@ fn bindgen_test_layout_PackedToOne() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToOne; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -137,8 +161,14 @@ fn bindgen_test_layout_PackedToTwo() { concat!("Alignment of ", stringify!(PackedToTwo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToTwo; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -149,8 +179,14 @@ fn bindgen_test_layout_PackedToTwo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PackedToTwo; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 871849aa47..2af82ca2ca 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -28,8 +28,14 @@ fn bindgen_test_layout_AutoIdVector() { concat!("Alignment of ", stringify!(AutoIdVector)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ar as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const AutoIdVector; + let field_ptr = std::ptr::addr_of!(struct_instance.ar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index e04ff24cba..990d4a6811 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -28,8 +28,15 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).ar as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::<_bindgen_ty_1>() }; + let struct_ptr = &struct_instance as *const _bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.ar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 01abdcc412..bd48d69e77 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -62,7 +62,15 @@ fn bindgen_test_layout_g() { concat!("Alignment of ", stringify!(g)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).h as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const g; + let field_ptr = std::ptr::addr_of!(struct_instance.h); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) ); diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs index 4147c1d228..d3024cfa77 100644 --- a/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -28,7 +28,15 @@ fn bindgen_test_layout_Foo_Bar() { concat!("Alignment of ", stringify!(Foo_Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).abc as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo_Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.abc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -51,7 +59,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); @@ -79,7 +95,15 @@ fn bindgen_test_layout_Baz_Bar() { concat!("Alignment of ", stringify!(Baz_Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).abc as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Baz_Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.abc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", 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 15822b5bdf..b241d27d5c 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -28,7 +28,15 @@ fn bindgen_test_layout_NoDebug() { concat!("Alignment of ", stringify!(NoDebug)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NoDebug; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -76,9 +84,16 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ShouldDeriveDebugButDoesNot; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -89,9 +104,16 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ShouldDeriveDebugButDoesNot; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index 5ad6694730..e35c32c83f 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -37,9 +37,16 @@ pub mod root { concat!("Alignment of ", stringify!(CapturingContentInfo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const CapturingContentInfo; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index 4ccc4504c3..71b3aac0a6 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -37,7 +37,15 @@ pub mod root { concat!("Alignment of ", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const c; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) ); @@ -60,7 +68,15 @@ pub mod root { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index 99c96b969b..3261a8eede 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -33,7 +33,15 @@ pub mod root { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); @@ -56,8 +64,15 @@ pub mod root { concat!("Alignment of ", stringify!(nsCSSValue)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const nsCSSValue; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 6fe3cc681f..42704d0ae1 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -51,7 +51,15 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) ); 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 7fd9caa309..c4273f0a95 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 @@ -120,9 +120,14 @@ fn bindgen_test_layout_Allowlisted() { concat!("Alignment of ", stringify!(Allowlisted)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).some_member as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Allowlisted; + let field_ptr = std::ptr::addr_of!(struct_instance.some_member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index dc50fe1bfa..6254fefcf4 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -25,8 +25,15 @@ fn bindgen_test_layout_ShouldNotBeCopy() { concat!("Alignment of ", stringify!(ShouldNotBeCopy)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ShouldNotBeCopy; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 5b8427913c..7c589dd56c 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -293,45 +293,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .i32_ as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .u32_ as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .why as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) - ); } impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn default() -> Self { @@ -355,9 +316,16 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).payload - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const jsval_layout__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.payload); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -389,93 +357,6 @@ fn bindgen_test_layout_jsval_layout() { 8usize, concat!("Alignment of ", stringify!(jsval_layout)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asBits as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).debugView as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).s as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asDouble as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asPtr as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asWord as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asUIntPtr as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) - ); } impl Default for jsval_layout { fn default() -> Self { @@ -504,7 +385,15 @@ fn bindgen_test_layout_Value() { concat!("Alignment of ", stringify!(Value)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).data as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Value; + let field_ptr = std::ptr::addr_of!(struct_instance.data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 260282dbba..02964ad1ee 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -343,45 +343,6 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .i32_ as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .u32_ as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .why as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) - ); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn clone(&self) -> Self { @@ -401,9 +362,16 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).payload - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const jsval_layout__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.payload); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -431,93 +399,6 @@ fn bindgen_test_layout_jsval_layout() { 8usize, concat!("Alignment of ", stringify!(jsval_layout)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asBits as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).debugView as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).s as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asDouble as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asPtr as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asWord as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).asUIntPtr as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) - ); } impl Clone for jsval_layout { fn clone(&self) -> Self { @@ -542,7 +423,15 @@ fn bindgen_test_layout_Value() { concat!("Alignment of ", stringify!(Value)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).data as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Value; + let field_ptr = std::ptr::addr_of!(struct_instance.data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index d6642d7e2b..dd00c7d02c 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -41,9 +41,14 @@ fn bindgen_test_layout_ether_addr() { concat!("Alignment of ", stringify!(ether_addr)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).addr_bytes as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ether_addr; + let field_ptr = std::ptr::addr_of!(struct_instance.addr_bytes); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -80,8 +85,14 @@ fn bindgen_test_layout_arp_ipv4() { concat!("Alignment of ", stringify!(arp_ipv4)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_sha as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_ipv4; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_sha); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -92,8 +103,14 @@ fn bindgen_test_layout_arp_ipv4() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_sip as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_ipv4; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_sip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 6usize, concat!( @@ -104,8 +121,14 @@ fn bindgen_test_layout_arp_ipv4() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_tha as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_ipv4; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_tha); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 10usize, concat!( @@ -116,8 +139,14 @@ fn bindgen_test_layout_arp_ipv4() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_tip as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_ipv4; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_tip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -152,8 +181,14 @@ fn bindgen_test_layout_arp_hdr() { concat!("Alignment of ", stringify!(arp_hdr)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_hrd as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_hrd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -164,8 +199,14 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_pro as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_pro); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -176,8 +217,14 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_hln as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_hln); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -188,8 +235,14 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_pln as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_pln); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 5usize, concat!( @@ -200,8 +253,14 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_op as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_op); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 6usize, concat!( @@ -212,8 +271,14 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arp_data as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const arp_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.arp_data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 3ba1b6d0ba..39d157fa13 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -80,9 +80,15 @@ fn bindgen_test_layout_rte_mempool_ops() { concat!("Alignment of ", stringify!(rte_mempool_ops)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).name as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.name); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -93,9 +99,15 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).alloc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.alloc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -106,9 +118,15 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).free as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.free); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( @@ -119,9 +137,15 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).enqueue as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.enqueue); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 48usize, concat!( @@ -132,9 +156,15 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dequeue as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.dequeue); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -145,9 +175,15 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).get_count as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.get_count); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -197,9 +233,15 @@ fn bindgen_test_layout_rte_spinlock_t() { concat!("Alignment of ", stringify!(rte_spinlock_t)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).locked as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_spinlock_t; + let field_ptr = std::ptr::addr_of!(struct_instance.locked); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -242,9 +284,15 @@ fn bindgen_test_layout_rte_mempool_ops_table() { concat!("Alignment of ", stringify!(rte_mempool_ops_table)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sl as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops_table; + let field_ptr = std::ptr::addr_of!(struct_instance.sl); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -255,9 +303,15 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).num_ops - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops_table; + let field_ptr = std::ptr::addr_of!(struct_instance.num_ops); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -268,9 +322,15 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ops as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mempool_ops_table; + let field_ptr = std::ptr::addr_of!(struct_instance.ops); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -318,9 +378,16 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lh_first - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const malloc_heap__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.lh_first); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -353,8 +420,14 @@ fn bindgen_test_layout_malloc_heap() { concat!("Alignment of ", stringify!(malloc_heap)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lock as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const malloc_heap; + let field_ptr = std::ptr::addr_of!(struct_instance.lock); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -365,9 +438,14 @@ fn bindgen_test_layout_malloc_heap() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).free_head as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const malloc_heap; + let field_ptr = std::ptr::addr_of!(struct_instance.free_head); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -378,9 +456,14 @@ fn bindgen_test_layout_malloc_heap() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).alloc_count as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const malloc_heap; + let field_ptr = std::ptr::addr_of!(struct_instance.alloc_count); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 112usize, concat!( @@ -391,9 +474,14 @@ fn bindgen_test_layout_malloc_heap() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).total_size as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const malloc_heap; + let field_ptr = std::ptr::addr_of!(struct_instance.total_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 120usize, concat!( diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index c9880ea2a9..51620a111d 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -46,7 +46,15 @@ fn bindgen_test_layout_ip_frag() { concat!("Alignment of ", stringify!(ip_frag)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ofs as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag; + let field_ptr = std::ptr::addr_of!(struct_instance.ofs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -56,7 +64,15 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag; + let field_ptr = std::ptr::addr_of!(struct_instance.len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 2usize, concat!( "Offset of field: ", @@ -66,7 +82,15 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mb as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag; + let field_ptr = std::ptr::addr_of!(struct_instance.mb); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!( "Offset of field: ", @@ -109,8 +133,14 @@ fn bindgen_test_layout_ip_frag_key() { concat!("Alignment of ", stringify!(ip_frag_key)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_dst as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_key; + let field_ptr = std::ptr::addr_of!(struct_instance.src_dst); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -121,8 +151,14 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).id as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_key; + let field_ptr = std::ptr::addr_of!(struct_instance.id); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -133,8 +169,14 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).key_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_key; + let field_ptr = std::ptr::addr_of!(struct_instance.key_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 36usize, concat!( @@ -185,9 +227,16 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tqe_next - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ip_frag_pkt__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.tqe_next); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -198,9 +247,16 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tqe_prev - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ip_frag_pkt__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.tqe_prev); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -233,8 +289,14 @@ fn bindgen_test_layout_ip_frag_pkt() { concat!("Alignment of ", stringify!(ip_frag_pkt)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lru as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.lru); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -245,8 +307,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).key as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.key); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -257,8 +325,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).start as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.start); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -269,9 +343,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).total_size as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.total_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -282,9 +361,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).frag_size as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.frag_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 68usize, concat!( @@ -295,9 +379,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).last_idx as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.last_idx); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 72usize, concat!( @@ -308,8 +397,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).frags as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.frags); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 80usize, concat!( diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 644b1b8aab..6679bcf8bf 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -26,9 +26,15 @@ fn bindgen_test_layout_cmdline_token_hdr() { concat!("Alignment of ", stringify!(cmdline_token_hdr)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ops as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.ops); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -39,9 +45,15 @@ fn bindgen_test_layout_cmdline_token_hdr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).offset as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_hdr; + let field_ptr = std::ptr::addr_of!(struct_instance.offset); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -128,9 +140,15 @@ fn bindgen_test_layout_cmdline_token_ops() { concat!("Alignment of ", stringify!(cmdline_token_ops)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).parse as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.parse); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -141,9 +159,15 @@ fn bindgen_test_layout_cmdline_token_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).complete_get_nb - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.complete_get_nb); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -154,9 +178,16 @@ fn bindgen_test_layout_cmdline_token_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).complete_get_elt - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_ops; + let field_ptr = + std::ptr::addr_of!(struct_instance.complete_get_elt); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -167,9 +198,15 @@ fn bindgen_test_layout_cmdline_token_ops() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).get_help as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_ops; + let field_ptr = std::ptr::addr_of!(struct_instance.get_help); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -210,9 +247,15 @@ fn bindgen_test_layout_cmdline_token_num_data() { concat!("Alignment of ", stringify!(cmdline_token_num_data)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).type_ as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_num_data; + let field_ptr = std::ptr::addr_of!(struct_instance.type_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -251,9 +294,15 @@ fn bindgen_test_layout_cmdline_token_num() { concat!("Alignment of ", stringify!(cmdline_token_num)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hdr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_num; + let field_ptr = std::ptr::addr_of!(struct_instance.hdr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -264,9 +313,15 @@ fn bindgen_test_layout_cmdline_token_num() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).num_data as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const cmdline_token_num; + let field_ptr = std::ptr::addr_of!(struct_instance.num_data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index e880608203..1b941b9e0c 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -171,9 +171,15 @@ fn bindgen_test_layout_rte_eth_rxmode() { concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rxmode; + let field_ptr = std::ptr::addr_of!(struct_instance.mq_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -184,9 +190,15 @@ fn bindgen_test_layout_rte_eth_rxmode() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_rx_pkt_len - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rxmode; + let field_ptr = std::ptr::addr_of!(struct_instance.max_rx_pkt_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -197,9 +209,15 @@ fn bindgen_test_layout_rte_eth_rxmode() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).split_hdr_size - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rxmode; + let field_ptr = std::ptr::addr_of!(struct_instance.split_hdr_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -436,9 +454,15 @@ fn bindgen_test_layout_rte_eth_txmode() { concat!("Alignment of ", stringify!(rte_eth_txmode)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_txmode; + let field_ptr = std::ptr::addr_of!(struct_instance.mq_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -449,8 +473,15 @@ fn bindgen_test_layout_rte_eth_txmode() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pvid as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_txmode; + let field_ptr = std::ptr::addr_of!(struct_instance.pvid); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -574,9 +605,15 @@ fn bindgen_test_layout_rte_eth_rss_conf() { concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_key as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rss_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_key); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -587,9 +624,15 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_key_len as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rss_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_key_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -600,9 +643,15 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_hf as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rss_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_hf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -694,9 +743,17 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_id); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -707,9 +764,17 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .pools as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -733,9 +798,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -746,9 +817,16 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .enable_default_pool as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.enable_default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -759,9 +837,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 5usize, concat!( @@ -772,9 +856,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_pool_maps); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 6usize, concat!( @@ -785,9 +875,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.pool_map); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -798,9 +894,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1032usize, concat!( @@ -841,9 +943,15 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_tcs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -854,9 +962,15 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -897,9 +1011,16 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -910,9 +1031,16 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -953,9 +1081,15 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_tcs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -966,9 +1100,15 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1007,9 +1147,15 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1071,9 +1217,17 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_rx_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_id); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1084,9 +1238,17 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pools - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_rx_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1110,9 +1272,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1123,9 +1291,16 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).enable_default_pool - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.enable_default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1136,9 +1311,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 5usize, concat!( @@ -1149,9 +1330,16 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).enable_loop_back - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.enable_loop_back); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 6usize, concat!( @@ -1162,9 +1350,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_pool_maps); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 7usize, concat!( @@ -1175,9 +1369,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rx_mode as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rx_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1188,9 +1388,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.pool_map); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1276,9 +1482,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.src_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1289,9 +1501,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1302,9 +1520,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tos as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.tos); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1315,9 +1539,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ttl as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.ttl); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 9usize, concat!( @@ -1328,9 +1558,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.proto); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 10usize, concat!( @@ -1369,9 +1605,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.src_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1382,9 +1624,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1395,9 +1643,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -1408,9 +1662,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.proto); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 33usize, concat!( @@ -1421,9 +1681,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hop_limits as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.hop_limits); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 34usize, concat!( @@ -1471,9 +1737,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vlan_tci_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_tci_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1484,9 +1756,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ipv4_mask as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.ipv4_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1497,9 +1775,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ipv6_mask as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.ipv6_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1510,9 +1794,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_port_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.src_port_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 52usize, concat!( @@ -1523,9 +1813,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_port_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_port_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 54usize, concat!( @@ -1536,9 +1832,16 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mac_addr_byte_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = + std::ptr::addr_of!(struct_instance.mac_addr_byte_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -1549,9 +1852,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tunnel_id_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.tunnel_id_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 60usize, concat!( @@ -1562,9 +1871,16 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tunnel_type_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = + std::ptr::addr_of!(struct_instance.tunnel_type_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -1608,9 +1924,16 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).type_ - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_flex_payload_cfg; + let field_ptr = std::ptr::addr_of!(struct_instance.type_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1621,9 +1944,16 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_offset - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_flex_payload_cfg; + let field_ptr = std::ptr::addr_of!(struct_instance.src_offset); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1664,9 +1994,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flow_type - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_mask; + let field_ptr = std::ptr::addr_of!(struct_instance.flow_type); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1677,9 +2013,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mask as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_mask; + let field_ptr = std::ptr::addr_of!(struct_instance.mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -1715,9 +2057,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_payloads - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_payloads); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1728,9 +2076,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_flexmasks - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_flexmasks); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -1741,9 +2095,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flex_set - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.flex_set); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1754,9 +2114,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flex_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.flex_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 292usize, concat!( @@ -1807,8 +2173,15 @@ fn bindgen_test_layout_rte_fdir_conf() { concat!("Alignment of ", stringify!(rte_fdir_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mode as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1819,9 +2192,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pballoc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.pballoc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1832,9 +2211,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).status as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.status); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1845,9 +2230,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).drop_queue as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.drop_queue); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -1858,8 +2249,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mask as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1870,9 +2268,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flex_conf as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.flex_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 84usize, concat!( @@ -1914,8 +2318,15 @@ fn bindgen_test_layout_rte_intr_conf() { concat!("Alignment of ", stringify!(rte_intr_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lsc as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_intr_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.lsc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1926,8 +2337,15 @@ fn bindgen_test_layout_rte_intr_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rxq as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_intr_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rxq); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -1996,9 +2414,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -2009,9 +2434,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vmdq_dcb_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vmdq_dcb_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -2022,9 +2454,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_rx_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_rx_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1064usize, concat!( @@ -2035,9 +2474,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vmdq_rx_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vmdq_rx_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1080usize, concat!( @@ -2076,45 +2522,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .vmdq_dcb_tx_conf as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tx_conf - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vmdq_tx_conf - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) - ); } impl Default for rte_eth_conf__bindgen_ty_2 { fn default() -> Self { @@ -2138,9 +2545,14 @@ fn bindgen_test_layout_rte_eth_conf() { concat!("Alignment of ", stringify!(rte_eth_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).link_speeds as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.link_speeds); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -2151,8 +2563,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rxmode as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rxmode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -2163,8 +2581,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).txmode as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.txmode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -2175,9 +2599,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lpbk_mode as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.lpbk_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -2188,9 +2617,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rx_adv_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rx_adv_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -2201,9 +2635,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tx_adv_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.tx_adv_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2152usize, concat!( @@ -2214,9 +2653,15 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_capability_en - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.dcb_capability_en); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2164usize, concat!( @@ -2227,9 +2672,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).fdir_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.fdir_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2168usize, concat!( @@ -2240,9 +2690,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).intr_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.intr_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2940usize, concat!( diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index fde1c678cf..59a355b154 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -214,9 +214,15 @@ fn bindgen_test_layout_rte_eth_rxmode() { concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rxmode; + let field_ptr = std::ptr::addr_of!(struct_instance.mq_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -227,9 +233,15 @@ fn bindgen_test_layout_rte_eth_rxmode() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_rx_pkt_len - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rxmode; + let field_ptr = std::ptr::addr_of!(struct_instance.max_rx_pkt_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -240,9 +252,15 @@ fn bindgen_test_layout_rte_eth_rxmode() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).split_hdr_size - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rxmode; + let field_ptr = std::ptr::addr_of!(struct_instance.split_hdr_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -484,9 +502,15 @@ fn bindgen_test_layout_rte_eth_txmode() { concat!("Alignment of ", stringify!(rte_eth_txmode)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_txmode; + let field_ptr = std::ptr::addr_of!(struct_instance.mq_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -497,8 +521,15 @@ fn bindgen_test_layout_rte_eth_txmode() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pvid as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_txmode; + let field_ptr = std::ptr::addr_of!(struct_instance.pvid); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -627,9 +658,15 @@ fn bindgen_test_layout_rte_eth_rss_conf() { concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_key as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rss_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_key); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -640,9 +677,15 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_key_len as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rss_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_key_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -653,9 +696,15 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_hf as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_rss_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_hf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -752,9 +801,17 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_id); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -765,9 +822,17 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .pools as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -796,9 +861,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -809,9 +880,16 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .enable_default_pool as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.enable_default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -822,9 +900,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 5usize, concat!( @@ -835,9 +919,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_pool_maps); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 6usize, concat!( @@ -848,9 +938,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.pool_map); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -861,9 +957,15 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_dcb_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1032usize, concat!( @@ -909,9 +1011,15 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_tcs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -922,9 +1030,15 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -970,9 +1084,16 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -983,9 +1104,16 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1031,9 +1159,15 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_tcs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1044,9 +1178,15 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_dcb_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1090,9 +1230,15 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_tx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1159,9 +1305,17 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_rx_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_id); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1172,9 +1326,17 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pools - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_eth_vmdq_rx_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1203,9 +1365,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_queue_pools); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1216,9 +1384,16 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).enable_default_pool - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.enable_default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1229,9 +1404,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.default_pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 5usize, concat!( @@ -1242,9 +1423,16 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).enable_loop_back - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.enable_loop_back); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 6usize, concat!( @@ -1255,9 +1443,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_pool_maps); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 7usize, concat!( @@ -1268,9 +1462,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rx_mode as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rx_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1281,9 +1481,15 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_vmdq_rx_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.pool_map); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1374,9 +1580,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.src_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1387,9 +1599,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1400,9 +1618,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tos as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.tos); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1413,9 +1637,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ttl as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.ttl); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 9usize, concat!( @@ -1426,9 +1656,15 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv4_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.proto); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 10usize, concat!( @@ -1472,9 +1708,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.src_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1485,9 +1727,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_ip); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1498,9 +1746,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.tc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -1511,9 +1765,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.proto); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 33usize, concat!( @@ -1524,9 +1784,15 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hop_limits as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_ipv6_flow; + let field_ptr = std::ptr::addr_of!(struct_instance.hop_limits); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 34usize, concat!( @@ -1579,9 +1845,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vlan_tci_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_tci_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1592,9 +1864,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ipv4_mask as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.ipv4_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1605,9 +1883,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ipv6_mask as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.ipv6_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1618,9 +1902,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_port_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.src_port_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 52usize, concat!( @@ -1631,9 +1921,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dst_port_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.dst_port_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 54usize, concat!( @@ -1644,9 +1940,16 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mac_addr_byte_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = + std::ptr::addr_of!(struct_instance.mac_addr_byte_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -1657,9 +1960,15 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tunnel_id_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = std::ptr::addr_of!(struct_instance.tunnel_id_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 60usize, concat!( @@ -1670,9 +1979,16 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tunnel_type_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_masks; + let field_ptr = + std::ptr::addr_of!(struct_instance.tunnel_type_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -1721,9 +2037,16 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).type_ - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_flex_payload_cfg; + let field_ptr = std::ptr::addr_of!(struct_instance.type_); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1734,9 +2057,16 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_offset - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_flex_payload_cfg; + let field_ptr = std::ptr::addr_of!(struct_instance.src_offset); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1782,9 +2112,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flow_type - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_mask; + let field_ptr = std::ptr::addr_of!(struct_instance.flow_type); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1795,9 +2131,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mask as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_mask; + let field_ptr = std::ptr::addr_of!(struct_instance.mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -1838,9 +2180,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_payloads - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_payloads); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1851,9 +2199,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_flexmasks - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_flexmasks); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -1864,9 +2218,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flex_set - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.flex_set); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1877,9 +2237,15 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flex_mask - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_fdir_flex_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.flex_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 292usize, concat!( @@ -1935,8 +2301,15 @@ fn bindgen_test_layout_rte_fdir_conf() { concat!("Alignment of ", stringify!(rte_fdir_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mode as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1947,9 +2320,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pballoc as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.pballoc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -1960,9 +2339,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).status as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.status); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1973,9 +2358,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).drop_queue as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.drop_queue); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -1986,8 +2377,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mask as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1998,9 +2396,15 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flex_conf as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_fdir_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.flex_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 84usize, concat!( @@ -2047,8 +2451,15 @@ fn bindgen_test_layout_rte_intr_conf() { concat!("Alignment of ", stringify!(rte_intr_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lsc as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_intr_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.lsc); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -2059,8 +2470,15 @@ fn bindgen_test_layout_rte_intr_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rxq as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_intr_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rxq); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -2134,9 +2552,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.rss_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -2147,9 +2572,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vmdq_dcb_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vmdq_dcb_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -2160,9 +2592,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_rx_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.dcb_rx_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1064usize, concat!( @@ -2173,9 +2612,16 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vmdq_rx_conf - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const rte_eth_conf__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.vmdq_rx_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1080usize, concat!( @@ -2220,45 +2666,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .vmdq_dcb_tx_conf as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_tx_conf - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vmdq_tx_conf - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) - ); } impl Clone for rte_eth_conf__bindgen_ty_2 { fn clone(&self) -> Self { @@ -2278,9 +2685,14 @@ fn bindgen_test_layout_rte_eth_conf() { concat!("Alignment of ", stringify!(rte_eth_conf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).link_speeds as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.link_speeds); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -2291,8 +2703,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rxmode as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rxmode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -2303,8 +2721,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).txmode as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.txmode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -2315,9 +2739,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lpbk_mode as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.lpbk_mode); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -2328,9 +2757,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rx_adv_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.rx_adv_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -2341,9 +2775,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tx_adv_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.tx_adv_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2152usize, concat!( @@ -2354,9 +2793,15 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dcb_capability_en - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = + std::ptr::addr_of!(struct_instance.dcb_capability_en); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2164usize, concat!( @@ -2367,9 +2812,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).fdir_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.fdir_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2168usize, concat!( @@ -2380,9 +2830,14 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).intr_conf as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_conf; + let field_ptr = std::ptr::addr_of!(struct_instance.intr_conf); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2940usize, concat!( diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index e73344c7d0..8796b9a92f 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -45,9 +45,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { concat!("Alignment of ", stringify!(rte_kni_mbuf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_addr as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -58,9 +63,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_physaddr as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_physaddr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -71,8 +81,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pad0 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pad0); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -83,9 +99,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data_off as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.data_off); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 18usize, concat!( @@ -96,8 +117,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pad1 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pad1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 20usize, concat!( @@ -108,9 +135,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_segs as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_segs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 22usize, concat!( @@ -121,8 +153,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pad4 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pad4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 23usize, concat!( @@ -133,9 +171,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ol_flags as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.ol_flags); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -146,8 +189,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pad2 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pad2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -158,9 +207,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pkt_len as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pkt_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 36usize, concat!( @@ -171,9 +225,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data_len as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.data_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( @@ -184,8 +243,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pad3 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pad3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -196,8 +261,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pool as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 72usize, concat!( @@ -208,8 +279,14 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).next as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.next); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 80usize, concat!( diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 4208e7259c..8d288712f0 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -76,7 +76,15 @@ fn bindgen_test_layout_ip_frag() { concat!("Alignment of ", stringify!(ip_frag)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ofs as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag; + let field_ptr = std::ptr::addr_of!(struct_instance.ofs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -86,7 +94,15 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag; + let field_ptr = std::ptr::addr_of!(struct_instance.len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 2usize, concat!( "Offset of field: ", @@ -96,7 +112,15 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mb as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag; + let field_ptr = std::ptr::addr_of!(struct_instance.mb); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!( "Offset of field: ", @@ -139,8 +163,14 @@ fn bindgen_test_layout_ip_frag_key() { concat!("Alignment of ", stringify!(ip_frag_key)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).src_dst as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_key; + let field_ptr = std::ptr::addr_of!(struct_instance.src_dst); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -151,8 +181,14 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).id as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_key; + let field_ptr = std::ptr::addr_of!(struct_instance.id); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -163,8 +199,14 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).key_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_key; + let field_ptr = std::ptr::addr_of!(struct_instance.key_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 36usize, concat!( @@ -215,9 +257,16 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tqe_next - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ip_frag_pkt__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.tqe_next); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -228,9 +277,16 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tqe_prev - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ip_frag_pkt__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.tqe_prev); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -263,8 +319,14 @@ fn bindgen_test_layout_ip_frag_pkt() { concat!("Alignment of ", stringify!(ip_frag_pkt)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lru as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.lru); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -275,8 +337,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).key as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.key); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -287,8 +355,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).start as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.start); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -299,9 +373,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).total_size as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.total_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -312,9 +391,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).frag_size as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.frag_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 68usize, concat!( @@ -325,9 +409,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).last_idx as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.last_idx); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 72usize, concat!( @@ -338,8 +427,14 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).frags as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_pkt; + let field_ptr = std::ptr::addr_of!(struct_instance.frags); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 80usize, concat!( @@ -378,9 +473,14 @@ fn bindgen_test_layout_ip_pkt_list() { concat!("Alignment of ", stringify!(ip_pkt_list)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tqh_first as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_pkt_list; + let field_ptr = std::ptr::addr_of!(struct_instance.tqh_first); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -391,9 +491,14 @@ fn bindgen_test_layout_ip_pkt_list() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tqh_last as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_pkt_list; + let field_ptr = std::ptr::addr_of!(struct_instance.tqh_last); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -444,9 +549,15 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { concat!("Alignment of ", stringify!(ip_frag_tbl_stat)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).find_num as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_tbl_stat; + let field_ptr = std::ptr::addr_of!(struct_instance.find_num); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -457,9 +568,15 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).add_num as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_tbl_stat; + let field_ptr = std::ptr::addr_of!(struct_instance.add_num); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -470,9 +587,15 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).del_num as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_tbl_stat; + let field_ptr = std::ptr::addr_of!(struct_instance.del_num); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -483,9 +606,15 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).reuse_num as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_tbl_stat; + let field_ptr = std::ptr::addr_of!(struct_instance.reuse_num); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -496,9 +625,15 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).fail_total as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_tbl_stat; + let field_ptr = std::ptr::addr_of!(struct_instance.fail_total); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -509,9 +644,15 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).fail_nospace - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ip_frag_tbl_stat; + let field_ptr = std::ptr::addr_of!(struct_instance.fail_nospace); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( @@ -572,9 +713,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { concat!("Alignment of ", stringify!(rte_ip_frag_tbl)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_cycles as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.max_cycles); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -585,9 +732,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).entry_mask as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.entry_mask); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -598,9 +751,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_entries as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.max_entries); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -611,9 +770,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).use_entries as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.use_entries); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -624,9 +789,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).bucket_entries - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.bucket_entries); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 20usize, concat!( @@ -637,9 +808,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_entries as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_entries); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -650,9 +827,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_buckets as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_buckets); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 28usize, concat!( @@ -663,9 +846,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).last as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.last); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -676,8 +865,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lru as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.lru); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( @@ -688,9 +884,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).stat as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.stat); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -701,8 +903,15 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pkt as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ip_frag_tbl; + let field_ptr = std::ptr::addr_of!(struct_instance.pkt); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 128usize, concat!( diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index aefce3d6e3..a9fa1e9cb9 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -117,8 +117,15 @@ fn bindgen_test_layout_rte_atomic16_t() { concat!("Alignment of ", stringify!(rte_atomic16_t)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cnt as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_atomic16_t; + let field_ptr = std::ptr::addr_of!(struct_instance.cnt); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -202,32 +209,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).refcnt_atomic - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).refcnt - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) - ); } impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { @@ -421,19 +402,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).packet_type - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) - ); } impl Default for rte_mbuf__bindgen_ty_2 { fn default() -> Self { @@ -480,8 +448,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ) { assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . hash as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . id as * const _ as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq ! ({ let struct_instance = unsafe { std :: mem :: zeroed :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () } ; let struct_ptr = & struct_instance as * const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ; let field_ptr = std :: ptr :: addr_of ! (struct_instance . hash) ; let struct_address = struct_ptr as usize ; let field_address = field_ptr as usize ; std :: mem :: forget (struct_instance) ; field_address . checked_sub (struct_address) . unwrap () } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! ({ let struct_instance = unsafe { std :: mem :: zeroed :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () } ; let struct_ptr = & struct_instance as * const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ; let field_ptr = std :: ptr :: addr_of ! (struct_instance . id) ; let struct_address = struct_ptr as usize ; let field_address = field_ptr as usize ; std :: mem :: forget (struct_instance) ; field_address . checked_sub (struct_address) . unwrap () } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { @@ -504,21 +472,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >())) - .lo as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) - ); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { @@ -548,9 +501,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.hi); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -595,9 +556,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lo - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_mbuf__bindgen_ty_3__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.lo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -608,9 +577,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_mbuf__bindgen_ty_3__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.hi); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -633,58 +610,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).fdir as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sched as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).usr as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) - ); } impl Default for rte_mbuf__bindgen_ty_3 { fn default() -> Self { @@ -715,32 +640,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).userdata - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).udata64 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) - ); } impl Default for rte_mbuf__bindgen_ty_4 { fn default() -> Self { @@ -915,19 +814,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tx_offload - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) - ); } impl Default for rte_mbuf__bindgen_ty_5 { fn default() -> Self { @@ -951,8 +837,14 @@ fn bindgen_test_layout_rte_mbuf() { concat!("Alignment of ", stringify!(rte_mbuf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cacheline0 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.cacheline0); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -963,8 +855,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_addr as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -975,9 +873,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_physaddr as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_physaddr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -988,8 +891,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1000,8 +909,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rearm_data as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.rearm_data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 18usize, concat!( @@ -1012,8 +927,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data_off as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.data_off); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 18usize, concat!( @@ -1024,8 +945,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_segs as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_segs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 22usize, concat!( @@ -1036,8 +963,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).port as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.port); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 23usize, concat!( @@ -1048,8 +981,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ol_flags as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.ol_flags); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -1060,9 +999,15 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rx_descriptor_fields1 - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = + std::ptr::addr_of!(struct_instance.rx_descriptor_fields1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -1073,8 +1018,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pkt_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pkt_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 36usize, concat!( @@ -1085,8 +1036,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.data_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( @@ -1097,8 +1054,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vlan_tci as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_tci); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 42usize, concat!( @@ -1109,8 +1072,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hash as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.hash); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 44usize, concat!( @@ -1121,8 +1090,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).seqn as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.seqn); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 52usize, concat!( @@ -1133,9 +1108,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vlan_tci_outer as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_tci_outer); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -1146,8 +1126,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cacheline1 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.cacheline1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -1158,8 +1144,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pool as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 72usize, concat!( @@ -1170,8 +1162,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).next as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.next); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 80usize, concat!( @@ -1182,8 +1180,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).priv_size as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.priv_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 96usize, concat!( @@ -1194,8 +1198,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).timesync as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.timesync); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 98usize, concat!( diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index ce4c66c2f0..4ee237b446 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -160,8 +160,15 @@ fn bindgen_test_layout_rte_atomic16_t() { concat!("Alignment of ", stringify!(rte_atomic16_t)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cnt as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_atomic16_t; + let field_ptr = std::ptr::addr_of!(struct_instance.cnt); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -251,32 +258,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).refcnt_atomic - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).refcnt - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) - ); } impl Clone for rte_mbuf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -473,19 +454,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).packet_type - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) - ); } impl Clone for rte_mbuf__bindgen_ty_2 { fn clone(&self) -> Self { @@ -531,8 +499,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ) { assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . hash as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . id as * const _ as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq ! ({ let struct_instance = unsafe { std :: mem :: zeroed :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () } ; let struct_ptr = & struct_instance as * const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ; let field_ptr = std :: ptr :: addr_of ! (struct_instance . hash) ; let struct_address = struct_ptr as usize ; let field_address = field_ptr as usize ; std :: mem :: forget (struct_instance) ; field_address . checked_sub (struct_address) . unwrap () } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! ({ let struct_instance = unsafe { std :: mem :: zeroed :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () } ; let struct_ptr = & struct_instance as * const rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ; let field_ptr = std :: ptr :: addr_of ! (struct_instance . id) ; let struct_address = struct_ptr as usize ; let field_address = field_ptr as usize ; std :: mem :: forget (struct_instance) ; field_address . checked_sub (struct_address) . unwrap () } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 @@ -562,21 +530,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >())) - .lo as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) - ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -602,9 +555,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_mbuf__bindgen_ty_3__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.hi); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -645,9 +606,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).lo - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_mbuf__bindgen_ty_3__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.lo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -658,9 +627,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const rte_mbuf__bindgen_ty_3__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.hi); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -688,58 +665,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rss as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).fdir as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sched as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).usr as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) - ); } impl Clone for rte_mbuf__bindgen_ty_3 { fn clone(&self) -> Self { @@ -767,32 +692,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).userdata - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).udata64 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) - ); } impl Clone for rte_mbuf__bindgen_ty_4 { fn clone(&self) -> Self { @@ -970,19 +869,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tx_offload - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) - ); } impl Clone for rte_mbuf__bindgen_ty_5 { fn clone(&self) -> Self { @@ -997,8 +883,14 @@ fn bindgen_test_layout_rte_mbuf() { concat!("Size of: ", stringify!(rte_mbuf)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cacheline0 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.cacheline0); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1009,8 +901,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_addr as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_addr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -1021,9 +919,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_physaddr as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_physaddr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -1034,8 +937,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buf_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.buf_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -1046,8 +955,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rearm_data as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.rearm_data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 18usize, concat!( @@ -1058,8 +973,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data_off as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.data_off); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 18usize, concat!( @@ -1070,8 +991,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).nb_segs as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.nb_segs); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 22usize, concat!( @@ -1082,8 +1009,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).port as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.port); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 23usize, concat!( @@ -1094,8 +1027,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ol_flags as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.ol_flags); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -1106,9 +1045,15 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).rx_descriptor_fields1 - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = + std::ptr::addr_of!(struct_instance.rx_descriptor_fields1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 32usize, concat!( @@ -1119,8 +1064,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pkt_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pkt_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 36usize, concat!( @@ -1131,8 +1082,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data_len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.data_len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( @@ -1143,8 +1100,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vlan_tci as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_tci); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 42usize, concat!( @@ -1155,8 +1118,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).hash as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.hash); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 44usize, concat!( @@ -1167,8 +1136,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).seqn as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.seqn); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 52usize, concat!( @@ -1179,9 +1154,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).vlan_tci_outer as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.vlan_tci_outer); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -1192,8 +1172,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cacheline1 as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.cacheline1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 64usize, concat!( @@ -1204,8 +1190,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).pool as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.pool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 72usize, concat!( @@ -1216,8 +1208,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).next as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.next); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 80usize, concat!( @@ -1228,8 +1226,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).priv_size as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.priv_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 96usize, concat!( @@ -1240,8 +1244,14 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).timesync as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_mbuf; + let field_ptr = std::ptr::addr_of!(struct_instance.timesync); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 98usize, concat!( diff --git a/tests/expectations/tests/libclang-9/call-conv-field.rs b/tests/expectations/tests/libclang-9/call-conv-field.rs index f134bd8a46..7d42cad81d 100644 --- a/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -29,9 +29,15 @@ fn bindgen_test_layout_JNINativeInterface_() { concat!("Alignment of ", stringify!(JNINativeInterface_)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).GetVersion - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const JNINativeInterface_; + let field_ptr = std::ptr::addr_of!(struct_instance.GetVersion); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -42,9 +48,15 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).__hack as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const JNINativeInterface_; + let field_ptr = std::ptr::addr_of!(struct_instance.__hack); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index e4527de0e2..4b2b915bd3 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -54,12 +54,28 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).big_array as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!( "Offset of field: ", @@ -97,9 +113,16 @@ fn bindgen_test_layout_C_with_zero_length_array() { concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -110,9 +133,16 @@ fn bindgen_test_layout_C_with_zero_length_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -123,9 +153,17 @@ fn bindgen_test_layout_C_with_zero_length_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -164,9 +202,16 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array_2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -177,9 +222,17 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -209,9 +262,15 @@ fn bindgen_test_layout_C_with_incomplete_array() { concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_with_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -222,9 +281,15 @@ fn bindgen_test_layout_C_with_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_with_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -235,9 +300,16 @@ fn bindgen_test_layout_C_with_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).incomplete_array - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_with_incomplete_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -276,9 +348,16 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_incomplete_array_2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -289,9 +368,17 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_incomplete_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -328,11 +415,18 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .a as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -343,11 +437,18 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .big_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -358,11 +459,19 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .zero_length_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -373,11 +482,19 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .incomplete_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -425,11 +542,19 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array_2, - >())) - .a as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::< + C_with_zero_length_array_and_incomplete_array_2, + >() + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array_2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -440,11 +565,20 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array_2, - >())) - .zero_length_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::< + C_with_zero_length_array_and_incomplete_array_2, + >() + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -455,11 +589,20 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array_2, - >())) - .incomplete_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::< + C_with_zero_length_array_and_incomplete_array_2, + >() + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -488,7 +631,15 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithDtor; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -516,9 +667,16 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).whatever - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const IncompleteArrayNonCopiable; + let field_ptr = std::ptr::addr_of!(struct_instance.whatever); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -529,9 +687,17 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const IncompleteArrayNonCopiable; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -569,16 +735,6 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) - ); } impl Default for Union { fn default() -> Self { @@ -607,8 +763,14 @@ fn bindgen_test_layout_WithUnion() { concat!("Alignment of ", stringify!(WithUnion)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithUnion; + let field_ptr = std::ptr::addr_of!(struct_instance.data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs index 4263bd144c..ae31f2329e 100644 --- a/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -97,12 +97,28 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).big_array as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!( "Offset of field: ", @@ -150,9 +166,16 @@ fn bindgen_test_layout_C_with_zero_length_array() { concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -163,9 +186,16 @@ fn bindgen_test_layout_C_with_zero_length_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -176,9 +206,17 @@ fn bindgen_test_layout_C_with_zero_length_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -217,9 +255,16 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array_2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -230,9 +275,17 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_zero_length_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -262,9 +315,15 @@ fn bindgen_test_layout_C_with_incomplete_array() { concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_with_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -275,9 +334,15 @@ fn bindgen_test_layout_C_with_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_with_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -288,9 +353,16 @@ fn bindgen_test_layout_C_with_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).incomplete_array - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C_with_incomplete_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -329,9 +401,16 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_incomplete_array_2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -342,9 +421,17 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const C_with_incomplete_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -381,11 +468,18 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .a as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -396,11 +490,18 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .big_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = std::ptr::addr_of!(struct_instance.big_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -411,11 +512,19 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .zero_length_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -426,11 +535,19 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array, - >())) - .incomplete_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::( + ) + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 37usize, concat!( @@ -478,11 +595,19 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array_2, - >())) - .a as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::< + C_with_zero_length_array_and_incomplete_array_2, + >() + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array_2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -493,11 +618,20 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array_2, - >())) - .zero_length_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::< + C_with_zero_length_array_and_incomplete_array_2, + >() + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -508,11 +642,20 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - C_with_zero_length_array_and_incomplete_array_2, - >())) - .incomplete_array as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::< + C_with_zero_length_array_and_incomplete_array_2, + >() + }; + let struct_ptr = &struct_instance + as *const C_with_zero_length_array_and_incomplete_array_2; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -541,7 +684,15 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithDtor; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -569,9 +720,16 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).whatever - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const IncompleteArrayNonCopiable; + let field_ptr = std::ptr::addr_of!(struct_instance.whatever); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -582,9 +740,17 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const IncompleteArrayNonCopiable; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -623,16 +789,6 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) - ); } impl Clone for Union { fn clone(&self) -> Self { @@ -657,8 +813,14 @@ fn bindgen_test_layout_WithUnion() { concat!("Alignment of ", stringify!(WithUnion)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithUnion; + let field_ptr = std::ptr::addr_of!(struct_instance.data); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 32607b375f..8a11bcd9d0 100644 --- a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -54,14 +54,28 @@ fn bindgen_test_layout_test() { concat!("Alignment of ", stringify!(test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const test; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).zero_length_array as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const test; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -91,14 +105,28 @@ fn bindgen_test_layout_test2() { concat!("Alignment of ", stringify!(test2)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const test2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).incomplete_array as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const test2; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -129,14 +157,28 @@ fn bindgen_test_layout_test3() { concat!("Alignment of ", stringify!(test3)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const test3; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).zero_length_array as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const test3; + let field_ptr = + std::ptr::addr_of!(struct_instance.zero_length_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -147,9 +189,15 @@ fn bindgen_test_layout_test3() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).incomplete_array as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const test3; + let field_ptr = + std::ptr::addr_of!(struct_instance.incomplete_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 382195dbb9..3848333c57 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -141,7 +141,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 49664cdd5e..098ff158cc 100644 --- a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -61,9 +61,15 @@ fn bindgen_test_layout_rte_ring_prod() { concat!("Alignment of ", stringify!(rte_ring_prod)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).watermark as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ring_prod; + let field_ptr = std::ptr::addr_of!(struct_instance.watermark); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -92,9 +98,15 @@ fn bindgen_test_layout_rte_ring_cons() { concat!("Alignment of ", stringify!(rte_ring_cons)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sc_dequeue as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ring_cons; + let field_ptr = std::ptr::addr_of!(struct_instance.sc_dequeue); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -118,8 +130,14 @@ fn bindgen_test_layout_rte_ring() { concat!("Alignment of ", stringify!(rte_ring)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).memzone as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ring; + let field_ptr = std::ptr::addr_of!(struct_instance.memzone); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -130,8 +148,14 @@ fn bindgen_test_layout_rte_ring() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).prod as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ring; + let field_ptr = std::ptr::addr_of!(struct_instance.prod); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -142,8 +166,14 @@ fn bindgen_test_layout_rte_ring() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cons as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ring; + let field_ptr = std::ptr::addr_of!(struct_instance.cons); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -154,8 +184,14 @@ fn bindgen_test_layout_rte_ring() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).ring as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_ring; + let field_ptr = std::ptr::addr_of!(struct_instance.ring); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index 4ad5417577..899112ceac 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -148,8 +148,14 @@ fn bindgen_test_layout_rte_kni_fifo() { concat!("Alignment of ", stringify!(rte_kni_fifo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).write as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_fifo; + let field_ptr = std::ptr::addr_of!(struct_instance.write); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -160,8 +166,14 @@ fn bindgen_test_layout_rte_kni_fifo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).read as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_fifo; + let field_ptr = std::ptr::addr_of!(struct_instance.read); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -172,8 +184,14 @@ fn bindgen_test_layout_rte_kni_fifo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).len as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_fifo; + let field_ptr = std::ptr::addr_of!(struct_instance.len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -184,9 +202,14 @@ fn bindgen_test_layout_rte_kni_fifo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).elem_size as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_fifo; + let field_ptr = std::ptr::addr_of!(struct_instance.elem_size); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -197,8 +220,14 @@ fn bindgen_test_layout_rte_kni_fifo() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).buffer as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_kni_fifo; + let field_ptr = std::ptr::addr_of!(struct_instance.buffer); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -241,9 +270,14 @@ fn bindgen_test_layout_rte_eth_link() { concat!("Alignment of ", stringify!(rte_eth_link)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).link_speed as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const rte_eth_link; + let field_ptr = std::ptr::addr_of!(struct_instance.link_speed); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index f874e9d221..2d7d40e29e 100644 --- a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Rooted() { concat!("Alignment of ", stringify!(Rooted)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Rooted; + let field_ptr = std::ptr::addr_of!(struct_instance.ptr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/tests/expectations/tests/libclang-9/zero-sized-array.rs index 6514b930c7..10c0afac21 100644 --- a/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -54,8 +54,15 @@ fn bindgen_test_layout_ZeroSizedArray() { concat!("Alignment of ", stringify!(ZeroSizedArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arr as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ZeroSizedArray; + let field_ptr = std::ptr::addr_of!(struct_instance.arr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -85,9 +92,15 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).zsa as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContainsZeroSizedArray; + let field_ptr = std::ptr::addr_of!(struct_instance.zsa); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -137,9 +150,15 @@ fn bindgen_test_layout_DynamicallySizedArray() { concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).arr as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const DynamicallySizedArray; + let field_ptr = std::ptr::addr_of!(struct_instance.arr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -169,9 +188,16 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).dsa - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ContainsDynamicallySizedArray; + let field_ptr = std::ptr::addr_of!(struct_instance.dsa); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/long_double.rs b/tests/expectations/tests/long_double.rs index dbd4248ee5..0834ff95fe 100644 --- a/tests/expectations/tests/long_double.rs +++ b/tests/expectations/tests/long_double.rs @@ -24,7 +24,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index ea5a90b871..ec5bab031f 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -24,7 +24,15 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) ); diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index 9f5865fccc..28f861c435 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -24,7 +24,15 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m_member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.m_member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -34,7 +42,15 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m_other as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.m_other); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!( "Offset of field: ", @@ -62,9 +78,14 @@ fn bindgen_test_layout_NonCopiable() { concat!("Alignment of ", stringify!(NonCopiable)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).m_member as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NonCopiable; + let field_ptr = std::ptr::addr_of!(struct_instance.m_member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -99,9 +120,17 @@ fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .m_member as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const NonCopiableWithNonCopiableMutableMember; + let field_ptr = std::ptr::addr_of!(struct_instance.m_member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 576fc9336f..abe4fb4895 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -44,7 +44,15 @@ pub mod root { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index 92cd6605b4..9a1ede6ac0 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Calc() { concat!("Alignment of ", stringify!(Calc)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).w as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Calc; + let field_ptr = std::ptr::addr_of!(struct_instance.w); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) ); @@ -70,8 +78,14 @@ fn bindgen_test_layout_Test_Size() { concat!("Alignment of ", stringify!(Test_Size)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mWidth as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test_Size; + let field_ptr = std::ptr::addr_of!(struct_instance.mWidth); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -82,8 +96,14 @@ fn bindgen_test_layout_Test_Size() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mHeight as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test_Size; + let field_ptr = std::ptr::addr_of!(struct_instance.mHeight); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index 86b9b8c68b..158f4b7ac3 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -35,8 +35,15 @@ pub mod root { concat!("Alignment of ", stringify!(Bar_Baz)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar_Baz; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -60,8 +67,14 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -90,8 +103,14 @@ pub mod root { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).baz as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Baz; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index 7a9d0d82b5..e7d56203d6 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).s as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.s); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) ); diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index a62eaa5df5..6460178ce8 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -32,12 +32,28 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index eda13aad68..5656d0bf6d 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -32,12 +32,28 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bar; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-hash-allowlisted.rs b/tests/expectations/tests/no-hash-allowlisted.rs index 1cd7f672b6..4f07c38cc5 100644 --- a/tests/expectations/tests/no-hash-allowlisted.rs +++ b/tests/expectations/tests/no-hash-allowlisted.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_NoHash() { concat!("Alignment of ", stringify!(NoHash)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NoHash; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/no-partialeq-allowlisted.rs b/tests/expectations/tests/no-partialeq-allowlisted.rs index cd3ed3b935..e10f4f248a 100644 --- a/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -23,8 +23,14 @@ fn bindgen_test_layout_NoPartialEq() { concat!("Alignment of ", stringify!(NoPartialEq)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NoPartialEq; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/no-recursive-allowlisting.rs b/tests/expectations/tests/no-recursive-allowlisting.rs index 0aa0b5e322..3d02d0509b 100644 --- a/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/tests/expectations/tests/no-recursive-allowlisting.rs @@ -25,7 +25,15 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index f63ac4512b..9de5d52337 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -30,17 +30,41 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/no_copy_allowlisted.rs b/tests/expectations/tests/no_copy_allowlisted.rs index fa53bb66fe..bec0066185 100644 --- a/tests/expectations/tests/no_copy_allowlisted.rs +++ b/tests/expectations/tests/no_copy_allowlisted.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_NoCopy() { concat!("Alignment of ", stringify!(NoCopy)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NoCopy; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/no_debug_allowlisted.rs b/tests/expectations/tests/no_debug_allowlisted.rs index e240d645fb..f5f8cf5aae 100644 --- a/tests/expectations/tests/no_debug_allowlisted.rs +++ b/tests/expectations/tests/no_debug_allowlisted.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_NoDebug() { concat!("Alignment of ", stringify!(NoDebug)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NoDebug; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/no_default_allowlisted.rs b/tests/expectations/tests/no_default_allowlisted.rs index 980f1575f0..1b726b3f70 100644 --- a/tests/expectations/tests/no_default_allowlisted.rs +++ b/tests/expectations/tests/no_default_allowlisted.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_NoDefault() { concat!("Alignment of ", stringify!(NoDefault)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const NoDefault; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index acd7a09f3a..9443cd1fd7 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -27,9 +27,14 @@ fn bindgen_test_layout_UsesArray() { concat!("Alignment of ", stringify!(UsesArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).array_char_16 as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const UsesArray; + let field_ptr = std::ptr::addr_of!(struct_instance.array_char_16); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -40,9 +45,14 @@ fn bindgen_test_layout_UsesArray() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).array_bool_8 as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const UsesArray; + let field_ptr = std::ptr::addr_of!(struct_instance.array_bool_8); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -53,9 +63,14 @@ fn bindgen_test_layout_UsesArray() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).array_int_4 as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const UsesArray; + let field_ptr = std::ptr::addr_of!(struct_instance.array_int_4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index cef29c8c96..4552e3ac56 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -45,8 +45,14 @@ fn bindgen_test_layout_FooStruct() { concat!("Alignment of ", stringify!(FooStruct)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const FooStruct; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index f47aff0552..c54d11c2f2 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -32,9 +32,15 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBlah as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContainsOpaqueTemplate; + let field_ptr = std::ptr::addr_of!(struct_instance.mBlah); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -45,9 +51,15 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBaz as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContainsOpaqueTemplate; + let field_ptr = std::ptr::addr_of!(struct_instance.mBaz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -78,9 +90,15 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).wow as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const InheritsOpaqueTemplate; + let field_ptr = std::ptr::addr_of!(struct_instance.wow); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index a3c67784de..e7c98a9a11 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -30,9 +30,15 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBlah as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContainsOpaqueTemplate; + let field_ptr = std::ptr::addr_of!(struct_instance.mBlah); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -43,9 +49,15 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBaz as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContainsOpaqueTemplate; + let field_ptr = std::ptr::addr_of!(struct_instance.mBaz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 404usize, concat!( @@ -90,9 +102,15 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).wow as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const InheritsOpaqueTemplate; + let field_ptr = std::ptr::addr_of!(struct_instance.wow); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 408usize, concat!( diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index e972443ed3..50d27d00ef 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -46,8 +46,14 @@ pub mod root { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Foo; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -76,8 +82,14 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.i); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -106,9 +118,17 @@ pub mod root { concat!("Alignment of ", stringify!(ContainsInstantiation)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).not_opaque - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ContainsInstantiation; + let field_ptr = + std::ptr::addr_of!(struct_instance.not_opaque); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -149,9 +169,17 @@ pub mod root { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .opaque as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const ContainsOpaqueInstantiation; + let field_ptr = std::ptr::addr_of!(struct_instance.opaque); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 6f0f31b376..72ca95ac36 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -38,9 +38,15 @@ fn bindgen_test_layout_ContainsInstantiation() { concat!("Alignment of ", stringify!(ContainsInstantiation)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).not_opaque - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContainsInstantiation; + let field_ptr = std::ptr::addr_of!(struct_instance.not_opaque); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -78,9 +84,16 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() { concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).opaque - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const ContainsOpaqueInstantiation; + let field_ptr = std::ptr::addr_of!(struct_instance.opaque); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 980df3d612..eec1c45173 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -43,8 +43,14 @@ fn bindgen_test_layout_container() { concat!("Alignment of ", stringify!(container)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).contained as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const container; + let field_ptr = std::ptr::addr_of!(struct_instance.contained); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 90b019b290..b5c49275dc 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -51,9 +51,15 @@ fn bindgen_test_layout_WithOpaquePtr() { concat!("Alignment of ", stringify!(WithOpaquePtr)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).whatever as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithOpaquePtr; + let field_ptr = std::ptr::addr_of!(struct_instance.whatever); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -64,8 +70,15 @@ fn bindgen_test_layout_WithOpaquePtr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).other as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithOpaquePtr; + let field_ptr = std::ptr::addr_of!(struct_instance.other); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -76,8 +89,15 @@ fn bindgen_test_layout_WithOpaquePtr() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).t as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithOpaquePtr; + let field_ptr = std::ptr::addr_of!(struct_instance.t); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( diff --git a/tests/expectations/tests/packed-n-with-padding.rs b/tests/expectations/tests/packed-n-with-padding.rs index 13cb030620..1aa49e881e 100644 --- a/tests/expectations/tests/packed-n-with-padding.rs +++ b/tests/expectations/tests/packed-n-with-padding.rs @@ -26,22 +26,54 @@ fn bindgen_test_layout_Packed() { concat!("Alignment of ", stringify!(Packed)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Packed; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Packed; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 2usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Packed; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Packed; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 6usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 328f97f08f..0586ae7faa 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -25,9 +25,14 @@ fn bindgen_test_layout_HasPrivate() { concat!("Alignment of ", stringify!(HasPrivate)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mNotPrivate as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const HasPrivate; + let field_ptr = std::ptr::addr_of!(struct_instance.mNotPrivate); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -38,9 +43,14 @@ fn bindgen_test_layout_HasPrivate() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mIsPrivate as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const HasPrivate; + let field_ptr = std::ptr::addr_of!(struct_instance.mIsPrivate); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -71,9 +81,14 @@ fn bindgen_test_layout_VeryPrivate() { concat!("Alignment of ", stringify!(VeryPrivate)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mIsPrivate as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const VeryPrivate; + let field_ptr = std::ptr::addr_of!(struct_instance.mIsPrivate); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -84,9 +99,14 @@ fn bindgen_test_layout_VeryPrivate() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mIsAlsoPrivate as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const VeryPrivate; + let field_ptr = std::ptr::addr_of!(struct_instance.mIsAlsoPrivate); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -118,9 +138,15 @@ fn bindgen_test_layout_ContradictPrivate() { concat!("Alignment of ", stringify!(ContradictPrivate)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mNotPrivate - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContradictPrivate; + let field_ptr = std::ptr::addr_of!(struct_instance.mNotPrivate); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -131,9 +157,15 @@ fn bindgen_test_layout_ContradictPrivate() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mIsPrivate as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ContradictPrivate; + let field_ptr = std::ptr::addr_of!(struct_instance.mIsPrivate); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs index 92a4bf653b..8e674b4997 100644 --- a/tests/expectations/tests/private_fields.rs +++ b/tests/expectations/tests/private_fields.rs @@ -110,7 +110,15 @@ fn bindgen_test_layout_PubPriv() { concat!("Alignment of ", stringify!(PubPriv)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PubPriv; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -120,7 +128,15 @@ fn bindgen_test_layout_PubPriv() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PubPriv; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!( "Offset of field: ", @@ -346,7 +362,15 @@ fn bindgen_test_layout_Base() { concat!("Alignment of ", stringify!(Base)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Base; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -416,9 +440,16 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const WithAnonStruct__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -447,9 +478,16 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = + &struct_instance as *const WithAnonStruct__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index 1f4fa6e1b8..cbfafab07f 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -31,8 +31,14 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).bazz as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.bazz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index 7bec94b8d2..ad320ad1ee 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -29,7 +29,15 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/repr-align.rs b/tests/expectations/tests/repr-align.rs index df2353686a..bf3fc8ced2 100644 --- a/tests/expectations/tests/repr-align.rs +++ b/tests/expectations/tests/repr-align.rs @@ -26,12 +26,28 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); @@ -56,12 +72,28 @@ fn bindgen_test_layout_b() { concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const b; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const b; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) ); diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 056b671b33..1d6393d4c1 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -29,8 +29,15 @@ fn bindgen_test_layout_JS_shadow_Zone() { concat!("Alignment of ", stringify!(JS_shadow_Zone)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const JS_shadow_Zone; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -41,8 +48,15 @@ fn bindgen_test_layout_JS_shadow_Zone() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const JS_shadow_Zone; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index 5f2ec54d5a..6b5b15f8cb 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -40,9 +40,16 @@ pub mod root { concat!("Alignment of ", stringify!(sentry)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i_am_plain_sentry - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const sentry; + let field_ptr = + std::ptr::addr_of!(struct_instance.i_am_plain_sentry); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -89,10 +96,19 @@ pub mod root { concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .i_am_not_template_wrapper_sentry - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const NotTemplateWrapper_sentry; + let field_ptr = std::ptr::addr_of!( + struct_instance.i_am_not_template_wrapper_sentry + ); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -132,10 +148,19 @@ pub mod root { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())) - .i_am_inline_not_template_wrapper_sentry - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = &struct_instance + as *const InlineNotTemplateWrapper_sentry; + let field_ptr = std::ptr::addr_of!( + struct_instance.i_am_inline_not_template_wrapper_sentry + ); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -239,12 +264,21 @@ pub mod root { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >())) - .i_am_double_wrapper_sentry as *const _ - as usize + { + let struct_instance = unsafe { + std::mem::zeroed::< + OuterDoubleWrapper_InnerDoubleWrapper_sentry, + >() + }; + let struct_ptr = &struct_instance + as *const OuterDoubleWrapper_InnerDoubleWrapper_sentry; + let field_ptr = std::ptr::addr_of!( + struct_instance.i_am_double_wrapper_sentry + ); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -275,7 +309,7 @@ pub mod root { ) { assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > ())) . i_am_double_wrapper_inline_sentry as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); + assert_eq ! ({ let struct_instance = unsafe { std :: mem :: zeroed :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () } ; let struct_ptr = & struct_instance as * const OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry ; let field_ptr = std :: ptr :: addr_of ! (struct_instance . i_am_double_wrapper_inline_sentry) ; let struct_address = struct_ptr as usize ; let field_address = field_ptr as usize ; std :: mem :: forget (struct_instance) ; field_address . checked_sub (struct_address) . unwrap () } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( @@ -347,9 +381,16 @@ pub mod root { concat!("Alignment of ", stringify!(sentry)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).i_am_outside_namespace_sentry - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const sentry; + let field_ptr = std::ptr::addr_of!( + struct_instance.i_am_outside_namespace_sentry + ); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/size_t_is_usize.rs index 0d9ab2caba..39e76a7279 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/size_t_is_usize.rs @@ -25,17 +25,41 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.len); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).offset as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.offset); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).next as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.next); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) ); diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 6796bc9f3a..c591433148 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).arr as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.arr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 7298095e21..3cd285a801 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).val_a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.val_a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) ); @@ -55,7 +63,15 @@ fn bindgen_test_layout_b() { concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).val_b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const b; + let field_ptr = std::ptr::addr_of!(struct_instance.val_b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) ); diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index 34c9dbd21e..e9f049bb92 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -23,9 +23,15 @@ fn bindgen_test_layout_typedef_named_struct() { concat!("Alignment of ", stringify!(typedef_named_struct)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).has_name - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const typedef_named_struct; + let field_ptr = std::ptr::addr_of!(struct_instance.has_name); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -54,9 +60,15 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).no_name as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::<_bindgen_ty_1>() }; + let struct_ptr = &struct_instance as *const _bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.no_name); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index ef91fe49a9..7aaaa412d6 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -30,9 +30,15 @@ pub mod root { concat!("Alignment of ", stringify!(typedef_struct)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).foo as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const typedef_struct; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -70,9 +76,15 @@ pub mod root { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).foo as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::<_bindgen_ty_1>() }; + let struct_ptr = &struct_instance as *const _bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 0f5d3dac91..8e92421c93 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -29,8 +29,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -41,8 +48,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -66,7 +80,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index d5a5044832..81361454c7 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -30,8 +30,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -42,8 +49,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -73,8 +87,15 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -85,8 +106,15 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -110,12 +138,28 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 16usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 0ed19f7634..b50afa8af0 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -29,8 +29,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -41,8 +48,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -66,7 +80,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 15b8c9e449..99b5aba9f2 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -28,30 +28,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -75,7 +51,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/tests/expectations/tests/struct_with_anon_union_1_0.rs index b02c44482a..8321ecafa6 100644 --- a/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -72,30 +72,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -115,7 +91,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 30751e7d83..806511a815 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -29,8 +29,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -41,8 +48,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 17a83574e7..5152951da5 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -28,30 +28,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index f72abd2b03..c4ab43de95 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -72,30 +72,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 2e95726f4c..cfa9069840 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -113,7 +113,15 @@ fn bindgen_test_layout_bitfield() { concat!("Alignment of ", stringify!(bitfield)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).e as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const bitfield; + let field_ptr = std::ptr::addr_of!(struct_instance.e); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 721ba96caf..ed77c782b8 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -23,8 +23,14 @@ fn bindgen_test_layout_LittleArray() { concat!("Alignment of ", stringify!(LittleArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const LittleArray; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -53,7 +59,15 @@ fn bindgen_test_layout_BigArray() { concat!("Alignment of ", stringify!(BigArray)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const BigArray; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -90,8 +104,15 @@ fn bindgen_test_layout_WithLittleArray() { concat!("Alignment of ", stringify!(WithLittleArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithLittleArray; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -120,8 +141,14 @@ fn bindgen_test_layout_WithBigArray() { concat!("Alignment of ", stringify!(WithBigArray)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const WithBigArray; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index 56179c20f8..7d544cff24 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -23,8 +23,14 @@ fn bindgen_test_layout_S() { concat!("Alignment of ", stringify!(S)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const S; + let field_ptr = std::ptr::addr_of!(struct_instance.large_array); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 7ced63e6ce..97a495bd1c 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -37,9 +37,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.c1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -50,9 +58,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.c2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -84,9 +100,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d1 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -97,9 +121,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d2 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1usize, concat!( @@ -110,9 +142,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d3 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -123,9 +163,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d4 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 3usize, concat!( @@ -148,18 +196,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -183,7 +219,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/tests/expectations/tests/struct_with_nesting_1_0.rs index 9f27161a0c..772036326f 100644 --- a/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -81,9 +81,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.c1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -94,9 +102,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.c2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -133,9 +149,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d1 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -146,9 +170,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d2 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1usize, concat!( @@ -159,9 +191,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d3 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d3); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -172,9 +212,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).d4 - as *const _ as usize + { + let struct_instance = unsafe { + std::mem::zeroed::() + }; + let struct_ptr = + &struct_instance as *const foo__bindgen_ty_1__bindgen_ty_2; + let field_ptr = std::ptr::addr_of!(struct_instance.d4); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 3usize, concat!( @@ -202,18 +250,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -233,7 +269,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index 14ee36fbaa..e8c2cbc94d 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -24,12 +24,28 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const a; + let field_ptr = std::ptr::addr_of!(struct_instance.c); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 1usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index c605c6e2e3..37e7b37cec 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -29,8 +29,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -41,8 +48,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.y); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -66,7 +80,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 9c48488693..8672db6284 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -78,13 +78,27 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mB as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mB); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBConstPtr as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBConstPtr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -95,8 +109,15 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBConstStructPtr as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = + std::ptr::addr_of!(struct_instance.mBConstStructPtr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -107,9 +128,15 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBConstStructPtrArray as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = + std::ptr::addr_of!(struct_instance.mBConstStructPtrArray); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 24usize, concat!( @@ -120,7 +147,15 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBConst as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBConst); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 32usize, concat!( "Offset of field: ", @@ -130,8 +165,14 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBVolatile as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBVolatile); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 36usize, concat!( @@ -142,8 +183,14 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBConstBool as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBConstBool); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 40usize, concat!( @@ -154,8 +201,14 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBConstChar as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBConstChar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 42usize, concat!( @@ -166,7 +219,15 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBArray as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBArray); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 44usize, concat!( "Offset of field: ", @@ -176,8 +237,14 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBPtrArray as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBPtrArray); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 48usize, concat!( @@ -188,8 +255,14 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBArrayPtr as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBArrayPtr); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 56usize, concat!( @@ -200,13 +273,27 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBRef as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBRef); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 64usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBConstRef as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mBConstRef); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 72usize, concat!( @@ -217,7 +304,15 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mPtrRef as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mPtrRef); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 80usize, concat!( "Offset of field: ", @@ -227,7 +322,15 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mArrayRef as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.mArrayRef); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 88usize, concat!( "Offset of field: ", @@ -312,9 +415,15 @@ fn bindgen_test_layout_RootedContainer() { concat!("Alignment of ", stringify!(RootedContainer)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).root as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const RootedContainer; + let field_ptr = std::ptr::addr_of!(struct_instance.root); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -368,9 +477,15 @@ fn bindgen_test_layout_PODButContainsDtor() { concat!("Alignment of ", stringify!(PODButContainsDtor)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).member as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const PODButContainsDtor; + let field_ptr = std::ptr::addr_of!(struct_instance.member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -414,8 +529,14 @@ fn bindgen_test_layout_POD() { concat!("Alignment of ", stringify!(POD)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).opaque_member as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const POD; + let field_ptr = std::ptr::addr_of!(struct_instance.opaque_member); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/tests/expectations/tests/test_mixed_header_and_header_contents.rs index c97be9b006..c230453258 100644 --- a/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -44,52 +44,142 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.ch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cu as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cd as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cu as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cd as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 9usize, concat!( "Offset of field: ", @@ -99,12 +189,30 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccu as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccd as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index c77c18342a..2ac3c4ffbe 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -38,52 +38,142 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.ch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.u); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.d); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cu as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cd as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.cd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cu as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cd as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Cd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccch as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccch); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 9usize, concat!( "Offset of field: ", @@ -93,12 +183,30 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccu as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccu); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccd as *const _ as usize }, + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Test; + let field_ptr = std::ptr::addr_of!(struct_instance.Ccd); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index 72ada37ad3..39df82da22 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -111,7 +111,15 @@ fn bindgen_test_layout_timex() { concat!("Alignment of ", stringify!(timex)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).tai as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const timex; + let field_ptr = std::ptr::addr_of!(struct_instance.tai); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", @@ -150,8 +158,14 @@ fn bindgen_test_layout_timex_named() { concat!("Alignment of ", stringify!(timex_named)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).tai as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const timex_named; + let field_ptr = std::ptr::addr_of!(struct_instance.tai); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 568f94336b..ce0d98378d 100644 --- a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -23,8 +23,14 @@ fn bindgen_test_layout_dl_phdr_info() { concat!("Alignment of ", stringify!(dl_phdr_info)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const dl_phdr_info; + let field_ptr = std::ptr::addr_of!(struct_instance.x); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 1c34be7e9b..cd9133508f 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -23,9 +23,15 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mIsLocalRef - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const mozilla_FragmentOrURL; + let field_ptr = std::ptr::addr_of!(struct_instance.mIsLocalRef); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -99,7 +105,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mFoo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.mFoo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); @@ -130,7 +144,15 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const nsFoo; + let field_ptr = std::ptr::addr_of!(struct_instance.mBar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index 2820d9f96c..a7e7cf21fc 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -66,9 +66,15 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mIsLocalRef - as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const mozilla_FragmentOrURL; + let field_ptr = std::ptr::addr_of!(struct_instance.mIsLocalRef); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -137,7 +143,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mFoo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.mFoo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); @@ -174,7 +188,15 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const nsFoo; + let field_ptr = std::ptr::addr_of!(struct_instance.mBar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index 6ef2d8a124..f79c8bbbb7 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -24,7 +24,15 @@ fn bindgen_test_layout_ptr_t() { concat!("Alignment of ", stringify!(ptr_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).__ as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const ptr_t; + let field_ptr = std::ptr::addr_of!(struct_instance.__); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) ); diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index 8612764186..c28a685c4c 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -23,11 +23,6 @@ fn bindgen_test_layout_Bar() { 16usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) - ); } impl Default for Bar { fn default() -> Self { @@ -56,11 +51,6 @@ fn bindgen_test_layout_Baz() { 16usize, concat!("Alignment of ", stringify!(Baz)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) - ); } impl Default for Baz { fn default() -> Self { diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index b52c6c3600..d5fae0c98d 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -26,16 +26,6 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/tests/expectations/tests/union-in-ns_1_0.rs index c210c38c74..5c7e60b852 100644 --- a/tests/expectations/tests/union-in-ns_1_0.rs +++ b/tests/expectations/tests/union-in-ns_1_0.rs @@ -73,16 +73,6 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); } impl Clone for bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 94ad3fd873..6fe939f2a9 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -22,30 +22,6 @@ fn bindgen_test_layout_UnionWithDtor() { 8usize, concat!("Alignment of ", stringify!(UnionWithDtor)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mFoo as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBar as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) - ); } extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/tests/expectations/tests/union_dtor_1_0.rs index a59f99fc6c..6e16a4ecbb 100644 --- a/tests/expectations/tests/union_dtor_1_0.rs +++ b/tests/expectations/tests/union_dtor_1_0.rs @@ -67,30 +67,6 @@ fn bindgen_test_layout_UnionWithDtor() { 8usize, concat!("Alignment of ", stringify!(UnionWithDtor)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mFoo as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mBar as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) - ); } extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 6cd0d56cdb..b2b1be6d93 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -24,43 +24,6 @@ fn bindgen_test_layout_nsStyleUnion() { 8usize, concat!("Alignment of ", stringify!(nsStyleUnion)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mInt as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mFloat as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mPointer as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) - ); } impl Default for nsStyleUnion { fn default() -> Self { diff --git a/tests/expectations/tests/union_fields_1_0.rs b/tests/expectations/tests/union_fields_1_0.rs index 36972b6b8f..d2399369a5 100644 --- a/tests/expectations/tests/union_fields_1_0.rs +++ b/tests/expectations/tests/union_fields_1_0.rs @@ -68,43 +68,6 @@ fn bindgen_test_layout_nsStyleUnion() { 8usize, concat!("Alignment of ", stringify!(nsStyleUnion)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mInt as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mFloat as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mPointer as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) - ); } impl Clone for nsStyleUnion { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index afb735043d..b34c53a5ed 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -29,8 +29,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -41,8 +48,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -65,11 +79,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/tests/expectations/tests/union_with_anon_struct_1_0.rs index 09dcfa1b08..f69761e7d6 100644 --- a/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -73,8 +73,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -85,8 +92,15 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -114,11 +128,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 09ed515f99..9036d89ef8 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -174,11 +174,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 43736b0311..6dec77a126 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -223,11 +223,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index a24962c4a6..5c9507f4c3 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -28,30 +28,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -74,11 +50,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/tests/expectations/tests/union_with_anon_union_1_0.rs index f892c45f8b..55e2cceb7f 100644 --- a/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -73,30 +73,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -115,11 +91,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 94380d1a54..b0c5773c49 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -32,9 +32,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).r as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.r); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -45,9 +51,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).g as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.g); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1usize, concat!( @@ -58,9 +70,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -71,9 +89,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 3usize, concat!( @@ -96,16 +120,6 @@ fn bindgen_test_layout_pixel() { 4usize, concat!("Alignment of ", stringify!(pixel)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).rgba as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) - ); } impl Default for pixel { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index cbdac700fb..5f97be72c2 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -76,9 +76,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).r as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.r); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -89,9 +95,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).g as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.g); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 1usize, concat!( @@ -102,9 +114,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 2usize, concat!( @@ -115,9 +133,15 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + { + let struct_instance = + unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const pixel__bindgen_ty_1; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 3usize, concat!( @@ -145,16 +169,6 @@ fn bindgen_test_layout_pixel() { 4usize, concat!("Alignment of ", stringify!(pixel)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).rgba as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) - ); } impl Clone for pixel { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 2004ff4cef..ee651435a6 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -29,30 +29,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) - ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -75,11 +51,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 910f5885c0..0ea64ff663 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -74,30 +74,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) - ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -116,11 +92,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 3f9294dd05..5aac1cebe0 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -23,30 +23,6 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) - ); } impl Default for WithBigArray { fn default() -> Self { @@ -75,30 +51,6 @@ fn bindgen_test_layout_WithBigArray2() { 4usize, concat!("Alignment of ", stringify!(WithBigArray2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) - ); } impl Default for WithBigArray2 { fn default() -> Self { @@ -127,30 +79,6 @@ fn bindgen_test_layout_WithBigMember() { 4usize, concat!("Alignment of ", stringify!(WithBigMember)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) - ); } impl Default for WithBigMember { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs index 541c9d4c77..c9da6a6e97 100644 --- a/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/tests/expectations/tests/union_with_big_member_1_0.rs @@ -67,30 +67,6 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) - ); } impl Clone for WithBigArray { fn clone(&self) -> Self { @@ -125,30 +101,6 @@ fn bindgen_test_layout_WithBigArray2() { 4usize, concat!("Alignment of ", stringify!(WithBigArray2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) - ); } impl Clone for WithBigArray2 { fn clone(&self) -> Self { @@ -174,30 +126,6 @@ fn bindgen_test_layout_WithBigMember() { 4usize, concat!("Alignment of ", stringify!(WithBigMember)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) - ); } impl Clone for WithBigMember { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 54a3179b41..bb5038a9d2 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -35,32 +35,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b1 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b2 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) - ); } impl Default for foo__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { @@ -89,32 +63,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) - ); } impl Default for foo__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { @@ -159,11 +107,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/tests/expectations/tests/union_with_nesting_1_0.rs index 3f105c39e8..86ad0a2217 100644 --- a/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/tests/expectations/tests/union_with_nesting_1_0.rs @@ -80,32 +80,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b1 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).b2 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) - ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -131,32 +105,6 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) - ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { @@ -193,11 +141,6 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index 8dbda00d71..108094d9d3 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -26,9 +26,15 @@ fn bindgen_test_layout_max_align_t() { concat!("Alignment of ", stringify!(max_align_t)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).__clang_max_align_nonce1 - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const max_align_t; + let field_ptr = + std::ptr::addr_of!(struct_instance.__clang_max_align_nonce1); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -39,9 +45,15 @@ fn bindgen_test_layout_max_align_t() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).__clang_max_align_nonce2 - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const max_align_t; + let field_ptr = + std::ptr::addr_of!(struct_instance.__clang_max_align_nonce2); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index d919b6e745..006a98b5a5 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -27,17 +27,41 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); @@ -69,30 +93,6 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).bar as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) - ); - assert_eq!( - unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).baz as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) - ); } impl Default for _bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index 61ddfc42cb..c0cb1630c8 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -70,17 +70,41 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.a); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.b); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); @@ -118,30 +142,6 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).bar as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) - ); - assert_eq!( - unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).baz as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) - ); } impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index 2931f9121c..63962c4daa 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m_baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Bar; + let field_ptr = std::ptr::addr_of!(struct_instance.m_baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 04f4de714b..246313b1b1 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mMember as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const foo; + let field_ptr = std::ptr::addr_of!(struct_instance.mMember); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index eac6aa665e..e3db231816 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -23,7 +23,15 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const A; + let field_ptr = std::ptr::addr_of!(struct_instance.foo); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) ); @@ -49,7 +57,15 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const B; + let field_ptr = std::ptr::addr_of!(struct_instance.bar); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) ); @@ -84,7 +100,15 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const C; + let field_ptr = std::ptr::addr_of!(struct_instance.baz); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() + }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index c4dfa55ad9..f9e21cad2f 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -132,9 +132,15 @@ fn bindgen_test_layout_Weird() { concat!("Alignment of ", stringify!(Weird)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mStrokeDasharrayLength as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = + std::ptr::addr_of!(struct_instance.mStrokeDasharrayLength); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -145,8 +151,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mClipRule as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mClipRule); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!( @@ -157,9 +169,15 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mColorInterpolation as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = + std::ptr::addr_of!(struct_instance.mColorInterpolation); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 9usize, concat!( @@ -170,9 +188,15 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mColorInterpolationFilters - as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = + std::ptr::addr_of!(struct_instance.mColorInterpolationFilters); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 10usize, concat!( @@ -183,8 +207,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mFillRule as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mFillRule); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 11usize, concat!( @@ -195,9 +225,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mImageRendering as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mImageRendering); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 12usize, concat!( @@ -208,8 +243,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mPaintOrder as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mPaintOrder); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 13usize, concat!( @@ -220,9 +261,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mShapeRendering as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mShapeRendering); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 14usize, concat!( @@ -233,9 +279,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mStrokeLinecap as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mStrokeLinecap); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 15usize, concat!( @@ -246,9 +297,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mStrokeLinejoin as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mStrokeLinejoin); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 16usize, concat!( @@ -259,8 +315,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mTextAnchor as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mTextAnchor); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 17usize, concat!( @@ -271,9 +333,14 @@ fn bindgen_test_layout_Weird() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).mTextRendering as *const _ - as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const Weird; + let field_ptr = std::ptr::addr_of!(struct_instance.mTextRendering); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 18usize, concat!( diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs index 92b6798fb2..842e1e3e90 100644 --- a/tests/expectations/tests/zero-size-array-align.rs +++ b/tests/expectations/tests/zero-size-array-align.rs @@ -55,8 +55,14 @@ fn bindgen_test_layout_dm_deps() { concat!("Alignment of ", stringify!(dm_deps)) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).count as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const dm_deps; + let field_ptr = std::ptr::addr_of!(struct_instance.count); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 0usize, concat!( @@ -67,8 +73,14 @@ fn bindgen_test_layout_dm_deps() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).filler as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const dm_deps; + let field_ptr = std::ptr::addr_of!(struct_instance.filler); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 4usize, concat!( @@ -79,8 +91,14 @@ fn bindgen_test_layout_dm_deps() { ) ); assert_eq!( - unsafe { - &(*(::std::ptr::null::())).device as *const _ as usize + { + let struct_instance = unsafe { std::mem::zeroed::() }; + let struct_ptr = &struct_instance as *const dm_deps; + let field_ptr = std::ptr::addr_of!(struct_instance.device); + let struct_address = struct_ptr as usize; + let field_address = field_ptr as usize; + std::mem::forget(struct_instance); + field_address.checked_sub(struct_address).unwrap() }, 8usize, concat!(