Closed
Description
pub fn f(l: &Vec<u64>) -> u64 {
let mut sum = 0;
for i in 0..l.len() {
sum += l[i]
}
sum
}
Compiles with -C opt-level=3 -C panic=abort to:
example::f:
mov rdx, qword ptr [rdi + 16]
test rdx, rdx
je .LBB0_1
mov rcx, qword ptr [rdi]
xor eax, eax
xor esi, esi
.LBB0_4:
cmp rdx, rsi
jbe .LBB0_5
add rax, qword ptr [rcx + 8*rsi]
inc rsi
cmp rsi, rdx
jb .LBB0_4
jmp .LBB0_2
.LBB0_1:
xor eax, eax
.LBB0_2:
ret
.LBB0_5:
push rbp
mov rbp, rsp
lea rdi, [rip + panic_bounds_check_loc.1]
call core::panicking::panic_bounds_check@PLT
ud2
It should be possible for the bounds check to be dropped.