1#ifndef MY_COMPILER_INCLUDED
2#define MY_COMPILER_INCLUDED
36#ifndef MYSQL_ABI_CHECK
53#ifdef HAVE_BUILTIN_EXPECT
56#if defined(__cplusplus)
57constexpr bool likely(
bool expr) {
return __builtin_expect(expr,
true); }
58constexpr bool unlikely(
bool expr) {
return __builtin_expect(expr,
false); }
60#define likely(x) __builtin_expect((x), 1)
61#define unlikely(x) __builtin_expect((x), 0)
66#if defined(__cplusplus)
67constexpr bool likely(
bool expr) {
return expr; }
68constexpr bool unlikely(
bool expr) {
return expr; }
71#define unlikely(x) (x)
77#ifdef HAVE_BUILTIN_UNREACHABLE
78#define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
80#define MY_ASSERT_UNREACHABLE() \
87#if !defined(__cplusplus) && defined(_MSC_VER)
88#define inline __inline
93#define __func__ __FUNCTION__
97#define ALWAYS_INLINE __forceinline
99#define ALWAYS_INLINE __attribute__((always_inline)) inline
103#define NO_INLINE __declspec(noinline)
105#define NO_INLINE __attribute__((noinline))
108#ifndef __has_attribute
109#define __has_attribute(x) 0
112#ifndef SUPPRESS_UBSAN
114#if defined(HAVE_UBSAN) && defined(__clang__)
115#define SUPPRESS_UBSAN MY_ATTRIBUTE((no_sanitize("undefined")))
117#elif defined(HAVE_UBSAN) && __has_attribute(no_sanitize_undefined)
118#define SUPPRESS_UBSAN MY_ATTRIBUTE((no_sanitize_undefined))
120#define SUPPRESS_UBSAN
125#if defined(HAVE_TSAN) && defined(__clang__)
126#define SUPPRESS_TSAN MY_ATTRIBUTE((no_sanitize("thread")))
127#elif defined(HAVE_TSAN) && __has_attribute(no_sanitize_thread)
128#define SUPPRESS_TSAN MY_ATTRIBUTE((no_sanitize_thread))
135#define STDCALL __stdcall
143#define MY_COMPILER_CPP11_PRAGMA(X) _Pragma(#X)
147#define MY_COMPILER_MSVC_PRAGMA(X) __pragma(X)
176#if defined(__clang__)
177#define MY_COMPILER_CLANG_DIAGNOSTIC_PUSH() \
178 MY_COMPILER_CPP11_PRAGMA(clang diagnostic push)
179#define MY_COMPILER_CLANG_DIAGNOSTIC_POP() \
180 MY_COMPILER_CPP11_PRAGMA(clang diagnostic pop)
186#define MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE(X) \
187 MY_COMPILER_CPP11_PRAGMA(clang diagnostic ignored X)
194#define MY_COMPILER_CLANG_DIAGNOSTIC_ERROR(X) \
195 MY_COMPILER_CPP11_PRAGMA(clang diagnostic error X)
197#elif defined(__GNUC__)
198#define MY_COMPILER_GCC_DIAGNOSTIC_PUSH() \
199 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic push)
200#define MY_COMPILER_GCC_DIAGNOSTIC_POP() \
201 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic pop)
207#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X) \
208 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic ignored X)
215#define MY_COMPILER_GCC_DIAGNOSTIC_ERROR(X) \
216 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic error X)
221#define MY_COMPILER_MSVC_DIAGNOSTIC_PUSH() \
222 MY_COMPILER_MSVC_PRAGMA(warning(push))
223#define MY_COMPILER_MSVC_DIAGNOSTIC_POP() MY_COMPILER_MSVC_PRAGMA(warning(pop))
229#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X) \
230 MY_COMPILER_MSVC_PRAGMA(warning(disable : X))
231#define MY_COMPILER_MSVC_DIAGNOSTIC_ERROR(X) \
232 MY_COMPILER_MSVC_PRAGMA(warning(error : X))
236#if !defined(MY_COMPILER_CLANG_DIAGNOSTIC_ERROR)
237#define MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE(X)
238#define MY_COMPILER_CLANG_DIAGNOSTIC_ERROR(X)
241#if !defined(MY_COMPILER_GCC_DIAGNOSTIC_ERROR)
242#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X)
243#define MY_COMPILER_GCC_DIAGNOSTIC_ERROR(X)
246#if !defined(MY_COMPILER_MSVC_DIAGNOSTIC_ERROR)
247#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X)
248#define MY_COMPILER_MSVC_DIAGNOSTIC_ERROR(X)
267#if defined(__clang__)
268#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_CLANG_DIAGNOSTIC_PUSH()
269#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_CLANG_DIAGNOSTIC_POP()
270#elif defined(__GNUC__)
271#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_GCC_DIAGNOSTIC_PUSH()
272#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_GCC_DIAGNOSTIC_POP()
273#elif defined(_MSC_VER)
274#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_MSVC_DIAGNOSTIC_PUSH()
275#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_MSVC_DIAGNOSTIC_POP()
277#define MY_COMPILER_DIAGNOSTIC_PUSH()
278#define MY_COMPILER_DIAGNOSTIC_POP()
300#define MY_COMPILER_CLANG_WORKAROUND_TPARAM_DOCBUG() \
301 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wdocumentation")
324#define MY_COMPILER_CLANG_WORKAROUND_REF_DOCBUG() \
325 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wdocumentation")
348#define MY_COMPILER_CLANG_WORKAROUND_FALSE_POSITIVE_UNUSED_VARIABLE_WARNING() \
349 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wunused-variable")
constexpr bool likely(bool expr)
Definition: my_compiler.h:57
constexpr bool unlikely(bool expr)
Definition: my_compiler.h:58