Skip to content

Commit 1e2c9de

Browse files
committed
[Swiftify] fix missing owning module
Implicit decls don't have an owning module, since multiple modules could instantiate them on demand. Since no implicit functions currently have any need for safe wrappers we can simply detect this and early exit. For templated functions, we need to fetch the owning module from the instantiation.
1 parent de53140 commit 1e2c9de

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/ClangImporter/SwiftifyDecl.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
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
337338
struct 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+
396404
template<typename T>
397405
static 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

Comments
 (0)