Skip to content

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Sep 16, 2025

Before this PR, SSA assignment definitions like x = y would use the control-flow node of x as the point where the assignment happens. This works most of the time, except when the assignee also occurs in the RHS, e.g. x = x + 1, because we evaluate assignments left-to-right.

This PR changes the above to instead use the control-flow node for the assignment itself (which comes after x and y in the control flow graph; all expressions are post-order).

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Sep 16, 2025
@hvitved hvitved force-pushed the rust/ssa-adjust-write-note branch from 926006e to 7cac226 Compare September 16, 2025 11:06
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Looks plausible, fixes my issue, I'd like to see the results of the DCA run before merging...

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

DCA LGTM. We can ignore the RequestForgery.ql test failure, that is unrelated and has been fixed on main.

@hvitved hvitved added the no-change-note-required This PR does not need a change note label Sep 17, 2025
@hvitved hvitved marked this pull request as ready for review September 17, 2025 07:25
@hvitved hvitved requested a review from a team as a code owner September 17, 2025 07:25
@Copilot Copilot AI review requested due to automatic review settings September 17, 2025 07:25
@hvitved hvitved merged commit a7173e0 into github:main Sep 17, 2025
22 of 23 checks passed
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adjusts SSA write node handling for assignments to use the control-flow node of the assignment expression itself rather than the control-flow node of the left-hand side variable. This change ensures proper ordering when the assignee appears in both the left-hand side and right-hand side of an assignment (e.g., x = x + 1).

Key changes:

  • Modified SSA write node tracking to use assignment expression CFG nodes instead of left-hand side variable CFG nodes
  • Added test case for self-assignment (x2 = x2) to verify the fix
  • Updated several library functions to support the new write node structure

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/ql/test/library-tests/variables/main.rs Added test case for self-assignment to verify SSA ordering
rust/ql/test/library-tests/variables/variables.expected Updated expected test results with new SSA node numbering
rust/ql/test/library-tests/variables/CONSISTENCY/PathResolutionConsistency.expected Updated line number references due to test additions
rust/ql/src/queries/unusedentities/UnusedValue.ql Updated to use new variableWrite predicate signature
rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll Enhanced VariableWriteAccess to track the assignment expression
rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll Modified variableWrite predicate to separate write node from access node
rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Updated to use getWriteAccess instead of getControlFlowNode
rust/ql/lib/codeql/rust/dataflow/Ssa.qll Enhanced WriteDefinition to properly handle assignment expressions
rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll Added AssignmentExprChildMapping for proper CFG node handling
rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll Added new CFG node classes for variable accesses and assignments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants