diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-04-14 15:51:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-14 15:51:48 -0700 |
commit | 359525bc5c04798e394a6e0a48c40fbfed7366db (patch) | |
tree | 79f921c918d8df0268ff580dd5b35f67a8c229b8 | |
parent | ec76e9e8922a55b521c8b72ca970c7aee7b6d44a (diff) | |
download | binaryen-359525bc5c04798e394a6e0a48c40fbfed7366db.tar.gz binaryen-359525bc5c04798e394a6e0a48c40fbfed7366db.tar.bz2 binaryen-359525bc5c04798e394a6e0a48c40fbfed7366db.zip |
Note removal of catch body in Vacuum (#2765)
When it is certain that the try body does not throw, we can replace the
try-catch with the try body. But in this case we have to notify the type
updater that the catch body is removed, so that all parents' type should
be updated properly.
-rw-r--r-- | src/passes/Vacuum.cpp | 1 | ||||
-rw-r--r-- | test/passes/vacuum_all-features.txt | 3 | ||||
-rw-r--r-- | test/passes/vacuum_all-features.wast | 15 |
3 files changed, 19 insertions, 0 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 9b67a3a16..94537619c 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -423,6 +423,7 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> { if (!EffectAnalyzer(getPassOptions(), getModule()->features, curr->body) .throws) { replaceCurrent(curr->body); + typeUpdater.noteRecursiveRemoval(curr->catchBody); } } diff --git a/test/passes/vacuum_all-features.txt b/test/passes/vacuum_all-features.txt index 91a8a8edb..d563d70ed 100644 --- a/test/passes/vacuum_all-features.txt +++ b/test/passes/vacuum_all-features.txt @@ -463,4 +463,7 @@ ) ) ) + (func $br-in-catch + (unreachable) + ) ) diff --git a/test/passes/vacuum_all-features.wast b/test/passes/vacuum_all-features.wast index 98f13dd69..35d6fbd30 100644 --- a/test/passes/vacuum_all-features.wast +++ b/test/passes/vacuum_all-features.wast @@ -824,4 +824,19 @@ ) ) ) + + ;; When catch body is removed, the removal of 'br' inside the catch body + ;; should be propagated up to the outer block, so that its type will be + ;; correctly updated to unreachable. + (func $br-in-catch + (block $label$1 + (try + (unreachable) + (catch + (drop (exnref.pop)) + (br $label$1) + ) + ) + ) + ) ) |