]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
move the alignment macro to compiler.h
authorYann Collet <cyan@fb.com>
Thu, 2 Dec 2021 19:20:01 +0000 (11:20 -0800)
committerYann Collet <cyan@fb.com>
Thu, 2 Dec 2021 19:20:01 +0000 (11:20 -0800)
because mem.h is dropped in the Linux kernel.

Changed macro definition order (gcc/clang/msvc before c11)
due to a limitation in the kernel source builder.

Changed the backup to sizeof(),
reverting to previous behavior when no support of alignof() is detected.

lib/common/compiler.h
lib/common/mem.h

index ea5fe2f472d0273ffe82e1cde4468ee895f3a545..907b6bfacd1a43e51e729154d535a354cdad7b97 100644 (file)
 # endif
 #endif
 
+/*-**************************************************************
+*  Alignment check
+*****************************************************************/
+
+/* this test was initially positioned in mem.h,
+ * but this file is removed (or replaced) for linux kernel
+ * so it's now hosted in compiler.h,
+ * which remains valid for both user & kernel spaces.
+ */
+
+#ifndef MEM_ALIGN_COND
+# if defined(__GNUC__) || defined(_MSC_VER)
+/* covers gcc, clang & MSVC */
+/* note : this section must come first, before C11,
+ * due to a limitation in the kernel source generator */
+#  define MEM_ALIGN_COND(T) __alignof(T)
+
+# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+/* C11 support */
+#  include <stdalign.h>
+#  define MEM_ALIGN_COND(T) alignof(T)
+
+# else
+/* No known support for alignof() - imperfect backup */
+#  define MEM_ALIGN_COND(T) sizeof(T)
+
+# endif
+#endif /* MEM_ALIGN_COND */
+
+/*-**************************************************************
+*  Sanitizer
+*****************************************************************/
+
 #if ZSTD_MEMORY_SANITIZER
 /* Not all platforms that support msan provide sanitizers/msan_interface.h.
  * We therefore declare the functions we need ourselves, rather than trying to
index 4803897cf80dcd9ea08f103e6b94c5b4ce7bf73b..1c61b7e52f1b61085e96a3762aeb12cc9bb00968 100644 (file)
@@ -80,26 +80,6 @@ extern "C" {
 #endif
 
 
-/*-**************************************************************
-*  Alignment check
-*****************************************************************/
-
-/* C11 support */
-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
-
-#include <stdalign.h>
-# define MEM_ALIGN_COND(T) alignof(T)
-
-#elif defined(__GNUC__) || defined(_MSC_VER)
-
-# define MEM_ALIGN_COND(T) __alignof(T)
-
-#else
-
-# define MEM_ALIGN_COND(T) 1  /* most likely incorrect, just to pass tests */
-
-#endif
-
 /*-**************************************************************
 *  Memory I/O API
 *****************************************************************/