Skip to content

Fix Go expression-switch CFG migration to shared library#22035

Draft
Copilot wants to merge 5 commits into
copilot/vscode-mndb17m3-9fpvfrom
copilot/update-switch-stmt-usage
Draft

Fix Go expression-switch CFG migration to shared library#22035
Copilot wants to merge 5 commits into
copilot/vscode-mndb17m3-9fpvfrom
copilot/update-switch-stmt-usage

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Continues migrating Go's expression-switch control-flow graph onto the shared CFG library (shared/controlflow), fixing correctness bugs surfaced while verifying the new graph. No change notes added, per instruction.

CFG construction

  • Exceptional-exit edges: getChild (ControlFlowGraphShared.qll) now sees through the transparent expression-switch body block so case clauses remain children of the switch. The shared library's abrupt-completion propagation walks the AST child chain, so severing it dropped panic-style edges from case bodies to the function's exceptional exit.
  • Empty-switch self-loop: simpleLeafNode (shared ControlFlowGraph.qll) now excludes Switch. A childless switch {} was merged into a single before/after node, turning its explicit before→after step into a self-loop.

Constant-case sanitizer

  • In the new CFG a case body's predecessor is the case clause's matched node, not After testExpr. isSwitchCaseTestPassingEdge now keys on pred.isAfter(cc) (public signature unchanged).
  • Its sole consumer (TaintTrackingUtil.qll) now treats the body edge as constant-sanitizing only when all of a case's test expressions are constant, since every pattern of a case shares one matched edge — preserving precision for mixed const/non-const cases.

Expected output

  • Regenerated the CFG .expected (new [match]/[no-match] case-clause nodes; fallthrough flows to the next case body).
  • Updated the five SSA .expected files: location-only relocations (structure preserved; phi nodes now sit at the merge construct).

Type-switch follow-up (investigation only)

Type switches fit the shared Switch/Case model — pattern tests are already match/no-match rather than boolean, and operand/init/default/flattened bodies map onto existing hooks. The one gap is the implicit per-case binder in switch x := y.(type), which has no unconditional slot between match and body. Recommended path: add a default-none getCaseBinding(Case) hook (mirroring getSwitchInit/fallsThrough) and then retire the bespoke typeSwitch/typeCaseClause predicates. Not implemented here.

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
Copilot AI changed the title Investigation: switchStmt shared-CFG refactor blocked by missing prerequisite Go CFG: move switch handling onto the shared CFG library Jun 23, 2026
Copilot AI changed the title Go CFG: move switch handling onto the shared CFG library Adopt shared CFG library for Go switch statements (analysis + migration plan) Jun 23, 2026
@owen-mc owen-mc changed the base branch from main to copilot/vscode-mndb17m3-9fpv June 23, 2026 12:42
Copilot AI changed the title Adopt shared CFG library for Go switch statements (analysis + migration plan) Spike: migrate Go expression-switch CFG onto the shared library (investigation, no committed changes) Jun 23, 2026
Copilot AI changed the title Spike: migrate Go expression-switch CFG onto the shared library (investigation, no committed changes) Migrate Go expression switch CFG to the shared control-flow library Jun 23, 2026
Copilot AI changed the title Migrate Go expression switch CFG to the shared control-flow library Fix Go expression-switch CFG migration to shared library Jun 23, 2026
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