-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-30104: Compile dtoa.c without strict aliasing #1340
Conversation
I tested manually the patch on Linux using clang 4.0: dtoa.c is compiled with -fno-strict-aliasing, test_strtod test pass, and only dtoa.c is compiled with -fno-strict-aliasing so other C optimized are optimized with strict aliasing rules. |
The main question is if the -no-strict-aliasing option is supported by all UNIX and BSD compilers? What about Solaris and HP-UX compilers? I propose to push the change and fix it later if someone complains. What do you think? |
I don't know well autotools, so I also tested to compile CPython from a different directory:
dtoa.o is written into build_cpython/Python, not in ~/prog/python/master/Python: it works :-) |
I chose to add the flag for any C compiler. If you think that a C compiler may not support that option, we can start by only adding the option on clang, and maybe add it on other C compilers if someone complains. configure is now able to detect correctly the clang compiler. |
Originally, However, there are definitely compilers out there which will not support this flag, for example the Microsoft C/C++ compiler. Does this commit affect the flags passed to Microsoft C/C++? |
No, we use the PCbuild directory for Microsoft Visual Studio and its C compiler. It's a completely different build system.
Do you suggest to first only define the flag on clang? |
Yes, that should the most minimal way of fixing the original issue, since gcc itself won't need it. |
On clang, only compile dtoa.c with -fno-strict-aliasing, use strict aliasing to compile all other C files.
Ok, done. The new change now only impacts clang and only use -fno-strict-aliasing on dtoa.c to optimize correctly all other C files using strict aliasing, as decided in bpo-30124. |
I tested that clang uses -fno-strict-aliasing but only on dtoa.c and gcc never uses -fno-strict-aliasing. |
dtoa.c uses union to cast double to unsigned long[2]. clang 4.0 with
-O2 or higher and strict aliasing miscompiles the ratio() function
causing rounding issues. Always disable strict aliasing on dtoa.c to
prevent any risk of bug caused by optimizations.