diff --git a/AK/BigIntBase.h b/AK/BigIntBase.h index 179e053abc5..20212ae9cc2 100644 --- a/AK/BigIntBase.h +++ b/AK/BigIntBase.h @@ -196,7 +196,7 @@ ALWAYS_INLINE constexpr NativeWord add_words(NativeWord word1, NativeWord word2, ALWAYS_INLINE constexpr NativeWord sub_words(NativeWord word1, NativeWord word2, bool& carry) { if (!is_constant_evaluated()) { -#if __has_builtin(__builtin_subc) +#if __has_builtin(__builtin_subc) && !defined(AK_BUILTIN_SUBC_BROKEN) NativeWord ncarry, output; if constexpr (SameAs) output = __builtin_subc(word1, word2, carry, reinterpret_cast(&ncarry)); diff --git a/AK/Platform.h b/AK/Platform.h index 7a80ab7b91c..ec5cc454ee2 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -117,6 +117,13 @@ # define AK_HAS_CONDITIONALLY_TRIVIAL #endif +// Apple Clang 14.0.3 (shipped in Xcode 14.3) has a bug that causes __builtin_subc{,l,ll} +// to incorrectly return whether a borrow occurred on AArch64. See our writeup for the Qemu +// issue also caused by it: https://gitlab.com/qemu-project/qemu/-/issues/1659#note_1408275831 +#if ARCH(AARCH64) && defined(__apple_build_version__) && __clang_major__ == 14 +# define AK_BUILTIN_SUBC_BROKEN +#endif + #ifdef ALWAYS_INLINE # undef ALWAYS_INLINE #endif