From a264cf79c40cf32c9e9590e6fd56b414a869f3d3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 21 Dec 2023 13:11:14 +0100 Subject: [PATCH] AK: Use fallback builtins for overflow checks in AK::Checked If we don't have __builtin_add_overflow_p(), we can also try using __builtin_add_overflow(). This makes debug builds with Clang significantly faster since they no longer need to use the generic implementation. Same for multiplication. --- AK/Checked.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AK/Checked.h b/AK/Checked.h index 353e6e9e493..e07216bf3cf 100644 --- a/AK/Checked.h +++ b/AK/Checked.h @@ -348,6 +348,9 @@ public: { #if __has_builtin(__builtin_add_overflow_p) return __builtin_add_overflow_p(u, v, (T)0); +#elif __has_builtin(__builtin_add_overflow) + T result; + return __builtin_add_overflow(u, v, &result); #else Checked checked; checked = u; @@ -385,6 +388,9 @@ public: { #if __has_builtin(__builtin_mul_overflow_p) return __builtin_mul_overflow_p(u, v, (T)0); +#elif __has_builtin(__builtin_mul_overflow) + T result; + return __builtin_mul_overflow(u, v, &result); #else Checked checked; checked = u;