Skip to content

Commit

Permalink
LibWasm/WASI: Don't convert enums and u8s into i64
Browse files Browse the repository at this point in the history
Doing so results in incorrect values being created, ultimately leading
to traps or errors.

(cherry picked from commit f6c3b333334f7bb5314a844804cb259cf277005e)
  • Loading branch information
alimpfard committed Jun 30, 2024
1 parent 7181c3f commit a4eb46f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Userland/Libraries/LibWasm/WASI/Wasi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,20 @@ ErrorOr<HostFunction> Implementation::function_by_name(StringView name)
namespace ABI {

template<typename T>
auto CompatibleValueType = IsOneOf<T, i8, i16, i32>
struct HostTypeImpl {
using Type = T;
};

template<Enum T>
struct HostTypeImpl<T> {
using Type = UnderlyingType<T>;
};

template<typename T>
using HostType = typename HostTypeImpl<T>::Type;

template<typename T>
auto CompatibleValueType = IsOneOf<HostType<T>, i8, i16, i32, u8, u16>
? Wasm::ValueType(Wasm::ValueType::I32)
: Wasm::ValueType(Wasm::ValueType::I64);

Expand Down

0 comments on commit a4eb46f

Please sign in to comment.