mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Java: Improve precision of SuccessorType labels in CFG.
This commit is contained in:
@@ -82,6 +82,7 @@ module;
|
||||
*/
|
||||
|
||||
import java
|
||||
private import codeql.controlflow.SuccessorType
|
||||
private import codeql.util.Boolean
|
||||
private import Completion
|
||||
private import controlflow.internal.Preconditions
|
||||
@@ -124,6 +125,28 @@ module ControlFlow {
|
||||
result = succ(this, NormalCompletion())
|
||||
}
|
||||
|
||||
/** Gets an immediate successor of this node of a given type, if any. */
|
||||
Node getASuccessor(SuccessorType t) {
|
||||
result = branchSuccessor(this, t.(BooleanSuccessor).getValue())
|
||||
or
|
||||
exists(Completion completion |
|
||||
result = succ(this, completion) and
|
||||
not result = branchSuccessor(this, _)
|
||||
|
|
||||
completion = NormalCompletion() and t instanceof DirectSuccessor
|
||||
or
|
||||
completion = ReturnCompletion() and t instanceof ReturnSuccessor
|
||||
or
|
||||
completion = BreakCompletion(_) and t instanceof BreakSuccessor
|
||||
or
|
||||
completion = YieldCompletion(_) and t instanceof BreakSuccessor
|
||||
or
|
||||
completion = ContinueCompletion(_) and t instanceof ContinueSuccessor
|
||||
or
|
||||
completion = ThrowCompletion(_) and t instanceof ExceptionSuccessor
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the basic block that contains this node. */
|
||||
BasicBlock getBasicBlock() { result.getANode() = this }
|
||||
|
||||
|
||||
@@ -22,20 +22,8 @@ private module Input implements BB::InputSig<Location> {
|
||||
/** Gets the CFG scope in which this node occurs. */
|
||||
CfgScope nodeGetCfgScope(Node node) { node.getEnclosingCallable() = result }
|
||||
|
||||
private Node getASpecificSuccessor(Node node, SuccessorType t) {
|
||||
node.(ConditionNode).getABranchSuccessor(t.(BooleanSuccessor).getValue()) = result
|
||||
or
|
||||
node.getAnExceptionSuccessor() = result and t instanceof ExceptionSuccessor
|
||||
}
|
||||
|
||||
/** Gets an immediate successor of this node. */
|
||||
Node nodeGetASuccessor(Node node, SuccessorType t) {
|
||||
result = getASpecificSuccessor(node, t)
|
||||
or
|
||||
node.getASuccessor() = result and
|
||||
t instanceof DirectSuccessor and
|
||||
not result = getASpecificSuccessor(node, _)
|
||||
}
|
||||
Node nodeGetASuccessor(Node node, SuccessorType t) { result = node.getASuccessor(t) }
|
||||
|
||||
/**
|
||||
* Holds if `node` represents an entry node to be used when calculating
|
||||
|
||||
Reference in New Issue
Block a user