summaryrefslogtreecommitdiff
path: root/gl
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2011-11-08 21:20:07 +0100
committerSimon Josefsson <simon@josefsson.org>2011-11-08 21:31:47 +0100
commit89c3301101f3bc1b16351f0965436a4e0ecfc771 (patch)
treecd6bf9ea07a32d0b92312cb565d0572f2f39000d /gl
parenta171181a4c1a39954a0868c2f77973ef4f8a360e (diff)
downloadgnutls-89c3301101f3bc1b16351f0965436a4e0ecfc771.tar.gz
Update gnulib files.
Diffstat (limited to 'gl')
-rw-r--r--gl/Makefile.am39
-rw-r--r--gl/alignof.h53
-rw-r--r--gl/argp-parse.c2
-rw-r--r--gl/closedir.c4
-rw-r--r--gl/m4/gnulib-comp.m48
-rw-r--r--gl/m4/math_h.m413
-rw-r--r--gl/m4/stdalign.m422
-rw-r--r--gl/math.in.h74
-rw-r--r--gl/stdalign.in.h89
-rw-r--r--gl/stdlib.in.h2
-rw-r--r--gl/sys_socket.in.h2
-rw-r--r--gl/tests/Makefile.am8
-rw-r--r--gl/tests/putenv.c2
-rw-r--r--gl/tests/test-stdalign.c116
14 files changed, 366 insertions, 68 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am
index a4548c199a..320b2c0d89 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -67,13 +67,6 @@ EXTRA_libgnu_la_SOURCES += accept.c
## end gnulib module accept
-## begin gnulib module alignof
-
-
-EXTRA_DIST += alignof.h
-
-## end gnulib module alignof
-
## begin gnulib module alloca
@@ -713,6 +706,9 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
-e 's/@''GNULIB_FLOOR''@/$(GNULIB_FLOOR)/g' \
-e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \
-e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \
+ -e 's/@''GNULIB_FMA''@/$(GNULIB_FMA)/g' \
+ -e 's/@''GNULIB_FMAF''@/$(GNULIB_FMAF)/g' \
+ -e 's/@''GNULIB_FMAL''@/$(GNULIB_FMAL)/g' \
-e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \
-e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \
-e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \
@@ -766,6 +762,9 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
-e 's|@''HAVE_EXPF''@|$(HAVE_EXPF)|g' \
-e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \
-e 's|@''HAVE_FABSF''@|$(HAVE_FABSF)|g' \
+ -e 's|@''HAVE_FMA''@|$(HAVE_FMA)|g' \
+ -e 's|@''HAVE_FMAF''@|$(HAVE_FMAF)|g' \
+ -e 's|@''HAVE_FMAL''@|$(HAVE_FMAL)|g' \
-e 's|@''HAVE_FMODF''@|$(HAVE_FMODF)|g' \
-e 's|@''HAVE_FREXPF''@|$(HAVE_FREXPF)|g' \
-e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
@@ -817,6 +816,9 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
-e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \
-e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \
-e 's|@''REPLACE_FLOORL''@|$(REPLACE_FLOORL)|g' \
+ -e 's|@''REPLACE_FMA''@|$(REPLACE_FMA)|g' \
+ -e 's|@''REPLACE_FMAF''@|$(REPLACE_FMAF)|g' \
+ -e 's|@''REPLACE_FMAL''@|$(REPLACE_FMAL)|g' \
-e 's|@''REPLACE_FREXPF''@|$(REPLACE_FREXPF)|g' \
-e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \
-e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \
@@ -1275,6 +1277,29 @@ EXTRA_DIST += w32sock.h
## end gnulib module sockets
+## begin gnulib module stdalign
+
+BUILT_SOURCES += $(STDALIGN_H)
+
+# We need the following in order to create <stdalign.h> when the system
+# doesn't have one that works.
+if GL_GENERATE_STDALIGN_H
+stdalign.h: stdalign.in.h $(top_builddir)/config.status
+ $(AM_V_GEN)rm -f $@-t $@ && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ cat $(srcdir)/stdalign.in.h; \
+ } > $@-t && \
+ mv $@-t $@
+else
+stdalign.h: $(top_builddir)/config.status
+ rm -f $@
+endif
+MOSTLYCLEANFILES += stdalign.h stdalign.h-t
+
+EXTRA_DIST += stdalign.in.h
+
+## end gnulib module stdalign
+
## begin gnulib module stdarg
BUILT_SOURCES += $(STDARG_H)
diff --git a/gl/alignof.h b/gl/alignof.h
deleted file mode 100644
index 1c1f75c5e7..0000000000
--- a/gl/alignof.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Determine alignment of types.
- Copyright (C) 2003-2004, 2006, 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, 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, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-#ifndef _ALIGNOF_H
-#define _ALIGNOF_H
-
-#include <stddef.h>
-
-/* Determine the alignment of a structure slot (field) of a given type,
- at compile time. Note that the result depends on the ABI.
- Note: The result cannot be used as a value for an 'enum' constant,
- due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
-#if defined __cplusplus
- template <class type> struct alignof_helper { char __slot1; type __slot2; };
-# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
-#else
-# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
-#endif
-
-/* Determine the good alignment of an object of the given type at compile time.
- Note that this is not necessarily the same as alignof_slot(type).
- For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
- - when -malign-double is not specified: alignof_slot(double) = 4,
- - when -malign-double is specified: alignof_slot(double) = 8.
- Note: The result cannot be used as a value for an 'enum' constant,
- due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
-#if defined __GNUC__
-# define alignof_type __alignof__
-#else
-# define alignof_type alignof_slot
-#endif
-
-/* alignof is an alias for alignof_slot semantics, since that's what most
- callers need.
- Note: The result cannot be used as a value for an 'enum' constant,
- due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
-#define alignof alignof_slot
-
-#endif /* _ALIGNOF_H */
diff --git a/gl/argp-parse.c b/gl/argp-parse.c
index 5cab8cec35..64360beac0 100644
--- a/gl/argp-parse.c
+++ b/gl/argp-parse.c
@@ -21,6 +21,7 @@
#endif
#include <alloca.h>
+#include <stdalign.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -42,7 +43,6 @@
#include "argp.h"
#include "argp-namefrob.h"
-#define alignof(type) offsetof (struct { char c; type x; }, x)
#define alignto(n, d) ((((n) + (d) - 1) / (d)) * (d))
/* Getopt return values. */
diff --git a/gl/closedir.c b/gl/closedir.c
index 700d60eeb4..0fdce18054 100644
--- a/gl/closedir.c
+++ b/gl/closedir.c
@@ -19,6 +19,10 @@
/* Specification. */
#include <dirent.h>
+#if REPLACE_FCHDIR
+# include <unistd.h>
+#endif
+
#if HAVE_CLOSEDIR
/* Override closedir(), to keep track of the open file descriptors.
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 9e8e355fe4..75c46af2d8 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -40,7 +40,6 @@ AC_DEFUN([gl_EARLY],
AC_REQUIRE([gl_PROG_AR_RANLIB])
# Code from module accept:
# Code from module accept-tests:
- # Code from module alignof:
# Code from module alloca:
# Code from module alloca-opt:
# Code from module alloca-opt-tests:
@@ -249,6 +248,8 @@ AC_DEFUN([gl_EARLY],
# Code from module ssize_t:
# Code from module stat:
# Code from module stat-tests:
+ # Code from module stdalign:
+ # Code from module stdalign-tests:
# Code from module stdarg:
dnl Some compilers (e.g., AIX 5.3 cc) need to be in c99 mode
dnl for the builtin va_copy to work. With Autoconf 2.60 or later,
@@ -702,6 +703,7 @@ gl_SOCKETLIB
gl_SOCKETS
gl_TYPE_SOCKLEN_T
gt_TYPE_SSIZE_T
+gl_STDALIGN_H
gl_STDARG_H
AM_STDBOOL_H
gl_STDDEF_H
@@ -1081,7 +1083,6 @@ AC_DEFUN([gl_FILE_LIST], [
build-aux/useless-if-before-free
build-aux/vc-list-files
lib/accept.c
- lib/alignof.h
lib/alloca.c
lib/alloca.in.h
lib/alphasort.c
@@ -1207,6 +1208,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/socket.c
lib/sockets.c
lib/sockets.h
+ lib/stdalign.in.h
lib/stdarg.in.h
lib/stdbool.in.h
lib/stddef.in.h
@@ -1379,6 +1381,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/sockpfaf.m4
m4/ssize_t.m4
m4/stat.m4
+ m4/stdalign.m4
m4/stdarg.m4
m4/stdbool.m4
m4/stddef_h.m4
@@ -1548,6 +1551,7 @@ AC_DEFUN([gl_FILE_LIST], [
tests/test-sockets.c
tests/test-stat.c
tests/test-stat.h
+ tests/test-stdalign.c
tests/test-stdbool.c
tests/test-stddef.c
tests/test-stdint.c
diff --git a/gl/m4/math_h.m4 b/gl/m4/math_h.m4
index e5a2892481..e58a9e908c 100644
--- a/gl/m4/math_h.m4
+++ b/gl/m4/math_h.m4
@@ -1,4 +1,4 @@
-# math_h.m4 serial 53
+# math_h.m4 serial 56
dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -41,7 +41,7 @@ AC_DEFUN([gl_MATH_H],
gl_WARN_ON_USE_PREPARE([[#include <math.h>]],
[acosf acosl asinf asinl atanf atanl
ceilf ceill copysign copysignf copysignl cosf cosl coshf
- expf expl fabsf floorf floorl fmodf frexpf frexpl
+ expf expl fabsf floorf floorl fma fmaf fmal fmodf frexpf frexpl
ldexpf ldexpl logb logf logl log10f modff powf
rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
tanf tanl tanhf trunc truncf truncl])
@@ -80,6 +80,9 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR])
GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF])
GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL])
+ GNULIB_FMA=0; AC_SUBST([GNULIB_FMA])
+ GNULIB_FMAF=0; AC_SUBST([GNULIB_FMAF])
+ GNULIB_FMAL=0; AC_SUBST([GNULIB_FMAL])
GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF])
GNULIB_FREXPF=0; AC_SUBST([GNULIB_FREXPF])
GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP])
@@ -133,6 +136,9 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
HAVE_EXPF=1; AC_SUBST([HAVE_EXPF])
HAVE_EXPL=1; AC_SUBST([HAVE_EXPL])
HAVE_FABSF=1; AC_SUBST([HAVE_FABSF])
+ HAVE_FMA=1; AC_SUBST([HAVE_FMA])
+ HAVE_FMAF=1; AC_SUBST([HAVE_FMAF])
+ HAVE_FMAL=1; AC_SUBST([HAVE_FMAL])
HAVE_FMODF=1; AC_SUBST([HAVE_FMODF])
HAVE_FREXPF=1; AC_SUBST([HAVE_FREXPF])
HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF])
@@ -183,6 +189,9 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
REPLACE_FLOOR=0; AC_SUBST([REPLACE_FLOOR])
REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF])
REPLACE_FLOORL=0; AC_SUBST([REPLACE_FLOORL])
+ REPLACE_FMA=0; AC_SUBST([REPLACE_FMA])
+ REPLACE_FMAF=0; AC_SUBST([REPLACE_FMAF])
+ REPLACE_FMAL=0; AC_SUBST([REPLACE_FMAL])
REPLACE_FREXPF=0; AC_SUBST([REPLACE_FREXPF])
REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP])
REPLACE_FREXPL=0; AC_SUBST([REPLACE_FREXPL])
diff --git a/gl/m4/stdalign.m4 b/gl/m4/stdalign.m4
new file mode 100644
index 0000000000..da64dc6332
--- /dev/null
+++ b/gl/m4/stdalign.m4
@@ -0,0 +1,22 @@
+# Check for stdalign.h that conforms to C1x.
+
+dnl Copyright 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Prepare for substituting <stdalign.h> if it is not supported.
+
+AC_DEFUN([gl_STDALIGN_H],
+[
+ AC_CHECK_HEADERS_ONCE([stdalign.h])
+
+ if test $ac_cv_header_stdalign_h = yes; then
+ STDALIGN_H=''
+ else
+ STDALIGN_H='stdalign.h'
+ fi
+
+ AC_SUBST([STDALIGN_H])
+ AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"])
+])
diff --git a/gl/math.in.h b/gl/math.in.h
index e0742ecbf8..eadb489cd4 100644
--- a/gl/math.in.h
+++ b/gl/math.in.h
@@ -507,6 +507,80 @@ _GL_WARN_ON_USE (floorl, "floorl is unportable - "
#endif
+#if @GNULIB_FMAF@
+# if @REPLACE_FMAF@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fmaf
+# define fmaf rpl_fmaf
+# endif
+_GL_FUNCDECL_RPL (fmaf, float, (float x, float y, float z));
+_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z));
+# else
+# if !@HAVE_FMAF@
+_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z));
+# endif
+_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z));
+# endif
+_GL_CXXALIASWARN (fmaf);
+#elif defined GNULIB_POSIXCHECK
+# undef fmaf
+# if HAVE_RAW_DECL_FMAF
+_GL_WARN_ON_USE (fmaf, "fmaf is unportable - "
+ "use gnulib module fmaf for portability");
+# endif
+#endif
+
+#if @GNULIB_FMA@
+# if @REPLACE_FMA@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fma
+# define fma rpl_fma
+# endif
+_GL_FUNCDECL_RPL (fma, double, (double x, double y, double z));
+_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z));
+# else
+# if !@HAVE_FMA@
+_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z));
+# endif
+_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z));
+# endif
+_GL_CXXALIASWARN (fma);
+#elif defined GNULIB_POSIXCHECK
+# undef fma
+# if HAVE_RAW_DECL_FMA
+_GL_WARN_ON_USE (fma, "fma is unportable - "
+ "use gnulib module fma for portability");
+# endif
+#endif
+
+#if @GNULIB_FMAL@
+# if @REPLACE_FMAL@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fmal
+# define fmal rpl_fmal
+# endif
+_GL_FUNCDECL_RPL (fmal, long double,
+ (long double x, long double y, long double z));
+_GL_CXXALIAS_RPL (fmal, long double,
+ (long double x, long double y, long double z));
+# else
+# if !@HAVE_FMAL@
+_GL_FUNCDECL_SYS (fmal, long double,
+ (long double x, long double y, long double z));
+# endif
+_GL_CXXALIAS_SYS (fmal, long double,
+ (long double x, long double y, long double z));
+# endif
+_GL_CXXALIASWARN (fmal);
+#elif defined GNULIB_POSIXCHECK
+# undef fmal
+# if HAVE_RAW_DECL_FMAL
+_GL_WARN_ON_USE (fmal, "fmal is unportable - "
+ "use gnulib module fmal for portability");
+# endif
+#endif
+
+
#if @GNULIB_FMODF@
# if !@HAVE_FMODF@
# undef fmodf
diff --git a/gl/stdalign.in.h b/gl/stdalign.in.h
new file mode 100644
index 0000000000..79e5691a52
--- /dev/null
+++ b/gl/stdalign.in.h
@@ -0,0 +1,89 @@
+/* A substitute for ISO C 1x <stdalign.h>.
+
+ Copyright 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, 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, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Paul Eggert and Bruno Haible. */
+
+#ifndef _GL_STDALIGN_H
+#define _GL_STDALIGN_H
+
+/* ISO C1X <stdalign.h> for platforms that lack it.
+
+ References:
+ ISO C1X <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>
+ sections 6.5.3.4, 6.7.5, 7.15.
+ C++0X <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>
+ section 18.10. */
+
+/* alignof (TYPE), also known as _Alignof (TYPE), yields the alignment
+ requirement of a structure member (i.e., slot or field) that is of
+ type TYPE, as an integer constant expression.
+
+ This differs from GCC's __alignof__ operator, which can yield a
+ better-performing alignment for an object of that type. For
+ example, on x86 with GCC, __alignof__ (double) and __alignof__
+ (long long) are 8, whereas alignof (double) and alignof (long long)
+ are 4 unless the option '-malign-double' is used.
+
+ The result cannot be used as a value for an 'enum' constant, if you
+ want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. */
+#include <stddef.h>
+#if defined __cplusplus
+ template <class __t> struct __alignof_helper { char __a; __t __b; };
+# define _Alignof(type) offsetof (__alignof_helper<type>, __b)
+#else
+# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
+#endif
+#define alignof _Alignof
+#define __alignof_is_defined 1
+
+/* alignas (A), also known as _Alignas (A), aligns a variable or type
+ to the alignment A, where A is an integer constant expression. For
+ example:
+
+ int alignas (8) foo;
+ struct s { int a; int alignas (8) bar; };
+
+ aligns the address of FOO and the offset of BAR to be multiples of 8.
+
+ A should be a power of two that is at least the type's alignment
+ and at most the implementation's alignment limit. This limit is
+ 2**28 on typical GNUish hosts, and 2**13 on MSVC. To be portable
+ to MSVC through at least version 10.0, A should be an integer
+ constant, as MSVC does not support expressions such as 1 << 3.
+ To be portable to Sun C 5.11, do not align auto variables to
+ anything stricter than their default alignment.
+
+ The following draft C1X requirements are not supported here:
+
+ - If A is zero, alignas has no effect.
+ - alignas can be used multiple times; the strictest one wins.
+ - alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
+
+ */
+
+#if __GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C
+# define _Alignas(a) __attribute__ ((__aligned__ (a)))
+#elif 1300 <= _MSC_VER
+# define _Alignas(a) __declspec (align (a))
+#endif
+#ifdef _Alignas
+# define alignas _Alignas
+# define __alignas_is_defined 1
+#endif
+
+#endif /* _GL_STDALIGN_H */
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index 19d0d67a5d..1a8df492c9 100644
--- a/gl/stdlib.in.h
+++ b/gl/stdlib.in.h
@@ -247,7 +247,7 @@ _GL_CXXALIASWARN (grantpt);
#elif defined GNULIB_POSIXCHECK
# undef grantpt
# if HAVE_RAW_DECL_GRANTPT
-_GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
+_GL_WARN_ON_USE (grantpt, "grantpt is not portable - "
"use gnulib module grantpt for portability");
# endif
#endif
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index aba28f86f0..43681a403e 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -85,7 +85,7 @@ typedef unsigned short sa_family_t;
# endif
# endif
#else
-# include <alignof.h>
+# include <stdalign.h>
/* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */
# define __ss_aligntype unsigned long int
diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am
index 4a96e59c0f..0edbe385a0 100644
--- a/gl/tests/Makefile.am
+++ b/gl/tests/Makefile.am
@@ -1032,6 +1032,14 @@ EXTRA_DIST += test-stat.h test-stat.c signature.h macros.h
## end gnulib module stat-tests
+## begin gnulib module stdalign-tests
+
+TESTS += test-stdalign
+check_PROGRAMS += test-stdalign
+EXTRA_DIST += test-stdalign.c macros.h
+
+## end gnulib module stdalign-tests
+
## begin gnulib module stdbool-tests
TESTS += test-stdbool
diff --git a/gl/tests/putenv.c b/gl/tests/putenv.c
index 3c332791bb..2da33760b9 100644
--- a/gl/tests/putenv.c
+++ b/gl/tests/putenv.c
@@ -36,7 +36,7 @@
#if _LIBC
# if HAVE_GNU_LD
-# define environ __environ
+# define environ __environ
# else
extern char **environ;
# endif
diff --git a/gl/tests/test-stdalign.c b/gl/tests/test-stdalign.c
new file mode 100644
index 0000000000..7090a26860
--- /dev/null
+++ b/gl/tests/test-stdalign.c
@@ -0,0 +1,116 @@
+/* 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"
+
+#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;
+
+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
+/* 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
+# define _Alignas(alignment)
+# define alignas(alignment)
+# define TEST_ALIGNMENT 1
+#endif
+
+#define CHECK_STATIC(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); \
+ type alignas (TEST_ALIGNMENT) static_##type##_alignas; \
+ 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
+ /* Avoid a test failure due to Sun Studio Developer Bug Report #2125432. */
+ fputs ("Skipping test: known Sun C compiler bug\n", stderr);
+ return 77;
+#else
+ CHECK_ALIGNED (static_char_alignas);
+ CHECK_ALIGNED (static_char_Alignas);
+ CHECK_ALIGNED (static_short_alignas);
+ CHECK_ALIGNED (static_short_Alignas);
+ CHECK_ALIGNED (static_int_alignas);
+ CHECK_ALIGNED (static_int_Alignas);
+ CHECK_ALIGNED (static_long_alignas);
+ CHECK_ALIGNED (static_long_Alignas);
+# ifdef INT64_MAX
+ CHECK_ALIGNED (static_int64_t_alignas);
+ CHECK_ALIGNED (static_int64_t_Alignas);
+# endif
+ CHECK_ALIGNED (static_float_alignas);
+ CHECK_ALIGNED (static_float_Alignas);
+ CHECK_ALIGNED (static_double_alignas);
+ CHECK_ALIGNED (static_double_Alignas);
+ CHECK_ALIGNED (static_longdouble_alignas);
+ CHECK_ALIGNED (static_longdouble_Alignas);
+ CHECK_ALIGNED (static_struct1_alignas);
+ CHECK_ALIGNED (static_struct1_Alignas);
+ CHECK_ALIGNED (static_struct2_alignas);
+ CHECK_ALIGNED (static_struct2_Alignas);
+ CHECK_ALIGNED (static_struct3_alignas);
+ CHECK_ALIGNED (static_struct3_Alignas);
+ CHECK_ALIGNED (static_struct4_alignas);
+ CHECK_ALIGNED (static_struct4_Alignas);
+ return 0;
+#endif
+}