@@ -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
@@ -157,7 +156,7 @@ final class ArgumentPosition extends TArgumentPosition {
157156 inMethodCall = true
158157 or
159158 result = call .( IndexExpr ) .getIndex ( ) and
160- pos = 1 and
159+ pos = 0 and
161160 inMethodCall = true
162161 )
163162 }
@@ -201,8 +200,7 @@ final class ArgumentPosition extends TArgumentPosition {
201200predicate isArgumentForCall ( Expr arg , Call call , ArgumentPosition pos ) {
202201 // TODO: Handle index expressions as calls in data flow.
203202 not call instanceof IndexExpr and
204- arg = pos .getArgument ( call ) and
205- not ( pos .isReceiver ( ) and call .receiverImplicitlyBorrowed ( ) )
203+ arg = pos .getArgument ( call )
206204}
207205
208206/** Provides logic related to SSA. */
@@ -333,14 +331,6 @@ module LocalFlow {
333331 or
334332 nodeFrom .asPat ( ) .( OrPat ) .getAPat ( ) = nodeTo .asPat ( )
335333 or
336- // Simple value step from receiver expression to receiver node, in case
337- // there is no implicit deref or borrow operation.
338- nodeFrom .asExpr ( ) = nodeTo .( ReceiverNode ) .getReceiver ( )
339- or
340- // The dual step of the above, for the post-update nodes.
341- nodeFrom .( PostUpdateNode ) .getPreUpdateNode ( ) .( ReceiverNode ) .getReceiver ( ) =
342- nodeTo .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
343- or
344334 nodeTo .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) =
345335 getPostUpdateReverseStep ( nodeFrom .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) , true )
346336 }
@@ -430,7 +420,7 @@ module RustDataFlow implements InputSig<Location> {
430420 node .( FlowSummaryNode ) .getSummaryNode ( ) .isHidden ( ) or
431421 node instanceof CaptureNode or
432422 node instanceof ClosureParameterNode or
433- node instanceof ReceiverNode or
423+ node instanceof DerefBorrowNode or
434424 node .asExpr ( ) instanceof ParenExpr or
435425 nodeIsHidden ( node .( PostUpdateNode ) .getPreUpdateNode ( ) )
436426 }
@@ -584,16 +574,16 @@ module RustDataFlow implements InputSig<Location> {
584574 }
585575
586576 pragma [ nomagic]
587- private predicate implicitDerefToReceiver ( Node node1 , ReceiverNode node2 , ReferenceContent c ) {
588- TypeInference :: receiverHasImplicitDeref ( node1 . asExpr ( ) ) and
589- node1 .asExpr ( ) = node2 .getReceiver ( ) and
577+ private predicate implicitDeref ( Node node1 , DerefBorrowNode node2 , ReferenceContent c ) {
578+ not node2 . isBorrow ( ) and
579+ node1 .asExpr ( ) = node2 .getNode ( ) and
590580 exists ( c )
591581 }
592582
593583 pragma [ nomagic]
594- private predicate implicitBorrowToReceiver ( Node node1 , ReceiverNode node2 , ReferenceContent c ) {
595- TypeInference :: receiverHasImplicitBorrow ( node1 . asExpr ( ) ) and
596- node1 .asExpr ( ) = node2 .getReceiver ( ) and
584+ private predicate implicitBorrow ( Node node1 , DerefBorrowNode node2 , ReferenceContent c ) {
585+ node2 . isBorrow ( ) and
586+ node1 .asExpr ( ) = node2 .getNode ( ) and
597587 exists ( c )
598588 }
599589
@@ -603,6 +593,15 @@ module RustDataFlow implements InputSig<Location> {
603593 exists ( c )
604594 }
605595
596+ private Node getFieldExprContainerNode ( FieldExpr fe ) {
597+ exists ( Expr container | container = fe .getContainer ( ) |
598+ not any ( DerefBorrowNode n ) .getNode ( ) = container and
599+ result .asExpr ( ) = container
600+ or
601+ result .( DerefBorrowNode ) .getNode ( ) = container
602+ )
603+ }
604+
606605 pragma [ nomagic]
607606 additional predicate readContentStep ( Node node1 , Content c , Node node2 ) {
608607 exists ( TupleStructPat pat , int pos |
@@ -627,9 +626,9 @@ module RustDataFlow implements InputSig<Location> {
627626 node1 .asPat ( ) .( RefPat ) .getPat ( ) = node2 .asPat ( )
628627 or
629628 exists ( FieldExpr access |
630- node1 .asExpr ( ) = access .getContainer ( ) and
631629 node2 .asExpr ( ) = access and
632- access = c .( FieldContent ) .getAnAccess ( )
630+ access = c .( FieldContent ) .getAnAccess ( ) and
631+ node1 = getFieldExprContainerNode ( access )
633632 )
634633 or
635634 exists ( IndexExpr arr |
@@ -680,12 +679,10 @@ module RustDataFlow implements InputSig<Location> {
680679 referenceExprToExpr ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
681680 node1 .( PostUpdateNode ) .getPreUpdateNode ( ) , c )
682681 or
683- // Step from receiver expression to receiver node, in case of an implicit
684- // dereference.
685- implicitDerefToReceiver ( node1 , node2 , c )
682+ implicitDeref ( node1 , node2 , c )
686683 or
687684 // A read step dual to the store step for implicit borrows.
688- implicitBorrowToReceiver ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
685+ implicitBorrow ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
689686 node1 .( PostUpdateNode ) .getPreUpdateNode ( ) , c )
690687 or
691688 VariableCapture:: readStep ( node1 , c , node2 )
@@ -721,7 +718,7 @@ module RustDataFlow implements InputSig<Location> {
721718 exists ( AssignmentExpr assignment , FieldExpr access |
722719 assignment .getLhs ( ) = access and
723720 node1 .asExpr ( ) = assignment .getRhs ( ) and
724- node2 . asExpr ( ) = access . getContainer ( ) and
721+ node2 = getFieldExprContainerNode ( access ) and
725722 access = c .getAnAccess ( )
726723 )
727724 }
@@ -793,9 +790,11 @@ module RustDataFlow implements InputSig<Location> {
793790 or
794791 VariableCapture:: storeStep ( node1 , c , node2 )
795792 or
796- // Step from receiver expression to receiver node, in case of an implicit
797- // borrow.
798- implicitBorrowToReceiver ( node1 , node2 , c )
793+ implicitBorrow ( node1 , node2 , c )
794+ or
795+ // A store step dual to the read step for implicit dereferences.
796+ implicitDeref ( node2 .( PostUpdateNode ) .getPreUpdateNode ( ) ,
797+ node1 .( PostUpdateNode ) .getPreUpdateNode ( ) , c )
799798 }
800799
801800 /**
0 commit comments