Skip to content

Commit 571288f

Browse files
authored
Merge pull request #35596 from atrick/fix-unmanaged-release
Fix SILInstruction::mayRelease to handle unmanaged_release_value.
2 parents 3efa18f + 9a48d0e commit 571288f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ bool SILInstruction::mayRelease() const {
11261126
case SILInstructionKind::YieldInst:
11271127
case SILInstructionKind::DestroyAddrInst:
11281128
case SILInstructionKind::StrongReleaseInst:
1129+
#define UNCHECKED_REF_STORAGE(Name, ...) \
1130+
case SILInstructionKind::Name##ReleaseValueInst:
11291131
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
11301132
case SILInstructionKind::Name##ReleaseInst:
11311133
#include "swift/AST/ReferenceStorage.def"

test/SILOptimizer/access_enforcement_opts_ossa.sil

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,3 +1760,32 @@ bb0(%0 : @guaranteed ${ var Int64 }):
17601760
end_access %access : $*Int64
17611761
return %val : $Int64
17621762
}
1763+
1764+
1765+
// Test that SILInstruction::mayRelease recognizes
1766+
// unmanaged_release_value without asserting.
1767+
// CHECK-LABEL: sil [transparent] [serialized] [ossa] @testUnmanagedRelease : $@convention(method) <T where T : AnyObject> (@inout T) -> () {
1768+
// CHECK: begin_access
1769+
// CHECK: unmanaged_release_value
1770+
// CHECK-LABEL: } // end sil function 'testUnmanagedRelease'
1771+
sil [transparent] [serialized] [ossa] @testUnmanagedRelease : $@convention(method) <T where T : AnyObject> (@inout T) -> () {
1772+
bb0(%0 : $*T):
1773+
%access = begin_access [modify] [dynamic] %0 : $*T
1774+
%load = load [copy] %access : $*T
1775+
end_access %access : $*T
1776+
%unmanaged1 = ref_to_unmanaged %load : $T to $@sil_unmanaged T
1777+
%copy1 = strong_copy_unmanaged_value %unmanaged1 : $@sil_unmanaged T
1778+
unmanaged_retain_value %copy1 : $T
1779+
%cast1 = unchecked_bitwise_cast %copy1 : $T to $UnsafeRawPointer
1780+
destroy_value %copy1 : $T
1781+
%cast2 = unchecked_bitwise_cast %cast1 : $UnsafeRawPointer to $T
1782+
%copy2 = copy_value %cast2 : $T
1783+
%unmanaged2 = ref_to_unmanaged %copy2 : $T to $@sil_unmanaged T
1784+
destroy_value %copy2 : $T
1785+
%copy3 = strong_copy_unmanaged_value %unmanaged2 : $@sil_unmanaged T
1786+
unmanaged_release_value %copy3 : $T
1787+
destroy_value %copy3 : $T
1788+
destroy_value %load : $T
1789+
%108 = tuple ()
1790+
return %108 : $()
1791+
}

0 commit comments

Comments
 (0)