Open
Description
#![feature(box_syntax)]
use std::convert::TryInto;
const N: usize = 100_000;
pub fn foo1() -> Vec<u32> {
vec![0; N]
}
pub fn foo2() -> Box<[u32]> {
box [0; N]
}
pub fn foo3() -> Box<[u32; N]> {
box [0; N]
}
pub fn foo4() -> Box<[u32; N]> {
vec![0; N].into_boxed_slice().try_into().unwrap()
}
Gives (rustc 1.51.0-nightly 8018418 2021-01-03):
.LCPI0_0:
.quad 100000
.quad 100000
foo1:
push rbx
mov rbx, rdi
mov edi, 400000
mov esi, 4
call qword ptr [rip + __rust_alloc_zeroed@GOTPCREL]
test rax, rax
je .LBB0_1
mov qword ptr [rbx], rax
vmovaps xmm0, xmmword ptr [rip + .LCPI0_0]
vmovups xmmword ptr [rbx + 8], xmm0
mov rax, rbx
pop rbx
ret
.LBB0_1:
mov edi, 400000
mov esi, 4
call qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
ud2
foo2:
push rbx
mov edi, 400000
mov esi, 4
call qword ptr [rip + __rust_alloc@GOTPCREL]
test rax, rax
je .LBB1_1
mov rbx, rax
mov edx, 400000
mov rdi, rax
xor esi, esi
call qword ptr [rip + memset@GOTPCREL]
mov edx, 100000
mov rax, rbx
pop rbx
ret
.LBB1_1:
mov edi, 400000
mov esi, 4
call qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
ud2
foo3:
push rbx
mov edi, 400000
mov esi, 4
call qword ptr [rip + __rust_alloc@GOTPCREL]
test rax, rax
je .LBB2_1
mov rbx, rax
mov edx, 400000
mov rdi, rax
xor esi, esi
call qword ptr [rip + memset@GOTPCREL]
mov rax, rbx
pop rbx
ret
.LBB2_1:
mov edi, 400000
mov esi, 4
call qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
ud2
foo4:
push rax
mov edi, 400000
mov esi, 4
call qword ptr [rip + __rust_alloc_zeroed@GOTPCREL]
test rax, rax
je .LBB3_1
pop rcx
ret
.LBB3_1:
mov edi, 400000
mov esi, 4
call qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
ud2
I think box should use rust_alloc_zeroed instead.