@@ -1084,7 +1084,8 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
10841084 const AbstractFunctionDecl *FD, const LoweredFunctionSignature &signature,
10851085 StringRef swiftSymbolName, const NominalTypeDecl *typeDeclContext,
10861086 const ModuleDecl *moduleContext, Type resultTy, const ParameterList *params,
1087- bool hasThrows, const AnyFunctionType *funcType, bool isStaticMethod) {
1087+ bool hasThrows, const AnyFunctionType *funcType, bool isStaticMethod,
1088+ Optional<IRABIDetailsProvider::MethodDispatchInfo> dispatchInfo) {
10881089 if (typeDeclContext)
10891090 ClangSyntaxPrinter (os).printNominalTypeOutsideMemberDeclInnerStaticAssert (
10901091 typeDeclContext);
@@ -1096,9 +1097,29 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
10961097 os << " void* opaqueError = nullptr;\n " ;
10971098 os << " void* _ctx = nullptr;\n " ;
10981099 }
1100+ Optional<StringRef> indirectFunctionVar;
1101+ if (dispatchInfo &&
1102+ dispatchInfo->getKind () !=
1103+ IRABIDetailsProvider::MethodDispatchInfo::Kind::Direct) {
1104+ assert (dispatchInfo->getKind () == IRABIDetailsProvider::MethodDispatchInfo::
1105+ Kind::IndirectVTableStaticOffset);
1106+ auto vtableBitOffset = dispatchInfo->getStaticBitOffset ();
1107+
1108+ os << " void ***selfPtr_ = reinterpret_cast<void ***>( "
1109+ " ::swift::_impl::_impl_RefCountedClass::getOpaquePointer(*this));\n " ;
1110+ os << " void **vtable_ = *selfPtr_;\n " ;
1111+ os << " using FType = decltype(" << cxx_synthesis::getCxxImplNamespaceName ()
1112+ << " ::" << swiftSymbolName << " );\n " ;
1113+ os << " FType *fptr_ = reinterpret_cast<FType *>(*(vtable_ + "
1114+ << (vtableBitOffset / 8 ) << " ));\n " ; // FIXME: not 8
1115+ indirectFunctionVar = StringRef (" fptr_" );
1116+ }
10991117 auto printCallToCFunc = [&](Optional<StringRef> additionalParam) {
1100- os << cxx_synthesis::getCxxImplNamespaceName () << " ::" << swiftSymbolName
1101- << ' (' ;
1118+ if (indirectFunctionVar)
1119+ os << " (* " << *indirectFunctionVar << ' )' ;
1120+ else
1121+ os << cxx_synthesis::getCxxImplNamespaceName () << " ::" << swiftSymbolName;
1122+ os << ' (' ;
11021123
11031124 bool needsComma = false ;
11041125 size_t paramIndex = 1 ;
@@ -1329,7 +1350,8 @@ static StringRef getConstructorName(const AbstractFunctionDecl *FD) {
13291350void DeclAndTypeClangFunctionPrinter::printCxxMethod (
13301351 const NominalTypeDecl *typeDeclContext, const AbstractFunctionDecl *FD,
13311352 const LoweredFunctionSignature &signature, StringRef swiftSymbolName,
1332- Type resultTy, bool isStatic, bool isDefinition) {
1353+ Type resultTy, bool isStatic, bool isDefinition,
1354+ Optional<IRABIDetailsProvider::MethodDispatchInfo> dispatchInfo) {
13331355 bool isConstructor = isa<ConstructorDecl>(FD);
13341356 os << " " ;
13351357
@@ -1357,10 +1379,11 @@ void DeclAndTypeClangFunctionPrinter::printCxxMethod(
13571379
13581380 os << " {\n " ;
13591381 // FIXME: should it be objTy for resultTy?
1360- printCxxThunkBody (
1361- FD, signature, swiftSymbolName, typeDeclContext, FD->getModuleContext (),
1362- resultTy, FD->getParameters (), FD->hasThrows (),
1363- FD->getInterfaceType ()->castTo <AnyFunctionType>(), isStatic);
1382+ printCxxThunkBody (FD, signature, swiftSymbolName, typeDeclContext,
1383+ FD->getModuleContext (), resultTy, FD->getParameters (),
1384+ FD->hasThrows (),
1385+ FD->getInterfaceType ()->castTo <AnyFunctionType>(), isStatic,
1386+ dispatchInfo);
13641387 os << " }\n " ;
13651388}
13661389
0 commit comments