From: Bruno Haible Date: Sat, 21 Jan 2023 09:07:19 +0000 (+0100) Subject: alignasof tests: Rename test file. X-Git-Tag: v1.0~1794 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f44111b0ab75dc5f6fcd7fafebe56177b464727e;p=gnulib.git alignasof tests: Rename test file. * tests/test-alignasof.c: Renamed from tests/test-stdalign.c. * modules/alignasof-tests (Files, Makefile.am): Update accordingly. --- diff --git a/ChangeLog b/ChangeLog index ac0509b30f..1de0058d5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-01-21 Bruno Haible + + alignasof tests: Rename test file. + * tests/test-alignasof.c: Renamed from tests/test-stdalign.c. + * modules/alignasof-tests (Files, Makefile.am): Update accordingly. + 2023-01-21 Bruno Haible alignasof tests: Fix GCC warning (regression 2023-01-15). diff --git a/modules/alignasof-tests b/modules/alignasof-tests index 95602c2fef..35bef17b99 100644 --- a/modules/alignasof-tests +++ b/modules/alignasof-tests @@ -1,5 +1,5 @@ Files: -tests/test-stdalign.c +tests/test-alignasof.c tests/macros.h Depends-on: @@ -9,5 +9,5 @@ stdint configure.ac: Makefile.am: -TESTS += test-stdalign -check_PROGRAMS += test-stdalign +TESTS += test-alignasof +check_PROGRAMS += test-alignasof diff --git a/tests/test-alignasof.c b/tests/test-alignasof.c new file mode 100644 index 0000000000..18c0d48866 --- /dev/null +++ b/tests/test-alignasof.c @@ -0,0 +1,100 @@ +/* Test of alignasof module. + Copyright 2009-2023 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert, inspired by Bruno Haible's test-alignof.c. */ + +#include + +#include +#include + +#include "macros.h" + +typedef long double longdouble; +typedef struct { char a[1]; } struct1; +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) +/* 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 + +#define CHECK_STATIC(type) \ + typedef struct { char slot1; type slot2; } type##_helper; \ + static_assert (alignof (type) == offsetof (type##_helper, slot2)); \ + const int type##_alignment = alignof (type); \ + type alignas (TEST_ALIGNMENT) static_##type##_alignas + +#define CHECK_ALIGNED(var) ASSERT ((uintptr_t) &(var) % TEST_ALIGNMENT == 0) + +CHECK_STATIC (char); +CHECK_STATIC (short); +CHECK_STATIC (int); +CHECK_STATIC (long); +#ifdef INT64_MAX +CHECK_STATIC (int64_t); +#endif +CHECK_STATIC (float); +CHECK_STATIC (double); +/* CHECK_STATIC (longdouble); */ +CHECK_STATIC (struct1); +CHECK_STATIC (struct2); +CHECK_STATIC (struct3); +CHECK_STATIC (struct4); + +int +main () +{ +#if defined __SUNPRO_C && __SUNPRO_C < 0x5150 + /* Avoid a test failure due to Sun Studio Developer Bug Report #2125432. */ + fputs ("Skipping test: known Sun C compiler bug\n", stderr); + return 77; +#elif defined __HP_cc && __ia64 + /* Avoid a test failure due to HP-UX Itanium cc bug; see: + https://lists.gnu.org/r/bug-gnulib/2017-03/msg00078.html */ + fputs ("Skipping test: known HP-UX Itanium cc compiler bug\n", stderr); + return 77; +#elif defined __clang__ && defined __ibmxl__ + /* Avoid a test failure with IBM xlc 16.1. It ignores alignas (8), + _Alignas (8), and __attribute__ ((__aligned__ (8))). */ + fputs ("Skipping test: known AIX XL C compiler deficiency\n", stderr); + return 77; +#else + CHECK_ALIGNED (static_char_alignas); + CHECK_ALIGNED (static_short_alignas); + CHECK_ALIGNED (static_int_alignas); + CHECK_ALIGNED (static_long_alignas); +# ifdef INT64_MAX + CHECK_ALIGNED (static_int64_t_alignas); +# endif + CHECK_ALIGNED (static_float_alignas); + CHECK_ALIGNED (static_double_alignas); + /* CHECK_ALIGNED (static_longdouble_alignas); */ + CHECK_ALIGNED (static_struct1_alignas); + CHECK_ALIGNED (static_struct2_alignas); + CHECK_ALIGNED (static_struct3_alignas); + CHECK_ALIGNED (static_struct4_alignas); + return 0; +#endif +} diff --git a/tests/test-stdalign.c b/tests/test-stdalign.c deleted file mode 100644 index 85008e62e4..0000000000 --- a/tests/test-stdalign.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Test of . - Copyright 2009-2023 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* Written by Paul Eggert, inspired by Bruno Haible's test-alignof.c. */ - -#include - -#include -#include - -#include "macros.h" - -typedef long double longdouble; -typedef struct { char a[1]; } struct1; -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) -/* 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 - -#define CHECK_STATIC(type) \ - typedef struct { char slot1; type slot2; } type##_helper; \ - static_assert (alignof (type) == offsetof (type##_helper, slot2)); \ - const int type##_alignment = alignof (type); \ - type alignas (TEST_ALIGNMENT) static_##type##_alignas - -#define CHECK_ALIGNED(var) ASSERT ((uintptr_t) &(var) % TEST_ALIGNMENT == 0) - -CHECK_STATIC (char); -CHECK_STATIC (short); -CHECK_STATIC (int); -CHECK_STATIC (long); -#ifdef INT64_MAX -CHECK_STATIC (int64_t); -#endif -CHECK_STATIC (float); -CHECK_STATIC (double); -/* CHECK_STATIC (longdouble); */ -CHECK_STATIC (struct1); -CHECK_STATIC (struct2); -CHECK_STATIC (struct3); -CHECK_STATIC (struct4); - -int -main () -{ -#if defined __SUNPRO_C && __SUNPRO_C < 0x5150 - /* Avoid a test failure due to Sun Studio Developer Bug Report #2125432. */ - fputs ("Skipping test: known Sun C compiler bug\n", stderr); - return 77; -#elif defined __HP_cc && __ia64 - /* Avoid a test failure due to HP-UX Itanium cc bug; see: - https://lists.gnu.org/r/bug-gnulib/2017-03/msg00078.html */ - fputs ("Skipping test: known HP-UX Itanium cc compiler bug\n", stderr); - return 77; -#elif defined __clang__ && defined __ibmxl__ - /* Avoid a test failure with IBM xlc 16.1. It ignores alignas (8), - _Alignas (8), and __attribute__ ((__aligned__ (8))). */ - fputs ("Skipping test: known AIX XL C compiler deficiency\n", stderr); - return 77; -#else - CHECK_ALIGNED (static_char_alignas); - CHECK_ALIGNED (static_short_alignas); - CHECK_ALIGNED (static_int_alignas); - CHECK_ALIGNED (static_long_alignas); -# ifdef INT64_MAX - CHECK_ALIGNED (static_int64_t_alignas); -# endif - CHECK_ALIGNED (static_float_alignas); - CHECK_ALIGNED (static_double_alignas); - /* CHECK_ALIGNED (static_longdouble_alignas); */ - CHECK_ALIGNED (static_struct1_alignas); - CHECK_ALIGNED (static_struct2_alignas); - CHECK_ALIGNED (static_struct3_alignas); - CHECK_ALIGNED (static_struct4_alignas); - return 0; -#endif -}