Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2aba15d

Browse files
committedFeb 9, 2023
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 2aba15d

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed
 

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

+145
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)
Please sign in to comment.