Skip to content

Commit 9026b6e

Browse files
authored
Concurrency: fix UB in DefaultActor initialization (#40263)
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.
1 parent 424bc40 commit 9026b6e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class DefaultActorImpl : public HeapObject {
685685

686686
/// Properly construct an actor, except for the heap header.
687687
void initialize() {
688-
new (&CurrentState) std::atomic<State>(State{JobRef(), Flags()});
688+
new (&CurrentState) swift::atomic<State>(State{JobRef(), Flags()});
689689
JobStorageHeapObject.metadata = nullptr;
690690
}
691691

0 commit comments

Comments
 (0)