summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h3
-rw-r--r--test/use-import-and-drop.asm.js19
-rw-r--r--test/use-import-and-drop.fromasm7
-rw-r--r--test/use-import-and-drop.fromasm.imprecise6
-rw-r--r--test/use-import-and-drop.fromasm.imprecise.no-opts53
-rw-r--r--test/use-import-and-drop.fromasm.no-opts53
6 files changed, 140 insertions, 1 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index ccbf91c70..b952521ae 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -418,9 +418,10 @@ private:
previous->params.push_back(type->params[i]); // add a new param
}
}
+ // we accept none and a concrete type, but two concrete types mean we need to use an f64 to contain anything
if (previous->result == none) {
previous->result = type->result; // use a more concrete type
- } else if (previous->result != type->result) {
+ } else if (previous->result != type->result && type->result != none) {
previous->result = f64; // overloaded return type, make it a double
}
}
diff --git a/test/use-import-and-drop.asm.js b/test/use-import-and-drop.asm.js
new file mode 100644
index 000000000..57688ced9
--- /dev/null
+++ b/test/use-import-and-drop.asm.js
@@ -0,0 +1,19 @@
+Module["asm"] = (function(global, env, buffer) {
+ "use asm";
+ var setTempRet0=env.setTempRet0;
+ var Math_imul = global.Math.imul;
+ function test1() {
+ var $b$1 = 0, $x_sroa_0_0_extract_trunc = 0, $2 = 0, $1$1 = 0, $1$0 = 0;
+ // Here we use setTempRet0 as if it returns i32, and later as if no return value.
+ // We should *not* expand the return type to f64, as this is not an overloaded return value
+ return (setTempRet0((((Math_imul($b$1, $x_sroa_0_0_extract_trunc) | 0) + $2 | 0) + $1$1 | $1$1 & 0) | 0), 0 | $1$0 & -1) | 0;
+ }
+ function test2() {
+ setTempRet0(10);
+ }
+ return {
+ };
+});
+
+
+
diff --git a/test/use-import-and-drop.fromasm b/test/use-import-and-drop.fromasm
new file mode 100644
index 000000000..0fc6d78f7
--- /dev/null
+++ b/test/use-import-and-drop.fromasm
@@ -0,0 +1,7 @@
+(module
+ (import "env" "memory" (memory $0 256 256))
+ (import "env" "table" (table 0 0 anyfunc))
+ (import "env" "memoryBase" (global $memoryBase i32))
+ (import "env" "tableBase" (global $tableBase i32))
+ (data (get_global $memoryBase) "use-import-and-drop.asm.js")
+)
diff --git a/test/use-import-and-drop.fromasm.imprecise b/test/use-import-and-drop.fromasm.imprecise
new file mode 100644
index 000000000..cc8aa47c3
--- /dev/null
+++ b/test/use-import-and-drop.fromasm.imprecise
@@ -0,0 +1,6 @@
+(module
+ (import "env" "memory" (memory $0 256 256))
+ (import "env" "table" (table 0 0 anyfunc))
+ (import "env" "memoryBase" (global $memoryBase i32))
+ (import "env" "tableBase" (global $tableBase i32))
+)
diff --git a/test/use-import-and-drop.fromasm.imprecise.no-opts b/test/use-import-and-drop.fromasm.imprecise.no-opts
new file mode 100644
index 000000000..d7ca6c81d
--- /dev/null
+++ b/test/use-import-and-drop.fromasm.imprecise.no-opts
@@ -0,0 +1,53 @@
+(module
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
+ (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32)))
+ (import "env" "memory" (memory $0 256 256))
+ (import "env" "table" (table 0 0 anyfunc))
+ (import "env" "memoryBase" (global $memoryBase i32))
+ (import "env" "tableBase" (global $tableBase i32))
+ (func $test1 (result i32)
+ (local $$b$1 i32)
+ (local $$x_sroa_0_0_extract_trunc i32)
+ (local $$2 i32)
+ (local $$1$1 i32)
+ (local $$1$0 i32)
+ (return
+ (block i32
+ (drop
+ (call $setTempRet0
+ (i32.or
+ (i32.add
+ (i32.add
+ (i32.mul
+ (get_local $$b$1)
+ (get_local $$x_sroa_0_0_extract_trunc)
+ )
+ (get_local $$2)
+ )
+ (get_local $$1$1)
+ )
+ (i32.and
+ (get_local $$1$1)
+ (i32.const 0)
+ )
+ )
+ )
+ )
+ (i32.or
+ (i32.const 0)
+ (i32.and
+ (get_local $$1$0)
+ (i32.const -1)
+ )
+ )
+ )
+ )
+ )
+ (func $test2
+ (drop
+ (call $setTempRet0
+ (i32.const 10)
+ )
+ )
+ )
+)
diff --git a/test/use-import-and-drop.fromasm.no-opts b/test/use-import-and-drop.fromasm.no-opts
new file mode 100644
index 000000000..d7ca6c81d
--- /dev/null
+++ b/test/use-import-and-drop.fromasm.no-opts
@@ -0,0 +1,53 @@
+(module
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
+ (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32)))
+ (import "env" "memory" (memory $0 256 256))
+ (import "env" "table" (table 0 0 anyfunc))
+ (import "env" "memoryBase" (global $memoryBase i32))
+ (import "env" "tableBase" (global $tableBase i32))
+ (func $test1 (result i32)
+ (local $$b$1 i32)
+ (local $$x_sroa_0_0_extract_trunc i32)
+ (local $$2 i32)
+ (local $$1$1 i32)
+ (local $$1$0 i32)
+ (return
+ (block i32
+ (drop
+ (call $setTempRet0
+ (i32.or
+ (i32.add
+ (i32.add
+ (i32.mul
+ (get_local $$b$1)
+ (get_local $$x_sroa_0_0_extract_trunc)
+ )
+ (get_local $$2)
+ )
+ (get_local $$1$1)
+ )
+ (i32.and
+ (get_local $$1$1)
+ (i32.const 0)
+ )
+ )
+ )
+ )
+ (i32.or
+ (i32.const 0)
+ (i32.and
+ (get_local $$1$0)
+ (i32.const -1)
+ )
+ )
+ )
+ )
+ )
+ (func $test2
+ (drop
+ (call $setTempRet0
+ (i32.const 10)
+ )
+ )
+ )
+)