Skip to content

Commit ebb99cd

Browse files
authored
Merge pull request #68957 from eeckstein/fix-explicit-copy-addr-5.10
[5.10] SIL: need to handle explicit_copy_addr in SILInstruction::mayRelease
2 parents 0a254b4 + 6b0d2b5 commit ebb99cd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,13 @@ bool SILInstruction::mayRelease() const {
11501150
return Cast->getConsumptionKind() == CastConsumptionKind::TakeAlways;
11511151
}
11521152

1153+
case SILInstructionKind::ExplicitCopyAddrInst: {
1154+
auto *CopyAddr = cast<ExplicitCopyAddrInst>(this);
1155+
// copy_addr without initialization can cause a release.
1156+
return CopyAddr->isInitializationOfDest() ==
1157+
IsInitialization_t::IsNotInitialization;
1158+
}
1159+
11531160
case SILInstructionKind::CopyAddrInst: {
11541161
auto *CopyAddr = cast<CopyAddrInst>(this);
11551162
// copy_addr without initialization can cause a release.

test/SILOptimizer/side_effects.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,3 +1182,16 @@ bb0(%0 : $*T, %1 : $*T):
11821182
return %4 : $()
11831183
}
11841184

1185+
// CHECK-LABEL: sil [ossa] @test_explicit_copy_addr
1186+
// CHECK-NEXT: [%0: read v**, copy v**]
1187+
// CHECK-NEXT: [global: read,write,copy,destroy,allocate,deinit_barrier]
1188+
// CHECK-NEXT: {{^[^[]}}
1189+
sil [ossa] @test_explicit_copy_addr : $@convention(thin) <T> (@in_guaranteed T) -> () {
1190+
bb0(%0 : $*T):
1191+
%1 = alloc_stack $T
1192+
explicit_copy_addr %0 to [init] %1 : $*T
1193+
destroy_addr %1 : $*T
1194+
dealloc_stack %1 : $*T
1195+
%r = tuple()
1196+
return %r : $()
1197+
}

0 commit comments

Comments
 (0)