Repository navigation
transform: assert that pointer-bearing selects do not reach escape analysis - #5882
Closed
davecheney wants to merge 1 commit into
Closed
davecheney wants to merge 1 commit into
davecheney wants to merge 1 commit into
Conversation
…alysis Escape analysis does not follow pointers through select instructions. It treats these uses as escaping, which can leave allocations on the heap. The passes before OptimizeAllocs do not currently produce these selects. Add an assertion to detect a pipeline change that breaks this assumption, rather than silently reducing allocation optimization.
davecheney
force-pushed
the
davecheney-check-assert-aggregate-select
branch
from
October 15, 2026 22:37
c83a995 to
0c1c658
Compare
davecheney
marked this pull request as draft
October 15, 2026 22:52
Contributor
Author
davecheney
added a commit
that referenced
this pull request
Oct 16, 2026
…ect (#5891) Escape analysis treats every select as an escape, so allocations that flow through a select stay on the heap even when nothing outside the function can see them. The frontend makes these selects for min and max on strings, and instcombine can make a select over a pointer before OptimizeAllocs runs. This came up in review of #5882, which tried to assert that no pointer-bearing select reaches escape analysis. That assumption is false, and the assertion crashes the compiler on valid Go code that calls min on a string that points to a local allocation. The better fix is to follow the select result in the same way as a bitcast, because the pointer can only leave through that result. The allocs2.go case does not show the stack allocation, because runtime.stringLess is only declared in that test. The IR cases in allocs-aggregate.ll show both the heap and the stack result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Escape analysis does not follow pointers through select instructions. It treats these uses as escaping, which can leave allocations on the heap.
The passes before OptimizeAllocs do not currently produce these selects. Add an assertion to detect a pipeline change that breaks this assumption, rather than silently reducing allocation optimization.