From 5e5a0437e15842d9bacfe3115418417121441953 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Sat, 30 May 2026 07:27:56 +0100 Subject: [PATCH] Shared CFG: allow init stmts for IfStmt --- .../codeql/controlflow/ControlFlowGraph.qll | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll b/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll index fff877b9fcd9..68b230f735bd 100644 --- a/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll +++ b/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll @@ -95,6 +95,9 @@ signature module AstSig { Stmt getElse(); } + /** Gets the initializer of this `if` statement, if any. */ + default AstNode getIfInit(IfStmt ifstmt) { none() } + /** * A loop statement. Loop statements are further subclassed into specific * types of loops. @@ -1509,6 +1512,13 @@ module Make0 Ast> { or exists(IfStmt ifstmt | n1.isBefore(ifstmt) and + ( + n2.isBefore(getIfInit(ifstmt)) + or + not exists(getIfInit(ifstmt)) and n2.isBefore(ifstmt.getCondition()) + ) + or + n1.isAfter(getIfInit(ifstmt)) and n2.isBefore(ifstmt.getCondition()) or n1.isAfterTrue(ifstmt.getCondition()) and