Blame m4/stdalign.m4

Packit 709fb3
# Check for stdalign.h that conforms to C11.
Packit 709fb3
Packit 709fb3
dnl Copyright 2011-2017 Free Software Foundation, Inc.
Packit 709fb3
dnl This file is free software; the Free Software Foundation
Packit 709fb3
dnl gives unlimited permission to copy and/or distribute it,
Packit 709fb3
dnl with or without modifications, as long as this notice is preserved.
Packit 709fb3
Packit 709fb3
# Prepare for substituting <stdalign.h> if it is not supported.
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_STDALIGN_H],
Packit 709fb3
[
Packit 709fb3
  AC_CACHE_CHECK([for working stdalign.h],
Packit 709fb3
    [gl_cv_header_working_stdalign_h],
Packit 709fb3
    [AC_COMPILE_IFELSE(
Packit 709fb3
       [AC_LANG_PROGRAM(
Packit 709fb3
          [[#include <stdalign.h>
Packit 709fb3
            #include <stddef.h>
Packit 709fb3
Packit 709fb3
            /* Test that alignof yields a result consistent with offsetof.
Packit 709fb3
               This catches GCC bug 52023
Packit 709fb3
               <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.  */
Packit 709fb3
            #ifdef __cplusplus
Packit 709fb3
               template <class t> struct alignof_helper { char a; t b; };
Packit 709fb3
            # define ao(type) offsetof (alignof_helper<type>, b)
Packit 709fb3
            #else
Packit 709fb3
            # define ao(type) offsetof (struct { char a; type b; }, b)
Packit 709fb3
            #endif
Packit 709fb3
            char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1];
Packit 709fb3
            char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
Packit 709fb3
            char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];
Packit 709fb3
Packit 709fb3
            /* Test _Alignas only on platforms where gnulib can help.  */
Packit 709fb3
            #if \
Packit 709fb3
                ((defined __cplusplus && 201103 <= __cplusplus) \
Packit 709fb3
                 || (defined __APPLE__ && defined __MACH__ \
Packit 709fb3
                     ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
Packit 709fb3
                     : __GNUC__) \
Packit 709fb3
                 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
Packit 709fb3
                 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__ \
Packit 709fb3
                 || 1300 <= _MSC_VER)
Packit 709fb3
              struct alignas_test { char c; char alignas (8) alignas_8; };
Packit 709fb3
              char test_alignas[offsetof (struct alignas_test, alignas_8) == 8
Packit 709fb3
                                ? 1 : -1];
Packit 709fb3
            #endif
Packit 709fb3
          ]])],
Packit 709fb3
       [gl_cv_header_working_stdalign_h=yes],
Packit 709fb3
       [gl_cv_header_working_stdalign_h=no])])
Packit 709fb3
Packit 709fb3
  if test $gl_cv_header_working_stdalign_h = yes; then
Packit 709fb3
    STDALIGN_H=''
Packit 709fb3
  else
Packit 709fb3
    STDALIGN_H='stdalign.h'
Packit 709fb3
  fi
Packit 709fb3
Packit 709fb3
  AC_SUBST([STDALIGN_H])
Packit 709fb3
  AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"])
Packit 709fb3
])