You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong code generated for union with bitfields #3184
The below outputs are with bindgen 0.71.1 (no flags) on x86_64-pc-windows-msvc.
Consider the union below. There are two issues:
The accessors for bitfld_b and bitfld_c use bit offsets of 4 and 8, respectively, while they should be 0.
The generated type has the wrong size, resulting in a compile error. The C type has size 4 and alignment 1, but the generated type has size 2. (On x86_64-unknown-linux-gnu it happens to compile(!) because the alignment is 4 which makes the size also 4.) Therefore, padding needs to be added.
Don't ask me why someone put a bitfield in a union. (The case I found was an anonymous union in a struct, but that doesn't seem to make a difference.)
#[repr(C)]#[derive(Copy,Clone)]pubunionUnion{pub_bitfield_align_1:[u8;0],pub_bitfield_1:__BindgenBitfieldUnit<[u8;2usize]>,// ^^^^^^ should be 4usize}#[allow(clippy::unnecessary_operation, clippy::identity_op)]const _:() = {["Size of Union"][::std::mem::size_of::<Union>() - 4usize];["Alignment of Union"][::std::mem::align_of::<Union>() - 1usize];};implUnion{// ...pubfnbitfld_b(&self) -> ::std::os::raw::c_int{unsafe{::std::mem::transmute(self._bitfield_1.get(4usize,4u8)asu32)}// ^^^^^^ should be 0usize}// ...}
Compile error
error[E0080]: evaluation of constant value failed
--> bindings.rs:148:23
|
148 | ["Size of Union"][::std::mem::size_of::<Union>() - 4usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `2_usize - 4_usize`, which would overflow
Activity
Fix tests on Windows