diff options
author | Heejin Ahn <aheejin@gmail.com> | 2021-03-01 10:30:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 10:30:00 +0900 |
commit | 7d453930f1b211baf324b1c010924d3709ff12ba (patch) | |
tree | 43773af4e683faecd10273b78a853b46bb6376a6 | |
parent | 0eb513d730b122f38bd6c66280c8acfe183b9b35 (diff) | |
download | binaryen-7d453930f1b211baf324b1c010924d3709ff12ba.tar.gz binaryen-7d453930f1b211baf324b1c010924d3709ff12ba.tar.bz2 binaryen-7d453930f1b211baf324b1c010924d3709ff12ba.zip |
Allow empty body within catch block (#3630)
Previously we assumed catch body's size should be at least 3: `catch`
keyword, event name, and body. But catch's body can be empty when the
event's type is none. This PR fixes the bug and allows empty catch
bodies to be parsed correctly.
Fixes #3629.
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 2 | ||||
-rw-r--r-- | test/exception-handling.wast | 7 | ||||
-rw-r--r-- | test/exception-handling.wast.from-wast | 43 | ||||
-rw-r--r-- | test/exception-handling.wast.fromBinary | 9 | ||||
-rw-r--r-- | test/exception-handling.wast.fromBinary.noDebugInfo | 9 |
5 files changed, 52 insertions, 18 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index edf8ec6f0..3874bd2c0 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2237,7 +2237,7 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) { while (i < s.size() && elementStartsWith(*s[i], "catch")) { Element& inner = *s[i++]; - if (inner.size() < 3) { + if (inner.size() < 2) { throw ParseException("invalid catch block", inner.line, inner.col); } Name event = getEventName(*inner[1]); diff --git a/test/exception-handling.wast b/test/exception-handling.wast index 45cb21910..833010e73 100644 --- a/test/exception-handling.wast +++ b/test/exception-handling.wast @@ -2,6 +2,7 @@ (event $e-i32 (attr 0) (param i32)) (event $e-i64 (attr 0) (param i64)) (event $e-i32-i64 (attr 0) (param i32 i64)) + (event $e-empty (attr 0)) (func $foo) (func $bar) @@ -188,6 +189,12 @@ ) (delegate 0) ) + + ;; 'catch' body can be empty when the event's type is none. + (try + (do) + (catch $e-empty) + ) ) (func $rethrow-test diff --git a/test/exception-handling.wast.from-wast b/test/exception-handling.wast.from-wast index c397edcd8..6d997c521 100644 --- a/test/exception-handling.wast.from-wast +++ b/test/exception-handling.wast.from-wast @@ -6,6 +6,7 @@ (event $e-i32 (attr 0) (param i32)) (event $e-i64 (attr 0) (param i64)) (event $e-i32-i64 (attr 0) (param i32 i64)) + (event $e-empty (attr 0) (param)) (func $foo (nop) ) @@ -226,6 +227,14 @@ ) (delegate 0) ) + (try $try17 + (do + (nop) + ) + (catch $e-empty + (nop) + ) + ) ) (func $rethrow-test (try $l0 @@ -242,8 +251,8 @@ (rethrow $l0) ) ) - (block $l018 - (try $l017 + (block $l019 + (try $l018 (do (call $foo) ) @@ -251,14 +260,14 @@ (drop (pop i32) ) - (rethrow $l017) + (rethrow $l018) ) (catch_all - (br $l018) + (br $l019) ) ) ) - (try $l019 + (try $l020 (do (call $foo) ) @@ -271,20 +280,20 @@ (drop (pop i32) ) - (rethrow $l019) + (rethrow $l020) ) (catch_all - (rethrow $l019) + (rethrow $l020) ) ) ) ) - (try $l020 + (try $l021 (do (call $foo) ) (catch_all - (try $try21 + (try $try22 (do (call $foo) ) @@ -293,25 +302,25 @@ (pop i32) ) (block $b0 - (rethrow $l020) + (rethrow $l021) ) ) (catch_all (block $b1 - (rethrow $l020) + (rethrow $l021) ) ) ) ) ) - (try $l022 + (try $l023 (do (call $foo) ) (catch_all - (try $try23 + (try $try24 (do - (rethrow $l022) + (rethrow $l023) ) (catch_all (nop) @@ -319,14 +328,14 @@ ) ) ) - (try $l024 + (try $l025 (do (call $foo) ) (catch_all - (try $try25 + (try $try26 (do - (rethrow $l024) + (rethrow $l025) ) (catch_all (nop) diff --git a/test/exception-handling.wast.fromBinary b/test/exception-handling.wast.fromBinary index afb9da9ac..851ec0eb4 100644 --- a/test/exception-handling.wast.fromBinary +++ b/test/exception-handling.wast.fromBinary @@ -6,6 +6,7 @@ (event $event$0 (attr 0) (param i32)) (event $event$1 (attr 0) (param i64)) (event $event$2 (attr 0) (param i32 i64)) + (event $event$3 (attr 0) (param)) (func $foo (nop) ) @@ -257,6 +258,14 @@ ) (delegate 0) ) + (try $label$28 + (do + (nop) + ) + (catch $event$3 + (nop) + ) + ) ) (func $rethrow-test (try $label$3 diff --git a/test/exception-handling.wast.fromBinary.noDebugInfo b/test/exception-handling.wast.fromBinary.noDebugInfo index 19ac444fc..3ec4a690c 100644 --- a/test/exception-handling.wast.fromBinary.noDebugInfo +++ b/test/exception-handling.wast.fromBinary.noDebugInfo @@ -6,6 +6,7 @@ (event $event$0 (attr 0) (param i32)) (event $event$1 (attr 0) (param i64)) (event $event$2 (attr 0) (param i32 i64)) + (event $event$3 (attr 0) (param)) (func $0 (nop) ) @@ -257,6 +258,14 @@ ) (delegate 0) ) + (try $label$28 + (do + (nop) + ) + (catch $event$3 + (nop) + ) + ) ) (func $4 (try $label$3 |