Skip to content

Commit 05229f7

Browse files
authored
Rollup merge of #72547 - alex:patch-1, r=oli-obk
Added a codegen test for a recent optimization for overflow-checks=on Closes #58692
2 parents d19b51e + cd5f228 commit 05229f7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/test/codegen/integer-overflow.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// no-system-llvm
2+
// compile-flags: -O -C overflow-checks=on
3+
4+
#![crate_type = "lib"]
5+
6+
7+
pub struct S1<'a> {
8+
data: &'a [u8],
9+
position: usize,
10+
}
11+
12+
// CHECK-LABEL: @slice_no_index_order
13+
#[no_mangle]
14+
pub fn slice_no_index_order<'a>(s: &'a mut S1, n: usize) -> &'a [u8] {
15+
// CHECK-NOT: slice_index_order_fail
16+
let d = &s.data[s.position..s.position+n];
17+
s.position += n;
18+
return d;
19+
}
20+
21+
// CHECK-LABEL: @test_check
22+
#[no_mangle]
23+
pub fn test_check<'a>(s: &'a mut S1, x: usize, y: usize) -> &'a [u8] {
24+
// CHECK: slice_index_order_fail
25+
&s.data[x..y]
26+
}

0 commit comments

Comments
 (0)