]>
The Tcpdump Group git mirrors - libpcap/blob - diag-control.h
1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
3 * Copyright (c) 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the Computer Systems
17 * Engineering Group at Lawrence Berkeley Laboratory.
18 * 4. Neither the name of the University nor of the Laboratory may be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #ifndef _diag_control_h
36 #define _diag_control_h
38 #include "pcap/compiler-tests.h"
42 * Clang and GCC both support this way of putting pragmas into #defines.
43 * We don't use it unless we have a compiler that supports it; the
44 * warning-suppressing pragmas differ between Clang and GCC, so we test
45 * for both of those separately.
47 #define PCAP_DO_PRAGMA(x) _Pragma (#x)
51 * Suppress "enum value not explicitly handled in switch" warnings.
52 * We may have to build on multiple different Windows SDKs, so we
53 * may not be able to include all enum values in a switch, as they
54 * won't necessarily be defined on all the SDKs, and, unlike
55 * #defines, there's no easy way to test whether a given enum has
56 * a given value. It *could* be done by the configure script or
60 #define DIAG_OFF_ENUM_SWITCH \
61 __pragma(warning(push)) \
62 __pragma(warning(disable:4061))
63 #define DIAG_ON_ENUM_SWITCH \
64 __pragma(warning(pop))
66 #define DIAG_OFF_ENUM_SWITCH
67 #define DIAG_ON_ENUM_SWITCH
71 * Suppress "switch statement has only a default case" warnings.
72 * There's a switch in bpf_filter.c that only has additional
76 #define DIAG_OFF_DEFAULT_ONLY_SWITCH \
77 __pragma(warning(push)) \
78 __pragma(warning(disable:4065))
79 #define DIAG_ON_DEFAULT_ONLY_SWITCH \
80 __pragma(warning(pop))
82 #define DIAG_OFF_DEFAULT_ONLY_SWITCH
83 #define DIAG_ON_DEFAULT_ONLY_SWITCH
87 * Suppress Flex, narrowing, and deprecation warnings.
91 * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
92 * and __pragma(warning(push/pop)).
94 * Suppress signed-vs-unsigned comparison, narrowing, and unreachable
97 #define DIAG_OFF_FLEX \
98 __pragma(warning(push)) \
99 __pragma(warning(disable:4127)) \
100 __pragma(warning(disable:4242)) \
101 __pragma(warning(disable:4244)) \
102 __pragma(warning(disable:4702))
103 #define DIAG_ON_FLEX \
104 __pragma(warning(pop))
107 * Suppress narrowing warnings.
109 #define DIAG_OFF_NARROWING \
110 __pragma(warning(push)) \
111 __pragma(warning(disable:4242)) \
112 __pragma(warning(disable:4311))
113 #define DIAG_ON_NARROWING \
114 __pragma(warning(pop))
117 * Suppress deprecation warnings.
119 #define DIAG_OFF_DEPRECATION \
120 __pragma(warning(push)) \
121 __pragma(warning(disable:4996))
122 #define DIAG_ON_DEPRECATION \
123 __pragma(warning(pop))
124 #define DIAG_OFF_FORMAT_TRUNCATION
125 #define DIAG_ON_FORMAT_TRUNCATION
126 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
128 * This is Clang 2.8 or later; we can use "clang diagnostic
129 * ignored -Wxxx" and "clang diagnostic push/pop".
131 * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation,
132 * at least according to the GCC 7.3 documentation. Apparently, Flex
133 * generates code that upsets at least some versions of Clang's
136 #define DIAG_OFF_FLEX \
137 PCAP_DO_PRAGMA(clang diagnostic push) \
138 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
139 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
140 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") \
141 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
142 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
143 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
144 #define DIAG_ON_FLEX \
145 PCAP_DO_PRAGMA(clang diagnostic pop)
148 * Suppress the only narrowing warnings you get from Clang.
150 #define DIAG_OFF_NARROWING \
151 PCAP_DO_PRAGMA(clang diagnostic push) \
152 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32")
154 #define DIAG_ON_NARROWING \
155 PCAP_DO_PRAGMA(clang diagnostic pop)
158 * Suppress deprecation warnings.
160 #define DIAG_OFF_DEPRECATION \
161 PCAP_DO_PRAGMA(clang diagnostic push) \
162 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
163 #define DIAG_ON_DEPRECATION \
164 PCAP_DO_PRAGMA(clang diagnostic pop)
165 #define DIAG_OFF_FORMAT_TRUNCATION
166 #define DIAG_ON_FORMAT_TRUNCATION
167 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
169 * This is GCC 4.6 or later, or a compiler claiming to be that.
170 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
171 * and "GCC diagnostic push/pop" (introduced in 4.6).
173 #define DIAG_OFF_FLEX \
174 PCAP_DO_PRAGMA(GCC diagnostic push) \
175 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
176 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
177 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
178 #define DIAG_ON_FLEX \
179 PCAP_DO_PRAGMA(GCC diagnostic pop)
182 * GCC currently doesn't issue any narrowing warnings.
184 #define DIAG_OFF_NARROWING
185 #define DIAG_ON_NARROWING
188 * Suppress deprecation warnings.
190 #define DIAG_OFF_DEPRECATION \
191 PCAP_DO_PRAGMA(GCC diagnostic push) \
192 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
193 #define DIAG_ON_DEPRECATION \
194 PCAP_DO_PRAGMA(GCC diagnostic pop)
197 * Suppress format-truncation= warnings.
198 * GCC 7.1 had introduced this warning option. Earlier versions (at least
199 * one particular copy of GCC 4.6.4) treat the request as a warning.
201 #if PCAP_IS_AT_LEAST_GNUC_VERSION(7,1)
202 #define DIAG_OFF_FORMAT_TRUNCATION \
203 PCAP_DO_PRAGMA(GCC diagnostic push) \
204 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wformat-truncation=")
205 #define DIAG_ON_FORMAT_TRUNCATION \
206 PCAP_DO_PRAGMA(GCC diagnostic pop)
208 #define DIAG_OFF_FORMAT_TRUNCATION
209 #define DIAG_ON_FORMAT_TRUNCATION
213 * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
214 * or a compiler claiming to be that; there's nothing we know of that
217 #define DIAG_OFF_FLEX
219 #define DIAG_OFF_NARROWING
220 #define DIAG_ON_NARROWING
221 #define DIAG_OFF_DEPRECATION
222 #define DIAG_ON_DEPRECATION
223 #define DIAG_OFF_FORMAT_TRUNCATION
224 #define DIAG_ON_FORMAT_TRUNCATION
231 * It generates a global declaration of yylval, or the appropriately
232 * prefixed version of yylval, in grammar.h, *even though it's been
233 * told to generate a pure parser, meaning it doesn't have any global
234 * variables*. Bison doesn't do this.
236 * That causes a warning due to the local declaration in the parser
237 * shadowing the global declaration.
239 * So, if the compiler warns about that, we turn off -Wshadow warnings.
241 * In addition, the generated code may have functions with unreachable
242 * code, so suppress warnings about those.
244 #if defined(_MSC_VER)
246 * This is Microsoft Visual Studio; we can use
247 * __pragma(warning(disable:XXXX)).
249 #define DIAG_OFF_BISON_BYACC \
250 __pragma(warning(disable:4702))
251 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
253 * This is Clang 2.8 or later; we can use "clang diagnostic
256 #define DIAG_OFF_BISON_BYACC \
257 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
258 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
259 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
261 * This is GCC 4.6 or later, or a compiler claiming to be that.
262 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
263 * but it may not actually work very well prior to 4.6).
265 #define DIAG_OFF_BISON_BYACC \
266 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
267 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
270 * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
271 * claiming to be that; there's nothing we know of that we can do.
273 #define DIAG_OFF_BISON_BYACC
279 * The generated code may have functions with unreachable code and
280 * switches with only a default case, so suppress warnings about those.
282 #if defined(_MSC_VER)
284 * This is Microsoft Visual Studio; we can use
285 * __pragma(warning(disable:XXXX)).
287 * Suppress some /Wall warnings.
289 #define DIAG_OFF_BISON_BYACC \
290 __pragma(warning(disable:4065)) \
291 __pragma(warning(disable:4127)) \
292 __pragma(warning(disable:4242)) \
293 __pragma(warning(disable:4244)) \
294 __pragma(warning(disable:4702))
295 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
297 * This is Clang 2.8 or later; we can use "clang diagnostic
300 #define DIAG_OFF_BISON_BYACC \
301 PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
302 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
304 * This is GCC 4.6 or later, or a compiler claiming to be that.
305 * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2,
306 * but it may not actually work very well prior to 4.6).
308 #define DIAG_OFF_BISON_BYACC \
309 PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
312 * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
313 * claiming to be that; there's nothing we know of that we can do.
315 #define DIAG_OFF_BISON_BYACC
320 * GCC needs this on AIX for longjmp().
322 #if PCAP_IS_AT_LEAST_GNUC_VERSION(5,1)
324 * Beware that the effect of this builtin is more than just squelching the
325 * warning! GCC trusts it enough for the process to segfault if the control
326 * flow reaches the builtin (an infinite empty loop in the same context would
327 * squelch the warning and ruin the process too, albeit in a different way).
328 * So please remember to use this very carefully.
330 #define PCAP_UNREACHABLE __builtin_unreachable();
332 #define PCAP_UNREACHABLE
335 #endif /* _diag_control_h */