Debian Codegraph @

m4/stddef_h.m4

raw
1 # stddef_h.m4
2 # serial 17
3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl A placeholder for <stddef.h>, for platforms that have issues.
10
11 AC_DEFUN_ONCE([gl_STDDEF_H],
12 [
13 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
14
15 dnl Persuade OpenBSD <stddef.h> to declare max_align_t.
16 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17
18 GL_GENERATE_STDDEF_H=false
19
20 dnl Test whether the type max_align_t exists and whether its alignment
21 dnl "is as great as is supported by the implementation in all contexts".
22 AC_CACHE_CHECK([for good max_align_t],
23 [gl_cv_type_max_align_t],
24 [AC_COMPILE_IFELSE(
25 [AC_LANG_PROGRAM(
26 [[/* On FreeBSD 12.0/x86, max_align_t defined by <stddef.h> has
27 the correct alignment with the default (wrong) definition of
28 _Alignof, but a wrong alignment as soon as we activate an
29 ISO C compliant _Alignof definition. */
30 #if ((defined __GNUC__ && 4 <= __GNUC__) || defined __clang__) && !defined __cplusplus
31 #define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
32 #endif
33 #include <stddef.h>
34 unsigned int s = sizeof (max_align_t);
35 #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
36 int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
37 int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1];
38 #endif
39 typedef struct { char a; max_align_t b; } max_helper;
40 typedef struct { char a; long b; } long_helper;
41 typedef struct { char a; double b; } double_helper;
42 typedef struct { char a; long double b; } long_double_helper;
43 int check3[2 * (offsetof (long_helper, b) <= offsetof (max_helper, b)) - 1];
44 int check4[2 * (offsetof (double_helper, b) <= offsetof (max_helper, b)) - 1];
45 int check5[2 * (offsetof (long_double_helper, b) <= offsetof (max_helper, b)) - 1];
46 ]])],
47 [gl_cv_type_max_align_t=yes],
48 [gl_cv_type_max_align_t=no])
49 ])
50 if test $gl_cv_type_max_align_t = no; then
51 HAVE_MAX_ALIGN_T=0
52 GL_GENERATE_STDDEF_H=true
53 fi
54
55 AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions],
56 [gl_cv_decl_null_works],
57 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
58 int test[2 * (sizeof NULL == sizeof (void *)) -1];
59 ]])],
60 [gl_cv_decl_null_works=yes],
61 [gl_cv_decl_null_works=no])])
62 if test $gl_cv_decl_null_works = no; then
63 REPLACE_NULL=1
64 GL_GENERATE_STDDEF_H=true
65 fi
66
67 AC_CACHE_CHECK([for unreachable],
68 [gl_cv_func_unreachable],
69 [AC_LINK_IFELSE(
70 [AC_LANG_PROGRAM(
71 [[#include <stddef.h>
72 ]],
73 [[unreachable ();
74 ]])],
75 [gl_cv_func_unreachable=yes],
76 [gl_cv_func_unreachable=no])
77 ])
78 if test $gl_cv_func_unreachable = no; then
79 GL_GENERATE_STDDEF_H=true
80 fi
81
82 dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114869
83 AC_CACHE_CHECK([whether nullptr_t needs <stddef.h>],
84 [gl_cv_nullptr_t_needs_stddef],
85 [AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[nullptr_t x;]],
86 [gl_cv_nullptr_t_needs_stddef=no],
87 [gl_cv_nullptr_t_needs_stddef=yes])])
88 if test "$gl_cv_nullptr_t_needs_stddef" = no; then
89 NULLPTR_T_NEEDS_STDDEF=0
90 GL_GENERATE_STDDEF_H=true
91 fi
92
93 AC_CACHE_CHECK([for clean definition of __STDC_VERSION_STDDEF_H__],
94 [gl_cv_clean_version_stddef],
95 [AC_PREPROC_IFELSE(
96 [AC_LANG_SOURCE(
97 [[/* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870 */
98 #include <stddef.h>
99 #undef __STDC_VERSION_STDDEF_H__
100 #include <time.h>
101 #ifdef __STDC_VERSION_STDDEF_H__
102 # error "<time.h> defines __STDC_VERSION_STDDEF_H__"
103 #endif
104 ]])],
105 [gl_cv_clean_version_stddef=yes],
106 [gl_cv_clean_version_stddef=no])])
107 if test "$gl_cv_clean_version_stddef" = no; then
108 STDDEF_NOT_IDEMPOTENT=1
109 GL_GENERATE_STDDEF_H=true
110 fi
111
112 if $GL_GENERATE_STDDEF_H; then
113 gl_NEXT_HEADERS([stddef.h])
114 fi
115 ])
116
117 # gl_STDDEF_MODULE_INDICATOR([modulename])
118 # sets the shell variable that indicates the presence of the given module
119 # to a C preprocessor expression that will evaluate to 1.
120 # This macro invocation must not occur in macros that are AC_REQUIREd.
121 AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
122 [
123 dnl Ensure to expand the default settings once only.
124 gl_STDDEF_H_REQUIRE_DEFAULTS
125 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
126 ])
127
128 # Initializes the default values for AC_SUBSTed shell variables.
129 # This macro must not be AC_REQUIREd. It must only be invoked, and only
130 # outside of macros or in macros that are not AC_REQUIREd.
131 AC_DEFUN([gl_STDDEF_H_REQUIRE_DEFAULTS],
132 [
133 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS], [
134 ])
135 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS])
136 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
137 ])
138
139 AC_DEFUN([gl_STDDEF_H_DEFAULTS],
140 [
141 dnl Assume proper GNU behavior unless another module says otherwise.
142 NULLPTR_T_NEEDS_STDDEF=1; AC_SUBST([NULLPTR_T_NEEDS_STDDEF])
143 STDDEF_NOT_IDEMPOTENT=0; AC_SUBST([STDDEF_NOT_IDEMPOTENT])
144 REPLACE_NULL=0; AC_SUBST([REPLACE_NULL])
145 HAVE_MAX_ALIGN_T=1; AC_SUBST([HAVE_MAX_ALIGN_T])
146 ])