mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Make Checked.h work with Clang
Apparently Clang does not have __builtin_foo_overflow_p() Fixes #2044.
This commit is contained in:
parent
b5039a047f
commit
ea839861e5
Notes:
sideshowbarker
2024-07-19 07:07:48 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ea839861e5e
1 changed files with 14 additions and 0 deletions
14
AK/Checked.h
14
AK/Checked.h
|
@ -237,13 +237,27 @@ public:
|
||||||
template<typename U, typename V>
|
template<typename U, typename V>
|
||||||
static bool addition_would_overflow(U u, V v)
|
static bool addition_would_overflow(U u, V v)
|
||||||
{
|
{
|
||||||
|
#ifdef __clang__
|
||||||
|
Checked checked;
|
||||||
|
checked = u;
|
||||||
|
checked += v;
|
||||||
|
return checked.has_overflow();
|
||||||
|
#else
|
||||||
return __builtin_add_overflow_p(u, v, (T)0);
|
return __builtin_add_overflow_p(u, v, (T)0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename V, typename X>
|
template<typename U, typename V, typename X>
|
||||||
static bool multiplication_would_overflow(U u, V v)
|
static bool multiplication_would_overflow(U u, V v)
|
||||||
{
|
{
|
||||||
|
#ifdef __clang__
|
||||||
|
Checked checked;
|
||||||
|
checked = u;
|
||||||
|
checked *= v;
|
||||||
|
return checked.has_overflow();
|
||||||
|
#else
|
||||||
return __builtin_mul_overflow_p(u, v, (T)0);
|
return __builtin_mul_overflow_p(u, v, (T)0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename V, typename X>
|
template<typename U, typename V, typename X>
|
||||||
|
|
Loading…
Reference in a new issue