Skip to content

Commit bccd0b6

Browse files
authored
Merge pull request #30055 from slavapestov/vtable-thunk-generic-subclass-non-generic-base-class-5.2
SILGen: Fix crash when emitting vtable thunk for a generic subclass of non-generic base class [5.2]
2 parents b1336e1 + a426e2f commit bccd0b6

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4417,10 +4417,14 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
44174417
if (derivedClass->getSuperclass().isNull())
44184418
return nullptr;
44194419

4420-
if (baseGenericCtx->getGenericSignature().isNull() ||
4421-
derivedGenericCtx->getGenericSignature().isNull())
4420+
auto baseGenericSig = baseGenericCtx->getGenericSignature();
4421+
auto derivedGenericSig = derivedGenericCtx->getGenericSignature();
4422+
if (derivedGenericSig.isNull())
44224423
return nullptr;
44234424

4425+
if (baseGenericSig.isNull())
4426+
return derivedGenericSig;
4427+
44244428
auto baseClassSig = baseClass->getGenericSignature();
44254429
auto subMap = derivedClass->getSuperclass()->getContextSubstitutionMap(
44264430
derivedClass->getModuleContext(), baseClass);

test/SILGen/vtable_thunks.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ class Noot : Aap {
228228
override func map() -> (S?) -> () -> Noot {}
229229
}
230230

231+
// rdar://problem/59669591
232+
class Base {
233+
func returnsOptional() -> Int? { return nil }
234+
}
235+
236+
class Derived<Foo> : Base {
237+
// The thunk here needs to be generic.
238+
override func returnsOptional() -> Int { return 0 }
239+
}
240+
231241
// CHECK-LABEL: sil private [thunk] [ossa] @$s13vtable_thunks3BarC3foo{{[_0-9a-zA-Z]*}}FTV : $@convention(method) (@guaranteed @callee_guaranteed (Int) -> Int, @guaranteed Bar) -> @owned Optional<@callee_guaranteed (Int) -> Int>
232242
// CHECK: [[IMPL:%.*]] = function_ref @$s13vtable_thunks3BarC3foo{{[_0-9a-zA-Z]*}}F
233243
// CHECK: apply [[IMPL]]
@@ -257,6 +267,8 @@ class Noot : Aap {
257267
// CHECK: [[OUTER:%.*]] = convert_function [[INNER]] : $@callee_guaranteed () -> @owned Noot to $@callee_guaranteed () -> @owned Optional<Aap>
258268
// CHECK: return [[OUTER]]
259269

270+
// CHECK-LABEL: sil private [thunk] [ossa] @$s13vtable_thunks7DerivedC15returnsOptionalSiyFAA4BaseCADSiSgyFTV : $@convention(method) <τ_0_0> (@guaranteed Derived<τ_0_0>) -> Optional<Int> {
271+
260272
// CHECK-LABEL: sil_vtable D {
261273
// CHECK: #B.iuo!1: {{.*}} : @$s13vtable_thunks1D{{[A-Z0-9a-z_]*}}FTV
262274
// CHECK: #B.f!1: {{.*}} : @$s13vtable_thunks1D{{[A-Z0-9a-z_]*}}F
@@ -321,3 +333,8 @@ class Noot : Aap {
321333
// CHECK-LABEL: sil_vtable NoThrowVariance {
322334
// CHECK: #ThrowVariance.mightThrow!1: {{.*}} : @$s13vtable_thunks{{[A-Z0-9a-z_]*}}F
323335

336+
// CHECK-LABEL: sil_vtable Base {
337+
// CHECK: #Base.returnsOptional!1: (Base) -> () -> Int? : @$s13vtable_thunks4BaseC15returnsOptionalSiSgyF
338+
339+
// CHECK-LABEL: sil_vtable Derived {
340+
// CHECK: #Base.returnsOptional!1: (Base) -> () -> Int? : @$s13vtable_thunks7DerivedC15returnsOptionalSiyFAA4BaseCADSiSgyFTV [override]

0 commit comments

Comments
 (0)