]> Savannah Git Hosting - gnulib.git/commitdiff
stdalign-tests: new module
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 16 Oct 2011 23:58:23 +0000 (16:58 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Oct 2011 20:05:42 +0000 (13:05 -0700)
* modules/stdalign-tests, tests/test-stdalign.c: New files.

ChangeLog
modules/stdalign-tests [new file with mode: 0644]
tests/test-stdalign.c [new file with mode: 0644]

index 9fa90a7049253a018cd136d9031db712e5b3191c..7b607346eef1d9ac6a4e148571cd80c8884b167b 100644 (file)
--- 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  <bruno@clisp.org>
 
        raise test: Avoid a test failure on Linux/MIPS.
diff --git a/modules/stdalign-tests b/modules/stdalign-tests
new file mode 100644 (file)
index 0000000..44382bf
--- /dev/null
@@ -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 (file)
index 0000000..136661a
--- /dev/null
@@ -0,0 +1,77 @@
+/* Test of <stdalign.h>.
+   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 <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert, inspired by Bruno Haible's test-alignof.c.  */
+
+#include <config.h>
+
+#include <stdalign.h>
+
+#include <stddef.h>
+#include <stdint.h>
+
+#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;
+}