Skip to content

Commit

Permalink
Add test for #98294
Browse files Browse the repository at this point in the history
Add a test to make that the failure condition for this pattern is
optimized away.

Fixes #98294.
  • Loading branch information
nikic committed Sep 5, 2022
1 parent 406e03f commit cbf3b24
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/test/codegen/issue-98294-get-mut-copy-from-slice-opt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// min-llvm-version: 15.0.0
// ignore-debug: The debug assertions get in the way
// compile-flags: -O

#![crate_type = "lib"]

// There should be no calls to panic / len_mismatch_fail.

#[no_mangle]
pub fn test(a: &mut [u8], offset: usize, bytes: &[u8]) {
// CHECK-LABEL: @test(
// CHECK-NOT: call
// CHECK: call void @llvm.memcpy
// CHECK-NOT: call
// CHECK: }
if let Some(dst) = a.get_mut(offset..offset + bytes.len()) {
dst.copy_from_slice(bytes);
}
}

0 comments on commit cbf3b24

Please sign in to comment.