Skip to content

Commit 08b9994

Browse files
committed
Python ESSA: Fix definition of Essa non-local variables.
1 parent d933152 commit 08b9994

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

python/ql/src/semmle/python/dataflow/SsaDefinitions.qll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ abstract class PythonSsaSourceVariable extends SsaSourceVariable {
107107

108108
}
109109

110-
111110
class FunctionLocalVariable extends PythonSsaSourceVariable {
112111

113112
FunctionLocalVariable() {
114-
this.(LocalVariable).getScope() instanceof Function and not this.(LocalVariable).escapes()
113+
this.(LocalVariable).getScope() instanceof Function and
114+
not this instanceof NonLocalVariable
115115
}
116116

117117
override ControlFlowNode getAnImplicitUse() {
@@ -120,8 +120,14 @@ class FunctionLocalVariable extends PythonSsaSourceVariable {
120120

121121
override ControlFlowNode getScopeEntryDefinition() {
122122
not this.(LocalVariable).getId() = "*" and
123-
not this.(LocalVariable).isParameter() and
124-
this.(LocalVariable).getScope().getEntryNode() = result
123+
exists(Scope s |
124+
s.getEntryNode() = result |
125+
s = this.(LocalVariable).getScope() and
126+
not this.(LocalVariable).isParameter()
127+
or
128+
s != this.(LocalVariable).getScope() and
129+
s = this.(LocalVariable).getALoad().getScope()
130+
)
125131
}
126132

127133
override CallNode redefinedAtCallSite() { none() }
@@ -131,7 +137,10 @@ class FunctionLocalVariable extends PythonSsaSourceVariable {
131137
class NonLocalVariable extends PythonSsaSourceVariable {
132138

133139
NonLocalVariable() {
134-
this.(LocalVariable).getScope() instanceof Function and this.(LocalVariable).escapes()
140+
exists(Function f |
141+
this.(LocalVariable).getScope() = f and
142+
this.(LocalVariable).getAStore().getScope() != f
143+
)
135144
}
136145

137146
override ControlFlowNode getAnImplicitUse() {

0 commit comments

Comments
 (0)