Debian Codegraph @

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