Skip to content

Commit d14d31c

Browse files
authored
Merge pull request #1410 from markshannon/python-no-methodcall-defs-in-tests
Python ESSA: Remove method-callsite definitions when call is in a test defining a pi-node.
2 parents 61f7c78 + 0f0dc81 commit d14d31c

15 files changed

+75
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ cached module SsaSource {
356356
/** Holds if `v` is used as the receiver in a method call. */
357357
cached predicate method_call_refinement(Variable v, ControlFlowNode use, CallNode call) {
358358
use = v.getAUse() and
359-
call.getFunction().(AttrNode).getObject() = use
359+
call.getFunction().(AttrNode).getObject() = use and
360+
not test_contains(_, call)
360361
}
361362

362363
/** Holds if `v` is defined by assignment at `defn` and given `value`. */

python/ql/test/library-tests/PointsTo/new/Dataflow.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
| b_condition.py:0 | h_0 = ScopeEntryDefinition |
5555
| b_condition.py:0 | k_0 = ScopeEntryDefinition |
5656
| b_condition.py:0 | loop_0 = ScopeEntryDefinition |
57+
| b_condition.py:0 | method_check_0 = ScopeEntryDefinition |
5758
| b_condition.py:0 | not_or_not_0 = ScopeEntryDefinition |
5859
| b_condition.py:0 | odasa6261_0 = ScopeEntryDefinition |
5960
| b_condition.py:0 | split_bool1_0 = ScopeEntryDefinition |
@@ -160,6 +161,13 @@
160161
| b_condition.py:104 | a_1 = Pi(a_0) [false] |
161162
| b_condition.py:105 | a_2 = Pi(a_1) [false] |
162163
| b_condition.py:107 | a_3 = Pi(a_2) [false] |
164+
| b_condition.py:109 | method_check_1 = FunctionExpr |
165+
| b_condition.py:109 | x_0 = ParameterDefinition |
166+
| b_condition.py:109 | x_5 = phi(x_2, x_4) |
167+
| b_condition.py:111 | x_1 = Pi(x_0) [true] |
168+
| b_condition.py:111 | x_2 = ArgumentRefinement(x_1) |
169+
| b_condition.py:113 | x_3 = Pi(x_0) [false] |
170+
| b_condition.py:113 | x_4 = ArgumentRefinement(x_3) |
163171
| d_globals.py:0 | D_0 = ScopeEntryDefinition |
164172
| d_globals.py:0 | Ugly_0 = ScopeEntryDefinition |
165173
| d_globals.py:0 | X_0 = ScopeEntryDefinition |

python/ql/test/library-tests/PointsTo/new/Definitions.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
| b_condition.py:0 | Global Variable h | ScopeEntryDefinition |
3838
| b_condition.py:0 | Global Variable k | ScopeEntryDefinition |
3939
| b_condition.py:0 | Global Variable loop | ScopeEntryDefinition |
40+
| b_condition.py:0 | Global Variable method_check | ScopeEntryDefinition |
4041
| b_condition.py:0 | Global Variable not_or_not | ScopeEntryDefinition |
4142
| b_condition.py:0 | Global Variable odasa6261 | ScopeEntryDefinition |
4243
| b_condition.py:0 | Global Variable split_bool1 | ScopeEntryDefinition |
@@ -136,6 +137,13 @@
136137
| b_condition.py:104 | Local Variable a | PyEdgeRefinement |
137138
| b_condition.py:105 | Local Variable a | PyEdgeRefinement |
138139
| b_condition.py:107 | Local Variable a | PyEdgeRefinement |
140+
| b_condition.py:109 | Global Variable method_check | AssignmentDefinition |
141+
| b_condition.py:109 | Local Variable x | ParameterDefinition |
142+
| b_condition.py:109 | Local Variable x | PhiFunction |
143+
| b_condition.py:111 | Local Variable x | ArgumentRefinement |
144+
| b_condition.py:111 | Local Variable x | PyEdgeRefinement |
145+
| b_condition.py:113 | Local Variable x | ArgumentRefinement |
146+
| b_condition.py:113 | Local Variable x | PyEdgeRefinement |
139147
| d_globals.py:0 | Global Variable D | ScopeEntryDefinition |
140148
| d_globals.py:0 | Global Variable Ugly | ScopeEntryDefinition |
141149
| d_globals.py:0 | Global Variable X | ScopeEntryDefinition |

python/ql/test/library-tests/PointsTo/new/Live.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@
162162
| Global Variable list | b_condition.py:101 | entry |
163163
| Global Variable loop | b_condition.py:42 | exit |
164164
| Global Variable loop | b_condition.py:43 | entry |
165+
| Global Variable method_check | b_condition.py:42 | exit |
166+
| Global Variable method_check | b_condition.py:43 | entry |
165167
| Global Variable not_or_not | b_condition.py:42 | exit |
166168
| Global Variable not_or_not | b_condition.py:43 | entry |
167169
| Global Variable object | b_condition.py:0 | entry |
@@ -298,6 +300,10 @@
298300
| Global Variable use | b_condition.py:88 | exit |
299301
| Global Variable use | b_condition.py:90 | entry |
300302
| Global Variable use | b_condition.py:90 | exit |
303+
| Global Variable use | b_condition.py:109 | entry |
304+
| Global Variable use | b_condition.py:110 | exit |
305+
| Global Variable use | b_condition.py:111 | entry |
306+
| Global Variable use | b_condition.py:113 | entry |
301307
| Global Variable v2 | b_condition.py:42 | exit |
302308
| Global Variable v2 | b_condition.py:43 | entry |
303309
| Global Variable v2 | b_condition.py:44 | exit |
@@ -372,6 +378,12 @@
372378
| Local Variable x | b_condition.py:88 | exit |
373379
| Local Variable x | b_condition.py:90 | entry |
374380
| Local Variable x | b_condition.py:90 | exit |
381+
| Local Variable x | b_condition.py:109 | entry |
382+
| Local Variable x | b_condition.py:110 | exit |
383+
| Local Variable x | b_condition.py:111 | entry |
384+
| Local Variable x | b_condition.py:111 | exit |
385+
| Local Variable x | b_condition.py:113 | entry |
386+
| Local Variable x | b_condition.py:113 | exit |
375387
| Local Variable y | b_condition.py:5 | entry |
376388
| Local Variable y | b_condition.py:5 | exit |
377389
| Local Variable y | b_condition.py:7 | exit |

python/ql/test/library-tests/PointsTo/new/NameSpace.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| b_condition.py:0 | Module code.b_condition | h | Function h |
1515
| b_condition.py:0 | Module code.b_condition | k | Function k |
1616
| b_condition.py:0 | Module code.b_condition | loop | Function loop |
17+
| b_condition.py:0 | Module code.b_condition | method_check | Function method_check |
1718
| b_condition.py:0 | Module code.b_condition | not_or_not | Function not_or_not |
1819
| b_condition.py:0 | Module code.b_condition | odasa6261 | Function odasa6261 |
1920
| b_condition.py:0 | Module code.b_condition | split_bool1 | Function split_bool1 |

python/ql/test/library-tests/PointsTo/new/PointsToUnknown.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@
114114
| b_condition.py:99 | ControlFlowNode for use() | 99 |
115115
| b_condition.py:105 | ControlFlowNode for Subscript | 105 |
116116
| b_condition.py:105 | ControlFlowNode for UnaryExpr | 105 |
117+
| b_condition.py:110 | ControlFlowNode for Attribute | 110 |
118+
| b_condition.py:110 | ControlFlowNode for Attribute() | 110 |
119+
| b_condition.py:110 | ControlFlowNode for x | 109 |
120+
| b_condition.py:111 | ControlFlowNode for use | 111 |
121+
| b_condition.py:111 | ControlFlowNode for use() | 111 |
122+
| b_condition.py:113 | ControlFlowNode for use | 113 |
123+
| b_condition.py:113 | ControlFlowNode for use() | 113 |
117124
| c_tests.py:5 | ControlFlowNode for IfExp | 5 |
118125
| c_tests.py:5 | ControlFlowNode for cond | 5 |
119126
| c_tests.py:5 | ControlFlowNode for unknown | 5 |

python/ql/test/library-tests/PointsTo/new/PointsToWithContext.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ WARNING: Predicate points_to has been deprecated and may be removed in future (P
185185
| b_condition.py:106 | ControlFlowNode for Exception | builtin-class Exception | builtin-class type | 106 | runtime |
186186
| b_condition.py:106 | ControlFlowNode for Exception() | Exception() | builtin-class Exception | 106 | runtime |
187187
| b_condition.py:107 | ControlFlowNode for Str | 'Hello' | builtin-class str | 107 | runtime |
188+
| b_condition.py:109 | ControlFlowNode for FunctionExpr | Function method_check | builtin-class function | 109 | import |
189+
| b_condition.py:109 | ControlFlowNode for method_check | Function method_check | builtin-class function | 109 | import |
188190
| e_temporal.py:2 | ControlFlowNode for ImportExpr | Module sys | builtin-class module | 2 | import |
189191
| e_temporal.py:2 | ControlFlowNode for sys | Module sys | builtin-class module | 2 | import |
190192
| e_temporal.py:4 | ControlFlowNode for FunctionExpr | Function f | builtin-class function | 4 | import |

python/ql/test/library-tests/PointsTo/new/PointsToWithType.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ WARNING: Predicate points_to has been deprecated and may be removed in future (P
185185
| b_condition.py:106 | ControlFlowNode for Exception | builtin-class Exception | builtin-class type | 106 |
186186
| b_condition.py:106 | ControlFlowNode for Exception() | Exception() | builtin-class Exception | 106 |
187187
| b_condition.py:107 | ControlFlowNode for Str | 'Hello' | builtin-class str | 107 |
188+
| b_condition.py:109 | ControlFlowNode for FunctionExpr | Function method_check | builtin-class function | 109 |
189+
| b_condition.py:109 | ControlFlowNode for method_check | Function method_check | builtin-class function | 109 |
188190
| d_globals.py:2 | ControlFlowNode for FunctionExpr | Function j | builtin-class function | 2 |
189191
| d_globals.py:2 | ControlFlowNode for j | Function j | builtin-class function | 2 |
190192
| d_globals.py:3 | ControlFlowNode for Tuple | Tuple | builtin-class tuple | 3 |

python/ql/test/library-tests/PointsTo/new/SSA.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ WARNING: Predicate ssa_variable_points_to has been deprecated and may be removed
8686
| b_condition.py:96 | y_6 = SingleSuccessorGuard(y_5) [false] | NoneType None | builtin-class NoneType |
8787
| b_condition.py:97 | x_3 = ArgumentRefinement(x_2) | NoneType None | builtin-class NoneType |
8888
| b_condition.py:101 | not_or_not_1 = FunctionExpr | Function not_or_not | builtin-class function |
89+
| b_condition.py:109 | method_check_1 = FunctionExpr | Function method_check | builtin-class function |
8990
| c_tests.py:0 | __name___0 = ScopeEntryDefinition | 'code.c_tests' | builtin-class str |
9091
| c_tests.py:4 | f_0 = FunctionExpr | Function f | builtin-class function |
9192
| c_tests.py:5 | x_0 = IfExp | NoneType None | builtin-class NoneType |

python/ql/test/library-tests/PointsTo/new/SourceEdgeDefinitions.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
| b_condition.py:102 | Local Variable a | ControlFlowNode for a |
2121
| b_condition.py:104 | Local Variable a | ControlFlowNode for a |
2222
| b_condition.py:105 | Local Variable a | ControlFlowNode for a |
23+
| b_condition.py:110 | Local Variable x | ControlFlowNode for x |

0 commit comments

Comments
 (0)