Skip to content

Commit d59c82a

Browse files
committed
BUG: fix eplicit_padding when a struct ends in a bitfield.
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.
1 parent ae68172 commit d59c82a

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed

bindgen-tests/tests/expectations/tests/explicit-padding.rs

+146
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/headers/explicit-padding.h

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ union dont_pad_me {
1515
uint32_t second;
1616
uint16_t third;
1717
};
18+
19+
struct also_pad_me {
20+
uint16_t first;
21+
uint8_t bits: 1;
22+
};

bindgen/codegen/struct_layout.rs

+5
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ impl<'a> StructLayoutTracker<'a> {
285285
return None;
286286
}
287287

288+
// If the last field was a bitfield, it will already have been padded.
289+
if self.last_field_was_bitfield {
290+
return None;
291+
}
292+
288293
// Padding doesn't make sense for rust unions.
289294
if self.is_rust_union {
290295
return None;

0 commit comments

Comments
 (0)