Re: [PATCH] ARM: xor-neon: Replace __GNUC__ checks with CONFIG_CC_IS_GCC

From: Arnd Bergmann
Date: Fri May 31 2019 - 04:09:20 EST


On Wed, May 29, 2019 at 1:57 AM Nathan Chancellor
<natechancellor@xxxxxxxxx> wrote:
>
> Currently, when compiling this code with clang, the following warning is
> emitted:
>
> CC arch/arm/lib/xor-neon.o
> arch/arm/lib/xor-neon.c:33:2: warning: This code requires at least
> version 4.6 of GCC [-W#warnings]
>
> This is because clang poses as GCC 4.2.1 with its __GNUC__ conditionals
> for glibc compatibility[1]:
>
> $ echo | clang -dM -E -x c /dev/null | grep GNUC | awk '{print $2" "$3}'
> __GNUC_MINOR__ 2
> __GNUC_PATCHLEVEL__ 1
> __GNUC_STDC_INLINE__ 1
> __GNUC__ 4
>
> As pointed out by Ard Biesheuvel and Arnd Bergmann in an earlier
> thread[2], the oldest version of GCC that is currently supported is gcc
> 4.6 after commit cafa0010cd51 ("Raise the minimum required gcc version
> to 4.6") so we do not need to check for anything older anymore.
>
> However, just removing the version check is not enough to silence clang
> because it does not recognize '#pragma GCC optimize':
>
> arch/arm/lib/xor-neon.c:25:13: warning: unknown pragma ignored
> [-Wunknown-pragmas]
> #pragma GCC optimize "tree-vectorize"
>
> Looking into it further, -ftree-vectorize (which '#pragma GCC optimize
> "tree-vectorize"' enables) is an alias in clang for -fvectorize[3],
> which according to the documentation is on by default[4] (at least at
> -O2 or -Os).
>
> Just add the pragma when compiling with GCC so that clang does not
> unnecessarily warn.

If I remember correctly, we also had the same issue with older versions
of clang, possibly even newer ones. Shouldn't we check for a minimum
compiler version when building with clang to ensure that the code is
really vectorized?

Arnd