>From 1f4fe409ea4379c3e537507822151e135be758d8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 24 Jan 2023 13:36:11 +0100 Subject: [PATCH] stdalign: Fix a compilation error on FreeBSD 12.0. * lib/stdalign.in.h (_Alignof): In C mode, prefer __builtin_offsetof over offsetof when possible, since __builtin_offsetof works also when has not been fully included yet. * m4/stdalign.m4 (gl_STDALIGN_H): Likewise. --- ChangeLog | 8 ++++++++ lib/stdalign.in.h | 8 ++++++-- m4/stdalign.m4 | 8 ++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca8306d1e4..bd7fd9ab5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-01-24 Bruno Haible + + stdalign: Fix a compilation error on FreeBSD 12.0. + * lib/stdalign.in.h (_Alignof): In C mode, prefer __builtin_offsetof + over offsetof when possible, since __builtin_offsetof works also when + has not been fully included yet. + * m4/stdalign.m4 (gl_STDALIGN_H): Likewise. + 2023-01-22 Paul Eggert sigsegv, vma-iter: port to Solaris 10 diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h index 17357810c7..7f9dbb466e 100644 --- a/lib/stdalign.in.h +++ b/lib/stdalign.in.h @@ -66,8 +66,12 @@ # define _GL_STDALIGN_NEEDS_STDDEF 1 # endif # else -# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) -# define _GL_STDALIGN_NEEDS_STDDEF 1 +# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__ +# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b) +# else +# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) +# define _GL_STDALIGN_NEEDS_STDDEF 1 +# endif # endif #endif #if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)) diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 index b1438eeace..dc2971753d 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -93,8 +93,12 @@ AC_DEFUN([gl_STDALIGN_H], # define _GL_STDALIGN_NEEDS_STDDEF 1 # endif # else -# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) -# define _GL_STDALIGN_NEEDS_STDDEF 1 +# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__ +# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b) +# else +# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) +# define _GL_STDALIGN_NEEDS_STDDEF 1 +# endif # endif # endif # if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)) -- 2.34.1