Botan 3.6.1
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#ifndef BOTAN_UTIL_COMPILER_FLAGS_H_
9#define BOTAN_UTIL_COMPILER_FLAGS_H_
10
11#include <botan/build.h>
12
13/*
14NOTE: Avoid using BOTAN_COMPILER_IS_XXX macros anywhere in this file
15
16This macro is set based on what compiler was used to build the
17library, but it is possible that the library is built with one
18compiler and then the application is built using another.
19
20For example using BOTAN_COMPILER_IS_CLANG would trigger (incorrectly)
21when the application is later compiled using GCC.
22*/
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_DEPRECATED(msg) BOTAN_DLL
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* Used to annotate API exports which are exported but only for the
55* purposes of fuzzing. They should not be used by applications and
56* may be removed or changed without notice.
57*
58* They are only exported if the fuzzers are being built
59*/
60#if defined(BOTAN_FUZZERS_ARE_BEING_BUILT)
61 #define BOTAN_FUZZER_API BOTAN_DLL
62#else
63 #define BOTAN_FUZZER_API
64#endif
65
66/*
67* Define BOTAN_COMPILER_HAS_BUILTIN
68*/
69#if defined(__has_builtin)
70 #define BOTAN_COMPILER_HAS_BUILTIN(x) __has_builtin(x)
71#else
72 #define BOTAN_COMPILER_HAS_BUILTIN(x) 0
73#endif
74
75/*
76* Define BOTAN_COMPILER_HAS_ATTRIBUTE
77*/
78#if defined(__has_attribute)
79 #define BOTAN_COMPILER_HAS_ATTRIBUTE(x) __has_attribute(x)
80 #define BOTAN_COMPILER_ATTRIBUTE(x) __attribute__((x))
81#else
82 #define BOTAN_COMPILER_HAS_ATTRIBUTE(x) 0
83 #define BOTAN_COMPILER_ATTRIBUTE(x) /**/
84#endif
85
86/*
87* Define BOTAN_FUNC_ISA
88*/
89#if BOTAN_COMPILER_HAS_ATTRIBUTE(target)
90 #define BOTAN_FUNC_ISA(isa) BOTAN_COMPILER_ATTRIBUTE(target(isa))
91#else
92 #define BOTAN_FUNC_ISA(isa)
93#endif
94
95/*
96* Define BOTAN_FUNC_ISA_INLINE
97*/
98#define BOTAN_FUNC_ISA_INLINE(isa) BOTAN_FUNC_ISA(isa) BOTAN_FORCE_INLINE
99
100/*
101* Define BOTAN_MALLOC_FN
102*/
103#if BOTAN_COMPILER_HAS_ATTRIBUTE(malloc)
104 #define BOTAN_MALLOC_FN BOTAN_COMPILER_ATTRIBUTE(malloc)
105#elif defined(_MSC_VER)
106 #define BOTAN_MALLOC_FN __declspec(restrict)
107#else
108 #define BOTAN_MALLOC_FN
109#endif
110
111/*
112* Define BOTAN_EARLY_INIT
113*/
114#if BOTAN_COMPILER_HAS_ATTRIBUTE(init_priority)
115 #define BOTAN_EARLY_INIT(prio) BOTAN_COMPILER_ATTRIBUTE(init_priority(prio))
116#else
117 #define BOTAN_EARLY_INIT(prio) /**/
118#endif
119
120/*
121* Define BOTAN_DEPRECATED
122*/
123#if !defined(BOTAN_NO_DEPRECATED_WARNINGS) && !defined(BOTAN_AMALGAMATION_H_) && !defined(BOTAN_IS_BEING_BUILT)
124
125 #define BOTAN_DEPRECATED(msg) [[deprecated(msg)]]
126
127 #if defined(__clang__)
128 #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("message \"this header is deprecated\"")
129 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("message \"this header will be made internal in the future\"")
130 #elif defined(_MSC_VER)
131 #define BOTAN_DEPRECATED_HEADER(hdr) __pragma(message("this header is deprecated"))
132 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) __pragma(message("this header will be made internal in the future"))
133 #elif defined(__GNUC__)
134 #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("GCC warning \"this header is deprecated\"")
135 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr) \
136 _Pragma("GCC warning \"this header will be made internal in the future\"")
137 #endif
138
139#endif
140
141#if !defined(BOTAN_DEPRECATED)
142 #define BOTAN_DEPRECATED(msg)
143#endif
144
145#if !defined(BOTAN_DEPRECATED_HEADER)
146 #define BOTAN_DEPRECATED_HEADER(hdr)
147#endif
148
149#if !defined(BOTAN_FUTURE_INTERNAL_HEADER)
150 #define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
151#endif
152
153/*
154* Define BOTAN_FORCE_INLINE
155*/
156#if !defined(BOTAN_FORCE_INLINE)
157
158 #if BOTAN_COMPILER_HAS_ATTRIBUTE(always_inline)
159 #define BOTAN_FORCE_INLINE inline BOTAN_COMPILER_ATTRIBUTE(always_inline)
160
161 #elif defined(_MSC_VER)
162 #define BOTAN_FORCE_INLINE __forceinline
163
164 #else
165 #define BOTAN_FORCE_INLINE inline
166 #endif
167
168#endif
169
170#if defined(__clang__)
171 #define BOTAN_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
172 #define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
173 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
174 #define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
175 #define BOTAN_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
176#elif defined(__GNUG__)
177 #define BOTAN_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
178 #define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
179 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
180 #define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
181 #define BOTAN_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
182#elif defined(_MSC_VER)
183 #define BOTAN_DIAGNOSTIC_PUSH __pragma(warning(push))
184 #define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS __pragma(warning(disable : 4996))
185 #define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE __pragma(warning(disable : 4250))
186 #define BOTAN_DIAGNOSTIC_POP __pragma(warning(pop))
187#else
188 #define BOTAN_DIAGNOSTIC_PUSH
189 #define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
190 #define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
191 #define BOTAN_DIAGNOSTIC_POP
192#endif
193
194#endif