@@ -716,18 +716,20 @@ class DeclAndTypePrinter::Implementation
716
716
.printSwiftABIFunctionSignatureAsCxxFunction (
717
717
AFD, methodTy,
718
718
/* selfTypeDeclContext=*/ typeDeclContext);
719
+ if (!funcABI)
720
+ return ;
719
721
owningPrinter.prologueOS << cFuncPrologueOS.str ();
720
722
721
723
DeclAndTypeClangFunctionPrinter declPrinter (os, owningPrinter.prologueOS ,
722
724
owningPrinter.typeMapping ,
723
725
owningPrinter.interopContext );
724
726
if (auto *accessor = dyn_cast<AccessorDecl>(AFD)) {
725
727
declPrinter.printCxxPropertyAccessorMethod (
726
- typeDeclContext, accessor, funcABI. getSymbolName (), resultTy,
728
+ typeDeclContext, accessor, funcABI-> getSymbolName (), resultTy,
727
729
/* isDefinition=*/ false );
728
730
} else {
729
731
declPrinter.printCxxMethod (typeDeclContext, AFD,
730
- funcABI. getSymbolName (), resultTy,
732
+ funcABI-> getSymbolName (), resultTy,
731
733
/* isDefinition=*/ false );
732
734
}
733
735
@@ -739,11 +741,12 @@ class DeclAndTypePrinter::Implementation
739
741
if (auto *accessor = dyn_cast<AccessorDecl>(AFD)) {
740
742
741
743
defPrinter.printCxxPropertyAccessorMethod (
742
- typeDeclContext, accessor, funcABI. getSymbolName (), resultTy,
744
+ typeDeclContext, accessor, funcABI-> getSymbolName (), resultTy,
743
745
/* isDefinition=*/ true );
744
746
} else {
745
- defPrinter.printCxxMethod (typeDeclContext, AFD, funcABI.getSymbolName (),
746
- resultTy, /* isDefinition=*/ true );
747
+ defPrinter.printCxxMethod (typeDeclContext, AFD,
748
+ funcABI->getSymbolName (), resultTy,
749
+ /* isDefinition=*/ true );
747
750
}
748
751
749
752
// FIXME: SWIFT_WARN_UNUSED_RESULT
@@ -1074,7 +1077,8 @@ class DeclAndTypePrinter::Implementation
1074
1077
}
1075
1078
1076
1079
// Print out the extern C Swift ABI function signature.
1077
- FuncionSwiftABIInformation printSwiftABIFunctionSignatureAsCxxFunction (
1080
+ Optional<FuncionSwiftABIInformation>
1081
+ printSwiftABIFunctionSignatureAsCxxFunction (
1078
1082
AbstractFunctionDecl *FD, Optional<FunctionType *> givenFuncType = None,
1079
1083
Optional<NominalTypeDecl *> selfTypeDeclContext = None) {
1080
1084
assert (outputLang == OutputLanguageMode::Cxx);
@@ -1094,13 +1098,16 @@ class DeclAndTypePrinter::Implementation
1094
1098
auto resultTy =
1095
1099
getForeignResultType (FD, funcTy, asyncConvention, errorConvention);
1096
1100
1101
+ std::string cRepresentationString;
1102
+ llvm::raw_string_ostream cRepresentationOS (cRepresentationString);
1103
+
1097
1104
FuncionSwiftABIInformation funcABI (FD);
1098
1105
1099
- os << " SWIFT_EXTERN " ;
1106
+ cRepresentationOS << " SWIFT_EXTERN " ;
1100
1107
1101
- DeclAndTypeClangFunctionPrinter funcPrinter (os, owningPrinter. prologueOS ,
1102
- owningPrinter.typeMapping ,
1103
- owningPrinter.interopContext );
1108
+ DeclAndTypeClangFunctionPrinter funcPrinter (
1109
+ cRepresentationOS, owningPrinter. prologueOS , owningPrinter.typeMapping ,
1110
+ owningPrinter.interopContext );
1104
1111
auto ABIparams = owningPrinter.interopContext .getIrABIDetails ()
1105
1112
.getFunctionABIAdditionalParams (FD);
1106
1113
llvm::SmallVector<DeclAndTypeClangFunctionPrinter::AdditionalParam, 2 >
@@ -1116,10 +1123,16 @@ class DeclAndTypePrinter::Implementation
1116
1123
if (!selfTypeDeclContext && !ABIparams.empty ())
1117
1124
convertABIAdditionalParams (FD, resultTy, ABIparams, additionalParams);
1118
1125
1119
- funcPrinter.printFunctionSignature (
1126
+ auto representation = funcPrinter.printFunctionSignature (
1120
1127
FD, funcABI.getSymbolName (), resultTy,
1121
1128
DeclAndTypeClangFunctionPrinter::FunctionSignatureKind::CFunctionProto,
1122
1129
additionalParams);
1130
+ if (representation.isUnsupported ()) {
1131
+ // FIXME: Emit remark about unemitted declaration.
1132
+ return None;
1133
+ }
1134
+
1135
+ os << cRepresentationOS.str ();
1123
1136
// Swift functions can't throw exceptions, we can only
1124
1137
// throw them from C++ when emitting C++ inline thunks for the Swift
1125
1138
// functions.
@@ -1402,8 +1415,10 @@ class DeclAndTypePrinter::Implementation
1402
1415
llvm::raw_string_ostream cFuncPrologueOS (cFuncDecl);
1403
1416
auto funcABI = Implementation (cFuncPrologueOS, owningPrinter, outputLang)
1404
1417
.printSwiftABIFunctionSignatureAsCxxFunction (FD);
1418
+ if (!funcABI)
1419
+ return ;
1405
1420
owningPrinter.prologueOS << cFuncPrologueOS.str ();
1406
- printAbstractFunctionAsCxxFunctionThunk (FD, funcABI);
1421
+ printAbstractFunctionAsCxxFunctionThunk (FD, * funcABI);
1407
1422
return ;
1408
1423
}
1409
1424
if (FD->getDeclContext ()->isTypeContext ())
0 commit comments