@@ -373,6 +373,63 @@ private class NewArrayAllocationExpr extends AllocationExpr, NewArrayExpr {
373373 override predicate requiresDealloc ( ) { not exists ( this .getPlacementPointer ( ) ) }
374374}
375375
376+ /**
377+ * Holds if `f` is an allocation function according to the
378+ * extensible `allocationFunctionModel` predicate.
379+ */
380+ private predicate isAllocationFunctionFromModel (
381+ Function f , string namespace , string type , string name
382+ ) {
383+ exists ( boolean subtypes | allocationFunctionModel ( namespace , type , subtypes , name , _, _, _, _) |
384+ if type = ""
385+ then f .hasQualifiedName ( namespace , "" , name )
386+ else
387+ exists ( Class c |
388+ c .hasQualifiedName ( namespace , type ) and f .hasQualifiedName ( namespace , _, name )
389+ |
390+ if subtypes = true
391+ then f = c .getADerivedClass * ( ) .getAMemberFunction ( )
392+ else f = c .getAMemberFunction ( )
393+ )
394+ )
395+ }
396+
397+ /**
398+ * An allocation function modeled via the extensible `allocationFunctionModel` predicate.
399+ */
400+ private class AllocationFunctionFromModel extends AllocationFunction {
401+ string namespace ;
402+ string type ;
403+ string name ;
404+
405+ AllocationFunctionFromModel ( ) { isAllocationFunctionFromModel ( this , namespace , type , name ) }
406+
407+ final override int getSizeArg ( ) {
408+ exists ( string sizeArg |
409+ allocationFunctionModel ( namespace , type , _, name , sizeArg , _, _, _) and
410+ result = sizeArg .toInt ( )
411+ )
412+ }
413+
414+ final override int getSizeMult ( ) {
415+ exists ( string sizeMult |
416+ allocationFunctionModel ( namespace , type , _, name , _, sizeMult , _, _) and
417+ result = sizeMult .toInt ( )
418+ )
419+ }
420+
421+ final override int getReallocPtrArg ( ) {
422+ exists ( string reallocPtrArg |
423+ allocationFunctionModel ( namespace , type , _, name , _, _, reallocPtrArg , _) and
424+ result = reallocPtrArg .toInt ( )
425+ )
426+ }
427+
428+ final override predicate requiresDealloc ( ) {
429+ allocationFunctionModel ( namespace , type , _, name , _, _, _, true )
430+ }
431+ }
432+
376433private module HeuristicAllocation {
377434 /** A class that maps an `AllocationExpr` to an `HeuristicAllocationExpr`. */
378435 private class HeuristicAllocationModeled extends HeuristicAllocationExpr instanceof AllocationExpr
0 commit comments