Botan 3.0.0-alpha0
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_FUNC_ISA
55*/
56#if defined(__GNUC__) || defined(__clang__)
57 #define BOTAN_FUNC_ISA(isa) __attribute__ ((target(isa)))
58#else
59 #define BOTAN_FUNC_ISA(isa)
60#endif
61
62/*
63* Define BOTAN_MALLOC_FN
64*/
65#if defined(__ibmxl__)
66 /* XLC pretends to be both Clang and GCC, but is neither */
67 #define BOTAN_MALLOC_FN __attribute__ ((malloc))
68#elif defined(__GNUC__)
69 #define BOTAN_MALLOC_FN __attribute__ ((malloc, alloc_size(1,2)))
70#elif defined(_MSC_VER)
71 #define BOTAN_MALLOC_FN __declspec(restrict)
72#else
73 #define BOTAN_MALLOC_FN
74#endif
75
76/*
77* Define BOTAN_DEPRECATED
78*/
79#if !defined(BOTAN_NO_DEPRECATED_WARNINGS) && !defined(BOTAN_AMALGAMATION_H_)
80
81 #if defined(__cplusplus)
82 #define BOTAN_DEPRECATED(msg) [[deprecated(msg)]]
83 #elif defined(__clang__) || defined(__GNUC__)
84 #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
85 #elif defined(_MSC_VER)
86 #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg))
87 #endif
88
89 #if !defined(BOTAN_IS_BEING_BUILT)
90 #if defined(__clang__)
91 #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("message \"this header is deprecated\"")
92 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("message \"this header will be made internal in the future\"")
93 #elif defined(_MSC_VER)
94 #define BOTAN_DEPRECATED_HEADER(hdr) __pragma(message("this header is deprecated"))
95 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) __pragma(message("this header will be made internal in the future"))
96 #elif defined(__GNUC__)
97 #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("GCC warning \"this header is deprecated\"")
98 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("GCC warning \"this header will be made internal in the future\"")
99 #endif
100 #endif
101
102#endif
103
104#if !defined(BOTAN_DEPRECATED)
105 #define BOTAN_DEPRECATED(msg)
106#endif
107
108#if !defined(BOTAN_DEPRECATED_HEADER)
109 #define BOTAN_DEPRECATED_HEADER(hdr)
110#endif
111
112#if !defined(BOTAN_FUTURE_INTERNAL_HEADER)
113 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
114#endif
115
116/*
117* Define BOTAN_FORCE_INLINE
118*/
119#if !defined(BOTAN_FORCE_INLINE)
120
121 #if defined (__clang__) || defined (__GNUC__)
122 #define BOTAN_FORCE_INLINE __attribute__ ((__always_inline__)) inline
123
124 #elif defined (_MSC_VER)
125 #define BOTAN_FORCE_INLINE __forceinline
126
127 #else
128 #define BOTAN_FORCE_INLINE inline
129 #endif
130
131#endif
132
133/*
134* Define BOTAN_PARALLEL_SIMD_FOR
135*/
136#if !defined(BOTAN_PARALLEL_SIMD_FOR)
137
138#if defined(BOTAN_BUILD_COMPILER_IS_GCC)
139 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
140#else
141 #define BOTAN_PARALLEL_SIMD_FOR for
142#endif
143
144#endif
145
146#if defined(BOTAN_BUILD_COMPILER_IS_GCC) || defined(BOTAN_BUILD_COMPILER_IS_CLANG)
147
148 #if defined(BOTAN_BUILD_COMPILER_IS_GCC)
149 #define BOTAN_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
150 #define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
151 #define BOTAN_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
152 #elif defined(BOTAN_BUILD_COMPILER_IS_CLANG)
153 #define BOTAN_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
154 #define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
155 #define BOTAN_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
156 #endif
157
158#endif
159
160#endif