diag-control.h 8.3 KB

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