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
44
#ifndef __has_extension
45
#define __has_extension __has_feature /* Compatibility with older versions of clang */
48
#define CLANG_PRAGMA(PRAGMA) _Pragma(PRAGMA)
50
/* Specific compiler features */
51
#define WTF_COMPILER_SUPPORTS_CXX_VARIADIC_TEMPLATES __has_extension(cxx_variadic_templates)
53
/* There is a bug in clang that comes with Xcode 4.2 where AtomicStrings can't be implicitly converted to Strings
54
in the presence of move constructors and/or move assignment operators. This bug has been fixed in Xcode 4.3 clang, so we
55
check for both cxx_rvalue_references as well as the unrelated cxx_nonstatic_member_init feature which we know was added in 4.3 */
56
#define WTF_COMPILER_SUPPORTS_CXX_RVALUE_REFERENCES __has_extension(cxx_rvalue_references) && __has_extension(cxx_nonstatic_member_init)
58
#define WTF_COMPILER_SUPPORTS_CXX_DELETED_FUNCTIONS __has_extension(cxx_deleted_functions)
59
#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR __has_feature(cxx_nullptr)
60
#define WTF_COMPILER_SUPPORTS_CXX_EXPLICIT_CONVERSIONS __has_feature(cxx_explicit_conversions)
61
#define WTF_COMPILER_SUPPORTS_BLOCKS __has_feature(blocks)
62
#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT __has_extension(c_static_assert)
63
#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL __has_extension(cxx_override_control)
64
#define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
69
#define CLANG_PRAGMA(PRAGMA)
72
/* COMPILER(MSVC) - Microsoft Visual C++ */
73
/* COMPILER(MSVC7_OR_LOWER) - Microsoft Visual C++ 2003 or lower*/
74
/* COMPILER(MSVC9_OR_LOWER) - Microsoft Visual C++ 2008 or lower*/
76
#define WTF_COMPILER_MSVC 1
78
#define WTF_COMPILER_MSVC7_OR_LOWER 1
80
#define WTF_COMPILER_MSVC9_OR_LOWER 1
83
/* Specific compiler features */
84
#if !COMPILER(CLANG) && _MSC_VER >= 1600
85
#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1
89
#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL 1
90
#define WTF_COMPILER_QUIRK_FINAL_IS_CALLED_SEALED 1
95
/* COMPILER(RVCT) - ARM RealView Compilation Tools */
96
/* COMPILER(RVCT4_OR_GREATER) - ARM RealView Compilation Tools 4.0 or greater */
97
#if defined(__CC_ARM) || defined(__ARMCC__)
98
#define WTF_COMPILER_RVCT 1
99
#define RVCT_VERSION_AT_LEAST(major, minor, patch, build) (__ARMCC_VERSION >= (major * 100000 + minor * 10000 + patch * 1000 + build))
101
/* Define this for !RVCT compilers, just so we can write things like RVCT_VERSION_AT_LEAST(3, 0, 0, 0). */
102
#define RVCT_VERSION_AT_LEAST(major, minor, patch, build) 0
105
/* COMPILER(GCCE) - GNU Compiler Collection for Embedded */
106
#if defined(__GCCE__)
107
#define WTF_COMPILER_GCCE 1
108
#define GCCE_VERSION (__GCCE__ * 10000 + __GCCE_MINOR__ * 100 + __GCCE_PATCHLEVEL__)
109
#define GCCE_VERSION_AT_LEAST(major, minor, patch) (GCCE_VERSION >= (major * 10000 + minor * 100 + patch))
112
/* COMPILER(GCC) - GNU Compiler Collection */
113
/* --gnu option of the RVCT compiler also defines __GNUC__ */
114
#if defined(__GNUC__) && !COMPILER(RVCT)
115
#define WTF_COMPILER_GCC 1
116
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
117
#define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
119
/* Define this for !GCC compilers, just so we can write things like GCC_VERSION_AT_LEAST(4, 1, 0). */
120
#define GCC_VERSION_AT_LEAST(major, minor, patch) 0
123
/* Specific compiler features */
124
#if COMPILER(GCC) && !COMPILER(CLANG)
125
#if GCC_VERSION_AT_LEAST(4, 7, 0) && defined(__cplusplus) && __cplusplus >= 201103L
126
#define WTF_COMPILER_SUPPORTS_CXX_RVALUE_REFERENCES 1
127
#define WTF_COMPILER_SUPPORTS_CXX_DELETED_FUNCTIONS 1
128
#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1
129
#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL 1
130
#define WTF_COMPILER_QUIRK_GCC11_GLOBAL_ISINF_ISNAN 1
132
#elif GCC_VERSION_AT_LEAST(4, 6, 0) && defined(__GXX_EXPERIMENTAL_CXX0X__)
133
#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1
134
#define WTF_COMPILER_QUIRK_GCC11_GLOBAL_ISINF_ISNAN 1
139
/* COMPILER(MINGW) - MinGW GCC */
140
/* COMPILER(MINGW64) - mingw-w64 GCC - only used as additional check to exclude mingw.org specific functions */
141
#if defined(__MINGW32__)
142
#define WTF_COMPILER_MINGW 1
143
#include <_mingw.h> /* private MinGW header */
144
#if defined(__MINGW64_VERSION_MAJOR) /* best way to check for mingw-w64 vs mingw.org */
145
#define WTF_COMPILER_MINGW64 1
146
#endif /* __MINGW64_VERSION_MAJOR */
147
#endif /* __MINGW32__ */
149
/* COMPILER(INTEL) - Intel C++ Compiler */
150
#if defined(__INTEL_COMPILER)
151
#define WTF_COMPILER_INTEL 1
154
/* COMPILER(SUNCC) */
155
#if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
156
#define WTF_COMPILER_SUNCC 1
159
/* ==== Compiler features ==== */
164
#ifndef ALWAYS_INLINE
165
#if COMPILER(GCC) && defined(NDEBUG) && !COMPILER(MINGW)
166
#define ALWAYS_INLINE inline __attribute__((__always_inline__))
167
#elif (COMPILER(MSVC) || COMPILER(RVCT)) && defined(NDEBUG)
168
#define ALWAYS_INLINE __forceinline
170
#define ALWAYS_INLINE inline
179
#define NEVER_INLINE __attribute__((__noinline__))
181
#define NEVER_INLINE __declspec(noinline)
191
#if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
192
#define UNLIKELY(x) __builtin_expect((x), 0)
194
#define UNLIKELY(x) (x)
202
#if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
203
#define LIKELY(x) __builtin_expect((x), 1)
205
#define LIKELY(x) (x)
215
#define NO_RETURN __attribute((__noreturn__))
216
#elif COMPILER(MSVC) || COMPILER(RVCT)
217
#define NO_RETURN __declspec(noreturn)
224
/* NO_RETURN_WITH_VALUE */
226
#ifndef NO_RETURN_WITH_VALUE
228
#define NO_RETURN_WITH_VALUE NO_RETURN
230
#define NO_RETURN_WITH_VALUE
235
/* WARN_UNUSED_RETURN */
238
#define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result))
240
#define WARN_UNUSED_RETURN
243
/* OVERRIDE and FINAL */
245
#if COMPILER_SUPPORTS(CXX_OVERRIDE_CONTROL)
246
#define OVERRIDE override
248
#if COMPILER_QUIRK(FINAL_IS_CALLED_SEALED)
259
/* REFERENCED_FROM_ASM */
261
#ifndef REFERENCED_FROM_ASM
263
#define REFERENCED_FROM_ASM __attribute__((used))
265
#define REFERENCED_FROM_ASM
273
#define OBJC_CLASS @class
275
#define OBJC_CLASS class
280
#if defined(__ARM_EABI__) || defined(__EABI__)
281
#define WTF_COMPILER_SUPPORTS_EABI 1
284
#endif /* WTF_Compiler_h */