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