diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6bbb7ab591..72bea7ea59 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2025,7 +2025,9 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::repr("C")); } - if ctx.options().rust_features().repr_align { + if ctx.options().rust_features().repr_align && !packed { + // We can't specify both packed(N) and align(N), but the align() + // should be redundant in this case. if let Some(explicit) = explicit_align { // Ensure that the struct has the correct alignment even in // presence of alignas. diff --git a/tests/expectations/struct_with_anon_struct_array_float.rs b/tests/expectations/struct_with_anon_struct_array_float.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/tests/expectations/struct_with_anon_struct_array_float.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/expectations/tests/packed-align-conflict.rs b/tests/expectations/tests/packed-align-conflict.rs new file mode 100644 index 0000000000..e78e5f9c75 --- /dev/null +++ b/tests/expectations/tests/packed-align-conflict.rs @@ -0,0 +1,38 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C, packed(2))] +#[derive(Debug, Default, Copy, Clone)] +pub struct FndrOpaqueInfo { + pub opaque: [::std::os::raw::c_char; 16usize], +} +#[test] +fn bindgen_test_layout_FndrOpaqueInfo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(FndrOpaqueInfo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(FndrOpaqueInfo)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(FndrOpaqueInfo), + "::", + stringify!(opaque) + ) + ); +} diff --git a/tests/headers/packed-align-conflict.h b/tests/headers/packed-align-conflict.h new file mode 100644 index 0000000000..aca17a64b4 --- /dev/null +++ b/tests/headers/packed-align-conflict.h @@ -0,0 +1,3 @@ +struct FndrOpaqueInfo { + char opaque[16]; +} __attribute__((aligned(2), packed));