Skip to content

Commit 9ae709d

Browse files
committed
IRGen: Correctly register conformances for generic ObjC classes.
They aren't really generic at runtime, so register them as conformances on the nongeneric class. Fixes rdar://problem/27869089.
1 parent 95e92d5 commit 9ae709d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ getTypeEntityInfo(IRGenModule &IGM, CanType conformingType) {
20002000

20012001
auto nom = conformingType->getAnyNominal();
20022002
auto clas = dyn_cast<ClassDecl>(nom);
2003-
if (nom->isGenericContext() ||
2003+
if ((nom->isGenericContext() && (!clas || !clas->usesObjCGenericsModel())) ||
20042004
(clas && doesClassMetadataRequireDynamicInitialization(IGM, clas))) {
20052005
// Conformances for generics and concrete subclasses of generics
20062006
// are represented by referencing the nominal type descriptor.
@@ -2152,7 +2152,7 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
21522152
LinkEntity::forProtocolDescriptor(conformance->getProtocol()),
21532153
getPointerAlignment(), ProtocolDescriptorStructTy);
21542154
auto typeEntity = getTypeEntityInfo(*this,
2155-
conformance->getType()->getCanonicalType());
2155+
conformance->getType()->getCanonicalType());
21562156
auto flags = typeEntity.flags
21572157
.withConformanceKind(ProtocolConformanceReferenceKind::WitnessTable);
21582158

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import Foundation;
2+
3+
@interface Thingy<T>: NSObject
4+
5+
@end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-ir %s -import-objc-header %S/Inputs/objc_bridged_generic_conformance.h | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
// CHECK-NOT: _TMnCSo
5+
6+
// CHECK: @"\01l_protocol_conformances" = {{.*}} @"got.OBJC_CLASS_$_Thingy"
7+
8+
// CHECK-NOT: _TMnCSo
9+
10+
protocol P { func test() }
11+
12+
extension Thingy: P {
13+
func test() {}
14+
}

0 commit comments

Comments
 (0)