Skip to content

Commit

Permalink
Consider alignment contribution from bitfields (#2680)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 authored Dec 11, 2023
1 parent b6ff609 commit be197f3
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 22 deletions.

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

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

1 change: 0 additions & 1 deletion bindgen-tests/tests/expectations/tests/bitfield_align.rs

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

1 change: 0 additions & 1 deletion bindgen-tests/tests/expectations/tests/bitfield_align_2.rs

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

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

96 changes: 95 additions & 1 deletion bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs

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

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

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

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

2 changes: 1 addition & 1 deletion bindgen-tests/tests/expectations/tests/issue-1034.rs

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

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

1 change: 0 additions & 1 deletion bindgen-tests/tests/expectations/tests/issue-1947.rs

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

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

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

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

2 changes: 1 addition & 1 deletion bindgen-tests/tests/expectations/tests/only_bitfields.rs

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

1 change: 0 additions & 1 deletion bindgen-tests/tests/expectations/tests/union_bitfield.rs

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

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

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

11 changes: 11 additions & 0 deletions bindgen-tests/tests/headers/bitfield_pragma_packed.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ struct Struct {
unsigned char e : 8;
};
#pragma pack(pop)

struct Inner {
unsigned short a: 16;
unsigned short b: 16;
};

#pragma pack(push, 1)
struct Outer {
struct Inner inner;
};
#pragma pop
4 changes: 1 addition & 3 deletions bindgen/codegen/struct_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ impl<'a> StructLayoutTracker<'a> {

self.latest_field_layout = Some(layout);
self.last_field_was_bitfield = true;
// NB: We intentionally don't update the max_field_align here, since our
// bitfields code doesn't necessarily guarantee it, so we need to
// actually generate the dummy alignment.
self.max_field_align = cmp::max(self.max_field_align, layout.align);
}

/// Returns a padding field if necessary for a given new field _before_
Expand Down

0 comments on commit be197f3

Please sign in to comment.