[libc-commits] [libc] [libc] Some more MSVC compatibility in src/__support. (PR #158108)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Thu Sep 11 10:32:20 PDT 2025


================
@@ -16,13 +16,49 @@
 namespace LIBC_NAMESPACE_DECL {
 
 // We rely on compiler preprocessor defines to allow for cross compilation.
+#ifdef LIBC_COMPILER_IS_MSVC
+#define __BYTE_ORDER__ 0
+#define __ORDER_LITTLE_ENDIAN__ 0
+#define __ORDER_BIG_ENDIAN__ 1
+#else // !LIBC_COMPILER_IS_MSVC
 #if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) ||           \
     !defined(__ORDER_BIG_ENDIAN__)
 #error "Missing preprocessor definitions for endianness detection."
 #endif
+#endif // LIBC_COMPILER_IS_MSVC
 
 namespace internal {
 
+template <typename T> LIBC_INLINE T byte_swap(T value);
+
+template <> LIBC_INLINE uint16_t byte_swap<uint16_t>(uint16_t value) {
+#if __has_builtin(__builtin_bswap16)
+  return __builtin_bswap16(value);
+#else
+  return (v << 8) | (v >> 8);
+#endif // __builtin_bswap16
+};
----------------
SchrodingerZhu wrote:

extra semi

https://github.com/llvm/llvm-project/pull/158108


More information about the libc-commits mailing list