Skip to content

Go: Use DataFlowIntegration for local SSA flow - #23130

Open
owen-mc wants to merge 11 commits into
github:mainfrom
owen-mc:go/data-flow-integration
Open

owen-mc wants to merge 11 commits into
github:mainfrom
owen-mc:go/data-flow-integration

Conversation

@owen-mc

@owen-mc owen-mc commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Use the shared DataFlowIntegration library for Go’s local SSA flow, following the earlier migration to MakeSsa.

This preserves Go’s field-sensitive barrier guards and closure flow, defines SsaNode.getBasicBlock, and hides internal merge nodes from path explanations.

Because local flow now steps through SSA merge and cycle edges, adapt interface dispatch, go/impossible-interface-nil-check, and go/clear-text-logging to preserve existing behavior.

Also exclude non-rvalue expressions from IR::EvalInstruction.reads and enable SSA consistency checks (remaining single-input phi findings come from synthetic exit reads used to retain captured definitions, which will be removed soon when Go adopts to the shared variable capture library).

DCA looks neutral.

Commit-by-commit review is recommended.

@github-actions github-actions Bot added the Go label Nov 13, 2026
@owen-mc
owen-mc force-pushed the go/data-flow-integration branch from f3daf4e to 135d102 Compare November 13, 2026 16:49
owen-mc and others added 5 commits November 18, 2026 16:45
Do not treat select-receive assignment targets or other pure lvalues as variable reads in EvalInstruction.reads, matching ReadInstruction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… merges

Record pre-migration behavior across SSA merges, loops, and captured overwrites before switching local SSA flow to DataFlowIntegration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Propagate unknown or possibly nil origins through SSA cycles and uncertain writes in interface dispatch and nil checks, and exclude SSA phi definitions from cleartext logging variable sources.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the shared DataFlowIntegration library for local SSA flow while preserving Go's field-sensitive barrier guards and closure flow, hiding synthetic SSA merge nodes from paths, and defining SsaNode.getBasicBlock.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Enable shared SSA and DataFlowIntegration consistency queries and record the remaining capture-retention exit-read phi baselines.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@owen-mc
owen-mc force-pushed the go/data-flow-integration branch from 5ff21cd to 646eeee Compare November 19, 2026 09:36
@owen-mc
owen-mc marked this pull request as ready for review November 19, 2026 09:48
@owen-mc
owen-mc requested a review from a team as a code owner November 19, 2026 09:48
@owen-mc
owen-mc requested review from aschackmull and an adaptive review from Copilot November 19, 2026 09:48

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.

🟡 Changes recommended

Existing FlowSteps expectations are stale because loop-header phi edges are now retained, and the change note incorrectly claims local-flow reachability is unchanged.

2 open issues
What changed in this PR

Migrates Go’s local SSA data flow to the shared DataFlowIntegration library, building on the earlier MakeSsa migration.

Changes:

  • Connects shared SSA nodes and flow steps while preserving Go’s barrier guards and closure flow.
  • Adapts interface dispatch, nil checks, and clear-text logging to merge and cycle edges.
  • Adds regression coverage, enables SSA consistency checks, and documents the changes.
File Description
go/​ql/​test/​query-tests/​Security/​CWE-643/​CONSISTENCY/​SsaConsistency.expected Records known phi consistency diagnostics.
go/​ql/​test/​query-tests/​Security/​CWE-312/​passwords.go Tests password flow through branch merges.
go/​ql/​test/​query-tests/​Security/​CWE-312/​CleartextLogging.expected Records merged-password alerts and paths.
go/​ql/​test/​query-tests/​RedundantCode/​ImpossibleInterfaceNilCheck/​ssa.go Tests loops, typed nils, and captured writes.
go/​ql/​test/​query-tests/​RedundantCode/​ImpossibleInterfaceNilCheck/​ImpossibleInterfaceNilCheck.expected Records expected nil-check alerts.
go/​ql/​test/​library-tests/​semmle/​go/​frameworks/​Twirp/​CONSISTENCY/​SsaConsistency.expected Records Twirp phi consistency diagnostics.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​SSADataFlowIntegration/​main.go Adds merge, loop, closure, and guard fixtures.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​SSADataFlowIntegration/​HiddenNodes.ql Checks that internal SSA nodes stay hidden from paths.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​SSADataFlowIntegration/​HiddenNodes.expected Records flow counts and hidden-node checks.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​SSADataFlowIntegration/​Flows.ql Checks value flow, barriers, and node regions.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​SSADataFlowIntegration/​Flows.expected Records successful flow and region checks.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​SSADataFlowIntegration/​CONSISTENCY/​SsaConsistency.expected Records known capture-related phi diagnostics.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​InterfaceDispatch/​Targets.ql Queries viable interface-call targets.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​InterfaceDispatch/​Targets.expected Records expected dispatch targets.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​InterfaceDispatch/​main.go Adds loop and closure dispatch fixtures.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​InterfaceDispatch/​Flows.ql Runs interface-dispatch flow checks.
go/​ql/​test/​library-tests/​semmle/​go/​dataflow/​InterfaceDispatch/​Flows.expected Records no inline flow-test failures.
go/​ql/​test/​library-tests/​semmle/​go/​controlflow/​ControlFlowGraph/​CONSISTENCY/​SsaConsistency.expected Records an epilogue phi diagnostic.
go/​ql/​test/​experimental/​CWE-942/​CONSISTENCY/​SsaConsistency.expected Records a captured-variable phi diagnostic.
go/​ql/​src/​RedundantCode/​ImpossibleInterfaceNilCheck.ql Handles SSA cycles and uncertain writes.
go/​ql/​lib/​semmle/​go/​security/​CleartextLoggingCustomizations.qll Excludes phi definitions from password sources.
go/​ql/​lib/​semmle/​go/​dataflow/​SsaImpl.qll Configures and exposes shared SSA flow integration.
go/​ql/​lib/​semmle/​go/​dataflow/​internal/​DataFlowUtil.qll Consolidates barrier-node lookup.
go/​ql/​lib/​semmle/​go/​dataflow/​internal/​DataFlowPrivate.qll Uses shared flow steps and hides merge nodes.
go/​ql/​lib/​semmle/​go/​dataflow/​internal/​DataFlowNodes.qll Maps shared SSA nodes and supplies basic blocks.
go/​ql/​lib/​semmle/​go/​dataflow/​internal/​DataFlowDispatch.qll Handles cyclic flow and unknown receiver origins.
go/​ql/​lib/​semmle/​go/​controlflow/​IR.qll Restricts expression reads to rvalues.
go/​ql/​lib/​change-notes/​2026-11-18-ssa-data-flow-integration.md Documents flow and basic-block changes.
go/​ql/​consistency-queries/​SsaConsistency.ql Enables shared SSA consistency checks.

Review effort: Max (adaptive)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
category: minorAnalysis
---
* Local SSA data flow now uses the shared `DataFlowIntegration` library. `DataFlow::localFlowStep` and `TaintTracking::localTaintStep` may now step through intermediate SSA phi and synthetic merge-read nodes at control-flow joins rather than directly between uses across branches; `DataFlow::localFlow` reachability and global path explanations are unchanged.
* `DataFlow::SsaNode.getBasicBlock()` now returns the basic block of the underlying SSA definition, and `IR::EvalInstruction.reads` no longer treats `select` receive assignment targets as variable reads.

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.

DataFlow::SsaNode.getBasicBlock() now returns the basic block of the underlying SSA definition

This part of the change note is pretty poor - surely this sounds like the reasonable thing to expect, so was this a bugfix? If so, then it sounds quite minor. Is the intended audience a hypothetical custom query writer making use of DataFlow::Node.getBasicBlock? If so, does it matter to them? If it was a bugfix, then state that, otherwise it should probably just be left out. Or maybe just leave it out regardless.

Comment on lines 17 to +18
MkSsaNode(SsaDefinition ssa) or
MkSsaSynthReadNode(SsaFlow::SsaSynthReadNode ssa) or

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.

I believe these two cases jointly cover exactly SsaFlow::SsaNode. So they could be replaced by

  MkSsaNode(SsaFlow::SsaNode ssa) or

@owen-mc owen-mc Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion would drop phi definitions that the shared flow graph bypasses when their next adjacent use is unique, because they don't have a SsaFlow::SsaNode. I checked and found three places we expect to be able to find an SsaNode for a phi definition. I could change those places to use SsaDefinition directly instead, if you think it's worth it, but I'd rather do it in a follow-up PR.

|
result.asInstruction() = rhs
or
result.(PostUpdateNode).getPreUpdateNode().asInstruction() = rhs

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.

This looks weird to me. How can a post-update be the incoming value for an SSA write definition?

Comment on lines +1 to +2
| neverSkip | 8 | 0 | 0 |
| stateful | 8 | 0 | 0 |

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.

I don't get the point of this test - it looks like the sort of throwaway test that one might do to aid ones own understanding.

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

There's a bunch of consistency checks that are failing without explanation.

---
category: minorAnalysis
---
* Local SSA data flow now uses the shared `DataFlowIntegration` library. `DataFlow::localFlowStep` and `TaintTracking::localTaintStep` may now step through intermediate SSA phi and synthetic merge-read nodes at control-flow joins rather than directly between uses across branches. Local flow can also enter uncertain SSA definitions of captured variables from preceding definitions or reads. Phi and synthetic merge-read nodes are hidden from global path explanations.

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.

Let's add a bit about the actual impact: This improves performance in certain pathological cases.
(That's the point of phi-read nodes - they make the use-use step relation linear instead of quadratic for certain corner-case code patterns)

@aschackmull aschackmull 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 reasonable overall with the caveats already mentioned. I have not looked closely at the bulk of the added data flow tests - I presume you've looked at them and found them reasonable, and that's good enough for me.

@owen-mc

owen-mc commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

In the PR description I mentioned the cause for the SSA consistency check results. I can put an explanation somewhere else, but they will be removed by the next PR in this series, so I'm not sure it's worth documenting them well.

remaining single-input phi findings come from synthetic exit reads used to retain captured definitions, which will be removed soon when Go adopts to the shared variable capture library

These check that internal merge nodes remain hidden under both forced
path-node retention and stateful flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Post-update nodes on explicit SSA write RHS instructions only arise for
composite literals and address expressions, neither of which receives
post-update flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@owen-mc
owen-mc force-pushed the go/data-flow-integration branch from f7d88d0 to 20ecb21 Compare November 24, 2026 18:02

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.

4 participants