Clang doesn't consider the currently declared function as the proper intrinsic function (a few parameters differ vaguely), and even if declared properly, clang requires building for a target with the cx16 flag enabled to be able to use that intrinsic.
Instead just use the inline assembly or GCC builtin version instead.
This fixes building in PE mode with Clang in MSVC mode for both x86_64 and aarch64.
Signed-off-by: Martin Storsjo martin@martin.st --- include/winnt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/winnt.h b/include/winnt.h index 04353d9405d..9d797a85099 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -6894,7 +6894,7 @@ static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
#ifdef _WIN64
-#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(__clang__)
#define InterlockedCompareExchange128 _InterlockedCompareExchange128 static inline unsigned char _InterlockedCompareExchange128(__int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare); @@ -6913,7 +6913,7 @@ static inline unsigned char InterlockedCompareExchange128(__int64 *dest, __int64 return ret; }
-#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__clang__)
static inline unsigned char InterlockedCompareExchange128(__int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare) {
Hi Martin,
On 18.12.2020 23:35, Martin Storsjo wrote:
This fixes building in PE mode with Clang in MSVC mode for both x86_64 and aarch64.
I'd expect x86_64 to be fixed by [1], we could do the same for aarch64.
If changing header is preferable for some reason, we should reflect that in configure and maybe reorder #ifdefs to simplify it a bit.
Thanks,
Jacek
[1] https://source.winehq.org/git/wine.git/commitdiff/dc199ae8b8b38ac088eb0bcd05...
Hi Jacek,
On Sat, 19 Dec 2020, Jacek Caban wrote:
Hi Martin,
On 18.12.2020 23:35, Martin Storsjo wrote:
This fixes building in PE mode with Clang in MSVC mode for both x86_64 and aarch64.
I'd expect x86_64 to be fixed by [1], we could do the same for aarch64.
Ah, I see - that explains it. Yeah I was a bit surprised to see that it didn't work as expected, as I presumed that you had tested building in MSVC mode.
The actual issue here seems to be that the signature of the intrinsic _InterlockedCompareExchange128 is slightly wrong. Clang 11 and older (and MSVC itself) doesn't mind, but I was testing with a fresh trunk version of clang, where it needs to match better. See https://godbolt.org/z/TWbMs8 for an example of the difference.
FWIW, I bisected the change in behaviour down to https://reviews.llvm.org/D77491.
In that case, the fix is simply to correct the signature of the declaration - sending a new patch for that instead.
// Martin