@@ -10,6 +10,7 @@ private import codeql.dataflow.internal.DataFlowImpl
1010private import rust
1111private import SsaImpl as SsaImpl
1212private import codeql.rust.controlflow.internal.Scope as Scope
13+ private import codeql.rust.elements.internal.CallExprImpl:: Impl as CallExprImpl
1314private import codeql.rust.internal.PathResolution
1415private import codeql.rust.controlflow.ControlFlowGraph
1516private import codeql.rust.dataflow.Ssa
@@ -85,62 +86,10 @@ final class DataFlowCall extends TDataFlowCall {
8586 Location getLocation ( ) { result = this .asCall ( ) .getLocation ( ) }
8687}
8788
88- /**
89- * The position of a parameter in a function.
90- *
91- * In Rust there is a 1-to-1 correspondence between parameter positions and
92- * arguments positions, so we use the same underlying type for both.
93- */
94- final class ParameterPosition extends TParameterPosition {
95- /** Gets the underlying integer position, if any. */
96- int getPosition ( ) { this = TPositionalParameterPosition ( result ) }
97-
98- predicate hasPosition ( ) { exists ( this .getPosition ( ) ) }
99-
100- /** Holds if this position represents the `self` position. */
101- predicate isSelf ( ) { this = TSelfParameterPosition ( ) }
102-
103- /**
104- * Holds if this position represents a reference to a closure itself. Only
105- * used for tracking flow through captured variables.
106- */
107- predicate isClosureSelf ( ) { this = TClosureSelfParameterPosition ( ) }
108-
109- /** Gets a textual representation of this position. */
110- string toString ( ) {
111- result = this .getPosition ( ) .toString ( )
112- or
113- result = "self" and this .isSelf ( )
114- or
115- result = "closure self" and this .isClosureSelf ( )
116- }
117-
118- ParamBase getParameterIn ( ParamList ps ) {
119- result = ps .getParam ( this .getPosition ( ) )
120- or
121- result = ps .getSelfParam ( ) and this .isSelf ( )
122- }
123- }
124-
125- /**
126- * The position of an argument in a call.
127- *
128- * In Rust there is a 1-to-1 correspondence between parameter positions and
129- * arguments positions, so we use the same underlying type for both.
130- */
131- final class ArgumentPosition extends ParameterPosition {
132- /** Gets the argument of `call` at this position, if any. */
133- Expr getArgument ( Call call ) {
134- result = call .getPositionalArgument ( this .getPosition ( ) )
135- or
136- result = call .( MethodCall ) .getReceiver ( ) and this .isSelf ( )
137- }
138- }
139-
14089/**
14190 * Holds if `arg` is an argument of `call` at the position `pos`.
14291 */
143- predicate isArgumentForCall ( Expr arg , Call call , ArgumentPosition pos ) {
92+ predicate isArgumentForCall ( Expr arg , Call call , RustDataFlow :: ArgumentPosition pos ) {
14493 // TODO: Handle index expressions as calls in data flow.
14594 not call instanceof IndexExpr and
14695 arg = pos .getArgument ( call )
@@ -292,8 +241,8 @@ predicate lambdaCreationExpr(Expr creation) {
292241 * Holds if `call` is a lambda call of kind `kind` where `receiver` is the
293242 * invoked expression.
294243 */
295- predicate lambdaCallExpr ( ClosureCallExpr call , LambdaCallKind kind , Expr receiver ) {
296- receiver = call .getClosureExpr ( ) and
244+ predicate lambdaCallExpr ( CallExprImpl :: DynamicCallExpr call , LambdaCallKind kind , Expr receiver ) {
245+ receiver = call .getFunction ( ) and
297246 exists ( kind )
298247}
299248
@@ -305,10 +254,6 @@ private module Aliases {
305254
306255 class DataFlowCallAlias = DataFlowCall ;
307256
308- class ParameterPositionAlias = ParameterPosition ;
309-
310- class ArgumentPositionAlias = ArgumentPosition ;
311-
312257 class ContentAlias = Content ;
313258
314259 class ContentSetAlias = ContentSet ;
@@ -340,6 +285,58 @@ module RustDataFlow implements InputSig<Location> {
340285
341286 final class CastNode = Node:: CastNode ;
342287
288+ /**
289+ * The position of a parameter in a function.
290+ *
291+ * In Rust there is a 1-to-1 correspondence between parameter positions and
292+ * arguments positions, so we use the same underlying type for both.
293+ */
294+ final class ParameterPosition extends TParameterPosition {
295+ /** Gets the underlying integer position, if any. */
296+ int getPosition ( ) { this = TPositionalParameterPosition ( result ) }
297+
298+ predicate hasPosition ( ) { exists ( this .getPosition ( ) ) }
299+
300+ /** Holds if this position represents the `self` position. */
301+ predicate isSelf ( ) { this = TSelfParameterPosition ( ) }
302+
303+ /**
304+ * Holds if this position represents a reference to a closure itself. Only
305+ * used for tracking flow through captured variables.
306+ */
307+ predicate isClosureSelf ( ) { this = TClosureSelfParameterPosition ( ) }
308+
309+ /** Gets a textual representation of this position. */
310+ string toString ( ) {
311+ result = this .getPosition ( ) .toString ( )
312+ or
313+ result = "self" and this .isSelf ( )
314+ or
315+ result = "closure self" and this .isClosureSelf ( )
316+ }
317+
318+ ParamBase getParameterIn ( ParamList ps ) {
319+ result = ps .getParam ( this .getPosition ( ) )
320+ or
321+ result = ps .getSelfParam ( ) and this .isSelf ( )
322+ }
323+ }
324+
325+ /**
326+ * The position of an argument in a call.
327+ *
328+ * In Rust there is a 1-to-1 correspondence between parameter positions and
329+ * arguments positions, so we use the same underlying type for both.
330+ */
331+ final class ArgumentPosition extends ParameterPosition {
332+ /** Gets the argument of `call` at this position, if any. */
333+ Expr getArgument ( Call call ) {
334+ result = call .getPositionalArgument ( this .getPosition ( ) )
335+ or
336+ result = call .( MethodCall ) .getReceiver ( ) and this .isSelf ( )
337+ }
338+ }
339+
343340 /** Holds if `p` is a parameter of `c` at the position `pos`. */
344341 predicate isParameterNode ( ParameterNode p , DataFlowCallable c , ParameterPosition pos ) {
345342 p .isParameterOf ( c , pos )
@@ -449,10 +446,6 @@ module RustDataFlow implements InputSig<Location> {
449446
450447 ContentApprox getContentApprox ( Content c ) { result = c }
451448
452- class ParameterPosition = ParameterPositionAlias ;
453-
454- class ArgumentPosition = ArgumentPositionAlias ;
455-
456449 /**
457450 * Holds if the parameter position `ppos` matches the argument position
458451 * `apos`.
@@ -664,7 +657,7 @@ module RustDataFlow implements InputSig<Location> {
664657 pragma [ nomagic]
665658 additional predicate storeContentStep ( Node node1 , Content c , Node node2 ) {
666659 exists ( CallExpr ce , TupleField tf , int pos |
667- node1 .asExpr ( ) = ce .getSyntacticArgument ( pos ) and
660+ node1 .asExpr ( ) = ce .getSyntacticPositionalArgument ( pos ) and
668661 node2 .asExpr ( ) = ce and
669662 c = TTupleFieldContent ( tf )
670663 |
@@ -716,7 +709,7 @@ module RustDataFlow implements InputSig<Location> {
716709 exists ( DataFlowCall call , int i |
717710 isArgumentNode ( node1 , call , TPositionalParameterPosition ( i ) ) and
718711 lambdaCall ( call , _, node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ) and
719- c .( ClosureCallArgumentContent ) .getPosition ( ) = i
712+ c .( FunctionCallArgumentContent ) .getPosition ( ) = i
720713 )
721714 or
722715 VariableCapture:: storeStep ( node1 , c , node2 )
@@ -825,7 +818,7 @@ module RustDataFlow implements InputSig<Location> {
825818 */
826819 predicate lambdaCall ( DataFlowCall call , LambdaCallKind kind , Node receiver ) {
827820 (
828- receiver .asExpr ( ) = call .asCall ( ) .( ClosureCallExpr ) . getClosureExpr ( )
821+ receiver .asExpr ( ) = call .asCall ( ) .( CallExprImpl :: DynamicCallExpr ) . getFunction ( )
829822 or
830823 call .isSummaryCall ( _, receiver .( FlowSummaryNode ) .getSummaryNode ( ) )
831824 ) and
0 commit comments