Skip to content

Commit 306662f

Browse files
committed
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.
1 parent f8fdcbb commit 306662f

File tree

3 files changed

+1
-7
lines changed

3 files changed

+1
-7
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ class DefaultActorImpl : public HeapObject {
698698
void initialize(bool isDistributedRemote = false) {
699699
auto flags = Flags();
700700
flags.setIsDistributedRemote(isDistributedRemote);
701-
new (&CurrentState) std::atomic<State>(State{JobRef(), flags});
701+
new (&CurrentState) swift::atomic<State>(State{JobRef(), flags});
702702
JobStorageHeapObject.metadata = nullptr;
703703
}
704704

test/Distributed/Runtime/distributed_actor_dynamic_remote_func.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
// UNSUPPORTED: use_os_stdlib
88
// UNSUPPORTED: back_deployment_runtime
99

10-
// FIXME(distributed): remote functions dont seem to work on windows?
11-
// XFAIL: OS=windows-msvc
12-
1310
import _Distributed
1411

1512
distributed actor LocalWorker {

test/Distributed/Runtime/distributed_actor_isRemote.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// UNSUPPORTED: use_os_stdlib
99
// UNSUPPORTED: back_deployment_runtime
1010

11-
// FIXME(distributed): remote functions dont seem to work on windows?
12-
// XFAIL: OS=windows-msvc
13-
1411
import _Distributed
1512

1613
@available(SwiftStdlib 5.6, *)

0 commit comments

Comments
 (0)