diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index b13b3c81cd..beea517eed 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -200,6 +200,45 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).big_array + as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array + as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -224,6 +263,32 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -250,6 +315,66 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(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 + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .big_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .zero_length_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .incomplete_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -283,6 +408,51 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(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 + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .zero_length_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -329,6 +499,32 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).whatever + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index b341bdbe87..d527dfd75f 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -253,6 +253,45 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).big_array + as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array + as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -277,6 +316,32 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -303,6 +368,66 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(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 + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .big_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .zero_length_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array, + >())) + .incomplete_array as *const _ as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -336,6 +461,51 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(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 + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .zero_length_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::< + C_with_zero_length_array_and_incomplete_array_2, + >())) + .incomplete_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] @@ -382,6 +552,32 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).whatever + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())) + .incomplete_array as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 851080749d..32607b375f 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -90,6 +90,24 @@ fn bindgen_test_layout_test2() { 4usize, concat!("Alignment of ", stringify!(test2)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -110,4 +128,35 @@ fn bindgen_test_layout_test3() { 4usize, concat!("Alignment of ", stringify!(test3)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).zero_length_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).incomplete_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array) + ) + ); } diff --git a/tests/expectations/tests/incomplete-array-padding.rs b/tests/expectations/tests/incomplete-array-padding.rs index a0fa750c6a..c380a0cc8d 100644 --- a/tests/expectations/tests/incomplete-array-padding.rs +++ b/tests/expectations/tests/incomplete-array-padding.rs @@ -140,6 +140,11 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index 35a5e52ca3..d8f2ac6ee8 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -117,6 +117,54 @@ fn bindgen_test_layout_rte_ring() { 8usize, concat!("Alignment of ", stringify!(rte_ring)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).memzone as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(memzone) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).prod as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(prod) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cons as *const _ as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(cons) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).ring as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(ring) + ) + ); } impl Default for rte_ring { fn default() -> Self { diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 44998a8947..d153fa5ec4 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -147,6 +147,67 @@ fn bindgen_test_layout_rte_kni_fifo() { 8usize, concat!("Alignment of ", stringify!(rte_kni_fifo)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).write as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).read as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).len as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).elem_size as *const _ + as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).buffer as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(buffer) + ) + ); } impl Default for rte_kni_fifo { fn default() -> Self { diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index 347c22649d..6514b930c7 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -136,6 +136,19 @@ fn bindgen_test_layout_DynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).arr as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr) + ) + ); } /// No `_address` field here either. #[repr(C)] @@ -155,4 +168,17 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).dsa + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa) + ) + ); }