Index: llvm/trunk/include/llvm/IR/DomTreeUpdater.h =================================================================== --- llvm/trunk/include/llvm/IR/DomTreeUpdater.h +++ llvm/trunk/include/llvm/IR/DomTreeUpdater.h @@ -143,8 +143,9 @@ /// erased from available trees if it exists and finally get deleted. /// Under Eager UpdateStrategy, DelBB will be processed immediately. /// Under Lazy UpdateStrategy, DelBB will be queued until a flush event and - /// all available trees are up-to-date. When both DT and PDT are nullptrs, - /// DelBB will be queued until flush() is called. + /// all available trees are up-to-date. Assert if any instruction of DelBB is + /// modified while awaiting deletion. When both DT and PDT are nullptrs, DelBB + /// will be queued until flush() is called. void deleteBB(BasicBlock *DelBB); /// Delete DelBB. DelBB will be removed from its Parent and @@ -152,8 +153,9 @@ /// be called. Finally, DelBB will be deleted. /// Under Eager UpdateStrategy, DelBB will be processed immediately. /// Under Lazy UpdateStrategy, DelBB will be queued until a flush event and - /// all available trees are up-to-date. - /// Multiple callbacks can be queued for one DelBB under Lazy UpdateStrategy. + /// all available trees are up-to-date. Assert if any instruction of DelBB is + /// modified while awaiting deletion. Multiple callbacks can be queued for one + /// DelBB under Lazy UpdateStrategy. void callbackDeleteBB(BasicBlock *DelBB, std::function Callback); Index: llvm/trunk/lib/IR/DomTreeUpdater.cpp =================================================================== --- llvm/trunk/lib/IR/DomTreeUpdater.cpp +++ llvm/trunk/lib/IR/DomTreeUpdater.cpp @@ -136,6 +136,13 @@ return false; for (auto *BB : DeletedBBs) { + // After calling deleteBB or callbackDeleteBB under Lazy UpdateStrategy, + // validateDeleteBB() removes all instructions of DelBB and adds an + // UnreachableInst as its terminator. So we check whether the BasicBlock to + // delete only has an UnreachableInst inside. + assert(BB->getInstList().size() == 1 && + isa(BB->getTerminator()) && + "DelBB has been modified while awaiting deletion."); BB->removeFromParent(); eraseDelBBNode(BB); delete BB;