From 2ac7b5579704091a2b64265d9f5d1db327722213 Mon Sep 17 00:00:00 2001 From: relapids Date: Mon, 15 Aug 2022 05:26:48 -0700 Subject: [PATCH 1/2] Allow building with clang-cl on Windows. --- qemu/include/qemu/atomic.h | 64 +++++++++++++++++------------------ qemu/include/qemu/int128.h | 2 ++ qemu/target/ppc/excp_helper.c | 4 +++ 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/qemu/include/qemu/atomic.h b/qemu/include/qemu/atomic.h index 3eb72dbe..4e26bedf 100644 --- a/qemu/include/qemu/atomic.h +++ b/qemu/include/qemu/atomic.h @@ -31,38 +31,38 @@ * implicit promotion. int and larger types, as well as pointers, can be * converted to a non-qualified type just by applying a binary operator. */ -#define typeof_strip_qual(expr) \ - typeof( \ - __builtin_choose_expr( \ - __builtin_types_compatible_p(typeof(expr), bool) || \ - __builtin_types_compatible_p(typeof(expr), const bool) || \ - __builtin_types_compatible_p(typeof(expr), volatile bool) || \ - __builtin_types_compatible_p(typeof(expr), const volatile bool), \ - (bool)1, \ - __builtin_choose_expr( \ - __builtin_types_compatible_p(typeof(expr), signed char) || \ - __builtin_types_compatible_p(typeof(expr), const signed char) || \ - __builtin_types_compatible_p(typeof(expr), volatile signed char) || \ - __builtin_types_compatible_p(typeof(expr), const volatile signed char), \ - (signed char)1, \ - __builtin_choose_expr( \ - __builtin_types_compatible_p(typeof(expr), unsigned char) || \ - __builtin_types_compatible_p(typeof(expr), const unsigned char) || \ - __builtin_types_compatible_p(typeof(expr), volatile unsigned char) || \ - __builtin_types_compatible_p(typeof(expr), const volatile unsigned char), \ - (unsigned char)1, \ - __builtin_choose_expr( \ - __builtin_types_compatible_p(typeof(expr), signed short) || \ - __builtin_types_compatible_p(typeof(expr), const signed short) || \ - __builtin_types_compatible_p(typeof(expr), volatile signed short) || \ - __builtin_types_compatible_p(typeof(expr), const volatile signed short), \ - (signed short)1, \ - __builtin_choose_expr( \ - __builtin_types_compatible_p(typeof(expr), unsigned short) || \ - __builtin_types_compatible_p(typeof(expr), const unsigned short) || \ - __builtin_types_compatible_p(typeof(expr), volatile unsigned short) || \ - __builtin_types_compatible_p(typeof(expr), const volatile unsigned short), \ - (unsigned short)1, \ +#define typeof_strip_qual(expr) \ + __typeof__( \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof__(expr), bool) || \ + __builtin_types_compatible_p(__typeof__(expr), const bool) || \ + __builtin_types_compatible_p(__typeof__(expr), volatile bool) || \ + __builtin_types_compatible_p(__typeof__(expr), const volatile bool), \ + (bool)1, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof__(expr), signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), const signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), volatile signed char) || \ + __builtin_types_compatible_p(__typeof__(expr), const volatile signed char), \ + (signed char)1, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof__(expr), unsigned char) || \ + __builtin_types_compatible_p(__typeof__(expr), const unsigned char) || \ + __builtin_types_compatible_p(__typeof__(expr), volatile unsigned char) || \ + __builtin_types_compatible_p(__typeof__(expr), const volatile unsigned char), \ + (unsigned char)1, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof__(expr), signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), const signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), volatile signed short) || \ + __builtin_types_compatible_p(__typeof__(expr), const volatile signed short), \ + (signed short)1, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), const unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), volatile unsigned short) || \ + __builtin_types_compatible_p(__typeof__(expr), const volatile unsigned short), \ + (unsigned short)1, \ (expr)+0)))))) #ifdef __ATOMIC_RELAXED diff --git a/qemu/include/qemu/int128.h b/qemu/include/qemu/int128.h index d32511a6..d1d1ad44 100644 --- a/qemu/include/qemu/int128.h +++ b/qemu/include/qemu/int128.h @@ -146,7 +146,9 @@ static inline Int128 bswap128(Int128 a) #else /* !CONFIG_INT128 */ typedef struct Int128 Int128; +#if !(defined(_MSC_VER) && defined(__clang__)) typedef Int128 __int128_t; +#endif struct Int128 { uint64_t lo; diff --git a/qemu/target/ppc/excp_helper.c b/qemu/target/ppc/excp_helper.c index beaef6cd..f1114b5b 100644 --- a/qemu/target/ppc/excp_helper.c +++ b/qemu/target/ppc/excp_helper.c @@ -1061,7 +1061,11 @@ void helper_store_msr(CPUPPCState *env, target_ulong val) } #if defined(TARGET_PPC64) +#if defined(_MSC_VER) && defined(__clang__) +void helper_pminsn(CPUPPCState *env, uint32_t insn) +#else void helper_pminsn(CPUPPCState *env, powerpc_pm_insn_t insn) +#endif { CPUState *cs; From 5a54b3d7af7fd2477bce9ac61485d0ea260795cb Mon Sep 17 00:00:00 2001 From: relapids Date: Mon, 15 Aug 2022 06:45:25 -0700 Subject: [PATCH 2/2] Fix a segfault inside tb_remove_from_jmp_list by forcing clang-cl to use the same atomic routines as MSVC. --- qemu/include/qemu/atomic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu/include/qemu/atomic.h b/qemu/include/qemu/atomic.h index 4e26bedf..84922100 100644 --- a/qemu/include/qemu/atomic.h +++ b/qemu/include/qemu/atomic.h @@ -65,7 +65,7 @@ (unsigned short)1, \ (expr)+0)))))) -#ifdef __ATOMIC_RELAXED +#if defined(__ATOMIC_RELAXED) && !(defined(_MSC_VER) && defined(__clang__)) /* For C11 atomic ops */ /* Sanity check that the size of an atomic operation isn't "overly large".