Botan  2.4.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_USE_GCC_INLINE_ASM) && (defined(__GNUC__) || defined(__xlc__) || defined(__SUNPRO_CC))
17  #define BOTAN_USE_GCC_INLINE_ASM 1
18 #endif
19 
20 /**
21 * Used to annotate API exports which are public and supported.
22 * These APIs will not be broken/removed unless strictly required for
23 * functionality or security, and only in new major versions.
24 * @param maj The major version this public API was released in
25 * @param min The minor version this public API was released in
26 */
27 #define BOTAN_PUBLIC_API(maj,min) BOTAN_DLL
28 
29 /**
30 * Used to annotate API exports which are public and can be used by
31 * applications if needed, but which are intentionally not documented,
32 * and which may change incompatibly in a future major version.
33 */
34 #define BOTAN_UNSTABLE_API BOTAN_DLL
35 
36 /**
37 * Used to annotate API exports which are exported but only for the
38 * purposes of testing. They should not be used by applications and
39 * may be removed or changed without notice.
40 */
41 #define BOTAN_TEST_API BOTAN_DLL
42 
43 /*
44 * Define BOTAN_GCC_VERSION
45 */
46 #ifdef __GNUC__
47  #define BOTAN_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
48 #else
49  #define BOTAN_GCC_VERSION 0
50 #endif
51 
52 /*
53 * Define BOTAN_CLANG_VERSION
54 */
55 #ifdef __clang__
56  #define BOTAN_CLANG_VERSION (__clang_major__ * 10 + __clang_minor__)
57 #else
58  #define BOTAN_CLANG_VERSION 0
59 #endif
60 
61 /*
62 * Define special macro when building under MSVC 2013 since there are
63 * many compiler workarounds required for that version.
64 */
65 #if defined(_MSC_VER) && (_MSC_VER < 1900)
66  #define BOTAN_BUILD_COMPILER_IS_MSVC_2013
67 #endif
68 
69 /*
70 * Define BOTAN_FUNC_ISA
71 */
72 #if (defined(__GNUG__) && !defined(__clang__)) || (BOTAN_CLANG_VERSION > 38)
73  #define BOTAN_FUNC_ISA(isa) __attribute__ ((target(isa)))
74 #else
75  #define BOTAN_FUNC_ISA(isa)
76 #endif
77 
78 /*
79 * Define BOTAN_WARN_UNUSED_RESULT
80 */
81 #if defined(__GNUG__) || defined(__clang__)
82  #define BOTAN_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
83 #else
84  #define BOTAN_WARN_UNUSED_RESULT
85 #endif
86 
87 /*
88 * Define BOTAN_MALLOC_FN
89 */
90 #if defined(__GNUG__) || defined(__clang__)
91  #define BOTAN_MALLOC_FN __attribute__ ((malloc))
92 #elif defined(_MSC_VER)
93  #define BOTAN_MALLOC_FN __declspec(restrict)
94 #else
95  #define BOTAN_MALLOC_FN
96 #endif
97 
98 /*
99 * Define BOTAN_DEPRECATED
100 */
101 #if !defined(BOTAN_NO_DEPRECATED_WARNINGS)
102 
103  #if defined(__clang__)
104  #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated))
105 
106  #elif defined(_MSC_VER)
107  #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg))
108 
109  #elif defined(__GNUG__)
110  // msg supported since GCC 4.5, earliest we support is 4.8
111  #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
112  #endif
113 
114 #endif
115 
116 #if !defined(BOTAN_DEPRECATED)
117  #define BOTAN_DEPRECATED(msg)
118 #endif
119 
120 /*
121 * Define BOTAN_NORETURN
122 */
123 #if !defined(BOTAN_NORETURN)
124 
125  #if defined (__clang__) || defined (__GNUG__)
126  #define BOTAN_NORETURN __attribute__ ((__noreturn__))
127 
128  #elif defined (_MSC_VER)
129  #define BOTAN_NORETURN __declspec(noreturn)
130 
131  #else
132  #define BOTAN_NORETURN
133  #endif
134 
135 #endif
136 
137 /*
138 * Define BOTAN_CURRENT_FUNCTION
139 */
140 #if defined(_MSC_VER)
141  #define BOTAN_CURRENT_FUNCTION __FUNCTION__
142 #else
143  #define BOTAN_CURRENT_FUNCTION __func__
144 #endif
145 
146 /*
147 * Define BOTAN_NOEXCEPT (for MSVC 2013)
148 */
149 #if defined(BOTAN_BUILD_COMPILER_IS_MSVC_2013)
150  // noexcept is not supported in VS 2013
151  #include <yvals.h>
152  #define BOTAN_NOEXCEPT _NOEXCEPT
153 #else
154  #define BOTAN_NOEXCEPT noexcept
155 #endif
156 
157 /*
158 * Define BOTAN_ALIGNAS (for MSVC 2013)
159 */
160 #if defined(BOTAN_BUILD_COMPILER_IS_MSVC_2013)
161  #define BOTAN_ALIGNAS(n) /**/
162 #else
163  #define BOTAN_ALIGNAS(n) alignas(n)
164 #endif
165 
166 /*
167 * Define BOTAN_PARALLEL_FOR
168 */
169 #if !defined(BOTAN_PARALLEL_FOR)
170 
171 #if defined(BOTAN_TARGET_HAS_OPENMP)
172  #define BOTAN_PARALLEL_FOR _Pragma("omp parallel for") for
173 #else
174  #define BOTAN_PARALLEL_FOR for
175 #endif
176 
177 #endif
178 
179 /*
180 * Define BOTAN_PARALLEL_SIMD_FOR
181 */
182 #if !defined(BOTAN_PARALLEL_SIMD_FOR)
183 
184 #if defined(BOTAN_TARGET_HAS_OPENMP)
185  #define BOTAN_PARALLEL_SIMD_FOR _Pragma("omp simd") for
186 #elif defined(BOTAN_BUILD_COMPILER_IS_GCC) && (BOTAN_GCC_VERSION >= 490)
187  #define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
188 #else
189  #define BOTAN_PARALLEL_SIMD_FOR for
190 #endif
191 
192 #endif
193 
194 #endif