assert! and assert_eq! generate different assembly · Issue #55914 · rust-lang/rust (original) (raw)
Concidering this simple code
pub fn foo1(a: u32, b: u32) -> bool { assert!(a == b); true }
pub fn foo2(a: u32, b: u32) -> bool { assert_eq!(a, b); true }
The generate very different assembly
example::foo1: push rax cmp edi, esi jne .LBB7_1 mov al, 1 pop rcx ret .LBB7_1: // panicing
example::foo2: sub rsp, 104 mov dword ptr [rsp], edi mov dword ptr [rsp + 4], esi mov rax, rsp mov qword ptr [rsp + 8], rax lea rax, [rsp + 4] mov qword ptr [rsp + 16], rax cmp edi, esi jne .LBB8_1 mov al, 1 add rsp, 104 ret .LBB8_1: // panicing
There is a difference regarding the parameter formatting in the "assert_false" branch LBB7_1
and LBB8_1
, but what's even worse is, that the assert itself does differ and I don't see a reason why.