1*d881c474Schristos /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ 2*d881c474Schristos /* 3*d881c474Schristos * Copyright (c) 1993, 1994, 1995, 1996, 1997 4*d881c474Schristos * The Regents of the University of California. All rights reserved. 5*d881c474Schristos * 6*d881c474Schristos * Redistribution and use in source and binary forms, with or without 7*d881c474Schristos * modification, are permitted provided that the following conditions 8*d881c474Schristos * are met: 9*d881c474Schristos * 1. Redistributions of source code must retain the above copyright 10*d881c474Schristos * notice, this list of conditions and the following disclaimer. 11*d881c474Schristos * 2. Redistributions in binary form must reproduce the above copyright 12*d881c474Schristos * notice, this list of conditions and the following disclaimer in the 13*d881c474Schristos * documentation and/or other materials provided with the distribution. 14*d881c474Schristos * 3. All advertising materials mentioning features or use of this software 15*d881c474Schristos * must display the following acknowledgement: 16*d881c474Schristos * This product includes software developed by the Computer Systems 17*d881c474Schristos * Engineering Group at Lawrence Berkeley Laboratory. 18*d881c474Schristos * 4. Neither the name of the University nor of the Laboratory may be used 19*d881c474Schristos * to endorse or promote products derived from this software without 20*d881c474Schristos * specific prior written permission. 21*d881c474Schristos * 22*d881c474Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*d881c474Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*d881c474Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*d881c474Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*d881c474Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*d881c474Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*d881c474Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*d881c474Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*d881c474Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*d881c474Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*d881c474Schristos * SUCH DAMAGE. 33*d881c474Schristos */ 34*d881c474Schristos 35*d881c474Schristos #ifndef nd_compiler_tests_h 36*d881c474Schristos #define nd_compiler_tests_h 37*d881c474Schristos 38*d881c474Schristos /* 39*d881c474Schristos * This was introduced by Clang: 40*d881c474Schristos * 41*d881c474Schristos * https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute 42*d881c474Schristos * 43*d881c474Schristos * in some version (which version?); it has been picked up by GCC 5.0. 44*d881c474Schristos */ 45*d881c474Schristos #ifndef __has_attribute 46*d881c474Schristos /* 47*d881c474Schristos * It's a macro, so you can check whether it's defined to check 48*d881c474Schristos * whether it's supported. 49*d881c474Schristos * 50*d881c474Schristos * If it's not, define it to always return 0, so that we move on to 51*d881c474Schristos * the fallback checks. 52*d881c474Schristos */ 53*d881c474Schristos #define __has_attribute(x) 0 54*d881c474Schristos #endif 55*d881c474Schristos 56*d881c474Schristos /* 57*d881c474Schristos * Note that the C90 spec's "6.8.1 Conditional inclusion" and the 58*d881c474Schristos * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: 59*d881c474Schristos * 60*d881c474Schristos * Prior to evaluation, macro invocations in the list of preprocessing 61*d881c474Schristos * tokens that will become the controlling constant expression are 62*d881c474Schristos * replaced (except for those macro names modified by the defined unary 63*d881c474Schristos * operator), just as in normal text. If the token "defined" is 64*d881c474Schristos * generated as a result of this replacement process or use of the 65*d881c474Schristos * "defined" unary operator does not match one of the two specified 66*d881c474Schristos * forms prior to macro replacement, the behavior is undefined. 67*d881c474Schristos * 68*d881c474Schristos * so you shouldn't use defined() in a #define that's used in #if or 69*d881c474Schristos * #elif. Some versions of Clang, for example, will warn about this. 70*d881c474Schristos * 71*d881c474Schristos * Instead, we check whether the pre-defined macros for particular 72*d881c474Schristos * compilers are defined and, if not, define the "is this version XXX 73*d881c474Schristos * or a later version of this compiler" macros as 0. 74*d881c474Schristos */ 75*d881c474Schristos 76*d881c474Schristos /* 77*d881c474Schristos * Check whether this is GCC major.minor or a later release, or some 78*d881c474Schristos * compiler that claims to be "just like GCC" of that version or a 79*d881c474Schristos * later release. 80*d881c474Schristos */ 81*d881c474Schristos 82*d881c474Schristos #if ! defined(__GNUC__) 83*d881c474Schristos /* Not GCC and not "just like GCC" */ 84*d881c474Schristos #define ND_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 85*d881c474Schristos #else 86*d881c474Schristos /* GCC or "just like GCC" */ 87*d881c474Schristos #define ND_IS_AT_LEAST_GNUC_VERSION(major, minor) \ 88*d881c474Schristos (__GNUC__ > (major) || \ 89*d881c474Schristos (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 90*d881c474Schristos #endif 91*d881c474Schristos 92*d881c474Schristos /* 93*d881c474Schristos * Check whether this is Clang major.minor or a later release. 94*d881c474Schristos */ 95*d881c474Schristos 96*d881c474Schristos #if !defined(__clang__) 97*d881c474Schristos /* Not Clang */ 98*d881c474Schristos #define ND_IS_AT_LEAST_CLANG_VERSION(major, minor) 0 99*d881c474Schristos #else 100*d881c474Schristos /* Clang */ 101*d881c474Schristos #define ND_IS_AT_LEAST_CLANG_VERSION(major, minor) \ 102*d881c474Schristos (__clang_major__ > (major) || \ 103*d881c474Schristos (__clang_major__ == (major) && __clang_minor__ >= (minor))) 104*d881c474Schristos #endif 105*d881c474Schristos 106*d881c474Schristos /* 107*d881c474Schristos * Check whether this is Sun C/SunPro C/Oracle Studio major.minor 108*d881c474Schristos * or a later release. 109*d881c474Schristos * 110*d881c474Schristos * The version number in __SUNPRO_C is encoded in hex BCD, with the 111*d881c474Schristos * uppermost hex digit being the major version number, the next 112*d881c474Schristos * one or two hex digits being the minor version number, and 113*d881c474Schristos * the last digit being the patch version. 114*d881c474Schristos * 115*d881c474Schristos * It represents the *compiler* version, not the product version; 116*d881c474Schristos * see 117*d881c474Schristos * 118*d881c474Schristos * https://sourceforge.net/p/predef/wiki/Compilers/ 119*d881c474Schristos * 120*d881c474Schristos * for a partial mapping, which we assume continues for later 121*d881c474Schristos * 12.x product releases. 122*d881c474Schristos */ 123*d881c474Schristos 124*d881c474Schristos #if ! defined(__SUNPRO_C) 125*d881c474Schristos /* Not Sun/Oracle C */ 126*d881c474Schristos #define ND_IS_AT_LEAST_SUNC_VERSION(major,minor) 0 127*d881c474Schristos #else 128*d881c474Schristos /* Sun/Oracle C */ 129*d881c474Schristos #define ND_SUNPRO_VERSION_TO_BCD(major, minor) \ 130*d881c474Schristos (((minor) >= 10) ? \ 131*d881c474Schristos (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ 132*d881c474Schristos (((major) << 8) | ((minor) << 4))) 133*d881c474Schristos #define ND_IS_AT_LEAST_SUNC_VERSION(major,minor) \ 134*d881c474Schristos (__SUNPRO_C >= ND_SUNPRO_VERSION_TO_BCD((major), (minor))) 135*d881c474Schristos #endif 136*d881c474Schristos 137*d881c474Schristos /* 138*d881c474Schristos * Check whether this is IBM XL C major.minor or a later release. 139*d881c474Schristos * 140*d881c474Schristos * The version number in __xlC__ has the major version in the 141*d881c474Schristos * upper 8 bits and the minor version in the lower 8 bits. 142*d881c474Schristos * On AIX __xlC__ is always defined, __ibmxl__ becomes defined in XL C 16.1. 143*d881c474Schristos * On Linux since XL C 13.1.6 __xlC__ is not defined by default anymore, but 144*d881c474Schristos * __ibmxl__ is defined since at least XL C 13.1.1. 145*d881c474Schristos */ 146*d881c474Schristos 147*d881c474Schristos #if ! defined(__xlC__) && ! defined(__ibmxl__) 148*d881c474Schristos /* Not XL C */ 149*d881c474Schristos #define ND_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 150*d881c474Schristos #define ND_IS_AT_LEAST_XL_C_MODFIX(modification, fixlevel) 0 151*d881c474Schristos #else 152*d881c474Schristos /* XL C */ 153*d881c474Schristos #if defined(__ibmxl__) 154*d881c474Schristos /* 155*d881c474Schristos * Later Linux version of XL C; use __ibmxl_version__ to test 156*d881c474Schristos * the version. 157*d881c474Schristos */ 158*d881c474Schristos #define ND_IS_AT_LEAST_XL_C_VERSION(major, minor) \ 159*d881c474Schristos (__ibmxl_version__ > (major) || \ 160*d881c474Schristos (__ibmxl_version__ == (major) && __ibmxl_release__ >= (minor))) 161*d881c474Schristos #define ND_IS_AT_LEAST_XL_C_MODFIX(modification, fixlevel) \ 162*d881c474Schristos (__ibmxl_modification__ > (modification) || \ 163*d881c474Schristos (__ibmxl_modification__ == (modification) && \ 164*d881c474Schristos __ibmxl_ptf_fix_level__ >= (fixlevel))) 165*d881c474Schristos #else /* __ibmxl__ */ 166*d881c474Schristos /* 167*d881c474Schristos * __ibmxl__ not defined; use __xlC__ to test the version. 168*d881c474Schristos */ 169*d881c474Schristos #define ND_IS_AT_LEAST_XL_C_VERSION(major, minor) \ 170*d881c474Schristos (__xlC__ >= (((major) << 8) | (minor))) 171*d881c474Schristos #define ND_IS_AT_LEAST_XL_C_MODFIX(modification, fixlevel) \ 172*d881c474Schristos ((((modification) << 8) | (fixlevel)) >= __xlC_ver__) 173*d881c474Schristos #endif /* __ibmxl__ */ 174*d881c474Schristos #endif 175*d881c474Schristos 176*d881c474Schristos /* 177*d881c474Schristos * Check whether this is HP aC++/HP C major.minor or a later release. 178*d881c474Schristos * 179*d881c474Schristos * The version number in __HP_aCC is encoded in zero-padded decimal BCD, 180*d881c474Schristos * with the "A." stripped off, the uppermost two decimal digits being 181*d881c474Schristos * the major version number, the next two decimal digits being the minor 182*d881c474Schristos * version number, and the last two decimal digits being the patch version. 183*d881c474Schristos * (Strip off the A., remove the . between the major and minor version 184*d881c474Schristos * number, and add two digits of patch.) 185*d881c474Schristos */ 186*d881c474Schristos 187*d881c474Schristos #if ! defined(__HP_aCC) 188*d881c474Schristos /* Not HP C */ 189*d881c474Schristos #define ND_IS_AT_LEAST_HP_C_VERSION(major,minor) 0 190*d881c474Schristos #else 191*d881c474Schristos /* HP C */ 192*d881c474Schristos #define ND_IS_AT_LEAST_HP_C_VERSION(major,minor) \ 193*d881c474Schristos (__HP_aCC >= ((major)*10000 + (minor)*100)) 194*d881c474Schristos #endif 195*d881c474Schristos 196*d881c474Schristos #endif /* nd_funcattrs_h */ 197