about summary refs log tree commit diff
path: root/tests/codegen-llvm/integer-overflow.rs
blob: df7845be06d17b6e60a92e407027cd67f4b5ecc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//@ compile-flags: -Copt-level=3 -C overflow-checks=on

#![crate_type = "lib"]

pub struct S1<'a> {
    data: &'a [u8],
    position: usize,
}

// CHECK-LABEL: @slice_no_index_order
#[no_mangle]
pub fn slice_no_index_order<'a>(s: &'a mut S1, n: usize) -> &'a [u8] {
    // CHECK-COUNT-1: slice_index_fail
    let d = &s.data[s.position..s.position + n];
    s.position += n;
    return d;
}

// CHECK-LABEL: @test_check
#[no_mangle]
pub fn test_check<'a>(s: &'a mut S1, x: usize, y: usize) -> &'a [u8] {
    // CHECK-COUNT-1: slice_index_fail
    &s.data[x..y]
}