[Top][All Lists]

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

stddef: Fix test-stddef compilation error on MidnightBSD/x86

From: Bruno Haible
Subject: stddef: Fix test-stddef compilation error on MidnightBSD/x86
Date: Mon, 08 Feb 2021 23:26:00 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

On MidnightBSD 2.0/x86, test-stddef fails to compile when CC=cc is used
(but not with CC=gcc7):

../../gltests/test-stddef.c:63:1: error: static_assert failed due to 
requirement '__alignof(double) <= __alignof(__max_align_t)' "verify 
(__alignof__ (double) <= __alignof__ (max_align_t))"
verify (__alignof__ (double) <= __alignof__ (max_align_t));
^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The reason is that max_align_t is defined with alignment 4. This program

#include <stddef.h>
#include <sys/types.h>
#include <stdio.h>
int main ()
  printf ("%d %d %d\n", _Alignof (double), _Alignof (long long), _Alignof 
  printf ("%d %d %d\n", __alignof (double), __alignof (long long), __alignof 
  printf ("%d %d %d\n", __alignof__ (double), __alignof__ (long long), 
__alignof__ (max_align_t));

4 4 4
8 8 4
8 8 4

(both when compiled as a C program and as a C++ program).

The configure test detects this and sets HAVE_MAX_ALIGN_T=0.

So, the hack that motivated the test of _GCC_MAX_ALIGN_T (see
is not needed with clang. This patch fixes the issue.

2021-02-08  Bruno Haible  <bruno@clisp.org>

        stddef: Fix test-stddef compilation error on MidnightBSD/x86.
        * lib/stddef.in.h (_GL_STDDEF_ALIGNAS, rpl_max_align_t, max_align_t):
        Don't ignore HAVE_MAX_ALIGN_T if the compiler is clang.

diff --git a/lib/stddef.in.h b/lib/stddef.in.h
index 5d3e087..6385892 100644
--- a/lib/stddef.in.h
+++ b/lib/stddef.in.h
@@ -109,7 +109,7 @@ typedef long max_align_t;
     && defined __cplusplus
 # include <cstddef>
-# if ! (@HAVE_MAX_ALIGN_T@ || defined _GCC_MAX_ALIGN_T)
+# if ! (@HAVE_MAX_ALIGN_T@ || (defined _GCC_MAX_ALIGN_T && !defined __clang__))
 #  if !GNULIB_defined_max_align_t
 /* On the x86, the maximum storage alignment of double, long, etc. is 4,
    but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,

reply via email to

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