Commit | Line | Data |
---|---|---|
4fee8096 JA |
1 | #ifndef FIO_COMPILER_H |
2 | #define FIO_COMPILER_H | |
3 | ||
c473a9bd | 4 | /* IWYU pragma: begin_exports */ |
5b3da165 | 5 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) || __clang_major__ >= 6 |
4fee8096 | 6 | #include "compiler-gcc4.h" |
4fee8096 | 7 | #else |
baa16486 | 8 | #error Compiler too old, need at least gcc 4.9 |
4fee8096 | 9 | #endif |
c473a9bd | 10 | /* IWYU pragma: end_exports */ |
4fee8096 | 11 | |
993cca04 JA |
12 | #ifndef __must_check |
13 | #define __must_check | |
14 | #endif | |
15 | ||
7b4203d7 JA |
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 | ||
225ba9e3 JA |
23 | #define fio_unlikely(x) __builtin_expect(!!(x), 0) |
24 | ||
ff8039b7 JA |
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; \ | |
3376ecf4 | 31 | __typeof__(x) __dummy2; \ |
ff8039b7 JA |
32 | (void)(&__dummy == &__dummy2); \ |
33 | 1; \ | |
34 | }) | |
35 | ||
5018f79f AH |
36 | |
37 | #if defined(CONFIG_STATIC_ASSERT) | |
38 | #define compiletime_assert(condition, msg) _Static_assert(condition, msg) | |
39 | ||
484817a9 JA |
40 | #elif !defined(CONFIG_DISABLE_OPTIMIZATIONS) |
41 | ||
029716a2 JA |
42 | #ifndef __compiletime_error |
43 | #define __compiletime_error(message) | |
44 | #endif | |
484817a9 | 45 | |
029716a2 JA |
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 | ||
484817a9 JA |
65 | #else |
66 | ||
67 | #define compiletime_assert(condition, msg) do { } while (0) | |
68 | ||
4fee8096 | 69 | #endif |
5018f79f | 70 | |
c26438ad JA |
71 | #ifdef FIO_INTERNAL |
72 | #define ARRAY_SIZE(x) (sizeof((x)) / (sizeof((x)[0]))) | |
3376ecf4 | 73 | #define FIELD_SIZE(s, f) (sizeof(((__typeof__(s))0)->f)) |
c26438ad JA |
74 | #endif |
75 | ||
5018f79f | 76 | #endif |