Closed
Description
Consider this code
use std::time::Instant;
fn collatz(i: usize) -> bool {
if i == 1 {
true
} else if i % 2 == 0 {
collatz(i / 2)
} else {
collatz(3 * i + 1)
}
}
fn main() {
static TIMES: usize = 500000;
let start = Instant::now();
for i in 0..TIMES {
if ! collatz(i) {
println!("{}", i);
return;
}
}
println!("Done, {} millis elapsed!", start.elapsed().as_millis());
}
It contains infinite recursion (collatz(0)
), but the whole loop gets optimized away with Nightly + Release.
Related: #28728 (Perhaps also related to this commit).
Not sure if this is an LLVM bug?