|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -predictable-deadalloc-elim | %FileCheck %s |
| 2 | + |
| 3 | +sil_stage canonical |
| 4 | + |
| 5 | +import Swift |
| 6 | +import Builtin |
| 7 | + |
| 8 | +// CHECK-LABEL: sil @simple_trivial_stack : $@convention(thin) (Builtin.Int32) -> () { |
| 9 | +// CHECK-NOT: alloc_stack |
| 10 | +// CHECK: } // end sil function 'simple_trivial_stack' |
| 11 | +sil @simple_trivial_stack : $@convention(thin) (Builtin.Int32) -> () { |
| 12 | +bb0(%0 : $Builtin.Int32): |
| 13 | + %1 = alloc_stack $Builtin.Int32 |
| 14 | + store %0 to %1 : $*Builtin.Int32 |
| 15 | + dealloc_stack %1 : $*Builtin.Int32 |
| 16 | + %9999 = tuple() |
| 17 | + return %9999 : $() |
| 18 | +} |
| 19 | + |
| 20 | +// CHECK-LABEL: sil @simple_trivial_init_box : $@convention(thin) (Builtin.Int32) -> () { |
| 21 | +// CHECK-NOT: alloc_box |
| 22 | +// CHECK: } // end sil function 'simple_trivial_init_box' |
| 23 | +sil @simple_trivial_init_box : $@convention(thin) (Builtin.Int32) -> () { |
| 24 | +bb0(%0 : $Builtin.Int32): |
| 25 | + %1 = alloc_box ${ var Builtin.Int32 } |
| 26 | + %2 = project_box %1 : ${ var Builtin.Int32 }, 0 |
| 27 | + store %0 to %2 : $*Builtin.Int32 |
| 28 | + strong_release %1 : ${ var Builtin.Int32 } |
| 29 | + %9999 = tuple() |
| 30 | + return %9999 : $() |
| 31 | +} |
| 32 | + |
| 33 | +// CHECK-LABEL: sil @simple_trivial_uninit_box : $@convention(thin) (Builtin.Int32) -> () { |
| 34 | +// CHECK-NOT: alloc_box |
| 35 | +// CHECK: } // end sil function 'simple_trivial_uninit_box' |
| 36 | +sil @simple_trivial_uninit_box : $@convention(thin) (Builtin.Int32) -> () { |
| 37 | +bb0(%0 : $Builtin.Int32): |
| 38 | + %1 = alloc_box ${ var Builtin.Int32 } |
| 39 | + %2 = project_box %1 : ${ var Builtin.Int32 }, 0 |
| 40 | + store %0 to %2 : $*Builtin.Int32 |
| 41 | + dealloc_box %1 : ${ var Builtin.Int32 } |
| 42 | + %9999 = tuple() |
| 43 | + return %9999 : $() |
| 44 | +} |
| 45 | + |
| 46 | +// CHECK-LABEL: sil @simple_nontrivial_stack : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 47 | +// CHECK: bb0([[ARG:%.*]] : |
| 48 | +// CHECK-NEXT: strong_release [[ARG]] |
| 49 | +// CHECK-NEXT: tuple |
| 50 | +// CHECK-NEXT: return |
| 51 | +// CHECK: } // end sil function 'simple_nontrivial_stack' |
| 52 | +sil @simple_nontrivial_stack : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 53 | +bb0(%0 : $Builtin.NativeObject): |
| 54 | + %1 = alloc_stack $Builtin.NativeObject |
| 55 | + store %0 to %1 : $*Builtin.NativeObject |
| 56 | + destroy_addr %1 : $*Builtin.NativeObject |
| 57 | + dealloc_stack %1 : $*Builtin.NativeObject |
| 58 | + %9999 = tuple() |
| 59 | + return %9999 : $() |
| 60 | +} |
| 61 | + |
| 62 | +// We do not handle this today, since we do not understand that we need to treat |
| 63 | +// the strong_release of the alloc_box as a destroy_addr of the entire value. |
| 64 | +// |
| 65 | +// FIXME: We should be able to handle this. |
| 66 | +// |
| 67 | +// CHECK-LABEL: sil @simple_nontrivial_init_box : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 68 | +// CHECK: alloc_box |
| 69 | +// CHECK: } // end sil function 'simple_nontrivial_init_box' |
| 70 | +sil @simple_nontrivial_init_box : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 71 | +bb0(%0 : $Builtin.NativeObject): |
| 72 | + %1 = alloc_box ${ var Builtin.NativeObject } |
| 73 | + %2 = project_box %1 : ${ var Builtin.NativeObject }, 0 |
| 74 | + store %0 to %2 : $*Builtin.NativeObject |
| 75 | + strong_release %1 : ${ var Builtin.NativeObject } |
| 76 | + %9999 = tuple() |
| 77 | + return %9999 : $() |
| 78 | +} |
| 79 | + |
| 80 | +// CHECK-LABEL: sil @simple_nontrivial_uninit_box : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 81 | +// CHECK: bb0([[ARG:%.*]] : |
| 82 | +// CHECK-NEXT: strong_release [[ARG]] |
| 83 | +// CHECK-NEXT: tuple |
| 84 | +// CHECK-NEXT: return |
| 85 | +// CHECK: } // end sil function 'simple_nontrivial_uninit_box' |
| 86 | +sil @simple_nontrivial_uninit_box : $@convention(thin) (@owned Builtin.NativeObject) -> () { |
| 87 | +bb0(%0 : $Builtin.NativeObject): |
| 88 | + %1 = alloc_box ${ var Builtin.NativeObject } |
| 89 | + %2 = project_box %1 : ${ var Builtin.NativeObject }, 0 |
| 90 | + store %0 to %2 : $*Builtin.NativeObject |
| 91 | + destroy_addr %2 : $*Builtin.NativeObject |
| 92 | + dealloc_box %1 : ${ var Builtin.NativeObject } |
| 93 | + %9999 = tuple() |
| 94 | + return %9999 : $() |
| 95 | +} |
0 commit comments