-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
Description
See the following extreme test-case:
#[repr(align(1024))]
pub struct Foo(usize);
pub fn foo() -> Box<Foo> {
Box::new(Foo(42))
}
This is what godbolt says rust stable does with it with -O:
push rbx
sub rsp, 1024
mov edi, 1024
mov esi, 1024
call __rust_alloc@PLT
test rax, rax
je .LBB0_1
mov rbx, rax
mov qword ptr [rax], 42
mov rdi, rax
add rdi, 8
lea rsi, [rsp + 8]
mov edx, 1016
call memcpy@PLT
mov rax, rbx
add rsp, 1024
pop rbx
ret
.LBB0_1:
mov edi, 1024
mov esi, 1024
call alloc::alloc::handle_alloc_error@PLT
That is, it allocates 1024 bytes (expected), writes 42
directly at the allocated location, and then proceeds to copy 1016 (uninitialized) bytes from the stack.
hanna-kruppe
Metadata
Metadata
Assignees
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.