From a9d2d806b61df3b84af06744b6fad670f4012539 Mon Sep 17 00:00:00 2001 From: davidot Date: Tue, 23 Aug 2022 20:24:59 +0200 Subject: LibJS: Use __builtin_isnan in static_assert instead of isnan For the fuzzer build isnan was not usable in a constexpr context however __builtin_isnan seems to always be. Also while we're here add my name to the copyright since I forgot after the Value rewrite. --- Userland/Libraries/LibJS/Runtime/Value.cpp | 1 + Userland/Libraries/LibJS/Runtime/Value.h | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 06c2bafc2e..8575e5f4fb 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2020-2022, Linus Groh + * Copyright (c) 2022, David Tuin * * SPDX-License-Identifier: BSD-2-Clause */ diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index 4e54e4016e..87ebc71aab 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020-2021, Andreas Kling * Copyright (c) 2020-2022, Linus Groh + * Copyright (c) 2022, David Tuin * * SPDX-License-Identifier: BSD-2-Clause */ @@ -47,8 +48,9 @@ static_assert(POSITIVE_INFINITY_BITS == 0x7FF0000000000000); static_assert(NEGATIVE_INFINITY_BITS == 0xFFF0000000000000); // However as long as any bit is set in the mantissa with the exponent of all // ones this value is a NaN, and it even ignores the sign bit. -static_assert(isnan(bit_cast(0x7FF0000000000001))); -static_assert(isnan(bit_cast(0xFFF0000000040000))); +// (NOTE: we have to use __builtin_isnan here since some isnan implementations are not constexpr) +static_assert(__builtin_isnan(bit_cast(0x7FF0000000000001))); +static_assert(__builtin_isnan(bit_cast(0xFFF0000000040000))); // This means we can use all of these NaNs to store all other options for Value. // To make sure all of these other representations we use 0x7FF8 as the base top // 2 bytes which ensures the value is always a NaN. -- cgit v1.2.3