Skip to content

Commit 4f3708b

Browse files
FIx
1 parent 04e281e commit 4f3708b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/passes/CodeFolding.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ struct CodeFolding
436436
// conservative approximation because there can be cases that
437437
// 'try'/'try_table' is within the expression that may throw so it is
438438
// safe to take the expression out.
439+
// TODO: optimize this check to avoid two FindAlls.
439440
if (effects.throws() &&
440441
(FindAll<Try>(outOf).has() || FindAll<TryTable>(outOf).has())) {
441442
return false;
@@ -645,6 +646,8 @@ struct CodeFolding
645646
if (tails.size() < 2) {
646647
return false;
647648
}
649+
// Storage for lazily-computed body branch targets. Must be declared at
650+
// function scope so it outlives the pointer stored in bodyTargets.
648651
BranchUtils::NameSet localBodyTargets;
649652
// remove things that are untoward and cannot be optimized
650653
tails.erase(
@@ -708,6 +711,7 @@ struct CodeFolding
708711
// if we cannot merge to the end, then we definitely need 2 blocks,
709712
// and a branch. Use the pre-computed bodyTargets to avoid repeated
710713
// O(N) getBranchTargets calls.
714+
assert(bodyTargets);
711715
bool canMoveItems = canMove(items, getFunction()->body, *bodyTargets);
712716
if (!canMoveItems) {
713717
cost += 1 + WORTH_ADDING_BLOCK_TO_REMOVE_THIS_MUCH;

0 commit comments

Comments
 (0)