Skip to content

Commit b8376fd

Browse files
committed
Add some read only tests for MutableSpan
1 parent 40a2ecb commit b8376fd

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/SILOptimizer/mutable_span_bounds_check_tests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,54 @@
77

88
// REQUIRES: swift_stdlib_no_asserts, optimized_stdlib
99

10+
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0a1_B11_sum_w_trapySis11MutableSpanVySiGF :
11+
// CHECK-SIL: bb3({{.*}}):
12+
// CHECK-SIL-NOT: cond_fail {{.*}}, "index out of bounds"
13+
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0a1_B11_sum_w_trapySis11MutableSpanVySiGF'
14+
public func mutable_span_sum_w_trap(_ ms: borrowing MutableSpan<Int>) -> Int {
15+
var sum = 0
16+
for i in ms.indices {
17+
sum += ms[i]
18+
}
19+
return sum
20+
}
21+
22+
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0a1_B12_sum_wo_trapySis11MutableSpanVySiGF :
23+
// CHECK-SIL: bb3({{.*}}):
24+
// CHECK-SIL-NOT: cond_fail {{.*}}, "index out of bounds"
25+
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0a1_B12_sum_wo_trapySis11MutableSpanVySiGF'
26+
public func mutable_span_sum_wo_trap(_ ms: borrowing MutableSpan<Int>) -> Int {
27+
var sum = 0
28+
for i in ms.indices {
29+
sum &+= ms[i]
30+
}
31+
return sum
32+
}
33+
34+
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0a1_B25_sum_w_trap_unknown_boundySis11MutableSpanVySiG_SitF :
35+
// CHECK-SIL: bb3({{.*}}):
36+
// CHECK-SIL-NOT: cond_fail {{.*}}, "index out of bounds"
37+
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0a1_B25_sum_w_trap_unknown_boundySis11MutableSpanVySiG_SitF'
38+
public func mutable_span_sum_w_trap_unknown_bound(_ ms: borrowing MutableSpan<Int>, _ n: Int) -> Int {
39+
var sum = 0
40+
for i in 0...n {
41+
sum += ms[i]
42+
}
43+
return sum
44+
}
45+
46+
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0a1_B26_sum_wo_trap_unknown_boundySis11MutableSpanVySiG_SitF :
47+
// CHECK-SIL: bb3({{.*}}):
48+
// CHECK-SIL-NOT: cond_fail {{.*}}, "index out of bounds"
49+
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0a1_B26_sum_wo_trap_unknown_boundySis11MutableSpanVySiG_SitF'
50+
public func mutable_span_sum_wo_trap_unknown_bound(_ ms: borrowing MutableSpan<Int>, _ n: Int) -> Int {
51+
var sum = 0
52+
for i in 0...n {
53+
sum &+= ms[i]
54+
}
55+
return sum
56+
}
57+
1058
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B10_zero_inityys11MutableSpanVySiGzF :
1159
// CHECK-SIL: bb3({{.*}}):
1260
// CHECK-SIL: cond_fail {{.*}}, "index out of bounds"

0 commit comments

Comments
 (0)