Skip to content

Commit 41ddb28

Browse files
committed
[IRGen] Distributed: Destroy loaded arguments after the call
Arguments that have been loaded due to underlying method conversion have to be destroyed after the call otherwise they are going to leak. Resolves: #65853 Resolves: rdar://109207043
1 parent 143b016 commit 41ddb28

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class DistributedAccessor {
134134
/// The list of all arguments that were allocated on the stack.
135135
SmallVector<StackAddress, 4> AllocatedArguments;
136136

137+
/// The list of all the arguments that were loaded.
138+
SmallVector<std::pair<Address, SILType>, 4> LoadedArguments;
139+
137140
public:
138141
DistributedAccessor(IRGenFunction &IGF, SILFunction *target,
139142
CanSILFunctionType accessorTy);
@@ -498,13 +501,16 @@ void DistributedAccessor::decodeArgument(unsigned argumentIdx,
498501
resultValue.getAddress(), IGM.getStorageType(paramTy));
499502

500503
cast<LoadableTypeInfo>(paramInfo).loadAsTake(IGF, eltPtr, arguments);
504+
LoadedArguments.push_back(std::make_pair(eltPtr, paramTy));
501505
break;
502506
}
503507

504508
case ParameterConvention::Direct_Owned: {
505509
// Copy the value out at +1.
506510
cast<LoadableTypeInfo>(paramInfo).loadAsCopy(IGF, resultValue.getAddress(),
507511
arguments);
512+
LoadedArguments.push_back(std::make_pair(
513+
resultValue.getAddress(), param.getSILStorageInterfaceType()));
508514
break;
509515
}
510516
}
@@ -584,6 +590,13 @@ void DistributedAccessor::emitReturn(llvm::Value *errorValue) {
584590
}
585591
}
586592

593+
// Destroy loaded arguments.
594+
llvm::for_each(LoadedArguments, [&](const auto &argInfo) {
595+
auto argTy = argInfo.second;
596+
IGM.getTypeInfo(argTy).destroy(IGF, argInfo.first, argTy,
597+
/*isOutlined=*/false);
598+
});
599+
587600
Explosion voidResult;
588601

589602
Explosion error;

0 commit comments

Comments
 (0)