18dffb485Schristos# Check for stdalign.h that conforms to C11. 28dffb485Schristos 3*4b169a6bSchristosdnl Copyright 2011-2022 Free Software Foundation, Inc. 48dffb485Schristosdnl This file is free software; the Free Software Foundation 58dffb485Schristosdnl gives unlimited permission to copy and/or distribute it, 68dffb485Schristosdnl with or without modifications, as long as this notice is preserved. 78dffb485Schristos 88dffb485Schristos# Prepare for substituting <stdalign.h> if it is not supported. 98dffb485Schristos 108dffb485SchristosAC_DEFUN([gl_STDALIGN_H], 118dffb485Schristos[ 128dffb485Schristos AC_CACHE_CHECK([for working stdalign.h], 138dffb485Schristos [gl_cv_header_working_stdalign_h], 148dffb485Schristos [AC_COMPILE_IFELSE( 158dffb485Schristos [AC_LANG_PROGRAM( 16*4b169a6bSchristos [[#include <stdint.h> 17*4b169a6bSchristos #include <stdalign.h> 188dffb485Schristos #include <stddef.h> 198dffb485Schristos 208dffb485Schristos /* Test that alignof yields a result consistent with offsetof. 218dffb485Schristos This catches GCC bug 52023 228dffb485Schristos <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */ 238dffb485Schristos #ifdef __cplusplus 248dffb485Schristos template <class t> struct alignof_helper { char a; t b; }; 258dffb485Schristos # define ao(type) offsetof (alignof_helper<type>, b) 268dffb485Schristos #else 278dffb485Schristos # define ao(type) offsetof (struct { char a; type b; }, b) 288dffb485Schristos #endif 298dffb485Schristos char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1]; 308dffb485Schristos char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1]; 318dffb485Schristos char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1]; 328dffb485Schristos 338dffb485Schristos /* Test _Alignas only on platforms where gnulib can help. */ 348dffb485Schristos #if \ 358dffb485Schristos ((defined __cplusplus && 201103 <= __cplusplus) \ 36*4b169a6bSchristos || (__TINYC__ && defined __attribute__) \ 378dffb485Schristos || (defined __APPLE__ && defined __MACH__ \ 388dffb485Schristos ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \ 398dffb485Schristos : __GNUC__) \ 408dffb485Schristos || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \ 418dffb485Schristos || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__ \ 428dffb485Schristos || 1300 <= _MSC_VER) 438dffb485Schristos struct alignas_test { char c; char alignas (8) alignas_8; }; 448dffb485Schristos char test_alignas[offsetof (struct alignas_test, alignas_8) == 8 458dffb485Schristos ? 1 : -1]; 468dffb485Schristos #endif 478dffb485Schristos ]])], 488dffb485Schristos [gl_cv_header_working_stdalign_h=yes], 498dffb485Schristos [gl_cv_header_working_stdalign_h=no])]) 508dffb485Schristos 518dffb485Schristos if test $gl_cv_header_working_stdalign_h = yes; then 52*4b169a6bSchristos GL_GENERATE_STDALIGN_H=false 538dffb485Schristos else 54*4b169a6bSchristos GL_GENERATE_STDALIGN_H=true 558dffb485Schristos fi 568dffb485Schristos]) 57