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