Skip to content

Commit 7b89360

Browse files
committed
[libcxx] Fix setup of MSVC specific intrinsics in Ryu code
This fixes warnings about implicitly declared `_umul128` and `__shiftright128` when building for x86_64 with clang-cl. Use `_MSC_VER` instead of `_LIBCPP_COMPILER_MSVC` for enabling MSVC specific code; `_MSC_VER` is defined both in clang-cl and MSVC, while `_LIBCPP_COMPILER_MSVC` only is defined if building with the actual MSVC compiler. Include `ryu.h` at the head of `d2s_intrinsics.h`, as it uses the `_LIBCPP_64_BIT` define, which is defined in `ryu.h`. Now the Ryu files build without warnings with clang-cl for i386, x86_64, arm and aarch64. Differential Revision: https://reviews.llvm.org/D119647
1 parent 1234011 commit 7b89360

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

libcxx/src/include/ryu/d2s_intrinsics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
#include "__config"
4646

47+
#include "include/ryu/ryu.h"
48+
4749
_LIBCPP_BEGIN_NAMESPACE_STD
4850

4951
#if defined(_M_X64) && defined(_MSC_VER)

libcxx/src/include/ryu/ryu.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
#include "include/ryu/d2s.h"
5757
#include "include/ryu/d2fixed.h"
5858

59-
#if defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
60-
#include <intrin0.h> // for _umul128() and __shiftright128()
61-
#endif // defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
59+
#if defined(_MSC_VER)
60+
#include <intrin.h> // for _umul128(), __shiftright128(), _BitScanForward{,64}
61+
#endif // defined(_MSC_VER)
6262

6363
#if defined(_WIN64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__aarch64__)
6464
#define _LIBCPP_64_BIT
@@ -68,7 +68,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
6868

6969
// https://github.com/ulfjack/ryu/tree/59661c3/ryu
7070

71-
#if !defined(_LIBCPP_COMPILER_MSVC)
71+
#if !defined(_MSC_VER)
7272
_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __index, unsigned long long __mask) {
7373
if (__mask == 0) {
7474
return false;
@@ -84,7 +84,7 @@ _LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __inde
8484
*__index = __builtin_ctz(__mask);
8585
return true;
8686
}
87-
#endif // _LIBCPP_COMPILER_MSVC
87+
#endif // !_MSC_VER
8888

8989
template <class _Floating>
9090
[[nodiscard]] to_chars_result _Floating_to_chars_ryu(

0 commit comments

Comments
 (0)