comp: Fix alignment of bitfields in some edge cases. #3247
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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