From 265c1b5d5025a1cb3bdc26b99f35317079a55c36 Mon Sep 17 00:00:00 2001 From: kadiwa Date: Tue, 22 Aug 2023 14:43:53 +0200 Subject: [PATCH] add regression test for not memcpying padding bytes --- .../{box-maybe-uninit.rs => box-uninit-bytes.rs} | 14 ++++++++++++++ 1 file changed, 14 insertions(+) rename tests/codegen/{box-maybe-uninit.rs => box-uninit-bytes.rs} (76%) diff --git a/tests/codegen/box-maybe-uninit.rs b/tests/codegen/box-uninit-bytes.rs similarity index 76% rename from tests/codegen/box-maybe-uninit.rs rename to tests/codegen/box-uninit-bytes.rs index 282af99b06736..732da0a179494 100644 --- a/tests/codegen/box-maybe-uninit.rs +++ b/tests/codegen/box-uninit-bytes.rs @@ -25,6 +25,20 @@ pub fn box_uninitialized2() -> Box> { Box::new(MaybeUninit::uninit()) } +#[repr(align(1024))] +pub struct LotsaPadding(usize); + +// Boxing a value with padding should not copy junk from the stack +#[no_mangle] +pub fn box_lotsa_padding() -> Box { + // CHECK-LABEL: @box_lotsa_padding + // CHECK-NOT: alloca + // CHECK-NOT: getelementptr + // CHECK-NOT: memcpy + // CHECK-NOT: memset + Box::new(LotsaPadding(42)) +} + // Hide the `allocalign` attribute in the declaration of __rust_alloc // from the CHECK-NOT above, and also verify the attributes got set reasonably. // CHECK: declare {{(dso_local )?}}noalias noundef ptr @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+}} allocalign noundef) unnamed_addr [[RUST_ALLOC_ATTRS:#[0-9]+]]