Skip to content

Go: fix CFG bug - implicit field selections with depth 0 - #22670

Open
owen-mc wants to merge 2 commits into
github:mainfrom
owen-mc:go/fix/impl-field-cfg
Open

owen-mc wants to merge 2 commits into
github:mainfrom
owen-mc:go/fix/impl-field-cfg

Conversation

@owen-mc

@owen-mc owen-mc commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

This fixes a bug where CFG nodes are made for implicit field selections with depth 0 when there is a recursive struct. This bug was introduced when migrating Go to the new shared CFG library. It caused FPs in go/unreachable-statement. A test has been added to demonstrate the bug and show that it is fixed.

This does not need a change note as it is fixing an FP that hasn't been in any release.

@owen-mc
owen-mc requested a review from a team September 23, 2026 14:54
@owen-mc
owen-mc requested a review from a team as a code owner September 23, 2026 14:54
Copilot AI balanced review requested due to automatic review settings September 23, 2026 14:54
@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Sep 23, 2026
@github-actions github-actions Bot added the Go label Sep 23, 2026

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

🟢 Approval recommended

The depth guard matches CFG indexing semantics, and the regression test covers the reported false positive.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes Go CFG generation so direct field and method selections do not create invalid depth-zero implicit-field nodes, preventing false unreachable-statement alerts.

Changes:

  • Restricts implicit selections to positive depths.
  • Adds a regression test using recursive embedding.
File Description
go/​ql/​lib/​semmle/​go/​controlflow/​ControlFlowGraphImpl.qll Excludes depth-zero implicit selections.
go/​ql/​test/​query-tests/​RedundantCode/​UnreachableStatement/​main.go Tests reachability for a direct field on a recursively embedded type.

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

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

Labels

Go 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.

2 participants