diff options
-rw-r--r-- | src/asm2wasm.h | 10 | ||||
-rw-r--r-- | test/unit.asm.js | 12 | ||||
-rw-r--r-- | test/unit.fromasm | 14 | ||||
-rw-r--r-- | test/unit.fromasm.clamp | 14 | ||||
-rw-r--r-- | test/unit.fromasm.clamp.no-opts | 28 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 14 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise.no-opts | 28 | ||||
-rw-r--r-- | test/unit.fromasm.no-opts | 28 |
8 files changed, 134 insertions, 14 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 2fbe4d0ae..6327920fe 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -478,8 +478,14 @@ private: } FunctionType* getFunctionType(Ref parent, ExpressionList& operands) { - // generate signature - WasmType result = !!parent ? detectWasmType(parent, nullptr) : none; + WasmType result = none; + if (!!parent) { + // if the parent is a seq, we cannot be the last element in it (we would have a coercion, which would be + // the parent), so we must be (us, somethingElse), and so our return is void + if (parent[0] != SEQ) { + result = detectWasmType(parent, nullptr); + } + } return ensureFunctionType(getSig(result, operands), &wasm); } diff --git a/test/unit.asm.js b/test/unit.asm.js index ebde4d398..0bd0ab21b 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -703,11 +703,18 @@ function asm(global, env, buffer) { return x | 0; } + function indirectInSequence() { + var i1 = 0; + // this indirect call should have the right type, vi + i1 = (FUNCTION_TABLE_vi[1 & 7](0), 1); + } + function keepAlive() { sqrts(3.14159); f2u(100.0); f2s(100.0); autoDrop(52) | 0; + indirectInSequence(); } function v() { @@ -715,11 +722,16 @@ function asm(global, env, buffer) { function vi(x) { x = x | 0; } + function ii(x) { + x = x | 0; + return x | 0; + } var FUNCTION_TABLE_a = [ v, big_negative, v, v ]; var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ]; var FUNCTION_TABLE_c = [ z, cneg, z, z, z, z, z, z ]; var FUNCTION_TABLE_vi = [ vi, vi, vi, vi, vi, vi, vi, vi ]; + var FUNCTION_TABLE_ii = [ ii ]; return { big_negative: big_negative, pick: forgetMe, pick: exportMe, doubleCompares: doubleCompares, intOps: intOps, conversions: conversions, switcher: switcher, frem: frem, big_uint_div_u: big_uint_div_u, fr: fr, negZero: negZero, neg: neg, smallCompare: smallCompare, cneg_nosemicolon: cneg_nosemicolon, forLoop: forLoop, ceiling_32_64: ceiling_32_64, aborts: aborts, continues: continues, bitcasts: bitcasts, recursiveBlockMerging: recursiveBlockMerging, lb: lb, zeroInit: zeroInit, phi: phi, smallIf: smallIf, dropCall: dropCall, useSetGlobal: useSetGlobal, usesSetGlobal2: usesSetGlobal2, breakThroughMany: breakThroughMany, ifChainEmpty: ifChainEmpty, heap8NoShift: heap8NoShift, conditionalTypeFun: conditionalTypeFun, loadSigned: loadSigned, globalOpts: globalOpts, dropCallImport: dropCallImport, loophi: loophi, loophi2: loophi2, relooperJumpThreading: relooperJumpThreading, relooperJumpThreading__ZN4game14preloadweaponsEv: relooperJumpThreading__ZN4game14preloadweaponsEv, __Z12multi_varargiz: __Z12multi_varargiz, jumpThreadDrop: jumpThreadDrop, dropIgnoredImportInIf: dropIgnoredImportInIf, dropIgnoredImportsInIf: dropIgnoredImportsInIf, relooperJumpThreading_irreducible: relooperJumpThreading_irreducible, store_fround: store_fround, exportedNumber: 42, relocatableAndModules: relocatableAndModules, exported_f32_user: exported_f32_user, keepAlive: keepAlive }; } diff --git a/test/unit.fromasm b/test/unit.fromasm index f0145265d..2b077edee 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -17,14 +17,14 @@ (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) - (import "env" "table" (table 24 24 anyfunc)) + (import "env" "table" (table 25 25 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (global $Int (mut i32) (i32.const 0)) (global $Double (mut f64) (f64.const 0)) (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $exportedNumber i32 (i32.const 42)) - (elem (get_global $tableBase) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi) + (elem (get_global $tableBase) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi $ii) (data (get_global $memoryBase) "unit.asm.js") (export "big_negative" (func $big_negative)) (export "pick" (func $big_negative)) @@ -1170,6 +1170,12 @@ ) (get_local $0) ) + (func $indirectInSequence + (call_indirect $FUNCSIG$vi + (i32.const 0) + (i32.const 17) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1191,10 +1197,14 @@ (i32.const 52) ) ) + (call $indirectInSequence) ) (func $vi (param $0 i32) (nop) ) + (func $ii (param $0 i32) (result i32) + (get_local $0) + ) (func $legalstub$fr (param $0 f64) (call $fr (f32.demote/f64 diff --git a/test/unit.fromasm.clamp b/test/unit.fromasm.clamp index f95accb61..34d95925d 100644 --- a/test/unit.fromasm.clamp +++ b/test/unit.fromasm.clamp @@ -15,14 +15,14 @@ (import "env" "return_int" (func $return_int (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) - (import "env" "table" (table 24 24 anyfunc)) + (import "env" "table" (table 25 25 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (global $Int (mut i32) (i32.const 0)) (global $Double (mut f64) (f64.const 0)) (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $exportedNumber i32 (i32.const 42)) - (elem (get_global $tableBase) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi) + (elem (get_global $tableBase) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi $ii) (data (get_global $memoryBase) "unit.asm.js") (export "big_negative" (func $big_negative)) (export "pick" (func $big_negative)) @@ -1194,6 +1194,12 @@ ) (get_local $0) ) + (func $indirectInSequence + (call_indirect $FUNCSIG$vi + (i32.const 0) + (i32.const 17) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1215,10 +1221,14 @@ (i32.const 52) ) ) + (call $indirectInSequence) ) (func $vi (param $0 i32) (nop) ) + (func $ii (param $0 i32) (result i32) + (get_local $0) + ) (func $legalstub$fr (param $0 f64) (call $fr (f32.demote/f64 diff --git a/test/unit.fromasm.clamp.no-opts b/test/unit.fromasm.clamp.no-opts index 4fddffd49..31aa0e384 100644 --- a/test/unit.fromasm.clamp.no-opts +++ b/test/unit.fromasm.clamp.no-opts @@ -19,7 +19,7 @@ (import "env" "return_int" (func $return_int (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) - (import "env" "table" (table 24 24 anyfunc)) + (import "env" "table" (table 25 25 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (global $t (mut f64) (get_global $t$asm2wasm$import)) @@ -30,7 +30,7 @@ (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) (global $exportedNumber i32 (i32.const 42)) - (elem (get_global $tableBase) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi) + (elem (get_global $tableBase) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi $ii) (export "big_negative" (func $big_negative)) (export "pick" (func $exportMe)) (export "doubleCompares" (func $doubleCompares)) @@ -1959,6 +1959,24 @@ (get_local $x) ) ) + (func $indirectInSequence + (local $i1 i32) + (set_local $i1 + (block i32 + (call_indirect $FUNCSIG$vi + (i32.const 0) + (i32.add + (i32.and + (i32.const 1) + (i32.const 7) + ) + (i32.const 16) + ) + ) + (i32.const 1) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1980,6 +1998,7 @@ (i32.const 52) ) ) + (call $indirectInSequence) ) (func $v (nop) @@ -1987,6 +2006,11 @@ (func $vi (param $x i32) (nop) ) + (func $ii (param $x i32) (result i32) + (return + (get_local $x) + ) + ) (func $legalstub$fr (param $0 f64) (call $fr (f32.demote/f64 diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 6cdab7aa0..b0f46e7ad 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -15,14 +15,14 @@ (import "env" "return_int" (func $return_int (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) - (import "env" "table" (table 24 24 anyfunc)) + (import "env" "table" (table 25 25 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (global $Int (mut i32) (i32.const 0)) (global $Double (mut f64) (f64.const 0)) (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $exportedNumber i32 (i32.const 42)) - (elem (get_global $tableBase) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi) + (elem (get_global $tableBase) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi $ii) (export "big_negative" (func $big_negative)) (export "pick" (func $big_negative)) (export "doubleCompares" (func $doubleCompares)) @@ -1143,6 +1143,12 @@ ) (get_local $0) ) + (func $indirectInSequence + (call_indirect $FUNCSIG$vi + (i32.const 0) + (i32.const 17) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1164,10 +1170,14 @@ (i32.const 52) ) ) + (call $indirectInSequence) ) (func $vi (param $0 i32) (nop) ) + (func $ii (param $0 i32) (result i32) + (get_local $0) + ) (func $legalstub$fr (param $0 f64) (call $fr (f32.demote/f64 diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index f49a6f29f..0e930990d 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -19,7 +19,7 @@ (import "env" "return_int" (func $return_int (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) - (import "env" "table" (table 24 24 anyfunc)) + (import "env" "table" (table 25 25 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (global $t (mut f64) (get_global $t$asm2wasm$import)) @@ -30,7 +30,7 @@ (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) (global $exportedNumber i32 (i32.const 42)) - (elem (get_global $tableBase) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi) + (elem (get_global $tableBase) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi $ii) (export "big_negative" (func $big_negative)) (export "pick" (func $exportMe)) (export "doubleCompares" (func $doubleCompares)) @@ -1919,6 +1919,24 @@ (get_local $x) ) ) + (func $indirectInSequence + (local $i1 i32) + (set_local $i1 + (block i32 + (call_indirect $FUNCSIG$vi + (i32.const 0) + (i32.add + (i32.and + (i32.const 1) + (i32.const 7) + ) + (i32.const 16) + ) + ) + (i32.const 1) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1940,6 +1958,7 @@ (i32.const 52) ) ) + (call $indirectInSequence) ) (func $v (nop) @@ -1947,6 +1966,11 @@ (func $vi (param $x i32) (nop) ) + (func $ii (param $x i32) (result i32) + (return + (get_local $x) + ) + ) (func $legalstub$fr (param $0 f64) (call $fr (f32.demote/f64 diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index 48b6426b6..32c854dd7 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -21,7 +21,7 @@ (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) - (import "env" "table" (table 24 24 anyfunc)) + (import "env" "table" (table 25 25 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) (import "env" "tableBase" (global $tableBase i32)) (global $t (mut f64) (get_global $t$asm2wasm$import)) @@ -32,7 +32,7 @@ (global $n (mut i32) (get_global $n$asm2wasm$import)) (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) (global $exportedNumber i32 (i32.const 42)) - (elem (get_global $tableBase) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi) + (elem (get_global $tableBase) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi $ii) (export "big_negative" (func $big_negative)) (export "pick" (func $exportMe)) (export "doubleCompares" (func $doubleCompares)) @@ -1935,6 +1935,24 @@ (get_local $x) ) ) + (func $indirectInSequence + (local $i1 i32) + (set_local $i1 + (block i32 + (call_indirect $FUNCSIG$vi + (i32.const 0) + (i32.add + (i32.and + (i32.const 1) + (i32.const 7) + ) + (i32.const 16) + ) + ) + (i32.const 1) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1956,6 +1974,7 @@ (i32.const 52) ) ) + (call $indirectInSequence) ) (func $v (nop) @@ -1963,6 +1982,11 @@ (func $vi (param $x i32) (nop) ) + (func $ii (param $x i32) (result i32) + (return + (get_local $x) + ) + ) (func $legalstub$fr (param $0 f64) (call $fr (f32.demote/f64 |