-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong alignment of struct #1034
Comments
Reduced by
Reduced by
|
For alignment problem:
this little program outputs Generated bindings looks like: #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#[repr(C)]
#[derive(Debug, Default, Copy)]
pub struct S2 {
pub _bitfield_1: u16,
pub __bindgen_align: [u8; 0usize],
}
#[test]
fn bindgen_test_layout_S2() {
assert_eq!(
::std::mem::size_of::<S2>(),
2usize,
concat!("Size of: ", stringify!(S2))
);
assert_eq!(
::std::mem::align_of::<S2>(),
1usize,
concat!("Alignment of ", stringify!(S2))
);
}
impl Clone for S2 {
fn clone(&self) -> Self {
*self
}
}
impl S2 {
#[inline]
pub fn new_bitfield_1() -> u16 {
0
}
} |
Interesting -- it looks like the layout libclang gives us says |
I compiled with
|
Oops, my comment #1034 (comment) contains copy-pasta issue. It tells that it outputs Sorry about that! Fixed version: #include <stdio.h>
struct S2 {
unsigned : 11;
};
int main() {
printf("sizeof(S2)=%lu,alignof(S2)=%lu\n", sizeof(S2), alignof(S2));
} returns This makes things a little clearer. |
Is it possible to solve now? If I understand correctly to make this struct #[repr(C)]
#[derive(Debug, Default, Copy)]
pub struct S2 {
pub _bitfield_1: u16,
pub __bindgen_align: [u8; 0usize],
} to have alignment of 1 we should have |
Depends on #849 and rust-lang/rust#33626 |
It seems that It appears that we actually need to use |
Use `repr(packed)` If struct requires explicit alignment of 1. Fixes #1034
Input C/C++ Header
Generated by C-Smith:
Bindgen Invocation
Actual Results
Expected Results
No layout test failures.
The text was updated successfully, but these errors were encountered: