diff options
-rw-r--r-- | src/asm2wasm.h | 4 | ||||
-rw-r--r-- | test/unreachable-import_wasm-only.asm.js | 107 | ||||
-rw-r--r-- | test/unreachable-import_wasm-only.fromasm | 19 | ||||
-rw-r--r-- | test/unreachable-import_wasm-only.fromasm.imprecise | 18 | ||||
-rw-r--r-- | test/unreachable-import_wasm-only.fromasm.imprecise.no-opts | 87 | ||||
-rw-r--r-- | test/unreachable-import_wasm-only.fromasm.no-opts | 87 |
6 files changed, 321 insertions, 1 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index f7f084376..d8a2053be 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -960,7 +960,9 @@ void Asm2WasmBuilder::processAsm(Ref ast) { val->type = val->value.type = type->params[i]; curr->operands.push_back(val); } else if (curr->operands[i]->type != type->params[i]) { - assert(type->params[i] == f64); + // if the param is used, then we have overloading here and the combined type must be f64; + // if this is an unreachable param, then it doesn't matter. + assert(type->params[i] == f64 || curr->operands[i]->type == unreachable); // overloaded, upgrade to f64 switch (curr->operands[i]->type) { case i32: curr->operands[i] = parent->builder.makeUnary(ConvertSInt32ToFloat64, curr->operands[i]); break; diff --git a/test/unreachable-import_wasm-only.asm.js b/test/unreachable-import_wasm-only.asm.js new file mode 100644 index 000000000..9df74a192 --- /dev/null +++ b/test/unreachable-import_wasm-only.asm.js @@ -0,0 +1,107 @@ +function asm(global, env, buffer) { + "use asm"; + + var HEAP8 = new global.Int8Array(buffer); + var HEAP16 = new global.Int16Array(buffer); + var HEAP32 = new global.Int32Array(buffer); + var HEAPU8 = new global.Uint8Array(buffer); + var HEAPU16 = new global.Uint16Array(buffer); + var HEAPU32 = new global.Uint32Array(buffer); + var HEAPF32 = new global.Float32Array(buffer); + var HEAPF64 = new global.Float64Array(buffer); + + var DYNAMICTOP_PTR=env.DYNAMICTOP_PTR|0; + var tempDoublePtr=env.tempDoublePtr|0; + var ABORT=env.ABORT|0; + var STACKTOP=env.STACKTOP|0; + var STACK_MAX=env.STACK_MAX|0; + var ___async=env.___async|0; + var ___async_unwind=env.___async_unwind|0; + var ___async_retval=env.___async_retval|0; + var ___async_cur_frame=env.___async_cur_frame|0; + + var __THREW__ = 0; + var threwValue = 0; + var setjmpId = 0; + var undef = 0; + var nan = global.NaN, inf = global.Infinity; + var tempInt = 0, tempBigInt = 0, tempBigIntP = 0, tempBigIntS = 0, tempBigIntR = 0.0, tempBigIntI = 0, tempBigIntD = 0, tempValue = 0, tempDouble = 0.0; + var tempRet0 = 0; + + var Math_floor=global.Math.floor; + var Math_abs=global.Math.abs; + var Math_sqrt=global.Math.sqrt; + var Math_pow=global.Math.pow; + var Math_cos=global.Math.cos; + var Math_sin=global.Math.sin; + var Math_tan=global.Math.tan; + var Math_acos=global.Math.acos; + var Math_asin=global.Math.asin; + var Math_atan=global.Math.atan; + var Math_atan2=global.Math.atan2; + var Math_exp=global.Math.exp; + var Math_log=global.Math.log; + var Math_ceil=global.Math.ceil; + var Math_imul=global.Math.imul; + var Math_min=global.Math.min; + var Math_max=global.Math.max; + var Math_clz32=global.Math.clz32; + var Math_fround=global.Math.fround; + var abort=env.abort; + var assert=env.assert; + var enlargeMemory=env.enlargeMemory; + var getTotalMemory=env.getTotalMemory; + var abortOnCannotGrowMemory=env.abortOnCannotGrowMemory; + var invoke_iiii=env.invoke_iiii; + var invoke_viiiii=env.invoke_viiiii; + var invoke_vi=env.invoke_vi; + var invoke_ii=env.invoke_ii; + var invoke_v=env.invoke_v; + var invoke_viiiiii=env.invoke_viiiiii; + var invoke_viiii=env.invoke_viiii; + var _pthread_cleanup_pop=env._pthread_cleanup_pop; + var _pthread_key_create=env._pthread_key_create; + var ___syscall6=env.___syscall6; + var ___gxx_personality_v0=env.___gxx_personality_v0; + var ___assert_fail=env.___assert_fail; + var ___cxa_allocate_exception=env.___cxa_allocate_exception; + var __ZSt18uncaught_exceptionv=env.__ZSt18uncaught_exceptionv; + var ___setErrNo=env.___setErrNo; + var ___cxa_begin_catch=env.___cxa_begin_catch; + var _emscripten_memcpy_big=env._emscripten_memcpy_big; + var ___resumeException=env.___resumeException; + var ___cxa_find_matching_catch=env.___cxa_find_matching_catch; + var _pthread_getspecific=env._pthread_getspecific; + var _pthread_once=env._pthread_once; + var ___syscall54=env.___syscall54; + var ___unlock=env.___unlock; + var _pthread_setspecific=env._pthread_setspecific; + var ___cxa_throw=env.___cxa_throw; + var ___lock=env.___lock; + var _abort=env._abort; + var _pthread_cleanup_push=env._pthread_cleanup_push; + var ___syscall140=env.___syscall140; + var ___cxa_pure_virtual=env.___cxa_pure_virtual; + var ___syscall146=env.___syscall146; + var tempFloat = Math_fround(0); + const f0 = Math_fround(0); + +function __ZN10WasmAssertC2Ev__async_cb($0) { + $0 = $0|0; + switch (0) { + case 0: { + store4(12,26); + return; + break; + } + default: { + $0 = (___cxa_allocate_exception(4)|0); + store4($0,1); + ___cxa_throw(($0|0),(1280|0),(0|0)); + } + } +} + + return { __ZN10WasmAssertC2Ev__async_cb: __ZN10WasmAssertC2Ev__async_cb }; +} + diff --git a/test/unreachable-import_wasm-only.fromasm b/test/unreachable-import_wasm-only.fromasm new file mode 100644 index 000000000..22e2e4826 --- /dev/null +++ b/test/unreachable-import_wasm-only.fromasm @@ -0,0 +1,19 @@ +(module + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (import "env" "___cxa_throw" (func $___cxa_throw (param i32 i32 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)) + (data (get_global $memoryBase) "unreachable-import_wasm-only.asm.js") + (export "__ZN10WasmAssertC2Ev__async_cb" (func $__ZN10WasmAssertC2Ev__async_cb)) + (func $__ZN10WasmAssertC2Ev__async_cb (param $0 i32) + (block $switch-default + (i32.store + (i32.const 12) + (i32.const 26) + ) + (return) + ) + ) +) diff --git a/test/unreachable-import_wasm-only.fromasm.imprecise b/test/unreachable-import_wasm-only.fromasm.imprecise new file mode 100644 index 000000000..6c982299a --- /dev/null +++ b/test/unreachable-import_wasm-only.fromasm.imprecise @@ -0,0 +1,18 @@ +(module + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (import "env" "___cxa_throw" (func $___cxa_throw (param i32 i32 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)) + (export "__ZN10WasmAssertC2Ev__async_cb" (func $__ZN10WasmAssertC2Ev__async_cb)) + (func $__ZN10WasmAssertC2Ev__async_cb (param $0 i32) + (block $switch-default + (i32.store + (i32.const 12) + (i32.const 26) + ) + (return) + ) + ) +) diff --git a/test/unreachable-import_wasm-only.fromasm.imprecise.no-opts b/test/unreachable-import_wasm-only.fromasm.imprecise.no-opts new file mode 100644 index 000000000..ad60bb6fd --- /dev/null +++ b/test/unreachable-import_wasm-only.fromasm.imprecise.no-opts @@ -0,0 +1,87 @@ +(module + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (import "env" "DYNAMICTOP_PTR" (global $DYNAMICTOP_PTR$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "___async" (global $___async$asm2wasm$import i32)) + (import "env" "___async_unwind" (global $___async_unwind$asm2wasm$import i32)) + (import "env" "___async_retval" (global $___async_retval$asm2wasm$import i32)) + (import "env" "___async_cur_frame" (global $___async_cur_frame$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) + (import "env" "___cxa_allocate_exception" (func $___cxa_allocate_exception (param i32) (result i32))) + (import "env" "___cxa_throw" (func $___cxa_throw (param i32 i32 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)) + (global $DYNAMICTOP_PTR (mut i32) (get_global $DYNAMICTOP_PTR$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $___async (mut i32) (get_global $___async$asm2wasm$import)) + (global $___async_unwind (mut i32) (get_global $___async_unwind$asm2wasm$import)) + (global $___async_retval (mut i32) (get_global $___async_retval$asm2wasm$import)) + (global $___async_cur_frame (mut i32) (get_global $___async_cur_frame$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempFloat (mut f32) (f32.const 0)) + (global $f0 (mut f32) (f32.const 0)) + (export "__ZN10WasmAssertC2Ev__async_cb" (func $__ZN10WasmAssertC2Ev__async_cb)) + (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) + (block $switch + (block $switch-default + (block $switch-case + (br_table $switch-case $switch-default + (i32.sub + (i32.const 0) + (i32.const 0) + ) + ) + ) + (block + (i32.store + (i32.const 12) + (i32.const 26) + ) + (return) + (br $switch) + ) + ) + (block + (set_local $$0 + (call $___cxa_allocate_exception + (i32.const 4) + ) + ) + (i32.store + (get_local $$0) + (i32.const 1) + ) + (call $___cxa_throw + (get_local $$0) + (i32.const 1280) + (i32.const 0) + ) + ) + ) + ) +) diff --git a/test/unreachable-import_wasm-only.fromasm.no-opts b/test/unreachable-import_wasm-only.fromasm.no-opts new file mode 100644 index 000000000..ad60bb6fd --- /dev/null +++ b/test/unreachable-import_wasm-only.fromasm.no-opts @@ -0,0 +1,87 @@ +(module + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (import "env" "DYNAMICTOP_PTR" (global $DYNAMICTOP_PTR$asm2wasm$import i32)) + (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) + (import "env" "ABORT" (global $ABORT$asm2wasm$import i32)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) + (import "env" "___async" (global $___async$asm2wasm$import i32)) + (import "env" "___async_unwind" (global $___async_unwind$asm2wasm$import i32)) + (import "env" "___async_retval" (global $___async_retval$asm2wasm$import i32)) + (import "env" "___async_cur_frame" (global $___async_cur_frame$asm2wasm$import i32)) + (import "global" "NaN" (global $nan$asm2wasm$import f64)) + (import "global" "Infinity" (global $inf$asm2wasm$import f64)) + (import "env" "___cxa_allocate_exception" (func $___cxa_allocate_exception (param i32) (result i32))) + (import "env" "___cxa_throw" (func $___cxa_throw (param i32 i32 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)) + (global $DYNAMICTOP_PTR (mut i32) (get_global $DYNAMICTOP_PTR$asm2wasm$import)) + (global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import)) + (global $ABORT (mut i32) (get_global $ABORT$asm2wasm$import)) + (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import)) + (global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import)) + (global $___async (mut i32) (get_global $___async$asm2wasm$import)) + (global $___async_unwind (mut i32) (get_global $___async_unwind$asm2wasm$import)) + (global $___async_retval (mut i32) (get_global $___async_retval$asm2wasm$import)) + (global $___async_cur_frame (mut i32) (get_global $___async_cur_frame$asm2wasm$import)) + (global $__THREW__ (mut i32) (i32.const 0)) + (global $threwValue (mut i32) (i32.const 0)) + (global $setjmpId (mut i32) (i32.const 0)) + (global $undef (mut i32) (i32.const 0)) + (global $nan (mut f64) (get_global $nan$asm2wasm$import)) + (global $inf (mut f64) (get_global $inf$asm2wasm$import)) + (global $tempInt (mut i32) (i32.const 0)) + (global $tempBigInt (mut i32) (i32.const 0)) + (global $tempBigIntP (mut i32) (i32.const 0)) + (global $tempBigIntS (mut i32) (i32.const 0)) + (global $tempBigIntR (mut f64) (f64.const 0)) + (global $tempBigIntI (mut i32) (i32.const 0)) + (global $tempBigIntD (mut i32) (i32.const 0)) + (global $tempValue (mut i32) (i32.const 0)) + (global $tempDouble (mut f64) (f64.const 0)) + (global $tempRet0 (mut i32) (i32.const 0)) + (global $tempFloat (mut f32) (f32.const 0)) + (global $f0 (mut f32) (f32.const 0)) + (export "__ZN10WasmAssertC2Ev__async_cb" (func $__ZN10WasmAssertC2Ev__async_cb)) + (func $__ZN10WasmAssertC2Ev__async_cb (param $$0 i32) + (block $switch + (block $switch-default + (block $switch-case + (br_table $switch-case $switch-default + (i32.sub + (i32.const 0) + (i32.const 0) + ) + ) + ) + (block + (i32.store + (i32.const 12) + (i32.const 26) + ) + (return) + (br $switch) + ) + ) + (block + (set_local $$0 + (call $___cxa_allocate_exception + (i32.const 4) + ) + ) + (i32.store + (get_local $$0) + (i32.const 1) + ) + (call $___cxa_throw + (get_local $$0) + (i32.const 1280) + (i32.const 0) + ) + ) + ) + ) +) |