stdalign.m4 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Check for stdalign.h that conforms to C11.
  2. dnl Copyright 2011-2013 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 <stdalign.h>
  14. #include <stddef.h>
  15. /* Test that alignof yields a result consistent with offsetof.
  16. This catches GCC bug 52023
  17. <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */
  18. #ifdef __cplusplus
  19. template <class t> struct alignof_helper { char a; t b; };
  20. # define ao(type) offsetof (alignof_helper<type>, b)
  21. #else
  22. # define ao(type) offsetof (struct { char a; type b; }, b)
  23. #endif
  24. char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1];
  25. char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
  26. char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];
  27. /* Test _Alignas only on platforms where gnulib can help. */
  28. #if \
  29. (__GNUC__ || __IBMC__ || __IBMCPP__ \
  30. || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER)
  31. struct alignas_test { char c; char alignas (8) alignas_8; };
  32. char test_alignas[offsetof (struct alignas_test, alignas_8) == 8
  33. ? 1 : -1];
  34. #endif
  35. ]])],
  36. [gl_cv_header_working_stdalign_h=yes],
  37. [gl_cv_header_working_stdalign_h=no])])
  38. if test $gl_cv_header_working_stdalign_h = yes; then
  39. STDALIGN_H=''
  40. else
  41. STDALIGN_H='stdalign.h'
  42. fi
  43. AC_SUBST([STDALIGN_H])
  44. AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"])
  45. ])