mirror of
https://github.com/github/codeql.git
synced 2026-05-14 19:29:28 +02:00
Python: Extend reachability analysis with common guards
Adds `if False: ...` and `if typing.TYPE_CHECKING: ...` to the set of nodes that are unlikely to be reachable.
This commit is contained in:
@@ -2417,6 +2417,24 @@ module Reachability {
|
||||
// Exception edge from a node that is unlikely to raise
|
||||
unlikelyToRaise(node) and
|
||||
succ = node.getAnExceptionalSuccessor()
|
||||
or
|
||||
// True branch of `if False:` or `if TYPE_CHECKING:`
|
||||
isAlwaysFalseGuard(node) and
|
||||
succ = node.getATrueSuccessor()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `node` is a condition that is always `False` at runtime.
|
||||
* This covers `if False:` and `if typing.TYPE_CHECKING:`.
|
||||
*/
|
||||
private predicate isAlwaysFalseGuard(ControlFlowNode node) {
|
||||
node.getNode() instanceof False
|
||||
or
|
||||
node =
|
||||
API::moduleImport("typing")
|
||||
.getMember("TYPE_CHECKING")
|
||||
.getAValueReachableFromSource()
|
||||
.asCfgNode()
|
||||
}
|
||||
|
||||
private predicate startBbLikelyReachable(BasicBlock b) {
|
||||
|
||||
Reference in New Issue
Block a user