diff options
author | Bruno Haible <bruno@clisp.org> | 2020-08-09 15:58:10 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-08-09 15:58:10 +0200 |
commit | 57caf9541d98314102a55dd1cd0b8dc2be747471 (patch) | |
tree | 4ce7a17a15154f0f84398b7df3313e2126ead326 /lib | |
parent | cae4fcab00ff89a5271376aed615cfa8c067fca2 (diff) | |
download | gnulib-57caf9541d98314102a55dd1cd0b8dc2be747471.tar.gz |
Use __alignof__ with clang.
* m4/stddef_h.m4 (gl_STDDEF_H): Test the alignment of max_align_t also
on clang.
* lib/alignof.h (alignof_type): Use __alignof__ also on clang.
* lib/stdalign.in.h (_Alignof): Don't activate the GCC workaround on
clang.
* lib/malloca.h (sa_alignof): Use __alignof__ also on clang.
* lib/bitset/list.c (lbitset_elt_alloc): Use __alignof__ also on clang.
* lib/bitset/table.c (tbitset_elt_alloc): Likewise.
* tests/test-stddef.c: Very the behaviour of __alignof__ also on clang.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/alignof.h | 6 | ||||
-rw-r--r-- | lib/bitset/list.c | 2 | ||||
-rw-r--r-- | lib/bitset/table.c | 2 | ||||
-rw-r--r-- | lib/malloca.h | 2 | ||||
-rw-r--r-- | lib/stdalign.in.h | 14 |
5 files changed, 15 insertions, 11 deletions
diff --git a/lib/alignof.h b/lib/alignof.h index c72e914406..3a8d8d2343 100644 --- a/lib/alignof.h +++ b/lib/alignof.h @@ -36,12 +36,14 @@ /* alignof_type (TYPE) 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 + For example, with GNU C on x86 platforms and with clang on Linux/x86: + alignof_type(long long) = 8, but alignof_slot(long long) = 4. + And 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__ || defined __IBM__ALIGNOF__ +#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__ # define alignof_type __alignof__ #else # define alignof_type alignof_slot diff --git a/lib/bitset/list.c b/lib/bitset/list.c index ed975ef001..c1f3d9b153 100644 --- a/lib/bitset/list.c +++ b/lib/bitset/list.c @@ -122,7 +122,7 @@ lbitset_elt_alloc (void) # define OBSTACK_CHUNK_FREE free #endif -#if ! defined __GNUC__ || __GNUC__ < 2 +#if !(defined __GNUC__ || defined __clang__) # define __alignof__(type) 0 #endif diff --git a/lib/bitset/table.c b/lib/bitset/table.c index 56f1a860a4..c80eebffa5 100644 --- a/lib/bitset/table.c +++ b/lib/bitset/table.c @@ -206,7 +206,7 @@ tbitset_elt_alloc (void) # define OBSTACK_CHUNK_FREE free #endif -#if ! defined __GNUC__ || __GNUC__ < 2 +#if !(defined __GNUC__ || defined __clang__) # define __alignof__(type) 0 #endif diff --git a/lib/malloca.h b/lib/malloca.h index 2eb84805e3..b1fa21b33a 100644 --- a/lib/malloca.h +++ b/lib/malloca.h @@ -89,7 +89,7 @@ extern void freea (void *p); /* ------------------- Auxiliary, non-public definitions ------------------- */ /* Determine the alignment of a type at compile time. */ -#if defined __GNUC__ || defined __IBM__ALIGNOF__ +#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__ # define sa_alignof __alignof__ #elif defined __cplusplus template <class type> struct sa_alignof_helper { char __slot1; type __slot2; }; diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h index 831307ff22..10eedc550e 100644 --- a/lib/stdalign.in.h +++ b/lib/stdalign.in.h @@ -34,11 +34,12 @@ 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. + This differs from GCC's and clang's __alignof__ operator, which can + yield a better-performing alignment for an object of that type. For + example, on x86 with GCC and on Linux/x86 with clang, + __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. @@ -55,7 +56,8 @@ /* GCC releases before GCC 4.9 had a bug in _Alignof. See GCC bug 52023 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */ #if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \ - || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9))) + || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \ + && !defined __clang__)) # ifdef __cplusplus # if 201103 <= __cplusplus # define _Alignof(type) alignof (type) |