Skip to content

Commit 17681d6

Browse files
committed
Python: factor out helper predicate to prevent bad join-order.
1 parent 9dc6245 commit 17681d6

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,6 @@ module PointsTo {
752752
origin = orig.asCfgNodeOrHere(f)
753753
|
754754
mod.getSourceModule() = f.getEnclosingModule() and
755-
exists(EssaVariable var |
756-
var.getSourceVariable().getName() = name and var.getAUse() = f and
757-
ssa_variable_points_to(var, context, value, cls, orig)
758-
)
759-
or
760-
mod.getSourceModule() = f.getEnclosingModule() and
761755
not exists(EssaVariable var | var.getSourceVariable().getName() = name and var.getAUse() = f) and
762756
exists(EssaVariable dollar |
763757
isModuleStateVariable(dollar) and dollar.getAUse() = f and
@@ -767,6 +761,20 @@ module PointsTo {
767761
not mod.getSourceModule() = f.getEnclosingModule() and
768762
Layer::module_attribute_points_to(mod, name, value, cls, orig)
769763
)
764+
or
765+
exists(EssaVariable var, CfgOrigin orig |
766+
var = ssa_variable_for_module_attribute(f, context) and
767+
ssa_variable_points_to(var, context, value, cls, orig) and
768+
origin = orig.asCfgNodeOrHere(f)
769+
)
770+
}
771+
772+
private EssaVariable ssa_variable_for_module_attribute(ImportMemberNode f, PointsToContext context) {
773+
exists(string name, ModuleObject mod, Module m |
774+
mod.getSourceModule() = m and m = f.getEnclosingModule() and m = result.getScope() and
775+
points_to(f.getModule(name), context, mod, _, _) and
776+
result.getSourceVariable().getName() = name and result.getAUse() = f
777+
)
770778
}
771779

772780
/** Holds if `f` is of the form `getattr(x, "name")` and x.name points to `(value, cls, origin)`. */

0 commit comments

Comments
 (0)