mirror of
https://github.com/github/codeql.git
synced 2026-05-27 17:41:24 +02:00
Python: SSA: handle closure variables via per-scope entry defs
The new SSA's implicit entry-def predicate previously placed entries in
the variable's defining scope. For closure variables that's the outer
function, so inner functions had no entry def for the captured
variable — reads in the inner scope failed to resolve to any
definition.
Mirrors legacy ESSA's 'NonLocalVariable.getScopeEntryDefinition()':
place an implicit entry def at every reading scope's entry block,
independently of where the variable is *defined*. A closure variable
accessed in two nested functions and the outer one gets three entry
defs (one per reading scope).
Also makes 'ScopeEntryDefinition' extend 'EssaNodeDefinition' (matching
legacy ESSA), with 'getDefiningNode()' returning the scope's entry CFG
node. This requires extending the private 'writeDefNode' helper to
project i=-1 entries to bb.getNode(0).
Updates the new-vs-legacy comparison snapshot: closure-variable reads
('x:32:5'), nested global reads ('GLOBAL:52:1') now resolve. New
'def-only-new' entries appear for unbound names ('sum', 'open',
'compute') — the new SSA uniformly creates scope-entry defs for all
non-local reads, including those that legacy ESSA classifies as
builtin and excludes. This is a more uniform semantic and arguably
cleaner.
Updates the SsaTest 'some_undefined' annotation: previously documented
as a known limitation, now correctly resolves to a scope-entry def.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
| def-only-new | compute:37:1 |
|
||||
| def-only-new | open:44:1 |
|
||||
| def-only-new | sum:27:1 |
|
||||
| def-only-old | $:0:0 |
|
||||
| def-only-old | GLOBAL:49:1 |
|
||||
| def-only-old | GLOBAL:52:1 |
|
||||
| def-only-old | __name__:0:0 |
|
||||
| def-only-old | __package__:0:0 |
|
||||
| def-only-old | closure:31:5 |
|
||||
@@ -17,4 +19,3 @@
|
||||
| def-only-old | with_binding:44:5 |
|
||||
| def-only-old | x:20:1 |
|
||||
| def-only-old | x:31:13 |
|
||||
| def-only-old | x:32:5 |
|
||||
|
||||
@@ -35,6 +35,6 @@ def if_else_phi(cond): # $ def=cond
|
||||
|
||||
|
||||
def use_global():
|
||||
return some_undefined # known limitation: undefined globals not resolved here
|
||||
return some_undefined # $ use=some_undefined
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user