Re: [PATCH 4/7] Compiler Attributes: homogenize __must_be_array

From: Nick Desaulniers
Date: Fri Aug 31 2018 - 17:16:59 EST


On Fri, Aug 31, 2018 at 10:05 AM Miguel Ojeda
<miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> Different definitions of __must_be_array:
>
> * gcc: disabled for __CHECKER__
>
> * clang: same definition as gcc's, but without __CHECKER__
>
> * intel: the comment claims __builtin_types_compatible_p()
> is unsupported; but icc seems to support it since 13.0.1
> (released in 2012). See https://godbolt.org/z/S0l6QQ

Indeed. It seems that if we can't find a contact for ICC, then 13.0.1
(the oldest version supported by godbolt) is a best effort, IMO. If
we end up adding patches for minimal compiler versions, maybe v13.0.1
is a good minimal for ICC. But I would really defer to someone who
has an install of ICC (not me).

>
> Therefore, we can remove all of them and have a single definition
> in compiler.h
>
> Cc: Eli Friedman <efriedma@xxxxxxxxxxxxxx>
> Cc: Christopher Li <sparse@xxxxxxxxxxx>
> Cc: Kees Cook <keescook@xxxxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Cc: Arnd Bergmann <arnd@xxxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: Masahiro Yamada <yamada.masahiro@xxxxxxxxxxxxx>
> Cc: Joe Perches <joe@xxxxxxxxxxx>
> Cc: Dominique Martinet <asmadeus@xxxxxxxxxxxxx>
> Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
> Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx>
> ---
> include/linux/compiler-clang.h | 1 -
> include/linux/compiler-gcc.h | 7 -------
> include/linux/compiler-intel.h | 3 ---
> include/linux/compiler.h | 7 +++++++
> 4 files changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
> index efda74f4eeba..0aee694d3ab8 100644
> --- a/include/linux/compiler-clang.h
> +++ b/include/linux/compiler-clang.h
> @@ -41,6 +41,5 @@
> * compilers, like ICC.
> */
> #define barrier() __asm__ __volatile__("" : : : "memory")
> -#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
> #define __assume_aligned(a, ...) \
> __attribute__((assume_aligned(a, ## __VA_ARGS__)))
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index dbfbecf703f8..66e1eb8822d9 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -68,13 +68,6 @@
> */
> #define uninitialized_var(x) x = x
>
> -#ifdef __CHECKER__
> -#define __must_be_array(a) 0
> -#else
> -/* &a[0] degrades to a pointer: a different type from an array */
> -#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
> -#endif
> -
> #ifdef RETPOLINE
> #define __noretpoline __attribute__((indirect_branch("keep")))
> #endif
> diff --git a/include/linux/compiler-intel.h b/include/linux/compiler-intel.h
> index 4c7f9befa9f6..18bd4362deaa 100644
> --- a/include/linux/compiler-intel.h
> +++ b/include/linux/compiler-intel.h
> @@ -29,9 +29,6 @@
> */
> #define OPTIMIZER_HIDE_VAR(var) barrier()
>
> -/* Intel ECC compiler doesn't support __builtin_types_compatible_p() */
> -#define __must_be_array(a) 0
> -
> #endif
>
> /* icc has this, but it's called _bswap16 */
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index e0e55eb3f242..e4a702f99e50 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -357,4 +357,11 @@ static inline void *offset_to_ptr(const int *off)
> compiletime_assert(__native_word(t), \
> "Need native word sized stores/loads for atomicity.")
>
> +#ifdef __CHECKER__
> +#define __must_be_array(a) 0
> +#else
> +/* &a[0] degrades to a pointer: a different type from an array */
> +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
> +#endif
> +
> #endif /* __LINUX_COMPILER_H */
> --
> 2.17.1
>

Reviewed-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>

--
Thanks,
~Nick Desaulniers