[libc-commits] [libc] [libc] Some compatibility update for building with MSVC. (PR #157701)
via libc-commits
libc-commits at lists.llvm.org
Tue Sep 9 09:16:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (lntue)
<details>
<summary>Changes</summary>
Add compiler identity macro and disable some unsupported features.
---
Full diff: https://github.com/llvm/llvm-project/pull/157701.diff
6 Files Affected:
- (modified) libc/src/__support/CMakeLists.txt (+1)
- (modified) libc/src/__support/CPP/CMakeLists.txt (+1)
- (modified) libc/src/__support/CPP/type_traits/is_complex.h (+7)
- (modified) libc/src/__support/common.h (+3-2)
- (modified) libc/src/__support/macros/optimization.h (+3)
- (modified) libc/src/__support/macros/properties/compiler.h (+3-3)
``````````diff
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 2196d9e23bba7..b6e87ac336fb2 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -97,6 +97,7 @@ add_header_library(
common.h
endian_internal.h
macros/properties/architectures.h
+ macros/properties/compiler.h
macros/attributes.h
macros/config.h
DEPENDS
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index a389a6d1702fe..671f96267bcb3 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -171,6 +171,7 @@ add_header_library(
libc.include.llvm-libc-macros.stdfix_macros
libc.src.__support.macros.attributes
libc.src.__support.macros.properties.types
+ libc.src.__support.macros.properties.compiler
libc.src.__support.macros.properties.complex_types
)
diff --git a/libc/src/__support/CPP/type_traits/is_complex.h b/libc/src/__support/CPP/type_traits/is_complex.h
index 23f05c08ccab5..5da1a40892c2a 100644
--- a/libc/src/__support/CPP/type_traits/is_complex.h
+++ b/libc/src/__support/CPP/type_traits/is_complex.h
@@ -13,12 +13,17 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
// LIBC_TYPES_HAS_CFLOAT16 && LIBC_TYPES_HAS_CFLOAT128
+#include "src/__support/macros/properties/compiler.h"
#include "src/__support/macros/properties/complex_types.h"
namespace LIBC_NAMESPACE_DECL {
namespace cpp {
// is_complex
+#ifdef LIBC_COMPILER_IS_MSVC
+// TODO: Add support for complex types with MSVC.
+template <typename T> struct is_complex : false_type {};
+#else
template <typename T> struct is_complex {
private:
template <typename Head, typename... Args>
@@ -40,6 +45,8 @@ template <typename T> struct is_complex {
#endif
>();
};
+#endif // LIBC_COMPILER_IS_MSVC
+
template <typename T>
LIBC_INLINE_VAR constexpr bool is_complex_v = is_complex<T>::value;
template <typename T1, typename T2>
diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 15209b76978af..a2808147f3e54 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -16,6 +16,7 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
+#include "src/__support/macros/properties/compiler.h"
#ifndef LLVM_LIBC_FUNCTION_ATTR
#define LLVM_LIBC_FUNCTION_ATTR
@@ -41,12 +42,12 @@
// to cleanly export and alias the C++ symbol `LIBC_NAMESPACE::func` with the C
// symbol `func`. So for public packaging on MacOS, we will only export the C
// symbol. Moreover, a C symbol `func` in macOS is mangled as `_func`.
-#if defined(LIBC_COPT_PUBLIC_PACKAGING)
+#if defined(LIBC_COPT_PUBLIC_PACKAGING) && !defined(LIBC_COMPILER_IS_MSVC)
#ifndef __APPLE__
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
LLVM_LIBC_ATTR(name) \
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
- __##name##_impl__ __asm__(#name); \
+ __##name##_impl__ asm(#name); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
type __##name##_impl__ arglist
#else // __APPLE__
diff --git a/libc/src/__support/macros/optimization.h b/libc/src/__support/macros/optimization.h
index 250a9e060728a..dbefd20a5cd16 100644
--- a/libc/src/__support/macros/optimization.h
+++ b/libc/src/__support/macros/optimization.h
@@ -34,6 +34,9 @@ LIBC_INLINE constexpr bool expects_bool_condition(T value, T expected) {
#elif defined(LIBC_COMPILER_IS_GCC)
#define LIBC_LOOP_NOUNROLL _Pragma("GCC unroll 0")
#define LIBC_LOOP_UNROLL _Pragma("GCC unroll 2048")
+#elif defined(LIBC_COMPILER_IS_MSVC)
+#define LIBC_LOOP_NOUNROLL
+#define LIBC_LOOP_UNROLL
#else
#error "Unhandled compiler"
#endif
diff --git a/libc/src/__support/macros/properties/compiler.h b/libc/src/__support/macros/properties/compiler.h
index b9ec0dd1defb9..6947bc7aa9010 100644
--- a/libc/src/__support/macros/properties/compiler.h
+++ b/libc/src/__support/macros/properties/compiler.h
@@ -34,10 +34,10 @@
#define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
#endif
-#if defined(_MSC_VER)
-#define LIBC_COMPILER_IS_MSC
+#if defined(_MSC_VER) && !defined(__clang__)
+#define LIBC_COMPILER_IS_MSVC
// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
-#define LIBC_COMPILER_MSC_VER (_MSC_VER)
+#define LIBC_COMPILER_MSVC_VER (_MSC_VER)
#endif
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H
``````````
</details>
https://github.com/llvm/llvm-project/pull/157701
More information about the libc-commits
mailing list