Skip to content

5.9: [MoveOnlyAddressChecker] Fix representation for reinit'd fields. #66947

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 reinitialize ranges of fields of a move-only value. Previously, it recorded instructions which reinitialized and the reinitialized fields via a map from instructions to ranges of fields of the value. But a single instruction can reinitialize 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 uses. Here, the representation of a bit vector is implemented.
Risk: Low. The change is straightforward and similar in spirit to #66738 .
Scope: Narrow. This only affects move-only types.
Original PR: #66945
Reviewed By: Andrew Trick ( @atrick )
Testing: Added test that the move-only address checker previously miscompiled.
Resolves: rdar://111356251

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

@swift-ci please test

@nate-chandler nate-chandler requested review from atrick and tbkka June 27, 2023 03:55
Used the TypeTreeLeafTypeRange::setBits helper rather than looping over
the range and setting the bits in place.
In preparation to share the getOrCreateConsumingBlock functionality with
another overload of recordConsumingBlock.
The new overload iterates over the contiguous ranges in the bit vector
and calls through to the overload that takes a range.
The address checker records instructions that reinit fields in its
reinitInsts map.  Previously, that map mapped from an instruction to a
range of fields of the type.  But an instruction can use multiple
discontiguous fields of a single value.  (Indeed an attempt to add a
second range that was reinit'd by an already reinit'ing
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 reinit'd by the instruction.  As in
swiftlang#66728 , a SmallBitVector is the
representation chosen.

rdar://111356251
@nate-chandler nate-chandler force-pushed the cherrypick/release/5.9/rdar111356251 branch from b983f47 to 9570263 Compare June 27, 2023 17:57
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows platform

@nate-chandler nate-chandler merged commit acf3671 into swiftlang:release/5.9 Jun 27, 2023
@nate-chandler nate-chandler deleted the cherrypick/release/5.9/rdar111356251 branch June 27, 2023 23:32
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