rust-bindgen: Incorrect layout with large bitfield

Follow up to https://github.com/rust-lang-nursery/rust-bindgen/pull/1001

Input C/C++ Header

struct {
  unsigned : 632;
} a;

Bindgen Invocation

$ bindgen input.h

Actual Results

Panic when running the layout tests: our generated struct ends up with the wrong size.

Expected Results

We generate a struct with the correct layout, and it passes its layout tests.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Looks like g++ agrees with clang++ on a size of 80:

$ cat big-bitfield.cpp 
struct HasBigBitfield {
    unsigned : 632;
};

int f(HasBigBitfield*);

int main() {
    HasBigBitfield b;
    return f(&b);
}
$ g++ -g -c big-bitfield.cpp -o big-bitfield.o
big-bitfield.cpp:2:16: warning: width of ‘HasBigBitfield::<anonymous>’ exceeds its type
     unsigned : 632;
                ^~~
$ dwarfdump big-bitfield.o
...
< 1><0x0000002d>    DW_TAG_structure_type
                      DW_AT_name                  HasBigBitfield
                      DW_AT_byte_size             0x00000050
                      DW_AT_decl_file             0x00000001 /home/fitzgen/scratch/big-bitfield.cpp
                      DW_AT_decl_line             0x00000001
...
$