Skip to content

Commit d6bb97a

Browse files
committed
DI: Factor out LifetimeChecker::emitSelfConsumedDiagnostic()
1 parent 3e9a30b commit d6bb97a

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ namespace {
521521

522522
private:
523523

524+
void emitSelfConsumedDiagnostic(SILInstruction *Inst);
525+
524526
LiveOutBlockState &getBlockInfo(SILBasicBlock *BB) {
525527
return PerBlockInfo.insert({BB,
526528
LiveOutBlockState(TheMemory.NumElements)}).first->second;
@@ -920,18 +922,21 @@ void LifetimeChecker::handleLoadUse(unsigned UseID) {
920922
}
921923
}
922924

925+
void LifetimeChecker::emitSelfConsumedDiagnostic(SILInstruction *Inst) {
926+
if (!shouldEmitError(Inst))
927+
return;
928+
929+
diagnose(Module, Inst->getLoc(),
930+
diag::self_inside_catch_superselfinit,
931+
(unsigned)TheMemory.isDelegatingInit());
932+
}
933+
923934
void LifetimeChecker::handleStoreUse(unsigned UseID) {
924935
DIMemoryUse &InstInfo = Uses[UseID];
925936

926937
if (TheMemory.isAnyInitSelf()) {
927938
if (getSelfConsumedAtInst(InstInfo.Inst) != DIKind::No) {
928-
// FIXME: more specific diagnostics here, handle this case gracefully below.
929-
if (!shouldEmitError(InstInfo.Inst))
930-
return;
931-
932-
diagnose(Module, InstInfo.Inst->getLoc(),
933-
diag::self_inside_catch_superselfinit,
934-
(unsigned)TheMemory.isDelegatingInit());
939+
emitSelfConsumedDiagnostic(InstInfo.Inst);
935940
return;
936941
}
937942
}
@@ -1027,13 +1032,7 @@ void LifetimeChecker::handleInOutUse(const DIMemoryUse &Use) {
10271032
// before the "address" is passed as an l-value.
10281033
if (!isInitializedAtUse(Use, &IsSuperInitDone, &FailedSelfUse)) {
10291034
if (FailedSelfUse) {
1030-
// FIXME: more specific diagnostics here, handle this case gracefully below.
1031-
if (!shouldEmitError(Use.Inst))
1032-
return;
1033-
1034-
diagnose(Module, Use.Inst->getLoc(),
1035-
diag::self_inside_catch_superselfinit,
1036-
(unsigned)TheMemory.isDelegatingInit());
1035+
emitSelfConsumedDiagnostic(Use.Inst);
10371036
return;
10381037
}
10391038

@@ -1135,13 +1134,7 @@ void LifetimeChecker::handleEscapeUse(const DIMemoryUse &Use) {
11351134
auto Inst = Use.Inst;
11361135

11371136
if (FailedSelfUse) {
1138-
// FIXME: more specific diagnostics here, handle this case gracefully below.
1139-
if (!shouldEmitError(Inst))
1140-
return;
1141-
1142-
diagnose(Module, Inst->getLoc(),
1143-
diag::self_inside_catch_superselfinit,
1144-
(unsigned)TheMemory.isDelegatingInit());
1137+
emitSelfConsumedDiagnostic(Inst);
11451138
return;
11461139
}
11471140

@@ -1502,13 +1495,7 @@ void LifetimeChecker::handleLoadUseFailure(const DIMemoryUse &Use,
15021495
SILInstruction *Inst = Use.Inst;
15031496

15041497
if (FailedSelfUse) {
1505-
// FIXME: more specific diagnostics here, handle this case gracefully below.
1506-
if (!shouldEmitError(Inst))
1507-
return;
1508-
1509-
diagnose(Module, Inst->getLoc(),
1510-
diag::self_inside_catch_superselfinit,
1511-
(unsigned)TheMemory.isDelegatingInit());
1498+
emitSelfConsumedDiagnostic(Inst);
15121499
return;
15131500
}
15141501

@@ -1670,13 +1657,7 @@ void LifetimeChecker::handleSelfInitUse(DIMemoryUse &InstInfo) {
16701657
assert(TheMemory.getType()->hasReferenceSemantics());
16711658

16721659
if (getSelfConsumedAtInst(Inst) != DIKind::No) {
1673-
// FIXME: more specific diagnostics here, handle this case gracefully below.
1674-
if (!shouldEmitError(Inst))
1675-
return;
1676-
1677-
diagnose(Module, Inst->getLoc(),
1678-
diag::self_inside_catch_superselfinit,
1679-
(unsigned)TheMemory.isDelegatingInit());
1660+
emitSelfConsumedDiagnostic(Inst);
16801661
return;
16811662
}
16821663

0 commit comments

Comments
 (0)