Java: Replace the MaD Object.clone() models with a non-aliasing value step.

This commit is contained in:
Anders Schack-Mulligen
2024-06-25 15:46:53 +02:00
parent 0fb27fb6fc
commit 12d6875cc4
4 changed files with 16 additions and 3 deletions

View File

@@ -22,6 +22,8 @@ module JavaDataFlow implements InputSig<Location> {
predicate getSecondLevelScope = Private::getSecondLevelScope/1;
predicate validParameterAliasStep = Private::validParameterAliasStep/2;
predicate mayBenefitFromCallContext = Private::mayBenefitFromCallContext/1;
predicate viableImplInCallContext = Private::viableImplInCallContext/2;

View File

@@ -400,6 +400,18 @@ class CastNode extends ExprNode {
}
}
/** Holds if `n1` is the qualifier of a call to `clone()` and `n2` is the result. */
predicate cloneStep(Node n1, Node n2) {
exists(MethodCall mc |
mc.getMethod() instanceof CloneMethod and
n1 = getInstanceArgument(mc) and
n2.asExpr() = mc
)
}
bindingset[node1, node2]
predicate validParameterAliasStep(Node node1, Node node2) { not cloneStep(node1, node2) }
private newtype TDataFlowCallable =
TSrcCallable(Callable c) or
TSummarizedCallable(SummarizedCallable c) or

View File

@@ -258,6 +258,8 @@ private predicate simpleLocalFlowStep0(Node node1, Node node2, string model) {
model = "ValuePreservingMethod"
)
or
cloneStep(node1, node2) and model = "CloneStep"
or
FlowSummaryImpl::Private::Steps::summaryLocalStep(node1.(FlowSummaryNode).getSummaryNode(),
node2.(FlowSummaryNode).getSummaryNode(), true, model)
}