Skip to content

Commit 05e498d

Browse files
committed
Python: Clarify pruning code.
1 parent 2bdf423 commit 05e498d

File tree

2 files changed

+6
-54
lines changed

2 files changed

+6
-54
lines changed

python/ql/src/semmle/python/Pruning.qll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ module Pruner {
423423
reachableEdge(_, bb)
424424
}
425425

426-
Constraint constraintFromTest(SsaVariable var, UnprunedCfgNode node) {
426+
Constraint constraintFromExpr(SsaVariable var, UnprunedCfgNode node) {
427427
py_ssa_use(node, var) and result = TTruthy(true)
428428
or
429429
exists(boolean b |
@@ -435,7 +435,11 @@ module Pruner {
435435
result = TConstrainedByConstant(op, k)
436436
)
437437
or
438-
result = constraintFromTest(var, node.(UnprunedNot).getOperand()).invert()
438+
result = constraintFromExpr(var, node.(UnprunedNot).getOperand()).invert()
439+
}
440+
441+
Constraint constraintFromTest(SsaVariable var, UnprunedCfgNode node) {
442+
result = constraintFromExpr(var, node) and node.isBranch()
439443
}
440444

441445
predicate none_test(UnprunedCompareNode test, SsaVariable var, boolean is) {
@@ -462,8 +466,6 @@ module Pruner {
462466
py_ssa_use(right, var) and
463467
intValue(left.getNode()) = k
464468
)
465-
or
466-
int_test(test.(UnprunedNot).getOperand(), var, op.invert(), k)
467469
}
468470

469471
private predicate constrainingValue(Expr e) {

python/ql/test/library-tests/ControlFlow/pruning/Constraint.expected

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
| 8 | test | test | Truthy | test |
22
| 10 | test | test | Truthy | test |
33
| 14 | seq | seq | Truthy | test |
4-
| 16 | seq | seq | Truthy | test |
54
| 17 | seq | seq | Truthy | test |
65
| 21 | UnaryExpr | t1 | Falsey | test |
7-
| 21 | t1 | t1 | Truthy | test |
86
| 24 | t1 | t1 | Truthy | test |
97
| 25 | t1 | t1 | Truthy | test |
108
| 26 | t2 | t2 | Truthy | test |
@@ -24,91 +22,43 @@
2422
| 40 | t6 | t6 | Truthy | test |
2523
| 43 | t1 | t1 | Truthy | test |
2624
| 44 | UnaryExpr | t2 | Falsey | test |
27-
| 44 | t2 | t2 | Truthy | test |
2825
| 47 | t1 | t1 | Truthy | test |
2926
| 48 | t2 | t2 | Truthy | test |
3027
| 49 | t2 | t2 | Truthy | test |
3128
| 51 | t2 | t2 | Truthy | test |
3229
| 52 | t2 | t2 | Truthy | test |
3330
| 55 | seq1 | seq1 | Truthy | test |
3431
| 57 | UnaryExpr | seq2 | Falsey | test |
35-
| 57 | seq2 | seq2 | Truthy | test |
3632
| 60 | seq1 | seq1 | Truthy | test |
37-
| 62 | seq1 | seq1 | Truthy | test |
3833
| 63 | seq2 | seq2 | Truthy | test |
39-
| 65 | seq2 | seq2 | Truthy | test |
4034
| 66 | seq3 | seq3 | Truthy | test |
4135
| 68 | UnaryExpr | seq4 | Falsey | test |
42-
| 68 | seq4 | seq4 | Truthy | test |
43-
| 71 | seq3 | seq3 | Truthy | test |
44-
| 73 | var | var | Truthy | test |
45-
| 74 | seq4 | seq4 | Truthy | test |
46-
| 76 | var | var | Truthy | test |
4736
| 78 | seq5 | seq5 | Truthy | test |
48-
| 80 | seq5 | seq5 | Truthy | test |
49-
| 81 | seq5 | seq5 | Truthy | test |
50-
| 83 | var | var | Truthy | test |
5137
| 88 | UnaryExpr | x | Falsey | test |
52-
| 88 | x | x | Truthy | test |
53-
| 89 | Exception | Exception | Truthy | test |
5438
| 90 | y | y | Truthy | test |
55-
| 91 | Exception | Exception | Truthy | test |
56-
| 92 | make_a_call | make_a_call | Truthy | test |
5739
| 93 | UnaryExpr | x | Falsey | test |
58-
| 93 | x | x | Truthy | test |
59-
| 94 | count | count | Truthy | test |
6040
| 95 | y | y | Truthy | test |
61-
| 96 | count | count | Truthy | test |
6241
| 99 | another_module | another_module | Truthy | assign |
63-
| 101 | make_a_call | make_a_call | Truthy | test |
6442
| 102 | UnaryExpr | another_module | Falsey | test |
65-
| 102 | another_module | another_module | Truthy | test |
66-
| 103 | count | count | Truthy | test |
6743
| 107 | UnaryExpr | t1 | Falsey | test |
68-
| 107 | t1 | t1 | Truthy | test |
6944
| 109 | t2 | t2 | Truthy | test |
7045
| 111 | t1 | t1 | Truthy | test |
7146
| 113 | UnaryExpr | t2 | Falsey | test |
72-
| 113 | t2 | t2 | Truthy | test |
7347
| 117 | UnaryExpr | test | Falsey | test |
74-
| 117 | test | test | Truthy | test |
7548
| 119 | UnaryExpr | test | Falsey | test |
76-
| 119 | test | test | Truthy | test |
7749
| 123 | m | m | Truthy | test |
78-
| 125 | m | m | Truthy | test |
7950
| 126 | m | m | Truthy | test |
8051
| 158 | Compare | ps | Is not None | test |
81-
| 158 | ps | ps | Truthy | test |
82-
| 159 | ps | ps | Truthy | test |
8352
| 160 | Compare | ps | Is None | test |
84-
| 160 | ps | ps | Truthy | test |
85-
| 171 | __name__ | __name__ | Truthy | test |
86-
| 172 | None | None | Truthy | test |
8753
| 172 | escapes | escapes | Is None | assign |
88-
| 174 | func | func | Truthy | test |
89-
| 175 | Exception | Exception | Truthy | test |
90-
| 176 | count | count | Truthy | test |
9154
| 177 | Compare | escapes | Is None | test |
92-
| 177 | None | None | Truthy | test |
93-
| 177 | escapes | escapes | Truthy | test |
94-
| 178 | count | count | Truthy | test |
95-
| 180 | count | count | Truthy | test |
96-
| 188 | true12 | true12 | Truthy | test |
9755
| 191 | true12 | true12 | == 0 | assign |
9856
| 195 | Compare | x | < 4 | test |
99-
| 195 | x | x | Truthy | test |
10057
| 197 | Compare | x | < 4 | test |
101-
| 197 | x | x | Truthy | test |
10258
| 201 | Compare | x | < 4 | test |
103-
| 201 | x | x | Truthy | test |
104-
| 203 | Compare | x | >= 4 | test |
10559
| 203 | UnaryExpr | x | < 4 | test |
106-
| 203 | x | x | Truthy | test |
10760
| 207 | Compare | x | < 4 | test |
108-
| 207 | x | x | Truthy | test |
10961
| 209 | Compare | x | < 4 | test |
110-
| 209 | x | x | Truthy | test |
111-
| 214 | None | None | Truthy | test |
11262
| 215 | x | x | Truthy | test |
11363
| 215 | y | y | Truthy | test |
11464
| 217 | x | x | Truthy | test |

0 commit comments

Comments
 (0)