-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Machineary behind an unreachable panic!
ends-up in final optimized binary
#121879
Comments
Probably a LLVM thing? cc @nikic |
Doesn't reproduce on play.rust-lang.org (release, 1.78.0-nightly) with main function added. alloc::raw_vec::RawVec<T,A>::reserve::do_reserve_and_handle:
# ...
.LBB6_8:
callq *alloc::raw_vec::capacity_overflow@GOTPCREL(%rip)
.LBB6_6:
movq 24(%rsp), %rsi
callq *alloc::alloc::handle_alloc_error@GOTPCREL(%rip)
# -- End function
playground::foo: # @playground::foo
# %bb.0:
pushq %rbx
movq (%rdi), %rax
movq 16(%rdi), %rsi
subq %rsi, %rax
cmpq $1, %rax
jbe .LBB7_1
.LBB7_2:
movq 8(%rdi), %rax
movw $256, (%rax,%rsi) # imm = 0x100
addq $2, %rsi
movq %rsi, 16(%rdi)
popq %rbx
retq
.LBB7_1:
movq %rdi, %rbx
callq alloc::raw_vec::RawVec<T,A>::reserve::do_reserve_and_handle
movq %rbx, %rdi
movq 16(%rbx), %rsi
jmp .LBB7_2
# -- End function
playground::main: # @playground::main
# ... |
@rustbot +requires-nightly |
I only see a single call to |
Oh... That makes sense... I guess a local literal Still not sure why |
OK, thanks @bjorn3 and @ProgramCrafter |
Well, unless I don't know how to read assembly...
https://godbolt.org/z/4ca98x5s6
In
foo
, theassert_unchecked
hint correctly tells thatpush
shouldn't invoke_unreachable
but the formatting machinery behindpanic!
still ends-up in the final optimized binary. The removal ofcold
orinline(never)
does not alter this behaviour but regardless, the compiler should infer that no-one is using such thing.On the other side, ad-hoc
panic!
in thepush
function correctly erases everything.The text was updated successfully, but these errors were encountered: