forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#14858 from yoff/python/demonstrate-use-use-…
…explosion Python: Test demonstrating the need for phi-read-nodes
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
python/ql/test/experimental/dataflow/use-use-flow/read_explosion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This test file is inspired by | ||
# `csharp/ql/test/library-tests/dataflow/local/UseUseExplosion.cs` | ||
# but with `n=3` kept small, since we do have the explosion. | ||
|
||
cond = ... | ||
|
||
# global variables are slightly special, | ||
# so we go into a function scope | ||
def scope(): | ||
x = 0 | ||
|
||
if(cond > 3): | ||
if(cond > 2): | ||
if(cond > 1): | ||
pass | ||
else: | ||
use(x) | ||
else: | ||
use(x) | ||
else: | ||
use(x) | ||
|
||
if(cond > 3): | ||
if(cond > 2): | ||
if(cond > 1): | ||
pass | ||
else: | ||
use(x) | ||
else: | ||
use(x) | ||
else: | ||
use(x) | ||
|
||
def use(v): | ||
# this could just be `pass` but we do not want it optimized away. | ||
y = v+2 |
24 changes: 24 additions & 0 deletions
24
python/ql/test/experimental/dataflow/use-use-flow/use-use-counts.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
implicit_use_count | ||
| 0 | | ||
implicit_use | ||
source_use_count | ||
| 6 | | ||
source_use | ||
| read_explosion.py:17:15:17:15 | ControlFlowNode for x | | ||
| read_explosion.py:19:13:19:13 | ControlFlowNode for x | | ||
| read_explosion.py:21:11:21:11 | ControlFlowNode for x | | ||
| read_explosion.py:28:15:28:15 | ControlFlowNode for x | | ||
| read_explosion.py:30:13:30:13 | ControlFlowNode for x | | ||
| read_explosion.py:32:11:32:11 | ControlFlowNode for x | | ||
use_use_edge_count | ||
| 9 | | ||
use_use_edge | ||
| read_explosion.py:17:15:17:15 | ControlFlowNode for x | read_explosion.py:28:15:28:15 | ControlFlowNode for x | | ||
| read_explosion.py:17:15:17:15 | ControlFlowNode for x | read_explosion.py:30:13:30:13 | ControlFlowNode for x | | ||
| read_explosion.py:17:15:17:15 | ControlFlowNode for x | read_explosion.py:32:11:32:11 | ControlFlowNode for x | | ||
| read_explosion.py:19:13:19:13 | ControlFlowNode for x | read_explosion.py:28:15:28:15 | ControlFlowNode for x | | ||
| read_explosion.py:19:13:19:13 | ControlFlowNode for x | read_explosion.py:30:13:30:13 | ControlFlowNode for x | | ||
| read_explosion.py:19:13:19:13 | ControlFlowNode for x | read_explosion.py:32:11:32:11 | ControlFlowNode for x | | ||
| read_explosion.py:21:11:21:11 | ControlFlowNode for x | read_explosion.py:28:15:28:15 | ControlFlowNode for x | | ||
| read_explosion.py:21:11:21:11 | ControlFlowNode for x | read_explosion.py:30:13:30:13 | ControlFlowNode for x | | ||
| read_explosion.py:21:11:21:11 | ControlFlowNode for x | read_explosion.py:32:11:32:11 | ControlFlowNode for x | |
37 changes: 37 additions & 0 deletions
37
python/ql/test/experimental/dataflow/use-use-flow/use-use-counts.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import python | ||
private import semmle.python.dataflow.new.internal.DataFlowPrivate | ||
|
||
query int implicit_use_count() { | ||
exists(SsaSourceVariable x | x.getName() = "x" | result = count(x.getAnImplicitUse())) | ||
} | ||
|
||
query ControlFlowNode implicit_use() { | ||
exists(SsaSourceVariable x | x.getName() = "x" | result = x.getAnImplicitUse()) | ||
} | ||
|
||
query int source_use_count() { | ||
exists(SsaSourceVariable x | x.getName() = "x" | result = count(x.getASourceUse())) | ||
} | ||
|
||
query ControlFlowNode source_use() { | ||
exists(SsaSourceVariable x | x.getName() = "x" | result = x.getASourceUse()) | ||
} | ||
|
||
query int use_use_edge_count() { | ||
exists(SsaSourceVariable x | x.getName() = "x" | | ||
result = | ||
count(NameNode use1, NameNode use2 | | ||
use1 = x.getAUse() and | ||
use2 = x.getAUse() and | ||
LocalFlow::useToNextUse(use1, use2) | ||
) | ||
) | ||
} | ||
|
||
query predicate use_use_edge(NameNode use1, NameNode use2) { | ||
exists(SsaSourceVariable x | x.getName() = "x" | | ||
use1 = x.getAUse() and | ||
use2 = x.getAUse() and | ||
LocalFlow::useToNextUse(use1, use2) | ||
) | ||
} |