|
| 1 | +// RUN: %target-swift-frontend -enable-sil-ownership -Onone -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=NONE |
| 2 | +// RUN: %target-swift-frontend -enable-sil-ownership -Osize -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=OPT |
| 3 | +// RUN: %target-swift-frontend -enable-sil-ownership -O -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=OPT |
| 4 | +// RUN: %target-swift-frontend -enable-sil-ownership -Ounchecked -emit-sil -parse-as-library %s | %FileCheck %s --check-prefix=CHECK --check-prefix=UNCHECKED |
| 5 | + |
| 6 | +@inline(never) |
| 7 | +func takesInoutAndEscaping(_: inout Int, _ f: @escaping () -> ()) { |
| 8 | + f() |
| 9 | +} |
| 10 | + |
| 11 | +@inline(never) |
| 12 | +func escapeClosure(_ f: @escaping () -> ()) -> () -> () { |
| 13 | + return f |
| 14 | +} |
| 15 | + |
| 16 | +public func accessIntTwice() { |
| 17 | + var x = 0 |
| 18 | + takesInoutAndEscaping(&x, escapeClosure({ x = 3 })) |
| 19 | +} |
| 20 | + |
| 21 | +// accessIntTwice() |
| 22 | +// CHECK-LABEL: sil @$s26access_enforcement_options0A8IntTwiceyyF : $@convention(thin) () -> () { |
| 23 | +// CHECK: [[BOX:%.*]] = alloc_box ${ var Int }, var, name "x" |
| 24 | +// CHECK: [[PROJ:%.*]] = project_box [[BOX]] : ${ var Int }, 0 |
| 25 | +// NONE: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[PROJ]] : $*Int |
| 26 | +// OPT: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[PROJ]] : $*Int |
| 27 | +// UNCHECKED-NOT: = begin_access |
| 28 | +// CHECK-LABEL: } // end sil function '$s26access_enforcement_options0A8IntTwiceyyF' |
| 29 | + |
| 30 | +// closure #1 in accessIntTwice() |
| 31 | +// CHECK-LABEL: sil private @$s26access_enforcement_options0A8IntTwiceyyFyycfU_ : $@convention(thin) (@guaranteed { var Int }) -> () { |
| 32 | +// CHECK: bb0(%0 : ${ var Int }): |
| 33 | +// CHECK: [[PROJ:%.*]] = project_box %0 : ${ var Int }, 0 |
| 34 | +// NONE: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[PROJ]] : $*Int |
| 35 | +// OPT: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [no_nested_conflict] [[PROJ]] : $*Int |
| 36 | +// UNCHECKED-NOT: = begin_access |
| 37 | +// CHECK-LABEL: } // end sil function '$s26access_enforcement_options0A8IntTwiceyyFyycfU_' |
0 commit comments