@@ -8,7 +8,6 @@ private import codeql.util.Boolean
88private import codeql.dataflow.DataFlow
99private import codeql.dataflow.internal.DataFlowImpl
1010private import rust
11- private import codeql.rust.elements.Call
1211private import SsaImpl as SsaImpl
1312private import codeql.rust.controlflow.internal.Scope as Scope
1413private import codeql.rust.internal.PathResolution
@@ -57,8 +56,8 @@ final class DataFlowCallable extends TDataFlowCallable {
5756}
5857
5958final class DataFlowCall extends TDataFlowCall {
60- /** Gets the underlying call in the CFG , if any. */
61- Call asCall ( ) { this = TCall ( result ) }
59+ /** Gets the underlying function call , if any. */
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 .asCall ( ) .getEnclosingCfgScope ( )
69+ result .asCfgScope ( ) = this .asCallExpr ( ) .getEnclosingCfgScope ( )
7170 or
7271 this .isSummaryCall ( result .asSummarizedCallable ( ) , _)
7372 }
7473
7574 string toString ( ) {
76- result = this .asCall ( ) .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 .asCall ( ) .getLocation ( ) }
85+ Location getLocation ( ) { result = this .asCallExpr ( ) .getLocation ( ) }
8786}
8887
8988/**
@@ -131,8 +130,8 @@ final class ParameterPosition extends TParameterPosition {
131130 */
132131final class ArgumentPosition extends ParameterPosition {
133132 /** Gets the argument of `call` at this position, if any. */
134- Expr getArgument ( Call call ) {
135- result = call .getPositionalArgument ( this .getPosition ( ) )
133+ Expr getArgument ( CallExpr call ) {
134+ result = call .getArgument ( this .getPosition ( ) )
136135 or
137136 this .isSelf ( ) and result = call .getReceiver ( )
138137 }
@@ -141,9 +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 , Call call , ArgumentPosition pos ) {
145- // TODO: Handle index expressions as calls in data flow.
146- not call instanceof IndexExpr and
143+ predicate isArgumentForCall ( Expr arg , CallExpr call , ArgumentPosition pos ) {
147144 arg = pos .getArgument ( call )
148145}
149146
@@ -293,10 +290,8 @@ predicate lambdaCreationExpr(Expr creation) {
293290 * Holds if `call` is a lambda call of kind `kind` where `receiver` is the
294291 * invoked expression.
295292 */
296- predicate lambdaCallExpr ( CallExpr call , LambdaCallKind kind , Expr receiver ) {
297- receiver = call .getFunction ( ) and
298- // All calls to complex expressions and local variable accesses are lambda call.
299- ( receiver instanceof PathExpr implies receiver = any ( Variable v ) .getAnAccess ( ) ) and
293+ predicate lambdaCallExpr ( ClosureCallExpr call , LambdaCallKind kind , Expr receiver ) {
294+ receiver = call .getClosureExpr ( ) and
300295 exists ( kind )
301296}
302297
@@ -406,7 +401,7 @@ module RustDataFlow implements InputSig<Location> {
406401
407402 /** Gets a viable implementation of the target of the given `Call`. */
408403 DataFlowCallable viableCallable ( DataFlowCall call ) {
409- exists ( Call c | c = call .asCall ( ) |
404+ exists ( CallExpr c | c = call .asCallExpr ( ) |
410405 result .asCfgScope ( ) = c .getARuntimeTarget ( )
411406 or
412407 exists ( SummarizedCallable sc , Function staticTarget |
@@ -666,8 +661,8 @@ module RustDataFlow implements InputSig<Location> {
666661
667662 pragma [ nomagic]
668663 additional predicate storeContentStep ( Node node1 , Content c , Node node2 ) {
669- exists ( CallExpr call , int pos |
670- node1 .asExpr ( ) = call .getArg ( pragma [ only_bind_into ] ( pos ) ) and
664+ exists ( ParenArgsExpr call , int pos |
665+ node1 .asExpr ( ) = call .getArgument ( pragma [ only_bind_into ] ( pos ) ) and
671666 node2 .asExpr ( ) = call and
672667 c = TTupleFieldContent ( call .getTupleField ( pragma [ only_bind_into ] ( pos ) ) )
673668 )
@@ -818,7 +813,7 @@ module RustDataFlow implements InputSig<Location> {
818813 // pointer. Except if the path occurs directly in a call, then it's just a
819814 // call to the function and not a function being passed as data.
820815 resolvePath ( e .( PathExpr ) .getPath ( ) ) = c .asCfgScope ( ) and
821- not any ( CallExpr call ) .getFunction ( ) = e
816+ not any ( ParenArgsExpr call ) .getBase ( ) = e
822817 )
823818 }
824819
@@ -828,11 +823,7 @@ module RustDataFlow implements InputSig<Location> {
828823 */
829824 predicate lambdaCall ( DataFlowCall call , LambdaCallKind kind , Node receiver ) {
830825 (
831- receiver .asExpr ( ) = call .asCall ( ) .( CallExpr ) .getFunction ( ) and
832- // All calls to complex expressions and local variable accesses are lambda call.
833- exists ( Expr f | f = receiver .asExpr ( ) |
834- f instanceof PathExpr implies f = any ( Variable v ) .getAnAccess ( )
835- )
826+ receiver .asExpr ( ) = call .asCallExpr ( ) .( ClosureCallExpr ) .getClosureExpr ( )
836827 or
837828 call .isSummaryCall ( _, receiver .( FlowSummaryNode ) .getSummaryNode ( ) )
838829 ) and
@@ -994,11 +985,9 @@ private module Cached {
994985
995986 cached
996987 newtype TDataFlowCall =
997- TCall ( Call call ) {
988+ TCallExpr ( CallExpr call ) {
998989 Stages:: DataFlowStage:: ref ( ) and
999- call .hasEnclosingCfgScope ( ) and
1000- // TODO: Handle index expressions as calls in data flow.
1001- not call instanceof IndexExpr
990+ call .hasEnclosingCfgScope ( )
1002991 } or
1003992 TSummaryCall (
1004993 FlowSummaryImpl:: Public:: SummarizedCallable c , FlowSummaryImpl:: Private:: SummaryNode receiver
@@ -1026,10 +1015,8 @@ private module Cached {
10261015 cached
10271016 newtype TParameterPosition =
10281017 TPositionalParameterPosition ( int i ) {
1029- i in [ 0 .. max ( [ any ( ParamList l ) .getNumberOfParams ( ) , any ( ArgList l ) .getNumberOfArgs ( ) ] ) - 1 ]
1030- or
1031- FlowSummaryImpl:: ParsePositions:: isParsedArgumentPosition ( _, i )
1032- or
1018+ i in [ 0 .. max ( [ any ( ParamList l ) .getNumberOfParams ( ) , any ( ArgList l ) .getNumberOfArgs ( ) ] ) - 1 ] or
1019+ FlowSummaryImpl:: ParsePositions:: isParsedArgumentPosition ( _, i ) or
10331020 FlowSummaryImpl:: ParsePositions:: isParsedParameterPosition ( _, i )
10341021 } or
10351022 TClosureSelfParameterPosition ( ) or
0 commit comments