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