From a1d014bdbc0159c6ed60e29dc0c3ef3110ff9776 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 6 Aug 2021 20:33:02 +0300 Subject: Avoid using the `copy_nonoverlapping` wrapper through `mem::replace`. --- src/test/codegen/mem-replace-direct-memcpy.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/codegen/mem-replace-direct-memcpy.rs (limited to 'src/test/codegen') diff --git a/src/test/codegen/mem-replace-direct-memcpy.rs b/src/test/codegen/mem-replace-direct-memcpy.rs new file mode 100644 index 00000000000..47f4fc27fd8 --- /dev/null +++ b/src/test/codegen/mem-replace-direct-memcpy.rs @@ -0,0 +1,25 @@ +// This test ensures that `mem::replace::` only ever calls `@llvm.memcpy` +// with `size_of::()` as the size, and never goes through any wrapper that +// may e.g. multiply `size_of::()` with a variable "count" (which is only +// known to be `1` after inlining). + +// compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] + +pub fn replace_byte(dst: &mut u8, src: u8) -> u8 { + std::mem::replace(dst, src) +} + +// NOTE(eddyb) the `CHECK-NOT`s ensure that the only calls of `@llvm.memcpy` in +// the entire output, are the two direct calls we want, from `ptr::{read,write}`. + +// CHECK-NOT: call void @llvm.memcpy +// CHECK: ; core::ptr::read +// CHECK-NOT: call void @llvm.memcpy +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{.*}}(i8* align 1 %{{.*}}, i8* align 1 %src, i{{.*}} 1, i1 false) +// CHECK-NOT: call void @llvm.memcpy +// CHECK: ; core::ptr::write +// CHECK-NOT: call void @llvm.memcpy +// CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{.*}}(i8* align 1 %dst, i8* align 1 %src, i{{.*}} 1, i1 false) +// CHECK-NOT: call void @llvm.memcpy -- cgit 1.4.1-3-g733a5