@@ -4419,12 +4419,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4419
4419
" have at least one argument for self." );
4420
4420
}
4421
4421
4422
- // / Verify the various control-flow-sensitive rules of SIL:
4423
- // /
4424
- // / - stack allocations and deallocations must obey a stack discipline
4425
- // / - accesses must be uniquely ended
4426
- // / - flow-sensitive states must be equivalent on all paths into a block
4427
- void verifyFlowSensitiveRules (SILFunction *F) {
4422
+ struct VerifyFlowSensitiveRulesDetails {
4428
4423
enum CFGState {
4429
4424
// / No special rules are in play.
4430
4425
Normal,
@@ -4433,6 +4428,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4433
4428
// / We've followed the unwind edge of a yield.
4434
4429
YieldUnwind
4435
4430
};
4431
+
4436
4432
struct BBState {
4437
4433
std::vector<SingleValueInstruction*> Stack;
4438
4434
@@ -4441,17 +4437,24 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4441
4437
4442
4438
CFGState CFG = Normal;
4443
4439
};
4440
+ };
4444
4441
4442
+ // / Verify the various control-flow-sensitive rules of SIL:
4443
+ // /
4444
+ // / - stack allocations and deallocations must obey a stack discipline
4445
+ // / - accesses must be uniquely ended
4446
+ // / - flow-sensitive states must be equivalent on all paths into a block
4447
+ void verifyFlowSensitiveRules (SILFunction *F) {
4445
4448
// Do a breath-first search through the basic blocks.
4446
4449
// Note that we intentionally don't verify these properties in blocks
4447
4450
// that can't be reached from the entry block.
4448
- llvm::DenseMap<SILBasicBlock*, BBState> visitedBBs;
4451
+ llvm::DenseMap<SILBasicBlock*, VerifyFlowSensitiveRulesDetails:: BBState> visitedBBs;
4449
4452
SmallVector<SILBasicBlock*, 16 > Worklist;
4450
4453
visitedBBs.try_emplace (&*F->begin ());
4451
4454
Worklist.push_back (&*F->begin ());
4452
4455
while (!Worklist.empty ()) {
4453
4456
SILBasicBlock *BB = Worklist.pop_back_val ();
4454
- BBState state = visitedBBs[BB];
4457
+ VerifyFlowSensitiveRulesDetails:: BBState state = visitedBBs[BB];
4455
4458
for (SILInstruction &i : *BB) {
4456
4459
CurInstruction = &i;
4457
4460
@@ -4486,26 +4489,26 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4486
4489
" return with operations still active" );
4487
4490
4488
4491
if (isa<UnwindInst>(term)) {
4489
- require (state.CFG == YieldUnwind,
4492
+ require (state.CFG == VerifyFlowSensitiveRulesDetails:: YieldUnwind,
4490
4493
" encountered 'unwind' when not on unwind path" );
4491
4494
} else {
4492
- require (state.CFG != YieldUnwind,
4495
+ require (state.CFG != VerifyFlowSensitiveRulesDetails:: YieldUnwind,
4493
4496
" encountered 'return' or 'throw' when on unwind path" );
4494
4497
if (isa<ReturnInst>(term) &&
4495
4498
F->getLoweredFunctionType ()->getCoroutineKind () ==
4496
4499
SILCoroutineKind::YieldOnce &&
4497
4500
F->getModule ().getStage () != SILStage::Raw) {
4498
- require (state.CFG == YieldOnceResume,
4501
+ require (state.CFG == VerifyFlowSensitiveRulesDetails:: YieldOnceResume,
4499
4502
" encountered 'return' before yielding a value in "
4500
4503
" yield_once coroutine" );
4501
4504
}
4502
4505
}
4503
4506
}
4504
4507
4505
4508
if (isa<YieldInst>(term)) {
4506
- require (state.CFG != YieldOnceResume,
4509
+ require (state.CFG != VerifyFlowSensitiveRulesDetails:: YieldOnceResume,
4507
4510
" encountered multiple 'yield's along single path" );
4508
- require (state.CFG == Normal,
4511
+ require (state.CFG == VerifyFlowSensitiveRulesDetails:: Normal,
4509
4512
" encountered 'yield' on abnormal CFG path" );
4510
4513
}
4511
4514
@@ -4532,14 +4535,14 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
4532
4535
if (isa<YieldInst>(term)) {
4533
4536
// Enforce that the unwind logic is segregated in all stages.
4534
4537
if (i == 1 ) {
4535
- insertResult.first ->second .CFG = YieldUnwind;
4538
+ insertResult.first ->second .CFG = VerifyFlowSensitiveRulesDetails:: YieldUnwind;
4536
4539
4537
4540
// We check the yield_once rule in the mandatory analyses,
4538
4541
// so we can't assert it yet in the raw stage.
4539
4542
} else if (F->getLoweredFunctionType ()->getCoroutineKind ()
4540
4543
== SILCoroutineKind::YieldOnce &&
4541
4544
F->getModule ().getStage () != SILStage::Raw) {
4542
- insertResult.first ->second .CFG = YieldOnceResume;
4545
+ insertResult.first ->second .CFG = VerifyFlowSensitiveRulesDetails:: YieldOnceResume;
4543
4546
}
4544
4547
}
4545
4548
0 commit comments