-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multi-payload enums with Class Existential payloads on 32-bit targets #77027
Fix multi-payload enums with Class Existential payloads on 32-bit targets #77027
Conversation
…gets Class existentials expose spare bits from all of the pointers, not just the first one. Due to a bad bug here, we were properly exposing spare bits from the first pointer, but then claiming that all bits of subsequent pointers were spare. This accidentally resulted in the correct operation on 64-bit targets (it picked the highest-order spare bit, which happened to be spare in both the broken mask and the correct mask). But on 32-bit targets, this exposed the high-order bits of pointers, which is incorrect. Expand the test a bit while we're here as well. Resolves rdar://132715829
@swift-ci Please test |
auto mpePointerSpareBits = TC.getBuilder().getMultiPayloadEnumPointerMask(); | ||
mask.andMask(mpePointerSpareBits, 0); | ||
mask.keepOnlyLeastSignificantBytes(TC.targetPointerSize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The truncation in the previous code here inadvertently marked everything beyond the first pointer as spare bits. This accidentally worked for 64-bit because MPEs pick the most-significant spare bit.
mask.keepOnlyLeastSignificantBytes(TC.targetPointerSize()); | ||
auto mpePointerSpareBitMask = BitMask(TC.targetPointerSize(), mpePointerSpareBits); | ||
for (int offset = 0; offset < (int)getSize(); offset += TC.targetPointerSize()) { | ||
mask.andMask(mpePointerSpareBitMask, offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the new code, we loop to apply the standard pointer spare bit mask to every pointer-sized field.
@@ -10,9 +10,6 @@ | |||
// UNSUPPORTED: use_os_stdlib | |||
// UNSUPPORTED: asan | |||
|
|||
// This is broken on ARM64_32, disable it temporarily until we can fix it. rdar://137351613 | |||
// UNSUPPORTED: CPU=arm64_32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay! It works for 32-bit watchOS now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@swift-ci Please test macOS Platform |
1 similar comment
@swift-ci Please test macOS Platform |
The first word in a class existential is the class pointer itself. This pointer exposes spare bits differently depending on the platform, which becomes apparent when you try to reflect an Optional carrying such an MPE. Add new test cases and some logic to zero out the first word of spare bit information only on platforms with 8-byte pointers.
// itself, which can be tagged or have other mysteries on 64-bit, so | ||
// it exposes no spare bits from the first word there... | ||
auto pointerBytes = TC.targetPointerSize(); | ||
if (pointerBytes == 8) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anyone is trying to get RemoteMirror to work on non-Darwin, they may need to tweak this some more.
@swift-ci Please test |
@swift-ci Please test |
Class existentials expose spare bits from all of the pointers, not just the first one. Due to a bad bug here, we were properly exposing spare bits from the first pointer, but then claiming that all bits of subsequent pointers were spare. This accidentally resulted in the correct operation on 64-bit targets (it picked the highest-order spare bit, which happened to be spare in both the broken mask and the correct mask). But on 32-bit targets, this exposed the high-order bits of pointers, which is incorrect.
Expand the test a bit while we're here as well.
Resolves rdar://132715829