Repository navigation
Fix: Keep live ranges inside the program when a branch ends it. - #7
Merged
Merged
Conversation
processBranchState ends each path's stretch of the program at the token after a branch. When the branch was the program's last token, as in the ps2gl programs that loop back with b and have no --exit block, that token was the end of the token list. Dereferencing it read past the list, and the ranges of values live across the branch ended at whatever number was there: in general.vcl, two ranges ended near 1.8 billion, a different number on each run. On macOS that number is always past every line, so the allocation came out the same, but the read is undefined behaviour and what it finds depends on the standard library and the memory layout. End the stretch at the branch itself when nothing follows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Not sure what happened with the MacOS test below, seems to have timed out and I don't think I can rerun it. I am working on a Mac, so the MacOS tests are passing.
Cheers! |
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.
RegisterAllocator::processBranchStateends each path's stretch of the program at the token after a branch. It doesToken& token = *curr; curr++;, and then, for a branch, uses&*curras the end of the path's trace and(*curr).lineNumber()in its backward-branch check. When the branch is the program's last token,curristokens.end(). The ps2gl fixtures hit this: they loop back withb main_loop_lidand have no--exitblock.Dereferencing
end()is undefined behaviour. In practice it reads whatever lies past the list's sentinel node, and the ranges of values live across the branch end at that number.--show-reg-allocontest/fixtures/general.vclshows two ranges like[271-1842013280], with a different end on each run. On macOS the number is always past every line, so the allocation comes out the same. But what the read finds depends on the standard library and the memory layout. A small value would tripassert( start <= stop )inAlias::addRange, or give an inverted range in a release build.This fix ends the stretch at the branch itself when nothing follows it (
Token& after = (curr != end) ? *curr : token;).test_trailing_branch_ranges.cppcompiles a program that ends withband checks that every range--show-reg-allocprints ends within the program. It fails without this fix.stapip_cull_td_vu1runs out of VF registers. On master, 10 of the programs print ranges that end past their last line: the ninegeneral*fixtures and ps2gl's billboard renderer. With the fix, none do.