-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CodeGen][CodeLayout] Fix segfault on access to deleted block in MBP. #142357
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
base: main
Are you sure you want to change the base?
Conversation
We have caught the bug on the custom out-of-tree backend in a ~200Kb function of ~70 basic blocks with several loops, switch instructions etc.. Any attempt to reduce the test case results in bug disappearing. I'm afraid, I'm not able to provide the reproducer / regression test for any in-tree backend in a reasonable time. |
Could you please review the PR? |
From function markBlockSuccessors, a BB can be added to BlockWorkList only when UnscheduledPredecessors reaches 0. So how was B added to BlockWorkList in the first place? |
Yes, it is a bit tricky:
Work lists might contain blocks from chains with non-zero |
Some test in flang failed. Need to be investigated. |
501954d
to
034458b
Compare
PR is ready for review. Seems like flang test is flaky. I've failed to reproduce the problem locally and it disappeared after rerun. |
Missing test |
If test is a mandatory requirement for this PR, it is ok for me to reject PR. |
Did you try llvm-reduce on it? |
Yes. No effect. I've spent ~1 day in different attempts to reduce the test case =) |
Problem 1: There is a typo which reassigns
BlockWorkList
toEHPadWorkList
on attempt to removeRemBB
from work lists.Problem 2:
Chain->UnscheduledPredecessors == 0
is an incorrect way to check whetherRemBB
is enqueued or not. The root cause is a postponed deletion ofWorkList
from already scheduled blocks inselectBestCandidateBlock
. Bug happens in the following scenario:FunctionChain
is being processed with non-zeroUnscheduledPredecessors
B'
is added to theBlockWorkList
B'
is chosen as the best successor (selectBestSuccessor
) for some another block and added intoChain
B'
is removed by tail duplicator.RemovalCallback
erroneously won't eraseB'
fromBlockWorkList
, becauseUnscheduledPredecessors
value ofFunctionChain
is not zero (and it is allowed to be non-zero).Proposed solution is to always cleanup worklists on block deletion by tail duplicator.