Skip to content

Commit 8ecc3e3

Browse files
committed
[Exclusivity] access enforcement SIL tests.
1 parent 45967ce commit 8ecc3e3

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// RUN: %target-sil-opt -access-enforcement-selection -enforce-exclusivity=checked %s | %FileCheck %s
2+
3+
import Builtin
4+
import Swift
5+
6+
sil_stage raw
7+
8+
// Test undef begin_access operands.
9+
// CHECK-LABEL: sil hidden @undefStack : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
10+
// CHECK: bb0(%0 : $Builtin.Int64):
11+
// CHECK: unreachable
12+
// CHECK: bb1:
13+
// CHECK: [[WRITE:%.*]] = begin_access [modify] [static] undef : $*Builtin.Int64
14+
// CHECK: store %{{.*}} to [trivial] [[WRITE]] : $*Builtin.Int64
15+
// CHECK: end_access [[WRITE]] : $*Builtin.Int64
16+
// CHECK: br
17+
// CHECK: bb2:
18+
// CHECK: [[READ:%.*]] = begin_access [read] [static] undef : $*Builtin.Int64
19+
// CHECK: %{{.*}} = load [trivial] [[READ]] : $*Builtin.Int64
20+
// CHECK: end_access [[READ]] : $*Builtin.Int64
21+
// CHECK-LABEL: } // end sil function 'undefStack'
22+
sil hidden @undefStack : $@convention(thin) (Builtin.Int64) -> Builtin.Int64 {
23+
bb0(%0 : $Builtin.Int64):
24+
unreachable
25+
26+
bb1:
27+
%23 = integer_literal $Builtin.Int64, 42
28+
%25 = begin_access [modify] [unknown] undef : $*Builtin.Int64
29+
store %23 to [trivial] %25 : $*Builtin.Int64
30+
end_access %25 : $*Builtin.Int64
31+
br bb2
32+
33+
bb2:
34+
%29 = begin_access [read] [unknown] undef : $*Builtin.Int64
35+
%30 = load [trivial] %29 : $*Builtin.Int64
36+
end_access %29 : $*Builtin.Int64
37+
dealloc_stack undef : $*Builtin.Int64
38+
return %30 : $Builtin.Int64
39+
}
40+
41+
// Test static enforcement selection in the presence of mark_function_escape.
42+
// This really isn't really a special case, but depends on pass pipeline.
43+
//
44+
// CHECK-LABEL: sil hidden @markFuncEscape : $@convention(thin) () -> () {
45+
// CHECK: bb0:
46+
// CHECK: [[BOX:%.*]] = alloc_box ${ var Builtin.Int64 }, var, name "x"
47+
// CHECK: [[ADR:%.*]] = project_box [[BOX]] : ${ var Builtin.Int64 }, 0
48+
// CHECK: mark_function_escape [[ADR]] : $*Builtin.Int64
49+
// CHECK: [[READ:%.*]] = begin_access [read] [static] [[ADR]] : $*Builtin.Int64
50+
// CHECK: %{{.*}} = load [trivial] [[READ]] : $*Builtin.Int64
51+
// CHECK: end_access [[READ]] : $*Builtin.Int64
52+
// CHECK: destroy_value [[BOX]] : ${ var Builtin.Int64 }
53+
// CHECK: return %{{.*}} : $()
54+
// CHECK-LABEL:} // end sil function 'markFuncEscape'
55+
sil hidden @markFuncEscape : $@convention(thin) () -> () {
56+
%2 = alloc_box ${ var Builtin.Int64 }, var, name "x"
57+
%3 = project_box %2 : ${ var Builtin.Int64 }, 0
58+
mark_function_escape %3 : $*Builtin.Int64
59+
%39 = begin_access [read] [unknown] %3 : $*Builtin.Int64
60+
%40 = load [trivial] %39 : $*Builtin.Int64
61+
end_access %39 : $*Builtin.Int64
62+
destroy_value %2 : ${ var Builtin.Int64 }
63+
%98 = tuple ()
64+
%99 = return %98 : $()
65+
}
66+
67+
// Test static enforcement of copied boxes.
68+
// FIXME: Oops... We make this dynamic.
69+
//
70+
// CHECK-LABEL: sil hidden @copyBox : $@convention(thin) () -> () {
71+
// CHECK: bb0:
72+
// CHECK: [[BOX:%.*]] = alloc_box ${ var Builtin.Int64 }, var, name "x"
73+
// CHECK: [[ADR1:%.*]] = project_box [[BOX]] : ${ var Builtin.Int64 }, 0
74+
// CHECK: [[CPY:%.*]] = copy_value [[BOX]] : ${ var Builtin.Int64 }
75+
// CHECK: [[ADR2:%.*]] = project_box [[CPY]] : ${ var Builtin.Int64 }, 0
76+
// CHECK: [[READ:%.*]] = begin_access [read] [dynamic] [[ADR2]] : $*Builtin.Int64
77+
// CHECK: %{{.*}} = load [trivial] [[READ]] : $*Builtin.Int64
78+
// CHECK: end_access [[READ]] : $*Builtin.Int64
79+
// CHECK: [[READ:%.*]] = begin_access [read] [dynamic] [[ADR1]] : $*Builtin.Int64
80+
// CHECK: %{{.*}} = load [trivial] [[READ]] : $*Builtin.Int64
81+
// CHECK: end_access [[READ]] : $*Builtin.Int64
82+
// CHECK: destroy_value [[CPY]] : ${ var Builtin.Int64 }
83+
// CHECK: destroy_value [[BOX]] : ${ var Builtin.Int64 }
84+
// CHECK: return %{{.*}} : $()
85+
// CHECK-LABEL: } // end sil function 'copyBox'
86+
sil hidden @copyBox : $@convention(thin) () -> () {
87+
%2 = alloc_box ${ var Builtin.Int64 }, var, name "x"
88+
%3 = project_box %2 : ${ var Builtin.Int64 }, 0
89+
%16 = copy_value %2 : ${ var Builtin.Int64 }
90+
%17 = project_box %16 : ${ var Builtin.Int64 }, 0
91+
%18 = begin_access [read] [unknown] %17 : $*Builtin.Int64
92+
%19 = load [trivial] %18 : $*Builtin.Int64
93+
end_access %18 : $*Builtin.Int64
94+
%39 = begin_access [read] [unknown] %3 : $*Builtin.Int64
95+
%40 = load [trivial] %39 : $*Builtin.Int64
96+
end_access %39 : $*Builtin.Int64
97+
destroy_value %16 : ${ var Builtin.Int64 }
98+
destroy_value %2 : ${ var Builtin.Int64 }
99+
%98 = tuple ()
100+
%99 = return %98 : $()
101+
}

0 commit comments

Comments
 (0)