Botan  2.11.0
Crypto and TLS for C++11
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(__GNUG__) && !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(__GNUG__) || 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(__clang__) || (BOTAN_GCC_VERSION >= 500)
90  #define BOTAN_MALLOC_FN __attribute__ ((malloc, returns_nonnull, alloc_size(1,2)))
91 #elif defined(__GNUG__)
92  #define BOTAN_MALLOC_FN __attribute__ ((malloc, alloc_size(1,2)))
93 #elif defined(_MSC_VER)
94  #define BOTAN_MALLOC_FN __declspec(restrict)
95 #else
96  #define BOTAN_MALLOC_FN
97 #endif
98 
99 /*
100 * Define BOTAN_DEPRECATED
101 */
102 #if !defined(BOTAN_NO_DEPRECATED_WARNINGS)
103 
104  #if defined(__clang__)
105  #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated))
106  #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("message \"this header is deprecated\"")
107 
108  #elif defined(_MSC_VER)
109  #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg))
110  #define BOTAN_DEPRECATED_HEADER(hdr) __pragma("message \"this header is deprecated\"")
111 
112  #elif defined(__GNUG__)
113  /* msg supported since GCC 4.5, earliest we support is 4.8 */
114  #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
115  #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("GCC warning \"this header is deprecated\"")
116  #endif
117 
118 #endif
119 
120 #if !defined(BOTAN_DEPRECATED)
121  #define BOTAN_DEPRECATED(msg)
122 #endif
123 
124 #if !defined(BOTAN_DEPRECATED_HEADER)
125  #define BOTAN_DEPRECATED_HEADER(hdr)
126 #endif
127 
128 /*
129 * Define BOTAN_NORETURN
130 */
131 #if !defined(BOTAN_NORETURN)
132 
133  #if defined (__clang__) || defined (__GNUG__)
134  #define BOTAN_NORETURN __attribute__ ((__noreturn__))
135 
136  #elif defined (_MSC_VER)
137  #define BOTAN_NORETURN __declspec(noreturn)
138 
139  #else
140  #define BOTAN_NORETURN
141  #endif
142 
143 #endif
144 
145 /*
146 * Define BOTAN_THREAD_LOCAL
147 */
148 #if defined(BOTAN_TARGET_OS_HAS_THREADS)
149  #define BOTAN_THREAD_LOCAL thread_local
150 #else
151  #define BOTAN_THREAD_LOCAL /**/
152 #endif
153 
154 /*
155 * Define BOTAN_IF_CONSTEXPR
156 */
157 #if !defined(BOTAN_IF_CONSTEXPR)
158  #if __cplusplus > 201402
159  #define BOTAN_IF_CONSTEXPR if constexpr
160  #else
161  #define BOTAN_IF_CONSTEXPR if
162  #endif
163 #endif
164 
165 /*
166 * Define BOTAN_PARALLEL_FOR
167 */
168 #if !defined(BOTAN_PARALLEL_FOR)
169 
170 #if defined(BOTAN_TARGET_HAS_OPENMP)
171  #define BOTAN_PARALLEL_FOR _Pragma("omp parallel for") for
172 #else
173  #define BOTAN_PARALLEL_FOR for
174 #endif
175 
176 #endif
177 
178 /*
179 * Define BOTAN_PARALLEL_SIMD_FOR
180 */
181 #if !defined(BOTAN_PARALLEL_SIMD_FOR)
182 
183 #if defined(BOTAN_TARGET_HAS_OPENMP)
184  #define BOTAN_PARALLEL_SIMD_FOR _Pragma("omp simd") for
185 #elif defined(BOTAN_BUILD_COMPILER_IS_GCC) && (BOTAN_GCC_VERSION >= 490)
186  #define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
187 #else
188  #define BOTAN_PARALLEL_SIMD_FOR for
189 #endif
190 
191 #endif
192 
193 #endif