Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 040196f

Browse files
committed
cache more basicblock predicates
1 parent 79713e0 commit 040196f

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

python/ql/lib/semmle/python/Flow.qll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,7 @@ class BasicBlock extends @py_flow_node {
10121012
}
10131013

10141014
/** Whether this basic block dominates the other */
1015-
cached
10161015
predicate dominates(BasicBlock other) {
1017-
Stages::AST::ref() and
10181016
this = other
10191017
or
10201018
this.strictlyDominates(other)
@@ -1060,7 +1058,11 @@ class BasicBlock extends @py_flow_node {
10601058
}
10611059

10621060
/** Gets a successor to this basic block */
1063-
BasicBlock getASuccessor() { result = this.getLastNode().getASuccessor().getBasicBlock() }
1061+
cached
1062+
BasicBlock getASuccessor() {
1063+
Stages::AST::ref() and
1064+
result = this.getLastNode().getASuccessor().getBasicBlock()
1065+
}
10641066

10651067
/** Gets a predecessor to this basic block */
10661068
BasicBlock getAPredecessor() { result.getASuccessor() = this }
@@ -1130,7 +1132,11 @@ class BasicBlock extends @py_flow_node {
11301132
}
11311133

11321134
/** Holds if this basic block strictly reaches the other. Is the start of other reachable from the end of this. */
1133-
predicate strictlyReaches(BasicBlock other) { this.getASuccessor+() = other }
1135+
cached
1136+
predicate strictlyReaches(BasicBlock other) {
1137+
Stages::AST::ref() and
1138+
this.getASuccessor+() = other
1139+
}
11341140

11351141
/** Holds if this basic block reaches the other. Is the start of other reachable from the end of this. */
11361142
predicate reaches(BasicBlock other) { this = other or this.strictlyReaches(other) }

python/ql/lib/semmle/python/internal/CachedStages.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ module Stages {
8080
or
8181
any(PyFlow::BasicBlock b).strictlyDominates(_)
8282
or
83-
any(PyFlow::BasicBlock b).dominates(_)
83+
any(PyFlow::BasicBlock b).strictlyReaches(_)
84+
or
85+
exists(any(PyFlow::BasicBlock b).getASuccessor())
8486
or
8587
exists(any(PyFlow::ControlFlowNode b).getScope())
8688
or

0 commit comments

Comments
 (0)