Skip to content

[6.0] Turn mishandled reinitialize-in-defer-after-consume cases into errors. #74170

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

jckarter
Copy link
Contributor

@jckarter jckarter commented Jun 6, 2024

Explanation: If an inout parameter's value is consumed with the consume operator and reinitialized in a defer block that also contains control flow such as if, while, switch, etc., then the compiler would miscompile the code leading to runtime memory corruption. This patch turns these mishandled cases into errors.
Scope: Prevents a miscompile by adding a diagnostic.
Issue: rdar://129303198.
Original PR: #74154
Risk: Low. Turns code that would lead to corrupt code generation into hard errors.
Testing: Swift CI, test case from bug report
Reviewer: @nate-chandler

…rors.

The handling of multi-basic-block control flow in `defer` blocks looks like it
was left incomplete and completely untested; I fixed a few obvious problems but
it still completely lacks any analysis of conditional reinitializations. For now,
change it to treat attempted reinitializations as uses-after-consumes so we raise
reliable errors now instead of emitting code that causes memory corruption at
runtime. Fixes rdar://129303198.
@jckarter jckarter requested a review from a team as a code owner June 6, 2024 04:14
@jckarter
Copy link
Contributor Author

jckarter commented Jun 6, 2024

@swift-ci Please test

@jckarter jckarter merged commit 5c6afb9 into swiftlang:release/6.0 Jun 6, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants