summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2023-04-23 15:47:28 +0900
committerGitHub <noreply@github.com>2023-04-23 15:47:28 +0900
commit3dd36ab00f6eb117fafbcd0e55170ca2a3796c13 (patch)
tree1cdfdc8048781733eaebd15c1ad377c54c05d1e5
parentbd1822dde2b08c79c6e98667a5317194ca913545 (diff)
downloadbinaryen-3dd36ab00f6eb117fafbcd0e55170ca2a3796c13.tar.gz
binaryen-3dd36ab00f6eb117fafbcd0e55170ca2a3796c13.tar.bz2
binaryen-3dd36ab00f6eb117fafbcd0e55170ca2a3796c13.zip
[EH] Support assert_exception (#5684)
`assert_exception` is similar to `assert_trap` but for exceptions, which is supported in the interpreter of the EH proposal (https://github.com/WebAssembly/exception-handling/tree/main/interpreter). We've been using `assert_trap` for both traps and exceptions, but this PR distinguishes them.
-rw-r--r--src/tools/wasm-shell.cpp22
-rw-r--r--test/spec/exception-handling.wast14
2 files changed, 26 insertions, 10 deletions
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp
index 70f52a038..29ccc6c7f 100644
--- a/src/tools/wasm-shell.cpp
+++ b/src/tools/wasm-shell.cpp
@@ -35,6 +35,7 @@ using namespace wasm;
Name ASSERT_RETURN("assert_return");
Name ASSERT_TRAP("assert_trap");
+Name ASSERT_EXCEPTION("assert_exception");
Name ASSERT_INVALID("assert_invalid");
Name ASSERT_MALFORMED("assert_malformed");
Name ASSERT_UNLINKABLE("assert_unlinkable");
@@ -114,6 +115,8 @@ protected:
parseAssertReturn(s);
} else if (id == ASSERT_TRAP) {
parseAssertTrap(s);
+ } else if (id == ASSERT_EXCEPTION) {
+ parseAssertException(s);
} else if ((id == ASSERT_INVALID) || (id == ASSERT_MALFORMED)) {
parseModuleAssertion(s);
}
@@ -203,11 +206,24 @@ protected:
parseOperation(inner);
} catch (const TrapException&) {
trapped = true;
+ }
+ assert(trapped);
+ }
+
+ void parseAssertException(Element& s) {
+ [[maybe_unused]] bool thrown = false;
+ auto& inner = *s[1];
+ if (inner[0]->str() == MODULE) {
+ return parseModuleAssertion(s);
+ }
+
+ try {
+ parseOperation(inner);
} catch (const WasmException& e) {
std::cout << "[exception thrown: " << e << "]" << std::endl;
- trapped = true;
+ thrown = true;
}
- assert(trapped);
+ assert(thrown);
}
void parseAssertReturn(Element& s) {
@@ -284,7 +300,7 @@ protected:
ModuleUtils::iterImportedMemories(wasm, reportUnknownImport);
}
- if (!invalid && id == ASSERT_TRAP) {
+ if (!invalid && (id == ASSERT_TRAP || id == ASSERT_EXCEPTION)) {
try {
instantiate(&wasm);
} catch (const TrapException&) {
diff --git a/test/spec/exception-handling.wast b/test/spec/exception-handling.wast
index 4b817a81d..5ec78dfed 100644
--- a/test/spec/exception-handling.wast
+++ b/test/spec/exception-handling.wast
@@ -285,23 +285,23 @@
)
)
-(assert_trap (invoke "throw_single_value"))
-(assert_trap (invoke "throw_multiple_values"))
+(assert_exception (invoke "throw_single_value"))
+(assert_exception (invoke "throw_multiple_values"))
(assert_return (invoke "try_nothrow") (i32.const 3))
(assert_return (invoke "try_throw_catch") (i32.const 3))
-(assert_trap (invoke "try_throw_nocatch"))
+(assert_exception (invoke "try_throw_nocatch"))
(assert_return (invoke "try_throw_catchall") (i32.const 3))
(assert_return (invoke "try_call_catch") (i32.const 5))
(assert_return (invoke "try_throw_multivalue_catch") (i32.const 5))
-(assert_trap (invoke "try_throw_rethrow"))
-(assert_trap (invoke "try_call_rethrow"))
+(assert_exception (invoke "try_throw_rethrow"))
+(assert_exception (invoke "try_call_rethrow"))
(assert_return (invoke "rethrow_target_test1") (i32.const 2))
(assert_return (invoke "rethrow_target_test2") (i32.const 1))
(assert_return (invoke "rethrow_target_test3") (i32.const 1))
(assert_return (invoke "try_delegate_caught") (i32.const 3))
-(assert_trap (invoke "try_delegate_to_catchless_try"))
+(assert_exception (invoke "try_delegate_to_catchless_try"))
(assert_return (invoke "try_delegate_to_delegate") (i32.const 3))
-(assert_trap (invoke "try_delegate_to_caller"))
+(assert_exception (invoke "try_delegate_to_caller"))
(assert_invalid
(module