summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-05-14 15:43:57 -0700
committerGitHub <noreply@github.com>2020-05-14 15:43:57 -0700
commit8e73ee0d79c03468ca764adfa4ef869e53dcdff6 (patch)
treebf98e7cf4455377d084659f14c6232581b616c7b
parent5db77a72a7c62d045e6650e96974fe1455fa1a1a (diff)
downloadbinaryen-8e73ee0d79c03468ca764adfa4ef869e53dcdff6.tar.gz
binaryen-8e73ee0d79c03468ca764adfa4ef869e53dcdff6.tar.bz2
binaryen-8e73ee0d79c03468ca764adfa4ef869e53dcdff6.zip
Make 'do' clause mandatory in 'try' (#2851)
Previously we were able to omit the new syntax `do` when `try` body is empty. This makes `do` clause mandatory, so when a `try` body is empty, the folded text format will be ``` (try (do) (catch ... ) ``` Suggested in https://github.com/WebAssembly/exception-handling/issues/52#issuecomment-626696720.
-rw-r--r--src/wasm/wasm-s-parser.cpp15
-rw-r--r--test/exception-handling.wast2
-rw-r--r--test/passes/dce_all-features.txt3
-rw-r--r--test/passes/dce_all-features.wast7
-rw-r--r--test/passes/remove-unused-names_code-folding_all-features.wast1
-rw-r--r--test/passes/remove-unused-names_optimize-instructions_all-features.wast1
-rw-r--r--test/passes/rse_all-features.wast1
7 files changed, 21 insertions, 9 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index eae03faa6..65351fe99 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1825,15 +1825,11 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) {
}
auto label = nameMapper.pushLabelName(sName);
Type type = parseOptionalResultType(s, i); // signature
- if (elementStartsWith(*s[i], "catch")) { // empty try body
- ret->body = makeNop();
- } else {
- if (!elementStartsWith(*s[i], "do")) {
- throw ParseException(
- "try body should start with 'do'", s[i]->line, s[i]->col);
- }
- ret->body = makeTryOrCatchBody(*s[i++], type, true);
+ if (!elementStartsWith(*s[i], "do")) {
+ throw ParseException(
+ "try body should start with 'do'", s[i]->line, s[i]->col);
}
+ ret->body = makeTryOrCatchBody(*s[i++], type, true);
if (!elementStartsWith(*s[i], "catch")) {
throw ParseException("catch clause does not exist", s[i]->line, s[i]->col);
}
@@ -1859,6 +1855,9 @@ SExpressionWasmBuilder::makeTryOrCatchBody(Element& s, Type type, bool isTry) {
if (!isTry && !elementStartsWith(s, "catch")) {
throw ParseException("invalid catch clause", s.line, s.col);
}
+ if (s.size() == 1) { // (do) or (catch) without instructions
+ return makeNop();
+ }
auto ret = allocator.alloc<Block>();
for (size_t i = 1; i < s.size(); i++) {
ret->list.push_back(parseExpression(s[i]));
diff --git a/test/exception-handling.wast b/test/exception-handling.wast
index 9681e234a..57766c2d3 100644
--- a/test/exception-handling.wast
+++ b/test/exception-handling.wast
@@ -40,6 +40,7 @@
;; Empty try body
(try
+ (do)
(catch
(drop (exnref.pop))
)
@@ -62,6 +63,7 @@
;; Test subtype relationship
(func $subtype_test
(try
+ (do)
(catch
(drop (exnref.pop))
(drop
diff --git a/test/passes/dce_all-features.txt b/test/passes/dce_all-features.txt
index be8f34c43..d1d116046 100644
--- a/test/passes/dce_all-features.txt
+++ b/test/passes/dce_all-features.txt
@@ -513,6 +513,9 @@
(unreachable)
)
(catch
+ (drop
+ (exnref.pop)
+ )
)
)
(call $foo)
diff --git a/test/passes/dce_all-features.wast b/test/passes/dce_all-features.wast
index 42d23829a..641211eab 100644
--- a/test/passes/dce_all-features.wast
+++ b/test/passes/dce_all-features.wast
@@ -746,13 +746,18 @@
(do
(unreachable)
)
- (catch)
+ (catch
+ (drop
+ (exnref.pop)
+ )
+ )
)
(call $foo) ;; shouldn't be dce'd
)
(func $catch_unreachable
(try
+ (do)
(catch
(unreachable)
)
diff --git a/test/passes/remove-unused-names_code-folding_all-features.wast b/test/passes/remove-unused-names_code-folding_all-features.wast
index f62714810..bbe05648b 100644
--- a/test/passes/remove-unused-names_code-folding_all-features.wast
+++ b/test/passes/remove-unused-names_code-folding_all-features.wast
@@ -1196,6 +1196,7 @@
(try
(do
(try
+ (do)
(catch
;; Expressions containing exnref.pop should NOT be taken out and
;; folded.
diff --git a/test/passes/remove-unused-names_optimize-instructions_all-features.wast b/test/passes/remove-unused-names_optimize-instructions_all-features.wast
index 1c39a9d84..119667f42 100644
--- a/test/passes/remove-unused-names_optimize-instructions_all-features.wast
+++ b/test/passes/remove-unused-names_optimize-instructions_all-features.wast
@@ -64,6 +64,7 @@
(try (result i32)
(do
(try
+ (do)
(catch
(drop (exnref.pop))
(throw $e (i32.const 0))
diff --git a/test/passes/rse_all-features.wast b/test/passes/rse_all-features.wast
index 307b614e0..0f5f72c17 100644
--- a/test/passes/rse_all-features.wast
+++ b/test/passes/rse_all-features.wast
@@ -291,6 +291,7 @@
(func $try1
(local $x i32)
(try
+ (do)
(catch
(drop (exnref.pop))
(local.set $x (i32.const 1))