summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-10 20:31:58 -0700
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-11 11:07:46 -0700
commitb2445bf12b1ba96209b6ebece3806503411f1c94 (patch)
tree3573d04f7ea3645f5608a142ffd0219385dcd963
parent4be7ec00157250ca83b61a2e1885645c67c6369c (diff)
downloadbinaryen-b2445bf12b1ba96209b6ebece3806503411f1c94.tar.gz
binaryen-b2445bf12b1ba96209b6ebece3806503411f1c94.tar.bz2
binaryen-b2445bf12b1ba96209b6ebece3806503411f1c94.zip
changing a set to a tee or vice versa needs to take into account the value may be unreachable
-rw-r--r--src/asm2wasm.h2
-rw-r--r--src/wasm/wasm.cpp1
-rw-r--r--test/passes/simplify-locals-nostructure.txt4
-rw-r--r--test/passes/simplify-locals.txt9
-rw-r--r--test/passes/simplify-locals.wast11
5 files changed, 23 insertions, 4 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index b71561d4d..2245bd2b5 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -1984,9 +1984,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
// No wasm support, so use a temp local
ensureI32Temp();
auto set = allocator.alloc<SetLocal>();
- set->setTee(false);
set->index = function->getLocalIndex(I32_TEMP);
set->value = value;
+ set->setTee(false);
set->finalize();
auto get = [&]() {
auto ret = allocator.alloc<GetLocal>();
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 20b075fd1..4f5f46f0a 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -324,6 +324,7 @@ bool SetLocal::isTee() {
void SetLocal::setTee(bool is) {
if (is) type = value->type;
else type = none;
+ finalize(); // type may need to be unreachable
}
void SetLocal::finalize() {
diff --git a/test/passes/simplify-locals-nostructure.txt b/test/passes/simplify-locals-nostructure.txt
index 6857a4c7a..2cb942f43 100644
--- a/test/passes/simplify-locals-nostructure.txt
+++ b/test/passes/simplify-locals-nostructure.txt
@@ -64,8 +64,6 @@
)
(func $no-unreachable (type $0)
(local $x i32)
- (drop
- (unreachable)
- )
+ (unreachable)
)
)
diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals.txt
index 8c12c274a..2be81e8c6 100644
--- a/test/passes/simplify-locals.txt
+++ b/test/passes/simplify-locals.txt
@@ -866,4 +866,13 @@
)
)
)
+ (func $drop-tee-unreachable (type $FUNCSIG$v)
+ (local $x i32)
+ (tee_local $x
+ (unreachable)
+ )
+ (drop
+ (get_local $x)
+ )
+ )
)
diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals.wast
index 359620a18..534bd8883 100644
--- a/test/passes/simplify-locals.wast
+++ b/test/passes/simplify-locals.wast
@@ -860,4 +860,15 @@
)
(get_local $label)
)
+ (func $drop-tee-unreachable
+ (local $x i32)
+ (drop
+ (tee_local $x
+ (unreachable)
+ )
+ )
+ (drop
+ (get_local $x)
+ )
+ )
)