Skip to content

IRGen: Gracefully handle protocol forward declaration references without definitions #61967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/IRGen/GenObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ static void updateProtocolRefs(IRGenModule &IGM,
auto oldVar = protocolRefs->getOperand(currentIdx);
// Map the objc protocol to swift protocol.
auto optionalDecl = clangImporter->importDeclCached(inheritedObjCProtocol);
// This should not happen but the compiler currently silently accepts
// protocol forward declarations without definitions (102058759).
if (!optionalDecl || *optionalDecl == nullptr) {
++currentIdx;
continue;
}
auto inheritedSwiftProtocol = cast<ProtocolDecl>(*optionalDecl);
// Get the objc protocol record we use in Swift.
auto record = IGM.getAddrOfObjCProtocolRecord(inheritedSwiftProtocol,
Expand Down
7 changes: 7 additions & 0 deletions test/IRGen/Inputs/usr/include/Gizmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,10 @@ __attribute__((objc_non_runtime_protocol))

@protocol Runtime2P<NonRuntimeP, OtherNonRuntimeP, P3>
@end


@protocol DeclarationOnly;

@protocol DeclarationOnlyUser<DeclarationOnly>
- (void) printIt;
@end
6 changes: 6 additions & 0 deletions test/IRGen/objc_protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,9 @@ func triggerDoubleInheritedFunging() -> AnyObject {
class TestNonRuntimeProto : RuntimeP { }

class TestNonRuntime2Proto : Runtime2P {}

public class SomeImpl : DeclarationOnlyUser {
public func printIt() {
print("hello")
}
}