Skip to content

Commit ba23be5

Browse files
committed
Test access markers during mandatory passes.
1 parent 4355cad commit ba23be5

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %target-sil-opt -enforce-exclusivity=checked -emit-sorted-sil -access-marker-elim %s | %FileCheck %s
2+
3+
sil_stage raw
4+
5+
import Builtin
6+
import Swift
7+
import SwiftShims
8+
9+
public struct S {
10+
@sil_stored var i: Builtin.Int64 { get set }
11+
init(i: Int)
12+
}
13+
14+
// CHECK-LABEL: sil hidden [noinline] @initS : $@convention(thin) () -> @owned S {
15+
// CHECK: bb0:
16+
// CHECK: %[[BOX:.*]] = alloc_box ${ var S }, var, name "s"
17+
// CHECK: %[[ADDRS:.*]] = project_box %[[BOX]] : ${ var S }, 0
18+
// CHECK: %[[NUM:.*]] = integer_literal $Builtin.Int64, 1
19+
// CHECK-NOT: begin_access
20+
// CHECK: %[[ADDRI:.*]] = struct_element_addr %[[ADDRS]] : $*S, #S.i
21+
// CHECK: assign %[[NUM]] to %[[ADDRI]] : $*Builtin.Int64
22+
// CHECK-NOT: end_access
23+
// CHECK-NOT: begin_access
24+
// CHECK: %[[VALS:.*]] = load [trivial] %[[ADDRS]] : $*S
25+
// CHECK-NOT: end_access
26+
// CHECK: destroy_value %[[BOX]] : ${ var S }
27+
// CHECK: return %[[VALS]] : $S
28+
// CHECK-LABEL: } // end sil function 'initS'
29+
sil hidden [noinline] @initS : $@convention(thin) () -> @owned S {
30+
bb0:
31+
%0 = alloc_box ${ var S }, var, name "s"
32+
%1 = project_box %0 : ${ var S }, 0
33+
%2 = integer_literal $Builtin.Int64, 1
34+
%3 = begin_access [modify] [unknown] %1 : $*S
35+
%4 = struct_element_addr %3 : $*S, #S.i
36+
assign %2 to %4 : $*Builtin.Int64
37+
end_access %3 : $*S
38+
%7 = begin_access [read] [unknown] %1 : $*S
39+
%8 = load [trivial] %7 : $*S
40+
end_access %7 : $*S
41+
destroy_value %0 : ${ var S }
42+
return %8 : $S
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)