Files
nanahi 9281bccfdf osdep/compiler: don't use __has_builtin for __builtin_mul_overflow
The feature test macro is nonstandard and not available on older GCC
version, which causes build failure despite the compiler does support
__builtin_mul_overflow.

Since there are no fallback when __builtin_mul_overflow is not
available, there is no need to check, so simply remove it.
If __builtin_mul_overflow is not supported compilation will still fail
just like currently.
2026-07-06 18:25:12 +02:00

95 lines
2.4 KiB
C

#ifndef MPV_COMPILER_H
#define MPV_COMPILER_H
#include <assert.h>
#include <stdio.h>
#define MP_EXPAND_ARGS(...) __VA_ARGS__
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
#include <stdckdint.h>
#define MP_NORETURN [[noreturn]]
#define MP_FALLTHROUGH [[fallthrough]]
#define MP_WARN_UNUSED_RESULT [[nodiscard]]
#define MP_UNUSED [[maybe_unused]]
#elif defined(__GNUC__) || defined(__clang__)
#define MP_NORETURN __attribute__((noreturn))
#define MP_FALLTHROUGH __attribute__((fallthrough))
#define MP_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define MP_UNUSED __attribute__((unused))
#else
#define MP_NORETURN
#define MP_FALLTHROUGH do {} while (0)
#define MP_WARN_UNUSED_RESULT
#define MP_UNUSED
#endif
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ < 202311L) && !defined(thread_local)
#define thread_local _Thread_local
#endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#if __has_attribute(nonstring)
#define MP_NONSTRING __attribute__((nonstring))
#else
#define MP_NONSTRING
#endif
#if __has_attribute(no_sanitize)
#define MP_NO_ASAN __attribute__((no_sanitize("address")))
#else
#define MP_NO_ASAN
#endif
#ifndef NDEBUG
#define MP_ASSERT_UNREACHABLE() (assert(!"unreachable"), abort())
#elif __has_builtin(__builtin_unreachable)
#define MP_ASSERT_UNREACHABLE() __builtin_unreachable()
#elif defined(_MSC_VER)
#define MP_ASSERT_UNREACHABLE() __assume(0)
#elif __STDC_VERSION__ >= 202311L
#include <stddef.h>
#define MP_ASSERT_UNREACHABLE() unreachable()
#else
#define MP_ASSERT_UNREACHABLE() ((void)0)
#endif
#ifdef __MINGW_PRINTF_FORMAT
#define MP_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
#elif __has_attribute(format)
#define MP_PRINTF_FORMAT __printf__
#endif
#ifdef __MINGW_SCANF_FORMAT
#define MP_SCANF_FORMAT __MINGW_SCANF_FORMAT
#elif __has_attribute(format)
#define MP_SCANF_FORMAT __scanf__
#endif
#ifdef MP_PRINTF_FORMAT
#define MP_PRINTF_ATTRIBUTE(a1, a2) __attribute__((format(MP_PRINTF_FORMAT, a1, a2)))
#else
#define MP_PRINTF_ATTRIBUTE(a1, a2)
#endif
#ifdef MP_SCANF_FORMAT
#define MP_SCANF_ATTRIBUTE(a1, a2) __attribute__((format(MP_SCANF_FORMAT, a1, a2)))
#else
#define MP_SCANF_ATTRIBUTE(a1, a2)
#endif
#if defined(__STDC_VERSION_STDCKDINT_H__) && __STDC_VERSION_STDCKDINT_H__ >= 202311L
#define MP_CKD_MUL(result, a, b) ckd_mul(result, a, b)
#else
#define MP_CKD_MUL(result, a, b) __builtin_mul_overflow(a, b, result)
#endif
#endif