Botan 3.9.0
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/api.h>
12#include <botan/build.h>
13
14// NOLINTBEGIN(*-macro-usage)
15
17
18/*
19* Define BOTAN_COMPILER_HAS_BUILTIN
20*/
21#if defined(__has_builtin)
22 #define BOTAN_COMPILER_HAS_BUILTIN(x) __has_builtin(x)
23#else
24 #define BOTAN_COMPILER_HAS_BUILTIN(x) 0
25#endif
26
27/*
28* Define BOTAN_COMPILER_HAS_ATTRIBUTE
29*/
30#if defined(__has_attribute)
31 #define BOTAN_COMPILER_HAS_ATTRIBUTE(x) __has_attribute(x)
32 #define BOTAN_COMPILER_ATTRIBUTE(x) __attribute__((x))
33#else
34 #define BOTAN_COMPILER_HAS_ATTRIBUTE(x) 0
35 #define BOTAN_COMPILER_ATTRIBUTE(x) /**/
36#endif
37
38/*
39* Hack for Loongarch64 GCC bug
40*
41* For some reason __has_attribute(target) is true, but it does not support the
42* target attribute... this supposedly is fixed in GCC 15 but this is untested.
43*/
44#if defined(__GNUC__) && defined(__loongarch64) && (__GNUC__ <= 14)
45 #define BOTAN_COMPILER_DOES_NOT_HAVE_TARGET_ATTRIBUTE
46#endif
47
48/*
49* Define BOTAN_FUNC_ISA
50*
51* TODO(Botan4) Move this to isa_extn.h
52*/
53#if BOTAN_COMPILER_HAS_ATTRIBUTE(target) && !defined(BOTAN_COMPILER_DOES_NOT_HAVE_TARGET_ATTRIBUTE)
54 #define BOTAN_FUNC_ISA(isa) BOTAN_COMPILER_ATTRIBUTE(target(isa))
55#else
56 #define BOTAN_FUNC_ISA(isa)
57#endif
58
59/*
60* Define BOTAN_FUNC_ISA_INLINE
61*
62* TODO(Botan4) Remove this
63*/
64#define BOTAN_FUNC_ISA_INLINE(isa) BOTAN_FUNC_ISA(isa) BOTAN_FORCE_INLINE
65
66/*
67* Define BOTAN_EARLY_INIT
68*/
69#if BOTAN_COMPILER_HAS_ATTRIBUTE(init_priority)
70 #define BOTAN_EARLY_INIT(prio) BOTAN_COMPILER_ATTRIBUTE(init_priority(prio))
71#else
72 #define BOTAN_EARLY_INIT(prio) /**/
73#endif
74
75/*
76* Define BOTAN_FORCE_INLINE
77*/
78#if !defined(BOTAN_FORCE_INLINE)
79
80 #if BOTAN_COMPILER_HAS_ATTRIBUTE(always_inline)
81 #define BOTAN_FORCE_INLINE inline BOTAN_COMPILER_ATTRIBUTE(always_inline)
82
83 #elif defined(_MSC_VER)
84 #define BOTAN_FORCE_INLINE __forceinline
85
86 #else
87 #define BOTAN_FORCE_INLINE inline
88 #endif
89
90#endif
91
92// NOLINTEND(*-macro-usage)
93
94#endif
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition api.h:98