summaryrefslogtreecommitdiffstats
path: root/gl/m4/stdalign.m4
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2023-02-10 10:43:20 (GMT)
committerGitHub <noreply@github.com>2023-02-10 10:43:20 (GMT)
commitc07206f2ccc2356aa74bc6813a94c2190017d44e (patch)
tree1677e5fdca5c3ce544e92c5484e16a0b68df1cc9 /gl/m4/stdalign.m4
parente92046f810658016b7c373677efefda3b21400e4 (diff)
parentd2fcf49ad4afc15f37d082d7bc96a808369ec2d4 (diff)
downloadmonitoring-plugins-c07206f.tar.gz
Merge pull request #1832 from RincewindsHat/gnulib_update_2023
Gnulib update 2023 and attendant fixes
Diffstat (limited to 'gl/m4/stdalign.m4')
-rw-r--r--gl/m4/stdalign.m4121
1 files changed, 103 insertions, 18 deletions
diff --git a/gl/m4/stdalign.m4 b/gl/m4/stdalign.m4
index 20be01a..dc29717 100644
--- a/gl/m4/stdalign.m4
+++ b/gl/m4/stdalign.m4
@@ -1,6 +1,6 @@
1# Check for stdalign.h that conforms to C11. 1# Check for alignas and alignof that conform to C23.
2 2
3dnl Copyright 2011-2013 Free Software Foundation, Inc. 3dnl Copyright 2011-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -9,16 +9,23 @@ dnl with or without modifications, as long as this notice is preserved.
9 9
10AC_DEFUN([gl_STDALIGN_H], 10AC_DEFUN([gl_STDALIGN_H],
11[ 11[
12 AC_CACHE_CHECK([for working stdalign.h], 12 AC_CACHE_CHECK([for alignas and alignof],
13 [gl_cv_header_working_stdalign_h], 13 [gl_cv_header_working_stdalign_h],
14 [AC_COMPILE_IFELSE( 14 [gl_save_CFLAGS=$CFLAGS
15 for gl_working in "yes, keywords" "yes, <stdalign.h> macros"; do
16 AS_CASE([$gl_working],
17 [*stdalign.h*], [CFLAGS="$gl_save_CFLAGS -DINCLUDE_STDALIGN_H"])
18 AC_COMPILE_IFELSE(
15 [AC_LANG_PROGRAM( 19 [AC_LANG_PROGRAM(
16 [[#include <stdalign.h> 20 [[#include <stdint.h>
21 #ifdef INCLUDE_STDALIGN_H
22 #include <stdalign.h>
23 #endif
17 #include <stddef.h> 24 #include <stddef.h>
18 25
19 /* Test that alignof yields a result consistent with offsetof. 26 /* Test that alignof yields a result consistent with offsetof.
20 This catches GCC bug 52023 27 This catches GCC bug 52023
21 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */ 28 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */
22 #ifdef __cplusplus 29 #ifdef __cplusplus
23 template <class t> struct alignof_helper { char a; t b; }; 30 template <class t> struct alignof_helper { char a; t b; };
24 # define ao(type) offsetof (alignof_helper<type>, b) 31 # define ao(type) offsetof (alignof_helper<type>, b)
@@ -29,25 +36,103 @@ AC_DEFUN([gl_STDALIGN_H],
29 char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1]; 36 char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
30 char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1]; 37 char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];
31 38
32 /* Test _Alignas only on platforms where gnulib can help. */ 39 /* Test alignas only on platforms where gnulib can help. */
33 #if \ 40 #if \
34 ((defined __cplusplus && 201103 <= __cplusplus) \ 41 ((defined __cplusplus && 201103 <= __cplusplus) \
35 || __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC \ 42 || (__TINYC__ && defined __attribute__) \
36 || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER) 43 || (defined __APPLE__ && defined __MACH__ \
44 ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
45 : __GNUC__) \
46 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
47 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__ \
48 || 1300 <= _MSC_VER)
37 struct alignas_test { char c; char alignas (8) alignas_8; }; 49 struct alignas_test { char c; char alignas (8) alignas_8; };
38 char test_alignas[offsetof (struct alignas_test, alignas_8) == 8 50 char test_alignas[offsetof (struct alignas_test, alignas_8) == 8
39 ? 1 : -1]; 51 ? 1 : -1];
40 #endif 52 #endif
41 ]])], 53 ]])],
42 [gl_cv_header_working_stdalign_h=yes], 54 [gl_cv_header_working_stdalign_h=$gl_working],
43 [gl_cv_header_working_stdalign_h=no])]) 55 [gl_cv_header_working_stdalign_h=no])
56
57 CFLAGS=$gl_save_CFLAGS
58 test "$gl_cv_header_working_stdalign_h" != no && break
59 done])
60
61 GL_GENERATE_STDALIGN_H=false
62 AS_CASE([$gl_cv_header_working_stdalign_h],
63 [no],
64 [GL_GENERATE_STDALIGN_H=true],
65 [yes*keyword*],
66 [AC_DEFINE([HAVE_C_ALIGNASOF], [1],
67 [Define to 1 if the alignas and alignof keywords work.])])
44 68
45 if test $gl_cv_header_working_stdalign_h = yes; then 69 AC_CHECK_HEADERS_ONCE([stdalign.h])
46 STDALIGN_H=''
47 else
48 STDALIGN_H='stdalign.h'
49 fi
50 70
51 AC_SUBST([STDALIGN_H]) 71 dnl The "zz" puts this toward config.h's end, to avoid potential
52 AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"]) 72 dnl collisions with other definitions.
73 AH_VERBATIM([zzalignas],
74[#if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 && !defined alignof
75# if HAVE_STDALIGN_H
76# include <stdalign.h>
77# else
78 /* Substitute. Keep consistent with gnulib/lib/stdalign.in.h. */
79# ifndef _GL_STDALIGN_H
80# define _GL_STDALIGN_H
81# undef _Alignas
82# undef _Alignof
83# if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
84 || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
85 && !defined __clang__) \
86 || (defined __clang__ && __clang_major__ < 8))
87# ifdef __cplusplus
88# if (201103 <= __cplusplus || defined _MSC_VER)
89# define _Alignof(type) alignof (type)
90# else
91 template <class __t> struct __alignof_helper { char __a; __t __b; };
92# define _Alignof(type) offsetof (__alignof_helper<type>, __b)
93# define _GL_STDALIGN_NEEDS_STDDEF 1
94# endif
95# else
96# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
97# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
98# else
99# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
100# define _GL_STDALIGN_NEEDS_STDDEF 1
101# endif
102# endif
103# endif
104# if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
105# define alignof _Alignof
106# endif
107# define __alignof_is_defined 1
108# if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
109# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)
110# define _Alignas(a) alignas (a)
111# elif (!defined __attribute__ \
112 && ((defined __APPLE__ && defined __MACH__ \
113 ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
114 : __GNUC__ && !defined __ibmxl__) \
115 || (4 <= __clang_major__) \
116 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
117 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
118# define _Alignas(a) __attribute__ ((__aligned__ (a)))
119# elif 1300 <= _MSC_VER
120# define _Alignas(a) __declspec (align (a))
121# endif
122# endif
123# if ((defined _Alignas \
124 && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \
125 || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
126# define alignas _Alignas
127# endif
128# if (defined alignas \
129 || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)))
130# define __alignas_is_defined 1
131# endif
132# if _GL_STDALIGN_NEEDS_STDDEF
133# include <stddef.h>
134# endif
135# endif /* _GL_STDALIGN_H */
136# endif
137#endif])
53]) 138])