diff --git a/ir/irfunction.cpp b/ir/irfunction.cpp index 72374cc194..f3405a1c32 100644 --- a/ir/irfunction.cpp +++ b/ir/irfunction.cpp @@ -138,7 +138,7 @@ void ScopeStack::runCleanups( } // Insert the unconditional branch to the first cleanup block. - irs->ir->CreateBr(cleanupScopes.back().beginBlock); + irs->ir->CreateBr(cleanupScopes[sourceScope - 1].beginBlock); // Update all the control flow in the cleanups to make sure we end up where // we want. @@ -353,6 +353,7 @@ llvm::BasicBlock* ScopeStack::emitLandingPad() { it != end; ++it ) { // Insert any cleanups in between the last catch we ran and this one. + assert(lastCleanup >= it->cleanupScope); if (lastCleanup > it->cleanupScope) { landingPad->setCleanup(true); llvm::BasicBlock* afterCleanupBB = llvm::BasicBlock::Create( diff --git a/ir/irfunction.h b/ir/irfunction.h index d176e7c33a..27ab0e60e4 100644 --- a/ir/irfunction.h +++ b/ir/irfunction.h @@ -322,7 +322,8 @@ private: /// std::vector continueTargets; - /// + /// cleanupScopes[i] contains the information to go from + /// currentCleanupScope() == i + 1 to currentCleanupScope() == i. std::vector cleanupScopes; /// @@ -361,7 +362,9 @@ llvm::CallSite ScopeStack::callOrInvoke(llvm::Value* callee, const T &args, } if (currentLandingPads().empty()) { - // Have not encountered. + // Have not encountered any catches (for which we would push a scope) or + // calls to throwing functions (where we would have already executed + // this if) in this cleanup scope yet. currentLandingPads().push_back(0); }