Skip to content

Commit 181cf98

Browse files
authored
Merge pull request #4599 from eeckstein/er-matcher-fix
ARC: fix epilog-release-matcher. It has to handle dealloc_ref instructions
2 parents a63e114 + 3970b4b commit 181cf98

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SILOptimizer/Analysis/ARCAnalysis.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,11 @@ collectMatchingReleases(SILBasicBlock *BB) {
777777
for (auto II = std::next(BB->rbegin()), IE = BB->rend(); II != IE; ++II) {
778778
// If we do not have a release_value or strong_release. We can continue
779779
if (!isa<ReleaseValueInst>(*II) && !isa<StrongReleaseInst>(*II)) {
780+
781+
// We cannot match a final release if it is followed by a dealloc_ref.
782+
if (isa<DeallocRefInst>(*II))
783+
break;
784+
780785
// We do not know what this instruction is, do a simple check to make sure
781786
// that it does not decrement the reference count of any of its operand.
782787
//

test/SILOptimizer/epilogue_release_dumper.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ bb0(%0 : $foo, %1 : $*foo):
9494
return %3 : $()
9595
}
9696

97+
// CHECK-LABEL: START: sil @dealloc_ref_after_last_release
98+
// CHECK: [[IN1:%.*]] = argument of bb0 : $foo
99+
// CHECK-NOT: strong_release [[IN1]] : $foo
100+
// CHECK: END: sil @dealloc_ref_after_last_release
101+
sil @dealloc_ref_after_last_release : $@convention(thin) (@owned foo) -> () {
102+
bb0(%0 : $foo):
103+
strong_retain %0 : $foo
104+
strong_release %0 : $foo
105+
dealloc_ref %0 : $foo
106+
%3 = tuple ()
107+
return %3 : $()
108+
}
109+
97110
// CHECK-LABEL: START: sil @single_release_bar
98111
// CHECK: [[IN1:%.*]] = argument of bb0 : $bar
99112
// CHECK: strong_release [[IN1]] : $bar

0 commit comments

Comments
 (0)