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")))
116#if (__clang_major__ >= 10)
117#define SUPPRESS_UBSAN_CLANG10 MY_ATTRIBUTE((no_sanitize("undefined")))
120#elif defined(HAVE_UBSAN) && __has_attribute(no_sanitize_undefined)
121#define SUPPRESS_UBSAN MY_ATTRIBUTE((no_sanitize_undefined))
123#define SUPPRESS_UBSAN
128#ifndef SUPPRESS_UBSAN_CLANG10
129#define SUPPRESS_UBSAN_CLANG10
133#if defined(HAVE_TSAN) && defined(__clang__)
134#define SUPPRESS_TSAN MY_ATTRIBUTE((no_sanitize("thread")))
135#elif defined(HAVE_TSAN) && __has_attribute(no_sanitize_thread)
136#define SUPPRESS_TSAN MY_ATTRIBUTE((no_sanitize_thread))
143#define STDCALL __stdcall
151#define MY_COMPILER_CPP11_PRAGMA(X) _Pragma(#X)
155#define MY_COMPILER_MSVC_PRAGMA(X) __pragma(X)
184#if defined(__clang__)
185#define MY_COMPILER_CLANG_DIAGNOSTIC_PUSH() \
186 MY_COMPILER_CPP11_PRAGMA(clang diagnostic push)
187#define MY_COMPILER_CLANG_DIAGNOSTIC_POP() \
188 MY_COMPILER_CPP11_PRAGMA(clang diagnostic pop)
194#define MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE(X) \
195 MY_COMPILER_CPP11_PRAGMA(clang diagnostic ignored X)
202#define MY_COMPILER_CLANG_DIAGNOSTIC_ERROR(X) \
203 MY_COMPILER_CPP11_PRAGMA(clang diagnostic error X)
205#elif defined(__GNUC__)
206#define MY_COMPILER_GCC_DIAGNOSTIC_PUSH() \
207 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic push)
208#define MY_COMPILER_GCC_DIAGNOSTIC_POP() \
209 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic pop)
215#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X) \
216 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic ignored X)
223#define MY_COMPILER_GCC_DIAGNOSTIC_ERROR(X) \
224 MY_COMPILER_CPP11_PRAGMA(GCC diagnostic error X)
229#define MY_COMPILER_MSVC_DIAGNOSTIC_PUSH() \
230 MY_COMPILER_MSVC_PRAGMA(warning(push))
231#define MY_COMPILER_MSVC_DIAGNOSTIC_POP() MY_COMPILER_MSVC_PRAGMA(warning(pop))
237#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X) \
238 MY_COMPILER_MSVC_PRAGMA(warning(disable : X))
239#define MY_COMPILER_MSVC_DIAGNOSTIC_ERROR(X) \
240 MY_COMPILER_MSVC_PRAGMA(warning(error : X))
244#if !defined(MY_COMPILER_CLANG_DIAGNOSTIC_ERROR)
245#define MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE(X)
246#define MY_COMPILER_CLANG_DIAGNOSTIC_ERROR(X)
249#if !defined(MY_COMPILER_GCC_DIAGNOSTIC_ERROR)
250#define MY_COMPILER_GCC_DIAGNOSTIC_IGNORE(X)
251#define MY_COMPILER_GCC_DIAGNOSTIC_ERROR(X)
254#if !defined(MY_COMPILER_MSVC_DIAGNOSTIC_ERROR)
255#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X)
256#define MY_COMPILER_MSVC_DIAGNOSTIC_ERROR(X)
275#if defined(__clang__)
276#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_CLANG_DIAGNOSTIC_PUSH()
277#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_CLANG_DIAGNOSTIC_POP()
278#elif defined(__GNUC__)
279#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_GCC_DIAGNOSTIC_PUSH()
280#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_GCC_DIAGNOSTIC_POP()
281#elif defined(_MSC_VER)
282#define MY_COMPILER_DIAGNOSTIC_PUSH() MY_COMPILER_MSVC_DIAGNOSTIC_PUSH()
283#define MY_COMPILER_DIAGNOSTIC_POP() MY_COMPILER_MSVC_DIAGNOSTIC_POP()
285#define MY_COMPILER_DIAGNOSTIC_PUSH()
286#define MY_COMPILER_DIAGNOSTIC_POP()
308#define MY_COMPILER_CLANG_WORKAROUND_TPARAM_DOCBUG() \
309 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wdocumentation")
332#define MY_COMPILER_CLANG_WORKAROUND_REF_DOCBUG() \
333 MY_COMPILER_CLANG_DIAGNOSTIC_IGNORE("-Wdocumentation")
356#define MY_COMPILER_CLANG_WORKAROUND_FALSE_POSITIVE_UNUSED_VARIABLE_WARNING() \
357 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