@@ -6289,18 +6289,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
6289
6289
}
6290
6290
6291
6291
void visitSILBasicBlock (SILBasicBlock *BB) {
6292
- // Make sure that each of the successors/predecessors of this basic block
6293
- // have this basic block in its predecessor/successor list.
6294
- for (const auto *SuccBB : BB->getSuccessorBlocks ()) {
6295
- require (SuccBB->isPredecessorBlock (BB),
6296
- " Must be a predecessor of each successor." );
6297
- }
6298
-
6299
- for (const SILBasicBlock *PredBB : BB->getPredecessorBlocks ()) {
6300
- require (PredBB->isSuccessorBlock (BB),
6301
- " Must be a successor of each predecessor." );
6302
- }
6303
-
6304
6292
SILInstructionVisitor::visitSILBasicBlock (BB);
6305
6293
verifyDebugScopeHoles (BB);
6306
6294
}
@@ -6331,6 +6319,33 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
6331
6319
continue ;
6332
6320
visitSILBasicBlock (&BB);
6333
6321
}
6322
+
6323
+ verifyPredecessorSucessorStructure (F);
6324
+ }
6325
+
6326
+ // Make sure that each of the successors/predecessors of a basic block
6327
+ // have this basic block in its predecessor/successor list.
6328
+ void verifyPredecessorSucessorStructure (SILFunction *f) {
6329
+ using PredSuccPair = std::pair<SILBasicBlock *, SILBasicBlock *>;
6330
+ llvm::DenseSet<PredSuccPair> foundSuccessors;
6331
+ llvm::DenseSet<PredSuccPair> foundPredecessors;
6332
+
6333
+ for (auto &block : *f) {
6334
+ for (SILBasicBlock *succ : block.getSuccessorBlocks ()) {
6335
+ foundSuccessors.insert ({&block, succ});
6336
+ }
6337
+ for (SILBasicBlock *pred : block.getPredecessorBlocks ()) {
6338
+ foundPredecessors.insert ({pred, &block});
6339
+ }
6340
+ }
6341
+ for (PredSuccPair predSucc : foundSuccessors) {
6342
+ require (foundPredecessors.contains (predSucc),
6343
+ " block is not predecessor of its successor" );
6344
+ }
6345
+ for (PredSuccPair predSucc : foundPredecessors) {
6346
+ require (foundSuccessors.contains (predSucc),
6347
+ " block is not successor of its predecessor" );
6348
+ }
6334
6349
}
6335
6350
6336
6351
void visitSILFunction (SILFunction *F) {
0 commit comments