Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / wtf / Compiler.h
blob6317ee0a73a40f9e721bd977c344d371aa633a5c
1 /*
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
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.
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
43 #endif
45 /* COMPILER(MSVC) - Microsoft Visual C++ */
46 #if defined(_MSC_VER)
47 #define WTF_COMPILER_MSVC 1
48 #endif
50 /* COMPILER(GCC) - GNU Compiler Collection */
51 #if defined(__GNUC__)
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))
55 #else
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
58 #endif
60 /* ==== Compiler features ==== */
63 /* ALWAYS_INLINE */
65 #ifndef ALWAYS_INLINE
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
70 #else
71 #define ALWAYS_INLINE inline
72 #endif
73 #endif
76 /* NEVER_INLINE */
78 #ifndef NEVER_INLINE
79 #if COMPILER(GCC)
80 #define NEVER_INLINE __attribute__((__noinline__))
81 #elif COMPILER(MSVC)
82 #define NEVER_INLINE __declspec(noinline)
83 #else
84 #define NEVER_INLINE
85 #endif
86 #endif
89 /* UNLIKELY */
91 #ifndef UNLIKELY
92 #if COMPILER(GCC)
93 #define UNLIKELY(x) __builtin_expect((x), 0)
94 #else
95 #define UNLIKELY(x) (x)
96 #endif
97 #endif
100 /* LIKELY */
102 #ifndef LIKELY
103 #if COMPILER(GCC)
104 #define LIKELY(x) __builtin_expect((x), 1)
105 #else
106 #define LIKELY(x) (x)
107 #endif
108 #endif
111 /* NO_RETURN */
113 #ifndef NO_RETURN
114 #if COMPILER(GCC)
115 #define NO_RETURN __attribute((__noreturn__))
116 #elif COMPILER(MSVC)
117 #define NO_RETURN __declspec(noreturn)
118 #else
119 #define NO_RETURN
120 #endif
121 #endif
124 /* WARN_UNUSED_RETURN */
126 #if COMPILER(GCC)
127 #define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result))
128 #else
129 #define WARN_UNUSED_RETURN
130 #endif
133 /* ALLOW_UNUSED_LOCAL */
135 #define ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0
138 /* OBJC_CLASS */
140 #ifndef OBJC_CLASS
141 #ifdef __OBJC__
142 #define OBJC_CLASS @class
143 #else
144 #define OBJC_CLASS class
145 #endif
146 #endif
149 /* WTF_PRETTY_FUNCTION */
151 #if COMPILER(GCC)
152 #define WTF_COMPILER_SUPPORTS_PRETTY_FUNCTION 1
153 #define WTF_PRETTY_FUNCTION __PRETTY_FUNCTION__
154 #elif COMPILER(MSVC)
155 #define WTF_COMPILER_SUPPORTS_PRETTY_FUNCTION 1
156 #define WTF_PRETTY_FUNCTION __FUNCSIG__
157 #else
158 #define WTF_PRETTY_FUNCTION __FUNCTION__
159 #endif
162 /* NO_SANITIZE_UNRELATED_CAST - Disable runtime checks related to casts between
163 * unrelated objects (-fsanitize=cfi-unrelated-cast or -fsanitize=vptr). */
165 #if COMPILER(CLANG)
166 #define NO_SANITIZE_UNRELATED_CAST __attribute__((no_sanitize("cfi-unrelated-cast", "vptr")))
167 #else
168 #define NO_SANITIZE_UNRELATED_CAST
169 #endif
171 #endif /* WTF_Compiler_h */