Merge pull request #81383 from mikeash/function-cast-ptrauth-6.2

[6.2][Concurrency] Use reinterpret_cast for function_cast when ptrauth is on.
This commit is contained in:
Mike Ash
2025-05-09 14:08:19 -04:00
committed by GitHub

View File

@@ -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"
return reinterpret_cast<Destination>(source);
#pragma clang diagnostic pop
#else
Destination destination;
memcpy(&destination, &source, sizeof(source));
return destination;
#endif
}
}