Skip to content

Commit 715042f

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

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/codegen/maybeuninit-rvo.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: -O -Cpanic=abort
2+
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+
}

0 commit comments

Comments
 (0)