|
| 1 | +// RUN: %target-sil-opt -unit-test-runner %s -o /dev/null 2>&1 | %FileCheck %s |
| 2 | + |
| 3 | +import Builtin |
| 4 | + |
| 5 | +typealias AnyObject = Builtin.AnyObject |
| 6 | + |
| 7 | +struct Unmanaged<Instance> where Instance : AnyObject { |
| 8 | + unowned(unsafe) var _value: @sil_unmanaged Instance |
| 9 | +} |
| 10 | + |
| 11 | +// CHECK-LABEL: begin {{.*}} on copy_and_move_argument: canonicalize-borrow-scope |
| 12 | +// CHECK-LABEL: sil [ossa] @copy_and_move_argument : {{.*}} { |
| 13 | +// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : |
| 14 | +// CHECK: [[UNMANAGED:%[^,]+]] = ref_to_unmanaged [[INSTANCE]] |
| 15 | +// CHECK: [[RETVAL:%[^,]+]] = struct $Unmanaged<Instance> ([[UNMANAGED]] : $@sil_unmanaged Instance) |
| 16 | +// CHECK: return [[RETVAL]] |
| 17 | +// CHECK-LABEL: } // end sil function 'copy_and_move_argument' |
| 18 | +// CHECK-LABEL: end {{.*}} on copy_and_move_argument: canonicalize-borrow-scope |
| 19 | +sil [ossa] @copy_and_move_argument : $@convention(thin) <Instance where Instance : AnyObject> (@guaranteed Instance) -> Unmanaged<Instance> { |
| 20 | +bb0(%instance : @guaranteed $Instance): |
| 21 | + test_specification "canonicalize-borrow-scope @argument" |
| 22 | + %copy_1 = copy_value %instance : $Instance |
| 23 | + %copy_2 = copy_value %copy_1 : $Instance |
| 24 | + %move = move_value %copy_2 : $Instance |
| 25 | + %copy_3 = copy_value %move : $Instance |
| 26 | + %copy_4 = copy_value %copy_3 : $Instance |
| 27 | + %unmanaged = ref_to_unmanaged %copy_4 : $Instance to $@sil_unmanaged Instance |
| 28 | + destroy_value %copy_4 : $Instance |
| 29 | + destroy_value %copy_3 : $Instance |
| 30 | + destroy_value %move : $Instance |
| 31 | + destroy_value %copy_1 : $Instance |
| 32 | + %retval = struct $Unmanaged<Instance> (%unmanaged : $@sil_unmanaged Instance) |
| 33 | + return %retval : $Unmanaged<Instance> |
| 34 | +} |
| 35 | + |
| 36 | +// CHECK-LABEL: begin {{.*}} on copy_and_move_lexical_argument: canonicalize-borrow-scope |
| 37 | +// CHECK-LABEL: sil [ossa] @copy_and_move_lexical_argument : {{.*}} { |
| 38 | +// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : |
| 39 | +// CHECK: [[UNMANAGED:%[^,]+]] = ref_to_unmanaged [[INSTANCE]] |
| 40 | +// CHECK: [[RETVAL:%[^,]+]] = struct $Unmanaged<Instance> ([[UNMANAGED]] : $@sil_unmanaged Instance) |
| 41 | +// CHECK: return [[RETVAL]] |
| 42 | +// CHECK-LABEL: } // end sil function 'copy_and_move_lexical_argument' |
| 43 | +// CHECK-LABEL: end {{.*}} on copy_and_move_lexical_argument: canonicalize-borrow-scope |
| 44 | +sil [ossa] @copy_and_move_lexical_argument : $@convention(thin) <Instance where Instance : AnyObject> (@guaranteed Instance) -> Unmanaged<Instance> { |
| 45 | +bb0(%instance : @guaranteed $Instance): |
| 46 | + test_specification "canonicalize-borrow-scope @argument" |
| 47 | + %copy_1 = copy_value %instance : $Instance |
| 48 | + %copy_2 = copy_value %copy_1 : $Instance |
| 49 | + %move = move_value [lexical] %copy_2 : $Instance |
| 50 | + %copy_3 = copy_value %move : $Instance |
| 51 | + %copy_4 = copy_value %copy_3 : $Instance |
| 52 | + %unmanaged = ref_to_unmanaged %copy_4 : $Instance to $@sil_unmanaged Instance |
| 53 | + destroy_value %copy_4 : $Instance |
| 54 | + destroy_value %copy_3 : $Instance |
| 55 | + destroy_value %move : $Instance |
| 56 | + destroy_value %copy_1 : $Instance |
| 57 | + %retval = struct $Unmanaged<Instance> (%unmanaged : $@sil_unmanaged Instance) |
| 58 | + return %retval : $Unmanaged<Instance> |
| 59 | +} |
0 commit comments