Skip to content

Commit 38a4c9c

Browse files
[libc][msvc] fix mathlib build on WoA (llvm#161258)
Fix build errors encountered when building math library on WoA. 1. Skip FEnv equality check for MSVC 2. Provide a placeholder type for vector types.
1 parent 786358a commit 38a4c9c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

libc/src/string/memory_utils/op_generic.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,22 @@ static_assert((UINTPTR_MAX == 4294967295U) ||
4141
"We currently only support 32- or 64-bit platforms");
4242

4343
#ifdef LIBC_COMPILER_IS_MSVC
44-
44+
#ifdef LIBC_TARGET_ARCH_IS_X86
4545
namespace LIBC_NAMESPACE_DECL {
4646
using generic_v128 = __m128i;
4747
using generic_v256 = __m256i;
4848
using generic_v512 = __m512i;
4949
} // namespace LIBC_NAMESPACE_DECL
50+
#else
51+
// Special handling when target does not have real vector types.
52+
// We can potentially use uint8x16_t etc. However, MSVC does not provide
53+
// subscript operation.
54+
namespace LIBC_NAMESPACE_DECL {
55+
struct alignas(16) generic_v128 : public cpp::array<uint8_t, 16> {};
56+
struct alignas(32) generic_v256 : public cpp::array<uint8_t, 32> {};
57+
struct alignas(64) generic_v512 : public cpp::array<uint8_t, 64> {};
58+
} // namespace LIBC_NAMESPACE_DECL
59+
#endif
5060

5161
#else
5262
namespace LIBC_NAMESPACE_DECL {
@@ -159,7 +169,8 @@ template <typename T> struct Memset {
159169

160170
LIBC_INLINE static void block(Ptr dst, uint8_t value) {
161171
if constexpr (is_scalar_v<T> || is_vector_v<T>) {
162-
store<T>(dst, splat<T>(value));
172+
// Avoid ambiguous call due to ADL
173+
generic::store<T>(dst, splat<T>(value));
163174
} else if constexpr (is_array_v<T>) {
164175
using value_type = typename T::value_type;
165176
const auto Splat = splat<value_type>(value);

libc/test/UnitTest/FEnvSafeTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void FEnvSafeTest::set_fenv(const fenv_t &fenv) {
4343

4444
void FEnvSafeTest::expect_fenv_eq(const fenv_t &before_fenv,
4545
const fenv_t &after_fenv) {
46-
#if defined(LIBC_TARGET_ARCH_IS_AARCH64)
46+
#if defined(LIBC_TARGET_ARCH_IS_AARCH64) && !defined(LIBC_COMPILER_IS_MSVC)
4747
using FPState = LIBC_NAMESPACE::fputil::FEnv::FPState;
4848
const FPState &before_state = reinterpret_cast<const FPState &>(before_fenv);
4949
const FPState &after_state = reinterpret_cast<const FPState &>(after_fenv);

0 commit comments

Comments
 (0)