-
Couldn't load subscription status.
- Fork 25
WI #2016 Implement unreachable code detection #2023
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
| foreach (var unreachableBlockIndex in unreachableBlocks) | ||
| { | ||
| var unreachableBlock = this.CurrentProgramCfgBuilder.Cfg.AllBlocks[unreachableBlockIndex]; | ||
| this.CurrentProgramCfgBuilder.Cfg.AddUnreachableBlock(unreachableBlock); | ||
|
|
||
| var firstInstruction = unreachableBlock.Instructions.First.Value; | ||
| var diagnostic = new Diagnostic(MessageCode.Warning, firstInstruction.CodeElement.Position(), "Unreachable code detected"); | ||
| AddDiagnostic(diagnostic); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you already have the block in the previous for-loop, why do you store them in an HashSet of indexes, to get them again after?
This whole foreach could replace the unreachableBlocks.Add(block.Index); line 1352.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well not exactly, in the previous foreach, we may have duplicate of the same block so we still need the HashSet to keep track of unique unreachable blocks. But you're right, we can merge the two loops, using the HashSet only as a marker and not iterating over it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done in 2280c09.
Fix #2016.
This is a first attempt at unreachable code detection, it should be improved with the support of multiline diagnostics (see #1846) to report unreachable code ranges just like RdZ does.