Issues when building with clang (__float128)
Hello,
I am currently testing clang compilation and ran into several issues. Due to #1669 being unfixed at this moment I mostly relied on 3.8.0 win32 and 3.9.0 rc3 win32, however I tested mingw-w64-i686-clang (3.8) as well. Due to reports getting large I decided to split them.
1. __float128 is completely broken starting with clang 3.9 after all
Before 3.9.0 clang did not support __float128 and prior to 3.9.0 it was defining a type alias to get libstdc++ headers compile.
Starting with 3.9.0 clang implemented native __float128 support and the alias workaround was removed. The only targets supporting __float128 at this moment are linux x86_64 and i686, and some powerpc, which means no mingw.
Relevant lines are:
_msys64\mingw32\include\c++\6.1.0\i686-w64-mingw32\bits\c++config.h_
/* Define if __float128 is supported on this host. */
#define _GLIBCXX_USE_FLOAT128 1
_msys64\mingw32\include\c++\6.1.0\type_traits_
#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
template<>
struct __is_floating_point_helper<__float128>
: public true_type { };
#endif
Minimal sample (works with clang 3.8, does not with 3.9):
_clang++ -target i686-w64-mingw32 -std=gnu++11 example.cpp_
#include <type_traits>
int main() {}
__STRICT_ANSI__ does fix it but disables a number of gnu extensions, which is undesired;__FLOAT128__ macro if __float128 is properly supported (according to the first review).Suggested solution:
Since clang had never supported __float128 before 3.9.0 and since 3.9.0 still did not add the support it on win, although this may get changed in the future, I would like to see the following change to be applied to _c++config.h_:
/* Define if __float128 is supported on this host. */
#if defined(__FLOAT128__) || !defined(__clang__)
#define _GLIBCXX_USE_FLOAT128 1
#endif
It should not affect any configurations but will fix the compilation and allow upgrading clang to 3.9.0.
Modifying libstdc++ in that way is against their policy and should be avoided if possible.
It's Clang issue and should be resolved in Clang.
Possible solutions are:
@mati865 how is that a clang issue? Clang does not provide support for __float128 on 32-bit x86.
And libstc++ is built with gcc instead of clang, which does support it. Clearly if libstdc++ is built properly, then clang will compile fine.
Your suggestion to fallback to old typedef workaround will no longer work on 3.9. Since clang added proper support to __float128 on supported targets, and __float128 is a reserved keyword.
libstdc++ is GCC stuff (that's why they are creating libc++) so it's normal to be compiled with GCC.
If Clang wants to use libstdc++ then it's obligated to be compatible with it.
@mati865 libstdc++ is _not_ GCC stuff. This is just a gnu c++ library, and license issues are the main reasons people at llvm work on libc++.
Each library is to be compiled for the compiler it is meant to use with. Clang does support libstdc++ when _configured_ and _compiled_ to be used with clang. Why should it be aware of _other_ compilers, which are unrelated.
It's located inside GCC source tree and compiled by GCC on (almost?) every GNU/Linux. Modifying it isn't real solution because if some wants to take and use Clang from here he would also have to patch libstdc++.
I don't know what MSYS2 developers think about it but I'm against patching libstdc++ for Clang bugs.
We must be pragmatic here. How much is missing for __float128 support on mingw-w64 i686? @martell, any ideas?
@mati865, you are also an MSYS2 developer! 馃檪
@mingwandroid, not officially 馃槈.
I think code from Linux module should work but I don't really know how to enable it.
Anyway I'm sorting and cleaning up patches and tomorrow will open WIP PR so everyone can take a look/test.
Okay I'm back and finally have time to work on this fun stuff over the next few days :)
The most telling change is in lib/AST/MicrosoftMangle.cpp it should never have been committed into clang without support for all the targets. Unfortunately mingw is a second class citizen.
I can understand however why they really wanted to merge it for power8 before the branch was made.
I think getting a release of 3.9.0 for MINGW-PACKAGES is priority over waiting for a fix so
Rather then editing c++config.h I will create a patch to revert parts of https://reviews.llvm.org/rL266186 to apply on top of 3.9.0 until I create a test case and get support added for mingw upstream.
I will be looking at having support for this come the 4.0.0 release.
Great, thanks @martell.
I've reverted whole _float128 patch https://github.com/Alexpux/MINGW-packages/pull/1833 and it seems to work.
Resolved
Alright, thanks. Let me close this for now. I will reopen if I get the issue when I try it next time.
Resolved upstream
https://bugs.llvm.org//show_bug.cgi?id=30685
Most helpful comment
@mati865, you are also an MSYS2 developer! 馃檪