Skip to content

Commit 6674043

Browse files
authored
Merge pull request swiftlang#26504 from slavapestov/final-req-test
SILGen: Add test to ensure we don't have a vtable entry for synthesized members of a final class
2 parents 0fd8d07 + 57f6fc2 commit 6674043

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/SILGen/synthesized_conformance_class.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ extension Nonfinal: Encodable where T: Encodable {}
6363
// CHECK-LABEL: // Nonfinal<A>.encode(to:)
6464
// CHECK-NEXT: sil hidden [ossa] @$s29synthesized_conformance_class8NonfinalCAASERzlE6encode2toys7Encoder_p_tKF : $@convention(method) <T where T : Encodable> (@in_guaranteed Encoder, @guaranteed Nonfinal<T>) -> @error Error {
6565

66+
final class FinalHashableClass : Hashable {
67+
static func ==(lhs: FinalHashableClass, rhs: FinalHashableClass) -> Bool {
68+
return false
69+
}
70+
71+
func hash(into: inout Hasher) {}
72+
}
73+
74+
// CHECK-LABEL: sil hidden [ossa] @$s29synthesized_conformance_class4doItySiAA18FinalHashableClassCF : $@convention(thin) (@guaranteed FinalHashableClass) -> Int {
75+
// CHECK: bb0(%0 : @guaranteed $FinalHashableClass):
76+
// CHECK: [[FN:%.*]] = function_ref @$s29synthesized_conformance_class18FinalHashableClassC9hashValueSivg : $@convention(method) (@guaranteed FinalHashableClass) -> Int
77+
// CHECK-NEXT: [[RESULT:%.*]] = apply [[FN]](%0) : $@convention(method) (@guaranteed FinalHashableClass) -> Int
78+
// CHECK-NEXT: return [[RESULT]] : $Int
79+
80+
func doIt(_ c: FinalHashableClass) -> Int {
81+
return c.hashValue
82+
}
83+
84+
// VTable for FinalHashableClass
85+
//
86+
// Note: we should not be emitting a vtable entry for the synthesized
87+
// FinalHashableClass.hashValue getter!
88+
89+
// CHECK: sil_vtable FinalHashableClass {
90+
// CHECK-NEXT: #FinalHashableClass.init!allocator.1: (FinalHashableClass.Type) -> () -> FinalHashableClass : @$s29synthesized_conformance_class18FinalHashableClassCACycfC
91+
// CHECK-NEXT: #FinalHashableClass.deinit!deallocator.1: @$s29synthesized_conformance_class18FinalHashableClassCfD
92+
// CHECK-NEXT: }
93+
6694
// Witness tables for Final
6795

6896
// CHECK-LABEL: sil_witness_table hidden <T where T : Encodable> Final<T>: Encodable module synthesized_conformance_class {

0 commit comments

Comments
 (0)