mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +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>
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename U, typename V, typename X>
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename U, typename V, typename X>
|
||||
|
|
Loading…
Reference in a new issue