-
Notifications
You must be signed in to change notification settings - Fork 13k
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
fesetround() when called from Rust on Linux doesn't work correctly, but does on Windows, gcc, and clang. #118102
Comments
What's the behaviour if you compile a pure C program? |
I included the output of clang and gcc in my README |
I just noticed that without the --release flag, the Linux build produces the correct result. |
On Linux, with --release, objdump -d shows this code for the test function:
Without --release
|
I think you are just rediscovering #72252 and the issue would be resolved by rust-lang/rfcs#3514 which says your program executes UB. If you think your program should not be UB, I encourage you to read the RFC and the discussion then engage with it. |
A bit of extra information here is that optimized gcc also breaks, but clang doesn't:
If this code is UB then fesetround (and the other intrinsics) should come with a huge notice that they don't always work correctly. |
To prevent compiler optimization with rint(), I call it from assembly:
And this seems to produce correct results on Rust, clang, and gcc all with and without optimizations. |
Yes they should. This code is UB in most C compilers as well. You need to set some This should be filed as a bug against the libm man pages. |
I know this is C code, but I promise this is about Rust. I tried this C code using extern "C" rust calls:
I expected to see this happen: Should be -4: -4
Instead, this happened: Should be -4: -5
Meta
I have built a repository at https://github.com/sarchar/fesetroundbug but generally, this behavior only exists in the Linux build. With clang, gcc, and windows Rust, the correct value is displayed.
Please help.
The text was updated successfully, but these errors were encountered: