commit b6dbca7699c79335c2d904700be4fe77ac41bdd3
parent a066a34138c38d702b9f335f22f320cfc795ccda
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Mon, 13 Sep 2021 21:00:54 +0300
Moved some logic from 'configure' to 'mhd_align.h'
This should improve readability and maintainability of the code.
Diffstat:
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -308,13 +308,6 @@ AC_CACHE_CHECK([[for C11 'alignof()' support]], [[mhd_cv_c_alignof]],
#include <stdalign.h>
#endif
]], [[
-#if (defined (__GNUC__) && __GNUC__ < 4 && __GNUC_MINOR__ < 9 && ! defined(__clang__)) || \
- (defined (__clang__) && __clang_major__ < 8)
-/* GCC before 4.9 and clang before 8.0 have incorrect implementation of 'alignof()'
- which returns preferred alignment instead of minimal required alignment */
-#error Compiler has incorrect implementation of alignof()
-choke me now
-#endif
int var1[(alignof(int) >= 2) ? 1 : -1];
int var2[alignof(unsigned int) - 1];
int var3[(alignof(char) > 0) ? 1 : -1];
diff --git a/src/microhttpd/mhd_align.h b/src/microhttpd/mhd_align.h
@@ -33,24 +33,36 @@
#endif
#ifdef HAVE_C_ALIGNOF
-
#ifdef HAVE_STDALIGN_H
#include <stdalign.h>
-#endif
-
+#endif /* HAVE_STDALIGN_H */
#define _MHD_ALIGNOF(type) alignof(type)
-
#endif /* HAVE_C_ALIGNOF */
#ifndef _MHD_ALIGNOF
-#if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER >= 1900
-/* MSVC has the same problem as older GCC versions:
- '__alignof()' may return "preferred" alignment instead of "required",
- but it is related to floating point variables only. */
+#if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER >= 1700
#define _MHD_ALIGNOF(type) __alignof(type)
#endif /* _MSC_VER >= 1900 */
#endif /* !_MHD_ALIGNOF */
+#ifdef _MHD_ALIGNOF
+#if (defined (__GNUC__) && __GNUC__ < 4 && __GNUC_MINOR__ < 9 && \
+ ! defined(__clang__)) || \
+ (defined (__clang__) && __clang_major__ < 8) || \
+ (defined (__clang__) && __clang_major__ < 11 && \
+ defined(__apple_build_version__))
+/* GCC before 4.9 and clang before 8.0 have incorrect implementation of 'alignof()'
+ which returns preferred alignment instead of minimal required alignment */
+#define _MHD_ALIGNOF_UNRELIABLE 1
+#endif
+
+#if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1900
+/* MSVC has the same problem as old GCC versions:
+ '__alignof()' may return "preferred" alignment instead of "required". */
+#define _MHD_ALIGNOF_UNRELIABLE 1
+#endif /* _MSC_VER < 1900 */
+#endif /* _MHD_ALIGNOF */
+
#ifdef offsetof
#define _MHD_OFFSETOF(strct, membr) offsetof(strct, membr)
@@ -61,7 +73,7 @@
/* Provide a limited set of alignment macros */
/* The set could be extended as needed */
-#ifdef _MHD_ALIGNOF
+#if defined(_MHD_ALIGNOF) && ! defined(_MHD_ALIGNOF_UNRELIABLE)
#define _MHD_UINT32_ALIGN _MHD_ALIGNOF(uint32_t)
#define _MHD_UINT64_ALIGN _MHD_ALIGNOF(uint64_t)
#else /* ! _MHD_ALIGNOF */