Skip to content

Commit 265c1b5

Browse files
committed
add regression test for not memcpying padding bytes
1 parent 9530589 commit 265c1b5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/codegen/box-maybe-uninit.rs tests/codegen/box-uninit-bytes.rs

+14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
2525
Box::new(MaybeUninit::uninit())
2626
}
2727

28+
#[repr(align(1024))]
29+
pub struct LotsaPadding(usize);
30+
31+
// Boxing a value with padding should not copy junk from the stack
32+
#[no_mangle]
33+
pub fn box_lotsa_padding() -> Box<LotsaPadding> {
34+
// CHECK-LABEL: @box_lotsa_padding
35+
// CHECK-NOT: alloca
36+
// CHECK-NOT: getelementptr
37+
// CHECK-NOT: memcpy
38+
// CHECK-NOT: memset
39+
Box::new(LotsaPadding(42))
40+
}
41+
2842
// Hide the `allocalign` attribute in the declaration of __rust_alloc
2943
// from the CHECK-NOT above, and also verify the attributes got set reasonably.
3044
// 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]+]]

0 commit comments

Comments
 (0)