@@ -14,6 +14,7 @@ private import codeql.rust.controlflow.ControlFlowGraph
1414private import codeql.rust.controlflow.CfgNodes
1515private import codeql.rust.dataflow.Ssa
1616private import codeql.rust.dataflow.FlowSummary
17+ private import codeql.rust.internal.TypeInference as TypeInference
1718private import Node as Node
1819private import DataFlowImpl
1920private import FlowSummaryImpl as FlowSummaryImpl
@@ -238,35 +239,37 @@ final class ExprArgumentNode extends ArgumentNode, ExprNode {
238239 private Call call_ ;
239240 private RustDataFlow:: ArgumentPosition pos_ ;
240241
241- ExprArgumentNode ( ) { isArgumentForCall ( n , call_ , pos_ ) }
242+ ExprArgumentNode ( ) {
243+ isArgumentForCall ( n , call_ , pos_ ) and
244+ not TypeInference:: argumentHasImplicitBorrow ( n ) and
245+ not TypeInference:: receiverHasImplicitDeref ( n )
246+ }
242247
243248 override predicate isArgumentOf ( DataFlowCall call , RustDataFlow:: ArgumentPosition pos ) {
244249 call .asCall ( ) = call_ and pos = pos_
245250 }
246251}
247252
248253/**
249- * The receiver of a method call _after_ any implicit borrow or dereferencing
254+ * The argument of a call _after_ any implicit borrow or dereferencing
250255 * has taken place.
251256 */
252- final class ReceiverNode extends ArgumentNode , TReceiverNode {
253- private Call n ;
254-
255- ReceiverNode ( ) { this = TReceiverNode ( n , false ) }
257+ final class ArgBorrowNode extends ArgumentNode , TArgBorrowNode {
258+ private Expr arg ;
256259
257- Expr getReceiver ( ) { result = n . getReceiver ( ) }
260+ ArgBorrowNode ( ) { this = TArgBorrowNode ( arg , false ) }
258261
259- MethodCallExpr getMethodCall ( ) { result = n }
262+ Expr getArg ( ) { result = arg }
260263
261264 override predicate isArgumentOf ( DataFlowCall call , RustDataFlow:: ArgumentPosition pos ) {
262- call .asCall ( ) = n and pos = TReceiverArgumentPosition ( )
265+ isArgumentForCall ( arg , call .asCall ( ) , pos )
263266 }
264267
265- override CfgScope getCfgScope ( ) { result = n .getEnclosingCfgScope ( ) }
268+ override CfgScope getCfgScope ( ) { result = arg .getEnclosingCfgScope ( ) }
266269
267- override Location getLocation ( ) { result = this . getReceiver ( ) .getLocation ( ) }
270+ override Location getLocation ( ) { result = arg .getLocation ( ) }
268271
269- override string toString ( ) { result = "receiver for " + this . getReceiver ( ) }
272+ override string toString ( ) { result = "receiver for " + arg }
270273}
271274
272275final class SummaryArgumentNode extends FlowSummaryNode , ArgumentNode {
@@ -414,16 +417,16 @@ final class ExprPostUpdateNode extends PostUpdateNode, TExprPostUpdateNode {
414417 override Location getLocation ( ) { result = e .getLocation ( ) }
415418}
416419
417- final class ReceiverPostUpdateNode extends PostUpdateNode , TReceiverNode {
418- private Call call ;
420+ final class ArgBorrowPostUpdateNode extends PostUpdateNode , TArgBorrowNode {
421+ private Expr arg ;
419422
420- ReceiverPostUpdateNode ( ) { this = TReceiverNode ( call , true ) }
423+ ArgBorrowPostUpdateNode ( ) { this = TArgBorrowNode ( arg , true ) }
421424
422- override Node getPreUpdateNode ( ) { result = TReceiverNode ( call , false ) }
425+ override Node getPreUpdateNode ( ) { result = TArgBorrowNode ( arg , false ) }
423426
424- override CfgScope getCfgScope ( ) { result = call .getEnclosingCfgScope ( ) }
427+ override CfgScope getCfgScope ( ) { result = arg .getEnclosingCfgScope ( ) }
425428
426- override Location getLocation ( ) { result = call . getReceiver ( ) .getLocation ( ) }
429+ override Location getLocation ( ) { result = arg .getLocation ( ) }
427430}
428431
429432final class SummaryPostUpdateNode extends FlowSummaryNode , PostUpdateNode {
@@ -486,11 +489,13 @@ newtype TNode =
486489 ]
487490 )
488491 } or
489- TReceiverNode ( Call call , Boolean isPost ) {
490- call .hasEnclosingCfgScope ( ) and
491- call .receiverImplicitlyBorrowed ( ) and
492+ TArgBorrowNode ( Expr arg , Boolean isPost ) {
492493 // TODO: Handle index expressions as calls in data flow.
493- not call instanceof IndexExpr
494+ not arg = any ( IndexExpr ie ) .getBase ( ) and
495+ (
496+ TypeInference:: argumentHasImplicitBorrow ( arg ) or
497+ TypeInference:: receiverHasImplicitDeref ( arg )
498+ )
494499 } or
495500 TSsaNode ( SsaImpl:: DataFlowIntegration:: SsaNode node ) or
496501 TFlowSummaryNode ( FlowSummaryImpl:: Private:: SummaryNode sn ) or
0 commit comments