Botan  2.9.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 #ifdef __GNUC__
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 #ifdef __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(__GNUG__) || defined(__clang__)
87  #define BOTAN_MALLOC_FN __attribute__ ((malloc))
88 #elif defined(_MSC_VER)
89  #define BOTAN_MALLOC_FN __declspec(restrict)
90 #else
91  #define BOTAN_MALLOC_FN
92 #endif
93 
94 /*
95 * Define BOTAN_DEPRECATED
96 */
97 #if !defined(BOTAN_NO_DEPRECATED_WARNINGS)
98 
99  #if defined(__clang__)
100  #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated))
101 
102  #elif defined(_MSC_VER)
103  #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg))
104 
105  #elif defined(__GNUG__)
106  // msg supported since GCC 4.5, earliest we support is 4.8
107  #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
108  #endif
109 
110 #endif
111 
112 #if !defined(BOTAN_DEPRECATED)
113  #define BOTAN_DEPRECATED(msg)
114 #endif
115 
116 /*
117 * Define BOTAN_NORETURN
118 */
119 #if !defined(BOTAN_NORETURN)
120 
121  #if defined (__clang__) || defined (__GNUG__)
122  #define BOTAN_NORETURN __attribute__ ((__noreturn__))
123 
124  #elif defined (_MSC_VER)
125  #define BOTAN_NORETURN __declspec(noreturn)
126 
127  #else
128  #define BOTAN_NORETURN
129  #endif
130 
131 #endif
132 
133 /*
134 * Define BOTAN_PARALLEL_FOR
135 */
136 #if !defined(BOTAN_PARALLEL_FOR)
137 
138 #if defined(BOTAN_TARGET_HAS_OPENMP)
139  #define BOTAN_PARALLEL_FOR _Pragma("omp parallel for") for
140 #else
141  #define BOTAN_PARALLEL_FOR for
142 #endif
143 
144 #endif
145 
146 /*
147 * Define BOTAN_PARALLEL_SIMD_FOR
148 */
149 #if !defined(BOTAN_PARALLEL_SIMD_FOR)
150 
151 #if defined(BOTAN_TARGET_HAS_OPENMP)
152  #define BOTAN_PARALLEL_SIMD_FOR _Pragma("omp simd") for
153 #elif defined(BOTAN_BUILD_COMPILER_IS_GCC) && (BOTAN_GCC_VERSION >= 490)
154  #define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
155 #else
156  #define BOTAN_PARALLEL_SIMD_FOR for
157 #endif
158 
159 #endif
160 
161 #endif