Skip to content

Commit bd011d4

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 bd011d4

Some content is hidden

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

52 files changed

+1074
-222
lines changed

bindgen-integration/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,18 @@ fn test_bitfields_seventh() {
178178
fn test_bitfield_constructors() {
179179
use std::mem;
180180
let mut first = bindings::bitfields::First {
181-
_bitfield_align_1: [],
182181
_bitfield_1: bindings::bitfields::First::new_bitfield_1(1, 2, 3),
183182
};
184183
assert!(unsafe { first.assert(1, 2, 3) });
185184

186185
let mut second = bindings::bitfields::Second {
187-
_bitfield_align_1: [],
186+
_bindgen_align: [],
188187
_bitfield_1: bindings::bitfields::Second::new_bitfield_1(1337, true),
189188
};
190189
assert!(unsafe { second.assert(1337, true) });
191190

192191
let mut third = bindings::bitfields::Third {
193-
_bitfield_align_1: [],
192+
_bindgen_align: [],
194193
_bitfield_1: bindings::bitfields::Third::new_bitfield_1(
195194
42,
196195
false,

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)