Description
In this code:
pub fn foo(g: fn()) {
let _var: Option<Box<i32>> = None;
g();
}
Assembly:
core::ptr::drop_in_place<core::option::Option<alloc::boxed::Box<i32>>>:
mov rdi, qword ptr [rdi]
test rdi, rdi
je .LBB0_1
mov esi, 4
mov edx, 4
jmp qword ptr [rip + __rust_dealloc@GOTPCREL]
.LBB0_1:
ret
example::foo:
push rbx
sub rsp, 16
mov qword ptr [rsp + 8], 0
call rdi
add rsp, 16
pop rbx
ret
mov rbx, rax
lea rdi, [rsp + 8]
call core::ptr::drop_in_place<core::option::Option<alloc::boxed::Box<i32>>>
mov rdi, rbx
call _Unwind_Resume@PLT
ud2
DW.ref.rust_eh_personality:
.quad rust_eh_personality
_var
is known to be None
so the deallocation is optimized away in the normal flow. But in landing pad for unwinding, it still generates a branch to check if _var
is null. But it's a local variable which is not able to be modified in anywhere else and should be known to be null.
I'm expecting the drop
of _var
should be completely elided so that g()
can be a tail call.