Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ssa: Trim the use-use relation to skip irrelevant nodes #19044

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

aschackmull
Copy link
Contributor

This PR contains 3 tweaks to the shared SSA use-use step relation in the data flow integration module. Each of them trims the step relation in order to generate fewer nodes and fewer edges.

  • WriteDefinitions are skipped for Java. There should be no need to include an extra node in the step from the RHS of an assignment to the first use of the variable, but some languages may depend on the flow out of definitions for now, so so far this is opt-in only.
  • Synthetic reads on the input edges to phi nodes are necessary for proper BarrierGuards. But it's only a fraction of them that are actually potentially needed by any guard, so we can restrict their creation quite a bit. Furthermore, I've added a hook to allow certain SSA usages to skip these nodes entirely if BarrierGuards are not going to be used. I expect to use this option in the VariableCapture use-case.
  • Finally, phi nodes only exist as intermediate nodes to prevent blow-ups in the number of edges, so if the successor is unique, we can safely skip the phi node.

@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Mar 17, 2025
@Copilot Copilot bot review requested due to automatic review settings March 17, 2025 13:08
@aschackmull aschackmull requested a review from a team as a code owner March 17, 2025 13:08

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (2)
  • java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll: Language not supported
  • shared/ssa/codeql/ssa/Ssa.qll: Language not supported

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

@github-actions github-actions bot added the Java label Mar 17, 2025
@aschackmull aschackmull requested review from a team as code owners March 18, 2025 09:44
@github-actions github-actions bot added C# Ruby Rust Pull requests that update Rust code labels Mar 18, 2025
@geoffw0
Copy link
Contributor

geoffw0 commented Mar 18, 2025

Looking at the DCA runs:

  • CPP has 4 new and 4 lost results for cpp/invalid-pointer-deref. They're not just moved results. I'm not sure what's going on with these.
  • Rust shows a large increase in data flow inconsistencies, which should be understood before we merge this. There's also a small (but surprising) improvement to taint reach and a 3.8% analysis slowdown (I'm not sure if either is significant).
  • Swift hasn't been run (yet)

I'm a bit surprised because from the PR description I wasn't expecting to see changes in results.

@aschackmull
Copy link
Contributor Author

I've restarted dca after fixing a performance bug, the 3.8% slowdown on Rust is now 0.1% instead. As for the data flow inconsistencies (for e.g. Rust), these were fixed by the commit "SSA: Skip identity steps".

There should be no need to run dca for Swift, since Swift doesn't use the Data Flow Integration module.

As I mentioned on slack, result changes should not occur, but they do for C++ due to the somewhat ad-hoc DataFlow::flowsToBackEdge barrier, which breaks the SSA abstraction boundary somewhat.

@aschackmull
Copy link
Contributor Author

Hmm, looks like at least Java needs some tweaking before this can work as intended. The dependence of the trimming on guard.controls causes the SSA stage to collapse with range analysis. And the C++ situation also needs some additional thought to address the result differences. Let me put this in draft for now.

@aschackmull aschackmull marked this pull request as draft March 18, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# Java no-change-note-required This PR does not need a change note Ruby Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants