From 7f105648709691ee56bc59dbb2f5cf0a367f9b50 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 18 Jan 2025 22:06:55 -0800 Subject: [PATCH] alignasof: port to IBM XL C 16.1 * doc/gnulib.texi (alignof): Improve doc to match implementation 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 | 7 +++---- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 862f154fa8..55e4b6db66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2025-01-18 Paul Eggert + + alignasof: port to IBM XL C 16.1 + * doc/gnulib.texi (alignof): + Improve doc to match implementation 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 renameatu: Work around a GNU/Hurd bug. diff --git a/doc/gnulib.texi b/doc/gnulib.texi index b6ce2c653d..d9b6640ad2 100644 --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -940,9 +940,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{} must be included before using @code{alignas} or @code{alignof}. @@ -951,6 +948,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 07599cc6da..2d11e08089 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, @@ -180,7 +180,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 12f6956664..b0c74f848f 100644 --- a/tests/test-alignasof.c +++ b/tests/test-alignasof.c @@ -1,5 +1,5 @@ /* Test of alignasof module. - Copyright 2009-2024 Free Software Foundation, Inc. + Copyright 2009-2025 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -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.39.5