Skip to content

Commit 6c6f0d0

Browse files
authored
Merge pull request #14646 from DougGregor/relative-objc-classrefs
[Runtime] Reference ObjC class objects indirectly in conformance records
2 parents 1a08342 + 65b4c9a commit 6c6f0d0

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

include/swift/IRGen/Linking.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,9 @@ class LinkEntity {
723723
bool isForeignTypeMetadataCandidate() const {
724724
return getKind() == Kind::ForeignTypeMetadataCandidate;
725725
}
726+
bool isObjCClassRef() const {
727+
return getKind() == Kind::ObjCClassRef;
728+
}
726729

727730
/// Determine whether this entity will be weak-imported.
728731
bool isWeakImported(ModuleDecl *module) const {

lib/IRGen/GenDecl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,9 @@ IRGenModule::getAddrOfLLVMVariableOrGOTEquivalent(LinkEntity entity,
23732373
auto foreignCandidate
23742374
= getAddrOfForeignTypeMetadataCandidate(entity.getType());
23752375
(void)foreignCandidate;
2376+
} else if (entity.isObjCClassRef()) {
2377+
(void)getAddrOfObjCClassRef(
2378+
const_cast<ClassDecl *>(cast<ClassDecl>(entity.getDecl())));
23762379
} else {
23772380
getAddrOfLLVMVariable(entity, alignment, ConstantInit(),
23782381
defaultType, DebugTypeInfo());
@@ -2463,7 +2466,7 @@ getTypeEntityInfo(IRGenModule &IGM, CanType conformingType) {
24632466
typeKind = TypeMetadataRecordKind::IndirectObjCClass;
24642467
defaultTy = IGM.TypeMetadataPtrTy;
24652468
defaultPtrTy = IGM.TypeMetadataPtrTy;
2466-
entity = LinkEntity::forObjCClass(clas);
2469+
entity = LinkEntity::forObjCClassRef(clas);
24672470
} else {
24682471
// Conformances for generics and concrete subclasses of generics
24692472
// are represented by referencing the nominal type descriptor.

test/IRGen/objc_bridged_generic_conformance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// CHECK-NOT: _TMnCSo
55

6-
// CHECK: @"$SSo6ThingyCyxG32objc_bridged_generic_conformance1PADMc" = hidden constant %swift.protocol_conformance_descriptor {{.*}} @"got.OBJC_CLASS_$_Thingy"
6+
// CHECK: @"$SSo6ThingyCyxG32objc_bridged_generic_conformance1PADMc" = hidden constant %swift.protocol_conformance_descriptor {{.*}} @"OBJC_CLASS_REF_$_Thingy"
77

88
// CHECK-NOT: _TMnCSo
99

test/IRGen/protocol_conformance_records_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension NSRect: Runcible {
3030
// -- protocol descriptor
3131
// CHECK-SAME: [[RUNCIBLE]]
3232
// -- class object reference
33-
// CHECK-SAME: @"got.OBJC_CLASS_$_Gizmo"
33+
// CHECK-SAME: @"OBJC_CLASS_REF_$_Gizmo"
3434
// -- witness table
3535
// CHECK-SAME: @"$SSo5GizmoC33protocol_conformance_records_objc8RuncibleACWP"
3636
// -- flags

0 commit comments

Comments
 (0)