changeset 39826:4bc6c3133bdd

stddef: Override max_align_t on NetBSD 8.0/x86. * m4/stddef_h.m4 (gl_STDDEF_H): When testing for max_align_t, test also the value of __alignof__ (max_align_t). * doc/posix-headers/stddef.texi: Mention the issue.
author Bruno Haible <bruno@clisp.org>
date Thu, 06 Sep 2018 22:44:01 +0200
parents b07bc729e806
children 96fe1f932130
files ChangeLog doc/posix-headers/stddef.texi m4/stddef_h.m4
diffstat 3 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Sep 06 18:36:02 2018 +0200
+++ b/ChangeLog	Thu Sep 06 22:44:01 2018 +0200
@@ -1,3 +1,10 @@
+2018-09-06  Bruno Haible  <bruno@clisp.org>
+
+	stddef: Override max_align_t on NetBSD 8.0/x86.
+	* m4/stddef_h.m4 (gl_STDDEF_H): When testing for max_align_t, test also
+	the value of __alignof__ (max_align_t).
+	* doc/posix-headers/stddef.texi: Mention the issue.
+
 2018-09-06  Bruno Haible  <bruno@clisp.org>
 
 	fcntl: Fix F_DUPFD_CLOEXEC behaviour on Haiku.
--- a/doc/posix-headers/stddef.texi	Thu Sep 06 18:36:02 2018 +0200
+++ b/doc/posix-headers/stddef.texi	Thu Sep 06 22:44:01 2018 +0200
@@ -12,6 +12,10 @@
 Solaris 11.0 and others.
 
 @item
+@code{max_align_t} does not have the expected alignment on some platforms:
+NetBSD 8.0/x86.
+
+@item
 Some old platforms fail to provide @code{wchar_t}.
 
 @item
--- a/m4/stddef_h.m4	Thu Sep 06 18:36:02 2018 +0200
+++ b/m4/stddef_h.m4	Thu Sep 06 22:44:01 2018 +0200
@@ -1,5 +1,5 @@
 dnl A placeholder for <stddef.h>, for platforms that have issues.
-# stddef_h.m4 serial 5
+# stddef_h.m4 serial 6
 dnl Copyright (C) 2009-2018 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,13 +10,33 @@
   AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
   AC_REQUIRE([gt_TYPE_WCHAR_T])
   STDDEF_H=
-  AC_CHECK_TYPE([max_align_t], [], [HAVE_MAX_ALIGN_T=0; STDDEF_H=stddef.h],
-    [[#include <stddef.h>
-    ]])
+
+  dnl Test whether the type max_align_t exists and whether its alignment
+  dnl "is as great as is supported by the implementation in all contexts".
+  AC_CACHE_CHECK([for good max_align_t],
+    [gl_cv_type_max_align_t],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <stddef.h>
+            unsigned int s = sizeof (max_align_t);
+            #if defined __GNUC__ || defined __IBM__ALIGNOF__
+            int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
+            int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1];
+            #endif
+          ]])],
+       [gl_cv_type_max_align_t=yes],
+       [gl_cv_type_max_align_t=no])
+    ])
+  if test $gl_cv_type_max_align_t = no; then
+    HAVE_MAX_ALIGN_T=0
+    STDDEF_H=stddef.h
+  fi
+
   if test $gt_cv_c_wchar_t = no; then
     HAVE_WCHAR_T=0
     STDDEF_H=stddef.h
   fi
+
   AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions],
     [gl_cv_decl_null_works],
     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
@@ -28,6 +48,7 @@
     REPLACE_NULL=1
     STDDEF_H=stddef.h
   fi
+
   AC_SUBST([STDDEF_H])
   AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"])
   if test -n "$STDDEF_H"; then