diff options
author | Heejin Ahn <aheejin@gmail.com> | 2021-01-15 18:48:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 18:48:00 +0900 |
commit | beccdf70258cd99ea25f10af13103e14dc243ffa (patch) | |
tree | 1081d7d350fbab7f901b917f2f082c8d351c3157 /test/exception-handling.wast | |
parent | f18c18e01d03d6d293fe3d701408855bbcea58bd (diff) | |
download | binaryen-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 'test/exception-handling.wast')
-rw-r--r-- | test/exception-handling.wast | 92 |
1 files changed, 75 insertions, 17 deletions
diff --git a/test/exception-handling.wast b/test/exception-handling.wast index 862b82d88..72eb0be4a 100644 --- a/test/exception-handling.wast +++ b/test/exception-handling.wast @@ -1,6 +1,7 @@ (module - (event $e0 (attr 0) (param i32)) - (event $e1 (attr 0) (param externref)) + (event $e-i32 (attr 0) (param i32)) + (event $e-i64 (attr 0) (param i64)) + (event $e-i32-i64 (attr 0) (param i32 i64)) (func $exnref_test (param $0 exnref) (result exnref) (local.get $0) @@ -9,20 +10,27 @@ (func $foo) (func $bar) - (func $eh_test (local $exn exnref) + (func $eh_test (local $x (i32 i64)) + ;; Simple try-catch (try (do - (throw $e0 (i32.const 0)) + (throw $e-i32 (i32.const 0)) ) - (catch - ;; Multi-value is not available yet, so block can't take a value from - ;; stack. So this uses locals for now. - (local.set $exn (pop exnref)) + (catch $e-i32 + (drop (pop i32)) + ) + ) + + ;; try-catch with multivalue event + (try + (do + (throw $e-i32-i64 (i32.const 0) (i64.const 0)) + ) + (catch $e-i32-i64 + (local.set $x (pop i32 i64)) (drop - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e0 (local.get $exn)) - ) + (tuple.extract 0 + (local.get $x) ) ) ) @@ -33,7 +41,8 @@ (do (br $l1) ) - (catch + (catch $e-i32 + (drop (pop i32)) (br $l1) ) ) @@ -41,8 +50,8 @@ ;; Empty try body (try (do) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) ) ) @@ -52,11 +61,60 @@ (call $foo) (call $bar) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) + (call $foo) + (call $bar) + ) + ) + + ;; Multiple catch clauses + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch $e-i32 + (drop (pop i32)) + ) + (catch $e-i64 + (drop (pop i64)) + ) + ) + + ;; Single catch-all clause + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch_all) + ) + + ;; catch and catch-all clauses together + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch $e-i32 + (drop (pop i32)) + ) + (catch $e-i64 + (drop (pop i64)) + ) + (catch_all (call $foo) (call $bar) ) ) + + ;; rethrow + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch $e-i32 + (drop (pop i32)) + (rethrow 0) + ) + ) ) ) |