-
Notifications
You must be signed in to change notification settings - Fork 696
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
"Calculated wrong layout" for structs with reference member #1443
Comments
Yeah, looks like there's a subtle bug somewhere, if you look at the debug log, we think that Looks like clang may return the wrong layout here for references. In fact, if you change the 'give me a size for this type function' like: diff --git a/src/clang.rs b/src/clang.rs
index f8f7e581..cf4bb7b0 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -862,16 +862,19 @@ impl Type {
}
/// What is the size of this type?
pub fn fallible_size(&self) -> Result<usize, LayoutError> {
let val = unsafe { clang_Type_getSizeOf(self.x) };
if val < 0 {
Err(LayoutError::from(val as i32))
} else {
+ if self.kind() == CXType_LValueReference {
+ println!("{:?} -> {:?}", self, val);
+ }
Ok(val as usize)
}
} You can then see the following printed:
Which is clearly bogus. This can produce incorrect results, so it's a bug. Good thing is that we actually know the layout of a pointer, and know the thing we have is a reference, so this is fixable, but I don't know yet where's the best place to fix it... Probably we can just override the clang value from |
A more scary case: struct Foo;
struct Bar {
const Foo& f;
unsigned m;
}; Which generates: #[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Foo {
_unused: [u8; 0],
}
#[repr(C)]
#[repr(align(8))]
#[derive(Debug, Copy, Clone)]
pub struct Bar {
pub f: *const Foo,
pub __bindgen_padding_0: [u32; 2usize],
pub m: ::std::os::raw::c_uint,
} Which is clearly bogus. |
Fixed by #1531. |
Input C/C++ Header
Bindgen Invocation
Actual Results
The resulting conversion looks ok to me, so I guess that is just noise, which would make it a really minor issue, but I just wasn't sure if there is a hidden alignment bug when handling references, that should be checked by someone know who knows the code better.
The text was updated successfully, but these errors were encountered: