summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-validator.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-01-15 18:48:00 +0900
committerGitHub <noreply@github.com>2021-01-15 18:48:00 +0900
commitbeccdf70258cd99ea25f10af13103e14dc243ffa (patch)
tree1081d7d350fbab7f901b917f2f082c8d351c3157 /src/wasm/wasm-validator.cpp
parentf18c18e01d03d6d293fe3d701408855bbcea58bd (diff)
downloadbinaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.tar.gz
binaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.tar.bz2
binaryen-beccdf70258cd99ea25f10af13103e14dc243ffa.zip
Basic EH instrucion support for the new spec (#3487)
This updates `try`-`catch`-`catch_all` and `rethrow` instructions to match the new spec. `delegate` is not included. Now `Try` contains not a single `catchBody` expression but a vector of catch bodies and events. This updates most existing routines, optimizations, and tests modulo the interpreter and the CFG traversal. Because the interpreter has not been updated yet, the EH spec test is temporarily disabled in check.py. Also, because the CFG traversal for EH is not yet updated, several EH tests in `rse_all-features.wast`, which uses CFG traversal, are temporarily commented out. Also added a few more tests in existing EH test functions in test/passes. In the previous spec, `catch` was catching all exceptions so it was assumed that anything `try` body throws is caught by its `catch`, but now we can assume the same only if there is a `catch_all`. Newly added tests test cases when there is a `catch_all` and cases there are only `catch`es separately.
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r--src/wasm/wasm-validator.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index b0fc4d9c8..064a151c3 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -2026,21 +2026,28 @@ void FunctionValidator::visitTry(Try* curr) {
curr->type,
curr->body,
"try's type does not match try body's type");
- shouldBeSubTypeOrFirstIsUnreachable(
- curr->catchBody->type,
- curr->type,
- curr->catchBody,
- "try's type does not match catch's body type");
+ for (auto catchBody : curr->catchBodies) {
+ shouldBeSubTypeOrFirstIsUnreachable(
+ catchBody->type,
+ curr->type,
+ catchBody,
+ "try's type does not match catch's body type");
+ }
} else {
shouldBeEqual(curr->body->type,
Type(Type::unreachable),
curr,
"unreachable try-catch must have unreachable try body");
- shouldBeEqual(curr->catchBody->type,
- Type(Type::unreachable),
- curr,
- "unreachable try-catch must have unreachable catch body");
+ for (auto catchBody : curr->catchBodies) {
+ shouldBeEqual(catchBody->type,
+ Type(Type::unreachable),
+ curr,
+ "unreachable try-catch must have unreachable catch body");
+ }
}
+ shouldBeTrue(curr->catchBodies.size() - curr->catchEvents.size() <= 1,
+ curr,
+ "the number of catch blocks and events do not match");
}
void FunctionValidator::visitThrow(Throw* curr) {
@@ -2084,11 +2091,10 @@ void FunctionValidator::visitRethrow(Rethrow* curr) {
Type(Type::unreachable),
curr,
"rethrow's type must be unreachable");
- shouldBeSubTypeOrFirstIsUnreachable(
- curr->exnref->type,
- Type::exnref,
- curr->exnref,
- "rethrow's argument must be exnref type or its subtype");
+ // TODO Allow non-zero depths and Validate the depth field. The current LLVM
+ // toolchain only generates depth 0 for C++ support.
+ shouldBeEqual(
+ curr->depth, (Index)0, curr, "rethrow only support depth 0 at the moment");
}
void FunctionValidator::visitBrOnExn(BrOnExn* curr) {