Skip to content

Commit 850f65c

Browse files
committed
IRGen: Gracefully handle protocol forward declaration references without definitions
``` @protocol DeclarationOnly; @protocol DeclarationOnlyUser<DeclarationOnly> - (void) printIt; @EnD ``` This should not be neccessary, but the compiler currently accepts cases like the one in the test case added. rdar://101828847
1 parent a2c64b6 commit 850f65c

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/IRGen/GenObjC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ static void updateProtocolRefs(IRGenModule &IGM,
515515
auto oldVar = protocolRefs->getOperand(currentIdx);
516516
// Map the objc protocol to swift protocol.
517517
auto optionalDecl = clangImporter->importDeclCached(inheritedObjCProtocol);
518+
// This should not happen but the compiler currently silently accepts
519+
// protocol forward declarations without definitions (102058759).
520+
if (!optionalDecl || *optionalDecl == nullptr) {
521+
++currentIdx;
522+
continue;
523+
}
518524
auto inheritedSwiftProtocol = cast<ProtocolDecl>(*optionalDecl);
519525
// Get the objc protocol record we use in Swift.
520526
auto record = IGM.getAddrOfObjCProtocolRecord(inheritedSwiftProtocol,

test/IRGen/Inputs/usr/include/Gizmo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,10 @@ __attribute__((objc_non_runtime_protocol))
200200

201201
@protocol Runtime2P<NonRuntimeP, OtherNonRuntimeP, P3>
202202
@end
203+
204+
205+
@protocol DeclarationOnly;
206+
207+
@protocol DeclarationOnlyUser<DeclarationOnly>
208+
- (void) printIt;
209+
@end

test/IRGen/objc_protocols.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,9 @@ func triggerDoubleInheritedFunging() -> AnyObject {
222222
class TestNonRuntimeProto : RuntimeP { }
223223

224224
class TestNonRuntime2Proto : Runtime2P {}
225+
226+
public class SomeImpl : DeclarationOnlyUser {
227+
public func printIt() {
228+
print("hello")
229+
}
230+
}

0 commit comments

Comments
 (0)