@@ -21,8 +21,7 @@ private class SelfLocalSourceNode extends DataFlow::LocalSourceNode {
21
21
SelfLocalSourceNode ( ) {
22
22
self = this .( SelfParameterNodeImpl ) .getSelfVariable ( )
23
23
or
24
- self = this .( SsaSelfDefinitionNode ) .getVariable ( ) and
25
- not LocalFlow:: localFlowSsaParamInput ( _, this )
24
+ self = this .( SsaSelfDefinitionNode ) .getVariable ( )
26
25
}
27
26
28
27
/** Gets the `self` variable. */
@@ -424,6 +423,7 @@ private module Cached {
424
423
cached
425
424
newtype TArgumentPosition =
426
425
TSelfArgumentPosition ( ) or
426
+ TLambdaSelfArgumentPosition ( ) or
427
427
TBlockArgumentPosition ( ) or
428
428
TPositionalArgumentPosition ( int pos ) {
429
429
exists ( Call c | exists ( c .getArgument ( pos ) ) )
@@ -446,6 +446,7 @@ private module Cached {
446
446
cached
447
447
newtype TParameterPosition =
448
448
TSelfParameterPosition ( ) or
449
+ TLambdaSelfParameterPosition ( ) or
449
450
TBlockParameterPosition ( ) or
450
451
TPositionalParameterPosition ( int pos ) {
451
452
pos = any ( Parameter p ) .getPosition ( )
@@ -941,20 +942,24 @@ private module TrackSingletonMethodOnInstanceInput implements CallGraphConstruct
941
942
private predicate paramReturnFlow (
942
943
DataFlow:: Node nodeFrom , DataFlow:: PostUpdateNode nodeTo , StepSummary summary
943
944
) {
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
+ |
945
949
TypeTrackerSpecific:: callStep ( call , arg , p ) and
946
950
nodeTo .getPreUpdateNode ( ) = arg and
947
951
summary .toString ( ) = "return" and
948
952
(
949
- nodeFromPreExpr = nodeFrom .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) . getExpr ( )
953
+ nodeFromPreExpr = nodeFrom .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( )
950
954
or
951
- nodeFromPreExpr = nodeFrom .asExpr ( ) . getExpr ( ) and
952
- singletonMethodOnInstance ( _, _, nodeFromPreExpr )
955
+ nodeFromPreExpr = nodeFrom .asExpr ( ) and
956
+ singletonMethodOnInstance ( _, _, nodeFromPreExpr . getExpr ( ) )
953
957
)
954
958
|
955
- nodeFromPreExpr = p .getParameter ( ) .( NamedParameter ) .getVariable ( ) .getAnAccess ( )
959
+ nodeFromPreExpr =
960
+ LocalFlow:: getParameterDefNode ( p .getParameter ( ) ) .getDefinitionExt ( ) .getARead ( )
956
961
or
957
- nodeFromPreExpr = p .( SelfParameterNodeImpl ) .getSelfVariable ( ) .getAnAccess ( )
962
+ nodeFromPreExpr = p .( SelfParameterNodeImpl ) .getSelfDefinition ( ) .getARead ( )
958
963
)
959
964
}
960
965
@@ -1276,6 +1281,9 @@ class ParameterPosition extends TParameterPosition {
1276
1281
/** Holds if this position represents a `self` parameter. */
1277
1282
predicate isSelf ( ) { this = TSelfParameterPosition ( ) }
1278
1283
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
+
1279
1287
/** Holds if this position represents a block parameter. */
1280
1288
predicate isBlock ( ) { this = TBlockParameterPosition ( ) }
1281
1289
@@ -1313,6 +1321,8 @@ class ParameterPosition extends TParameterPosition {
1313
1321
string toString ( ) {
1314
1322
this .isSelf ( ) and result = "self"
1315
1323
or
1324
+ this .isLambdaSelf ( ) and result = "lambda self"
1325
+ or
1316
1326
this .isBlock ( ) and result = "block"
1317
1327
or
1318
1328
exists ( int pos | this .isPositional ( pos ) and result = "position " + pos )
@@ -1342,6 +1352,9 @@ class ArgumentPosition extends TArgumentPosition {
1342
1352
/** Holds if this position represents a `self` argument. */
1343
1353
predicate isSelf ( ) { this = TSelfArgumentPosition ( ) }
1344
1354
1355
+ /** Holds if this position represents a lambda `self` argument. Only used for tracking flow through captured variables. */
1356
+ predicate isLambdaSelf ( ) { this = TLambdaSelfArgumentPosition ( ) }
1357
+
1345
1358
/** Holds if this position represents a block argument. */
1346
1359
predicate isBlock ( ) { this = TBlockArgumentPosition ( ) }
1347
1360
@@ -1374,6 +1387,8 @@ class ArgumentPosition extends TArgumentPosition {
1374
1387
string toString ( ) {
1375
1388
this .isSelf ( ) and result = "self"
1376
1389
or
1390
+ this .isLambdaSelf ( ) and result = "lambda self"
1391
+ or
1377
1392
this .isBlock ( ) and result = "block"
1378
1393
or
1379
1394
exists ( int pos | this .isPositional ( pos ) and result = "position " + pos )
@@ -1393,16 +1408,24 @@ class ArgumentPosition extends TArgumentPosition {
1393
1408
}
1394
1409
1395
1410
pragma [ 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
+ }
1397
1415
1398
1416
pragma [ 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
+ }
1400
1421
1401
1422
/** Holds if arguments at position `apos` match parameters at position `ppos`. */
1402
1423
pragma [ nomagic]
1403
1424
predicate parameterMatch ( ParameterPosition ppos , ArgumentPosition apos ) {
1404
1425
ppos .isSelf ( ) and apos .isSelf ( )
1405
1426
or
1427
+ ppos .isLambdaSelf ( ) and apos .isLambdaSelf ( )
1428
+ or
1406
1429
ppos .isBlock ( ) and apos .isBlock ( )
1407
1430
or
1408
1431
exists ( int pos | ppos .isPositional ( pos ) and apos .isPositional ( pos ) )
@@ -1441,8 +1464,6 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
1441
1464
* This is a temporary hook to support technical debt in the Go language; do not use.
1442
1465
*/
1443
1466
pragma [ inline]
1444
- predicate golangSpecificParamArgFilter (
1445
- DataFlowCall call , DataFlow:: ParameterNode p , ArgumentNode arg
1446
- ) {
1467
+ predicate golangSpecificParamArgFilter ( DataFlowCall call , ParameterNodeImpl p , ArgumentNode arg ) {
1447
1468
any ( )
1448
1469
}
0 commit comments