@@ -1088,8 +1088,8 @@ private CfgScope getTargetSingleton(RelevantCall call, string method) {
1088
1088
}
1089
1089
1090
1090
/**
1091
- * Holds if `ctx` targets `encl`, which is the enclosing callable of `call`, the receiver
1092
- * of `call` is a parameter access, where the corresponding argument of `ctx` is `arg`.
1091
+ * Holds if `ctx` targets the enclosing callable of `call`, the receiver of `call` is a
1092
+ * parameter access, where the corresponding argument of `ctx` is `arg`.
1093
1093
*
1094
1094
* `name` is the name of the method being called by `call`, `source` is a
1095
1095
* `LocalSourceNode` that flows to `arg`, and `paramDef` is the SSA definition for the
@@ -1098,11 +1098,11 @@ private CfgScope getTargetSingleton(RelevantCall call, string method) {
1098
1098
pragma [ nomagic]
1099
1099
private predicate argMustFlowToReceiver (
1100
1100
RelevantCall ctx , DataFlow:: LocalSourceNode source , DataFlow:: Node arg , RelevantCall call ,
1101
- Callable encl , string name
1101
+ string name
1102
1102
) {
1103
1103
exists (
1104
1104
ParameterNodeImpl p , SsaDefinitionExtNode paramDef , ParameterPosition ppos ,
1105
- ArgumentPosition apos
1105
+ ArgumentPosition apos , Callable encl
1106
1106
|
1107
1107
// the receiver of `call` references `p`
1108
1108
exists ( DataFlow:: Node receiver |
@@ -1133,26 +1133,26 @@ private predicate argMustFlowToReceiver(
1133
1133
}
1134
1134
1135
1135
/**
1136
- * Holds if `ctx` targets `encl`, which is the enclosing callable of `new`, and
1136
+ * Holds if `ctx` targets the enclosing callable of `new`, and
1137
1137
* the receiver of `new` is a parameter access, where the corresponding argument
1138
1138
* `arg` of `ctx` has type `tp`.
1139
1139
*
1140
1140
* `new` calls the object creation `new` method.
1141
1141
*/
1142
1142
pragma [ nomagic]
1143
1143
private predicate mayBenefitFromCallContextInitialize (
1144
- RelevantCall ctx , RelevantCall new , DataFlow:: Node arg , Callable encl , Module tp , string name
1144
+ RelevantCall ctx , RelevantCall new , DataFlow:: Node arg , Module tp , string name
1145
1145
) {
1146
1146
exists ( DataFlow:: LocalSourceNode source |
1147
- argMustFlowToReceiver ( ctx , pragma [ only_bind_into ] ( source ) , arg , new , encl , "new" ) and
1147
+ argMustFlowToReceiver ( ctx , pragma [ only_bind_into ] ( source ) , arg , new , "new" ) and
1148
1148
source = trackModuleAccess ( tp ) and
1149
1149
name = "initialize" and
1150
1150
exists ( lookupMethod ( tp , name ) )
1151
1151
)
1152
1152
}
1153
1153
1154
1154
/**
1155
- * Holds if `ctx` targets `encl`, which is the enclosing callable of `call`, and
1155
+ * Holds if `ctx` targets the enclosing callable of `call`, and
1156
1156
* the receiver of `call` is a parameter access, where the corresponding argument
1157
1157
* `arg` of `ctx` has type `tp`.
1158
1158
*
@@ -1161,19 +1161,18 @@ private predicate mayBenefitFromCallContextInitialize(
1161
1161
*/
1162
1162
pragma [ nomagic]
1163
1163
private predicate mayBenefitFromCallContextInstance (
1164
- RelevantCall ctx , RelevantCall call , DataFlow:: Node arg , Callable encl , Module tp , boolean exact ,
1165
- string name
1164
+ RelevantCall ctx , RelevantCall call , DataFlow:: Node arg , Module tp , boolean exact , string name
1166
1165
) {
1167
1166
exists ( DataFlow:: LocalSourceNode source |
1168
- argMustFlowToReceiver ( ctx , pragma [ only_bind_into ] ( source ) , arg , call , encl ,
1167
+ argMustFlowToReceiver ( ctx , pragma [ only_bind_into ] ( source ) , arg , call ,
1169
1168
pragma [ only_bind_into ] ( name ) ) and
1170
1169
source = trackInstance ( tp , exact ) and
1171
1170
exists ( lookupMethod ( tp , pragma [ only_bind_into ] ( name ) ) )
1172
1171
)
1173
1172
}
1174
1173
1175
1174
/**
1176
- * Holds if `ctx` targets `encl`, which is the enclosing callable of `call`, and
1175
+ * Holds if `ctx` targets the enclosing callable of `call`, and
1177
1176
* the receiver of `call` is a parameter access, where the corresponding argument
1178
1177
* `arg` of `ctx` is a module access targeting a module of type `tp`.
1179
1178
*
@@ -1182,12 +1181,11 @@ private predicate mayBenefitFromCallContextInstance(
1182
1181
*/
1183
1182
pragma [ nomagic]
1184
1183
private predicate mayBenefitFromCallContextSingleton (
1185
- RelevantCall ctx , RelevantCall call , DataFlow:: Node arg , Callable encl , Module tp , boolean exact ,
1186
- string name
1184
+ RelevantCall ctx , RelevantCall call , DataFlow:: Node arg , Module tp , boolean exact , string name
1187
1185
) {
1188
1186
exists ( DataFlow:: LocalSourceNode source |
1189
1187
argMustFlowToReceiver ( ctx , pragma [ only_bind_into ] ( source ) , pragma [ only_bind_into ] ( arg ) , call ,
1190
- encl , pragma [ only_bind_into ] ( name ) ) and
1188
+ pragma [ only_bind_into ] ( name ) ) and
1191
1189
exists ( lookupSingletonMethod ( tp , pragma [ only_bind_into ] ( name ) , exact ) )
1192
1190
|
1193
1191
source = trackModuleAccess ( tp ) and
@@ -1208,16 +1206,14 @@ private predicate mayBenefitFromCallContextSingleton(
1208
1206
1209
1207
/**
1210
1208
* Holds if the set of viable implementations that can be called by `call`
1211
- * might be improved by knowing the call context. This is the case if the
1212
- * receiver accesses a parameter of the enclosing callable `c` (including
1213
- * the implicit `self` parameter).
1209
+ * might be improved by knowing the call context.
1214
1210
*/
1215
- predicate mayBenefitFromCallContext ( DataFlowCall call , DataFlowCallable c ) {
1216
- mayBenefitFromCallContextInitialize ( _, call .asCall ( ) , _, c . asCallable ( ) , _, _)
1211
+ predicate mayBenefitFromCallContext ( DataFlowCall call ) {
1212
+ mayBenefitFromCallContextInitialize ( _, call .asCall ( ) , _, _, _)
1217
1213
or
1218
- mayBenefitFromCallContextInstance ( _, call .asCall ( ) , _, c . asCallable ( ) , _, _, _)
1214
+ mayBenefitFromCallContextInstance ( _, call .asCall ( ) , _, _, _, _)
1219
1215
or
1220
- mayBenefitFromCallContextSingleton ( _, call .asCall ( ) , _, c . asCallable ( ) , _, _, _)
1216
+ mayBenefitFromCallContextSingleton ( _, call .asCall ( ) , _, _, _, _)
1221
1217
}
1222
1218
1223
1219
/**
@@ -1226,25 +1222,25 @@ predicate mayBenefitFromCallContext(DataFlowCall call, DataFlowCallable c) {
1226
1222
*/
1227
1223
pragma [ nomagic]
1228
1224
DataFlowCallable viableImplInCallContext ( DataFlowCall call , DataFlowCall ctx ) {
1229
- mayBenefitFromCallContext ( call , _ ) and
1225
+ mayBenefitFromCallContext ( call ) and
1230
1226
(
1231
1227
// `ctx` can provide a potentially better type bound
1232
1228
exists ( RelevantCall call0 , Callable res |
1233
1229
call0 = call .asCall ( ) and
1234
1230
res = result .asCallable ( ) and
1235
1231
exists ( Module m , string name |
1236
- mayBenefitFromCallContextInitialize ( ctx .asCall ( ) , pragma [ only_bind_into ] ( call0 ) , _, _ ,
1232
+ mayBenefitFromCallContextInitialize ( ctx .asCall ( ) , pragma [ only_bind_into ] ( call0 ) , _,
1237
1233
pragma [ only_bind_into ] ( m ) , pragma [ only_bind_into ] ( name ) ) and
1238
1234
res = getInitializeTarget ( call0 ) and
1239
1235
res = lookupMethod ( m , name )
1240
1236
or
1241
1237
exists ( boolean exact |
1242
- mayBenefitFromCallContextInstance ( ctx .asCall ( ) , pragma [ only_bind_into ] ( call0 ) , _, _ ,
1238
+ mayBenefitFromCallContextInstance ( ctx .asCall ( ) , pragma [ only_bind_into ] ( call0 ) , _,
1243
1239
pragma [ only_bind_into ] ( m ) , pragma [ only_bind_into ] ( exact ) , pragma [ only_bind_into ] ( name ) ) and
1244
1240
res = getTargetInstance ( call0 , name ) and
1245
1241
res = lookupMethod ( m , name , exact )
1246
1242
or
1247
- mayBenefitFromCallContextSingleton ( ctx .asCall ( ) , pragma [ only_bind_into ] ( call0 ) , _, _ ,
1243
+ mayBenefitFromCallContextSingleton ( ctx .asCall ( ) , pragma [ only_bind_into ] ( call0 ) , _,
1248
1244
pragma [ only_bind_into ] ( m ) , pragma [ only_bind_into ] ( exact ) , pragma [ only_bind_into ] ( name ) ) and
1249
1245
res = getTargetSingleton ( call0 , name ) and
1250
1246
res = lookupSingletonMethod ( m , name , exact )
@@ -1257,15 +1253,15 @@ DataFlowCallable viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) {
1257
1253
exists ( RelevantCall call0 , RelevantCall ctx0 , DataFlow:: Node arg , string name |
1258
1254
call0 = call .asCall ( ) and
1259
1255
ctx0 = ctx .asCall ( ) and
1260
- argMustFlowToReceiver ( ctx0 , _, arg , call0 , _ , name ) and
1261
- not mayBenefitFromCallContextInitialize ( ctx0 , call0 , arg , _, _, _ ) and
1262
- not mayBenefitFromCallContextInstance ( ctx0 , call0 , arg , _, _, _ , name ) and
1263
- not mayBenefitFromCallContextSingleton ( ctx0 , call0 , arg , _, _, _ , name ) and
1256
+ argMustFlowToReceiver ( ctx0 , _, arg , call0 , name ) and
1257
+ not mayBenefitFromCallContextInitialize ( ctx0 , call0 , arg , _, _) and
1258
+ not mayBenefitFromCallContextInstance ( ctx0 , call0 , arg , _, _, name ) and
1259
+ not mayBenefitFromCallContextSingleton ( ctx0 , call0 , arg , _, _, name ) and
1264
1260
result .asCallable ( ) = viableSourceCallable ( call0 )
1265
1261
)
1266
1262
or
1267
1263
// library calls should always be able to resolve
1268
- argMustFlowToReceiver ( ctx .asCall ( ) , _, _, call .asCall ( ) , _, _ ) and
1264
+ argMustFlowToReceiver ( ctx .asCall ( ) , _, _, call .asCall ( ) , _) and
1269
1265
result = viableLibraryCallable ( call )
1270
1266
)
1271
1267
}
0 commit comments