Skip to content

Commit

Permalink
LibWasm: Allow all Value::to<Integral>() calls
Browse files Browse the repository at this point in the history
This brings back the old behaviour of Value::to<short>() (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().
  • Loading branch information
alimpfard committed Aug 16, 2024
1 parent e3b3041 commit 0d05ab2
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,16 @@ class Value {
template<typename T>
ALWAYS_INLINE T to() const
{
static_assert(IsOneOf<T, u128, u64, i64, f32, f64, Reference> || IsIntegral<T>, "Unsupported type for Value::to()");

if constexpr (IsSame<T, u128>) {
return m_value;
}
if constexpr (IsSame<T, u32>) {
u32 low = m_value.low() & 0xFFFFFFFF;
return low;
}
if constexpr (IsSame<T, i32>) {
u32 low = m_value.low() & 0xFFFFFFFF;
return bit_cast<i32>(low);
}
if constexpr (IsSame<T, u64>) {
return bit_cast<u64>(m_value.low());
if constexpr (IsOneOf<T, u64, i64>) {
return bit_cast<T>(m_value.low());
}
if constexpr (IsSame<T, i64>) {
return bit_cast<i64>(m_value.low());
if constexpr (IsIntegral<T> && sizeof(T) < 8) {
return bit_cast<T>(static_cast<MakeUnsigned<T>>(m_value.low() & NumericLimits<MakeUnsigned<T>>::max()));
}
if constexpr (IsSame<T, f32>) {
u32 low = m_value.low() & 0xFFFFFFFF;
Expand Down

0 comments on commit 0d05ab2

Please sign in to comment.