On Sun, Jan 26, 2025 at 11:00 PM Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote: > > On Sun, 26 Jan 2025 at 11:47, Uros Bizjak <ubizjak@xxxxxxxxx> wrote: > > > > > #if __clang_major__ >= 19 > > > # define CC_HAS_TYPEOF_UNQUAL 1 > > > #endif > > > > It is available in gcc-14. > > Ok, let's take that approach, instead of messing with CONFIG_CC_HAS_xyz. Please find attached an incremental patch that implements the proposed approach. The detection is put in include/linux/compiler.h where we can consolidate checks for both compilers: --cut here-- /* * Declare compiler support for __typeof_unqual__() operator. * * bindgen uses LLVM even if our C compiler is gcc, so we cannot * rely on the auto-detected CONFIG_CC_HAS_TYPEOF_UNQUAL. * * XXX: Remove test for __CHECKER__ once * sparse learns about __typeof_unqual__. */ #if ((defined(__GNUC__) && __GNUC__ >= 14) || \ (defined(__clang__) && __clang_major__ >= 19)) && \ !defined(__CHECKER__) # define CC_HAS_TYPEOF_UNQUAL 1 #endif /* * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof * operator when available, to return an unqualified type of the exp. */ #if defined(CC_HAS_TYPEOF_UNQUAL) # define TYPEOF_UNQUAL(exp) __typeof_unqual__(exp) #else # define TYPEOF_UNQUAL(exp) __typeof__(exp) #endif --cut here-- The above also consolidates checks for __CHECKER__, resulting in a much simpler compile check in arch/x86/include/percpu.h. I have tested the new patch series with a bunch of compilers, works as expected, but it is getting a bit late here. I'll resend the series tomorrow, after some more testing. Uros.
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 1ef08289e667..9f0831a5e712 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -95,12 +95,7 @@ #endif /* CONFIG_SMP */ -/* - * XXX: Remove test for __CHECKER__ once - * sparse learns about __typeof_unqual__. - */ -#if defined(CONFIG_USE_X86_SEG_SUPPORT) && \ - defined(CONFIG_CC_HAS_TYPEOF_UNQUAL) && !defined(__CHECKER__) +#if defined(CONFIG_USE_X86_SEG_SUPPORT) && defined(CC_HAS_TYPEOF_UNQUAL) # define __my_cpu_type(var) typeof(var) # define __my_cpu_ptr(ptr) (ptr) # define __my_cpu_var(var) (var) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index eac58025ecfc..7a52bea4ba76 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -314,13 +314,25 @@ static inline void *offset_to_ptr(const int *off) #define prevent_tail_call_optimization() mb() /* - * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof - * operator when available, to return unqualified type of the exp. + * Declare compiler support for __typeof_unqual__() operator. + * + * bindgen uses LLVM even if our C compiler is gcc, so we cannot + * rely on the auto-detected CONFIG_CC_HAS_TYPEOF_UNQUAL. * * XXX: Remove test for __CHECKER__ once * sparse learns about __typeof_unqual__. */ -#if defined(CONFIG_CC_HAS_TYPEOF_UNQUAL) && !defined(__CHECKER__) +#if ((defined(__GNUC__) && __GNUC__ >= 14) || \ + (defined(__clang__) && __clang_major__ >= 19)) && \ + !defined(__CHECKER__) +# define CC_HAS_TYPEOF_UNQUAL 1 +#endif + +/* + * Define TYPEOF_UNQUAL() to use __typeof_unqual__() as typeof + * operator when available, to return an unqualified type of the exp. + */ +#if defined(CC_HAS_TYPEOF_UNQUAL) # define TYPEOF_UNQUAL(exp) __typeof_unqual__(exp) #else # define TYPEOF_UNQUAL(exp) __typeof__(exp) diff --git a/init/Kconfig b/init/Kconfig index a1507b8714e4..7fe82a46e88c 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -897,9 +897,6 @@ config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH config CC_HAS_INT128 def_bool !$(cc-option,$(m64-flag) -D__SIZEOF_INT128__=0) && 64BIT -config CC_HAS_TYPEOF_UNQUAL - def_bool $(success,echo 'int foo (int a) { __typeof_unqual__(a) b = a; return b; }' | $(CC) -x c - -S -o /dev/null) - config CC_IMPLICIT_FALLTHROUGH string default "-Wimplicit-fallthrough=5" if CC_IS_GCC && $(cc-option,-Wimplicit-fallthrough=5)