@@ -618,6 +618,15 @@ static bool isOptionalObjCExistential(Type ty) {
618618 return false ;
619619}
620620
621+ static bool isOptionalForeignReferenceType (Type ty) {
622+ if (auto obj = ty->getOptionalObjectType ()) {
623+ if (const auto *cd =
624+ dyn_cast_or_null<ClassDecl>(obj->getNominalOrBoundGenericNominal ()))
625+ return cd->isForeignReferenceType ();
626+ }
627+ return false ;
628+ }
629+
621630// Returns false if the given direct type is not yet supported because
622631// of its ABI.
623632template <class T >
@@ -658,7 +667,8 @@ static bool printDirectReturnOrParamCType(
658667 if (isKnownCType (valueType, typeMapping) ||
659668 (Count == 1 && lastOffset.isZero () && !valueType->hasTypeParameter () &&
660669 (valueType->isAnyClassReferenceType () ||
661- isOptionalObjCExistential (valueType)))) {
670+ isOptionalObjCExistential (valueType) ||
671+ isOptionalForeignReferenceType (valueType)))) {
662672 prettifiedValuePrinter ();
663673 return true ;
664674 }
@@ -1506,10 +1516,9 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
15061516 if (!nonOptResultType)
15071517 nonOptResultType = resultTy;
15081518 if (auto *classDecl = nonOptResultType->getClassOrBoundGenericClass ();
1509- classDecl || nonOptResultType->isObjCExistentialType ()) {
1519+ (classDecl && isa<clang::ObjCContainerDecl>(classDecl->getClangDecl ())) ||
1520+ nonOptResultType->isObjCExistentialType ()) {
15101521 assert (!classDecl || classDecl->hasClangNode ());
1511- assert (!classDecl ||
1512- isa<clang::ObjCContainerDecl>(classDecl->getClangDecl ()));
15131522 os << " return (__bridge_transfer " ;
15141523 declPrinter.withOutputStream (os).print (nonOptResultType);
15151524 os << " )(__bridge void *)" ;
@@ -1766,6 +1775,9 @@ bool DeclAndTypeClangFunctionPrinter::hasKnownOptionalNullableCxxMapping(
17661775 optionalObjectType->getNominalOrBoundGenericNominal ())) {
17671776 return typeInfo->canBeNullable ;
17681777 }
1778+ if (const auto *cd = dyn_cast<ClassDecl>(nominal))
1779+ if (cd->isForeignReferenceType ())
1780+ return true ;
17691781 return isa_and_nonnull<clang::ObjCInterfaceDecl>(nominal->getClangDecl ());
17701782 }
17711783 }
0 commit comments