Python: Fix CP in pruner and cache to avoid re-evaluation.

This commit is contained in:
Mark Shannon
2019-05-15 15:25:12 +01:00
parent 75feab53db
commit d7558e8fe5
2 changed files with 13 additions and 10 deletions

View File

@@ -33,7 +33,7 @@ private AstNode toAst(ControlFlowNode n) {
*/
class ControlFlowNode extends @py_flow_node {
ControlFlowNode() {
cached ControlFlowNode() {
not Pruner::unreachable(this)
}

View File

@@ -1,5 +1,9 @@
import python
private import AST
private import Exprs
private import Stmts
private import Import
private import Operations
module Pruner {
@@ -68,8 +72,6 @@ module Pruner {
right.getBasicBlock().dominates(this.getBasicBlock())
}
override Compare getNode() { result = super.getNode() }
}
/** A control flow node corresponding to a unary not expression: (`not x`) */
@@ -152,6 +154,7 @@ module Pruner {
}
private import Comparisons
private import SSA
newtype TConstraint =
TTruthy(boolean b) { b = true or b = false }
@@ -477,7 +480,7 @@ module Pruner {
a.getValue() instanceof False and result = false
)
or
module_import(var) and result = true
module_import(asgn, var) and result = true
}
/** Gets the constraint on `var` resulting from the an assignment in `asgn` */
@@ -587,14 +590,14 @@ module Pruner {
* truthiness.
*/
predicate whitelisted(SsaVariable var) {
module_import(var)
module_import(_, var)
}
private predicate module_import(SsaVariable var) {
exists(Alias alias, UnprunedCfgNode node |
private predicate module_import(UnprunedCfgNode asgn, SsaVariable var) {
exists(Alias alias |
alias.getValue() instanceof ImportExpr and
py_ssa_defn(var, node) and
alias.getAsname() = node.getNode()
py_ssa_defn(var, asgn) and
alias.getAsname() = asgn.getNode()
)
}
}