From 913cffe92899a97839fc717ecfe2a8a373672b87 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 22 Apr 2024 20:17:37 -0600 Subject: [PATCH] AK: Add workaround for faulty Sanitizer warning on gcc 13+ in Atomic gcc can't seem to figure out that the address of a member variable of AK::Atomic in AtomicRefCounted cannot be null when fetch_sub-ing. Add a bogus condition to convince the compiler that it can't be null. --- AK/Atomic.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AK/Atomic.h b/AK/Atomic.h index 6e2f80d2e8..2d4d7412ce 100644 --- a/AK/Atomic.h +++ b/AK/Atomic.h @@ -279,7 +279,13 @@ public: ALWAYS_INLINE T fetch_sub(T val, MemoryOrder order = DefaultMemoryOrder) volatile noexcept { - return __atomic_fetch_sub(&m_value, val, order); + T volatile* ptr = &m_value; + // FIXME: GCC > 12 will wrongly warn on -Wstringop-overflow here with ASAN+UBSAN +#if defined(AK_COMPILER_GCC) && defined(HAS_ADDRESS_SANITIZER) + if (!ptr) + __builtin_unreachable(); +#endif + return __atomic_fetch_sub(ptr, val, order); } ALWAYS_INLINE T operator&=(T val) volatile noexcept