You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code generates an overflow check, when opt-level="z" and lto=true are set in the Cargo.toml. As the implementation of Iterator for Range states this check shouldn't actually be there: https://doc.rust-lang.org/src/core/iter/range.rs.html#215
My build target is x86_64-unknown-linux-gnu. I'm building with cargo build --release.
This is the code producing the bug:
fnmain(){let arr1 = [1,2,3];let arr2 = [4,5];println!("{} {}", add(&arr1), add(&arr2));}#[inline(never)]pubexternfnadd(numbers:&[i32]) -> i32{letmut result = 0;for i in0..numbers.len(){
result += numbers[i];}
result
}
Combined with this Cargo.toml:
[package]
name = "rust_binary"
version = "0.1.0"
[profile.release]
lto = true
opt-level = "z"
This is the resulting add function:
0000000000006a76 <rust_binary::add>: 6a76: xorecx,ecx 6a78: xoreax,eax 6a7a: jmp 6a8b <rust_binary::add+0x15> 6a7c: movrdx,rcx 6a7f: addrdx,0x1 6a83: jb 6a90 <rust_binary::add+0x1a> # This is the overflow check 6a85: addeax,DWORD PTR [rdi+rcx*4] 6a88: incrcx 6a8b: cmprcx,rsi 6a8e: jb 6a7c <rust_binary::add+0x6> 6a90: ret
The following code generates an overflow check, when
opt-level="z"
andlto=true
are set in theCargo.toml
. As the implementation ofIterator
forRange
states this check shouldn't actually be there: https://doc.rust-lang.org/src/core/iter/range.rs.html#215My build target is
x86_64-unknown-linux-gnu
. I'm building withcargo build --release
.This is the code producing the bug:
Combined with this
Cargo.toml
:This is the resulting
add
function:Meta
The text was updated successfully, but these errors were encountered: