Skip to content

[cxx-interop][IRGen] Assign Clang function types to copy constructors #72770

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
Apr 4, 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
11 changes: 9 additions & 2 deletions lib/IRGen/GenStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,17 @@ namespace {
ParameterConvention::Direct_Unowned);
SILResultInfo result(T.getASTType(), ResultConvention::Indirect);

auto clangFnType = T.getASTContext().getCanonicalClangFunctionType(
{ptrParam}, result, SILFunctionTypeRepresentation::CFunctionPointer);
auto extInfo = SILExtInfoBuilder()
.withClangFunctionType(clangFnType)
.withRepresentation(
SILFunctionTypeRepresentation::CFunctionPointer)
.build();

return SILFunctionType::get(
GenericSignature(),
SILFunctionType::ExtInfo().withRepresentation(
SILFunctionTypeRepresentation::CFunctionPointer),
extInfo,
SILCoroutineKind::None,
/*callee=*/ParameterConvention::Direct_Unowned,
/*params*/ {ptrParam},
Expand Down
6 changes: 6 additions & 0 deletions test/Interop/Cxx/class/Inputs/constructors.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ struct DeletedCopyConstructor {
DeletedCopyConstructor(const DeletedCopyConstructor &) = delete;
};

#ifdef ENABLE_PTRAUTH
struct HasPtrAuthMember {
void (*__ptrauth(1, 1, 3) handler)();
};
#endif

#endif // TEST_INTEROP_CXX_CLASS_INPUTS_CONSTRUCTORS_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %swift -emit-ir -module-name CopyConstructorsPtrAuth -target arm64e-apple-macosx11.0 -use-clang-function-types -Xcc -D -Xcc ENABLE_PTRAUTH -dump-clang-diagnostics -I %S/Inputs -cxx-interoperability-mode=default %s -parse-as-library

// REQUIRES: CPU=arm64e
// REQUIRES: OS=macosx

import Constructors

public func copyPtrAuthMemberWithDefaultCopyConstructor(_ x: HasPtrAuthMember)
-> (HasPtrAuthMember, HasPtrAuthMember) {
return (x, x)
}