Add test for #98294

Add a test to make that the failure condition for this pattern is
optimized away.

Fixes #98294.
This commit is contained in:
Nikita Popov 2022-08-31 13:18:46 +02:00
parent 406e03fd02
commit cbf3b2432e

View File

@ -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);
}
}