Skip to content

Commit d28c4fb

Browse files
authored
Merge pull request github#3202 from jbj/pathStep-join-unique
Java/C++/C#: Use `unique` to improve join order fix
2 parents 230e5a3 + 37e3bc4 commit d28c4fb

File tree

20 files changed

+134
-381
lines changed

20 files changed

+134
-381
lines changed

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplLocal.qll

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowUtil.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Node extends TNode {
4343
/**
4444
* INTERNAL: Do not use. Alternative name for `getFunction`.
4545
*/
46-
Function getEnclosingCallable() { result = this.getFunction() }
46+
final Function getEnclosingCallable() { result = unique(Function f | f = this.getFunction() | f) }
4747

4848
/** Gets the type of this node. */
4949
Type getType() { none() } // overridden in subclasses

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl2.qll

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl3.qll

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl4.qll

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,13 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22932293
* a callable is recorded by `cc`.
22942294
*/
22952295
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2296-
exists(
2297-
AccessPath ap0, Node midnode, Configuration conf, DataFlowCallable enclosing,
2298-
LocalCallContext localCC
2299-
|
2300-
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2301-
localCC = getLocalCallContext(cc, enclosing)
2296+
exists(AccessPath ap0, Node midnode, Configuration conf, LocalCallContext localCC |
2297+
midnode = mid.getNode() and
2298+
conf = mid.getConfiguration() and
2299+
cc = mid.getCallContext() and
2300+
sc = mid.getSummaryCtx() and
2301+
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2302+
ap0 = mid.getAp()
23022303
|
23032304
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23042305
ap = ap0
@@ -2331,20 +2332,6 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23312332
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
23322333
}
23332334

2334-
pragma[nomagic]
2335-
private predicate pathIntoLocalStep(
2336-
PathNodeMid mid, Node midnode, CallContext cc, DataFlowCallable enclosing, SummaryCtx sc,
2337-
AccessPath ap0, Configuration conf
2338-
) {
2339-
midnode = mid.getNode() and
2340-
cc = mid.getCallContext() and
2341-
conf = mid.getConfiguration() and
2342-
localFlowBigStep(midnode, _, _, _, conf, _) and
2343-
enclosing = midnode.getEnclosingCallable() and
2344-
sc = mid.getSummaryCtx() and
2345-
ap0 = mid.getAp()
2346-
}
2347-
23482335
pragma[nomagic]
23492336
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23502337
readDirect(node1, f, node2) and

0 commit comments

Comments
 (0)