test-wasm: Don't cast signed values to unsigned types in wasm_invoke

If a negative value ends up in one of the arguments for an invoked
function, we don't want to cast it from a floating point type to an
unsigned type. This fixes a float-cast-overflow UBSAN error on macOS
with llvm 15.0.6.
This commit is contained in:
Andrew Kaster 2022-12-23 22:22:41 -07:00 committed by Andrew Kaster
parent 4ae2a54f3d
commit 8d015bd71c
Notes: sideshowbarker 2024-07-17 05:00:08 +09:00

View file

@ -211,14 +211,14 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
double_value = TRY(argument.to_double(vm));
switch (param.kind()) {
case Wasm::ValueType::Kind::I32:
arguments.append(Wasm::Value(param, static_cast<u64>(double_value)));
arguments.append(Wasm::Value(param, static_cast<i64>(double_value)));
break;
case Wasm::ValueType::Kind::I64:
if (argument.is_bigint()) {
auto value = TRY(argument.to_bigint_int64(vm));
arguments.append(Wasm::Value(param, bit_cast<u64>(value)));
arguments.append(Wasm::Value(param, value));
} else {
arguments.append(Wasm::Value(param, static_cast<u64>(double_value)));
arguments.append(Wasm::Value(param, static_cast<i64>(double_value)));
}
break;
case Wasm::ValueType::Kind::F32: