Skip to content

IRGen: Fix out-of-order task_dealloc with parameter pack metadata #81516

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 3 commits into from
May 15, 2025

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented May 14, 2025

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.

@slavapestov slavapestov force-pushed the fix-pack-task-dealloc branch 2 times, most recently from d787293 to 8f12df2 Compare May 15, 2025 04:06
@slavapestov slavapestov marked this pull request as ready for review May 15, 2025 04:07
@slavapestov slavapestov force-pushed the fix-pack-task-dealloc branch 2 times, most recently from 074d9da to f4e0c25 Compare May 15, 2025 04:22
@slavapestov slavapestov requested a review from ktoso as a code owner May 15, 2025 04:22
@slavapestov slavapestov force-pushed the fix-pack-task-dealloc branch from f4e0c25 to ec03156 Compare May 15, 2025 04:25
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

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.
A pack archetype from an outer expansion here is treated as a scalar.
@slavapestov slavapestov force-pushed the fix-pack-task-dealloc branch from ec03156 to be860a8 Compare May 15, 2025 16:22
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov enabled auto-merge May 15, 2025 16:22
Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@slavapestov slavapestov merged commit 2eceb29 into swiftlang:main May 15, 2025
3 checks passed
hamishknight added a commit to hamishknight/swift that referenced this pull request May 22, 2025
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.

'freed pointer was not the last allocation' when using parameter pack version of existing api
2 participants