1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

AK: Work around Apple Clang __builtin_subc codegen issue

Apple Clang 14.0.3 (Xcode 14.3) miscompiles this builtin on AArch64,
causing the borrow flag to be set incorrectly. I have added a detailed
writeup on Qemu's issue tracker, where the same issue led to a hang when
emulating x86:

https://gitlab.com/qemu-project/qemu/-/issues/1659#note_1408275831

I don't know of any specific issue caused by this on Lagom, but better
safe than sorry.
This commit is contained in:
Daniel Bertalan 2023-06-23 09:18:29 +00:00 committed by Andreas Kling
parent 7dadc9ff33
commit 9d4dfc1061
2 changed files with 8 additions and 1 deletions

View file

@ -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<NativeWord, unsigned int>)
output = __builtin_subc(word1, word2, carry, reinterpret_cast<unsigned int*>(&ncarry));