Skip to content

Commit ccfe9b0

Browse files
committed
Shared CFG: Add includeCallableEntry hook
1 parent 8f767af commit ccfe9b0

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

‎shared/controlflow/codeql/controlflow/ControlFlowGraph.qll‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,14 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
12041204
}
12051205

12061206
signature module InputSig2 {
1207+
/**
1208+
* Holds if control flow is constructed and reachability starts at the
1209+
* entry of `callable` in this stage.
1210+
* By default, all callable entries are included. Restricting this is useful
1211+
* for auxiliary CFG stages that are only needed for selected callables.
1212+
*/
1213+
default predicate includeCallableEntry(Callable callable) { any() }
1214+
12071215
/**
12081216
* Holds if `ast` may result in an abrupt completion `c` originating at
12091217
* `n`. The boolean `always` indicates whether the abrupt completion
@@ -1938,6 +1946,7 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
19381946
*/
19391947
private predicate defaultCfg(AstNode ast) {
19401948
hasCfg(ast) and
1949+
Input2::includeCallableEntry(getEnclosingCallable(ast)) and
19411950
not explicitStep(any(PreControlFlowNode n | n.isBefore(ast)), _)
19421951
}
19431952

@@ -1989,7 +1998,8 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
19891998

19901999
/** Holds if there is a local non-abrupt step from `n1` to `n2`. */
19912000
private predicate step(PreControlFlowNode n1, PreControlFlowNode n2) {
1992-
explicitStep(n1, n2) or defaultStep(n1, n2)
2001+
Input2::includeCallableEntry(n1.getEnclosingCallable()) and
2002+
(explicitStep(n1, n2) or defaultStep(n1, n2))
19932003
}
19942004

19952005
/**
@@ -2023,25 +2033,28 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
20232033
}
20242034

20252035
private predicate preSucc(PreControlFlowNode n1, PreControlFlowNode n2, SuccessorType t) {
2026-
step(n1, n2) and n2 = TAfterValueNode(_, t)
2027-
or
2028-
step(n1, n2) and n2.(AdditionalNode).getSuccessorType() = t
2029-
or
2030-
step(n1, n2) and
2031-
not n2 instanceof AfterValueNode and
2032-
not n2 instanceof AdditionalNode and
2033-
t instanceof DirectSuccessor
2034-
or
2035-
exists(AstNode ast, AbruptCompletion c |
2036-
last(ast, n1, c) and endAbruptCompletion(ast, n2, c) and t = c.getSuccessorType()
2036+
Input2::includeCallableEntry(n1.getEnclosingCallable()) and
2037+
(
2038+
step(n1, n2) and n2 = TAfterValueNode(_, t)
2039+
or
2040+
step(n1, n2) and n2.(AdditionalNode).getSuccessorType() = t
2041+
or
2042+
step(n1, n2) and
2043+
not n2 instanceof AfterValueNode and
2044+
not n2 instanceof AdditionalNode and
2045+
t instanceof DirectSuccessor
2046+
or
2047+
exists(AstNode ast, AbruptCompletion c |
2048+
last(ast, n1, c) and endAbruptCompletion(ast, n2, c) and t = c.getSuccessorType()
2049+
)
20372050
)
20382051
}
20392052

20402053
/** Holds if `n` is reachable from an entry node. */
20412054
cached
20422055
private predicate reachable(PreControlFlowNode n) {
20432056
Input1::cfgCachedStageRef() and
2044-
n instanceof EntryNodeImpl
2057+
Input2::includeCallableEntry(n.(EntryNodeImpl).getEnclosingCallable())
20452058
or
20462059
exists(PreControlFlowNode mid | reachable(mid) and preSucc(mid, n, _))
20472060
}

0 commit comments

Comments
 (0)