|
| 1 | +// This test ensures that `mem::replace::<T>` only ever calls `@llvm.memcpy` |
| 2 | +// with `size_of::<T>()` as the size, and never goes through any wrapper that |
| 3 | +// may e.g. multiply `size_of::<T>()` with a variable "count" (which is only |
| 4 | +// known to be `1` after inlining). |
| 5 | + |
| 6 | +// compile-flags: -C no-prepopulate-passes -Zinline-mir=no |
| 7 | +// ignore-debug: the debug assertions get in the way |
| 8 | + |
| 9 | +#![crate_type = "lib"] |
| 10 | + |
| 11 | +#[repr(C, align(8))] |
| 12 | +pub struct Big([u64; 7]); |
| 13 | +pub fn replace_big(dst: &mut Big, src: Big) -> Big { |
| 14 | + // Before the `read_via_copy` intrinsic, this emitted six `memcpy`s. |
| 15 | + std::mem::replace(dst, src) |
| 16 | +} |
| 17 | + |
| 18 | +// NOTE(eddyb) the `CHECK-NOT`s ensure that the only calls of `@llvm.memcpy` in |
| 19 | +// the entire output, are the direct calls we want, from `ptr::replace`. |
| 20 | + |
| 21 | +// CHECK-NOT: call void @llvm.memcpy |
| 22 | + |
| 23 | +// For a large type, we expect exactly three `memcpy`s |
| 24 | +// CHECK-LABEL: define internal void @{{.+}}mem{{.+}}replace{{.+}}sret(%Big) |
| 25 | + // CHECK-NOT: alloca |
| 26 | + // CHECK: alloca %Big |
| 27 | + // CHECK-NOT: alloca |
| 28 | + // CHECK-NOT: call void @llvm.memcpy |
| 29 | + // CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false) |
| 30 | + // CHECK-NOT: call void @llvm.memcpy |
| 31 | + // CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false) |
| 32 | + // CHECK-NOT: call void @llvm.memcpy |
| 33 | + // CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %{{.*}}, {{i8\*|ptr}} align 8 %{{.*}}, i{{.*}} 56, i1 false) |
| 34 | + // CHECK-NOT: call void @llvm.memcpy |
| 35 | + |
| 36 | +// CHECK-NOT: call void @llvm.memcpy |
0 commit comments