Skip to content

Commit b12b4e9

Browse files
committed
Don't crash in RawSILInstLowering if DI produced an error.
In case DI doesn't classify assign_by_wrapper (because of another error), make sure that RawSILInstLowering can handle this. rdar://75433096
1 parent 91be112 commit b12b4e9

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

lib/SILOptimizer/Mandatory/RawSILInstLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b,
179179

180180
switch (inst->getMode()) {
181181
case AssignByWrapperInst::Unknown:
182-
llvm_unreachable("assign_by_wrapper must have a valid mode");
183-
182+
assert(b.getModule().getASTContext().hadError() &&
183+
"assign_by_wrapper must have a valid mode");
184+
// In case DefiniteInitialization already gave up with an error, just
185+
// treat the assign_by_wrapper as an "init".
186+
LLVM_FALLTHROUGH;
184187
case AssignByWrapperInst::Initialization:
185188
case AssignByWrapperInst::Assign: {
186189
SILValue initFn = inst->getInitializer();

test/SILOptimizer/definite_init_diagnostics.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify
2-
// RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify
32

43
import Swift
54

@@ -1606,4 +1605,29 @@ class A {
16061605
self.init(x: i)
16071606
}
16081607
} // expected-error {{'self.init' isn't called on all paths before returning from initializer}}
1609-
}
1608+
}
1609+
1610+
@propertyWrapper
1611+
struct Wrapper<T> {
1612+
var wrappedValue: T
1613+
1614+
init(wrappedValue initialValue: T) {
1615+
self.wrappedValue = initialValue
1616+
}
1617+
}
1618+
1619+
func foo(_ d: DerivedWrappedProperty) {
1620+
print(d)
1621+
}
1622+
1623+
class DerivedWrappedProperty : SomeClass {
1624+
@Wrapper var y: String
1625+
var z : String
1626+
1627+
init(s: String) {
1628+
y = s
1629+
z = s
1630+
foo(self) // expected-error {{'self' used in method call 'foo' before 'super.init' call}}
1631+
} // expected-error {{'super.init' isn't called on all paths before returning from initializer}}
1632+
1633+
}

0 commit comments

Comments
 (0)