Use a loop to avoid emitting long sequences of retags. - #163567
Merged
rust-bors[bot] merged 1 commit intoOct 5, 2026
Merged
Conversation
Member
|
@bors r+ rollup |
Contributor
rust-bors Bot
pushed a commit
that referenced
this pull request
Oct 5, 2026
Rollup merge of #163567 - BorrowSanitizer:codegen-retag-fix-loop, r=saethlin Use a loop to avoid emitting long sequences of retags. See MCP [#958](rust-lang/compiler-team#958) for context on `-Zcodegen-emit-retag`. If we need to retag an array of references, then we will retag every element of the array. This does not scale for large arrays. For example: ```rust const N: usize = 100_000; fn example(array: [&u32; N]) {} fn main() { example([&0; N]); } ``` This program will cause `rustc` to hang at `-O0` with `-Zcodegen-emit-retag`. In the body of `example`, we need to ensure that every element of `array` receives a function-entry retag, so we emit 100,000 retag function calls within a single basic block! This PR fixes this issue by adjusting how we retag the contents of arrays. Instead of retagging ever element in succession, we emit a loop that applies a single retag call to every element of the array. I have tested it on BorrowSanitizer's test suite. Also, I saw the new `#FIXME` comment about supporting `repr(simd)` types. Some of the changes that I made here will be helpful for fixing that issue in a subsequent PR. cc: @mojeanmac r? @saethlin
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.
See MCP #958 for context on
-Zcodegen-emit-retag.If we need to retag an array of references, then we will retag every element of the array. This does not scale for large arrays. For example:
This program will cause
rustcto hang at-O0with-Zcodegen-emit-retag. In the body ofexample, we need to ensure that every element ofarrayreceives a function-entry retag, so we emit 100,000 retag function calls within a single basic block!This PR fixes this issue by adjusting how we retag the contents of arrays. Instead of retagging ever element in succession, we emit a loop that applies a single retag call to every element of the array. I have tested it on BorrowSanitizer's test suite.
Also, I saw the new
#FIXMEcomment about supportingrepr(simd)types. Some of the changes that I made here will be helpful for fixing that issue in a subsequent PR.cc: @mojeanmac
r? @saethlin