1/* 2 * Copyright (C) 2011, 2012, 2014 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef WTF_Compiler_h 27#define WTF_Compiler_h 28 29/* COMPILER() - the compiler being used to build the project */ 30#define COMPILER(WTF_FEATURE) (defined WTF_COMPILER_##WTF_FEATURE && WTF_COMPILER_##WTF_FEATURE) 31 32/* COMPILER_SUPPORTS() - whether the compiler being used to build the project supports the given feature. */ 33#define COMPILER_SUPPORTS(WTF_COMPILER_FEATURE) (defined WTF_COMPILER_SUPPORTS_##WTF_COMPILER_FEATURE && WTF_COMPILER_SUPPORTS_##WTF_COMPILER_FEATURE) 34 35/* COMPILER_QUIRK() - whether the compiler being used to build the project requires a given quirk. */ 36#define COMPILER_QUIRK(WTF_COMPILER_QUIRK) (defined WTF_COMPILER_QUIRK_##WTF_COMPILER_QUIRK && WTF_COMPILER_QUIRK_##WTF_COMPILER_QUIRK) 37 38/* ==== COMPILER() - primary detection of the compiler being used to build the project, in alphabetical order ==== */ 39 40/* COMPILER(CLANG) - Clang */ 41 42#if defined(__clang__) 43#define WTF_COMPILER_CLANG 1 44#define WTF_COMPILER_SUPPORTS_BLOCKS __has_feature(blocks) 45#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT __has_feature(c_static_assert) 46#define WTF_COMPILER_SUPPORTS_CXX_CONSTEXPR __has_feature(cxx_constexpr) 47#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS __has_feature(cxx_reference_qualified_functions) 48#define WTF_COMPILER_SUPPORTS_CXX_USER_LITERALS __has_feature(cxx_user_literals) 49#define WTF_COMPILER_SUPPORTS_FALLTHROUGH_WARNINGS __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough") 50#endif 51 52/* COMPILER(GCC) - GNU Compiler Collection */ 53 54/* Note: This section must come after the Clang section since we check !COMPILER(CLANG) here. */ 55 56#if defined(__GNUC__) 57#define WTF_COMPILER_GCC 1 58#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 59#define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch)) 60#endif 61 62/* Define GCC_VERSION_AT_LEAST for all compilers, so we can write things like GCC_VERSION_AT_LEAST(4, 1, 0). */ 63/* FIXME: Doesn't seem all that valuable. Can we remove this? */ 64#if !defined(GCC_VERSION_AT_LEAST) 65#define GCC_VERSION_AT_LEAST(major, minor, patch) 0 66#endif 67 68#if COMPILER(GCC) && !COMPILER(CLANG) && !GCC_VERSION_AT_LEAST(4, 7, 0) 69#error "Please use a newer version of GCC. WebKit requires GCC 4.7.0 or newer to compile." 70#endif 71 72#if COMPILER(GCC) && !COMPILER(CLANG) 73#define WTF_COMPILER_SUPPORTS_CXX_CONSTEXPR 1 74#define WTF_COMPILER_SUPPORTS_CXX_USER_LITERALS 1 75#endif 76 77#if COMPILER(GCC) && !COMPILER(CLANG) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L 78#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT 1 79#endif 80 81#if COMPILER(GCC) && !COMPILER(CLANG) && GCC_VERSION_AT_LEAST(4, 8, 0) 82#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 83#endif 84 85#if COMPILER(GCC) && !COMPILER(CLANG) && (defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(__cplusplus) && __cplusplus >= 201103L)) 86#pragma GCC diagnostic ignored "-Wunused-local-typedefs" 87#endif 88 89/* COMPILER(MINGW) - MinGW GCC */ 90 91#if defined(__MINGW32__) 92#define WTF_COMPILER_MINGW 1 93#include <_mingw.h> 94#endif 95 96/* COMPILER(MINGW64) - mingw-w64 GCC - used as additional check to exclude mingw.org specific functions */ 97 98/* Note: This section must come after the MinGW section since we check COMPILER(MINGW) here. */ 99 100#if COMPILER(MINGW) && defined(__MINGW64_VERSION_MAJOR) /* best way to check for mingw-w64 vs mingw.org */ 101#define WTF_COMPILER_MINGW64 1 102#endif 103 104/* COMPILER(MSVC) - Microsoft Visual C++ */ 105 106#if defined(_MSC_VER) 107#define WTF_COMPILER_MSVC 1 108#endif 109 110#if defined(_MSC_VER) && _MSC_VER < 1800 111#error "Please use a newer version of Visual Studio. WebKit requires VS2013 or newer to compile." 112#endif 113 114/* COMPILER(SUNCC) */ 115 116#if defined(__SUNPRO_CC) || defined(__SUNPRO_C) 117#define WTF_COMPILER_SUNCC 1 118#endif 119 120/* ==== COMPILER_SUPPORTS - additional compiler feature detection, in alphabetical order ==== */ 121 122/* COMPILER_SUPPORTS(EABI) */ 123 124#if defined(__ARM_EABI__) || defined(__EABI__) 125#define WTF_COMPILER_SUPPORTS_EABI 1 126#endif 127 128/* ==== Compiler-independent macros for various compiler features, in alphabetical order ==== */ 129 130/* ALWAYS_INLINE */ 131 132#if !defined(ALWAYS_INLINE) && COMPILER(GCC) && defined(NDEBUG) && !COMPILER(MINGW) 133#define ALWAYS_INLINE inline __attribute__((__always_inline__)) 134#endif 135 136#if !defined(ALWAYS_INLINE) && COMPILER(MSVC) && defined(NDEBUG) 137#define ALWAYS_INLINE __forceinline 138#endif 139 140#if !defined(ALWAYS_INLINE) 141#define ALWAYS_INLINE inline 142#endif 143 144/* CONSTEXPR */ 145 146#if !defined(CONSTEXPR) && COMPILER_SUPPORTS(CXX_CONSTEXPR) 147#define CONSTEXPR constexpr 148#endif 149 150#if !defined(CONSTEXPR) 151#define CONSTEXPR 152#endif 153 154/* FALLTHROUGH */ 155 156#if !defined(FALLTHROUGH) && COMPILER_SUPPORTS(FALLTHROUGH_WARNINGS) && COMPILER(CLANG) 157#define FALLTHROUGH [[clang::fallthrough]] 158#endif 159 160#if !defined(FALLTHROUGH) 161#define FALLTHROUGH 162#endif 163 164/* LIKELY */ 165 166#if !defined(LIKELY) && COMPILER(GCC) 167#define LIKELY(x) __builtin_expect(!!(x), 1) 168#endif 169 170#if !defined(LIKELY) 171#define LIKELY(x) (x) 172#endif 173 174/* NEVER_INLINE */ 175 176#if !defined(NEVER_INLINE) && COMPILER(GCC) 177#define NEVER_INLINE __attribute__((__noinline__)) 178#endif 179 180#if !defined(NEVER_INLINE) && COMPILER(MSVC) 181#define NEVER_INLINE __declspec(noinline) 182#endif 183 184#if !defined(NEVER_INLINE) 185#define NEVER_INLINE 186#endif 187 188/* NO_RETURN */ 189 190#if !defined(NO_RETURN) && COMPILER(GCC) 191#define NO_RETURN __attribute((__noreturn__)) 192#endif 193 194#if !defined(NO_RETURN) && COMPILER(MSVC) 195#define NO_RETURN __declspec(noreturn) 196#endif 197 198#if !defined(NO_RETURN) 199#define NO_RETURN 200#endif 201 202/* NO_RETURN_WITH_VALUE */ 203 204#if !defined(NO_RETURN_WITH_VALUE) && !COMPILER(MSVC) 205#define NO_RETURN_WITH_VALUE NO_RETURN 206#endif 207 208#if !defined(NO_RETURN_WITH_VALUE) 209#define NO_RETURN_WITH_VALUE 210#endif 211 212/* OBJC_CLASS */ 213 214#if !defined(OBJC_CLASS) && defined(__OBJC__) 215#define OBJC_CLASS @class 216#endif 217 218#if !defined(OBJC_CLASS) 219#define OBJC_CLASS class 220#endif 221 222/* PURE_FUNCTION */ 223 224#if !defined(PURE_FUNCTION) && COMPILER(GCC) 225#define PURE_FUNCTION __attribute__((__pure__)) 226#endif 227 228#if !defined(PURE_FUNCTION) 229#define PURE_FUNCTION 230#endif 231 232/* REFERENCED_FROM_ASM */ 233 234#if !defined(REFERENCED_FROM_ASM) && COMPILER(GCC) 235#define REFERENCED_FROM_ASM __attribute__((__used__)) 236#endif 237 238#if !defined(REFERENCED_FROM_ASM) 239#define REFERENCED_FROM_ASM 240#endif 241 242/* UNLIKELY */ 243 244#if !defined(UNLIKELY) && COMPILER(GCC) 245#define UNLIKELY(x) __builtin_expect(!!(x), 0) 246#endif 247 248#if !defined(UNLIKELY) 249#define UNLIKELY(x) (x) 250#endif 251 252/* UNUSED_LABEL */ 253 254/* Keep the compiler from complaining for a local label that is defined but not referenced. */ 255/* Helpful when mixing hand-written and autogenerated code. */ 256 257#if !defined(UNUSED_LABEL) && COMPILER(MSVC) 258#define UNUSED_LABEL(label) if (false) goto label 259#endif 260 261#if !defined(UNUSED_LABEL) 262#define UNUSED_LABEL(label) UNUSED_PARAM(&& label) 263#endif 264 265/* UNUSED_PARAM */ 266 267#if !defined(UNUSED_PARAM) && COMPILER(MSVC) 268#define UNUSED_PARAM(variable) (void)&variable 269#endif 270 271#if !defined(UNUSED_PARAM) 272#define UNUSED_PARAM(variable) (void)variable 273#endif 274 275/* WARN_UNUSED_RETURN */ 276 277#if !defined(WARN_UNUSED_RETURN) && COMPILER(GCC) 278#define WARN_UNUSED_RETURN __attribute__((__warn_unused_result__)) 279#endif 280 281#if !defined(WARN_UNUSED_RETURN) 282#define WARN_UNUSED_RETURN 283#endif 284 285#endif /* WTF_Compiler_h */ 286