diff options
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 15 | ||||
-rw-r--r-- | test/exception-handling.wast | 2 | ||||
-rw-r--r-- | test/passes/dce_all-features.txt | 3 | ||||
-rw-r--r-- | test/passes/dce_all-features.wast | 7 | ||||
-rw-r--r-- | test/passes/remove-unused-names_code-folding_all-features.wast | 1 | ||||
-rw-r--r-- | test/passes/remove-unused-names_optimize-instructions_all-features.wast | 1 | ||||
-rw-r--r-- | test/passes/rse_all-features.wast | 1 |
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)) |