From 5d90167464ef5709406aea7d87ad1657eec8618b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 29 May 2024 16:49:59 -0700 Subject: Fix Vacuuming of code leading up to an infinite loop (#6632) We had that logic right in other places, but the specific part of Vacuum that looks at code that leads up to an unreachable did not check for infinite loops, so it could remove them. --- src/passes/Vacuum.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 41a8e02da..4a4963291 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -158,15 +158,16 @@ struct Vacuum : public WalkerPass> { continue; } - // Check if we may no longer be heading to a trap. Two situations count - // here: Control flow might branch, or we might call (since a call might - // reach an import; see notes on that in pass.h:trapsNeverHappen). + // Check if we may no longer be heading to a trap. We can only optimize + // if the trap will actually be reached. Two situations can prevent that + // here: Control flow might branch away, or we might hang (which can + // happen in a call or a loop). // // We also cannot remove a pop as it is necessary for structural // reasons. EffectAnalyzer effects(getPassOptions(), *getModule(), list[i]); if (effects.transfersControlFlow() || effects.calls || - effects.danglingPop) { + effects.mayNotReturn || effects.danglingPop) { headingToTrap = false; continue; } -- cgit v1.2.3