From 292269159ceab5d2443d6931b9cc6f0163665a65 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 30 Mar 2016 15:34:57 -0700 Subject: fix wasm.js loads of i64 that read <8 bytes --- src/wasm-js.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp index d978e4a2a..ab6f02d16 100644 --- a/src/wasm-js.cpp +++ b/src/wasm-js.cpp @@ -267,26 +267,27 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() { } // nicely aligned if (!isWasmTypeFloat(load->type)) { + int32_t ret; if (load->bytes == 1) { if (load->signed_) { - return Literal(EM_ASM_INT({ return Module['info'].parent['HEAP8'][$0] }, addr)); + ret = EM_ASM_INT({ return Module['info'].parent['HEAP8'][$0] }, addr); } else { - return Literal(EM_ASM_INT({ return Module['info'].parent['HEAPU8'][$0] }, addr)); + ret = EM_ASM_INT({ return Module['info'].parent['HEAPU8'][$0] }, addr); } } else if (load->bytes == 2) { if (load->signed_) { - return Literal(EM_ASM_INT({ return Module['info'].parent['HEAP16'][$0 >> 1] }, addr)); + ret = EM_ASM_INT({ return Module['info'].parent['HEAP16'][$0 >> 1] }, addr); } else { - return Literal(EM_ASM_INT({ return Module['info'].parent['HEAPU16'][$0 >> 1] }, addr)); + ret = EM_ASM_INT({ return Module['info'].parent['HEAPU16'][$0 >> 1] }, addr); } } else if (load->bytes == 4) { if (load->signed_) { - return Literal(EM_ASM_INT({ return Module['info'].parent['HEAP32'][$0 >> 2] }, addr)); + ret = EM_ASM_INT({ return Module['info'].parent['HEAP32'][$0 >> 2] }, addr); } else { - return Literal(EM_ASM_INT({ return Module['info'].parent['HEAPU32'][$0 >> 2] }, addr)); + ret = EM_ASM_INT({ return Module['info'].parent['HEAPU32'][$0 >> 2] }, addr); } - } - abort(); + } else abort(); + return load->type == i32 ? Literal(ret) : Literal(int64_t(ret)); } else { if (load->bytes == 4) { return Literal((float)EM_ASM_DOUBLE({ return Module['info'].parent['HEAPF32'][$0 >> 2] }, addr)); -- cgit v1.2.3