Skip to content

Commit bf0fba6

Browse files
committed
Refactor UnreachableBasicBlock to make it clearer
1 parent efb34ae commit bf0fba6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

java/ql/lib/semmle/code/java/controlflow/UnreachableBlocks.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,15 @@ class UnreachableBasicBlock extends BasicBlock {
217217
not this instanceof CatchClause
218218
or
219219
// Switch statements with a constant comparison expression may have unreachable cases.
220-
exists(ConstSwitchStmt constSwitchStmt, BasicBlock failingCaseBlock |
221-
failingCaseBlock = constSwitchStmt.getAFailingCase().getBasicBlock()
222-
|
220+
exists(ConstSwitchStmt constSwitchStmt, BasicBlock unreachableCaseBlock |
221+
// Not accessible from the switch expression
222+
unreachableCaseBlock = constSwitchStmt.getAFailingCase().getBasicBlock() and
223223
// Not accessible from the successful case
224-
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() = failingCaseBlock and
225-
// Blocks dominated by the failing case block are unreachable
226-
failingCaseBlock.bbDominates(this)
224+
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() =
225+
unreachableCaseBlock
226+
|
227+
// Blocks dominated by an unreachable case block are unreachable
228+
unreachableCaseBlock.bbDominates(this)
227229
)
228230
}
229231
}

0 commit comments

Comments
 (0)