From 62d478eab3e0bf480b4672e3b83194d66d3592a4 Mon Sep 17 00:00:00 2001 From: Jonas Jensen Date: Thu, 29 Nov 2018 15:09:53 +0100 Subject: [PATCH] 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. --- .../controlflow/LocalScopeVariableReachability.qll | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cpp/ql/src/semmle/code/cpp/controlflow/LocalScopeVariableReachability.qll b/cpp/ql/src/semmle/code/cpp/controlflow/LocalScopeVariableReachability.qll index f89171263959..bdd641f9338b 100644 --- a/cpp/ql/src/semmle/code/cpp/controlflow/LocalScopeVariableReachability.qll +++ b/cpp/ql/src/semmle/code/cpp/controlflow/LocalScopeVariableReachability.qll @@ -96,10 +96,18 @@ abstract class LocalScopeVariableReachability extends string { private predicate bbEntryReachesLocally(BasicBlock bb, SemanticStackVariable v, ControlFlowNode node) { exists(int n | - node = bb.getNode(n) and isSink(node, v) | - not exists(int m | m < n | isBarrier(bb.getNode(m), v)) + node = bb.getNode(n) and + isSink(node, v) + | + not exists(this.firstBarrierIndexIn(bb, v)) + or + n <= this.firstBarrierIndexIn(bb, v) ) } + + private int firstBarrierIndexIn(BasicBlock bb, SemanticStackVariable v) { + result = min(int m | isBarrier(bb.getNode(m), v)) + } } /**