Skip to content

Commit c505d76

Browse files
authored
Rollup merge of rust-lang#119555 - Kobzol:maybeuninit-rvo-codegen-test, r=nikic
Add codegen test for RVO on MaybeUninit Codegen test for rust-lang#90595. Currently, this only works with `-Cpanic=abort`, but hopefully in the [future](https://www.npopov.com/2024/01/01/This-year-in-LLVM-2023.html#writable-and-dead_on_unwind) it should also work in the presence of panics. r? ``@nikic``
2 parents f4335a4 + 0c56ccf commit c505d76

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/codegen/maybeuninit-rvo.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// compile-flags: -O
2+
#![feature(c_unwind)]
3+
#![crate_type = "lib"]
4+
5+
pub struct Foo([u8; 1000]);
6+
7+
extern "C" {
8+
fn init(p: *mut Foo);
9+
}
10+
11+
pub fn new_from_uninit() -> Foo {
12+
// CHECK-LABEL: new_from_uninit
13+
// CHECK-NOT: call void @llvm.memcpy.
14+
let mut x = std::mem::MaybeUninit::uninit();
15+
unsafe {
16+
init(x.as_mut_ptr());
17+
x.assume_init()
18+
}
19+
}
20+
21+
extern "C-unwind" {
22+
fn init_unwind(p: *mut Foo);
23+
}
24+
25+
pub fn new_from_uninit_unwind() -> Foo {
26+
// CHECK-LABEL: new_from_uninit
27+
// CHECK: call void @llvm.memcpy.
28+
let mut x = std::mem::MaybeUninit::uninit();
29+
unsafe {
30+
init_unwind(x.as_mut_ptr());
31+
x.assume_init()
32+
}
33+
}

0 commit comments

Comments
 (0)