Skip to content

Commit c47135a

Browse files
committed
Cfg: Add consistency check for relevant child indices.
1 parent ab4a575 commit c47135a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

shared/controlflow/codeql/controlflow/ControlFlowGraph.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
20902090
module Consistency {
20912091
/** Holds if the consistency query `query` has `results` results. */
20922092
query predicate consistencyOverview(string query, int results) {
2093+
query = "siblingsWithSameIndexInDefaultCfg" and
2094+
results =
2095+
strictcount(AstNode parent, AstNode child1, AstNode child2, int i |
2096+
siblingsWithSameIndexInDefaultCfg(parent, child1, child2, i)
2097+
)
2098+
or
20932099
query = "deadEnd" and results = strictcount(ControlFlowNode node | deadEnd(node))
20942100
or
20952101
query = "nonUniqueEnclosingCallable" and
@@ -2135,6 +2141,20 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
21352141
results = strictcount(ControlFlowNode node, SuccessorType t | selfLoop(node, t))
21362142
}
21372143

2144+
/**
2145+
* Holds if `parent` uses default left-to-right control flow and has
2146+
* two different children `child1` and `child2` at the same index
2147+
* `i`.
2148+
*/
2149+
query predicate siblingsWithSameIndexInDefaultCfg(
2150+
AstNode parent, AstNode child1, AstNode child2, int i
2151+
) {
2152+
defaultCfg(parent) and
2153+
getChild(parent, i) = child1 and
2154+
getChild(parent, i) = child2 and
2155+
child1 != child2
2156+
}
2157+
21382158
/**
21392159
* Holds if `node` is lacking a successor.
21402160
*

0 commit comments

Comments
 (0)