Skip to content

CFG: Add a new shared inline CFG test and apply it to unified/swift - #22557

Open
aschackmull wants to merge 4 commits into
github:mainfrom
aschackmull:cfg/inline-test
Open

aschackmull wants to merge 4 commits into
github:mainfrom
aschackmull:cfg/inline-test

Conversation

@aschackmull

Copy link
Copy Markdown
Contributor

The test is structured around "basic block slices", i.e. basic blocks cut by line boundaries. Ordinary intra-block control flow is elided and so is flow from/to non-AST CFG nodes, but everything else is reported.

Basic block slices are reported by nonSimple if they aren't left-to-right in the location-induced syntax tree.
If the basic block cuts that made the slices aren't trivial (i.e. the block continues on the next line), then the link is reported by bbContinues.
All basic block steps are reported by bbStep (with purely synthetic blocks being skipped over).
Lines with AST nodes, but no CFG nodes are reported by noCfg.

Additionally, a separate query dumps all basic block slices, but that's not suitable for inline expectation.

@aschackmull
aschackmull requested a review from a team as a code owner September 14, 2026 08:54
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Sep 14, 2026
@aschackmull
aschackmull requested a review from a team as a code owner September 14, 2026 08:54
Copilot AI balanced review requested due to automatic review settings September 14, 2026 08:54
Comment on lines +134 to +136
if Input::getParent+(a2) = a1
then dir = Down()
else none()

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.

Copilot review overview

🟡 Changes recommended

Multiline CFG nodes are incorrectly excluded from slice-link and noCfg existence checks.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity

Open findings (1)
What changed in this PR

Adds shared inline CFG-test utilities and applies them to Unified Swift control-flow testing.

Changes:

  • Introduces reusable basic-block slice and CFG expectation predicates.
  • Exposes the test module through the shared CFG implementation.
  • Adds Swift fixtures, inline expectations, and generated outputs.
File Description
shared/​controlflow/​codeql/​controlflow/​test/​TestCfg.qll Implements shared CFG-test predicates.
shared/​controlflow/​codeql/​controlflow/​ControlFlowGraph.qll Exposes the inline test module.
unified/​ql/​test/​library-tests/​controlflow/​cfg.swift Adds Swift CFG fixtures and expectations.
unified/​ql/​test/​library-tests/​controlflow/​cfg.ql Imports the inline CFG test.
unified/​ql/​test/​library-tests/​controlflow/​cfg.qlref Configures expectation post-processing.
unified/​ql/​test/​library-tests/​controlflow/​cfg.expected Records generated inline-test output.
unified/​ql/​test/​library-tests/​controlflow/​basicblock-slices.ql Dumps block slices.
unified/​ql/​test/​library-tests/​controlflow/​basicblock-slices.expected Records generated slice output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread shared/controlflow/codeql/controlflow/test/TestCfg.qll

@hvitved hvitved 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.

CI is failing.

@aschackmull

Copy link
Copy Markdown
Contributor Author

CI is failing.

Should be fixed now (🤞 )

@asgerf asgerf 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.

Looks good to me in the sense that I've read through the whole thing and nothing stood out, though the code was not that easy to follow. I'll take another look tomorrow.

I suspect it could be simplified by adding a LineBlock newtype early on? Probably not worth blocking the PR but might be worth considering if it starts to get hard to maintain.

Comment thread shared/controlflow/codeql/controlflow/test/TestCfg.qll Outdated
Comment thread shared/controlflow/codeql/controlflow/test/TestCfg.qll Outdated
Co-authored-by: Anders Schack-Mulligen <aschackmull@users.noreply.github.com>
Comment thread shared/controlflow/codeql/controlflow/test/TestCfg.qll Outdated

@asgerf asgerf 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.

Thanks! I found it much easier to follow now. LGTM assuming CI turns green

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

Labels

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