Skip to content

Commit ae3be0f

Browse files
authored
Merge pull request #4 from yoff/java/lightweight-IR-layer
Java: fix UnreachabaleBasicBlock
2 parents d854396 + 88fb0d5 commit ae3be0f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,12 @@ class UnreachableBasicBlock extends BasicBlock {
207207
conditionBlock.controls(this, constant.booleanNot())
208208
)
209209
or
210-
// This block is not reachable in the CFG, and is not a callable, a body of a callable, an
211-
// expression in an annotation, an expression in an assert statement, or a catch clause.
210+
// This block is not reachable in the CFG, and is not the entrypoint in a callable, an
211+
// expression in an assert statement, or a catch clause.
212212
forall(BasicBlock bb | bb = this.getABBPredecessor() | bb instanceof UnreachableBasicBlock) and
213-
not exists(Callable c | c.getBody() = this) and
214-
not this instanceof Callable and
215-
not exists(Annotation a | a.getAChildExpr*() = this) and
216-
not this.(Expr).getEnclosingStmt() instanceof AssertStmt and
217-
not this instanceof CatchClause
213+
not exists(Callable c | c.getBody().getControlFlowNode() = this.getFirstNode()) and
214+
not exists(AssertStmt a | a = this.getFirstNode().asExpr().getEnclosingStmt()) and
215+
not this.getFirstNode().asStmt() instanceof CatchClause
218216
or
219217
// Switch statements with a constant comparison expression may have unreachable cases.
220218
exists(ConstSwitchStmt constSwitchStmt, BasicBlock failingCaseBlock |
@@ -223,7 +221,7 @@ class UnreachableBasicBlock extends BasicBlock {
223221
// Not accessible from the successful case
224222
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() = failingCaseBlock and
225223
// Blocks dominated by the failing case block are unreachable
226-
constSwitchStmt.getAFailingCase().getBasicBlock().bbDominates(this)
224+
failingCaseBlock.bbDominates(this)
227225
)
228226
}
229227
}

0 commit comments

Comments
 (0)