Skip to content

Commit c6016bb

Browse files
committed
Java/C++/C#: Improve join-order in pathStep predicate
1 parent ecad925 commit c6016bb

File tree

19 files changed

+361
-133
lines changed

19 files changed

+361
-133
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,11 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22572257
* a callable is recorded by `cc`.
22582258
*/
22592259
private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCtx sc, AccessPath ap) {
2260-
exists(LocalCallContext localCC, AccessPath ap0, Node midnode, Configuration conf |
2261-
midnode = mid.getNode() and
2262-
conf = mid.getConfiguration() and
2263-
cc = mid.getCallContext() and
2264-
sc = mid.getSummaryCtx() and
2265-
localCC = getLocalCallContext(cc, midnode.getEnclosingCallable()) and
2266-
ap0 = mid.getAp()
2260+
exists(
2261+
AccessPath ap0, Node midnode, Configuration conf, Callable enclosing, LocalCallContext localCC
2262+
|
2263+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2264+
localCC = getLocalCallContext(cc, enclosing)
22672265
|
22682266
localFlowBigStep(midnode, node, true, conf, localCC) and
22692267
ap = ap0
@@ -2297,6 +2295,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972295
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982296
}
22992297

2298+
pragma[nomagic]
2299+
private predicate pathIntoLocalStep(
2300+
PathNodeMid mid, Node midnode, CallContext cc, Callable enclosing, SummaryCtx sc, AccessPath ap0,
2301+
Configuration conf
2302+
) {
2303+
midnode = mid.getNode() and
2304+
cc = mid.getCallContext() and
2305+
conf = mid.getConfiguration() and
2306+
localFlowBigStep(midnode, _, _, conf, _) and
2307+
enclosing = midnode.getEnclosingCallable() and
2308+
sc = mid.getSummaryCtx() and
2309+
ap0 = mid.getAp()
2310+
}
2311+
23002312
pragma[nomagic]
23012313
private predicate readCand(Node node1, Content f, Node node2, Configuration config) {
23022314
readDirect(node1, f, node2) and

0 commit comments

Comments
 (0)