summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-06-07 18:20:28 -0700
committerGitHub <noreply@github.com>2020-06-07 18:20:28 -0700
commit6ec03c5c0c664660a88fdb61ac1d3bd1f8b14771 (patch)
tree4efaa7e0d0c4fec182d9a7cfb6b77289a7b11ccd /src
parent7fdec3735c712eb3588728c42bec4d34b82c5185 (diff)
downloadbinaryen-6ec03c5c0c664660a88fdb61ac1d3bd1f8b14771.tar.gz
binaryen-6ec03c5c0c664660a88fdb61ac1d3bd1f8b14771.tar.bz2
binaryen-6ec03c5c0c664660a88fdb61ac1d3bd1f8b14771.zip
Prevent calls from sinking into 'try' (#2899)
Expressions that may throw cannot be sinked into 'try'. At the start of 'try', we drop all sinkables that may throw.
Diffstat (limited to 'src')
-rw-r--r--src/passes/SimplifyLocals.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp
index 85c719d4c..ca3d714f4 100644
--- a/src/passes/SimplifyLocals.cpp
+++ b/src/passes/SimplifyLocals.cpp
@@ -302,6 +302,20 @@ struct SimplifyLocals
Expression** currp) {
Expression* curr = *currp;
+ // Expressions that may throw cannot be sinked into 'try'. At the start of
+ // 'try', we drop all sinkables that may throw.
+ if (curr->is<Try>()) {
+ std::vector<Index> invalidated;
+ for (auto& sinkable : self->sinkables) {
+ if (sinkable.second.effects.throws) {
+ invalidated.push_back(sinkable.first);
+ }
+ }
+ for (auto index : invalidated) {
+ self->sinkables.erase(index);
+ }
+ }
+
EffectAnalyzer effects(self->getPassOptions(), self->getModule()->features);
if (effects.checkPre(curr)) {
self->checkInvalidations(effects);