From 8e73ee0d79c03468ca764adfa4ef869e53dcdff6 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 14 May 2020 15:43:57 -0700 Subject: 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. --- src/wasm/wasm-s-parser.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') 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(); for (size_t i = 1; i < s.size(); i++) { ret->list.push_back(parseExpression(s[i])); -- cgit v1.2.3