Skip to content

Commit d282c28

Browse files
emilioqinghon
andcommitted
comp: Fix alignment of bitfields in some edge cases.
In order to properly compute the size of the bitfield for overaligned fields, we need to know the offset in the struct, not just in the allocation unit. E.g., something like: char; // Byte 1 char: 8; // Byte 2 short: 16; // Bytes 3 and 4 Should align differently than: char: 8; // Byte 1 short: 16; // Bytes 3 and 4 If we can't find the start offset in the struct, we fall back to our previous behavior (this can happen with C++ templates for example). We remove some code related to `is_ms_struct`, which was effectively dead. If someone cares about it they can resurrect it. We also don't align per-bitfield unit, but in order to mostly preserve behavior, we keep inserting a field at the beginning of the struct rather than using repr(align). Otherwise we hit #2179 in cases where we did not use to. We might want to extend that approach to repr(align) stuff, in order to try to fix #2179 more often, but for now do the minimal change. Fixes #1377 Fixes #3105 Fixes #743 Fixes #981 Fixes #1314 Co-authored-by: qinghon <[email protected]>
1 parent f015c10 commit d282c28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1065
-219
lines changed

bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield-large.rs

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield-template.rs

Lines changed: 214 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield_align.rs

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield_align_2.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)