@@ -21,8 +21,7 @@ private class SelfLocalSourceNode extends DataFlow::LocalSourceNode {
2121 SelfLocalSourceNode ( ) {
2222 self = this .( SelfParameterNodeImpl ) .getSelfVariable ( )
2323 or
24- self = this .( SsaSelfDefinitionNode ) .getVariable ( ) and
25- not LocalFlow:: localFlowSsaParamInput ( _, this )
24+ self = this .( SsaSelfDefinitionNode ) .getVariable ( )
2625 }
2726
2827 /** Gets the `self` variable. */
@@ -424,6 +423,7 @@ private module Cached {
424423 cached
425424 newtype TArgumentPosition =
426425 TSelfArgumentPosition ( ) or
426+ TLambdaSelfArgumentPosition ( ) or
427427 TBlockArgumentPosition ( ) or
428428 TPositionalArgumentPosition ( int pos ) {
429429 exists ( Call c | exists ( c .getArgument ( pos ) ) )
@@ -446,6 +446,7 @@ private module Cached {
446446 cached
447447 newtype TParameterPosition =
448448 TSelfParameterPosition ( ) or
449+ TLambdaSelfParameterPosition ( ) or
449450 TBlockParameterPosition ( ) or
450451 TPositionalParameterPosition ( int pos ) {
451452 pos = any ( Parameter p ) .getPosition ( )
@@ -941,20 +942,24 @@ private module TrackSingletonMethodOnInstanceInput implements CallGraphConstruct
941942 private predicate paramReturnFlow (
942943 DataFlow:: Node nodeFrom , DataFlow:: PostUpdateNode nodeTo , StepSummary summary
943944 ) {
944- exists ( RelevantCall call , DataFlow:: Node arg , DataFlow:: ParameterNode p , Expr nodeFromPreExpr |
945+ exists (
946+ RelevantCall call , DataFlow:: Node arg , DataFlow:: ParameterNode p ,
947+ CfgNodes:: ExprCfgNode nodeFromPreExpr
948+ |
945949 TypeTrackerSpecific:: callStep ( call , arg , p ) and
946950 nodeTo .getPreUpdateNode ( ) = arg and
947951 summary .toString ( ) = "return" and
948952 (
949- nodeFromPreExpr = nodeFrom .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) . getExpr ( )
953+ nodeFromPreExpr = nodeFrom .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
950954 or
951- nodeFromPreExpr = nodeFrom .asExpr ( ) . getExpr ( ) and
952- singletonMethodOnInstance ( _, _, nodeFromPreExpr )
955+ nodeFromPreExpr = nodeFrom .asExpr ( ) and
956+ singletonMethodOnInstance ( _, _, nodeFromPreExpr . getExpr ( ) )
953957 )
954958 |
955- nodeFromPreExpr = p .getParameter ( ) .( NamedParameter ) .getVariable ( ) .getAnAccess ( )
959+ nodeFromPreExpr =
960+ LocalFlow:: getParameterDefNode ( p .getParameter ( ) ) .getDefinitionExt ( ) .getARead ( )
956961 or
957- nodeFromPreExpr = p .( SelfParameterNodeImpl ) .getSelfVariable ( ) .getAnAccess ( )
962+ nodeFromPreExpr = p .( SelfParameterNodeImpl ) .getSelfDefinition ( ) .getARead ( )
958963 )
959964 }
960965
@@ -1276,6 +1281,9 @@ class ParameterPosition extends TParameterPosition {
12761281 /** Holds if this position represents a `self` parameter. */
12771282 predicate isSelf ( ) { this = TSelfParameterPosition ( ) }
12781283
1284+ /** Holds if this position represents a reference to a lambda itself. Only used for tracking flow through captured variables. */
1285+ predicate isLambdaSelf ( ) { this = TLambdaSelfParameterPosition ( ) }
1286+
12791287 /** Holds if this position represents a block parameter. */
12801288 predicate isBlock ( ) { this = TBlockParameterPosition ( ) }
12811289
@@ -1313,6 +1321,8 @@ class ParameterPosition extends TParameterPosition {
13131321 string toString ( ) {
13141322 this .isSelf ( ) and result = "self"
13151323 or
1324+ this .isLambdaSelf ( ) and result = "lambda self"
1325+ or
13161326 this .isBlock ( ) and result = "block"
13171327 or
13181328 exists ( int pos | this .isPositional ( pos ) and result = "position " + pos )
@@ -1342,6 +1352,9 @@ class ArgumentPosition extends TArgumentPosition {
13421352 /** Holds if this position represents a `self` argument. */
13431353 predicate isSelf ( ) { this = TSelfArgumentPosition ( ) }
13441354
1355+ /** Holds if this position represents a lambda `self` argument. Only used for tracking flow through captured variables. */
1356+ predicate isLambdaSelf ( ) { this = TLambdaSelfArgumentPosition ( ) }
1357+
13451358 /** Holds if this position represents a block argument. */
13461359 predicate isBlock ( ) { this = TBlockArgumentPosition ( ) }
13471360
@@ -1374,6 +1387,8 @@ class ArgumentPosition extends TArgumentPosition {
13741387 string toString ( ) {
13751388 this .isSelf ( ) and result = "self"
13761389 or
1390+ this .isLambdaSelf ( ) and result = "lambda self"
1391+ or
13771392 this .isBlock ( ) and result = "block"
13781393 or
13791394 exists ( int pos | this .isPositional ( pos ) and result = "position " + pos )
@@ -1393,16 +1408,24 @@ class ArgumentPosition extends TArgumentPosition {
13931408}
13941409
13951410pragma [ nomagic]
1396- private predicate parameterPositionIsNotSelf ( ParameterPosition ppos ) { not ppos .isSelf ( ) }
1411+ private predicate parameterPositionIsNotSelf ( ParameterPosition ppos ) {
1412+ not ppos .isSelf ( ) and
1413+ not ppos .isLambdaSelf ( )
1414+ }
13971415
13981416pragma [ nomagic]
1399- private predicate argumentPositionIsNotSelf ( ArgumentPosition apos ) { not apos .isSelf ( ) }
1417+ private predicate argumentPositionIsNotSelf ( ArgumentPosition apos ) {
1418+ not apos .isSelf ( ) and
1419+ not apos .isLambdaSelf ( )
1420+ }
14001421
14011422/** Holds if arguments at position `apos` match parameters at position `ppos`. */
14021423pragma [ nomagic]
14031424predicate parameterMatch ( ParameterPosition ppos , ArgumentPosition apos ) {
14041425 ppos .isSelf ( ) and apos .isSelf ( )
14051426 or
1427+ ppos .isLambdaSelf ( ) and apos .isLambdaSelf ( )
1428+ or
14061429 ppos .isBlock ( ) and apos .isBlock ( )
14071430 or
14081431 exists ( int pos | ppos .isPositional ( pos ) and apos .isPositional ( pos ) )
@@ -1441,8 +1464,6 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
14411464 * This is a temporary hook to support technical debt in the Go language; do not use.
14421465 */
14431466pragma [ inline]
1444- predicate golangSpecificParamArgFilter (
1445- DataFlowCall call , DataFlow:: ParameterNode p , ArgumentNode arg
1446- ) {
1467+ predicate golangSpecificParamArgFilter ( DataFlowCall call , ParameterNodeImpl p , ArgumentNode arg ) {
14471468 any ( )
14481469}
0 commit comments