Files
swift-mirror/test/Serialization/ossa_sil.sil
Erik Eckstein 26b03096c6 SIL: fix serialization of the unchecked_ref_cast instruction
We didn't serialize the ownership kind, which resulted in a miscompile causing an over-release.

The unchecked_ref_cast is the only instruction for which we change the ownership in the optimizer, so that it doesn't match the operand's ownership. Therefore this fix is sufficient for now - we don't need to serialize the ownership of other instructions.
But this is really a design flaw of the `OwnershipForwardingMixin`. It should not allow to set the ownership to arbitrary values.

rdar://92696202
2022-05-06 15:30:51 +02:00

22 lines
670 B
Plaintext

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-module -module-name ossa -o %t/ossa.swiftmodule %s
// RUN: %target-sil-opt %t/ossa.swiftmodule | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
import SwiftShims
class X {}
// CHECK-LABEL: sil [serialized] [canonical] [ossa] @test_unchecked_ref_cast
sil [serialized] [ossa] @test_unchecked_ref_cast : $@convention(thin) (@guaranteed AnyObject) -> @owned X {
bb0(%0 : @guaranteed $AnyObject):
// CHECK: %1 = unchecked_ref_cast %0 : $AnyObject to $X, forwarding: @unowned
%1 = unchecked_ref_cast %0 : $AnyObject to $X, forwarding: @unowned
%2 = copy_value %1 : $X
return %2 : $X
}