@@ -66,6 +66,8 @@ bool isResilientType(Type t) {
66
66
return false ;
67
67
}
68
68
69
+ bool isGenericType (Type t) { return t->is <GenericTypeParamType>(); }
70
+
69
71
bool isKnownCxxType (Type t, PrimitiveTypeMapping &typeMapping) {
70
72
return isKnownType (t, typeMapping, OutputLanguageMode::Cxx);
71
73
}
@@ -223,7 +225,12 @@ class CFunctionSignatureTypePrinter
223
225
Optional<OptionalTypeKind> optionalKind,
224
226
bool isInOutParam) {
225
227
// 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
+ }
227
234
if (!isInOutParam)
228
235
os << " const " ;
229
236
if (languageMode == OutputLanguageMode::Cxx) {
@@ -321,7 +328,7 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
321
328
bool isIndirectReturnType =
322
329
kind == FunctionSignatureKind::CFunctionProto &&
323
330
!isKnownCType (resultTy, typeMapping) &&
324
- (isResilientType (resultTy) ||
331
+ (isResilientType (resultTy) || isGenericType (resultTy) ||
325
332
interopContext.getIrABIDetails ().shouldReturnIndirectly (resultTy));
326
333
if (!isIndirectReturnType) {
327
334
OptionalTypeKind retKind;
@@ -542,6 +549,16 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
542
549
// indirectly by a pointer.
543
550
if (!isKnownCxxType (resultTy, typeMapping) &&
544
551
!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
+ }
545
562
if (auto *decl = resultTy->getNominalOrBoundGenericNominal ()) {
546
563
if ((isa<StructDecl>(decl) || isa<EnumDecl>(decl))) {
547
564
bool isIndirect =
0 commit comments