llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.85k stars 11.47k forks source link

[clang] document default for `__GNUC__` macros #99804

Open h-vetinari opened 1 month ago

h-vetinari commented 1 month ago

While the documentation notes how to override GNU compatibility macros using -fgnuc-version=, it doesn't note that it's set by default (it is), nor what value it is set to.

It takes a fair bit of digging in the code to actually figure out that it's still at

__GNUC__=4
__GNUC_MINOR__=2
__GNUC_PATCHLEVEL__=1

which is ancient (cf. #42162). The consequence of this is that benign-looking code based on these macros will implicitly fall back to workarounds that shouldn't actually be necessary, and end up pessimizing clang-compiled code. Example: https://github.com/scipy/scipy/issues/20479

ms178 commented 1 month ago

You might be already aware of it, but just for posterity, OpenMandriva carries several patches to Glibc to overcome some limitations of using higher -fgnuc-version= values:

1) https://github.com/OpenMandrivaAssociation/glibc/blob/master/glibc-2.19-no-__builtin_va_arg_pack-with-clang.patch 2) https://github.com/OpenMandrivaAssociation/glibc/blob/master/glibc-2.33-clang-_Float32-_Float64.patch 3) https://github.com/OpenMandrivaAssociation/glibc/blob/master/glibc-2.34-headers-clang.patch

But even when using these with a patched Glibc, I've ran into some issues in the past and present compiling some projects due to missing features in Clang: https://github.com/llvm/llvm-project/issues/63642 (while this is just one example that got fixed by OpenMandriva, there are similar ones that I did not report due to the hacky nature of that override).

I think these subtle differences between GCC and Clang prevented raising the mentioned default value for some time now. But I am not an expert.