diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-04-02 10:35:53 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-04-02 10:36:37 -0700 |
commit | e2e66692cd072a39ce26ecf94117f934008aab24 (patch) | |
tree | b79c5b49c2d065f753f74a1307a64d677ac43118 /lib/stddef.in.h | |
parent | 106a3866d01f9dd57ab4f10dbeb0d5a8db73a9f7 (diff) | |
download | gnulib-e2e66692cd072a39ce26ecf94117f934008aab24.tar.gz |
stddef: port to pre-C11 GCC on x86
On this platform, max_align_t should have an alignment of 8 even
though the storage alignments of double, long, etc. max out at 4.
Inspired by a comment of Andreas Schwab's here:
https://sourceware.org/ml/libc-alpha/2015-04/msg00017.html
* lib/stddef.in.h (_GL_STDDEF_ALIGNAS) [!HAVE_MAX_ALIGN_T]: New macro.
(max_align_t) [!HAVE_MAX_ALIGN_T]: Use it.
* tests/test-stddef.c: Test __alignof__ too, if available.
Diffstat (limited to 'lib/stddef.in.h')
-rw-r--r-- | lib/stddef.in.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/stddef.in.h b/lib/stddef.in.h index 535132a4e2..d6b81fac82 100644 --- a/lib/stddef.in.h +++ b/lib/stddef.in.h @@ -83,12 +83,23 @@ /* Some platforms lack max_align_t. */ #if !@HAVE_MAX_ALIGN_T@ +/* On the x86, the maximum storage alignment of double, long, etc. is 4, + but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8, + and the C11 standard allows this. Work around this problem by + using __alignof__ (which returns 8 for double) rather than _Alignof + (which returns 4), and align each union member accordingly. */ +# ifdef __GNUC__ +# define _GL_STDDEF_ALIGNAS(type) \ + __attribute__ ((__aligned__ (__alignof__ (type)))) +# else +# define _GL_STDDEF_ALIGNAS(type) /* */ +# endif typedef union { - char *__p; - double __d; - long double __ld; - long int __i; + char *__p _GL_STDDEF_ALIGNAS (char *); + double __d _GL_STDDEF_ALIGNAS (double); + long double __ld _GL_STDDEF_ALIGNAS (long double); + long int __i _GL_STDDEF_ALIGNAS (long int); } max_align_t; #endif |