[Clang importer] Import incomplete SWIFT_SHARED_REFERENCE types

Normally, Swift cannot import an incomplete type. However, when we are
importing a SWIFT_SHARED_REFERENCE type, we're always dealing with
pointers to the type, and there is no need for the underlying type to
be complete. This permits a common pattern in C libraries where the
actual underlying storage is opaque and all APIs traffic in the
pointer, e.g.,

    typedef struct MyTypeImpl *MyType;
    void MyTypeRetain(MyType ptr);
    void MyTypeRelease(MyType ptr);

to use SWIFT_SHARED_REFERENCE to import such types as foreign
references, rather than as OpaquePointer.

Fixes rdar://155970441.
This commit is contained in:
Doug Gregor
2025-07-17 21:30:55 -07:00
parent c88d8cf885
commit 72be0e0851
11 changed files with 220 additions and 56 deletions

View File

@@ -2560,7 +2560,7 @@ llvm::SmallVector<clang::CXXMethodDecl *, 4>
SwiftDeclSynthesizer::synthesizeStaticFactoryForCXXForeignRef(
const clang::CXXRecordDecl *cxxRecordDecl) {
if (cxxRecordDecl->isAbstract())
if (!cxxRecordDecl->isCompleteDefinition() || cxxRecordDecl->isAbstract())
return {};
clang::ASTContext &clangCtx = cxxRecordDecl->getASTContext();