Skip to content

Commit 167c837

Browse files
authored
Merge pull request #21914 from owen-mc/shared/cfg/if-init
Shared CFG: allow init stmts for IfStmt
2 parents d11fc3a + be9c785 commit 167c837

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

shared/controlflow/codeql/controlflow/ControlFlowGraph.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ signature module AstSig<LocationSig Location> {
9595
Stmt getElse();
9696
}
9797

98+
/** Gets the initializer of `if` statement `ifstmt`, if any. */
99+
default AstNode getIfInit(IfStmt ifstmt) { none() }
100+
98101
/**
99102
* A loop statement. Loop statements are further subclassed into specific
100103
* types of loops.
@@ -1509,6 +1512,13 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
15091512
or
15101513
exists(IfStmt ifstmt |
15111514
n1.isBefore(ifstmt) and
1515+
(
1516+
n2.isBefore(getIfInit(ifstmt))
1517+
or
1518+
not exists(getIfInit(ifstmt)) and n2.isBefore(ifstmt.getCondition())
1519+
)
1520+
or
1521+
n1.isAfter(getIfInit(ifstmt)) and
15121522
n2.isBefore(ifstmt.getCondition())
15131523
or
15141524
n1.isAfterTrue(ifstmt.getCondition()) and

0 commit comments

Comments
 (0)