Skip to content

Commit b05d3c2

Browse files
author
Joe Shajrawi
authored
Merge pull request #5138 from shajrawi/copy_addr_to_moves
Comment on why we can't replace copy_addr instructions with moves in arc-inert blocks
2 parents 4bdf252 + 13b7bd5 commit b05d3c2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,6 +3420,16 @@ bool SimplifyCFG::simplifyProgramTerminationBlock(SILBasicBlock *BB) {
34203420
bool Changed = false;
34213421
llvm::SmallPtrSet<SILInstruction *, 4> InstsToRemove;
34223422
for (auto &I : *BB) {
3423+
// We can only remove the instructions below from the ARC-inert BB
3424+
// We *can't* replace copy_addr with move instructions:
3425+
// If the copy_addr was [take] [initialization]:
3426+
// * previous passes would have replaced it with moves
3427+
// If the copy_addr contains [initialization]:
3428+
// * nothing we can do - the target address is invalid
3429+
// Else, i.e. the copy_addr was [take] assignment, it is not always safe:
3430+
// The type being operated on might contain weak references,
3431+
// or other side references - We'll corrupt the weak reference table
3432+
// if we fail to release the old value.
34233433
if (!isa<StrongReleaseInst>(I) && !isa<UnownedReleaseInst>(I) &&
34243434
!isa<ReleaseValueInst>(I) && !isa<DestroyAddrInst>(I))
34253435
continue;

0 commit comments

Comments
 (0)