Skip to content

Incorrect layout of bitfields #3384

Description

@avahahn

I have run into an issue with rust-bindgen where the bitfield objects made do not actually map correctly onto the underlying C structure.
Here is a small, self contained sample where you can observe the issue: https://github.com/avahahn/bindgen-issue-repro

Here, I have a struct with a number of fields, including these two specifically:

(lib.h)

typedef struct {

    (... omitted ...)

  unsigned request_body_file_log_level : 3;
  unsigned request_body_no_buffering : 1;
} fields;

When working with this struct definition in rust you might expect that calling the following code will result in setting request_body_no_buffering to 1:

        global_fields.set_request_body_no_buffering(1);

However, it does not. Instead it sets request_body_file_log_level to 2. This reproduces on my x86_64 box as well as my arm64 box.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions