Skip to content

[5.5][SILGen] Fix a miscompile when emitting the application of a wrapped parameter #37323

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

Conversation

hborla
Copy link
Member

@hborla hborla commented May 7, 2021

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

… wrapped

or projected value in RValueEmitter::visitAppliedPropertyWrapperExpr
@hborla hborla requested a review from a team as a code owner May 7, 2021 19:57
@hborla
Copy link
Member Author

hborla commented May 7, 2021

@swift-ci please test

@hborla hborla added the r5.5 label May 7, 2021
@airspeedswift airspeedswift merged commit 7236117 into swiftlang:release/5.5 May 10, 2021
@hborla hborla deleted the 5.5-wrapped-parameter-miscompile branch May 10, 2021 21:52
@AnthonyLatsis AnthonyLatsis added swift 5.5 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants