Skip to content

[cxx-interop] Fix extra indirection when exporting CFData arguments #74330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,12 @@ getCxxReferencePointeeTypeOrNone(const clang::Type *type);
/// Returns true if the given type is a C++ `const` reference type.
bool isCxxConstReferenceType(const clang::Type *type);

/// Determine whether this typedef is a CF type.
bool isCFTypeDecl(const clang::TypedefNameDecl *Decl);

/// Determine the imported CF type for the given typedef-name, or the empty
/// string if this is not an imported CF type name.
llvm::StringRef getCFTypeName(const clang::TypedefNameDecl *decl);
} // namespace importer

struct ClangInvocationFileMapping {
Expand Down
7 changes: 0 additions & 7 deletions lib/ClangImporter/CFTypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ class CFPointeeInfo {
return Decl.get<const clang::TypedefNameDecl *>();
}
};

/// Determine whether this typedef is a CF type.
bool isCFTypeDecl(const clang::TypedefNameDecl *Decl);

/// Determine the imported CF type for the given typedef-name, or the empty
/// string if this is not an imported CF type name.
llvm::StringRef getCFTypeName(const clang::TypedefNameDecl *decl);
}
}

Expand Down
10 changes: 8 additions & 2 deletions lib/PrintAsClang/PrintClangFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "swift/IRGen/IRABIDetailsProvider.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "llvm/ADT/STLExtras.h"

Expand Down Expand Up @@ -273,8 +274,13 @@ class CFunctionSignatureTypePrinter
bool isInOutParam) {
auto *cd = CT->getDecl();
if (cd->hasClangNode()) {
ClangSyntaxPrinter(os).printClangTypeReference(cd->getClangDecl());
os << " *"
const auto *clangDecl = cd->getClangDecl();
ClangSyntaxPrinter(os).printClangTypeReference(clangDecl);
bool alreadyPointer = false;
if (const auto *typedefDecl = dyn_cast<clang::TypedefNameDecl>(clangDecl))
if (importer::isCFTypeDecl(typedefDecl))
alreadyPointer = true;
os << (alreadyPointer ? " " : " *")
<< (!optionalKind || *optionalKind == OTK_None ? "_Nonnull"
: "_Nullable");
if (isInOutParam) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -typecheck %s -typecheck -module-name UseCoreFoundation -enable-experimental-cxx-interop -clang-header-expose-decls=all-public -emit-clang-header-path %t/UseCoreFoundation.h
// RUN: %FileCheck %s < %t/UseCoreFoundation.h

// REQUIRES: objc_interop

import CoreFoundation

public func foobar(_ a: CFData) -> Bool {
true
}

// CHECK: SWIFT_EXTERN bool $s17UseCoreFoundation6foobarySbSo9CFDataRefaF(CFDataRef _Nonnull a) SWIFT_NOEXCEPT SWIFT_CALL; // foobar(_:)