diff options
-rw-r--r-- | src/asm2wasm.h | 8 | ||||
-rw-r--r-- | test/wasm-only.fromasm | 4 | ||||
-rw-r--r-- | test/wasm-only.fromasm.imprecise | 4 | ||||
-rw-r--r-- | test/wasm-only.fromasm.imprecise.no-opts | 4 | ||||
-rw-r--r-- | test/wasm-only.fromasm.no-opts | 4 |
5 files changed, 19 insertions, 5 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index f00004b1f..d9618d8fd 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -539,6 +539,12 @@ private: return call; } + Expression* truncateToInt32(Expression* value) { + if (value->type == i64) return builder.makeUnary(UnaryOp::WrapInt64, value); + // either i32, or a call_import whose type we don't know yet (but would be legalized to i32 anyhow) + return value; + } + Function* processFunction(Ref ast); }; @@ -1432,7 +1438,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { } else if (what == IF) { auto* condition = process(ast[1]); auto* ifTrue = process(ast[2]); - return builder.makeIf(condition, ifTrue, !!ast[3] ? process(ast[3]) : nullptr); + return builder.makeIf(truncateToInt32(condition), ifTrue, !!ast[3] ? process(ast[3]) : nullptr); } else if (what == CALL) { if (ast[1][0] == NAME) { IString name = ast[1][1]->getIString(); diff --git a/test/wasm-only.fromasm b/test/wasm-only.fromasm index e8f8cfc79..26d6cde4f 100644 --- a/test/wasm-only.fromasm +++ b/test/wasm-only.fromasm @@ -290,7 +290,9 @@ ) (func $ifValue64 (param $0 i64) (param $1 i64) (result i64) (if i64 - (get_local $1) + (i32.wrap/i64 + (get_local $1) + ) (call $call2 (get_local $0) ) diff --git a/test/wasm-only.fromasm.imprecise b/test/wasm-only.fromasm.imprecise index b27eb3f9b..ec74eb35b 100644 --- a/test/wasm-only.fromasm.imprecise +++ b/test/wasm-only.fromasm.imprecise @@ -218,7 +218,9 @@ ) (func $ifValue64 (param $0 i64) (param $1 i64) (result i64) (if i64 - (get_local $1) + (i32.wrap/i64 + (get_local $1) + ) (call $call2 (get_local $0) ) diff --git a/test/wasm-only.fromasm.imprecise.no-opts b/test/wasm-only.fromasm.imprecise.no-opts index 90a5eeccd..d9490bf9b 100644 --- a/test/wasm-only.fromasm.imprecise.no-opts +++ b/test/wasm-only.fromasm.imprecise.no-opts @@ -613,7 +613,9 @@ (local $$9 i64) (local $$10 i64) (if - (get_local $$6) + (i32.wrap/i64 + (get_local $$6) + ) (block (set_local $$9 (call $call2 diff --git a/test/wasm-only.fromasm.no-opts b/test/wasm-only.fromasm.no-opts index 1ea6753ef..1959a2937 100644 --- a/test/wasm-only.fromasm.no-opts +++ b/test/wasm-only.fromasm.no-opts @@ -661,7 +661,9 @@ (local $$9 i64) (local $$10 i64) (if - (get_local $$6) + (i32.wrap/i64 + (get_local $$6) + ) (block (set_local $$9 (call $call2 |