[5.5][SILGen] Fix a miscompile when emitting the application of a wrapped parameter #37323
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.
Cherry-pick of #37301
Explanation: Extending property wrappers to parameters added a new way to invoke property wrapper generator functions. When emitting a call to the generator function for wrapped parameters, SILGen passed down the
SGFContext
when emitting the r-value of the argument. This caused a miscompile when the argument was an address-only type (e.g. a resilient type), because the argument was incorrectly initialized in place using the context, which was meant for the result of the generator function. The caller ended up overwriting the initialization with the result of the generator function anyway, and the r-value of the argument was never emitted, which violated ownership rules. The solution is to simply not pass down the context when emitting the argument.Scope: The scope is limited to property wrappers on function and closure parameters.
Risk: Low risk.
SGFContext
is just an optimization, so not including it will not impact the correctness of emitting an r-value.Testing: Added an automated test to ensure that the problematic case does not violate any ownership rules. Without this change, the added test trips up the SIL verifier with
SIL verification failed: Found mutating or consuming use of an in_guaranteed parameter?!: !ImmutableAddressUseVerifier().isMutatingOrConsuming(fArg)
.Reviewer: @slavapestov
Resolves: rdar://77572130