Skip to content

[6.2] IRGen: Fix out-of-order task_dealloc with parameter pack metadata #81523

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

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented May 15, 2025

6.2 cherry-pick of #81516

  • Description: Fixes a miscompile resulting in a runtime crash when parameter packs are used together with async functions. On-stack packs were sometimes deallocated in the wrong order because of a bad interaction with debug info. While not specific to async functions, in a non-async function this was not actually a problem because of how LLVM lowers the instructions in question.

  • Origination: This problem has been there since parameter packs shipped in Swift 5.9.

  • Risk: Low.

  • Reviewed by: @adrian-prantl

@slavapestov slavapestov requested a review from a team as a code owner May 15, 2025 04:11
@slavapestov slavapestov changed the title IRGen: Fix out-of-order task_dealloc with parameter pack metadata [6.2] IRGen: Fix out-of-order task_dealloc with parameter pack metadata May 15, 2025
@slavapestov slavapestov force-pushed the fix-pack-task-dealloc-6.2 branch 3 times, most recently from ce40ded to 7fb678c Compare May 15, 2025 04:25
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov force-pushed the fix-pack-task-dealloc-6.2 branch from 7fb678c to 9b26ab1 Compare May 15, 2025 16:23
We deallocate an instruction's packs at points where no further
control flow path uses the value. In the case of an alloc_stack,
this will be right after the dealloc_stack. Thus, if alloc_stack
allocates some packs to build type metadata for a tuple type
that contains a pack, and then proceeds to allocate a value
large enough to hold the tuple, we will free the second allocation
first, before we free the pack, as expected.

However, after stack allocating the value, alloc_stack does
some further work to emit debug info. This could result in
emission of additional metadata packs.

Split up the debug info emission into two parts; the first we do
before we perform the stack allocation, the rest we do after.

- Fixes swiftlang#67702.
- Fixes rdar://problem/141363236.
@slavapestov slavapestov force-pushed the fix-pack-task-dealloc-6.2 branch from 9b26ab1 to bf8d836 Compare May 15, 2025 16:24
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov enabled auto-merge May 15, 2025 16:46
@slavapestov slavapestov merged commit 21f3bc1 into swiftlang:release/6.2 May 16, 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