mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
Python: Use aggressive dead-code elimination when pruning.
This commit is contained in:
@@ -105,3 +105,10 @@
|
||||
| 207 | x | x | Truthy |
|
||||
| 209 | Compare | x | < 4 |
|
||||
| 209 | x | x | Truthy |
|
||||
| 214 | None | None | Truthy |
|
||||
| 215 | x | x | Truthy |
|
||||
| 215 | y | y | Truthy |
|
||||
| 217 | x | x | Truthy |
|
||||
| 217 | y | y | Truthy |
|
||||
| 219 | x | x | Truthy |
|
||||
| 223 | y | y | Truthy |
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
| 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 |
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
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()
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
| 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 |
|
||||
12
python/ql/test/library-tests/ControlFlow/pruning/Pruned.ql
Normal file
12
python/ql/test/library-tests/ControlFlow/pruning/Pruned.ql
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
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()
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
| 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 |
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
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()
|
||||
|
||||
@@ -53,3 +53,7 @@
|
||||
| 198 | 0 |
|
||||
| 204 | 0 |
|
||||
| 210 | 0 |
|
||||
| 220 | 1 |
|
||||
| 222 | 1 |
|
||||
| 224 | 1 |
|
||||
| 226 | 1 |
|
||||
|
||||
@@ -209,3 +209,18 @@ def reversed_inequality(x):
|
||||
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
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
semmle-extractor-options: --max-import-depth=3
|
||||
semmle-extractor-options: --max-import-depth=3 --dont-prune-graph
|
||||
optimize: true
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
semmle-extractor-options: --max-import-depth=4
|
||||
semmle-extractor-options: --max-import-depth=4 --dont-prune-graph
|
||||
optimize: true
|
||||
|
||||
Reference in New Issue
Block a user