|
| 1 | +// RUN: %target-sil-opt \ |
| 2 | +// RUN: -test-runner \ |
| 3 | +// RUN: -module-name Swift \ |
| 4 | +// RUN: %s \ |
| 5 | +// RUN: -o /dev/null \ |
| 6 | +// RUN: 2>&1 | %FileCheck %s |
| 7 | + |
| 8 | +import Builtin |
| 9 | + |
| 10 | +@_marker protocol Copyable {} |
| 11 | + |
| 12 | +class C {} |
| 13 | +struct NC : ~Copyable { |
| 14 | + var c: C |
| 15 | +} |
| 16 | + |
| 17 | +// CHECK-LABEL: begin running test {{.*}} on consume_move_only |
| 18 | +// CHECK-LABEL: sil [ossa] @consume_move_only : {{.*}} { |
| 19 | +// CHECK: bb0([[C:%[^,]+]] : |
| 20 | +// Necessary copy. |
| 21 | +// CHECK: [[COPY:%[^,]+]] = copy_value [[C]] |
| 22 | +// CHECK: [[NC:%[^,]+]] = struct $NC ([[COPY]] |
| 23 | +// CHECK: apply undef([[NC]]) |
| 24 | +// CHECK-LABEL: } // end sil function 'consume_move_only' |
| 25 | +// CHECK-LABEL: end running test {{.*}} on consume_move_only |
| 26 | +sil [ossa] @consume_move_only : $@convention(thin) (@guaranteed C) -> () { |
| 27 | +bb0(%c : @guaranteed $C): |
| 28 | + specify_test "canonicalize_function_argument @argument" |
| 29 | + %copy = copy_value %c |
| 30 | + %nc = struct $NC (%copy) |
| 31 | + apply undef(%nc) : $@convention(thin) (@owned NC) -> () |
| 32 | + %retval = tuple () |
| 33 | + return %retval |
| 34 | +} |
| 35 | + |
| 36 | +// CHECK-LABEL: begin running test {{.*}} on borrow_move_only |
| 37 | +// CHECK-LABEL: sil [ossa] @borrow_move_only : {{.*}} { |
| 38 | +// CHECK: bb0([[C:%[^,]+]] : |
| 39 | +// No copy! |
| 40 | +// CHECK: [[NC:%[^,]+]] = struct $NC ([[C]] |
| 41 | +// CHECK: apply undef([[NC]]) |
| 42 | +// CHECK-LABEL: } // end sil function 'borrow_move_only' |
| 43 | +// CHECK-LABEL: end running test {{.*}} on borrow_move_only |
| 44 | +sil [ossa] @borrow_move_only : $@convention(thin) (@guaranteed C) -> () { |
| 45 | +bb0(%c : @guaranteed $C): |
| 46 | + specify_test "canonicalize_function_argument @argument" |
| 47 | + %copy = copy_value %c |
| 48 | + %nc = struct $NC (%copy) |
| 49 | + apply undef(%nc) : $@convention(thin) (@guaranteed NC) -> () |
| 50 | + destroy_value %nc |
| 51 | + %retval = tuple () |
| 52 | + return %retval |
| 53 | +} |
| 54 | + |
| 55 | +// CHECK-LABEL: begin running test {{.*}} on consume_and_borrow_move_only |
| 56 | +// CHECK-LABEL: sil [ossa] @consume_and_borrow_move_only : {{.*}} { |
| 57 | +// CHECK: bb0([[C:%[^,]+]] : |
| 58 | +// No copy! |
| 59 | +// CHECK: [[NC1:%[^,]+]] = struct $NC ([[C]] |
| 60 | +// CHECK: apply undef([[NC1]]) |
| 61 | +// Necessary copy. |
| 62 | +// CHECK: [[COPY2:%[^,]+]] = copy_value [[C]] |
| 63 | +// CHECK: [[NC2:%[^,]+]] = struct $NC ([[COPY2]] |
| 64 | +// CHECK: apply undef([[NC2]]) |
| 65 | +// CHECK-LABEL: } // end sil function 'consume_and_borrow_move_only' |
| 66 | +// CHECK-LABEL: end running test {{.*}} on consume_and_borrow_move_only |
| 67 | +sil [ossa] @consume_and_borrow_move_only : $@convention(thin) (@guaranteed C) -> () { |
| 68 | +bb0(%c : @guaranteed $C): |
| 69 | + specify_test "canonicalize_function_argument @argument" |
| 70 | + %copy1 = copy_value %c |
| 71 | + %nc1 = struct $NC (%copy1) |
| 72 | + apply undef(%nc1) : $@convention(thin) (@guaranteed NC) -> () |
| 73 | + destroy_value %nc1 |
| 74 | + %copy2 = copy_value %c |
| 75 | + %nc2 = struct $NC (%copy2) |
| 76 | + apply undef(%nc2) : $@convention(thin) (@owned NC) -> () |
| 77 | + %retval = tuple () |
| 78 | + return %retval |
| 79 | +} |
0 commit comments