* stddef: Fix test-stddef compilation error on FreeBSD 12/x86
@ 2023-01-27 19:47 Bruno Haible
0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2023-01-27 19:47 UTC (permalink / raw)
To: bug-gnulib
On FreeBSD 12.0/x86, on the stable-202301 branch, I'm seeing this compilation
error:
../../gltests/test-stddef.c:62:1: error: static_assert failed "static assertion failed"
static_assert (__alignof__ (double) <= __alignof__ (max_align_t));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/assert.h:73:23: note: expanded from macro 'static_assert'
#define static_assert _Static_assert
^
../gllib/assert.h:256:7: note: expanded from macro '_Static_assert'
_GL_STATIC_ASSERT (__VA_ARGS__, "static assertion failed", -)
^ ~~~~~~~~~~~
../gllib/assert.h:241:48: note: expanded from macro '_GL_STATIC_ASSERT'
# define _GL_STATIC_ASSERT(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC)
^ ~
1 error generated.
What happens is that the fix for a wrong _Alignof that we have in the
stdalign / alignasof module causes max_align_t to have too small alignment.
| original | ISO C compliant |
| _Alignof | _Alignof |
--------------+--------------+-------------------+
long long | 8 | 4 |
--------------+--------------+-------------------+
double | 8 | 4 |
--------------+--------------+-------------------+
long double | 4 | 4 |
--------------+--------------+-------------------+
max_align_t being defined through _Alignof(long long) and _Alignof(long double),
it alignment shrinks from 8 to 4, and thus
__alignof__ (double) <= __alignof__ (max_align_t)
is no longer fulfilled.
This patch fixes it: the configure test "checking for good max_align_t..."
now reports no instead of yes, and max_align_t gets overridden.
2023-01-27 Bruno Haible <bruno@clisp.org>
stddef: Fix test-stddef compilation error on FreeBSD 12/x86.
* m4/stddef_h.m4 (gl_STDDEF_H): When testing for good max_align_t, use
an ISO C compliant definition of _Alignof.
diff --git a/m4/stddef_h.m4 b/m4/stddef_h.m4
index c0553d6f2f..a2322ebb7e 100644
--- a/m4/stddef_h.m4
+++ b/m4/stddef_h.m4
@@ -1,4 +1,4 @@
-# stddef_h.m4 serial 12
+# stddef_h.m4 serial 13
dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -22,7 +22,14 @@ AC_DEFUN_ONCE([gl_STDDEF_H],
[gl_cv_type_max_align_t],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
- [[#include <stddef.h>
+ [[/* On FreeBSD 12.0/x86, max_align_t defined by <stddef.h> has
+ the correct alignment with the default (wrong) definition of
+ _Alignof, but a wrong alignment as soon as we activate an
+ ISO C compliant _Alignof definition. */
+ #if ((defined __GNUC__ && 4 <= __GNUC__) || defined __clang__) && !defined __cplusplus
+ #define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
+ #endif
+ #include <stddef.h>
unsigned int s = sizeof (max_align_t);
#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-27 19:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 19:47 stddef: Fix test-stddef compilation error on FreeBSD 12/x86 Bruno Haible
Code repositories for project(s) associated with this public inbox
https://public-inbox.org/mirrors/gnulib.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).