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