Skip to content

Commit b58f54c

Browse files
committed
CastOptimizer: fix a minor bug with memory lifetime.
This was not a real leak, because it only happened in an error condition where the block ends in an trap instructon anyway. But it must be fixed to make the MemoryLifetimeVerifier happy.
1 parent 0bac147 commit b58f54c

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,7 @@ SILInstruction *CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(
16231623
Builder.emitStoreValueOperation(Loc, undef, dynamicCast.getDest(),
16241624
StoreOwnershipQualifier::Init);
16251625
}
1626+
Builder.emitDestroyAddr(Loc, Inst->getSrc());
16261627
auto *TrapI = Builder.createBuiltinTrap(Loc);
16271628
eraseInstAction(Inst);
16281629
Builder.setInsertionPoint(std::next(TrapI->getIterator()));

test/SILOptimizer/sil_combine_uncheck.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ bb0(%0 : $Builtin.Int1):
3939
// CHECK-LABEL: sil @test_unconditional_checked_cast_addr_fail
4040
// CHECK: bb0
4141
// CHECK-NEXT: store undef
42+
// CHECK-NEXT: destroy_addr
4243
// CHECK-NEXT: builtin "int_trap"
4344
// CHECK: unreachable
4445
// CHECK: }

0 commit comments

Comments
 (0)