2 * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
3 * Copyright (c) 2015-2018 The strace developers.
6 * SPDX-License-Identifier: LGPL-2.1-or-later
9 #ifndef STRACE_GCC_COMPAT_H
10 # define STRACE_GCC_COMPAT_H
12 # if defined __GNUC__ && defined __GNUC_MINOR__
13 # define GNUC_PREREQ(maj, min) \
14 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
16 # define GNUC_PREREQ(maj, min) 0
19 # if defined __clang__ && defined __clang_major__ && defined __clang_minor__
20 # define CLANG_PREREQ(maj, min) \
21 ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
23 # define CLANG_PREREQ(maj, min) 0
26 # if !(GNUC_PREREQ(2, 0) || CLANG_PREREQ(1, 0))
27 # define __attribute__(x) /* empty */
30 # if GNUC_PREREQ(2, 5)
31 # define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
33 # define ATTRIBUTE_NORETURN /* empty */
36 # if GNUC_PREREQ(2, 7)
37 # define ATTRIBUTE_FORMAT(args) __attribute__((__format__ args))
38 # define ATTRIBUTE_ALIGNED(arg) __attribute__((__aligned__(arg)))
39 # define ATTRIBUTE_PACKED __attribute__((__packed__))
41 # define ATTRIBUTE_FORMAT(args) /* empty */
42 # define ATTRIBUTE_ALIGNED(arg) /* empty */
43 # define ATTRIBUTE_PACKED /* empty */
46 # if GNUC_PREREQ(3, 0)
47 # define SAME_TYPE(x, y) __builtin_types_compatible_p(typeof(x), typeof(y))
48 # define FAIL_BUILD_ON_ZERO(expr) (sizeof(int[-1 + 2 * !!(expr)]) * 0)
49 /* &(a)[0] is a pointer and not an array, shouldn't be treated as the same */
50 # define MUST_BE_ARRAY(a) FAIL_BUILD_ON_ZERO(!SAME_TYPE((a), &(a)[0]))
52 # define SAME_TYPE(x, y) 0
53 # define MUST_BE_ARRAY(a) 0
56 # if GNUC_PREREQ(3, 0)
57 # define ATTRIBUTE_MALLOC __attribute__((__malloc__))
59 # define ATTRIBUTE_MALLOC /* empty */
62 # if GNUC_PREREQ(3, 1)
63 # define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
65 # define ATTRIBUTE_NOINLINE /* empty */
68 # if GNUC_PREREQ(4, 0)
69 # define ATTRIBUTE_SENTINEL __attribute__((__sentinel__))
71 # define ATTRIBUTE_SENTINEL /* empty */
74 # if GNUC_PREREQ(4, 1)
75 # define ALIGNOF(t_) __alignof__(t_)
77 # define ALIGNOF(t_) (sizeof(struct { char x_; t_ y_; }) - sizeof(t_))
80 # if GNUC_PREREQ(4, 3)
81 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__((__alloc_size__ args))
83 # define ATTRIBUTE_ALLOC_SIZE(args) /* empty */
86 # if GNUC_PREREQ(7, 0)
87 # define ATTRIBUTE_FALLTHROUGH __attribute__((__fallthrough__))
89 # define ATTRIBUTE_FALLTHROUGH ((void) 0)
92 # if CLANG_PREREQ(2, 8)
93 # define DIAG_PUSH_IGNORE_OVERRIDE_INIT \
94 _Pragma("clang diagnostic push"); \
95 _Pragma("clang diagnostic ignored \"-Winitializer-overrides\"");
96 # define DIAG_POP_IGNORE_OVERRIDE_INIT \
97 _Pragma("clang diagnostic pop");
98 # elif GNUC_PREREQ(4, 2)
99 # define DIAG_PUSH_IGNORE_OVERRIDE_INIT \
100 _Pragma("GCC diagnostic push"); \
101 _Pragma("GCC diagnostic ignored \"-Woverride-init\"");
102 # define DIAG_POP_IGNORE_OVERRIDE_INIT \
103 _Pragma("GCC diagnostic pop");
105 # define DIAG_PUSH_IGNORE_OVERRIDE_INIT /* empty */
106 # define DIAG_POP_IGNORE_OVERRIDE_INIT /* empty */
109 # if GNUC_PREREQ(6, 0)
110 # define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE \
111 _Pragma("GCC diagnostic push"); \
112 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"");
113 # define DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE \
114 _Pragma("GCC diagnostic pop");
116 # define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE /* empty */
117 # define DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE /* empty */
120 #endif /* !STRACE_GCC_COMPAT_H */