]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/compiler.h
Merge pull request #3695 from brauner/2021-02-24/fixes_3
[mirror_lxc.git] / src / lxc / compiler.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #ifndef __LXC_COMPILER_H
4 #define __LXC_COMPILER_H
5
6 #ifndef _GNU_SOURCE
7 #define _GNU_SOURCE 1
8 #endif
9
10 #include "config.h"
11
12 #ifndef thread_local
13 #if __STDC_VERSION__ >= 201112L && \
14 !(defined(__STDC_NO_THREADS__) || \
15 (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
16 #define thread_local _Thread_local
17 #else
18 #define thread_local __thread
19 #endif
20 #endif
21
22 #if __GNUC__ >= 7
23 #define __fallthrough __attribute__((__fallthrough__))
24 #else
25 #define __fallthrough /* fall through */
26 #endif
27
28 #ifndef __noreturn
29 # if __STDC_VERSION__ >= 201112L
30 # if !IS_BIONIC
31 # define __noreturn _Noreturn
32 # else
33 # define __noreturn __attribute__((__noreturn__))
34 # endif
35 # elif IS_BIONIC
36 # define __noreturn __attribute__((__noreturn__))
37 # else
38 # define __noreturn __attribute__((noreturn))
39 # endif
40 #endif
41
42 #ifndef __hot
43 # define __hot __attribute__((hot))
44 #endif
45
46 #ifndef __returns_twice
47 #define __returns_twice __attribute__((returns_twice))
48 #endif
49
50 /* This attribute is required to silence clang warnings */
51 #if defined(__GNUC__)
52 #define __lxc_unused __attribute__ ((unused))
53 #else
54 #define __lxc_unused
55 #endif
56
57 /* Indicates taking ownership */
58 #define __owns
59
60 #define __cgfsng_ops
61
62 /* access attribute */
63 #define __access_r_nosize(x)
64 #define __access_r(x, y)
65 #define __access_w(x, y)
66 #define __access_rw(x, y)
67
68 #ifdef __has_attribute
69 #if __has_attribute(access)
70 #undef __access_r
71 #define __access_r(x, y) __attribute__((access(read_only, x, y)))
72
73 #undef __access_r_nosize
74 #define __access_r_nosize(x) __attribute__((access(read_only, x)))
75
76 #undef __access_w
77 #define __access_w(x, y) __attribute__((access(write_only, x, y)))
78
79 #undef __access_rw
80 #define __access_rw(x, y) __attribute__((access(read_write, x, y)))
81 #endif
82 #endif
83
84 #ifndef __hidden
85 #define __hidden __attribute__((visibility("hidden")))
86 #endif
87
88 #ifndef __public
89 #define __public __attribute__((visibility("default")))
90 #endif
91
92 #define likely(x) __builtin_expect(!!(x), 1)
93 #define unlikely(x) __builtin_expect(!!(x), 0)
94
95 #endif /* __LXC_COMPILER_H */