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

Data flow: Track call contexts in parameterValueFlow #17876

Merged
merged 3 commits into from
Nov 21, 2024

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Oct 30, 2024

When investigating a Ruby performance issue, I found that we produced some false positive return-through-parameter flow, which is because we are not tracking call contexts in the parameterValueFlow logic. This PR adds tracking of call contexts.

@hvitved hvitved changed the title Data flow: Track call contexts in parameterFlow Data flow: Track call contexts in parameterValueFlow Oct 31, 2024
@hvitved hvitved force-pushed the dataflow/param-flow-call-ctx branch from 6dd83e4 to 9037ff0 Compare October 31, 2024 08:52
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Nov 1, 2024
@hvitved hvitved marked this pull request as ready for review November 1, 2024 08:23
@hvitved hvitved requested a review from a team as a code owner November 1, 2024 08:23
Comment on lines 1443 to 1448
// call may restrict the set of call sites that can be returned to
ctx2.(CachedCallContextSensitivity::CcReturn).isReturn(callable, call)
or
// call does not restrict the set of call sites that can be returned to
not exists(CachedCallContextSensitivity::CcReturn ret | ret.isReturn(callable, call)) and
CachedCallContextSensitivity::viableImplNotCallContextReducedReverse(ctx2)
Copy link
Contributor

Choose a reason for hiding this comment

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

This calculation that derives ctx2 from the (callable, call) pair is a deflating calculation, so it'll be more efficient to do it earlier. We can push it all the way into argumentValueFlowsThrough0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it already exists as a bindingset-annotated predicate: getCallContextReturn, so no need to duplicate that logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

One simplification suggested, otherwise LGTM.

Cand::argumentValueFlowsThroughCand(arg, _, _)
}

pragma[nomagic]
private predicate argumentValueFlowsThrough0(
DataFlowCall call, ArgNode arg, ReturnKind kind, ReadStepTypesOption read, string model
DataFlowCall call, DataFlowCallable callable, ArgNode arg, ReturnKind kind,
Copy link
Contributor

Choose a reason for hiding this comment

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

The callable column is unused and can be pushed into the exists.


pragma[nomagic]
private predicate argumentValueFlowsThrough(
DataFlowCall call, DataFlowCallable callable, ArgNode arg, ReadStepTypesOption read,
Copy link
Contributor

Choose a reason for hiding this comment

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

The call column can be pushed into the exists here.

@@ -628,6 +628,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
override string toString() {
exists(DataFlowCall call | this = TReturn(_, call) | result = "CcReturn(" + call + ")")
}

predicate isReturn(DataFlowCallable c, DataFlowCall call) { this = TReturn(c, call) }
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed now.

@hvitved hvitved merged commit 6dc599c into github:main Nov 21, 2024
35 checks passed
@hvitved hvitved deleted the dataflow/param-flow-call-ctx branch November 21, 2024 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataFlow Library Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants