Skip to content

Commit 983b5ee

Browse files
committed
[IRGen] Eliminate infinite loop in keypath generation.
Uncovered by the investigation of rdar://problem/45685649.
1 parent 0bea666 commit 983b5ee

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ emitWitnessTableGeneratorForKeyPath(IRGenModule &IGM,
732732
static unsigned getClassFieldIndex(ClassDecl *classDecl, VarDecl *property) {
733733
SmallVector<ClassDecl *, 3> superclasses;
734734
for (auto *superDecl = classDecl; superDecl != nullptr;
735-
superDecl = classDecl->getSuperclassDecl()) {
735+
superDecl = superDecl->getSuperclassDecl()) {
736736
superclasses.push_back(superDecl);
737737
}
738738

test/IRGen/keypaths.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ struct G<T> {
3333
subscript<U: Hashable>(x: U) -> T { get set }
3434
}
3535

36+
class C1: C { }
37+
class C2: C1 {
38+
var reabstracted: () -> ()
39+
}
40+
3641
sil_vtable C {}
42+
sil_vtable C1 {}
43+
sil_vtable C2 {}
3744

3845
// CHECK: %TSi = type <{ [[WORD:i.*]] }>
3946

@@ -195,6 +202,10 @@ sil_vtable C {}
195202
// CHECK-SAME: void (%swift.function*, %T8keypaths1SV*)* @m_get,
196203
// CHECK-SAME: void (%swift.function*, %T8keypaths1SV*)* @m_set }>
197204

205+
// -- %m2: reabstracted
206+
// Note: the contents here aren't interesting. The test triggered infinite
207+
// looping in the compiler at one point.
208+
// CHECK: [[KP_M:@keypath.*]] = private global <{ {{.*}} }> <{
198209

199210
// -- %i: Gen<A>.x
200211
// CHECK: [[KP_I:@keypath.*]] = private global <{ {{.*}} }> <{
@@ -261,6 +272,7 @@ entry:
261272
%k = keypath $KeyPath<S, Int>, (root $S; gettable_property $Int, id @k_id : $@convention(thin) () -> (), getter @k_get : $@convention(thin) (@in_guaranteed S) -> @out Int)
262273
%l = keypath $KeyPath<C, Int>, (root $C; settable_property $Int, id #C.w!getter.1, getter @l_get : $@convention(thin) (@in_guaranteed C) -> @out Int, setter @l_set : $@convention(thin) (@in_guaranteed Int, @in_guaranteed C) -> ())
263274
%m = keypath $KeyPath<S, () -> ()>, (root $S; settable_property $() -> (), id ##S.reabstracted, getter @m_get : $@convention(thin) (@in_guaranteed S) -> @out @callee_guaranteed () -> @out (), setter @m_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout S) -> ())
275+
%m2 = keypath $KeyPath<C2, () -> ()>, (root $C2; settable_property $() -> (), id ##C2.reabstracted, getter @m2_get : $@convention(thin) (@in_guaranteed C2) -> @out @callee_guaranteed () -> @out (), setter @m2_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout C2) -> ())
264276

265277
return undef : $()
266278
}
@@ -274,6 +286,9 @@ sil @l_set : $@convention(thin) (@in_guaranteed Int, @in_guaranteed C) -> ()
274286
sil @m_get : $@convention(thin) (@in_guaranteed S) -> @out @callee_guaranteed () -> @out ()
275287
sil @m_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout S) -> ()
276288

289+
sil @m2_get : $@convention(thin) (@in_guaranteed C2) -> @out @callee_guaranteed () -> @out ()
290+
sil @m2_set : $@convention(thin) (@in_guaranteed @callee_guaranteed () -> @out (), @inout C2) -> ()
291+
277292
struct Gen<T, U> {
278293
var x: T
279294
var y: U

0 commit comments

Comments
 (0)