[libcxx] r291286 - Add _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM] macros.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 6 13:42:58 PST 2017


Author: ericwf
Date: Fri Jan  6 15:42:58 2017
New Revision: 291286

URL: http://llvm.org/viewvc/llvm-project?rev=291286&view=rev
Log:
Add _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM] macros.

This patch refactors the compiler detection done in `__config` by creating a
set of `_LIBCPP_COMPILER_<TYPE>` macros. The goal of this patch is to make
it easier to detect what compiler is being used outside of `__config`.

Additionally this patch removes workarounds for GCC in `__bit_reference`. I
tested GCC 4.8 and 4.9 without the workaround and neither seemed to need it
anymore.

Modified:
    libcxx/trunk/include/__bit_reference
    libcxx/trunk/include/__config
    libcxx/trunk/include/support/win32/support.h
    libcxx/trunk/include/type_traits
    libcxx/trunk/src/locale.cpp

Modified: libcxx/trunk/include/__bit_reference
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__bit_reference?rev=291286&r1=291285&r2=291286&view=diff
==============================================================================
--- libcxx/trunk/include/__bit_reference (original)
+++ libcxx/trunk/include/__bit_reference Fri Jan  6 15:42:58 2017
@@ -40,11 +40,8 @@ class __bit_reference
     __storage_pointer __seg_;
     __storage_type    __mask_;
 
-#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC)
     friend typename _Cp::__self;
-#else
-    friend class _Cp::__self;
-#endif
+
     friend class __bit_const_reference<_Cp>;
     friend class __bit_iterator<_Cp, false>;
 public:
@@ -130,11 +127,7 @@ class __bit_const_reference
     __storage_pointer        __seg_;
     __storage_type __mask_;
 
-#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC)
     friend typename _Cp::__self;
-#else
-    friend class _Cp::__self;
-#endif
     friend class __bit_iterator<_Cp, true>;
 public:
     _LIBCPP_INLINE_VISIBILITY
@@ -1221,11 +1214,8 @@ private:
     __bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
         : __seg_(__s), __ctz_(__ctz) {}
 
-#if defined(__clang__) || defined(__IBMCPP__) || defined(_LIBCPP_MSVC)
     friend typename _Cp::__self;
-#else
-    friend class _Cp::__self;
-#endif
+
     friend class __bit_reference<_Cp>;
     friend class __bit_const_reference<_Cp>;
     friend class __bit_iterator<_Cp, true>;

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=291286&r1=291285&r2=291286&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Jan  6 15:42:58 2017
@@ -101,6 +101,16 @@
 #define __is_identifier(__x) 1
 #endif
 
+#if defined(__clang__)
+#define _LIBCPP_COMPILER_CLANG
+#elif defined(__GNUC__)
+#define _LIBCPP_COMPILER_GCC
+#elif defined(_MSC_VER)
+#define _LIBCPP_COMPILER_MSVC
+#elif defined(__IBMCPP__)
+#define _LIBCPP_COMPILER_IBM
+#endif
+
 // Need to detect which libc we're using if we're on Linux.
 #if defined(__linux__)
 #include <features.h>
@@ -164,16 +174,7 @@
 #  define _LIBCPP_LITTLE_ENDIAN 1
 #  define _LIBCPP_BIG_ENDIAN    0
 #  define _LIBCPP_SHORT_WCHAR   1
-// Compiler intrinsics (MSVC)
-#  if defined(_MSC_VER) && _MSC_VER >= 1400
-#    define _LIBCPP_HAS_IS_BASE_OF
-#  endif
-#  if defined(_MSC_VER) && !defined(__clang__)
-#    define _LIBCPP_MSVC // Using Microsoft Visual C++ compiler
-#    define _LIBCPP_TOSTRING2(x) #x
-#    define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
-#    define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
-#  endif
+
 // If mingw not explicitly detected, assume using MS C runtime only.
 #  ifndef __MINGW32__
 #    define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
@@ -230,7 +231,7 @@
 #define _LIBCPP_NO_CFI
 #endif
 
-#if defined(__clang__)
+#if defined(_LIBCPP_COMPILER_CLANG)
 
 // _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for
 // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility.
@@ -386,7 +387,7 @@ namespace std {
 #define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
 #endif 
 
-#elif defined(__GNUC__)
+#elif defined(_LIBCPP_COMPILER_GCC)
 
 #define _ALIGNAS(x) __attribute__((__aligned__(x)))
 #define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
@@ -469,8 +470,17 @@ using namespace _LIBCPP_NAMESPACE __attr
 #define _LIBCPP_HAS_NO_ASAN
 #endif
 
-#elif defined(_LIBCPP_MSVC)
+#elif defined(_LIBCPP_COMPILER_MSVC)
 
+#define _LIBCPP_TOSTRING2(x) #x
+#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
+#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
+
+#if _MSC_VER < 1900
+#error "MSVC versions prior to Visual Studio 2015 are not supported"
+#endif
+
+#define _LIBCPP_HAS_IS_BASE_OF
 #define _LIBCPP_HAS_NO_CONSTEXPR
 #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
@@ -493,7 +503,7 @@ namespace std {
 
 #define _LIBCPP_HAS_NO_ASAN
 
-#elif defined(__IBMCPP__)
+#elif defined(_LIBCPP_COMPILER_IBM)
 
 #define _ALIGNAS(x) __attribute__((__aligned__(x)))
 #define _ALIGNAS_TYPE(x) __attribute__((__aligned__(__alignof(x))))
@@ -523,7 +533,7 @@ namespace std {
 
 #define _LIBCPP_HAS_NO_ASAN
 
-#endif // __clang__ || __GNUC__ || _MSC_VER || __IBMCPP__
+#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
 
 #if defined(__ELF__)
 #define _LIBCPP_OBJECT_FORMAT_ELF   1
@@ -559,7 +569,7 @@ namespace std {
 #define _LIBCPP_FUNC_VIS_ONLY
 #define _LIBCPP_ENUM_VIS
 
-#if defined(_LIBCPP_MSVC)
+#if defined(_LIBCPP_COMPILER_MSVC)
 # define _LIBCPP_INLINE_VISIBILITY __forceinline
 # define _LIBCPP_ALWAYS_INLINE     __forceinline
 # define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY __forceinline

Modified: libcxx/trunk/include/support/win32/support.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/support.h?rev=291286&r1=291285&r2=291286&view=diff
==============================================================================
--- libcxx/trunk/include/support/win32/support.h (original)
+++ libcxx/trunk/include/support/win32/support.h Fri Jan  6 15:42:58 2017
@@ -18,7 +18,7 @@
 #include <cstdarg> // va_ macros
 // "builtins" not implemented here for Clang or GCC as they provide
 // implementations. Assuming required for elsewhere else, certainly MSVC.
-#if defined(_LIBCPP_MSVC)
+#if defined(_LIBCPP_COMPILER_MSVC)
 #include <intrin.h>
 #endif
 #if defined(_LIBCPP_MSVCRT)
@@ -49,7 +49,7 @@ size_t wcsnrtombs(char *__restrict dst,
 #define _Exit _exit
 #endif
 
-#if defined(_LIBCPP_MSVC)
+#if defined(_LIBCPP_COMPILER_MSVC)
 
 // Bit builtin's make these assumptions when calling _BitScanForward/Reverse
 // etc. These assumptions are expected to be true for Win32/Win64 which this

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=291286&r1=291285&r2=291286&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Fri Jan  6 15:42:58 2017
@@ -1503,7 +1503,7 @@ template <class _Tp> _LIBCPP_CONSTEXPR b
 
 // is_polymorphic
 
-#if __has_feature(is_polymorphic) || defined(_LIBCPP_MSVC)
+#if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC)
 
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_polymorphic

Modified: libcxx/trunk/src/locale.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=291286&r1=291285&r2=291286&view=diff
==============================================================================
--- libcxx/trunk/src/locale.cpp (original)
+++ libcxx/trunk/src/locale.cpp Fri Jan  6 15:42:58 2017
@@ -140,7 +140,7 @@ class _LIBCPP_HIDDEN locale::__imp
     : public facet
 {
     enum {N = 28};
-#if defined(_LIBCPP_MSVC)
+#if defined(_LIBCPP_COMPILER_MSVC)
 // FIXME: MSVC doesn't support aligned parameters by value.
 // I can't get the __sso_allocator to work here
 // for MSVC I think for this reason.




More information about the cfe-commits mailing list