Skip to content

Commit f812a3f

Browse files
authored
Rollup merge of rust-lang#115096 - kadiwa4:no_memcpy_padding, r=cjgillot
Add regression test for not `memcpy`ing padding bytes Closes rust-lang#56297 See this comparison: https://rust.godbolt.org/z/jjzfonfcE I don't have any experience with codegen tests, I hope this is correct
2 parents fa38ec0 + 265c1b5 commit f812a3f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/codegen/box-maybe-uninit.rs renamed to 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)