Are the `memcpy`s still done with Rust 2018/2021 without using this crate?
jaques-sam opened this issue · 1 comments
jaques-sam commented
Are the `memcpy`s still done with Rust 2018/2021 without using this crate?
kvark commented
Not seeing the copy any more on Rust playground:
#[inline(never)]
fn foo() -> Box<Foo> {
Box::new(Foo::Small(4)) // this has 1 memcopy
//Box::alloc().init(Foo::Small(4)) // this has 0 memcopies
}
LLVM:
; playground::foo
; Function Attrs: noinline nounwind nonlazybind uwtable
define internal fastcc noalias nonnull align 4 %Foo* @_ZN10playground3foo17h5e126e6c87b576a8E() unnamed_addr #2 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
start:
%0 = tail call dereferenceable_or_null(404) i8* @__rust_alloc(i64 404, i64 4) #11, !noalias !7
%1 = icmp eq i8* %0, null
br i1 %1, label %bb3.i.i, label %"_ZN5alloc5boxed12Box$LT$T$GT$3new17hab47e76bc0e39a63E.exit"
bb3.i.i: ; preds = %start
; call alloc::alloc::handle_alloc_error
tail call void @_ZN5alloc5alloc18handle_alloc_error17h0ece3c434a8e0eb4E(i64 404, i64 4) #12, !noalias !7
unreachable
"_ZN5alloc5boxed12Box$LT$T$GT$3new17hab47e76bc0e39a63E.exit": ; preds = %start
%2 = bitcast i8* %0 to %Foo*
store i8 0, i8* %0, align 4
%_1.sroa.4.0..sroa_raw_idx = getelementptr inbounds i8, i8* %0, i64 1
store i8 4, i8* %_1.sroa.4.0..sroa_raw_idx, align 1
ret %Foo* %2
}
Asm:
playground::foo:
pushq %rax
movl $404, %edi
movl $4, %esi
callq *__rust_alloc@GOTPCREL(%rip)
testq %rax, %rax
je .LBB2_1
movw $1024, (%rax)
popq %rcx
retq
Added the "[deprecated]" to crate description now.