]> granicus.if.org Git - strace/blob - gcc_compat.h
tests: implement ioctl_evdev-success-v.test via ioctl_evdev-success.test
[strace] / gcc_compat.h
1 /*
2  * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2015-2018 The strace developers.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8
9 #ifndef STRACE_GCC_COMPAT_H
10 # define STRACE_GCC_COMPAT_H
11
12 # if defined __GNUC__ && defined __GNUC_MINOR__
13 #  define GNUC_PREREQ(maj, min) \
14         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
15 # else
16 #  define GNUC_PREREQ(maj, min) 0
17 # endif
18
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))
22 # else
23 #  define CLANG_PREREQ(maj, min)        0
24 # endif
25
26 # if !(GNUC_PREREQ(2, 0) || CLANG_PREREQ(1, 0))
27 #  define __attribute__(x)      /* empty */
28 # endif
29
30 # if GNUC_PREREQ(2, 5)
31 #  define ATTRIBUTE_NORETURN    __attribute__((__noreturn__))
32 # else
33 #  define ATTRIBUTE_NORETURN    /* empty */
34 # endif
35
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__))
40 # else
41 #  define ATTRIBUTE_FORMAT(args)        /* empty */
42 #  define ATTRIBUTE_ALIGNED(arg)        /* empty */
43 #  define ATTRIBUTE_PACKED      /* empty */
44 # endif
45
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]))
51 # else
52 #  define SAME_TYPE(x, y)       0
53 #  define MUST_BE_ARRAY(a)      0
54 # endif
55
56 # if GNUC_PREREQ(3, 0)
57 #  define ATTRIBUTE_MALLOC      __attribute__((__malloc__))
58 # else
59 #  define ATTRIBUTE_MALLOC      /* empty */
60 # endif
61
62 # if GNUC_PREREQ(3, 1)
63 #  define ATTRIBUTE_NOINLINE    __attribute__((__noinline__))
64 # else
65 #  define ATTRIBUTE_NOINLINE    /* empty */
66 # endif
67
68 # if GNUC_PREREQ(4, 0)
69 #  define ATTRIBUTE_SENTINEL    __attribute__((__sentinel__))
70 # else
71 #  define ATTRIBUTE_SENTINEL    /* empty */
72 # endif
73
74 # if GNUC_PREREQ(4, 1)
75 #  define ALIGNOF(t_)   __alignof__(t_)
76 # else
77 #  define ALIGNOF(t_)   (sizeof(struct { char x_; t_ y_; }) - sizeof(t_))
78 # endif
79
80 # if GNUC_PREREQ(4, 3)
81 #  define ATTRIBUTE_ALLOC_SIZE(args)    __attribute__((__alloc_size__ args))
82 # else
83 #  define ATTRIBUTE_ALLOC_SIZE(args)    /* empty */
84 # endif
85
86 # if GNUC_PREREQ(7, 0)
87 #  define ATTRIBUTE_FALLTHROUGH __attribute__((__fallthrough__))
88 # else
89 #  define ATTRIBUTE_FALLTHROUGH ((void) 0)
90 # endif
91
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");
104 # else
105 #  define DIAG_PUSH_IGNORE_OVERRIDE_INIT        /* empty */
106 #  define DIAG_POP_IGNORE_OVERRIDE_INIT /* empty */
107 # endif
108
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");
115 # else
116 #  define DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE /* empty */
117 #  define DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE  /* empty */
118 # endif
119
120 #endif /* !STRACE_GCC_COMPAT_H */