Skip to content

Commit 9971a0c

Browse files
committed
wip3
1 parent 7706ef3 commit 9971a0c

29 files changed

+507
-187
lines changed

rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
private import rust
7-
private import codeql.rust.elements.Call
87
private import ControlFlowGraph
98
private import internal.ControlFlowGraphImpl as CfgImpl
109
private import internal.CfgNodes
@@ -223,13 +222,13 @@ final class MethodCallExprCfgNode extends Nodes::MethodCallExprCfgNode {
223222
*
224223
* This class abstract over the different ways in which a function can be called in Rust.
225224
*/
226-
final class CallCfgNode extends ExprCfgNode {
227-
private Call node;
225+
final class CallExprCfgNode extends ExprCfgNode {
226+
private CallExpr node;
228227

229-
CallCfgNode() { node = this.getAstNode() }
228+
CallExprCfgNode() { node = this.getAstNode() }
230229

231230
/** Gets the underlying `Call`. */
232-
Call getCall() { result = node }
231+
CallExpr getCall() { result = node }
233232

234233
/** Gets the receiver of this call if it is a method call. */
235234
ExprCfgNode getReceiver() {
@@ -243,18 +242,19 @@ final class CallCfgNode extends ExprCfgNode {
243242
}
244243

245244
/**
246-
* A function call expression. For example:
245+
* An expression with parenthesized arguments. For example:
247246
* ```rust
248247
* foo(42);
249248
* foo::<u32, u64>(42);
250249
* foo[0](42);
251250
* foo(1) = 4;
251+
* Option::Some(42);
252252
* ```
253253
*/
254-
final class CallExprCfgNode extends Nodes::CallExprCfgNode {
255-
private CallExprChildMapping node;
254+
final class ParenArgsExprCfgNode extends Nodes::ParenArgsExprCfgNode {
255+
private ParenArgsExprChildMapping node;
256256

257-
CallExprCfgNode() { node = this.getAstNode() }
257+
ParenArgsExprCfgNode() { node = this.getAstNode() }
258258

259259
/** Gets the `i`th argument of this call. */
260260
ExprCfgNode getArgument(int i) {

rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class BreakExprTargetChildMapping extends ParentAstNode, Expr {
5757
override predicate relevantChild(AstNode child) { child.(BreakExpr).getTarget() = this }
5858
}
5959

60-
class CallExprChildMapping extends ParentAstNode, CallExpr {
60+
class ParenArgsExprChildMapping extends ParentAstNode, ParenArgsExpr {
6161
override predicate relevantChild(AstNode child) { child = this.getArgList().getAnArg() }
6262
}
6363

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ module ExprTrees {
292292
}
293293
}
294294

295-
class CallExprTree extends StandardPostOrderTree instanceof CallExpr {
295+
class CallExprTree extends StandardPostOrderTree instanceof ParenArgsExpr {
296296
override AstNode getChildNode(int i) {
297-
i = 0 and result = super.getFunction()
297+
i = 0 and result = super.getBase()
298298
or
299299
result = super.getArgList().getArg(i - 1)
300300
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ newtype TContent =
269269
)]
270270
} or
271271
TFunctionCallReturnContent() or
272-
TFunctionCallArgumentContent(int pos) {
273-
pos in [0 .. any(CallExpr c).getArgList().getNumberOfArgs() - 1]
274-
} or
272+
TFunctionCallArgumentContent(int pos) { pos in [0 .. any(CallExpr c).getNumberOfArgs() - 1] } or
275273
TCapturedVariableContent(VariableCapture::CapturedVariable v) or
276274
TReferenceContent()

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ private import codeql.util.Boolean
88
private import codeql.dataflow.DataFlow
99
private import codeql.dataflow.internal.DataFlowImpl
1010
private import rust
11-
private import codeql.rust.elements.Call
1211
private import SsaImpl as SsaImpl
1312
private import codeql.rust.controlflow.internal.Scope as Scope
1413
private import codeql.rust.internal.PathResolution
@@ -58,7 +57,7 @@ final class DataFlowCallable extends TDataFlowCallable {
5857

5958
final class DataFlowCall extends TDataFlowCall {
6059
/** Gets the underlying function call, if any. */
61-
FunctionCall asFunctionCall() { this = TFunctionCall(result) }
60+
CallExpr asCallExpr() { this = TCallExpr(result) }
6261

6362
predicate isSummaryCall(
6463
FlowSummaryImpl::Public::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNode receiver
@@ -67,13 +66,13 @@ final class DataFlowCall extends TDataFlowCall {
6766
}
6867

6968
DataFlowCallable getEnclosingCallable() {
70-
result.asCfgScope() = this.asFunctionCall().getEnclosingCfgScope()
69+
result.asCfgScope() = this.asCallExpr().getEnclosingCfgScope()
7170
or
7271
this.isSummaryCall(result.asSummarizedCallable(), _)
7372
}
7473

7574
string toString() {
76-
result = this.asFunctionCall().toString()
75+
result = this.asCallExpr().toString()
7776
or
7877
exists(
7978
FlowSummaryImpl::Public::SummarizedCallable c, FlowSummaryImpl::Private::SummaryNode receiver
@@ -83,7 +82,7 @@ final class DataFlowCall extends TDataFlowCall {
8382
)
8483
}
8584

86-
Location getLocation() { result = this.asFunctionCall().getLocation() }
85+
Location getLocation() { result = this.asCallExpr().getLocation() }
8786
}
8887

8988
/**
@@ -131,7 +130,7 @@ final class ParameterPosition extends TParameterPosition {
131130
*/
132131
final class ArgumentPosition extends ParameterPosition {
133132
/** Gets the argument of `call` at this position, if any. */
134-
Expr getArgument(Call call) {
133+
Expr getArgument(CallExpr call) {
135134
result = call.getArgument(this.getPosition())
136135
or
137136
this.isSelf() and result = call.getReceiver()
@@ -141,7 +140,7 @@ final class ArgumentPosition extends ParameterPosition {
141140
/**
142141
* Holds if `arg` is an argument of `call` at the position `pos`.
143142
*/
144-
predicate isArgumentForCall(Expr arg, FunctionCall call, ArgumentPosition pos) {
143+
predicate isArgumentForCall(Expr arg, CallExpr call, ArgumentPosition pos) {
145144
arg = pos.getArgument(call)
146145
}
147146

@@ -291,8 +290,8 @@ predicate lambdaCreationExpr(Expr creation) {
291290
* Holds if `call` is a lambda call of kind `kind` where `receiver` is the
292291
* invoked expression.
293292
*/
294-
predicate lambdaCallExpr(ClosureCall call, LambdaCallKind kind, Expr receiver) {
295-
receiver = call.getFunction() and
293+
predicate lambdaCallExpr(ClosureCallExpr call, LambdaCallKind kind, Expr receiver) {
294+
receiver = call.getClosureExpr() and
296295
exists(kind)
297296
}
298297

@@ -402,7 +401,7 @@ module RustDataFlow implements InputSig<Location> {
402401

403402
/** Gets a viable implementation of the target of the given `Call`. */
404403
DataFlowCallable viableCallable(DataFlowCall call) {
405-
exists(FunctionCall c | c = call.asFunctionCall() |
404+
exists(CallExpr c | c = call.asCallExpr() |
406405
result.asCfgScope() = c.getARuntimeTarget()
407406
or
408407
exists(SummarizedCallable sc, Function staticTarget |
@@ -662,7 +661,7 @@ module RustDataFlow implements InputSig<Location> {
662661

663662
pragma[nomagic]
664663
additional predicate storeContentStep(Node node1, Content c, Node node2) {
665-
exists(CallExpr call, int pos |
664+
exists(ParenArgsExpr call, int pos |
666665
node1.asExpr() = call.getArgument(pragma[only_bind_into](pos)) and
667666
node2.asExpr() = call and
668667
c = TTupleFieldContent(call.getTupleField(pragma[only_bind_into](pos)))
@@ -814,7 +813,7 @@ module RustDataFlow implements InputSig<Location> {
814813
// pointer. Except if the path occurs directly in a call, then it's just a
815814
// call to the function and not a function being passed as data.
816815
resolvePath(e.(PathExpr).getPath()) = c.asCfgScope() and
817-
not any(CallExpr call).getFunction() = e
816+
not any(ParenArgsExpr call).getBase() = e
818817
)
819818
}
820819

@@ -824,7 +823,7 @@ module RustDataFlow implements InputSig<Location> {
824823
*/
825824
predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
826825
(
827-
receiver.asExpr() = call.asFunctionCall().(ClosureCall).getFunction()
826+
receiver.asExpr() = call.asCallExpr().(ClosureCallExpr).getClosureExpr()
828827
or
829828
call.isSummaryCall(_, receiver.(FlowSummaryNode).getSummaryNode())
830829
) and
@@ -986,7 +985,7 @@ private module Cached {
986985

987986
cached
988987
newtype TDataFlowCall =
989-
TFunctionCall(FunctionCall call) {
988+
TCallExpr(CallExpr call) {
990989
Stages::DataFlowStage::ref() and
991990
call.hasEnclosingCfgScope()
992991
} or

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Input implements InputSig<Location, RustDataFlow> {
2222

2323
/** Holds if the associated call resolves to `path`. */
2424
final predicate callResolvesTo(string path) {
25-
path = this.getCall().getStaticTarget().getCanonicalPath()
25+
path = this.getCall().getResolvedTarget().getCanonicalPath()
2626
}
2727
}
2828

@@ -31,19 +31,19 @@ module Input implements InputSig<Location, RustDataFlow> {
3131
abstract class SinkBase extends SourceSinkBase { }
3232

3333
private class CallExprFunction extends SourceBase, SinkBase {
34-
private CallExpr call;
34+
private ParenArgsExpr call;
3535

36-
CallExprFunction() { this = call.getFunction() }
36+
CallExprFunction() { this = call.getBase() }
3737

38-
override CallExpr getCall() { result = call }
38+
override ParenArgsExpr getCall() { result = call }
3939
}
4040

4141
private class MethodCallExprNameRef extends SourceBase, SinkBase {
4242
private MethodCallExpr call;
4343

4444
MethodCallExprNameRef() { this = call.getIdentifier() }
4545

46-
override MethodCallExpr getCall() { result = call }
46+
override CallLikeExpr getCall() { result = call }
4747
}
4848

4949
RustDataFlow::ArgumentPosition callbackSelfParameterPosition() { result.isClosureSelf() }
@@ -129,7 +129,7 @@ private import Make<Location, RustDataFlow, Input> as Impl
129129

130130
private module StepsInput implements Impl::Private::StepsInputSig {
131131
DataFlowCall getACall(Public::SummarizedCallable sc) {
132-
result.asFunctionCall().getStaticTarget() = sc
132+
result.asCallExpr().getStaticTarget() = sc
133133
}
134134

135135
/** Gets the argument of `source` described by `sc`, if any. */
@@ -172,7 +172,7 @@ private module StepsInput implements Impl::Private::StepsInputSig {
172172
}
173173

174174
RustDataFlow::Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) {
175-
exists(Call call, Expr arg, ArgumentPosition pos |
175+
exists(CallLikeExpr call, Expr arg, ArgumentPosition pos |
176176
result.asExpr() = arg and
177177
sc = Impl::Private::SummaryComponent::argument(pos) and
178178
call = sink.getCall() and

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ abstract class ArgumentNode extends Node {
224224
}
225225

226226
final class ExprArgumentNode extends ArgumentNode, ExprNode {
227-
private FunctionCall call_;
227+
private CallExpr call_;
228228
private RustDataFlow::ArgumentPosition pos_;
229229

230230
ExprArgumentNode() {
@@ -234,7 +234,7 @@ final class ExprArgumentNode extends ArgumentNode, ExprNode {
234234
}
235235

236236
override predicate isArgumentOf(DataFlowCall call, RustDataFlow::ArgumentPosition pos) {
237-
call.asFunctionCall() = call_ and pos = pos_
237+
call.asCallExpr() = call_ and pos = pos_
238238
}
239239
}
240240

@@ -269,7 +269,7 @@ final class DerefBorrowArgNode extends DerefBorrowNode, ArgumentNode {
269269
private DataFlowCall call_;
270270
private RustDataFlow::ArgumentPosition pos_;
271271

272-
DerefBorrowArgNode() { isArgumentForCall(n, call_.asFunctionCall(), pos_) }
272+
DerefBorrowArgNode() { isArgumentForCall(n, call_.asCallExpr(), pos_) }
273273

274274
override predicate isArgumentOf(DataFlowCall call, RustDataFlow::ArgumentPosition pos) {
275275
call = call_ and pos = pos_
@@ -299,7 +299,7 @@ final class ClosureArgumentNode extends ArgumentNode, ExprNode {
299299
ClosureArgumentNode() { lambdaCallExpr(call_, _, this.asExpr()) }
300300

301301
override predicate isArgumentOf(DataFlowCall call, RustDataFlow::ArgumentPosition pos) {
302-
call.asFunctionCall() = call_ and pos.isClosureSelf()
302+
call.asCallExpr() = call_ and pos.isClosureSelf()
303303
}
304304
}
305305

@@ -347,11 +347,11 @@ abstract class OutNode extends Node {
347347
}
348348

349349
final private class ExprOutNode extends ExprNode, OutNode {
350-
ExprOutNode() { this.asExpr() instanceof FunctionCall }
350+
ExprOutNode() { this.asExpr() instanceof CallExpr }
351351

352352
/** Gets the underlying call CFG node that includes this out node. */
353353
override DataFlowCall getCall(ReturnKind kind) {
354-
result.asFunctionCall() = n and
354+
result.asCallExpr() = n and
355355
kind = TNormalReturnKind()
356356
}
357357
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private predicate variableWriteInOuterScope(BasicBlock bb, int i, Variable v, Cf
154154
}
155155

156156
/** Holds if evaluating `e` jumps to the evaluation of a different CFG scope. */
157-
private predicate isControlFlowJump(Expr e) { e instanceof FunctionCall or e instanceof AwaitExpr }
157+
private predicate isControlFlowJump(Expr e) { e instanceof CallExpr or e instanceof AwaitExpr }
158158

159159
/**
160160
* Holds if the call `call` at index `i` in basic block `bb` may reach
@@ -325,7 +325,7 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
325325

326326
predicate ssaDefHasSource(WriteDefinition def) { none() } // handled in `DataFlowImpl.qll` instead
327327

328-
private predicate isArg(FunctionCall call, Expr e) {
328+
private predicate isArg(CallExpr call, Expr e) {
329329
call.getAnArgument() = e
330330
or
331331
call.getReceiver() = e

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

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

0 commit comments

Comments
 (0)