6.3: Fix KeyPath with 16-byte-aligned subscript traps on 32-bit targets#89323
Merged
MaxDesiatov merged 1 commit intoMay 22, 2026
Merged
Conversation
- **Explanation**: Fixes a crash with key paths on 32-bit platforms reproducible for types that have 16-byte alignment. The intended bit layout of `ComputedArgumentSize` in `KeyPath` on 32-bit is: ``` ┌───────┬───────────┐ │ bits │ field │ ├───────┼───────────┤ │ 0–27 │ size │ ├───────┼───────────┤ │ 28–29 │ padding │ ├───────┼───────────┤ │ 30–31 │ alignment │ └───────┴───────────┘ ``` Currently, `alignmentMask = 0x6000_0000`, i.e. bits 29–30, not 30–31. It overlaps paddingMask (bits 28–29) at bit 29, meaning that alignment and padding unintentionally share a bit. With `alignmentShift = 30`, storing `shift = 2 << 30` places 1 at bit 31, which the mask doesn't cover. Correct value is `0xC000_0000` covers bits 30–31, which matches `alignmentShift = 30` so both `shift = 1` and `shift = 2` round-trip, and it does not overlap with `paddingMask = 0x3000_0000` (bits 28–29). It also mirrors the 64-bit layout (top bits of the word reserved for alignment, just 2 of them instead of 1). - **Scope**: Limited to 32-bit platforms. - **Issues**: rdar://175799967 - **Risk**: Low due to increased test coverage. - **Testing**: Previously crashing on 32-bit platforms sample code is now added to the test suite.
Contributor
Author
|
@swift-ci test |
al45tair
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Cherry-pick of #88725
ComputedArgumentSizeinKeyPathon 32-bit is:Currently,
alignmentMask = 0x6000_0000, i.e. bits 29–30, not 30–31. It overlaps paddingMask (bits 28–29) at bit 29, meaning that alignment and padding unintentionally share a bit. WithalignmentShift = 30, storingshift = 2 << 30places 1 at bit 31, which the mask doesn't cover.Correct value is
0xC000_0000covers bits 30–31, which matchesalignmentShift = 30so bothshift = 1andshift = 2round-trip, and it does not overlap withpaddingMask = 0x3000_0000(bits 28–29). It also mirrors the 64-bit layout (top bits of the word reserved for alignment, just 2 of them instead of 1).rdar://175799967
rdar://177213829
mainandrelease/6.4.