2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef WTF_Compiler_h
27 #define WTF_Compiler_h
29 /* COMPILER() - the compiler being used to build the project */
30 #define COMPILER(WTF_FEATURE) (defined WTF_COMPILER_##WTF_FEATURE && WTF_COMPILER_##WTF_FEATURE)
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)
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)
38 /* ==== COMPILER() - the compiler being used to build the project ==== */
40 /* COMPILER(CLANG) - Clang */
41 #if defined(__clang__)
42 #define WTF_COMPILER_CLANG 1
45 /* COMPILER(MSVC) - Microsoft Visual C++ */
47 #define WTF_COMPILER_MSVC 1
50 /* COMPILER(GCC) - GNU Compiler Collection */
52 #define WTF_COMPILER_GCC 1
53 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
54 #define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
56 /* Define this for !GCC compilers, just so we can write things like GCC_VERSION_AT_LEAST(4, 1, 0). */
57 #define GCC_VERSION_AT_LEAST(major, minor, patch) 0
60 /* ==== Compiler features ==== */
66 #if COMPILER(GCC) && defined(NDEBUG) && !COMPILER(MINGW)
67 #define ALWAYS_INLINE inline __attribute__((__always_inline__))
68 #elif COMPILER(MSVC) && defined(NDEBUG)
69 #define ALWAYS_INLINE __forceinline
71 #define ALWAYS_INLINE inline
80 #define NEVER_INLINE __attribute__((__noinline__))
82 #define NEVER_INLINE __declspec(noinline)
93 #define UNLIKELY(x) __builtin_expect((x), 0)
95 #define UNLIKELY(x) (x)
104 #define LIKELY(x) __builtin_expect((x), 1)
106 #define LIKELY(x) (x)
115 #define NO_RETURN __attribute((__noreturn__))
117 #define NO_RETURN __declspec(noreturn)
124 /* WARN_UNUSED_RETURN */
127 #define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result))
129 #define WARN_UNUSED_RETURN
133 /* ALLOW_UNUSED_LOCAL */
135 #define ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0
142 #define OBJC_CLASS @class
144 #define OBJC_CLASS class
149 /* WTF_PRETTY_FUNCTION */
152 #define WTF_COMPILER_SUPPORTS_PRETTY_FUNCTION 1
153 #define WTF_PRETTY_FUNCTION __PRETTY_FUNCTION__
155 #define WTF_COMPILER_SUPPORTS_PRETTY_FUNCTION 1
156 #define WTF_PRETTY_FUNCTION __FUNCSIG__
158 #define WTF_PRETTY_FUNCTION __FUNCTION__
162 /* NO_SANITIZE_UNRELATED_CAST - Disable runtime checks related to casts between
163 * unrelated objects (-fsanitize=cfi-unrelated-cast or -fsanitize=vptr). */
166 #define NO_SANITIZE_UNRELATED_CAST __attribute__((no_sanitize("cfi-unrelated-cast", "vptr")))
168 #define NO_SANITIZE_UNRELATED_CAST
171 #endif /* WTF_Compiler_h */