Skip to content

[Concurrency] Fix null pointer dereference for task-to-thread model. #82204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stdlib/public/Concurrency/ExecutorBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ internal func _jobGetExecutorPrivateData(
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_getMainExecutor")
internal func _getMainExecutor() -> any SerialExecutor {
internal func _getMainExecutorAsSerialExecutor() -> (any SerialExecutor)? {
return MainActor.executor
}
#else
// For task-to-thread model, this is implemented in C++
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_getMainExecutor")
internal func _getMainExecutor() -> any SerialExecutor
internal func _getMainExecutorAsSerialExecutor() -> (any SerialExecutor)?
#endif // SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
#endif // !$Embedded

Expand Down
6 changes: 5 additions & 1 deletion stdlib/public/Concurrency/ExecutorImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ internal func donateToGlobalExecutor(
@available(SwiftStdlib 6.2, *)
@_silgen_name("swift_task_getMainExecutorImpl")
internal func getMainExecutor() -> UnownedSerialExecutor {
return unsafe _getMainExecutor().asUnownedSerialExecutor()
let executor = _getMainExecutorAsSerialExecutor()
if let executor {
return unsafe executor.asUnownedSerialExecutor()
}
return unsafe unsafeBitCast(executor, to: UnownedSerialExecutor.self)
}

@available(SwiftStdlib 6.2, *)
Expand Down