configure: disable compile time asserts for !opt and !static_assert
[fio.git] / compiler / compiler.h
CommitLineData
4fee8096
JA
1#ifndef FIO_COMPILER_H
2#define FIO_COMPILER_H
5018f79f 3#include <assert.h>
4fee8096
JA
4
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
12
993cca04
JA
13#ifndef __must_check
14#define __must_check
15#endif
16
7b4203d7
JA
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
225ba9e3
JA
24#define fio_unlikely(x) __builtin_expect(!!(x), 0)
25
ff8039b7
JA
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
5018f79f
AH
37
38#if defined(CONFIG_STATIC_ASSERT)
39#define compiletime_assert(condition, msg) _Static_assert(condition, msg)
40
484817a9
JA
41#elif !defined(CONFIG_DISABLE_OPTIMIZATIONS)
42
029716a2
JA
43#ifndef __compiletime_error
44#define __compiletime_error(message)
45#endif
484817a9 46
029716a2
JA
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
484817a9
JA
66#else
67
68#define compiletime_assert(condition, msg) do { } while (0)
69
4fee8096 70#endif
5018f79f
AH
71
72#endif