Skip to content

Commit 8569c9d

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 8569c9d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 11 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, /*type=*/llvm::Value *>, 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, argumentType));
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(
513+
std::make_pair(resultValue.getAddress(), argumentType));
508514
break;
509515
}
510516
}
@@ -584,6 +590,11 @@ void DistributedAccessor::emitReturn(llvm::Value *errorValue) {
584590
}
585591
}
586592

593+
// Destroy loaded arguments.
594+
llvm::for_each(LoadedArguments, [&](const auto &argInfo) {
595+
emitDestroyCall(IGF, argInfo.second, argInfo.first);
596+
});
597+
587598
Explosion voidResult;
588599

589600
Explosion error;

0 commit comments

Comments
 (0)