Skip to content

Commit 1249899

Browse files
committed
[6.2][Concurrency] Use reinterpret_cast for function_cast when ptrauth is on.
We need to use reinterpret_cast when ptrauth is enabled to ensure that any necessary auth-and-sign operations are performed. rdar://150747009 (cherry picked from commit 0f2b047)
1 parent 6f696a4 commit 1249899

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/swift/Basic/Casting.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ Destination function_cast(Source source) {
4141
static_assert(std::is_trivially_copyable_v<Destination>,
4242
"The destination type must be trivially constructible");
4343

44+
#if __has_feature(ptrauth_calls)
45+
// Use reinterpret_cast here so we perform any necessary auth-and-sign.
46+
#pragma clang diagnostic push
47+
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
48+
return reinterpret_cast<Destination>(source);
49+
#pragma clang diagnostic pop
50+
#else
4451
Destination destination;
4552
memcpy(&destination, &source, sizeof(source));
4653
return destination;
54+
#endif
4755
}
4856

4957
}

0 commit comments

Comments
 (0)