Skip to content

Fix SILInstruction::mayRelease to handle unmanaged_release_value. #35596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/SIL/IR/SILInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,8 @@ bool SILInstruction::mayRelease() const {
case SILInstructionKind::YieldInst:
case SILInstructionKind::DestroyAddrInst:
case SILInstructionKind::StrongReleaseInst:
#define UNCHECKED_REF_STORAGE(Name, ...) \
case SILInstructionKind::Name##ReleaseValueInst:
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
case SILInstructionKind::Name##ReleaseInst:
#include "swift/AST/ReferenceStorage.def"
Expand Down
29 changes: 29 additions & 0 deletions test/SILOptimizer/access_enforcement_opts_ossa.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1760,3 +1760,32 @@ bb0(%0 : @guaranteed ${ var Int64 }):
end_access %access : $*Int64
return %val : $Int64
}


// Test that SILInstruction::mayRelease recognizes
// unmanaged_release_value without asserting.
// CHECK-LABEL: sil [transparent] [serialized] [ossa] @testUnmanagedRelease : $@convention(method) <T where T : AnyObject> (@inout T) -> () {
// CHECK: begin_access
// CHECK: unmanaged_release_value
// CHECK-LABEL: } // end sil function 'testUnmanagedRelease'
sil [transparent] [serialized] [ossa] @testUnmanagedRelease : $@convention(method) <T where T : AnyObject> (@inout T) -> () {
bb0(%0 : $*T):
%access = begin_access [modify] [dynamic] %0 : $*T
%load = load [copy] %access : $*T
end_access %access : $*T
%unmanaged1 = ref_to_unmanaged %load : $T to $@sil_unmanaged T
%copy1 = strong_copy_unmanaged_value %unmanaged1 : $@sil_unmanaged T
unmanaged_retain_value %copy1 : $T
%cast1 = unchecked_bitwise_cast %copy1 : $T to $UnsafeRawPointer
destroy_value %copy1 : $T
%cast2 = unchecked_bitwise_cast %cast1 : $UnsafeRawPointer to $T
%copy2 = copy_value %cast2 : $T
%unmanaged2 = ref_to_unmanaged %copy2 : $T to $@sil_unmanaged T
destroy_value %copy2 : $T
%copy3 = strong_copy_unmanaged_value %unmanaged2 : $@sil_unmanaged T
unmanaged_release_value %copy3 : $T
destroy_value %copy3 : $T
destroy_value %load : $T
%108 = tuple ()
return %108 : $()
}