Skip to content

Commit 404173d

Browse files
committed
[NFC] Add MutableSpan bounds check test
1 parent 1dc03fe commit 404173d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-swift-frontend -O -emit-sil %s -disable-availability-checking | %FileCheck %s --check-prefix=CHECK-SIL
2+
3+
public protocol P {
4+
mutating func mutate(_ other: Self)
5+
}
6+
7+
// CHECK-SIL-LABEL: sil @$s38mutable_span_stdlib_bounds_check_tests0a1_B7_doubleyys11MutableSpanVyxGzAA1PRzlF :
8+
// CHECK-SIL: bb3({{.*}}):
9+
// CHECK-SIL-NOT: end_cow_mutation
10+
// CHECK-SIL-NOT: cond_fail "index out of bounds"
11+
// CHECK-SIL-LABEL: } // end sil function '$s38mutable_span_stdlib_bounds_check_tests0a1_B7_doubleyys11MutableSpanVyxGzAA1PRzlF'
12+
public func mutable_span_double<T: P>(_ ms: inout MutableSpan<T>) {
13+
for i in ms.indices {
14+
ms[i].mutate(ms[i])
15+
}
16+
}
17+
18+
extension Int : P {
19+
public mutating func mutate(_ other: Int) {
20+
self += other
21+
}
22+
}
23+
24+
// CHECK-SIL-LABEL: sil @$s38mutable_span_stdlib_bounds_check_tests17specializedCalleryySaySiGzF : $@convention(thin) (@inout Array<Int>) -> () {
25+
// CHECK-SIL-NOT: cond_fail "index out of bounds"
26+
// CHECK-SIL-LABEL: } // end sil function '$s38mutable_span_stdlib_bounds_check_tests17specializedCalleryySaySiGzF'
27+
public func specializedCaller(_ array: inout Array<Int>) {
28+
var mut = array.mutableSpan
29+
mutable_span_double(&mut)
30+
}
31+

0 commit comments

Comments
 (0)