xref: /dragonfly/contrib/libpcap/diag-control.h (revision 479ab7f0)
1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2 /*
3  * Copyright (c) 1993, 1994, 1995, 1996, 1997
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
21  *
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
32  * SUCH DAMAGE.
33  */
34 
35 #ifndef _diag_control_h
36 #define _diag_control_h
37 
38 #include "pcap/compiler-tests.h"
39 
40 #ifndef _MSC_VER
41   /*
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.
46    */
47   #define PCAP_DO_PRAGMA(x) _Pragma (#x)
48 #endif
49 
50 /*
51  * Suppress Flex warnings.
52  */
53 #if defined(_MSC_VER)
54   /*
55    * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
56    * and __pragma(warning(push/pop)).
57    *
58    * Suppress signed-vs-unsigned comparison, narrowing, and unreachable
59    * code warnings.
60    */
61   #define DIAG_OFF_FLEX \
62     __pragma(warning(push)) \
63     __pragma(warning(disable:4127)) \
64     __pragma(warning(disable:4242)) \
65     __pragma(warning(disable:4244)) \
66     __pragma(warning(disable:4702))
67   #define DIAG_ON_FLEX  __pragma(warning(pop))
68 #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
69   /*
70    * This is Clang 2.8 or later; we can use "clang diagnostic
71    * ignored -Wxxx" and "clang diagnostic push/pop".
72    *
73    * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation,
74    * at least according to the GCC 7.3 documentation.  Apparently, Flex
75    * generates code that upsets at least some versions of Clang's
76    * -Wdocumentation.
77    */
78   #define DIAG_OFF_FLEX \
79     PCAP_DO_PRAGMA(clang diagnostic push) \
80     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
81     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
82     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
83     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
84     PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
85   #define DIAG_ON_FLEX \
86     PCAP_DO_PRAGMA(clang diagnostic pop)
87 #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
88   /*
89    * This is GCC 4.6 or later, or a compiler claiming to be that.
90    * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
91    * and "GCC diagnostic push/pop" (introduced in 4.6).
92    */
93   #define DIAG_OFF_FLEX \
94     PCAP_DO_PRAGMA(GCC diagnostic push) \
95     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \
96     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \
97     PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
98   #define DIAG_ON_FLEX \
99     PCAP_DO_PRAGMA(GCC diagnostic pop)
100 #else
101   /*
102    * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
103    * or a compiler claiming to be that; there's nothing we know of that
104    * we can do.
105    */
106   #define DIAG_OFF_FLEX
107   #define DIAG_ON_FLEX
108 #endif
109 
110 #ifdef YYBYACC
111   /*
112    * Berkeley YACC.
113    *
114    * It generates a global declaration of yylval, or the appropriately
115    * prefixed version of yylval, in grammar.h, *even though it's been
116    * told to generate a pure parser, meaning it doesn't have any global
117    * variables*.  Bison doesn't do this.
118    *
119    * That causes a warning due to the local declaration in the parser
120    * shadowing the global declaration.
121    *
122    * So, if the compiler warns about that, we turn off -Wshadow warnings.
123    *
124    * In addition, the generated code may have functions with unreachable
125    * code, so suppress warnings about those.
126    */
127   #if defined(_MSC_VER)
128     /*
129      * This is Microsoft Visual Studio; we can use
130      * __pragma(warning(disable:XXXX)) and __pragma(warning(push/pop)).
131      */
132     #define DIAG_OFF_BISON_BYACC \
133       __pragma(warning(push)) \
134       __pragma(warning(disable:4702))
135     #define DIAG_ON_BISON_BYACC  __pragma(warning(pop))
136   #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
137     /*
138      * This is Clang 2.8 or later; we can use "clang diagnostic
139      * ignored -Wxxx" and "clang diagnostic push/pop".
140      */
141     #define DIAG_OFF_BISON_BYACC \
142       PCAP_DO_PRAGMA(clang diagnostic push) \
143       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \
144       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
145     #define DIAG_ON_BISON_BYACC \
146       PCAP_DO_PRAGMA(clang diagnostic pop)
147   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
148     /*
149      * This is GCC 4.6 or later, or a compiler claiming to be that.
150      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
151      * and "GCC diagnostic push/pop" (introduced in 4.6).
152      */
153     #define DIAG_OFF_BISON_BYACC \
154       PCAP_DO_PRAGMA(GCC diagnostic push) \
155       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
156       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
157     #define DIAG_ON_BISON_BYACC \
158       PCAP_DO_PRAGMA(GCC diagnostic pop)
159   #else
160     /*
161      * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
162      * claiming to be that; there's nothing we know of that we can do.
163      */
164     #define DIAG_OFF_BISON_BYACC
165     #define DIAG_ON_BISON_BYACC
166   #endif
167 #else
168   /*
169    * Bison.
170    *
171    * The generated code may have functions with unreachable code, so
172    * suppress warnings about those.
173    */
174   #if defined(_MSC_VER)
175     /*
176      * This is Microsoft Visual Studio; we can use
177      * __pragma(warning(disable:XXXX)) and __pragma(warning(push/pop)).
178      *
179      * Suppress some /Wall warnings.
180      */
181     #define DIAG_OFF_BISON_BYACC \
182       __pragma(warning(push)) \
183       __pragma(warning(disable:4127)) \
184       __pragma(warning(disable:4242)) \
185       __pragma(warning(disable:4244)) \
186       __pragma(warning(disable:4702))
187     #define DIAG_ON_BISON_BYACC  __pragma(warning(pop))
188   #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
189     /*
190      * This is Clang 2.8 or later; we can use "clang diagnostic
191      * ignored -Wxxx" and "clang diagnostic push/pop".
192      */
193     #define DIAG_OFF_BISON_BYACC \
194       PCAP_DO_PRAGMA(clang diagnostic push) \
195       PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
196     #define DIAG_ON_BISON_BYACC \
197       PCAP_DO_PRAGMA(clang diagnostic pop)
198   #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
199     /*
200      * This is GCC 4.6 or later, or a compiler claiming to be that.
201      * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2)
202      * and "GCC diagnostic push/pop" (introduced in 4.6).
203      */
204     #define DIAG_OFF_BISON_BYACC \
205       PCAP_DO_PRAGMA(GCC diagnostic push) \
206       PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
207     #define DIAG_ON_BISON_BYACC \
208       PCAP_DO_PRAGMA(GCC diagnostic pop)
209   #else
210     /*
211      * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
212      * claiming to be that; there's nothing we know of that we can do.
213      */
214     #define DIAG_OFF_BISON_BYACC
215     #define DIAG_ON_BISON_BYACC
216   #endif
217 #endif
218 
219 #endif /* _diag_control_h */
220