| 1 | #ifndef FIO_COMPILER_H |
| 2 | #define FIO_COMPILER_H |
| 3 | |
| 4 | /* IWYU pragma: begin_exports */ |
| 5 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) |
| 6 | #include "compiler-gcc4.h" |
| 7 | #else |
| 8 | #error Compiler too old, need at least gcc 4.1.0 |
| 9 | #endif |
| 10 | /* IWYU pragma: end_exports */ |
| 11 | |
| 12 | #ifndef __must_check |
| 13 | #define __must_check |
| 14 | #endif |
| 15 | |
| 16 | /* |
| 17 | * Mark unused variables passed to ops functions as unused, to silence gcc |
| 18 | */ |
| 19 | #define fio_unused __attribute__((__unused__)) |
| 20 | #define fio_init __attribute__((constructor)) |
| 21 | #define fio_exit __attribute__((destructor)) |
| 22 | |
| 23 | #define fio_unlikely(x) __builtin_expect(!!(x), 0) |
| 24 | |
| 25 | /* |
| 26 | * Check at compile time that something is of a particular type. |
| 27 | * Always evaluates to 1 so you may use it easily in comparisons. |
| 28 | */ |
| 29 | #define typecheck(type,x) \ |
| 30 | ({ type __dummy; \ |
| 31 | __typeof__(x) __dummy2; \ |
| 32 | (void)(&__dummy == &__dummy2); \ |
| 33 | 1; \ |
| 34 | }) |
| 35 | |
| 36 | |
| 37 | #if defined(CONFIG_STATIC_ASSERT) |
| 38 | #define compiletime_assert(condition, msg) _Static_assert(condition, msg) |
| 39 | |
| 40 | #elif !defined(CONFIG_DISABLE_OPTIMIZATIONS) |
| 41 | |
| 42 | #ifndef __compiletime_error |
| 43 | #define __compiletime_error(message) |
| 44 | #endif |
| 45 | |
| 46 | #ifndef __compiletime_error_fallback |
| 47 | #define __compiletime_error_fallback(condition) do { } while (0) |
| 48 | #endif |
| 49 | |
| 50 | #define __compiletime_assert(condition, msg, prefix, suffix) \ |
| 51 | do { \ |
| 52 | int __cond = !(condition); \ |
| 53 | extern void prefix ## suffix(void) __compiletime_error(msg); \ |
| 54 | if (__cond) \ |
| 55 | prefix ## suffix(); \ |
| 56 | __compiletime_error_fallback(__cond); \ |
| 57 | } while (0) |
| 58 | |
| 59 | #define _compiletime_assert(condition, msg, prefix, suffix) \ |
| 60 | __compiletime_assert(condition, msg, prefix, suffix) |
| 61 | |
| 62 | #define compiletime_assert(condition, msg) \ |
| 63 | _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) |
| 64 | |
| 65 | #else |
| 66 | |
| 67 | #define compiletime_assert(condition, msg) do { } while (0) |
| 68 | |
| 69 | #endif |
| 70 | |
| 71 | #ifdef FIO_INTERNAL |
| 72 | #define ARRAY_SIZE(x) (sizeof((x)) / (sizeof((x)[0]))) |
| 73 | #define FIELD_SIZE(s, f) (sizeof(((__typeof__(s))0)->f)) |
| 74 | #endif |
| 75 | |
| 76 | #endif |