-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Test demonstrating the need for phi-read-nodes #14858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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) | ||
) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also add a test for normal phi nodes, i.e. something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put that in #14861. (Looks like I came to the exact same example :-))