Closed
Description
This function
fn foo(v: &mut Vec<i32>) {
let len = v.len();
assert!(len > 1);
v[len - 2] += 1;
v.pop();
}
gives the following assembly
.section .text._ZN8rust_out3foo17h5b3f981e51393a1aE,"ax",@progbits
.p2align 4, 0x90
.type _ZN8rust_out3foo17h5b3f981e51393a1aE,@function
_ZN8rust_out3foo17h5b3f981e51393a1aE:
.cfi_startproc
pushq %rax
.Ltmp20:
.cfi_def_cfa_offset 16
movq 16(%rdi), %rax
cmpq $1, %rax
jbe .LBB6_4
movq (%rdi), %rcx
incl -8(%rcx,%rax,4)
movq 16(%rdi), %rax
testq %rax, %rax
je .LBB6_3
decq %rax
movq %rax, 16(%rdi)
.LBB6_3:
popq %rax
retq
.LBB6_4:
callq _ZN3std9panicking11begin_panic17hc03e2830c2c89a5fE
.Lfunc_end6:
.size _ZN8rust_out3foo17h5b3f981e51393a1aE, .Lfunc_end6-_ZN8rust_out3foo17h5b3f981e51393a1aE
.cfi_endproc
There is a conditional branch to .LBB6_4
if the length is < 2. There is no conditional branch created for v[len - 2]
, which is good, as the length is >= 2. However, there is a conditional branch to .LBB6_3
created for v.pop()
which can never be taken.