|
| 1 | +// RUN: %target-swift-frontend -c -disable-availability-checking -Xllvm --sil-print-final-ossa-module -O -module-name=main -o /dev/null %s 2>&1 | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: concurrency |
| 4 | + |
| 5 | +// CHECK-LABEL: sil [ossa] @async_dead_arg_call : {{.*}} { |
| 6 | +// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @_eagerMove @owned |
| 7 | +// CHECK: destroy_value [[INSTANCE]] |
| 8 | +// CHECK: [[EXECUTOR:%[^,]+]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt |
| 9 | +// CHECK: [[CALLEE:%[^,]+]] = function_ref @async_callee |
| 10 | +// CHECK: apply [[CALLEE]]() |
| 11 | +// CHECK: hop_to_executor [[EXECUTOR]] |
| 12 | +// CHECK-LABEL: } // end sil function 'async_dead_arg_call' |
| 13 | +@_silgen_name("async_dead_arg_call") |
| 14 | +public func async_dead_arg_call(o: consuming AnyObject) async { |
| 15 | + // o should be destroyed here |
| 16 | + await bar() |
| 17 | +} |
| 18 | + |
| 19 | +// CHECK-LABEL: sil [ossa] @async_dead_arg_call_lexical : {{.*}} { |
| 20 | +// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @_lexical @owned |
| 21 | +// CHECK: [[MOVE:%[^,]+]] = move_value [lexical] [[INSTANCE]] |
| 22 | +// CHECK: [[EXECUTOR:%[^,]+]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt |
| 23 | +// CHECK: [[CALLEE:%[^,]+]] = function_ref @async_callee |
| 24 | +// CHECK: apply [[CALLEE]]() |
| 25 | +// CHECK: hop_to_executor [[EXECUTOR]] |
| 26 | +// CHECK: destroy_value [[MOVE]] |
| 27 | +// CHECK-LABEL: } // end sil function 'async_dead_arg_call_lexical' |
| 28 | +@_silgen_name("async_dead_arg_call_lexical") |
| 29 | +public func async_dead_arg_call_lexical(@_noEagerMove o: consuming AnyObject) async { |
| 30 | + await bar() |
| 31 | + // o should be destroyed here |
| 32 | +} |
| 33 | + |
| 34 | +extension C { |
| 35 | + // CHECK-LABEL: sil [ossa] @async_dead_arg_call_lexical_method : {{.*}} { |
| 36 | + // CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @_lexical @owned |
| 37 | + // CHECK-LABEL: } // end sil function 'async_dead_arg_call_lexical_method' |
| 38 | + @_silgen_name("async_dead_arg_call_lexical_method") |
| 39 | + @_noEagerMove |
| 40 | + consuming |
| 41 | + public func async_dead_arg_call_lexical_method() async { |
| 42 | + await bar() |
| 43 | + // self should be destroyed here |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +public class C { |
| 48 | + // CHECK-LABEL: sil [ossa] @async_dead_arg_call_method : {{.*}} { |
| 49 | + // CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : @_eagerMove @owned |
| 50 | + // CHECK: destroy_value [[INSTANCE]] |
| 51 | + // CHECK: [[EXECUTOR:%[^,]+]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt |
| 52 | + // CHECK: [[CALLEE:%[^,]+]] = function_ref @async_callee : $@convention(thin) @async () -> () |
| 53 | + // CHECK: apply [[CALLEE]]() : $@convention(thin) @async () -> () |
| 54 | + // CHECK: hop_to_executor [[EXECUTOR]] |
| 55 | + // CHECK-LABEL: } // end sil function 'async_dead_arg_call_method' |
| 56 | + @_silgen_name("async_dead_arg_call_method") |
| 57 | + consuming |
| 58 | + public func async_dead_arg_call() async { |
| 59 | + // self should be destroyed here |
| 60 | + await bar() |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +@inline(never) |
| 65 | +@_silgen_name("async_callee") |
| 66 | +func bar() async {} |
| 67 | + |
| 68 | +// CHECK-LABEL: sil [ossa] @write_to_pointer : {{.*}} { |
| 69 | +// CHECK: {{bb[0-9]+}}([[CONSUMED_INSTANCE:%[^,]+]] : @_eagerMove @owned $AnyObject, [[UMP:%[^,]+]] : |
| 70 | +// CHECK: [[PTR:%[^,]+]] = struct_extract [[UMP]] |
| 71 | +// CHECK: [[ADDR:%[^,]+]] = pointer_to_address [[PTR]] |
| 72 | +// CHECK: store [[CONSUMED_INSTANCE]] to [assign] [[ADDR]] |
| 73 | +// CHECK: [[PTR2:%[^,]+]] = struct_extract [[UMP]] |
| 74 | +// CHECK: [[ADDR2:%[^,]+]] = pointer_to_address [[PTR2]] |
| 75 | +// CHECK: [[OUT:%[^,]+]] = load [copy] [[ADDR2]] |
| 76 | +// CHECK: return [[OUT]] |
| 77 | +// CHECK-LABEL: } // end sil function 'write_to_pointer' |
| 78 | +@_silgen_name("write_to_pointer") |
| 79 | +public func write_to_pointer(o: consuming AnyObject, p: UnsafeMutablePointer<AnyObject>) -> AnyObject { |
| 80 | + // o should be destroyed here |
| 81 | + p.pointee = o |
| 82 | + return p.pointee |
| 83 | +} |
| 84 | + |
| 85 | +extension C { |
| 86 | + // CHECK-LABEL: sil [ossa] @write_to_pointer_method : {{.*}} { |
| 87 | + // CHECK: {{bb[0-9]+}}([[UMP:%[^,]+]] : $UnsafeMutablePointer<C>, [[INSTANCE:%[^,]+]] : @_eagerMove @owned |
| 88 | + // CHECK: [[PTR:%[^,]+]] = struct_extract [[UMP]] |
| 89 | + // CHECK: [[ADDR:%[^,]+]] = pointer_to_address [[PTR]] |
| 90 | + // CHECK: store [[INSTANCE]] to [assign] [[ADDR]] |
| 91 | + // CHECK: [[ADDR2:%[^,]+]] = struct_extract [[UMP]] |
| 92 | + // CHECK: [[PTR2:%[^,]+]] = pointer_to_address [[ADDR2]] |
| 93 | + // CHECK: [[OUT:%[^,]+]] = load [copy] [[PTR2]] |
| 94 | + // CHECK: return [[OUT]] |
| 95 | + // CHECK-LABEL: } // end sil function 'write_to_pointer_method' |
| 96 | + @_silgen_name("write_to_pointer_method") |
| 97 | + consuming |
| 98 | + public func write_to_pointer(p: UnsafeMutablePointer<C>) -> C { |
| 99 | + // o should be destroyed here |
| 100 | + p.pointee = self |
| 101 | + return p.pointee |
| 102 | + } |
| 103 | +} |
0 commit comments