coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
compiler.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */
2 
3 #ifndef _COMMONLIB_BSD_COMPILER_H_
4 #define _COMMONLIB_BSD_COMPILER_H_
5 
6 #ifndef __packed
7 #if defined(__WIN32) || defined(__WIN64)
8 #define __packed __attribute__((gcc_struct, packed))
9 #else
10 #define __packed __attribute__((packed))
11 #endif
12 #endif
13 
14 #ifndef __aligned
15 #define __aligned(x) __attribute__((aligned(x)))
16 #endif
17 
18 #ifndef __always_unused
19 #define __always_unused __attribute__((unused))
20 #endif
21 
22 #ifndef __must_check
23 #define __must_check __attribute__((warn_unused_result))
24 #endif
25 
26 #ifndef __weak
27 #define __weak __attribute__((weak))
28 #endif
29 
30 #ifndef __noreturn
31 #define __noreturn __attribute__((noreturn))
32 #endif
33 
34 #ifndef __always_inline
35 #define __always_inline inline __attribute__((always_inline))
36 #endif
37 
38 #ifndef __fallthrough
39 #define __fallthrough __attribute__((__fallthrough__))
40 #endif
41 
42 /* This evaluates to the type of the first expression, unless that is constant
43  in which case it evaluates to the type of the second. This is useful when
44  assigning macro parameters to temporary variables, because that would
45  normally circumvent the special loosened type promotion rules for integer
46  literals. By using this macro, the promotion can happen at the time the
47  literal is assigned to the temporary variable. If the literal doesn't fit in
48  the chosen type, -Werror=overflow will catch it, so this should be safe. */
49 #define __TYPEOF_UNLESS_CONST(expr, fallback_expr) __typeof__( \
50  __builtin_choose_expr(__builtin_constant_p(expr), fallback_expr, expr))
51 
52 /* This creates a unique local variable name for use in macros. */
53 #define __TMPNAME_3(i) __tmpname_##i
54 #define __TMPNAME_2(i) __TMPNAME_3(i)
55 #define __TMPNAME __TMPNAME_2(__COUNTER__)
56 
57 #endif