Skip to content

Commit 0b9a79b

Browse files
authored
[libc] Some compatibility update for building with MSVC. (#157701)
Add compiler identity macro and disable some unsupported features.
1 parent 97c9878 commit 0b9a79b

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

libc/src/__support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ add_header_library(
9797
common.h
9898
endian_internal.h
9999
macros/properties/architectures.h
100+
macros/properties/compiler.h
100101
macros/attributes.h
101102
macros/config.h
102103
DEPENDS

libc/src/__support/CPP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ add_header_library(
171171
libc.include.llvm-libc-macros.stdfix_macros
172172
libc.src.__support.macros.attributes
173173
libc.src.__support.macros.properties.types
174+
libc.src.__support.macros.properties.compiler
174175
libc.src.__support.macros.properties.complex_types
175176
)
176177

libc/src/__support/CPP/type_traits/is_complex.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
#include "src/__support/macros/attributes.h"
1414
#include "src/__support/macros/config.h"
1515
// LIBC_TYPES_HAS_CFLOAT16 && LIBC_TYPES_HAS_CFLOAT128
16+
#include "src/__support/macros/properties/compiler.h"
1617
#include "src/__support/macros/properties/complex_types.h"
1718

1819
namespace LIBC_NAMESPACE_DECL {
1920
namespace cpp {
2021

2122
// is_complex
23+
#ifdef LIBC_COMPILER_IS_MSVC
24+
// TODO: Add support for complex types with MSVC.
25+
template <typename T> struct is_complex : false_type {};
26+
#else
2227
template <typename T> struct is_complex {
2328
private:
2429
template <typename Head, typename... Args>
@@ -40,6 +45,8 @@ template <typename T> struct is_complex {
4045
#endif
4146
>();
4247
};
48+
#endif // LIBC_COMPILER_IS_MSVC
49+
4350
template <typename T>
4451
LIBC_INLINE_VAR constexpr bool is_complex_v = is_complex<T>::value;
4552
template <typename T1, typename T2>

libc/src/__support/common.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/__support/macros/attributes.h"
1717
#include "src/__support/macros/config.h"
1818
#include "src/__support/macros/properties/architectures.h"
19+
#include "src/__support/macros/properties/compiler.h"
1920

2021
#ifndef LLVM_LIBC_FUNCTION_ATTR
2122
#define LLVM_LIBC_FUNCTION_ATTR
@@ -41,12 +42,12 @@
4142
// to cleanly export and alias the C++ symbol `LIBC_NAMESPACE::func` with the C
4243
// symbol `func`. So for public packaging on MacOS, we will only export the C
4344
// symbol. Moreover, a C symbol `func` in macOS is mangled as `_func`.
44-
#if defined(LIBC_COPT_PUBLIC_PACKAGING)
45+
#if defined(LIBC_COPT_PUBLIC_PACKAGING) && !defined(LIBC_COMPILER_IS_MSVC)
4546
#ifndef __APPLE__
4647
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
4748
LLVM_LIBC_ATTR(name) \
4849
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
49-
__##name##_impl__ __asm__(#name); \
50+
__##name##_impl__ asm(#name); \
5051
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
5152
type __##name##_impl__ arglist
5253
#else // __APPLE__

libc/src/__support/macros/optimization.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ LIBC_INLINE constexpr bool expects_bool_condition(T value, T expected) {
3434
#elif defined(LIBC_COMPILER_IS_GCC)
3535
#define LIBC_LOOP_NOUNROLL _Pragma("GCC unroll 0")
3636
#define LIBC_LOOP_UNROLL _Pragma("GCC unroll 2048")
37+
#elif defined(LIBC_COMPILER_IS_MSVC)
38+
#define LIBC_LOOP_NOUNROLL
39+
#define LIBC_LOOP_UNROLL
3740
#else
3841
#error "Unhandled compiler"
3942
#endif

libc/src/__support/macros/properties/compiler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
3535
#endif
3636

37-
#if defined(_MSC_VER)
38-
#define LIBC_COMPILER_IS_MSC
37+
#if defined(_MSC_VER) && !defined(__clang__)
38+
#define LIBC_COMPILER_IS_MSVC
3939
// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
40-
#define LIBC_COMPILER_MSC_VER (_MSC_VER)
40+
#define LIBC_COMPILER_MSVC_VER (_MSC_VER)
4141
#endif
4242

4343
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_COMPILER_H

0 commit comments

Comments
 (0)