xref: /freebsd/contrib/jemalloc/include/jemalloc/internal/jemalloc_internal_macros.h (revision c43cad87172039ccf38172129c79755ea79e6102)
1 #ifndef JEMALLOC_INTERNAL_MACROS_H
2 #define JEMALLOC_INTERNAL_MACROS_H
3 
4 #ifdef JEMALLOC_DEBUG
5 #  define JEMALLOC_ALWAYS_INLINE static inline
6 #else
7 #  ifdef _MSC_VER
8 #    define JEMALLOC_ALWAYS_INLINE static __forceinline
9 #  else
10 #    define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline
11 #  endif
12 #endif
13 #ifdef _MSC_VER
14 #  define inline _inline
15 #endif
16 
17 #define UNUSED JEMALLOC_ATTR(unused)
18 
19 #define ZU(z)	((size_t)z)
20 #define ZD(z)	((ssize_t)z)
21 #define QU(q)	((uint64_t)q)
22 #define QD(q)	((int64_t)q)
23 
24 #define KZU(z)	ZU(z##ULL)
25 #define KZD(z)	ZD(z##LL)
26 #define KQU(q)	QU(q##ULL)
27 #define KQD(q)	QI(q##LL)
28 
29 #ifndef __DECONST
30 #  define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
31 #endif
32 
33 #if !defined(JEMALLOC_HAS_RESTRICT) || defined(__cplusplus)
34 #  define restrict
35 #endif
36 
37 /* Various function pointers are static and immutable except during testing. */
38 #ifdef JEMALLOC_JET
39 #  define JET_MUTABLE
40 #else
41 #  define JET_MUTABLE const
42 #endif
43 
44 #define JEMALLOC_VA_ARGS_HEAD(head, ...) head
45 #define JEMALLOC_VA_ARGS_TAIL(head, ...) __VA_ARGS__
46 
47 /* Diagnostic suppression macros */
48 #if defined(_MSC_VER) && !defined(__clang__)
49 #  define JEMALLOC_DIAGNOSTIC_PUSH __pragma(warning(push))
50 #  define JEMALLOC_DIAGNOSTIC_POP __pragma(warning(pop))
51 #  define JEMALLOC_DIAGNOSTIC_IGNORE(W) __pragma(warning(disable:W))
52 #  define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS
53 #  define JEMALLOC_DIAGNOSTIC_IGNORE_TYPE_LIMITS
54 #  define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
55 #  define JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS
56 /* #pragma GCC diagnostic first appeared in gcc 4.6. */
57 #elif (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && \
58   (__GNUC_MINOR__ > 5)))) || defined(__clang__)
59 /*
60  * The JEMALLOC_PRAGMA__ macro is an implementation detail of the GCC and Clang
61  * diagnostic suppression macros and should not be used anywhere else.
62  */
63 #  define JEMALLOC_PRAGMA__(X) _Pragma(#X)
64 #  define JEMALLOC_DIAGNOSTIC_PUSH JEMALLOC_PRAGMA__(GCC diagnostic push)
65 #  define JEMALLOC_DIAGNOSTIC_POP JEMALLOC_PRAGMA__(GCC diagnostic pop)
66 #  define JEMALLOC_DIAGNOSTIC_IGNORE(W) \
67      JEMALLOC_PRAGMA__(GCC diagnostic ignored W)
68 
69 /*
70  * The -Wmissing-field-initializers warning is buggy in GCC versions < 5.1 and
71  * all clang versions up to version 7 (currently trunk, unreleased).  This macro
72  * suppresses the warning for the affected compiler versions only.
73  */
74 #  if ((defined(__GNUC__) && !defined(__clang__)) && (__GNUC__ < 5)) || \
75      defined(__clang__)
76 #    define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS  \
77           JEMALLOC_DIAGNOSTIC_IGNORE("-Wmissing-field-initializers")
78 #  else
79 #    define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS
80 #  endif
81 
82 #  define JEMALLOC_DIAGNOSTIC_IGNORE_TYPE_LIMITS  \
83      JEMALLOC_DIAGNOSTIC_IGNORE("-Wtype-limits")
84 #  define JEMALLOC_DIAGNOSTIC_IGNORE_UNUSED_PARAMETER \
85      JEMALLOC_DIAGNOSTIC_IGNORE("-Wunused-parameter")
86 #  if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 7)
87 #    define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN \
88        JEMALLOC_DIAGNOSTIC_IGNORE("-Walloc-size-larger-than=")
89 #  else
90 #    define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
91 #  endif
92 #  define JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS \
93   JEMALLOC_DIAGNOSTIC_PUSH \
94   JEMALLOC_DIAGNOSTIC_IGNORE_UNUSED_PARAMETER
95 #else
96 #  define JEMALLOC_DIAGNOSTIC_PUSH
97 #  define JEMALLOC_DIAGNOSTIC_POP
98 #  define JEMALLOC_DIAGNOSTIC_IGNORE(W)
99 #  define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS
100 #  define JEMALLOC_DIAGNOSTIC_IGNORE_TYPE_LIMITS
101 #  define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
102 #  define JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS
103 #endif
104 
105 /*
106  * Disables spurious diagnostics for all headers.  Since these headers are not
107  * included by users directly, it does not affect their diagnostic settings.
108  */
109 JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS
110 
111 #endif /* JEMALLOC_INTERNAL_MACROS_H */
112