]> git.lizzy.rs Git - rust.git/blob - tests/codegen/box-maybe-uninit.rs
Rollup merge of #107769 - compiler-errors:pointer-like, r=eholk
[rust.git] / tests / codegen / box-maybe-uninit.rs
1 // compile-flags: -O
2 // min-llvm-version: 15.0
3 #![crate_type = "lib"]
4
5 use std::mem::MaybeUninit;
6
7 // Boxing a `MaybeUninit` value should not copy junk from the stack
8 #[no_mangle]
9 pub fn box_uninitialized() -> Box<MaybeUninit<usize>> {
10     // CHECK-LABEL: @box_uninitialized
11     // CHECK-NOT: store
12     // CHECK-NOT: alloca
13     // CHECK-NOT: memcpy
14     // CHECK-NOT: memset
15     Box::new(MaybeUninit::uninit())
16 }
17
18 // https://github.com/rust-lang/rust/issues/58201
19 #[no_mangle]
20 pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
21     // CHECK-LABEL: @box_uninitialized2
22     // CHECK-NOT: store
23     // CHECK-NOT: alloca
24     // CHECK-NOT: memcpy
25     // CHECK-NOT: memset
26     Box::new(MaybeUninit::uninit())
27 }
28
29 // Hide the `allocalign` attribute in the declaration of __rust_alloc
30 // from the CHECK-NOT above, and also verify the attributes got set reasonably.
31 // CHECK: declare noalias noundef ptr @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+}} allocalign noundef) unnamed_addr [[RUST_ALLOC_ATTRS:#[0-9]+]]
32
33 // CHECK-DAG: attributes [[RUST_ALLOC_ATTRS]] = { {{.*}} allockind("alloc,uninitialized,aligned") allocsize(0) uwtable "alloc-family"="__rust_alloc" {{.*}} }