| /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ |
| |
| #ifndef _LINUX_COMPILER_H_ |
| #define _LINUX_COMPILER_H_ |
| |
| #include <linux/compiler_types.h> |
| |
| #if defined(__OPTIMIZE__) && __has_attribute(__error__) |
| # define __compiletime_assert(condition, msg, prefix, suffix) \ |
| do { \ |
| extern void prefix ## suffix(void) __compiletime_error(msg); \ |
| if (!(condition)) \ |
| prefix ## suffix(); \ |
| } while (0) |
| #else |
| # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) |
| #endif |
| |
| #define _compiletime_assert(condition, msg, prefix, suffix) \ |
| __compiletime_assert(condition, msg, prefix, suffix) |
| |
| /** |
| * compiletime_assert - break build and emit msg if condition is false |
| * @condition: a compile-time constant condition to check |
| * @msg: a message to emit if condition is false |
| * |
| * In tradition of POSIX assert, this macro will break the build if the |
| * supplied condition is *false*, emitting the supplied error message if the |
| * compiler has support to do so. |
| */ |
| #define compiletime_assert(condition, msg) \ |
| _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) |
| |
| /* Are two types/vars the same type (ignoring qualifiers)? */ |
| #ifndef __same_type |
| # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) |
| #endif |
| |
| #ifndef __maybe_unused |
| # define __maybe_unused __attribute__((unused)) |
| #endif |
| |
| #ifndef __weak |
| # define __weak __attribute__((weak)) |
| #endif |
| |
| #endif |