@@ -882,6 +882,14 @@ class IRGenSILFunction :
882882 return isTaskAlloc;
883883 }
884884
885+ static bool isCallToMalloc (llvm::Value *val) {
886+ auto *call = dyn_cast<llvm::CallInst>(val);
887+ if (!call)
888+ return false ;
889+ auto *callee = call->getCalledFunction ();
890+ return callee && callee->getName () == " malloc" ;
891+ }
892+
885893 static bool isTaskAlloc (llvm::Value *Storage) {
886894 while (Storage) {
887895 if (auto *LdInst = dyn_cast<llvm::LoadInst>(Storage))
@@ -6518,7 +6526,8 @@ void IRGenSILFunction::emitDebugInfoAfterAllocStack(AllocStackInst *i,
65186526
65196527 // At this point addr must be an alloca or an undef.
65206528 assert (isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr) ||
6521- isa<llvm::IntrinsicInst>(addr) || isCallToSwiftTaskAlloc (addr));
6529+ isa<llvm::IntrinsicInst>(addr) || isCallToSwiftTaskAlloc (addr) ||
6530+ isCallToMalloc (addr));
65226531
65236532 auto Indirection = DirectValue;
65246533 if (InCoroContext (*CurSILFn, *i))
@@ -6575,7 +6584,8 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
65756584 DebugTypeInfo DbgTy;
65766585 emitDebugInfoBeforeAllocStack (i, type, DbgTy);
65776586
6578- auto stackAddr = type.allocateStack (*this , i->getElementType (), dbgname);
6587+ auto stackAddr = type.allocateStack (*this , i->getElementType (), dbgname,
6588+ i->isStackAllocationNested ());
65796589 setLoweredStackAddress (i, stackAddr);
65806590 Address addr = stackAddr.getAddress ();
65816591
@@ -6668,23 +6678,27 @@ void IRGenSILFunction::visitDeallocStackInst(swift::DeallocStackInst *i) {
66686678 if (auto *closure = dyn_cast<PartialApplyInst>(i->getOperand ())) {
66696679 assert (closure->isOnStack ());
66706680 auto stackAddr = LoweredPartialApplyAllocations[i->getOperand ()];
6671- emitDeallocateDynamicAlloca (stackAddr);
6681+ emitDeallocateDynamicAlloca (stackAddr, closure-> isStackAllocationNested () );
66726682 return ;
66736683 }
66746684 if (isaResultOf<BeginApplyInst>(i->getOperand ())) {
66756685 auto *mvi = getAsResultOf<BeginApplyInst>(i->getOperand ());
66766686 auto *bai = cast<BeginApplyInst>(mvi->getParent ());
6687+ // FIXME: [non_nested]
66776688 const auto &coroutine = getLoweredCoroutine (bai->getTokenResult ());
66786689 emitDeallocYieldOnce2CoroutineFrame (*this ,
66796690 coroutine.getCalleeAllocatedFrame ());
66806691 return ;
66816692 }
66826693
6683- auto allocatedType = i->getOperand ()->getType ();
6694+ auto *asi = cast<AllocStackInst>(i->getOperand ());
6695+
6696+ auto allocatedType = asi->getType ();
66846697 const TypeInfo &allocatedTI = getTypeInfo (allocatedType);
6685- StackAddress stackAddr = getLoweredStackAddress (i->getOperand ());
6698+ StackAddress stackAddr = getLoweredStackAddress (asi);
6699+ auto isNested = asi->isStackAllocationNested ();
66866700
6687- allocatedTI.deallocateStack (*this , stackAddr, allocatedType);
6701+ allocatedTI.deallocateStack (*this , stackAddr, allocatedType, isNested );
66886702}
66896703
66906704void IRGenSILFunction::visitDeallocStackRefInst (DeallocStackRefInst *i) {
0 commit comments