LibWasm/WASI: Don't convert enums and u8s into i64

Doing so results in incorrect values being created, ultimately leading
to traps or errors.

(cherry picked from commit f6c3b333334f7bb5314a844804cb259cf277005e)
This commit is contained in:
Ali Mohammad Pur 2024-06-30 20:29:31 +02:00 committed by Ali Mohammad Pur
parent 7181c3f2ea
commit a4eb46fcca
Notes: sideshowbarker 2024-07-17 10:31:19 +09:00

View File

@ -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);