|
| 1 | +// RUN: %target-sil-opt -definite-init %s | %FileCheck %s |
| 2 | + |
| 3 | +// Make sure that DI properly converts mark_must_check |
| 4 | +// [assignable_but_not_consumable] -> mark_must_check |
| 5 | +// [initable_but_not_consumable]. |
| 6 | + |
| 7 | +sil_stage raw |
| 8 | + |
| 9 | +fileprivate final class _Box<T> { |
| 10 | + var value: _Node<T> |
| 11 | + |
| 12 | + init(_ value: consuming _Node<T>) |
| 13 | +} |
| 14 | + |
| 15 | +struct _Node<T> : ~Copyable { |
| 16 | + var value: T |
| 17 | + var _next: ListEntry<T> |
| 18 | + |
| 19 | + init(_ newValue: T) |
| 20 | +} |
| 21 | + |
| 22 | +struct ListEntry<T> : ~Copyable { |
| 23 | + private var innerBox: _Box<T> |
| 24 | +} |
| 25 | + |
| 26 | +// CHECK-LABEL: sil private [ossa] @boxInit : $@convention(method) <T> (@in _Node<T>, @owned _Box<T>) -> @owned _Box<T> { |
| 27 | +// CHECK: bb0([[INPUT:%.*]] : $*_Node<T>, [[SELF:%.*]] : @owned |
| 28 | +// CHECK: [[BORROW_SELF:%.*]] = begin_borrow [[SELF]] |
| 29 | +// CHECK: [[REF:%.*]] = ref_element_addr [[BORROW_SELF]] |
| 30 | +// CHECK: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[REF]] |
| 31 | +// CHECK: [[MARK:%.*]] = mark_must_check [initable_but_not_consumable] [[ACCESS]] |
| 32 | +// CHECK: copy_addr [take] {{%.*}} to [init] [[MARK]] |
| 33 | +// CHECK: end_access [[ACCESS]] |
| 34 | +// CHECK: } // end sil function 'boxInit' |
| 35 | +sil private [ossa] @boxInit : $@convention(method) <T> (@in _Node<T>, @owned _Box<T>) -> @owned _Box<T> { |
| 36 | +bb0(%0 : $*_Node<T>, %1 : @owned $_Box<T>): |
| 37 | + %2 = alloc_stack [lexical] $_Node<T>, var, name "value" |
| 38 | + %3 = mark_must_check [consumable_and_assignable] %2 : $*_Node<T> |
| 39 | + copy_addr [take] %0 to [init] %3 : $*_Node<T> |
| 40 | + debug_value %1 : $_Box<T>, let, name "self", argno 2, implicit |
| 41 | + %6 = mark_uninitialized [rootself] %1 : $_Box<T> |
| 42 | + %7 = begin_borrow %6 : $_Box<T> |
| 43 | + %8 = begin_access [read] [static] %3 : $*_Node<T> |
| 44 | + %9 = alloc_stack $_Node<T> |
| 45 | + copy_addr %8 to [init] %9 : $*_Node<T> |
| 46 | + end_access %8 : $*_Node<T> |
| 47 | + %12 = ref_element_addr %7 : $_Box<T>, #_Box.value |
| 48 | + %13 = begin_access [modify] [dynamic] %12 : $*_Node<T> |
| 49 | + %14 = mark_must_check [assignable_but_not_consumable] %13 : $*_Node<T> |
| 50 | + copy_addr [take] %9 to %14 : $*_Node<T> |
| 51 | + end_access %13 : $*_Node<T> |
| 52 | + dealloc_stack %9 : $*_Node<T> |
| 53 | + end_borrow %7 : $_Box<T> |
| 54 | + %19 = copy_value %6 : $_Box<T> |
| 55 | + destroy_value %6 : $_Box<T> |
| 56 | + destroy_addr %3 : $*_Node<T> |
| 57 | + dealloc_stack %2 : $*_Node<T> |
| 58 | + return %19 : $_Box<T> |
| 59 | +} |
0 commit comments