[Lldb-commits] [lldb] 7978abd - [lldb] fix build issue on MSVC because of missing byte-swap builtins

Ashay Rane via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 17 12:39:11 PDT 2023


Author: Ashay Rane
Date: 2023-04-17T14:39:00-05:00
New Revision: 7978abd5aef1ba84d7a1cefbc3443245acff2c48

URL: https://github.com/llvm/llvm-project/commit/7978abd5aef1ba84d7a1cefbc3443245acff2c48
DIFF: https://github.com/llvm/llvm-project/commit/7978abd5aef1ba84d7a1cefbc3443245acff2c48.diff

LOG: [lldb] fix build issue on MSVC because of missing byte-swap builtins

The `__builtin_bswap{32,64}()` builtins (introduced in commit e07a421d)
are missing from MSVC, which causes build errors when compiling LLDB on
Windows (tested with MSVC 19.34.31943.0).  This patch replaces the
builtins with either MSVC's `_byteswap_u{long,64}()` or the original
builtins, or the `bswap_{32,64}()` functions from byteswap.h, depending
on which ones are available.

Reviewed By: bulbazord

Differential Revision: https://reviews.llvm.org/D148541

Added: 
    

Modified: 
    lldb/source/Core/DumpRegisterValue.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Core/DumpRegisterValue.cpp b/lldb/source/Core/DumpRegisterValue.cpp
index 0e85e8e9ea893..3e59fb13b8cad 100644
--- a/lldb/source/Core/DumpRegisterValue.cpp
+++ b/lldb/source/Core/DumpRegisterValue.cpp
@@ -18,10 +18,24 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/lldb-private-types.h"
 
+#if !defined(__has_builtin)
+#define __has_builtin(x) 0
+#endif
+
+#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+#elif defined(_MSC_VER)
+#define bswap_32(x) _byteswap_ulong(x)
+#define bswap_64(x) _byteswap_uint64(x)
+#else
+#include <byteswap.h>
+#endif
+
 using namespace lldb;
 
-static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
-static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
+static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
+static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
 
 template <typename T>
 static void dump_type_value(lldb_private::CompilerType &fields_type, T value,


        


More information about the lldb-commits mailing list