Skip to content

Commit 1b11e87

Browse files
committed
[IRGen] Skip witness table query for protocols that do not require one
Some protocols, such as protocols marked with 'objc', do not have a Witness Table. The code before this patch assumes all protocols do have a Witness Table when generating the layout of an OpaqueTypeDescriptor, causing an assert to be triggered for opaque return types that conform to an 'objc' protocol. Fixes SR-12257 / rdar://problem/59740179
1 parent 4c7bc26 commit 1b11e87

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,12 @@ namespace {
17411741
auto underlyingConformance = conformance
17421742
.subst(O->getUnderlyingInterfaceType(),
17431743
*O->getUnderlyingTypeSubstitutions());
1744-
1744+
1745+
// Skip protocols without Witness tables, e.g. @objc protocols.
1746+
if (!Lowering::TypeConverter::protocolRequiresWitnessTable(
1747+
underlyingConformance.getRequirement()))
1748+
continue;
1749+
17451750
auto witnessTableRef = IGM.emitWitnessTableRefString(
17461751
underlyingType, underlyingConformance,
17471752
contextSig,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir %s
2+
// REQUIRES: objc_interop
3+
//
4+
// Ensures this does not cause a crash, as @objc protocols are a special case
5+
// because they do not require a witness table
6+
// rdar://problem/59740179
7+
import Foundation
8+
9+
@objc
10+
public protocol MyProtocol {}
11+
12+
extension NSIndexSet: MyProtocol {}
13+
14+
public func toSomeMyProtocol() -> some MyProtocol {
15+
return NSIndexSet(index: 7)
16+
}

0 commit comments

Comments
 (0)