mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Merge pull request #17988 from owen-mc/java/fix-unreachable-blocks-in-const-switch-stmt
Java: fix unreachable basic blocks in const switch stmt
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
category: minorAnalysis
|
||||||
|
---
|
||||||
|
* In a switch statement with a constant switch expression, all non-matching cases were being marked as unreachable, including those that can be reached by falling through from the matching case. This has now been fixed.
|
||||||
@@ -217,13 +217,15 @@ class UnreachableBasicBlock extends BasicBlock {
|
|||||||
not this instanceof CatchClause
|
not this instanceof CatchClause
|
||||||
or
|
or
|
||||||
// Switch statements with a constant comparison expression may have unreachable cases.
|
// Switch statements with a constant comparison expression may have unreachable cases.
|
||||||
exists(ConstSwitchStmt constSwitchStmt, BasicBlock failingCaseBlock |
|
exists(ConstSwitchStmt constSwitchStmt, BasicBlock unreachableCaseBlock |
|
||||||
failingCaseBlock = constSwitchStmt.getAFailingCase().getBasicBlock()
|
// Not accessible from the switch expression
|
||||||
|
|
unreachableCaseBlock = constSwitchStmt.getAFailingCase().getBasicBlock() and
|
||||||
// Not accessible from the successful case
|
// Not accessible from the successful case
|
||||||
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() = failingCaseBlock and
|
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() =
|
||||||
// Blocks dominated by the failing case block are unreachable
|
unreachableCaseBlock
|
||||||
constSwitchStmt.getAFailingCase().getBasicBlock().bbDominates(this)
|
|
|
||||||
|
// Blocks dominated by an unreachable case block are unreachable
|
||||||
|
unreachableCaseBlock.bbDominates(this)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
| unreachableblocks/Unreachable.java:12:22:14:3 | { ... } |
|
| unreachableblocks/Unreachable.java:12:22:14:3 | { ... } |
|
||||||
| unreachableblocks/Unreachable.java:17:3:17:9 | case ... |
|
| unreachableblocks/Unreachable.java:17:3:17:9 | case ... |
|
||||||
| unreachableblocks/Unreachable.java:19:3:19:9 | case ... |
|
| unreachableblocks/Unreachable.java:19:3:19:9 | case ... |
|
||||||
| unreachableblocks/Unreachable.java:22:3:22:9 | case ... |
|
|
||||||
| unreachableblocks/Unreachable.java:24:3:24:9 | case ... |
|
| unreachableblocks/Unreachable.java:24:3:24:9 | case ... |
|
||||||
| unreachableblocks/Unreachable.java:26:3:26:10 | case ... |
|
| unreachableblocks/Unreachable.java:26:3:26:10 | case ... |
|
||||||
| unreachableblocks/Unreachable.java:27:3:27:10 | default |
|
| unreachableblocks/Unreachable.java:27:3:27:10 | default |
|
||||||
|
|||||||
Reference in New Issue
Block a user