Skip to content

Commit

Permalink
BUG: fix eplicit_padding when a struct ends in a bitfield.
Browse files Browse the repository at this point in the history
A struct ending in a bitfield will have its trailing padding
duplicated. This change skips adding the trailing padding if the last
field was a bitfield, and thus, already has already been padded.
  • Loading branch information
sw17ch committed Feb 9, 2023
1 parent ae68172 commit d59c82a
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
146 changes: 146 additions & 0 deletions bindgen-tests/tests/expectations/tests/explicit-padding.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions bindgen-tests/tests/headers/explicit-padding.h
Expand Up @@ -15,3 +15,8 @@ union dont_pad_me {
uint32_t second;
uint16_t third;
};

struct also_pad_me {
uint16_t first;
uint8_t bits: 1;
};
5 changes: 5 additions & 0 deletions bindgen/codegen/struct_layout.rs
Expand Up @@ -285,6 +285,11 @@ impl<'a> StructLayoutTracker<'a> {
return None;
}

// If the last field was a bitfield, it will already have been padded.
if self.last_field_was_bitfield {
return None;
}

// Padding doesn't make sense for rust unions.
if self.is_rust_union {
return None;
Expand Down

0 comments on commit d59c82a

Please sign in to comment.