-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Sign of zero from differs between CTFE and normal execution (float % float) #102403
Sign of zero from differs between CTFE and normal execution (float % float) #102403
Comments
Reminds me of #55131, though this one's probably less ugly since signs of zeros are less FUBAR than signs of NANs. |
Probably another apfloat bug, either in the LLVM original or in the transpilation? |
To look at LLVM, just feed it through constant folding: https://godbolt.org/z/oWqrhKe4h So it looks like current LLVM APFloat results in negative sign. So this looks like it might be another bug like #100233 (comment) :/ EDIT: you don't need to run any code to see the bug in action, you can trigger it with MIR inlining: https://godbolt.org/z/nYxchqv9P Current output (just the relevant parts): fn f_one() -> f64 {
let mut _0: f64;
bb0: {
_0 = const 0f64;
return;
}
}
fn minus_zero() -> f64 {
let mut _0: f64;
bb0: {
_0 = const -0f64;
return;
}
} |
So... basically const prop is unsound around floats? |
The example is a CTFE bug, not a ConstProp bug. |
Using the reproducer from #109567
Yes. ConstProp disagrees with LLVM: https://godbolt.org/z/5dPrfqMYq (once again wishing we could either pin to a nightly in godbolt or otherwise set mir-opt flags in a stable compiler, because this link will eventually not reproduce if we fix this) pub fn make_me_a_float() -> f64 {
-1.0 % -1.0
} With fn make_me_a_float() -> f64 {
let mut _0: f64; // return place in scope 0 at /app/example.rs:1:29: 1:32
bb0: {
_0 = const 0f64; // scope 0 at /app/example.rs:2:5: 2:16
return; // scope 0 at /app/example.rs:3:2: 3:2
}
} But with define double @_ZN7example15make_me_a_float17h53a3e1048ece245eE() unnamed_addr #0 !dbg !6 {
ret double -0.000000e+00, !dbg !11
} |
#109567 has some other examples reproducing this. |
While trying to make progress on #113409 I noticed this was showing up as "C++ But, this is not a porting bug, it's a LLVM one, fixed very soon after my port: llvm/llvm-project@f2c2851 My best guess is that LLVM was unaffected by its own bug because the host C EDIT: for the record, I would not have figured this out as easily if not for my WIP fuzzing system: |
I posted a longer update to #55993 (comment) regarding the progress with the whole |
Accidentally closed (overzealous GitHub), my bad. |
With this code:
The assertion fails: compile-time evaluation gives 0.0 while runtime evaluation gives -0.0.
This is probably relevant to tracking issue #57241.
The text was updated successfully, but these errors were encountered: