Skip to content

Commit 0cc3218

Browse files
authored
Merge pull request #2872 from aschackmull/dataflow/pathstep-localflow-join
Java/C++/C#: Improve join-order in pathStep predicate
2 parents 2df3fe8 + 9116643 commit 0cc3218

File tree

19 files changed

+380
-133
lines changed

19 files changed

+380
-133
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,13 +2257,12 @@ 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, DataFlowCallable enclosing,
2262+
LocalCallContext localCC
2263+
|
2264+
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
2265+
localCC = getLocalCallContext(cc, enclosing)
22672266
|
22682267
localFlowBigStep(midnode, node, true, conf, localCC) and
22692268
ap = ap0
@@ -2297,6 +2296,20 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
22972296
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
22982297
}
22992298

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

0 commit comments

Comments
 (0)