]> Savannah Git Hosting - gnulib.git/commitdiff
Use __alignof__ with clang.
authorBruno Haible <bruno@clisp.org>
Sun, 9 Aug 2020 13:58:10 +0000 (15:58 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Aug 2020 13:58:10 +0000 (15:58 +0200)
* 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.

ChangeLog
lib/alignof.h
lib/bitset/list.c
lib/bitset/table.c
lib/malloca.h
lib/stdalign.in.h
m4/stddef_h.m4
tests/test-stddef.c

index 92cdbf8574d09739dea2fce3793f7ff8ba2703a9..7347ea828b63607e5d2cf63a358bbb732df53b4c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+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.
index c72e914406ab03c2af3a17c8568ccd16e73e9ed5..3a8d8d2343d7cc6083c52a028b5e56a51d57dfff 100644 (file)
 /* 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
index ed975ef001b8e4ecf457bf107a27da5bbba1e641..c1f3d9b153a6dd7e22236e0573657cdcb4f30bc4 100644 (file)
@@ -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
 
index 56f1a860a45ea9b9f02a917d467d1bad2ab85623..c80eebffa5d260a2a2714739b770ee24cc338ce0 100644 (file)
@@ -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
 
index 2eb84805e3709c31798e204084c46fbe8026149e..b1fa21b33aa8185029bf7613d9880b9868e0a9b4 100644 (file)
@@ -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; };
index 831307ff22ae1fa97537b362c292208ca2a53534..10eedc550e34d11f97767f68455c0dd430a647f6 100644 (file)
    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)
index 6bcfadb74ef402b7078d32b5d37f8e8d60204338..d8bc8ff64e4cc6a2d730fa3099e9cc424d4b2201 100644 (file)
@@ -1,5 +1,5 @@
 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,
@@ -19,7 +19,7 @@ AC_DEFUN([gl_STDDEF_H],
        [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
index 636c075f17cce82549aa9cabba3bb0464fd9c807..4d8c732ad98a253871b77f6d6ca8766f80915cc2 100644 (file)
@@ -59,7 +59,7 @@ verify (alignof (ptrdiff_t) <= alignof (max_align_t));
 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));