From 0f076223d1b36690323e8410f4a82a7716b84875 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Fri, 24 Apr 2020 13:07:26 -0600 Subject: [PATCH] Fix MSVC-Clang Builds introduce better compiler id macros --- include/experimental/__p0009_bits/config.hpp | 46 ++++++++++++++++--- .../__p0009_bits/layout_stride.hpp | 2 +- include/experimental/__p0009_bits/macros.hpp | 32 +++++++------ .../__p0009_bits/no_unique_address.hpp | 2 +- .../standard_layout_static_array.hpp | 4 +- .../__p0009_bits/trait_backports.hpp | 2 +- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/include/experimental/__p0009_bits/config.hpp b/include/experimental/__p0009_bits/config.hpp index 2eb9ba4d..d81d47c1 100644 --- a/include/experimental/__p0009_bits/config.hpp +++ b/include/experimental/__p0009_bits/config.hpp @@ -69,8 +69,38 @@ static_assert(_MDSPAN_CPLUSPLUS >= 201102L, "MDSpan requires C++11 or later."); #define MDSPAN_HAS_CXX_14 (_MDSPAN_CPLUSPLUS >= MDSPAN_CXX_STD_14) #define MDSPAN_HAS_CXX_17 (_MDSPAN_CPLUSPLUS >= MDSPAN_CXX_STD_17) -#ifdef __apple_build_version__ -# define _MDSPAN_COMPILER_APPLECLANG +#ifndef _MDSPAN_COMPILER_CLANG +# if defined(__clang__) +# define _MDSPAN_COMPILER_CLANG __clang__ +# endif +#endif + +#if !defined(_MDSPAN_COMPILER_MSVC) && !defined(_MDSPAN_COMPILER_MSVC_CLANG) +# if defined(_MSC_VER) +# if !defined(_MDSPAN_COMPILER_CLANG) +# define _MDSPAN_COMPILER_MSVC _MSC_VER +# else +# define _MDSPAN_COMPILER_MSVC_CLANG _MSC_VER +# endif +# endif +#endif + +#ifndef _MDSPAN_COMPILER_INTEL +# ifdef __INTEL_COMPILER +# define _MDSPAN_COMPILER_INTEL __INTEL_COMPILER +# endif +#endif + +#ifndef _MDSPAN_COMPILER_APPLECLANG +# ifdef __apple_build_version__ +# define _MDSPAN_COMPILER_APPLECLANG __apple_build_version__ +# endif +#endif + +#ifndef _MDSPAN_HAS_CUDA +# if defined(__CUDACC__) +# define _MDSPAN_HAS_CUDA __CUDACC__ +# endif #endif #ifndef __has_cpp_attribute @@ -135,7 +165,7 @@ static_assert(_MDSPAN_CPLUSPLUS >= 201102L, "MDSpan requires C++11 or later."); #endif #ifndef _MDSPAN_USE_INTEGER_SEQUENCE -# ifdef _MSC_VER +# if defined(_MDSPAN_COMPILER_MSVC) # if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) # define _MDSPAN_USE_INTEGER_SEQUENCE 1 # endif @@ -148,7 +178,7 @@ static_assert(_MDSPAN_CPLUSPLUS >= 201102L, "MDSpan requires C++11 or later."); || (defined(__GLIBCXX__) && __GLIBCXX__ > 20150422 && __GNUC__ < 5 && !defined(__INTEL_CXX11_MODE__)) // several compilers lie about integer_sequence working properly unless the C++14 standard is used # define _MDSPAN_USE_INTEGER_SEQUENCE 1 -# elif defined(_MDSPAN_COMPILER_APPLECLANG) && MDSPAN_HAS_CXX_14 +# elif defined(_MDSPAN_COMPILER_APPLE_CLANG) && MDSPAN_HAS_CXX_14 // appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 making // integer_sequence work # define _MDSPAN_USE_INTEGER_SEQUENCE 1 @@ -156,7 +186,7 @@ static_assert(_MDSPAN_CPLUSPLUS >= 201102L, "MDSpan requires C++11 or later."); #endif #ifndef _MDSPAN_USE_RETURN_TYPE_DEDUCTION -# ifdef _MSC_VER +# ifdef _MDSPAN_COMPILER_MSVC # if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) && MDSPAN_HAS_CXX_14 # define _MDSPAN_USE_RETURN_TYPE_DEDUCTION 1 # endif @@ -180,8 +210,10 @@ static_assert(_MDSPAN_CPLUSPLUS >= 201102L, "MDSpan requires C++11 or later."); #endif #ifndef _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND -# if __GNUC__ < 9 -# define _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND 1 +# ifdef __GNUC__ +# if __GNUC__ < 9 +# define _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND 1 +# endif # endif #endif diff --git a/include/experimental/__p0009_bits/layout_stride.hpp b/include/experimental/__p0009_bits/layout_stride.hpp index c7ee36ce..0d254a43 100644 --- a/include/experimental/__p0009_bits/layout_stride.hpp +++ b/include/experimental/__p0009_bits/layout_stride.hpp @@ -202,7 +202,7 @@ class layout_stride_impl< // TODO @proposal-bug @proposal-extension layout stride needs this constructor // clang-format off -#if defined(__INTEL_COMPILER) +#if defined(_MDSPAN_COMPILER_INTEL) // Work-around for an ICE. layout_stride won't properly SFINAE with ICC, but oh well MDSPAN_FUNCTION_REQUIRES( (MDSPAN_INLINE_FUNCTION constexpr explicit), diff --git a/include/experimental/__p0009_bits/macros.hpp b/include/experimental/__p0009_bits/macros.hpp index 2b8b9a20..470d9b8f 100644 --- a/include/experimental/__p0009_bits/macros.hpp +++ b/include/experimental/__p0009_bits/macros.hpp @@ -48,31 +48,35 @@ #include // std::is_void -#ifndef MDSPAN_FORCE_INLINE_FUNCTION -# ifdef _MSC_VER // Microsoft compilers -# define MDSPAN_FORCE_INLINE_FUNCTION __forceinline -# elif defined(__CUDA_ARCH__) -# define MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) __host__ __device__ +#ifndef _MDSPAN_HOST_DEVICE +# if defined(_MDSPAN_HAS_CUDA) || defined(_MDSPAN_HAS_HIP) +# define _MDSPAN_HOST_DEVICE __host__ __device__ # else -# define MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) +# define _MDSPAN_HOST_DEVICE # endif #endif -#ifndef MDSPAN_INLINE_FUNCTION -# if defined(__CUDA_ARCH__) -# define MDSPAN_INLINE_FUNCTION inline __host__ __device__ + +#ifndef MDSPAN_FORCE_INLINE_FUNCTION +# ifdef _MDSPAN_COMPILER_MSVC // Microsoft compilers +# define MDSPAN_FORCE_INLINE_FUNCTION __forceinline _MDSPAN_HOST_DEVICE # else -# define MDSPAN_INLINE_FUNCTION inline +# define MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) _MDSPAN_HOST_DEVICE # endif #endif + +#ifndef MDSPAN_INLINE_FUNCTION +# define MDSPAN_INLINE_FUNCTION inline _MDSPAN_HOST_DEVICE +#endif + +// In CUDA defaulted functions do not need host device markup #ifndef MDSPAN_INLINE_FUNCTION_DEFAULTED -# define MDSPAN_INLINE_FUNCTION_DEFAULTED inline +# define MDSPAN_INLINE_FUNCTION_DEFAULTED #endif //============================================================================== // {{{1 - -#ifdef _MSC_VER // Microsoft compilers +#if defined(_MDSPAN_COMPILER_MSVC) // Microsoft compilers #define MDSPAN_PP_COUNT(...) \ _MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE( \ @@ -161,7 +165,7 @@ #endif -#ifdef _MSC_VER +#if defined(_MDSPAN_COMPILER_MSVC) # define MDSPAN_TEMPLATE_REQUIRES(...) \ MDSPAN_PP_CAT( \ MDSPAN_PP_CAT(MDSPAN_TEMPLATE_REQUIRES_, MDSPAN_PP_COUNT(__VA_ARGS__))\ diff --git a/include/experimental/__p0009_bits/no_unique_address.hpp b/include/experimental/__p0009_bits/no_unique_address.hpp index 5ebbecc6..d2834ee1 100644 --- a/include/experimental/__p0009_bits/no_unique_address.hpp +++ b/include/experimental/__p0009_bits/no_unique_address.hpp @@ -76,7 +76,7 @@ struct __no_unique_address_emulation< // won't be called at the right time, so don't use this // specialization _MDSPAN_TRAIT(is_trivially_destructible, _T)>> : -#ifdef _MSC_VER +#ifdef _MDSPAN_COMPILER_MSVC // MSVC doesn't allow you to access public static member functions of a type // when you *happen* to privately inherit from that type. protected diff --git a/include/experimental/__p0009_bits/standard_layout_static_array.hpp b/include/experimental/__p0009_bits/standard_layout_static_array.hpp index 7ca950d0..2404c4f8 100644 --- a/include/experimental/__p0009_bits/standard_layout_static_array.hpp +++ b/include/experimental/__p0009_bits/standard_layout_static_array.hpp @@ -108,7 +108,7 @@ struct __standard_layout_psa< } static constexpr auto __size = sizeof...(_Idxs) + 1; -#ifdef _MSC_VER +#ifdef _MDSPAN_COMPILER_MSVC // MSVC doesn't like the fact that __next_t happens to be a base // class that's private, even though __size_synamic is public in // it's definition. @@ -145,7 +145,7 @@ struct __standard_layout_psa< MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( - __construct_partially_static_array_from_sizes_tag_t, _T const &__val, + __construct_partially_static_array_from_sizes_tag_t, _T const & /*__val*/, __repeated_with_idxs<_Idxs, _T> const &... __vals) noexcept : __base_t(__base_t{__next_t( __construct_partially_static_array_from_sizes_tag, __vals...)}) {} diff --git a/include/experimental/__p0009_bits/trait_backports.hpp b/include/experimental/__p0009_bits/trait_backports.hpp index 4a8ec0fe..a94e1a1e 100644 --- a/include/experimental/__p0009_bits/trait_backports.hpp +++ b/include/experimental/__p0009_bits/trait_backports.hpp @@ -53,7 +53,7 @@ //============================================================================== // {{{1 -#if _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS +#ifdef _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS #if _MDSPAN_USE_VARIABLE_TEMPLATES namespace std {