From c3bafc75ab5f3a6623b1c2247351159e0c7de763 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 21 May 2026 13:40:26 +0100 Subject: [PATCH 1/3] Shared CFG: allow statements for init and update of for loop --- .../controlflow/codeql/controlflow/ControlFlowGraph.qll | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll b/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll index 7a6b6318ed11..efb6be55273c 100644 --- a/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll +++ b/shared/controlflow/codeql/controlflow/ControlFlowGraph.qll @@ -118,14 +118,14 @@ signature module AstSig { /** A traditional C-style `for` loop. */ class ForStmt extends LoopStmt { - /** Gets the initializer expression of the loop at the specified (zero-based) position, if any. */ - Expr getInit(int index); + /** Gets the initializer of the loop at the specified (zero-based) position, if any. */ + AstNode getInit(int index); /** Gets the boolean condition of this `for` loop. */ Expr getCondition(); - /** Gets the update expression of this loop at the specified (zero-based) position, if any. */ - Expr getUpdate(int index); + /** Gets the update of this loop at the specified (zero-based) position, if any. */ + AstNode getUpdate(int index); } /** A for-loop that iterates over the elements of a collection. */ From 2070dafeb2a31bd5db0d2a8c8bd46515b75c7e7c Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 21 May 2026 13:41:29 +0100 Subject: [PATCH 2/3] Java: add ForStmt wrapper class --- java/ql/lib/semmle/code/java/ControlFlowGraph.qll | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/java/ql/lib/semmle/code/java/ControlFlowGraph.qll b/java/ql/lib/semmle/code/java/ControlFlowGraph.qll index 27f0102b3cfb..3407a43403e8 100644 --- a/java/ql/lib/semmle/code/java/ControlFlowGraph.qll +++ b/java/ql/lib/semmle/code/java/ControlFlowGraph.qll @@ -84,7 +84,13 @@ private module Ast implements AstSig { class DoStmt = J::DoStmt; - class ForStmt = J::ForStmt; + final private class FinalForStmt = J::ForStmt; + + class ForStmt extends FinalForStmt { + AstNode getInit(int index) { result = super.getInit(index) } + + AstNode getUpdate(int index) { result = super.getUpdate(index) } + } final private class FinalEnhancedForStmt = J::EnhancedForStmt; From 039b5927f0ebd8aee9bc7902adc8d0bc5e72e327 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 21 May 2026 13:45:30 +0100 Subject: [PATCH 3/3] C#: update ForStmt wrapper class --- .../code/csharp/controlflow/internal/ControlFlowGraph.qll | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll b/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll index ca71e213e327..7e5072637c30 100644 --- a/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll +++ b/csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll @@ -175,7 +175,9 @@ module Ast implements AstSig { final private class FinalForStmt = CS::ForStmt; class ForStmt extends FinalForStmt { - Expr getInit(int index) { result = this.getInitializer(index) } + AstNode getInit(int index) { result = super.getInitializer(index) } + + AstNode getUpdate(int index) { result = super.getUpdate(index) } } final private class FinalForeachStmt = CS::ForeachStmt;