diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-10-11 16:07:36 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-10-14 14:15:46 +0200 |
commit | 5591a103551080ba599b0809458ced65c5633bff (patch) | |
tree | bb09525069290b50d0b9ff7caa11b1aabec7e850 | |
parent | 601baa2f6bd2158ab361c81418977fc7485d5d6e (diff) |
Update test expectations for libclang 9.0.
8 files changed, 2329 insertions, 7 deletions
diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs new file mode 100644 index 00000000..285c108b --- /dev/null +++ b/tests/expectations/tests/libclang-9/class.rs @@ -0,0 +1,636 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct C { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], +} +#[test] +fn bindgen_test_layout_C() { + assert_eq!( + ::std::mem::size_of::<C>(), + 40usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::<C>(), + 4usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C>())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C>())).big_array as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); +} +impl Default for C { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +pub struct C_with_zero_length_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array>(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_zero_length_array>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_zero_length_array>())).big_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_zero_length_array>())).zero_length_array as *const _ + as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); +} +impl Default for C_with_zero_length_array { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array_2() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array_2>(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array_2>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_zero_length_array_2>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_zero_length_array_2>())).zero_length_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); +} +#[repr(C)] +pub struct C_with_incomplete_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_incomplete_array() { + assert_eq!( + ::std::mem::size_of::<C_with_incomplete_array>(), + 40usize, + concat!("Size of: ", stringify!(C_with_incomplete_array)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_incomplete_array>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_incomplete_array>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_incomplete_array>())).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::<C_with_incomplete_array>())).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 { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_incomplete_array_2() { + assert_eq!( + ::std::mem::size_of::<C_with_incomplete_array_2>(), + 4usize, + concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_incomplete_array_2>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_incomplete_array_2>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_incomplete_array_2>())).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 { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array>(), + 40usize, + concat!( + "Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array) + ) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>(), + 4usize, + concat!( + "Alignment of ", + 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 { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_and_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array_2>(), + 4usize, + concat!( + "Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2) + ) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array_2>(), + 4usize, + concat!( + "Alignment of ", + 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)] +pub struct WithDtor { + pub b: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_WithDtor() { + assert_eq!( + ::std::mem::size_of::<WithDtor>(), + 4usize, + concat!("Size of: ", stringify!(WithDtor)) + ); + assert_eq!( + ::std::mem::align_of::<WithDtor>(), + 4usize, + concat!("Alignment of ", stringify!(WithDtor)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<WithDtor>())).b as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); +} +#[repr(C)] +pub struct IncompleteArrayNonCopiable { + pub whatever: *mut ::std::os::raw::c_void, + pub incomplete_array: __IncompleteArrayField<C>, +} +#[test] +fn bindgen_test_layout_IncompleteArrayNonCopiable() { + assert_eq!( + ::std::mem::size_of::<IncompleteArrayNonCopiable>(), + 8usize, + concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + ); + assert_eq!( + ::std::mem::align_of::<IncompleteArrayNonCopiable>(), + 8usize, + concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<IncompleteArrayNonCopiable>())).whatever as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<IncompleteArrayNonCopiable>())).incomplete_array as *const _ + as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); +} +impl Default for IncompleteArrayNonCopiable { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union Union { + pub d: f32, + pub i: ::std::os::raw::c_int, + _bindgen_union_align: u32, +} +#[test] +fn bindgen_test_layout_Union() { + assert_eq!( + ::std::mem::size_of::<Union>(), + 4usize, + concat!("Size of: ", stringify!(Union)) + ); + assert_eq!( + ::std::mem::align_of::<Union>(), + 4usize, + concat!("Alignment of ", stringify!(Union)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<Union>())).d as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<Union>())).i as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + ); +} +impl Default for Union { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct WithUnion { + pub data: Union, +} +#[test] +fn bindgen_test_layout_WithUnion() { + assert_eq!( + ::std::mem::size_of::<WithUnion>(), + 4usize, + concat!("Size of: ", stringify!(WithUnion)) + ); + assert_eq!( + ::std::mem::align_of::<WithUnion>(), + 4usize, + concat!("Alignment of ", stringify!(WithUnion)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<WithUnion>())).data as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); +} +impl Default for WithUnion { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] +pub struct RealAbstractionWithTonsOfMethods { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { + assert_eq!( + ::std::mem::size_of::<RealAbstractionWithTonsOfMethods>(), + 1usize, + concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + ); + assert_eq!( + ::std::mem::align_of::<RealAbstractionWithTonsOfMethods>(), + 1usize, + concat!( + "Alignment of ", + stringify!(RealAbstractionWithTonsOfMethods) + ) + ); +} +extern "C" { + #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar(this: *const RealAbstractionWithTonsOfMethods); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar1(this: *mut RealAbstractionWithTonsOfMethods); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] + pub fn RealAbstractionWithTonsOfMethods_bar2( + this: *mut RealAbstractionWithTonsOfMethods, + foo: ::std::os::raw::c_int, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] + pub fn RealAbstractionWithTonsOfMethods_sta(); +} +impl RealAbstractionWithTonsOfMethods { + #[inline] + pub unsafe fn bar(&self) { + RealAbstractionWithTonsOfMethods_bar(self) + } + #[inline] + pub unsafe fn bar1(&mut self) { + RealAbstractionWithTonsOfMethods_bar1(self) + } + #[inline] + pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { + RealAbstractionWithTonsOfMethods_bar2(self, foo) + } + #[inline] + pub unsafe fn sta() { + RealAbstractionWithTonsOfMethods_sta() + } +} diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs new file mode 100644 index 00000000..b331dcdf --- /dev/null +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -0,0 +1,694 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +#[repr(C)] +pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>); +impl<T> __BindgenUnionField<T> { + #[inline] + pub fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } +} +impl<T> ::std::default::Default for __BindgenUnionField<T> { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl<T> ::std::clone::Clone for __BindgenUnionField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl<T> ::std::marker::Copy for __BindgenUnionField<T> {} +impl<T> ::std::fmt::Debug for __BindgenUnionField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl<T> ::std::hash::Hash for __BindgenUnionField<T> { + fn hash<H: ::std::hash::Hasher>(&self, _state: &mut H) {} +} +impl<T> ::std::cmp::PartialEq for __BindgenUnionField<T> { + fn eq(&self, _other: &__BindgenUnionField<T>) -> bool { + true + } +} +impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {} +#[repr(C)] +#[derive(Copy)] +pub struct C { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], +} +#[test] +fn bindgen_test_layout_C() { + assert_eq!( + ::std::mem::size_of::<C>(), + 40usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::<C>(), + 4usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C>())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C>())).big_array as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); +} +impl Clone for C { + fn clone(&self) -> Self { + *self + } +} +impl Default for C { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl ::std::cmp::PartialEq for C { + fn eq(&self, other: &C) -> bool { + self.a == other.a && &self.big_array[..] == &other.big_array[..] + } +} +#[repr(C)] +pub struct C_with_zero_length_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array>(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_zero_length_array>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_zero_length_array>())).big_array as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_zero_length_array>())).zero_length_array as *const _ + as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); +} +impl Default for C_with_zero_length_array { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array_2() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array_2>(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array_2>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_zero_length_array_2>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_zero_length_array_2>())).zero_length_array as *const _ + as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); +} +#[repr(C)] +pub struct C_with_incomplete_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_incomplete_array() { + assert_eq!( + ::std::mem::size_of::<C_with_incomplete_array>(), + 40usize, + concat!("Size of: ", stringify!(C_with_incomplete_array)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_incomplete_array>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_incomplete_array>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_incomplete_array>())).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::<C_with_incomplete_array>())).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 { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_incomplete_array_2() { + assert_eq!( + ::std::mem::size_of::<C_with_incomplete_array_2>(), + 4usize, + concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + ); + assert_eq!( + ::std::mem::align_of::<C_with_incomplete_array_2>(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<C_with_incomplete_array_2>())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<C_with_incomplete_array_2>())).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 { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array>(), + 40usize, + concat!( + "Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array) + ) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array>(), + 4usize, + concat!( + "Alignment of ", + 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 { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_and_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { + assert_eq!( + ::std::mem::size_of::<C_with_zero_length_array_and_incomplete_array_2>(), + 4usize, + concat!( + "Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2) + ) + ); + assert_eq!( + ::std::mem::align_of::<C_with_zero_length_array_and_incomplete_array_2>(), + 4usize, + concat!( + "Alignment of ", + 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)] +pub struct WithDtor { + pub b: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_WithDtor() { + assert_eq!( + ::std::mem::size_of::<WithDtor>(), + 4usize, + concat!("Size of: ", stringify!(WithDtor)) + ); + assert_eq!( + ::std::mem::align_of::<WithDtor>(), + 4usize, + concat!("Alignment of ", stringify!(WithDtor)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<WithDtor>())).b as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); +} +#[repr(C)] +pub struct IncompleteArrayNonCopiable { + pub whatever: *mut ::std::os::raw::c_void, + pub incomplete_array: __IncompleteArrayField<C>, +} +#[test] +fn bindgen_test_layout_IncompleteArrayNonCopiable() { + assert_eq!( + ::std::mem::size_of::<IncompleteArrayNonCopiable>(), + 8usize, + concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + ); + assert_eq!( + ::std::mem::align_of::<IncompleteArrayNonCopiable>(), + 8usize, + concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<IncompleteArrayNonCopiable>())).whatever as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<IncompleteArrayNonCopiable>())).incomplete_array as *const _ + as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); +} +impl Default for IncompleteArrayNonCopiable { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Hash, PartialEq)] +pub struct Union { + pub d: __BindgenUnionField<f32>, + pub i: __BindgenUnionField<::std::os::raw::c_int>, + pub bindgen_union_field: u32, +} +#[test] +fn bindgen_test_layout_Union() { + assert_eq!( + ::std::mem::size_of::<Union>(), + 4usize, + concat!("Size of: ", stringify!(Union)) + ); + assert_eq!( + ::std::mem::align_of::<Union>(), + 4usize, + concat!("Alignment of ", stringify!(Union)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<Union>())).d as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<Union>())).i as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + ); +} +impl Clone for Union { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Hash, PartialEq)] +pub struct WithUnion { + pub data: Union, +} +#[test] +fn bindgen_test_layout_WithUnion() { + assert_eq!( + ::std::mem::size_of::<WithUnion>(), + 4usize, + concat!("Size of: ", stringify!(WithUnion)) + ); + assert_eq!( + ::std::mem::align_of::<WithUnion>(), + 4usize, + concat!("Alignment of ", stringify!(WithUnion)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<WithUnion>())).data as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); +} +impl Clone for WithUnion { + fn clone(&self) -> Self { + *self + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] +pub struct RealAbstractionWithTonsOfMethods { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { + assert_eq!( + ::std::mem::size_of::<RealAbstractionWithTonsOfMethods>(), + 1usize, + concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + ); + assert_eq!( + ::std::mem::align_of::<RealAbstractionWithTonsOfMethods>(), + 1usize, + concat!( + "Alignment of ", + stringify!(RealAbstractionWithTonsOfMethods) + ) + ); +} +extern "C" { + #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar(this: *const RealAbstractionWithTonsOfMethods); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar1(this: *mut RealAbstractionWithTonsOfMethods); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] + pub fn RealAbstractionWithTonsOfMethods_bar2( + this: *mut RealAbstractionWithTonsOfMethods, + foo: ::std::os::raw::c_int, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] + pub fn RealAbstractionWithTonsOfMethods_sta(); +} +impl Clone for RealAbstractionWithTonsOfMethods { + fn clone(&self) -> Self { + *self + } +} +impl RealAbstractionWithTonsOfMethods { + #[inline] + pub unsafe fn bar(&self) { + RealAbstractionWithTonsOfMethods_bar(self) + } + #[inline] + pub unsafe fn bar1(&mut self) { + RealAbstractionWithTonsOfMethods_bar1(self) + } + #[inline] + pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { + RealAbstractionWithTonsOfMethods_bar2(self, foo) + } + #[inline] + pub unsafe fn sta() { + RealAbstractionWithTonsOfMethods_sta() + } +} 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 new file mode 100644 index 00000000..0e0516dc --- /dev/null +++ b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -0,0 +1,158 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct test { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_test() { + assert_eq!( + ::std::mem::size_of::<test>(), + 4usize, + concat!("Size of: ", stringify!(test)) + ); + assert_eq!( + ::std::mem::align_of::<test>(), + 4usize, + concat!("Alignment of ", stringify!(test)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<test>())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<test>())).zero_length_array as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test), + "::", + stringify!(zero_length_array) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct test2 { + pub a: ::std::os::raw::c_int, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_test2() { + assert_eq!( + ::std::mem::size_of::<test2>(), + 4usize, + concat!("Size of: ", stringify!(test2)) + ); + assert_eq!( + ::std::mem::align_of::<test2>(), + 4usize, + concat!("Alignment of ", stringify!(test2)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<test2>())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<test2>())).incomplete_array as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct test3 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_test3() { + assert_eq!( + ::std::mem::size_of::<test3>(), + 4usize, + concat!("Size of: ", stringify!(test3)) + ); + assert_eq!( + ::std::mem::align_of::<test3>(), + 4usize, + concat!("Alignment of ", stringify!(test3)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<test3>())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<test3>())).zero_length_array as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<test3>())).incomplete_array as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array) + ) + ); +} diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs new file mode 100644 index 00000000..d089eaf6 --- /dev/null +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -0,0 +1,178 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit<Storage, Align> { + storage: Storage, + align: [Align; 0], +} +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage, align: [] } + } +} +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +#[repr(C)] +#[derive(Debug)] +pub struct foo { + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::<foo>(), + 8usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::<foo>(), + 8usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<foo>())).b as *const _ as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); +} +impl Default for foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +impl foo { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_char { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1(a: ::std::os::raw::c_char) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize], u8> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 1u8, { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }); + __bindgen_bitfield_unit + } +} diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs new file mode 100644 index 00000000..85c4c0d9 --- /dev/null +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -0,0 +1,172 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +#[repr(C)] +#[derive(Debug)] +pub struct rte_ring { + pub memzone: *mut rte_memzone, + pub prod: rte_ring_prod, + pub cons: rte_ring_cons, + pub ring: __IncompleteArrayField<*mut ::std::os::raw::c_void>, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct rte_ring_prod { + pub watermark: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_rte_ring_prod() { + assert_eq!( + ::std::mem::size_of::<rte_ring_prod>(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_prod)) + ); + assert_eq!( + ::std::mem::align_of::<rte_ring_prod>(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_prod)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_ring_prod>())).watermark as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct rte_ring_cons { + pub sc_dequeue: ::std::os::raw::c_uint, +} +#[test] +fn bindgen_test_layout_rte_ring_cons() { + assert_eq!( + ::std::mem::size_of::<rte_ring_cons>(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_cons)) + ); + assert_eq!( + ::std::mem::align_of::<rte_ring_cons>(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_cons)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_ring_cons>())).sc_dequeue as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue) + ) + ); +} +#[test] +fn bindgen_test_layout_rte_ring() { + assert_eq!( + ::std::mem::size_of::<rte_ring>(), + 16usize, + concat!("Size of: ", stringify!(rte_ring)) + ); + assert_eq!( + ::std::mem::align_of::<rte_ring>(), + 8usize, + concat!("Alignment of ", stringify!(rte_ring)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_ring>())).memzone as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(memzone) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_ring>())).prod as *const _ as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(prod) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_ring>())).cons as *const _ as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(cons) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_ring>())).ring as *const _ as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(ring) + ) + ); +} +impl Default for rte_ring { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct rte_memzone { + pub _address: u8, +} diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs new file mode 100644 index 00000000..be4df10e --- /dev/null +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -0,0 +1,297 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit<Storage, Align> { + storage: Storage, + align: [Align; 0], +} +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage, align: [] } + } +} +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + byte & mask == mask + } + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + let mask = 1 << bit_index; + if val { + *byte |= mask; + } else { + *byte &= !mask; + } + } + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); + let mut val = 0; + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + val + } + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +#[repr(C)] +#[derive(Debug)] +pub struct rte_kni_fifo { + ///< Next position to be written + pub write: ::std::os::raw::c_uint, + ///< Next position to be read + pub read: ::std::os::raw::c_uint, + ///< Circular buffer length + pub len: ::std::os::raw::c_uint, + ///< Pointer size - for 32/64 bit OS + pub elem_size: ::std::os::raw::c_uint, + ///< The buffer contains mbuf pointers + pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, +} +#[test] +fn bindgen_test_layout_rte_kni_fifo() { + assert_eq!( + ::std::mem::size_of::<rte_kni_fifo>(), + 16usize, + concat!("Size of: ", stringify!(rte_kni_fifo)) + ); + assert_eq!( + ::std::mem::align_of::<rte_kni_fifo>(), + 8usize, + concat!("Alignment of ", stringify!(rte_kni_fifo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_kni_fifo>())).write as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_kni_fifo>())).read as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_kni_fifo>())).len as *const _ as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_kni_fifo>())).elem_size as *const _ as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_kni_fifo>())).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 { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Default, Copy, Clone)] +pub struct rte_eth_link { + ///< ETH_SPEED_NUM_ + pub link_speed: u32, + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub __bindgen_padding_0: [u8; 3usize], +} +#[test] +fn bindgen_test_layout_rte_eth_link() { + assert_eq!( + ::std::mem::size_of::<rte_eth_link>(), + 8usize, + concat!("Size of: ", stringify!(rte_eth_link)) + ); + assert_eq!( + ::std::mem::align_of::<rte_eth_link>(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_link)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<rte_eth_link>())).link_speed as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_link), + "::", + stringify!(link_speed) + ) + ); +} +impl rte_eth_link { + #[inline] + pub fn link_duplex(&self) -> u16 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } + } + #[inline] + pub fn set_link_duplex(&mut self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn link_autoneg(&self) -> u16 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } + } + #[inline] + pub fn set_link_autoneg(&mut self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn link_status(&self) -> u16 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } + } + #[inline] + pub fn set_link_status(&mut self, val: u16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + link_duplex: u16, + link_autoneg: u16, + link_status: u16, + ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize], u8> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 1u8, { + let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; + link_duplex as u64 + }); + __bindgen_bitfield_unit.set(1usize, 1u8, { + let link_autoneg: u16 = unsafe { ::std::mem::transmute(link_autoneg) }; + link_autoneg as u64 + }); + __bindgen_bitfield_unit.set(2usize, 1u8, { + let link_status: u16 = unsafe { ::std::mem::transmute(link_status) }; + link_status as u64 + }); + __bindgen_bitfield_unit + } +} diff --git a/tests/expectations/tests/libclang-9/objc_template.rs b/tests/expectations/tests/libclang-9/objc_template.rs index 06a9a55f..84eef1ef 100644 --- a/tests/expectations/tests/libclang-9/objc_template.rs +++ b/tests/expectations/tests/libclang-9/objc_template.rs @@ -1,18 +1,22 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - -#![cfg(target_os="macos")] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] #[macro_use] extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait Foo { - unsafe fn get(self) - -> *mut ObjectType; + unsafe fn get(self) -> u64; } impl Foo for id { - unsafe fn get(self) -> *mut ObjectType { msg_send!(self , get) } + unsafe fn get(self) -> u64 { + msg_send!(self, get) + } } diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/tests/expectations/tests/libclang-9/zero-sized-array.rs new file mode 100644 index 00000000..41dc5c4f --- /dev/null +++ b/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -0,0 +1,183 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); +impl<T> __IncompleteArrayField<T> { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub unsafe fn as_ptr(&self) -> *const T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +/// Bizarrely enough, this should *not* get an `_address` field. +#[repr(C)] +#[derive(Debug, Default)] +pub struct ZeroSizedArray { + pub arr: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_ZeroSizedArray() { + assert_eq!( + ::std::mem::size_of::<ZeroSizedArray>(), + 0usize, + concat!("Size of: ", stringify!(ZeroSizedArray)) + ); + assert_eq!( + ::std::mem::align_of::<ZeroSizedArray>(), + 1usize, + concat!("Alignment of ", stringify!(ZeroSizedArray)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<ZeroSizedArray>())).arr as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ZeroSizedArray), + "::", + stringify!(arr) + ) + ); +} +/// And nor should this get an `_address` field. +#[repr(C)] +#[derive(Debug, Default)] +pub struct ContainsZeroSizedArray { + pub zsa: ZeroSizedArray, +} +#[test] +fn bindgen_test_layout_ContainsZeroSizedArray() { + assert_eq!( + ::std::mem::size_of::<ContainsZeroSizedArray>(), + 0usize, + concat!("Size of: ", stringify!(ContainsZeroSizedArray)) + ); + assert_eq!( + ::std::mem::align_of::<ContainsZeroSizedArray>(), + 1usize, + concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<ContainsZeroSizedArray>())).zsa as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsZeroSizedArray), + "::", + stringify!(zsa) + ) + ); +} +/// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted +/// either. +#[repr(C)] +#[derive(Debug, Default)] +pub struct InheritsZeroSizedArray { + pub _base: ZeroSizedArray, +} +#[test] +fn bindgen_test_layout_InheritsZeroSizedArray() { + assert_eq!( + ::std::mem::size_of::<InheritsZeroSizedArray>(), + 0usize, + concat!("Size of: ", stringify!(InheritsZeroSizedArray)) + ); + assert_eq!( + ::std::mem::align_of::<InheritsZeroSizedArray>(), + 1usize, + concat!("Alignment of ", stringify!(InheritsZeroSizedArray)) + ); +} +/// And this should not get an `_address` field either. +#[repr(C)] +#[derive(Debug, Default)] +pub struct DynamicallySizedArray { + pub arr: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[test] +fn bindgen_test_layout_DynamicallySizedArray() { + assert_eq!( + ::std::mem::size_of::<DynamicallySizedArray>(), + 0usize, + concat!("Size of: ", stringify!(DynamicallySizedArray)) + ); + assert_eq!( + ::std::mem::align_of::<DynamicallySizedArray>(), + 1usize, + concat!("Alignment of ", stringify!(DynamicallySizedArray)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<DynamicallySizedArray>())).arr as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr) + ) + ); +} +/// No `_address` field here either. +#[repr(C)] +#[derive(Debug, Default)] +pub struct ContainsDynamicallySizedArray { + pub dsa: DynamicallySizedArray, +} +#[test] +fn bindgen_test_layout_ContainsDynamicallySizedArray() { + assert_eq!( + ::std::mem::size_of::<ContainsDynamicallySizedArray>(), + 0usize, + concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)) + ); + assert_eq!( + ::std::mem::align_of::<ContainsDynamicallySizedArray>(), + 1usize, + concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::<ContainsDynamicallySizedArray>())).dsa as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa) + ) + ); +} |