From dc0dcd01d2cb05070fd187d081a61466ec0cde8b Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 5 Jun 2021 09:23:00 +0800 Subject: [PATCH 1/4] fix singlepass issue #2347 --- lib/compiler-singlepass/src/codegen_x64.rs | 2 +- tests/compilers/imports.rs | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/compiler-singlepass/src/codegen_x64.rs b/lib/compiler-singlepass/src/codegen_x64.rs index 6a7670fcdaf..953bda078dd 100644 --- a/lib/compiler-singlepass/src/codegen_x64.rs +++ b/lib/compiler-singlepass/src/codegen_x64.rs @@ -330,9 +330,9 @@ impl<'a> FuncGen<'a> { let tmp1 = self.machine.acquire_temp_xmm().unwrap(); let tmp2 = self.machine.acquire_temp_xmm().unwrap(); let tmp3 = self.machine.acquire_temp_xmm().unwrap(); - let tmpg1 = self.machine.acquire_temp_gpr().unwrap(); self.emit_relaxed_binop(Assembler::emit_mov, sz, input, Location::XMM(tmp1)); + let tmpg1 = self.machine.acquire_temp_gpr().unwrap(); match sz { Size::S32 => { diff --git a/tests/compilers/imports.rs b/tests/compilers/imports.rs index c66286b8277..b3222f4dd69 100644 --- a/tests/compilers/imports.rs +++ b/tests/compilers/imports.rs @@ -9,6 +9,9 @@ use std::sync::{ Arc, }; use wasmer::*; +#[cfg(feature = "singlepass")] +use wasmer_compiler_singlepass::Singlepass; +use wasmer_engine_universal::Universal; fn get_module(store: &Store) -> Result { let wat = r#" @@ -432,3 +435,27 @@ fn instance_local_memory_lifetime(config: crate::Config) -> Result<()> { Ok(()) } + +#[cfg(feature = "singlepass")] +#[test] +fn test_singlepass_emit_bug() -> Result<()> { + // https://github.com/wasmerio/wasmer/issues/2347 + let wat = r#"(module + (type (;0;) (func (param f64) (result i32))) + (func (;0;) (type 0) (param f64) (result i32) + unreachable) + (func (;1;) (type 0) (param f64) (result i32) + i32.const -16579585 + f64.convert_i32_s + f64.ceil + f64.ceil + local.get 0 + f64.copysign + unreachable)) + "#; + + let store = Store::new(&Universal::new(Singlepass::default()).engine()); + let module = Module::new(&store, wat)?; + + Ok(()) +} From 57edf702bfaef45165f593cf3237640900bdb0de Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 7 Jun 2021 20:23:27 +0800 Subject: [PATCH 2/4] refactor unitcase and add changelog --- CHANGELOG.md | 1 + tests/compilers/imports.rs | 27 --------------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9120d182bce..987ed89fb59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C - [#2157](https://github.com/wasmerio/wasmer/pull/2157) Simplify the code behind `WasmPtr` ### Fixed +- [#2391](https://github.com/wasmerio/wasmer/pull/2391) Fix Singlepass emit bug, [#2347](https://github.com/wasmerio/wasmer/issues/2347) and [#2159](https://github.com/wasmerio/wasmer/issues/2159) - [#2327](https://github.com/wasmerio/wasmer/pull/2327) Fix memory leak preventing internal instance memory from being freed when a WasmerEnv contained an exported extern (e.g. Memory, etc.). - [#2247](https://github.com/wasmerio/wasmer/pull/2247) Internal WasiFS logic updated to be closer to what WASI libc does when finding a preopened fd for a path. - [#2241](https://github.com/wasmerio/wasmer/pull/2241) Fix Undefined Behavior in setting memory in emscripten `EmEnv`. diff --git a/tests/compilers/imports.rs b/tests/compilers/imports.rs index b3222f4dd69..c66286b8277 100644 --- a/tests/compilers/imports.rs +++ b/tests/compilers/imports.rs @@ -9,9 +9,6 @@ use std::sync::{ Arc, }; use wasmer::*; -#[cfg(feature = "singlepass")] -use wasmer_compiler_singlepass::Singlepass; -use wasmer_engine_universal::Universal; fn get_module(store: &Store) -> Result { let wat = r#" @@ -435,27 +432,3 @@ fn instance_local_memory_lifetime(config: crate::Config) -> Result<()> { Ok(()) } - -#[cfg(feature = "singlepass")] -#[test] -fn test_singlepass_emit_bug() -> Result<()> { - // https://github.com/wasmerio/wasmer/issues/2347 - let wat = r#"(module - (type (;0;) (func (param f64) (result i32))) - (func (;0;) (type 0) (param f64) (result i32) - unreachable) - (func (;1;) (type 0) (param f64) (result i32) - i32.const -16579585 - f64.convert_i32_s - f64.ceil - f64.ceil - local.get 0 - f64.copysign - unreachable)) - "#; - - let store = Store::new(&Universal::new(Singlepass::default()).engine()); - let module = Module::new(&store, wat)?; - - Ok(()) -} From af59712ec1f99051ca72f13427ccb34b6bc34d96 Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 7 Jun 2021 20:25:42 +0800 Subject: [PATCH 3/4] add testcase --- tests/wast/wasmer/nan-canonicalization-bug1.wast | 14 ++++++++++++++ tests/wast/wasmer/nan-canonicalization-bug2.wast | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/wast/wasmer/nan-canonicalization-bug1.wast create mode 100644 tests/wast/wasmer/nan-canonicalization-bug2.wast diff --git a/tests/wast/wasmer/nan-canonicalization-bug1.wast b/tests/wast/wasmer/nan-canonicalization-bug1.wast new file mode 100644 index 00000000000..575d33c65d7 --- /dev/null +++ b/tests/wast/wasmer/nan-canonicalization-bug1.wast @@ -0,0 +1,14 @@ +;; https://github.com/wasmerio/wasmer/issues/2347 +(module + (type (;0;) (func (param f64) (result i32))) + (func (;0;) (type 0) (param f64) (result i32) + unreachable) + (func (;1;) (type 0) (param f64) (result i32) + i32.const -16579585 + f64.convert_i32_s + f64.ceil + f64.ceil + local.get 0 + f64.copysign + unreachable)) + \ No newline at end of file diff --git a/tests/wast/wasmer/nan-canonicalization-bug2.wast b/tests/wast/wasmer/nan-canonicalization-bug2.wast new file mode 100644 index 00000000000..6a1253ce26f --- /dev/null +++ b/tests/wast/wasmer/nan-canonicalization-bug2.wast @@ -0,0 +1,10 @@ +;; https://github.com/wasmerio/wasmer/issues/2159 +(module + (func (export "_start") (result f64) + f64.const 0x0p+0 (;=0;) + f64.const 0x0p+0 (;=0;) + f64.const 0x0p+0 (;=0;) + f64.div + f64.copysign + ) +) \ No newline at end of file From b99542b56b4c2cb6e74c90065afa7534ffd995db Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 8 Jun 2021 08:58:58 +0800 Subject: [PATCH 4/4] rename testcase file --- ...icalization-bug2.wast => nan-canonicalization-issue-2159.wast} | 0 ...icalization-bug1.wast => nan-canonicalization-issue-2347.wast} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/wast/wasmer/{nan-canonicalization-bug2.wast => nan-canonicalization-issue-2159.wast} (100%) rename tests/wast/wasmer/{nan-canonicalization-bug1.wast => nan-canonicalization-issue-2347.wast} (100%) diff --git a/tests/wast/wasmer/nan-canonicalization-bug2.wast b/tests/wast/wasmer/nan-canonicalization-issue-2159.wast similarity index 100% rename from tests/wast/wasmer/nan-canonicalization-bug2.wast rename to tests/wast/wasmer/nan-canonicalization-issue-2159.wast diff --git a/tests/wast/wasmer/nan-canonicalization-bug1.wast b/tests/wast/wasmer/nan-canonicalization-issue-2347.wast similarity index 100% rename from tests/wast/wasmer/nan-canonicalization-bug1.wast rename to tests/wast/wasmer/nan-canonicalization-issue-2347.wast