summaryrefslogtreecommitdiff
path: root/src/passes/CodeFolding.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/CodeFolding.cpp')
-rw-r--r--src/passes/CodeFolding.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/passes/CodeFolding.cpp b/src/passes/CodeFolding.cpp
index dc2301f9c..2d17f6d31 100644
--- a/src/passes/CodeFolding.cpp
+++ b/src/passes/CodeFolding.cpp
@@ -343,15 +343,18 @@ private:
if (effects.danglingPop) {
return false;
}
- // When an expression can throw and it is within a try scope, taking it
- // out of the try scope changes the program's behavior, because the
- // expression that would otherwise have been caught by the try now
- // throws up to the next try scope or even up to the caller. We restrict
- // the move if 'outOf' contains a 'try' anywhere in it. This is a
- // conservative approximation because there can be cases that 'try' is
- // within the expression that may throw so it is safe to take the
- // expression out.
- if (effects.throws() && !FindAll<Try>(outOf).list.empty()) {
+ // When an expression can throw and it is within a try/try_table scope,
+ // taking it out of the try/try_table scope changes the program's
+ // behavior, because the expression that would otherwise have been
+ // caught by the try/try_table now throws up to the next try/try_table
+ // scope or even up to the caller. We restrict the move if 'outOf'
+ // contains a 'try' or 'try_table' anywhere in it. This is a
+ // conservative approximation because there can be cases that
+ // 'try'/'try_table' is within the expression that may throw so it is
+ // safe to take the expression out.
+ // TODO: optimize this check to avoid two FindAlls.
+ if (effects.throws() &&
+ (FindAll<Try>(outOf).has() || FindAll<TryTable>(outOf).has())) {
return false;
}
}