+void Verifier::visitEHPadPredecessors(Instruction &I) {
+ assert(I.isEHPad());
+
+ BasicBlock *BB = I.getParent();
+ Function *F = BB->getParent();
+
+ Assert(BB != &F->getEntryBlock(), "EH pad cannot be in entry block.", &I);
+
+ if (auto *LPI = dyn_cast<LandingPadInst>(&I)) {
+ // The landingpad instruction defines its parent as a landing pad block. The
+ // landing pad block may be branched to only by the unwind edge of an
+ // invoke.
+ for (BasicBlock *PredBB : predecessors(BB)) {
+ const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator());
+ Assert(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,
+ "Block containing LandingPadInst must be jumped to "
+ "only by the unwind edge of an invoke.",
+ LPI);
+ }
+ return;
+ }
+
+ for (BasicBlock *PredBB : predecessors(BB)) {
+ TerminatorInst *TI = PredBB->getTerminator();
+ if (auto *II = dyn_cast<InvokeInst>(TI))
+ Assert(II->getUnwindDest() == BB && II->getNormalDest() != BB,
+ "EH pad must be jumped to via an unwind edge", &I, II);
+ else if (auto *CPI = dyn_cast<CatchPadInst>(TI))
+ Assert(CPI->getUnwindDest() == BB && CPI->getNormalDest() != BB,
+ "EH pad must be jumped to via an unwind edge", &I, CPI);
+ else if (isa<CatchEndPadInst>(TI))
+ ;
+ else if (isa<CleanupReturnInst>(TI))
+ ;
+ else if (isa<CleanupEndPadInst>(TI))
+ ;
+ else if (isa<TerminatePadInst>(TI))
+ ;
+ else
+ Assert(false, "EH pad must be jumped to via an unwind edge", &I, TI);
+ }
+}