bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stddef: override max_align_t on NetBSD 8.0/x86


From: Bruno Haible
Subject: stddef: override max_align_t on NetBSD 8.0/x86
Date: Thu, 06 Sep 2018 22:44:47 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-134-generic; KDE/5.18.0; x86_64; ; )

On NetBSD 8.0/x86 I'm seeing this compilation failure:

In file included from ../../gltests/test-stddef.c:24:0:
../../gltests/../gllib/verify.h:207:21: error: static assertion failed: "verify 
(__alignof__ (double) <= __alignof__ (max_align_t))"
 # define _GL_VERIFY _Static_assert
                     ^
../../gltests/../gllib/verify.h:252:20: note: in expansion of macro '_GL_VERIFY'
 # define verify(R) _GL_VERIFY (R, "verify (" #R ")")
                    ^
../../gltests/test-stddef.c:63:1: note: in expansion of macro 'verify'
 verify (__alignof__ (double) <= __alignof__ (max_align_t));
 ^
Makefile:8514: recipe for target 'test-stddef.o' failed


The reason is that NetBSD 8.0 defines max_align_t, but they do so
without using the GCC built-in __alignof__. Hence, the "alignment
for optimization" that GCC knows about is not large enough. I refer
to Paul's explanations in
<https://sourceware.org/ml/libc-alpha/2015-04/msg00026.html>
<https://lists.gnu.org/archive/html/bug-gnulib/2015-04/msg00006.html>

This patch fixes it.


2018-09-06  Bruno Haible  <address@hidden>

        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.

diff --git a/doc/posix-headers/stddef.texi b/doc/posix-headers/stddef.texi
index f5b6696..a27b597 100644
--- a/doc/posix-headers/stddef.texi
+++ b/doc/posix-headers/stddef.texi
@@ -12,6 +12,10 @@ Some platforms fail to provide @code{max_align_t}, which was 
added in C11:
 Solaris 11.0 and others.
 
 @item
address@hidden does not have the expected alignment on some platforms:
+NetBSD 8.0/x86.
+
address@hidden
 Some old platforms fail to provide @code{wchar_t}.
 
 @item
diff --git a/m4/stddef_h.m4 b/m4/stddef_h.m4
index ba3d201..07b040a 100644
--- a/m4/stddef_h.m4
+++ b/m4/stddef_h.m4
@@ -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_DEFUN([gl_STDDEF_H],
   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 @@ AC_DEFUN([gl_STDDEF_H],
     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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]