Skip to content

Commit 664a933

Browse files
committed
Concurrency: Adopt std::bit_cast to suppress more warnings.
1 parent 80cfb7c commit 664a933

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

include/swift/Runtime/STLCompatibility.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===---- STLCompatibility.h - Runtime C++ Compatibiltiy Stubs --*- C++ -*-===//
1+
//===---- STLCompatibility.h - Runtime C++ Compatibility Stubs --*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//

stdlib/public/Concurrency/Task.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
#include "swift/Basic/Lazy.h"
3434
#include "swift/Runtime/Concurrency.h"
3535
#include "swift/Runtime/EnvironmentVariables.h"
36-
#include "swift/Runtime/HeapObject.h"
3736
#include "swift/Runtime/Heap.h"
37+
#include "swift/Runtime/HeapObject.h"
38+
#include "swift/Runtime/STLCompatibility.h"
3839
#include "swift/Threading/Mutex.h"
3940
#include <atomic>
4041
#include <new>
@@ -583,11 +584,8 @@ SWIFT_CC(swiftasync)
583584
static void task_wait_throwing_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
584585

585586
auto context = static_cast<TaskFutureWaitAsyncContext *>(_context);
586-
#pragma clang diagnostic push
587-
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
588587
auto resumeWithError =
589-
reinterpret_cast<AsyncVoidClosureEntryPoint *>(context->ResumeParent);
590-
#pragma clang diagnostic pop
588+
std::bit_cast<AsyncVoidClosureEntryPoint *>(context->ResumeParent);
591589
return resumeWithError(context->Parent, context->errorResult);
592590
}
593591

@@ -962,23 +960,17 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
962960
auto asyncContextPrefix = reinterpret_cast<AsyncContextPrefix *>(
963961
reinterpret_cast<char *>(allocation) + headerSize -
964962
sizeof(AsyncContextPrefix));
965-
#pragma clang diagnostic push
966-
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
967963
asyncContextPrefix->asyncEntryPoint =
968-
reinterpret_cast<AsyncVoidClosureEntryPoint *>(function);
969-
#pragma clang diagnostic pop
964+
std::bit_cast<AsyncVoidClosureEntryPoint *>(function);
970965
asyncContextPrefix->closureContext = closureContext;
971966
function = non_future_adapter;
972967
assert(sizeof(AsyncContextPrefix) == 3 * sizeof(void *));
973968
} else {
974969
auto asyncContextPrefix = reinterpret_cast<FutureAsyncContextPrefix *>(
975970
reinterpret_cast<char *>(allocation) + headerSize -
976971
sizeof(FutureAsyncContextPrefix));
977-
#pragma clang diagnostic push
978-
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
979972
asyncContextPrefix->asyncEntryPoint =
980-
reinterpret_cast<AsyncGenericClosureEntryPoint *>(function);
981-
#pragma clang diagnostic pop
973+
std::bit_cast<AsyncGenericClosureEntryPoint *>(function);
982974
function = future_adapter;
983975
asyncContextPrefix->closureContext = closureContext;
984976
assert(sizeof(FutureAsyncContextPrefix) == 4 * sizeof(void *));
@@ -1049,8 +1041,6 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
10491041
// Initialize the parent context pointer to null.
10501042
initialContext->Parent = nullptr;
10511043

1052-
#pragma clang diagnostic push
1053-
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
10541044
// Initialize the resumption funclet pointer (async return address) to
10551045
// the final funclet for completing the task.
10561046

@@ -1064,21 +1054,20 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
10641054
// The final funclet shouldn't release the task or the task function.
10651055
} else if (asyncLet) {
10661056
initialContext->ResumeParent =
1067-
reinterpret_cast<TaskContinuationFunction*>(&completeTask);
1057+
std::bit_cast<TaskContinuationFunction *>(&completeTask);
10681058

10691059
// If we have a non-null closure context and the task function is not
10701060
// consumed by calling it, use a final funclet that releases both the
10711061
// task and the closure context.
10721062
} else if (closureContext && !taskCreateFlags.isTaskFunctionConsumed()) {
10731063
initialContext->ResumeParent =
1074-
reinterpret_cast<TaskContinuationFunction*>(&completeTaskWithClosure);
1064+
std::bit_cast<TaskContinuationFunction *>(&completeTaskWithClosure);
10751065

10761066
// Otherwise, just release the task.
10771067
} else {
10781068
initialContext->ResumeParent =
1079-
reinterpret_cast<TaskContinuationFunction*>(&completeTaskAndRelease);
1069+
std::bit_cast<TaskContinuationFunction *>(&completeTaskAndRelease);
10801070
}
1081-
#pragma clang diagnostic pop
10821071

10831072
// Initialize the task-local allocator and our other private runtime
10841073
// state for the task.
@@ -1292,13 +1281,10 @@ AsyncTaskAndContext swift::swift_task_create(
12921281
FutureAsyncSignature,
12931282
SpecialPointerAuthDiscriminators::AsyncFutureFunction>(closureEntry);
12941283

1295-
#pragma clang diagnostic push
1296-
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
12971284
return swift_task_create_common(
12981285
rawTaskCreateFlags, options, futureResultType,
1299-
reinterpret_cast<TaskContinuationFunction *>(taskEntry), closureContext,
1286+
std::bit_cast<TaskContinuationFunction *>(taskEntry), closureContext,
13001287
initialContextSize);
1301-
#pragma clang diagnostic pop
13021288
}
13031289
}
13041290

@@ -1383,10 +1369,7 @@ void swift_task_future_wait_throwingImpl(
13831369
waitingTask->ResumeTask = task_wait_throwing_resume_adapter;
13841370
waitingTask->ResumeContext = callContext;
13851371

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);
13901373

13911374
// Wait on the future.
13921375
assert(task->isFuture());

0 commit comments

Comments
 (0)