Skip to content

Commit fcd2b97

Browse files
authored
Merge pull request #19510 from jmittert/NsStdError
Hoist CFGState and BBState out of function scope
2 parents 401c5e8 + c71d24b commit fcd2b97

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,12 +4425,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44254425
"have at least one argument for self.");
44264426
}
44274427

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 {
44344429
enum CFGState {
44354430
/// No special rules are in play.
44364431
Normal,
@@ -4439,6 +4434,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44394434
/// We've followed the unwind edge of a yield.
44404435
YieldUnwind
44414436
};
4437+
44424438
struct BBState {
44434439
std::vector<SingleValueInstruction*> Stack;
44444440

@@ -4447,17 +4443,24 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44474443

44484444
CFGState CFG = Normal;
44494445
};
4446+
};
44504447

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) {
44514454
// Do a breath-first search through the basic blocks.
44524455
// Note that we intentionally don't verify these properties in blocks
44534456
// that can't be reached from the entry block.
4454-
llvm::DenseMap<SILBasicBlock*, BBState> visitedBBs;
4457+
llvm::DenseMap<SILBasicBlock*, VerifyFlowSensitiveRulesDetails::BBState> visitedBBs;
44554458
SmallVector<SILBasicBlock*, 16> Worklist;
44564459
visitedBBs.try_emplace(&*F->begin());
44574460
Worklist.push_back(&*F->begin());
44584461
while (!Worklist.empty()) {
44594462
SILBasicBlock *BB = Worklist.pop_back_val();
4460-
BBState state = visitedBBs[BB];
4463+
VerifyFlowSensitiveRulesDetails::BBState state = visitedBBs[BB];
44614464
for (SILInstruction &i : *BB) {
44624465
CurInstruction = &i;
44634466

@@ -4492,26 +4495,26 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44924495
"return with operations still active");
44934496

44944497
if (isa<UnwindInst>(term)) {
4495-
require(state.CFG == YieldUnwind,
4498+
require(state.CFG == VerifyFlowSensitiveRulesDetails::YieldUnwind,
44964499
"encountered 'unwind' when not on unwind path");
44974500
} else {
4498-
require(state.CFG != YieldUnwind,
4501+
require(state.CFG != VerifyFlowSensitiveRulesDetails::YieldUnwind,
44994502
"encountered 'return' or 'throw' when on unwind path");
45004503
if (isa<ReturnInst>(term) &&
45014504
F->getLoweredFunctionType()->getCoroutineKind() ==
45024505
SILCoroutineKind::YieldOnce &&
45034506
F->getModule().getStage() != SILStage::Raw) {
4504-
require(state.CFG == YieldOnceResume,
4507+
require(state.CFG == VerifyFlowSensitiveRulesDetails::YieldOnceResume,
45054508
"encountered 'return' before yielding a value in "
45064509
"yield_once coroutine");
45074510
}
45084511
}
45094512
}
45104513

45114514
if (isa<YieldInst>(term)) {
4512-
require(state.CFG != YieldOnceResume,
4515+
require(state.CFG != VerifyFlowSensitiveRulesDetails::YieldOnceResume,
45134516
"encountered multiple 'yield's along single path");
4514-
require(state.CFG == Normal,
4517+
require(state.CFG == VerifyFlowSensitiveRulesDetails::Normal,
45154518
"encountered 'yield' on abnormal CFG path");
45164519
}
45174520

@@ -4538,14 +4541,14 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
45384541
if (isa<YieldInst>(term)) {
45394542
// Enforce that the unwind logic is segregated in all stages.
45404543
if (i == 1) {
4541-
insertResult.first->second.CFG = YieldUnwind;
4544+
insertResult.first->second.CFG = VerifyFlowSensitiveRulesDetails::YieldUnwind;
45424545

45434546
// We check the yield_once rule in the mandatory analyses,
45444547
// so we can't assert it yet in the raw stage.
45454548
} else if (F->getLoweredFunctionType()->getCoroutineKind()
45464549
== SILCoroutineKind::YieldOnce &&
45474550
F->getModule().getStage() != SILStage::Raw) {
4548-
insertResult.first->second.CFG = YieldOnceResume;
4551+
insertResult.first->second.CFG = VerifyFlowSensitiveRulesDetails::YieldOnceResume;
45494552
}
45504553
}
45514554

0 commit comments

Comments
 (0)