Skip to content

Shared CFG: fix nested and self-looping goto targets - #22687

Open
owen-mc wants to merge 1 commit into
github:mainfrom
owen-mc:shared/cfg/goto-targets
Open

owen-mc wants to merge 1 commit into
github:mainfrom
owen-mc:shared/cfg/goto-targets

Conversation

@owen-mc

@owen-mc owen-mc commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Model labeled statements in the shared CFG AST signature and handle label propagation centrally:

  • propagate enclosing labels inward when matching labeled break and continue;
  • propagate goto targets outward through nested LabeledStmt nodes;
  • keep source labels direct so a goto cannot acquire multiple target labels;
  • support goto self-loops and labels nested beside the statement containing the goto.

The Go adapter now exposes direct labels only. Java uses the same shared handling for labeled breaks and continues. Other shared-CFG adapters implement the new AST signature.

Tests

The Go test checks immediate CFG successors without pre-filtering targets by label name. It covers stacked sibling labels, nested sibling labels, self-loops, and jumps to enclosing stacked labels. Go consistency queries are also enabled for the test.

@owen-mc
owen-mc requested review from a team as code owners September 28, 2026 09:37
Copilot AI balanced review requested due to automatic review settings September 28, 2026 09:37
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Sep 28, 2026
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll Fixed
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll Fixed
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll Fixed

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

External Go gotos targeting an inner stacked label still fail to connect to their destination.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Generalizes shared CFG abrupt completions to carry resolved jump targets, enabling precise Go and C# goto handling.

Changes:

  • Adds resolved JumpTarget support to the shared CFG.
  • Implements target resolution for Go and C#.
  • Adds Go regression coverage and updates other language integrations.
File Description
shared/​controlflow/​codeql/​controlflow/​ControlFlowGraph.qll Adds targeted abrupt-completion propagation.
go/​ql/​lib/​semmle/​go/​controlflow/​ControlFlowGraphImpl.qll Resolves Go goto destinations.
go/​ql/​test/​library-tests/​semmle/​go/​controlflow/​GotoTarget/​GotoTarget.ql Queries goto target reachability.
go/​ql/​test/​library-tests/​semmle/​go/​controlflow/​GotoTarget/​GotoTarget.expected Records expected test results.
go/​ql/​test/​library-tests/​semmle/​go/​controlflow/​GotoTarget/​gotos.go Supplies stacked-label test cases.
csharp/​ql/​lib/​semmle/​code/​csharp/​controlflow/​ControlFlowGraph.qll Resolves label, case, and default gotos.
java/​ql/​lib/​semmle/​code/​java/​ControlFlowGraph.qll Implements the extended shared interface.
python/​ql/​lib/​semmle/​python/​controlflow/​internal/​AstNodeImpl.qll Implements the extended shared interface.
ruby/​ql/​lib/​codeql/​ruby/​controlflow/​ControlFlowGraph.qll Implements the extended shared interface.
unified/​ql/​lib/​codeql/​unified/​internal/​ControlFlowGraph.qll Implements the extended shared interface.

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

Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll Outdated
@owen-mc
owen-mc force-pushed the shared/cfg/goto-targets branch 2 times, most recently from ba548eb to 86ead25 Compare September 28, 2026 23:43
@owen-mc
owen-mc requested a review from aschackmull September 29, 2026 08:28
@owen-mc
owen-mc force-pushed the shared/cfg/goto-targets branch from 86ead25 to 832228f Compare September 29, 2026 08:42
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll Fixed
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll Fixed
Comment thread go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll Fixed
@owen-mc
owen-mc force-pushed the shared/cfg/goto-targets branch from 832228f to 22dea67 Compare September 30, 2026 15:27
@owen-mc owen-mc changed the title Shared CFG: generalize targeted abrupt completions Shared CFG: fix nested labeled goto targets Sep 30, 2026
l = n.(Go::GotoStmt).getLabel()
}

private predicate hasLabelOrEnclosingLabel(Ast::AstNode n, Label l) {
@owen-mc owen-mc changed the title Shared CFG: fix nested labeled goto targets Shared CFG: fix nested and self-looping goto targets Sep 30, 2026
@owen-mc
owen-mc force-pushed the shared/cfg/goto-targets branch from 8e98770 to e7d3ae3 Compare September 30, 2026 15:56

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants