Skip to content

[Concurrency] Use reinterpret_cast for function_cast when ptrauth is on. #81380

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
May 9, 2025
Merged
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
8 changes: 8 additions & 0 deletions include/swift/Basic/Casting.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ Destination function_cast(Source source) {
static_assert(std::is_trivially_copyable_v<Destination>,
"The destination type must be trivially constructible");

#if __has_feature(ptrauth_calls)
// Use reinterpret_cast here so we perform any necessary auth-and-sign.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we should be silencing away this warning. This is technically UB, and the compiler is pointing that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t see any use in leaving it. The cast is necessary for correct behavior when ptrauth_calls is on, so we’d just have a warning we can’t address.

return reinterpret_cast<Destination>(source);
#pragma clang diagnostic pop
#else
Destination destination;
memcpy(&destination, &source, sizeof(source));
return destination;
#endif
}

}
Expand Down