Skip to content

Commit c71d24b

Browse files
author
Jason Mittertreiner
committed
Hoist CFGState and BBState out of function scope
MSVC (Version 19.15.26726) has some really wonky behaviour with enums and structs in function scopes. Hoisting them outside seems to work around it.
1 parent cc3db35 commit c71d24b

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
@@ -4419,12 +4419,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44194419
"have at least one argument for self.");
44204420
}
44214421

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 {
44284423
enum CFGState {
44294424
/// No special rules are in play.
44304425
Normal,
@@ -4433,6 +4428,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44334428
/// We've followed the unwind edge of a yield.
44344429
YieldUnwind
44354430
};
4431+
44364432
struct BBState {
44374433
std::vector<SingleValueInstruction*> Stack;
44384434

@@ -4441,17 +4437,24 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44414437

44424438
CFGState CFG = Normal;
44434439
};
4440+
};
44444441

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

@@ -4486,26 +4489,26 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
44864489
"return with operations still active");
44874490

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

45054508
if (isa<YieldInst>(term)) {
4506-
require(state.CFG != YieldOnceResume,
4509+
require(state.CFG != VerifyFlowSensitiveRulesDetails::YieldOnceResume,
45074510
"encountered multiple 'yield's along single path");
4508-
require(state.CFG == Normal,
4511+
require(state.CFG == VerifyFlowSensitiveRulesDetails::Normal,
45094512
"encountered 'yield' on abnormal CFG path");
45104513
}
45114514

@@ -4532,14 +4535,14 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
45324535
if (isa<YieldInst>(term)) {
45334536
// Enforce that the unwind logic is segregated in all stages.
45344537
if (i == 1) {
4535-
insertResult.first->second.CFG = YieldUnwind;
4538+
insertResult.first->second.CFG = VerifyFlowSensitiveRulesDetails::YieldUnwind;
45364539

45374540
// We check the yield_once rule in the mandatory analyses,
45384541
// so we can't assert it yet in the raw stage.
45394542
} else if (F->getLoweredFunctionType()->getCoroutineKind()
45404543
== SILCoroutineKind::YieldOnce &&
45414544
F->getModule().getStage() != SILStage::Raw) {
4542-
insertResult.first->second.CFG = YieldOnceResume;
4545+
insertResult.first->second.CFG = VerifyFlowSensitiveRulesDetails::YieldOnceResume;
45434546
}
45444547
}
45454548

0 commit comments

Comments
 (0)