@@ -1125,6 +1125,7 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
1125
1125
// Create the new set of arguments to apply including their substitutions.
1126
1126
SubstitutionMap NewCallSubs = Apply.getSubstitutionMap ();
1127
1127
SmallVector<SILValue, 8 > NewArgs;
1128
+ SmallVector<SILValue, 8 > valuesToClean;
1128
1129
unsigned ArgIdx = 0 ;
1129
1130
// Push the indirect result arguments.
1130
1131
for (unsigned EndIdx = Apply.getSubstCalleeConv ().getSILArgIndexOfFirstParam ();
@@ -1186,7 +1187,15 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
1186
1187
concreteArgCopies.push_back (*argSub);
1187
1188
NewArgs.push_back (argSub->tempArg );
1188
1189
} else {
1189
- NewArgs.push_back (CEI.ConcreteValue );
1190
+ auto argValue = CEI.ConcreteValue ;
1191
+ if (argValue->getOwnershipKind () == OwnershipKind::Owned) {
1192
+ SILBuilderWithScope copyBuilder (argValue->getNextInstruction (),
1193
+ BuilderCtx);
1194
+ argValue = copyBuilder.createCopyValue (
1195
+ argValue->getNextInstruction ()->getLoc (), argValue);
1196
+ valuesToClean.push_back (argValue);
1197
+ }
1198
+ NewArgs.push_back (argValue);
1190
1199
}
1191
1200
1192
1201
// Form a new set of substitutions where the argument is
@@ -1290,6 +1299,10 @@ SILInstruction *SILCombiner::createApplyWithConcreteType(
1290
1299
cleanupBuilder.createDestroyAddr (cleanupLoc, argCopy.origArg );
1291
1300
cleanupBuilder.createDeallocStack (cleanupLoc, argCopy.tempArg );
1292
1301
}
1302
+ // Insert compensating destroys for owned values.
1303
+ for (auto value : valuesToClean) {
1304
+ cleanupBuilder.createDestroyValue (cleanupLoc, value);
1305
+ }
1293
1306
}
1294
1307
return NewApply.getInstruction ();
1295
1308
}
0 commit comments