xref: /aosp_15_r20/external/tcpdump/diag-control.h (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Li /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2*05b00f60SXin Li /*
3*05b00f60SXin Li  * Copyright (c) 1993, 1994, 1995, 1996, 1997
4*05b00f60SXin Li  *	The Regents of the University of California.  All rights reserved.
5*05b00f60SXin Li  *
6*05b00f60SXin Li  * Redistribution and use in source and binary forms, with or without
7*05b00f60SXin Li  * modification, are permitted provided that the following conditions
8*05b00f60SXin Li  * are met:
9*05b00f60SXin Li  * 1. Redistributions of source code must retain the above copyright
10*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer.
11*05b00f60SXin Li  * 2. Redistributions in binary form must reproduce the above copyright
12*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer in the
13*05b00f60SXin Li  *    documentation and/or other materials provided with the distribution.
14*05b00f60SXin Li  * 3. All advertising materials mentioning features or use of this software
15*05b00f60SXin Li  *    must display the following acknowledgement:
16*05b00f60SXin Li  *	This product includes software developed by the Computer Systems
17*05b00f60SXin Li  *	Engineering Group at Lawrence Berkeley Laboratory.
18*05b00f60SXin Li  * 4. Neither the name of the University nor of the Laboratory may be used
19*05b00f60SXin Li  *    to endorse or promote products derived from this software without
20*05b00f60SXin Li  *    specific prior written permission.
21*05b00f60SXin Li  *
22*05b00f60SXin Li  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*05b00f60SXin Li  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*05b00f60SXin Li  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*05b00f60SXin Li  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*05b00f60SXin Li  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*05b00f60SXin Li  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*05b00f60SXin Li  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*05b00f60SXin Li  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*05b00f60SXin Li  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*05b00f60SXin Li  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*05b00f60SXin Li  * SUCH DAMAGE.
33*05b00f60SXin Li  */
34*05b00f60SXin Li 
35*05b00f60SXin Li #ifndef _diag_control_h
36*05b00f60SXin Li #define _diag_control_h
37*05b00f60SXin Li 
38*05b00f60SXin Li #include "compiler-tests.h"
39*05b00f60SXin Li 
40*05b00f60SXin Li #ifndef _MSC_VER
41*05b00f60SXin Li   /*
42*05b00f60SXin Li    * Clang and GCC both support this way of putting pragmas into #defines.
43*05b00f60SXin Li    * We don't use it unless we have a compiler that supports it; the
44*05b00f60SXin Li    * warning-suppressing pragmas differ between Clang and GCC, so we test
45*05b00f60SXin Li    * for both of those separately.
46*05b00f60SXin Li    */
47*05b00f60SXin Li   #define DIAG_DO_PRAGMA(x) _Pragma (#x)
48*05b00f60SXin Li #endif
49*05b00f60SXin Li 
50*05b00f60SXin Li /*
51*05b00f60SXin Li  * XL C 12.1 and 13.1 for AIX require no attention in this department.
52*05b00f60SXin Li  * XL C 16.1 defines both __GNUC__ and __clang__, so has to be tested first.
53*05b00f60SXin Li  */
54*05b00f60SXin Li #if ND_IS_AT_LEAST_XL_C_VERSION(16,1)
55*05b00f60SXin Li   /*
56*05b00f60SXin Li    * See respective Clang note below.
57*05b00f60SXin Li    */
58*05b00f60SXin Li   #define DIAG_OFF_ASSIGN_ENUM \
59*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic push) \
60*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic ignored "-Wassign-enum")
61*05b00f60SXin Li   #define DIAG_ON_ASSIGN_ENUM \
62*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic pop)
63*05b00f60SXin Li 
64*05b00f60SXin Li   #define DIAG_OFF_CAST_QUAL
65*05b00f60SXin Li   #define DIAG_ON_CAST_QUAL
66*05b00f60SXin Li   #define DIAG_OFF_DEPRECATION
67*05b00f60SXin Li   #define DIAG_ON_DEPRECATION
68*05b00f60SXin Li /*
69*05b00f60SXin Li  * The current clang compilers also define __GNUC__ and __GNUC_MINOR__
70*05b00f60SXin Li  * thus we need to test the clang case before the GCC one
71*05b00f60SXin Li  */
72*05b00f60SXin Li #elif ND_IS_AT_LEAST_CLANG_VERSION(2,8)
73*05b00f60SXin Li   /*
74*05b00f60SXin Li    * Clang complains if you OR together multiple enum values of a
75*05b00f60SXin Li    * given enum type and them pass it as an argument of that enum
76*05b00f60SXin Li    * type.  Some libcap-ng routines use enums to define bit flags;
77*05b00f60SXin Li    * we want to squelch the warnings that produces.
78*05b00f60SXin Li    */
79*05b00f60SXin Li   #define DIAG_OFF_ASSIGN_ENUM \
80*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic push) \
81*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic ignored "-Wassign-enum")
82*05b00f60SXin Li   #define DIAG_ON_ASSIGN_ENUM \
83*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic pop)
84*05b00f60SXin Li 
85*05b00f60SXin Li   /*
86*05b00f60SXin Li    * It also legitimately complains about some code in the BSD
87*05b00f60SXin Li    * getopt_long() - that code explicitly and deliberately
88*05b00f60SXin Li    * violates the contract by permuting the argument vector
89*05b00f60SXin Li    * (declared as char const *argv[], meaning "I won't change
90*05b00f60SXin Li    * the vector by changing any of its elements), as do the
91*05b00f60SXin Li    * GNU and Solaris getopt_long().  This is documented in the
92*05b00f60SXin Li    * man pages for all versions; it can be suppressed by setting
93*05b00f60SXin Li    * the environment variable POSIXLY_CORRECT or by putting a "+"
94*05b00f60SXin Li    * at the beginning of the option string.
95*05b00f60SXin Li    *
96*05b00f60SXin Li    * We suppress the warning.
97*05b00f60SXin Li    */
98*05b00f60SXin Li   #define DIAG_OFF_CAST_QUAL \
99*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic push) \
100*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic ignored "-Wcast-qual")
101*05b00f60SXin Li   #define DIAG_ON_CAST_QUAL \
102*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic pop)
103*05b00f60SXin Li 
104*05b00f60SXin Li   /*
105*05b00f60SXin Li    * Suppress deprecation warnings.
106*05b00f60SXin Li    */
107*05b00f60SXin Li   #define DIAG_OFF_DEPRECATION \
108*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic push) \
109*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
110*05b00f60SXin Li   #define DIAG_ON_DEPRECATION \
111*05b00f60SXin Li     DIAG_DO_PRAGMA(clang diagnostic pop)
112*05b00f60SXin Li 
113*05b00f60SXin Li   /*
114*05b00f60SXin Li    * Clang supports the generic C11 extension even if run with the -std=gnu99
115*05b00f60SXin Li    * flag, which leads FreeBSD <sys/cdefs.h> to use the extension, which
116*05b00f60SXin Li    * results in Clang emitting a -Wc11-extensions warning. The warning is not
117*05b00f60SXin Li    * documented in the user manual, but it happens with Clang 10.0.1 on
118*05b00f60SXin Li    * FreeBSD 12.2, so let's use that as a reference.
119*05b00f60SXin Li    */
120*05b00f60SXin Li   #if ND_IS_AT_LEAST_CLANG_VERSION(10,0)
121*05b00f60SXin Li     #define DIAG_OFF_C11_EXTENSIONS \
122*05b00f60SXin Li       DIAG_DO_PRAGMA(clang diagnostic push) \
123*05b00f60SXin Li       DIAG_DO_PRAGMA(clang diagnostic ignored "-Wc11-extensions")
124*05b00f60SXin Li     #define DIAG_ON_C11_EXTENSIONS \
125*05b00f60SXin Li       DIAG_DO_PRAGMA(clang diagnostic pop)
126*05b00f60SXin Li   #endif
127*05b00f60SXin Li #elif ND_IS_AT_LEAST_GNUC_VERSION(4,2)
128*05b00f60SXin Li   /* GCC apparently doesn't complain about ORing enums together. */
129*05b00f60SXin Li   #define DIAG_OFF_ASSIGN_ENUM
130*05b00f60SXin Li   #define DIAG_ON_ASSIGN_ENUM
131*05b00f60SXin Li 
132*05b00f60SXin Li   /*
133*05b00f60SXin Li    * It does, however, complain about casting away constness in
134*05b00f60SXin Li    * missing/getopt_long.c.
135*05b00f60SXin Li    */
136*05b00f60SXin Li   #define DIAG_OFF_CAST_QUAL \
137*05b00f60SXin Li     DIAG_DO_PRAGMA(GCC diagnostic push) \
138*05b00f60SXin Li     DIAG_DO_PRAGMA(GCC diagnostic ignored "-Wcast-qual")
139*05b00f60SXin Li   #define DIAG_ON_CAST_QUAL \
140*05b00f60SXin Li     DIAG_DO_PRAGMA(GCC diagnostic pop)
141*05b00f60SXin Li 
142*05b00f60SXin Li   /*
143*05b00f60SXin Li    * Suppress deprecation warnings.
144*05b00f60SXin Li    */
145*05b00f60SXin Li   #define DIAG_OFF_DEPRECATION \
146*05b00f60SXin Li     DIAG_DO_PRAGMA(GCC diagnostic push) \
147*05b00f60SXin Li     DIAG_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
148*05b00f60SXin Li   #define DIAG_ON_DEPRECATION \
149*05b00f60SXin Li     DIAG_DO_PRAGMA(GCC diagnostic pop)
150*05b00f60SXin Li   /*
151*05b00f60SXin Li    * GCC supports -Wc99-c11-compat since version 5.1.0, but the warning does
152*05b00f60SXin Li    * not trigger for now, so let's just leave it be.
153*05b00f60SXin Li    */
154*05b00f60SXin Li #else
155*05b00f60SXin Li   #define DIAG_OFF_ASSIGN_ENUM
156*05b00f60SXin Li   #define DIAG_ON_ASSIGN_ENUM
157*05b00f60SXin Li   #define DIAG_OFF_CAST_QUAL
158*05b00f60SXin Li   #define DIAG_ON_CAST_QUAL
159*05b00f60SXin Li   #define DIAG_OFF_DEPRECATION
160*05b00f60SXin Li   #define DIAG_ON_DEPRECATION
161*05b00f60SXin Li #endif
162*05b00f60SXin Li 
163*05b00f60SXin Li #ifndef DIAG_OFF_C11_EXTENSIONS
164*05b00f60SXin Li #define DIAG_OFF_C11_EXTENSIONS
165*05b00f60SXin Li #endif
166*05b00f60SXin Li #ifndef DIAG_ON_C11_EXTENSIONS
167*05b00f60SXin Li #define DIAG_ON_C11_EXTENSIONS
168*05b00f60SXin Li #endif
169*05b00f60SXin Li 
170*05b00f60SXin Li /*
171*05b00f60SXin Li  * GCC needs this on AIX for longjmp().
172*05b00f60SXin Li  */
173*05b00f60SXin Li #if ND_IS_AT_LEAST_GNUC_VERSION(5,1)
174*05b00f60SXin Li   /*
175*05b00f60SXin Li    * Beware that the effect of this builtin is more than just squelching the
176*05b00f60SXin Li    * warning! GCC trusts it enough for the process to segfault if the control
177*05b00f60SXin Li    * flow reaches the builtin (an infinite empty loop in the same context would
178*05b00f60SXin Li    * squelch the warning and ruin the process too, albeit in a different way).
179*05b00f60SXin Li    * So please remember to use this very carefully.
180*05b00f60SXin Li    */
181*05b00f60SXin Li   #define ND_UNREACHABLE __builtin_unreachable();
182*05b00f60SXin Li #else
183*05b00f60SXin Li   #define ND_UNREACHABLE
184*05b00f60SXin Li #endif
185*05b00f60SXin Li 
186*05b00f60SXin Li #endif /* _diag_control_h */
187