1335640Shselasky/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ 2335640Shselasky/* 3335640Shselasky * Copyright (c) 1993, 1994, 1995, 1996, 1997 4335640Shselasky * The Regents of the University of California. All rights reserved. 5335640Shselasky * 6335640Shselasky * Redistribution and use in source and binary forms, with or without 7335640Shselasky * modification, are permitted provided that the following conditions 8335640Shselasky * are met: 9335640Shselasky * 1. Redistributions of source code must retain the above copyright 10335640Shselasky * notice, this list of conditions and the following disclaimer. 11335640Shselasky * 2. Redistributions in binary form must reproduce the above copyright 12335640Shselasky * notice, this list of conditions and the following disclaimer in the 13335640Shselasky * documentation and/or other materials provided with the distribution. 14335640Shselasky * 3. All advertising materials mentioning features or use of this software 15335640Shselasky * must display the following acknowledgement: 16335640Shselasky * This product includes software developed by the Computer Systems 17335640Shselasky * Engineering Group at Lawrence Berkeley Laboratory. 18335640Shselasky * 4. Neither the name of the University nor of the Laboratory may be used 19335640Shselasky * to endorse or promote products derived from this software without 20335640Shselasky * specific prior written permission. 21335640Shselasky * 22335640Shselasky * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23335640Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24335640Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25335640Shselasky * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26335640Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27335640Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28335640Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29335640Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30335640Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31335640Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32335640Shselasky * SUCH DAMAGE. 33335640Shselasky */ 34335640Shselasky 35335640Shselasky#ifndef _diag_control_h 36335640Shselasky#define _diag_control_h 37335640Shselasky 38335640Shselasky#include "pcap/compiler-tests.h" 39335640Shselasky 40335640Shselasky#ifndef _MSC_VER 41335640Shselasky /* 42335640Shselasky * Clang and GCC both support this way of putting pragmas into #defines. 43335640Shselasky * We don't use it unless we have a compiler that supports it; the 44335640Shselasky * warning-suppressing pragmas differ between Clang and GCC, so we test 45335640Shselasky * for both of those separately. 46335640Shselasky */ 47335640Shselasky #define PCAP_DO_PRAGMA(x) _Pragma (#x) 48335640Shselasky#endif 49335640Shselasky 50335640Shselasky/* 51335640Shselasky * Suppress Flex warnings. 52335640Shselasky */ 53335640Shselasky#if defined(_MSC_VER) 54335640Shselasky /* 55335640Shselasky * This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX)) 56335640Shselasky * and __pragma(warning(push/pop)). 57335640Shselasky * 58335640Shselasky * Suppress signed-vs-unsigned comparison, narrowing, and unreachable 59335640Shselasky * code warnings. 60335640Shselasky */ 61335640Shselasky #define DIAG_OFF_FLEX \ 62335640Shselasky __pragma(warning(push)) \ 63335640Shselasky __pragma(warning(disable:4127)) \ 64335640Shselasky __pragma(warning(disable:4242)) \ 65335640Shselasky __pragma(warning(disable:4244)) \ 66335640Shselasky __pragma(warning(disable:4702)) 67335640Shselasky #define DIAG_ON_FLEX __pragma(warning(pop)) 68335640Shselasky#elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) 69335640Shselasky /* 70335640Shselasky * This is Clang 2.8 or later; we can use "clang diagnostic 71335640Shselasky * ignored -Wxxx" and "clang diagnostic push/pop". 72335640Shselasky * 73335640Shselasky * Suppress -Wdocumentation warnings; GCC doesn't support -Wdocumentation, 74335640Shselasky * at least according to the GCC 7.3 documentation. Apparently, Flex 75335640Shselasky * generates code that upsets at least some versions of Clang's 76335640Shselasky * -Wdocumentation. 77335640Shselasky */ 78335640Shselasky #define DIAG_OFF_FLEX \ 79335640Shselasky PCAP_DO_PRAGMA(clang diagnostic push) \ 80335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \ 81335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \ 82335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \ 83335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \ 84335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code") 85335640Shselasky #define DIAG_ON_FLEX \ 86335640Shselasky PCAP_DO_PRAGMA(clang diagnostic pop) 87335640Shselasky#elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) 88335640Shselasky /* 89335640Shselasky * This is GCC 4.6 or later, or a compiler claiming to be that. 90335640Shselasky * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2) 91335640Shselasky * and "GCC diagnostic push/pop" (introduced in 4.6). 92335640Shselasky */ 93335640Shselasky #define DIAG_OFF_FLEX \ 94335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic push) \ 95335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wsign-compare") \ 96335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-parameter") \ 97335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code") 98335640Shselasky #define DIAG_ON_FLEX \ 99335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic pop) 100335640Shselasky#else 101335640Shselasky /* 102335640Shselasky * Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later 103335640Shselasky * or a compiler claiming to be that; there's nothing we know of that 104335640Shselasky * we can do. 105335640Shselasky */ 106335640Shselasky #define DIAG_OFF_FLEX 107335640Shselasky #define DIAG_ON_FLEX 108335640Shselasky#endif 109335640Shselasky 110335640Shselasky#ifdef YYBYACC 111335640Shselasky /* 112335640Shselasky * Berkeley YACC. 113335640Shselasky * 114335640Shselasky * It generates a global declaration of yylval, or the appropriately 115335640Shselasky * prefixed version of yylval, in grammar.h, *even though it's been 116335640Shselasky * told to generate a pure parser, meaning it doesn't have any global 117335640Shselasky * variables*. Bison doesn't do this. 118335640Shselasky * 119335640Shselasky * That causes a warning due to the local declaration in the parser 120335640Shselasky * shadowing the global declaration. 121335640Shselasky * 122335640Shselasky * So, if the compiler warns about that, we turn off -Wshadow warnings. 123356341Scy * 124356341Scy * In addition, the generated code may have functions with unreachable 125356341Scy * code, so suppress warnings about those. 126335640Shselasky */ 127335640Shselasky #if defined(_MSC_VER) 128335640Shselasky /* 129335640Shselasky * This is Microsoft Visual Studio; we can use 130335640Shselasky * __pragma(warning(disable:XXXX)) and __pragma(warning(push/pop)). 131335640Shselasky */ 132335640Shselasky #define DIAG_OFF_BISON_BYACC \ 133335640Shselasky __pragma(warning(push)) \ 134335640Shselasky __pragma(warning(disable:4702)) 135335640Shselasky #define DIAG_ON_BISON_BYACC __pragma(warning(pop)) 136335640Shselasky #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) 137335640Shselasky /* 138335640Shselasky * This is Clang 2.8 or later; we can use "clang diagnostic 139335640Shselasky * ignored -Wxxx" and "clang diagnostic push/pop". 140335640Shselasky */ 141335640Shselasky #define DIAG_OFF_BISON_BYACC \ 142335640Shselasky PCAP_DO_PRAGMA(clang diagnostic push) \ 143335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshadow") \ 144335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code") 145335640Shselasky #define DIAG_ON_BISON_BYACC \ 146335640Shselasky PCAP_DO_PRAGMA(clang diagnostic pop) 147335640Shselasky #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) 148335640Shselasky /* 149335640Shselasky * This is GCC 4.6 or later, or a compiler claiming to be that. 150335640Shselasky * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2) 151335640Shselasky * and "GCC diagnostic push/pop" (introduced in 4.6). 152335640Shselasky */ 153335640Shselasky #define DIAG_OFF_BISON_BYACC \ 154335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic push) \ 155335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \ 156335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code") 157335640Shselasky #define DIAG_ON_BISON_BYACC \ 158335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic pop) 159335640Shselasky #else 160335640Shselasky /* 161335640Shselasky * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler 162335640Shselasky * claiming to be that; there's nothing we know of that we can do. 163335640Shselasky */ 164335640Shselasky #define DIAG_OFF_BISON_BYACC 165335640Shselasky #define DIAG_ON_BISON_BYACC 166335640Shselasky #endif 167335640Shselasky#else 168335640Shselasky /* 169335640Shselasky * Bison. 170356341Scy * 171356341Scy * The generated code may have functions with unreachable code, so 172356341Scy * suppress warnings about those. 173335640Shselasky */ 174335640Shselasky #if defined(_MSC_VER) 175335640Shselasky /* 176335640Shselasky * This is Microsoft Visual Studio; we can use 177335640Shselasky * __pragma(warning(disable:XXXX)) and __pragma(warning(push/pop)). 178335640Shselasky * 179335640Shselasky * Suppress some /Wall warnings. 180335640Shselasky */ 181335640Shselasky #define DIAG_OFF_BISON_BYACC \ 182335640Shselasky __pragma(warning(push)) \ 183335640Shselasky __pragma(warning(disable:4127)) \ 184335640Shselasky __pragma(warning(disable:4242)) \ 185335640Shselasky __pragma(warning(disable:4244)) \ 186335640Shselasky __pragma(warning(disable:4702)) 187335640Shselasky #define DIAG_ON_BISON_BYACC __pragma(warning(pop)) 188335640Shselasky #elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) 189335640Shselasky /* 190335640Shselasky * This is Clang 2.8 or later; we can use "clang diagnostic 191335640Shselasky * ignored -Wxxx" and "clang diagnostic push/pop". 192335640Shselasky */ 193335640Shselasky #define DIAG_OFF_BISON_BYACC \ 194335640Shselasky PCAP_DO_PRAGMA(clang diagnostic push) \ 195335640Shselasky PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code") 196335640Shselasky #define DIAG_ON_BISON_BYACC \ 197335640Shselasky PCAP_DO_PRAGMA(clang diagnostic pop) 198335640Shselasky #elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) 199335640Shselasky /* 200335640Shselasky * This is GCC 4.6 or later, or a compiler claiming to be that. 201335640Shselasky * We can use "GCC diagnostic ignored -Wxxx" (introduced in 4.2) 202335640Shselasky * and "GCC diagnostic push/pop" (introduced in 4.6). 203335640Shselasky */ 204335640Shselasky #define DIAG_OFF_BISON_BYACC \ 205335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic push) \ 206335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code") 207335640Shselasky #define DIAG_ON_BISON_BYACC \ 208335640Shselasky PCAP_DO_PRAGMA(GCC diagnostic pop) 209335640Shselasky #else 210335640Shselasky /* 211335640Shselasky * Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler 212335640Shselasky * claiming to be that; there's nothing we know of that we can do. 213335640Shselasky */ 214335640Shselasky #define DIAG_OFF_BISON_BYACC 215335640Shselasky #define DIAG_ON_BISON_BYACC 216335640Shselasky #endif 217335640Shselasky#endif 218335640Shselasky 219335640Shselasky#endif /* _diag_control_h */ 220