1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// RUN: %sil-opt -enable-sil-verify-all %s -sil-combine | %FileCheck %s
// Note: Intentionally not using %target-sil-opt, because we need at least a
// swift 5.1 deployment target.
// REQUIRES: swift_in_compiler
sil_stage canonical
import Builtin
import Swift
import SwiftShims
sil_global public_external @_swiftEmptyArrayStorage : $_SwiftEmptyArrayStorage
// CHECK-LABEL: sil @testEmptyArraySingleton
// CHECK: global_addr
// CHECK-NOT: retain
// CHECK: } // end sil function 'testEmptyArraySingleton'
sil @testEmptyArraySingleton : $@convention(thin) () -> @owned Builtin.BridgeObject {
bb0:
%0 = global_addr @_swiftEmptyArrayStorage : $*_SwiftEmptyArrayStorage
%1 = address_to_pointer %0 : $*_SwiftEmptyArrayStorage to $Builtin.RawPointer
%2 = raw_pointer_to_ref %1 : $Builtin.RawPointer to $__EmptyArrayStorage
%3 = unchecked_ref_cast %2 : $__EmptyArrayStorage to $Builtin.BridgeObject
strong_retain %3 : $Builtin.BridgeObject
return %3 : $Builtin.BridgeObject
}
sil_global @staticArray : $_ContiguousArrayStorage<Int> = {
%0 = integer_literal $Builtin.Int64, 0
%1 = struct $UInt (%0 : $Builtin.Int64)
%2 = struct $Int (%0 : $Builtin.Int64)
%3 = struct $_SwiftArrayBodyStorage (%2 : $Int, %1 : $UInt)
%4 = struct $_ArrayBody (%3 : $_SwiftArrayBodyStorage)
%initval = object $_ContiguousArrayStorage<Int> (%4 : $_ArrayBody)
}
// CHECK-LABEL: sil @testGlobalValue
// CHECK: global_value
// CHECK-NOT: retain
// CHECK: } // end sil function 'testGlobalValue'
sil @testGlobalValue : $@convention(thin) () -> @owned Builtin.BridgeObject {
bb0:
%0 = global_value @staticArray : $_ContiguousArrayStorage<Int>
%1 = unchecked_ref_cast %0 : $_ContiguousArrayStorage<Int> to $Builtin.BridgeObject
strong_retain %1 : $Builtin.BridgeObject
return %1 : $Builtin.BridgeObject
}
// CHECK-LABEL: sil [serialized] @testGlobalValueSerialized
// CHECK: global_value
// CHECK: retain
// CHECK: } // end sil function 'testGlobalValueSerialized'
sil [serialized] @testGlobalValueSerialized : $@convention(thin) () -> @owned Builtin.BridgeObject {
bb0:
%0 = global_value @staticArray : $_ContiguousArrayStorage<Int>
%1 = unchecked_ref_cast %0 : $_ContiguousArrayStorage<Int> to $Builtin.BridgeObject
strong_retain %1 : $Builtin.BridgeObject
return %1 : $Builtin.BridgeObject
}
@_semantics("arc.immortal") protocol P : AnyObject {
}
@_semantics("arc.immortal") class C {
init()
}
@_inheritsConvenienceInitializers class D : C {
override init()
}
class E : P {
init()
}
// CHECK-LABEL: sil @testSemanticsOnClass
// CHECK-NOT: retain
// CHECK: } // end sil function 'testSemanticsOnClass'
sil @testSemanticsOnClass : $@convention(thin) (@guaranteed C) -> @owned C {
bb0(%0 : $C):
strong_retain %0 : $C
return %0 : $C // id: %3
}
// CHECK-LABEL: sil @testSemanticsOnDerivedClass
// CHECK-NOT: retain
// CHECK: } // end sil function 'testSemanticsOnDerivedClass'
sil @testSemanticsOnDerivedClass : $@convention(thin) (@guaranteed D) -> @owned D {
bb0(%0 : $D):
strong_retain %0 : $D
return %0 : $D
}
// CHECK-LABEL: sil @testSemanticsOnConformingClass
// CHECK-NOT: retain
// CHECK: } // end sil function 'testSemanticsOnConformingClass'
sil @testSemanticsOnConformingClass : $@convention(thin) (@guaranteed E) -> @owned E {
bb0(%0 : $E):
strong_retain %0 : $E
return %0 : $E
}
// CHECK-LABEL: sil @testSemanticsOnProtocol
// CHECK-NOT: retain
// CHECK: } // end sil function 'testSemanticsOnProtocol'
sil @testSemanticsOnProtocol : $@convention(thin) (@guaranteed any P) -> @owned any P {
bb0(%0 : $any P):
strong_retain %0 : $any P
return %0 : $any P
}
|