Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

compiler.h
Go to the documentation of this file.
1 /*
2 * Define useful compiler-specific macros
3 * (C) 2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 /* This header is included in both C++ and C (via ffi.h) and should only
9 contain macro definitions. Avoid C++ style // comments in this file.
10 */
11
12 #ifndef BOTAN_UTIL_COMPILER_FLAGS_H_
13 #define BOTAN_UTIL_COMPILER_FLAGS_H_
14
15 /* Should we use GCC-style inline assembler? */
16 #if defined(BOTAN_BUILD_COMPILER_IS_GCC) || \
17 defined(BOTAN_BUILD_COMPILER_IS_CLANG) || \
18 defined(BOTAN_BUILD_COMPILER_IS_XLC) || \
19 defined(BOTAN_BUILD_COMPILER_IS_SUN_STUDIO)
20
21 #define BOTAN_USE_GCC_INLINE_ASM
22 #endif
23
24 /**
25 * Used to annotate API exports which are public and supported.
26 * These APIs will not be broken/removed unless strictly required for
27 * functionality or security, and only in new major versions.
28 * @param maj The major version this public API was released in
29 * @param min The minor version this public API was released in
30 */
31 #define BOTAN_PUBLIC_API(maj,min) BOTAN_DLL
32
33 /**
34 * Used to annotate API exports which are public and can be used by
35 * applications if needed, but which are intentionally not documented,
36 * and which may change incompatibly in a future major version.
37 */
38 #define BOTAN_UNSTABLE_API BOTAN_DLL
39
40 /**
41 * Used to annotate API exports which are exported but only for the
42 * purposes of testing. They should not be used by applications and
43 * may be removed or changed without notice.
44 */
45 #define BOTAN_TEST_API BOTAN_DLL
46
47 /*
48 * Define BOTAN_GCC_VERSION
49 */
50 #if defined(__GNUC__) && !defined(__clang__)
51 #define BOTAN_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
52 #else
53 #define BOTAN_GCC_VERSION 0
54 #endif
55
56 /*
57 * Define BOTAN_CLANG_VERSION
58 */
59 #if defined(__clang__)
60 #define BOTAN_CLANG_VERSION (__clang_major__ * 10 + __clang_minor__)
61 #else
62 #define BOTAN_CLANG_VERSION 0
63 #endif
64
65 /*
66 * Define BOTAN_FUNC_ISA
67 */
68 #if (defined(__GNUC__) && !defined(__clang__)) || (BOTAN_CLANG_VERSION > 38)
69 #define BOTAN_FUNC_ISA(isa) __attribute__ ((target(isa)))
70 #else
71 #define BOTAN_FUNC_ISA(isa)
72 #endif
73
74 /*
75 * Define BOTAN_WARN_UNUSED_RESULT
76 */
77 #if defined(__GNUC__) || defined(__clang__)
78 #define BOTAN_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
79 #else
80 #define BOTAN_WARN_UNUSED_RESULT
81 #endif
82
83 /*
84 * Define BOTAN_MALLOC_FN
85 */
86 #if defined(__ibmxl__)
87 // XLC pretends to be both Clang and GCC, but is neither
88 #define BOTAN_MALLOC_FN __attribute__ ((malloc))
89 #elif defined(__GNUC__)
90 #define BOTAN_MALLOC_FN __attribute__ ((malloc, alloc_size(1,2)))
91 #elif defined(_MSC_VER)
92 #define BOTAN_MALLOC_FN __declspec(restrict)
93 #else
94 #define BOTAN_MALLOC_FN
95 #endif
96
97 /*
98 * Define BOTAN_DEPRECATED
99 */
100 #if !defined(BOTAN_NO_DEPRECATED_WARNINGS)
101
102 #if defined(__clang__)
103 #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
104 #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("message \"this header is deprecated\"")
105
106 #if !defined(BOTAN_IS_BEING_BUILT)
107 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("message \"this header will be made internal in the future\"")
108 #endif
109
110 #elif defined(_MSC_VER)
111 #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg))
112 #define BOTAN_DEPRECATED_HEADER(hdr) __pragma(message("this header is deprecated"))
113
114 #if !defined(BOTAN_IS_BEING_BUILT)
115 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) __pragma(message("this header will be made internal in the future"))
116 #endif
117
118 #elif defined(__GNUC__)
119 /* msg supported since GCC 4.5, earliest we support is 4.8 */
120 #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
121 #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("GCC warning \"this header is deprecated\"")
122
123 #if !defined(BOTAN_IS_BEING_BUILT)
124 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("GCC warning \"this header will be made internal in the future\"")
125 #endif
126 #endif
127
128 #endif
129
130 #if !defined(BOTAN_DEPRECATED)
131 #define BOTAN_DEPRECATED(msg)
132 #endif
133
134 #if !defined(BOTAN_DEPRECATED_HEADER)
135 #define BOTAN_DEPRECATED_HEADER(hdr)
136 #endif
137
138 #if !defined(BOTAN_FUTURE_INTERNAL_HEADER)
139 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
140 #endif
141
142 /*
143 * Define BOTAN_NORETURN
144 */
145 #if !defined(BOTAN_NORETURN)
146
147 #if defined (__clang__) || defined (__GNUC__)
148 #define BOTAN_NORETURN __attribute__ ((__noreturn__))
149
150 #elif defined (_MSC_VER)
151 #define BOTAN_NORETURN __declspec(noreturn)
152
153 #else
154 #define BOTAN_NORETURN
155 #endif
156
157 #endif
158
159 /*
160 * Define BOTAN_THREAD_LOCAL
161 */
162 #if !defined(BOTAN_THREAD_LOCAL)
163
164 #if defined(BOTAN_TARGET_OS_HAS_THREADS) && defined(BOTAN_TARGET_OS_HAS_THREAD_LOCAL)
165 #define BOTAN_THREAD_LOCAL thread_local
166 #else
167 #define BOTAN_THREAD_LOCAL /**/
168 #endif
169
170 #endif
171
172 /*
173 * Define BOTAN_IF_CONSTEXPR
174 */
175 #if !defined(BOTAN_IF_CONSTEXPR)
176 #if __cplusplus >= 201703
177 #define BOTAN_IF_CONSTEXPR if constexpr
178 #else
179 #define BOTAN_IF_CONSTEXPR if
180 #endif
181 #endif
182
183 /*
184 * Define BOTAN_PARALLEL_FOR
185 */
186 #if !defined(BOTAN_PARALLEL_FOR)
187
188 #if defined(BOTAN_TARGET_HAS_OPENMP)
189 #define BOTAN_PARALLEL_FOR _Pragma("omp parallel for") for
190 #else
191 #define BOTAN_PARALLEL_FOR for
192 #endif
193
194 #endif
195
196 /*
197 * Define BOTAN_FORCE_INLINE
198 */
199 #if !defined(BOTAN_FORCE_INLINE)
200
201 #if defined (__clang__) || defined (__GNUC__)
202 #define BOTAN_FORCE_INLINE __attribute__ ((__always_inline__)) inline
203
204 #elif defined (_MSC_VER)
205 #define BOTAN_FORCE_INLINE __forceinline
206
207 #else
208 #define BOTAN_FORCE_INLINE inline
209 #endif
210
211 #endif
212
213 /*
214 * Define BOTAN_PARALLEL_SIMD_FOR
215 */
216 #if !defined(BOTAN_PARALLEL_SIMD_FOR)
217
218 #if defined(BOTAN_TARGET_HAS_OPENMP)
219 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("omp simd") for
220 #elif defined(BOTAN_BUILD_COMPILER_IS_GCC) && (BOTAN_GCC_VERSION >= 490)
221 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
222 #else
223 #define BOTAN_PARALLEL_SIMD_FOR for
224 #endif
225
226 #endif
227
228 #endif