Skip to content

[6.2] SILGen: insert an end_lifetime in the throw-branch of a Builtin.emplace #81606

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
merged 1 commit into from
May 19, 2025

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented May 19, 2025

  • Explanation: This fixes a mis-compile which results in a program crash when using the closure-based InlineArray.init for arrays with certain non-trivial types. The move-only checker inserted a wrong destroy on the throwing path in the initializer. But this is wrong because the initializer has already cleaned up the array buffer when the closure throws. The fix is to insert an end_lifetime instruction so that the move-only checker doesn't insert a wrong destroy_addr.
  • Risk: Low. It only affects this InlineArray initializer. This is the only place where the builtin is used with a (potentially) throwing closure.
  • Testing: Tested by lit tests.
  • Issue: rdar://151461109
  • Reviewer: @atrick
  • Main branch PR: SILGen: insert an end_lifetime in the throw-branch of a Builtin.emplace #81567

…place`

When the called closure throws an error, it needs to clean up the buffer.
This means that the buffer is uninitialized at this point.

We need an `end_lifetime` so that the move-only checker doesn't insert a wrong `destroy_addr` because it thinks that the buffer is initialized.

Fixes a mis-compile.

rdar://151461109
@eeckstein eeckstein requested a review from a team as a code owner May 19, 2025 12:00
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested a review from atrick May 19, 2025 12:01
@eeckstein eeckstein enabled auto-merge May 19, 2025 19:36
@eeckstein eeckstein merged commit ecdcef8 into swiftlang:release/6.2 May 19, 2025
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.

2 participants