-
Notifications
You must be signed in to change notification settings - Fork 241
Fix S1854 FP: Throw should connect to outer catch #9528
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,6 +138,10 @@ private void BuildBranches(BasicBlock block) | |
| AddPredecessorsOutsideRegion(finallyBlock); | ||
| } | ||
| } | ||
| if (block.IsEnclosedIn(ControlFlowRegionKind.Catch) && block.Successors.Any(x => x.Semantics == ControlFlowBranchSemantics.Rethrow)) | ||
| { | ||
| BuildBranchesNestedCatchRethrow(block); | ||
| } | ||
|
|
||
| void AddPredecessorsOutsideRegion(BasicBlock destination) | ||
| { | ||
|
|
@@ -161,6 +165,15 @@ private void BuildBranchesFinally(BasicBlock source, ControlFlowRegion finallyRe | |
| } | ||
| } | ||
|
|
||
| private void BuildBranchesNestedCatchRethrow(BasicBlock block) | ||
| { | ||
| var reachableHandlers = block.EnclosingRegion(ControlFlowRegionKind.TryAndCatch).NestedRegion(ControlFlowRegionKind.Try).ReachableHandlers(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pavel-mikula-sonarsource I'm after asking for var reachableHandlers = block.EnclosingRegion(ControlFlowRegionKind.TryAndCatch).NestedRegion(ControlFlowRegionKind.Try).ReachableHandlers();
foreach (var catchBlock in reachableHandlers.Where(x => x.Kind == ControlFlowRegionKind.Catch && x.FirstBlockOrdinal > block.Ordinal).SelectMany(x => x.Blocks(Cfg)))
{}Also not sure what you mean neighbouring catches :/
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try
Catch Ex As IOException
Throw 'You are here, with your block.Ordinal
Catch Ex As FormatException
'This is a neighbour that you don't want to connect to. And it has FirstBlockOrdinal > block.Ordinal
End Try
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go escape, you'd need to store your
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got It!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| foreach (var catchBlock in reachableHandlers.Where(x => x.Kind == ControlFlowRegionKind.Catch && x.FirstBlockOrdinal > block.Ordinal).SelectMany(x => x.Blocks(Cfg))) | ||
| { | ||
| AddBranch(block, catchBlock); | ||
| } | ||
| } | ||
|
|
||
| private void AddBranch(BasicBlock source, BasicBlock destination) | ||
| { | ||
| blockSuccessors[source.Ordinal].Add(destination); | ||
|
|
||
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.
What about
Throwsemantics? All the UTs havethrow, butthrow new Excetion("Whaaat?", ex)should behave the sameThere 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.
fixed here #9530
Thanks @sebastien-marichal