From 50d69741cb35db1a535282060c51e536a863ce99 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Thu, 20 Jan 2022 18:12:14 +0000 Subject: [PATCH] ENH: Add changes that allow NumPy to compile with clang-cl Port over changes needed to compile NumPy using clang-cl from #13816. Desirable to retain these even though distutils is effectively deprecated and so not worth the effort to alter. --- numpy/core/include/numpy/ndarraytypes.h | 2 +- numpy/core/include/numpy/npy_common.h | 7 ++++--- numpy/core/src/common/simd/intdiv.h | 2 +- numpy/core/src/multiarray/common_dtype.c | 2 +- numpy/core/src/umath/loops_unary_fp.dispatch.c.src | 3 +++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h index 47d063178d15..35d82ec036bd 100644 --- a/numpy/core/include/numpy/ndarraytypes.h +++ b/numpy/core/include/numpy/ndarraytypes.h @@ -87,7 +87,7 @@ enum NPY_TYPES { NPY_BOOL=0, /* The number of types not including the new 1.6 types */ NPY_NTYPES_ABI_COMPATIBLE=21 }; -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) #pragma deprecated(NPY_CHAR) #endif diff --git a/numpy/core/include/numpy/npy_common.h b/numpy/core/include/numpy/npy_common.h index 1d6234e20e0f..2bcc45e4f677 100644 --- a/numpy/core/include/numpy/npy_common.h +++ b/numpy/core/include/numpy/npy_common.h @@ -131,9 +131,10 @@ #endif #endif -#if defined(_MSC_VER) - #define NPY_INLINE __inline -#elif defined(__GNUC__) +#if defined(_MSC_VER) && !defined(__clang__) + #define NPY_INLINE __inline +/* clang included here to handle clang-cl on Windows */ +#elif defined(__GNUC__) || defined(__clang__) #if defined(__STRICT_ANSI__) #define NPY_INLINE __inline__ #else diff --git a/numpy/core/src/common/simd/intdiv.h b/numpy/core/src/common/simd/intdiv.h index a7a461721dba..42f022c551a7 100644 --- a/numpy/core/src/common/simd/intdiv.h +++ b/numpy/core/src/common/simd/intdiv.h @@ -136,7 +136,7 @@ NPY_FINLINE npy_uint64 npyv__divh128_u64(npy_uint64 high, npy_uint64 divisor) { assert(divisor > 1); npy_uint64 quotient; -#if defined(_M_X64) && defined(_MSC_VER) && _MSC_VER >= 1920 +#if defined(_M_X64) && defined(_MSC_VER) && _MSC_VER >= 1920 && !defined(__clang__) npy_uint64 remainder; quotient = _udiv128(high, 0, divisor, &remainder); (void)remainder; diff --git a/numpy/core/src/multiarray/common_dtype.c b/numpy/core/src/multiarray/common_dtype.c index ca80b1ed7002..3561a905aa7a 100644 --- a/numpy/core/src/multiarray/common_dtype.c +++ b/numpy/core/src/multiarray/common_dtype.c @@ -41,7 +41,7 @@ * @param dtype2 Second DType class. * @return The common DType or NULL with an error set */ -NPY_NO_EXPORT NPY_INLINE PyArray_DTypeMeta * +NPY_NO_EXPORT PyArray_DTypeMeta * PyArray_CommonDType(PyArray_DTypeMeta *dtype1, PyArray_DTypeMeta *dtype2) { if (dtype1 == dtype2) { diff --git a/numpy/core/src/umath/loops_unary_fp.dispatch.c.src b/numpy/core/src/umath/loops_unary_fp.dispatch.c.src index 5817cf500b40..78e231965bca 100644 --- a/numpy/core/src/umath/loops_unary_fp.dispatch.c.src +++ b/numpy/core/src/umath/loops_unary_fp.dispatch.c.src @@ -128,6 +128,9 @@ NPY_FINLINE double c_square_f64(double a) #if __clang_major__ < 10 // Clang before v10 #define WORKAROUND_CLANG_RECIPROCAL_BUG 1 + #elif defined(_MSC_VER) + // clang-cl has the same bug + #define WORKAROUND_CLANG_RECIPROCAL_BUG 1 #elif defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64) // Clang v10+, targeting i386 or x86_64 #define WORKAROUND_CLANG_RECIPROCAL_BUG 0