From 7147e95add876561def5588c8a38b4214815c3dc Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Mon, 7 Jun 2021 14:53:18 +0100 Subject: [PATCH] cranelift: Fix endianness bug in filetests runner Enabling runtests for the s390x backend exposed a pre-existing endian bug with handling bool test case return values. These are written as integers of the same width by the trampoline, but are always read out as the Rust "bool" type. This happens to work on little-endian systems, but fails for any boolean type larger than 1 byte on big-endian systems. See: https://github.com/bytecodealliance/wasmtime/pull/2964#issuecomment-855879866 --- cranelift/filetests/src/function_runner.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cranelift/filetests/src/function_runner.rs b/cranelift/filetests/src/function_runner.rs index a41d5f2869..1546cb1459 100644 --- a/cranelift/filetests/src/function_runner.rs +++ b/cranelift/filetests/src/function_runner.rs @@ -251,7 +251,13 @@ impl UnboxedValues { ir::types::I64 => DataValue::I64(ptr::read(p as *const i64)), ir::types::F32 => DataValue::F32(ptr::read(p as *const Ieee32)), ir::types::F64 => DataValue::F64(ptr::read(p as *const Ieee64)), - _ if ty.is_bool() => DataValue::B(ptr::read(p as *const bool)), + _ if ty.is_bool() => match ty.bytes() { + 1 => DataValue::B(ptr::read(p as *const i8) != 0), + 2 => DataValue::B(ptr::read(p as *const i16) != 0), + 4 => DataValue::B(ptr::read(p as *const i32) != 0), + 8 => DataValue::B(ptr::read(p as *const i64) != 0), + _ => unimplemented!(), + }, _ if ty.is_vector() && ty.bytes() == 16 => { DataValue::V128(ptr::read(p as *const [u8; 16])) }