6.1: [OSSACanonicalizeOwned] Fix liveness passed to completion. #78674
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.
Explanation: Fix a use-after-free on dead-end paths.
To ensure that it doesn't illegally hoist the destroys of any values across deinit barriers,
CopyPropagation
'sOSSACanonicalizeOwned
utility must add to liveness instructions at the end of a value's lifetime on every path. Concretely, the final destroys of a value are added to liveness. Until values have complete lifetimes throughout the OSSA pipeline, however, a value need not have a final destroy on a dead-end path. The utility must still add something to liveness to avoid "hoisting" a destroy from "the end of the dead-end path" to somewhere above it. To find the appropriate instructions to add to liveness, the utility relies onOSSACompleteLifetime
to visit the availability boundary of the value; that boundary describes where the value's lifetime ends on dead-end paths (not always simply just beforeunreachable
instructions, say).OSSACompleteLifetime
depends on an instance of liveness for its work, andOSSACanonicalizeOwned
provides it with a perturbed version of its own.OSSACanonicalizeOwned
operates on a "copy-extended value".OSSACompleteLifetime
operates on a standard OSSA value. The liveness produced byOSSACanonicalizeOwned
reflects that copy-extended-ness: it may contain consuming uses in the middle (corresponding to a consume of a copy of the base value in the middle).OSSACompleteLifetime
relies on its liveness being that for a standard OSSA value: it may not have consuming uses in the middle (that would correspond to a use-after-free). So there is a mismatch in the characteristics of the liveness produced by the former and used by the latter.Fix this by perturbing even more the copy of liveness passed from
OSSACanonicalizeOwned
toOSSACompleteLifetime
: demote consuming uses in the middle to non-consuming uses.Scope: Affects optimized code.
Issue: rdar://142846936
Original PR: #78624
Risk: Low.
Testing: Added tests.
Reviewer: Andrew Trick ( @atrick )