2424#include " clang/AST/ASTContext.h"
2525#include " clang/AST/Attr.h"
2626#include " clang/AST/Decl.h"
27+ #include " clang/AST/DeclObjC.h"
2728#include " clang/AST/RecursiveASTVisitor.h"
2829#include " clang/AST/StmtVisitor.h"
2930#include " clang/AST/Type.h"
@@ -337,9 +338,9 @@ struct UnaliasedInstantiationVisitor
337338struct ForwardDeclaredConcreteTypeVisitor
338339 : clang::RecursiveASTVisitor<ForwardDeclaredConcreteTypeVisitor> {
339340 bool hasForwardDeclaredConcreteType = false ;
340- clang::Module *Owner;
341+ const clang::Module *Owner;
341342
342- ForwardDeclaredConcreteTypeVisitor (clang::Module *Owner) : Owner(Owner) {};
343+ ForwardDeclaredConcreteTypeVisitor (const clang::Module *Owner) : Owner(Owner) { ASSERT (Owner); };
343344
344345 bool VisitRecordType (clang::RecordType *RT) {
345346 const clang::RecordDecl *RD = RT->getDecl ()->getDefinition ();
@@ -393,6 +394,13 @@ static size_t getNumParams(const clang::FunctionDecl* D) {
393394}
394395} // namespace
395396
397+ static const clang::Decl *getTemplateInstantiation (const clang::FunctionDecl *D) {
398+ return D->getTemplateInstantiationPattern ();
399+ }
400+ static const clang::Decl *getTemplateInstantiation (const clang::ObjCMethodDecl *) {
401+ return nullptr ;
402+ }
403+
396404template <typename T>
397405static bool swiftifyImpl (ClangImporter::Implementation &Self,
398406 SwiftifyInfoFunctionPrinter &printer,
@@ -406,9 +414,20 @@ static bool swiftifyImpl(ClangImporter::Implementation &Self,
406414 ClangDecl->getAccess () == clang::AS_private)
407415 return false ;
408416
417+ if (ClangDecl->isImplicit ()) {
418+ DLOG (" implicit functions lack lifetime and bounds info" );
419+ return false ;
420+ }
421+
409422 clang::ASTContext &clangASTContext = Self.getClangASTContext ();
410423
411- ForwardDeclaredConcreteTypeVisitor CheckForwardDecls (ClangDecl->getOwningModule ());
424+ const clang::Module *OwningModule = nullptr ;
425+ if (const auto *Instance = getTemplateInstantiation (ClangDecl)) {
426+ OwningModule = Instance->getOwningModule ();
427+ } else {
428+ OwningModule = ClangDecl->getOwningModule ();
429+ }
430+ ForwardDeclaredConcreteTypeVisitor CheckForwardDecls (OwningModule);
412431
413432 // We only attach the macro if it will produce an overload. Any __counted_by
414433 // will produce an overload, since UnsafeBufferPointer is still an improvement
0 commit comments