Skip to content

Commit 856cd66

Browse files
Test that NRVO elides the call to memcpy
1 parent 1deaaa6 commit 856cd66

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/codegen/nrvo.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -O
2+
3+
#![crate_type = "lib"]
4+
5+
// Ensure that we do not call `memcpy` for the following function.
6+
// `memset` and `init` should be called directly on the return pointer.
7+
#[no_mangle]
8+
pub fn nrvo(init: fn(&mut [u8; 4096])) -> [u8; 4096] {
9+
// CHECK-LABEL: nrvo
10+
// CHECK: @llvm.memset
11+
// CHECK-NOT: @llvm.memcpy
12+
// CHECK: ret
13+
// CHECK-EMPTY
14+
let mut buf = [0; 4096];
15+
init(&mut buf);
16+
buf
17+
}

0 commit comments

Comments
 (0)