@@ -521,6 +521,8 @@ namespace {
521
521
522
522
private:
523
523
524
+ void emitSelfConsumedDiagnostic (SILInstruction *Inst);
525
+
524
526
LiveOutBlockState &getBlockInfo (SILBasicBlock *BB) {
525
527
return PerBlockInfo.insert ({BB,
526
528
LiveOutBlockState (TheMemory.NumElements )}).first ->second ;
@@ -920,18 +922,23 @@ void LifetimeChecker::handleLoadUse(unsigned UseID) {
920
922
}
921
923
}
922
924
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
+
923
934
void LifetimeChecker::handleStoreUse (unsigned UseID) {
924
935
DIMemoryUse &InstInfo = Uses[UseID];
925
936
926
- if (getSelfConsumedAtInst (InstInfo. Inst ) != DIKind::No ) {
927
- // FIXME: more specific diagnostics here, handle this case gracefully below.
928
- if (! shouldEmitError ( InstInfo.Inst ))
937
+ if (TheMemory. isAnyInitSelf () ) {
938
+ if ( getSelfConsumedAtInst (InstInfo. Inst ) != DIKind::No) {
939
+ emitSelfConsumedDiagnostic ( InstInfo.Inst );
929
940
return ;
930
-
931
- diagnose (Module, InstInfo.Inst ->getLoc (),
932
- diag::self_inside_catch_superselfinit,
933
- (unsigned )TheMemory.isDelegatingInit ());
934
- return ;
941
+ }
935
942
}
936
943
937
944
// Determine the liveness state of the element that we care about.
@@ -1025,13 +1032,7 @@ void LifetimeChecker::handleInOutUse(const DIMemoryUse &Use) {
1025
1032
// before the "address" is passed as an l-value.
1026
1033
if (!isInitializedAtUse (Use, &IsSuperInitDone, &FailedSelfUse)) {
1027
1034
if (FailedSelfUse) {
1028
- // FIXME: more specific diagnostics here, handle this case gracefully below.
1029
- if (!shouldEmitError (Use.Inst ))
1030
- return ;
1031
-
1032
- diagnose (Module, Use.Inst ->getLoc (),
1033
- diag::self_inside_catch_superselfinit,
1034
- (unsigned )TheMemory.isDelegatingInit ());
1035
+ emitSelfConsumedDiagnostic (Use.Inst );
1035
1036
return ;
1036
1037
}
1037
1038
@@ -1133,13 +1134,7 @@ void LifetimeChecker::handleEscapeUse(const DIMemoryUse &Use) {
1133
1134
auto Inst = Use.Inst ;
1134
1135
1135
1136
if (FailedSelfUse) {
1136
- // FIXME: more specific diagnostics here, handle this case gracefully below.
1137
- if (!shouldEmitError (Inst))
1138
- return ;
1139
-
1140
- diagnose (Module, Inst->getLoc (),
1141
- diag::self_inside_catch_superselfinit,
1142
- (unsigned )TheMemory.isDelegatingInit ());
1137
+ emitSelfConsumedDiagnostic (Inst);
1143
1138
return ;
1144
1139
}
1145
1140
@@ -1500,13 +1495,7 @@ void LifetimeChecker::handleLoadUseFailure(const DIMemoryUse &Use,
1500
1495
SILInstruction *Inst = Use.Inst ;
1501
1496
1502
1497
if (FailedSelfUse) {
1503
- // FIXME: more specific diagnostics here, handle this case gracefully below.
1504
- if (!shouldEmitError (Inst))
1505
- return ;
1506
-
1507
- diagnose (Module, Inst->getLoc (),
1508
- diag::self_inside_catch_superselfinit,
1509
- (unsigned )TheMemory.isDelegatingInit ());
1498
+ emitSelfConsumedDiagnostic (Inst);
1510
1499
return ;
1511
1500
}
1512
1501
@@ -1664,16 +1653,11 @@ void LifetimeChecker::handleLoadUseFailure(const DIMemoryUse &Use,
1664
1653
void LifetimeChecker::handleSelfInitUse (DIMemoryUse &InstInfo) {
1665
1654
auto *Inst = InstInfo.Inst ;
1666
1655
1656
+ assert (TheMemory.isAnyInitSelf ());
1667
1657
assert (TheMemory.getType ()->hasReferenceSemantics ());
1668
1658
1669
1659
if (getSelfConsumedAtInst (Inst) != DIKind::No) {
1670
- // FIXME: more specific diagnostics here, handle this case gracefully below.
1671
- if (!shouldEmitError (Inst))
1672
- return ;
1673
-
1674
- diagnose (Module, Inst->getLoc (),
1675
- diag::self_inside_catch_superselfinit,
1676
- (unsigned )TheMemory.isDelegatingInit ());
1660
+ emitSelfConsumedDiagnostic (Inst);
1677
1661
return ;
1678
1662
}
1679
1663
@@ -1899,8 +1883,10 @@ void LifetimeChecker::processNonTrivialRelease(unsigned ReleaseID) {
1899
1883
isa<DestroyAddrInst>(Release));
1900
1884
1901
1885
auto Availability = getLivenessAtInst (Release, 0 , TheMemory.NumElements );
1902
- DIKind SelfConsumed =
1903
- getSelfConsumedAtInst (Release);
1886
+ DIKind SelfConsumed = DIKind::No;
1887
+
1888
+ if (TheMemory.isAnyInitSelf ())
1889
+ SelfConsumed = getSelfConsumedAtInst (Release);
1904
1890
1905
1891
if (SelfConsumed == DIKind::Yes) {
1906
1892
// We're in an error path after performing a self.init or super.init
@@ -2643,12 +2629,14 @@ bool LifetimeChecker::isInitializedAtUse(const DIMemoryUse &Use,
2643
2629
bool *FailedSelfUse) {
2644
2630
if (FailedSelfUse) *FailedSelfUse = false ;
2645
2631
if (SuperInitDone) *SuperInitDone = true ;
2646
-
2647
- // If the self.init() or super.init() call threw an error and
2648
- // we caught it, self is no longer available.
2649
- if (getSelfConsumedAtInst (Use.Inst ) != DIKind::No) {
2650
- if (FailedSelfUse) *FailedSelfUse = true ;
2651
- return false ;
2632
+
2633
+ if (TheMemory.isAnyInitSelf ()) {
2634
+ // If the self.init() or super.init() call threw an error and
2635
+ // we caught it, self is no longer available.
2636
+ if (getSelfConsumedAtInst (Use.Inst ) != DIKind::No) {
2637
+ if (FailedSelfUse) *FailedSelfUse = true ;
2638
+ return false ;
2639
+ }
2652
2640
}
2653
2641
2654
2642
// Determine the liveness states of the elements that we care about.
0 commit comments