Repository navigation
Conversation
f3daf4e to
135d102
Compare
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>
135d102 to
67b2034
Compare
5ff21cd to
646eeee
Compare
There was a problem hiding this comment.
🟡 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. |
There was a problem hiding this comment.
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.
| MkSsaNode(SsaDefinition ssa) or | ||
| MkSsaSynthReadNode(SsaFlow::SsaSynthReadNode ssa) or |
There was a problem hiding this comment.
I believe these two cases jointly cover exactly SsaFlow::SsaNode. So they could be replaced by
MkSsaNode(SsaFlow::SsaNode ssa) or
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This looks weird to me. How can a post-update be the incoming value for an SSA write definition?
There was a problem hiding this comment.
It is indeed redundant. I got copilot to look into why it was there. It was introduced at an intermediate implementation in the use-use-flow PR, when the value of literal initialization was written to the post-update node. In the same PR we changed that to just use the original literal node for initialization, but didn't get rid of this edge. (It's always been redundant for address expressions.)
| | neverSkip | 8 | 0 | 0 | | ||
| | stateful | 8 | 0 | 0 | |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
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.
|
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>
f7d88d0 to
20ecb21
Compare


Use the shared
DataFlowIntegrationlibrary for Go’s local SSA flow, following the earlier migration toMakeSsa.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, andgo/clear-text-loggingto preserve existing behavior.Also exclude non-rvalue expressions from
IR::EvalInstruction.readsand 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.