|
1 | 1 | // RUN: %target-sil-opt -parse-serialized-sil -enable-sil-verify-all %s -array-property-opt | %FileCheck %s
|
2 | 2 |
|
| 3 | +// Linux doesn't have the same symbol name for _ArrayBuffer, which is part of |
| 4 | +// the ObjC runtime interop. Use `_ContiguousArrayBuffer instead. |
| 5 | +// REQUIRES: objc_interop |
| 6 | + |
3 | 7 | sil_stage canonical
|
4 | 8 |
|
5 | 9 | import Builtin
|
@@ -258,3 +262,132 @@ bb10: // Exit dominated by bb3
|
258 | 262 | bb11: // Non-exit dominated by bb1
|
259 | 263 | return %4 : $Builtin.Int1
|
260 | 264 | }
|
| 265 | + |
| 266 | +class Klass { |
| 267 | + var val: Optional<Int> |
| 268 | +} |
| 269 | + |
| 270 | +struct WrapperStruct { |
| 271 | + var val: Klass |
| 272 | +} |
| 273 | + |
| 274 | +sil @use_klass : $@convention(thin) (@in_guaranteed Klass) -> () |
| 275 | + |
| 276 | +sil @test_sink_address_proj : $@convention(thin) (@inout MyArray<MyClass>, @in_guaranteed WrapperStruct) -> () { |
| 277 | +bb0(%0 : $*MyArray<MyClass>, %1 : $*WrapperStruct): |
| 278 | + %3 = load %0 : $*MyArray<MyClass> |
| 279 | + br bb1 |
| 280 | + |
| 281 | +bb1: |
| 282 | + %2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| 283 | + retain_value %3 : $MyArray<MyClass> |
| 284 | + %5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| 285 | + %ele = struct_element_addr %1 : $*WrapperStruct, #WrapperStruct.val |
| 286 | + cond_br undef, bb5, bb2 |
| 287 | + |
| 288 | +bb2: |
| 289 | + %6 = integer_literal $Builtin.Int1, -1 |
| 290 | + cond_br %6, bb3, bb4 |
| 291 | + |
| 292 | +bb3: |
| 293 | + br bb1 |
| 294 | + |
| 295 | +bb4: |
| 296 | + br bb6 |
| 297 | + |
| 298 | +bb5: |
| 299 | + %f = function_ref @use_klass : $@convention(thin) (@in_guaranteed Klass) -> () |
| 300 | + %a = apply %f(%ele) : $@convention(thin) (@in_guaranteed Klass) -> () |
| 301 | + br bb6 |
| 302 | + |
| 303 | +bb6: |
| 304 | + %t = tuple () |
| 305 | + return %t : $() |
| 306 | +} |
| 307 | + |
| 308 | +sil [_semantics "array.props.isNativeTypeChecked"] @hoistableIsNativeTypeChecked : $@convention(method) (@guaranteed Array<Klass>) -> Bool |
| 309 | +sil [_semantics "array.get_element"] @getElement : $@convention(method) (Int, Bool, _DependenceToken, @guaranteed Array<Klass>) -> @owned Klass |
| 310 | +sil [_semantics "array.get_count"] @getCount : $@convention(method) (@guaranteed Array<Klass>) -> Int |
| 311 | + |
| 312 | +sil hidden @test_array_prop_opt : $@convention(thin) (@guaranteed Optional<Array<Klass>>) -> Int { |
| 313 | +bb0(%0 : $Optional<Array<Klass>>): |
| 314 | + %4 = integer_literal $Builtin.Int64, 0 |
| 315 | + switch_enum %0 : $Optional<Array<Klass>>, case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb1 |
| 316 | + |
| 317 | +bb1: |
| 318 | + br bb12(%4 : $Builtin.Int64) |
| 319 | + |
| 320 | +bb2(%12 : $Array<Klass>): |
| 321 | + %14 = function_ref @getCount : $@convention(method) (@guaranteed Array<Klass>) -> Int |
| 322 | + retain_value %0 : $Optional<Array<Klass>> |
| 323 | + retain_value %0 : $Optional<Array<Klass>> |
| 324 | + %17 = apply %14(%12) : $@convention(method) (@guaranteed Array<Klass>) -> Int |
| 325 | + %18 = struct_extract %17 : $Int, #Int._value |
| 326 | + %19 = builtin "cmp_eq_Int64"(%18 : $Builtin.Int64, %4 : $Builtin.Int64) : $Builtin.Int1 |
| 327 | + cond_br %19, bb3, bb4 |
| 328 | + |
| 329 | +bb3: |
| 330 | + release_value %0 : $Optional<Array<Klass>> |
| 331 | + %22 = unchecked_enum_data %0 : $Optional<Array<Klass>>, #Optional.some!enumelt |
| 332 | + %23 = struct_extract %22 : $Array<Klass>, #Array._buffer |
| 333 | + %24 = struct_extract %23 : $_ArrayBuffer<Klass>, #_ArrayBuffer._storage |
| 334 | + %25 = struct_extract %24 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue |
| 335 | + strong_release %25 : $Builtin.BridgeObject |
| 336 | + br bb12(%4 : $Builtin.Int64) |
| 337 | + |
| 338 | +bb4: |
| 339 | + %28 = function_ref @hoistableIsNativeTypeChecked : $@convention(method) (@guaranteed Array<Klass>) -> Bool |
| 340 | + %29 = function_ref @getElement : $@convention(method) (Int, Bool, _DependenceToken, @guaranteed Array<Klass>) -> @owned Klass |
| 341 | + %30 = integer_literal $Builtin.Int64, 1 |
| 342 | + %31 = integer_literal $Builtin.Int1, -1 |
| 343 | + %32 = struct $_DependenceToken () |
| 344 | + br bb5(%4 : $Builtin.Int64) |
| 345 | + |
| 346 | +bb5(%34 : $Builtin.Int64): |
| 347 | + %35 = struct $Int (%34 : $Builtin.Int64) |
| 348 | + %36 = apply %28(%12) : $@convention(method) (@guaranteed Array<Klass>) -> Bool |
| 349 | + %37 = apply %29(%35, %36, %32, %12) : $@convention(method) (Int, Bool, _DependenceToken, @guaranteed Array<Klass>) -> @owned Klass |
| 350 | + %38 = builtin "sadd_with_overflow_Int64"(%34 : $Builtin.Int64, %30 : $Builtin.Int64, %31 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) |
| 351 | + %39 = tuple_extract %38 : $(Builtin.Int64, Builtin.Int1), 0 |
| 352 | + %40 = tuple_extract %38 : $(Builtin.Int64, Builtin.Int1), 1 |
| 353 | + cond_fail %40 : $Builtin.Int1, "arithmetic overflow" |
| 354 | + %43 = ref_element_addr %37 : $Klass, #Klass.val |
| 355 | + %44 = begin_access [read] [dynamic] [no_nested_conflict] %43 : $*Optional<Int> |
| 356 | + %45 = load %44 : $*Optional<Int> |
| 357 | + end_access %44 : $*Optional<Int> |
| 358 | + switch_enum %45 : $Optional<Int>, case #Optional.some!enumelt: bb9, case #Optional.none!enumelt: bb6 |
| 359 | + |
| 360 | +bb6: |
| 361 | + strong_release %37 : $Klass |
| 362 | + %49 = builtin "cmp_eq_Int64"(%39 : $Builtin.Int64, %18 : $Builtin.Int64) : $Builtin.Int1 |
| 363 | + cond_br %49, bb7, bb8 |
| 364 | + |
| 365 | +bb7: |
| 366 | + release_value %0 : $Optional<Array<Klass>> |
| 367 | + release_value %0 : $Optional<Array<Klass>> |
| 368 | + br bb12(%4 : $Builtin.Int64) |
| 369 | + |
| 370 | +bb8: |
| 371 | + br bb5(%39 : $Builtin.Int64) |
| 372 | + |
| 373 | +bb9: |
| 374 | + release_value %0 : $Optional<Array<Klass>> |
| 375 | + %57 = begin_access [read] [dynamic] [no_nested_conflict] %43 : $*Optional<Int> |
| 376 | + %58 = load %57 : $*Optional<Int> |
| 377 | + end_access %57 : $*Optional<Int> |
| 378 | + switch_enum %58 : $Optional<Int>, case #Optional.some!enumelt: bb11, case #Optional.none!enumelt: bb10 |
| 379 | + |
| 380 | +bb10: |
| 381 | + cond_fail %31 : $Builtin.Int1, "Unexpectedly found nil while unwrapping an Optional value" |
| 382 | + unreachable |
| 383 | + |
| 384 | +bb11(%63 : $Int): |
| 385 | + release_value %0 : $Optional<Array<Klass>> |
| 386 | + strong_release %37 : $Klass |
| 387 | + %66 = struct_extract %63 : $Int, #Int._value |
| 388 | + br bb12(%66 : $Builtin.Int64) |
| 389 | + |
| 390 | +bb12(%69 : $Builtin.Int64): |
| 391 | + %70 = struct $Int (%69 : $Builtin.Int64) |
| 392 | + return %70 : $Int |
| 393 | +} |
0 commit comments