]> wimlib.net Git - wimlib/blob - include/wimlib/compiler.h
Add sparse annotations for endianness checking
[wimlib] / include / wimlib / compiler.h
1 /*
2  * compiler.h
3  *
4  * The author dedicates this file to the public domain.
5  * You can do whatever you want with this file.
6  */
7
8 #ifndef _WIMLIB_COMPILER_H
9 #define _WIMLIB_COMPILER_H
10
11 #ifdef __GNUC__
12 #       if defined(__CYGWIN__) || defined(__WIN32__)
13 #               define WIMLIBAPI __declspec(dllexport)
14 #       else
15 #               define WIMLIBAPI __attribute__((visibility("default")))
16 #       endif
17 #       define _always_inline_attribute inline __attribute__((always_inline))
18 #       define _packed_attribute __attribute__((packed))
19 #       define _format_attribute(type, format_str, args_start) \
20                         /*__attribute__((format(type, format_str, args_start))) */
21 #       if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
22 #               define _cold_attribute     __attribute__((cold))
23 #       else
24 #               define _cold_attribute
25 #       endif
26 #       define _malloc_attribute __attribute__((malloc))
27 #       define _warn_unused_result_attribute __attribute__((warn_unused_result))
28 #       define _aligned_attribute(size) __attribute__((aligned(size)))
29 #       define likely(x) __builtin_expect(!!(x), 1)
30 #       define unlikely(x) __builtin_expect(!!(x), 0)
31 #       define inline inline __attribute__((always_inline))
32 #       define prefetch(x) __builtin_prefetch(x)
33 #       define is_constant(x) __builtin_constant_p(x)
34 #else
35 #       define WIMLIBAPI
36 #       define _always_inline_attribute inline
37 #       define _format_attribute(type, format_str, args_start)
38 #       define _cold_attribute
39 #       define _packed_attribute
40 #       define _malloc_attribute
41 #       define _warn_unused_result_attribute
42 #       define _aligned_attribute(size)
43 #       define likely(x) (x)
44 #       define unlikely(x) (x)
45 #       define prefetch(x)
46 #       define is_constant(x) (0)
47 #endif /* __GNUC__ */
48
49 #ifdef __CHECKER__
50 #  define _bitwise_attr __attribute__((bitwise))
51 #  define _force_attr   __attribute__((force))
52 #else
53 #  define _bitwise_attr
54 #  define _force_attr
55 #endif
56
57 #endif /* _WIMLIB_COMPILER_H */