@@ -618,6 +618,15 @@ static bool isOptionalObjCExistential(Type ty) {
618
618
return false ;
619
619
}
620
620
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
+
621
630
// Returns false if the given direct type is not yet supported because
622
631
// of its ABI.
623
632
template <class T >
@@ -658,7 +667,8 @@ static bool printDirectReturnOrParamCType(
658
667
if (isKnownCType (valueType, typeMapping) ||
659
668
(Count == 1 && lastOffset.isZero () && !valueType->hasTypeParameter () &&
660
669
(valueType->isAnyClassReferenceType () ||
661
- isOptionalObjCExistential (valueType)))) {
670
+ isOptionalObjCExistential (valueType) ||
671
+ isOptionalForeignReferenceType (valueType)))) {
662
672
prettifiedValuePrinter ();
663
673
return true ;
664
674
}
@@ -1506,10 +1516,9 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
1506
1516
if (!nonOptResultType)
1507
1517
nonOptResultType = resultTy;
1508
1518
if (auto *classDecl = nonOptResultType->getClassOrBoundGenericClass ();
1509
- classDecl || nonOptResultType->isObjCExistentialType ()) {
1519
+ (classDecl && isa<clang::ObjCContainerDecl>(classDecl->getClangDecl ())) ||
1520
+ nonOptResultType->isObjCExistentialType ()) {
1510
1521
assert (!classDecl || classDecl->hasClangNode ());
1511
- assert (!classDecl ||
1512
- isa<clang::ObjCContainerDecl>(classDecl->getClangDecl ()));
1513
1522
os << " return (__bridge_transfer " ;
1514
1523
declPrinter.withOutputStream (os).print (nonOptResultType);
1515
1524
os << " )(__bridge void *)" ;
@@ -1766,6 +1775,9 @@ bool DeclAndTypeClangFunctionPrinter::hasKnownOptionalNullableCxxMapping(
1766
1775
optionalObjectType->getNominalOrBoundGenericNominal ())) {
1767
1776
return typeInfo->canBeNullable ;
1768
1777
}
1778
+ if (const auto *cd = dyn_cast<ClassDecl>(nominal))
1779
+ if (cd->isForeignReferenceType ())
1780
+ return true ;
1769
1781
return isa_and_nonnull<clang::ObjCInterfaceDecl>(nominal->getClangDecl ());
1770
1782
}
1771
1783
}
0 commit comments