Shared CFG: Make the init and update parts of a for loop statements#21880
Merged
owen-mc merged 3 commits intoMay 21, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the shared Control Flow Graph AST signature so for-loop initializer and update components are represented as AST nodes (not necessarily expressions), enabling languages like Go where these parts can be statements.
Changes:
- Generalize
ForStmt.getInit/getUpdatein the shared CFG AST signature fromExprtoAstNode. - Adjust Java CFG AST adapter to expose
getInit/getUpdatewith the newAstNodereturn type. - Adjust C# CFG AST adapter similarly (and align initializer access via
super).
Show a summary per file
| File | Description |
|---|---|
| shared/controlflow/codeql/controlflow/ControlFlowGraph.qll | Generalizes shared ForStmt init/update accessors to return AstNode and updates docstrings. |
| java/ql/lib/semmle/code/java/ControlFlowGraph.qll | Wraps Java ForStmt to provide AstNode-typed getInit/getUpdate implementations matching the shared signature. |
| csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll | Updates C# ForStmt adapter to return AstNode for init/update per the shared signature. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
Comment on lines
+121
to
+128
| /** 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); |
aschackmull
approved these changes
May 21, 2026
Contributor
aschackmull
left a comment
There was a problem hiding this comment.
Right, there's no real reason that these need to be Exprs, so this change makes sense.
LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is needed for Go.