diff mbox series

mips: Fix unroll macro when building with Clang

Message ID 20191010203159.20565-1-natechancellor@gmail.com (mailing list archive)
State Mainlined
Commit df3da04880b45b059b8b064c2dd67289a793109e
Delegated to: Paul Burton
Headers show
Series mips: Fix unroll macro when building with Clang | expand

Commit Message

Nathan Chancellor Oct. 10, 2019, 8:31 p.m. UTC
Building with Clang errors after commit 6baaeadae911 ("MIPS: Provide
unroll() macro, use it for cache ops") since the GCC_VERSION macro
is defined in include/linux/compiler-gcc.h, which is only included
in compiler.h when using GCC:

In file included from arch/mips/kernel/mips-mt.c:20:
./arch/mips/include/asm/r4kcache.h:254:1: error: use of undeclared
identifier 'GCC_VERSION'; did you mean 'S_VERSION'?
__BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32,
)
^
./arch/mips/include/asm/r4kcache.h:219:4: note: expanded from macro
'__BUILD_BLAST_CACHE'
                        cache_unroll(32, kernel_cache, indexop,
                        ^
./arch/mips/include/asm/r4kcache.h:203:2: note: expanded from macro
'cache_unroll'
        unroll(times, _cache_op, insn, op, (addr) + (i++ * (lsize)));
        ^
./arch/mips/include/asm/unroll.h:28:15: note: expanded from macro
'unroll'
        BUILD_BUG_ON(GCC_VERSION >= 40700 &&                    \
                     ^

Use CONFIG_GCC_VERSION, which will always be set by Kconfig.
Additionally, Clang 8 had improvements around __builtin_constant_p so
use that as a lower limit for this check with Clang (although MIPS
wasn't buildable until Clang 9); building a kernel with Clang 9.0.0
has no issues after this change.

Fixes: 6baaeadae911 ("MIPS: Provide unroll() macro, use it for cache ops")
Link: https://github.com/ClangBuiltLinux/linux/issues/736
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/mips/include/asm/unroll.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Paul Burton Oct. 10, 2019, 9:04 p.m. UTC | #1
Hello,

Nathan Chancellor wrote:
> Building with Clang errors after commit 6baaeadae911 ("MIPS: Provide
> unroll() macro, use it for cache ops") since the GCC_VERSION macro
> is defined in include/linux/compiler-gcc.h, which is only included
> in compiler.h when using GCC:
> 
> In file included from arch/mips/kernel/mips-mt.c:20:
> ./arch/mips/include/asm/r4kcache.h:254:1: error: use of undeclared
> identifier 'GCC_VERSION'; did you mean 'S_VERSION'?
> __BUILD_BLAST_CACHE(i, icache, Index_Invalidate_I, Hit_Invalidate_I, 32,
> )
> ^
> ./arch/mips/include/asm/r4kcache.h:219:4: note: expanded from macro
> '__BUILD_BLAST_CACHE'
>                         cache_unroll(32, kernel_cache, indexop,
>                         ^
> ./arch/mips/include/asm/r4kcache.h:203:2: note: expanded from macro
> 'cache_unroll'
>         unroll(times, _cache_op, insn, op, (addr) + (i++ * (lsize)));
>         ^
> ./arch/mips/include/asm/unroll.h:28:15: note: expanded from macro
> 'unroll'
>         BUILD_BUG_ON(GCC_VERSION >= 40700 &&                    \
>                      ^
> 
> Use CONFIG_GCC_VERSION, which will always be set by Kconfig.
> Additionally, Clang 8 had improvements around __builtin_constant_p so
> use that as a lower limit for this check with Clang (although MIPS
> wasn't buildable until Clang 9); building a kernel with Clang 9.0.0
> has no issues after this change.

Applied to mips-next.

> commit df3da04880b4
> https://git.kernel.org/mips/c/df3da04880b4
> 
> Fixes: 6baaeadae911 ("MIPS: Provide unroll() macro, use it for cache ops")
> Link: https://github.com/ClangBuiltLinux/linux/issues/736
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> Signed-off-by: Paul Burton <paul.burton@mips.com>

Thanks,
    Paul

[ This message was auto-generated; if you believe anything is incorrect
  then please email paul.burton@mips.com to report it. ]
diff mbox series

Patch

diff --git a/arch/mips/include/asm/unroll.h b/arch/mips/include/asm/unroll.h
index df1cdcfc5a47..c628747d4ecd 100644
--- a/arch/mips/include/asm/unroll.h
+++ b/arch/mips/include/asm/unroll.h
@@ -25,7 +25,8 @@ 
 	 * generate reasonable code for the switch statement,	\
 	 * so we skip the sanity check for those compilers.	\
 	 */							\
-	BUILD_BUG_ON(GCC_VERSION >= 40700 &&			\
+	BUILD_BUG_ON((CONFIG_GCC_VERSION >= 40700 ||		\
+		      CONFIG_CLANG_VERSION >= 80000) &&		\
 		     !__builtin_constant_p(times));		\
 								\
 	switch (times) {					\