Skip to content

Commit 812a0bc

Browse files
criemenaschackmull
authored andcommitted
Address some parts of Anders' review.
1 parent 0f5dd5d commit 812a0bc

File tree

6 files changed

+53
-33
lines changed

6 files changed

+53
-33
lines changed

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ private predicate localFlowStepPlus(
917917
) and
918918
node1 != node2 and
919919
cc.validFor(node1) and
920+
not isUnreachableInCall(node1, cc.(LocalCallContextSpecificCall).getCall()) and
920921
nodeCand(node2, unbind(config))
921922
or
922923
exists(Node mid |
@@ -1733,7 +1734,7 @@ private class PathNodeSink extends PathNode, TPathNodeSink {
17331734
* a callable is recorded by `cc`.
17341735
*/
17351736
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPath ap) {
1736-
exists(LocalCallContext localCC | localCC.matchesCallContext(cc) |
1737+
exists(LocalCallContext localCC | localCC = getMatchingLocalCallContext(cc) |
17371738
localFlowBigStep(mid.getNode(), node, true, mid.getConfiguration(), localCC) and
17381739
cc = mid.getCallContext() and
17391740
ap = mid.getAp()
@@ -1744,8 +1745,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17441745
ap = node.(AccessPathNilNode).getAp()
17451746
)
17461747
or
1747-
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1748-
(
17491748
jumpStep(mid.getNode(), node, mid.getConfiguration()) and
17501749
cc instanceof CallContextAny and
17511750
ap = mid.getAp()
@@ -1755,6 +1754,8 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17551754
mid.getAp() instanceof AccessPathNil and
17561755
ap = node.(AccessPathNilNode).getAp()
17571756
or
1757+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1758+
(
17581759
contentReadStep(mid, node, ap) and cc = mid.getCallContext()
17591760
or
17601761
exists(Content f, AccessPath ap0 | contentStoreStep(mid, node, ap0, f, cc) and push(ap0, f, ap))
@@ -2236,6 +2237,8 @@ private module FlowExploration {
22362237
ap = TPartialNil(getErasedRepr(node.getType())) and
22372238
config = mid.getConfiguration()
22382239
or
2240+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
2241+
(
22392242
partialPathStoreStep(mid, _, _, node, ap) and
22402243
cc = mid.getCallContext() and
22412244
config = mid.getConfiguration()
@@ -2254,6 +2257,7 @@ private module FlowExploration {
22542257
partialPathThroughCallable(mid, node, cc, ap, config)
22552258
or
22562259
valuePartialPathThroughCallable(mid, node, cc, ap, config)
2260+
)
22572261
}
22582262

22592263
bindingset[result, i]

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl2.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ private predicate localFlowStepPlus(
917917
) and
918918
node1 != node2 and
919919
cc.validFor(node1) and
920+
not isUnreachableInCall(node1, cc.(LocalCallContextSpecificCall).getCall()) and
920921
nodeCand(node2, unbind(config))
921922
or
922923
exists(Node mid |
@@ -1733,7 +1734,7 @@ private class PathNodeSink extends PathNode, TPathNodeSink {
17331734
* a callable is recorded by `cc`.
17341735
*/
17351736
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPath ap) {
1736-
exists(LocalCallContext localCC | localCC.matchesCallContext(cc) |
1737+
exists(LocalCallContext localCC | localCC = getMatchingLocalCallContext(cc) |
17371738
localFlowBigStep(mid.getNode(), node, true, mid.getConfiguration(), localCC) and
17381739
cc = mid.getCallContext() and
17391740
ap = mid.getAp()
@@ -1744,8 +1745,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17441745
ap = node.(AccessPathNilNode).getAp()
17451746
)
17461747
or
1747-
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1748-
(
17491748
jumpStep(mid.getNode(), node, mid.getConfiguration()) and
17501749
cc instanceof CallContextAny and
17511750
ap = mid.getAp()
@@ -1755,6 +1754,8 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17551754
mid.getAp() instanceof AccessPathNil and
17561755
ap = node.(AccessPathNilNode).getAp()
17571756
or
1757+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1758+
(
17581759
contentReadStep(mid, node, ap) and cc = mid.getCallContext()
17591760
or
17601761
exists(Content f, AccessPath ap0 | contentStoreStep(mid, node, ap0, f, cc) and push(ap0, f, ap))
@@ -2236,6 +2237,8 @@ private module FlowExploration {
22362237
ap = TPartialNil(getErasedRepr(node.getType())) and
22372238
config = mid.getConfiguration()
22382239
or
2240+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
2241+
(
22392242
partialPathStoreStep(mid, _, _, node, ap) and
22402243
cc = mid.getCallContext() and
22412244
config = mid.getConfiguration()
@@ -2254,6 +2257,7 @@ private module FlowExploration {
22542257
partialPathThroughCallable(mid, node, cc, ap, config)
22552258
or
22562259
valuePartialPathThroughCallable(mid, node, cc, ap, config)
2260+
)
22572261
}
22582262

22592263
bindingset[result, i]

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl3.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ private predicate localFlowStepPlus(
917917
) and
918918
node1 != node2 and
919919
cc.validFor(node1) and
920+
not isUnreachableInCall(node1, cc.(LocalCallContextSpecificCall).getCall()) and
920921
nodeCand(node2, unbind(config))
921922
or
922923
exists(Node mid |
@@ -1733,7 +1734,7 @@ private class PathNodeSink extends PathNode, TPathNodeSink {
17331734
* a callable is recorded by `cc`.
17341735
*/
17351736
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPath ap) {
1736-
exists(LocalCallContext localCC | localCC.matchesCallContext(cc) |
1737+
exists(LocalCallContext localCC | localCC = getMatchingLocalCallContext(cc) |
17371738
localFlowBigStep(mid.getNode(), node, true, mid.getConfiguration(), localCC) and
17381739
cc = mid.getCallContext() and
17391740
ap = mid.getAp()
@@ -1744,8 +1745,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17441745
ap = node.(AccessPathNilNode).getAp()
17451746
)
17461747
or
1747-
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1748-
(
17491748
jumpStep(mid.getNode(), node, mid.getConfiguration()) and
17501749
cc instanceof CallContextAny and
17511750
ap = mid.getAp()
@@ -1755,6 +1754,8 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17551754
mid.getAp() instanceof AccessPathNil and
17561755
ap = node.(AccessPathNilNode).getAp()
17571756
or
1757+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1758+
(
17581759
contentReadStep(mid, node, ap) and cc = mid.getCallContext()
17591760
or
17601761
exists(Content f, AccessPath ap0 | contentStoreStep(mid, node, ap0, f, cc) and push(ap0, f, ap))
@@ -2236,6 +2237,8 @@ private module FlowExploration {
22362237
ap = TPartialNil(getErasedRepr(node.getType())) and
22372238
config = mid.getConfiguration()
22382239
or
2240+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
2241+
(
22392242
partialPathStoreStep(mid, _, _, node, ap) and
22402243
cc = mid.getCallContext() and
22412244
config = mid.getConfiguration()
@@ -2254,6 +2257,7 @@ private module FlowExploration {
22542257
partialPathThroughCallable(mid, node, cc, ap, config)
22552258
or
22562259
valuePartialPathThroughCallable(mid, node, cc, ap, config)
2260+
)
22572261
}
22582262

22592263
bindingset[result, i]

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl4.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ private predicate localFlowStepPlus(
917917
) and
918918
node1 != node2 and
919919
cc.validFor(node1) and
920+
not isUnreachableInCall(node1, cc.(LocalCallContextSpecificCall).getCall()) and
920921
nodeCand(node2, unbind(config))
921922
or
922923
exists(Node mid |
@@ -1733,7 +1734,7 @@ private class PathNodeSink extends PathNode, TPathNodeSink {
17331734
* a callable is recorded by `cc`.
17341735
*/
17351736
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPath ap) {
1736-
exists(LocalCallContext localCC | localCC.matchesCallContext(cc) |
1737+
exists(LocalCallContext localCC | localCC = getMatchingLocalCallContext(cc) |
17371738
localFlowBigStep(mid.getNode(), node, true, mid.getConfiguration(), localCC) and
17381739
cc = mid.getCallContext() and
17391740
ap = mid.getAp()
@@ -1744,8 +1745,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17441745
ap = node.(AccessPathNilNode).getAp()
17451746
)
17461747
or
1747-
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1748-
(
17491748
jumpStep(mid.getNode(), node, mid.getConfiguration()) and
17501749
cc instanceof CallContextAny and
17511750
ap = mid.getAp()
@@ -1755,6 +1754,8 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17551754
mid.getAp() instanceof AccessPathNil and
17561755
ap = node.(AccessPathNilNode).getAp()
17571756
or
1757+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1758+
(
17581759
contentReadStep(mid, node, ap) and cc = mid.getCallContext()
17591760
or
17601761
exists(Content f, AccessPath ap0 | contentStoreStep(mid, node, ap0, f, cc) and push(ap0, f, ap))
@@ -2236,6 +2237,8 @@ private module FlowExploration {
22362237
ap = TPartialNil(getErasedRepr(node.getType())) and
22372238
config = mid.getConfiguration()
22382239
or
2240+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
2241+
(
22392242
partialPathStoreStep(mid, _, _, node, ap) and
22402243
cc = mid.getCallContext() and
22412244
config = mid.getConfiguration()
@@ -2254,6 +2257,7 @@ private module FlowExploration {
22542257
partialPathThroughCallable(mid, node, cc, ap, config)
22552258
or
22562259
valuePartialPathThroughCallable(mid, node, cc, ap, config)
2260+
)
22572261
}
22582262

22592263
bindingset[result, i]

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl5.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ private predicate localFlowStepPlus(
917917
) and
918918
node1 != node2 and
919919
cc.validFor(node1) and
920+
not isUnreachableInCall(node1, cc.(LocalCallContextSpecificCall).getCall()) and
920921
nodeCand(node2, unbind(config))
921922
or
922923
exists(Node mid |
@@ -1733,7 +1734,7 @@ private class PathNodeSink extends PathNode, TPathNodeSink {
17331734
* a callable is recorded by `cc`.
17341735
*/
17351736
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPath ap) {
1736-
exists(LocalCallContext localCC | localCC.matchesCallContext(cc) |
1737+
exists(LocalCallContext localCC | localCC = getMatchingLocalCallContext(cc) |
17371738
localFlowBigStep(mid.getNode(), node, true, mid.getConfiguration(), localCC) and
17381739
cc = mid.getCallContext() and
17391740
ap = mid.getAp()
@@ -1744,8 +1745,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17441745
ap = node.(AccessPathNilNode).getAp()
17451746
)
17461747
or
1747-
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1748-
(
17491748
jumpStep(mid.getNode(), node, mid.getConfiguration()) and
17501749
cc instanceof CallContextAny and
17511750
ap = mid.getAp()
@@ -1755,6 +1754,8 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, AccessPat
17551754
mid.getAp() instanceof AccessPathNil and
17561755
ap = node.(AccessPathNilNode).getAp()
17571756
or
1757+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
1758+
(
17581759
contentReadStep(mid, node, ap) and cc = mid.getCallContext()
17591760
or
17601761
exists(Content f, AccessPath ap0 | contentStoreStep(mid, node, ap0, f, cc) and push(ap0, f, ap))
@@ -2236,6 +2237,8 @@ private module FlowExploration {
22362237
ap = TPartialNil(getErasedRepr(node.getType())) and
22372238
config = mid.getConfiguration()
22382239
or
2240+
not isUnreachableInCall(node, cc.(CallContextSpecificCall).getCall()) and
2241+
(
22392242
partialPathStoreStep(mid, _, _, node, ap) and
22402243
cc = mid.getCallContext() and
22412244
config = mid.getConfiguration()
@@ -2254,6 +2257,7 @@ private module FlowExploration {
22542257
partialPathThroughCallable(mid, node, cc, ap, config)
22552258
or
22562259
valuePartialPathThroughCallable(mid, node, cc, ap, config)
2260+
)
22572261
}
22582262

22592263
bindingset[result, i]

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,9 @@ private module ImplCommon {
576576
}
577577

578578
/**
579-
* Record a call site in the dataflow graph if it either improves
580-
* virtual dispatch or if we can remove unreachable edges by recoring this call site
579+
* Holds if recording a dataflow call site either improves
580+
* virtual dispatch or if we can remove unreachable edges in the dataflow graph
581+
* by recoring this call site
581582
*/
582583
cached
583584
predicate recordDataFlowCallSite(DataFlowCall call, DataFlowCallable callable) {
@@ -626,7 +627,7 @@ private module ImplCommon {
626627
* - `TSpecificCall(DataFlowCall call, int i)` : Flow entered through the `i`th
627628
* parameter at the given `call`. This call improves the set of viable
628629
* dispatch targets for at least one method call in the current callable
629-
* or helps pruning unreachable nodes from the data flow graph.
630+
* or helps to prune unreachable nodes from the data flow graph.
630631
* - `TSomeCall(ParameterNode p)` : Flow entered through parameter `p`. The
631632
* originating call does not improve the set of dispatch targets for any
632633
* method call in the current callable and was therefore not recorded.
@@ -665,24 +666,29 @@ private module ImplCommon {
665666
}
666667

667668
/**
668-
* A call context which is used to restrict local data flow nodes
669+
* A call context that is used to restrict local data flow nodes
669670
* to nodes which are actually reachable in a call context.
670671
*/
671672
abstract class LocalCallContext extends TLocalFlowCallContext {
672673
abstract string toString();
673674

674-
abstract predicate matchesCallContext(CallContext ctx);
675-
676675
abstract predicate validFor(Node n);
677676
}
678677

679-
class LocalCallContextAny extends LocalCallContext, TAnyLocalCall {
680-
override string toString() { result = "LocalCcAny" }
681-
682-
override predicate matchesCallContext(CallContext ctx) {
678+
LocalCallContext getMatchingLocalCallContext(CallContext ctx) {
679+
(
683680
not ctx instanceof CallContextSpecificCall or
684681
not exists(TSpecificLocalCall(ctx.(CallContextSpecificCall).getCall()))
685-
}
682+
) and
683+
exists(LocalCallContextAny l | result = l)
684+
or
685+
exists(LocalCallContextSpecificCall l |
686+
ctx.(CallContextSpecificCall).getCall() = l.getCall() and result = l
687+
)
688+
}
689+
690+
class LocalCallContextAny extends LocalCallContext, TAnyLocalCall {
691+
override string toString() { result = "LocalCcAny" }
686692

687693
override predicate validFor(Node n) { any() }
688694
}
@@ -701,13 +707,7 @@ private module ImplCommon {
701707

702708
override string toString() { result = "LocalCcCall(" + call + ")" }
703709

704-
override predicate matchesCallContext(CallContext ctx) {
705-
ctx.(CallContextSpecificCall).getCall() = call
706-
}
707-
708-
override predicate validFor(Node n) {
709-
hasUnreachableNode(call, n.getEnclosingCallable())
710-
}
710+
override predicate validFor(Node n) { hasUnreachableNode(call, n.getEnclosingCallable()) }
711711
}
712712

713713
/** A callable tagged with a relevant return kind. */

0 commit comments

Comments
 (0)