Invalid c struct bitfield generation in some cases
Discussed in https://github.com/rust-lang/rust-bindgen/discussions/3104
So, i'm trying to run bindgen from a pokemon decomp project, and having issues with some structs not passing the sanity checks.
I've pinpointed it to an alignment issue on some structs with bitfields, here is a minimal reproduction:
struct Test
{
char a;
char b:4;
char c:4;
short x:6;
short y:10;
};
clang/gcc make that struct fit into 4 bytes, but bindgen adds a full byte of padding between c and x
I've experimented quickly and stepped through the code for handling bitfields in bindgen/ir/comp.rs and I'm pretty sure it's an issue with bindgen's handling. I think it's because bitfield groups are constructed as if they are already starting aligned, but I'm an informed layman at best.
Yeah this looks like a bug. Unfortunately our bitfield generation is kinda reverse-engineered from LLVM, it seems we're getting that case wrong. Fixing and adding it as a test would be great.
This might be a dupe of https://github.com/rust-lang/rust-bindgen/issues/1377