@@ -5289,6 +5289,40 @@ Address irgen::emitAllocYieldManyCoroutineBuffer(IRGenFunction &IGF) {
5289
5289
getYieldManyCoroutineBufferAlignment (IGF.IGM ));
5290
5290
}
5291
5291
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
+
5292
5326
static llvm::Constant *getAddrOfGlobalCoroAllocator (
5293
5327
IRGenModule &IGM, CoroAllocatorKind kind, bool shouldDeallocateImmediately,
5294
5328
llvm::Constant *allocFn, llvm::Constant *deallocFn) {
@@ -5310,7 +5344,8 @@ static llvm::Constant *getAddrOfGlobalCoroAllocator(
5310
5344
llvm::Constant *IRGenModule::getAddrOfGlobalCoroMallocAllocator () {
5311
5345
return getAddrOfGlobalCoroAllocator (*this , CoroAllocatorKind::Malloc,
5312
5346
/* shouldDeallocateImmediately=*/ true ,
5313
- getMallocFn (), getFreeFn ());
5347
+ getAddrOfSwiftCCMalloc (*this ),
5348
+ getAddrOfSwiftCCFree (*this ));
5314
5349
}
5315
5350
llvm::Constant *IRGenModule::getAddrOfGlobalCoroAsyncTaskAllocator () {
5316
5351
return getAddrOfGlobalCoroAllocator (*this , CoroAllocatorKind::Async,
0 commit comments