+2020-08-09 Bruno Haible <bruno@clisp.org>
+
+ 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.
+
2020-08-09 Bruno Haible <bruno@clisp.org>
ignore-value: Simplify on clang.
/* 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
# define OBSTACK_CHUNK_FREE free
#endif
-#if ! defined __GNUC__ || __GNUC__ < 2
+#if !(defined __GNUC__ || defined __clang__)
# define __alignof__(type) 0
#endif
# define OBSTACK_CHUNK_FREE free
#endif
-#if ! defined __GNUC__ || __GNUC__ < 2
+#if !(defined __GNUC__ || defined __clang__)
# define __alignof__(type) 0
#endif
/* ------------------- 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; };
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.
/* 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)
dnl A placeholder for <stddef.h>, for platforms that have issues.
-# stddef_h.m4 serial 6
+# stddef_h.m4 serial 7
dnl Copyright (C) 2009-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
[AC_LANG_PROGRAM(
[[#include <stddef.h>
unsigned int s = sizeof (max_align_t);
- #if defined __GNUC__ || defined __IBM__ALIGNOF__
+ #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1];
#endif
verify (alignof (size_t) <= alignof (max_align_t));
verify (alignof (wchar_t) <= alignof (max_align_t));
verify (alignof (struct d) <= alignof (max_align_t));
-#if defined __GNUC__ || defined __IBM__ALIGNOF__
+#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
verify (__alignof__ (double) <= __alignof__ (max_align_t));
verify (__alignof__ (int) <= __alignof__ (max_align_t));
verify (__alignof__ (long double) <= __alignof__ (max_align_t));