Botan 2.19.5 Crypto and TLS for C&

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, but are now deprecated
35* and which will be removed in a future major release.
36*/
37#define BOTAN_DEPRECATED_API(msg) BOTAN_DLL BOTAN_DEPRECATED(msg)
38
39/**
40* Used to annotate API exports which are public and can be used by
41* applications if needed, but which are intentionally not documented,
42* and which may change incompatibly in a future major version.
43*/
44#define BOTAN_UNSTABLE_API BOTAN_DLL
45
46/**
47* Used to annotate API exports which are exported but only for the
48* purposes of testing. They should not be used by applications and
49* may be removed or changed without notice.
50*/
51#define BOTAN_TEST_API BOTAN_DLL
52
53/*
54* Define BOTAN_GCC_VERSION
55*/
56#if defined(__GNUC__) && !defined(__clang__)
57 #define BOTAN_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
58#else
59 #define BOTAN_GCC_VERSION 0
60#endif
61
62/*
63* Define BOTAN_CLANG_VERSION
64*/
65#if defined(__clang__)
66 #define BOTAN_CLANG_VERSION (__clang_major__ * 10 + __clang_minor__)
67#else
68 #define BOTAN_CLANG_VERSION 0
69#endif
70
71/*
72* Define BOTAN_FUNC_ISA
73*/
74#if (defined(__GNUC__) && !defined(__clang__)) || (BOTAN_CLANG_VERSION > 38)
75 #define BOTAN_FUNC_ISA(isa) __attribute__ ((target(isa)))
76#else
77 #define BOTAN_FUNC_ISA(isa)
78#endif
79
80/*
81* Define BOTAN_WARN_UNUSED_RESULT
82*/
83#if defined(__GNUC__) || defined(__clang__)
84 #define BOTAN_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
85#else
86 #define BOTAN_WARN_UNUSED_RESULT
87#endif
88
89/*
90* Define BOTAN_MALLOC_FN
91*/
92#if defined(__ibmxl__)
93 /* XLC pretends to be both Clang and GCC, but is neither */
94 #define BOTAN_MALLOC_FN __attribute__ ((malloc))
95#elif defined(__GNUC__)
96 #define BOTAN_MALLOC_FN __attribute__ ((malloc, alloc_size(1,2)))
97#elif defined(_MSC_VER)
98 #define BOTAN_MALLOC_FN __declspec(restrict)
99#else
100 #define BOTAN_MALLOC_FN
101#endif
102
103/*
104* Define BOTAN_DEPRECATED
105*/
106#if !defined(BOTAN_NO_DEPRECATED_WARNINGS) && !defined(BOTAN_IS_BEING_BUILT) && !defined(BOTAN_AMALGAMATION_H_)
107
108 #if defined(__clang__)
109 #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
110 #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("message \"this header is deprecated\"")
111 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("message \"this header will be made internal in the future\"")
112
113 #elif defined(_MSC_VER)
114 #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg))
115 #define BOTAN_DEPRECATED_HEADER(hdr) __pragma(message("this header is deprecated"))
116 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) __pragma(message("this header will be made internal in the future"))
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 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("GCC warning \"this header will be made internal in the future\"")
123 #endif
124
125#endif
126
127#if !defined(BOTAN_DEPRECATED)
128 #define BOTAN_DEPRECATED(msg)
129#endif
130
131#if !defined(BOTAN_DEPRECATED_HEADER)
132 #define BOTAN_DEPRECATED_HEADER(hdr)
133#endif
134
135#if !defined(BOTAN_FUTURE_INTERNAL_HEADER)
136 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
137#endif
138
139/*
140* Define BOTAN_NORETURN
141*/
142#if !defined(BOTAN_NORETURN)
143
144 #if defined (__clang__) || defined (__GNUC__)
145 #define BOTAN_NORETURN __attribute__ ((__noreturn__))
146
147 #elif defined (_MSC_VER)
148 #define BOTAN_NORETURN __declspec(noreturn)
149
150 #else
151 #define BOTAN_NORETURN
152 #endif
153
154#endif
155
156/*
157* Define BOTAN_THREAD_LOCAL
158*/
159#if !defined(BOTAN_THREAD_LOCAL)
160
161 #if defined(BOTAN_TARGET_OS_HAS_THREADS) && defined(BOTAN_TARGET_OS_HAS_THREAD_LOCAL)
162 #define BOTAN_THREAD_LOCAL thread_local
163 #else
164 #define BOTAN_THREAD_LOCAL /**/
165 #endif
166
167#endif
168
169/*
170* Define BOTAN_IF_CONSTEXPR
171*/
172#if !defined(BOTAN_IF_CONSTEXPR)
173 #if __cplusplus >= 201703
174 #define BOTAN_IF_CONSTEXPR if constexpr
175 #else
176 #define BOTAN_IF_CONSTEXPR if
177 #endif
178#endif
179
180/*
181* Define BOTAN_PARALLEL_FOR
182*/
183#if !defined(BOTAN_PARALLEL_FOR)
184
185#if defined(BOTAN_TARGET_HAS_OPENMP)
186 #define BOTAN_PARALLEL_FOR _Pragma("omp parallel for") for
187#else
188 #define BOTAN_PARALLEL_FOR for
189#endif
190
191#endif
192
193#if !defined(BOTAN_ALIGNAS)
194
195#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 8)
196 #define BOTAN_ALIGNAS(x) /**/
197#else
198 #define BOTAN_ALIGNAS(x) alignas(x)
199#endif
200
201#endif
202
203/*
204* Define BOTAN_FORCE_INLINE
205*/
206#if !defined(BOTAN_FORCE_INLINE)
207
208 #if defined (__clang__) || defined (__GNUC__)
209 #define BOTAN_FORCE_INLINE __attribute__ ((__always_inline__)) inline
210
211 #elif defined (_MSC_VER)
212 #define BOTAN_FORCE_INLINE __forceinline
213
214 #else
215 #define BOTAN_FORCE_INLINE inline
216 #endif
217
218#endif
219
220/*
221* Define BOTAN_PARALLEL_SIMD_FOR
222*/
223#if !defined(BOTAN_PARALLEL_SIMD_FOR)
224
225#if defined(BOTAN_TARGET_HAS_OPENMP)
226 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("omp simd") for
227#elif defined(BOTAN_BUILD_COMPILER_IS_GCC) && (BOTAN_GCC_VERSION >= 490)
228 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
229#else
230 #define BOTAN_PARALLEL_SIMD_FOR for
231#endif
232
233#endif
234
235#endif