@@ -63,6 +63,12 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst,
63
63
return false ;
64
64
}
65
65
66
+ // Don't delete dead drop_deinit instruction. They are a marker to eliminate
67
+ // user-defined deinit and we do not want to lose it.
68
+ if (isa<DropDeinitInst>(inst)) {
69
+ return false ;
70
+ }
71
+
66
72
for (auto result : inst->getResults ()) {
67
73
// If inst has any owned move-only value as a result, deleting it may
68
74
// shorten that value's lifetime which is illegal according to language
@@ -268,9 +274,16 @@ void InstructionDeleter::deleteWithUses(SILInstruction *inst, bool fixLifetimes,
268
274
if (fixLifetimes) {
269
275
LoadInst *li = nullptr ;
270
276
if (operand.isConsuming ()) {
271
- SILBuilderWithScope builder (inst);
272
- auto *dvi = builder.createDestroyValue (inst->getLoc (), operandValue);
273
- getCallbacks ().createdNewInst (dvi);
277
+ if (isa<DropDeinitInst>(operandValue)) {
278
+ SILBuilderWithScope builder (inst);
279
+ auto *eli = builder.createEndLifetime (inst->getLoc (), operandValue);
280
+ getCallbacks ().createdNewInst (eli);
281
+ } else {
282
+ SILBuilderWithScope builder (inst);
283
+ auto *dvi =
284
+ builder.createDestroyValue (inst->getLoc (), operandValue);
285
+ getCallbacks ().createdNewInst (dvi);
286
+ }
274
287
} else if ((li = dyn_cast<LoadInst>(inst)) &&
275
288
li->getOwnershipQualifier () ==
276
289
LoadOwnershipQualifier::Take) {
0 commit comments