mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
introduce a common superclass, SILNode. This is in preparation for allowing instructions to have multiple results. It is also a somewhat more elegant representation for instructions that have zero results. Instructions that are known to have exactly one result inherit from a class, SingleValueInstruction, that subclasses both ValueBase and SILInstruction. Some care must be taken when working with SILNode pointers and testing for equality; please see the comment on SILNode for more information. A number of SIL passes needed to be updated in order to handle this new distinction between SIL values and SIL instructions. Note that the SIL parser is now stricter about not trying to assign a result value from an instruction (like 'return' or 'strong_retain') that does not produce any.
97 lines
2.5 KiB
Plaintext
97 lines
2.5 KiB
Plaintext
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-silgen | %FileCheck %s
|
|
|
|
// Check that all reference counting instructions can take the [nonatomic]
|
|
// attribute. SIL parser should be able to parse this attribute and
|
|
// SIL printer should properly print it.
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
import Swift
|
|
import SwiftShims
|
|
|
|
public class C {
|
|
deinit
|
|
init()
|
|
}
|
|
|
|
// foo(C) -> C
|
|
sil [noinline] @_TF28nonatomic_reference_counting3fooFCS_1CS0_ : $@convention(thin) (@owned C) -> @owned C {
|
|
bb0(%0 : $C):
|
|
return %0 : $C
|
|
}
|
|
|
|
// CHECK-LABEL: sil @test_strong_nonatomic_rr
|
|
// CHECK: strong_retain [nonatomic]
|
|
// CHECK: strong_release [nonatomic]
|
|
// CHECK: return
|
|
sil @test_strong_nonatomic_rr: $@convention(thin) () -> @owned C {
|
|
bb0:
|
|
%1 = alloc_ref $C
|
|
strong_retain [nonatomic] %1 : $C
|
|
strong_release [nonatomic] %1 : $C
|
|
return %1 : $C
|
|
}
|
|
|
|
// CHECK-LABEL: sil @test_nonatomic_rr_value
|
|
// CHECK: retain_value [nonatomic]
|
|
// CHECK: release_value [nonatomic]
|
|
// CHECK: return
|
|
sil @test_nonatomic_rr_value: $@convention(thin) () -> @owned C {
|
|
bb0:
|
|
%1 = alloc_ref $C
|
|
retain_value [nonatomic] %1 : $C
|
|
release_value [nonatomic] %1 : $C
|
|
return %1 : $C
|
|
}
|
|
|
|
// CHECK-LABEL: sil @test_nonatomic_pin_unpin
|
|
// CHECK: strong_pin [nonatomic]
|
|
// CHECK: strong_unpin [nonatomic]
|
|
// CHECK: return
|
|
sil @test_nonatomic_pin_unpin: $@convention(thin) () -> () {
|
|
bb0:
|
|
%0 = alloc_ref $C
|
|
%1 = unchecked_ref_cast %0 : $C to $Builtin.NativeObject
|
|
%2 = strong_pin [nonatomic] %1 : $Builtin.NativeObject
|
|
strong_unpin [nonatomic] %2 : $Optional<Builtin.NativeObject>
|
|
%3 = tuple ()
|
|
return %3 : $()
|
|
}
|
|
|
|
// CHECK-LABEL: sil @test_unowned_nonatomic_rr
|
|
// CHECK: unowned_retain [nonatomic]
|
|
// CHECK: unowned_release [nonatomic]
|
|
// CHECK: return
|
|
sil @test_unowned_nonatomic_rr: $@convention(thin) () -> () {
|
|
bb0:
|
|
%0 = alloc_ref $C
|
|
%1 = ref_to_unowned %0 : $C to $@sil_unowned C
|
|
unowned_retain [nonatomic] %1 : $@sil_unowned C
|
|
unowned_release [nonatomic] %1 : $@sil_unowned C
|
|
%3 = tuple ()
|
|
return %3 : $()
|
|
}
|
|
|
|
// CHECK-LABEL: sil @test_set_deallocating
|
|
// CHECK: set_deallocating [nonatomic]
|
|
// CHECK: return
|
|
sil @test_set_deallocating : $C -> C {
|
|
bb0(%0 : $C):
|
|
set_deallocating [nonatomic] %0 : $C
|
|
return %0 : $C
|
|
}
|
|
|
|
// C.__deallocating_deinit
|
|
sil @_TFC28nonatomic_reference_counting1CD : $@convention(method) (@owned C) -> () {
|
|
bb0(%0 : $C):
|
|
dealloc_ref %0 : $C
|
|
%4 = tuple ()
|
|
return %4 : $()
|
|
}
|
|
|
|
sil_vtable C {
|
|
#C.deinit!deallocator: _TFC28nonatomic_reference_counting1CD // C.__deallocating_deinit
|
|
}
|
|
|