* doc/gnulib.texi (alignof): Improve doc to match implementationa better. * m4/stdalign.m4 (alignas): Do not define to _Alignas if __xlC__ claims to conform to C11, because _Alignas fails with weird diagnostics "Unexpected text %1$s encountered." * tests/test-alignasof.c (TEST_ALIGNMENT, alignas): Follow doc advice. --- ChangeLog | 11 +++++++++++ doc/gnulib.texi | 23 ++++++++++++++++++++--- m4/stdalign.m4 | 5 +++-- tests/test-alignasof.c | 5 ++--- 4 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 283f98849d..a2495cc31a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2025-01-18 Paul Eggert <egg...@cs.ucla.edu> + + alignasof: port to IBM XL C 16.1 + * doc/gnulib.texi (alignof): + Improve doc to match implementationa better. + * m4/stdalign.m4 (alignas): Do not define to _Alignas + if __xlC__ claims to conform to C11, because _Alignas fails with + weird diagnostics "Unexpected text %1$s encountered." + * tests/test-alignasof.c (TEST_ALIGNMENT, alignas): + Follow doc advice. + 2025-01-18 Collin Funk <collin.fu...@gmail.com> renameatu: Work around a GNU/Hurd bug. diff --git a/doc/gnulib.texi b/doc/gnulib.texi index 81f8399d59..5eed50d4e0 100644 --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -970,9 +970,6 @@ to be more like standard C@. Portability problems fixed by Gnulib: @itemize -@item -Pre-C11 platforms lack @code{alignas} and @code{alignof}. - @item On pre-C23 platforms, @code{<stdalign.h>} must be included before using @code{alignas} or @code{alignof}. @@ -981,6 +978,26 @@ using @code{alignas} or @code{alignof}. Portability problems not fixed by Gnulib: @itemize +@item +The set of alignments supported by @code{alignas} is implementation +dependent, and implementations need not support alignments greater +than @code{alignof (max_align_t)}. + +@item +Some older platforms do not support @code{alignas}. +To test this, use the @code{alignasof} module +along with the @code{#if} conditional +@code{(defined alignas || defined __alignas_is_defined +|| 202311 <= __STDC_VERSION__ || 201103 <= __cplusplus)}. +Platforms where @code{alignas} does not work include: +IBM XL C for AIX V16.1. + +@item +On some platforms, the argument of @code{alignas} must be an integer +constant like @samp{8}, instead of an integer constant expression +like @samp{4 + 4} that evaluates to 8: +GCC 4.9. + @item On pre-C23 platforms, @code{alignas} and @code{alignof} are macros. @end itemize diff --git a/m4/stdalign.m4 b/m4/stdalign.m4 index bd4ec12e89..885feafdd8 100644 --- a/m4/stdalign.m4 +++ b/m4/stdalign.m4 @@ -1,5 +1,5 @@ # stdalign.m4 -# serial 2 +# serial 3 dnl Copyright 2011-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -181,7 +181,8 @@ AC_DEFUN([gl_ALIGNASOF], # if ((defined _Alignas \ && !(defined __cplusplus \ && (201103 <= __cplusplus || defined _MSC_VER))) \ - || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) + || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__ \ + && !defined __xlC__)) # define alignas _Alignas # endif # endif diff --git a/tests/test-alignasof.c b/tests/test-alignasof.c index 638b4be281..b0c74f848f 100644 --- a/tests/test-alignasof.c +++ b/tests/test-alignasof.c @@ -29,13 +29,12 @@ typedef struct { char a[2]; } struct2; typedef struct { char a[3]; } struct3; typedef struct { char a[4]; } struct4; -#if (202311 <= __STDC_VERSION__ || __alignas_is_defined \ - || 201103 <= __cplusplus) +#if (defined alignas || __alignas_is_defined \ + || 202311 <= __STDC_VERSION__ || 201103 <= __cplusplus) /* mingw can go up only to 8. 8 is all that GNU Emacs needs, so let's limit the test to 8 for now. */ # define TEST_ALIGNMENT 8 #else -# undef alignas # define alignas(alignment) # define TEST_ALIGNMENT 1 #endif -- 2.45.2