Skip to content

Commit ec08041

Browse files
committed
Python points-to: Assorted tweaks to get nore tests passing.
1 parent 3b42f3c commit ec08041

File tree

9 files changed

+38
-26
lines changed

9 files changed

+38
-26
lines changed

python/ql/src/Exceptions/UnguardedNextInGenerator.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FunctionObject iter() {
1616
result = Object::builtin("iter")
1717
}
1818

19-
FunctionObject next() {
19+
BuiltinFunctionObject next() {
2020
result = Object::builtin("next")
2121
}
2222

python/ql/src/analysis/CallGraphEfficiency.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import semmle.python.pointsto.PointsToContext
99

1010
from int total_facts, int total_size, int depth, float efficiency
1111
where
12-
total_facts = strictcount(ControlFlowNode call, FunctionObject func |
12+
total_facts = strictcount(ControlFlowNode call, CallableValue func |
1313
exists(PointsToContext ctx |
14-
call = PointsTo::get_a_call(func, ctx) and
14+
call = func.getACall(ctx) and
1515
depth = ctx.getDepth()
1616
)
1717
)
1818
and
19-
total_size = strictcount(ControlFlowNode call, FunctionObject func, PointsToContext ctx |
20-
call = PointsTo::get_a_call(func, ctx) and
19+
total_size = strictcount(ControlFlowNode call, CallableValue func, PointsToContext ctx |
20+
call = func.getACall(ctx) and
2121
depth = ctx.getDepth()
2222
)
2323
and

python/ql/src/analysis/CallGraphMarginalEfficiency.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import semmle.python.pointsto.PointsToContext
88

99
from int total_facts, int total_size, int depth, float efficiency
1010
where
11-
total_facts = strictcount(ControlFlowNode call, FunctionObject func |
11+
total_facts = strictcount(ControlFlowNode call, CallableValue func |
1212
exists(PointsToContext ctx |
13-
call = PointsTo::get_a_call(func, ctx) and
13+
call = func.getACall(ctx) and
1414
depth = ctx.getDepth()
1515
and not
1616
exists(PointsToContext shallower |
17-
call = PointsTo::get_a_call(func, shallower) and
17+
call = func.getACall(shallower) and
1818
shallower.getDepth() < depth
1919
)
2020
)
2121
)
2222
and
23-
total_size = strictcount(ControlFlowNode call, FunctionObject func, PointsToContext ctx |
24-
call = PointsTo::get_a_call(func, ctx) and
23+
total_size = strictcount(ControlFlowNode call, CallableValue func, PointsToContext ctx |
24+
call = func.getACall(ctx) and
2525
depth = ctx.getDepth()
2626
)
2727
and

python/ql/src/analysis/KeyPointsToFailure.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import python
1212
predicate points_to_failure(Expr e) {
1313
exists(ControlFlowNode f |
1414
f = e.getAFlowNode() |
15-
not f.refersTo(_)
15+
not exists(f.pointsTo())
1616
)
1717
}
1818

python/ql/src/analysis/Pruned.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from int size
66

77
where
88
size = count(ControlFlowNode f |
9-
not PointsTo::Test::reachableBlock(f.getBasicBlock(), _)
9+
not PointsToInternal::reachableBlock(f.getBasicBlock(), _)
1010
)
1111

1212

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,16 @@ predicate issubclass(CallNode fc, ControlFlowNode cls, ControlFlowNode use) {
3131
fc.getArg(0) = use and cls = fc.getArg(1)
3232
}
3333

34+
/** Holds if `c` is a test comparing `x` and `y`. `is` is true if the operator is `is` or `==`, it is false if the operator is `is not` or `!=`. */
35+
predicate equality_test(CompareNode c, ControlFlowNode x, boolean is, ControlFlowNode y) {
36+
exists(Cmpop op |
37+
c.operands(x, op, y) or
38+
c.operands(y, op, x)
39+
|
40+
(is = true and op instanceof Is or
41+
is = false and op instanceof IsNot or
42+
is = true and op instanceof Eq or
43+
is = false and op instanceof NotEq
44+
)
45+
)
46+
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,20 +1145,6 @@ module Expressions {
11451145
)
11461146
}
11471147

1148-
/** Holds if `c` is a test comparing `x` and `y`. `is` is true if the operator is `is` or `==`, it is false if the operator is `is not` or `!=`. */
1149-
private predicate equality_test(CompareNode c, ControlFlowNode x, boolean is, ControlFlowNode y) {
1150-
exists(Cmpop op |
1151-
c.operands(x, op, y) or
1152-
c.operands(y, op, x)
1153-
|
1154-
(is = true and op instanceof Is or
1155-
is = false and op instanceof IsNot or
1156-
is = true and op instanceof Eq or
1157-
is = false and op instanceof NotEq
1158-
)
1159-
)
1160-
}
1161-
11621148
pragma [noinline]
11631149
private boolean inequalityEvaluatesTo(ControlFlowNode expr, PointsToContext context, ControlFlowNode use, ObjectInternal val) {
11641150
exists(ControlFlowNode r, boolean sense |

python/ql/src/semmle/python/types/FunctionObject.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ abstract class BuiltinCallable extends FunctionObject {
257257

258258
abstract override string getQualifiedName();
259259

260+
override ControlFlowNode getArgumentForCall(CallNode call, int n) {
261+
call = this.getACall() and result = call.getArg(n)
262+
}
263+
260264
}
261265

262266
class BuiltinMethodObject extends BuiltinCallable {

python/ql/src/semmle/python/types/Object.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,15 @@ class SuperBoundMethod extends Object {
515515
result = "super()." + name
516516
}
517517

518+
Object getFunction(string fname) {
519+
fname = name and
520+
exists(SuperInstance sup, BoundMethodObjectInternal m |
521+
sup = this.(AttrNode).getObject(name).pointsTo() and
522+
sup.attribute(name, m, _) and
523+
result = m.getFunction().getSource()
524+
)
525+
}
526+
518527
}
519528

520529

0 commit comments

Comments
 (0)