-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Value differs between debug and release: 1.0 / ((-0.0) * black_box_zero) #102402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here's another program with similar behavior, failing only in release. Not sure if it's the same issue. fn main() {
let black_box_one = (std::env::args().len()) as f32;
let result = - (black_box_one / 0.0);
let expected = f32::NEG_INFINITY;
assert_eq!(result, expected);
} |
This function, based on the first code example, is misoptimized to unconditionally return false (godbolt): pub fn foo(n: usize) -> bool {
let black_box_zero = (n - 1) as f32;
let result = 1.0 / ((-0.0) * black_box_zero);
result == std::f32::NEG_INFINITY
} This was not misoptimized before rustc 1.25, which upgraded LLVM to version 6.0. This appears to be a misoptimization by LLVM (Unless there's some allowed variability to do with the signs of zeroes that I'm not aware of?) @rustbot label A-LLVM A-floating-point I-unsound T-compiler regression-from-stable-to-stable |
This C code miscompiled under Clang as well: https://godbolt.org/z/bfqoGePW1. Confirmed to be a LLVM bug. |
The second example does actually appear to be different - it doesn't miscompile until rustc 1.30 (godbolt) (which upgraded to LLVM 8). |
Upstream issue: llvm/llvm-project#58046 |
possibly related: #55131 |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-high |
T-compiler P-high review (also, @Mark-Simulacrum notes that since upstream llvm/llvm-project#58046 is fixed now, this issue should eventually get resolved by either an LLVM upgrade or by cherry-picking the fix to Rust's LLVM fork.) |
Does that fix take care of the second example? |
Update LLVM submodule This merges in the current upstream release/15.x branch. Fixes rust-lang#102402.
Should we add a test for this? |
This code has differing behavior in debug and release (playground):
When compiled in debug mode (without optimizations), the program produces no output.
When compiled in release mode (with optimizations), the assertion fails:
(This output doesn't make sense to me: how can they be unequal, but both negative infinity?)
The text was updated successfully, but these errors were encountered: