summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/Compiler.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WTF/wtf/Compiler.h')
-rw-r--r--Source/WTF/wtf/Compiler.h149
1 files changed, 103 insertions, 46 deletions
diff --git a/Source/WTF/wtf/Compiler.h b/Source/WTF/wtf/Compiler.h
index 2e2cfba4b..aa41805b2 100644
--- a/Source/WTF/wtf/Compiler.h
+++ b/Source/WTF/wtf/Compiler.h
@@ -35,56 +35,71 @@
/* COMPILER_QUIRK() - whether the compiler being used to build the project requires a given quirk. */
#define COMPILER_QUIRK(WTF_COMPILER_QUIRK) (defined WTF_COMPILER_QUIRK_##WTF_COMPILER_QUIRK && WTF_COMPILER_QUIRK_##WTF_COMPILER_QUIRK)
+/* COMPILER_HAS_CLANG_BUILTIN() - whether the compiler supports a particular clang builtin. */
+#ifdef __has_builtin
+#define COMPILER_HAS_CLANG_BUILTIN(x) __has_builtin(x)
+#else
+#define COMPILER_HAS_CLANG_BUILTIN(x) 0
+#endif
+
+/* COMPILER_HAS_CLANG_HEATURE() - whether the compiler supports a particular language or library feature. */
+/* http://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension */
+#ifdef __has_feature
+#define COMPILER_HAS_CLANG_FEATURE(x) __has_feature(x)
+#else
+#define COMPILER_HAS_CLANG_FEATURE(x) 0
+#endif
+
/* ==== COMPILER() - primary detection of the compiler being used to build the project, in alphabetical order ==== */
/* COMPILER(CLANG) - Clang */
#if defined(__clang__)
#define WTF_COMPILER_CLANG 1
-#define WTF_COMPILER_SUPPORTS_BLOCKS __has_feature(blocks)
-#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT __has_feature(c_static_assert)
-#define WTF_COMPILER_SUPPORTS_CXX_CONSTEXPR __has_feature(cxx_constexpr)
-#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS __has_feature(cxx_reference_qualified_functions)
-#define WTF_COMPILER_SUPPORTS_CXX_USER_LITERALS __has_feature(cxx_user_literals)
-#define WTF_COMPILER_SUPPORTS_FALLTHROUGH_WARNINGS __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
-#endif
+#define WTF_COMPILER_SUPPORTS_BLOCKS COMPILER_HAS_CLANG_FEATURE(blocks)
+#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT COMPILER_HAS_CLANG_FEATURE(c_static_assert)
+#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS COMPILER_HAS_CLANG_FEATURE(cxx_reference_qualified_functions)
+#define WTF_COMPILER_SUPPORTS_CXX_USER_LITERALS COMPILER_HAS_CLANG_FEATURE(cxx_user_literals)
+#define WTF_COMPILER_SUPPORTS_FALLTHROUGH_WARNINGS COMPILER_HAS_CLANG_FEATURE(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
+#define WTF_COMPILER_SUPPORTS_CXX_EXCEPTIONS COMPILER_HAS_CLANG_FEATURE(cxx_exceptions)
+#define WTF_COMPILER_SUPPORTS_BUILTIN_IS_TRIVIALLY_COPYABLE COMPILER_HAS_CLANG_FEATURE(is_trivially_copyable)
-/* COMPILER(GCC) - GNU Compiler Collection */
+#ifdef __cplusplus
+#if __cplusplus <= 201103L
+#define WTF_CPP_STD_VER 11
+#elif __cplusplus <= 201402L
+#define WTF_CPP_STD_VER 14
+#endif
+#endif
-/* Note: This section must come after the Clang section since we check !COMPILER(CLANG) here. */
+#endif // defined(__clang__)
+/* COMPILER(GCC_OR_CLANG) - GNU Compiler Collection or Clang */
#if defined(__GNUC__)
-#define WTF_COMPILER_GCC 1
-#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
-#define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
+#define WTF_COMPILER_GCC_OR_CLANG 1
#endif
-/* Define GCC_VERSION_AT_LEAST for all compilers, so we can write things like GCC_VERSION_AT_LEAST(4, 1, 0). */
-/* FIXME: Doesn't seem all that valuable. Can we remove this? */
-#if !defined(GCC_VERSION_AT_LEAST)
-#define GCC_VERSION_AT_LEAST(major, minor, patch) 0
-#endif
+/* COMPILER(GCC) - GNU Compiler Collection */
+/* Note: This section must come after the Clang section since we check !COMPILER(CLANG) here. */
+#if COMPILER(GCC_OR_CLANG) && !COMPILER(CLANG)
+#define WTF_COMPILER_GCC 1
+#define WTF_COMPILER_SUPPORTS_CXX_USER_LITERALS 1
+#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS 1
-#if COMPILER(GCC) && !COMPILER(CLANG) && !GCC_VERSION_AT_LEAST(4, 7, 0)
-#error "Please use a newer version of GCC. WebKit requires GCC 4.7.0 or newer to compile."
-#endif
+#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+#define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
-#if COMPILER(GCC) && !COMPILER(CLANG)
-#define WTF_COMPILER_SUPPORTS_CXX_CONSTEXPR 1
-#define WTF_COMPILER_SUPPORTS_CXX_USER_LITERALS 1
+#if !GCC_VERSION_AT_LEAST(4, 9, 0)
+#error "Please use a newer version of GCC. WebKit requires GCC 4.9.0 or newer to compile."
#endif
-#if COMPILER(GCC) && !COMPILER(CLANG) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT 1
#endif
-#if COMPILER(GCC) && !COMPILER(CLANG) && GCC_VERSION_AT_LEAST(4, 8, 0)
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
-#endif
-#if COMPILER(GCC) && !COMPILER(CLANG) && (defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(__cplusplus) && __cplusplus >= 201103L))
-#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
-#endif
+#endif /* COMPILER(GCC) */
/* COMPILER(MINGW) - MinGW GCC */
@@ -104,11 +119,14 @@
/* COMPILER(MSVC) - Microsoft Visual C++ */
#if defined(_MSC_VER)
+
#define WTF_COMPILER_MSVC 1
+#define WTF_COMPILER_SUPPORTS_CXX_REFERENCE_QUALIFIED_FUNCTIONS 1
+
+#if _MSC_VER < 1900
+#error "Please use a newer version of Visual Studio. WebKit requires VS2015 or newer to compile."
#endif
-#if defined(_MSC_VER) && _MSC_VER < 1800
-#error "Please use a newer version of Visual Studio. WebKit requires VS2013 or newer to compile."
#endif
/* COMPILER(SUNCC) */
@@ -117,6 +135,10 @@
#define WTF_COMPILER_SUNCC 1
#endif
+#if !COMPILER(CLANG) && !COMPILER(MSVC)
+#define WTF_COMPILER_QUIRK_CONSIDERS_UNREACHABLE_CODE 1
+#endif
+
/* ==== COMPILER_SUPPORTS - additional compiler feature detection, in alphabetical order ==== */
/* COMPILER_SUPPORTS(EABI) */
@@ -125,11 +147,33 @@
#define WTF_COMPILER_SUPPORTS_EABI 1
#endif
+/* RELAXED_CONSTEXPR */
+
+#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
+#define WTF_COMPILER_SUPPORTS_RELAXED_CONSTEXPR 1
+#endif
+
+#if !defined(RELAXED_CONSTEXPR)
+#if COMPILER_SUPPORTS(RELAXED_CONSTEXPR)
+#define RELAXED_CONSTEXPR constexpr
+#else
+#define RELAXED_CONSTEXPR
+#endif
+#endif
+
+#define ASAN_ENABLED COMPILER_HAS_CLANG_FEATURE(address_sanitizer)
+
+#if ASAN_ENABLED
+#define SUPPRESS_ASAN __attribute__((no_sanitize_address))
+#else
+#define SUPPRESS_ASAN
+#endif
+
/* ==== Compiler-independent macros for various compiler features, in alphabetical order ==== */
/* ALWAYS_INLINE */
-#if !defined(ALWAYS_INLINE) && COMPILER(GCC) && defined(NDEBUG) && !COMPILER(MINGW)
+#if !defined(ALWAYS_INLINE) && COMPILER(GCC_OR_CLANG) && defined(NDEBUG) && !COMPILER(MINGW)
#define ALWAYS_INLINE inline __attribute__((__always_inline__))
#endif
@@ -141,14 +185,14 @@
#define ALWAYS_INLINE inline
#endif
-/* CONSTEXPR */
+/* WTF_EXTERN_C_{BEGIN, END} */
-#if !defined(CONSTEXPR) && COMPILER_SUPPORTS(CXX_CONSTEXPR)
-#define CONSTEXPR constexpr
-#endif
-
-#if !defined(CONSTEXPR)
-#define CONSTEXPR
+#ifdef __cplusplus
+#define WTF_EXTERN_C_BEGIN extern "C" {
+#define WTF_EXTERN_C_END }
+#else
+#define WTF_EXTERN_C_BEGIN
+#define WTF_EXTERN_C_END
#endif
/* FALLTHROUGH */
@@ -163,7 +207,7 @@
/* LIKELY */
-#if !defined(LIKELY) && COMPILER(GCC)
+#if !defined(LIKELY) && COMPILER(GCC_OR_CLANG)
#define LIKELY(x) __builtin_expect(!!(x), 1)
#endif
@@ -173,7 +217,7 @@
/* NEVER_INLINE */
-#if !defined(NEVER_INLINE) && COMPILER(GCC)
+#if !defined(NEVER_INLINE) && COMPILER(GCC_OR_CLANG)
#define NEVER_INLINE __attribute__((__noinline__))
#endif
@@ -187,7 +231,7 @@
/* NO_RETURN */
-#if !defined(NO_RETURN) && COMPILER(GCC)
+#if !defined(NO_RETURN) && COMPILER(GCC_OR_CLANG)
#define NO_RETURN __attribute((__noreturn__))
#endif
@@ -199,6 +243,15 @@
#define NO_RETURN
#endif
+/* RETURNS_NONNULL */
+#if !defined(RETURNS_NONNULL) && COMPILER(GCC_OR_CLANG)
+#define RETURNS_NONNULL __attribute__((returns_nonnull))
+#endif
+
+#if !defined(RETURNS_NONNULL)
+#define RETURNS_NONNULL
+#endif
+
/* NO_RETURN_WITH_VALUE */
#if !defined(NO_RETURN_WITH_VALUE) && !COMPILER(MSVC)
@@ -221,7 +274,7 @@
/* PURE_FUNCTION */
-#if !defined(PURE_FUNCTION) && COMPILER(GCC)
+#if !defined(PURE_FUNCTION) && COMPILER(GCC_OR_CLANG)
#define PURE_FUNCTION __attribute__((__pure__))
#endif
@@ -231,7 +284,7 @@
/* REFERENCED_FROM_ASM */
-#if !defined(REFERENCED_FROM_ASM) && COMPILER(GCC)
+#if !defined(REFERENCED_FROM_ASM) && COMPILER(GCC_OR_CLANG)
#define REFERENCED_FROM_ASM __attribute__((__used__))
#endif
@@ -241,7 +294,7 @@
/* UNLIKELY */
-#if !defined(UNLIKELY) && COMPILER(GCC)
+#if !defined(UNLIKELY) && COMPILER(GCC_OR_CLANG)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#endif
@@ -274,7 +327,7 @@
/* WARN_UNUSED_RETURN */
-#if !defined(WARN_UNUSED_RETURN) && COMPILER(GCC)
+#if !defined(WARN_UNUSED_RETURN) && COMPILER(GCC_OR_CLANG)
#define WARN_UNUSED_RETURN __attribute__((__warn_unused_result__))
#endif
@@ -282,4 +335,8 @@
#define WARN_UNUSED_RETURN
#endif
+#if !defined(__has_include) && COMPILER(MSVC)
+#define __has_include(path) 0
+#endif
+
#endif /* WTF_Compiler_h */