Skip to content

Commit 2149a46

Browse files
committed
[DI] InitAccessors: Ignore unreachable blocks when check property initialization inside of an init accessor
1 parent 645e8df commit 2149a46

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,12 @@ void LifetimeChecker::doIt() {
11821182
while (returnBB != F.end()) {
11831183
auto *terminator = returnBB->getTerminator();
11841184

1185+
// If this is an unreachable block, let's ignore it.
1186+
if (isa<UnreachableInst>(terminator)) {
1187+
++returnBB;
1188+
continue;
1189+
}
1190+
11851191
if (!isInitializedAtUse(DIMemoryUse(terminator, DIUseKind::Load, 0, 1)))
11861192
diagnoseMissingInit();
11871193

Diff for: test/SILOptimizer/init_accessor_definite_init_diagnostics.swift

+11
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ class TestInitWithGuard {
189189
}
190190
}
191191

192+
do {
193+
struct TestPropertyInitWithUnreachableBlocks {
194+
var _a: Int
195+
var a: Int? {
196+
@storageRestrictions(initializes: _a)
197+
init { _a = newValue ?? 0 } // Ok
198+
get { 42 }
199+
}
200+
}
201+
}
202+
192203
do {
193204
class Base<T: Collection> {
194205
private var _v: T

0 commit comments

Comments
 (0)