From 10a4c67a613d84e80cba5fd52442d5cc30970cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 5 Mar 2021 16:01:46 +0100 Subject: [PATCH] Add regression test for #75525 --- src/test/codegen/issue-75525-bounds-checks.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/codegen/issue-75525-bounds-checks.rs diff --git a/src/test/codegen/issue-75525-bounds-checks.rs b/src/test/codegen/issue-75525-bounds-checks.rs new file mode 100644 index 0000000000000..a03c63c1d0948 --- /dev/null +++ b/src/test/codegen/issue-75525-bounds-checks.rs @@ -0,0 +1,27 @@ +// Regression test for #75525, verifies that no bounds checks are generated. + +// min-llvm-version: 12.0.0 +// compile-flags: -O + +#![crate_type = "lib"] + +// CHECK-LABEL: @f0 +// CHECK-NOT: panic +#[no_mangle] +pub fn f0(idx: usize, buf: &[u8; 10]) -> u8 { + if idx < 8 { buf[idx + 1] } else { 0 } +} + +// CHECK-LABEL: @f1 +// CHECK-NOT: panic +#[no_mangle] +pub fn f1(idx: usize, buf: &[u8; 10]) -> u8 { + if idx > 5 && idx < 8 { buf[idx - 1] } else { 0 } +} + +// CHECK-LABEL: @f2 +// CHECK-NOT: panic +#[no_mangle] +pub fn f2(idx: usize, buf: &[u8; 10]) -> u8 { + if idx > 5 && idx < 8 { buf[idx] } else { 0 } +}