Skip to content

Commit 46fc913

Browse files
committed
Java/C++/C#: Revert the join order fix from github#2872
This revert brings back the performance problems in `DataFlowImplLocal.qll` so they can be fixed in a different way. The fix in github#2872 was asymptotically good but had undesired overhead because it introduced another predicate in the SCC that existed purely for join ordering. I did the revert by inlining the helper predicate, eliminating the `enclosing` variable, and re-ordering the resulting lines to what they were before github#2872.
1 parent 1096e5d commit 46fc913

File tree

19 files changed

+133
-380
lines changed

19 files changed

+133
-380
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/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)