Skip to content

Commit 7706ef3

Browse files
committed
wip
1 parent eef3ded commit 7706ef3

File tree

7 files changed

+30
-74
lines changed

7 files changed

+30
-74
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Input implements InputSig<Location, RustDataFlow> {
1818

1919
abstract private class SourceSinkBase extends AstNode {
2020
/** Gets the associated call. */
21-
abstract Call getCall();
21+
abstract CallLikeExpr getCall();
2222

2323
/** Holds if the associated call resolves to `path`. */
2424
final predicate callResolvesTo(string path) {

rust/ql/lib/codeql/rust/elements/Call.qll

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,40 @@
33
*/
44

55
private import rust
6-
private import internal.CallImpl
6+
private import internal.CallLikeExprImpl
77

8-
final class Call = Impl::Call;
9-
10-
private predicate isClosureCall(CallExpr call) {
11-
exists(Expr receiver | receiver = call.getFunction() |
12-
// All calls to complex expressions and local variable accesses are lambda calls
13-
receiver instanceof PathExpr implies receiver = any(Variable v).getAnAccess()
14-
)
15-
}
8+
final class CallLikeExpr = Impl::CallLikeExpr;
169

1710
/**
1811
* Holds if `call` is guaranteed to be a method call, even if we cannot resolve
1912
* its target.
2013
*/
21-
private predicate isGuaranteedMethodCall(Call call) {
14+
private predicate isGuaranteedMethodCall(CallLikeExpr call) {
2215
call instanceof MethodCallExpr
2316
or
2417
call.(Operation).isOverloaded(_, _, _)
2518
or
2619
call instanceof IndexExpr
2720
}
2821

22+
/**
23+
* A call expression.
24+
*/
25+
final class Call extends CallLikeExpr {
26+
Call() {
27+
forall(Addressable target | target = this.getStaticTarget() | target instanceof Callable)
28+
or
29+
isGuaranteedMethodCall(this)
30+
}
31+
}
32+
33+
private predicate isClosureCall(CallExpr call) {
34+
exists(Expr receiver | receiver = call.getFunction() |
35+
// All calls to complex expressions and local variable accesses are lambda calls
36+
receiver instanceof PathExpr implies receiver = any(Variable v).getAnAccess()
37+
)
38+
}
39+
2940
/**
3041
* A call expression that targets a function or a closure.
3142
*

rust/ql/lib/codeql/rust/elements/internal/CallImpl.qll

Lines changed: 0 additions & 54 deletions
This file was deleted.

rust/ql/lib/codeql/rust/elements/internal/IndexExprImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private import codeql.rust.elements.internal.generated.IndexExpr
1111
* be referenced directly.
1212
*/
1313
module Impl {
14-
private import codeql.rust.elements.internal.CallImpl::Impl as CallImpl
14+
private import codeql.rust.elements.internal.CallLikeExprImpl::Impl as CallLikeExprImpl
1515

1616
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1717
/**
@@ -21,7 +21,7 @@ module Impl {
2121
* list[42] = 1;
2222
* ```
2323
*/
24-
class IndexExpr extends Generated::IndexExpr, CallImpl::Call {
24+
class IndexExpr extends Generated::IndexExpr, CallLikeExprImpl::CallLikeExpr {
2525
override string toStringImpl() {
2626
result =
2727
this.getBase().toAbbreviatedString() + "[" + this.getIndex().toAbbreviatedString() + "]"

rust/ql/lib/codeql/rust/elements/internal/MethodCallExprImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private import codeql.rust.elements.internal.generated.MethodCallExpr
1212
* be referenced directly.
1313
*/
1414
module Impl {
15-
private import codeql.rust.elements.internal.CallImpl::Impl as CallImpl
15+
private import codeql.rust.elements.internal.CallLikeExprImpl::Impl as CallLikeExprImpl
1616

1717
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1818
/**
@@ -25,7 +25,7 @@ module Impl {
2525
* Consider using `MethodCall` instead, as that also includes calls to methods using
2626
* function call syntax (e.g., `Foo::method(x)`).
2727
*/
28-
class MethodCallExpr extends Generated::MethodCallExpr, CallImpl::Call {
28+
class MethodCallExpr extends Generated::MethodCallExpr, CallLikeExprImpl::CallLikeExpr {
2929
private string toStringPart(int index) {
3030
index = 0 and
3131
result = this.getReceiver().toAbbreviatedString()

rust/ql/lib/codeql/rust/elements/internal/OperationImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl
1212
* be referenced directly.
1313
*/
1414
module Impl {
15-
private import codeql.rust.elements.internal.CallImpl::Impl as CallImpl
15+
private import codeql.rust.elements.internal.CallLikeExprImpl::Impl as CallLikeExprImpl
1616

1717
/**
1818
* Holds if the operator `op` with arity `arity` is overloaded to a trait with
@@ -102,7 +102,7 @@ module Impl {
102102
/**
103103
* An operation, for example `&&`, `+=`, `!` or `*`.
104104
*/
105-
abstract class Operation extends CallImpl::Call {
105+
abstract class Operation extends CallLikeExprImpl::CallLikeExpr {
106106
/** Gets the operator name of this operation, if it exists. */
107107
abstract string getOperatorName();
108108

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ private import codeql.typeinference.internal.TypeInference
1414
private import codeql.rust.frameworks.stdlib.Stdlib
1515
private import codeql.rust.frameworks.stdlib.Builtins as Builtins
1616
private import codeql.rust.elements.Call
17-
private import codeql.rust.elements.internal.CallImpl::Impl as CallImpl
1817
private import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl
1918

2019
class Type = T::Type;
@@ -1363,7 +1362,7 @@ private module MethodResolution {
13631362
*
13641363
* [1]: https://doc.rust-lang.org/std/ops/trait.Index.html
13651364
*/
1366-
abstract class MethodCall extends Call {
1365+
abstract class MethodCall extends CallLikeExpr {
13671366
abstract predicate hasNameAndArity(string name, int arity);
13681367

13691368
abstract Expr getArg(ArgumentPosition pos);
@@ -3484,7 +3483,7 @@ private module Cached {
34843483

34853484
/** Gets an item (function or tuple struct/variant) that `call` resolves to, if any. */
34863485
cached
3487-
Addressable resolveCallTarget(Call call) {
3486+
Addressable resolveCallTarget(CallLikeExpr call) {
34883487
result = call.(MethodResolution::MethodCall).resolveCallTarget(_, _, _)
34893488
or
34903489
result = call.(NonMethodResolution::NonMethodCall).resolveCallTarget()

0 commit comments

Comments
 (0)