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

From: Luc Van Oostenryck
Date: Sat Sep 01 2018 - 05:17:48 EST


On Fri, Aug 31, 2018 at 07:05:11PM +0200, Miguel Ojeda wrote:
> Different definitions of __must_be_array:
>
> * gcc: disabled for __CHECKER__
> 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 */

You can also remove the #ifdef __CHECKER__ because:
1) even ancient version of sparse don't have a problem
2) BUILD_BUG_ON_ZERO() is currently disabled for __CHECKER__

-- Luc Van Oostenryck