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