Skip to content

ENH: Add changes that allow NumPy to compile with clang-cl #20866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/core/include/numpy/ndarraytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions numpy/core/include/numpy/npy_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/common/simd/intdiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/common_dtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem with NPY_INLINE here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is no export and inline, clang-cl only lets it be used in the same translation unit. It is later linked across object files which makes clang-cl error.

PyArray_CommonDType(PyArray_DTypeMeta *dtype1, PyArray_DTypeMeta *dtype2)
{
if (dtype1 == dtype2) {
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/src/umath/loops_unary_fp.dispatch.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down