@@ -215,6 +215,10 @@ class BuiltinFunctionObjectInternal extends CallableObjectInternal, TBuiltinFunc
215
215
cls = ObjectInternal:: builtin ( "bool" ) and obj = ObjectInternal:: bool ( _)
216
216
) and
217
217
origin = CfgOrigin:: unknown ( )
218
+ or
219
+ this .returnTypeUnknown ( ) and
220
+ obj = ObjectInternal:: unknown ( ) and
221
+ origin = CfgOrigin:: unknown ( )
218
222
}
219
223
220
224
override ControlFlowNode getOrigin ( ) {
@@ -231,27 +235,15 @@ class BuiltinFunctionObjectInternal extends CallableObjectInternal, TBuiltinFunc
231
235
232
236
Builtin getReturnType ( ) {
233
237
exists ( Builtin func |
234
- func = this .getBuiltin ( ) |
235
- /* Enumerate the types of a few builtin functions, that the CPython analysis misses.
236
- */
237
- func = Builtin:: builtin ( "hex" ) and result = Builtin:: special ( "str" )
238
- or
239
- func = Builtin:: builtin ( "oct" ) and result = Builtin:: special ( "str" )
240
- or
241
- func = Builtin:: builtin ( "intern" ) and result = Builtin:: special ( "str" )
242
- or
243
- func = Builtin:: builtin ( "__import__" ) and result = Builtin:: special ( "ModuleType" )
244
- or
245
- /* Fix a few minor inaccuracies in the CPython analysis */
246
- ext_rettype ( func , result ) and not (
247
- func = Builtin:: builtin ( "__import__" )
248
- or
249
- func = Builtin:: builtin ( "compile" ) and result = Builtin:: special ( "NoneType" )
250
- or
251
- func = Builtin:: builtin ( "sum" )
252
- or
253
- func = Builtin:: builtin ( "filter" )
254
- )
238
+ func = this .getBuiltin ( ) and
239
+ result = getBuiltinFunctionReturnType ( func )
240
+ )
241
+ }
242
+
243
+ private predicate returnTypeUnknown ( ) {
244
+ exists ( Builtin func |
245
+ func = this .getBuiltin ( ) and
246
+ not exists ( getBuiltinFunctionReturnType ( func ) )
255
247
)
256
248
}
257
249
@@ -294,6 +286,29 @@ class BuiltinFunctionObjectInternal extends CallableObjectInternal, TBuiltinFunc
294
286
295
287
}
296
288
289
+ private Builtin getBuiltinFunctionReturnType ( Builtin func ) {
290
+ /* Enumerate the types of a few builtin functions, that the CPython analysis misses. */
291
+ func = Builtin:: builtin ( "hex" ) and result = Builtin:: special ( "str" )
292
+ or
293
+ func = Builtin:: builtin ( "oct" ) and result = Builtin:: special ( "str" )
294
+ or
295
+ func = Builtin:: builtin ( "intern" ) and result = Builtin:: special ( "str" )
296
+ or
297
+ func = Builtin:: builtin ( "__import__" ) and result = Builtin:: special ( "ModuleType" )
298
+ or
299
+ /* Fix a few minor inaccuracies in the CPython analysis */
300
+ ext_rettype ( func , result ) and not (
301
+ func = Builtin:: builtin ( "__import__" )
302
+ or
303
+ func = Builtin:: builtin ( "compile" ) and result = Builtin:: special ( "NoneType" )
304
+ or
305
+ func = Builtin:: builtin ( "sum" )
306
+ or
307
+ func = Builtin:: builtin ( "filter" )
308
+ )
309
+ }
310
+
311
+
297
312
/** Class representing methods of built-in classes (otherwise known as method-descriptors) such as `list.append`.
298
313
*/
299
314
class BuiltinMethodObjectInternal extends CallableObjectInternal , TBuiltinMethodObject {
@@ -330,6 +345,10 @@ class BuiltinMethodObjectInternal extends CallableObjectInternal, TBuiltinMethod
330
345
cls = ObjectInternal:: builtin ( "bool" ) and obj = ObjectInternal:: bool ( _)
331
346
) and
332
347
origin = CfgOrigin:: unknown ( )
348
+ or
349
+ this .returnTypeUnknown ( ) and
350
+ obj = ObjectInternal:: unknown ( ) and
351
+ origin = CfgOrigin:: unknown ( )
333
352
}
334
353
335
354
Builtin getReturnType ( ) {
@@ -338,14 +357,13 @@ class BuiltinMethodObjectInternal extends CallableObjectInternal, TBuiltinMethod
338
357
func = this .getBuiltin ( ) |
339
358
ext_rettype ( func , result )
340
359
)
341
- or
342
- /* Otherwise, if no such record exists, use `object` as the return type. */
343
- not exists ( Builtin func |
344
- // We cannot do `this.getBuiltin()` here, as that would introduce negative recursion.
345
- // Instead, we appeal directly to the underlying IPA type.
346
- this = TBuiltinMethodObject ( func ) and
347
- ext_rettype ( func , _) )
348
- and result = Builtin:: builtin ( "object" )
360
+ }
361
+
362
+ private predicate returnTypeUnknown ( ) {
363
+ exists ( Builtin func |
364
+ func = this .getBuiltin ( ) |
365
+ not ext_rettype ( func , _)
366
+ )
349
367
}
350
368
351
369
override ControlFlowNode getOrigin ( ) {
0 commit comments