xref: /linux/tools/include/linux/compiler_types.h (revision f4b369c6fe0ceaba2da2daff8c9eb415f85926dd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_COMPILER_TYPES_H
3 #define __LINUX_COMPILER_TYPES_H
4 
5 /* Builtins */
6 
7 /*
8  * __has_builtin is supported on gcc >= 10, clang >= 3 and icc >= 21.
9  * In the meantime, to support gcc < 10, we implement __has_builtin
10  * by hand.
11  */
12 #ifndef __has_builtin
13 #define __has_builtin(x) (0)
14 #endif
15 
16 #include <linux/compiler-context-analysis.h>
17 
18 /* Compiler specific macros. */
19 #ifdef __GNUC__
20 #include <linux/compiler-gcc.h>
21 #endif
22 
23 #ifndef asm_goto_output
24 #define asm_goto_output(x...) asm goto(x)
25 #endif
26 
27 /*
28  * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
29  *			       non-scalar types unchanged.
30  */
31 /*
32  * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
33  * is not type-compatible with 'signed char', and we define a separate case.
34  */
35 #define __scalar_type_to_expr_cases(type)				\
36 		unsigned type:	(unsigned type)0,			\
37 		signed type:	(signed type)0
38 
39 #define __unqual_scalar_typeof(x) typeof(				\
40 		_Generic((x),						\
41 			 char:	(char)0,				\
42 			 __scalar_type_to_expr_cases(char),		\
43 			 __scalar_type_to_expr_cases(short),		\
44 			 __scalar_type_to_expr_cases(int),		\
45 			 __scalar_type_to_expr_cases(long),		\
46 			 __scalar_type_to_expr_cases(long long),	\
47 			 default: (x)))
48 
49 #endif /* __LINUX_COMPILER_TYPES_H */
50