From 0d05ab2ad0cc56cc6fe9ee647dfcfda44a92b4f2 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 16 Aug 2024 16:07:17 +0200 Subject: [PATCH] LibWasm: Allow all Value::to() calls This brings back the old behaviour of Value::to() (and other similar calls), which WASI depends on. To make sure all similar issues are caught in the future, this commit also introduces an static assertion in Value::to(). --- .../LibWasm/AbstractMachine/AbstractMachine.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index d27f24548952..0bab4898c800 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -142,22 +142,16 @@ class Value { template ALWAYS_INLINE T to() const { + static_assert(IsOneOf || IsIntegral, "Unsupported type for Value::to()"); + if constexpr (IsSame) { return m_value; } - if constexpr (IsSame) { - u32 low = m_value.low() & 0xFFFFFFFF; - return low; - } - if constexpr (IsSame) { - u32 low = m_value.low() & 0xFFFFFFFF; - return bit_cast(low); - } - if constexpr (IsSame) { - return bit_cast(m_value.low()); + if constexpr (IsOneOf) { + return bit_cast(m_value.low()); } - if constexpr (IsSame) { - return bit_cast(m_value.low()); + if constexpr (IsIntegral && sizeof(T) < 8) { + return bit_cast(static_cast>(m_value.low() & NumericLimits>::max())); } if constexpr (IsSame) { u32 low = m_value.low() & 0xFFFFFFFF;