File tree Expand file tree Collapse file tree 3 files changed +97
-0
lines changed
python/ql/test/experimental/dataflow/use-use-flow Expand file tree Collapse file tree 3 files changed +97
-0
lines changed Original file line number Diff line number Diff line change
1
+ # This test file is inspired by
2
+ # `csharp/ql/test/library-tests/dataflow/local/UseUseExplosion.cs`
3
+ # but with `n=3` kept small, since we do have the explosion.
4
+
5
+ cond = ...
6
+
7
+ # global variables are slightly special,
8
+ # so we go into a function scope
9
+ def scope ():
10
+ x = 0
11
+
12
+ if (cond > 3 ):
13
+ if (cond > 2 ):
14
+ if (cond > 1 ):
15
+ pass
16
+ else :
17
+ use (x )
18
+ else :
19
+ use (x )
20
+ else :
21
+ use (x )
22
+
23
+ if (cond > 3 ):
24
+ if (cond > 2 ):
25
+ if (cond > 1 ):
26
+ pass
27
+ else :
28
+ use (x )
29
+ else :
30
+ use (x )
31
+ else :
32
+ use (x )
33
+
34
+ def use (v ):
35
+ # this could just be `pass` but we do not want it optimized away.
36
+ y = v + 2
Original file line number Diff line number Diff line change
1
+ implicit_use_count
2
+ | 0 |
3
+ implicit_use
4
+ source_use_count
5
+ | 6 |
6
+ source_use
7
+ | read_explosion.py:17:15:17:15 | ControlFlowNode for x |
8
+ | read_explosion.py:19:13:19:13 | ControlFlowNode for x |
9
+ | read_explosion.py:21:11:21:11 | ControlFlowNode for x |
10
+ | read_explosion.py:28:15:28:15 | ControlFlowNode for x |
11
+ | read_explosion.py:30:13:30:13 | ControlFlowNode for x |
12
+ | read_explosion.py:32:11:32:11 | ControlFlowNode for x |
13
+ use_use_edge_count
14
+ | 9 |
15
+ use_use_edge
16
+ | read_explosion.py:17:15:17:15 | ControlFlowNode for x | read_explosion.py:28:15:28:15 | ControlFlowNode for x |
17
+ | read_explosion.py:17:15:17:15 | ControlFlowNode for x | read_explosion.py:30:13:30:13 | ControlFlowNode for x |
18
+ | read_explosion.py:17:15:17:15 | ControlFlowNode for x | read_explosion.py:32:11:32:11 | ControlFlowNode for x |
19
+ | read_explosion.py:19:13:19:13 | ControlFlowNode for x | read_explosion.py:28:15:28:15 | ControlFlowNode for x |
20
+ | read_explosion.py:19:13:19:13 | ControlFlowNode for x | read_explosion.py:30:13:30:13 | ControlFlowNode for x |
21
+ | read_explosion.py:19:13:19:13 | ControlFlowNode for x | read_explosion.py:32:11:32:11 | ControlFlowNode for x |
22
+ | read_explosion.py:21:11:21:11 | ControlFlowNode for x | read_explosion.py:28:15:28:15 | ControlFlowNode for x |
23
+ | read_explosion.py:21:11:21:11 | ControlFlowNode for x | read_explosion.py:30:13:30:13 | ControlFlowNode for x |
24
+ | read_explosion.py:21:11:21:11 | ControlFlowNode for x | read_explosion.py:32:11:32:11 | ControlFlowNode for x |
Original file line number Diff line number Diff line change
1
+ import python
2
+ private import semmle.python.dataflow.new.internal.DataFlowPrivate
3
+
4
+ query int implicit_use_count ( ) {
5
+ exists ( SsaSourceVariable x | x .getName ( ) = "x" | result = count ( x .getAnImplicitUse ( ) ) )
6
+ }
7
+
8
+ query ControlFlowNode implicit_use ( ) {
9
+ exists ( SsaSourceVariable x | x .getName ( ) = "x" | result = x .getAnImplicitUse ( ) )
10
+ }
11
+
12
+ query int source_use_count ( ) {
13
+ exists ( SsaSourceVariable x | x .getName ( ) = "x" | result = count ( x .getASourceUse ( ) ) )
14
+ }
15
+
16
+ query ControlFlowNode source_use ( ) {
17
+ exists ( SsaSourceVariable x | x .getName ( ) = "x" | result = x .getASourceUse ( ) )
18
+ }
19
+
20
+ query int use_use_edge_count ( ) {
21
+ exists ( SsaSourceVariable x | x .getName ( ) = "x" |
22
+ result =
23
+ count ( NameNode use1 , NameNode use2 |
24
+ use1 = x .getAUse ( ) and
25
+ use2 = x .getAUse ( ) and
26
+ LocalFlow:: useToNextUse ( use1 , use2 )
27
+ )
28
+ )
29
+ }
30
+
31
+ query predicate use_use_edge ( NameNode use1 , NameNode use2 ) {
32
+ exists ( SsaSourceVariable x | x .getName ( ) = "x" |
33
+ use1 = x .getAUse ( ) and
34
+ use2 = x .getAUse ( ) and
35
+ LocalFlow:: useToNextUse ( use1 , use2 )
36
+ )
37
+ }
You can’t perform that action at this time.
0 commit comments