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