From d8d46061939c9528bba057389d62e77371152ead Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 19 Nov 2021 07:23:09 -0800 Subject: [PATCH] Concurrency: fix UB in DefaultActor initialization This fixes a latent UB instance in the `DefaultActor` implementation that has haunted the Windows target. The shared constructor for the type caused an errant typo that happened to compile which introduced UB but happened to work for the non-Windows cases. This happened to work for the other targets as `swift::atomic` had a `std::atomic` at on most configurations, and the C delegate for the Actor initializer happened to overlap and initialize the memory properly. The Windows case used an inline pointer width value but would be attempted to be initialized as a `std::atomic`. Relying on the overlap is unsafe to assume, and we should use the type's own constructor which delegates appropriately. --- stdlib/public/Concurrency/Actor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/Concurrency/Actor.cpp b/stdlib/public/Concurrency/Actor.cpp index d70e751d455c0..681f2ea91b7c5 100644 --- a/stdlib/public/Concurrency/Actor.cpp +++ b/stdlib/public/Concurrency/Actor.cpp @@ -685,7 +685,7 @@ class DefaultActorImpl : public HeapObject { /// Properly construct an actor, except for the heap header. void initialize() { - new (&CurrentState) std::atomic(State{JobRef(), Flags()}); + new (&CurrentState) swift::atomic(State{JobRef(), Flags()}); JobStorageHeapObject.metadata = nullptr; }