Skip to content

6.0: [IRGen] Deadends don't need dealloc_pack_metadata. #73236

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

nate-chandler
Copy link
Contributor

Explanation: Fix a false-positive assertion failure for variadic generics.

When a SIL instruction involving variadic generic types is lowered, pack metadata may be allocated. As an optimization, that metadata is allocated on the stack. To correctly nest these on-stack pack allocations, there are matching alloc_pack_metadata and dealloc_pack_metadata instructions.

To catch issues with bad nesting, some verification is run in asserts builds during IRGen. This patch corrects a false positive that was being flagged by that verification.

Specifically, the verification was checking that for any alloc_pack_metadata instruction for which metadata was indeed allocated during IRGen that there was at least one matching dealloc_pack_metadata instruction which would clean it up. Such a cleanup instruction need not and does not exist, however, if the alloc_pack_metadata is in a "dead end block" (all paths passing through the alloc_pack_metadata instruction end in unreachable--caused, for example, by a call to fatalError()). This patch adds a check for whether the alloc_pack_metadata instruction is in a dead end block and does not require there to be a matching dealloc_pack_metadata if so.
Scope: Affects asserts builds only. Affects variadic generic code.
Issue: rdar://125265980
Original PR: #73191
Risk: Very low. Only affects asserts builds.
Testing: Added regression test.
Reviewer: Arnold Schwaighofer ( @aschwaighofer )

There is a debug-build-only verification that is done for
alloc_pack_metadata instructions that checks that there exist paired
dealloc_pack_metadata instructions which will be keyed off of to clean
up the on-stack variadic metadata packs corresponding to (the
instruction after) the alloc_pack_metadata.

StackNesting omits the deallocation instruction (as does
PackMetadataMarkerInserter) if it would be created in a dead end block.
If all blocks in the dominance frontier of the alloc_pack_metadata
instruction are dead-end blocks, then the verification will incorrectly
fail.  It should not fail because it is not necessary to clean up the
on-stack pack metadata (or any other stack allocations) in such a case.

If all such blocks are dead-end blocks, however, the
alloc_pack_metadata's block itself is a dead-end block as well.  So
during the verification, check whether the alloc_pack_metadata occurs in
a dead-end block and do not fail verification if it does.

rdar://125265980
@nate-chandler nate-chandler requested a review from a team as a code owner April 24, 2024 23:29
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler enabled auto-merge April 24, 2024 23:40
@nate-chandler nate-chandler merged commit 327fa92 into swiftlang:release/6.0 Apr 25, 2024
@nate-chandler nate-chandler deleted the cherrypick/release/6.0/rdar125265980 branch April 25, 2024 14:00
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