diff options
-rw-r--r-- | src/wasm-builder.h | 4 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 4 | ||||
-rw-r--r-- | test/passes/simplify-locals.txt | 16 | ||||
-rw-r--r-- | test/passes/simplify-locals.wast | 13 |
4 files changed, 34 insertions, 3 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 4ef4b1e0b..7432562d1 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -164,14 +164,14 @@ public: auto* ret = allocator.alloc<SetLocal>(); ret->index = index; ret->value = value; - ret->type = none; + ret->finalize(); return ret; } SetLocal* makeTeeLocal(Index index, Expression* value) { auto* ret = allocator.alloc<SetLocal>(); ret->index = index; ret->value = value; - ret->type = value->type; + ret->setTee(true); return ret; } GetGlobal* makeGetGlobal(Name name, WasmType type) { diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index f82a06e68..ab2db6bd5 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -332,6 +332,10 @@ void SetLocal::setTee(bool is) { void SetLocal::finalize() { if (value->type == unreachable) { type = unreachable; + } else if (isTee()) { + type = value->type; + } else { + type = none; } } diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals.txt index a46f74c69..39fc1d97d 100644 --- a/test/passes/simplify-locals.txt +++ b/test/passes/simplify-locals.txt @@ -9,6 +9,7 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $8 (func (param i32 i32))) (type $9 (func (param i32 i32 i32) (result i32))) + (type $10 (func (param i64))) (import "env" "waka" (func $waka)) (import "env" "waka_int" (func $waka_int (result i32))) (import "env" "i64sub" (func $_i64Subtract (param i32 i32 i32 i32) (result i32))) @@ -875,6 +876,21 @@ (get_local $x) ) ) + (func $if-return-but-unreachable (type $10) (param $var$0 i64) + (tee_local $var$0 + (if + (unreachable) + (block (result i64) + (nop) + (get_local $var$0) + ) + (block (result i64) + (nop) + (i64.const 1) + ) + ) + ) + ) ) (module (type $FUNCSIG$v (func)) diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals.wast index 344e0934e..eff5ff6be 100644 --- a/test/passes/simplify-locals.wast +++ b/test/passes/simplify-locals.wast @@ -871,6 +871,17 @@ (get_local $x) ) ) + (func $if-return-but-unreachable (param $var$0 i64) + (if + (unreachable) + (set_local $var$0 + (get_local $var$0) + ) + (set_local $var$0 + (i64.const 1) + ) + ) + ) ) (module (memory 256 256 shared) @@ -929,4 +940,4 @@ (drop (i32.atomic.load (i32.const 1028))) (drop (get_local $x)) ) -)
\ No newline at end of file +) |