Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/test/codegen/issue-75525-bounds-checks.rs
Original file line number Diff line number Diff line change
@@ -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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: This test case does not appear to have generated a bounds check before 12.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 }
}