Skip to content

Commit 62d478e

Browse files
committed
C++: Fix performance of bbEntryReachesLocally
This predicate was fast with the queries and engine from 1.18. With the queries from `master` it got a bad join order in the `UninitializedLocal.ql` query, which made it take 2m34s on Wireshark. This commit decomposes `bbEntryReachesLocally` into two predicates that together take only 4s.
1 parent f4ec168 commit 62d478e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/LocalScopeVariableReachability.qll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ abstract class LocalScopeVariableReachability extends string {
9696

9797
private predicate bbEntryReachesLocally(BasicBlock bb, SemanticStackVariable v, ControlFlowNode node) {
9898
exists(int n |
99-
node = bb.getNode(n) and isSink(node, v) |
100-
not exists(int m | m < n | isBarrier(bb.getNode(m), v))
99+
node = bb.getNode(n) and
100+
isSink(node, v)
101+
|
102+
not exists(this.firstBarrierIndexIn(bb, v))
103+
or
104+
n <= this.firstBarrierIndexIn(bb, v)
101105
)
102106
}
107+
108+
private int firstBarrierIndexIn(BasicBlock bb, SemanticStackVariable v) {
109+
result = min(int m | isBarrier(bb.getNode(m), v))
110+
}
103111
}
104112

105113
/**

0 commit comments

Comments
 (0)