Compiler Attributes: homogenize __must_be_array
authorMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Thu, 30 Aug 2018 17:25:14 +0000 (19:25 +0200)
committerMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Sun, 30 Sep 2018 18:14:03 +0000 (20:14 +0200)
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

Therefore, we can remove all of them and have a single definition
in compiler.h

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # on top of v4.19-rc5, clang 7
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
include/linux/compiler-clang.h
include/linux/compiler-gcc.h
include/linux/compiler-intel.h
include/linux/compiler.h

index d11cad61ba5c690c72cabc581333e07af29e3401..fa9532f8d88549a30da224b7330c37770e07e5ba 100644 (file)
@@ -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__)))
index 7a1de7683df5b057e1f72170ca1e2d78c1cd4270..3b32bbfa5a4917dc498527cf2b40979aacc146b0 100644 (file)
  */
 #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
index fef8bb3e53efea3f9318fae65b79b005df8e8c72..6004b4588bd44429a591308f3d760e713c02b3e0 100644 (file)
@@ -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 */
index ec4a28bad2c6f62ceebda511a8da1fd700bdf437..165b1d5683edd2270fef5b286739a46d4812430d 100644 (file)
@@ -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 */