Skip to content

Cfg: Add support for unless and until statements#21980

Open
aschackmull wants to merge 2 commits into
github:mainfrom
aschackmull:cfg/unless-until
Open

Cfg: Add support for unless and until statements#21980
aschackmull wants to merge 2 commits into
github:mainfrom
aschackmull:cfg/unless-until

Conversation

@aschackmull

Copy link
Copy Markdown
Contributor

This adds support for unless and until statements (motivated by Ruby). The unless statements are particularly simple, since they're merely if statements without a then branch.

@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Jun 12, 2026
Copilot AI review requested due to automatic review settings June 12, 2026 11:58
@aschackmull aschackmull requested review from a team as code owners June 12, 2026 11:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UntilStmt and treat it analogously to WhileStmt (with inverted condition semantics).
  • Updates IfStmt CFG construction to handle conditionals with missing then branches (supporting unless-style constructs).
  • Adds placeholder UntilStmt bindings 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 michaelnebel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Easy to review after your CFG talk 😄

@owen-mc owen-mc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame that it needs a little bit of boilerplate for languages that don't have this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# Java no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants