From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: stddef: Fix test-stddef compilation error on FreeBSD 12/x86
Date: Fri, 27 Jan 2023 20:47:22 +0100 [thread overview]
Message-ID: <2511333.SWmJFuOJt8@nimes> (raw)
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];
reply other threads:[~2023-01-27 19:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2511333.SWmJFuOJt8@nimes \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).