Skip to content

Commit 0c56ccf

Browse files
committed
Add codegen test for RVO on MaybeUninit
Currently, this only works with `-Cpanic=abort`.
1 parent 1a47f5b commit 0c56ccf

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)