diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2018-08-01 10:12:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-01 10:12:46 +0200 |
| commit | fe4358a34ffb6d8f1de5b7ffda7e4c104abee5c5 (patch) | |
| tree | a2ee9ddd0610916e77a48687b22e4fcb3e40645e /src/test/codegen | |
| parent | 61b9a516d3c0495596b21fae10eab0f82c4c7f7f (diff) | |
| parent | fb7d8a12db2a561c7dcc2534714243793446c7c4 (diff) | |
| download | rust-fe4358a34ffb6d8f1de5b7ffda7e4c104abee5c5.tar.gz rust-fe4358a34ffb6d8f1de5b7ffda7e4c104abee5c5.zip | |
Rollup merge of #52825 - RalfJung:codegen, r=alexcrichton
Make sure #47772 does not regress Mostly to make my life in https://github.com/rust-lang/rust/pull/52206 harder.^^ Or should I just add that test there?
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/slice-position-bounds-check.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/codegen/slice-position-bounds-check.rs b/src/test/codegen/slice-position-bounds-check.rs new file mode 100644 index 00000000000..a6c846d7dab --- /dev/null +++ b/src/test/codegen/slice-position-bounds-check.rs @@ -0,0 +1,42 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-system-llvm +// compile-flags: -O -C panic=abort +#![crate_type = "lib"] + +fn search<T: Ord + Eq>(arr: &mut [T], a: &T) -> Result<usize, ()> { + match arr.iter().position(|x| x == a) { + Some(p) => { + Ok(p) + }, + None => Err(()), + } +} + +// CHECK-LABEL: @position_no_bounds_check +#[no_mangle] +pub fn position_no_bounds_check(y: &mut [u32], x: &u32, z: &u32) -> bool { + // This contains "call assume" so we cannot just rule out all calls + // CHECK-NOT: panic_bounds_check + if let Ok(p) = search(y, x) { + y[p] == *z + } else { + false + } +} + +// just to make sure that panicking really emits "panic_bounds_check" somewhere in the IR +// CHECK-LABEL: @test_check +#[no_mangle] +pub fn test_check(y: &[i32]) -> i32 { + // CHECK: panic_bounds_check + y[12] +} |
