Skip to content

Investigation: switchStmt shared-CFG refactor blocked by missing prerequisite#22035

Draft
Copilot wants to merge 1 commit into
mainfrom
copilot/update-switch-stmt-usage
Draft

Investigation: switchStmt shared-CFG refactor blocked by missing prerequisite#22035
Copilot wants to merge 1 commit into
mainfrom
copilot/update-switch-stmt-usage

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

The task asks to refactor the Go switchStmt() predicate in go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll to adopt the shared CFG library's default switch handling. No code changes were made because the referenced predicate and file do not exist on this branch.

Findings

  • Missing filego/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll is absent from this branch, from main (the PR base, f0576046), and from all available git history. The Go CFG directory only contains ControlFlowGraph.qll, ControlFlowGraphImpl.qll, BasicBlocks.qll, and IR.qll.
  • No switchStmt() predicate — Go's switch CFG is built by a bespoke SwitchTree/CaseClauseTree mechanism in ControlFlowGraphImpl.qll (~lines 1076–2120) using Go's own ControlFlowTree framework.
  • Go does not instantiate the shared CFG library — although codeql/controlflow is a declared dependency in go/ql/lib/qlpack.yml, the Go CFG is entirely hand-written. Java and C# do instantiate the shared library, where the generic Switch/Case handling lives (shared/controlflow/codeql/controlflow/ControlFlowGraph.qll).

Why this is blocked

The shared library's switch handling (Switch, Case, fallsThrough, getRankedCaseCfgOrder, and the isBefore/isAfter PreControlFlowNode machinery) is integral to the shared CFG construction framework. It cannot be adopted in isolation — it requires Go's CFG to first instantiate that framework. This points to a prerequisite migration branch (introducing ControlFlowGraphShared.qll and wiring Go to the shared CFG) that is not present here.

Open questions for the reviewer

  • Is there a base/feature branch carrying the in-progress shared-CFG migration that this PR should stack on? If so, the switchStmt() refactor belongs there.
  • Otherwise, should this PR bootstrap the shared-CFG instantiation for Go? That is a substantial change beyond a surgical edit and warrants scope confirmation before proceeding.

No ControlFlowGraphShared.qll was fabricated, as doing so would produce code that does not compile against the current tree.

Original prompt

This predicate switchStmt() encodes the edges for switch statements. We should instead be using the default handling of switch statements in the shared cfg library as much as much as possible. There are some go-specific behaviours (type switches, implicit variables for type switches, no switch expression meaning an implicit true), but try to adopt the shared library where possible.

The user has attached the following file paths as relevant context:

  • go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll
  • .github/instructions/ql-files.instructions.md

Created from VS Code.

Copilot AI changed the title [WIP] Refactor switchStmt to leverage shared cfg library Investigation: switchStmt shared-CFG refactor blocked by missing prerequisite Jun 22, 2026
Copilot AI requested a review from owen-mc June 22, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants