Skip to content

More bitfield brokenness #743

Open
Open
@emilio

Description

While investigating #739, I found out that the following:

#define POINTER_WIDTH (sizeof(void*) * 8)

struct Foo {
  int dummy;
  unsigned long foo: 1;
  unsigned long bar: POINTER_WIDTH;
};

Generates what I think it's correct code:

#[repr(C)]
#[derive(Debug, Copy)]
pub struct Foo {
    pub dummy: ::std::os::raw::c_int,
    pub _bitfield_1: [u64; 2usize],
    pub __bindgen_align: [u64; 0usize],
}

But apparently isn't, and Clang manages to stick the first bitfield after the int (wat).

The following is also incorrect, generating the right layout but the wrong offset:

struct Foobie {
  int dummy;
  unsigned long foo: 1;
  unsigned long bar: POINTER_WIDTH - 1;
};

We generate an int, then one word when we stick the two bitfields, but clang does the first bit at offset 32 (right after the int), and the other 63 bits after the gap, in the next u64.

Sigh.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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