Skip to content

Commit f176ea9

Browse files
authored
Merge pull request #35675 from meg-gupta/fixmayrelease
Handle unchecked_ownership_conversion in SILInstruction::mayRelease
2 parents ab03052 + dae076d commit f176ea9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ bool SILInstruction::mayRelease() const {
11311131

11321132
case SILInstructionKind::UnconditionalCheckedCastAddrInst:
11331133
case SILInstructionKind::UnconditionalCheckedCastValueInst:
1134+
case SILInstructionKind::UncheckedOwnershipConversionInst:
11341135
return true;
11351136

11361137
case SILInstructionKind::CheckedCastAddrBranchInst: {

test/SILOptimizer/access_enforcement_opts_ossa.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ struct X {
1414
init()
1515
}
1616

17+
class Klass {
18+
19+
}
20+
1721
var globalX: X
1822

1923
var globalOtherX: X
@@ -1789,3 +1793,27 @@ bb0(%0 : $*T):
17891793
%108 = tuple ()
17901794
return %108 : $()
17911795
}
1796+
1797+
// Test that SILInstruction::mayRelease recognizes
1798+
// unchecked_ownership_conversion without asserting.
1799+
// CHECK-LABEL: sil hidden [ossa] @$testUncheckedOwnershipConversion :
1800+
// CHECK: begin_access
1801+
// CHECK: unchecked_ownership_conversion
1802+
// CHECK-LABEL: } // end sil function '$testUncheckedOwnershipConversion'
1803+
sil hidden [ossa] @$testUncheckedOwnershipConversion : $@convention(method) (@guaranteed Klass, @in Int64) -> @owned Builtin.NativeObject {
1804+
bb0(%0 : @guaranteed $Klass, %1 : $*Int64):
1805+
%2 = begin_access [modify] [dynamic] %1 : $*Int64
1806+
%3 = struct_element_addr %2 : $*Int64, #Int64._value
1807+
%4 = load [trivial] %3 : $*Builtin.Int64
1808+
%5 = integer_literal $Builtin.Int1, -1
1809+
%6 = builtin "ssub_with_overflow_Int64"(%4 : $Builtin.Int64, %4 : $Builtin.Int64, %5 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
1810+
(%7, %8) = destructure_tuple %6 : $(Builtin.Int64, Builtin.Int1)
1811+
cond_fail %8 : $Builtin.Int1, "arithmetic overflow"
1812+
%10 = struct $Int64 (%7 : $Builtin.Int64)
1813+
store %10 to [trivial] %2 : $*Int64
1814+
end_access %2 : $*Int64
1815+
%13 = unchecked_ref_cast %0 : $Klass to $Builtin.NativeObject
1816+
%14 = unchecked_ownership_conversion %13 : $Builtin.NativeObject, @guaranteed to @owned
1817+
return %14 : $Builtin.NativeObject
1818+
}
1819+

0 commit comments

Comments
 (0)