@@ -12,7 +12,6 @@ private import codeql.rust.elements.Call
1212private import SsaImpl as SsaImpl
1313private import codeql.rust.controlflow.internal.Scope as Scope
1414private import codeql.rust.internal.PathResolution
15- private import codeql.rust.internal.TypeInference as TypeInference
1615private import codeql.rust.controlflow.ControlFlowGraph
1716private import codeql.rust.dataflow.Ssa
1817private import codeql.rust.dataflow.FlowSummary
@@ -135,24 +134,17 @@ final class ArgumentPosition extends ParameterPosition {
135134 Expr getArgument ( Call call ) {
136135 result = call .getPositionalArgument ( this .getPosition ( ) )
137136 or
138- result = call . getReceiver ( ) and this . isSelf ( )
137+ this . isSelf ( ) and result = call . getReceiver ( )
139138 }
140139}
141140
142141/**
143142 * Holds if `arg` is an argument of `call` at the position `pos`.
144- *
145- * Note that this does not hold for the receiever expression of a method call
146- * as the synthetic `ReceiverNode` is the argument for the `self` parameter.
147143 */
148- predicate isArgumentForCall ( Expr arg , Call call , ParameterPosition pos ) {
144+ predicate isArgumentForCall ( Expr arg , Call call , ArgumentPosition pos ) {
149145 // TODO: Handle index expressions as calls in data flow.
150146 not call instanceof IndexExpr and
151- (
152- call .getPositionalArgument ( pos .getPosition ( ) ) = arg
153- or
154- call .getReceiver ( ) = arg and pos .isSelf ( ) and not call .receiverImplicitlyBorrowed ( )
155- )
147+ arg = pos .getArgument ( call )
156148}
157149
158150/** Provides logic related to SSA. */
@@ -283,14 +275,6 @@ module LocalFlow {
283275 or
284276 nodeFrom .asPat ( ) .( OrPat ) .getAPat ( ) = nodeTo .asPat ( )
285277 or
286- // Simple value step from receiver expression to receiver node, in case
287- // there is no implicit deref or borrow operation.
288- nodeFrom .asExpr ( ) = nodeTo .( ReceiverNode ) .getReceiver ( )
289- or
290- // The dual step of the above, for the post-update nodes.
291- nodeFrom .( PostUpdateNode ) .getPreUpdateNode ( ) .( ReceiverNode ) .getReceiver ( ) =
292- nodeTo .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
293- or
294278 nodeTo .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) =
295279 getPostUpdateReverseStep ( nodeFrom .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) , true )
296280 }
@@ -380,7 +364,7 @@ module RustDataFlow implements InputSig<Location> {
380364 node .( FlowSummaryNode ) .getSummaryNode ( ) .isHidden ( ) or
381365 node instanceof CaptureNode or
382366 node instanceof ClosureParameterNode or
383- node instanceof ReceiverNode or
367+ node instanceof DerefBorrowNode or
384368 node .asExpr ( ) instanceof ParenExpr or
385369 nodeIsHidden ( node .( PostUpdateNode ) .getPreUpdateNode ( ) )
386370 }
@@ -520,16 +504,16 @@ module RustDataFlow implements InputSig<Location> {
520504 }
521505
522506 pragma [ nomagic]
523- private predicate implicitDerefToReceiver ( Node node1 , ReceiverNode node2 , ReferenceContent c ) {
524- TypeInference :: receiverHasImplicitDeref ( node1 . asExpr ( ) ) and
525- node1 .asExpr ( ) = node2 .getReceiver ( ) and
507+ private predicate implicitDeref ( Node node1 , DerefBorrowNode node2 , ReferenceContent c ) {
508+ not node2 . isBorrow ( ) and
509+ node1 .asExpr ( ) = node2 .getNode ( ) and
526510 exists ( c )
527511 }
528512
529513 pragma [ nomagic]
530- private predicate implicitBorrowToReceiver ( Node node1 , ReceiverNode node2 , ReferenceContent c ) {
531- TypeInference :: receiverHasImplicitBorrow ( node1 . asExpr ( ) ) and
532- node1 .asExpr ( ) = node2 .getReceiver ( ) and
514+ private predicate implicitBorrow ( Node node1 , DerefBorrowNode node2 , ReferenceContent c ) {
515+ node2 . isBorrow ( ) and
516+ node1 .asExpr ( ) = node2 .getNode ( ) and
533517 exists ( c )
534518 }
535519
@@ -539,6 +523,15 @@ module RustDataFlow implements InputSig<Location> {
539523 exists ( c )
540524 }
541525
526+ private Node getFieldExprContainerNode ( FieldExpr fe ) {
527+ exists ( Expr container | container = fe .getContainer ( ) |
528+ not any ( DerefBorrowNode n ) .getNode ( ) = container and
529+ result .asExpr ( ) = container
530+ or
531+ result .( DerefBorrowNode ) .getNode ( ) = container
532+ )
533+ }
534+
542535 pragma [ nomagic]
543536 additional predicate readContentStep ( Node node1 , Content c , Node node2 ) {
544537 exists ( TupleStructPat pat , int pos |
@@ -563,9 +556,9 @@ module RustDataFlow implements InputSig<Location> {
563556 node1 .asPat ( ) .( RefPat ) .getPat ( ) = node2 .asPat ( )
564557 or
565558 exists ( FieldExpr access |
566- node1 .asExpr ( ) = access .getContainer ( ) and
567559 node2 .asExpr ( ) = access and
568- access = c .( FieldContent ) .getAnAccess ( )
560+ access = c .( FieldContent ) .getAnAccess ( ) and
561+ node1 = getFieldExprContainerNode ( access )
569562 )
570563 or
571564 exists ( IndexExpr arr |
@@ -616,12 +609,10 @@ module RustDataFlow implements InputSig<Location> {
616609 referenceExprToExpr ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
617610 node1 .( PostUpdateNode ) .getPreUpdateNode ( ) , c )
618611 or
619- // Step from receiver expression to receiver node, in case of an implicit
620- // dereference.
621- implicitDerefToReceiver ( node1 , node2 , c )
612+ implicitDeref ( node1 , node2 , c )
622613 or
623614 // A read step dual to the store step for implicit borrows.
624- implicitBorrowToReceiver ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
615+ implicitBorrow ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
625616 node1 .( PostUpdateNode ) .getPreUpdateNode ( ) , c )
626617 or
627618 VariableCapture:: readStep ( node1 , c , node2 )
@@ -657,7 +648,7 @@ module RustDataFlow implements InputSig<Location> {
657648 exists ( AssignmentExpr assignment , FieldExpr access |
658649 assignment .getLhs ( ) = access and
659650 node1 .asExpr ( ) = assignment .getRhs ( ) and
660- node2 . asExpr ( ) = access . getContainer ( ) and
651+ node2 = getFieldExprContainerNode ( access ) and
661652 access = c .getAnAccess ( )
662653 )
663654 }
@@ -729,9 +720,11 @@ module RustDataFlow implements InputSig<Location> {
729720 or
730721 VariableCapture:: storeStep ( node1 , c , node2 )
731722 or
732- // Step from receiver expression to receiver node, in case of an implicit
733- // borrow.
734- implicitBorrowToReceiver ( node1 , node2 , c )
723+ implicitBorrow ( node1 , node2 , c )
724+ or
725+ // A store step dual to the read step for implicit dereferences.
726+ implicitDeref ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
727+ node1 .( PostUpdateNode ) .getPreUpdateNode ( ) , c )
735728 }
736729
737730 /**
0 commit comments