Skip to content

Commit 647271a

Browse files
authored
fix autoDrop, now that we properly set block types, unreachable can easily happen, and autoDrop wasn't handling it (#1005)
1 parent 64aa81e commit 647271a

8 files changed

+184
-1
lines changed

src/ast_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop>> {
426426
}
427427
if (maybeDrop(curr->list.back())) {
428428
reFinalize();
429-
assert(curr->type == none);
429+
assert(curr->type == none || curr->type == unreachable);
430430
}
431431
}
432432

test/unit.asm.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,25 @@ function asm(global, env, buffer) {
689689
return (~~x) | 0;
690690
}
691691

692+
function autoDrop(x) {
693+
x = x | 0;
694+
while (1) {
695+
if ((x | 0) == 17) {
696+
return 5;
697+
autoDrop(1) | 0;
698+
} else {
699+
break;
700+
x = autoDrop(2) | 0;
701+
}
702+
}
703+
return x | 0;
704+
}
705+
692706
function keepAlive() {
693707
sqrts(3.14159);
694708
f2u(100.0);
695709
f2s(100.0);
710+
autoDrop(52) | 0;
696711
}
697712

698713
function v() {

test/unit.fromasm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,18 @@
11581158
(get_local $0)
11591159
)
11601160
)
1161+
(func $autoDrop (param $0 i32) (result i32)
1162+
(if
1163+
(i32.eq
1164+
(get_local $0)
1165+
(i32.const 17)
1166+
)
1167+
(return
1168+
(i32.const 5)
1169+
)
1170+
)
1171+
(get_local $0)
1172+
)
11611173
(func $keepAlive
11621174
(drop
11631175
(call $sqrts
@@ -1174,6 +1186,11 @@
11741186
(f64.const 100)
11751187
)
11761188
)
1189+
(drop
1190+
(call $autoDrop
1191+
(i32.const 52)
1192+
)
1193+
)
11771194
)
11781195
(func $vi (param $0 i32)
11791196
(nop)

test/unit.fromasm.clamp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,18 @@
11821182
(get_local $0)
11831183
)
11841184
)
1185+
(func $autoDrop (param $0 i32) (result i32)
1186+
(if
1187+
(i32.eq
1188+
(get_local $0)
1189+
(i32.const 17)
1190+
)
1191+
(return
1192+
(i32.const 5)
1193+
)
1194+
)
1195+
(get_local $0)
1196+
)
11851197
(func $keepAlive
11861198
(drop
11871199
(call $sqrts
@@ -1198,6 +1210,11 @@
11981210
(f64.const 100)
11991211
)
12001212
)
1213+
(drop
1214+
(call $autoDrop
1215+
(i32.const 52)
1216+
)
1217+
)
12011218
)
12021219
(func $vi (param $0 i32)
12031220
(nop)

test/unit.fromasm.clamp.no-opts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,40 @@
19251925
)
19261926
)
19271927
)
1928+
(func $autoDrop (param $x i32) (result i32)
1929+
(loop $while-in
1930+
(block $while-out
1931+
(if
1932+
(i32.eq
1933+
(get_local $x)
1934+
(i32.const 17)
1935+
)
1936+
(block
1937+
(return
1938+
(i32.const 5)
1939+
)
1940+
(drop
1941+
(call $autoDrop
1942+
(i32.const 1)
1943+
)
1944+
)
1945+
)
1946+
(block
1947+
(br $while-out)
1948+
(set_local $x
1949+
(call $autoDrop
1950+
(i32.const 2)
1951+
)
1952+
)
1953+
)
1954+
)
1955+
(br $while-in)
1956+
)
1957+
)
1958+
(return
1959+
(get_local $x)
1960+
)
1961+
)
19281962
(func $keepAlive
19291963
(drop
19301964
(call $sqrts
@@ -1941,6 +1975,11 @@
19411975
(f64.const 100)
19421976
)
19431977
)
1978+
(drop
1979+
(call $autoDrop
1980+
(i32.const 52)
1981+
)
1982+
)
19441983
)
19451984
(func $v
19461985
(nop)

test/unit.fromasm.imprecise

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,18 @@
11311131
(get_local $0)
11321132
)
11331133
)
1134+
(func $autoDrop (param $0 i32) (result i32)
1135+
(if
1136+
(i32.eq
1137+
(get_local $0)
1138+
(i32.const 17)
1139+
)
1140+
(return
1141+
(i32.const 5)
1142+
)
1143+
)
1144+
(get_local $0)
1145+
)
11341146
(func $keepAlive
11351147
(drop
11361148
(call $sqrts
@@ -1147,6 +1159,11 @@
11471159
(f64.const 100)
11481160
)
11491161
)
1162+
(drop
1163+
(call $autoDrop
1164+
(i32.const 52)
1165+
)
1166+
)
11501167
)
11511168
(func $vi (param $0 i32)
11521169
(nop)

test/unit.fromasm.imprecise.no-opts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,40 @@
18851885
)
18861886
)
18871887
)
1888+
(func $autoDrop (param $x i32) (result i32)
1889+
(loop $while-in
1890+
(block $while-out
1891+
(if
1892+
(i32.eq
1893+
(get_local $x)
1894+
(i32.const 17)
1895+
)
1896+
(block
1897+
(return
1898+
(i32.const 5)
1899+
)
1900+
(drop
1901+
(call $autoDrop
1902+
(i32.const 1)
1903+
)
1904+
)
1905+
)
1906+
(block
1907+
(br $while-out)
1908+
(set_local $x
1909+
(call $autoDrop
1910+
(i32.const 2)
1911+
)
1912+
)
1913+
)
1914+
)
1915+
(br $while-in)
1916+
)
1917+
)
1918+
(return
1919+
(get_local $x)
1920+
)
1921+
)
18881922
(func $keepAlive
18891923
(drop
18901924
(call $sqrts
@@ -1901,6 +1935,11 @@
19011935
(f64.const 100)
19021936
)
19031937
)
1938+
(drop
1939+
(call $autoDrop
1940+
(i32.const 52)
1941+
)
1942+
)
19041943
)
19051944
(func $v
19061945
(nop)

test/unit.fromasm.no-opts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,40 @@
19011901
)
19021902
)
19031903
)
1904+
(func $autoDrop (param $x i32) (result i32)
1905+
(loop $while-in
1906+
(block $while-out
1907+
(if
1908+
(i32.eq
1909+
(get_local $x)
1910+
(i32.const 17)
1911+
)
1912+
(block
1913+
(return
1914+
(i32.const 5)
1915+
)
1916+
(drop
1917+
(call $autoDrop
1918+
(i32.const 1)
1919+
)
1920+
)
1921+
)
1922+
(block
1923+
(br $while-out)
1924+
(set_local $x
1925+
(call $autoDrop
1926+
(i32.const 2)
1927+
)
1928+
)
1929+
)
1930+
)
1931+
(br $while-in)
1932+
)
1933+
)
1934+
(return
1935+
(get_local $x)
1936+
)
1937+
)
19041938
(func $keepAlive
19051939
(drop
19061940
(call $sqrts
@@ -1917,6 +1951,11 @@
19171951
(f64.const 100)
19181952
)
19191953
)
1954+
(drop
1955+
(call $autoDrop
1956+
(i32.const 52)
1957+
)
1958+
)
19201959
)
19211960
(func $v
19221961
(nop)

0 commit comments

Comments
 (0)