# HG changeset patch # User Paul Eggert # Date 1318809503 25200 # Node ID d3ffa7ff0caf67816afe7287a8b27e47179e1d02 # Parent f0478fc67be5349dd3122df24c0854d063ac6d1a stdalign-tests: new module * modules/stdalign-tests, tests/test-stdalign.c: New files. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ * MODULES.html.sh (c1x_core_properties): Add stdalign. * doc/gnulib.texi (Header File Substitutes): Add stdalign. + stdalign-tests: new module + * modules/stdalign-tests, tests/test-stdalign.c: New files. + 2011-10-27 Bruno Haible raise test: Avoid a test failure on Linux/MIPS. diff --git a/modules/stdalign-tests b/modules/stdalign-tests new file mode 100644 --- /dev/null +++ b/modules/stdalign-tests @@ -0,0 +1,12 @@ +Files: +tests/test-stdalign.c + +Depends-on: +verify +stdint + +configure.ac: + +Makefile.am: +TESTS += test-stdalign +check_PROGRAMS += test-stdalign diff --git a/tests/test-stdalign.c b/tests/test-stdalign.c new file mode 100644 --- /dev/null +++ b/tests/test-stdalign.c @@ -0,0 +1,77 @@ +/* Test of . + Copyright 2009-2011 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 + +#include "verify.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; + +verify (__alignof_is_defined == 1); +#ifndef alignof +# error "alignof is not a macro" +#endif + +#if __alignas_is_defined +verify (__alignas_is_defined == 1); +# ifndef alignas +# error "alignas is not a macro" +# endif +# define CHECK_ALIGNAS(type) \ + type alignas (1 << 3) type##_alignas; \ + type _Alignas (1 << 3) type##_Alignas; +#else +# define CHECK_ALIGNAS(type) +#endif + +#define CHECK(type) \ + typedef struct { char slot1; type slot2; } type##_helper; \ + verify (alignof (type) == offsetof (type##_helper, slot2)); \ + verify (_Alignof (type) == alignof (type)); \ + const int type##_alignment = alignof (type); \ + CHECK_ALIGNAS(type) + +CHECK (char) +CHECK (short) +CHECK (int) +CHECK (long) +CHECK (float) +CHECK (double) +CHECK (longdouble) +#ifdef INT64_MAX +CHECK (int64_t) +#endif +CHECK (struct1) +CHECK (struct2) +CHECK (struct3) +CHECK (struct4) + +int +main () +{ + return 0; +}