Skip to content

5.9: [MoveOnlyAddressChecker] Fix representation for initialized fields. #66960

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

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Jun 27, 2023

Description: Fix a class of miscompiles in the move-only address checker.

The move-only address checker records which instructions initialize ranges of fields of a move-only value. Previously, it recorded instructions which initialized and the initialized fields via a map from instructions to ranges of fields of the value. But a single instruction can initialize non-contiguous fields of the value being checked.

The fix is to change the the value stored corresponding to an instruction to have enough information to store all the non-contiguous fields of the value that it initializes. Here, as elsewhere, the representation of a bit vector is used.
Risk: Low. The change is straightforward and similar in spirit to #66738 and #66947 .
Scope: Narrow. This only affects move-only types.
Original PR: #66955
Reviewed By: Andrew Trick ( @atrick ), Michael Gottesman ( @gottesmm )
Testing: Added test that the move-only address checker previously miscompiled.
Resolves: rdar://111391893

@nate-chandler nate-chandler requested a review from a team as a code owner June 27, 2023 18:43
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler requested review from atrick and tbkka June 27, 2023 18:45
In preparation for having a third instance getting or creating the bits
affected by an instruction, introduce a typealias for maps
SILInstruction->SmallBitVector and a helper function that returns
a reference to the SmallBitVector for an instruction and two others that
set into those bits the bits from another bit vector or from a range.
The address checker records instructions that initialize fields in its
initInsts map.  Previously, that map mapped from an instruction to a
range of fields of the type.  But an instruction can initialize multiple
discontiguous fields of a single value.  (Indeed an attempt to add a
second range that was initialized by an already initializing
instruction--even if it were overlapping or adjacent--would have no
effect and the map wouldn't be updated.)  Here, this is fixed by fixing
the representation and updating the storage whenver a new range is seen
to be initialized by the instruction.  As in
swiftlang#66728 , a SmallBitVector is the
representation chosen.

rdar://111391893
@nate-chandler nate-chandler force-pushed the cherrypick/release/5.9/rdar111391893 branch from f4e3fce to cdf4307 Compare June 28, 2023 00:00
@nate-chandler
Copy link
Contributor Author

@swift-ci please test and merge

@swift-ci swift-ci merged commit 306a646 into swiftlang:release/5.9 Jun 28, 2023
@nate-chandler nate-chandler deleted the cherrypick/release/5.9/rdar111391893 branch July 5, 2023 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants