Files
codeql/python/ql/test/library-tests/dataflow-new-ssa/test.py
yoff 2ef25e8839 Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-30 17:04:19 +02:00

49 lines
1.5 KiB
Python

# Basic SSA tests for the new-CFG SSA adapter.
#
# The shared SSA implementation prunes its construction by liveness:
# write definitions of variables that are never read in their scope are
# not materialised (except for module-scope globals, which may be read by
# importers). Scope-entry defs are only created for non-local reads when
# the variable has a defining store somewhere in the program.
#
# Annotations:
# def=<var>: there is an SSA write definition of <var> at this line
# use=<var>: <var> is used here and the read resolves to some def
#
# Note: a module-level `def name(...)` statement is itself a write
# definition of the module global `name`, which is live (it can be read
# externally), so every function below carries a `def=<name>` annotation
# on its `def` line.
def basic_param(x): # $ def=basic_param def=x
return x # $ use=x
def basic_assign(): # $ def=basic_assign
y = 1 # $ def=y
return y # $ use=y
def reassignment(): # $ def=reassignment
x = 1
x = 2 # $ def=x
return x # $ use=x
def if_else_phi(cond): # $ def=if_else_phi def=cond
if cond: # $ use=cond phi=x
x = 1 # $ def=x
else:
x = 2 # $ def=x
return x # $ use=x
# `some_undefined` is never assigned anywhere, so (matching legacy ESSA)
# the SSA library creates no entry definition for it: an undefined-name
# read resolves to no SSA def, hence there is no `use=` here.
def use_global(): # $ def=use_global
return some_undefined