|
| 1 | +// RUN: %target-swift-frontend -parse-as-library -Xllvm -sil-full-demangle -enforce-exclusivity=checked -emit-sil %s | %FileCheck %s |
| 2 | + |
| 3 | +public struct S { |
| 4 | + var i: Int |
| 5 | + var o: AnyObject |
| 6 | +} |
| 7 | + |
| 8 | +// CHECK-LABEL: sil [noinline] @_T023access_marker_mandatory5initSAA1SVSi_s9AnyObject_ptF : $@convention(thin) (Int, @owned AnyObject) -> @owned S { |
| 9 | +// CHECK: bb0(%0 : $Int, %1 : $AnyObject): |
| 10 | +// CHECK: %[[STK:.*]] = alloc_stack $S, var, name "s" |
| 11 | +// CHECK: cond_br %{{.*}}, bb1, bb2 |
| 12 | +// CHECK: bb1: |
| 13 | +// CHECK-NOT: begin_access |
| 14 | +// CHECK: store %{{.*}} to %[[STK]] : $*S |
| 15 | +// CHECK-NOT: end_access |
| 16 | +// CHECK: bb2: |
| 17 | +// CHECK-NOT: begin_access |
| 18 | +// CHECK: store %{{.*}} to %[[STK]] : $*S |
| 19 | +// CHECK-NOT: end_access |
| 20 | +// CHECK: bb3: |
| 21 | +// CHECK-NOT: begin_access |
| 22 | +// CHECK: %[[RET:.*]] = load %[[STK]] : $*S |
| 23 | +// CHECK-NOT: end_access |
| 24 | +// CHECK: destroy_addr %[[STK]] |
| 25 | +// CHECK: dealloc_stack %[[STK]] |
| 26 | +// CHECK: return %[[RET]] : $S |
| 27 | +// CHECK-LABEL: } // end sil function '_T023access_marker_mandatory5initSAA1SVSi_s9AnyObject_ptF' |
| 28 | +@inline(never) |
| 29 | +public func initS(_ x: Int, _ o: AnyObject) -> S { |
| 30 | + var s: S |
| 31 | + if x == 0 { |
| 32 | + s = S(i: 1, o: o) |
| 33 | + } else { |
| 34 | + s = S(i: x, o: o) |
| 35 | + } |
| 36 | + return s |
| 37 | +} |
| 38 | + |
| 39 | +@inline(never) |
| 40 | +func takeS(_ s: S) {} |
| 41 | + |
| 42 | +// CHECK-LABEL: sil @_T023access_marker_mandatory14modifyAndReadSys9AnyObject_p1o_tF : $@convention(thin) (@owned AnyObject) -> () { |
| 43 | +// CHECK: bb0(%0 : $AnyObject): |
| 44 | +// CHECK: %[[STK:.*]] = alloc_stack $S, var, name "s" |
| 45 | +// CHECK: %[[FINIT:.*]] = function_ref @_T023access_marker_mandatory5initSAA1SVSi_s9AnyObject_ptF : $@convention(thin) (Int, @owned AnyObject) -> @owned S |
| 46 | +// CHECK: %[[INITS:.*]] = apply %[[FINIT]](%{{.*}}, %0) : $@convention(thin) (Int, @owned AnyObject) -> @owned S |
| 47 | +// CHECK-NOT: begin_access |
| 48 | +// CHECK: store %[[INITS]] to %[[STK]] : $*S |
| 49 | +// CHECK-NOT: end_access |
| 50 | +// CHECK-NOT: begin_access |
| 51 | +// CHECK: %[[ADDRI:.*]] = struct_element_addr %[[STK]] : $*S, #S.i |
| 52 | +// CHECK: store %{{.*}} to %[[ADDRI]] : $*Int |
| 53 | +// CHECK-NOT: end_access |
| 54 | +// CHECK-NOT: begin_access |
| 55 | +// CHECK: %[[FTAKE:.*]] = function_ref @_T023access_marker_mandatory5takeSyAA1SVF : $@convention(thin) (@owned S) -> () |
| 56 | +// CHECK: apply %[[FTAKE]](%{{.*}}) : $@convention(thin) (@owned S) -> () |
| 57 | +// CHECK-LABEL: } // end sil function '_T023access_marker_mandatory14modifyAndReadSys9AnyObject_p1o_tF' |
| 58 | +public func modifyAndReadS(o: AnyObject) { |
| 59 | + var s = initS(3, o) |
| 60 | + s.i = 42 |
| 61 | + takeS(s) |
| 62 | +} |
0 commit comments