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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
|
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-library-evolution \
// RUN: -emit-module-path=%t/resilient_struct.swiftmodule \
// RUN: -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
// RUN: %target-sil-opt -sdk %clang-importer-sdk-path -enable-sil-verify-all %s -sil-combine -jumpthread-simplify-cfg -I %t | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
import resilient_struct
import ctypes
// CHECK-LABEL: sil @convert_inject_enum_addr_select_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> ()
// CHECK-NOT: init_existential_addr
// CHECK-NOT: inject_enum_addr
// CHECK-NOT: select_enum_addr
// CHECK-NOT: bb1
// CHECK-NOT: unchecked_take_enum_data_addr
// CHECK: return
sil @convert_inject_enum_addr_select_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> () {
bb0(%0 : $*Int, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $Int
%6 = load %0 : $*Int
store %6 to %5 : $*Int
unconditional_checked_cast_addr Int in %5 : $*Int to CustomStringConvertible in %4 : $*CustomStringConvertible
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
dealloc_stack %5 : $*Int
%11 = integer_literal $Builtin.Int1, -1
%12 = integer_literal $Builtin.Int1, 0
%13 = select_enum_addr %3 : $*Optional<CustomStringConvertible>, case #Optional.some!enumelt: %11, case #Optional.none!enumelt: %12 : $Builtin.Int1
cond_br %13, bb2, bb1
bb1:
%15 = tuple ()
dealloc_stack %3 : $*Optional<CustomStringConvertible>
dealloc_stack %2 : $*CustomStringConvertible
return %15 : $()
bb2:
%19 = unchecked_take_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
copy_addr [take] %19 to [init] %2 : $*CustomStringConvertible
br bb1
}
// CHECK-LABEL: sil @convert_inject_enum_addr_switch_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> ()
// CHECK-NOT: init_existential_addr
// CHECK-NOT: inject_enum_addr
// CHECK-NOT: switch_enum_addr
// CHECK-NOT: bb1
// CHECK-NOT: unchecked_take_enum_data_addr
// CHECK: return
sil @convert_inject_enum_addr_switch_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> () {
bb0(%0 : $*Int, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $Int
%6 = load %0 : $*Int
store %6 to %5 : $*Int
unconditional_checked_cast_addr Int in %5 : $*Int to CustomStringConvertible in %4 : $*CustomStringConvertible
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
dealloc_stack %5 : $*Int
switch_enum_addr %3 : $*Optional<CustomStringConvertible>, case #Optional.some!enumelt: bb3, case #Optional.none!enumelt: bb2
bb1:
%15 = tuple ()
dealloc_stack %3 : $*Optional<CustomStringConvertible>
dealloc_stack %2 : $*CustomStringConvertible
return %15 : $()
bb2:
br bb1
bb3:
%19 = unchecked_take_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
copy_addr [take] %19 to [init] %2 : $*CustomStringConvertible
br bb1
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
//
// CHECK-LABEL: sil @convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> ()
// CHECK: store
// CHECK-NOT: checked_cast_addr_br
// CHECK-NOT: bb1
// CHECK: inject_enum_addr %{{.*}} : $*Optional<any CustomStringConvertible>, #Optional.some!enumelt
// CHECK: dealloc_stack
// CHECK: return
sil @convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> () {
bb0(%0 : $*Int, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $Int
%6 = load %0 : $*Int
store %6 to %5 : $*Int
checked_cast_addr_br take_always Int in %5 : $*Int to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*Int
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
class A {
}
private final class B {
}
public class C {
}
// D cannot be extended elsewhere, but C can!
private class D : C {
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
// In a negative case, take care that check for internal types are not folded (unless
// a whole module optimization is used), because an extension implementing a conformance
// could be defined elsewhere.
//
// CHECK-LABEL: sil @convert_checked_cast_addr_br_with_internal_type : $@convention(thin) (@in A, @inout _Stdout) -> ()
// CHECK: checked_cast_addr_br
// CHECK: inject_enum_addr %{{.*}} : $*Optional<any CustomStringConvertible>, #Optional.some!enumelt
// CHECK: dealloc_stack
// CHECK: return
// CHECK: inject_enum_addr %{{.*}} : $*Optional<any CustomStringConvertible>, #Optional.none!enumelt
// CHECK: }
sil @convert_checked_cast_addr_br_with_internal_type : $@convention(thin) (@in A, @inout _Stdout) -> () {
bb0(%0 : $*A, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $A
%6 = load %0 : $*A
store %6 to %5 : $*A
checked_cast_addr_br take_always A in %5 : $*A to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*A
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
// In a negative case, if the source type is private, it is safe to fold the check,
// because a conformance for this type cannot be defined elsewhere.
//
// CHECK-LABEL: sil @convert_checked_cast_addr_br_with_private_type : $@convention(thin) (@in B, @inout _Stdout) -> ()
// CHECK: store
// CHECK-NOT: checked_cast_addr_br
// CHECK-NOT: bb1
// CHECK: inject_enum_addr %{{.*}} : $*Optional<any CustomStringConvertible>, #Optional.none!enumelt
// CHECK: dealloc_stack
// CHECK: return
sil @convert_checked_cast_addr_br_with_private_type : $@convention(thin) (@in B, @inout _Stdout) -> () {
bb0(%0 : $*B, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $B
%6 = load %0 : $*B
store %6 to %5 : $*B
checked_cast_addr_br take_always B in %5 : $*B to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*B
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
// In a negative case, take care that cast for private types are not folded if one
// of its superclasses could have a conformance extension defined elsewhere.
//
// CHECK-LABEL: sil @convert_checked_cast_addr_br_with_non_private_superclass : $@convention(thin) (@in D, @inout _Stdout) -> ()
// CHECK: checked_cast_addr_br
// CHECK: inject_enum_addr %{{.*}} : $*Optional<any CustomStringConvertible>, #Optional.some!enumelt
// CHECK: dealloc_stack
// CHECK: return
// CHECK: inject_enum_addr %{{.*}} : $*Optional<any CustomStringConvertible>, #Optional.none!enumelt
// CHECK: }
sil @convert_checked_cast_addr_br_with_non_private_superclass : $@convention(thin) (@in D, @inout _Stdout) -> () {
bb0(%0 : $*D, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $D
%6 = load %0 : $*D
store %6 to %5 : $*D
checked_cast_addr_br take_always D in %5 : $*D to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*D
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
sil @no_init : $@convention(thin) () -> (@out ())
// CHECK-LABEL: sil @test_empty_tuple_uninintialized : $@convention(thin) () -> () {
// TODO-NOT: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_tuple_uninintialized'
sil @test_empty_tuple_uninintialized : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $Optional<()>
%1 = init_enum_data_addr %0 : $*Optional<()>, #Optional.some!enumelt
%f = function_ref @no_init : $@convention(thin) () -> (@out ())
apply %f(%1) : $@convention(thin) () -> (@out ())
inject_enum_addr %0 : $*Optional<()>, #Optional.some!enumelt
%2 = load %0 : $*Optional<()>
switch_enum %2 : $Optional<()>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
bb1(%4 : $()):
br bb3
bb2:
br bb3
bb3:
dealloc_stack %0 : $*Optional<()>
%8 = tuple ()
return %8 : $()
}
sil @no_init_nested_tuple : $@convention(thin) () -> (@out ((), ()))
// CHECK-LABEL: sil @test_empty_nested_tuple_uninintialized : $@convention(thin) () -> () {
// TODO-NOT: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_nested_tuple_uninintialized'
sil @test_empty_nested_tuple_uninintialized : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $Optional<((), ())>
%1 = init_enum_data_addr %0 : $*Optional<((), ())>, #Optional.some!enumelt
%f = function_ref @no_init_nested_tuple : $@convention(thin) () -> (@out ((), ()))
apply %f(%1) : $@convention(thin) () -> (@out ((), ()))
inject_enum_addr %0 : $*Optional<((), ())>, #Optional.some!enumelt
%2 = load %0 : $*Optional<((), ())>
switch_enum %2 : $Optional<((), ())>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
bb1(%4 : $((), ())):
br bb3
bb2:
br bb3
bb3:
dealloc_stack %0 : $*Optional<((), ())>
%8 = tuple ()
return %8 : $()
}
sil @no_init_struct : $@convention(thin) () -> (@out ResilientEmptyStruct)
// CHECK-LABEL: sil @test_empty_struct_uninitialized : $@convention(thin) () -> () {
// TODO-NOT: switch_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_struct_uninitialized'
sil @test_empty_struct_uninitialized : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $Optional<ResilientEmptyStruct>
%1 = init_enum_data_addr %0 : $*Optional<ResilientEmptyStruct>, #Optional.some!enumelt
%f = function_ref @no_init_struct : $@convention(thin) () -> (@out ResilientEmptyStruct)
apply %f(%1) : $@convention(thin) () -> (@out ResilientEmptyStruct)
inject_enum_addr %0 : $*Optional<ResilientEmptyStruct>, #Optional.some!enumelt
switch_enum_addr %0 : $*Optional<ResilientEmptyStruct>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
bb1:
br bb3
bb2:
br bb3
bb3:
dealloc_stack %0 : $*Optional<ResilientEmptyStruct>
%8 = tuple ()
return %8 : $()
}
sil @no_init_c_union : $@convention(thin) () -> (@out EmptyCUnion)
// CHECK-LABEL: sil @test_empty_c_union : $@convention(thin) () -> () {
// TODO: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_c_union'
sil @test_empty_c_union : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $Optional<EmptyCUnion>
%1 = init_enum_data_addr %0 : $*Optional<EmptyCUnion>, #Optional.some!enumelt
%f = function_ref @no_init_c_union : $@convention(thin) () -> (@out EmptyCUnion)
apply %f(%1) : $@convention(thin) () -> (@out EmptyCUnion)
inject_enum_addr %0 : $*Optional<EmptyCUnion>, #Optional.some!enumelt
switch_enum_addr %0 : $*Optional<EmptyCUnion>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
bb1:
br bb3
bb2:
br bb3
bb3:
dealloc_stack %0 : $*Optional<EmptyCUnion>
%8 = tuple ()
return %8 : $()
}
struct NestedUnreferenceableStorage {
let e: EmptyCUnion
}
sil @no_init_nested_c_union : $@convention(thin) () -> (@out NestedUnreferenceableStorage)
// CHECK-LABEL: sil @test_empty_nested_c_union : $@convention(thin) () -> () {
// TODO: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_nested_c_union'
sil @test_empty_nested_c_union : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $Optional<NestedUnreferenceableStorage>
%1 = init_enum_data_addr %0 : $*Optional<NestedUnreferenceableStorage>, #Optional.some!enumelt
%f = function_ref @no_init_nested_c_union : $@convention(thin) () -> (@out NestedUnreferenceableStorage)
apply %f(%1) : $@convention(thin) () -> (@out NestedUnreferenceableStorage)
inject_enum_addr %0 : $*Optional<NestedUnreferenceableStorage>, #Optional.some!enumelt
switch_enum_addr %0 : $*Optional<NestedUnreferenceableStorage>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
bb1:
br bb3
bb2:
br bb3
bb3:
dealloc_stack %0 : $*Optional<NestedUnreferenceableStorage>
%8 = tuple ()
return %8 : $()
}
|