From d14cf34cc6c5eaf39f95b4bb9bdd5d600eeca6cd Mon Sep 17 00:00:00 2001 From: Jonas Jensen Date: Sat, 1 Dec 2018 10:07:08 +0100 Subject: [PATCH] C++: data flow AlwaysTrueUponEntryLoop perf fix The predicate `AlwaysTrueUponEntryLoop.getARelevantVariable` was very sensitive to join ordering, and with the 1.19 QL engine it got an unfortunate join order that made it explode on certain snapshots. With this change, it goes from taking minutes to taking less than a second on a libretro-uae snapshot. --- .../semmle/code/cpp/dataflow/internal/FlowVar.qll | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll b/cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll index 1e22c1b1997e..75d5d300bae5 100644 --- a/cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll +++ b/cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll @@ -292,10 +292,7 @@ module FlowVar_internal { * Gets a variable that is assigned in this loop and read outside the loop. */ private Variable getARelevantVariable() { - exists(BasicBlock bbAssign | - assignmentLikeOperation(bbAssign.getANode(), result, _) and - this.bbInLoop(bbAssign) - ) and + result = this.getAVariableAssignedInLoop() and exists(VariableAccess va | va.getTarget() = result and readAccess(va) and @@ -303,6 +300,15 @@ module FlowVar_internal { ) } + /** Gets a variable that is assigned in this loop. */ + pragma[noinline] + private Variable getAVariableAssignedInLoop() { + exists(BasicBlock bbAssign | + assignmentLikeOperation(bbAssign.getANode(), result, _) and + this.bbInLoop(bbAssign) + ) + } + private predicate bbInLoopCondition(BasicBlock bb) { getCFNParent*(bb.getANode()) = this.(Loop).getCondition() }