1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 3 #ifndef _LINUX_COMPILER_H_ 4 #define _LINUX_COMPILER_H_ 5 6 #include <linux/compiler_types.h> 7 8 #if defined(__OPTIMIZE__) && __has_attribute(__error__) 9 # define __compiletime_assert(condition, msg, prefix, suffix) \ 10 do { \ 11 extern void prefix ## suffix(void) __compiletime_error(msg); \ 12 if (!(condition)) \ 13 prefix ## suffix(); \ 14 } while (0) 15 #else 16 # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) 17 #endif 18 19 #define _compiletime_assert(condition, msg, prefix, suffix) \ 20 __compiletime_assert(condition, msg, prefix, suffix) 21 22 /** 23 * compiletime_assert - break build and emit msg if condition is false 24 * @condition: a compile-time constant condition to check 25 * @msg: a message to emit if condition is false 26 * 27 * In tradition of POSIX assert, this macro will break the build if the 28 * supplied condition is *false*, emitting the supplied error message if the 29 * compiler has support to do so. 30 */ 31 #define compiletime_assert(condition, msg) \ 32 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) 33 34 /* Are two types/vars the same type (ignoring qualifiers)? */ 35 #ifndef __same_type 36 # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 37 #endif 38 39 #ifndef __maybe_unused 40 # define __maybe_unused __attribute__((unused)) 41 #endif 42 43 #ifndef __weak 44 # define __weak __attribute__((weak)) 45 #endif 46 47 #endif 48