1 #ifndef __LINUX_COMPILER_TYPES_H
2 #define __LINUX_COMPILER_TYPES_H
7 # define __user __attribute__((noderef, address_space(1)))
8 # define __kernel __attribute__((address_space(0)))
9 # define __safe __attribute__((safe))
10 # define __force __attribute__((force))
11 # define __nocast __attribute__((nocast))
12 # define __iomem __attribute__((noderef, address_space(2)))
13 # define __must_hold(x) __attribute__((context(x,1,1)))
14 # define __acquires(x) __attribute__((context(x,0,1)))
15 # define __releases(x) __attribute__((context(x,1,0)))
16 # define __acquire(x) __context__(x,1)
17 # define __release(x) __context__(x,-1)
18 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
19 # define __percpu __attribute__((noderef, address_space(3)))
20 # define __rcu __attribute__((noderef, address_space(4)))
21 # define __private __attribute__((noderef))
22 extern void __chk_user_ptr(const volatile void __user *);
23 extern void __chk_io_ptr(const volatile void __iomem *);
24 # define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
25 #else /* __CHECKER__ */
26 # ifdef STRUCTLEAK_PLUGIN
27 # define __user __attribute__((user))
36 # define __chk_user_ptr(x) (void)0
37 # define __chk_io_ptr(x) (void)0
38 # define __builtin_warning(x, y...) (1)
39 # define __must_hold(x)
40 # define __acquires(x)
41 # define __releases(x)
42 # define __acquire(x) (void)0
43 # define __release(x) (void)0
44 # define __cond_lock(x,c) (c)
48 # define ACCESS_PRIVATE(p, member) ((p)->member)
49 #endif /* __CHECKER__ */
51 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
52 #define ___PASTE(a,b) a##b
53 #define __PASTE(a,b) ___PASTE(a,b)
57 /* Compiler specific macros. */
59 #include <linux/compiler-clang.h>
60 #elif defined(__INTEL_COMPILER)
61 #include <linux/compiler-intel.h>
62 #elif defined(__GNUC__)
63 /* The above compilers also define __GNUC__, so order is important here. */
64 #include <linux/compiler-gcc.h>
66 #error "Unknown compiler"
70 * Generic compiler-independent macros required for kernel
71 * build go below this comment. Actual compiler/compiler version
72 * specific implementations come from the above header files
75 struct ftrace_branch_data {
81 unsigned long correct;
82 unsigned long incorrect;
88 unsigned long miss_hit[2];
92 struct ftrace_likely_data {
93 struct ftrace_branch_data data;
94 unsigned long constant;
97 /* Don't. Just don't. */
99 #define __deprecated_for_modules
101 #endif /* __KERNEL__ */
103 #endif /* __ASSEMBLY__ */
106 * The below symbols may be defined for one or more, but not ALL, of the above
107 * compilers. We don't consider that to be an error, so set them to nothing.
108 * For example, some of them are for compiler specific plugins.
110 #ifndef __designated_init
111 # define __designated_init
114 #ifndef __latent_entropy
115 # define __latent_entropy
118 #ifndef __randomize_layout
119 # define __randomize_layout __designated_init
122 #ifndef __no_randomize_layout
123 # define __no_randomize_layout
126 #ifndef randomized_struct_fields_start
127 # define randomized_struct_fields_start
128 # define randomized_struct_fields_end
136 * Assume alignment of return value.
138 #ifndef __assume_aligned
139 #define __assume_aligned(a, ...)
142 /* Are two types/vars the same type (ignoring qualifiers)? */
143 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
145 /* Is this type a native word size -- useful for atomic operations */
146 #define __native_word(t) \
147 (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
148 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
150 #ifndef __attribute_const__
151 #define __attribute_const__ __attribute__((__const__))
158 /* Helpers for emitting diagnostics in pragmas. */
160 #define __diag(string)
164 #define __diag_GCC(version, severity, string)
167 #define __diag_push() __diag(push)
168 #define __diag_pop() __diag(pop)
170 #define __diag_ignore(compiler, version, option, comment) \
171 __diag_ ## compiler(version, ignore, option)
172 #define __diag_warn(compiler, version, option, comment) \
173 __diag_ ## compiler(version, warn, option)
174 #define __diag_error(compiler, version, option, comment) \
175 __diag_ ## compiler(version, error, option)
178 * From the GCC manual:
180 * Many functions have no effects except the return value and their
181 * return value depends only on the parameters and/or global
182 * variables. Such a function can be subject to common subexpression
183 * elimination and loop optimization just as an arithmetic operator
187 #define __pure __attribute__((pure))
188 #define __aligned(x) __attribute__((aligned(x)))
189 #define __aligned_largest __attribute__((aligned))
190 #define __printf(a, b) __attribute__((format(printf, a, b)))
191 #define __scanf(a, b) __attribute__((format(scanf, a, b)))
192 #define __maybe_unused __attribute__((unused))
193 #define __always_unused __attribute__((unused))
194 #define __mode(x) __attribute__((mode(x)))
195 #define __malloc __attribute__((__malloc__))
196 #define __used __attribute__((__used__))
197 #define __noreturn __attribute__((noreturn))
198 #define __packed __attribute__((packed))
199 #define __weak __attribute__((weak))
200 #define __alias(symbol) __attribute__((alias(#symbol)))
201 #define __cold __attribute__((cold))
202 #define __section(S) __attribute__((__section__(#S)))
205 #ifdef CONFIG_ENABLE_MUST_CHECK
206 #define __must_check __attribute__((warn_unused_result))
211 #if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__)
212 #define notrace __attribute__((hotpatch(0, 0)))
214 #define notrace __attribute__((no_instrument_function))
217 #define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
220 * Feature detection for gnu_inline (gnu89 extern inline semantics). Either
221 * __GNUC_STDC_INLINE__ is defined (not using gnu89 extern inline semantics,
222 * and we opt in to the gnu89 semantics), or __GNUC_STDC_INLINE__ is not
223 * defined so the gnu89 semantics are the default.
225 #ifdef __GNUC_STDC_INLINE__
226 # define __gnu_inline __attribute__((gnu_inline))
228 # define __gnu_inline
232 * Force always-inline if the user requests it so via the .config.
233 * GCC does not warn about unused static inline functions for
234 * -Wunused-function. This turns out to avoid the need for complex #ifdef
235 * directives. Suppress the warning in clang as well by using "unused"
236 * function attribute, which is redundant but not harmful for gcc.
237 * Prefer gnu_inline, so that extern inline functions do not emit an
238 * externally visible function. This makes extern inline behave as per gnu89
239 * semantics rather than c99. This prevents multiple symbol definition errors
240 * of extern inline functions at link time.
241 * A lot of inline functions can cause havoc with function tracing.
243 #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
244 !defined(CONFIG_OPTIMIZE_INLINING)
246 inline __attribute__((always_inline, unused)) notrace __gnu_inline
248 #define inline inline __attribute__((unused)) notrace __gnu_inline
251 #define __inline__ inline
252 #define __inline inline
253 #define noinline __attribute__((noinline))
255 #ifndef __always_inline
256 #define __always_inline inline __attribute__((always_inline))
260 * Rather then using noinline to prevent stack consumption, use
261 * noinline_for_stack instead. For documentation reasons.
263 #define noinline_for_stack noinline
265 #endif /* __LINUX_COMPILER_TYPES_H */