Skip to content

Commit b2445bf

Browse files
committed
changing a set to a tee or vice versa needs to take into account the value may be unreachable
1 parent 4be7ec0 commit b2445bf

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/asm2wasm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,9 +1984,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
19841984
// No wasm support, so use a temp local
19851985
ensureI32Temp();
19861986
auto set = allocator.alloc<SetLocal>();
1987-
set->setTee(false);
19881987
set->index = function->getLocalIndex(I32_TEMP);
19891988
set->value = value;
1989+
set->setTee(false);
19901990
set->finalize();
19911991
auto get = [&]() {
19921992
auto ret = allocator.alloc<GetLocal>();

src/wasm/wasm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ bool SetLocal::isTee() {
324324
void SetLocal::setTee(bool is) {
325325
if (is) type = value->type;
326326
else type = none;
327+
finalize(); // type may need to be unreachable
327328
}
328329

329330
void SetLocal::finalize() {

test/passes/simplify-locals-nostructure.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
)
6565
(func $no-unreachable (type $0)
6666
(local $x i32)
67-
(drop
68-
(unreachable)
69-
)
67+
(unreachable)
7068
)
7169
)

test/passes/simplify-locals.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,4 +866,13 @@
866866
)
867867
)
868868
)
869+
(func $drop-tee-unreachable (type $FUNCSIG$v)
870+
(local $x i32)
871+
(tee_local $x
872+
(unreachable)
873+
)
874+
(drop
875+
(get_local $x)
876+
)
877+
)
869878
)

test/passes/simplify-locals.wast

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,4 +860,15 @@
860860
)
861861
(get_local $label)
862862
)
863+
(func $drop-tee-unreachable
864+
(local $x i32)
865+
(drop
866+
(tee_local $x
867+
(unreachable)
868+
)
869+
)
870+
(drop
871+
(get_local $x)
872+
)
873+
)
863874
)

0 commit comments

Comments
 (0)