1#ifndef MY_COMPILER_INCLUDED
2#define MY_COMPILER_INCLUDED
36#ifndef MYSQL_ABI_CHECK
51#ifdef HAVE_BUILTIN_EXPECT
54#if defined(__cplusplus)
55constexpr bool likely(
bool expr) {
return __builtin_expect(expr,
true); }
56constexpr bool unlikely(
bool expr) {
return __builtin_expect(expr,
false); }
58#define likely(x) __builtin_expect((x), 1)
59#define unlikely(x) __builtin_expect((x), 0)
64#if defined(__cplusplus)
65constexpr bool likely(
bool expr) {
return expr; }
66constexpr bool unlikely(
bool expr) {
return expr; }
69#define unlikely(x) (x)
75#ifdef HAVE_BUILTIN_UNREACHABLE
76#define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
78#define MY_ASSERT_UNREACHABLE() \
85#if !defined(__cplusplus) && defined(_MSC_VER)
86#define inline __inline
91#define __func__ __FUNCTION__
100#if defined(__GNUC__) || defined(__clang__)
101#define MY_ATTRIBUTE(A) __attribute__(A)
103#define MY_ATTRIBUTE(A)
108#define ALWAYS_INLINE __forceinline
110#define ALWAYS_INLINE __attribute__((always_inline)) inline
114#define NO_INLINE __declspec(noinline)
116#define NO_INLINE __attribute__((noinline))
119#ifndef __has_attribute
120#define __has_attribute(x) 0
123#ifndef SUPPRESS_UBSAN
125#if defined(HAVE_UBSAN) && defined(__clang__)
126#define SUPPRESS_UBSAN MY_ATTRIBUTE((no_sanitize("undefined")))
127#if (__clang_major__ >= 10)
128#define SUPPRESS_UBSAN_CLANG10 MY_ATTRIBUTE((no_sanitize("undefined")))
131#elif defined(HAVE_UBSAN) && __has_attribute(no_sanitize_undefined)
132#define SUPPRESS_UBSAN MY_ATTRIBUTE((no_sanitize_undefined))
134#define SUPPRESS_UBSAN
139#ifndef SUPPRESS_UBSAN_CLANG10
140#define SUPPRESS_UBSAN_CLANG10
144#if defined(HAVE_TSAN) && defined(__clang__)
145#define SUPPRESS_TSAN MY_ATTRIBUTE((no_sanitize("thread")))
146#elif defined(HAVE_TSAN) && __has_attribute(no_sanitize_thread)
147#define SUPPRESS_TSAN MY_ATTRIBUTE((no_sanitize_thread))
154#define STDCALL __stdcall
162#define MY_COMPILER_CPP11_PRAGMA(X) _Pragma(#X)
166#define MY_COMPILER_MSVC_PRAGMA(X) __pragma(X)
195#if defined(__clang__)
196#define MY_COMPILER_CLANG_DIAGNOSTIC_PUSH() \
197 MY_COMPILER_CPP11_PRAGMA(clang diagnostic push)
198#define MY_COMPILER_CLANG_DIAGNOSTIC_POP() \
199 MY_COMPILER_CPP11_PRAGMA(clang diagnostic pop)
205#define MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE(X) \
206 MY_COMPILER_CPP11_PRAGMA(clang diagnostic ignored X)
213#define MY_COMPILER_CLANG_DIAGNOSTIC_ERROR(X) \
214 MY_COMPILER_CPP11_PRAGMA(clang diagnostic error X)
216#elif defined(__GNUC__)
217#define MY_COMPILER_GCC_DIAGNOSTIC_PUSH() \
218 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic push)
219#define MY_COMPILER_GCC_DIAGNOSTIC_POP() \
220 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic pop)
226#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X) \
227 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic ignored X)
234#define MY_COMPILER_GCC_DIAGNOSTIC_ERROR(X) \
235 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic error X)
240#define MY_COMPILER_MSVC_DIAGNOSTIC_PUSH() \
241 MY_COMPILER_MSVC_PRAGMA(warning(push))
242#define MY_COMPILER_MSVC_DIAGNOSTIC_POP() MY_COMPILER_MSVC_PRAGMA(warning(pop))
248#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X) \
249 MY_COMPILER_MSVC_PRAGMA(warning(disable : X))
250#define MY_COMPILER_MSVC_DIAGNOSTIC_ERROR(X) \
251 MY_COMPILER_MSVC_PRAGMA(warning(error : X))
255#if !defined(MY_COMPILER_CLANG_DIAGNOSTIC_ERROR)
256#define MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE(X)
257#define MY_COMPILER_CLANG_DIAGNOSTIC_ERROR(X)
260#if !defined(MY_COMPILER_GCC_DIAGNOSTIC_ERROR)
261#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X)
262#define MY_COMPILER_GCC_DIAGNOSTIC_ERROR(X)
265#if !defined(MY_COMPILER_MSVC_DIAGNOSTIC_ERROR)
266#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X)
267#define MY_COMPILER_MSVC_DIAGNOSTIC_ERROR(X)
286#if defined(__clang__)
287#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_CLANG_DIAGNOSTIC_PUSH()
288#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_CLANG_DIAGNOSTIC_POP()
289#elif defined(__GNUC__)
290#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_GCC_DIAGNOSTIC_PUSH()
291#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_GCC_DIAGNOSTIC_POP()
292#elif defined(_MSC_VER)
293#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_MSVC_DIAGNOSTIC_PUSH()
294#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_MSVC_DIAGNOSTIC_POP()
296#define MY_COMPILER_DIAGNOSTIC_PUSH()
297#define MY_COMPILER_DIAGNOSTIC_POP()
319#define MY_COMPILER_CLANG_WORKAROUND_TPARAM_DOCBUG() \
320 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wdocumentation")
343#define MY_COMPILER_CLANG_WORKAROUND_REF_DOCBUG() \
344 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wdocumentation")
367#define MY_COMPILER_CLANG_WORKAROUND_FALSE_POSITIVE_UNUSED_VARIABLE_WARNING() \
368 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wunused-variable")
constexpr bool likely(bool expr)
Definition: my_compiler.h:55
constexpr bool unlikely(bool expr)
Definition: my_compiler.h:56