-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert! and assert_eq! generate different assembly #55914
Comments
These two things give different output. With
while
|
It's implemented like this: macro_rules! assert_eq {
($left:expr, $right:expr) => ({
match (&$left, &$right) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!(r#"assertion failed: `(left == right)`
left: `{:?}`,
right: `{:?}`"#, left_val, right_val)
}
}
}
}); Note how the In your case it's still using the original register for the actual comparison, |
As an update to this: 1.30.0: 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 1.36.0 example::foo2:
sub rsp, 104
mov dword ptr [rsp], edi
mov dword ptr [rsp + 4], esi
cmp edi, esi
jne .LBB9_1
mov al, 1
add rsp, 104
ret huge improvement. A few things could be done better, e.g. the Should we close this? |
What about a codegen regression test? |
On current stable (1.52) this looks promising, but still not from perfect:
example::foo1:
cmp edi, esi
jne .LBB3_1
mov al, 1
ret
.LBB3_1:
// panic
example::foo2:
sub rsp, 56
mov dword ptr [rsp], edi
mov dword ptr [rsp + 4], esi
cmp edi, esi
jne .LBB4_1
mov al, 1
add rsp, 56
ret
.LBB4_1:
// panic |
Concidering this simple code
The generate very different assembly
There is a difference regarding the parameter formatting in the "assert_false" branch
LBB7_1
andLBB8_1
, but what's even worse is, that the assert itself does differ and I don't see a reason why.The text was updated successfully, but these errors were encountered: