Cfg: Add support for unless and until statements#21980
Open
aschackmull wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds shared-CFG support for until loops and unless-style conditionals (modeled as if statements without a then branch), to enable consistent control-flow construction across language frontends (motivated by Ruby).
Changes:
- Extends the shared AST signature and CFG construction to recognize
UntilStmtand treat it analogously toWhileStmt(with inverted condition semantics). - Updates
IfStmtCFG construction to handle conditionals with missingthenbranches (supportingunless-style constructs). - Adds placeholder
UntilStmtbindings in Java and C# CFG AST adapters (as unsupported stubs) to satisfy the shared AST signature.
Show a summary per file
| File | Description |
|---|---|
| shared/controlflow/codeql/controlflow/ControlFlowGraph.qll | Adds UntilStmt to the shared AST signature and updates shared CFG edge construction for until and unless-style conditionals. |
| java/ql/lib/semmle/code/java/ControlFlowGraph.qll | Introduces a stub UntilStmt in the Java AST adapter to match the shared signature. |
| csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll | Introduces a stub UntilStmt in the C# AST adapter to match the shared signature. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 2
Comment on lines
+124
to
+125
| /** Gets the boolean condition of this `until` loop. */ | ||
| Expr getCondition(); |
Comment on lines
+1526
to
+1527
| not exists(ifstmt.getThen()) and | ||
| n2.isAfter(ifstmt) |
michaelnebel
approved these changes
Jun 12, 2026
michaelnebel
left a comment
Contributor
There was a problem hiding this comment.
LGTM!
Easy to review after your CFG talk 😄
hvitved
approved these changes
Jun 12, 2026
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 adds support for
unlessanduntilstatements (motivated by Ruby). Theunlessstatements are particularly simple, since they're merelyifstatements without athenbranch.