stdalign.m4 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Check for stdalign.h that conforms to C11.
  2. dnl Copyright 2011-2021 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. # Prepare for substituting <stdalign.h> if it is not supported.
  7. AC_DEFUN([gl_STDALIGN_H],
  8. [
  9. AC_CACHE_CHECK([for working stdalign.h],
  10. [gl_cv_header_working_stdalign_h],
  11. [AC_COMPILE_IFELSE(
  12. [AC_LANG_PROGRAM(
  13. [[#include <stdint.h>
  14. #include <stdalign.h>
  15. #include <stddef.h>
  16. /* Test that alignof yields a result consistent with offsetof.
  17. This catches GCC bug 52023
  18. <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */
  19. #ifdef __cplusplus
  20. template <class t> struct alignof_helper { char a; t b; };
  21. # define ao(type) offsetof (alignof_helper<type>, b)
  22. #else
  23. # define ao(type) offsetof (struct { char a; type b; }, b)
  24. #endif
  25. char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1];
  26. char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
  27. char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];
  28. /* Test _Alignas only on platforms where gnulib can help. */
  29. #if \
  30. ((defined __cplusplus && 201103 <= __cplusplus) \
  31. || (__TINYC__ && defined __attribute__) \
  32. || (defined __APPLE__ && defined __MACH__ \
  33. ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
  34. : __GNUC__) \
  35. || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
  36. || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__ \
  37. || 1300 <= _MSC_VER)
  38. struct alignas_test { char c; char alignas (8) alignas_8; };
  39. char test_alignas[offsetof (struct alignas_test, alignas_8) == 8
  40. ? 1 : -1];
  41. #endif
  42. ]])],
  43. [gl_cv_header_working_stdalign_h=yes],
  44. [gl_cv_header_working_stdalign_h=no])])
  45. if test $gl_cv_header_working_stdalign_h = yes; then
  46. STDALIGN_H=''
  47. else
  48. STDALIGN_H='stdalign.h'
  49. fi
  50. AC_SUBST([STDALIGN_H])
  51. AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"])
  52. ])