mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Python: Test demonstrating need for phi-read-nodes
Or for a data flow node filling that role, at least.
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,24 @@
|
||||
implicit_use_count
|
||||
| 0 |
|
||||
implicit_use
|
||||
source_use_count
|
||||
| 6 |
|
||||
source_use
|
||||
| read_explosion.py:13:15:13:15 | ControlFlowNode for x |
|
||||
| read_explosion.py:15:13:15:13 | ControlFlowNode for x |
|
||||
| read_explosion.py:17:11:17:11 | ControlFlowNode for x |
|
||||
| read_explosion.py:24:15:24:15 | ControlFlowNode for x |
|
||||
| read_explosion.py:26:13:26:13 | ControlFlowNode for x |
|
||||
| read_explosion.py:28:11:28:11 | ControlFlowNode for x |
|
||||
use_use_edge_count
|
||||
| 9 |
|
||||
use_use_edge
|
||||
| read_explosion.py:13:15:13:15 | ControlFlowNode for x | read_explosion.py:24:15:24:15 | ControlFlowNode for x |
|
||||
| read_explosion.py:13:15:13:15 | ControlFlowNode for x | read_explosion.py:26:13:26:13 | ControlFlowNode for x |
|
||||
| read_explosion.py:13:15:13:15 | ControlFlowNode for x | read_explosion.py:28:11:28:11 | ControlFlowNode for x |
|
||||
| read_explosion.py:15:13:15:13 | ControlFlowNode for x | read_explosion.py:24:15:24:15 | ControlFlowNode for x |
|
||||
| read_explosion.py:15:13:15:13 | ControlFlowNode for x | read_explosion.py:26:13:26:13 | ControlFlowNode for x |
|
||||
| read_explosion.py:15:13:15:13 | ControlFlowNode for x | read_explosion.py:28:11:28:11 | ControlFlowNode for x |
|
||||
| read_explosion.py:17:11:17:11 | ControlFlowNode for x | read_explosion.py:24:15:24:15 | ControlFlowNode for x |
|
||||
| read_explosion.py:17:11:17:11 | ControlFlowNode for x | read_explosion.py:26:13:26:13 | ControlFlowNode for x |
|
||||
| read_explosion.py:17:11:17:11 | ControlFlowNode for x | read_explosion.py:28:11:28:11 | ControlFlowNode for x |
|
||||
@@ -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)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user