Skip to content

Commit 87f2b88

Browse files
committed
Concurrency: remove workaround for silencing UB
The newer clang properly identifies UB on invalid pointer casts. This was previously being silenced by suppressing the warnings. Adjust the code to use `std::bit_cast` (or the shim implementation) to avoid the UB in this code.
1 parent 433ff59 commit 87f2b88

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "swift/Runtime/EnvironmentVariables.h"
3636
#include "swift/Runtime/HeapObject.h"
3737
#include "swift/Runtime/Heap.h"
38+
#include "swift/Runtime/STLCompatibility.h"
3839
#include "swift/Threading/Mutex.h"
3940
#include <atomic>
4041
#include <new>
@@ -1059,8 +1060,6 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
10591060
// Initialize the parent context pointer to null.
10601061
initialContext->Parent = nullptr;
10611062

1062-
#pragma clang diagnostic push
1063-
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
10641063
// Initialize the resumption funclet pointer (async return address) to
10651064
// the final funclet for completing the task.
10661065

@@ -1074,21 +1073,20 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
10741073
// The final funclet shouldn't release the task or the task function.
10751074
} else if (asyncLet) {
10761075
initialContext->ResumeParent =
1077-
reinterpret_cast<TaskContinuationFunction*>(&completeTask);
1076+
std::bit_cast<TaskContinuationFunction *>(&completeTask);
10781077

10791078
// If we have a non-null closure context and the task function is not
10801079
// consumed by calling it, use a final funclet that releases both the
10811080
// task and the closure context.
10821081
} else if (closureContext && !taskCreateFlags.isTaskFunctionConsumed()) {
10831082
initialContext->ResumeParent =
1084-
reinterpret_cast<TaskContinuationFunction*>(&completeTaskWithClosure);
1083+
std::bit_cast<TaskContinuationFunction *>(&completeTaskWithClosure);
10851084

10861085
// Otherwise, just release the task.
10871086
} else {
10881087
initialContext->ResumeParent =
1089-
reinterpret_cast<TaskContinuationFunction*>(&completeTaskAndRelease);
1088+
std::bit_cast<TaskContinuationFunction *>(&completeTaskAndRelease);
10901089
}
1091-
#pragma clang diagnostic pop
10921090

10931091
// Initialize the task-local allocator and our other private runtime
10941092
// state for the task.

test/embedded/dependencies-concurrency-custom-executor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// DEP: _exit
1919
// DEP: _free
2020
// DEP: _malloc
21+
// DEP: _memcpy
2122
// DEP: _memmove
2223
// DEP: _memset
2324
// DEP: _memset_s

test/embedded/dependencies-concurrency.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// DEP: _exit
1919
// DEP: _free
2020
// DEP: _malloc
21+
// DEP: _memcpy
2122
// DEP: _memmove
2223
// DEP: _memset
2324
// DEP: _memset_s

test/embedded/dependencies-concurrency2.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// DEP: _exit
1717
// DEP: _free
1818
// DEP: _malloc
19+
// DEP: _memcpy
1920
// DEP: _memmove
2021
// DEP: _memset
2122
// DEP: _memset_s

0 commit comments

Comments
 (0)