-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Use of infinity() in code compiled with -ffast-math ( durationutiltest.cpp & frametest.cpp ) #13780
Comments
likely fairly straightforward to fix using |
Do you have an idea on how to ensure we don't create an |
For the durationutiltest.cpp it's pretty easy to use max() instead. But for the FramePos I'm unsure. I would've fixed it, if I would understand this. |
We have already a hack implemented for this in FpClassify Line 2546 in a716202
So you may use infinity though that library to rely on a defined representation in the targets memory. |
Compiling this without -ffast-math as for FpClassify would remove the errors of cause. But I don't think this is a proper fix, as there seems to be no need to use slow math here. |
The solution is to add a wrapper for |
I don't think that works. Its UB the moment |
Think of CPU Registers and memory. Just because the CPU executed code compiled with fast-math there is no effect to thesese even if there are infinity values. This "trick" has been introduced to hand elexactly the case you described, when we receive infinity from libraries not compiled with fast-math we can handle them via declassify. |
We had this discussion before. If you program in C++, you're not programming against the CPU, you're programming against the C++ abstract machine. The entire point is that the compiler is free to change the behavior in cases which (from the viewpoint of the compiler) can't happen (such as The usecase with external libraries is the only reasonable use of fpclassify. Any operation on infinity in -ffast-math code is still UB regardless of whether the underlying hardware may be able to handle it. Your proposal of introducing To conclude. See this code example where |
Confirmed.
Confirmed
Confirmed.
Confirmed
No, it is not intended/possible to deal with inf in that code. All operations dealing with inf() need to be done via in the fpcallsify.cpp wrapper.
Not really, we use anyway library functions for that, the additional wrapper "just" prevents inlining and optimizing away inf handling as shown in the compiler explorer. The fpcallsify.cpp wrapper makes sure the left asm representation in your compiler explorer of the C++ code is used. |
I agree with @Swiftb0y here, moving the code to fpcallsify.cpp would be an ugly workaround and no proper fix. It's our own code, that uses INF - therefore we can and should fix it, instead of moving it into the slow-math entity. |
I see how @daschuer's proposal could work, but its really easy to accidentally make mistakes with it IMO. If we get an |
I don't mind which solution we pick. It is finally a question how easy and risky a logic change is. For my understanding the issue is only to fix a new more strict and valid warning in code that still works because the UB is like we want. Wrapping it by a library with defined behaviour is therefore a valid fix. And any math operation on inf() fails anyway in any code. |
Bug Description
If I compile with clang-tidy 18, I get the following errors, because we use infinity() in code that is compiled with option
-ffast-math
. And-ffast-math
sets-ffinite-math-only
.Version
main
OS
Clang 18
The text was updated successfully, but these errors were encountered: