From f11b5ab42f302e138eaf87d9a9ab613a12da0a36 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Sat, 1 Dec 2018 16:36:49 +0000 Subject: [PATCH] Python ESSA: Fix performance of PythonSsaSourceVariable.hasRefinementEdge() --- .../semmle/python/dataflow/SsaDefinitions.qll | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/python/ql/src/semmle/python/dataflow/SsaDefinitions.qll b/python/ql/src/semmle/python/dataflow/SsaDefinitions.qll index d6d49949053..c605b3d973f 100644 --- a/python/ql/src/semmle/python/dataflow/SsaDefinitions.qll +++ b/python/ql/src/semmle/python/dataflow/SsaDefinitions.qll @@ -79,24 +79,12 @@ abstract class PythonSsaSourceVariable extends SsaSourceVariable { } override predicate hasRefinementEdge(ControlFlowNode use, BasicBlock pred, BasicBlock succ) { + test_contains(pred.getLastNode(), use) and use.(NameNode).uses(this) and - exists(ControlFlowNode test | - test.getAChild*() = use and - test.isBranch() and - test = pred.getLastNode() - ) and - (pred.getAFalseSuccessor() = succ or pred.getATrueSuccessor() = succ) - and + (pred.getAFalseSuccessor() = succ or pred.getATrueSuccessor() = succ) and /* There is a store to this variable -- We don't want to refine builtins */ - exists(this.(Variable).getAStore()) and - /* There is at least one use or definition of the variable that is reachable by the test */ - exists(ControlFlowNode n | - n = this.getAUse() or - this.hasDefiningNode(n) | - pred.(ConditionBlock).strictlyReaches(n.getBasicBlock()) - ) + exists(this.(Variable).getAStore()) } - override ControlFlowNode getASourceUse() { result.(NameNode).uses(this) or