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