Skip to content

Commit a7fcf52

Browse files
authored
Python: Fix bad join in total_cost
The recent change to `appliesTo` lead to a perturbation in the join order of this predicate, which resulted in a cartesian product between `call` and `ctx` being created (before being filtered by `appliesTo`). By splitting the intermediate result into its own helper predicate, suitably marked to prevent inlining/magic, we prevent this from happening again.
1 parent 591ac38 commit a7fcf52

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

python/ql/src/semmle/python/pointsto/PointsToContext.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ private int total_call_cost(CallNode call) {
100100
if call_to_init_or_del(call) then result = 1 else result = call_cost(call) + splay_cost(call)
101101
}
102102

103+
pragma[nomagic]
104+
private int relevant_call_cost(PointsToContext ctx, CallNode call) {
105+
ctx.appliesTo(call) and result = total_call_cost(call)
106+
}
107+
103108
pragma[noinline]
104109
private int total_cost(CallNode call, PointsToContext ctx) {
105-
ctx.appliesTo(call) and
106-
result = total_call_cost(call) + context_cost(ctx)
110+
result = relevant_call_cost(ctx, call) + context_cost(ctx)
107111
}
108112

109113
cached

0 commit comments

Comments
 (0)