blob: ee2ff88d108d03ea689484230615461004f98f42 [file] [log] [blame]
Julius Werner98eeb962019-12-11 15:47:42 -08001/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */
Stefan Reinauer6a001132017-07-13 02:20:27 +02002
Julius Werner98eeb962019-12-11 15:47:42 -08003#ifndef _COMMONLIB_BSD_COMPILER_H_
4#define _COMMONLIB_BSD_COMPILER_H_
Stefan Reinauer6a001132017-07-13 02:20:27 +02005
Nico Huberd44221f2018-10-04 23:42:42 +02006#ifndef __packed
Stefan Reinauer6a001132017-07-13 02:20:27 +02007#if defined(__WIN32) || defined(__WIN64)
8#define __packed __attribute__((gcc_struct, packed))
9#else
10#define __packed __attribute__((packed))
11#endif
Nico Huberd44221f2018-10-04 23:42:42 +020012#endif
Stefan Reinauer6a001132017-07-13 02:20:27 +020013
Nico Huberd44221f2018-10-04 23:42:42 +020014#ifndef __aligned
Stefan Reinauer6a001132017-07-13 02:20:27 +020015#define __aligned(x) __attribute__((aligned(x)))
Nico Huberd44221f2018-10-04 23:42:42 +020016#endif
17
18#ifndef __always_unused
Stefan Reinauer6a001132017-07-13 02:20:27 +020019#define __always_unused __attribute__((unused))
Nico Huberd44221f2018-10-04 23:42:42 +020020#endif
21
22#ifndef __must_check
Caveh Jalali0068a9f2017-08-03 15:49:09 -070023#define __must_check __attribute__((warn_unused_result))
Nico Huberd44221f2018-10-04 23:42:42 +020024#endif
25
26#ifndef __weak
Aaron Durbin64031672018-04-21 14:45:32 -060027#define __weak __attribute__((weak))
Nico Huberd44221f2018-10-04 23:42:42 +020028#endif
29
30#ifndef __noreturn
Aaron Durbin0370bcf2018-09-05 09:37:11 -060031#define __noreturn __attribute__((noreturn))
Nico Huberd44221f2018-10-04 23:42:42 +020032#endif
33
34#ifndef __always_inline
Aaron Durbin75a62e72018-09-13 02:10:45 -060035#define __always_inline inline __attribute__((always_inline))
Nico Huberd44221f2018-10-04 23:42:42 +020036#endif
Stefan Reinauer6a001132017-07-13 02:20:27 +020037
Julius Wernerd371cf32015-05-22 18:09:48 -070038/* This evaluates to the type of the first expression, unless that is constant
39 in which case it evalutates to the type of the second. This is useful when
40 assigning macro parameters to temporary variables, because that would
41 normally circumvent the special loosened type promotion rules for integer
42 literals. By using this macro, the promotion can happen at the time the
43 literal is assigned to the temporary variable. If the literal doesn't fit in
44 the chosen type, -Werror=overflow will catch it, so this should be safe. */
45#define __TYPEOF_UNLESS_CONST(expr, fallback_expr) __typeof__( \
46 __builtin_choose_expr(__builtin_constant_p(expr), fallback_expr, expr))
47
48/* This creates a unique local variable name for use in macros. */
49#define __TMPNAME_3(i) __tmpname_##i
50#define __TMPNAME_2(i) __TMPNAME_3(i)
51#define __TMPNAME __TMPNAME_2(__COUNTER__)
52
Stefan Reinauer6a001132017-07-13 02:20:27 +020053#endif