Skip to content

[Runtime] Fixed multi-payload empty-case masking. #42131

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

Merged
merged 1 commit into from
Apr 1, 2022

Conversation

nate-chandler
Copy link
Contributor

When storing a tag into a multi-payload enum for an empty case via swift_storeEnumTagMultiPayload, the tag is split between the storage for payloads (i.e. the associated values of the non-empty cases) and the storage for tags (i.e. the integers which refer to the non-empty cases).

Typically, the number of non-empty cases (i.e. one beyond the tag that refers to the last non-empty case) is stored into the tag storage and the integer which distinguishes which among the empty cases the enum is in is stored into storage for payloads. When the enum is small, however--specifically, when the payload size is less than four bytes--that information is packaged differently via masking.

Previously, there was a problem with that masking. While the value stored into the tag storage was correct (and correctly indicated that the enum was in some empty case), the value stored into the payload storage was not. The result was that which empty case an enum was in would be corrupted.

Here, that is fixed by fixing the masking.

rdar://87914343

When storing a tag into a multi-payload enum for an empty case via
swift_storeEnumTagMultiPayload, the tag is split between the storage for
payloads (i.e. the associated values of the non-empty cases) and the
storage for tags (i.e. the integers which refer to the non-empty cases).

Typically, the number of non-empty cases (i.e. one beyond the tag
that refers to the last non-empty case) is stored into the tag storage
and the integer which distinguishes which among the empty cases the enum
is in is stored into storage for payloads.  When the enum is small,
however--specifically, when the payload size is less than four
bytes--that information is packaged differently via masking.

Previously, there was a problem with that masking.  While the value
stored into the tag storage was correct (and correctly indicated that
the enum was in some empty case), the value stored into the payload
storage was not.  The result was that which empty case an enum was in
would be corrupted.

Here, that is fixed by fixing the masking.

rdar://87914343
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler requested a review from jckarter April 1, 2022 04:11
Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Thank you!

@nate-chandler nate-chandler merged commit 2d370fb into swiftlang:main Apr 1, 2022
@nate-chandler nate-chandler deleted the rdar87914343 branch April 1, 2022 15:22
nate-chandler added a commit to nate-chandler/swift that referenced this pull request Apr 1, 2022
Verify the behavior of swift_storeEnumTagMultiPayload in the face of
small payload sizes (8 bits) and many empty cases (more than 2^8).

Additional test of the behavior that was fixed at
swiftlang#42131
aschwaighofer added a commit to aschwaighofer/swift that referenced this pull request Aug 17, 2022
…o bits

Transfer the fix in swiftlang#42131 to the typelayout lowering code. Noticed as part of
investigating the fix for swiftlang#60590.
meg-gupta pushed a commit to meg-gupta/swift that referenced this pull request Aug 18, 2022
…o bits

Transfer the fix in swiftlang#42131 to the typelayout lowering code. Noticed as part of
investigating the fix for swiftlang#60590.
aschwaighofer added a commit to aschwaighofer/swift that referenced this pull request Aug 25, 2022
…ntimes

Older runtimes have a bug that was fixed by PR swiftlang#42131 that this test exercises.

rdar://99099912
meg-gupta pushed a commit to meg-gupta/swift that referenced this pull request Aug 27, 2022
…ntimes

Older runtimes have a bug that was fixed by PR swiftlang#42131 that this test exercises.

rdar://99099912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants