summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-05-09 16:04:30 -0700
committerGitHub <noreply@github.com>2017-05-09 16:04:30 -0700
commit647271a97ac534320ef5477367d1eb511afdebd5 (patch)
tree5f8a31c217323fbc2128e5df4aa491abdc76dada
parent64aa81e0e9655cf16e3af65e1bbe98e7fc6cf974 (diff)
downloadbinaryen-647271a97ac534320ef5477367d1eb511afdebd5.tar.gz
binaryen-647271a97ac534320ef5477367d1eb511afdebd5.tar.bz2
binaryen-647271a97ac534320ef5477367d1eb511afdebd5.zip
fix autoDrop, now that we properly set block types, unreachable can easily happen, and autoDrop wasn't handling it (#1005)
-rw-r--r--src/ast_utils.h2
-rw-r--r--test/unit.asm.js15
-rw-r--r--test/unit.fromasm17
-rw-r--r--test/unit.fromasm.clamp17
-rw-r--r--test/unit.fromasm.clamp.no-opts39
-rw-r--r--test/unit.fromasm.imprecise17
-rw-r--r--test/unit.fromasm.imprecise.no-opts39
-rw-r--r--test/unit.fromasm.no-opts39
8 files changed, 184 insertions, 1 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index 17627d959..5a7c40630 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -426,7 +426,7 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop>> {
}
if (maybeDrop(curr->list.back())) {
reFinalize();
- assert(curr->type == none);
+ assert(curr->type == none || curr->type == unreachable);
}
}
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 9d5f40aea..ebde4d398 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -689,10 +689,25 @@ function asm(global, env, buffer) {
return (~~x) | 0;
}
+ function autoDrop(x) {
+ x = x | 0;
+ while (1) {
+ if ((x | 0) == 17) {
+ return 5;
+ autoDrop(1) | 0;
+ } else {
+ break;
+ x = autoDrop(2) | 0;
+ }
+ }
+ return x | 0;
+ }
+
function keepAlive() {
sqrts(3.14159);
f2u(100.0);
f2s(100.0);
+ autoDrop(52) | 0;
}
function v() {
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 580057f82..f0145265d 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -1158,6 +1158,18 @@
(get_local $0)
)
)
+ (func $autoDrop (param $0 i32) (result i32)
+ (if
+ (i32.eq
+ (get_local $0)
+ (i32.const 17)
+ )
+ (return
+ (i32.const 5)
+ )
+ )
+ (get_local $0)
+ )
(func $keepAlive
(drop
(call $sqrts
@@ -1174,6 +1186,11 @@
(f64.const 100)
)
)
+ (drop
+ (call $autoDrop
+ (i32.const 52)
+ )
+ )
)
(func $vi (param $0 i32)
(nop)
diff --git a/test/unit.fromasm.clamp b/test/unit.fromasm.clamp
index 7bfcdd531..f95accb61 100644
--- a/test/unit.fromasm.clamp
+++ b/test/unit.fromasm.clamp
@@ -1182,6 +1182,18 @@
(get_local $0)
)
)
+ (func $autoDrop (param $0 i32) (result i32)
+ (if
+ (i32.eq
+ (get_local $0)
+ (i32.const 17)
+ )
+ (return
+ (i32.const 5)
+ )
+ )
+ (get_local $0)
+ )
(func $keepAlive
(drop
(call $sqrts
@@ -1198,6 +1210,11 @@
(f64.const 100)
)
)
+ (drop
+ (call $autoDrop
+ (i32.const 52)
+ )
+ )
)
(func $vi (param $0 i32)
(nop)
diff --git a/test/unit.fromasm.clamp.no-opts b/test/unit.fromasm.clamp.no-opts
index d8fab1d25..4fddffd49 100644
--- a/test/unit.fromasm.clamp.no-opts
+++ b/test/unit.fromasm.clamp.no-opts
@@ -1925,6 +1925,40 @@
)
)
)
+ (func $autoDrop (param $x i32) (result i32)
+ (loop $while-in
+ (block $while-out
+ (if
+ (i32.eq
+ (get_local $x)
+ (i32.const 17)
+ )
+ (block
+ (return
+ (i32.const 5)
+ )
+ (drop
+ (call $autoDrop
+ (i32.const 1)
+ )
+ )
+ )
+ (block
+ (br $while-out)
+ (set_local $x
+ (call $autoDrop
+ (i32.const 2)
+ )
+ )
+ )
+ )
+ (br $while-in)
+ )
+ )
+ (return
+ (get_local $x)
+ )
+ )
(func $keepAlive
(drop
(call $sqrts
@@ -1941,6 +1975,11 @@
(f64.const 100)
)
)
+ (drop
+ (call $autoDrop
+ (i32.const 52)
+ )
+ )
)
(func $v
(nop)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index f78f530c1..6cdab7aa0 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -1131,6 +1131,18 @@
(get_local $0)
)
)
+ (func $autoDrop (param $0 i32) (result i32)
+ (if
+ (i32.eq
+ (get_local $0)
+ (i32.const 17)
+ )
+ (return
+ (i32.const 5)
+ )
+ )
+ (get_local $0)
+ )
(func $keepAlive
(drop
(call $sqrts
@@ -1147,6 +1159,11 @@
(f64.const 100)
)
)
+ (drop
+ (call $autoDrop
+ (i32.const 52)
+ )
+ )
)
(func $vi (param $0 i32)
(nop)
diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts
index 736f51222..f49a6f29f 100644
--- a/test/unit.fromasm.imprecise.no-opts
+++ b/test/unit.fromasm.imprecise.no-opts
@@ -1885,6 +1885,40 @@
)
)
)
+ (func $autoDrop (param $x i32) (result i32)
+ (loop $while-in
+ (block $while-out
+ (if
+ (i32.eq
+ (get_local $x)
+ (i32.const 17)
+ )
+ (block
+ (return
+ (i32.const 5)
+ )
+ (drop
+ (call $autoDrop
+ (i32.const 1)
+ )
+ )
+ )
+ (block
+ (br $while-out)
+ (set_local $x
+ (call $autoDrop
+ (i32.const 2)
+ )
+ )
+ )
+ )
+ (br $while-in)
+ )
+ )
+ (return
+ (get_local $x)
+ )
+ )
(func $keepAlive
(drop
(call $sqrts
@@ -1901,6 +1935,11 @@
(f64.const 100)
)
)
+ (drop
+ (call $autoDrop
+ (i32.const 52)
+ )
+ )
)
(func $v
(nop)
diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts
index 3b80ebe1b..48b6426b6 100644
--- a/test/unit.fromasm.no-opts
+++ b/test/unit.fromasm.no-opts
@@ -1901,6 +1901,40 @@
)
)
)
+ (func $autoDrop (param $x i32) (result i32)
+ (loop $while-in
+ (block $while-out
+ (if
+ (i32.eq
+ (get_local $x)
+ (i32.const 17)
+ )
+ (block
+ (return
+ (i32.const 5)
+ )
+ (drop
+ (call $autoDrop
+ (i32.const 1)
+ )
+ )
+ )
+ (block
+ (br $while-out)
+ (set_local $x
+ (call $autoDrop
+ (i32.const 2)
+ )
+ )
+ )
+ )
+ (br $while-in)
+ )
+ )
+ (return
+ (get_local $x)
+ )
+ )
(func $keepAlive
(drop
(call $sqrts
@@ -1917,6 +1951,11 @@
(f64.const 100)
)
)
+ (drop
+ (call $autoDrop
+ (i32.const 52)
+ )
+ )
)
(func $v
(nop)