@@ -5289,6 +5289,40 @@ Address irgen::emitAllocYieldManyCoroutineBuffer(IRGenFunction &IGF) {
52895289 getYieldManyCoroutineBufferAlignment (IGF.IGM ));
52905290}
52915291
5292+ static llvm::Constant *getAddrOfSwiftCCMalloc (IRGenModule &IGM) {
5293+ auto mallocFnPtr = IGM.getMallocFunctionPointer ();
5294+ auto sig = mallocFnPtr.getSignature ();
5295+ if (sig.getCallingConv () == IGM.SwiftCC ) {
5296+ return IGM.getMallocFn ();
5297+ }
5298+ return IGM.getOrCreateHelperFunction (
5299+ " _swift_malloc" , sig.getType ()->getReturnType (), sig.getType ()->params (),
5300+ [](IRGenFunction &IGF) {
5301+ auto parameters = IGF.collectParameters ();
5302+ auto *size = parameters.claimNext ();
5303+ auto malloc = IGF.IGM .getMallocFunctionPointer ();
5304+ auto *call = IGF.Builder .CreateCall (malloc, {size});
5305+ IGF.Builder .CreateRet (call);
5306+ });
5307+ }
5308+
5309+ static llvm::Constant *getAddrOfSwiftCCFree (IRGenModule &IGM) {
5310+ auto freeFnPtr = IGM.getFreeFunctionPointer ();
5311+ auto sig = freeFnPtr.getSignature ();
5312+ if (sig.getCallingConv () == IGM.SwiftCC ) {
5313+ return IGM.getFreeFn ();
5314+ }
5315+ return IGM.getOrCreateHelperFunction (
5316+ " _swift_free" , sig.getType ()->getReturnType (), sig.getType ()->params (),
5317+ [](IRGenFunction &IGF) {
5318+ auto parameters = IGF.collectParameters ();
5319+ auto *ptr = parameters.claimNext ();
5320+ auto free = IGF.IGM .getFreeFunctionPointer ();
5321+ IGF.Builder .CreateCall (free, {ptr});
5322+ IGF.Builder .CreateRetVoid ();
5323+ });
5324+ }
5325+
52925326static llvm::Constant *getAddrOfGlobalCoroAllocator (
52935327 IRGenModule &IGM, CoroAllocatorKind kind, bool shouldDeallocateImmediately,
52945328 llvm::Constant *allocFn, llvm::Constant *deallocFn) {
@@ -5310,7 +5344,8 @@ static llvm::Constant *getAddrOfGlobalCoroAllocator(
53105344llvm::Constant *IRGenModule::getAddrOfGlobalCoroMallocAllocator () {
53115345 return getAddrOfGlobalCoroAllocator (*this , CoroAllocatorKind::Malloc,
53125346 /* shouldDeallocateImmediately=*/ true ,
5313- getMallocFn (), getFreeFn ());
5347+ getAddrOfSwiftCCMalloc (*this ),
5348+ getAddrOfSwiftCCFree (*this ));
53145349}
53155350llvm::Constant *IRGenModule::getAddrOfGlobalCoroAsyncTaskAllocator () {
53165351 return getAddrOfGlobalCoroAllocator (*this , CoroAllocatorKind::Async,
0 commit comments