-
Notifications
You must be signed in to change notification settings - Fork 742
E0587 error on packed and aligned structures from C #1538
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I assume you mean 0.47.3?
Can you put an example? I assume the workaround would look like: #[repr(align(64))]
pub struct xregs_state(pub xreg_state_inner);
#[repr(packed)]
pub struct xreg_state_inner {
// fields
} Is that right? If so, that's feasible. But it only solves this very specific case, which is slightly unfortunate. I haven't dug deep into how to properly generate rust code for aligned structs inside packed structs and such. That's something that rustc errors on, but C compilers happily allow it without issues. Actually, for this test-case, it seems we're being naive, and we could just generate |
Err, wrong button of course. |
Ah, I was wrong. |
There's a further complication, which is that there's no good way I know of distinguishing this case from |
I submitted https://reviews.llvm.org/D59299 to be able to distinguish that case, eventually. |
Woo, thanks for jumping on this. |
Sorry, I meant 0.48.1 (the latest version). |
#[repr(align(64))]
pub struct xregs_state(pub xreg_state_inner);
#[repr(packed)]
pub struct xreg_state_inner {
// fields
} Yes, that's basically what we had in mind, but I'm hoping that this can be fixed in rustc instead. |
Worth mentioning: 0.47.3 generates code that compiles just fine because the definition for that structure is: #[repr(C)]
pub struct xregs_state {
pub _bindgen_opaque_blob: [u8; 576usize],
} This is only a problem on newer bindgen because it now generates the full definition for the structure. |
Well, that's not fine (as in, it doesn't have the right alignment), but as I said you can go back to that (and with the right alignment thanks to #1530) using the |
The test was failing.
I ran into the following issue when converting some kernel headers with bindgen 0.48.1:
When converting C structures that are both packed and aligned using either C2Rust or bindgen, such as:
the code that either tool produces looks something like:
This Rust code fails to compile due to error
E0587
:We can work around this in C2Rust by emitting an aligned outer/packed inner structure pair (I think bindgen could do the same), but I'm wondering if it would be better to fix this on the Rust language/compiler side (I also opened rust-lang/rust#59154 for a discussion on this).
The text was updated successfully, but these errors were encountered: