From b6dbca7699c79335c2d904700be4fe77ac41bdd3 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Mon, 13 Sep 2021 21:00:54 +0300 Subject: [PATCH] Moved some logic from 'configure' to 'mhd_align.h' This should improve readability and maintainability of the code. --- configure.ac | 7 ------- src/microhttpd/mhd_align.h | 30 +++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 5a5b82f0..0ac7b6b7 100644 --- a/configure.ac +++ b/configure.ac @@ -308,13 +308,6 @@ AC_CACHE_CHECK([[for C11 'alignof()' support]], [[mhd_cv_c_alignof]], #include #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 index c570eaa7..4169236f 100644 --- 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 -#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 */