Skip to content

SSA: Refactor post-update support in DataFlowIntegration. - #22914

Open
aschackmull wants to merge 7 commits into
github:mainfrom
aschackmull:ssa/postupdate
Open

aschackmull wants to merge 7 commits into
github:mainfrom
aschackmull:ssa/postupdate

Conversation

@aschackmull

@aschackmull aschackmull commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Unified added ad-hoc support for post-updates in SSA DataFlowIntegration to occur later in the CFG than the corresponding reads.
This PR refactors this support to make it a more principled inclusion in the various parts of SSA.
Along the way I uncovered a bug: when a read coincides with a write in the CFG then we mistakenly used to add outgoing use-use steps from the read. Fixing this uncovered another bug in C/C++, which had accidentally relied on the faulty use-use steps to get the desired flow steps. With the help of copilot and @MathiasVP, I also added a commit to fix this.

Comment thread shared/ssa/codeql/ssa/Ssa.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.

🟡 Changes recommended

Unresolved post-update SSA defects lose mutation flow and can introduce cross-variable flow, while a missing counter expectation will fail the Rust diagnostic test.

3 open issues
What changed in this PR

Refactors post-update handling in shared SSA, moving logic out of Unified’s data-flow integration and replacing synthetic reads with explicit read-to-update associations.

Changes:

  • Adds mappings between variable reads and their post-update control-flow positions.
  • Centralizes post-update traversal in shared SSA and adds a consistency check.
  • Simplifies Unified’s SSA node mapping and local-flow integration.
File Description
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​LocalSsa.qll Supplies explicit post-update mappings and removes Unified-specific traversal workarounds.
shared/​ssa/​codeql/​ssa/​Ssa.qll Implements shared post-update handling across reference traversal, data-flow nodes, and diagnostics.

Review effort: Max

Comment thread shared/ssa/codeql/ssa/Ssa.qll Outdated
Comment thread unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.qll Outdated
Comment thread shared/ssa/codeql/ssa/Ssa.qll Outdated
@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Oct 29, 2026
Comment thread unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.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.

🟡 Changes recommended

Critical SSA defects can skip write definitions and conflate post-update nodes, producing incorrect same-variable links and pre-update read mappings.

2 open issues
3 resolved since last review

Review effort: Max

Comment thread shared/ssa/codeql/ssa/Ssa.qll Outdated
Comment on lines +1859 to +1863
exists(DfInput::Expr e1, BasicBlock bb1, int i1, BasicBlock bb2, int i2 |
result = TExprNode(e1, v_, false) and
e1.hasCfgNode(bb1, i1) and
variableReadWithPostUpdate(bb1, i1, v_, bb2, i2) and
e.hasCfgNode(bb2, i2)

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.

Irrelevant. We should get rid of getPreUpdateNode in the SSA output, since from the SSA point of view we actually want to conflate those two post-updates.

@github-actions github-actions Bot added the C++ label Oct 30, 2026
@aschackmull
aschackmull marked this pull request as ready for review October 30, 2026 11:58
@aschackmull
aschackmull requested review from a team as code owners October 30, 2026 11:58
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Oct 30, 2026

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

Unified and SSA changes LGTM

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

C++ no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants