Skip to content

Conversation

@fm-117
Copy link
Contributor

@fm-117 fm-117 commented Aug 10, 2021

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.

@fm-117 fm-117 added this to the CobolEditor milestone Aug 10, 2021
@fm-117 fm-117 requested review from delevoye and mayanje August 10, 2021 10:35
@fm-117 fm-117 self-assigned this Aug 10, 2021
@trafico-bot trafico-bot bot added the 🔍 Ready for Review Pull Request is not reviewed yet label Aug 10, 2021
mayanje
mayanje previously approved these changes Aug 12, 2021
@trafico-bot trafico-bot bot removed the 🔍 Ready for Review Pull Request is not reviewed yet label Aug 12, 2021
@trafico-bot trafico-bot bot added the 🔍 Ready for Review Pull Request is not reviewed yet label Aug 12, 2021
Comment on lines 1358 to 1366
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);
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done in 2280c09.

@trafico-bot trafico-bot bot added ⚠️ Changes requested Pull Request needs changes before it can be reviewed again and removed 🔍 Ready for Review Pull Request is not reviewed yet labels Aug 16, 2021
@trafico-bot trafico-bot bot added 🔍 Ready for Review Pull Request is not reviewed yet and removed ⚠️ Changes requested Pull Request needs changes before it can be reviewed again labels Aug 16, 2021
@fm-117 fm-117 requested review from delevoye and mayanje August 17, 2021 06:27
@trafico-bot trafico-bot bot removed the 🔍 Ready for Review Pull Request is not reviewed yet label Aug 17, 2021
@fm-117 fm-117 merged commit aea6c3c into develop Aug 17, 2021
@trafico-bot trafico-bot bot added the ✨ Merged Pull Request has been merged successfully label Aug 17, 2021
@fm-117 fm-117 deleted the 2016_DetectUnreachableCode branch August 17, 2021 10:25
@mayanje mayanje mentioned this pull request Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ Merged Pull Request has been merged successfully

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CFG Detect unreachable Code

4 participants