Closed
Description
This is a reopening of #37114 which was fixed in 1.28.0 but seems to have regressed again since 1.30.0.
pub fn foo(v: &mut Vec<i32>) {
let len = v.len();
assert!(len > 1);
v[len - 2] += 1;
v.pop();
}
The asm for 1.38 is
example::foo:
push rax
mov rax, qword ptr [rdi + 16]
cmp rax, 2
jb .LBB7_4
mov rcx, qword ptr [rdi]
add dword ptr [rcx + 4*rax - 8], 1
; 1.28 does not generate these 3 instructions:
mov rax, qword ptr [rdi + 16]
test rax, rax
je .LBB7_3
; end of unnecessary code
add rax, -1
mov qword ptr [rdi + 16], rax
.LBB7_3:
pop rax
ret
.LBB7_4:
call std::panicking::begin_panic
ud2