Skip to content

C++: Fix return type of DataFlow::parameterNode - #23288

Open
MathiasVP wants to merge 4 commits into
github:mainfrom
MathiasVP:fix-parameter-node-for-reference-parameters
Open

MathiasVP wants to merge 4 commits into
github:mainfrom
MathiasVP:fix-parameter-node-for-reference-parameters

Conversation

@MathiasVP

Copy link
Copy Markdown
Contributor

Given a reference parameter int& r we have two parameter nodes:

  • One parameter for the reference (i.e., "the pointer"), and
  • one parameter for what r points to (i.e., "the indirection of the pointer")

Very early on when we introduced indirections into dataflow "someone" decided that it would make porting queries easier if we modified the behavior of Node.asParameter so that the indirect parameter node was the node for which Node.asParameter gave back the indirection.

No one has really complained about this, and it did reduce the amount of rewrites we had to do in queries so it was probably the right thing to do. However, we never updated the return type of the inverse predicate parameterNode which maps a Parameter to its dataflow node. So for references this predicate would sometimes not have a result.

This PR fixes that. It's a one-line fix, but most of the work involves adding tests around the fix so we can actually observe the effects of the change.

@MathiasVP
MathiasVP requested a review from a team as a code owner November 27, 2026 14:42
Copilot AI adaptive review requested due to automatic review settings November 27, 2026 14:42

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.

🟢 Approval recommended

No active review issues are recorded for the C++ data-flow parameter-mapping fix.

No open issues 🎉

What changed in this PR

Fixes C++ data-flow parameterNode so reference parameters map to the indirect nodes returned by Node.asParameter.

Changes:

  • Widens the return type to ParameterNode and uses asParameter() for the mapping.
  • Extends the test query to check parameter mappings and node counts.
  • Adds regression cases for value, pointer, and reference parameters.
File Description
cpp/​ql/​test/​library-tests/​dataflow/​asExpr/​test.ql Adds checks for asParameter and parameterNode.
cpp/​ql/​test/​library-tests/​dataflow/​asExpr/​test.cpp Adds expected mappings for several parameter types.
cpp/​ql/​lib/​semmle/​code/​cpp/​ir/​dataflow/​internal/​DataFlowNodes.qll Corrects the return type and mapping of parameterNode.

Review effort: Balanced (adaptive)

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

LGTM if DCA is happy.

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.

3 participants