@@ -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 CallCfgNode 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 .getExpr ( ) ) and
245+ not TypeInference:: receiverHasImplicitDeref ( n .getExpr ( ) )
246+ }
242247
243248 override predicate isArgumentOf ( DataFlowCall call , RustDataFlow:: ArgumentPosition pos ) {
244249 call .asCallCfgNode ( ) = 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 CallCfgNode n ;
254-
255- ReceiverNode ( ) { this = TReceiverNode ( n , false ) }
257+ final class ArgBorrowNode extends ArgumentNode , TArgBorrowNode {
258+ private ExprCfgNode arg ;
256259
257- ExprCfgNode getReceiver ( ) { result = n . getReceiver ( ) }
260+ ArgBorrowNode ( ) { this = TArgBorrowNode ( arg , false ) }
258261
259- MethodCallExprCfgNode getMethodCall ( ) { result = n }
262+ ExprCfgNode getArg ( ) { result = arg }
260263
261264 override predicate isArgumentOf ( DataFlowCall call , RustDataFlow:: ArgumentPosition pos ) {
262- call .asCallCfgNode ( ) = n and pos = TReceiverArgumentPosition ( )
265+ isArgumentForCall ( arg , call .asCallCfgNode ( ) , pos )
263266 }
264267
265- override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
268+ override CfgScope getCfgScope ( ) { result = arg .getAstNode ( ) .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 = n .getLocation ( ) }
415418}
416419
417- final class ReceiverPostUpdateNode extends PostUpdateNode , TReceiverNode {
418- private CallCfgNode n ;
420+ final class ArgBorrowPostUpdateNode extends PostUpdateNode , TArgBorrowNode {
421+ private ExprCfgNode arg ;
419422
420- ReceiverPostUpdateNode ( ) { this = TReceiverNode ( n , true ) }
423+ ArgBorrowPostUpdateNode ( ) { this = TArgBorrowNode ( arg , true ) }
421424
422- override Node getPreUpdateNode ( ) { result = TReceiverNode ( n , false ) }
425+ override Node getPreUpdateNode ( ) { result = TArgBorrowNode ( arg , false ) }
423426
424- override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
427+ override CfgScope getCfgScope ( ) { result = arg .getAstNode ( ) .getEnclosingCfgScope ( ) }
425428
426- override Location getLocation ( ) { result = n . getReceiver ( ) .getLocation ( ) }
429+ override Location getLocation ( ) { result = arg .getLocation ( ) }
427430}
428431
429432final class SummaryPostUpdateNode extends FlowSummaryNode , PostUpdateNode {
@@ -483,10 +486,15 @@ newtype TNode =
483486 getPostUpdateReverseStep ( any ( PostUpdateNode n ) .getPreUpdateNode ( ) .asExpr ( ) , _)
484487 ]
485488 } or
486- TReceiverNode ( CallCfgNode mc , Boolean isPost ) {
487- mc .getCall ( ) .receiverImplicitlyBorrowed ( ) and
488- // TODO: Handle index expressions as calls in data flow.
489- not mc .getCall ( ) instanceof IndexExpr
489+ TArgBorrowNode ( ExprCfgNode arg , Boolean isPost ) {
490+ exists ( Expr e |
491+ e = arg .getExpr ( ) and
492+ // TODO: Handle index expressions as calls in data flow.
493+ not e = any ( IndexExpr ie ) .getBase ( )
494+ |
495+ TypeInference:: argumentHasImplicitBorrow ( e ) or
496+ TypeInference:: receiverHasImplicitDeref ( e )
497+ )
490498 } or
491499 TSsaNode ( SsaImpl:: DataFlowIntegration:: SsaNode node ) or
492500 TFlowSummaryNode ( FlowSummaryImpl:: Private:: SummaryNode sn ) or
0 commit comments