Closed codertao closed 1 year ago
Slightly simpler code:
fn main() {
esp_idf_sys::link_patches();
let val = calculate_on(0.26);
if !val {
panic!("First interval isn't being calculated as on correctly");
}
for _ in 0..100 {
println!("Works :'(")
}
panic!("Hack for reasons");
}
fn calculate_on(mut time: f32) -> bool {
println!("Digit Start: {}", time);
time -= 0.25;
for i in 0..4 {
time -= if i > 0 { 0.4 } else { 0.2 };
if time <= 0.0 { return true }
}
false
}
Removing any one of if i > 0
(replace w/ const), for i in 0..4
, or the println!
; causes the test to pass; with all present it fails.
Please see https://github.com/esp-rs/rust/issues/180#issuecomment-1587144551 on how to "fix" this before it's fixed in llvm. This is the same issue as #180.
For context: I was doing simple math to calculate an LED pattern, and I was very consistently not seeing the results I expected when using opt levels z or s. Pared down the code in question to the below, and testing under z or s (with 1.66.0 nightly) I'm seeing a crash; under opt level zero I'm not seeing the crash.
I tried this code:
I expected to see this happen: Moderately-infinite loop
Instead, this happened: Crashes on the first loop, with:
So, it's hitting
which should take
time
below 0 regardless of *bit; but it's apparently not applying the operation- or something else is going wrong. While doing initial debugging I was also getting GuruError: (I think memory access exception), but I don't have logs for that anymore.Meta
rustc --version --verbose
:Switching away from f32 fixed the issue in this code, and I expect disabling hardware f32 would also resolve the problem (as mentioned in the FFT issue), but I suspect some of my apps are at the point where the performance overhead would be a problem.