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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
// RUN: %target-swift-emit-sil -I %S/Inputs -cxx-interoperability-mode=upcoming-swift -disable-availability-checking -diagnostic-style llvm %s -validate-tbd-against-ir=none -Xcc -fignore-exceptions | %FileCheck %s
import FunctionsAndMethodsReturningFRT
func testFriendFunctionsReturningFRT() {
let frtLocalVar1 = returnInstanceOfFRTStruct()
// CHECK: function_ref @{{.*}}returnInstanceOfFRTStruct{{.*}} : $@convention(c) () -> Optional<FRTStruct>
let frtLocalVar2 = returnInstanceOfFRTStructWithAttrReturnsRetained()
// CHECK: function_ref @{{.*}}returnInstanceOfFRTStructWithAttrReturnsRetained{{.*}} : $@convention(c) () -> @owned Optional<FRTStruct>
let frtLocalVar3 = returnInstanceOfFRTStructWithAttrReturnsUnretained()
// CHECK: function_ref @{{.*}}returnInstanceOfFRTStructWithAttrReturnsUnretained{{.*}} : $@convention(c) () -> Optional<FRTStruct>
}
func testFreeFunctionsWithoutAttrubutes() {
let frtLocalVar1 = global_function_returning_FRT()
// CHECK: function_ref @{{.*}}global_function_returning_FRT{{.*}} : $@convention(c) () -> FRTStruct
// Free/global functions having copy/create in the function name are passed as owned by default
let frtLocalVar2 = global_function_returning_copy()
// CHECK: function_ref @{{.*}}global_function_returning_copy{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar3 = global_function_returning_create()
// CHECK: function_ref @{{.*}}global_function_returning_create{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar4 = global_function_returning_init()
// CHECK: function_ref @{{.*}}global_function_returning_init{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar5 = global_function_returning_clone()
// CHECK: function_ref @{{.*}}global_function_returning_clone{{.*}} : $@convention(c) () -> FRTStruct
}
func testFreeFunctionsWithAttrubuteReturnsRetained() {
let frtLocalVar1 = global_function_returning_FRT_with_attr_returns_retained()
// CHECK: function_ref @{{.*}}global_function_returning_FRT_with_attr_returns_retained{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar2 = global_function_returning_copy_with_attr_returns_retained()
// CHECK: function_ref @{{.*}}global_function_returning_copy_with_attr_returns_retained{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar3 = global_function_returning_create_with_attr_returns_retained()
// CHECK: function_ref @{{.*}}global_function_returning_create_with_attr_returns_retained{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar4 = global_function_returning_init_with_attr_returns_retained()
// CHECK: function_ref @{{.*}}global_function_returning_init_with_attr_returns_retained{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar5 = global_function_returning_clone_with_attr_returns_retained()
// CHECK: function_ref @{{.*}}global_function_returning_clone_with_attr_returns_retained{{.*}} : $@convention(c) () -> @owned FRTStruct
}
func testFreeFunctionsWithAttrubuteReturnsUnretained() {
let frtLocalVar1 = global_function_returning_FRT_with_attr_returns_unretained()
// CHECK: function_ref @{{.*}}global_function_returning_FRT_with_attr_returns_unretained{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar2 = global_function_returning_copy_with_attr_returns_unretained()
// CHECK: function_ref @{{.*}}global_function_returning_copy_with_attr_returns_unretained{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar3 = global_function_returning_create_with_attr_returns_unretained()
// CHECK: function_ref @{{.*}}global_function_returning_create_with_attr_returns_unretained{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar4 = global_function_returning_init_with_attr_returns_unretained()
// CHECK: function_ref @{{.*}}global_function_returning_init_with_attr_returns_unretained{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar5 = global_function_returning_clone_with_attr_returns_unretained()
// CHECK: function_ref @{{.*}}global_function_returning_clone_with_attr_returns_unretained{{.*}} : $@convention(c) () -> FRTStruct
}
func testStaticFreeFunctions() {
let frtLocalVar1 = global_static_function_returning_FRT()
// CHECK: function_ref @{{.*}}global_static_function_returning_FRT{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar2 = global_static_function_returning_FRT_with_attr_returns_retained()
// CHECK: function_ref @{{.*}}global_static_function_returning_FRT_with_attr_returns_retained{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar3 = global_static_function_returning_FRT_with_attr_returns_unretained()
// CHECK: function_ref @{{.*}}global_static_function_returning_FRT_with_attr_returns_unretained{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar4 = global_static_function_returning_copy()
// CHECK: function_ref @{{.*}}global_static_function_returning_copy{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar5 = global_static_function_returning_create()
// CHECK: function_ref @{{.*}}global_static_function_returning_create{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar6 = global_static_function_returning_copy_with_attr_returns_retained()
// CHECK: function_ref @{{.*}}global_static_function_returning_copy_with_attr_returns_retained{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar7 = global_static_function_returning_copy_with_attr_returns_unretained()
// CHECK: function_ref @{{.*}}global_static_function_returning_copy_with_attr_returns_unretained{{.*}} : $@convention(c) () -> FRTStruct
}
// Testing Global/free C++ functions without _Nonnull
func testtFreeFunctionsWithoutNonnull() {
let frtLocalVar1 = global_function_returning_FRT_wihout_Nonnull()
// CHECK: function_ref @{{.*}}global_function_returning_FRT_wihout_Nonnull{{.*}} : $@convention(c) () -> Optional<FRTStruct>
let frtLocalVar2 = global_function_returning_FRT_with_attr_returns_retained_wihout_Nonnull()
// CHECK: function_ref @{{.*}}global_function_returning_FRT_with_attr_returns_retained_wihout_Nonnull{{.*}} : $@convention(c) () -> @owned Optional<FRTStruct>
let frtLocalVar3 = global_function_returning_FRT_with_attr_returns_unretained_wihout_Nonnull()
// CHECK: function_ref @{{.*}}global_function_returning_FRT_with_attr_returns_unretained_wihout_Nonnull{{.*}} : $@convention(c) () -> Optional<FRTStruct>
let frtLocalVar4 = global_function_returning_copy_wihout_Nonnull()
// CHECK: function_ref @{{.*}}global_function_returning_copy_wihout_Nonnull{{.*}} : $@convention(c) () -> @owned Optional<FRTStruct>
let frtLocalVar5 = global_function_returning_create_wihout_Nonnull()
// CHECK: function_ref @{{.*}}global_function_returning_create_wihout_Nonnull{{.*}} : $@convention(c) () -> @owned Optional<FRTStruct>
let frtLocalVar6 = global_function_returning_copy_with_attr_returns_retained_wihout_Nonnull()
// CHECK: function_ref @{{.*}}global_function_returning_copy_with_attr_returns_retained_wihout_Nonnull{{.*}} : $@convention(c) () -> @owned Optional<FRTStruct>
let frtLocalVar7 = global_function_returning_copy_with_attr_returns_unretained_wihout_Nonnull()
// CHECK: function_ref @{{.*}}global_function_returning_copy_with_attr_returns_unretained_wihout_Nonnull{{.*}} : $@convention(c) () -> Optional<FRTStruct>
}
func testStaticMethodsWithoutAttrubutes() {
let frtLocalVar1 = StructWithStaticMethodsReturningFRTWithoutAttributes.StaticMethodReturningFRT()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar2 = StructWithStaticMethodsReturningFRTWithoutAttributes.StaticMethodReturningFRT_copy()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_copy{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar3 = StructWithStaticMethodsReturningFRTWithoutAttributes.StaticMethodReturningFRT_create()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_create{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar4 = StructWithStaticMethodsReturningFRTWithoutAttributes.StaticMethodReturningFRT_init()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_init{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar5 = StructWithStaticMethodsReturningFRTWithoutAttributes.StaticMethodReturningFRT_clone()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_clone{{.*}} : $@convention(c) () -> FRTStruct
}
func testStaticMethodsWithAttrubuteReturnsRetained() {
let frtLocalVar1 = StructWithStaticMethodsReturningFRTWithAttributeReturnsRetained.StaticMethodReturningFRT()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar2 = StructWithStaticMethodsReturningFRTWithAttributeReturnsRetained.StaticMethodReturningFRT_copy()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_copy{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar3 = StructWithStaticMethodsReturningFRTWithAttributeReturnsRetained.StaticMethodReturningFRT_create()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_create{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar4 = StructWithStaticMethodsReturningFRTWithAttributeReturnsRetained.StaticMethodReturningFRT_init()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_init{{.*}} : $@convention(c) () -> @owned FRTStruct
let frtLocalVar5 = StructWithStaticMethodsReturningFRTWithAttributeReturnsRetained.StaticMethodReturningFRT_clone()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_clone{{.*}} : $@convention(c) () -> @owned FRTStruct
}
func testStaticMethodsWithAttrubuteReturnsUnretained() {
let frtLocalVar1 = StructWithStaticMethodsReturningFRTWithAttributeReturnsUnretained.StaticMethodReturningFRT()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar2 = StructWithStaticMethodsReturningFRTWithAttributeReturnsUnretained.StaticMethodReturningFRT_copy()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_copy{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar3 = StructWithStaticMethodsReturningFRTWithAttributeReturnsUnretained.StaticMethodReturningFRT_create()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_create{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar4 = StructWithStaticMethodsReturningFRTWithAttributeReturnsUnretained.StaticMethodReturningFRT_init()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_init{{.*}} : $@convention(c) () -> FRTStruct
let frtLocalVar5 = StructWithStaticMethodsReturningFRTWithAttributeReturnsUnretained.StaticMethodReturningFRT_clone()
// CHECK: function_ref @{{.*}}StaticMethodReturningFRT_clone{{.*}} : $@convention(c) () -> FRTStruct
}
func testFreeFunctionsReturningNonFRT() {
let frtLocalVar1 = global_function_returning_non_FRT()
// CHECK: function_ref @{{.*}}global_function_returning_non_FRT{{.*}} : $@convention(c) () -> UnsafeMutablePointer<NonFRTStruct>
let frtLocalVar4 = global_function_returning_non_FRT_create()
// CHECK: function_ref @{{.*}}global_function_returning_non_FRT_create{{.*}} : $@convention(c) () -> UnsafeMutablePointer<NonFRTStruct>
let frtLocalVar5 = global_function_returning_non_FRT_copy()
// CHECK: function_ref @{{.*}}global_function_returning_non_FRT_copy{{.*}} : $@convention(c) () -> UnsafeMutablePointer<NonFRTStruct>
}
func testStaticMethodsReturningNonFRT() {
let frtLocalVar1 = StructWithStaticMethodsReturningNonFRT.StaticMethodReturningNonFRT()
// CHECK: function_ref @{{.*}}StaticMethodReturningNonFRT{{.*}} : $@convention(c) () -> UnsafeMutablePointer<NonFRTStruct>
let frtLocalVar4 = StructWithStaticMethodsReturningNonFRT.StaticMethodReturningNonFRT_create()
// CHECK: function_ref @{{.*}}StaticMethodReturningNonFRT_create{{.*}} : $@convention(c) () -> UnsafeMutablePointer<NonFRTStruct>
let frtLocalVar5 = StructWithStaticMethodsReturningNonFRT.StaticMethodReturningNonFRT_copy()
// CHECK: function_ref @{{.*}}StaticMethodReturningNonFRT_copy{{.*}} : $@convention(c) () -> UnsafeMutablePointer<NonFRTStruct>
}
func testtFreeFunctionsTemplated(frt : FRTStruct) {
let frtLocalVar1 : Int = 1;
let frtLocalVar2 = global_templated_function_returning_FRT(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT{{.*}} : $@convention(c) (Int) -> FRTStruct
let frtLocalVar3 = global_templated_function_returning_FRT_copy(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_copy{{.*}} : $@convention(c) (Int) -> @owned FRTStruct
let frtLocalVar4 = global_templated_function_returning_FRT_create(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_create{{.*}} : $@convention(c) (Int) -> @owned FRTStruct
let frtLocalVar5 = global_templated_function_returning_FRT_init(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_init{{.*}} : $@convention(c) (Int) -> FRTStruct
let frtLocalVar6 = global_templated_function_returning_FRT_clone(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_clone{{.*}} : $@convention(c) (Int) -> FRTStruct
let frtLocalVar7 = global_templated_function_returning_FRT_with_attr_returns_retained(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_with_attr_returns_retained{{.*}} : $@convention(c) (Int) -> @owned FRTStruct
let frtLocalVar8 = global_templated_function_returning_FRT_copy_with_attr_returns_retained(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_copy_with_attr_returns_retained{{.*}} : $@convention(c) (Int) -> @owned FRTStruct
let frtLocalVar9 = global_templated_function_returning_FRT_create_with_attr_returns_retained(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_create_with_attr_returns_retained{{.*}} : $@convention(c) (Int) -> @owned FRTStruct
let frtLocalVar10 = global_templated_function_returning_FRT_with_attr_returns_unretained(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_with_attr_returns_unretained{{.*}} : $@convention(c) (Int) -> FRTStruct
let frtLocalVar11 = global_templated_function_returning_FRT_copy_with_attr_returns_unretained(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_copy_with_attr_returns_unretained{{.*}} : $@convention(c) (Int) -> FRTStruct
let frtLocalVar12 = global_templated_function_returning_FRT_create_with_attr_returns_unretained(frtLocalVar1)
// CHECK: function_ref @{{.*}}global_templated_function_returning_FRT_create_with_attr_returns_unretained{{.*}} : $@convention(c) (Int) -> FRTStruct
let frtLocalVar13 = global_function_returning_templated_retrun_frt(frt)
// CHECK: function_ref @{{.*}}global_function_returning_templated_retrun_frt{{.*}} : $@convention(c) (FRTStruct) -> FRTStruct
let frtLocalVar14 = global_function_returning_templated_retrun_frt_owned(frt)
// CHECK: function_ref @{{.*}}global_function_returning_templated_retrun_frt_owned{{.*}} : $@convention(c) (FRTStruct) -> @owned FRTStruct
}
func testVirtualMethods(base: Base, derived: Derived) {
var mutableBase = base
var mutableDerived = derived
var frt1 = mutableBase.VirtualMethodReturningFRTUnowned()
// CHECK: function_ref @{{.*}}VirtualMethodReturningFRTUnowned{{.*}} : $@convention(cxx_method) (@inout Base) -> FRTStruct
var frt2 = mutableDerived.VirtualMethodReturningFRTUnowned()
// CHECK: function_ref @{{.*}}VirtualMethodReturningFRTUnowned{{.*}} : $@convention(cxx_method) (@inout Derived) -> FRTStruct
var frt3 = mutableBase.VirtualMethodReturningFRTOwned()
// CHECK: function_ref @{{.*}}VirtualMethodReturningFRTOwned{{.*}} : $@convention(cxx_method) (@inout Base) -> @owned FRTStruct
var frt4 = mutableDerived.VirtualMethodReturningFRTOwned()
// CHECK: function_ref @{{.*}}VirtualMethodReturningFRTOwned{{.*}} : $@convention(cxx_method) (@inout Derived) -> @owned FRTStruct
}
|