@@ -66,6 +66,8 @@ bool isResilientType(Type t) {
6666 return false ;
6767}
6868
69+ bool isGenericType (Type t) { return t->is <GenericTypeParamType>(); }
70+
6971bool isKnownCxxType (Type t, PrimitiveTypeMapping &typeMapping) {
7072 return isKnownType (t, typeMapping, OutputLanguageMode::Cxx);
7173}
@@ -223,7 +225,12 @@ class CFunctionSignatureTypePrinter
223225 Optional<OptionalTypeKind> optionalKind,
224226 bool isInOutParam) {
225227 // FIXME: handle optionalKind.
226- // FIXME: handle isInOutParam.
228+ if (typeUseKind == FunctionSignatureTypeUse::ReturnType) {
229+ // generic is always returned indirectly in C signature.
230+ assert (languageMode == OutputLanguageMode::Cxx);
231+ os << genericTpt->getName ();
232+ return ;
233+ }
227234 if (!isInOutParam)
228235 os << " const " ;
229236 if (languageMode == OutputLanguageMode::Cxx) {
@@ -321,7 +328,7 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
321328 bool isIndirectReturnType =
322329 kind == FunctionSignatureKind::CFunctionProto &&
323330 !isKnownCType (resultTy, typeMapping) &&
324- (isResilientType (resultTy) ||
331+ (isResilientType (resultTy) || isGenericType (resultTy) ||
325332 interopContext.getIrABIDetails ().shouldReturnIndirectly (resultTy));
326333 if (!isIndirectReturnType) {
327334 OptionalTypeKind retKind;
@@ -542,6 +549,16 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
542549 // indirectly by a pointer.
543550 if (!isKnownCxxType (resultTy, typeMapping) &&
544551 !hasKnownOptionalNullableCxxMapping (resultTy)) {
552+ if (isGenericType (resultTy)) {
553+ // FIXME: Support returning value types.
554+ os << " T returnValue;\n " ;
555+ std::string returnAddress;
556+ llvm::raw_string_ostream ros (returnAddress);
557+ ros << " reinterpret_cast<void *>(&returnValue)" ;
558+ printCallToCFunc (/* additionalParam=*/ StringRef (ros.str ()));
559+ os << " ;\n return returnValue;\n " ;
560+ return ;
561+ }
545562 if (auto *decl = resultTy->getNominalOrBoundGenericNominal ()) {
546563 if ((isa<StructDecl>(decl) || isa<EnumDecl>(decl))) {
547564 bool isIndirect =
0 commit comments