Skip to content

Commit

Permalink
Refactor UnreachableBasicBlock to make it clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-mc committed Nov 14, 2024
1 parent efb34ae commit bf0fba6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions java/ql/lib/semmle/code/java/controlflow/UnreachableBlocks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ class UnreachableBasicBlock extends BasicBlock {
not this instanceof CatchClause
or
// Switch statements with a constant comparison expression may have unreachable cases.
exists(ConstSwitchStmt constSwitchStmt, BasicBlock failingCaseBlock |
failingCaseBlock = constSwitchStmt.getAFailingCase().getBasicBlock()
|
exists(ConstSwitchStmt constSwitchStmt, BasicBlock unreachableCaseBlock |
// Not accessible from the switch expression
unreachableCaseBlock = constSwitchStmt.getAFailingCase().getBasicBlock() and
// Not accessible from the successful case
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() = failingCaseBlock and
// Blocks dominated by the failing case block are unreachable
failingCaseBlock.bbDominates(this)
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() =
unreachableCaseBlock
|
// Blocks dominated by an unreachable case block are unreachable
unreachableCaseBlock.bbDominates(this)
)
}
}
Expand Down

0 comments on commit bf0fba6

Please sign in to comment.