Skip to content

Commit ee18c00

Browse files
[NFC] Crash if we try to convert non-ObjC protocols.
This should be a non-functional change because we shouldn't be converting protocols which aren't ObjC.
1 parent 1abd35a commit ee18c00

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/AST/ClangTypeConverter.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ clang::QualType ClangTypeConverter::visitProtocolType(ProtocolType *type) {
372372
auto &clangCtx = ClangASTContext;
373373

374374
if (!proto->isObjC())
375-
return getClangIdType(ClangASTContext);
375+
return clang::QualType();
376376

377377
assert(!cast_or_null<clang::ObjCProtocolDecl>(proto->getClangDecl())
378378
&& "We shouldn't be creating duplicate decls; see `convert`");
@@ -416,6 +416,8 @@ clang::QualType ClangTypeConverter::visitClassType(ClassType *type) {
416416
auto &clangCtx = ClangASTContext;
417417
auto swiftDecl = type->getDecl();
418418

419+
// TODO: [non-objc-class-clang-type-conversion]
420+
// See the corresponding note in GenClangType.cpp
419421
if (!swiftDecl->isObjC())
420422
return getClangIdType(clangCtx);
421423

lib/IRGen/GenClangType.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,13 @@ clang::CanQualType GenClangType::visitProtocolType(CanProtocolType type) {
374374
auto proto = type->getDecl();
375375
auto &clangCtx = getClangASTContext();
376376

377-
if (!proto->isObjC())
378-
return getClangIdType(clangCtx);
377+
if (!proto->isObjC()) {
378+
std::string s;
379+
llvm::raw_string_ostream err(s);
380+
err << "Trying to compute the clang type for a non-ObjC protocol type\n";
381+
proto->dump(err);
382+
llvm::report_fatal_error(err.str());
383+
}
379384

380385
// Single protocol -> id<Proto>
381386
clang::IdentifierInfo *name = &clangCtx.Idents.get(proto->getName().get());
@@ -410,6 +415,9 @@ clang::CanQualType GenClangType::visitClassType(CanClassType type) {
410415
auto &clangCtx = getClangASTContext();
411416
auto swiftDecl = type->getDecl();
412417

418+
// TODO: [non-objc-class-clang-type-conversion]
419+
// Crashing here instead of returning a bogus 'id' leads to test failures,
420+
// which is surprising.
413421
if (!swiftDecl->isObjC())
414422
return getClangIdType(clangCtx);
415423

0 commit comments

Comments
 (0)