Skip to content

Invalid c struct bitfield generation in some cases #3105

Open
@Strackeror

Description

@Strackeror

Discussed in #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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions