diff options
Diffstat (limited to 'gl/stdalign.in.h')
-rw-r--r-- | gl/stdalign.in.h | 78 |
1 files changed, 53 insertions, 25 deletions
diff --git a/gl/stdalign.in.h b/gl/stdalign.in.h index 7254a3d..7f9dbb4 100644 --- a/gl/stdalign.in.h +++ b/gl/stdalign.in.h | |||
@@ -1,19 +1,19 @@ | |||
1 | /* A substitute for ISO C11 <stdalign.h>. | 1 | /* A substitute for ISO C11 <stdalign.h>. |
2 | 2 | ||
3 | Copyright 2011-2013 Free Software Foundation, Inc. | 3 | Copyright 2011-2023 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This file is free software: you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU Lesser General Public License as |
7 | the Free Software Foundation; either version 3, or (at your option) | 7 | published by the Free Software Foundation; either version 2.1 of the |
8 | any later version. | 8 | License, or (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This file is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU Lesser General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Lesser General Public License |
16 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ | 16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
17 | 17 | ||
18 | /* Written by Paul Eggert and Bruno Haible. */ | 18 | /* Written by Paul Eggert and Bruno Haible. */ |
19 | 19 | ||
@@ -34,17 +34,15 @@ | |||
34 | requirement of a structure member (i.e., slot or field) that is of | 34 | requirement of a structure member (i.e., slot or field) that is of |
35 | type TYPE, as an integer constant expression. | 35 | type TYPE, as an integer constant expression. |
36 | 36 | ||
37 | This differs from GCC's __alignof__ operator, which can yield a | 37 | This differs from GCC's and clang's __alignof__ operator, which can |
38 | better-performing alignment for an object of that type. For | 38 | yield a better-performing alignment for an object of that type. For |
39 | example, on x86 with GCC, __alignof__ (double) and __alignof__ | 39 | example, on x86 with GCC and on Linux/x86 with clang, |
40 | (long long) are 8, whereas alignof (double) and alignof (long long) | 40 | __alignof__ (double) and __alignof__ (long long) are 8, whereas |
41 | are 4 unless the option '-malign-double' is used. | 41 | alignof (double) and alignof (long long) are 4 unless the option |
42 | '-malign-double' is used. | ||
42 | 43 | ||
43 | The result cannot be used as a value for an 'enum' constant, if you | 44 | The result cannot be used as a value for an 'enum' constant, if you |
44 | want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. | 45 | want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc. */ |
45 | |||
46 | Include <stddef.h> for offsetof. */ | ||
47 | #include <stddef.h> | ||
48 | 46 | ||
49 | /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other | 47 | /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other |
50 | standard headers, defines conflicting implementations of _Alignas | 48 | standard headers, defines conflicting implementations of _Alignas |
@@ -52,19 +50,33 @@ | |||
52 | #undef _Alignas | 50 | #undef _Alignas |
53 | #undef _Alignof | 51 | #undef _Alignof |
54 | 52 | ||
55 | #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 | 53 | /* GCC releases before GCC 4.9 had a bug in _Alignof. See GCC bug 52023 |
54 | <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. | ||
55 | clang versions < 8.0.0 have the same bug. */ | ||
56 | #if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \ | ||
57 | || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \ | ||
58 | && !defined __clang__) \ | ||
59 | || (defined __clang__ && __clang_major__ < 8)) | ||
56 | # ifdef __cplusplus | 60 | # ifdef __cplusplus |
57 | # if 201103 <= __cplusplus | 61 | # if (201103 <= __cplusplus || defined _MSC_VER) |
58 | # define _Alignof(type) alignof (type) | 62 | # define _Alignof(type) alignof (type) |
59 | # else | 63 | # else |
60 | template <class __t> struct __alignof_helper { char __a; __t __b; }; | 64 | template <class __t> struct __alignof_helper { char __a; __t __b; }; |
61 | # define _Alignof(type) offsetof (__alignof_helper<type>, __b) | 65 | # define _Alignof(type) offsetof (__alignof_helper<type>, __b) |
66 | # define _GL_STDALIGN_NEEDS_STDDEF 1 | ||
62 | # endif | 67 | # endif |
63 | # else | 68 | # else |
64 | # define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) | 69 | # if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__ |
70 | # define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b) | ||
71 | # else | ||
72 | # define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) | ||
73 | # define _GL_STDALIGN_NEEDS_STDDEF 1 | ||
74 | # endif | ||
65 | # endif | 75 | # endif |
66 | #endif | 76 | #endif |
67 | #define alignof _Alignof | 77 | #if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)) |
78 | # define alignof _Alignof | ||
79 | #endif | ||
68 | #define __alignof_is_defined 1 | 80 | #define __alignof_is_defined 1 |
69 | 81 | ||
70 | /* alignas (A), also known as _Alignas (A), aligns a variable or type | 82 | /* alignas (A), also known as _Alignas (A), aligns a variable or type |
@@ -93,17 +105,33 @@ | |||
93 | */ | 105 | */ |
94 | 106 | ||
95 | #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 | 107 | #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 |
96 | # if defined __cplusplus && 201103 <= __cplusplus | 108 | # if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER) |
97 | # define _Alignas(a) alignas (a) | 109 | # define _Alignas(a) alignas (a) |
98 | # elif __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC || 0x5110 <= __SUNPRO_C | 110 | # elif (!defined __attribute__ \ |
111 | && ((defined __APPLE__ && defined __MACH__ \ | ||
112 | ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \ | ||
113 | : __GNUC__ && !defined __ibmxl__) \ | ||
114 | || (4 <= __clang_major__) \ | ||
115 | || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \ | ||
116 | || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__)) | ||
99 | # define _Alignas(a) __attribute__ ((__aligned__ (a))) | 117 | # define _Alignas(a) __attribute__ ((__aligned__ (a))) |
100 | # elif 1300 <= _MSC_VER | 118 | # elif 1300 <= _MSC_VER |
101 | # define _Alignas(a) __declspec (align (a)) | 119 | # define _Alignas(a) __declspec (align (a)) |
102 | # endif | 120 | # endif |
103 | #endif | 121 | #endif |
104 | #if defined _Alignas || (defined __STDC_VERSION && 201112 <= __STDC_VERSION__) | 122 | #if ((defined _Alignas \ |
123 | && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \ | ||
124 | || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) | ||
105 | # define alignas _Alignas | 125 | # define alignas _Alignas |
126 | #endif | ||
127 | #if (defined alignas \ | ||
128 | || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) | ||
106 | # define __alignas_is_defined 1 | 129 | # define __alignas_is_defined 1 |
107 | #endif | 130 | #endif |
108 | 131 | ||
132 | /* Include <stddef.h> if needed for offsetof. */ | ||
133 | #if _GL_STDALIGN_NEEDS_STDDEF | ||
134 | # include <stddef.h> | ||
135 | #endif | ||
136 | |||
109 | #endif /* _GL_STDALIGN_H */ | 137 | #endif /* _GL_STDALIGN_H */ |