Skip to content

Commit a473565

Browse files
authored
Merge pull request #21954 from aschackmull/cfg/consistency-child-idx
Cfg: Add consistency check for relevant child indices.
2 parents 3cbc8f0 + c47135a commit a473565

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
@@ -2100,6 +2100,12 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
21002100
module Consistency {
21012101
/** Holds if the consistency query `query` has `results` results. */
21022102
query predicate consistencyOverview(string query, int results) {
2103+
query = "siblingsWithSameIndexInDefaultCfg" and
2104+
results =
2105+
strictcount(AstNode parent, AstNode child1, AstNode child2, int i |
2106+
siblingsWithSameIndexInDefaultCfg(parent, child1, child2, i)
2107+
)
2108+
or
21032109
query = "deadEnd" and results = strictcount(ControlFlowNode node | deadEnd(node))
21042110
or
21052111
query = "nonUniqueEnclosingCallable" and
@@ -2145,6 +2151,20 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
21452151
results = strictcount(ControlFlowNode node, SuccessorType t | selfLoop(node, t))
21462152
}
21472153

2154+
/**
2155+
* Holds if `parent` uses default left-to-right control flow and has
2156+
* two different children `child1` and `child2` at the same index
2157+
* `i`.
2158+
*/
2159+
query predicate siblingsWithSameIndexInDefaultCfg(
2160+
AstNode parent, AstNode child1, AstNode child2, int i
2161+
) {
2162+
defaultCfg(parent) and
2163+
getChild(parent, i) = child1 and
2164+
getChild(parent, i) = child2 and
2165+
child1 != child2
2166+
}
2167+
21482168
/**
21492169
* Holds if `node` is lacking a successor.
21502170
*

0 commit comments

Comments
 (0)