Skip to content

Commit 6041085

Browse files
ashayFerdinand Lemaire
authored andcommitted
[lldb] fix build issue on MSVC because of missing byte-swap builtins
The `__builtin_bswap{32,64}()` builtins (introduced in commit e07a421) 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
1 parent 5aa2c1b commit 6041085

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lldb/source/Core/DumpRegisterValue.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@
1818
#include "lldb/Utility/StreamString.h"
1919
#include "lldb/lldb-private-types.h"
2020

21+
#if !defined(__has_builtin)
22+
#define __has_builtin(x) 0
23+
#endif
24+
25+
#if __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
26+
#define bswap_32(x) __builtin_bswap32(x)
27+
#define bswap_64(x) __builtin_bswap64(x)
28+
#elif defined(_MSC_VER)
29+
#define bswap_32(x) _byteswap_ulong(x)
30+
#define bswap_64(x) _byteswap_uint64(x)
31+
#else
32+
#include <byteswap.h>
33+
#endif
34+
2135
using namespace lldb;
2236

23-
static uint32_t swap_value(uint32_t v) { return __builtin_bswap32(v); }
24-
static uint64_t swap_value(uint64_t v) { return __builtin_bswap64(v); }
37+
static uint32_t swap_value(uint32_t v) { return bswap_32(v); }
38+
static uint64_t swap_value(uint64_t v) { return bswap_64(v); }
2539

2640
template <typename T>
2741
static void dump_type_value(lldb_private::CompilerType &fields_type, T value,

0 commit comments

Comments
 (0)