@@ -623,13 +623,44 @@ clang::QualType ClangTypeConverter::visitEnumType(EnumType *type) {
623623}
624624
625625clang::QualType ClangTypeConverter::visitFunctionType (FunctionType *type) {
626- // We must've already computed it before if applicable.
627- return clang::QualType (type->getClangTypeInfo ().getType (), 0 );
626+ const clang::Type *clangTy = nullptr ;
627+ auto repr = type->getRepresentation ();
628+ bool useClangTypes = type->getASTContext ().LangOpts .UseClangFunctionTypes ;
629+ if (useClangTypes && (getSILFunctionLanguage (convertRepresentation (repr)) ==
630+ SILFunctionLanguage::C)) {
631+ clangTy = type->getClangTypeInfo ().getType ();
632+ } else if (!useClangTypes || repr == FunctionTypeRepresentation::Swift) {
633+ // C function pointer types themselves are not bridged but their components
634+ // can be. If a component is an @convention(block) function, it may be
635+ // bridged to a Swift function type.
636+ auto newRepr = (repr == FunctionTypeRepresentation::Swift
637+ ? FunctionTypeRepresentation::Block
638+ : repr);
639+ clangTy = getFunctionType (type->getParams (), type->getResult (), newRepr);
640+ }
641+ return clang::QualType (clangTy, 0 );
628642}
629643
630644clang::QualType ClangTypeConverter::visitSILFunctionType (SILFunctionType *type) {
631- // We must've already computed it before if applicable.
632- return clang::QualType (type->getClangTypeInfo ().getType (), 0 );
645+ const clang::Type *clangTy = nullptr ;
646+ auto repr = type->getRepresentation ();
647+ bool useClangTypes = type->getASTContext ().LangOpts .UseClangFunctionTypes ;
648+ if (useClangTypes &&
649+ (getSILFunctionLanguage (repr) == SILFunctionLanguage::C)) {
650+ clangTy = type->getClangTypeInfo ().getType ();
651+ } else if (!useClangTypes || repr == SILFunctionTypeRepresentation::Thick) {
652+ // C function pointer types themselves are not bridged but their components
653+ // can be. If a component is an @convention(block) function, it may be
654+ // bridged to a Swift function type.
655+ auto newRepr = (repr == SILFunctionTypeRepresentation::Thick
656+ ? SILFunctionTypeRepresentation::Block
657+ : repr);
658+ auto results = type->getResults ();
659+ auto optionalResult =
660+ results.empty () ? None : llvm::Optional<SILResultInfo>(results[0 ]);
661+ clangTy = getFunctionType (type->getParameters (), optionalResult, newRepr);
662+ }
663+ return clang::QualType (clangTy, 0 );
633664}
634665
635666clang::QualType
0 commit comments