xref: /linux/include/linux/compiler_types.h (revision c752c21c90b808a059ae8e0070ff7566a65f8577)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_COMPILER_TYPES_H
3 #define __LINUX_COMPILER_TYPES_H
4 
5 /*
6  * __has_builtin is supported on gcc >= 10, clang >= 3 and icc >= 21.
7  * In the meantime, to support gcc < 10, we implement __has_builtin
8  * by hand.
9  */
10 #ifndef __has_builtin
11 #define __has_builtin(x) (0)
12 #endif
13 
14 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
15 #define ___PASTE(a, b) a##b
16 #define __PASTE(a, b) ___PASTE(a, b)
17 
18 #ifndef __ASSEMBLY__
19 
20 /*
21  * C23 introduces "auto" as a standard way to define type-inferred
22  * variables, but "auto" has been a (useless) keyword even since K&R C,
23  * so it has always been "namespace reserved."
24  *
25  * Until at some future time we require C23 support, we need the gcc
26  * extension __auto_type, but there is no reason to put that elsewhere
27  * in the source code.
28  */
29 #if __STDC_VERSION__ < 202311L
30 # define auto __auto_type
31 #endif
32 
33 /*
34  * Skipped when running bindgen due to a libclang issue;
35  * see https://github.com/rust-lang/rust-bindgen/issues/2244.
36  */
37 #if defined(CONFIG_DEBUG_INFO_BTF) && defined(CONFIG_PAHOLE_HAS_BTF_TAG) && \
38 	__has_attribute(btf_type_tag) && !defined(__BINDGEN__)
39 # define BTF_TYPE_TAG(value) __attribute__((btf_type_tag(#value)))
40 #else
41 # define BTF_TYPE_TAG(value) /* nothing */
42 #endif
43 
44 /* sparse defines __CHECKER__; see Documentation/dev-tools/sparse.rst */
45 #ifdef __CHECKER__
46 /* address spaces */
47 # define __kernel	__attribute__((address_space(0)))
48 # define __user		__attribute__((noderef, address_space(__user)))
49 # define __iomem	__attribute__((noderef, address_space(__iomem)))
50 # define __percpu	__attribute__((noderef, address_space(__percpu)))
51 # define __rcu		__attribute__((noderef, address_space(__rcu)))
__chk_user_ptr(const volatile void __user * ptr)52 static inline void __chk_user_ptr(const volatile void __user *ptr) { }
__chk_io_ptr(const volatile void __iomem * ptr)53 static inline void __chk_io_ptr(const volatile void __iomem *ptr) { }
54 /* context/locking */
55 # define __must_hold(x)	__attribute__((context(x,1,1)))
56 # define __acquires(x)	__attribute__((context(x,0,1)))
57 # define __cond_acquires(x) __attribute__((context(x,0,-1)))
58 # define __releases(x)	__attribute__((context(x,1,0)))
59 # define __acquire(x)	__context__(x,1)
60 # define __release(x)	__context__(x,-1)
61 # define __cond_lock(x,c)	((c) ? ({ __acquire(x); 1; }) : 0)
62 /* other */
63 # define __force	__attribute__((force))
64 # define __nocast	__attribute__((nocast))
65 # define __safe		__attribute__((safe))
66 # define __private	__attribute__((noderef))
67 # define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
68 #else /* __CHECKER__ */
69 /* address spaces */
70 # define __kernel
71 # ifdef STRUCTLEAK_PLUGIN
72 #  define __user	__attribute__((user))
73 # else
74 #  define __user	BTF_TYPE_TAG(user)
75 # endif
76 # define __iomem
77 # define __percpu	__percpu_qual BTF_TYPE_TAG(percpu)
78 # define __rcu		BTF_TYPE_TAG(rcu)
79 
80 # define __chk_user_ptr(x)	(void)0
81 # define __chk_io_ptr(x)	(void)0
82 /* context/locking */
83 # define __must_hold(x)
84 # define __acquires(x)
85 # define __cond_acquires(x)
86 # define __releases(x)
87 # define __acquire(x)	(void)0
88 # define __release(x)	(void)0
89 # define __cond_lock(x,c) (c)
90 /* other */
91 # define __force
92 # define __nocast
93 # define __safe
94 # define __private
95 # define ACCESS_PRIVATE(p, member) ((p)->member)
96 # define __builtin_warning(x, y...) (1)
97 #endif /* __CHECKER__ */
98 
99 #ifdef __KERNEL__
100 
101 /* Attributes */
102 #include <linux/compiler_attributes.h>
103 
104 #if CONFIG_FUNCTION_ALIGNMENT > 0
105 #define __function_aligned		__aligned(CONFIG_FUNCTION_ALIGNMENT)
106 #else
107 #define __function_aligned
108 #endif
109 
110 /*
111  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-cold-function-attribute
112  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-cold-label-attribute
113  *
114  * When -falign-functions=N is in use, we must avoid the cold attribute as
115  * GCC drops the alignment for cold functions. Worse, GCC can implicitly mark
116  * callees of cold functions as cold themselves, so it's not sufficient to add
117  * __function_aligned here as that will not ensure that callees are correctly
118  * aligned.
119  *
120  * See:
121  *
122  *   https://lore.kernel.org/lkml/Y77%2FqVgvaJidFpYt@FVFF77S0Q05N
123  *   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345#c9
124  */
125 #if defined(CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT) || (CONFIG_FUNCTION_ALIGNMENT == 0)
126 #define __cold				__attribute__((__cold__))
127 #else
128 #define __cold
129 #endif
130 
131 /*
132  * On x86-64 and arm64 targets, __preserve_most changes the calling convention
133  * of a function to make the code in the caller as unintrusive as possible. This
134  * convention behaves identically to the C calling convention on how arguments
135  * and return values are passed, but uses a different set of caller- and callee-
136  * saved registers.
137  *
138  * The purpose is to alleviates the burden of saving and recovering a large
139  * register set before and after the call in the caller.  This is beneficial for
140  * rarely taken slow paths, such as error-reporting functions that may be called
141  * from hot paths.
142  *
143  * Note: This may conflict with instrumentation inserted on function entry which
144  * does not use __preserve_most or equivalent convention (if in assembly). Since
145  * function tracing assumes the normal C calling convention, where the attribute
146  * is supported, __preserve_most implies notrace.  It is recommended to restrict
147  * use of the attribute to functions that should or already disable tracing.
148  *
149  * Optional: not supported by gcc.
150  *
151  * clang: https://clang.llvm.org/docs/AttributeReference.html#preserve-most
152  */
153 #if __has_attribute(__preserve_most__) && (defined(CONFIG_X86_64) || defined(CONFIG_ARM64))
154 # define __preserve_most notrace __attribute__((__preserve_most__))
155 #else
156 # define __preserve_most
157 #endif
158 
159 /*
160  * Annotating a function/variable with __retain tells the compiler to place
161  * the object in its own section and set the flag SHF_GNU_RETAIN. This flag
162  * instructs the linker to retain the object during garbage-cleanup or LTO
163  * phases.
164  *
165  * Note that the __used macro is also used to prevent functions or data
166  * being optimized out, but operates at the compiler/IR-level and may still
167  * allow unintended removal of objects during linking.
168  *
169  * Optional: only supported since gcc >= 11, clang >= 13
170  *
171  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-retain-function-attribute
172  * clang: https://clang.llvm.org/docs/AttributeReference.html#retain
173  */
174 #if __has_attribute(__retain__) && \
175 	(defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || \
176 	 defined(CONFIG_LTO_CLANG))
177 # define __retain			__attribute__((__retain__))
178 #else
179 # define __retain
180 #endif
181 
182 /* Compiler specific macros. */
183 #ifdef __clang__
184 #include <linux/compiler-clang.h>
185 #elif defined(__GNUC__)
186 /* The above compilers also define __GNUC__, so order is important here. */
187 #include <linux/compiler-gcc.h>
188 #else
189 #error "Unknown compiler"
190 #endif
191 
192 /*
193  * Some architectures need to provide custom definitions of macros provided
194  * by linux/compiler-*.h, and can do so using asm/compiler.h. We include that
195  * conditionally rather than using an asm-generic wrapper in order to avoid
196  * build failures if any C compilation, which will include this file via an
197  * -include argument in c_flags, occurs prior to the asm-generic wrappers being
198  * generated.
199  */
200 #ifdef CONFIG_HAVE_ARCH_COMPILER_H
201 #include <asm/compiler.h>
202 #endif
203 
204 struct ftrace_branch_data {
205 	const char *func;
206 	const char *file;
207 	unsigned line;
208 	union {
209 		struct {
210 			unsigned long correct;
211 			unsigned long incorrect;
212 		};
213 		struct {
214 			unsigned long miss;
215 			unsigned long hit;
216 		};
217 		unsigned long miss_hit[2];
218 	};
219 };
220 
221 struct ftrace_likely_data {
222 	struct ftrace_branch_data	data;
223 	unsigned long			constant;
224 };
225 
226 #if defined(CC_USING_HOTPATCH)
227 #define notrace			__attribute__((hotpatch(0, 0)))
228 #elif defined(CC_USING_PATCHABLE_FUNCTION_ENTRY)
229 #define notrace			__attribute__((patchable_function_entry(0, 0)))
230 #else
231 #define notrace			__attribute__((__no_instrument_function__))
232 #endif
233 
234 /*
235  * it doesn't make sense on ARM (currently the only user of __naked)
236  * to trace naked functions because then mcount is called without
237  * stack and frame pointer being set up and there is no chance to
238  * restore the lr register to the value before mcount was called.
239  */
240 #define __naked			__attribute__((__naked__)) notrace
241 
242 /*
243  * Prefer gnu_inline, so that extern inline functions do not emit an
244  * externally visible function. This makes extern inline behave as per gnu89
245  * semantics rather than c99. This prevents multiple symbol definition errors
246  * of extern inline functions at link time.
247  * A lot of inline functions can cause havoc with function tracing.
248  */
249 #define inline inline __gnu_inline __inline_maybe_unused notrace
250 
251 /*
252  * gcc provides both __inline__ and __inline as alternate spellings of
253  * the inline keyword, though the latter is undocumented. New kernel
254  * code should only use the inline spelling, but some existing code
255  * uses __inline__. Since we #define inline above, to ensure
256  * __inline__ has the same semantics, we need this #define.
257  *
258  * However, the spelling __inline is strictly reserved for referring
259  * to the bare keyword.
260  */
261 #define __inline__ inline
262 
263 /*
264  * GCC does not warn about unused static inline functions for -Wunused-function.
265  * Suppress the warning in clang as well by using __maybe_unused, but enable it
266  * for W=2 build. This will allow clang to find unused functions.
267  */
268 #ifdef KBUILD_EXTRA_WARN2
269 #define __inline_maybe_unused
270 #else
271 #define __inline_maybe_unused __maybe_unused
272 #endif
273 
274 /*
275  * Rather then using noinline to prevent stack consumption, use
276  * noinline_for_stack instead.  For documentation reasons.
277  */
278 #define noinline_for_stack noinline
279 
280 /*
281  * Use noinline_for_tracing for functions that should not be inlined.
282  * For tracing reasons.
283  */
284 #define noinline_for_tracing noinline
285 
286 /*
287  * Sanitizer helper attributes: Because using __always_inline and
288  * __no_sanitize_* conflict, provide helper attributes that will either expand
289  * to __no_sanitize_* in compilation units where instrumentation is enabled
290  * (__SANITIZE_*__), or __always_inline in compilation units without
291  * instrumentation (__SANITIZE_*__ undefined).
292  */
293 #ifdef __SANITIZE_ADDRESS__
294 /*
295  * We can't declare function 'inline' because __no_sanitize_address conflicts
296  * with inlining. Attempt to inline it may cause a build failure.
297  *     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
298  * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
299  */
300 # define __no_kasan_or_inline __no_sanitize_address notrace __maybe_unused
301 # define __no_sanitize_or_inline __no_kasan_or_inline
302 #else
303 # define __no_kasan_or_inline __always_inline
304 #endif
305 
306 #ifdef __SANITIZE_THREAD__
307 /*
308  * Clang still emits instrumentation for __tsan_func_{entry,exit}() and builtin
309  * atomics even with __no_sanitize_thread (to avoid false positives in userspace
310  * ThreadSanitizer). The kernel's requirements are stricter and we really do not
311  * want any instrumentation with __no_kcsan.
312  *
313  * Therefore we add __disable_sanitizer_instrumentation where available to
314  * disable all instrumentation. See Kconfig.kcsan where this is mandatory.
315  */
316 # define __no_kcsan __no_sanitize_thread __disable_sanitizer_instrumentation
317 /*
318  * Type qualifier to mark variables where all data-racy accesses should be
319  * ignored by KCSAN. Note, the implementation simply marks these variables as
320  * volatile, since KCSAN will treat such accesses as "marked".
321  */
322 # define __data_racy volatile
323 # define __no_sanitize_or_inline __no_kcsan notrace __maybe_unused
324 #else
325 # define __no_kcsan
326 # define __data_racy
327 #endif
328 
329 #ifdef __SANITIZE_MEMORY__
330 /*
331  * Similarly to KASAN and KCSAN, KMSAN loses function attributes of inlined
332  * functions, therefore disabling KMSAN checks also requires disabling inlining.
333  *
334  * __no_sanitize_or_inline effectively prevents KMSAN from reporting errors
335  * within the function and marks all its outputs as initialized.
336  */
337 # define __no_sanitize_or_inline __no_kmsan_checks notrace __maybe_unused
338 #endif
339 
340 #ifndef __no_sanitize_or_inline
341 #define __no_sanitize_or_inline __always_inline
342 #endif
343 
344 /*
345  * The assume attribute is used to indicate that a certain condition is
346  * assumed to be true. If this condition is violated at runtime, the behavior
347  * is undefined. Compilers may or may not use this indication to generate
348  * optimized code.
349  *
350  * Note that the clang documentation states that optimizers may react
351  * differently to this attribute, and this may even have a negative
352  * performance impact. Therefore this attribute should be used with care.
353  *
354  * Optional: only supported since gcc >= 13
355  * Optional: only supported since clang >= 19
356  *
357  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#index-assume-statement-attribute
358  * clang: https://clang.llvm.org/docs/AttributeReference.html#id13
359  *
360  */
361 #ifdef CONFIG_CC_HAS_ASSUME
362 # define __assume(expr)			__attribute__((__assume__(expr)))
363 #else
364 # define __assume(expr)
365 #endif
366 
367 /*
368  * Optional: only supported since gcc >= 15
369  * Optional: only supported since clang >= 18
370  *
371  *   gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
372  * clang: https://github.com/llvm/llvm-project/pull/76348
373  *
374  * __bdos on clang < 19.1.2 can erroneously return 0:
375  * https://github.com/llvm/llvm-project/pull/110497
376  *
377  * __bdos on clang < 19.1.3 can be off by 4:
378  * https://github.com/llvm/llvm-project/pull/112636
379  */
380 #ifdef CONFIG_CC_HAS_COUNTED_BY
381 # define __counted_by(member)		__attribute__((__counted_by__(member)))
382 #else
383 # define __counted_by(member)
384 #endif
385 
386 /*
387  * Optional: only supported since gcc >= 15
388  * Optional: not supported by Clang
389  *
390  * gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
391  */
392 #ifdef CONFIG_CC_HAS_MULTIDIMENSIONAL_NONSTRING
393 # define __nonstring_array		__attribute__((__nonstring__))
394 #else
395 # define __nonstring_array
396 #endif
397 
398 /*
399  * Apply __counted_by() when the Endianness matches to increase test coverage.
400  */
401 #ifdef __LITTLE_ENDIAN
402 #define __counted_by_le(member)	__counted_by(member)
403 #define __counted_by_be(member)
404 #else
405 #define __counted_by_le(member)
406 #define __counted_by_be(member)	__counted_by(member)
407 #endif
408 
409 /*
410  * This designates the minimum number of elements a passed array parameter must
411  * have. For example:
412  *
413  *     void some_function(u8 param[at_least 7]);
414  *
415  * If a caller passes an array with fewer than 7 elements, the compiler will
416  * emit a warning.
417  */
418 #ifndef __CHECKER__
419 #define at_least static
420 #else
421 #define at_least
422 #endif
423 
424 /* Do not trap wrapping arithmetic within an annotated function. */
425 #ifdef CONFIG_UBSAN_INTEGER_WRAP
426 # define __signed_wrap __attribute__((no_sanitize("signed-integer-overflow")))
427 #else
428 # define __signed_wrap
429 #endif
430 
431 /* Section for code which can't be instrumented at all */
432 #define __noinstr_section(section)					\
433 	noinline notrace __attribute((__section__(section)))		\
434 	__no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage \
435 	__no_sanitize_memory __signed_wrap
436 
437 #define noinstr __noinstr_section(".noinstr.text")
438 
439 /*
440  * The __cpuidle section is used twofold:
441  *
442  *  1) the original use -- identifying if a CPU is 'stuck' in idle state based
443  *     on it's instruction pointer. See cpu_in_idle().
444  *
445  *  2) supressing instrumentation around where cpuidle disables RCU; where the
446  *     function isn't strictly required for #1, this is interchangeable with
447  *     noinstr.
448  */
449 #define __cpuidle __noinstr_section(".cpuidle.text")
450 
451 #endif /* __KERNEL__ */
452 
453 #endif /* __ASSEMBLY__ */
454 
455 /*
456  * The below symbols may be defined for one or more, but not ALL, of the above
457  * compilers. We don't consider that to be an error, so set them to nothing.
458  * For example, some of them are for compiler specific plugins.
459  */
460 #ifndef __latent_entropy
461 # define __latent_entropy
462 #endif
463 
464 #if defined(RANDSTRUCT) && !defined(__CHECKER__)
465 # define __randomize_layout __designated_init __attribute__((randomize_layout))
466 # define __no_randomize_layout __attribute__((no_randomize_layout))
467 /* This anon struct can add padding, so only enable it under randstruct. */
468 # define randomized_struct_fields_start	struct {
469 # define randomized_struct_fields_end	} __randomize_layout;
470 #else
471 # define __randomize_layout __designated_init
472 # define __no_randomize_layout
473 # define randomized_struct_fields_start
474 # define randomized_struct_fields_end
475 #endif
476 
477 #ifndef __no_kstack_erase
478 # define __no_kstack_erase
479 #endif
480 
481 #ifndef __noscs
482 # define __noscs
483 #endif
484 
485 #if defined(CONFIG_CFI)
486 # define __nocfi		__attribute__((__no_sanitize__("kcfi")))
487 #else
488 # define __nocfi
489 #endif
490 
491 #if defined(CONFIG_ARCH_USES_CFI_GENERIC_LLVM_PASS)
492 # define __nocfi_generic	__nocfi
493 #else
494 # define __nocfi_generic
495 #endif
496 
497 /*
498  * Any place that could be marked with the "alloc_size" attribute is also
499  * a place to be marked with the "malloc" attribute, except those that may
500  * be performing a _reallocation_, as that may alias the existing pointer.
501  * For these, use __realloc_size().
502  */
503 #ifdef __alloc_size__
504 # define __alloc_size(x, ...)	__alloc_size__(x, ## __VA_ARGS__) __malloc
505 # define __realloc_size(x, ...)	__alloc_size__(x, ## __VA_ARGS__)
506 #else
507 # define __alloc_size(x, ...)	__malloc
508 # define __realloc_size(x, ...)
509 #endif
510 
511 /*
512  * When the size of an allocated object is needed, use the best available
513  * mechanism to find it. (For cases where sizeof() cannot be used.)
514  *
515  * Optional: only supported since gcc >= 12
516  *
517  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
518  * clang: https://clang.llvm.org/docs/LanguageExtensions.html#evaluating-object-size
519  */
520 #if __has_builtin(__builtin_dynamic_object_size)
521 #define __struct_size(p)	__builtin_dynamic_object_size(p, 0)
522 #define __member_size(p)	__builtin_dynamic_object_size(p, 1)
523 #else
524 #define __struct_size(p)	__builtin_object_size(p, 0)
525 #define __member_size(p)	__builtin_object_size(p, 1)
526 #endif
527 
528 /*
529  * Determine if an attribute has been applied to a variable.
530  * Using __annotated needs to check for __annotated being available,
531  * or negative tests may fail when annotation cannot be checked. For
532  * example, see the definition of __is_cstr().
533  */
534 #if __has_builtin(__builtin_has_attribute)
535 #define __annotated(var, attr)	__builtin_has_attribute(var, attr)
536 #endif
537 
538 /*
539  * Some versions of gcc do not mark 'asm goto' volatile:
540  *
541  *  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103979
542  *
543  * We do it here by hand, because it doesn't hurt.
544  */
545 #ifndef asm_goto_output
546 #define asm_goto_output(x...) asm volatile goto(x)
547 #endif
548 
549 /*
550  * Clang has trouble with constraints with multiple
551  * alternative behaviors (mainly "g" and "rm").
552  */
553 #ifndef ASM_INPUT_G
554   #define ASM_INPUT_G "g"
555   #define ASM_INPUT_RM "rm"
556 #endif
557 
558 #ifdef CONFIG_CC_HAS_ASM_INLINE
559 #define asm_inline asm __inline
560 #else
561 #define asm_inline asm
562 #endif
563 
564 /* Are two types/vars the same type (ignoring qualifiers)? */
565 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
566 
567 /*
568  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
569  *			       non-scalar types unchanged.
570  */
571 /*
572  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
573  * is not type-compatible with 'signed char', and we define a separate case.
574  */
575 #define __scalar_type_to_expr_cases(type)				\
576 		unsigned type:	(unsigned type)0,			\
577 		signed type:	(signed type)0
578 
579 #define __unqual_scalar_typeof(x) typeof(				\
580 		_Generic((x),						\
581 			 char:	(char)0,				\
582 			 __scalar_type_to_expr_cases(char),		\
583 			 __scalar_type_to_expr_cases(short),		\
584 			 __scalar_type_to_expr_cases(int),		\
585 			 __scalar_type_to_expr_cases(long),		\
586 			 __scalar_type_to_expr_cases(long long),	\
587 			 default: (x)))
588 
589 /* Is this type a native word size -- useful for atomic operations */
590 #define __native_word(t) \
591 	(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
592 	 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
593 
594 #ifdef __OPTIMIZE__
595 /*
596  * #ifdef __OPTIMIZE__ is only a good approximation; for instance "make
597  * CFLAGS_foo.o=-Og" defines __OPTIMIZE__, does not elide the conditional code
598  * and can break compilation with wrong error message(s). Combine with
599  * -U__OPTIMIZE__ when needed.
600  */
601 # define __compiletime_assert(condition, msg, prefix, suffix)		\
602 	do {								\
603 		/*							\
604 		 * __noreturn is needed to give the compiler enough	\
605 		 * information to avoid certain possibly-uninitialized	\
606 		 * warnings (regardless of the build failing).		\
607 		 */							\
608 		__noreturn extern void prefix ## suffix(void)		\
609 			__compiletime_error(msg);			\
610 		if (!(condition))					\
611 			prefix ## suffix();				\
612 	} while (0)
613 #else
614 # define __compiletime_assert(condition, msg, prefix, suffix) ((void)(condition))
615 #endif
616 
617 #define _compiletime_assert(condition, msg, prefix, suffix) \
618 	__compiletime_assert(condition, msg, prefix, suffix)
619 
620 /**
621  * compiletime_assert - break build and emit msg if condition is false
622  * @condition: a compile-time constant condition to check
623  * @msg:       a message to emit if condition is false
624  *
625  * In tradition of POSIX assert, this macro will break the build if the
626  * supplied condition is *false*, emitting the supplied error message if the
627  * compiler has support to do so.
628  */
629 #define compiletime_assert(condition, msg) \
630 	_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
631 
632 #define compiletime_assert_atomic_type(t)				\
633 	compiletime_assert(__native_word(t),				\
634 		"Need native word sized stores/loads for atomicity.")
635 
636 /* Helpers for emitting diagnostics in pragmas. */
637 #ifndef __diag
638 #define __diag(string)
639 #endif
640 
641 #ifndef __diag_GCC
642 #define __diag_GCC(version, severity, string)
643 #endif
644 
645 #define __diag_push()	__diag(push)
646 #define __diag_pop()	__diag(pop)
647 
648 #define __diag_ignore(compiler, version, option, comment) \
649 	__diag_ ## compiler(version, ignore, option)
650 #define __diag_warn(compiler, version, option, comment) \
651 	__diag_ ## compiler(version, warn, option)
652 #define __diag_error(compiler, version, option, comment) \
653 	__diag_ ## compiler(version, error, option)
654 
655 #ifndef __diag_ignore_all
656 #define __diag_ignore_all(option, comment)
657 #endif
658 
659 #endif /* __LINUX_COMPILER_TYPES_H */
660