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
|
// RUN: %target-swift-emit-sil -sil-verify-all -module-name moveonly_lifetime -o /dev/null -Xllvm -sil-print-canonical-module -Onone -verify -enable-experimental-feature MoveOnlyClasses %s | %FileCheck %s
// REQUIRES: swift_feature_MoveOnlyClasses
struct C : ~Copyable {
deinit {}
}
@_silgen_name("getC")
func getC() -> C
@_silgen_name("takeC")
func takeC(_ c: __owned C)
@_silgen_name("borrowC")
func borrowC(_ c: borrowing C)
@_silgen_name("something")
func something()
// Verify that a move-only value's lifetime extends to the end of the
// non-consuming scope where it appears but not further (which would require a
// copy).
//
// NOTE: We do not properly maximize lifetimes yet in the address checker. So
// the lifetimes are shortened in the sides of the diamonds inappropriately.
//
// CHECK-LABEL: sil hidden [ossa] @test_diamond__consume_r__use_l : $@convention(thin) (Bool) -> () {
// CHECK: [[STACK:%.*]] = alloc_stack
// CHECK: cond_br {{%[^,]+}}, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
//
// CHECK: [[RIGHT]]:
// CHECK: [[INSTANCE:%.*]] = load [take] [[STACK]]
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: apply [[TAKE_C]]([[INSTANCE]])
// CHECK: br [[BOTTOM:bb[0-9]+]]
//
// CHECK: [[LEFT]]:
// CHECK: [[INSTANCE:%.*]] = load_borrow [[STACK]]
// CHECK: [[BORROW_C:%[^,]+]] = function_ref @borrowC
// CHECK: apply [[BORROW_C]]([[INSTANCE]])
// CHECK: [[SOMETHING:%[^,]+]] = function_ref @something
// CHECK: apply [[SOMETHING]]
// CHECK: destroy_addr [[STACK]]
// CHECK: br [[BOTTOM]]
// CHECK-LABEL: } // end sil function 'test_diamond__consume_r__use_l'
@_silgen_name("test_diamond__consume_r__use_l")
func test_diamond(_ condition: Bool) {
let c = getC()
if condition {
borrowC(c)
something()
} else {
takeC(c)
}
}
|