Python: Remove tests for pruning in QL.

This commit is contained in:
Mark Shannon
2019-08-25 15:36:38 +01:00
parent c6c307ffef
commit f11d0638cf
14 changed files with 2 additions and 614 deletions

View File

@@ -1,79 +0,0 @@
| 8 | test | test | Truthy | test |
| 10 | test | test | Truthy | test |
| 14 | seq | seq | Truthy | test |
| 17 | seq | seq | Truthy | test |
| 21 | UnaryExpr | t1 | Falsey | test |
| 24 | t1 | t1 | Truthy | test |
| 25 | t1 | t1 | Truthy | test |
| 26 | t2 | t2 | Truthy | test |
| 29 | t2 | t2 | Truthy | test |
| 30 | t2 | t2 | Truthy | test |
| 31 | t3 | t3 | Truthy | test |
| 31 | t4 | t4 | Truthy | test |
| 32 | t3 | t3 | Truthy | test |
| 33 | t3 | t3 | Truthy | test |
| 34 | t3 | t3 | Truthy | test |
| 35 | t4 | t4 | Truthy | test |
| 36 | t5 | t5 | Truthy | test |
| 36 | t6 | t6 | Truthy | test |
| 37 | t5 | t5 | Truthy | test |
| 38 | t5 | t5 | Truthy | test |
| 39 | t6 | t6 | Truthy | test |
| 40 | t6 | t6 | Truthy | test |
| 43 | t1 | t1 | Truthy | test |
| 44 | UnaryExpr | t2 | Falsey | test |
| 47 | t1 | t1 | Truthy | test |
| 48 | t2 | t2 | Truthy | test |
| 49 | t2 | t2 | Truthy | test |
| 51 | t2 | t2 | Truthy | test |
| 52 | t2 | t2 | Truthy | test |
| 55 | seq1 | seq1 | Truthy | test |
| 57 | UnaryExpr | seq2 | Falsey | test |
| 60 | seq1 | seq1 | Truthy | test |
| 63 | seq2 | seq2 | Truthy | test |
| 66 | seq3 | seq3 | Truthy | test |
| 68 | UnaryExpr | seq4 | Falsey | test |
| 88 | UnaryExpr | x | Falsey | test |
| 90 | y | y | Truthy | test |
| 93 | UnaryExpr | x | Falsey | test |
| 95 | y | y | Truthy | test |
| 99 | another_module | another_module | Truthy | assign |
| 102 | UnaryExpr | another_module | Falsey | test |
| 107 | UnaryExpr | t1 | Falsey | test |
| 109 | t2 | t2 | Truthy | test |
| 111 | t1 | t1 | Truthy | test |
| 113 | UnaryExpr | t2 | Falsey | test |
| 117 | UnaryExpr | test | Falsey | test |
| 119 | UnaryExpr | test | Falsey | test |
| 123 | m | m | Truthy | test |
| 126 | m | m | Truthy | test |
| 158 | Compare | ps | Is not None | test |
| 160 | Compare | ps | Is None | test |
| 172 | escapes | escapes | Is None | assign |
| 177 | Compare | escapes | Is None | test |
| 191 | true12 | true12 | == 0 | assign |
| 195 | Compare | x | < 4 | test |
| 197 | Compare | x | < 4 | test |
| 201 | Compare | x | < 4 | test |
| 203 | UnaryExpr | x | < 4 | test |
| 207 | Compare | x | < 4 | test |
| 209 | Compare | x | < 4 | test |
| 215 | x | x | Truthy | test |
| 215 | y | y | Truthy | test |
| 217 | x | x | Truthy | test |
| 217 | y | y | Truthy | test |
| 219 | x | x | Truthy | test |
| 223 | y | y | Truthy | test |
| 229 | k | k | Falsey | assign |
| 230 | k | k | Truthy | test |
| 237 | k | k | == 3 | assign |
| 238 | k | k | Truthy | test |
| 245 | k | k | Is None | assign |
| 246 | k | k | Truthy | test |
| 253 | a | a | Truthy | test |
| 254 | k | k | Truthy | assign |
| 256 | k | k | Falsey | assign |
| 257 | k | k | Truthy | test |
| 264 | var | var | Truthy | assign |
| 266 | var | var | Falsey | assign |
| 267 | var | var | Truthy | test |

View File

@@ -1,14 +0,0 @@
import python
import semmle.python.Pruning
from Pruner::Constraint c, SsaVariable var, Pruner::UnprunedCfgNode node, int line, string kind
where line = node.getNode().getLocation().getStartLine() and line > 0 and
(
c = Pruner::constraintFromTest(var, node) and kind = "test"
or
c = Pruner::constraintFromAssignment(var, node) and kind = "assign"
)
select line, node.getNode().toString(), var.getId(), c, kind

View File

@@ -1,40 +0,0 @@
| 10 | test | 11 | count |
| 24 | t1 | 24 | count |
| 25 | t1 | 26 | t2 |
| 29 | t2 | 30 | BoolExpr |
| 30 | t2 | 30 | count |
| 37 | t5 | 37 | count |
| 38 | t5 | 39 | BoolExpr |
| 39 | t6 | 39 | count |
| 40 | t6 | 20 | Function boolop |
| 47 | t1 | 48 | BoolExpr |
| 47 | t1 | 51 | BoolExpr |
| 48 | t2 | 48 | count |
| 49 | t2 | 42 | Function with_splitting |
| 51 | t2 | 51 | count |
| 52 | t2 | 42 | Function with_splitting |
| 93 | UnaryExpr | 94 | count |
| 95 | y | 96 | count |
| 102 | UnaryExpr | 103 | count |
| 111 | t1 | 113 | t2 |
| 113 | UnaryExpr | 106 | Function negated_conditional_live |
| 119 | UnaryExpr | 120 | count |
| 160 | Compare | 161 | count |
| 160 | Compare | 163 | count |
| 197 | Compare | 198 | count |
| 203 | UnaryExpr | 204 | count |
| 209 | Compare | 210 | count |
| 217 | x | 217 | UnaryExpr |
| 217 | x | 217 | y |
| 217 | y | 217 | UnaryExpr |
| 219 | x | 220 | count |
| 219 | x | 222 | count |
| 223 | y | 224 | count |
| 223 | y | 226 | count |
| 230 | k | 231 | count |
| 238 | k | 241 | count |
| 246 | k | 247 | count |
| 257 | k | 258 | count |
| 257 | k | 259 | Pass |
| 267 | var | 268 | count |
| 267 | var | 269 | Pass |

View File

@@ -1,12 +0,0 @@
import python
import semmle.python.Pruning
from Pruner::UnprunedBasicBlock pred, Pruner::UnprunedBasicBlock succ, int line1, int line2
where Pruner::contradictoryEdge(pred, succ) and
line1 = pred.last().getNode().getLocation().getStartLine() and
line2 = succ.first().getNode().getLocation().getStartLine() and
line1 > 0
select line1, pred.last().getNode().toString(), line2, succ.first().getNode().toString()

View File

@@ -1,95 +0,0 @@
| 10 | test | 11 | count |
| 11 | count | 7 | Function conditional_dead |
| 24 | count | 25 | BoolExpr |
| 24 | t1 | 24 | count |
| 25 | t1 | 26 | t2 |
| 29 | t2 | 30 | BoolExpr |
| 30 | count | 31 | BoolExpr |
| 30 | t2 | 30 | count |
| 37 | count | 38 | BoolExpr |
| 37 | t5 | 37 | count |
| 38 | t5 | 39 | BoolExpr |
| 39 | count | 40 | BoolExpr |
| 39 | t6 | 39 | count |
| 40 | t6 | 20 | Function boolop |
| 47 | t1 | 48 | BoolExpr |
| 47 | t1 | 51 | BoolExpr |
| 48 | count | 49 | BoolExpr |
| 48 | t2 | 48 | count |
| 48 | t2 | 49 | BoolExpr |
| 49 | count | 42 | Function with_splitting |
| 49 | t2 | 42 | Function with_splitting |
| 49 | t2 | 49 | count |
| 51 | count | 52 | BoolExpr |
| 51 | t2 | 51 | count |
| 51 | t2 | 52 | BoolExpr |
| 52 | count | 42 | Function with_splitting |
| 52 | t2 | 42 | Function with_splitting |
| 52 | t2 | 52 | count |
| 93 | UnaryExpr | 94 | count |
| 94 | count | 95 | y |
| 95 | y | 96 | count |
| 96 | count | 99 | ImportExpr |
| 102 | UnaryExpr | 103 | count |
| 103 | count | 106 | FunctionExpr |
| 111 | t1 | 113 | t2 |
| 113 | UnaryExpr | 106 | Function negated_conditional_live |
| 119 | UnaryExpr | 120 | count |
| 120 | count | 116 | Function negated_conditional_dead |
| 130 | None | 131 | count |
| 132 | UnaryExpr | 133 | count |
| 132 | UnaryExpr | 134 | False |
| 133 | count | 134 | False |
| 134 | False | 135 | count |
| 134 | False | 137 | count |
| 138 | True | 139 | count |
| 138 | True | 141 | count |
| 139 | count | 142 | IntegerLiteral |
| 141 | count | 142 | IntegerLiteral |
| 142 | IntegerLiteral | 143 | count |
| 142 | IntegerLiteral | 145 | count |
| 143 | count | 146 | IntegerLiteral |
| 145 | count | 146 | IntegerLiteral |
| 146 | UnaryExpr | 147 | count |
| 146 | UnaryExpr | 149 | count |
| 147 | count | 151 | False |
| 149 | count | 151 | False |
| 151 | UnaryExpr | 152 | count |
| 151 | UnaryExpr | 153 | False |
| 152 | count | 153 | False |
| 153 | UnaryExpr | 129 | Function prune_const_branches |
| 153 | UnaryExpr | 154 | count |
| 154 | count | 129 | Function prune_const_branches |
| 160 | Compare | 161 | count |
| 160 | Compare | 163 | count |
| 161 | count | 157 | Function attribute_lookup_cannot_effect_comparisons_with_immutable_constants |
| 163 | count | 157 | Function attribute_lookup_cannot_effect_comparisons_with_immutable_constants |
| 197 | Compare | 198 | count |
| 198 | count | 194 | Function inequality1 |
| 203 | UnaryExpr | 204 | count |
| 204 | count | 200 | Function inequality2 |
| 209 | Compare | 210 | count |
| 210 | count | 206 | Function reversed_inequality |
| 217 | x | 217 | UnaryExpr |
| 217 | x | 217 | y |
| 217 | y | 217 | UnaryExpr |
| 219 | x | 220 | count |
| 219 | x | 222 | count |
| 220 | count | 223 | y |
| 222 | count | 223 | y |
| 223 | y | 224 | count |
| 223 | y | 226 | count |
| 224 | count | 214 | Function split_bool1 |
| 226 | count | 214 | Function split_bool1 |
| 230 | k | 231 | count |
| 231 | count | 234 | Pass |
| 238 | k | 241 | count |
| 241 | count | 242 | Pass |
| 246 | k | 247 | count |
| 247 | count | 250 | Pass |
| 257 | k | 258 | count |
| 257 | k | 259 | Pass |
| 258 | count | 259 | Pass |
| 267 | var | 268 | count |
| 267 | var | 269 | Pass |
| 268 | count | 269 | Pass |

View File

@@ -1,12 +0,0 @@
import python
import semmle.python.Pruning
from Pruner::UnprunedCfgNode pred, Pruner::UnprunedCfgNode succ, int line1, int line2
where Pruner::unreachableEdge(pred, succ) and
line1 = pred.getNode().getLocation().getStartLine() and
line2 = succ.getNode().getLocation().getStartLine() and
line1 > 0
select line1, pred.getNode().toString(), line2, succ.getNode().toString()

View File

@@ -1,8 +0,0 @@
| 130 | None | 131 | count |
| 132 | UnaryExpr | 134 | False |
| 134 | False | 135 | count |
| 138 | True | 141 | count |
| 142 | IntegerLiteral | 143 | count |
| 146 | UnaryExpr | 149 | count |
| 151 | UnaryExpr | 152 | count |
| 153 | UnaryExpr | 129 | Function prune_const_branches |

View File

@@ -1,12 +0,0 @@
import python
import semmle.python.Pruning
from Pruner::UnprunedBasicBlock pred, Pruner::UnprunedBasicBlock succ, int line1, int line2
where Pruner::simplyDead(pred, succ) and
line1 = pred.last().getNode().getLocation().getStartLine() and
line2 = succ.first().getNode().getLocation().getStartLine() and
line1 > 0
select line1, pred.last().getNode().toString(), line2, succ.first().getNode().toString()

View File

@@ -1,2 +0,0 @@
semmle-extractor-options: --dont-prune-graph
optimize: true

View File

@@ -1,64 +0,0 @@
| 5 | 0 |
| 11 | 0 |
| 18 | 1 |
| 24 | 0 |
| 25 | 1 |
| 29 | 1 |
| 30 | 0 |
| 32 | 1 |
| 33 | 1 |
| 34 | 1 |
| 35 | 1 |
| 37 | 0 |
| 38 | 1 |
| 39 | 0 |
| 40 | 1 |
| 48 | 0 |
| 49 | 1 |
| 51 | 1 |
| 52 | 1 |
| 61 | 1 |
| 64 | 1 |
| 94 | 0 |
| 96 | 0 |
| 103 | 0 |
| 112 | 1 |
| 114 | 1 |
| 120 | 0 |
| 127 | 1 |
| 131 | 0 |
| 133 | 1 |
| 135 | 0 |
| 137 | 1 |
| 139 | 1 |
| 141 | 0 |
| 143 | 0 |
| 145 | 1 |
| 147 | 1 |
| 149 | 0 |
| 152 | 0 |
| 154 | 1 |
| 161 | 1 |
| 163 | 1 |
| 176 | 1 |
| 178 | 1 |
| 180 | 1 |
| 184 | 1 |
| 186 | 1 |
| 189 | 1 |
| 192 | 1 |
| 198 | 0 |
| 204 | 0 |
| 210 | 0 |
| 220 | 1 |
| 222 | 1 |
| 224 | 1 |
| 226 | 1 |
| 231 | 0 |
| 233 | 1 |
| 239 | 1 |
| 241 | 0 |
| 247 | 0 |
| 249 | 1 |
| 258 | 1 |
| 268 | 1 |

View File

@@ -1,269 +0,0 @@
#Test number of CFG nodes for each use of 'count'
def dead():
return 0
count
def conditional_dead(test):
if test:
return
if test:
count
def made_true(seq):
if seq:
return
seq.append(1)
if seq:
count
def boolop(t1, t2, t3, t4, t5, t6):
if not t1:
return
#bool(t1) must be True
t1 or count
t1 and count
if t2:
return
#bool(t2) must be False
t2 or count
t2 and count
if t3 or t4:
t3 or count
t3 and count
t3 or count
t4 and count
if t5 and t6:
t5 or count
t5 and count
t6 or count
t6 and count
def with_splitting(t1, t2):
if t1:
if not t2:
return
#Cannot have bool(t1) be True and bool(t2) be False
if t1:
t2 or count #Unreachable
t2 and count
else:
t2 or count
t2 and count
def loops(seq1, seq2, seq3, seq4, seq5):
if seq1:
return
if not seq2:
return
#bool(seq1) is False; bool(seq2) is True
while seq1:
count #This is unreachable, but the pop below forces us to be conservative.
seq1.pop()
while seq2:
count
seq2.pop()
if seq3:
return
if not seq4:
return
#bool(seq3) is False; bool(seq4) is True
#for var in seq3:
# count #This is unreachable, but we cannot infer this yet.
# print(var)
#for var in seq4:
# count
# print(var)
##seq5 false then made true
#if seq5:
# return
#seq5.append(1)
#for var in seq5:
# count
# print(var)
#Logic does not apply to global variables in calls,
#as they may be changed from true to false externally.
from some_module import x, y
if not x:
raise Exception()
if y:
raise Exception()
make_a_call()
if not x:
count
if y:
count
# However, modules are always true -- Which is important.
import another_module
make_a_call()
if not another_module:
count
def negated_conditional_live(t1, t2):
if not t1:
return
if t2:
return
if t1:
count
if not t2:
count
def negated_conditional_dead(test):
if not test:
return
if not test:
count
def made_true2(m):
if m:
return
del m['a']
if m:
count
def prune_const_branches():
if None:
count
if not None:
count
if False:
count
else:
count
if True:
count
else:
count
if 0:
count
else:
count
if -4:
count
else:
count
#Muliptle nots
if not not False:
count
if not not not False:
count
#ODASA-6794
def attribute_lookup_cannot_effect_comparisons_with_immutable_constants(ps):
if ps is not None:
ps_clamped = ps.clamp()
if ps is None:
count
else:
count
def func():
global escapes
so_something()
escapes = True
#Don't prune on `escapes` as it escapes.
if __name__ == '__main__':
escapes = None # global
try:
func()
except Exception as err:
count
if escapes is None:
count
else:
count
def func2():
while 1:
count
if cond12:
count
try:
true12()
count
except IOError:
true12 = 0
count
def inequality1(x):
if x < 4:
return
if x < 4:
count
def inequality2(x):
if x < 4:
return
if not x >= 4:
count
def reversed_inequality(x):
if x < 4:
return
if 4 > x:
count
#Splittings with boolean expressions:
def split_bool1(x=None,y=None):
if x and y:
raise
if not (x or y):
raise
if x:
count
else:
count
if y:
count
else:
count
def prune_on_constant1():
k = False
if k:
count
else:
count
pass
def prune_on_constant2():
k = 3
if k:
count
else:
count
pass
def prune_on_constant3():
k = None
if k:
count
else:
count
pass
def prune_on_constant_in_test(a, b):
if a:
k = True
else:
k = False
if k:
count
pass
def prune_on_constant_in_try():
try:
import foo
var = True
except:
var = False
if var:
count
pass

View File

@@ -1,5 +0,0 @@
import python
from Name n
where n.getId() = "count"
select n.getLocation().getStartLine(), count(n.getAFlowNode())

View File

@@ -1,2 +1,2 @@
semmle-extractor-options: --max-import-depth=3 --dont-prune-graph
semmle-extractor-options: --max-import-depth=3
optimize: true

View File

@@ -1,2 +1,2 @@
semmle-extractor-options: --max-import-depth=4 --dont-prune-graph
semmle-extractor-options: --max-import-depth=4
optimize: true