mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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.
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include "swift/Runtime/EnvironmentVariables.h"
|
#include "swift/Runtime/EnvironmentVariables.h"
|
||||||
#include "swift/Runtime/HeapObject.h"
|
#include "swift/Runtime/HeapObject.h"
|
||||||
#include "swift/Runtime/Heap.h"
|
#include "swift/Runtime/Heap.h"
|
||||||
|
#include "swift/Runtime/STLCompatibility.h"
|
||||||
#include "swift/Threading/Mutex.h"
|
#include "swift/Threading/Mutex.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <new>
|
#include <new>
|
||||||
@@ -1059,8 +1060,6 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
|
|||||||
// Initialize the parent context pointer to null.
|
// Initialize the parent context pointer to null.
|
||||||
initialContext->Parent = nullptr;
|
initialContext->Parent = nullptr;
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wcast-function-type-mismatch"
|
|
||||||
// Initialize the resumption funclet pointer (async return address) to
|
// Initialize the resumption funclet pointer (async return address) to
|
||||||
// the final funclet for completing the task.
|
// the final funclet for completing the task.
|
||||||
|
|
||||||
@@ -1074,21 +1073,20 @@ swift_task_create_commonImpl(size_t rawTaskCreateFlags,
|
|||||||
// The final funclet shouldn't release the task or the task function.
|
// The final funclet shouldn't release the task or the task function.
|
||||||
} else if (asyncLet) {
|
} else if (asyncLet) {
|
||||||
initialContext->ResumeParent =
|
initialContext->ResumeParent =
|
||||||
reinterpret_cast<TaskContinuationFunction*>(&completeTask);
|
std::bit_cast<TaskContinuationFunction *>(&completeTask);
|
||||||
|
|
||||||
// If we have a non-null closure context and the task function is not
|
// If we have a non-null closure context and the task function is not
|
||||||
// consumed by calling it, use a final funclet that releases both the
|
// consumed by calling it, use a final funclet that releases both the
|
||||||
// task and the closure context.
|
// task and the closure context.
|
||||||
} else if (closureContext && !taskCreateFlags.isTaskFunctionConsumed()) {
|
} else if (closureContext && !taskCreateFlags.isTaskFunctionConsumed()) {
|
||||||
initialContext->ResumeParent =
|
initialContext->ResumeParent =
|
||||||
reinterpret_cast<TaskContinuationFunction*>(&completeTaskWithClosure);
|
std::bit_cast<TaskContinuationFunction *>(&completeTaskWithClosure);
|
||||||
|
|
||||||
// Otherwise, just release the task.
|
// Otherwise, just release the task.
|
||||||
} else {
|
} else {
|
||||||
initialContext->ResumeParent =
|
initialContext->ResumeParent =
|
||||||
reinterpret_cast<TaskContinuationFunction*>(&completeTaskAndRelease);
|
std::bit_cast<TaskContinuationFunction *>(&completeTaskAndRelease);
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic pop
|
|
||||||
|
|
||||||
// Initialize the task-local allocator and our other private runtime
|
// Initialize the task-local allocator and our other private runtime
|
||||||
// state for the task.
|
// state for the task.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
// DEP: _exit
|
// DEP: _exit
|
||||||
// DEP: _free
|
// DEP: _free
|
||||||
// DEP: _malloc
|
// DEP: _malloc
|
||||||
|
// DEP: _memcpy
|
||||||
// DEP: _memmove
|
// DEP: _memmove
|
||||||
// DEP: _memset
|
// DEP: _memset
|
||||||
// DEP: _memset_s
|
// DEP: _memset_s
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
// DEP: _exit
|
// DEP: _exit
|
||||||
// DEP: _free
|
// DEP: _free
|
||||||
// DEP: _malloc
|
// DEP: _malloc
|
||||||
|
// DEP: _memcpy
|
||||||
// DEP: _memmove
|
// DEP: _memmove
|
||||||
// DEP: _memset
|
// DEP: _memset
|
||||||
// DEP: _memset_s
|
// DEP: _memset_s
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
// DEP: _exit
|
// DEP: _exit
|
||||||
// DEP: _free
|
// DEP: _free
|
||||||
// DEP: _malloc
|
// DEP: _malloc
|
||||||
|
// DEP: _memcpy
|
||||||
// DEP: _memmove
|
// DEP: _memmove
|
||||||
// DEP: _memset
|
// DEP: _memset
|
||||||
// DEP: _memset_s
|
// DEP: _memset_s
|
||||||
|
|||||||
Reference in New Issue
Block a user