33
33
#include " swift/Basic/Lazy.h"
34
34
#include " swift/Runtime/Concurrency.h"
35
35
#include " swift/Runtime/EnvironmentVariables.h"
36
- #include " swift/Runtime/HeapObject.h"
37
36
#include " swift/Runtime/Heap.h"
37
+ #include " swift/Runtime/HeapObject.h"
38
+ #include " swift/Runtime/STLCompatibility.h"
38
39
#include " swift/Threading/Mutex.h"
39
40
#include < atomic>
40
41
#include < new>
@@ -583,11 +584,8 @@ SWIFT_CC(swiftasync)
583
584
static void task_wait_throwing_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
584
585
585
586
auto context = static_cast <TaskFutureWaitAsyncContext *>(_context);
586
- #pragma clang diagnostic push
587
- #pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
588
587
auto resumeWithError =
589
- reinterpret_cast <AsyncVoidClosureEntryPoint *>(context->ResumeParent );
590
- #pragma clang diagnostic pop
588
+ std::bit_cast<AsyncVoidClosureEntryPoint *>(context->ResumeParent );
591
589
return resumeWithError (context->Parent , context->errorResult );
592
590
}
593
591
@@ -962,23 +960,17 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
962
960
auto asyncContextPrefix = reinterpret_cast <AsyncContextPrefix *>(
963
961
reinterpret_cast <char *>(allocation) + headerSize -
964
962
sizeof (AsyncContextPrefix));
965
- #pragma clang diagnostic push
966
- #pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
967
963
asyncContextPrefix->asyncEntryPoint =
968
- reinterpret_cast <AsyncVoidClosureEntryPoint *>(function);
969
- #pragma clang diagnostic pop
964
+ std::bit_cast<AsyncVoidClosureEntryPoint *>(function);
970
965
asyncContextPrefix->closureContext = closureContext;
971
966
function = non_future_adapter;
972
967
assert (sizeof (AsyncContextPrefix) == 3 * sizeof (void *));
973
968
} else {
974
969
auto asyncContextPrefix = reinterpret_cast <FutureAsyncContextPrefix *>(
975
970
reinterpret_cast <char *>(allocation) + headerSize -
976
971
sizeof (FutureAsyncContextPrefix));
977
- #pragma clang diagnostic push
978
- #pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
979
972
asyncContextPrefix->asyncEntryPoint =
980
- reinterpret_cast <AsyncGenericClosureEntryPoint *>(function);
981
- #pragma clang diagnostic pop
973
+ std::bit_cast<AsyncGenericClosureEntryPoint *>(function);
982
974
function = future_adapter;
983
975
asyncContextPrefix->closureContext = closureContext;
984
976
assert (sizeof (FutureAsyncContextPrefix) == 4 * sizeof (void *));
@@ -1049,8 +1041,6 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
1049
1041
// Initialize the parent context pointer to null.
1050
1042
initialContext->Parent = nullptr ;
1051
1043
1052
- #pragma clang diagnostic push
1053
- #pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
1054
1044
// Initialize the resumption funclet pointer (async return address) to
1055
1045
// the final funclet for completing the task.
1056
1046
@@ -1064,21 +1054,20 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
1064
1054
// The final funclet shouldn't release the task or the task function.
1065
1055
} else if (asyncLet) {
1066
1056
initialContext->ResumeParent =
1067
- reinterpret_cast <TaskContinuationFunction*>(&completeTask);
1057
+ std::bit_cast <TaskContinuationFunction *>(&completeTask);
1068
1058
1069
1059
// If we have a non-null closure context and the task function is not
1070
1060
// consumed by calling it, use a final funclet that releases both the
1071
1061
// task and the closure context.
1072
1062
} else if (closureContext && !taskCreateFlags.isTaskFunctionConsumed ()) {
1073
1063
initialContext->ResumeParent =
1074
- reinterpret_cast <TaskContinuationFunction*>(&completeTaskWithClosure);
1064
+ std::bit_cast <TaskContinuationFunction *>(&completeTaskWithClosure);
1075
1065
1076
1066
// Otherwise, just release the task.
1077
1067
} else {
1078
1068
initialContext->ResumeParent =
1079
- reinterpret_cast <TaskContinuationFunction*>(&completeTaskAndRelease);
1069
+ std::bit_cast <TaskContinuationFunction *>(&completeTaskAndRelease);
1080
1070
}
1081
- #pragma clang diagnostic pop
1082
1071
1083
1072
// Initialize the task-local allocator and our other private runtime
1084
1073
// state for the task.
@@ -1292,13 +1281,10 @@ AsyncTaskAndContext swift::swift_task_create(
1292
1281
FutureAsyncSignature,
1293
1282
SpecialPointerAuthDiscriminators::AsyncFutureFunction>(closureEntry);
1294
1283
1295
- #pragma clang diagnostic push
1296
- #pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
1297
1284
return swift_task_create_common (
1298
1285
rawTaskCreateFlags, options, futureResultType,
1299
- reinterpret_cast <TaskContinuationFunction *>(taskEntry), closureContext,
1286
+ std::bit_cast <TaskContinuationFunction *>(taskEntry), closureContext,
1300
1287
initialContextSize);
1301
- #pragma clang diagnostic pop
1302
1288
}
1303
1289
}
1304
1290
@@ -1383,10 +1369,7 @@ void swift_task_future_wait_throwingImpl(
1383
1369
waitingTask->ResumeTask = task_wait_throwing_resume_adapter;
1384
1370
waitingTask->ResumeContext = callContext;
1385
1371
1386
- #pragma clang diagnostic push
1387
- #pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
1388
- auto resumeFn = reinterpret_cast <TaskContinuationFunction *>(resumeFunction);
1389
- #pragma clang diagnostic pop
1372
+ auto resumeFn = std::bit_cast<TaskContinuationFunction *>(resumeFunction);
1390
1373
1391
1374
// Wait on the future.
1392
1375
assert (task->isFuture ());
0 commit comments